home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume1 / 8707 / 64 / arccvt.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-07-13  |  4.5 KB  |  128 lines

  1. static char *RCSid = "$Header: arccvt.c,v 1.2 86/07/15 07:52:46 turner Exp $";
  2.  
  3. /*
  4.  * $Log:    arccvt.c,v $
  5.  * Hack-attack 1.3  86/12/20  01:23:45  wilhite@usceast.uucp
  6.  *     Bludgeoned into submission for VAX 11/780 BSD4.2
  7.  *    (ugly code, but fewer core dumps)
  8.  *
  9.  * Revision 1.2  86/07/15  07:52:46  turner
  10.  * 
  11.  * Revision 1.1  86/06/26  14:59:56  turner
  12.  * initial version
  13.  * 
  14.  */
  15.  
  16. /*  ARC - Archive utility - ARCCVT
  17.  
  18. $define(tag,$$segment(@1,$$index(@1,=)+1))#
  19. $define(version,Version $tag(
  20. TED_VERSION DB =1.16), created on $tag(
  21. TED_DATE DB =02/03/86) at $tag(
  22. TED_TIME DB =22:53:02))#
  23. $undefine(tag)#
  24.     $version
  25.  
  26. (C) COPYRIGHT 1985 by System Enhancement Associates; ALL RIGHTS RESERVED
  27.  
  28.     By:  Thom Henderson
  29.  
  30.     Description:
  31.          This file contains the routines used to convert archives to use
  32.          newer file storage methods.
  33.  
  34.     Language:
  35.          Computer Innovations Optimizing C86
  36. */
  37. #include <stdio.h>
  38. #include "arc.h"
  39.  
  40. static char tempname[STRLEN];         /* temp file name */
  41.  
  42. INT cvtarc(num,arg)                        /* convert archive */
  43. INT num;                               /* number of arguments */
  44. char *arg[];                           /* pointers to arguments */
  45. {
  46.     struct heads hdr;                  /* file header */
  47.  INT cvt;                           /* true to convert current file */
  48.  INT did[MAXARG];                  /* true when argument was used */
  49.  INT n;                             /* index */
  50.     char *makefnam();                  /* filename fixer */
  51.     FILE *fopen();                     /* file opener */
  52.     INT cvtfile();
  53.  
  54.     if(arctemp)                   /* use temp area if specified */
  55.          sprintf(tempname,"%s.CVT",arctemp);
  56.     else makefnam("$ARCTEMP.CVT",arcname,tempname);
  57.  
  58.     openarc(1);                        /* open archive for changes */
  59.  
  60.     for(n=0; n<num; n++)               /* for each argument */
  61.          did[n] = 0;                   /* reset usage flag */
  62.     rempath(num,arg);                  /* strip off paths */
  63.  
  64.     if(num)                            /* if files were named */
  65.     {    while(readhdr(&hdr,arc))      /* while more files to check */
  66.          {    cvt = 0;                 /* reset convert flag */
  67.               for(n=0; n<num; n++)     /* for each template given */
  68.               {    if(match(hdr.name,arg[n]))
  69.                    {    cvt = 1;       /* turn on convert flag */
  70.                         did[n] = 1;    /* turn on usage flag */
  71.                         break;         /* stop looking */
  72.                    }
  73.               }
  74.  
  75.               if(cvt)                  /* if converting this one */
  76.                    cvtfile(&hdr);      /* then do it */
  77.               else                     /* else just copy it */
  78.               {    writehdr(&hdr,new);
  79.                    filecopy(arc,new,hdr.size);
  80.               }
  81.          }
  82.     }
  83.  
  84.     else while(readhdr(&hdr,arc))      /* else convert all files */
  85.          cvtfile(&hdr);
  86.  
  87.     hdrver = 0;                        /* archive EOF type */
  88.     writehdr(&hdr,new);                /* write out our end marker */
  89.     closearc(1);                       /* close archive after changes */
  90.  
  91.     if(note)
  92.     {    for(n=0; n<num; n++)          /* report unused args */
  93.          {    if(!did[n])
  94.               {    printf("File not found: %s\n",arg[n]);
  95.                    nerrs++;
  96.               }
  97.          }
  98.     }
  99. }
  100.  
  101. static INT cvtfile(hdr)                    /* convert a file */
  102. struct heads *hdr;                     /* pointer to header data */
  103. {
  104.     long starts, ftell();              /* where the file goes */
  105.     FILE *tmp, *fopen();               /* temporary file */
  106.  
  107.     if(!(tmp=fopen(tempname,"w+")))
  108.          abort("Unable to create temporary file %s",tempname);
  109.  
  110.     if(note)
  111.      { printf("Converting file: %-12s   reading, ",hdr->name); fflush(stdout);}
  112.  
  113.     unpack(arc,tmp,hdr);               /* unpack the entry */
  114.     fseek(tmp,0L,0);                   /* reset temp for reading */
  115.     starts = ftell(new);               /* note where header goes */
  116.     hdrver = ARCVER;                   /* anything but end marker */
  117.     writehdr(hdr,new);                 /* write out header skeleton */
  118.     pack(tmp,new,hdr);                 /* pack file into archive */
  119.     fseek(new,starts,0);               /* move back to header skeleton */
  120.     writehdr(hdr,new);                 /* write out real header */
  121.     fseek(new,hdr->size,1);            /* skip over data to next header */
  122.     fclose(tmp);                       /* all done with the file */
  123.     if(unlink(tempname) && warn)
  124.     {    printf("Cannot unsave %s\n",tempname);
  125.          nerrs++;
  126.     }
  127. }
  128.