Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <dirent.h>
- #include "csv_converter.h"
- #include "util_converter.h"
- #include "hulke.h"
- #define NUMBER_OF_CHARACTERS_IN_QUESTION 500
- #define NUMBER_OF_CHARACTERS_IN_TEACHER 500
- #define NUMBER_OF_CHARACTERS_IN_DISCIPLINE 500
- #define NUMBER_OF_CHARACTERS_IN_PATH 500
- #define NUMBER_OF_QUESTIONS 100000
- #define NUMBER_OF_TEACHERS 100000
- #define NUMBER_OF_DISCIPLINES 100000
- #define NUMBER_OF_RESPONSES 200000
- #define FILENAME_QUESTION "questao.csv"
- #define FILENAME_TEACHER "professor.csv"
- #define FILENAME_DISCIPLINE "disciplina.csv"
- #define FILENAME_RESPONSE "resposta.csv"
- #define STRING_HEADER_QUESTION "id,descricao"
- #define STRING_HEADER_TEACHER "id,nome"
- #define STRING_HEADER_DISCIPLINE "id,descricao,id_professor"
- #define STRING_HEADER_RESPONSE "id_questionario,id_disciplina,id_questao,ip,inicio,fim,arquivo,resposta"
- #define COLUMN_START_QUESTIONNAIRE 11
- #define COLUMN_ID_QUESTIONNAIRE 0
- #define COLUMN_START_DATE 1
- #define COLUMN_END_DATE 2
- #define COLUMN_IP 3
- #define INT_SIZE_IN_CHAR 10
- struct {
- int length;
- char* description[NUMBER_OF_QUESTIONS];
- } cache_file_question = {0, {}};
- struct {
- int length;
- char* name[NUMBER_OF_TEACHERS];
- } cache_file_teacher = {0, {}};
- struct {
- int length;
- char* description[NUMBER_OF_DISCIPLINES],
- * id_teacher[NUMBER_OF_DISCIPLINES];
- } cache_file_discipline = {0, {}};
- struct {
- int length,
- id_question[NUMBER_OF_RESPONSES],
- id_discipline[NUMBER_OF_RESPONSES];
- } cache_file_response = {0, {}, {}};
- int blob;
- int main(argc, argv)
- int argc;
- char** argv;
- {
- DIR* directory;
- struct dirent* file;
- FILE* fp_question,
- * fp_teacher,
- * fp_discipline,
- * fp_response;
- int responses_column,
- number_of_file = 0;
- char string_question[NUMBER_OF_CHARACTERS_IN_QUESTION] = {},
- string_teacher[NUMBER_OF_CHARACTERS_IN_TEACHER] = {},
- string_discipline[NUMBER_OF_CHARACTERS_IN_DISCIPLINE] = {},
- path_to_file[NUMBER_OF_CHARACTERS_IN_PATH] = {};
- if(argc != 2) {
- printf("�� necess��rio especificar um diret��rio. Formato:\n[./]%s um/diretorio/aqui\n", *argv);
- exit(1);
- } else
- directory = opendir(argv[1]);
- open_file(&fp_question, FILENAME_QUESTION, STRING_HEADER_QUESTION);
- open_file(&fp_teacher, FILENAME_TEACHER, STRING_HEADER_TEACHER);
- open_file(&fp_discipline, FILENAME_DISCIPLINE, STRING_HEADER_DISCIPLINE);
- open_file(&fp_response, FILENAME_RESPONSE, STRING_HEADER_RESPONSE);
- putchar('\n');
- while(IS_NOT_NULL(file = readdir(directory))) {
- if(file->d_type != DT_REG)
- continue;
- printf("----------- Arquivo %d - %s -----------\n\n", ++number_of_file, file->d_name);
- path_to_file[i] = NUL;
- strcat(path_to_file, argv[1]);
- strcat(path_to_file, file->d_name);
- if(IS_NULL(csvc_open_file(path_to_file))) {
- printf("Erro ao abrir o arquivo: \"%s\"\n", file->d_name);
- exit(1);
- }
- if(csvc_next_record() && csvc_load_record()) {
- responses_column = COLUMN_START_QUESTIONNAIRE;
- while(extract_question_teacher_discipline(csvc_field_value(responses_column++), string_question, string_teacher, string_discipline)) {
- int id_question;
- if(IS_EOF(id_question=find_in_array(string_question, cache_file_question.description, cache_file_question.length))) {
- cache_file_question.description[cache_file_question.length] = malloc(strlen(string_question) + 1);
- strcpy(cache_file_question.description[cache_file_question.length], string_question);
- cache_file_question.length++;
- fprintf(fp_question, "%d,\"%s\"\n", id_question=cache_file_question.length, string_question);
- } else
- id_question++;
- cache_file_response.id_question[cache_file_response.length] = id_question;
- int id_teacher;
- if(IS_EOF(id_teacher=find_in_array(string_teacher, cache_file_teacher.name, cache_file_teacher.length))) {
- cache_file_teacher.name[cache_file_teacher.length] = malloc(strlen(string_teacher) + 1);
- strcpy(cache_file_teacher.name[cache_file_teacher.length], string_teacher);
- cache_file_teacher.length++;
- fprintf(fp_teacher, "%d,\"%s\"\n", id_teacher=cache_file_teacher.length, string_teacher);
- } else
- id_teacher++;
- char string_id_teacher[INT_SIZE_IN_CHAR];
- itoa(id_teacher, string_id_teacher);
- int id_discipline,
- discipline_id_teacher;
- if( IS_EOF(id_discipline=find_two_in_arrays(string_discipline, string_id_teacher,
- cache_file_discipline.description, cache_file_discipline.id_teacher,
- cache_file_discipline.length))
- ) {
- cache_file_discipline.description[cache_file_discipline.length] = malloc(strlen(string_discipline) + 1);
- strcpy(cache_file_discipline.description[cache_file_discipline.length], string_discipline);
- cache_file_discipline.id_teacher[cache_file_discipline.length] = malloc(strlen(string_id_teacher) + 1);
- strcpy(cache_file_discipline.id_teacher[cache_file_discipline.length], string_id_teacher);
- cache_file_discipline.length++;
- fprintf(fp_discipline, "%d,\"%s\",%s\n", id_discipline=cache_file_discipline.length, string_discipline, string_id_teacher);
- } else
- id_discipline++;
- cache_file_response.id_discipline[cache_file_response.length] = id_discipline;
- cache_file_response.length++;
- }
- printf("1) Quest��es, professores e disciplinas extra��dos e adicionados respectivamente nos arquivos:\n\t%s, %s e %s\n", FILENAME_QUESTION, FILENAME_TEACHER, FILENAME_DISCIPLINE);
- }
- char* column_id_questionnaire,
- * column_ip,
- * column_start_date,
- * column_end_date;
- int cache_position;
- while(IS_NOT_EOF(csvc_load_record())) {
- responses_column = COLUMN_START_QUESTIONNAIRE;
- column_id_questionnaire = csvc_field_value(COLUMN_ID_QUESTIONNAIRE);
- column_ip = csvc_field_value(COLUMN_IP);
- column_start_date = csvc_field_value(COLUMN_START_DATE);
- column_end_date = csvc_field_value(COLUMN_END_DATE);
- while(responses_column < csvc_record.length) {
- cache_position = responses_column - COLUMN_START_QUESTIONNAIRE;
- fprintf(fp_response, "\"%s\",%d,%d,\"%s\",\"%s\",\"%s\",\"%s\",\"%s\"\n", column_id_questionnaire,
- cache_file_response.id_discipline[cache_position],
- cache_file_response.id_question[cache_position],
- column_ip,
- column_start_date,
- column_end_date,
- file->d_name,
- csvc_field_value(responses_column)
- );
- responses_column++;
- }
- }
- cache_file_response.length = 0;
- printf("2)Respostas foram extra��das e adicionadas no arquivo: %s\n", FILENAME_RESPONSE);
- if(IS_NOT_EOF(csvc_close_file()))
- printf("\n---Conclu��do----------------------\n\n\n");
- }
- fclose(fp_question);
- fclose(fp_teacher);
- fclose(fp_discipline);
- fclose(fp_response);
- printf("\n--------------------------------\nConvers��o conclu��da com sucesso!\n\n");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment