home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 1 / 1578 < prev    next >
Internet Message Format  |  1990-12-28  |  54KB

  1. From: wht@n4hgf.Mt-Park.GA.US (Warren Tucker)
  2. Newsgroups: alt.sources
  3. Subject: shar 3.32 part 1/2
  4. Message-ID: <163@n4hgf.Mt-Park.GA.US>
  5. Date: 14 Jul 90 18:00:44 GMT
  6.  
  7. Submitted-by: wht@n4hgf.Mt-Park.GA.US
  8. Archive-name: shar332/part01
  9.  
  10. Here is a new, improved flame generator.
  11.  
  12. #!/bin/sh
  13. # This is shar332, a shell archive (shar 3.32)
  14. # made 07/14/1990 17:58 UTC by wht@n4hgf.Mt-Park.GA.US
  15. # Source directory /u1/src/shar
  16. #
  17. # existing files WILL be overwritten
  18. # This format requires very little intelligence at unshar time.
  19. # "echo" and "sed" will be needed.
  20. #
  21. # This shar contains:
  22. # length  mode       name
  23. # ------ ---------- ------------------------------------------
  24. #   9514 -rw-r--r-- README
  25. #   6433 -rw-r--r-- shar.1
  26. #   1261 -rw-r--r-- unshar.1
  27. #   1600 -rw-r--r-- Makefile
  28. #  31324 -rw-r--r-- shar.c
  29. #  10889 -rw-r--r-- unshar.c
  30. #   1152 -rw-r--r-- uushar.c
  31. #   2803 -rw-r--r-- who@where.c
  32. #
  33. # ============= README ==============
  34. echo "x - extracting README (Text)"
  35. sed 's/^X//' << 'SHAR_EOF' > README &&
  36. XThis file last revised Wed Jun 13 18:57:32 EDT 1990
  37. X
  38. XHere is shar 3.30, an updated version of shar 3.11, derived from 'shar2'.
  39. XThis offering is the work of many people. Thanks to rhg@CPS.COM (Richard H.
  40. XGumpertz), colas@avahi.inria.fr (Colas Nahaboo), bill@netagw.com (Bill
  41. XAten) and marks@rex.cs.tulane.edu and maaaany others.
  42. X
  43. XThis version's shar:
  44. X1) generates shell code which attempts to create missing directories
  45. X2) handle deviants sun, vax, pyramid, sequent, and SCO XENIX/UNIX
  46. X   automatically; for system V systems I did not catch, add -DSYS5
  47. X   to CFLAGS; for other BSD-like systems, add -DBSD42
  48. X3) if unsharing system's touch is Sys V compatible (allows touch -m),
  49. X   the unshar process restores file dates
  50. X4) An archive name may be specified for includion in the header
  51. X   of the shar files( -n switch)
  52. X5) allows automatic generation of "Submitted-by: who@where" &
  53. X   "Archive-name: <name>/part##" headers
  54. X6) uses getopt; no good system library should be without a copy
  55. X   but it is readily available (like look in unshar.c)
  56. X7) other chrome-plated junque
  57. X
  58. XThis version's unshar:
  59. X1) can change directory before unsharing
  60. X2) can unshar from standard in, from a COLLECTION of shars,
  61. X   from a file containing multiple concatenated shars,
  62. X   or a mixture of shar files and concatenated-shar files.
  63. X3) does not have an Social Security number.
  64. X
  65. X------------------------ shar  usage -----------------------------------
  66. Xshar 3.30
  67. Xusage: shar [ options ] file [ file1 ... ] ]
  68. X-V  produce "vanilla" shars demanding little of the unshar environment
  69. X-v  verbose messages OFF while executing
  70. X-w  don't check with 'wc -c' after unpack
  71. X-n  Name of archive (documentation)
  72. X-a  Generate Submitted-by: & Archive-name: headers
  73. X-s  override automatically determined submitter name
  74. X-x  don't overwrite existing files
  75. X-X  interactively overwrite existing files (NOT FOR NET SHARS)
  76. X-b  treat all files as binary, use uuencode
  77. X-t  treat all files as text (default)
  78. X-C  compress and uuencode all files
  79. X-p  allow positional parameter options. The options "-b" and "-t"
  80. X    and "-C" may be embedded, and files to the right of the
  81. X    option will be processed in the specified mode
  82. X-M  mixed mode. Determine if the files are text or
  83. X    binary and archive correctly.
  84. X-P  use temp files instead of pipes in the shar file
  85. X-c  start the shar with a cut line
  86. X-f  restore by filename only, rather than path
  87. X-dXXX   use XXX to delimit the files in the shar
  88. X-oXXX   (or -o XXX) output to file XXX.01 thru XXX.nn
  89. X-lXX    limit output file size to XXk bytes (but don't split files)
  90. X-LXX    limit output file size to XXk bytes (may split files)
  91. X-S      read files to wrap from stdin, ignoring argument line
  92. X
  93. XThe -S option reads filenames one per line from stdin; input
  94. Xformat must be similar to 'find' output, except that if -p
  95. Xis specified, -b, -t or -C may be used (on lines by themselves)
  96. Xe.g., find . -type f -print | sort | shar -C -L50 -o /tmp/big
  97. X
  98. XThe 'o' option is required if the 'l' or 'L' option is used
  99. XThe 'n' option is required if the 'a' option is used
  100. XThe 'x' and 'L' options are incompatible
  101. X
  102. X-a generates sharname/part## headers. If the -a argument contains
  103. Xa '/', then /patch is not appended
  104. XThe automatic submitter name is trivial: essentially `whoami`@`uname`
  105. X
  106. X------------------------ unshar usage -----------------------------------
  107. XUnshar has no usage built in.  It has default actions when invoked
  108. Xwith no arguments (read from stdin).
  109. X
  110. XUsage:     unshar [-c] [-C exit_line] [ -d directory ] [ file ] ...
  111. X
  112. X     The -d flag tells unshar to change directory before unsharing
  113. X
  114. X     It can unshar shar files concatenated in one file, with the
  115. X     the "-c" command, which separates files by recognizing the
  116. X     "exit 0" string at the beginning of a line
  117. X
  118. X     (The -C string option allows you to specify this string, thus
  119. X     -c is equivalent to -C "exit 0")
  120. X
  121. X
  122. X--------------------- history -----------------------------------------
  123. XChanges since 3.11: kudos to rhg@CPS.COM (Richard H. Gumpertz)
  124. X
  125. X1.  The -l switch still specifies a maximum size for the generated
  126. X    shar files, but now it prevents files from spanning shar parts.
  127. X    Shars generated using this method may be unpacked in any order.
  128. X
  129. X2.  The old -l switch functionality is precisely emulated by using the
  130. X    the -L switch.  That is, archived files may be split across parts.
  131. X    Shars generated using this method must still be unpacked in order.
  132. X
  133. X3.  The -C switch causes files to be compressed, then uuencoded.
  134. X    Unpacking reverses the process.
  135. X
  136. X4.  The -P causes the shar to use temp files instead of pipes in
  137. X    the unshar process.
  138. X
  139. X5.  The -f causes files to be resotred by name only (i.e., strip
  140. X    directory portion of input filenames before placing the name
  141. X    into the shar.
  142. X
  143. X
  144. XChanges since 3.20: kudos to colas@avahi.inria.fr (Colas Nahaboo)
  145. X
  146. X1.  The Archived-name: header no longer uses "/part" if there is
  147. X    a "/" in the -n name.  Thus
  148. X        -n xyzzy                     procduces:
  149. X                                     xyzzy/part01
  150. X                                     xyzzy/part02
  151. X
  152. X        -n xyzzy/patch               procduces:
  153. X                                     xyzzy/patch01
  154. X                                     xyzzy/patch02
  155. X
  156. X        -n xyzzy/patch01.            procduces:
  157. X                                     xyzzy/patch01.01
  158. X                                     xyzzy/patch01.02
  159. X2.  The Archive-name part number other than part01 had no leading zero
  160. X    in the number.
  161. X
  162. X3.  The "Submitted-by:" header was missing the hyphen (minus for olde
  163. X    UNIX hackres).
  164. X
  165. X4.  The unshar program may now unshar a whole mailbox or concatenation
  166. X    of shar files.
  167. X
  168. X    -C "string" looks for "string" at the beginning of the line to
  169. X       break the file into individual shar files
  170. X    -c is equivalent to -C "exit 0"
  171. X
  172. X    This of course will only work if there is something in the shar
  173. X    file recognizable to terminate the shar.  Some shars dont have
  174. X    "exit 0" at the end.  However, a clue: most/many .signatures have
  175. X    "--" on a line right before them.
  176. X
  177. X5.  Unshar -d (change directory) no longer makes argv files unreachable.
  178. X    I had never used the feature until the other day.  I guess the
  179. X    author has used in only for unsharing from stdin.
  180. X
  181. XChanges since 3.21: thanks to Adri Verhoef, <a3@rivm.UUCP>
  182. X
  183. X1.  Some vaxen do not run BSD.  I guess I knew this, but -er-
  184. X    here is Adri's note:
  185. X> Hi Warren,
  186. X> 
  187. X>   I encountered a problem trying to get 'shar3.21' to compile on System V
  188. X> on a vax.  Yes, can you believe it?  We run System V Release 3.0 on VAXen!
  189. X> The shar3.21 code assumes that you are BSD if you're on a vax.  This is not
  190. X> always true!  What I did to get the code compiled on System V, was:
  191. X> (+) edit the Makefile and add -DSYS5 to CFLAGS.
  192. X> (+) edit all the C-source files to circumcise compiler warnings
  193. X>     ("SYS5 redefined").
  194. X> 
  195. X
  196. XHe made a suggestion about having a localize.sh edit a distribution
  197. XMakefile, but for now, I'll just suggest you add -DSYS5 to CFLAGS 
  198. Xmanually.
  199. X
  200. X2.  jhd@irfu.se (Jan Dj{rv, sorry about the screwed up character
  201. X    translation, Jan) wrote man pages.  Thanks!
  202. X
  203. XChanges since 3.22: thanks to Dennis Boylan <dennis@nanovx>
  204. X
  205. X1.  The new -S option allows the list of files to be packed
  206. X    to be read from the standard input rather than from the
  207. X    command line.
  208. X
  209. X2.  A few purist checks were made to ensure fork() or malloc()
  210. X    doesn't fail and excite the "if 20 hours of your time is
  211. X    free then why isn't 200?" crowd (who probably will never see
  212. X    this revision anyway :-))
  213. X
  214. XChanges since 3.23:
  215. X
  216. X1.  The -V mode was added.
  217. X
  218. X2.  Altos doesn't like the '@' in filenames.  The filename format
  219. X    was changed.  Thanks to rhg@cps.com.
  220. X
  221. XChanges since 3.24:
  222. X
  223. X1.  Man pages were revised by gam@netcom (Gordon Moffet). Thanks.
  224. X
  225. X2.  When -L was specified, the "Starting ..." message was not
  226. Xproduced on standard error (with or without -v).
  227. X
  228. X3.  When using -X, the 'not for net' warning was printed on standard
  229. Xoutput rather thsn standard error.
  230. X
  231. X4.  marks@rex.cs.tulane.edu reccommends adding -F 5000 to the load
  232. X    line of unshar when using on XENIX 286 to avoid stack overflow
  233. X    core dumps.  I added this information to an excellkent remake
  234. X    of the Makefile by bill@netagw.com.
  235. X
  236. XChanges since 3.25:
  237. X
  238. X1.  Fixed one minor bug with -a/-n.  The period supplied when a
  239. X    slash appears in the -n name was omitted.  This is a hatefully
  240. X    small bug to fix and reissue a whole release, but
  241. X    a) several new names are on the sharlist now and they have
  242. X       only 3.24 to work with,
  243. X    b) this will surely sync us all up, and
  244. X    c) I think it will put shar to bed for a while ("no known bugs
  245. X       at this ti ... bus error core dumped").
  246. X
  247. XChanges since 3.27:
  248. X
  249. X1.  The unshar-time test for a touch -m facility now greps for
  250. X    'mmdd', not '[-amc]', making it more universally successful.
  251. X
  252. X2.  NOTE:  there is still a problem with -n arguments using
  253. X    a 'x/y' construct, but I don't know how to properly generalize
  254. X    it so you'll have to edit shars made with some uses of -a
  255. X    with -n x/y.
  256. X
  257. X3.  This is surely my last work on this.  It does everything
  258. X    I needed and more.  Thanks for all the help and suggestions.
  259. X    It seems as though we didn't precipitate 'death of the shar'
  260. X    after all :-) :-) :-).
  261. X
  262. X---------------------------------------------------------------------
  263. XWarren Tucker, TuckerWare  emory!n4hgf!wht or wht@n4hgf.Mt-Park.GA.US
  264. X{gatech,emory,tridom,kd4nc}!n4hgf!wht                   (404)587-5766
  265. Xwht%n4hgf.uucp@emory.mathcs.emory.edu
  266. SHAR_EOF
  267. # ============= shar.1 ==============
  268. echo "x - extracting shar.1 (Text)"
  269. sed 's/^X//' << 'SHAR_EOF' > shar.1 &&
  270. X.TH shar 1 local
  271. X.SH NAME
  272. Xshar \- create shell archives
  273. X.SH SYNOPSIS
  274. X.nf
  275. Xshar [ options ] [ file1 ... ]
  276. Xshar \-S [ options ]
  277. X.fi
  278. X.SH DESCRIPTION
  279. XShar 3.23 (or later)
  280. Xcreates "shell archives" (or shar files) which are in text format
  281. Xand can be mailed. These files may be unpacked later by executing them
  282. Xwith /bin/sh. The resulting archive is sent to standard out unless the
  283. X\f2\-o\f1 option is given.  A wide range of features provide extensive
  284. Xflexibility in manufacturing shars and in specifying shar "smartness."
  285. XArchives may be "vanilla" or comprehensive.
  286. X.SS OPTIONS
  287. X.PP
  288. XOptions can be given in any order. Some options depend on each other:
  289. X.nf
  290. X    The \f2\-o\f1 option is required if the \f2\-l\f1 or \f2\-L\f1 option is used.
  291. X    The \f2\-n\f1 option is required if the \f2\-a\f1 option is used.
  292. X    The \f2\-x\f1 and \f2\-L\f1 option are incompatible.
  293. X    See \f2\-V\f1 below.
  294. X.fi
  295. X.IP "\f2\-V\f1"
  296. XProduce "vanilla" shars which rely only upon the existence of sed and
  297. Xecho in the unsharing environment.  In addition, "if test" must also be
  298. Xsupported if the \f2\-X\f1 option is used.  The \f2\-V\f1 silently
  299. Xdisables options offensive to the "network cop" (or "brown shirt"), but
  300. Xdoes warn you if it is specified with \f2\-b\f1, \f2\-C\f1, \f2\-p\f1
  301. Xor \f2\-M\f1 (any of which does or might require uudecode or compress in
  302. Xthe unsharing environment).
  303. X.IP "\f2\-v\f1"
  304. XVerbose OFF. Disables the inclusion of comments to be output when the archive
  305. Xis unpacked.
  306. X.IP "\f2\-w\f1"
  307. XDo NOT check with 'wc \-c' after unpack. The default is to check.
  308. X.IP "\f2\-n\f1 name"
  309. XName of archive to be included in the header of the shar files.
  310. XSee the \f2\-a\f1 switch.
  311. X.IP "\f2\-a\f1"
  312. XAllows automatic generation of headers:
  313. X.nf
  314. X    Submitted-by: who@where
  315. X    Archive-name: <name>/part##
  316. X.fi
  317. XThe <name> must be given with the \f2\-n\f1 switch.
  318. XIf name includes a '/' "/part" isn't used. Thus:
  319. X.RS 10m
  320. X.nf
  321. X.ta 30m
  322. X\-n xyzzy    produces:
  323. X    xyzzy/part01
  324. X    xyzzy/part02
  325. X
  326. X\-n xyzzy/patch    produces:
  327. X    xyzzy/patch01
  328. X    xyzzy/patch02
  329. X
  330. X\-n xyzzy/patch01.    produces:
  331. X    xyzzy/patch01.01
  332. X    xyzzy/patch01.02
  333. X.RE
  334. X.fi
  335. X.IP ""
  336. XThe who@where can be
  337. Xexplicitly stated with the \f2\-s\f1 switch if the default isn't apropriate.
  338. XWho@where is essentially built as `whoami`@`uname`.
  339. X.IP "\f2\-s\f1 who@where"
  340. XOverride automatically determined submitter name.
  341. X.IP "\f2\-x\f1"
  342. XDon't overwrite existing files. The unpack will check for an existing file
  343. Xbefore unpacking a given file from the archive.
  344. X.IP "\f2\-X\f1"
  345. XInteractively overwrite existing files
  346. X(DO NOT USE FOR SHARS SUBMITTED TO THE NET).
  347. X.IP "\f2\-b\f1"
  348. XTreat all files as binary, use uuencode prior to packing. This increases the
  349. Xsize of the archive. The recipient must have uudecode in order to unpack.
  350. X(USE OF UUENCODE IS NOT APPRECIATED BY MANY ON THE NET).
  351. X.IP "\f2\-t\f1"
  352. XTreat all files as text (default).
  353. X.IP "\f2\-C\f1"
  354. XCompress and uuencode all files prior to packing. The recipient must have
  355. Xuudecode and uncompress in order to unpack
  356. X(USE OF UUENCODE AND COMPRESS IS NOT APPRECIATED BY MANY ON THE NET).
  357. X.IP "\f2\-p\f1"
  358. XAllow positional parameter options. The options "\f2\-b\f1" and "\f2\-t\f1"
  359. Xand "\f2\-C\f1" may be embedded, and files to the right of the
  360. Xoption will be processed in the specified mode.
  361. X.IP "\f2\-M\f1"
  362. XMixed mode. Determine if the files are text or binary and archive correctly.
  363. XFiles found to be binary are uudecoded prior to packing
  364. X(USE OF UUENCODE IS NOT APPRECIATED BY MANY ON THE NET).
  365. X.IP "\f2\-P\f1"
  366. XUse temporary files instead of pipes in the shar file.
  367. X.IP "\f2\-c\f1"
  368. XStart the shar with a cut line. A line saying 'Cut here' is placed at the
  369. Xstart of each output file.
  370. X.IP "\f2\-f\f1"
  371. XRestore by filename only, rather than path. This option causes only file
  372. Xnames to be used, which is useful when building a shar from several
  373. Xdirectories, or another directory.
  374. X.IP "\f2\-d\f1 XXX"
  375. XUse XXX to delimit the files in the shar instead of SHAR_EOF.
  376. XThis is for those who want to personalize their shar files.
  377. X.IP "\f2\-o\f1 XXX"
  378. XSave the archive to files XXX.01 thru XXX.nn instead of standard out.
  379. XMust be used when the \f2\-l\f1 or the \f2\-L\f1 switches are used
  380. X.IP "\f2\-l\f1 XX"
  381. XLimit the output file size to XXk bytes but don't split input files.
  382. X.IP "\f2\-L\f1 XX"
  383. XLimit output file size to XXk bytes and split files if necessary. The archives
  384. Xcreated with this option must be unpacked in correct order.
  385. X.IP "\f2\-S\f1"
  386. XRead list of files to be packed from the standard input rather than
  387. Xfrom the command line.  Input must be in a form similar to
  388. Xthat generated by the find command, one filename per line.  This
  389. Xswitch is especially useful when the command line will not hold
  390. Xthe list of files to be packed. For example:
  391. X.nf
  392. X
  393. Xfind . \-type f \-print | sort | shar \-S \-C \-L50 \-o /tmp/big
  394. X
  395. X.fi
  396. XIf \f2\-p\f1 is specified on the command line, then the 
  397. Xoptions "\f2\-b\f1" and "\f2\-t\f1" and "\f2\-C\f1" may be included
  398. Xin the standard input (on a line separate from filenames).
  399. XThe maximum number of lines of standard input, file names
  400. Xand options, may not exceed 1024.
  401. X.SH EXAMPLES
  402. X.nf
  403. X.ta 37m
  404. Xshar *.c > cprog.shar    # all C prog sources
  405. Xshar \-v *.[ch] > cprog.shar    # non-verbose, .c and .h files
  406. Xshar \-b \-l28 \-oarc.sh *.arc    # all binary .arc files, into
  407. X    # files arc.sh.01 thru arc.sh.NN
  408. Xshar \-f /lcl/src/u*.c > u.sh    # use only the filenames
  409. X.ta
  410. X.fi
  411. X.SH WARNINGS
  412. X.PP
  413. XUse of the \f2\-b\f1, \f2\-M\f1 or \f2\-C\f1 may slow the archive process
  414. Xconsiderably, depending on the number of files.
  415. X.PP
  416. XUse of \f2\-X\f1 produces shars which \f2WILL\f1 cause problems
  417. Xwith many unshar procedures.  Use this feature only for archives
  418. Xto be passed among agreeable parties.  Certainly, \f2\-X\f1 is NOT
  419. Xfor shell archives which are to be submitted to Usenet.
  420. XUsage of \f2\-b\f1 or \f2\-C\f1 in net shars will cause you to
  421. Xbe flamed off the earth.
  422. X.SH SEE ALSO
  423. X.PP 
  424. Xunshar(1)
  425. X.SH DIAGNOSTICS
  426. X.PP
  427. XError messages for illegal or incompatible options,
  428. Xfor non-regular, missing or inaccessible files or for (unlikely)
  429. Xmemory allocation failure.
  430. X.SH AUTHORS
  431. X.nf
  432. Xshar3 is a derived work based on the efforts of:
  433. Xdecvax!microsof!uw-beave!jim (James Gosling at CMU)
  434. XMichael A. Thompson, Dalhousie University, Halifax, N.S., Canada
  435. Xdavidsen@sixhub (Bill Davidsen)
  436. Xrhg@CPS.COM (Richard H. Gumpertz)
  437. Xcolas@avahi.inria.fr (Colas Nahaboo)
  438. Xbill@netagw.com (Bill Aten)
  439. Xdennis%nanovx@gatech.edu (Dennis Boylan)
  440. Xwht%n4hgf@gatech.edu (Warren Tucker)
  441. X(other anonymous persons)
  442. X
  443. Xman pages:
  444. Xjhd@irfu.se (Jan Dj{rv)
  445. X.fi
  446. SHAR_EOF
  447. # ============= unshar.1 ==============
  448. echo "x - extracting unshar.1 (Text)"
  449. sed 's/^X//' << 'SHAR_EOF' > unshar.1 &&
  450. X.TH unshar 1 local
  451. X.SH NAME
  452. Xunshar \- unpack a shar file
  453. X.SH SYNOPSIS
  454. Xunshar [ \f2\-c\f1 ] [ \f2\-C\f1 exit_line ] [ \f2\-d\f1 directory ] [ file ... ]
  455. X.SH DESCRIPTION
  456. X.PP
  457. XUnshar scans mail messages looking for the start of a shell archive. It
  458. Xthen passes the archive through a copy of the shell to unpack it. It
  459. Xwill accept multiple files. If no files are given, standard input is used.
  460. X.PP
  461. XThe \f2\-d\f1 options tells unshar to change directory before unpacking
  462. Xany files.
  463. X.PP
  464. XUnshar can unpack shar files that are concatenated in one file with the
  465. X\f2\-c\f1 option, which separates files by recognizing the "exit 0" string
  466. Xat the beginning of a line. 
  467. XThe \f2\-C\f1 option allows you to specify the string that separates archives
  468. Xif "exit 0" isn't appropriate. (Hint: most .signatures have a "\-\-" on a line
  469. Xright before them). \f2\-c\f1 is equivalent to \f2\-C "exit 0"\f1.
  470. X.SH SEE ALSO
  471. Xshar(1)
  472. X.SH DIAGNOSTICS
  473. XAny message from the shell may be displayed.
  474. X.SH AUTHORS
  475. X.nf
  476. XMichael Mauldin at Carnegie-Mellon University
  477. Xguido@mcvax (Guido van Rossum at CWI, Amsterdam)
  478. Xdavidsen@sixhub.uuxp (Bill Davidsen)
  479. Xwht%n4hgf@gatech.edu (Warren Tucker)
  480. Xrhg@CPS.COM (Richard H. Gumpertz)
  481. Xcolas@avahi.inria.fr (Colas Nahaboo)
  482. X
  483. Xman pages:
  484. Xjhd@irfu.se (Jan Dj{rv)
  485. X.fi
  486. X.PP
  487. SHAR_EOF
  488. # ============= Makefile ==============
  489. echo "x - extracting Makefile (Text)"
  490. sed 's/^X//' << 'SHAR_EOF' > Makefile &&
  491. X#  CHK=0xDDF8
  492. X#
  493. X#  makefile for shar
  494. X#
  495. X#+:EDITS:
  496. X#:05-14-1990-17:33-wht@n4hgf-add -F 5000 for XENIX 286
  497. X#:05-14-1990-17:32-bill@netagw.com-expanded Makefile
  498. X#:03-28-1990-14:54-wht@n4hgf-for 3.10, add who@where.c
  499. X
  500. XBINDIR    =/usr/local/bin
  501. XOWNER    =root
  502. XGROUP    =staff
  503. XBINMODE    =0555
  504. XMANDIR    =/usr/man/mann
  505. XMANEXT    =n
  506. XMANOWN    =root
  507. XMANGRP    =staff
  508. XMANMODE    =0444
  509. X
  510. X# For SUN, VAX, PYRAMID, SEQUENT and SCO XENIX/UNIX 386
  511. XCFLAGS    = -O 
  512. XLDFLAGS    =
  513. X
  514. X# For SCO XENIX 286
  515. X#CFLAGS    = -O 
  516. X#LDFLAGS    = -F 5000
  517. X
  518. X# For other System V systems I did not catch
  519. X#CFLAGS    = -O -DSYS5
  520. X#LDFLAGS    =
  521. X
  522. X# For other BSD-like systems
  523. X#CFLAGS    = -O -DBSD42
  524. X#LDFLAGS    =
  525. X
  526. XSHAR    = shar.o uushar.o who@where.o
  527. XUNSHAR    = unshar.o
  528. X
  529. Xall: shar unshar
  530. X
  531. Xshar: shar.o uushar.o who@where.o
  532. X    cc ${LDFLAGS} ${SHAR} -o shar
  533. X
  534. Xunshar : unshar.o
  535. X    cc ${LDFLAGS} ${UNSHAR} -o unshar
  536. X
  537. Xshar.o : shar.c
  538. X    cc ${CFLAGS} shar.c -c shar.o
  539. X
  540. Xunshar.o : unshar.c
  541. X    cc ${CFLAGS} unshar.c -c unshar.o
  542. X
  543. Xuushar.o : uushar.c
  544. X    cc ${CFLAGS} uushar.c -c uushar.o
  545. X
  546. Xwho@where.o : who@where.c
  547. X    cc ${CFLAGS} who@where.c -c who@where.o
  548. X
  549. Xinstall : shar unshar
  550. X    cp shar unshar ${BINDIR}
  551. X    strip ${BINDIR}/shar ${BINDIR}/unshar
  552. X    chown ${OWNER} ${BINDIR}/shar ${BINDIR}/unshar
  553. X    chgrp ${GROUP} ${BINDIR}/shar ${BINDIR}/unshar
  554. X    chmod ${BINMODE} ${BINDIR}/shar ${BINDIR}/unshar
  555. X    cp shar.1   ${MANDIR}/shar.${MANEXT}
  556. X    cp unshar.1 ${MANDIR}/unshar.${MANEXT}
  557. X    chown ${MANOWN}  ${MANDIR}/shar.${MANEXT} ${MANDIR}/unshar.${MANEXT}
  558. X    chgrp ${MANGRP}  ${MANDIR}/shar.${MANEXT} ${MANDIR}/unshar.${MANEXT}
  559. X    chmod ${MANMODE} ${MANDIR}/shar.${MANEXT} ${MANDIR}/unshar.${MANEXT}
  560. X
  561. Xclean :
  562. X    rm -f shar unshar *.o core
  563. SHAR_EOF
  564. # ============= shar.c ==============
  565. echo "x - extracting shar.c (Text)"
  566. sed 's/^X//' << 'SHAR_EOF' > shar.c &&
  567. Xchar *revision = "3.32";
  568. X/*
  569. X** shar.c
  570. X
  571. X  Defined functions:
  572. X    Rname(file)
  573. X    exit_incompat()
  574. X    gen_mkdir(path)
  575. X    gen_mkdir_script(path)
  576. X    setTOUCH()
  577. X    header(argc,argv)
  578. X    helpuser()
  579. X    main(argc,argv)
  580. X    mode_map(mode,mode_str)
  581. X    shar(file)
  582. X
  583. X*/
  584. X/*+:EDITS:*/
  585. X/*:07-09-1990-19:24-wht@n4hgf-back to fgrep amc -- fits more -m touches */
  586. X/*:07-01-1990-18:37-wht@n4hgf-wait() needed after fork() */
  587. X/*:05-19-1990-02:47-wht@n4hgf-change fgrep amc to mmdd */
  588. X/*:05-16-1990-01:53-wht@n4hgf-Archive-name had extra period sometimes */
  589. X/*:05-10-1990-20:39-wht@n4hgf-altos does not not like at-sign in filenames */
  590. X/*:05-10-1990-13:38-wht@n4hgf-add -V Vanilla mode */
  591. X/*:05-07-1990-00:06-wht@n4hgf-test all mallocs for Purity Of Essence */
  592. X/*:05-07-1990-00:06-wht@n4hgf-add -S switch */
  593. X/*:05-05-1990-01:37-relay.EU.net!rivm!a3-dont assume vax is running BSD */
  594. X/*:04-18-1990-02:01-wht@n4hgf-3.20 rhg@cps.com did all the NICE work */
  595. X/*:04-17-1990-14:30-rhg@cps.com-pretty up if-then-else-fi in shar file */
  596. X/*:04-17-1990-12:13-rhg@cps.com-add Split and renamed old -l to -L */
  597. X/*:04-17-1990-12:13-rhg@cps.com-add -c option to shar file execution */
  598. X/*:04-17-1990-11:20-rhg@cps.com-simplify TOUCH logic in shar file */
  599. X/*:04-17-1990-10:27-rhg@cps.com-create setTOUCH to avoid duplicate code */
  600. X/*:04-17-1990-04:43-rhg@cps.com-add missing && to commands in shar file(s) */
  601. X/*:04-17-1990-02:03-rhg@cps.com-add Compress */
  602. X/*:04-16-1990-17:08-rhg@cps.com-add AvoidPipes as well as code to use pipes */
  603. X/*:04-03-1990-20:09-wht@n4hgf-3.11 */
  604. X/*:04-01-1990-13:20-pat@rwing-correct case on M option in getopt() call */
  605. X/*:04-01-1990-13:50-pat@rwing-change defaults on -v, -w to be on */
  606. X/*:03-29-1990-18:23-wht@n4hgf-add automatic sequent support */
  607. X/*:03-28-1990-15:56-wht@n4hgf-add mode and length net.bandwidth chrome */
  608. X/*:03-28-1990-14:23-wht@n4hgf-correct some runtime diagnostics */
  609. X/*:11-14-1989-02:21-wht-SHAR_EOF was botched if last file char not newline */
  610. X/*:11-02-1989-14:11-wht-add touch -am */
  611. X
  612. X/*
  613. X Shar puts readable text files together in a package
  614. X from which they are easy to extract.
  615. X earlier attribution wht@n4hgf has:    decvax!microsof!uw-beave!jim
  616. X                                    (James Gosling at CMU)
  617. X*/
  618. X/*
  619. X *    I have made several mods to this program:
  620. X *
  621. X *    1) the -----Cut Here-----... now preceds the script.
  622. X *    2) the cat has been changed to a sed which removes a prefix
  623. X *    character from the beginning of each line of the extracted
  624. X *    file, this prefix character is added to each line of the archived
  625. X *    files and is not the same as the first character of the
  626. X *    file delimeter.
  627. X *    3) added several options:
  628. X *        -c    - add the -----Cut Here-----... line.
  629. X *        -d'del' - change the file delimeter to del.
  630. X *        -s    - cause the resulting script to print the wc of
  631. X *              the orignal file and the wc of the extracted
  632. X *              file.
  633. X *
  634. X *                Michael A. Thompson
  635. X *                Dalhousie University
  636. X *                Halifax, N.S., Canada.
  637. X */
  638. X
  639. X/*
  640. X *    I, too, have been hacking this code. This is the version on sixhub
  641. X *        bill davidsen (davidsen@sixhub.uucp)
  642. X *
  643. X *    - added support for binary files
  644. X *    - automatic creation of limited size multiple file archives,
  645. X *      each of which may be unpacked separately, and with sequence
  646. X *      checking.
  647. X *    - support for mixed text and binary files
  648. X *    - preserve file permissions
  649. X *    - restore to filename rather than pathname
  650. X *
  651. X */
  652. X/*
  653. X *  One good hack deserves another ... this version generates shell
  654. X *  code which attempts to create missing directories
  655. X *  handle deviants sun, vax, pyr (pyramid), SCO XENIX/UNIX automatically
  656. X *  for sequent, add -DBSD42
  657. X *  force Verbose on
  658. X *  if unsharing system's touch Sys V compatible (allows touch -m),
  659. X *  restore file dates
  660. X *  -n switch puts an alpha "name" in header
  661. X *  -a (if also -n) puts "Submitted-by:" & "Archive-name: <name>/part##
  662. X *  use getopt
  663. X *  as well as some other chrome-plated junque
  664. X *  ...!gatech!emory!tridom!wht (wht%n4hgf@gatech.edu) Warren Tucker
  665. X *
  666. X *  3.11 - Fri Apr  6 14:21:51 EDT 1990
  667. X *  With due deference to davidsen@sixhub, more changes..... copies
  668. X *  of this, like 3.10,  were mailed to him:
  669. X *  From wht  Fri Apr  6 15:14:30 1990 remote from n4hgf
  670. X *  Received: by n4hgf.UUCP (smail2.5-UNIX/386 5.3.2)
  671. X *      id AA01781; 6 Apr 90 15:14:30 EDT (Fri)
  672. X *  Date: Fri, 6 Apr 90 15:14:30 EDT
  673. X *  X-Mailer: Mail User's Shell (6.5 4/17/89)
  674. X *  From: wht@n4hgf (Warren Tucker)
  675. X *  To: davidsen@sixhub
  676. X *  Subject: shar 3.11
  677. X *  X-Bang-Reply-to: gatech!n4hgf!wht -or- emory!tridom!n4hgf!wht
  678. X *  Reply-to: wht%n4hgf@gatech.edu
  679. X *  Message-Id: <9004061514.AA01781@n4hgf.UUCP>
  680. X *
  681. X *  1. changes suggested by pat@rwing (Pat Myrto) and silvert@cs.dal.ca
  682. X *  (Bill Silvert)
  683. X *  2. fixes to who_am_i code in who@where.c
  684. X *
  685. X *  3.20 - Wed Apr 18 01:58:32 EDT 1990
  686. X *  changes were made per edit notes by
  687. XFrom: gatech!mailrus!uunet!cpsolv.CPS.COM!rhg (Richard H. Gumpertz)
  688. X *  ...!gatech!n4hgf!wht (wht%n4hgf@gatech.edu) Warren Tucker
  689. X *
  690. X */
  691. X
  692. X#include <stdio.h>
  693. X#include <sys/types.h>
  694. X#include <time.h>
  695. X#include <sys/stat.h>
  696. X
  697. X/* assume system v unless otherwise fixed */
  698. X#if (defined(pyr) || defined(vax) || defined(sequent)) && !defined(BSD42) && !defined(SYS5)
  699. X#define BSD42
  700. X#endif
  701. X#if defined(sun)    /* this miscreant doesn't exactly fit BSD or SYSV */
  702. X#undef BSD42
  703. X#undef SYS5
  704. X#endif
  705. X#if !defined(BSD42) && !defined(sun) && !defined(SYS5)
  706. X#define SYS5
  707. X#endif
  708. X
  709. X#if defined(sun) || defined(BSD42)
  710. X#define strchr    index
  711. X#define strrchr    rindex
  712. X#endif
  713. X
  714. Xchar *strchr();
  715. Xchar *strrchr();
  716. X#ifdef __STDC__ /* my concession to ANSI-pansiness */
  717. Xvoid *malloc();
  718. X#else
  719. Xchar *malloc();
  720. X#endif
  721. XFILE *fdopen();
  722. XFILE *popen();
  723. X
  724. X#define    DELIM        "SHAR_EOF"/* put after each file */
  725. X#define PREFIX1        'X'    /* goes in front of each line */
  726. X#define PREFIX2        'Y'    /* goes in front of each line if Delim
  727. X                         * starts with PREFIX1 */
  728. X#define PREFIX        (Delim[0] == PREFIX1 ? PREFIX2 : PREFIX1)
  729. X#define WC            "wc -c"
  730. X
  731. Xint Archive_name = 0;    /* option to generate "Archive-name:" headers */
  732. Xint Verbose = 1;        /* option to provide append/extract feedback */
  733. Xint Wc_c = 1;            /* option to provide wc checking */
  734. Xchar *Delim = DELIM;    /* pointer to delimiter string */
  735. Xint Cut = 0;            /* option to provide cut mark */
  736. Xint Binary = 0;            /* flag for binary files */
  737. Xint AvoidPipes = 0;        /* use temp file instead of pipe to feed uudecode, etc.
  738. X                           (better error detection at expense of disk space) */
  739. Xint Vanilla = 0;        /* no Brown-Shirt mode */
  740. Xint Compress = 0;        /* run input files through compress (requires Binary) */
  741. Xint Mixed = 0;            /* mixed text and binary files */
  742. Xint eXists = 0;            /* check if file exists */
  743. Xint InterOW = 0;        /* interactive overwrite */
  744. Xint PosParam = 0;        /* allow positional parameters */
  745. Xint FileStrip;            /* strip directories from filenames */
  746. X#ifdef    DEBUG
  747. Xint de_bug = 0;            /* switch for debugging on */
  748. X#define DeBug(f,v) if (de_bug) printf(f, v)
  749. X#else    /* normal compile */
  750. X#define DeBug(f,v)        /* do nothing */
  751. X#endif
  752. X
  753. XFILE *fpout = stdout;
  754. Xchar *Rname();            /* file restore name */
  755. Xunsigned limit = 0;
  756. Xint Split = 0;            /* Split files in the middle */
  757. Xlong ftell();
  758. Xlong TypePos;            /* position for archive type message */
  759. Xlong EndHeadPos;        /* position for first file in the shar file */
  760. Xchar outname[50];        /* base for output filename */
  761. Xchar filename[50];        /* actual output filename */
  762. Xchar *sharname = (char *)0;
  763. Xchar *submitter = (char *)0;
  764. Xint filenum = 0;        /* output file # */
  765. Xstruct stat fst;        /* check file type, access */
  766. X
  767. Xmain(argc,argv)
  768. Xchar **argv;
  769. X{
  770. Xint status = 0;
  771. Xint stdin_file_list = 0;
  772. Xchar *oname;
  773. Xint c;
  774. Xextern int optind;
  775. Xextern char *optarg;
  776. X
  777. X    while((c = getopt(argc,argv,"VSvwd:btCxXcfMpPas:n:l:L:o:h")) != -1)
  778. X    {
  779. X        switch(c)
  780. X        {
  781. X        case 'V':
  782. X            Vanilla = 1;
  783. X            break;
  784. X        case 'S':
  785. X            stdin_file_list = 1;
  786. X            break;
  787. X        case 'v':
  788. X            Verbose = 0;
  789. X            break;
  790. X        case 'w':
  791. X            Wc_c = 0;
  792. X            break;
  793. X        case 'd':
  794. X            Delim = optarg;
  795. X            break;
  796. X        case 'b': /* binary files */
  797. X            Binary = 1;
  798. X            Compress = 0;
  799. X            break;
  800. X        case 't': /* text mode */
  801. X            Binary = 0;
  802. X            Compress = 0;
  803. X            break;
  804. X        case 'C': /* Compress */
  805. X            Binary = 1;
  806. X            Compress = 1;
  807. X            break;
  808. X        case 'x': /* does the file exist */
  809. X            eXists = 1;
  810. X            if(InterOW || Split)
  811. X                exit_incompat();
  812. X            break;
  813. X        case 'X': /* does the file exist */
  814. X            InterOW = 1;
  815. X            if(eXists || Split)
  816. X                exit_incompat();
  817. X            eXists = 1;
  818. X            break;
  819. X        case 'c':
  820. X            Cut = 1;
  821. X            break;
  822. X        case 'f': /* filenames only */
  823. X            FileStrip = 1;
  824. X            break;
  825. X        case 'M': /* mixed text and binary */
  826. X            Mixed = 1;
  827. X            break;
  828. X        case 'p': /* allow positional parameters */
  829. X            PosParam = 1;
  830. X            break;
  831. X        case 'P': /* use temp files instead of pipes in the shar file */
  832. X            AvoidPipes = 1;
  833. X            break;
  834. X        case 'l': /* soft size limit in k */
  835. X            if((limit = atoi(optarg)) > 1)
  836. X                --limit;
  837. X            Split = 0;
  838. X            DeBug("Soft limit %dk\n",limit);
  839. X            break;
  840. X        case 'L': /* hard size limit in k */
  841. X            if(eXists)
  842. X                exit_incompat();
  843. X            if((limit = atoi(optarg)) > 1)
  844. X                --limit;
  845. X            Split = (limit != 0);
  846. X            AvoidPipes = 1;
  847. X            DeBug("Hard limit %dk\n",limit);
  848. X            break;
  849. X        case 'n': /* name of archive */
  850. X            sharname = optarg;
  851. X            break;
  852. X        case 's': /* submitter */
  853. X            submitter = optarg;
  854. X            break;
  855. X        case 'a': /* generate Archive-name: headers */
  856. X            Archive_name = 1;
  857. X            break;
  858. X        case 'o': /* specify output file */
  859. X            oname = optarg;
  860. X            strcpy(outname,oname);
  861. X            strcat(outname,".");
  862. X            filenum = 1;
  863. X            strcpy(filename,outname);
  864. X            strcat(filename,"01");
  865. X            fpout = fopen(filename,"w");
  866. X            if(!fpout)
  867. X            { /* creation error */
  868. X                perror("can't create output file");
  869. X                exit(1);
  870. X            }
  871. X            break;
  872. X#ifdef    DEBUG
  873. X        case '$': /* totally undocumented $ option, debug on */
  874. X            de_bug = 1;
  875. X            break;
  876. X#endif
  877. X        default: /* invalid option */
  878. X        case 'h': /* help */
  879. X            helpuser();
  880. X            break;
  881. X        }
  882. X    }
  883. X
  884. X    if(Vanilla)
  885. X    {
  886. X        fprintf(stderr,"Vanilla mode disabling years of progress :-)\n");
  887. X        if(Binary || Mixed || Compress || PosParam)
  888. X            fprintf(stderr,"WARNING: non-Text storage options overridden.\n");
  889. X        Wc_c = 0;
  890. X        Binary = 0;
  891. X        Compress = 0;
  892. X        InterOW = 0;
  893. X        Mixed = 0;
  894. X        PosParam = 0;
  895. X        AvoidPipes = 0;
  896. X    }
  897. X
  898. X    if(stdin_file_list)
  899. X    {
  900. X        char stdin_buf[258];
  901. X        argc = 0;
  902. X        if(!(argv = (char **)malloc(1024 * sizeof(char *))))
  903. X            goto MEMORY_ERROR;
  904. X        stdin_buf[0] = 0;
  905. X        while(fgets(stdin_buf,sizeof(stdin_buf),stdin))
  906. X        {
  907. X            if(argc == 1024)
  908. X            {
  909. X                fprintf(stderr,"max files from stdin is 1024!\n");
  910. X                exit(1);
  911. X            }
  912. X            if(stdin_buf[0])
  913. X                stdin_buf[strlen(stdin_buf) - 1] = 0;
  914. X            if(!(argv[argc] = malloc(strlen(stdin_buf) + 1)))
  915. X            {
  916. XMEMORY_ERROR: /* NOT likely, but free software must pure as snow! */
  917. X                fprintf(stderr,"out of memory handling stdin input at %d\n",
  918. X                    argc);
  919. X                exit(1);
  920. X            }
  921. X            strcpy(argv[argc],stdin_buf);
  922. X            argc++;
  923. X            stdin_buf[0] = 0;
  924. X        }
  925. X        optind = 0;
  926. X    }
  927. X
  928. X    if(optind >= argc)
  929. X    {
  930. X        fprintf(stderr,"shar: No input files\n");
  931. X        helpuser();
  932. X        exit(1);
  933. X    }
  934. X
  935. X    if(Archive_name && !sharname)
  936. X    {
  937. X        fprintf(stderr,"shar: -n must accompany -a\n");
  938. X        helpuser();
  939. X        exit(1);
  940. X    }
  941. X
  942. X    if(!submitter)
  943. X    {
  944. X        if(!(submitter = malloc(128)))
  945. X        {
  946. X            fprintf(stderr,"memory allocation failed\n"); /* NOT likely */
  947. X            exit(1);
  948. X        }
  949. X        who_where(submitter);
  950. X    }
  951. X
  952. X    if(header(argc-optind,&argv[optind]))
  953. X        exit(2);
  954. X
  955. X    if(InterOW)
  956. X    {
  957. X        Verbose = 1;
  958. X        fprintf(fpout,"wish=\n");
  959. X        if(Archive_name)
  960. X        {
  961. X            fprintf(stderr,
  962. X                "PLEASE do not submit -X shars to the usenet or other\n");
  963. X            fprintf(stderr,
  964. X                "public networks.  They will cause problems.\n");
  965. X        }
  966. X    }
  967. X
  968. X    EndHeadPos = ftell(fpout);
  969. X
  970. X    while(optind < argc)
  971. X    { /* process positional parameters and files */
  972. X        if(PosParam)
  973. X        {        /* allow -b and -t and -C inline */
  974. X            if(strcmp(argv[optind],"-b") == 0)
  975. X            { /* set binary */
  976. X                Binary = 1;
  977. X                Compress = 0;
  978. X                optind++;
  979. X                continue;
  980. X            }
  981. X            if(strcmp(argv[optind],"-t") == 0)
  982. X            { /* set mode text */
  983. X                Binary = 0;
  984. X                Compress = 0;
  985. X                optind++;
  986. X                continue;
  987. X            }
  988. X            if(strcmp(argv[optind],"-C") == 0)
  989. X            { /* set compress */
  990. X                Binary = 1;
  991. X                Compress = 1;
  992. X                optind++;
  993. X                continue;
  994. X            }
  995. X        }
  996. X        status += shar(argv[optind++]);
  997. X    }
  998. X
  999. X    /* delete the sequence file, if any */
  1000. X    if(Split && filenum > 1)
  1001. X    {
  1002. X        fputs("rm -f shar3_seq_.tmp\n",fpout);
  1003. X        fputs("echo \"You have unpacked the last part\"\n",fpout);
  1004. X        if(!Verbose)
  1005. X            fprintf(stderr,"Created %d files\n",filenum);
  1006. X    }
  1007. X    fputs("exit 0\n",fpout);
  1008. X    exit(status);
  1009. X}
  1010. X
  1011. X/*+-----------------------------------------------------------------------
  1012. X    mode_map(mode,mode_str)    build drwxrwxrwx string
  1013. X------------------------------------------------------------------------*/
  1014. Xchar *
  1015. Xmode_map(mode,mode_str)
  1016. Xunsigned short mode;
  1017. Xchar *mode_str;
  1018. X{
  1019. Xregister unsigned ftype = mode & S_IFMT;
  1020. Xregister char *rtn;
  1021. Xstatic char result[12];
  1022. X
  1023. X    rtn = (mode_str == (char *)0) ? result : mode_str;
  1024. X
  1025. X    /*          drwxrwxrwx */
  1026. X    /*          0123456789 */
  1027. X    strcpy(rtn,"----------");
  1028. X
  1029. X#ifdef THIS_IS_NOT_NEEDED_FOR_SHAR
  1030. X    switch(ftype)
  1031. X    {
  1032. X        case S_IFIFO:    *rtn = 'p'; break; /* FIFO (named pipe) */
  1033. X        case S_IFDIR:    *rtn = 'd'; break; /* directory */
  1034. X        case S_IFCHR:    *rtn = 'c'; break; /* character special */
  1035. X        case S_IFBLK:    *rtn = 'b'; break; /* block special */
  1036. X        case S_IFREG:    *rtn = '-'; break; /* regular */
  1037. X
  1038. X#if defined(sun) | defined(BSD42)
  1039. X        case S_IFLNK:    *rtn = 'l'; break; /* symbolic link */
  1040. X        case S_IFSOCK:    *rtn = 's'; break; /* socket */
  1041. X#endif
  1042. X
  1043. X#if defined (SYS5)
  1044. X        case S_IFNAM:                        /* name space entry */
  1045. X            if(mode & S_INSEM)                /* semaphore */
  1046. X            {
  1047. X                *rtn = 's';
  1048. X                break;
  1049. X            }
  1050. X            if(mode & S_INSHD)                /* shared memory */
  1051. X            {
  1052. X                *rtn = 'm';
  1053. X                break;
  1054. X            }
  1055. X#endif
  1056. X
  1057. X        default:        *rtn = '?'; break;    /* ??? */
  1058. X    }
  1059. X#endif /* THIS_IS_NOT_NEEDED_FOR_SHAR */
  1060. X
  1061. X    if(mode & 000400) *(rtn + 1) = 'r';
  1062. X    if(mode & 000200) *(rtn + 2) = 'w';
  1063. X    if(mode & 000100) *(rtn + 3) = 'x';
  1064. X    if(mode & 004000) *(rtn + 3) = 's';
  1065. X    if(mode & 000040) *(rtn + 4) = 'r';
  1066. X    if(mode & 000020) *(rtn + 5) = 'w';
  1067. X    if(mode & 000010) *(rtn + 6) = 'x';
  1068. X    if(mode & 002000) *(rtn + 6) = 's';
  1069. X    if(mode & 000004) *(rtn + 7) = 'r';
  1070. X    if(mode & 000002) *(rtn + 8) = 'w';
  1071. X    if(mode & 000001) *(rtn + 9) = 'x';
  1072. X    if(mode & 001000) *(rtn + 9) = 't';
  1073. X
  1074. X    return(rtn);
  1075. X
  1076. X}    /* end of mode_map */
  1077. X
  1078. Xvoid
  1079. XsetTOUCH()
  1080. X{
  1081. X    if(Vanilla)
  1082. X        return;
  1083. X    fputs("if touch 2>&1 | fgrep 'amc' > /dev/null\n",fpout);
  1084. X    fputs(" then TOUCH=touch\n",fpout);
  1085. X    fputs(" else TOUCH=true\n",fpout);
  1086. X    fputs("fi\n",fpout);
  1087. X} /* end of setTOUCH */
  1088. X
  1089. Xheader(argc,argv)
  1090. Xchar **argv;
  1091. X{
  1092. Xint i;
  1093. Xint status;
  1094. XFILE *fpsource;    /* pipe temp */
  1095. Xchar s128[128];
  1096. Xlong now;
  1097. Xstruct tm *utc;
  1098. Xstruct tm *gmtime();
  1099. X
  1100. X    /* see if any conflicting options */
  1101. X    if(limit && !filenum)
  1102. X    { /* can't rename what you don't have */
  1103. X        fprintf(stderr,"Can't use -l or -L option without -o\n");
  1104. X        helpuser();
  1105. X        return(1);
  1106. X    }
  1107. X
  1108. X    for(i = 0; i < argc; i++)
  1109. X    { /* skip positional parameters */
  1110. X        if(PosParam &&
  1111. X            (strcmp(argv[i],"-b") == 0 ||
  1112. X             strcmp(argv[i],"-t") == 0 ||
  1113. X             strcmp(argv[i],"-C") == 0))
  1114. X            continue;
  1115. X
  1116. X        /* see if access and correct type */
  1117. X        if(access(argv[i],4))
  1118. X        {
  1119. X            fprintf(stderr,"shar: Can't access %s\n",argv[i]);
  1120. X            return(1);
  1121. X        }
  1122. X
  1123. X        /* get file type */
  1124. X        stat(argv[i],&fst);
  1125. X        status = fst.st_mode & S_IFMT;
  1126. X
  1127. X        /* at this point I check to see that this is a regular file */
  1128. X        if(status != S_IFREG)
  1129. X        { /* this is not a regular file */
  1130. X            fprintf(stderr,"shar: %s is not a regular file\n",argv[i]);
  1131. X            return(1);
  1132. X        }
  1133. X    }
  1134. X
  1135. X    if(Archive_name)
  1136. X    {
  1137. X        fprintf(fpout,"Submitted-by: %s\n",submitter);
  1138. X        fprintf(fpout,"Archive-name: %s%s%02d\n\n",
  1139. X            sharname,(strchr(sharname,'/')) ? "" : "/part",
  1140. X            (filenum) ? filenum : 1);
  1141. X    }
  1142. X
  1143. X    if(Cut)
  1144. X        fputs("---- Cut Here and unpack ----\n",fpout);
  1145. X    fputs("#!/bin/sh\n",fpout);
  1146. X    if(sharname)
  1147. X        fprintf(fpout,"# This is %s, a shell archive (shar %s)\n",
  1148. X            sharname,revision);
  1149. X    else
  1150. X        fprintf(fpout,"# This is a shell archive (shar %s)\n",revision);
  1151. X
  1152. X    time(&now);
  1153. X    utc = gmtime(&now);
  1154. X    fprintf(fpout,"# made %02d/%02d/%04d %02d:%02d UTC ",
  1155. X        utc->tm_mon + 1,utc->tm_mday,utc->tm_year + 1900,
  1156. X        utc->tm_hour,utc->tm_min);
  1157. X
  1158. X    fputs("by ",fpout);
  1159. X    fputs(submitter,fpout);
  1160. X    fputs("\n",fpout);
  1161. X
  1162. X#if defined(SYS5)
  1163. X    if(!(fpsource = popen("/bin/pwd","r")))
  1164. X        return(-1);
  1165. X    fgets(s128,sizeof(s128),fpsource);
  1166. X    s128[strlen(s128) - 1] = 0;
  1167. X    fclose(fpsource);
  1168. X#else
  1169. X#if defined(BSD42) || defined(sun)
  1170. X    getwd(s128);
  1171. X#else
  1172. X#include "Need_conditional_compile_fix"
  1173. X#endif
  1174. X#endif
  1175. X    fprintf(fpout,"# Source directory %s\n",s128);
  1176. X
  1177. X    fprintf(fpout,"#\n# existing files %s be overwritten\n",
  1178. X        (eXists) ? "will NOT"
  1179. X                 : ((InterOW) ? "MAY" : "WILL"));
  1180. X    if(InterOW)
  1181. X        fprintf(fpout,"# The unsharer will be INTERACTIVELY queried.\n");
  1182. X
  1183. X    if(Vanilla)
  1184. X    {
  1185. X        fprintf(fpout,
  1186. X        "# This format requires very little intelligence at unshar time.\n");
  1187. X        fputs("# ",fpout);
  1188. X        if(eXists)
  1189. X            fputs("\"if test\", ",fpout);
  1190. X        fputs("\"echo\" and \"sed\" will be needed.\n",fpout);
  1191. X    }
  1192. X
  1193. X    if(Split)
  1194. X    { /* may be split, explain */
  1195. X        fputs("#\n",fpout);
  1196. X        TypePos = ftell(fpout);
  1197. X        fprintf(fpout,"%-75s\n%-75s\n","#","#");
  1198. X    }
  1199. X
  1200. X    fputs("#\n# This shar contains:\n",fpout);
  1201. X    fputs("# length  mode       name\n",fpout);
  1202. X    fputs("# ------ ---------- ------------------------------------------\n",
  1203. X        fpout);
  1204. X    for(i = 0; i < argc; i++)
  1205. X    { /* output names of files but not parameters */
  1206. X        if(PosParam &&
  1207. X            (strcmp(argv[i],"-b") == 0 ||
  1208. X             strcmp(argv[i],"-t") == 0 ||
  1209. X             strcmp(argv[i],"-C") == 0))
  1210. X            continue;
  1211. X        stat(argv[i],&fst);
  1212. X        fst.st_mode &= ~(07000); /* turn off setuid, setgid and sticky bits */
  1213. X        fprintf(fpout,"# %6ld %s %s\n",fst.st_size,
  1214. X            mode_map(fst.st_mode,(char *)0),Rname(argv[i]));
  1215. X    }
  1216. X    fputs("#\n",fpout);
  1217. X
  1218. X    setTOUCH();
  1219. X
  1220. X    if(Split)
  1221. X    { /* now check the sequence */
  1222. X        fputs("if test -r shar3_seq_.tmp; then\n",fpout);
  1223. X        fputs("\techo \"Must unpack archives in sequence!\"\n",fpout);
  1224. X        fputs("\tnext=`cat shar3_seq_.tmp`; ",fpout);
  1225. X        fputs("echo \"Please unpack part $next next\"\n\texit 1\nfi\n",fpout);
  1226. X    }
  1227. X    return(0);
  1228. X}
  1229. X
  1230. X#define MAX_MKDIR_ALREADY    128    /* ridiculously enough */
  1231. Xchar *mkdir_already[MAX_MKDIR_ALREADY];
  1232. Xint mkdir_already_count = 0;
  1233. X
  1234. Xvoid
  1235. Xgen_mkdir(path)
  1236. Xchar *path;
  1237. X{
  1238. Xregister int ialready;
  1239. Xchar *cptr;
  1240. X
  1241. X/* if already generated code for this dir creation, dont do again */
  1242. X    for(ialready = 0; ialready < mkdir_already_count; ialready++)
  1243. X    {
  1244. X        if(!strcmp(path,mkdir_already[ialready]))
  1245. X            return;
  1246. X    }
  1247. X
  1248. X/* haven't done this one */
  1249. X    if(mkdir_already_count == MAX_MKDIR_ALREADY)
  1250. X    {
  1251. X        fprintf(stderr,"too many directories for mkdir generation\n");
  1252. X        exit(255);
  1253. X    }
  1254. X    if(!(cptr = mkdir_already[mkdir_already_count++] = malloc(strlen(path)+1)))
  1255. X    {
  1256. X        fprintf(stderr,"out of memory for mkdir generation\n");
  1257. X        exit(255);
  1258. X    }
  1259. X    strcpy(cptr,path);
  1260. X
  1261. X/* generate the text */
  1262. X    fprintf(fpout,"if test ! -d '%s'; then\n",path);
  1263. X    if(Verbose)
  1264. X        fprintf(fpout,"    echo \"x - creating directory %s\"\n",path);
  1265. X    fprintf(fpout,"    mkdir '%s'\n",path);
  1266. X    fprintf(fpout,"fi\n");
  1267. X
  1268. X}    /* end of gen_mkdir */
  1269. X
  1270. Xvoid
  1271. Xgen_mkdir_script(path)
  1272. Xregister char *path;
  1273. X{
  1274. Xregister char *cptr;
  1275. X
  1276. X    for(cptr = strchr(path,'/'); cptr; cptr = strchr(cptr + 1,'/'))
  1277. X    {
  1278. X        /* avoid empty string if leading or double '/' */
  1279. X        if(cptr == path || *(cptr - 1) == '/')
  1280. X            continue;
  1281. X        /* omit '.' */
  1282. X        if((*(cptr - 1) == '.') && ((cptr == path + 1) || (*(cptr - 2) == '/')))
  1283. X            continue;
  1284. X        *cptr = 0;                /* temporarily terminate string */
  1285. X        gen_mkdir(path);
  1286. X        *cptr = '/';
  1287. X    }
  1288. X}    /* end of gen_mkdir_script */
  1289. X
  1290. Xshar(file)
  1291. Xchar *file;
  1292. X{
  1293. Xchar line[BUFSIZ];
  1294. XFILE *fpsource;
  1295. Xlong cursize,remaining,ftell();
  1296. Xint split = 0;        /* file split flag */
  1297. Xchar *filetype;        /* text or binary */
  1298. Xchar *RstrName;        /* name for restore */
  1299. Xstruct tm *lt;
  1300. Xchar *filename_base;
  1301. X
  1302. X    /* get file size, dates, and mode for later */
  1303. X    stat(file,&fst);
  1304. X
  1305. X    /* if limit set, get the current output length */
  1306. X    if(limit)
  1307. X    {
  1308. X        cursize = ftell(fpout);
  1309. X        remaining = (limit * 1024L) - cursize;
  1310. X        DeBug("In shar: remaining size %ld\n",remaining);
  1311. X        
  1312. X        if(!Split && cursize > EndHeadPos &&
  1313. X            (Binary ? fst.st_size + fst.st_size/3 : fst.st_size) > remaining)
  1314. X        { /* change to another file */
  1315. X            DeBug("Newfile, remaining %ld, ",remaining);
  1316. X            DeBug("limit still %d\n",limit);
  1317. X
  1318. X            fprintf(fpout,
  1319. X                "echo \"End of part %d, continue with part %d\"\n",
  1320. X                filenum,filenum + 1);
  1321. X            fprintf(fpout,"exit 0\n");
  1322. X
  1323. X            fclose(fpout);
  1324. X
  1325. X            /* form the next filename */
  1326. X            sprintf(filename,"%s%02d",outname,++filenum);
  1327. X            fpout = fopen(filename,"w");
  1328. X            if(Verbose)
  1329. X                fprintf(stderr,"Starting file %s\n",filename);
  1330. X            if(Archive_name)
  1331. X            {
  1332. X                fprintf(fpout,"Submitted-by: %s\n",submitter);
  1333. X                fprintf(fpout,"Archive-name: %s%s%02d\n\n",
  1334. X                    sharname,(strchr(sharname,'/')) ? "" : "/part",
  1335. X                    (filenum) ? filenum : 1);
  1336. X            }
  1337. X
  1338. X            if(Cut)
  1339. X                fputs("---- Cut Here and unpack ----\n",fpout);
  1340. X            if(!(filename_base = strrchr(filename,'/')))
  1341. X                filename_base = filename;
  1342. X            else
  1343. X                filename_base++;
  1344. X
  1345. X            fprintf(fpout,"#!/bin/sh\n");
  1346. X            fprintf(fpout,"# This is part %02d of %s\n",
  1347. X                filenum,(sharname) ? sharname : "a multipart archive");
  1348. X
  1349. X            setTOUCH();
  1350. X
  1351. X            EndHeadPos = ftell(fpout);
  1352. X        }
  1353. X    }
  1354. X
  1355. X    /* determine the name to use for restore */
  1356. X    RstrName = Rname(file);
  1357. X
  1358. X    fputs("# ============= ",fpout);
  1359. X    fputs(RstrName,fpout);
  1360. X    fputs(" ==============\n",fpout);
  1361. X
  1362. X    gen_mkdir_script(RstrName);
  1363. X
  1364. X    /* if mixed, determine the file type */
  1365. X    if(Mixed)
  1366. X    {
  1367. X        int count;
  1368. X        sprintf(line,"file %s | egrep -c \"text|shell\"",file);
  1369. X        fpsource = popen(line,"r");
  1370. X        fscanf(fpsource,"%d",&count);
  1371. X        pclose(fpsource);
  1372. X        Binary = (count != 1);
  1373. X    }
  1374. X
  1375. X    if(Binary)
  1376. X    { /* fork a uuencode process */
  1377. X        static int pid,pipex[2];
  1378. X
  1379. X        pipe(pipex);
  1380. X        fflush(fpout);
  1381. X
  1382. X        if(pid = fork())
  1383. X        { /* parent, create a file to read */
  1384. X            if(pid < 0)
  1385. X            {
  1386. X                fprintf(stderr,"could not fork!\n");
  1387. X                exit(1);
  1388. X            }
  1389. X            close(pipex[1]);
  1390. X            fpsource = fdopen(pipex[0],"r");
  1391. X            filetype = (Compress ? "Compressed" : "Binary");
  1392. X        }
  1393. X        else
  1394. X        { /* start writing the pipe with encodes */
  1395. X            FILE *outptr;
  1396. X
  1397. X            if(Compress)
  1398. X            {
  1399. X                sprintf(line, "compress -b12 < %s", file);
  1400. X                fpsource = popen(line, "r");
  1401. X            }
  1402. X            else
  1403. X                fpsource = fopen(file, "rb");
  1404. X            outptr = fdopen(pipex[1],"w");
  1405. X            fprintf(outptr,"begin 600 %s\n",
  1406. X                (Compress ? "shar3_cmp_.tmp" : RstrName));
  1407. X            encode(fpsource,outptr);
  1408. X            fprintf(outptr,"end\n");
  1409. X            if(Compress)
  1410. X                pclose(fpsource);
  1411. X            else
  1412. X            {
  1413. X                fclose(fpsource);
  1414. X            }
  1415. X            exit(0);
  1416. X        }
  1417. X    }
  1418. X    else
  1419. X    {
  1420. X        fpsource = fopen(file,"r");
  1421. X        filetype = "Text";
  1422. X    }
  1423. X
  1424. X    if(fpsource)
  1425. X    {
  1426. X        /* protect existing files */
  1427. X        if(eXists)
  1428. X        {
  1429. X            fprintf(fpout,"if test X\"$1\" != X\"-c\" -a -f '%s'; then\n",
  1430. X                RstrName);
  1431. X            if(InterOW)
  1432. X            {
  1433. X                fprintf(fpout,"\tcase $wish in\n");
  1434. X                fprintf(fpout,"\tA*|a*) echo x - overwriting '%s';;\n",
  1435. X                    RstrName);
  1436. X                fprintf(fpout,
  1437. X        "\t*) echo \"? - overwrite '%s' -- [No], [Y]es, [A]ll, [Q]uit? \"\n",
  1438. X                    RstrName);
  1439. X                fprintf(fpout,"\t\tread wish;;\n");
  1440. X                fprintf(fpout,"\tesac\n");
  1441. X                fprintf(fpout,"\tcase $wish in\n");
  1442. X                fprintf(fpout,"\tQ*|q*) echo aborted; exit 86;;\n");
  1443. X                fprintf(fpout,"\tA*|a*|Y*|y*) x=Y;;\n");
  1444. X                fprintf(fpout,"\t*) x=N;;\n");
  1445. X                fprintf(fpout,"\tesac\n");
  1446. X                fprintf(fpout,"else\n");
  1447. X                fprintf(fpout,"\tx=Y\n");
  1448. X                fprintf(fpout,"fi\n");
  1449. X                fprintf(fpout,"if test $x != Y; then\n");
  1450. X                fprintf(fpout,"\techo x - skipping '%s'\n",RstrName);
  1451. X            }
  1452. X            else
  1453. X                fprintf(fpout,"\techo \"File already exists: skipping '%s'\"\n",
  1454. X                    RstrName);
  1455. X            fprintf(fpout,"else\n");
  1456. X        }
  1457. X
  1458. X        fprintf(stderr,"shar: saving %s (%s)\n",file,filetype);
  1459. X        if(Verbose)
  1460. X        { /* info on archive and unpack */
  1461. X            fprintf(fpout,"echo \"x - extracting %s (%s)\"\n",
  1462. X                RstrName,filetype);
  1463. X        }
  1464. X        if(Binary)
  1465. X        { /* run sed through uudecode (via temp file if might get split) */
  1466. X            fprintf(fpout, "sed 's/^%c//' << '%s' %s &&\n",
  1467. X                   PREFIX,Delim,
  1468. X                (AvoidPipes ? "> shar3_tmp_.tmp" : "| uudecode"));
  1469. X        }
  1470. X        else
  1471. X        { /* just run it into the file */
  1472. X            fprintf(fpout,"sed 's/^%c//' << '%s' > %s &&\n",
  1473. X                PREFIX,Delim,RstrName);
  1474. X        }
  1475. X        while(fgets(line,BUFSIZ,fpsource))
  1476. X        { /* output a line and test the length */
  1477. X            fprintf(fpout,"%c%s",PREFIX,line);
  1478. X            if(Split && (remaining -= strlen(line) + 2) < 0)
  1479. X            { /* change to another file */
  1480. X                DeBug("Newfile, remaining %ld, ",remaining);
  1481. X                DeBug("limit still %d\n",limit);
  1482. X
  1483. X                if(line[strlen(line) - 1] != '\n')
  1484. X                    fputc('\n',fpout);
  1485. X
  1486. X                fprintf(fpout,"%s\n",Delim);
  1487. X                if(Verbose)
  1488. X                { /* output some reassurance */
  1489. X                    fprintf(fpout,
  1490. X                        "echo \"End of %s part %d\"\n",
  1491. X                            (sharname) ? sharname : "",filenum);
  1492. X                    fprintf(fpout,
  1493. X                        "echo \"File %s is continued in part %d\"\n",
  1494. X                        RstrName,filenum + 1);
  1495. X                }
  1496. X                else
  1497. X                    fprintf(fpout,
  1498. X                        "echo \"End of part %d, continue with part %d\"\n",
  1499. X                        filenum,filenum + 1);
  1500. X                fprintf(fpout,"echo \"%d\" > shar3_seq_.tmp\n",filenum + 1);
  1501. X                fprintf(fpout,"exit 0\n");
  1502. X
  1503. X                if(filenum == 1)
  1504. X                { /* rewrite the info lines on the firstheader */
  1505. X                    fseek(fpout,TypePos,0);
  1506. X                    fprintf(fpout,"%-75s\n%-75s\n",
  1507. X                        "# This is part 1 of a multipart archive",
  1508. X                        "# do not concatenate these parts, unpack them in order with /bin/sh");
  1509. X                }
  1510. X                fclose(fpout);
  1511. X
  1512. X                /* form the next filename */
  1513. X                sprintf(filename,"%s%02d",outname,++filenum);
  1514. X                fpout = fopen(filename,"w");
  1515. X
  1516. X                if(Archive_name)
  1517. X                {
  1518. X                    fprintf(fpout,"Submitted-by: %s\n",submitter);
  1519. X                    fprintf(fpout,"Archive-name: %s%s%02d\n\n",
  1520. X                        sharname,(strchr(sharname,'/')) ? "" : "/part",
  1521. X                        (filenum) ? filenum : 1);
  1522. X                }
  1523. X
  1524. X                if(Cut)
  1525. X                    fputs("---- Cut Here and unpack ----\n",fpout);
  1526. X                if(!(filename_base = strrchr(filename,'/')))
  1527. X                    filename_base = filename;
  1528. X                else
  1529. X                    filename_base++;
  1530. X
  1531. X                fprintf(fpout,"#!/bin/sh\n");
  1532. X                fprintf(fpout,
  1533. X                    "# this is %s (part %d of %s)\n",
  1534. X                    filename_base,
  1535. X                    filenum,
  1536. X                    (sharname) ? sharname : "a multipart archive");
  1537. X                fputs("# do not concatenate these parts, ",fpout);
  1538. X                fputs("unpack them in order with /bin/sh\n",fpout);
  1539. X                fprintf(fpout,"# file %s continued\n#\n",RstrName);
  1540. X
  1541. X                setTOUCH();
  1542. X                
  1543. X                fputs("if test ! -r shar3_seq_.tmp; then\n",fpout);
  1544. X                fputs("\techo \"Please unpack part 1 first!\"\n",fpout);
  1545. X                fputs("\texit 1\nfi\n",fpout);
  1546. X                fputs("(read Scheck\n",fpout);
  1547. X                fprintf(fpout,
  1548. X                      " if test \"$Scheck\" != %d; then\n",filenum);
  1549. X                fputs("\techo \"Please unpack part $Scheck next!\"\n",
  1550. X                    fpout);
  1551. X                fputs("\texit 1\n",fpout);
  1552. X                fputs(" else\n\texit 0\n fi\n",fpout);
  1553. X                fputs(") < shar3_seq_.tmp || exit 1\n",fpout);
  1554. X
  1555. X                if(Verbose)
  1556. X                { /* keep everybody informed */
  1557. X                    fprintf(stderr,"Starting file %s\n",filename);
  1558. X                    fprintf(fpout,
  1559. X                        "echo \"x - Continuing file %s\"\n",RstrName);
  1560. X                }
  1561. X                fprintf(fpout,
  1562. X                    "sed 's/^%c//' << '%s' >> %s &&\n",
  1563. X                    PREFIX,Delim,
  1564. X                    (Binary ? "shar3_tmp_.tmp" : RstrName));
  1565. X                remaining = limit * 1024L;
  1566. X                split = 1;
  1567. X            }
  1568. X        }
  1569. X
  1570. X        (void) fclose(fpsource);
  1571. X        while(wait((int *)0) >= 0)
  1572. X            ;
  1573. X
  1574. X        if(line[strlen(line) - 1] != '\n')
  1575. X            fputc('\n',fpout);
  1576. X
  1577. X        fprintf(fpout,"%s\n",Delim);
  1578. X        if(split && Verbose)
  1579. X            fprintf(fpout,
  1580. X                "echo \"File %s is complete\" &&\n",RstrName);
  1581. X
  1582. X        /* if this file was uuencoded w/Split, decode it and drop the temp */
  1583. X        if(Binary && AvoidPipes)
  1584. X        {
  1585. X            if(Verbose)
  1586. X                fprintf(fpout,"echo \"uudecoding file %s\" &&\n",RstrName);
  1587. X            fprintf(fpout,
  1588. X                "uudecode < shar3_tmp_.tmp && rm -f shar3_tmp_.tmp &&\n");
  1589. X        }
  1590. X
  1591. X        /* if this file was compressed, uncompress it and drop the temp */
  1592. X        if(Compress)
  1593. X        {
  1594. X            if(Verbose)
  1595. X                fprintf(fpout,"echo \"uncompressing file %s\" &&\n",RstrName);
  1596. X            fprintf(fpout,
  1597. X                "compress -d < shar3_cmp_.tmp > %s && rm -f shar3_cmp_.tmp &&\n",
  1598. X                RstrName);
  1599. X        }
  1600. X
  1601. X        if(!Vanilla)
  1602. X        {
  1603. X            /* set the dates as they were */
  1604. X            lt = localtime(&fst.st_mtime);
  1605. X            fprintf(fpout,"$TOUCH -am %02d%02d%02d%02d%02d %s &&\n",
  1606. X                lt->tm_mon + 1,lt->tm_mday,lt->tm_hour,lt->tm_min,
  1607. X                lt->tm_year,RstrName);
  1608. X
  1609. X            /* set the permissions as they were */
  1610. X            fprintf(fpout,"chmod %04o %s ||\n",
  1611. X                fst.st_mode & 00777,RstrName);
  1612. X
  1613. X            /* report an error if any of the above failed */
  1614. X            fprintf(fpout,"echo \"restore of %s failed\"\n",RstrName);
  1615. X
  1616. X            if(Wc_c)
  1617. X            { /* validate the transferred file */
  1618. X                FILE *pfp;
  1619. X                char command[BUFSIZ];
  1620. X
  1621. X                sprintf(command,"%s %s",WC,file);
  1622. X                if((pfp = popen(command,"r")))
  1623. X                {
  1624. X                    char wc[BUFSIZ];
  1625. X
  1626. X                    fscanf(pfp,"%s",wc);
  1627. X                    fprintf(fpout,"set `%s %s`;Wc_c=$1\n",
  1628. X                        WC,RstrName);
  1629. X                    fprintf(fpout,
  1630. X                        "if test \"$Wc_c\" != \"%s\"; then\n",wc);
  1631. X                    fprintf(fpout,
  1632. X                        "\techo original size %s, current size $Wc_c\nfi\n",
  1633. X                        wc);
  1634. X                    pclose(pfp);
  1635. X                }
  1636. X            }
  1637. X        }
  1638. X
  1639. X        /* if the exists option is in place close the if */
  1640. X        if(eXists)
  1641. X            fprintf(fpout,"fi\n");
  1642. X
  1643. X        return(0);
  1644. X    }
  1645. X    else
  1646. X    {
  1647. X        fprintf(stderr,"shar: Can't open %s (%s): ",file,filetype);
  1648. X        perror("");
  1649. X        return(1);
  1650. X    }
  1651. X}
  1652. X
  1653. Xchar *
  1654. XRname(file)
  1655. Xregister char *file;
  1656. X{
  1657. X    register char *RstrName;
  1658. X
  1659. X    if(FileStrip)
  1660. X    { /* use just the filename */
  1661. X        RstrName = file+strlen(file);
  1662. X        while(RstrName > file && *RstrName != '/')
  1663. X            RstrName--;
  1664. X        if(*RstrName == '/') RstrName++;
  1665. X    }
  1666. X    else
  1667. X        RstrName = file;
  1668. X    if(!strncmp(RstrName,"./",2))
  1669. X        RstrName += 2;
  1670. X    return(RstrName);
  1671. X}
  1672. X
  1673. X/*****************************************************************
  1674. X |  exit_incompat - incompatible options
  1675. X ****************************************************************/
  1676. X
  1677. Xexit_incompat()
  1678. X{
  1679. X       fputs("You may only specify one of -L, -X or -x\n",stderr);
  1680. X    exit(1);
  1681. X}
  1682. X
  1683. Xchar *helpinfo[] =
  1684. X{
  1685. X    "-V  produce \"vanilla\" shars demanding little of the unshar environment",
  1686. X    "-v  verbose messages OFF while executing",
  1687. X    "-w  don't check with 'wc -c' after unpack",
  1688. X    "-n  Name of archive (documentation)",
  1689. X    "-a  Generate Submitted-by: & Archive-name: headers",
  1690. X    "-s  override automatically determined submitter name",
  1691. X    "-x  don't overwrite existing files",
  1692. X    "-X  interactively overwrite existing files (NOT FOR NET SHARS)",
  1693. X    "-b  treat all files as binary, use uuencode",
  1694. X    "-t  treat all files as text (default)",
  1695. X    "-C  compress and uuencode all files",
  1696. X    "-p  allow positional parameter options. The options \"-b\" and \"-t\"",
  1697. X    "    and \"-C\" may be embedded, and files to the right of the",
  1698. X    "    option will be processed in the specified mode",
  1699. X    "-M  mixed mode. Determine if the files are text or",
  1700. X    "    binary and archive correctly.",
  1701. X    "-P  use temp files instead of pipes in the shar file",
  1702. X    "-c  start the shar with a cut line",
  1703. X    "-f  restore by filename only, rather than path",
  1704. X    "-dXXX   use XXX to delimit the files in the shar",
  1705. X    "-oXXX   (or -o XXX) output to file XXX.01 thru XXX.nn",
  1706. X    "-lXX    limit output file size to XXk bytes (but don't split files)",
  1707. X    "-LXX    limit output file size to XXk bytes (may split files)",
  1708. X    "-S      read files to wrap from stdin, ignoring argument line",
  1709. X    "\nThe -S option reads filenames one per line from stdin; input",
  1710. X    "format must be similar to 'find' output, except that if -p",
  1711. X    "is specified, -b, -t or -C may be used (on lines by themselves)",
  1712. X    "e.g., find . -type f -print | sort | shar -C -L50 -o /tmp/big",
  1713. X    "\nThe 'o' option is required if the 'l' or 'L' option is used",
  1714. X    "The 'n' option is required if the 'a' option is used",
  1715. X    "The 'x' and 'L' options are incompatible",
  1716. X    "\n-a generates sharname/part## headers. If the -a argument contains",
  1717. X    "a '/', then /patch is not appended",
  1718. X    "The automatic submitter name is trivial: essentially `whoami`@`uname`",
  1719. X    (char *)0
  1720. X};
  1721. X
  1722. Xhelpuser()
  1723. X{                /* output a command format message */
  1724. X    register char **ptr;
  1725. X    fprintf(stderr,
  1726. X        "shar %s\nusage: shar [ options ] file [ file1 ... ] ]\n",revision);
  1727. X    for(ptr = helpinfo; *ptr; ptr++)
  1728. X        fprintf(stderr,"%s\n",*ptr);
  1729. X
  1730. X    exit(1);
  1731. X}
  1732. X/* vi: set tabstop=4 shiftwidth=4: */
  1733. SHAR_EOF
  1734. echo "End of part 1, continue with part 2"
  1735. exit 0
  1736.  
  1737. --------------------------------------------------------------------
  1738. Warren Tucker, TuckerWare emory!n4hgf!wht or wht@n4hgf.Mt-Park.GA.US
  1739. Sforzando (It., sfohr-tsahn'-doh).   A direction to perform the tone
  1740. or chord with special stress, or marked and sudden emphasis.
  1741.