michael@0: #! perl michael@0: # This Source Code Form is subject to the terms of the Mozilla Public michael@0: # License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: # file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: michael@0: michael@0: # Converts a list of atoms in the form: michael@0: # // OUTPUT_CLASS= michael@0: # // MACRO_NAME= michael@0: # (atomName, "String") michael@0: # (atomName2, "String2") michael@0: # michael@0: # into a file suitable for gperf using static atoms michael@0: # michael@0: # usage: michael@0: # make-atom-strings < file.h > file.gperf michael@0: # michael@0: # the lines in the C++ comments define two variables: michael@0: # OUTPUT_CLASS is the class who has all the atoms as members michael@0: # MACRO_NAME is the macro to look for in the rest of the file michael@0: # michael@0: # for example michael@0: # // OUTPUT_CLASS=nsHTMLAtoms michael@0: # // MACRO_NAME=HTML_ATOM michael@0: # HTML_ATOM(a, "a") michael@0: # HTML_ATOM(body, "body") michael@0: # michael@0: # etc... michael@0: # michael@0: # this will generate a file that looks like: michael@0: # struct nsStaticAtom ( const char* mValue; nsIAtom** aAtom; } michael@0: # %% michael@0: # "a", &nsHTMLAtoms::a michael@0: # "body", &nsHTMLAtoms::body michael@0: # michael@0: # etc... michael@0: # michael@0: # the output can be plugged into gperf to generate a perfect hash michael@0: michael@0: print "struct nsStaticAtom {const char* mValue; nsIAtom** aAtom; };\n"; michael@0: print "%%\n"; michael@0: michael@0: my $classname, $macroname; michael@0: michael@0: while (<>) { michael@0: chop; michael@0: if (/OUTPUT_CLASS=(\S+)/) { michael@0: $classname=$1; michael@0: } elsif (/MACRO_NAME=(\S+)/) { michael@0: $macroname=$1; michael@0: } michael@0: elsif ($classname && $macroname && michael@0: /$macroname\((\S+),\s*\"(.*?)\"\s*\)/) { michael@0: my ($str, $atom) = ($2, $1); michael@0: print "\"$str\", (nsIAtom**)&${classname}::$atom\n"; michael@0: } michael@0: }