commit c5f711cbf206a5b42438333439d96600f1ce2b6c
parent 608fda620724f8cea962aea240a0230a327e07b7
Author: klewer-martin <mk@inspiron.localdomain>
Date: Mon, 25 Jan 2021 17:01:34 -0300
Merged all files in a single folder, in the future they will be
separated into differents folders again;
Diffstat:
13 files changed, 191 insertions(+), 109 deletions(-)
diff --git a/arguments.c b/arguments.c
@@ -0,0 +1,47 @@
+#include "arguments.h"
+#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/include/arguments.h b/arguments.h
diff --git a/data.c b/data.c
@@ -0,0 +1,16 @@
+#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/include/data.h b/data.h
diff --git a/include/main.h b/include/main.h
@@ -1,14 +0,0 @@
-#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/load_country_codes.c b/load_country_codes.c
@@ -0,0 +1,57 @@
+#include "main.h"
+#include "load_country_codes.h"
+
+status_t empty_country_codes(char country_codes[COUNTRIES_NUMBER][ARRAYS_LENGTH])
+{
+ size_t i, j;
+ for(i = 0; i < COUNTRIES_NUMBER; i++)
+ for(j = 0; j < (ARRAYS_LENGTH - 1); j++) {
+ country_codes[i][j] = 'a';
+
+ country_codes[i][ARRAYS_LENGTH - 1] = '\n';
+ }
+
+ return OK;
+}
+
+status_t load_country_codes(char country_codes[COUNTRIES_NUMBER][ARRAYS_LENGTH])
+{
+ FILE *fp;
+
+ char *buff;
+ char buff_2[10];
+
+ int country_code;
+ char country_name[INITIAL_SIZE];
+
+ size_t i, j;
+ part_t part;
+
+ buff = malloc(INITIAL_SIZE);
+
+
+ if((fp = fopen("iso3166-1_numbers_and_countries.csv", "r")) == NULL)
+ return ERROR_NULL_POINTER;
+
+ while(fgets(buff, INITIAL_SIZE, fp) != NULL) {
+ for(i = 0, j = 0, part = CODE; (*(buff + i)) != '\0'; i++) {
+ if((*(buff + i + 1)) == ',') {
+ country_code = atoi(buff_2);
+ part = NAME;
+ }
+
+
+ switch(part)
+ {
+ case CODE: buff_2[i] = *(buff + i); break;
+ case NAME: country_name[j] = *(buff + i); j++; break;
+ }
+ }
+ strcpy(country_name, country_codes[country_code]);
+ }
+
+ fclose(fp);
+ free(buff);
+ return OK;
+}
+
diff --git a/load_country_codes.h b/load_country_codes.h
@@ -0,0 +1,26 @@
+#ifndef LOAD_COUNTRY_CODES
+#define LOAD_COUNTRY_CODES
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#define INITIAL_SIZE 65
+#define COUNTRIES_NUMBER 500
+#define ARRAYS_LENGTH 25
+
+typedef enum {
+ OK,
+ ERROR_NULL_POINTER,
+ ERROR_LOADING_COUNTRY_CODES
+} status_t;
+
+typedef enum {
+ CODE,
+ NAME
+} part_t;
+
+status_t empty_country_codes(char country_codes[COUNTRIES_NUMBER][ARRAYS_LENGTH]);
+status_t load_country_codes(char country_codes[COUNTRIES_NUMBER][ARRAYS_LENGTH]);
+
+#endif
diff --git a/include/macros.h b/macros.h
diff --git a/main.c b/main.c
@@ -0,0 +1,29 @@
+#include "main.h"
+#include "arguments.h"
+#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;
+}
+
+
diff --git a/main.h b/main.h
@@ -0,0 +1,16 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.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
@@ -1,47 +0,0 @@
-#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
@@ -1,16 +0,0 @@
-#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
@@ -1,32 +0,0 @@
-#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;
-}
-
-