commit 8f0c18fa1f9fbdd4b1648ba0704cd2410dfcbd1d parent 301cc5f9e579c50b3f5f5cd94ee720969ce88539 Author: Christos Margiolis <christos@margiolis.net> Date: Sun, 19 Jan 2020 22:55:10 +0200 added ccolors.h Diffstat:
15 files changed, 117 insertions(+), 3 deletions(-)
diff --git a/assignment-1.5-arrays-pointers-files/combinations/bin/combs b/assignment-1.5-arrays-pointers-files/combinations/bin/combs Binary files differ. diff --git a/assignment-1.5-arrays-pointers-files/combinations/include/ccolors.h b/assignment-1.5-arrays-pointers-files/combinations/include/ccolors.h @@ -0,0 +1,30 @@ +#ifndef C_COLORS_H +#define C_COLORS_H + +#include <stdio.h> + +typedef enum {RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, BOLD_RED, BOLD_GREEN, BOLD_YELLOW, BOLD_BLUE, BOLD_MAGENTA, BOLD_CYAN, STANDARD} options; + +__attribute__((always_inline)) void inline set_color(options color) +{ + switch (color) + { + case RED: printf("\033[0;31m"); break; + case GREEN: printf("\033[0;32m"); break; + case YELLOW: printf("\033[0;33m"); break; + case BLUE: printf("\033[0;34m"); break; + case MAGENTA: printf("\033[0;35m"); break; + case CYAN: printf("\033[0;36m"); break; + + case BOLD_RED: printf("\033[1;31m"); break; + case BOLD_GREEN: printf("\033[1;32m"); break; + case BOLD_YELLOW: printf("\033[1;33m"); break; + case BOLD_BLUE: printf("\033[1;34m"); break; + case BOLD_MAGENTA: printf("\033[1;35m"); break; + case BOLD_CYAN: printf("\033[1;36m"); break; + + case STANDARD: printf("\033[0m"); break; + } +} + +#endif+ \ No newline at end of file diff --git a/assignment-1.5-arrays-pointers-files/combinations/obj/arrhandler.o b/assignment-1.5-arrays-pointers-files/combinations/obj/arrhandler.o Binary files differ. diff --git a/assignment-1.5-arrays-pointers-files/combinations/obj/combinations.o b/assignment-1.5-arrays-pointers-files/combinations/obj/combinations.o Binary files differ. diff --git a/assignment-1.5-arrays-pointers-files/combinations/src/arrhandler.c b/assignment-1.5-arrays-pointers-files/combinations/src/arrhandler.c @@ -2,6 +2,7 @@ #include <stdlib.h> #include "arrhandler.h" #include "combinations.h" +#include "ccolors.h" int *fill_array(int N) @@ -11,8 +12,10 @@ int *fill_array(int N) if (arr == NULL) { + set_color(BOLD_RED); printf("Error! Not enough memory, exiting...\n"); exit(EXIT_FAILURE); + set_color(STANDARD); } else { diff --git a/assignment-1.5-arrays-pointers-files/combinations/src/combinations.c b/assignment-1.5-arrays-pointers-files/combinations/src/combinations.c @@ -3,6 +3,7 @@ #include <stdbool.h> #include "combinations.h" #include "arrhandler.h" +#include "ccolors.h" int get_n() @@ -53,8 +54,10 @@ void print_combs(int *arr, int N, int x1, int x2, int y1, int y2) if (currComb == NULL) { + set_color(BOLD_RED); printf("Error! Not enough memory, exiting...\n"); exit(EXIT_FAILURE); + set_color(STANDARD); } else { diff --git a/assignment-1.5-arrays-pointers-files/documentation/assignment-1.5.pdf b/assignment-1.5-arrays-pointers-files/documentation/assignment-1.5.pdf Binary files differ. diff --git a/assignment-1.5-arrays-pointers-files/documentation/assignment-1.5.synctex.gz b/assignment-1.5-arrays-pointers-files/documentation/assignment-1.5.synctex.gz Binary files differ. diff --git a/assignment-1.5-arrays-pointers-files/fcombinations/include/ccolors.h b/assignment-1.5-arrays-pointers-files/fcombinations/include/ccolors.h @@ -0,0 +1,30 @@ +#ifndef C_COLORS_H +#define C_COLORS_H + +#include <stdio.h> + +typedef enum {RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, BOLD_RED, BOLD_GREEN, BOLD_YELLOW, BOLD_BLUE, BOLD_MAGENTA, BOLD_CYAN, STANDARD} options; + +__attribute__((always_inline)) void inline set_color(options color) +{ + switch (color) + { + case RED: printf("\033[0;31m"); break; + case GREEN: printf("\033[0;32m"); break; + case YELLOW: printf("\033[0;33m"); break; + case BLUE: printf("\033[0;34m"); break; + case MAGENTA: printf("\033[0;35m"); break; + case CYAN: printf("\033[0;36m"); break; + + case BOLD_RED: printf("\033[1;31m"); break; + case BOLD_GREEN: printf("\033[1;32m"); break; + case BOLD_YELLOW: printf("\033[1;33m"); break; + case BOLD_BLUE: printf("\033[1;34m"); break; + case BOLD_MAGENTA: printf("\033[1;35m"); break; + case BOLD_CYAN: printf("\033[1;36m"); break; + + case STANDARD: printf("\033[0m"); break; + } +} + +#endif+ \ No newline at end of file diff --git a/assignment-1.5-arrays-pointers-files/fcombinations/src/arrhandler.c b/assignment-1.5-arrays-pointers-files/fcombinations/src/arrhandler.c @@ -2,6 +2,7 @@ #include <stdlib.h> #include "arrhandler.h" #include "fcombinations.h" +#include "ccolors.h" int *fill_array(int N) @@ -11,8 +12,10 @@ int *fill_array(int N) if (arr == NULL) { + set_color(BOLD_RED); printf("Error! Not enough memory, exiting...\n"); exit(EXIT_FAILURE); + set_color(STANDARD); } else { diff --git a/assignment-1.5-arrays-pointers-files/fcombinations/src/fcombinations.c b/assignment-1.5-arrays-pointers-files/fcombinations/src/fcombinations.c @@ -3,6 +3,7 @@ #include <stdbool.h> #include <string.h> #include "fcombinations.h" +#include "ccolors.h" #define COMBSN 6 @@ -13,8 +14,10 @@ void read_file(char **argv) if (dataFile == NULL) { - printf("Error opening the file, exiting...\n"); + set_color(BOLD_RED); + printf("Error! Not enough memory, exiting...\n"); exit(EXIT_FAILURE); + set_color(STANDARD); } else { @@ -57,8 +60,10 @@ void print_combs(int *arr, int N, int x1, int x2, int y1, int y2) if (currComb == NULL) { + set_color(BOLD_RED); printf("Error! Not enough memory, exiting...\n"); exit(EXIT_FAILURE); + set_color(STANDARD); } else { diff --git a/assignment-1.5-arrays-pointers-files/kcombinations/include/ccolors.h b/assignment-1.5-arrays-pointers-files/kcombinations/include/ccolors.h @@ -0,0 +1,30 @@ +#ifndef C_COLORS_H +#define C_COLORS_H + +#include <stdio.h> + +typedef enum {RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, BOLD_RED, BOLD_GREEN, BOLD_YELLOW, BOLD_BLUE, BOLD_MAGENTA, BOLD_CYAN, STANDARD} options; + +__attribute__((always_inline)) void inline set_color(options color) +{ + switch (color) + { + case RED: printf("\033[0;31m"); break; + case GREEN: printf("\033[0;32m"); break; + case YELLOW: printf("\033[0;33m"); break; + case BLUE: printf("\033[0;34m"); break; + case MAGENTA: printf("\033[0;35m"); break; + case CYAN: printf("\033[0;36m"); break; + + case BOLD_RED: printf("\033[1;31m"); break; + case BOLD_GREEN: printf("\033[1;32m"); break; + case BOLD_YELLOW: printf("\033[1;33m"); break; + case BOLD_BLUE: printf("\033[1;34m"); break; + case BOLD_MAGENTA: printf("\033[1;35m"); break; + case BOLD_CYAN: printf("\033[1;36m"); break; + + case STANDARD: printf("\033[0m"); break; + } +} + +#endif+ \ No newline at end of file diff --git a/assignment-1.5-arrays-pointers-files/kcombinations/src/arrhandler.c b/assignment-1.5-arrays-pointers-files/kcombinations/src/arrhandler.c @@ -2,6 +2,7 @@ #include <stdlib.h> #include "arrhandler.h" #include "kcombinations.h" +#include "ccolors.h" int *fill_array(int N) @@ -11,8 +12,10 @@ int *fill_array(int N) if (arr == NULL) { + set_color(BOLD_RED); printf("Error! Not enough memory, exiting...\n"); exit(EXIT_FAILURE); + set_color(STANDARD); } else { diff --git a/assignment-1.5-arrays-pointers-files/kcombinations/src/kcombinations.c b/assignment-1.5-arrays-pointers-files/kcombinations/src/kcombinations.c @@ -3,6 +3,7 @@ #include <stdbool.h> #include "kcombinations.h" #include "arrhandler.h" +#include "ccolors.h" int get_n() @@ -67,8 +68,10 @@ void print_combs(int *arr, int N, int K, int x1, int x2, int y1, int y2) if (currComb == NULL) { + set_color(BOLD_RED); printf("Error! Not enough memory, exiting...\n"); exit(EXIT_FAILURE); + set_color(STANDARD); } else { diff --git a/assignment-1.5-arrays-pointers-files/notes.md b/assignment-1.5-arrays-pointers-files/notes.md @@ -1,2 +1,3 @@ * meter function -* kcombinations- \ No newline at end of file +* kcombinations +* ccolors+ \ No newline at end of file