I wrote a Batch program that take FC output and rearrange it in a way that is much more pleasant to read. The program identify new sections added between two lines of original file, or sections deleted from original file, or sections that was modified in any other way (updated) and display them in a format that allows you to identify each case in an easy way. When a section is updated the old and new versions are displayed side by side, so they can be easily compared.
Cool!
Code: Select all
@echo off
setlocal EnableDelayedExpansion
rem FComp.bat: Format FC output in a pleasant way
rem Antonio Perez Ayala - Nov/10/2012
if "%~2" neq "" goto begin
echo Format FC output identifying added, deleted or modified sections
echo/
echo FCOMP same parameters and switches of FC command
goto :EOF
:begin
set while=if not
set and=if not
set do=goto endwhile
set endwhile=goto while
set break=goto endwhile
set "spaces39="
for /L %%i in (1,1,39) do set "spaces39=!spaces39! "
set params=%*
set "cutNumber="
if "!params:/N=!" neq "!params!" set "cutNumber=:~8"
fc %* > differences.txt
if %errorlevel% equ 0 (
echo FComp: no differences encountered
) else (
call :FormatFCOutput < differences.txt
)
del differences.txt
goto :EOF
:FormatFCOutput
set /P line=
echo %line%
set /P line=
:while There is another set of differences
%while% defined line %do%
set "line="
set /P line=
set old=0
:while1 There is another line in this old section
%while% "!line:~0,5!" neq "*****" %do%1
set /A old+=1
set "oldLine[%old%]=!line!"
:while1.5 PATCH FOR FC GLITCH: Concatenate next line while current is 127 chars. long
%while% defined line %do%1.5
%and% "!line:~126,1!" neq "" %do%1.5
set "line="
set /P line=
rem or until this set of differences ends
if "!line:~0,5!" equ "*****" %break%1
set "oldLine[%old%]=!oldLine[%old%]!!line%cutNumber%!"
%endwhile%1.5
:endwhile1.5
set "oldLine[%old%]=!oldLine[%old%]! "
set "line="
set /P line=
%endwhile%1
:endwhile1
set "line="
set /P line=
set new=0
:while2 There is another line in this new section
%while% "!line:~0,5!" neq "*****" %do%2
set /A new+=1
set "newLine[%new%]=!line!"
:while2.5 PATCH FOR FC GLITCH: Concatenate next line while current is 127 chars. long
%while% defined line %do%2.5
%and% "!line:~126,1!" neq "" %do%2.5
set "line="
set /P line=
rem or until this set of differences ends
if "!line:~0,5!" equ "*****" %break%2
set "newLine[%new%]=!newLine[%new%]!!line%cutNumber%!"
%endwhile%2.5
:endwhile2.5
set "newLine[%new%]=!newLine[%new%]! "
set "line="
set /P line=
%endwhile%2
:endwhile2
rem Identify the type of this set
echo/
rem PATCH FOR FC GLITCH: If both versions are size 2, it is a modified section
set /A "oldEqu2_And_NewNeq2=^!(old-2)*(new-2), newEqu2_And_OldNeq2=^!(new-2)*(old-2)"
if %old% equ 0 (
echo ====== NEW SECTION ADDED AT END OF FILE =====================================
echo/
for /L %%i in (1,1,!new!) do echo + ^|!newLine[%%i]:~0,70!
) else if %new% equ 0 (
echo OLD SECTION DELETED AT END OF FILE ===========================================
echo/
for /L %%i in (1,1,!old!) do echo -!oldLine[%%i]:~0,78!
) else if %oldEqu2_And_NewNeq2% neq 0 (
call :getBothLines[1]
if "!oldLine!" equ "!newLine!" (
echo ====== NEW SECTION ADDED ====================================================
echo/
echo(!oldLine[1]:~0,79!
set /A new-=1
for /L %%i in (2,1,!new!) do echo + ^|!newLine[%%i]:~0,70!
echo(!oldLine[2]:~0,79!
) else (
echo ====== NEW SECTION ADDED AT BEGINNING OF FILE ===============================
echo/
set /A new-=2
for /L %%i in (1,1,!new!) do echo + ^|!newLine[%%i]:~0,70!
)
) else if %newEqu2_And_OldNeq2% neq 0 (
call :getBothLines[1]
if "!oldLine!" equ "!newLine!" (
echo OLD SECTION DELETED ==========================================================
echo/
echo ---------!newLine[1]:~0,70!
set /A old-=1
for /L %%i in (2,1,!old!) do echo -!oldLine[%%i]:~0,78!
echo ---------!newLine[2]:~0,70!
) else (
echo OLD SECTION DELETED AT BEGINNING OF FILE =====================================
echo/
set /A old-=2
for /L %%i in (1,1,!old!) do echo -!oldLine[%%i]:~0,78!
)
) else (
echo ============================== SECTION MODIFIED =============================
echo/
if %old% lss %new% (
for /L %%i in (1,1,%old%) do call :showBothLines %%i
set /A old+=1
for /L %%i in (!old!,1,%new%) do call :showNewLine %%i
) else (
for /L %%i in (1,1,%new%) do call :showBothLines %%i
set /A new+=1
for /L %%i in (!new!,1,%old%) do call :showOldLine %%i
)
)
rem Pass to next set of differences
set /P line=
set "line="
set /P line=
%endwhile%
:endwhile
exit /B
:getBothLines[1]
set "oldLine=!oldLine[1]%cutNumber%!"
set "newLine=!newLine[1]%cutNumber%!"
exit /B
:showBothLines i
set "oldLine=!oldLine[%1]!%spaces39%"
echo !oldLine:~0,39!^|!newLine[%1]:~0,39!
set "oldLine=!oldLine[%1]:~39,-1!"
if defined oldLine (
set definedOldLine=TRUE
if "!oldLine:~39,1!" equ "" (
set "oldLine=%spaces39%!oldLine!"
set "oldLine=!oldLine:~-39!"
)
set "separator=&"
) else (
set definedOldLine=FALSE
set oldLine=%spaces39%
set "separator=>"
)
set "newLine=!newLine[%1]:~39,-1!"
:while3 Show a long new line at right side, old line or spaces at left side
%while% defined newLine %do%3
if "!newLine:~39,1!" equ "" (
set "newLine=%spaces39%!newLine!"
set "newLine=!newLine:~-39!"
)
echo !oldLine:~0,39!!separator!!newLine:~0,39!
if %definedOldLine% equ TRUE set "oldLine=!oldLine:~39!"
if defined oldLine (
if "!oldLine:~39,1!" equ "" (
set "oldLine=%spaces39%!oldLine!"
set "oldLine=!oldLine:~-39!"
)
) else (
set definedOldLine=FALSE
set oldLine=%spaces39%
set "separator=>"
)
set "newLine=!newLine:~39!"
%endwhile%3
:endwhile3
if %definedOldLine% neq TRUE set oldLine=
:while4 Show the rest of a long old line at left side
%while% defined oldLine %do%4
if "!oldLine:~39,1!" equ "" (
set "oldLine=%spaces39%!oldLine!"
set "oldLine=!oldLine:~-39!"
)
echo !oldLine:~0,39!^<
set "oldLine=!oldLine:~39!"
%endwhile%4
:endwhile4
exit /B
:showNewLine i
echo %spaces39%^|!newLine[%1]:~0,39!
set "newLine=!newLine[%1]:~39,-1!"
:while5 Show a long new line at right side, spaces at left side
%while% defined newLine %do%5
if "!newLine:~39,1!" equ "" (
set "newLine=%spaces39%!newLine!"
set "newLine=!newLine:~-39!"
)
echo %spaces39%^>!newLine:~0,39!
set "newLine=!newLine:~39!"
%endwhile%5
:endwhile5
exit /B
:showOldLine i
echo(!oldLine[%1]:~0,39!
set "oldLine=!oldLine[%1]:~39,-1!"
:while6 Show a long old line at left side
%while% defined oldLine %do%6
if "!oldLine:~39,1!" equ "" (
set "oldLine=%spaces39%!oldLine!"
set "oldLine=!oldLine:~-39!"
)
echo !oldLine:~0,39!^<
set "oldLine=!oldLine:~39!"
%endwhile%6
:endwhile6
exit /B
FComp.bat is designed to meet most FC output details and glitches. For example, FC command split long output lines every 127 characters and lost the character at position 128 in each division, so I had to insert a patch to manage this situation. Occasionally the initial line of an updated section is not the same in both versions; if the resulting section is only 2 lines long it may be erroneously reported as an added or deleted section, so I had to manage this particular case with special code again. Anyway, I am afraid that my program will make mistakes now and then, but I am tired of made endless tests and the program grew too much already.
To use FComp.bat place the same FC parameters and switches in the usual way. In this case, /N switch (numbered lines) could be very useful.
For example, this is the output of FComp OriginalPost.txt ModifiedPost.txt:
Code: Select all
Comparing files OriginalPost.txt and MODIFIEDPOST.TXT
============================== SECTION UPDATED ==============================
you to identify each case in an easy wa|you to identify each case in an easy wa
y. When a section is updated the old an&y. When a section is updated the old an
d & d
new versions are displayed side by side|new versions are displayed side by side
, so they can be easily compared.& , so they can be easily compared. Of
Cool! 8) |course, this feature requires to cut ea
>ch section at half the screen, but if a
> ny
|input line is longer then the rest of t
> he line(s) will be displayed in
|additional screen lines 39 characters l
> ong.
|Cool! 8)
====== NEW SECTION ADDED AT END OF FILE =====================================
+ |
+ |You may use /1 FC switch for a finer isolating of mismatched sections
+ |(the default is /2). This way, two deleted sections separated by 2
+ |lines (instead of 3 by default) will be reported as two deleted
+ |sections instead of one large updated section, for example. However,
+ |in this case several updated sections separated by just one line will
+ |be reported separately with the same ending-beginning lines instead of
+ |as just one large updated section. You may tune up this parameter to
+ |fit your needs.
Antonio