home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / coders / proasm / routines / arexx.r < prev    next >
Text File  |  1993-12-28  |  9KB  |  480 lines

  1.  
  2. ;---;  ARexx  ;----------------------------------------------------------------
  3. *
  4. *    ****    ARexx HANDLER ROUTINES    ****
  5. *
  6. *    Author        Daniel Weber
  7. *    Version        1.12
  8. *    Last Revision    28.12.93
  9. *    Identifier    rxx_defined
  10. *       Prefix        rxx_    (ARexx Routines)
  11. *                  ¯ ¯¯
  12. *    Functions    CreateARexxPort()    - create a valid arexx port
  13. *            DeleteARexxPort()    - delete/remove it
  14. *            DoARexxMsg()        - send an arexx msg and wait
  15. *            SendARexxMsg()        - send an arexx message
  16. *            SendFlagedARexxMsg()    - send an arexx message with flags
  17. *            FreeARexxCommand()    - free contents of a arexx msg
  18. *            GetARexxCommand()    - get first argument of a msg
  19. *            CheckARexxCommand()    - check if it's a valid arexx msg
  20. *            ReplyARexxMessage()    - returns a msg to the server
  21. *            GetARexxArg()        - get the argument from a msg
  22. *            GetARexxResult()    - get the result(s)
  23. *
  24. ;------------------------------------------------------------------------------
  25.  
  26. ;------------------
  27.     IFND    rxx_defined
  28. rxx_defined    SET    1
  29.  
  30. ;------------------
  31. rxx_oldbase    EQU    __BASE
  32.     BASE    rxx_base
  33. rxx_base:
  34.  
  35. ;------------------
  36.     opt    sto,o+,ow-,q+,qw-    ;all optimisations on
  37.  
  38. ;------------------
  39.     incdir    include:
  40.     incdir    routines:
  41. ;    include    "exec/types.i"        ;included via rexx/storage.i
  42. ;    include    "exec/ports.i"        ;"        "   "
  43.     include    "rexx/rxslib.i"
  44.     include    "rexx/rexxio.i"
  45.  
  46.     include    ports.r
  47.  
  48. ;------------------
  49.     IFND    MN_NODE
  50. MN_NODE    equ    0            ;value taken from 'Struct.doc'
  51.     ENDC
  52.  
  53.  
  54.  
  55. ;------------------------------------------------------------------------------
  56. *
  57. * CreateARexxPort()
  58. *
  59. * a0: MsgPort structure (see structure.r)
  60. * a1: Portname
  61. *
  62. * => d0: MsgPort or 0 if an error is occured
  63. *
  64. ;------------------------------------------------------------------------------
  65.     IFD    xxx_CreateARexxPort
  66.  
  67. CreateARexxPort:
  68. ;------------------
  69.  
  70.     movem.l    d1-a6,-(a7)
  71.     move.l    a0,a4
  72.     move.l    4.w,a6
  73.     jsr    -390(a6)            ;findport()
  74.     tst.l    d0
  75.     bne.s    .out
  76.  
  77.     move.l    a4,a0
  78.     bsr    MakePort
  79. .out:    movem.l    (a7)+,d0-a6
  80.     rts
  81.  
  82.     ENDC
  83.  
  84.  
  85. ;------------------------------------------------------------------------------
  86. *
  87. * DeleteARexxPort()
  88. *
  89. * a0: MsgPort
  90. *
  91. ;------------------------------------------------------------------------------
  92.     IFD    xxx_DeleteARexxPort
  93.  
  94. DeleteARexxPort:
  95. ;------------------
  96.  
  97.     movem.l    d0-a6,-(a7)
  98.     move.l    a0,d0
  99.     beq.s    .out
  100.     bsr    UnMakePort
  101. .out:    movem.l    (a7)+,d0-a6
  102.     rts
  103.  
  104.     ENDC
  105.  
  106.  
  107. ;------------------------------------------------------------------------------
  108. *
  109. * DoARexxMsg()
  110. *
  111. * d0: MsgPort
  112. * a0: Target port name
  113. * a1: Command string
  114. * a2: File extension (default: .rexx)
  115. *
  116. * => d0: (0: false/error   -: ARexxMessage)
  117. *
  118. ;------------------------------------------------------------------------------
  119.     IFD    xxx_DoARexxMsg
  120. xxx_SendARexxMsg    SET    1
  121.  
  122. DoARexxMsg:
  123. ;------------------
  124.  
  125.     movem.l    d0-d1/a0-a2/a6,-(a7)
  126.     bsr.s    SendARexxMsg
  127.     tst.l    d0                ;error occured???
  128.     beq.s    1$
  129.     move.l    4.w,a6
  130.     move.l    (a7),a0                ;msgport
  131.     jsr    -384(a6)            ;waitport()
  132. 1$:    movem.l    (a7)+,d0-d1/a0-a2/a6
  133.     rts
  134.  
  135.     ENDC
  136.  
  137.  
  138. ;------------------------------------------------------------------------------
  139. *
  140. * SendARexxMsg()
  141. * SendFlagedARexxMsg()
  142. *
  143. * d0: MsgPort
  144. * (d1: command flags, for SentFlagedARexxMsg only)
  145. * a0: target port name
  146. * a1: command string
  147. * a2: file extension (default: .rexx)
  148. *
  149. * => d0: (0: false/error   -: RexxMessage)
  150. *
  151. ;------------------------------------------------------------------------------
  152.  
  153.     IFD    xxx_SendFlagedARexxMsg
  154. xxx_SendARexxMsg    SET    1
  155.  
  156. SendFlagedARexxMsg:
  157. ;------------------
  158.     movem.l    d1-a6,-(a7)
  159.     move.l    d1,d5
  160.     bra.s    rxx_SendARexxMsg
  161.  
  162.     ENDC
  163.  
  164.  
  165. ;----------------------------
  166.     IFD    xxx_SendARexxMsg
  167. xxx_rxx_getstrlen    SET    1
  168.  
  169. SendARexxMsg:
  170. ;------------------
  171.  
  172.     movem.l    d1-a6,-(a7)
  173.     moveq    #0,d5            ;no additional flags
  174. ;
  175. ; d5: additional command flags
  176. ;
  177. rxx_SendARexxMsg:            ;entry for SendFlagedARexxMsg
  178.     move.l    d0,d7            ;no port given
  179.     beq    \senderror
  180.     move.l    a1,d6            ;no commandstring given
  181.     beq    \senderror
  182.  
  183.     move.l    a0,d0            ;init...
  184.     beq    \senderror        ;no target port name
  185.     move.l    a2,d1
  186.     bne.s    11$
  187.     lea    rxx_rexxext(pc),a2
  188. 11$:    move.l    a2,a1            ;extension
  189.     move.l    RexxBase(pc),a6    ;RexxBase        (d1)
  190.     move.l    d7,a0            ;replyport
  191.     jsr    _LVOCreateRexxMsg(a6)
  192.     move.l    d0,d7
  193.     beq    \senderror
  194.     move.l    d0,a4            ;save message structure
  195.  
  196.     move.l    d6,a0
  197.     bsr    rxx_getstrlen
  198.     jsr    _LVOCreateArgstring(a6)
  199.     move.l    d0,rm_Args(a4)
  200.     beq.s    \argerror
  201.  
  202.     or.l    #RXCOMM,d5
  203.     move.l    d5,rm_Action(a4)    ;not a function
  204.  
  205.     move.l    4.w,a6
  206.     jsr    -132(a6)        ;forbid()
  207.     lea    rxx_rexxport(pc),a1    ;"REXX"
  208.     jsr    -390(a6)        ;findport()
  209.     tst.l    d0            ;no rexxport opened
  210.     beq    \argerror2
  211.  
  212.     move.l    d0,a0            ;dest. Port (REXX)
  213.     move.l    a4,a1            ;Message
  214.     jsr    -366(a6)        ;putmsg()
  215.     jsr    -138(a6)        ;permit()
  216.  
  217.     move.l    a4,d0            ;message in d0
  218.     movem.l    (a7)+,d1-a6
  219.     rts
  220.  
  221.  
  222. \argerror2:
  223.     jsr    -138(a6)        ;permit()
  224. \argerror:
  225.     move.l    RexxBase(pc),a6
  226.     move.l    a4,a0
  227.     jsr    _LVODeleteRexxMsg(a6)
  228. \senderror:                ;no...
  229.     movem.l    (a7)+,d1-a6        ;commandstring, port
  230.     moveq    #0,d0            ;or REXX-port
  231.     rts                ;found
  232.  
  233. rxx_rexxport
  234. rxx_rexxext:
  235.     dc.b    "REXX",0
  236.     even
  237.  
  238.     ENDC
  239.  
  240.  
  241. ;--------------------------------------
  242. ;a0: string
  243. ;=> d0: length
  244. ;
  245.     IFD    xxx_rxx_getstrlen
  246.  
  247. rxx_getstrlen:
  248.     move.l    a0,-(a7)
  249.     moveq    #0,d0
  250. \loop:
  251.     tst.b    (a0)+
  252.     beq.s    2$
  253.     addq.l    #1,d0
  254.     bra.s    \loop
  255. 2$:    move.l    (a7)+,a0
  256.     rts
  257.  
  258.     ENDC
  259.  
  260.  
  261. ;------------------------------------------------------------------------------
  262. *
  263. * FreeARexxCommand()
  264. *
  265. * d0: RexxMessage
  266. *
  267. ;------------------------------------------------------------------------------
  268.     IFD    xxx_FreeARexxCommand
  269.  
  270. FreeARexxCommand:
  271. ;------------------
  272.  
  273.     movem.l    d0-a6,-(a7)
  274.     tst.l    d0
  275.     beq.s    .out
  276.     move.l    d0,a4
  277.     move.l    RexxBase(pc),a6        ;RexxBase    (d1)
  278.     move.l    rm_Args(a4),d0
  279.     beq.s    \noargs
  280.     move.l    d0,a0
  281.     jsr    _LVODeleteArgstring(a6)
  282.  
  283. \noargs:
  284.     move.l    a4,a0
  285.     jsr    _LVODeleteRexxMsg(a6)
  286. .out:    movem.l    (a7)+,d0-a6
  287.     rts
  288.  
  289.     ENDC
  290.  
  291.  
  292. ;------------------------------------------------------------------------------
  293. *
  294. * GetARexxCommand()
  295. *
  296. * a0: RexxMessage
  297. *
  298. * => d0: first argument or 0 if no message arrived...
  299. *
  300. ;------------------------------------------------------------------------------
  301.     IFD    xxx_GetARexxCommand
  302.  
  303. GetARexxCommand:
  304. ;------------------
  305.  
  306.     movem.l    d1-a6,-(a7)
  307.     move.l    MN_NODE(a0),d0
  308.     beq.s    .out
  309.     move.l    d0,a1
  310.     cmp.w    #NT_REPLYMSG,RRTYPE(a1)    ;RRTYPE=LN_TYPE
  311.     beq.s    \nomessage
  312.     move.l    rm_Args(a1),d0        ;first argument
  313. .out    movem.l    (a7)+,d1-a6
  314.     rts
  315.  
  316.     ENDC
  317.  
  318.  
  319. ;------------------------------------------------------------------------------
  320. *
  321. * CheckARexxMsg()
  322. *
  323. * a0: RexxMessage
  324. *
  325. * => d0: TRUE(-1) if it is a RexxMsg, FALSE(0) if it is not a RexxMsg
  326. *
  327. ;------------------------------------------------------------------------------
  328.     IFD    xxx_CheckARexxMsg
  329.  
  330. CheckARexxMsg:
  331. ;------------------
  332.  
  333.     movem.l    d1-a6,-(a7)
  334.     move.l    a0,d0
  335.     beq.s    \nomsg
  336.     move.l    RexxBase(pc),a6
  337.     jsr    _LVOIsRexxMsg(a6)    ;IsRexxMsg()
  338. \nomsq:    movem.l    (a7)+,d1-a6
  339.     rts
  340.  
  341.     ENDC
  342.  
  343.  
  344. ;------------------------------------------------------------------------------
  345. *
  346. * ReplyARexxMessage()
  347. *
  348. * d0: Error# (or zero if no error)
  349. * a0: ARexx Message
  350. * a1: Return String (Result) [string will be doublicated by Rexx]
  351. *
  352. ;------------------------------------------------------------------------------
  353.     IFD    xxx_ReplyARexxMessage
  354. xxx_rxx_getstrlen    SET    1
  355.  
  356. ReplyARexxMessage:
  357. ;------------------
  358.  
  359.     movem.l    d0-a6,-(a7)
  360.     move.l    RexxBase(pc),a6
  361.     move.l    a0,a4
  362.     clr.l    rm_Result2(a4)
  363.     move.l    d0,rm_Result1(a4)    ;error?
  364.     bne.s    .return            ;yes, no further result handling
  365.     move.l    rm_Action(a4),d0
  366.     and.l    #RXFF_RESULT,d0        ;result requeted
  367.     beq.s    .return
  368.     move.l    a1,d0
  369.     beq.s    1$
  370.     move.l    d0,a0
  371.     bsr    rxx_getstrlen
  372. 1$:    jsr    _LVOCreateArgstring(a6)
  373.     move.l    d0,rm_Result2(a4)
  374. .return:
  375.     move.l    4.w,a6
  376.     move.l    a4,a1
  377.     jsr    _LVOReplyMsg(a6)
  378.     movem.l    (a7)+,d0-a6
  379.     rts
  380.  
  381.     ENDC
  382.  
  383.  
  384. ;------------------------------------------------------------------------------
  385. *
  386. * GetARexxArg()
  387. *
  388. * d0: Argument number (0-15)
  389. * a0: RexxMessage
  390. *
  391. * =>d0: Argument (or zero if the argument number is higher than 15!)
  392. * =>d1: start of first argument (or zero if the arg number is higher than 15!)
  393. *
  394. ;------------------------------------------------------------------------------
  395.     IFD    xxx_GetARexxArg
  396.  
  397. GetARexxArg:
  398. ;------------------
  399.  
  400.     movem.l    d2-a6,-(a7)
  401.     move.l    a0,d2
  402.     beq.s    \noRexxMsg
  403.     moveq    #15,d2
  404.     cmp.l    d2,d0
  405.     bhi.s    \noRexxMsg
  406.     lsl.w    #2,d0
  407.     lea.l    rm_Args(a0),a0
  408.     move.l    (a0,d0.w),d0        ;get the argument
  409.     move.l    a0,d1            ;pointer to the first arg (rm_Arg0)
  410.     movem.l    (a7)+,d2-a6
  411.     rts
  412.  
  413. \noRexxMsg:
  414.     movem.l    (a7)+,d2-a6
  415.     moveq    #0,d0
  416.     moveq    #0,d1
  417.     rts
  418.  
  419.     ENDC
  420.  
  421.  
  422. ;------------------------------------------------------------------------------
  423. *
  424. * GetARexxResult()
  425. *
  426. * d0: RexxMessage
  427. * d1: Result number (1/2/- : Result1/Result2/Result1&2)
  428. *
  429. * =>d0: result_1/2
  430. * =>d1: result_2, if the result number wasnot equal to 1 or 2
  431. *
  432. ;------------------------------------------------------------------------------
  433.     IFD    xxx_GetARexxResult
  434.  
  435. GetARexxResult:
  436. ;------------------
  437.  
  438.     movem.l    d2-a6,-(a7)
  439.     tst.l    d0
  440.     beq.s    \norexxmessage
  441.     move.l    d0,a0
  442.     subq.l    #1,d1
  443.     bne.s    \Result2
  444.  
  445. \Result1:                ;get the first Result...
  446.     move.l    rm_Result1(a0),d0
  447.     bra.s    \norexxmessage
  448.  
  449. \Result2:                ;...the second Result...
  450.     subq.l    #1,d1
  451.     bne.s    \bothResults
  452.     move.l    rm_Result2(a0),d0
  453.     bra.s    \norexxmessage
  454.  
  455. \bothResults:                ;... both Results!
  456.     move.l    rm_Result1(a0),d0
  457.     move.l    rm_Result2(a0),d1
  458.  
  459. \norexxmessage:
  460.     movem.l    (a7)+,d2-a6
  461.     rts
  462.  
  463.  
  464.     ENDC
  465.  
  466.  
  467. ;--------------------------------------------------------------------
  468.  
  469. ;------------------
  470.     BASE    rxx_oldbase
  471.  
  472. ;------------------
  473.     opt    rcl
  474.  
  475. ;------------------
  476.     ENDIF
  477.  
  478.     end
  479.  
  480.