int main(void) { node_t *head = NULL; head = create(head, 5); head = del_node(head); show_destroy(head); return 0; }
int open_file(char *filename) { // open a file (for now, just save_file) // loop vars int i, j; // file pointer FILE *fp; // stream string char *buffer; // data storage char *data; // operation storage char *operation; // name storage char *name; // info storage char *info; // performer storage char *perfnum_buffer; // performer number int perfnum; // exit code int excode; // sizing for allocation int size; // finished flag int done; // placeholder for char int index; // coord number int cnum; // coordinates double x, y; // new operation char *op; // Structures // performer structures perf_t **perfs; perf_t *perf; // Set structure set_t *currset; // open file for reading if (!filename) return -1; if (!(fp = fopen(filename,"r"))) return -1; // check for valid file excode = file_getValidLine(fp, &buffer); if (strcmp(buffer, "#drillwriter")) { // not a valid save file return -1; } free(buffer); // get the name excode = file_getValidLine(fp, &buffer); size = strlen(buffer); name = (char*)malloc((size+2)*sizeof(char)); if (!name) return -1; strncpy(name, buffer, size+1); excode = file_linetoOps(name, &op, '='); free(op); free(buffer); // store name free(pshow->showname); pshow->showname = (char*)malloc((strlen(name)+1)*sizeof(char)); if (!pshow->showname) return -1; strcpy(pshow->showname, name); free(name); // get info excode = file_getValidLine(fp, &buffer); size = strlen(buffer); info = (char*)malloc((size+2)*sizeof(char)); if (!info) return -1; strncpy(info, buffer, size+1); excode = file_linetoOps(info, &op, '='); free(op); free(buffer); // store info free(pshow->showinfo); pshow->showinfo = (char*)malloc((strlen(info)+1)*sizeof(char)); if (!pshow->showinfo) return -1; strcpy(pshow->showinfo, info); free(info); // get perfnum excode = file_getValidLine(fp, &buffer); size = strlen(buffer); perfnum_buffer = (char*)malloc((size+2)*sizeof(char)); if (!perfnum_buffer) return -1; strncpy(perfnum_buffer, buffer, size+1); excode = file_linetoOps(perfnum_buffer, &op, '='); free(op); free(buffer); perfnum = atoi(perfnum_buffer); free(perfnum_buffer); // make the show show_destroy(&pshow); excode = show_construct(&pshow, perfnum); //printf("perfnum = %i\n", perfnum); // build performers buffer = (char*)malloc(sizeof(char)); if (!buffer) return -1; // get performer info perfs = pshow->perfs; perf = perfs[0]; done = 0; i = -1; do { if (i != -1) { if (perfs[i]) perf = perfs[i]; else exit(-1); } // grab performer pieces free(buffer); // get a valid line excode = file_getValidLine(fp, &buffer); size = strlen(buffer); // get operations at data from line data = (char*)malloc((size+2)*sizeof(char)); if (!data) return -1; strncpy(data, buffer, size+1); excode = file_linetoOps(data, &operation, '='); // interpret data based on operation if (!strcmp(operation, "index")) { // info perf->index = atoi(data); i++; } else if (!strcmp(operation, "symbol")) { // symbol free(perf->symbol); perf->symbol = (char*)malloc((size+1)*sizeof(char)); if (!perf->symbol) return -1; strcpy(perf->symbol, data); } else if (!strcmp(operation, "valid")) { // validity flag perf->valid = atoi(data); } else if (!strcmp(operation, "sets:")) { // moving to coords. finished with perfs done = 1; } free(data); free(operation); } while (done == 0); for (i=i+1; i<perfnum; i++) perfs[i]->valid = 0; // go to first set set_first(); currset = pshow->sets->currset; // get set information do { free(buffer); excode = file_getValidLine(fp, &buffer); //printf("buffer = %s\n", buffer); size = strlen(buffer); data = (char*)malloc((size+2)*sizeof(char)); if (!data) return -1; strncpy(data, buffer, size+1); file_linetoOps(data, &operation, '='); //printf("op = %s data = %s\n", operation, data); // find correct operation if (!strcmp(operation, "set")) { // set if (atoi(data) != 0) { // need a new set //add_set(); set_add_after_current(); currset = pshow->sets->currset; } } else if (!strcmp(operation, "counts")) { // counts currset->counts = atoi(data); } else if (!strcmp(operation, "tempo")) { // tempo //printf("changing tempo\n"); //printf("%i: new tempo = %i\n", pstate.setnum, atoi(data)); change_tempo(atoi(data), &pshow->currtempo); update_tempo(); //printf("ping\n"); } else if (!strcmp(operation, "coords:")) { // store coords i = 0; do { free(buffer); excode = file_getValidLine(fp, &buffer); if (excode == -1) exit(-1); else if (!strcmp(buffer, "done")) break; size = strlen(buffer); free(data); data = (char*)malloc((size+2)*sizeof(char)); if (excode == -1) exit(-1); strncpy(data, buffer, size+1); for (j=0; j<size && buffer[j] != ':'; j++) data[j] = buffer[j]; data[j] = '\0'; cnum = atoi(data); j++; // pass any whitespace for (j=j; j<size && buffer[j] == ' '; j++) { } index = j; // get first number for (j=j; j<size && buffer[j] != ' '; j++) { data[j-index] = buffer[j]; } data[j-index] = '\0'; x = atof(data); // pass whitespace for (j=j; j<size && buffer[j] == ' '; j++) { } index = j; // get second number for (j=j; j<size; j++) { data[j-index] = buffer[j]; } data[j-index] = '\0'; y = atof(data); //printf("(x,y) = %i %.2f %.2f\n", cnum, x, y); //printf("valid = %i\n", perfs[i]->valid); //if (perfs[i]->valid != 0) //{ //coords_set_coord(pshow, cnum, x, y); coords_set(pshow->sets->currset->coords[cnum], x, y); //} perf_set_valid(pshow->perfs[i]); i++; } while (i < perfnum); } free(operation); free(data); } while (excode != 1); free(buffer); set_first(); update_tempo(); fclose(fp); // update valid flags //printf("perfnum = %i\n", perfnum); undo_destroy(&pstate.undobr, pshow); return 0; }