json-gen-c  0.1.5
json-gen-c generate C code for json manipulation
diag.c File Reference

Diagnostic engine implementation. More...

#include "utils/diag.h"
#include "utils/compat.h"
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Include dependency graph for diag.c:

Macros

#define _POSIX_C_SOURCE   200809L
 
#define DIAG_INITIAL_CAPACITY   16
 
#define DIAG_MAX_ERRORS_DEFAULT   20
 
#define DIAG_MSG_BUF_SIZE   1024
 
#define ANSI_RESET   "\033[0m"
 
#define ANSI_BOLD   "\033[1m"
 
#define ANSI_RED   "\033[1;31m"
 
#define ANSI_MAGENTA   "\033[1;35m"
 
#define ANSI_CYAN   "\033[1;36m"
 
#define ANSI_GREEN   "\033[1;32m"
 

Functions

struct diag_enginediag_engine_new (const char *filename, const char *source, long source_len)
 Create a new diagnostic engine.
 
void diag_engine_free (struct diag_engine *engine)
 Free a diagnostic engine and all its entries.
 
void diag_emit (struct diag_engine *engine, enum diag_severity severity, int line, int col, const char *fmt,...)
 
void diag_print_all (struct diag_engine *engine, FILE *stream)
 Print all accumulated diagnostics to a stream. Uses ANSI colors if stream is a terminal.
 
int diag_has_errors (struct diag_engine *engine)
 Check if any errors were emitted.
 
int diag_error_count (struct diag_engine *engine)
 Get the number of errors emitted.
 

Detailed Description

Diagnostic engine implementation.

Function Documentation

◆ diag_engine_new()

struct diag_engine * diag_engine_new ( const char *  filename,
const char *  source,
long  source_len 
)

Create a new diagnostic engine.

Parameters
filenameSource filename (not owned, must outlive engine)
sourceSource content string (not owned)
source_lenLength of source content
Returns
Pointer to new engine, or NULL on allocation failure