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