9511_project03

project 3 for algorithms & programming I (9511) prof. Cardozo
Index Commits Files Refs README LICENSE
commit 0e62a1459f3dfa33a7cdc1da70a2205cdce7dcb8
parent bc9c7b0060e88220486c9e3a879ce7ff82218d85
Author: klewer-martin <martin.cachari@gmail.com>
Date:   Fri, 23 Jul 2021 20:36:55 -0300

Update;

Diffstat:
M.gitignore | 1+
MMakefile | 2+-
Mexamples/input_gen.py | 4++--
Msource/cla.c | 14+++++++++-----
Msource/io.c | 28+++++++++++++++++++---------
Msource/main.c | 6++++++
Msource/user.c | 11+++++++----
Dtest.sh | 22----------------------
8 files changed, 45 insertions(+), 43 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -5,3 +5,4 @@
 *.xml
 *.bin
 main
+*.sh
diff --git a/Makefile b/Makefile
@@ -1,5 +1,5 @@
 CC=gcc
-CFLAGS=-g -pedantic -Wall
+CFLAGS=-pedantic -Wall
 SRCFOLDER=source
 HFOLDER=include
 PROGNAME=main
diff --git a/examples/input_gen.py b/examples/input_gen.py
@@ -2,7 +2,7 @@ from string import digits
 from time import strftime, gmtime
 from random import randint, choice
 
-LINES = 5000
+LINES = 500000000
 
 # OUTPUT:
 #     ID_TRANSACCION, ID_USUARIO, FECHA, MONTO, NUMERO DE TRAJETA, DESCRIPCION
@@ -16,7 +16,7 @@ def card_number_generator():
 def generate_file(max_lines):
     id_transaction_base = 123400
     id_user_base = 1
-    id_user_max = 200
+    id_user_max = 20000
     amount_base = 1
     amount_max = 10000
     for i in range(max_lines):
