Home | History | Annotate | Download | only in radeon

Lines Matching refs:bof

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