From 83156bf650bda04230f6473a9e5d4600e2e413fe Mon Sep 17 00:00:00 2001 From: Richard Cornwell Date: Sun, 3 Nov 2019 13:42:56 -0500 Subject: [PATCH] SCP: Updated to current. --- scp.c | 48 ++++++++++++++++++------------------------------ sim_defs.h | 4 ++-- sim_fio.c | 28 ++++++++++++++++++++++++++++ sim_sock.c | 8 ++++---- 4 files changed, 52 insertions(+), 36 deletions(-) diff --git a/scp.c b/scp.c index f3f7341..ba15f05 100644 --- a/scp.c +++ b/scp.c @@ -1651,6 +1651,8 @@ static const char simh_help[] = "++%%~pI%% - expands the value of %%I%% to a path only\n" "++%%~nI%% - expands the value of %%I%% to a file name only\n" "++%%~xI%% - expands the value of %%I%% to a file extension only\n\n" + "++%%~tI%% - expands the value of %%I%% to date/time of file\n\n" + "++%%~zI%% - expands the value of %%I%% to size of file\n\n" " The modifiers can be combined to get compound results:\n\n" "++%%~pnI%% - expands the value of %%I%% to a path and name only\n" "++%%~nxI%% - expands the value of %%I%% to a file name and extension only\n\n" @@ -3125,7 +3127,7 @@ if (dptr->modifiers) { if ((!mptr->disp) || (!mptr->pstring) || !(*mptr->pstring)) continue; fprint_header (st, &found, header); - sprintf (buf, "show %s %s%s", sim_dname (dptr), mptr->pstring, MODMASK(mptr,MTAB_SHP) ? "=arg" : ""); + sprintf (buf, "show %s %s%s", sim_dname (dptr), mptr->pstring, MODMASK(mptr,MTAB_SHP) ? "{=arg}" : ""); fprintf (st, "%-30s\t%s\n", buf, mptr->help ? mptr->help : ""); } } @@ -4210,7 +4212,7 @@ for (; *ip && (op < oend); ) { if (*ip == '~') { expand_it = TRUE; ++ip; - for (i=0; (i < (sizeof (parts) - 1)) && (strchr ("fpnx", *ip)); i++, ip++) { + for (i=0; (i < (sizeof (parts) - 1)) && (strchr ("fpnxtz", *ip)); i++, ip++) { parts[i] = *ip; parts[i + 1] = '\0'; } @@ -5310,11 +5312,6 @@ while (*cptr != 0) { /* do all mods */ } else if (!mptr->desc) /* value desc? */ break; -// else if (mptr->mask & MTAB_VAL) { /* take a value? */ -// if (!cvptr) return SCPE_MISVAL; /* none? error */ -// r = dep_reg (0, cvptr, (REG *) mptr->desc, 0); -// if (r != SCPE_OK) return r; -// } else if (cvptr) /* = value? */ return SCPE_ARG; else *((int32 *) mptr->desc) = mptr->match; @@ -5529,9 +5526,9 @@ if ((dptr = find_dev (gbuf))) { /* device match? */ } else if ((dptr = find_unit (gbuf, &uptr))) { /* unit match? */ if (uptr == NULL) /* invalid unit */ - return SCPE_NXUN; + return sim_messagef (SCPE_NXUN, "Non-existent unit: %s\n", gbuf); if (uptr->flags & UNIT_DIS) /* disabled? */ - return SCPE_UDIS; + return sim_messagef (SCPE_UDIS, "Unit disabled: %s\n", gbuf); shtb = show_unit_tab; /* global table */ lvl = MTAB_VUN; /* unit match */ GET_SWITCHES (cptr); /* get more switches */ @@ -5544,7 +5541,7 @@ else { if (sim_dflt_dev->modifiers) { if ((cvptr = strchr (gbuf, '='))) /* = value? */ *cvptr++ = 0; - for (mptr = sim_dflt_dev->modifiers; mptr->mask != 0; mptr++) { + for (mptr = sim_dflt_dev->modifiers; mptr && (mptr->mask != 0); mptr++) { if ((((mptr->mask & MTAB_VDV) == MTAB_VDV) && (mptr->pstring && (MATCH_CMD (gbuf, mptr->pstring) == 0))) || (!(mptr->mask & MTAB_VDV) && (mptr->mstring && (MATCH_CMD (gbuf, mptr->mstring) == 0)))) { @@ -5561,7 +5558,7 @@ else { if ((shptr = find_shtab (show_dev_tab, gbuf))) /* global match? */ return shptr->action (ofile, sim_dflt_dev, uptr, shptr->arg, cptr); else - return SCPE_NXDEV; /* no match */ + return sim_messagef (SCPE_NXDEV, "Non-existent device: %s\n", gbuf);/* no match */ } } @@ -5581,13 +5578,9 @@ while (*cptr != 0) { /* do all mods */ ((mptr->mask & lvl) == lvl): (MTAB_VUN & lvl)) && ((mptr->disp && mptr->pstring && /* named disp? */ (MATCH_CMD (gbuf, mptr->pstring) == 0)) - // || - // ((mptr->mask & MTAB_VAL) && /* named value? */ - // mptr->mstring && - // (MATCH_CMD (gbuf, mptr->mstring) == 0))) )) { - if (cvptr && !(mptr->mask & MTAB_SHP)) - return SCPE_ARG; + if (cvptr && !MODMASK(mptr,MTAB_SHP)) + return sim_messagef (SCPE_ARG, "Invalid Argument: %s=%s\n", gbuf, cvptr); show_one_mod (ofile, dptr, uptr, mptr, cvptr, 1); break; } /* end if */ @@ -5600,10 +5593,12 @@ while (*cptr != 0) { /* do all mods */ if (r != SCPE_OK) return r; } - else if (!dptr->modifiers) /* no modifiers? */ - return SCPE_NOPARAM; - else - return SCPE_NXPAR; + else { + if (!dptr->modifiers) /* no modifiers? */ + return sim_messagef (SCPE_NOPARAM, "%s device has no parameters\n", dptr->name); + else + return sim_messagef (SCPE_NXPAR, "Non-existent parameter: %s\n", gbuf); + } } /* end if */ } /* end while */ return SCPE_OK; @@ -6255,18 +6250,11 @@ t_stat show_one_mod (FILE *st, DEVICE *dptr, UNIT *uptr, MTAB *mptr, CONST char *cptr, int32 flag) { t_stat r = SCPE_OK; -//t_value val; if (mptr->disp) r = mptr->disp (st, uptr, mptr->match, (CONST void *)(cptr? cptr: mptr->desc)); -//else if ((mptr->mask & MTAB_XTD) && (mptr->mask & MTAB_VAL)) { -// REG *rptr = (REG *) mptr->desc; -// fprintf (st, "%s=", mptr->pstring); -// val = get_rval (rptr, 0); -// fprint_val (st, val, rptr->radix, rptr->width, -// rptr->flags & REG_FMT); -// } -else fputs (mptr->pstring, st); +else + fputs (mptr->pstring, st); if ((r == SCPE_OK) && (flag && !((mptr->mask & MTAB_XTD) && MODMASK(mptr,MTAB_NMO)))) fputc ('\n', st); return r; diff --git a/sim_defs.h b/sim_defs.h index a92433d..e400c6e 100644 --- a/sim_defs.h +++ b/sim_defs.h @@ -749,8 +749,8 @@ struct MTAB { t_stat (*disp)(FILE *st, UNIT *up, int32 v, CONST void *dp); /* display routine */ void *desc; /* value descriptor */ - /* REG * if MTAB_VAL */ - /* int * if not */ + /* pointer to something needed by */ + /* the validation and/or display routines */ const char *help; /* help string */ }; diff --git a/sim_fio.c b/sim_fio.c index cc43e2c..97c1c0c 100644 --- a/sim_fio.c +++ b/sim_fio.c @@ -742,6 +742,8 @@ char *fullpath = NULL, *result = NULL; char *c, *name, *ext; char chr; const char *p; +char filesizebuf[32] = ""; +char filedatetimebuf[32] = ""; if (((*filepath == '\'') || (*filepath == '"')) && (filepath[strlen (filepath) - 1] == *filepath)) { @@ -812,6 +814,20 @@ if (ext == NULL) tot_size = 0; if (*parts == '\0') /* empty part specifier means strip only quotes */ tot_size = strlen (tempfilepath); +if (strchr (parts, 't') || strchr (parts, 'z')) { + struct stat filestat; + struct tm *tm; + + memset (&filestat, 0, sizeof (filestat)); + (void)stat (fullpath, &filestat); + if (sizeof (filestat.st_size) == 4) + sprintf (filesizebuf, "%ld ", filestat.st_size); + else + sprintf (filesizebuf, "%" LL_FMT "d ", (LL_TYPE)filestat.st_size); + tm = localtime (&filestat.st_mtime); + sprintf (filedatetimebuf, "%02d/%02d/%04d %02d:%02d %cM ", 1 + tm->tm_mon, tm->tm_mday, 1900 + tm->tm_year, + tm->tm_hour % 12, tm->tm_min, (0 == (tm->tm_hour % 12)) ? 'A' : 'P'); + } for (p = parts; *p; p++) { switch (*p) { case 'f': @@ -826,6 +842,12 @@ for (p = parts; *p; p++) { case 'x': tot_size += strlen (ext); break; + case 't': + tot_size += strlen (filedatetimebuf); + break; + case 'z': + tot_size += strlen (filesizebuf); + break; } } result = (char *)malloc (1 + tot_size); @@ -852,6 +874,12 @@ for (p = parts; *p; p++) { case 'x': strlcat (result, ext, 1 + tot_size); break; + case 't': + strlcat (result, filedatetimebuf, 1 + tot_size); + break; + case 'z': + strlcat (result, filesizebuf, 1 + tot_size); + break; } } free (fullpath); diff --git a/sim_sock.c b/sim_sock.c index 858a74b..4235cea 100644 --- a/sim_sock.c +++ b/sim_sock.c @@ -1045,7 +1045,7 @@ int keepalive = 1; defined (__APPLE__) || defined (__OpenBSD__) || \ defined(__NetBSD__) || defined(__FreeBSD__) || \ (defined(__hpux) && defined(_XOPEN_SOURCE_EXTENDED)) || \ - defined (__HAIKU__) + defined (__HAIKU__) || defined(__CYGWIN__) socklen_t size; #elif defined (_WIN32) || defined (__EMX__) || \ (defined (__ALPHA) && defined (__unix__)) || \ @@ -1111,7 +1111,7 @@ struct sockaddr_storage peername; defined (__APPLE__) || defined (__OpenBSD__) || \ defined(__NetBSD__) || defined(__FreeBSD__) || \ (defined(__hpux) && defined(_XOPEN_SOURCE_EXTENDED)) || \ - defined (__HAIKU__) + defined (__HAIKU__) || defined(__CYGWIN__) socklen_t peernamesize = (socklen_t)sizeof(peername); #elif defined (_WIN32) || defined (__EMX__) || \ (defined (__ALPHA) && defined (__unix__)) || \ @@ -1147,7 +1147,7 @@ static int _sim_getaddrname (struct sockaddr *addr, size_t addrsize, char *hostn defined (__APPLE__) || defined (__OpenBSD__) || \ defined(__NetBSD__) || defined(__FreeBSD__) || \ (defined(__hpux) && defined(_XOPEN_SOURCE_EXTENDED)) || \ - defined (__HAIKU__) + defined (__HAIKU__) || defined(__CYGWIN__) socklen_t size = (socklen_t)addrsize; #elif defined (_WIN32) || defined (__EMX__) || \ (defined (__ALPHA) && defined (__unix__)) || \ @@ -1181,7 +1181,7 @@ struct sockaddr_storage sockname, peername; defined (__APPLE__) || defined (__OpenBSD__) || \ defined(__NetBSD__) || defined(__FreeBSD__) || \ (defined(__hpux) && defined(_XOPEN_SOURCE_EXTENDED)) || \ - defined (__HAIKU__) + defined (__HAIKU__) || defined(__CYGWIN__) socklen_t socknamesize = (socklen_t)sizeof(sockname); socklen_t peernamesize = (socklen_t)sizeof(peername); #elif defined (_WIN32) || defined (__EMX__) || \