home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 1 / ARM_CLUB_CD.iso / contents / apps / program / a / backthrow / !backthrow_c_backthrow < prev    next >
Encoding:
Text File  |  1993-02-07  |  4.8 KB  |  176 lines

  1. /* throwback.c - program for feeding previously saved throwback output back to
  2.  * the throwback module */
  3. /* GTK 09.09.1992 */
  4.  
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <string.h>
  8. #include <kernel.h>
  9. #include "throwback.h"
  10. #include "core.h"
  11. #include "Error.h"
  12.  
  13. #ifndef FALSE
  14. #       define FALSE 0
  15. #       define TRUE (!FALSE)
  16. #endif
  17.  
  18. #define BUFFERSIZE 4096
  19.  
  20. /* general purpose buffer */
  21. char buffer[BUFFERSIZE];
  22.  
  23. /* holds the pathname found in the previously processed line */
  24. char *previous_pathname = NULL;
  25.  
  26. /* skip blanks, tabs and commas */
  27. void skipblanks(char *str, int *idx)
  28. {
  29.         while (str[*idx] == ',' || str[*idx] == ' ' || str[*idx] == '\t')
  30.                 *idx = *idx + 1;
  31. }
  32.  
  33. /* get the pathname from the current line */
  34. char *getfname(char *from, int *idx)
  35. {
  36.         int cnt = 0;
  37.         static char fname[BUFSIZ];
  38.  
  39.         /* skip first double quote */
  40.         *idx = *idx + 1;
  41.         /* filename is enclosed in double quotes, so copy until */
  42.         /* second double quote is reached */
  43.         while (from[*idx] != '\"')
  44.         {
  45.                 fname[cnt++] = from[*idx];
  46.                 *idx = *idx + 1;
  47.         }
  48.  
  49.         fname[cnt] = '\0';
  50.         /* skip last double quote */
  51.         *idx = *idx + 1;
  52.         return (fname);
  53. }
  54.  
  55. /* parse one line from the file */
  56. void parse_string(char *str)
  57. {
  58.         char *pathname;
  59.         char *mesg;
  60.         int errtype;
  61.         int line;
  62.         int idx;
  63.  
  64.         /* if the first char is not a doublequote, then the line is */
  65.         /* not part of an error/info message */
  66.         if (*str == '\"')
  67.         {
  68.                 idx = 0;
  69.  
  70.                 /* the filename is _always_ first */
  71.                 pathname = getfname(str, &idx);
  72.                 if (strcmp(pathname, previous_pathname) != 0)
  73.                 {
  74.                         throwback_processing(pathname);
  75.                         if (previous_pathname != NULL)
  76.                                 free(previous_pathname);
  77.                         previous_pathname = strdup(pathname);
  78.                 }
  79.  
  80.                 /* next thing is the keyword 'line:' */
  81.  
  82.                 skipblanks(str, &idx);
  83.                 if (strncmp(&str[idx], "line", 4) == 0)
  84.                 {
  85.                         /* get line number, then update index into string */
  86.                         line = (int) strtol(&str[idx+5], NULL, 10);
  87.                         while (str[idx++] != ':');
  88.                 }
  89.                 else
  90.                         /* skip current line if line keyword could */
  91.                         /* not be found */
  92.                         return;
  93.  
  94.                 /* next token is either 'Error:' or 'Warning:' or */
  95.                 /* 'Serious Error:', or it is the message. If one */
  96.                 /* of the keywords could be found, determine error */
  97.                 /* severity and update index into string */
  98.                 skipblanks(str, &idx);
  99.                 errtype = -1;
  100.                 if (strncmp(&str[idx], "Warning:", 8) == 0)
  101.                 {
  102.                         idx += 8;
  103.                         errtype = 0;
  104.                 }
  105.                 else
  106.                 if (strncmp(&str[idx], "Error:", 6) == 0)
  107.                 {
  108.                         idx += 6;
  109.                         errtype = 1;
  110.                 }
  111.                 else
  112.                 if (strncmp(&str[idx], "Serious error:", 14) == 0)
  113.                 {
  114.                         idx += 14;
  115.                         errtype = 2;
  116.                 }
  117.  
  118.                 /* skip one space after token: */
  119.                 if (errtype > -1)
  120.                         idx++;
  121.  
  122.                 /* get message */
  123.                 mesg = &str[idx];
  124.  
  125.                 /* and issue throwback message */
  126.                 if (errtype == -1)
  127.                         throwback_info(line, mesg);
  128.                 else
  129.                         throwback_error(line, errtype, mesg);
  130.         }
  131. }
  132.  
  133. /* parse one file */
  134. int parse_file(char *filename)
  135. {
  136.         FILE *infile;
  137.  
  138.         infile = fopen(filename, "r");
  139.         if (infile == NULL)
  140.                 return TRUE;
  141.  
  142.         /* pass file line-by-line to parse_line() until the end */
  143.         /* of the file is reached */
  144.         while (!feof(infile))
  145.         {
  146.                 fgets(buffer, BUFFERSIZE, infile);
  147.                 parse_string(buffer);
  148.         }
  149.         fclose(infile);
  150.         return (FALSE);
  151. }
  152.  
  153. BOOL backthrow(int argc, char **argv)
  154. {
  155.         int i;
  156.         _kernel_oserror *err;
  157.  
  158.         throwback_start();
  159.         if ((err = _kernel_last_oserror()) != NULL)
  160.         {
  161.             _kernel_raise_error(err);
  162.             return(FALSE);
  163.         }
  164.  
  165.         for (i = 0; i < argc; i++)
  166.                 if (parse_file(argv[i]))
  167.                 {
  168.                         strcpy(buffer, "not found: ");
  169.                         Error_Report(42, strcat (buffer, argv[i]));
  170.                 }
  171.  
  172.         throwback_end();
  173.  
  174.         return TRUE;
  175. }
  176.