Lines Matching refs:bof
34 static int bof_entry_grow(bof_t *bof) in bof_entry_grow() argument
38 if (bof->array_size < bof->nentry) in bof_entry_grow()
40 array = realloc(bof->array, (bof->nentry + 16) * sizeof(void*)); in bof_entry_grow()
43 bof->array = array; in bof_entry_grow()
44 bof->nentry += 16; in bof_entry_grow()
125 bof_t *bof_array_get(bof_t *bof, unsigned i) in bof_array_get() argument
127 if (!bof_is_array(bof) || i >= bof->array_size) in bof_array_get()
129 return bof->array[i]; in bof_array_get()
132 unsigned bof_array_size(bof_t *bof) in bof_array_size() argument
134 if (!bof_is_array(bof)) in bof_array_size()
136 return bof->array_size; in bof_array_size()
160 unsigned bof_blob_size(bof_t *bof) in bof_blob_size() argument
162 if (!bof_is_blob(bof)) in bof_blob_size()
164 return bof->size - 12; in bof_blob_size()
167 void *bof_blob_value(bof_t *bof) in bof_blob_value() argument
169 if (!bof_is_blob(bof)) in bof_blob_value()
171 return bof->value; in bof_blob_value()
216 int32_t bof_int32_value(bof_t *bof) in bof_int32_value() argument
218 return *((uint32_t*)bof->value); in bof_int32_value()
232 static void bof_print_bof(bof_t *bof, int level, int entry) in bof_print_bof() argument
235 if (bof == NULL) { in bof_print_bof()
239 switch (bof->type) { in bof_print_bof()
241 fprintf(stderr, "%p string [%s %d]\n", bof, (char*)bof->value, bof->size); in bof_print_bof()
244 fprintf(stderr, "%p int32 [%d %d]\n", bof, *(int*)bof->value, bof->size); in bof_print_bof()
247 fprintf(stderr, "%p blob [%d]\n", bof, bof->size); in bof_print_bof()
250 fprintf(stderr, "%p null [%d]\n", bof, bof->size); in bof_print_bof()
253 fprintf(stderr, "%p object [%d %d]\n", bof, bof->array_size / 2, bof->size); in bof_print_bof()
256 fprintf(stderr, "%p array [%d %d]\n", bof, bof->array_size, bof->size); in bof_print_bof()
259 fprintf(stderr, "%p unknown [%d]\n", bof, bof->type); in bof_print_bof()
264 static void bof_print_rec(bof_t *bof, int level, int entry) in bof_print_rec() argument
268 bof_print_bof(bof, level, entry); in bof_print_rec()
269 for (i = 0; i < bof->array_size; i++) { in bof_print_rec()
270 bof_print_rec(bof->array[i], level + 2, i); in bof_print_rec()
274 void bof_print(bof_t *bof) in bof_print() argument
276 bof_print_rec(bof, 0, 0); in bof_print()
281 bof_t *bof = NULL; in bof_read() local
290 bof = bof_object(); in bof_read()
291 if (bof == NULL) in bof_read()
293 bof->offset = ftell(file); in bof_read()
294 r = fread(&bof->type, 4, 1, file); in bof_read()
297 r = fread(&bof->size, 4, 1, file); in bof_read()
300 r = fread(&bof->array_size, 4, 1, file); in bof_read()
303 switch (bof->type) { in bof_read()
307 bof->value = calloc(1, bof->size - 12); in bof_read()
308 if (bof->value == NULL) { in bof_read()
311 r = fread(bof->value, bof->size - 12, 1, file); in bof_read()
313 fprintf(stderr, "error reading %d\n", bof->size - 12); in bof_read()
321 r = bof_read(bof, file, bof->offset + bof->size, level + 2); in bof_read()
326 fprintf(stderr, "invalid type %d\n", bof->type); in bof_read()
329 root->array[root->centry++] = bof; in bof_read()
332 bof_decref(bof); in bof_read()
372 void bof_incref(bof_t *bof) in bof_incref() argument
374 bof->refcount++; in bof_incref()
377 void bof_decref(bof_t *bof) in bof_decref() argument
381 if (bof == NULL) in bof_decref()
383 if (--bof->refcount > 0) in bof_decref()
385 for (i = 0; i < bof->array_size; i++) { in bof_decref()
386 bof_decref(bof->array[i]); in bof_decref()
387 bof->array[i] = NULL; in bof_decref()
389 bof->array_size = 0; in bof_decref()
390 if (bof->file) { in bof_decref()
391 fclose(bof->file); in bof_decref()
392 bof->file = NULL; in bof_decref()
394 free(bof->array); in bof_decref()
395 free(bof->value); in bof_decref()
396 free(bof); in bof_decref()
399 static int bof_file_write(bof_t *bof, FILE *file) in bof_file_write() argument
404 r = fwrite(&bof->type, 4, 1, file); in bof_file_write()
407 r = fwrite(&bof->size, 4, 1, file); in bof_file_write()
410 r = fwrite(&bof->array_size, 4, 1, file); in bof_file_write()
413 switch (bof->type) { in bof_file_write()
415 if (bof->size) in bof_file_write()
421 r = fwrite(bof->value, bof->size - 12, 1, file); in bof_file_write()
427 for (i = 0; i < bof->array_size; i++) { in bof_file_write()
428 r = bof_file_write(bof->array[i], file); in bof_file_write()
439 int bof_dump_file(bof_t *bof, const char *filename) in bof_dump_file() argument
444 if (bof->file) { in bof_dump_file()
445 fclose(bof->file); in bof_dump_file()
446 bof->file = NULL; in bof_dump_file()
448 bof->file = fopen(filename, "w"); in bof_dump_file()
449 if (bof->file == NULL) { in bof_dump_file()
454 r = fseek(bof->file, 0L, SEEK_SET); in bof_dump_file()
459 r = fwrite(&bof->type, 4, 1, bof->file); in bof_dump_file()
462 r = fwrite(&bof->size, 4, 1, bof->file); in bof_dump_file()
465 r = fwrite(&bof->array_size, 4, 1, bof->file); in bof_dump_file()
468 for (i = 0; i < bof->array_size; i++) { in bof_dump_file()
469 r = bof_file_write(bof->array[i], bof->file); in bof_dump_file()
474 fclose(bof->file); in bof_dump_file()
475 bof->file = NULL; in bof_dump_file()