int write_objects(FILE *fp) { F_arc *a; F_compound *c; F_ellipse *e; F_line *l; F_spline *s; F_text *t; /* * A 2 for the orientation means that the origin (0,0) is at the upper * left corner of the screen (2nd quadrant). */ if (!update_figs) put_msg("Writing . . ."); #ifdef I18N /* set the numeric locale to C so we get decimal points for numbers */ setlocale(LC_NUMERIC, "C"); #endif /* I18N */ write_fig_header(fp); for (a = objects.arcs; a != NULL; a = a->next) { num_object++; write_arc(fp, a); } for (c = objects.compounds; c != NULL; c = c->next) { num_object++; write_compound(fp, c); } for (e = objects.ellipses; e != NULL; e = e->next) { num_object++; write_ellipse(fp, e); } for (l = objects.lines; l != NULL; l = l->next) { num_object++; write_line(fp, l); } for (s = objects.splines; s != NULL; s = s->next) { num_object++; write_spline(fp, s); } for (t = objects.texts; t != NULL; t = t->next) { num_object++; write_text(fp, t); } #ifdef I18N /* reset to original locale */ setlocale(LC_NUMERIC, ""); #endif /* I18N */ if (ferror(fp)) { fclose(fp); return (-1); } if (fclose(fp) == EOF) return (-1); return (0); }
void write_fluffy_decls(FILE *output, const translation_unit_t *unit) { out = output; global_scope = &unit->scope; print_to_file(out); fprintf(out, "/* WARNING: Automatically generated file */\n"); /* write structs,unions + enums */ entity_t *entity = unit->scope.entities; for( ; entity != NULL; entity = entity->base.next) { if (entity->kind != ENTITY_TYPEDEF) continue; type_t *type = entity->typedefe.type; if(type->kind == TYPE_COMPOUND_STRUCT || type->kind == TYPE_COMPOUND_UNION) { write_compound(entity->base.symbol, &type->compound); } else if(type->kind == TYPE_ENUM) { write_enum(entity->base.symbol, &type->enumt); } } /* write global variables */ entity = unit->scope.entities; for( ; entity != NULL; entity = entity->base.next) { if (entity->kind != ENTITY_VARIABLE) continue; write_variable(entity); } /* write functions */ entity = unit->scope.entities; for( ; entity != NULL; entity = entity->base.next) { if (entity->kind != ENTITY_FUNCTION) continue; write_function(entity); } }
void write_jna_decls(FILE *output, const translation_unit_t *unit) { out = output; global_scope = &unit->scope; pset_new_init(&avoid_symbols); print_to_file(out); fprintf(out, "/* WARNING: Automatically generated file */\n"); fputs("import com.sun.jna.Native;\n", out); fputs("import com.sun.jna.Pointer;\n", out); fputs("\n", out); const char *register_libname = libname; if (register_libname == NULL) register_libname = "library"; /* TODO: where to get the name from? */ fputs("public class binding {\n", out); fputs("\tstatic {\n", out); fprintf(out, "\t\tNative.register(\"%s\");\n", register_libname); fputs("\t}\n", out); fputs("\n", out); /* read the avoid list */ FILE *avoid = fopen("avoid.config", "r"); if (avoid != NULL) { for (;;) { char buf[1024]; char *res = fgets(buf, sizeof(buf), avoid); if (res == NULL) break; if (buf[0] == 0) continue; size_t len = strlen(buf); if (buf[len-1] == '\n') buf[len-1] = 0; char *str = malloc(len+1); memcpy(str, buf, len+1); symbol_t *symbol = symbol_table_insert(str); pset_new_insert(&avoid_symbols, symbol); } fclose(avoid); } /* write structs,unions + enums */ entity_t *entity = unit->scope.entities; for ( ; entity != NULL; entity = entity->base.next) { if (entity->kind == ENTITY_ENUM) { if (find_enum_typedef(&entity->enume) != NULL) continue; write_enum(entity->base.symbol, &entity->enume); } else if (entity->kind == ENTITY_TYPEDEF) { type_t *type = entity->declaration.type; if (type->kind == TYPE_ENUM) { write_enum(entity->base.symbol, type->enumt.enume); } } #if 0 if (is_type_compound(type)) { write_compound(entity->base.symbol, &type->compound); } #endif } /* write functions */ entity = unit->scope.entities; for ( ; entity != NULL; entity = entity->base.next) { if (entity->kind != ENTITY_FUNCTION) continue; if (entity->base.pos.is_system_header) continue; if (entity->function.elf_visibility != ELF_VISIBILITY_DEFAULT) continue; if (output_limits != NULL) { bool in_limits = false; char const *const input_name = entity->base.pos.input_name; for (output_limit *limit = output_limits; limit != NULL; limit = limit->next) { if (streq(limit->filename, input_name)) { in_limits = true; break; } } if (!in_limits) continue; } if (pset_new_contains(&avoid_symbols, entity->base.symbol)) continue; write_function(entity); } fputs("}\n", out); pset_new_destroy(&avoid_symbols); }