From: Ian Darwin Date: Wed, 24 Mar 1993 14:22:13 +0000 (+0000) Subject: Guy Harris: check has_escapes before names stuff, so can use as an X-Git-Tag: FILE3_27~162 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5d38a89907fea031b67de00fe27386ed78720e64;p=file Guy Harris: check has_escapes before names stuff, so can use as an LPR checker for PCL stuff. Also some delinting. --- diff --git a/src/ascmagic.c b/src/ascmagic.c index 1b21396c..f4203ec3 100644 --- a/src/ascmagic.c +++ b/src/ascmagic.c @@ -36,7 +36,7 @@ #ifndef lint static char *moduleid = - "@(#)$Id: ascmagic.c,v 1.12 1993/02/19 14:22:43 ian Exp $"; + "@(#)$Id: ascmagic.c,v 1.13 1993/03/24 14:22:13 ian Exp $"; #endif /* lint */ /* an optimisation over plain strcmp() */ @@ -48,9 +48,8 @@ unsigned char *buf; int nbytes; /* size actually read */ { int i, isblock, has_escapes = 0; - unsigned char *s; + unsigned char *s, *token; char nbuf[HOWMANY+1]; /* one extra for terminating '\0' */ - char *token; register struct names *p; /* these are easy, do them first */ @@ -79,12 +78,22 @@ int nbytes; /* size actually read */ /* look for tokens from names.h - this is expensive! */ /* make a copy of the buffer here because strtok() will destroy it */ - s = (unsigned char*) memcpy(nbuf, buf, HOWMANY); - while ((token = strtok((char*)s, " \t\n\r\f")) != NULL) { + s = (unsigned char*)memcpy(nbuf, buf, HOWMANY); + while ((token = (unsigned char*)strtok((char*)s," \t\n\r\f")) != NULL) { + if (!has_escapes) { + for (s = (unsigned char*)token; *s != NULL; s++) + if (*s == '\033') { + has_escapes++; + break; + } + } s = NULL; /* make strtok() keep on tokin' */ for (p = names; p < names + NNAMES; p++) { - if (STREQ(p->name, token)) { + if (STREQ(p->name, (char*)token)) { ckfputs(types[p->type], stdout); + if (has_escapes) + ckfputs(" (with escape sequences)", + stdout); return 1; } } @@ -99,12 +108,12 @@ int nbytes; /* size actually read */ return 1; } - if (i = is_compress(buf, &isblock)) { + if ((i = is_compress(buf, &isblock))) { if (zflag) { unsigned char *newbuf; int newsize; - if (newsize = uncompress(buf, &newbuf, nbytes)) { + if ((newsize = uncompress(buf, &newbuf, nbytes))) { tryit(newbuf, newsize); free(newbuf); } @@ -120,16 +129,15 @@ int nbytes; /* size actually read */ if (!isascii(*(buf+i))) return 0; /* not all ascii */ if (*(buf+i) == '\033') /* ascii ESCAPE */ - has_escapes ++; + has_escapes++; + /* do NOT break here - must check all bytes */ } /* all else fails, but it is ascii... */ - if (has_escapes){ - ckfputs("ascii text (with escape sequences)", stdout); - } - else { - ckfputs("ascii text", stdout); - } + ckfputs("ascii text", stdout); + if (has_escapes) { + ckfputs(" (with escape sequences)", stdout); + } return 1; }