comparison src/dirfns.cc @ 2669:c821858188b6

[project @ 1997-02-13 18:25:39 by jwe]
author jwe
date Thu, 13 Feb 1997 18:25:40 +0000
parents fda09c1e787e
children 9aeba8e006a4
comparison
equal deleted inserted replaced
2668:0d865ef7478f 2669:c821858188b6
439 439
440 return retval; 440 return retval;
441 } 441 }
442 442
443 DEFUN (readdir, args, , 443 DEFUN (readdir, args, ,
444 "readdir (NAME)\n\ 444 "[FILES, STATUS, MSG] = readdir (NAME)\n\
445 \n\ 445 \n\
446 Return an array of strings containing the list of all files in the 446 Return an array of strings containing the list of all files in the
447 named directory. If sucessful, returns 0; otherwise an error message 447 named directory in FILES, or an empty matrix if an error occurs\n\
448 is printed.") 448 \n\
449 If successful, STATUS is 0 and MSG is an empty string. Otherwise,\n\
450 STATUS is nonzero and MSG contains a system-dependent error message.")
449 { 451 {
450 octave_value_list retval; 452 octave_value_list retval;
453
454 retval(2) = string ();
455 retval(1) = -1.0;
456 retval(0) = Matrix ();
451 457
452 if (args.length () == 1) 458 if (args.length () == 1)
453 { 459 {
454 string dirname = args(0).string_value (); 460 string dirname = args(0).string_value ();
455 461
461 467
462 if (dir) 468 if (dir)
463 { 469 {
464 string_vector dirlist = dir.read (); 470 string_vector dirlist = dir.read ();
465 retval(0) = dirlist.qsort (); 471 retval(0) = dirlist.qsort ();
472 retval(1) = 0.0;
466 } 473 }
467 else 474 else
468 { 475 {
469 string msg = dir.error (); 476 retval(2) = dir.error ();
470 error ("%s", msg.c_str ());
471 } 477 }
472 } 478 }
473 } 479 }
474 else 480 else
475 print_usage ("readdir"); 481 print_usage ("readdir");
479 485
480 // XXX FIXME XXX -- should probably also allow second arg to specify 486 // XXX FIXME XXX -- should probably also allow second arg to specify
481 // mode. 487 // mode.
482 488
483 DEFUN (mkdir, args, , 489 DEFUN (mkdir, args, ,
484 "mkdir (NAME)\n\ 490 "[STATUS, MSG] = mkdir (NAME)\n\
485 \n\ 491 \n\
486 Create the directory named by NAME. If successful, returns 0;\n\ 492 Create the directory named by NAME.\n\
487 otherwise prints an error message.") 493 \n\
494 If successful, STATUS is 0 and MSG is an empty string. Otherwise,\n\
495 STATUS is nonzero and MSG contains a system-dependent error message.")
488 { 496 {
489 octave_value_list retval; 497 octave_value_list retval;
490 498
491 int status = 0; 499 retval(1) = string ();
500 retval(0) = -1.0;
492 501
493 if (args.length () == 1) 502 if (args.length () == 1)
494 { 503 {
495 string dirname = args(0).string_value (); 504 string dirname = args(0).string_value ();
496 505
497 if (error_state) 506 if (error_state)
498 gripe_wrong_type_arg ("mkdir", args(0)); 507 gripe_wrong_type_arg ("mkdir", args(0));
499 else 508 else
500 { 509 {
501 int mkdir_retval = oct_mkdir (oct_tilde_expand (dirname), 0777); 510 string msg;
502 511
503 if (mkdir_retval < 0) 512 int status = oct_mkdir (oct_tilde_expand (dirname),
504 { 513 0777, msg);
505 status = -1; 514
506 error ("%s", strerror (errno)); 515 retval(0) = (double) status;
507 } 516
517 if (status < 0)
518 retval(1) = msg;
508 } 519 }
509 } 520 }
510 else 521 else
511 print_usage ("mkdir"); 522 print_usage ("mkdir");
512 523
513 if (status == 0)
514 retval (0) = (double) status;
515
516 return retval; 524 return retval;
517 } 525 }
518 526
519 DEFUN (rmdir, args, , 527 DEFUN (rmdir, args, ,
520 "rmdir (NAME)\n\ 528 "[STATUS, MSG] = rmdir (NAME)\n\
521 \n\ 529 \n\
522 Remove the directory named by NAME. If successful, returns 0;\n\ 530 Remove the directory named by NAME.\n\
523 otherwise prints an error message.") 531 \n\
532 If successful, STATUS is 0 and MSG is an empty string. Otherwise,\n\
533 STATUS is nonzero and MSG contains a system-dependent error message.")
524 { 534 {
525 octave_value_list retval; 535 octave_value_list retval;
526 536
527 int status = 0; 537 retval(1) = string ();
538 retval(0) = -1.0;
528 539
529 if (args.length () == 1) 540 if (args.length () == 1)
530 { 541 {
531 string dirname = args(0).string_value (); 542 string dirname = args(0).string_value ();
532 543
533 if (error_state) 544 if (error_state)
534 gripe_wrong_type_arg ("rmdir", args(0)); 545 gripe_wrong_type_arg ("rmdir", args(0));
535 else 546 else
536 { 547 {
537 int rmdir_retval = oct_rmdir (oct_tilde_expand (dirname)); 548 string msg;
538 549
539 if (rmdir_retval < 0) 550 int status = oct_rmdir (oct_tilde_expand (dirname), msg);
540 { 551
541 status = -1; 552 retval(0) = (double) status;
542 error ("%s", strerror (errno)); 553
543 } 554 if (status < 0)
555 retval(1) = msg;
544 } 556 }
545 } 557 }
546 else 558 else
547 print_usage ("rmdir"); 559 print_usage ("rmdir");
548 560
549 if (status == 0)
550 retval (0) = (double) status;
551
552 return retval; 561 return retval;
553 } 562 }
554 563
555 DEFUN (rename, args, , 564 DEFUN (rename, args, ,
556 "rename (FROM, TO)\n\ 565 "[STATUS, MSG] = rename (FROM, TO)\n\
557 \n\ 566 \n\
558 Rename a file. If successful, returns 0;\n\ 567 Rename a file.\n\
559 otherwise prints an error message and returns -1.") 568 \n\
569 If successful, STATUS is 0 and MSG is an empty string. Otherwise,\n\
570 STATUS is nonzero and MSG contains a system-dependent error message.")
560 { 571 {
561 octave_value_list retval; 572 octave_value_list retval;
562 573
563 int status = 0; 574 retval(1) = string ();
575 retval(0) = -1.0;
564 576
565 if (args.length () == 2) 577 if (args.length () == 2)
566 { 578 {
567 string from = args(0).string_value (); 579 string from = args(0).string_value ();
568 580
572 { 584 {
573 string to = args(1).string_value (); 585 string to = args(1).string_value ();
574 586
575 if (error_state) 587 if (error_state)
576 gripe_wrong_type_arg ("rename", args(1)); 588 gripe_wrong_type_arg ("rename", args(1));
577 else if (oct_rename (from, to) < 0) 589 else
578 { 590 {
579 status = -1; 591 string msg;
580 error ("%s", strerror (errno)); 592
593 int status = oct_rename (from, to, msg);
594
595 retval(0) = (double) status;
596
597 if (status < 0)
598 retval(1) = msg;
581 } 599 }
582 } 600 }
583 } 601 }
584 else 602 else
585 print_usage ("rename"); 603 print_usage ("rename");
586
587 if (status == 0)
588 retval (0) = (double) status;
589 604
590 return retval; 605 return retval;
591 } 606 }
592 607
593 DEFUN (glob, args, , 608 DEFUN (glob, args, ,