From: James Hammons Date: Wed, 11 Jan 2012 17:31:31 +0000 (+0000) Subject: Fix submitted by partycle: Make errors GNU compatible. X-Git-Tag: 1.3.0~39 X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?p=rmac;a=commitdiff_plain;h=1eb7e52711137fdd2c58265bcfb5e71d3e370da0 Fix submitted by partycle: Make errors GNU compatible. --- diff --git a/error.c b/error.c index 26f82b7..c831d73 100644 --- a/error.c +++ b/error.c @@ -10,152 +10,213 @@ #include "token.h" #include "listing.h" -int errcnt; // Error count -char *err_fname; // Name of error message file +int errcnt; // Error count +char * err_fname; // Name of error message file static char nl[] = "\n"; + // -// --- Report error if not at EOL ------------------------------------------------------------------ +// Report error if not at EOL // - -int at_eol(void) { - if(*tok != EOL) +int at_eol(void) +{ + if (*tok != EOL) error("syntax error"); - return(0); + + return 0; } + // -// --- Cannot Create a File ------------------------------------------------------------------------ +// Cannot Create a File // - -void cantcreat(char *fn) { +void cantcreat(char * fn) +{ printf("cannot create: '%s'\n", fn); exit(1); } + // -// --- Setup for Error Message --------------------------------------------------------------------- +// Setup for Error Message // o Create error listing file (if necessary) // o Set current filename // +void err_setup(void) +{ + char fnbuf[FNSIZ]; + + setfnum(cfileno); + + if (err_fname != NULL) + { + strcpy(fnbuf, err_fname); + + if (*fnbuf == EOS) + strcpy(fnbuf, firstfname); + + err_fname = NULL; -void err_setup(void) { - char fnbuf[FNSIZ]; - - setfnum(cfileno); - if(err_fname != NULL) { - strcpy(fnbuf, err_fname); - if(*fnbuf == EOS) { - strcpy(fnbuf, firstfname); - } - err_fname = NULL; - - if((err_fd = open(fnbuf, _OPEN_FLAGS, _PERM_MODE)) < 0) - cantcreat(fnbuf); - err_flag = 1; - } + if ((err_fd = open(fnbuf, _OPEN_FLAGS, _PERM_MODE)) < 0) + cantcreat(fnbuf); + + err_flag = 1; + } } + // -// --- Display Error Message ----------------------------------------------------------------------- +// Display Error Message // +int error(char * s) +{ + char buf[EBUFSIZ]; + unsigned int length; + + err_setup(); + + if (listing > 0) + ship_ln(s); + + sprintf(buf, "%s%d: Error: %s%s", curfname, curlineno, s, nl); + length = strlen(buf); -int error(char *s) { - char buf[EBUFSIZ]; - unsigned int length; + if (err_flag) + write(err_fd, buf, length); + else + printf("%s", buf); - err_setup(); - if(listing > 0) ship_ln(s); - sprintf(buf, "%s[%d]: Error: %s%s", curfname, curlineno, s, nl); - length = strlen(buf); - if(err_flag) write(err_fd, buf, length); - else printf("%s", buf); - taglist('E'); - ++errcnt; + taglist('E'); + ++errcnt; - return(ERROR); + return(ERROR); } -int errors(char *s, char *s1) { - char buf[EBUFSIZ]; - char buf1[EBUFSIZ]; +int errors(char * s, char * s1) +{ + char buf[EBUFSIZ]; + char buf1[EBUFSIZ]; + + err_setup(); + sprintf(buf, s, s1); + + if (listing > 0) + ship_ln(buf); + + sprintf(buf1, "%s%d: Error: %s%s", curfname, curlineno, buf, nl); + + if (err_flag) + write(err_fd, buf1, (LONG)strlen(buf1)); + else + printf("%s", buf1); - err_setup(); - sprintf(buf, s, s1); - if(listing > 0) ship_ln(buf); - sprintf(buf1, "%s[%d]: Error: %s%s", curfname, curlineno, buf, nl); - if(err_flag) write(err_fd, buf1, (LONG)strlen(buf1)); - else printf("%s", buf1); - taglist('E'); - ++errcnt; + taglist('E'); + ++errcnt; - return(ERROR); + return(ERROR); } -int warn(char *s) { - char buf[EBUFSIZ]; +int warn(char * s) +{ + char buf[EBUFSIZ]; - err_setup(); - if(listing > 0) ship_ln(s); - sprintf(buf, "%s[%d]: Warning: %s%s", curfname, curlineno, s, nl); - if(err_flag) write(err_fd, buf, (LONG)strlen(buf)); - else printf("%s", buf); - taglist('W'); + err_setup(); - return(OK); + if (listing > 0) + ship_ln(s); + + sprintf(buf, "%s%d: Warning: %s%s", curfname, curlineno, s, nl); + + if (err_flag) + write(err_fd, buf, (LONG)strlen(buf)); + else + printf("%s", buf); + + taglist('W'); + + return(OK); } -int warns(char *s, char *s1) { - char buf[EBUFSIZ]; - char buf1[EBUFSIZ]; +int warns(char * s, char * s1) +{ + char buf[EBUFSIZ]; + char buf1[EBUFSIZ]; + + err_setup(); + sprintf(buf, s, s1); - err_setup(); - sprintf(buf, s, s1); - if(listing > 0) ship_ln(s); - sprintf(buf1, "%s[%d]: Warning: %s%s", curfname, curlineno, buf, nl); - if(err_flag) write(err_fd, buf1, (LONG)strlen(buf1)); - else printf("%s", buf1); - taglist('W'); + if (listing > 0) + ship_ln(s); - return(OK); + sprintf(buf1, "%s%d: Warning: %s%s", curfname, curlineno, buf, nl); + + if (err_flag) + write(err_fd, buf1, (LONG)strlen(buf1)); + else + printf("%s", buf1); + + taglist('W'); + + return(OK); } -int warni(char *s, unsigned i) { - char buf[EBUFSIZ]; - char buf1[EBUFSIZ]; +int warni(char * s, unsigned i) +{ + char buf[EBUFSIZ]; + char buf1[EBUFSIZ]; + + err_setup(); + sprintf(buf, s, i); + + if (listing > 0) + ship_ln(buf); - err_setup(); - sprintf(buf, s, i); - if(listing > 0) ship_ln(buf); - sprintf(buf1, "%s[%d]: Warning: %s%s", curfname, curlineno, buf, nl); - if(err_flag) write(err_fd, buf1, (LONG)strlen(buf1)); - else printf("%s", buf1); - taglist('W'); + sprintf(buf1, "%s%d: Warning: %s%s", curfname, curlineno, buf, nl); - return(OK); + if (err_flag) + write(err_fd, buf1, (LONG)strlen(buf1)); + else + printf("%s", buf1); + + taglist('W'); + + return(OK); } -int fatal(char *s) { - char buf[EBUFSIZ]; +int fatal(char * s) +{ + char buf[EBUFSIZ]; - err_setup(); - if(listing > 0) ship_ln(s); - sprintf(buf, "%s[%d]: Fatal: %s%s", curfname, curlineno, s, nl); - if(err_flag) write(err_fd, buf, (LONG)strlen(buf)); - else printf("%s", buf); + err_setup(); - exit(1); + if (listing > 0) + ship_ln(s); + + sprintf(buf, "%s%d: Fatal: %s%s", curfname, curlineno, s, nl); + + if (err_flag) + write(err_fd, buf, (LONG)strlen(buf)); + else + printf("%s", buf); + + exit(1); } -int interror(int n) { - char buf[EBUFSIZ]; +int interror(int n) +{ + char buf[EBUFSIZ]; - err_setup(); - sprintf(buf, "%s[%d]: Internal Error Number %d%s", curfname, curlineno, n, nl); - if(listing > 0) ship_ln(buf); - if(err_flag) write(err_fd, buf, (LONG)strlen(buf)); - else printf("%s", buf); + err_setup(); + sprintf(buf, "%s%d: Internal Error Number %d%s", curfname, curlineno, n, nl); - exit(1); + if (listing > 0) + ship_ln(buf); + + if (err_flag) + write(err_fd, buf, (LONG)strlen(buf)); + else + printf("%s", buf); + + exit(1); }