fz_error * fz_openwbuffer(fz_stream **stmp, fz_buffer *buf) { fz_error *error; error = openbuffer(stmp, buf, FZ_SWRITE); if (error) return fz_rethrow(error, "cannot create writing buffer stream"); return fz_okay; }
fz_error * fz_openrbuffer(fz_stream **stmp, fz_buffer *buf) { fz_error *error; error = openbuffer(stmp, buf, FZ_SREAD); if (error) return fz_rethrow(error, "cannot create reading buffer stream"); return fz_okay; }
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; }
/* 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)), " "); }
/* strv -- print a formatted string into gc space */ extern char *strv(const char *fmt, va_list args) { Buffer *buf; Format format; gcdisable(0); buf = openbuffer(0); format.u.p = buf; format.args = args; format.buf = buf->str; format.bufbegin = buf->str; format.bufend = buf->str + buf->len; format.grow = str_grow; format.flushed = 0; printfmt(&format, fmt); fmtputc(&format, '\0'); gcenable(); return sealbuffer(format.u.p); }
/* 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; }