IBM1130: more robust detection of SCP command files dropped into GUI
as discussed in #456
This commit is contained in:
parent
d9cc6636d4
commit
1cf4f7795a
1 changed files with 12 additions and 1 deletions
|
@ -1438,19 +1438,30 @@ static BOOL is_scp_file(const char *filename)
|
||||||
FILE *f = fopen(filename, "r");
|
FILE *f = fopen(filename, "r");
|
||||||
int lines = 0, comment_lines = 0;
|
int lines = 0, comment_lines = 0;
|
||||||
BOOL result = TRUE;
|
BOOL result = TRUE;
|
||||||
|
size_t i;
|
||||||
|
|
||||||
if (!f)
|
if (!f)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
while (1) {
|
while (result) {
|
||||||
CONST char *cptr;
|
CONST char *cptr;
|
||||||
|
|
||||||
cptr = fgets(cbuf, sizeof(cbuf), f);
|
cptr = fgets(cbuf, sizeof(cbuf), f);
|
||||||
if (cptr == NULL)
|
if (cptr == NULL)
|
||||||
break;
|
break;
|
||||||
|
if (strlen(cptr) == sizeof(cbuf)-1) /* VERY long lines are not SCP commands */
|
||||||
|
result = FALSE;
|
||||||
|
if (!strchr(cptr, '\n')) /* lines without newlines are not SCP commands */
|
||||||
|
result = FALSE;
|
||||||
|
if (!memcmp(cptr,"!// ", 4)) /* indirect deck file literals are not SCP commands */
|
||||||
|
result = FALSE;
|
||||||
cptr = sim_trim_endspc(cbuf);
|
cptr = sim_trim_endspc(cbuf);
|
||||||
while (sim_isspace (*cptr)) /* trim leading space */
|
while (sim_isspace (*cptr)) /* trim leading space */
|
||||||
cptr++;
|
cptr++;
|
||||||
++lines;
|
++lines;
|
||||||
|
for (i = 0; i < strlen(cptr); i++)
|
||||||
|
if ((cptr[i] & 0x80) ||
|
||||||
|
((!isprint(cptr[i])) && (!isspace(cptr[i]))))
|
||||||
|
result = FALSE; /* SCP files only have printable ASCII */
|
||||||
if ((*cptr == ';') || (*cptr == '#')) { /* ignore comments */
|
if ((*cptr == ';') || (*cptr == '#')) { /* ignore comments */
|
||||||
++comment_lines;
|
++comment_lines;
|
||||||
continue;
|
continue;
|
||||||
|
|
Loading…
Add table
Reference in a new issue