home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Club Amiga de Montreal - CAM
/
CAM_CD_1.iso
/
files
/
011.lha
/
tool_wrapper
/
wrapper.c
< prev
next >
Wrap
C/C++ Source or Header
|
1986-11-10
|
2KB
|
86 lines
/* ToolWrapper.c
Constructs and executes a CLI command from Workbench messages
M Abel, August 1986, Foster City, CA 94404
*/
#define MMOVE(from, to) { register char *fptr; \
for (fptr = from; (*to++ = *fptr++) ; ); --to; }
#include <exec/types.h>
#include <exec/execbase.h>
#include <exec/memory.h>
#include <workbench/startup.h>
#include <workbench/workbench.h>
#include <workbench/icon.h>
#include <libraries/dosextens.h>
#include <libraries/dos.h>
LONG *IconBase, *OpenLibrary();
void CloseLibrary();
main(argc,argv)
int argc;
char **argv;
{
struct WBStartup *WBenchMsg;
WBenchMsg = (struct WBStartup *)argv;
if (argc==0) {
IconBase = OpenLibrary(ICONNAME, 1L);
if (IconBase != (long *)NULL) {
buildCommand(WBenchMsg);
CloseLibrary(IconBase);
}
}
}
buildCommand(msg)
struct WBStartup *msg;
{
struct WBArg *arg;
register int cp,i,k;
char c, *pathname, *cli_cmd, *strcpy(), *malloc();
struct FileHandle *nil_handle, *Open();
cli_cmd = malloc(512);
pathname = malloc(512);
arg = msg->sm_ArgList;
arg++;
CurrentDir(arg->wa_Lock);
cp = Find_Tool_Name(arg->wa_Name, cli_cmd);
if (cp > 0 ) {
for (i=1; i<msg->sm_NumArgs; i++, arg++) {
mkpath(arg->wa_Lock, pathname);
cli_cmd[cp++] = ' ';
for (k = 0; (cli_cmd[cp++] = pathname[k++] ) ; ) ; --cp;
for (k = 0; (cli_cmd[cp++] = arg->wa_Name[k++] ) ; ) ; --cp;
}
cli_cmd[cp++] = '\0';
nil_handle = Open("nil:", (long)MODE_OLDFILE);
Execute(cli_cmd, 0L, nil_handle);
Close(nil_handle);
}
free(cli_cmd);
free(pathname);
}
Find_Tool_Name(filename, retval)
char *filename, *retval;
{
struct DiskObject *diskobj, *GetDiskObject();
register char *toolname, *temp_ptr;
char *FindToolType();
diskobj = GetDiskObject(filename);
toolname = FindToolType(diskobj->do_ToolTypes,"TOOL");
temp_ptr = retval;
if (toolname != NULL) MMOVE(toolname, temp_ptr);
FreeDiskObject(diskobj);
return(temp_ptr-retval);
}