commit 6eddc08b12444959ad6b6dae35de59986d8f5001
Author: Martin J. Klöckner <martin.cachari@gmail.com>
Date: Sun, 20 Dec 2020 02:03:55 -0300
Created new repository to store the summer project for Algorithms &
Programation I, probably gonna be private until delivery date;
Diffstat:
9 files changed, 216 insertions(+), 0 deletions(-)
diff --git a/Makefile b/Makefile
@@ -0,0 +1,21 @@
+$(CC)=gcc
+
+all: make_main clean
+
+
+make_main: main.o arguments.o data.o
+ $(CC) main.o arguments.o data.o -o main
+
+main.o: src/main.c include/main.h include/arguments.h include/macros.h
+ $(CC) -c src/main.c
+
+arguments.o: src/arguments.c include/arguments.h include/macros.h
+ $(CC) -c src/arguments.c
+
+data.o: src/main.c include/main.h
+ $(CC) -c src/data.c
+
+clean:
+ rm -f *.o
+
+
diff --git a/README.md b/README.md
@@ -0,0 +1,39 @@
+# PROJECT NUMBER 1 - ALGORITHMS & PROGRAMATION I
+
+This folder contains the first project of "algoritmos y
+programacion I" a subject from Facultad de Ingenieria de la
+Universidad de Buenos Aires. The project is a program that
+runs on CLI which its function is to process data entered via
+a .csv file.
+
+What it does is receive a number for a country, date, and number of
+cases (of COVID19), and prints it on stdout with a human readable
+format.
+
+Bibliography:
+
+"The C programming language" - Brian W. Kernighan & Dennis Ritchie.
+
+NAME
+ analisis_covid - analyze RAW data and export it with a human
+ readable format.
+
+SYNOPSIS
+ analisis_covid [-in] SOURCE [-out] DEST
+ analisis_covid [-out] DEST [-in] SOURCE
+
+DESCRIPTION
+ Process RAW data from a .csv(comma separated values) file,
+ and export it to another .csv file, if the output file doesn't
+ exist then it creates one with the specified name.
+
+ When you invoke analisis_covid, expects.. to be continued
+
+
+AUTHOR
+ Written by Martin J. Klöckner - Argentina - December 2020.
+
+
+
+
+
diff --git a/include/arguments.h b/include/arguments.h
@@ -0,0 +1,15 @@
+#include "main.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#ifndef ARGUMENTS_H
+#define ARGUMENTS_H
+
+void print_error(status_t error);
+
+status_t validate_arguments(int argc, char * argv[]);
+
+status_t set_files_name(int argc, char * argv[], char * src, char * dest);
+
+#endif
diff --git a/include/data.h b/include/data.h
@@ -0,0 +1,9 @@
+#include <stdlib.h>
+#include "../include/main.h"
+
+#ifndef DATA_H
+#define DATA_H
+
+void print_error(status_t error);
+
+#endif
diff --git a/include/macros.h b/include/macros.h
@@ -0,0 +1,23 @@
+#ifndef MACROS_H
+#define MACROS_H
+
+#define NO_CMD_ARGUMENTS 1
+#define MAX_CMD_ARGUMENTS 5
+
+#define SOURCE_ARGUMENT "-in"
+#define DESTINATION_ARGUMENT "-out"
+
+#define INITIAL_SIZE 100
+
+#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 "ERROR_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_OK "Everything executed correctly"
+
+#endif
diff --git a/include/main.h b/include/main.h
@@ -0,0 +1,14 @@
+#include <stdio.h>
+#include "macros.h"
+
+#ifndef MAIN_H
+#define MAIN_H
+
+typedef enum {
+ OK,
+ ERROR_INVOCATING_PROGRAM,
+ ERROR_NULL_POINTER,
+ NOT_FOUND
+} status_t;
+
+#endif
diff --git a/src/arguments.c b/src/arguments.c
@@ -0,0 +1,47 @@
+#include "../include/arguments.h"
+#include "../include/macros.h"
+
+// Checks if the arguments are right;
+status_t validate_arguments(int argc, char * argv[])
+{
+ if(argc == NO_CMD_ARGUMENTS)
+ return ERROR_INVOCATING_PROGRAM;
+ else if(argv == NULL)
+ return ERROR_NULL_POINTER;
+
+ return OK;
+}
+
+// Set the files name acording to the arguments;
+status_t set_files_name(int argc, char * argv[], char * src, char * dest)
+{
+ int i;
+ status_t inputFile, outputFile;
+ inputFile = outputFile = NOT_FOUND;
+
+ for(i = 1; i < argc; i++) {
+ if(!strcmp(argv[i], SOURCE_ARGUMENT)) {
+ printf("Encontre un '-in'\n");
+ if(!strcmp(argv[i + 1], DESTINATION_ARGUMENT))
+ return ERROR_INVOCATING_PROGRAM;
+
+ strcpy(src, argv[++i]);
+ printf("\tthen input file: '%s'\n", src);
+ inputFile = OK;
+ } else if(!strcmp(argv[i], DESTINATION_ARGUMENT)) {
+ printf("Encontre un '-out'\n");
+ if(!strcmp(argv[i + 1], SOURCE_ARGUMENT))
+
+ return ERROR_INVOCATING_PROGRAM;
+ strcpy(dest, argv[++i]);
+ printf("\tthen output file: '%s'\n", argv[i]);
+ outputFile = OK;
+ }
+ }
+// Return error if it could get input or output file names;
+ if((inputFile && outputFile) != OK)
+ return ERROR_INVOCATING_PROGRAM;
+
+ return OK;
+}
+
diff --git a/src/data.c b/src/data.c
@@ -0,0 +1,16 @@
+#include "../include/main.h"
+
+void print_error(status_t error)
+{
+ switch (error) {
+ case ERROR_INVOCATING_PROGRAM:
+ fprintf(stderr, MSG_ERROR_INVOCATING_PROGRAM"\n");
+ break;
+ case ERROR_NULL_POINTER:
+ fprintf(stderr, MSG_ERROR_NULL_POINTER"\n");
+ break;
+ default:
+ fprintf(stdin, MSG_OK"\n");
+ }
+}
+
diff --git a/src/main.c b/src/main.c
@@ -0,0 +1,32 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "../include/main.h"
+#include "../include/arguments.h"
+#include "../include/macros.h"
+
+int main(int argc, char * argv[])
+{
+ status_t st;
+ if((st = validate_arguments(argc, argv)) != OK) {
+ print_error(st);
+ return st;
+ }
+
+ char * src;
+ char * dest;
+
+ src = (char *)malloc(INITIAL_SIZE * sizeof(char));
+ dest = (char *)malloc(INITIAL_SIZE * sizeof(char));
+
+ if((st = set_files_name(argc, argv, src, dest)) != OK) {
+ print_error(st);
+ return st;
+ }
+
+
+
+ return OK;
+}
+
+