Mercurial > hg > xemacs-beta
comparison lib-src/etags.c @ 410:de805c49cfc1 r21-2-35
Import from CVS: tag r21-2-35
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:19:21 +0200 |
parents | 2f8bb876ab1d |
children | 697ef44129c6 |
comparison
equal
deleted
inserted
replaced
409:301b9ebbdf3b | 410:de805c49cfc1 |
---|---|
57 | 57 |
58 #ifndef _GNU_SOURCE | 58 #ifndef _GNU_SOURCE |
59 # define _GNU_SOURCE 1 /* enables some compiler checks on GNU */ | 59 # define _GNU_SOURCE 1 /* enables some compiler checks on GNU */ |
60 #endif | 60 #endif |
61 | 61 |
62 #ifdef MSDOS | 62 #ifdef WIN32_NATIVE |
63 # undef MSDOS | |
64 # define MSDOS TRUE | |
65 # include <fcntl.h> | |
66 # include <sys/param.h> | |
67 # include <io.h> | |
68 # ifndef HAVE_CONFIG_H | |
69 # define DOS_NT | |
70 # include <sys/config.h> | |
71 # endif | |
72 #else | |
73 # define MSDOS FALSE | |
74 #endif /* MSDOS */ | |
75 | |
76 #ifdef WINDOWSNT | |
77 # include <stdlib.h> | 63 # include <stdlib.h> |
78 # include <fcntl.h> | 64 # include <fcntl.h> |
79 # include <string.h> | 65 # include <string.h> |
80 # include <direct.h> | 66 # include <direct.h> |
81 # include <io.h> | 67 # include <io.h> |
82 # define MAXPATHLEN _MAX_PATH | 68 # define MAXPATHLEN _MAX_PATH |
83 # ifdef HAVE_CONFIG_H | |
84 # undef HAVE_NTGUI | |
85 # else | |
86 # define DOS_NT | |
87 # endif /* not HAVE_CONFIG_H */ | |
88 # ifndef HAVE_GETCWD | 69 # ifndef HAVE_GETCWD |
89 # define HAVE_GETCWD | 70 # define HAVE_GETCWD |
90 # endif /* undef HAVE_GETCWD */ | 71 # endif /* undef HAVE_GETCWD */ |
91 #else /* !WINDOWSNT */ | 72 #else /* !WIN32_NATIVE */ |
92 # ifdef STDC_HEADERS | 73 # ifdef STDC_HEADERS |
93 # include <stdlib.h> | 74 # include <stdlib.h> |
94 # include <string.h> | 75 # include <string.h> |
95 # else | 76 # else |
96 extern char *getenv (); | 77 extern char *getenv (); |
97 # endif | 78 # endif |
98 #endif /* !WINDOWSNT */ | 79 #endif /* !WIN32_NATIVE */ |
99 | 80 |
100 #ifdef HAVE_UNISTD_H | 81 #ifdef HAVE_UNISTD_H |
101 # include <unistd.h> | 82 # include <unistd.h> |
102 #else | 83 #else |
103 # if defined (HAVE_GETCWD) && !WINDOWSNT | 84 # if defined (HAVE_GETCWD) && !defined (WIN32_NATIVE) |
104 extern char *getcwd (char *buf, size_t size); | 85 extern char *getcwd (char *buf, size_t size); |
105 # endif | 86 # endif |
106 #endif /* HAVE_UNISTD_H */ | 87 #endif /* HAVE_UNISTD_H */ |
107 | 88 |
108 #include <stdio.h> | 89 #include <stdio.h> |
887 linebuffer filename_lb; | 868 linebuffer filename_lb; |
888 #ifdef VMS | 869 #ifdef VMS |
889 bool got_err; | 870 bool got_err; |
890 #endif | 871 #endif |
891 | 872 |
892 #ifdef DOS_NT | 873 #ifdef WIN32_NATIVE |
893 _fmode = O_BINARY; /* all of files are treated as binary files */ | 874 _fmode = O_BINARY; /* all of files are treated as binary files */ |
894 #endif /* DOS_NT */ | 875 #endif /* WIN32_NATIVE */ |
895 | 876 |
896 progname = argv[0]; | 877 progname = argv[0]; |
897 nincluded_files = 0; | 878 nincluded_files = 0; |
898 included_files = xnew (argc, char *); | 879 included_files = xnew (argc, char *); |
899 current_arg = 0; | 880 current_arg = 0; |
1073 if (!CTAGS) | 1054 if (!CTAGS) |
1074 { | 1055 { |
1075 if (streq (tagfile, "-")) | 1056 if (streq (tagfile, "-")) |
1076 { | 1057 { |
1077 tagf = stdout; | 1058 tagf = stdout; |
1078 #ifdef DOS_NT | 1059 #ifdef WIN32_NATIVE |
1079 /* Switch redirected `stdout' to binary mode (setting `_fmode' | 1060 /* Switch redirected `stdout' to binary mode (setting `_fmode' |
1080 doesn't take effect until after `stdout' is already open). */ | 1061 doesn't take effect until after `stdout' is already open). */ |
1081 if (!isatty (fileno (stdout))) | 1062 if (!isatty (fileno (stdout))) |
1082 setmode (fileno (stdout), O_BINARY); | 1063 setmode (fileno (stdout), O_BINARY); |
1083 #endif /* DOS_NT */ | 1064 #endif /* WIN32_NATIVE */ |
1084 } | 1065 } |
1085 else | 1066 else |
1086 tagf = fopen (tagfile, append_to_tagfile ? "a" : "w"); | 1067 tagf = fopen (tagfile, append_to_tagfile ? "a" : "w"); |
1087 if (tagf == NULL) | 1068 if (tagf == NULL) |
1088 pfatal (tagfile); | 1069 pfatal (tagfile); |
1208 { | 1189 { |
1209 compressor *compr; | 1190 compressor *compr; |
1210 char *slash, *suffix; | 1191 char *slash, *suffix; |
1211 | 1192 |
1212 /* This relies on FN to be after canonicalize_filename, | 1193 /* This relies on FN to be after canonicalize_filename, |
1213 so we don't need to consider backslashes on DOS_NT. */ | 1194 so we don't need to consider backslashes on WIN32_NATIVE. */ |
1214 slash = etags_strrchr (file, '/'); | 1195 slash = etags_strrchr (file, '/'); |
1215 suffix = etags_strrchr (file, '.'); | 1196 suffix = etags_strrchr (file, '.'); |
1216 if (suffix == NULL || suffix < slash) | 1197 if (suffix == NULL || suffix < slash) |
1217 return NULL; | 1198 return NULL; |
1218 if (extptr != NULL) | 1199 if (extptr != NULL) |
1219 *extptr = suffix; | 1200 *extptr = suffix; |
1220 suffix += 1; | 1201 suffix += 1; |
1221 /* Let those poor souls who live with DOS 8+3 file name limits get | 1202 /* Let those poor souls who live with DOS 8+3 file name limits get |
1222 some solace by treating foo.cgz as if it were foo.c.gz, etc. | 1203 some solace by treating foo.cgz as if it were foo.c.gz, etc. |
1223 Only the first do loop is run if not MSDOS */ | 1204 */ |
1224 do | 1205 do |
1225 { | 1206 { |
1226 for (compr = compressors; compr->suffix != NULL; compr++) | 1207 for (compr = compressors; compr->suffix != NULL; compr++) |
1227 if (streq (compr->suffix, suffix)) | 1208 if (streq (compr->suffix, suffix)) |
1228 return compr; | 1209 return compr; |
1229 if (!MSDOS) | 1210 if (1) /* !MSDOS */ |
1230 break; /* do it only once: not really a loop */ | 1211 break; /* do it only once: not really a loop */ |
1231 if (extptr != NULL) | 1212 if (extptr != NULL) |
1232 *extptr = ++suffix; | 1213 *extptr = ++suffix; |
1233 } while (*suffix != '\0'); | 1214 } while (*suffix != '\0'); |
1234 return NULL; | 1215 return NULL; |
1371 for (compr = compressors; compr->suffix != NULL; compr++) | 1352 for (compr = compressors; compr->suffix != NULL; compr++) |
1372 { | 1353 { |
1373 compressed_name = concat (file, ".", compr->suffix); | 1354 compressed_name = concat (file, ".", compr->suffix); |
1374 if (stat (compressed_name, &stat_buf) != 0) | 1355 if (stat (compressed_name, &stat_buf) != 0) |
1375 { | 1356 { |
1376 if (MSDOS) | 1357 /* XEmacs: delete MSDOS code */ |
1377 { | |
1378 char *suf = compressed_name + strlen (file); | |
1379 size_t suflen = strlen (compr->suffix) + 1; | |
1380 for ( ; suf[1]; suf++, suflen--) | |
1381 { | |
1382 memmove (suf, suf + 1, suflen); | |
1383 if (stat (compressed_name, &stat_buf) == 0) | |
1384 { | |
1385 real_name = compressed_name; | |
1386 break; | |
1387 } | |
1388 } | |
1389 if (real_name != NULL) | |
1390 break; | |
1391 } /* MSDOS */ | |
1392 free (compressed_name); | 1358 free (compressed_name); |
1393 compressed_name = NULL; | 1359 compressed_name = NULL; |
1394 } | 1360 } |
1395 else | 1361 else |
1396 { | 1362 { |
5029 if (c == '\n') | 4995 if (c == '\n') |
5030 { | 4996 { |
5031 if (p > buffer && p[-1] == '\r') | 4997 if (p > buffer && p[-1] == '\r') |
5032 { | 4998 { |
5033 p -= 1; | 4999 p -= 1; |
5034 #ifdef DOS_NT | 5000 #ifdef WIN32_NATIVE |
5035 /* Assume CRLF->LF translation will be performed by Emacs | 5001 /* Assume CRLF->LF translation will be performed by Emacs |
5036 when loading this file, so CRs won't appear in the buffer. | 5002 when loading this file, so CRs won't appear in the buffer. |
5037 It would be cleaner to compensate within Emacs; | 5003 It would be cleaner to compensate within Emacs; |
5038 however, Emacs does not know how many CRs were deleted | 5004 however, Emacs does not know how many CRs were deleted |
5039 before any given point in the file. */ | 5005 before any given point in the file. */ |
5285 | 5251 |
5286 canonicalize_filename (path); | 5252 canonicalize_filename (path); |
5287 return path; | 5253 return path; |
5288 | 5254 |
5289 #else /* not HAVE_GETCWD */ | 5255 #else /* not HAVE_GETCWD */ |
5290 #ifdef MSDOS | |
5291 char *p, path[MAXPATHLEN + 1]; /* Fixed size is safe on MSDOS. */ | |
5292 | |
5293 getwd (path); | |
5294 | |
5295 for (p = path; *p != '\0'; p++) | |
5296 if (*p == '\\') | |
5297 *p = '/'; | |
5298 else | |
5299 *p = lowcase (*p); | |
5300 | |
5301 return strdup (path); | |
5302 #else /* not MSDOS */ | |
5303 linebuffer path; | 5256 linebuffer path; |
5304 FILE *pipe; | 5257 FILE *pipe; |
5305 | 5258 |
5306 initbuffer (&path); | 5259 initbuffer (&path); |
5307 pipe = (FILE *) popen ("pwd 2>/dev/null", "r"); | 5260 pipe = (FILE *) popen ("pwd 2>/dev/null", "r"); |
5308 if (pipe == NULL || readline_internal (&path, pipe) == 0) | 5261 if (pipe == NULL || readline_internal (&path, pipe) == 0) |
5309 pfatal ("pwd"); | 5262 pfatal ("pwd"); |
5310 pclose (pipe); | 5263 pclose (pipe); |
5311 | 5264 |
5312 return path.buffer; | 5265 return path.buffer; |
5313 #endif /* not MSDOS */ | |
5314 #endif /* not HAVE_GETCWD */ | 5266 #endif /* not HAVE_GETCWD */ |
5315 } | 5267 } |
5316 | 5268 |
5317 /* Return a newly allocated string containing the file name of FILE | 5269 /* Return a newly allocated string containing the file name of FILE |
5318 relative to the absolute directory DIR (which should end with a slash). */ | 5270 relative to the absolute directory DIR (which should end with a slash). */ |
5328 fp = afn; | 5280 fp = afn; |
5329 dp = dir; | 5281 dp = dir; |
5330 while (*fp++ == *dp++) | 5282 while (*fp++ == *dp++) |
5331 continue; | 5283 continue; |
5332 fp--, dp--; /* back to the first differing char */ | 5284 fp--, dp--; /* back to the first differing char */ |
5333 #ifdef DOS_NT | 5285 #ifdef WIN32_NATIVE |
5334 if (fp == afn && afn[0] != '/') /* cannot build a relative name */ | 5286 if (fp == afn && afn[0] != '/') /* cannot build a relative name */ |
5335 return afn; | 5287 return afn; |
5336 #endif | 5288 #endif |
5337 do /* look at the equal chars until '/' */ | 5289 do /* look at the equal chars until '/' */ |
5338 fp--, dp--; | 5290 fp--, dp--; |
5362 { | 5314 { |
5363 char *slashp, *cp, *res; | 5315 char *slashp, *cp, *res; |
5364 | 5316 |
5365 if (filename_is_absolute (file)) | 5317 if (filename_is_absolute (file)) |
5366 res = savestr (file); | 5318 res = savestr (file); |
5367 #ifdef DOS_NT | 5319 #ifdef WIN32_NATIVE |
5368 /* We don't support non-absolute file names with a drive | 5320 /* We don't support non-absolute file names with a drive |
5369 letter, like `d:NAME' (it's too much hassle). */ | 5321 letter, like `d:NAME' (it's too much hassle). */ |
5370 else if (file[1] == ':') | 5322 else if (file[1] == ':') |
5371 fatal ("%s: relative file names with drive letters not supported", file); | 5323 fatal ("%s: relative file names with drive letters not supported", file); |
5372 #endif | 5324 #endif |
5386 do | 5338 do |
5387 cp--; | 5339 cp--; |
5388 while (cp >= res && !filename_is_absolute (cp)); | 5340 while (cp >= res && !filename_is_absolute (cp)); |
5389 if (cp < res) | 5341 if (cp < res) |
5390 cp = slashp; /* the absolute name begins with "/.." */ | 5342 cp = slashp; /* the absolute name begins with "/.." */ |
5391 #ifdef DOS_NT | 5343 #ifdef WIN32_NATIVE |
5392 /* Under MSDOS and NT we get `d:/NAME' as absolute | 5344 /* Under Windows we get `d:/NAME' as absolute |
5393 file name, so the luser could say `d:/../NAME'. | 5345 file name, so the luser could say `d:/../NAME'. |
5394 We silently treat this as `d:/NAME'. */ | 5346 We silently treat this as `d:/NAME'. */ |
5395 else if (cp[0] != '/') | 5347 else if (cp[0] != '/') |
5396 cp = slashp; | 5348 cp = slashp; |
5397 #endif | 5349 #endif |
5442 static bool | 5394 static bool |
5443 filename_is_absolute (fn) | 5395 filename_is_absolute (fn) |
5444 char *fn; | 5396 char *fn; |
5445 { | 5397 { |
5446 return (fn[0] == '/' | 5398 return (fn[0] == '/' |
5447 #ifdef DOS_NT | 5399 #ifdef WIN32_NATIVE |
5448 || (isalpha(fn[0]) && fn[1] == ':' && fn[2] == '/') | 5400 || (isalpha(fn[0]) && fn[1] == ':' && fn[2] == '/') |
5449 #endif | 5401 #endif |
5450 ); | 5402 ); |
5451 } | 5403 } |
5452 | 5404 |
5453 /* Translate backslashes into slashes. Works in place. */ | 5405 /* Translate backslashes into slashes. Works in place. */ |
5454 static void | 5406 static void |
5455 canonicalize_filename (fn) | 5407 canonicalize_filename (fn) |
5456 register char *fn; | 5408 register char *fn; |
5457 { | 5409 { |
5458 #ifdef DOS_NT | 5410 #ifdef WIN32_NATIVE |
5459 /* Canonicalize drive letter case. */ | 5411 /* Canonicalize drive letter case. */ |
5460 if (islower (fn[0]) && fn[1] == ':') | 5412 if (islower (fn[0]) && fn[1] == ':') |
5461 fn[0] = toupper (fn[0]); | 5413 fn[0] = toupper (fn[0]); |
5462 /* Convert backslashes to slashes. */ | 5414 /* Convert backslashes to slashes. */ |
5463 for (; *fn != '\0'; fn++) | 5415 for (; *fn != '\0'; fn++) |