home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PROGRAMS / UTILS / COMPRESS / ARC520S.ZIP / ARCCVT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1986-10-23  |  4.1 KB  |  107 lines

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