Let's have a file with some 'graphic' (ascii art to be exact):
Code: Select all
_____
5 6 /ELEV/ 1
________________/ /_______
/ / / /
4/ 1st floor / / /
/_______________/____/ ____/
3 / / 2
56/___/
Desired output (number 6 in this example should be in color - it does not display correctly (at least for me)):
(only 6 should be matched, 56 should not be matched). It is possible to have a nonnumeric character before/after but if numeric character is before/after this should not be considered a correct match (regex should be used?).
Code: Select all
_____
5 [color=#FF0000]6[/color] /ELEV/ 1
________________/ /_______
/ / / /
4/ 1st floor / / /
/_______________/____/ ____/
3 / / 2
56/___/
Things I need (should work on XP):
- I supply a number (or string) that should be searched for and this number (string) should be displayed in color. In the example number 6. This number/string can be more than 1 character in size.
One of the ways:
- read each line from the 'graphic' file
- if it does not contain a 'match' -> display it
- if it contains a match then:
- find the offset of the character
- use Carlos' COLOR function (viewtopic.php?p=25305#p25305) to display it
- continue with the rest of the lines
Is it possible to display flashing characters? (on ZX Spectrum: FLASH 1) If so this might be even better.
Here is version 1:
Code: Select all
@echo off
rem create graphic file
>graphic.txt (echo _____)
>>graphic.txt (echo 5 6 /ELEV/ 1)
>>graphic.txt (echo ________________/ /_______)
>>graphic.txt (echo / / / /)
>>graphic.txt (echo 4/ 1st floor / / /)
>>graphic.txt (echo /_______________/____/ ____/)
>>graphic.txt (echo 3 / / 2)
>>graphic.txt (echo 56/___/)
set string_to_search=6
for /f "tokens=1 delims=" %%f in (graphic.txt) do call :dosomework "%%f"
goto :EOF
:dosomework
set par1=%~1
set /a fillen=-1
set /a cnt=0
:goback
call set current_character=%%par1:~%cnt%,1%%
if "%current_character%"=="" set fillen=%cnt%&goto :work1
REM echo CURR_CHR=_%current_character%_
REM Here should make a test for a character before a match to not be a number
if "%current_character%"=="%string_to_search%" goto :work1
set /a cnt+=1
goto :goback
:work1
set /a cnt1=cnt - 0
REM 1 below assumes one character width - needs correction to support string of
REM different lengths.
set /a cnt2=cnt + 1
if "%fillen%"=="%cnt%" echo(%par1%&goto :EOF
call set left_part=%%par1:~0,%cnt1%%%
call set right_part=%%par1:~%cnt2%%%
call :color 07 "%left_part%" 0E "%string_to_search%" 07 "%right_part%"
echo.
goto :EOF
:Color
:: v23c Carlos
:: Arguments: hexColor text [\n] ...
:: \n -> newline ... -> repeat
:: Supported in windows XP, 7, 8.
:: This version works using Cmd /U
:: In XP extended ascii characters are printed as dots.
:: For print quotes, use empty text.
SetLocal EnableExtensions EnableDelayedExpansion
Subst `: "!Temp!" >Nul &`: &Cd \
SetLocal DisableDelayedExpansion
Echo(|(Pause >Nul &Findstr "^" >`)
Cmd /A /D /C Set /P "=." >>` <Nul
For /F %%# In (
'"Prompt $H &For %%_ In (_) Do Rem"') Do (
Cmd /A /D /C Set /P "=%%# %%#" <Nul >`.1
Copy /Y `.1 /B + `.1 /B + `.1 /B `.3 /B >Nul
Copy /Y `.1 /B + `.1 /B + `.3 /B `.5 /B >Nul
Copy /Y `.1 /B + `.1 /B + `.5 /B `.7 /B >Nul
)
:__Color
Set "Text=%~2"
If Not Defined Text (Set Text=^")
SetLocal EnableDelayedExpansion
For %%_ In ("&" "|" ">" "<"
) Do Set "Text=!Text:%%~_=^%%~_!"
Set /P "LF=" <` &Set "LF=!LF:~0,1!"
For %%# in ("!LF!") Do For %%_ In (
\ / :) Do Set "Text=!Text:%%_=%%~#%%_%%~#!"
For /F delims^=^ eol^= %%# in ("!Text!") Do (
If #==#! EndLocal
If \==%%# (Findstr /A:%~1 . \` Nul
Type `.3) Else If /==%%# (Findstr /A:%~1 . /.\` Nul
Type `.5) Else (Cmd /A /D /C Echo %%#\..\`>`.dat
Findstr /F:`.dat /A:%~1 .
Type `.7))
If "\n"=="%~3" (Shift
Echo()
Shift
Shift
If ""=="%~1" Del ` `.1 `.3 `.5 `.7 `.dat &Goto :Eof
Goto :__Color
Output:
This can't be done in just a few commands (FINDSTR /A), right?
Thanks.
Saso