comparison liboctave/kpse.cc @ 10411:479cc8a0a846

use gnulib namespace
author John W. Eaton <jwe@octave.org>
date Mon, 15 Mar 2010 15:57:23 -0400
parents 07ebe522dac2
children 6ccf1130f23c
comparison
equal deleted inserted replaced
10410:b3ec24dc305a 10411:479cc8a0a846
181 #define KPSE_DEBUG_SEARCH 5 /* searches */ 181 #define KPSE_DEBUG_SEARCH 5 /* searches */
182 #define KPSE_DEBUG_VARS 6 /* variable values */ 182 #define KPSE_DEBUG_VARS 6 /* variable values */
183 #define KPSE_LAST_DEBUG KPSE_DEBUG_VARS 183 #define KPSE_LAST_DEBUG KPSE_DEBUG_VARS
184 184
185 /* A printf for the debugging. */ 185 /* A printf for the debugging. */
186 #define DEBUGF_START() do { fputs ("kdebug:", stderr) 186 #define DEBUGF_START() do { gnulib::fputs ("kdebug:", stderr)
187 #define DEBUGF_END() fflush (stderr); } while (0) 187 #define DEBUGF_END() fflush (stderr); } while (0)
188 188
189 #define DEBUGF(str) \ 189 #define DEBUGF(str) \
190 DEBUGF_START (); fputs (str, stderr); DEBUGF_END () 190 DEBUGF_START (); gnulib::fputs (str, stderr); DEBUGF_END ()
191 #define DEBUGF1(str, e1) \ 191 #define DEBUGF1(str, e1) \
192 DEBUGF_START (); fprintf (stderr, str, e1); DEBUGF_END () 192 DEBUGF_START (); gnulib::fprintf (stderr, str, e1); DEBUGF_END ()
193 #define DEBUGF2(str, e1, e2) \ 193 #define DEBUGF2(str, e1, e2) \
194 DEBUGF_START (); fprintf (stderr, str, e1, e2); DEBUGF_END () 194 DEBUGF_START (); gnulib::fprintf (stderr, str, e1, e2); DEBUGF_END ()
195 #define DEBUGF3(str, e1, e2, e3) \ 195 #define DEBUGF3(str, e1, e2, e3) \
196 DEBUGF_START (); fprintf (stderr, str, e1, e2, e3); DEBUGF_END () 196 DEBUGF_START (); gnulib::fprintf (stderr, str, e1, e2, e3); DEBUGF_END ()
197 #define DEBUGF4(str, e1, e2, e3, e4) \ 197 #define DEBUGF4(str, e1, e2, e3, e4) \
198 DEBUGF_START (); fprintf (stderr, str, e1, e2, e3, e4); DEBUGF_END () 198 DEBUGF_START (); gnulib::fprintf (stderr, str, e1, e2, e3, e4); DEBUGF_END ()
199 199
200 #undef fopen 200 #undef fopen
201 #define fopen kpse_fopen_trace 201 #define fopen kpse_fopen_trace
202 static FILE *fopen (const char *filename, const char *mode); 202 static FILE *fopen (const char *filename, const char *mode);
203 203
256 with status `errno', because that might be 256, which would mean 256 with status `errno', because that might be 256, which would mean
257 success (exit statuses are truncated to eight bits). */ 257 success (exit statuses are truncated to eight bits). */
258 #define FATAL_PERROR(str) \ 258 #define FATAL_PERROR(str) \
259 do \ 259 do \
260 { \ 260 { \
261 fputs ("pathsearch: ", stderr); \ 261 gnulib::fputs ("pathsearch: ", stderr); \
262 perror (str); exit (EXIT_FAILURE); \ 262 perror (str); exit (EXIT_FAILURE); \
263 } \ 263 } \
264 while (0) 264 while (0)
265 265
266 #define FATAL(str) \ 266 #define FATAL(str) \
267 do \ 267 do \
268 { \ 268 { \
269 fputs ("pathsearch: fatal: ", stderr); \ 269 gnulib::fputs ("pathsearch: fatal: ", stderr); \
270 fputs (str, stderr); \ 270 gnulib::fputs (str, stderr); \
271 fputs (".\n", stderr); \ 271 gnulib::fputs (".\n", stderr); \
272 exit (1); \ 272 exit (1); \
273 } \ 273 } \
274 while (0) 274 while (0)
275 275
276 #ifndef WIN32 276 #ifndef WIN32
387 #ifdef KPSE_DEBUG 387 #ifdef KPSE_DEBUG
388 if (KPSE_DEBUG_P (KPSE_DEBUG_HASH)) 388 if (KPSE_DEBUG_P (KPSE_DEBUG_HASH))
389 { 389 {
390 DEBUGF1 ("hash_lookup (%s) =>", key.c_str ()); 390 DEBUGF1 ("hash_lookup (%s) =>", key.c_str ());
391 if (ret.empty ()) 391 if (ret.empty ())
392 fputs (" (nil)\n", stderr); 392 gnulib::fputs (" (nil)\n", stderr);
393 else 393 else
394 { 394 {
395 int len = ret.length (); 395 int len = ret.length ();
396 for (int i = 0; i < len; i++) 396 for (int i = 0; i < len; i++)
397 { 397 {
398 putc (' ', stderr); 398 gnulib::putc (' ', stderr);
399 fputs (ret[i].c_str (), stderr); 399 gnulib::fputs (ret[i].c_str (), stderr);
400 } 400 }
401 putc ('\n', stderr); 401 gnulib::putc ('\n', stderr);
402 } 402 }
403 fflush (stderr); 403 fflush (stderr);
404 } 404 }
405 #endif 405 #endif
406 406
673 { 673 {
674 std::string filename = filenames[e]; 674 std::string filename = filenames[e];
675 675
676 /* Only record absolute filenames, for privacy. */ 676 /* Only record absolute filenames, for privacy. */
677 if (log_file && kpse_absolute_p (filename.c_str (), false)) 677 if (log_file && kpse_absolute_p (filename.c_str (), false))
678 fprintf (log_file, "%lu %s\n", 678 gnulib::fprintf (log_file, "%lu %s\n",
679 static_cast<unsigned long> (time (0)), 679 static_cast<unsigned long> (time (0)),
680 filename.c_str ()); 680 filename.c_str ());
681 681
682 /* And show them online, if debugging. We've already started 682 /* And show them online, if debugging. We've already started
683 the debugging line in `search', where this is called, so 683 the debugging line in `search', where this is called, so
684 just print the filename here, don't use DEBUGF. */ 684 just print the filename here, don't use DEBUGF. */
685 if (KPSE_DEBUG_P (KPSE_DEBUG_SEARCH)) 685 if (KPSE_DEBUG_P (KPSE_DEBUG_SEARCH))
686 fputs (filename.c_str (), stderr); 686 gnulib::fputs (filename.c_str (), stderr);
687 } 687 }
688 } 688 }
689 } 689 }
690 690
691 /* Concatenate each element in DIRS with NAME (assume each ends with a 691 /* Concatenate each element in DIRS with NAME (assume each ends with a
871 DEBUGF1 ("search (%s) =>", original_name.c_str ()); 871 DEBUGF1 ("search (%s) =>", original_name.c_str ());
872 872
873 log_search (ret_list); 873 log_search (ret_list);
874 874
875 if (KPSE_DEBUG_P (KPSE_DEBUG_SEARCH)) 875 if (KPSE_DEBUG_P (KPSE_DEBUG_SEARCH))
876 putc ('\n', stderr); 876 gnulib::putc ('\n', stderr);
877 } 877 }
878 878
879 return ret_list; 879 return ret_list;
880 } 880 }
881 881
1038 { 1038 {
1039 string_vector ret_list; 1039 string_vector ret_list;
1040 1040
1041 if (KPSE_DEBUG_P (KPSE_DEBUG_SEARCH)) 1041 if (KPSE_DEBUG_P (KPSE_DEBUG_SEARCH))
1042 { 1042 {
1043 fputs ("start find_first_of ((", stderr); 1043 gnulib::fputs ("start find_first_of ((", stderr);
1044 1044
1045 int len = names.length (); 1045 int len = names.length ();
1046 1046
1047 for (int i = 0; i < len; i++) 1047 for (int i = 0; i < len; i++)
1048 { 1048 {
1049 if (i == 0) 1049 if (i == 0)
1050 fputs (names[i].c_str (), stderr); 1050 gnulib::fputs (names[i].c_str (), stderr);
1051 else 1051 else
1052 fprintf (stderr, ", %s", names[i].c_str ()); 1052 gnulib::fprintf (stderr, ", %s", names[i].c_str ());
1053 } 1053 }
1054 1054
1055 fprintf (stderr, "), path=%s, must_exist=%d).\n", 1055 gnulib::fprintf (stderr, "), path=%s, must_exist=%d).\n",
1056 path.c_str (), must_exist); 1056 path.c_str (), must_exist);
1057 } 1057 }
1058 1058
1059 for (int i = 0; i < names.length (); i++) 1059 for (int i = 0; i < names.length (); i++)
1060 { 1060 {
1061 std::string name = names[i]; 1061 std::string name = names[i];
1087 /* Record the filenames we found, if desired. And wrap them in a 1087 /* Record the filenames we found, if desired. And wrap them in a
1088 debugging line if we're doing that. */ 1088 debugging line if we're doing that. */
1089 1089
1090 if (KPSE_DEBUG_P (KPSE_DEBUG_SEARCH)) 1090 if (KPSE_DEBUG_P (KPSE_DEBUG_SEARCH))
1091 { 1091 {
1092 fputs ("find_first_of (", stderr); 1092 gnulib::fputs ("find_first_of (", stderr);
1093 1093
1094 int len = names.length (); 1094 int len = names.length ();
1095 1095
1096 for (int i = 0; i < len; i++) 1096 for (int i = 0; i < len; i++)
1097 { 1097 {
1098 if (i == 0) 1098 if (i == 0)
1099 fputs (names[i].c_str (), stderr); 1099 gnulib::fputs (names[i].c_str (), stderr);
1100 else 1100 else
1101 fprintf (stderr, ", %s", names[i].c_str ()); 1101 gnulib::fprintf (stderr, ", %s", names[i].c_str ());
1102 } 1102 }
1103 fputs (") =>", stderr); 1103
1104 gnulib::fputs (") =>", stderr);
1104 } 1105 }
1105 1106
1106 log_search (ret_list); 1107 log_search (ret_list);
1107 1108
1108 if (KPSE_DEBUG_P (KPSE_DEBUG_SEARCH)) 1109 if (KPSE_DEBUG_P (KPSE_DEBUG_SEARCH))
1109 putc ('\n', stderr); 1110 gnulib::putc ('\n', stderr);
1110 } 1111 }
1111 1112
1112 return ret_list; 1113 return ret_list;
1113 } 1114 }
1114 1115
2218 FindClose (hnd); 2219 FindClose (hnd);
2219 2220
2220 #else /* not WIN32 */ 2221 #else /* not WIN32 */
2221 2222
2222 /* If we can't open it, quit. */ 2223 /* If we can't open it, quit. */
2223 dir = opendir (name.c_str ()); 2224 dir = gnulib::opendir (name.c_str ());
2224 2225
2225 if (! dir) 2226 if (! dir)
2226 return; 2227 return;
2227 2228
2228 /* Include top level before subdirectories, if nothing to match. */ 2229 /* Include top level before subdirectories, if nothing to match. */
2379 DEBUGF1 ("path element %s =>", elt.c_str ()); 2380 DEBUGF1 ("path element %s =>", elt.c_str ());
2380 if (ret) 2381 if (ret)
2381 { 2382 {
2382 str_llist_elt_type *e; 2383 str_llist_elt_type *e;
2383 for (e = *ret; e; e = STR_LLIST_NEXT (*e)) 2384 for (e = *ret; e; e = STR_LLIST_NEXT (*e))
2384 fprintf (stderr, " %s", (STR_LLIST (*e)).c_str ()); 2385 gnulib::fprintf (stderr, " %s", (STR_LLIST (*e)).c_str ());
2385 } 2386 }
2386 putc ('\n', stderr); 2387 gnulib::putc ('\n', stderr);
2387 fflush (stderr); 2388 fflush (stderr);
2388 } 2389 }
2389 #endif /* KPSE_DEBUG */ 2390 #endif /* KPSE_DEBUG */
2390 2391
2391 return ret; 2392 return ret;
2393 2394
2394 #ifndef WIN32 2395 #ifndef WIN32
2395 void 2396 void
2396 xclosedir (DIR *d) 2397 xclosedir (DIR *d)
2397 { 2398 {
2398 #ifdef CLOSEDIR_VOID 2399 int ret = gnulib::closedir (d);
2399 closedir (d);
2400 #else
2401 int ret = closedir (d);
2402 2400
2403 if (ret != 0) 2401 if (ret != 0)
2404 FATAL ("closedir failed"); 2402 FATAL ("closedir failed");
2405 #endif
2406 } 2403 }
2407 #endif 2404 #endif
2408 2405
2409 /* Help the user discover what's going on. */ 2406 /* Help the user discover what's going on. */
2410 2407