[BACK]Return to main.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / error

Diff for /src/usr.bin/error/Attic/main.c between version 1.4 and 1.5

version 1.4, 2000/06/30 16:00:12 version 1.5, 2000/08/12 02:32:49
Line 76 
Line 76 
   
 int     errorsort();  int     errorsort();
 void    onintr();  void    onintr();
   void    usage();
   
 /*  /*
  *      error [-I ignorename] [-n] [-q] [-t suffixlist] [-s] [-v] [infile]   *      error [-I ignorename] [-n] [-q] [-t suffixlist] [-s] [-v] [infile]
  *   *
Line 110 
Line 112 
  *              Take the following argument and use it as the name of   *              Take the following argument and use it as the name of
  *              the pascal source file, suffix .p   *              the pascal source file, suffix .p
  *   *
  *      -E:     show the errors in sorted order; intended for  
  *              debugging.  
  *  
  *      -S:     show the errors in unsorted order   *      -S:     show the errors in unsorted order
  *              (as they come from the error file)   *              (as they come from the error file)
  *   *
  *      infile: The error messages come from this file.   *      infile: The error messages come from this file.
  *              Default: stdin   *              Default: stdin
  */   */
   int
 main(argc, argv)  main(argc, argv)
         int     argc;          int argc;
         char    *argv[];          char *argv[];
 {  {
         char    *cp;          char *ignorename = 0;
         char    *ignorename = 0;          char **ed_argv;         /* return from touchfiles */
         int     ed_argc;          int ch, ed_argc;
         char    **ed_argv;              /*return from touchfiles*/  
         boolean show_errors = FALSE;          boolean show_errors = FALSE;
         boolean Show_Errors = FALSE;          boolean Show_Errors = FALSE;
         boolean pr_summary = FALSE;          boolean pr_summary = FALSE;
         boolean edit_files = FALSE;          boolean edit_files = FALSE;
   
         errorfile = stdin;          errorfile = stdin;
         if (argc > 1) for(; (argc > 1) && (argv[1][0] == '-'); argc--, argv++){          while ((ch = getopt(argc, argv, "STnqsvI:t:")) != -1)
                 for (cp = argv[1] + 1; *cp; cp++) switch(*cp){                  switch (ch) {
                 default:                  case 'S':
                         errx(1, "-%c: Unknown flag", *cp);                          Show_Errors = TRUE;
                         break;                          break;
                   case 'T':
                 case 'n':       notouch = TRUE; break;                          terse = TRUE;
                 case 'q':       query = TRUE;   break;  
                 case 'S':       Show_Errors = TRUE;     break;  
                 case 's':       pr_summary = TRUE;      break;  
                 case 'v':       edit_files = TRUE;      break;  
                 case 'T':       terse = TRUE;   break;  
                 case 't':  
                         *cp-- = 0; argv++; argc--;  
                         if (argc > 1){  
                                 suffixlist = argv[1];  
                         }  
                         break;                          break;
                 case 'I':       /*ignore file name*/                  case 'n':
                         *cp-- = 0; argv++; argc--;                          notouch = TRUE;
                         if (argc > 1)  
                                 ignorename = argv[1];  
                         break;                          break;
                   case 'q':
                           query = TRUE;
                           break;
                   case 's':
                           pr_summary = TRUE;
                           break;
                   case 'v':
                           edit_files = TRUE;
                           break;
                   case 'I':
                           ignorename = optarg;
                           break;
                   case 't':
                           suffixlist = optarg;
                           break;
                   default:
                           usage();
                 }                  }
         }  
           argc -= optind;
           argv += optind;
   
         if (notouch)          if (notouch)
                 suffixlist = 0;                  suffixlist = NULL;
         if (argc > 1){  
           if (argc > 1) {
                 if (argc > 3)                  if (argc > 3)
                         errx(3, "Only takes 0 or 1 arguments\n");                          errx(3, "Only takes 0 or 1 arguments.\n");
                 if ( (errorfile = fopen(argv[1], "r")) == NULL)                  if ((errorfile = fopen(argv[1], "r")) == NULL)
                         err(4, "%s", argv[1]);                          err(4, "%s", argv[1]);
         }          }
         if ( (queryfile = fopen(im_on, "r")) == NULL){  
                 if (query){          if ((queryfile = fopen(im_on, "r")) == NULL) {
                   if (query) {
                         errx(9, "Can't open \"%s\" to query the user.", im_on);                          errx(9, "Can't open \"%s\" to query the user.", im_on);
                         exit(9);                          exit(9);
                 }                  }
         }          }
   
         if (signal(SIGINT, onintr) == SIG_IGN)          if (signal(SIGINT, onintr) == SIG_IGN)
                 signal(SIGINT, SIG_IGN);                  signal(SIGINT, SIG_IGN);
         if (signal(SIGTERM, onintr) == SIG_IGN)          if (signal(SIGTERM, onintr) == SIG_IGN)
                 signal(SIGTERM, SIG_IGN);                  signal(SIGTERM, SIG_IGN);
   
         getignored(ignorename);          getignored(ignorename);
         eaterrors(&nerrors, &errors);          eaterrors(&nerrors, &errors);
   
         if (Show_Errors)          if (Show_Errors)
                 printerrors(TRUE, nerrors, errors);                  printerrors(TRUE, nerrors, errors);
   
         qsort(errors, nerrors, sizeof(Eptr), errorsort);          qsort(errors, nerrors, sizeof(Eptr), errorsort);
   
         if (show_errors)          if (show_errors)
                 printerrors(FALSE, nerrors, errors);                  printerrors(FALSE, nerrors, errors);
   
         findfiles(nerrors, errors, &nfiles, &files);          findfiles(nerrors, errors, &nfiles, &files);
   
 #define P(msg, arg) fprintf(stdout, msg, arg)  #define P(msg, arg) fprintf(stdout, msg, arg)
         if (pr_summary){  
             if (nunknown)          if (pr_summary) {
               P("%d Errors are unclassifiable.\n", nunknown);                  if (nunknown)
             if (nignore)                          P("%d Errors are unclassifiable.\n", nunknown);
               P("%d Errors are classifiable, but totally discarded.\n",nignore);                  if (nignore)
             if (nsyncerrors)                          P("%d Errors are classifiable, but totally discarded.\n",nignore);
               P("%d Errors are synchronization errors.\n", nsyncerrors);                  if (nsyncerrors)
             if (nignore)                          P("%d Errors are synchronization errors.\n", nsyncerrors);
               P("%d Errors are discarded because they refer to sacrosinct files.\n", ndiscard);                  if (nignore)
             if (nnulled)                          P("%d Errors are discarded because they refer to sacrosinct files.\n", ndiscard);
               P("%d Errors are nulled because they refer to specific functions.\n", nnulled);                  if (nnulled)
             if (nnonspec)                          P("%d Errors are nulled because they refer to specific functions.\n", nnulled);
               P("%d Errors are not specific to any file.\n", nnonspec);                  if (nnonspec)
             if (nthisfile)                          P("%d Errors are not specific to any file.\n", nnonspec);
               P("%d Errors are specific to a given file, but not to a line.\n", nthisfile);                  if (nthisfile)
             if (ntrue)                          P("%d Errors are specific to a given file, but not to a line.\n", nthisfile);
               P("%d Errors are true errors, and can be inserted into the files.\n", ntrue);                  if (ntrue)
                           P("%d Errors are true errors, and can be inserted into the files.\n", ntrue);
         }          }
   
         filenames(nfiles, files);          filenames(nfiles, files);
         fflush(stdout);          fflush(stdout);
   
         if (touchfiles(nfiles, files, &ed_argc, &ed_argv) && edit_files)          if (touchfiles(nfiles, files, &ed_argc, &ed_argv) && edit_files)
                 forkvi(ed_argc, ed_argv);                  forkvi(ed_argc, ed_argv);
 }  }
