This repository has been archived by the owner on Oct 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
264 lines (222 loc) · 7.5 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
/*
Bibtex Project - Main.c
Maxime B. & Nathan O. (TC03)
Main.c : insert a description here.
*/
#include <bibtexmanager.h>
#include <time.h>
int main(int argc, char** argv)
{
AbstractList library, tmpLibrary, libraryDateAuthor, libraryAuthorDate;
AuthorPublications authorPublication;
DatePublications datePublications;
Author tmpAuthor;
char* userAnswer;
int userDecision = 0;
library = initList(sizeof(Entry));
tmpLibrary = initList(sizeof(tmpLibrary));
libraryAuthorDate = initList(sizeof(AuthorPublications));
libraryDateAuthor = initList(sizeof(DatePublications));
userAnswer = (char*) malloc(500*sizeof(char));
printf("\n== Managing of a bibtex file ==\n");
do
{
do
{
printf("Write the name of the bibtex file : ");
gets(userAnswer);
library = parseBibtexFile(userAnswer);
printf("\n");
}while(isEmpty(library));
tmpLibrary = library;
do
{
printf("The insertEntry and removeEntry are done but not for user.\n\n");
printf("If you want to do the 6, do the 1 before.\n");
printf("If you want to do the 7, do the 2 before.\n\n");
do
{
printf("Which function do you want to use on this bibtex file ?\n");
printf("1 : sortLibraryAuthorDate\n");
printf("2 : sortLibraryDateAuthor\n");
printf("3 : getAuthorReferences\n");
printf("4 : getYearReferences\n");
printf("5 : printLibrary\n");
printf("6 : printAuthorsPublications\n");
printf("7 : printDatesPublications\n");
printf("8 : exportLibrary\n");
printf("9 : exportAuthorsPublications\n");
printf("10 : exportDatePublications\n");
printf("11 : removeEntry\n\n");
scanf("%d", &userDecision);
}while(userDecision < 0 || userDecision > 11);
printf("\n");
switch (userDecision) {
case 1 :
libraryAuthorDate = sortLibraryAuthorDate(library);
printf("== Library sorted in AuthorsPublications ==\n\n");
printf("If you want to print it, use the function 6 : printAuthorsPublications\n\n");
break;
case 2 :
libraryDateAuthor = sortLibraryDateAuthor(library);
printf("== Library sorted in DatesPublications ==\n\n");
printf("If you want to print it, use the function 7 : printDatesPublications\n\n");
break;
case 3 :
do
{
printf("Write the author's first name : ");
clean_stdin();
gets(userAnswer);
}while(strcmp(userAnswer, "") == 0);
tmpAuthor.firstName = (char*) malloc(sizeof(char)*(strlen(userAnswer)+1));
strcpy(tmpAuthor.firstName, userAnswer);
do
{
printf("Write the author's last name : ");
scanf("%s", userAnswer);
}while(strcmp(userAnswer, "") == 0);
tmpAuthor.lastName = (char*) malloc(sizeof(char)*(strlen(userAnswer)+1));
strcpy(tmpAuthor.lastName, userAnswer);
authorPublication = getAuthorPublications(library, tmpAuthor);
if(isEmpty(authorPublication.publicationsList))
{
printf("\n\t\t%s %s\n", tmpAuthor.firstName, tmpAuthor.lastName);
printf("No publication for this author.\n\n");
}
else
printAuthorPublications(authorPublication);
break;
case 4 :
do
{
printf("Write the year : ");
clean_stdin();
gets(userAnswer);
}while(strcmp(userAnswer, "") == 0);
datePublications = getDatePublications(library, userAnswer);
if(isEmpty(datePublications.publicationsList))
{
printf("\n\t\t%s\n\n", datePublications.year);
printf("No publication for this year.\n\n");
}
else
printDatePublications(datePublications);
break;
case 5 :
printLibrary(library);
break;
case 6 :
if(isEmpty(libraryAuthorDate))
{
printf("The list of AuthorDatePublications is empty.\n");
do {
printf("Do you want to create it with the sortLibraryAuthorDate function ? (Y/N)\n");
clean_stdin();
userAnswer[0] = getchar();
} while(userAnswer[0] != 'Y' && userAnswer[0] != 'y' && userAnswer[0] != 'N' && userAnswer[0] != 'n');
if(userAnswer[0] == 'Y' || userAnswer[0] == 'y')
{
printListAuthorPublications(libraryAuthorDate);
}
}
else
printListAuthorPublications(libraryAuthorDate);
break;
case 7 :
if(isEmpty(libraryAuthorDate))
{
printf("The list of DateAuthorPublications is empty.\n");
do {
printf("Do you want to create it with the sortLibraryDateAuthor function ? (Y/N)\n");
clean_stdin();
userAnswer[0] = getchar();
} while(userAnswer[0] != 'Y' && userAnswer[0] != 'y' && userAnswer[0] != 'N' && userAnswer[0] != 'n');
if(userAnswer[0] == 'Y' || userAnswer[0] == 'y')
{
printListDatePublications(libraryDateAuthor);
}
}
else
printListDatePublications(libraryDateAuthor);
break;
case 8 :
do
{
printf("Write the name of the HTML file in which the Library will be exported : ");
clean_stdin();
gets(userAnswer);
}while(strcmp(userAnswer, "") == 0);
exportToHTML(library,userAnswer);
printf("The Library has been exported in %s\n", userAnswer);
break;
case 9 :
do
{
printf("Write the name of the HTML file in which the AuthorsPublications will be exported : ");
clean_stdin();
gets(userAnswer);
}while(strcmp(userAnswer, "") == 0);
if(isEmpty(libraryAuthorDate))
{
libraryAuthorDate = sortLibraryAuthorDate(library);
}
exportAuthorsPublications(libraryAuthorDate,userAnswer);
printf("The list of AuthorPublications has been exported in %s\n", userAnswer);
break;
case 10 :
do
{
printf("Write the name of the HTML file in which the DatePublications will be exported : ");
clean_stdin();
gets(userAnswer);
}while(strcmp(userAnswer, "") == 0);
if(isEmpty(libraryDateAuthor))
{
libraryDateAuthor = sortLibraryAuthorDate(library);
}
exportDatePublications(libraryDateAuthor,userAnswer);
printf("The list of DatePublications has been exported in %s\n", userAnswer);
break;
case 11 :
printf("Pleas give the key of the Entry you want to remove : ");
scanf("%s", userAnswer);
if(checkEntry(library, userAnswer))
{
removeEntry(library, userAnswer);
printf("== The Entry \"%s\" has been deleted. ==\n\n", userAnswer);
if(!isEmpty(libraryDateAuthor))
{
libraryDateAuthor = sortLibraryAuthorDate(library);
}
if(!isEmpty(libraryAuthorDate))
{
libraryAuthorDate = sortLibraryAuthorDate(library);
}
}
else
printf("== The Entry \"%s\" doesn't exist in the library ==\n\n", userAnswer);
break;
}
do
{
printf("Do you want to do an other operation on this file ? (Y/N) ");
clean_stdin();
scanf("%s", userAnswer);
}while(strcmp(stringToUpper(userAnswer), "Y") != 0 && strcmp(stringToUpper(userAnswer), "N") != 0);
}while(strcmp(stringToUpper(userAnswer), "Y") == 0);
freeDatePublications(libraryDateAuthor);
freeAuthorsPublications(libraryAuthorDate);
freeLibrary(library, TRUE);
do
{
printf("Do you want to open a new file ? (Y/N) ");
scanf("%s", userAnswer);
}while(strcmp(stringToUpper(userAnswer), "Y") != 0 && strcmp(stringToUpper(userAnswer), "N") != 0);
printf("\n");
}
while(strcmp(stringToUpper(userAnswer), "Y") == 0);
free(userAnswer);
return EXIT_SUCCESS;
}