Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/netbsd-1-5]: src/usr.bin/file Pull up file 3.32 (requested by christos, ...



details:   https://anonhg.NetBSD.org/src/rev/f5939d71dfae
branches:  netbsd-1-5
changeset: 489599:f5939d71dfae
user:      simonb <simonb%NetBSD.org@localhost>
date:      Sat Sep 30 06:20:43 2000 +0000

description:
Pull up file 3.32 (requested by christos, approved by thorpej).

diffstat:

 usr.bin/file/Header             |    1 +
 usr.bin/file/Makefile           |    4 +-
 usr.bin/file/README             |    4 +-
 usr.bin/file/apprentice.c       |   64 ++-
 usr.bin/file/ascmagic.c         |  649 +++++++++++++++++++++++++++++++++++++--
 usr.bin/file/compress.c         |   77 ++--
 usr.bin/file/config.h           |    2 +-
 usr.bin/file/file.1             |   94 +++-
 usr.bin/file/file.c             |  134 ++++----
 usr.bin/file/file2netbsd        |   12 +-
 usr.bin/file/fsmagic.c          |   11 +-
 usr.bin/file/is_tar.c           |   24 +-
 usr.bin/file/magdir/alpha       |    9 +
 usr.bin/file/magdir/animation   |    8 +
 usr.bin/file/magdir/apple       |  104 ++++++
 usr.bin/file/magdir/blender     |   17 +
 usr.bin/file/magdir/commands    |    7 +
 usr.bin/file/magdir/database    |  133 +++----
 usr.bin/file/magdir/elf         |   24 +-
 usr.bin/file/magdir/filesystems |   15 +-
 usr.bin/file/magdir/images      |    5 +-
 usr.bin/file/magdir/macintosh   |  209 ++++++++++-
 usr.bin/file/magdir/mail.news   |    3 +
 usr.bin/file/magdir/msvc        |    2 +-
 usr.bin/file/magdir/netbsd      |   11 +
 usr.bin/file/magdir/python      |    5 +
 usr.bin/file/magdir/sniffer     |   45 ++
 usr.bin/file/magdir/troff       |    2 +-
 usr.bin/file/magdir/vmware      |   13 +-
 usr.bin/file/names.h            |   31 +-
 usr.bin/file/patchlevel.h       |   15 +-
 usr.bin/file/print.c            |   70 ++--
 usr.bin/file/readelf.c          |  178 +++++++---
 usr.bin/file/softmagic.c        |   48 +-
 34 files changed, 1538 insertions(+), 492 deletions(-)

diffs (truncated from 3059 to 300 lines):

diff -r c3b0bec6832b -r f5939d71dfae usr.bin/file/Header
--- a/usr.bin/file/Header       Sat Sep 30 01:47:17 2000 +0000
+++ b/usr.bin/file/Header       Sat Sep 30 06:20:43 2000 +0000
@@ -1,3 +1,4 @@
+# Magic
 # Magic data for file(1) command.
 # Machine-generated from src/cmd/file/magdir/*; edit there only!
 # Format is described in magic(files), where:
diff -r c3b0bec6832b -r f5939d71dfae usr.bin/file/Makefile
--- a/usr.bin/file/Makefile     Sat Sep 30 01:47:17 2000 +0000
+++ b/usr.bin/file/Makefile     Sat Sep 30 06:20:43 2000 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.24 2000/05/14 22:53:37 christos Exp $
+#      $NetBSD: Makefile,v 1.24.4.1 2000/09/30 06:20:43 simonb Exp $
 
 .include <bsd.own.mk>
 
@@ -12,7 +12,7 @@
 
 PROG=          file
 SRCS=          file.c apprentice.c fsmagic.c softmagic.c ascmagic.c is_tar.c \
-               print.c compress.c readelf.c internat.c
+               print.c compress.c readelf.c 
 CPPFLAGS+=     -DMAGIC='"$(MAGIC)"' -DHAVE_CONFIG_H -I${.CURDIR}
 CPPFLAGS+=     -DBUILTIN_ELF -DELFCORE
 MAN=           file.1 magic.5
diff -r c3b0bec6832b -r f5939d71dfae usr.bin/file/README
--- a/usr.bin/file/README       Sat Sep 30 01:47:17 2000 +0000
+++ b/usr.bin/file/README       Sat Sep 30 06:20:43 2000 +0000
@@ -1,4 +1,4 @@
-$NetBSD: README,v 1.6 1998/09/20 15:27:15 christos Exp $
+$NetBSD: README,v 1.6.10.1 2000/09/30 06:20:43 simonb Exp $
 ** README for file(1) Command **
 @(#) Id: README,v 1.22 1997/11/05 16:03:18 christos Exp 
 
@@ -81,7 +81,7 @@
       }
       bytes_in += (ulg)insize;
 
-E-mail: christos%astron.com@localhost, moraes%deshaw.com@localhost
+E-mail: christos%astron.com@localhost
 
 Phone: Do not even think of telephoning me about this program. Send cash first!
 
diff -r c3b0bec6832b -r f5939d71dfae usr.bin/file/apprentice.c
--- a/usr.bin/file/apprentice.c Sat Sep 30 01:47:17 2000 +0000
+++ b/usr.bin/file/apprentice.c Sat Sep 30 06:20:43 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: apprentice.c,v 1.19 2000/05/14 22:53:37 christos Exp $ */
+/*     $NetBSD: apprentice.c,v 1.19.4.1 2000/09/30 06:20:44 simonb Exp $       */
 
 /*
  * apprentice - make one pass through /etc/magic, learning its secrets.
@@ -39,7 +39,7 @@
 #if 0
 FILE_RCSID("@(#)Id: apprentice.c,v 1.32 2000/04/23 04:32:19 christos Exp ")
 #else
-__RCSID("$NetBSD: apprentice.c,v 1.19 2000/05/14 22:53:37 christos Exp $");
+__RCSID("$NetBSD: apprentice.c,v 1.19.4.1 2000/09/30 06:20:44 simonb Exp $");
 #endif
 #endif /* lint */
 
@@ -68,8 +68,8 @@
 
 int
 apprentice(fn, check)
-const char *fn;                        /* list of magic files */
-int check;                     /* non-zero? checking-only run. */
+       const char *fn;                 /* list of magic files */
+       int check;                      /* non-zero? checking-only run. */
 {
        char *p, *mfn;
        int file_err, errs = -1;
@@ -107,8 +107,8 @@
 
 static int
 apprentice_1(fn, check)
-const char *fn;                        /* name of magic file */
-int check;                     /* non-zero? checking-only run. */
+       const char *fn;                 /* name of magic file */
+       int check;                      /* non-zero? checking-only run. */
 {
        static const char hdr[] =
                "cont\toffset\ttype\topcode\tmask\tvalue\tdesc";
@@ -120,8 +120,8 @@
        if (f==NULL) {
                if (errno != ENOENT)
                        (void) fprintf(stderr,
-                       "%s: can't read magic file %s (%s)\n", 
-                       progname, fn, strerror(errno));
+                           "%s: can't read magic file %s (%s)\n", 
+                           progname, fn, strerror(errno));
                return -1;
        }
 
@@ -148,8 +148,8 @@
  */
 uint32
 signextend(m, v)
-struct magic *m;
-uint32 v;
+       struct magic *m;
+       uint32 v;
 {
        if (!(m->flag & UNSIGNED))
                switch(m->type) {
@@ -189,8 +189,8 @@
  */
 static int
 parse(l, ndx, check)
-char *l;
-int *ndx, check;
+       char *l;
+       int *ndx, check;
 {
        int i = 0, nd = *ndx;
        struct magic *m;
@@ -451,8 +451,8 @@
  */
 static int
 getvalue(m, p)
-struct magic *m;
-char **p;
+       struct magic *m;
+       char **p;
 {
        int slen;
 
@@ -475,14 +475,14 @@
  */
 static char *
 getstr(s, p, plen, slen)
-register char  *s;
-register char  *p;
-int    plen, *slen;
+       char    *s;
+       char    *p;
+       int     plen, *slen;
 {
        char    *origs = s, *origp = p;
        char    *pmax = p + plen - 1;
-       register int    c;
-       register int    val;
+       int     c;
+       int     val;
 
        while ((c = *s++) != '\0') {
                if (isspace((unsigned char) c))
@@ -578,13 +578,17 @@
 /* Single hex char to int; -1 if not a hex char. */
 static int
 hextoint(c)
-int c;
+       int c;
 {
-       if (!isascii((unsigned char) c))        return -1;
-       if (isdigit((unsigned char) c))         return c - '0';
-       if ((c>='a')&&(c<='f')) return c + 10 - 'a';
-       if ((c>='A')&&(c<='F')) return c + 10 - 'A';
-                               return -1;
+       if (!isascii((unsigned char) c))
+               return -1;
+       if (isdigit((unsigned char) c))
+               return c - '0';
+       if ((c >= 'a')&&(c <= 'f'))
+               return c + 10 - 'a';
+       if (( c>= 'A')&&(c <= 'F'))
+               return c + 10 - 'A';
+       return -1;
 }
 
 
@@ -593,11 +597,11 @@
  */
 void
 showstr(fp, s, len)
-FILE *fp;
-const char *s;
-int len;
+       FILE *fp;
+       const char *s;
+       int len;
 {
-       register char   c;
+       char    c;
 
        for (;;) {
                c = *s++;
@@ -652,7 +656,7 @@
  */
 static void
 eatsize(p)
-char **p;
+       char **p;
 {
        char *l = *p;
 
diff -r c3b0bec6832b -r f5939d71dfae usr.bin/file/ascmagic.c
--- a/usr.bin/file/ascmagic.c   Sat Sep 30 01:47:17 2000 +0000
+++ b/usr.bin/file/ascmagic.c   Sat Sep 30 06:20:43 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ascmagic.c,v 1.14 2000/05/14 22:53:37 christos Exp $   */
+/*     $NetBSD: ascmagic.c,v 1.14.4.1 2000/09/30 06:20:44 simonb Exp $ */
 
 /*
  * ASCII magic -- file types that we know based on keywords
@@ -7,6 +7,14 @@
  * Copyright (c) Ian F. Darwin, 1987.
  * Written by Ian F. Darwin.
  *
+ * Extensively modified by Eric Fischer <enf%pobox.com@localhost> in July, 2000,
+ * to handle character codes other than ASCII on a unified basis.
+ *
+ * Joerg Wunsch <joerg%freebsd.org@localhost> wrote the original support for 8-bit
+ * international characters, now subsumed into this file.
+ */
+
+/*
  * This software is not subject to any license of the American Telephone
  * and Telegraph Company or of the Regents of the University of California.
  *
@@ -44,23 +52,54 @@
 #if 0
 FILE_RCSID("@(#)Id: ascmagic.c,v 1.27 2000/04/23 04:28:19 christos Exp ")
 #else
-__RCSID("$NetBSD: ascmagic.c,v 1.14 2000/05/14 22:53:37 christos Exp $");
+__RCSID("$NetBSD: ascmagic.c,v 1.14.4.1 2000/09/30 06:20:44 simonb Exp $");
 #endif
 #endif /* lint */
 
                        /* an optimisation over plain strcmp() */
 #define        STREQ(a, b)     (*(a) == *(b) && strcmp((a), (b)) == 0)
 
+typedef unsigned long unichar;
+
+#define MAXLINELEN 300 /* longest sane line length */
+#define ISSPC(x) ((x) == ' ' || (x) == '\t' || (x) == '\r' || (x) == '\n' \
+                 || (x) == 0x85 || (x) == '\f')
+
+static int looks_ascii __P((const unsigned char *, int, unichar *, int *));
+static int looks_utf8 __P((const unsigned char *, int, unichar *, int *));
+static int looks_unicode __P((const unsigned char *, int, unichar *, int *));
+static int looks_latin1 __P((const unsigned char *, int, unichar *, int *));
+static int looks_extended __P((const unsigned char *, int, unichar *, int *));
+static void from_ebcdic __P((const unsigned char *, int, unsigned char *));
+static int ascmatch __P((const unsigned char *, const unichar *, int));
+
 int
 ascmagic(buf, nbytes)
-unsigned char *buf;
-int nbytes;    /* size actually read */
+       unsigned char *buf;
+       int nbytes;     /* size actually read */
 {
-       int i, has_escapes = 0;
-       unsigned char *s;
-       char nbuf[HOWMANY+1];   /* one extra for terminating '\0' */
-       char *token;
-       register struct names *p;
+       int i;
+       char nbuf[HOWMANY+1];           /* one extra for terminating '\0' */
+       unichar ubuf[HOWMANY+1];        /* one extra for terminating '\0' */
+       int ulen;
+       struct names *p;
+
+       char *code = NULL;
+       char *code_mime = NULL;
+       char *type = NULL;
+       char *subtype = NULL;
+       char *subtype_mime = NULL;
+
+       int has_escapes = 0;
+       int has_backspace = 0;
+
+       int n_crlf = 0;
+       int n_lf = 0;
+       int n_cr = 0;
+       int n_nel = 0;
+
+       int last_line_end = -1;
+       int has_long_lines = 0;
 
        /*
         * Do the tar test first, because if the first file in the tar
@@ -76,58 +115,582 @@
                return 1;
        }
 
+       /* Undo the NUL-termination kindly provided by process() */
+
+       while (nbytes > 0 && buf[nbytes - 1] == '\0')
+               nbytes--;
+
+       /*
+        * Then try to determine whether it's any character code we can
+        * identify.  Each of these tests, if it succeeds, will leave
+        * the text converted into one-unichar-per-character Unicode in
+        * ubuf, and the number of characters converted in ulen.
+        */
+       if (looks_ascii(buf, nbytes, ubuf, &ulen)) {



Home | Main Index | Thread Index | Old Index