]> granicus.if.org Git - file/commitdiff
Add dollop of code for compression. Nbytes no longer global, but
authorIan Darwin <ian@darwinsys.com>
Wed, 23 Jan 1991 13:22:06 +0000 (13:22 +0000)
committerIan Darwin <ian@darwinsys.com>
Wed, 23 Jan 1991 13:22:06 +0000 (13:22 +0000)
now zflag is. Tweak troff code a little.

src/ascmagic.c

index c4402f18877e1bb9979cc788310a0e5390e0e4ba..2d9e987cdd35e99eb6ae5dd1eac359c8694d1818 100644 (file)
 
 #ifndef        lint
 static char *moduleid = 
-       "@(#)$Header: /home/glen/git/file/cvs/file/src/ascmagic.c,v 1.5 1987/09/16 14:44:45 ian Exp $";
+       "@(#)$Header: /home/glen/git/file/cvs/file/src/ascmagic.c,v 1.6 1991/01/23 13:22:06 ian Exp $";
 #endif /* lint */
 
-char ckfmsg[] = "write error on output";
+char *ckfmsg = "write error on output";
 
                        /* an optimisation over plain strcmp() */
 #define        STREQ(a, b)     (*(a) == *(b) && strcmp((a), (b)) == 0)
 
-ascmagic(buf)
+ascmagic(buf, nbytes)
 register char  *buf;
+int nbytes;    /* size actually read */
 {
-       register int i;
-       char    *s, *strtok(), *token;
+       int i, isblock, is_tar(), is_compress();
+       char *s, *strtok(), *token;
        register struct names *p;
-       extern int nbytes;
        short has_escapes = 0;
+       extern int zflag;
 
        /* these are easy, do them first */
 
        /*
-        * for troff, look for . + letter + letter;
+        * for troff, look for . + letter + letter or .\";
         * this must be done to disambiguate tar archives' ./file
         * and other trash from real troff input.
         */
-       if (*buf == '.' && 
-               isascii(*(buf+1)) && isalnum(*(buf+1)) &&
-               isascii(*(buf+2)) && isalnum(*(buf+2))){
-               ckfputs("troff or preprocessor input text", stdout);
-               return 1;
+       if (*buf == '.') {
+               char *p = buf + 1;
+
+               while (isascii(*p) && isspace(*p))
+                       ++p;    /* skip leading whitespace */
+               if ((isascii(*p) && (isalnum(*p) || *p=='\\') &&
+                   isascii(*(p+1)) && (isalnum(*(p+1)) || *p=='"'))) {
+                       ckfputs("troff or preprocessor input text", stdout);
+                       return 1;
+               }
        }
        if ((*buf == 'c' || *buf == 'C') && 
            isascii(*(buf + 1)) && isspace(*(buf + 1))) {
@@ -90,6 +96,22 @@ register char        *buf;
                return 1;
        }
 
+       if (i = is_compress(buf, &isblock)) {
+               if (zflag) {
+                       char *newbuf;
+                       int newsize;
+
+                       newsize = uncompress(buf, nbytes, &newbuf);
+                       try(newbuf, newsize);
+                       /* free(newbuf) */
+                       printf("(%scompressed data - %d bits)",
+                               isblock ? "block " : "", i);
+               }
+               else printf("%scompressed data - %d bits",
+                       isblock ? "block " : "", i);
+               return 1;
+       }
+
        for (i = 0; i < nbytes; i++) {
                if (!isascii(*(buf+i)))
                        return 0;       /* not all ascii */