LogicLib.nsh 31 KB

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