]> granicus.if.org Git - file/commitdiff
Guy Harris: check has_escapes before names stuff, so can use as an
authorIan Darwin <ian@darwinsys.com>
Wed, 24 Mar 1993 14:22:13 +0000 (14:22 +0000)
committerIan Darwin <ian@darwinsys.com>
Wed, 24 Mar 1993 14:22:13 +0000 (14:22 +0000)
LPR checker for PCL stuff. Also some delinting.

src/ascmagic.c

index 1b21396cb0ecdb40cadf9afc5051d4200c83f853..f4203ec3e11c54f842a709116842c6fe6e43926c 100644 (file)
@@ -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;
 }