home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / arexx / easyrexx.lha / EasyREXX / Source / test2.c < prev   
Encoding:
C/C++ Source or Header  |  1995-02-10  |  3.1 KB  |  146 lines

  1. /*
  2.  *    File:                    test2.c
  3.  *    Description:    Small program to show how easy EasyRexx.library makes
  4.  *                                the AREXX handling.  Shows how to handle AREXX messages
  5.  *                                calling the userdata functions in the commandTable.  Must be
  6.  *                                linked with easyrexx.lib.
  7.  *
  8.  *    (C) 1994-1995, Ketil Hunn
  9.  *
  10.  *    Set tab to 2 for best readability
  11.  *
  12.  */
  13.  
  14. #include <stdio.h>
  15.  
  16. #include <libraries/easyrexx.h>
  17. struct Library *EasyRexxBase;
  18.  
  19. BYTE done=FALSE;
  20.  
  21. #define    AREXX_CLEAR            1
  22. #define    AREXX_OPEN            2
  23. #define    AREXX_SAVEAS        3
  24. #define    AREXX_HELP            4
  25. #define    AREXX_TEXT            5
  26. #define    AREXX_ROW                6
  27. #define    AREXX_QUIT            7
  28. #define    AREXX_VERSION        8
  29. #define    AREXX_NAME            9
  30.  
  31. LONG arexx_clear(struct ARexxContext *c)
  32. {
  33.     printf("CLEAR");
  34.     return RC_OK;
  35. }
  36.  
  37. LONG arexx_open(struct ARexxContext *c)
  38. {
  39.     printf("OPEN");
  40.     if(ARG(c, 1))
  41.         printf(" TEXT");
  42.     else
  43.         printf(" PROJECT");
  44.     if(ARG(c, 2))
  45.         printf(" '%s'", ARGSTRING(c,2));
  46.     return RC_OK;
  47. }
  48.  
  49. LONG arexx_saveas(struct ARexxContext *c)
  50. {
  51.     printf("SAVEAS '%s'", ARGSTRING(c,0));
  52.     return RC_OK;
  53. }
  54.  
  55. LONG arexx_help(struct ARexxContext *c)
  56. {
  57.     printf("HELP");
  58.     if(ARG(c, 0))
  59.         printf(" AMIGAGUIDE");
  60.     if(ARG(c, 1))
  61.         printf(" '%s'", ARGSTRING(c,1));
  62.     return RC_OK;
  63. }
  64.  
  65. LONG arexx_text(struct ARexxContext *c)
  66. {
  67.     printf("TEXT '%s'", ARGSTRING(c,0));
  68.     return RC_OK;
  69. }
  70.  
  71. LONG arexx_row(struct ARexxContext *c)
  72. {
  73.     printf("ROW %ld", ARGNUMBER(c,0));
  74.     return RC_OK;
  75. }
  76.  
  77. LONG arexx_quit(struct ARexxContext *c)
  78. {
  79.     printf("QUIT");
  80.     done=TRUE;
  81.     return RC_OK;
  82. }
  83. /*
  84. LONG arexx_version(struct ARexxContext *c)
  85. {
  86.     printf("VERSION");
  87.     return RC_OK;
  88. }
  89.  
  90. LONG arexx_name(struct ARexxContext *c)
  91. {
  92.     printf("NAME");
  93.     return RC_OK;
  94. }
  95. */
  96. /* This application supports these AREXX commands */
  97. struct ARexxCommandTable commandTable[]=
  98. {
  99. /*    ID              CMD       ARGUMENT TEMPLATE             USERDATA  */
  100.  
  101.     AREXX_CLEAR,        "CLEAR",        "FORCE/S",                                        arexx_clear,
  102.     AREXX_OPEN,            "OPEN",            "PROJECT/S,TEXT/S,NAME/F",        arexx_open,
  103.     AREXX_SAVEAS,        "SAVEAS",        "NAME/K",                                            arexx_saveas,
  104.     AREXX_HELP,            "HELP",            "AMIGAGUIDE/S,TOPIC/F",                arexx_help,
  105.     AREXX_TEXT,            "TEXT",            "TEXT/A/F",                                        arexx_text,
  106.     AREXX_ROW,            "ROW",            "ROWNUMBER/A/N",                            arexx_row,
  107.     AREXX_QUIT,            "QUIT",            NULL,                                                    arexx_quit,
  108.     AREXX_VERSION,    "VERSION",    NULL,                                                    NULL,
  109.     AREXX_NAME,            "NAME",            NULL,                                                    NULL,
  110.     TABLE_END,
  111. };
  112.  
  113. void main(int argc, char **argv)
  114. {
  115.     if(EasyRexxBase=OpenLibrary(EASYREXXNAME, EASYREXXVERSION))
  116.     {
  117.         struct ARexxContext    *context;
  118.  
  119.         if(context=AllocARexxContext(    ER_Portname,            "EASYREXX_TEST",
  120.                                                                     ER_CommandTable,    commandTable,
  121.                                                                     TAG_DONE))
  122.         {
  123.             ULONG signal;
  124.  
  125.             printf(    "Welcome to a small EasyRexx demonstration\n"
  126.                             "-----------------------------------------\n"
  127.                             "Open another shell and start the small\n"
  128.                             "AREXX script: rx test\n"
  129.                             "or doubleclick on the test.rexx icon.\n");
  130.             while(!done)
  131.             {
  132.                 signal=Wait(ER_SIGNAL(context));
  133.  
  134.                 if(signal & ER_SIGNAL(context))
  135.                 {
  136.                     printf("Received: ");
  137.                     HandleARexxFuncs(context);
  138.                     printf("\n");
  139.                 }
  140.             }
  141.             FreeARexxContext(context);
  142.         }
  143.         CloseLibrary(EasyRexxBase);
  144.     }
  145. }
  146.