zOs/REXX.O13/DIFF

/*REXX*****************************************************************
       OMS.DIV.P0.STAT.RZ2.Y04M11
       OMS.DIV.P0.STAT.RZ2.SOR.Y04M11
 **********************************************************************/
parse arg left right
if left = '' then
    left = "'OMS.DIV.P0.STAT.RZ1.Y04M12'"
    /* left = 'POVDOKU.des.y04m09' */
if right = '' then
    right = "'OMS.DIV.P0.STAT.RZ1.Y04M12.SV041218'"
    /* right = 'POVDOKU.old.y04m09' */
call diffThree left, right
exit
call diffOne 'POVDOKU.lib(dif04X10)'

diffThree: procedure
parse arg left, right
    sayCnt = 0
    call adrTso "ALLOC DS("left") F(fiLe) REU SHR "
    call adrTso "ALLOC DS("right") F(fiRi) REU SHR "
    laDiff = ''
    leFi = 1
    leX = 0
    leRc = leRead()
    riX = 0
    riRc = riRead()
    toLeSk = 0
    toRiSk = 0
    to0 = 0
    to10 = 0
    toXX = 0
    toSub = 0
    toLeDay = 0
    toRiDay = 0
    laSay = ''
    do while leRc = 0 & riRc = 0
        if leKey <> riKey then do
            diff = ''
            call addDiff
            leSk = 0
            riSk = 0
            do while leRc = 0 & riRc = 0
                if leKey = riKey then
                    leave
                else if leKey = riKey1 | leKey = riKey2 | leKey=riKey3 ,
                      | leKey = riKey4 then do
                    if leRead() = 0 then
                        leSk = leSk + 1
                    end
                else if riKey = leKey1 | riKey = leKey2 | riKey=leKey4 ,
                      | riKey = leKey4 then do
                    if riRead() = 0 then
                        riSk = riSk + 1
                    end
                else if left(reRi1, 8) = 'SUBFILE=' then do
                      call riRead
                      toSub = toSub + 1
                    end
                else if left(leKey, 3) > left(riKey, 3) then do
                    if laLeDay <> left(leKey, 3) then do
                        say 'skip left begin day' left(leKey, 3)
                        laLEDay = left(LEKey, 3)
                        end
                    call LeRead
                    toLeDay = toLeDay + 1
                    end
                else if left(leKey, 3) < left(riKey, 3) then do
                    if laRiDay <> left(riKey, 3) then do
                        say 'skip right begin day' left(riKey, 3)
                        laRiDay = left(riKey, 3)
                        end
                    call riRead
                    toRiDay = toRiDay + 1
                    end
                else do
                    say 'key not found' leX riX 'key' leKey riKey
                    call leRead
                    leSk = leSk + 1
                    end
                end
          /* say 'skipped left' leSk 'to' leX 'right' riSk 'to' riX */
            toLeSk = toLeSk + leSk
            toRiSk = toRiSk + riSk
            leFi = leX
            end
        if laSay <> left(leKey, 3) then do
            say time() leX riX 'skip' toLeSk toRiSk 'sub' toSub ,
                  'day' toLeDay toRiDay 'after day' laSay
            laSay = left(leKey, 3)
            end
        diff = diff(reLe1, reRi1)
        if diff <> laDiff then
            call addDiff
        call leRead
        call riRead
        end
    if leRc = 0 then
         call addDiff 1
    else do
         leX = leX + 1
         call addDiff
         leX = leX - 1
         end
    say 'end left' leX 'rc' leRc 'right' riX 'rc' riRc
    say 'tot = ' to0 ', <10' to10 ', >' toXX
    say 'skip left ' toLeSk 'right' toRiSk ,
               'sub' toSub 'day' toLeDay toRiDay
return /* diffThree */

