From:	CSBVAX::MRGATE!info-vax-RELAY@KL.SRI.COM@SMTP  8-JUL-1988 20:35
To:	ARISIA::EVERHART
Subj:	ARC_C.SHAR03_OF_19


Received: from CORNELLC.CCS.CORNELL.EDU by KL.SRI.COM with TCP; Fri, 24 Jun 88 18:12:41 PDT
Received: from UNCAEDU.BITnet by CORNELLC.CCS.CORNELL.EDU ; Fri, 24 Jun 88 21:12:57 EDT
Received: from Stasis.MRC.AdhocNet.CA by UcEdu.UNCA.AdhocNet.CA with DECNET ;
          Fri, 24 Jun 88 09:28:27 MDT
Date:    Fri, 24 Jun 88 09:23:21 MDT
From:     ewilts%Ins.MRC.AdhocNet.CA%Stasis.MRC.AdhocNet.CA%UNCAEDU.@CORNELLC.CCS.CORNELL.EDU
         BITnet (Ed Wilts)
Message-Id: <880624092323.023@Ins.MRC.AdhocNet.CA>
Subject: ARC_C.SHAR03_OF_19
To:       info-vax@kl.sri.com
X-ST-Vmsmail-To: INFOVAX

$Part03:
$ File_is="ARCCVT.C"
$ Check_Sum_is=1752392383
$ Copy SYS$Input VMS_SHAR_DUMMY.DUMMY
Xstatic char *RCSid = "$Header: arccvt.c,v 1.2 86/07/15 07:52:46 turner Exp $";
X
X/*
X * $Log:`009arccvt.c,v $
X * Hack-attack 1.3  86/12/20  01:23:45  wilhite@usceast.uucp
X * `009Bludgeoned into submission for VAX 11/780 BSD4.2
X *`009(ugly code, but fewer core dumps)
X *
X * Revision 1.2  86/07/15  07:52:46  turner
X *
X *
X * Revision 1.1  86/06/26  14:59:56  turner
X * initial version
X *
X *
X */
X
X/*  ARC - Archive utility - ARCCVT
X
X$define(tag,$$segment(@1,$$index(@1,=)+1))#
X$define(version,Version $tag(
XTED_VERSION DB =1.16), created on $tag(
XTED_DATE DB =02/03/86) at $tag(
XTED_TIME DB =22:53:02))#
X$undefine(tag)#
X    $version
X
X(C) COPYRIGHT 1985 by System Enhancement Associates; ALL RIGHTS RESERVED
X
X    By:  Thom Henderson
X
X    Description:
X         This file contains the routines used to convert archives to use
X         newer file storage methods.
X
X    Language:
X         Computer Innovations Optimizing C86
X*/
X#include <stdio.h>
X#include "arc.h"
X
Xstatic char tempname[STRLEN];         /* temp file name */
X
XINT cvtarc(num,arg)                        /* convert archive */
XINT num;                               /* number of arguments */
Xchar *arg[];                           /* pointers to arguments */
X{
X    struct heads hdr;                  /* file header */
X INT cvt;                           /* true to convert current file */
X INT did[MAXARG];                  /* true when argument was used */
X INT n;                             /* index */
X    char *makefnam();                  /* filename fixer */
X    FILE *fopen();                     /* file opener */
X    INT cvtfile();
X
X    if(arctemp)                   /* use temp area if specified */
X         sprintf(tempname,"%s.CVT",arctemp);
X    else makefnam("$ARCTEMP.CVT",arcname,tempname);
X
X    openarc(1);                        /* open archive for changes */
X
X    for(n=0; n<num; n++)               /* for each argument */
X         did[n] = 0;                   /* reset usage flag */
X    rempath(num,arg);                  /* strip off paths */
X
X    if(num)                            /* if files were named */
X    {    while(readhdr(&hdr,arc))      /* while more files to check */
X         {    cvt = 0;                 /* reset convert flag */
X              for(n=0; n<num; n++)     /* for each template given */
X              {    if(match(hdr.name,arg[n]))
X                   {    cvt = 1;       /* turn on convert flag */
X                        did[n] = 1;    /* turn on usage flag */
X                        break;         /* stop looking */
X                   }
X              }
X
X              if(cvt)                  /* if converting this one */
X                   cvtfile(&hdr);      /* then do it */
X              else                     /* else just copy it */
X              {    writehdr(&hdr,new);
X                   filecopy(arc,new,hdr.size);
X              }
X         }
X    }
X
X    else while(readhdr(&hdr,arc))      /* else convert all files */
X         cvtfile(&hdr);
X
X    hdrver = 0;                        /* archive EOF type */
X    writehdr(&hdr,new);                /* write out our end marker */
X    closearc(1);                       /* close archive after changes */
X
X    if(note)
X    {    for(n=0; n<num; n++)          /* report unused args */
X         {    if(!did[n])
X              {    printf("File not found: %s\n",arg[n]);
X                   nerrs++;
X              }
X         }
X    }
X}
X
Xstatic INT cvtfile(hdr)                    /* convert a file */
Xstruct heads *hdr;                     /* pointer to header data */
X{
X    long starts, ftell();              /* where the file goes */
X    FILE *tmp, *fopen();               /* temporary file */
X
X    if(!(tmp=fopen(tempname,"w+")))
X         abort("Unable to create temporary file %s",tempname);
X
X    if(note)
X     { printf("Converting file: %-12s   reading, ",hdr->name); fflush(stdout);}
X
X    unpack(arc,tmp,hdr);               /* unpack the entry */
X    fseek(tmp,0L,0);                   /* reset temp for reading */
X    starts = ftell(new);               /* note where header goes */
X    hdrver = ARCVER;                   /* anything but end marker */
X    writehdr(hdr,new);                 /* write out header skeleton */
X    pack(tmp,new,hdr);                 /* pack file into archive */
X    fseek(new,starts,0);               /* move back to header skeleton */
X    writehdr(hdr,new);                 /* write out real header */
X    fseek(new,hdr->size,1);            /* skip over data to next header */
X    fclose(tmp);                       /* all done with the file */
X    if(unlink(tempname) && warn)
X    {    printf("Cannot unsave %s\n",tempname);
X         nerrs++;
X    }
X}
X
$ GoSub Convert_File
$ File_is="ARCDEL.C"
$ Check_Sum_is=1634934886
$ Copy SYS$Input VMS_SHAR_DUMMY.DUMMY
Xstatic char *RCSid = "$Header: arcdel.c,v 1.2 86/07/15 07:52:53 turner Exp $";
X
X/*
X * $Log:`009arcdel.c,v $
X * Hack-attack 1.3  86/12/20  01:23:45  wilhite@usceast.uucp
X * `009Bludgeoned into submission for VAX 11/780 BSD4.2
X *`009(ugly code, but fewer core dumps)
X *
X * Revision 1.2  86/07/15  07:52:53  turner
X *
X *
X * Revision 1.1  86/06/26  15:00:04  turner
X * initial version
X *
X *
X */
X
X/*  ARC - Archive utility - ARCDEL
X
X$define(tag,$$segment(@1,$$index(@1,=)+1))#
X$define(version,Version $tag(
XTED_VERSION DB =2.09), created on $tag(
XTED_DATE DB =02/03/86) at $tag(
XTED_TIME DB =22:53:27))#
X$undefine(tag)#
X    $version
X
X(C) COPYRIGHT 1985 by System Enhancement Associates; ALL RIGHTS RESERVED
X
X    By:  Thom Henderson
X
X    Description:
X         This file contains the routines used to delete entries
X         in an archive.
X
X    Language:
X         Computer Innovations Optimizing C86
X*/
X#include <stdio.h>
X#include "arc.h"
X
XINT delarc(num,arg)                        /* remove files from archive */
XINT num;                               /* number of arguments */
Xchar *arg[];                           /* pointers to arguments */
X{
X    struct heads hdr;                  /* header data */
X INT del;                           /* true to delete a file */
X INT did[MAXARG];                  /* true when argument used */
X INT n;                             /* index */
X
X    if(!num)                           /* she must specify which */
X         abort("You must tell me which files to delete!");
X
X    for(n=0; n<num; n++)               /* for each argument */
X         did[n] = 0;                   /* reset usage flag */
X    rempath(num,arg);                  /* strip off paths */
X
X    openarc(1);                        /* open archive for changes */
X
X    while(readhdr(&hdr,arc))           /* while more entries in archive */
X    {    del = 0;                      /* reset delete flag */
X         for(n=0; n<num; n++)          /* for each template given */
X         {    if(match(hdr.name,arg[n]))
X              {    del = 1;            /* turn on delete flag */
X                   did[n] = 1;         /* turn on usage flag */
X                   break;              /* stop looking */
X              }
X         }
X
X         if(del)                       /* skip over unwanted files */
X         {    fseek(arc,hdr.size,1);
X              if(note)
X                   printf("Deleting file: %s\n",hdr.name);
X         }
X         else                          /* else copy over file data */
X         {    writehdr(&hdr,new);      /* write out header and file */
X              filecopy(arc,new,hdr.size);
X         }
X    }
X
X    hdrver = 0;                        /* special end of archive type */
X    writehdr(&hdr,new);                /* write out archive end marker */
X    closearc(1);                       /* close archive after changes */
X
X    if(note)
X    {    for(n=0; n<num; n++)          /* report unused arguments */
X         {    if(!did[n])
X              {    printf("File not found: %s\n",arg[n]);
X                   nerrs++;
X              }
X         }
X    }
X}
X
$ GoSub Convert_File
$ Goto Part04
