home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 March / CMCD0304.ISO / Software / Freeware / Programare / nullsoft / nsis20.exe / Examples / primes.nsi < prev    next >
Text File  |  2003-09-05  |  2KB  |  69 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.  
  16. DirText "Select a directory to write primes.txt. $_CLICK"
  17.  
  18. ;--------------------------------
  19.  
  20. ;Pages
  21.  
  22. Page directory
  23. Page instfiles
  24.  
  25. ;--------------------------------
  26.  
  27. Section ""
  28.   SetOutPath $INSTDIR
  29.   Call DoPrimes 
  30. SectionEnd
  31.  
  32. ;--------------------------------
  33.  
  34. Function DoPrimes
  35.  
  36. ; we put this in here so it doesn't update the progress bar (faster)
  37.  
  38. !define PPOS $0 ; position in prime searching
  39. !define PDIV $1 ; divisor
  40. !define PMOD $2 ; the result of the modulus
  41. !define PCNT $3 ; count of how many we've printed
  42.   FileOpen $9 $INSTDIR\primes.txt w
  43.  
  44.   DetailPrint "2 is prime!"
  45.   FileWrite $9 "2 is prime!$\r$\n"
  46.   DetailPrint "3 is prime!"
  47.   FileWrite $9 "3 is prime!$\r$\n"
  48.   Strcpy ${PPOS} 3
  49.   Strcpy ${PCNT} 2
  50. outerloop:
  51.    StrCpy ${PDIV} 3
  52.    innerloop:
  53.      IntOp ${PMOD} ${PPOS} % ${PDIV}
  54.      IntCmp ${PMOD} 0 notprime
  55.      IntOp ${PDIV} ${PDIV} + 2
  56.      IntCmp ${PDIV} ${PPOS} 0 innerloop 0
  57.        DetailPrint "${PPOS} is prime!"
  58.        FileWrite $9 "${PPOS} is prime!$\r$\n"
  59.        IntOp ${PCNT} ${PCNT} + 1
  60.        IntCmp ${PCNT} 100 0 innerloop
  61.        StrCpy ${PCNT} 0
  62.        MessageBox MB_YESNO "Process more?" IDNO stop
  63.      notprime:
  64.        IntOp ${PPOS} ${PPOS} + 2
  65.      Goto outerloop
  66.    stop:
  67.   FileClose $9
  68.   
  69. FunctionEnd