home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 28 / amigaformatcd28.iso / -seriously_amiga- / archivers / arcppc / src / rcs / arcext.c,v < prev    next >
Text File  |  1998-04-23  |  8KB  |  405 lines

  1. head     1.5;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    hyc:1.5; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.5
  10. date     88.06.01.19.26.31;  author hyc;  state Exp;
  11. branches ;
  12. next     1.4;
  13.  
  14. 1.4
  15. date     88.06.01.15.32.51;  author hyc;  state Exp;
  16. branches ;
  17. next     1.3;
  18.  
  19. 1.3
  20. date     88.06.01.15.27.38;  author hyc;  state Exp;
  21. branches ;
  22. next     1.2;
  23.  
  24. 1.2
  25. date     88.04.11.17.59.09;  author hyc;  state Exp;
  26. branches ;
  27. next     1.1;
  28.  
  29. 1.1
  30. date     88.04.11.17.56.12;  author hyc;  state Exp;
  31. branches ;
  32. next     ;
  33.  
  34.  
  35. desc
  36. @@
  37.  
  38.  
  39. 1.5
  40. log
  41. @Changed compilation conditionals
  42. @
  43. text
  44. @/*
  45.  * $Header: arcext.c,v 1.4 88/06/01 15:32:51 hyc Locked $
  46.  */
  47.  
  48. /*
  49.  * ARC - Archive utility - ARCEXT
  50.  * 
  51.  * Version 2.19, created on 10/24/86 at 14:53:32
  52.  * 
  53.  * (C) COPYRIGHT 1985 by System Enhancement Associates; ALL RIGHTS RESERVED
  54.  * 
  55.  * By:  Thom Henderson
  56.  * 
  57.  * Description: This file contains the routines used to extract files from an
  58.  * archive.
  59.  * 
  60.  * Language: Computer Innovations Optimizing C86
  61.  */
  62. #include <stdio.h>
  63. #include "arc.h"
  64. #if    !MSDOS
  65. #include <ctype.h>
  66. #endif
  67.  
  68. void    openarc(), closearc(), setstamp();
  69. int    free(), match(), readhr(), unpack();
  70. char    *strcpy(), *strcat();
  71.  
  72. void
  73. extarc(num, arg, prt)        /* extract files from archive */
  74.     int             num;    /* number of arguments */
  75.     char           *arg[];    /* pointers to arguments */
  76.     int             prt;        /* true if printing */
  77. {
  78.     struct heads    hdr;    /* file header */
  79.     int             save;    /* true to save current file */
  80.     int             did[MAXARG];/* true when argument was used */
  81.     char           *i, *rindex();    /* string index */
  82.     char          **name, *malloc();    /* name pointer list,
  83.                          * allocator */
  84.     int             n;    /* index */
  85.     void            extfile();
  86.  
  87.     name = (char **) malloc(num * sizeof(char *));    /* get storage for name
  88.                              * pointers */
  89.  
  90.     for (n = 0; n < num; n++) {    /* for each argument */
  91.         did[n] = 0;    /* reset usage flag */
  92. #if    !MTS
  93.         if (!(i = rindex(arg[n], '\\')))    /* find start of name */
  94.             if (!(i = rindex(arg[n], '/')))
  95.                 if (!(i = rindex(arg[n], ':')))
  96.                     i = arg[n] - 1;
  97. #else
  98.         if (!(i = rindex(arg[n], sepchr[0])))
  99.             if (arg[n][0] != tmpchr[0])
  100.                 i = arg[n] - 1;
  101.             else
  102.                 i = arg[n];
  103. #endif
  104.         name[n] = i + 1;
  105.     }
  106.  
  107.  
  108.     openarc(0);        /* open archive for reading */
  109.  
  110.     if (num) {        /* if files were named */
  111.         while (readhdr(&hdr, arc)) {    /* while more files to check */
  112.             save = 0;    /* reset save flag */
  113.             for (n = 0; n < num; n++) {    /* for each template
  114.                              * given */
  115.                 if (match(hdr.name, name[n])) {
  116.                     save = 1;    /* turn on save flag */
  117.                     did[n] = 1;    /* turn on usage flag */
  118.                     break;    /* stop looking */
  119.                 }
  120.             }
  121.  
  122.             if (save)    /* extract if desired, else skip */
  123.                 extfile(&hdr, arg[n], prt);
  124.             else
  125.                 fseek(arc, hdr.size, 1);
  126.         }
  127.     } else
  128.         while (readhdr(&hdr, arc))    /* else extract all files */
  129.             extfile(&hdr, "", prt);
  130.  
  131.     closearc(0);        /* close archive after reading */
  132.  
  133.     if (note) {
  134.         for (n = 0; n < num; n++) {    /* report unused args */
  135.             if (!did[n]) {
  136.                 printf("File not found: %s\n", arg[n]);
  137.                 nerrs++;
  138.             }
  139.         }
  140.     }
  141.     free(name);
  142. }
  143.  
  144. void
  145. extfile(hdr, path, prt)        /* extract a file */
  146.     struct heads   *hdr;    /* pointer to header data */
  147.     char           *path;    /* pointer to path name */
  148.     int             prt;    /* true if printing */
  149. {
  150.     FILE           *f, *fopen();    /* extracted file, opener */
  151.     char            buf[STRLEN];    /* input buffer */
  152.     char            fix[STRLEN];    /* fixed name buffer */
  153.     char           *i, *rindex();    /* string index */
  154.  
  155.     if (prt) {        /* printing is much easier */
  156.         unpack(arc, stdout, hdr);    /* unpack file from archive */
  157.         printf("\f");    /* eject the form */
  158.         return;        /* see? I told you! */
  159.     }
  160.     strcpy(fix, path);    /* note path name template */
  161. #if    !MTS
  162.     if (*path) {
  163.     if (!(i = rindex(fix, '\\')))    /* find start of name */
  164.         if (!(i = rindex(fix, '/')))
  165.             if (!(i = rindex(fix, ':')))
  166.                 i = fix - 1;
  167.     } else i = fix -1;
  168. #else
  169.     if (!(i = rindex(fix, sepchr[0])))
  170.         if (fix[0] != tmpchr[0])
  171.             i = fix - 1;
  172.         else
  173.             i = fix;
  174. #endif
  175.     strcpy(i + 1, hdr->name);    /* replace template with name */
  176.  
  177.     if (note)
  178.         printf("Extracting file: %s\n", fix);
  179.  
  180.     if (warn && !overlay) {
  181.         if (f = fopen(fix, "r")) {    /* see if it exists */
  182.                 fclose(f);
  183.                 printf("WARNING: File %s already exists!", fix);
  184.                 fflush(stdout);
  185.                 while (1) {
  186.                     printf("  Overwrite it (y/n)? ");
  187.                     fflush(stdout);
  188.                     fgets(buf, STRLEN, stdin);
  189.                     *buf = toupper(*buf);
  190.                     if (*buf == 'Y' || *buf == 'N')
  191.                         break;
  192.                 }
  193.                 if (*buf == 'N') {
  194.                     printf("%s not extracted.\n", fix);
  195.                     fseek(arc, hdr->size, 1);
  196.                     return;
  197.                 }
  198.         }
  199.     }
  200. #if    !MTS
  201.     if (!(f = fopen(fix, "wb")))
  202. #else
  203.     {
  204.         fortran         create();
  205.         void        memset();
  206.         char            c_name[256];
  207.         struct crsize {
  208.             short           maxsize, cursize;
  209.         }               c_size;
  210.         char            c_vol[6];
  211.         int             c_type;
  212.         strcpy(c_name, fix);
  213.         strcat(c_name, " ");
  214.         c_size.maxsize = 0;
  215.         c_size.cursize = hdr->length / 4096 + 1;
  216.         memset(c_vol, 0, sizeof(c_vol));
  217.         c_type = 0x100;
  218.         create(c_name, &c_size, c_vol, &c_type);
  219.     }
  220.     if (image) {
  221.         f = fopen(fix, "wb");
  222.     } else
  223.         f = fopen(fix, "w");
  224.     if (!f)
  225. #endif
  226.     {
  227.         if (warn) {
  228.             printf("Cannot create %s\n", fix);
  229.             nerrs++;
  230.         }
  231.         fseek(arc, hdr->size, 1);
  232.         return;
  233.     }
  234.     /* now unpack the file */
  235.  
  236.     unpack(arc, f, hdr);    /* unpack file from archive */
  237. #if    MSDOS
  238.     setstamp(f, hdr->date, hdr->time);    /* set the proper date/time
  239.                          * stamp */
  240. #endif
  241.     fclose(f);        /* all done writing to file */
  242. #if    UNIX || GEMDOS
  243.     setstamp(fix, hdr->date, hdr->time);    /* use filename for stamp */
  244. #endif
  245. }
  246. @
  247.  
  248.  
  249. 1.4
  250. log
  251. @Merged Atari ST code
  252. @
  253. text
  254. @d2 1
  255. a2 1
  256.  * $Header: arcext.c,v 1.3 88/06/01 15:27:38 hyc Locked $
  257. d21 1
  258. a21 1
  259. #ifndef MSDOS
  260. d49 1
  261. a49 1
  262. #ifndef MTS
  263. d118 1
  264. a118 1
  265. #ifndef MTS
  266. d157 1
  267. a157 4
  268. #ifdef BSD
  269.     if (!(f = fopen(fix, "w")))
  270. #endif
  271. #ifdef    DOS
  272. d159 1
  273. a159 2
  274. #endif
  275. #ifdef MTS
  276. d194 1
  277. a194 1
  278. #ifdef MSDOS
  279. d199 2
  280. a200 5
  281. #ifdef BSD
  282.     setstamp(fix, hdr->date, hdr->time);    /* use filename for BSD stamp */
  283. #endif
  284. #ifdef    GEMDOS
  285.     setstamp(fix, hdr->date, hdr->time);    /* FIX ME */
  286. @
  287.  
  288.  
  289. 1.3
  290. log
  291. @Fix declarations
  292. @
  293. text
  294. @d2 1
  295. a2 1
  296.  * $Header: arcext.c,v 1.4 88/04/19 01:39:42 hyc Exp $
  297. d119 1
  298. d124 1
  299. d157 7
  300. a163 3
  301. #ifndef MTS
  302.     if (!(f = fopen(fix, "w"))) {
  303. #else
  304. d185 1
  305. a185 1
  306.     if (!f) {
  307. d187 1
  308. d205 3
  309. @
  310.  
  311.  
  312. 1.2
  313. log
  314. @re-synch with MTS, formatting
  315. @
  316. text
  317. @d2 1
  318. a2 11
  319.  * $Log:    arcext.c,v $
  320.  * Revision 1.1  88/04/11  17:56:12  hyc
  321.  * Initial revision
  322.  * 
  323.  * Revision 1.4  87/08/13  17:03:21  hyc
  324.  * Run thru the indent program...
  325.  *  Revision 1.3  87/07/21  11:39:59  hyc minor
  326.  * fixups
  327.  * 
  328.  * Revision 1.2  87/07/21  07:32:17  hyc added BSD goodies
  329.  * 
  330. d21 3
  331. d25 5
  332. a29 1
  333. INT
  334. d31 1
  335. a31 1
  336.     INT             num;    /* number of arguments */
  337. d33 1
  338. a33 1
  339. INT             prt;        /* true if printing */
  340. d36 2
  341. a37 2
  342.     INT             save;    /* true to save current file */
  343.     INT             did[25];/* true when argument was used */
  344. d41 2
  345. a42 2
  346.     INT             n;    /* index */
  347.     INT             extfile();
  348. d101 1
  349. a101 1
  350. INT
  351. d105 1
  352. a105 1
  353.     INT             prt;    /* true if printing */
  354. d108 2
  355. a109 2
  356.     char            buf[100];    /* input buffer */
  357.     char            fix[100];    /* fixed name buffer */
  358. a136 3
  359. #ifdef MTS
  360.             if ((buf[0] = fgetc(f)) != EOF) {    /* kludge for temp files */
  361. #endif
  362. d143 1
  363. a143 1
  364.                     fgets(buf, 100, stdin);
  365. a152 3
  366. #ifdef MTS
  367.             }
  368. #endif
  369. d160 1
  370. a176 1
  371.         fseek(f, 0, 0);
  372. @
  373.  
  374.  
  375. 1.1
  376. log
  377. @Initial revision
  378. @
  379. text
  380. @d2 4
  381. a5 1
  382.  * $Log:        arcext.c,v $
  383. d42 1
  384. a42 1
  385.     char          **name, *malloc();    /* name pointer list, *
  386. d47 2
  387. a48 2
  388.     name = (char **) malloc(num * sizeof(char *));
  389.     /* get storage for name * pointers */
  390. d73 1
  391. a73 1
  392.             for (n = 0; n < num; n++) {    /* for each template *
  393. d104 1
  394. a104 1
  395. static          INT
  396. d201 2
  397. a202 2
  398.     setstamp(f, hdr->date, hdr->time);
  399.     /* set the proper date/time * stamp */
  400. d206 1
  401. a206 2
  402.     setstamp(fix, hdr->date, hdr->time);
  403.     /* use filename for BSD stamp */
  404. @
  405.