File: primes.nsi

package info (click to toggle)
nsis 3.11-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 12,496 kB
  • sloc: cpp: 39,326; ansic: 27,284; python: 1,386; asm: 712; xml: 409; pascal: 231; makefile: 225; javascript: 67
file content (70 lines) | stat: -rwxr-xr-x 1,656 bytes parent folder | download
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
; primes.nsi
;
; This is an example of the possibilities of the NSIS Script language.
; It calculates prime numbers.

;--------------------------------

Name "primes"
AllowRootDirInstall true
OutFile "primes.exe"
Caption "Prime number generator"
ShowInstDetails show
AllowRootDirInstall true
InstallDir "$EXEDIR"
RequestExecutionLevel user

DirText "Select a directory to write primes.txt. $_CLICK"

;--------------------------------

;Pages

Page directory
Page instfiles

;--------------------------------

Section ""
  SetOutPath $INSTDIR
  Call DoPrimes 
SectionEnd

;--------------------------------

Function DoPrimes

; we put this in here so it doesn't update the progress bar (faster)

!define PPOS $0 ; position in prime searching
!define PDIV $1 ; divisor
!define PMOD $2 ; the result of the modulus
!define PCNT $3 ; count of how many we've printed
  FileOpen $9 $INSTDIR\primes.txt w

  DetailPrint "2 is prime!"
  FileWrite $9 "2 is prime!$\r$\n"
  DetailPrint "3 is prime!"
  FileWrite $9 "3 is prime!$\r$\n"
  Strcpy ${PPOS} 3
  Strcpy ${PCNT} 2
outerloop:
   StrCpy ${PDIV} 3
   innerloop:
     IntOp ${PMOD} ${PPOS} % ${PDIV}
     IntCmp ${PMOD} 0 notprime
     IntOp ${PDIV} ${PDIV} + 2
     IntCmp ${PDIV} ${PPOS} 0 innerloop 0
       DetailPrint "${PPOS} is prime!"
       FileWrite $9 "${PPOS} is prime!$\r$\n"
       IntOp ${PCNT} ${PCNT} + 1
       IntCmp ${PCNT} 100 0 innerloop
       StrCpy ${PCNT} 0
       MessageBox MB_YESNO "Process more?" IDNO stop
     notprime:
       IntOp ${PPOS} ${PPOS} + 2
     Goto outerloop
   stop:
  FileClose $9
  
FunctionEnd