aboutsummaryrefslogtreecommitdiffstats
path: root/lib-src
diff options
context:
space:
mode:
authorFrancesco Potortì1995-01-10 09:07:15 +0000
committerFrancesco Potortì1995-01-10 09:07:15 +0000
commitaab1fdaecc9bca65ebd9a086107aabb951712444 (patch)
tree0729f654f4e4489fdca9553d67b2530d2cb0f82c /lib-src
parentde52827f3ff67f8674e32eaeea37cc4a18409c17 (diff)
downloademacs-aab1fdaecc9bca65ebd9a086107aabb951712444.tar.gz
emacs-aab1fdaecc9bca65ebd9a086107aabb951712444.zip
* etags.c (Lang_function): Use void instead to declare the
language functions, because many compilers are buggy. (etags_getcwd): Fix the previous fix on the #else branch. (readline_internal): Discard possible \r before \n here. (C_entries): Do not deal with \r here: undo previous fix.
Diffstat (limited to 'lib-src')
-rw-r--r--lib-src/etags.c131
1 files changed, 72 insertions, 59 deletions
diff --git a/lib-src/etags.c b/lib-src/etags.c
index 9e059b88db3..e1fcbdedd9c 100644
--- a/lib-src/etags.c
+++ b/lib-src/etags.c
@@ -31,7 +31,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
31 * Francesco Potorti` (pot@cnuce.cnr.it) is the current maintainer. 31 * Francesco Potorti` (pot@cnuce.cnr.it) is the current maintainer.
32 */ 32 */
33 33
34char pot_etags_version[] = "@(#) pot revision number is 11.9"; 34char pot_etags_version[] = "@(#) pot revision number is 11.12";
35 35
36#ifdef MSDOS 36#ifdef MSDOS
37#include <fcntl.h> 37#include <fcntl.h>
@@ -47,9 +47,8 @@ char pot_etags_version[] = "@(#) pot revision number is 11.9";
47 47
48#ifdef HAVE_CONFIG_H 48#ifdef HAVE_CONFIG_H
49#include <config.h> 49#include <config.h>
50/* On some systems, Emacs defines static as nothing 50/* On some systems, Emacs defines static as nothing for the sake
51 for the sake of unexec. We don't want that here 51 of unexec. We don't want that here since we don't use unexec. */
52 since we don't use unexec. */
53#undef static 52#undef static
54#endif 53#endif
55 54
@@ -122,8 +121,8 @@ extern char *getenv ();
122 121
123 /* real implementation */ 122 /* real implementation */
124typedef long FILEPOS; 123typedef long FILEPOS;
125#define GET_CHARNO(pos) ((pos) + 0) 124#define GET_CHARNO(pos) ((pos) + 0)
126#define SET_FILEPOS(pos, fp, cno) ((void) ((pos) = (cno))) 125#define SET_FILEPOS(pos,fp,cno) ((void) ((pos) = (cno)))
127 126
128#else 127#else
129#undef DEBUG 128#undef DEBUG
@@ -136,15 +135,14 @@ typedef struct
136} FILEPOS; 135} FILEPOS;
137 136
138#define GET_CHARNO(pos) ((pos).charno + 0) 137#define GET_CHARNO(pos) ((pos).charno + 0)
139#define SET_FILEPOS(pos, fp, cno) \ 138#define SET_FILEPOS(pos,fp,cno) \
140 ((void) ((pos).charno = (cno), \ 139 ((void) ((pos).charno = (cno), \
141 (cno) != ftell (fp) ? (error ("SET_FILEPOS inconsistency"), 0) \ 140 (cno) != ftell (fp) ? (error ("SET_FILEPOS inconsistency"), 0) \
142 : 0)) 141 : 0))
143#endif 142#endif
144 143
145#define streq(s, t) (strcmp (s, t) == 0) 144#define streq(s,t) (strcmp (s, t) == 0)
146#define strneq(s, t, n) (strncmp (s, t, n) == 0) 145#define strneq(s,t,n) (strncmp (s, t, n) == 0)
147#define logical int
148 146
149#define TRUE 1 147#define TRUE 1
150#define FALSE 0 148#define FALSE 0
@@ -156,6 +154,8 @@ typedef struct
156 154
157#define max(I1,I2) ((I1) > (I2) ? (I1) : (I2)) 155#define max(I1,I2) ((I1) > (I2) ? (I1) : (I2))
158 156
157typedef int logical;
158
159struct nd_st 159struct nd_st
160{ /* sorting structure */ 160{ /* sorting structure */
161 char *name; /* function or type name */ 161 char *name; /* function or type name */
@@ -185,6 +185,7 @@ char *relative_filename (), *absolute_filename (), *absolute_dirname ();
185char *xmalloc (), *xrealloc (); 185char *xmalloc (), *xrealloc ();
186 186
187typedef void Lang_function (); 187typedef void Lang_function ();
188#if 0 /* many compilers barf on this */
188Lang_function Asm_labels; 189Lang_function Asm_labels;
189Lang_function default_C_entries; 190Lang_function default_C_entries;
190Lang_function C_entries; 191Lang_function C_entries;
@@ -198,6 +199,21 @@ Lang_function Prolog_functions;
198Lang_function Scheme_functions; 199Lang_function Scheme_functions;
199Lang_function TeX_functions; 200Lang_function TeX_functions;
200Lang_function just_read_file; 201Lang_function just_read_file;
202#else /* so let's write it this way */
203void Asm_labels ();
204void default_C_entries ();
205void C_entries ();
206void Cplusplus_entries ();
207void Cstar_entries ();
208void Fortran_functions ();
209void Yacc_entries ();
210void Lisp_functions ();
211void Pascal_functions ();
212void Prolog_functions ();
213void Scheme_functions ();
214void TeX_functions ();
215void just_read_file ();
216#endif
201 217
202logical get_language (); 218logical get_language ();
203int total_size_of_entries (); 219int total_size_of_entries ();
@@ -226,7 +242,7 @@ void takeprec ();
226 * SYNOPSIS 242 * SYNOPSIS
227 * Type *xnew (int n, Type); 243 * Type *xnew (int n, Type);
228 */ 244 */
229#define xnew(n, Type) ((Type *) xmalloc ((n) * sizeof (Type))) 245#define xnew(n,Type) ((Type *) xmalloc ((n) * sizeof (Type)))
230 246
231/* 247/*
232 * Symbol table types. 248 * Symbol table types.
@@ -320,10 +336,11 @@ FILE *tagf; /* ioptr for tags file */
320NODE *head; /* the head of the binary tree of tags */ 336NODE *head; /* the head of the binary tree of tags */
321logical permit_duplicates = TRUE; /* allow duplicate tags */ 337logical permit_duplicates = TRUE; /* allow duplicate tags */
322 338
323/* A `struct linebuffer' is a structure which holds a line of text. 339/*
324 `readline' reads a line from a stream into a linebuffer 340 * A `struct linebuffer' is a structure which holds a line of text.
325 and works regardless of the length of the line. */ 341 * `readline' reads a line from a stream into a linebuffer and works
326 342 * regardless of the length of the line.
343 */
327struct linebuffer 344struct linebuffer
328{ 345{
329 long size; 346 long size;
@@ -1237,8 +1254,12 @@ pfnote (name, is_func, named, linestart, linelen, lno, cno)
1237 np->is_func = is_func; 1254 np->is_func = is_func;
1238 np->named = named; 1255 np->named = named;
1239 np->lno = lno; 1256 np->lno = lno;
1240 /* UNCOMMENT THE +1 HERE: */ 1257 /* Our char numbers are 0-base, because of C language tradition?
1241 np->cno = cno /* + 1 */ ; /* our char numbers are 0-base; emacs's are 1-base */ 1258 ctags compatibility? old versions compatibility? I don't know.
1259 Anyway, since emacs's are 1-base we espect etags.el to take care
1260 of the difference. If we wanted to have 1-based numbers, we would
1261 uncomment the +1 below. */
1262 np->cno = cno /* + 1 */ ;
1242 np->left = np->right = 0; 1263 np->left = np->right = 0;
1243 if (!CTAGS) 1264 if (!CTAGS)
1244 { 1265 {
@@ -1973,9 +1994,6 @@ C_entries (c_ext, inf)
1973 c = *lp++; 1994 c = *lp++;
1974 if (c == '\\') 1995 if (c == '\\')
1975 { 1996 {
1976 /* deal with \r (13) at end of msdos lines */
1977 if ((*lp =='\r')&&(*(lp+1)=='\0'))
1978 *lp = '\0';
1979 /* If we're at the end of the line, the next character is a 1997 /* If we're at the end of the line, the next character is a
1980 '\0'; don't skip it, because it's the thing that tells us 1998 '\0'; don't skip it, because it's the thing that tells us
1981 to read the next line. */ 1999 to read the next line. */
@@ -2675,13 +2693,12 @@ Asm_labels (inf)
2675 dbp = lb.buffer; \ 2693 dbp = lb.buffer; \
2676} 2694}
2677 2695
2678/* Locates tags for procedures & functions. 2696/*
2679 * Doesn't do any type- or var-definitions. 2697 * Locates tags for procedures & functions. Doesn't do any type- or
2680 * It does look for the keyword "extern" or "forward" 2698 * var-definitions. It does look for the keyword "extern" or
2681 * immediately following the procedure statement; 2699 * "forward" immediately following the procedure statement; if found,
2682 * if found, the tag is skipped. 2700 * the tag is skipped.
2683 */ 2701 */
2684
2685void 2702void
2686Pascal_functions (inf) 2703Pascal_functions (inf)
2687 FILE *inf; 2704 FILE *inf;
@@ -3040,7 +3057,6 @@ get_scheme ()
3040/* TEX_toktab is a table of TeX control sequences that define tags. 3057/* TEX_toktab is a table of TeX control sequences that define tags.
3041 Each TEX_tabent records one such control sequence. 3058 Each TEX_tabent records one such control sequence.
3042 CONVERT THIS TO USE THE Stab TYPE!! */ 3059 CONVERT THIS TO USE THE Stab TYPE!! */
3043
3044struct TEX_tabent 3060struct TEX_tabent
3045{ 3061{
3046 char *name; 3062 char *name;
@@ -3067,7 +3083,6 @@ char TEX_clgrp = '}';
3067/* 3083/*
3068 * TeX/LaTeX scanning loop. 3084 * TeX/LaTeX scanning loop.
3069 */ 3085 */
3070
3071void 3086void
3072TeX_functions (inf) 3087TeX_functions (inf)
3073 FILE *inf; 3088 FILE *inf;
@@ -3114,9 +3129,8 @@ TeX_functions (inf)
3114#define TEX_SESC '!' 3129#define TEX_SESC '!'
3115#define TEX_cmt '%' 3130#define TEX_cmt '%'
3116 3131
3117/* Figure out whether TeX's escapechar is '\\' or '!' and set grouping */ 3132/* Figure out whether TeX's escapechar is '\\' or '!' and set grouping
3118/* chars accordingly. */ 3133 chars accordingly. */
3119
3120void 3134void
3121TEX_mode (inf) 3135TEX_mode (inf)
3122 FILE *inf; 3136 FILE *inf;
@@ -3148,9 +3162,8 @@ TEX_mode (inf)
3148 rewind (inf); 3162 rewind (inf);
3149} 3163}
3150 3164
3151/* Read environment and prepend it to the default string. */ 3165/* Read environment and prepend it to the default string.
3152/* Build token table. */ 3166 Build token table. */
3153
3154struct TEX_tabent * 3167struct TEX_tabent *
3155TEX_decode_env (evarname, defenv) 3168TEX_decode_env (evarname, defenv)
3156 char *evarname; 3169 char *evarname;
@@ -3203,7 +3216,6 @@ TEX_decode_env (evarname, defenv)
3203/* Record a tag defined by a TeX command of length LEN and starting at NAME. 3216/* Record a tag defined by a TeX command of length LEN and starting at NAME.
3204 The name being defined actually starts at (NAME + LEN + 1). 3217 The name being defined actually starts at (NAME + LEN + 1).
3205 But we seem to include the TeX command in the tag name. */ 3218 But we seem to include the TeX command in the tag name. */
3206
3207void 3219void
3208TEX_getit (name, len) 3220TEX_getit (name, len)
3209 char *name; 3221 char *name;
@@ -3227,9 +3239,8 @@ TEX_getit (name, len)
3227 3239
3228/* If the text at CP matches one of the tag-defining TeX command names, 3240/* If the text at CP matches one of the tag-defining TeX command names,
3229 return the pointer to the first occurrence of that command in TEX_toktab. 3241 return the pointer to the first occurrence of that command in TEX_toktab.
3230 Otherwise return -1. */ 3242 Otherwise return -1.
3231 3243 Keep the capital `T' in `Token' for dumb truncating compilers
3232/* Keep the capital `T' in `Token' for dumb truncating compilers
3233 (this distinguishes it from `TEX_toktab' */ 3244 (this distinguishes it from `TEX_toktab' */
3234int 3245int
3235TEX_Token (cp) 3246TEX_Token (cp)
@@ -3245,9 +3256,8 @@ TEX_Token (cp)
3245 3256
3246/* Support for Prolog. */ 3257/* Support for Prolog. */
3247 3258
3248/* whole head (not only functor, but also arguments) 3259/* Whole head (not only functor, but also arguments)
3249 is gotten in compound term. */ 3260 is gotten in compound term. */
3250
3251void 3261void
3252prolog_getit (s) 3262prolog_getit (s)
3253 char *s; 3263 char *s;
@@ -3301,7 +3311,6 @@ prolog_getit (s)
3301} 3311}
3302 3312
3303/* It is assumed that prolog predicate starts from column 0. */ 3313/* It is assumed that prolog predicate starts from column 0. */
3304
3305void 3314void
3306Prolog_functions (inf) 3315Prolog_functions (inf)
3307 FILE *inf; 3316 FILE *inf;
@@ -3546,7 +3555,7 @@ readline_internal (linebuffer, stream)
3546 char *buffer = linebuffer->buffer; 3555 char *buffer = linebuffer->buffer;
3547 register char *p = linebuffer->buffer; 3556 register char *p = linebuffer->buffer;
3548 register char *pend; 3557 register char *pend;
3549 int newline; /* 1 if ended with '\n', 0 if ended with EOF */ 3558 int chars_deleted;
3550 3559
3551 pend = p + linebuffer->size; /* Separate to avoid 386/IX compiler bug. */ 3560 pend = p + linebuffer->size; /* Separate to avoid 386/IX compiler bug. */
3552 3561
@@ -3561,16 +3570,29 @@ readline_internal (linebuffer, stream)
3561 pend = buffer + linebuffer->size; 3570 pend = buffer + linebuffer->size;
3562 linebuffer->buffer = buffer; 3571 linebuffer->buffer = buffer;
3563 } 3572 }
3564 if (c == EOF || c == '\n') 3573 if (c == EOF)
3565 { 3574 {
3566 *p = 0; 3575 chars_deleted = 0;
3567 newline = (c == '\n') ? 1 : 0; 3576 break;
3577 }
3578 if (c == '\n')
3579 {
3580 if (p[-1] == '\r' && p > buffer)
3581 {
3582 *--p = '\0';
3583 chars_deleted = 2;
3584 }
3585 else
3586 {
3587 *p = '\0';
3588 chars_deleted = 1;
3589 }
3568 break; 3590 break;
3569 } 3591 }
3570 *p++ = c; 3592 *p++ = c;
3571 } 3593 }
3572 3594
3573 return p - buffer + newline; 3595 return p - buffer + chars_deleted;
3574} 3596}
3575 3597
3576/* 3598/*
@@ -3674,7 +3696,6 @@ savenstr (cp, len)
3674 * 3696 *
3675 * Identical to System V strrchr, included for portability. 3697 * Identical to System V strrchr, included for portability.
3676 */ 3698 */
3677
3678char * 3699char *
3679etags_strrchr (sp, c) 3700etags_strrchr (sp, c)
3680 register char *sp, c; 3701 register char *sp, c;
@@ -3697,7 +3718,6 @@ etags_strrchr (sp, c)
3697 * 3718 *
3698 * Identical to System V strchr, included for portability. 3719 * Identical to System V strchr, included for portability.
3699 */ 3720 */
3700
3701char * 3721char *
3702etags_strchr (sp, c) 3722etags_strchr (sp, c)
3703 register char *sp, c; 3723 register char *sp, c;
@@ -3711,8 +3731,6 @@ etags_strchr (sp, c)
3711} 3731}
3712 3732
3713/* Print error message and exit. */ 3733/* Print error message and exit. */
3714
3715/* VARARGS1 */
3716void 3734void
3717fatal (s1, s2) 3735fatal (s1, s2)
3718 char *s1, *s2; 3736 char *s1, *s2;
@@ -3722,8 +3740,6 @@ fatal (s1, s2)
3722} 3740}
3723 3741
3724/* Print error message. `s1' is printf control string, `s2' is arg for it. */ 3742/* Print error message. `s1' is printf control string, `s2' is arg for it. */
3725
3726/* VARARGS1 */
3727void 3743void
3728error (s1, s2) 3744error (s1, s2)
3729 char *s1, *s2; 3745 char *s1, *s2;
@@ -3735,7 +3751,6 @@ error (s1, s2)
3735 3751
3736/* Return a newly-allocated string whose contents 3752/* Return a newly-allocated string whose contents
3737 concatenate those of s1, s2, s3. */ 3753 concatenate those of s1, s2, s3. */
3738
3739char * 3754char *
3740concat (s1, s2, s3) 3755concat (s1, s2, s3)
3741 char *s1, *s2, *s3; 3756 char *s1, *s2, *s3;
@@ -3771,10 +3786,11 @@ etags_getcwd ()
3771char * 3786char *
3772etags_getcwd () 3787etags_getcwd ()
3773{ 3788{
3789 char *buf;
3774 int bufsize = 256; 3790 int bufsize = 256;
3775 char *buf = xnew (bufsize, char);
3776 3791
3777#ifdef HAVE_GETCWD 3792#ifdef HAVE_GETCWD
3793 buf = xnew (bufsize, char);
3778 while (getcwd (buf, bufsize / 2) == NULL) 3794 while (getcwd (buf, bufsize / 2) == NULL)
3779 { 3795 {
3780 if (errno != ERANGE) 3796 if (errno != ERANGE)
@@ -3790,6 +3806,8 @@ etags_getcwd ()
3790 { 3806 {
3791 FILE *pipe; 3807 FILE *pipe;
3792 3808
3809 buf = xnew (bufsize, char);
3810
3793 pipe = (FILE *) popen ("pwd 2>/dev/null", "r"); 3811 pipe = (FILE *) popen ("pwd 2>/dev/null", "r");
3794 if (pipe == NULL) 3812 if (pipe == NULL)
3795 { 3813 {
@@ -3804,7 +3822,6 @@ etags_getcwd ()
3804 pclose (pipe); 3822 pclose (pipe);
3805 3823
3806 bufsize *= 2; 3824 bufsize *= 2;
3807 buf = xnew (bufsize, char);
3808 3825
3809 } while (buf[strlen (buf) - 1] != '\n'); 3826 } while (buf[strlen (buf) - 1] != '\n');
3810#endif 3827#endif
@@ -3817,7 +3834,6 @@ etags_getcwd ()
3817/* Return a newly allocated string containing the filename 3834/* Return a newly allocated string containing the filename
3818 of FILE relative to the absolute directory DIR (which 3835 of FILE relative to the absolute directory DIR (which
3819 should end with a slash). */ 3836 should end with a slash). */
3820
3821char * 3837char *
3822relative_filename (file, dir) 3838relative_filename (file, dir)
3823 char *file, *dir; 3839 char *file, *dir;
@@ -3853,7 +3869,6 @@ relative_filename (file, dir)
3853/* Return a newly allocated string containing the 3869/* Return a newly allocated string containing the
3854 absolute filename of FILE given CWD (which should 3870 absolute filename of FILE given CWD (which should
3855 end with a slash). */ 3871 end with a slash). */
3856
3857char * 3872char *
3858absolute_filename (file, cwd) 3873absolute_filename (file, cwd)
3859 char *file, *cwd; 3874 char *file, *cwd;
@@ -3908,7 +3923,6 @@ absolute_filename (file, cwd)
3908/* Return a newly allocated string containing the absolute 3923/* Return a newly allocated string containing the absolute
3909 filename of dir where FILE resides given CWD (which should 3924 filename of dir where FILE resides given CWD (which should
3910 end with a slash). */ 3925 end with a slash). */
3911
3912char * 3926char *
3913absolute_dirname (file, cwd) 3927absolute_dirname (file, cwd)
3914 char *file, *cwd; 3928 char *file, *cwd;
@@ -3928,7 +3942,6 @@ absolute_dirname (file, cwd)
3928} 3942}
3929 3943
3930/* Like malloc but get fatal error if memory is exhausted. */ 3944/* Like malloc but get fatal error if memory is exhausted. */
3931
3932char * 3945char *
3933xmalloc (size) 3946xmalloc (size)
3934 unsigned int size; 3947 unsigned int size;