-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.c
81 lines (77 loc) · 1.69 KB
/
helpers.c
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
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include "helpers.h"
void COLOR(int color){
// NEGATIVE:BOLD // 0:RESET
// 1:RED // 2:GREEN
// 3:YELLOW // 4:BLUE
// 5:MAGENTA // 6:CYAN
if (!color)
printf("\033[0m");
else
printf(color>0?"\033[0;3%dm":"\033[1;3%dm",abs(color));
}
void ERROR(char *c, ...)
{
fprintf( stderr, "ERROR:line:%ld>> ",lineNUM+1);
va_list lst;
va_start(lst, c);
while(*c!='\0')
{
if(*c!='%')
{
fprintf( stderr, "%c",*c);
c++;
continue;
}
c++;
switch(*c)
{
case 's': fputs(va_arg(lst, char *), stderr); break;
case 'c': fprintf(stderr,"%c",(va_arg(lst, int))); break;
}
c++;
}
printf("\n");
exit(-1);
}
void VERBOSE(char *c, ...)
{
if (!Verbose) return;
//COLOR(-2);
fprintf(stdout, "VERBOSE>> ");
//COLOR(3);
va_list lst;
va_start(lst, c);
while (*c != '\0') {
if (*c != '%') {
fprintf(stdout, "%c", *c);
c++;
continue;
}
c++;
switch (*c) {
case 's':
fputs(va_arg(lst, char *), stdout);
break;
case 'c':
fprintf(stdout, "%c", (va_arg(lst, int)));
break;
case 'd':
fprintf(stdout,"%d",(va_arg(lst, int)));
}
c++;
}
//COLOR(0);
printf("\n");
}
char* removeSpaces(char* str){
int count = 0;
for(int i = 0;str[i];i++){
if (str[i]!=' ')
str[count++] = str[i];
}
str[count]= '\0';
return str;
}