00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifdef HAVE_CONFIG_H
00024 #include <config.h>
00025 #endif
00026
00027 #include <cstdlib>
00028
00029 #include <string>
00030
00031 #include "lo-utils.h"
00032 #include "oct-env.h"
00033 #include "pathsearch.h"
00034 #include "str-vec.h"
00035 #include "str-vec.h"
00036
00037 #include "kpse.cc"
00038
00039 static bool octave_kpathsea_initialized = false;
00040
00041 string_vector
00042 dir_path::elements (void)
00043 {
00044 return initialized ? pv : string_vector ();
00045 }
00046
00047 string_vector
00048 dir_path::all_directories (void)
00049 {
00050 int count = 0;
00051 string_vector retval;
00052
00053 if (initialized)
00054 {
00055 int len = pv.length ();
00056
00057 int nmax = len > 32 ? len : 32;
00058
00059 retval.resize (len);
00060
00061 for (int i = 0; i < len; i++)
00062 {
00063 str_llist_type *elt_dirs = kpse_element_dirs (pv[i]);
00064
00065 if (elt_dirs)
00066 {
00067 str_llist_elt_type *dir;
00068
00069 for (dir = *elt_dirs; dir; dir = STR_LLIST_NEXT (*dir))
00070 {
00071 const std::string elt_dir = STR_LLIST (*dir);
00072
00073 if (! elt_dir.empty ())
00074 {
00075 if (count == nmax)
00076 nmax *= 2;
00077
00078 retval.resize (nmax);
00079
00080 retval[count++] = elt_dir;
00081 }
00082 }
00083 }
00084 }
00085
00086 retval.resize (count);
00087 }
00088
00089 return retval;
00090 }
00091
00092 std::string
00093 dir_path::find_first (const std::string& nm)
00094 {
00095 return initialized ? kpse_path_search (p, nm, true) : std::string ();
00096 }
00097
00098 string_vector
00099 dir_path::find_all (const std::string& nm)
00100 {
00101 return initialized ? kpse_all_path_search (p, nm) : string_vector ();
00102 }
00103
00104 std::string
00105 dir_path::find_first_of (const string_vector& names)
00106 {
00107 return initialized
00108 ? kpse_path_find_first_of (p, names, true) : std::string ();
00109 }
00110
00111 string_vector
00112 dir_path::find_all_first_of (const string_vector& names)
00113 {
00114 return initialized
00115 ? kpse_all_path_find_first_of (p, names) : string_vector ();
00116 }
00117
00118 void
00119 dir_path::init (void)
00120 {
00121 if (! octave_kpathsea_initialized)
00122 {
00123 std::string val = octave_env::getenv ("KPATHSEA_DEBUG");
00124
00125 if (! val.empty ())
00126 kpathsea_debug |= atoi (val.c_str ());
00127
00128 octave_kpathsea_initialized = true;
00129 }
00130
00131 p = kpse_path_expand (p_default.empty ()
00132 ? p_orig : kpse_expand_default (p_orig, p_default));
00133
00134 int count = 0;
00135 for (kpse_path_iterator pi (p); pi != NPOS; pi++)
00136 count++;
00137
00138 pv.resize (count);
00139
00140 kpse_path_iterator pi (p);
00141
00142 for (int i = 0; i < count; i++)
00143 pv[i] = *pi++;
00144
00145 initialized = true;
00146 }
00147
00148
00149
00150
00151
00152