FComp.bat: Reformating FC output to get better info

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Aacini
Expert
Posts: 1885
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

FComp.bat: Reformating FC output to get better info

#1 Post by Aacini » 10 Nov 2012 22:26

FC.EXE program is one of the most used DOS commands; however, it's output is confusing and annoying and always require an additional effort to make the most of it. If a mismatched section is too large, screen output is just useless so it is customary to redirect FC output to a file and then open the file in order to make good use of the result. I need to use FC in my everyday job, so I frequently complained about it... Until now!

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! 8)

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
Last edited by Aacini on 05 May 2014 12:25, edited 3 times in total.

Aacini
Expert
Posts: 1885
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: FComp.bat: Reformating FC output to get better info

#2 Post by Aacini » 12 Nov 2012 18:38

I slightly modified FComp.bat program above to get FC parameters and switches in the original order; I think it is simpler this way. I also made a couple cosmetic changes. This is the output of FComp /N /W FComp.OLD FComp.bat:

Code: Select all

Comparing files FComp.OLD and FCOMP.BAT

==============================  SECTION UPDATED  ==============================

    7:  echo/                          |    7:  echo/
    8:  echo FCOMP filename1 filename2 |    8:  echo FCOMP same parameters and
                          [FC switches]&                 switches of FC command
    9:  goto :EOF                      |    9:  goto :EOF

======  NEW SECTION ADDED  ====================================================

   13:  set while=if not
+       |   14:  set   and=if not
   14:  set do=goto endwhile

==============================  SECTION UPDATED  ==============================

   20:  if "%params: /N=%" neq "%params|   21:  if "%params: /N=%" neq "%params
             %" set numbersInLines=TRUE&             %" set numbersInLines=TRUE
   21:  fc %3 %4 %5 %6 %7 %8 %9 %1 %2 >|   22:  fc %* > differences.txt
                        differences.txt<
   22:  if %errorlevel% equ 0 echo FC: |   23:  if %errorlevel% equ 0 echo FC:
             no differences encountered&             no differences encountered

==============================  SECTION UPDATED  ==============================

   41:        %while% defined line %do%|   42:        %while% defined line
                                    1.5&                                %do%1.5
   42:        %while% "!line:~126,1!" n|   43:          %and% "!line:~126,1!" n
                          eq "" %do%1.5&                          eq "" %do%1.5
   43:           set line=             |   44:           set line=

==============================  SECTION UPDATED  ==============================

   61:        %while% defined line %do%|   62:        %while% defined line
                                    2.5&                                %do%2.5
   62:        %while% "!line:~126,1!" n|   63:          %and% "!line:~126,1!" n
                          eq "" %do%2.5&                          eq "" %do%2.5
   63:           set line=             |   64:           set line=

Antonio

Aacini
Expert
Posts: 1885
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: FComp.bat: Reformating FC output to get better info

#3 Post by Aacini » 15 Dec 2014 21:44

I have modified the original FComp.bat program in order to get just the modifications of the first file when it is compared vs the second one. This data may serve to obtain the new version of a certain file when the modifications are applied to original file via the new Update-Rollback.bat program. This way, when several versions of a file needs to be posted, these two programs allows to post just the first version of the file and all the necessary modifications files. If the base file is big, this method may save a large amount of space.

The method may also be used in the opposite direction: post only the last version of a file and post also a modifications file in the reverse direction that allows to roll back to the previous version. This method is convenient if the last version is the important one, but allows to recover previous versions if they are needed for any reason. For further details, execute Update-Rollback.bat program with no parameters.

This is the new version of FComp.bat program with /Modifications switch:

Code: Select all

@echo off
setlocal EnableDelayedExpansion

rem FComp.bat: Format FC output in a pleasant way
rem Antonio Perez Ayala

rem Nov/10/2012 - First version
rem Dec/15/2014 - /M switch create a Modifications file for Update-Rollback.bat program

if "%~2" neq "" goto begin
echo Format FC output identifying added, deleted and modified sections
echo/
echo FCOMP [/M] same parameters and switches of FC command
echo/
echo    /M  create Modifications file. If this switch is included,
echo        the rest of switches must be moved to end of command:
echo        FCOMP /M firstFile secondFile switches...
echo/
echo A Modifications file serve to obtain a new version file when it is applied to
echo previous version via Update-Rollback.bat program.
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 "Mswitch="
set "number="
if "!params:/M =!" neq "!params!" (
   set "Mswitch=true"
   set "params=!params:/M =/N !"
   set "number=:~0,5"
   set lastOldLine=0
   for /F %%a in ('find /C /V "" ^< "%~2"') do set /A "lastFileLine=%%a, lastFileLineP1=%%a+1"
   set "mods="
   set badOld="%~N2.log"
   set badNew="%~N3.log"
   del !badOld! !badNew! 2> NUL
)
set "cutNumber="
if "!params:/N =!" neq "!params!" set "cutNumber=:~8"
fc !params! > differences.tmp
if %errorlevel% equ 0 (
   echo FComp: no differences encountered
) else (
   call :FormatFCOutput < differences.tmp
)
del differences.tmp
goto :EOF


