/* Append an input line to a String.
*
* Empty lines and leading whitespace are removed.
*/
static char *
rdline(Biobuf *fp, String *to)
{
int c;
int len = 0;
c = Bgetc(fp);
/* eat leading white */
while(c==' ' || c=='\t' || c=='\n' || c=='\r')
c = Bgetc(fp);
if(c < 0)
return 0;
for(;;){
switch(c) {
case -1:
goto out;
case '\\':
c = Bgetc(fp);
if (c != '\n') {
s_putc(to, '\\');
s_putc(to, c);
len += 2;
}
break;
case '\r':
break;
case '\n':
if(len != 0)
goto out;
break;
default:
s_putc(to, c);
len++;
break;
}
c = Bgetc(fp);
}
out:
s_terminate(to);
return to->ptr - len;
}
/* Append an input line to a String.
*
* Returns a pointer to the character string (or 0).
* Leading whitespace and newlines are removed.
* Lines starting with #include cause us to descend into the new file.
* Empty lines and other lines starting with '#' are ignored.
*/
extern char *
s_rdinstack(Sinstack *sp, String *to)
{
char *p;
Biobuf *fp, *nfp;