-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.h
More file actions
98 lines (84 loc) · 2.99 KB
/
Copy pathutils.h
File metadata and controls
98 lines (84 loc) · 2.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
* STUDENTS: Buda Francesco, Ceredi Tommaso, Maglia Danilo, Severi Tommaso
* DATE: 11/15/2021
* FILE: utils.h
* DESCRIPTION: INTERFACE FOR THE "utils" LIBRARY. THIS HEADER
* CONTAINS DEFINITIONS OF FUNCTIONS THAT OFTEN HAPPEN
* TO USE IN DIFFERENT PROGRAMS.
* ALSO THE HEADER DEFINES MACROS TO IMPROVE
* THE PORTABILITY OF THE VARIOUS PROGRAMS AND DEFINES OF THE MACROS
* FOR COLORS.
* VERSION: 1.5
*/
#ifndef GROUP_UTILS_H // Include guard
#define GROUP_UTILS_H
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
// PROBABILITY MACROS
#if defined __linux__ || defined __APPLE__ // If compiles in linux or macos
#include <unistd.h>
#define sleep(x) usleep( x * 1000 ); // Milliseconds macros fo sleep (usleep works in microseconds)
#define BAR_FULL "\u2588"
#define BAR_EMPTY "\u2591"
#define PRINTBAR(x) printf("%s", x)
#elif _WIN32 // If compiles on windows
#include <windows.h>
#define sleep(x) Sleep(x)
#define BAR_FULL 219
#define BAR_EMPTY 176
#define PRINTBAR(x) printf("%c", x)
#endif
// CURSOR MOVEMENT MACROS
#define MOVE_CUR(x,y) "\033["#x";"#y"H"
#define MOVE_CUR_UP(y) "\033["#y"A"
#define MOVE_CUR_DOWN(y) "\033["#y"B"
#define MOVE_CUR_RIGHT(x) "\033["#x"C"
#define MOVE_CUR_LEFT(x) "\033["#x"D"
#define SAVE_CUR_POS "\033[s"
#define RESTORE_CUR_POS "\033[u"
#define CLEAR_SCREEN "\033[2J"
#define RESET_CURSOR "\033[H"
// COLOR MACROS
#define CON_RESET "\033[0m"
#define COLOR_GREEN "\033[32m"
#define COLOR_BLACK "\e[0;30m"
#define COLOR_RED "\e[0;31m"
#define COLOR_YELLOW "\e[0;33m"
#define COLOR_BLUE "\e[0;34m"
#define COLOR_MAGENTA "\e[0;35m"
#define COLOR_CYANO "\e[0;36m"
#define COLOR_WHITE "\e[0;37m"
#ifndef MAX_STRING_SIZE
#define MAX_STRING_SIZE 100
#endif
// ESCAPE SEQUENCE FUNCTIONS
void initEscapeSequence();
void clearScreen();
// INPUT FUNCTIONS
void stralloc(char** str);
void fstralloc(char**, FILE*);
void flushStdin();
// CURSOR MOVEMENT FUNCTIONS
void moveCursor(int x, int y);
void moveCurUp(int y);
void moveCurDown(int y);
void moveCurRight(int x);
void moveCurLeft(int x);
void saveCurPos();
void restoreCurPos();
// COLOR FUNCTIONS
void setColor(char* color);
void resetColor();
void coloredMessage(char* color, char* message);
// RANDOM GENERATION FUNCTIONS
void initRandom();
int randomIntRange(int min, int max);
// ARRAY FUNCTIONS
bool existsInt(int* v, int n, int size);
bool existsFloat(float* v, float n, int size);
void printArrayInt(int* v, int size);
void printArrayFloat(float* v, float size);
// BAR PROGRESSION FUNCTION
void progress(int perc);
#endif