home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 113 / EnigmaAmiga113CD.iso / software / on-line / amster_install / source / rexx.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-06-09  |  3.3 KB  |  135 lines

  1. /*
  2. ** ARexx Support
  3. */
  4.  
  5. #include "include/config.h"
  6.  
  7. #include <stdio.h>
  8. #include <string.h>
  9. #include <stdarg.h>
  10.  
  11. #include <proto/exec.h>
  12. #include <proto/dos.h>
  13. #include <proto/rexxsyslib.h>
  14. #include <rexx/storage.h>
  15.  
  16. #include "include/msg.h"
  17. #include "include/mui.h"
  18. #include "include/search.h"
  19. #include "include/gui.h"
  20. #include "include/rexx.h"
  21. #include "amster_Cat.h"
  22.  
  23. MUIF rexx_con(REG(a0) struct Hook *h,REG(a2) Object *app, REG(a1) char **array);
  24. MUIF rexx_dis(REG(a0) struct Hook *h,REG(a2) Object *app, REG(a1) char **array);
  25. MUIF rexx_ison(REG(a0) struct Hook *h,REG(a2) Object *app, REG(a1) char **array);
  26. MUIF rexx_search(REG(a0) struct Hook *h,REG(a2) Object *app, REG(a1) char **array);
  27. MUIF rexx_sstat(REG(a0) struct Hook *h,REG(a2) Object *app, REG(a1) char **array);
  28. MUIF rexx_whois(REG(a0) struct Hook *h,REG(a2) Object *app, REG(a1) char **array);
  29.  
  30. struct Hook rexx_conHook = { {0,0}, &rexx_con, NULL, NULL };
  31. struct Hook rexx_disHook = { {0,0}, &rexx_dis, NULL, NULL };
  32. struct Hook rexx_isonHook = { {0,0}, &rexx_ison, NULL, NULL };
  33. struct Hook rexx_searchHook = { {0,0}, &rexx_search, NULL, NULL };
  34. struct Hook rexx_sstatHook = { {0,0}, &rexx_sstat, NULL, NULL };
  35. struct Hook rexx_whoisHook = { {0,0}, &rexx_whois, NULL, NULL };
  36.  
  37. struct MUI_Command rexx_cmds[] = {
  38.     { "connect", NULL, 0, &rexx_conHook },
  39.     { "disconnect", NULL, 0, &rexx_disHook },
  40.     { "isonline", NULL, 0, &rexx_isonHook },
  41.     { "search", "TITLE/A", 1, &rexx_searchHook },
  42.     { "searchstate", NULL, 0, &rexx_sstatHook },
  43.     { "whois", "USER/A", 1, &rexx_whoisHook },
  44.     { NULL, NULL, 0, NULL }
  45. };
  46.  
  47.  
  48. MUIF rexx_con(REG(a0) struct Hook *h,REG(a2) Object *app, REG(a1) char **array)
  49. {
  50.     if (!gui_napon) nap_login();
  51.     return(0);
  52. }
  53.  
  54.  
  55. MUIF rexx_dis(REG(a0) struct Hook *h,REG(a2) Object *app, REG(a1) char **array)
  56. {
  57.     nap_logout();
  58.     set(gui->stat, MUIA_Text_Contents, MSG_STATUS2_NOTCONNECTED);
  59.     return(0);
  60. }
  61.  
  62.  
  63. MUIF rexx_ison(REG(a0) struct Hook *h,REG(a2) Object *app, REG(a1) char **array)
  64. {
  65.     if (gui_napon) return(1); else return(0);
  66. }
  67.  
  68.  
  69. MUIF rexx_search(REG(a0) struct Hook *h,REG(a2) Object *app, REG(a1) char **array)
  70. {
  71.     DoMethod(gui->searchpanel, SEARCH_GO, array[0]);
  72.     return(0);
  73. }
  74.  
  75.  
  76. MUIF rexx_sstat(REG(a0) struct Hook *h,REG(a2) Object *app, REG(a1) char **array)
  77. {
  78.     DoMethod(gui->searchpanel, SEARCH_GETSTATE);
  79.     return (ULONG)search_state;
  80. }
  81.  
  82.  
  83. MUIF rexx_whois(REG(a0) struct Hook *h,REG(a2) Object *app, REG(a1) char **array)
  84. {
  85.     if (gui_napon) nap_sendbuf(NAPC_WHOIS, array[0]);
  86.     return(0);
  87. }
  88.  
  89.  
  90. u_long rexx_sendcommand(char *port, char *com)
  91. {
  92.     struct MsgPort *me,*him;
  93.     struct RexxMsg *rmsg;
  94.     u_long rc=0;
  95.  
  96.     if (me=CreateMsgPort()) {
  97.         if (rmsg = CreateRexxMsg(me,NULL,NULL)) {
  98.             if (rmsg->rm_Args[0] = CreateArgstring(com, strlen(com))) {
  99.                 rmsg->rm_Action = RXCOMM;
  100.                 Forbid();
  101.                 him = FindPort(port);
  102.                 Permit();
  103.                 if (him) {
  104.                     PutMsg(him, (struct Message *)rmsg);
  105.                     WaitPort(me);
  106.                     GetMsg(me);
  107.                     rc = rmsg->rm_Result1;
  108. /*                    if (!rc && rmsg->rm_Result2) DeleteArgstring(rmsg->rm_Result2);*/
  109.                 }
  110.                 DeleteArgstring(rmsg->rm_Args[0]);
  111.             }
  112.             DeleteRexxMsg(rmsg);
  113.         }
  114.         DeleteMsgPort(me);
  115.     }
  116.     return(rc);
  117. }
  118.  
  119.  
  120. void rexx_execute(char *com, char *argfmt, ...)
  121. {
  122.     static char buf[1024];
  123.     char *p;
  124.     va_list ap;
  125.  
  126.     p = buf + sprintf(buf,"Run <>NIL: RexxC:RX %s ",com);
  127.     if(argfmt) {
  128.         va_start(ap,argfmt);
  129.         vsprintf(p,argfmt,ap);
  130.         va_end(ap);
  131.     }
  132.  
  133.     Execute(buf, 0, 0);
  134. }
  135.