home *** CD-ROM | disk | FTP | other *** search
/ TopWare Tools / TOOLS.iso / tools / top1477 / inidif.mnu < prev   
Encoding:
MarxMenu script  |  1994-02-10  |  8.4 KB  |  361 lines

  1. Comment
  2. ==========================================================
  3.  
  4. Computer Tyme IniDif * Copyright 1993 by Marc Perkel
  5. All Rights Reserved
  6.  
  7. Computer Tyme * 411 North Sherman, Suite 300 * Springfield Mo. 65802
  8. (800) 548-5353 Sales * (417) 866-1222 Voice * (417) 866-1665 Data
  9.  
  10. IniDif is a Windows *.INI file comparer. It is designed to assist the
  11. network administrator who has to maintain INI files for many users.
  12.  
  13. USAGE: INIDIF NewFile OldFile ChangeFile
  14.  
  15. Example:
  16.   INIDIF SYSTEM.INI SYSTEM.OLD SYSTEM.CHG
  17.  
  18. ==========================================================
  19. EndComment
  20.  
  21. ;------ Create Variables
  22.  
  23. var
  24.   OrigFileName
  25.   Orig
  26.   UOrig
  27.   NewFileName
  28.   New
  29.   UNew
  30.   ChangeFileName
  31.   Changes
  32.   Match
  33.   NameIndex
  34.   BlockStartIndex
  35.   BlockEndIndex
  36.   ThisSection
  37.   LastSection
  38.   LastSectionNumber
  39.   DriversSection
  40.  
  41.  
  42. Main
  43.  
  44. ;======================= P R O C E D U R E S ===========================
  45.  
  46. Comment
  47. ================================================
  48.  
  49. The file is read into the array Orig. It is then processed and a
  50. parallel array UOrig is created. The lines in UOrig are upper case with
  51. extra spaces and comments removed and are more suitable for searching
  52. and comparing.
  53.  
  54. NameIndex contains a list of group headings. BlockStartIndex contains a list
  55. of line numbers that groups start. BlockEndIndex contains a list og line
  56. numbers where groups end. That way when I search I know what range of
  57. line numbers to start and end at.
  58.  
  59. ================================================
  60. EndComment
  61.  
  62.  
  63. Procedure IndexFile
  64. var LastTextLine NotFirst
  65.    UOrig = Orig
  66.    Loop UOrig
  67.       LoopVal = ProcessLine(LoopVal)
  68.    EndLoop
  69.    Loop UOrig
  70.       if Left(LoopVal,1) = '['
  71.          AppendArray(NameIndex,LoopVal)
  72.          AppendArray(BlockStartIndex,LoopIndex)
  73.          if NotFirst
  74.             AppendArray(BlockEndIndex,LastTextLine)
  75.          else
  76.             NotFirst = True
  77.          endif
  78.       endif
  79.       if LoopVal > '' then LastTextLine = LoopIndex
  80.    EndLoop
  81.    AppendArray(BlockEndIndex,LastTextLine)
  82. EndProc
  83.  
  84. ;----- New Original line to uppercase and removes comment lines
  85.  
  86. Procedure ProcessLine (St)
  87. var P
  88.    Trim(St)
  89.    if Left(St,1) = ';'
  90.       St = ''
  91.    elseif Left(St,1) = '#'
  92.       St = ''
  93.    else
  94.       St = UpperCase(St)
  95.    endif
  96.    P = pos('=',St)
  97.    if P > 0
  98.       P = P + 1
  99.       while Mid(St,P,1) = ' '
  100.          delete(St,P,1)
  101.       endwhile
  102.       P = P - 2
  103.       while (Mid(St,P,1) = ' ') and (P > 0)
  104.          delete(St,P,1)
  105.          P = P - 1
  106.       endwhile
  107.    endif
  108.    Return St
  109. EndProc
  110.  
  111.  
  112. Procedure SectionName
  113.    if ThisSection = 0 then Return ''
  114.    Return NameIndex[ThisSection]
  115. EndProc
  116.  
  117.  
  118. Procedure FindSection (St)
  119.    ThisSection = PosInList(St,NameIndex)
  120.    if ThisSection = 0
  121.       DriversSection = False
  122.    else
  123.       DriversSection = St = '[386ENH]'
  124.       Match[BlockStartIndex[ThisSection]] = True
  125.    endif
  126. EndProc
  127.  
  128.  
  129. Procedure FindLine (St)
  130. var S E KeyWord
  131.    if ThisSection = 0 then Return 0
  132.    KeyWord = Left(St,pos('=',St))
  133.  
  134.    ;- The [386Enh] section is a special case if adding drivers
  135.  
  136.    if DriversSection
  137.       if KeyWord = 'DEVICE='
  138.          KeyWord = St
  139.       endif
  140.    endif
  141.  
  142.    S = BlockStartIndex[ThisSection]
  143.    E = BlockEndIndex[ThisSection]
  144.  
  145.    if DriversSection
  146.  
  147.       while S <= E
  148.          if pos(KeyWord,UOrig[S]) > 0
  149.             Match[S] = True
  150.             Return S
  151.          endif
  152.          S = S + 1
  153.       endwhile
  154.  
  155.    else
  156.  
  157.       while S <= E
  158.          if Left(UOrig[S],length(KeyWord)) = KeyWord
  159.             Match[S] = True
  160.             Return S
  161.          endif
  162.          S = S + 1
  163.       endwhile
  164.  
  165.    endif
  166.    Return 0
  167. EndProc
  168.  
  169.  
  170. Procedure Log (St)
  171.    AppendArray(Changes,St)
  172. EndProc
  173.  
  174.  
  175. Procedure CheckForDelete (Section)
  176. var S E
  177.    if Section = 0 then Return
  178.    S = BlockStartIndex[Section] + 1
  179.    E = BlockEndIndex[Section]
  180.  
  181.    while S <= E
  182.       if not Match[S]
  183.          if UOrig[S] > '' then Log('DEL ' + Orig[S])
  184.       endif
  185.       S = S + 1
  186.    endwhile
  187. EndProc
  188.  
  189.  
  190. Procedure CheckForDeleteSections
  191.    Loop BlockStartIndex
  192.       if LoopVal > 0
  193.          if BlockEndIndex[LoopIndex] > 0
  194.             if not Match[LoopVal]
  195.                Log ''
  196.                Log('DEL ' + Orig[LoopVal])
  197.             endif
  198.          endif
  199.       endif
  200.    EndLoop
  201. EndProc
  202.  
  203.  
  204. Procedure LogChange (St)
  205.    if SectionName <> LastSection
  206.       if LastSection <> ''
  207.          CheckForDelete(LastSectionNumber)
  208.          Log ''
  209.       endif
  210.       if BlockEndIndex[ThisSection] = 0
  211.          Log New[BlockStartIndex[ThisSection]]
  212.       else
  213.          Log Orig[BlockStartIndex[ThisSection]]
  214.       endif
  215.       LastSection = SectionName
  216.       LastSectionNumber = ThisSection
  217.    endif
  218.    if St > '' then Log St
  219. EndProc
  220.  
  221.  
  222. Procedure CompareFiles
  223. var St Line Del AddMode ChangeMode Line Tmp
  224.    Loop New
  225.       St = UNew[LoopIndex]
  226.       if St > ''
  227.          if Left(St,1) = '['
  228.  
  229.             ;- New Group
  230.  
  231.             FindSection(St)
  232.             if ThisSection = 0
  233.                AppendArray(NameIndex,St)
  234.                AppendArray(BlockStartIndex,LoopIndex)
  235.                AppendArray(BlockEndIndex,0)
  236.                ThisSection = NumberOfElements(NameIndex)
  237.             endif
  238.          else
  239.             Line = FindLine(St)
  240.             if Line = 0
  241.                LogChange LoopVal
  242.             else
  243.                if LoopVal <> Orig[Line]
  244.                   LogChange LoopVal
  245.                endif
  246.             endif
  247.          endif
  248.       endif
  249.    EndLoop
  250.    CheckForDelete(LastSectionNumber)
  251.    CheckForDeleteSections
  252. EndProc
  253.  
  254.  
  255. Procedure Help
  256.    Writeln 'Computer Tyme INIDIF * Copyright 1993 by Marc Perkel'
  257.    Writeln 'All Rights Reserved * Version 1.2 * Release Date: 11-29-93'
  258.  
  259.    Include 'ADDRESS.INC'
  260.  
  261.    Writeln 'INIDIF compares two INI files and produces a third file that contains'
  262.    Writeln 'the differences between the two INI files. This allows you to install'
  263.    Writeln 'a new windows program and compare the changed INI file to the original'
  264.    Writeln 'INI file. The change file can then be used with INITYME to apply the same'
  265.    Writeln 'changes to other INI files of other users on a network.'
  266.    Writeln
  267.    Writeln 'USAGE: INIDIF NewFile OldFile ChangeFile'
  268.    Writeln
  269.    Writeln 'Example:'
  270.    Writeln '  INIDIF SYSTEM.INI SYSTEM.OLD SYSTEM.CHG'
  271.    Writeln
  272.    Writeln 'INIDIF is licensed for $35/User, $95/fileserver, $995 site license.'
  273.    Writeln 'INITYME comes free with INIDIF.'
  274.    ExitMenu
  275. EndProc
  276.  
  277.  
  278. Procedure Beg
  279. var Jessica
  280.    BoxHeader ' * Shameless Beg Screen * '
  281.    DrawBox 10 8 61 7
  282.    Writeln
  283.    WriteCenter '* IniDif Evaluation Copy *'
  284.    Writeln
  285.    WriteCenter 'Please remember to register this software.'
  286.    Writeln
  287.    if Timer and 1 = 0
  288.       Jessica = Now - TimeOf('1-17-80') / SecondsInDay / 365 + 2
  289.       WriteCenter 'I have a ' Jessica ' year old daughter who wants to go shopping.'
  290.    else
  291.       WriteCenter "I'd sure hate to have to find a real job."
  292.    endif
  293.    Wait 600
  294.    EraseTopWindow
  295.    ClearKbdBuffer
  296. EndProc
  297.  
  298.  
  299. Procedure AddIniExtension (Name)
  300.    Name = UpperCase(Name)
  301.    if pos('.',Name) > 0 then Return Name
  302.    Return ForceExtension(Name,'INI')
  303. EndProc
  304.  
  305.  
  306. Procedure Setup
  307.    BoxBorderColor Green Blue
  308.    BoxInsideColor White Blue
  309.    BoxHeaderColor Yellow Mag
  310.   ;Beg
  311.    StandardIO
  312.    Writeln
  313.    ExitCode = 0
  314.    NewFileName = AddIniExtension(ParamStr(2))
  315.    OrigFileName = AddIniExtension(ParamStr(3))
  316.    ChangeFileName = AddIniExtension(ParamStr(4))
  317.    if (ChangeFileName = '') or not ExistFile(NewFileName) or not ExistFile(OrigFileName)
  318.       Help
  319.    endif
  320.    Write 'Reading Files ... '
  321.    ReadTextFile(NewFileName,New)
  322.    UNew = New
  323.    Loop UNew
  324.       LoopVal = ProcessLine(LoopVal)
  325.    EndLoop
  326. EndProc
  327.  
  328.  
  329. Procedure ResetVariables
  330.    dispose(NameIndex)
  331.    dispose(BlockStartIndex)
  332.    dispose(BlockEndIndex)
  333.    ThisSection = 0
  334. EndProc
  335.  
  336.  
  337. Procedure ProcessFile
  338. var FileList
  339.    ReadTextFile(OrigFileName,Orig)
  340.    if NumberOfElements(Orig) = 0 then Return
  341.    ResetVariables
  342.    Log('; Changes to turn ' + OrigFileName + ' into ' + NewFileName)
  343.    Log('; File created: ' + DateString + ' ' + TimeString)
  344.    Log ''
  345.    Writeln
  346.    Write 'Comparing Files ... '
  347.    IndexFile
  348.    CompareFiles
  349.    Writeln
  350.    Write 'Writing Changes ... '
  351.    WriteTextFile(ChangeFileName,Changes)
  352.    Writeln
  353.    Writeln 'Done!'
  354. EndProc
  355.  
  356.  
  357. Procedure Main
  358.    Setup
  359.    ProcessFile
  360. EndProc
  361.