On 18/10/2012 05:55, Larry__Weiss wrote:
> I'm trying to use fc.exe for some general source code comparisons and I'm finding out that it is
> very buggy.
>
> Anyone else have any experience using fc.exe ?
>
> If so have you experienced bugs in the results, especially with respect to the line numbers you get
> using the /N argument to fc.exe ?
>
> - LarryW
>
Somebody else had to use FC and wrote a tool for it.
Any lines in column 1 have wrapped.
http://www.dostips.com/forum/viewtopic.php?f=3&t=3968&view=unread#unread
@echo off
rem FComp.bat: Format FC output in a pleasant way
rem Antonio Perez Ayala - Nov/10/2012
if "%~2" neq "" goto start
echo Format FC output identifying added, deleted or updated sections
echo/
echo FCOMP filename1 filename2 [FC switches]
goto :EOF
:start
setlocal EnableDelayedExpansion
set while=if not
set do=goto endwhile
set endwhile=goto while
set "space= "
set "spaces39= "
set numbersInLines=
set params=%*
if "%params: /N=%" neq "%params%" set numbersInLines=TRUE
fc %3 %4 %5 %6 %7 %8 %9 %1 %2 > differences.txt
if %errorlevel% equ 0 echo FC: no differences encountered
if %errorlevel% equ 1 call :FormatFCOutput < differences.txt
del differences.txt
goto :EOF
:FormatFCOutput
set /P line=
echo %line%
set /P line=
:while Process each set of differences
%while% defined line %do%
set line=
set /P line=
set old=0
:while1 Load old section of this set
%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
%while% "!line:~126,1!" neq "" %do%1.5
set line=
set /P line=
set oldLine[%old%]=!oldLine[%old%]! !line!
%endwhile%1.5
:endwhile1.5
set oldLine[%old%]=!oldLine[%old%]!%space%
set line=
set /P line=
%endwhile%1
:endwhile1
set line=
set /P line=
set new=0
:while2 Load new section of this set
%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
%while% "!line:~126,1!" neq "" %do%2.5
set line=
set /P line=
set newLine[%new%]=!newLine[%new%]! !line!
%endwhile%2.5
:endwhile2.5
set newLine[%new%]=!newLine[%new%]!%space%
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 an updated 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 UPDATED ==============================
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]!
set newLine=!newLine[1]!
if defined numbersInLines (
set oldLine=!oldLine:*:=!
set newLine=!newLine:*:=!
)
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
--
foxi