Commit 003d3e48f2e0955c6a4373de1d5dd7d2c982aa6f
1 parent
11c78e6d
update6 withHash
Showing
4 changed files
with
58 additions
and
30 deletions
Show diff stats
1 | 1 | #include "dico.h" |
2 | 2 | |
3 | 3 | void make_empty_dico(dico d){ |
4 | - for(int i=0;i<NB1CHAR;i++) | |
4 | + for(int i=0;i<NBCHAR;i++) | |
5 | 5 | d[i]=NULL; |
6 | 6 | } |
7 | 7 | void delete_dico(dico d){ |
... | ... | @@ -11,7 +11,7 @@ void delete_dico(dico d){ |
11 | 11 | |
12 | 12 | |
13 | 13 | |
14 | -bool addto_dico(dico d,string s){ | |
14 | +bool addto_dico(dico d,const string s){ | |
15 | 15 | byte endKind=end_kind(s); |
16 | 16 | if(!is_word(endKind)){ |
17 | 17 | printf("incorrect word"); |
... | ... | @@ -27,32 +27,52 @@ bool addto_dico(dico d,string s){ |
27 | 27 | } |
28 | 28 | } |
29 | 29 | |
30 | -bool lire(string s,FILE*stream){ | |
31 | - //need to check if stream !=NULL | |
32 | - //ret true if error else false | |
33 | - char* posRet=NULL; | |
34 | - if (fscanf(stream,"%s",s) != NULL){ | |
35 | - posRet=strchr(chaine, '\n'); | |
36 | - if (posRet!= NULL){ | |
37 | - *posRet = '\0'; | |
38 | - } | |
39 | - return false; | |
40 | - } | |
41 | - else | |
42 | - return true; | |
43 | -} | |
44 | - | |
45 | 30 | void loadfrom_keyboard(dico d){loadfrom_file(d,stdin);} |
46 | 31 | void loadfrom_file(dico d,FILE*stream){ |
47 | 32 | if(stream==NULL){ |
48 | 33 | printf("sorry, we can't open the file"); |
49 | 34 | return; |
50 | 35 | } |
51 | - string str=calloc(30*sizeof(char)); | |
52 | - while(fscanf(""strstream)!=NULL) | |
36 | + char word[30]={0}; | |
37 | + while(fscanf(stream,"%s",word)!=EOF) | |
38 | + addto_dico(d,word); | |
39 | + printf("load success"); | |
53 | 40 | } |
54 | 41 | |
55 | 42 | void printto_terminal(dico d){printto_file(dico,stdout);} |
56 | -void printto_file(dico d,FILE*f){ | |
57 | - ; | |
43 | +void printto_file(dico d,FILE*stream){ | |
44 | + if(stream==NULL){ | |
45 | + printf("sorry, we can't open the file"); | |
46 | + return; | |
47 | + } | |
48 | + if(d==NULL){ | |
49 | + printf("sorry, we can't open the dictionary"); | |
50 | + return; | |
51 | + } | |
52 | + for(int i=0;i<NBCHAR;i++){ | |
53 | + print(d[i],stream,""); | |
54 | + } | |
55 | +} | |
56 | + | |
57 | +void print(tree t,FILE*stream,string prefix){ | |
58 | + //needs to check stream!=NULL | |
59 | + if(is_empty(t)) | |
60 | + return; | |
61 | + if(is_end(t)){ | |
62 | + if(is_acronyme_end(t)){ | |
63 | + if(is_straight_end(t)){} | |
64 | + else{} | |
65 | + } | |
66 | + if(is_proper_end(t)){ | |
67 | + if(is_straight_end(t)){} | |
68 | + else{} | |
69 | + } | |
70 | + if(is_common_end(t)){ | |
71 | + if(is_straight_end(t)){} | |
72 | + else{} | |
73 | + } | |
74 | + } | |
75 | + for(int i=0;i<NBCHAR;i++){ | |
76 | + print(t->next[i],stream); | |
77 | + } | |
58 | 78 | } | ... | ... |
... | ... | @@ -7,7 +7,7 @@ typedef tree dico[NBCHAR]; |
7 | 7 | |
8 | 8 | void make_empty_dico(dico); |
9 | 9 | void delete_dico(dico); |
10 | -bool addto_dico(dico,string); | |
10 | +bool addto_dico(dico,const string); | |
11 | 11 | |
12 | 12 | |
13 | 13 | void loadfrom_file(dico,FILE*); |
... | ... | @@ -15,6 +15,6 @@ void loadfrom_keyboard(dico);//i.e. loadfrom_file(dico,stdin); |
15 | 15 | |
16 | 16 | void printto_file(dico,FILE*); |
17 | 17 | void printto_terminal(dico);//i.e. printto_file(dico,stdout); |
18 | - | |
18 | +void print(tree,FILE*,string) | |
19 | 19 | |
20 | 20 | #endif | ... | ... |
treeh.c
... | ... | @@ -45,12 +45,13 @@ bool is_followed(const tree t){ |
45 | 45 | } |
46 | 46 | |
47 | 47 | //functions is_end |
48 | -bool is_end(const tree t){return t->isEnd & 21;}//0b00010101 | |
49 | -bool ends_with_apostrophe(const tree t){return t->isEnd & 42;}//0b00101010 | |
48 | +bool is_end(const tree t){return isEnd;} | |
49 | +bool is_straight_end(const tree t){return t->isEnd & STRAIGHT_END;} | |
50 | +bool ends_with_apostrophe(const tree t){return t->isEnd & APOSTROPHE_END;} | |
50 | 51 | |
51 | -bool is_common_end(const tree t){return t->isEnd & 3;}//0b00000011 | |
52 | -bool is_proper_end(const tree t){return t->isEnd & 12;}//0b00001100 | |
53 | -bool is_acronyme_end(const tree t){return t->isEnd & 48;}//0b00110000 | |
52 | +bool is_common_end(const tree t){return t->isEnd & COMMON_END ;} | |
53 | +bool is_proper_end(const tree t){return t->isEnd & PROPER_END;} | |
54 | +bool is_acronyme_end(const tree t){return t->isEnd & ACRONYME_END;} | |
54 | 55 | |
55 | 56 | |
56 | 57 | ... | ... |
treeh.h
... | ... | @@ -8,6 +8,12 @@ |
8 | 8 | |
9 | 9 | #define NBCHAR 26 //A-Z |
10 | 10 | |
11 | +#define COMMON_END 0x03 | |
12 | +#define PROPER_END 0x0B | |
13 | +#define ACRONYME_END 0x30 | |
14 | +#define STRAIGHT_END 0X15 | |
15 | +#define APOSTROPHE_END 0X2A | |
16 | + | |
11 | 17 | typedef char *string,byte; |
12 | 18 | typedef struct _node node, *tree; |
13 | 19 | struct _node{ |
... | ... | @@ -26,8 +32,9 @@ void delete_tree(tree);//free(tree) and delete tree on all t->next |
26 | 32 | bool is_empty(const tree);//==NULL |
27 | 33 | bool is_followed(const tree);//if true tree has following letters |
28 | 34 | |
29 | -bool is_end(const tree);//if true word can end here | |
30 | -bool ends_with_apostrophe(const tree);//if true word can be word's | |
35 | +bool is_end(const tree);//true when at least 1 of the following functions is true | |
36 | +bool is_straight_end(const tree);//if true word can end here | |
37 | +bool ends_with_apostrophe(const tree);//if true word can end here with apostrophe | |
31 | 38 | bool is_common_end(const tree);//if true all letters are lower |
32 | 39 | bool is_proper_end(const tree);//if true 1st letter is upper |
33 | 40 | bool is_acronyme_end(const tree);//if true all letters are upper | ... | ... |