Newer
Older
CVSS_3.0_GUI / node_modules / nwjs-builder-phoenix / assets / nsis / Include / LogicLib.nsh
root on 7 May 2019 30 KB Initial commit
  1. ; NSIS LOGIC LIBRARY - LogicLib.nsh
  2. ; Version 2.6 - 08/12/2007
  3. ; By dselkirk@hotmail.com
  4. ; and eccles@users.sf.net
  5. ; with IfNot support added by Message
  6. ;
  7. ; Questions/Comments -
  8. ; See http://forums.winamp.com/showthread.php?s=&postid=1116241
  9. ;
  10. ; Description:
  11. ; Provides the use of various logic statements within NSIS.
  12. ;
  13. ; Usage:
  14. ; The following "statements" are available:
  15. ; If|IfNot|Unless..{ElseIf|ElseIfNot|ElseUnless}..[Else]..EndIf|EndUnless
  16. ; - Conditionally executes a block of statements, depending on the value
  17. ; of an expression. IfNot and Unless are equivalent and
  18. ; interchangeable, as are ElseIfNot and ElseUnless.
  19. ; AndIf|AndIfNot|AndUnless|OrIf|OrIfNot|OrUnless
  20. ; - Adds any number of extra conditions to If, IfNot, Unless, ElseIf,
  21. ; ElseIfNot and ElseUnless statements.
  22. ; IfThen|IfNotThen..|..|
  23. ; - Conditionally executes an inline statement, depending on the value
  24. ; of an expression.
  25. ; IfCmd..||..|
  26. ; - Conditionally executes an inline statement, depending on a true
  27. ; value of the provided NSIS function.
  28. ; Select..{Case[2|3|4|5]}..[CaseElse|Default]..EndSelect
  29. ; - Executes one of several blocks of statements, depending on the value
  30. ; of an expression.
  31. ; Switch..{Case|CaseElse|Default}..EndSwitch
  32. ; - Jumps to one of several labels, depending on the value of an
  33. ; expression.
  34. ; Do[While|Until]..{ExitDo|Continue|Break}..Loop[While|Until]
  35. ; - Repeats a block of statements until stopped, or depending on the
  36. ; value of an expression.
  37. ; While..{ExitWhile|Continue|Break}..EndWhile
  38. ; - An alias for DoWhile..Loop (for backwards-compatibility)
  39. ; For[Each]..{ExitFor|Continue|Break}..Next
  40. ; - Repeats a block of statements varying the value of a variable.
  41. ;
  42. ; The following "expressions" are available:
  43. ; Standard (built-in) string tests (which are case-insensitive):
  44. ; a == b; a != b
  45. ; Additional case-insensitive string tests (using System.dll):
  46. ; a S< b; a S>= b; a S> b; a S<= b
  47. ; Case-sensitive string tests:
  48. ; a S== b; a S!= b
  49. ; Standard (built-in) signed integer tests:
  50. ; a = b; a <> b; a < b; a >= b; a > b; a <= b; a & b
  51. ; Standard (built-in) unsigned integer tests:
  52. ; a U< b; a U>= b; a U> b; a U<= b
  53. ; 64-bit integer tests (using System.dll):
  54. ; a L= b; a L<> b; a L< b; a L>= b; a L> b; a L<= b
  55. ; ptrdiff_t integer tests
  56. ; a P= b; a P<> b; a P< b; a P>= b; a P> b; a P<= b
  57. ; size_t integer tests
  58. ; a Z= b; a Z<> b; a Z< b; a Z>= b; a Z> b; a Z<= b
  59. ; Built-in NSIS flag tests:
  60. ; ${Abort}; ${Errors}; ${RebootFlag}; ${Silent}
  61. ; Built-in NSIS other tests:
  62. ; ${FileExists} a
  63. ; Any conditional NSIS instruction test:
  64. ; ${Cmd} a
  65. ; Section flag tests:
  66. ; ${SectionIsSelected} a; ${SectionIsSectionGroup} a;
  67. ; ${SectionIsSectionGroupEnd} a; ${SectionIsBold} a;
  68. ; ${SectionIsReadOnly} a; ${SectionIsExpanded} a;
  69. ; ${SectionIsPartiallySelected} a
  70. ;
  71. ; Examples:
  72. ; See LogicLib.nsi in the Examples folder for lots of example usage.
  73.  
  74. !verbose push
  75. !verbose 3
  76. !ifndef LOGICLIB_VERBOSITY
  77. !define LOGICLIB_VERBOSITY 3
  78. !endif
  79. !define _LOGICLIB_VERBOSITY ${LOGICLIB_VERBOSITY}
  80. !undef LOGICLIB_VERBOSITY
  81. !verbose ${_LOGICLIB_VERBOSITY}
  82.  
  83. !ifndef LOGICLIB
  84. !define LOGICLIB
  85. !define | "'"
  86. !define || "' '"
  87. !define LOGICLIB_COUNTER 0
  88.  
  89. !include Sections.nsh
  90.  
  91. !macro _LOGICLIB_TEMP
  92. !ifndef _LOGICLIB_TEMP
  93. !define _LOGICLIB_TEMP
  94. Var /GLOBAL _LOGICLIB_TEMP ; Temporary variable to aid the more elaborate logic tests
  95. !endif
  96. !macroend
  97.  
  98. !macro LogicLib_JumpToBranch _Jump _Skip
  99. StrCmp "" "" `${_Jump}` ${_Skip}
  100. !macroend
  101.  
  102. !macro _IncreaseCounter
  103. !define /redef /math LOGICLIB_COUNTER `${LOGICLIB_COUNTER}` + 1
  104. !macroend
  105.  
  106. !macro _PushLogic
  107. !insertmacro _PushScope Logic _LogicLib_Label_${LOGICLIB_COUNTER}
  108. !insertmacro _IncreaseCounter
  109. !macroend
  110.  
  111. !macro _PopLogic
  112. !insertmacro _PopScope Logic
  113. !macroend
  114.  
  115. !macro _PushScope Type label
  116. !ifdef _${Type} ; If we already have a statement
  117. !define _Cur${Type} ${_${Type}}
  118. !undef _${Type}
  119. !define _${Type} ${label}
  120. !define ${_${Type}}Prev${Type} ${_Cur${Type}} ; Save the current logic
  121. !undef _Cur${Type}
  122. !else
  123. !define _${Type} ${label} ; Initialise for first statement
  124. !endif
  125. !macroend
  126.  
  127. !macro _PopScope Type
  128. !ifndef _${Type}
  129. !error "Cannot use _Pop${Type} without a preceding _Push${Type}"
  130. !endif
  131. !ifdef ${_${Type}}Prev${Type} ; If a previous statment was active then restore it
  132. !define _Cur${Type} ${_${Type}}
  133. !undef _${Type}
  134. !define _${Type} ${${_Cur${Type}}Prev${Type}}
  135. !undef ${_Cur${Type}}Prev${Type}
  136. !undef _Cur${Type}
  137. !else
  138. !undef _${Type}
  139. !endif
  140. !macroend
  141.  
  142. ; String tests
  143. !macro _== _a _b _t _f
  144. StrCmp `${_a}` `${_b}` `${_t}` `${_f}`
  145. !macroend
  146.  
  147. !macro _!= _a _b _t _f
  148. !insertmacro _== `${_a}` `${_b}` `${_f}` `${_t}`
  149. !macroend
  150.  
  151. ; Case-sensitive string tests
  152. !macro _S== _a _b _t _f
  153. StrCmpS `${_a}` `${_b}` `${_t}` `${_f}`
  154. !macroend
  155.  
  156. !macro _S!= _a _b _t _f
  157. !insertmacro _S== `${_a}` `${_b}` `${_f}` `${_t}`
  158. !macroend
  159.  
  160. ; Extra string tests (cannot do these case-sensitively - I tried and lstrcmp still ignored the case)
  161. !macro _StrCmpI _a _b _e _l _m
  162. !insertmacro _LOGICLIB_TEMP
  163. System::Call `kernel32::lstrcmpi(ts, ts) i.s` `${_a}` `${_b}`
  164. Pop $_LOGICLIB_TEMP
  165. IntCmp $_LOGICLIB_TEMP 0 `${_e}` `${_l}` `${_m}`
  166. !macroend
  167.  
  168. !macro _S< _a _b _t _f
  169. !insertmacro _StrCmpI `${_a}` `${_b}` `${_f}` `${_t}` `${_f}`
  170. !macroend
  171.  
  172. !macro _S>= _a _b _t _f
  173. !insertmacro _S< `${_a}` `${_b}` `${_f}` `${_t}`
  174. !macroend
  175.  
  176. !macro _S> _a _b _t _f
  177. !insertmacro _StrCmpI `${_a}` `${_b}` `${_f}` `${_f}` `${_t}`
  178. !macroend
  179.  
  180. !macro _S<= _a _b _t _f
  181. !insertmacro _S> `${_a}` `${_b}` `${_f}` `${_t}`
  182. !macroend
  183.  
  184. ; Integer tests
  185. !macro _= _a _b _t _f
  186. IntCmp `${_a}` `${_b}` `${_t}` `${_f}` `${_f}`
  187. !macroend
  188.  
  189. !macro _<> _a _b _t _f
  190. !insertmacro _= `${_a}` `${_b}` `${_f}` `${_t}`
  191. !macroend
  192.  
  193. !macro _< _a _b _t _f
  194. IntCmp `${_a}` `${_b}` `${_f}` `${_t}` `${_f}`
  195. !macroend
  196.  
  197. !macro _>= _a _b _t _f
  198. !insertmacro _< `${_a}` `${_b}` `${_f}` `${_t}`
  199. !macroend
  200.  
  201. !macro _> _a _b _t _f
  202. IntCmp `${_a}` `${_b}` `${_f}` `${_f}` `${_t}`
  203. !macroend
  204.  
  205. !macro _<= _a _b _t _f
  206. !insertmacro _> `${_a}` `${_b}` `${_f}` `${_t}`
  207. !macroend
  208.  
  209. !macro _& _a _b _t _f
  210. !insertmacro _LOGICLIB_TEMP
  211. IntOp $_LOGICLIB_TEMP `${_a}` & `${_b}`
  212. !insertmacro _<> $_LOGICLIB_TEMP 0 `${_t}` `${_f}`
  213. !macroend
  214.  
  215. ; Unsigned integer tests (NB: no need for extra equality tests)
  216. !macro _U< _a _b _t _f
  217. IntCmpU `${_a}` `${_b}` `${_f}` `${_t}` `${_f}`
  218. !macroend
  219.  
  220. !macro _U>= _a _b _t _f
  221. !insertmacro _U< `${_a}` `${_b}` `${_f}` `${_t}`
  222. !macroend
  223.  
  224. !macro _U> _a _b _t _f
  225. IntCmpU `${_a}` `${_b}` `${_f}` `${_f}` `${_t}`
  226. !macroend
  227.  
  228. !macro _U<= _a _b _t _f
  229. !insertmacro _U> `${_a}` `${_b}` `${_f}` `${_t}`
  230. !macroend
  231.  
  232. ; Int64 tests
  233. !macro _Int64Cmp _a _o _b _t _f
  234. !insertmacro _LOGICLIB_TEMP
  235. System::Int64Op `${_a}` `${_o}` `${_b}`
  236. Pop $_LOGICLIB_TEMP
  237. !insertmacro _= $_LOGICLIB_TEMP 0 `${_f}` `${_t}`
  238. !macroend
  239.  
  240. !macro _L= _a _b _t _f
  241. !insertmacro _Int64Cmp `${_a}` = `${_b}` `${_t}` `${_f}`
  242. !macroend
  243.  
  244. !macro _L<> _a _b _t _f
  245. !insertmacro _L= `${_a}` `${_b}` `${_f}` `${_t}`
  246. !macroend
  247.  
  248. !macro _L< _a _b _t _f
  249. !insertmacro _Int64Cmp `${_a}` < `${_b}` `${_t}` `${_f}`
  250. !macroend
  251.  
  252. !macro _L>= _a _b _t _f
  253. !insertmacro _L< `${_a}` `${_b}` `${_f}` `${_t}`
  254. !macroend
  255.  
  256. !macro _L> _a _b _t _f
  257. !insertmacro _Int64Cmp `${_a}` > `${_b}` `${_t}` `${_f}`
  258. !macroend
  259.  
  260. !macro _L<= _a _b _t _f
  261. !insertmacro _L> `${_a}` `${_b}` `${_f}` `${_t}`
  262. !macroend
  263.  
  264. ; ptrdiff_t & size_t tests
  265. !macro LogicLib_PtrDiffTest _o _a _b _t _f
  266. !if "${NSIS_PTR_SIZE}" <= 4
  267. !insertmacro _${_o} `${_a}` `${_b}` `${_t}` `${_f}`
  268. !else
  269. !insertmacro _L${_o} `${_a}` `${_b}` `${_t}` `${_f}`
  270. !endif
  271. !macroend
  272. !macro _P= _a _b _t _f
  273. !insertmacro LogicLib_PtrDiffTest = `${_a}` `${_b}` `${_t}` `${_f}`
  274. !macroend
  275. !macro _P<> _a _b _t _f
  276. !insertmacro LogicLib_PtrDiffTest <> `${_a}` `${_b}` `${_t}` `${_f}`
  277. !macroend
  278. !macro _P< _a _b _t _f
  279. !insertmacro LogicLib_PtrDiffTest < `${_a}` `${_b}` `${_t}` `${_f}`
  280. !macroend
  281. !macro _P>= _a _b _t _f
  282. !insertmacro LogicLib_PtrDiffTest >= `${_a}` `${_b}` `${_t}` `${_f}`
  283. !macroend
  284. !macro _P> _a _b _t _f
  285. !insertmacro LogicLib_PtrDiffTest > `${_a}` `${_b}` `${_t}` `${_f}`
  286. !macroend
  287. !macro _P<= _a _b _t _f
  288. !insertmacro LogicLib_PtrDiffTest <= `${_a}` `${_b}` `${_t}` `${_f}`
  289. !macroend
  290. !include Util.nsh
  291. !macro _Z= _a _b _t _f
  292. !insertmacro LogicLib_PtrDiffTest = `${_a}` `${_b}` `${_t}` `${_f}`
  293. !macroend
  294. !macro _Z<> _a _b _t _f
  295. !insertmacro LogicLib_PtrDiffTest <> `${_a}` `${_b}` `${_t}` `${_f}`
  296. !macroend
  297. !macro _Z< _a _b _t _f
  298. !insertmacro IntPtrCmpU `${_a}` `${_b}` `${_f}` `${_t}` `${_f}`
  299. !macroend
  300. !macro _Z>= _a _b _t _f
  301. !insertmacro IntPtrCmpU `${_a}` `${_b}` `${_t}` `${_f}` `${_t}`
  302. !macroend
  303. !macro _Z> _a _b _t _f
  304. !insertmacro IntPtrCmpU `${_a}` `${_b}` `${_f}` `${_f}` `${_t}`
  305. !macroend
  306. !macro _Z<= _a _b _t _f
  307. !insertmacro IntPtrCmpU `${_a}` `${_b}` `${_t}` `${_t}` `${_f}`
  308. !macroend
  309.  
  310. ; Flag tests
  311. !macro _Abort _a _b _t _f
  312. IfAbort `${_t}` `${_f}`
  313. !macroend
  314. !define Abort `"" Abort ""`
  315.  
  316. !macro _Errors _a _b _t _f
  317. IfErrors `${_t}` `${_f}`
  318. !macroend
  319. !define Errors `"" Errors ""`
  320.  
  321. !macro _FileExists _a _b _t _f
  322. IfFileExists `${_b}` `${_t}` `${_f}`
  323. !macroend
  324. !define FileExists `"" FileExists`
  325.  
  326. !macro _RebootFlag _a _b _t _f
  327. IfRebootFlag `${_t}` `${_f}`
  328. !macroend
  329. !define RebootFlag `"" RebootFlag ""`
  330.  
  331. !macro _Silent _a _b _t _f
  332. IfSilent `${_t}` `${_f}`
  333. !macroend
  334. !define Silent `"" Silent ""`
  335.  
  336. ; "Any instruction" test
  337. !macro _Cmd _a _b _t _f
  338. !define _t=${_t}
  339. !ifdef _t= ; If no true label then make one
  340. !define __t _LogicLib_Label_${LOGICLIB_COUNTER}
  341. !insertmacro _IncreaseCounter
  342. !else
  343. !define __t ${_t}
  344. !endif
  345. ${_b} ${__t}
  346. !define _f=${_f}
  347. !ifndef _f= ; If a false label then go there
  348. Goto ${_f}
  349. !endif
  350. !undef _f=${_f}
  351. !ifdef _t= ; If we made our own true label then place it
  352. ${__t}:
  353. !endif
  354. !undef __t
  355. !undef _t=${_t}
  356. !macroend
  357. !define Cmd `"" Cmd`
  358.  
  359. ; Section flag test
  360. !macro _SectionFlagIsSet _a _b _t _f
  361. !insertmacro _LOGICLIB_TEMP
  362. SectionGetFlags `${_b}` $_LOGICLIB_TEMP
  363. IntOp $_LOGICLIB_TEMP $_LOGICLIB_TEMP & `${_a}`
  364. !insertmacro _= $_LOGICLIB_TEMP `${_a}` `${_t}` `${_f}`
  365. !macroend
  366. !define SectionIsSelected `${SF_SELECTED} SectionFlagIsSet`
  367. !define SectionIsSubSection `${SF_SUBSEC} SectionFlagIsSet`
  368. !define SectionIsSubSectionEnd `${SF_SUBSECEND} SectionFlagIsSet`
  369. !define SectionIsSectionGroup `${SF_SECGRP} SectionFlagIsSet`
  370. !define SectionIsSectionGroupEnd `${SF_SECGRPEND} SectionFlagIsSet`
  371. !define SectionIsBold `${SF_BOLD} SectionFlagIsSet`
  372. !define SectionIsReadOnly `${SF_RO} SectionFlagIsSet`
  373. !define SectionIsExpanded `${SF_EXPAND} SectionFlagIsSet`
  374. !define SectionIsPartiallySelected `${SF_PSELECTED} SectionFlagIsSet`
  375.  
  376. !define IfCmd `!insertmacro _IfThen "" Cmd ${|}`
  377.  
  378. !macro _If _c _a _o _b
  379. !verbose push
  380. !verbose ${LOGICLIB_VERBOSITY}
  381. !insertmacro _PushLogic
  382. !define ${_Logic}If
  383. !define ${_Logic}Else _LogicLib_ElseLabel_${LOGICLIB_COUNTER} ; Get a label for the Else
  384. !insertmacro _IncreaseCounter
  385. !define _c=${_c}
  386. !ifdef _c=true ; If is true
  387. !insertmacro _${_o} `${_a}` `${_b}` "" ${${_Logic}Else}
  388. !else ; If condition is false
  389. !insertmacro _${_o} `${_a}` `${_b}` ${${_Logic}Else} ""
  390. !endif
  391. !undef _c=${_c}
  392. !verbose pop
  393. !macroend
  394. !define If `!insertmacro _If true`
  395. !define Unless `!insertmacro _If false`
  396. !define IfNot `!insertmacro _If false`
  397.  
  398. !macro _And _c _a _o _b
  399. !verbose push
  400. !verbose ${LOGICLIB_VERBOSITY}
  401. !ifndef _Logic | ${_Logic}If
  402. !error "Cannot use And without a preceding If or IfNot/Unless"
  403. !endif
  404. !ifndef ${_Logic}Else
  405. !error "Cannot use And following an Else"
  406. !endif
  407. !define _c=${_c}
  408. !ifdef _c=true ; If is true
  409. !insertmacro _${_o} `${_a}` `${_b}` "" ${${_Logic}Else}
  410. !else ; If condition is false
  411. !insertmacro _${_o} `${_a}` `${_b}` ${${_Logic}Else} ""
  412. !endif
  413. !undef _c=${_c}
  414. !verbose pop
  415. !macroend
  416. !define AndIf `!insertmacro _And true`
  417. !define AndUnless `!insertmacro _And false`
  418. !define AndIfNot `!insertmacro _And false`
  419.  
  420. !macro _Or _c _a _o _b
  421. !verbose push
  422. !verbose ${LOGICLIB_VERBOSITY}
  423. !ifndef _Logic | ${_Logic}If
  424. !error "Cannot use Or without a preceding If or IfNot/Unless"
  425. !endif
  426. !ifndef ${_Logic}Else
  427. !error "Cannot use Or following an Else"
  428. !endif
  429. !define _label _LogicLib_Label_${LOGICLIB_COUNTER} ; Skip this test as we already
  430. !insertmacro _IncreaseCounter
  431. Goto ${_label} ; have a successful result
  432. ${${_Logic}Else}: ; Place the Else label
  433. !undef ${_Logic}Else ; and remove it
  434. !define ${_Logic}Else _LogicLib_ElseLabel_${LOGICLIB_COUNTER} ; Get a label for the next Else and perform the new If
  435. !insertmacro _IncreaseCounter
  436. !define _c=${_c}
  437. !ifdef _c=true ; If is true
  438. !insertmacro _${_o} `${_a}` `${_b}` "" ${${_Logic}Else}
  439. !else ; If condition is false
  440. !insertmacro _${_o} `${_a}` `${_b}` ${${_Logic}Else} ""
  441. !endif
  442. !undef _c=${_c}
  443. ${_label}:
  444. !undef _label
  445. !verbose pop
  446. !macroend
  447. !define OrIf `!insertmacro _Or true`
  448. !define OrUnless `!insertmacro _Or false`
  449. !define OrIfNot `!insertmacro _Or false`
  450.  
  451. !macro _Else
  452. !verbose push
  453. !verbose ${LOGICLIB_VERBOSITY}
  454. !ifndef _Logic | ${_Logic}If
  455. !error "Cannot use Else without a preceding If or IfNot/Unless"
  456. !endif
  457. !ifndef ${_Logic}Else
  458. !error "Cannot use Else following an Else"
  459. !endif
  460. !ifndef ${_Logic}EndIf ; First Else for this If?
  461. !define ${_Logic}EndIf _LogicLib_EndIfLabel_${LOGICLIB_COUNTER} ; Get a label for the EndIf
  462. !insertmacro _IncreaseCounter
  463. !endif
  464. Goto ${${_Logic}EndIf} ; Go to the EndIf
  465. ${${_Logic}Else}: ; Place the Else label
  466. !undef ${_Logic}Else ; and remove it
  467. !verbose pop
  468. !macroend
  469. !define Else `!insertmacro _Else`
  470.  
  471. !macro _ElseIf _c _a _o _b
  472. !verbose push
  473. !verbose ${LOGICLIB_VERBOSITY}
  474. ${Else} ; Perform the Else
  475. !define ${_Logic}Else _LogicLib_ElseLabel_${LOGICLIB_COUNTER} ; Get a label for the next Else and perform the new If
  476. !insertmacro _IncreaseCounter
  477. !define _c=${_c}
  478. !ifdef _c=true ; If is true
  479. !insertmacro _${_o} `${_a}` `${_b}` "" ${${_Logic}Else}
  480. !else ; If condition is false
  481. !insertmacro _${_o} `${_a}` `${_b}` ${${_Logic}Else} ""
  482. !endif
  483. !undef _c=${_c}
  484. !verbose pop
  485. !macroend
  486. !define ElseIf `!insertmacro _ElseIf true`
  487. !define ElseUnless `!insertmacro _ElseIf false`
  488. !define ElseIfNot `!insertmacro _ElseIf false`
  489.  
  490. !macro _EndIf _n
  491. !verbose push
  492. !verbose ${LOGICLIB_VERBOSITY}
  493. !ifndef _Logic | ${_Logic}If
  494. !error "Cannot use End${_n} without a preceding If or IfNot/Unless"
  495. !endif
  496. !ifdef ${_Logic}Else
  497. ${${_Logic}Else}: ; Place the Else label
  498. !undef ${_Logic}Else ; and remove it
  499. !endif
  500. !ifdef ${_Logic}EndIf
  501. ${${_Logic}EndIf}: ; Place the EndIf
  502. !undef ${_Logic}EndIf ; and remove it
  503. !endif
  504. !undef ${_Logic}If
  505. !insertmacro _PopLogic
  506. !verbose pop
  507. !macroend
  508. !define EndIf `!insertmacro _EndIf If`
  509. !define EndUnless `!insertmacro _EndIf Unless`
  510.  
  511. !macro _IfThen _a _o _b _t
  512. !verbose push
  513. !verbose ${LOGICLIB_VERBOSITY}
  514. ${If} `${_a}` `${_o}` `${_b}`
  515. ${_t}
  516. ${EndIf}
  517. !verbose pop
  518. !macroend
  519. !define IfThen `!insertmacro _IfThen`
  520.  
  521. !macro _IfNotThen _a _o _b _t
  522. !verbose push
  523. !verbose ${LOGICLIB_VERBOSITY}
  524. ${IfNot} `${_a}` `${_o}` `${_b}`
  525. ${_t}
  526. ${EndIf}
  527. !verbose pop
  528. !macroend
  529. !define IfNotThen `!insertmacro _IfNotThen`
  530.  
  531. !macro _ForEach _v _f _t _o _s
  532. !verbose push
  533. !verbose ${LOGICLIB_VERBOSITY}
  534. StrCpy "${_v}" "${_f}" ; Assign the initial value
  535. Goto +2 ; Skip the loop expression for the first iteration
  536. !define _DoLoopExpression `IntOp "${_v}" "${_v}" "${_o}" "${_s}"` ; Define the loop expression
  537. !define _o=${_o}
  538. !ifdef _o=+ ; Check the loop expression operator
  539. !define __o > ; to determine the correct loop condition
  540. !else ifdef _o=-
  541. !define __o <
  542. !else
  543. !error "Unsupported ForEach step operator (must be + or -)"
  544. !endif
  545. !undef _o=${_o}
  546. !insertmacro _Do For false `${_v}` `${__o}` `${_t}` ; Let Do do the rest
  547. !undef __o
  548. !verbose pop
  549. !macroend
  550. !define ForEach `!insertmacro _ForEach`
  551.  
  552. !macro _For _v _f _t
  553. !verbose push
  554. !verbose ${LOGICLIB_VERBOSITY}
  555. ${ForEach} `${_v}` `${_f}` `${_t}` + 1 ; Pass on to ForEach
  556. !verbose pop
  557. !macroend
  558. !define For `!insertmacro _For`
  559.  
  560. !define ExitFor `!insertmacro _Goto ExitFor For`
  561.  
  562. !define Next `!insertmacro _Loop For Next "" "" "" ""`
  563.  
  564. !define While `!insertmacro _Do While true`
  565.  
  566. !define ExitWhile `!insertmacro _Goto ExitWhile While`
  567.  
  568. !define EndWhile `!insertmacro _Loop While EndWhile "" "" "" ""`
  569.  
  570. !macro _Do _n _c _a _o _b
  571. !verbose push
  572. !verbose ${LOGICLIB_VERBOSITY}
  573. !insertmacro _PushLogic
  574. !define ${_Logic}${_n} _LogicLib_Label_${LOGICLIB_COUNTER} ; Get a label for the start of the loop
  575. !insertmacro _IncreaseCounter
  576. ${${_Logic}${_n}}:
  577. !insertmacro _PushScope Exit${_n} _LogicLib_Label_${LOGICLIB_COUNTER} ; Get a label for the end of the loop
  578. !insertmacro _IncreaseCounter
  579. !insertmacro _PushScope Break ${_Exit${_n}} ; Break goes to the end of the loop
  580. !ifdef _DoLoopExpression
  581. ${_DoLoopExpression} ; Special extra parameter for inserting code
  582. !undef _DoLoopExpression ; between the Continue label and the loop condition
  583. !endif
  584. !define _c=${_c}
  585. !ifdef _c= ; No starting condition
  586. !insertmacro _PushScope Continue _LogicLib_Label_${LOGICLIB_COUNTER} ; Get a label for Continue at the end of the loop
  587. !insertmacro _IncreaseCounter
  588. !else
  589. !insertmacro _PushScope Continue ${${_Logic}${_n}} ; Continue goes to the start of the loop
  590. !ifdef _c=true ; If is true
  591. !insertmacro _${_o} `${_a}` `${_b}` "" ${_Exit${_n}}
  592. !else ; If condition is false
  593. !insertmacro _${_o} `${_a}` `${_b}` ${_Exit${_n}} ""
  594. !endif
  595. !endif
  596. !undef _c=${_c}
  597. !define ${_Logic}Condition ${_c} ; Remember the condition used
  598. !verbose pop
  599. !macroend
  600. !define Do `!insertmacro _Do Do "" "" "" ""`
  601. !define DoWhile `!insertmacro _Do Do true`
  602. !define DoUntil `!insertmacro _Do Do false`
  603.  
  604. !macro _Goto _n _s
  605. !verbose push
  606. !verbose ${LOGICLIB_VERBOSITY}
  607. !ifndef _${_n}
  608. !error "Cannot use ${_n} without a preceding ${_s}"
  609. !endif
  610. Goto ${_${_n}}
  611. !verbose pop
  612. !macroend
  613. !define ExitDo `!insertmacro _Goto ExitDo Do`
  614.  
  615. !macro _Loop _n _e _c _a _o _b
  616. !verbose push
  617. !verbose ${LOGICLIB_VERBOSITY}
  618. !ifndef _Logic | ${_Logic}${_n}
  619. !error "Cannot use ${_e} without a preceding ${_n}"
  620. !endif
  621. !define _c=${${_Logic}Condition}
  622. !ifdef _c= ; If Do had no condition place the Continue label
  623. ${_Continue}:
  624. !endif
  625. !undef _c=${${_Logic}Condition}
  626. !define _c=${_c}
  627. !ifdef _c= ; No ending condition
  628. Goto ${${_Logic}${_n}}
  629. !else ifdef _c=true ; If condition is true
  630. !insertmacro _${_o} `${_a}` `${_b}` ${${_Logic}${_n}} ${_Exit${_n}}
  631. !else ; If condition is false
  632. !insertmacro _${_o} `${_a}` `${_b}` ${_Exit${_n}} ${${_Logic}${_n}}
  633. !endif
  634. !undef _c=${_c}
  635. Goto ${_Continue} ; Just to ensure it is referenced at least once
  636. Goto ${_Exit${_n}} ; Just to ensure it is referenced at least once
  637. ${_Exit${_n}}: ; Place the loop exit point
  638. !undef ${_Logic}Condition
  639. !insertmacro _PopScope Continue
  640. !insertmacro _PopScope Break
  641. !insertmacro _PopScope Exit${_n}
  642. !undef ${_Logic}${_n}
  643. !insertmacro _PopLogic
  644. !verbose pop
  645. !macroend
  646. !define Loop `!insertmacro _Loop Do Loop "" "" "" ""`
  647. !define LoopWhile `!insertmacro _Loop Do LoopWhile true`
  648. !define LoopUntil `!insertmacro _Loop Do LoopUntil false`
  649.  
  650. !define Continue `!insertmacro _Goto Continue "For or Do or While"`
  651. !define Break `!insertmacro _Goto Break "For or Do or While"`
  652.  
  653. !macro _Select _a
  654. !verbose push
  655. !verbose ${LOGICLIB_VERBOSITY}
  656. !insertmacro _PushLogic
  657. !define ${_Logic}Select `${_a}` ; Remember the left hand side of the comparison
  658. !verbose pop
  659. !macroend
  660. !define Select `!insertmacro _Select`
  661.  
  662. !macro _Select_CaseElse
  663. !verbose push
  664. !verbose ${LOGICLIB_VERBOSITY}
  665. !ifndef _Logic | ${_Logic}Select
  666. !error "Cannot use Case without a preceding Select"
  667. !endif
  668. !ifdef ${_Logic}EndSelect ; This is set only after the first case
  669. !ifndef ${_Logic}Else
  670. !error "Cannot use Case following a CaseElse"
  671. !endif
  672. Goto ${${_Logic}EndSelect} ; Go to EndSelect (Ends the previous Case)
  673. !define /IfNDef _LogicLib_EndSelectLabelUsed_${_Logic}
  674. ${${_Logic}Else}: ; Place the Else label
  675. !undef ${_Logic}Else ; and remove it
  676. !else
  677. !define ${_Logic}EndSelect _LogicLib_EndSelectLabel_${LOGICLIB_COUNTER} ; Get a label for the EndSelect
  678. !insertmacro _IncreaseCounter
  679. !endif
  680. !verbose pop
  681. !macroend
  682. !define CaseElse `!insertmacro _CaseElse`
  683. !define Case_Else `!insertmacro _CaseElse` ; Compatibility with 2.2 and earlier
  684. !define Default `!insertmacro _CaseElse` ; For the C-minded
  685.  
  686. !macro _Select_Case _a
  687. !verbose push
  688. !verbose ${LOGICLIB_VERBOSITY}
  689. ${CaseElse} ; Perform the CaseElse
  690. !define ${_Logic}Else _LogicLib_NextSelectCaseLabel_${LOGICLIB_COUNTER} ; Get a label for the next Else and perform the new Case
  691. !insertmacro _IncreaseCounter
  692. !insertmacro _== `${${_Logic}Select}` `${_a}` "" ${${_Logic}Else}
  693. !verbose pop
  694. !macroend
  695. !define Case `!insertmacro _Case`
  696.  
  697. !macro _Case2 _a _b
  698. !verbose push
  699. !verbose ${LOGICLIB_VERBOSITY}
  700. ${CaseElse} ; Perform the CaseElse
  701. !define ${_Logic}Else _LogicLib_NextSelectCaseLabel_${LOGICLIB_COUNTER} ; Get a label for the next Else and perform the new Case
  702. !insertmacro _IncreaseCounter
  703. !insertmacro _== `${${_Logic}Select}` `${_a}` +2 ""
  704. !insertmacro _== `${${_Logic}Select}` `${_b}` "" ${${_Logic}Else}
  705. !verbose pop
  706. !macroend
  707. !define Case2 `!insertmacro _Case2`
  708.  
  709. !macro _Case3 _a _b _c
  710. !verbose push
  711. !verbose ${LOGICLIB_VERBOSITY}
  712. ${CaseElse} ; Perform the CaseElse
  713. !define ${_Logic}Else _LogicLib_NextSelectCaseLabel_${LOGICLIB_COUNTER} ; Get a label for the next Else and perform the new Case
  714. !insertmacro _IncreaseCounter
  715. !insertmacro _== `${${_Logic}Select}` `${_a}` +3 ""
  716. !insertmacro _== `${${_Logic}Select}` `${_b}` +2 ""
  717. !insertmacro _== `${${_Logic}Select}` `${_c}` "" ${${_Logic}Else}
  718. !verbose pop
  719. !macroend
  720. !define Case3 `!insertmacro _Case3`
  721.  
  722. !macro _Case4 _a _b _c _d
  723. !verbose push
  724. !verbose ${LOGICLIB_VERBOSITY}
  725. ${CaseElse} ; Perform the CaseElse
  726. !define ${_Logic}Else _LogicLib_NextSelectCaseLabel_${LOGICLIB_COUNTER} ; Get a label for the next Else and perform the new Case
  727. !insertmacro _IncreaseCounter
  728. !insertmacro _== `${${_Logic}Select}` `${_a}` +4 ""
  729. !insertmacro _== `${${_Logic}Select}` `${_b}` +3 ""
  730. !insertmacro _== `${${_Logic}Select}` `${_c}` +2 ""
  731. !insertmacro _== `${${_Logic}Select}` `${_d}` "" ${${_Logic}Else}
  732. !verbose pop
  733. !macroend
  734. !define Case4 `!insertmacro _Case4`
  735.  
  736. !macro _Case5 _a _b _c _d _e
  737. !verbose push
  738. !verbose ${LOGICLIB_VERBOSITY}
  739. ${CaseElse} ; Perform the CaseElse
  740. !define ${_Logic}Else _LogicLib_NextSelectCaseLabel_${LOGICLIB_COUNTER} ; Get a label for the next Else and perform the new Case
  741. !insertmacro _IncreaseCounter
  742. !insertmacro _== `${${_Logic}Select}` `${_a}` +5 ""
  743. !insertmacro _== `${${_Logic}Select}` `${_b}` +4 ""
  744. !insertmacro _== `${${_Logic}Select}` `${_c}` +3 ""
  745. !insertmacro _== `${${_Logic}Select}` `${_d}` +2 ""
  746. !insertmacro _== `${${_Logic}Select}` `${_e}` "" ${${_Logic}Else}
  747. !verbose pop
  748. !macroend
  749. !define Case5 `!insertmacro _Case5`
  750.  
  751. !macro _EndSelect
  752. !verbose push
  753. !verbose ${LOGICLIB_VERBOSITY}
  754. !ifndef _Logic | ${_Logic}Select
  755. !error "Cannot use EndSelect without a preceding Select"
  756. !endif
  757. !ifdef ${_Logic}Else
  758. ${${_Logic}Else}: ; Place the Else label
  759. !undef ${_Logic}Else ; and remove it
  760. !endif
  761. !ifdef ${_Logic}EndSelect ; This won't be set if there weren't any cases
  762. !ifdef _LogicLib_EndSelectLabelUsed_${_Logic} ; There is no jump to ${${_Logic}EndSelect}: if there is only one Case
  763. ${${_Logic}EndSelect}: ; Place the EndSelect
  764. !undef _LogicLib_EndSelectLabelUsed_${_Logic}
  765. !endif
  766. !undef ${_Logic}EndSelect ; and remove it
  767. !endif
  768. !undef ${_Logic}Select
  769. !insertmacro _PopLogic
  770. !verbose pop
  771. !macroend
  772. !define EndSelect `!insertmacro _EndSelect`
  773.  
  774. !macro _Switch _a
  775. !verbose push
  776. !verbose ${LOGICLIB_VERBOSITY}
  777. !insertmacro _PushLogic
  778. !insertmacro _PushScope Switch ${_Logic} ; Keep a separate stack for switch data
  779. !insertmacro _PushScope Break _LogicLib_Label_${LOGICLIB_COUNTER} ; Get a lable for beyond the end of the switch
  780. !insertmacro _IncreaseCounter
  781. !define ${_Switch}Var `${_a}` ; Remember the left hand side of the comparison
  782. !tempfile ${_Switch}Tmp ; Create a temporary file
  783. !define ${_Logic}Switch _LogicLib_Label_${LOGICLIB_COUNTER} ; Get a label for the end of the switch
  784. !insertmacro _IncreaseCounter
  785. Goto ${${_Logic}Switch} ; and go there
  786. !verbose pop
  787. !macroend
  788. !define Switch `!insertmacro _Switch`
  789.  
  790. !macro _Case _a
  791. !verbose push
  792. !verbose ${LOGICLIB_VERBOSITY}
  793. !ifdef _Logic & ${_Logic}Select ; Check for an active Select
  794. !insertmacro _Select_Case `${_a}`
  795. !else ifndef _Switch ; If not then check for an active Switch
  796. !error "Cannot use Case without a preceding Select or Switch"
  797. !else
  798. !define _label _LogicLib_Label_${LOGICLIB_COUNTER} ; Get a label for this case,
  799. !insertmacro _IncreaseCounter
  800. ${_label}: ; place it and add it's check to the temp file
  801. !appendfile "${${_Switch}Tmp}" `!insertmacro _== $\`${${_Switch}Var}$\` $\`${_a}$\` ${_label} ""$\n`
  802. !undef _label
  803. !endif
  804. !verbose pop
  805. !macroend
  806.  
  807. !macro _CaseElse
  808. !verbose push
  809. !verbose ${LOGICLIB_VERBOSITY}
  810. !ifdef _Logic & ${_Logic}Select ; Check for an active Select
  811. !insertmacro _Select_CaseElse
  812. !else ifndef _Switch ; If not then check for an active Switch
  813. !error "Cannot use Case without a preceding Select or Switch"
  814. !else ifdef ${_Switch}Else ; Already had a default case?
  815. !error "Cannot use CaseElse following a CaseElse"
  816. !else
  817. !define ${_Switch}Else _LogicLib_Label_${LOGICLIB_COUNTER} ; Get a label for the default case,
  818. !insertmacro _IncreaseCounter
  819. ${${_Switch}Else}: ; and place it
  820. !endif
  821. !verbose pop
  822. !macroend
  823.  
  824. !macro _EndSwitch
  825. !verbose push
  826. !verbose ${LOGICLIB_VERBOSITY}
  827. !ifndef _Logic | ${_Logic}Switch
  828. !error "Cannot use EndSwitch without a preceding Switch"
  829. !endif
  830. Goto ${_Break} ; Skip the jump table
  831. ${${_Logic}Switch}: ; Place the end of the switch
  832. !undef ${_Logic}Switch
  833. !include "${${_Switch}Tmp}" ; Include the jump table
  834. !delfile "${${_Switch}Tmp}" ; and clear it up
  835. !ifdef ${_Switch}Else ; Was there a default case?
  836. Goto ${${_Switch}Else} ; then go there if all else fails
  837. !undef ${_Switch}Else
  838. !endif
  839. !undef ${_Switch}Tmp
  840. !undef ${_Switch}Var
  841. ${_Break}: ; Place the break label
  842. !insertmacro _PopScope Break
  843. !insertmacro _PopScope Switch
  844. !insertmacro _PopLogic
  845. !verbose pop
  846. !macroend
  847. !define EndSwitch `!insertmacro _EndSwitch`
  848.  
  849. !endif ; LOGICLIB
  850. !verbose 3
  851. !define LOGICLIB_VERBOSITY ${_LOGICLIB_VERBOSITY}
  852. !undef _LOGICLIB_VERBOSITY
  853. !verbose pop
Buy Me A Coffee