#include #include #include #include #include "dffviewer.h" #define OBJS 1; Objs *ReadIde(FILE *file) { int temp; /* int i; */ static int insideblock = 0; int blocktype; char line[256]; char *test; Objs *obj; obj = NULL; obj = malloc(sizeof(Objs)); if ((test = fgets(line, 256, file)) == NULL) return NULL; temp = strlen(line); line[temp-1] = '\0'; if (line[temp-2] == 0xd) line[temp-2] = '\0'; printf("%s\n", line); while (!insideblock) { if (strcmp(line, "objs") == 0) { printf("found objs\n"); blocktype = OBJS; insideblock = 1; if ((test = fgets(line, 256, file)) == NULL) return NULL; temp = strlen(line); line[temp-1] = '\0'; if (line[temp-2] == 0xd) line[temp-2] = '\0'; } } if (strcmp(line, "end") == 0) { printf("Found end\n"); blocktype = 0; insideblock = 0; if ((test = fgets(line, 256, file)) == NULL) return NULL; temp = strlen(line); line[temp-1] = '\0'; if (line[temp-2] == 0xd) line[temp-2] = '\0'; } obj->DrawDist = malloc(sizeof(float)); sscanf(line, "%d, %s %s %d, %f, %d", &obj->Id, obj->Model, obj->Texture, &obj->ObjCount, &obj->DrawDist[0], &obj->Flags); /* Remove comma and add file extension */ obj->Model[strlen(obj->Model)-1] = '.'; strcat(obj->Model, "dff"); obj->Texture[strlen(obj->Texture)-1] = '.'; strcat(obj->Texture, "txd"); ToUpperLine(obj->Model); ToUpperLine(obj->Texture); /* for (i = 0; i < strlen(obj->Model); i++) if (isupper(obj->Model[i])) obj->Model[i] = tolower(obj->Model[i]); for (i = 0; i < strlen(obj->Texture); i++) if (isupper(obj->Texture[i])) obj->Texture[i] = tolower(obj->Texture[i]); */ if (obj->ObjCount != 1) { fprintf(stderr, "Only first clump supported\n"); return NULL; } return obj; }