home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Frozen Fish 1: Amiga
/
FrozenFish-Apr94.iso
/
bbs
/
alib
/
d3xx
/
d325
/
farprint.lha
/
FarPrint
/
FarCom1.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-02-27
|
4KB
|
183 lines
/* FarCom.c *****************************************************************
*
* FarCom -------- Debugging functions for programs which don't
* have links to their environment.
*
* FarPrint communication routines.
*
* Author -------- Olaf Barthel of MXM
* Brabeckstrasse 35
* D-3000 Hannover 71
*
* Federal Republic of Germany.
*
* This program truly is in the PUBLIC DOMAIN. Written on a sunny
* September day in 1989, updated 27 January 1990.
*
* Compiled using Aztec C 3.6a, CygnusEd Professional 2 & ARexx.
*
****************************************************************************/
#include <exec/memory.h>
#include <exec/ports.h>
/* Forward declarations. */
extern struct MsgPort *FindPort();
extern struct MsgPort *CreatePort();
extern void *AllocMem();
/* Global task <-> task communication stuff. */
#define FM_ADDTXT 0
#define FM_REQTXT 1
#define FM_REQNUM 2
struct FarMessage
{
struct Message fm_ExecMessage;
USHORT fm_Command;
STRPTR fm_Identifier;
STRPTR fm_Text;
};
/* SendIt(MessageText,Identifier,Command):
*
* Sends message/request to FarPort, completely
* reentrant, shouldn't work from interrupt code
* since we wait for the reply.
*/
BOOL
SendIt(MessageText,Identifier,Command)
STRPTR MessageText,Identifier;
USHORT Command;
{
struct MsgPort *ReplyPort,*FarPort;
struct FarMessage FarMessage;
/* Destination port present? */
if(FarPort = (struct MsgPort *)FindPort("FarPort"))
{
/* Initialize custom message structure. */
FarMessage . fm_ExecMessage . mn_Length = sizeof(struct FarMessage);
FarMessage . fm_Identifier = Identifier;
FarMessage . fm_Text = MessageText;
FarMessage . fm_Command = Command;
/* This is a text to be added. */
if(Command == FM_ADDTXT)
{
struct FarMessage *TempMessage = (struct FarMessage *)AllocMem(sizeof(struct FarMessage),MEMF_PUBLIC);
STRPTR TempString = (STRPTR)AllocMem(strlen(MessageText) + 1,MEMF_PUBLIC);
/* In this case both text and message
* structure will be cloned (we won't have
* to wait for a reply).
*/
if(TempString)
{
strcpy(TempString,MessageText);
if(TempMessage)
{
FarMessage . fm_ExecMessage . mn_ReplyPort = NULL;
FarMessage . fm_Text = TempString;
CopyMem(&FarMessage,TempMessage,sizeof(struct FarMessage));
PutMsg(FarPort,TempMessage);
return(TRUE);
}
FreeMem(TempString,strlen(MessageText) + 1);
}
if(TempMessage)
FreeMem(TempMessage,sizeof(struct FarMessage));
return(FALSE);
}
/* Create a replyport. */
if(ReplyPort = (struct MsgPort *)CreatePort(NULL,0))
{
FarMessage . fm_ExecMessage . mn_ReplyPort = ReplyPort;
/* Send it and wait for a reply. */
PutMsg(FarPort,&FarMessage);
Wait(1 << ReplyPort -> mp_SigBit);
/* Remove the replyport. */
DeletePort(ReplyPort);
return(TRUE);
}
}
return(FALSE);
}
/* AddText(MessageText):
*
* Subroutine called by SendText, adds a Text to
* the list of messages FarPrint maintains.
*/
BOOL
AddText(MessageText)
STRPTR MessageText;
{
return(SendIt(MessageText,NULL,FM_ADDTXT));
}
/* RequestNumber(Identifier):
*
* Requests a number to be entered by the user.
* Identifier points to a string which is to
* identify the calling process.
*/
long
RequestNumber(Identifier)
STRPTR Identifier;
{
UBYTE NumBuff[81];
setmem(NumBuff,81,0);
SendIt(NumBuff,Identifier,FM_REQNUM);
return(atoi(NumBuff));
}
/* RequestString(Identifier):
*
* Requests a string to be entered by the user,
* Identifier points to a string which is to
* identify the calling process. Note: this one
* isn't reentrant since it uses a temporary
* string buffer. This could easily be fixed
* by using a second argument to be used as
* a destination string buffer.
*/
STRPTR
RequestString(Identifier,TxtBuff)
STRPTR Identifier,TxtBuff;
{
if(SendIt(TxtBuff,Identifier,FM_REQTXT))
return(TxtBuff);
else
return(NULL);
}