Separate out the string parsing for .include/.library file names and macro arguments.

They behave observably different from generic string parsing and trying
to account for them generically just gets in the way.
.rept is treated the same as a macro.
This commit is contained in:
Olaf Seibert
2015-05-22 16:36:16 +02:00
parent 536d1856f0
commit 435cdb0b7f
6 changed files with 114 additions and 36 deletions

52
parse.c
View File

@@ -77,6 +77,49 @@ char *getstring(
return str;
}
/* Parses a string from the input stream for .include and .library.
* These have a special kind of delimiters. It likes
* .include /name/ ?name? \name\ "name"
* but not
* .include ^/name/ <name> name =name= :name:
* .include :name: seems to be silently ignored.
*/
char *getstring_fn(
char *cp,
char **endp)
{
char endstr[4];
int len;
char *str;
switch (*cp) {
case '<':
case '=':
case ':':
return NULL;
}
if (!ispunct(*cp)) {
return NULL;
}
endstr[0] = *cp;
endstr[1] = '\n';
endstr[2] = '\0';
cp++;
len = strcspn(cp, endstr);
if (endp)
*endp = cp + len + 1;
str = memcheck(malloc(len + 1));
memcpy(str, cp, len);
str[len] = 0;
return str;
}
/* Get what would be the operation code from the line. */
/* Used to find the ends of streams without evaluating them, like
finding the closing .ENDM on a macro definition */
@@ -584,15 +627,6 @@ int brackrange(
endlen = 1;
*start = 1;
break;
case '/': /* seen on page 6-52 */
case '?': /* seen on page 6-52 */
case '\\': /* seen on page 6-52 */
case '"': /* seen in Kermit-11 source for RT11 */
endstr[0] = cp[0];
strcpy(endstr + 1, "\n");
*start = 1;
endlen = 1;
break;
default:
return FALSE;
}