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

  1. /*  ARC - Archive utility - ARCRUN
  2.  
  3.     Version 1.20, created on 03/24/86 at 19:34:31
  4.  
  5. (C) COPYRIGHT 1985,85 by System Enhancement Associates; ALL RIGHTS RESERVED
  6.  
  7.     By:  Thom Henderson
  8.  
  9.     Description:
  10.          This file contains the routines used to "run" a file
  11.          which is stored in an archive.  At present, all we really do
  12.          is (a) extract a temporary file, (b) give its name as a system
  13.          command, and then (c) delete the file.
  14.  
  15.     Language:
  16.          Computer Innovations Optimizing C86
  17. */
  18. #include <stdio.h>
  19. #include "arc.h"
  20.  
  21. runarc(num,arg)                        /* run file from archive */
  22. int num;                               /* number of arguments */
  23. char *arg[];                           /* pointers to arguments */
  24. {
  25.     struct heads hdr;                  /* file header */
  26.     char *makefnam();                  /* filename fixer */
  27.     char buf[100];                 /* filename buffer */
  28.     FILE *fopen();                     /* file opener */
  29.  
  30.     rempath(num,arg);                  /* strip off paths */
  31.  
  32.     openarc(0);                        /* open archive for reading */
  33.  
  34.     if(num)                            /* if files were named */
  35.     {    while(readhdr(&hdr,arc))      /* while more files to check */
  36.          {    if(match(hdr.name,makefnam(arg[0],".*",buf)))
  37.                    runfile(&hdr,num,&arg[1]);
  38.               else fseek(arc,hdr.size,1);
  39.          }
  40.     }
  41.  
  42.     else while(readhdr(&hdr,arc))      /* else run all files */
  43.          runfile(&hdr,0,NULL);
  44.  
  45.     closearc(0);                       /* close archive after changes */
  46. }
  47.  
  48. static runfile(hdr,num,arg)            /* run a file */
  49. struct heads *hdr;                     /* pointer to header data */
  50. int num;                               /* number of arguments */
  51. char *arg[];                           /* pointers to arguments */
  52. {
  53.     FILE *tmp, *fopen();               /* temporary file */
  54.     char buf[100], *makefnam();    /* temp file name, fixer */
  55.     char sys[100];                 /* invocation command buffer */
  56.     char *dir, *gcdir();               /* directory stuff */
  57.     int n;                             /* index */
  58.  
  59.     makefnam("$ARCTEMP",hdr->name,buf);
  60.  
  61.     if(!strcmp(buf,"$ARCTEMP.BAS"))
  62.          strcpy(sys,"BASICA $ARCTEMP");
  63.  
  64.     else if(!strcmp(buf,"$ARCTEMP.BAT")
  65.          || !strcmp(buf,"$ARCTEMP.COM")
  66.          || !strcmp(buf,"$ARCTEMP.EXE"))
  67.          strcpy(sys,"$ARCTEMP");
  68.  
  69.     else
  70.     {    if(warn)
  71.          {    printf("File %s is not a .BAS, .BAT, .COM, or .EXE\n",
  72.                    hdr->name);
  73.               nerrs++;
  74.          }
  75.          fseek(arc,hdr->size,1);  /* skip this file */
  76.          return;
  77.     }
  78.  
  79.     if(warn)
  80.          if(tmp=fopen(buf,"rb"))
  81.               abort("Temporary file %s already exists",buf);
  82.     if(!(tmp=fopen(makefnam("$ARCTEMP",hdr->name,buf),"wrb")))
  83.          abort("Unable to create temporary file %s",buf);
  84.  
  85.     if(note)
  86.          printf("Invoking file: %s\n",hdr->name);
  87.  
  88.     for(n=0; n<num; n++)               /* add command line arguments */
  89.     {    strcat(sys," ");
  90.          strcat(sys,arg[n]);
  91.     }
  92.  
  93.     dir = gcdir("");                   /* see where we are */
  94.     unpack(arc,tmp,hdr);               /* unpack the entry */
  95.     fclose(tmp);                       /* release the file */
  96.     system(sys);                       /* try to invoke it */
  97.     chdir(dir); free(dir);             /* return to whence we started */
  98.     if(unlink(buf) && warn)
  99.     {    printf("Cannot unsave temporary file %s\n",buf);
  100.          nerrs++;
  101.     }
  102. }
  103.