TextFunc.nsh 23 KB

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