/* Make a db.h that will be link-time compatible with Sleepycat's Berkeley DB. */ #include #include #include #include #define DECL_LIMIT 100 #define FIELD_LIMIT 100 struct fieldinfo { char decl[DECL_LIMIT]; unsigned int off; unsigned int size; } fields[FIELD_LIMIT]; int field_counter=0; int compare_fields (const void *av, const void *bv) { const struct fieldinfo *a = av; const struct fieldinfo *b = bv; if (a->off < b->off) return -1; if (a->off > b->off) return 1; return 0; } #define STRUCT_SETUP(typ, name, fstring) ({ snprintf(fields[field_counter].decl, DECL_LIMIT, fstring, #name); \ fields[field_counter].off = __builtin_offsetof(typ, name); \ { typ dummy; \ fields[field_counter].size = sizeof(dummy.name); } \ field_counter++; }) FILE *outf; void open_file (void) { char fname[100]; snprintf(fname, 100, "sample_offsets_%d.h", __WORDSIZE); outf = fopen(fname, "w"); assert(outf); } void sort_and_dump_fields (const char *structname, unsigned int sizeofstruct) { int i; qsort(fields, field_counter, sizeof(fields[0]), compare_fields); fprintf(outf, "struct fieldinfo %s_fields%d[] = {\n", structname, __WORDSIZE); for (i=0; i