summaryrefslogtreecommitdiff
path: root/src/util/shared.h
blob: 26e27c30e5f34c4c1daa0acdbfdb18c75a0a7b4e (plain)
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
#pragma once

#include <stdio.h>
#include <stdbool.h>
#include <time.h>
#include <fcntl.h>

#define ANSCII          "\x1b["
#define NEXT            ";"

#define RESET           "0"
#define BOLD            "1"

#define NORMAL          "3"
#define BACKGROUND      "4"
#define HIGHLIGHT       "9"

#define BLACK           "0"
#define RED             "1"
#define GREEN           "2"
#define YELLOW          "3"
#define BLUE            "4"
#define MAGENTA         "5"
#define TURQUOISE       "6"
#define WHITE           "7"

#define COLOR           "m"

enum When {
    YES,
    NO,
    AUTO
};

__attribute__ ((__format__(printf, 1, 2)))
void error_s(const char* format, ...);

__attribute__ ((__format__(printf, 1, 2)))
void error(const char* format, ...);

__attribute__ ((__format__(printf, 1, 2)))
void output(const char* format, ...);

FILE* get_file_s(const char* path, const char* type);
FILE* get_file(const char* path, const char* type);
long int get_number(const char* text);
long int get_blkm(const char* text);
mode_t get_mode(const char* next);

bool streql(const char* a, const char* b);
bool prefix(const char* pre, const char* str);

void print_file_size(size_t bytes, char buf[5]);
void print_date_time(time_t mills, char buf[13]);

#define UNUSED(x) (void)(x)
#define ARG_UNUSED  0
#define ARG_USED    1
#define ARG_IGNORE  2
#define ARG_INVALID 3

void check_arg (char* arg);
void global_help(void (*help)(void));
void parse_help (int argc, char** argv, void (*help)(void));
int parse_args (int argc, char** argv, void (*help)(void), int (*short_arg)(char, char*), int (*long_arg)(char*, char*));

int get_tty();
FILE* get_tty_stream(char* type);

char* get_path_buffer();
int push_path_buffer(const char* string);
void pop_path_buffer(int i);

char* get_path_buffer_2();
int push_path_buffer_2(const char* string);
void pop_path_buffer_2(int i);

bool is_dot_dir(const char* path);