/** model_init **/ int model_init(FILE *in, model_t *model) { /****variables****/ obj_t *obj = NULL; char buf[256]; char objclass[128]; int ctr; int flag; /*****************/ /* Load the objects in the scene */ while (fscanf(in, "%128s", objclass) == 1) { /* The word just inputted must be either a class name or the beginning of a comment */ flag = 0; if (objclass[0] == '#') { /* It's a comment -- skip the rest of the line */ fgets(buf, sizeof(buf), in); /* consume rest of line */ } else { for(ctr = 0; ctr < (sizeof(helper)/sizeof(*helper)); ctr++) { // Use helper struct to call correct init if(strcmp(objclass, (helper[ctr]).objecttype) == 0) { obj = helper[ctr].init(in, objclass); flag = 1; break; } } // Catches objects not in the helper struct if (flag == 0) { fprintf(stderr, "Unrecognized object type\n"); exit(1); } // Catches failed initiation procedure otherwise adds if (obj == NULL) { fprintf(stderr, "Failed to load type %s \n", objclass); model_dump(model); exit(2); } else { /* Add object to scene object linked list */ if(obj->objcat == 0) l_add(model->scene, obj); else l_add(model->lights, obj); } } /* End else "not a comment" */ } return(0); }
int device_db_dump(FILE * f) { struct db_info * inf; int i; if ((inf = db_info_get()) == NULL) return -1; db_info_dump(f, inf); for (i = 0 ; i < inf->obj_cnt; ++i) { struct db_dev_model * obj = inf->obj[i]; fprintf(f, "%2d - ", i); model_dump(f, obj); } return 0; }
int main (int argc, char *argv[]) { if (argc < 3) { fprintf (stderr, "missing command line arguments\n"); return 1; } FILE *input = fopen (argv[1], "rb"); assert (input != NULL); FILE *output = fopen (argv[2], "wb"); assert (output != NULL); struct modelA cmodel; model_init (&cmodel); model_dump (); printf ("decompressing...\n"); decompress (input, output, &cmodel); printf ("%" PRIu64 "\n", cmodel.m_bytesProcessed); fclose (input); fclose (output); return 0; }