comparison runtime/doc/doctags.c @ 29538:af4ffc4b2a26 v9.0.0110

patch 9.0.0110: help tag generation picks up words in code examples Commit: https://github.com/vim/vim/commit/ddab3ce3457aadffb16ce0127f67a99966a065a8 Author: Carlo Teubner <carlo@cteubner.net> Date: Sat Jul 30 12:03:16 2022 +0100 patch 9.0.0110: help tag generation picks up words in code examples Problem: Help tag generation picks up words in code examples. Solution: Skip over examples. (Carlo Teubner, closes https://github.com/vim/vim/issues/10813)
author Bram Moolenaar <Bram@vim.org>
date Sat, 30 Jul 2022 13:15:03 +0200
parents c002c4899529
children
comparison
equal deleted inserted replaced
29537:a61fbf5cc251 29538:af4ffc4b2a26
19 { 19 {
20 char line[LINELEN]; 20 char line[LINELEN];
21 char *p1, *p2; 21 char *p1, *p2;
22 char *p; 22 char *p;
23 FILE *fd; 23 FILE *fd;
24 int len;
25 int in_example;
24 26
25 if (argc <= 1) 27 if (argc <= 1)
26 { 28 {
27 fprintf(stderr, "Usage: doctags docfile ... >tags\n"); 29 fprintf(stderr, "Usage: doctags docfile ... >tags\n");
28 exit(1); 30 exit(1);
35 if (fd == NULL) 37 if (fd == NULL)
36 { 38 {
37 fprintf(stderr, "Unable to open %s for reading\n", argv[0]); 39 fprintf(stderr, "Unable to open %s for reading\n", argv[0]);
38 continue; 40 continue;
39 } 41 }
42 in_example = 0;
40 while (fgets(line, LINELEN, fd) != NULL) 43 while (fgets(line, LINELEN, fd) != NULL)
41 { 44 {
42 p1 = strchr(line, '*'); /* find first '*' */ 45 if (in_example)
46 {
47 // skip over example; non-blank in first column ends example
48 if (strchr(" \t\n\r", line[0]) != NULL)
49 continue;
50 in_example = 0;
51 }
52 p1 = strchr(line, '*'); // find first '*'
43 while (p1 != NULL) 53 while (p1 != NULL)
44 { 54 {
45 p2 = strchr(p1 + 1, '*'); /* find second '*' */ 55 p2 = strchr(p1 + 1, '*'); // find second '*'
46 if (p2 != NULL && p2 > p1 + 1) /* skip "*" and "**" */ 56 if (p2 != NULL && p2 > p1 + 1) // skip "*" and "**"
47 { 57 {
48 for (p = p1 + 1; p < p2; ++p) 58 for (p = p1 + 1; p < p2; ++p)
49 if (*p == ' ' || *p == '\t' || *p == '|') 59 if (*p == ' ' || *p == '\t' || *p == '|')
50 break; 60 break;
51 /* 61 // Only accept a *tag* when it consists of valid
52 * Only accept a *tag* when it consists of valid 62 // characters, there is white space before it and is
53 * characters, there is white space before it and is 63 // followed by a white character or end-of-line.
54 * followed by a white character or end-of-line.
55 */
56 if (p == p2 64 if (p == p2
57 && (p1 == line || p1[-1] == ' ' || p1[-1] == '\t') 65 && (p1 == line || p1[-1] == ' ' || p1[-1] == '\t')
58 && (strchr(" \t\n\r", p[1]) != NULL 66 && (strchr(" \t\n\r", p[1]) != NULL
59 || p[1] == '\0')) 67 || p[1] == '\0'))
60 { 68 {
61 *p2 = '\0'; 69 *p2 = '\0';
62 ++p1; 70 ++p1;
63 printf("%s\t%s\t/*", p1, argv[0]); 71 printf("%s\t%s\t/*", p1, argv[0]);
64 while (*p1) 72 while (*p1)
65 { 73 {
66 /* insert backslash before '\\' and '/' */ 74 // insert backslash before '\\' and '/'
67 if (*p1 == '\\' || *p1 == '/') 75 if (*p1 == '\\' || *p1 == '/')
68 putchar('\\'); 76 putchar('\\');
69 putchar(*p1); 77 putchar(*p1);
70 ++p1; 78 ++p1;
71 } 79 }
72 printf("*\n"); 80 printf("*\n");
73 p2 = strchr(p2 + 1, '*'); /* find next '*' */ 81 p2 = strchr(p2 + 1, '*'); // find next '*'
74 } 82 }
75 } 83 }
76 p1 = p2; 84 p1 = p2;
77 } 85 }
86 len = strlen(line);
87 if ((len == 2 && strcmp(&line[len - 2], ">\n") == 0)
88 || (len >= 3 && strcmp(&line[len - 3], " >\n") == 0))
89 in_example = 1;
78 } 90 }
79 fclose(fd); 91 fclose(fd);
80 } 92 }
81 return 0; 93 return 0;
82 } 94 }