Mercurial > hg > octave-nkf
comparison src/DLD-FUNCTIONS/urlwrite.cc @ 14846:460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Example: func() => func ()
* dynamic.txi, func.txi, oop.txi, var.txi, embedded.cc, fortdemo.cc,
funcdemo.cc, paramdemo.cc, stringdemo.cc, unwinddemo.cc, Array.cc, Array.h,
CColVector.cc, CDiagMatrix.h, CMatrix.cc, CNDArray.cc, CRowVector.cc,
CSparse.cc, CmplxGEPBAL.cc, EIG.cc, MSparse.cc, MatrixType.cc,
Sparse-op-defs.h, Sparse-perm-op-defs.h, Sparse.cc, Sparse.h,
SparseCmplxCHOL.cc, SparseCmplxCHOL.h, SparseCmplxLU.cc, SparseCmplxQR.cc,
SparseCmplxQR.h, SparseQR.cc, SparseQR.h, SparsedbleCHOL.cc, SparsedbleCHOL.h,
SparsedbleLU.cc, SparsedbleLU.h, base-lu.cc, cmd-hist.cc, dColVector.cc,
dDiagMatrix.h, dMatrix.cc, dNDArray.cc, dRowVector.cc, dSparse.cc, dbleCHOL.cc,
dbleGEPBAL.cc, dim-vector.cc, eigs-base.cc, f2c-main.c, fCColVector.cc,
fCDiagMatrix.h, fCMatrix.cc, fCNDArray.cc, fCRowVector.cc, fCmplxGEPBAL.cc,
fColVector.cc, fDiagMatrix.h, fEIG.cc, fMatrix.cc, fNDArray.cc, fRowVector.cc,
file-ops.cc, file-stat.cc, floatCHOL.cc, floatGEPBAL.cc, idx-vector.h,
lo-specfun.cc, lo-sysdep.cc, mx-inlines.cc, oct-binmap.h, oct-convn.cc,
oct-md5.cc, oct-mem.h, oct-rand.cc, oct-syscalls.cc, randgamma.c, randmtzig.c,
sparse-base-chol.cc, sparse-base-chol.h, sparse-base-lu.cc, sparse-dmsolve.cc,
tempname.c, curl.m, divergence.m, randi.m, dlmwrite.m, edit.m, getappdata.m,
what.m, getarchdir.m, install.m, installed_packages.m, repackage.m,
unload_packages.m, colorbar.m, figure.m, isosurface.m, legend.m, loglog.m,
plot.m, plot3.m, plotyy.m, polar.m, __errplot__.m, __ghostscript__.m,
__marching_cube__.m, __plt__.m, __scatter__.m, semilogx.m, semilogy.m,
trimesh.m, trisurf.m, demo.m, test.m, datetick.m, __delaunayn__.cc,
__dsearchn__.cc, __fltk_uigetfile__.cc, __glpk__.cc, __init_fltk__.cc,
__lin_interpn__.cc, __magick_read__.cc, __pchip_deriv__.cc, balance.cc,
bsxfun.cc, ccolamd.cc, cellfun.cc, chol.cc, daspk.cc, dasrt.cc, dassl.cc,
dmperm.cc, eig.cc, eigs.cc, fftw.cc, filter.cc, find.cc, kron.cc, lookup.cc,
lsode.cc, matrix_type.cc, md5sum.cc, mgorth.cc, qr.cc, quad.cc, rand.cc,
regexp.cc, symbfact.cc, tril.cc, urlwrite.cc, op-bm-bm.cc, op-cdm-cdm.cc,
op-cell.cc, op-chm.cc, op-cm-cm.cc, op-cm-scm.cc, op-cm-sm.cc, op-cs-scm.cc,
op-cs-sm.cc, op-dm-dm.cc, op-dm-scm.cc, op-dm-sm.cc, op-fcdm-fcdm.cc,
op-fcm-fcm.cc, op-fdm-fdm.cc, op-fm-fm.cc, op-int.h, op-m-m.cc, op-m-scm.cc,
op-m-sm.cc, op-pm-pm.cc, op-pm-scm.cc, op-pm-sm.cc, op-range.cc, op-s-scm.cc,
op-s-sm.cc, op-sbm-sbm.cc, op-scm-cm.cc, op-scm-cs.cc, op-scm-m.cc,
op-scm-s.cc, op-scm-scm.cc, op-scm-sm.cc, op-sm-cm.cc, op-sm-cs.cc, op-sm-m.cc,
op-sm-s.cc, op-sm-scm.cc, op-sm-sm.cc, op-str-str.cc, op-struct.cc, bitfcns.cc,
data.cc, debug.cc, dynamic-ld.cc, error.cc, gl-render.cc, graphics.cc,
graphics.in.h, load-path.cc, ls-hdf5.cc, ls-mat5.cc, ls-mat5.h,
ls-oct-ascii.cc, ls-oct-ascii.h, mex.cc, mk-errno-list, oct-map.cc, oct-obj.h,
oct-parse.yy, octave-config.in.cc, ov-base-int.cc, ov-base-mat.cc, ov-base.cc,
ov-bool-mat.cc, ov-bool-sparse.cc, ov-bool.cc, ov-cell.cc, ov-class.cc,
ov-class.h, ov-cx-mat.cc, ov-cx-sparse.cc, ov-fcn-handle.cc, ov-flt-cx-mat.cc,
ov-flt-re-mat.cc, ov-intx.h, ov-range.h, ov-re-mat.cc, ov-re-sparse.cc,
ov-str-mat.cc, ov-struct.cc, ov-usr-fcn.h, ov.h, pr-output.cc, pt-id.cc,
pt-id.h, pt-mat.cc, pt-select.cc, sparse.cc, symtab.cc, symtab.h, syscalls.cc,
toplev.cc, txt-eng-ft.cc, variables.cc, zfstream.cc, zfstream.h, Dork.m,
getStash.m, myStash.m, Gork.m, Pork.m, myStash.m, getStash.m, myStash.m,
getStash.m, myStash.m, fntests.m: Use Octave coding convention for
cuddled parenthis in function calls with empty argument lists.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Sun, 08 Jul 2012 11:28:50 -0700 |
parents | c267a3522d6c |
children | 5ae9f0f77635 |
comparison
equal
deleted
inserted
replaced
14844:5bc9b9cb4362 | 14846:460a3c6d8bf1 |
---|---|
186 { | 186 { |
187 rep->host = _host; | 187 rep->host = _host; |
188 init (user, passwd, std::cin, octave_stdout); | 188 init (user, passwd, std::cin, octave_stdout); |
189 | 189 |
190 std::string url = "ftp://" + _host; | 190 std::string url = "ftp://" + _host; |
191 setopt (CURLOPT_URL, url.c_str()); | 191 setopt (CURLOPT_URL, url.c_str ()); |
192 | 192 |
193 // Setup the link, with no transfer | 193 // Setup the link, with no transfer |
194 if (!error_state) | 194 if (!error_state) |
195 perform (); | 195 perform (); |
196 } | 196 } |
218 { | 218 { |
219 setopt (CURLOPT_URL, url.c_str ()); | 219 setopt (CURLOPT_URL, url.c_str ()); |
220 setopt (CURLOPT_POSTFIELDS, query_string.c_str ()); | 220 setopt (CURLOPT_POSTFIELDS, query_string.c_str ()); |
221 } | 221 } |
222 else | 222 else |
223 setopt (CURLOPT_URL, url.c_str()); | 223 setopt (CURLOPT_URL, url.c_str ()); |
224 | 224 |
225 if (!error_state) | 225 if (!error_state) |
226 retval = perform (false); | 226 retval = perform (false); |
227 } | 227 } |
228 | 228 |
294 | 294 |
295 void cwd (const std::string& path) const | 295 void cwd (const std::string& path) const |
296 { | 296 { |
297 struct curl_slist *slist = 0; | 297 struct curl_slist *slist = 0; |
298 std::string cmd = "cwd " + path; | 298 std::string cmd = "cwd " + path; |
299 slist = curl_slist_append (slist, cmd.c_str()); | 299 slist = curl_slist_append (slist, cmd.c_str ()); |
300 setopt (CURLOPT_POSTQUOTE, slist); | 300 setopt (CURLOPT_POSTQUOTE, slist); |
301 if (! error_state) | 301 if (! error_state) |
302 perform (); | 302 perform (); |
303 setopt (CURLOPT_POSTQUOTE, 0); | 303 setopt (CURLOPT_POSTQUOTE, 0); |
304 curl_slist_free_all (slist); | 304 curl_slist_free_all (slist); |
306 | 306 |
307 void del (const std::string& file) const | 307 void del (const std::string& file) const |
308 { | 308 { |
309 struct curl_slist *slist = 0; | 309 struct curl_slist *slist = 0; |
310 std::string cmd = "dele " + file; | 310 std::string cmd = "dele " + file; |
311 slist = curl_slist_append (slist, cmd.c_str()); | 311 slist = curl_slist_append (slist, cmd.c_str ()); |
312 setopt (CURLOPT_POSTQUOTE, slist); | 312 setopt (CURLOPT_POSTQUOTE, slist); |
313 if (! error_state) | 313 if (! error_state) |
314 perform (); | 314 perform (); |
315 setopt (CURLOPT_POSTQUOTE, 0); | 315 setopt (CURLOPT_POSTQUOTE, 0); |
316 curl_slist_free_all (slist); | 316 curl_slist_free_all (slist); |
318 | 318 |
319 void rmdir (const std::string& path) const | 319 void rmdir (const std::string& path) const |
320 { | 320 { |
321 struct curl_slist *slist = 0; | 321 struct curl_slist *slist = 0; |
322 std::string cmd = "rmd " + path; | 322 std::string cmd = "rmd " + path; |
323 slist = curl_slist_append (slist, cmd.c_str()); | 323 slist = curl_slist_append (slist, cmd.c_str ()); |
324 setopt (CURLOPT_POSTQUOTE, slist); | 324 setopt (CURLOPT_POSTQUOTE, slist); |
325 if (! error_state) | 325 if (! error_state) |
326 perform (); | 326 perform (); |
327 setopt (CURLOPT_POSTQUOTE, 0); | 327 setopt (CURLOPT_POSTQUOTE, 0); |
328 curl_slist_free_all (slist); | 328 curl_slist_free_all (slist); |
331 bool mkdir (const std::string& path, bool curlerror = true) const | 331 bool mkdir (const std::string& path, bool curlerror = true) const |
332 { | 332 { |
333 bool retval = false; | 333 bool retval = false; |
334 struct curl_slist *slist = 0; | 334 struct curl_slist *slist = 0; |
335 std::string cmd = "mkd " + path; | 335 std::string cmd = "mkd " + path; |
336 slist = curl_slist_append (slist, cmd.c_str()); | 336 slist = curl_slist_append (slist, cmd.c_str ()); |
337 setopt (CURLOPT_POSTQUOTE, slist); | 337 setopt (CURLOPT_POSTQUOTE, slist); |
338 if (! error_state) | 338 if (! error_state) |
339 retval = perform (curlerror); | 339 retval = perform (curlerror); |
340 setopt (CURLOPT_POSTQUOTE, 0); | 340 setopt (CURLOPT_POSTQUOTE, 0); |
341 curl_slist_free_all (slist); | 341 curl_slist_free_all (slist); |
344 | 344 |
345 void rename (const std::string& oldname, const std::string& newname) const | 345 void rename (const std::string& oldname, const std::string& newname) const |
346 { | 346 { |
347 struct curl_slist *slist = 0; | 347 struct curl_slist *slist = 0; |
348 std::string cmd = "rnfr " + oldname; | 348 std::string cmd = "rnfr " + oldname; |
349 slist = curl_slist_append (slist, cmd.c_str()); | 349 slist = curl_slist_append (slist, cmd.c_str ()); |
350 cmd = "rnto " + newname; | 350 cmd = "rnto " + newname; |
351 slist = curl_slist_append (slist, cmd.c_str()); | 351 slist = curl_slist_append (slist, cmd.c_str ()); |
352 setopt (CURLOPT_POSTQUOTE, slist); | 352 setopt (CURLOPT_POSTQUOTE, slist); |
353 if (! error_state) | 353 if (! error_state) |
354 perform (); | 354 perform (); |
355 setopt (CURLOPT_POSTQUOTE, 0); | 355 setopt (CURLOPT_POSTQUOTE, 0); |
356 curl_slist_free_all (slist); | 356 curl_slist_free_all (slist); |
357 } | 357 } |
358 | 358 |
359 void put (const std::string& file, std::istream& is) const | 359 void put (const std::string& file, std::istream& is) const |
360 { | 360 { |
361 std::string url = "ftp://" + rep->host + "/" + file; | 361 std::string url = "ftp://" + rep->host + "/" + file; |
362 setopt (CURLOPT_URL, url.c_str()); | 362 setopt (CURLOPT_URL, url.c_str ()); |
363 setopt (CURLOPT_UPLOAD, 1); | 363 setopt (CURLOPT_UPLOAD, 1); |
364 setopt (CURLOPT_NOBODY, 0); | 364 setopt (CURLOPT_NOBODY, 0); |
365 set_istream (is); | 365 set_istream (is); |
366 if (! error_state) | 366 if (! error_state) |
367 perform (); | 367 perform (); |
368 set_istream (std::cin); | 368 set_istream (std::cin); |
369 setopt (CURLOPT_NOBODY, 1); | 369 setopt (CURLOPT_NOBODY, 1); |
370 setopt (CURLOPT_UPLOAD, 0); | 370 setopt (CURLOPT_UPLOAD, 0); |
371 url = "ftp://" + rep->host; | 371 url = "ftp://" + rep->host; |
372 setopt (CURLOPT_URL, url.c_str()); | 372 setopt (CURLOPT_URL, url.c_str ()); |
373 } | 373 } |
374 | 374 |
375 void get (const std::string& file, std::ostream& os) const | 375 void get (const std::string& file, std::ostream& os) const |
376 { | 376 { |
377 std::string url = "ftp://" + rep->host + "/" + file; | 377 std::string url = "ftp://" + rep->host + "/" + file; |
378 setopt (CURLOPT_URL, url.c_str()); | 378 setopt (CURLOPT_URL, url.c_str ()); |
379 setopt (CURLOPT_NOBODY, 0); | 379 setopt (CURLOPT_NOBODY, 0); |
380 set_ostream (os); | 380 set_ostream (os); |
381 if (! error_state) | 381 if (! error_state) |
382 perform (); | 382 perform (); |
383 set_ostream (octave_stdout); | 383 set_ostream (octave_stdout); |
384 setopt (CURLOPT_NOBODY, 1); | 384 setopt (CURLOPT_NOBODY, 1); |
385 url = "ftp://" + rep->host; | 385 url = "ftp://" + rep->host; |
386 setopt (CURLOPT_URL, url.c_str()); | 386 setopt (CURLOPT_URL, url.c_str ()); |
387 } | 387 } |
388 | 388 |
389 void dir (void) const | 389 void dir (void) const |
390 { | 390 { |
391 std::string url = "ftp://" + rep->host + "/"; | 391 std::string url = "ftp://" + rep->host + "/"; |
392 setopt (CURLOPT_URL, url.c_str()); | 392 setopt (CURLOPT_URL, url.c_str ()); |
393 setopt (CURLOPT_NOBODY, 0); | 393 setopt (CURLOPT_NOBODY, 0); |
394 if (! error_state) | 394 if (! error_state) |
395 perform (); | 395 perform (); |
396 setopt (CURLOPT_NOBODY, 1); | 396 setopt (CURLOPT_NOBODY, 1); |
397 url = "ftp://" + rep->host; | 397 url = "ftp://" + rep->host; |
398 setopt (CURLOPT_URL, url.c_str()); | 398 setopt (CURLOPT_URL, url.c_str ()); |
399 } | 399 } |
400 | 400 |
401 string_vector list (void) const | 401 string_vector list (void) const |
402 { | 402 { |
403 std::ostringstream buf; | 403 std::ostringstream buf; |
404 std::string url = "ftp://" + rep->host + "/"; | 404 std::string url = "ftp://" + rep->host + "/"; |
405 setopt (CURLOPT_WRITEDATA, static_cast<void*> (&buf)); | 405 setopt (CURLOPT_WRITEDATA, static_cast<void*> (&buf)); |
406 setopt (CURLOPT_URL, url.c_str()); | 406 setopt (CURLOPT_URL, url.c_str ()); |
407 setopt (CURLOPT_DIRLISTONLY, 1); | 407 setopt (CURLOPT_DIRLISTONLY, 1); |
408 setopt (CURLOPT_NOBODY, 0); | 408 setopt (CURLOPT_NOBODY, 0); |
409 if (! error_state) | 409 if (! error_state) |
410 perform (); | 410 perform (); |
411 setopt (CURLOPT_NOBODY, 1); | 411 setopt (CURLOPT_NOBODY, 1); |
412 url = "ftp://" + rep->host; | 412 url = "ftp://" + rep->host; |
413 setopt (CURLOPT_WRITEDATA, static_cast<void*> (&octave_stdout)); | 413 setopt (CURLOPT_WRITEDATA, static_cast<void*> (&octave_stdout)); |
414 setopt (CURLOPT_DIRLISTONLY, 0); | 414 setopt (CURLOPT_DIRLISTONLY, 0); |
415 setopt (CURLOPT_URL, url.c_str()); | 415 setopt (CURLOPT_URL, url.c_str ()); |
416 | 416 |
417 // Count number of directory entries | 417 // Count number of directory entries |
418 std::string str = buf.str (); | 418 std::string str = buf.str (); |
419 octave_idx_type n = 0; | 419 octave_idx_type n = 0; |
420 size_t pos = 0; | 420 size_t pos = 0; |
441 } | 441 } |
442 | 442 |
443 void get_fileinfo (const std::string& filename, double& filesize, | 443 void get_fileinfo (const std::string& filename, double& filesize, |
444 time_t& filetime, bool& fileisdir) const | 444 time_t& filetime, bool& fileisdir) const |
445 { | 445 { |
446 std::string path = pwd(); | 446 std::string path = pwd (); |
447 | 447 |
448 std::string url = "ftp://" + rep->host + "/" + path + "/" + filename; | 448 std::string url = "ftp://" + rep->host + "/" + path + "/" + filename; |
449 setopt (CURLOPT_URL, url.c_str()); | 449 setopt (CURLOPT_URL, url.c_str ()); |
450 setopt (CURLOPT_FILETIME, 1); | 450 setopt (CURLOPT_FILETIME, 1); |
451 setopt (CURLOPT_HEADERFUNCTION, throw_away); | 451 setopt (CURLOPT_HEADERFUNCTION, throw_away); |
452 setopt (CURLOPT_WRITEFUNCTION, throw_away); | 452 setopt (CURLOPT_WRITEFUNCTION, throw_away); |
453 | 453 |
454 // FIXME | 454 // FIXME |
478 | 478 |
479 setopt (CURLOPT_WRITEFUNCTION, write_data); | 479 setopt (CURLOPT_WRITEFUNCTION, write_data); |
480 setopt (CURLOPT_HEADERFUNCTION, 0); | 480 setopt (CURLOPT_HEADERFUNCTION, 0); |
481 setopt (CURLOPT_FILETIME, 0); | 481 setopt (CURLOPT_FILETIME, 0); |
482 url = "ftp://" + rep->host; | 482 url = "ftp://" + rep->host; |
483 setopt (CURLOPT_URL, url.c_str()); | 483 setopt (CURLOPT_URL, url.c_str ()); |
484 | 484 |
485 // The MDTM command seems to reset the path to the root with the | 485 // The MDTM command seems to reset the path to the root with the |
486 // servers I tested with, so cd again into the correct path. Make | 486 // servers I tested with, so cd again into the correct path. Make |
487 // the path absolute so that this will work even with servers that | 487 // the path absolute so that this will work even with servers that |
488 // don't end up in the root after an MDTM command. | 488 // don't end up in the root after an MDTM command. |
501 setopt (CURLOPT_WRITEHEADER, static_cast<void *>(&buf)); | 501 setopt (CURLOPT_WRITEHEADER, static_cast<void *>(&buf)); |
502 | 502 |
503 if (! error_state) | 503 if (! error_state) |
504 { | 504 { |
505 perform (); | 505 perform (); |
506 retval = buf.str(); | 506 retval = buf.str (); |
507 | 507 |
508 // Can I assume that the path is alway in "" on the last line | 508 // Can I assume that the path is alway in "" on the last line |
509 size_t pos2 = retval.rfind ('"'); | 509 size_t pos2 = retval.rfind ('"'); |
510 size_t pos1 = retval.rfind ('"', pos2 - 1); | 510 size_t pos1 = retval.rfind ('"', pos2 - 1); |
511 retval = retval.substr(pos1 + 1, pos2 - pos1 - 1); | 511 retval = retval.substr(pos1 + 1, pos2 - pos1 - 1); |
534 { | 534 { |
535 std::string name = param(i).string_value (); | 535 std::string name = param(i).string_value (); |
536 std::string text = param(i+1).string_value (); | 536 std::string text = param(i+1).string_value (); |
537 | 537 |
538 // Encode strings. | 538 // Encode strings. |
539 char *enc_name = curl_easy_escape (rep->handle(), name.c_str (), | 539 char *enc_name = curl_easy_escape (rep->handle (), name.c_str (), |
540 name.length ()); | 540 name.length ()); |
541 char *enc_text = curl_easy_escape (rep->handle(), text.c_str (), | 541 char *enc_text = curl_easy_escape (rep->handle (), text.c_str (), |
542 text.length ()); | 542 text.length ()); |
543 | 543 |
544 query << enc_name << "=" << enc_text; | 544 query << enc_name << "=" << enc_text; |
545 | 545 |
546 curl_free (enc_name); | 546 curl_free (enc_name); |
547 curl_free (enc_text); | 547 curl_free (enc_text); |
548 | 548 |
549 if (i < param.numel()-1) | 549 if (i < param.numel ()-1) |
550 query << "&"; | 550 query << "&"; |
551 } | 551 } |
552 | 552 |
553 query.flush (); | 553 query.flush (); |
554 | 554 |
613 | 613 |
614 ~curl_handles (void) | 614 ~curl_handles (void) |
615 { | 615 { |
616 // Remove the elements of the map explicitly as they should | 616 // Remove the elements of the map explicitly as they should |
617 // be deleted before the call to curl_global_cleanup | 617 // be deleted before the call to curl_global_cleanup |
618 map.erase (begin(), end()); | 618 map.erase (begin (), end ()); |
619 | 619 |
620 curl_global_cleanup (); | 620 curl_global_cleanup (); |
621 } | 621 } |
622 | 622 |
623 iterator begin (void) { return iterator (map.begin ()); } | 623 iterator begin (void) { return iterator (map.begin ()); } |
739 { | 739 { |
740 print_usage (); | 740 print_usage (); |
741 return retval; | 741 return retval; |
742 } | 742 } |
743 | 743 |
744 std::string url = args(0).string_value(); | 744 std::string url = args(0).string_value (); |
745 | 745 |
746 if (error_state) | 746 if (error_state) |
747 { | 747 { |
748 error ("urlwrite: URL must be a character string"); | 748 error ("urlwrite: URL must be a character string"); |
749 return retval; | 749 return retval; |
750 } | 750 } |
751 | 751 |
752 // name to store the file if download is succesful | 752 // name to store the file if download is succesful |
753 std::string filename = args(1).string_value(); | 753 std::string filename = args(1).string_value (); |
754 | 754 |
755 if (error_state) | 755 if (error_state) |
756 { | 756 { |
757 error ("urlwrite: LOCALFILE must be a character string"); | 757 error ("urlwrite: LOCALFILE must be a character string"); |
758 return retval; | 758 return retval; |
761 std::string method; | 761 std::string method; |
762 Cell param; // empty cell array | 762 Cell param; // empty cell array |
763 | 763 |
764 if (nargin == 4) | 764 if (nargin == 4) |
765 { | 765 { |
766 method = args(2).string_value(); | 766 method = args(2).string_value (); |
767 | 767 |
768 if (error_state) | 768 if (error_state) |
769 { | 769 { |
770 error ("urlwrite: METHOD must be \"get\" or \"post\""); | 770 error ("urlwrite: METHOD must be \"get\" or \"post\""); |
771 return retval; | 771 return retval; |
775 { | 775 { |
776 error ("urlwrite: METHOD must be \"get\" or \"post\""); | 776 error ("urlwrite: METHOD must be \"get\" or \"post\""); |
777 return retval; | 777 return retval; |
778 } | 778 } |
779 | 779 |
780 param = args(3).cell_value(); | 780 param = args(3).cell_value (); |
781 | 781 |
782 if (error_state) | 782 if (error_state) |
783 { | 783 { |
784 error ("urlwrite: parameters (PARAM) for get and post requests must be given as a cell"); | 784 error ("urlwrite: parameters (PARAM) for get and post requests must be given as a cell"); |
785 return retval; | 785 return retval; |
797 // create it, and the download fails. We use unwind_protect to do | 797 // create it, and the download fails. We use unwind_protect to do |
798 // it so that the deletion happens no matter how we exit the function. | 798 // it so that the deletion happens no matter how we exit the function. |
799 | 799 |
800 file_stat fs (filename); | 800 file_stat fs (filename); |
801 | 801 |
802 std::ofstream ofile (filename.c_str(), std::ios::out | std::ios::binary); | 802 std::ofstream ofile (filename.c_str (), std::ios::out | std::ios::binary); |
803 | 803 |
804 if (! ofile.is_open ()) | 804 if (! ofile.is_open ()) |
805 { | 805 { |
806 error ("urlwrite: unable to open file"); | 806 error ("urlwrite: unable to open file"); |
807 return retval; | 807 return retval; |
899 { | 899 { |
900 print_usage (); | 900 print_usage (); |
901 return retval; | 901 return retval; |
902 } | 902 } |
903 | 903 |
904 std::string url = args(0).string_value(); | 904 std::string url = args(0).string_value (); |
905 | 905 |
906 if (error_state) | 906 if (error_state) |
907 { | 907 { |
908 error ("urlread: URL must be a character string"); | 908 error ("urlread: URL must be a character string"); |
909 return retval; | 909 return retval; |
912 std::string method; | 912 std::string method; |
913 Cell param; // empty cell array | 913 Cell param; // empty cell array |
914 | 914 |
915 if (nargin == 3) | 915 if (nargin == 3) |
916 { | 916 { |
917 method = args(1).string_value(); | 917 method = args(1).string_value (); |
918 | 918 |
919 if (error_state) | 919 if (error_state) |
920 { | 920 { |
921 error ("urlread: METHOD must be \"get\" or \"post\""); | 921 error ("urlread: METHOD must be \"get\" or \"post\""); |
922 return retval; | 922 return retval; |
926 { | 926 { |
927 error ("urlread: METHOD must be \"get\" or \"post\""); | 927 error ("urlread: METHOD must be \"get\" or \"post\""); |
928 return retval; | 928 return retval; |
929 } | 929 } |
930 | 930 |
931 param = args(2).cell_value(); | 931 param = args(2).cell_value (); |
932 | 932 |
933 if (error_state) | 933 if (error_state) |
934 { | 934 { |
935 error ("urlread: parameters (PARAM) for get and post requests must be given as a cell"); | 935 error ("urlread: parameters (PARAM) for get and post requests must be given as a cell"); |
936 return retval; | 936 return retval; |
1266 if (!error_state) | 1266 if (!error_state) |
1267 { | 1267 { |
1268 const curl_handle curl = handles.contents (handle); | 1268 const curl_handle curl = handles.contents (handle); |
1269 | 1269 |
1270 if (curl.is_valid ()) | 1270 if (curl.is_valid ()) |
1271 retval = (curl.is_ascii() ? "ascii" : "binary"); | 1271 retval = (curl.is_ascii () ? "ascii" : "binary"); |
1272 else | 1272 else |
1273 error ("__ftp_binary__: invalid ftp handle"); | 1273 error ("__ftp_binary__: invalid ftp handle"); |
1274 } | 1274 } |
1275 } | 1275 } |
1276 #else | 1276 #else |
1420 { | 1420 { |
1421 string_vector retval; | 1421 string_vector retval; |
1422 | 1422 |
1423 if (! curl.mkdir (dir, false)) | 1423 if (! curl.mkdir (dir, false)) |
1424 warning ("__ftp_mput__: can not create the remote directory ""%s""", | 1424 warning ("__ftp_mput__: can not create the remote directory ""%s""", |
1425 (base.length() == 0 ? dir : base + | 1425 (base.length () == 0 ? dir : base + |
1426 file_ops::dir_sep_str () + dir).c_str ()); | 1426 file_ops::dir_sep_str () + dir).c_str ()); |
1427 | 1427 |
1428 curl.cwd (dir); | 1428 curl.cwd (dir); |
1429 | 1429 |
1430 if (! error_state) | 1430 if (! error_state) |
1431 { | 1431 { |
1432 unwind_protect_safe frame; | 1432 unwind_protect_safe frame; |
1433 | 1433 |
1434 frame.add_fcn (reset_path, curl); | 1434 frame.add_fcn (reset_path, curl); |
1435 | 1435 |
1436 std::string realdir = base.length() == 0 ? dir : base + | 1436 std::string realdir = base.length () == 0 ? dir : base + |
1437 file_ops::dir_sep_str () + dir; | 1437 file_ops::dir_sep_str () + dir; |
1438 | 1438 |
1439 dir_entry dirlist (realdir); | 1439 dir_entry dirlist (realdir); |
1440 | 1440 |
1441 if (dirlist) | 1441 if (dirlist) |
1467 break; | 1467 break; |
1468 } | 1468 } |
1469 else | 1469 else |
1470 { | 1470 { |
1471 // FIXME Does ascii mode need to be flagged here? | 1471 // FIXME Does ascii mode need to be flagged here? |
1472 std::ifstream ifile (realfile.c_str(), std::ios::in | | 1472 std::ifstream ifile (realfile.c_str (), std::ios::in | |
1473 std::ios::binary); | 1473 std::ios::binary); |
1474 | 1474 |
1475 if (! ifile.is_open ()) | 1475 if (! ifile.is_open ()) |
1476 { | 1476 { |
1477 error ("__ftp_mput__: unable to open file ""%s""", | 1477 error ("__ftp_mput__: unable to open file ""%s""", |
1490 } | 1490 } |
1491 } | 1491 } |
1492 } | 1492 } |
1493 else | 1493 else |
1494 error ("__ftp_mput__: can not read the directory ""%s""", | 1494 error ("__ftp_mput__: can not read the directory ""%s""", |
1495 realdir.c_str()); | 1495 realdir.c_str ()); |
1496 } | 1496 } |
1497 | 1497 |
1498 return retval; | 1498 return retval; |
1499 } | 1499 } |
1500 #endif | 1500 #endif |
1545 break; | 1545 break; |
1546 } | 1546 } |
1547 else | 1547 else |
1548 { | 1548 { |
1549 // FIXME Does ascii mode need to be flagged here? | 1549 // FIXME Does ascii mode need to be flagged here? |
1550 std::ifstream ifile (file.c_str(), std::ios::in | | 1550 std::ifstream ifile (file.c_str (), std::ios::in | |
1551 std::ios::binary); | 1551 std::ios::binary); |
1552 | 1552 |
1553 if (! ifile.is_open ()) | 1553 if (! ifile.is_open ()) |
1554 { | 1554 { |
1555 error ("__ftp_mput__: unable to open file"); | 1555 error ("__ftp_mput__: unable to open file"); |
1591 std::string msg; | 1591 std::string msg; |
1592 int status = octave_mkdir (dir, 0777, msg); | 1592 int status = octave_mkdir (dir, 0777, msg); |
1593 | 1593 |
1594 if (status < 0) | 1594 if (status < 0) |
1595 error ("__ftp_mget__: can't create directory %s%s%s. %s", | 1595 error ("__ftp_mget__: can't create directory %s%s%s. %s", |
1596 target.c_str(), sep.c_str(), dir.c_str(), msg.c_str()); | 1596 target.c_str (), sep.c_str (), dir.c_str (), msg.c_str ()); |
1597 } | 1597 } |
1598 | 1598 |
1599 if (! error_state) | 1599 if (! error_state) |
1600 { | 1600 { |
1601 curl.cwd (dir); | 1601 curl.cwd (dir); |
1619 if (fisdir) | 1619 if (fisdir) |
1620 getallfiles (curl, sv(i), target + dir + sep); | 1620 getallfiles (curl, sv(i), target + dir + sep); |
1621 else | 1621 else |
1622 { | 1622 { |
1623 std::string realfile = target + dir + sep + sv(i); | 1623 std::string realfile = target + dir + sep + sv(i); |
1624 std::ofstream ofile (realfile.c_str(), | 1624 std::ofstream ofile (realfile.c_str (), |
1625 std::ios::out | | 1625 std::ios::out | |
1626 std::ios::binary); | 1626 std::ios::binary); |
1627 | 1627 |
1628 if (! ofile.is_open ()) | 1628 if (! ofile.is_open ()) |
1629 { | 1629 { |
1697 | 1697 |
1698 if (fisdir) | 1698 if (fisdir) |
1699 getallfiles (curl, sv(i), target); | 1699 getallfiles (curl, sv(i), target); |
1700 else | 1700 else |
1701 { | 1701 { |
1702 std::ofstream ofile ((target + sv(i)).c_str(), | 1702 std::ofstream ofile ((target + sv(i)).c_str (), |
1703 std::ios::out | | 1703 std::ios::out | |
1704 std::ios::binary); | 1704 std::ios::binary); |
1705 | 1705 |
1706 if (! ofile.is_open ()) | 1706 if (! ofile.is_open ()) |
1707 { | 1707 { |