diff --git a/dico.c b/dico.c index 8b0a6ef..596a19d 100644 --- a/dico.c +++ b/dico.c @@ -15,15 +15,16 @@ byte addto_dico(dico d,const string word){ //-1 if word can't enter, 0if allready in dico, 1 if added int i; byte isIn, endKind=end_kind(word); + printf("%x\n",endKind); if(!is_word(endKind)){ - printf("incorrect word\n"); + printf("%s is incorrect\n",word); return -1; } tree*tmp=&d[hash(word[0])],*temp; //1st, let's go through the tree, until the word is not in tree - for(i=1; word[i]!='\0' && word[i]!='\'' && !is_empty(*tmp) ;i++){ + for(i=0; word[i]!='\0' && word[i]!='\'' && !is_empty(*tmp) ;i++){ temp=tmp; - tmp=&((*tmp)->next[hash(word[i])]); + tmp=&((*tmp)->next[hash(word[i+1])]); } //if word is not ended at the end of the tree if(is_empty(*tmp)){ @@ -34,14 +35,14 @@ byte addto_dico(dico d,const string word){ tmp=&((*tmp)->next[hash(word[i])]); } (*temp)->isEnd = endKind; - printf("actions ended\n"); + printf("%s added\n",word); fflush(stdout); } //if word is ended else{ - isIn=endKind & is_end(*tmp); - (*tmp)->isEnd = endKind | is_end(*tmp); - printf("action ended\n"); + isIn=endKind & (*temp)->isEnd; + (*temp)->isEnd = endKind | is_end(*temp); + printf("%s allready in\n",word); fflush(stdout); } return isIn; @@ -88,7 +89,7 @@ void printto_file(dico d,FILE*stream){ printf("sorry, we can't open the dictionary\n"); return; } - printf("This is what the dictionnary contains :\n"); + printf("\n\nThis is what the dictionnary contains :\n"); for(int i=0;iletter='\0'; - n->isEnd=0; + n->isEnd=NOT_AN_END; for(int i=0;inext[i]=make_empty_tree(); return n; @@ -46,12 +46,12 @@ bool is_followed(const tree t){ //functions is_end bool is_end(const tree t){return t->isEnd;} -bool is_straight_end(const tree t){return t->isEnd & STRAIGHT_END;} -bool ends_with_apostrophe(const tree t){return t->isEnd & APOSTROPHE_END;} +bool is_straight_end(const tree t){return (t->isEnd & STRAIGHT_END);} +bool ends_with_apostrophe(const tree t){return (t->isEnd & APOSTROPHE_END);} -bool is_common_end(const tree t){return t->isEnd & COMMON_END ;} -bool is_proper_end(const tree t){return t->isEnd & PROPER_END;} -bool is_acronyme_end(const tree t){return t->isEnd & ACRONYME_END;} +bool is_common_end(const tree t){return (t->isEnd & COMMON_END);} +bool is_proper_end(const tree t){return (t->isEnd & PROPER_END);} +bool is_acronyme_end(const tree t){return (t->isEnd & ACRONYME_END);} @@ -85,44 +85,14 @@ byte end_kind(const string s){ } } //then let's consider the end - if(s[i]=='\0') - return endKind & STRAIGHT_END; - if(s[i]=='\''&&s[i+1]=='s'&&s[i+2]=='\0') - return endKind & APOSTROPHE_END; + if(s[i]=='\0'){ + return (endKind & STRAIGHT_END); + } + if(s[i]=='\'' && s[i+1]=='s' && s[i+2]=='\0'){ + return (endKind & APOSTROPHE_END); + } return NOT_AN_END; } bool is_word(const byte endKind){ return endKind!=0; } - - - - - -bool addto_treeIT(tree*t,const string word ,byte endKind){ - bool isIn; - int i; - //1st, let's go through the tree, until the word is not in tree - for(i=1; word[i]!='\0' && word[i]!='\'' && !is_empty(*t) ;i++){ - t=&((*t)->next[hash(word[i])]); - } - printf("hi\n"); - //if word is not ended at the end of the tree - if(is_empty(*t)){ - isIn=false; - for(; word[i]!='\0' && word[i]!='\'';i++){ - *t=make_node(tolower(word[i]),NOT_AN_END); - t=&((*t)->next[hash(word[i])]); - } - (*t)->isEnd=endKind; - printf("actions ended\n"); - } - //if word is ended - else{ - isIn=endKind & is_end(*t); - (*t)->isEnd=endKind | is_end(*t); - printf("action ended\n"); - } - return isIn; -} - diff --git a/treeh.h b/treeh.h index a73f722..fbd2fa1 100644 --- a/treeh.h +++ b/treeh.h @@ -10,9 +10,11 @@ #define NBCHAR 26 //A-Z #define NOT_AN_END 0x00 + #define COMMON_END 0x03 -#define PROPER_END 0x0B +#define PROPER_END 0x0C #define ACRONYME_END 0x30 + #define STRAIGHT_END 0x15 #define APOSTROPHE_END 0x2A @@ -46,10 +48,5 @@ bool ischar_of_word(char);//tells if char can be in a word bool is_word(byte endKind);//pass end_kind() as parameter byte end_kind(string); -//recursive can only be called in a addto_dico -//bool addto_tree(tree,const string,byte); -//void addto_tree2(tree,const string,byte); -//bool addto_treeIT(tree*,const string,byte); - #endif //TREEH_H -- libgit2 0.21.2