root/GetFromSource.cmd

Revision 1060, 3.9 KB (checked in by BasiL, 6 months ago)

* =CORE=.txt - +2 страны из ICQ
* =UNsorted=.txt - -4 строки (элементы UI)
* GetFromSource.cmd - добавил фильтр на коментарии (в которых так же встречаются переводы строк) после двух слешей \\
* ICQ.txt - +1 - строка с ошибкой из изходников.

Line 
1@echo off
2Title GetFromSource v0.5
3rem FileMask: *.h;*.c;*.cpp;*.rc
4rem RegExp:
5rem \b(LPGENT?|TranslateT?|_T)\("text_here"\)
6rem \b(CONTROL|(DEF)?PUSHBUTTON|GROUPBOX|CAPTION|MENUITEM|POPUP|[LRC]TEXT)\b.*"text_here"
7
8
9rem get translatable strings from source files.
10rem WARNING! Due to restrictions of cmd parser, strings with "!" sign cames out with "#1#", replace after parsing complete.
11rem ATTENTION! If you get "hang" more than 5 seconds, press Ctrl+C but don't brake operations!
12rem (i.e. press "N" for next question)
13rem this "hang" coused by findstr with asteriks inside.
14
15set /p source="directory:"
16for /f "tokens=*" %%a in ("%source%") do set file=%%~na
17set target=%cd%\%file%.tmp
18set output=%cd%\%file%.txt
19set tempfile=%cd%\%file%.temp
20
21rem delete old file.
22del /f /q %output% 2>nul
23
24rem collect all strings with translations to one file - %tempfile%
25for /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        )
34echo Start parsing %tempfile%
35setlocal enabledelayedexpansion
36for /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
61rem Sources analyzed, now analyze resources (*.rc)
62echo Now parsing *.RC files
63for /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
85echo.
86echo Strings collected. Sorting and removing dupes...
87echo.
88del /f /q %tempfile% 2>nul
89findstr /l /x /v "[Tree1] [Tree2] [Spin1] [Spin5] [Custom1] [Slider2] [ ] [-] [+] [V] [x] [...] [&¤] [x] [V] [rb] [wb]" %target% >> %tempfile%
90
91set str=
92for /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        )
99del /f /q %target% %tempfile% 2>nul
100echo.
101echo Done!
102pause
103goto :eof
104:parse
105set strT=!strT:^*%~1=(!
106set strT=!strT:^("=($!
107set strT=!strT:")=$)!
108for /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        )
121rem if we have anoter entry with same function, parse it again, if not, search next function
122echo "!strT!" | find %1
123if !errorlevel!==0 (call :parse %1)
124goto :eof
Note: See TracBrowser for help on using the browser.