]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/file/file.h
This commit was generated by cvs2svn to compensate for changes in r98841,
[FreeBSD/FreeBSD.git] / contrib / file / file.h
1 /*
2  * file.h - definitions for file(1) program
3  * @(#)$Id: file.h,v 1.37 2001/07/22 21:04:15 christos 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 #ifndef __file_h__
30 #define __file_h__
31
32 #ifdef HAVE_CONFIG_H
33 #include <config.h>
34 #endif
35
36 typedef int int32;
37 typedef unsigned int uint32;
38 typedef short int16;
39 typedef unsigned short uint16;
40 typedef char int8;
41 typedef unsigned char uint8;
42
43 #ifndef HOWMANY
44 # define HOWMANY 16384          /* how much of the file to look at */
45 #endif
46 #define MAXMAGIS 1000           /* max entries in /etc/magic */
47 #define MAXDESC 50              /* max leng of text description */
48 #define MAXstring 32            /* max leng of "string" types */
49
50 #define MAGICNO         0xF11E041C
51 #define VERSIONNO       1
52
53 #define CHECK   1
54 #define COMPILE 2
55
56 struct magic {
57         uint16 cont_level;/* level of ">" */
58         uint8 nospflag; /* supress space character */
59         uint8 flag;
60 #define INDIR   1               /* if '>(...)' appears,  */
61 #define UNSIGNED 2              /* comparison is unsigned */
62 #define OFFADD  4               /* if '>&' appears,  */
63         uint8 reln;             /* relation (0=eq, '>'=gt, etc) */
64         uint8 vallen;           /* length of string value, if any */
65         uint8 type;             /* int, short, long or string. */
66         uint8 in_type;          /* type of indirrection */
67 #define                         BYTE    1
68 #define                         SHORT   2
69 #define                         LONG    4
70 #define                         STRING  5
71 #define                         DATE    6
72 #define                         BESHORT 7
73 #define                         BELONG  8
74 #define                         BEDATE  9
75 #define                         LESHORT 10
76 #define                         LELONG  11
77 #define                         LEDATE  12
78 #define                         PSTRING 13
79 #define                         LDATE   14
80 #define                         BELDATE 15
81 #define                         LELDATE 16
82         uint8 in_op;            /* operator for indirection */
83         uint8 mask_op;          /* operator for mask */
84 #define                         OPAND   1
85 #define                         OPOR    2
86 #define                         OPXOR   3
87 #define                         OPADD   4
88 #define                         OPMINUS 5
89 #define                         OPMULTIPLY      6
90 #define                         OPDIVIDE        7
91 #define                         OPMODULO        8
92 #define                         OPINVERSE       0x80
93         int32 offset;           /* offset to magic number */
94         int32 in_offset;        /* offset from indirection */
95         union VALUETYPE {
96                 unsigned char b;
97                 unsigned short h;
98                 uint32 l;
99                 char s[MAXstring];
100                 unsigned char hs[2];    /* 2 bytes of a fixed-endian "short" */
101                 unsigned char hl[4];    /* 4 bytes of a fixed-endian "long" */
102         } value;                /* either number or string */
103         uint32 mask;    /* mask before comparison with value */
104         char desc[MAXDESC];     /* description */
105 };
106
107 #define BIT(A)   (1 << (A))
108 #define STRING_IGNORE_LOWERCASE         BIT(0)
109 #define STRING_COMPACT_BLANK            BIT(1)
110 #define STRING_COMPACT_OPTIONAL_BLANK   BIT(2)
111 #define CHAR_IGNORE_LOWERCASE           'c'
112 #define CHAR_COMPACT_BLANK              'B'
113 #define CHAR_COMPACT_OPTIONAL_BLANK     'b'
114
115
116 /* list of magic entries */
117 struct mlist {
118         struct magic *magic;            /* array of magic entries */
119         uint32 nmagic;                  /* number of entries in array */
120         struct mlist *next, *prev;
121 };
122
123 #include <stdio.h>      /* Include that here, to make sure __P gets defined */
124 #include <errno.h>
125
126 #ifndef __P
127 # if defined(__STDC__) || defined(__cplusplus)
128 #  define __P(a) a
129 # else
130 #  define __P(a) ()
131 #  define const
132 # endif
133 #endif
134
135 extern int   apprentice         __P((const char *, int));
136 extern int   ascmagic           __P((unsigned char *, int));
137 extern void  error              __P((const char *, ...));
138 extern void  ckfputs            __P((const char *, FILE *));
139 struct stat;
140 extern int   fsmagic            __P((const char *, struct stat *));
141 extern char *fmttime            __P((long, int));
142 extern int   is_compress        __P((const unsigned char *, int *));
143 extern int   is_tar             __P((unsigned char *, int));
144 extern void  magwarn            __P((const char *, ...));
145 extern void  mdump              __P((struct magic *));
146 extern void  process            __P((const char *, int));
147 extern void  showstr            __P((FILE *, const char *, int));
148 extern int   softmagic          __P((unsigned char *, int));
149 extern int   tryit              __P((unsigned char *, int, int));
150 extern int   zmagic             __P((unsigned char *, int));
151 extern void  ckfprintf          __P((FILE *, const char *, ...));
152 extern uint32 signextend        __P((struct magic *, unsigned int32));
153 extern void tryelf              __P((int, unsigned char *, int));
154
155 extern char *progname;          /* the program name                     */
156 extern const char *magicfile;   /* name of the magic file               */
157 extern int lineno;              /* current line number in magic file    */
158
159 extern struct mlist mlist;      /* list of arrays of magic entries      */
160
161 extern int debug;               /* enable debugging?                    */
162 extern int zflag;               /* process compressed files?            */
163 extern int lflag;               /* follow symbolic links?               */
164 extern int sflag;               /* read/analyze block special files?    */
165 extern int iflag;               /* Output types as mime-types           */
166
167 extern int optind;              /* From getopt(3)                       */
168 extern char *optarg;
169
170 #ifndef HAVE_STRERROR
171 extern int sys_nerr;
172 extern char *sys_errlist[];
173 #define strerror(e) \
174         (((e) >= 0 && (e) < sys_nerr) ? sys_errlist[(e)] : "Unknown error")
175 #endif
176
177 #ifndef HAVE_STRTOUL
178 #define strtoul(a, b, c)        strtol(a, b, c)
179 #endif
180
181 #if defined(HAVE_MMAP) && defined(HAVE_SYS_MMAN_H) && !defined(QUICK)
182 #define QUICK
183 #endif
184
185 #ifdef __STDC__
186 #define FILE_RCSID(id) \
187 static const char *rcsid(const char *p) { \
188         return rcsid(p = id); \
189 }
190 #else
191 #define FILE_RCSID(id) static char rcsid[] = id;
192 #endif
193
194 #endif /* __file_h__ */