BB2 C port
API reference: Blitz libraries in C and the shared code
Loading...
Searching...
No Matches
riarexxlib.c File Reference
#include "blitzlib.h"
#include "blitzexec.h"
#include <exec/ports.h>
#include <exec/memory.h>
#include <rexx/storage.h>
#include <proto/dos.h>

Data Structures

struct  msglists

Macros

#define __NOLIBBASE__
#define DOS_BASE_NAME   dosbase
#define AO   BLITZ_AMIGAONLY
#define MSGLIST_FULL()
#define NOWORD   ((ULONG)-1)
#define REPLYWAIT_TICKS   250

Functions

void _rxcreateport (void)
void _rxdeleteport (void)
void readport (void)
void waitport (void)
void _replymsg (void)
void _replymsg2 (void)
void _rxruncommand2 (void)
void _rxruncommand (void)
void _rxsendersname (void)
void _rxsendcommand2 (void)
void _rxsendcommand (void)
void _rxnumargs (void)
void _rxgetarg (void)
void _rxexecutescript (void)
void _rxrunscript (void)
void _rxdefportname (void)
void _rxnextarg (void)
void _rxreturncode (void)
void _rxtokenise (void)
void _rxmessagelist (void)
void _rxquotechar (void)
void riarexxlib_libinit (void)
void riarexxlib_libfinit (void)
void portchk (void)
static void portchk_c (void)
static void * allocvec (ULONG size, ULONG flags)
static void freevec (void *block)
static ULONG createargstring_lib (const UBYTE *s, ULONG len)
static ULONG createargstring (const UBYTE *s, ULONG len)
static void deleteargstring (ULONG s)
static ULONG allocst (ULONG s, ULONG len)
static void freest (ULONG s)
static ULONG tostring (const UBYTE *s)
static ULONG libinit_c (void)
 init: open rexxsyslib.library V34; the defaults (quote '"', RXTokenise on, the default port "REXX").
