TextFunc.nsh 23 KB

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