home *** CD-ROM | disk | FTP | other *** search
/ Hackers Magazine 57 / CdHackersMagazineNr57.iso / Software / Programming / nsis-2.46-setup.exe / Include / TextFunc.nsh < prev    next >
Encoding:
Text File  |  2008-12-20  |  23.8 KB  |  1,215 lines

  1. /*
  2. _____________________________________________________________________________
  3.  
  4.                        Text Functions Header v2.4
  5. _____________________________________________________________________________
  6.  
  7.  2006 Shengalts Aleksander aka Instructor (Shengalts@mail.ru)
  8.  
  9.  See documentation for more information about the following functions.
  10.  
  11.  Usage in script:
  12.  1. !include "TextFunc.nsh"
  13.  2. [Section|Function]
  14.       ${TextFunction} "File" "..."  $var
  15.     [SectionEnd|FunctionEnd]
  16.  
  17.  
  18.  TextFunction=[LineFind|LineRead|FileReadFromEnd|LineSum|FileJoin|
  19.                TextCompare|TextCompareS|ConfigRead|ConfigReadS|
  20.                ConfigWrite|ConfigWriteS|FileRecode|TrimNewLines]
  21.  
  22. _____________________________________________________________________________
  23.  
  24.                        Thanks to:
  25. _____________________________________________________________________________
  26.  
  27. LineRead
  28.     Afrow UK (Based on his idea of Function "ReadFileLine")
  29. LineSum
  30.     Afrow UK (Based on his idea of Function "LineCount")
  31. FileJoin
  32.     Afrow UK (Based on his idea of Function "JoinFiles")
  33. ConfigRead
  34.     vbgunz (His idea)
  35. ConfigWrite
  36.     vbgunz (His idea)
  37. TrimNewLines
  38.     sunjammer (Based on his Function "TrimNewLines")
  39. */
  40.  
  41.  
  42. ;_____________________________________________________________________________
  43. ;
  44. ;                                   Macros
  45. ;_____________________________________________________________________________
  46. ;
  47. ; Change log window verbosity (default: 3=no script)
  48. ;
  49. ; Example:
  50. ; !include "TextFunc.nsh"
  51. ; !insertmacro LineFind
  52. ; ${TEXTFUNC_VERBOSE} 4   # all verbosity
  53. ; !insertmacro LineSum
  54. ; ${TEXTFUNC_VERBOSE} 3   # no script
  55.  
  56. !ifndef TEXTFUNC_INCLUDED
  57. !define TEXTFUNC_INCLUDED
  58.  
  59. !include FileFunc.nsh
  60. !include Util.nsh
  61.  
  62. !verbose push
  63. !verbose 3
  64. !ifndef _TEXTFUNC_VERBOSE
  65.     !define _TEXTFUNC_VERBOSE 3
  66. !endif
  67. !verbose ${_TEXTFUNC_VERBOSE}
  68. !define TEXTFUNC_VERBOSE `!insertmacro TEXTFUNC_VERBOSE`
  69. !verbose pop
  70.  
  71. !macro TEXTFUNC_VERBOSE _VERBOSE
  72.     !verbose push
  73.     !verbose 3
  74.     !undef _TEXTFUNC_VERBOSE
  75.     !define _TEXTFUNC_VERBOSE ${_VERBOSE}
  76.     !verbose pop
  77. !macroend
  78.  
  79. !macro LineFindCall _INPUT _OUTPUT _RANGE _FUNC
  80.     !verbose push
  81.     !verbose ${_TEXTFUNC_VERBOSE}
  82.     Push $0
  83.     Push `${_INPUT}`
  84.     Push `${_OUTPUT}`
  85.     Push `${_RANGE}`
  86.     GetFunctionAddress $0 `${_FUNC}`
  87.     Push `$0`
  88.     ${CallArtificialFunction} LineFind_
  89.     Pop $0
  90.     !verbose pop
  91. !macroend
  92.  
  93. !macro LineReadCall _FILE _NUMBER _RESULT
  94.     !verbose push
  95.     !verbose ${_TEXTFUNC_VERBOSE}
  96.     Push `${_FILE}`
  97.     Push `${_NUMBER}`
  98.     ${CallArtificialFunction} LineRead_
  99.     Pop ${_RESULT}
  100.     !verbose pop
  101. !macroend
  102.  
  103. !macro FileReadFromEndCall _FILE _FUNC
  104.     !verbose push
  105.     !verbose ${_TEXTFUNC_VERBOSE}
  106.     Push $0
  107.     Push `${_FILE}`
  108.     GetFunctionAddress $0 `${_FUNC}`
  109.     Push `$0`
  110.     ${CallArtificialFunction} FileReadFromEnd_
  111.     Pop $0
  112.     !verbose pop
  113. !macroend
  114.  
  115. !macro LineSumCall _FILE _RESULT
  116.     !verbose push
  117.     !verbose ${_TEXTFUNC_VERBOSE}
  118.     Push `${_FILE}`
  119.     ${CallArtificialFunction} LineSum_
  120.     Pop ${_RESULT}
  121.     !verbose pop
  122. !macroend
  123.  
  124. !macro FileJoinCall _FILE1 _FILE2 _FILE3
  125.     !verbose push
  126.     !verbose ${_TEXTFUNC_VERBOSE}
  127.     Push `${_FILE1}`
  128.     Push `${_FILE2}`
  129.     Push `${_FILE3}`
  130.     ${CallArtificialFunction} FileJoin_
  131.     !verbose pop
  132. !macroend
  133.  
  134. !macro TextCompareCall _FILE1 _FILE2 _OPTION _FUNC
  135.     !verbose push
  136.     !verbose ${_TEXTFUNC_VERBOSE}
  137.     Push $0
  138.     Push `${_FILE1}`
  139.     Push `${_FILE2}`
  140.     Push `${_OPTION}`
  141.     GetFunctionAddress $0 `${_FUNC}`
  142.     Push `$0`
  143.     ${CallArtificialFunction} TextCompare_
  144.     Pop $0
  145.     !verbose pop
  146. !macroend
  147.  
  148. !macro TextCompareSCall _FILE1 _FILE2 _OPTION _FUNC
  149.     !verbose push
  150.     !verbose ${_TEXTFUNC_VERBOSE}
  151.     Push $0
  152.     Push `${_FILE1}`
  153.     Push `${_FILE2}`
  154.     Push `${_OPTION}`
  155.     GetFunctionAddress $0 `${_FUNC}`
  156.     Push `$0`
  157.     ${CallArtificialFunction} TextCompareS_
  158.     Pop $0
  159.     !verbose pop
  160. !macroend
  161.  
  162. !macro ConfigReadCall _FILE _ENTRY _RESULT
  163.     !verbose push
  164.     !verbose ${_TEXTFUNC_VERBOSE}
  165.     Push `${_FILE}`
  166.     Push `${_ENTRY}`
  167.     ${CallArtificialFunction} ConfigRead_
  168.     Pop ${_RESULT}
  169.     !verbose pop
  170. !macroend
  171.  
  172. !macro ConfigReadSCall _FILE _ENTRY _RESULT
  173.     !verbose push
  174.     !verbose ${_TEXTFUNC_VERBOSE}
  175.     Push `${_FILE}`
  176.     Push `${_ENTRY}`
  177.     ${CallArtificialFunction} ConfigReadS_
  178.     Pop ${_RESULT}
  179.     !verbose pop
  180. !macroend
  181.  
  182. !macro ConfigWriteCall _FILE _ENTRY _VALUE _RESULT
  183.     !verbose push
  184.     !verbose ${_TEXTFUNC_VERBOSE}
  185.     Push `${_FILE}`
  186.     Push `${_ENTRY}`
  187.     Push `${_VALUE}`
  188.     ${CallArtificialFunction} ConfigWrite_
  189.     Pop ${_RESULT}
  190.     !verbose pop
  191. !macroend
  192.  
  193. !macro ConfigWriteSCall _FILE _ENTRY _VALUE _RESULT
  194.     !verbose push
  195.     !verbose ${_TEXTFUNC_VERBOSE}
  196.     Push `${_FILE}`
  197.     Push `${_ENTRY}`
  198.     Push `${_VALUE}`
  199.     ${CallArtificialFunction} ConfigWriteS_
  200.     Pop ${_RESULT}
  201.     !verbose pop
  202. !macroend
  203.  
  204. !macro FileRecodeCall _FILE _FORMAT
  205.     !verbose push
  206.     !verbose ${_TEXTFUNC_VERBOSE}
  207.     Push `${_FILE}`
  208.     Push `${_FORMAT}`
  209.     ${CallArtificialFunction} FileRecode_
  210.     !verbose pop
  211. !macroend
  212.  
  213. !macro TrimNewLinesCall _FILE _RESULT
  214.     !verbose push
  215.     !verbose ${_TEXTFUNC_VERBOSE}
  216.     Push `${_FILE}`
  217.     ${CallArtificialFunction} TrimNewLines_
  218.     Pop ${_RESULT}
  219.     !verbose pop
  220. !macroend
  221.  
  222. !macro _TextFunc_TempFileForFile _FILE _RESULT
  223.     # XXX replace with GetParent
  224.     Push `${_FILE}`
  225.     Exch $0
  226.     Push $1
  227.     Push $2
  228.  
  229.     StrCpy $2 $0 1 -1
  230.     StrCmp $2 '\' 0 +3
  231.     StrCpy $0 $0 -1
  232.     goto -3
  233.  
  234.     StrCpy $1 0
  235.     IntOp $1 $1 - 1
  236.     StrCpy $2 $0 1 $1
  237.     StrCmp $2 '\' +2
  238.     StrCmp $2 '' 0 -3
  239.     StrCpy $0 $0 $1
  240.  
  241.     Pop $2
  242.     Pop $1
  243.     Exch $0
  244.     Pop ${_RESULT}
  245.     # XXX
  246.     StrCmp ${_RESULT} "" 0 +2
  247.         StrCpy ${_RESULT} $EXEDIR
  248.     GetTempFileName ${_RESULT} ${_RESULT}
  249.     StrCmp ${_RESULT} "" 0 +2
  250.         GetTempFileName ${_RESULT}
  251.     ClearErrors
  252. !macroend
  253.  
  254. !define LineFind `!insertmacro LineFindCall`
  255. !define un.LineFind `!insertmacro LineFindCall`
  256.  
  257. !macro LineFind
  258. !macroend
  259.  
  260. !macro un.LineFind
  261. !macroend
  262.  
  263. !macro LineFind_
  264.     !verbose push
  265.     !verbose ${_TEXTFUNC_VERBOSE}
  266.  
  267.     Exch $3
  268.     Exch
  269.     Exch $2
  270.     Exch
  271.     Exch 2
  272.     Exch $1
  273.     Exch 2
  274.     Exch 3
  275.     Exch $0
  276.     Exch 3
  277.     Push $4
  278.     Push $5
  279.     Push $6
  280.     Push $7
  281.     Push $8
  282.     Push $9
  283.     Push $R4
  284.     Push $R5
  285.     Push $R6
  286.     Push $R7
  287.     Push $R8
  288.     Push $R9
  289.     ClearErrors
  290.  
  291.     IfFileExists '$0' 0 TextFunc_LineFind_error
  292.     StrCmp $1 '/NUL' TextFunc_LineFind_begin
  293.     StrCpy $8 0
  294.     IntOp $8 $8 - 1
  295.     StrCpy $9 $1 1 $8
  296.     StrCmp $9 \ +2
  297.     StrCmp $9 '' +3 -3
  298.     StrCpy $9 $1 $8
  299.     IfFileExists '$9\*.*' 0 TextFunc_LineFind_error
  300.  
  301.     TextFunc_LineFind_begin:
  302.     StrCpy $4 1
  303.     StrCpy $5 -1
  304.     StrCpy $6 0
  305.     StrCpy $7 0
  306.     StrCpy $R4 ''
  307.     StrCpy $R6 ''
  308.     StrCpy $R7 ''
  309.     StrCpy $R8 0
  310.  
  311.     StrCpy $8 $2 1
  312.     StrCmp $8 '{' 0 TextFunc_LineFind_delspaces
  313.     StrCpy $2 $2 '' 1
  314.     StrCpy $8 $2 1 -1
  315.     StrCmp $8 '}' 0 TextFunc_LineFind_delspaces
  316.     StrCpy $2 $2 -1
  317.     StrCpy $R6 TextFunc_LineFind_cut
  318.  
  319.     TextFunc_LineFind_delspaces:
  320.     StrCpy $8 $2 1
  321.     StrCmp $8 ' ' 0 +3
  322.     StrCpy $2 $2 '' 1
  323.     goto -3
  324.     StrCmp $2$7 '0' TextFunc_LineFind_file
  325.     StrCpy $4 ''
  326.     StrCpy $5 ''
  327.     StrCmp $2 '' TextFunc_LineFind_writechk
  328.  
  329.     TextFunc_LineFind_range:
  330.     StrCpy $8 0
  331.     StrCpy $9 $2 1 $8
  332.     StrCmp $9 '' +5
  333.     StrCmp $9 ' ' +4
  334.     StrCmp $9 ':' +3
  335.     IntOp $8 $8 + 1
  336.     goto -5
  337.     StrCpy $5 $2 $8
  338.     IntOp $5 $5 + 0
  339.     IntOp $8 $8 + 1
  340.     StrCpy $2 $2 '' $8
  341.     StrCmp $4 '' 0 +2
  342.     StrCpy $4 $5
  343.     StrCmp $9 ':' TextFunc_LineFind_range
  344.  
  345.     IntCmp $4 0 0 +2
  346.     IntCmp $5 -1 TextFunc_LineFind_goto 0 TextFunc_LineFind_growthcmp
  347.     StrCmp $R7 '' 0 TextFunc_LineFind_minus2plus
  348.     StrCpy $R7 0
  349.     FileOpen $8 $0 r
  350.     FileRead $8 $9
  351.     IfErrors +3
  352.     IntOp $R7 $R7 + 1
  353.     Goto -3
  354.     FileClose $8
  355.  
  356.     TextFunc_LineFind_minus2plus:
  357.     IntCmp $4 0 +5 0 +5
  358.     IntOp $4 $R7 + $4
  359.     IntOp $4 $4 + 1
  360.     IntCmp $4 0 +2 0 +2
  361.     StrCpy $4 0
  362.     IntCmp $5 -1 TextFunc_LineFind_goto 0 TextFunc_LineFind_growthcmp
  363.     IntOp $5 $R7 + $5
  364.     IntOp $5 $5 + 1
  365.     TextFunc_LineFind_growthcmp:
  366.     IntCmp $4 $5 TextFunc_LineFind_goto TextFunc_LineFind_goto
  367.     StrCpy $5 $4
  368.     TextFunc_LineFind_goto:
  369.     goto $7
  370.  
  371.     TextFunc_LineFind_file:
  372.     StrCmp $1 '/NUL' TextFunc_LineFind_notemp
  373.     !insertmacro _TextFunc_TempFileForFile $1 $R4
  374.     Push $R4
  375.     FileOpen $R4 $R4 w
  376.     TextFunc_LineFind_notemp:
  377.     FileOpen $R5 $0 r
  378.     IfErrors TextFunc_LineFind_preerror
  379.  
  380.     TextFunc_LineFind_loop:
  381.     IntOp $R8 $R8 + 1
  382.     FileRead $R5 $R9
  383.     IfErrors TextFunc_LineFind_handleclose
  384.  
  385.     TextFunc_LineFind_cmp:
  386.     StrCmp $2$4$5 '' TextFunc_LineFind_writechk
  387.     IntCmp $4 $R8 TextFunc_LineFind_call 0 TextFunc_LineFind_writechk
  388.     StrCmp $5 -1 TextFunc_LineFind_call
  389.     IntCmp $5 $R8 TextFunc_LineFind_call 0 TextFunc_LineFind_call
  390.  
  391.     GetLabelAddress $7 TextFunc_LineFind_cmp
  392.     goto TextFunc_LineFind_delspaces
  393.  
  394.     TextFunc_LineFind_call:
  395.     StrCpy $7 $R9
  396.     Push $0
  397.     Push $1
  398.     Push $2
  399.     Push $3
  400.     Push $4
  401.     Push $5
  402.     Push $6
  403.     Push $7
  404.     Push $R4
  405.     Push $R5
  406.     Push $R6
  407.     Push $R7
  408.     Push $R8
  409.     StrCpy $R6 '$4:$5'
  410.     StrCmp $R7 '' +3
  411.     IntOp $R7 $R8 - $R7
  412.     IntOp $R7 $R7 - 1
  413.     Call $3
  414.     Pop $9
  415.     Pop $R8
  416.     Pop $R7
  417.     Pop $R6
  418.     Pop $R5
  419.     Pop $R4
  420.     Pop $7
  421.     Pop $6
  422.     Pop $5
  423.     Pop $4
  424.     Pop $3
  425.     Pop $2
  426.     Pop $1
  427.     Pop $0
  428.     IfErrors TextFunc_LineFind_preerror
  429.     StrCmp $9 'StopLineFind' 0 +3
  430.     IntOp $6 $6 + 1
  431.     goto TextFunc_LineFind_handleclose
  432.     StrCmp $1 '/NUL' TextFunc_LineFind_loop
  433.     StrCmp $9 'SkipWrite' 0 +3
  434.     IntOp $6 $6 + 1
  435.     goto TextFunc_LineFind_loop
  436.     StrCmp $7 $R9 TextFunc_LineFind_write
  437.     IntOp $6 $6 + 1
  438.     goto TextFunc_LineFind_write
  439.  
  440.     TextFunc_LineFind_writechk:
  441.     StrCmp $1 '/NUL' TextFunc_LineFind_loop
  442.     StrCmp $R6 TextFunc_LineFind_cut 0 TextFunc_LineFind_write
  443.     IntOp $6 $6 + 1
  444.     goto TextFunc_LineFind_loop
  445.  
  446.     TextFunc_LineFind_write:
  447.     FileWrite $R4 $R9
  448.     goto TextFunc_LineFind_loop
  449.  
  450.     TextFunc_LineFind_preerror:
  451.     SetErrors
  452.  
  453.     TextFunc_LineFind_handleclose:
  454.     StrCmp $1 '/NUL' +3
  455.     FileClose $R4
  456.     Pop $R4
  457.     FileClose $R5
  458.     IfErrors TextFunc_LineFind_error
  459.  
  460.     StrCmp $1 '/NUL' TextFunc_LineFind_end
  461.     StrCmp $1 '' 0 +2
  462.     StrCpy $1 $0
  463.     StrCmp $6 0 0 TextFunc_LineFind_rename
  464.     FileOpen $7 $0 r
  465.     FileSeek $7 0 END $8
  466.     FileClose $7
  467.     FileOpen $7 $R4 r
  468.     FileSeek $7 0 END $9
  469.     FileClose $7
  470.     IntCmp $8 $9 0 TextFunc_LineFind_rename
  471.     Delete $R4
  472.     StrCmp $1 $0 TextFunc_LineFind_end
  473.     CopyFiles /SILENT $0 $1
  474.     goto TextFunc_LineFind_end
  475.  
  476.     TextFunc_LineFind_rename:
  477.     Delete '$EXEDIR\$1'
  478.     Rename $R4 '$EXEDIR\$1'
  479.     IfErrors 0 TextFunc_LineFind_end
  480.     Delete $1
  481.     Rename $R4 $1
  482.     IfErrors 0 TextFunc_LineFind_end
  483.  
  484.     TextFunc_LineFind_error:
  485.     SetErrors
  486.  
  487.     TextFunc_LineFind_end:
  488.     Pop $R9
  489.     Pop $R8
  490.     Pop $R7
  491.     Pop $R6
  492.     Pop $R5
  493.     Pop $R4
  494.     Pop $9
  495.     Pop $8
  496.     Pop $7
  497.     Pop $6
  498.     Pop $5
  499.     Pop $4
  500.     Pop $3
  501.     Pop $2
  502.     Pop $1
  503.     Pop $0
  504.  
  505.     !verbose pop
  506. !macroend
  507.  
  508. !define LineRead `!insertmacro LineReadCall`
  509. !define un.LineRead `!insertmacro LineReadCall`
  510.  
  511. !macro LineRead
  512. !macroend
  513.  
  514. !macro un.LineRead
  515. !macroend
  516.  
  517. !macro LineRead_
  518.     !verbose push
  519.     !verbose ${_TEXTFUNC_VERBOSE}
  520.  
  521.     Exch $1
  522.     Exch
  523.     Exch $0
  524.     Exch
  525.     Push $2
  526.     Push $3
  527.     Push $4
  528.     ClearErrors
  529.  
  530.     IfFileExists $0 0 TextFunc_LineRead_error
  531.     IntOp $1 $1 + 0
  532.     IntCmp $1 0 TextFunc_LineRead_error 0 TextFunc_LineRead_plus
  533.     StrCpy $4 0
  534.     FileOpen $2 $0 r
  535.     IfErrors TextFunc_LineRead_error
  536.     FileRead $2 $3
  537.     IfErrors +3
  538.     IntOp $4 $4 + 1
  539.     Goto -3
  540.     FileClose $2
  541.     IntOp $1 $4 + $1
  542.     IntOp $1 $1 + 1
  543.     IntCmp $1 0 TextFunc_LineRead_error TextFunc_LineRead_error
  544.  
  545.     TextFunc_LineRead_plus:
  546.     FileOpen $2 $0 r
  547.     IfErrors TextFunc_LineRead_error
  548.     StrCpy $3 0
  549.     IntOp $3 $3 + 1
  550.     FileRead $2 $0
  551.     IfErrors +4
  552.     StrCmp $3 $1 0 -3
  553.     FileClose $2
  554.     goto TextFunc_LineRead_end
  555.     FileClose $2
  556.  
  557.     TextFunc_LineRead_error:
  558.     SetErrors
  559.     StrCpy $0 ''
  560.  
  561.     TextFunc_LineRead_end:
  562.     Pop $4
  563.     Pop $3
  564.     Pop $2
  565.     Pop $1
  566.     Exch $0
  567.  
  568.     !verbose pop
  569. !macroend
  570.  
  571. !define FileReadFromEnd `!insertmacro FileReadFromEndCall`
  572. !define un.FileReadFromEnd `!insertmacro FileReadFromEndCall`
  573.  
  574. !macro FileReadFromEnd
  575. !macroend
  576.  
  577. !macro un.FileReadFromEnd
  578. !macroend
  579.  
  580. !macro FileReadFromEnd_
  581.     !verbose push
  582.     !verbose ${_TEXTFUNC_VERBOSE}
  583.  
  584.     Exch $1
  585.     Exch
  586.     Exch $0
  587.     Exch
  588.     Push $7
  589.     Push $8
  590.     Push $9
  591.     ClearErrors
  592.  
  593.     StrCpy $7 -1
  594.     StrCpy $8 0
  595.     IfFileExists $0 0 TextFunc_FileReadFromEnd_error
  596.     FileOpen $0 $0 r
  597.     IfErrors TextFunc_FileReadFromEnd_error
  598.     FileRead $0 $9
  599.     IfErrors +4
  600.     Push $9
  601.     IntOp $8 $8 + 1
  602.     goto -4
  603.     FileClose $0
  604.  
  605.     TextFunc_FileReadFromEnd_nextline:
  606.     StrCmp $8 0 TextFunc_FileReadFromEnd_end
  607.     Pop $9
  608.     Push $1
  609.     Push $7
  610.     Push $8
  611.     Call $1
  612.     Pop $0
  613.     Pop $8
  614.     Pop $7
  615.     Pop $1
  616.     IntOp $7 $7 - 1
  617.     IntOp $8 $8 - 1
  618.     IfErrors TextFunc_FileReadFromEnd_error
  619.     StrCmp $0 'StopFileReadFromEnd' TextFunc_FileReadFromEnd_clearstack TextFunc_FileReadFromEnd_nextline
  620.  
  621.     TextFunc_FileReadFromEnd_error:
  622.     SetErrors
  623.  
  624.     TextFunc_FileReadFromEnd_clearstack:
  625.     StrCmp $8 0 TextFunc_FileReadFromEnd_end
  626.     Pop $9
  627.     IntOp $8 $8 - 1
  628.     goto TextFunc_FileReadFromEnd_clearstack
  629.  
  630.     TextFunc_FileReadFromEnd_end:
  631.     Pop $9
  632.     Pop $8
  633.     Pop $7
  634.     Pop $1
  635.     Pop $0
  636.  
  637.     !verbose pop
  638. !macroend
  639.  
  640. !define LineSum `!insertmacro LineSumCall`
  641. !define un.LineSum `!insertmacro LineSumCall`
  642.  
  643. !macro LineSum
  644. !macroend
  645.  
  646. !macro un.LineSum
  647. !macroend
  648.  
  649. !macro LineSum_
  650.     !verbose push
  651.     !verbose ${_TEXTFUNC_VERBOSE}
  652.  
  653.     Exch $0
  654.     Push $1
  655.     Push $2
  656.     ClearErrors
  657.  
  658.     IfFileExists $0 0 TextFunc_LineSum_error
  659.     StrCpy $2 0
  660.     FileOpen $0 $0 r
  661.     IfErrors TextFunc_LineSum_error
  662.     FileRead $0 $1
  663.     IfErrors +3
  664.     IntOp $2 $2 + 1
  665.     Goto -3
  666.     FileClose $0
  667.     StrCpy $0 $2
  668.     goto TextFunc_LineSum_end
  669.  
  670.     TextFunc_LineSum_error:
  671.     SetErrors
  672.     StrCpy $0 ''
  673.  
  674.     TextFunc_LineSum_end:
  675.     Pop $2
  676.     Pop $1
  677.     Exch $0
  678.  
  679.     !verbose pop
  680. !macroend
  681.  
  682. !define FileJoin `!insertmacro FileJoinCall`
  683. !define un.FileJoin `!insertmacro FileJoinCall`
  684.  
  685. !macro FileJoin
  686. !macroend
  687.  
  688. !macro un.FileJoin
  689. !macroend
  690.  
  691. !macro FileJoin_
  692.     !verbose push
  693.     !verbose ${_TEXTFUNC_VERBOSE}
  694.  
  695.     Exch $2
  696.     Exch
  697.     Exch $1
  698.     Exch
  699.     Exch 2
  700.     Exch $0
  701.     Exch 2
  702.     Push $3
  703.     Push $4
  704.     Push $5
  705.     ClearErrors
  706.  
  707.     IfFileExists $0 0 TextFunc_FileJoin_error
  708.     IfFileExists $1 0 TextFunc_FileJoin_error
  709.     StrCpy $3 0
  710.     IntOp $3 $3 - 1
  711.     StrCpy $4 $2 1 $3
  712.     StrCmp $4 \ +2
  713.     StrCmp $4 '' +3 -3
  714.     StrCpy $4 $2 $3
  715.     IfFileExists '$4\*.*' 0 TextFunc_FileJoin_error
  716.  
  717.     StrCmp $2 $0 0 +2
  718.     StrCpy $2 ''
  719.     StrCmp $2 '' 0 +3
  720.     StrCpy $4 $0
  721.     Goto TextFunc_FileJoin_notemp
  722.     !insertmacro _TextFunc_TempFileForFile $2 $4
  723.     CopyFiles /SILENT $0 $4
  724.     TextFunc_FileJoin_notemp:
  725.     FileOpen $3 $4 a
  726.     IfErrors TextFunc_FileJoin_error
  727.     FileSeek $3 -1 END
  728.     FileRead $3 $5
  729.     StrCmp $5 '$\r' +3
  730.     StrCmp $5 '$\n' +2
  731.     FileWrite $3 '$\r$\n'
  732.  
  733.     ;FileWrite $3 '$\r$\n--Divider--$\r$\n'
  734.  
  735.     FileOpen $0 $1 r
  736.     IfErrors TextFunc_FileJoin_error
  737.     FileRead $0 $5
  738.     IfErrors +3
  739.     FileWrite $3 $5
  740.     goto -3
  741.     FileClose $0
  742.     FileClose $3
  743.     StrCmp $2 '' TextFunc_FileJoin_end
  744.     Delete '$EXEDIR\$2'
  745.     Rename $4 '$EXEDIR\$2'
  746.     IfErrors 0 TextFunc_FileJoin_end
  747.     Delete $2
  748.     Rename $4 $2
  749.     IfErrors 0 TextFunc_FileJoin_end
  750.  
  751.     TextFunc_FileJoin_error:
  752.     SetErrors
  753.  
  754.     TextFunc_FileJoin_end:
  755.     Pop $5
  756.     Pop $4
  757.     Pop $3
  758.     Pop $2
  759.     Pop $1
  760.     Pop $0
  761.  
  762.     !verbose pop
  763. !macroend
  764.  
  765. !macro TextCompareBody _TEXTFUNC_S
  766.     Exch $3
  767.     Exch
  768.     Exch $2
  769.     Exch
  770.     Exch 2
  771.     Exch $1
  772.     Exch 2
  773.     Exch 3
  774.     Exch $0
  775.     Exch 3
  776.     Push $4
  777.     Push $5
  778.     Push $6
  779.     Push $7
  780.     Push $8
  781.     Push $9
  782.     ClearErrors
  783.  
  784.     IfFileExists $0 0 TextFunc_TextCompare${_TEXTFUNC_S}_error
  785.     IfFileExists $1 0 TextFunc_TextCompare${_TEXTFUNC_S}_error
  786.     StrCmp $2 'FastDiff' +5
  787.     StrCmp $2 'FastEqual' +4
  788.     StrCmp $2 'SlowDiff' +3
  789.     StrCmp $2 'SlowEqual' +2
  790.     goto TextFunc_TextCompare${_TEXTFUNC_S}_error
  791.  
  792.     FileOpen $4 $0 r
  793.     IfErrors TextFunc_TextCompare${_TEXTFUNC_S}_error
  794.     FileOpen $5 $1 r
  795.     IfErrors TextFunc_TextCompare${_TEXTFUNC_S}_error
  796.     SetDetailsPrint textonly
  797.  
  798.     StrCpy $6 0
  799.     StrCpy $8 0
  800.  
  801.     TextFunc_TextCompare${_TEXTFUNC_S}_nextline:
  802.     StrCmp${_TEXTFUNC_S} $4 '' TextFunc_TextCompare${_TEXTFUNC_S}_fast
  803.     IntOp $8 $8 + 1
  804.     FileRead $4 $9
  805.     IfErrors 0 +4
  806.     FileClose $4
  807.     StrCpy $4 ''
  808.     StrCmp${_TEXTFUNC_S} $5 '' TextFunc_TextCompare${_TEXTFUNC_S}_end
  809.     StrCmp $2 'FastDiff' TextFunc_TextCompare${_TEXTFUNC_S}_fast
  810.     StrCmp $2 'FastEqual' TextFunc_TextCompare${_TEXTFUNC_S}_fast TextFunc_TextCompare${_TEXTFUNC_S}_slow
  811.  
  812.     TextFunc_TextCompare${_TEXTFUNC_S}_fast:
  813.     StrCmp${_TEXTFUNC_S} $5 '' TextFunc_TextCompare${_TEXTFUNC_S}_call
  814.     IntOp $6 $6 + 1
  815.     FileRead $5 $7
  816.     IfErrors 0 +5
  817.     FileClose $5
  818.     StrCpy $5 ''
  819.     StrCmp${_TEXTFUNC_S} $4 '' TextFunc_TextCompare${_TEXTFUNC_S}_end
  820.     StrCmp $2 'FastDiff' TextFunc_TextCompare${_TEXTFUNC_S}_call TextFunc_TextCompare${_TEXTFUNC_S}_close
  821.     StrCmp $2 'FastDiff' 0 +2
  822.     StrCmp${_TEXTFUNC_S} $7 $9 TextFunc_TextCompare${_TEXTFUNC_S}_nextline TextFunc_TextCompare${_TEXTFUNC_S}_call
  823.     StrCmp${_TEXTFUNC_S} $7 $9 TextFunc_TextCompare${_TEXTFUNC_S}_call TextFunc_TextCompare${_TEXTFUNC_S}_nextline
  824.  
  825.     TextFunc_TextCompare${_TEXTFUNC_S}_slow:
  826.     StrCmp${_TEXTFUNC_S} $4 '' TextFunc_TextCompare${_TEXTFUNC_S}_close
  827.     StrCpy $6 ''
  828.     DetailPrint '$8. $9'
  829.     FileSeek $5 0
  830.  
  831.     TextFunc_TextCompare${_TEXTFUNC_S}_slownext:
  832.     FileRead $5 $7
  833.     IfErrors 0 +2
  834.     StrCmp $2 'SlowDiff' TextFunc_TextCompare${_TEXTFUNC_S}_call TextFunc_TextCompare${_TEXTFUNC_S}_nextline
  835.     StrCmp $2 'SlowDiff' 0 +2
  836.     StrCmp${_TEXTFUNC_S} $7 $9 TextFunc_TextCompare${_TEXTFUNC_S}_nextline TextFunc_TextCompare${_TEXTFUNC_S}_slownext
  837.     IntOp $6 $6 + 1
  838.     StrCmp${_TEXTFUNC_S} $7 $9 0 TextFunc_TextCompare${_TEXTFUNC_S}_slownext
  839.  
  840.     TextFunc_TextCompare${_TEXTFUNC_S}_call:
  841.     Push $2
  842.     Push $3
  843.     Push $4
  844.     Push $5
  845.     Push $6
  846.     Push $7
  847.     Push $8
  848.     Push $9
  849.     Call $3
  850.     Pop $0
  851.     Pop $9
  852.     Pop $8
  853.     Pop $7
  854.     Pop $6
  855.     Pop $5
  856.     Pop $4
  857.     Pop $3
  858.     Pop $2
  859.     StrCmp $0 'StopTextCompare' 0 TextFunc_TextCompare${_TEXTFUNC_S}_nextline
  860.  
  861.     TextFunc_TextCompare${_TEXTFUNC_S}_close:
  862.     FileClose $4
  863.     FileClose $5
  864.     goto TextFunc_TextCompare${_TEXTFUNC_S}_end
  865.  
  866.     TextFunc_TextCompare${_TEXTFUNC_S}_error:
  867.     SetErrors
  868.  
  869.     TextFunc_TextCompare${_TEXTFUNC_S}_end:
  870.     SetDetailsPrint both
  871.     Pop $9
  872.     Pop $8
  873.     Pop $7
  874.     Pop $6
  875.     Pop $5
  876.     Pop $4
  877.     Pop $3
  878.     Pop $2
  879.     Pop $1
  880.     Pop $0
  881. !macroend
  882.  
  883. !define TextCompare `!insertmacro TextCompareCall`
  884. !define un.TextCompare `!insertmacro TextCompareCall`
  885.  
  886. !macro TextCompare
  887. !macroend
  888.  
  889. !macro un.TextCompare
  890. !macroend
  891.  
  892. !macro TextCompare_
  893.     !verbose push
  894.     !verbose ${_TEXTFUNC_VERBOSE}
  895.  
  896.     !insertmacro TextCompareBody ''
  897.  
  898.     !verbose pop
  899. !macroend
  900.  
  901. !define TextCompareS `!insertmacro TextCompareSCall`
  902. !define un.TextCompareS `!insertmacro TextCompareSCall`
  903.  
  904. !macro TextCompareS
  905. !macroend
  906.  
  907. !macro un.TextCompareS
  908. !macroend
  909.  
  910. !macro TextCompareS_
  911.     !verbose push
  912.     !verbose ${_TEXTFUNC_VERBOSE}
  913.  
  914.     !insertmacro TextCompareBody 'S'
  915.  
  916.     !verbose pop
  917. !macroend
  918.  
  919. !macro ConfigReadBody _TEXTFUNC_S
  920.     Exch $1
  921.     Exch
  922.     Exch $0
  923.     Exch
  924.     Push $2
  925.     Push $3
  926.     Push $4
  927.     ClearErrors
  928.  
  929.     FileOpen $2 $0 r
  930.     IfErrors TextFunc_ConfigRead${_TEXTFUNC_S}_error
  931.     StrLen $0 $1
  932.     StrCmp${_TEXTFUNC_S} $0 0 TextFunc_ConfigRead${_TEXTFUNC_S}_error
  933.  
  934.     TextFunc_ConfigRead${_TEXTFUNC_S}_readnext:
  935.     FileRead $2 $3
  936.     IfErrors TextFunc_ConfigRead${_TEXTFUNC_S}_error
  937.     StrCpy $4 $3 $0
  938.     StrCmp${_TEXTFUNC_S} $4 $1 0 TextFunc_ConfigRead${_TEXTFUNC_S}_readnext
  939.     StrCpy $0 $3 '' $0
  940.     StrCpy $4 $0 1 -1
  941.     StrCmp${_TEXTFUNC_S} $4 '$\r' +2
  942.     StrCmp${_TEXTFUNC_S} $4 '$\n' 0 TextFunc_ConfigRead${_TEXTFUNC_S}_close
  943.     StrCpy $0 $0 -1
  944.     goto -4
  945.  
  946.     TextFunc_ConfigRead${_TEXTFUNC_S}_error:
  947.     SetErrors
  948.     StrCpy $0 ''
  949.  
  950.     TextFunc_ConfigRead${_TEXTFUNC_S}_close:
  951.     FileClose $2
  952.  
  953.     Pop $4
  954.     Pop $3
  955.     Pop $2
  956.     Pop $1
  957.     Exch $0
  958. !macroend
  959.  
  960. !define ConfigRead `!insertmacro ConfigReadCall`
  961. !define un.ConfigRead `!insertmacro ConfigReadCall`
  962.  
  963. !macro ConfigRead
  964. !macroend
  965.  
  966. !macro un.ConfigRead
  967. !macroend
  968.  
  969. !macro ConfigRead_
  970.     !verbose push
  971.     !verbose ${_TEXTFUNC_VERBOSE}
  972.  
  973.     !insertmacro ConfigReadBody ''
  974.  
  975.     !verbose pop
  976. !macroend
  977.  
  978. !define ConfigReadS `!insertmacro ConfigReadSCall`
  979. !define un.ConfigReadS `!insertmacro ConfigReadSCall`
  980.  
  981. !macro ConfigReadS
  982. !macroend
  983.  
  984. !macro un.ConfigReadS
  985. !macroend
  986.  
  987. !macro ConfigReadS_
  988.     !verbose push
  989.     !verbose ${_TEXTFUNC_VERBOSE}
  990.  
  991.     !insertmacro ConfigReadBody 'S'
  992.  
  993.     !verbose pop
  994. !macroend
  995.  
  996. !macro ConfigWriteBody _TEXTFUNC_S
  997.     Exch $2
  998.     Exch
  999.     Exch $1
  1000.     Exch
  1001.     Exch 2
  1002.     Exch $0
  1003.     Exch 2
  1004.     Push $3
  1005.     Push $4
  1006.     Push $5
  1007.     Push $6
  1008.     ClearErrors
  1009.  
  1010.     IfFileExists $0 0 TextFunc_ConfigWrite${_TEXTFUNC_S}_error
  1011.     FileOpen $3 $0 a
  1012.     IfErrors TextFunc_ConfigWrite${_TEXTFUNC_S}_error
  1013.  
  1014.     StrLen $0 $1
  1015.     StrCmp${_TEXTFUNC_S} $0 0 0 TextFunc_ConfigWrite${_TEXTFUNC_S}_readnext
  1016.     StrCpy $0 ''
  1017.     goto TextFunc_ConfigWrite${_TEXTFUNC_S}_close
  1018.  
  1019.     TextFunc_ConfigWrite${_TEXTFUNC_S}_readnext:
  1020.     FileRead $3 $4
  1021.     IfErrors TextFunc_ConfigWrite${_TEXTFUNC_S}_add
  1022.     StrCpy $5 $4 $0
  1023.     StrCmp${_TEXTFUNC_S} $5 $1 0 TextFunc_ConfigWrite${_TEXTFUNC_S}_readnext
  1024.  
  1025.     StrCpy $5 0
  1026.     IntOp $5 $5 - 1
  1027.     StrCpy $6 $4 1 $5
  1028.     StrCmp${_TEXTFUNC_S} $6 '$\r' -2
  1029.     StrCmp${_TEXTFUNC_S} $6 '$\n' -3
  1030.     StrCpy $6 $4
  1031.     StrCmp${_TEXTFUNC_S} $5 -1 +3
  1032.     IntOp $5 $5 + 1
  1033.     StrCpy $6 $4 $5
  1034.  
  1035.     StrCmp${_TEXTFUNC_S} $2 '' TextFunc_ConfigWrite${_TEXTFUNC_S}_change
  1036.     StrCmp${_TEXTFUNC_S} $6 '$1$2' 0 TextFunc_ConfigWrite${_TEXTFUNC_S}_change
  1037.     StrCpy $0 SAME
  1038.     goto TextFunc_ConfigWrite${_TEXTFUNC_S}_close
  1039.  
  1040.     TextFunc_ConfigWrite${_TEXTFUNC_S}_change:
  1041.     FileSeek $3 0 CUR $5
  1042.     StrLen $4 $4
  1043.     IntOp $4 $5 - $4
  1044.     FileSeek $3 0 END $6
  1045.     IntOp $6 $6 - $5
  1046.  
  1047.     System::Alloc $6
  1048.     Pop $0
  1049.     FileSeek $3 $5 SET
  1050.     System::Call 'kernel32::ReadFile(i r3, i r0, i $6, t.,)'
  1051.     FileSeek $3 $4 SET
  1052.     StrCmp${_TEXTFUNC_S} $2 '' +2
  1053.     FileWrite $3 '$1$2$\r$\n'
  1054.     System::Call 'kernel32::WriteFile(i r3, i r0, i $6, t.,)'
  1055.     System::Call 'kernel32::SetEndOfFile(i r3)'
  1056.     System::Free $0
  1057.     StrCmp${_TEXTFUNC_S} $2 '' +3
  1058.     StrCpy $0 CHANGED
  1059.     goto TextFunc_ConfigWrite${_TEXTFUNC_S}_close
  1060.     StrCpy $0 DELETED
  1061.     goto TextFunc_ConfigWrite${_TEXTFUNC_S}_close
  1062.  
  1063.     TextFunc_ConfigWrite${_TEXTFUNC_S}_add:
  1064.     StrCmp${_TEXTFUNC_S} $2 '' 0 +3
  1065.     StrCpy $0 SAME
  1066.     goto TextFunc_ConfigWrite${_TEXTFUNC_S}_close
  1067.     FileSeek $3 -1 END
  1068.     FileRead $3 $4
  1069.     IfErrors +4
  1070.     StrCmp${_TEXTFUNC_S} $4 '$\r' +3
  1071.     StrCmp${_TEXTFUNC_S} $4 '$\n' +2
  1072.     FileWrite $3 '$\r$\n'
  1073.     FileWrite $3 '$1$2$\r$\n'
  1074.     StrCpy $0 ADDED
  1075.  
  1076.     TextFunc_ConfigWrite${_TEXTFUNC_S}_close:
  1077.     FileClose $3
  1078.     goto TextFunc_ConfigWrite${_TEXTFUNC_S}_end
  1079.  
  1080.     TextFunc_ConfigWrite${_TEXTFUNC_S}_error:
  1081.     SetErrors
  1082.     StrCpy $0 ''
  1083.  
  1084.     TextFunc_ConfigWrite${_TEXTFUNC_S}_end:
  1085.     Pop $6
  1086.     Pop $5
  1087.     Pop $4
  1088.     Pop $3
  1089.     Pop $2
  1090.     Pop $1
  1091.     Exch $0
  1092. !macroend
  1093.  
  1094. !define ConfigWrite `!insertmacro ConfigWriteCall`
  1095. !define un.ConfigWrite `!insertmacro ConfigWriteCall`
  1096.  
  1097. !macro ConfigWrite
  1098. !macroend
  1099.  
  1100. !macro un.ConfigWrite
  1101. !macroend
  1102.  
  1103. !macro ConfigWrite_
  1104.     !verbose push
  1105.     !verbose ${_TEXTFUNC_VERBOSE}
  1106.  
  1107.     !insertmacro ConfigWriteBody ''
  1108.  
  1109.     !verbose pop
  1110. !macroend
  1111.  
  1112. !define ConfigWriteS `!insertmacro ConfigWriteSCall`
  1113. !define un.ConfigWriteS `!insertmacro ConfigWriteSCall`
  1114.  
  1115. !macro ConfigWriteS
  1116. !macroend
  1117.  
  1118. !macro un.ConfigWriteS
  1119. !macroend
  1120.  
  1121. !macro ConfigWriteS_
  1122.     !verbose push
  1123.     !verbose ${_TEXTFUNC_VERBOSE}
  1124.  
  1125.     !insertmacro ConfigWriteBody 'S'
  1126.  
  1127.     !verbose pop
  1128. !macroend
  1129.  
  1130. !define FileRecode `!insertmacro FileRecodeCall`
  1131. !define un.FileRecode `!insertmacro FileRecodeCall`
  1132.  
  1133. !macro FileRecode
  1134. !macroend
  1135.  
  1136. !macro un.FileRecode
  1137. !macroend
  1138.  
  1139. !macro FileRecode_
  1140.     !verbose push
  1141.     !verbose ${_TEXTFUNC_VERBOSE}
  1142.  
  1143.     Exch $1
  1144.     Exch
  1145.     Exch $0
  1146.     Exch
  1147.     Push $2
  1148.     Push $3
  1149.     Push $4
  1150.  
  1151.     IfFileExists $0 0 TextFunc_FileRecode_error
  1152.     StrCmp $1 OemToChar +2
  1153.     StrCmp $1 CharToOem 0 TextFunc_FileRecode_error
  1154.  
  1155.     FileOpen $2 $0 a
  1156.     FileSeek $2 0 END $3
  1157.     System::Alloc $3
  1158.     Pop $4
  1159.     FileSeek $2 0 SET
  1160.     System::Call 'kernel32::ReadFile(i r2, i r4, i $3, t.,)'
  1161.     System::Call 'user32::$1Buff(i r4, i r4, i $3)'
  1162.     FileSeek $2 0 SET
  1163.     System::Call 'kernel32::WriteFile(i r2, i r4, i $3, t.,)'
  1164.     System::Free $4
  1165.     FileClose $2
  1166.     goto TextFunc_FileRecode_end
  1167.  
  1168.     TextFunc_FileRecode_error:
  1169.     SetErrors
  1170.  
  1171.     TextFunc_FileRecode_end:
  1172.     Pop $4
  1173.     Pop $3
  1174.     Pop $2
  1175.     Pop $1
  1176.     Pop $0
  1177.  
  1178.     !verbose pop
  1179. !macroend
  1180.  
  1181. !define TrimNewLines `!insertmacro TrimNewLinesCall`
  1182. !define un.TrimNewLines `!insertmacro TrimNewLinesCall`
  1183.  
  1184. !macro TrimNewLines
  1185. !macroend
  1186.  
  1187. !macro un.TrimNewLines
  1188. !macroend
  1189.  
  1190. !macro TrimNewLines_
  1191.     !verbose push
  1192.     !verbose ${_TEXTFUNC_VERBOSE}
  1193.  
  1194.     Exch $0
  1195.     Push $1
  1196.     Push $2
  1197.  
  1198.     StrCpy $1 0
  1199.     IntOp $1 $1 - 1
  1200.     StrCpy $2 $0 1 $1
  1201.     StrCmp $2 '$\r' -2
  1202.     StrCmp $2 '$\n' -3
  1203.     StrCmp $1 -1 +3
  1204.     IntOp $1 $1 + 1
  1205.     StrCpy $0 $0 $1
  1206.  
  1207.     Pop $2
  1208.     Pop $1
  1209.     Exch $0
  1210.  
  1211.     !verbose pop
  1212. !macroend
  1213.  
  1214. !endif
  1215.