names.h revision 175297
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.29 2007/12/27 20:30:35 christos 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
59static const struct {
60	const char *human;
61	const char *mime;
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	{ 0, 0}
79};
80
81/*
82 * XXX - how should we distinguish Java from C++?
83 * The trick used in a Debian snapshot, of having "extends" or "implements"
84 * as tags for Java, doesn't work very well, given that those keywords
85 * are often preceded by "class", which flags it as C++.
86 *
87 * Perhaps we need to be able to say
88 *
89 *	If "class" then
90 *
91 *		if "extends" or "implements" then
92 *			Java
93 *		else
94 *			C++
95 *	endif
96 *
97 * Or should we use other keywords, such as "package" or "import"?
98 * Unfortunately, Ada95 uses "package", and Modula-3 uses "import",
99 * although I infer from the language spec at
100 *
101 *	http://www.research.digital.com/SRC/m3defn/html/m3.html
102 *
103 * that Modula-3 uses "IMPORT" rather than "import", i.e. it must be
104 * in all caps.
105 *
106 * So, for now, we go with "import".  We must put it before the C++
107 * stuff, so that we don't misidentify Java as C++.  Not using "package"
108 * means we won't identify stuff that defines a package but imports
109 * nothing; hopefully, very little Java code imports nothing (one of the
110 * reasons for doing OO programming is to import as much as possible
111 * and write only what you need to, right?).
112 *
113 * Unfortunately, "import" may cause us to misidentify English text
114 * as Java, as it comes after "the" and "The".  Perhaps we need a fancier
115 * heuristic to identify Java?
116 */
117static struct names {
118	const char *name;
119	short type;
120} names[] = {
121	/* These must be sorted by eye for optimal hit rate */
122	/* Add to this list only after substantial meditation */
123	{"msgid",	L_PO},
124	{"dnl",		L_M4},
125	{"import",	L_JAVA},
126	{"\"libhdr\"",	L_BCPL},
127	{"\"LIBHDR\"",	L_BCPL},
128	{"//",		L_CC},
129	{"template",	L_CC},
130	{"virtual",	L_CC},
131	{"class",	L_CC},
132	{"public:",	L_CC},
133	{"private:",	L_CC},
134	{"/*",		L_C},	/* must precede "The", "the", etc. */
135	{"#include",	L_C},
136	{"char",	L_C},
137	{"The",		L_ENG},
138	{"the",		L_ENG},
139	{"double",	L_C},
140	{"extern",	L_C},
141	{"float",	L_C},
142	{"struct",	L_C},
143	{"union",	L_C},
144	{"CFLAGS",	L_MAKE},
145	{"LDFLAGS",	L_MAKE},
146	{"all:",	L_MAKE},
147	{".PRECIOUS",	L_MAKE},
148/* Too many files of text have these words in them.  Find another way
149 * to recognize Fortrash.
150 */
151#ifdef	NOTDEF
152	{"subroutine",	L_FORT},
153	{"function",	L_FORT},
154	{"block",	L_FORT},
155	{"common",	L_FORT},
156	{"dimension",	L_FORT},
157	{"integer",	L_FORT},
158	{"data",	L_FORT},
159#endif	/*NOTDEF*/
160	{".ascii",	L_MACH},
161	{".asciiz",	L_MACH},
162	{".byte",	L_MACH},
163	{".even",	L_MACH},
164	{".globl",	L_MACH},
165	{".text",	L_MACH},
166	{"clr",		L_MACH},
167	{"(input,",	L_PAS},
168	{"program",	L_PAS},
169	{"record",	L_PAS},
170	{"dcl",		L_PLI},
171	{"Received:",	L_MAIL},
172	{">From",	L_MAIL},
173	{"Return-Path:",L_MAIL},
174	{"Cc:",		L_MAIL},
175	{"Newsgroups:",	L_NEWS},
176	{"Path:",	L_NEWS},
177	{"Organization:",L_NEWS},
178	{"href=",	L_HTML},
179	{"HREF=",	L_HTML},
180	{"<body",	L_HTML},
181	{"<BODY",	L_HTML},
182	{"<html",	L_HTML},
183	{"<HTML",	L_HTML},
184	{NULL,		0}
185};
186#define NNAMES ((sizeof(names)/sizeof(struct names)) - 1)
187