home *** CD-ROM | disk | FTP | other *** search
-
- /* SOURCE FILE *****************************************************
- * WTAPI.C - Writing Tools API C-Callable Interface Functions
- *******************************************************************
- * Copyright (C) 1993 WordPerfect Corp., All Rights Reserved.
- *******************************************************************/
-
-
- /***** DEFINE THE APPROPRIATE ITEM TO USE THE CODE FOR WRITING *****/
- /***** TOOL SERVERS OR WRITING TOOL CLIENTS (OR BOTH). *****/
- /* define WTAPI_SERVER */
- /* define WTAPI_CLIENT */
-
-
- #include <string.h>
-
- #include "wtapi.h"
- #include "wtcomm.h"
-
- /*----------------------------------------------------------
- External Variables
- ------------------------------------------------------------*/
- #ifdef WTAPI_SERVER
- extern WTCOMM comm_id; /* Platform specific communication ID */
- #endif /* WTAPI_SERVER */
- extern WTPTR wtsess; /* Writing Tool Session Structure */
-
- /*----------------------------------------------------------
- External Functions
- ------------------------------------------------------------*/
- MSG_ERRS SendRequestAct(WTPIPE,char *,char *,MSG_TYPE,char *,int,FUNCP);
-
- #ifdef WTAPI_SERVER
- WTSTATUS WTCInitRcv(WTCINITP);
- WTSTATUS WTCClActiveRcv(WTCCLACTIVEP);
- WTSTATUS WTCClInactiveRcv(WTCCLINACTIVEP);
- WTSTATUS WTCRqTlTermRcv(void);
- #endif /* WTAPI_SERVER */
-
- #ifdef WTAPI_CLIENT
- WTSTATUS WTQInfoBlockRcv(WTPTR, WTQINFOBLOCKP, WTRINFOBLOCKP, WTBUFP);
- WTSTATUS WTCTlTermRcv(WTPTR);
- WTSTATUS WTQInfoBlockRcv(WTPTR, WTQINFOBLOCKP, WTRINFOBLOCKP, WTBUFP);
- WTSTATUS WTQUnitInfoRcv(WTPTR, WTRUNITINFOP);
- WTSTATUS WTQReadToolDataRcv(WTPTR, WTQREADTOOLDATAP, WTRREADTOOLDATAP, WTBUFP);
- WTSTATUS WTQWriteToolDataRcv(WTPTR, WTQWRITETOOLDATAP, WTBUFP, WTRWRITETOOLDATAP);
- WTSTATUS WTQTextBlockRcv(WTPTR, WTQTEXTBLOCKP, WTRTEXTBLOCKP, WTBUFP);
- WTSTATUS WTQNextTextBlockRcv(WTPTR, WTQNEXTTEXTBLOCKP, WTRTEXTBLOCKP, WTBUFP);
- WTSTATUS WTQReadTextObjectRcv(WTPTR, WTQREADTEXTOBJECTP, WTRREADTEXTOBJECTP, WTBUFP);
- WTSTATUS WTQWriteTextObjectRcv(WTPTR, WTQWRITETEXTOBJECTP, WTBUFP, WTRWRITETEXTOBJECTP);
- WTSTATUS WTQGotoRcv(WTPTR, WTQGOTOP, WTRGOTOP);
- WTSTATUS WTQHiliteRcv(WTPTR, WTQHILITEP, WTRHILITEP);
- WTSTATUS WTQDehiliteRcv(WTPTR, WTQDEHILITEP, WTRDEHILITEP);
- WTSTATUS WTQReplaceRcv(WTPTR, WTQREPLACEP, WTBUFP, WTRREPLACEP);
- WTSTATUS WTQUndoReplaceRcv(WTPTR, WTRREPLACEP);
- WTSTATUS WTCRqClActiveRcv(WTPTR);
- WTSTATUS WTCRqInitRcv(WTPTR, WTCRQINITP, WTBUFP);
- WTSTATUS WTCTlInactiveRcv(WTPTR);
- WTSTATUS WTQTlActiveRcv(WTPTR, WTRTLACTIVEP);
- #endif /* WTAPI_CLIENT */
-
- /*----------------------------------------------------------
- Internal Variables
- ------------------------------------------------------------*/
- static WTBUFP rtmsgptr;
- static WTBUFP rtbufptr;
-
- /*----------------------------------------------------------
- Internal Functions
- ------------------------------------------------------------*/
- static MSG_ERRS wtReplyReceive(char *, char *);
-
- /* FUNCTION ********************************************************
- * wtqClSend - Client sends a WTAPI query message
- * In: comm = comm info for this conversation
- * inmsgid = message to be sent
- * inmsg = buffer holding message
- * inmsgsize = size of message
- * inbuf = buffer holding message data
- * inbufsize = size of message data
- * rtmsgid = message to be returned
- * rtmsg = buffer to hold return message
- * rtmsgsize = size of message return buffer
- * rtbuf = buffer to hold return message data
- * rtbufsize = size of message data return buffer
- * Out: none
- * Return: WTSTATUS
- * Notes:
- *******************************************************************/
- WTSTATUS wtqClSend (WTCOMM comm, WTMSGID inmsgid, WTBUFP inmsg,
- WTSIZE inmsgsize, WTBUFP inbuf, WTSIZE inbufsize,
- WTMSGID rtmsgid, WTBUFP rtmsg, WTSIZE rtmsgsize,
- WTBUFP rtbuf, WTSIZE rtbufsize)
- {
- #ifdef WTAPI_CLIENT
- MSG_ERRS status;
- char *data;
- int datasize;
-
- rtmsgptr = rtmsg;
- rtbufptr = rtbuf;
-
- datasize = sizeof(WTMSGHEADER) + inmsgsize + inbufsize;
- if ((data = (char *)malloc(datasize)) == 0) {
- return WTS_NOMEMORY;
- }
-
- ((WTMSGHEADERP)data)->inmsgid = inmsgid;
- ((WTMSGHEADERP)data)->inmsgsize = inmsgsize;
- ((WTMSGHEADERP)data)->inbufsize = inbufsize;
- ((WTMSGHEADERP)data)->rtmsgid = rtmsgid;
- ((WTMSGHEADERP)data)->rtmsgsize = rtmsgsize;
- ((WTMSGHEADERP)data)->rtbufsize = rtbufsize;
-
- memcpy(data+sizeof(WTMSGHEADER), (char *)inmsg, inmsgsize);
- if (inbuf) {
- memcpy(data+sizeof(WTMSGHEADER)+inmsgsize, (char *)inbuf, inbufsize);
- }
- if (rtmsgid == WTC_NOMESSAGE) {
- status = SendMsg(comm->cl_pipe, comm->client, comm->tool,
- WTAPI_CLIENT_COMMAND, data, datasize);
- } else {
- status = SendRequestAct(comm->cl_pipe, comm->client, comm->tool,
- WTAPI_CLIENT_QUERY, data, datasize, (FUNCP)wtReplyReceive);
- }
- free(data);
- if (status != MSG_OK) {
- return WTS_COMERROR;
- } else {
- return WTS_OK;
- }
- #endif /* WTAPI_CLIENT */
- return WTS_OK;
- } /* wtqClSend */
-
- /* FUNCTION ********************************************************
- * wtqTlSend - Send WTAPI msg to writing tool user and wait for a
- * return message.
- * Globals: hOutgoingMsg is set so that WtMsgSend can send it.
- * TlMsgWaiting is used as a semaphore to know when we
- * received the reply to the message we sent.
- * hTlDataReceived is a handle to a copy of the reply data
- * Return: WTS_OK if successful.
- * WTS_COMERROR if error occurred.
- * WTS_NOMEMORY if no memory for send buffer.
- * WTS_QUITAPI if message received to terminate API.
- * Descrip:
- *******************************************************************/
- WTSTATUS wtqTlSend (WTCOMM comm, WTMSGID inmsgid, WTBUFP inmsg,
- WTSIZE inmsgsize, WTBUFP inbuf, WTSIZE inbufsize,
- WTMSGID rtmsgid, WTBUFP rtmsg, WTSIZE rtmsgsize,
- WTBUFP rtbuf, WTSIZE rtbufsize)
- {
- #ifdef WTAPI_SERVER
- MSG_ERRS status;
- char *data;
- int datasize;
-
- if (!comm) {
- return WTS_COMERROR;
- }
- rtmsgptr = rtmsg;
- rtbufptr = rtbuf;
-
- datasize = sizeof(WTMSGHEADER) + inmsgsize + inbufsize;
- if ((data = (char *)malloc(datasize)) == 0) {
- return WTS_NOMEMORY;
- }
-
- ((WTMSGHEADERP)data)->inmsgid = inmsgid;
- ((WTMSGHEADERP)data)->inmsgsize = inmsgsize;
- ((WTMSGHEADERP)data)->inbufsize = inbufsize;
- ((WTMSGHEADERP)data)->rtmsgid = rtmsgid;
- ((WTMSGHEADERP)data)->rtmsgsize = rtmsgsize;
- ((WTMSGHEADERP)data)->rtbufsize = rtbufsize;
-
- memcpy(data + sizeof(WTMSGHEADER), (char *)inmsg, inmsgsize);
- if (inbuf) {
- memcpy(data+sizeof(WTMSGHEADER)+inmsgsize, (char *)inbuf, inbufsize);
- }
-
- status = SendRequestAct(comm->tl_pipe, comm->tool, comm->client,
- WTAPI_TOOL_QUERY, data, datasize, (FUNCP)wtReplyReceive);
- free(data);
- if (status) {
- return WTS_COMERROR;
- } else {
- return WTS_OK;
- }
- #endif /* WTAPI_SERVER */
- return WTS_OK;
- } /* wtqTlSend */
-
- /*COMMENT********************************************************
- ;wtReplyReceive
- Title: Receive a writing tools API reply message
- In: sender - sender name
- retdata - return message data
- Out: none
- Xin: rtmsgptr, rtbufptr
- XOut: none
- Return: MSG_OK
- Notes:
- *****************************************************************/
- static MSG_ERRS wtReplyReceive(char *sender, char *retdata)
- {
- WTSIZE rtmsgsize, rtbufsize;
- WTMSGHEADER header;
-
- if (retdata) {
- memcpy((char *)&header, retdata, sizeof(WTMSGHEADER));
- rtmsgsize = header.inmsgsize;
- rtbufsize = header.inbufsize;
- if (rtmsgptr) {
- memcpy(rtmsgptr, retdata+sizeof(WTMSGHEADER), rtmsgsize);
- }
- if (rtbufptr) {
- memcpy(rtbufptr, retdata+sizeof(WTMSGHEADER)+rtmsgsize, rtbufsize);
- }
- }
- return MSG_OK;
- } /* wtReplyReceive */
-
- /* FUNCTION ********************************************************
- * wtClReceive - Receive client WTAPI messages
- * In: comm = comm info for this api session
- * msgid = WTMSGID of incoming message
- * inmsg = buffer containing message
- * inbuf = buffer for incoming data
- * Out: rtmsg = buffer to hold return message
- * rtbuf = buffer to hold return data
- * rtbufsizep = holds actualsize of data in rtbuf
- * Return: WTSTATUS from message handling routines
- * Notes:
- *******************************************************************/
- WTSTATUS wtClReceive(WTCOMM comm, WTMSGID msgid, WTBUFP inmsg, WTBUFP inbuf,
- WTBUFP rtmsg, WTBUFP rtbuf, WTSIZEP rtbufsizep)
- {
- WTSTATUS status = WTS_OK;
- #ifdef WTAPI_CLIENT
-
- *rtbufsizep = 0;
- switch (msgid) {
- case WTC_RQINIT:
- status = WTCRqInitRcv(wtsess, (WTCRQINITP)inmsg, inbuf);
- break;
-
- case WTQ_INFOBLOCK:
- status = WTQInfoBlockRcv(wtsess, (WTQINFOBLOCKP)inmsg,
- (WTRINFOBLOCKP)rtmsg, rtbuf);
- *rtbufsizep = ((WTRINFOBLOCKP)rtmsg)->winsize;
- break;
-
- case WTQ_UNITINFO:
- status = WTQUnitInfoRcv(wtsess, (WTRUNITINFOP)rtmsg);
- break;
-
- case WTQ_READTOOLDATA:
- status = WTQReadToolDataRcv(wtsess, (WTQREADTOOLDATAP)inmsg,
- (WTRREADTOOLDATAP)rtmsg, rtbuf);
- *rtbufsizep = ((WTRREADTOOLDATAP)rtmsg)->size;
- break;
-
- case WTQ_WRITETOOLDATA:
- status = WTQWriteToolDataRcv(wtsess, (WTQWRITETOOLDATAP)inmsg,
- inbuf, (WTRWRITETOOLDATAP)rtmsg);
- break;
-
- case WTQ_TEXTBLOCK:
- status = WTQTextBlockRcv(wtsess, (WTQTEXTBLOCKP)inmsg,
- (WTRTEXTBLOCKP)rtmsg, rtbuf);
- *rtbufsizep = ((WTRTEXTBLOCKP)rtmsg)->size;
- break;
-
- case WTQ_NEXTTEXTBLOCK:
- status = WTQNextTextBlockRcv(wtsess, (WTQNEXTTEXTBLOCKP)inmsg,
- (WTRTEXTBLOCKP)rtmsg, rtbuf);
- *rtbufsizep = ((WTRTEXTBLOCKP)rtmsg)->size;
- break;
-
- case WTQ_READTEXTOBJECT:
- status = WTQReadTextObjectRcv(wtsess, (WTQREADTEXTOBJECTP)inmsg,
- (WTRREADTEXTOBJECTP)rtmsg, rtbuf);
- *rtbufsizep = ((WTRREADTEXTOBJECTP)rtmsg)->size;
- break;
-
- case WTQ_WRITETEXTOBJECT:
- status = WTQWriteTextObjectRcv(wtsess, (WTQWRITETEXTOBJECTP)inmsg,
- inbuf, (WTRWRITETEXTOBJECTP)rtmsg);
- break;
-
- case WTQ_GOTO:
- status = WTQGotoRcv(wtsess, (WTQGOTOP)inmsg, (WTRGOTOP)rtmsg);
- break;
-
- case WTQ_HILITE:
- status = WTQHiliteRcv(wtsess, (WTQHILITEP)inmsg, (WTRHILITEP)rtmsg);
- break;
-
- case WTQ_DEHILITE:
- status = WTQDehiliteRcv(wtsess, (WTQDEHILITEP)inmsg, (WTRDEHILITEP)rtmsg);
- break;
-
- case WTQ_REPLACE:
- status = WTQReplaceRcv(wtsess, (WTQREPLACEP)inmsg, inbuf,
- (WTRREPLACEP)rtmsg);
- break;
-
- case WTQ_UNDOREPLACE:
- status = WTQUndoReplaceRcv(wtsess, (WTRREPLACEP)rtmsg);
- break;
-
- case WTC_RQCLACTIVE:
- status = WTCRqClActiveRcv(wtsess);
- break;
-
- case WTC_TLINACTIVE:
- status = WTCTlInactiveRcv(wtsess);
- break;
-
- case WTQ_TLACTIVE:
- status = WTQTlActiveRcv(wtsess, (WTRTLACTIVEP)rtmsg);
- break;
-
- case WTC_TLTERM:
- status = WTCTlTermRcv(wtsess);
- break;
-
- default:
- status = WTS_BADREQUEST; /* we got something we didn't expect */
- break;
- }
- #endif /* WTAPI_CLIENT */
- return status;
- } /* wtClReceive */
-
- /* FUNCTION ********************************************************
- * wtTlReceive - Receive Writing Tools API messages
- * In: comm = conversation handle
- * msgid = id of writing tools message
- * inmsg = buffer containing incoming message
- * inbuf = buffer containing incoming message data
- * rtmsg = buffer to contain outgoing message
- * rtbuf = buffer to contain outgoing message data
- * Out: rtbufsizep = will hold the actual size of the data in rtbuf
- * Return: WTSTATUS
- * Notes:
- *******************************************************************/
- WTSTATUS wtTlReceive(WTCOMM comm, WTMSGID msgid, WTBUFP inmsg, WTBUFP inbuf,
- WTBUFP rtmsg, WTBUFP rtbuf, WTSIZEP rtbufsizep)
- {
- WTSTATUS status = WTS_OK;
- #ifdef WTAPI_SERVER
-
- *rtbufsizep = 0;
- switch (msgid) {
- case WTC_INIT:
- comm_id = comm;
- status = WTCInitRcv((WTCINITP)inmsg);
- break;
-
- case WTC_CLACTIVE:
- status = WTCClActiveRcv((WTCCLACTIVEP)inmsg);
- break;
-
- case WTC_CLINACTIVE:
- status = WTCClInactiveRcv((WTCCLINACTIVEP)inmsg);
- break;
-
- case WTC_RQTLTERM:
- status = WTCRqTlTermRcv();
- break;
-
- default:
- break;
- }
- #endif /* WTAPI_SERVER */
- return status;
- } /* wtTlReceive */
-