home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Amiga 12 / MA_Cover_12.iso / libs / bgui / examples / source / arexxdemo.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-02-19  |  8.1 KB  |  242 lines

  1. /*
  2.  * @(#) $Header: /cvsroot/bgui/examples/Attic/ARexxDemo.c,v 1.1.2.2 1999/02/19 05:03:45 mlemos Exp $
  3.  *
  4.  * ARexxDemo.c
  5.  *
  6.  * (C) Copyright 1998 Manuel Lemos.
  7.  * (C) Copyright 1994-1995 Jan van den Baard.
  8.  * (C) Copyright 1994-1995 Jaba Development.
  9.  * All Rights Reserved.
  10.  *
  11.  * Description: Simple demonstration of the arexx class.
  12.  *
  13.  * $Log: ARexxDemo.c,v $
  14.  * Revision 1.1.2.2  1999/02/19 05:03:45  mlemos
  15.  * Added support to build with Storm C.
  16.  *
  17.  * Revision 1.1.2.1  1998/10/12 01:50:43  mlemos
  18.  * Initial revision integrated from Ian sources.
  19.  *
  20.  *
  21.  *
  22.  */
  23.  
  24. /* Execute me to compile with DICE V3.0
  25. dcc arexxdemo.c -proto -mi -ms -lbgui -larexxclass.o
  26. quit
  27. */
  28.  
  29. #include "DemoCode.h"
  30.  
  31. /*
  32. **      Protos for the arexx command functions.
  33. **/
  34. ASM VOID rx_Name( REG(a0) REXXARGS *, REG(a1) struct RexxMsg * );
  35. ASM VOID rx_Version( REG(a0) REXXARGS *, REG(a1) struct RexxMsg * );
  36. ASM VOID rx_Author( REG(a0) REXXARGS *, REG(a1) struct RexxMsg * );
  37. ASM VOID rx_Date( REG(a0) REXXARGS *, REG(a1) struct RexxMsg * );
  38.  
  39. struct Library *BGUIBase = NULL;
  40.  
  41. /*
  42. **      The following commands are
  43. **      valid for this demo.
  44. **/
  45. REXXCOMMAND Commands[] = {
  46.         "NAME",                 NULL,                   rx_Name,
  47.         "VERSION",              NULL,                   rx_Version,
  48.         "AUTHOR",               NULL,                   rx_Author,
  49.         "DATE",                 "SYSTEM/S",             rx_Date,
  50. };
  51.  
  52. /*
  53. **      NAME
  54. **/
  55. #ifdef __STORM__
  56. VOID SAVEDS ASM
  57. #else
  58. SAVEDS ASM VOID
  59. #endif
  60. rx_Name( REG(a0) REXXARGS *ra, REG(a1) struct RexxMsg *rxm )
  61. {
  62.         /*
  63.         **      Simply return the program name.
  64.         **/
  65.         ra->ra_Result = "ARexxDemo";
  66. }
  67.  
  68. /*
  69. **      VERSION
  70. **/
  71. #ifdef __STORM__
  72. VOID SAVEDS ASM rx_Version( REG(a0) REXXARGS *ra, REG(a1) struct RexxMsg *rxm )
  73. #else
  74. SAVEDS ASM VOID rx_Version( REG(a0) REXXARGS *ra, REG(a1) struct RexxMsg *rxm )
  75. #endif
  76. {
  77.         /*
  78.         **      Simply return the program version.
  79.         **/
  80.         ra->ra_Result = "1.0";
  81. }
  82.  
  83. /*
  84. **      AUTHOR
  85. **/
  86. #ifdef __STORM__
  87. VOID SAVEDS ASM rx_Author( REG(a0) REXXARGS *ra, REG(a1) struct RexxMsg *rxm )
  88. #else
  89. SAVEDS ASM VOID rx_Author( REG(a0) REXXARGS *ra, REG(a1) struct RexxMsg *rxm )
  90. #endif
  91. {
  92.         /*
  93.         **      Simply return the authors name.
  94.         **/
  95.         ra->ra_Result = "Jan van den Baard";
  96. }
  97.  
  98. /*
  99. **      Buffer for the system date.
  100. **/
  101. UBYTE                   systemDate[ 10 ];
  102.  
  103. /*
  104. **      DATE
  105. **/
  106. #ifdef __STORM__
  107. VOID SAVEDS ASM rx_Date( REG(a0) REXXARGS *ra, REG(a1) struct RexxMsg *rxm )
  108. #else
  109. SAVEDS ASM VOID rx_Date( REG(a0) REXXARGS *ra, REG(a1) struct RexxMsg *rxm )
  110. #endif
  111. {
  112.         struct DateTime                 dt;
  113.  
  114.         /*
  115.         **      SYSTEM switch specified?
  116.         **/
  117.         if ( ! ra->ra_ArgList[ 0 ] )
  118.                 /*
  119.                 **      No. Simply return the compilation date.
  120.                 **/
  121.                 ra->ra_Result = "25-09-94";
  122.         else {
  123.                 /*
  124.                 **      Compute system date.
  125.                 **/
  126.                 DateStamp(( struct DateStamp * )&dt );
  127.                 dt.dat_Format  = FORMAT_CDN;
  128.                 dt.dat_StrDate = systemDate;
  129.                 dt.dat_Flags   = 0;
  130.                 dt.dat_StrDay  = NULL;
  131.                 dt.dat_StrTime = NULL;
  132.                 DateToStr(&dt);
  133.                 /*
  134.                 **      And return it.
  135.                 **/
  136.                 ra->ra_Result = systemDate;
  137.         }
  138. }
  139.  
  140. /*
  141. **      Object ID's.
  142. **/
  143. #define ID_QUIT                 1
  144.  
  145. VOID StartDemo()
  146. {
  147.    struct Window           *window;
  148.    Object                  *WO_Window, *GO_Quit, *AO_Rexx;
  149.    ULONG                    signal = 0, rxsig = 0L, rc, sigrec;
  150.    BOOL                     running = TRUE;
  151.  
  152.    /*
  153.     *      Create host object.
  154.     */
  155.    if ( AO_Rexx = BGUI_NewObject(BGUI_AREXX_OBJECT, AC_HostName, "RXDEMO", AC_CommandList, Commands, TAG_END )) {
  156.         /*
  157.         **      Create the window object.
  158.         **/
  159.         WO_Window = WindowObject,
  160.                 WINDOW_Title,           "ARexx Demo",
  161.                 WINDOW_SizeGadget,      FALSE,
  162.                 WINDOW_RMBTrap,         TRUE,
  163.                 WINDOW_AutoAspect,      TRUE,
  164.                 WINDOW_MasterGroup,
  165.                         VGroupObject, HOffset( 4 ), VOffset( 4 ), Spacing( 4 ), GROUP_BackFill, SHINE_RASTER,
  166.                                 StartMember,
  167.                                         InfoFixed( NULL,
  168.                                                    ISEQ_C "This is a small demonstration of\n"
  169.                                                    "the ARexx BOOPSI class. Please run the\n"
  170.                                                    ISEQ_B "Demo.rexx" ISEQ_N " script and see\n"
  171.                                                    "what happens",
  172.                                                    NULL,
  173.                                                    4 ),
  174.                                 EndMember,
  175.                                 StartMember,
  176.                                         HGroupObject,
  177.                                                 VarSpace( 50 ),
  178.                                                 StartMember, GO_Quit  = KeyButton( "_Quit",  ID_QUIT  ), EndMember,
  179.                                                 VarSpace( 50 ),
  180.                                         EndObject,
  181.                                 EndMember,
  182.                         EndObject,
  183.         EndObject;
  184.  
  185.         /*
  186.         **      Object created OK?
  187.         **/
  188.         if ( WO_Window ) {
  189.                 /*
  190.                 **      Assign a key to the button.
  191.                 **/
  192.                 if ( GadgetKey( WO_Window, GO_Quit,  "q" )) {
  193.                         /*
  194.                         **      try to open the window.
  195.                         **/
  196.                         if ( window = WindowOpen( WO_Window )) {
  197.                                 /*
  198.                                 **      Obtain wait masks.
  199.                                 **/
  200.                                 GetAttr( WINDOW_SigMask, WO_Window, &signal );
  201.                                 GetAttr( AC_RexxPortMask, AO_Rexx, &rxsig );
  202.                                 /*
  203.                                 **      Event loop...
  204.                                 **/
  205.                                 do {
  206.                                         sigrec = Wait( signal | rxsig );
  207.  
  208.                                         /*
  209.                                         **      ARexx event?
  210.                                         **/
  211.                                         if ( sigrec & rxsig )
  212.                                                 DoMethod( AO_Rexx, ACM_HANDLE_EVENT );
  213.  
  214.                                         /*
  215.                                         **      Window event?
  216.                                         **/
  217.                                         if ( sigrec & signal ) {
  218.                                                 /*
  219.                                                 **      Handle events.
  220.                                                 **/
  221.                                                 while (( rc = HandleEvent( WO_Window )) != WMHI_NOMORE ) {
  222.                                                         /*
  223.                                                         **      Evaluate return code.
  224.                                                         **/
  225.                                                         switch (rc)
  226.                                                         {
  227.                                                         case WMHI_CLOSEWINDOW:
  228.                                                         case ID_QUIT:
  229.                                                            running = FALSE;
  230.                                                            break;
  231.                                                         }
  232.                                                 }
  233.                                         }
  234.                                 } while ( running );
  235.                         } else PutStr ( "Could not open the window.\n" );
  236.                 } else PutStr( "Could not assign gadget keys.\n" );
  237.                 DisposeObject( WO_Window );
  238.         } else PutStr( "Could not create the window object.\n" );
  239.         DisposeObject( AO_Rexx );
  240.    } else PutStr( "Could not create the ARexx host.\n" );
  241. }
  242.