home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / perl / 4959 < prev    next >
Encoding:
Internet Message Format  |  1992-07-25  |  16.5 KB

  1. Path: sparky!uunet!mcsun!corton!ircam!fingerhu
  2. From: fingerhu@ircam.fr (Michel Fingerhut)
  3. Newsgroups: comp.lang.perl
  4. Subject: VERSIONS 3.1 -- program to retrieve version numbers of programs
  5. Message-ID: <1992Jul25.095442.22767@ircam.fr>
  6. Date: 25 Jul 92 09:54:42 GMT
  7. Organization: Inst. de Recherche et Coordination Acoustique/Musique, Paris
  8. Lines: 533
  9.  
  10. The following shar file is a much augmented version of 'versions', the
  11. program used to identify the version number of installed programs.
  12.  
  13. Here is a brief list of some of the new features since release 2.3:
  14.  
  15. * allow output in tbl format (suitable for piping into tbl | ??roff or
  16.   inclusion in reports).
  17. * allow use of alternate methods file (e.g., for debugging or personal
  18.   programs).
  19. * allow use of environment variables in the methods file (e.g., $HOME,
  20.   $PROJ, ...) as dynamic paths.
  21. * allow use of relative paths to programs, automatically searched in $PATH,
  22.   to be used as further simplification of the methods file (e.g.,
  23.             gcc    %% -v 2>&1    %v
  24.   (at the cost of search time).  This form can also be used as a way
  25.   to list the versions of those programs in the users' $PATHs -- which may
  26.   override the publically installed ones.
  27.  
  28. As usual, please email me any comments.
  29.  
  30. -------------------------------------- cut here --------------------------------
  31. #! /bin/sh
  32. # This is a shell archive.  Remove anything before this line, then unpack
  33. # it by saving it into a file and typing "sh file".  To overwrite existing
  34. # files, type "sh file -c".  You can also feed this as standard input via
  35. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  36. # will see the following message at the end:
  37. #        "End of shell archive."
  38. # Contents:  versions.1 versions.sh versions.dat Makefile
  39. # Wrapped by fingerhu@vaslav on Sat Jul 25 11:41:41 1992
  40. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  41. if test -f 'versions.1' -a "${1}" != "-c" ; then 
  42.   echo shar: Will not clobber existing file \"'versions.1'\"
  43. else
  44. echo shar: Extracting \"'versions.1'\" \(3759 characters\)
  45. sed "s/^X//" >'versions.1' <<'END_OF_FILE'
  46. X.TH VERSIONS 1 "IRCAM 3.1 7/25/92"
  47. X.SH NAME
  48. Xversions - print versions of locally-installed programs
  49. X.SH SYNOPSIS
  50. X.B versions
  51. X[
  52. X.B \-v
  53. X]
  54. X[
  55. X.B \-l
  56. X]
  57. X[
  58. X.B \-t
  59. X]
  60. X[
  61. X.B \-f
  62. X.I specs-file
  63. X]
  64. X[
  65. X.I program ...
  66. X]
  67. X.SH DESCRIPTION
  68. X.PP
  69. X.B Versions
  70. Xprints the current version number (and installation date, if
  71. X.BR \-l )
  72. Xof some locally installed programs.
  73. XIf no program name is given, it lists all the programs found in the
  74. X.B /usr/local/lib/versions.dat
  75. Xmethods file (or from the
  76. X.I specs-file
  77. Xspecified with the optional
  78. X.B \-f
  79. Xflag).
  80. X
  81. XIf any program names are specified, it lists the required information
  82. Xfor them (if they appear in the methods file).
  83. X.SH OPTIONS
  84. X.TP
  85. X.B \-v
  86. Xprints its own version (equivalent to
  87. X.BR versions\ versions )
  88. Xand exit.
  89. X.TP
  90. X.B \-l
  91. X(long format) prints also installation date
  92. X.TP
  93. X.B \-t
  94. Xproduce output in
  95. X.B tbl
  96. Xformat (suitable to be piped into further processing tools).  If this
  97. Xoption is selected, long format is automatically chosen too.
  98. X.TP
  99. X.B \-f
  100. X.I specs-file
  101. Xread the methods used to extract the version from this file instead of the
  102. Xdefault
  103. X.B /usr/local/lib/versions.dat.
  104. X.TP
  105. X.I program ...
  106. Xprint only the version numbers (and installation dates)
  107. Xof the programs (if their names
  108. Xappear in the methods file).
  109. X.SH THE METHODS FILE
  110. X.I Specs-file
  111. X(or the default
  112. X.BR /usr/local/lib/versions.dat)
  113. Xcontains a list of programs with the method used to retrieve the version
  114. Xnumber in each.  Each line consists of 3
  115. X.I tab-separated
  116. Xfields: the first one
  117. Xis the path to the program, the second one a shell command used
  118. Xin order to extract a string containing the version information,
  119. Xand the last one a perl pattern used to extract the version from the string
  120. Xobtained via the shell command.
  121. X
  122. XThe path may either be absolute, in which case
  123. X.B versions
  124. Xuses it as the location of the program, or relative, in which case it
  125. Xsearches for the file in the
  126. X.B $PATH
  127. Xenvironment variable (at the expense of time).  This allows specifying
  128. Xprograms which may live in different places for different users.
  129. X
  130. XThe perl pattern must include one or two ``bracketing-construct'' ( ... )
  131. Xwhich enclose the pattern retrieving the version number, the second one
  132. Xbeing for the level number.  Hence the use of parentheses in the pattern
  133. Xmust take into account that $1 and $2 are used by the program in order
  134. Xto print the 
  135. X.I version(level)
  136. Xinformation.
  137. X
  138. XEnvironment variables can be used within any part of the line.  It can be
  139. Xused in retrieving user-dependent path as
  140. X.B $HOME/bin.
  141. X
  142. XA limited form of one-level macros is permitted so as to simplify the
  143. Xdescription.  The special
  144. X.B %%
  145. Xmacro stands for the full path (i.e., the first field
  146. Xin each line, usually used in the 2nd field).  Other macros can
  147. Xbe defined in that file: the definition is on a line of the form
  148. X.IR macro=string ,
  149. Xand any subsequent occurrence of 
  150. X.BI % macro
  151. Xis replaced by
  152. X.I string.
  153. XMacro definition lines should not contain tabs (other than leading
  154. Xto a possible comment).
  155. X
  156. XBlank lines and comments (following a # to the end of the line) are
  157. Xpermitted and ignored.  Hence the # character cannot appear in a macro
  158. Xname or value nor anywhere else except as a comment-starter: the pattern
  159. Xfor
  160. X.B named
  161. Xused to be
  162. X.B @(#)named
  163. Xwhich broke with the introduction of comments.  This can be safely
  164. Xreplaced by
  165. X.B @(.)named
  166. Xe.g.
  167. X.SH BUGS
  168. XNot all programs are included, since some don't have an idea of their
  169. Xown version number (other than in the sources, sometimes, wherever they
  170. Xmay be).  It would be nice if people writing significant programs
  171. Xprovided a flag returning the version information, or at least
  172. Xan identifiable string in the executable from which it could be inferred.
  173. X.SH AUTHOR
  174. XMichel Fingerhut (fingerhu@ircam.fr) with suggestions by
  175. XPeter W Osel (pwo@sunrise.zfe.siemens.de).
  176. END_OF_FILE
  177. if test 3759 -ne `wc -c <'versions.1'`; then
  178.     echo shar: \"'versions.1'\" unpacked with wrong size!
  179. fi
  180. # end of 'versions.1'
  181. fi
  182. if test -f 'versions.sh' -a "${1}" != "-c" ; then 
  183.   echo shar: Will not clobber existing file \"'versions.sh'\"
  184. else
  185. echo shar: Extracting \"'versions.sh'\" \(5638 characters\)
  186. sed "s/^X//" >'versions.sh' <<'END_OF_FILE'
  187. X#!/usr/local/bin/perl
  188. X#            Copyright (c) 1992 by IRCAM
  189. X#                All rights reserved.
  190. X#
  191. X#  For any information regarding this and other IRCAM software, please 
  192. X#  send email to:
  193. X#                              manager@ircam.fr
  194. X
  195. X#
  196. X# versions    2.8 IRCAM 7/24/92
  197. X#
  198. X# Extract program version number
  199. X#
  200. X# Modification history
  201. X#
  202. X# 22-Jul-92 - Michel Fingerhut (fingerhu@ircam.fr)
  203. X#    added suggestions from Peter W Osel (pwo@sunrise.zfe.siemens.de)
  204. X#    (use of getopts, -f flag)
  205. X#
  206. X# 21-Jul-92 - Michel Fingerhut (fingerhu@ircam.fr)
  207. X#    added macro capability and various sanity checks
  208. X#
  209. X# 20-Jul-92 - Michel Fingerhut (fingerhu@ircam.fr)
  210. X#    initial version
  211. X#
  212. X
  213. X$[          = 1;                 # set array base to 1
  214. X$,          = ' ';               # set output field separator
  215. X$\          = "\n";              # set output record separator
  216. X$options    = 'f:vlt';         # for getopts
  217. X
  218. X$specs_file = "/usr/local/lib/versions.dat";    # unless -f to override
  219. X$usage      = "Usage: $0 [-v] [-l] [-t] [-f specs-file] [program ...]\n";
  220. X
  221. X$today        = &asctime(time);
  222. X
  223. X#-------------------------------------------------------------------------------
  224. X# formats for short form of output
  225. X#-------------------------------------------------------------------------------
  226. X
  227. X$format_top_s= "
  228. Xprogram          version
  229. X-------          -------
  230. X.
  231. X";
  232. X
  233. X$format_s= '
  234. X@<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<<<<<<<
  235. X$program,     $version
  236. X.
  237. X';
  238. X
  239. X#-------------------------------------------------------------------------------
  240. X# formats for long form of output
  241. X#-------------------------------------------------------------------------------
  242. X
  243. X$format_top_l= "
  244. Xprogram          version                   date installed
  245. X-------          -------                   --------------
  246. X.
  247. X";
  248. X
  249. X$format_l= '
  250. X@<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<<
  251. X$program,     $version,                 &asctimefile($path)
  252. X.
  253. X';
  254. X
  255. X#------------------------------------------------------------------------------
  256. X# tbl output
  257. X#------------------------------------------------------------------------------
  258. X
  259. X$format_top_t= "print \"
  260. X.(c
  261. XINSTALLED PROGRAMS ON $today
  262. X.)c
  263. X.sp 5
  264. X.TS
  265. Xcenter box;
  266. Xc c c
  267. Xl l l.
  268. XProgram\tVersion\tDate installed
  269. X_\"";
  270. X
  271. X$format_t    = 'printf "%s\t%s\t%s\n", $program, $version, &asctimefile($path);';
  272. X
  273. X$format_end_t= 'print ".TE"';
  274. X
  275. X#------------------------------------------------------------------------------
  276. X# main program
  277. X#------------------------------------------------------------------------------
  278. X
  279. X# parse arguments
  280. Xrequire 'getopts.pl';
  281. Xdie $usage if ! &Getopts($options);    # failed parsing the arguments
  282. X$specs_file= $opt_f if defined $opt_f;    # override default specs file
  283. X
  284. X# if -v, print version and exit
  285. Xif (defined $opt_v) {
  286. X    print "2.8 IRCAM 7/24/92";
  287. X    exit;
  288. X}
  289. X
  290. X# set format according to -l (long) otherwise short
  291. Xif ($opt_t) {
  292. X    eval $format_top_t;
  293. X} elsif ($opt_l) {
  294. X    eval "format top= $format_top_l; format= $format_l" ;
  295. X} else {
  296. X    eval "format top= $format_top_s; format= $format_s" ;
  297. X}
  298. X
  299. X# determine which selected programs to list
  300. Xif ($#ARGV) {
  301. X    foreach $a (@ARGV) {
  302. X    $doit{$a} = 1;
  303. X    }
  304. X}
  305. X
  306. X# read dat file and execute program
  307. X
  308. Xopen (DAT, $specs_file) || die "Couldn't find specs file $specs_file: $!\n";
  309. X
  310. Xwhile (<DAT>) {
  311. X
  312. X    chop;
  313. X    s/\s*#.*$//;            # strip comments
  314. X    next if /^$/;            # skip empty lines
  315. X    while (/.*\$(\w+).*/) {             # find all occurrences
  316. X    $value= $ENV{eval $1};        # compute the value
  317. X    s/(\$\w+)/$value/;        # and do the replacement
  318. X    }
  319. X
  320. X    if ( ! /\t/ ) {             # macro descr section contains no tabs
  321. X
  322. X    # this is a macro definition - find name and store the definition
  323. X    @l = split(/=/);
  324. X    die "*** macro % cannot be defined (reserved)\n" if $l[1] eq '%';
  325. X    die "*** macro $l[1] multiply defined\n" if defined $macro{$l[1]};
  326. X    $macro{$l[1]}= $l[2];
  327. X
  328. X    } else {                # if tab, description section
  329. X
  330. X    # perform macro substitution on all the line
  331. X    foreach $key (keys %macro) { 
  332. X        s/\%$key/$macro{$key}/g;
  333. X    }
  334. X
  335. X    # split the line into the path, shell command and perl pattern
  336. X        ($path, $command, $pattern)= split(/\t+/);
  337. X
  338. X    # check if the file exists
  339. X    if ($path !~ /^\/.*/) {
  340. X        # relative path: look for file in $PATH (we won't do aliases!)
  341. X        foreach $dir (split(/:/, $ENV{'PATH'})) {
  342. X        $path= "$dir/$path", last if -f "$dir/$path";
  343. X        }
  344. X    }
  345. X    next if $path !~ /^\/.*/ || ! -f $path;
  346. X
  347. X    # perform special macro subst: %% -> $path
  348. X    $command=~ s/\%\%/$path/g;
  349. X
  350. X    # identify the program name (after last / in path name)
  351. X    ($program= $path) =~ s/.*\///;    #    isolate prog name (after last / )
  352. X
  353. X    # ignore this entry if there are arguments and it is not one of them
  354. X        next if $#ARGV && ! defined $doit{$program};
  355. X
  356. X    # find version number from pattern
  357. X        undef $version;
  358. X        $version= $1 if `$command` =~ /.*$pattern.*/;
  359. X        $version .= "($2)" if $2;
  360. X
  361. X    # print
  362. X        write          unless $opt_t;
  363. X    eval $format_t if $opt_t;
  364. X    }
  365. X}
  366. Xclose(DAT);
  367. Xeval $format_end_t if $opt_t;
  368. X
  369. X#------------------------------------------------------------------------------
  370. X# asctimefile - return creation time of a file in ascii
  371. X#------------------------------------------------------------------------------
  372. Xsub asctimefile {{
  373. X    return &asctime((stat($_[1]))[10]);
  374. X}}
  375. X
  376. X#------------------------------------------------------------------------------
  377. X# asctime - convert time from 1/1/1970 to ascii
  378. X#------------------------------------------------------------------------------
  379. Xsub asctime {{
  380. X    @mon= ('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
  381. X       'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
  382. X    @time= localtime($_[1]);
  383. X    return sprintf("%2d %s 19%02d %02d:%02d",
  384. X    $time[4], $mon[$time[5]+1], $time[6], $time[3], $time[2]);
  385. X}}
  386. END_OF_FILE
  387. if test 5638 -ne `wc -c <'versions.sh'`; then
  388.     echo shar: \"'versions.sh'\" unpacked with wrong size!
  389. fi
  390. # end of 'versions.sh'
  391. fi
  392. if test -f 'versions.dat' -a "${1}" != "-c" ; then 
  393.   echo shar: Will not clobber existing file \"'versions.dat'\"
  394. else
  395. echo shar: Extracting \"'versions.dat'\" \(1967 characters\)
  396. sed "s/^X//" >'versions.dat' <<'END_OF_FILE'
  397. X# Macros 3.1 IRCAM 7/24/92 for versions
  398. X#
  399. X#                       Copyright (c) 1992 by IRCAM
  400. X#                           All rights reserved.
  401. X#
  402. X#  For any information regarding this and other IRCAM software, please
  403. X#  send email to:
  404. X#                              manager@ircam.fr
  405. X
  406. XBIN=/usr/local/bin        # where most of our binaries are
  407. XETC=/usr/local/etc        # where some odd ones live
  408. XLIB=/usr/local/lib        # where most of our libraries are
  409. X
  410. Xl=level[^ ]* ([^ ,\n]+)        # retrieves the level number (in $2, usually)
  411. Xv=[Vv]ersion[^ ]* ([^ ,\n]+)    # retrieves the version number (in $1, hopefully)
  412. Xs=[^ ,\n]+            # version number string in most cases
  413. Xj=.*\n.*            # junk between version and level across lines
  414. X
  415. XTEX=tex/inputs            # to shorten the macro def. line for tex
  416. Xtv=.def.texinfoversion
  417. X
  418. X# Methods
  419. X
  420. X%ETC/amd        %% -v 2>&1            amd (%s)
  421. X%BIN/bison        bison --version 2>/dev/null    Bison %v
  422. X%BIN/diff        diff +version 2>&1        GNU diff %v
  423. X%BIN/f2c        echo | %%            version of (.*) ..:
  424. X%BIN/find        %% /dev/null -version 2>&1    %v
  425. X%BIN/flex        %% -v < /dev/null 2>&1        %v
  426. X%BIN/formes        %% -h                NEW:\t(%s)
  427. X%BIN/ftoch        %% -v                Version . (%s)
  428. X%BIN/g++        gcc -v 2>&1            %v
  429. X%BIN/gcc        %% -v 2>&1            %v
  430. X%BIN/gdb        echo quit | %%            GDB (%s),
  431. X%BIN/gnuplot        echo sh ver | %% 2>&1        %v%j%l
  432. X%BIN/X11/ghostview    strings %%            Ghostview, %v
  433. X%BIN/grep        %% -V 2>&1            grep, %v
  434. X%BIN/kcl        echo \(bye\) | %%        Version\((%s)\)
  435. X%BIN/kermit        echo quit | %%            C-Kermit, (%s)
  436. X%BIN/lelisp        echo \(end\) | %%        %v
  437. X%BIN/make        %% -v 2>/dev/null        %v
  438. X%BIN/matlab        %% -v 2>/dev/null        %v
  439. X%ETC/named        strings %%            @\(.\)named (%s)
  440. X%BIN/patch        %% -v 2>&1            patch.c,v (%s)%j%l
  441. X%BIN/perl        %% -v                Revision: (%s)%j%l
  442. X%BIN/rcs        strings %%            rcs.c,v (%s)
  443. X/usr/lib/sendmail    echo quit | %% -bs        Sendmail (%s)
  444. X%BIN/svp        %% 2>&1                %v
  445. X%BIN/tar        %% +version 2>&1        %v
  446. X%BIN/tex        cd /tmp; echo \\end | %%    %v
  447. X%LIB/%TEX/texinfo.tex    cat %%                %tv{(%s)}
  448. X%BIN/top        strings %%            Top, %v
  449. X%BIN/unzip        %% 2>&1                Zipfile Extract v(.*) of
  450. X%BIN/versions        %% -v                ^(%s)
  451. END_OF_FILE
  452. if test 1967 -ne `wc -c <'versions.dat'`; then
  453.     echo shar: \"'versions.dat'\" unpacked with wrong size!
  454. fi
  455. # end of 'versions.dat'
  456. fi
  457. if test -f 'Makefile' -a "${1}" != "-c" ; then 
  458.   echo shar: Will not clobber existing file \"'Makefile'\"
  459. else
  460. echo shar: Extracting \"'Makefile'\" \(1782 characters\)
  461. sed "s/^X//" >'Makefile' <<'END_OF_FILE'
  462. X# 7/23/92 IRCAM @(#)Makefile    1.1
  463. X#                       Copyright (c) 1991 by IRCAM
  464. X#                           All rights reserved.
  465. X#
  466. X#  For any information regarding this and other IRCAM software, please
  467. X#  send email to:
  468. X#                              manager@ircam.fr
  469. X
  470. X#
  471. X# Gnumake file automatically generated by makemake for versions
  472. X#
  473. X# Modification history
  474. X#
  475. X
  476. XMAKEFILE    := Makefile
  477. XTARGET        := versions
  478. XROOTDIR        := /usr/local
  479. XOWNER        := root
  480. XGROUP        := wheel
  481. X# Where executables and man pages go
  482. XBINDIR        := $(ROOTDIR)/bin
  483. XLIBDIR        := $(ROOTDIR)/lib
  484. XMANDIR        := $(ROOTDIR)/man
  485. XDESTDIR        := $(BINDIR)
  486. XSHFILES        :=  versions.sh
  487. XTAPE        := /dev/rmt0h
  488. XLIBFILES    := versions.dat
  489. XMANFILES1    :=  versions.1
  490. XMANFILES    :=  $(MANFILES1)
  491. XINSTMANFILES    := $(addprefix $(MANDIR)/man1/, $(MANFILES1))
  492. XINSTLIBFILES    := $(addprefix $(LIBDIR)/, $(LIBFILES))
  493. XDOCFILES    := 
  494. XOTHERS        := 
  495. XOBJECTS        := 
  496. XSOURCE        := $(MAKEFILE) $(MANFILES) $(DOCFILES) $(SHFILES) \
  497. X           $(OTHERS) $(INCLUDES) $(YACCFILES) $(LEXFILES) \
  498. X           $(CFILES) $(FFILES) $(ASFILES)
  499. XLISTFILES    := $(MAKEFILE) $(SHFILES) $(INCLUDES) $(YACCFILES) \
  500. X           $(LEXFILES) $(CFILES) $(FFILES) $(ASFILES)
  501. X
  502. X.PHONY: all install uninstall clean depend
  503. Xall:     $(TARGET)
  504. X
  505. Xinstall: $(DESTDIR)/$(TARGET) $(INSTMANFILES) $(INSTLIBFILES)
  506. X
  507. Xuninstall:
  508. X    rm -f $(DESTDIR)/$(TARGET) $(INSTMANFILES) $(INSTLIBFILES)
  509. X
  510. Xdepend:
  511. X
  512. X$(TARGET):    $(TARGET).sh
  513. X
  514. X$(DESTDIR)/$(TARGET): $(TARGET)
  515. X    install -c -o $(OWNER) -g $(GROUP) -m 0755 $< $@
  516. X
  517. X$(MANDIR)/man1/% : %
  518. X    install -c -o $(OWNER) -g $(GROUP) -m 0644 $< $@
  519. X$(LIBDIR)/% : %
  520. X    install -c -o $(OWNER) -g $(GROUP) -m 0644 $< $@
  521. Xtar:
  522. X    tar rfcb $(TAPE) 20 $(SOURCE)
  523. Xcpio:
  524. X    ls $(SOURCE) | cpio -oB
  525. Xlint:
  526. X    $(LINT) $(CPPFLAGS) $(CFILES)
  527. Xclean:
  528. X    -rm -f $(OBJECTS)
  529. X    sccs clean
  530. Xclobber: clean
  531. X    -rm -f $(TARGET)
  532. Xtouch:
  533. X    touch $(TARGET)
  534. X
  535. END_OF_FILE
  536. if test 1782 -ne `wc -c <'Makefile'`; then
  537.     echo shar: \"'Makefile'\" unpacked with wrong size!
  538. fi
  539. # end of 'Makefile'
  540. fi
  541. echo shar: End of shell archive.
  542. exit 0
  543.