-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoutput.c
112 lines (98 loc) · 2.61 KB
/
output.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
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
/*
* common_output.c - define some easy fuctions
* Copyright © 2014 - Niels Neumann <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "output.h"
#include <stdlib.h>
#ifdef COLOR
void styledOutput(char *type, char *mesg, char *color) {
outplain("[");
outplain(color);
outplain(type);
outplain("]");
outplain(CSI_RESET);
outplain(mesg);
outplain("\n");
}
#else
void styledOutput(char *type, char *mesg) {
outplain("[");
outplain(type);
outplain("]");
outplain(mesg);
outplain("\n");
}
#endif
// extended wrapper for write to stderr with colors
void outerr(char *tmp) {
#ifdef COLOR
styledOutput("err",tmp,CSI_RED);
#else
styledOutput("err",tmp);
#endif
}
void outfatal(char *tmp) {
outerr(tmp);
exit(1);
}
// extended wrapper for write to stdout as debug messages
#ifdef DEBUG
void outdeb(char *tmp) {
#ifdef COLOR
styledoutput("deb",tmp,CSI_YELLOW);
#else
styledoutput("deb",tmp);
#endif
}
void outedeb(char *msg,char *content) {
outdeb(msg);
outplain(" : ");
outplain(content);
outplain("\n");
}
#endif
void outstat(char *tmp) {
outplain(" => ");
outplain(tmp);
outplain("\n");
}
/**
* output programname -h for help message
*/
void showHelp(char *app_name, char *app_help) {
char *buffer = NULL;
strmcat(&buffer, "%1 for Linux, BSD and Windows\nuse: %1 %2\n\n");
strmreplace(&buffer,"%1",app_name);
strmreplace(&buffer,"%1",app_name);
strmreplace(&buffer,"%2",app_help);
outplain(buffer);
free(buffer);
}
/**
* output programname -v for version message
*/
void showVersion(char *app_name, char *app_version) {
char *buffer = NULL;
strmcat(&buffer, "%1 %2\nCopyright (C) %3 Niels Neumann <[email protected]\n\
License GPLv3+: GNU GPL Version 3 or later <http://gnu.org/licenses/gpl.html>.\
\nThis is free software: you are free to change and redistribute it.\
\nThere is NO WARRANTY, to the extent permitted by law.\n\n");
strmreplace(&buffer,"%1",app_name);
strmreplace(&buffer,"%2",app_version);
strmreplace(&buffer,"%3",__DATE__);
outplain(buffer);
free(buffer);
}