[BACK]Return to pi.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / usr.bin / error

Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.

Diff for /src/usr.bin/error/pi.c between version 1.13 and 1.14

version 1.13, 2009/08/13 02:10:50 version 1.14, 2009/08/13 03:07:49
Line 43  __RCSID("$NetBSD$");
Line 43  __RCSID("$NetBSD$");
 #include <stdlib.h>  #include <stdlib.h>
 #include "error.h"  #include "error.h"
   
 static  char    *c_linenumber;  static char *c_linenumber;
 static  char    *unk_hdr[] = {"In", "program", "???"};  static char *unk_hdr[] = {"In", "program", "???"};
 static  char    **c_header = &unk_hdr[0];  static char **c_header = &unk_hdr[0];
   
 static boolean alldigits(char *);  static boolean alldigits(char *);
 static boolean isdateformat(int, char **);  static boolean isdateformat(int, char **);
Line 54  static boolean piptr(char *);
Line 54  static boolean piptr(char *);
   
   
 /*  /*
  *      Attempt to handle error messages produced by pi (and by pc)   * Attempt to handle error messages produced by pi (and by pc)
  *   *
  *      problem #1:     There is no file name available when a file does not   *      problem #1:     There is no file name available when a file does not
  *                      use a #include; this will have to be given to error   *                      use a #include; this will have to be given to error
Line 88  static boolean piptr(char *);
Line 88  static boolean piptr(char *);
  *      define msg = .*   *      define msg = .*
  *      define digit = [0-9]   *      define digit = [0-9]
  *      definename = .*   *      definename = .*
  *      define date_format letter*3 letter*3 (digit | (digit digit))   *      define date_format letter*3 letter*3 (digit | (digit digit))
  *                      (digit | (digit digit)):digit*2 digit*4   *                      (digit | (digit digit)):digit*2 digit*4
  *   *
  *      {e,E} (piptr) (msg)     Encounter an error during textual scan   *      {e,E} (piptr) (msg)     Encounter an error during textual scan
Line 99  static boolean piptr(char *);
Line 99  static boolean piptr(char *);
  *      ... (msg)               When refer to the previous line   *      ... (msg)               When refer to the previous line
  *      'In' ('procedure'|'function'|'program') (name):   *      'In' ('procedure'|'function'|'program') (name):
  *                              pi is now complaining about 2nd pass errors.   *                              pi is now complaining about 2nd pass errors.
  *   *
  *      Here is the output from a compilation   *      Here is the output from a compilation
  *   *
  *   *
Line 138  static boolean piptr(char *);
Line 138  static boolean piptr(char *);
  */   */
 static char *Months[] = {  static char *Months[] = {
         "Jan", "Feb", "Mar", "Apr", "May", "Jun",          "Jan", "Feb", "Mar", "Apr", "May", "Jun",
         "Jul", "Aug", "Sep", "Oct","Nov", "Dec",          "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
         0          0
 };  };
 static char *Days[] = {  static char *Days[] = {
         "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", 0          "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", 0
 };  };
 static char *Piroutines[] = {  static char *Piroutines[] = {
                 "program", "function", "procedure", 0          "program", "function", "procedure", 0
 };  };
   
   
 static boolean  structured, multiple;  static boolean structured, multiple;
   
 static char *pi_Endmatched[] = {"End", "matched"};  static char *pi_Endmatched[] = {"End", "matched"};
 static char *pi_Inserted[] = {"Inserted", "keyword", "end", "matching"};  static char *pi_Inserted[] = {"Inserted", "keyword", "end", "matching"};
