Mercurial > hg > octave-lyh
comparison src/utils.cc @ 686:0faebdd7df57
[project @ 1994-09-09 21:09:24 by jwe]
author | jwe |
---|---|
date | Fri, 09 Sep 1994 21:10:43 +0000 |
parents | 93c63deed7aa |
children | d7c4962ec7a0 |
comparison
equal
deleted
inserted
replaced
685:eb88bf09a645 | 686:0faebdd7df57 |
---|---|
87 | 87 |
88 #include "procstream.h" | 88 #include "procstream.h" |
89 #include "user-prefs.h" | 89 #include "user-prefs.h" |
90 #include "variables.h" | 90 #include "variables.h" |
91 #include "dirfns.h" | 91 #include "dirfns.h" |
92 #include "defun.h" | |
92 #include "error.h" | 93 #include "error.h" |
94 #include "help.h" | |
93 #include "gripes.h" | 95 #include "gripes.h" |
94 #include "pager.h" | 96 #include "pager.h" |
95 #include "utils.h" | 97 #include "utils.h" |
96 #include "input.h" | 98 #include "input.h" |
97 #include "octave.h" | 99 #include "octave.h" |
614 } | 616 } |
615 | 617 |
616 // See if the given file is in the path. | 618 // See if the given file is in the path. |
617 | 619 |
618 char * | 620 char * |
621 search_path_for_file (const char *path, const char *name) | |
622 { | |
623 char *retval = 0; | |
624 | |
625 char *tmp = kpse_path_search (path, name, kpathsea_true); | |
626 | |
627 if (tmp) | |
628 { | |
629 retval = make_absolute (tmp, the_current_working_directory); | |
630 free (tmp); | |
631 } | |
632 | |
633 return retval; | |
634 } | |
635 | |
636 DEFUN ("file_in_path", Ffile_in_pat, Sfile_in_path, 3, 1, | |
637 "file_in_path (PATH, NAME)") | |
638 { | |
639 Octave_object retval; | |
640 | |
641 DEFINE_ARGV("file_in_path"); | |
642 | |
643 if (argc == 3) | |
644 { | |
645 char *fname = search_path_for_file (argv[1], argv[2]); | |
646 | |
647 if (fname) | |
648 retval = fname; | |
649 else | |
650 retval = Matrix (); | |
651 } | |
652 else | |
653 print_usage ("file_in_path"); | |
654 | |
655 DELETE_ARGV; | |
656 | |
657 return retval; | |
658 } | |
659 | |
660 | |
661 char * | |
619 file_in_path (const char *name, const char *suffix) | 662 file_in_path (const char *name, const char *suffix) |
620 { | 663 { |
621 char *retval = 0; | 664 char *retval = 0; |
622 | 665 |
623 char *nm = strsave (name); | 666 char *nm = strsave (name); |
667 | |
624 if (suffix) | 668 if (suffix) |
625 { | 669 { |
626 char *tmp = nm; | 670 char *tmp = nm; |
627 nm = strconcat (tmp, suffix); | 671 nm = strconcat (tmp, suffix); |
628 delete [] tmp; | 672 delete [] tmp; |
629 } | 673 } |
630 | 674 |
631 if (! the_current_working_directory) | 675 if (! the_current_working_directory) |
632 get_working_directory ("file_in_path"); | 676 get_working_directory ("file_in_path"); |
633 | 677 |
634 char *tmp = kpse_path_search (user_pref.loadpath, nm, kpathsea_true); | 678 retval = search_path_for_file (user_pref.loadpath, nm); |
635 | 679 |
636 if (tmp) | 680 delete [] nm; |
637 { | |
638 retval = make_absolute (tmp, the_current_working_directory); | |
639 free (tmp); | |
640 delete [] nm; | |
641 } | |
642 | 681 |
643 return retval; | 682 return retval; |
644 } | 683 } |
645 | 684 |
646 // See if there is an function file in the path. If so, return the | 685 // See if there is an function file in the path. If so, return the |