[comp.os.vms] ARC_C.SHAR11_OF_19

ewilts%Ins.MRC.AdhocNet.CA%Stasis.MRC.AdhocNet.CA%UNCAEDU.@CORNELLC.CCS.CORNELL.EDU.BITNET (Ed Wilts) (06/24/88)

$Part11:
$ File_is="ARCRUN.C"
$ Check_Sum_is=6780394
$ Copy SYS$Input VMS_SHAR_DUMMY.DUMMY
Xstatic char *RCSid = "$Header: arcrun.c,v 1.2 86/07/15 07:53:55 turner Exp $";
X
X/*
X * $Log:`009arcrun.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:53:55  turner
X *
X *
X * Revision 1.1  86/06/26  15:00:40  turner
X * initial version
X *
X *
X */
X
X/*  ARC - Archive utility - ARCRUN
X
X$define(tag,$$segment(@1,$$index(@1,=)+1))#
X$define(version,Version $tag(
XTED_VERSION DB =1.17), created on $tag(
XTED_DATE DB =02/03/86) at $tag(
XTED_TIME DB =22:59:06))#
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 "run" a file
X         which is stored in an archive.  At present, all we really do
X         is (a) extract a temporary file, (b) give its name as a system
X         command, and then (c) delete the file.
X
X    Language:
X         Computer Innovations Optimizing C86
X*/
X#include <stdio.h>
X#include "arc.h"
X
XINT runarc(num,arg)                        /* run file from archive */
XINT num;                               /* number of arguments */
Xchar *arg[];                           /* pointers to arguments */
X{
X    struct heads hdr;                  /* file header */
X INT run;                           /* true to run current file */
X INT did[MAXARG];                  /* true when argument was used */
X INT n;                             /* index */
X    char *makefnam();                  /* filename fixer */
X    char buf[STRLEN];                 /* filename buffer */
X    FILE *fopen();                     /* file opener */
X    INT runfile();
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(0);                        /* open archive for reading */
X
X    if(num)                            /* if files were named */
X    {    while(readhdr(&hdr,arc))      /* while more files to check */
X         {    run = 0;                 /* reset run flag */
X              for(n=0; n<num; n++)     /* for each template given */
X              {    if(match(hdr.name,makefnam(arg[n],".*",buf)))
X                   {    run = 1;       /* turn on run flag */
X                        did[n] = 1;    /* turn on usage flag */
X                        break;         /* stop looking */
X                   }
X              }
X
X              if(run)                  /* if running this one */
X                   runfile(&hdr);      /* then do it */
X              else                     /* else just skip it */
X                   fseek(arc,hdr.size,1);
X         }
X    }
X
X    else while(readhdr(&hdr,arc))      /* else run all files */
X         runfile(&hdr);
X
X    closearc(0);                       /* 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 runfile(hdr)                    /* run a file */
Xstruct heads *hdr;                     /* pointer to header data */
X{
X    FILE *tmp, *fopen();               /* temporary file */
X    char buf[STRLEN], *makefnam();    /* temp file name, fixer */
X    char sys[STRLEN];                 /* invocation command buffer */
X    char *dir, *gcdir();               /* directory stuff */
X
X/*  Replaced $ARCTEMP as the "system" call didn't approve.  */
X/*  makefnam("$ARCTEMP",hdr->name,buf); */
X    sprintf(buf,"%s.RUN",arctemp);
X
X/*  if(!strcmp(buf,"$ARCTEMP.BAS"))
X *       strcpy(sys,"BASICA $ARCTEMP");
X *
X *  else if(!strcmp(buf,"$ARCTEMP.BAT")
X *       || !strcmp(buf,"$ARCTEMP.COM")
X *       || !strcmp(buf,"$ARCTEMP.EXE"))
X *       strcpy(sys,"$ARCTEMP");
X *
X *  else
X *  {    if(warn)
X *       {    printf("File %s is not a .BAS, .BAT, .COM, or .EXE\n",
X *                 hdr->name);
X *            nerrs++;
X *       }
X *       fseek(arc,hdr->size,1);
X *       return;
X *  }
X */
X
X    if(warn)
X         if(tmp=fopen(buf,"r"))
X              abort("Temporary file %s already exists",buf);
X    if(!(tmp=fopen(buf,"w")))
X         abort("Unable to create temporary file %s",buf);
X
X    if(note)
X         printf("Invoking file: %s\n",hdr->name);
X
X    dir = gcdir("");                   /* see where we are */
X    unpack(arc,tmp,hdr);               /* unpack the entry */
X    fclose(tmp);                       /* release the file */
X    chmod(buf,"700");                  /* make it exec'able */
X#ifdef VAXC
X/*
X * If we want to get fancy we could check for .COM files etc...
X */
X    strcpy(sys,"$ RUN ");
X    strcat(sys, buf);
X    system(sys);
X#else
X    system(buf);                       /* try to invoke it */
X#endif
X    chdir(dir); free(dir);             /* return to whence we started */
X
X    if(unlink(buf) && warn)
X    {    printf("Cannot unsave temporary file %s\n",buf);
X         nerrs++;
X    }
X}
X
$ GoSub Convert_File
$ Goto Part13