static void deleteport (BB_BOOL freename)
static void libfinit_c (void)
 finit: RXTokenise on again, delete the port if there is one (as RXDeletePort, with its wait of up to 5 s for the replies of the sent list (fixed #1095); the name is left to maxslib, which frees its strings at the end of the program), close rexxsyslib.library.
static void rxquotechar_c (const UBYTE *s)
 RXQuoteChar char$: the quote character of the parser (RXTokenise on; default '"').
static ULONG rxmessagelist_c (void)
 RXMessageList: the list of received messages not yet current.
static void rxtokenise_c (ULONG on)
 RXTokenise on|off: whether commands are split into words (with RXQuoteChar quotes) or sent as one argument string.
static ULONG rxreturncode_c (void)
 RXReturnCode: the Result1 of the last reply to RXSendCommand.
static void rxdefportname_c (const UBYTE *s)
 RXDefaultPort portname$: the port of the forms of RXRunCommand and RXSendCommand without a port name.
static const UBYTE * defport (void)
static void addtolist (ULONG *l, ULONG item)
static BB_BOOL addsent (ULONG item)
static ULONG * findsent (ULONG item)
static void deleteitem (ULONG *item)
static void parseinit (const UBYTE *s)
static ULONG nextparsearg (UBYTE *out)
static struct RexxMsg * makemsg (void)
static void makemsgargs (UBYTE *word)
static ULONG waitport_c (ULONG result)
static ULONG readport_c (void)
 RXReadPort: take every message from the port; the first of the message list becomes the current message.
static ULONG sendmsg (void)
static ULONG sendmessage (void)
static ULONG sendto (const UBYTE *port, ULONG cmd, ULONG type, UWORD wait, UWORD whole, UWORD nores)
static ULONG runcommand (const UBYTE *port, ULONG cmd)
static ULONG rxruncommand_c (const UBYTE *port, ULONG cmd)
 RXRunCommand portname$,command$: send a command to a port, no reply awaited.
static ULONG rxruncommand2_c (ULONG cmd)
 RXRunCommand command$: as RXRunCommand to the RXDefaultPort port.
static ULONG rxexecutescript_c (ULONG name)
 RXExecuteScript scriptname$: run an ARexx script through the port "REXX" and wait for its end.
static ULONG rxrunscript_c (ULONG name)
 RXRunScript scriptname$: run an ARexx script through the port "REXX", no reply awaited.
static ULONG sendcommand (const UBYTE *port, ULONG cmd)
static ULONG rxsendcommand2_c (ULONG cmd)
 RXSendCommand(command$): as RXSendCommand to the RXDefaultPort port.
static ULONG rxsendcommand_c (const UBYTE *port, ULONG cmd, const ULONG *args)
 RXSendCommand(portname$,command$): send a command and wait for the reply; its result string.
static void freemsg (ULONG *item)
static void storeresult (struct RexxMsg *m)
static void handlereply (void)
static void takereplies (void)
static ULONG donereadport (ULONG passed)
static ULONG rxwaitport_c (ULONG result)
 RXWaitPort: wait for a message (if none is in the list), then RXReadPort.
static BB_BOOL replymsg (ULONG code, const UBYTE *res, const ULONG *args)
static void replymsg_c (ULONG code)
 RXReplyMsg errcode: reply the current message.
static void replymsg2_c (ULONG code, const UBYTE *res, const ULONG *args)
 RXReplyMsg errcode,result$: reply the current message with a result string (CreateArgString).
static ULONG rxsendersname_c (void)
 RXSendersName: the name of the current message (ln_Name: the sender's port).
static ULONG getarg (ULONG n)
static ULONG rxgetarg_c (ULONG n)
 RXGetArg(argnum): argument argnum (1..16) of the current message.
static ULONG rxnextarg_c (ULONG argnum)
 RXNextArg: the next argument of the current message (from 1 on, as RXGetArg).
static ULONG rxnumargs_c (void)
 RXNumArgs: the number of arguments of the current message (up to the first 0 of rm_Args).
static void replywaiting (void)
static ULONG ticksnow (struct Library *dosbase)
static BB_BOOL waitsent (void)
static void rxdeleteport_c (void)
 RXDeletePort: delete the port.
static ULONG rxcreateport_c (ULONG name, const ULONG *args)
 RXCreatePort(name$): make the public port name$ and the message lists.

Variables

static struct MsgPort * msgport
static ULONG msgstring
static ULONG msgtype
static UBYTE * msgportname
static UBYTE quote
static UWORD tokenise
static UWORD oktodelete
static UWORD wholearg
static UWORD noresult
static const UBYTE * curadr
static const char rexxname [] = "rexxsyslib.library"
static const char dosname [] = "dos.library"
static const char realrexxportname [] = "REXX"
static const char emptyname [] = ""
static UBYTE * defportname
struct { 
   struct Library *   rexxbase 
   struct MsgPort *   destport 
   UBYTE *   returnstring 
   ULONG   returncode 
   ULONG *   sentlist 
   ULONG *   messagelist 
   ULONG   waitreply 
   UWORD   replyreq 
   struct RexxMsg *   thismsg 
   struct RexxMsg *   currentmessage 
   UWORD   currentarg 
} v

Macro Definition Documentation

◆ __NOLIBBASE__

#define __NOLIBBASE__

◆ AO

#define AO   BLITZ_AMIGAONLY

◆ DOS_BASE_NAME

#define DOS_BASE_NAME   dosbase

◆ MSGLIST_FULL

#define MSGLIST_FULL ( )
Value:
(v.messagelist[30] != 0)
static struct @342026374002303043102303243063125232020331002053 v

◆ NOWORD

#define NOWORD   ((ULONG)-1)

◆ REPLYWAIT_TICKS

#define REPLYWAIT_TICKS   250

Function Documentation

◆ _replymsg()

void _replymsg ( void )

◆ _replymsg2()

void _replymsg2 ( void )

◆ _rxcreateport()

void _rxcreateport ( void )

◆ _rxdefportname()

void _rxdefportname ( void )

◆ _rxdeleteport()

void _rxdeleteport ( void )

◆ _rxexecutescript()

void _rxexecutescript ( void )

◆ _rxgetarg()

void _rxgetarg ( void )

◆ _rxmessagelist()

void _rxmessagelist ( void )

◆ _rxnextarg()

void _rxnextarg ( void )

◆ _rxnumargs()

void _rxnumargs ( void )

◆ _rxquotechar()

void _rxquotechar ( void )

◆ _rxreturncode()

void _rxreturncode ( void )

◆ _rxruncommand()

void _rxruncommand ( void )

◆ _rxruncommand2()

void _rxruncommand2 ( void )

◆ _rxrunscript()

void _rxrunscript ( void )

◆ _rxsendcommand()

void _rxsendcommand ( void )

◆ _rxsendcommand2()

void _rxsendcommand2 ( void )

◆ _rxsendersname()

void _rxsendersname ( void )

◆ _rxtokenise()

void _rxtokenise ( void )

◆ addsent()

BB_BOOL addsent ( ULONG item)
static

◆ addtolist()

void addtolist ( ULONG * l,
ULONG item )
static

◆ allocst()

ULONG allocst ( ULONG s,
ULONG len )
static

◆ allocvec()

void * allocvec ( ULONG size,
ULONG flags )
static

◆ createargstring()

ULONG createargstring ( const UBYTE * s,
ULONG len )
static

◆ createargstring_lib()

ULONG createargstring_lib ( const UBYTE * s,
ULONG len )
static

◆ defport()

const UBYTE * defport ( void )
static

◆ deleteargstring()

void deleteargstring ( ULONG s)
static

◆ deleteitem()

void deleteitem ( ULONG * item)
static

◆ deleteport()

void deleteport ( BB_BOOL freename)
static

◆ donereadport()

ULONG donereadport ( ULONG passed)
static

◆ findsent()

ULONG * findsent ( ULONG item)
static

◆ freemsg()

void freemsg ( ULONG * item)
static

◆ freest()

void freest ( ULONG s)
static

◆ freevec()

void freevec ( void * block)
static

◆ getarg()

ULONG getarg ( ULONG n)
static

◆ handlereply()

void handlereply ( void )
static

◆ libfinit_c()

void libfinit_c ( void )
static

finit: RXTokenise on again, delete the port if there is one (as RXDeletePort, with its wait of up to 5 s for the replies of the sent list (fixed #1095); the name is left to maxslib, which frees its strings at the end of the program), close rexxsyslib.library.

Fixed (#1093): the original never closed rexxsyslib.library.

◆ libinit_c()

ULONG libinit_c ( void )
static

init: open rexxsyslib.library V34; the defaults (quote '"', RXTokenise on, the default port "REXX").

Fixed (#532): the default port is "REXX" again; the original wrote "REXX" and a 0 at +5 over the name, so the byte at +4 of an earlier RXDefaultPort stayed. A copy of an earlier run is maxslib's, freed at that run's end (#529).

Returns
d0: 0

◆ makemsg()

struct RexxMsg * makemsg ( void )
static

◆ makemsgargs()

void makemsgargs ( UBYTE * word)
static

◆ nextparsearg()

ULONG nextparsearg ( UBYTE * out)
static

◆ parseinit()

void parseinit ( const UBYTE * s)
static

◆ portchk()

void portchk ( void )

◆ portchk_c()

void portchk_c ( void )
static

◆ readport()

void readport ( void )

◆ readport_c()

ULONG readport_c ( void )
static

RXReadPort: take every message from the port; the first of the message list becomes the current message.

Replies to our messages are freed (to RXSendCommand's: its result kept); messages go to the message list; anything else is replied and ends the reading. Fixed (#1100): while the list holds 31 messages the others stay in the port, in their order, and only the replies are taken out of it; the original appended every message without a limit, past the list. Error check portchk: "No message port opened!".

Returns
d0: the new current message (0 if the list is empty); 0 while RXSendCommand waits (oktodelete: no message becomes current)

◆ replymsg()

BB_BOOL replymsg ( ULONG code,
const UBYTE * res,
const ULONG * args )
static

◆ replymsg2_c()

void replymsg2_c ( ULONG code,
const UBYTE * res,
const ULONG * args )
static

RXReplyMsg errcode,result$: reply the current message with a result string (CreateArgString).

The string only if the message asked for a result (RXFF_RESULT) and errcode is 0 (fixed #539: the original made it always), and only when the sender's port exists (fixed #540: the original made it first and, with the port gone, tested the Result2 at the a0 FindPort leaves). As the form without.

Parameters
coded0: Result1
resd1: result$, Result2
argsa2: the argument stack, -4(a2) the length of result$

◆ replymsg_c()

void replymsg_c ( ULONG code)
static

RXReplyMsg errcode: reply the current message.

Nothing without a current message. If the port of the message's ln_Name no longer exists, it is not replied. Afterwards there is no current message (fixed #541: the original kept the replied one).

Parameters
coded0: Result1

◆ replywaiting()

void replywaiting ( void )
static

◆ riarexxlib_libfinit()

void riarexxlib_libfinit ( void )

◆ riarexxlib_libinit()

void riarexxlib_libinit ( void )

◆ runcommand()

ULONG runcommand ( const UBYTE * port,
ULONG cmd )
static

◆ rxcreateport_c()

ULONG rxcreateport_c ( ULONG name,
const ULONG * args )
static

RXCreatePort(name$): make the public port name$ and the message lists.

The name is copied with AllocSt. Fixed (#528): the lists are allocated before the port is made public, AddPort is not tested, and on failure what was allocated is freed (0, D-018); the original added the port first, tested the d0 AddPort leaves and on failure deleted the port without RemPort, so it stayed in the public list.

Parameters
named0: name$
argsa2: the argument stack, -4(a2) the length of name$
Returns
d0: the MsgPort; 0 if there is one already, if a public port of the name exists (fixed #1096) or on failure

◆ rxdefportname_c()

void rxdefportname_c ( const UBYTE * s)
static

RXDefaultPort portname$: the port of the forms of RXRunCommand and RXSendCommand without a port name.

Fixed (#529): the name is kept as a copy of its own length (maxslib AllocSt), the copy before freed; the original copied it without a limit into the 65 bytes of rexxportname, over rexxbase and the variables behind it.

Parameters
sd0: portname$

◆ rxdeleteport_c()

void rxdeleteport_c ( void )
static

RXDeletePort: delete the port.

Messages still waiting are replied (RXReplyMsg 5 for the current message, then for each one RXReadPort makes current, then ReplyMsg for the rest of the message list); then it waits up to 5 s for the replies to the messages sent without waiting (RXRunCommand, RXRunScript), replying 5 to messages that arrive meanwhile; then RemPort, the port freed; the block of the lists and the name are freed (fixed #530: the original freed neither). With a reply still outstanding after 5 s the port is only taken off the public list: it and the name stay allocated for the late reply (fixed #1095: the original did not wait, the reply went to the deleted port). Fixed (#1101): the original never replied the message current when it was called. Error check portchk.

◆ rxexecutescript_c()

ULONG rxexecutescript_c ( ULONG name)
static

RXExecuteScript scriptname$: run an ARexx script through the port "REXX" and wait for its end.

RXCOMM|RXFF_RESULT, the name as one argument; while it waits, received messages go to the message list (as RXSendCommand). The script's code is RXReturnCode, a result string is deleted. Fixed (#544, user decision W4 Q1 (b)): the original's _rxruncommand overwrote the type, so it sent RXCOMM|RXFF_STRING (the name as a tokenised string program) and did not wait.

Parameters
named0: scriptname$
Returns
d0: -1 when sent and replied; 0 if there is no REXX port or no message

◆ rxgetarg_c()

ULONG rxgetarg_c ( ULONG n)
static

RXGetArg(argnum): argument argnum (1..16) of the current message.

Parameters
nd0.w: the argument's number
Returns
d0: the length of the argument (at a3); 0 if out of range, without a current message or argument

◆ rxmessagelist_c()

ULONG rxmessagelist_c ( void )
static

RXMessageList: the list of received messages not yet current.

Returns
d0: the list (32 longs, 0 ended; 0 before RXCreatePort)

◆ rxnextarg_c()

ULONG rxnextarg_c ( ULONG argnum)
static

RXNextArg: the next argument of the current message (from 1 on, as RXGetArg).

Fixed (#534): it advances when the argument slot is not 0; the original tested the length, so at an empty argument it stayed.

Parameters
argnumd0: no argument; MOVE.w currentarg,d0 keeps its upper word
Returns
d0: the length of the argument (at a3); 0 at the end

◆ rxnumargs_c()

ULONG rxnumargs_c ( void )
static

RXNumArgs: the number of arguments of the current message (up to the first 0 of rm_Args).

Returns
d0: the count; 0 without a current message

◆ rxquotechar_c()

void rxquotechar_c ( const UBYTE * s)
static

RXQuoteChar char$: the quote character of the parser (RXTokenise on; default '"').

Parameters
sd0: the string, its first character

◆ rxreturncode_c()

ULONG rxreturncode_c ( void )
static

RXReturnCode: the Result1 of the last reply to RXSendCommand.

Fixed (#542): also while no message is current; the original returned 0 then, e.g. right after an RXSendCommand that found the list empty.

Returns
d0: the code

◆ rxruncommand2_c()

ULONG rxruncommand2_c ( ULONG cmd)
static

RXRunCommand command$: as RXRunCommand to the RXDefaultPort port.

Parameters
cmdd0: command$
Returns
d0: as above

◆ rxruncommand_c()

ULONG rxruncommand_c ( const UBYTE * port,
ULONG cmd )
static

RXRunCommand portname$,command$: send a command to a port, no reply awaited.

The message (RXCOMM|RXFF_STRING) goes into the sent list (31 at most: when it is full nothing is sent, 0); its reply is freed with its arguments and its entry (fixed #531).

Parameters
portd0: portname$
cmdd1: command$
Returns
d0: 0 if the port is not found or there is no message; else -1 (fixed #543: the original returned the d0 PutMsg leaves)

◆ rxrunscript_c()

ULONG rxrunscript_c ( ULONG name)
static

RXRunScript scriptname$: run an ARexx script through the port "REXX", no reply awaited.

RXCOMM, the name as one argument, into the sent list as RXRunCommand. Fixed (#544): the original's _rxruncommand overwrote the type (it sent RXCOMM|RXFF_STRING, the name as a tokenised string program).

Parameters
named0: scriptname$
Returns
d0: as RXRunCommand

◆ rxsendcommand2_c()

ULONG rxsendcommand2_c ( ULONG cmd)
static

RXSendCommand(command$): as RXSendCommand to the RXDefaultPort port.

Parameters
cmdd0: command$
Returns
d0: the length of the result string (at a3); 0 without

◆ rxsendcommand_c()

ULONG rxsendcommand_c ( const UBYTE * port,
ULONG cmd,
const ULONG * args )
static

RXSendCommand(portname$,command$): send a command and wait for the reply; its result string.

RXCOMM|RXFF_STRING|RXFF_RESULT. The result goes over the two arguments: a3 back by both lengths (on the a2 stack) + 2. While it waits, received messages go to the message list. The reply's Result1 is RXReturnCode; its Result2 is the result string only with Result1 0 (fixed #545: the original read it as a string also with an error). The result string is copied to a3 and the reply's string deleted (fixed #546: the original copied it with AllocSt, never freed the copy and never deleted the string).

Parameters
portd0: portname$
cmdd1: command$
argsa2: the argument stack, -4/-8(a2) the two lengths
Returns
d0: the length of the result string; 0 without one or if the port is not found

◆ rxsendersname_c()

ULONG rxsendersname_c ( void )
static

RXSendersName: the name of the current message (ln_Name: the sender's port).

Returns
d0: the length of the name (at a3); 0 without a current message

◆ rxtokenise_c()

void rxtokenise_c ( ULONG on)
static

RXTokenise on|off: whether commands are split into words (with RXQuoteChar quotes) or sent as one argument string.

Fixed (#547): only the word is stored; the original's MOVE.l d0 stored the upper word of the register too, so "off" with a set upper word stayed on.

Parameters
ond0.w: 0 off, else on (the upper word is not part of it)

◆ rxwaitport_c()

ULONG rxwaitport_c ( ULONG result)
static

RXWaitPort: wait for a message (if none is in the list), then RXReadPort.

Parameters
resultd0: returned instead of a message while RXSendCommand waits (oktodelete)
Returns
d0: as RXReadPort

◆ sendcommand()

ULONG sendcommand ( const UBYTE * port,
ULONG cmd )
static

◆ sendmessage()

ULONG sendmessage ( void )
static

◆ sendmsg()

ULONG sendmsg ( void )
static

◆ sendto()

ULONG sendto ( const UBYTE * port,
ULONG cmd,
ULONG type,
UWORD wait,
UWORD whole,
UWORD nores )
static

◆ storeresult()

void storeresult ( struct RexxMsg * m)
static

◆ takereplies()

void takereplies ( void )
static

◆ ticksnow()

ULONG ticksnow ( struct Library * dosbase)
static

◆ tostring()

ULONG tostring ( const UBYTE * s)
static

◆ waitport()

void waitport ( void )

◆ waitport_c()

ULONG waitport_c ( ULONG result)
static

◆ waitsent()

BB_BOOL waitsent ( void )
static

Variable Documentation

◆ curadr

const UBYTE* curadr
static

◆ currentarg

UWORD currentarg

◆ currentmessage

struct RexxMsg* currentmessage

◆ defportname

UBYTE* defportname
static

◆ destport

struct MsgPort* destport

◆ dosname

const char dosname[] = "dos.library"
static

◆ emptyname

const char emptyname[] = ""
static

◆ messagelist

ULONG* messagelist

◆ msgport

struct MsgPort* msgport
static

◆ msgportname

UBYTE* msgportname
static

◆ msgstring

ULONG msgstring
static

◆ msgtype

ULONG msgtype
static

◆ noresult

UWORD noresult
static

◆ oktodelete

UWORD oktodelete
static

◆ quote

UBYTE quote
static

◆ realrexxportname

const char realrexxportname[] = "REXX"
static

◆ replyreq

UWORD replyreq

◆ returncode

ULONG returncode

◆ returnstring

UBYTE* returnstring ( void )

◆ rexxbase

struct Library* rexxbase

◆ rexxname

const char rexxname[] = "rexxsyslib.library"
static

◆ sentlist

ULONG* sentlist

◆ thismsg

struct RexxMsg* thismsg

◆ tokenise

UWORD tokenise
static

◆ [struct]

struct { ... } v

◆ waitreply

ULONG waitreply

◆ wholearg

UWORD wholearg
static