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

  1. From: wht@n4hgf.uucp (Warren Tucker)
  2. Newsgroups: alt.sources
  3. Subject: shar311/patch03
  4. Message-ID: <862@ixos.UUCP>
  5. Date: 19 Apr 90 11:37:27 GMT
  6.  
  7. Submitted by: wht%n4hgf@gatech.edu
  8. Archive-name: shar311/patch03
  9.  
  10. rhg@CPS.COM (Richard H. Gumpertz) added a GREAT set of new features to
  11. shar 3.11.  This posting replaces the previous README and shar.c files.
  12. The revision number is now 3.20.
  13.  
  14. The files are supplied since the diffs to shar.c were 40k and the whole
  15. file is only 28k.
  16.  
  17. If you missed the previous postings, I'll be glad to mail you a complete
  18. mailing.  Please forgive me if the snefru header fails; it's my first
  19. try and it might get out of here wrong.
  20.  
  21. Changes since 3.11: 
  22.  
  23. 1.  The -l switch still specifies a maximum size for the generated
  24.     shar files, but now it prevents files from spanning shar parts.
  25.     Shars generated using this method may be unpacked in any order.
  26.  
  27. 2.  The old -l switch functionality is precisely emulated by using the
  28.     the -L switch.  That is, archived files may be split across parts.
  29.     Shars generated using this method must still be unpacked in order.
  30.  
  31. 3.  The -C switch causes files to be compressed, then uuencoded.
  32.     Unpacking reverses the process.
  33.  
  34. 4.  The -P causes the shar to use temp files instead of pipes in
  35.     the unshar process.
  36.  
  37. 5.  The -f causes files to be restored by name only (i.e., strip
  38.     directory portion of input filenames before placing the name
  39.     into the shar.
  40.  
  41. #!/bin/sh
  42. # This is shar311/patch03, a shell archive (shar 3.20)
  43. # made 04/18/1990 06:54 UTC by wht%n4hgf@gatech.edu
  44. # Source directory /u1/src/shar
  45. #
  46. # existing files WILL be overwritten
  47. #
  48. # This shar contains:
  49. # length  mode       name
  50. # ------ ---------- ------------------------------------------
  51. #   3445 -rw-r--r-- README
  52. #  28686 -rw-r--r-- shar.c
  53. #
  54. if touch 2>&1 | fgrep '[-amc]' > /dev/null
  55.  then TOUCH=touch
  56.  else TOUCH=true
  57. fi
  58. # ============= README ==============
  59. echo "x - extracting README (Text)"
  60. sed 's/^X//' << 'SHAR_EOF' > README &&
  61. XSubmitted by: wht%n4hgf@gatech.edu
  62. XArchive-name: shar320/part01
  63. X
  64. XHere is shar 3.20, an updated version of shar 3.11, derived from 'shar2'
  65. XThis offering is the work of many people. rhg@CPS.COM (Richard H.
  66. XGumpertz) made significant changes to 3.11. They are outlined at
  67. Xthe bottom of this file.
  68. X
  69. XThis version
  70. X1) generates shell code which attempts to create missing directories
  71. X2) handle deviants sun, vax, pyramid, sequent, and SCO XENIX/UNIX
  72. X   automatically; for system V systems I did not catch, add -DSYS5
  73. X   to CFLAGS; for other BSD-like systems, add -DBSD42
  74. X3) if unsharing system's touch is Sys V compatible (allows touch -m),
  75. X   the unshar process restores file dates
  76. X4) An archive name may be specified for includion in the header
  77. X   of the shar files( -n switch)
  78. X5) allows automatic generation of "Submitted-by: who@where" &
  79. X   "Archive-name: <name>/part##" headers
  80. X6) uses getopt; no good system library should be without a copy
  81. X   but it is readily available
  82. X7) other chrome-plated junque
  83. X
  84. X------------------------ usage -----------------------------------
  85. X
  86. Xshar 3.20
  87. Xusage: shar [ options ] file [ file1 ... ] ]
  88. X-v  verbose messages OFF while executing
  89. X-w  don't check with 'wc -c' after unpack
  90. X-n  Name of archive (documentation)
  91. X-a  Generate Submitted-by: & Archive-name: headers
  92. X-s  override automatically determined submitter name
  93. X-x  don't overwrite existing files
  94. X-X  interactively overwrite existing files (NOT FOR NET SHARS)
  95. X-b  treat all files as binary, use uuencode
  96. X-t  treat all files as text (default)
  97. X-C  compress and uuencode all files
  98. X-p  allow positional parameter options. The options "-b" and "-t"
  99. X    and "-C" may be embedded, and files to the right of the
  100. X    option will be processed in the specified mode
  101. X-M  mixed mode. Determine if the files are text or
  102. X    binary and archive correctly.
  103. X-P  use temp files instead of pipes in the shar file
  104. X-c  start the shar with a cut line
  105. X-f  restore by filename only, rather than path
  106. X-dXXX   use XXX to delimit the files in the shar
  107. X-oXXX   (or -o XXX) output to file XXX.01 thru XXX.nn
  108. X-lXX    limit output file size to XXk bytes (but don't split files)
  109. X-LXX    limit output file size to XXk bytes (may split files)
  110. X
  111. XThe 'o' option is required if the 'l' or 'L' option is used
  112. XThe 'n' option is required if the 'a' option is used
  113. XThe 'x' and 'L' options are incompatible
  114. X
  115. X-a generates sharname/part## headers. If you are producing patches
  116. Xyou'll need to edit -a headers (or please improve shar :-))
  117. XThe automatic submitter name is trivial: essentially `whoami`@`uname`
  118. X
  119. X--------------------- history -----------------------------------------
  120. XChanges since 3.11: kudos to rhg@CPS.COM (Richard H. Gumpertz)
  121. X
  122. X1.  The -l switch still specifies a maximum size for the generated
  123. X    shar files, but now it prevents files from spanning shar parts.
  124. X    Shars generated using this method may be unpacked in any order.
  125. X
  126. X2.  The old -l switch functionality is precisely emulated by using the
  127. X    the -L switch.  That is, archived files may be split across parts.
  128. X    Shars generated using this method must still be unpacked in order.
  129. X
  130. X3.  The -C switch causes files to be compressed, then uuencoded.
  131. X    Unpacking reverses the process.
  132. X
  133. X4.  The -P causes the shar to use temp files instead of pipes in
  134. X    the unshar process.
  135. X
  136. X5.  The -f causes files to be restored by name only (i.e., strip
  137. X    directory portion of input filenames before placing the name
  138. X    into the shar.
  139. X
  140. X
  141. SHAR_EOF
  142. $TOUCH -am 0418025190 README &&
  143. chmod 0644 README ||
  144. echo "restore of README failed"
  145. set `wc -c README`;Wc_c=$1
  146. if test "$Wc_c" != "3445"; then
  147.     echo original size 3445, current size $Wc_c
  148. fi
  149. # ============= shar.c ==============
  150. echo "x - extracting shar.c (Text)"
  151. sed 's/^X//' << 'SHAR_EOF' > shar.c &&
  152. X/* CHK=0xE0B7 */
  153. Xchar *revision = "3.20";
  154. X/*
  155. X** shar.c
  156. X
  157. X  Defined functions:
  158. X    Rname(file)
  159. X    exit_incompat()
  160. X    gen_mkdir(path)
  161. X    gen_mkdir_script(path)
  162. X    setTOUCH()
  163. X    header(argc,argv)
  164. X    helpuser()
  165. X    main(argc,argv)
  166. X    mode_map(mode,mode_str)
  167. X    shar(file)
  168. X
  169. X*/
  170. X/*+:EDITS:*/
  171. X/*:04-18-1990-02:01-wht@n4hgf-3.20 rhg@cps.com did all the NICE work */
  172. X/*:04-17-1990-14:30-rhg@cps.com-pretty up if-then-else-fi in shar file */
  173. X/*:04-17-1990-12:13-rhg@cps.com-add Split and renamed old -l to -L */
  174. X/*:04-17-1990-12:13-rhg@cps.com-add -c option to shar file execution */
  175. X/*:04-17-1990-11:20-rhg@cps.com-simplify TOUCH logic in shar file */
  176. X/*:04-17-1990-10:27-rhg@cps.com-create setTOUCH to avoid duplicate code */
  177. X/*:04-17-1990-04:43-rhg@cps.com-add missing && to commands in shar file(s) */
  178. X/*:04-17-1990-02:03-rhg@cps.com-add Compress */
  179. X/*:04-16-1990-17:08-rhg@cps.com-add AvoidPipes as well as code to use pipes */
  180. X/*:04-03-1990-20:09-wht@n4hgf-3.11 */
  181. X/*:04-01-1990-13:20-pat@rwing-correct case on M option in getopt() call */
  182. X/*:04-01-1990-13:50-pat@rwing-change defaults on -v, -w to be on */
  183. X/*:03-29-1990-18:23-wht@n4hgf-add automatic sequent support */
  184. X/*:03-28-1990-15:56-wht@n4hgf-add mode and length net.bandwidth chrome */
  185. X/*:03-28-1990-14:23-wht@n4hgf-correct some runtime diagnostics */
  186. X/*:11-14-1989-02:21-wht-SHAR_EOF was botched if last file char not newline */
  187. X/*:11-02-1989-14:11-wht-add touch -am */
  188. X
  189. X/*
  190. X Shar puts readable text files together in a package
  191. X from which they are easy to extract.
  192. X earlier attribution wht@n4hgf has:    decvax!microsof!uw-beave!jim
  193. X                                    (James Gosling at CMU)
  194. X*/
  195. X/*
  196. X *    I have made several mods to this program:
  197. X *
  198. X *    1) the -----Cut Here-----... now preceds the script.
  199. X *    2) the cat has been changed to a sed which removes a prefix
  200. X *    character from the beginning of each line of the extracted
  201. X *    file, this prefix character is added to each line of the archived
  202. X *    files and is not the same as the first character of the
  203. X *    file delimeter.
  204. X *    3) added several options:
  205. X *        -c    - add the -----Cut Here-----... line.
  206. X *        -d'del' - change the file delimeter to del.
  207. X *        -s    - cause the resulting script to print the wc of
  208. X *              the orignal file and the wc of the extracted
  209. X *              file.
  210. X *
  211. X *                Michael A. Thompson
  212. X *                Dalhousie University
  213. X *                Halifax, N.S., Canada.
  214. X */
  215. X
  216. X/*
  217. X *    I, too, have been hacking this code. This is the version on sixhub
  218. X *        bill davidsen (davidsen@sixhub.uucp)
  219. X *
  220. X *    - added support for binary files
  221. X *    - automatic creation of limited size multiple file archives,
  222. X *      each of which may be unpacked separately, and with sequence
  223. X *      checking.
  224. X *    - support for mixed text and binary files
  225. X *    - preserve file permissions
  226. X *    - restore to filename rather than pathname
  227. X *
  228. X */
  229. X/*
  230. X *  One good hack deserves another ... this version generates shell
  231. X *  code which attempts to create missing directories
  232. X *  handle deviants sun, vax, pyr (pyramid), SCO XENIX/UNIX automatically
  233. X *  for sequent, add -DBSD42
  234. X *  force Verbose on
  235. X *  if unsharing system's touch Sys V compatible (allows touch -m),
  236. X *  restore file dates
  237. X *  -n switch puts an alpha "name" in header
  238. X *  -a (if also -n) puts "Submitted-by:" & "Archive-name: <name>/part##
  239. X *  use getopt
  240. X *  as well as some other chrome-plated junque
  241. X *  ...!gatech!emory!tridom!wht (wht%n4hgf@gatech.edu) Warren Tucker
  242. X *
  243. X *  3.11 - Fri Apr  6 14:21:51 EDT 1990
  244. X *  With due deference to davidsen@sixhub, more changes..... copies
  245. X *  of this, like 3.10,  were mailed to him:
  246. X *  From wht  Fri Apr  6 15:14:30 1990 remote from n4hgf
  247. X *  Received: by n4hgf.UUCP (smail2.5-UNIX/386 5.3.2)
  248. X *      id AA01781; 6 Apr 90 15:14:30 EDT (Fri)
  249. X *  Date: Fri, 6 Apr 90 15:14:30 EDT
  250. X *  X-Mailer: Mail User's Shell (6.5 4/17/89)
  251. X *  From: wht@n4hgf (Warren Tucker)
  252. X *  To: davidsen@sixhub
  253. X *  Subject: shar 3.11
  254. X *  X-Bang-Reply-to: gatech!n4hgf!wht -or- emory!tridom!n4hgf!wht
  255. X *  Reply-to: wht%n4hgf@gatech.edu
  256. X *  Message-Id: <9004061514.AA01781@n4hgf.UUCP>
  257. X *
  258. X *  1. changes suggested by pat@rwing (Pat Myrto) and silvert@cs.dal.ca
  259. X *  (Bill Silvert)
  260. X *  2. fixes to who_am_i code in who@where.c
  261. X *
  262. X *  3.20 - Wed Apr 18 01:58:32 EDT 1990
  263. X *  changes were made per edit notes by
  264. XFrom: gatech!mailrus!uunet!cpsolv.CPS.COM!rhg (Richard H. Gumpertz)
  265. X *  ...!gatech!n4hgf!wht (wht%n4hgf@gatech.edu) Warren Tucker
  266. X *
  267. X */
  268. X
  269. X#include <stdio.h>
  270. X#include <sys/types.h>
  271. X#include <time.h>
  272. X#include <sys/stat.h>
  273. X
  274. X/* assume system v unless otherwise fixed */
  275. X#if (defined(pyr) || defined(vax) || defined(sequent)) && !defined(BSD42)
  276. X#define BSD42
  277. X#endif
  278. X#if defined(sun)    /* this miscreant doesn't exactly fit BSD or SYSV */
  279. X#undef BSD42
  280. X#undef SYS5
  281. X#endif
  282. X#if !defined(BSD42) && !defined(sun)
  283. X#define SYS5
  284. X#endif
  285. X
  286. X#if defined(sun) || defined(BSD42)
  287. X#define strchr    index
  288. X#define strrchr    rindex
  289. X#endif
  290. X
  291. Xchar *strchr();
  292. Xchar *strrchr();
  293. X#ifdef __STDC__ /* my concession to ANSI-pansiness */
  294. Xvoid *malloc();
  295. X#else
  296. Xchar *malloc();
  297. X#endif
  298. XFILE *fdopen();
  299. XFILE *popen();
  300. X
  301. X#define    DELIM        "SHAR_EOF"/* put after each file */
  302. X#define PREFIX1        'X'    /* goes in front of each line */
  303. X#define PREFIX2        'Y'    /* goes in front of each line if Delim
  304. X                         * starts with PREFIX1 */
  305. X#define PREFIX        (Delim[0] == PREFIX1 ? PREFIX2 : PREFIX1)
  306. X#define WC            "wc -c"
  307. X
  308. Xint Archive_name = 0;    /* option to generate "Archive-name:" headers */
  309. Xint Verbose = 1;        /* option to provide append/extract feedback */
  310. Xint Wc_c = 1;            /* option to provide wc checking */
  311. Xchar *Delim = DELIM;    /* pointer to delimiter string */
  312. Xint Cut = 0;            /* option to provide cut mark */
  313. Xint Binary = 0;            /* flag for binary files */
  314. Xint AvoidPipes = 0;        /* use temp file instead of pipe to feed uudecode, etc.
  315. X                           (better error detection at expense of disk space) */
  316. Xint Compress = 0;        /* run input files through compress (requires Binary) */
  317. Xint Mixed = 0;            /* mixed text and binary files */
  318. Xint eXists = 0;            /* check if file exists */
  319. Xint InterOW = 0;        /* interactive overwrite */
  320. Xint PosParam = 0;        /* allow positional parameters */
  321. Xint FileStrip;            /* strip directories from filenames */
  322. X#ifdef    DEBUG
  323. Xint de_bug = 0;            /* switch for debugging on */
  324. X#define DeBug(f,v) if (de_bug) printf(f, v)
  325. X#else    /* normal compile */
  326. X#define DeBug(f,v)        /* do nothing */
  327. X#endif
  328. X
  329. XFILE *fpout = stdout;
  330. Xchar *Rname();            /* file restore name */
  331. Xunsigned limit = 0;
  332. Xint Split = 0;            /* Split files in the middle */
  333. Xlong ftell();
  334. Xlong TypePos;            /* position for archive type message */
  335. Xlong EndHeadPos;        /* position for first file in the shar file */
  336. Xchar outname[50];        /* base for output filename */
  337. Xchar filename[50];        /* actual output filename */
  338. Xchar *sharname = (char *)0;
  339. Xchar *submitter = (char *)0;
  340. Xint filenum = 0;        /* output file # */
  341. Xstruct stat fst;        /* check file type, access */
  342. X
  343. Xmain(argc,argv)
  344. Xchar **argv;
  345. X{
  346. Xint status = 0;
  347. Xchar *oname;
  348. Xint c;
  349. Xextern int optind;
  350. Xextern char *optarg;
  351. X
  352. X    while((c = getopt(argc,argv,"vwd:btCxXcfMpPas:n:l:L:o:h")) != -1)
  353. X    {
  354. X        switch(c)
  355. X        {
  356. X        case 'v':
  357. X            Verbose = 0;
  358. X            break;
  359. X        case 'w':
  360. X            Wc_c = 0;
  361. X            break;
  362. X        case 'd':
  363. X            Delim = optarg;
  364. X            break;
  365. X        case 'b': /* binary files */
  366. X            Binary = 1;
  367. X            Compress = 0;
  368. X            break;
  369. X        case 't': /* text mode */
  370. X            Binary = 0;
  371. X            Compress = 0;
  372. X            break;
  373. X        case 'C': /* Compress */
  374. X            Binary = 1;
  375. X            Compress = 1;
  376. X            break;
  377. X        case 'x': /* does the file exist */
  378. X            eXists = 1;
  379. X            if(InterOW || Split)
  380. X                exit_incompat();
  381. X            break;
  382. X        case 'X': /* does the file exist */
  383. X            InterOW = 1;
  384. X            if(eXists || Split)
  385. X                exit_incompat();
  386. X            eXists = 1;
  387. X            break;
  388. X        case 'c':
  389. X            Cut = 1;
  390. X            break;
  391. X        case 'f': /* filenames only */
  392. X            FileStrip = 1;
  393. X            break;
  394. X        case 'M': /* mixed text and binary */
  395. X            Mixed = 1;
  396. X            break;
  397. X        case 'p': /* allow positional parameters */
  398. X            PosParam = 1;
  399. X            break;
  400. X        case 'P': /* use temp files instead of pipes in the shar file */
  401. X            AvoidPipes = 1;
  402. X            break;
  403. X        case 'l': /* soft size limit in k */
  404. X            if((limit = atoi(optarg)) > 1)
  405. X                --limit;
  406. X            Split = 0;
  407. X            DeBug("Soft limit %dk\n",limit);
  408. X            break;
  409. X        case 'L': /* hard size limit in k */
  410. X            if(eXists)
  411. X                exit_incompat();
  412. X            if((limit = atoi(optarg)) > 1)
  413. X                --limit;
  414. X            Split = (limit != 0);
  415. X            AvoidPipes = 1;
  416. X            DeBug("Hard limit %dk\n",limit);
  417. X            break;
  418. X        case 'n': /* name of archive */
  419. X            sharname = optarg;
  420. X            break;
  421. X        case 's': /* submitter */
  422. X            submitter = optarg;
  423. X            break;
  424. X        case 'a': /* generate Archive-name: headers */
  425. X            Archive_name = 1;
  426. X            break;
  427. X        case 'o': /* specify output file */
  428. X            oname = optarg;
  429. X            strcpy(outname,oname);
  430. X            strcat(outname,".");
  431. X            filenum = 1;
  432. X            strcpy(filename,outname);
  433. X            strcat(filename,"01");
  434. X            fpout = fopen(filename,"w");
  435. X            if(!fpout)
  436. X            { /* creation error */
  437. X                perror("can't create output file");
  438. X                exit(1);
  439. X            }
  440. X            break;
  441. X#ifdef    DEBUG
  442. X        case '$': /* totally undocumented $ option, debug on */
  443. X            de_bug = 1;
  444. X            break;
  445. X#endif
  446. X        default: /* invalid option */
  447. X        case 'h': /* help */
  448. X            helpuser();
  449. X            break;
  450. X        }
  451. X    }
  452. X
  453. X    if(optind >= argc)
  454. X    {
  455. X        fprintf(stderr,"shar: No input files\n");
  456. X        helpuser();
  457. X        exit(1);
  458. X    }
  459. X
  460. X    if(Archive_name && !sharname)
  461. X    {
  462. X        fprintf(stderr,"shar: -n must accompany -a\n");
  463. X        helpuser();
  464. X        exit(1);
  465. X    }
  466. X
  467. X    if(!submitter)
  468. X    {
  469. X        submitter = malloc(128);
  470. X        who_where(submitter);
  471. X    }
  472. X
  473. X    if(header(argc-optind,&argv[optind]))
  474. X        exit(2);
  475. X
  476. X    if(InterOW)
  477. X    {
  478. X        Verbose = 1;
  479. X        fprintf(fpout,"wish=\n");
  480. X        if(Archive_name)
  481. X        {
  482. X            printf("PLEASE do not submit -X shars to the usenet or other\n");
  483. X            printf("public networks.  They will cause problems.\n");
  484. X        }
  485. X    }
  486. X
  487. X    EndHeadPos = ftell(fpout);
  488. X
  489. X    while(optind < argc)
  490. X    { /* process positional parameters and files */
  491. X        if(PosParam)
  492. X        {        /* allow -b and -t and -C inline */
  493. X            if(strcmp(argv[optind],"-b") == 0)
  494. X            { /* set binary */
  495. X                Binary = 1;
  496. X                Compress = 0;
  497. X                optind++;
  498. X                continue;
  499. X            }
  500. X            if(strcmp(argv[optind],"-t") == 0)
  501. X            { /* set mode text */
  502. X                Binary = 0;
  503. X                Compress = 0;
  504. X                optind++;
  505. X                continue;
  506. X            }
  507. X            if(strcmp(argv[optind],"-C") == 0)
  508. X            { /* set compress */
  509. X                Binary = 1;
  510. X                Compress = 1;
  511. X                optind++;
  512. X                continue;
  513. X            }
  514. X        }
  515. X        status += shar(argv[optind++]);
  516. X    }
  517. X
  518. X    /* delete the sequence file, if any */
  519. X    if(Split && filenum > 1)
  520. X    {
  521. X        fputs("rm -f @shar_seq_.tmp\n",fpout);
  522. X        fputs("echo \"You have unpacked the last part\"\n",fpout);
  523. X        if(!Verbose)
  524. X            fprintf(stderr,"Created %d files\n",filenum);
  525. X    }
  526. X    fputs("exit 0\n",fpout);
  527. X    exit(status);
  528. X}
  529. X
  530. X/*+-----------------------------------------------------------------------
  531. X    mode_map(mode,mode_str)    build drwxrwxrwx string
  532. X------------------------------------------------------------------------*/
  533. Xchar *
  534. Xmode_map(mode,mode_str)
  535. Xunsigned short mode;
  536. Xchar *mode_str;
  537. X{
  538. Xregister unsigned ftype = mode & S_IFMT;
  539. Xregister char *rtn;
  540. Xstatic char result[12];
  541. X
  542. X    rtn = (mode_str == (char *)0) ? result : mode_str;
  543. X
  544. X    /*          drwxrwxrwx */
  545. X    /*          0123456789 */
  546. X    strcpy(rtn,"----------");
  547. X
  548. X#ifdef THIS_IS_NOT_NEEDED_FOR_SHAR
  549. X    switch(ftype)
  550. X    {
  551. X        case S_IFIFO:    *rtn = 'p'; break; /* FIFO (named pipe) */
  552. X        case S_IFDIR:    *rtn = 'd'; break; /* directory */
  553. X        case S_IFCHR:    *rtn = 'c'; break; /* character special */
  554. X        case S_IFBLK:    *rtn = 'b'; break; /* block special */
  555. X        case S_IFREG:    *rtn = '-'; break; /* regular */
  556. X
  557. X#if defined(sun) | defined(BSD42)
  558. X        case S_IFLNK:    *rtn = 'l'; break; /* symbolic link */
  559. X        case S_IFSOCK:    *rtn = 's'; break; /* socket */
  560. X#endif
  561. X
  562. X#if defined (SYS5)
  563. X        case S_IFNAM:                        /* name space entry */
  564. X            if(mode & S_INSEM)                /* semaphore */
  565. X            {
  566. X                *rtn = 's';
  567. X                break;
  568. X            }
  569. X            if(mode & S_INSHD)                /* shared memory */
  570. X            {
  571. X                *rtn = 'm';
  572. X                break;
  573. X            }
  574. X#endif
  575. X
  576. X        default:        *rtn = '?'; break;    /* ??? */
  577. X    }
  578. X#endif /* THIS_IS_NOT_NEEDED_FOR_SHAR */
  579. X
  580. X    if(mode & 000400) *(rtn + 1) = 'r';
  581. X    if(mode & 000200) *(rtn + 2) = 'w';
  582. X    if(mode & 000100) *(rtn + 3) = 'x';
  583. X    if(mode & 004000) *(rtn + 3) = 's';
  584. X    if(mode & 000040) *(rtn + 4) = 'r';
  585. X    if(mode & 000020) *(rtn + 5) = 'w';
  586. X    if(mode & 000010) *(rtn + 6) = 'x';
  587. X    if(mode & 002000) *(rtn + 6) = 's';
  588. X    if(mode & 000004) *(rtn + 7) = 'r';
  589. X    if(mode & 000002) *(rtn + 8) = 'w';
  590. X    if(mode & 000001) *(rtn + 9) = 'x';
  591. X    if(mode & 001000) *(rtn + 9) = 't';
  592. X
  593. X    return(rtn);
  594. X
  595. X}    /* end of mode_map */
  596. X
  597. Xvoid
  598. XsetTOUCH()
  599. X{
  600. X    fputs("if touch 2>&1 | fgrep '[-amc]' > /dev/null\n",fpout);
  601. X    fputs(" then TOUCH=touch\n",fpout);
  602. X    fputs(" else TOUCH=true\n",fpout);
  603. X    fputs("fi\n",fpout);
  604. X} /* end of setTOUCH */
  605. X
  606. Xheader(argc,argv)
  607. Xchar **argv;
  608. X{
  609. Xint i;
  610. Xint status;
  611. XFILE *fpsource;    /* pipe temp */
  612. Xchar s128[128];
  613. Xlong now;
  614. Xstruct tm *utc;
  615. Xstruct tm *gmtime();
  616. X
  617. X    /* see if any conflicting options */
  618. X    if(limit && !filenum)
  619. X    { /* can't rename what you don't have */
  620. X        fprintf(stderr,"Can't use -l or -L option without -o\n");
  621. X        helpuser();
  622. X    }
  623. X
  624. X    for(i = 0; i < argc; i++)
  625. X    { /* skip positional parameters */
  626. X        if(PosParam &&
  627. X            (strcmp(argv[i],"-b") == 0 ||
  628. X             strcmp(argv[i],"-t") == 0 ||
  629. X             strcmp(argv[i],"-C") == 0))
  630. X            continue;
  631. X
  632. X        /* see if access and correct type */
  633. X        if(access(argv[i],4))
  634. X        {
  635. X            fprintf(stderr,"shar: Can't access %s\n",argv[i]);
  636. X            return(1);
  637. X        }
  638. X
  639. X        /* get file type */
  640. X        stat(argv[i],&fst);
  641. X        status = fst.st_mode & S_IFMT;
  642. X
  643. X        /* at this point I check to see that this is a regular file */
  644. X        if(status != S_IFREG)
  645. X        { /* this is not a regular file */
  646. X            fprintf(stderr,"shar: %s is not a regular file\n",argv[i]);
  647. X            return(1);
  648. X        }
  649. X    }
  650. X
  651. X    if(Archive_name)
  652. X    {
  653. X        fprintf(fpout,"Submitted by: %s\n",submitter);
  654. X        fprintf(fpout,"Archive-name: %s/part%02d\n\n",
  655. X            sharname,(filenum) ? filenum : 1);
  656. X    }
  657. X
  658. X    if(Cut)
  659. X        fputs("---- Cut Here and unpack ----\n",fpout);
  660. X    fputs("#!/bin/sh\n",fpout);
  661. X    if(sharname)
  662. X        fprintf(fpout,"# This is %s, a shell archive (shar %s)\n",
  663. X            sharname,revision);
  664. X    else
  665. X        fprintf(fpout,"# This is a shell archive (shar %s)\n",revision);
  666. X
  667. X    time(&now);
  668. X    utc = gmtime(&now);
  669. X    fprintf(fpout,"# made %02d/%02d/%04d %02d:%02d UTC ",
  670. X        utc->tm_mon + 1,utc->tm_mday,utc->tm_year + 1900,
  671. X        utc->tm_hour,utc->tm_min);
  672. X
  673. X    fputs("by ",fpout);
  674. X    fputs(submitter,fpout);
  675. X    fputs("\n",fpout);
  676. X
  677. X#if defined(SYS5)
  678. X    if(!(fpsource = popen("/bin/pwd","r")))
  679. X        return(-1);
  680. X    fgets(s128,sizeof(s128),fpsource);
  681. X    s128[strlen(s128) - 1] = 0;
  682. X    fclose(fpsource);
  683. X#else
  684. X#if defined(BSD42) || defined(sun)
  685. X    getwd(s128);
  686. X#else
  687. X#include "Need_conditional_compile_fix"
  688. X#endif
  689. X#endif
  690. X    fprintf(fpout,"# Source directory %s\n",s128);
  691. X
  692. X    fprintf(fpout,"#\n# existing files %s be overwritten\n",
  693. X        (eXists) ? "will NOT"
  694. X                 : ((InterOW) ? "MAY" : "WILL"));
  695. X    if(InterOW)
  696. X        fprintf(fpout,"# The unsharer will be INTERACTIVELY queried.\n");
  697. X
  698. X    if(Split)
  699. X    { /* may be split, explain */
  700. X        fputs("#\n",fpout);
  701. X        TypePos = ftell(fpout);
  702. X        fprintf(fpout,"%-75s\n%-75s\n","#","#");
  703. X    }
  704. X
  705. X    fputs("#\n# This shar contains:\n",fpout);
  706. X    fputs("# length  mode       name\n",fpout);
  707. X    fputs("# ------ ---------- ------------------------------------------\n",
  708. X        fpout);
  709. X    for(i = 0; i < argc; i++)
  710. X    { /* output names of files but not parameters */
  711. X        if(PosParam &&
  712. X            (strcmp(argv[i],"-b") == 0 ||
  713. X             strcmp(argv[i],"-t") == 0 ||
  714. X             strcmp(argv[i],"-C") == 0))
  715. X            continue;
  716. X        stat(argv[i],&fst);
  717. X        fst.st_mode &= ~(07000); /* turn off setuid, setgid and sticky bits */
  718. X        fprintf(fpout,"# %6ld %s %s\n",fst.st_size,
  719. X            mode_map(fst.st_mode,(char *)0),Rname(argv[i]));
  720. X    }
  721. X    fputs("#\n",fpout);
  722. X
  723. X    setTOUCH();
  724. X
  725. X    if(Split)
  726. X    { /* now check the sequence */
  727. X        fputs("if test -r @shar_seq_.tmp; then\n",fpout);
  728. X        fputs("\techo \"Must unpack archives in sequence!\"\n",fpout);
  729. X        fputs("\tnext=`cat @shar_seq_.tmp`; ",fpout);
  730. X        fputs("echo \"Please unpack part $next next\"\n\texit 1\nfi\n",fpout);
  731. X    }
  732. X    return(0);
  733. X}
  734. X
  735. X#define MAX_MKDIR_ALREADY    128    /* ridiculously enough */
  736. Xchar *mkdir_already[MAX_MKDIR_ALREADY];
  737. Xint mkdir_already_count = 0;
  738. X
  739. Xvoid
  740. Xgen_mkdir(path)
  741. Xchar *path;
  742. X{
  743. Xregister int ialready;
  744. Xchar *cptr;
  745. X
  746. X/* if already generated code for this dir creation, dont do again */
  747. X    for(ialready = 0; ialready < mkdir_already_count; ialready++)
  748. X    {
  749. X        if(!strcmp(path,mkdir_already[ialready]))
  750. X            return;
  751. X    }
  752. X
  753. X/* haven't done this one */
  754. X    if(mkdir_already_count == MAX_MKDIR_ALREADY)
  755. X    {
  756. X        fprintf(stderr,"too many directories for mkdir generation\n");
  757. X        exit(255);
  758. X    }
  759. X    if(!(cptr = mkdir_already[mkdir_already_count++] = malloc(strlen(path)+1)))
  760. X    {
  761. X        fprintf(stderr,"out of memory for mkdir generation\n");
  762. X        exit(255);
  763. X    }
  764. X    strcpy(cptr,path);
  765. X
  766. X/* generate the text */
  767. X    fprintf(fpout,"if test ! -d '%s'; then\n",path);
  768. X    if(Verbose)
  769. X        fprintf(fpout,"    echo \"x - creating directory %s\"\n",path);
  770. X    fprintf(fpout,"    mkdir '%s'\n",path);
  771. X    fprintf(fpout,"fi\n");
  772. X
  773. X}    /* end of gen_mkdir */
  774. X
  775. Xvoid
  776. Xgen_mkdir_script(path)
  777. Xregister char *path;
  778. X{
  779. Xregister char *cptr;
  780. X
  781. X    for(cptr = strchr(path,'/'); cptr; cptr = strchr(cptr + 1,'/'))
  782. X    {
  783. X        /* avoid empty string if leading or double '/' */
  784. X        if(cptr == path || *(cptr - 1) == '/')
  785. X            continue;
  786. X        /* omit '.' */
  787. X        if((*(cptr - 1) == '.') && ((cptr == path + 1) || (*(cptr - 2) == '/')))
  788. X            continue;
  789. X        *cptr = 0;                /* temporarily terminate string */
  790. X        gen_mkdir(path);
  791. X        *cptr = '/';
  792. X    }
  793. X}    /* end of gen_mkdir_script */
  794. X
  795. Xshar(file)
  796. Xchar *file;
  797. X{
  798. Xchar line[BUFSIZ];
  799. XFILE *fpsource;
  800. Xlong cursize,remaining,ftell();
  801. Xint split = 0;        /* file split flag */
  802. Xchar *filetype;        /* text or binary */
  803. Xchar *RstrName;        /* name for restore */
  804. Xstruct tm *lt;
  805. Xchar *filename_base;
  806. X
  807. X    /* get file size, dates, and mode for later */
  808. X    stat(file,&fst);
  809. X
  810. X    /* if limit set, get the current output length */
  811. X    if(limit)
  812. X    {
  813. X        cursize = ftell(fpout);
  814. X        remaining = (limit * 1024L) - cursize;
  815. X        DeBug("In shar: remaining size %ld\n",remaining);
  816. X        
  817. X        if(!Split && cursize > EndHeadPos &&
  818. X            (Binary ? fst.st_size + fst.st_size/3 : fst.st_size) > remaining)
  819. X        { /* change to another file */
  820. X            DeBug("Newfile, remaining %ld, ",remaining);
  821. X            DeBug("limit still %d\n",limit);
  822. X
  823. X            fprintf(fpout,
  824. X                "echo \"End of part %d, continue with part %d\"\n",
  825. X                filenum,filenum + 1);
  826. X            fprintf(fpout,"exit 0\n");
  827. X
  828. X            fclose(fpout);
  829. X
  830. X            /* form the next filename */
  831. X            sprintf(filename,"%s%02d",outname,++filenum);
  832. X            fpout = fopen(filename,"w");
  833. X
  834. X            if(Archive_name)
  835. X            {
  836. X                fprintf(fpout,"Submitted by: %s\n",submitter);
  837. X                fprintf(fpout,"Archive-name: %s/part%2d\n\n",
  838. X                    sharname,(filenum) ? filenum : 1);
  839. X            }
  840. X
  841. X            if(Cut)
  842. X                fputs("---- Cut Here and unpack ----\n",fpout);
  843. X            if(!(filename_base = strrchr(filename,'/')))
  844. X                filename_base = filename;
  845. X            else
  846. X                filename_base++;
  847. X
  848. X            fprintf(fpout,"#!/bin/sh\n");
  849. X            fprintf(fpout,
  850. X                "# this is %s (part %d of %s)\n",
  851. X                filename_base,
  852. X                filenum,
  853. X                (sharname) ? sharname : "a multipart archive");
  854. X
  855. X            setTOUCH();
  856. X
  857. X            EndHeadPos = ftell(fpout);
  858. X        }
  859. X    }
  860. X
  861. X    /* determine the name to use for restore */
  862. X    RstrName = Rname(file);
  863. X
  864. X    fputs("# ============= ",fpout);
  865. X    fputs(RstrName,fpout);
  866. X    fputs(" ==============\n",fpout);
  867. X
  868. X    gen_mkdir_script(RstrName);
  869. X
  870. X    /* if mixed, determine the file type */
  871. X    if(Mixed)
  872. X    {
  873. X        int count;
  874. X        sprintf(line,"file %s | egrep -c \"text|shell\"",file);
  875. X        fpsource = popen(line,"r");
  876. X        fscanf(fpsource,"%d",&count);
  877. X        pclose(fpsource);
  878. X        Binary = (count != 1);
  879. X    }
  880. X
  881. X    if(Binary)
  882. X    { /* fork a uuencode process */
  883. X        static int pid,pipex[2];
  884. X
  885. X        pipe(pipex);
  886. X        fflush(fpout);
  887. X
  888. X        if(pid = fork())
  889. X        { /* parent, create a file to read */
  890. X            close(pipex[1]);
  891. X            fpsource = fdopen(pipex[0],"r");
  892. X            filetype = (Compress ? "Compressed" : "Binary");
  893. X        }
  894. X        else
  895. X        { /* start writing the pipe with encodes */
  896. X            FILE *outptr;
  897. X
  898. X            if(Compress)
  899. X            {
  900. X                sprintf(line, "compress < %s", file);
  901. X                fpsource = popen(line, "r");
  902. X            }
  903. X            else
  904. X                fpsource = fopen(file, "rb");
  905. X            outptr = fdopen(pipex[1],"w");
  906. X            fprintf(outptr,"begin 600 %s\n",
  907. X                (Compress ? "@shar_cmp_.tmp" : RstrName));
  908. X            encode(fpsource,outptr);
  909. X            fprintf(outptr,"end\n");
  910. X            if(Compress)
  911. X                pclose(fpsource);
  912. X            else
  913. X                fclose(fpsource);
  914. X            exit(0);
  915. X        }
  916. X    }
  917. X    else
  918. X    {
  919. X        fpsource = fopen(file,"r");
  920. X        filetype = "Text";
  921. X    }
  922. X
  923. X    if(fpsource)
  924. X    {
  925. X        /* protect existing files */
  926. X        if(eXists)
  927. X        {
  928. X            fprintf(fpout,"if test X\"$1\" != X\"-c\" -a -f '%s'; then\n",
  929. X                RstrName);
  930. X            if(InterOW)
  931. X            {
  932. X                fprintf(fpout,"\tcase $wish in\n");
  933. X                fprintf(fpout,"\tA*|a*) echo x - overwriting '%s';;\n",
  934. X                    RstrName);
  935. X                fprintf(fpout,
  936. X        "\t*) echo \"? - overwrite '%s' -- [No], [Y]es, [A]ll, [Q]uit? \"\n",
  937. X                    RstrName);
  938. X                fprintf(fpout,"\t\tread wish;;\n");
  939. X                fprintf(fpout,"\tesac\n");
  940. X                fprintf(fpout,"\tcase $wish in\n");
  941. X                fprintf(fpout,"\tQ*|q*) echo aborted; exit 86;;\n");
  942. X                fprintf(fpout,"\tA*|a*|Y*|y*) x=Y;;\n");
  943. X                fprintf(fpout,"\t*) x=N;;\n");
  944. X                fprintf(fpout,"\tesac\n");
  945. X                fprintf(fpout,"else\n");
  946. X                fprintf(fpout,"\tx=Y\n");
  947. X                fprintf(fpout,"fi\n");
  948. X                fprintf(fpout,"if test $x != Y; then\n");
  949. X                fprintf(fpout,"\techo x - skipping '%s'\n",RstrName);
  950. X            }
  951. X            else
  952. X                fprintf(fpout,"\techo \"File already exists: skipping '%s'\"\n",
  953. X                    RstrName);
  954. X            fprintf(fpout,"else\n");
  955. X        }
  956. X
  957. X        fprintf(stderr,"shar: saving %s (%s)\n",file,filetype);
  958. X        if(Verbose)
  959. X        { /* info on archive and unpack */
  960. X            fprintf(fpout,"echo \"x - extracting %s (%s)\"\n",
  961. X                RstrName,filetype);
  962. X        }
  963. X        if(Binary)
  964. X        { /* run sed through uudecode (via temp file if might get split) */
  965. X            fprintf(fpout, "sed 's/^%c//' << '%s' %s &&\n",
  966. X                   PREFIX,Delim,
  967. X                (AvoidPipes ? "> @shar_tmp_.tmp" : "| uudecode"));
  968. X        }
  969. X        else
  970. X        { /* just run it into the file */
  971. X            fprintf(fpout,"sed 's/^%c//' << '%s' > %s &&\n",
  972. X                PREFIX,Delim,RstrName);
  973. X        }
  974. X        while(fgets(line,BUFSIZ,fpsource))
  975. X        { /* output a line and test the length */
  976. X            fprintf(fpout,"%c%s",PREFIX,line);
  977. X            if(Split && (remaining -= strlen(line) + 2) < 0)
  978. X            { /* change to another file */
  979. X                DeBug("Newfile, remaining %ld, ",remaining);
  980. X                DeBug("limit still %d\n",limit);
  981. X
  982. X                if(line[strlen(line) - 1] != '\n')
  983. X                    fputc('\n',fpout);
  984. X
  985. X                fprintf(fpout,"%s\n",Delim);
  986. X                if(Verbose)
  987. X                { /* output some reassurance */
  988. X                    fprintf(fpout,
  989. X                        "echo \"End of %s part %d\"\n",
  990. X                            (sharname) ? sharname : "",filenum);
  991. X                    fprintf(fpout,
  992. X                        "echo \"File %s is continued in part %d\"\n",
  993. X                        RstrName,filenum + 1);
  994. X                }
  995. X                else
  996. X                    fprintf(fpout,
  997. X                        "echo \"End of part %d, continue with part %d\"\n",
  998. X                        filenum,filenum + 1);
  999. X                fprintf(fpout,"echo \"%d\" > @shar_seq_.tmp\n",filenum + 1);
  1000. X                fprintf(fpout,"exit 0\n");
  1001. X
  1002. X                if(filenum == 1)
  1003. X                { /* rewrite the info lines on the firstheader */
  1004. X                    fseek(fpout,TypePos,0);
  1005. X                    fprintf(fpout,"%-75s\n%-75s\n",
  1006. X                        "# This is part 1 of a multipart archive",
  1007. X                        "# do not concatenate these parts, unpack them in order with /bin/sh");
  1008. X                }
  1009. X                fclose(fpout);
  1010. X
  1011. X                /* form the next filename */
  1012. X                sprintf(filename,"%s%02d",outname,++filenum);
  1013. X                fpout = fopen(filename,"w");
  1014. X
  1015. X                if(Archive_name)
  1016. X                {
  1017. X                    fprintf(fpout,"Submitted by: %s\n",submitter);
  1018. X                    fprintf(fpout,"Archive-name: %s/part%2d\n\n",
  1019. X                        sharname,(filenum) ? filenum : 1);
  1020. X                }
  1021. X
  1022. X                if(Cut)
  1023. X                    fputs("---- Cut Here and unpack ----\n",fpout);
  1024. X                if(!(filename_base = strrchr(filename,'/')))
  1025. X                    filename_base = filename;
  1026. X                else
  1027. X                    filename_base++;
  1028. X
  1029. X                fprintf(fpout,"#!/bin/sh\n");
  1030. X                fprintf(fpout,
  1031. X                    "# this is %s (part %d of %s)\n",
  1032. X                    filename_base,
  1033. X                    filenum,
  1034. X                    (sharname) ? sharname : "a multipart archive");
  1035. X                fputs("# do not concatenate these parts, ",fpout);
  1036. X                fputs("unpack them in order with /bin/sh\n",fpout);
  1037. X                fprintf(fpout,"# file %s continued\n#\n",RstrName);
  1038. X
  1039. X                setTOUCH();
  1040. X                
  1041. X                fputs("if test ! -r @shar_seq_.tmp; then\n",fpout);
  1042. X                fputs("\techo \"Please unpack part 1 first!\"\n",fpout);
  1043. X                fputs("\texit 1\nfi\n",fpout);
  1044. X                fputs("(read Scheck\n",fpout);
  1045. X                fprintf(fpout,
  1046. X                      " if test \"$Scheck\" != %d; then\n",filenum);
  1047. X                fputs("\techo \"Please unpack part $Scheck next!\"\n",
  1048. X                    fpout);
  1049. X                fputs("\texit 1\n",fpout);
  1050. X                fputs(" else\n\texit 0\n fi\n",fpout);
  1051. X                fputs(") < @shar_seq_.tmp || exit 1\n",fpout);
  1052. X
  1053. X                if(Verbose)
  1054. X                { /* keep everybody informed */
  1055. X                    fprintf(stderr,"Starting file %s\n",filename);
  1056. X                    fprintf(fpout,
  1057. X                        "echo \"x - Continuing file %s\"\n",RstrName);
  1058. X                }
  1059. X                fprintf(fpout,
  1060. X                    "sed 's/^%c//' << '%s' >> %s &&\n",
  1061. X                    PREFIX,Delim,
  1062. X                    (Binary ? "@shar_tmp_.tmp" : RstrName));
  1063. X                remaining = limit * 1024L;
  1064. X                split = 1;
  1065. X            }
  1066. X        }
  1067. X
  1068. X        (void) fclose(fpsource);
  1069. X
  1070. X        if(line[strlen(line) - 1] != '\n')
  1071. X            fputc('\n',fpout);
  1072. X
  1073. X        fprintf(fpout,"%s\n",Delim);
  1074. X        if(split && Verbose)
  1075. X            fprintf(fpout,
  1076. X                "echo \"File %s is complete\" &&\n",RstrName);
  1077. X
  1078. X        /* if this file was uuencoded w/Split, decode it and drop the temp */
  1079. X        if(Binary && AvoidPipes)
  1080. X        {
  1081. X            if(Verbose)
  1082. X                fprintf(fpout,"echo \"uudecoding file %s\" &&\n",RstrName);
  1083. X            fprintf(fpout,
  1084. X                "uudecode < @shar_tmp_.tmp && rm -f @shar_tmp_.tmp &&\n");
  1085. X        }
  1086. X
  1087. X        /* if this file was compressed, uncompress it and drop the temp */
  1088. X        if(Compress)
  1089. X        {
  1090. X            if(Verbose)
  1091. X                fprintf(fpout,"echo \"uncompressing file %s\" &&\n",RstrName);
  1092. X            fprintf(fpout,
  1093. X                "compress -d < @shar_cmp_.tmp > %s && rm -f @shar_cmp_.tmp &&\n",
  1094. X                RstrName);
  1095. X        }
  1096. X
  1097. X        /* set the dates as they were */
  1098. X        lt = localtime(&fst.st_mtime);
  1099. X        fprintf(fpout,"$TOUCH -am %02d%02d%02d%02d%02d %s &&\n",
  1100. X            lt->tm_mon + 1,lt->tm_mday,lt->tm_hour,lt->tm_min,lt->tm_year,
  1101. X            RstrName);
  1102. X
  1103. X        /* set the permissions as they were */
  1104. X        fprintf(fpout,"chmod %04o %s ||\n",
  1105. X            fst.st_mode & 00777,RstrName);
  1106. X
  1107. X        /* report an error if any of the above failed */
  1108. X        fprintf(fpout,"echo \"restore of %s failed\"\n",RstrName);
  1109. X
  1110. X        if(Wc_c)
  1111. X        { /* validate the transferred file */
  1112. X            FILE *pfp;
  1113. X            char command[BUFSIZ];
  1114. X
  1115. X            sprintf(command,"%s %s",WC,file);
  1116. X            if((pfp = popen(command,"r")))
  1117. X            {
  1118. X                char wc[BUFSIZ];
  1119. X
  1120. X                fscanf(pfp,"%s",wc);
  1121. X                fprintf(fpout,"set `%s %s`;Wc_c=$1\n",
  1122. X                    WC,RstrName);
  1123. X                fprintf(fpout,
  1124. X                    "if test \"$Wc_c\" != \"%s\"; then\n",wc);
  1125. X                fprintf(fpout,
  1126. X                    "\techo original size %s, current size $Wc_c\nfi\n",
  1127. X                    wc);
  1128. X                pclose(pfp);
  1129. X            }
  1130. X        }
  1131. X
  1132. X        /* if the exists option is in place close the if */
  1133. X        if(eXists)
  1134. X            fprintf(fpout,"fi\n");
  1135. X
  1136. X        return(0);
  1137. X    }
  1138. X    else
  1139. X    {
  1140. X        fprintf(stderr,"shar: Can't open %s (%s): ",file,filetype);
  1141. X        perror("");
  1142. X        return(1);
  1143. X    }
  1144. X}
  1145. X
  1146. Xchar *
  1147. XRname(file)
  1148. Xregister char *file;
  1149. X{
  1150. X    register char *RstrName;
  1151. X
  1152. X    if(FileStrip)
  1153. X    { /* use just the filename */
  1154. X        RstrName = file+strlen(file);
  1155. X        while(RstrName > file && *RstrName != '/')
  1156. X            RstrName--;
  1157. X        if(*RstrName == '/') RstrName++;
  1158. X    }
  1159. X    else
  1160. X        RstrName = file;
  1161. X    if(!strncmp(RstrName,"./",2))
  1162. X        RstrName += 2;
  1163. X    return(RstrName);
  1164. X}
  1165. X
  1166. X/*****************************************************************
  1167. X |  exit_incompat - incompatible options
  1168. X ****************************************************************/
  1169. X
  1170. Xexit_incompat()
  1171. X{
  1172. X       fputs("You may only specify one of -L, -X or -x\n",stderr);
  1173. X    exit(1);
  1174. X}
  1175. X
  1176. Xhelpuser()
  1177. X{                /* output a command format message */
  1178. X    register char **ptr;
  1179. X    static char *helpinfo[] =
  1180. X    {
  1181. X        "-v  verbose messages OFF while executing",
  1182. X        "-w  don't check with 'wc -c' after unpack",
  1183. X        "-n  Name of archive (documentation)",
  1184. X        "-a  Generate Submitted-by: & Archive-name: headers",
  1185. X        "-s  override automatically determined submitter name",
  1186. X        "-x  don't overwrite existing files",
  1187. X        "-X  interactively overwrite existing files (NOT FOR NET SHARS)",
  1188. X        "-b  treat all files as binary, use uuencode",
  1189. X        "-t  treat all files as text (default)",
  1190. X        "-C  compress and uuencode all files",
  1191. X        "-p  allow positional parameter options. The options \"-b\" and \"-t\"",
  1192. X        "    and \"-C\" may be embedded, and files to the right of the",
  1193. X        "    option will be processed in the specified mode",
  1194. X        "-M  mixed mode. Determine if the files are text or",
  1195. X        "    binary and archive correctly.",
  1196. X        "-P  use temp files instead of pipes in the shar file",
  1197. X#ifdef THIS_APPEARS_TO_BE_OBSOLETE
  1198. X        "-D  output date, user, and directory comments to the archive",
  1199. X#endif /* THIS_APPEARS_TO_BE_OBSOLETE */
  1200. X        "-c  start the shar with a cut line",
  1201. X        "-f  restore by filename only, rather than path",
  1202. X        "-dXXX   use XXX to delimit the files in the shar",
  1203. X        "-oXXX   (or -o XXX) output to file XXX.01 thru XXX.nn",
  1204. X        "-lXX    limit output file size to XXk bytes (but don't split files)",
  1205. X        "-LXX    limit output file size to XXk bytes (may split files)",
  1206. X        "\nThe 'o' option is required if the 'l' or 'L' option is used",
  1207. X        "The 'n' option is required if the 'a' option is used",
  1208. X        "The 'x' and 'L' options are incompatible",
  1209. X        "\n-a generates sharname/part## headers. If you are producing patches",
  1210. X        "you'll need to edit -a headers (or please improve shar :-))",
  1211. X        "The automatic submitter name is trivial: essentially `whoami`@`uname`",
  1212. X        (char *)0
  1213. X    };
  1214. X    fprintf(stderr,
  1215. X        "shar %s\nusage: shar [ options ] file [ file1 ... ] ]\n",revision);
  1216. X    for(ptr = helpinfo; *ptr; ptr++)
  1217. X        fprintf(stderr,"%s\n",*ptr);
  1218. X
  1219. X    exit(1);
  1220. X}
  1221. X/* vi: set tabstop=4 shiftwidth=4: */
  1222. SHAR_EOF
  1223. $TOUCH -am 0418021390 shar.c &&
  1224. chmod 0644 shar.c ||
  1225. echo "restore of shar.c failed"
  1226. set `wc -c shar.c`;Wc_c=$1
  1227. if test "$Wc_c" != "28686"; then
  1228.     echo original size 28686, current size $Wc_c
  1229. fi
  1230. exit 0
  1231.  
  1232. ------------------------------------------------------------------
  1233. Warren Tucker, TuckerWare gatech!n4hgf!wht or wht%n4hgf@gatech.edu
  1234. McCarthyism did to cinema what ANSI did to C,  cast a great number
  1235. of characters into the void.
  1236.