/usr/share/doc/nsis/Examples/LogicLib.nsi is in nsis-doc 2.51-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 | !verbose 2
Name "NSIS LogicLib Example"
OutFile "LogicLib.exe"
ShowInstDetails show
RequestExecutionLevel user
!include "LogicLib.nsh"
;!undef LOGICLIB_VERBOSITY
;!define LOGICLIB_VERBOSITY 4 ; For debugging - watch what logiclib does with your code!
Page components "" "" ComponentsLeave
Page instfiles
Section /o "Run tests" TESTS
; kinds of if other than "value1 comparison value2"
ClearErrors
FindFirst $R1 $R2 "$PROGRAMFILES\*"
${Unless} ${Errors}
${Do}
${Select} $R2
${Case2} "." ".."
; Do nothing
${CaseElse}
DetailPrint "Found $PROGRAMFILES\$R2"
${EndSelect}
FindNext $R1 $R2
${LoopUntil} ${Errors}
FindClose $R1
${EndUnless}
${If} ${FileExists} "${__FILE__}"
DetailPrint 'Source file "${__FILE__}" still exists'
${Else}
DetailPrint 'Source file "${__FILE__}" has gone'
${EndIf}
; if..endif
StrCpy $R1 1
StrCpy $R2 ""
${If} $R1 = 1
StrCpy $R2 $R2A
${EndIf}
${If} $R1 = 2
StrCpy $R2 $R2B
${EndIf}
${If} $R1 < 2
StrCpy $R2 $R2C
${EndIf}
${If} $R1 < -2
StrCpy $R2 $R2D
${EndIf}
${If} $R1 > 2
StrCpy $R2 $R2E
${EndIf}
${If} $R1 > -2
StrCpy $R2 $R2F
${EndIf}
${If} $R1 <> 1
StrCpy $R2 $R2G
${EndIf}
${If} $R1 <> 2
StrCpy $R2 $R2H
${EndIf}
${If} $R1 >= 2
StrCpy $R2 $R2I
${EndIf}
${If} $R1 >= -2
StrCpy $R2 $R2J
${EndIf}
${If} $R1 <= 2
StrCpy $R2 $R2K
${EndIf}
${If} $R1 <= -2
StrCpy $R2 $R2L
${EndIf}
${If} $R2 == "ACFHJK"
DetailPrint "PASSED If..EndIf test"
${Else}
DetailPrint "FAILED If..EndIf test"
${EndIf}
; if..elseif..else..endif
StrCpy $R1 A
StrCpy $R2 ""
${If} $R1 == A
StrCpy $R2 $R2A
${ElseIf} $R1 == B
StrCpy $R2 $R2B
${ElseUnless} $R1 != C
StrCpy $R2 $R2C
${Else}
StrCpy $R2 $R2D
${EndIf}
${If} $R1 == D
StrCpy $R2 $R2D
${ElseIf} $R1 == A
StrCpy $R2 $R2A
${ElseUnless} $R1 != B
StrCpy $R2 $R2B
${Else}
StrCpy $R2 $R2C
${EndIf}
${If} $R1 == C
StrCpy $R2 $R2C
${ElseIf} $R1 == D
StrCpy $R2 $R2D
${ElseUnless} $R1 != A
StrCpy $R2 $R2A
${Else}
StrCpy $R2 $R2B
${EndIf}
${If} $R1 == B
StrCpy $R2 $R2B
${ElseIf} $R1 == C
StrCpy $R2 $R2C
${ElseUnless} $R1 != D
StrCpy $R2 $R2D
${Else}
StrCpy $R2 $R2A
${EndIf}
${If} $R2 == "$R1$R1$R1$R1"
DetailPrint "PASSED If..ElseIf..Else..EndIf test"
${Else}
DetailPrint "FAILED If..ElseIf..Else..EndIf test"
${EndIf}
; if..andif..orif..endif
StrCpy $R2 ""
${If} 1 = 1
${AndIf} 2 = 2
StrCpy $R2 $R2A
${Else}
StrCpy $R2 $R2B
${EndIf}
${If} 1 = 1
${AndIf} 2 = 3
StrCpy $R2 $R2B
${Else}
StrCpy $R2 $R2A
${EndIf}
${If} 1 = 2
${AndIf} 2 = 2
StrCpy $R2 $R2B
${Else}
StrCpy $R2 $R2A
${EndIf}
${If} 1 = 2
${AndIf} 2 = 3
StrCpy $R2 $R2B
${Else}
StrCpy $R2 $R2A
${EndIf}
${If} 1 = 1
${OrIf} 2 = 2
StrCpy $R2 $R2A
${Else}
StrCpy $R2 $R2B
${EndIf}
${If} 1 = 1
${OrIf} 2 = 3
StrCpy $R2 $R2A
${Else}
StrCpy $R2 $R2B
${EndIf}
${If} 1 = 2
${OrIf} 2 = 2
StrCpy $R2 $R2A
${Else}
StrCpy $R2 $R2B
${EndIf}
${If} 1 = 2
${OrIf} 2 = 3
StrCpy $R2 $R2B
${Else}
StrCpy $R2 $R2A
${EndIf}
${If} 1 = 1
${AndIf} 2 = 2
${OrIf} 3 = 3
StrCpy $R2 $R2A
${Else}
StrCpy $R2 $R2B
${EndIf}
${If} 1 = 1
${AndIf} 2 = 3
${OrIf} 3 = 3
StrCpy $R2 $R2A
${Else}
StrCpy $R2 $R2B
${EndIf}
${If} 1 = 2
${AndIf} 2 = 2
${OrIf} 3 = 3
StrCpy $R2 $R2A
${Else}
StrCpy $R2 $R2B
${EndIf}
${If} 1 = 2
${AndIf} 2 = 3
${OrIf} 3 = 3
StrCpy $R2 $R2A
${Else}
StrCpy $R2 $R2B
${EndIf}
${If} 1 = 1
${AndIf} 2 = 2
${OrIf} 3 = 4
StrCpy $R2 $R2A
${Else}
StrCpy $R2 $R2B
${EndIf}
${If} 1 = 1
${AndIf} 2 = 3
${OrIf} 3 = 4
StrCpy $R2 $R2B
${Else}
StrCpy $R2 $R2A
${EndIf}
${If} 1 = 2
${AndIf} 2 = 2
${OrIf} 3 = 4
StrCpy $R2 $R2B
${Else}
StrCpy $R2 $R2A
${EndIf}
${If} 1 = 2
${AndIf} 2 = 3
${OrIf} 3 = 4
StrCpy $R2 $R2B
${Else}
StrCpy $R2 $R2A
${EndIf}
${If} 1 = 1
${OrIf} 2 = 2
${AndIf} 3 = 3
StrCpy $R2 $R2A
${Else}
StrCpy $R2 $R2B
${EndIf}
${If} 1 = 1
${OrIf} 2 = 3
${AndIf} 3 = 3
StrCpy $R2 $R2A
${Else}
StrCpy $R2 $R2B
${EndIf}
${If} 1 = 2
${OrIf} 2 = 2
${AndIf} 3 = 3
StrCpy $R2 $R2A
${Else}
StrCpy $R2 $R2B
${EndIf}
${If} 1 = 2
${OrIf} 2 = 3
${AndIf} 3 = 3
StrCpy $R2 $R2B
${Else}
StrCpy $R2 $R2A
${EndIf}
${If} 1 = 1
${OrIf} 2 = 2
${AndIf} 3 = 4
StrCpy $R2 $R2B
${Else}
StrCpy $R2 $R2A
${EndIf}
${If} 1 = 1
${OrIf} 2 = 3
${AndIf} 3 = 4
StrCpy $R2 $R2B
${Else}
StrCpy $R2 $R2A
${EndIf}
${If} 1 = 2
${OrIf} 2 = 2
${AndIf} 3 = 4
StrCpy $R2 $R2B
${Else}
StrCpy $R2 $R2A
${EndIf}
${If} 1 = 2
${OrIf} 2 = 3
${AndIf} 3 = 4
StrCpy $R2 $R2B
${Else}
StrCpy $R2 $R2A
${EndIf}
${If} $R2 == "AAAAAAAAAAAAAAAAAAAAAAAA"
DetailPrint "PASSED If..AndIf..OrIf..Else..EndIf test"
${Else}
DetailPrint "FAILED If..AndIf..OrIf..Else..EndIf test"
${EndIf}
; ifthen..|..|
StrCpy $R1 1
StrCpy $R2 ""
${IfThen} $R1 = 1 ${|} StrCpy $R2 $R2A ${|}
${IfThen} $R1 = 2 ${|} StrCpy $R2 $R2B ${|}
${IfNotThen} $R1 = 1 ${|} StrCpy $R2 $R2C ${|}
${IfNotThen} $R1 = 2 ${|} StrCpy $R2 $R2D ${|}
${If} $R2 == "AD"
DetailPrint "PASSED IfThen test"
${Else}
DetailPrint "FAILED IfThen test"
${EndIf}
; ifcmd..||..| and if/unless cmd
StrCpy $R2 ""
${IfCmd} MessageBox MB_YESNO "Please click Yes" IDYES ${||} StrCpy $R2 $R2A ${|}
${Unless} ${Cmd} `MessageBox MB_YESNO|MB_DEFBUTTON2 "Please click No" IDYES`
StrCpy $R2 $R2B
${EndUnless}
${If} $R2 == "AB"
DetailPrint "PASSED IfCmd/If Cmd test"
${Else}
DetailPrint "FAILED IfCmd/If Cmd test"
${EndIf}
; select..case..case2..case3..case4..case5..caseelse..endselect
StrCpy $R1 1
StrCpy $R2 ""
${Select} $R1
${Case} "1"
StrCpy $R2 $R2A
${Case} "2"
StrCpy $R2 $R2B
${Case2} "3" "4"
StrCpy $R2 $R2C
${CaseElse}
StrCpy $R2 $R2D
${EndSelect}
${Select} $R1
${Case} "2"
StrCpy $R2 $R2A
${Case} "3"
StrCpy $R2 $R2B
${Case2} "4" "5"
StrCpy $R2 $R2C
${CaseElse}
StrCpy $R2 $R2D
${EndSelect}
${Select} $R1
${Case} "3"
StrCpy $R2 $R2A
${Case} "4"
StrCpy $R2 $R2B
${Case2} "5" "1"
StrCpy $R2 $R2C
${CaseElse}
StrCpy $R2 $R2D
${EndSelect}
${Select} $R1
${Case} "4"
StrCpy $R2 $R2A
${Case} "5"
StrCpy $R2 $R2B
${Case2} "1" "2"
StrCpy $R2 $R2C
${CaseElse}
StrCpy $R2 $R2D
${EndSelect}
${If} $R2 == "ADCC"
DetailPrint "PASSED Select..Case*..EndSelect test"
${Else}
DetailPrint "FAILED Select..Case*..EndSelect test"
${EndIf}
; switch..case..caseelse..endswitch
StrCpy $R2 ""
${For} $R1 1 10
${Switch} $R1
${Case} 3
StrCpy $R2 $R2A
${Case} 4
StrCpy $R2 $R2B
${Break}
${Case} 5
StrCpy $R2 $R2C
${EndSwitch}
${Switch} $R1
${Case} 1
StrCpy $R2 $R2D
${Default}
StrCpy $R2 $R2E
${Break}
${Case} 2
StrCpy $R2 $R2F
${EndSwitch}
${Switch} $R1
${Case} 6
${Case} 7
StrCpy $R2 $R2G
${If} $R1 = 6
${Case} 8
StrCpy $R2 $R2H
${Switch} $R1
${Case} 6
StrCpy $R2 $R2I
${Break}
${Case} 8
StrCpy $R2 $R2J
${EndSwitch}
${EndIf}
StrCpy $R2 $R2K
${Break}
${Default}
StrCpy $R2 $R2L
${Case} 9
StrCpy $R2 $R2M
${EndSwitch}
${Next}
${If} $R2 == "DELMFLMABELMBELMCELMEGHIKEGKEHJKEMELM"
DetailPrint "PASSED Switch..Case*..EndSwitch test"
${Else}
DetailPrint "FAILED Switch..Case*..EndSwitch test"
${EndIf}
; for[each]..exitfor..next
StrCpy $R2 ""
${For} $R1 1 5
StrCpy $R2 $R2$R1
${Next}
${ForEach} $R1 10 1 - 1
StrCpy $R2 $R2$R1
${Next}
${For} $R1 1 0
StrCpy $R2 $R2$R1
${Next}
${If} $R2 == "1234510987654321"
DetailPrint "PASSED For[Each]..Next test"
${Else}
DetailPrint "FAILED For[Each]..Next test"
${EndIf}
; do..loop
StrCpy $R1 0
Call DoLoop
${If} $R1 == 5
DetailPrint "PASSED Do..Loop test"
${Else}
DetailPrint "FAILED Do..Loop test"
${EndIf}
; do..exitdo..loop
StrCpy $R1 0
StrCpy $R2 ""
${Do}
StrCpy $R2 $R2$R1
IntOp $R1 $R1 + 1
${If} $R1 > 10
${ExitDo}
${EndIf}
${Loop}
${If} $R2 == "012345678910"
DetailPrint "PASSED Do..ExitDo..Loop test"
${Else}
DetailPrint "FAILED Do..ExitDo..Loop test"
${EndIf}
; do..exitdo..loopuntil
StrCpy $R1 0
StrCpy $R2 ""
${Do}
StrCpy $R2 $R2$R1
IntOp $R1 $R1 + 1
${LoopUntil} $R1 >= 5
${If} $R2 == "01234"
DetailPrint "PASSED Do..ExitDo..LoopUntil test"
${Else}
DetailPrint "FAILED Do..ExitDo..LoopUntil test"
${EndIf}
; dountil..exitdo..loop
StrCpy $R1 0
StrCpy $R2 ""
${DoUntil} $R1 >= 5
StrCpy $R2 $R2$R1
IntOp $R1 $R1 + 1
${Loop}
${If} $R2 == "01234"
DetailPrint "PASSED DoUntil..ExitDo..Loop test"
${Else}
DetailPrint "FAILED DoUntil..ExitDo..Loop test"
${EndIf}
; nested do test
StrCpy $R1 0
StrCpy $R2 0
StrCpy $R3 ""
${Do}
StrCpy $R3 $R3$R1$R2
IntOp $R1 $R1 + 1
${If} $R1 > 5
${ExitDo}
${EndIf}
StrCpy $R2 0
${Do}
StrCpy $R3 $R3$R1$R2
IntOp $R2 $R2 + 1
${If} $R2 >= 5
${ExitDo}
${EndIf}
${Loop}
${Loop}
${If} $R3 == "00101112131415202122232425303132333435404142434445505152535455"
DetailPrint "PASSED nested Do test"
${Else}
DetailPrint "FAILED nested Do test"
${EndIf}
; while..exitwhile..endwhile (exact replica of dowhile..enddo}
StrCpy $R1 0
StrCpy $R2 ""
${While} $R1 < 5
StrCpy $R2 $R2$R1
IntOp $R1 $R1 + 1
${EndWhile}
${If} $R2 == "01234"
DetailPrint "PASSED While..ExitWhile..EndWhile test"
${Else}
DetailPrint "FAILED While..ExitWhile..EndWhile test"
${EndIf}
; Unsigned integer tests
StrCpy $R2 ""
${If} -1 < 1
StrCpy $R2 $R2A
${EndIf}
${If} -1 U< 1
StrCpy $R2 $R2B
${EndIf}
${If} 0xFFFFFFFF > 1
StrCpy $R2 $R2C
${EndIf}
${If} 0xFFFFFFFF U> 1
StrCpy $R2 $R2D
${EndIf}
${If} $R2 == "AD"
DetailPrint "PASSED unsigned integer test"
${Else}
DetailPrint "FAILED unsigned integer test"
${EndIf}
; 64-bit integer tests (uses System.dll)
StrCpy $R2 ""
${If} 0x100000000 L= 4294967296
StrCpy $R2 $R2A
${EndIf}
${If} 0x100000000 L< 0x200000000
StrCpy $R2 $R2B
${EndIf}
${If} 0x500000000 L>= 0x500000000
StrCpy $R2 $R2C
${EndIf}
${If} $R2 == "ABC"
DetailPrint "PASSED 64-bit integer test"
${Else}
DetailPrint "FAILED 64-bit integer test"
${EndIf}
; Extra string tests (uses System.dll)
StrCpy $R2 ""
${If} "A" S< "B"
StrCpy $R2 $R2A
${EndIf}
${If} "b" S> "A"
StrCpy $R2 $R2B
${EndIf}
${If} "a" S<= "B"
StrCpy $R2 $R2C
${EndIf}
${If} "B" S< "B"
StrCpy $R2 $R2D
${EndIf}
${If} "A" S== "A"
StrCpy $R2 $R2E
${EndIf}
${If} "A" S== "a"
StrCpy $R2 $R2F
${EndIf}
${If} "A" S!= "a"
StrCpy $R2 $R2G
${EndIf}
${If} $R2 == "ABCEG"
DetailPrint "PASSED extra string test"
${Else}
DetailPrint "FAILED extra string test"
${EndIf}
SectionEnd
Function ComponentsLeave
; Section flags tests (requires sections.nsh be included)
${Unless} ${SectionIsSelected} ${TESTS}
MessageBox MB_OK "Please select the component"
Abort
${EndIf}
FunctionEnd
Function DoLoop
${Do}
IntOp $R1 $R1 + 1
${If} $R1 == 5
Return
${EndIf}
${Loop}
FunctionEnd
!verbose 3
|