[net.micro.amiga] Tool for running CLI things from Workbench

rico@oscvax.UUCP (07/30/86)

<----- Purina Line Eater Chow ----->

Don't look now, here comes my first ever public source posting...

This little ditty will allow you to run CLI commands from the workbench.
It's a mite kludgy but it is pretty effective...  In any case, this is just
a preliminary release, I hope to get something a little more polished out here
soon.

#ifdef AZTEC

To compile runner.c using Manx C just

	cc runner.c
	ln runner.o -lc

#else  /* must be Lattice C */

If you only have Lettuce then you'll have to make one small change to the
source, just declare WBenchMsg as an external rather than as the second
argument to main.  

You should be able to compile it with that "make" script that's on the
Lettuce disk... (but I ain't got Lettuce so I haven't tried it)

#endif

Once you have the executable 'runner', you must

a) install it in the c: directory of your favourite workbench disk(s)

b) change the startup-sequence so that the original CLI is *not* ended
   (this is to give CLI commands that you run with runner a place to
    write their output and maybe get input... you'll want to size the
    window to your taste once you see what commands you like to run)

c) using your favourite workbench tool (say Notepad), create a project,
   a small one, with minimal data in it.  Now select the icon that
   was created and ask for it's Info from the Workbench (pick the
   "Info" entry from the "Workbench" menu).  Now here's where the
   fun starts.

d) fill in the "comment" field with a CLI command you would like to run

e) change the default tool to c:runner

f) get rid of all the "tool types" junk (if any) by picking DEL until
   they are all gone.

g) pick save on the info screen.

h) rename the project to something that reflects what you put in the 
   comment field.  If you're really keen edit the icon image too...
   
i) double click the icon you just made and watch the fun!

From here on in you can just duplicate and edit the command icon
you used for your first one, be careful because AmigaDOS doesn't
preserve the Comment field across copies.  I've used runner with
success on Kickstart 1.1 and 1.2 Beta 4.

Caveats:  Your command will be run with its current directory as
	  DF0:  and with only 4000 bytes of stack (the defaults (sorry
	  I don't know how to fix this right now)).

	  If you need more stack than 4000, you can just create a CLI
	  batch file that has a suitable "stack" command in it as well
	  as the command you really want to execute and then aim the
	  comment field at your batch file.

	  The main affect of the current directory being DF0: is that
	  you almost always have to specify a complete path to your files
	  in the commands that you run (Sigh).

	  You will find it all too easy to start more than one task, but
	  keep in mind that they will all share their stdin and stdout
	  (it's gonna be that CLI screen I told you to leave around unless
	  you explictly redirect it in the command you put in the comment
	  string (not such a bad idea)) so that window can get real
	  cluttered...

Suggested things to do with runner:

	invoke your favourite editor on a source file
	compile a source file
	run make
	do a dir on some useful directory
	call up the vt100 emulator with arguments for your favourite colours
			and baud rate and ... and...
	etc.

Feel free to mail any suggestions to me, or better yet post them...
This program is so simple that oodles of people should be able
to make improvements (and it does need them!).

	  Rico Mariani
	    {allegra|ihnp4|watmath|linus|decvax}!utzoo!oscvax!rico

	  

-------runner.c-----AIM-LASER-WEAPON-HERE-------
/* :ts=8 */
/*
 * runner.c   July 29/86	Rico Mariani
 * runs CLI commands from the comment field of an icon
 *
 */

#include <exec/types.h>
#include <workbench/startup.h>
#include <libraries/dos.h>
#include <libraries/dosextens.h>
#include <stdio.h>

struct FileLock *Lock();
struct FileLock *CurrentDir();

main(argc,WBenchMsg)
int argc;
struct WBStartup *WBenchMsg;
{
	struct WBArg *arg;
	struct FileLock *olddir;
	char buf[80];
	int stat;

	if (argc) {
		printf("run from workbench\n");
		exit(999);
	}

	arg = WBenchMsg->sm_ArgList;

	if (WBenchMsg->sm_NumArgs != 2 )
		exit(999);

	arg++;
	if (arg->wa_Lock) {
		olddir = CurrentDir(arg->wa_Lock);
		strcpy(buf,arg->wa_Name);
		stat = runit(buf);
		CurrentDir(olddir);
		exit (stat);
	}
	exit(999);
}

runit(buf)
char *buf;
{
	struct FileLock *lock;
	struct FileInfoBlock fib;

	lock = Lock(buf,ACCESS_READ);

	if (!lock) return(999);
	if (!Examine(lock,&fib)) { UnLock(lock); return(999); }

	UnLock(lock);
	return(Execute(fib.fib_Comment,0L,0L));
}