home *** CD-ROM | disk | FTP | other *** search
/ Hackers Magazine 57 / CdHackersMagazineNr57.iso / Software / Programming / nsis-2.46-setup.exe / Examples / primes.nsi < prev    next >
Text File  |  2008-01-27  |  2KB  |  70 lines

  1. ; primes.nsi
  2. ;
  3. ; This is an example of the possibities of the NSIS Script language.
  4. ; It calculates prime numbers.
  5.  
  6. ;--------------------------------
  7.  
  8. Name "primes"
  9. AllowRootDirInstall true
  10. OutFile "primes.exe"
  11. Caption "Prime number generator"
  12. ShowInstDetails show
  13. AllowRootDirInstall true
  14. InstallDir "$EXEDIR"
  15. RequestExecutionLevel user
  16.  
  17. DirText "Select a directory to write primes.txt. $_CLICK"
  18.  
  19. ;--------------------------------
  20.  
  21. ;Pages
  22.  
  23. Page directory
  24. Page instfiles
  25.  
  26. ;--------------------------------
  27.  
  28. Section ""
  29.   SetOutPath $INSTDIR
  30.   Call DoPrimes 
  31. SectionEnd
  32.  
  33. ;--------------------------------
  34.  
  35. Function DoPrimes
  36.  
  37. ; we put this in here so it doesn't update the progress bar (faster)
  38.  
  39. !define PPOS $0 ; position in prime searching
  40. !define PDIV $1 ; divisor
  41. !define PMOD $2 ; the result of the modulus
  42. !define PCNT $3 ; count of how many we've printed
  43.   FileOpen $9 $INSTDIR\primes.txt w
  44.  
  45.   DetailPrint "2 is prime!"
  46.   FileWrite $9 "2 is prime!$\r$\n"
  47.   DetailPrint "3 is prime!"
  48.   FileWrite $9 "3 is prime!$\r$\n"
  49.   Strcpy ${PPOS} 3
  50.   Strcpy ${PCNT} 2
  51. outerloop:
  52.    StrCpy ${PDIV} 3
  53.    innerloop:
  54.      IntOp ${PMOD} ${PPOS} % ${PDIV}
  55.      IntCmp ${PMOD} 0 notprime
  56.      IntOp ${PDIV} ${PDIV} + 2
  57.      IntCmp ${PDIV} ${PPOS} 0 innerloop 0
  58.        DetailPrint "${PPOS} is prime!"
  59.        FileWrite $9 "${PPOS} is prime!$\r$\n"
  60.        IntOp ${PCNT} ${PCNT} + 1
  61.        IntCmp ${PCNT} 100 0 innerloop
  62.        StrCpy ${PCNT} 0
  63.        MessageBox MB_YESNO "Process more?" IDNO stop
  64.      notprime:
  65.        IntOp ${PPOS} ${PPOS} + 2
  66.      Goto outerloop
  67.    stop:
  68.   FileClose $9
  69.   
  70. FunctionEnd