=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/less/tags.c,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- src/usr.bin/less/tags.c 2010/07/02 22:43:38 1.8 +++ src/usr.bin/less/tags.c 2011/09/16 18:12:09 1.9 @@ -1,5 +1,5 @@ /* - * Copyright (C) 1984-2002 Mark Nudelman + * Copyright (C) 1984-2011 Mark Nudelman * * You may distribute under the terms of either the GNU General Public * License or the Less License, as specified in the README file. @@ -54,7 +54,7 @@ * * Use either pattern or line number. * findgtag() always uses line number, so pattern is always NULL. - * findctag() usually either pattern (in which case line number is 0), + * findctag() uses either pattern (in which case line number is 0), * or line number (in which case pattern is NULL). */ struct taglist { @@ -73,10 +73,10 @@ static struct tag *curtag; #define TAG_INS(tp) \ - (tp)->next = taglist.tl_first; \ - (tp)->prev = TAG_END; \ - taglist.tl_first->prev = (tp); \ - taglist.tl_first = (tp); + (tp)->next = TAG_END; \ + (tp)->prev = taglist.tl_last; \ + taglist.tl_last->next = (tp); \ + taglist.tl_last = (tp); #define TAG_RM(tp) \ (tp)->next->prev = (tp)->prev; \ @@ -412,7 +412,7 @@ * starting position of that line in linepos. */ linepos = pos; - pos = forw_raw_line(pos, &line); + pos = forw_raw_line(pos, &line, (int *)NULL); if (linenum != 0) linenum++; @@ -471,6 +471,7 @@ char buf[256]; FILE *fp; struct tag *tp; + size_t len; if (type != T_CTAGS_X && tag == NULL) return TAG_NOFILE; @@ -492,7 +493,7 @@ #if !HAVE_POPEN return TAG_NOFILE; #else - char command[512]; + char *command; char *flag; char *qtag; char *cmd = lgetenv("LESSGLOBALTAGS"); @@ -522,11 +523,13 @@ qtag = shell_quote(tag); if (qtag == NULL) qtag = tag; - snprintf(command, sizeof(command), "%s -x%s %s", cmd, - flag, qtag); + len = strlen(cmd) + strlen(flag) + strlen(qtag) + 5; + command = (char *) ecalloc(len, sizeof(char)); + snprintf(command, len, "%s -x%s %s", cmd, flag, qtag); if (qtag != tag) free(qtag); fp = popen(command, "r"); + free(command); #endif } if (fp != NULL) @@ -534,7 +537,6 @@ while (fgets(buf, sizeof(buf), fp)) { char *name, *file, *line; - size_t len; if (sigs) { @@ -544,8 +546,9 @@ #endif return TAG_INTR; } - if ((len = strlen(buf)) && buf[len - 1] == '\n') - buf[len - 1] = 0; + len = strlen(buf); + if (len > 0 && buf[len-1] == '\n') + buf[len-1] = '\0'; else { int c; @@ -691,14 +694,6 @@ * The tag, file, and line will each be NUL-terminated pointers * into buf. */ - -#ifndef isspace -#define isspace(c) ((c) == ' ' || (c) == '\t' || (c) == '\n' || (c) == '\r' || (c) == '\f') -#endif -#ifndef isdigit -#define isdigit(c) ((c) >= '0' && (c <= '9')) -#endif - static int getentry(buf, tag, file, line) char *buf; /* standard or extended ctags -x format data */ @@ -708,12 +703,12 @@ { char *p = buf; - for (*tag = p; *p && !isspace(*p); p++) /* tag name */ + for (*tag = p; *p && !IS_SPACE(*p); p++) /* tag name */ ; if (*p == 0) return (-1); *p++ = 0; - for ( ; isspace(*p); p++) /* (skip blanks) */ + for ( ; *p && IS_SPACE(*p); p++) /* (skip blanks) */ ; if (*p == 0) return (-1); @@ -721,27 +716,27 @@ * If the second part begin with other than digit, * it is assumed tag type. Skip it. */ - if (!isdigit(*p)) + if (!IS_DIGIT(*p)) { - for ( ; *p && !isspace(*p); p++) /* (skip tag type) */ + for ( ; *p && !IS_SPACE(*p); p++) /* (skip tag type) */ ; - for (; isspace(*p); p++) /* (skip blanks) */ + for (; *p && IS_SPACE(*p); p++) /* (skip blanks) */ ; } - if (!isdigit(*p)) + if (!IS_DIGIT(*p)) return (-1); *line = p; /* line number */ - for (*line = p; *p && !isspace(*p); p++) + for (*line = p; *p && !IS_SPACE(*p); p++) ; if (*p == 0) return (-1); *p++ = 0; - for ( ; isspace(*p); p++) /* (skip blanks) */ + for ( ; *p && IS_SPACE(*p); p++) /* (skip blanks) */ ; if (*p == 0) return (-1); *file = p; /* file name */ - for (*file = p; *p && !isspace(*p); p++) + for (*file = p; *p && !IS_SPACE(*p); p++) ; if (*p == 0) return (-1);