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

  1. Path: sparky!uunet!mcsun!corton!ircam!fingerhu
  2. From: fingerhu@ircam.fr (Michel Fingerhut)
  3. Newsgroups: comp.lang.perl
  4. Subject: versions 2.1 (extract version number of programs)
  5. Message-ID: <1992Jul21.143117.24207@ircam.fr>
  6. Date: 21 Jul 92 14:31:17 GMT
  7. Organization: Inst. de Recherche et Coordination Acoustique/Musique, Paris
  8. Lines: 368
  9.  
  10. Here is the second (and last, I let it rest for a day or two) version of
  11. my 'versions' program, used to list the version number of selected programs.
  12. The main differences with the previous version are:
  13.  
  14. 1.  as an option, it lists the installation date of the program.
  15. 2.  the description file's format has been extended to allow for macros,
  16.     which simplify the writing.
  17.  
  18. Comments by email are welcome.
  19.  
  20. ------------------------------ cut here -------------------------------------
  21. #! /bin/sh
  22. # This is a shell archive.  Remove anything before this line, then unpack
  23. # it by saving it into a file and typing "sh file".  To overwrite existing
  24. # files, type "sh file -c".  You can also feed this as standard input via
  25. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  26. # will see the following message at the end:
  27. #        "End of shell archive."
  28. # Contents:  versions.1 versions versions.dat Makefile
  29. # Wrapped by fingerhu@nadia on Tue Jul 21 16:30:00 1992
  30. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  31. if test -f 'versions.1' -a "${1}" != "-c" ; then 
  32.   echo shar: Will not clobber existing file \"'versions.1'\"
  33. else
  34. echo shar: Extracting \"'versions.1'\" \(1776 characters\)
  35. sed "s/^X//" >'versions.1' <<'END_OF_FILE'
  36. X.TH VERSIONS 1 "IRCAM 2.1 7/21/92"
  37. X.SH NAME
  38. Xversions - print versions of locally-installed programs
  39. X.SH SYNOPSIS
  40. X.B versions
  41. X[
  42. X.B -v
  43. X]
  44. X[
  45. X.B -l
  46. X]
  47. X[
  48. X.I program ...
  49. X]
  50. X.SH DESCRIPTION
  51. X.PP
  52. X.I Versions
  53. Xprints the current version number (and installation date, if
  54. X.BR \-l )
  55. Xof some locally installed programs.
  56. XIf no option is given, it lists all the programs found in the
  57. X.B /usr/local/bin/versions.dat
  58. Xdescription file, otherwise it lists only those whose names are
  59. Xspecified on the command line.
  60. X.SH OPTIONS
  61. X.TP
  62. X.B -v
  63. Xprints its own version (equivalent to
  64. X.B versions\ version )
  65. Xand exit.
  66. X.TP
  67. X.B \-l
  68. X(long format) prints also installation date
  69. X.TP
  70. X.I program ...
  71. Xprint only the version numbers (and installation dates)
  72. Xof the programs (if their names
  73. Xappear in the description file).
  74. X.SH FILES
  75. X.TP
  76. X.I /usr/local/bin/versions.dat
  77. Xcontains a list of programs with the method used to retrieve the version
  78. Xnumber in each.  Each line consists of 3 tab-separated fields: the first one
  79. Xis the absolute path to the program, the second one a shell command to extract
  80. Xa string containing the version information, and the last a perl pattern
  81. Xused to extract the version from the string obtained via the shell command.
  82. X
  83. XA limited form of macros is permitted so as to simplify the description.
  84. XThe special
  85. X.B %%
  86. Xmacro stands for the full path (i.e., the first field
  87. Xin each line, usually used in the 2nd field).  Other macros can
  88. Xbe defined in that file: the definition is on a line of the form
  89. X.IR macro=string ,
  90. Xand any subsequent occurrence of 
  91. X.BI % macro
  92. Xis replaced by
  93. X.I string.
  94. X.SH BUGS
  95. XNot all programs are included, since some don't have an idea of their
  96. Xown version number (other than in the sources, sometimes, wherever they
  97. Xmay be).
  98. X.SH AUTHOR
  99. XMichel Fingerhut (fingerhu@ircam.fr)
  100. END_OF_FILE
  101. if test 1776 -ne `wc -c <'versions.1'`; then
  102.     echo shar: \"'versions.1'\" unpacked with wrong size!
  103. fi
  104. # end of 'versions.1'
  105. fi
  106. if test -f 'versions' -a "${1}" != "-c" ; then 
  107.   echo shar: Will not clobber existing file \"'versions'\"
  108. else
  109. echo shar: Extracting \"'versions'\" \(3496 characters\)
  110. sed "s/^X//" >'versions' <<'END_OF_FILE'
  111. X#!/usr/local/bin/perl -s
  112. X#            Copyright (c) 1992 by IRCAM
  113. X#                All rights reserved.
  114. X#
  115. X#  For any information regarding this and other IRCAM software, please 
  116. X#  send email to:
  117. X#                              manager@ircam.fr
  118. X
  119. X#
  120. X# versions    2.1 IRCAM 7/21/92
  121. X#
  122. X# Modification history
  123. X#
  124. X# Extract program version number
  125. X#
  126. X# 20-Jul-92 - Michel Fingerhut (fingerhu@ircam.fr)
  127. X#
  128. X
  129. X$[ = 1;                 # set array base to 1
  130. X$, = ' ';               # set output field separator
  131. X$\ = "\n";              # set output record separator
  132. X
  133. X#-------------------------------------------------------------------------------
  134. X# formats for short form of output
  135. X#-------------------------------------------------------------------------------
  136. X
  137. X$format_top_s= "
  138. Xprogram          version
  139. X-------          -------
  140. X.
  141. X";
  142. X
  143. X$format_s= '
  144. X@<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<<
  145. X$program,     $version
  146. X.
  147. X';
  148. X
  149. X#-------------------------------------------------------------------------------
  150. X# formats for long form of output
  151. X#-------------------------------------------------------------------------------
  152. X
  153. X$format_top_l= "
  154. Xprogram          version              date installed
  155. X-------          -------              --------------
  156. X.
  157. X";
  158. X
  159. X$format_l= '
  160. X@<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<<
  161. X$program,     $version,            &asctime($path)
  162. X.
  163. X';
  164. X
  165. X#------------------------------------------------------------------------------
  166. X# main program
  167. X#------------------------------------------------------------------------------
  168. X
  169. X# if -v, print version and exit
  170. Xif ($v) {
  171. X    print "2.1 IRCAM 7/21/92";
  172. X    exit;
  173. X}
  174. X
  175. X# set format according to -l (long) otherwise short
  176. Xif ($l) {
  177. X    eval "format top= $format_top_l; format= $format_l" ;
  178. X} else {
  179. X    eval "format top= $format_top_s; format= $format_s" ;
  180. X}
  181. X
  182. X# determine which selected programs to list
  183. Xif ($#ARGV) {
  184. X    foreach $a (@ARGV) {
  185. X    $doit{$a} = 1;
  186. X    }
  187. X}
  188. X
  189. X# read dat file and execute program
  190. X
  191. Xopen (DAT, "/usr/local/lib/versions.dat") || die "Couldn't find dat file: $!\n";
  192. X
  193. Xwhile (<DAT>) {
  194. X
  195. X    chop;
  196. X    next if /^$/;
  197. X
  198. X    if ( ! /\t/ ) {             # macro descr section contains no tabs
  199. X
  200. X    # this is a macro definition - find name and store the definition
  201. X    @l = split(/=/);
  202. X    $macro{$l[1]}= $l[2];
  203. X
  204. X    } else {                # if tab, description section
  205. X
  206. X    # perform macro substitution on all the line
  207. X    foreach $key (%macro) { 
  208. X        s/\%$key/$macro{$key}/g;
  209. X    }
  210. X
  211. X    # split the line into the path, shell command and perl pattern
  212. X        ($path, $command, $pattern)= split(/\t+/);
  213. X    next if (! -f $path);
  214. X
  215. X    # perform special macro subst: %% -> $path
  216. X    $command=~ s/\%\%/$path/g;
  217. X
  218. X    # identify the program name (after last / in path name)
  219. X    ($program= $path) =~ s/.*\///;    #    isolate prog name (after last / )
  220. X
  221. X    # ignore this entry if there are arguments and it is not one of them
  222. X        next if $#ARGV && ! defined $doit{$program};
  223. X
  224. X    # find version number from pattern
  225. X        undef $version;
  226. X        $version= $1 if `$command` =~ /.*$pattern.*/;
  227. X        $version .= "($2)" if $2;
  228. X
  229. X    # print
  230. X        write;
  231. X    }
  232. X}
  233. Xclose(DAT);
  234. X
  235. X#------------------------------------------------------------------------------
  236. X# asctime - convert time from 1/1/1970 to ascii
  237. X#------------------------------------------------------------------------------
  238. Xsub asctime {{
  239. X    @mon= ('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
  240. X       'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
  241. X    @time= localtime((stat($_[1]))[10]);
  242. X    return sprintf("%2d %s 19%02d %02d:%02d",
  243. X    $time[4], $mon[$time[5]+1], $time[6], $time[3], $time[2]);
  244. X}}
  245. END_OF_FILE
  246. if test 3496 -ne `wc -c <'versions'`; then
  247.     echo shar: \"'versions'\" unpacked with wrong size!
  248. fi
  249. chmod +x 'versions'
  250. # end of 'versions'
  251. fi
  252. if test -f 'versions.dat' -a "${1}" != "-c" ; then 
  253.   echo shar: Will not clobber existing file \"'versions.dat'\"
  254. else
  255. echo shar: Extracting \"'versions.dat'\" \(1034 characters\)
  256. sed "s/^X//" >'versions.dat' <<'END_OF_FILE'
  257. XBIN=/usr/local/bin
  258. Xl=level
  259. Xv=version
  260. XV=Version
  261. Xp=patch.c,v
  262. X
  263. X%BIN/f2c        echo | %%            %v of (.*) ..:
  264. X%BIN/find        %% /dev/null -%v 2>&1        %v ([^ ]*)
  265. X%BIN/flex        %% -v < /dev/null 2>&1        %v ([^ ]*)
  266. X%BIN/formes        %% -h                NEW:\t([^ ]*)
  267. X%BIN/ftoch        %% -v                %V . ([^ ]*)
  268. X%BIN/g++        gcc -v 2>&1            %v ([\d\.]+)
  269. X%BIN/gcc        %% -v 2>&1            %v ([\d\.]+)
  270. X%BIN/gdb        echo quit | %%            GDB ([\d\.]+)
  271. X%BIN/X11/ghostview    strings %%            Ghostview, %v ([\d\.]+)
  272. X%BIN/grep        %% -V 2>&1            grep, %v ([^ ]*)
  273. X%BIN/kcl        echo \(bye\) | %%        %V\((.*)\)
  274. X%BIN/kermit        echo quit | %%            C-Kermit, ([^ ]*)
  275. X%BIN/lelisp        echo \(end\) | %%        %v ([^ ]*)
  276. X%BIN/make        %% -v 2>/dev/null        %v ([\d\.]+)
  277. X%BIN/matlab        %% -v 2>/dev/null        %V ([^ ]*)
  278. X%BIN/patch        %% -v 2>&1 | tr '\012' ' '    %p ([^ ]*).*%l: ([^ ]*)
  279. X%BIN/perl        %% -v | tr '\012' ' '        %v ([^ ]*).*%l: ([^ ]*)
  280. X%BIN/rcs        strings %%            rcs.c,v ([^ ]*)
  281. X%BIN/svp        %% 2>&1                %v. ([^ ]*)
  282. X%BIN/tar        %% -%v 2>&1            %v ([\d\.]+)
  283. X%BIN/tex        cd /tmp; echo \\end | %%    %V ([^ ]*)
  284. X%BIN/top        strings %%            Top, %v ([^,]*)
  285. X%BIN/versions        %% -v                ^([^ ]*)
  286. END_OF_FILE
  287. if test 1034 -ne `wc -c <'versions.dat'`; then
  288.     echo shar: \"'versions.dat'\" unpacked with wrong size!
  289. fi
  290. # end of 'versions.dat'
  291. fi
  292. if test -f 'Makefile' -a "${1}" != "-c" ; then 
  293.   echo shar: Will not clobber existing file \"'Makefile'\"
  294. else
  295. echo shar: Extracting \"'Makefile'\" \(1765 characters\)
  296. sed "s/^X//" >'Makefile' <<'END_OF_FILE'
  297. X# %G% IRCAM %W%
  298. X#                       Copyright (c) 1991 by IRCAM
  299. X#                           All rights reserved.
  300. X#
  301. X#  For any information regarding this and other IRCAM software, please
  302. X#  send email to:
  303. X#                              manager@ircam.fr
  304. X
  305. X#
  306. X# Gnumake file automatically generated by makemake for versions
  307. X#
  308. X# Modification history
  309. X#
  310. X
  311. XMAKEFILE    := Makefile
  312. XTARGET        := versions
  313. XROOTDIR        := /usr/local
  314. XOWNER        := root
  315. XGROUP        := wheel
  316. X# Where executables and man pages go
  317. XBINDIR        := $(ROOTDIR)/bin
  318. XLIBDIR        := $(ROOTDIR)/lib
  319. XMANDIR        := $(ROOTDIR)/man
  320. XDESTDIR        := $(BINDIR)
  321. XSHFILES        :=  versions.sh
  322. XTAPE        := /dev/rmt0h
  323. XLIBFILES    := versions.dat
  324. XMANFILES1    :=  versions.1
  325. XMANFILES    :=  $(MANFILES1)
  326. XINSTMANFILES    := $(addprefix $(MANDIR)/man1/, $(MANFILES1))
  327. XINSTLIBFILES    := $(addprefix $(LIBDIR)/, $(LIBFILES))
  328. XDOCFILES    := 
  329. XOTHERS        := 
  330. XOBJECTS        := 
  331. XSOURCE        := $(MAKEFILE) $(MANFILES) $(DOCFILES) $(SHFILES) \
  332. X           $(OTHERS) $(INCLUDES) $(YACCFILES) $(LEXFILES) \
  333. X           $(CFILES) $(FFILES) $(ASFILES)
  334. XLISTFILES    := $(MAKEFILE) $(SHFILES) $(INCLUDES) $(YACCFILES) \
  335. X           $(LEXFILES) $(CFILES) $(FFILES) $(ASFILES)
  336. X
  337. X.PHONY: all install uninstall clean depend
  338. Xall:     $(TARGET)
  339. X
  340. Xinstall: $(DESTDIR)/$(TARGET) $(INSTMANFILES) $(INSTLIBFILES)
  341. X
  342. Xuninstall:
  343. X    rm -f $(DESTDIR)/$(TARGET) $(INSTMANFILES) $(INSTLIBFILES)
  344. X
  345. Xdepend:
  346. X
  347. X$(TARGET):    $(TARGET).sh
  348. X
  349. X$(DESTDIR)/$(TARGET): $(TARGET)
  350. X    install -c -o $(OWNER) -g $(GROUP) -m 0755 $< $@
  351. X
  352. X$(MANDIR)/man1/% : %
  353. X    install -c -o $(OWNER) -g $(GROUP) -m 0644 $< $@
  354. X$(LIBDIR)/% : %
  355. X    install -c -o $(OWNER) -g $(GROUP) -m 0644 $< $@
  356. Xtar:
  357. X    tar rfcb $(TAPE) 20 $(SOURCE)
  358. Xcpio:
  359. X    ls $(SOURCE) | cpio -oB
  360. Xlint:
  361. X    $(LINT) $(CPPFLAGS) $(CFILES)
  362. Xclean:
  363. X    -rm -f $(OBJECTS)
  364. X    sccs clean
  365. Xclobber: clean
  366. X    -rm -f $(TARGET)
  367. Xtouch:
  368. X    touch $(TARGET)
  369. X
  370. END_OF_FILE
  371. if test 1765 -ne `wc -c <'Makefile'`; then
  372.     echo shar: \"'Makefile'\" unpacked with wrong size!
  373. fi
  374. # end of 'Makefile'
  375. fi
  376. echo shar: End of shell archive.
  377. exit 0
  378.