This repository has been archived by the owner on Feb 14, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
buffer.cpp
1851 lines (1519 loc) · 54.1 KB
/
buffer.cpp
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
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "buffer.h"
#include "producao.h"
#include <iostream>
#include <fstream>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
using namespace std;
int baker(docente** docentes, producao** producoes, int* rules, character** orientacoes, character* congressos, character* periodicos, char* curso, const char* regrasNomeArquivo, int anoEntrada ,int anoSaida){
int sucess = 1;
if((*docentes) != NULL && (*producoes) != NULL){
if(rules != NULL && orientacoes != NULL && congressos != NULL && periodicos != NULL){
dictionary* issnDictionary = NULL;
docente* currentDocente = NULL;
char* slashN = new char[2];
slashN[0] = '\n';
slashN[1] = '\0';
//It is here to avoid bug of going non stop through .csv
int numberOfLinesCongressoCSV = numberOfLinesBufferFile(congressos);
cout << "======================"<< curso << "=======================" << endl;
int numDeProducoes = 0;
int numDeCogressos = 0;
//Get the first node from the Double Linked List
currentDocente = (*docentes);
//Iterate through all docentes
while(currentDocente != NULL){
numDeProducoes = 0;
cout << "Docente: " << currentDocente->name << endl;
//Store the every single "producao" from the current docente
producao* allProducao = NULL;
//It willcurrentProducao = removeProducao(&allProducao) receive the last "producao" whithing the current docente node at the BST
allProducao = getAllProducoesFromThatDocente(*producoes, currentDocente->id);
//If the docente has some producao
if(allProducao != NULL){
cout << "Producoes: "<< endl;
//Iterate through all producoes
producao* currentProducao = NULL;
while((currentProducao = removeProducao(&allProducao))){
//If the current producao is a normal publicacao
if(((!strcmp(currentProducao->type, "ARTIGO-PUBLICADO")) || (!strcmp(currentProducao->type, "ARTIGO-ACEITO-PARA-PUBLICACAO"))) && (currentProducao->year >= anoEntrada) && (currentProducao->year <= anoSaida)){
int semEstratoQualis = 1;
cout << currentProducao->year << endl;
//Iterate through all issn's that match
character* iterator = periodicos;
while(iterator = find(iterator, currentProducao->issn)){
//Check if the type is the same at the rule file
char* areaAvaliacao = getNthColumnDataFromCur(iterator->prev, 3);
if(!strcmp(curso,areaAvaliacao) ){
//Set docente points
semEstratoQualis = 0;
char* qualis = clean(getNthColumnDataFromCur(iterator->prev, 4));
int pontos = qualisCodePeriodicosToInt(qualis,rules);
currentDocente->points[getPosQualisPeriodico(qualis)] += pontos;
currentDocente->totalPoints += pontos;
cout << "\t" << clean(getNthColumnDataFromCur(iterator->prev, 4)) << " (" << pontos << ")" << " - " << currentProducao->issn << " - " << currentProducao->type << " - " << currentProducao->title << " - " <<currentProducao->year<< endl;
numDeProducoes++;
delete[] qualis;
break;
}
iterator = iterator->next;
}
if(semEstratoQualis == 1){
int pontos = rules[8];
currentDocente->points[8] += pontos;
cout << "\t" << "Sem Estrato Qualis" << " (" << pontos << ")" << " - " << currentProducao->issn << " - " << currentProducao->type << " - " <<currentProducao->title <<" - " << currentProducao->year << endl;
currentDocente->totalPoints += pontos;
numDeProducoes++;
}
}else if((!strcmp(currentProducao->type, "TRABALHO_EM_EVENTO") )&& (currentProducao->year >= anoEntrada) && (currentProducao->year <= anoSaida)){
char* localProducao = new char[2048];
strcpy(localProducao,(currentProducao->local));
int hasNoQualis = 1;
character* iteratorSiglaCongresso = congressos;
//Separate all words whiting the field LOCAL
char* siglaProducao = strtok(currentProducao->local, " -.,():");
char* siglaCSV = getNthColumnDataCongresso(iteratorSiglaCongresso,4);
//Update siglaCSV value
while(siglaProducao != NULL){
while(siglaCSV != NULL){
char* siglaUpperCase = convertToUpper(siglaProducao);
char* congressoCompleteName = strstr(getNthColumnDataCongresso(iteratorSiglaCongresso, 1)," - ");
congressoCompleteName++;
congressoCompleteName++;
congressoCompleteName++;
//Check if the name OR sigla match of congresso match with the local
//Ponha um strstr aqui tendo o local da producao e o nome do congresso
if((!strcmp(siglaUpperCase,siglaCSV)) || (strstr(localProducao,congressoCompleteName) != NULL)){
delete[] siglaUpperCase;
hasNoQualis = 0;
char* qualis = clean(getNthColumnDataCongresso(iteratorSiglaCongresso, 5));
int pontos = qualisCodeCongressosToInt(qualis,rules);
currentDocente->points[getPosQualisCongresso(qualis)] += pontos;
currentDocente->totalPoints += pontos;
cout << "\t" << clean(getNthColumnDataCongresso(iteratorSiglaCongresso, 5)) << " (" << pontos << ")" << " - " << currentProducao->type << " - " <<currentProducao->title <<" - " << currentProducao->year << endl;
numDeProducoes++;
break;
}
iteratorSiglaCongresso = find(iteratorSiglaCongresso->next,slashN);
siglaCSV = getNthColumnDataCongresso(iteratorSiglaCongresso,4);
}
if(hasNoQualis == 0)
break;
iteratorSiglaCongresso = congressos;
siglaCSV = getNthColumnDataCongresso(iteratorSiglaCongresso,4);
//Separate all words whiting the field take, the next one
siglaProducao = strtok(NULL, " -.,():");
}
if(hasNoQualis == 1){
int pontos = rules[17];
currentDocente->points[17] += pontos;
cout << "\t" <<"Sem Estrato Qualis" << " (" << pontos << ")" << " - " << currentProducao->type << " - " <<currentProducao->title <<" - " << currentProducao->year << endl;
currentDocente->totalPoints += pontos;
numDeProducoes++;
}
strcpy(currentProducao->local, localProducao);
delete[] localProducao;
}
destroyProducao(¤tProducao);
}
}
//Count the number of orientacoes
char* idDocente = new char[257];
long sizeIdDocente = sprintf (idDocente,"%ld", currentDocente->id);
character* txt = createBufferFile(regrasNomeArquivo);
while(txt != NULL){
//Go to the start of the line
char* titleOrientacao = getNthColumnLocalOrientacao(txt,4);
char* idDoDocenteTmp = getNthColumnLocalOrientacao(txt,1);
long idDoDocente = stringToLong(getNthColumnLocalOrientacao(txt,1));
char* typeOrientacao = getNthColumnLocalOrientacao(txt,3);
char* tmpYear = getNthColumnLocalOrientacao(txt,6);
int year = stringToInt(tmpYear);
int pontos = 0;
if((!strcmp(typeOrientacao,"INICIACAO_CIENTIFICA")) && idDoDocente == currentDocente->id && (year >= anoEntrada) && (year <= anoSaida)){
pontos = rules[18];
currentDocente->points[18] += pontos;
currentDocente->totalPoints += pontos;
cout << "\t" << typeOrientacao << " (" << pontos << ")" << " - " << typeOrientacao << " - " << titleOrientacao <<" - " << year << endl;
}else if((!strcmp(typeOrientacao,"TRABALHO_DE_CONCLUSAO_DE_CURSO_GRADUACAO")) && idDoDocente == currentDocente->id && (year >= anoEntrada) && (year <= anoSaida)){
pontos = rules[19];
currentDocente->points[19] += pontos;
currentDocente->totalPoints += pontos;
cout << "\t" << typeOrientacao << " (" << pontos << ")" << " - " << typeOrientacao << " - " << titleOrientacao <<" - " << year << endl;
}else if((!strcmp(typeOrientacao,"Dissertação de mestrado")) && idDoDocente == currentDocente->id && (year >= anoEntrada) && (year <= anoSaida)){
pontos = rules[20];
currentDocente->points[20] += pontos;
currentDocente->totalPoints += pontos;
cout << "\t" << typeOrientacao << " (" << pontos << ")" << " - " << typeOrientacao << " - " << titleOrientacao <<" - " << year << endl;
}else if((!strcmp(typeOrientacao,"Tese de doutorado")) && idDoDocente == currentDocente->id && (year >= anoEntrada) && (year <= anoSaida)){
pontos = rules[21];
currentDocente->points[21] += pontos;
currentDocente->totalPoints += pontos;
cout << "\t" << typeOrientacao << " (" << pontos << ")" << " - " << typeOrientacao << " - " << titleOrientacao <<" - " << year << endl;
}
delete[] titleOrientacao;
delete[] idDoDocenteTmp;
delete[] typeOrientacao;
delete[] tmpYear;
character* deleteme = removeFirstBufferLine(&txt);
destroyBufferFile(&deleteme);
}
currentDocente = currentDocente->next;
cout << "==============================================" << endl;
}
}
}
return sucess;
}
int getPosQualisPeriodico(char* qualisCode){
int pos = -1;
if(qualisCode != NULL){
if(!strcmp(qualisCode,"A1")){
pos = 0;
}else if(!strcmp(qualisCode,"A2")){
pos = 1;
}else if(!strcmp(qualisCode,"B1")){
pos = 2;
}else if(!strcmp(qualisCode,"B2")){
pos = 3;
}else if(!strcmp(qualisCode,"B3")){
pos = 4;
}else if(!strcmp(qualisCode,"B4")){
pos = 5;
}else if(!strcmp(qualisCode,"B5")){
pos = 6;
}else if(!strcmp(qualisCode,"C")){
pos = 7;
}
//0 = sem estrato no qualis ??
}
return pos;
}
int getPosQualisCongresso(char* qualisCode){
int pos = -1;
if(qualisCode != NULL){
if(!strcmp(qualisCode,"A1")){
pos = 9;
}else if(!strcmp(qualisCode,"A2")){
pos = 10;
}else if(!strcmp(qualisCode,"B1")){
pos = 11;
}else if(!strcmp(qualisCode,"B2")){
pos = 12;
}else if(!strcmp(qualisCode,"B3")){
pos = 13;
}else if(!strcmp(qualisCode,"B4")){
pos = 14;
}else if(!strcmp(qualisCode,"B5")){
pos = 15;
}else if(!strcmp(qualisCode,"C")){
pos = 16;
}
}
return pos;
}
char* getNthColumnLocalOrientacao(character* bufferFile, int collumn){
char* data = NULL;
if(bufferFile!= NULL){
if(collumn > 0 || collumn < 7){
switch (collumn) {
case 1:{
int numberOfChars = 0;
character* cur = bufferFile;
//Move to the first letter
cur = cur->next;
//Count the number of characters
while(cur->next != NULL){
if(cur->data == '"'){
break;
}else{
numberOfChars++;
}
cur = cur->next;
}
data = new char[numberOfChars+1];
//Go back to start
cur = bufferFile;
//Jump the first quote
cur = cur->next;
//Copy the string
for(int i=0; i < numberOfChars; i++){
data[i] = cur->data;
cur = cur->next;
}
data[numberOfChars] = '\0';
break;
}
case 2:{
int numberOfChars = 0;
character* cur = bufferFile;
character* start = NULL;
while(cur->next != NULL){
if(cur->data == ',' && cur->prev->data == '"'){
//Move to the first number
cur = cur->next;
//Save it's address
start = cur;
break;
}
cur = cur->next;
}
//Count the number of characters
while(cur->next != NULL){
if(cur->data == ','){
break;
}else{
numberOfChars++;
}
cur = cur->next;
}
//alocate it
data = new char[numberOfChars+1];
//Go back to the start of the data
cur = start;
//Copy the string
for(int i=0; i < numberOfChars; i++){
data[i] = cur->data;
cur = cur->next;
}
data[numberOfChars] = '\0';
break;
}
case 3:{
int numberOfChars = 0;
character* cur = bufferFile;
character* start = NULL;
int numberOfCommas = 0;
int numberOfQuotes = 0;
cur = bufferFile;
start = NULL;
while(cur->next != NULL){
if(cur->data == '"'){
numberOfQuotes++;
}
if(cur->data == ','){
numberOfCommas++;
}
if((numberOfCommas == 2) && (numberOfQuotes == 2)){
//Move to the first character
cur = cur->next->next;
start = cur;
break;
}
cur = cur->next;
}
//Count the number of characters
while(cur->next != NULL){
if(cur->data == '"'){
break;
}else{
numberOfChars++;
}
cur = cur->next;
}
//alocate it
data = new char[numberOfChars+1];
//Go back to the start of the data
cur = start;
//Copy the string
for(int i=0; i < numberOfChars; i++){
data[i] = cur->data;
cur = cur->next;
}
data[numberOfChars] = '\0';
break;
}
case 4:{
character* cur = bufferFile;
character* start = NULL;
int numberOfChars = 0;
int numberOfCommas = 0;
int numberOfQuotes = 0;
cur = bufferFile;
start = NULL;
while(cur->next != NULL){
if(cur->data == '"'){
numberOfQuotes++;
}
if(cur->data == ','){
numberOfCommas++;
}
if((numberOfCommas == 3) && (numberOfQuotes == 4)){
//Move to the first character
cur = cur->next->next;
break;
}
cur = cur->next;
}
start = cur;
//Count the number of characters
while(cur->next != NULL){
if(cur->data == '"'){
break;
}else{
numberOfChars++;
}
cur = cur->next;
}
//alocate it
data = new char[numberOfChars+1];
//Go back to the start of the data
cur = start;
//Copy the string
for(int i=0; i < numberOfChars; i++){
data[i] = cur->data;
cur = cur->next;
}
data[numberOfChars] = '\0';
break;
}
case 5:{
}
case 6:{
character* cur = bufferFile;
character* start = NULL;
int numberOfChars = 0;
int numberOfCommas = 0;
int numberOfQuotes = 0;
int numberOfMarks = 0;
cur = bufferFile;
start = NULL;
//Go to the last comma
while(cur->next != NULL){
if(cur->data == ',' && cur->prev->data == '"'){
numberOfMarks++;
}
if(numberOfMarks == 4){
break;
}
cur = cur->next;
}
//Go to the first number
cur = cur->next;
//save its address
start = cur;
//Count the number of characters
while(cur->next != NULL){
if(cur->data == '\n'){
break;
}else{
numberOfChars++;
}
cur = cur->next;
}
numberOfChars--;
//alocate it
data = new char[numberOfChars+1];
//Go back to the start of the data
cur = start;
//Copy the string
for(int i=0; i < numberOfChars; i++){
data[i] = cur->data;
cur = cur->next;
}
data[numberOfChars] = '\0';
break;
}
}
}
}
return data;
}
char* getNthColumnLocal(character* bufferFile){
char* string = NULL;
if(bufferFile != NULL){
char* slashN = new char[2];
slashN[0] = '\n';
slashN[1] = '\0';
//Go until the end of the string
character* iterator = bufferFile;
while(iterator->next != NULL){
iterator = iterator->next;
}
delete[] slashN;
while(iterator->prev != NULL){
if(iterator->data == ',' && iterator->prev->data == '\"'){
//The last letter of the field local
iterator = iterator->prev->prev;
break;
}
iterator = iterator->prev;
}
while(iterator->prev != NULL){
if(iterator->prev->data == '\"'){
//Iterator points to first letter
break;
}
iterator = iterator->prev;
}
character* start = iterator;
character* end = NULL;
int numberOfChars = 0;
//Move through the line char by char
while(iterator->next != NULL && iterator->data != '\"'){
//Count how many character there are
numberOfChars++;
iterator = iterator->next;
}
end = iterator;
//Alocate a new string
string = new char[(numberOfChars+1)];
if(string != NULL){
//Load the first character again to move throught the line
iterator = start;
//Copy all chars from the buffer file to the new char array
for(int i=0; i<(numberOfChars); i++){
string[i] = iterator->data;
iterator = iterator->next;
}
//Put the special character at it's end
string[numberOfChars] = '\0';
}
}
return string;
}
char* convertToUpper(char* str){
char* upperCaseStr = NULL;
if(str != NULL){
upperCaseStr = new char[strlen(str)+1];
for(int i=0; i<strlen(str); i++){
upperCaseStr[i] = toupper(str[i]);
}
upperCaseStr[strlen(str)] = '\0';
}
return upperCaseStr;
}
char* getNthColumnDataCongresso(character* bufferFile, int position){
//A buffer line with a copy of the N position data
char* nthText = NULL;
if(bufferFile != NULL){
if(position > 0){
//The first character of the right data
character* startPoint = NULL;
//The last character of the right data
character* finishPoint = NULL;
int numberOfCommas = 0;
character* iterator = bufferFile;
//Make a backup of the first character address
character* firstCharAddress = iterator;
//Count the number of VALID commas int the text
while(iterator->next != NULL){
if(iterator->prev != NULL && iterator->next != NULL && iterator->prev->data == '\"' && iterator->data == ',' && iterator->next->data == '\"'){
numberOfCommas++;
}
iterator = iterator->next;
}
iterator = firstCharAddress;
//The required collumn does not exist
if(position > (numberOfCommas+1)){
return NULL;
//The last collumn is bein required
}else if (position == (numberOfCommas+1)){
numberOfCommas = 0;
//Goes until the given collumn
while(iterator->next != NULL){
if(iterator->prev != NULL && iterator->next != NULL && iterator->prev->data == '\"' && iterator->data == ',' && iterator->next->data == '\"'){
numberOfCommas++;
}
//Everything behind this comma until another is the wanted data
if(numberOfCommas == (position-1)){
//Count how many valid characters there's (Quotes are not valid)
character* commaPosition = iterator;
int numberOfChars = 0;
//Go foward one char, to ignore read the comma
iterator = iterator->next;
while(iterator->next != NULL){
//everything before this quotes, belongs to other data
if(iterator->prev != NULL && iterator->next != NULL && iterator->prev->data == '\"' && iterator->data == ',' && iterator->next->data == '\"'){
break;
}
//if the character is diferent of a quote
if(iterator->data != '\"'){
numberOfChars++;
}
iterator = iterator->next;
}
//Alocate the string to receive each character
nthText = new char[numberOfChars+1];
//The extra char is for \0
nthText[numberOfChars] = '\0';
//The last valid character
//int i = (numberOfChars-1);
int i = 0;
//If the text was successfully allocated
if(nthText != NULL){
iterator = commaPosition->next;
while(iterator->next != NULL){
//Everything before this quotes, belongs to other data
if(iterator->prev != NULL && iterator->next != NULL && iterator->prev->data == '\"' && iterator->data == ',' && iterator->next->data == '\"'){
break;
}
//if the character is diferent of a quote
if(iterator->data != '"'){
nthText[i] = iterator->data;
i++;
}
iterator = iterator->next;
}
}else{
cerr << "Error: Function: getNthColumnData. Desc: error while allocating nthText." << endl;
}
//Make the iterator go back to the position where it was
iterator = commaPosition;
//End the function
break;
}
iterator = iterator->next;
}
//The collumn given is anyone but the last
}else if((position < (numberOfCommas+1)) && position > 0){
numberOfCommas = 0;
//Goes until the given collumn
while(iterator->next != NULL){
if(iterator->prev != NULL && iterator->next != NULL && iterator->prev->data == '\"' && iterator->data == ',' && iterator->next->data == '\"'){
numberOfCommas++;
}
//Everything behind this comma until another is the wanted data
if(numberOfCommas == position){
//Count how many valid characters there's (Quotes are not valid)
character* commaPosition = iterator;
int numberOfChars = 0;
//Go backwards one char, to ignore read the comma
iterator = iterator->prev;
while(iterator->prev != NULL){
//everything before this quotes, belongs to other data
if(iterator->prev != NULL && iterator->next != NULL && iterator->prev->data == '\"' && iterator->data == ',' && iterator->next->data == '\"'){
break;
}
//if the character is diferent of a quote
if(iterator->data != '\"'){
numberOfChars++;
}
iterator = iterator->prev;
}
//Alocate the string to receive each character
nthText = new char[numberOfChars+1];
//The extra char is for \0
nthText[numberOfChars] = '\0';
//The last valid character
int i = (numberOfChars-1);
//If the text was successfully allocated
if(nthText != NULL){
iterator = commaPosition->prev;
while(iterator->prev != NULL){
//Everything before this quotes, belongs to other data
if(iterator->prev != NULL && iterator->next != NULL && iterator->prev->data == '\"' && iterator->data == ',' && iterator->next->data == '\"'){
break;
}
//if the character is diferent of a quote
if(iterator->data != '"'){
nthText[i] = iterator->data;
i--;
}
iterator = iterator->prev;
}
}else{
cerr << "Error: Function: getNthColumnData. Desc: error while allocating nthText." << endl;
}
//Make the iterator go back to the position where it was
iterator = commaPosition;
//End the function
break;
}
iterator = iterator->next;
}
}
}
}
return nthText;
}
int numberOfLinesBufferFile(character* congressosCSV){
int numberOfLines = 0;
if(congressosCSV!= NULL){
char* slashN = new char[2];
slashN[0] = '\n';
slashN[1] = '\0';
//Jump the header
character* iterator = congressosCSV;
while(iterator = find(iterator->next,slashN)){
numberOfLines++;
iterator = iterator->next;
}
}
return (numberOfLines+1);
}
char* clean2(char* string){
char* cleanedString = NULL;
if(string != NULL){
cleanedString = new char[strlen(string)];
int lastPos = 0;
for(int i=0; i<strlen(string) && string[i] != '\n';i++){
cleanedString[i] = string[i];
lastPos = i;
}
cleanedString[lastPos+1] = '\0';
}
return cleanedString;
}
char* clean(char* string){
char* cleanedString = NULL;
if(string != NULL){
cleanedString = new char[strlen(string)];
int lastPos = 0;
for(int i=0; i<strlen(string) && string[i] != '\n';i++){
cleanedString[i] = string[i];
lastPos = i;
}
cleanedString[lastPos] = '\0';
}
return cleanedString;
}
char* stringToUpperCase(char* string){
char* upperCaseString = NULL;
if(string != NULL){
upperCaseString = new char[strlen(string)+1];
for(int i=0; i<strlen(string); i++){
upperCaseString[i] = toupper(string[i]);
}
upperCaseString[strlen(string)] = '\0';
}
return upperCaseString;
}
char* loadAreaAvaliacao(const char* filePath){
char* areaDeAvaliacao = NULL;
if(filePath != NULL){
//Load the rule file into memory
character* ruleTxt = createBufferFile(filePath);
if(ruleTxt != NULL){
//Remove the header of the file
character* header = removeFirstBufferLine(&ruleTxt);
destroyBufferFile(&header);
//Get the "area de avaliacao"
character* area = removeFirstBufferLine(&ruleTxt);
areaDeAvaliacao = bufferStringToString(area);
//remove the '\n' from the end of the line
areaDeAvaliacao[strlen(areaDeAvaliacao)-1] = '\0' ;
destroyBufferFile(&area);
}
return areaDeAvaliacao;
}
return areaDeAvaliacao;
}
int qualisCodePeriodicosToInt(char* qualisCode ,int* rules){
int value = 0;
if(qualisCode != NULL){
if(rules != NULL){
if(!strcmp(qualisCode,"A1")){
value = rules[0];
}else if(!strcmp(qualisCode,"A2")){
value = rules[1];
}else if(!strcmp(qualisCode,"B1")){
value = rules[2];
}else if(!strcmp(qualisCode,"B2")){
value = rules[3];
}else if(!strcmp(qualisCode,"B3")){
value = rules[4];
}else if(!strcmp(qualisCode,"B4")){
value = rules[5];
}else if(!strcmp(qualisCode,"B5")){
value = rules[6];
}else if(!strcmp(qualisCode,"C")){
value = rules[7];
}
//0 = sem estrato no qualis ??
}
}
return value;
}
int qualisCodeCongressosToInt(char* qualisCode ,int* rules){
int value = 0;
if(qualisCode != NULL){
if(rules != NULL){
if(!strcmp(qualisCode,"A1")){
value = rules[9];
}else if(!strcmp(qualisCode,"A2")){
value = rules[10];
}else if(!strcmp(qualisCode,"B1")){
value = rules[11];
}else if(!strcmp(qualisCode,"B2")){
value = rules[12];
}else if(!strcmp(qualisCode,"B3")){
value = rules[13];
}else if(!strcmp(qualisCode,"B4")){
value = rules[14];
}else if(!strcmp(qualisCode,"B5")){
value = rules[15];
}else if(!strcmp(qualisCode,"C")){
value = rules[16];
}
//0 = sem estrato no qualis ??
}
}
return value;
}
void addDictionaryWord(dictionary** dictionaryToAdd, char* word, int value){
if((*dictionaryToAdd)!= NULL ){
if(word != NULL){
//If the last word was not set yet
if((*dictionaryToAdd)->last == NULL){
dictionary* iterator = (*dictionaryToAdd);
//Go until the last word
while(iterator->next != NULL){
iterator = iterator->next;
}
//Save its address
(*dictionaryToAdd)->last = iterator;
}
//create a new word and add it
dictionary* newWord = new dictionary[1];
if(newWord != NULL){
newWord->next = NULL;
newWord->value = value;
strcpy(newWord->word,word);
newWord->prev = (*dictionaryToAdd)->last;
(*dictionaryToAdd)->last->next = newWord;
(*dictionaryToAdd)->last = newWord;
}
}
}else{
(*dictionaryToAdd) = createDictionary(word,value);
}
}
char* getNthColumnDataFromCur(character* bufferFile, int position){
//A buffer line with a copy of the N position data
char* nthText = NULL;
if(bufferFile != NULL){
if(position > 0){
//The first character of the right data
character* startPoint = NULL;
//The last character of the right data
character* finishPoint = NULL;
int numberOfCommas = 0;
character* iterator = bufferFile;
//Make a backup of the first character address
character* firstCharAddress = iterator;
//Count the number of commas int the text
while(iterator->next != NULL){
if(iterator->data == ','){
numberOfCommas++;
}
iterator = iterator->next;
}
iterator = firstCharAddress;
//The required collumn does not exist
if(position > (numberOfCommas+1)){
return NULL;
//The last collumn is bein required
}else if (position == (numberOfCommas+1)){
numberOfCommas = 0;
//Goes until the given collumn
while(iterator->next != NULL){
if(iterator->data == ','){
numberOfCommas++;
}
//Everything behind this comma until another is the wanted data
if(numberOfCommas == (position-1)){
//Count how many valid characters there's (Quotes are not valid)
character* commaPosition = iterator;
int numberOfChars = 0;
//Go foward one char, to ignore read the comma
iterator = iterator->next;
while(iterator->next != NULL){
//everything before this quotes, belongs to other data
if(iterator->data == ','){
break;
}
//if the character is diferent of a quote
if(iterator->data != '\"'){
numberOfChars++;
}
iterator = iterator->next;
}
//Alocate the string to receive each character
nthText = new char[numberOfChars+1];
//The extra char is for \0
nthText[numberOfChars] = '\0';
//The last valid character
//int i = (numberOfChars-1);