home *** CD-ROM | disk | FTP | other *** search
- /*
- ** $Source: WB_2.1:homes/rkr/prog/sercli/src/RCS/rexx.c,v $
- ** $Author: rkr $
- ** $Revision: 1.9 $
- ** $Locker: rkr $
- ** $State: Exp $
- ** $Date: 1993/06/16 23:29:30 $
- **
- ** sercli (an Amiga .device <-> FIFO interface tool)
- ** Copyright (C) 1993 Richard Rauch
- **
- ** See /doc/sercli.doc and /COPYING for use and distribution license.
- **
- */
-
- #include <rexx/errors.h>
-
- #include <clib/alib_protos.h>
- #include <clib/exec_protos.h>
- #include <clib/intuition_protos.h>
- #include <clib/rexxsyslib_protos.h>
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
-
- #include "config.h"
- #include "defs.h"
- #include "rexx.h"
- #include "keywords.h"
- #include "sercli-config.h"
- #include "ser_supp.h"
-
- void *RexxSysBase; /*** screwey `struct RxsLib' name, if you care ***/
-
- MsgPort *rexx_port;
-
- ULONG rexx_mask;
-
- static RexxMsg *rm;
-
- /*
- ** Reply to an ARexx message.
- **
- ** Args:
- ** {rm} - The ARexx msg to reply to
- ** {rc} - Result1 to send back
- ** {res} - Result2 to send back
- **
- ** NOTE that according to ARexx documentation, you should only set {res}
- ** when {rc} is 0. rexx_reply() makes NO such checks!
- **
- ** {rm} isn't really needed in this context, since we only have the global
- ** {rm}, but it's a bit more flexible this way (should probably stick
- ** {rm}s in more of the function parameter lists...).
- **
- */
- void rexx_reply (RexxMsg *rm, LONG rc, char *res)
- {
- rm->rm_Result1 = rc;
- if ( (rm->rm_Action & RXFF_RESULT) && (res) )
- rm->rm_Result2 = CreateArgstring (res, strlen (res) );
- ReplyMsg ( (Message *)rm);
- }
-
-
- /*
- ** Creates an ARexx port.
- **
- ** Does NOT open the arexx libraries; that will be handled by autoinit
- ** code (if Dillon hasn't yet put auto support for ARexx in, I'll add
- ** that...
- **
- ** Basically, creates a port with {prog_id} (a global; that global
- ** defaults to "sercli" but can be set before this function is called...
- ** In the current context (i.e., the sercli program) it may be set by
- ** read_sercli_config() when reading in a config file with an appropriate
- ** config line...).
- **
- */
- void open_rexx (void)
- {
- if (RexxSysBase)
- {
- Forbid ();
- {
- if (FindPort (prog_id) )
- exit (10);
- rexx_port = CreatePort (prog_id, 1);
- }
- Permit ();
- rexx_mask = 1 << (rexx_port->mp_SigBit);
- }
- }
-
-
- /*
- ** Closes down the ARexx port.
- **
- ** Like open_rexx(), close_rexx() does not deal with the libraries (and
- ** for analogous reasons).
- **
- */
- void close_rexx (void)
- {
- if (rexx_port)
- {
- RemPort (rexx_port);
-
- while (rm = (RexxMsg *) GetMsg (rexx_port) )
- rexx_reply (rm, RC_ERROR, NULL);
-
- DeletePort (rexx_port);
- rexx_port = NULL;
- rexx_mask = 0;
- }
- }
-
-
- /*
- ** Handles all ARexx messages that accumulate at {rexx_port}.
- **
- ** The {rexx_port} is a global, as is {rm} (the {RexxMsg *}).
- **
- */
- void handle_rexx (void)
- {
- int ser_soft_param = 0;
- int ser_hard_param = 0;
-
- while (rm = (RexxMsg *)GetMsg (rexx_port) )
- {
- char *line;
- char *result = 0;
- char *tmp;
- LONG rc = RC_OK;
-
- line = tmp = rm->rm_Args [0];
- while ( (*tmp) && (*tmp++ != ':') )
- ;
-
- while ( (*tmp) && (*tmp == ' ') )
- ++tmp;
-
- switch (match (line, keywords) )
- {
- case OPTION_NOT_FOUND:
- rc = RC_ERROR;
- break;
-
-
- case OPTION_COMMENT:
- break;
-
- /*
- ** General:
- ** Add support to return the "old" values for these serial
- ** param controls?
- **
- ** Or else call ser_soft_set() from each & return the result
- ** of that?
- **
- */
- case SER_BPS:
- if (*tmp)
- {
- ser_bps = strtol (tmp, NULL, 0);
- ser_soft_param = 1;
- }
- else if (alert_loc)
- printf ("Invalid {bps} in rexx msg: {%s}\n", line);
- break;
-
-
- case SER_BITS:
- if (*tmp)
- {
- ser_read_bits = ser_write_bits = strtol (tmp, NULL, 0);
- ser_soft_param = 1;
- }
- else if (alert_loc)
- printf ("Invalid {bits} in rexx msg {%s}.\n", line);
- break;
-
-
- case SER_STOP_BITS:
- if (*tmp)
- {
- ser_stop_bits = strtol (tmp, NULL, 0);
- ser_soft_param = 1;
- }
- else if (alert_loc)
- printf ("Invalid {stop bits} in rexx msg {%s}.\n", line);
- break;
-
-
- case SER_7WIRE:
- ser_7wire = 1;
- ser_hard_param = 1;
- break;
-
-
- case SER_3WIRE:
- ser_7wire = 0;
- ser_hard_param = 1;
- break;
-
-
- case SER_XON_XOFF:
- ser_xon_xoff = 1;
- ser_soft_param = 1; /*** hard?? ***/
- break;
-
-
- case SER_NO_XON_XOFF:
- ser_xon_xoff = 0;
- ser_soft_param = 1; /*** hard?? ***/
- break;
-
-
- case SER_SHARED:
- ser_exclusive = 0;
- ser_hard_param = 1;
- break;
-
-
- case SER_EXCLUSIVE:
- ser_exclusive = 1;
- ser_hard_param = 1;
- break;
-
-
- case SER_NO_RAD_BOOGIE:
- ser_rad_boogie = 0;
- ser_hard_param = 1;
- break;
-
-
- case SER_RAD_BOOGIE:
- ser_rad_boogie = 1;
- ser_hard_param = 1;
- break;
-
-
- case SER_NO_PARITY:
- ser_parity = 0;
- ser_soft_param = 1;
- break;
-
-
- case SER_ODD_PARITY:
- ser_parity = 1;
- ser_soft_param = 1;
- break;
-
-
- case SER_EVEN_PARITY:
- ser_parity = 2;
- ser_soft_param = 1;
- break;
-
-
- case SET_WINDOW_TITLE:
- {
- char buf [256];
-
- int len;
-
- if (nether_name)
- free (nether_name);
-
- /*
- ** return old title; gets freed on way out...
- **
- */
- result = window_title; /*** Just use nw.Title??? ***/
- nether_name = strdup (tmp);
- len = sprintf
- (
- buf,
- "sercli: with {%s} id {%s}",
- nether_name,
- prog_id
- );
- window_title = strdup (buf); /*** Just use nw.Title??? ***/
- SetWindowTitles (win, window_title, (UBYTE *)~0);
-
- rc = RC_OK;
- break;
- }
-
-
- case SET_WINDOW_SIZE:
- {
- int new_width;
- int new_height;
-
- rc = RC_ERROR;
-
- sscanf (tmp, "%d %d", &new_width, &new_height);
- if ( (new_width > 0) && (new_height > 0) )
- {
- char buf [256];
-
- SizeWindow (win, new_width - win_width, new_height - win_height);
-
- sprintf (buf, "%d %d", win_width, win_height);
- result = strdup (buf);
-
- win_width = new_width;
- win_height = new_height;
-
- rc = RC_OK;
- }
- break;
- }
-
-
- case ALERT_LOC:
- alert_loc = 1;
- break;
-
-
- case ALERT_SER:
- alert_ser = 1;
- break;
-
-
- case NO_ALERT_LOC:
- alert_loc = 0;
- break;
-
-
- case NO_ALERT_SER:
- alert_ser = 0;
- break;
-
-
- case SER_QUERY:
- /*
- ** Not really and "error," but this'll do the job for now.
- **
- */
- handle_error (error_type_serial, query_ser () );
- break;
-
-
- default:
- if (alert_loc)
- printf ("rexx command {%s} not implemented.\n", line);
- rc = RC_ERROR;
- break;
- }
-
- rexx_reply (rm, rc, result);
- if (result)
- free (result);
- }
-
- if (ser_hard_param)
- {
- close_ser ();
- open_ser ();
- }
- else if (ser_soft_param)
- set_ser_soft ();
- }
-
-