9511_project01

project 1 for algorithms & programming I (9511) prof. Cardozo
Index Commits Files Refs README
commit a7ad93763f665debfe54e711119f8a3c88c9ea25
parent 113047735e446135f1800ee9fd535c0e4113a31a
Author: klewer-martin <martin.cachari@gmail.com>
Date:   Wed,  3 Feb 2021 19:05:33 -0300

Modified and reorganized dependencies now much more cleaner, data.c
changes name to perrors.c (for 'print_errors');

Diffstat:
MMakefile | 8++++----
Marguments.h | 3---
Ddata.c | 38--------------------------------------
Ddata.h | 9---------
Mload_country_codes.c | 2--
Mmacros.h | 3++-
Mmain.c | 1+
Mmain.h | 2++
Aperrors.c | 37+++++++++++++++++++++++++++++++++++++
Aperrors.h | 42++++++++++++++++++++++++++++++++++++++++++
Mreadlines.c | 4+++-
Mreadlines.h | 2+-
12 files changed, 92 insertions(+), 59 deletions(-)
diff --git a/Makefile b/Makefile
@@ -4,8 +4,8 @@ CFLAGS = -std=c99 -Wall -pedantic
 all: main clean
 
 
-main: main.o arguments.o data.o load_country_codes.o readlines.o
-    $(CC) $(CFLAGS) main.o arguments.o data.o load_country_codes.o readlines.o -o main 
+main: main.o arguments.o perrors.o load_country_codes.o readlines.o
+    $(CC) $(CFLAGS) main.o arguments.o perrors.o load_country_codes.o readlines.o -o main 
 
 main.o: main.c main.h arguments.h macros.h
     $(CC) -c main.c
@@ -13,8 +13,8 @@ main.o: main.c main.h arguments.h macros.h
 arguments.o: arguments.c arguments.h macros.h
     $(CC) -c arguments.c
 
-data.o: main.c main.h
-    $(CC) -c data.c
+perrors.o: main.c main.h
+    $(CC) -c perrors.c
 
 load_country_codes.o: load_country_codes.h main.h
     $(CC) -c load_country_codes.c 
diff --git a/arguments.h b/arguments.h
@@ -2,7 +2,6 @@
 #define ARGUMENTS_H
 
 #include "main.h"
-#include "macros.h"
 
 #define INPUT_ARGUMENT_FOUND_MSG     "Encontre un '-in'\n"
 #define OUTPUT_ARGUMENT_FOUND_MSG     "Encontre un '-out'\n"
@@ -10,8 +9,6 @@
 #define INPUT_FILE_NAME_MSG     "\t -> Archivo de entrada: "
 #define OUTPUT_FILE_NAME_MSG     "\t -> Archivo de salida: "
 
-void print_error(status_t error);
-
 status_t validate_arguments(int argc, char * argv[], char * src, char * dest);
 
 #endif
diff --git a/data.c b/data.c
@@ -1,38 +0,0 @@
-#include "main.h"
-#include "macros.h"
-
-
-//    The switch below the order of the error must be in the same as "main.h" 
-//    status_t structure, in order to print the correct errors;
-void print_error(status_t error)
-{
-    switch (error) {
-        case IO_FILE_NOT_FOUND: 
-            fprintf(stderr, MSG_IO_FILE_NOT_FOUND"\n");
-            break;
-        case ERROR_INVOCATING_PROGRAM: 
-            fprintf(stderr, MSG_ERROR_INVOCATING_PROGRAM"\n");
-            break;
-        case ERROR_NULL_POINTER:
-            fprintf(stderr, MSG_ERROR_NULL_POINTER"\n");
-            break;
-        case ERROR_LOADING_COUNTRY_CODES:
-            fprintf(stderr, MSG_ERROR_LOADING_COUNTRY_CODES"\n");
-            break;
-        case ERROR_PRINTING: 
-            fprintf(stderr, MSG_ERROR_PRINTING"\n");
-            break;
-        case ERROR_READING_FILE:
-            fprintf(stderr, MSG_ERROR_READING_FILE"\n");
-            break;
-        case ERROR_ALLOCATING_TIME: 
-            fprintf(stderr, MSG_ERROR_ALLOCATING_TIME"\n");
-            break;
-        case ERROR_DATA_ON_FILE_MISSING: 
-            fprintf(stderr, MSG_ERROR_DATA_ON_FILE_MISSING"\n");
-            break;
-        default:
-            fprintf(stdin, MSG_OK"\n");
-    }
-}
-
diff --git a/data.h b/data.h
@@ -1,9 +0,0 @@
-#include <stdlib.h>
-#include "main.h"
-
-#ifndef DATA_H
-#define DATA_H
-
-void print_error(status_t error);
-
-#endif
diff --git a/load_country_codes.c b/load_country_codes.c
@@ -3,8 +3,6 @@
 // a dicho arreglo con los codigos cargados;
 
 
-#include "main.h"
-#include "macros.h"
 #include "load_country_codes.h"
 
 
diff --git a/macros.h b/macros.h
@@ -10,6 +10,7 @@
 
 #define INITIAL_SIZE        1000
 
+/*
 #define MSG_ERROR_NULL_POINTER    "ERROR_NULL_POINTER\n"\
                                 "An unexpected error has occured during the execution\n"\
                                 "of the program"
@@ -43,5 +44,5 @@
                                         "el programa nuevamente"
 
 #define MSG_OK "\nEverything executed correctly.\n"
-
+*/
 #endif
