1 /****************************************************************************
2  * bfs                                                                      *
3  * Copyright (C) 2017-2020 Tavian Barnes <tavianator@tavianator.com>        *
4  *                                                                          *
5  * Permission to use, copy, modify, and/or distribute this software for any *
6  * purpose with or without fee is hereby granted.                           *
7  *                                                                          *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES *
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF         *
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR  *
11  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES   *
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN    *
13  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF  *
14  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.           *
15  ****************************************************************************/
16 
17 /**
18  * Implementation of -printf/-fprintf.
19  */
20 
21 #ifndef BFS_PRINTF_H
22 #define BFS_PRINTF_H
23 
24 #include "color.h"
25 
26 struct BFTW;
27 struct bfs_ctx;
28 
29 /**
30  * A printf command, the result of parsing a single format string.
31  */
32 struct bfs_printf;
33 
34 /**
35  * Parse a -printf format string.
36  *
37  * @param ctx
38  *         The bfs context.
39  * @param format
40  *         The format string to parse.
41  * @return
42  *         The parsed printf command, or NULL on failure.
43  */
44 struct bfs_printf *bfs_printf_parse(const struct bfs_ctx *ctx, const char *format);
45 
46 /**
47  * Evaluate a parsed format string.
48  *
49  * @param cfile
50  *         The CFILE to print to.
51  * @param format
52  *         The parsed printf format.
53  * @param ftwbuf
54  *         The bftw() data for the current file.
55  * @return
56  *         0 on success, -1 on failure.
57  */
58 int bfs_printf(CFILE *cfile, const struct bfs_printf *format, const struct BFTW *ftwbuf);
59 
60 /**
61  * Free a parsed format string.
62  */
63 void bfs_printf_free(struct bfs_printf *format);
64 
65 #endif // BFS_PRINTF_H
66