:FormatFCOutput

set /P line=
if not defined Mswitch 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!"
      set "badLine="
      :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%!"
         set "badLine=true"
      %endwhile%1.5
      :endwhile1.5
      if defined badLine if defined MSwitch echo !oldLine[%old%]!>> !badOld!
      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!"
      set "badLine="
      :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%!"
         set "badLine=true"
      %endwhile%2.5
      :endwhile2.5
      if defined badLine if defined MSwitch echo !newLine[%new%]!>> !badNew!
      set "newLine[%new%]=!newLine[%new%]! "
      set "line="
      set /P line=
   %endwhile%2
   :endwhile2

   rem Identify the type of this set

   if not defined Mswitch 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 (
      if not defined Mswitch (
         echo ======  NEW SECTION ADDED AT END OF FILE  =====================================
         echo/
         for /L %%i in (1,1,%new%) do echo +       ^|!newLine[%%i]:~0,70!
      ) else (
         call :checkOldRange %lastFileLineP1%
         echo !mods!+%new%
         for /L %%i in (1,1,%new%) do echo !newLine[%%i]!
         set "mods="
         set /P "=." < NUL > CON
      )
   ) else if %new% equ 0 (
      if not defined Mswitch (
         echo OLD SECTION DELETED FROM END OF FILE  =========================================
         echo/
         for /L %%i in (1,1,%old%) do echo -!oldLine[%%i]:~0,78!
      ) else (
         call :checkOldRange !oldLine[1]%number%! %lastFileLine%
         rem Just ignore the last section
         REM set "mods=!mods!-!oldRange! "
      )
   ) else if %oldEqu2_And_NewNeq2% neq 0 (
      call :getBothLines[1]
      if "!oldLine!" equ "!newLine!" (
         set /A new-=1
         if not defined Mswitch (
            echo ======  NEW SECTION ADDED  ====================================================
            echo/
            echo(!oldLine[1]:~0,79!
            for /L %%i in (2,1,!new!) do echo +       ^|!newLine[%%i]:~0,70!
            echo(!oldLine[2]:~0,79!
         ) else (
            set /A oldP1=!oldLine[1]%number%! + 1, newM1=new-1
            call :checkOldRange !oldP1!
            echo !mods!+!newM1!
            for /L %%i in (2,1,!new!) do echo !newLine[%%i]!
            set "mods="
            set /P "=." < NUL > CON
         )
      ) else (
         set /A new-=2
         if not defined Mswitch (
            echo ======  NEW SECTION ADDED AT BEGINNING OF FILE  ===============================
            echo/
            for /L %%i in (1,1,!new!) do echo +       ^|!newLine[%%i]:~0,70!
            echo(!oldLine[1]:~0,79!
         ) else (
            echo +!new!
            for /L %%i in (1,1,!new!) do echo !newLine[%%i]!
         )
      )
   ) else if %newEqu2_And_OldNeq2% neq 0 (
      call :getBothLines[1]
      if "!oldLine!" equ "!newLine!" (
         set /A old-=1
         if not defined Mswitch (
            echo OLD SECTION DELETED  ==========================================================
            echo/
            echo ---------!newLine[1]:~0,70!
            for /L %%i in (2,1,!old!) do echo -!oldLine[%%i]:~0,78!
            echo ---------!newLine[2]:~0,70!
         ) else (
            call :checkOldRange !oldLine[2]%number%! %%oldLine[!old!]%number%%%
            set "mods=!mods!-!oldRange! "
         )
      ) else (
         set /A old-=2
         if not defined Mswitch (
            echo OLD SECTION DELETED FROM BEGINNING OF FILE  ===================================
            echo/
            for /L %%i in (1,1,!old!) do echo -!oldLine[%%i]:~0,78!
         ) else (
            call :checkOldRange 1 %%oldLine[!old!]%number%%%
            set "mods=!mods!-!oldRange! "
         )
      )
   ) else (
      if not defined Mswitch (
         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
         )
      ) else (
         set /A old-=1, new-=1, newM1=new-1
         call :checkOldRange !oldLine[2]%number%! %%oldLine[!old!]%number%%%
         echo !mods!-!oldRange! +!newM1!
         for /L %%i in (2,1,!new!) do echo !newLine[%%i]!
         set "mods="
         set /P "=." < NUL > CON
      )
   )

   if defined mods if "%mods:~78%" neq "" (
      echo %mods%
      set "mods="
      set /P "=." < NUL > CON
   )

   rem Pass to next set of differences
   set /P line=
   set "line="
   set /P line=
%endwhile%
:endwhile

if defined Mswitch (
   call :checkOldRange %lastFileLineP1%
   if defined mods echo !mods!
   echo/> CON
   echo/> CON
   echo Modifications data created> CON
)

set "badLines="
if exist !badOld! set badLines=true
if exist !badNew! set badLines=true
(if defined badLines (
   echo/
   echo/
   echo ATTENTION: You must review the Modifications data generated. The FC command
   echo incorrectly divides lines longer than 127 characters, so the line numeration is
   echo out of step by 1 or more for each long line that appear in the files.
   echo/
   echo The offending lines detected are stored in files with same names and .log
   echo extension: !badOld! and !badNew!
)) > CON

exit /B


:checkOldRange oldStart [oldEnd]
set /A lastLine=lastOldLine+1
if %lastLine% lss %1 (
   set /A lines=%1-lastLine
   set "mods=!mods!!lines! "
   set /A lastOldLine+=lines
)
if "%2" neq "" (
   set /A oldRange=%2-%1+1, lastOldLine=%2
)
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

This is Update-Rollback.bat program:

Code: Select all

@echo off

rem Update/Rollback to/from a new version using the /Modifications data created by FComp.bat
rem Antonio Perez Ayala

if "%~2" neq "" goto checkParams
echo Update-Rollback to/from a new version file
echo/
echo %0 BaseVersionFile.ext Modifications.txt
echo/
echo Modify the first file applying the modifications indicated by second file.
echo The second file must be created by FComp.bat program with the /M switch.
echo/
echo This program obtain anoter version of a base file that depends on the way
echo that the modifications file was created by FComp /M program.
echo/
echo If FComp was executed like this:
echo     FComp /M PreviousVersion.ext NewVersion.ext ^> DataToUpdate.txt
echo then an update of previous version may be obtained this way:
echo     Update-Rollback PreviousVersion.ext DataToUpdate.txt ^> NewVersion.ext
echo/
echo If FComp was executed like this:
echo     FComp /M NewVersion.ext PreviousVersion.ext ^> DataToRollback.txt
echo then a rollback from new version may be obtained this way:
echo     Update-Rollback NewVersion.ext DataToRollback.txt ^> PreviousVersion.ext
goto :EOF

:checkParams
if not exist %1 echo Base file not found: %1 & goto :EOF
if not exist %2 echo Modifications file not found: %2 & goto :EOF

setlocal EnableDelayedExpansion
set "insert=0"
< %1 (for /F "delims=" %%a in (%2) do (
   if !insert! gtr 0 (
      setlocal DisableDelayedExpansion
      set "line=%%a"
      setlocal EnableDelayedExpansion
      set "line=!line:~0,-1!"
      echo(!line:*:  =!
      endlocal & endlocal
      set /A insert-=1
   ) else (
      for %%b in (%%a) do (
         set "mod=%%b"
         if "!mod:~0,1!" equ "+" (
            set "insert=!mod:~1!"
         ) else if "!mod:~0,1!" equ "-" (
            for /L %%i in (1,1,!mod:~1!) do set /P "line="
         ) else (
            for /L %%i in (1,1,!mod!) do (
               set "line="
               set /P "line="
               echo(!line!
            )
         )
      )
   )
))


Antonio

brinda
Posts: 78
Joined: 25 Apr 2012 23:51

Re: FComp.bat: Reformating FC output to get better info

#4 Post by brinda » 16 Dec 2014 06:48

antonio,

thanks for the Update-Rollback.bat and how it works.

Samir
Posts: 384
Joined: 16 Jul 2013 12:00
Location: HSV
Contact:

Re: FComp.bat: Reformating FC output to get better info

#5 Post by Samir » 22 Dec 2014 02:28

Great stuff. I've always been using windiff for side by side line comparisons, but fcomp.bat will be nice as I don't exactly have the luxury of having a gui all the time. 8)

Post Reply