LogicLib.nsh 31 KB

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