home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 277.lha / TestRH / src / rderxrt.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-08-08  |  6.5 KB  |  319 lines

  1.  
  2.  
  3. /*
  4.  *    RDERXRT.C
  5.  *      routines in C for testrh
  6.  *      (C) Copyright 1989 by Vidyanath Rao
  7.  *              All rights reserved.
  8.  *
  9.  * These routines may be used in freely redistributable software for
  10.  * the Amiga (TM of Commodore-Amiga) computer, provided that credit
  11.  * is given and this notice appears in the software or the documentation.
  12.  */
  13.  
  14. #include <exec/exec.h>
  15. #include <rexx/storage.h>
  16. #include "defs.h"
  17.  
  18. #define SRMF_ASYNCH 1L<<16
  19. #define SRMF_HOSTNM 1L<<17
  20.  
  21. extern char *RHUsrPassWd, *RHMcrPassWd;
  22. extern char *rxerrmsg(), *breakout();
  23. extern UWORD RMSeqNo;
  24.  
  25. /*
  26.  * do_rxc() is a synchronous call to ARexx.
  27.  * do_rximpl(s1, s2) is a synchronous call to ARexx that sends
  28.  * s1 concatenated with s2 as the command.
  29.  * In both cases the call is simply
  30.  *      rxend(sendrxmsg(RXCOMM, xxx, ptr to command str, 0), 0)
  31.  *                        ^ string arg,          ^ no id.
  32.  *                          synchronous
  33.  *                          Host nmae variable
  34.  *
  35.  * do_rxc()
  36.  * {
  37.  *     return(rxend(sendrxmsg(RXCOMM, 0, &av[1], 0)));
  38.  * }
  39.  *
  40.  * do_rximpl(s1, s2)
  41.  *     char *s1, *s2;
  42.  *
  43.  * {
  44.  *     char store[256], *str = store;
  45.  *
  46.  *     strcpy(str, s1);
  47.  *     strcat(str, s2);
  48.  *     return(rxend(sendrxmsg(RXCOMM, SRMF_HOSTNM, &str, 0)));
  49.  * }
  50.  *
  51.  */
  52.  
  53.  
  54. #asm
  55.         public  _do_rxc
  56.  
  57. _do_rxc:
  58.         link    a5,#0
  59.         clr.l   -(sp) ; push the arguments; id = 0
  60.         pea     _av+4 ; cmd str = av[1]
  61.         clr.l   -(sp) ; sync, and string args
  62.         bra.s   dril05
  63.  
  64. SRMF_HOSTNM     EQU     1L<<17
  65.  
  66.         public  _do_rximpld
  67. _do_rximpld:
  68.         link    a5,#-260 ; space for local variables
  69.         lea     -256(a5),a0 ; -256(a5) = local storage
  70.         move.l  a0,-260(a5) ; -260(a5) will point at it.
  71.         move.l  8(a5),a1 ; copy the first string into the storage
  72. dril01: move.b  (a1)+,(a0)+
  73.         bne     dril01
  74.         move.b  #$20,-1(a0) ; seperate the strings with space.
  75.         move.l  12(a5),a1; now concat the second string
  76. dril02: move.b  (a1)+,(a0)+
  77.         bne     dril02
  78.  
  79.         clr.l   -(sp) ; push the args: id = 0
  80.         pea     -260(a5) ; cmd str = store
  81.         move.l  #SRMF_HOSTNM,-(sp) ; str arg and sync call
  82. dril05: pea     16777216 ; action = RXCOMM
  83.         jsr     _sendrxmsg
  84.         addq.l  #8,sp
  85.         clr.l   4(sp) ; id = 0
  86.         move.l  d0,(sp)
  87.         jsr     _rxend
  88.         addq.l  #8,sp
  89.         unlk    a5
  90.         rts
  91. #endasm
  92.  
  93.  
  94. rxend(n, id)
  95.     long n, id;
  96. {
  97.     switch(n) {
  98.       case 0:
  99.         return(1);
  100.       case 1:
  101.         puts("Too many outstanding Rexx commands.");
  102.         CmdErr |= RDE_RXBAD;
  103.         break;
  104.       case 2:
  105.         puts("Unable to create/fill Rexx message");
  106.         CmdErr |= RDE_NOMEM;
  107.         break;
  108.       case 3:
  109.         puts("No public Rexx port.");
  110.         CmdErr |= RDE_RXBAD;
  111.         break;
  112.       default:
  113.         ;
  114.     }
  115. /* The clean-up code for the id goes here */
  116.     CmdErr |= RDE_CMDERR;
  117.     return(0);
  118. }
  119.  
  120.  
  121. do_rxo()
  122. {
  123.     register long act, flags;
  124.     char *args[15];
  125.     long id = 0;
  126.     register int count = 0;
  127.     UWORD rc;
  128.     char qut, pad;
  129.  
  130.     flags = 0;
  131. {
  132. #asm
  133.         move.l  4+_av,a0
  134.         bra     drxol1
  135. drxol2: bset    #5,(a0)+
  136. drxol1: tst.b   (a0)
  137.         bne     drxol2
  138. #endasm
  139. };
  140.  
  141.     if ( av[1][0] == 'f') {
  142.         for (count = 0, qut = 0; (count <= 14); count++) {
  143.             if ( (args[count] = breakout(&av[2], &qut)) == NULL) {
  144.                 break;
  145.             }
  146.         }
  147.         if ( (qut >= 2) || (count == 0) ) {
  148.             for(--count; count >= 0; --count) {
  149.                 free(args[count]);
  150.             }
  151.             return(0);
  152.         }
  153.         act = RXFUNC | (count-1);
  154.     } else {
  155.         args[0] = av[2];
  156.         act = RXCOMM;
  157.     }
  158.  
  159.     if ( av[1][1] == 'r') {
  160.         act |= RXFF_RESULT;
  161.     }
  162.     if (av[1][2] == 's') {
  163.         act |= RXFF_STRING;
  164.         flags |= SRMF_HOSTNM;
  165.     }
  166.     if ( av[1][3] == 't') {
  167.         act |= RXFF_TOKEN;
  168.     }
  169.  
  170.     if ( av[1][4] == 'a') {
  171.         id = 0x00010000 | ( (long) RMSeqNo) ;
  172.         flags |= SRMF_ASYNCH;
  173.     }
  174.  
  175.     rc = sendrxmsg(act, flags, args, id);
  176.     for (--count; count >= 0; --count) {
  177.         free(args[count]);
  178.     }
  179.     return(rxend(rc, id));
  180.  
  181. }
  182.  
  183. drm_end(r2, r1, id)
  184.     union {long err; char *res;} r2;
  185.     long r1, id;
  186.  
  187. {
  188.     char store[128];
  189.  
  190.     if (id == 0) {
  191.         strcpy(store, "Rexx Macro ");
  192.     } else {
  193.         sprintf(store, "RM# %6d ", 0xffff & id);
  194.         store[11] = '\0';
  195.     }
  196.  
  197.     if (r1 == 0) {
  198.         if (r2.res != NULL) {
  199.             if (String != NULL) {
  200.                 free(String);
  201.             }
  202.             String = r2.res;
  203.         }
  204.         strcpy(&store[11], "completed successfully");
  205.     } else if (r1 > 0) {
  206.         sprintf(&store[11], "error (sev %d): %s", r1, rxerrmsg(r2.err));
  207.         if (id == 0) { /* synchornous msg. set CmdErr */
  208.             CmdErr |= RDE_RXBAD;
  209.         }
  210.     } else if (r1 == -1) {
  211.         strcpy(&store[11], "no memory for result");
  212.         CmdErr |= RDE_NOMEM;
  213.     }
  214.  
  215. /* Clean-up routine for the id goes here */
  216.     puts(store);
  217. }
  218.  
  219. do_rhlocks()
  220.  
  221. {
  222.     switch (av[0][0]) {
  223.       case 'c' :
  224.         if (RHMcrPassWd != NULL) {
  225.             free(RHMcrPassWd);
  226.             RHMcrPassWd == NULL;
  227.         }
  228.         RHFlags &= ~(RHF_USRLCK | RHF_MCRLCK);
  229.         puts("Rexx Host locks cleared");
  230.         break;
  231.       case 'l' :
  232.         if (RHUsrPassWd == NULL) {
  233.             puts("No password set");
  234.             return(0);
  235.         } else {
  236.             puts("Rexx Host locked");
  237.             RHFlags |= RHF_USRLCK;
  238.             break;
  239.         }
  240.       case 'u' :
  241.         RHFlags &= ~RHF_USRLCK;
  242.         puts("Rexx Host unlocked");
  243.         break;
  244.     }
  245.     return(1);
  246. }
  247.  
  248. rh_lock(arg, str, len)
  249.     long len;
  250.     char *str, *arg;
  251.  
  252. {
  253.     if (RHFlags & RHF_MCRLCK) {
  254.         return(5);
  255.     }
  256.     if ( (len = strlen(arg)) == 0) {
  257.         return(5);
  258.     }
  259.  
  260.     if ( (RHMcrPassWd = malloc(len+1)) == NULL) {
  261.         return(10);
  262.     }
  263.  
  264.     strcpy (RHMcrPassWd, arg);
  265.     len = 0;
  266.     RHFlags |= RHF_MCRLCK;
  267.     return(0);
  268. }
  269.  
  270. rh_unlock(arg, str, len)
  271.     long len;
  272.     char *str, *arg;
  273.  
  274. {
  275.     if (RHFlags & RHF_MCRLCK == 0) {
  276.         return(5);
  277.     }
  278.     free(RHMcrPassWd);
  279.     RHMcrPassWd == NULL;
  280.     RHFlags &= ~RHF_MCRLCK;
  281.     return(0);
  282. }
  283.  
  284. rh_string(arg, str, len)
  285.     long len;
  286.     char *str, *arg;
  287.  
  288. {
  289.     if ( (len = strlen(String)) == 0) {
  290.         len = 1;
  291.     }
  292.     if ( (str = malloc(len+1)) == NULL) {
  293.         return(10);
  294.     } else {
  295.         strcpy(str, String);
  296.         str[len] = '\0';
  297.         return(0);
  298.     }
  299. }
  300.  
  301. rh_msg2usr(arg, str, len)
  302.     long len;
  303.     char *str, *arg;
  304.  
  305. {
  306.     puts(arg);
  307.     return(0);
  308. }
  309.  
  310. /*
  311. noname(arg, str, len)
  312.     long len;
  313.     char *str, *arg;
  314.  
  315. {
  316.     return(0);
  317. }
  318. */
  319.