/*
 * Econ ARexx  (C) 1994 Software Sculptors
 *                 All Rights Under Copyright Reserved
 *
 * Version 1.0
 *
 * Written using SAS/C 6.3
 * Using Magic User Interface (MUI) by Stefan Stuntz
 *
 * By John M. Haubrich, Jr.
 *
 *
 * Version~ Date~~~~~~~ Comments~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 * -------  ----        --------
 *    1.0   APR 16 1994 First MUI version.
 *             ;
 */

#include "common.h"

extern struct MyGlobals        MG;
extern struct MainWindow       MAIN;
extern struct DataEntryWindow  DENT;
extern char                    GL_szFault[256];


/*
 * REXX SUBROUTINES ---------------------------------
 */
void fnrxInitWindowFromRexx( char *pszName, BOOL fDoD5,
                             char *psz1, char *psz2, char *psz3,
                             char *psz4, char *psz5, ULONG ulCComp )
{
   set( DENT.STR_Name, MUIA_String_Contents, pszName );

   set( DENT.STR_DataLine1, MUIA_String_Contents, psz1 );
   set( DENT.STR_DataLine2, MUIA_String_Contents, psz2 );
   set( DENT.STR_DataLine3, MUIA_String_Contents, psz3 );
   set( DENT.STR_DataLine4, MUIA_String_Contents, psz4 );

   if ( fDoD5 )
   {
      set( DENT.STR_DataLine5, MUIA_String_Contents, psz5 );
   }
   else
   {
      set( DENT.STR_DataLine5, MUIA_String_Contents, NULL );
   }

   switch( ulCComp )
   {
      case 0:
      case 1:
         set( DENT.CHE_ContComp, MUIA_Selected, ulCComp );
         set( DENT.CHE_ContComp, MUIA_Disabled, FALSE );
         break;
      case 2:
         set( DENT.CHE_ContComp, MUIA_Selected, FALSE );
         set( DENT.CHE_ContComp, MUIA_Disabled, TRUE );
         break;
   }
}

/*
 * AREXX HOOKS --------------------------------------
 */
