| 1 | @echo off |
|---|
| 2 | Title GetFromSource v0.5 |
|---|
| 3 | rem FileMask: *.h;*.c;*.cpp;*.rc |
|---|
| 4 | rem RegExp: |
|---|
| 5 | rem \b(LPGENT?|TranslateT?|_T)\("text_here"\) |
|---|
| 6 | rem \b(CONTROL|(DEF)?PUSHBUTTON|GROUPBOX|CAPTION|MENUITEM|POPUP|[LRC]TEXT)\b.*"text_here" |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | rem get translatable strings from source files. |
|---|
| 10 | rem WARNING! Due to restrictions of cmd parser, strings with "!" sign cames out with "#1#", replace after parsing complete. |
|---|
| 11 | rem ATTENTION! If you get "hang" more than 5 seconds, press Ctrl+C but don't brake operations! |
|---|
| 12 | rem (i.e. press "N" for next question) |
|---|
| 13 | rem this "hang" coused by findstr with asteriks inside. |
|---|
| 14 | |
|---|
| 15 | set /p source="directory:" |
|---|
| 16 | for /f "tokens=*" %%a in ("%source%") do set file=%%~na |
|---|
| 17 | set target=%cd%\%file%.tmp |
|---|
| 18 | set output=%cd%\%file%.txt |
|---|
| 19 | set tempfile=%cd%\%file%.temp |
|---|
| 20 | |
|---|
| 21 | rem delete old file. |
|---|
| 22 | del /f /q %output% 2>nul |
|---|
| 23 | |
|---|
| 24 | rem collect all strings with translations to one file - %tempfile% |
|---|
| 25 | for /r %source% %%a in (*.h,*.c,*.cpp) do ( |
|---|
| 26 | echo %%a |
|---|
| 27 | rem remove "!" sign, it broke parse logic. Totaly 5 "!" will be removed. Hope it's enough |
|---|
| 28 | rem trail "!" does not make any sense |
|---|
| 29 | rem added "eol=/" to remove commeted strings from parsing. |
|---|
| 30 | for /f "tokens=1-5 delims=! eol=/" %%b in ('"findstr /c:"LPGEN(" /c:"LPGENT(" /c:"TranslateT(" /c:"Translate(" /c:"_T(" "%%a""') do ( |
|---|
| 31 | echo %%b#1#%%c#1#%%d#1#%%e#1#%%f>>%tempfile% |
|---|
| 32 | ) |
|---|
| 33 | ) |
|---|
| 34 | echo Start parsing %tempfile% |
|---|
| 35 | setlocal enabledelayedexpansion |
|---|
| 36 | for /f "tokens=*" %%b in (%tempfile%) do ( |
|---|
| 37 | set "str=%%b" |
|---|
| 38 | rem change \' to ' |
|---|
| 39 | set str=!str:^\'='! |
|---|
| 40 | rem now change start ( " and end of thanslation - " ) without spases. |
|---|
| 41 | set str=!str:^( "=("! |
|---|
| 42 | set str=!str:" )="^)! |
|---|
| 43 | rem remove empty translations |
|---|
| 44 | set str=!str:""=! |
|---|
| 45 | rem change all service signs to #?# |
|---|
| 46 | set str=!str:^\"=#0#! |
|---|
| 47 | set str=!str:^&=#2#! |
|---|
| 48 | set str=!str:^>=#3#! |
|---|
| 49 | set str=!str:^<=#4#! |
|---|
| 50 | set str=!str:^|=#5#! |
|---|
| 51 | set str=!str:$=#6#! |
|---|
| 52 | set str=!str:^("=($! |
|---|
| 53 | set str=!str:")=$)! |
|---|
| 54 | for %%c in ("_T(" "LPGEN(" "LPGENT(" "TranslateT(" "Translate(") do ( |
|---|
| 55 | set strT=!str! |
|---|
| 56 | echo "!str!" | find %%c |
|---|
| 57 | if !errorlevel!==0 call :parse %%c |
|---|
| 58 | ) |
|---|
| 59 | ) |
|---|
| 60 | |
|---|
| 61 | rem Sources analyzed, now analyze resources (*.rc) |
|---|
| 62 | echo Now parsing *.RC files |
|---|
| 63 | for /r %source% %%a in (*.rc) do ( |
|---|
| 64 | echo %%a |
|---|
| 65 | for /f "tokens=1-5 delims=!" %%b in ('"findstr /i /r /c:"\^<CONTROL\^>" /c:"\^<PUSHBUTTON\^>" /c:"\^<DEFPUSHBUTTON\^>" /c:"\^<GROUPBOX\^>" /c:"\^<CAPTION\^>" /c:"\^<MENUITEM\^>" /c:"\^<POPUP\^>" /c:"\^<[LRC]TEXT\^>" "%%a""') do ( |
|---|
| 66 | set "str=%%b#1#%%c#1#%%d#1#%%e#1#%%f" |
|---|
| 67 | rem change \" to @@ |
|---|
| 68 | set str=!str:^\"=@@! |
|---|
| 69 | rem change "" to @@ |
|---|
| 70 | set str=!str:""=@@! |
|---|
| 71 | rem change " to $ - our separator |
|---|
| 72 | set str=!str:"=$! |
|---|
| 73 | rem change \' to '. We don't need slash in translation |
|---|
| 74 | set str=!str:^\'='! |
|---|
| 75 | for /f "tokens=2 delims=, " %%A in ("!str!") do ( |
|---|
| 76 | if not "%%A"=="@@" ( |
|---|
| 77 | rem rollback @@ to " |
|---|
| 78 | set str=!str:@@="! |
|---|
| 79 | for /f "delims=$ tokens=2" %%e in ("!str!") do echo [%%e]>>%target% |
|---|
| 80 | ) |
|---|
| 81 | ) |
|---|
| 82 | ) |
|---|
| 83 | ) |
|---|
| 84 | |
|---|
| 85 | echo. |
|---|
| 86 | echo Strings collected. Sorting and removing dupes... |
|---|
| 87 | echo. |
|---|
| 88 | del /f /q %tempfile% 2>nul |
|---|
| 89 | findstr /l /x /v "[Tree1] [Tree2] [Spin1] [Spin5] [Custom1] [Slider2] [ ] [-] [+] [V] [x] [...] [&¤] [x] [V] [rb] [wb]" %target% >> %tempfile% |
|---|
| 90 | |
|---|
| 91 | set str= |
|---|
| 92 | for /f "tokens=*" %%y in ('sort /+1 %tempfile%') do ( |
|---|
| 93 | if not "%%y"=="!str!" ( |
|---|
| 94 | findstr /l /x /c:"%%y" %output% 2>nul |
|---|
| 95 | if not !ERRORLEVEL!==0 echo %%y>>%output% |
|---|
| 96 | ) |
|---|
| 97 | set "str=%%y" |
|---|
| 98 | ) |
|---|
| 99 | del /f /q %target% %tempfile% 2>nul |
|---|
| 100 | echo. |
|---|
| 101 | echo Done! |
|---|
| 102 | pause |
|---|
| 103 | goto :eof |
|---|
| 104 | :parse |
|---|
| 105 | set strT=!strT:^*%~1=(! |
|---|
| 106 | set strT=!strT:^("=($! |
|---|
| 107 | set strT=!strT:")=$)! |
|---|
| 108 | for /f "tokens=2 delims=$" %%d in ("!strT!") do ( |
|---|
| 109 | set out=[%%d] |
|---|
| 110 | set out=!out:#0#="! |
|---|
| 111 | rem set out=!out:#1#==^!!^! |
|---|
| 112 | set out=!out:#2#=^&! |
|---|
| 113 | set out=!out:#3#=^>! |
|---|
| 114 | set out=!out:#4#=^<! |
|---|
| 115 | set out=!out:#5#=^|! |
|---|
| 116 | set out=!out:#6#=$! |
|---|
| 117 | echo !out!>>%target% |
|---|
| 118 | set str=!str:"%%d"=! |
|---|
| 119 | set strT=!strT:$%%d$=! |
|---|
| 120 | ) |
|---|
| 121 | rem if we have anoter entry with same function, parse it again, if not, search next function |
|---|
| 122 | echo "!strT!" | find %1 |
|---|
| 123 | if !errorlevel!==0 (call :parse %1) |
|---|
| 124 | goto :eof |
|---|