1
0
mirror of https://github.com/rcornwell/sims.git synced 2026-04-03 12:22:52 +00:00

SCP: Updated to current.

This commit is contained in:
Richard Cornwell
2020-01-03 17:06:53 -05:00
parent 6ed7b3add1
commit 81cf803a85
9 changed files with 85 additions and 68 deletions

68
scp.c
View File

@@ -451,6 +451,7 @@ t_addr (*sim_vm_parse_addr) (DEVICE *dptr, CONST char *cptr, CONST char **tptr)
t_value (*sim_vm_pc_value) (void) = NULL;
t_bool (*sim_vm_is_subroutine_call) (t_addr **ret_addrs) = NULL;
t_bool (*sim_vm_fprint_stopped) (FILE *st, t_stat reason) = NULL;
const char *sim_vm_release = NULL;
const char **sim_clock_precalibrate_commands = NULL;
@@ -563,6 +564,7 @@ static t_stat _sim_debug_flush (void);
/* Global data */
const char *sim_prog_name = NULL; /* pointer to the executable name */
DEVICE *sim_dflt_dev = NULL;
UNIT *sim_clock_queue = QUEUE_LIST_END;
int32 sim_interval = 0;
@@ -2546,6 +2548,7 @@ set_prompt (0, "sim>"); /* start with set standa
sim_switches = 0; /* init switches */
lookswitch = TRUE;
stdnul = fopen(NULL_DEVICE,"wb");
sim_prog_name = argv [0]; /* save a pointer to the program name */
for (i = 1; i < argc; i++) { /* loop thru args */
if (argv[i] == NULL) /* paranoia */
continue;
@@ -2630,10 +2633,8 @@ if (!sim_quiet) {
}
sim_timer_precalibrate_execution_rate ();
show_version (stdnul, NULL, NULL, 1, NULL); /* Quietly set SIM_OSTYPE */
#if defined (HAVE_PCREPOSIX_H)
setenv ("SIM_REGEX_TYPE", "PCREPOSIX", 1); /* Publish regex type */
#elif defined (HAVE_REGEX_H)
setenv ("SIM_REGEX_TYPE", "REGEX", 1); /* Publish regex type */
#if defined (HAVE_PCRE_H)
setenv ("SIM_REGEX_TYPE", "PCRE", 1); /* Publish regex type */
#endif
if (*argv[0]) { /* sim name arg? */
char *np; /* "path.ini" */
@@ -5803,6 +5804,10 @@ setenv ("SIM_MINOR", vmin_s, 1);
sprintf (vpat_s, "%d", vpat);
setenv ("SIM_PATCH", vpat_s, 1);
fprintf (st, "%s simulator V%d.%d-%d", sim_name, vmaj, vmin, vpat);
if (sim_vm_release != NULL) { /* if a release string is defined */
setenv ("SIM_VM_RELEASE", sim_vm_release, 1);
fprintf (st, " Release %s", sim_vm_release); /* then display it */
}
if (vdelt) {
sprintf (vdelt_s, "%d", vdelt);
setenv ("SIM_DELTA", vdelt_s, 1);
@@ -11899,7 +11904,7 @@ free (ep->match_pattern); /* deallocate the displa
free (ep->act); /* deallocate action */
#if defined(USE_REGEX)
if (ep->switches & EXP_TYP_REGEX)
regfree (&ep->regex); /* release compiled regex */
pcre_free (ep->regex); /* release compiled regex */
#endif
exp->size -= 1; /* decrement count */
for (i=ep-exp->rules; i<exp->size; i++) /* shuffle up remaining rules */
@@ -11934,7 +11939,7 @@ for (i=0; i<exp->size; i++) {
free (exp->rules[i].act); /* deallocate action */
#if defined(USE_REGEX)
if (exp->rules[i].switches & EXP_TYP_REGEX)
regfree (&exp->rules[i].regex); /* release compiled regex */
pcre_free (exp->rules[i].regex); /* release compiled regex */
#endif
}
free (exp->rules);
@@ -11966,25 +11971,21 @@ if (switches & EXP_TYP_REGEX) {
return sim_messagef (SCPE_ARG, "RegEx support not available\n");
}
#else /* USE_REGEX */
int res;
regex_t re;
pcre *re;
const char *errmsg;
int erroffset, re_nsub;
memset (&re, 0, sizeof(re));
memcpy (match_buf, match+1, strlen(match)-2); /* extract string without surrounding quotes */
match_buf[strlen(match)-2] = '\0';
res = regcomp (&re, (char *)match_buf, REG_EXTENDED | ((switches & EXP_TYP_REGEX_I) ? REG_ICASE : 0));
if (res) {
size_t err_size = regerror (res, &re, NULL, 0);
char *err_buf = (char *)calloc (err_size+1, 1);
regerror (res, &re, err_buf, err_size);
sim_messagef (SCPE_ARG, "Regular Expression Error: %s\n", err_buf);
free (err_buf);
re = pcre_compile (match_buf, (switches & EXP_TYP_REGEX_I) ? PCRE_CASELESS : 0, &errmsg, &erroffset, NULL);
if (re == NULL) {
sim_messagef (SCPE_ARG, "Regular Expression Error: %s\n", errmsg);
free (match_buf);
return SCPE_ARG|SCPE_NOMESSAGE;
}
sim_debug (exp->dbit, exp->dptr, "Expect Regular Expression: \"%s\" has %d sub expressions\n", match_buf, (int)re.re_nsub);
regfree (&re);
(void)pcre_fullinfo(re, NULL, PCRE_INFO_CAPTURECOUNT, &re_nsub);
sim_debug (exp->dbit, exp->dptr, "Expect Regular Expression: \"%s\" has %d sub expressions\n", match_buf, re_nsub);
pcre_free (re);
}
#endif
else {
@@ -12024,9 +12025,13 @@ if ((match_buf == NULL) || (ep->match_pattern == NULL)) {
}
if (switches & EXP_TYP_REGEX) {
#if defined(USE_REGEX)
const char *errmsg;
int erroffset;
memcpy (match_buf, match+1, strlen(match)-2); /* extract string without surrounding quotes */
match_buf[strlen(match)-2] = '\0';
regcomp (&ep->regex, (char *)match_buf, REG_EXTENDED);
ep->regex = pcre_compile ((char *)match_buf, (switches & EXP_TYP_REGEX_I) ? PCRE_CASELESS : 0, &errmsg, &erroffset, NULL);
(void)pcre_fullinfo(ep->regex, NULL, PCRE_INFO_CAPTURECOUNT, &ep->re_nsub);
#endif
free (match_buf);
match_buf = NULL;
@@ -12161,7 +12166,8 @@ for (i=0; i < exp->size; i++) {
ep = &exp->rules[i];
if (ep->switches & EXP_TYP_REGEX) {
#if defined (USE_REGEX)
regmatch_t *matches;
int *ovector = NULL;
int rc;
char *cbuf = (char *)exp->buf;
static size_t sim_exp_match_sub_count = 0;
@@ -12179,23 +12185,24 @@ for (i=0; i < exp->size; i++) {
}
}
++regex_checks;
matches = (regmatch_t *)calloc ((ep->regex.re_nsub + 1), sizeof(*matches));
ovector = (int *)malloc (3 * (ep->re_nsub + 1) * sizeof (*ovector));
if (sim_deb && exp->dptr && (exp->dptr->dctrl & exp->dbit)) {
char *estr = sim_encode_quoted_string (exp->buf, exp->buf_ins);
sim_debug (exp->dbit, exp->dptr, "Checking String: %s\n", estr);
sim_debug (exp->dbit, exp->dptr, "Against RegEx Match Rule: %s\n", ep->match_pattern);
free (estr);
}
if (!regexec (&ep->regex, cbuf, ep->regex.re_nsub + 1, matches, REG_NOTBOL)) {
rc = pcre_exec (ep->regex, NULL, cbuf, exp->buf_ins, 0, PCRE_NOTBOL, ovector, 3 * (ep->re_nsub + 1));
if (rc >= 0) {
size_t j;
char *buf = (char *)malloc (1 + exp->buf_ins);
for (j=0; j<ep->regex.re_nsub + 1; j++) {
for (j=0; j < (size_t)rc; j++) {
char env_name[32];
sprintf (env_name, "_EXPECT_MATCH_GROUP_%d", (int)j);
memcpy (buf, &cbuf[matches[j].rm_so], matches[j].rm_eo-matches[j].rm_so);
buf[matches[j].rm_eo-matches[j].rm_so] = '\0';
memcpy (buf, &cbuf[ovector[2 * j]], ovector[2 * j + 1] - ovector[2 * j]);
buf[ovector[2 * j + 1] - ovector[2 * j]] = '\0';
setenv (env_name, buf, 1); /* Make the match and substrings available as environment variables */
sim_debug (exp->dbit, exp->dptr, "%s=%s\n", env_name, buf);
}
@@ -12205,12 +12212,13 @@ for (i=0; i < exp->size; i++) {
sprintf (env_name, "_EXPECT_MATCH_GROUP_%d", (int)j);
setenv (env_name, "", 1); /* Remove previous extra environment variables */
}
sim_exp_match_sub_count = ep->regex.re_nsub;
free (matches);
sim_exp_match_sub_count = ep->re_nsub;
free (ovector);
ovector = NULL;
free (buf);
break;
}
free (matches);
free (ovector);
#endif
}
else {
@@ -13611,7 +13619,7 @@ rewind (tmp);
/* Discard leading blank lines/redundant titles */
for (i =0; i < skiplines; i++)
fgets (tbuf, sizeof (tbuf), tmp);
if (fgets (tbuf, sizeof (tbuf), tmp)) {};
while (fgets (tbuf, sizeof (tbuf), tmp)) {
if (tbuf[0] != '\n')

4
scp.h
View File

@@ -388,7 +388,8 @@ extern uint32 sim_brk_dflt;
extern uint32 sim_brk_summ;
extern uint32 sim_brk_match_type;
extern t_addr sim_brk_match_addr;
extern BRKTYPTAB *sim_brk_type_desc; /* type descriptions */
extern BRKTYPTAB *sim_brk_type_desc; /* type descriptions */
extern const char *sim_prog_name; /* executable program name */
extern FILE *stdnul;
extern t_bool sim_asynch_enabled;
#if defined(SIM_ASYNCH_IO)
@@ -399,6 +400,7 @@ void sim_aio_activate (ACTIVATE_API caller, UNIT *uptr, int32 event_time);
/* VM interface */
extern char sim_name[64];
extern const char *sim_vm_release;
extern DEVICE *sim_devices[];
extern REG *sim_PC;
extern const char *sim_stop_messages[SCPE_BASE];

View File

@@ -172,7 +172,7 @@ unsigned int checksum = 0;
char *c;
int i;
char cleaned_rom_filename[512];
char include_filename[512];
char *include_filename;
char array_name[512];
if (NULL == (rFile = fopen (rom_filename, "rb"))) {
@@ -207,15 +207,16 @@ if ((c = strchr (array_name, '.')))
*c = '_';
if ((c = strchr (array_name, '/')))
*c = '_';
include_filename[sizeof (include_filename) - 1] = '\0';
snprintf (include_filename, sizeof (include_filename) - 1, "%s.h", cleaned_rom_filename);
include_filename = (char *)calloc (3 + strlen (cleaned_rom_filename), sizeof (*include_filename));
sprintf (include_filename, "%s.h", cleaned_rom_filename);
if ((c = strrchr (include_filename, '/')))
sprintf (c+1, "%s.h", array_name);
else
snprintf (include_filename, sizeof (include_filename) - 1, "%s.h", array_name);
sprintf (include_filename, "%s.h", array_name);
printf ("The ROMs array entry for this new ROM image file should look something like:\n");
printf ("{\"%s\", \"%s\", %d, 0x%08X, \"%s\"}\n",
rom_filename, include_filename, (int)(statb.st_size), checksum, array_name);
free (include_filename);
free (ROMData);
return 1;
}

View File

@@ -1318,7 +1318,7 @@ sim_card_attach(UNIT * uptr, CONST char *cptr)
sprintf (uptr->filename, "%s-F %s %s", (eof)?"-E ": "", fmt, cptr);
}
r = sim_messagef(SCPE_OK, "%s: %d card Deck Loaded from %s\n",
sim_uname(uptr), data->hopper_cards - previous_cards, cptr);
sim_uname(uptr), (int)(data->hopper_cards - previous_cards), cptr);
} else {
if (uptr->dynflags & UNIT_ATTMULT)
uptr->flags |= UNIT_ATT;
@@ -1430,22 +1430,22 @@ sprintf (cmd, "%s -S -E File40.deck", dptr->name);
SIM_TEST(attach_cmd (0, cmd));
sprintf (saved_filename, "%s %s", dptr->name, dptr->units->filename);
show_cmd (0, dptr->name);
sim_printf ("Input Hopper Count: %d\n", sim_card_input_hopper_count(dptr->units));
sim_printf ("Output Hopper Count: %d\n", sim_card_output_hopper_count(dptr->units));
sim_printf ("Input Hopper Count: %d\n", (int)sim_card_input_hopper_count(dptr->units));
sim_printf ("Output Hopper Count: %d\n", (int)sim_card_output_hopper_count(dptr->units));
while (!sim_card_eof (dptr->units))
SIM_TEST(sim_read_card (dptr->units, card_image));
sim_printf ("Input Hopper Count: %d\n", sim_card_input_hopper_count(dptr->units));
sim_printf ("Output Hopper Count: %d\n", sim_card_output_hopper_count(dptr->units));
sim_printf ("Input Hopper Count: %d\n", (int)sim_card_input_hopper_count(dptr->units));
sim_printf ("Output Hopper Count: %d\n", (int)sim_card_output_hopper_count(dptr->units));
sim_printf ("Detaching %s\n", dptr->name);
SIM_TEST(detach_cmd (0, dptr->name));
show_cmd (0, dptr->name);
sim_printf ("Input Hopper Count: %d\n", sim_card_input_hopper_count(dptr->units));
sim_printf ("Output Hopper Count: %d\n", sim_card_output_hopper_count(dptr->units));
sim_printf ("Input Hopper Count: %d\n", (int)sim_card_input_hopper_count(dptr->units));
sim_printf ("Output Hopper Count: %d\n", (int)sim_card_output_hopper_count(dptr->units));
sim_printf ("Attaching Saved Filenames: %s\n", saved_filename + strlen(dptr->name));
SIM_TEST(attach_cmd (0, saved_filename));
show_cmd (0, dptr->name);
sim_printf ("Input Hopper Count: %d\n", sim_card_input_hopper_count(dptr->units));
sim_printf ("Output Hopper Count: %d\n", sim_card_output_hopper_count(dptr->units));
sim_printf ("Input Hopper Count: %d\n", (int)sim_card_input_hopper_count(dptr->units));
sim_printf ("Output Hopper Count: %d\n", (int)sim_card_output_hopper_count(dptr->units));
SIM_TEST(detach_cmd (0, dptr->name));
(void)remove ("file10.deck");
(void)remove ("file20.deck");

View File

@@ -437,7 +437,7 @@ if (*cptr == 0) { /* show all */
while (*cptr != 0) {
cptr = get_glyph (cptr, gbuf, ','); /* get modifier */
if ((shptr = find_shtab (show_con_tab, gbuf)))
shptr->action (st, dptr, uptr, shptr->arg, cptr);
shptr->action (st, dptr, uptr, shptr->arg, NULL);
else return SCPE_NOPARAM;
}
return SCPE_OK;
@@ -4219,7 +4219,7 @@ static t_stat sim_os_putchar (int32 out)
char c;
c = out;
(void)write (1, &c, 1);
if (write (1, &c, 1)) {};
return SCPE_OK;
}

View File

@@ -146,13 +146,9 @@ extern int sim_vax_snprintf(char *buf, size_t buf_size, const char *fmt, ...);
#ifdef USE_REGEX
#undef USE_REGEX
#endif
#if defined(HAVE_PCREPOSIX_H)
#include <pcreposix.h>
#if defined(HAVE_PCRE_H)
#include <pcre.h>
#define USE_REGEX 1
#elif defined(HAVE_REGEX_H)
#include <regex.h>
#define USE_REGEX 1
#endif
#ifdef __cplusplus
@@ -818,7 +814,8 @@ struct EXPTAB {
#define EXP_TYP_REGEX_I (SWMASK ('I')) /* regular expression pattern matching should be case independent */
#define EXP_TYP_TIME (SWMASK ('T')) /* halt delay is in microseconds instead of instructions */
#if defined(USE_REGEX)
regex_t regex; /* compiled regular expression */
pcre *regex; /* compiled regular expression */
int re_nsub; /* regular expression sub expression count */
#endif
char *act; /* action string */
};

View File

@@ -417,7 +417,7 @@ t_stat eth_mac_scan_ex (ETH_MAC* mac, const char* strmac, UNIT *uptr)
memset (&state, 0, sizeof(state));
_eth_get_system_id (state.system_id, sizeof(state.system_id));
strlcpy (state.sim, sim_name, sizeof(state.sim));
getcwd (state.cwd, sizeof(state.cwd));
if (getcwd (state.cwd, sizeof(state.cwd))) {};
if (uptr)
strlcpy (state.uname, sim_uname (uptr), sizeof(state.uname));
cptr = strchr (strmac, '>');
@@ -426,7 +426,7 @@ t_stat eth_mac_scan_ex (ETH_MAC* mac, const char* strmac, UNIT *uptr)
strlcpy (state.file, cptr + 1, sizeof(state.file));
if ((f = fopen (state.file, "r"))) {
filebuf[sizeof(filebuf)-1] = '\0';
fgets (filebuf, sizeof(filebuf)-1, f);
if (fgets (filebuf, sizeof(filebuf)-1, f)) {};
strmac = filebuf;
fclose (f);
strcpy (state.file, ""); /* avoid saving */
@@ -1573,10 +1573,10 @@ static void eth_get_nic_hw_addr(ETH_DEV* dev, const char *devname)
memset(command, 0, sizeof(command));
/* try to force an otherwise unused interface to be turned on */
snprintf(command, sizeof(command)-1, "ifconfig %.*s up", (int)(sizeof(command) - 14), devname);
(void)system(command);
if (system(command)) {};
for (i=0; patterns[i] && (0 == dev->have_host_nic_phy_addr); ++i) {
snprintf(command, sizeof(command)-1, "ifconfig %.*s | %s >NIC.hwaddr", (int)(sizeof(command) - (26 + strlen(patterns[i]))), devname, patterns[i]);
(void)system(command);
if (system(command)) {};
if (NULL != (f = fopen("NIC.hwaddr", "r"))) {
while (0 == dev->have_host_nic_phy_addr) {
if (fgets(command, sizeof(command)-1, f)) {
@@ -1662,12 +1662,12 @@ FILE *f;
memset (buf, 0, buf_size);
if ((f = fopen ("/etc/machine-id", "r"))) {
fread (buf, 1, buf_size, f);
if (fread (buf, 1, buf_size - 1, f)) {};
fclose (f);
}
else {
if ((f = popen ("hostname", "r"))) {
fread (buf, 1, buf_size, f);
if (fread (buf, 1, buf_size - 1, f)) {};
pclose (f);
}
}
@@ -2165,7 +2165,7 @@ else { /* !tap: */
/* try to force an otherwise unused interface to be turned on */
memset(command, 0, sizeof(command));
snprintf(command, sizeof(command)-1, "ifconfig %s up", savname);
(void)system(command);
if (system(command)) {};
errbuf[0] = '\0';
*handle = (void*) pcap_open_live(savname, bufsz, ETH_PROMISC, PCAP_READ_TIMEOUT, errbuf);
}

View File

@@ -953,6 +953,7 @@ glob_t paths;
#else
DIR *dir;
#endif
int found_count = 0;
struct stat filestat;
char *c;
char DirName[PATH_MAX + 1], WholeName[PATH_MAX + 1], WildName[PATH_MAX + 1];
@@ -982,7 +983,7 @@ if (dir) {
struct dirent *ent;
#endif
t_offset FileSize;
char FileName[PATH_MAX + 1];
char *FileName;
const char *MatchName = 1 + strrchr (cptr, '/');
char *p_name;
struct tm *local;
@@ -992,24 +993,29 @@ if (dir) {
#if defined (HAVE_GLOB)
for (i=0; i<paths.gl_pathc; i++) {
FileName = (char *)malloc (1 + strlen (paths.gl_pathv[i]));
sprintf (FileName, "%s", paths.gl_pathv[i]);
#else
#else /* !defined (HAVE_GLOB) */
while ((ent = readdir (dir))) {
#if defined (HAVE_FNMATCH)
if (fnmatch(MatchName, ent->d_name, 0))
continue;
#else
/* only match exact name without fnmatch support */
if (strcmp(MatchName, ent->d_name) != 0)
#else /* !defined (HAVE_FNMATCH) */
/* only match all names or exact name without fnmatch support */
if ((strcmp(MatchName, "*") != 0) &&
(strcmp(MatchName, ent->d_name) != 0))
continue;
#endif
#endif /* defined (HAVE_FNMATCH) */
FileName = (char *)malloc (1 + strlen (DirName) + strlen (ent->d_name));
sprintf (FileName, "%s%s", DirName, ent->d_name);
#endif
#endif /* defined (HAVE_GLOB) */
p_name = FileName + strlen (DirName);
memset (&filestat, 0, sizeof (filestat));
(void)stat (FileName, &filestat);
FileSize = (t_offset)((filestat.st_mode & S_IFDIR) ? 0 : sim_fsize_name_ex (FileName));
entry (DirName, p_name, FileSize, &filestat, context);
free (FileName);
++found_count;
}
#if defined (HAVE_GLOB)
globfree (&paths);
@@ -1019,6 +1025,9 @@ if (dir) {
}
else
return SCPE_ARG;
return SCPE_OK;
if (found_count)
return SCPE_OK;
else
return SCPE_ARG;
}
#endif /* !defined(_WIN32) */

View File

@@ -867,7 +867,7 @@ if (!simulator_panel) {
p->pidProcess = fork();
if (p->pidProcess == 0) {
close (0); close (1); close (2); /* make sure not to pass the open standard handles */
dup (dup (open ("/dev/null", O_RDWR))); /* open standard handles to /dev/null */
if (dup (dup (open ("/dev/null", O_RDWR)))) {}; /* open standard handles to /dev/null */
if (execlp (sim_path, sim_path, p->temp_config, NULL, NULL)) {
perror ("execl");
exit(errno);