Exemplo n.º 1
0
extern List *endsplit(void) {
    List *result;

    if (buffer != NULL) {
        Term *term = mkterm(sealcountedbuffer(buffer), NULL);
        value = mklist(term, value);
        buffer = NULL;
    }
    result = reverse(value);
    value = NULL;
    return result;
}
Exemplo n.º 2
0
extern void splitstring(char *in, size_t len, Boolean endword) {
    Buffer *buf = buffer;
    unsigned char *s = (unsigned char *) in, *inend = s + len;

    if (splitchars) {
        assert(buf == NULL);
        while (s < inend) {
            Term *term = mkterm(gcndup((char *) s++, 1), NULL);
            value = mklist(term, value);
        }
        return;
    }

    if (!coalesce && buf == NULL)
        buf = openbuffer(0);

    while (s < inend) {
        int c = *s++;
        if (buf != NULL)
            if (isifs[c]) {
                Term *term = mkterm(sealcountedbuffer(buf), NULL);
                value = mklist(term, value);
                buf = coalesce ? NULL : openbuffer(0);
            } else
                buf = bufputc(buf, c);
        else if (!isifs[c])
            buf = bufputc(openbuffer(0), c);
    }

    if (endword && buf != NULL) {
        Term *term = mkterm(sealcountedbuffer(buf), NULL);
        value = mklist(term, value);
        buf = NULL;
    }
    buffer = buf;
}
Exemplo n.º 3
0
/* getherevar -- read a variable from a here doc */
extern Tree *getherevar(void) {
	int c;
	char *s;
	Buffer *buf = openbuffer(0);
	while (!dnw[c = GETC()])
		buf = bufputc(buf, c);
	s = sealcountedbuffer(buf);
	if (buf->len == 0) {
		yyerror("null variable name in here document");
		return NULL;
	}
	if (c != '^')
		UNGETC(c);
	return flatten(mk(nVar, mk(nWord, s)), " ");
}
Exemplo n.º 4
0
/* snarfheredoc -- read a heredoc until the eof marker */
extern Tree *snarfheredoc(const char *eof, Boolean quoted) {
	Tree *tree, **tailp;
	Buffer *buf;
	unsigned char *s;

	assert(quoted || strchr(eof, '$') == NULL);	/* can never be typed (whew!) */
	if (strchr(eof, '\n') != NULL) {
		yyerror("here document eof-marker contains a newline");
		return NULL;
	}
	disablehistory = TRUE;

	for (tree = NULL, tailp = &tree, buf = openbuffer(0);;) {
		int c;
		print_prompt2();
		for (s = (unsigned char *) eof; (c = GETC()) == *s; s++)
			;
		if (*s == '\0' && (c == '\n' || c == EOF)) {
			if (buf->current == 0 && tree != NULL)
				freebuffer(buf);
			else
				*tailp = treecons(mk(nQword, sealcountedbuffer(buf)), NULL);
			break;
		}
		if (s != (unsigned char *) eof)
			buf = bufncat(buf, eof, s - (unsigned char *) eof);
		for (;; c = GETC()) {
			if (c == EOF) {
				yyerror("incomplete here document");
				freebuffer(buf);
				disablehistory = FALSE;
				return NULL;
			}
			if (c == '$' && !quoted && (c = GETC()) != '$') {
				Tree *var;
				UNGETC(c);
				if (buf->current == 0)
					freebuffer(buf);
				else {
					*tailp = treecons(mk(nQword, sealcountedbuffer(buf)), NULL);
					tailp = &(*tailp)->CDR;
				}
				var = getherevar();
				if (var == NULL) {
					freebuffer(buf);
					disablehistory = FALSE;
					return NULL;
				}
				*tailp = treecons(var, NULL);
				tailp = &(*tailp)->CDR;
				buf = openbuffer(0);
				continue;
			}
			buf = bufputc(buf, c);
			if (c == '\n')
				break;
		}
	}

	disablehistory = FALSE;
	return tree->CDR == NULL ? tree->CAR : tree;
}