home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 3 / 3614 < prev    next >
Encoding:
Internet Message Format  |  1991-07-11  |  27.3 KB

  1. From: dhesi@bsu-cs.bsu.edu (Rahul Dhesi)
  2. Newsgroups: alt.sources
  3. Subject: zoo 2.1 source part 11/15
  4. Message-ID: <12778@bsu-cs.bsu.edu>
  5. Date: 10 Jul 91 11:05:04 GMT
  6.  
  7. Checksum:  317039834 (verify with "brik -cv")
  8. Submitted-by: dhesi@bsu-cs.bsu.edu
  9. Archive-name: zoo210/part11
  10.  
  11. ---- Cut Here and feed the following to sh ----
  12. #!/bin/sh
  13. # This is part 11 of zoo210
  14. # ============= zoo.c ==============
  15. if test -f 'zoo.c' -a X"$1" != X"-c"; then
  16.     echo 'x - skipping zoo.c (File already exists)'
  17. else
  18. echo 'x - extracting zoo.c (Text)'
  19. sed 's/^X//' << 'SHAR_EOF' > 'zoo.c' &&
  20. #ifndef LINT
  21. /* derived from: zoo.c 2.24 88/01/29 00:55:09 */
  22. static char sccsid[]="$Id: zoo.c,v 1.21 91/07/09 02:36:40 dhesi Exp $";
  23. #endif /* LINT */
  24. X
  25. #if 0
  26. #define TRACEI(item)    printf("line %d: %s= %d\n", __LINE__, #item, item)
  27. #define TRACES(item)    printf("line %d: %s= [%s]\n", __LINE__, #item, item)
  28. #endif
  29. X
  30. extern char version[];
  31. X
  32. /*
  33. Copyright (C) 1986, 1987 Rahul Dhesi -- All rights reserved
  34. (C) Copyright 1988 Rahul Dhesi -- All rights reserved
  35. (C) Copyright 1991 Rahul Dhesi -- All rights reserved
  36. */
  37. #include "options.h"
  38. #include "zooio.h"
  39. #include "various.h"
  40. X
  41. #include "zoo.h"
  42. #include "zoofns.h"
  43. X
  44. #include "errors.i"
  45. #include "zoomem.h"
  46. X
  47. static void ms_help();
  48. static void wait_return();
  49. X
  50. #ifdef TRACE_IO
  51. int verbose = 0;
  52. #endif
  53. X
  54. int instr PARMS ((char *, char *));
  55. X
  56. char *out_buf_adr;      /* points to memory allocated for output buffer(s) */
  57. char *in_buf_adr;       /* points to memory allocated for input buffer */
  58. X
  59. /* static declarations */
  60. int quiet = 0;             /* whether to be quiet */
  61. int next_arg = FIRST_ARG; /* filenames start at this position */
  62. int arg_count;          /* count of arguments supplied to program */
  63. char **arg_vector;      /* vector of arguments supplied to program */
  64. X
  65. main(argc,argv)
  66. register int argc;
  67. register char **argv;
  68. {
  69. X   char *zooname;          /* synonym for argv[2] -- to make life easier */
  70. #ifndef OOZ
  71. X   static char incorrect_args[] = "Incorrect number of arguments.\n";
  72. X   int filecount;          /* how many filespecs supplied */
  73. #endif /* OOZ */
  74. X
  75. #ifdef OOZ
  76. #else
  77. /* else not OOZ */
  78. X      static char usage[] = "Usage: zoo {acDeglLPTuUvx}[aAcCdEfInmMNoOpPqu1:/.@n] archive file\n(\"zoo h\" for help, \"zoo H\" for extended help)\n";
  79. X      static char nov_usage[] =
  80. X          "\nNovice usage:  zoo -cmd archive[.zoo] file...  where -cmd is one of these:\n";
  81. X      char *option;
  82. X
  83. X      static char nov_cmds[] =
  84. X         /* ADD=0EXT=5    MOV=14TES=20PRI=26 DEL=33  LIS=41UPD=47  FRE=55   COMMENT=64 */
  85. X           "-add -extract -move -test -print -delete -list -update -freshen -comment\n";
  86. X
  87. #ifdef NOENUM
  88. #define NONE   -1
  89. #define ADD    0
  90. #define EXTRACT 5
  91. #define MOVE   14
  92. #define TEST   20
  93. #define PRINT  26
  94. #define DELETE 33
  95. #define LIST   41
  96. #define UPDATE 47
  97. #define FRESHEN   55
  98. #define COMMENT   64
  99. X
  100. int cmd = NONE;
  101. X
  102. #else
  103. X   enum choice {
  104. X      NONE = -1, ADD = 0, EXTRACT = 5, MOVE = 14, TEST = 20, PRINT = 26,
  105. X      DELETE = 33, LIST = 41, UPDATE = 47, FRESHEN = 55, COMMENT = 64
  106. X   };
  107. X   enum choice cmd = NONE;          /* assume no Novice command */
  108. #endif
  109. X
  110. #endif /* end of not OOZ */
  111. X
  112. #ifdef SPECINIT
  113. X    void spec_init PARMS ((void));
  114. X    spec_init();                            /* system-specific startup code */
  115. #endif
  116. X
  117. X    /* make sure T_UINT16 is an unsigned 16-bit type, exactly.  This
  118. X        code is included only if T_UINT16 was defined by default at the
  119. X        end of options.h. */
  120. #ifdef CHECK_TUINT
  121. X    {
  122. X        T_UINT16 i;
  123. X        int status = 0;
  124. X        i = ((unsigned) 1) << 15;
  125. X        if (i < 0)
  126. X            status = 1;
  127. X        if (i != ((unsigned) 1) << 15)
  128. X            status = 1;
  129. X        i *= 2;
  130. X        if (i != 0)
  131. X            status = 1;
  132. X        if (status != 0)
  133. X            prterror('w', "Configuration problem: T_UINT16 is not 16 bits\n");
  134. X    }
  135. #endif
  136. X
  137. X   arg_count = argc;
  138. X   arg_vector = argv;
  139. X   zooname = argv[FIRST_ARG-1];     /* points to name or archive */
  140. X
  141. #ifdef OOZ
  142. X   if (argc < 2) {
  143. X      putstr (usage1);
  144. X      putstr (usage2);
  145. X      zooexit (1);
  146. X   }
  147. #else
  148. /* else not OOZ */
  149. X   if (argc < 2)
  150. X      goto show_usage;
  151. X   filecount = argc - 3;
  152. X   option = str_dup(argv[1]);
  153. X
  154. #ifdef TRACE_IO
  155. X   if (*option == ':') {         /* for debugging output */
  156. X      verbose++;
  157. X      option++;                  /* hide the : from other functions */
  158. X   }
  159. #endif
  160. X
  161. #ifdef WAIT_PROMPT
  162. X   if (*option == 'w') {
  163. X        option++;                        /* hide w from other functions */
  164. X        wait_return();
  165. X    }
  166. #endif /* WAIT_PROMPT */
  167. X
  168. X   if (*option == 'H') ms_help(option);
  169. X   if (*option == 'h' || *option == 'H')
  170. X      goto bigusage;
  171. X    if (strchr("-acDegflLPTuUvVx", *option) == NULL)
  172. X        goto give_list;
  173. X
  174. X   if (*option == '-') {
  175. X
  176. #ifdef NOENUM
  177. X      cmd = instr (nov_cmds, str_lwr(option));
  178. #else
  179. X      cmd = (enum choice) instr (nov_cmds, str_lwr(option));
  180. #endif
  181. X
  182. X      if (strlen(option) < 2 || cmd == NONE)
  183. X         goto show_usage;
  184. X      if (  ((cmd == ADD || cmd == MOVE || cmd == FRESHEN ||
  185. X                  cmd == UPDATE || cmd == DELETE) && argc < 4) ||
  186. X            ((cmd == EXTRACT || cmd == TEST || cmd == LIST ||
  187. X                     cmd == PRINT || cmd == COMMENT) && argc < 3)) {
  188. X         fprintf (stderr, incorrect_args);
  189. X         goto show_usage;
  190. X      }
  191. X   } else {
  192. X        char *wheresI;        /* will be null if I option not supplied */
  193. X        if    (
  194. X                (
  195. X                    strchr("au",*option) &&
  196. X                    (
  197. X                        (((wheresI = strchr(option,'I')) != 0) &&
  198. X                            argc != 3) ||
  199. X                        wheresI==NULL && argc < 4
  200. X                    )
  201. X                ) ||
  202. X                 strchr("DU",*option) && argc < 4 ||
  203. X             strchr("cexlvVL",*option) && argc < 3 ||
  204. X             strchr("TP",*option)   && argc != 3 ||
  205. X                 (*option == 'f' && argc != 2) ||
  206. X                 (*option == 'g' &&
  207. X                    (strchr(option,'A') == NULL && argc < 4 ||
  208. X                     strchr(option,'A') != NULL && argc != 3
  209. X                    )
  210. X                 )
  211. X            ) {
  212. X         fprintf (stderr, incorrect_args);
  213. X         goto show_usage;
  214. X      }
  215. X   }
  216. #endif /* end of not OOZ */
  217. X
  218. #ifndef OOZ
  219. X   /* if not doing a list and no extension in archive name, add default
  220. X   extension */
  221. X   if (*option != 'f' && cmd != LIST && strchr("lvVL", *option) == NULL &&
  222. X         strchr(nameptr (zooname), EXT_CH) == NULL)
  223. X      zooname = newcat (zooname, EXT_DFLT);
  224. #endif
  225. X
  226. /*
  227. Here we allocate a large block of memory for the duration of the program.
  228. lzc() and lzd() will use half of it each.  Routine getfile() will use all
  229. of it.  Routine decode() will use the first 8192 bytes of it.  Routine
  230. encode() will use all of it. */
  231. X
  232. /*                          fudge/2           fudge/2
  233. **             [______________||________________|]
  234. **               output buffer    input buffer
  235. */
  236. X   out_buf_adr = ealloc (MEM_BLOCK_SIZE);
  237. X   in_buf_adr = out_buf_adr + OUT_BUF_SIZE + (FUDGE/2);
  238. X
  239. #ifdef OOZ
  240. zooext(zooname, "\0");     /* just extract -- no fancy stuff   */
  241. zooexit (0);                  /* and exit normally                */
  242. #else
  243. /* else not OOZ -- parse command line and invoke a routine */
  244. X   if (cmd != NONE) {
  245. X      switch (cmd) {
  246. X
  247. X         case ADD:      zooadd (zooname, filecount, &argv[3], "aP:"); break;
  248. X         case FRESHEN:  zooadd (zooname, filecount, &argv[3], "auP:"); break;
  249. X         case UPDATE:   zooadd (zooname, filecount, &argv[3], "aunP:"); break;
  250. X         case MOVE:     zooadd (zooname, filecount, &argv[3], "aMP:"); break;
  251. X
  252. X         case EXTRACT:  zooext (zooname, "x"); break;
  253. X         case TEST:     zooext (zooname, "xNd"); break;
  254. X         case PRINT:    zooext (zooname, "xp"); break;
  255. X
  256. X         case DELETE:   zoodel (zooname, "DP",1); break;
  257. X         case LIST:     zoolist (&argv[2], "VC", argc-2); break;
  258. X         case COMMENT:  comment (zooname, "c"); break;
  259. X         default: goto show_usage;
  260. X      }
  261. X   } else
  262. X      switch (*option) {
  263. X
  264. X         case 'a':
  265. X         case 'u':
  266. X         case 'T':   
  267. X            zooadd (zooname, filecount, &argv[3], option); break;
  268. #ifdef FILTER
  269. X            case 'f':
  270. X                zoofilt (option);  break;
  271. #endif /* FILTER */
  272. X         case 'D':
  273. X            zoodel (zooname, option, 1); break;
  274. X         case 'U':
  275. X            zoodel (zooname, option, 0); break;
  276. X            case 'g':
  277. X                zoodel (zooname, option, 2); break;
  278. X         case 'v':
  279. X            case 'V':
  280. X         case 'l': 
  281. X            zoolist(&argv[2], option, 1); break;
  282. X         case 'L': 
  283. X            zoolist(&argv[2], option, argc-2); break;
  284. X         case 'e':
  285. X         case 'x': 
  286. X            zooext(zooname, option); break;
  287. X         case 'P':
  288. X            zoopack (zooname, option); break;
  289. X         case 'c':
  290. X            comment (zooname, option); break;
  291. X         default:
  292. X            goto give_list;
  293. X      }
  294. zooexit (0);      /* don't fall through */
  295. X
  296. /* usage list including Novice commands */
  297. show_usage:
  298. X   fprintf (stderr, "%s\n\n%s%s%s", version, usage, nov_usage, nov_cmds);
  299. X    zooexit (1);
  300. X
  301. /* brief usage list */
  302. give_list:
  303. X    fprintf (stderr, usage); zooexit (1);
  304. X
  305. /* help screen */
  306. bigusage:
  307. printf("\n\n\n\n\n\n\n\n");
  308. printf ("Zoo archiver, %s\n", version);
  309. printf("(C) Copyright 1991 Rahul Dhesi -- Noncommercial use permitted\n");
  310. X
  311. printf (usage);
  312. printf ("\nChoose a command from within {} and zero or more modifiers from within [].\n");
  313. X
  314. printf ("E.g.:  `zoo a save /bin/*' will archive all files in /bin into save.zoo.\n");
  315. printf ("(Please see the user manual for a complete description of commands.)\n\n");
  316. printf (nov_usage);
  317. printf (nov_cmds);
  318. printf ("\n\n\n\n");
  319. wait_return();    /* print msg & wait for RETURN */
  320. X
  321. printf ("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
  322. printf (usage);
  323. X
  324. printf (" Commands in {} mean:         |Modifiers in [] mean:\n");
  325. X
  326. printf ("  a     add files             | a     show archive name(s) in listing\n");
  327. printf ("  c     update comments       | A     apply g or c to archive\n");
  328. printf ("  D     delete stored files   | c     add/list comments\n");
  329. printf ("  e,x   extract files         | d     extract/list deleted files too\n");
  330. printf ("  g     adj. gen. limit/count | dd    extract/list only deleted files\n");
  331. printf ("  l,L,v,V list filenames      | E     erase backup after packing\n");
  332. printf ("  P     pack archive          | f     fast add (no compression) or list\n");
  333. printf ("  T     fix archive datestamp | M     move when adding (erase original)\n");
  334. printf ("  u     add only newer files  | n     add only files not already in archive\n");
  335. printf ("  U     undelete stored files | N     send extracted data to Nowhere\n");
  336. #ifdef FILTER
  337. printf ("  f     act as filter         | c/u   compress/uncompress as filter\n");
  338. #endif /* FILTER */
  339. printf (" -----------------------------  O     don't ask \"Overwrite?\"\n");
  340. printf ("  q     be quiet                p     pipe extracted data to standard output\n");
  341. printf ("  :     don't store dir names   /,//  extract full pathnames\n");
  342. printf ("  .     pack to current dir     I     add filenames read from stdin\n");
  343. printf ("  C     show file CRC value     +/-   enable/disable generations\n");
  344. printf ("  S     overwrite newer files   g     list generation limits\n");
  345. printf ("  P     pack after adding       @n    start extract/list at position n\n");
  346. X
  347. #ifdef FATTR
  348. printf ("  m     list file modes         OO    overwrite read-only files\n");
  349. #endif /* FATTR */
  350. printf ("  C     change archive cmnt     h     use high-compression method\n");
  351. #endif /* end of not OOZ */
  352. X
  353. /* NOTE:  if allowed to fall through and return without an exit() statement,
  354. X   it was printing garbage--corrupted stack?  Why--bug in Microsoft C? */
  355. zooexit (1);
  356. return 1;    /* keep lint & compilers happy */
  357. }
  358. X
  359. /* multi-screen help facility thanks to Bill Davidsen */
  360. X
  361. /* help screens */
  362. static char *scrn1[] = {
  363. X   "",
  364. X    "command line format:",
  365. X    "  zoo {command}[options] archive files(s)",
  366. X    "",
  367. X    "Commands:",
  368. X    " a  add files",
  369. X    "    u - update, replace only if file is newer than saved version",
  370. X    "    n - new, add if file is not in archive",
  371. X    "    f - fast, don't compress at all",
  372. X    "    h - high performance compressor, slower than default",
  373. X    "    M - move files to archive, delete after saving",
  374. X    "    c - add a comment to each file added",
  375. X    "    C - add a comment to the archive as a whole",
  376. X    "    : - strip directory names, save filenames only",
  377. X    "    q - quiet (qq suppresses warnings, qqq suppresses nonfatal errors too)",
  378. X    "    P - pack after adding, remove overwritten or deleted files",
  379. X    "        (leaves a .bak file, use PP to overwrite it)",
  380. X    "    I - read filenames from standard input",
  381. X    "    + - enable generations",
  382. X    (char *)NULL
  383. };
  384. X
  385. static char *scrn2[] = {
  386. X   "",
  387. X    " e  extract files",
  388. X    " x  extract files",
  389. X    "    : - extract to current directory (ignore pathnames)",
  390. X   "    . - make absolute pathnames relative to current directory",
  391. X    "        (name /etc/hosts becomes ./etc/hosts)",
  392. X    "    / - extract to subdirs, // create subdirs as needed - default",
  393. X    "        (the sequence :/ may be used to use but not create subdirs)",
  394. X    "    q - quiet",
  395. X    "    d - extract deleted files, too. dd extract *only* deleted files",
  396. X    "    N - extract to nowhere. Used to test the archive with xN or xNq",
  397. X    "    p - extract for pipe to standard output. Use q to avoid header",
  398. X    "",
  399. #ifdef FATTR
  400. X    "    O - overwrite without asking, OO overwrites readonly files",
  401. #else
  402. X    "    O - overwrite without asking",
  403. #endif
  404. X    "    S - overwrite superceded (newer) files",
  405. X    (char *)NULL
  406. };
  407. X
  408. static char *scrn3[] = {
  409. X   "",
  410. X    " l  list archive info",
  411. X    " L  list info for multiple archives",
  412. X    " v  list verbose file info and archive comment",
  413. X    " V  list verbose file info, archive and file comments",
  414. X    "    v - verbose (same as v command, used with L for multiple files",
  415. X    "    V - verbose with file comments",
  416. X    "    C - show CRC",
  417. X    "    a - show archive name in file listing (useful with L)",
  418. #ifdef FATTR
  419. X    "    m - mode, show file modes in octal",
  420. #endif
  421. X    "    d - show deleted files",
  422. X    "    q - quiet, shows only file info, no comments or headers",
  423. X    "    f - fast, lists only filename, no pathname, multiple columns",
  424. X    "    1 - one column output (for the f option)",
  425. X    "",
  426. X    " c  comment changes, change or add comments to listed files",
  427. X    "    (changes all file comments if no files given)",
  428. X    "    A - only change archive comment",
  429. X    (char *)NULL
  430. };
  431. X
  432. static char *scrn4[] = {
  433. X   "",
  434. X    " P  pack archive, remove deleted or overwritten files",
  435. X    "    E - erase the .bak file when done",
  436. X    "",
  437. X    " D  delete files by name",
  438. X    "    P - pack after deletion, use PP if .bak file exists",
  439. X    "    q - quiet",
  440. X    "",
  441. X    " T  timestamp adjust, make archive age of newest file",
  442. X    "",
  443. X    " g  generation commands",
  444. X    "    l - set generation limit on files",
  445. X    "    A - apply limit to archive rather than a file (with gl)",
  446. X    "",
  447. X    " f  filter, copy stdin to stdout with [de]compression",
  448. X    "    c - compress",
  449. X    "    u - uncompress",
  450. X    "    h - use the high compression method",
  451. X    (char *)NULL
  452. };
  453. X
  454. static char *scrn5[] = {
  455. X   "",
  456. X    "Examples:",
  457. X    "",
  458. X    "# just add a few files",
  459. X    "    zoo a arch file1 files",
  460. X    "# add C source files in subdirectories",
  461. X    "    zoo a test part1/*.c part2/*.c",
  462. X    "# add documentation files with high compression",
  463. X    "    zoo ah test *.doc",
  464. X    "",
  465. X    "# extract all files",
  466. X    "    zoo x test",
  467. X    "# extract files into the current directory",
  468. X    "    zoo x: test",
  469. X    "# extract a single file and sort before listing",
  470. X    "    zoo xp test users.lst | sort",
  471. X    "",
  472. X    "# list the contents and archive comments",
  473. X    "    zoo v arch",
  474. X    "# list all files in all archives",
  475. X    "    zoo L xxx.zoo /doc/*.zoo ../*.zoo",
  476. X    (char *)NULL
  477. };
  478. X
  479. static char **screens[] = {
  480. X    scrn1,        /* intro and add */
  481. X    scrn2,        /* extract */
  482. X    scrn3,        /* list commands */
  483. X    scrn4,        /* other commands */
  484. X    scrn5,        /* add and extract examples */
  485. X    (char **)NULL
  486. };
  487. X
  488. /* multi-screen help routine */
  489. static void ms_help(options)
  490. char *options;
  491. {
  492. #ifndef SZ_SCREEN            /* screen size can be overridden in options.h */
  493. # define SZ_SCREEN 24
  494. #endif
  495. X    int scrnlen = SZ_SCREEN;
  496. X    char ***curscreen, **curline;
  497. X    int linecount;
  498. X
  499. X    /* if "Hnn" output in nn line format */
  500. X    if (++options) sscanf(options, "%d", &scrnlen);
  501. X    if (scrnlen < 2)
  502. X        scrnlen = SZ_SCREEN;
  503. X
  504. X    /* loop thru screens */
  505. X    for (curscreen = screens; *curscreen != NULL; ++curscreen) {
  506. X        printf("\n\n\n\n");
  507. X        linecount = scrnlen;
  508. X        curline = *curscreen;
  509. X        while (*curline != NULL) {
  510. X            printf("%s\n", *(curline++));
  511. X            --linecount;
  512. X        }
  513. X
  514. X        /* slew page */
  515. X        while (--linecount != 0) putchar('\n');
  516. X        wait_return();    /* print msg & wait for RETURN */
  517. X    }
  518. X
  519. X    exit(0);
  520. }
  521. X
  522. /* wait_return prints a message, then waits until user hits RETURN key,
  523. then returns.  Special cases:  (a) if not interactive (as tested with
  524. isatty() if available), it returns immediately; (b) while waiting for
  525. RETURN, if EOF occurs, it causes zooexit(0) */
  526. X
  527. static void wait_return() 
  528. {
  529. #ifdef HAVE_ISATTY
  530. X    if (!isatty(fileno(stdout)) || !isatty(fileno(stdin)))
  531. X        return;
  532. #endif
  533. X    (void) printf("Hit RETURN (or ENTER) key to continue...");
  534. X    for ( ; ;) {
  535. X        int key; 
  536. X        key = getchar();
  537. X        if (key == EOF)
  538. X            zooexit(0);
  539. X        if (key == '\n' || key == '\r')
  540. X            return;
  541. X    }
  542. }
  543. SHAR_EOF
  544. chmod 0644 zoo.c ||
  545. echo 'restore of zoo.c failed'
  546. Wc_c="`wc -c < 'zoo.c'`"
  547. test 16090 -eq "$Wc_c" ||
  548.     echo 'zoo.c: original size 16090, current size' "$Wc_c"
  549. fi
  550. # ============= zoo.h ==============
  551. if test -f 'zoo.h' -a X"$1" != X"-c"; then
  552.     echo 'x - skipping zoo.h (File already exists)'
  553. else
  554. echo 'x - extracting zoo.h (Text)'
  555. sed 's/^X//' << 'SHAR_EOF' > 'zoo.h' &&
  556. /* derived from: zoo.h 2.16 88/01/27 23:21:36 */
  557. X
  558. /*
  559. The contents of this file are hereby released to the public domain.
  560. X
  561. X                           -- Rahul Dhesi 1986/11/14
  562. */
  563. X
  564. X
  565. /* Global data structures and also some information about archive structure.
  566. X
  567. Among other things, the archive header contains:  
  568. X
  569. (a) A text message.  In the MS-DOS version this message is terminated by
  570. control Z.  This allows naive users to type the archive to the screen
  571. and see a brief but meaningful message instead of garbage.  The contents of
  572. the text message are however not used by Zoo and they may be anything.  
  573. In particular, the text message may identify the type or archive or the
  574. particular computer system it was created on.  When an archive is packed
  575. by any version of Zoo, the text message is changed to the text message
  576. used by that version.  For example, if Zoo 1.10 packs an archive created
  577. by Zoo 1.31, the text message changes to "Zoo 1.10 archive.".  This
  578. was once considered a shortcoming, but it is now an essential feature,
  579. because packing will also update an old archiver header structure
  580. into a new one.
  581. X
  582. (b) A four-byte tag that identifies all Zoo archives.  This helps prevent
  583. arbitrary binary files from being treated as Zoo archives.  The tag value is
  584. arbitrary, but seemed to be unlikely to occur in an executable file.  The
  585. same tag value is used to identify each directory entry.  
  586. X
  587. (c) A long pointer to where in the file the archive starts.  This pointer
  588. is stored along with its negation for consistency checking.  It is hoped
  589. that if the archive is damaged, both the pointer and its negation won't
  590. be damaged and at least one would still be usable to tell us where the 
  591. data begins.
  592. X
  593. (d) A two-byte value giving the major and minor version number of the
  594. minimum version of Zoo that is needed to fully manipulate the archive.  
  595. As the archive structure is modified, this version number may increase.
  596. Currently version 1.71 of Zoo creates archives that may be fully manipulated
  597. by version 1.40 onwards.
  598. X
  599. (e) With zoo 2.00 addtional fields have been added in the archive
  600. header to store information about the archive comment and generation
  601. limit.
  602. X
  603. Version numbering:  
  604. The directory entry of each file will contain the minimum version number of
  605. Zoo needed to extract that file.  As far as possible, version 1.00 of Zoo
  606. will be able to extract files from future version archives.
  607. */
  608. X
  609. #define H_TYPE    1                /* archive header type */
  610. X
  611. /* Define major and minor version numbers */
  612. #define MAJOR_VER 2        /* needed to manipulate archive */
  613. #define MINOR_VER 0
  614. X
  615. /* version needed to extract packing method 1 */
  616. #define MAJOR_EXT_VER 1
  617. #define MINOR_EXT_VER 0
  618. X
  619. /* version needed to extract packing method 2 */
  620. #define MAJOR_LZH_VER    2
  621. #define MINOR_LZH_VER    1
  622. X
  623. #define CTRL_Z 26
  624. X
  625. /* should be 0xFDC4A7DCUL but many c compilers don't recognize UL at end */
  626. #define ZOO_TAG ((unsigned long) 0xFDC4A7DCL) /* A random choice */
  627. #define TEXT "ZOO 2.10 Archive.\032"   /* Header text for archive. */
  628. #define SIZ_TEXT  20                   /* Size of header text */
  629. X
  630. #define PATHSIZE 256                   /* Max length of pathname */
  631. #define FNAMESIZE 13                   /* Size of DOS filename */
  632. #define LFNAMESIZE 256                 /* Size of long filename */
  633. #define ROOTSIZE 8                     /* Size of fname without extension */
  634. #define EXTLEN 3                       /* Size of extension */
  635. #define FILE_LEADER  "@)#("            /* Allowing location of file data */
  636. #define SIZ_FLDR  5                    /* 4 chars plus null */
  637. #define MAX_PACK 2                     /* max packing method we can handle */
  638. #define BACKUP_EXT ".bak"              /* extension of backup file */
  639. X
  640. #ifdef OOZ
  641. #define FIRST_ARG 2
  642. #endif
  643. X
  644. #ifdef ZOO
  645. #define FIRST_ARG 3        /* argument position of filename list */
  646. #endif
  647. X
  648. typedef unsigned char uchar;
  649. X
  650. /* WARNING:  Static initialization in zooadd.c or zooext.c depends on the 
  651. X   order of fields in struct zoo_header */
  652. struct zoo_header {
  653. X   char text[SIZ_TEXT];       /* archive header text */
  654. X   unsigned long zoo_tag;     /* identifies archives */
  655. X   long zoo_start;            /* where the archive's data starts */
  656. X   long zoo_minus;              /* for consistency checking of zoo_start */
  657. X   uchar major_ver;
  658. X   uchar minor_ver;           /* minimum version to extract all files   */
  659. X    uchar type;                        /* type of archive header */
  660. X    long acmt_pos;                    /* position of archive comment */
  661. X    unsigned int acmt_len;        /* length of archive comment */
  662. X    unsigned int vdata;            /* byte in archive;  data about versions */
  663. };
  664. X
  665. struct direntry {
  666. X   unsigned long zoo_tag;     /* tag -- redundancy check */
  667. X   uchar type;                 /* type of directory entry.  always 1 for now */
  668. X   uchar packing_method;       /* 0 = no packing, 1 = normal LZW */
  669. X   long next;                 /* pos'n of next directory entry */
  670. X   long offset;               /* position of this file */
  671. X   unsigned int date;         /* DOS format date */
  672. X   unsigned int time;         /* DOS format time */
  673. X   unsigned int file_crc;     /* CRC of this file */
  674. X   long org_size;
  675. X   long size_now;
  676. X   uchar major_ver;
  677. X   uchar minor_ver;            /* minimum version needed to extract */
  678. X   uchar deleted;              /* will be 1 if deleted, 0 if not */
  679. X   uchar struc;                /* file structure if any */
  680. X   long comment;              /* points to comment;  zero if none */
  681. X   unsigned int cmt_size;         /* length of comment, 0 if none */
  682. X   char fname[FNAMESIZE];         /* filename */
  683. X
  684. X   int var_dir_len;           /* length of variable part of dir entry */
  685. X   uchar tz;                   /* timezone where file was archived */
  686. X   unsigned int dir_crc;      /* CRC of directory entry */
  687. X
  688. X   /* fields for variable part of directory entry follow */
  689. X   uchar namlen;               /* length of long filename */
  690. X   uchar dirlen;               /* length of directory name */
  691. X   char lfname[LFNAMESIZE];   /* long filename */
  692. X   char dirname[PATHSIZE];    /* directory name */
  693. X   unsigned int system_id;    /* Filesystem ID */
  694. X    unsigned long fattr;            /* File attributes -- 24 bits */
  695. X    unsigned int vflag;            /* version flag bits -- one byte in archive */
  696. X    unsigned int version_no;    /* file version number if any */
  697. };
  698. X
  699. /* Values for direntry.system_id */
  700. #define SYSID_NIX       0     /* UNIX and similar filesystems */
  701. #define SYSID_MS        1     /* MS-DOS filesystem */
  702. #define SYSID_PORTABLE  2     /* Portable syntax */
  703. X
  704. /* Structure of header of small archive containing just one file */
  705. X
  706. #define  TINYTAG     0x07FE   /* magic number */
  707. X
  708. #ifndef PORTABLE
  709. struct tiny_header {          /* one-file small archive */
  710. X   int tinytag;               /* magic number */
  711. X   char type;                 /* always 1 for now */
  712. X   char packing_method;
  713. X   unsigned int date;
  714. X   unsigned int time;
  715. X   unsigned int file_crc;
  716. X   long org_size;
  717. X   long size_now;
  718. X   char major_ver;
  719. X   char minor_ver;
  720. X   unsigned int cmt_size; /* length of comment, 0 if none */
  721. X   char fname[FNAMESIZE];     /* filename */
  722. };
  723. #endif /* ifndef PORTABLE */
  724. X
  725. #define    FIXED_OFFSET 34        /* zoo_start in old archives */
  726. #define    MINZOOHSIZ 34            /* minimum size of archive header */
  727. #define  SIZ_ZOOH  42            /* length of current archive header */
  728. X
  729. /* offsets of items within the canonical zoo archive header */
  730. #define  TEXT_I    0           /* text in header */
  731. #define  ZTAG_I    20          /* zoo tag */
  732. #define  ZST_I     24          /* start offset */
  733. #define  ZSTM_I    28          /* negative of start offset */
  734. #define  MAJV_I    32          /* major version */
  735. #define  MINV_I    33          /* minor version */
  736. #define    HTYPE_I     34            /* archive header type */
  737. #define    ACMTPOS_I 35            /* position of archive comment */
  738. #define    ACMTLEN_I 39            /* length of archive comment */
  739. #define    HVDATA_I     41            /* version data */
  740. X
  741. /* offsets of items within the canonical directory entry structure */
  742. #define  SIZ_DIR  51          /* length of type 1 directory entry */
  743. #define  SIZ_DIRL 56          /* length of type 2 directory entry */
  744. #define  DTAG_I   0           /* tag within directory entry */
  745. #define  DTYP_I   4           /* type of directory entry */
  746. #define  PKM_I    5           /* packing method */
  747. #define  NXT_I    6           /* pos'n of next directory entry */
  748. #define  OFS_I    10          /* position (offset) of this file */
  749. #define  DAT_I    14          /* DOS format date */
  750. #define  TIM_I    16          /* DOS format time */
  751. #define  CRC_I    18          /* CRC of this file */
  752. #define  ORGS_I   20          /* original size */
  753. #define  SIZNOW_I 24          /* size now */
  754. #define  DMAJ_I   28          /* major version number */
  755. #define  DMIN_I   29          /* minor version number */
  756. #define  DEL_I    30          /* deleted or not */
  757. #define  STRUC_I  31          /* file structure */
  758. #define  CMT_I    32          /* comment [offset] */
  759. #define  CMTSIZ_I 36          /* comment size */
  760. #define  FNAME_I  38          /* filename */
  761. #define  VARDIRLEN_I  51      /* length of var. direntry */
  762. #define  TZ_I     53          /* timezone */
  763. #define  DCRC_I   54          /* CRC of directory entry */
  764. X
  765. #define  FNM_SIZ  13          /* size of stored filename */
  766. X
  767. /* Offsets within variable part of directory entry */
  768. #define  NAMLEN_I   (SIZ_DIRL + 0)
  769. #define  DIRLEN_I   (SIZ_DIRL + 1)
  770. #define  LFNAME_I   (SIZ_DIRL + 2)
  771. #define  DIRNAME_I  LFNAME_I  /* plus length of filename */
  772. X
  773. /*
  774. Total size of fixed plus variable directory recognized currently:
  775. One byte each for dirlen and namlen, 256 each for long filename and
  776. directory name, 2 for system id, 3 for file attributes, 1 for 
  777. version flag, 2 for version number, plus a fudge factor of 5.
  778. */
  779. #define  MAXDIRSIZE  (SIZ_DIRL+1+1+256+256+2+3+1+2+5)
  780. X
  781. /* Value used to stuff into timezone field if it is not known */
  782. #define  NO_TZ    127
  783. X
  784. /* Value for no file attributes */
  785. #define    NO_FATTR        0L
  786. X
  787. /* version flag bits */
  788. #define    VFL_ON    0x80        /* enable version numbering */
  789. #define    VFL_GEN    0x0f        /* generation count */
  790. #define    VFL_LAST 0x40        /* last generation of this file */
  791. X
  792. /* default generation value for archive */
  793. #define    GEN_DEFAULT            3
  794. /* max generation count, file or archive */
  795. #define    MAXGEN                0x0f
  796. /* version mask to prune down to correct size on large-word machines */
  797. #define VER_MASK                0xffff
  798. SHAR_EOF
  799. chmod 0644 zoo.h ||
  800. echo 'restore of zoo.h failed'
  801. Wc_c="`wc -c < 'zoo.h'`"
  802. test 10237 -eq "$Wc_c" ||
  803.     echo 'zoo.h: original size 10237, current size' "$Wc_c"
  804. fi
  805. true || echo 'restore of zoo.man failed'
  806. echo End of part 11, continue with part 12
  807. exit 0
  808.