home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 28 / amigaformatcd28.iso / -seriously_amiga- / archivers / arcppc / src / rcs / arcrun.c,v < prev    next >
Text File  |  1998-04-23  |  6KB  |  293 lines

  1. head     1.4;
  2. branch   ;
  3. access   ;
  4. symbols  patch1:1.4;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.4
  10. date     88.07.31.18.52.50;  author hyc;  state Exp;
  11. branches ;
  12. next     1.3;
  13.  
  14. 1.3
  15. date     88.06.01.19.57.16;  author hyc;  state Exp;
  16. branches ;
  17. next     1.2;
  18.  
  19. 1.2
  20. date     88.06.01.16.24.17;  author hyc;  state Exp;
  21. branches ;
  22. next     1.1;
  23.  
  24. 1.1
  25. date     88.06.01.16.09.17;  author hyc;  state Exp;
  26. branches ;
  27. next     ;
  28.  
  29.  
  30. desc
  31. @@
  32.  
  33.  
  34. 1.4
  35. log
  36. @fix declarations, fix args to fopen()
  37. @
  38. text
  39. @/*
  40.  * $Header: arcrun.c,v 1.3 88/06/01 19:57:16 hyc Locked $
  41.  */
  42.  
  43. /*
  44.  * ARC - Archive utility - ARCRUN
  45.  * 
  46.  * Version 1.20, created on 03/24/86 at 19:34:31
  47.  * 
  48.  * (C) COPYRIGHT 1985,85 by System Enhancement Associates; ALL RIGHTS RESERVED
  49.  * 
  50.  * By:  Thom Henderson
  51.  * 
  52.  * Description: This file contains the routines used to "run" a file which is
  53.  * stored in an archive.  At present, all we really do is (a) extract a
  54.  * temporary file, (b) give its name as a system command, and then (c) delete
  55.  * the file.
  56.  * 
  57.  * Language: Computer Innovations Optimizing C86
  58.  */
  59. #include <stdio.h>
  60. #include "arc.h"
  61.  
  62. void    rempath(), openarc(), closearc(), abort();
  63. int    readhdr(), match(), unpack();
  64. static    void    runfile();
  65. char    *strcat();
  66.  
  67. void
  68. runarc(num, arg)        /* run file from archive */
  69.     int             num;    /* number of arguments */
  70.     char           *arg[];    /* pointers to arguments */
  71. {
  72.     struct heads    hdr;    /* file header */
  73.     char           *makefnam();    /* filename fixer */
  74.     char            buf[STRLEN];    /* filename buffer */
  75.     FILE           *fopen();/* file opener */
  76.     char           *dummy[2];
  77.  
  78.     dummy[0]="dummy";
  79.     dummy[1]=NULL;
  80.     rempath(num, arg);    /* strip off paths */
  81.  
  82.     openarc(0);        /* open archive for reading */
  83.  
  84.     if (num) {        /* if files were named */
  85.         while (readhdr(&hdr, arc)) {    /* while more files to check */
  86.             if (match(hdr.name, makefnam(arg[0], ".*", buf)))
  87.                 runfile(&hdr, num, arg);
  88.             else
  89.                 fseek(arc, hdr.size, 1);
  90.         }
  91.     } else
  92.         while (readhdr(&hdr, arc))    /* else run all files */
  93.             runfile(&hdr, 1, dummy);
  94.  
  95.     closearc(0);        /* close archive after changes */
  96. }
  97.  
  98. static  void
  99. runfile(hdr, num, arg)        /* run a file */
  100.     struct heads   *hdr;    /* pointer to header data */
  101.     int             num;    /* number of arguments */
  102.     char           *arg[];    /* pointers to arguments */
  103. {
  104.     FILE           *tmp, *fopen();    /* temporary file */
  105.     char           *dir, *gcdir();    /* directory stuff */
  106.     char            buf[STRLEN], *makefnam();    /* temp file name, fixer */
  107. #if    DOS
  108.     char        nbuf[64], *i, *rindex();
  109. #endif
  110. #if    !GEMDOS
  111.     int             n;    /* index */
  112.     char            sys[STRLEN];    /* invocation command buffer */
  113. #endif
  114.  
  115.     /* makefnam("$ARCTEMP",hdr->name,buf); */
  116. #if    UNIX
  117.     sprintf(buf, "%s.RUN", arctemp);
  118.     strcpy(sys, buf);
  119. #else
  120.     strcpy(nbuf, arctemp);
  121.     makefnam(nbuf,hdr->name,buf);
  122.     i = rindex(buf,'.');
  123. #endif
  124. #if    MSDOS
  125.     if (!strcmp(i, ".BAS")) {
  126.         strcpy(sys, "BASICA ");
  127.         strcat(sys, buf);
  128.     }
  129.     else if (!strcmp(i, ".BAT")
  130.          || !strcmp(i, ".COM")
  131.          || !strcmp(i, ".EXE"))
  132.         strcpy(sys, buf);
  133.  
  134.     else {
  135.         if (warn) {
  136.             printf("File %s is not a .BAS, .BAT, .COM, or .EXE\n",
  137.                    hdr->name);
  138.             nerrs++;
  139.         }
  140.         fseek(arc, hdr->size, 1);    /* skip this file */
  141.         return;
  142.     }
  143. #endif
  144. #if    GEMDOS
  145.       if (strcmp(i, ".PRG")
  146.               && strcmp(i, ".TTP")
  147.               && strcmp(i, ".TOS"))
  148.       {
  149.               if (warn) {
  150.                       printf("File %s is not a .PRG, .TOS, or .TTP\n",
  151.                               hdr->name);
  152.                       nerrs++;
  153.               }
  154.               fseek(arc, hdr->size, 1);       /* skip this file */
  155.               return;
  156.       }
  157. #endif
  158.  
  159.     if (warn)
  160.         if (tmp = fopen(buf, "r"))
  161.             abort("Temporary file %s already exists", buf);
  162.     if (!(tmp = fopen(buf, OPEN_W)))
  163.         abort("Unable to create temporary file %s", buf);
  164.  
  165.     if (note)
  166.         printf("Invoking file: %s\n", hdr->name);
  167.  
  168.     dir = gcdir("");    /* see where we are */
  169.     unpack(arc, tmp, hdr);    /* unpack the entry */
  170.     fclose(tmp);        /* release the file */
  171.     chmod(buf, "700");    /* make it executable */
  172. #if    GEMDOS
  173.     execve(buf, arg, NULL);
  174. #else
  175.     for (n = 1; n < num; n++) {    /* add command line arguments */
  176.         strcat(sys, " ");
  177.         strcat(sys, arg[n]);
  178.     }
  179.     system(buf);        /* try to invoke it */
  180. #endif
  181.     chdir(dir);
  182.     free(dir);        /* return to whence we started */
  183.     if (unlink(buf) && warn) {
  184.         printf("Cannot unsave temporary file %s\n", buf);
  185.         nerrs++;
  186.     }
  187. }
  188. @
  189.  
  190.  
  191. 1.3
  192. log
  193. @Changed compilation conditionals
  194. @
  195. text
  196. @d2 1
  197. a2 1
  198.  * $Header: arcrun.c,v 1.2 88/06/01 16:24:17 hyc Locked $
  199. d25 2
  200. a37 1
  201.     int             runfile();
  202. d60 1
  203. a60 1
  204. static          int
  205. d124 1
  206. a124 1
  207.     if (!(tmp = fopen(buf, "wb")))
  208. @
  209.  
  210.  
  211. 1.2
  212. log
  213. @Merge Atari ST code
  214. @
  215. text
  216. @d2 1
  217. a2 1
  218.  * $Header: arcrun.c,v 1.1 88/06/01 16:09:17 hyc Locked $
  219. d37 1
  220. a37 1
  221.     char           *dummy[2]={"dummy",NULL};
  222. d39 2
  223. d68 1
  224. a68 1
  225. #ifdef    DOS
  226. d71 1
  227. a71 1
  228. #ifndef    GEMDOS
  229. d77 1
  230. a77 1
  231. #ifdef    BSD
  232. d85 1
  233. a85 1
  234. #ifdef MSDOS
  235. d105 1
  236. a105 1
  237. #ifdef    GEMDOS
  238. d133 1
  239. a133 1
  240. #ifdef    GEMDOS
  241. @
  242.  
  243.  
  244. 1.1
  245. log
  246. @Initial revision
  247. @
  248. text
  249. @d2 1
  250. a2 1
  251.  * $Header: arcrun.c,v 1.4 88/04/19 01:40:14 hyc Exp $
  252. d37 1
  253. d46 1
  254. a46 1
  255.                 runfile(&hdr, num, &arg[1]);
  256. d52 1
  257. a52 1
  258.             runfile(&hdr, 0, NULL);
  259. d64 1
  260. d66 5
  261. a70 1
  262. #ifdef MSDOS
  263. a72 2
  264.     char           *dir, *gcdir();    /* directory stuff */
  265.     int             n;    /* index */
  266. d75 1
  267. d77 6
  268. a82 1
  269.  
  270. d84 8
  271. a91 2
  272.     if (!strcmp(buf, "$ARCTEMP.BAS"))
  273.         strcpy(sys, "BASICA $ARCTEMP");
  274. a92 5
  275.     else if (!strcmp(buf, "$ARCTEMP.BAT")
  276.          || !strcmp(buf, "$ARCTEMP.COM")
  277.          || !strcmp(buf, "$ARCTEMP.EXE"))
  278.         strcpy(sys, "$ARCTEMP");
  279.  
  280. d103 14
  281. d121 1
  282. a121 1
  283.     if (!(tmp = fopen(buf, "w")))
  284. a126 5
  285.     for (n = 0; n < num; n++) {    /* add command line arguments */
  286.         strcat(buf, " ");
  287.         strcat(buf, arg[n]);
  288.     }
  289.  
  290. d131 7
  291. d139 1
  292. @
  293.