home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
GEMini Atari
/
GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso
/
zip
/
utility
/
runprg.arc
/
RUNPRG.C
next >
Wrap
C/C++ Source or Header
|
1985-11-20
|
4KB
|
140 lines
/*
* RUNPRG.ACC - A desk accessory to run programs...
* by Todd A. Coram 21aug87
* Can you say Buggy? Tricky to run .PRG files.... Runs .TOS & .TTP w/o param
*/
#include <stdio.h>
#include <gemdefs.h>
#include <osbind.h>
/* Some lazy GEM programs allocate all mem and leave us nothing,
so we beat them to the punch and allocate some mem on boot-up. Ha!
*/
#define DEFAULTRES 100000 /* reserve 100k for selected program */
#define RESERVEFILE "\\runprg.res"
long int reserved; /* contains memory to reserve */
extern int gl_apid;
int contrl[12];
int intin[128];
int ptsin[128];
int intout[128];
int ptsout[128];
int menu_id;
int msg_buf[8];
char *new_scr, *old_phy, *old_log;
char *reserve; /* pointer to reserved memory */
char workpath[20],filespec[80],filepath[20];
int fresult,fbutton;
FILE *fp;
main()
{
long int n;
char buf[80], prgname[12];
filespec[0]=0;
/* Find out how much memory to reserve */
if ((fp = fopen(RESERVEFILE,"r")) == NULL)
reserved = DEFAULTRES;
else{ /* open file and try to read 1 number, filespec and prg name*/
if (fscanf(fp, "%ld,%80s %12s", &reserved,filespec,prgname) < 1)
reserved = DEFAULTRES;
fclose(fp);
}
appl_init();
if (filespec[0] == 0)
menu_id = menu_register(gl_apid, " Execute Prg");
else
menu_id = menu_register(gl_apid, prgname);
if ((reserve = (char *)malloc(reserved)) == 0 ){
sprintf(buf, "[3][Can't allocate %6ld bytes][OK]", reserved);
form_alert(1, buf);
}
strcpy(workpath,"\\*.*"); /* set path */
/* Q: How long is forever? A: A very long time */
while (1){
evnt_mesag(msg_buf); /* wait....be patient until we are selected */
if ((msg_buf[0] == 40) && (msg_buf[4] == menu_id)){
/* free reserved memory */
free (reserve);
/* allocate space for a new screen */
if ((new_scr = (char *)calloc(32512,1)) == 0 )
form_alert(1, "[3][Can't allocate 32512 bytes][OK]");
else {
/* setup a new screen */
n = (long int)new_scr;
/* align on a 512 page boundary */
new_scr = (char *)(n + (512-(n % 512)));
old_phy = (char *)Physbase();
old_log = (char *)Logbase();
/* fsel a program */
if (filespec[0] != 0){ /* got a reserved program to execute */
Cursconf(1,0);
/* set a new screen and Pexec that program */
Setscreen(new_scr, new_scr, -1);
Pexec(0,filespec,"",0L);
Setscreen(old_log, old_phy, -1);
Cursconf(0,0);
free(new_scr); /* free screen */
}
else {
filepath[0]=0;
fresult=fsel_input(workpath,filepath,&fbutton);
if(fresult>0 && fbutton==1){
strcpy(filespec,workpath);
strip_wild(filespec);
strcat(filespec,filepath);
Cursconf(1,0);
/* set a new screen and Pexec that program */
Setscreen(new_scr, new_scr, -1);
Pexec(0,filespec,"",0L);
Setscreen(old_log, old_phy, -1);
Cursconf(0,0);
free(new_scr); /* free screen */
}
}
/* try and re-reserve memory released */
if ((reserve = (char *)malloc(reserved)) == 0 ){
sprintf(buf, "[3][Can't allocate %6ld bytes][OK]", reserved);
form_alert(1, buf);
}
}
}
}
}
/*
* STRIP_WILD strips wildcards
*/
strip_wild(string)
char *string;
{
register int x;
for(x=strlen(string); x>=0; --x){
if(string[x] == 92) /* is it \? */
break;
}
string[x+1]=0;
}