Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: st: Programming a version-number check


From   "Mark Schaffer" <[email protected]>
To   [email protected]
Subject   RE: st: Programming a version-number check
Date   Mon, 26 Sep 2005 08:58:02 +0100 (BST)

Thanks, Scott, that's great.  I had expected there would be no avoiding
-file-, but the programming isn't as messy as I had feared.  Interesting,
on my Windows 2000 machine, -findfile- returns a path with a mixture of \s
and /s, but -file open- is unfazed by this.

To answer Richard's question, I am writing an ado that calls another ado
that can be used separately and may have been installed earlier.  If so,
and if it's an old version, it won't be compatible with the new ado.  I
want the new ado to check the version of the old ado and exit gracefully
with an error message that says "update the old one".

Cheers,
Mark

> Here is oneway:
>
> *! version 1.0.0
> * Adapted from -ltype- [P] file
> program release_marker, rclass
> 	version 9.1
>  	qui findfile `0'.ado
>  	local 0 `"using `"`r(fn)'"'"'
> 	syntax using/
> 	tempname fh
>  	file open `fh' using `"`using'"', read
>  	file read `fh' line
> 	tokenize "`macval(line)'"
> 	if substr("`1'",1,2) == "*!" {
>  		if "`2'" == "version" {
>  			local rm = "`3'"
>  			}
>  		if "`3'" == "version" {
>  			local rm = "`4'"
>  			}
>  		if  real(substr("`3'",1,1))  != . {
> 		        local rm = "`3'"
>  			}
>               	if real(substr("`2'",1,1)) != . {
> 			local rm = "`2'"
> 		}
> 	}
> 	if "`1'" == "*!version" {
> 		local rm = "`2'"
> 	}
> 	file read `fh' line
>         file close `fh'
>  	disp in gr "Release marker = ""`rm'"
>  	return local release_marker  "`rm'"
> end
>
>
> . release_marker gologit2
> Release marker = 2.02
>
> . release_marker xtreg
> Release marker = 1.5.1
>
> . release_marker ivreg2
> Release marker = 2.1.08
>
> . release_marker ivreg
> Release marker = 5.3.4
>
> This assumes the release marker is in the first line.
>
> Hope this helps,
> Scott
>
>
>> -----Original Message-----
>> From: [email protected] [mailto:owner-
>> [email protected]] On Behalf Of Mark Schaffer
>> Sent: Sunday, September 25, 2005 5:13 PM
>> To: [email protected]
>> Cc: [email protected]
>> Subject: Re: st: Programming a version-number check
>>
>> Richard,
>>
>> > At 03:59 PM 9/25/2005, Mark Schaffer wrote:
>> >>Using -findfile- to get the path to the ado, opening the ado with
>> -file-
>> ,
>> >>and then messing about with file i/o is unappealing, though I suppose
>> it
>> >>could be made to work.  Is there anything easier?
>> >>
>> >>--Mark
>> >
>> > One additional complication is that there is nothing that says an ado
>> > file has to use the same version number throughout, e.g. different
>> > subroutines could use different version numbers.  Would you need to
>> > track all of them, the highest one, the lowest one, or what?
>>
>> What I have in mind is pretty straightforward in principle.  Many ados
>> have a few lines at the top that start with the characters "*!".  I
>> would
>> want to grab the line that has "*!" followed by "version".  E.g., ivreg
>> has at the top
>>
>> *! version 5.1.3  21jul2004
>>
>> I would take that line, tokenize it, and if the second token is
>> "version",
>> the third token would be the version number, namely "5.1.3".
>>
>> I suppose this could be done with -findfile-, then -file open- and -file
>> read-, but it's a hassle, esp. dealing with pathnames and different
>> operating systems, \ vs. /, and all that.
>>
>> --Mark
>
>
> *
> *   For searches and help try:
> *   http://www.stata.com/support/faqs/res/findit.html
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
>


Prof. Mark Schaffer
Director, CERT
Department of Economics
School of Management & Languages
Heriot-Watt University, Edinburgh EH14 4AS
tel +44-131-451-3494 / fax +44-131-451-3294
email: [email protected]
web: http://www.sml.hw.ac.uk/ecomes



__________________________________________________________________

DISCLAIMER:

This e-mail message is subject to http://www.hw.ac.uk/disclaim.htm
__________________________________________________________________

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index