/**************************************************************** * Summary: Generates a dictionary from given dictionary file. * * * * Parameters: fp_dictionary - represents the dictionary file. * * * * Returns: The first node in the dictionary if successful, * * otherwise NULL. * ****************************************************************/ list_node_t * create_dictionary(FILE *fp_dictionary) { char *temp_word = NULL; char *temp_line = NULL; list_node_t *first = NULL; list_node_t *last = NULL; /* Allocate memory */ temp_line = (char *)malloc(sizeof(char) * DICTIONARY_MAX_LINE); if (NULL == temp_line) { return NULL; } /* Build dictionary */ while (NULL != fgets(temp_line, DICTIONARY_MAX_LINE, fp_dictionary)) { last = interpret_line(temp_line, last); /* If interpret_line failed, free memory and return NULL */ if(NULL == last) { if (NULL != first) { list_node_kill(first); } free(temp_line); return NULL; } if (NULL == first) { first = last; } } free(temp_line); /* Free memory */ return first; }
void call_script(char *script_name) { FILE *scr,*snf; char name[256]; char snd_name[256],*c; int i,fr,lfr=0,wfr=-1; scr=fopen(script_name,"r"); strcpy(snd_name,script_name); c=strrchr(snd_name,'.'); if (c==NULL) strcat(snd_name,SND_NAME); else strcpy(c,SND_NAME); if (scr==NULL) { printf("Nemohu otev©¡t script: %s\n",script_name); exit(1); } snf=fopen(snd_name,"r"); i=fscanf(scr,"%255s",name); open_files(name); if (i!=1) { printf("Chyba ve script souboru: %s. Prvni mus¡ b˜t jm‚no c¡lov‚ho souboru.\n",scr); exit(1); } while ((i=fgetc(scr))!=EOF && i!='\n'); for(fr=1;fr<gh.frames;fr++) { cprintf("frame %d\r",fr); read_frame(); do { if (wfr==-1) { i=fgetc(scr); if (i!=EOF) { if (i!='#') { fscanf(snf,"%d",&lfr); while ((i=fgetc(scr))!=EOF && i!='\n'); } else { fscanf(scr,"%d",&wfr); wfr+=lfr-1; } } else wfr=9999999; } if (wfr<=fr && wfr!=-1) { interpret_line(scr); wfr=-1; } } while (wfr==-1); press_sound_chunk(); lseek(tf,next_frame,SEEK_SET); } fclose(scr); if (snf!=NULL) fclose(snf); }