diff options
author | Sebastien Marie <semarie@cvs.openbsd.org> | 2015-08-22 04:23:08 +0000 |
---|---|---|
committer | Sebastien Marie <semarie@cvs.openbsd.org> | 2015-08-22 04:23:08 +0000 |
commit | 447124d4f712296cdcbc4abbe9832c1ed70c6870 (patch) | |
tree | 946cce4b8134203e53cdbd58fc2e341a70022d93 /usr.bin | |
parent | 46d32e18b9ce13b631d123fe18ee0c6af957d66c (diff) |
system(3) call remove for updating (ctags -u)
done by changing the logic behind updating, by parsing and preloading the tags
file at startup.
"looks good" deraadt@
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/ctags/ctags.1 | 10 | ||||
-rw-r--r-- | usr.bin/ctags/ctags.c | 102 | ||||
-rw-r--r-- | usr.bin/ctags/ctags.h | 4 | ||||
-rw-r--r-- | usr.bin/ctags/tree.c | 7 |
4 files changed, 92 insertions, 31 deletions
diff --git a/usr.bin/ctags/ctags.1 b/usr.bin/ctags/ctags.1 index 39e8d577f1b..a9961586024 100644 --- a/usr.bin/ctags/ctags.1 +++ b/usr.bin/ctags/ctags.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: ctags.1,v 1.28 2015/03/13 19:58:41 jmc Exp $ +.\" $OpenBSD: ctags.1,v 1.29 2015/08/22 04:23:07 semarie Exp $ .\" $NetBSD: ctags.1,v 1.4 1995/03/26 20:14:04 glass Exp $ .\" .\" Copyright (c) 1987, 1990, 1993 @@ -30,7 +30,7 @@ .\" .\" @(#)ctags.1 8.1 (Berkeley) 6/6/93 .\" -.Dd $Mdocdate: March 13 2015 $ +.Dd $Mdocdate: August 22 2015 $ .Dt CTAGS 1 .Os .Sh NAME @@ -89,12 +89,8 @@ The default behaviour is to place them in a file called Update the specified files in the .Ar tags file, that is, all -references to them are deleted, and the new values are appended to the +references to them are regenerated, keeping only the others values in the file. -(Beware: this option is implemented in a way which is rather -slow; it is usually faster to simply rebuild the -.Ar tags -file.) .It Fl v An index of the form expected by vgrind is produced on the standard output. diff --git a/usr.bin/ctags/ctags.c b/usr.bin/ctags/ctags.c index 453708d8167..17473055871 100644 --- a/usr.bin/ctags/ctags.c +++ b/usr.bin/ctags/ctags.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ctags.c,v 1.15 2015/02/08 23:40:34 deraadt Exp $ */ +/* $OpenBSD: ctags.c,v 1.16 2015/08/22 04:23:07 semarie Exp $ */ /* $NetBSD: ctags.c,v 1.4 1995/09/02 05:57:23 jtc Exp $ */ /* @@ -65,6 +65,7 @@ char lbuf[LINE_MAX]; void init(void); void find_entries(char *); +void preload_entries(char *, int, char *[]); int main(int argc, char *argv[]) @@ -75,7 +76,6 @@ main(int argc, char *argv[]) int exit_val; /* exit value */ int step; /* step through args */ int ch; /* getopts char */ - char *cmd; aflag = uflag = NO; while ((ch = getopt(argc, argv, "BFadf:tuwvx")) != -1) @@ -122,6 +122,8 @@ usage: (void)fprintf(stderr, } init(); + if (uflag && !vflag && !xflag) + preload_entries(outfile, argc, argv); for (exit_val = step = 0; step < argc; ++step) if (!(inf = fopen(argv[step], "r"))) { @@ -138,30 +140,10 @@ usage: (void)fprintf(stderr, if (xflag) put_entries(head); else { - if (uflag) { - for (step = 0; step < argc; step++) { - if (asprintf(&cmd, - "mv %s OTAGS; fgrep -v '\t%s\t' OTAGS >%s; rm OTAGS", - outfile, argv[step], outfile) == -1) - err(1, "out of space"); - system(cmd); - free(cmd); - cmd = NULL; - } - aflag = 1; - } if (!(outf = fopen(outfile, aflag ? "a" : "w"))) err(exit_val, "%s", outfile); put_entries(head); (void)fclose(outf); - if (uflag) { - if (asprintf(&cmd, "sort -o %s %s", - outfile, outfile) == -1) - err(1, "out of space"); - system(cmd); - free(cmd); - cmd = NULL; - } } } exit(exit_val); @@ -253,3 +235,79 @@ find_entries(char *file) } /* C */ c_entries(); } + +void +preload_entries(char *tagsfile, int argc, char *argv[]) +{ + FILE *fp; + char line[LINE_MAX]; + char *entry = NULL; + char *file = NULL; + char *pattern = NULL; + char *eol; + int i; + + in_preload = YES; + + if ((fp = fopen(tagsfile, "r")) == NULL) + err(1, "preload_entries: %s", tagsfile); + + while (1) { +next: + if (fgets(line, sizeof(line), fp) == NULL) + break; + + if ((eol = strchr(line, '\n')) == NULL) + errx(1, "preload_entries: line too long"); + *eol = '\0'; + + /* extract entry */ + entry = line; + if ((file = strchr(line, '\t')) == NULL) + errx(1, "preload_entries: couldn't parse entry: %s", + tagsfile); + *file = '\0'; + + /* extract file */ + file++; + if ((pattern = strchr(file, '\t')) == NULL) + errx(1, "preload_entries: couldn't parse filename: %s", + tagsfile); + *pattern = '\0'; + + /* skip this file ? */ + for(i = 0; i < argc; i++) + if (strcmp(file, argv[i]) == 0) + goto next; + + /* rest of string is pattern */ + pattern++; + + /* grab searchar, and don't keep it around the pattern */ + if ((pattern[0] == '/' || pattern[0] == '?') + && pattern[1] == '^') { + + i = strlen(pattern); + if (pattern[i-1] == pattern[0]) + /* remove searchar at end */ + pattern[i-1] = '\0'; + else + errx(1, "preload_entries: couldn't parse " + "pattern: %s", tagsfile); + + /* remove searchar at begin */ + pattern += 2; + } + + /* add entry */ + if ((curfile = strdup(file)) == NULL) + err(1, "preload_entries: strdup"); + (void)strlcpy(lbuf, pattern, sizeof(lbuf)); + pfnote(entry, 0); + } + if (ferror(fp)) + err(1, "preload_entries: fgets"); + + (void)fclose(fp); + in_preload = NO; +} diff --git a/usr.bin/ctags/ctags.h b/usr.bin/ctags/ctags.h index b232027a51c..0a76c2429b7 100644 --- a/usr.bin/ctags/ctags.h +++ b/usr.bin/ctags/ctags.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ctags.h,v 1.8 2014/12/10 19:44:21 tobias Exp $ */ +/* $OpenBSD: ctags.h,v 1.9 2015/08/22 04:23:07 semarie Exp $ */ /* $NetBSD: ctags.h,v 1.3 1995/03/26 20:14:07 glass Exp $ */ /* @@ -56,6 +56,7 @@ typedef struct nd_st { /* sorting structure */ *pat; /* search pattern */ int lno; /* for -x option */ bool been_warned; /* set if noticed dup */ + bool dynfile; /* set if file will need freed */ } NODE; extern char *curfile; /* current input file name */ @@ -72,6 +73,7 @@ extern bool _wht[], _itk[], _btk[]; extern char lbuf[LINE_MAX]; extern char *lbp; extern char searchar; /* ex search character */ +extern bool in_preload; extern int cicmp(char *); extern void get_line(void); diff --git a/usr.bin/ctags/tree.c b/usr.bin/ctags/tree.c index 98ac352b2f5..e419edabdfa 100644 --- a/usr.bin/ctags/tree.c +++ b/usr.bin/ctags/tree.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tree.c,v 1.11 2015/08/20 22:32:41 deraadt Exp $ */ +/* $OpenBSD: tree.c,v 1.12 2015/08/22 04:23:07 semarie Exp $ */ /* $NetBSD: tree.c,v 1.4 1995/03/26 20:14:11 glass Exp $ */ /* @@ -39,6 +39,8 @@ #include "ctags.h" +bool in_preload = NO; + static void add_node(NODE *, NODE *); static void free_tree(NODE *); @@ -79,6 +81,7 @@ pfnote(char *name, int ln) np->lno = ln; np->left = np->right = 0; np->been_warned = NO; + np->dynfile = in_preload; if (!(np->pat = strdup(lbuf))) err(1, NULL); if (!head) @@ -128,6 +131,8 @@ free_tree(NODE *node) free(node->entry); free(node->pat); + if (node->dynfile == YES) + free(node->file); free(node); } } |