This repository has been archived by the owner on Mar 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
util.h
114 lines (87 loc) · 2.71 KB
/
util.h
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#ifndef POWAUR_UTIL_H
#define POWAUR_UTIL_H
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <alpm_list.h>
#include "error.h"
#include "powaur.h"
#include "environment.h"
#include "wrapper.h"
int powaur_backup(alpm_list_t *targets);
extern int (*pw_printf)(enum pwloglevel_t lvl, const char *fmt, ...)
__attribute__((format (printf, 2, 3)));
extern int (*pw_fprintf)(enum pwloglevel_t lvl, FILE *stream, const char *fmt, ...)
__attribute__((format (printf, 3, 4)));
extern int (*pw_vfprintf)(enum pwloglevel_t lvl, FILE *stream, const char *fmt, va_list ap)
__attribute__((format (printf, 3, 0)));
/* Setup color printing functions */
void color_print_setup(void);
/* Restore color printing functions to non-colorized versions */
void color_print_restore(void);
int extract_file(const char *filename);
int getcols(void);
char *strtrim(char *line);
int wait_or_whine(pid_t pid, char *argv0);
/* Prints c for rep times */
void print_repeat(char c, int rep);
void indent_print(enum pwloglevel_t lvl, alpm_list_t *list, size_t indent);
void print_list(alpm_list_t *list, const char *prefix);
void print_list_break(alpm_list_t *list, const char *prefix);
void print_list_deps(alpm_list_t *list, const char *prefix);
void print_pkginfo(alpm_list_t *list);
int yesno(const char *fmt, ...);
int mcq(const char *qn, const char *array, int arraySize, int preset);
char *have_dotinstall(void);
alpm_list_t *list_diff(alpm_list_t *left, alpm_list_t *right,
alpm_list_fn_cmp cmpfn);
alpm_list_t *list_intersect(alpm_list_t *left, alpm_list_t *right,
alpm_list_fn_cmp cmpfn);
/* Prints the color of a repo */
void color_repo(const char *repo);
/* Prints groups in color */
void color_groups(alpm_list_t *grp);
#define MINI_BUFSZ 60
#define ASSERT(somecond, someact) do {\
if (!(somecond)) {\
someact;\
}\
} while (0)
#define PW_SETERRNO(errnum) do {\
pwerrno = errnum;\
pw_fprintf(PW_LOG_ERROR, stderr, "%s: %s\n", __func__, pw_strerrorlast());\
} while (0)
#define CLEAR_ERRNO() do {\
pwerrno = PW_ERR_OK;\
} while (0)
#define RET_ERR(errnum, retval) do {\
pwerrno = errnum;\
pw_printf(PW_LOG_ERROR, "%s: %s\n", __func__, pw_strerror(errnum));\
return retval;\
} while (0)
#define RET_ERR_VOID(errnum) do {\
pwerrno = errnum;\
return;\
} while (0)
#define CALLOC(myptr, nmemb, mysz, act) do {\
myptr = xcalloc(nmemb, mysz);\
if (!myptr) {\
act;\
}\
} while (0)
#define MALLOC(myptr, mysz, act) do {\
myptr = malloc(mysz);\
if (!myptr) {\
act;\
}\
} while (0)
#define STRDUP(mydest, myorig, act) do {\
mydest = strdup(myorig);\
if (!mydest) {\
act;\
}\
} while(0)
#define FREE(myptr) if (myptr) { free(myptr); }
#define FCLOSE(myfp) if (myfp) { fclose(myfp); myfp = NULL; }
#endif