diff --git a/src/client/Makefile b/client/Makefile similarity index 70% rename from src/client/Makefile rename to client/Makefile index f4fbec7..b4f32c9 100644 --- a/src/client/Makefile +++ b/client/Makefile @@ -1,6 +1,6 @@ CC = gcc FLAGS = -Wall -Wextra -Wshadow -SRC = main.c sock.c http.c utils.c fraction.c +SRC = src/main.c src/sock.c src/http.c src/utils.c src/fraction.c OUT = client all: diff --git a/src/client/fraction.h b/client/include/fraction.h similarity index 91% rename from src/client/fraction.h rename to client/include/fraction.h index 500ad09..52ba967 100644 --- a/src/client/fraction.h +++ b/client/include/fraction.h @@ -26,4 +26,5 @@ int fraction_parse(char *data, size_t size, fraction_t *fraction); int check_magic(uint32_t data); void print_fraction(fraction_t fraction); void fraction_free(fraction_t *fraction); +int compare_fractions(const void* a, const void* b); #endif diff --git a/src/client/http.h b/client/include/http.h similarity index 100% rename from src/client/http.h rename to client/include/http.h diff --git a/src/client/sock.h b/client/include/sock.h similarity index 100% rename from src/client/sock.h rename to client/include/sock.h diff --git a/src/client/utils.h b/client/include/utils.h similarity index 99% rename from src/client/utils.h rename to client/include/utils.h index 5304b75..6f073e0 100644 --- a/src/client/utils.h +++ b/client/include/utils.h @@ -1,7 +1,7 @@ #ifndef UTILS_H #define UTILS_H -#include +#include #include #include #include diff --git a/src/client/fraction.c b/client/src/fraction.c similarity index 90% rename from src/client/fraction.c rename to client/src/fraction.c index 93eb9f9..84ecc8d 100644 --- a/src/client/fraction.c +++ b/client/src/fraction.c @@ -1,4 +1,4 @@ -#include "fraction.h" +#include "../include/fraction.h" #include @@ -108,3 +108,15 @@ void fraction_free(fraction_t *fraction) { fraction->index = 0; fraction->crc = 0; } + +// Function used by qsort() to compare the index of our fractions +int compare_fractions(const void* a, const void* b) { + const fraction_t* frac_a = (const fraction_t*)a; + const fraction_t* frac_b = (const fraction_t*)b; + + if (frac_a->index < frac_b->index) { + return -1; + } else { + return 1; + } +} diff --git a/src/client/http.c b/client/src/http.c similarity index 99% rename from src/client/http.c rename to client/src/http.c index 04b7bf6..355380a 100644 --- a/src/client/http.c +++ b/client/src/http.c @@ -1,4 +1,4 @@ -#include "http.h" +#include "../include/http.h" #define HTTP_BUFFER_SIZE 1024 diff --git a/src/client/main.c b/client/src/main.c similarity index 90% rename from src/client/main.c rename to client/src/main.c index 02ccb5b..4ebc17a 100644 --- a/src/client/main.c +++ b/client/src/main.c @@ -2,16 +2,16 @@ #include #include -#include "fraction.h" -#include "http.h" -#include "sock.h" -#include "utils.h" +#include "../include/fraction.h" +#include "../include/http.h" +#include "../include/sock.h" +#include "../include/utils.h" /* Networking constants */ #define SERVER_IP "127.0.0.1" #define SERVER_PORT "8000" -int main() { +int main(void) { struct addrinfo hints, *ainfo; int sfd; // socket file descriptor char hostname[NI_MAXHOST]; @@ -66,6 +66,7 @@ int main() { goto cleanup_socket; } + // Storing the fractions in a array fraction_t *fractions = malloc(lines_read * sizeof(fraction_t)); for (int i=0; i