Add support for :winpos
[MacVim.git] / runtime / doc / doctags.c
blob9213dd9c1e236e2b69e907e522ab127e743e098c
1 /* vim:set ts=4 sw=4:
2 * this program makes a tags file for vim_ref.txt
4 * Usage: doctags vim_ref.txt vim_win.txt ... >tags
6 * A tag in this context is an identifier between stars, e.g. *c_files*
7 */
9 #include <stdio.h>
10 #include <string.h>
11 #include <ctype.h>
12 #include <stdlib.h>
14 #define LINELEN 200
16 int
17 main(argc, argv)
18 int argc;
19 char **argv;
21 char line[LINELEN];
22 char *p1, *p2;
23 char *p;
24 FILE *fd;
26 if (argc <= 1)
28 fprintf(stderr, "Usage: doctags docfile ... >tags\n");
29 exit(1);
31 printf("help-tags\ttags\t1\n");
32 while (--argc > 0)
34 ++argv;
35 fd = fopen(argv[0], "r");
36 if (fd == NULL)
38 fprintf(stderr, "Unable to open %s for reading\n", argv[0]);
39 continue;
41 while (fgets(line, LINELEN, fd) != NULL)
43 p1 = strchr(line, '*'); /* find first '*' */
44 while (p1 != NULL)
46 p2 = strchr(p1 + 1, '*'); /* find second '*' */
47 if (p2 != NULL && p2 > p1 + 1) /* skip "*" and "**" */
49 for (p = p1 + 1; p < p2; ++p)
50 if (*p == ' ' || *p == '\t' || *p == '|')
51 break;
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.
57 if (p == p2
58 && (p1 == line || p1[-1] == ' ' || p1[-1] == '\t')
59 && (strchr(" \t\n\r", p[1]) != NULL
60 || p[1] == '\0'))
62 *p2 = '\0';
63 ++p1;
64 printf("%s\t%s\t/*", p1, argv[0]);
65 while (*p1)
67 /* insert backslash before '\\' and '/' */
68 if (*p1 == '\\' || *p1 == '/')
69 putchar('\\');
70 putchar(*p1);
71 ++p1;
73 printf("*\n");
74 p2 = strchr(p2 + 1, '*'); /* find next '*' */
77 p1 = p2;
80 fclose(fd);
82 return 0;