[comp.sys.amiga.tech] WorkBench Processes...

sdean1@uvicctr.UUCP (Steven A. Dean) (04/06/88)

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.  The CLI-Process
is blessed with an stdin and stdout set as well as any other CLI dependant
thingies (with the CLI struct off of the process superstructure).  The
WorkBench-Process is a "simple process" but still has the ability to
access the base DOS commands (obviously Input() and Output() wouldn't work
to swift).  A simple task cannot do anything that deals with the DOS system
at all (no message port for the packet sending?).

My big question to all of you Guru types out there is... How can you create a
WorkBench type process while within the CLI?  I tried the simple approach
(blindly, I might add) and it failed (simple approach, loadseg an object,
and do a createproc on it).  Which is to say, the actual loading program
worked like a champ, but the sub-process didn't quite exit as gracefully
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.

Does anyone out there know how to do this?  The main reason I want to have the
ability to do this is that I hate the 20 CLI process limit.  It's not really
that unreasonable a limit, I just don't much like 'em :-).  Besides, all of
my code tends to use the Intuition I/O style rather than the standard Un*x
style (stdin - stdout) :-).

Many Thanks for whatever replies I can get my hands on....

                        -Steve
----
Steven A. Dean, Consultant, University of Victoria, Victoria, B.C., GWN.
....uw-beaver!uvicctr!sdean1
....ubc-vision!uvicctr!sdean1
sdean1@uvunix.BITNET   ....   sdean1@uvunix.UVic.CDN

peter@sugar.UUCP (Peter da Silva) (04/15/88)

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 <exec/memory.h>
X#include <workbench/startup.h>
X#include <workbench/workbench.h>
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*.

walker@sas.UUCP (Doug Walker) (04/20/88)

In article <1837@sugar.UUCP> peter@sugar.UUCP (Peter da Silva) writes:
>> 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.

You can also use 'WBRUN' by John Toebes.  It's on one of the Fish disks.
You don't even have to wait for it to finish:  it starts the process and
then returns your CLI to you.  Also, you don't even have to have workbench
loaded to do it.

peter@sugar.UUCP (Peter da Silva) (04/20/88)

In article <467@sas.UUCP>, walker@sas.UUCP (Doug Walker) writes:
> In article <1837@sugar.UUCP> peter@sugar.UUCP (Peter da Silva) writes:
> >"click" ... runs a workbench process and waits for it to finish.

> You can also use 'WBRUN' by John Toebes.  It's on one of the Fish disks.
> You don't even have to wait for it to finish:  it starts the process and
> then returns your CLI to you.  Also, you don't even have to have workbench
> loaded to do it.

And how does WBRUN handle cleaning up the WBStartup message? That's why I wait
for it to finish... you need to get that message back and clean up after
yourself.

You don't need workbench loaded to run "click", either, by the way.
-- 
-- 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*.