The wrapped up example code is:
static int merge_sets(struct x1f4_function_type **set) { int status = 0; struct x1f4_function_type *function_data; unsigned count, trans; x1f4_count_functions(x1f4_e4_defaults, &count); x1f4_count_functions(simple_output, &trans); function_data = (struct x1f4_function_type *) malloc((count + trans + 1) * sizeof(struct x1f4_function_type)); if (!function_data) { status = 1; } else { *set = function_data; memcpy(function_data, x1f4_e4_defaults, count * sizeof(struct x1f4_function_type)); function_data += count; memcpy(function_data, _libx1f4i0_e4_io, (trans + 1) * sizeof(struct x1f4_function_type)); } return status; } static int select_function(const char *f, unsigned length, const void *context, const struct x1f4_function_type **function) { int status = X1f4_E4_PARSE_ERROR; const struct x1f4_function_type *function_data; function_data = context; if (function_data) { while (function_data->name) { if (length == function_data->length && !memcmp((void *) f, function_data->name, length)) { break; } function_data++; } if (function_data->name) { status = 0; *function = function_data; } } return status; } static int test_cast(void *cast, const char *name, unsigned size) { return 1 ^ fwrite(name, size, 1, cast); } ... struct x1f4_function_type *function_data; if (merge_sets(&function_data)) { ... } else { struct x1f4_a1_type a1; struct x1f4_a1record_type a1record; void *program; a1.bcollect_set.a1record_data = &a1record; a1.function_set.get = select_function; a1.function_set.context = function_data; x1f4_llink_operator1s(&a1.operator1s); x1f4_llink_operator2s(&a1.operator2s); a1.variable_set.context = NULL; status = x1f4_init_shuffle(&program, data, X1f4_A1_BCOLLECT, &a1); if (status) { if (status == X1f4_A1_ALLOC_ERROR) { perror(argv[0]); } else { fprintf(stderr, "%s: cannot parse `%s'\n", argv[0], ...); fprintf(stderr, "%s: ", argv[0]); x1f4_stat_shuffle(stderr, test_cast, data, &a1record, NULL); fprintf(stderr, "\n"); } } else { status = x1f4_link_shuffle(program, NULL); if (status) { fprintf(stderr, "%s: cannot execute `%s'\n", argv[0], ...); } x1f4_fini_shuffle(&program); } free(function_data); }
Standard output printing functions set code is to be added.