#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() */
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 */
/* 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;
}
}
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);
}
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;
}