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
# 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}
--- /dev/null
+# 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();
+}
# 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 "";
- }
}