SAVEDS ASM LONG RX_1ClearFunc      ( REG(a0) struct Hook *hook, REG(a2) Object *appl, REG(a1) ULONG *arg )
{
   ULONG ulForce;


   ulForce = *((ULONG *)arg);
   if ( ulForce )
   {
      DoMethod( MAIN.LIS_EditList, MUIM_List_Clear, TRUE );
      set( MAIN.TXT_TotalAll,      MUIA_Text_Contents, "0.00" );
      set( MAIN.TXT_TotalSelected, MUIA_Text_Contents, "0.00" );
      MG.pCCPNode = NULL;
      return( RETURN_OK );
   }
   else if ( MUI_Request( MG.App, MG.WIN_Main, 0, NULL, "OK|*Cancel",
                          "Are you sure you wish to clear all data?", NULL ) == 1 )
   {
      DoMethod( MAIN.LIS_EditList, MUIM_List_Clear, TRUE );
      set( MAIN.TXT_TotalAll,      MUIA_Text_Contents, "0.00" );
      set( MAIN.TXT_TotalSelected, MUIA_Text_Contents, "0.00" );
      MG.pCCPNode = NULL;
      return( RETURN_OK );
   }

   return( RETURN_ERROR );
}
SAVEDS ASM LONG RX_1OpenFunc       ( REG(a0) struct Hook *hook, REG(a2) Object *appl, REG(a1) ULONG *arg )
{
   ULONG  ulForce;
   char  *pszFile;


   pszFile =  ((char *)*arg);
   ulForce = *((ULONG *)(arg+1));

   if ( ulForce )
   {
      fnReadData( pszFile, TRUE );
      return( RETURN_OK );
   }
   else if ( MUI_Request( MG.App, MG.WIN_Main, 0, NULL, "OK|*Cancel",
                          "Data has been modified.\nAre you sure you wish to continue?", NULL ) == 1 )
   {
      fnReadData( pszFile, TRUE );
      return( RETURN_OK );
   }

   return( RETURN_ERROR );
}
SAVEDS ASM LONG RX_1SaveasFunc     ( REG(a0) struct Hook *hook, REG(a2) Object *appl, REG(a1) ULONG *arg )
{
   char  *pszFile;
   char   szTmpSpec[ FMSIZE+1 ];


   pszFile =  ((char *)*arg);
   strcpy( szTmpSpec, MG.szProjectSpec );
   strcpy( MG.szProjectSpec, pszFile );

   if ( fnWriteData( FALSE, TRUE ) != RETURN_OK )
   {
      strcpy( MG.szProjectSpec, szTmpSpec );
      JMH_WindowTitle();
   }
   return( RETURN_OK );
}
SAVEDS ASM LONG RX_1PrintFunc      ( REG(a0) struct Hook *hook, REG(a2) Object *appl, REG(a1) ULONG *arg )
{
   ULONG  ulPrompt, ulAll;


   ulPrompt = *((ULONG *)arg);
   ulAll    = *((ULONG *)arg+1);

   if ( ulPrompt )
   {
      fnPrintAs( TRUE );
   }
   else
   {
      fnPrint( ( ulAll ? 1 : 2 ), TRUE );
   }
   return( RETURN_OK );
}
SAVEDS ASM LONG RX_2CutFunc        ( REG(a0) struct Hook *hook, REG(a2) Object *appl, REG(a1) ULONG *arg )
{
   struct LVNode  *pNode = NULL;
   ULONG           ulLen;


   DoMethod( MAIN.LIS_EditList, MUIM_List_GetEntry, MUIV_List_GetEntry_Active, &pNode );

   if ( pNode )
   {
      if ( MG.pCCPNode )   FreeVec( MG.pCCPNode );
      ulLen = sizeof( struct LVNode ) +
              strlen( pNode->pszName ) +
              strlen( pNode->pszResult ) +
              strlen( pNode->pszText1 ) +
              strlen( pNode->pszText2 ) +
              strlen( pNode->pszText3 ) +
              strlen( pNode->pszText4 ) +
              strlen( pNode->pszText5 ) + 1;
      if ( MG.pCCPNode = AllocVec( ulLen, MEMF_ANY | MEMF_CLEAR ) )
      {
         memcpy( MG.pCCPNode, pNode, ulLen );
      }
      DoMethod( MAIN.LIS_EditList, MUIM_List_Remove, MUIV_List_Remove_Active );

      return( RETURN_OK );
   }
   else
   {
      return( RETURN_ERROR );
   }
}
SAVEDS ASM LONG RX_2CopyFunc       ( REG(a0) struct Hook *hook, REG(a2) Object *appl, REG(a1) ULONG *arg )
{
   struct LVNode  *pNode = NULL;
   ULONG           ulLen;


   DoMethod( MAIN.LIS_EditList, MUIM_List_GetEntry, MUIV_List_GetEntry_Active, &pNode );

   if ( pNode )
   {
      if ( MG.pCCPNode )   FreeVec( MG.pCCPNode );
      ulLen = sizeof( struct LVNode ) +
              strlen( pNode->pszName ) +
              strlen( pNode->pszResult ) +
              strlen( pNode->pszText1 ) +
              strlen( pNode->pszText2 ) +
              strlen( pNode->pszText3 ) +
              strlen( pNode->pszText4 ) +
              strlen( pNode->pszText5 ) + 1;
      if ( MG.pCCPNode = AllocVec( ulLen, MEMF_ANY | MEMF_CLEAR ) )
      {
         memcpy( MG.pCCPNode, pNode, ulLen );
      }
      return( RETURN_OK );
   }
   else
   {
      return( RETURN_ERROR );
   }
}
SAVEDS ASM LONG RX_2PasteFunc      ( REG(a0) struct Hook *hook, REG(a2) Object *appl, REG(a1) ULONG *arg )
{
   char           szBuf[200];
   struct LVNode *pLVNode = NULL;
   UBYTE          ubStore;


   if ( MG.pCCPNode )
   {
      pLVNode = (struct LVNode *)MG.pCCPNode;
      sprintf( szBuf,   "%c%s%c%s%c%s%c%s%c%s%c%s%c%s%c",
                        pLVNode->ubContComp,
                        pLVNode->pszName,    255,
                        pLVNode->pszResult,  255,
                        pLVNode->pszText1,   255,
                        pLVNode->pszText2,   255,
                        pLVNode->pszText3,   255,
                        pLVNode->pszText4,   255,
                        pLVNode->pszText5,   255
             );
      ubStore = MG.ubCurrentEntryMode;
      MG.ubCurrentEntryMode = pLVNode->ubDataEntryMode;
      DoMethod( MAIN.LIS_EditList, MUIM_List_InsertSingle, &szBuf, MUIV_List_Insert_Sorted );
      MG.ubCurrentEntryMode = ubStore;
      return( RETURN_OK );
   }
   else
   {
      return( RETURN_ERROR );
   }
}
SAVEDS ASM LONG RX_2EraseFunc      ( REG(a0) struct Hook *hook, REG(a2) Object *appl, REG(a1) ULONG *arg )
{
   LONG   rc = RETURN_ERROR;
   ULONG  ulForce;


   ulForce = *((ULONG *)arg);

   if ( !ulForce )
   {
      if ( MUI_Request( MG.App, MG.WIN_Main, 0, NULL, "OK|*Cancel",
                        "Are you sure you want to erase this item?", NULL ) == 1 )
      {
         DoMethod( MAIN.LIS_EditList, MUIM_List_Remove, MUIV_List_Remove_Active );
         rc = RETURN_OK;
      }
   }
   else
   {
      DoMethod( MAIN.LIS_EditList, MUIM_List_Remove, MUIV_List_Remove_Active );
      rc = RETURN_OK;
   }

   return( rc );
}
SAVEDS ASM LONG RX_4MoveWdwFunc    ( REG(a0) struct Hook *hook, REG(a2) Object *appl, REG(a1) ULONG *arg )
{
   LONG   lX, lY;
   char  *pszWindow;

   struct Window *wdw;


   pszWindow =  ((char *)*arg);
   lX        = *((ULONG *)*(arg+1));
   lY        = *((ULONG *)*(arg+2));

   if ( strcmp( pszWindow, "MAIN" ) == 0 )
   {
      get( MG.WIN_Main, MUIA_Window_Window, &wdw );
      ChangeWindowBox( wdw, lX, lY, wdw->Width, wdw->Height );
   }
   else if ( strcmp( pszWindow, "DENT" ) == 0 )
   {
      get( MG.WIN_Dent, MUIA_Window_Window, &wdw );
      ChangeWindowBox( wdw, lX, lY, wdw->Width, wdw->Height );
   }
   return( RETURN_OK );
}
SAVEDS ASM LONG RX_4SizeWdwFunc    ( REG(a0) struct Hook *hook, REG(a2) Object *appl, REG(a1) ULONG *arg )
{
   LONG   lW, lH;
   char  *pszWindow;

   struct Window *wdw;


   pszWindow =  ((char *)*arg);
   lW        = *((ULONG *)*(arg+1));
   lH        = *((ULONG *)*(arg+2));

   if ( strcmp( pszWindow, "MAIN" ) == 0 )
   {
      get( MG.WIN_Main, MUIA_Window_Window, &wdw );
      ChangeWindowBox( wdw, wdw->LeftEdge, wdw->TopEdge, lW, lH );
   }
   else if ( strcmp( pszWindow, "DENT" ) == 0 )
   {
      get( MG.WIN_Dent, MUIA_Window_Window, &wdw );
      ChangeWindowBox( wdw, wdw->LeftEdge, wdw->TopEdge, lW, lH );
   }
   return( RETURN_OK );
}
SAVEDS ASM LONG RX_4ChangeWdwFunc  ( REG(a0) struct Hook *hook, REG(a2) Object *appl, REG(a1) ULONG *arg )
{
   LONG   lX, lY, lW, lH;
   char  *pszWindow;

   struct Window *wdw;


   pszWindow =  ((char *)*arg);
   lX        = *((ULONG *)*(arg+1));
   lY        = *((ULONG *)*(arg+2));
   lW        = *((ULONG *)*(arg+3));
   lH        = *((ULONG *)*(arg+4));

   if ( strcmp( pszWindow, "MAIN" ) == 0 )
   {
      get( MG.WIN_Main, MUIA_Window_Window, &wdw );
      ChangeWindowBox( wdw, lX, lY, lW, lH );
   }
   else if ( strcmp( pszWindow, "DENT" ) == 0 )
   {
      get( MG.WIN_Dent, MUIA_Window_Window, &wdw );
      ChangeWindowBox( wdw, lX, lY, lW, lH );
   }
   return( RETURN_OK );
}
SAVEDS ASM LONG RX_4Wdw2FrontFunc  ( REG(a0) struct Hook *hook, REG(a2) Object *appl, REG(a1) ULONG *arg )
{
   char  *pszWindow;
   struct Window *wdw;


   pszWindow =  ((char *)*arg);

   if ( strcmp( pszWindow, "MAIN" ) == 0 )
   {
      get( MG.WIN_Main, MUIA_Window_Window, &wdw );
      WindowToFront( wdw );
   }
   else if ( strcmp( pszWindow, "DENT" ) == 0 )
   {
      get( MG.WIN_Dent, MUIA_Window_Window, &wdw );
      WindowToFront( wdw );
   }
   return( RETURN_OK );
}
SAVEDS ASM LONG RX_4Wdw2BackFunc   ( REG(a0) struct Hook *hook, REG(a2) Object *appl, REG(a1) ULONG *arg )
{
   char  *pszWindow;
   struct Window *wdw;


   pszWindow =  ((char *)*arg);

   if ( strcmp( pszWindow, "MAIN" ) == 0 )
   {
      get( MG.WIN_Main, MUIA_Window_Window, &wdw );
      WindowToBack( wdw );
   }
   else if ( strcmp( pszWindow, "DENT" ) == 0 )
   {
      get( MG.WIN_Dent, MUIA_Window_Window, &wdw );
      WindowToBack( wdw );
   }
   return( RETURN_OK );
}
SAVEDS ASM LONG RX_4ActivateWdwFunc( REG(a0) struct Hook *hook, REG(a2) Object *appl, REG(a1) ULONG *arg )
{
   char  *pszWindow;
   struct Window *wdw;


   pszWindow =  ((char *)*arg);

   if ( strcmp( pszWindow, "MAIN" ) == 0 )
   {
      get( MG.WIN_Main, MUIA_Window_Window, &wdw );
      ActivateWindow( wdw );
   }
   else if ( strcmp( pszWindow, "DENT" ) == 0 )
   {
      get( MG.WIN_Dent, MUIA_Window_Window, &wdw );
      ActivateWindow( wdw );
   }
   return( RETURN_OK );
}
SAVEDS ASM LONG RX_4ZoomWdwFunc    ( REG(a0) struct Hook *hook, REG(a2) Object *appl, REG(a1) ULONG *arg )
{
   char  *pszWindow;
   struct Window *wdw;


   pszWindow =  ((char *)*arg);

   if ( strcmp( pszWindow, "MAIN" ) == 0 )
   {
      get( MG.WIN_Main, MUIA_Window_Window, &wdw );
      ZipWindow( wdw );
   }
   else if ( strcmp( pszWindow, "DENT" ) == 0 )
   {
      get( MG.WIN_Dent, MUIA_Window_Window, &wdw );
      ZipWindow( wdw );
   }
   return( RETURN_OK );
}
SAVEDS ASM LONG RX_4UnzoomWdwFunc  ( REG(a0) struct Hook *hook, REG(a2) Object *appl, REG(a1) ULONG *arg )
{
   char  *pszWindow;
   struct Window *wdw;


   pszWindow =  ((char *)*arg);

   if ( strcmp( pszWindow, "MAIN" ) == 0 )
   {
      get( MG.WIN_Main, MUIA_Window_Window, &wdw );
      ZipWindow( wdw );
   }
   else if ( strcmp( pszWindow, "DENT" ) == 0 )
   {
      get( MG.WIN_Dent, MUIA_Window_Window, &wdw );
      ZipWindow( wdw );
   }
   return( RETURN_OK );
}
SAVEDS ASM LONG RX_5SortByFunc     ( REG(a0) struct Hook *hook, REG(a2) Object *appl, REG(a1) ULONG *arg )
{
   char  *pszSortType;


   pszSortType =  ((char *)*arg);

   if ( strcmp( pszSortType, "NAME" ) == 0 )
   {
      set( MAIN.CYC_ViewBy, MUIA_Cycle_Active, 0 );
   }
   else if ( strcmp( pszSortType, "ENTRYTYPE" ) == 0 )
   {
      set( MAIN.CYC_ViewBy, MUIA_Cycle_Active, 1 );
   }

   set( MAIN.LIS_EditList, MUIA_List_Quiet, TRUE );
   DoMethod( MAIN.LIS_EditList, MUIM_List_Sort, TRUE );
   set( MAIN.LIS_EditList, MUIA_List_Quiet, FALSE );
   return( RETURN_OK );
}
SAVEDS ASM LONG RX_5SetActiveLnFunc        ( REG(a0) struct Hook *hook, REG(a2) Object *appl, REG(a1) ULONG *arg )
{
   ULONG  ulLine, ulNumEntries;
   ULONG  ulNone;


   ulNone = *((ULONG *)arg);
   ulLine = *((ULONG *)*(arg+1));

   if ( ulNone )
   {
      set( MAIN.LIS_EditList, MUIA_List_Active, MUIV_List_Active_Off );
   }
   else
   {
      get( MAIN.LIS_EditList, MUIA_List_Entries, &ulNumEntries );
      if ( ulLine < ulNumEntries )
      {
         set( MAIN.LIS_EditList, MUIA_List_Active, ulLine-1 );
         return( RETURN_OK );
      }
      else
      {
         return( RETURN_ERROR );
      }
   }
}
SAVEDS ASM LONG RX_5SelFunc        ( REG(a0) struct Hook *hook, REG(a2) Object *appl, REG(a1) ULONG *arg )
{
   ULONG  ulLine, ulNumEntries;


   ulLine = *((ULONG *)*arg);

   get( MAIN.LIS_EditList, MUIA_List_Entries, &ulNumEntries );
   if ( ulLine < ulNumEntries )
   {
      DoMethod( MAIN.LIS_EditList, MUIM_List_Select, ulLine-1, MUIV_List_Select_On, NULL);
      return( RETURN_OK );
   }
   else
   {
      return( RETURN_ERROR );
   }
}
SAVEDS ASM LONG RX_5DeSelFunc      ( REG(a0) struct Hook *hook, REG(a2) Object *appl, REG(a1) ULONG *arg )
{
   ULONG  ulLine, ulAll;


   ulAll  = *((ULONG *)arg);
   ulLine = *((ULONG *)*(arg+1));

   if ( ulAll )
   {
      DoMethod( MAIN.LIS_EditList, MUIM_List_Select,
                MUIV_List_Select_All, MUIV_List_Select_Off, NULL);
   }
   else
   {
      DoMethod( MAIN.LIS_EditList, MUIM_List_Select,
                ulLine-1, MUIV_List_Select_Off, NULL);
   }
   return( RETURN_OK );
}
SAVEDS ASM LONG RX_5QryIFunc       ( REG(a0) struct Hook *hook, REG(a2) Object *appl, REG(a1) ULONG *arg )
{
   ULONG          ulSelected, ulLine;
   char           cDelimeter;
   struct LVNode *pNode = NULL;
   static char    szBuf[100];


   ulSelected = *((ULONG *)arg);
   ulLine     = *((ULONG *)*(arg+1));
   cDelimeter = (char)*((ULONG *)*(arg+2));

   if ( !cDelimeter )   cDelimeter = ' ';

   DoMethod( MAIN.LIS_EditList, MUIM_List_GetEntry,
             ( ulSelected ? MUIV_List_GetEntry_Active : ulLine-1 ), &pNode );

   if ( pNode )
   {
      sprintf( szBuf, "%c%c%s%c%s%c%s%c%s%c%s%c%s%c%s",
               ( pNode->ubContComp ? 'C' : ' ' ),  cDelimeter,
               pNode->pszName,                     cDelimeter,
               pNode->pszResult,                   cDelimeter,
               pNode->pszText1,                    cDelimeter,
               pNode->pszText2,                    cDelimeter,
               pNode->pszText3,                    cDelimeter,
               pNode->pszText4,                    cDelimeter,
               pNode->pszText5
             );
      set( MG.App, MUIA_Application_RexxString, szBuf );
      return( RETURN_OK );
   }
   else
   {
      return( RETURN_ERROR );
   }
}
SAVEDS ASM LONG RX_5QryNIFunc      ( REG(a0) struct Hook *hook, REG(a2) Object *appl, REG(a1) ULONG *arg )
{
   LONG  lStat;


   get( MAIN.LIS_EditList, MUIA_List_Entries, &lStat );
   return( lStat );
}
SAVEDS ASM LONG RX_5I1Func         ( REG(a0) struct Hook *hook, REG(a2) Object *appl, REG(a1) ULONG *arg )
{
   char   *pszName;
   double  d1, d2;
   ULONG   u3, u4;
   ULONG   ulNoReq, ulCComp;
   char    sz1[25], sz2[25], sz3[25], sz4[25];


   pszName = ((char *)*arg);
   d1      = atof( (char *)*(arg+1));
   d2      = atof( (char *)*(arg+2));
   u3      = atol( (char *)*(arg+3));
   u4      = atol( (char *)*(arg+4));
   ulNoReq = *((ULONG *)(arg+5));
   ulCComp = *((ULONG *)(arg+6));

   sprintf( sz1, "%.2f", d1 );
   sprintf( sz2, "%.2f", d2 );
   sprintf( sz3, "%lu",  u3 );
   sprintf( sz4, "%lu",  u4 );
   fnInitDentWindow( 11, FALSE, ( ulNoReq ? FALSE : TRUE ) );
   fnrxInitWindowFromRexx( pszName, FALSE, sz1, sz2, sz3, sz4, NULL, ulCComp );

   MG.ubCurrentEntryMode = 11;
   MG.fReplacementMode   = FALSE;
   return( fnDoCalculation( TRUE, ( ulNoReq ? TRUE : FALSE ) ) );
}
SAVEDS ASM LONG RX_5I2Func         ( REG(a0) struct Hook *hook, REG(a2) Object *appl, REG(a1) ULONG *arg )
{
   char   *pszName;
   double  d1, d2;
   ULONG   u3, u4;
   ULONG   ulNoReq, ulCComp;
   char    sz1[25], sz2[25], sz3[25], sz4[25];


   pszName = ((char *)*arg);
   d1      = atof( (char *)*(arg+1));
   d2      = atof( (char *)*(arg+2));
   u3      = atol( (char *)*(arg+3));
   u4      = atol( (char *)*(arg+4));
   ulNoReq = *((ULONG *)(arg+5));
   ulCComp = *((ULONG *)(arg+6));

   sprintf( sz1, "%.2f", d1 );
   sprintf( sz2, "%.2f", d2 );
   sprintf( sz3, "%lu",  u3 );
   sprintf( sz4, "%lu",  u4 );
   fnInitDentWindow( 12, FALSE, ( ulNoReq ? FALSE : TRUE ) );
   fnrxInitWindowFromRexx( pszName, FALSE, sz1, sz2, sz3, sz4, NULL, ulCComp );

   MG.ubCurrentEntryMode = 12;
   MG.fReplacementMode   = FALSE;
   return( fnDoCalculation( TRUE, ( ulNoReq ? TRUE : FALSE ) ) );
}
SAVEDS ASM LONG RX_5I3Func         ( REG(a0) struct Hook *hook, REG(a2) Object *appl, REG(a1) ULONG *arg )
{
   char   *pszName;
   double  d1, d2;
   ULONG   u3, u4;
   ULONG   ulNoReq, ulCComp;
   char    sz1[25], sz2[25], sz3[25], sz4[25];


   pszName = ((char *)*arg);
   d1      = atof( (char *)*(arg+1));
   d2      = atof( (char *)*(arg+2));
   u3      = atol( (char *)*(arg+3));
   u4      = atol( (char *)*(arg+4));
   ulNoReq = *((ULONG *)(arg+5));
   ulCComp = *((ULONG *)(arg+6));

   sprintf( sz1, "%.2f", d1 );
   sprintf( sz2, "%.2f", d2 );
   sprintf( sz3, "%lu",  u3 );
   sprintf( sz4, "%lu",  u4 );
   fnInitDentWindow( 13, FALSE, ( ulNoReq ? FALSE : TRUE ) );
   fnrxInitWindowFromRexx( pszName, FALSE, sz1, sz2, sz3, sz4, NULL, ulCComp );

   MG.ubCurrentEntryMode = 13;
   MG.fReplacementMode   = FALSE;
   return( fnDoCalculation( TRUE, ( ulNoReq ? TRUE : FALSE ) ) );
}
SAVEDS ASM LONG RX_5I4Func         ( REG(a0) struct Hook *hook, REG(a2) Object *appl, REG(a1) ULONG *arg )
{
   char   *pszName;
   double  d1, d2;
   ULONG   u3, u4;
   ULONG   ulNoReq, ulCComp;
   char    sz1[25], sz2[25], sz3[25], sz4[25];


   pszName = ((char *)*arg);
   d1      = atof( (char *)*(arg+1));
   d2      = atof( (char *)*(arg+2));
   u3      = atol( (char *)*(arg+3));
   u4      = atol( (char *)*(arg+4));
   ulNoReq = *((ULONG *)(arg+5));
   ulCComp = *((ULONG *)(arg+6));

   sprintf( sz1, "%.2f", d1 );
   sprintf( sz2, "%.2f", d2 );
   sprintf( sz3, "%lu",  u3 );
   sprintf( sz4, "%lu",  u4 );
   fnInitDentWindow( 14, FALSE, ( ulNoReq ? FALSE : TRUE ) );
   fnrxInitWindowFromRexx( pszName, FALSE, sz1, sz2, sz3, sz4, NULL, ulCComp );

   MG.ubCurrentEntryMode = 14;
   MG.fReplacementMode   = FALSE;
   return( fnDoCalculation( TRUE, ( ulNoReq ? TRUE : FALSE ) ) );
}
SAVEDS ASM LONG RX_5I5Func         ( REG(a0) struct Hook *hook, REG(a2) Object *appl, REG(a1) ULONG *arg )
{
   char   *pszName;
   double  d1, d2;
   ULONG   u3, u4;
   ULONG   ulNoReq, ulCComp;
   char    sz1[25], sz2[25], sz3[25], sz4[25];


   pszName = ((char *)*arg);
   d1      = atof( (char *)*(arg+1));
   d2      = atof( (char *)*(arg+2));
   u3      = atol( (char *)*(arg+3));
   u4      = atol( (char *)*(arg+4));
   ulNoReq = *((ULONG *)(arg+5));
   ulCComp = *((ULONG *)(arg+6));

   sprintf( sz1, "%.2f", d1 );
   sprintf( sz2, "%.2f", d2 );
   sprintf( sz3, "%lu",  u3 );
   sprintf( sz4, "%lu",  u4 );
   fnInitDentWindow( 15, FALSE, ( ulNoReq ? FALSE : TRUE ) );
   fnrxInitWindowFromRexx( pszName, FALSE, sz1, sz2, sz3, sz4, NULL, ulCComp );

   MG.ubCurrentEntryMode = 15;
   MG.fReplacementMode   = FALSE;
   return( fnDoCalculation( TRUE, ( ulNoReq ? TRUE : FALSE ) ) );
}
SAVEDS ASM LONG RX_5I6Func         ( REG(a0) struct Hook *hook, REG(a2) Object *appl, REG(a1) ULONG *arg )
{
   char   *pszName;
   double  d1, d2;
   ULONG   u3, u4;
   ULONG   ulNoReq, ulCComp;
   char    sz1[25], sz2[25], sz3[25], sz4[25];


   pszName = ((char *)*arg);
   d1      = atof( (char *)*(arg+1));
   d2      = atof( (char *)*(arg+2));
   u3      = atol( (char *)*(arg+3));
   u4      = atol( (char *)*(arg+4));
   ulNoReq = *((ULONG *)(arg+5));
   ulCComp = *((ULONG *)(arg+6));

   sprintf( sz1, "%.2f", d1 );
   sprintf( sz2, "%.2f", d2 );
   sprintf( sz3, "%lu",  u3 );
   sprintf( sz4, "%lu",  u4 );
   fnInitDentWindow( 16, FALSE, ( ulNoReq ? FALSE : TRUE ) );
   fnrxInitWindowFromRexx( pszName, FALSE, sz1, sz2, sz3, sz4, NULL, ulCComp );

   if ( !ulNoReq )
   {
      set( MG.WIN_Dent, MUIA_Window_Open, TRUE );
   }

   MG.ubCurrentEntryMode = 16;
   MG.fReplacementMode   = FALSE;
   return( fnDoCalculation( TRUE, ( ulNoReq ? TRUE : FALSE ) ) );
}
SAVEDS ASM LONG RX_5I7Func         ( REG(a0) struct Hook *hook, REG(a2) Object *appl, REG(a1) ULONG *arg )
{
   char   *pszName;
   double  d1, d2;
   ULONG   u3, u4;
   ULONG   ulNoReq;
   char    sz1[25], sz2[25], sz3[25], sz4[25];


   pszName = ((char *)*arg);
   d1      = atof( (char *)*(arg+1));
   d2      = atof( (char *)*(arg+2));
   u3      = atol( (char *)*(arg+3));
   u4      = atol( (char *)*(arg+4));
   ulNoReq = *((ULONG *)(arg+5));

   sprintf( sz1, "%.2f", d1 );
   sprintf( sz2, "%.2f", d2 );
   sprintf( sz3, "%lu",  u3 );
   sprintf( sz4, "%lu",  u4 );

   fnInitDentWindow( 17, FALSE, ( ulNoReq ? FALSE : TRUE ) );
   fnrxInitWindowFromRexx( pszName, FALSE, sz1, sz2, sz3, sz4, NULL, 2 );

   MG.ubCurrentEntryMode = 17;
   MG.fReplacementMode   = FALSE;
   return( fnDoCalculation( TRUE, ( ulNoReq ? TRUE : FALSE ) ) );
}
SAVEDS ASM LONG RX_5L1Func         ( REG(a0) struct Hook *hook, REG(a2) Object *appl, REG(a1) ULONG *arg )
{
   char   *pszName;
   double  d1, d3;
   ULONG   u2, u4;
   ULONG   ulNoReq, ulCComp;
   char    sz1[25], sz2[25], sz3[25], sz4[25];


   pszName = ((char *)*arg);
   d1      = atof( (char *)*(arg+1));
   u2      = atol( (char *)*(arg+2));
   d3      = atof( (char *)*(arg+3));
   u4      = atol( (char *)*(arg+4));
   ulNoReq = *((ULONG *)(arg+5));
   ulCComp = *((ULONG *)(arg+6));

   sprintf( sz1, "%.2f", d1 );
   sprintf( sz2, "%lu",  u2 );
   sprintf( sz3, "%.2f", d3 );
   sprintf( sz4, "%lu",  u4 );

   fnInitDentWindow( 21, FALSE, ( ulNoReq ? FALSE : TRUE ) );
   fnrxInitWindowFromRexx( pszName, FALSE, sz1, sz2, sz3, sz4, NULL, ulCComp );

   MG.ubCurrentEntryMode = 21;
   MG.fReplacementMode   = FALSE;
   return( fnDoCalculation( TRUE, ( ulNoReq ? TRUE : FALSE ) ) );
}
SAVEDS ASM LONG RX_5L2Func         ( REG(a0) struct Hook *hook, REG(a2) Object *appl, REG(a1) ULONG *arg )
{
   char   *pszName;
   double  d1, d3;
   ULONG   u2, u4;
   ULONG   ulNoReq, ulCComp;
   char    sz1[25], sz2[25], sz3[25], sz4[25];


   pszName = ((char *)*arg);
   d1      = atof( (char *)*(arg+1));
   u2      = atol( (char *)*(arg+2));
   d3      = atof( (char *)*(arg+3));
   u4      = atol( (char *)*(arg+4));
   ulNoReq = *((ULONG *)(arg+5));
   ulCComp = *((ULONG *)(arg+6));

   sprintf( sz1, "%.2f", d1 );
   sprintf( sz2, "%lu",  u2 );
   sprintf( sz3, "%.2f", d3 );
   sprintf( sz4, "%lu",  u4 );

   fnInitDentWindow( 22, FALSE, ( ulNoReq ? FALSE : TRUE ) );
   fnrxInitWindowFromRexx( pszName, FALSE, sz1, sz2, sz3, sz4, NULL, ulCComp );

   MG.ubCurrentEntryMode = 22;
   MG.fReplacementMode   = FALSE;
   return( fnDoCalculation( TRUE, ( ulNoReq ? TRUE : FALSE ) ) );
}
SAVEDS ASM LONG RX_5L3Func         ( REG(a0) struct Hook *hook, REG(a2) Object *appl, REG(a1) ULONG *arg )
{
   char   *pszName;
   double  d1, d2, d3;
   ULONG   u4;
   ULONG   ulNoReq;
   char    sz1[25], sz2[25], sz3[25], sz4[25];


   pszName = ((char *)*arg);
   d1      = atof( (char *)*(arg+1));
   d2      = atof( (char *)*(arg+2));
   d3      = atof( (char *)*(arg+3));
   u4      = atol( (char *)*(arg+4));
   ulNoReq = *((ULONG *)(arg+5));

   sprintf( sz1, "%.2f", d1 );
   sprintf( sz2, "%.2f", d2 );
   sprintf( sz3, "%.2f", d3 );
   sprintf( sz4, "%lu",  u4 );

   fnInitDentWindow( 23, FALSE, ( ulNoReq ? FALSE : TRUE ) );
   fnrxInitWindowFromRexx( pszName, FALSE, sz1, sz2, sz3, sz4, NULL, 2 );

   MG.ubCurrentEntryMode = 23;
   MG.fReplacementMode   = FALSE;
   return( fnDoCalculation( TRUE, ( ulNoReq ? TRUE : FALSE ) ) );
}
SAVEDS ASM LONG RX_5L4Func         ( REG(a0) struct Hook *hook, REG(a2) Object *appl, REG(a1) ULONG *arg )
{
   char   *pszName;
   double  d1, d3;
   ULONG   u2, u4;
   ULONG   ulNoReq;
   char    sz1[25], sz2[25], sz3[25], sz4[25];


   pszName = ((char *)*arg);
   d1      = atof( (char *)*(arg+1));
   u2      = atol( (char *)*(arg+2));
   d3      = atof( (char *)*(arg+3));
   u4      = atol( (char *)*(arg+4));
   ulNoReq = *((ULONG *)(arg+5));

   sprintf( sz1, "%.2f", d1 );
   sprintf( sz2, "%lu",  u2 );
   sprintf( sz3, "%.2f", d3 );
   sprintf( sz4, "%lu",  u4 );

   fnInitDentWindow( 24, FALSE, ( ulNoReq ? FALSE : TRUE ) );
   fnrxInitWindowFromRexx( pszName, FALSE, sz1, sz2, sz3, sz4, NULL, 2 );

   if ( !ulNoReq )
   {
      set( MG.WIN_Dent, MUIA_Window_Open, TRUE );
   }

   MG.ubCurrentEntryMode = 24;
   MG.fReplacementMode   = FALSE;
   return( fnDoCalculation( TRUE, ( ulNoReq ? TRUE : FALSE ) ) );
}
SAVEDS ASM LONG RX_5L5Func         ( REG(a0) struct Hook *hook, REG(a2) Object *appl, REG(a1) ULONG *arg )
{
   char   *pszName;
   double  d1, d2, d3;
   ULONG   u4, u5;
   ULONG   ulNoReq;
   char    sz1[25], sz2[25], sz3[25], sz4[25], sz5[25];


   pszName = ((char *)*arg);
   d1      = atof( (char *)*(arg+1));
   d2      = atof( (char *)*(arg+2));
   d3      = atof( (char *)*(arg+3));
   u4      = atol( (char *)*(arg+4));
   u5      = atol( (char *)*(arg+5));
   ulNoReq = *((ULONG *)(arg+4));

   sprintf( sz1, "%.2f", d1 );
   sprintf( sz2, "%.2f", d2 );
   sprintf( sz3, "%.2f", d3 );
   sprintf( sz4, "%lu",  u4 );
   sprintf( sz5, "%lu",  u5 );

   fnInitDentWindow( 25, FALSE, ( ulNoReq ? FALSE : TRUE ) );
   fnrxInitWindowFromRexx( pszName, FALSE, sz1, sz2, sz3, sz4, sz5, 2 );

   MG.ubCurrentEntryMode = 25;
   MG.fReplacementMode   = FALSE;
   return( fnDoCalculation( TRUE, ( ulNoReq ? TRUE : FALSE ) ) );
}
SAVEDS ASM LONG RX_6LockGUIFunc    ( REG(a0) struct Hook *hook, REG(a2) Object *appl, REG(a1) ULONG *arg )
{
   set( MG.App, MUIA_Application_Sleep, TRUE );
   return( RETURN_OK );
}
SAVEDS ASM LONG RX_6UnlockGUIFunc  ( REG(a0) struct Hook *hook, REG(a2) Object *appl, REG(a1) ULONG *arg )
{
   set( MG.App, MUIA_Application_Sleep, FALSE );
   return( RETURN_OK );
}


