commit 872c63278ec024d3270ebd02537f45a13031668b
parent 92fa63cacb06ecce7ccea4c6bd6c91c4fd7993ae
Author: klewer-martin <martin.cachari@gmail.com>
Date: Tue, 2 Feb 2021 21:49:15 -0300
Update on some files source code and the removal of 'tests' folder;
Diffstat:
17 files changed, 5 insertions(+), 857 deletions(-)
diff --git a/.~lock.iso3166-1_numbers_and_countries.csv# b/.~lock.iso3166-1_numbers_and_countries.csv#
@@ -1 +0,0 @@
-,mk,inspiron.localdomain,02.02.2021 20:20,file:///home/mk/.config/libreoffice/4;
-\ No newline at end of file
diff --git a/arguments.c b/arguments.c
@@ -1,7 +1,7 @@
#include "arguments.h"
-#define INPUT_ARGUMENT_FOUND_MSG "Encontre un -in\n"
-#define OUTPUT_ARGUMENT_FOUND_MSG "Encontre un -out\n"
+#define INPUT_ARGUMENT_FOUND_MSG "Encontre un '-in'\n"
+#define OUTPUT_ARGUMENT_FOUND_MSG "Encontre un '-out'\n"
#define INPUT_FILE_NAME_MSG "\t -> Archivo de entrada: "
#define OUTPUT_FILE_NAME_MSG "\t -> Archivo de salida: "
diff --git a/input.csv b/input.csv
@@ -22,4 +22,4 @@ PAIS, FECHA, INFECTADOS
512,1579521600,4214
586,1577880000,8432
591,1579089600,9129
-620,1579521600,4214
+384,1579521600,4214
diff --git a/readlines.c b/readlines.c
@@ -4,12 +4,6 @@
const char date_print_format[] = "%d %b %Y";
-status_t print_country(size_t country_code, char country_codes[COUNTRIES_NUMBER][ARRAYS_LENGTH]);
-status_t print_date(size_t data);
-status_t print_infected(size_t data);
-status_t clean_buffer(char *buffer);
-status_t time_translator(time_t unix_time, char *res, size_t size);
-
status_t readlines(void)
{
size_t line, i, j;
@@ -57,8 +51,8 @@ status_t readlines(void)
}
}
print_country(country, country_codes);
-// print_date(date);
-// print_infected(infected);
+ print_date(date);
+ print_infected(infected);
}
}
diff --git a/tests/Makefile b/tests/Makefile
@@ -1,13 +0,0 @@
-$(CC)=gcc
-
-all: make_main
-
-
-make_main: main.o
- $(CC) readlines.o -o main
-
-main.o: readlines.c ISO3166-1.h
- $(CC) -c readlines.c
-
-clean:
- rm -f *.o *.out main
diff --git a/tests/input.csv b/tests/input.csv
@@ -1,10 +0,0 @@
-PAIS, FECHA, INFECTADOS
-32,1577880000,2342
-32,1578657600,4923
-32,1579089600,9324
-170,1577880000,8234
-170,1578657600,9234
-170,1579089600,9423
-276,1577880000,8432
-276,1579089600,9129
-276,1579521600,4214
diff --git a/tests/iso3166-1.csv b/tests/iso3166-1.csv
@@ -1,249 +0,0 @@
-Afghanistan,4
-Åland Islands,248
-Albania,8
-Algeria,12
-American Samoa,16
-Andorra,20
-Angola,24
-Anguilla,660
-Antarctica,10
-Antigua and Barbuda,28
-Argentina,32
-Armenia,51
-Aruba,533
-Australia,36
-Austria,40
-Azerbaijan,31
-Bahamas,44
-Bahrain,48
-Bangladesh,50
-Barbados,52
-Belarus,112
-Belgium,56
-Belize,84
-Benin,204
-Bermuda,60
-Bhutan,64
-Bolivia (Plurinational State of),68
-"Bonaire, Sint Eustatius and Saba",535
-Bosnia and Herzegovina,70
-Botswana,72
-Bouvet Island,74
-Brazil,76
-British Indian Ocean Territory,86
-Brunei Darussalam,96
-Bulgaria,100
-Burkina Faso,854
-Burundi,108
-Cabo Verde,132
-Cambodia,116
-Cameroon,120
-Canada,124
-Cayman Islands,136
-Central African Republic,140
-Chad,148
-Chile,152
-China,156
-Christmas Island,162
-Cocos (Keeling) Islands,166
-Colombia,170
-Comoros,174
-Congo,178
-"Congo, Democratic Republic of the",180
-Cook Islands,184
-Costa Rica,188
-Côte d'Ivoire,384
-Croatia,191
-Cuba,192
-Curaçao,531
-Cyprus,196
-Czechia,203
-Denmark,208
-Djibouti,262
-Dominica,212
-Dominican Republic,214
-Ecuador,218
-Egypt,818
-El Salvador,222
-Equatorial Guinea,226
-Eritrea,232
-Estonia,233
-Eswatini,748
-Ethiopia,231
-Falkland Islands (Malvinas),238
-Faroe Islands,234
-Fiji,242
-Finland,246
-France,250
-French Guiana,254
-French Polynesia,258
-French Southern Territories,260
-Gabon,266
-Gambia,270
-Georgia,268
-Germany,276
-Ghana,288
-Gibraltar,292
-Greece,300
-Greenland,304
-Grenada,308
-Guadeloupe,312
-Guam,316
-Guatemala,320
-Guernsey,831
-Guinea,324
-Guinea-Bissau,624
-Guyana,328
-Haiti,332
-Heard Island and McDonald Islands,334
-Holy See,336
-Honduras,340
-Hong Kong,344
-Hungary,348
-Iceland,352
-India,356
-Indonesia,360
-Iran (Islamic Republic of),364
-Iraq,368
-Ireland,372
-Isle of Man,833
-Israel,376
-Italy,380
-Jamaica,388
-Japan,392
-Jersey,832
-Jordan,400
-Kazakhstan,398
-Kenya,404
-Kiribati,296
-Korea (Democratic People's Republic of),408
-"Korea, Republic of",410
-Kuwait,414
-Kyrgyzstan,417
-Lao People's Democratic Republic,418
-Latvia,428
-Lebanon,422
-Lesotho,426
-Liberia,430
-Libya,434
-Liechtenstein,438
-Lithuania,440
-Luxembourg,442
-Macao,446
-Madagascar,450
-Malawi,454
-Malaysia,458
-Maldives,462
-Mali,466
-Malta,470
-Marshall Islands,584
-Martinique,474
-Mauritania,478
-Mauritius,480
-Mayotte,175
-Mexico,484
-Micronesia (Federated States of),583
-"Moldova, Republic of",498
-Monaco,492
-Mongolia,496
-Montenegro,499
-Montserrat,500
-Morocco,504
-Mozambique,508
-Myanmar,104
-Namibia,516
-Nauru,520
-Nepal,524
-Netherlands,528
-New Caledonia,540
-New Zealand,554
-Nicaragua,558
-Niger,562
-Nigeria,566
-Niue,570
-Norfolk Island,574
-North Macedonia,807
-Northern Mariana Islands,580
-Norway,578
-Oman,512
-Pakistan,586
-Palau,585
-"Palestine, State of",275
-Panama,591
-Papua New Guinea,598
-Paraguay,600
-Peru,604
-Philippines,608
-Pitcairn,612
-Poland,616
-Portugal,620
-Puerto Rico,630
-Qatar,634
-Réunion,638
-Romania,642
-Russian Federation,643
-Rwanda,646
-Saint Barthélemy,652
-"Saint Helena, Ascension and Tristan da Cunha",654
-Saint Kitts and Nevis,659
-Saint Lucia,662
-Saint Martin (French part),663
-Saint Pierre and Miquelon,666
-Saint Vincent and the Grenadines,670
-Samoa,882
-San Marino,674
-Sao Tome and Principe,678
-Saudi Arabia,682
-Senegal,686
-Serbia,688
-Seychelles,690
-Sierra Leone,694
-Singapore,702
-Sint Maarten (Dutch part),534
-Slovakia,703
-Slovenia,705
-Solomon Islands,90
-Somalia,706
-South Africa,710
-South Georgia and the South Sandwich Islands,239
-South Sudan,728
-Spain,724
-Sri Lanka,144
-Sudan,729
-Suriname,740
-Svalbard and Jan Mayen,744
-Sweden,752
-Switzerland,756
-Syrian Arab Republic,760
-"Taiwan, Province of China",158
-Tajikistan,762
-"Tanzania, United Republic of",834
-Thailand,764
-Timor-Leste,626
-Togo,768
-Tokelau,772
-Tonga,776
-Trinidad and Tobago,780
-Tunisia,788
-Turkey,792
-Turkmenistan,795
-Turks and Caicos Islands,796
-Tuvalu,798
-Uganda,800
-Ukraine,804
-United Arab Emirates,784
-United Kingdom of Great Britain and Northern Ireland,826
-United States of America,840
-United States Minor Outlying Islands,581
-Uruguay,858
-Uzbekistan,860
-Vanuatu,548
-Venezuela (Bolivarian Republic of),862
-Viet Nam,704
-Virgin Islands (British),92
-Virgin Islands (U.S.),850
-Wallis and Futuna,876
-Western Sahara,732
-Yemen,887
-Zambia,894
-Zimbabwe,716
diff --git a/tests/iso3166-1.h b/tests/iso3166-1.h
@@ -1,11 +0,0 @@
-#ifndef ISO3166
-#define ISO3166
-
-
-#define ARG "ARGENTINA"
-#define COL "COLOMBIA"
-#define GER "GERMANY"
-
-
-
-#endif
diff --git a/tests/iso3166-1_numbers_and_countries.csv b/tests/iso3166-1_numbers_and_countries.csv
@@ -1,249 +0,0 @@
-4,Afghanistan
-248,Åland Islands
-8,Albania
-12,Algeria
-16,American Samoa
-20,Andorra
-24,Angola
-660,Anguilla
-10,Antarctica
-28,Antigua and Barbuda
-32,Argentina
-51,Armenia
-533,Aruba
-36,Australia
-40,Austria
-31,Azerbaijan
-44,Bahamas
-48,Bahrain
-50,Bangladesh
-52,Barbados
-112,Belarus
-56,Belgium
-84,Belize
-204,Benin
-60,Bermuda
-64,Bhutan
-68,Bolivia (Plurinational State of)
-535,"Bonaire, Sint Eustatius and Saba"
-70,Bosnia and Herzegovina
-72,Botswana
-74,Bouvet Island
-76,Brazil
-86,British Indian Ocean Territory
-96,Brunei Darussalam
-100,Bulgaria
-854,Burkina Faso
-108,Burundi
-132,Cabo Verde
-116,Cambodia
-120,Cameroon
-124,Canada
-136,Cayman Islands
-140,Central African Republic
-148,Chad
-152,Chile
-156,China
-162,Christmas Island
-166,Cocos (Keeling) Islands
-170,Colombia
-174,Comoros
-178,Congo
-180,"Congo, Democratic Republic of the"
-184,Cook Islands
-188,Costa Rica
-384,Côte d'Ivoire
-191,Croatia
-192,Cuba
-531,Curaçao
-196,Cyprus
-203,Czechia
-208,Denmark
-262,Djibouti
-212,Dominica
-214,Dominican Republic
-218,Ecuador
-818,Egypt
-222,El Salvador
-226,Equatorial Guinea
-232,Eritrea
-233,Estonia
-748,Eswatini
-231,Ethiopia
-238,Falkland Islands (Malvinas)
-234,Faroe Islands
-242,Fiji
-246,Finland
-250,France
-254,French Guiana
-258,French Polynesia
-260,French Southern Territories
-266,Gabon
-270,Gambia
-268,Georgia
-276,Germany
-288,Ghana
-292,Gibraltar
-300,Greece
-304,Greenland
-308,Grenada
-312,Guadeloupe
-316,Guam
-320,Guatemala
-831,Guernsey
-324,Guinea
-624,Guinea-Bissau
-328,Guyana
-332,Haiti
-334,Heard Island and McDonald Islands
-336,Holy See
-340,Honduras
-344,Hong Kong
-348,Hungary
-352,Iceland
-356,India
-360,Indonesia
-364,Iran (Islamic Republic of)
-368,Iraq
-372,Ireland
-833,Isle of Man
-376,Israel
-380,Italy
-388,Jamaica
-392,Japan
-832,Jersey
-400,Jordan
-398,Kazakhstan
-404,Kenya
-296,Kiribati
-408,Korea (Democratic People's Republic of)
-410,"Korea, Republic of"
-414,Kuwait
-417,Kyrgyzstan
-418,Lao People's Democratic Republic
-428,Latvia
-422,Lebanon
-426,Lesotho
-430,Liberia
-434,Libya
-438,Liechtenstein
-440,Lithuania
-442,Luxembourg
-446,Macao
-450,Madagascar
-454,Malawi
-458,Malaysia
-462,Maldives
-466,Mali
-470,Malta
-584,Marshall Islands
-474,Martinique
-478,Mauritania
-480,Mauritius
-175,Mayotte
-484,Mexico
-583,Micronesia (Federated States of)
-498,"Moldova, Republic of"
-492,Monaco
-496,Mongolia
-499,Montenegro
-500,Montserrat
-504,Morocco
-508,Mozambique
-104,Myanmar
-516,Namibia
-520,Nauru
-524,Nepal
-528,Netherlands
-540,New Caledonia
-554,New Zealand
-558,Nicaragua
-562,Niger
-566,Nigeria
-570,Niue
-574,Norfolk Island
-807,North Macedonia
-580,Northern Mariana Islands
-578,Norway
-512,Oman
-586,Pakistan
-585,Palau
-275,"Palestine, State of"
-591,Panama
-598,Papua New Guinea
-600,Paraguay
-604,Peru
-608,Philippines
-612,Pitcairn
-616,Poland
-620,Portugal
-630,Puerto Rico
-634,Qatar
-638,Réunion
-642,Romania
-643,Russian Federation
-646,Rwanda
-652,Saint Barthélemy
-654,"Saint Helena, Ascension and Tristan da Cunha"
-659,Saint Kitts and Nevis
-662,Saint Lucia
-663,Saint Martin (French part)
-666,Saint Pierre and Miquelon
-670,Saint Vincent and the Grenadines
-882,Samoa
-674,San Marino
-678,Sao Tome and Principe
-682,Saudi Arabia
-686,Senegal
-688,Serbia
-690,Seychelles
-694,Sierra Leone
-702,Singapore
-534,Sint Maarten (Dutch part)
-703,Slovakia
-705,Slovenia
-90,Solomon Islands
-706,Somalia
-710,South Africa
-239,South Georgia and the South Sandwich Islands
-728,South Sudan
-724,Spain
-144,Sri Lanka
-729,Sudan
-740,Suriname
-744,Svalbard and Jan Mayen
-752,Sweden
-756,Switzerland
-760,Syrian Arab Republic
-158,"Taiwan, Province of China"
-762,Tajikistan
-834,"Tanzania, United Republic of"
-764,Thailand
-626,Timor-Leste
-768,Togo
-772,Tokelau
-776,Tonga
-780,Trinidad and Tobago
-788,Tunisia
-792,Turkey
-795,Turkmenistan
-796,Turks and Caicos Islands
-798,Tuvalu
-800,Uganda
-804,Ukraine
-784,United Arab Emirates
-826,United Kingdom of Great Britain and Northern Ireland
-840,United States of America
-581,United States Minor Outlying Islands
-858,Uruguay
-860,Uzbekistan
-548,Vanuatu
-862,Venezuela (Bolivarian Republic of)
-704,Viet Nam
-92,Virgin Islands (British)
-850,Virgin Islands (U.S.)
-876,Wallis and Futuna
-732,Western Sahara
-887,Yemen
-894,Zambia
-716,Zimbabwe
diff --git a/tests/load_country_codes.c b/tests/load_country_codes.c
@@ -1,56 +0,0 @@
-#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/tests/load_country_codes.h b/tests/load_country_codes.h
@@ -1,26 +0,0 @@
-#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/tests/main.c b/tests/main.c
diff --git a/tests/pointer.c b/tests/pointer.c
@@ -1,24 +0,0 @@
-#include <stdio.h>
-#include <string.h>
-
-void clean(char * buffer)
-{
- puts(buffer);
- printf("%lu\n", strlen(buffer));
- while(*buffer != '\0')
- {
- (*buffer) = ' ';
- buffer++;
- }
-}
-
-int main (void)
-{
- char str[] = "Hello world!";
- puts(str);
-
- clean(str);
- puts(str);
-
- return 0;
-}
diff --git a/tests/readlines.c b/tests/readlines.c
@@ -1,136 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <time.h>
-#include "readlines.h"
-
-const char date_print_format[] = "%d %b %Y";
-
-status_t print_country(size_t country_code);
-status_t print_date(size_t data);
-status_t print_infected(size_t data);
-status_t clean_buffer(char *buffer);
-status_t time_translator(time_t unix_time, char *res, size_t size);
-
-int main(void)
-{
- size_t line, i, j;
- FILE *fp;
- char buff1[] = " ";
- char buff2[] = " ";
- data_t data;
-
- unsigned long country;
- unsigned long date;
- unsigned long infected;
-
- if((fp = fopen(INPUT_FILE_NAME, "r")) == NULL)
- return ERROR_READING_FILE;
-
- for(line = 0; fgets(buff1, sizeof(buff1), fp) != NULL; line++)
- {
-// This if is to skip the first line which doesn't contain information;
- if(line != 0) {
- for(i = 0, j = 0, data = PAIS; buff1[i] != '\0'; i++)
- {
- if((buff1[i] == ',') || (buff1[i] == '\n'))
- {
- i++;
- switch(data)
- {
- case PAIS: country = atoi(buff2); break;
- case DATE: date = atol(buff2); j++; break;
- case INFECTED: infected = atol(buff2); break;
- }
- data++;
- j = 0;
- clean_buffer(buff2);
- }
-
- switch(data)
- {
- case PAIS: buff2[i] = buff1[i]; break;
- case DATE: buff2[j] = buff1[i]; j++; break;
- case INFECTED: buff2[j] = buff1[i]; j++; break;
-
- }
- }
- print_country(country);
- print_date(date);
- print_infected(infected);
- }
- }
-
-// char country_codes[COUNTRIES_NUMBER][ARRAYS_LENGTH];
-
-// if(load_country_codes(country_codes) != OK)
-// return ERROR_LOADING_COUNTRY_CODES;
-// empty_country_codes(country_codes);
-
-// size_t i;
-// for(i = 0; i < 500; i++)
-// printf("%s", *(country_codes + i));
-
-
- fclose(fp);
- return 0;
-}
-
-
-
-status_t print_country(size_t country_code)
-{
- switch(country_code)
- {
- case 32: printf("Pais: "ARG"\n"); break;
- case 170: printf("Pais: "COL"\n"); break;
- case 276: printf("Pais: "GER"\n"); break;
- }
- return OK;
-}
-
-status_t print_date(size_t date)
-{
- char time_c[TIME_MAX_DIGITS];
-
- time_translator(date, time_c, sizeof(time_c));
- printf("Fecha: %s\n", time_c);
-
- return OK;
-}
-
-status_t print_infected(size_t infected)
-{
- printf("Infectados: %lu\n\n", infected);
-
- return OK;
-}
-
-status_t clean_buffer(char *buffer)
-{
- if(buffer == NULL)
- return ERROR_NULL_POINTER;
-
- while(*buffer != '\0')
- {
- (*buffer) = ' ';
- buffer++;
- }
- return OK;
-}
-
-
-status_t time_translator(time_t unix_time, char *res, size_t size)
-{
- const char *format = date_print_format;
- struct tm *tmp = gmtime(&unix_time);
-
- if (strftime(res, size, format, tmp) == 0) {
- (void) fprintf(stderr, "strftime(3): cannot format supplied "
- "date/time into buffer of size %u "
- "using: '%s'\n",
- (unsigned int)sizeof(res), format);
- return ERROR_ALLOCATING_TIME;
- }
- return OK;
-}
-
diff --git a/tests/readlines.h b/tests/readlines.h
@@ -1,26 +0,0 @@
-#ifndef READLINES
-#define READLINES
-
-#define INPUT_FILE_NAME "input.csv"
-#define INITIAL_SIZE 1000
-#define TIME_MAX_DIGITS 1000
-
-#define ARG "Argentina"
-#define COL "Colombia"
-#define GER "Germany"
-
-typedef enum {
- OK,
- ERROR_PRINTING,
- ERROR_READING_FILE,
- ERROR_NULL_POINTER,
- ERROR_ALLOCATING_TIME
-} status_t;
-
-typedef enum {
- PAIS,
- DATE,
- INFECTED
-} data_t;
-
-#endif
diff --git a/tests/time_translator.c b/tests/time_translator.c
@@ -1,38 +0,0 @@
-#include <stdio.h>
-#include <time.h>
-#include <string.h>
-
-const char default_format[] = "%B %d %Y";
-
-typedef enum {
- OK,
- ERROR_NULL_POINTER
-} status_t;
-
-status_t date_translator(time_t unix_time, char *res, size_t size)
-{
- const char *format = default_format;
- struct tm *tmp = gmtime(&unix_time);
-
- if (strftime(res, size, format, tmp) == 0) {
- (void) fprintf(stderr, "strftime(3): cannot format supplied "
- "date/time into buffer of size %u "
- "using: '%s'\n",
- (unsigned int)sizeof(res), format);
- return 1;
- }
- return 0;
-}
-
-int main (void)
-{
- char res[32];
-
- time_t t;
-
- t = 1577880000;
-
- date_translator(t, res, sizeof(res));
- puts(res);
- return 0;
-}
diff --git a/tests/time_translator.h b/tests/time_translator.h
@@ -1,6 +0,0 @@
-#ifndef TIME_TRANSLATOR
-#define TIME_TRANSLATOR
-
-
-
-#endif