home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 March / CMCD0304.ISO / Software / Freeware / Programare / nullsoft / nsis20.exe / Include / StrFunc.nsh < prev    next >
Text File  |  2004-02-07  |  27KB  |  1,137 lines

  1. /*
  2.  
  3. Functions Header File for NSIS
  4.  
  5. StrFunc.nsh
  6. This file contains functions for string manipulation for NSIS
  7.  
  8. by Diego Pedroso (aka deguix)
  9.  
  10. */
  11.  
  12. !ifndef MUI_VERBOSE
  13.   !define MUI_VERBOSE 3
  14. !endif
  15.  
  16. !echo "$\r$\n----------------------------------------------------------------------$\r$\nNSIS String Functions Header File 1.02 - ⌐ 2004 Diego Pedroso$\r$\n----------------------------------------------------------------------$\r$\n$\r$\n"
  17.  
  18. !define StrClbGet "!insertmacro FUNCTION_STRING_StrClbGet"
  19. !define StrClbSet "!insertmacro FUNCTION_STRING_StrClbSet"
  20. !define StrIOToNSIS "!insertmacro FUNCTION_STRING_StrIOToNSIS"
  21. !define StrLoc "!insertmacro FUNCTION_STRING_StrLoc"
  22. !define StrLowerCase "!insertmacro FUNCTION_STRING_StrLowerCase"
  23. !define StrNSISToIO "!insertmacro FUNCTION_STRING_StrNSISToIO"
  24. !define StrRep "!insertmacro FUNCTION_STRING_StrRep"
  25. !define StrSort "!insertmacro FUNCTION_STRING_StrSort"
  26. !define StrStr "!insertmacro FUNCTION_STRING_StrStr"
  27. !define StrStrAdv "!insertmacro FUNCTION_STRING_StrStrAdv"
  28. !define StrTok "!insertmacro FUNCTION_STRING_StrTok"
  29. !define StrTrimNewLines "!insertmacro FUNCTION_STRING_StrTrimNewLines"
  30. !define StrUpperCase "!insertmacro FUNCTION_STRING_StrUpperCase"
  31.  
  32. !macro FUNCTION_STRING_StrStr
  33.  
  34.   !ifndef FUNCTION_STRING_StrStr
  35.  
  36.     !echo "$\r$\n----------------------------------------------------------------------$\r$\nSearch in String Function - 2002-2004 Ximon Eighteen\r$\n----------------------------------------------------------------------$\r$\n$\r$\n"
  37.  
  38.     !define FUNCTION_STRING_StrStr
  39.     !undef StrStr
  40.     !define StrStr "!insertmacro FUNCTION_STRING_StrStr_Call"
  41.  
  42.     Function StrStr
  43.       Exch $R1 ; st=haystack,old$R1, $R1=needle
  44.       Exch    ; st=old$R1,haystack
  45.       Exch $R2 ; st=old$R1,old$R2, $R2=haystack
  46.       Push $R3
  47.       Push $R4
  48.       Push $R5
  49.       StrLen $R3 $R1
  50.       StrCpy $R4 0
  51.       ; $R1=needle
  52.       ; $R2=haystack
  53.       ; $R3=len(needle)
  54.       ; $R4=cnt
  55.       ; $R5=tmp
  56.       loop:
  57.         StrCpy $R5 $R2 $R3 $R4
  58.         StrCmp $R5 $R1 done
  59.         StrCmp $R5 "" done
  60.         IntOp $R4 $R4 + 1
  61.         Goto loop
  62.       done:
  63.       StrCpy $R1 $R2 "" $R4
  64.       Pop $R5
  65.       Pop $R4
  66.       Pop $R3
  67.       Pop $R2
  68.       Exch $R1
  69.     FunctionEnd
  70.  
  71.   !endif
  72.  
  73. !macroend
  74.  
  75. !macro FUNCTION_STRING_StrStr_Call ResultVar String StrToSearchFor
  76.  
  77.   !echo `$ {StrStr} "${ResultVar}" "${String}" "${StrToSearchFor}"$\r$\n`
  78.  
  79.   Push `${String}`
  80.   Push `${StrToSearchFor}`
  81.  
  82.   Call StrStr
  83.  
  84.   Pop `${ResultVar}`
  85.  
  86. !macroend
  87.  
  88. !macro FUNCTION_STRING_StrLoc
  89.  
  90.   !ifndef FUNCTION_STRING_StrLoc
  91.  
  92.     !echo "$\r$\n----------------------------------------------------------------------$\r$\nLocalize in String Function - ⌐ 2004 Diego Pedroso\r$\n----------------------------------------------------------------------$\r$\n$\r$\n"
  93.  
  94.     !define FUNCTION_STRING_StrLoc
  95.     !undef StrLoc
  96.     !define StrLoc "!insertmacro FUNCTION_STRING_StrLoc_Call"
  97.  
  98.     Function StrLoc
  99.       Exch $R0
  100.       Exch
  101.       Exch $R1 ; st=haystack,old$R1, $R1=needle
  102.       Exch 2    ; st=old$R1,haystack
  103.       Exch $R2 ; st=old$R1,old$R2, $R2=haystack
  104.  
  105.       Push $R3
  106.       Push $R4
  107.       Push $R5
  108.       StrLen $R3 $R1
  109.       StrCpy $R4 0
  110.       loop:
  111.         StrCpy $R5 $R2 $R3 $R4
  112.         StrCmp $R5 $R1 done
  113.         StrCmp $R5 "" error
  114.         IntOp $R4 $R4 + 1
  115.         Goto loop
  116.       done:
  117.  
  118.       StrCmp $R0 "<" 0 +5
  119.         StrLen $R0 $R2
  120.         IntOp $R5 $R3 + $R4
  121.         IntOp $R0 $R0 - $R5
  122.         Goto +2
  123.  
  124.       StrCpy $R0 $R4
  125.       Goto +2
  126.  
  127.       error:
  128.       StrCpy $R0 ""
  129.  
  130.       Pop $R5
  131.       Pop $R4
  132.       Pop $R3
  133.       Pop $R2
  134.       Pop $R1
  135.       Exch $R0
  136.     FunctionEnd
  137.  
  138.   !endif
  139.  
  140. !macroend
  141.  
  142. !macro FUNCTION_STRING_StrLoc_Call ResultVar String StrToSearchFor OffsetDirection
  143.  
  144.   !echo `$ {StrLoc} "${ResultVar}" "${String}" "${StrToSearchFor}" "${OffsetDirection}"$\r$\n`
  145.  
  146.   Push `${String}`
  147.   Push `${StrToSearchFor}`
  148.   Push `${OffsetDirection}`
  149.  
  150.   Call StrLoc
  151.  
  152.   Pop `${ResultVar}`
  153.  
  154. !macroend
  155.  
  156. !macro FUNCTION_STRING_StrStrAdv
  157.  
  158.   !ifndef FUNCTION_STRING_StrStrAdv
  159.  
  160.     !echo "$\r$\n----------------------------------------------------------------------$\r$\nAdvanced Search in String Function - ⌐ 2003-2004 Diego Pedroso$\r$\n----------------------------------------------------------------------$\r$\n$\r$\n"
  161.  
  162.     !define FUNCTION_STRING_StrStrAdv
  163.     !undef StrStrAdv
  164.  
  165.     !define StrStrAdv "!insertmacro FUNCTION_STRING_StrStrAdv_Call"
  166.  
  167.     Function AdvancedStrStr
  168.  
  169.      # Preparing Variables
  170.  
  171.      Exch $R9
  172.      Exch
  173.      Exch $R8
  174.      Exch
  175.      Exch 2
  176.      Exch $R7
  177.      Exch 2
  178.      Exch 3
  179.      Exch $R6
  180.      Exch 3
  181.      Exch 4
  182.      Exch $R5
  183.      Exch 4
  184.      Exch 5
  185.      Exch $R4
  186.      Exch 5
  187.      Push $R3
  188.      Push $R2
  189.      Push $R1
  190.      Push $R0
  191.      Push $9
  192.      Push $8
  193.      Push $7
  194.      Push $6
  195.      StrCpy $R2 $R4
  196.      StrCpy $R1 $R5
  197.      StrCpy $R4 ""
  198.      StrCpy $R5 ""
  199.      StrCpy $7 $R2
  200.  
  201.      # Detect Empty Input
  202.  
  203.      StrCmp $R1 "" 0 +3
  204.        SetErrors
  205.        Goto granddone
  206.  
  207.      StrCmp $R2 "" 0 +3
  208.        SetErrors
  209.        Goto granddone
  210.  
  211.      StrCmp $R6 "" 0 +2
  212.        StrCpy $R6 >
  213.  
  214.      StrCmp $R7 "" 0 +2
  215.        StrCpy $R7 >
  216.  
  217.      # Preparing StrStr
  218.  
  219.      StrCpy $R0 0
  220.  
  221.      IntCmp $R9 1 +2 0 +2
  222.        StrCpy $R9 0
  223.  
  224.      IntOp $R9 $R9 + 1
  225.  
  226.      # Loops and more loops if you want...
  227.  
  228.        grandloop:
  229.  
  230.        # Detect if the loops number given by user = code runs...
  231.  
  232.        StrCpy $R4 0
  233.        StrLen $R3 $R1
  234.        StrCpy $6 $R3
  235.        StrCmp $9 1 0 +4
  236.          StrCmp $R6 "<" 0 +2
  237.            IntOp $R3 $R3 + 1
  238.            IntOp $R4 $R4 + 1
  239.  
  240.        StrCmp $R6 "<" 0 +5
  241.          IntOp $R3 $R3 * -1
  242.          StrCpy $6 $R3
  243.          IntCmp $R0 0 +2 0 0
  244.            IntOp $6 $6 + 1
  245.  
  246.        # Searching the string
  247.  
  248.          loop:
  249.  
  250.          # RTL...
  251.  
  252.          StrCmp $R6 "<" 0 EndBack
  253.  
  254.            IntOp $9 $R4 * -1
  255.  
  256.            StrCmp $9 0 0 +3
  257.              StrCpy $R5 $R2 "" $R3
  258.              Goto +2
  259.            StrCpy $R5 $R2 $9 $R3
  260.            Goto +2
  261.  
  262.          EndBack:
  263.  
  264.          # LTR...
  265.  
  266.          StrCpy $R5 $R2 $R3 $R4
  267.  
  268.          # Detect if the value returned is the searched...
  269.  
  270.          StrCmp $R5 $R1 done
  271.  
  272.          StrCmp $R5 "" granddone
  273.  
  274.              # If not, make a loop...
  275.  
  276.              IntOp $R4 $R4 + 1
  277.              StrCmp $R6 "<" 0 +2
  278.                IntOp $R3 $R3 - 1
  279.  
  280.          Goto loop
  281.  
  282.        done:
  283.  
  284.        StrCmp $R6 "<" 0 +3
  285.          IntOp $8 $9 + $8
  286.            Goto +2
  287.        IntOp $8 $R4 + $8
  288.  
  289.        # Looping Calculation...
  290.  
  291.         IntOp $R0 $R0 + 1
  292.  
  293.        IntCmp $R0 $R9 0 continueloop 0
  294.  
  295.        # Customizing the string to fit user conditions (supported by loops)...
  296.  
  297.        # RTL...
  298.  
  299.          StrCmp $R6 "<" 0 EndBackward
  300.            StrCmp $R7 ">" 0 +7
  301.              StrCmp $8 0 0 +3
  302.                StrCpy $R2 ""
  303.                Goto +2
  304.              StrCpy $R2 $7 "" $8
  305.              StrCpy $R2 $R1$R2
  306.              Goto +3
  307.  
  308.            StrCmp $9 0 +2
  309.              StrCpy $R2 $R2 $9
  310.  
  311.            StrCmp $R8 1 EndForward 0
  312.              StrCmp $R7 ">" 0 End>
  313.                Push $6
  314.                IntOp $6 $6 * -1
  315.                StrCpy $R2 $R2 "" $6
  316.                Pop $6
  317.                  Goto +2
  318.              End>:
  319.              StrCpy $R2 $R2 $6
  320.                Goto EndForward
  321.          EndBackward:
  322.  
  323.          # LTR...
  324.  
  325.          StrCmp $R7 "<" 0 +4
  326.            StrCpy $R2 $7 $8
  327.            StrCpy $R2 $R2$R1
  328.            Goto +2
  329.          StrCpy $R2 $R2 "" $R4
  330.          StrCmp $R8 1 EndForward 0
  331.            StrCmp $R7 "<" 0 End<
  332.              Push $6
  333.              IntOp $6 $6 * 2
  334.              StrCpy $R2 $R2 $6
  335.              Pop $6
  336.                Goto +2
  337.            End<:
  338.            StrCpy $R2 $R2 "" $R3
  339.          EndForward:
  340.  
  341.          Goto stoploop
  342.  
  343.        continueloop:
  344.  
  345.        # Customizing the string to fits user conditions (not supported by loops)...
  346.  
  347.        # RTL...
  348.  
  349.        StrCmp $R6 "<" 0 +4
  350.          StrCmp $9 0 +4
  351.          StrCpy $R2 $R2 $9
  352.            Goto +2
  353.  
  354.        # LTR...
  355.  
  356.        StrCpy $R2 $R2 "" $R4
  357.  
  358.        stoploop:
  359.  
  360.        # Return to grandloop init...
  361.  
  362.        StrCpy $9 1
  363.  
  364.        IntCmp $R0 $R9 0 grandloop 0
  365.  
  366.      StrCpy $R4 $R2
  367.  
  368.      Goto +2
  369.  
  370.      granddone:
  371.  
  372.      # Return the result to user
  373.  
  374.      StrCpy $R4 ""
  375.  
  376.      Pop $6
  377.      Pop $7
  378.      Pop $8
  379.      Pop $9
  380.      Pop $R0
  381.      Pop $R1
  382.      Pop $R2
  383.      Pop $R3
  384.      Pop $R9
  385.      Pop $R8
  386.      Pop $R7
  387.      Pop $R6
  388.      Pop $R5
  389.      Exch $R4
  390.  
  391.     FunctionEnd
  392.  
  393.   !endif
  394.  
  395. !macroend
  396.  
  397. !macro FUNCTION_STRING_StrStrAdv_Call ResultVar String StrToSearchFor SearchDirection ResultStrDirection DisplayStrToSearch Loops
  398.  
  399.   !echo `$ {StrStrAdv} "${ResultVar}" "${String}" "${StrToSearchFor}" "${SearchDirection}" "${ResultStrDirection}" "${DisplayStrToSearch}" "${Loops}"$\r$\n`
  400.  
  401.   Push `${String}`
  402.   Push `${StrToSearchFor}`
  403.   Push `${SearchDirection}`
  404.   Push `${ResultStrDirection}`
  405.   Push `${DisplayStrToSearch}`
  406.   Push `${Loops}`
  407.  
  408.   Call AdvancedStrStr
  409.  
  410.   Pop `${ResultVar}`
  411.  
  412. !macroend
  413.  
  414. !macro FUNCTION_STRING_StrTok
  415.  
  416.   !ifndef FUNCTION_STRING_StrTok
  417.  
  418.     !echo "$\r$\n----------------------------------------------------------------------$\r$\nAdvanced Token String Function - ⌐ 2004 Diego Pedroso$\r$\n----------------------------------------------------------------------$\r$\n$\r$\n"
  419.  
  420.     !define FUNCTION_STRING_StrTok
  421.     !undef StrTok
  422.     !define StrTok "!insertmacro FUNCTION_STRING_StrTok_Call"
  423.  
  424.     Function AdvancedStrTok
  425.       Exch $9
  426.       Exch
  427.       Exch $R0
  428.       Exch 2
  429.       Exch $R1
  430.       Exch 3
  431.       Exch $R2
  432.       Push $R3
  433.       Push $R4
  434.       Push $R5
  435.       Push $R6
  436.       Push $R7
  437.       Push $R8
  438.       Push $R9
  439.       Push $0
  440.       Push $1
  441.       Push $2
  442.  
  443.       StrCpy $R8 0
  444.       StrCpy $R9 $R1
  445.       
  446.       IntCmp $R0 0 0 0 +2
  447.         StrCpy $R0 L
  448.       
  449.       
  450.       StrCmp $R0 L 0 +5
  451.         StrCpy $2 1
  452.         StrCpy $R0 0
  453.         StrCpy $1 ""
  454.         StrCpy $9 1
  455.       
  456.       PartLoop:
  457.  
  458.       StrCpy $R4 0
  459.       IntOp $R8 $R8 + 1
  460.       StrCpy $0 0
  461.       
  462.       loop:
  463.  
  464.         StrCpy $R5 $R2 1 $R4
  465.         StrCmp $R5 "" done
  466.  
  467.         StrCpy $R6 -1
  468.         StrCpy $R7 0
  469.         loop2:
  470.  
  471.           IntOp $R6 $R6 + 1
  472.           IntOp $R7 $R6 + 1
  473.           StrCpy $R3 $R1 $R7 $R6
  474.           StrCmp $R3 "" 0 +3
  475.             IntOp $0 $0 + 1
  476.             Goto ContLoop2
  477.           StrCmp $R5 $R3 0 Loop2
  478.             StrCmp $9 1 0 done
  479.               StrCmp $0 0 0 done
  480.                 StrCpy $R2 $R2 "" 1
  481.                 Goto Loop
  482.             
  483.         ContLoop2:
  484.  
  485.         IntOp $R4 $R4 + 1
  486.         Goto loop
  487.  
  488.       done:
  489.       IntOp $R4 $R4 + $0
  490.       StrCpy $R1 $R2 $0
  491.       IntOp $0 $0 + 1
  492.       StrCpy $R2 $R2 "" $0
  493.       
  494.       StrCmp $2 1 0 +4
  495.         StrCmp $R1 "" 0 +3
  496.           StrCpy $R1 $1
  497.           Goto End
  498.  
  499.       StrCmp $R0 $R8 End
  500.         StrCmp $2 1 0 +2
  501.           StrCpy $1 $R1
  502.         StrCpy $R1 $R9
  503.         Goto PartLoop
  504.         
  505.       End:
  506.  
  507.       StrCpy $9 $R1
  508.  
  509.       Pop $2
  510.       Pop $1
  511.       Pop $0
  512.       Pop $R9
  513.       Pop $R8
  514.       Pop $R7
  515.       Pop $R6
  516.       Pop $R5
  517.       Pop $R4
  518.       Pop $R3
  519.       Pop $R2
  520.       Pop $R1
  521.       Pop $R0
  522.       Exch $9
  523.     FunctionEnd
  524.  
  525.   !endif
  526.  
  527. !macroend
  528.  
  529. !macro FUNCTION_STRING_StrTok_Call ResultVar StrToTokenize Separators ResultPart SkipEmptyParts
  530.  
  531.   !echo `$ {StrTok} "${ResultVar}" "${StrToTokenize}" "${Separators}" "${ResultPart}" "${SkipEmptyParts}"$\r$\n`
  532.  
  533.   Push `${StrToTokenize}`
  534.   Push `${Separators}`
  535.   Push `${ResultPart}`
  536.   Push `${SkipEmptyParts}`
  537.  
  538.   Call AdvancedStrTok
  539.  
  540.   Pop `${ResultVar}`
  541.  
  542. !macroend
  543.  
  544. !macro FUNCTION_STRING_StrClbSet
  545.  
  546.   !ifndef FUNCTION_STRING_StrClbSet
  547.  
  548.     !echo "$\r$\n----------------------------------------------------------------------$\r$\nCopy To Clipboard - 2003-2004 Nik Medved$\r$\n----------------------------------------------------------------------$\r$\n$\r$\n"
  549.  
  550.     !define FUNCTION_STRING_StrClbSet
  551.     !undef StrClbSet
  552.     
  553.     !define StrClbSet "!insertmacro FUNCTION_STRING_StrClb_Set"
  554.  
  555.     Function CopyToClipboard
  556.       Exch $0 ;input string
  557.       Push $1
  558.       Push $2
  559.       System::Call 'user32::OpenClipboard(i 0)'
  560.       System::Call 'user32::EmptyClipboard()'
  561.       StrLen $1 $0
  562.       IntOp $1 $1 + 1
  563.       System::Call 'kernel32::GlobalAlloc(i 2, i r1) i.r1'
  564.       System::Call 'kernel32::GlobalLock(i r1) i.r2'
  565.       System::Call 'kernel32::lstrcpyA(i r2, t r0)'
  566.       System::Call 'kernel32::GlobalUnlock(i r1)'
  567.       System::Call 'user32::SetClipboardData(i 1, i r1)'
  568.       System::Call 'user32::CloseClipboard()'
  569.       Pop $2
  570.       Pop $1
  571.       Pop $0
  572.     FunctionEnd
  573.  
  574.   !endif
  575.  
  576. !macroend
  577.  
  578. !macro FUNCTION_STRING_StrClbGet 
  579.  
  580.   !ifndef FUNCTION_STRING_StrClbGet
  581.  
  582.     !echo "$\r$\n----------------------------------------------------------------------$\r$\nCopy From Clipboard Function - 2003-2004 Nik Medved - changed by Diego Pedroso$\r$\n----------------------------------------------------------------------$\r$\n$\r$\n"
  583.  
  584.     !define FUNCTION_STRING_StrClbGet
  585.     !undef StrClbGet
  586.  
  587.     !define StrClbGet "!insertmacro FUNCTION_STRING_StrClb_Get"
  588.  
  589.     Function CopyFromClipboard
  590.       Push $0
  591.       System::Call 'user32::OpenClipboard(i 0)'
  592.       System::Call 'user32::GetClipboardData(i 1) t .r0'
  593.       System::Call 'user32::CloseClipboard()'
  594.       Exch $0
  595.     FunctionEnd
  596.  
  597.   !endif
  598.  
  599. !macroend
  600.  
  601. !macro FUNCTION_STRING_StrClb_Set String
  602.  
  603.   !echo `$ {StrClbSet} "${String}"$\r$\n`
  604.  
  605.   Push `${String}`
  606.  
  607.   Call CopyToClipboard
  608.   
  609. !macroend
  610.  
  611. !macro FUNCTION_STRING_StrClb_Get ResultVar
  612.  
  613.   !echo `$ {StrClbGet} "${ResultVar}"$\r$\n`
  614.  
  615.   Call CopyFromClipboard
  616.   
  617.   Pop `${ResultVar}`
  618.  
  619. !macroend
  620.  
  621. !macro FUNCTION_STRING_StrUpperCase
  622.  
  623.   !ifndef FUNCTION_STRING_StrUpperCase
  624.  
  625.     !echo "$\r$\n----------------------------------------------------------------------$\r$\nUppercase String Function - 2002-2004 Dave Laundon $\r$\n----------------------------------------------------------------------$\r$\n$\r$\n"
  626.  
  627.     !define FUNCTION_STRING_StrUpperCase
  628.     !undef StrUpperCase
  629.     !define StrUpperCase "!insertmacro FUNCTION_STRING_StrUpperCase_Call"
  630.  
  631.     Function StrUpper
  632.       Exch $0 ; Original string
  633.       Push $1 ; Final string
  634.       Push $2 ; Current character
  635.       Push $3
  636.       Push $4
  637.       StrCpy $1 ""
  638.     Loop:
  639.       StrCpy $2 $0 1 ; Get next character
  640.       StrCmp $2 "" Done
  641.       StrCpy $0 $0 "" 1
  642.       StrCpy $3 65 ; 65 = ASCII code for A
  643.     Loop2:
  644.       IntFmt $4 %c $3 ; Get character from current ASCII code
  645.       StrCmp $2 $4 Match
  646.       IntOp $3 $3 + 1
  647.       StrCmp $3 91 NoMatch Loop2 ; 91 = ASCII code one beyond Z
  648.     Match:
  649.       StrCpy $2 $4 ; It 'matches' (either case) so grab the uppercase version
  650.     NoMatch:
  651.       StrCpy $1 $1$2 ; Append to the final string
  652.       Goto Loop
  653.     Done:
  654.       StrCpy $0 $1 ; Return the final string
  655.       Pop $4
  656.       Pop $3
  657.       Pop $2
  658.       Pop $1
  659.       Exch $0
  660.     FunctionEnd
  661.  
  662.   !endif
  663.  
  664. !macroend
  665.  
  666. !macro FUNCTION_STRING_StrUpperCase_Call ResultVar String
  667.  
  668.   !echo `$ {StrUpperCase} "${ResultVar}" "${String}"$\r$\n`
  669.  
  670.   Push `${String}`
  671.  
  672.   Call StrUpper
  673.  
  674.   Pop `${ResultVar}`
  675.  
  676. !macroend
  677.  
  678. !macro FUNCTION_STRING_StrLowerCase
  679.  
  680.   !ifndef FUNCTION_STRING_StrLowerCase
  681.  
  682.     !echo "$\r$\n----------------------------------------------------------------------$\r$\nLowercase String Function - changed from Uppercase String Function 2002-2004 Dave Laundon$\r$\n----------------------------------------------------------------------$\r$\n$\r$\n"
  683.  
  684.     !define FUNCTION_STRING_StrLowerCase
  685.     !undef StrLowerCase
  686.     !define StrLowerCase "!insertmacro FUNCTION_STRING_StrLowerCase_Call"
  687.  
  688.     Function StrLower
  689.       Exch $0 ; Original string
  690.       Push $1 ; Final string
  691.       Push $2 ; Current character
  692.       Push $3
  693.       Push $4
  694.       StrCpy $1 ""
  695.     Loop:
  696.       StrCpy $2 $0 1 ; Get next character
  697.       StrCmp $2 "" Done
  698.       StrCpy $0 $0 "" 1
  699.       StrCpy $3 122 ; 122 = ASCII code for z
  700.     Loop2:
  701.       IntFmt $4 %c $3 ; Get character from current ASCII code
  702.       StrCmp $2 $4 Match
  703.       IntOp $3 $3 - 1
  704.       StrCmp $3 91 NoMatch Loop2 ; 90 = ASCII code one beyond Z
  705.     Match:
  706.       StrCpy $2 $4 ; It 'matches' (either case) so grab the lowercase version
  707.     NoMatch:
  708.       StrCpy $1 $1$2 ; Append to the final string
  709.       Goto Loop
  710.     Done:
  711.       StrCpy $0 $1 ; Return the final string
  712.       Pop $4
  713.       Pop $3
  714.       Pop $2
  715.       Pop $1
  716.       Exch $0
  717.     FunctionEnd
  718.  
  719.   !endif
  720.  
  721. !macroend
  722.  
  723. !macro FUNCTION_STRING_StrLowerCase_Call ResultVar String
  724.  
  725.   !echo `$ {StrLowerCase} "${ResultVar}" "${String}"$\r$\n`
  726.  
  727.   Push `${String}`
  728.  
  729.   Call StrLower
  730.  
  731.   Pop `${ResultVar}`
  732.  
  733. !macroend
  734.  
  735. !macro FUNCTION_STRING_StrRep
  736.  
  737.   !ifndef FUNCTION_STRING_StrRep
  738.  
  739.     !echo "$\r$\n----------------------------------------------------------------------$\r$\nReplace String Function - 2002-2004 Hendri Adriaens$\r$\n----------------------------------------------------------------------$\r$\n$\r$\n"
  740.  
  741.     !define FUNCTION_STRING_StrRep
  742.     !undef StrRep
  743.     !define StrRep "!insertmacro FUNCTION_STRING_StrRep_Call"
  744.  
  745.     Function StrReplace
  746.       Exch $0 ;this will replace wrong characters
  747.       Exch
  748.       Exch $1 ;needs to be replaced
  749.       Exch
  750.       Exch 2
  751.       Exch $2 ;the orginal string
  752.       Push $3 ;counter
  753.       Push $4 ;temp character
  754.       Push $5 ;temp string
  755.       Push $6 ;length of string that need to be replaced
  756.       Push $7 ;length of string that will replace
  757.       Push $R0 ;tempstring
  758.       Push $R1 ;tempstring
  759.       Push $R2 ;tempstring
  760.       StrCpy $3 "-1"
  761.       StrCpy $5 ""
  762.       StrLen $6 $1
  763.       StrLen $7 $0
  764.       Loop:
  765.       IntOp $3 $3 + 1
  766.       StrCpy $4 $2 $6 $3
  767.       StrCmp $4 "" ExitLoop
  768.       StrCmp $4 $1 Replace
  769.       Goto Loop
  770.       Replace:
  771.       StrCpy $R0 $2 $3
  772.       IntOp $R2 $3 + $6
  773.       StrCpy $R1 $2 "" $R2
  774.       StrCpy $2 $R0$0$R1
  775.       IntOp $3 $3 + $7
  776.       Goto Loop
  777.       ExitLoop:
  778.       StrCpy $0 $2
  779.       Pop $R2
  780.       Pop $R1
  781.       Pop $R0
  782.       Pop $7
  783.       Pop $6
  784.       Pop $5
  785.       Pop $4
  786.       Pop $3
  787.       Pop $2
  788.       Pop $1
  789.       Exch $0
  790.     FunctionEnd
  791.  
  792.   !endif
  793.  
  794. !macroend
  795.  
  796. !macro FUNCTION_STRING_StrRep_Call ResultVar String StringToReplace ReplacementString
  797.  
  798.   !echo `$ {StrRep} "${ResultVar}" "${String}" "${StringToReplace}" "${ReplacementString}"$\r$\n`
  799.  
  800.   Push `${String}`
  801.   Push `${StringToReplace}`
  802.   Push `${ReplacementString}`
  803.  
  804.   Call StrReplace
  805.  
  806.   Pop `${ResultVar}`
  807.  
  808. !macroend
  809.  
  810. !macro FUNCTION_STRING_StrSort
  811.  
  812.   !ifndef FUNCTION_STRING_StrSort
  813.  
  814.     !echo "$\r$\n----------------------------------------------------------------------$\r$\nAdvanced String Sort Function - ⌐ 2004 Diego Pedroso$\r$\n----------------------------------------------------------------------$\r$\n$\r$\n"
  815.  
  816.     !define FUNCTION_STRING_StrSort
  817.     !undef StrSort
  818.     !define StrSort "!insertmacro FUNCTION_STRING_StrSort_Call"
  819.  
  820.     Function AdvStrSort
  821.  
  822.       # Prepare Variables
  823.  
  824.       Exch $R7 ;Include Center string
  825.       Exch
  826.       Exch $R6 ;Include Left and Right strings
  827.       Exch 2
  828.       Exch $0 ;Right String
  829.       Exch 3
  830.       Exch $1 ;Left String
  831.       Exch 4
  832.       Exch $2 ;Center String
  833.       Exch 5
  834.       Exch $R0 ;String
  835.       Push $3
  836.       Push $4
  837.       Push $5
  838.       Push $R1
  839.       Push $R2
  840.       Push $R3
  841.       Push $R4
  842.       Push $R5
  843.  
  844.       StrLen $3 $0
  845.       StrLen $4 $1
  846.       StrLen $5 $2
  847.       StrCpy $R1 0
  848.  
  849.       # Center String Search
  850.  
  851.       loop:
  852.         StrCpy $R3 $R0 $5 $R1
  853.         StrCmp $R3 "" error
  854.           StrCmp $R3 $2 done
  855.             IntOp $R1 $R1 + 1
  856.             Goto loop
  857.       done:
  858.  
  859.       StrCpy $R5 $R1
  860.  
  861.       IntOp $R1 $R1 - $4
  862.  
  863.       # Left String Search
  864.  
  865.       loop2:
  866.         StrCpy $R3 $R0 $4 $R1
  867.         StrCmp $R3 "" error2
  868.           StrCmp $R3 $1 done2
  869.             IntOp $R1 $R1 - 1
  870.             Goto loop2
  871.  
  872.         error2:
  873.         StrCpy $R1 0
  874.         StrCpy $R3 0
  875.         Goto +2
  876.  
  877.       done2:
  878.       StrCpy $R3 1
  879.  
  880.       StrCpy $R4 $R0 $R5
  881.  
  882.       StrCmp $R1 0 +2
  883.         StrCpy $R4 $R4 "" $R1
  884.  
  885.       StrCmp $R3 1 0 +3
  886.         StrCmp $R6 0 0 +2
  887.           StrCpy $R4 $R4 "" $4
  888.  
  889.       # Center String Addition
  890.  
  891.       StrCmp $R7 0 +2
  892.         StrCpy $R4 $R4$2
  893.  
  894.       StrCpy $R1 $R5
  895.       IntOp $R1 $R1 + $5
  896.  
  897.       # Right String Search
  898.  
  899.       loop3:
  900.  
  901.         StrCpy $R3 $R0 $3 $R1
  902.         StrCmp $R3 "" error3
  903.           StrCmp $R3 $0 done3
  904.             IntOp $R1 $R1 + 1
  905.             Goto loop3
  906.  
  907.         error3:
  908.         StrCpy $R1 0
  909.  
  910.       done3:
  911.  
  912.       IntOp $R5 $R5 + $5
  913.       StrCpy $R3 $R0 "" $R5
  914.  
  915.       StrCmp $R1 0 +5
  916.         IntOp $R1 $R1 - $R5
  917.         StrCmp $R6 0 +2
  918.           IntOp $R1 $R1 + $3
  919.         StrCpy $R3 $R3 $R1
  920.  
  921.       StrCpy $R4 $R4$R3
  922.  
  923.       StrCpy $2 $R4
  924.       Goto +2
  925.  
  926.         Error:
  927.         StrCpy $2 ""
  928.  
  929.       # Return to User
  930.  
  931.       Pop $R5
  932.       Pop $R4
  933.       Pop $R3
  934.       Pop $R2
  935.       Pop $R1
  936.       Pop $5
  937.       Pop $4
  938.       Pop $3
  939.       Pop $R0
  940.       Pop $R7
  941.       Pop $R6
  942.       Pop $0
  943.       Pop $1
  944.       Exch $2
  945.  
  946.     FunctionEnd
  947.  
  948.   !endif
  949.  
  950. !macroend
  951.  
  952. !macro FUNCTION_STRING_StrSort_Call ResultVar String CenterStr LeftStr RightStr IncludeLeftRightStr IncludeCenterStr
  953.  
  954.   !echo `$ {StrSort} "${ResultVar}" "${String}" "${CenterStr}" "${LeftStr}" "${RightStr}" "${IncludeLeftRightStr}" "${IncludeCenterStr}"$\r$\n`
  955.  
  956.   Push `${String}`
  957.   Push `${CenterStr}`
  958.   Push `${LeftStr}`
  959.   Push `${RightStr}`
  960.   Push `${IncludeLeftRightStr}`
  961.   Push `${IncludeCenterStr}`
  962.  
  963.   Call AdvStrSort
  964.  
  965.   Pop `${ResultVar}`
  966.  
  967. !macroend
  968.  
  969. !macro FUNCTION_STRING_StrTrimNewLines
  970.  
  971.   !ifndef FUNCTION_STRING_StrTrimNewLines
  972.  
  973.     !echo "$\r$\n----------------------------------------------------------------------$\r$\nTrim New Lines Function - 2003-2004 Ximon Eighteen$\r$\n----------------------------------------------------------------------$\r$\n$\r$\n"
  974.  
  975.     !define FUNCTION_STRING_StrTrimNewLines
  976.     !undef StrTrimNewLines
  977.     !define StrTrimNewLines "!insertmacro FUNCTION_STRING_StrTrimNewLines_Call"
  978.  
  979.     Function TrimNewlines
  980.       Exch $R0
  981.       Push $R1
  982.       Push $R2
  983.       StrCpy $R1 0
  984.  
  985.     loop:
  986.       IntOp $R1 $R1 - 1
  987.       StrCpy $R2 $R0 1 $R1
  988.       StrCmp $R2 "$\r" loop
  989.       StrCmp $R2 "$\n" loop
  990.  
  991.       IntOp $R1 $R1 + 1
  992.       IntCmp $R1 0 no_trim_needed
  993.       StrCpy $R0 $R0 $R1
  994.  
  995.     no_trim_needed:
  996.       Pop $R2
  997.       Pop $R1
  998.       Exch $R0
  999.     FunctionEnd
  1000.  
  1001.   !endif
  1002.  
  1003. !macroend
  1004.  
  1005. !macro FUNCTION_STRING_StrTrimNewLines_Call ResultVar String
  1006.  
  1007.   !echo `$ {StrTrimNewLines} "${ResultVar}" "${String}"$\r$\n`
  1008.  
  1009.   Push `${String}`
  1010.  
  1011.   Call TrimNewLines
  1012.  
  1013.   Pop `${ResultVar}`
  1014.  
  1015. !macroend
  1016.  
  1017. !macro FUNCTION_STRING_StrNSISToIO
  1018.  
  1019.   !ifndef FUNCTION_STRING_StrNSISToIO
  1020.  
  1021.     !echo "$\r$\n----------------------------------------------------------------------$\r$\nNSIS -> Install Options String Convertion Function - 2003-2004 Amir Szekely, Joost Verburg and Dave Laundon$\r$\n----------------------------------------------------------------------$\r$\n$\r$\n"
  1022.  
  1023.     !define FUNCTION_STRING_StrNSISToIO
  1024.     !undef StrNSISToIO
  1025.     !define StrNSISToIO "!insertmacro FUNCTION_STRING_StrNSISToIO_Call"
  1026.  
  1027.     Function Nsis2Io
  1028.       Exch $0 ; The source
  1029.       Push $1 ; The output
  1030.       Push $2 ; Temporary char
  1031.       StrCpy $1 "" ; Initialise the output
  1032.     loop:
  1033.       StrCpy $2 $0 1 ; Get the next source char
  1034.       StrCmp $2 "" done ; Abort when none left
  1035.         StrCpy $0 $0 "" 1 ; Remove it from the source
  1036.         StrCmp $2 "\" "" +3 ; Back-slash?
  1037.           StrCpy $1 "$1\\"
  1038.           Goto loop
  1039.         StrCmp $2 "$\r" "" +3 ; Carriage return?
  1040.           StrCpy $1 "$1\r"
  1041.           Goto loop
  1042.         StrCmp $2 "$\n" "" +3 ; Line feed?
  1043.           StrCpy $1 "$1\n"
  1044.           Goto loop
  1045.         StrCmp $2 "$\t" "" +3 ; Tab?
  1046.           StrCpy $1 "$1\t"
  1047.           Goto loop
  1048.         StrCpy $1 "$1$2" ; Anything else
  1049.         Goto loop
  1050.     done:
  1051.       StrCpy $0 $1
  1052.       Pop $2
  1053.       Pop $1
  1054.       Exch $0
  1055.     FunctionEnd
  1056.  
  1057.   !endif
  1058.  
  1059. !macroend
  1060.  
  1061. !macro FUNCTION_STRING_StrNSISToIO_Call ResultVar String
  1062.  
  1063.   !echo `$ {StrNSISToIO} "${ResultVar}" "${String}"$\r$\n`
  1064.  
  1065.   Push `${String}`
  1066.  
  1067.   Call NSIS2IO
  1068.  
  1069.   Pop `${ResultVar}`
  1070.  
  1071. !macroend
  1072.  
  1073. !macro FUNCTION_STRING_StrIOToNSIS
  1074.  
  1075.   !ifndef FUNCTION_STRING_StrIOToNSIS
  1076.  
  1077.     !echo "$\r$\n----------------------------------------------------------------------$\r$\nInstall Options -> NSIS String Convertion Function - 2003-2004 Amir Szekely, Joost Verburg and Dave Laundon$\r$\n----------------------------------------------------------------------$\r$\n$\r$\n"
  1078.  
  1079.     !define FUNCTION_STRING_StrIOToNSIS
  1080.     !undef StrIOToNSIS
  1081.     !define StrIOToNSIS "!insertmacro FUNCTION_STRING_StrIOToNSIS_Call"
  1082.  
  1083.     Function Io2Nsis
  1084.       Exch $0 ; The source
  1085.       Push $1 ; The output
  1086.       Push $2 ; Temporary char
  1087.       StrCpy $1 "" ; Initialise the output
  1088.     loop:
  1089.       StrCpy $2 $0 1 ; Get the next source char
  1090.       StrCmp $2 "" done ; Abort when none left
  1091.         StrCpy $0 $0 "" 1 ; Remove it from the source
  1092.         StrCmp $2 "\" +3 ; Escape character?
  1093.           StrCpy $1 "$1$2" ; If not just output
  1094.           Goto loop
  1095.         StrCpy $2 $0 1 ; Get the next source char
  1096.         StrCpy $0 $0 "" 1 ; Remove it from the source
  1097.         StrCmp $2 "\" "" +3 ; Back-slash?
  1098.           StrCpy $1 "$1\"
  1099.           Goto loop
  1100.         StrCmp $2 "r" "" +3 ; Carriage return?
  1101.           StrCpy $1 "$1$\r"
  1102.           Goto loop
  1103.         StrCmp $2 "n" "" +3 ; Line feed?
  1104.           StrCpy $1 "$1$\n"
  1105.           Goto loop
  1106.         StrCmp $2 "t" "" +3 ; Tab?
  1107.           StrCpy $1 "$1$\t"
  1108.           Goto loop
  1109.         StrCpy $1 "$1$2" ; Anything else (should never get here)
  1110.         Goto loop
  1111.     done:
  1112.       StrCpy $0 $1
  1113.       Pop $2
  1114.       Pop $1
  1115.       Exch $0
  1116.     FunctionEnd
  1117.  
  1118.   !endif
  1119.  
  1120. !macroend
  1121.  
  1122. !macro FUNCTION_STRING_StrIOToNSIS_Call ResultVar String
  1123.  
  1124.   !echo `$ {StrIOToNSIS} "${ResultVar}" "${String}"$\r$\n`
  1125.  
  1126.   Push `${String}`
  1127.  
  1128.   Call IO2NSIS
  1129.  
  1130.   Pop `${ResultVar}`
  1131.  
  1132. !macroend
  1133.  
  1134. !ifndef MUI_VERBOSE
  1135.   !define MUI_VERBOSE 4
  1136. !endif
  1137.