home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 230.lha / ArexxFunctionHost / rh_demo.c < prev    next >
C/C++ Source or Header  |  1989-04-03  |  5KB  |  232 lines

  1. /*  ARexx_Host module Demo   */
  2.  
  3.  
  4. /*        Copyright © 1989 by Donald T. Meyer
  5.  *        All Rights Reserved
  6.  *
  7.  *        This source code may be compiled and used in any software
  8.  *        product.
  9.  *        No portion of this source code is to be
  10.  *        re-distributed or sold for profit without the written
  11.  *        permission of the author, Donald T. Meyer.
  12.  *
  13.  *        Donald T. Meyer
  14.  *        Stormgate Software
  15.  *        4 Rustic Creek Court
  16.  *        St. Peters, MO  63376
  17.  *
  18.  *        BIX:    donmeyer
  19.  *        GEnie:    D.MEYER
  20.  *        PLINK:    Stormgate
  21.  */
  22.  
  23.  
  24.  
  25. #include <intuition/intuition.h>
  26.  
  27. #include <proto/intuition.h>
  28. #include <proto/exec.h>
  29.  
  30. #include "rexxfunchost.h"
  31.  
  32.  
  33.  
  34. /*------------------------------------------------------------------*/
  35. /*                    External Function Declarations                    */
  36. /*------------------------------------------------------------------*/
  37.  
  38.  
  39. /*------------------------------------------------------------------*/
  40. /*                    Local Function Declarations                        */
  41. /*------------------------------------------------------------------*/
  42.  
  43. /* Declare all of the host function functions */
  44.  
  45. void func_rats( struct RexxMsg * );
  46. void func_dbeep( struct RexxMsg * );
  47. void func_bigword( struct RexxMsg * );
  48. void func_myerror( struct RexxMsg * );
  49.  
  50.  
  51.  
  52. /*------------------------------------------------------------------*/
  53. /*                    Variable Definitions                            */
  54. /*------------------------------------------------------------------*/
  55.  
  56. char *hostname = "DEMO_FUNC_HOST";
  57. int hostpri = 5;
  58.  
  59.  
  60.  
  61. /* This is the stuff to let us become detached... */
  62.  
  63. long _stack = 4096;
  64. long _priority = 0;
  65. char *_procname = "Demo_ARexxHost";
  66.  
  67.  
  68.  
  69. char *hello_string = "Demo ARexx Function Host Version 0.0\n\
  70. Copyright \xA9 by Don Meyer, Stormgate Software\n\n";
  71.  
  72. char *success_string = "Function Host installation successful!\n";
  73.  
  74. char *removal_string = "Removing existing demo function host!\n";
  75.  
  76. char *redundant_string =
  77.     "Oops, we already are running.  No action taken.\n";
  78.  
  79. char *noclone_string = "No existing demo host to remove!\n";
  80.  
  81.  
  82. char *console_def_string = "CON:30/30/500/60/ARexx Function Host";
  83.  
  84.  
  85.  
  86. struct RexxFunction func_table[] = {
  87.     { "rats", &func_rats, 0, FALSE },
  88.     { "dbeep", &func_dbeep, 0, FALSE },
  89.     { "bigword", &func_bigword, 1, FALSE },
  90.     { "myerror", &func_myerror, -1, FALSE },
  91.  
  92.     /* Mark end-of-table */
  93.     { NULL, NULL, 0, FALSE }
  94. };
  95.  
  96.  
  97.  
  98. /* These are needed only if these librarys will be opened and used. */
  99.  
  100. struct IntuitionBase *IntuitionBase = NULL;
  101. struct GfxBase *GfxBase = NULL;
  102.  
  103.  
  104.  
  105. /*------------------------------------------------------------------*/
  106. /*                    Functions                                        */
  107. /*------------------------------------------------------------------*/
  108.  
  109.  
  110.         /*****************************************
  111.          **                                        **
  112.          **            The Host Functions            **
  113.          **                                        **
  114.          ****************************************/
  115.  
  116.  
  117. /* A function which returns nothing */
  118. /*
  119.  *    call dbeep()
  120.  */
  121.  
  122. void func_dbeep( struct RexxMsg *rexxmsg )
  123. {
  124.     DisplayBeep( NULL );
  125.  
  126.     rexxmsg->rm_Result1 = RC_OK;
  127.     rexxmsg->rm_Result2 = 0;
  128. }
  129.  
  130.  
  131.  
  132. /* A function which returns a string */
  133. /*
  134.  *        say rats()
  135.  */
  136.  
  137. void func_rats( struct RexxMsg *rexxmsg )
  138. {
  139.     SetResultString( rexxmsg, "Large Rodents!" );
  140.  
  141.  
  142. /* "manual" method -----v                                        */
  143. /*                                                                */
  144. /*    rexxmsg->rm_Result1 = RC_OK;                                */
  145. /*    rexxmsg->rm_Result2 =                                        */
  146. /*        (ULONG)CreateArgstring( "Large Rodents!", (LONG)14 );    */
  147. /*                                                                */
  148. }
  149.  
  150.  
  151.  
  152. /* A function which takes one argument and returns a boolean */
  153. /*
  154.  *        say bigword( "Supercalifragilisticexpaladouchs" )
  155.  */
  156.  
  157. void func_bigword( struct RexxMsg *rexxmsg )
  158. {
  159.     if(  LengthArgstring( (struct RexxArg *)ARG1(rexxmsg) ) > 15  )
  160.     {
  161.         SetResultString( rexxmsg, "1" );
  162.     }
  163.     else
  164.     {
  165.         SetResultString( rexxmsg, "0" );
  166.     }
  167. }
  168.  
  169.  
  170.  
  171. /* Returns a function error no matter what */
  172.  
  173. void func_myerror( struct RexxMsg *rexxmsg )
  174. {
  175.     SetResultString( rexxmsg, NULL );
  176.  
  177. /* "manual" method -----v                                        */
  178. /*                                                                */
  179. /*    rexxmsg->rm_Result1 = RC_OK;                                */
  180. /*    rexxmsg->rm_Result2 = ERR10_012                                */
  181. }
  182.  
  183.  
  184.  
  185. /*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
  186.  
  187.  
  188. /* These two functions will be called by the startup and cleanup.
  189.  * Typical use is to open librarys, etc.
  190.  */
  191.  
  192.  
  193. /* This should return a pointer to an error message string to
  194.  * indicate failure
  195.  */
  196.  
  197. char *client_init( void )
  198. {
  199.     /*   Intuition   */
  200.     if(  ! ( IntuitionBase = (struct IntuitionBase *)
  201.         OpenLibrary("intuition.library", LIBRARY_VERSION) )  )
  202.     {
  203.         return( "Unable to open the Intuition Library" );
  204.     }
  205.  
  206.     /*   Graphics   */
  207.     if(  ! ( GfxBase = (struct GfxBase *)
  208.         OpenLibrary("graphics.library", LIBRARY_VERSION) )  )
  209.     {
  210.         return( "Unable to open the Graphics Library" );
  211.     }
  212.  
  213.     return( NULL );
  214. }
  215.  
  216.  
  217.  
  218. /* This will be called prior to exiting.  Note that this will be
  219.  * called no matter what the reason for exiting is (normal completion
  220.  * or termination due to error).
  221.  */
  222.  
  223. void client_cleanup( void )
  224. {
  225.     if( IntuitionBase )
  226.         CloseLibrary( (struct Library *)IntuitionBase );
  227.  
  228.     if( GfxBase )
  229.         CloseLibrary( (struct Library *)GfxBase );
  230. }
  231.  
  232.