1 /***************************************************************************
4 begin : Wed Mar 21 21:39:53 EST 2001
5 copyright : (C) 2001 by Haavard Froeiland 2264228
6 email : havard@student.unsw.edu.au
8 ***************************************************************************/
23 typedef struct WordNode
*WordList
;
28 struct WordNode
*next
;
31 void *addWord(WordList first
, char w
[])
35 ptr
=malloc(sizeof(struct WordNode
));
41 void printWordList(WordList l
)
43 struct WordNode
*ptr
=l
;
44 /* loop throug the linked list */
47 printf("%s\n",ptr
->word
);
52 void printLevel(FILE *f
,char *l
[])
59 while(l
[arrayMax
]!=NULL
)
64 if (arrayMax
== 0) return;
65 /* loop throug the linked list */
68 arrayPos
=((float)rand()/RAND_MAX
)*arrayMax
;
69 pos
=pos
+strlen(l
[arrayPos
]);
70 fprintf(f
,"%s",l
[arrayPos
]);
86 void creatLevelList(WordList l
,char *levelList
[],char s_or
[], char s_and
[])
88 struct WordNode
*ptr
=l
;
95 /* loop throug the linked list */
98 /* loop through the word */
99 /* printf("%s\n",ptr->word); */
100 i
=strlen(ptr
->word
)-1;
108 if(ptr
->word
[i
]==s_or
[j
])
119 if(ptr
->word
[i
]==s_and
[j
])
131 if(or_failed
==false && and_failed
==false)
133 levelList
[pos
]=ptr
->word
;
135 /* printf("%d\n",pos); */
144 int main(int argc
, char *argv
[])
149 char *levelList
[100000];
157 printf("\nUsage: ktouchgen ConfigFile WordFile TrainingFile\n");
162 * Read in the configFile
165 if((file
= fopen(argv
[1],"r"))==NULL
)
167 printf("can't open config_file:%s for reading",argv
[2]);
172 fscanf(file
,"%s",word
);
184 * Read in the wordFile and add each word to the list
187 printf("Starting reading words");
188 if((file
= fopen(argv
[2],"r"))==NULL
)
190 printf("can't open word_file:%s for reading",argv
[2]);
194 fscanf(file
,"%s",word
);
195 list
=addWord(list
, word
);
200 if((file
= fopen(argv
[3],"w"))==NULL
)
202 printf("Error when writing to file:%s",argv
[3]);
206 fprintf(file
,"#############################################################\n");
207 fprintf(file
,"# Rrainingfile genereated %s",ctime(<
));
208 fprintf(file
,"# Program written by Håvard Frøiland\n");
209 fprintf(file
,"#############################################################\n\n");
216 if (strlen(test
) + strlen(s
[i
]) + 1 > sizeof(test
))
218 printf("Buffer overflow.\n");
222 fprintf(file
,"# Level %d\n",i
+1);
223 fprintf(file
,"%s\n", s
[i
]);
224 creatLevelList(list
,levelList
,test
,s
[i
]);
225 printLevel(file
,levelList
);