addDiff:
parse arg sayIt
    if leFi < leX & sayIt = '1' then do
        say time() forRange(leFi, leX-1, 15) laDiff
        sayCnt = sayCnt + 1
        end
    if length(laDiff) < 1 then
        to0 = to0 + leX - leFi
    else if length(laDiff) < 10 then
        to10 = to10 + leX - leFi
    else
        toXX = toXX + leX - leFi
    laDiff = diff
    leFi = leX
return /* end addDiff */

diffTwo: procedure
parse arg left, right
    sayCnt = 0
    call adrTso "ALLOC DS("left") F(fiLe) REU SHR "
    call adrTso "ALLOC DS("right") F(fiRi) REU SHR "
    laDiff = ''
    leFi = 1
    leRc = adrTsoRc("EXECIO 1 DISKRU fiLe (STEM reLe)")
    leX = 1
    riRc = adrTsoRC("EXECIO 1 DISKRU fiRi (STEM reRi)")
    riX = 1
    toLeSk = 0
    toRiSk = 0
    to0 = 0
    to10 = 0
    toXX = 0
    do while lx < 300000 & sayCnt < 300 & leRc = 0 & riRc = 0
        diff = diff(reLe1, reRi1)
        leRc = adrTsoRc("EXECIO 1 DISKRU fiLe (STEM reLe)")
        riRc = adrTsoRC("EXECIO 1 DISKRU fiRi (STEM reRi)")
        if diff <> laDiff then do
            if laDiff <> '' then do
                say time() forRange(leFi, leX-1, 15) laDiff
                sayCnt = sayCnt + 1
                if length(laDiff) < 10 then
                    to10 = to10 + leX - leFi
                else
                    toXX = toXX + leX - leFi
                end
            else
                to0 = to0 + leX - leFi
            leKey = bitXor(substr(reLe1, 124, 3),,'ff'x) ,
                        || substr(reLe1,5,44)
            riKey = bitXor(substr(reRi1, 124, 3),,'ff'x) ,
                       ||  substr(reRi1,5,44)
            leSk = 0
            riSk = 0
            do while leRc = 0 & riRc = 0
                if leKey < riKey then do
                    leRc = adrTsoRc("EXECIO 1 DISKRU fiLe (STEM reLe)")
                    leKey = bitXor(substr(reLe1, 124, 3),,'ff'x) ,
                               || substr(reLe1,5,44)
                    leSK = leSk + 1
                    end
                else if leKey > riKey then do
                    riRc = adrTsoRc("EXECIO 1 DISKRU fiRi (STEM reRi)")
                    riSk = riSk + 1
                    riKey = bitXor(substr(reRi1, 124, 3),,'ff'x) ,
                               || substr(reRi1,5,44)
                    end
                else
                    leave
                end
            leX = leX + leSk
            toLeSk = toLeSk + leSk
            riX = riX + riSk
            toRiSk = toRiSk + riSk
            if leSk = 0 & riSk = 0 then do
                laDiff = diff
                end
            else do
                say 'skipped left ' leSk 'to' (leX + 1) ,
                       'right ' riSk 'to' (riX + 1)
                laDiff = diff(reLe1, reRi1)
                end
            leFi = leX
            end
        else if (leX-leFi) // 10000 = 0 then
            say time() leX riX 'laDiff' laDiff
        leX = leX + 1
        riX = riX + 1
        end
    if leX > leFi then do
        say time() forRange(leFi, leX-1, 15) laDiff
        if length(laDiff) < 1  then
            to0 = to0 + leX - leFi
        else if length(laDiff) < 10 then
            to10 = to10 + leX - leFi
        else
            toXX = toXX + leX - leFi
        end
    if leRc <> 0 then
        leX = leX - 1
    if riRc <> 0 then
        riX = riX - 1
    say 'end left' leX 'rc' leRc 'right' riX 'rc' riRc
    say 'tot = ' to0 ', <10' to10 ', >' toXX
    say 'skip left ' toLeSk 'right' toRiSk
return /* diffTwo */