/*
 * AREXX PROTOS -------------------------------------
 */
static const struct Hook RX_1ClearHook       = { {NULL, NULL}, (void *)RX_1ClearFunc      , NULL, NULL };
static const struct Hook RX_1OpenHook        = { {NULL, NULL}, (void *)RX_1OpenFunc       , NULL, NULL };
static const struct Hook RX_1SaveasHook      = { {NULL, NULL}, (void *)RX_1SaveasFunc     , NULL, NULL };
static const struct Hook RX_1PrintHook       = { {NULL, NULL}, (void *)RX_1PrintFunc      , NULL, NULL };
static const struct Hook RX_2CutHook         = { {NULL, NULL}, (void *)RX_2CutFunc        , NULL, NULL };
static const struct Hook RX_2CopyHook        = { {NULL, NULL}, (void *)RX_2CopyFunc       , NULL, NULL };
static const struct Hook RX_2PasteHook       = { {NULL, NULL}, (void *)RX_2PasteFunc      , NULL, NULL };
static const struct Hook RX_2EraseHook       = { {NULL, NULL}, (void *)RX_2EraseFunc      , NULL, NULL };
static const struct Hook RX_4MoveWdwHook     = { {NULL, NULL}, (void *)RX_4MoveWdwFunc    , NULL, NULL };
static const struct Hook RX_4SizeWdwHook     = { {NULL, NULL}, (void *)RX_4SizeWdwFunc    , NULL, NULL };
static const struct Hook RX_4ChangeWdwHook   = { {NULL, NULL}, (void *)RX_4ChangeWdwFunc  , NULL, NULL };
static const struct Hook RX_4Wdw2FrontHook   = { {NULL, NULL}, (void *)RX_4Wdw2FrontFunc  , NULL, NULL };
static const struct Hook RX_4Wdw2BackHook    = { {NULL, NULL}, (void *)RX_4Wdw2BackFunc   , NULL, NULL };
static const struct Hook RX_4ActivateWdwHook = { {NULL, NULL}, (void *)RX_4ActivateWdwFunc, NULL, NULL };
static const struct Hook RX_4ZoomWdwHook     = { {NULL, NULL}, (void *)RX_4ZoomWdwFunc    , NULL, NULL };
static const struct Hook RX_4UnzoomWdwHook   = { {NULL, NULL}, (void *)RX_4UnzoomWdwFunc  , NULL, NULL };
static const struct Hook RX_5SortByHook      = { {NULL, NULL}, (void *)RX_5SortByFunc     , NULL, NULL };
static const struct Hook RX_5SetActiveLnHook = { {NULL, NULL}, (void *)RX_5SetActiveLnFunc, NULL, NULL };
static const struct Hook RX_5SelHook         = { {NULL, NULL}, (void *)RX_5SelFunc        , NULL, NULL };
static const struct Hook RX_5DeSelHook       = { {NULL, NULL}, (void *)RX_5DeSelFunc      , NULL, NULL };
static const struct Hook RX_5QryIHook        = { {NULL, NULL}, (void *)RX_5QryIFunc       , NULL, NULL };
static const struct Hook RX_5QryNIHook       = { {NULL, NULL}, (void *)RX_5QryNIFunc      , NULL, NULL };
static const struct Hook RX_5I1Hook          = { {NULL, NULL}, (void *)RX_5I1Func         , NULL, NULL };
static const struct Hook RX_5I2Hook          = { {NULL, NULL}, (void *)RX_5I2Func         , NULL, NULL };
static const struct Hook RX_5I3Hook          = { {NULL, NULL}, (void *)RX_5I3Func         , NULL, NULL };
static const struct Hook RX_5I4Hook          = { {NULL, NULL}, (void *)RX_5I4Func         , NULL, NULL };
static const struct Hook RX_5I5Hook          = { {NULL, NULL}, (void *)RX_5I5Func         , NULL, NULL };
static const struct Hook RX_5I6Hook          = { {NULL, NULL}, (void *)RX_5I6Func         , NULL, NULL };
static const struct Hook RX_5I7Hook          = { {NULL, NULL}, (void *)RX_5I7Func         , NULL, NULL };
static const struct Hook RX_5L1Hook          = { {NULL, NULL}, (void *)RX_5L1Func         , NULL, NULL };
static const struct Hook RX_5L2Hook          = { {NULL, NULL}, (void *)RX_5L2Func         , NULL, NULL };
static const struct Hook RX_5L3Hook          = { {NULL, NULL}, (void *)RX_5L3Func         , NULL, NULL };
static const struct Hook RX_5L4Hook          = { {NULL, NULL}, (void *)RX_5L4Func         , NULL, NULL };
static const struct Hook RX_5L5Hook          = { {NULL, NULL}, (void *)RX_5L5Func         , NULL, NULL };
static const struct Hook RX_6LockGUIHook     = { {NULL, NULL}, (void *)RX_6LockGUIFunc    , NULL, NULL };
static const struct Hook RX_6UnlockGUIHook   = { {NULL, NULL}, (void *)RX_6UnlockGUIFunc  , NULL, NULL };


