Path: utzoo!mnetor!uunet!husc6!mailrus!ames!pasteur!ucbvax!ucsd!rutgers!bellcore!tness7!tness1!sugar!peter From: peter@sugar.UUCP (Peter da Silva) Newsgroups: comp.sys.amiga.tech Subject: Re: WorkBench Processes... Message-ID: <1837@sugar.UUCP> Date: 15 Apr 88 04:33:40 GMT References: <386@uvicctr.UUCP> Distribution: na Organization: Sugar Land UNIX - Houston, TX Lines: 229 Summary: When comp.sources.amiga comes back, you will see! In article <386@uvicctr.UUCP>, sdean1@uvicctr.UUCP (Steven A. Dean) writes: > As I understand it, there are three basic types of "running entity" on the > Amiga. A CLI-Process, a WorkBench-Process, and a simple task. Well, there are also device drivers, but that's the basic idea. > My big question to all of you Guru types out there is... How can you create a > WorkBench type process while within the CLI? Use the program that I sent to the comp.source.amiga moderators just before they started having problems and stopped moderating. It's called "click", and runs a workbench process and waits for it to finish. Eventually I will have a program called "launch" that will allow you to do this without waiting, but right now I have too much stuff to do elsewhere. Would anyone like me to post click to comp.sys.amiga? It's very short. Unlike the CLI, the Workbench is VERY easy to handle. > as I might have liked (can you say GURU?). Now, perhaps I'm on the wrong > track entirely, but I believe that all I have to do is figure out how DOS > actually sets up the initial stack for the process and provide some code > to allow the graceful exit I want. You're on the wrong track entirely. What you need to do is provide what's called a Workbench Startup Message (struct WBStartup). > Many Thanks for whatever replies I can get my hands on.... You can also use "Browser", which is where I developed the code for "click". Note... some programs will not run as Workbench processes, for one reason or another. They seem to assume they have a CLI structure, input, or output. Hey... it's only 4K ------------------------- Snip, Snap, Snorr ---------------------------- : This archive contains the following files... : 'click.doc' : 'click.c' : 'Makefile' : To extract them, run the following through /bin/sh echo x - click.doc sed 's/^X//' > click.doc << '//END' XCLICK -- start a workbench application from the CLI. X XThis is an example of how you run a workbench application. As you can see, Xit's pretty complex... even with the stuff encapsulated like this. However, Xonce you get it working it works just fine... unlike the CLI. Just ask anyone Xwho's tried to run a program under the CLI from, say, runback. X XUsage: click program X XLoads and executes program in a workbench environment, then returns to the XCLI. X XAuthor: Peter da Silva. //END echo x - click.c sed 's/^X//' > click.c << '//END' X#include X#include X#include X Xmain(ac, av) Xint ac; Xchar **av; X{ X click(av[1]); X} X XUBYTE *AllocMem(); Xstruct SegList *LoadSeg(); Xstruct MsgPort *CreateProc(), *CreatePort(); Xstruct WBStartup *BuildStartup(); X Xstruct MsgPort *rport; Xstruct WBStartup *startup; X Xcleanup(msg, name) Xchar *msg; Xchar *name; X{ X if(msg && name) X printf("click: %s: %s\n", name, msg); X if(startup) X FreeStartup(startup); X if(rport) DeletePort(rport); X} X Xclick(name) Xchar *name; X{ X rport = NULL; X X rport = CreatePort(0, 0); X if(!rport) { X cleanup("Can't create reply port", name); X exit(20); X } X X startup = BuildStartup(name); X if(!startup) { X cleanup("Can't load", name); X exit(20); X } X X startup->sm_Message.mn_ReplyPort = rport; X startup->sm_Message.mn_Length = sizeof(struct WBStartup); X startup->sm_Message.mn_Node.ln_Type = NT_MESSAGE; X X PutMsg(startup->sm_Process, startup); X WaitPort(rport); X X cleanup(0, 0); X exit(0); X} X XFreeStartup(msg) Xstruct WBStartup *msg; X{ X if(msg->sm_ArgList) { X int i; X for(i = 0; i < msg->sm_NumArgs; i++) { X if(msg->sm_ArgList[i].wa_Lock) X UnLock(msg->sm_ArgList[i].wa_Lock); X if(msg->sm_ArgList[i].wa_Name) X FreeMem(msg->sm_ArgList[i].wa_Name, X strlen(msg->sm_ArgList[i].wa_Name)+1); X } X FreeMem(msg->sm_ArgList, X sizeof(struct WBArg) * msg->sm_NumArgs); X } X if(msg->sm_Segment) X UnLoadSeg(msg->sm_Segment); X if(msg->sm_ToolWindow) X FreeMem(msg->sm_ToolWindow, X strlen(msg->sm_ToolWindow)+1); X FreeMem(msg, sizeof(struct WBStartup)); X} X Xstruct WBStartup * XBuildStartup(name) Xchar *name; X{ X ULONG flock; X struct WBStartup *msg; X char *s, *namep; X X msg = (struct WBStartup *) X AllocMem(sizeof(struct WBStartup), MEMF_PUBLIC|MEMF_CLEAR); X if(!msg) X return 0; X X msg->sm_Segment = LoadSeg(name); X if(!msg->sm_Segment) { X FreeStartup(msg); X return 0; X } X X msg->sm_ToolWindow = 0; X X msg->sm_ArgList = (struct WBArg *) X AllocMem(sizeof(struct WBArg), MEMF_PUBLIC | MEMF_CLEAR); X if(!msg->sm_ArgList) { X FreeStartup(msg); X return 0; X } X X msg->sm_NumArgs = 1; X X flock = Lock(name); X if(!flock) { X FreeStartup(msg); X return 0; X } X msg->sm_ArgList[0].wa_Lock = ParentDir(flock); X UnLock(flock); X if(!msg->sm_ArgList[0].wa_Lock) { X FreeStartup(msg); X return 0; X } X X namep = name; X for(s = name; *s; s++) X if(*s=='/' || *s==':') X namep = s+1; X msg->sm_ArgList[0].wa_Name = AllocMem(strlen(namep)+1, MEMF_PUBLIC); X if(!msg->sm_ArgList[0].wa_Name) { X FreeStartup(msg); X return 0; X } X strcpy(msg->sm_ArgList[0].wa_Name, namep); X X msg->sm_Process = X CreateProc(msg->sm_ArgList[0].wa_Name, 0, msg->sm_Segment, 8192); X if(!msg->sm_Process) { X FreeStartup(msg); X return 0; X } X X return msg; X} //END echo x - Makefile sed 's/^X//' > Makefile << '//END' X.SUFFIXES: .c .o .h .x X X.c.o: X -delete $*.o X cc +P -B -DAMIGA $*.c X Xclick: click.o X -delete click X ln -o t:click click.o -lcl32 X copy t:click click X -delete t:click X Xclick.arc: click.doc click click.c Makefile X arc a click click.doc click click.c Makefile X Xclick.shar: click.doc click.c Makefile X shar >click.shar click.doc click.c Makefile //END : end of archive. exit 0 -- -- Peter da Silva `-_-' ...!hoptoad!academ!uhnix1!sugar!peter -- "Have you hugged your U wolf today?" ...!bellcore!tness1!sugar!peter -- Disclaimer: These aren't mere opinions, these are *values*.