7
|
1 /* vim:set ts=4 sw=4:
|
|
2 * this program makes a tags file for vim_ref.txt
|
|
3 *
|
|
4 * Usage: doctags vim_ref.txt vim_win.txt ... >tags
|
|
5 *
|
|
6 * A tag in this context is an identifier between stars, e.g. *c_files*
|
|
7 */
|
|
8
|
|
9 #include <stdio.h>
|
|
10 #include <string.h>
|
|
11 #include <ctype.h>
|
|
12 #include <stdlib.h>
|
|
13
|
|
14 #define LINELEN 200
|
|
15
|
|
16 int
|
|
17 main(argc, argv)
|
|
18 int argc;
|
|
19 char **argv;
|
|
20 {
|
|
21 char line[LINELEN];
|
|
22 char *p1, *p2;
|
|
23 char *p;
|
|
24 FILE *fd;
|
|
25
|
|
26 if (argc <= 1)
|
|
27 {
|
|
28 fprintf(stderr, "Usage: doctags docfile ... >tags\n");
|
|
29 exit(1);
|
|
30 }
|
|
31 printf("help-tags\ttags\t1\n");
|
|
32 while (--argc > 0)
|
|
33 {
|
|
34 ++argv;
|
|
35 fd = fopen(argv[0], "r");
|
|
36 if (fd == NULL)
|
|
37 {
|
|
38 fprintf(stderr, "Unable to open %s for reading\n", argv[0]);
|
|
39 continue;
|
|
40 }
|
|
41 while (fgets(line, LINELEN, fd) != NULL)
|
|
42 {
|
|
43 p1 = strchr(line, '*'); /* find first '*' */
|
|
44 while (p1 != NULL)
|
|
45 {
|
|
46 p2 = strchr(p1 + 1, '*'); /* find second '*' */
|
|
47 if (p2 != NULL && p2 > p1 + 1) /* skip "*" and "**" */
|
|
48 {
|
|
49 for (p = p1 + 1; p < p2; ++p)
|
|
50 if (*p == ' ' || *p == '\t' || *p == '|')
|
|
51 break;
|
|
52 /*
|
|
53 * Only accept a *tag* when it consists of valid
|
|
54 * characters, there is white space before it and is
|
|
55 * followed by a white character or end-of-line.
|
|
56 */
|
|
57 if (p == p2
|
|
58 && (p1 == line || p1[-1] == ' ' || p1[-1] == '\t')
|
|
59 && (strchr(" \t\n\r", p[1]) != NULL
|
|
60 || p[1] == '\0'))
|
|
61 {
|
|
62 *p2 = '\0';
|
|
63 ++p1;
|
|
64 printf("%s\t%s\t/*", p1, argv[0]);
|
|
65 while (*p1)
|
|
66 {
|
|
67 /* insert backslash before '\\' and '/' */
|
|
68 if (*p1 == '\\' || *p1 == '/')
|
|
69 putchar('\\');
|
|
70 putchar(*p1);
|
|
71 ++p1;
|
|
72 }
|
|
73 printf("*\n");
|
|
74 p2 = strchr(p2 + 1, '*'); /* find next '*' */
|
|
75 }
|
|
76 }
|
|
77 p1 = p2;
|
|
78 }
|
|
79 }
|
|
80 fclose(fd);
|
|
81 }
|
|
82 return 0;
|
|
83 }
|