9511_project03

project 3 for algorithms & programming I (9511) prof. Cardozo
Index Commits Files Refs README LICENSE
commit b0bd63f5cbe875194b8929d20802394ca794da5a
parent da304d4497262a05bfcee0f9d5d8e0f08a1c9d6d
Author: Martin J. Klöckner <64109770+klewer-martin@users.noreply.github.com>
Date:   Sun, 25 Jul 2021 17:07:55 -0300

Merge pull request #2 from klewer-martin/user_module

Update;
Diffstat:
MMakefile | 37++++++++++++++++++++++++++++++++-----
Mexamples/input_gen.py | 2+-
Minclude/io.h | 19+++++++++----------
Minclude/sort.h | 2+-
Minclude/status.h | 12++++++++----
Minclude/user.h | 14+++++++++-----
Msource/cla.c | 19++++++++++---------
Msource/io.c | 1+
Msource/main.c | 6+++---
9 files changed, 74 insertions(+), 38 deletions(-)
diff --git a/Makefile b/Makefile
@@ -6,10 +6,10 @@ PROGNAME=main
 
 all: main clean
 
-main: main.o cla.o status.o io.o sort.o user.o
+main: cla.o status.o sort.o io.o main.o user.o 
     $(CC) $(CFLAGS) main.o cla.o status.o io.o sort.o user.o -o $(PROGNAME)
 
-main.o: $(HFOLDER)/cla.h $(HFOLDER)/status.h
+main.o: $(HFOLDER)/cla.h $(HFOLDER)/status.h $(HFOLDER)/user.h
     $(CC) $(CFLAGS) -c $(SRCFOLDER)/main.c
 
 cla.o: $(HFOLDER)/cla.h $(HFOLDER)/status.h
@@ -18,14 +18,41 @@ cla.o: $(HFOLDER)/cla.h $(HFOLDER)/status.h
 status.o: $(HFOLDER)/status.h
     $(CC) $(CFLAGS) -c $(SRCFOLDER)/status.c
 
-io.o: $(HFOLDER)/status.h
+io.o: $(HFOLDER)/status.h $(HFOLDER)/user.h
     $(CC) $(CFLAGS) -c $(SRCFOLDER)/io.c
 
-sort.o: $(HFOLDER)/status.h
+sort.o: $(HFOLDER)/status.h $(HFOLDER)/user.h
     $(CC) $(CFLAGS) -c $(SRCFOLDER)/sort.c
 
-user.o: $(HFOLDER)/status.h
+user.o: $(HFOLDER)/status.h $(HFOLDER)/user.h
     $(CC) $(CFLAGS) -c $(SRCFOLDER)/user.c
 
 clean:
     rm *.o
+
+run20:
+    ./main -fmt csv -out output.csv -in examples/test_file_20.csv -ti 1320498000 -tf 1320498046
+
+run2k:
+    ./main -fmt csv -out output.csv -in examples/test_file_2k.csv -ti 1320498000 -tf 1325499000
+
+run50:
+    ./main -fmt csv -out output.csv -in examples/test_file_50.csv -ti 1320498000 -tf 1320498049
+
+run500:
+    ./main -fmt csv -out output.csv -in examples/test_file_500.csv -ti 1320498000 -tf 1320529000
+
+run5k:
+    ./main -fmt csv -out output.csv -in examples/test_file_5k.csv -ti 1320498000 -tf 1320529000
+
+run50k:
+    ./main -fmt csv -out output.csv -in examples/test_file_50k.csv -ti 1320498000 -tf 1420529000
+
+run500k:
+    ./main -fmt csv -out output.csv -in examples/test_file_500k.csv -ti 1320498000 -tf 1420529000
+
+run50xml:
+    ./main -fmt xml -out output.xml -in examples/test_file_50.csv -ti 1320498000 -tf 1320498049
+
+run5kxml:
+    ./main -fmt xml -out output.xml -in examples/test_file_5k.csv -ti 1320498000 -tf 1360498049
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 = 500000000
+LINES = 500000
 
 # OUTPUT:
 #     ID_TRANSACCION, ID_USUARIO, FECHA, MONTO, NUMERO DE TRAJETA, DESCRIPCION
diff --git a/include/io.h b/include/io.h
@@ -6,9 +6,8 @@
 #include <string.h>
 
 #include "cla.h"
-#include "status.h"
-#include "sort.h"
 #include "user.h"
+#include "status.h"
 
 #define _XOPEN_SOURCE
 #define __USE_XOPEN
@@ -39,14 +38,14 @@
 #define XML_DEBT_OPEN    "<debits>"
 #define XML_DEBT_CLOSE    "</debits>"
 
-typedef enum {
-    POS_ID_TXN,
-    POS_USER_ID,
-    POS_TXN_DATE,
-    POS_AMOUNT,
-    POS_CARD_NUMBER,
-    POS_DESC
-} csv_pos_t;
+/* typedef enum { */
+/*     POS_ID_TXN, */
+/*     POS_USER_ID, */
+/*     POS_TXN_DATE, */
+/*     POS_AMOUNT, */
+/*     POS_CARD_NUMBER, */
+/*     POS_DESC */
+/* } csv_pos_t; */
 
 status_t process_file(cla_t cla, user_t **users, size_t *i);
 
