2682edcc3a0ffc5fb552e1d7ea2b0891c2ea9b55
[dragonfly.git] / contrib / file / src / names.h
1 /*
2  * Copyright (c) Ian F. Darwin 1986-1995.
3  * Software written by Ian F. Darwin and others;
4  * maintained 1995-present by Christos Zoulas and others.
5  * 
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice immediately at the beginning of the file, without modification,
11  *    this list of conditions, and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *  
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
20  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  */
28 /*
29  * Names.h - names and types used by ascmagic in file(1).
30  * These tokens are here because they can appear anywhere in
31  * the first HOWMANY bytes, while tokens in MAGIC must
32  * appear at fixed offsets into the file. Don't make HOWMANY
33  * too high unless you have a very fast CPU.
34  *
35  * $File: names.h,v 1.32 2008/02/11 00:19:29 rrt Exp $
36  */
37
38 /*
39         modified by Chris Lowth - 9 April 2000
40         to add mime type strings to the types table.
41 */
42
43 /* these types are used to index the table 'types': keep em in sync! */
44 #define L_C     0               /* first and foremost on UNIX */
45 #define L_CC    1               /* Bjarne's postincrement */
46 #define L_MAKE  2               /* Makefiles */
47 #define L_PLI   3               /* PL/1 */
48 #define L_MACH  4               /* some kinda assembler */
49 #define L_ENG   5               /* English */
50 #define L_PAS   6               /* Pascal */
51 #define L_MAIL  7               /* Electronic mail */
52 #define L_NEWS  8               /* Usenet Netnews */
53 #define L_JAVA  9               /* Java code */
54 #define L_HTML  10              /* HTML */
55 #define L_BCPL  11              /* BCPL */
56 #define L_M4    12              /* M4 */
57 #define L_PO    13              /* PO */
58
59 static const struct {
60         char human[48];
61         char mime[16];
62 } types[] = {
63         { "C program",                                  "text/x-c", },
64         { "C++ program",                                "text/x-c++" },
65         { "make commands",                              "text/x-makefile" },
66         { "PL/1 program",                               "text/x-pl1" },
67         { "assembler program",                          "text/x-asm" },
68         { "English",                                    "text/plain" },
69         { "Pascal program",                             "text/x-pascal" },
70         { "mail",                                       "text/x-mail" },
71         { "news",                                       "text/x-news" },
72         { "Java program",                               "text/x-java" },
73         { "HTML document",                              "text/html", },
74         { "BCPL program",                               "text/x-bcpl" },
75         { "M4 macro language pre-processor",            "text/x-m4" },
76         { "PO (gettext message catalogue)",             "text/x-po" },
77         { "cannot happen error on names.h/types",       "error/x-error" }
78 };
79
80 /*
81  * XXX - how should we distinguish Java from C++?
82  * The trick used in a Debian snapshot, of having "extends" or "implements"
83  * as tags for Java, doesn't work very well, given that those keywords
84  * are often preceded by "class", which flags it as C++.
85  *
86  * Perhaps we need to be able to say
87  *
88  *      If "class" then
89  *
90  *              if "extends" or "implements" then
91  *                      Java
92  *              else
93  *                      C++
94  *      endif
95  *
96  * Or should we use other keywords, such as "package" or "import"?
97  * Unfortunately, Ada95 uses "package", and Modula-3 uses "import",
98  * although I infer from the language spec at
99  *
100  *      http://www.research.digital.com/SRC/m3defn/html/m3.html
101  *
102  * that Modula-3 uses "IMPORT" rather than "import", i.e. it must be
103  * in all caps.
104  *
105  * So, for now, we go with "import".  We must put it before the C++
106  * stuff, so that we don't misidentify Java as C++.  Not using "package"
107  * means we won't identify stuff that defines a package but imports
108  * nothing; hopefully, very little Java code imports nothing (one of the
109  * reasons for doing OO programming is to import as much as possible
110  * and write only what you need to, right?).
111  *
112  * Unfortunately, "import" may cause us to misidentify English text
113  * as Java, as it comes after "the" and "The".  Perhaps we need a fancier
114  * heuristic to identify Java?
115  */
116 static const struct names {
117         char name[14];
118         short type;
119 } names[] = {
120         /* These must be sorted by eye for optimal hit rate */
121         /* Add to this list only after substantial meditation */
122         {"msgid",       L_PO},
123         {"dnl",         L_M4},
124         {"import",      L_JAVA},
125         {"\"libhdr\"",  L_BCPL},
126         {"\"LIBHDR\"",  L_BCPL},
127         {"//",          L_CC},
128         {"template",    L_CC},
129         {"virtual",     L_CC},
130         {"class",       L_CC},
131         {"public:",     L_CC},
132         {"private:",    L_CC},
133         {"/*",          L_C},   /* must precede "The", "the", etc. */
134         {"#include",    L_C},
135         {"char",        L_C},
136         {"The",         L_ENG},
137         {"the",         L_ENG},
138         {"double",      L_C},
139         {"extern",      L_C},
140         {"float",       L_C},
141         {"struct",      L_C},
142         {"union",       L_C},
143         {"CFLAGS",      L_MAKE},
144         {"LDFLAGS",     L_MAKE},
145         {"all:",        L_MAKE},
146         {".PRECIOUS",   L_MAKE},
147         {".ascii",      L_MACH},
148         {".asciiz",     L_MACH},
149         {".byte",       L_MACH},
150         {".even",       L_MACH},
151         {".globl",      L_MACH},
152         {".text",       L_MACH},
153         {"clr",         L_MACH},
154         {"(input,",     L_PAS},
155         {"program",     L_PAS},
156         {"record",      L_PAS},
157         {"dcl",         L_PLI},
158         {"Received:",   L_MAIL},
159         {">From",       L_MAIL},
160         {"Return-Path:",L_MAIL},
161         {"Cc:",         L_MAIL},
162         {"Newsgroups:", L_NEWS},
163         {"Path:",       L_NEWS},
164         {"Organization:",L_NEWS},
165         {"href=",       L_HTML},
166         {"HREF=",       L_HTML},
167         {"<body",       L_HTML},
168         {"<BODY",       L_HTML},
169         {"<html",       L_HTML},
170         {"<HTML",       L_HTML},
171         {"<!--",        L_HTML},
172 };
173 #define NNAMES (sizeof(names)/sizeof(struct names))