Line 167  alldigits(char *string)
Line 167  alldigits(char *string)
 {  {
         for (; *string && isdigit((unsigned char)*string); string++)          for (; *string && isdigit((unsigned char)*string); string++)
                 continue;                  continue;
         return(*string == '\0');          return (*string == '\0');
 }  }
   
 static boolean  static boolean
 instringset(char *member, char **set)  instringset(char *member, char **set)
 {  {
         for(; *set; set++){          for (; *set; set++) {
                 if (strcmp(*set, member) == 0)                  if (strcmp(*set, member) == 0)
                         return(TRUE);                          return (TRUE);
         }          }
         return(FALSE);          return (FALSE);
 }  }
   
 static boolean  static boolean
 isdateformat(int wordc, char **wordv)  isdateformat(int wordc, char **wordv)
 {  {
         return(          return (
                 (wordc == 5)                  (wordc == 5)
              && (instringset(wordv[0], Days))               && (instringset(wordv[0], Days))
              && (instringset(wordv[1], Months))               && (instringset(wordv[1], Months))
              && (alldigits(wordv[2]))               && (alldigits(wordv[2]))
              && (alldigits(wordv[4])) );               && (alldigits(wordv[4])));
 }  }
   
 static boolean  static boolean
 piptr(char *string)  piptr(char *string)
 {  {
         if (*string != '-')          if (*string != '-')
                 return(FALSE);                  return (FALSE);
         while (*string && *string == '-')          while (*string && *string == '-')
                 string++;                  string++;
         if (*string != '^')          if (*string != '^')
                 return(FALSE);                  return (FALSE);
         string++;          string++;
         while (*string && *string == '-')          while (*string && *string == '-')
                 string++;                  string++;
         return(*string == '\0');          return (*string == '\0');
 }  }
   
 extern  int     wordc;  extern int wordc;
 extern  char    **wordv;  extern char **wordv;
   
 Errorclass  Errorclass
 pi(void)  pi(void)
 {  {
         char    **nwordv;          char **nwordv;
   
         nwordv = NULL;          nwordv = NULL;
         if (wordc < 2)          if (wordc < 2)
Line 221  pi(void)
Line 221  pi(void)
             && ( (wordv[1][0] == 'e') || (wordv[1][0] == 'E') )              && ( (wordv[1][0] == 'e') || (wordv[1][0] == 'E') )
             && ( piptr(wordv[2]) )              && ( piptr(wordv[2]) )
         ) {          ) {
                 boolean longpiptr = 0;                  boolean longpiptr = 0;
   
                 /*                  /*
                  *      We have recognized a first pass error of the form:                   *      We have recognized a first pass error of the form:
                  *      letter ------^---- message                   *      letter ------^---- message
Line 250  pi(void)
Line 251  pi(void)
                 nwordv = wordvsplice(longpiptr ? 2 : 4, wordc, wordv+1);                  nwordv = wordvsplice(longpiptr ? 2 : 4, wordc, wordv+1);
                 nwordv[0] = strdup(currentfilename);                  nwordv[0] = strdup(currentfilename);
                 nwordv[1] = strdup(c_linenumber);                  nwordv[1] = strdup(c_linenumber);
                 if (!longpiptr){                  if (!longpiptr) {
                         nwordv[2] = "pascal errortype";                          nwordv[2] = "pascal errortype";
                         nwordv[3] = wordv[1];                          nwordv[3] = wordv[1];
                         nwordv[4] = strdup("%%%\n");                          nwordv[4] = strdup("%%%\n");
Line 259  pi(void)
Line 260  pi(void)
                 }                  }
                 wordv = nwordv - 1;             /* convert to 1 based */                  wordv = nwordv - 1;             /* convert to 1 based */
                 wordc += longpiptr ? 2 : 4;                  wordc += longpiptr ? 2 : 4;
                 return(C_TRUE);                  return (C_TRUE);
         }          }
         if (   (wordc >= 4)          if ((wordc >= 4)
             && (strlen(wordv[1]) == 1)              && (strlen(wordv[1]) == 1)
             && ( (*wordv[1] == 'E') || (*wordv[1] == 'w') || (*wordv[1] == 'e') )              && ((*wordv[1] == 'E') || (*wordv[1] == 'w') || (*wordv[1] == 'e'))
             && (alldigits(wordv[2]))              && (alldigits(wordv[2]))
             && (strlen(wordv[3]) == 1)              && (strlen(wordv[3]) == 1)
             && (wordv[3][0] == '-')              && (wordv[3][0] == '-')
         ){          ) {
                 /*                  /*
                  *      Message of the form: letter linenumber - message                   * Message of the form: letter linenumber - message
                  *      Turn into form: filename linenumber letter - message                   * Turn into form: filename linenumber letter - message
                  */                   */
                 language = INPI;                  language = INPI;
                 nwordv = wordvsplice(1, wordc, wordv + 1);                  nwordv = wordvsplice(1, wordc, wordv + 1);
Line 280  pi(void)
Line 281  pi(void)
                 c_linenumber = wordv[2];                  c_linenumber = wordv[2];
                 wordc += 1;                  wordc += 1;
                 wordv = nwordv - 1;                  wordv = nwordv - 1;
                 return(C_TRUE);                  return (C_TRUE);
         }          }
         if (   (wordc >= 3)          if ((wordc >= 3)
             && (strlen(wordv[1]) == 1)              && (strlen(wordv[1]) == 1)
             && ( (*(wordv[1]) == 'E') || (*(wordv[1]) == 'w') || (*(wordv[1]) == 'e') )              && ((*(wordv[1]) == 'E') || (*(wordv[1]) == 'w') || (*(wordv[1]) == 'e'))
             && (strlen(wordv[2]) == 1)              && (strlen(wordv[2]) == 1)
             && (wordv[2][0] == '-')              && (wordv[2][0] == '-')
         ) {          ) {
                 /*                  /*
                  *      Message of the form: letter - message                   * Message of the form: letter - message
                  *      This happens only when we are traversing the tree                   *
                  *      during the second pass of pi, and discover semantic                   * This happens only when we are traversing the tree
                  *      errors.                   * during the second pass of pi, and discover semantic
                    * errors.
                    *
                    * We have already (presumably) saved the header message
                    * and can now construct a nulled error message for the
                    * current file.
                  *                   *
                  *      We have already (presumably) saved the header message                   * Turns into a message of the form:
                  *      and can now construct a nulled error message for the                   *      filename (header) letter - message
                  *      current file.  
                  *                   *
                  *      Turns into a message of the form:                   * First, see if it is a message referring to more than
                  *      filename (header) letter - message                   * one line number.  Only of the form:
                  *                   *      %s undefined on line%s
                  *      First, see if it is a message referring to more than                   *      %s improperly used on line%s
                  *      one line number.  Only of the form:  
                  *              %s undefined on line%s  
                  *              %s improperly used on line%s  
                  */                   */
                 boolean undefined = 0;                  boolean undefined = 0;
                 int     wordindex;                  int wordindex;
   
                 language = INPI;                  language = INPI;
                 if (    (undefined = (wordvcmp(wordv+2, 3, pi_und1) == 0) )                  if ((undefined = (wordvcmp(wordv+2, 3, pi_und1) == 0))
                      || (undefined = (wordvcmp(wordv+2, 3, pi_und2) == 0) )                       || (undefined = (wordvcmp(wordv+2, 3, pi_und2) == 0))
                      || (wordvcmp(wordv+2, 4, pi_imp1) == 0)                       || (wordvcmp(wordv+2, 4, pi_imp1) == 0)
                      || (wordvcmp(wordv+2, 4, pi_imp2) == 0)                       || (wordvcmp(wordv+2, 4, pi_imp2) == 0)
                 ){                  ) {
                         for (wordindex = undefined ? 5 : 6; wordindex <= wordc;                          for (wordindex = undefined ? 5 : 6; wordindex <= wordc;
                             wordindex++){                              wordindex++) {
                                 if (nwordv) {                                  if (nwordv) {
                                         free(nwordv[0]);                                          free(nwordv[0]);
                                         free(nwordv);                                          free(nwordv);
Line 330  pi(void)
Line 332  pi(void)
                         }                          }
                         wordc = undefined ? 4 : 5;                          wordc = undefined ? 4 : 5;
                         wordv = nwordv - 1;                          wordv = nwordv - 1;
                         return(C_TRUE);                          return (C_TRUE);
                 }                  }
   
                 nwordv = wordvsplice(1+3, wordc, wordv+1);                  nwordv = wordvsplice(1+3, wordc, wordv+1);
Line 340  pi(void)
Line 342  pi(void)
                 nwordv[3] = strdup(c_header[2]);                  nwordv[3] = strdup(c_header[2]);
                 wordv = nwordv - 1;                  wordv = nwordv - 1;
                 wordc += 1 + 3;                  wordc += 1 + 3;
                 return(C_THISFILE);                  return (C_THISFILE);
         }          }
         if (strcmp(wordv[1], "...") == 0){          if (strcmp(wordv[1], "...") == 0) {
                 /*                  /*
                  *      have a continuation error message                   * have a continuation error message
                  *      of the form: ... message                   * of the form: ... message
                  *      Turn into form : filename linenumber message                   * Turn into form : filename linenumber message
                  */                   */
                 language = INPI;                  language = INPI;
                 nwordv = wordvsplice(1, wordc, wordv+1);                  nwordv = wordvsplice(1, wordc, wordv+1);
Line 354  pi(void)
Line 356  pi(void)
                 nwordv[1] = strdup(c_linenumber);                  nwordv[1] = strdup(c_linenumber);
                 wordv = nwordv - 1;                  wordv = nwordv - 1;
                 wordc += 1;                  wordc += 1;
                 return(C_TRUE);                  return (C_TRUE);
         }          }
         if(   (wordc == 6)          if ((wordc == 6)
            && (lastchar(wordv[6]) == ':')             && (lastchar(wordv[6]) == ':')
            && (isdateformat(5, wordv + 1))             && (isdateformat(5, wordv + 1))
         ){          ) {
                 /*                  /*
                  *      Have message that tells us we have changed files                   * Have message that tells us we have changed files
                  */                   */
                 language = INPI;                  language = INPI;
                 currentfilename = strdup(wordv[6]);                  currentfilename = strdup(wordv[6]);
                 clob_last(currentfilename, '\0');                  clob_last(currentfilename, '\0');
                 return(C_SYNC);                  return (C_SYNC);
         }          }
         if(   (wordc == 3)          if ((wordc == 3)
            && (strcmp(wordv[1], "In") == 0)             && (strcmp(wordv[1], "In") == 0)
            && (lastchar(wordv[3]) == ':')             && (lastchar(wordv[3]) == ':')
            && (instringset(wordv[2], Piroutines))             && (instringset(wordv[2], Piroutines))
         ) {          ) {
                 language = INPI;                  language = INPI;
                 c_header = wordvsplice(0, wordc, wordv+1);                  c_header = wordvsplice(0, wordc, wordv+1);
                 return(C_SYNC);                  return (C_SYNC);
         }          }
   
         /*          /*
          *      now, check for just the line number followed by the text           * now, check for just the line number followed by the text
          */           */
         if (alldigits(wordv[1])){          if (alldigits(wordv[1])) {
                 language = INPI;                  language = INPI;
                 c_linenumber = wordv[1];                  c_linenumber = wordv[1];
                 return(C_IGNORE);                  return (C_IGNORE);
         }          }
   
         /*          /*
          *      Attempt to match messages refering to a line number           * Attempt to match messages refering to a line number
          *           *
          *      Multiply defined label in case, lines %d and %d           * Multiply defined label in case, lines %d and %d
          *      Goto %s from line %d is into a structured statement           * Goto %s from line %d is into a structured statement
          *      End matched %s on line %d           * End matched %s on line %d
          *      Inserted keyword end matching %s on line %d           * Inserted keyword end matching %s on line %d
          */           */
         multiple = structured = 0;          multiple = structured = 0;
         if (          if (
                ( (wordc == 6) && (wordvcmp(wordv+1, 2, pi_Endmatched) == 0))                 ((wordc == 6) && (wordvcmp(wordv+1, 2, pi_Endmatched) == 0))
             || ( (wordc == 8) && (wordvcmp(wordv+1, 4, pi_Inserted) == 0))              || ((wordc == 8) && (wordvcmp(wordv+1, 4, pi_Inserted) == 0))
             || ( multiple = ((wordc == 9) && (wordvcmp(wordv+1,6, pi_multiple) == 0) ) )              || (multiple = ((wordc == 9) && (wordvcmp(wordv+1,6, pi_multiple) == 0)))
             || ( structured = ((wordc == 10) && (wordvcmp(wordv+6,5, pi_structured) == 0 ) ))              || (structured = ((wordc == 10) && (wordvcmp(wordv+6,5, pi_structured) == 0 )))
         ){          ) {
                 language = INPI;                  language = INPI;
                 nwordv = wordvsplice(2, wordc, wordv+1);                  nwordv = wordvsplice(2, wordc, wordv+1);
                 nwordv[0] = strdup(currentfilename);                  nwordv[0] = strdup(currentfilename);
Line 407  pi(void)
Line 411  pi(void)
                 wordc += 2;                  wordc += 2;
                 wordv = nwordv - 1;                  wordv = nwordv - 1;
                 if (!multiple)                  if (!multiple)
                         return(C_TRUE);                          return (C_TRUE);
                 erroradd(wordc, nwordv, C_TRUE, C_UNKNOWN);                  erroradd(wordc, nwordv, C_TRUE, C_UNKNOWN);
                 nwordv = wordvsplice(0, wordc, nwordv);                  nwordv = wordvsplice(0, wordc, nwordv);
                 nwordv[1] = wordv[wordc - 2];                  nwordv[1] = wordv[wordc - 2];
                 return(C_TRUE);                  return (C_TRUE);
         }          }
         return(C_UNKNOWN);          return (C_UNKNOWN);
 }  }

Legend:
Removed from v.1.13  
changed lines
  Added in v.1.14

CVSweb <webmaster@jp.NetBSD.org>