StrFunc.nsh 43 KB

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