home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 1 / crawlyvol1.bin / utility / system / runprog / runprg.c < prev   
Text File  |  1990-10-24  |  4KB  |  135 lines

  1. /*
  2.  * RUNPRG.ACC - A desk accessory to run programs...
  3.  *   by Todd A. Coram 21aug87
  4.  *   Can you say Buggy? Tricky to run .PRG files.... Runs .TOS & .TTP w/o param
  5.  */
  6.  
  7. #include <stdio.h>
  8. #include <gemdefs.h>
  9. #include <osbind.h>
  10.  
  11. /* Some lazy GEM programs allocate all mem and leave us nothing, 
  12.    so we beat them to the punch and allocate some mem on boot-up. Ha!
  13. */
  14. #define DEFAULTRES 100000  /* reserve 100k for selected program */
  15. #define RESERVEFILE "\\runprg.res"
  16. long int reserved; /* contains memory to reserve */
  17.  
  18. extern int gl_apid;
  19.  
  20. int contrl[12];
  21. int intin[128];
  22. int ptsin[128];
  23. int intout[128];
  24. int ptsout[128];
  25.  
  26. int menu_id;
  27. int msg_buf[8];
  28. char *new_scr, *old_phy, *old_log;
  29.  
  30. char *reserve; /* pointer to reserved memory */
  31.  
  32. char workpath[20],filespec[80],filepath[20];
  33. int fresult,fbutton;
  34.  
  35. FILE *fp;
  36.  
  37. main()
  38. {
  39.    long int n;
  40.    char buf[80], prgname[12];
  41.  
  42.    filespec[0]=0;
  43.  
  44.    /* Find out how much memory to reserve */
  45.    if ((fp = fopen(RESERVEFILE,"r")) == NULL)
  46.       reserved = DEFAULTRES;
  47.    else{  /* open file and try to read 1 number, filespec and prg name*/
  48.       if (fscanf(fp, "%ld,%80s %12s", &reserved,filespec,prgname) < 1)
  49.          reserved = DEFAULTRES;
  50.       fclose(fp);
  51.    }
  52.  
  53.    appl_init();
  54.  
  55.    if (filespec[0] == 0)
  56.       menu_id = menu_register(gl_apid, "  Execute Prg");
  57.    else
  58.       menu_id = menu_register(gl_apid, prgname);
  59.  
  60.    if ((reserve = (char *)malloc(reserved)) == 0 ){
  61.       sprintf(buf, "[3][Can't allocate %6ld bytes][OK]", reserved);
  62.       form_alert(1, buf);
  63.    }
  64.  
  65.    strcpy(workpath,"\\*.*"); /* set path */
  66.  
  67.    /* Q: How long is forever? A: A very long time */
  68.    while (1){
  69.       evnt_mesag(msg_buf); /* wait....be patient until we are selected */
  70.       if ((msg_buf[0] == 40) && (msg_buf[4] == menu_id)){
  71.  
  72.          /* free reserved memory */
  73.          free (reserve); 
  74.  
  75.          /* allocate space for a new screen */
  76.          if ((new_scr = (char *)calloc(32512,1)) == 0 )
  77.             form_alert(1, "[3][Can't allocate 32512 bytes][OK]");
  78.          else {
  79.             /* setup a new screen */
  80.             n = (long int)new_scr;
  81.             /* align on a 512 page boundary */
  82.             new_scr = (char *)(n + (512-(n % 512))); 
  83.  
  84.             old_phy = (char *)Physbase();
  85.             old_log = (char *)Logbase();
  86.  
  87.             /* fsel a program */
  88.             if (filespec[0] != 0){ /* got a reserved program to execute */
  89.                Cursconf(1,0);
  90.                /* set a new screen and Pexec that program */
  91.                Setscreen(new_scr, new_scr, -1);
  92.                Pexec(0,filespec,"",0L); 
  93.                Setscreen(old_log, old_phy, -1);
  94.                Cursconf(0,0);
  95.                free(new_scr);  /* free screen */
  96.              }
  97.              else {
  98.                filepath[0]=0;
  99.                fresult=fsel_input(workpath,filepath,&fbutton);
  100.  
  101.                if(fresult>0 && fbutton==1){
  102.                   strcpy(filespec,workpath);
  103.                   strip_wild(filespec);
  104.                   strcat(filespec,filepath);
  105.  
  106.                   Cursconf(1,0);
  107.                   /* set a new screen and Pexec that program */
  108.                   Setscreen(new_scr, new_scr, -1);
  109.                   Pexec(0,filespec,"",0L); 
  110.                   Setscreen(old_log, old_phy, -1);
  111.                   Cursconf(0,0);
  112.                   free(new_scr);  /* free screen */
  113.                }
  114.             }
  115.                /* try and re-reserve memory released */
  116.         if ((reserve = (char *)malloc(reserved)) == 0 ){
  117.            sprintf(buf, "[3][Can't allocate %6ld bytes][OK]", reserved);
  118.            form_alert(1, buf);
  119.             }
  120.          }
  121.       }
  122.    }
  123. }
  124.  
  125.  
  126. /*
  127.  * STRIP_WILD strips wildcards
  128.  */
  129. strip_wild(string)
  130. /
  131.  
  132. cps wildcards
  133.  */
  134. strip_wild(           /* ,⇩,גcבnew screen andcאC"s]2TR0g r *md llomd esefi d))P0 s0 a∙aij*IJb(   r2TR0g r *md llk/
  135. strip_wild(         *IJb(,