home *** CD-ROM | disk | FTP | other *** search
- /* prf_rexx.c */
- /* V1.1 10-9-92 */
-
- #include "prf.h"
- #include <rexx/rexxio.h>
- #include <rexx/rxslib.h>
- #include <rexx/errors.h>
- #include <rexx/storage.h>
-
- #pragma libcall RexxSysBase CreateArgString 7e 0802
- #pragma libcall RexxSysBase DeleteArgString 84 801
- #pragma libcall RexxSysBase LengthArgString 8a 801
- #pragma libcall RexxSysBase CreateRexxMsg 90 09803
- #pragma libcall RexxSysBase DeleteRexxMsg 96 801
-
- UBYTE *CreateArgString(UBYTE *string,unsigned long length);
- void DeleteArgString(UBYTE *argstring);
- ULONG LenghtArgString(UBYTE *argstring);
- struct RexxMsg *CreateRexxMsg(struct MsgPort *port, UBYTE *extension,UBYTE *host);
- void DeleteRexxMsg(struct RexxMsg *packet);
-
- struct rexx_Cmd
- {
- UBYTE *rx_cmd;
- ULONG rx_code;
- };
-
- struct rexx_Cmd rexxCmd[] =
- {
- T_RX_RESET,CMD_RESETALL,
- T_RX_CLEAR,CMD_CLEARLIST,
- T_RX_OPENWINDOW,CMD_OPENWD,
- T_RX_CLOSEWINDOW,CMD_CLOSEWD,
- T_RX_INSFILE,CMD_STR_INSERT,
- T_RX_REMFILE,CMD_REMOVE,
- T_RX_PAGE,CMD_PAGE_ON,
- T_RX_TIME,CMD_TIME_ON,
- T_RX_FILE,CMD_NAME_ON,
- T_RX_FF,CMD_FF_ON,
- T_RX_CRLF,CMD_CRLF_ON,
- T_RX_FOOT,CMD_FOOT,
- T_RX_HEAD,CMD_HEAD,
- T_RX_QUIT,CMD_RXQUIT,
- T_RX_DATE,CMD_DATE_ON,
- T_RX_LINE,CMD_LINE_ON,
- T_RX_LINES,CMD_LINES,
- T_RX_RMARGIN,CMD_RMARGIN,
- T_RX_LMARGIN,CMD_LMARGIN,
- T_RX_DRAFT,CMD_DRAFT,
- T_RX_LQ,CMD_LQ,
- T_RX_PITCH6,CMD_PITCH6,
- T_RX_PITCH8,CMD_PITCH8,
- T_RX_10CPI,CMD_10CPI,
- T_RX_12CPI,CMD_12CPI,
- T_RX_15CPI,CMD_15CPI,
- T_RX_PRINT,CMD_PRINT,
- T_RX_SAVEPREFS,CMD_SAVEPREFS,
- T_RX_STATUS,CMD_STATUS,
- T_RX_VERSION,CMD_VERSION,
- NULL,0
- };
-
- char *RexxPortName = RXPORTNAME;
-
- void AttemptOpenRexx(struct prf_info *info)
- {
- if(RexxSysBase = (struct RxsLib *)OpenLibrary(RXSNAME,0L))
- {
- Forbid();
- if(FindPort(RexxPortName))
- {
- Permit();
- }
- else
- {
- if(info->rexxPort = CreatePort(RexxPortName,0L))Permit();
- }
- }
- }
-
- void CloseRexx(struct prf_info *info)
- {
- if(info->rexxPort)
- {
- DeletePort(info->rexxPort);
- }
- if(RexxSysBase) CloseLibrary((struct Library *)RexxSysBase);
- }
-
- long HandleRexxMsg(struct prf_info *info)
- {
- UBYTE filename[STR_SIZE];
- long rc = CMD_NEUTRAL;
- long numarg;
- long i,found,c;
- UBYTE cmd_string[STR_SIZE],arg1[STR_SIZE],arg2[STR_SIZE],arg3[STR_SIZE];
- numarg = (long)sscanf(info->rmsg->rm_Args[0],"%s %s %s %s",cmd_string,arg1,arg2,arg3);
- c = RX_CMD_NEUTRAL;
- if(!strnicmp(arg1,T_RX_ON,strlen(arg1)))c = RX_CMD_ON;
- found = FALSE;i = 0L;
- while(!found)
- {
- if(rexxCmd[i].rx_cmd == NULL){found = TRUE; i = -1L;}
- else
- {
- if(!strnicmp(rexxCmd[i].rx_cmd,cmd_string,strlen(cmd_string)))
- {
- found = TRUE;
- i=rexxCmd[i].rx_code;
- }
- else i++;
- }
- }
- if(i != -1L)
- {
- switch(i)
- {
- case CMD_STATUS : if(info->rmsg->rm_Action & (1L << RXFB_RESULT))
- {
- if(info->flags & FLAG_PRINT)
- info->rmsg->rm_Result2 = (long)CreateArgString(T_RX_PMSG,strlen(T_RX_PMSG));
- else
- info->rmsg->rm_Result2 = (long)CreateArgString(T_RX_WMSG,strlen(T_RX_WMSG));
- }
- break;
- case CMD_VERSION : if(info->rmsg->rm_Action & (1L << RXFB_RESULT))
- {
- info->rmsg->rm_Result2 = (long)CreateArgString(RX_VERSION_STR,strlen(RX_VERSION_STR));
- }
- break;
-
- case CMD_SAVEPREFS : strcpy(filename,arg1);
- if(*filename) SavePreferences(info,filename);
- else rc = CMD_SAVEPREFS;
- break;
- case CMD_FOOT : strcpy(info->Footline,info->rmsg->rm_Args[0]+1+strlen(T_RX_FOOT));
- if(info->Swd)GT_SetGadgetAttrs(info->SGadgets[GD_Footline],info->Swd,NULL,GTST_String,info->Footline,TAG_DONE);
- break;
- case CMD_HEAD : strcpy(info->Headline,info->rmsg->rm_Args[0]+1+strlen(T_RX_HEAD));
- if(info->Swd)GT_SetGadgetAttrs(info->SGadgets[GD_Headline],info->Swd,NULL,GTST_String,info->Headline,TAG_DONE);
- break;
- case CMD_OPENWD : if(!stricmp(arg1,T_RX_CONTROL))
- {
- if(*arg2)SwdTags[0].ti_Data = atol(arg2);
- if(*arg3)SwdTags[1].ti_Data = atol(arg3);
- if(SwdTags[0].ti_Data > (info->PubScr->Width - SwdTags[2].ti_Data))
- SwdTags[0].ti_Data = info->PubScr->Width - SwdTags[2].ti_Data;
- if(SwdTags[1].ti_Data > (info->PubScr->Height - SwdTags[3].ti_Data))
- SwdTags[1].ti_Data = info->PubScr->Height - SwdTags[3].ti_Data;
- rc = CMD_OPENWD;
- }
- else
- if(!stricmp(arg1,T_RX_PREFS))
- {
- if(*arg2)PwdTags[0].ti_Data = atol(arg2);
- if(*arg3)PwdTags[1].ti_Data = atol(arg3);
- if(PwdTags[0].ti_Data > (info->PubScr->Width - PwdTags[2].ti_Data))
- PwdTags[0].ti_Data = info->PubScr->Width - PwdTags[2].ti_Data;
- if(PwdTags[1].ti_Data > (info->PubScr->Height - PwdTags[3].ti_Data))
- PwdTags[1].ti_Data = info->PubScr->Height - PwdTags[3].ti_Data;
- rc = CMD_OPENPWD;
- }
- break;
- case CMD_CLOSEWD : if(!stricmp(arg1,T_RX_CONTROL)) rc = CMD_CLOSEWD;
- else if(!stricmp(arg1,T_RX_PREFS)) rc = CMD_CLOSEPWD;
- break;
- case CMD_STR_INSERT : if(*arg1)
- {
- long cmd = CMD_INSERTTAIL;
- info->Special1 = (APTR)arg1;
- info->Special2 = (APTR)&cmd;
- InsertName(info);
- info->Special1 = NULL;
- info->Special2 = NULL;
- }
- break;
- case CMD_REMOVE : info->Special1 = (APTR)arg1;
- RemoveName(info);
- info->Special1 = NULL;
- break;
- case CMD_RMARGIN : if(*arg1)info->Rmargin = atol(arg1);
- if(info->Pwd)GT_SetGadgetAttrs(info->PGadgets[GD_Rmargin - PGD],info->Pwd,NULL,GTIN_Number,info->Rmargin,TAG_DONE);
- break;
- case CMD_LMARGIN : if(*arg1)info->Lmargin = atol(arg1);
- if(info->Pwd)GT_SetGadgetAttrs(info->PGadgets[GD_Lmargin - PGD],info->Pwd,NULL,GTIN_Number,info->Lmargin,TAG_DONE);
- break;
- case CMD_LINES : if(*arg1)info->Lines = atol(arg1);
- if(info->Pwd)GT_SetGadgetAttrs(info->PGadgets[GD_Linesperpage - PGD],info->Pwd,NULL,GTIN_Number,info->Lines,TAG_DONE);
- break;
- case CMD_PAGE_ON : (c) ? (rc = CMD_PAGE_ON) : (rc = CMD_PAGE_OFF); break;
- case CMD_LINE_ON : (c) ? (rc = CMD_LINE_ON) : (rc = CMD_LINE_OFF); break;
- case CMD_NAME_ON : (c) ? (rc = CMD_NAME_ON) : (rc = CMD_NAME_OFF); break;
- case CMD_TIME_ON : (c) ? (rc = CMD_TIME_ON) : (rc = CMD_TIME_OFF); break;
- case CMD_FF_ON : (c) ? (rc = CMD_FF_ON) : (rc = CMD_FF_OFF); break;
- case CMD_CRLF_ON : (c) ? (rc = CMD_CRLF_ON) : (rc = CMD_CRLF_OFF); break;
- case CMD_DATE_ON : (c) ? (rc = CMD_DATE_ON) : (rc = CMD_DATE_OFF); break;
- default : rc = i;
- break;
- }
- }
- else
- {
- rc = CMD_NEUTRAL;
- if(info->rmsg->rm_Action & (1L << RXFB_RESULT))
- {
- info->rmsg->rm_Result2 = (long)CreateArgString(T_RX_ERROR,strlen(T_RX_ERROR));
- info->rmsg->rm_Result1 = RX_ERRORLEVEL;
- }
- }
- return rc;
- }
-