home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 3 / 3611 < prev    next >
Encoding:
Text File  |  1991-07-11  |  31.0 KB  |  1,154 lines

  1. Newsgroups: alt.sources
  2. Subject: zoo 2.1 source part 08/15
  3. Message-ID: <12775@bsu-cs.bsu.edu>
  4. From: dhesi@bsu-cs.bsu.edu (Rahul Dhesi)
  5. Date: 10 Jul 91 10:19:34 GMT
  6.  
  7. Checksum: 1455346899 (verify with "brik -cv")
  8. Submitted-by: dhesi@bsu-cs.bsu.edu
  9. Archive-name: zoo210/part08
  10.  
  11. ---- Cut Here and feed the following to sh ----
  12. #!/bin/sh
  13. # This is part 08 of zoo210
  14. # ============= prterror.c ==============
  15. if test -f 'prterror.c' -a X"$1" != X"-c"; then
  16.     echo 'x - skipping prterror.c (File already exists)'
  17. else
  18. echo 'x - extracting prterror.c (Text)'
  19. sed 's/^X//' << 'SHAR_EOF' > 'prterror.c' &&
  20. #ifndef LINT
  21. /* @(#) prterror.c 2.8 88/01/31 18:48:17 */
  22. static char sccsid[]="@(#) prterror.c 2.8 88/01/31 18:48:17";
  23. #endif /* LINT */
  24. X
  25. /*
  26. The contents of this file are hereby released to the public domain.
  27. X
  28. X                                 -- Rahul Dhesi 1986/11/14
  29. X
  30. */
  31. X
  32. #include "options.h"
  33. #ifndef    OK_STDIO
  34. #include <stdio.h>
  35. #define    OK_STDIO
  36. #endif
  37. #include "various.h"
  38. #include "zooio.h"
  39. #include "zoofns.h"
  40. X
  41. #ifdef NEEDCTYP
  42. # include <ctype.h>    /* for isdigit() */
  43. #endif
  44. X
  45. #ifdef STDARG
  46. # include <stdarg.h>
  47. #else
  48. # ifdef VARARGS
  49. #  include <varargs.h>
  50. # else
  51. #  include "MUST DEFINE STDARG OR VARARGS"
  52. # endif
  53. #endif
  54. X
  55. #ifdef NEED_VPRINTF
  56. static int zvfprintf();
  57. #endif
  58. X
  59. /* General error handler.  Input format:
  60. X
  61. X   parameter 1:  'w', 'e', or 'f'.
  62. X
  63. X      'm':  message
  64. X      'M':  message without preceding identification
  65. X      'w':  WARNING
  66. X      'e':  ERROR
  67. X      'f':  FATAL
  68. X      'F':  FATAL but program doesn't exist immediately
  69. X
  70. X   All text printed is preceded by "Zoo:  " or "Ooz:  "  depending
  71. X   upon conditional compilation, except in the case of 'M' messages
  72. X   which are printed without any text being added.
  73. X
  74. X   For messages, the text supplied is printed if and only if the global
  75. X   variable "quiet" is zero.  Control then returns to the caller.
  76. X
  77. X   For warnings, errors, and fatal errors, the variable "quiet" is used
  78. X    as follows.  Warning messages are suppressed if quiet > 1;  error
  79. X    messages are suppressed if quiet > 2.  Fatal error messages are 
  80. X    never suppressed--doing so would be a bit risky.
  81. X
  82. X   For warnings and errors, the error message is preceded by the "WARNING:"
  83. X   or "ERROR".  The error message is printed and control returns to the
  84. X   caller.
  85. X
  86. X   For fatal errors, the error message is preceded by "FATAL:" and an
  87. X   error message is printed.  If the option was 'f', the program exits with 
  88. X   a status of 1.  If the option was 'F', control returns to the caller and 
  89. X   it is assumed that the caller will do any cleaning up necessary and then 
  90. X   exit with an error status.
  91. X
  92. X   parameter 2:  The format control string for printf.   
  93. X    remining parameters:  passed on to vprintf().
  94. X
  95. X    All messages, whether informative or error, are sent to standard
  96. X    output via printf.  It might be a good idea to eventually send 'e' and
  97. X    'f' class messages to the standard error stream.  Best would be
  98. X    some way of telling if standard output and standard error are not
  99. X    the same device, so that we could always send error messages to
  100. X    standard error, and also duplicate them to standard output if 
  101. X    different from standard error.  This is one thing that VMS seems
  102. X    to be capable of doing.  There seems to be no way of doing this
  103. X    in the general case.
  104. */
  105. X
  106. extern int quiet;
  107. X
  108. /* These declarations must be equivalent to those in errors.i */
  109. char no_match[] = "No files matched.\n";
  110. char failed_consistency[] = "Archive header failed consistency check.\n";
  111. char invalid_header[] = "Invalid or corrupted archive.\n";
  112. char internal_error[]="Internal error.\n";
  113. char disk_full[]      = "I/O error or disk full.\n";
  114. char bad_directory[]  = "Directory entry in archive is invalid.\n";
  115. char no_memory[] = "Ran out of memory.\n";
  116. char too_many_files[] = "Some filenames ignored -- can only handle %d.\n";
  117. char packfirst[] = "Old format archive -- please pack first with P command.\n";
  118. char garbled[] = "Command is garbled.\n";
  119. char start_ofs[] = "Starting at %ld (offset %ld)\n";
  120. X
  121. #ifndef OOZ
  122. char wrong_version[]=
  123. X   "Zoo %d.%d or later is needed to fully manipulate this archive.\n";
  124. char cant_process[] =
  125. X   "The rest of the archive (%lu bytes) cannot be processed.\n";
  126. char option_ignored[] = "Ignoring option %c.\n";
  127. char inv_option[] = "Option %c is invalid.\n";
  128. char bad_crc[] = "\007Bad CRC, %s probably corrupted\n";
  129. #endif
  130. X
  131. #ifdef OOZ
  132. char could_not_open[] = "Could not open ";
  133. #else
  134. char could_not_open[] = "Could not open %s.\n";
  135. #endif
  136. X
  137. #ifdef STDARG
  138. void prterror(int level, char *format, ...)
  139. #else
  140. /*VARARGS*/
  141. void prterror(va_alist)
  142. va_dcl
  143. #endif
  144. {
  145. X    va_list args;
  146. X   char string[120];       /* local format string */
  147. #ifdef VARARGS
  148. X    int level;
  149. X    char *format;
  150. #endif
  151. X
  152. #ifdef STDARG
  153. X    va_start(args, format);
  154. #else
  155. X    va_start(args);
  156. X    level = va_arg(args, int);
  157. X    format = va_arg(args, char *);
  158. #endif
  159. X
  160. X   *string = '\0';         /* get a null string to begin with */
  161. X
  162. #ifdef OOZ
  163. X   strcpy (string, "Ooz:  ");
  164. #else
  165. X   strcpy (string, "Zoo:  ");
  166. #endif
  167. X
  168. X   switch (level) {
  169. X      case 'M': *string = '\0';                    /* fall through to 'm' */
  170. X      case 'm': if (quiet) return; break;
  171. X      case 'w': 
  172. X            if (quiet > 1) return;
  173. X            strcat (string, "WARNING:  "); break;
  174. X      case 'e': 
  175. X            if (quiet > 2) return;
  176. X            strcat (string, "ERROR:  ");   break;
  177. X      case 'F':
  178. X      case 'f': strcat (string, "FATAL:  ");   break;
  179. X      default: prterror ('f', internal_error);  /* slick recursive call */
  180. X   }
  181. X
  182. X   strcat (string, format);      /* just append supplied format string */
  183. X
  184. X    /* and print the whole thing */
  185. #ifdef NEED_VPRINTF
  186. X    (void) zvfprintf(stdout, string, args);
  187. #else
  188. X   (void) vprintf(string, args);
  189. #endif
  190. X    fflush (stdout);
  191. X
  192. X   if (level == 'f')       /* and abort on fatal error 'f' but not 'F' */
  193. X      zooexit (1);
  194. }
  195. X
  196. X
  197. #ifdef NEED_VPRINTF
  198. /* Some systems don't have vprintf;  if so, we roll our own.  The following
  199. has been adapted from a Usenet posting by Jef Poskanzer <jef@well.sf.ca.us>.
  200. X
  201. This is a portable mini-vfprintf that depends only on fprintf.
  202. X
  203. We don't call this routine vfprintf to avoid unexpected conflicts with any 
  204. library routine of the same name, notwithstanding the fact that we will 
  205. usually use it only when there is no conflict.  Also, even though we only 
  206. need vprintf, the routine used here implements vfprintf.  This will allow 
  207. future uses as needed when output is to be sent to a stream other than
  208. stdout.  */
  209. X
  210. /* Whether to support double.  Better not to, because it may cause
  211. math stuff to be linked in */
  212. X
  213. #undef NEED_DOUBLE
  214. X
  215. static int zvfprintf(stream, format, args)
  216. FILE *stream;
  217. char *format;
  218. va_list args;
  219. {
  220. X    char *ep;
  221. X    char fchar;
  222. X    char tformat[512];
  223. X    int do_long;        /* whether to print as long (l format suffix) */
  224. X    int do_star;        /* * used in format => get width from argument */
  225. X    int star_size;        /* size arg corresponding to "*" format */
  226. X    int i;
  227. X    long l;
  228. X    unsigned u;
  229. X    unsigned long ul;
  230. X    char *s;
  231. #ifdef NEED_DOUBLE
  232. X    double d;
  233. #endif
  234. X
  235. X    while (*format != '\0') {
  236. X        if (*format != '%') { /* Not special, just write out the char. */
  237. X            putc(*format, stream);
  238. X            ++format;
  239. X       } else {
  240. X            do_star = 0;
  241. X            do_long = 0;
  242. X            ep = format + 1;
  243. X
  244. X            /* Skip over all the field width and precision junk. */
  245. X            if (*ep == '-')
  246. X                ++ep;
  247. X            if (*ep == '0')
  248. X                ++ep;
  249. X            while (isdigit(*ep))
  250. X                ++ep;
  251. X          if (*ep == '.') {
  252. X                ++ep;
  253. X                while (isdigit(*ep))
  254. X                    ++ep;
  255. X            }
  256. X            if (*ep == '#')
  257. X                ++ep;
  258. X            if (*ep == '*') {
  259. X                do_star = 1;
  260. X                star_size = va_arg(args, int);    /* get * argument */
  261. X                ++ep;
  262. X            }
  263. X            if (*ep == 'l') {
  264. X                do_long = 1;
  265. X                ++ep;
  266. X            }
  267. X
  268. X          /* Here's the field type.  Extract it, and copy this format
  269. X          ** specifier to a temp string so we can add an end-of-string.
  270. X          */
  271. X          fchar = *ep;
  272. X          (void) strncpy(tformat, format, ep - format + 1);
  273. X          tformat[ep - format + 1] = '\0';
  274. X
  275. X          /* Now do a one-argument printf with the format string we have 
  276. X            isolated.  If the * format was used, we will also supply the 
  277. X            additional parameter star_size, which we have already obtained 
  278. X            from the variable argument list.  */
  279. X
  280. X          switch (fchar) {
  281. X             case 'd':
  282. X                if (do_long) {
  283. X                    l = va_arg(args, long);
  284. X                    if (do_star)
  285. X                        (void) fprintf(stream, tformat, star_size, l);
  286. X                    else
  287. X                        (void) fprintf(stream, tformat, l);
  288. X                } else {
  289. X                    i = va_arg(args, int);
  290. X                    if (do_star)
  291. X                        (void) fprintf(stream, tformat, star_size, i);
  292. X                    else
  293. X                        (void) fprintf(stream, tformat, i);
  294. X                }
  295. X                break;
  296. X
  297. X           case 'o':
  298. X           case 'x':
  299. X           case 'u':
  300. X              if (do_long) {
  301. X                    ul = va_arg(args, unsigned long);
  302. X                    if (do_star)
  303. X                        (void) fprintf(stream, tformat, star_size, ul);
  304. X                    else
  305. X                        (void) fprintf(stream, tformat, ul);
  306. X              } else {
  307. X                  u = va_arg(args, unsigned);
  308. X                    if (do_star)
  309. X                        (void) fprintf(stream, tformat, star_size, u);
  310. X                    else
  311. X                        (void) fprintf(stream, tformat, u);
  312. X              }
  313. X               break;
  314. X
  315. X             case 'c':
  316. X                i = (char) va_arg(args, int);
  317. X                if (do_star)
  318. X                    (void) fprintf(stream, tformat, star_size, i);
  319. X                else
  320. X                    (void) fprintf(stream, tformat, i);
  321. X                break;
  322. X
  323. X             case 's':
  324. X                s = va_arg(args, char *);
  325. X                if (do_star)
  326. X                    (void) fprintf(stream, tformat, star_size, s);
  327. X                else
  328. X                    (void) fprintf(stream, tformat, s);
  329. X                break;
  330. X
  331. #ifdef NEED_DOUBLE
  332. X           case 'e':
  333. X           case 'f':
  334. X           case 'g':
  335. X                d = va_arg(args, double);
  336. X                if (do_star)
  337. X                    (void) fprintf(stream, tformat, star_size, d);
  338. X                else
  339. X                    (void) fprintf(stream, tformat, d);
  340. X                break;
  341. #endif
  342. X
  343. X           case '%':
  344. X                putc('%', stream);
  345. X                break;
  346. X
  347. X             default:
  348. X                return -1;
  349. X            }
  350. X
  351. X            /* Resume formatting on the next character. */
  352. X            format = ep + 1;
  353. X        }
  354. X    }
  355. X    va_end(args);
  356. X    return 0;
  357. }
  358. #endif /*NEED_VPRINTF*/
  359. SHAR_EOF
  360. chmod 0644 prterror.c ||
  361. echo 'restore of prterror.c failed'
  362. Wc_c="`wc -c < 'prterror.c'`"
  363. test 9094 -eq "$Wc_c" ||
  364.     echo 'prterror.c: original size 9094, current size' "$Wc_c"
  365. fi
  366. # ============= sysv.c ==============
  367. if test -f 'sysv.c' -a X"$1" != X"-c"; then
  368.     echo 'x - skipping sysv.c (File already exists)'
  369. else
  370. echo 'x - extracting sysv.c (Text)'
  371. sed 's/^X//' << 'SHAR_EOF' > 'sysv.c' &&
  372. #ifndef LINT
  373. /* @(#) sysv.c 2.5 88/01/10 14:47:24 */
  374. static char sysvid[]="@(#) sysv.c 2.5 88/01/10 14:47:24";
  375. #endif /* LINT */
  376. X
  377. /* machine.c for System V */
  378. X
  379. /*
  380. The contents of this file are hereby released to the public domain.
  381. X
  382. X                                    -- Rahul Dhesi  1986/12/31
  383. */
  384. X
  385. #ifdef UNBUF_IO    /* do not use */
  386. /*
  387. Function tell() returns the current seek position for a file 
  388. descriptor.  Microport System V/AT has an undocumented tell()
  389. library function (why?) but the **IX PC doesn't, so we code
  390. one here.  It is needed for unbuffered I/O only.
  391. */
  392. long lseek PARMS ((int, long, int));
  393. long tell (fd)
  394. int fd;
  395. { return (lseek (fd, 0L, 1)); }
  396. #endif /* UNBUF_IO */
  397. X
  398. /****************
  399. Date and time functions are standard **IX-style functions.  "nixtime.i"
  400. will be included by machine.c.
  401. */
  402. X
  403. #include <sys/types.h>
  404. #include <sys/stat.h>
  405. #include <time.h>
  406. X
  407. /* Function isadir() returns 1 if the supplied handle is a directory, 
  408. else it returns 0.  
  409. */
  410. X
  411. int isadir (file)
  412. ZOOFILE file;
  413. {
  414. X   int handle = fileno(file);
  415. X   struct stat buf;           /* buffer to hold file information */
  416. X   if (fstat (handle, &buf) == -1) {
  417. X      return (0);             /* inaccessible -- assume not dir */
  418. X   } else {
  419. X      if (buf.st_mode & S_IFDIR)
  420. X         return (1);
  421. X      else
  422. X         return (0);
  423. X   }
  424. }
  425. X
  426. /****************
  427. Function fixfname() converts the supplied filename to a syntax
  428. legal for the host system.  It is used during extraction.
  429. */
  430. X
  431. char *fixfname(fname)
  432. char *fname;
  433. {
  434. X   return (fname); /* default is no-op */
  435. }
  436. X
  437. extern long timezone;   /* defined by library routine */
  438. long time ();
  439. struct tm *localtime ();
  440. X
  441. /* Function gettz(), returns the offset from GMT in seconds of the
  442. local time, taking into account daylight savings time */
  443. X
  444. #if 1        /* Following should work for System V */
  445. long gettz()
  446. {
  447. #define SEC_IN_DAY    (24L * 60L * 60L)
  448. #define INV_VALUE        (SEC_IN_DAY + 1L)
  449. X    static long retval = INV_VALUE;         /* cache, init to impossible value */
  450. X    struct tm *tm;
  451. X    long clock;
  452. X    if (retval != INV_VALUE)                 /* if have cached value, return it */
  453. X        return retval;
  454. X    clock = time ((long *) 0);
  455. X    tm = localtime (&clock);
  456. X    retval = timezone - tm->tm_isdst*3600;
  457. X    return retval;
  458. }
  459. #else
  460. /* This version of gettz should be portable to all Unices, although it can't
  461. X   be described as elegant. Users immediately west of the International
  462. X   Date Line (Polynesia, Soviet Far East) may get times out by 24 hours.
  463. X   Contributed by: Ian Phillipps <igp@camcon.co.uk> */
  464. X
  465. /* Function gettz(), returns the offset from GMT in seconds */
  466. long gettz()
  467. {
  468. #define NOONOFFSET 43200
  469. #define SEC_IN_DAY    (24L * 60L * 60L)
  470. #define INV_VALUE        (SEC_IN_DAY + 1L)
  471. X    static long retval = INV_VALUE;         /* cache, init to impossible value */
  472. X    extern long time();
  473. X    extern struct tm *localtime();
  474. X    long now;
  475. X    long noon;
  476. X    struct tm *noontm;
  477. X    if (retval != INV_VALUE)                 /* if have cached value, return it */
  478. X        return retval;
  479. X   now = time((long *) 0);
  480. X   /* Find local time for GMT noon today */
  481. X   noon = now - now % SEC_IN_DAY + NOONOFFSET ;
  482. X   noontm = localtime( &noon );
  483. X   retval = NOONOFFSET - 60 * ( 60 * noontm->tm_hour - noontm->tm_min );
  484. X    return retval;
  485. #undef NOONOFFSET
  486. }
  487. #endif
  488. X
  489. /* Standard **IX-compatible time functions */
  490. #include "nixtime.i"
  491. X
  492. /* Standard **IX-specific file attribute routines */
  493. #include "nixmode.i"
  494. X
  495. /* 
  496. Make a directory.  System V has no system call accessible to 
  497. ordinary users to make a new directory.  Hence we spawn a shell 
  498. and hope /bin/mkdir is there.  Since /bin/mkdir gives a nasty 
  499. error message if it fails, we call it only if nothing already 
  500. exists by the name of the needed directory.
  501. */
  502. X
  503. int mkdir(dirname)
  504. char *dirname;
  505. {
  506. X   char cmd[PATHSIZE+11+1]; /* room for "/bin/mkdir " used below  + 1 spare */
  507. X   if (!exists(dirname)) {
  508. X      strcpy(cmd, "/bin/mkdir ");
  509. X      strcat(cmd, dirname);
  510. X      return (system(cmd));
  511. X   }
  512. X    return (0);
  513. }
  514. X
  515. /* No file truncate system call in older System V.  If yours has one,
  516. add it here -- see bsd.c for example.  It's ok for zootrunc to be
  517. a no-op. */
  518. /*ARGSUSED*/
  519. int zootrunc(f) FILE *f; { return 0; }
  520. X    
  521. SHAR_EOF
  522. chmod 0644 sysv.c ||
  523. echo 'restore of sysv.c failed'
  524. Wc_c="`wc -c < 'sysv.c'`"
  525. test 4088 -eq "$Wc_c" ||
  526.     echo 'sysv.c: original size 4088, current size' "$Wc_c"
  527. fi
  528. # ============= turboc.c ==============
  529. if test -f 'turboc.c' -a X"$1" != X"-c"; then
  530.     echo 'x - skipping turboc.c (File already exists)'
  531. else
  532. echo 'x - extracting turboc.c (Text)'
  533. sed 's/^X//' << 'SHAR_EOF' > 'turboc.c' &&
  534. /* @(#) turboc.c 1.2 87/06/21 16:08:54 */
  535. X
  536. int _stklen = 30000;        /* stack size in bytes */
  537. void _setenvp() {}      /* don't initialize environment pointer etc. */
  538. #include <stdio.h>        /* to get fileno() */
  539. X
  540. /* following not needed any more since zoocreate() is fixed in portable.c */
  541. /* unsigned _fmode = O_BINARY; */
  542. X
  543. void dosname PARMS((char *, char *));
  544. #ifdef ANSI_HDRS
  545. # include <stdlib.h>
  546. #else
  547. char *strcpy PARMS((char *, char *));
  548. #endif
  549. X
  550. #include <signal.h>
  551. X
  552. /* register definitions specific for Turbo C */
  553. union    REGS    {
  554. X    struct { unsigned ax, bx, cx, dx, si, di, carry, flags; } x;
  555. X    struct { unsigned char al, ah, bl, bh, cl, ch, dl, dh; }  h;
  556. };
  557. X
  558. /****************
  559. function zootrunc() truncates a file at the current seek position.
  560. */
  561. X
  562. int zootrunc (f)
  563. FILE *f;
  564. {
  565. X    int handle = fileno(f);
  566. X    extern long tell();
  567. X    extern int chsize();
  568. X    return chsize(handle, tell(handle));
  569. }
  570. X
  571. /****************
  572. Function fixfname() converts the supplied filename to a syntax
  573. legal for the host system.  It is used during extraction.
  574. */
  575. X
  576. char *fixfname(fname)
  577. char *fname;
  578. {
  579. X    char tmpname[PATHSIZE];
  580. X    dosname (nameptr(fname), tmpname);
  581. X    strcpy(fname,tmpname);
  582. X    return(fname);
  583. }
  584. X
  585. static int set_break (int flag)
  586. {
  587. X    extern int intdos();
  588. X    int retval;
  589. X    union REGS regs;
  590. X    regs.x.ax = 0x3300;                /* get ctrl-break flag */
  591. X    intdos (®s, ®s);
  592. X    retval = regs.h.dl;                /* retval is old value of setting */
  593. X    regs.x.ax = 0x3301;                /* set ctrl-break flag */
  594. X    regs.h.dl = flag;                /* status to set to */
  595. X    intdos (®s, ®s);
  596. X    return (retval);
  597. }
  598. X
  599. static int break_flag;
  600. X
  601. void zooexit (int status)
  602. {
  603. X    set_break (break_flag);            /* restore control_break setting */
  604. X    exit (status);
  605. }
  606. X
  607. void gentab (void);
  608. X
  609. void spec_init(void)
  610. {
  611. X    break_flag = set_break (0);
  612. X    signal (SIGINT, zooexit);        /* install our own control-C handler */
  613. }
  614. X
  615. #ifndef fileno
  616. /* To allow compilation with -A (for testing), which makes fileno()
  617. unavailable, we define a function here by that name.  This may be 
  618. compiler-specific for Turbo C++ 1.0. */
  619. X
  620. int fileno(f)
  621. FILE *f;
  622. {
  623. X   return f->fd;
  624. }
  625. #endif /* ! fileno */
  626. SHAR_EOF
  627. chmod 0644 turboc.c ||
  628. echo 'restore of turboc.c failed'
  629. Wc_c="`wc -c < 'turboc.c'`"
  630. test 2063 -eq "$Wc_c" ||
  631.     echo 'turboc.c: original size 2063, current size' "$Wc_c"
  632. fi
  633. # ============= turboc.cfg ==============
  634. if test -f 'turboc.cfg' -a X"$1" != X"-c"; then
  635.     echo 'x - skipping turboc.cfg (File already exists)'
  636. else
  637. echo 'x - extracting turboc.cfg (Text)'
  638. sed 's/^X//' << 'SHAR_EOF' > 'turboc.cfg' &&
  639. -IC:\TC\INCLUDE
  640. -LC:\TC\LIB
  641. -a -f- -k- -v- -G -O -Z -c -O 
  642. -wrvl -wamb -wamp -wnod -wstv -wuse -wcln -wsig -wucp
  643. SHAR_EOF
  644. chmod 0644 turboc.cfg ||
  645. echo 'restore of turboc.cfg failed'
  646. Wc_c="`wc -c < 'turboc.cfg'`"
  647. test 113 -eq "$Wc_c" ||
  648.     echo 'turboc.cfg: original size 113, current size' "$Wc_c"
  649. fi
  650. # ============= various.h ==============
  651. if test -f 'various.h' -a X"$1" != X"-c"; then
  652.     echo 'x - skipping various.h (File already exists)'
  653. else
  654. echo 'x - extracting various.h (Text)'
  655. sed 's/^X//' << 'SHAR_EOF' > 'various.h' &&
  656. /* @(#) various.h 2.3 87/12/27 14:44:34 */
  657. X
  658. /*
  659. The contents of this file are hereby released to the public domain.
  660. X
  661. X                           -- Rahul Dhesi 1986/11/14
  662. */
  663. X
  664. /*
  665. This files gives definitions for most external functions used by Zoo.
  666. If ANSI_PROTO is defined, ANSI-style function prototypes are used, else
  667. normal K&R function declarations are used.
  668. X
  669. Note:  Always precede this file with an include of stdio.h because it uses
  670. the predefined type FILE.
  671. */
  672. X
  673. #ifndef PARMS
  674. #ifdef ANSI_PROTO
  675. #define    PARMS(x)        x
  676. #else
  677. #define    PARMS(x)        ()
  678. #endif
  679. #endif
  680. X
  681. #ifdef ANSI_HDRS /* if not defined in stdio.h */
  682. # include <string.h>
  683. # include <stdlib.h>
  684. #else
  685. FILE *fdopen PARMS ((int, char *));
  686. FILE *fopen PARMS ((char *, char *));
  687. char *fgets PARMS ((char *, int, FILE *));
  688. char *gets PARMS ((char *));
  689. VOIDPTR malloc PARMS ((unsigned int));
  690. VOIDPTR realloc PARMS ((char *, unsigned int));
  691. char *strcat PARMS ((char *, char *));
  692. char *strchr PARMS ((char *, int));
  693. char *strcpy PARMS ((char *, char *));
  694. char *strncat PARMS ((char *, char *, unsigned int));
  695. char *strncpy PARMS ((char *, char *, unsigned int));
  696. char *strrchr PARMS ((char *, int));
  697. int fclose PARMS ((FILE *));
  698. int fflush PARMS ((FILE *));
  699. int fgetc PARMS ((FILE *));
  700. int fgetchar PARMS (());
  701. int fprintf PARMS ((FILE *, char *, ...));
  702. int fputchar PARMS ((int));
  703. int fputs PARMS ((char *, FILE *));
  704. X
  705. #ifndef NO_STDIO_FN
  706. # ifdef ALWAYS_INT
  707. int fputc PARMS ((int, FILE *));
  708. int fread PARMS ((VOIDPTR, int, int, FILE *));
  709. int fwrite PARMS ((VOIDPTR, int, int, FILE *));
  710. # else
  711. int fputc PARMS ((char, FILE *));
  712. int fread PARMS ((VOIDPTR, unsigned, unsigned, FILE *));
  713. int fwrite PARMS ((VOIDPTR, unsigned, unsigned, FILE *));
  714. # endif /* ALWAYS_INT */
  715. #endif /* NO_STDIO_FN */
  716. X
  717. int fseek PARMS ((FILE *, long, int));
  718. int printf PARMS ((char *, ...));
  719. int rename PARMS ((char *, char *));
  720. int setmode PARMS ((int, int));
  721. int strcmp PARMS ((char *, char *));
  722. int strncmp PARMS ((char *, char *, unsigned int));
  723. int unlink PARMS ((char *));
  724. long ftell PARMS ((FILE *));
  725. unsigned int strlen PARMS ((char *));
  726. X
  727. #endif /* ! ANSI_HDRS */
  728. X
  729. SHAR_EOF
  730. chmod 0644 various.h ||
  731. echo 'restore of various.h failed'
  732. Wc_c="`wc -c < 'various.h'`"
  733. test 2097 -eq "$Wc_c" ||
  734.     echo 'various.h: original size 2097, current size' "$Wc_c"
  735. fi
  736. # ============= version.c ==============
  737. if test -f 'version.c' -a X"$1" != X"-c"; then
  738.     echo 'x - skipping version.c (File already exists)'
  739. else
  740. echo 'x - extracting version.c (Text)'
  741. sed 's/^X//' << 'SHAR_EOF' > 'version.c' &&
  742. /* derived from: version.c 2.9 1988/08/25 12:43:57  */
  743. char version[] = 
  744. "zoo 2.1 $Date: 91/07/09 02:10:34 $";
  745. SHAR_EOF
  746. chmod 0644 version.c ||
  747. echo 'restore of version.c failed'
  748. Wc_c="`wc -c < 'version.c'`"
  749. test 111 -eq "$Wc_c" ||
  750.     echo 'version.c: original size 111, current size' "$Wc_c"
  751. fi
  752. # ============= vms.c ==============
  753. if test -f 'vms.c' -a X"$1" != X"-c"; then
  754.     echo 'x - skipping vms.c (File already exists)'
  755. else
  756. echo 'x - extracting vms.c (Text)'
  757. sed 's/^X//' << 'SHAR_EOF' > 'vms.c' &&
  758. #ifndef LINT
  759. /* derived from: @(#) vms.c 2.2 88/01/09 03:47:52 */
  760. static char vmsid[]="$Source: /usr/home/dhesi/zoo/RCS/vms.c,v $\n\
  761. $Id: vms.c,v 1.10 91/07/07 14:41:17 dhesi Exp $";
  762. #endif /* LINT */
  763. X
  764. /* Support routines for VAX/VMS. */
  765. X
  766. #include <stat.h>
  767. #include <time.h>
  768. X
  769. /* our own version of NULL; avoid any interaction with system defn.
  770. but don't require inclusion of stdio.h */
  771. #define  NILPTR    0
  772. X
  773. /* Function isuadir() returns 1 if the supplied filename is a directory, 
  774. else it returns 0.  
  775. */
  776. X
  777. int isuadir (file)
  778. char *file;
  779. {
  780. X   struct stat buf;           /* buffer to hold file information */
  781. X   if (stat (file, &buf) == -1) {
  782. X      return (0);             /* inaccessible -- assume not dir */
  783. X   } else {
  784. X      if (buf.st_mode & S_IFDIR)
  785. X         return (1);
  786. X      else
  787. X         return (0);
  788. X   }
  789. }
  790. X
  791. /****************
  792. Function fixfname() converts the supplied filename to a syntax
  793. legal for the host system.  It is used during extraction.  We
  794. allow a maximum of one dot in the filename, and it must not
  795. be at the beginning.  We also truncate the number of charac-
  796. ters preceding and following the dot to at most 39.
  797. */
  798. X
  799. char *strchr();
  800. X
  801. char *fixfname(fname)
  802. char *fname;
  803. {
  804. X   char *p;
  805. X   char *dotpos;
  806. X   static char legal[] = 
  807. X      "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$_.0123456789";
  808. X
  809. X   /* convert all characters to legal characters */
  810. X   for (p = fname;  *p != '\0';  p++)
  811. X      if (strchr (legal, *p) == 0) {
  812. X         if (*p == '-' || *p == ' ')
  813. X            *p = '_';
  814. X         else
  815. X            *p = legal [ *p % 26 ];
  816. X      }
  817. X
  818. X   /* first char can't be dot */
  819. X   if (*fname == '.')
  820. X      *fname = 'X';
  821. X
  822. X   /* find embedded dot if any */
  823. X   dotpos = strchr (fname, '.');
  824. X
  825. X   if (dotpos != NILPTR) {
  826. X      for (p = dotpos+1;  *p != '\0';  p++)  /* remove 2nd dot onwards */
  827. X         if (*p == '.')
  828. X            *p = '_';
  829. X      if (dotpos - fname + 1 > 39) {  /* more than 39 before dot not allowed */
  830. X         char *q;
  831. X         p = fname + 39;
  832. X         q = dotpos;
  833. X         while (*p++ = *q++)  /* the notational convenience is considerable */
  834. X            ;
  835. X         dotpos = strchr (fname, '.');
  836. X      }
  837. X      if (strlen (dotpos + 1) > 39)  /* more than 39 after dot not allowed */
  838. X         *(dotpos + 39 + 1) = '\0';
  839. X   } else
  840. X      *(fname + 39) = '\0'; /* no dots, just truncate to 39 characters */
  841. X   return (fname);
  842. }
  843. X
  844. /*
  845. Function gettz(), returns the offset from GMT in seconds of the
  846. local time, taking into account daylight savings time -- or it
  847. would, if VAX/VMS knew about timezones!  It's just a no-op.
  848. */
  849. long gettz()
  850. {
  851. X   return 0L;
  852. }
  853. X
  854. struct tm *localtime();
  855. X
  856. /*****************
  857. Function gettime() gets the date and time of the file handle supplied.
  858. Date and time is in MSDOS format.  This function duplicated from nixtime.i.
  859. */
  860. X
  861. int gettime (file, date, time)
  862. ZOOFILE file;
  863. unsigned *date, *time;
  864. {
  865. X   struct stat buf;           /* buffer to hold file information */
  866. X   struct tm *tm;             /* will hold year/month/day etc. */
  867. X    int handle;
  868. X    handle = fileno(file);
  869. X   if (fstat (handle, &buf) == -1) {
  870. X      prterror ('w', "Could not get file time\n");
  871. X      *date = *time = 0;
  872. X   } else {
  873. X      tm = localtime (&buf.st_mtime); /* get info about file mod time */
  874. X      *date = tm->tm_mday + ((tm->tm_mon + 1) << 5) +
  875. X         ((tm->tm_year - 80) << 9);
  876. X      *time = tm->tm_sec / 2 + (tm->tm_min << 5) +
  877. X         (tm->tm_hour << 11);
  878. X   }
  879. X
  880. }
  881. X
  882. /*
  883. Function unlink() will delete a file using the VMS C delete()
  884. function.
  885. */
  886. int unlink (fname)
  887. char *fname;
  888. {
  889. X   return (delete (fname));
  890. }
  891. X
  892. /*
  893. Function zooexit() receives attempts at exit.  It always invokes
  894. exit() with status=1.
  895. */
  896. void zooexit (status)
  897. int status;
  898. {
  899. X   exit (1);
  900. }
  901. X
  902. X
  903. /*
  904. Function rename() renames a file.  
  905. Thanks to Owen Anthony (was <anthony@bsu-cs.bsu.edu> at one time).
  906. */
  907. X
  908. #include <descrip.h>
  909. X
  910. #ifdef NEED_VMS_RENAME /* if not using VMS 4.6 library rename() */
  911. int rename (old_name, new_name)
  912. char *old_name;
  913. char *new_name;
  914. {
  915. X   int status;
  916. X   struct dsc$descriptor_s file1, file2;
  917. X   file1.dsc$w_length = strlen (old_name);  /* descriptor for old name */
  918. X   file1.dsc$a_pointer = old_name;
  919. X   file1.dsc$b_class = DSC$K_CLASS_S;
  920. X   file1.dsc$b_dtype = DSC$K_DTYPE_T;
  921. X   file2.dsc$w_length = strlen (new_name);  /* descriptor for new name */
  922. X   file2.dsc$a_pointer = new_name;
  923. X   file2.dsc$b_class = DSC$K_CLASS_S;
  924. X   file2.dsc$b_dtype = DSC$K_DTYPE_T;
  925. X
  926. X   status = LIB$RENAME_FILE (&file1, &file2);
  927. X
  928. X   return ((status & ~1) == 1);
  929. }
  930. #endif /* VMS_RENAME */
  931. X
  932. /*
  933. Function specfname() modifies filenames before they are stored
  934. in an archive.  Currently we remove any trailing version field,
  935. and then any trailing dot.
  936. */
  937. char *specfname (fname)
  938. char *fname;
  939. {
  940. X   char *p;
  941. X   p = strchr (fname, ';');
  942. X   if (p != NILPTR)
  943. X      *p = '\0';
  944. X   if (*fname != '\0') {
  945. X      p = fname + strlen (fname) - 1; /* point to last char */
  946. X      if (*p == '.')                  /* remove any trailing dot */
  947. X         *p = '\0';
  948. X   }
  949. X   return (fname);
  950. }
  951. X
  952. /* 
  953. Function specdir() modifies directory names before they are stored
  954. in an archive.  We remove any leading device name or logical
  955. name and and the [ and ] that bracket any directory name.
  956. Then we change any dots in the directory name to slashes.
  957. */
  958. X
  959. #if 0
  960. /* test stub that just truncates dir to null string */
  961. char *specdir (fname) char *fname;
  962. { *fname = '\0'; return (fname); }
  963. #else
  964. X
  965. char *specdir (fname)
  966. char *fname;
  967. {
  968. X   char *p;
  969. X   char tmpstr[LFNAMESIZE];
  970. X
  971. X   p = strchr (fname, ':');      /* remove chars upto and including : */
  972. X   if (p != NILPTR) {
  973. X      strcpy (tmpstr, p+1);
  974. X      strcpy (fname, tmpstr);
  975. X   }
  976. X
  977. X   p = strchr (fname, '[');      /* remove chars upto and including [ */
  978. X   if (p != NILPTR) {
  979. X      strcpy (tmpstr, p+1);
  980. X      strcpy (fname, tmpstr);
  981. X   }
  982. X
  983. X   p = strchr (fname, ']');      /* truncate at ] */
  984. X   if (p != NILPTR) {
  985. X      if (*(p+1) != '\0')
  986. X         prterror ('w', "Trailing garbage in directory name\n");
  987. X      *p = '\0';
  988. X   }
  989. X
  990. X   for (p = fname;  *p != '\0';  p++)   /* change dots to slashes */
  991. X      if (*p == '.')
  992. X         *p = '/';
  993. X
  994. X   /* make sure there is a leading slash -- just a hack for now */
  995. X   if (*fname != '/') {
  996. X      strcpy (tmpstr, fname);
  997. X      strcpy (fname, "/");
  998. X      strcat (fname, tmpstr);
  999. X   }
  1000. X
  1001. #ifdef DEBUG
  1002. printf ("dir name transformed to \"%s\"\n", fname);
  1003. #endif
  1004. }
  1005. #endif
  1006. X
  1007. #define  FMAX  3        /* Number of different filename patterns */
  1008. X
  1009. char *nextfile (what, filespec, fileset)
  1010. int what;                        /* whether to initialize or match      */
  1011. register char *filespec;         /* filespec to match if initializing   */
  1012. register int fileset;            /* which set of files                  */
  1013. {
  1014. X   int status;
  1015. X   char *p;                      /* temp ptr */
  1016. X   struct dsc$descriptor_s d_fwild, d_ffound;
  1017. X   static int first_time [FMAX+1];
  1018. X   static char saved_fspec [FMAX+1][PATHSIZE];  /* our own copy of filespec */
  1019. X   static char found_fspec [FMAX+1][PATHSIZE];  /* matched filename */
  1020. X   static unsigned long context [FMAX+1];    /* needed by VMS */
  1021. X   if (what == 0) {
  1022. X      strcpy (saved_fspec[fileset], filespec);  /* save the filespec */
  1023. X      first_time[fileset] = 1;
  1024. X      return (0);
  1025. X   }
  1026. X
  1027. X   /* Reach here if what is not 0, so it must be 1 */
  1028. X
  1029. X   /* Create a descriptor for the wildcarded filespec */
  1030. X   d_fwild.dsc$w_length = strlen (saved_fspec[fileset]);
  1031. X   d_fwild.dsc$a_pointer = saved_fspec[fileset];
  1032. X   d_fwild.dsc$b_class = DSC$K_CLASS_S;
  1033. X   d_fwild.dsc$b_dtype = DSC$K_DTYPE_T;
  1034. X
  1035. X   d_ffound.dsc$w_length = sizeof (found_fspec[fileset]);
  1036. X   d_ffound.dsc$a_pointer = found_fspec[fileset];
  1037. X   d_ffound.dsc$b_class = DSC$K_CLASS_S;
  1038. X   d_ffound.dsc$b_dtype = DSC$K_DTYPE_T;
  1039. X
  1040. X   if (first_time[fileset]) {
  1041. X      first_time[fileset] = 0;
  1042. X      context[fileset] = 0L;   /* tell VMS this is first search */
  1043. X   }
  1044. X   status = LIB$FIND_FILE (&d_fwild, &d_ffound, &context[fileset]);
  1045. X   status = status & 1;    /* use only lowest bit */
  1046. X
  1047. X   if (status == 0) {
  1048. X      LIB$FIND_FILE_END (&context[fileset]);
  1049. X      return ((char *) 0);
  1050. X   } else {
  1051. X      found_fspec[fileset][d_ffound.dsc$w_length] = '\0'; /* just in case */
  1052. X      p = found_fspec[fileset];
  1053. X      while (*p != ' ' && *p != '\0')
  1054. X         p++;
  1055. X      if (*p != '\0')
  1056. X         *p = '\0';
  1057. X      return (found_fspec[fileset]);
  1058. X   }
  1059. }
  1060. X
  1061. /*
  1062. Function vmsmkdir() converts the received directory name into VMS
  1063. format and then creates a directory.
  1064. */
  1065. int vmsmkdir (subdir)
  1066. char *subdir;
  1067. {
  1068. X   char *lastptr();
  1069. X   char *p;
  1070. X   char tmp[LFNAMESIZE];
  1071. X
  1072. X   p = subdir;
  1073. X
  1074. X   /* leading "/" => "[", otherwise => "[." */
  1075. X   if (*p == '/') {
  1076. X      strcpy (tmp, "[");
  1077. X      p++;
  1078. X   } else {
  1079. X      strcpy (tmp, "[.");
  1080. X      while (*p == '/' || *p == '.')
  1081. X         p++;
  1082. X   }
  1083. X
  1084. X   strcat (tmp, p);
  1085. X
  1086. X   /* 
  1087. X   VMS doesn't like dots in directory names, so we convert them to
  1088. X   underscores.  Leave first two characters untouched, because
  1089. X   we don't want to corrupt a leading "[." into "[_".
  1090. X   */
  1091. X   for (p = tmp + 2;  *p != '\0';  p++)
  1092. X      if (*p == '.')
  1093. X         *p = '_';
  1094. X
  1095. X   /* convert all slashes to dots */
  1096. X   for (p = tmp; *p != '\0';  p++)
  1097. X      if (*p == '/')
  1098. X         *p = '.';
  1099. X
  1100. X   /* Remove any trailing dot */
  1101. X   p = lastptr (tmp);
  1102. X   if (*p == '.')
  1103. X      *p = '\0';
  1104. X
  1105. X   /* append closing bracket */
  1106. X   strcat (tmp, "]");
  1107. #if 0
  1108. X   printf ("\nmaking directory \"%s\"\n", tmp);
  1109. #endif
  1110. X   return (mkdir (tmp, 0));
  1111. }
  1112. X
  1113. /*
  1114. Function spec_wild() transforms a pattern supplied on the command line into one
  1115. suitable for wildcard expansion in the most efficient way possible.  We change
  1116. each "?" to "%" but let "*" remain unchanged.  We also append a ".*" if the
  1117. pattern contains no dot, so "*" will be interpreted as "*.*" for VMS globbing. 
  1118. */
  1119. char *spec_wild (arg)
  1120. char *arg;
  1121. {
  1122. X   char *p;
  1123. #ifdef DEBUG
  1124. X   printf ("spec_wild: arg = [%s]\n", arg);
  1125. #endif
  1126. X   if (*lastptr (arg) == ']')      /* add *.* if no filename */
  1127. X      strcat (arg, "*.*");
  1128. X   p = nameptr (arg);              /* point p to filename part */
  1129. X
  1130. X   /* if no dot in name append ".*" */
  1131. X   if (strchr (p, '.') == NILPTR)
  1132. X      strcat (p, ".*");
  1133. X
  1134. X   for ( ; *p != '\0';  p++)        /* change every "?" to "%" */
  1135. X      if (*p == '?')
  1136. X         *p = '%';
  1137. #ifdef DEBUG
  1138. X   printf ("spec_wild: arg changed to [%s]\n", arg);
  1139. #endif
  1140. X   return (arg);
  1141. }
  1142. X
  1143. int zootrunc(f) FILE *f; { return 0; }
  1144. SHAR_EOF
  1145. chmod 0644 vms.c ||
  1146. echo 'restore of vms.c failed'
  1147. Wc_c="`wc -c < 'vms.c'`"
  1148. test 10243 -eq "$Wc_c" ||
  1149.     echo 'vms.c: original size 10243, current size' "$Wc_c"
  1150. fi
  1151. true || echo 'restore of vmsbugs.doc failed'
  1152. echo End of part 8, continue with part 9
  1153. exit 0
  1154.