1 #include "asn1c_internal.h"
5 * Add an elementary chunk of target language text
6 * into appropriate output stream.
9 asn1c_compiled_output(arg_t *arg, const char *source, int lineno, const char *func, const char *fmt,
11 struct compiler_stream_destination_s *dst;
18 switch(arg->target->target) {
22 dst = &arg->target->destination[arg->target->target];
27 * Make sure the output has a single LF and only at the end.
29 for(lf_found = 0, p = fmt; *p; p++) {
35 assert(lf_found <= 1);
38 * Print out the indentation.
40 if(dst->indented == 0) {
41 int i = dst->indent_level;
44 fprintf(stderr, "target %d : Indent level %d ?!\n", arg->target->target, i);
49 ret = asn1c_compiled_output(arg, source, lineno, func, "\t");
50 if(ret == -1) return -1;
56 size_t debug_reserve_size = 0;
57 if(lf_found && (arg->flags & A1C_DEBUG_OUTPUT_ORIGIN_LINES)) {
59 sizeof("\t// :100000 ()") + strlen(source) + strlen(func);
65 m = calloc(1, sizeof(out_chunk_t));
66 if(m == NULL) return -1;
72 tmp = realloc(m->buf, m->len + debug_reserve_size);
81 ret = vsnprintf(m->buf, m->len, fmt, ap);
83 } while(ret >= (m->len - 1) || ret < 0);
87 /* Print out the origin of the lines */
88 if(lf_found && (arg->flags & A1C_DEBUG_OUTPUT_ORIGIN_LINES)) {
89 assert(m->buf[m->len - 1] == '\n');
90 ret = snprintf(m->buf + m->len - 1, debug_reserve_size,
91 "\t// %s:%03d %s()\n", source, lineno, func);
92 assert(ret > 0 && (size_t)ret < debug_reserve_size);
93 m->len = m->len - 1 + ret;
96 if(arg->target->target == OT_INCLUDES
97 || arg->target->target == OT_FWD_DECLS
98 || arg->target->target == OT_POST_INCLUDE) {
100 TQ_FOR(v, &dst->chunks, next) {
102 && !memcmp(m->buf, v->buf, m->len))
106 /* Entry is already present. Skip it. */
113 TQ_ADD(&dst->chunks, m, next);