home *** CD-ROM | disk | FTP | other *** search
/ PC-Test Pro / PCTESTPRO.iso / filetool / initme / entp / inityme.mnu < prev   
Encoding:
MarxMenu script  |  1996-01-18  |  28.8 KB  |  1,259 lines

  1. Comment
  2. ==========================================================
  3.  
  4. Computer Tyme IniTyme * Copyright 1993-96 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/Fax
  9.  
  10. IniTyme is a Windows *.INI file manipulator. It is designed to assist the
  11. network administrator who has to maintain INI files for many users.
  12.  
  13. USAGE: INITYME ChangeFile IniFile
  14.  
  15. Example:
  16.   INITYME CHANGE.INI SYSTEM.INI
  17.  
  18. ==========================================================
  19. EndComment
  20.  
  21. ;#Define McAfee
  22. ;#Define Shareware
  23. ;#Define MarxErrors       ;show MarxMenu Errors
  24.  
  25. ;------ Create Variables
  26.  
  27. var
  28.   Orig
  29.   KOrig
  30.   Changes
  31.   UChanges
  32.   NameIndex
  33.   BlockStartIndex
  34.   BlockEndIndex
  35.   CurrentSection
  36.   ThisSection
  37.   NeedsIndexing
  38.   SectionStart
  39.   SectionEnd
  40.   SubFind
  41.   SubReplace
  42.   SubFindG
  43.   SubReplaceG
  44.   GroupSection
  45.   GroupSectionNumber
  46.   GroupMode
  47.   GroupAdded
  48.   Sections
  49.   InsertPos
  50.   Logging
  51.   LogHandle
  52.   LogGroup
  53.   LogFirstLine
  54.   NoBackup
  55.   RestoreMode
  56.   TestMode
  57.   ChangeFileName
  58.   IniFileName
  59.   StDelim
  60.   Yak
  61.   Quiet
  62.   GlobalDups
  63.   BackupExtension
  64.   BackupName
  65.   FirstProcessFile
  66.   ProgName
  67.   CleanNoEquals
  68.   CleanEmptySections
  69.  
  70. var
  71.   IfArray
  72.   Stack
  73.   GotoList
  74.   IfLine
  75.   ParenLevel
  76.  
  77. Main
  78.  
  79. ;======================= P R O C E D U R E S ===========================
  80.  
  81.  
  82. Procedure IndexFile
  83. var LastTextLine St
  84.    Loop Orig
  85.       St = CleanIniLine(LoopVal)
  86.       if St StartsWith '['
  87.  
  88.          ;-- Process Header
  89.  
  90.          ThisSection = St
  91.          GroupSection = (ThisSection = '[GROUPS]') or (ThisSection = '[NETMENU]')
  92.          CurrentSection = CurrentSection + 1
  93.  
  94.          AppendArray(NameIndex,St)
  95.          AppendArray(BlockStartIndex,succ(LoopIndex))
  96.          if CurrentSection > 1
  97.             AppendArray(BlockEndIndex,LastTextLine)
  98.          endif
  99.          LastTextLine = succ(LoopIndex)
  100.       else
  101.          if St > ''
  102.             LastTextLine = LoopIndex
  103.             KOrig[LoopIndex] = KeyString(St)
  104.          endif
  105.       endif
  106.    EndLoop
  107.    Sections = CurrentSection
  108.    CurrentSection = 0
  109.    if Sections > 0
  110.       AppendArray(BlockEndIndex,LastTextLine)
  111.    endif
  112.    NeedsIndexing = False
  113.    TestFreeMemory
  114. EndProc
  115.  
  116.  
  117. Procedure KeyString (St)
  118. var KeyWord
  119.    KeyWord = LeftOfEqual(St)
  120.    if Hash(KeyWord + ThisSection)
  121.  
  122.       ;- duplicates allowed
  123.  
  124.       Return St
  125.    endif
  126.    GroupMode = False
  127.    if GroupSection
  128.       if St StartsWith 'GROUP'
  129.          GroupMode = True
  130.          KeyWord = 'GROUP=' + FilePart(RightOfEqual(St))
  131.       endif
  132.    endif
  133.    Return KeyWord
  134. EndProc
  135.  
  136.  
  137. ;----- When adding or deleting the BlockStartIndex must be updated
  138.  
  139. Procedure AdjustLineIndex (Line, Adj)
  140.    Loop BlockStartIndex
  141.       if LoopVal > Line
  142.          LoopVal = LoopVal + Adj
  143.       endif
  144.    EndLoop
  145.  
  146.    Loop BlockEndIndex
  147.       if LoopVal >= (Line - Adj)
  148.          LoopVal = LoopVal + Adj
  149.       endif
  150.    EndLoop
  151.  
  152.    if CurrentSection > 0
  153.       SectionStart = BlockStartIndex[CurrentSection]
  154.       SectionEnd   = BlockEndIndex[CurrentSection]
  155.    endif
  156.  
  157.    if InsertPos >= Line
  158.       InsertPos = InsertPos + Adj
  159.    endif
  160.  
  161. EndProc
  162.  
  163.  
  164. Procedure LogEvent ($St)
  165.    if Logging
  166.       if LogGroup <> ThisSection
  167.          if (LogGroup <> '') or LogFirstLine
  168.  
  169.             ;- First line of this log session
  170.  
  171.             if LogFirstLine
  172.  
  173.                FileLog(LogHandle,'')
  174.                FileLog(LogHandle,'======================================================')
  175.                FileLog(LogHandle,'')
  176.                FileLog(LogHandle,'MainFile=' + IniFileName)
  177.                FileLog(LogHandle,'ChangeFile=' + ChangeFileName)
  178.                if NovLoginName > ''
  179.                   FileLog(LogHandle,'User=' + NovLoginName)
  180.                endif
  181.                FileLog(LogHandle,'Time: ' + DateString + ' ' + TimeString)
  182.                FileLog(LogHandle,'')
  183.                FileLog(LogHandle,'======================================================')
  184.  
  185.             endif
  186.  
  187.             FileLog(LogHandle,'')
  188.             if Yak then Writeln
  189.             FileLog(LogHandle,ThisSection)
  190.             if Yak then Writeln ThisSection
  191.          endif
  192.          LogFirstLine = False
  193.          LogGroup = ThisSection
  194.       endif
  195.       FileLog(LogHandle,St)
  196.    endif
  197.    if Yak then Writeln St
  198. EndProc
  199.  
  200.  
  201. Procedure DelLine (Line)
  202.    if Line = 0 then Return
  203.    LogEvent '  Deleted: ' Orig[Line]
  204.    Delete(Orig,Line,1)
  205.    Delete(KOrig,Line,1)
  206.    AdjustLineIndex(Line,-1)
  207. EndProc
  208.  
  209.  
  210. Procedure InsertLine (St,Line)
  211.    ArrayInsert(Orig,Line,1)
  212.    ArrayInsert(KOrig,Line,1)
  213.  
  214.  
  215.    Orig[Line] = St
  216.    KOrig[Line] = KeyString(CleanINILine(Orig[Line]))
  217. EndProc
  218.  
  219.  
  220. ;----- Change a line, 0 for line number adds line
  221.  
  222. Procedure ChangeOrAddLine (St,Line)
  223. var Original
  224.    if Line = 0
  225.  
  226.       ;- add new line
  227.  
  228.       if CurrentSection > 0
  229.  
  230.          if GroupMode
  231.             St = 'Group' + Str(NextGroup) + '=' + RightOfEqual(St)
  232.          endif
  233.  
  234.          ;- Determine Insert Position
  235.  
  236.          if InsertPos = 0
  237.             Line = BlockEndIndex[CurrentSection] + 1
  238.             InsertLine(St,Line)
  239.             AdjustLineIndex(Line,1)
  240.          else
  241.             Line = InsertPos
  242.             InsertPos = 0
  243.             InsertLine(St,Line)
  244.             AdjustLineIndex(Line,1)
  245.          endif
  246.  
  247.          LogEvent '    Added: ' St
  248.       endif
  249.    else
  250.  
  251.       ;- change line
  252.  
  253.       Original = Orig[Line]
  254.       if InsertPos > 0
  255.  
  256.          ;- move the line
  257.  
  258.          Delete(Orig,Line,1)
  259.          Delete(KOrig,Line,1)
  260.          Line = InsertPos
  261.  
  262.          InsertLine(St,Line)
  263.          InsertPos = 0
  264.       endif
  265.  
  266.       if GroupMode
  267.          St = LeftOfEqual(Orig[Line]) + RightOfEqual(St)
  268.       endif
  269.  
  270.       if St <> Original
  271.          LogEvent '  Changed: ' Original ' to ' St
  272.          Orig[Line] = St
  273.          KOrig[Line] = KeyString(CleanIniLine(Orig[Line]))
  274.       endif
  275.    endif
  276. EndProc
  277.  
  278.  
  279. Procedure SetSectionInfo
  280.    InsertPos = 0
  281.    if CurrentSection = 0
  282.       ThisSection = ''
  283.       GroupSection = False
  284.       SectionStart = 0
  285.       SectionEnd = 0
  286.    else
  287.       ThisSection = NameIndex[CurrentSection]
  288.       SectionStart = BlockStartIndex[CurrentSection]
  289.       SectionEnd   = BlockEndIndex[CurrentSection]
  290.       GroupSection = (ThisSection = '[GROUPS]') or (ThisSection = '[NETMENU]')
  291.       HashLevel = 2
  292.       Loop GlobalDups
  293.          Hash(LoopVal + ThisSection) = True
  294.       EndLoop
  295.       HashLevel = 1
  296.    endif
  297. EndProc
  298.  
  299.  
  300. Procedure FindSection (St)
  301.    if NeedsIndexing then IndexFile
  302.    CurrentSection = PosInList(St,NameIndex)
  303.    SetSectionInfo
  304. EndProc
  305.  
  306.  
  307. Procedure AddSection (St)
  308. var Lines Proc
  309.    Proc = CleanIniLine(St)
  310.  
  311.    ;- Add a blank line
  312.  
  313.    AppendArray(Orig,'')
  314.    AppendArray(KOrig,'')
  315.  
  316.    ;- Add CurrentSection header
  317.  
  318.    AppendArray(Orig,St)
  319.    AppendArray(KOrig,Proc)
  320.  
  321.    ;- Update Indexes
  322.  
  323.    Lines = NumberOfElements(Orig)
  324.    AppendArray(NameIndex,Proc)
  325.    AppendArray(BlockStartIndex,Lines + 1)
  326.    AppendArray(BlockEndIndex,Lines + 1)
  327.  
  328.    ;- Make new CurrentSection the current CurrentSection
  329.  
  330.    CurrentSection = NumberOfElements(NameIndex)
  331.    SetSectionInfo
  332.  
  333.    if Logging
  334.       LogGroup = UpperCase(St)
  335.       LogEvent ''
  336.       LogEvent LogGroup ' -*- Section Added'
  337.    endif
  338.  
  339. EndProc
  340.  
  341.  
  342. Procedure DelSection (St)
  343. var S E D
  344.    FindSection(St)
  345.    if CurrentSection = 0 then Return
  346.  
  347.    S = BlockStartIndex[CurrentSection] - 1
  348.    E = BlockEndIndex[CurrentSection]
  349.    D = E - S + 1
  350.  
  351.    delete(Orig,S,D)
  352.    delete(KOrig,S,D)
  353.  
  354.    delete(NameIndex,CurrentSection,1)
  355.    delete(BlockStartIndex,CurrentSection,1)
  356.    delete(BlockEndIndex,CurrentSection,1)
  357.  
  358.    CurrentSection = 0
  359.    AdjustLineIndex(S,0 - D)
  360.    SetSectionInfo
  361.  
  362.    if Logging
  363.       LogGroup = ''
  364.       LogEvent ''
  365.       LogEvent UpperCase(St) ' -*- Section Deleted'
  366.    endif
  367.  
  368. EndProc
  369.  
  370.  
  371. Procedure FindLine (St)
  372.    Return PosInList(KeyString(St),KOrig,SectionStart,SectionEnd)
  373. EndProc
  374.  
  375.  
  376. ;----- Replaces text in block from the list of substitute text.
  377.  
  378. Procedure ApplySubstBlock (SubF,SubR,S,E)
  379. var P St
  380.    if NumberOfElements(SubF) = 0 then Return
  381.    while S <= E
  382.       Loop SubF
  383.  
  384.          St = Orig[S]
  385.          Substitute(Orig[S],SubF[LoopIndex],SubR[LoopIndex])
  386.          if St <> Orig[S] then ChangeOrAddLine(Orig[S],S)
  387.  
  388.       EndLoop
  389.       S = S + 1
  390.    endwhile
  391.    dispose(SubFind)
  392.    dispose(SubReplace)
  393. EndProc
  394.  
  395.  
  396. Procedure ApplySubst
  397.    if CurrentSection = 0 then Return
  398.    ApplySubstBlock(SubFind,SubReplace,BlockStartIndex[CurrentSection],BlockEndIndex[CurrentSection])
  399.    ApplySubstBlock(SubFindG,SubReplaceG,BlockStartIndex[CurrentSection],BlockEndIndex[CurrentSection])
  400. EndProc
  401.  
  402.  
  403. Procedure NextGroup
  404. var X S E St Match
  405.    GroupAdded = True
  406.    GroupSectionNumber = CurrentSection
  407.    X = 1
  408.    repeat
  409.       S = BlockStartIndex[CurrentSection]
  410.       E = BlockEndIndex[CurrentSection]
  411.       Match = False
  412.       while (S <= E) and not Match
  413.          St = 'GROUP' + Str(X)
  414.          Match = pos(St,CleanIniLine(Orig[S])) > 0
  415.          S = S + 1
  416.       endwhile
  417.       if not Match then Return X
  418.       X = X + 1
  419.    Forever
  420. EndProc
  421.  
  422.  
  423. Procedure SetOrderLine
  424. var St Order
  425.    Loop BlockStartIndex[GroupSectionNumber] BlockEndIndex[GroupSectionNumber] Orig
  426.       St = UpperCase(LeftOfEqual(LoopVal))
  427.       if St StartsWith 'GROUP'
  428.          delete(St,1,5)
  429.          delete(St,Length(St),1)
  430.          Order = Order + ' ' + St
  431.       endif
  432.    EndLoop
  433.    Trim(Order)
  434.    FindSection('[SETTINGS]')
  435.    if CurrentSection > 0
  436.       ChangeOrAddLine('Order=' + Order,FindLine('ORDER='))
  437.    endif
  438. EndProc
  439.  
  440.  
  441. Procedure GoodLine (St)
  442. var B
  443.    Return (St StartsWith '[') or (St StartsWith ';') or (St Contains '=')
  444. EndProc
  445.  
  446.  
  447. Procedure RemoveExtraBlankLines
  448. var Tmp
  449.  
  450.    ;- Remove Blank Lines
  451.  
  452.    Trim(Orig)
  453.    Tmp = Orig
  454.    dispose Orig
  455.  
  456.    Loop Tmp
  457.       if LoopVal > ''
  458.          TrimTrail(LoopVal)
  459.          AppendArray(Orig,LoopVal)
  460.       endif
  461.    EndLoop
  462.  
  463.    ;- Remove Junk Lines
  464.  
  465.    if CleanNoEquals
  466.       Tmp = Orig
  467.       dispose Orig
  468.       Loop Tmp
  469.          if GoodLine(LoopVal)
  470.             AppendArray(Orig,LoopVal)
  471.          endif
  472.       EndLoop
  473.    endif
  474.  
  475.    ;- Remove Empty Sections
  476.  
  477.    if CleanEmptySections
  478.       Tmp = Orig
  479.       dispose Orig
  480.       Loop Tmp
  481.          if not (LoopVal StartsWith '[') or not (Tmp[LoopIndex + 1] StartsWith '[')
  482.             AppendArray(Orig,LoopVal)
  483.          endif
  484.       EndLoop
  485.    endif
  486.  
  487.    Tmp = Orig
  488.    dispose Orig
  489.    Loop Tmp
  490.       if LoopIndex > 1
  491.          if LoopVal StartsWith '['
  492.             AppendArray(Orig,'')
  493.          endif
  494.       endif
  495.       AppendArray(Orig,LoopVal)
  496.    EndLoop
  497. EndProc
  498.  
  499.  
  500. Procedure AddItem (Line)
  501. var St List New UNew NewLine Next UNext
  502.    St = CleanIniLine(Orig[Line])
  503.    New = RightOfEqual(Changes[LoopIndex])
  504.    UNew = RightOfEqual(UChanges[LoopIndex])
  505.    St = RightOfEqual(St)
  506.    NewLine = Orig[Line]
  507.    while St > ''
  508.       AppendArray(List,NextWordDelim(St,StDelim))
  509.    endwhile
  510.    while UNew > ''
  511.       Next = NextWordDelim(New,StDelim);
  512.       UNext = NextWordDelim(UNew,StDelim);
  513.       if PosInList(UNext,List) = 0
  514.          NewLine = NewLine + ' ' + Next
  515.       endif
  516.    endwhile
  517.    TrimTrail(NewLine)
  518.  
  519.    ;- delete double spaces
  520.  
  521.    while pos('  ',NewLine) > 0
  522.       Delete(NewLine,pos('  ',NewLine),1)
  523.    endwhile
  524.  
  525.    ;- delete space after =
  526.  
  527.    if pos('= ',NewLine) > 0
  528.       Delete(NewLine,pos('= ',NewLine)+1,1)
  529.    endif
  530.  
  531.    ChangeOrAddLine(NewLine,Line)
  532. EndProc
  533.  
  534.  
  535. Procedure DelItem (Line)
  536. var St List New UNew NewLine Next UNext P
  537.    St = CleanIniLine(Orig[Line])
  538.    UNew = RightOfEqual(UChanges[LoopIndex])
  539.    St = St + ' '
  540.    NewLine = Orig[Line]
  541.    while UNew > ''
  542.       UNext = NextWordDelim(UNew,StDelim);
  543.       P = pos(UNext + ' ',St)
  544.       if P > 0
  545.          delete(St,P,length(UNext) + 1)
  546.          delete(NewLine,P,length(UNext) + 1)
  547.       endif
  548.    endwhile
  549.    TrimTrail(NewLine)
  550.  
  551.    ;- delete double spaces
  552.  
  553.    while pos('  ',NewLine) > 0
  554.       Delete(NewLine,pos('  ',NewLine),1)
  555.    endwhile
  556.  
  557.    ;- delete space after =
  558.  
  559.    if pos('= ',NewLine) > 0
  560.       Delete(NewLine,pos('= ',NewLine)+1,1)
  561.    endif
  562.  
  563.    ChangeOrAddLine(NewLine,Line)
  564. EndProc
  565.  
  566.  
  567. Procedure TrailEqu (St)
  568.    if St contains '='
  569.       Return St
  570.    else
  571.       Return St + '='
  572.    endif
  573. EndProc
  574.  
  575.  
  576. Procedure OpenLog (RestOfLine)
  577. var LogFileName
  578.    LogFileName = RestOfLine
  579.    if LogFileName = ''
  580.       LogFileName = ForceExtension(IniFileName,'LOG')
  581.    endif
  582.    LogFileName = DefaultExtension(LogFileName,'LOG')
  583.    FileAssign(LogHandle,LogFileName)
  584.    LogFirstLine
  585.    Logging
  586. EndProc
  587.  
  588.  
  589. Procedure ChangeFile
  590. var St New Line Tmp FirstWord RestOfLine LogFileName X Y FileName
  591.    Loop Changes
  592.  
  593.  
  594.       #If not MarxErrors
  595.  
  596.       ErrorLineNumber = LoopIndex
  597.  
  598.       #Endif
  599.  
  600.       New = LoopVal
  601.       St = UChanges[LoopIndex]
  602.       if St > ''
  603.  
  604.          RestOfLine = St
  605.          FirstWord = NextWordDelim(RestOfLine,'')
  606.          if Hash(FirstWord)
  607.             St = RestOfLine
  608.             Tmp = NextWordDelim(New,StDelim)
  609.  
  610.             if CurrentSection = 0
  611.                if FirstWord = 'TESTMODE'
  612.                   TestMode
  613.  
  614.                elseif FirstWord = 'LOG'
  615.                   OpenLog(RestOfLine)
  616.                   FileCreate(LogHandle)
  617.  
  618.                elseif FirstWord = 'APPENDLOG'
  619.                   OpenLog(RestOfLine)
  620.                   FileAppend(LogHandle)
  621.  
  622.                elseif FirstWord = 'NOBACKUP'
  623.                   NoBackup = True
  624.  
  625.                elseif FirstWord = 'CLEANNOEQUALS'
  626.                   CleanNoEquals = True
  627.  
  628.                elseif FirstWord = 'CLEANEMPTYSECTIONS'
  629.                   CleanEmptySections = True
  630.  
  631.                elseif FirstWord = 'YAK'
  632.                   if not Quiet
  633.                      Writeln
  634.                      Yak = True
  635.                   endif
  636.  
  637.                elseif FirstWord = 'BACKUPNAME'
  638.                   BackupName = Uppercase(NextWordDelim(RestOfLine,StDelim))
  639.                   if BackupName StartsWith '*.'
  640.                      BackupExtension = BackupName
  641.                      delete(BackupExtension,1,2)
  642.                      BackupName = ''
  643.                   endif
  644.  
  645.                elseif FirstWord = 'DUPLICATES'
  646.                   if RightOfEqual(RestOfLine) = '[*]'
  647.                      AppendArray(GlobalDups,LeftOfEqual(RestOfLine))
  648.                   else
  649.                      HashLevel = 2
  650.                      Hash(RestOfLine) = True
  651.                      HashLevel = 1
  652.                   endif
  653.                   LoopVal = ''
  654.                   UChanges[LoopIndex] = ''
  655.  
  656.                endif
  657.             endif
  658.  
  659.             if FirstWord = 'DEL'
  660.                if RestOfLine StartsWith '['
  661.                   ApplySubst
  662.                   DelSection(RestOfLine)
  663.                else
  664.                   RestOfLine = TrailEqu(RestOfLine)
  665.                   DelLine(FindLine(RestOfLine))
  666.                endif
  667.  
  668.             elseif FirstWord = 'ADD'
  669.                Line = FindLine(St)
  670.                if Line = 0
  671.                   ChangeOrAddLine(New,0)
  672.                endif
  673.  
  674.             elseif FirstWord = 'CHANGE'
  675.                Line = FindLine(St)
  676.                if Line > 0
  677.                   ChangeOrAddLine(New,Line)
  678.                endif
  679.  
  680.             elseif FirstWord = 'ADDVALUE'
  681.                Line = FindLine(St)
  682.                if Line > 0
  683.                   X = Value(RightOfEqual(New)) + Value(RightOfEqual(Orig[Line]))
  684.                   Tmp = LeftOfEqual(New)
  685.                   ChangeOrAddLine(Tmp + Str(X),Line)
  686.                endif
  687.  
  688.             elseif FirstWord = 'ADDITEM'
  689.                Line = FindLine(St)
  690.                if Line > 0
  691.                   AddItem(Line,St)
  692.                else
  693.                   ChangeOrAddLine(New,0)
  694.                endif
  695.  
  696.             elseif FirstWord = 'DELITEM'
  697.                Line = FindLine(St)
  698.                if Line > 0
  699.                   DelItem(Line,St)
  700.                endif
  701.  
  702.             elseif FirstWord = 'SUBST'
  703.                if CurrentSection = 0
  704.                   AppendArray(SubFindG,CleanIniLine(NextWordDelim(St,StDelim)))
  705.                   Tmp = NextWordDelim(New,StDelim)
  706.                   AppendArray(SubReplaceG,NextWordDelim(New,StDelim))
  707.                else
  708.                   AppendArray(SubFind,CleanIniLine(NextWordDelim(St,StDelim)))
  709.                   Tmp = NextWordDelim(New,StDelim)
  710.                   AppendArray(SubReplace,NextWordDelim(New,StDelim))
  711.                endif
  712.  
  713.             elseif FirstWord = 'BEFORE'
  714.                St = TrailEqu(St)
  715.                InsertPos = FindLine(St)
  716.  
  717.             elseif FirstWord = 'AFTER'
  718.                St = TrailEqu(St)
  719.                X = FindLine(St)
  720.                if X > 0 then InsertPos = succ(X)
  721.  
  722.             elseif FirstWord = 'FIRST'
  723.                InsertPos = BlockStartIndex[CurrentSection]
  724.  
  725.             endif
  726.  
  727.          else
  728.  
  729.             ;- Process Sections
  730.  
  731.             if St StartsWith '['
  732.  
  733.                ;- New Group
  734.  
  735.                ApplySubst
  736.                FindSection(St)
  737.                if CurrentSection = 0
  738.                   AddSection(LoopVal)
  739.                endif
  740.  
  741.             else
  742.  
  743.                ;- Process Lines
  744.  
  745.                ChangeOrAddLine(New,Findline(St))
  746.  
  747.             endif
  748.  
  749.          endif
  750.       endif
  751.       IfLine = IfArray[LoopIndex]
  752.       if IfLine > ''
  753.          Interpret
  754.          if NumberOfElements Stack <> 0
  755.             Error ('Too Many Parameters!',LoopIndex)
  756.          endif
  757.       endif
  758.       if ExitFlag then LoopIndex = LoopLimit
  759.    EndLoop
  760.    ApplySubst
  761.    ApplySubstBlock(SubFindG,SubReplaceG,1,NumberOfElements(Orig))
  762.    if GroupAdded then SetOrderLine
  763. EndProc
  764.  
  765.  
  766. Procedure Help
  767. var Help HelpFile St
  768.    St = ForceExtension(FilePart(MenuFileName),'HLP')
  769.    HelpFile = ExistOnPath(St)
  770.    if HelpFile = ''
  771.       St = ForceExtension(FilePart(MenuFileName),'TXT')
  772.       HelpFile = ExistOnPath(St)
  773.    endif
  774. {   Writeln
  775.    if HelpFile > ''
  776.       BoxHeader ' Viewing ' + HelpFile + ' '
  777.       DrawBox 1 1 ScreenWidth ScreenHeight
  778.       ViewTextFile(HelpFile)
  779.    endif}
  780.    StandardIO
  781.    Writeln ProgName ' * Version 2.52 * Release Date: 01-18-95'
  782.  
  783.    #If McAfee
  784.       Writeln
  785.       Writeln 'Copyright 1994-96 by McAfee Inc. (408) 988-3832'
  786.       Writeln 'Copyright 1993-96 by Computer Tyme Inc. (417) 866-1222'
  787.       Writeln
  788.       Writeln 'Computer Tyme BBS: 417-866-1665'
  789.       Writeln
  790.       Writeln 'Licensed to McAfee Inc. from Computer Tyme Inc.'
  791.       Writeln 'All Rights Reserved'
  792.    #Else
  793.       Writeln 'Copyright 1993-96 by Marc Perkel * All Rights Reserved'
  794.       Include 'ADDRESS.INC'
  795.    #Endif
  796.  
  797.    Writeln 'For help, read the file: ' HelpFile
  798.  
  799.    ExitMenu
  800. EndProc
  801.  
  802.  
  803. #If Shareware
  804. {
  805. Procedure Beg
  806.    BoxHeader ' * Shameless Beg Screen * '
  807.    DrawBox 10 8 61 6
  808.    Writeln
  809.  
  810.    #If McAfee
  811.       WriteCenter '* IniTool Evaluation Copy *'
  812.    #Else
  813.       WriteCenter '* IniTyme Evaluation Copy *'
  814.    #Endif
  815.  
  816.    Writeln
  817.    WriteCenter 'Please remember to register this software.'
  818.    Wait 600
  819.    EraseTopWindow
  820.    ClearKbdBuffer
  821. EndProc
  822. }
  823.  
  824. Procedure Beg
  825.    WritelnError
  826.  
  827.    #If McAfee
  828.       WritelnError '* IniTool Evaluation Copy *'
  829.    #Else
  830.       WritelnError '* IniTyme Evaluation Copy *'
  831.    #Endif
  832.  
  833.    WritelnError
  834.    WritelnError 'Please remember to register this software.'
  835.    WritelnError
  836.    ClearKbdBuffer
  837. EndProc
  838.  
  839.  
  840. #Endif
  841.  
  842. Procedure TestFreeMemory
  843.    if FreeMemory < 10000
  844.       Error('Not Enough Free Memory!',0)
  845.    endif
  846. EndProc
  847.  
  848.  
  849. Procedure Error (St,Line)
  850.    StandardIO
  851.    Writeln
  852.    if Line > 0
  853.       Writeln ProgName ' Error in line ' Line
  854.       Writeln St
  855.    else
  856.       Writeln ProgName ' Error: ' St
  857.    endif
  858.    ExitCode = 1
  859.    ExitMenu
  860. EndProc
  861.  
  862.  
  863. ;----- INITYME.INC has the conditional logic.
  864.  
  865. Include 'INITYME.INC'
  866.  
  867.  
  868. Procedure LookForCtlFile (Name)
  869. var St
  870.  
  871.    ;- IniTools Names
  872.  
  873.    Name = ForceExtension(Name,'CTL')
  874.    St = ExistOnPath(Name)
  875.    if St > '' then Return St
  876.  
  877.    St = CleanFileName(%CTLDIR% + '\' + Name)
  878.    if ExistFile (St) then Return St
  879.  
  880.    ;- IniMan Names
  881.  
  882.    Name = ForceExtension(Name,'DEF')
  883.    St = ExistOnPath(Name)
  884.    if St > '' then Return St
  885.  
  886.    St = CleanFileName(%S_CONFIG% + '\' + Name)
  887.    if ExistFile (St) then Return St
  888.  
  889.    Return ''
  890. EndProc
  891.  
  892.  
  893. Procedure ProcessChangeFile
  894. var St P
  895.    ReadTextFile(ChangeFileName,Changes)
  896.  
  897.    Loop Changes
  898.       Trim(LoopVal)
  899.       LoopVal = EnvExpandString(LoopVal)
  900.       UChanges[LoopIndex] = CleanIniLine(LoopVal)
  901.    EndLoop
  902.  
  903.    Loop UChanges
  904.  
  905.       if LoopVal StartsWith 'IF '
  906.          IfArray[LoopIndex] = LoopVal
  907.          LoopVal = ''
  908.          Changes[LoopIndex] = ''
  909.          PushStack(LoopIndex)
  910.  
  911.       elseif LoopVal StartsWith 'WRITE '
  912.          IfArray[LoopIndex] = LoopVal
  913.          LoopVal = ''
  914.          Changes[LoopIndex] = ''
  915.  
  916.       elseif LoopVal StartsWith 'WRITELN '
  917.          IfArray[LoopIndex] = LoopVal
  918.          LoopVal = ''
  919.          Changes[LoopIndex] = ''
  920.  
  921.       elseif LoopVal StartsWith '**'
  922.  
  923.          ;================= IniMan Code Begins ==================
  924.  
  925.          delete(LoopVal,1,2)
  926.          St = LoopVal
  927.          St = NextWordDelim(St,'=')
  928.  
  929.          if St = 'BEGIN'
  930.             LoopVal = ''
  931.  
  932.          elseif St = 'END'
  933.             LoopVal = ''
  934.  
  935.          elseif St = 'REV'   ;- Not Supported
  936.             LoopVal = ''
  937.  
  938.          elseif St = 'ELSE'
  939.             IfArray[LoopIndex] = 'GOTO'
  940.             P = 0
  941.             Loop LoopIndex + 2 LoopLimit UChanges
  942.  
  943.                ;- Search forward for END
  944.  
  945.                if LoopVal = '**END'
  946.                   P = LoopIndex
  947.                   LoopIndex = LoopLimit
  948.                endif
  949.             EndLoop
  950.             if P > 0
  951.                GotoList[LoopIndex] = P
  952.             else
  953.                P = LoopLimit
  954.             endif
  955.  
  956.          elseif HashExist('!' + St)   ;= Iniman Conditional Keyword
  957.  
  958.             LoopVal = 'IF ' + LoopVal
  959.             IfArray[LoopIndex] = LoopVal
  960.             P = 0
  961.  
  962.             if UChanges[LoopIndex + 1] = '**BEGIN'
  963.                Loop LoopIndex + 2 LoopLimit UChanges
  964.  
  965.                   ;- Search forward for END
  966.  
  967.                   if LoopVal = '**END'
  968.                      P = LoopIndex
  969.                      LoopIndex = LoopLimit
  970.  
  971.                   elseif LoopVal = '**ELSE'
  972.                      P = LoopIndex
  973.                      LoopIndex = LoopLimit
  974.  
  975.                   endif
  976.                EndLoop
  977.                if P = 0 then P = LoopLimit
  978.                GotoList[LoopIndex] = P
  979.  
  980.             elseif UChanges[LoopIndex + 1] StartsWith '['
  981.  
  982.                ;- Conditional applies to section
  983.  
  984.                Loop LoopIndex + 2 LoopLimit UChanges
  985.  
  986.                   ;- Search forward for next [Section]
  987.  
  988.                   if LoopVal StartsWith '['
  989.                      P = LoopIndex
  990.                      LoopIndex = LoopLimit
  991.                   endif
  992.                EndLoop
  993.  
  994.                if P = 0
  995.                   P = LoopLimit
  996.                else
  997.  
  998.                   ;- back up to end of section
  999.  
  1000.                   P = P - 1
  1001.                   while UChanges[P] StartsWith '**'
  1002.                      P = P - 1
  1003.                   endwhile
  1004.                endif
  1005.  
  1006.                GotoList[LoopIndex] = P
  1007.  
  1008.             else
  1009.                GotoList[LoopIndex] = LoopIndex + 1
  1010.             endif
  1011.  
  1012.          endif
  1013.  
  1014.          LoopVal = ''
  1015.          Changes[LoopIndex] = ''
  1016.  
  1017.          ;================= IniMan Code Ends ==================
  1018.  
  1019.       elseif LoopVal = 'ENDIF'
  1020.          LoopVal = ''
  1021.          Changes[LoopIndex] = ''
  1022.          GotoList[PopStack] = LoopIndex
  1023.  
  1024.       elseif LoopVal = 'ELSE'
  1025.          LoopVal = ''
  1026.          Changes[LoopIndex] = ''
  1027.          IfArray[LoopIndex] = 'GOTO'
  1028.          GotoList[PopStack] = LoopIndex
  1029.          PushStack(LoopIndex)
  1030.  
  1031.       endif
  1032.  
  1033.    EndLoop
  1034.  
  1035.    ;-- if you forgot an Endif then the stack contains values.
  1036.  
  1037.    if NumberOfElements Stack <> 0
  1038.       Error ('MisMatched Conditionals!',0)
  1039.    endif
  1040.  
  1041. EndProc
  1042.  
  1043.  
  1044. Procedure Setup
  1045. var St
  1046.    TestFreeMemory
  1047.  
  1048.    UpperCaseCompare On
  1049.    StDelim = ',"' + "'"
  1050.  
  1051.    BlankTime = 0
  1052.    BoxBorderColor Green Blue
  1053.    BoxInsideColor White Blue
  1054.    BoxHeaderColor Yellow Mag
  1055.  
  1056.    #If Shareware
  1057.       Beg
  1058.    #Endif
  1059.  
  1060.    Quiet = OptionSwitch(CmdLine,'Q')
  1061.    BackupExtension = 'BNI'
  1062.    FirstProcessFile = True
  1063.    ChangeFileName = UpperCase(ParamStr(2))
  1064.    IniFileName = UpperCase(ParamStr(3))
  1065.  
  1066.    #If McAfee
  1067.       ProgName = 'IniTool'
  1068.    #Else
  1069.       ProgName = 'IniTyme'
  1070.    #Endif
  1071.  
  1072.    ExitCode = 0
  1073.  
  1074.    RestoreMode = ChangeFileName = 'RESTORE'
  1075.  
  1076.    if (IniFileName = '')
  1077.       IniFileName = DefaultExtension(ChangeFileName,'INI')
  1078.       ChangeFileName = LookForCtlFile(ChangeFileName)
  1079.    else
  1080.       if ChangeFileName > ''
  1081.          if Extension ChangeFileName = ''
  1082.             St = ForceExtension(ChangeFileName,'INI')
  1083.             if ExistFile St
  1084.                ChangeFileName = St
  1085.             else
  1086.                ChangeFileName = LookForCtlFile(ChangeFileName)
  1087.             endif
  1088.          endif
  1089.       endif
  1090.    endif
  1091.  
  1092.    if not RestoreMode and (ChangeFileName = '')
  1093.       if ParamStr(2) = ''
  1094.          Help
  1095.       else
  1096.          Error('File not Found: ' + CleanFileName(ParamStr(2)))
  1097.       endif
  1098.    endif
  1099.  
  1100.    StandardIO
  1101.  
  1102.    if RestoreMode then Return
  1103.  
  1104.    ;-- Duplicates List - Add your own duplicates here.
  1105.  
  1106.    HashLevel = 1
  1107.    Hash('DEVICE=[386ENH]') = True
  1108.  
  1109.    if not Quiet then Writeln 'Processing Change File: ' ChangeFileName ' ...'
  1110.  
  1111.    SetupLibWords
  1112.    ProcessChangeFile
  1113.  
  1114.    Hash('ADD') = True
  1115.    Hash('ADDITEM') = True
  1116.    Hash('ADDVALUE') = True
  1117.    Hash('AFTER') = True
  1118.    Hash('APPENDLOG') = True
  1119.    Hash('BACKUPNAME') = True
  1120.    Hash('BEFORE') = True
  1121.    Hash('CHANGE') = True
  1122.    Hash('CLEANEMPTYSECTIONS') = True
  1123.    Hash('CLEANNOEQUALS') = True
  1124.    Hash('DEL') = True
  1125.    Hash('DELITEM') = True
  1126.    Hash('DUPLICATES') = True
  1127.    Hash('FIRST') = True
  1128.    Hash('LOG') = True
  1129.    Hash('NOBACKUP') = True
  1130.    Hash('SUBST') = True
  1131.    Hash('TESTMODE') = True
  1132.    Hash('YAK') = True
  1133.  
  1134.    TestFreeMemory
  1135.  
  1136.    #If not MarxErrors
  1137.  
  1138.    ErrorLineName = ChangeFileName
  1139.  
  1140.    #Endif
  1141.  
  1142. EndProc
  1143.  
  1144.  
  1145. Procedure ResetVariables
  1146.    dispose(NameIndex)
  1147.    dispose(BlockStartIndex)
  1148.    dispose(BlockEndIndex)
  1149.    dispose(SubFind)
  1150.    dispose(SubReplace)
  1151.    dispose(SubFindG)
  1152.    dispose(SubReplaceG)
  1153.    dispose(GlobalDups)
  1154.    HashDisposeLevel(2)
  1155.    LogGroup = ''
  1156.    CurrentSection = 0
  1157.    BackupName = ''
  1158.    BackupExtension = 'BNI'
  1159. EndProc
  1160.  
  1161.  
  1162. Procedure BackName
  1163.    if BackupName > '' then Return BackupName
  1164.    Return ForceExtension(IniFileName,BackupExtension)
  1165. EndProc
  1166.  
  1167.  
  1168. Procedure TestFileResult (Name)
  1169. var Err
  1170.    if FileResult = 0 then Return
  1171.    if FileResult = 5
  1172.       Error('File Access Error in ' + Name + ': Access Denied',0)
  1173.    else
  1174.       Error('File Access Error: ' + Str(FileResult) + ' in ' + Name,0)
  1175.    endif
  1176. EndProc
  1177.  
  1178.  
  1179. Procedure ProcessFile (Name)
  1180. var FileList MultiFile X
  1181.    if InputRedirected and FirstProcessFile
  1182.       IniFileName = ''
  1183.    else
  1184.       IniFileName = DefaultExtension(Name,'INI')
  1185.    endif
  1186.    FirstProcessFile = False
  1187.    ReadTextFile(IniFileName,Orig)
  1188.    TestFreeMemory
  1189.    if NumberOfElements Orig > 0
  1190.  
  1191.       ;- Loop Past Comments and blank lines
  1192.  
  1193.       X = 1
  1194.       while (X < NumberOfElements(Orig)) and ((Orig[X] StartsWith ';') or (Orig[X] = ''))
  1195.          X = X + 1
  1196.       endwhile
  1197.  
  1198.       if ExistFile(Orig[X])
  1199.          MultiFile = True
  1200.          FileList = Orig
  1201.          Loop FileList
  1202.             if LoopVal StartsWith ';' then LoopVal = ''
  1203.             if LoopVal > ''
  1204.                ProcessFile(LoopVal)
  1205.             endif
  1206.          EndLoop
  1207.       endif
  1208.    endif
  1209.    if not MultiFile
  1210.       if RestoreMode
  1211.          if ExistFile(BackName)
  1212.             Writeln 'Restoring ' IniFileName
  1213.             DelFile(ForceExtension(IniFileName,'BAK'))
  1214.             FileRename(IniFileName,ForceExtension(IniFileName,'BAK'))
  1215.             FileRename(BackName,IniFileName)
  1216.             TestFileResult(BackName)
  1217.          else
  1218.             Writeln BackName ' not Found!'
  1219.          endif
  1220.       else
  1221.          DsFileName = PathPart(IniFileName) + '\DS' + Str(NovConnection)
  1222.          DsFileName = CleanFileName(DsFileName + '.$$$')
  1223.          ResetVariables
  1224.          if not Quiet then Writeln 'Converting INI File: ' IniFileName ' '
  1225.          NeedsIndexing
  1226.          ChangeFile
  1227.          RemoveExtraBlankLines
  1228.  
  1229.          if TestMode
  1230.             WriteTextFile(BackName,Orig)
  1231.             TestFileResult(BackName)
  1232.          else
  1233.             DelFile(BackName)
  1234.             FileRename(IniFileName,BackName)
  1235.             WriteTextFile(IniFileName,Orig)
  1236.             TestFileResult(IniFileName)
  1237.          endif
  1238.  
  1239.          if NoBackup and not TestMode
  1240.             DelFile(BackName)
  1241.          endif
  1242.  
  1243.          if Logging
  1244.             FileClose(LogHandle)
  1245.             Logging Off
  1246.          endif
  1247.  
  1248.          if Yak then Writeln
  1249.       endif
  1250.    endif
  1251. ;   Writeln(FreeMemory)
  1252. EndProc
  1253.  
  1254.  
  1255. Procedure Main
  1256.    Setup
  1257.    ProcessFile(IniFileName)
  1258. EndProc
  1259.