/*
 * AREXX --------------------------------------------
 */
static struct MUI_Command rxcommands[] =
{
   // PROJECT-RELATED COMMANDS
   { "NEW",    MC_TEMPLATE_ID,         ID_MENU_NEW,   NULL            },
   { "CLEAR",  "FORCE/S",              1,             &RX_1ClearHook  },
   { "OPEN",   "FILENAME/A,FORCE/S",   2,             &RX_1OpenHook   },
   { "SAVE",   MC_TEMPLATE_ID,         ID_MENU_SAVE,  NULL            },
   { "SAVEAS", "NAME",                 1,             &RX_1SaveasHook },
   { "PRINT",  "PROMPT/S,ALL/S",       2,             &RX_1PrintHook  },
   { "CLOSE",  MC_TEMPLATE_ID,         ID_MENU_QUIT,  NULL            },

   // BLOCK-RELATED COMMANDS
   { "CUT",    "",               0, &RX_2CutHook   },
   { "COPY",   "",               0, &RX_2CopyHook  },
   { "PASTE",  "",               0, &RX_2PasteHook },
   { "ERASE",  "FORCE/S",        1, &RX_2EraseHook },

   // WINDOW-RELATED COMMANDS
   { "MOVEWINDOW",      "WINDOW/A,LEFTEDGE/N,TOPEDGE/N", 3, &RX_4MoveWdwHook     },
   { "SIZEWINDOW",      "WINDOW/A,WIDTH/N,HEIGHT/N",     3, &RX_4SizeWdwHook     },
   { "CHANGEWINDOW",    "WINDOW/A,LEFTEDGE/N,TOPEDGE/N,WIDTH/N,HEIGHT/N",
                                                         5, &RX_4ChangeWdwHook   },
   { "WINDOWTOFRONT",   "WINDOW/A",                      1, &RX_4Wdw2FrontHook   },
   { "WINDOWTOBACK",    "WINDOW/A",                      1, &RX_4Wdw2BackHook    },
   { "ACTIVATEWINDOW",  "WINDOW/A",                      1, &RX_4ActivateWdwHook },
   { "ZOOMWINDOW",      "WINDOW/A",                      1, &RX_4ZoomWdwHook     },
   { "UNZOOMWINDOW",    "WINDOW/A",                      1, &RX_4UnzoomWdwHook   },