diff --git a/source/cla.c b/source/cla.c
@@ -20,9 +20,11 @@ status_t validate_arguments(int argc,  char **argv)
 /* No chequea argumentos ya que se considera subfuncion de validate_arguments */
 status_t check_flags_position(int argc, char **argv)
 {
+    size_t i;
     bool prev_was_flag = 0;
     bool current_arg_is_flag = 0;
-    for(size_t i = 1; i < argc; i++, prev_was_flag = current_arg_is_flag) {
+
+    for(i = 1; i < argc; i++, prev_was_flag = current_arg_is_flag) {
         if(argv[i][0] == '-') current_arg_is_flag = 1;
         else current_arg_is_flag = 0;
 
@@ -33,7 +35,7 @@ status_t check_flags_position(int argc, char **argv)
 
 status_t check_flags_repeated(int argc, char **argv)
 {
-    size_t i, j, fflags_index;
+    size_t i, j, k, fflags_index;
     int founded_flags[FLAGS_MAX];
 
     /* Inicializa a -1 para evitar confusiones con 0 */
@@ -42,7 +44,7 @@ status_t check_flags_repeated(int argc, char **argv)
     for(i = 1, fflags_index = 0; i <= (argc - 2); i += 2) {
         for(j = 0; j < FLAGS_MAX; j++) {
             if(!strcmp(argv[i], available_flags[j])) {
-                for(size_t k = 0; k < FLAGS_MAX; k++) {
+                for(k = 0; k < FLAGS_MAX; k++) {
                     if(founded_flags[k] == j) return ERROR_FLAG_REPEATED;
                 }
                 founded_flags[fflags_index++] = j;
@@ -57,9 +59,11 @@ status_t check_flags_repeated(int argc, char **argv)
 status_t cla_setup(int argc, char **argv, cla_t *cla)
 {
     char *endptr;
+    size_t i;
+    flags_t f;
 
-    for(size_t i = 1; i < argc; i += 2) {
-        for(flags_t f = FLAG_FMT; f < FLAGS_MAX; f++) {
+    for(i = 1; i < argc; i += 2) {
+        for(f = FLAG_FMT; f < FLAGS_MAX; f++) {
             if(!strcmp(available_flags[f], argv[i])) {
                 switch (f) {
                     case FLAG_FMT: strcpy((*cla)->fmt, argv[i + 1]); break;
diff --git a/source/io.c b/source/io.c
@@ -131,9 +131,11 @@ status_t string_split(char *s, char **data, char *delim)
 
 status_t destroy_data(char **data)
 {
+    size_t i;
+
     if(data == NULL) return ERROR_NULL_POINTER;
 
-    for(size_t i = 0; i < INPUT_FILE_FIELDS; i++) {
+    for(i = 0; i < INPUT_FILE_FIELDS; i++) {
         free(data[i]);
         data[i] = NULL;
     }
@@ -144,10 +146,10 @@ status_t destroy_data(char **data)
 
 status_t export_data(cla_t cla, const user_t *users, size_t size)
 {
-    if(users == NULL) return ERROR_NULL_POINTER;
-
     FILE *fo;
 
+    if(users == NULL) return ERROR_NULL_POINTER;
+
     if((fo = fopen(cla->fo, "wt")) == NULL)
         return ERROR_OPENING_FILE;
 
@@ -163,10 +165,12 @@ status_t export_data(cla_t cla, const user_t *users, size_t size)
 
 status_t export_data_as_csv(FILE *fo, const user_t *users, size_t size)
 {
+    size_t i;
+
     if(fo == NULL || users == NULL)
         return ERROR_NULL_POINTER;
 
-    for(size_t i = 0; i < size; i++)
+    for(i = 0; i < size; i++)
         fprintf(fo, "%ld%s%ld%s%ld\n", users[i]->id, CSV_OUTPUT_DELIM,\
                 users[i]->credit, CSV_OUTPUT_DELIM, users[i]->debt);
 
@@ -175,11 +179,13 @@ status_t export_data_as_csv(FILE *fo, const user_t *users, size_t size)
 
 status_t export_data_as_xml(FILE *fo, const user_t *users, size_t size)
 {
+    size_t i;
+
     if(fo == NULL || users == NULL)
         return ERROR_NULL_POINTER;
 
     fprintf(fo, "%s\n%s\n", XML_HEADER, XML_ROOT_OPEN);
-    for(size_t i = 0; i < size; i++) {
+    for(i = 0; i < size; i++) {
         fprintf(fo, "\t%s\n", XML_ROW_OPEN);
         fprintf(fo, "\t\t%s%ld%s\n", XML_ID_OPEN, users[i]->id, XML_ID_CLOSE);
         fprintf(fo, "\t\t%s%ld%s\n", XML_CREDIT_OPEN, users[i]->credit, XML_CREDIT_CLOSE);
@@ -193,13 +199,17 @@ status_t export_data_as_xml(FILE *fo, const user_t *users, size_t size)
 
 void clean_buffer(char *buf)
 {
-    for(size_t i = 0; i < BUFFER_SIZE; i++)
+    size_t i;
+
+    for(i = 0; i < BUFFER_SIZE; i++)
         buf[i] = '\0';
 }
 
 void clean_data(char **data)
 {
-    for(size_t i = 0; i < INPUT_FILE_FIELDS; i++) {
+    size_t i;
+
+    for(i = 0; i < INPUT_FILE_FIELDS; i++) {
         free(data[i]);
         data[i] = NULL;
     }
@@ -207,10 +217,10 @@ void clean_data(char **data)
 
 status_t get_date(time_t *e, char **data)
 {
-    if(e == NULL || data == NULL) return ERROR_NULL_POINTER;
-
     struct tm tm;
 
+    if(e == NULL || data == NULL) return ERROR_NULL_POINTER;
+
     /* Desactiva el horario de verano */
     tm.tm_isdst = 0;
 
diff --git a/source/main.c b/source/main.c
@@ -7,6 +7,7 @@
 /* "ca" - creditos ascendentes | "cd" - creditos descendentes
  * "da" - debitos ascendentes  | "dd" - debitos descendentes */
 #define SORTING_ORDER    "cd"
+#define PRINT_EXIT_SUCCESS_MSG
 
 int main (int argc, char *argv[])
 {
@@ -57,11 +58,16 @@ int main (int argc, char *argv[])
         return st;
     }
 
+
+#ifdef PRINT_EXIT_SUCCESS_MSG
+
     /* Imprime un mensaje para darle a conocer al usuario
      * que todo se ejecuto correctamente    */
     printf("\n%s\n%s%ld\n%s%ld\n", EXIT_SUCCESS_MSG, USERS_REGISTERED_MSG,\
             size, PROCESED_LINES_MSG, cla->parsed_lines);
 
+#endif
+
     cla_destroy(&cla);
     destroy_users(users, size);
 
diff --git a/source/user.c b/source/user.c
@@ -21,11 +21,11 @@ void user_clean(user_t usr)
 
 status_t user_set_data(user_t *user, char **data) 
 {
-    if(data == NULL || user == NULL) return ERROR_NULL_POINTER;
-
     char *endptr;
     long amount;
 
+    if(data == NULL || user == NULL) return ERROR_NULL_POINTER;
+
     (*user)->id = strtol(data[POS_USER_ID], &endptr, 10);
     if(*endptr != '\0') return ERROR_CORRUPT_DATA;
 
@@ -53,7 +53,8 @@ user_t user_dup(user_t src)
 
 user_t user_find(const user_t *users, int id, size_t size)
 {
-    for(size_t i = 0; i < size; i++) {
+    size_t i;
+    for(i = 0; i < size; i++) {
         if(users[i]->id == id) {
             return users[i];
         }
@@ -63,9 +64,11 @@ user_t user_find(const user_t *users, int id, size_t size)
 
 status_t destroy_users(user_t *users, size_t size)
 {
+    size_t i;
+
     if(users == NULL) return ERROR_NULL_POINTER;
 
-    for(size_t i = 0; i < size; i++)
+    for(i = 0; i < size; i++)
         free(users[i]);
 
     free(users);
diff --git a/test.sh b/test.sh
@@ -1,22 +0,0 @@
-#!/bin/sh
-
-printf ">>Formato de salida: csv\n"
-
-./main -fmt csv -out output.csv -in examples/test_file_20.csv -ti 1320498000 -tf 1320498046
-./main -fmt csv -out output.csv -in examples/test_file_2k.csv -ti 1320498000 -tf 1325499000
-./main -fmt csv -out output.csv -in examples/test_file_50.csv -ti 1320498000 -tf 1320498049
-./main -fmt csv -out output.csv -in examples/test_file_500.csv -ti 1320498000 -tf 1320529000
-./main -fmt csv -out output.csv -in examples/test_file_5k.csv -ti 1320498000 -tf 1320529000
-./main -fmt csv -out output.csv -in examples/test_file_50k.csv -ti 1320498000 -tf 1420529000
-./main -fmt csv -out output.csv -in examples/test_file_500k.csv -ti 1320498000 -tf 1420529000
-
-
-printf "\n>>Formato de salida: xml\n"
-./main -fmt xml -out output.xml -in examples/test_file_50.csv -ti 1320498000 -tf 1320498049
-./main -fmt xml -out output.xml -in examples/test_file_5k.csv -ti 1320498000 -tf 1360498049
-./main -fmt xml -out output.xml -in examples/test_file_5m.csv -ti 1320498000 -tf 1360498049
-./main -fmt xml -out output.xml -in -ti 1320498000 -tf 1360498049
-./main -out output.xml -fmt xml -in examples/test_file_5k.csv -ti 1320498000 -tf 1360498049
-./main -out output.xml -fmt xml -in examples/test_file_5k.csv -tf 132049000 -ti 10498049
-./main -fmt rar -out output.csv -in examples/test_file_5k.csv -ti 1320498000 -tf 1360498049
-./main -in examples/test_file_5k.csv -fmt xml -out output.xml -ti 1320498000 -tf 1360498049