From: Jan Vorlicek Date: Fri, 10 Apr 2015 15:52:13 +0000 (+0200) Subject: Refactor the windows text resources processing X-Git-Tag: accepted/tizen/base/20180629.140029~6856^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4b960e2d1dae7f42400c76c72c254dc84652e349;p=platform%2Fupstream%2Fcoreclr.git Refactor the windows text resources processing 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. --- diff --git a/src/dlls/mscorrc/CMakeLists.txt b/src/dlls/mscorrc/CMakeLists.txt index 48429f5..c0f45f8 100644 --- a/src/dlls/mscorrc/CMakeLists.txt +++ b/src/dlls/mscorrc/CMakeLists.txt @@ -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 index 0000000..221212f --- /dev/null +++ b/src/dlls/mscorrc/processrc.awk @@ -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(); +} diff --git a/src/dlls/mscorrc/rctopo.awk b/src/dlls/mscorrc/rctopo.awk index 658e5c7..32aa9ca 100644 --- a/src/dlls/mscorrc/rctopo.awk +++ b/src/dlls/mscorrc/rctopo.awk @@ -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 ""; - } }