home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 291.lha / ArexxInterfaceLibrary_v.8 / smalldemo.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-09-02  |  9.0 KB  |  473 lines

  1. /*    smalldemo.c        */
  2.  
  3.  
  4. /* A small, compilable without my personal librarys, test demo
  5.  * program for the Rxil library.
  6.  *
  7.  * This must be run from the CLI only.
  8.  *
  9.  * This DOES depend on precompiler header files!
  10.  */
  11.  
  12. /*        Copyright © 1989 by Donald T. Meyer, Stormgate Software
  13.  *        All Rights Reserved
  14.  *
  15.  *        This source code may be compiled and used in any software
  16.  *        product.
  17.  *        No portion of this source code is to be re-distributed or
  18.  *        sold for profit.
  19.  *
  20.  *        Donald T. Meyer
  21.  *        Stormgate Software
  22.  *        P.O. Box 383
  23.  *        St. Peters, MO  63376
  24.  *
  25.  *        BIX:    donmeyer        (usually daily)
  26.  *        GEnie:    D.MEYER            (weekly)
  27.  *        PLINK:    Stormgate        (weekly)
  28.  */
  29.  
  30.  
  31. #include "rxil.h"
  32.  
  33.  
  34.  
  35.  
  36. /*--------------------------------------------------------------------*/
  37.  
  38. void openlibrarys( void );
  39. void closelibrarys( void );
  40. void cleanup( void );
  41. void bailout( char *message, int rc );
  42.  
  43. void eventloop( void );
  44.  
  45.  
  46.  
  47. void cmd_status( struct RexxMsg *rexxmsg );
  48. void cmd_quit( struct RexxMsg *rexxmsg );
  49. void cmd_launch_cmd( struct RexxMsg *rexxmsg );
  50. void cmd_launch_func( struct RexxMsg *rexxmsg );
  51. void cmd_ptest( struct RexxMsg *rexxmsg );
  52. void cmd_dump( struct RexxMsg *rexxmsg );
  53.  
  54.  
  55.  
  56. /*--------------------------------------------------------------------*/
  57.  
  58. struct IntuitionBase *IntuitionBase = NULL;
  59. struct GfxBase *GfxBase = NULL;
  60.  
  61.  
  62. BOOL finished = FALSE;
  63.  
  64.  
  65.  
  66. /************************************
  67.  *                                    *
  68.  *    Defined for Rexx Interface    *
  69.  *                                    *
  70.  ************************************/
  71.  
  72. struct RxilDef *global_rdef = NULL;
  73.  
  74.  
  75. struct RxilFunction rexx_cmd_table[] = {
  76.     { "lock", &RxilCmdLock, 0, FALSE, RXIL_PUBLIC },
  77.     { "unlock", &RxilCmdUnlock, 0, FALSE, RXIL_SECRET },
  78.  
  79.     { "status", &cmd_status, 1, FALSE, RXIL_PUBLIC },
  80.     { "quit", &cmd_quit, 0, FALSE, RXIL_PUBLIC },
  81.     { "dump", &cmd_dump, 0, FALSE, RXIL_PUBLIC },
  82.     { "lcmd", &cmd_launch_cmd, 0, FALSE, RXIL_PUBLIC },
  83.     { "lfunc", &cmd_launch_func, 0, FALSE, RXIL_PUBLIC },
  84.     { "ptest", &cmd_ptest, 0, FALSE, RXIL_SECRET },
  85.  
  86.     /* Mark end-of-table */
  87.     { NULL, NULL, 0, FALSE, 0 }
  88. };
  89.  
  90.  
  91. /********************************************************************/
  92.  
  93.  
  94.  
  95. struct RxilInvocation *rxi_cmd;
  96. struct RxilInvocation *rxi_func;
  97.  
  98.  
  99.  
  100. /*--------------------------------------------------------------------*/
  101.  
  102.  
  103. void main( int argc, char *argv[] )
  104. {
  105.     openlibrarys();
  106.  
  107.  
  108.     /* =+=+=+=+=+=+=+=+=+  ARexx Interface Note +=+=+=+=+=+=+=+=+=+=+
  109.      * This will open the rexx library, and the desired ports.
  110.      * If all we want to do is recieve commands, we probably
  111.      * would not open the secret port, although we might. 
  112.      */
  113.     global_rdef = RxilInit( RXIL_PUBLIC | RXIL_SECRET, "MYREXX_TEST" );
  114.     if( global_rdef == NULL )
  115.     {
  116.         bailout( "Unable to init rexx", 0 );
  117.     }
  118.  
  119.  
  120.     /* =+=+=+=+=+=+=+=+=+  ARexx Interface Note +=+=+=+=+=+=+=+=+=+=+
  121.      * Init the members in the RxilDef structure which customize
  122.      * the way things work.
  123.      */
  124.  
  125.     global_rdef->Console = "CON:10/10/400/150/RexxCon";
  126.         /* All commands or functions launched by this program will open
  127.          * a console window of this specification.  Set this to NULL to
  128.          * default to no window.
  129.          */
  130.  
  131.     global_rdef->Extension = "rexx";
  132.         /* this normally would be an application
  133.          * specific macro filename extension.
  134.          */
  135.  
  136.     global_rdef->HostPort = "REXX";
  137.         /* If this is AREXX, launches will default
  138.          * to async (as opposed to synchronous).
  139.          */
  140.  
  141.     global_rdef->CommandTable = &rexx_cmd_table[0];
  142.  
  143.  
  144.  
  145.  
  146.  
  147.     /* =+=+=+=+=+=+=+=+=+  ARexx Interface Note +=+=+=+=+=+=+=+=+=+=+
  148.      * Pre-allocate some invocation structures.  These could
  149.      * also be allocated and de-allocated on-the-fly if desired.
  150.      * One possible philosophy would be to allocate one structure
  151.      * for each possible macro command.  This would speed macro
  152.      * invocations by a slight amount.
  153.      */
  154.     rxi_cmd = RxilCreateRxi( NULL, RXCOMM );
  155.     if( rxi_cmd == NULL )
  156.     {
  157.         bailout( "Unable to allocate command_rxi", RETURN_FAIL );
  158.     }
  159.  
  160.     rxi_func = RxilCreateRxi( NULL, RXFUNC );
  161.     if( rxi_func == NULL )
  162.     {
  163.         bailout( "Unable to allocate function_rxi", RETURN_FAIL );
  164.     }
  165.  
  166.     eventloop();
  167.  
  168.     cleanup();
  169. }
  170.  
  171.  
  172.  
  173. /*-----------------------------------------------------------------*/
  174.  
  175.  
  176. void eventloop( void )
  177. {
  178.     struct RxilInvocation *rxi;
  179.     ULONG flags;
  180.  
  181. #if 0
  182.     /* define some variables to store Intuition Message data in */
  183.     struct IntuiMessage *message;
  184.     ULONG class;
  185.     USHORT code, qualifier;
  186.     SHORT mouseX, mouseY;
  187.     void *address;    /* void since this can point to Screens,
  188.                      * Gadgets, etc. */
  189. #endif
  190.  
  191.     while( !finished )    /* loop until closewindow causes a return() */
  192.     {
  193.         /* =+=+=+=+=+=+=+=+=+  ARexx Interface Note +=+=+=+=+=+=+=+=+=+=+
  194.          * Note that we include the rexx port signal bit(s) in the wait().
  195.          */
  196.         flags = Wait( /* (1L<<win->UserPort->mp_SigBit) | */
  197.             RXIL_WAITFLAG );
  198.  
  199.  
  200.         /* =+=+=+=+=+=+=+=+=+  ARexx Interface Note +=+=+=+=+=+=+=+=+=+=+
  201.          * Now do the ARexx port stuff.
  202.          */
  203.         if(  FlagIsSet( flags, RXIL_WAITFLAG )  )
  204.         {
  205.             RxilCheckPort();
  206.         }
  207.  
  208.         printf( "---Event---\n" );
  209.         printf( "rxi_cmd state: %d\n", (int)rxi_cmd->State );
  210.         printf( "rxi_func state: %d\n", (int)rxi_func->State );
  211.  
  212.         while( rxi = RxilGetReturn() )
  213.         {
  214.             if( rxi->Type == RXCOMM )
  215.             {
  216.                 printf( "Command Invocation completed\n" );
  217.  
  218.                 RxilHandleReturn( rxi );
  219.  
  220.                 RxilCleanupReturn( rxi );
  221.             }
  222.             else
  223.             {
  224.                 printf( "Function Invocation completed\n" );
  225.  
  226.                 RxilHandleReturn( rxi );
  227.  
  228.                 RxilCleanupReturn( rxi );
  229.             }
  230.         }
  231.  
  232.  
  233. #if 0
  234.         while( message = (struct IntuiMessage *)
  235.             GetMsg(win->UserPort) )
  236.         {
  237.             class = message->Class;
  238.             code = message->Code;
  239.             address = message->IAddress;
  240.             mouseX = message->MouseX;
  241.             mouseY = message->MouseY;
  242.             qualifier = message->Qualifier;
  243.  
  244.             ReplyMsg( (struct Message *)message );
  245.  
  246.             switch( class )
  247.             {
  248.                 BOOL bdown = FALSE;
  249.  
  250.                 case MOUSEBUTTONS:
  251.                     if( code == SELECTUP )
  252.                         bdown = FALSE;
  253.     
  254.                     if( code == SELECTDOWN )
  255.                         bdown = TRUE;
  256.  
  257.                     break;
  258.  
  259.                 case INTUITICKS:
  260.                     break;
  261.  
  262.                 case VANILLAKEY:
  263.                     switch( code )
  264.                     {
  265.                         case 'E':
  266.                         case 'e':
  267.                             printf("Enter text: ");
  268.                             gets(buf);
  269.                             PrintScrollText( stext, buf );
  270.                             break;
  271.  
  272.                         case 'd':
  273.                             break;
  274.  
  275.                         case 'l':
  276.                             break;
  277.  
  278.                         case 'r':
  279.                             break;
  280.                     }
  281.                     break;
  282.  
  283.                 case GADGETUP:
  284.                 case GADGETDOWN:
  285.                     HandleScrollText( stext,
  286.                         ((struct Gadget *)address), class );
  287.                     break;
  288.     
  289.                 case CLOSEWINDOW:
  290.                     finished = TRUE;
  291.                     break;
  292.             }
  293.         }
  294. #endif
  295.     }
  296. }
  297.  
  298.  
  299.  
  300.  
  301. void cmd_status( struct RexxMsg *rexxmsg )
  302. {
  303.     printf( "Cmd status\n" );
  304.     printf( "The FromRexx variable is %d\n", RXIL_FROM_REXX );
  305.  
  306.     switch( *RXIL_ARGV(1) )
  307.     {
  308.         case 'L':
  309.         case 'l':
  310.             RxilSetResult( rexxmsg, "Hi there!" );
  311.             break;
  312.  
  313.         case 'B':
  314.         case 'b':
  315.             RxilSetResult( rexxmsg, "I'm NOT Fine!" );
  316.             break;
  317.  
  318.         case 'X':
  319.             rexxmsg->rm_Result1 = 20;
  320.             break;
  321.  
  322.         case 'Y':
  323.             rexxmsg->rm_Result1 = 100;
  324.             break;
  325.  
  326.         case 'Z':
  327.             rexxmsg->rm_Result1 = 200;
  328.             break;
  329.  
  330.         default:
  331.             rexxmsg->rm_Result1 = RXERR_BAD_VARIABLE;
  332.     }
  333. }
  334.  
  335.  
  336.  
  337. /* This will only succeed if the command comes in at the private port.
  338.  */
  339.  
  340. void cmd_ptest( struct RexxMsg *rexxmsg )
  341. {
  342.     printf( "Cmd privlege test\n" );
  343.  
  344.     RxilSetResult( rexxmsg, "You are privleged indeed!" );
  345. }
  346.  
  347.  
  348.  
  349. /* Cause the demo program to exit. */
  350.  
  351. void cmd_quit( struct RexxMsg *rexxmsg )
  352. {
  353.     printf( "Cmd quit\n" );
  354.  
  355.     finished = TRUE;
  356. }
  357.  
  358.  
  359.  
  360. void cmd_dump( struct RexxMsg *rexxmsg )
  361. {
  362.     RxilDumpRdef( global_rdef );
  363. }
  364.  
  365.  
  366.  
  367. void cmd_launch_cmd( struct RexxMsg *rexxmsg )
  368. {
  369.     char buf[100];
  370.     LONG rc;
  371.  
  372.  
  373.     printf( "Cmd launch command:" );
  374.     gets( buf );
  375.  
  376.     rxi_cmd->Name = buf;
  377.     rc = RxilLaunch( rxi_cmd );
  378.     printf( "Launch returned %d\n", rc );
  379. }
  380.  
  381.  
  382.  
  383. static char buf[16][100];
  384.  
  385.  
  386. void cmd_launch_func( struct RexxMsg *rexxmsg )
  387. {
  388.     LONG rc;
  389.     int i;
  390.  
  391.  
  392.     printf( "Cmd launch function:" );
  393.     gets( &buf[0][0] );
  394.  
  395.     for( i=1; i<16; i++ )
  396.     {
  397.         printf( "Enter arg %d: ", i );
  398.         gets( &buf[i][0] );
  399.         if( strlen(&buf[i][0]) > 0 )
  400.         {
  401.             rxi_func->FuncArg[i] = &buf[i][0];
  402.         }
  403.         else
  404.         {
  405.             rxi_func->FuncArg[i] = NULL;
  406.             break;
  407.         }
  408.     }
  409.  
  410.     rxi_func->Name = &buf[0][0];
  411.     rc = RxilLaunch( rxi_func );
  412.  
  413.     printf( "Launch returned %d\n", rc );
  414. }
  415.  
  416.  
  417.  
  418. /*-----------------------------------------------------------------*/
  419.  
  420.  
  421.  
  422.  
  423. void openlibrarys( void )
  424. {
  425.     /*   Intuition   */
  426.     if(  ! ( IntuitionBase = (struct IntuitionBase *)
  427.         OpenLibrary("intuition.library", 33 ) )  )
  428.     {
  429.         bailout( "Unable to open the Intuition Library", RETURN_FAIL );
  430.     }
  431.  
  432.     /*   Graphics   */
  433.     if(  ! ( GfxBase = (struct GfxBase *)
  434.         OpenLibrary("graphics.library", 33 ) )  )
  435.     {
  436.         bailout("Unable to open the Graphics Library", RETURN_FAIL );
  437.     }
  438. }
  439.  
  440.  
  441.  
  442. void closelibrarys( void )
  443. {
  444.     if( IntuitionBase )   CloseLibrary( (struct Library *)IntuitionBase );
  445.     if( GfxBase )   CloseLibrary( (struct Library *)GfxBase );
  446. }
  447.  
  448.  
  449.  
  450. void cleanup( void )
  451. {
  452.     /* =+=+=+=+=+=+=+=+=+  ARexx Interface Note +=+=+=+=+=+=+=+=+=+=+
  453.      * This will handle ALL the cleanup details.  If we wished to make
  454.      * sure that there were no macro program invocations running before
  455.      * we call this routine (and it waits, which may distress the user)
  456.      * we should test our ability to terminate by calling RxilPending().
  457.      */
  458.     RxilCleanup( global_rdef );
  459.     global_rdef = NULL;
  460.  
  461.     closelibrarys();
  462. }
  463.  
  464.  
  465.  
  466. void bailout( char *message, int rc )
  467. {
  468.     printf( "%s/n", message );
  469.     cleanup();
  470.     exit( rc );
  471. }
  472.  
  473.