leRead:
    leRc = adrTsoRc("EXECIO 1 DISKRU fiLe (STEM reLe)")
    if leRc <> 0 then
        return leRc
    leX = leX + 1
    key = substr(reLe1, 124, 3)substr(reLe1,5,44)
    if leKey <> key then do
        leKey4 = leKey3
        leKey3 = leKey2
        leKey2 = leKey1
        leKey1 = leKey
        leKey = key
        end
return 0; /* leRead */

riRead:
    riRc = adrTsoRc("EXECIO 1 DISKRU fiRi (STEM reRi)")
    if riRc <> 0 then
        return riRc
    riX = riX + 1
    key = substr(reRi1, 124, 3)substr(reRi1,5,44)
    if riKey <> key then do
        riKey4 = riKey3
        riKey3 = riKey2
        riKey2 = riKey1
        riKey1 = riKey
        riKey = key
        end
return 0; /* riRead */

diffOne: procedure
parse arg left
    call adrTso "ALLOC DS("left") F(fiLe) REU SHR "
    laDiff = ''
    rf = 1
    call adrTSO "EXECIO 1 DISKRU fiLe (STEM reLe)"
    call adrTSO "EXECIO 1 DISKRU fiLe (STEM reRi)"
    do rx=2 by 1 while (reRi0 = 1)
        if (rx // 50000) < 20 | rx > 250000 then do
        diff = diff(reLe1, reRi1)
        if diff <> laDiff then do
            if laDiff <> '' then
                say time() forRange(rf, rx-1, 15) laDiff
            laDiff = diff
            rf = rx
            end
        reLe1 = reRi1
        end
        call adrTSO "EXECIO 1 DISKRU fiLe (STEM reRi)"
        end
    if laDiff <> '' then
        say forRange(rf, rx-1, 15) laDiff
return /* diffTwo */

forRange: procedure
parse arg rf, rt, le
    if rf = rt then
        res = rf
    else
        res = rf'-'rt
    if le = '' then
        return res
    if le <= length(res) then
        return res
    else
        return left(res, le)
/* end forRange */

diff: procedure
parse arg le, ri
    if length(le) < length(ri) then
        cz = length(le)
    else
        cz = length(ri)
    cx = 1
    diff = ''
    do while(cx <= cz)
        cy = compare(substr(le, cx), substr(ri, cx))
        if cy = 0 then
            leave
        cy = cx + cy - 1
        do cx = cy + 1 to cz while substr(le, cx, 1)<>substr(ri, cx, 1)
            end
        diff = diff forRange(cy, cx-1)
        end
    if length(le) < length(ri) then
        diff = diff "right" (length(le)+1) || '-' || length(ri)
    else if length(le) > length(ri) then
        diff = diff "left" (length(ri)+1) || '-' || length(le)
return diff /* end diff */

showtime:
parse arg showmsg
    say time() sysvar('syscpu') sysvar('syssrv') showmsg
return 0

adrTsoRc:
    parse arg adrCmd
    address tso adrCmd
return rc  /* end adrTsoRc */

adrTso:
    parse arg adrCmd
    address tso adrCmd
    if rc <> 0 then
        call err 'adrTso rc' rc 'for' adrCmd
return /* end adrTso */

adrIspRc:
    parse arg adrCmd
    address ispexec adrCmd
return rc /* end adrIspRc */

adrIsp:
    parse arg adrCmd
    address ispexec adrCmd
    if rc <> 0 then
        call err 'adrIsp rc' rc 'for' adrCmd
return /* end adrIsp */

adrEdit:
    parse arg adrCmd, ret
    address isrEdit adrCmd
    if rc <> 0 then
        call err 'adr isrEdit rc' rc 'for' adrCmd
return /* end adrEdit */

adrEditRc:
    parse arg adrCmd
    address isrEdit adrCmd
return rc /* end adrEditRc */

err:
    parse arg txt
    say 'fatal error in ??:' txt
exit 12