home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / vim42os2.zip / vim-4.2 / doc / doctags.c next >
C/C++ Source or Header  |  1996-06-18  |  1KB  |  67 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("vim_tags\tvim_tags\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)
  48.                 {
  49.                     for (p = p1 + 1; p < p2; ++p)
  50.                         if (*p == ' ' || *p == '\t' || *p == '|')
  51.                             break;
  52.                     if (p == p2)                /* if it is all valid
  53.                                                     characters */
  54.                     {
  55.                         *p2 = '\0';
  56.                         printf("%s\t%s\t/\\*%s\\*\n", p1 + 1, argv[0], p1 + 1);
  57.                         p2 = strchr(p2 + 1, '*');
  58.                     }
  59.                 }
  60.                 p1 = p2;
  61.             }
  62.         }
  63.         fclose(fd);
  64.     }
  65.     return 0;
  66. }
  67.