home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / vim53os2.zip / vim-5.3 / doc / doctags.c < prev    next >
C/C++ Source or Header  |  1998-08-30  |  2KB  |  82 lines

  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 and is followed by a white character or
  55.                      * end-of-line.
  56.                      */
  57.                     if (p == p2 &&
  58.                             (strchr(" \t\n\r", p[1]) != NULL || p[1] == '\0'))
  59.                     {
  60.                         *p2 = '\0';
  61.                         ++p1;
  62.                         printf("%s\t%s\t/*", p1, argv[0]);
  63.                         while (*p1)
  64.                         {
  65.                             /* insert backslash before '\\' and '/' */
  66.                             if (*p1 == '\\' || *p1 == '/')
  67.                                 putchar('\\');
  68.                             putchar(*p1);
  69.                             ++p1;
  70.                         }
  71.                         printf("*\n");
  72.                         p2 = strchr(p2 + 1, '*');        /* find next '*' */
  73.                     }
  74.                 }
  75.                 p1 = p2;
  76.             }
  77.         }
  78.         fclose(fd);
  79.     }
  80.     return 0;
  81. }
  82.