2 # This Source Code Form is subject to the terms of the Mozilla Public
3 # License, v. 2.0. If a copy of the MPL was not distributed with this
4 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 # Converts a list of atoms in the form:
8 # // OUTPUT_CLASS=<classname>
9 # // MACRO_NAME=<macro>
10 # <macroname>(atomName, "String")
11 # <macroname>(atomName2, "String2")
13 # into a file suitable for gperf using static atoms
16 # make-atom-strings < file.h > file.gperf
18 # the lines in the C++ comments define two variables:
19 # OUTPUT_CLASS is the class who has all the atoms as members
20 # MACRO_NAME is the macro to look for in the rest of the file
23 # // OUTPUT_CLASS=nsHTMLAtoms
24 # // MACRO_NAME=HTML_ATOM
26 # HTML_ATOM(body, "body")
30 # this will generate a file that looks like:
31 # struct nsStaticAtom ( const char* mValue; nsIAtom** aAtom; }
33 # "a", &nsHTMLAtoms::a
34 # "body", &nsHTMLAtoms::body
38 # the output can be plugged into gperf to generate a perfect hash
40 print "struct nsStaticAtom {const char* mValue; nsIAtom** aAtom; };\n";
43 my $classname, $macroname;
47 if (/OUTPUT_CLASS=(\S+)/) {
49 } elsif (/MACRO_NAME=(\S+)/) {
52 elsif ($classname && $macroname &&
53 /$macroname\((\S+),\s*\"(.*?)\"\s*\)/) {
54 my ($str, $atom) = ($2, $1);
55 print "\"$str\", (nsIAtom**)&${classname}::$atom\n";