Commit f233389a authored by John P. Willis's avatar John P. Willis
Browse files

Further $DEVICE improvements

parent 25097828
Pipeline #755 passed with stage
in 1 minute and 28 seconds
#!/bin/sh
echo "cleanup_shm.sh: cleaning up shared memory..."
ipcrm -M 0x00bbdd20
echo "cleanup_shm.sh: cleaning up semaphores..."
ipcrm -S 0x00bbdd21
ipcrm -S 0x00bbdd22
ipcrm -S 0x00bbdd23
ipcrm -S 0x00bbdd24
echo "Done."
......@@ -104,7 +104,7 @@ char errmes[MAXERR][ERRLEN] = {
"^$ZRPI only supported on Raspberry Pi hardware\201", /* NORPI */
"cannot redefine CONST\201", /* CREDEF */
"cannot modify CONST\201", /* CMODIFY */
" \201",
"cannot open existing file for WRITE\201", /* FILEXWR */
" \201",
" \201",
" \201",
......
......@@ -5834,9 +5834,14 @@ errexfun:
/* $DEVICE */
case 'd':
snprintf (a, 20, "0\201");
goto exec;
if (devstat[io].mdc_err == 0) {
snprintf (a, 3, "0\201\0");
}
else {
snprintf (a, 120, "%d,%d,%s\201\0", devstat[io].mdc_err, devstat[io].frm_err, devstat[io].err_txt);
}
goto exec;
/* $STORAGE */
case 's':
......
......@@ -320,6 +320,15 @@ char zloc[256] = "\201"; /* $ZL last local reference */
char zref[256] = "\201"; /* $ZR last global reference */
short nakoffs = 0; /* offset to naked reference */
char zfunkey[44][FUNLEN]; /* $ZF function key */
typedef struct frm_devstat {
short mdc_err;
short frm_err;
char err_txt[80];
} frm_devstat;
frm_devstat devstat[MAXDEV + 1]; /* channel statuses for $DEVICE */
short xpos[MAXDEV + 1]; /* $X-vector */
short ypos[MAXDEV + 1]; /* $Y-vector */
short crlf[MAXDEV + 1]; /* CR/LF flag vector */
......
......@@ -80,7 +80,6 @@ io_socket *io_sockets[MAXSCK];
addr_string: server:port[:family:[udp|tcp]]*/
short msck_open (int channel, char *addr_string)
{
#if !defined(MSDOS)
char *addr = "";
char *port = "";
......@@ -102,12 +101,15 @@ short msck_open (int channel, char *addr_string)
short i = channel + FIRSTSCK; /* get index into io_sockets[] array */
merr_clear_iochan_err (channel);
for (j = 0; j < strlen (addr_string); j++) {
if (addr_string[j] == ':') ct++;
}
if (ct < 1 || ct > 3) {
ierr = ARGLIST;
merr_set_iochan_err (channel, ARGLIST, "invalid OPEN parameters");
return -1;
}
......@@ -150,6 +152,7 @@ short msck_open (int channel, char *addr_string)
#endif
else {
ierr = SCKIFAM;
merr_set_iochan_err (channel, SCKIFAM, "invalid address family");
return 0;
}
......@@ -176,6 +179,7 @@ short msck_open (int channel, char *addr_string)
if (pt < 0 || pt > 65535) {
ierr = SCKIPRT;
merr_set_iochan_err (channel, SCKIPRT, "invalid port number");
return 0;
}
......@@ -187,6 +191,7 @@ short msck_open (int channel, char *addr_string)
if ((he = gethostbyname (addr)) == NULL) {
ierr = NAMERES;
merr_set_iochan_err (channel, NAMERES, "name resolution failure");
return 0;
}
......@@ -208,6 +213,7 @@ short msck_open (int channel, char *addr_string)
if (io_sockets[i]->sck == -1) {
ierr = SCKCREAT;
merr_set_iochan_err (channel, SCKCREAT, "error creating socket");
return 0;
}
......@@ -216,6 +222,7 @@ short msck_open (int channel, char *addr_string)
#else
ierr = SCKCREAT;
merr_set_iochan_err (channel, SCKCREAT, "error creating socket");
return 0;
#endif
......@@ -231,16 +238,19 @@ short msck_connect (int channel)
if (io_sockets[i]->typ != SOCK_STREAM) {
ierr = SCKAERR;
merr_set_iochan_err (channel, SCKAERR, "cannot CONNECT a UDP socket");
return 0;
}
if (io_sockets[i]->connected == TRUE) {
ierr = SCKACON;
merr_set_iochan_err (channel, SCKACON, "cannot CONNECT previously-connected socket");
return 0;
}
if (connect (io_sockets[i]->sck, (struct sockaddr *) &(io_sockets[i]->srv), sizeof (io_sockets[i]->srv)) < 0) {
ierr = SCKCERR;
merr_set_iochan_err (channel, SCKCERR, "error in CONNECT");
return 0;
}
else {
......@@ -268,14 +278,15 @@ short msck_write (int channel, char *buf, short length)
if (io_sockets[i]->connected == FALSE && io_sockets[i]->typ != SOCK_DGRAM) {
/* throw socket not connected error if not doing UDP */
ierr = SCKNCON;
merr_set_iochan_err (channel, SCKNCON, "TCP socket not connected");
return 0;
}
if ((ct = send (io_sockets[i]->sck, buf, length, 0)) < 0) {
ierr = SCKESND;
merr_set_iochan_err (channel, SCKESND, "error in WRITE to socket");
return 0;
}
......@@ -284,6 +295,7 @@ short msck_write (int channel, char *buf, short length)
#else
ierr = SCKNCON;
merr_set_iochan_err (channel, SCKNCON, "TCP socket not connected");
return 0;
#endif
......@@ -314,6 +326,7 @@ short msck_read (int channel, char *buf, long timeout, short timeoutms, short le
if (io_sockets[i]->connected == FALSE && io_sockets[i]->typ != SOCK_DGRAM) {
ierr = SCKNCON;
merr_set_iochan_err (channel, SCKNCON, "TCP socket not connected");
return 0;
}
......@@ -344,6 +357,7 @@ short msck_read (int channel, char *buf, long timeout, short timeoutms, short le
if ((rcvct = recv (io_sockets[i]->sck, rdbuf, 1, 0)) < 1) {
ierr = SCKERCV;
merr_set_iochan_err (channel, SCKERCV, "error in READ from socket");
return 0;
}
else {
......
......@@ -122,6 +122,7 @@ err_lut errtab[] = {
{61, "ZNORPI"},
{62, "ZCREDEF"},
{63, "ZCMODIFY"},
{64, "ZFILEXWR"},
{80, "ZECODEINV"},
{81, "ZASSERT"},
{82, "ZUSERERR"},
......@@ -368,3 +369,34 @@ done:
return;
}
void merr_set_iochan_err(int channel, short frm_err, char *err_text)
{
if (channel > MAXDEV || channel < 0) {
ierr = ARGLIST;
return;
}
devstat[channel].mdc_err = 1;
devstat[channel].frm_err = frm_err;
strncpy (devstat[channel].err_txt, err_text, 79);
return;
}
void merr_clear_iochan_err(int channel)
{
if (channel > MAXDEV || channel < 0) {
ierr = ARGLIST;
return;
}
devstat[channel].mdc_err = 1;
devstat[channel].frm_err = OK;
devstat[channel].err_txt[0] = '\0';
return;
}
......@@ -107,6 +107,7 @@
#define NORPI 61
#define CREDEF 62
#define CMODIFY 63
#define FILEXWR 64
#define ECODEINV 80
#define ASSERT 81
#define USERERR 82
......@@ -202,6 +203,8 @@ extern int merr_code_to_num (char *code);
extern void merr_set_ecode_ierr (void);
extern int merr_set_ecode (char *t_code);
extern void merr_dump (int num, char *rtn, char *nsn, char *tcod, int tpos);
extern void merr_set_iochan_err(int channel, short frm_err, char *err_text);
extern void merr_clear_iochan_err(int channel);
typedef struct merr_stackent {
char ECODE[256];
......
......@@ -185,6 +185,14 @@ extern char devopen[MAXDEV + 1]; /* 0 not open */
extern short fp_mode; /* 0 = fixed, 1 = IEEE 754 */
extern short en_revstrf; /* if 1, reverse $E, $P, $N enabled */
typedef struct frm_devstat {
short mdc_err;
short frm_err;
char err_txt[80];
} frm_devstat;
extern frm_devstat devstat[MAXDEV + 1]; /* device error statuses */
extern char dev[MAXDEV + 1][40]; /* names of IO devices */
extern char G0I[MAXDEV + 1][257]; /* G0 input translation table */
......
......@@ -84,14 +84,17 @@ void ssvn_device(short action, char *key, char *data)
goto done;
}
for (i = 0; i < strlen (r->subscripts[1]); i++) r->subscripts[1][i] = toupper (r->subscripts[1][i]);
fp = opnfile[channel];
if (channel != 0 && (fp == NULL || (fd = fileno (fp)) == -1) && channel < FIRSTSCK) {
if (channel != 0 && (fp == NULL || (fd = fileno (fp)) == -1) && channel < FIRSTSCK && strcmp (r->subscripts[1], "$DEVICE") != 0) {
ierr = NOPEN;
goto done;
}
for (i = 0; i < strlen (r->subscripts[1]); i++) r->subscripts[1][i] = toupper (r->subscripts[1][i]);
key = mref_to_internal (r);
......@@ -106,7 +109,19 @@ void ssvn_device(short action, char *key, char *data)
if (r->subscript_count == 2) {
if (r->subscript_count == 2) {
if (strcmp (r->subscripts[1], "$DEVICE") == 0) {
if (devstat[channel].mdc_err == 0) {
snprintf (data, 3, "0\201\0");
}
else {
snprintf (data, 120, "%d,%d,%s\201\0", devstat[channel].mdc_err, devstat[channel].frm_err, devstat[channel].err_txt);
}
break;
}
if (strcmp (r->subscripts[1], "EOF") == 0 && channel != 0) {
if (feof (fp)) {
......
......@@ -4981,6 +4981,7 @@ use_socket:
if (dev[k][0] == EOL) {
ierr = FILERR;
merr_set_iochan_err (k, FILERR, "file not found");
goto err;
}
......@@ -5147,6 +5148,18 @@ open10:
act_oucpath[k][0] = EOL;
ierr = (errno == ENOENT ? FILERR : PROTECT);
switch (ierr) {
case FILERR:
merr_set_iochan_err (k, FILERR, "file not found");
break;
case PROTECT:
merr_set_iochan_err (k, PROTECT, "file protection violation");
break;
}
goto err;
}
......@@ -5195,6 +5208,8 @@ open10:
act_oucpath[k][0] = EOL;
ierr = PROTECT;
merr_set_iochan_err (k, PROTECT, "file protection violation");
goto err;
}
......@@ -5215,6 +5230,7 @@ open10:
}
else {
ierr = ARGLIST;
merr_set_iochan_err (k, ARGLIST, "invalid argument");
goto err;
}
}
......@@ -5223,7 +5239,14 @@ open10:
open_socket:
if (*codptr != ':') {
ierr = ARGLIST;
if (j == 'w') {
ierr = FILEXWR;
merr_set_iochan_err (k, FILEXWR, "cannot open existing file for WRITE");
}
else {
ierr = ARGLIST;
merr_set_iochan_err (k, ARGLIST, "invalid argument");
}
goto err;
}
......@@ -5237,6 +5260,9 @@ open_socket:
stcnv_m2c (vn);
msck_open (k, vn);
if (ierr > OK) goto err;
ssvn_job_add_device (k, vn);
break;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment