Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

Getting version number of a Rebol Program.

 [1/12] from: gschwarz::netconnect::com::au at: 22-May-2003 9:28


I have been looking at ways to read (in text mode) a program to check if there is a newer version of the program. I can do it this way, may not be the best! a: to-block read %program.r b: load a/rebol ; just loads the rebol header do b ; make words from the header Then the word version would have the version number so you can compere if a newer version would be needed to download. Is this the only way of getting the version number (or any thing else in the rebol header)? Regards, Greg Schwarz.

 [2/12] from: antonr:iinet:au at: 22-May-2003 11:45


This is from my dir-utils.r library at http://www.lexicon.net/anton/rebol/library/dir-utils.r version?: func ["Returns the version from the header of a rebol script." ;does not evaluate the header. file [file!] /local whitespace non-whitespace a b version ][ if not all [exists? file attempt [script? file]][return none] error? try [ return select second load/all file to-set-word "version" ; does not evaluate header ] error? try [ print "trying parse." non-whitespace: complement whitespace: charset " ^/^-" parse/all read file [ thru "rebol" thru "[" thru "version:" some whitespace a: some non-whitespace b: (version: copy/part a b) to end ] return to-tuple version ] ;error? try [ ;return get in first load/header %my-script.r 'version ; evaluates header (dangerous) ;] return none ] Anton Rolls.

 [3/12] from: brett:codeconscious at: 22-May-2003 14:11


Your idea of loading the script is probably fine, but depending on your REBOL version have a look at LOAD/ALL and CONSTRUCT to avoid inadvertently evaluating header elements. Construct is safer than Context and DO where the source block is potentially untrustworthy. Compare these: probe construct [title: "test" version: 1.0.0 print now] probe context [title: "test" version: 1.0.0 print now] Also don't forget that a header is made up of pairs of set-word! and values. Each set-word! is a value. So once you have your header block you could just do the following: select [Title: "test" version: 1.0.0] to-set-word 'version But this is probably better hdr: construct [Title: "test" version: 1.0.0] hdr/version Regards, Brett.

 [4/12] from: gschwarz:netconnect:au at: 22-May-2003 16:49


Thank you Brett. I was not aware of CONSTRUCT, only write in REBOL at odd times. Regards, Greg

 [5/12] from: g:santilli:tiscalinet:it at: 22-May-2003 10:20


Hi Anton, On Thursday, May 22, 2003, 3:45:01 AM, you wrote: A> ;error? try [ A> ;return get in first load/header %my-script.r 'version ; evaluates header A> (dangerous) A> ;] BTW, just as a reminder, the latest /Core no longer evaluates the header, so if you know you're not running on an old version it is safe to just use LOAD. (In particular, it is safe for SDK users to use LOAD.) Regards, Gabriele. -- Gabriele Santilli <[g--santilli--tiscalinet--it]> -- REBOL Programmer Amigan -- AGI L'Aquila -- REB: http://web.tiscali.it/rebol/index.r

 [6/12] from: g:santilli:tiscalinet:it at: 22-May-2003 10:18


Hi Greg, On Thursday, May 22, 2003, 1:28:31 AM, you wrote: GS> Then the word version would have the version number so you can GS> compere if a newer version would be needed to download. Is GS> this the only way of getting the version number (or any thing GS> else in the rebol header)? You might want to have a look at system/script/header. :-) Regards, Gabriele. -- Gabriele Santilli <[g--santilli--tiscalinet--it]> -- REBOL Programmer Amigan -- AGI L'Aquila -- REB: http://web.tiscali.it/rebol/index.r

 [7/12] from: Cal:prolific at: 21-May-2003 18:33


>> a: first load/all/header %feedback.r >> a/version
== 1.0.0

 [8/12] from: gschwarz:netconnect:au at: 23-May-2003 9:31


Cal, Thank you for your input. Below is what I have done which is much neater, only some of the names changed. a: first load/all/header %program.r b: first load/all/header to-file join program-location [ "tools/program.r" ] if a/version <> b/version [ write %program.r read to-file join program-location [ "tools/program.r" ] print "Tools program updated, please restart program." wait 5 quit] Regards, Greg ----- Original Message ----- From: "Cal" <[Cal--prolific--com]> To: <[rebol-list--rebol--com]> Cc: <[gschwarz--netconnect--com--au]>

 [9/12] from: antonr:iinet:au at: 23-May-2003 11:08


if program-location is already a file, then join program-location something-else will result in a file, so you don't need to then convert using 'to-file. Anton.

 [10/12] from: gschwarz:netconnect:au at: 23-May-2003 12:09


Anton, In my case the program-location is a folder location for a number of programs. In an office all pc's would have the newest version of any program they are using all the time. No need to e-mail every one to load the latest version. Regards, Greg

 [11/12] from: Al:Bri:xtra at: 23-May-2003 17:52


> a: first load/all/header %program.r > b: first load/all/header to-file join program-location [
tools/program.r ]
> if a/version <> b/version [ write %program.r read to-file join > program-location [ "tools/program.r" ]
This is nicer: The_File: %tools/program.r b: first load/all/header program-location/:The_File if a/version <> b/version [ write %program.r read program-location/:The_File ] Andrew Martin ICQ: 26227169 http://www.rebol.it/Valley/ http://Valley.150m.com/

 [12/12] from: antonr:iinet:au at: 24-May-2003 15:36


Pardon me? Yes, I understand what the code is for, I'm just making a point about optimizing. In your code at bottom, twice you have written: to-file join program-location [...] My point is that can be simplified to: join program-location [...] as long as program-location is of type file! and ends in a slash. Sorry about any confusion. Regards, Anton.