home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 13 / AACD13.ISO / AACD / Resources / System / BoingBag1 / Contributions / Workbench / RexxArpLib3p6 / src / dispatch.c < prev    next >
C/C++ Source or Header  |  1998-06-20  |  7KB  |  283 lines

  1. /** Dispatch.c
  2.  *
  3.  *   DESCRIPTION:
  4.  *   ===========
  5.  *
  6.  * This function is called as the "query" entry point from the
  7.  * library.  The arguments are contained in a RexxMsg structure, which is
  8.  * used as a parameter block and doesn't need to be unlinked from a port.
  9.  * Dispatch() searches a table to see whether the requested function is
  10.  * contained in this library and calls it if it is found.  The "query"
  11.  * function should never alter the message packet, as it must be passed
  12.  * along to other libraries until the function is found.
  13.  *
  14.  *       Arguments:
  15.  * Up to 15 arguments may be passed in the rm_Args[] array of the parameter
  16.  * block.  Arguments are ALWAYS passed as argstrings and can generally be
  17.  * treated like string pointers in a 'C' program.  The called function may
  18.  * need to convert the strings to numeric values if arithmetic operations
  19.  * are to be performed.  A NULL value in the argument slot means that the
  20.  * argument was omitted from the function call.
  21.  *
  22.  * The total number of arguments (including the defaulted ones) is available
  23.  * in the low-order byte of the action code field rm_Action.
  24.  * Note that REXX supports function calls with varying numbers of arguments,
  25.  * and that the called function can always determine how many were actually
  26.  * passed.
  27.  *
  28.  * Error reporting:
  29.  * The function must return an integer error code and a result string if no
  30.  * errors were detected.  Errors are considered to be ARexx internal error
  31.  * codes, so the function should make use of these values as appropriate.
  32.  * A code of 0 is interpreted to mean that everything worked.
  33.  *
  34.  * Result strings:
  35.  * The result string must be returned as an argstring, a pointer to the
  36.  * string buffer of an RexxArg structure.  Argstrings can be created by a
  37.  * call to the ARexx Systems library function CreateArgstring().
  38.  * N.B. Never allocate a result string if the error code is non-zero!
  39.  *
  40.  *   PRIOR VERSION:
  41.  *   ============
  42.  *
  43.  * This version is written for Aztec C and implements a basic AmigaREXX
  44.  * ARP library. It is based on the example library by Jim Mackraz who
  45.  * got some stuff from Neil Katin, and the Dispatch() routine by Bill Hawes.
  46.  * All changes and additions by me.
  47.  *
  48.  *   AUTHOR/DATE:  W.G.J. Langeveld, November 1987.
  49.  *   ============
  50.  *
  51.  *    CURRENT VERSION:
  52.  *
  53.  *    This version has been converted to SAS C 6.5 format. It has been modified
  54.  *    for modern definition sequences for ANSI compilation.
  55.  *
  56.  *   AUTHOR/DATE:  Joanne Dow, jdow@bix.com, June 1998.
  57.  *   ============
  58.  *
  59. **/
  60. #include <functions.h>
  61. #include "ralprotos.h"
  62. #include <libraries/MyARP.h>
  63. #include <intuition/intuitionbase.h>
  64. #include <proto/rexxsyslib.h>
  65. #include <stdlib.h>
  66. #include <string.h>
  67. #include <ctype.h>
  68. #include <simpreq.h>
  69. #include "rexxarplib.h"
  70.  
  71. /*
  72.  *   Library bases
  73.  */
  74. struct ArpBase       *ArpBase = NULL;
  75. struct Library       *AslBase = NULL;
  76. struct IntuitionBase *IntuitionBase = NULL;
  77. struct GfxBase       *GfxBase = NULL;
  78. struct Library       *DiskfontBase = NULL;
  79. struct Library        *RexxSysBase = NULL;
  80. struct DosLibrary    *DOSBase = NULL;
  81.  
  82. /*
  83.  *   The function table
  84.  */
  85. static struct RXfunc rxfs[] = 
  86. {
  87.     {
  88.         rxf_getfile,   "GETFILE"       , 11, 0       
  89.     }
  90.     ,
  91.     {
  92.         rxf_getsimp,   "REQUEST"       , 7 , 0       
  93.     }
  94.     ,
  95.     {
  96.         rxf_getenv,    "GETENV"        , 1 , 1       
  97.     }
  98.     ,
  99.     {
  100.         rxf_setenv,    "SETENV"        , 2 , 1       
  101.     }
  102.     ,
  103.     {
  104.         rxf_postmsg,   "POSTMSG"       , 4 , 0       
  105.     }
  106.     ,
  107.     {
  108.         rxf_stofront,  "SCREENTOFRONT" , 1 , 0       
  109.     }
  110.     ,
  111.     {
  112.         rxf_stoback,   "SCREENTOBACK"  , 1 , 0       
  113.     }
  114.     ,
  115.     {
  116.         rxf_srows,     "SCREENROWS"    , 1 , 0       
  117.     }
  118.     ,
  119.     {
  120.         rxf_scols,     "SCREENCOLS"    , 1 , 0       
  121.     }
  122.     ,
  123.     {
  124.         rxf_slace,     "SCREENLACE"    , 1 , 0       
  125.     }
  126.     ,
  127.     {
  128.         rxf_sopen,     "OPENSCREEN"    , 9 , 5       
  129.     }
  130.     ,
  131.     {
  132.         rxf_sclose,    "CLOSESCREEN"   , 1 , 1       
  133.     }
  134.     ,
  135.     {
  136.         rxf_sendp,     "SENDPARSED"    , 15, 1       
  137.     }
  138.     ,
  139.     {
  140.         rxf_createhost,"CREATEHOST"    , 3 , 2       
  141.     }
  142.     ,
  143.     {
  144.         rxf_filelist,  "FILELIST"      , 4 , 2       
  145.     }
  146.     ,
  147.     {
  148.         rxf_scolor,    "SCREENCOLOR"   , 5 , 2       
  149.     }
  150.     ,
  151.     {
  152.         rxf_showtitle, "SHOWTITLE"     , 2 , 2       
  153.     }
  154.     ,
  155.     {
  156.         rxf_getfont,   "GETFONT"       , 14, 0       
  157.     }
  158.     ,
  159.     {
  160.         rxf_smove,     "MOVESCREEN"    , 3 , 1       
  161.     }
  162.     ,
  163.     {
  164.         rxf_getlist,   "REQUESTLIST"   , 10, 3       
  165.     }
  166.     ,
  167.     {
  168.         rxf_null,          NULL        , 1 , 0       
  169.     }
  170. };
  171.  
  172. /**
  173.  *
  174.  *   The dispatcher.
  175.  *
  176. **/
  177. long __stdargs __saveds RALDispatch( struct RexxMsg *rmptr, char **resptr )
  178. {
  179.     int nargs = 0, ival = 0, done = FALSE;
  180.     long result = 12L;
  181.     
  182.     DOSBase = (struct DosLibrary *) OpenLibrary("dos.library", 36);
  183.     if (DOSBase == NULL)
  184.         goto cleanup;
  185.     
  186.     ArpBase = (struct ArpBase*) OpenLibrary("arp.library", 0L);
  187.     if (ArpBase == NULL)
  188.         goto cleanup;
  189.     
  190.     AslBase = OpenLibrary("asl.library", 0L);
  191.     
  192.     DiskfontBase = (struct Library *) OpenLibrary("diskfont.library", 0L);
  193.     
  194.     RexxSysBase = OpenLibrary("rexxsyslib.library", 0L);
  195.     if (RexxSysBase == NULL)
  196.         goto cleanup;
  197.     
  198.     if (!SReqOpenLibs())
  199.         goto cleanup;
  200.     
  201.     result = 1L;
  202.     *resptr = NULL;
  203.     /*
  204.      *   Get the number of provided arguments.
  205.      */
  206.     nargs = (rmptr->rm_Action) & 0xFF;
  207.     /*
  208.      *   Get the function index
  209.      */
  210.     ival = rxhtable_index(rmptr->rm_Args[0]);
  211.     if (ival >= 0) 
  212.     {
  213.         /*
  214.          *   Got a regular function. Make sure it is an exact match.
  215.          */
  216.         if (strcmpu(rmptr->rm_Args[0], rxfs[ival].rexxname) == 0) 
  217.         {
  218.             result = 17L;
  219.             /*
  220.              *   Check number of arguments
  221.              */
  222.             if (nargs > rxfs[ival].nargs)
  223.                 goto cleanup;
  224.             if (nargs < rxfs[ival].nargs_req)
  225.                 goto cleanup;
  226.             /*
  227.              *   Call the function with the proper number of arguments.
  228.              *   14 is 'filelist'. Sorry 'bout the kludge... ;^)
  229.              *   17 is 'getfont'. Another kludge...
  230.              *   19 is 'requestlist', Another kludge...
  231.              */
  232.             if (ival == 14 || ival == 0 || ival == 17 || ival == 19) 
  233.             {
  234.                 *resptr = (*rxfs[ival].rexxfunc)(&result, nargs, (char **) rmptr);
  235.             }
  236.             else
  237.             {
  238.                 *resptr = (*rxfs[ival].rexxfunc)(&result, nargs, &(rmptr->rm_Args[1]));
  239.             }
  240.             done = TRUE;
  241.         }
  242.     }
  243.     
  244.     if (!done) 
  245.     {
  246.         /*
  247.          *   If not a regular function, see if this is a window host function
  248.          */
  249.         ival = whf_find(&result, nargs - 1, rmptr->rm_Args[0]);
  250.         
  251.         if (ival >= 0)
  252.             *resptr = whf_sendp(&result, nargs + 1, &(rmptr->rm_Args[0]));
  253.     }
  254.     
  255.     cleanup:
  256.     SReqCloseLibs();
  257.     if (RexxSysBase)
  258.         CloseLibrary( RexxSysBase );
  259.     if (DiskfontBase)
  260.         CloseLibrary( DiskfontBase );
  261.     if (ArpBase)
  262.         CloseLibrary( ( struct Library * ) ArpBase );
  263.     if (AslBase)
  264.         CloseLibrary( AslBase );
  265.     if (DOSBase)
  266.         CloseLibrary( ( struct Library * ) DOSBase );
  267.     
  268.     return(result);
  269. }
  270.  
  271.  
  272. /**
  273.  *
  274.  *   The null function
  275.  *
  276. **/
  277. char *rxf_null( long *err, int n, char **dummy )
  278. {
  279.     *err = 21L;
  280.     return(0L);
  281. }
  282.  
  283.