Bug 524462. Fix startup crash in pref fonts with funky cmaps. r=jdaggett
[mozilla-central.git] / config / make-atom-strings.pl
blob174d004091284851cfa2e25230007d7c54dbff0b
1 #! perl
3 # Converts a list of atoms in the form:
4 # // OUTPUT_CLASS=<classname>
5 # // MACRO_NAME=<macro>
6 # <macroname>(atomName, "String")
7 # <macroname>(atomName2, "String2")
9 # into a file suitable for gperf using static atoms
11 # usage:
12 # make-atom-strings < file.h > file.gperf
14 # the lines in the C++ comments define two variables:
15 # OUTPUT_CLASS is the class who has all the atoms as members
16 # MACRO_NAME is the macro to look for in the rest of the file
18 # for example
19 # // OUTPUT_CLASS=nsHTMLAtoms
20 # // MACRO_NAME=HTML_ATOM
21 # HTML_ATOM(a, "a")
22 # HTML_ATOM(body, "body")
24 # etc...
26 # this will generate a file that looks like:
27 # struct nsStaticAtom ( const char* mValue; nsIAtom** aAtom; }
28 # %%
29 # "a", &nsHTMLAtoms::a
30 # "body", &nsHTMLAtoms::body
32 # etc...
34 # the output can be plugged into gperf to generate a perfect hash
36 print "struct nsStaticAtom {const char* mValue; nsIAtom** aAtom; };\n";
37 print "%%\n";
39 my $classname, $macroname;
41 while (<>) {
42 chop;
43 if (/OUTPUT_CLASS=(\S+)/) {
44 $classname=$1;
45 } elsif (/MACRO_NAME=(\S+)/) {
46 $macroname=$1;
48 elsif ($classname && $macroname &&
49 /$macroname\((\S+),\s*\"(.*?)\"\s*\)/) {
50 my ($str, $atom) = ($2, $1);
51 print "\"$str\", (nsIAtom**)&${classname}::$atom\n";