Back to index

lightning-sunbird  0.9+nobinonly
genhash.inc
Go to the documentation of this file.
00001 @!
00002 @! ***** BEGIN LICENSE BLOCK *****
00003 @! Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004 @!
00005 @! The contents of this file are subject to the Mozilla Public License Version
00006 @! 1.1 (the "License"); you may not use this file except in compliance with
00007 @! the License. You may obtain a copy of the License at
00008 @! http://www.mozilla.org/MPL/
00009 @!
00010 @! Software distributed under the License is distributed on an "AS IS" basis,
00011 @! WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012 @! for the specific language governing rights and limitations under the
00013 @! License.
00014 @!
00015 @! The Original Code is mozilla.org code.
00016 @!
00017 @! The Initial Developer of the Original Code is
00018 @! Netscape Communications Corporation.
00019 @! Portions created by the Initial Developer are Copyright (C) 1998
00020 @! the Initial Developer. All Rights Reserved.
00021 @!
00022 @! Contributor(s):
00023 @!
00024 @! Alternatively, the contents of this file may be used under the terms of
00025 @! either of the GNU General Public License Version 2 or later (the "GPL"),
00026 @! or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027 @! in which case the provisions of the GPL or the LGPL are applicable instead
00028 @! of those above. If you wish to allow use of your version of this file only
00029 @! under the terms of either the GPL or the LGPL, and not to allow others to
00030 @! use your version of this file under the terms of the MPL, indicate your
00031 @! decision by deleting the provisions above and replace them with the notice
00032 @! and other provisions required by the GPL or the LGPL. If you do not delete
00033 @! the provisions above, a recipient may use your version of this file under
00034 @! the terms of any one of the MPL, the GPL or the LGPL.
00035 @!
00036 @! ***** END LICENSE BLOCK *****
00037 
00038 @! This file is used to generate static hash table lookups.
00039 @! A perl script merges this file  with the output of gperf to produce
00040 @! the hash functions.  Lines starting with @! are comments.  Lines which do
00041 @! not being with @! are copied straight to the output file. "@begin NAME
00042 @! /REGEX1/ /REGEX2/" means to  skip lines in the input until REGEX1 is
00043 @! matched, and then begin  saving output under name NAME, and stop when
00044 @! REGEX2 is matched. "@include NAME" inserts the data saved as "NAME".
00045 @! "@SUB NAME SUBREGEX" performs a substitution on the data saved in NAME.
00046 @!
00047 @! The following goop extracts the parts we need from the generated output
00048 @! of gperf.  We later merge that goop with custom code to generate
00049 @! the tag lookup function.
00050 @!
00051 @begin MACROS /#define/ /^$/
00052 @begin HASH_TABLE /static unsigned [a-z]+ (asso_values|hash_table)/ /};/
00053 @begin HASH_FUNC /register int hval = len;/ /return hval/
00054 @sub HASH_FUNC /return hval \+/hval +=/
00055 @sub HASH_FUNC /str\[/MYLOWER(str[/
00056 @sub HASH_FUNC /]]/])]/
00057 @begin LENGTH_TABLE /static unsigned char lengthtable/ /};/
00058 @begin TAG_TABLE /static struct StaticNameTable *wordlist/ /};/
00059 @!
00060 /*
00061 ** This is a generated file, do not edit it. This file is created by
00062 ** genhash.pl
00063 */
00064 
00065 #include "plstr.h"
00066 @classincl
00067 @include MACROS
00068 
00069 struct StaticNameTable {
00070   char* tag;
00071   PRInt32 id;
00072 };
00073 
00074 static const unsigned char kLowerLookup[256] = {
00075   0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
00076   16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,
00077   32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,
00078   48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,
00079   64,
00080     97,98,99,100,101,102,103,104,105,106,107,108,109,
00081     110,111,112,113,114,115,116,117,118,119,120,121,122,
00082 
00083    91, 92, 93, 94, 95, 96, 97, 98, 99,100,101,102,103,104,105,106,107,108,109,110,111,
00084   112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,
00085 
00086   128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,
00087   144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,
00088   160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,
00089   176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,
00090   192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,
00091   208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,
00092   224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,
00093   240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255
00094 };
00095 
00096 #define MYLOWER(x) kLowerLookup[((x) & 0x7f)]
00097 
00101 @classfunc
00102 {
00103 @include HASH_TABLE
00104 @include LENGTH_TABLE
00105 @include TAG_TABLE
00106 
00107   if (str != NULL) {
00108     int len = PL_strlen(str);
00109     if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) {
00110 @include HASH_FUNC
00111 @! "hval" now contains hash value
00112       if (hval <= MAX_HASH_VALUE && hval >= MIN_HASH_VALUE) {
00113         if (len == lengthtable[hval]) {
00114           register const char *tag = wordlist[hval].tag;
00115 
00116           /*
00117           ** While not at the end of the string, if they ever differ
00118           ** they are not equal.  We know "tag" is already lower case.
00119           */
00120           while ((*tag != '\0')&&(*str != '\0')) {
00121             if (*tag != (char) MYLOWER(*str)) {
00122               return -1;
00123             }
00124             tag++;
00125             str++;
00126           }
00127 
00128           /*
00129           ** One of the strings has ended, if they are both ended, then they
00130           ** are equal, otherwise not.
00131           */
00132           if ((*tag == '\0')&&(*str == '\0')) {
00133             return wordlist[hval].id;
00134           }
00135         }
00136       }
00137     }
00138   }
00139   return -1;
00140 }