   // APPLICATION-SPECIFIC COMMANDS
   { "SORTBY",          "SORTTYPE",                                        1, &RX_5SortByHook },
   { "SETACTIVELINE",   "NONE/S, LINE/N",                                  2, &RX_5SetActiveLnHook },
   { "SELECT",          "LINE/N",                                          1, &RX_5SelHook    },
   { "DESELECT",        "ALL/S, LINE/N",                                   2, &RX_5DeSelHook  },
   { "QUERYITEM",       "SELECTED/S, LINE/N, DELIMETER/K",                 3, &RX_5QryIHook   },
   { "QUERYNUMITEMS",   "",                                                0, &RX_5QryNIHook  },
   { "I1FVINVEST",      "NAME/A, VAL1/A, VAL2/A, VAL3/A, VAL4/A, NOREQ/S, CONTCOMP/S", 7, &RX_5I1Hook     },
   { "I2FVREGDEPOSIT",  "NAME/A, VAL1/A, VAL2/A, VAL3/A, VAL4/A, NOREQ/S, CONTCOMP/S", 7, &RX_5I2Hook     },
   { "I3FVDESIRED",     "NAME/A, VAL1/A, VAL2/A, VAL3/A, VAL4/A, NOREQ/S, CONTCOMP/S", 7, &RX_5I3Hook     },
   { "I4REGWITHDRAWAL", "NAME/A, VAL1/A, VAL2/A, VAL3/A, VAL4/A, NOREQ/S, CONTCOMP/S", 7, &RX_5I4Hook     },
   { "I5INITINVEST",    "NAME/A, VAL1/A, VAL2/A, VAL3/A, VAL4/A, NOREQ/S, CONTCOMP/S", 7, &RX_5I5Hook     },
   { "I6MININVEST",     "NAME/A, VAL1/A, VAL2/A, VAL3/A, VAL4/A, NOREQ/S, CONTCOMP/S", 7, &RX_5I6Hook     },
   { "I7INTEREST",      "NAME/A, VAL1/A, VAL2/A, VAL3/A, VAL4/A, NOREQ/S",             6, &RX_5I7Hook     },
   { "L1PAYMENT",       "NAME/A, VAL1/A, VAL2/A, VAL3/A, VAL4/A, NOREQ/S, CONTCOMP/S", 7, &RX_5L1Hook     },
//   { "L2PRINCIPAL",     "NAME/A, VAL1/A, VAL2/A, VAL3/A, VAL4/A, NOREQ/S, CONTCOMP/S", 7, &RX_5L2Hook     },
   { "L2PRINCIPAL",     "NAME/A, VAL1/A, VAL2/A, VAL3/A, VAL4/A, NOREQ/S", 6, &RX_5L2Hook     },
   { "L3TERM",          "NAME/A, VAL1/A, VAL2/A, VAL3/A, VAL4/A, NOREQ/S",             6, &RX_5L3Hook     },
   { "L4INTEREST",      "NAME/A, VAL1/A, VAL2/A, VAL3/A, VAL4/A, NOREQ/S",             6, &RX_5L4Hook     },
   { "L5REMBALANCE",    "NAME/A, VAL1/A, VAL2/A, VAL3/A, VAL4/A, VAL5/A, NOREQ/S",
                                                                           7, &RX_5L5Hook     },

   // INTERFACE COMMANDS
   { "LOCKGUI",   "", 0, &RX_6LockGUIHook    },
   { "UNLOCKGUI", "", 0, &RX_6UnlockGUIHook  },

   { NULL, NULL, NULL, NULL }
};

RXCommands = (struct MUI_Command *)rxcommands;
