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

RE: st: Programming a version-number check


From   "Scott Merryman" <[email protected]>
To   <[email protected]>
Subject   RE: st: Programming a version-number check
Date   Sun, 25 Sep 2005 22:33:26 -0500

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/



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