diff --git a/include/sort.h b/include/sort.h
@@ -2,6 +2,7 @@
 #define SORT__H
 
 #include "cla.h"
+#include "user.h"
 #include "status.h"
 
 #include <stdio.h>
@@ -13,6 +14,5 @@ int credit_maxmix(const void *, const void *);
 int debt_minmax(const void *, const void *);
 int debt_maxmin(const void *, const void *);
 
-status_t sort_users(user_t *users, size_t size, char *order);
 
 #endif
diff --git a/include/status.h b/include/status.h
@@ -27,10 +27,14 @@ typedef enum {
     ERROR_NULL_POINTER
 } status_t;
 
-typedef struct {
-    size_t id;
-    long credit, debt;
-} ADT_user_t, *user_t;
+typedef enum {
+    POS_ID_TXN,
+    POS_USER_ID,
+    POS_TXN_DATE,
+    POS_AMOUNT,
+    POS_CARD_NUMBER,
+    POS_DESC
+} csv_pos_t;
 
 void show_status(status_t st);
 void free_arrays(size_t num,...);
diff --git a/include/user.h b/include/user.h
@@ -2,17 +2,21 @@
 #define USER__H
 
 #include "status.h"
-#include "io.h"
 
-status_t destroy_users(user_t *users, size_t size);
-
-status_t user_create(user_t *usr);
-status_t user_set_data(user_t *user, char **data);
+typedef struct {
+    size_t id;
+    long credit, debt;
+} ADT_user_t, *user_t;
 
 user_t user_find(const user_t *users, int id, size_t size);
 user_t user_dup(user_t src);
 
+status_t user_create(user_t *usr);
+status_t user_set_data(user_t *user, char **data);
 
 void user_clean(user_t usr);
 
+status_t sort_users(user_t *users, size_t size, char *order);
+status_t destroy_users(user_t *users, size_t size);
+
 #endif
diff --git a/source/cla.c b/source/cla.c
@@ -41,12 +41,16 @@ status_t check_flags_repeated(int argc, char **argv)
     /* Inicializa a -1 para evitar confusiones con 0 */
     for(i = 0; i < FLAGS_MAX; i++) founded_flags[i] = -1;
 
+    /* Itera solo sobre las flags, guarda la posicion de la flag con respecto
+     * a available_flags a forma de tener una manera de checkear por repeticiones,
+     * si la posicion aparece multiples veces es un error */
     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(k = 0; k < FLAGS_MAX; k++) {
-                    if(founded_flags[k] == j) return ERROR_FLAG_REPEATED;
-                }
+                for(k = 0; k < fflags_index; k++)
+                    if(founded_flags[k] == j)
+                        return ERROR_FLAG_REPEATED;
+                
                 founded_flags[fflags_index++] = j;
                 break;
             }
@@ -69,12 +73,10 @@ status_t cla_setup(int argc, char **argv, cla_t *cla)
                     case FLAG_FMT: strcpy((*cla)->fmt, argv[i + 1]); break;
                     case FLAG_OUT: strcpy((*cla)->fo, argv[i + 1]); break;
                     case FLAG_IN: strcpy((*cla)->fi, argv[i + 1]); break;
-                    case FLAG_TI: 
-                                  (*cla)->ti = strtoul(argv[i + 1], &endptr, 10); 
+                    case FLAG_TI: (*cla)->ti = strtoul(argv[i + 1], &endptr, 10); 
                                   if(*endptr != '\0') return ERROR_WRONG_TIME;
                                   break;
-                    case FLAG_TF: 
-                                  (*cla)->tf = strtoul(argv[i + 1], &endptr, 10); 
+                    case FLAG_TF: (*cla)->tf = strtoul(argv[i + 1], &endptr, 10); 
                                   if(*endptr != '\0') return ERROR_WRONG_TIME;
                                   break;
                     default: return ERROR_FLAG_NOT_FOUND;
@@ -82,7 +84,6 @@ status_t cla_setup(int argc, char **argv, cla_t *cla)
             }
         }
     }
-
     return OK;
 }
 
@@ -127,7 +128,7 @@ status_t cla_destroy(cla_t *cla)
     free((*cla)->fi);
     free(*cla);
 
-    cla = NULL;
+    *cla = NULL;
 
     return OK;
 }
diff --git a/source/io.c b/source/io.c
@@ -185,6 +185,7 @@ status_t export_data_as_xml(FILE *fo, const user_t *users, size_t size)
         return ERROR_NULL_POINTER;
 
     fprintf(fo, "%s\n%s\n", XML_HEADER, XML_ROOT_OPEN);
+
     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);
diff --git a/source/main.c b/source/main.c
@@ -1,8 +1,8 @@
-#include "../include/cla.h"
-#include "../include/status.h"
 #include "../include/io.h"
-#include "../include/sort.h"
+#include "../include/cla.h"
 #include "../include/user.h"
+#include "../include/sort.h"
+#include "../include/status.h"
 
 /* "ca" - creditos ascendentes | "cd" - creditos descendentes
  * "da" - debitos ascendentes  | "dd" - debitos descendentes */