home *** CD-ROM | disk | FTP | other *** search
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <math.h>
- #include <proto/exec.h>
- #include <proto/dos.h>
- #include <workbench/startup.h>
- #include <dos/dostags.h>
-
- int main(int argc,char *argv[])
- {
- struct WBStartup s;
- char buffer[300],
- *p;
- FILE *file;
- short trovato,
- wb;
- struct WBArg arg[1];
- struct MsgPort *Port,
- *MyPort;
- BPTR Code,
- fileinout;
- int stack;
-
-
-
- if (!stricmp(argv[1],"CLI")) wb=FALSE;
- else if (!strcmp(argv[1],"WB")) wb=TRUE;
- else exit(5);
-
- stack=atoi(argv[2]);
- stack=max(4000,stack);
-
- if (!(file=fopen("SCOPTIONS","r"))) exit(5);
-
- trovato=FALSE;
- while((!feof(file))&&(!trovato))
- {
- fgets(buffer,sizeof(buffer)-1,file);
- if (!strncmp(buffer,"PROGRAMNAME=",12)) trovato=TRUE;
- }
-
- fclose(file);
-
- if (!trovato) exit(5);
-
- strcpy(buffer,buffer+12);
-
- if (buffer[0]) buffer[strlen(buffer)-1]='\0';
-
- if (!wb)
- {
- /***** Esegui il comando *****/
- strcat(buffer," ");
-
- if (file=fopen("PrjArguments","r"))
- {
- fgets(buffer+strlen(buffer),sizeof(buffer)-1,file);
- fclose(file);
- }
-
- p=argv[3];
- if (!p) p="CON://///AUTO/WAIT/CLOSE";
-
- if (!(fileinout=Open(p,MODE_NEWFILE)))
- exit(5);
-
- SystemTags(buffer,
- SYS_Input, fileinout,
- SYS_Output, NULL,
- SYS_Asynch, TRUE,
- NP_StackSize, stack,
- TAG_END);
- }
- else
- {
- arg[0].wa_Name=buffer;
-
- if (!(MyPort=CreateMsgPort())) exit(5);
-
- if (!(Code=LoadSeg((UBYTE*)buffer)))
- {
- DeleteMsgPort(MyPort);
- exit(5);
- }
-
- if (!(arg[0].wa_Lock=Lock((UBYTE*)"",ACCESS_READ)))
- {
- UnLoadSeg(Code);
- DeleteMsgPort(MyPort);
- exit(5);
- }
-
- if (!(Port=CreateProc((UBYTE*)buffer,0,Code,stack)))
-
- s.sm_Message.mn_Node.ln_Succ=NULL;
- s.sm_Message.mn_Node.ln_Pred=NULL;
- s.sm_Message.mn_Node.ln_Type=NT_MESSAGE;
- s.sm_Message.mn_Node.ln_Pri=0;
- s.sm_Message.mn_Node.ln_Name=NULL;
- s.sm_Message.mn_ReplyPort=MyPort;
- s.sm_Message.mn_Length=sizeof(struct WBStartup);
- s.sm_Process=Port;
- s.sm_Segment=Code;
- s.sm_NumArgs=1;
- s.sm_ToolWindow=NULL;
- s.sm_ArgList=arg;
-
- PutMsg(Port,(struct Message *)&s);
- WaitPort(MyPort);
- while(GetMsg(MyPort));
-
- UnLoadSeg(Code);
- DeleteMsgPort(MyPort);
- UnLock(arg[0].wa_Lock);
- }
-
- exit(0);
- }
-