src
yprintf.c
Go to the documentation of this file.
1
// Copyright (c) 2010-2016 The YP-Spur Authors, except where otherwise indicated.
2
//
3
// Permission is hereby granted, free of charge, to any person obtaining a copy
4
// of this software and associated documentation files (the "Software"), to
5
// deal in the Software without restriction, including without limitation the
6
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7
// sell copies of the Software, and to permit persons to whom the Software is
8
// furnished to do so, subject to the following conditions:
9
//
10
// The above copyright notice and this permission notice shall be included in
11
// all copies or substantial portions of the Software.
12
//
13
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
// SOFTWARE.
20
21
#include <stdarg.h>
22
#include <stdio.h>
23
#include <strings.h>
24
#include <unistd.h>
25
26
#ifdef HAVE_CONFIG_H
27
#include <config.h>
28
#endif // HAVE_CONFIG_H
29
30
#include <
param.h
>
31
32
void
yprintf
(
ParamOutputLv
level,
const
char
*format, ...)
33
{
34
va_list ap;
35
36
if
(
output_lv
() < level)
37
return
;
38
39
#if !defined(__MINGW32__)
40
if
(isatty(2))
41
{
42
switch
(level)
43
{
44
case
OUTPUT_LV_ERROR
:
45
fputs(
"\x1B[0;31m"
, stderr);
46
break
;
47
case
OUTPUT_LV_WARNING
:
48
fputs(
"\x1B[0;33m"
, stderr);
49
break
;
50
default
:
51
break
;
52
}
53
}
54
#endif // !defined(__MINGW32__)
55
56
va_start(ap, format);
57
vfprintf(stderr, format, ap);
58
va_end(ap);
59
60
#if !defined(__MINGW32__)
61
if
(isatty(2))
62
fputs(
"\x1B[0m"
, stderr);
63
#endif // !defined(__MINGW32__)
64
65
fflush(stderr);
66
}
67
68
void
ansi_clear_line
(
ParamOutputLv
level)
69
{
70
if
(
output_lv
() < level)
71
return
;
72
73
#if !defined(__MINGW32__)
74
if
(isatty(2))
75
fprintf(stderr,
"\x1B[2K\r"
);
76
else
77
fputs(
"\n"
, stderr);
78
#else
79
fputs(
"\n"
, stderr);
80
#endif // !defined(__MINGW32__)
81
}
yprintf
void yprintf(ParamOutputLv level, const char *format,...)
Definition:
yprintf.c:32
ansi_clear_line
void ansi_clear_line(ParamOutputLv level)
Definition:
yprintf.c:68
output_lv
ParamOutputLv output_lv(void)
Definition:
libypspur-md.c:1431
param.h
OUTPUT_LV_WARNING
@ OUTPUT_LV_WARNING
Definition:
param.h:68
OUTPUT_LV_ERROR
@ OUTPUT_LV_ERROR
Definition:
param.h:67
ParamOutputLv
ParamOutputLv
Definition:
param.h:65
yp-spur
Author(s):
autogenerated on Fri Oct 20 2023 03:02:42