diff --git a/main.c b/main.c
@@ -19,6 +19,7 @@
 #include "arguments.h"
 #include "load_country_codes.h"
 #include "readlines.h"
+#include "perrors.h"
 
 
 int main(int argc, char * argv[])
diff --git a/main.h b/main.h
@@ -6,6 +6,8 @@
 #include <string.h>
 #include <time.h>
 
+#include "macros.h"
+
 #define COUNTRY_CODES_FILE_NAME "iso3166-1.csv"
 
 typedef enum {
diff --git a/perrors.c b/perrors.c
@@ -0,0 +1,37 @@
+#include "perrors.h"
+#include "main.h"
+
+//    The switch below the order of the error must be in the same as "main.h" 
+//    status_t structure, in order to print the correct errors;
+void print_error(status_t error)
+{
+    switch (error) {
+        case IO_FILE_NOT_FOUND: 
+            fprintf(stderr, MSG_IO_FILE_NOT_FOUND"\n");
+            break;
+        case ERROR_INVOCATING_PROGRAM: 
+            fprintf(stderr, MSG_ERROR_INVOCATING_PROGRAM"\n");
+            break;
+        case ERROR_NULL_POINTER:
+            fprintf(stderr, MSG_ERROR_NULL_POINTER"\n");
+            break;
+        case ERROR_LOADING_COUNTRY_CODES:
+            fprintf(stderr, MSG_ERROR_LOADING_COUNTRY_CODES"\n");
+            break;
+        case ERROR_PRINTING: 
+            fprintf(stderr, MSG_ERROR_PRINTING"\n");
+            break;
+        case ERROR_READING_FILE:
+            fprintf(stderr, MSG_ERROR_READING_FILE"\n");
+            break;
+        case ERROR_ALLOCATING_TIME: 
+            fprintf(stderr, MSG_ERROR_ALLOCATING_TIME"\n");
+            break;
+        case ERROR_DATA_ON_FILE_MISSING: 
+            fprintf(stderr, MSG_ERROR_DATA_ON_FILE_MISSING"\n");
+            break;
+        default:
+            fprintf(stdin, MSG_OK"\n");
+    }
+}
+
diff --git a/perrors.h b/perrors.h
@@ -0,0 +1,42 @@
+#ifndef DATA_H
+#define DATA_H
+
+#include "main.h"
+
+void print_error(status_t error);
+
+#define MSG_ERROR_NULL_POINTER    "ERROR_NULL_POINTER\n"\
+                                "An unexpected error has occured during the execution\n"\
+                                "of the program"
+
+#define MSG_ERROR_INVOCATING_PROGRAM    "\nERROR_INVOCATING_PROGRAM\n"\
+                                        "Usage:\t$ ./main -in <input file> -out <outputfile>\n"\
+                                        "\t$ ./main -out <output file -in <input file>\n"\
+                                        "Read documentation to know more"
+
+#define MSG_IO_FILE_NOT_FOUND     "\nIO_FILE_NOT_FOUND\n"\
+                                "Un de los archivos de entrada o salida no se ha especificado"\
+
+#define MSG_ERROR_LOADING_COUNTRY_CODES "\nERROR_LOADING_COUNTRY_CODES\n"\
+                                        "Ha ocurrido un error al cargar los codigos de los paises.\n"\
+                                        "compruebe que el archivo \""COUNTRY_CODES_FILE_NAME"\" se encuentre\n"\
+                                        "disponible en el directorio de el programa ejecutado y que\n"\
+                                        "el nombre coincida con el de \"COUNTRY_CODES_FILE_NAME\" dentro\n"\
+                                        "de el archivo main.h\n"
+
+#define MSG_ERROR_PRINTING
+
+#define MSG_ERROR_READING_FILE            "\nERROR_READING_FILE\n"\
+                                        "El archivo de entrada no pudo ser leido, compruebe que el nombre este\n"\
+                                        "escrito correctamente y la existencia de el mismo"
+
+#define MSG_ERROR_ALLOCATING_TIME        "\nstrftime(3): el formato especificado "
+
+#define MSG_ERROR_DATA_ON_FILE_MISSING    "\nERROR_DATA_ON_FILE_MISSING\n"\
+                                        "En alguna linea de el archivo de entrada falta un dato,\n"\
+                                        "compruebe que dicho archivo no esta corrupto y ejecute\n"\
+                                        "el programa nuevamente"
+
+#define MSG_OK "\nEverything executed correctly.\n"
+
+#endif
diff --git a/readlines.c b/readlines.c
@@ -3,6 +3,8 @@
 
 #include "readlines.h"
 
+const char formato_de_la_fecha[] = "%d %b %Y";
+
 status_t readlines(char *src, char *dest)
 {
     size_t line, i, j;
@@ -172,7 +174,7 @@ status_t time_translator(time_t unix_time, char *res, size_t size)
     if(res == NULL)
         return ERROR_NULL_POINTER;
 
-    const char *format = date_output_format;
+    const char *format = formato_de_la_fecha;
     struct tm *tmp = gmtime(&unix_time);
 
     if (strftime(res, size, format, tmp) == 0) {
diff --git a/readlines.h b/readlines.h
@@ -12,7 +12,7 @@
 #define INITIAL_SIZE 1000
 #define TIME_MAX_DIGITS 1000
 
-const char date_output_format[] = "%d %b %Y";
+extern const char formato_de_la_fecha[];
 
 typedef enum {
     PAIS,