1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/config/make-atom-strings.pl Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,57 @@ 1.4 +#! perl 1.5 +# This Source Code Form is subject to the terms of the Mozilla Public 1.6 +# License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 +# file, You can obtain one at http://mozilla.org/MPL/2.0/. 1.8 + 1.9 + 1.10 +# Converts a list of atoms in the form: 1.11 +# // OUTPUT_CLASS=<classname> 1.12 +# // MACRO_NAME=<macro> 1.13 +# <macroname>(atomName, "String") 1.14 +# <macroname>(atomName2, "String2") 1.15 +# 1.16 +# into a file suitable for gperf using static atoms 1.17 +# 1.18 +# usage: 1.19 +# make-atom-strings < file.h > file.gperf 1.20 +# 1.21 +# the lines in the C++ comments define two variables: 1.22 +# OUTPUT_CLASS is the class who has all the atoms as members 1.23 +# MACRO_NAME is the macro to look for in the rest of the file 1.24 +# 1.25 +# for example 1.26 +# // OUTPUT_CLASS=nsHTMLAtoms 1.27 +# // MACRO_NAME=HTML_ATOM 1.28 +# HTML_ATOM(a, "a") 1.29 +# HTML_ATOM(body, "body") 1.30 +# 1.31 +# etc... 1.32 +# 1.33 +# this will generate a file that looks like: 1.34 +# struct nsStaticAtom ( const char* mValue; nsIAtom** aAtom; } 1.35 +# %% 1.36 +# "a", &nsHTMLAtoms::a 1.37 +# "body", &nsHTMLAtoms::body 1.38 +# 1.39 +# etc... 1.40 +# 1.41 +# the output can be plugged into gperf to generate a perfect hash 1.42 + 1.43 +print "struct nsStaticAtom {const char* mValue; nsIAtom** aAtom; };\n"; 1.44 +print "%%\n"; 1.45 + 1.46 +my $classname, $macroname; 1.47 + 1.48 +while (<>) { 1.49 + chop; 1.50 + if (/OUTPUT_CLASS=(\S+)/) { 1.51 + $classname=$1; 1.52 + } elsif (/MACRO_NAME=(\S+)/) { 1.53 + $macroname=$1; 1.54 + } 1.55 + elsif ($classname && $macroname && 1.56 + /$macroname\((\S+),\s*\"(.*?)\"\s*\)/) { 1.57 + my ($str, $atom) = ($2, $1); 1.58 + print "\"$str\", (nsIAtom**)&${classname}::$atom\n"; 1.59 + } 1.60 +}