1
0
mirror of https://github.com/rcornwell/sims.git synced 2026-01-11 23:52:48 +00:00

SCP: Updated to current.

This commit is contained in:
Richard Cornwell 2022-03-09 21:17:00 -05:00
parent 8d49c43499
commit d1dfea8966

86
scp.c
View File

@ -2791,18 +2791,22 @@ sim_tape_init (); /* init tape package */
for (i = 0; cmd_table[i].name; i++) {
size_t alias_len = strlen (cmd_table[i].name);
char *cmd_name = (char *)calloc (1 + alias_len, sizeof (*cmd_name));
char *env_cmd_val;
size_t env_cmd_val_len;
strcpy (cmd_name, cmd_table[i].name);
while (alias_len > 1) {
cmd_name[alias_len] = '\0'; /* Possible short form command name */
--alias_len;
if (getenv (cmd_name)) { /* Externally defined command alias? */
env_cmd_val = getenv (cmd_name);
if (env_cmd_val) { /* Externally defined command alias? */
env_cmd_val_len = strlen (env_cmd_val);
++sim_external_env_count;
sim_external_env = (struct deleted_env_var *)realloc (sim_external_env, sim_external_env_count * sizeof (*sim_external_env));
sim_external_env[sim_external_env_count - 1].name = (char *)malloc (1 + strlen (cmd_name));
strcpy (sim_external_env[sim_external_env_count - 1].name, cmd_name);
sim_external_env[sim_external_env_count - 1].value = (char *)malloc (1 + strlen (getenv (cmd_name)));
strcpy (sim_external_env[sim_external_env_count - 1].value, getenv (cmd_name));
sim_external_env[sim_external_env_count - 1].value = (char *)malloc (1 + env_cmd_val_len);
strlcpy (sim_external_env[sim_external_env_count - 1].value, env_cmd_val, 1 + env_cmd_val_len);
unsetenv (cmd_name); /* Remove it to protect against possibly malicious aliases */
}
}
@ -2907,32 +2911,34 @@ if (cptr == NULL) {
else
cptr2 = NULL;
docmdp = find_cmd ("DO");
if (cptr && (sizeof (nbuf) > strlen (cptr) + strlen ("/simh.ini") + 3)) {
snprintf(nbuf, sizeof (nbuf), "\"%s%s%ssimh.ini\"", cptr2 ? cptr2 : "", cptr, strchr (cptr, '/') ? "/" : "\\");
stat = docmdp->action (-1, nbuf) & ~SCPE_NOMESSAGE; /* simh.ini proc cmd file */
}
if (SCPE_BARE_STATUS(stat) == SCPE_OPENERR)
stat = docmdp->action (-1, "simh.ini"); /* simh.ini proc cmd file */
if (*cbuf) /* cmd file arg? */
stat = docmdp->action (0, cbuf); /* proc cmd file */
else {
if (*argv[0]) { /* sim name arg? */
char *np; /* "path.ini" */
nbuf[0] = '"'; /* starting " */
strlcpy (nbuf + 1, argv[0], PATH_MAX + 2); /* copy sim name */
if ((np = (char *)match_ext (nbuf, "EXE"))) /* remove .exe */
*np = 0;
strlcat (nbuf, ".ini\"", sizeof (nbuf)); /* add .ini" */
stat = docmdp->action (-1, nbuf) & ~SCPE_NOMESSAGE; /* proc default cmd file */
if (stat == SCPE_OPENERR) { /* didn't exist/can't open? */
np = strrchr (nbuf, '/'); /* stript path and try again in cwd */
if (np == NULL)
np = strrchr (nbuf, '\\'); /* windows path separator */
if (np == NULL)
np = strrchr (nbuf, ']'); /* VMS path separator */
if (np != NULL) {
*np = '"';
stat = docmdp->action (-1, np) & ~SCPE_NOMESSAGE;/* proc default cmd file */
if (docmdp) {
if (cptr && (sizeof (nbuf) > strlen (cptr) + strlen ("/simh.ini") + 3)) {
snprintf(nbuf, sizeof (nbuf), "\"%s%s%ssimh.ini\"", cptr2 ? cptr2 : "", cptr, strchr (cptr, '/') ? "/" : "\\");
stat = docmdp->action (-1, nbuf); /* simh.ini proc cmd file */
}
if (SCPE_BARE_STATUS(stat) == SCPE_OPENERR)
stat = docmdp->action (-1, "simh.ini"); /* simh.ini proc cmd file */
if (*cbuf) /* cmd file arg? */
stat = docmdp->action (0, cbuf); /* proc cmd file */
else {
if (*argv[0]) { /* sim name arg? */
char *np; /* "path.ini" */
nbuf[0] = '"'; /* starting " */
strlcpy (nbuf + 1, argv[0], PATH_MAX + 2); /* copy sim name */
if ((np = (char *)match_ext (nbuf, "EXE"))) /* remove .exe */
*np = 0;
strlcat (nbuf, ".ini\"", sizeof (nbuf)); /* add .ini" */
stat = docmdp->action (-1, nbuf) & ~SCPE_NOMESSAGE; /* proc default cmd file */
if (stat == SCPE_OPENERR) { /* didn't exist/can't open? */
np = strrchr (nbuf, '/'); /* stript path and try again in cwd */
if (np == NULL)
np = strrchr (nbuf, '\\'); /* windows path separator */
if (np == NULL)
np = strrchr (nbuf, ']'); /* VMS path separator */
if (np != NULL) {
*np = '"';
stat = docmdp->action (-1, np) & ~SCPE_NOMESSAGE;/* proc default cmd file */
}
}
}
}
@ -4297,24 +4303,26 @@ t_stat sim_call_argv (int (*main_like_routine)(int argc, char *argv[]), const ch
{
int argc = 1;
char **argv = (char **)calloc ((1 + argc), sizeof (*argv));
size_t cptr_len = strlen (cptr);
char *argline = (char *)malloc (2 + 2 * cptr_len);
size_t arg_size;
char *argline = NULL;
char *cp, quote;
t_stat result = SCPE_OK;
if ((argv == NULL) || (argline == NULL)) {
free (argv);
free (argline);
return SCPE_MEM;
}
if (cptr == NULL) {
free (argv);
free (argline);
return SCPE_ARG;
}
strcpy (argline, cptr);
cp = argline + cptr_len + 1;
strcpy (cp, cptr);
arg_size = 2 + (2 * strlen (cptr));
argline = (char *)malloc (arg_size);
if ((argv == NULL) || (argline == NULL)) {
free (argv);
free (argline);
return SCPE_MEM;
}
strlcpy (argline, cptr, arg_size);
cp = argline + (arg_size / 2);
strlcpy (cp, cptr, arg_size / 2);
argv[0] = argline; /* argv[0] points to unparsed arguments */
argv[argc + 1] = NULL; /* make sure the argument list always ends with a NULL */
while (*cp) {