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

  1. head     1.9;
  2. branch   ;
  3. access   ;
  4. symbols  patch1:1.9 arc521:1.5;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.9
  10. date     88.07.31.18.54.55;  author hyc;  state Exp;
  11. branches ;
  12. next     1.8;
  13.  
  14. 1.8
  15. date     88.06.13.00.42.59;  author hyc;  state Exp;
  16. branches ;
  17. next     1.7;
  18.  
  19. 1.7
  20. date     88.06.13.00.41.41;  author hyc;  state Exp;
  21. branches ;
  22. next     1.6;
  23.  
  24. 1.6
  25. date     88.06.01.19.57.18;  author hyc;  state Exp;
  26. branches ;
  27. next     1.5;
  28.  
  29. 1.5
  30. date     88.06.01.18.14.58;  author hyc;  state Exp;
  31. branches ;
  32. next     1.4;
  33.  
  34. 1.4
  35. date     88.06.01.16.37.29;  author hyc;  state Exp;
  36. branches ;
  37. next     1.3;
  38.  
  39. 1.3
  40. date     88.06.01.16.32.09;  author hyc;  state Exp;
  41. branches ;
  42. next     1.2;
  43.  
  44. 1.2
  45. date     88.04.11.18.42.09;  author hyc;  state Exp;
  46. branches ;
  47. next     1.1;
  48.  
  49. 1.1
  50. date     88.04.11.18.39.02;  author hyc;  state Exp;
  51. branches ;
  52. next     ;
  53.  
  54.  
  55. desc
  56. @@
  57.  
  58.  
  59. 1.9
  60. log
  61. @Fix args to fopen(), fix buffering on MTS
  62. @
  63. text
  64. @/*
  65.  * $Header: arcsvc.c,v 1.8 88/06/13 00:42:59 hyc Locked $
  66.  */
  67.  
  68. /*  ARC - Archive utility - ARCSVC
  69.  
  70.     Version 2.23, created on 04/22/87 at 13:10:10
  71.  
  72. (C) COPYRIGHT 1985-87 by System Enhancement Associates; ALL RIGHTS RESERVED
  73.  
  74.     By:     Thom Henderson
  75.  
  76.     Description:
  77.      This file contains service routines needed to maintain an archive.
  78.  
  79.     Language:
  80.      Computer Innovations Optimizing C86
  81. */
  82. #include <stdio.h>
  83. #include "arc.h"
  84. #if    MTS
  85. #include <mts.h>
  86. #endif
  87.  
  88. void    abort(), setstamp();
  89. int    unlink();
  90.  
  91. void
  92. openarc(chg)            /* open archive */
  93.     int             chg;    /* true to open for changes */
  94. {
  95.     FILE           *fopen();/* file opener */
  96.  
  97.     if (!(arc = fopen(arcname, OPEN_R))) {
  98.         if (chg) {
  99.             if (note)
  100.                 printf("Creating new archive: %s\n", arcname);
  101.         }
  102.         else
  103.             abort("Archive not found: %s", arcname);
  104.     }
  105. #if    MTS    /* allow reading archives of max MTS record length */
  106.     else {
  107.         char *buffer, *malloc();
  108.         int inlen;
  109.         struct GDDSECT *region;
  110.  
  111.         region=gdinfo(arc->_fd._fdub);
  112.         inlen=region->GDINLEN;
  113.         buffer=malloc(inlen);
  114.         setbuf(arc, buffer);
  115.         arc->_bufsiz=inlen;
  116.     }
  117. #endif
  118.     if (chg) {        /* if opening for changes */
  119.         if (!(new = fopen(newname, OPEN_W)))
  120.             abort("Cannot create archive copy: %s", newname);
  121.  
  122.     changing = chg;        /* note if open for changes */
  123.     }
  124. }
  125.  
  126. void
  127. closearc(chg)            /* close an archive */
  128.     int             chg;    /* true if archive was changed */
  129. {
  130.     if (arc) {        /* if we had an initial archive */
  131.         fclose(arc);
  132. #if    !MTS
  133.         if (kludge)    /* kludge to update timestamp */
  134.             setstamp(arcname, olddate, oldtime);
  135. #endif
  136.     }
  137.     if (chg) {        /* if things have changed */
  138.         fclose(new);    /* close the new copy */
  139.         if (arc) {    /* if we had an original archive */
  140.             if (keepbak) {    /* if a backup is wanted */
  141.                 unlink(bakname);    /* erase any old copies */
  142.                 if (move(arcname, bakname))
  143.                     abort("Cannot rename %s to %s", arcname, bakname);
  144.                 printf("Keeping backup archive: %s\n", bakname);
  145.             } else if (unlink(arcname))
  146.                 abort("Cannot delete old archive: %s", arcname);
  147.         }
  148.         if (move(newname, arcname))
  149.             abort("Cannot move %s to %s", newname, arcname);
  150. #if    !MTS
  151.         setstamp(arcname, arcdate, arctime);
  152. #endif
  153.     }
  154. }
  155.  
  156. /*
  157.  * CRC computation logic
  158.  * 
  159.  * The logic for this method of calculating the CRC 16 bit polynomial is taken
  160.  * from an article by David Schwaderer in the April 1985 issue of PC Tech
  161.  * Journal.
  162.  */
  163.  
  164. static short      crctab[] =    /* CRC lookup table */
  165. {
  166.  0x0000, 0xC0C1, 0xC181, 0x0140, 0xC301, 0x03C0, 0x0280, 0xC241,
  167.  0xC601, 0x06C0, 0x0780, 0xC741, 0x0500, 0xC5C1, 0xC481, 0x0440,
  168.  0xCC01, 0x0CC0, 0x0D80, 0xCD41, 0x0F00, 0xCFC1, 0xCE81, 0x0E40,
  169.  0x0A00, 0xCAC1, 0xCB81, 0x0B40, 0xC901, 0x09C0, 0x0880, 0xC841,
  170.  0xD801, 0x18C0, 0x1980, 0xD941, 0x1B00, 0xDBC1, 0xDA81, 0x1A40,
  171.  0x1E00, 0xDEC1, 0xDF81, 0x1F40, 0xDD01, 0x1DC0, 0x1C80, 0xDC41,
  172.  0x1400, 0xD4C1, 0xD581, 0x1540, 0xD701, 0x17C0, 0x1680, 0xD641,
  173.  0xD201, 0x12C0, 0x1380, 0xD341, 0x1100, 0xD1C1, 0xD081, 0x1040,
  174.  0xF001, 0x30C0, 0x3180, 0xF141, 0x3300, 0xF3C1, 0xF281, 0x3240,
  175.  0x3600, 0xF6C1, 0xF781, 0x3740, 0xF501, 0x35C0, 0x3480, 0xF441,
  176.  0x3C00, 0xFCC1, 0xFD81, 0x3D40, 0xFF01, 0x3FC0, 0x3E80, 0xFE41,
  177.  0xFA01, 0x3AC0, 0x3B80, 0xFB41, 0x3900, 0xF9C1, 0xF881, 0x3840,
  178.  0x2800, 0xE8C1, 0xE981, 0x2940, 0xEB01, 0x2BC0, 0x2A80, 0xEA41,
  179.  0xEE01, 0x2EC0, 0x2F80, 0xEF41, 0x2D00, 0xEDC1, 0xEC81, 0x2C40,
  180.  0xE401, 0x24C0, 0x2580, 0xE541, 0x2700, 0xE7C1, 0xE681, 0x2640,
  181.  0x2200, 0xE2C1, 0xE381, 0x2340, 0xE101, 0x21C0, 0x2080, 0xE041,
  182.  0xA001, 0x60C0, 0x6180, 0xA141, 0x6300, 0xA3C1, 0xA281, 0x6240,
  183.  0x6600, 0xA6C1, 0xA781, 0x6740, 0xA501, 0x65C0, 0x6480, 0xA441,
  184.  0x6C00, 0xACC1, 0xAD81, 0x6D40, 0xAF01, 0x6FC0, 0x6E80, 0xAE41,
  185.  0xAA01, 0x6AC0, 0x6B80, 0xAB41, 0x6900, 0xA9C1, 0xA881, 0x6840,
  186.  0x7800, 0xB8C1, 0xB981, 0x7940, 0xBB01, 0x7BC0, 0x7A80, 0xBA41,
  187.  0xBE01, 0x7EC0, 0x7F80, 0xBF41, 0x7D00, 0xBDC1, 0xBC81, 0x7C40,
  188.  0xB401, 0x74C0, 0x7580, 0xB541, 0x7700, 0xB7C1, 0xB681, 0x7640,
  189.  0x7200, 0xB2C1, 0xB381, 0x7340, 0xB101, 0x71C0, 0x7080, 0xB041,
  190.  0x5000, 0x90C1, 0x9181, 0x5140, 0x9301, 0x53C0, 0x5280, 0x9241,
  191.  0x9601, 0x56C0, 0x5780, 0x9741, 0x5500, 0x95C1, 0x9481, 0x5440,
  192.  0x9C01, 0x5CC0, 0x5D80, 0x9D41, 0x5F00, 0x9FC1, 0x9E81, 0x5E40,
  193.  0x5A00, 0x9AC1, 0x9B81, 0x5B40, 0x9901, 0x59C0, 0x5880, 0x9841,
  194.  0x8801, 0x48C0, 0x4980, 0x8941, 0x4B00, 0x8BC1, 0x8A81, 0x4A40,
  195.  0x4E00, 0x8EC1, 0x8F81, 0x4F40, 0x8D01, 0x4DC0, 0x4C80, 0x8C41,
  196.  0x4400, 0x84C1, 0x8581, 0x4540, 0x8701, 0x47C0, 0x4680, 0x8641,
  197.  0x8201, 0x42C0, 0x4380, 0x8341, 0x4100, 0x81C1, 0x8081, 0x4040
  198. };
  199.  
  200. int
  201. addcrc(crc, c)            /* update a CRC check */
  202.     int             crc;    /* running CRC value */
  203.     unsigned char   c;    /* character to add */
  204. {
  205.     return ((crc >> 8) & 0x00ff) ^ crctab[(crc ^ c) & 0x00ff];
  206. }
  207. @
  208.  
  209.  
  210. 1.8
  211. log
  212. @Added MTS code to allow reading .ARC files with nonstandard record
  213. lengths.
  214. @
  215. text
  216. @d2 1
  217. a2 1
  218.  * $Header: arcsvc.c,v 1.7 88/06/13 00:41:41 hyc Locked $
  219. d34 1
  220. a34 1
  221.     if (!(arc = fopen(arcname, "rb"))) {
  222. d48 1
  223. a48 1
  224.         region=gdinfo(arc->_fd);
  225. d56 1
  226. a56 1
  227.         if (!(new = fopen(newname, "wb")))
  228. d69 1
  229. a70 1
  230. #if    !MTS
  231. @
  232.  
  233.  
  234. 1.7
  235. log
  236. @Changed setstamp, rename stuff...
  237. @
  238. text
  239. @d2 1
  240. a2 1
  241.  * $Header: arcsvc.c,v 1.6 88/06/01 19:57:18 hyc Locked $
  242. d21 3
  243. d42 13
  244. @
  245.  
  246.  
  247. 1.6
  248. log
  249. @Changed compilation conditionals
  250. @
  251. text
  252. @d2 1
  253. a2 1
  254.  * $Header: arcsvc.c,v 1.5 88/06/01 18:14:58 hyc Locked $
  255. d52 1
  256. d54 3
  257. a56 2
  258.             setstamp(arc, olddate, oldtime);
  259.         fclose(arc);    /* then close it */
  260. a58 3
  261. #if    MSDOS
  262.         setstamp(new, arcdate, arctime);
  263. #endif
  264. a59 3
  265. #if    UNIX
  266.         setstamp(newname, arcdate, arctime);
  267. #endif
  268. d63 1
  269. a63 1
  270.                 if (rename(arcname, bakname))
  271. d69 3
  272. a71 3
  273.         if (rename(newname, arcname))
  274.             abort("Cannot rename %s to %s", newname, arcname);
  275. #if    GEMDOS
  276. @
  277.  
  278.  
  279. 1.5
  280. log
  281. @Merge ARC 5.21 changes
  282. @
  283. text
  284. @d2 1
  285. a2 1
  286.  * $Header: arcsvc.c,v 1.4 88/06/01 16:37:29 hyc Locked $
  287. d57 1
  288. a57 1
  289. #ifdef MSDOS
  290. d61 1
  291. a61 1
  292. #ifdef BSD
  293. d75 1
  294. a75 1
  295. #ifdef    GEMDOS
  296. @
  297.  
  298.  
  299. 1.4
  300. log
  301. @Merge Atari ST code
  302. @
  303. text
  304. @d2 1
  305. a2 1
  306.  * $Header: arcsvc.c,v 1.3 88/06/01 16:32:09 hyc Locked $
  307. d5 14
  308. a18 14
  309. /*
  310.  * ARC - Archive utility - ARCSVC
  311.  * 
  312.  * Version 2.20, created on 10/24/86 at 12:17:00
  313.  * 
  314.  * (C) COPYRIGHT 1985,86 by System Enhancement Associates; ALL RIGHTS RESERVED
  315.  * 
  316.  * By:  Thom Henderson
  317.  * 
  318.  * Description: This file contains service routines needed to maintain an
  319.  * archive.
  320.  * 
  321.  * Language: Computer Innovations Optimizing C86
  322.  */
  323. d32 4
  324. a35 2
  325.         if (chg)
  326.             printf("Creating new archive: %s\n", arcname);
  327. d42 2
  328. @
  329.  
  330.  
  331. 1.3
  332. log
  333. @Fix declarations
  334. @
  335. text
  336. @d2 1
  337. a2 1
  338.  * $Header: arcsvc.c,v 1.3 88/04/19 01:40:24 hyc Exp $
  339. a59 1
  340.  
  341. a61 10
  342. #ifdef BSD
  343.                 char           *buf;
  344.                 buf = (char *) malloc((5 + strlen(arcname) + strlen(bakname)) * sizeof(char));
  345.                 *buf = '\0';
  346.                 strcat(buf, "mv ");
  347.                 strcat(buf, arcname);
  348.                 strcat(buf, " ");
  349.                 strcat(buf, bakname);
  350.                 if (system(buf))
  351. #else
  352. a63 1
  353. #endif
  354. a65 3
  355. #ifdef BSD
  356.                 free(buf);
  357. #endif
  358. a68 11
  359. #ifdef BSD
  360.         {
  361.             char           *buf;
  362.             buf = (char *) malloc((5 + strlen(newname) + strlen(arcname)) * sizeof(char));
  363.             *buf = '\0';
  364.             strcat(buf, "mv ");
  365.             strcat(buf, newname);
  366.             strcat(buf, " ");
  367.             strcat(buf, arcname);
  368.             if (system(buf))
  369. #else
  370. d70 3
  371. a73 3
  372.             abort("Cannot rename %s to %s", newname, arcname);
  373. #ifdef BSD
  374.         free(buf);
  375. a74 2
  376. #endif
  377. }
  378. @
  379.  
  380.  
  381. 1.2
  382. log
  383. @re-synch with MTS...
  384. @
  385. text
  386. @d2 1
  387. a2 18
  388.  * $Log:    arcsvc.c,v $
  389.  * Revision 1.1  88/04/11  18:39:02  hyc
  390.  * Initial revision
  391.  * 
  392.  * Revision 1.2  87/12/19  04:28:54  hyc
  393.  * fixing indent problems
  394.  * 
  395.  * Revision 1.1  87/12/19  04:27:04  hyc
  396.  * Initial revision
  397.  * 
  398.  * Revision 1.4  87/08/13  17:05:58  hyc
  399.  * Run thru indent, fixed some signed vs. unsigned problems
  400.  * with bp <-> buf, and inbuf and localbuf...
  401.  *  Revision 1.3  87/07/21  11:42:06  hyc *** empty
  402.  * log message ***
  403.  * 
  404.  * Revision 1.2  87/07/21  09:22:03  hyc *** empty log message ***
  405.  * 
  406. d22 4
  407. a25 1
  408. INT
  409. d27 1
  410. a27 1
  411.     INT             chg;    /* true to open for changes */
  412. d43 1
  413. a43 1
  414. INT
  415. d45 1
  416. a45 1
  417.     INT             chg;    /* true if archive was changed */
  418. d113 1
  419. a113 1
  420. static INT      crctab[] =    /* CRC lookup table */
  421. d149 1
  422. a149 1
  423. INT
  424. d151 1
  425. a151 1
  426.     INT             crc;    /* running CRC value */
  427. @
  428.  
  429.  
  430. 1.1
  431. log
  432. @Initial revision
  433. @
  434. text
  435. @d3 3
  436. a38 3
  437. #ifdef MTS
  438. #define RNAME _renm
  439.  
  440. a39 21
  441. _renm(oldnam, newnam)
  442.     char           *oldnam, *newnam;
  443. {
  444.     char            oldbuf[256], newbuf[256];
  445. /*      fortran rename();  */
  446.  
  447.     strcpy(oldbuf, oldnam);
  448.     strcpy(newbuf, newnam);
  449.     strcat(oldbuf, " ");
  450.     strcat(newbuf, " ");
  451.     rename(oldbuf, newbuf);
  452.     if (RETCODE)
  453.         return (-1);
  454.     else
  455.         return (0);
  456. }
  457. #else
  458. #define RNAME rename
  459. #endif
  460.  
  461. INT
  462. a50 16
  463. #ifdef MTS
  464.     {
  465.         int             c;
  466.         c = fgetc(arc);
  467.         if (c != EOF)
  468.             ungetc(c, arc);
  469.         else {
  470.             fclose(arc);
  471.             arc = NULL;
  472.             unlink(arcname);
  473.             if (!chg)
  474.                 abort("Archive not found: %s", arcname);
  475.         }
  476.     }
  477. #endif
  478.  
  479. a53 3
  480. #ifdef MTS
  481.         fseek(new, 0, 0);
  482. #endif
  483. a54 3
  484. #ifdef MTS
  485.     fseek(arc, 0, 0);
  486. #endif
  487. d88 1
  488. a88 1
  489.                 if (RNAME(arcname, bakname))
  490. d109 1
  491. a109 1
  492.         if (RNAME(newname, arcname))
  493. @
  494.