YASH 0.1
CLI written in C
Loading...
Searching...
No Matches
debug.h
Go to the documentation of this file.
1
9#pragma once
10
11// ============================================================================
12// Includes
13// ============================================================================
14
15#include <stdio.h>
16
17// ============================================================================
18// Debug Configuration
19// ============================================================================
20
21// #define DEBUG 1
22
23// ============================================================================
24// Debug Macros
25// ============================================================================
26
27#ifdef DEBUG
29#define DEBUG_PRINT(fmt, ...) fprintf(stderr, "[DEBUG] " fmt "\n", ##__VA_ARGS__)
30
32#define DEBUG_PARSE(fmt, ...) fprintf(stderr, "[PARSE] " fmt "\n", ##__VA_ARGS__)
33
35#define DEBUG_EXEC(fmt, ...) fprintf(stderr, "[EXEC] " fmt "\n", ##__VA_ARGS__)
36
38#define DEBUG_JOBS(fmt, ...) fprintf(stderr, "[JOBS] " fmt "\n", ##__VA_ARGS__)
39
41#define DEBUG_SIGNALS(fmt, ...) fprintf(stderr, "[SIGNALS] " fmt "\n", ##__VA_ARGS__)
42
44#define DEBUG_COMMAND(cmd) \
45 do { \
46 DEBUG_PARSE("┌─ Parsed Command Structure"); \
47 DEBUG_PARSE("│ Command: %s", (cmd)->argv[0] ? (cmd)->argv[0] : "NULL"); \
48 DEBUG_PARSE("│ Background: %s", (cmd)->background ? "YES" : "NO"); \
49 DEBUG_PARSE("│ Input file: %s", (cmd)->in_file ? (cmd)->in_file : "stdin"); \
50 DEBUG_PARSE("│ Output file: %s", (cmd)->out_file ? (cmd)->out_file : "stdout"); \
51 DEBUG_PARSE("│ Error file: %s", (cmd)->err_file ? (cmd)->err_file : "stderr"); \
52 fprintf(stderr, "[PARSE] │ Arguments: "); \
53 for (int i = 0; i < MAX_ARGS && (cmd)->argv[i]; i++) { \
54 fprintf(stderr, "\"%s\" ", (cmd)->argv[i]); \
55 } \
56 fprintf(stderr, "\n"); \
57 DEBUG_PARSE("└─ End Command Structure"); \
58 } while (0)
59
61#define DEBUG_PROCESS(pid, status) DEBUG_EXEC("Process PID %d, status: %d", pid, status)
62
64#define DEBUG_JOB(job_id, pid, status) DEBUG_JOBS("Job %d: PID %d, status: %d", job_id, pid, status)
65
67#define DEBUG_SIGNAL(sig, action) DEBUG_SIGNALS("Signal %d: %s", sig, action)
68
69#else
70// No-op versions when DEBUG is disabled
72#define DEBUG_PRINT(fmt, ...)
74#define DEBUG_PARSE(fmt, ...)
76#define DEBUG_EXEC(fmt, ...)
78#define DEBUG_JOBS(fmt, ...)
80#define DEBUG_SIGNALS(fmt, ...)
82#define DEBUG_COMMAND(cmd)
84#define DEBUG_PROCESS(pid, status)
86#define DEBUG_JOB(job_id, pid, status)
88#define DEBUG_SIGNAL(sig, action)
89#endif