File indexing completed on 2024-04-21 05:41:58

0001 #/usr/bin/env perl
0002 # Author: Thiago Macieira <thiago@kde.org>
0003 #  This program is released into the public domain by the author.
0004 #
0005 # Feed this program a list of strings, one per line, and it'll generate
0006 # a C index list. All non-relocated data.
0007 
0008 $varname = "data";
0009 $varname = $ARGV[0] if $ARGV[0];
0010 
0011 print "static const char ${varname}_string[] =\n";
0012 $counter = 0;
0013 $i = 0;
0014 %hash = { };
0015 while (<STDIN>) {
0016     chomp;
0017     if (defined($hash{$_})) {
0018     # Entry already seen, output one of the old addresses
0019     print STDERR "Already seen " . $_ . "  " . $hash{$_} . "\n";
0020     $sizes[$i++] = $hash{$_};
0021     next;
0022     }
0023 
0024     m/^(i18n:)?(.*)$/i;
0025     print "    \"$2\\0\"\n" if (!$1);
0026     print "    I18N_NOOP(\"$2\")\"\\0\"\n" if ($1);
0027     $hash{$_} = $counter;
0028     $hash{""} = $counter + length $2 if ($i == 0); # make the empty string point to the first \0
0029     $sizes[$i++] = $counter;
0030 
0031     $counter += 1 + length $2;
0032 }
0033 
0034 print "    \"\\0\";\n\nstatic const int ${varname}_indices[] = {";
0035 for ($j = 0; $j < $i; ++$j) {
0036     if (($j % 8) == 0) {
0037     print "\n   ";
0038     }
0039 
0040     printf " %4d,", $sizes[$j];
0041 }
0042 if (($j % 8) == 0) {
0043     print "\n   ";
0044 }
0045 print "   -1\n};\n";