Switch source build property to DotNetBuildFromSource
[platform/upstream/coreclr.git] / src / nativeresources / rctocpp.awk
1 # Convert string resources from Windows native resource file to a C++
2 # source file with an array of structs representing the resources.
3
4 BEGIN {
5     numEntries = 0;
6 }
7
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)
14 {
15     quotient = number;
16
17     hexString = "";
18     for (digitCount = 0; digitCount < 8; digitCount++)
19     {
20         remainder = quotient % 16;
21         quotient = int(quotient / 16);
22         hexString = sprintf("%x"hexString, remainder);
23     }
24
25     hexString = "0x" hexString;
26     return hexString;
27 }
28
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()
33 {
34     for (entry in resourceArray)
35     {
36         # Write the entries to the C++ array ordered by the ID.
37         printf "    {%s,%s},\n", entry, resourceArray[entry] | "sort";
38     }
39
40     # Close the pipe to ensure that the data is written now.
41     close("sort");
42 }
43
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)
49 {
50     numEntries++;
51
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;
57 }
58
59 # Write file header and begin the array we will populate with the resources.
60 function writeheader(arrayName, tableName)
61 {
62     print "// This code was generated by rctocpp.awk and is not meant to be modified manually."
63     print "#include <resourcestring.h>";
64     print "";
65     print "extern const NativeStringResourceTable " tableName ";";
66     print "const NativeStringResource " arrayName "[] = {";
67 }
68
69 # Write file footer
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)
76 {
77     writesortedentries();
78     print "};";
79     print "";
80
81     print "const NativeStringResourceTable " tableName " = {";
82     print numEntries ",";
83     print arrayName "};";
84 }