home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / file39a.zip / src / file.h < prev    next >
C/C++ Source or Header  |  1993-04-07  |  5KB  |  146 lines

  1. /*
  2.  * file.h - definitions for file(1) program
  3.  * @(#)$Id: file.h,v 1.14 93/02/19 14:22:44 ian Exp $
  4.  *
  5.  * Copyright (c) Ian F. Darwin, 1987.
  6.  * Written by Ian F. Darwin.
  7.  *
  8.  * This software is not subject to any license of the American Telephone
  9.  * and Telegraph Company or of the Regents of the University of California.
  10.  *
  11.  * Permission is granted to anyone to use this software for any purpose on
  12.  * any computer system, and to alter it and redistribute it freely, subject
  13.  * to the following restrictions:
  14.  *
  15.  * 1. The author is not responsible for the consequences of use of this
  16.  *    software, no matter how awful, even if they arise from flaws in it.
  17.  *
  18.  * 2. The origin of this software must not be misrepresented, either by
  19.  *    explicit claim or by omission.  Since few users ever read sources,
  20.  *    credits must appear in the documentation.
  21.  *
  22.  * 3. Altered versions must be plainly marked as such, and must not be
  23.  *    misrepresented as being the original software.  Since few users
  24.  *    ever read sources, credits must appear in the documentation.
  25.  *
  26.  * 4. This notice may not be removed or altered.
  27.  */
  28.  
  29. #define HOWMANY    1024        /* how much of the file to look at */
  30. #ifdef MSC        /* 16-bit int */
  31. #define MAXMAGIC (0xff00 / sizeof(struct magic)) /* max entries in magicfile */
  32. #define MAXMAGIS MAXMAGIC                                 /* initial allocation */
  33. #else
  34. #define MAXMAGIS 1000        /* max entries in /etc/magic */
  35. #endif
  36. #define MAXDESC    50        /* max leng of text description */
  37. #define MAXstring 32        /* max leng of "string" types */
  38.  
  39. struct magic {
  40.     short flag;        
  41. #define INDIR    1        /* if '>(...)' appears,  */
  42.     short cont_level;    /* level of ">" */
  43.     struct {
  44.         char type;    /* byte short long */
  45.         long offset;    /* offset from indirection */
  46.     } in;
  47.     long offset;        /* offset to magic number */
  48. #define    MASK    0200        /* this is a masked op, like & v1 = v2 */
  49.     unsigned char reln;    /* relation (0=eq, '>'=gt, etc) */
  50.     char type;        /* int, short, long or string. */
  51.     char vallen;        /* length of string value, if any */
  52. #define             BYTE    1
  53. #define                SHORT    2
  54. #define                LONG    4
  55. #define                STRING    5
  56. #define                DATE    6
  57. #define                BESHORT    7
  58. #define                BELONG    8
  59. #define                BEDATE    9
  60. #define                LESHORT    10
  61. #define                LELONG    11
  62. #define                LEDATE    12
  63.     union VALUETYPE {
  64.         char b;
  65.         short h;
  66.         long l;
  67.         char s[MAXstring];
  68.         unsigned char hs[2];    /* 2 bytes of a fixed-endian "short" */
  69.         unsigned char hl[4];    /* 2 bytes of a fixed-endian "long" */
  70.     } value;        /* either number or string */
  71.     long mask;        /* mask before comparison with value */
  72.     char nospflag;        /* supress space character */
  73. #ifdef OS2
  74.     char *desc;            /* description */
  75. #else
  76.     char desc[MAXDESC];    /* description */
  77. #endif
  78. };
  79.  
  80. #include <stdio.h>    /* Include that here, to make sure __P gets defined */
  81.  
  82. #ifndef __P
  83. # if __STDC__ || __cplusplus
  84. #  define __P(a) a
  85. # else
  86. #  define __P(a) ()
  87. #  define const
  88. # endif
  89. #endif
  90.  
  91. extern int   apprentice        __P((char *, int));
  92. extern int   ascmagic        __P((unsigned char *, int));
  93. extern void  error        __P((const char *, ...));
  94. extern void  ckfputs        __P((const char *, FILE *));
  95. struct stat;
  96. extern int   fsmagic        __P((const char *, struct stat *));
  97. extern int   is_compress    __P((const unsigned char *, int *));
  98. extern int   is_tar        __P((unsigned char *));
  99. extern void  magwarn        __P((const char *, ...));
  100. extern void  mdump        __P((struct magic *));
  101. extern void  process        __P((const char *, int));
  102. extern void  showstr        __P((const char *));
  103. extern int   softmagic        __P((unsigned char *, int));
  104. extern void  tryit        __P((unsigned char *, int));
  105. extern int   uncompress        __P((const unsigned char *, unsigned char **, int));
  106. extern void  ckfprintf        __P((FILE *, const char *, ...));
  107.  
  108.  
  109. #ifndef OS2
  110. extern int errno;        /* Some unixes don't define this..    */
  111. #endif
  112.  
  113. extern char *progname;        /* the program name             */
  114. extern char *magicfile;        /* name of the magic file        */
  115. extern int lineno;        /* current line number in magic file    */
  116.  
  117. extern struct magic *magic;    /* array of magic entries        */
  118. extern int nmagic;        /* number of valid magic[]s         */
  119.  
  120.  
  121. extern int debug;        /* enable debugging?            */
  122. extern int zflag;        /* process compressed files?        */
  123. extern int lflag;        /* follow symbolic links?        */
  124.  
  125. extern int optind;        /* From getopt(3)            */
  126. extern char *optarg;
  127.  
  128. #if !defined(__STDC__) || defined(sun)
  129. extern int sys_nerr;
  130. extern char *sys_errlist[];
  131. #define strerror(e) \
  132.     (((e) >= 0 && (e) < sys_nerr) ? sys_errlist[(e)] : "Unknown error")
  133. #endif
  134.  
  135. #ifndef MAXPATHLEN
  136. #ifdef OS2
  137. #define    MAXPATHLEN    _MAX_PATH
  138. #else
  139. #define    MAXPATHLEN    512
  140. #endif
  141. #endif
  142.  
  143. #ifdef MSC
  144. char    *_getname(char *);
  145. #endif
  146.