-
Notifications
You must be signed in to change notification settings - Fork 0
/
format_print.h
65 lines (57 loc) · 2.33 KB
/
format_print.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
/*
* Copyright 2008-2013 Various Authors
* Copyright 2004 Timo Hirvonen
*
* 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 2 of the
* License, or (at your option) 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/>.
*/
#ifndef CMUS_FORMAT_PRINT_H
#define CMUS_FORMAT_PRINT_H
#include "gbuf.h"
struct format_option {
union {
/* NULL is treated like "" */
const char *fo_str;
int fo_int;
/* [h:]mm:ss. can be negative */
int fo_time;
double fo_double;
};
/* set to 1 if you want to disable printing */
unsigned int empty : 1;
/* set to 1 if zero padding is allowed */
unsigned int pad_zero : 1;
enum { FO_STR = 1, FO_INT, FO_TIME, FO_DOUBLE } type;
char ch;
const char *str;
};
/* gcc < 4.6 and icc < 12.0 can't properly initialize anonymous unions */
#if (defined(__GNUC__) && defined(__GNUC_MINOR__) && (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 6))) || \
(defined(__INTEL_COMPILER) && __INTEL_COMPILER < 1200)
#define UNION_INIT(f, v) { .f = v }
#else
#define UNION_INIT(f, v) .f = v
#endif
#define DEF_FO_STR(c, s, z) { UNION_INIT(fo_str, ""), .type = FO_STR, .pad_zero = z, .ch = c, .str = s }
#define DEF_FO_INT(c, s, z) { UNION_INIT(fo_int, 0), .type = FO_INT, .pad_zero = z, .ch = c, .str = s }
#define DEF_FO_TIME(c, s, z) { UNION_INIT(fo_time, 0), .type = FO_TIME, .pad_zero = z, .ch = c, .str = s }
#define DEF_FO_DOUBLE(c, s, z) { UNION_INIT(fo_double, 0.), .type = FO_DOUBLE, .pad_zero = z, .ch = c, .str = s }
#define DEF_FO_END { .type = 0 }
struct fp_len {
int llen;
int rlen;
};
struct fp_len format_print(char *buf, int str_width, const char *format, const struct format_option *fopts);
struct fp_len format_print_gbuf(struct gbuf *buf, int str_width, const char *format, const struct format_option *fopts);
int format_valid(const char *format, const struct format_option *fopts);
#endif