1 # Convert string resources from Windows native resource file to a C++
2 # source file with an array of structs representing the resources.
8 # Takes a number and returns a string corresponding to its hex
9 # representation. A string representation that has fewer than 8
10 # characters (not including the '0x' prefix) is padded with 0's
11 # to make it 8 characters.
12 # Example: an input of 49 yields "0x00000031".
13 function numberToHexString(number)
18 for (digitCount = 0; digitCount < 8; digitCount++)
20 remainder = quotient % 16;
21 quotient = int(quotient / 16);
22 hexString = sprintf("%x"hexString, remainder);
25 hexString = "0x" hexString;
29 # Add each entry that is in our associative array of entries to the
30 # C++ array we are building. The C++ array will be ordered by the
31 # resourceId (lowest to highest) to facilitate quick lookups.
32 function writesortedentries()
34 for (entry in resourceArray)
36 # Write the entries to the C++ array ordered by the ID.
37 printf " {%s,%s},\n", entry, resourceArray[entry] | "sort";
40 # Close the pipe to ensure that the data is written now.
44 # Write entry for a string resource
45 # This is called for each entry. Because we want to write them in
46 # sorted order once all the entries have come in, for now we just
47 # store each entry in an associative array.
48 function writestringentry(id, str)
52 # Use the string representation of the ID as the array index
53 # because the precision of numeric indices can be lost during
54 # the number -> string -> number conversions that would occur
55 # if numeric indices are used.
56 resourceArray[numberToHexString(id)] = str;
59 # Write file header and begin the array we will populate with the resources.
60 function writeheader(arrayName, tableName)
62 print "// This code was generated by rctocpp.awk and is not meant to be modified manually."
63 print "#include <resourcestring.h>";
65 print "extern const NativeStringResourceTable " tableName ";";
66 print "const NativeStringResource " arrayName "[] = {";
70 # This function is called after all of the entries have been given to
71 # writestringentry. Because we know there are no more entries, we can
72 # now write all the entries we received so far when this is called.
73 # After we have written all the entries, we close the array and add a
74 # constant for the size of the array for convenience.
75 function writefooter(arrayName, tableName)
81 print "const NativeStringResourceTable " tableName " = {";