aboutsummaryrefslogtreecommitdiffstats
path: root/lib-src
diff options
context:
space:
mode:
authorFrancesco Potortì1994-03-30 12:04:41 +0000
committerFrancesco Potortì1994-03-30 12:04:41 +0000
commitb02c5fea9079154ee8388d9b8a93699e9323fcf6 (patch)
tree02f860a4d5b6d250d13acf1293f0c025fde6b495 /lib-src
parent5fb5aa335ec035d80fd22a08fac3035e0e65da77 (diff)
downloademacs-b02c5fea9079154ee8388d9b8a93699e9323fcf6.tar.gz
emacs-b02c5fea9079154ee8388d9b8a93699e9323fcf6.zip
* etags.c (main): use etags_getcwd for compatibility.
(etags_getcwd): new function.
Diffstat (limited to 'lib-src')
-rw-r--r--lib-src/etags.c115
1 files changed, 73 insertions, 42 deletions
diff --git a/lib-src/etags.c b/lib-src/etags.c
index 0a77dbc1467..b6481bb475b 100644
--- a/lib-src/etags.c
+++ b/lib-src/etags.c
@@ -28,7 +28,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
28 * Francesco Potorti` (pot@cnuce.cnr.it) is the current maintainer. 28 * Francesco Potorti` (pot@cnuce.cnr.it) is the current maintainer.
29 */ 29 */
30 30
31char pot_etags_version[] = "@(#) pot revision number is 10.18"; 31char pot_etags_version[] = "@(#) pot revision number is 10.21";
32 32
33#ifdef MSDOS 33#ifdef MSDOS
34#include <fcntl.h> 34#include <fcntl.h>
@@ -50,7 +50,6 @@ char pot_etags_version[] = "@(#) pot revision number is 10.18";
50#include "getopt.h" 50#include "getopt.h"
51 51
52extern char *getenv (); 52extern char *getenv ();
53extern char *getcwd ();
54 53
55 54
56/* Define CTAGS to make the program "ctags" compatible with the usual one. 55/* Define CTAGS to make the program "ctags" compatible with the usual one.
@@ -148,12 +147,13 @@ logical header_file; /* TRUE if .h file, FALSE o.w. */
148/* boolean "functions" (see init) */ 147/* boolean "functions" (see init) */
149logical _wht[0177], _etk[0177], _itk[0177], _btk[0177]; 148logical _wht[0177], _etk[0177], _itk[0177], _btk[0177];
150 149
151char cwd [BUFSIZ]; /* current working directory */ 150char *cwd; /* current working directory */
152char *outfiledir; /* directory of tagfile */ 151char *outfiledir; /* directory of tagfile */
153 152
154char *concat (); 153char *concat ();
155char *savenstr (), *savestr (); 154char *savenstr (), *savestr ();
156char *etags_index (), *etags_rindex (); 155char *etags_strchr (), *etags_strrchr ();
156char *etags_getcwd ();
157char *relative_filename (), *absolute_filename (), *absolute_dirname (); 157char *relative_filename (), *absolute_filename (), *absolute_dirname ();
158char *xmalloc (), *xrealloc (); 158char *xmalloc (), *xrealloc ();
159int L_isdef (), L_isquote (); 159int L_isdef (), L_isquote ();
@@ -367,10 +367,6 @@ names from stdin.\n\n", progname);
367 puts ("-T, --typedefs-and-c++\n\ 367 puts ("-T, --typedefs-and-c++\n\
368 Generate tag entries for C typedefs, C struct/enum/union tags,\n\ 368 Generate tag entries for C typedefs, C struct/enum/union tags,\n\
369 and C++ member functions."); 369 and C++ member functions.");
370 }
371
372 if (CTAGS)
373 {
374 puts ("-u, --update\n\ 370 puts ("-u, --update\n\
375 Update the tag entries for the given files, leaving tag\n\ 371 Update the tag entries for the given files, leaving tag\n\
376 entries for other files in place. Currently, this is\n\ 372 entries for other files in place. Currently, this is\n\
@@ -441,8 +437,8 @@ main (argc, argv)
441 437
442 switch (opt) 438 switch (opt)
443 { 439 {
444 case '\0': 440 case 0:
445 /* If getopt returns '\0', then it has already processed a 441 /* If getopt returns 0, then it has already processed a
446 long-named option. We should do nothing. */ 442 long-named option. We should do nothing. */
447 break; 443 break;
448 444
@@ -479,47 +475,44 @@ main (argc, argv)
479 print_help (); 475 print_help ();
480 break; 476 break;
481 477
478#if (!CTAGS)
479
482 /* Etags options */ 480 /* Etags options */
483 case 'i': 481 case 'i':
484 if (CTAGS)
485 goto usage;
486 included_files[nincluded_files++] = optarg; 482 included_files[nincluded_files++] = optarg;
487 break; 483 break;
488 484
485#else /* CTAGS */
486
489 /* Ctags options. */ 487 /* Ctags options. */
490 case 'B': 488 case 'B':
491 searchar = '?'; 489 searchar = '?';
492 if (!CTAGS) goto usage;
493 break; 490 break;
494 case 'F': 491 case 'F':
495 searchar = '/'; 492 searchar = '/';
496 if (!CTAGS) goto usage;
497 break; 493 break;
498 case 't': 494 case 't':
499 typedefs++; 495 typedefs++;
500 if (!CTAGS) goto usage;
501 break; 496 break;
502 case 'T': 497 case 'T':
503 typedefs++; 498 typedefs++;
504 typedefs_and_cplusplus++; 499 typedefs_and_cplusplus++;
505 if (!CTAGS) goto usage;
506 break; 500 break;
507 case 'u': 501 case 'u':
508 update++; 502 update++;
509 if (!CTAGS) goto usage;
510 break; 503 break;
511 case 'v': 504 case 'v':
512 vgrind_style++; 505 vgrind_style++;
513 /*FALLTHRU*/ 506 /*FALLTHRU*/
514 case 'x': 507 case 'x':
515 cxref_style++; 508 cxref_style++;
516 if (!CTAGS) goto usage;
517 break; 509 break;
518 case 'w': 510 case 'w':
519 no_warnings++; 511 no_warnings++;
520 if (!CTAGS) goto usage;
521 break; 512 break;
522 513
514#endif /* CTAGS */
515
523 default: 516 default:
524 goto usage; 517 goto usage;
525 } 518 }
@@ -539,7 +532,7 @@ main (argc, argv)
539 { 532 {
540 outfile = CTAGS ? "tags" : "TAGS"; 533 outfile = CTAGS ? "tags" : "TAGS";
541 } 534 }
542 getcwd (cwd, BUFSIZ); /* the current working directory */ 535 cwd = etags_getcwd (); /* the current working directory */
543 strcat (cwd, "/"); 536 strcat (cwd, "/");
544 if (streq (outfile, "-")) 537 if (streq (outfile, "-"))
545 { 538 {
@@ -745,7 +738,7 @@ find_entries (file)
745 return FALSE; 738 return FALSE;
746 } 739 }
747 curfile = savestr (file); 740 curfile = savestr (file);
748 cp = etags_rindex (file, '.'); 741 cp = etags_strrchr (file, '.');
749 742
750 header_file = (cp && (streq (cp + 1, "h"))); 743 header_file = (cp && (streq (cp + 1, "h")));
751 744
@@ -904,9 +897,9 @@ pfnote (name, is_func, named, linestart, linelen, lno, cno)
904 /* If ctags mode, change name "main" to M<thisfilename>. */ 897 /* If ctags mode, change name "main" to M<thisfilename>. */
905 if (CTAGS && !cxref_style && streq (name, "main")) 898 if (CTAGS && !cxref_style && streq (name, "main"))
906 { 899 {
907 fp = etags_rindex (curfile, '/'); 900 fp = etags_strrchr (curfile, '/');
908 name = concat ("M", fp == 0 ? curfile : fp + 1, ""); 901 name = concat ("M", fp == 0 ? curfile : fp + 1, "");
909 fp = etags_rindex (name, '.'); 902 fp = etags_strrchr (name, '.');
910 if (fp && fp[1] != '\0' && fp[2] == '\0') 903 if (fp && fp[1] != '\0' && fp[2] == '\0')
911 *fp = 0; 904 *fp = 0;
912 named = TRUE; 905 named = TRUE;
@@ -2682,7 +2675,7 @@ TEX_funcs (fi)
2682 charno += readline (&lb, fi); 2675 charno += readline (&lb, fi);
2683 dbp = lb.buffer; 2676 dbp = lb.buffer;
2684 lasthit = dbp; 2677 lasthit = dbp;
2685 while (dbp = etags_index (dbp, TEX_esc)) /* Look at each escape in line */ 2678 while (dbp = etags_strchr (dbp, TEX_esc)) /* Look at each esc in line */
2686 { 2679 {
2687 register int i; 2680 register int i;
2688 2681
@@ -2760,7 +2753,7 @@ TEX_decode_env (evarname, defenv)
2760 2753
2761 /* Allocate a token table */ 2754 /* Allocate a token table */
2762 for (size = 1, p = env; p;) 2755 for (size = 1, p = env; p;)
2763 if ((p = etags_index (p, ':')) && *(++p)) 2756 if ((p = etags_strchr (p, ':')) && *(++p))
2764 size++; 2757 size++;
2765 /* Add 1 to leave room for null terminator. */ 2758 /* Add 1 to leave room for null terminator. */
2766 tab = xnew (size + 1, struct TEX_tabent); 2759 tab = xnew (size + 1, struct TEX_tabent);
@@ -2769,7 +2762,7 @@ TEX_decode_env (evarname, defenv)
2769 /* zero-length strings (leading ':', "::" and trailing ':') */ 2762 /* zero-length strings (leading ':', "::" and trailing ':') */
2770 for (i = 0; *env;) 2763 for (i = 0; *env;)
2771 { 2764 {
2772 p = etags_index (env, ':'); 2765 p = etags_strchr (env, ':');
2773 if (!p) /* End of environment string. */ 2766 if (!p) /* End of environment string. */
2774 p = env + strlen (env); 2767 p = env + strlen (env);
2775 if (p - env > 0) 2768 if (p - env > 0)
@@ -2816,7 +2809,7 @@ TEX_getit (name, len)
2816} 2809}
2817 2810
2818/* If the text at CP matches one of the tag-defining TeX command names, 2811/* If the text at CP matches one of the tag-defining TeX command names,
2819 return the etags_index of that command in TEX_toktab. 2812 return the pointer to the first occurrence of that command in TEX_toktab.
2820 Otherwise return -1. */ 2813 Otherwise return -1. */
2821 2814
2822/* Keep the capital `T' in `Token' for dumb truncating compilers 2815/* Keep the capital `T' in `Token' for dumb truncating compilers
@@ -2939,7 +2932,7 @@ substr (sub, s)
2939 char *sub; 2932 char *sub;
2940 char *s; 2933 char *s;
2941{ 2934{
2942 while (*s && (s = etags_index (s, *sub))) 2935 while (*s && (s = etags_strchr (s, *sub)))
2943 if (prestr (sub, s)) 2936 if (prestr (sub, s))
2944 return (TRUE); 2937 return (TRUE);
2945 else 2938 else
@@ -3036,11 +3029,11 @@ savenstr (cp, len)
3036 * Return the ptr in sp at which the character c last 3029 * Return the ptr in sp at which the character c last
3037 * appears; NULL if not found 3030 * appears; NULL if not found
3038 * 3031 *
3039 * Identical to v7 rindex, included for portability. 3032 * Identical to System V strrchr, included for portability.
3040 */ 3033 */
3041 3034
3042char * 3035char *
3043etags_rindex (sp, c) 3036etags_strrchr (sp, c)
3044 register char *sp, c; 3037 register char *sp, c;
3045{ 3038{
3046 register char *r; 3039 register char *r;
@@ -3059,11 +3052,11 @@ etags_rindex (sp, c)
3059 * Return the ptr in sp at which the character c first 3052 * Return the ptr in sp at which the character c first
3060 * appears; NULL if not found 3053 * appears; NULL if not found
3061 * 3054 *
3062 * Identical to v7 index, included for portability. 3055 * Identical to System V strchr, included for portability.
3063 */ 3056 */
3064 3057
3065char * 3058char *
3066etags_index (sp, c) 3059etags_strchr (sp, c)
3067 register char *sp, c; 3060 register char *sp, c;
3068{ 3061{
3069 do 3062 do
@@ -3114,9 +3107,43 @@ concat (s1, s2, s3)
3114 3107
3115 return result; 3108 return result;
3116} 3109}
3110
3111/* Identical to system V getcwd, but does not need to guess
3112 buffer size in advance. Included mostly for compatibility. */
3113char *
3114etags_getcwd ()
3115{
3116 FILE *pipe;
3117 char *buf;
3118 int bufsize;
3117 3119
3118/* Return a newly allocated string containing the filename of FILE relative 3120 do
3119 to the absolute directory DIR (which should end with a slash). */ 3121 {
3122 buf = xnew (bufsize, char);
3123
3124 pipe = popen ("pwd 2>/dev/null", "r");
3125 if (pipe == NULL)
3126 {
3127 perror ("pwd");
3128 exit (BAD);
3129 }
3130 if (fgets (buf, bufsize, pipe) == NULL)
3131 {
3132 perror ("pwd");
3133 exit (BAD);
3134 }
3135 pclose (pipe);
3136
3137 bufsize *= 2;
3138
3139 } while (buf[strlen (buf) - 1] != '\n');
3140
3141 return buf;
3142}
3143
3144/* Return a newly allocated string containing the filename
3145 of FILE relative to the absolute directory DIR (which
3146 should end with a slash). */
3120 3147
3121char * 3148char *
3122relative_filename (file, dir) 3149relative_filename (file, dir)
@@ -3137,9 +3164,9 @@ relative_filename (file, dir)
3137 while (*fp != '/'); 3164 while (*fp != '/');
3138 3165
3139 /* Build a sequence of "../" strings for the resulting relative filename. */ 3166 /* Build a sequence of "../" strings for the resulting relative filename. */
3140 for (dp = etags_index (dp + 1, '/'), res = ""; 3167 for (dp = etags_strchr (dp + 1, '/'), res = "";
3141 dp != NULL; 3168 dp != NULL;
3142 dp = etags_index (dp + 1, '/')) 3169 dp = etags_strchr (dp + 1, '/'))
3143 { 3170 {
3144 res = concat (res, "../", ""); 3171 res = concat (res, "../", "");
3145 } 3172 }
@@ -3151,7 +3178,9 @@ relative_filename (file, dir)
3151} 3178}
3152 3179
3153/* Return a newly allocated string containing the 3180/* Return a newly allocated string containing the
3154 absolute filename of FILE given CWD (which should end with a slash). */ 3181 absolute filename of FILE given CWD (which should
3182 end with a slash). */
3183
3155char * 3184char *
3156absolute_filename (file, cwd) 3185absolute_filename (file, cwd)
3157 char *file, *cwd; 3186 char *file, *cwd;
@@ -3164,7 +3193,7 @@ absolute_filename (file, cwd)
3164 res = concat (cwd, file, ""); 3193 res = concat (cwd, file, "");
3165 3194
3166 /* Delete the "/dirname/.." and "/." substrings. */ 3195 /* Delete the "/dirname/.." and "/." substrings. */
3167 slashp = etags_index (res, '/'); 3196 slashp = etags_strchr (res, '/');
3168 while (slashp != NULL && slashp[0] != '\0') 3197 while (slashp != NULL && slashp[0] != '\0')
3169 { 3198 {
3170 if (slashp[1] == '.') 3199 if (slashp[1] == '.')
@@ -3196,15 +3225,17 @@ absolute_filename (file, cwd)
3196 } 3225 }
3197 else 3226 else
3198 { 3227 {
3199 slashp = etags_index (slashp + 1, '/'); 3228 slashp = etags_strchr (slashp + 1, '/');
3200 } 3229 }
3201 } 3230 }
3202 3231
3203 return res; 3232 return res;
3204} 3233}
3205 3234
3206/* Return a newly allocated string containing the absolute filename 3235/* Return a newly allocated string containing the absolute
3207 of dir where FILE resides given CWD (which should end with a slash). */ 3236 filename of dir where FILE resides given CWD (which should
3237 end with a slash). */
3238
3208char * 3239char *
3209absolute_dirname (file, cwd) 3240absolute_dirname (file, cwd)
3210 char *file, *cwd; 3241 char *file, *cwd;
@@ -3212,7 +3243,7 @@ absolute_dirname (file, cwd)
3212 char *slashp, *res; 3243 char *slashp, *res;
3213 char save; 3244 char save;
3214 3245
3215 slashp = etags_rindex (file, '/'); 3246 slashp = etags_strrchr (file, '/');
3216 if (slashp == NULL) 3247 if (slashp == NULL)
3217 return cwd; 3248 return cwd;
3218 save = slashp[1]; 3249 save = slashp[1];