comparison lib-src/ootags.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 74fd4e045ea6
children 697ef44129c6
comparison
equal deleted inserted replaced
409:301b9ebbdf3b 410:de805c49cfc1
62 62
63 #ifndef DEBUG 63 #ifndef DEBUG
64 # define DEBUG FALSE 64 # define DEBUG FALSE
65 #endif 65 #endif
66 66
67 #ifdef MSDOS 67 #ifdef WIN32_NATIVE
68 # include <fcntl.h>
69 # include <sys/param.h>
70 # include <io.h>
71 # ifndef HAVE_CONFIG_H
72 # define DOS_NT
73 # include <sys/config.h>
74 # endif
75 #endif /* MSDOS */
76
77 #ifdef WINDOWSNT
78 # include <stdlib.h> 68 # include <stdlib.h>
79 # include <fcntl.h> 69 # include <fcntl.h>
80 # include <string.h> 70 # include <string.h>
81 # include <io.h> 71 # include <io.h>
82 # define MAXPATHLEN _MAX_PATH 72 # define MAXPATHLEN _MAX_PATH
83 # ifdef HAVE_CONFIG_H 73 # ifndef HAVE_CONFIG_H
84 # undef HAVE_NTGUI
85 # else
86 # define DOS_NT
87 # define HAVE_GETCWD 74 # define HAVE_GETCWD
88 # endif /* not HAVE_CONFIG_H */ 75 # endif /* not HAVE_CONFIG_H */
89 #endif /* WINDOWSNT */ 76 #endif /* WIN32_NATIVE */
90 77
91 #if !defined (WINDOWSNT) && defined (STDC_HEADERS) 78 #if !defined (WIN32_NATIVE) && defined (STDC_HEADERS)
92 #include <stdlib.h> 79 #include <stdlib.h>
93 #include <string.h> 80 #include <string.h>
94 #endif 81 #endif
95 82
96 #ifdef HAVE_UNISTD_H 83 #ifdef HAVE_UNISTD_H
868 linebuffer filename_lb; 855 linebuffer filename_lb;
869 #ifdef VMS 856 #ifdef VMS
870 bool got_err; 857 bool got_err;
871 #endif 858 #endif
872 859
873 #ifdef DOS_NT 860 #ifdef WIN32_NATIVE
874 _fmode = O_BINARY; /* all of files are treated as binary files */ 861 _fmode = O_BINARY; /* all of files are treated as binary files */
875 #endif /* DOS_NT */ 862 #endif /* WIN32_NATIVE */
876 863
877 progname = argv[0]; 864 progname = argv[0];
878 nincluded_files = 0; 865 nincluded_files = 0;
879 included_files = xnew (argc, char *); 866 included_files = xnew (argc, char *);
880 current_arg = 0; 867 current_arg = 0;
1062 if (!CTAGS) 1049 if (!CTAGS)
1063 { 1050 {
1064 if (streq (tagfile, "-")) 1051 if (streq (tagfile, "-"))
1065 { 1052 {
1066 tagf = stdout; 1053 tagf = stdout;
1067 #ifdef DOS_NT 1054 #ifdef WIN32_NATIVE
1068 /* Switch redirected `stdout' to binary mode (setting `_fmode' 1055 /* Switch redirected `stdout' to binary mode (setting `_fmode'
1069 doesn't take effect until after `stdout' is already open). */ 1056 doesn't take effect until after `stdout' is already open). */
1070 if (!isatty (fileno (stdout))) 1057 if (!isatty (fileno (stdout)))
1071 setmode (fileno (stdout), O_BINARY); 1058 setmode (fileno (stdout), O_BINARY);
1072 #endif /* DOS_NT */ 1059 #endif /* WIN32_NATIVE */
1073 } 1060 }
1074 else 1061 else
1075 tagf = fopen (tagfile, append_to_tagfile ? "a" : "w"); 1062 tagf = fopen (tagfile, append_to_tagfile ? "a" : "w");
1076 if (tagf == NULL) 1063 if (tagf == NULL)
1077 pfatal (tagfile); 1064 pfatal (tagfile);
4958 if (c == '\n') 4945 if (c == '\n')
4959 { 4946 {
4960 if (p > buffer && p[-1] == '\r') 4947 if (p > buffer && p[-1] == '\r')
4961 { 4948 {
4962 p -= 1; 4949 p -= 1;
4963 #ifdef DOS_NT 4950 #ifdef WIN32_NATIVE
4964 /* Assume CRLF->LF translation will be performed by Emacs 4951 /* Assume CRLF->LF translation will be performed by Emacs
4965 when loading this file, so CRs won't appear in the buffer. 4952 when loading this file, so CRs won't appear in the buffer.
4966 It would be cleaner to compensate within Emacs; 4953 It would be cleaner to compensate within Emacs;
4967 however, Emacs does not know how many CRs were deleted 4954 however, Emacs does not know how many CRs were deleted
4968 before any given point in the file. */ 4955 before any given point in the file. */
5214 5201
5215 canonicalize_filename (path); 5202 canonicalize_filename (path);
5216 return path; 5203 return path;
5217 5204
5218 #else /* not HAVE_GETCWD */ 5205 #else /* not HAVE_GETCWD */
5219 #ifdef MSDOS
5220 char *p, path[MAXPATHLEN + 1]; /* Fixed size is safe on MSDOS. */
5221
5222 getwd (path);
5223
5224 for (p = path; *p != '\0'; p++)
5225 if (*p == '\\')
5226 *p = '/';
5227 else
5228 *p = lowcase (*p);
5229
5230 return strdup (path);
5231 #else /* not MSDOS */
5232 linebuffer path; 5206 linebuffer path;
5233 FILE *pipe; 5207 FILE *pipe;
5234 5208
5235 initbuffer (&path); 5209 initbuffer (&path);
5236 pipe = (FILE *) popen ("pwd 2>/dev/null", "r"); 5210 pipe = (FILE *) popen ("pwd 2>/dev/null", "r");
5237 if (pipe == NULL || readline_internal (&path, pipe) == 0) 5211 if (pipe == NULL || readline_internal (&path, pipe) == 0)
5238 pfatal ("pwd"); 5212 pfatal ("pwd");
5239 pclose (pipe); 5213 pclose (pipe);
5240 5214
5241 return path.buffer; 5215 return path.buffer;
5242 #endif /* not MSDOS */
5243 #endif /* not HAVE_GETCWD */ 5216 #endif /* not HAVE_GETCWD */
5244 } 5217 }
5245 5218
5246 /* Return a newly allocated string containing the file name of FILE 5219 /* Return a newly allocated string containing the file name of FILE
5247 relative to the absolute directory DIR (which should end with a slash). */ 5220 relative to the absolute directory DIR (which should end with a slash). */
5287 { 5260 {
5288 char *slashp, *cp, *res; 5261 char *slashp, *cp, *res;
5289 5262
5290 if (filename_is_absolute (file)) 5263 if (filename_is_absolute (file))
5291 res = savestr (file); 5264 res = savestr (file);
5292 #ifdef DOS_NT 5265 #ifdef WIN32_NATIVE
5293 /* We don't support non-absolute file names with a drive 5266 /* We don't support non-absolute file names with a drive
5294 letter, like `d:NAME' (it's too much hassle). */ 5267 letter, like `d:NAME' (it's too much hassle). */
5295 else if (file[1] == ':') 5268 else if (file[1] == ':')
5296 fatal ("%s: relative file names with drive letters not supported", file); 5269 fatal ("%s: relative file names with drive letters not supported", file);
5297 #endif 5270 #endif
5311 do 5284 do
5312 cp--; 5285 cp--;
5313 while (cp >= res && !filename_is_absolute (cp)); 5286 while (cp >= res && !filename_is_absolute (cp));
5314 if (cp < res) 5287 if (cp < res)
5315 cp = slashp; /* the absolute name begins with "/.." */ 5288 cp = slashp; /* the absolute name begins with "/.." */
5316 #ifdef DOS_NT 5289 #ifdef WIN32_NATIVE
5317 /* Under MSDOS and NT we get `d:/NAME' as absolute 5290 /* Under Windows we get `d:/NAME' as absolute
5318 file name, so the luser could say `d:/../NAME'. 5291 file name, so the luser could say `d:/../NAME'.
5319 We silently treat this as `d:/NAME'. */ 5292 We silently treat this as `d:/NAME'. */
5320 else if (cp[0] != '/') 5293 else if (cp[0] != '/')
5321 cp = slashp; 5294 cp = slashp;
5322 #endif 5295 #endif
5367 bool 5340 bool
5368 filename_is_absolute (fn) 5341 filename_is_absolute (fn)
5369 char *fn; 5342 char *fn;
5370 { 5343 {
5371 return (fn[0] == '/' 5344 return (fn[0] == '/'
5372 #ifdef DOS_NT 5345 #ifdef WIN32_NATIVE
5373 || (isalpha(fn[0]) && fn[1] == ':' && fn[2] == '/') 5346 || (isalpha(fn[0]) && fn[1] == ':' && fn[2] == '/')
5374 #endif 5347 #endif
5375 ); 5348 );
5376 } 5349 }
5377 5350
5378 /* Translate backslashes into slashes. Works in place. */ 5351 /* Translate backslashes into slashes. Works in place. */
5379 void 5352 void
5380 canonicalize_filename (fn) 5353 canonicalize_filename (fn)
5381 register char *fn; 5354 register char *fn;
5382 { 5355 {
5383 #ifdef DOS_NT 5356 #ifdef WIN32_NATIVE
5384 for (; *fn != '\0'; fn++) 5357 for (; *fn != '\0'; fn++)
5385 if (*fn == '\\') 5358 if (*fn == '\\')
5386 *fn = '/'; 5359 *fn = '/';
5387 #else 5360 #else
5388 /* No action. */ 5361 /* No action. */