home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 324.lha / FarPrint_v1.3 / FarCom.c < prev    next >
C/C++ Source or Header  |  1989-12-12  |  4KB  |  193 lines

  1. /* FarCom.c *****************************************************************
  2. *
  3. *    FarCom --------    Debugging functions for programs which don't
  4. *            have links to their environment.
  5. *
  6. *            FarPrint communication routines.
  7. *
  8. *    Author --------    Olaf Barthel of ED Electronic Design Hannover
  9. *            Brabeckstrasse 35
  10. *            D-3000 Hannover 71
  11. *
  12. *            Federal Republic of Germany.
  13. *
  14. *    This program truly is in the PUBLIC DOMAIN. Written on a sunny
  15. *    September day in 1989.
  16. *
  17. *    Compiled using Aztec C 3.6a, CygnusEd Professional & ARexx.
  18. *
  19. ****************************************************************************/
  20.  
  21. #include <exec/ports.h>
  22.  
  23.     /* Forward declarations. */
  24.  
  25. extern struct MsgPort    *FindPort();
  26. extern struct MsgPort    *CreatePort();
  27.  
  28.     /* Global task <-> task communication stuff. */
  29.  
  30. #define FM_ADDTXT    0
  31. #define FM_REQTXT    1
  32. #define FM_REQNUM    2
  33.  
  34. struct FarMessage
  35. {
  36.     struct Message    fm_ExecMessage;
  37.  
  38.     USHORT        fm_Command;
  39.     STRPTR        fm_Identifier;
  40.     STRPTR        fm_Text;
  41. };
  42.  
  43.     /* SendIt(MessageText,Identifier,Command):
  44.      *
  45.      *    Sends message/request to FarPort, completely
  46.      *    reentrant, shouldn't work from interrupt code
  47.      *    since we wait for the reply.
  48.      */
  49.  
  50. BOOL
  51. SendIt(MessageText,Identifier,Command)
  52. STRPTR MessageText,Identifier;
  53. USHORT Command;
  54. {
  55.     struct MsgPort *ReplyPort,*FarPort;
  56.     struct FarMessage FarMessage;
  57.  
  58.         /* Destination port present? */
  59.  
  60.     if(FarPort = (struct MsgPort *)FindPort("FarPort"))
  61.     {
  62.             /* Create a replyport. */
  63.  
  64.         if(ReplyPort = (struct MsgPort *)CreatePort(NULL,0L))
  65.         {
  66.                 /* Initialize custom message structure. */
  67.  
  68.             FarMessage . fm_ExecMessage . mn_Node . ln_Type    = NT_MESSAGE;
  69.             FarMessage . fm_ExecMessage . mn_Length        = sizeof(struct FarMessage);
  70.             FarMessage . fm_ExecMessage . mn_ReplyPort    = ReplyPort;
  71.             FarMessage . fm_Text                = MessageText;
  72.             FarMessage . fm_Identifier            = Identifier;
  73.             FarMessage . fm_Command                = Command;
  74.  
  75.                 /* Send it and wait for a reply. */
  76.  
  77.             PutMsg(FarPort,&FarMessage);
  78.             Wait(1 << ReplyPort -> mp_SigBit);
  79.  
  80.                 /* Remove the replyport. */
  81.  
  82.             DeletePort(ReplyPort);
  83.  
  84.             return(TRUE);
  85.         }
  86.     }
  87.  
  88.     return(FALSE);
  89. }
  90.  
  91.     /* AddText(MessageText):
  92.      *
  93.      *    Subroutine called by SendText, adds a Text to
  94.      *    the list of messages FarPrint maintains.
  95.      */
  96.  
  97. BOOL
  98. AddText(MessageText)
  99. STRPTR MessageText;
  100. {
  101.     return(SendIt(MessageText,NULL,FM_ADDTXT));
  102. }
  103.  
  104.     /* RequestNumber(Identifier):
  105.      *
  106.      *    Requests a number to be entered by the user.
  107.      *    Identifier points to a string which is to
  108.      *    identify the calling process.
  109.      */
  110.  
  111. long
  112. RequestNumber(Identifier)
  113. STRPTR Identifier;
  114. {
  115.     UBYTE NumBuff[81];
  116.  
  117.     setmem(NumBuff,81,0);
  118.  
  119.     SendIt(NumBuff,Identifier,FM_REQNUM);
  120.  
  121.     return(atoi(NumBuff));
  122. }
  123.  
  124.     /* RequestString(Identifier):
  125.      *
  126.      *    Requests a string to be entered by the user,
  127.      *    Identifier points to a string which is to
  128.      *    identify the calling process. Note: this one
  129.      *    isn't reentrant since it uses a temporary
  130.      *    string buffer. This could easily be fixed
  131.      *    by using a second argument to be used as
  132.      *    a destination string buffer.
  133.      */
  134.  
  135. STRPTR
  136. RequestString(Identifier)
  137. STRPTR Identifier;
  138. {
  139.     static UBYTE TxtBuff[81];
  140.  
  141.     if(SendIt(TxtBuff,Identifier,FM_REQTXT))
  142.         return(TxtBuff);
  143.     else
  144.         return(NULL);
  145. }
  146.  
  147.     /* This embedded assembly fragment handles the SendText()
  148.      * function. It basically consists of a call to the
  149.      * exec RawDoFmt() function to build the argument string
  150.      * it passes to AddText(). Original Author: Justin V. McCormick.
  151.      */
  152.  
  153. #asm
  154. _LVORawDoFmt    EQU    $FFFFFDF6
  155.  
  156.         XDEF    kput1
  157.  
  158. kput1:        MOVE.B    D0,(A3)+
  159.         RTS
  160.  
  161.         XDEF    _SendText
  162.  
  163. _SendText:    LINK    A5,#-512
  164.         MOVEM.L    D1/A0-A3,-(SP)
  165.  
  166.         MOVEA.L    8(A5),A0
  167.         LEA    12(A5),A1
  168.         LEA    kput1(PC),A2
  169.         LEA    -512(A5),A3
  170.         MOVE.L    4,A6
  171.         JSR    _LVORawDoFmt(A6)
  172.     
  173.         LEA    -512(A5),A0
  174.  
  175.         MOVE.L    A5,-(SP)
  176.         MOVE.L    A0,-(SP)
  177.  
  178.         JSR    _geta4#    ; Use this call only with small code
  179.                 ; memory model or it will pull half of the
  180.                 ; standard library code into your
  181.                 ; program (devilish when developing
  182.                 ; a shared library!)
  183.  
  184.         JSR    _AddText
  185.  
  186.         ADD.W    #4,SP
  187.         MOVE.L    (SP)+,A5
  188.  
  189.         MOVEM.L    (SP)+,D1/A0-A3
  190.         UNLK    A5
  191.         RTS
  192. #endasm
  193.