home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 4
/
FreshFish_May-June1994.bin
/
bbs
/
mar94
/
os20
/
util
/
mcalc.lha
/
MCalc
/
Source
/
MCalcARexx.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-12-31
|
19KB
|
773 lines
/*
Auto: smake MCalc
*/
/* $Revision Header built automatically *************** (do not edit) ************
**
** © Copyright by GuntherSoft
**
** File : SnakeSYS:CPrgs/MUICalc/MCalcARexx.c
** Created on : Sunday, 05.12.93 14:37:01
** Created by : Kai Iske
** Current revision : V1.0
**
**
** Purpose
** -------
** - ARexx support for MUIProCalc
**
** Revision V1.0
** --------------
** created on Sunday, 05.12.93 14:37:01 by Kai Iske. LogMessage :
** --- Initial release ---
**
*********************************************************************************/
/**********************************************************************/
/* Routines for that module */
/**********************************************************************/
static APTR __saveds __asm DoRXCalc(register __a0 struct Hook *MyHook, register __a2 APTR *MyObject, register __a1 ULONG *Parms);
static APTR __saveds __asm DoRXCalcTeX(register __a0 struct Hook *MyHook, register __a2 APTR *MyObject, register __a1 ULONG *Parms);
static APTR __saveds __asm GetOutput(register __a0 struct Hook *MyHook, register __a2 APTR *MyObject, register __a1 ULONG *Parms);
static APTR __saveds __asm GetTeXOutput(register __a0 struct Hook *MyHook, register __a2 APTR *MyObject, register __a1 ULONG *Parms);
static APTR __saveds __asm GetInput(register __a0 struct Hook *MyHook, register __a2 APTR *MyObject, register __a1 ULONG *Parms);
static APTR __saveds __asm GetTeXInput(register __a0 struct Hook *MyHook, register __a2 APTR *MyObject, register __a1 ULONG *Parms);
static APTR __saveds __asm DoFormatTeX(register __a0 struct Hook *MyHook, register __a2 APTR *MyObject, register __a1 ULONG *Parms);
static APTR __saveds __asm SetMode(register __a0 struct Hook *MyHook, register __a2 APTR *MyObject, register __a1 ULONG *Parms);
static APTR ReturnEntry(UWORD Mode, UWORD OutMode, LONG Pos);
static void FormatTeX(char *Source, char *Dest);
/**********************************************************************/
/* external references to main programs variables */
/**********************************************************************/
extern APTR AppObject;
extern APTR InputString;
extern APTR OutputBox;
extern UWORD IntType;
extern UWORD IntBase;
extern UWORD IntSign;
extern UWORD IntAngle;
/**********************************************************************/
/* Hooks */
/**********************************************************************/
static struct Hook CalcHook =
{
{NULL},
(APTR)DoRXCalc,
NULL,
NULL
};
static struct Hook CalcTeXHook =
{
{NULL},
(APTR)DoRXCalcTeX,
NULL,
NULL
};
static struct Hook GetOutputHook =
{
{NULL},
(APTR)GetOutput,
NULL,
NULL
};
static struct Hook GetTeXOutputHook =
{
{NULL},
(APTR)GetTeXOutput,
NULL,
NULL
};
static struct Hook GetInputHook =
{
{NULL},
(APTR)GetInput,
NULL,
NULL
};
static struct Hook GetTeXInputHook =
{
{NULL},
(APTR)GetTeXInput,
NULL,
NULL
};
static struct Hook FormatTeXHook =
{
{NULL},
(APTR)DoFormatTeX,
NULL,
NULL
};
static struct Hook SetModeHook =
{
{NULL},
(APTR)SetMode,
NULL,
NULL
};
/**********************************************************************/
/* This is for our modes */
/**********************************************************************/
UWORD RXIntType;
UWORD RXIntBase;
UWORD RXIntSign;
UWORD RXIntAngle;
/**********************************************************************/
/* Array of ARexx commands for MUIProCalc */
/**********************************************************************/
struct MUI_Command RXCommands[] =
{
// Calculate an expression (normal output)
{
"CALC",
"EXPRESSION/A/M",
1,
&CalcHook
},
// Calculate an expression (TeX output)
{
"CALCTEX",
"EXPRESSION/A/M",
1,
&CalcTeXHook
},
// Select output from history (normal output; as is)
{
"GETOUTPUT",
"ENTRYNUM/N",
1,
&GetOutputHook
},
// Select output from history (TeX output)
{
"GETTEXOUTPUT",
"ENTRYNUM/N",
1,
&GetTeXOutputHook
},
// Select input from history (normal output; as is)
{
"GETINPUT",
"ENTRYNUM/N",
1,
&GetInputHook
},
// Select input from history (TeX output)
{
"GETTEXINPUT",
"ENTRYNUM/N",
1,
&GetTeXInputHook
},
// Format an expression to TeX format
{
"FORMATTEX",
"EXPRESSION/A/M",
1,
&FormatTeXHook
},
// Set output mode
{
"SETMODE",
"BASE/K,SIZE/K,SIGN/K,ANGLE/K",
4,
&SetModeHook
},
// Delimiter
{
NULL, NULL, NULL, NULL
}
};
/**********************************************************************/
/* Let MUIProCalc (normal output) calculate through ARexx */
/* ------------------------------------------------------ */
/* Parameters must be : */
/* Expr = Expression to calculate */
/**********************************************************************/
static APTR __saveds __asm DoRXCalc(register __a0 struct Hook *MyHook, register __a2 APTR *MyObject, register __a1 ULONG *Parms)
{
UWORD BackIntType, BackIntBase, BackIntSign, BackIntAngle;
char NewBuff[258], **Exprs;
BOOL GoOn = TRUE;
// Build expression from partial input
strcpy(NewBuff, "");
Exprs = (char **)Parms[0];
while(*Exprs && GoOn)
{
if((strlen(*Exprs) + strlen(NewBuff)) < 256)
strcat(NewBuff, *Exprs);
else
GoOn = FALSE;
Exprs++;
}
// Set input string to current expression
set(InputString, MUIA_String_Contents, NewBuff);
// Calculate expression (with ARexx settings)
BackIntType = IntType;
BackIntBase = IntBase;
BackIntSign = IntSign;
BackIntAngle = IntAngle;
IntType = RXIntType;
IntBase = RXIntBase;
IntSign = RXIntSign;
IntAngle = RXIntAngle;
GoOn = FormatOutput(FALSE);
IntType = BackIntType;
IntBase = BackIntBase;
IntSign = BackIntSign;
IntAngle = BackIntAngle;
if(GoOn)
{
// Return output
return(ReturnEntry(GET_OUTPUT, NORMAL_OUTPUT, GET_ACTIVE));
}
else
return((APTR)set(AppObject, MUIA_Application_RexxString, " "));
}
/**********************************************************************/
/* Let MUIProCalc (TeX output) calculate through ARexx */
/* --------------------------------------------------- */
/* Parameters must be : */
/* Expr = Expression to calculate */
/**********************************************************************/
static APTR __saveds __asm DoRXCalcTeX(register __a0 struct Hook *MyHook, register __a2 APTR *MyObject, register __a1 ULONG *Parms)
{
UWORD BackIntType, BackIntBase, BackIntSign, BackIntAngle;
char NewBuff[258], **Exprs;
BOOL GoOn = TRUE;
// Build expression from partial input
strcpy(NewBuff, "");
Exprs = (char **)Parms[0];
while(*Exprs && GoOn)
{
if((strlen(*Exprs) + strlen(NewBuff)) < 256)
strcat(NewBuff, *Exprs);
else
GoOn = FALSE;
Exprs++;
}
// Set input string to current expression
set(InputString, MUIA_String_Contents, NewBuff);
// Calculate expression (with ARexx settings)
BackIntType = IntType;
BackIntBase = IntBase;
BackIntSign = IntSign;
BackIntAngle = IntAngle;
IntType = RXIntType;
IntBase = RXIntBase;
IntSign = RXIntSign;
IntAngle = RXIntAngle;
GoOn = FormatOutput(FALSE);
IntType = BackIntType;
IntBase = BackIntBase;
IntSign = BackIntSign;
IntAngle = BackIntAngle;
if(GoOn)
{
// Return output
return(ReturnEntry(GET_OUTPUT, TEX_OUTPUT, GET_ACTIVE));
}
else
return((APTR)set(AppObject, MUIA_Application_RexxString, " "));
}
/**********************************************************************/
/* GetOutput (normal output) from History */
/* -------------------------------------- */
/* Parameters may be : */
/* n = Nth entry