Перейти из форума на сайт.

НовостиФайловые архивы
ПоискАктивные темыТоп лист
ПравилаКто в on-line?
Вход Забыли пароль? Первый раз на этом сайте? Регистрация
Компьютерный форум Ru.Board » Операционные системы » Microsoft Windows » Задачи на bat-файлах 4

Модерирует : KLASS, IFkO

evle (19-03-2008 19:44): Лимит страниц.
Задачи на bat-файлах 5
 Версия для печати • ПодписатьсяДобавить в закладки
На первую страницук этому сообщениюк последнему сообщению

   

BasiL



Silver Member
Редактировать | Профиль | Сообщение | Цитировать | Сообщить модератору
@echo off
Title GetFromSource v0.3
rem FileMask: *.h;*.c;*.cpp;*.rc
rem RegExp:
rem \b(LPGENT?|TranslateT|_T)\("text_here"\)
rem \b(CONTROL|(DEF)?PUSHBUTTON|GROUPBOX|CAPTION|MENUITEM|POPUP|[LRC]TEXT)\b.*"text_here"
 
 
rem get translatable strings from source files.
rem WARNING! Due to restrictions of cmd parser, strings with "!" sign cames out without "!"
rem ATTENTION! If you get "hang" more than 5 seconds, press Ctrl+C but don't brake operations!
rem (i.e. press "N" for next question)
rem this "hang" coused by findstr with asteriks inside.
 
set /p source="directory:"
for /f "tokens=*" %%a in ("%source%") do set file=%%~na
set target=%cd%\%file%.tmp
set output=%cd%\%file%.txt
set tempfile=%cd%\%file%.temp
 
rem delete old file.
del /f /q %output% 2>nul
 
rem collect all strings with translations to one file - %tempfile%
for /r %source% %%a in (*.h,*.c,*.cpp) do (
    echo %%a
    rem remove "!" sign, it broke parse logic. Totaly 5 "!" will be removed. Hope it's enough
    rem trail "!" does not make any sense
    for /f "eol=/ delims=! tokens=1-6" %%b in ('"findstr /c:"LPGEN(" /c:"LPGENT(" /c:"TranslateT(" /c:"_T(" "%%a""') do (
        echo %%b#1#%%c#1#%%d#1#%%e>>%tempfile%
            )
    )
 
echo Start parsing %tempfile%
setlocal enabledelayedexpansion
for /f "tokens=*" %%b in (%tempfile%) do (
        set "str=%%b"
        rem change \' to '
        set str=!str:^\'='!
        rem now change start ( " and end of thanslation - " ) without spases.
        set str=!str:^( "=("!
        set str=!str:" )="^)!
        rem remove empty translations
        set str=!str:""=!
        rem change all service signs to #?#
            set str=!str:^\"=#0#!
        set str=!str:^&=#2#!
        set str=!str:^>=#3#!
        set str=!str:^<=#4#!
        set str=!str:^|=#5#!
        for %%c in ("_T(" "LPGEN(" "LPGENT(" "TranslateT(") do (
            set strT=!str!
            echo  ESCAPES:!strT!
            echo "!str!" | find %%c
            if !errorlevel!==0 call arse %%c
            )
        )
 
rem Sources analyzed, now analyze resources (*.rc)
echo Now parsing *.RC files
for /r %source% %%a in (*.rc) do (
    echo %%a
    for /f "tokens=*" %%b in ('"findstr /i /r /c:"\^<CONTROL\^>" /c:"\^<PUSHBUTTON\^>" /c:"\^<DEFPUSHBUTTON\^>" /c:"\^<GROUPBOX\^>" /c:"\^<CAPTION\^>" /c:"\^<MENUITEM\^>" /c:"\^<POPUP\^>" /c:"\^<[LRC]TEXT\^>" "%%a""') do (
            set "str=%%b"
        rem change \" to @@
        set str=!str:^\"=@@!
        rem change "" to @@
        set str=!str:""=@@!
        rem change " to $ - our separator
        set str=!str:"=$!
        rem change \' to '. We don't need slash in translation
        set str=!str:^\'='!
        for /f "tokens=2 delims=, " %%A in ("!str!") do (
            if not "%%A"=="@@" (
                rem rollback @@ to "
                set str=!str:@@="!
                for /f "delims=$ tokens=2" %%e in ("!str!") do echo [%%e]>>%target%
                )
            )    
        )
    )
 
echo.
echo Strings collected. Sorting and removing dupes...
echo.
set str=
for /f "tokens=*" %%y in ('sort /+1 %target%') do (
    if not "%%y"=="!str!" (
        findstr /l /x /c:"%%y" %output% 2>nul
        if not !ERRORLEVEL!==0 echo %%y>>%output%
        )
    set "str=%%y"
    )
del /f /q %target% %tempfile%
echo.
echo Done!
 
arse
set strT=!strT:^*%~1=(!
set strT=!strT:^("=($!
set strT=!strT:")=$)!
echo  ToPARSE:!strT!
for /f "tokens=2 delims=$" %%d in ("!strT!") do (
    set out=[%%d]
    set out=!out:#0#="!
    set out=!out:#1#==^!!^!
    set out=!out:#2#=^&!
    set out=!out:#3#=^>!
    set out=!out:#4#=^<!
    set out=!out:#5#=^|!
    echo !out!>>%target%
    set str=!str:"%%d"=!
    set strT=!strT:$%%d$=!
    )
rem if we have anoter entry with same function, parse it again, if not, search next function
echo "!strT!" | find %1
if !errorlevel!==0 (call arse %1)

Всего записей: 3247 | Зарегистр. 13-03-2004 | Отправлено: 13:21 21-12-2007
   

На первую страницук этому сообщениюк последнему сообщению

Компьютерный форум Ru.Board » Операционные системы » Microsoft Windows » Задачи на bat-файлах 4
evle (19-03-2008 19:44): Лимит страниц.
Задачи на bat-файлах 5


Реклама на форуме Ru.Board.

Powered by Ikonboard "v2.1.7b" © 2000 Ikonboard.com
Modified by Ru.B0ard
© Ru.B0ard 2000-2024

BitCoin: 1NGG1chHtUvrtEqjeerQCKDMUi6S6CG4iC

Рейтинг.ru