forked from yanhan/powaur
/
util.h
103 lines (79 loc) · 3.25 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
#ifndef POWAUR_UTIL_H
#define POWAUR_UTIL_H
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <alpm.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);
/* Trims version from a string. ie, if you pass it "pacman>=3.5",
* the string will become "pacman".
*
* @param line modifiable string
*/
char *strtrim_ver(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);
void print_list_color(alpm_list_t *list, const char *wcolor);
void print_list_prefix(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);
/* Prints a list of aurpkg_t * */
void print_aurpkg_list(alpm_list_t *list);
/* Returns 1 for yes, 0 for no */
int yesno(const char *fmt, ...);
/* Asks the user a multiple choice question.
* returns the index of array corresponding to user's answer.
*
* @param qn question to ask
* @param array a character array of options
* @param arraySize size of array
* @param preset index of answer to return if user just presses Enter
*/
int mcq(const char *qn, const char *array, int arraySize, int preset);
char *have_dotinstall(void);
/* Prints the color of a repo */
void color_repo(const char *repo);
/* Prints groups in color */
void color_groups(alpm_list_t *grp);
/* sdbm string hashing function */
unsigned long sdbm(const char *str);
#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)
#endif