commit f0fa6fbd5a69595a6cef0cf1f318f87972f56d67
parent 8b6ce552697b1cf86bb7550a9f1ab198d9a2dd18
Author: Martin J. Klöckner <martin.cachari@gmail.com>
Date: Sun, 20 Dec 2020 00:40:39 -0300
Reorganized files & directories, and also added a project01, a homework
for the summer recess(probably gonna make it secret until delivery date).
Diffstat:
9 files changed, 216 insertions(+), 0 deletions(-)
diff --git a/95.11/project01/Makefile b/95.11/project01/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/95.11/project01/README.md b/95.11/project01/README.md
@@ -0,0 +1,39 @@
+# PROJECT NUMER 1 - ALGORITHMS & PROGRAMATION I (cod. 95.11)
+
+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/95.11/project01/include/arguments.h b/95.11/project01/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/95.11/project01/include/data.h b/95.11/project01/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/95.11/project01/include/macros.h b/95.11/project01/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/95.11/project01/include/main.h b/95.11/project01/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/95.11/project01/src/arguments.c b/95.11/project01/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/95.11/project01/src/data.c b/95.11/project01/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/95.11/project01/src/main.c b/95.11/project01/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;
+}
+
+