home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume13 / file / part02 < prev    next >
Encoding:
Internet Message Format  |  1988-01-30  |  44.2 KB

  1. Subject:  v13i028:  Replacement for the file(1) command, Part02/02
  2. Newsgroups: comp.sources.unix
  3. Sender: sources
  4. Approved: rsalz@uunet.UU.NET
  5.  
  6. Submitted-by: "Ian F. Darwin" <ian@sq.com>
  7. Posting-number: Volume 13, Issue 28
  8. Archive-name: file/part02
  9.  
  10. : to unbundle, sh this file
  11. echo x - strtok.c 1>&2
  12. cat >strtok.c <<'@@@End of strtok.c'
  13. /*
  14.  * Get next token from string s (NULL on 2nd, 3rd, etc. calls),
  15.  * where tokens are nonempty strings separated by runs of
  16.  * chars from delim.  Writes NULs into s to end tokens.  delim need not
  17.  * remain constant from call to call.
  18.  *
  19.  * Copyright (c) Henry Spencer.
  20.  * Written by Henry Spencer.
  21.  *
  22.  * This software is not subject to any license of the American Telephone
  23.  * and Telegraph Company or of the Regents of the University of California.
  24.  *
  25.  * Permission is granted to anyone to use this software for any purpose on
  26.  * any computer system, and to alter it and redistribute it freely, subject
  27.  * to the following restrictions:
  28.  *
  29.  * 1. The author is not responsible for the consequences of use of this
  30.  *    software, no matter how awful, even if they arise from flaws in it.
  31.  *
  32.  * 2. The origin of this software must not be misrepresented, either by
  33.  *    explicit claim or by omission.  Since few users ever read sources,
  34.  *    credits must appear in the documentation.
  35.  *
  36.  * 3. Altered versions must be plainly marked as such, and must not be
  37.  *    misrepresented as being the original software.  Since few users
  38.  *    ever read sources, credits must appear in the documentation.
  39.  *
  40.  * 4. This notice may not be removed or altered.
  41.  */
  42.  
  43. #define    NULL    0
  44. #define CONST
  45.  
  46. static char *scanpoint = NULL;
  47.  
  48. char *                /* NULL if no token left */
  49. strtok(s, delim)
  50. char *s;
  51. register CONST char *delim;
  52. {
  53.     register char *scan;
  54.     char *tok;
  55.     register CONST char *dscan;
  56.  
  57.     if (s == NULL && scanpoint == NULL)
  58.         return(NULL);
  59.     if (s != NULL)
  60.         scan = s;
  61.     else
  62.         scan = scanpoint;
  63.  
  64.     /*
  65.      * Scan leading delimiters.
  66.      */
  67.     for (; *scan != '\0'; scan++) {
  68.         for (dscan = delim; *dscan != '\0'; dscan++)
  69.             if (*scan == *dscan)
  70.                 break;
  71.         if (*dscan == '\0')
  72.             break;
  73.     }
  74.     if (*scan == '\0') {
  75.         scanpoint = NULL;
  76.         return(NULL);
  77.     }
  78.  
  79.     tok = scan;
  80.  
  81.     /*
  82.      * Scan token.
  83.      */
  84.     for (; *scan != '\0'; scan++) {
  85.         for (dscan = delim; *dscan != '\0';)    /* ++ moved down. */
  86.             if (*scan == *dscan++) {
  87.                 scanpoint = scan+1;
  88.                 *scan = '\0';
  89.                 return(tok);
  90.             }
  91.     }
  92.  
  93.     /*
  94.      * Reached end of string.
  95.      */
  96.     scanpoint = NULL;
  97.     return(tok);
  98. }
  99. @@@End of strtok.c
  100. echo x - strchr.c 1>&2
  101. cat >strchr.c <<'@@@End of strchr.c'
  102. /*
  103.  * Local copy of strchr (a.k.a. index) for portability.
  104.  * Totally public domain.
  105.  */
  106.  
  107. #include <stdio.h>
  108.  
  109. char *
  110. strchr(s, c)
  111. char *s, c;
  112. {
  113.     char *x = s;
  114.  
  115.     while (*x != c)
  116.         if (*x == '\0')
  117.             return(NULL);
  118.         else
  119.             ++x;
  120.     return(x);
  121. }
  122.  
  123. @@@End of strchr.c
  124. echo x - file.h 1>&2
  125. cat >file.h <<'@@@End of file.h'
  126. /*
  127.  * file.h - definitions for file(1) program
  128.  # @(#)$Header: file.h,v 1.4 87/09/18 10:56:09 ian Exp $
  129.  *
  130.  * Copyright (c) Ian F. Darwin, 1987.
  131.  * Written by Ian F. Darwin.
  132.  *
  133.  * This software is not subject to any license of the American Telephone
  134.  * and Telegraph Company or of the Regents of the University of California.
  135.  *
  136.  * Permission is granted to anyone to use this software for any purpose on
  137.  * any computer system, and to alter it and redistribute it freely, subject
  138.  * to the following restrictions:
  139.  *
  140.  * 1. The author is not responsible for the consequences of use of this
  141.  *    software, no matter how awful, even if they arise from flaws in it.
  142.  *
  143.  * 2. The origin of this software must not be misrepresented, either by
  144.  *    explicit claim or by omission.  Since few users ever read sources,
  145.  *    credits must appear in the documentation.
  146.  *
  147.  * 3. Altered versions must be plainly marked as such, and must not be
  148.  *    misrepresented as being the original software.  Since few users
  149.  *    ever read sources, credits must appear in the documentation.
  150.  *
  151.  * 4. This notice may not be removed or altered.
  152.  */
  153.  
  154. #define HOWMANY    1024        /* how much of the file to look at */
  155. #define MAXMAGIS 250        /* max entries in /etc/magic */
  156. #define MAXDESC    50        /* max leng of text description */
  157. #define MAXstring 32        /* max leng of "string" types */
  158. #define ckfputs(str,fil) {if (fputs(str,fil)==EOF) error(ckfmsg,"");}
  159.  
  160. struct magic {
  161.     short contflag;        /* 1 if '>0' appears */
  162.     long offset;        /* offset to magic number */
  163.     char reln;        /* relation (0=eq, '>'=gt, etc) */
  164.     char type;        /* int, short, long or string. */
  165.     char vallen;        /* length of string value, if any */
  166. #define             BYTE    1
  167. #define                SHORT    2
  168. #define                LONG    4
  169. #define                STRING    5
  170.     union VALUETYPE {
  171.         char b;
  172.         short h;
  173.         long l;
  174.         char s[MAXstring];
  175.     } value;        /* either number or string */
  176.     char desc[MAXDESC];    /* description */
  177. };
  178.  
  179. extern void error(), exit();
  180. @@@End of file.h
  181. echo x - names.h 1>&2
  182. cat >names.h <<'@@@End of names.h'
  183. /*
  184.  * Names.h - names and types used by ascmagic in file(1).
  185.  * These tokens are here because they can appear anywhere in
  186.  * the first HOWMANY bytes, while tokens in /etc/magic must
  187.  * appear at fixed offsets into the file. Don't make HOWMANY
  188.  * too high unless you have a very fast CPU.
  189.  *
  190.  * Copyright (c) Ian F. Darwin, 1987.
  191.  * Written by Ian F. Darwin.
  192.  *
  193.  * This software is not subject to any license of the American Telephone
  194.  * and Telegraph Company or of the Regents of the University of California.
  195.  *
  196.  * Permission is granted to anyone to use this software for any purpose on
  197.  * any computer system, and to alter it and redistribute it freely, subject
  198.  * to the terms in the accompanying LEGAL.NOTICE file.
  199.  */
  200.  
  201. /* these types are used to index the table 'types': keep em in sync! */
  202. #define L_C    0        /* first and foremost on UNIX */
  203. #define    L_FORT    1        /* the oldest one */
  204. #define L_MAKE    2        /* Makefiles */
  205. #define L_PLI    3        /* PL/1 */
  206. #define L_MACH    4        /* some kinda assembler */
  207. #define L_ENG    5        /* English */
  208. #define    L_PAS    6        /* Pascal */
  209. #define    L_MAIL    7        /* Electronic mail */
  210. #define    L_NEWS    8        /* Usenet Netnews */
  211.  
  212. char *types[] = {
  213.     "c program text",
  214.     "fortran program text",
  215.     "make commands text" ,
  216.     "pl/1 program text",
  217.     "assembler program text",
  218.     "English text",
  219.     "pascal program text",
  220.     "mail text",
  221.     "news text",
  222.     "can't happen error on names.h/types",
  223.     0};
  224.  
  225. struct names {
  226.     char *name;
  227.     short type;
  228. } names[] = {
  229.     /* These must be sorted by eye for optimal hit rate */
  230.     /* Add to this list only after substantial meditation */
  231.     {"/*",        L_C},    /* must preced "The", "the", etc. */
  232.     {"#include",    L_C},
  233.     {"char",    L_C},
  234.     {"The",        L_ENG},
  235.     {"the",        L_ENG},
  236.     {"double",    L_C},
  237.     {"extern",    L_C},
  238.     {"float",    L_C},
  239.     {"real",    L_C},
  240.     {"struct",    L_C},
  241.     {"union",    L_C},
  242.     {"CFLAGS",    L_MAKE},
  243.     {"LDFLAGS",    L_MAKE},
  244.     {"all:",    L_MAKE},
  245.     {".PRECIOUS",    L_MAKE},
  246. /* Too many files of text have these words in them.  Find another way
  247.  * to recognize Fortrash.
  248.  */
  249. #ifdef    NOTDEF
  250.     {"subroutine",    L_FORT},
  251.     {"function",    L_FORT},
  252.     {"block",    L_FORT},
  253.     {"common",    L_FORT},
  254.     {"dimension",    L_FORT},
  255.     {"integer",    L_FORT},
  256.     {"data",    L_FORT},
  257. #endif    /*NOTDEF*/
  258.     {".ascii",    L_MACH},
  259.     {".asciiz",    L_MACH},
  260.     {".byte",    L_MACH},
  261.     {".even",    L_MACH},
  262.     {".globl",    L_MACH},
  263.     {"clr",        L_MACH},
  264.     {"(input,",    L_PAS},
  265.     {"dcl",        L_PLI},
  266.     {"Received:",    L_MAIL},
  267.     {">From",    L_MAIL},
  268.     {"Return-Path:",L_MAIL},
  269.     {"Cc:",        L_MAIL},
  270.     {"Newsgroups:",    L_NEWS},
  271.     {"Path:",    L_NEWS},
  272.     {"Organization:",L_NEWS},
  273.     0};
  274. #define NNAMES ((sizeof(names)/sizeof(struct names)) - 1)
  275. @@@End of names.h
  276. echo x - tar.h 1>&2
  277. cat >tar.h <<'@@@End of tar.h'
  278. /*
  279.  * Header file for public domain tar (tape archive) program.
  280.  *
  281.  * @(#)tar.h 1.20 86/10/29    Public Domain.
  282.  *
  283.  * Created 25 August 1985 by John Gilmore, ihnp4!hoptoad!gnu.
  284.  */
  285.  
  286. /*
  287.  * Kludge for handling systems that can't cope with multiple
  288.  * external definitions of a variable.  In ONE routine (tar.c),
  289.  * we #define TAR_EXTERN to null; here, we set it to "extern" if
  290.  * it is not already set.
  291.  */
  292. #ifndef TAR_EXTERN
  293. #define TAR_EXTERN extern
  294. #endif
  295.  
  296. /*
  297.  * Header block on tape.
  298.  *
  299.  * I'm going to use traditional DP naming conventions here.
  300.  * A "block" is a big chunk of stuff that we do I/O on.
  301.  * A "record" is a piece of info that we care about.
  302.  * Typically many "record"s fit into a "block".
  303.  */
  304. #define    RECORDSIZE    512
  305. #define    NAMSIZ    100
  306. #define    TUNMLEN    32
  307. #define    TGNMLEN    32
  308.  
  309. union record {
  310.     char        charptr[RECORDSIZE];
  311.     struct header {
  312.         char    name[NAMSIZ];
  313.         char    mode[8];
  314.         char    uid[8];
  315.         char    gid[8];
  316.         char    size[12];
  317.         char    mtime[12];
  318.         char    chksum[8];
  319.         char    linkflag;
  320.         char    linkname[NAMSIZ];
  321.         char    magic[8];
  322.         char    uname[TUNMLEN];
  323.         char    gname[TGNMLEN];
  324.         char    devmajor[8];
  325.         char    devminor[8];
  326.     } header;
  327. };
  328.  
  329. /* The checksum field is filled with this while the checksum is computed. */
  330. #define    CHKBLANKS    "        "    /* 8 blanks, no null */
  331.  
  332. /* The magic field is filled with this if uname and gname are valid. */
  333. #define    TMAGIC        "ustar  "    /* 7 chars and a null */
  334.  
  335. /* The linkflag defines the type of file */
  336. #define    LF_OLDNORMAL    '\0'        /* Normal disk file, Unix compat */
  337. #define    LF_NORMAL    '0'        /* Normal disk file */
  338. #define    LF_LINK        '1'        /* Link to previously dumped file */
  339. #define    LF_SYMLINK    '2'        /* Symbolic link */
  340. #define    LF_CHR        '3'        /* Character special file */
  341. #define    LF_BLK        '4'        /* Block special file */
  342. #define    LF_DIR        '5'        /* Directory */
  343. #define    LF_FIFO        '6'        /* FIFO special file */
  344. #define    LF_CONTIG    '7'        /* Contiguous file */
  345. /* Further link types may be defined later. */
  346.  
  347. /*
  348.  * Exit codes from the "tar" program
  349.  */
  350. #define    EX_SUCCESS    0        /* success! */
  351. #define    EX_ARGSBAD    1        /* invalid args */
  352. #define    EX_BADFILE    2        /* invalid filename */
  353. #define    EX_BADARCH    3        /* bad archive */
  354. #define    EX_SYSTEM    4        /* system gave unexpected error */
  355.  
  356.  
  357. /*
  358.  * Global variables
  359.  */
  360. TAR_EXTERN union record    *ar_block;    /* Start of block of archive */
  361. TAR_EXTERN union record    *ar_record;    /* Current record of archive */
  362. TAR_EXTERN union record    *ar_last;    /* Last+1 record of archive block */
  363. TAR_EXTERN char        ar_reading;    /* 0 writing, !0 reading archive */
  364. TAR_EXTERN int        blocking;    /* Size of each block, in records */
  365. TAR_EXTERN int        blocksize;    /* Size of each block, in bytes */
  366. TAR_EXTERN char        *ar_file;    /* File containing archive */
  367. TAR_EXTERN char        *name_file;    /* File containing names to work on */
  368. TAR_EXTERN char        *tar;        /* Name of this program */
  369.  
  370. /*
  371.  * Flags from the command line
  372.  */
  373. TAR_EXTERN char    f_reblock;        /* -B */
  374. TAR_EXTERN char    f_create;        /* -c */
  375. TAR_EXTERN char    f_debug;        /* -d */
  376. TAR_EXTERN char    f_sayblock;        /* -D */
  377. TAR_EXTERN char    f_follow_links;        /* -h */
  378. TAR_EXTERN char    f_ignorez;        /* -i */
  379. TAR_EXTERN char    f_keep;            /* -k */
  380. TAR_EXTERN char    f_modified;        /* -m */
  381. TAR_EXTERN char    f_oldarch;        /* -o */
  382. TAR_EXTERN char    f_use_protection;    /* -p */
  383. TAR_EXTERN char    f_sorted_names;        /* -s */
  384. TAR_EXTERN char    f_list;            /* -t */
  385. TAR_EXTERN char    f_namefile;        /* -T */
  386. TAR_EXTERN char    f_verbose;        /* -v */
  387. TAR_EXTERN char    f_extract;        /* -x */
  388. TAR_EXTERN char    f_compress;        /* -z */
  389.  
  390. /*
  391.  * We now default to Unix Standard format rather than 4.2BSD tar format.
  392.  * The code can actually produce all three:
  393.  *    f_standard    ANSI standard
  394.  *    f_oldarch    V7
  395.  *    neither        4.2BSD
  396.  * but we don't bother, since 4.2BSD can read ANSI standard format anyway.
  397.  * The only advantage to the "neither" option is that we can cmp(1) our
  398.  * output to the output of 4.2BSD tar, for debugging.
  399.  */
  400. #define        f_standard        (!f_oldarch)
  401.  
  402. /*
  403.  * Structure for keeping track of filenames and lists thereof.
  404.  */
  405. struct name {
  406.     struct name    *next;
  407.     short        length;
  408.     char        found;
  409.     char        name[NAMSIZ+1];
  410. };
  411.  
  412. TAR_EXTERN struct name    *namelist;    /* Points to first name in list */
  413. TAR_EXTERN struct name    *namelast;    /* Points to last name in list */
  414.  
  415. TAR_EXTERN int        archive;    /* File descriptor for archive file */
  416. TAR_EXTERN int        errors;        /* # of files in error */
  417.  
  418. /*
  419.  *
  420.  * Due to the next struct declaration, each routine that includes
  421.  * "tar.h" must also include <sys/types.h>.  I tried to make it automatic,
  422.  * but System V has no defines in <sys/types.h>, so there is no way of
  423.  * knowing when it has been included.  In addition, it cannot be included
  424.  * twice, but must be included exactly once.  Argghh!
  425.  *
  426.  * Thanks, typedef.  Thanks, USG.
  427.  */
  428. struct link {
  429.     struct link    *next;
  430.     dev_t        dev;
  431.     ino_t        ino;
  432.     short        linkcount;
  433.     char        name[NAMSIZ+1];
  434. };
  435.  
  436. TAR_EXTERN struct link    *linklist;    /* Points to first link in list */
  437.  
  438.  
  439. /*
  440.  * Error recovery stuff
  441.  */
  442. TAR_EXTERN char        read_error_flag;
  443.  
  444.  
  445. /*
  446.  * Declarations of functions available to the world.
  447.  */
  448. /*LINTLIBRARY*/
  449. union record *findrec();
  450. void userec();
  451. union record *endofrecs();
  452. void anno();
  453. #define     annorec(stream, msg)    anno(stream, msg, 0)    /* Cur rec */
  454. #define    annofile(stream, msg)    anno(stream, msg, 1)    /* Saved rec */
  455. @@@End of tar.h
  456. echo x - Makefile 1>&2
  457. cat >Makefile <<'@@@End of Makefile'
  458. # Makefile for file(1) cmd. 
  459. # Copyright (c) Ian F. Darwin 86/09/01 - see LEGAL.NOTICE.
  460. # @(#)$Header: Makefile,v 1.17 88/01/15 13:03:16 ian Exp $
  461. #
  462.  
  463. SHELL    = /bin/sh
  464. MAGIC    = /etc/magic
  465. DEFS    = -DMAGIC='"$(MAGIC)"' # -Dvoid=int
  466. COPTS    = -O # -g
  467. CFLAGS    = $(COPTS) $(DEFS)
  468. SHAR    = bundle
  469. OFILE    = /bin/file.orig    # old or distributed version, for comparison
  470. # Where new binary lives; typically /usr/local (BSD), /usr/lbin (USG).
  471. BINDIR    = /usr/local
  472. # For installing our man pages; 
  473. # MANCxxx is manual section for Commands, MANFxxx is section for file formats.
  474. # MANxDIR is directory names; MANxEXT is the filename extention. Usual values:
  475. # Variable    V7        4BSD        Sys V
  476. # MANCDIR     /usr/man/man1    /usr/man/man1    /usr/man/u_man/man1
  477. # MANFDIR     /usr/man/man5    /usr/man/man5    /usr/man/u_man/man4
  478. # MANCEXT    1        1        1
  479. # MANFEXT    5        5        4
  480. # --- possible alternative for 4BSD ---
  481. # MANCDIR            /usr/man/manl
  482. # MANCEXT            l
  483. # --- possible alternative for USG ---
  484. # MANCDIR            /usr/man/local/man1
  485. # MANCEXT            1
  486.  
  487. MANCDIR    = /usr/man/manl
  488. MANFDIR    = /usr/man/man5
  489. MANCEXT    = l
  490. MANFEXT    = 5
  491.  
  492. # There are no system-dependant configuration options (except maybe CFLAGS).
  493. # Delete any of LOCALSRCS and LOCALOBJS that are in your C library.
  494. LOCALSRCS = getopt.c strtol.c strtok.c strchr.c
  495. SRCS = file.c apprentice.c fsmagic.c softmagic.c ascmagic.c is_tar.c \
  496.     print.c $(LOCALSRCS)
  497. LOCALOBJS = getopt.o strtol.o strtok.o strchr.o
  498. OBJS = file.o apprentice.o fsmagic.o softmagic.o ascmagic.o is_tar.o \
  499.     print.o $(LOCALOBJS)
  500.  
  501. ALLSRC = LEGAL.NOTICE README PORTING $(SRCS) *.h \
  502.     Makefile file.1 magic.4 magdir/[a-z]* tst/Makefile
  503.  
  504. all:        file magic
  505.  
  506. try:        all $(OFILE)
  507.         cd tst; make
  508.         time $(OFILE) -m ./magic * tst/* >/tmp/t1
  509.         time ./file -m ./magic * tst/* >/tmp/t2
  510.         -diff -b /tmp/t[12]
  511.         what ./file >lastnocore
  512.  
  513. file:        $(OBJS)
  514.         cc $(CFLAGS) $(OBJS) -o $@
  515. lint:        $(SRCS)
  516.         lint -ha $(DEFS) $(SRCS) | tee $@
  517. magic:        magdir
  518. #        exclude RCS or SCCS dirs:
  519.         cat magdir/[a-z]* >$@
  520.  
  521. ascmagic.o:    names.h
  522.  
  523. apprentice.o ascmagic.o file.o fsmagic.o print.o softmagic.o: file.h
  524.  
  525. install:    file magic file.1 magic.4 $(BINDIR) $(MANCDIR) $(MANCDIR)
  526.         cp file        $(BINDIR)/file
  527.         cp magic    $(MAGIC)
  528.         cp file.1    $(MANCDIR)/file.$(MANCEXT)
  529.         cp magic.4    $(MANFDIR)/magic.$(MANFEXT)
  530.  
  531. clean:
  532.         rm -f *.o file magic lint.out
  533.         (cd tst; make clean)
  534.  
  535. dist:        $(ALLSRC)
  536. #        Some versions of shar can't handle a single file from
  537. #        a subdirectory, so we manually insert mkdir as needed.
  538. #        Put the extra "mkdir" AFTER the ": to unbundle..." line.
  539.         $(SHAR) $(ALLSRC) | sed -e '1a\
  540.         mkdir magdir tst' >$@
  541.  
  542. @@@End of Makefile
  543. echo x - file.1 1>&2
  544. cat >file.1 <<'@@@End of file.1'
  545. ..TH FILE 1 "Copyright but distributable"
  546. ..SH NAME
  547. ..I file
  548. \- determine file type
  549. ..SH SYNOPSIS
  550. ..B file
  551. [
  552. ..B -c
  553. ]
  554. [
  555. ..B -f
  556. namefile ]
  557. [
  558. ..B -m 
  559. magicfile ]
  560. file ...
  561. ..SH DESCRIPTION
  562. ..I File
  563. tests each argument in an attempt to classify it.
  564. There are three sets of tests, performed in this order:
  565. filesystem tests, magic number tests, and language tests.
  566. The
  567. ..I first
  568. test that succeeds causes the file type to be printed.
  569. ..PP
  570. The type printed will usually contain one of the words
  571. ..B text
  572. (the file contains only ASCII characters and is 
  573. probably safe to read on an ASCII terminal),
  574. ..B executable
  575. (the file contains the result of compiling a program
  576. in a form understandable to some \s-1UNIX\s0 kernel or another),
  577. or
  578. ..B data
  579. meaning anything else (data is usually `binary' or non-printable).
  580. Exceptions are well-known file formats (core files, tar archives)
  581. that are known to contain binary data.
  582. When modifying the file
  583. ..I /etc/magic
  584. or the program itself, 
  585. ..B "preserve these keywords" .
  586. People depend on knowing that all the readable files in a directory
  587. have the word ``text'' printed.
  588. Don't do as one computer vendor did \- change ``shell commands text''
  589. to ``shell script''.
  590. ..PP
  591. The filesystem tests are based on examining the return from a
  592. ..I stat (2)
  593. system call.
  594. The program checks to see if the file is empty,
  595. or if it's some sort of special file.
  596. Any known file types appropriate to the system you are running on
  597. (sockets and symbolic links on 4.2BSD, named pipes (FIFOs) on System V)
  598. are intuited if they are defined in
  599. the system header file
  600. ..I sys/stat.h  .
  601. ..PP
  602. The magic number tests are used to check for files with data in
  603. particular fixed formats.
  604. The canonical example of this is a binary executable (compiled program)
  605. ..I a.out
  606. file, whose format is defined in 
  607. ..I a.out.h
  608. and possibly
  609. ..I exec.h
  610. in the standard include directory.
  611. These files have a `magic number' stored in a particular place
  612. near the beginning of the file that tells the \s-1UNIX\s0 operating system
  613. that the file is a binary executable, and which of several types thereof.
  614. The concept of `magic number' has been applied by extension to data files.
  615. Any file with some invariant identifier at a small fixed
  616. offset into the file can usually be described in this way.
  617. The information in these files is read from the magic file
  618. ..I /etc/magic .
  619. ..PP
  620. If an argument appears to be an
  621. ..SM ASCII 
  622. file,
  623. ..I file
  624. attempts to guess its language.
  625. The language tests look for particular strings (cf \fInames.h\fP)
  626. that can appear anywhere in the first few blocks of a file.
  627. For example, the keyword
  628. ..I .br
  629. indicates that the file is most likely a troff input file,
  630. just as the keyword 
  631. ..I struct
  632. indicates a C program.
  633. These tests are less reliable than the previous
  634. two groups, so they are performed last.
  635. The language test routines also test for some miscellany
  636. (such as 
  637. ..I tar
  638. archives) and determine whether an unknown file should be
  639. labelled as `ascii text' or `data'. 
  640. ..PP
  641. Use
  642. ..B -m
  643. ..I file
  644. to specify an alternate file of magic numbers.
  645. ..PP
  646. The
  647. ..B -c
  648. option causes a checking printout of the parsed form of the magic file.
  649. This is usually used in conjunction with 
  650. ..B -m
  651. to debug a new magic file before installing it.
  652. ..PP
  653. The 
  654. ..B -f
  655. ..I namefile
  656. option specifies that the names of the files to be examined
  657. are to be read (one per line) from 
  658. ..I namefile
  659. before the argument list.
  660. Either 
  661. ..I namefile
  662. or at least one filename argument must be present;
  663. to test the standard input, use ``-'' as a filename argument.
  664. ..SH FILES
  665. ..I /etc/magic
  666. \- default list of magic numbers
  667. ..SH SEE ALSO
  668. ..IR Magic (FILES)
  669. \- description of magic file format.
  670. ..br
  671. ..IR Strings (1), " od" (1)
  672. \- tools for examining non-textfiles.
  673. ..SH STANDARDS CONFORMANCE
  674. This program is believed to exceed the System V Interface Definition
  675. of FILE(CMD), as near as one can determine from the vague language
  676. contained therein. 
  677. Its behaviour is mostly compatible with the System V program of the same name.
  678. This version knows more magic, however, so it will produce
  679. different (albeit more accurate) output in many cases. 
  680. ..PP
  681. The one significant difference 
  682. between this version and System V
  683. is that this version treats any white space
  684. as a delimiter, so that spaces in pattern strings must be escaped.
  685. For example,
  686. ..br
  687. >10    string    language impress\     (imPRESS data)
  688. ..br
  689. in an existing magic file would have to be changed to
  690. ..br
  691. >10    string    language\e impress    (imPRESS data)
  692. ..PP
  693. The Sun Microsystems implementation of System V compatibility
  694. includes a file(1) command that has some extentions.
  695. My version differs from Sun's only in minor ways.
  696. The significant one is the `&' operator, which Sun's program expects as,
  697. for example,
  698. ..br
  699. >16    long&0x7fffffff    >0        not stripped
  700. ..br
  701. would be entered in my version as
  702. ..br
  703. >16    long    &0x7fffffff    not stripped
  704. ..br
  705. which is a little less general; it simply tests (location 16)&0x7ffffff
  706. and returns its truth value as a C expression.
  707. ..SH MAGIC DIRECTORY
  708. The magic file entries have been collected from various sources,
  709. mainly USENET, and contributed by various authors.
  710. Ian Darwin (address below) will collect additional
  711. or corrected magic file entries.
  712. A consolidation of magic file entries 
  713. will be distributed periodically.
  714. ..PP
  715. The order of entries in the magic file is significant.
  716. Depending on what system you are using, the order that
  717. they are put together may be incorrect.
  718. If your old
  719. ..I file
  720. command uses a magic file,
  721. keep the old magic file around for comparison purposes
  722. (rename it to 
  723. ..IR /etc/magic.orig ).
  724. ..SH HISTORY
  725. There has been a 
  726. ..I file
  727. command in every UNIX since at least Research Version 6
  728. (man page dated January, 1975).
  729. The System V version introduced one significant major change:
  730. the external list of magic number types.
  731. This slowed the program down slightly but made it a lot more flexible.
  732. ..PP
  733. This program, based on the System V version,
  734. was written by Ian Darwin without looking at anybody else's source code.
  735. ..PP
  736. John Gilmore revised the code extensively, making it better than
  737. the first version.
  738. Geoff Collyer found several inadequacies
  739. and provided some magic file entries.
  740. The program has undergone continued evolution since.
  741. ..SH NOTICE
  742. Copyright (c) Ian F. Darwin,  1986 and 1987.
  743. Written by Ian F. Darwin, UUCP address {utzoo | ihnp4}!darwin!ian,
  744. Internet address ian@sq.com,
  745. postal address: P.O. Box 603, Station F, Toronto, Ontario, CANADA M4Y 2L8.
  746. ..PP
  747. ..I Strtok.c
  748. and
  749. ..I getopt.c
  750. written by and copyright by Henry Spencer, utzoo!henry.
  751. ..PP
  752. This software is not subject to any license of the American Telephone
  753. and Telegraph Company or of the Regents of the University of California.
  754. ..PP
  755. Permission is granted to anyone to use this software for any purpose on
  756. any computer system, and to alter it and redistribute it freely, subject
  757. to the following restrictions:
  758. ..PP 
  759. 1. The author is not responsible for the consequences of use of this
  760. software, no matter how awful, even if they arise from flaws in it.
  761. ..PP
  762. 2. The origin of this software must not be misrepresented, either by
  763. explicit claim or by omission.  Since few users ever read sources,
  764. credits must appear in the documentation.
  765. ..PP
  766. 3. Altered versions must be plainly marked as such, and must not be
  767. misrepresented as being the original software.  Since few users
  768. ever read sources, credits must appear in the documentation.
  769. ..PP
  770. 4. This notice may not be removed or altered.
  771. ..PP
  772. A few support files (\fIgetopt\fP, \fIstrtok\fP)
  773. distributed with this package
  774. are by Henry Spencer and are subject to the same terms as above.
  775. ..PP
  776. A few simple support files (\fIstrtol\fP, \fIstrchr\fP)
  777. distributed with this package
  778. are in the public domain; they are so marked.
  779. ..PP
  780. The files
  781. ..I tar.h
  782. and
  783. ..I is_tar.c
  784. were written by John Gilmore from his public-domain
  785. ..I tar
  786. program, and are not covered by the above restrictions.
  787. ..SH BUGS
  788. There must be a way to automate the construction of the Magic
  789. file from all the glop in magdir. What is it?
  790. ..PP
  791. ..I File
  792. uses several algorithms that favor speed over accuracy,
  793. thus it can be misled about the contents of ASCII files.
  794. ..PP
  795. The support for ASCII files (primarily for programming languages)
  796. is simplistic, inefficient and requires recompilation to update.
  797. ..PP
  798. Should there be an ``else'' clause to follow a series of continuation lines?
  799. ..PP
  800. Is it worthwhile to implement recursive file inspection,
  801. so that compressed files, uuencoded, etc., can say ``compressed
  802. ascii text'' or ``compressed executable'' or ``compressed tar archive"
  803. or whatever? 
  804. ..PP
  805. The magic file and keywords should have regular expression support.
  806. ..PP
  807. It might be advisable to allow upper-case letters in keywords
  808. for e.g., troff commands vs man page macros.
  809. Regular expression support would make this easy.
  810. ..PP
  811. The program doesn't grok \s-2FORTRAN\s0.
  812. It should be able to figure \s-2FORTRAN\s0 by seeing some keywords which 
  813. appear indented at the start of line.
  814. Regular expression support would make this easy.
  815. ..PP
  816. The list of keywords in 
  817. ..I ascmagic
  818. probably belongs in the Magic file.
  819. This could be done by using some keyword like `*' for the offset value.
  820. ..PP
  821. The program should malloc the magic file structures,
  822. rather than using a fixed-size array as at present.
  823. ..PP
  824. The magic file should be compiled into binary 
  825. (or better yet, fixed-length ASCII strings 
  826. for use in heterogenous network environments) for faster startup.
  827. Then the program would run as fast as the Version 7 program of the same name,
  828. with the flexibility of the System V version.
  829. But then there would have to be yet another magic number for the 
  830. ..I magic.out
  831. file.
  832. ..PP
  833. Another optimisation would be to sort
  834. the magic file so that we can just run down all the
  835. tests for the first byte, first word, first long, etc, once we
  836. have fetched it.  Complain about conflicts in the magic file entries.
  837. Make a rule that the magic entries sort based on file offset rather
  838. than position within the magic file?
  839. ..PP
  840. The program should provide a way to give an estimate 
  841. of ``how good'' a guess is.
  842. We end up removing guesses (e.g. ``From '' as first 5 chars of file) because
  843. they are not as good as other guesses (e.g. ``Newsgroups:'' versus
  844. "Return-Path:").  Still, if the others don't pan out, it should be
  845. possible to use the first guess.  
  846. ..PP
  847. Perhaps the program should automatically try all tests with
  848. byte-swapping done, to avoid having to figure out the byte-swapped values
  849. when constructing the magic file.
  850. Of course this will run more slowly, so it should probably be
  851. an option (-a?).
  852. ..PP
  853. This manual page, and particularly this section, is too long.
  854. @@@End of file.1
  855. echo x - magic.4 1>&2
  856. cat >magic.4 <<'@@@End of magic.4'
  857. ..TH MAGIC FILES "Public Domain"
  858. ..\" install as magic.4 on USG, magic.5 on V7 or Berkeley systems.
  859. ..SH NAME
  860. magic \- file command's magic number file
  861. ..SH DESCRIPTION
  862. The
  863. ..IR file (1)
  864. command identifies the type of a file using,
  865. among other tests,
  866. a test for whether the file begins with a certain
  867. ..IR "magic number" .
  868. The file
  869. ..B /etc/magic
  870. specifies what magic numbers are to be tested for,
  871. what message to print if a particular magic number is found,
  872. and additional information to extract from the file.
  873. ..PP
  874. Each line of the file specifies a test to be performed.
  875. A test compares the data starting at a particular offset
  876. in the file with a 1-byte, 2-byte, or 4-byte numeric value or
  877. a string.  If the test succeeds, a message is printed.
  878. The line consists of the following fields:
  879. ..IP offset \w'message'u+2n
  880. A number specifying the offset, in bytes, into the file of the data
  881. which is to be tested.
  882. ..IP type
  883. The type of the data to be tested.  The possible values are:
  884. ..RS
  885. ..IP byte \w'message'u+2n
  886. A one-byte value.
  887. ..IP short
  888. A two-byte value (on most systems).
  889. ..IP long
  890. A four-byte value (on most systems).
  891. ..IP string
  892. A string of bytes.
  893. ..RE
  894. ..IP test
  895. The value to be compared with the value from the file.  If the type is
  896. numeric, this value
  897. is specified in C form; if it is a string, it is specified as a C string
  898. with the usual escapes permitted (e.g. \en for new-line).
  899. ..IP
  900. Numeric values
  901. may be preceded by a character indicating the operation to be performed.
  902. It may be
  903. ..BR = ,
  904. to specify that the value from the file must equal the specified value,
  905. ..BR < ,
  906. to specify that the value from the file must be less than the specified
  907. value,
  908. ..BR > ,
  909. to specify that the value from the file must be greater than the specified
  910. value,
  911. or
  912. ..BR & ,
  913. to specify that the value is to be AND'ed with the
  914. numeric value before any comparisons are done.
  915. Numeric values are specified in C form; e.g.
  916. ..B 13
  917. is decimal,
  918. ..B 013
  919. is octal, and
  920. ..B 0x13
  921. is hexadecimal.
  922. to specify that any value will match.  If the character
  923. is omitted, it is assumed to be
  924. ..BR = .
  925. ..IP
  926. For string values, the byte string from the
  927. file must match the specified byte string. 
  928. The operators =, < and > (but not &) can be applied to strings.
  929. The length used for matching is that of the string argument
  930. in the magic file.
  931. ..IP message
  932. The message to be printed if the comparison succeeds.  If the string
  933. contains a
  934. ..IR printf (3S)
  935. format specification, the value from the file (with any specified masking
  936. performed) is printed using the message as the format string.
  937. ..PP
  938. Some file formats contain additional information which is to be printed
  939. along with the file type.  A line which begins with the character
  940. ..B >
  941. indicates additional tests and messages to be printed.  If the test on the
  942. line preceding the first line with a
  943. ..B >
  944. succeeds, the tests specified in all the subsequent lines beginning with
  945. ..B >
  946. are performed, and the messages printed if the tests succeed.  The next
  947. line which does not begin with a
  948. ..B >
  949. terminates this.
  950. ..SH BUGS
  951. The formats 
  952. ..I long
  953. and
  954. ..I short
  955. are system-dependant; perhaps they should be specified as a number
  956. of bytes (2B, 4B, etc), 
  957. since the files being recognized typically come from
  958. a system on which the lengths are invariant.
  959. ..PP
  960. There should be more than one level of subtests,
  961. with the level possibly indicated by
  962. the number of
  963. ..B >
  964. at the beginning of the line.
  965. ..SH SEE ALSO
  966. ..IR file (1)
  967. \- the command that reads this file.
  968. ..\"
  969. ..\" From: guy@sun.uucp (Guy Harris)
  970. ..\" Newsgroups: net.bugs.usg
  971. ..\" Subject: /etc/magic's format isn't well documented
  972. ..\" Message-ID: <2752@sun.uucp>
  973. ..\" Date: 3 Sep 85 08:19:07 GMT
  974. ..\" Organization: Sun Microsystems, Inc.
  975. ..\" Lines: 136
  976. ..\" 
  977. ..\" Here's a manual page for the format accepted by the "file" made by adding
  978. ..\" the changes I posted to the S5R2 version.
  979. ..\"
  980. ..\" Modified for Ian Darwin's version of the file command.
  981. ..\" @(#)$Header: magic.4,v 1.5 87/11/06 20:54:31 ian Exp $
  982. @@@End of magic.4
  983. echo x - magdir/aa 1>&2
  984. cat >magdir/aa <<'@@@End of magdir/aa'
  985. #! file
  986. # Magic data for file(1) command.
  987. # Machine-genererated from src/cmd/file/magdir/*; edit there only!
  988. # Format is described in magic(files), where:
  989. # files is 4 on V7 and BSD, 4 on SV, and ?? in the SVID.
  990. @@@End of magdir/aa
  991. echo x - magdir/aalocal 1>&2
  992. cat >magdir/aalocal <<'@@@End of magdir/aalocal'
  993. #    Add any locally-observed files here.  Remember:
  994. #    text if readable, executable if runnable binary, data if unreadable.
  995. 22    short    023000        core dump data
  996. @@@End of magdir/aalocal
  997. echo x - magdir/arc 1>&2
  998. cat >magdir/arc <<'@@@End of magdir/arc'
  999. 0    byte        26        'arc' archive
  1000. >1    byte        0        (empty)
  1001. >1    byte        1        (old format)
  1002. @@@End of magdir/arc
  1003. echo x - magdir/archive 1>&2
  1004. cat >magdir/archive <<'@@@End of magdir/archive'
  1005. 0    short        070707        cpio archive
  1006. 0    string        070707        ASCII cpio archive
  1007. 0    long        0177555        very old archive
  1008. 0    short        0177555        very old PDP-11 archive
  1009. 0    long        0177545        old archive
  1010. 0    short        0177545        old PDP-11 archive
  1011. 0    long        0100554        apl workspace
  1012. 0    string        =<ar>        archive
  1013. 0    string        !<arch>        archive
  1014. >8    string        __.SYMDEF    random library
  1015. 0    string        -h-        archive (Software Tools format) text
  1016. @@@End of magdir/archive
  1017. echo x - magdir/c 1>&2
  1018. cat >magdir/c <<'@@@End of magdir/c'
  1019. #    this first will upset you if you're a PL/1 shop...
  1020. #    in which case rm it; ascmagic will catch real C programs
  1021. 0    string        /*        c program text
  1022. #    check for various C program generators...
  1023. #    offsets derived empirically, your offsets may vary!
  1024. #    (this obviously belongs in ascmagic.c/names.h!).
  1025. 53    string        yyprevious    c program text (from lex)
  1026. @@@End of magdir/c
  1027. echo x - magdir/commands 1>&2
  1028. cat >magdir/commands <<'@@@End of magdir/commands'
  1029. 0    string        #!\ /bin/sh    commands text
  1030. 0    string        #!/bin/sh    commands text
  1031. 0    string        #!\ /bin/csh    C shell commands text
  1032. 0    string        #!/bin/csh    C shell commands text
  1033. 0    string        #!\ /bin/awk    awk commands text
  1034. 0    string        #!/bin/awk    awk commands text
  1035. 0    string        #!\ /        some kinda commands text
  1036. 0    string        #!/        some kinda commands text
  1037. 0    string        #!\         commands text
  1038. >3    string        >\0         for %s
  1039. #    An "antique" kernel is either unmodified early V7,
  1040. #    without DMR's 1979 mod for #!, or any kernel
  1041. #    derived from a pre-v7 kernel (i.e., System V)
  1042. 0    string        :\         shell archive or commands for antique kernel text
  1043. @@@End of magdir/commands
  1044. echo x - magdir/compress 1>&2
  1045. cat >magdir/compress <<'@@@End of magdir/compress'
  1046. 0    short        017037        packed data
  1047. # CPL     - added pack to /etc/magic
  1048. 0    short        017436        packed data
  1049. 0    short        0145405        huf output
  1050.  
  1051. 0    string        \037\235    compressed data
  1052. # non block compressed
  1053. >2    byte        12        - with 12 bits
  1054. >2    byte        13        - with 13 bits
  1055. >2    byte        14        - with 14 bits
  1056. >2    byte        15        - with 15 bits
  1057. >2    byte        16        - with 16 bits
  1058. # block compressed
  1059. >2    byte        140        - with 12 bits
  1060. >2    byte        141        - with 13 bits
  1061. >2    byte        142        - with 14 bits
  1062. >2    byte        143        - with 15 bits
  1063. >2    byte        144        - with 16 bits
  1064. @@@End of magdir/compress
  1065. echo x - magdir/convex 1>&2
  1066. cat >magdir/convex <<'@@@End of magdir/convex'
  1067. 0    long        0513        Convex executable
  1068. @@@End of magdir/convex
  1069. echo x - magdir/diff 1>&2
  1070. cat >magdir/diff <<'@@@End of magdir/diff'
  1071. #
  1072. # magic file lines for output from "diff"...
  1073. 0    string        diff\     'diff' output text
  1074. 0    string        ***\         'diff' output text
  1075. 0    string        Only\ in\     'diff' output text
  1076. 0    string        Common\ subdirectories:\     'diff' output text
  1077. @@@End of magdir/diff
  1078. echo x - magdir/ditroff 1>&2
  1079. cat >magdir/ditroff <<'@@@End of magdir/ditroff'
  1080. # Magic numbers for ditroff intermediate language
  1081. 0    string        x\ T\ cat    titroff output for the C/A/T text
  1082. 0    string        x\ T\ ps    titroff output for PostScript
  1083. 0    string        x\ T         titroff output text
  1084. @@@End of magdir/ditroff
  1085. echo x - magdir/fonts 1>&2
  1086. cat >magdir/fonts <<'@@@End of magdir/fonts'
  1087. 0    string    FONT    ASCII vfont text
  1088. 0    short    0436    Berkeley vfont data
  1089. 0    short    017001    byte-swapped Berkeley vfont data
  1090. @@@End of magdir/fonts
  1091. echo x - magdir/frame 1>&2
  1092. cat >magdir/frame <<'@@@End of magdir/frame'
  1093. # Magic number for FrameMaker files
  1094. # Thanks to Berry Kercheval
  1095. #
  1096. 0    string        \<MakerFile    FrameMaker document
  1097. @@@End of magdir/frame
  1098. echo x - magdir/imagen 1>&2
  1099. cat >magdir/imagen <<'@@@End of magdir/imagen'
  1100. # Tell file about magic for IMAGEN printer-ready files:
  1101. 0    string    @document(        Imagen printer
  1102. # this only works if "language xxx" is first item in Imagen header.
  1103. >10    string    language\ impress    (imPRESS data)
  1104. >10    string    language\ daisy        (daisywheel text)
  1105. >10    string    language\ diablo        (daisywheel text)
  1106. >10    string    language\ printer    (line printer emulation)
  1107. >10    string    language\ tektronix    (Tektronix 4014 emulation)
  1108. # Add any other languages that your Imagen uses - remember
  1109. # to keep the word `text' if the file is human-readable.
  1110. #
  1111. # Now magic for IMAGEN font files...
  1112. 0    string        Rast        RST-format raster font data
  1113. >45    string        >0        face %
  1114. @@@End of magdir/imagen
  1115. echo x - magdir/intel 1>&2
  1116. cat >magdir/intel <<'@@@End of magdir/intel'
  1117. # various intel-CPU magic numbers
  1118. 0    short        01006        80286 executable (STL)
  1119. >31    byte        <0x040        small model
  1120. >31    byte        =0x048        large model    
  1121. >31    byte        =0x049        huge model 
  1122. >16    long        >0        not stripped
  1123. 0    string        MZ        DOS executable (EXE)
  1124. 0    string        LZ        DOS executable (built-in)
  1125. 0    byte        0xe9        DOS executable (COM)
  1126. 0    byte        0xeb        DOS executable (COM)
  1127. 0    short        =0512        80286 executable small model (COFF)
  1128. >12    long        >0        not stripped
  1129. >22    short        >0        - version %ld
  1130. 0    short        =0522        80286 executable large model (COFF)
  1131. >12    long        >0        not stripped
  1132. >22    short        >0        - version %ld
  1133. 0    short        =0514        80386 executable
  1134. >12    long        >0        not stripped
  1135. >22    short        >0        - version %ld
  1136.  
  1137. @@@End of magdir/intel
  1138. echo x - magdir/magic 1>&2
  1139. cat >magdir/magic <<'@@@End of magdir/magic'
  1140. 0    string        #magic        magic text file for file(1) cmd
  1141. @@@End of magdir/magic
  1142. echo x - magdir/mail.news 1>&2
  1143. cat >magdir/mail.news <<'@@@End of magdir/mail.news'
  1144. # Unfortunately, saved netnews also has From line added in some news software.
  1145. #0    string        From         mail text
  1146. # There are tests to ascmagic.c to cope with mail and news.
  1147. 0    string        Relay-Version:     old news text
  1148. 0    string        #!\ rnews    batched news text
  1149. 0    string        N#!\ rnews    mailed, batched news text
  1150. 0    string        Forward\ to     mail forwarding text
  1151. 0    string        Pipe\ to     mail piping text
  1152. 0    string        Return-Path:    smtp mail text
  1153. 0    string        Path:        news text
  1154. 0    string        Xref:        news text
  1155. 0    string        From:        news or mail text
  1156. 0    string        Article     saved news text
  1157. @@@End of magdir/mail.news
  1158. echo x - magdir/mirage 1>&2
  1159. cat >magdir/mirage <<'@@@End of magdir/mirage'
  1160. 0    long    31415        Mirage Assembler m.out executable
  1161. @@@End of magdir/mirage
  1162. echo x - magdir/misc 1>&2
  1163. cat >magdir/misc <<'@@@End of magdir/misc'
  1164. 0    string        begin         uuencoded mail text
  1165. @@@End of magdir/misc
  1166. echo x - magdir/misc2 1>&2
  1167. cat >magdir/misc2 <<'@@@End of magdir/misc2'
  1168. #    derived empirically, your offsets may vary!
  1169. 53    string        yyprevious    c program text (from lex)
  1170. @@@End of magdir/misc2
  1171. echo x - magdir/olda.out 1>&2
  1172. cat >magdir/olda.out <<'@@@End of magdir/olda.out'
  1173. 0    long        0407        executable
  1174. >16    long        >0        not stripped
  1175. #>2    short        >0        - version %ld
  1176. 0    short        0407        PDP-11 executable
  1177. >8    short        >0        not stripped
  1178. 0    short        0401        unix-rt ldp
  1179. 0    short        0405        old overlay
  1180. 0    long        0410        pure executable
  1181. >16    long        >0        not stripped
  1182. #>2    short        >0        - version %ld
  1183. 0    short        0410        PDP-11 pure executable
  1184. >8    short        >0        not stripped
  1185. #>2    short        >0        - version %ld
  1186. 0    short        0411        PDP-11 separate I&D executable
  1187. >8    short        >0        not stripped
  1188. #>2    short        >0        - version %ld
  1189. 0    long        0413        demand paged pure executable
  1190. >16    long        >0        not stripped
  1191. #>2    short        >0        - version %ld
  1192. 0    long        0420        demand paged (first page unmapped) pure executable
  1193. >16    long        >0        not stripped
  1194. #>2    short        >0        - version %ld
  1195. 0    short        0437        pdp11 kernel overlay
  1196. @@@End of magdir/olda.out
  1197. echo x - magdir/postscript 1>&2
  1198. cat >magdir/postscript <<'@@@End of magdir/postscript'
  1199. #
  1200. # Let us not forget PostScript
  1201. 0    string    %!            PostScript text
  1202. >2    string    PS-Adobe-        conforming
  1203. >11    string    1.0            at level %s
  1204. @@@End of magdir/postscript
  1205. echo x - magdir/rasterfile 1>&2
  1206. cat >magdir/rasterfile <<'@@@End of magdir/rasterfile'
  1207. # Sun rasterfiles
  1208. 0    string    \x59\xa6\x6a\x95    rasterfile
  1209. >4    long    >0        %d
  1210. >8    long    >0        x %d
  1211. >12    long    >0        x %d
  1212. >20    long    0        old format
  1213. >20    long    2        compressed
  1214. >24    long    1        with color map
  1215. @@@End of magdir/rasterfile
  1216. echo x - magdir/sccs 1>&2
  1217. cat >magdir/sccs <<'@@@End of magdir/sccs'
  1218. # SCCS archive structure:
  1219. # \001h01207
  1220. # \001s 00276/00000/00000
  1221. # \001d D 1.1 87/09/23 08:09:20 ian 1 0
  1222. # \001c date and time created 87/09/23 08:09:20 by ian
  1223. # \001e
  1224. # \001u
  1225. # \001U
  1226. # ... etc.
  1227. # Now '\001h' happens to be the same as the 3B20's a.out magic number (0550).
  1228. # *Sigh*. And these both came from various parts of the USG.
  1229. # Maybe we should just switch everybody from SCCS to RCS!
  1230. # Further, you can't just say '\001h0', because the five-digit number
  1231. # is a checksum that could (presumably) have any leading digit,
  1232. # and we don't have regular expression matching yet. 
  1233. # Hence the following official kludge:
  1234. 8    string        \001s\             SCCS archive.
  1235. @@@End of magdir/sccs
  1236. echo x - magdir/sequent 1>&2
  1237. cat >magdir/sequent <<'@@@End of magdir/sequent'
  1238. # For Sequent's multiprocessor systems (incomplete).
  1239. 0    long    000352        BALANCE NS32000 .o
  1240. 0    long    010352        BALANCE NS32000 executable (0 @ 0)
  1241. >16    long    >0        not stripped
  1242. 0    long    020352        BALANCE NS32000 executable (invalid @ 0)
  1243. >16    long    >0        not stripped
  1244. 0    long    030352        BALANCE NS32000 standalone executable
  1245. >16    long    >0        not stripped
  1246. # Also need info on Sequent "Symmetry" series...
  1247. @@@End of magdir/sequent
  1248. echo x - magdir/softquad 1>&2
  1249. cat >magdir/softquad <<'@@@End of magdir/softquad'
  1250. # SoftQuad troff magic numbers
  1251. # SoftQuad @(#)magic    1.2 86/09/15
  1252. 0    short        0125252        SoftQuad DESC or font file binary
  1253. >2    short        >0        - version %d
  1254. @@@End of magdir/softquad
  1255. echo x - magdir/sun 1>&2
  1256. cat >magdir/sun <<'@@@End of magdir/sun'
  1257. # Values for Sun MC680x0 binaries
  1258. 0    short        2        mc68020
  1259. >2    short        0407        executable
  1260. >2    short        0410        pure executable
  1261. >2    short        0413        demand paged executable
  1262. >16    long        >0        not stripped
  1263. 0    short        1        mc68010
  1264. >2    short        0407        executable
  1265. >2    short        0410        pure executable
  1266. >2    short        0413        demand paged executable
  1267. >16    long        >0        not stripped
  1268. 0    short        0        old sun-2
  1269. >2    short        0407        executable
  1270. >2    short        0410        pure executable
  1271. >2    short        0413        demand paged executable
  1272. >16    long        >0        not stripped
  1273. 0    long        0x080456    core file
  1274. >128    string        >0        from '%s'
  1275. #
  1276. 0    short        05401        byte-swapped demand paged executable
  1277. 0    short        010001        byte-swapped demand paged executable
  1278. @@@End of magdir/sun
  1279. echo x - magdir/tower 1>&2
  1280. cat >magdir/tower <<'@@@End of magdir/tower'
  1281. # NCR Tower objects, contributed by
  1282. # Michael R. Wayne  ***  TMC & Associates  ***  INTERNET: wayne@ford-vax.arpa
  1283. # uucp: {philabs | pyramid} !fmsrl7!wayne   OR   wayne@fmsrl7.UUCP
  1284. #
  1285. 0    short        000610    Tower/XP rel 2 object
  1286. >12       long            >0    not stripped
  1287. >20       short        0407    executable
  1288. >20       short        0410    pure executable
  1289. >22       short        >0    -version %ld
  1290. 0    short        000615    Tower/XP rel 2 object
  1291. >12       long            >0    not stripped
  1292. >20       short        0407    executable
  1293. >20       short        0410    pure executable
  1294. >22       short        >0    -version %ld
  1295. 0    short        000620    Tower/XP rel 3 object
  1296. >12       long            >0    not stripped
  1297. >20       short        0407    executable
  1298. >20       short        0410    pure executable
  1299. >22       short        >0    -version %ld
  1300. 0    short        000625    Tower/XP rel 3 object
  1301. >12       long            >0    not stripped
  1302. >20       short        0407    executable
  1303. >20       short        0410    pure executable
  1304. >22       short        >0    -version %ld
  1305. 0    short        000630    Tower32/600/400 68020 object
  1306. >12       long            >0    not stripped
  1307. >20       short        0407    executable
  1308. >20       short        0410    pure executable
  1309. >22       short        >0    -version %ld
  1310. 0    short        000640    Tower32/800 68020
  1311. >18       short        &020000    w/68881 object
  1312. >18       short        &040000    compatible object
  1313. >18       short        &~060000    object
  1314. >20       short        0407    executable
  1315. >20       short        0413    pure executable
  1316. >12       long            >0    not stripped
  1317. >22       short        >0    -version %ld
  1318. 0    short        000645    Tower32/800 68010
  1319. >18       short        &040000    compatible object
  1320. >18       short        &~060000 object
  1321. >20       short        0407    executable
  1322. >20       short        0413    pure executable
  1323. >12       long            >0    not stripped
  1324. >22       short        >0    -version %ld
  1325. @@@End of magdir/tower
  1326. echo x - magdir/typeset 1>&2
  1327. cat >magdir/typeset <<'@@@End of magdir/typeset'
  1328. # other typesetting magic
  1329. 0    string        \100\357    very old (C/A/T) troff output data
  1330. 0    string        Interpress/Xerox    Xerox InterPress data
  1331. @@@End of magdir/typeset
  1332. echo x - magdir/varied.out 1>&2
  1333. cat >magdir/varied.out <<'@@@End of magdir/varied.out'
  1334. #    Herewith many of the object file formats used by USG systems.
  1335. #    The `versions' should be un-commented if they work for you.
  1336. 0    short        0570        SysV executable
  1337. >12    long        >0        not stripped
  1338. #>22    short        >0        - version %ld
  1339. 0    short        0575        SysV pure executable
  1340. >12    long        >0        not stripped
  1341. #>22    short        >0        - version %ld
  1342. 0    short        0502        basic-16 executable
  1343. >12    long        >0        not stripped
  1344. 0    short        0503        basic-16 executable (TV)
  1345. >12    long        >0        not stripped
  1346. 0    short        0510        x86 executable
  1347. >12    long        >0        not stripped
  1348. 0    short        0511        x86 executable (TV)
  1349. >12    long        >0        not stripped
  1350. 0    short        0550        3b20 executable
  1351. >12    long        >0        not stripped
  1352. 0    short        0551        3b20 executable (TV)
  1353. >12    long        >0        not stripped
  1354. 0    short        0560        WE32000 executable
  1355. >12    long        >0        not stripped
  1356. 0    short        0561        WE32000 executable (TV)
  1357. >12    long        >0        not stripped
  1358. 0    short        0610        Perkin-Elmer executable
  1359.  
  1360. @@@End of magdir/varied.out
  1361. echo x - magdir/vax.byteswap 1>&2
  1362. cat >magdir/vax.byteswap <<'@@@End of magdir/vax.byteswap'
  1363. # Byte-swapped VAXen
  1364. # From: dupuy@amsterdam.columbia.edu (Alexander Dupuy)
  1365. # Here are a few lines you can add to /etc/magic on your sun workstations in
  1366. # order to recognize VAX executables and objects.... you could do something
  1367. # similar (in reverse) for your vaxen, but since 4.3+NFS' file(1) doesn't look
  1368. # for /etc/magic, I've never bothered.  It really should be built in to file(1)
  1369. # so you would see the state of setuid/setgid/sticky bits.  Or actually, there
  1370. # should be support for checking that sort of thing in /etc/magic.
  1371. #
  1372. 0    long        00700200000    VAX executable
  1373. >16    long        &0x7fffffff    not stripped
  1374. 0    long        01000200000    VAX pure executable
  1375. >16    long        &0x7fffffff    not stripped
  1376. 0    long        01300200000    VAX demand-paged pure executable
  1377. >16    long        &0x7fffffff    not stripped
  1378. 0    long        01100200000    PDP-11 executable
  1379. @@@End of magdir/vax.byteswap
  1380. echo x - magdir/xenix 1>&2
  1381. cat >magdir/xenix <<'@@@End of magdir/xenix'
  1382. # XENIX executable formats: derived empirically; treat as folklore until proven0    short    01006        XENIX (x.out) executable
  1383. >8    short    1        Middle model
  1384. >16    short    >0        not stripped
  1385. 0    short    02600        XENIX 8086 relocatable or 80286 small model
  1386.  
  1387. @@@End of magdir/xenix
  1388. echo x - tst/Makefile 1>&2
  1389. cat >tst/Makefile <<'@@@End of tst/Makefile'
  1390. # Make up some fake test files that are easily produced.
  1391. # By no means an exhaustive test!
  1392. # @(#) $Header: Makefile,v 1.4 87/11/07 12:46:09 ian Exp $
  1393. all:    ar cmd emp i t x
  1394. ar:
  1395.     echo '<ar> fake fake fake' >$@
  1396.     echo 070707 fake fake fake >$@.asc
  1397.     echo '!<arch>.__.SYMDEF fake fake fake' >$@.ranlib
  1398.     echo - -h- >$@.swt
  1399. cmd:
  1400.     echo '#! /bin/sh' >$@
  1401.     echo '#!/bin/sh' >c.sh2
  1402.     echo '#! /bin/csh' >c.csh1
  1403.     echo '#!/bin/csh' >c.csh2
  1404.     echo '#! /bin/awk' >c.awk1
  1405.     echo '#!/bin/awk' >c.awk2
  1406.     echo '#! /' >c.misc1
  1407.     echo '#!/' >c.misc2
  1408.     echo ': ' >c.broken
  1409. emp:
  1410.     touch $@
  1411. i:
  1412.     echo '@document(language impress)fake fake' >$@
  1413.     echo '@document(language diablo)fake fake' >$@.d
  1414. t:
  1415.     rm -f $@
  1416.     tar cvf $@ *
  1417. x:
  1418.     echo 'Interpress/Xerox fake fake fake' >$@
  1419.  
  1420. clean:
  1421.     rm -f [a-z]*
  1422. @@@End of tst/Makefile
  1423.  
  1424.