Refactor the windows text resources processing
authorJan Vorlicek <janvorli@microsoft.com>
Fri, 10 Apr 2015 15:52:13 +0000 (17:52 +0200)
committerJan Vorlicek <janvorli@microsoft.com>
Fri, 10 Apr 2015 21:46:49 +0000 (23:46 +0200)
This change refactors the windows text resource processing into
a parsing script and a script with platform specific function
responsible for writing to the output file.

src/dlls/mscorrc/CMakeLists.txt
src/dlls/mscorrc/processrc.awk [new file with mode: 0644]
src/dlls/mscorrc/rctopo.awk

index 48429f5..c0f45f8 100644 (file)
@@ -4,6 +4,7 @@ if(WIN32)
 else()
 
     set (RC_TO_PO ${CMAKE_CURRENT_SOURCE_DIR}/rctopo.awk)
+    set (PROCESS_RC ${CMAKE_CURRENT_SOURCE_DIR}/processrc.awk)
     
     # Create a command to build gettext resources binary file from windows .rc file
     # The target binary file path is returned in the variable specified by
@@ -33,7 +34,7 @@ else()
             # Preprocess the windows .rc file
             COMMAND ${CMAKE_CXX_COMPILER} -E -P ${PREPROCESS_DEFINITIONS} ${INCLUDE_DIRECTORIES} -o ${PREPROCESSED_SOURCE} -x c ${SOURCE}
             # Convert the preprocessed .rc file to the .po file which is a source for the gettext toolchain
-            COMMAND ${AWK} -f ${RC_TO_PO} ${PREPROCESSED_SOURCE} >${GETTEXT_SOURCE}
+            COMMAND ${AWK} -f ${RC_TO_PO} -f ${PROCESS_RC} ${PREPROCESSED_SOURCE} >${GETTEXT_SOURCE}
             # Compile the .po file into the target binary .mo file
             COMMAND ${MSGFMT} ${GETTEXT_SOURCE} -o ${GETTEXT_TARGET}
             DEPENDS ${SOURCE}
diff --git a/src/dlls/mscorrc/processrc.awk b/src/dlls/mscorrc/processrc.awk
new file mode 100644 (file)
index 0000000..221212f
--- /dev/null
@@ -0,0 +1,69 @@
+# Parse string resources from Windows native resource file 
+# and pass them to the writestringentry function that 
+# is responsible for writing the resource id and string
+# to a platform specific resource file.
+# A script containing this function needs to be specified
+# using the -f command line parameter before this script.
+
+BEGIN {
+    inStringTable = 0;
+    inBeginEnd = 0;
+    writeheader();
+}
+{
+    if ($1 == "STRINGTABLE" && $2 == "DISCARDABLE")
+    {
+        inStringTable = 1;
+    }
+    else if ($1 == "BEGIN")
+    {
+        inBeginEnd = inStringTable;
+    }
+    else if (inBeginEnd && $1 == "END")
+    {
+        inBeginEnd = 0;
+        inStringTable = 0;
+    }
+    else if (inBeginEnd && $1 != "")
+    {
+        # combine all items until the first string and remove them 
+        # from the line
+        i = 1
+        expression = ""
+        # string starts with either a quote or L followed by a quote
+        while (substr($i, 1, 1) != "\"" && substr($i, 1, 2) != "L\"")
+        {
+            # some of the resource ids contain cast to HRESULT
+            gsub(/\(HRESULT\)/, "", $i);
+            # some of the resource ids have trailing L
+            gsub(/L/, "", $i);
+            expression = expression $i;
+            $i="";
+            i++;
+        }
+        # evaluate the resource id expression and format it as hex number
+        cmd = "echo $(("expression"))";
+        cmd | getline var;
+        close(cmd);
+        # sprintf can only handle signed ints, so we need to convert
+        # values >= 0x80000000 to negative values
+        if (var >= 2147483648)
+        {
+            var = var - 4294967296;
+        }
+        var = sprintf("%X", var);
+        # remove the L prefix from strings
+        gsub(/L"/, "\"", $0);
+        # join strings "..." "..." into one
+        gsub(/" +"/, "", $0);
+        # remove all terminating newlines from the string - the msgfmt fails on those
+        # since it expects them to be at the end of the msgid as well
+        while(gsub(/\\n"/, "\"", $0)) {}
+
+        # write the resource entry to the target file
+        writestringentry(var, $0);
+    }
+}
+END {
+    writefooter();
+}
index 658e5c7..32aa9ca 100644 (file)
@@ -1,60 +1,20 @@
 # Convert string resources from Windows native resource file to the 
 # input format of the gettext toolchain.
-BEGIN {
-    inStringTable = 0;
-    inBeginEnd = 0;
+
+# Write entry for a string resource
+function writestringentry(id, str)
+{
+    print "msgid \""id"\"";
+    print "msgstr" str;
+    print "";
+}
+
+# Write file header
+function writeheader()
+{
 }
+
+# Write file footer
+function writefooter()
 {
-    if ($1 == "STRINGTABLE" && $2 == "DISCARDABLE")
-    {
-        inStringTable = 1;
-    }
-    else if ($1 == "BEGIN")
-    {
-        inBeginEnd = inStringTable;
-    }
-    else if (inBeginEnd && $1 == "END")
-    {
-        inBeginEnd = 0;
-        inStringTable = 0;
-    }
-    else if (inBeginEnd && $1 != "")
-    {
-        # combine all items until the first string and remove them 
-        # from the line
-        i = 1
-        expression = ""
-        # string starts with either a quote or L followed by a quote
-        while (substr($i, 1, 1) != "\"" && substr($i, 1, 2) != "L\"")
-        {
-            # some of the resource ids contain cast to HRESULT
-            gsub(/\(HRESULT\)/, "", $i);
-            # some of the resource ids have trailing L
-            gsub(/L/, "", $i);
-            expression = expression $i;
-            $i="";
-            i++;
-        }
-        # evaluate the resource id expression and format it as hex number
-        cmd = "echo $(("expression"))";
-        cmd | getline var;
-        close(cmd);
-        # sprintf can only handle signed ints, so we need to convert
-        # values >= 0x80000000 to negative values
-        if (var >= 2147483648)
-        {
-            var = var - 4294967296;
-        }
-        var = sprintf("%X", var);
-        print "msgid \""var"\"";
-        # remove the L prefix from strings
-        gsub(/L"/, "\"", $0);
-        # join strings "..." "..." into one
-        gsub(/" +"/, "", $0);
-        # remove all terminating newlines from the string - the msgfmt fails on those
-        # since it expects them to be at the end of the msgid as well
-        while(gsub(/\\n"/, "\"", $0)) {}
-        print "msgstr" $0;
-        print "";
-    }
 }