home *** CD-ROM | disk | FTP | other *** search
- /* throwback.c - program for feeding previously saved throwback output back to
- * the throwback module */
- /* GTK 09.09.1992 */
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <kernel.h>
- #include "throwback.h"
- #include "core.h"
- #include "Error.h"
-
- #ifndef FALSE
- # define FALSE 0
- # define TRUE (!FALSE)
- #endif
-
- #define BUFFERSIZE 4096
-
- /* general purpose buffer */
- char buffer[BUFFERSIZE];
-
- /* holds the pathname found in the previously processed line */
- char *previous_pathname = NULL;
-
- /* skip blanks, tabs and commas */
- void skipblanks(char *str, int *idx)
- {
- while (str[*idx] == ',' || str[*idx] == ' ' || str[*idx] == '\t')
- *idx = *idx + 1;
- }
-
- /* get the pathname from the current line */
- char *getfname(char *from, int *idx)
- {
- int cnt = 0;
- static char fname[BUFSIZ];
-
- /* skip first double quote */
- *idx = *idx + 1;
- /* filename is enclosed in double quotes, so copy until */
- /* second double quote is reached */
- while (from[*idx] != '\"')
- {
- fname[cnt++] = from[*idx];
- *idx = *idx + 1;
- }
-
- fname[cnt] = '\0';
- /* skip last double quote */
- *idx = *idx + 1;
- return (fname);
- }
-
- /* parse one line from the file */
- void parse_string(char *str)
- {
- char *pathname;
- char *mesg;
- int errtype;
- int line;
- int idx;
-
- /* if the first char is not a doublequote, then the line is */
- /* not part of an error/info message */
- if (*str == '\"')
- {
- idx = 0;
-
- /* the filename is _always_ first */
- pathname = getfname(str, &idx);
- if (strcmp(pathname, previous_pathname) != 0)
- {
- throwback_processing(pathname);
- if (previous_pathname != NULL)
- free(previous_pathname);
- previous_pathname = strdup(pathname);
- }
-
- /* next thing is the keyword 'line:' */
-
- skipblanks(str, &idx);
- if (strncmp(&str[idx], "line", 4) == 0)
- {
- /* get line number, then update index into string */
- line = (int) strtol(&str[idx+5], NULL, 10);
- while (str[idx++] != ':');
- }
- else
- /* skip current line if line keyword could */
- /* not be found */
- return;
-
- /* next token is either 'Error:' or 'Warning:' or */
- /* 'Serious Error:', or it is the message. If one */
- /* of the keywords could be found, determine error */
- /* severity and update index into string */
- skipblanks(str, &idx);
- errtype = -1;
- if (strncmp(&str[idx], "Warning:", 8) == 0)
- {
- idx += 8;
- errtype = 0;
- }
- else
- if (strncmp(&str[idx], "Error:", 6) == 0)
- {
- idx += 6;
- errtype = 1;
- }
- else
- if (strncmp(&str[idx], "Serious error:", 14) == 0)
- {
- idx += 14;
- errtype = 2;
- }
-
- /* skip one space after token: */
- if (errtype > -1)
- idx++;
-
- /* get message */
- mesg = &str[idx];
-
- /* and issue throwback message */
- if (errtype == -1)
- throwback_info(line, mesg);
- else
- throwback_error(line, errtype, mesg);
- }
- }
-
- /* parse one file */
- int parse_file(char *filename)
- {
- FILE *infile;
-
- infile = fopen(filename, "r");
- if (infile == NULL)
- return TRUE;
-
- /* pass file line-by-line to parse_line() until the end */
- /* of the file is reached */
- while (!feof(infile))
- {
- fgets(buffer, BUFFERSIZE, infile);
- parse_string(buffer);
- }
- fclose(infile);
- return (FALSE);
- }
-
- BOOL backthrow(int argc, char **argv)
- {
- int i;
- _kernel_oserror *err;
-
- throwback_start();
- if ((err = _kernel_last_oserror()) != NULL)
- {
- _kernel_raise_error(err);
- return(FALSE);
- }
-
- for (i = 0; i < argc; i++)
- if (parse_file(argv[i]))
- {
- strcpy(buffer, "not found: ");
- Error_Report(42, strcat (buffer, argv[i]));
- }
-
- throwback_end();
-
- return TRUE;
- }
-