home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / VILE327.ZIP / VILE327.TAR / vile3.27 / finderr.c < prev    next >
C/C++ Source or Header  |  1992-12-14  |  6KB  |  243 lines

  1. /* Find the next error in mentioned in the shell output window.
  2.  * Written for vile by Paul Fox, (c)1990
  3.  *
  4.  * $Log: finderr.c,v $
  5.  * Revision 1.13  1992/12/04  09:12:25  foxharp
  6.  * deleted unused assigns
  7.  *
  8.  * Revision 1.12  1992/08/19  22:57:45  foxharp
  9.  * no longer need to multiply NFILEN -- it's bigger
  10.  *
  11.  * Revision 1.11  1992/07/16  22:06:58  foxharp
  12.  * honor the "Entering/Leaving directory" messages that GNU make puts out
  13.  *
  14.  * Revision 1.10  1992/05/16  12:00:31  pgf
  15.  * prototypes/ansi/void-int stuff/microsoftC
  16.  *
  17.  * Revision 1.9  1992/03/19  23:35:27  pgf
  18.  * use b_linecount to index from end of file instead of top, to be
  19.  * less affected by insertions deletions up above
  20.  *
  21.  * Revision 1.8  1992/03/05  09:01:12  pgf
  22.  * shortened "found error" msg, and force it
  23.  *
  24.  * Revision 1.7  1992/01/05  00:06:13  pgf
  25.  * split mlwrite into mlwrite/mlprompt/mlforce to make errors visible more
  26.  * often.  also normalized message appearance somewhat.
  27.  *
  28.  * Revision 1.6  1991/11/01  14:38:00  pgf
  29.  * saber cleanup
  30.  *
  31.  * Revision 1.5  1991/09/20  13:11:53  pgf
  32.  * protect against passing null l_text pointer to sscanf
  33.  *
  34.  * Revision 1.4  1991/08/07  12:35:07  pgf
  35.  * added RCS log messages
  36.  *
  37.  * revision 1.3
  38.  * date: 1991/08/06 15:21:44;
  39.  * sprintf changes
  40.  * 
  41.  * revision 1.2
  42.  * date: 1991/06/25 19:52:42;
  43.  * massive data structure restructure
  44.  * 
  45.  * revision 1.1
  46.  * date: 1990/09/21 10:25:19;
  47.  * initial vile RCS revision
  48. */
  49.  
  50. #include    "estruct.h"
  51. #include        "edef.h"
  52.  
  53. #if FINDERR
  54.  
  55. #ifndef NULL
  56. #define NULL 0
  57. #endif
  58.  
  59. struct LINE *getdot();
  60.  
  61. /* edits the file and goes to the line pointed at by the next compiler
  62.         error in the "[output]" window.  It unfortunately doesn't mark
  63.         the lines for you, so adding lines to the file throws off the
  64.         later numbering.  Solutions to this seem messy at the moment */
  65.  
  66. /* ARGSUSED */
  67. int
  68. finderr(f,n)
  69. int f,n;
  70. {
  71.     register BUFFER *sbp;
  72.     register int s;
  73.     struct LINE *dotp;
  74.     int moveddot = FALSE;
  75.     
  76.     int errline;
  77.     char errfile[NFILEN];
  78.     char ferrfile[NFILEN];
  79.     
  80.     static int oerrline = -1;
  81.     static char oerrfile[256];
  82.     static int l = 0;
  83. #define DIRLEVELS 20
  84.     static char *dirs[DIRLEVELS];
  85.  
  86.     /* look up the right buffer */
  87.         if ((sbp=bfind(febuff, NO_CREAT, 0)) == NULL) {
  88.             mlforce("[No buffer to search for errors.]");
  89.                 return(FALSE);
  90.         }
  91.         
  92.         if (newfebuff) {
  93.             oerrline = -1;
  94.             oerrfile[0] = '\0';
  95.         l = 0;
  96.         dirs[0] = NULL;
  97.         }
  98.         newfebuff = FALSE;
  99.  
  100.     dotp = getdot(sbp);
  101.  
  102.     for(;;) {
  103.         /* to use this line, we need both the filename and the line
  104.             number in the expected places, and a different line
  105.             than last time */
  106.         /* accept lines of the form:
  107.             "file.c", line 223: error....
  108.             or
  109.             file.c: 223: error....
  110.         */
  111.         if ( dotp->l_text) {
  112.             char verb[20];
  113.             if ( (sscanf(dotp->l_text,
  114.             "\"%[^\"     ]\", line %d:",errfile,&errline) == 2 ||
  115.                  sscanf(dotp->l_text,
  116.             "%[^:     ]: %d:",errfile,&errline) == 2 
  117.                 ) && (oerrline != errline || 
  118.                     strcmp(errfile,oerrfile))) {
  119.                 break;
  120.             } else if (sscanf(dotp->l_text,
  121.             "%*[^     :`]: %20[^     `] directory `",verb) == 1 ) {
  122.                 char *d = strchr(dotp->l_text,'`') + 1;
  123.                 if (verb[0] == 'E') { /* Entering */
  124.                     if (l < DIRLEVELS)
  125.                         dirs[++l] = d;
  126.                 } else if (verb[0] == 'L'){ /* Leaving */
  127.                     if (l > 0)
  128.                         --l;
  129.                 }
  130.             }
  131.         }
  132.             
  133.         if (lforw(dotp) == sbp->b_line.l) {
  134.             mlforce("[No more errors in %s buffer]", febuff);
  135.             TTbeep();
  136.             /* start over at the top of file */
  137.             putdotback(sbp, lforw(sbp->b_line.l));
  138.             l = 0;
  139.             dirs[0] = NULL;
  140.             return FALSE;
  141.         }
  142.         dotp = lforw(dotp);
  143.         moveddot = TRUE;
  144.     }
  145.     /* put the new dot back, before possible changes to contents
  146.                 of current window from getfile() */
  147.     if (moveddot)
  148.         putdotback(sbp,dotp);
  149.  
  150.     if (dirs[l]) {
  151.         int i = 0;
  152.         while(dirs[l][i] != '\'') {
  153.             ferrfile[i] = dirs[l][i];
  154.             i++;
  155.         }
  156.         ferrfile[i++] = '/';
  157.         strcpy(&ferrfile[i],errfile);
  158.     } else {
  159.         /* lsprintf(ferrfile,"%s/%s",current_directory(FALSE),errfile); */
  160.         strcpy(ferrfile,errfile);
  161.     }
  162.     if (strcmp(ferrfile,curbp->b_bname) &&
  163.         strcmp(ferrfile,curbp->b_fname)) {
  164.         /* if we must change windows */
  165.         struct WINDOW *wp;
  166.         wp = wheadp;
  167.         while (wp != NULL) {
  168.             if (!strcmp(wp->w_bufp->b_bname,ferrfile) ||
  169.                 !strcmp(wp->w_bufp->b_fname,ferrfile))
  170.                 break;
  171.             wp = wp->w_wndp;
  172.         }
  173.         if (wp) {
  174.             curwp = wp;
  175.             make_current(curwp->w_bufp);
  176.             upmode();
  177.         } else {
  178.             s = getfile(ferrfile,TRUE);
  179.             if (s != TRUE)
  180.                 return s;
  181.         }
  182.     }
  183.  
  184.     mlforce("Error: %*S", dotp->l_used, dotp->l_text);
  185.  
  186.     /* it's an absolute move */
  187.     curwp->w_lastdot = curwp->w_dot;
  188.     gotoline(TRUE, -(curbp->b_linecount - errline + 1));
  189.  
  190.     oerrline = errline;
  191.     strcpy(oerrfile,errfile);
  192.  
  193.     return TRUE;
  194.  
  195. }
  196.  
  197. struct LINE *
  198. getdot(bp)
  199. struct BUFFER *bp;
  200. {
  201.     register WINDOW *wp;
  202.     if (bp->b_nwnd) {
  203.         /* scan for windows holding that buffer, 
  204.                     pull dot from the first */
  205.             wp = wheadp;
  206.             while (wp != NULL) {
  207.                     if (wp->w_bufp == bp) {
  208.                             return wp->w_dot.l;
  209.             }
  210.                     wp = wp->w_wndp;
  211.             }
  212.     }
  213.         return bp->b_dot.l;
  214. }
  215.  
  216. void
  217. putdotback(bp,dotp)
  218. struct BUFFER *bp;
  219. struct LINE *dotp;
  220. {
  221.     register WINDOW *wp;
  222.  
  223.     if (bp->b_nwnd) {
  224.             wp = wheadp;
  225.             while (wp != NULL) {
  226.                     if (wp->w_bufp == bp) {
  227.                         wp->w_dot.l = dotp;
  228.                         wp->w_dot.o = 0;
  229.                     wp->w_flag |= WFMOVE;
  230.             }
  231.                     wp = wp->w_wndp;
  232.             }
  233.         return;
  234.     }
  235.     /* then the buffer isn't displayed */
  236.         bp->b_dot.l = dotp;
  237.         bp->b_dot.o = 0;
  238. }
  239.  
  240. #else
  241. finderrhello() { }
  242. #endif
  243.