+ +
2da5fe7 OpenAVX v0.2.0 - High-performance open-standard IP audio and video transport suite
saifmukhtar · 2026-11-24
c · 72 lines · 1.6 KB · SPDX: MIT
main
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 #include <stdio.h>
9 #include <stdarg.h>
10 #include <ctype.h>
11  
12 #include <spa/utils/defs.h>
13  
14 #ifdef __cplusplus
15 extern "C" {
16 #endif
17  
18 /**
19 * \addtogroup spa_debug
20 * \{
21 */
22  
23 #ifndef spa_debugn
24 #define spa_debugn(_fmt,...) printf((_fmt), ## __VA_ARGS__)
25 #endif
26 #ifndef spa_debug
27 #define spa_debug(_fmt,...) spa_debugn(_fmt"\n", ## __VA_ARGS__)
28 #endif
29  
30  
31 #ifndef SPA_API_DEBUG_CONTEXT
32 #ifdef SPA_API_IMPL
33 #define SPA_API_DEBUG_CONTEXT SPA_API_IMPL
34 #else
35 #define SPA_API_DEBUG_CONTEXT static inline
36 #endif
37 #endif
38  
39 struct spa_debug_context {
40 void (*log) (struct spa_debug_context *ctx, const char *fmt, ...) SPA_PRINTF_FUNC(2, 3);
41 };
42  
43 #define spa_debugc(_c,_fmt,...) (_c)?((_c)->log((_c),_fmt, ## __VA_ARGS__)):(void)spa_debug(_fmt, ## __VA_ARGS__)
44  
45 SPA_API_DEBUG_CONTEXT void spa_debugc_error_location(struct spa_debug_context *c,
46 struct spa_error_location *loc)
47 {
48 int i, skip = loc->col > 80 ? loc->col - 40 : 0, lc = loc->col-skip-1;
49 char buf[80];
50  
51 for (i = 0; (size_t)i < sizeof(buf)-1 && (size_t)(i + skip) < loc->len; i++) {
52 char ch = loc->location[i + skip];
53 if (ch == '\n' || ch == '\0')
54 break;
55 buf[i] = isspace(ch) ? ' ' : ch;
56 }
57 buf[i] = '\0';
58 spa_debugc(c, "line:%6d | %s%s", loc->line, skip ? "..." : "", buf);
59 for (i = 0; buf[i]; i++)
60 buf[i] = i < lc ? '-' : i == lc ? '^' : ' ';
61 spa_debugc(c, "column:%4d |-%s%s", loc->col, skip ? "---" : "", buf);
62 }
63  
64 /**
65 * \}
66 */
67  
68 #ifdef __cplusplus
69 } /* extern "C" */
70 #endif
71  
72 #endif /* SPA_DEBUG_CONTEXT_H */