StrFunc.nsh 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761
  1. /*
  2. o-----------------------------------------------------------------------------o
  3. |String Functions Header File 1.09 |
  4. (-----------------------------------------------------------------------------)
  5. | By deguix / A Header file for NSIS 2.01 |
  6. | <cevo_deguix@yahoo.com.br> -------------------------------|
  7. | |
  8. | This header file contains NSIS functions for string manipulation. |
  9. o-----------------------------------------------------------------------------o
  10. */
  11. !verbose push 3
  12. !define /IfNDef STRFUNC_VERBOSITY 3
  13. !define /IfNDef _STRFUNC_VERBOSITY ${STRFUNC_VERBOSITY}
  14. !define /IfNDef _STRFUNC_CREDITVERBOSITY ${STRFUNC_VERBOSITY}
  15. !undef STRFUNC_VERBOSITY
  16. !verbose ${_STRFUNC_VERBOSITY}
  17. !include LogicLib.nsh
  18. !ifndef STRFUNC
  19. !define /IfNDef FALSE 0
  20. !define /IfNDef TRUE 1
  21. ;Header File Identification
  22. !define STRFUNC `String Functions Header File`
  23. !define STRFUNC_SHORT `StrFunc`
  24. !define STRFUNC_CREDITS `2004 Diego Pedroso`
  25. ;Header File Version
  26. !define STRFUNC_VERMAJ 1
  27. !define STRFUNC_VERMED 09
  28. ;!define STRFUNC_VERMIN 0
  29. ;!define STRFUNC_VERBLD 0
  30. !define STRFUNC_VER `${STRFUNC_VERMAJ}.${STRFUNC_VERMED}`
  31. ;Header File Init Message Prefix and Postfix
  32. !define STRFUNC_INITMSGPRE `----------------------------------------------------------------------$\r$\n`
  33. !define STRFUNC_INITMSGPOST `$\r$\n----------------------------------------------------------------------$\r$\n`
  34. ;Header File Init Message
  35. !verbose push ${_STRFUNC_CREDITVERBOSITY}
  36. !echo `${STRFUNC_INITMSGPRE}NSIS ${STRFUNC} ${STRFUNC_VER} - Copyright ${STRFUNC_CREDITS}${STRFUNC_INITMSGPOST}`
  37. !verbose pop
  38. ;Header File Function Init Message Prefix and Postfix
  39. !define STRFUNC_FUNCMSGPRE ``
  40. !define STRFUNC_FUNCMSGPOST ``
  41. ;Header File Function Macros
  42. !macro STRFUNC_FUNCLIST_INSERT Name
  43. !ifdef StrFunc_List
  44. !define StrFunc_List2 `${StrFunc_List}`
  45. !undef StrFunc_List
  46. !define StrFunc_List `${StrFunc_List2}|${Name}`
  47. !undef StrFunc_List2
  48. !else
  49. !define StrFunc_List `${Name}`
  50. !endif
  51. !macroend
  52. !macro STRFUNC_DEFFUNC Name
  53. !insertmacro STRFUNC_FUNCLIST_INSERT ${Name}
  54. !define `${Name}` `!insertmacro FUNCTION_STRING_${Name}`
  55. !define `Un${Name}` `!insertmacro FUNCTION_STRING_Un${Name}`
  56. !macroend
  57. !macro STRFUNC_FUNC ShortName Credits
  58. !verbose push ${_STRFUNC_CREDITVERBOSITY}
  59. !ifndef `Un${ShortName}`
  60. !echo `${STRFUNC_FUNCMSGPRE}$ {Un${ShortName}} - Copyright ${Credits}${STRFUNC_FUNCMSGPOST}`
  61. !verbose pop
  62. !define `Un${ShortName}` `!insertmacro FUNCTION_STRING_Un${ShortName}_Call`
  63. !define `Un${ShortName}_INCLUDED`
  64. Function `un.${ShortName}`
  65. !else
  66. !echo `${STRFUNC_FUNCMSGPRE}$ {${ShortName}} - Copyright ${Credits}${STRFUNC_FUNCMSGPOST}`
  67. !verbose pop
  68. !undef `${ShortName}`
  69. !define `${ShortName}` `!insertmacro FUNCTION_STRING_${ShortName}_Call`
  70. !define `${ShortName}_INCLUDED`
  71. Function `${ShortName}`
  72. !endif
  73. !macroend
  74. ;Function Names Startup Definition
  75. !insertmacro STRFUNC_DEFFUNC StrCase
  76. !define StrCase_List `ResultVar|String|Type`
  77. !define StrCase_TypeList `Output|Text|Option U L T S <>`
  78. !macro `FUNCTION_STRING_UnStrCase`
  79. !undef UnStrCase
  80. !insertmacro FUNCTION_STRING_StrCase
  81. !macroend
  82. !insertmacro STRFUNC_DEFFUNC StrClb
  83. !define StrClb_List `ResultVar|String|Action`
  84. !define StrClb_TypeList `Output|Text|Option > < <>`
  85. !macro `FUNCTION_STRING_UnStrClb`
  86. !undef UnStrClb
  87. !insertmacro FUNCTION_STRING_StrClb
  88. !macroend
  89. !insertmacro STRFUNC_DEFFUNC StrIOToNSIS
  90. !define StrIOToNSIS_List `ResultVar|String`
  91. !define StrIOToNSIS_TypeList `Output|Text`
  92. !macro `FUNCTION_STRING_UnStrIOToNSIS`
  93. !undef UnStrIOToNSIS
  94. !insertmacro FUNCTION_STRING_StrIOToNSIS
  95. !macroend
  96. !insertmacro STRFUNC_DEFFUNC StrLoc
  97. !define StrLoc_List `ResultVar|String|StrToSearchFor|CounterDirection`
  98. !define StrLoc_TypeList `Output|Text|Text|Option > <`
  99. !macro `FUNCTION_STRING_UnStrLoc`
  100. !undef UnStrLoc
  101. !insertmacro FUNCTION_STRING_StrLoc
  102. !macroend
  103. !insertmacro STRFUNC_DEFFUNC StrNSISToIO
  104. !define StrNSISToIO_List `ResultVar|String`
  105. !define StrNSISToIO_TypeList `Output|Text`
  106. !macro `FUNCTION_STRING_UnStrNSISToIO`
  107. !undef UnStrNSISToIO
  108. !insertmacro FUNCTION_STRING_StrNSISToIO
  109. !macroend
  110. !insertmacro STRFUNC_DEFFUNC StrRep
  111. !define StrRep_List `ResultVar|String|StrToReplace|ReplacementString`
  112. !define StrRep_TypeList `Output|Text|Text|Text`
  113. !macro `FUNCTION_STRING_UnStrRep`
  114. !undef UnStrRep
  115. !insertmacro FUNCTION_STRING_StrRep
  116. !macroend
  117. !insertmacro STRFUNC_DEFFUNC StrSort
  118. !define StrSort_List `ResultVar|String|LeftStr|CenterStr|RightStr|IncludeLeftStr|IncludeCenterStr|IncludeRightStr`
  119. !define StrSort_TypeList `Output|Text|Text|Text|Text|Option 1 0|Option 1 0|Option 1 0`
  120. !macro `FUNCTION_STRING_UnStrSort`
  121. !undef UnStrSort
  122. !insertmacro FUNCTION_STRING_StrSort
  123. !macroend
  124. !insertmacro STRFUNC_DEFFUNC StrStr
  125. !define StrStr_List `ResultVar|String|StrToSearchFor`
  126. !define StrStr_TypeList `Output|Text|Text`
  127. !macro `FUNCTION_STRING_UnStrStr`
  128. !undef UnStrStr
  129. !insertmacro FUNCTION_STRING_StrStr
  130. !macroend
  131. !insertmacro STRFUNC_DEFFUNC StrStrAdv
  132. !define StrStrAdv_List `ResultVar|String|StrToSearchFor|SearchDirection|ResultStrDirection|DisplayStrToSearch|Loops|CaseSensitive`
  133. !define StrStrAdv_TypeList `Output|Text|Text|Option > <|Option > <|Option 1 0|Text|Option 0 1`
  134. !macro `FUNCTION_STRING_UnStrStrAdv`
  135. !undef UnStrStrAdv
  136. !insertmacro FUNCTION_STRING_StrStrAdv
  137. !macroend
  138. !insertmacro STRFUNC_DEFFUNC StrTok
  139. !define StrTok_List `ResultVar|String|Separators|ResultPart|SkipEmptyParts`
  140. !define StrTok_TypeList `Output|Text|Text|Mixed L|Option 1 0`
  141. !macro `FUNCTION_STRING_UnStrTok`
  142. !undef UnStrTok
  143. !insertmacro FUNCTION_STRING_StrTok
  144. !macroend
  145. !insertmacro STRFUNC_DEFFUNC StrTrimNewLines
  146. !define StrTrimNewLines_List `ResultVar|String`
  147. !define StrTrimNewLines_TypeList `Output|Text`
  148. !macro `FUNCTION_STRING_UnStrTrimNewLines`
  149. !undef UnStrTrimNewLines
  150. !insertmacro FUNCTION_STRING_StrTrimNewLines
  151. !macroend
  152. ;Function Codes for Install and Uninstall
  153. # Function StrCase
  154. ################
  155. !macro FUNCTION_STRING_StrCase
  156. !insertmacro STRFUNC_FUNC `StrCase` `2004 Diego Pedroso - Based on functions by Dave Laundon`
  157. /*After this point:
  158. ------------------------------------------
  159. $0 = String (input)
  160. $1 = Type (input)
  161. $2 = StrLength (temp)
  162. $3 = StartChar (temp)
  163. $4 = EndChar (temp)
  164. $5 = ResultStr (temp)
  165. $6 = CurrentChar (temp)
  166. $7 = LastChar (temp)
  167. $8 = Temp (temp)*/
  168. ;Get input from user
  169. Exch $1
  170. Exch
  171. Exch $0
  172. Exch
  173. Push $2
  174. Push $3
  175. Push $4
  176. Push $5
  177. Push $6
  178. Push $7
  179. Push $8
  180. ;Initialize variables
  181. StrCpy $2 ""
  182. StrCpy $3 ""
  183. StrCpy $4 ""
  184. StrCpy $5 ""
  185. StrCpy $6 ""
  186. StrCpy $7 ""
  187. StrCpy $8 ""
  188. ;Upper and lower cases are simple to use
  189. ${If} $1 == "U"
  190. ;Upper Case System:
  191. ;------------------
  192. ; Convert all characters to upper case.
  193. System::Call "User32::CharUpper(t r0 r5)i"
  194. Goto StrCase_End
  195. ${ElseIf} $1 == "L"
  196. ;Lower Case System:
  197. ;------------------
  198. ; Convert all characters to lower case.
  199. System::Call "User32::CharLower(t r0 r5)i"
  200. Goto StrCase_End
  201. ${EndIf}
  202. ;For the rest of cases:
  203. ;Get "String" length
  204. StrLen $2 $0
  205. ;Make a loop until the end of "String"
  206. ${For} $3 0 $2
  207. ;Add 1 to "EndChar" counter also
  208. IntOp $4 $3 + 1
  209. # Step 1: Detect one character at a time
  210. ;Remove characters before "StartChar" except when
  211. ;"StartChar" is the first character of "String"
  212. ${If} $3 <> 0
  213. StrCpy $6 $0 `` $3
  214. ${EndIf}
  215. ;Remove characters after "EndChar" except when
  216. ;"EndChar" is the last character of "String"
  217. ${If} $4 <> $2
  218. ${If} $3 = 0
  219. StrCpy $6 $0 1
  220. ${Else}
  221. StrCpy $6 $6 1
  222. ${EndIf}
  223. ${EndIf}
  224. # Step 2: Convert to the advanced case user chose:
  225. ${If} $1 == "T"
  226. ;Title Case System:
  227. ;------------------
  228. ; Convert all characters after a non-alphabetic character to upper case.
  229. ; Else convert to lower case.
  230. ;Use "IsCharAlpha" for the job
  231. System::Call "*(&t1 r7) p .r8"
  232. System::Call "*$8(&i1 .r7)"
  233. System::Free $8
  234. System::Call "user32::IsCharAlpha(i r7) i .r8"
  235. ;Verify "IsCharAlpha" result and convert the character
  236. ${If} $8 = 0
  237. System::Call "User32::CharUpper(t r6 r6)i"
  238. ${Else}
  239. System::Call "User32::CharLower(t r6 r6)i"
  240. ${EndIf}
  241. ${ElseIf} $1 == "S"
  242. ;Sentence Case System:
  243. ;------------------
  244. ; Convert all characters after a ".", "!" or "?" character to upper case.
  245. ; Else convert to lower case. Spaces or tabs after these marks are ignored.
  246. ;Detect current characters and ignore if necessary
  247. ${If} $6 == " "
  248. ${OrIf} $6 == "$\t"
  249. Goto IgnoreLetter
  250. ${EndIf}
  251. ;Detect last characters and convert
  252. ${If} $7 == "."
  253. ${OrIf} $7 == "!"
  254. ${OrIf} $7 == "?"
  255. ${OrIf} $7 == ""
  256. System::Call "User32::CharUpper(t r6 r6)i"
  257. ${Else}
  258. System::Call "User32::CharLower(t r6 r6)i"
  259. ${EndIf}
  260. ${ElseIf} $1 == "<>"
  261. ;Switch Case System:
  262. ;------------------
  263. ; Switch all characters cases to their inverse case.
  264. ;Use "IsCharUpper" for the job
  265. System::Call "*(&t1 r6) p .r8"
  266. System::Call "*$8(&i1 .r7)"
  267. System::Free $8
  268. System::Call "user32::IsCharUpper(i r7) i .r8"
  269. ;Verify "IsCharUpper" result and convert the character
  270. ${If} $8 = 0
  271. System::Call "User32::CharUpper(t r6 r6)i"
  272. ${Else}
  273. System::Call "User32::CharLower(t r6 r6)i"
  274. ${EndIf}
  275. ${EndIf}
  276. ;Write the character to "LastChar"
  277. StrCpy $7 $6
  278. IgnoreLetter:
  279. ;Add this character to "ResultStr"
  280. StrCpy $5 `$5$6`
  281. ${Next}
  282. StrCase_End:
  283. /*After this point:
  284. ------------------------------------------
  285. $0 = OutVar (output)*/
  286. ; Copy "ResultStr" to "OutVar"
  287. StrCpy $0 $5
  288. ;Return output to user
  289. Pop $8
  290. Pop $7
  291. Pop $6
  292. Pop $5
  293. Pop $4
  294. Pop $3
  295. Pop $2
  296. Pop $1
  297. Exch $0
  298. FunctionEnd
  299. !macroend
  300. !macro FUNCTION_STRING_StrClb
  301. !insertmacro STRFUNC_FUNC `StrClb` `2004 Diego Pedroso - Based on functions by Nik Medved`
  302. /*After this point:
  303. ------------------------------------------
  304. $0 = String (input)
  305. $1 = Action (input)
  306. $2 = Lock/Unlock (temp)
  307. $3 = Temp (temp)
  308. $4 = Temp2 (temp)*/
  309. ;Get input from user
  310. Exch $1
  311. Exch
  312. Exch $0
  313. Exch
  314. Push $2
  315. Push $3
  316. Push $4
  317. StrCpy $2 ""
  318. StrCpy $3 ""
  319. StrCpy $4 ""
  320. ;Open the clipboard to do the operations the user chose (kichik's fix)
  321. System::Call 'user32::OpenClipboard(p $HWNDPARENT)'
  322. ${If} $1 == ">" ;Set
  323. ;Step 1: Clear the clipboard
  324. System::Call 'user32::EmptyClipboard()'
  325. ;Step 2: Allocate global heap
  326. StrLen $2 $0
  327. IntOp $2 $2 + 1
  328. IntOp $2 $2 * ${NSIS_CHAR_SIZE}
  329. System::Call 'kernel32::GlobalAlloc(i 2, i r2) p.r2'
  330. ;Step 3: Lock the handle
  331. System::Call 'kernel32::GlobalLock(p r2) i.r3'
  332. ;Step 4: Copy the text to locked clipboard buffer
  333. System::Call 'kernel32::lstrcpy(p r3, t r0)'
  334. ;Step 5: Unlock the handle again
  335. System::Call 'kernel32::GlobalUnlock(p r2)'
  336. ;Step 6: Set the information to the clipboard
  337. System::Call 'user32::SetClipboardData(i 1, p r2)'
  338. StrCpy $0 ""
  339. ${ElseIf} $1 == "<" ;Get
  340. ;Step 1: Get clipboard data
  341. System::Call 'user32::GetClipboardData(i 1) p .r2'
  342. ;Step 2: Lock and copy data (kichik's fix)
  343. System::Call 'kernel32::GlobalLock(p r2) t .r0'
  344. ;Step 3: Unlock (kichik's fix)
  345. System::Call 'kernel32::GlobalUnlock(p r2)'
  346. ${ElseIf} $1 == "<>" ;Swap
  347. ;Step 1: Get clipboard data
  348. System::Call 'user32::GetClipboardData(i 1) p .r2'
  349. ;Step 2: Lock and copy data (kichik's fix)
  350. System::Call 'kernel32::GlobalLock(p r2) t .r4'
  351. ;Step 3: Unlock (kichik's fix)
  352. System::Call 'kernel32::GlobalUnlock(p r2)'
  353. ;Step 4: Clear the clipboard
  354. System::Call 'user32::EmptyClipboard()'
  355. ;Step 5: Allocate global heap
  356. StrLen $2 $0
  357. IntOp $2 $2 + 1
  358. IntOp $2 $2 * ${NSIS_CHAR_SIZE}
  359. System::Call 'kernel32::GlobalAlloc(i 2, i r2) p.r2'
  360. ;Step 6: Lock the handle
  361. System::Call 'kernel32::GlobalLock(p r2) i.r3'
  362. ;Step 7: Copy the text to locked clipboard buffer
  363. System::Call 'kernel32::lstrcpy(p r3, t r0)'
  364. ;Step 8: Unlock the handle again
  365. System::Call 'kernel32::GlobalUnlock(p r2)'
  366. ;Step 9: Set the information to the clipboard
  367. System::Call 'user32::SetClipboardData(i 1, p r2)'
  368. StrCpy $0 $4
  369. ${Else} ;Clear
  370. ;Step 1: Clear the clipboard
  371. System::Call 'user32::EmptyClipboard()'
  372. StrCpy $0 ""
  373. ${EndIf}
  374. ;Close the clipboard
  375. System::Call 'user32::CloseClipboard()'
  376. /*After this point:
  377. ------------------------------------------
  378. $0 = OutVar (output)*/
  379. ;Return result to user
  380. Pop $4
  381. Pop $3
  382. Pop $2
  383. Pop $1
  384. Exch $0
  385. FunctionEnd
  386. !macroend
  387. # Function StrIOToNSIS
  388. ####################
  389. !macro FUNCTION_STRING_StrIOToNSIS
  390. !insertmacro STRFUNC_FUNC `StrIOToNSIS` `2004 "bluenet" - Based on functions by Amir Szekely, Joost Verburg, Dave Laundon and Diego Pedroso`
  391. /*After this point:
  392. ------------------------------------------
  393. $R0 = String (input/output)
  394. $R1 = StartCharPos (temp)
  395. $R2 = StrLen (temp)
  396. $R3 = TempStr (temp)
  397. $R4 = TempRepStr (temp)*/
  398. ;Get input from user
  399. Exch $R0
  400. Push $R1
  401. Push $R2
  402. Push $R3
  403. Push $R4
  404. ;Get "String" length
  405. StrLen $R2 $R0
  406. ;Loop until "String" end is reached
  407. ${For} $R1 0 $R2
  408. ;Get the next "String" characters
  409. StrCpy $R3 $R0 2 $R1
  410. ;Detect if current character is:
  411. ${If} $R3 == "\\" ;Back-slash
  412. StrCpy $R4 "\"
  413. ${ElseIf} $R3 == "\r" ;Carriage return
  414. StrCpy $R4 "$\r"
  415. ${ElseIf} $R3 == "\n" ;Line feed
  416. StrCpy $R4 "$\n"
  417. ${ElseIf} $R3 == "\t" ;Tab
  418. StrCpy $R4 "$\t"
  419. ${Else} ;Anything else
  420. StrCpy $R4 ""
  421. ${EndIf}
  422. ;Detect if "TempRepStr" is not empty
  423. ${If} $R4 != ""
  424. ;Replace the old characters with the new one
  425. StrCpy $R3 $R0 $R1
  426. IntOp $R1 $R1 + 2
  427. StrCpy $R0 $R0 "" $R1
  428. StrCpy $R0 "$R3$R4$R0"
  429. IntOp $R2 $R2 - 1 ;Decrease "StrLen"
  430. IntOp $R1 $R1 - 2 ;Go back to the next character
  431. ${EndIf}
  432. ${Next}
  433. Pop $R4
  434. Pop $R3
  435. Pop $R2
  436. Pop $R1
  437. Exch $R0
  438. FunctionEnd
  439. !macroend
  440. # Function StrLoc
  441. ###############
  442. !macro FUNCTION_STRING_StrLoc
  443. !insertmacro STRFUNC_FUNC `StrLoc` `2004 Diego Pedroso - Based on functions by Ximon Eighteen`
  444. /*After this point:
  445. ------------------------------------------
  446. $R0 = OffsetDirection (input)
  447. $R1 = StrToSearch (input)
  448. $R2 = String (input)
  449. $R3 = StrToSearchLen (temp)
  450. $R4 = StrLen (temp)
  451. $R5 = StartCharPos (temp)
  452. $R6 = TempStr (temp)*/
  453. ;Get input from user
  454. Exch $R0
  455. Exch
  456. Exch $R1
  457. Exch 2
  458. Exch $R2
  459. Push $R3
  460. Push $R4
  461. Push $R5
  462. Push $R6
  463. ;Get "String" and "StrToSearch" length
  464. StrLen $R3 $R1
  465. StrLen $R4 $R2
  466. ;Start "StartCharPos" counter
  467. StrCpy $R5 0
  468. ;Loop until "StrToSearch" is found or "String" reaches its end
  469. ${Do}
  470. ;Remove everything before and after the searched part ("TempStr")
  471. StrCpy $R6 $R2 $R3 $R5
  472. ;Compare "TempStr" with "StrToSearch"
  473. ${If} $R6 == $R1
  474. ${If} $R0 == `<`
  475. IntOp $R6 $R3 + $R5
  476. IntOp $R0 $R4 - $R6
  477. ${Else}
  478. StrCpy $R0 $R5
  479. ${EndIf}
  480. ${ExitDo}
  481. ${EndIf}
  482. ;If not "StrToSearch", this could be "String" end
  483. ${If} $R5 >= $R4
  484. StrCpy $R0 ``
  485. ${ExitDo}
  486. ${EndIf}
  487. ;If not, continue the loop
  488. IntOp $R5 $R5 + 1
  489. ${Loop}
  490. ;Return output to user
  491. Pop $R6
  492. Pop $R5
  493. Pop $R4
  494. Pop $R3
  495. Pop $R2
  496. Exch
  497. Pop $R1
  498. Exch $R0
  499. FunctionEnd
  500. !macroend
  501. # Function StrNSISToIO
  502. ####################
  503. !macro FUNCTION_STRING_StrNSISToIO
  504. !insertmacro STRFUNC_FUNC `StrNSISToIO` `2004 "bluenet" - Based on functions by Amir Szekely, Joost Verburg, Dave Laundon and Diego Pedroso`
  505. /*After this point:
  506. ------------------------------------------
  507. $R0 = String (input/output)
  508. $R1 = StartCharPos (temp)
  509. $R2 = StrLen (temp)
  510. $R3 = TempStr (temp)
  511. $R4 = TempRepStr (temp)*/
  512. ;Get input from user
  513. Exch $R0
  514. Push $R1
  515. Push $R2
  516. Push $R3
  517. Push $R4
  518. ;Get "String" length
  519. StrLen $R2 $R0
  520. ;Loop until "String" end is reached
  521. ${For} $R1 0 $R2
  522. ;Get the next "String" character
  523. StrCpy $R3 $R0 1 $R1
  524. ;Detect if current character is:
  525. ${If} $R3 == "$\r" ;Back-slash
  526. StrCpy $R4 "\r"
  527. ${ElseIf} $R3 == "$\n" ;Carriage return
  528. StrCpy $R4 "\n"
  529. ${ElseIf} $R3 == "$\t" ;Line feed
  530. StrCpy $R4 "\t"
  531. ${ElseIf} $R3 == "\" ;Tab
  532. StrCpy $R4 "\\"
  533. ${Else} ;Anything else
  534. StrCpy $R4 ""
  535. ${EndIf}
  536. ;Detect if "TempRepStr" is not empty
  537. ${If} $R4 != ""
  538. ;Replace the old character with the new ones
  539. StrCpy $R3 $R0 $R1
  540. IntOp $R1 $R1 + 1
  541. StrCpy $R0 $R0 "" $R1
  542. StrCpy $R0 "$R3$R4$R0"
  543. IntOp $R2 $R2 + 1 ;Increase "StrLen"
  544. ${EndIf}
  545. ${Next}
  546. ;Return output to user
  547. Pop $R4
  548. Pop $R3
  549. Pop $R2
  550. Pop $R1
  551. Exch $R0
  552. FunctionEnd
  553. !macroend
  554. # Function StrRep
  555. ###############
  556. !macro FUNCTION_STRING_StrRep
  557. !insertmacro STRFUNC_FUNC `StrRep` `2004 Diego Pedroso - Based on functions by Hendri Adriaens`
  558. /*After this point:
  559. ------------------------------------------
  560. $R0 = ReplacementString (input)
  561. $R1 = StrToSearch (input)
  562. $R2 = String (input)
  563. $R3 = RepStrLen (temp)
  564. $R4 = StrToSearchLen (temp)
  565. $R5 = StrLen (temp)
  566. $R6 = StartCharPos (temp)
  567. $R7 = TempStrL (temp)
  568. $R8 = TempStrR (temp)*/
  569. ;Get input from user
  570. Exch $R0
  571. Exch
  572. Exch $R1
  573. Exch
  574. Exch 2
  575. Exch $R2
  576. Push $R3
  577. Push $R4
  578. Push $R5
  579. Push $R6
  580. Push $R7
  581. Push $R8
  582. ;Return "String" if "StrToSearch" is ""
  583. ${IfThen} $R1 == "" ${|} Goto Done ${|}
  584. ;Get "ReplacementString", "String" and "StrToSearch" length
  585. StrLen $R3 $R0
  586. StrLen $R4 $R1
  587. StrLen $R5 $R2
  588. ;Start "StartCharPos" counter
  589. StrCpy $R6 0
  590. ;Loop until "StrToSearch" is found or "String" reaches its end
  591. ${Do}
  592. ;Remove everything before and after the searched part ("TempStrL")
  593. StrCpy $R7 $R2 $R4 $R6
  594. ;Compare "TempStrL" with "StrToSearch"
  595. ${If} $R7 == $R1
  596. ;Split "String" to replace the string wanted
  597. StrCpy $R7 $R2 $R6 ;TempStrL
  598. ;Calc: "StartCharPos" + "StrToSearchLen" = EndCharPos
  599. IntOp $R8 $R6 + $R4
  600. StrCpy $R8 $R2 "" $R8 ;TempStrR
  601. ;Insert the new string between the two separated parts of "String"
  602. StrCpy $R2 $R7$R0$R8
  603. ;Now calculate the new "StrLen" and "StartCharPos"
  604. StrLen $R5 $R2
  605. IntOp $R6 $R6 + $R3
  606. ${Continue}
  607. ${EndIf}
  608. ;If not "StrToSearch", this could be "String" end
  609. ${IfThen} $R6 >= $R5 ${|} ${ExitDo} ${|}
  610. ;If not, continue the loop
  611. IntOp $R6 $R6 + 1
  612. ${Loop}
  613. Done:
  614. /*After this point:
  615. ------------------------------------------
  616. $R0 = OutVar (output)*/
  617. ;Return output to user
  618. StrCpy $R0 $R2
  619. Pop $R8
  620. Pop $R7
  621. Pop $R6
  622. Pop $R5
  623. Pop $R4
  624. Pop $R3
  625. Pop $R2
  626. Pop $R1
  627. Exch $R0
  628. FunctionEnd
  629. !macroend
  630. # Function StrSort
  631. ################
  632. !macro FUNCTION_STRING_StrSort
  633. !insertmacro STRFUNC_FUNC `StrSort` `2004 Diego Pedroso - Based on functions by Stuart Welch`
  634. /*After this point:
  635. ------------------------------------------
  636. $R0 = String (input)
  637. $R1 = LeftStr (input)
  638. $R2 = CenterStr (input)
  639. $R3 = RightStr (input)
  640. $R4 = IncludeLeftStr (input)
  641. $R5 = IncludeCenterStr (input)
  642. $R6 = IncludeRightStr (input)
  643. $0 = StrLen (temp)
  644. $1 = LeftStrLen (temp)
  645. $2 = CenterStrLen (temp)
  646. $3 = RightStrLen (temp)
  647. $4 = StartPos (temp)
  648. $5 = EndPos (temp)
  649. $6 = StartCharPos (temp)
  650. $7 = EndCharPos (temp)
  651. $8 = TempStr (temp)*/
  652. ;Get input from user
  653. Exch $R6
  654. Exch
  655. Exch $R5
  656. Exch
  657. Exch 2
  658. Exch $R4
  659. Exch 2
  660. Exch 3
  661. Exch $R3
  662. Exch 3
  663. Exch 4
  664. Exch $R2
  665. Exch 4
  666. Exch 5
  667. Exch $R1
  668. Exch 5
  669. Exch 6
  670. Exch $R0
  671. Exch 6
  672. Push $0
  673. Push $1
  674. Push $2
  675. Push $3
  676. Push $4
  677. Push $5
  678. Push $6
  679. Push $7
  680. Push $8
  681. ;Parameter defaults
  682. ${IfThen} $R4 == `` ${|} StrCpy $R4 `1` ${|}
  683. ${IfThen} $R5 == `` ${|} StrCpy $R5 `1` ${|}
  684. ${IfThen} $R6 == `` ${|} StrCpy $R6 `1` ${|}
  685. ;Get "String", "CenterStr", "LeftStr" and "RightStr" length
  686. StrLen $0 $R0
  687. StrLen $1 $R1
  688. StrLen $2 $R2
  689. StrLen $3 $R3
  690. ;Start "StartCharPos" counter
  691. StrCpy $6 0
  692. ;Start "EndCharPos" counter based on "CenterStr" length
  693. IntOp $7 $6 + $2
  694. ;Loop until "CenterStr" is found or "String" reaches its end
  695. ${Do}
  696. ;Remove everything before and after the searched part ("TempStr")
  697. StrCpy $8 $R0 $2 $6
  698. ;Compare "TempStr" with "CenterStr"
  699. ${IfThen} $8 == $R2 ${|} ${ExitDo} ${|}
  700. ;If not, this could be "String" end
  701. ${IfThen} $7 >= $0 ${|} Goto Done ${|}
  702. ;If not, continue the loop
  703. IntOp $6 $6 + 1
  704. IntOp $7 $7 + 1
  705. ${Loop}
  706. # "CenterStr" was found
  707. ;Remove "CenterStr" from "String" if the user wants
  708. ${If} $R5 = ${FALSE}
  709. StrCpy $8 $R0 $6
  710. StrCpy $R0 $R0 `` $7
  711. StrCpy $R0 $8$R0
  712. ${EndIf}
  713. ;"StartPos" and "EndPos" will record "CenterStr" coordinates for now
  714. StrCpy $4 $6
  715. StrCpy $5 $7
  716. ;"StartCharPos" and "EndCharPos" should be before "CenterStr"
  717. IntOp $6 $6 - $1
  718. IntOp $7 $6 + $1
  719. ;Loop until "LeftStr" is found or "String" reaches its start
  720. ${Do}
  721. ;Remove everything before and after the searched part ("TempStr")
  722. StrCpy $8 $R0 $1 $6
  723. ;If "LeftStr" is empty
  724. ${If} $R1 == ``
  725. StrCpy $6 0
  726. StrCpy $7 0
  727. ${ExitDo}
  728. ${EndIf}
  729. ;Compare "TempStr" with "LeftStr"
  730. ${IfThen} $8 == $R1 ${|} ${ExitDo} ${|}
  731. ;If not, this could be "String" start
  732. ${IfThen} $6 <= 0 ${|} ${ExitDo} ${|}
  733. ;If not, continue the loop
  734. IntOp $6 $6 - 1
  735. IntOp $7 $7 - 1
  736. ${Loop}
  737. # "LeftStr" is found or "String" start was reached
  738. ;Remove "LeftStr" from "String" if the user wants
  739. ${If} $R4 = ${FALSE}
  740. IntOp $6 $6 + $1
  741. ${EndIf}
  742. ;Record "LeftStr" first character position on "TempStr" (temporarily)
  743. StrCpy $8 $6
  744. ;"StartCharPos" and "EndCharPos" should be after "CenterStr"
  745. ${If} $R5 = ${FALSE}
  746. StrCpy $6 $4
  747. ${Else}
  748. IntOp $6 $4 + $2
  749. ${EndIf}
  750. IntOp $7 $6 + $3
  751. ;Record "LeftStr" first character position on "StartPos"
  752. StrCpy $4 $8
  753. ;Loop until "RightStr" is found or "String" reaches its end
  754. ${Do}
  755. ;Remove everything before and after the searched part ("TempStr")
  756. StrCpy $8 $R0 $3 $6
  757. ;If "RightStr" is empty
  758. ${If} $R3 == ``
  759. StrCpy $6 $0
  760. StrCpy $7 $0
  761. ${ExitDo}
  762. ${EndIf}
  763. ;Compare "TempStr" with "RightStr"
  764. ${IfThen} $8 == $R3 ${|} ${ExitDo} ${|}
  765. ;If not, this could be "String" end
  766. ${IfThen} $7 >= $0 ${|} ${ExitDo} ${|}
  767. ;If not, continue the loop
  768. IntOp $6 $6 + 1
  769. IntOp $7 $7 + 1
  770. ${Loop}
  771. ;Remove "RightStr" from "String" if the user wants
  772. ${If} $R6 = ${FALSE}
  773. IntOp $7 $7 - $3
  774. ${EndIf}
  775. ;Record "RightStr" last character position on "StartPos"
  776. StrCpy $5 $7
  777. ;As the positionment is relative...
  778. IntOp $5 $5 - $4
  779. ;Write the string and finish the job
  780. StrCpy $R0 $R0 $5 $4
  781. Goto +2
  782. Done:
  783. StrCpy $R0 ``
  784. /*After this point:
  785. ------------------------------------------
  786. $R0 = OutVar (output)*/
  787. ;Return output to user
  788. Pop $8
  789. Pop $7
  790. Pop $6
  791. Pop $5
  792. Pop $4
  793. Pop $3
  794. Pop $2
  795. Pop $1
  796. Pop $0
  797. Pop $R6
  798. Pop $R5
  799. Pop $R4
  800. Pop $R3
  801. Pop $R2
  802. Pop $R1
  803. Exch $R0
  804. FunctionEnd
  805. !macroend
  806. # Function StrStr
  807. ###############
  808. !macro FUNCTION_STRING_StrStr
  809. !insertmacro STRFUNC_FUNC `StrStr` `2004 Diego Pedroso - Based on functions by Ximon Eighteen`
  810. /*After this point:
  811. ------------------------------------------
  812. $R0 = StrToSearch (input)
  813. $R1 = String (input)
  814. $R2 = StrToSearchLen (temp)
  815. $R3 = StrLen (temp)
  816. $R4 = StartCharPos (temp)
  817. $R5 = TempStr (temp)*/
  818. ;Get input from user
  819. Exch $R0
  820. Exch
  821. Exch $R1
  822. Push $R2
  823. Push $R3
  824. Push $R4
  825. Push $R5
  826. ;Get "String" and "StrToSearch" length
  827. StrLen $R2 $R0
  828. StrLen $R3 $R1
  829. ;Start "StartCharPos" counter
  830. StrCpy $R4 0
  831. ;Loop until "StrToSearch" is found or "String" reaches its end
  832. ${Do}
  833. ;Remove everything before and after the searched part ("TempStr")
  834. StrCpy $R5 $R1 $R2 $R4
  835. ;Compare "TempStr" with "StrToSearch"
  836. ${IfThen} $R5 == $R0 ${|} ${ExitDo} ${|}
  837. ;If not "StrToSearch", this could be "String" end
  838. ${IfThen} $R4 >= $R3 ${|} ${ExitDo} ${|}
  839. ;If not, continue the loop
  840. IntOp $R4 $R4 + 1
  841. ${Loop}
  842. /*After this point:
  843. ------------------------------------------
  844. $R0 = OutVar (output)*/
  845. ;Remove part before "StrToSearch" on "String" (if there has one)
  846. StrCpy $R0 $R1 `` $R4
  847. ;Return output to user
  848. Pop $R5
  849. Pop $R4
  850. Pop $R3
  851. Pop $R2
  852. Pop $R1
  853. Exch $R0
  854. FunctionEnd
  855. !macroend
  856. # Function StrStrAdv
  857. ##################
  858. !macro FUNCTION_STRING_StrStrAdv
  859. !insertmacro STRFUNC_FUNC `StrStrAdv` `2003-2004 Diego Pedroso`
  860. /*After this point:
  861. ------------------------------------------
  862. $0 = String (input)
  863. $1 = StringToSearch (input)
  864. $2 = DirectionOfSearch (input)
  865. $3 = DirectionOfReturn (input)
  866. $4 = ShowStrToSearch (input)
  867. $5 = NumLoops (input)
  868. $6 = CaseSensitive (input)
  869. $7 = StringLength (temp)
  870. $8 = StrToSearchLength (temp)
  871. $9 = CurrentLoop (temp)
  872. $R0 = EndCharPos (temp)
  873. $R1 = StartCharPos (temp)
  874. $R2 = OutVar (output)
  875. $R3 = Temp (temp)*/
  876. ;Get input from user
  877. Exch $6
  878. Exch
  879. Exch $5
  880. Exch
  881. Exch 2
  882. Exch $4
  883. Exch 2
  884. Exch 3
  885. Exch $3
  886. Exch 3
  887. Exch 4
  888. Exch $2
  889. Exch 4
  890. Exch 5
  891. Exch $1
  892. Exch 5
  893. Exch 6
  894. Exch $0
  895. Exch 6
  896. Push $7
  897. Push $8
  898. Push $9
  899. Push $R3
  900. Push $R2
  901. Push $R1
  902. Push $R0
  903. ; Clean $R0-$R3 variables
  904. StrCpy $R0 ""
  905. StrCpy $R1 ""
  906. StrCpy $R2 ""
  907. StrCpy $R3 ""
  908. ; Verify if we have the correct values on the variables
  909. ${If} $0 == ``
  910. SetErrors ;AdvStrStr_StrToSearch not found
  911. Goto AdvStrStr_End
  912. ${EndIf}
  913. ${If} $1 == ``
  914. SetErrors ;No text to search
  915. Goto AdvStrStr_End
  916. ${EndIf}
  917. ${If} $2 != <
  918. StrCpy $2 >
  919. ${EndIf}
  920. ${If} $3 != <
  921. StrCpy $3 >
  922. ${EndIf}
  923. ${If} $4 <> 0
  924. StrCpy $4 1
  925. ${EndIf}
  926. ${If} $5 <= 0
  927. StrCpy $5 0
  928. ${EndIf}
  929. ${If} $6 <> 1
  930. StrCpy $6 0
  931. ${EndIf}
  932. ; Find "AdvStrStr_String" length
  933. StrLen $7 $0
  934. ; Then find "AdvStrStr_StrToSearch" length
  935. StrLen $8 $1
  936. ; Now set up basic variables
  937. ${If} $2 == <
  938. IntOp $R1 $7 - $8
  939. StrCpy $R2 $7
  940. ${Else}
  941. StrCpy $R1 0
  942. StrCpy $R2 $8
  943. ${EndIf}
  944. StrCpy $9 0 ; First loop
  945. ;Let's begin the search
  946. ${Do}
  947. ; Step 1: If the starting or ending numbers are negative
  948. ; or more than AdvStrStr_StringLen, we return
  949. ; error
  950. ${If} $R1 < 0
  951. StrCpy $R1 ``
  952. StrCpy $R2 ``
  953. StrCpy $R3 ``
  954. SetErrors ;AdvStrStr_StrToSearch not found
  955. Goto AdvStrStr_End
  956. ${ElseIf} $R2 > $7
  957. StrCpy $R1 ``
  958. StrCpy $R2 ``
  959. StrCpy $R3 ``
  960. SetErrors ;AdvStrStr_StrToSearch not found
  961. Goto AdvStrStr_End
  962. ${EndIf}
  963. ; Step 2: Start the search depending on
  964. ; AdvStrStr_DirectionOfSearch. Chop down not needed
  965. ; characters.
  966. ${If} $R1 <> 0
  967. StrCpy $R3 $0 `` $R1
  968. ${EndIf}
  969. ${If} $R2 <> $7
  970. ${If} $R1 = 0
  971. StrCpy $R3 $0 $8
  972. ${Else}
  973. StrCpy $R3 $R3 $8
  974. ${EndIf}
  975. ${EndIf}
  976. ; Step 3: Make sure that's the string we want
  977. ; Case-Sensitive Support <- Use "AdvStrStr_Temp"
  978. ; variable because it won't be used anymore
  979. ${If} $6 == 1
  980. System::Call `kernel32::lstrcmp(ts, ts) i.s` `$R3` `$1`
  981. Pop $R3
  982. ${If} $R3 = 0
  983. StrCpy $R3 1 ; Continue
  984. ${Else}
  985. StrCpy $R3 0 ; Break
  986. ${EndIf}
  987. ${Else}
  988. ${If} $R3 == $1
  989. StrCpy $R3 1 ; Continue
  990. ${Else}
  991. StrCpy $R3 0 ; Break
  992. ${EndIf}
  993. ${EndIf}
  994. ; After the comparasion, confirm that it is the
  995. ; value we want.
  996. ${If} $R3 = 1
  997. ;We found it, return except if the user has set up to
  998. ;search for another one:
  999. ${If} $9 >= $5
  1000. ;Now, let's see if the user wants
  1001. ;AdvStrStr_StrToSearch to appear:
  1002. ${If} $4 == 0
  1003. ;Return depends on AdvStrStr_DirectionOfReturn
  1004. ${If} $3 == <
  1005. ; RTL
  1006. StrCpy $R0 $0 $R1
  1007. ${Else}
  1008. ; LTR
  1009. StrCpy $R0 $0 `` $R2
  1010. ${EndIf}
  1011. ${Break}
  1012. ${Else}
  1013. ;Return depends on AdvStrStr_DirectionOfReturn
  1014. ${If} $3 == <
  1015. ; RTL
  1016. StrCpy $R0 $0 $R2
  1017. ${Else}
  1018. ; LTR
  1019. StrCpy $R0 $0 `` $R1
  1020. ${EndIf}
  1021. ${Break}
  1022. ${EndIf}
  1023. ${Else}
  1024. ;If the user wants to have more loops, let's do it so!
  1025. IntOp $9 $9 + 1
  1026. ${If} $2 == <
  1027. IntOp $R1 $R1 - 1
  1028. IntOp $R2 $R2 - 1
  1029. ${Else}
  1030. IntOp $R1 $R1 + 1
  1031. IntOp $R2 $R2 + 1
  1032. ${EndIf}
  1033. ${EndIf}
  1034. ${Else}
  1035. ; Step 4: We didn't find it, so do steps 1 thru 3 again
  1036. ${If} $2 == <
  1037. IntOp $R1 $R1 - 1
  1038. IntOp $R2 $R2 - 1
  1039. ${Else}
  1040. IntOp $R1 $R1 + 1
  1041. IntOp $R2 $R2 + 1
  1042. ${EndIf}
  1043. ${EndIf}
  1044. ${Loop}
  1045. AdvStrStr_End:
  1046. ;Add 1 to AdvStrStr_EndCharPos to be supportable
  1047. ;by "StrCpy"
  1048. IntOp $R2 $R2 - 1
  1049. ;Return output to user
  1050. Exch $R0
  1051. Exch
  1052. Pop $R1
  1053. Exch
  1054. Pop $R2
  1055. Exch
  1056. Pop $R3
  1057. Exch
  1058. Pop $9
  1059. Exch
  1060. Pop $8
  1061. Exch
  1062. Pop $7
  1063. Exch
  1064. Pop $6
  1065. Exch
  1066. Pop $5
  1067. Exch
  1068. Pop $4
  1069. Exch
  1070. Pop $3
  1071. Exch
  1072. Pop $2
  1073. Exch
  1074. Pop $1
  1075. Exch
  1076. Pop $0
  1077. FunctionEnd
  1078. !macroend
  1079. # Function StrTok
  1080. ###############
  1081. !macro FUNCTION_STRING_StrTok
  1082. !insertmacro STRFUNC_FUNC `StrTok` `2004 Diego Pedroso - Based on functions by "bigmac666"`
  1083. /*After this point:
  1084. ------------------------------------------
  1085. $0 = SkipEmptyParts (input)
  1086. $1 = ResultPart (input)
  1087. $2 = Separators (input)
  1088. $3 = String (input)
  1089. $4 = StrToSearchLen (temp)
  1090. $5 = StrLen (temp)
  1091. $6 = StartCharPos (temp)
  1092. $7 = TempStr (temp)
  1093. $8 = CurrentLoop
  1094. $9 = CurrentSepChar
  1095. $R0 = CurrentSepCharNum
  1096. */
  1097. ;Get input from user
  1098. Exch $0
  1099. Exch
  1100. Exch $1
  1101. Exch
  1102. Exch 2
  1103. Exch $2
  1104. Exch 2
  1105. Exch 3
  1106. Exch $3
  1107. Exch 3
  1108. Push $4
  1109. Push $5
  1110. Push $6
  1111. Push $7
  1112. Push $8
  1113. Push $9
  1114. Push $R0
  1115. ;Parameter defaults
  1116. ${IfThen} $2 == `` ${|} StrCpy $2 `|` ${|}
  1117. ${IfThen} $1 == `` ${|} StrCpy $1 `L` ${|}
  1118. ${IfThen} $0 == `` ${|} StrCpy $0 `0` ${|}
  1119. ;Get "String" and "StrToSearch" length
  1120. StrLen $4 $2
  1121. StrLen $5 $3
  1122. ;Start "StartCharPos" and "ResultPart" counters
  1123. StrCpy $6 0
  1124. StrCpy $8 -1
  1125. ;Loop until "ResultPart" is met, "StrToSearch" is found or
  1126. ;"String" reaches its end
  1127. ResultPartLoop: ;"CurrentLoop" Loop
  1128. ;Increase "CurrentLoop" counter
  1129. IntOp $8 $8 + 1
  1130. StrSearchLoop:
  1131. ${Do} ;"String" Loop
  1132. ;Remove everything before and after the searched part ("TempStr")
  1133. StrCpy $7 $3 1 $6
  1134. ;Verify if it's the "String" end
  1135. ${If} $6 >= $5
  1136. ;If "CurrentLoop" is what the user wants, remove the part
  1137. ;after "TempStr" and itself and get out of here
  1138. ${If} $8 == $1
  1139. ${OrIf} $1 == `L`
  1140. StrCpy $3 $3 $6
  1141. ${Else} ;If not, empty "String" and get out of here
  1142. StrCpy $3 ``
  1143. ${EndIf}
  1144. StrCpy $R0 `End`
  1145. ${ExitDo}
  1146. ${EndIf}
  1147. ;Start "CurrentSepCharNum" counter (for "Separators" Loop)
  1148. StrCpy $R0 0
  1149. ${Do} ;"Separators" Loop
  1150. ;Use one "Separators" character at a time
  1151. ${If} $R0 <> 0
  1152. StrCpy $9 $2 1 $R0
  1153. ${Else}
  1154. StrCpy $9 $2 1
  1155. ${EndIf}
  1156. ;Go to the next "String" char if it's "Separators" end
  1157. ${IfThen} $R0 >= $4 ${|} ${ExitDo} ${|}
  1158. ;Or, if "TempStr" equals "CurrentSepChar", then...
  1159. ${If} $7 == $9
  1160. StrCpy $7 $3 $6
  1161. ;If "String" is empty because this result part doesn't
  1162. ;contain data, verify if "SkipEmptyParts" is activated,
  1163. ;so we don't return the output to user yet
  1164. ${If} $7 == ``
  1165. ${AndIf} $0 = ${TRUE}
  1166. IntOp $6 $6 + 1
  1167. StrCpy $3 $3 `` $6
  1168. StrCpy $6 0
  1169. Goto StrSearchLoop
  1170. ${ElseIf} $8 == $1
  1171. StrCpy $3 $3 $6
  1172. StrCpy $R0 "End"
  1173. ${ExitDo}
  1174. ${EndIf} ;If not, go to the next result part
  1175. IntOp $6 $6 + 1
  1176. StrCpy $3 $3 `` $6
  1177. StrCpy $6 0
  1178. Goto ResultPartLoop
  1179. ${EndIf}
  1180. ;Increase "CurrentSepCharNum" counter
  1181. IntOp $R0 $R0 + 1
  1182. ${Loop}
  1183. ${IfThen} $R0 == "End" ${|} ${ExitDo} ${|}
  1184. ;Increase "StartCharPos" counter
  1185. IntOp $6 $6 + 1
  1186. ${Loop}
  1187. /*After this point:
  1188. ------------------------------------------
  1189. $3 = OutVar (output)*/
  1190. ;Return output to user
  1191. Pop $R0
  1192. Pop $9
  1193. Pop $8
  1194. Pop $7
  1195. Pop $6
  1196. Pop $5
  1197. Pop $4
  1198. Pop $0
  1199. Pop $1
  1200. Pop $2
  1201. Exch $3
  1202. FunctionEnd
  1203. !macroend
  1204. # Function StrTrimNewLines
  1205. ########################
  1206. !macro FUNCTION_STRING_StrTrimNewLines
  1207. !insertmacro STRFUNC_FUNC `StrTrimNewLines` `2004 Diego Pedroso - Based on functions by Ximon Eighteen`
  1208. /*After this point:
  1209. ------------------------------------------
  1210. $R0 = String (input)
  1211. $R1 = TrimCounter (temp)
  1212. $R2 = Temp (temp)*/
  1213. ;Get input from user
  1214. Exch $R0
  1215. Push $R1
  1216. Push $R2
  1217. ;Initialize trim counter
  1218. StrCpy $R1 0
  1219. loop:
  1220. ;Subtract to get "String"'s last characters
  1221. IntOp $R1 $R1 - 1
  1222. ;Verify if they are either $\r or $\n
  1223. StrCpy $R2 $R0 1 $R1
  1224. ${If} $R2 == `$\r`
  1225. ${OrIf} $R2 == `$\n`
  1226. Goto loop
  1227. ${EndIf}
  1228. ;Trim characters (if needed)
  1229. IntOp $R1 $R1 + 1
  1230. ${If} $R1 < 0
  1231. StrCpy $R0 $R0 $R1
  1232. ${EndIf}
  1233. /*After this point:
  1234. ------------------------------------------
  1235. $R0 = OutVar (output)*/
  1236. ;Return output to user
  1237. Pop $R2
  1238. Pop $R1
  1239. Exch $R0
  1240. FunctionEnd
  1241. !macroend
  1242. ;Function Calls for Install and Uninstall
  1243. !macro FUNCTION_STRING_StrCase_Call ResultVar String Type
  1244. !verbose push ${_STRFUNC_CREDITVERBOSITY}
  1245. !echo `$ {StrCase} "${ResultVar}" "${String}" "${Type}"`
  1246. !verbose pop
  1247. Push `${String}`
  1248. Push `${Type}`
  1249. Call StrCase
  1250. Pop `${ResultVar}`
  1251. !macroend
  1252. !macro FUNCTION_STRING_UnStrCase_Call ResultVar String Type
  1253. !verbose push ${_STRFUNC_CREDITVERBOSITY}
  1254. !echo `$ {UnStrCase} "${ResultVar}" "${String}" "${Type}"`
  1255. !verbose pop
  1256. Push `${String}`
  1257. Push `${Type}`
  1258. Call un.StrCase
  1259. Pop `${ResultVar}`
  1260. !macroend
  1261. !macro FUNCTION_STRING_StrClb_Call ResultVar String Action
  1262. !verbose push ${_STRFUNC_CREDITVERBOSITY}
  1263. !echo `$ {StrClb} "${ResultVar}" "${String}" "${Action}"`
  1264. !verbose pop
  1265. Push `${String}`
  1266. Push `${Action}`
  1267. Call StrClb
  1268. Pop `${ResultVar}`
  1269. !macroend
  1270. !macro FUNCTION_STRING_UnStrClb_Call ResultVar String Action
  1271. !verbose push ${_STRFUNC_CREDITVERBOSITY}
  1272. !echo `$ {UnStrClb} "${ResultVar}" "${String}" "${Action}"`
  1273. !verbose pop
  1274. Push `${String}`
  1275. Push `${Action}`
  1276. Call un.StrClb
  1277. Pop `${ResultVar}`
  1278. !macroend
  1279. !macro FUNCTION_STRING_StrIOToNSIS_Call ResultVar String
  1280. !verbose push ${_STRFUNC_CREDITVERBOSITY}
  1281. !echo `$ {StrIOToNSIS} "${ResultVar}" "${String}"`
  1282. !verbose pop
  1283. Push `${String}`
  1284. Call StrIOToNSIS
  1285. Pop `${ResultVar}`
  1286. !macroend
  1287. !macro FUNCTION_STRING_UnStrIOToNSIS_Call ResultVar String
  1288. !verbose push ${_STRFUNC_CREDITVERBOSITY}
  1289. !echo `$ {UnStrIOToNSIS} "${ResultVar}" "${String}"`
  1290. !verbose pop
  1291. Push `${String}`
  1292. Call un.StrIOToNSIS
  1293. Pop `${ResultVar}`
  1294. !macroend
  1295. !macro FUNCTION_STRING_StrLoc_Call ResultVar String StrToSearchFor OffsetDirection
  1296. !verbose push ${_STRFUNC_CREDITVERBOSITY}
  1297. !echo `$ {StrLoc} "${ResultVar}" "${String}" "${StrToSearchFor}" "${OffsetDirection}"`
  1298. !verbose pop
  1299. Push `${String}`
  1300. Push `${StrToSearchFor}`
  1301. Push `${OffsetDirection}`
  1302. Call StrLoc
  1303. Pop `${ResultVar}`
  1304. !macroend
  1305. !macro FUNCTION_STRING_UnStrLoc_Call ResultVar String StrToSearchFor OffsetDirection
  1306. !verbose push ${_STRFUNC_CREDITVERBOSITY}
  1307. !echo `$ {UnStrLoc} "${ResultVar}" "${String}" "${StrToSearchFor}" "${OffsetDirection}"`
  1308. !verbose pop
  1309. Push `${String}`
  1310. Push `${StrToSearchFor}`
  1311. Push `${OffsetDirection}`
  1312. Call un.StrLoc
  1313. Pop `${ResultVar}`
  1314. !macroend
  1315. !macro FUNCTION_STRING_StrNSISToIO_Call ResultVar String
  1316. !verbose push ${_STRFUNC_CREDITVERBOSITY}
  1317. !echo `$ {StrNSISToIO} "${ResultVar}" "${String}"`
  1318. !verbose pop
  1319. Push `${String}`
  1320. Call StrNSISToIO
  1321. Pop `${ResultVar}`
  1322. !macroend
  1323. !macro FUNCTION_STRING_UnStrNSISToIO_Call ResultVar String
  1324. !verbose push ${_STRFUNC_CREDITVERBOSITY}
  1325. !echo `$ {UnStrNSISToIO} "${ResultVar}" "${String}"`
  1326. !verbose pop
  1327. Push `${String}`
  1328. Call un.StrNSISToIO
  1329. Pop `${ResultVar}`
  1330. !macroend
  1331. !macro FUNCTION_STRING_StrRep_Call ResultVar String StringToReplace ReplacementString
  1332. !verbose push ${_STRFUNC_CREDITVERBOSITY}
  1333. !echo `$ {StrRep} "${ResultVar}" "${String}" "${StringToReplace}" "${ReplacementString}"`
  1334. !verbose pop
  1335. Push `${String}`
  1336. Push `${StringToReplace}`
  1337. Push `${ReplacementString}`
  1338. Call StrRep
  1339. Pop `${ResultVar}`
  1340. !macroend
  1341. !macro FUNCTION_STRING_UnStrRep_Call ResultVar String StringToReplace ReplacementString
  1342. !verbose push ${_STRFUNC_CREDITVERBOSITY}
  1343. !echo `$ {UnStrRep} "${ResultVar}" "${String}" "${StringToReplace}" "${ReplacementString}"`
  1344. !verbose pop
  1345. Push `${String}`
  1346. Push `${StringToReplace}`
  1347. Push `${ReplacementString}`
  1348. Call un.StrRep
  1349. Pop `${ResultVar}`
  1350. !macroend
  1351. !macro FUNCTION_STRING_StrSort_Call ResultVar String CenterStr LeftStr RightStr IncludeCenterStr IncludeLeftStr IncludeRightStr
  1352. !verbose push ${_STRFUNC_CREDITVERBOSITY}
  1353. !echo `$ {StrSort} "${ResultVar}" "${String}" "${CenterStr}" "${LeftStr}" "${RightStr}" "${IncludeCenterStr}" "${IncludeLeftStr}" "${IncludeRightStr}"`
  1354. !verbose pop
  1355. Push `${String}`
  1356. Push `${CenterStr}`
  1357. Push `${LeftStr}`
  1358. Push `${RightStr}`
  1359. Push `${IncludeCenterStr}`
  1360. Push `${IncludeLeftStr}`
  1361. Push `${IncludeRightStr}`
  1362. Call StrSort
  1363. Pop `${ResultVar}`
  1364. !macroend
  1365. !macro FUNCTION_STRING_UnStrSort_Call ResultVar String CenterStr LeftStr RightStr IncludeCenterStr IncludeLeftStr IncludeRightStr
  1366. !verbose push ${_STRFUNC_CREDITVERBOSITY}
  1367. !echo `$ {UnStrSort} "${ResultVar}" "${String}" "${CenterStr}" "${LeftStr}" "${RightStr}" "${IncludeCenterStr}" "${IncludeLeftStr}" "${IncludeRightStr}"`
  1368. !verbose pop
  1369. Push `${String}`
  1370. Push `${CenterStr}`
  1371. Push `${LeftStr}`
  1372. Push `${RightStr}`
  1373. Push `${IncludeCenterStr}`
  1374. Push `${IncludeLeftStr}`
  1375. Push `${IncludeRightStr}`
  1376. Call un.StrSort
  1377. Pop `${ResultVar}`
  1378. !macroend
  1379. !macro FUNCTION_STRING_StrStr_Call ResultVar String StrToSearchFor
  1380. !verbose push ${_STRFUNC_CREDITVERBOSITY}
  1381. !echo `$ {StrStr} "${ResultVar}" "${String}" "${StrToSearchFor}"`
  1382. !verbose pop
  1383. Push `${String}`
  1384. Push `${StrToSearchFor}`
  1385. Call StrStr
  1386. Pop `${ResultVar}`
  1387. !macroend
  1388. !macro FUNCTION_STRING_UnStrStr_Call ResultVar String StrToSearchFor
  1389. !verbose push ${_STRFUNC_CREDITVERBOSITY}
  1390. !echo `$ {UnStrStr} "${ResultVar}" "${String}" "${StrToSearchFor}"`
  1391. !verbose pop
  1392. Push `${String}`
  1393. Push `${StrToSearchFor}`
  1394. Call un.StrStr
  1395. Pop `${ResultVar}`
  1396. !macroend
  1397. !macro FUNCTION_STRING_StrStrAdv_Call ResultVar String StrToSearchFor SearchDirection ResultStrDirection DisplayStrToSearch Loops CaseSensitive
  1398. !verbose push ${_STRFUNC_CREDITVERBOSITY}
  1399. !echo `$ {StrStrAdv} "${ResultVar}" "${String}" "${StrToSearchFor}" "${SearchDirection}" "${ResultStrDirection}" "${DisplayStrToSearch}" "${Loops}" "${CaseSensitive}"`
  1400. !verbose pop
  1401. Push `${String}`
  1402. Push `${StrToSearchFor}`
  1403. Push `${SearchDirection}`
  1404. Push `${ResultStrDirection}`
  1405. Push `${DisplayStrToSearch}`
  1406. Push `${Loops}`
  1407. Push `${CaseSensitive}`
  1408. Call StrStrAdv
  1409. Pop `${ResultVar}`
  1410. !macroend
  1411. !macro FUNCTION_STRING_UnStrStrAdv_Call ResultVar String StrToSearchFor SearchDirection ResultStrDirection DisplayStrToSearch Loops CaseSensitive
  1412. !verbose push ${_STRFUNC_CREDITVERBOSITY}
  1413. !echo `$ {UnStrStrAdv} "${ResultVar}" "${String}" "${StrToSearchFor}" "${SearchDirection}" "${ResultStrDirection}" "${DisplayStrToSearch}" "${Loops}" "${CaseSensitive}"`
  1414. !verbose pop
  1415. Push `${String}`
  1416. Push `${StrToSearchFor}`
  1417. Push `${SearchDirection}`
  1418. Push `${ResultStrDirection}`
  1419. Push `${DisplayStrToSearch}`
  1420. Push `${Loops}`
  1421. Push `${CaseSensitive}`
  1422. Call un.StrStrAdv
  1423. Pop `${ResultVar}`
  1424. !macroend
  1425. !macro FUNCTION_STRING_StrTok_Call ResultVar String Separators ResultPart SkipEmptyParts
  1426. !verbose push ${_STRFUNC_CREDITVERBOSITY}
  1427. !echo `$ {StrTok} "${ResultVar}" "${String}" "${Separators}" "${ResultPart}" "${SkipEmptyParts}"`
  1428. !verbose pop
  1429. Push `${String}`
  1430. Push `${Separators}`
  1431. Push `${ResultPart}`
  1432. Push `${SkipEmptyParts}`
  1433. Call StrTok
  1434. Pop `${ResultVar}`
  1435. !macroend
  1436. !macro FUNCTION_STRING_UnStrTok_Call ResultVar String Separators ResultPart SkipEmptyParts
  1437. !verbose push ${_STRFUNC_CREDITVERBOSITY}
  1438. !echo `$ {UnStrTok} "${ResultVar}" "${String}" "${Separators}" "${ResultPart}" "${SkipEmptyParts}"`
  1439. !verbose pop
  1440. Push `${String}`
  1441. Push `${Separators}`
  1442. Push `${ResultPart}`
  1443. Push `${SkipEmptyParts}`
  1444. Call un.StrTok
  1445. Pop `${ResultVar}`
  1446. !macroend
  1447. !macro FUNCTION_STRING_StrTrimNewLines_Call ResultVar String
  1448. !verbose push ${_STRFUNC_CREDITVERBOSITY}
  1449. !echo `$ {StrTrimNewLines} "${ResultVar}" "${String}"`
  1450. !verbose pop
  1451. Push `${String}`
  1452. Call StrTrimNewLines
  1453. Pop `${ResultVar}`
  1454. !macroend
  1455. !macro FUNCTION_STRING_UnStrTrimNewLines_Call ResultVar String
  1456. !verbose push ${_STRFUNC_CREDITVERBOSITY}
  1457. !echo `$ {UnStrTrimNewLines} "${ResultVar}" "${String}"`
  1458. !verbose pop
  1459. Push `${String}`
  1460. Call un.StrTrimNewLines
  1461. Pop `${ResultVar}`
  1462. !macroend
  1463. !endif
  1464. !verbose 3
  1465. !define STRFUNC_VERBOSITY ${_STRFUNC_VERBOSITY}
  1466. !undef _STRFUNC_VERBOSITY
  1467. !verbose pop