home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Club Amiga de Montreal - CAM
/
CAM_CD_1.iso
/
files
/
164.lha
/
ARexx
/
WB_ARexx_v1.1
/
wbrexx.c
< prev
next >
Wrap
C/C++ Source or Header
|
1988-04-28
|
5KB
|
183 lines
/** WBRexx.c
*
* WBRexx 1.1
* ==========
*
* Copyright 1988, W.G.J. Langeveld
* All Rights Reserved
* Freely Distributable
*
* This program can be used to execute REXX scripts or REXX command strings
* from the workbench. This can be accomplished either by double clicking on
* a WBRexx project icon, where the default tool points to this program, or
* by extended-selecting a number of such icons and double-clicking on the
* WBRexx tool icon.
*
* WINDOW tooltype support added by Steve Berry.
*
**/
#include "exec/exec.h"
#include "libraries/dos.h"
#include "libraries/dosextens.h"
#include "libraries/arpbase.h"
#include "intuition/intuition.h"
#include "workbench/startup.h"
#include "workbench/workbench.h"
#include "functions.h"
#include "stdio.h"
#include "arpfunctions.h"
static char *ExpandArg(), *rindex();
/**
*
* Main function. This one handles the Workbench message and all that stuff.
*
**/
void WBRexx(WB_msg)
struct WBStartup *WB_msg;
{
struct DiskObject *ARIcon = NULL;
int i, isrxstr = 0, debug = 0;
char buffer[80], *result1 = NULL, *result2 = NULL, *win = NULL, *SendREXXMsg();
struct FileLock *olddir = NULL;
/*
* Handle the WorkBench message.
*/
if (WB_msg) {
for (i = 0; i < (int) WB_msg->sm_NumArgs; i++) {
if (debug) {
strcpy(buffer, "Argument is ");
strncat(buffer, WB_msg->sm_ArgList[i].wa_Name, 58);
AReqBool(NULL, buffer, NULL, "Okay");
}
result1 = ExpandArg(&WB_msg->sm_ArgList[i], NULL);
/*
* If this is an inline rexx function (tooltype RX), it will have no file
* associated with it. Therefore, get the name of the info file.
*/
isrxstr = (strlen(result1) > 0) ? 0 : 1;
if (isrxstr) result1 = ExpandArg(&WB_msg->sm_ArgList[i], ".info");
if (debug) {
strcpy(buffer, "Expands to ");
strncat(buffer, result1, 59);
AReqBool(NULL, buffer, NULL, "Okay");
}
/*
* If the name string is still zero, ignore this one.
*/
if (strlen(result1) > 0) {
/*
* Else, open the icon.
*/
ARIcon = GetDiskObject(result1);
if (ARIcon != NULL) {
/*
* Only do project Icons, of course.
*/
if (ARIcon->do_Type == WBPROJECT) {
/*
* See if this one has a WINDOW tooltype
*/
win = FindToolType(ARIcon->do_ToolTypes, "WINDOW");
/*
* Check the RX tooltype if this is an inline string command. If it is,
* get the string from the ToolType RX.
*/
if (isrxstr) result1 = FindToolType(ARIcon->do_ToolTypes, "RX");
if (result1) {
if (debug) {
strcpy(buffer, "REXX gets ");
strncat(buffer, result1, 60);
AReqBool(NULL, buffer, NULL, "Okay");
}
/*
* Change to the icon's directory.
*/
if (WB_msg->sm_ArgList[i].wa_Lock)
olddir = CurrentDir(WB_msg->sm_ArgList[i].wa_Lock);
/*
* Send the command to Rexx. If there's an error, post an autorequest
*/
result2 = SendREXXMsg(result1, isrxstr, win);
if (result2) AReqBool(NULL, result2, NULL, "Okay");
/*
* Change back to the previous directory
*/
if (WB_msg->sm_ArgList[i].wa_Lock) CurrentDir(olddir);
}
}
/*
* If this is the tool icon, see if DEBUG is set.
*/
else if (ARIcon->do_Type == WBTOOL) {
result1 = FindToolType(ARIcon->do_ToolTypes, "DEBUG");
if (result1) {
if (MatchToolValue(result1, "ON")) debug = TRUE;
}
}
/*
* Free the icon.
*/
FreeDiskObject(ARIcon);
}
}
}
}
return;
}
/**
*
* This function expands a WBArg filename to include the full pathname and
* if given, the extension "extens".
*
**/
char *ExpandArg(arg, extens)
struct WBArg *arg;
char *extens;
{
struct FileLock *olddir, *lock;
static char iconname[255];
static char buff[80], *rind;
long len;
iconname[0] = '\0';
/*
* See if this type can be locked. If not, it must be a device, return.
*/
if (arg->wa_Lock == NULL) return(iconname);
/*
* Change directory to the tools directory.
*/
olddir = CurrentDir(arg->wa_Lock);
/*
* Get the current path
*/
strcpy(buff, arg->wa_Name);
/*
* If present, append the file extension.
*/
if (extens) strcat(buff, extens);
lock = Lock(buff, ACCESS_READ);
if (lock) {
len = PathName(lock, iconname, 1);
UnLock(lock);
if (extens) {
rind = rindex(iconname, '.');
if (rind) *rind = '\0';
}
}
/*
* Set directory back
*/
CurrentDir(olddir);
return(iconname);
}