names.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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.33 2010/10/08 21:58:44 christos Exp $
  36. */
  37. /*
  38. modified by Chris Lowth - 9 April 2000
  39. to add mime type strings to the types table.
  40. */
  41. /* these types are used to index the table 'types': keep em in sync! */
  42. #define L_C 0 /* first and foremost on UNIX */
  43. #define L_CC 1 /* Bjarne's postincrement */
  44. #define L_MAKE 2 /* Makefiles */
  45. #define L_PLI 3 /* PL/1 */
  46. #define L_MACH 4 /* some kinda assembler */
  47. #define L_ENG 5 /* English */
  48. #define L_PAS 6 /* Pascal */
  49. #define L_MAIL 7 /* Electronic mail */
  50. #define L_NEWS 8 /* Usenet Netnews */
  51. #define L_JAVA 9 /* Java code */
  52. #define L_HTML 10 /* HTML */
  53. #define L_BCPL 11 /* BCPL */
  54. #define L_M4 12 /* M4 */
  55. #define L_PO 13 /* PO */
  56. static const struct {
  57. char human[48];
  58. char mime[16];
  59. } types[] = {
  60. { "C program", "text/x-c", },
  61. { "C++ program", "text/x-c++" },
  62. { "make commands", "text/x-makefile" },
  63. { "PL/1 program", "text/x-pl1" },
  64. { "assembler program", "text/x-asm" },
  65. { "English", "text/plain" },
  66. { "Pascal program", "text/x-pascal" },
  67. { "mail", "text/x-mail" },
  68. { "news", "text/x-news" },
  69. { "Java program", "text/x-java" },
  70. { "HTML document", "text/html", },
  71. { "BCPL program", "text/x-bcpl" },
  72. { "M4 macro language pre-processor", "text/x-m4" },
  73. { "PO (gettext message catalogue)", "text/x-po" },
  74. { "cannot happen error on names.h/types", "error/x-error" }
  75. };
  76. /*
  77. * XXX - how should we distinguish Java from C++?
  78. * The trick used in a Debian snapshot, of having "extends" or "implements"
  79. * as tags for Java, doesn't work very well, given that those keywords
  80. * are often preceded by "class", which flags it as C++.
  81. *
  82. * Perhaps we need to be able to say
  83. *
  84. * If "class" then
  85. *
  86. * if "extends" or "implements" then
  87. * Java
  88. * else
  89. * C++
  90. * endif
  91. *
  92. * Or should we use other keywords, such as "package" or "import"?
  93. * Unfortunately, Ada95 uses "package", and Modula-3 uses "import",
  94. * although I infer from the language spec at
  95. *
  96. * http://www.research.digital.com/SRC/m3defn/html/m3.html
  97. *
  98. * that Modula-3 uses "IMPORT" rather than "import", i.e. it must be
  99. * in all caps.
  100. *
  101. * So, for now, we go with "import". We must put it before the C++
  102. * stuff, so that we don't misidentify Java as C++. Not using "package"
  103. * means we won't identify stuff that defines a package but imports
  104. * nothing; hopefully, very little Java code imports nothing (one of the
  105. * reasons for doing OO programming is to import as much as possible
  106. * and write only what you need to, right?).
  107. *
  108. * Unfortunately, "import" may cause us to misidentify English text
  109. * as Java, as it comes after "the" and "The". Perhaps we need a fancier
  110. * heuristic to identify Java?
  111. */
  112. static const struct names {
  113. char name[14];
  114. unsigned char type;
  115. unsigned char score;
  116. } names[] = {
  117. /* These must be sorted by eye for optimal hit rate */
  118. /* Add to this list only after substantial meditation */
  119. {"msgid", L_PO, 1 },
  120. {"dnl", L_M4, 2 },
  121. {"import", L_JAVA, 2 },
  122. {"\"libhdr\"", L_BCPL, 2 },
  123. {"\"LIBHDR\"", L_BCPL, 2 },
  124. {"//", L_CC, 2 },
  125. {"template", L_CC, 1 },
  126. {"virtual", L_CC, 1 },
  127. {"class", L_CC, 2 },
  128. {"public:", L_CC, 2 },
  129. {"private:", L_CC, 2 },
  130. {"/*", L_C, 2 }, /* must precede "The", "the", etc. */
  131. {"#include", L_C, 2 },
  132. {"char", L_C, 2 },
  133. {"The", L_ENG, 2 },
  134. {"the", L_ENG, 2 },
  135. {"double", L_C, 1 },
  136. {"extern", L_C, 2 },
  137. {"float", L_C, 1 },
  138. {"struct", L_C, 1 },
  139. {"union", L_C, 1 },
  140. {"main(", L_C, 2 },
  141. {"CFLAGS", L_MAKE, 2 },
  142. {"LDFLAGS", L_MAKE, 2 },
  143. {"all:", L_MAKE, 2 },
  144. {".PRECIOUS", L_MAKE, 2 },
  145. {".ascii", L_MACH, 2 },
  146. {".asciiz", L_MACH, 2 },
  147. {".byte", L_MACH, 2 },
  148. {".even", L_MACH, 2 },
  149. {".globl", L_MACH, 2 },
  150. {".text", L_MACH, 2 },
  151. {"clr", L_MACH, 2 },
  152. {"(input,", L_PAS, 2 },
  153. {"program", L_PAS, 1 },
  154. {"record", L_PAS, 1 },
  155. {"dcl", L_PLI, 2 },
  156. {"Received:", L_MAIL, 2 },
  157. {">From", L_MAIL, 2 },
  158. {"Return-Path:",L_MAIL, 2 },
  159. {"Cc:", L_MAIL, 2 },
  160. {"Newsgroups:", L_NEWS, 2 },
  161. {"Path:", L_NEWS, 2 },
  162. {"Organization:",L_NEWS, 2 },
  163. {"href=", L_HTML, 2 },
  164. {"HREF=", L_HTML, 2 },
  165. {"<body", L_HTML, 2 },
  166. {"<BODY", L_HTML, 2 },
  167. {"<html", L_HTML, 2 },
  168. {"<HTML", L_HTML, 2 },
  169. {"<!--", L_HTML, 2 },
  170. };
  171. #define NNAMES (sizeof(names)/sizeof(struct names))