home *** CD-ROM | disk | FTP | other *** search
/ Der Mediaplex Sampler - Die 6 von Plex / 6_v_plex.zip / 6_v_plex / DISK5 / DOS_50 / PVIC.ZIP / TAGCMD.C < prev    next >
C/C++ Source or Header  |  1993-04-21  |  4KB  |  134 lines

  1. /* 
  2.  * Routines to implement tags, and, especially, tag stacking.
  3.  * Added by Dave Tutelman - 12/89.
  4.  * The do_tag() routine is a modification of the posted
  5.  * version by Tony Andrews.
  6.  * The untag() routine is new.
  7.  */
  8.  
  9. #include <stdio.h>
  10. #include "pvic.h"
  11. #include "locdefs.h"
  12.  
  13. #define LSIZE   256     /* max. size of a line in the tags file */
  14.  
  15. #ifdef TAGSTACK
  16. /*  We build a stack of file records, on which we push info about
  17.  *  current file when do_tag() is called.
  18.  */
  19. #define TAGSTACKSIZE    12              /* how many tag calls can we stack? */
  20. static  struct filerecord {
  21.         char    *name;                  /* file name pointer */
  22.         int     linenum;                        /* line number when we left */
  23. } tagstack [TAGSTACKSIZE];
  24. static  int     stackindex = 0;         /* here's how we keep track */
  25. #endif
  26.  
  27. extern  char    **files;
  28. extern  int     current_file;
  29. static  void    pushtags(), poptags();
  30.  
  31.  
  32. /*
  33.  * do_tag(tag, force) - goto tag.  If force=(1), dump pending changes.
  34.  */
  35. void
  36. do_tag(tag, force)
  37. char    *tag;
  38. int     force;
  39. {
  40.     FILE    *tp, *fopen();
  41.     char    lbuf[LSIZE];            /* line buffer */
  42.     char    pbuf[LSIZE];            /* search pattern buffer */
  43.     register char   *fname, *str;
  44.     register char   *p;
  45.  
  46.     if ((tp = fopen("tags", "r")) == NULL) {
  47.         error_message("Can't open tags file");
  48.         return;
  49.     }
  50.  
  51.     while (fgets(lbuf, LSIZE, tp) != NULL) {
  52.     
  53.         if ((fname = get_pointer_to_chr_in_string(lbuf, CTRL_I)) == NULL) {
  54.             error_message("Format error in tags file");
  55.             return;
  56.         }
  57.         *fname++ = '\0';
  58.         if ((str = get_pointer_to_chr_in_string(fname, CTRL_I)) == NULL) {
  59.             error_message("Format error in tags file");
  60.             return;
  61.         }
  62.         *str++ = '\0';
  63.  
  64.         if (strcmp(lbuf, tag) == 0) {
  65.  
  66.             /*
  67.              * Scan through the search string. If we see a magic
  68.              * char, we have to quote it. This lets us use "real"
  69.              * implementations of ctags.
  70.              */
  71.             p = pbuf;
  72.             *p++ = *str++;          /* copy the '/' or '?' */
  73.             *p++ = *str++;          /* copy the '^' */
  74.  
  75.             for (; *str != '\0' ;str++) {
  76.                 if (*str == '\\') {
  77.                     *p++ = *str++;
  78.                     *p++ = *str;
  79.                 } else if (get_pointer_to_chr_in_string("/?", *str) != NULL) {
  80.                     if (str[1] != '\n') {
  81.                         *p++ = '\\';
  82.                         *p++ = *str;
  83.                     } else
  84.                         *p++ = *str;
  85.                 } else if (get_pointer_to_chr_in_string("^()*.", *str) != NULL) {
  86.                     *p++ = '\\';
  87.                     *p++ = *str;
  88.                 } else
  89.                     *p++ = *str;
  90.             }
  91.             *p = '\0';
  92.  
  93.  
  94.             /*
  95.              * This looks out of order, but by calling put_string_into_input_buffer()
  96.              * before do_e_command() we keep an extra screen update
  97.              * from occuring. This put_string_into_input_buffers() have no effect
  98.              * until we get back to the main loop, anyway.
  99.              */
  100.  
  101.             put_string_into_input_buffer(pbuf);             /* str has \n at end */
  102.             put_string_into_input_buffer("\007");   /* CTRL_G */
  103.  
  104.             if (do_e_command(fname, force)) {
  105.                 fclose(tp);
  106.                 return;
  107.             } else {
  108.                 put_string_into_input_buffer(NULL);     /* clear the input */
  109.             }
  110.         }
  111.     }
  112.     error_message("Tag not found");
  113.     fclose(tp);
  114. }
  115.  
  116. /*
  117.  * do_untag (spec) - undo the last ':ta' command, popping the tag stack.
  118.  *      spec is the appended character, giving specifics:
  119.  *        '!'   dump pending changes.
  120.  *        'e'   came from K_CCIRCM "shortcut".  do :e# if stack empty.
  121.  *        ' '   do normal untag.
  122.  *        else  bad command.
  123.  */
  124.  
  125. void
  126. do_untag (spec)
  127.   char spec;
  128. {
  129.     bad_command();       /* complain & return */
  130. }
  131.  
  132.  
  133.  
  134.