xref: /PHP-8.1/sapi/phpdbg/phpdbg_out.h (revision 6318040d)
1 /*
2    +----------------------------------------------------------------------+
3    | Copyright (c) The PHP Group                                          |
4    +----------------------------------------------------------------------+
5    | This source file is subject to version 3.01 of the PHP license,      |
6    | that is bundled with this package in the file LICENSE, and is        |
7    | available through the world-wide-web at the following url:           |
8    | https://www.php.net/license/3_01.txt                                 |
9    | If you did not receive a copy of the PHP license and are unable to   |
10    | obtain it through the world-wide-web, please send a note to          |
11    | license@php.net so we can mail you a copy immediately.               |
12    +----------------------------------------------------------------------+
13    | Authors: Felipe Pena <felipe@php.net>                                |
14    | Authors: Joe Watkins <joe.watkins@live.co.uk>                        |
15    | Authors: Bob Weinand <bwoebi@php.net>                                |
16    +----------------------------------------------------------------------+
17 */
18 
19 #ifndef PHPDBG_OUT_H
20 #define PHPDBG_OUT_H
21 
22 /**
23  * Error/notice/formatting helpers
24  */
25 enum {
26 	P_ERROR  = 1,
27 	P_NOTICE,
28 	P_WRITELN,
29 	P_WRITE,
30 	P_STDOUT,
31 	P_STDERR,
32 	P_LOG
33 };
34 
35 PHPDBG_API int phpdbg_print(int severity, int fd, const char *strfmt, ...) PHP_ATTRIBUTE_FORMAT(printf, 3, 4);
36 PHPDBG_API int phpdbg_log_internal(int fd, const char *fmt, ...) PHP_ATTRIBUTE_FORMAT(printf, 2, 3);
37 PHPDBG_API int phpdbg_out_internal(int fd, const char *fmt, ...) PHP_ATTRIBUTE_FORMAT(printf, 2, 3);
38 
39 #define phpdbg_error(strfmt, ...)              phpdbg_print(P_ERROR  , PHPDBG_G(io)[PHPDBG_STDOUT].fd, strfmt, ##__VA_ARGS__)
40 #define phpdbg_notice(strfmt, ...)             phpdbg_print(P_NOTICE , PHPDBG_G(io)[PHPDBG_STDOUT].fd, strfmt, ##__VA_ARGS__)
41 #define phpdbg_writeln(strfmt, ...)            phpdbg_print(P_WRITELN, PHPDBG_G(io)[PHPDBG_STDOUT].fd, strfmt, ##__VA_ARGS__)
42 #define phpdbg_write(strfmt, ...)              phpdbg_print(P_WRITE  , PHPDBG_G(io)[PHPDBG_STDOUT].fd, strfmt, ##__VA_ARGS__)
43 
44 #define phpdbg_log(fmt, ...)                   phpdbg_log_internal(PHPDBG_G(io)[PHPDBG_STDOUT].fd, fmt, ##__VA_ARGS__)
45 #define phpdbg_out(fmt, ...)                   phpdbg_out_internal(PHPDBG_G(io)[PHPDBG_STDOUT].fd, fmt, ##__VA_ARGS__)
46 
47 #define phpdbg_script(type, strfmt, ...)       phpdbg_print(type,      PHPDBG_G(io)[PHPDBG_STDOUT].fd, strfmt, ##__VA_ARGS__)
48 
49 #define phpdbg_asprintf(buf, ...) _phpdbg_asprintf(buf, ##__VA_ARGS__)
50 PHPDBG_API int _phpdbg_asprintf(char **buf, const char *format, ...);
51 
52 #if PHPDBG_DEBUG
53 #	define phpdbg_debug(strfmt, ...) phpdbg_log_internal(PHPDBG_G(io)[PHPDBG_STDERR].fd, strfmt, ##__VA_ARGS__)
54 #else
55 #	define phpdbg_debug(strfmt, ...)
56 #endif
57 
58 PHPDBG_API void phpdbg_free_err_buf(void);
59 PHPDBG_API void phpdbg_activate_err_buf(bool active);
60 PHPDBG_API int phpdbg_output_err_buf(const char *strfmt, ...);
61 
62 
63 /* {{{ For separation */
64 #define SEPARATE "------------------------------------------------" /* }}} */
65 
66 #endif /* PHPDBG_OUT_H */
67