LogicLib.nsh 29 KB

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