Line 213 
Line 232 
         int     argc;          int     argc;
         char    **argv;          char    **argv;
 {  {
         if (query){          if (query) {
                 switch(inquire(terse                  switch (inquire(terse ? "Edit? " :
                     ? "Edit? "                      "Do you still want to edit the files you touched? ")) {
                     : "Do you still want to edit the files you touched? ")){  
                 case Q_NO:                  case Q_NO:
                 case Q_no:                  case Q_no:
                         return;                          return;
Line 224 
Line 242 
                         break;                          break;
                 }                  }
         }          }
   
         /*          /*
          *      ed_agument's first argument is           *      ed_agument's first argument is
          *      a vi/ex compatabile search argument           *      a vi/ex compatabile search argument
Line 231 
Line 250 
          */           */
         try("vi", argc, argv);          try("vi", argc, argv);
         try("ex", argc, argv);          try("ex", argc, argv);
         try("ed", argc-1, argv+1);          try("ed", argc - 1, argv + 1);
         fprintf(stdout, "Can't find any editors.\n");          fprintf(stdout, "Can't find any editors.\n");
 }  }
   
 try(name, argc, argv)  try(name, argc, argv)
         char    *name;          char *name;
         int     argc;          int argc;
         char    **argv;          char **argv;
 {  {
         argv[0] = name;          argv[0] = name;
         wordvprint(stdout, argc, argv);          wordvprint(stdout, argc, argv);
Line 246 
Line 265 
         fflush(stderr);          fflush(stderr);
         fflush(stdout);          fflush(stdout);
         sleep(2);          sleep(2);
   
         if (freopen(im_on, "r", stdin) == NULL)          if (freopen(im_on, "r", stdin) == NULL)
                 return;                  return;
         if (freopen(im_on, "w", stdout) == NULL)          if (freopen(im_on, "w", stdout) == NULL)
                 return;                  return;
   
         execvp(name, argv);          execvp(name, argv);
 }  }
   
 int errorsort(epp1, epp2)  int errorsort(epp1, epp2)
                 Eptr    *epp1, *epp2;          Eptr *epp1, *epp2;
 {  {
         reg     Eptr    ep1, ep2;          reg Eptr ep1, ep2;
                 int     order;          int order;
   
         /*          /*
          *      Sort by:           *      Sort by:
          *      1)      synchronization, non specific, discarded errors first;           *      1) synchronization, non specific, discarded errors first;
          *      2)      nulled and true errors last           *      2) nulled and true errors last
          *              a)      grouped by similar file names           *          a) grouped by similar file names
          *                      1)      grouped in ascending line number           *          b) grouped in ascending line number
          */           */
         ep1 = *epp1; ep2 = *epp2;          ep1 = *epp1; ep2 = *epp2;
         if (ep1 == 0 || ep2 == 0)          if (ep1 == 0 || ep2 == 0)
                 return(0);                  return (0);
         if ( (NOTSORTABLE(ep1->error_e_class)) ^ (NOTSORTABLE(ep2->error_e_class))){  
                 return(NOTSORTABLE(ep1->error_e_class) ? -1 : 1);          if ((NOTSORTABLE(ep1->error_e_class)) ^
               (NOTSORTABLE(ep2->error_e_class))) {
                   return (NOTSORTABLE(ep1->error_e_class) ? -1 : 1);
         }          }
   
         if (NOTSORTABLE(ep1->error_e_class))    /* then both are */          if (NOTSORTABLE(ep1->error_e_class))    /* then both are */
                 return(ep1->error_no - ep2->error_no);                  return (ep1->error_no - ep2->error_no);
   
         order = strcmp(ep1->error_text[0], ep2->error_text[0]);          order = strcmp(ep1->error_text[0], ep2->error_text[0]);
         if (order == 0){          if (order == 0)
                 return(ep1->error_line - ep2->error_line);                  return (ep1->error_line - ep2->error_line);
         }  
         return(order);          return (order);
   }
   
   void
   usage()
   {
           extern char *__progname;
   
           (void)fprintf(stderr,
               "usage: %s [-STnsqv] [-I ignorefile] [-t suffixlist] [name]\n",
               __progname);
           exit(1);
 }  }

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.5