PipeWire
1.2.6
Loading...
Searching...
No Matches
context.h
Go to the documentation of this file.
1
/* Simple Plugin API */
2
/* SPDX-FileCopyrightText: Copyright © 2023 Wim Taymans */
3
/* SPDX-License-Identifier: MIT */
4
5
#ifndef SPA_DEBUG_CONTEXT_H
6
#define SPA_DEBUG_CONTEXT_H
7
8
#ifdef __cplusplus
9
extern
"C"
{
10
#endif
11
12
#include <stdio.h>
13
#include <stdarg.h>
14
#include <ctype.h>
15
16
#include <
spa/utils/defs.h
>
22
#ifndef spa_debugn
23
#define spa_debugn(_fmt,...) printf((_fmt), ## __VA_ARGS__)
24
#endif
25
#ifndef spa_debug
26
#define spa_debug(_fmt,...) spa_debugn(_fmt"\n", ## __VA_ARGS__)
27
#endif
28
29
struct
spa_debug_context
{
30
void (*
log
) (
struct
spa_debug_context
*ctx,
const
char
*fmt, ...)
SPA_PRINTF_FUNC
(2, 3);
31
};
32
33
#define spa_debugc(_c,_fmt,...) (_c)?((_c)->log((_c),_fmt, ## __VA_ARGS__)):(void)spa_debug(_fmt, ## __VA_ARGS__)
34
35
static
inline
void
spa_debugc_error_location
(
struct
spa_debug_context
*c,
36
struct
spa_error_location
*loc)
37
{
38
int
i, skip = loc->
col
> 80 ? loc->
col
- 40 : 0, lc = loc->
col
-skip-1;
39
char
buf[80];
40
41
for
(i = 0; (size_t)i <
sizeof
(buf)-1 && (size_t)(i + skip) < loc->
len
; i++) {
42
char
ch = loc->
location
[i + skip];
43
if
(ch ==
'\n'
|| ch ==
'\0'
)
44
break
;
45
buf[i] = isspace(ch) ?
' '
: ch;
46
}
47
buf[i] =
'\0'
;
48
spa_debugc
(c,
"line:%6d | %s%s"
, loc->
line
, skip ?
"..."
:
""
, buf);
49
for
(i = 0; buf[i]; i++)
50
buf[i] = i < lc ?
'-'
: i == lc ?
'^'
:
' '
;
51
spa_debugc
(c,
"column:%4d |-%s%s"
, loc->
col
, skip ?
"---"
:
""
, buf);
52
}
53
58
#ifdef __cplusplus
59
}
/* extern "C" */
60
#endif
61
62
#endif
/* SPA_DEBUG_CONTEXT_H */
defs.h
spa/utils/defs.h
spa_debugc_error_location
static void spa_debugc_error_location(struct spa_debug_context *c, struct spa_error_location *loc)
Definition
context.h:40
spa_debugc
#define spa_debugc(_c, _fmt,...)
Definition
context.h:38
SPA_PRINTF_FUNC
#define SPA_PRINTF_FUNC(fmt, arg1)
Definition
defs.h:295
spa_debug_context
Definition
context.h:34
spa_debug_context::log
void(* log)(struct spa_debug_context *ctx, const char *fmt,...)
Definition
context.h:35
spa_error_location
Definition
defs.h:414
spa_error_location::line
int line
Definition
defs.h:415
spa_error_location::location
const char * location
Definition
defs.h:418
spa_error_location::col
int col
Definition
defs.h:416
spa_error_location::len
size_t len
Definition
defs.h:417
spa
debug
context.h
Generated by
1.12.0