From bug-request at octave dot org Sat Dec 10 22:14:14 2005 Subject: Re: Can I submit a ver.m and license.m? From: William Poetra Yoga Hadisoeseno To: bug at octave dot org Date: Sun, 11 Dec 2005 12:12:39 +0800 ------=_Part_20427_27620205.1134274359994 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline I've added the struct to ver.m (similar to the cell array in license.m). The diff is attached. -- William Poetra Yoga Hadisoeseno ------=_Part_20427_27620205.1134274359994 Content-Type: text/plain; name=ver.diff.txt; charset=us-ascii Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="ver.diff.txt" Index: scripts/miscellaneous/ver.m =================================================================== RCS file: /cvs/octave/scripts/miscellaneous/ver.m,v retrieving revision 1.2 diff -u -r1.2 ver.m --- scripts/miscellaneous/ver.m 30 Nov 2005 03:04:45 -0000 1.2 +++ scripts/miscellaneous/ver.m 11 Dec 2005 04:07:08 -0000 at @ -18,51 +18,139 @@ ## 02110-1301, USA. ## -*- texinfo -*- -## at deftypefn {Function File} {} ver +## at deftypefn {Function File} {} ver () +## at deftypefnx {Function File} {@var{prodinfo} =} ver () +## at deftypefnx {Function File} {@var{prodinfo} =} ver (@var{product}) ## at code{ver} displays a header containing the current Octave version ## number, license string and operating system, followed by the version ## number for octave-forge, if installed. +## +## If called with a return value or a product name, return a structure +## with the fields at code{Name}, @code{Version}, @code{Release} and +## at code{Date} dot +## +## If product name at var{product} is specified, then the version information +## for that specific product (instead of all products) is returned in the +## structure. ## at end deftypefn +## ## at seealso{license, version} -## Author: William Poetra Yoga Hadisoeseno +## Author: William Poetra Yoga Hadisoeseno -function ver () +function prodinfo = ver (product) - if (nargin > 0) - usage ("ver"); + persistent __prodinfo__; + + if (isempty (__prodinfo__)) + __prodinfo__ = struct (); + __prodinfo__.Name = "Octave"; + __prodinfo__.Version = version (); + __prodinfo__.Release = __get_api_ver__ (); + __prodinfo__.Date = __expand_date__ (""); + if (exist ("OCTAVE_FORGE_VERSION")) + __prodinfo__(2).Name = "octave-forge"; + __prodinfo__(2).Version = num2str(OCTAVE_FORGE_VERSION); + __prodinfo__(2).Release = num2str(OCTAVE_FORGE_VERSION); + __prodinfo__(2).Date = __expand_date__ (num2str (OCTAVE_FORGE_VERSION)); + endif endif - octave_license = license (); + nin = nargin; + nout = nargout; + nr_products = length (__prodinfo__); + + if (nin == 0 && nout == 0) + + [unm, status] = uname (); + + if (status < 0) + os_string = "unknown"; + else + os_string = sprintf ("%s %s %s %s", unm.sysname, unm.release, + unm.version, unm.machine); + endif + + hbar(1:70) = "-"; + ver_line1 = "GNU Octave Version "; + ver_line2 = "GNU Octave License: "; + ver_line3 = "Operating System: "; + + ver_desc = sprintf ("%s\n%s%s (%s)\n%s%s\n%s%s\n%s\n", hbar, ver_line1, + __prodinfo__(1).Version, __prodinfo__(1).Release, + ver_line2, license (), ver_line3, os_string, hbar); + + if (length (__prodinfo__) > 1) + octave_forge_name = __prodinfo__(2).Name; + octave_forge_version = __prodinfo__(2).Version; + octave_forge_release = __prodinfo__(2).Release; + octave_forge_string = sprintf ("%s%sVersion %s%s(%s)\n", + octave_forge_name, + blanks (round(0.45 * length (hbar)) + - length (octave_forge_name)), + octave_forge_version, + blanks (round(0.35 * length (hbar)) - 8 + - length (octave_forge_version)), + octave_forge_release); + ver_desc = strcat (ver_desc, octave_forge_string); + endif + + puts (ver_desc); + + elseif (nin == 1 || nout == 1) + + if (nin == 1) + found = false; + for p = 1:nr_products + if (strcmpi (product, __prodinfo__(p).Name)) + found = true; + break; + endif + endfor + + if (found) + prodinfo = __prodinfo__(p); + else + prodinfo = struct ("Name", "", "Version", "", "Release", "", "Date", ""); + endif + + else + + prodinfo = __prodinfo__; - [unm, status] = uname (); + endif - if (status < 0) - os_string = "unknown"; else - os_string = sprintf ("%s %s %s %s", unm.sysname, unm.release, - unm.version, unm.machine); + + usage ("[prodinfo] = ver ([product])"); + endif - hbar(1:70) = "-"; - ver_line1 = "GNU Octave Version "; - ver_line2 = "GNU Octave License: "; - ver_line3 = "Operating System: "; - - ver_desc = sprintf ("%s\n%s%s\n%s%s\n%s%s\n%s\n", hbar, ver_line1, version, - ver_line2, octave_license, ver_line3, os_string, hbar); - - if (exist ("OCTAVE_FORGE_VERSION")) - octave_forge_name = "octave-forge"; - octave_forge_version = num2str (OCTAVE_FORGE_VERSION); - octave_forge_string = sprintf ("%s%s%s\n", octave_forge_name, - blanks (round(0.75 * length (hbar)) - - length (octave_forge_name) - - length (octave_forge_version)), - octave_forge_version); - ver_desc = strcat (ver_desc, octave_forge_string); +endfunction + +function api_ver = __get_api_ver__ () + + localapifcnfiledir = octave_config_info ("localapifcnfiledir"); + + idx0 = strfind (localapifcnfiledir, "api-v"); + + if (isempty (idx0)) + api_ver = ""; + return; + endif + + idx1 = strfind (localapifcnfiledir(idx0:end), "/"); + + if (isempty (idx1)) + idx1 = length (localapifcnfiledir(idx0:end)) + 1; endif - puts (ver_desc); + api_ver = localapifcnfiledir(idx0:(idx0 + idx1 - 2)); + +endfunction + +function expanded_date = __expand_date__ (date_string) + + expanded_date = strftime ("%d-%b-%Y", strptime (date_string, "%Y%m%d")); endfunction ------=_Part_20427_27620205.1134274359994-- ------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL. Octave's home on the web: http://www.octave.org How to fund new projects: http://www.octave.org/funding.html Subscription information: http://www.octave.org/archive.html -------------------------------------------------------------