void prependattributes(buffer *b, char *attributes) { char recipetag[RECIPETAG_STRMAX]; char *rt; char envvarname[VARNAMEMAX]; char *att; strcpy(recipetag, "<recipe "); rt = recipetag + 8; att = attributes; while (*att != '\0' && rt < &recipetag[RECIPETAG_STRMAX-1]) { if ( *att == '$' ) { int e; char *v; /* insert the value of an environent variable */ att++; e = 0; do { envvarname[e++] = *att; att++; } while ( e < (VARNAMEMAX-1) && (isalnum(*att) || *att == '_')); envvarname[e] = '\0'; /* DEBUG(("envvarname: %s\n", envvarname));*/ v = talon_getenv(envvarname); if (v) { /* DEBUG((" value: %s\n", v)); */ char *oldv=v; while (*v != '\0' && rt < &recipetag[RECIPETAG_STRMAX-1]) { *rt = *v; rt++; v++; } free(oldv); } } else { *rt = *att; rt++; att++; } } char *finish = ">\n<![CDATA[\n"; while (*finish != '\0' && rt < &recipetag[RECIPETAG_STRMAX-1]) { *rt = *finish; *rt++; finish++; } *rt = '\0'; buffer_prepend(b, recipetag, strlen(recipetag)); }
/** * call-seq: * Rev::Buffer#prepend(data) -> String * * Prepend the given data to the beginning of the buffer */ static VALUE Rev_Buffer_prepend(VALUE self, VALUE data) { struct buffer *buf; Data_Get_Struct(self, struct buffer, buf); data = rb_convert_type(data, T_STRING, "String", "to_str"); buffer_prepend(buf, RSTRING_PTR(data), RSTRING_LEN(data)); return data; }
int main(int argc, char *argv[]) { char *shell = getenv("TALON_SHELL"); char **args = malloc((argc+2)*sizeof(char *)); int i; proc *p; for (i=1; i < argc; i++) { args[i] = argv[i]; printf("arg: %s\n", args[i]); } args[argc] = NULL; if (! shell) { fprintf(stderr, "error: %s", "TALONSHELL not set in environment\n"); return 1; } args[0] = shell; p = process_run(shell, args, 4000); if (p) { buffer_prepend(p->output, "<recipe>\n<!CDATA<[[\n", 20); buffer_append(p->output, "\n]]></recipe>\n", 13); unsigned int iterator = 0; byteblock *bb; while ((bb = buffer_getbytes(p->output, &iterator))) { write(STDOUT_FILENO, &bb->byte0, bb->fill); } process_free(&p); } else { fprintf(stderr, "error: %s", "failed to run process\n"); return 1; } free(args); return 0; }
bool buffer_prepend0(Buffer *buf, const char *data) { return buffer_prepend(buf, data, strlen(data) + (buf->len == 0)); }