names.h 6.1 KB

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