home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume38 / buffer / part01 next >
Text File  |  1993-07-13  |  57KB  |  1,780 lines

  1. Newsgroups: comp.sources.misc
  2. From: lmjm@doc.ic.ac.uk (Lee M J McLoughlin)
  3. Subject: v38i051:  buffer - Very Fast Tape Writer, v1.17, Part01/01
  4. Message-ID: <1993Jul13.045427.17712@sparky.sterling.com>
  5. X-Md4-Signature: e2cc7464d32de1ff34299d4672ff3de3
  6. Sender: kent@sparky.sterling.com (Kent Landfield)
  7. Organization: Sterling Software
  8. Date: Tue, 13 Jul 1993 04:54:27 GMT
  9. Approved: kent@sparky.sterling.com
  10.  
  11. Submitted-by: lmjm@doc.ic.ac.uk (Lee M J McLoughlin)
  12. Posting-number: Volume 38, Issue 51
  13. Archive-name: buffer/part01
  14. Environment: SUNOS, SYSV, SYSVR4, HPUX, Shared Memory, Semaphores
  15. Supersedes: buffer1.16: Volume 37, Issue 98
  16.  
  17. This is version 1.17 of buffer.  This is a program designed to speed up 
  18. writing tapes on remote tape drives.  Requirements are shared memory and 
  19. locks which normally means that these are supported in your kernel.
  20.  
  21. Buffer has been tested under SunOS 4.0.*, SunOS 4.1.*, Solarix, HP-UX 7.0,
  22. and Gould UTX 2.1A (sv universe).
  23.  
  24. The program splits itself into two processes.  The first process reads
  25. (and reblocks) from stdin into a shared memory buffer.  The second
  26. writes from the shared memory buffer to stdout.  Doing it this way
  27. means that the writing side effectly sits in a tight write loop and
  28. doesn't have to wait for input.  Similarly for the input side.  It is
  29. this waiting that slows down other reblocking processes, like dd.
  30.  
  31. I run an archive and need to write large chunks out to tape regularly
  32. with an ethernet in the way.  Using 'buffer' in a command like:
  33.  
  34.         tar cvf - stuff | rsh somebox "buffer > /dev/rst8"
  35.  
  36. is a factor of 5 faster than the best alternative, gnu tar with its
  37. remote tape option:
  38.  
  39.         tar cvf somebox:/dev/rst8 stuff
  40.  
  41. We have been using buffer here at Imperial for a couple of years now
  42. for writing tar tapes and the main system dumps.
  43.  
  44. Thanks to Kevin Twidle <kpt@doc.ic.ac.uk> for the -p and -B code.
  45.  
  46. INSTALLATION:
  47.         Check that your kernel supports shared memory and semaphores.
  48.         A quick way to check is to build buffer and run it.
  49.         If it says "couldn't create shared memory segment" you probably
  50.         need to reconfigure and rebuild your kernel.
  51.  
  52.         To install edit the Makefile and tailor the variables to
  53.         your local systems.  Then type make.
  54.  
  55. DISCLAIMER:
  56.         This package is under the GNU GENERAL PUBLIC LICENSE!
  57.         In addtion under NO circumstances can I, or Imperial College,
  58.         be held liable for any event caused by the running or storing 
  59.         of this program or its documentation.
  60.         
  61. Lee McLoughlin.                          Phone: +44 71 589 5111 X 5085
  62. Dept of Computing, Imperial College,     Fax: +44 71 581 8024
  63. 180 Queens Gate, London, SW7 2BZ, UK.    Email: L.McLoughlin@doc.ic.ac.uk
  64. -------------------------------------------------------------------------
  65. #! /bin/sh
  66. # This is a shell archive.  Remove anything before this line, then unpack
  67. # it by saving it into a file and typing "sh file".  To overwrite existing
  68. # files, type "sh file -c".  You can also feed this as standard input via
  69. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  70. # will see the following message at the end:
  71. #        "End of shell archive."
  72. # Contents:  README buffer.man Makefile buffer.c sem.c COPYING
  73. # Wrapped by lmjm@swan.doc.ic.ac.uk on Fri Jun  4 16:46:25 1993
  74. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  75. if test -f 'README' -a "${1}" != "-c" ; then 
  76.   echo shar: Will not clobber existing file \"'README'\"
  77. else
  78. echo shar: Extracting \"'README'\" \(1979 characters\)
  79. sed "s/^X//" >'README' <<'END_OF_FILE'
  80. XThis is a program designed to speed up writing tapes on remote tape
  81. Xdrives.  Requirements are shared memory and locks which normally
  82. Xmeans that these are supported in your kernel.
  83. X
  84. XBuffer has been tested under SunOS 4.0.*, SunOS 4.1.*, Solarix, HP-UX 7.0,
  85. Xand Gould UTX 2.1A (sv universe).
  86. X
  87. XThe program splits itself into two processes.  The first process reads
  88. X(and reblocks) from stdin into a shared memory buffer.  The second
  89. Xwrites from the shared memory buffer to stdout.  Doing it this way
  90. Xmeans that the writing side effectly sits in a tight write loop and
  91. Xdoesn't have to wait for input.  Similarly for the input side.  It is
  92. Xthis waiting that slows down other reblocking processes, like dd.
  93. X
  94. XI run an archive and need to write large chunks out to tape regularly
  95. Xwith an ethernet in the way.  Using 'buffer' in a command like:
  96. X
  97. X    tar cvf - stuff | rsh somebox "buffer > /dev/rst8"
  98. X
  99. Xis a factor of 5 faster than the best alternative, gnu tar with its
  100. Xremote tape option:
  101. X
  102. X    tar cvf somebox:/dev/rst8 stuff
  103. X
  104. XWe have been using buffer here at Imperial for a couple of years now
  105. Xfor writing tar tapes and the main system dumps.
  106. X
  107. XThanks to Kevin Twidle <kpt@doc.ic.ac.uk> for the -p and -B code.
  108. X
  109. XINSTALLATION:
  110. X    Check that your kernel supports shared memory and semaphores.
  111. X    A quick way to check is to build buffer and run it.
  112. X    If it says "couldn't create shared memory segment" you probably
  113. X    need to reconfigure and rebuild your kernel.
  114. X
  115. X    To install edit the Makefile and tailor the variables to
  116. X    your local systems.  Then type make.
  117. X
  118. XDISCLAIMER:
  119. X    This package is under the GNU GENERAL PUBLIC LICENSE!
  120. X    In addtion under NO circumstances can I, or Imperial College,
  121. X    be held liable for any event caused by the running or storing 
  122. X    of this program or its documentation.
  123. X    
  124. XLee McLoughlin.                          Phone: +44 71 589 5111 X 5085
  125. XDept of Computing, Imperial College,     Fax: +44 71 581 8024
  126. X180 Queens Gate, London, SW7 2BZ, UK.    Email: L.McLoughlin@doc.ic.ac.uk
  127. END_OF_FILE
  128. if test 1979 -ne `wc -c <'README'`; then
  129.     echo shar: \"'README'\" unpacked with wrong size!
  130. fi
  131. # end of 'README'
  132. fi
  133. if test -f 'buffer.man' -a "${1}" != "-c" ; then 
  134.   echo shar: Will not clobber existing file \"'buffer.man'\"
  135. else
  136. echo shar: Extracting \"'buffer.man'\" \(5087 characters\)
  137. sed "s/^X//" >'buffer.man' <<'END_OF_FILE'
  138. X.\"    Buffer.  Very fast reblocking filter speedy writing of tapes.
  139. X.\"    Copyright (C) 1990,1991  Lee McLoughlin
  140. X.\"
  141. X.\"    This program is free software; you can redistribute it and/or modify
  142. X.\"    it under the terms of the GNU General Public License as published by
  143. X.\"    the Free Software Foundation; either version 1, or (at your option)
  144. X.\"    any later version.
  145. X.\"
  146. X.\"    This program is distributed in the hope that it will be useful,
  147. X.\"    but WITHOUT ANY WARRANTY; without even the implied warranty of
  148. X.\"    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  149. X.\"    GNU General Public License for more details.
  150. X.\"
  151. X.\"    You should have received a copy of the GNU General Public License
  152. X.\"    along with this program; if not, write to the Free Software
  153. X.\"    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  154. X.\"
  155. X.\"    Lee McLoughlin.
  156. X.\"    Dept of Computing, Imperial College,
  157. X.\"    180 Queens Gate, London, SW7 2BZ, UK.
  158. X.\"
  159. X.\"    Email: L.McLoughlin@doc.ic.ac.uk
  160. X.TH BUFFER 1 "14 May 1990"
  161. X.SH NAME
  162. Xbuffer \- very fast reblocking program
  163. X.SH SYNTAX
  164. X.B buffer
  165. X[\fB\-S size\fP] [\fB\-b blocks\fP] [\fB\-s size\fP] [\fB\-m size\fP]
  166. X[\fB\-p percentage\fP] [\fB\-u microseconds\fP] [\fB-B\fR] [\fB-t\fR]
  167. X[\fB-Z\fR] [\fB-i filename\fR] [\fB-o filename\fR] 
  168. X.SH OPTIONS
  169. X.TP 5
  170. X.B \-i filename
  171. XUse the given file as the input file.  The default is stdin.
  172. X.TP
  173. X.B \-o filename
  174. XUse the given file as the output file.  The default is stdout.
  175. X.TP
  176. X.B \-S size
  177. XAfter every chunk this size has been writen print out how much been writen so far.
  178. XBy default this is not set.
  179. X.TP
  180. X.B \-s size
  181. XSize in bytes of each block.  The default blocksize is 10k to match
  182. Xthe normal output of the
  183. X.I tar(1)
  184. Xprogram.
  185. X.TP
  186. X.B \-z size
  187. XCombines the
  188. X.B \-S
  189. Xand
  190. X.B \-s
  191. Xflags.
  192. X.TP
  193. X.B \-b blocks
  194. XNumber of blocks to allocate to shared memory circular buffer.
  195. XDefaults to the number required to fill up the shared memory requested.
  196. X.TP
  197. X.B \-m size
  198. XMaximum size of the shared memory chunk to allocate for the circular
  199. Xqueue. Defaults to one megabyte.
  200. X.TP
  201. X.B \-p percentage
  202. XOnly start a write when the given percentage of the internal queue is
  203. Xfull.  A percentage around 75 often proves best. Defaults to zero.
  204. X.TP
  205. X.B \-u microseconds
  206. XAfter every write pause for this many microseconds.  Defaults to zero.
  207. X(Suprisingly a small sleep, 100 usecs, after each write can greatly enhance
  208. Xthroughput on some drives.)
  209. X.TP
  210. X.B \-B
  211. XForce each block writen to be padded out to the blocksize.  This is needed by some tape
  212. Xand cartridge drives.  Defaults to unpadded.  This only affects the
  213. Xlast block writen.
  214. X.TP
  215. X.B \-t
  216. XOn exiting print to stderr a brief message showing the total number of
  217. Xbytes written.
  218. X.TP
  219. X.B \-Z
  220. XIf reading/writing directly to a character device (like a tape drive)
  221. Xthen after each gigabyte perform an lseek to the start of the file.
  222. XUse this flag with extreme care.  If can only be used on devices where
  223. Xan lseek does not rewind the tape but does reset the kernels position
  224. Xflags.  It is used to allow more than 2 gigabytes to be written.
  225. X.PP
  226. XSizes are a number with an optional trailing character.   A 'b' 
  227. Xmultiplies the size by 512, a 'k' by 1024 and an 'm' by a meg.
  228. X.SH DESCRIPTION
  229. X.I Buffer
  230. Xreads from standard input reblocking to the given blocksize and writes
  231. Xeach block to standard output.
  232. X.PP
  233. XInternally
  234. X.I buffer
  235. Xis a pair of processes communicating via a large circular queue held
  236. Xin shared memory.  The reader process only has to block when the queue
  237. Xis full and the writer process when the queue is empty.
  238. X.I Buffer
  239. Xis designed to try and keep the writer side continuously busy so that
  240. Xit can stream when writing to tape drives.  When used to write tapes
  241. Xwith an intervening network
  242. X.I buffer
  243. Xcan result in a considerable increase in throughput.
  244. X.PP
  245. XThe default settings for
  246. X.I buffer
  247. Xare normally good enough.  If you are a heavy tape user then it is
  248. Xworth your while trying out various different combinations of options.
  249. XIn particular running a
  250. X.I buffer
  251. Xat both ends of the pipe can provide a substantial increase (see last
  252. Xexample below).
  253. X.SH EXAMPLES
  254. X.br
  255. X$ \fBbuffer < /etc/termcap > /dev/rst8\fP
  256. X.br
  257. X.sp
  258. X$ \fBtar cf - . | rsh somehost 'buffer > /dev/rst8'\fP
  259. X.br
  260. X.sp
  261. X$ \fBdump fu - | rsh somehost 'buffer -s 16k > /dev/nrst8'\fP
  262. X.br
  263. X$ \fBtar cf - . | buffer | 
  264. X.br
  265. X\ \ \ rsh somehost 'buffer -S 500K -p 75 > /dev/rst0'\fP
  266. X.SH BUGS
  267. XInternally, for printing purposes, buffer counts in terms of the
  268. Xnumber of kilobytes output.  If the blocksize you use is not a whole
  269. Xnumber of kilobytes then the numbers printed will be inaccurate.
  270. X
  271. X.SH THANKS
  272. XThanks to Kevin Twidle <kpt@doc.ic.ac.uk> for a lot of early
  273. Xsuggestions and patches to make it work with non-tar/dump tapes to
  274. Xexabyte drives.
  275. X
  276. XThanks to Andi Karrer <karrer@bernina.ethz.ch>, Rumi Zahir
  277. X<rumi@iis.ethz.ch> and Christoph Wicki <wicki@iis.ethz.ch> for patches
  278. Xto make buffer work when trying to write single tape files of greater
  279. Xthan 2 gigabytes.
  280. X
  281. X.SH COPYRIGHT
  282. X.if n Copyright (C) 1990, 1991 by Lee McLoughlin.
  283. X.if t Copyright \(co 1990, 1991 by Lee McLoughlin.
  284. X.SH SEE ALSO
  285. Xdd(1), tar(1), rsh(1)
  286. END_OF_FILE
  287. if test 5087 -ne `wc -c <'buffer.man'`; then
  288.     echo shar: \"'buffer.man'\" unpacked with wrong size!
  289. fi
  290. # end of 'buffer.man'
  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'\" \(935 characters\)
  296. sed "s/^X//" >'Makefile' <<'END_OF_FILE'
  297. X# Make the buffer program
  298. X
  299. X# Add -DSYS5 for A System 5 (USG) version of unix
  300. X#   You should also add -DSYS5 for Ultrix, AIX, and Solarix.
  301. X# Add -DDEF_SHMEM=n if you can only have n bytes of shared memory
  302. X#   (eg: -DDEF_SHMEM=524288 if you can only have half a meg.)
  303. XCFLAGS=
  304. X
  305. X# Where to install buffer and its manual pages
  306. XINSTBIN=/usr/local/bin
  307. XINSTMAN=/usr/man/manl
  308. X# The manual page section (normally l or 1)
  309. XS=l
  310. X
  311. XRM=/bin/rm
  312. XALL=README buffer.man Makefile buffer.c sem.c COPYING
  313. X
  314. Xall: buffer
  315. X
  316. Xbuffer: buffer.o sem.o
  317. X    $(CC) -o buffer $(CFLAGS) buffer.o sem.o
  318. X
  319. Xclean:
  320. X    $(RM) -f *.o core buffer .merrs
  321. X
  322. Xinstall: buffer
  323. X    rm -f $(INSTBIN)/buffer
  324. X    cp buffer $(INSTBIN)/buffer
  325. X    chmod 111 $(INSTBIN)/buffer
  326. X    rm -f $(INSTMAN)/buffer.$S
  327. X    cp buffer.man $(INSTMAN)/buffer.$S
  328. X    chmod 444 $(INSTMAN)/buffer.$S
  329. X
  330. Xbuffer.tar: $(ALL)
  331. X    $(RM) -f buffer.tar
  332. X    tar cvf buffer.tar $(ALL)
  333. X
  334. Xbuffer.shar: $(ALL)
  335. X    $(RM) -f buffer.shar
  336. X    shar $(ALL) > buffer.shar
  337. END_OF_FILE
  338. if test 935 -ne `wc -c <'Makefile'`; then
  339.     echo shar: \"'Makefile'\" unpacked with wrong size!
  340. fi
  341. # end of 'Makefile'
  342. fi
  343. if test -f 'buffer.c' -a "${1}" != "-c" ; then 
  344.   echo shar: Will not clobber existing file \"'buffer.c'\"
  345. else
  346. echo shar: Extracting \"'buffer.c'\" \(20661 characters\)
  347. sed "s/^X//" >'buffer.c' <<'END_OF_FILE'
  348. X/*
  349. X    Buffer.  Very fast reblocking filter speedy writing of tapes.
  350. X    Copyright (C) 1990,1991  Lee McLoughlin
  351. X
  352. X    This program is free software; you can redistribute it and/or modify
  353. X    it under the terms of the GNU General Public License as published by
  354. X    the Free Software Foundation; either version 1, or (at your option)
  355. X    any later version.
  356. X
  357. X    This program is distributed in the hope that it will be useful,
  358. X    but WITHOUT ANY WARRANTY; without even the implied warranty of
  359. X    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  360. X    GNU General Public License for more details.
  361. X
  362. X    You should have received a copy of the GNU General Public License
  363. X    along with this program; if not, write to the Free Software
  364. X    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  365. X
  366. X    Lee McLoughlin.
  367. X    Dept of Computing, Imperial College,
  368. X    180 Queens Gate, London, SW7 2BZ, UK.
  369. X
  370. X    Email: L.McLoughlin@doc.ic.ac.uk
  371. X*/
  372. X
  373. X/* This is a reblocking process, designed to try and read from stdin
  374. X * and write to stdout - but to always try and keep the writing side
  375. X * busy.  It is meant to try and stream tape writes.
  376. X *
  377. X * This program runs in two parts.  The reader and the writer.  They
  378. X * communicate using shared memory with semaphores locking the access.
  379. X * The shared memory implements a circular list of blocks of data.
  380. X *
  381. X * L.McLoughlin, Imperial College, 1990
  382. X *
  383. X * $Log: buffer.c,v $
  384. X * Revision 1.17  1993/06/04  10:26:39  lmjm
  385. X * Cleaned up error reporting.
  386. X * Spot when the child terminating is not mine but inherited from via exec.
  387. X * Use only one semaphore group.
  388. X * Print out why writer died on error.
  389. X *
  390. X * Revision 1.16  1993/05/28  10:47:32  lmjm
  391. X * Debug shutdown sequence.
  392. X *
  393. X * Revision 1.15  1992/11/23  23:32:58  lmjm
  394. X * Oops!  This should be outside the ifdef
  395. X *
  396. X * Revision 1.14  1992/11/23  23:29:58  lmjm
  397. X * allow MAX_BLOCKSIZE and DEF_SHMEM to be configured
  398. X *
  399. X * Revision 1.13  1992/11/23  23:22:29  lmjm
  400. X * Printf's use %lu where appropriate.
  401. X *
  402. X * Revision 1.12  1992/11/23  23:17:55  lmjm
  403. X * Got rid of floats and use Kbyte counters instead.
  404. X *
  405. X * Revision 1.11  1992/11/03  23:11:51  lmjm
  406. X * Forgot Andi Karrer on the patch list.
  407. X *
  408. X * Revision 1.10  1992/11/03  22:58:41  lmjm
  409. X * Cleaned up the debugging prints.
  410. X *
  411. X * Revision 1.9  1992/11/03  22:53:00  lmjm
  412. X * Corrected stdin, stout and showevery use.
  413. X *
  414. X * Revision 1.8  1992/11/03  22:41:34  lmjm
  415. X * Added 2Gig patches from:
  416. X * Andi Karrer <karrer@bernina.ethz.ch>
  417. X * Rumi Zahir <rumi@iis.ethz.ch>
  418. X * Christoph Wicki <wicki@iis.ethz.ch>
  419. X *
  420. X * Revision 1.7  1992/07/23  20:42:03  lmjm
  421. X * Added 't' option to print total writen at end.
  422. X *
  423. X * Revision 1.6  1992/04/07  19:57:30  lmjm
  424. X * Added Kevins -B and -p options.
  425. X * Turn off buffering to make -S output appear ok.
  426. X * Added GPL.
  427. X *
  428. X * Revision 1.5  90/07/22  18:46:38  lmjm
  429. X * Added system 5 support.
  430. X * 
  431. X * Revision 1.4  90/07/22  18:29:48  lmjm
  432. X * Updated arg handling to be more consistent.
  433. X * Make sofar printing size an option.
  434. X * 
  435. X * Revision 1.3  90/05/15  23:27:46  lmjm
  436. X * Added -S option (show how much has been writen).
  437. X * Added -m option to specify how much shared memory to grab.
  438. X * Now tries to fill this with blocks.
  439. X * reader waits for writer to terminate and then frees the shared mem and sems.
  440. X * 
  441. X * Revision 1.2  90/01/20  21:37:59  lmjm
  442. X * Reset default number of  blocks and blocksize for best thruput of
  443. X * standard tar 10K blocks.
  444. X * Allow number of blocks to be changed.
  445. X * Don't need a hole in the circular queue since the semaphores prevent block
  446. X * clash.
  447. X * 
  448. X * Revision 1.1  90/01/17  11:30:23  lmjm
  449. X * Initial revision
  450. X * 
  451. X */
  452. X#include <unistd.h>
  453. X#include <stdio.h>
  454. X#include <signal.h>
  455. X#include <fcntl.h>
  456. X#include <sys/types.h>
  457. X#include <sys/stat.h>
  458. X#include <sys/ipc.h>
  459. X#include <sys/shm.h>
  460. X#include <sys/sem.h>
  461. X#include <sys/wait.h>
  462. X
  463. X#ifndef lint
  464. Xstatic char *rcsid = "$Header: /a/swan/home/swan/staff/csg/lmjm/src/buffer/RCS/buffer.c,v 1.17 1993/06/04 10:26:39 lmjm Exp lmjm $";
  465. X#endif
  466. X
  467. Xextern char *shmat();
  468. X
  469. X/* General macros */
  470. X#define TRUE 1
  471. X#define FALSE 0
  472. X#define K *1024
  473. X
  474. X/* Some forward declarations */
  475. Xvoid byee();
  476. Xvoid start_reader_and_writer();
  477. X
  478. X/* When showing print a note every this many bytes writen */
  479. Xint showevery = 0;
  480. X#define PRINT_EVERY 10 K
  481. X
  482. X/* Pause after every write */
  483. Xunsigned write_pause;
  484. X
  485. X/* This is the inter-process buffer - it implements a circular list
  486. X * of blocks. */
  487. X
  488. X#ifndef MAX_BLOCKSIZE
  489. X#define MAX_BLOCKSIZE (512 K)
  490. X#endif
  491. X#define DEF_BLOCKSIZE (10 K)
  492. Xint blocksize = DEF_BLOCKSIZE;
  493. X
  494. X/* Which process... in error reports*/
  495. Xchar *proc_string = "buffer";
  496. X
  497. X/* Numbers of blocks in the queue. 
  498. X */
  499. X#define MAX_BLOCKS 2048
  500. Xint blocks = 1;
  501. X/* Circular increment of a buffer index */
  502. X#define INC(i) (((i)+1) == blocks ? 0 : ((i)+1))
  503. X
  504. X/* Max amount of shared memory you can allocate - can't see a way to look
  505. X * this up.
  506. X */
  507. X#ifndef DEF_SHMEM
  508. X#define DEF_SHMEM (1 K K)
  509. X#endif
  510. Xint max_shmem = DEF_SHMEM;
  511. X
  512. X/* Just a flag to show unfilled */
  513. X#define NONE (-1)
  514. X
  515. X/* the shared memory id of the buffer */
  516. Xint buffer_id = NONE;
  517. Xstruct block {
  518. X    int bytes;
  519. X    char *data;
  520. X} *curr_block;
  521. X
  522. X#define NO_BUFFER ((struct buffer *)-1)
  523. Xstruct buffer {
  524. X    /* Id of the semaphore group */
  525. X    int semid;
  526. X
  527. X    /* writer will hang trying to lock this till reader fills in a block */
  528. X    int blocks_used_lock;
  529. X    /* reader will hang trying to lock this till writer empties a block */
  530. X    int blocks_free_lock;
  531. X
  532. X    int next_block_in;
  533. X    int next_block_out;
  534. X
  535. X    struct block block[ MAX_BLOCKS ];
  536. X
  537. X    /* These actual space for the blocks is here - the array extends
  538. X     * pass 1 */
  539. X    char data_space[ 1 ];
  540. X} *pbuffer = NO_BUFFER;
  541. Xint buffer_size;
  542. X
  543. Xint fdin    = 0;
  544. Xint fdout    = 1;
  545. Xint in_ISCHR    = 0;
  546. Xint out_ISCHR    = 0;
  547. Xint padblock    = FALSE;
  548. Xint writer_pid    = 0;
  549. Xint reader_pid    = 0;
  550. Xint free_shm    = 1;
  551. Xint percent    = 0;
  552. Xint debug    = 0;
  553. Xint Zflag    = 0;
  554. Xint writer_status = 0;
  555. Xchar *progname = "buffer";
  556. X
  557. Xchar print_total = 0;
  558. X/* Number of K output */
  559. Xunsigned long outk = 0;
  560. X
  561. Xmain( argc, argv )
  562. X    int argc;
  563. X    char **argv;
  564. X{
  565. X    parse_args( argc, argv );
  566. X
  567. X    set_handlers();
  568. X
  569. X    buffer_allocate();
  570. X
  571. X    start_reader_and_writer();
  572. X
  573. X    byee( 0 );
  574. X}
  575. X
  576. Xparse_args( argc, argv )
  577. X    int argc;
  578. X    char **argv;
  579. X{
  580. X    int c;
  581. X    int iflag = 0;
  582. X    int oflag = 0;
  583. X    int zflag = 0;
  584. X    extern char *optarg;
  585. X    extern int optind;
  586. X    char blocks_given = FALSE;
  587. X    struct stat buf;
  588. X
  589. X
  590. X    while( (c = getopt( argc, argv, "BS:Zdm:s:b:p:u:ti:o:z:" )) != -1 ){
  591. X        switch( c ){
  592. X        case 't': /* Print to stderr the total no of bytes writen */
  593. X            print_total++;
  594. X            break;
  595. X        case 'u': /* pause after write for given microseconds */
  596. X            write_pause = atoi( optarg );
  597. X            break;
  598. X        case 'B':   /* Pad last block */
  599. X            padblock = TRUE;
  600. X            break;
  601. X        case 'Z':   /* Zero by lseek on the tape device */
  602. X            Zflag = TRUE;
  603. X            break;
  604. X        case 'i': /* Input file */
  605. X            iflag++;
  606. X            if( iflag > 1 ){
  607. X                report_proc();
  608. X                fprintf( stderr, "-i given twice\n" );
  609. X                byee( -1 );
  610. X            }
  611. X            if( (fdin = open( optarg, O_RDONLY )) < 0 ){
  612. X                report_proc();
  613. X                perror( "cannot open input file" );
  614. X                fprintf( stderr, "filename: %s\n", optarg );
  615. X                byee ( -1 );
  616. X            }
  617. X            break;
  618. X        case 'o': /* Output file */
  619. X            oflag++;
  620. X            if( oflag > 1 ){
  621. X                report_proc();
  622. X                fprintf( stderr, "-o given twice\n" );
  623. X                byee( -1 );
  624. X            }
  625. X            if( (fdout = open( optarg, O_WRONLY | O_CREAT | O_TRUNC, 0666 )) < 0 ){
  626. X                report_proc();
  627. X                perror( "cannot open output file" );
  628. X                fprintf( stderr, "filename: %s\n", optarg );
  629. X                byee ( -1 );
  630. X            }
  631. X            break;
  632. X        case 'S':
  633. X            /* Show every once in a while how much is printed */
  634. X            showevery = do_size( optarg );
  635. X            if( showevery <= 0 )
  636. X                showevery = PRINT_EVERY;
  637. X            break;
  638. X        case 'd':    /* debug */
  639. X            debug++;
  640. X            if( debug == 1 ){
  641. X                setbuf( stdout, NULL );
  642. X                setbuf( stderr, NULL );
  643. X                fprintf( stderr, "debugging turned on\n" );
  644. X            }
  645. X            break;
  646. X        case 'm':
  647. X            /* Max size of shared memory lump */
  648. X            max_shmem = do_size( optarg );
  649. X
  650. X            if( max_shmem < (sizeof( struct buffer ) + (blocksize * blocks)) ){
  651. X                fprintf( stderr, "max_shmem %d too low\n", max_shmem );
  652. X                byee( -1 );
  653. X            }
  654. X            break;
  655. X        case 'b':
  656. X            /* Number of blocks */
  657. X            blocks_given = TRUE;
  658. X            blocks = atoi( optarg );
  659. X            if( (blocks <= 0) || (MAX_BLOCKS < blocks) ){
  660. X                fprintf( stderr, "blocks %d out of range\n", blocks );
  661. X                byee( -1 );
  662. X            }
  663. X            break;
  664. X        case 'p':    /* percent to wait before dumping */
  665. X            percent = atoi( optarg );
  666. X
  667. X            if( (percent < 0) || (100 < percent) ){
  668. X                fprintf( stderr, "percent %d out of range\n", percent );
  669. X                byee( -1 );
  670. X            }
  671. X            if( debug )
  672. X                fprintf( stderr, "percent set to %d\n", percent );
  673. X            break;
  674. X        case 'z':
  675. X            zflag++;
  676. X            /* FALL THRU */
  677. X        case 's':    /* Size of a block */
  678. X            blocksize = do_size( optarg );
  679. X
  680. X            if( (blocksize <= 0) || (MAX_BLOCKSIZE < blocksize) ){
  681. X                fprintf( stderr, "blocksize %d out of range\n", blocksize );
  682. X                byee( -1 );
  683. X            }
  684. X            break;
  685. X        default:
  686. X            fprintf( stderr, "Usage: %s [-B] [-t] [-S size] [-m memsize] [-b blocks] [-p percent] [-s blocksize] [-u pause] [-i infile] [-o outfile] [-z size]\n",
  687. X                progname );
  688. X            fprintf( stderr, "-B = blocked device - pad out last block\n" );
  689. X            fprintf( stderr, "-t = show total amount writen at end\n" );
  690. X            fprintf( stderr, "-S size = show amount writen every size bytes\n" );
  691. X            fprintf( stderr, "-m size = size of shared mem chunk to grab\n" );
  692. X            fprintf( stderr, "-b num = number of blocks in queue\n" );
  693. X            fprintf( stderr, "-p percent = don't start writing until percent blocks filled\n" );
  694. X            fprintf( stderr, "-s size = size of a block\n" );
  695. X            fprintf( stderr, "-u usecs = microseconds to sleep after each write\n" );
  696. X            fprintf( stderr, "-i infile = file to read from\n" );
  697. X            fprintf( stderr, "-o outfile = file to write to\n" );
  698. X            fprintf( stderr, "-z size = combined -S/-s flag\n" );
  699. X            byee( -1 );
  700. X        }
  701. X    }
  702. X
  703. X    if (zflag) showevery = blocksize;
  704. X
  705. X    /* If -b was not given try and work out the max buffer size */
  706. X    if( !blocks_given ){
  707. X        blocks = (max_shmem - sizeof( struct buffer )) / blocksize;
  708. X        if( blocks <= 0 ){
  709. X            fprintf( stderr, "Cannot handle blocks that big, aborting!\n" );
  710. X            byee( -1 );
  711. X        }
  712. X        if( MAX_BLOCKS < blocks  ){
  713. X            fprintf( stderr, "Cannot handle that many blocks, aborting!\n" );
  714. X            byee( -1 );
  715. X        }
  716. X    }
  717. X
  718. X    /* check if fdin or fdout are character special files */
  719. X    if( fstat( fdin, &buf ) != 0 ){
  720. X        report_proc();
  721. X        perror( "can't stat input file" );
  722. X        byee( -1 );
  723. X    }
  724. X    in_ISCHR = S_ISCHR( buf.st_mode );
  725. X    if( fstat( fdout, &buf ) != 0 ){
  726. X        report_proc();
  727. X        perror( "can't stat output file" );
  728. X        byee( -1 );
  729. X    }
  730. X    out_ISCHR = S_ISCHR( buf.st_mode );
  731. X}
  732. X
  733. X/* The interrupt handler */
  734. Xshutdown()
  735. X{
  736. X    static int shutting;
  737. X    if( shutting ){
  738. X        if( debug )
  739. X            fprintf( stderr, "%s: ALREADY SHUTTING!\n", proc_string );
  740. X        return;
  741. X    }
  742. X    shutting = 1;
  743. X    if( debug )
  744. X        fprintf( stderr, "%s: shutdown on signal\n", proc_string );
  745. X
  746. X    byee( -1 );
  747. X}
  748. X
  749. X/* Shutdown because the child has ended */
  750. Xchild_shutdown()
  751. X{
  752. X    /* Find out which child has died.  (They may not be my
  753. X     * children if buffer was exec'd on top of something that had
  754. X     * childred.)
  755. X     */
  756. X    int deadpid;
  757. X
  758. X    while( (deadpid = waitpid( -1, &writer_status, WNOHANG )) &&
  759. X        deadpid != -1 && deadpid != 0 ){
  760. X        if( debug > 2 )
  761. X            fprintf( stderr, "child_shutdown %d: 0x%04x\n", deadpid, writer_status );
  762. X        if( deadpid == writer_pid ){
  763. X            if( debug > 2 )
  764. X                fprintf( stderr, "writer has ended\n" );
  765. X            writer_pid = 0;
  766. X            byee( 0 );
  767. X        }
  768. X    }
  769. X}
  770. X
  771. Xset_handlers()
  772. X{
  773. X    if( debug )
  774. X        fprintf( stderr, "%s: setting handlers\n", proc_string );
  775. X
  776. X    signal( SIGHUP, shutdown );
  777. X    signal( SIGINT, shutdown );
  778. X    signal( SIGQUIT, shutdown );
  779. X    signal( SIGTERM, shutdown );
  780. X#ifdef SIGCHLD
  781. X    signal( SIGCHLD, child_shutdown );
  782. X#else
  783. X#ifdef SIGCLD
  784. X    signal( SIGCLD, child_shutdown );
  785. X#endif
  786. X#endif
  787. X}
  788. X
  789. Xbuffer_allocate()
  790. X{
  791. X    int i;
  792. X
  793. X    /* Allow for the data space */
  794. X    buffer_size = sizeof( struct buffer ) +
  795. X        ((blocks * blocksize) - sizeof( char ));
  796. X
  797. X    /* Create the space for the buffer */
  798. X    buffer_id = shmget( IPC_PRIVATE,
  799. X               buffer_size,
  800. X               IPC_CREAT|S_IREAD|S_IWRITE );
  801. X    if( buffer_id < 0 ){
  802. X        report_proc();
  803. X        perror( "couldn't create shared memory segment" );
  804. X        byee( -1 );
  805. X    }
  806. X
  807. X    get_buffer();
  808. X
  809. X    if( debug )
  810. X        fprintf( stderr, "%s pbuffer is 0x%08x, buffer_size is %d [%d x %d]\n",
  811. X            proc_string,
  812. X            (char *)pbuffer, buffer_size, blocks, blocksize );
  813. X
  814. X#ifdef SYS5
  815. X    memset( (char *)pbuffer, '\0', buffer_size );
  816. X#else
  817. X    bzero( (char *)pbuffer, buffer_size );
  818. X#endif
  819. X    pbuffer->semid = -1;
  820. X    pbuffer->blocks_used_lock = -1;
  821. X    pbuffer->blocks_free_lock = -1;
  822. X
  823. X    pbuffer->semid = new_sems( 2 );    /* Get a read and a write sem */
  824. X    pbuffer->blocks_used_lock = 0;
  825. X    /* Start it off locked - it is unlocked when a buffer gets filled in */
  826. X    lock( pbuffer->semid, pbuffer->blocks_used_lock );
  827. X
  828. X    pbuffer->blocks_free_lock = 1;
  829. X    /* start this off so lock() can be called on it for each block
  830. X     * till all the blocks are used up */
  831. X    sem_set( pbuffer->semid, pbuffer->blocks_free_lock, blocks - 1 );
  832. X
  833. X    /* Detattach the shared memory so the fork doesnt do anything odd */
  834. X    shmdt( (char *)pbuffer );
  835. X    pbuffer = NO_BUFFER;
  836. X}
  837. X
  838. Xbuffer_remove()
  839. X{
  840. X    static char removing = FALSE;
  841. X    int i;
  842. X
  843. X    /* Avoid accidental recursion */
  844. X    if( removing )
  845. X        return;
  846. X    removing = TRUE;
  847. X
  848. X    /* Buffer not yet created */
  849. X    if( buffer_id == NONE )
  850. X        return;
  851. X
  852. X    /* There should be a buffer so this must be after its detached it
  853. X     * but before the fork picks it up */
  854. X    if( pbuffer == NO_BUFFER )
  855. X        get_buffer();
  856. X
  857. X    if( debug )
  858. X        fprintf( stderr, "%s: removing semaphores and buffer\n", proc_string );
  859. X    remove_sems( pbuffer->semid );
  860. X    
  861. X    if( shmctl( buffer_id, IPC_RMID, (struct shmid_ds *)0 ) == -1 ){
  862. X        report_proc();
  863. X        perror( "failed to remove shared memory buffer" );
  864. X    }
  865. X}
  866. X
  867. Xget_buffer()
  868. X{
  869. X    int b;
  870. X
  871. X    /* Grab the buffer space */
  872. X    pbuffer = (struct buffer *)shmat( buffer_id, (char *)0, 0 );
  873. X    if( pbuffer == NO_BUFFER ){
  874. X        report_proc();
  875. X        perror( "failed to attach shared memory" );
  876. X        byee( -1 );
  877. X    }
  878. X
  879. X    /* Setup the data space pointers */
  880. X    for( b = 0; b < blocks; b++ )
  881. X        pbuffer->block[ b ].data =
  882. X            &pbuffer->data_space[ b * blocksize ];
  883. X
  884. X}
  885. X
  886. Xvoid
  887. Xstart_reader_and_writer()
  888. X{
  889. X    fflush( stdout );
  890. X    fflush( stderr );
  891. X
  892. X    if( (writer_pid = fork()) == -1 ){
  893. X        report_proc();
  894. X        perror( "unable to fork" );
  895. X        byee( -1 );
  896. X    }
  897. X    else if( writer_pid == 0 ){
  898. X        free_shm = 0;
  899. X        proc_string = "buffer (writer)";
  900. X        reader_pid = getppid();
  901. X
  902. X        /* Never trust fork() to propogate signals - reset them */
  903. X        set_handlers();
  904. X
  905. X        writer();
  906. X    }
  907. X    else {
  908. X        proc_string = "buffer (reader)";
  909. X        reader();
  910. X
  911. X        wait_for_writer_end();
  912. X    }
  913. X}
  914. X
  915. X/* Read from stdin into the buffer */
  916. Xreader()
  917. X{
  918. X    if( debug )
  919. X        fprintf( stderr, "R: Entering reader\n" );
  920. X
  921. X    get_buffer();
  922. X
  923. X    while( 1 ){
  924. X        get_next_free_block();
  925. X        if( ! fill_block() )
  926. X            break;
  927. X    }
  928. X
  929. X    if( debug )
  930. X        fprintf( stderr, "R: Exiting reader\n" );
  931. X}
  932. X
  933. Xget_next_free_block()
  934. X{
  935. X    test_writer();
  936. X
  937. X    /* Maybe wait till there is room in the buffer */
  938. X    lock( pbuffer->semid, pbuffer->blocks_free_lock );
  939. X
  940. X    curr_block = &pbuffer->block[ pbuffer->next_block_in ];
  941. X
  942. X    pbuffer->next_block_in = INC( pbuffer->next_block_in );
  943. X}
  944. X
  945. Xfill_block()
  946. X{
  947. X    int bytes;
  948. X    char *start;
  949. X    int toread;
  950. X    static char eof_reached = 0;
  951. X    
  952. X    if( eof_reached ){
  953. X        curr_block->bytes = 0;
  954. X        unlock( pbuffer->semid, pbuffer->blocks_used_lock );
  955. X        return 0;
  956. X    }
  957. X
  958. X    start = curr_block->data;
  959. X    toread = blocksize;
  960. X
  961. X    /* Fill the block with input.  This reblocks the input. */
  962. X    while( toread != 0 && (bytes = read( fdin, start, toread )) > 0 ){
  963. X        start += bytes;
  964. X        toread -= bytes;
  965. X    }
  966. X
  967. X    if( bytes == 0 ){
  968. X        eof_reached = 1;
  969. X    }
  970. X
  971. X    if( bytes < 0 ){
  972. X        report_proc();
  973. X        perror( "failed to read input" );
  974. X        byee( -1 );
  975. X    }
  976. X
  977. X    /* number of bytes available. Zero will be taken as eof */
  978. X    if( !padblock || toread == blocksize )
  979. X        curr_block->bytes = blocksize - toread;
  980. X    else {
  981. X        if( toread ) bzero( start, toread );
  982. X        curr_block->bytes = blocksize;
  983. X    }
  984. X
  985. X    if( debug > 1 )
  986. X        fprintf( stderr, "R: got %d bytes\n", curr_block->bytes );
  987. X
  988. X    unlock( pbuffer->semid, pbuffer->blocks_used_lock );
  989. X
  990. X    return curr_block->bytes;
  991. X}
  992. X
  993. X/* Write the buffer to stdout */
  994. Xwriter()
  995. X{
  996. X    int filled = 0;
  997. X    int maxfilled = (blocks * percent) / 100;
  998. X    int first_block;
  999. X
  1000. X    if( debug )
  1001. X        fprintf( stderr, "\tW: Entering writer\n blocks = %d\n maxfilled = %d\n",
  1002. X            blocks,
  1003. X            maxfilled );
  1004. X
  1005. X    get_buffer();
  1006. X
  1007. X    while( 1 ){
  1008. X        if( !filled )
  1009. X            first_block = pbuffer->next_block_out;
  1010. X        get_next_filled_block();
  1011. X        if( !data_to_write() )
  1012. X            break;
  1013. X
  1014. X        filled++;
  1015. X        if( debug > 1 )
  1016. X            fprintf( stderr, "W: filled = %d\n", filled );
  1017. X        if( filled >= maxfilled ){
  1018. X            if( debug > 1 )
  1019. X                fprintf( stderr, "W: writing\n" );
  1020. X            write_blocks_to_stdout( filled, first_block );
  1021. X            filled = 0;
  1022. X        }
  1023. X    }
  1024. X
  1025. X    write_blocks_to_stdout( filled, first_block );
  1026. X
  1027. X    if( showevery ){
  1028. X        pr_out();
  1029. X        fprintf( stderr, "\n" );
  1030. X    }
  1031. X
  1032. X    if( print_total ){
  1033. X        fprintf( stderr, "Kilobytes Out %lu\n", outk );
  1034. X    }
  1035. X
  1036. X    if( debug )
  1037. X        fprintf( stderr, "\tW: Exiting writer\n" );
  1038. X}
  1039. X
  1040. Xget_next_filled_block()
  1041. X{
  1042. X    /* Hang till some data is available */
  1043. X    lock( pbuffer->semid, pbuffer->blocks_used_lock );
  1044. X
  1045. X    curr_block = &pbuffer->block[ pbuffer->next_block_out ];
  1046. X
  1047. X    pbuffer->next_block_out = INC( pbuffer->next_block_out );
  1048. X}
  1049. X
  1050. Xdata_to_write()
  1051. X{
  1052. X    return curr_block->bytes;
  1053. X}
  1054. X
  1055. Xwrite_blocks_to_stdout( filled, first_block )
  1056. X    int filled;
  1057. X    int first_block;
  1058. X{
  1059. X    pbuffer->next_block_out = first_block;
  1060. X
  1061. X    while( filled-- ){
  1062. X        curr_block = &pbuffer->block[ pbuffer->next_block_out ];
  1063. X        pbuffer->next_block_out = INC( pbuffer->next_block_out );
  1064. X        write_block_to_stdout();
  1065. X    }
  1066. X}
  1067. X
  1068. Xwrite_block_to_stdout()
  1069. X{
  1070. X    static unsigned long out = 0;
  1071. X    static unsigned long last_gb = 0;
  1072. X    static unsigned long next_k = 0;
  1073. X    int written;
  1074. X
  1075. X    if( next_k == 0 && showevery ){
  1076. X        if( debug > 3 )
  1077. X            fprintf( stderr, "W: next_k = %lu showevery = %lu\n", next_k, showevery );
  1078. X        showevery = showevery / 1024;
  1079. X        next_k = showevery;
  1080. X    }
  1081. X
  1082. X    if( (written = write( fdout, curr_block->data, curr_block->bytes )) != curr_block->bytes ){
  1083. X        report_proc();
  1084. X        perror( "write of data failed" );
  1085. X        fprintf( stderr, "bytes to write=%d, bytes written=%d, total written %10luK\n", curr_block->bytes, written, outk );
  1086. X        byee( -1 );
  1087. X    }
  1088. X
  1089. X    if( write_pause ){
  1090. X        usleep( write_pause );
  1091. X    }
  1092. X
  1093. X    out = curr_block->bytes / 1024;
  1094. X    outk += out;
  1095. X    last_gb += out;
  1096. X
  1097. X    /*
  1098. X     * on character special devices (tapes), do an lseek() every 1 Gb,
  1099. X     * to overcome the 2Gb limit. This resets the file offset to
  1100. X     * zero, but -- at least on exabyte SCSI drives -- does not perform
  1101. X     * any actual action on the tape.
  1102. X     */
  1103. X    if( Zflag && last_gb >= 1 K K ){
  1104. X        last_gb = 0;
  1105. X        if( in_ISCHR )
  1106. X            (void) lseek( fdin, 0, SEEK_SET);
  1107. X        if( out_ISCHR )
  1108. X            (void) lseek( fdout, 0, SEEK_SET);
  1109. X    }
  1110. X    if( showevery ){
  1111. X        if( debug > 3 )
  1112. X            fprintf( stderr, "W: outk = %lu, next_k = %lu\n",
  1113. X                outk, next_k );
  1114. X        if( outk >= next_k ){
  1115. X            pr_out();
  1116. X            next_k += showevery;
  1117. X        }
  1118. X    }
  1119. X
  1120. X    unlock( pbuffer->semid, pbuffer->blocks_free_lock );
  1121. X}
  1122. X
  1123. X
  1124. Xvoid
  1125. Xbyee( exit_val )
  1126. X    int exit_val;
  1127. X{
  1128. X    if( writer_pid != 0 ){
  1129. X        if( exit_val != 0 ){
  1130. X            /* I am shutting down due to an error.
  1131. X             * Shut the writer down or else it will try to access
  1132. X             * the freed up locks */
  1133. X            end_writer();
  1134. X        }
  1135. X        wait_for_writer_end();
  1136. X    }
  1137. X
  1138. X    if( free_shm ){
  1139. X        buffer_remove();
  1140. X    }
  1141. X
  1142. X    /* If the child died or was killed show this in the exit value */
  1143. X    if( writer_status ){
  1144. X        if( WEXITSTATUS( writer_status ) || WIFSIGNALED( writer_status ) ){
  1145. X            if( debug )
  1146. X                fprintf( stderr, "writer died badly: 0x%04x\n", writer_status );
  1147. X            exit( -2 );
  1148. X        }
  1149. X    }
  1150. X
  1151. X    exit( exit_val );
  1152. X}
  1153. X
  1154. X/* Kill off the writer */
  1155. Xend_writer()
  1156. X{
  1157. X    if( writer_pid )
  1158. X        kill( writer_pid, SIGHUP );
  1159. X}
  1160. X
  1161. Xwait_for_writer_end()
  1162. X{
  1163. X    int deadpid;
  1164. X
  1165. X    /* Now wait for the writer to finish */
  1166. X    while( writer_pid && ((deadpid = wait( &writer_status )) != writer_pid) &&
  1167. X        deadpid != -1 )
  1168. X        ;
  1169. X}
  1170. X
  1171. Xtest_writer()
  1172. X{
  1173. X    /* Has the writer gone unexpectedly? */
  1174. X    if( writer_pid == 0 ){
  1175. X        fprintf( stderr, "writer has died unexpectedly\n" );
  1176. X        byee( -1 );
  1177. X    }
  1178. X}
  1179. X
  1180. X/* Given a string of <num>[<suff>] returns a num
  1181. X * suff =
  1182. X *   m/M for 1meg
  1183. X *   k/K for 1k
  1184. X *   b/B for 512
  1185. X */
  1186. Xdo_size( arg )
  1187. X    char *arg;
  1188. X{
  1189. X    char format[ 20 ];
  1190. X    int ret;
  1191. X
  1192. X    *format = '\0';
  1193. X    sscanf( arg, "%d%s", &ret, format );
  1194. X
  1195. X    switch( *format ){
  1196. X    case 'm':
  1197. X    case 'M':
  1198. X        ret = ret K K;
  1199. X        break;
  1200. X    case 'k':
  1201. X    case 'K':
  1202. X        ret = ret K;
  1203. X        break;
  1204. X    case 'b':
  1205. X    case 'B':
  1206. X        ret *= 512;
  1207. X        break;
  1208. X    }
  1209. X    
  1210. X    return ret;
  1211. X}
  1212. X
  1213. Xpr_out()
  1214. X{
  1215. X    fprintf( stderr, "% 10luK\r", outk );
  1216. X}
  1217. X
  1218. X#ifdef SYS5
  1219. X#include <sys/time.h>
  1220. X
  1221. Xbzero( b, l )
  1222. X    char *b;
  1223. X    unsigned l;
  1224. X{
  1225. X    memset( b, '\0', l );
  1226. X}
  1227. X
  1228. Xusleep_back()
  1229. X{
  1230. X}
  1231. X
  1232. Xusleep( u )
  1233. X    unsigned u;
  1234. X{
  1235. X    struct itimerval old, t;
  1236. X    signal( SIGALRM, usleep_back );
  1237. X    t.it_interval.tv_sec = 0;
  1238. X    t.it_interval.tv_usec = 0;
  1239. X    t.it_value.tv_sec = u / 1000000;
  1240. X    t.it_value.tv_usec = u % 1000000;
  1241. X    setitimer( ITIMER_REAL, &t, &old );
  1242. X    pause();
  1243. X    setitimer( ITIMER_REAL, &old, NULL );
  1244. X}
  1245. X#endif
  1246. X
  1247. X/* Called before error reports */
  1248. Xreport_proc()
  1249. X{
  1250. X    fprintf( stderr, "%s: ", proc_string );
  1251. X}
  1252. END_OF_FILE
  1253. if test 20661 -ne `wc -c <'buffer.c'`; then
  1254.     echo shar: \"'buffer.c'\" unpacked with wrong size!
  1255. fi
  1256. # end of 'buffer.c'
  1257. fi
  1258. if test -f 'sem.c' -a "${1}" != "-c" ; then 
  1259.   echo shar: Will not clobber existing file \"'sem.c'\"
  1260. else
  1261. echo shar: Extracting \"'sem.c'\" \(3070 characters\)
  1262. sed "s/^X//" >'sem.c' <<'END_OF_FILE'
  1263. X/*
  1264. X    Buffer.  Very fast reblocking filter speedy writing of tapes.
  1265. X    Copyright (C) 1990,1991  Lee McLoughlin
  1266. X
  1267. X    This program is free software; you can redistribute it and/or modify
  1268. X    it under the terms of the GNU General Public License as published by
  1269. X    the Free Software Foundation; either version 1, or (at your option)
  1270. X    any later version.
  1271. X
  1272. X    This program is distributed in the hope that it will be useful,
  1273. X    but WITHOUT ANY WARRANTY; without even the implied warranty of
  1274. X    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  1275. X    GNU General Public License for more details.
  1276. X
  1277. X    You should have received a copy of the GNU General Public License
  1278. X    along with this program; if not, write to the Free Software
  1279. X    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  1280. X
  1281. X    Lee McLoughlin.
  1282. X    Dept of Computing, Imperial College,
  1283. X    180 Queens Gate, London, SW7 2BZ, UK.
  1284. X
  1285. X    Email: L.McLoughlin@doc.ic.ac.uk
  1286. X*/
  1287. X
  1288. X/* This is a simple module to provide an easier to understand interface to
  1289. X * semaphores */
  1290. X
  1291. X#include <stdio.h>
  1292. X#include <sys/types.h>
  1293. X#include <sys/stat.h>
  1294. X#include <sys/ipc.h>
  1295. X#include <sys/sem.h>
  1296. X#include <errno.h>
  1297. X
  1298. X#if defined(SYS5) || defined(ultrix) || defined(_AIX)
  1299. Xunion semun {
  1300. X    int val;
  1301. X    struct semid_ds *buf;
  1302. X    ushort *array;
  1303. X};
  1304. X#endif
  1305. X
  1306. X/* IMPORTS */
  1307. X
  1308. X/* Used to print error messages */
  1309. Xextern void report_proc();
  1310. X
  1311. X/* Used to end the program - on error */
  1312. Xextern void byee();
  1313. X
  1314. X
  1315. X
  1316. X/* Set a semaphore to a particular value - meant to be used before
  1317. X * first lock/unlock */
  1318. Xvoid
  1319. Xsem_set( sem_id, semn, val )
  1320. X    int sem_id;
  1321. X    int semn;
  1322. X    int val;
  1323. X{
  1324. X    union semun arg;
  1325. X    extern int errno;
  1326. X
  1327. X    arg.val = val;
  1328. X
  1329. X    errno = 0;
  1330. X    semctl( sem_id, semn, SETVAL, arg );
  1331. X    if( errno != 0 ){
  1332. X        report_proc();
  1333. X        perror( "internal error, sem_set" );
  1334. X        byee( -1 );
  1335. X    }
  1336. X}
  1337. X    
  1338. Xint
  1339. Xnew_sems( nsems )
  1340. X    int nsems;
  1341. X{
  1342. X    int sem;
  1343. X    int i;
  1344. X
  1345. X    sem = semget( IPC_PRIVATE, nsems, IPC_CREAT|S_IREAD|S_IWRITE );
  1346. X    if( sem < 0 ){
  1347. X        report_proc();
  1348. X        perror( "internal error, couldn't create semaphore" );
  1349. X        byee( -1 );
  1350. X    }
  1351. X    
  1352. X    for( i = 0; i < nsems; i++ ){
  1353. X        sem_set( sem, i, 1 );
  1354. X    }
  1355. X
  1356. X    return sem;
  1357. X}
  1358. X
  1359. Xstatic
  1360. Xdo_sem( sem_id, pbuf, err )
  1361. X    int sem_id;
  1362. X    struct sembuf *pbuf;
  1363. X    char *err;
  1364. X{
  1365. X    /* This just keeps us going in case of EINTR */
  1366. X    while( 1 ){
  1367. X        if( semop( sem_id, pbuf, 1 ) == -1 ){
  1368. X            if( errno == EINTR ){
  1369. X                continue;
  1370. X            }
  1371. X            report_proc();
  1372. X            fprintf( stderr, "internal error pid %d, lock id %d\n",
  1373. X                getpid(), sem_id );
  1374. X            perror( err );
  1375. X            byee( -1 );
  1376. X        }
  1377. X        return;
  1378. X    }
  1379. X}
  1380. X
  1381. Xvoid
  1382. Xlock( sem_id, semn )
  1383. X    int sem_id;
  1384. X    int semn;
  1385. X{
  1386. X    struct sembuf sembuf;
  1387. X
  1388. X    sembuf.sem_num = semn;
  1389. X    sembuf.sem_op = -1;
  1390. X    sembuf.sem_flg = 0;
  1391. X
  1392. X    do_sem( sem_id, &sembuf, "lock error" );
  1393. X}
  1394. X
  1395. Xvoid
  1396. Xunlock( sem_id, semn )
  1397. X    int sem_id;
  1398. X    int semn;
  1399. X{
  1400. X    struct sembuf sembuf;
  1401. X
  1402. X    sembuf.sem_num = semn;
  1403. X    sembuf.sem_op = 1;
  1404. X    sembuf.sem_flg = 0;
  1405. X
  1406. X    do_sem( sem_id, &sembuf, "unlock error" );
  1407. X}
  1408. X
  1409. Xvoid
  1410. Xremove_sems( sem_id )
  1411. X    int sem_id;
  1412. X{
  1413. X    if( sem_id == -1 )
  1414. X        return;
  1415. X
  1416. X    if( semctl( sem_id, 0, IPC_RMID, NULL ) == -1 ){
  1417. X        report_proc();
  1418. X        perror( "internal error, failed to remove semaphore" );
  1419. X    }
  1420. X}
  1421. END_OF_FILE
  1422. if test 3070 -ne `wc -c <'sem.c'`; then
  1423.     echo shar: \"'sem.c'\" unpacked with wrong size!
  1424. fi
  1425. # end of 'sem.c'
  1426. fi
  1427. if test -f 'COPYING' -a "${1}" != "-c" ; then 
  1428.   echo shar: Will not clobber existing file \"'COPYING'\"
  1429. else
  1430. echo shar: Extracting \"'COPYING'\" \(17982 characters\)
  1431. sed "s/^X//" >'COPYING' <<'END_OF_FILE'
  1432. X            GNU GENERAL PUBLIC LICENSE
  1433. X               Version 2, June 1991
  1434. X
  1435. X Copyright (C) 1989, 1991 Free Software Foundation, Inc.
  1436. X                          675 Mass Ave, Cambridge, MA 02139, USA
  1437. X Everyone is permitted to copy and distribute verbatim copies
  1438. X of this license document, but changing it is not allowed.
  1439. X
  1440. X                Preamble
  1441. X
  1442. X  The licenses for most software are designed to take away your
  1443. Xfreedom to share and change it.  By contrast, the GNU General Public
  1444. XLicense is intended to guarantee your freedom to share and change free
  1445. Xsoftware--to make sure the software is free for all its users.  This
  1446. XGeneral Public License applies to most of the Free Software
  1447. XFoundation's software and to any other program whose authors commit to
  1448. Xusing it.  (Some other Free Software Foundation software is covered by
  1449. Xthe GNU Library General Public License instead.)  You can apply it to
  1450. Xyour programs, too.
  1451. X
  1452. X  When we speak of free software, we are referring to freedom, not
  1453. Xprice.  Our General Public Licenses are designed to make sure that you
  1454. Xhave the freedom to distribute copies of free software (and charge for
  1455. Xthis service if you wish), that you receive source code or can get it
  1456. Xif you want it, that you can change the software or use pieces of it
  1457. Xin new free programs; and that you know you can do these things.
  1458. X
  1459. X  To protect your rights, we need to make restrictions that forbid
  1460. Xanyone to deny you these rights or to ask you to surrender the rights.
  1461. XThese restrictions translate to certain responsibilities for you if you
  1462. Xdistribute copies of the software, or if you modify it.
  1463. X
  1464. X  For example, if you distribute copies of such a program, whether
  1465. Xgratis or for a fee, you must give the recipients all the rights that
  1466. Xyou have.  You must make sure that they, too, receive or can get the
  1467. Xsource code.  And you must show them these terms so they know their
  1468. Xrights.
  1469. X
  1470. X  We protect your rights with two steps: (1) copyright the software, and
  1471. X(2) offer you this license which gives you legal permission to copy,
  1472. Xdistribute and/or modify the software.
  1473. X
  1474. X  Also, for each author's protection and ours, we want to make certain
  1475. Xthat everyone understands that there is no warranty for this free
  1476. Xsoftware.  If the software is modified by someone else and passed on, we
  1477. Xwant its recipients to know that what they have is not the original, so
  1478. Xthat any problems introduced by others will not reflect on the original
  1479. Xauthors' reputations.
  1480. X
  1481. X  Finally, any free program is threatened constantly by software
  1482. Xpatents.  We wish to avoid the danger that redistributors of a free
  1483. Xprogram will individually obtain patent licenses, in effect making the
  1484. Xprogram proprietary.  To prevent this, we have made it clear that any
  1485. Xpatent must be licensed for everyone's free use or not licensed at all.
  1486. X
  1487. X  The precise terms and conditions for copying, distribution and
  1488. Xmodification follow.
  1489. X
  1490. X            GNU GENERAL PUBLIC LICENSE
  1491. X   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
  1492. X
  1493. X  0. This License applies to any program or other work which contains
  1494. Xa notice placed by the copyright holder saying it may be distributed
  1495. Xunder the terms of this General Public License.  The "Program", below,
  1496. Xrefers to any such program or work, and a "work based on the Program"
  1497. Xmeans either the Program or any derivative work under copyright law:
  1498. Xthat is to say, a work containing the Program or a portion of it,
  1499. Xeither verbatim or with modifications and/or translated into another
  1500. Xlanguage.  (Hereinafter, translation is included without limitation in
  1501. Xthe term "modification".)  Each licensee is addressed as "you".
  1502. X
  1503. XActivities other than copying, distribution and modification are not
  1504. Xcovered by this License; they are outside its scope.  The act of
  1505. Xrunning the Program is not restricted, and the output from the Program
  1506. Xis covered only if its contents constitute a work based on the
  1507. XProgram (independent of having been made by running the Program).
  1508. XWhether that is true depends on what the Program does.
  1509. X
  1510. X  1. You may copy and distribute verbatim copies of the Program's
  1511. Xsource code as you receive it, in any medium, provided that you
  1512. Xconspicuously and appropriately publish on each copy an appropriate
  1513. Xcopyright notice and disclaimer of warranty; keep intact all the
  1514. Xnotices that refer to this License and to the absence of any warranty;
  1515. Xand give any other recipients of the Program a copy of this License
  1516. Xalong with the Program.
  1517. X
  1518. XYou may charge a fee for the physical act of transferring a copy, and
  1519. Xyou may at your option offer warranty protection in exchange for a fee.
  1520. X
  1521. X  2. You may modify your copy or copies of the Program or any portion
  1522. Xof it, thus forming a work based on the Program, and copy and
  1523. Xdistribute such modifications or work under the terms of Section 1
  1524. Xabove, provided that you also meet all of these conditions:
  1525. X
  1526. X    a) You must cause the modified files to carry prominent notices
  1527. X    stating that you changed the files and the date of any change.
  1528. X
  1529. X    b) You must cause any work that you distribute or publish, that in
  1530. X    whole or in part contains or is derived from the Program or any
  1531. X    part thereof, to be licensed as a whole at no charge to all third
  1532. X    parties under the terms of this License.
  1533. X
  1534. X    c) If the modified program normally reads commands interactively
  1535. X    when run, you must cause it, when started running for such
  1536. X    interactive use in the most ordinary way, to print or display an
  1537. X    announcement including an appropriate copyright notice and a
  1538. X    notice that there is no warranty (or else, saying that you provide
  1539. X    a warranty) and that users may redistribute the program under
  1540. X    these conditions, and telling the user how to view a copy of this
  1541. X    License.  (Exception: if the Program itself is interactive but
  1542. X    does not normally print such an announcement, your work based on
  1543. X    the Program is not required to print an announcement.)
  1544. X
  1545. XThese requirements apply to the modified work as a whole.  If
  1546. Xidentifiable sections of that work are not derived from the Program,
  1547. Xand can be reasonably considered independent and separate works in
  1548. Xthemselves, then this License, and its terms, do not apply to those
  1549. Xsections when you distribute them as separate works.  But when you
  1550. Xdistribute the same sections as part of a whole which is a work based
  1551. Xon the Program, the distribution of the whole must be on the terms of
  1552. Xthis License, whose permissions for other licensees extend to the
  1553. Xentire whole, and thus to each and every part regardless of who wrote it.
  1554. X
  1555. XThus, it is not the intent of this section to claim rights or contest
  1556. Xyour rights to work written entirely by you; rather, the intent is to
  1557. Xexercise the right to control the distribution of derivative or
  1558. Xcollective works based on the Program.
  1559. X
  1560. XIn addition, mere aggregation of another work not based on the Program
  1561. Xwith the Program (or with a work based on the Program) on a volume of
  1562. Xa storage or distribution medium does not bring the other work under
  1563. Xthe scope of this License.
  1564. X
  1565. X  3. You may copy and distribute the Program (or a work based on it,
  1566. Xunder Section 2) in object code or executable form under the terms of
  1567. XSections 1 and 2 above provided that you also do one of the following:
  1568. X
  1569. X    a) Accompany it with the complete corresponding machine-readable
  1570. X    source code, which must be distributed under the terms of Sections
  1571. X    1 and 2 above on a medium customarily used for software interchange; or,
  1572. X
  1573. X    b) Accompany it with a written offer, valid for at least three
  1574. X    years, to give any third party, for a charge no more than your
  1575. X    cost of physically performing source distribution, a complete
  1576. X    machine-readable copy of the corresponding source code, to be
  1577. X    distributed under the terms of Sections 1 and 2 above on a medium
  1578. X    customarily used for software interchange; or,
  1579. X
  1580. X    c) Accompany it with the information you received as to the offer
  1581. X    to distribute corresponding source code.  (This alternative is
  1582. X    allowed only for noncommercial distribution and only if you
  1583. X    received the program in object code or executable form with such
  1584. X    an offer, in accord with Subsection b above.)
  1585. X
  1586. XThe source code for a work means the preferred form of the work for
  1587. Xmaking modifications to it.  For an executable work, complete source
  1588. Xcode means all the source code for all modules it contains, plus any
  1589. Xassociated interface definition files, plus the scripts used to
  1590. Xcontrol compilation and installation of the executable.  However, as a
  1591. Xspecial exception, the source code distributed need not include
  1592. Xanything that is normally distributed (in either source or binary
  1593. Xform) with the major components (compiler, kernel, and so on) of the
  1594. Xoperating system on which the executable runs, unless that component
  1595. Xitself accompanies the executable.
  1596. X
  1597. XIf distribution of executable or object code is made by offering
  1598. Xaccess to copy from a designated place, then offering equivalent
  1599. Xaccess to copy the source code from the same place counts as
  1600. Xdistribution of the source code, even though third parties are not
  1601. Xcompelled to copy the source along with the object code.
  1602. X
  1603. X  4. You may not copy, modify, sublicense, or distribute the Program
  1604. Xexcept as expressly provided under this License.  Any attempt
  1605. Xotherwise to copy, modify, sublicense or distribute the Program is
  1606. Xvoid, and will automatically terminate your rights under this License.
  1607. XHowever, parties who have received copies, or rights, from you under
  1608. Xthis License will not have their licenses terminated so long as such
  1609. Xparties remain in full compliance.
  1610. X
  1611. X  5. You are not required to accept this License, since you have not
  1612. Xsigned it.  However, nothing else grants you permission to modify or
  1613. Xdistribute the Program or its derivative works.  These actions are
  1614. Xprohibited by law if you do not accept this License.  Therefore, by
  1615. Xmodifying or distributing the Program (or any work based on the
  1616. XProgram), you indicate your acceptance of this License to do so, and
  1617. Xall its terms and conditions for copying, distributing or modifying
  1618. Xthe Program or works based on it.
  1619. X
  1620. X  6. Each time you redistribute the Program (or any work based on the
  1621. XProgram), the recipient automatically receives a license from the
  1622. Xoriginal licensor to copy, distribute or modify the Program subject to
  1623. Xthese terms and conditions.  You may not impose any further
  1624. Xrestrictions on the recipients' exercise of the rights granted herein.
  1625. XYou are not responsible for enforcing compliance by third parties to
  1626. Xthis License.
  1627. X
  1628. X  7. If, as a consequence of a court judgment or allegation of patent
  1629. Xinfringement or for any other reason (not limited to patent issues),
  1630. Xconditions are imposed on you (whether by court order, agreement or
  1631. Xotherwise) that contradict the conditions of this License, they do not
  1632. Xexcuse you from the conditions of this License.  If you cannot
  1633. Xdistribute so as to satisfy simultaneously your obligations under this
  1634. XLicense and any other pertinent obligations, then as a consequence you
  1635. Xmay not distribute the Program at all.  For example, if a patent
  1636. Xlicense would not permit royalty-free redistribution of the Program by
  1637. Xall those who receive copies directly or indirectly through you, then
  1638. Xthe only way you could satisfy both it and this License would be to
  1639. Xrefrain entirely from distribution of the Program.
  1640. X
  1641. XIf any portion of this section is held invalid or unenforceable under
  1642. Xany particular circumstance, the balance of the section is intended to
  1643. Xapply and the section as a whole is intended to apply in other
  1644. Xcircumstances.
  1645. X
  1646. XIt is not the purpose of this section to induce you to infringe any
  1647. Xpatents or other property right claims or to contest validity of any
  1648. Xsuch claims; this section has the sole purpose of protecting the
  1649. Xintegrity of the free software distribution system, which is
  1650. Ximplemented by public license practices.  Many people have made
  1651. Xgenerous contributions to the wide range of software distributed
  1652. Xthrough that system in reliance on consistent application of that
  1653. Xsystem; it is up to the author/donor to decide if he or she is willing
  1654. Xto distribute software through any other system and a licensee cannot
  1655. Ximpose that choice.
  1656. X
  1657. XThis section is intended to make thoroughly clear what is believed to
  1658. Xbe a consequence of the rest of this License.
  1659. X
  1660. X  8. If the distribution and/or use of the Program is restricted in
  1661. Xcertain countries either by patents or by copyrighted interfaces, the
  1662. Xoriginal copyright holder who places the Program under this License
  1663. Xmay add an explicit geographical distribution limitation excluding
  1664. Xthose countries, so that distribution is permitted only in or among
  1665. Xcountries not thus excluded.  In such case, this License incorporates
  1666. Xthe limitation as if written in the body of this License.
  1667. X
  1668. X  9. The Free Software Foundation may publish revised and/or new versions
  1669. Xof the General Public License from time to time.  Such new versions will
  1670. Xbe similar in spirit to the present version, but may differ in detail to
  1671. Xaddress new problems or concerns.
  1672. X
  1673. XEach version is given a distinguishing version number.  If the Program
  1674. Xspecifies a version number of this License which applies to it and "any
  1675. Xlater version", you have the option of following the terms and conditions
  1676. Xeither of that version or of any later version published by the Free
  1677. XSoftware Foundation.  If the Program does not specify a version number of
  1678. Xthis License, you may choose any version ever published by the Free Software
  1679. XFoundation.
  1680. X
  1681. X  10. If you wish to incorporate parts of the Program into other free
  1682. Xprograms whose distribution conditions are different, write to the author
  1683. Xto ask for permission.  For software which is copyrighted by the Free
  1684. XSoftware Foundation, write to the Free Software Foundation; we sometimes
  1685. Xmake exceptions for this.  Our decision will be guided by the two goals
  1686. Xof preserving the free status of all derivatives of our free software and
  1687. Xof promoting the sharing and reuse of software generally.
  1688. X
  1689. X                NO WARRANTY
  1690. X
  1691. X  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
  1692. XFOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
  1693. XOTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
  1694. XPROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
  1695. XOR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  1696. XMERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
  1697. XTO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
  1698. XPROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
  1699. XREPAIR OR CORRECTION.
  1700. X
  1701. X  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
  1702. XWILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
  1703. XREDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
  1704. XINCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
  1705. XOUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
  1706. XTO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
  1707. XYOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
  1708. XPROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
  1709. XPOSSIBILITY OF SUCH DAMAGES.
  1710. X
  1711. X             END OF TERMS AND CONDITIONS
  1712. X
  1713. X    Appendix: How to Apply These Terms to Your New Programs
  1714. X
  1715. X  If you develop a new program, and you want it to be of the greatest
  1716. Xpossible use to the public, the best way to achieve this is to make it
  1717. Xfree software which everyone can redistribute and change under these terms.
  1718. X
  1719. X  To do so, attach the following notices to the program.  It is safest
  1720. Xto attach them to the start of each source file to most effectively
  1721. Xconvey the exclusion of warranty; and each file should have at least
  1722. Xthe "copyright" line and a pointer to where the full notice is found.
  1723. X
  1724. X    <one line to give the program's name and a brief idea of what it does.>
  1725. X    Copyright (C) 19yy  <name of author>
  1726. X
  1727. X    This program is free software; you can redistribute it and/or modify
  1728. X    it under the terms of the GNU General Public License as published by
  1729. X    the Free Software Foundation; either version 2 of the License, or
  1730. X    (at your option) any later version.
  1731. X
  1732. X    This program is distributed in the hope that it will be useful,
  1733. X    but WITHOUT ANY WARRANTY; without even the implied warranty of
  1734. X    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  1735. X    GNU General Public License for more details.
  1736. X
  1737. X    You should have received a copy of the GNU General Public License
  1738. X    along with this program; if not, write to the Free Software
  1739. X    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  1740. X
  1741. XAlso add information on how to contact you by electronic and paper mail.
  1742. X
  1743. XIf the program is interactive, make it output a short notice like this
  1744. Xwhen it starts in an interactive mode:
  1745. X
  1746. X    Gnomovision version 69, Copyright (C) 19yy name of author
  1747. X    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
  1748. X    This is free software, and you are welcome to redistribute it
  1749. X    under certain conditions; type `show c' for details.
  1750. X
  1751. XThe hypothetical commands `show w' and `show c' should show the appropriate
  1752. Xparts of the General Public License.  Of course, the commands you use may
  1753. Xbe called something other than `show w' and `show c'; they could even be
  1754. Xmouse-clicks or menu items--whatever suits your program.
  1755. X
  1756. XYou should also get your employer (if you work as a programmer) or your
  1757. Xschool, if any, to sign a "copyright disclaimer" for the program, if
  1758. Xnecessary.  Here is a sample; alter the names:
  1759. X
  1760. X  Yoyodyne, Inc., hereby disclaims all copyright interest in the program
  1761. X  `Gnomovision' (which makes passes at compilers) written by James Hacker.
  1762. X
  1763. X  <signature of Ty Coon>, 1 April 1989
  1764. X  Ty Coon, President of Vice
  1765. X
  1766. XThis General Public License does not permit incorporating your program into
  1767. Xproprietary programs.  If your program is a subroutine library, you may
  1768. Xconsider it more useful to permit linking proprietary applications with the
  1769. Xlibrary.  If this is what you want to do, use the GNU Library General
  1770. XPublic License instead of this License.
  1771. END_OF_FILE
  1772. if test 17982 -ne `wc -c <'COPYING'`; then
  1773.     echo shar: \"'COPYING'\" unpacked with wrong size!
  1774. fi
  1775. # end of 'COPYING'
  1776. fi
  1777. echo shar: End of shell archive.
  1778. exit 0
  1779. exit 0 # Just in case...
  1780.