gwion-util
utilities for the Gwion project
Loading...
Searching...
No Matches
Data Structures | Macros | Typedefs | Enumerations | Functions | Variables
prettyerr.h File Reference
#include <stddef.h>
#include <stdbool.h>
#include <stdio.h>

Go to the source code of this file.

Data Structures

struct  libprettyerr_str
 
struct  libprettyerr_pos
 
struct  libprettyerr_error
 
struct  libprettyerr_printer
 

Macros

#define PERR_Str(line_, start_)    (struct libprettyerr_str){ .line = line_, .start = start_ }
 
#define PERR_Str_None()    PERR_Str(0, NULL)
 
#define PERR_Pos(index_, length_)    (struct libprettyerr_pos){ .index = index_, .length = length_ }
 
#define PERR_Error(type_, primary_, error_position_, main_, explain_, error_code_, filename_)
 
#define PERR_Secondary(type_, primary_, error_position_, main_, filename_)
 
#define PRETTYERR_EXPORT
 

Typedefs

typedef void(* libprettyerr_runner_t) (const struct libprettyerr_printer *, const struct libprettyerr_error *)
 
typedef struct libprettyerr_error perr_t
 
typedef struct libprettyerr_printer perr_printer_t
 
typedef libprettyerr_runner_t perr_runner_t
 

Enumerations

enum  libprettyerr_errtype {
  PERR_SUCCESS , PERR_ERROR , PERR_WARNING , PERR_INFO ,
  PERR_HINT
}
 
enum  libprettyerr_boxtype {
  PERR_BOX_THICK_VERT , PERR_BOX_THIN_HIGH , PERR_BOX_THIN_UL , PERR_BOX_THIN_UL_ROUNDED ,
  PERR_BOX_THIN_HORIZ , PERR_BOX_THIN_BL , PERR_BOX_THIN_BL_ROUNDED , PERR_BOX_THIN_VERT ,
  PERR_BOX_MAX
}
 

Functions

PRETTYERR_EXPORT void perr_printer_init (struct libprettyerr_printer *printer, FILE *stream, const char *source, bool utf8, libprettyerr_runner_t style)
 
PRETTYERR_EXPORT void perr_print_error (const struct libprettyerr_printer *printer, const struct libprettyerr_error *err)
 
PRETTYERR_EXPORT void perr_print_line_number (const struct libprettyerr_printer *printer, const struct libprettyerr_error *err, const char *color)
 

Variables

PRETTYERR_EXPORT perr_runner_t perr_runner_basic_style
 
PRETTYERR_EXPORT perr_runner_t perr_runner_secondary_style
 

Macro Definition Documentation

◆ PERR_Error

#define PERR_Error ( type_,
primary_,
error_position_,
main_,
explain_,
error_code_,
filename_ )
Value:
(struct libprettyerr_error){ \
.type = type_, .primary = primary_, .error_position = error_position_, \
.main = main_, .explain = explain_, .error_code = error_code_, \
.filename = filename_ \
}

Definition at line 75 of file prettyerr.h.

75#define PERR_Error(type_, primary_, error_position_, main_, explain_, error_code_, filename_) \
76 (struct libprettyerr_error){ \
77 .type = type_, .primary = primary_, .error_position = error_position_, \
78 .main = main_, .explain = explain_, .error_code = error_code_, \
79 .filename = filename_ \
80 }

◆ PERR_Pos

#define PERR_Pos ( index_,
length_ )    (struct libprettyerr_pos){ .index = index_, .length = length_ }

Definition at line 39 of file prettyerr.h.

39#define PERR_Pos(index_, length_) \
40 (struct libprettyerr_pos){ .index = index_, .length = length_ }

◆ PERR_Secondary

#define PERR_Secondary ( type_,
primary_,
error_position_,
main_,
filename_ )
Value:
(struct libprettyerr_error){ \
.type = type_, .primary = primary_, .error_position = error_position_, \
.main = main_, .filename = filename_ \
}

Definition at line 82 of file prettyerr.h.

82#define PERR_Secondary(type_, primary_, error_position_, main_, filename_) \
83 (struct libprettyerr_error){ \
84 .type = type_, .primary = primary_, .error_position = error_position_, \
85 .main = main_, .filename = filename_ \
86 }

◆ PERR_Str

#define PERR_Str ( line_,
start_ )    (struct libprettyerr_str){ .line = line_, .start = start_ }

Definition at line 29 of file prettyerr.h.

29#define PERR_Str(line_, start_) \
30 (struct libprettyerr_str){ .line = line_, .start = start_ }

◆ PERR_Str_None

#define PERR_Str_None ( )     PERR_Str(0, NULL)

Definition at line 31 of file prettyerr.h.

31#define PERR_Str_None() \
32 PERR_Str(0, NULL)

◆ PRETTYERR_EXPORT

#define PRETTYERR_EXPORT

Definition at line 101 of file prettyerr.h.

Typedef Documentation

◆ libprettyerr_runner_t

typedef void(* libprettyerr_runner_t) (const struct libprettyerr_printer *, const struct libprettyerr_error *)

Definition at line 90 of file prettyerr.h.

◆ perr_printer_t

Definition at line 120 of file prettyerr.h.

◆ perr_runner_t

Definition at line 121 of file prettyerr.h.

◆ perr_t

typedef struct libprettyerr_error perr_t

Definition at line 119 of file prettyerr.h.

Enumeration Type Documentation

◆ libprettyerr_boxtype

Enumerator
PERR_BOX_THICK_VERT 
PERR_BOX_THIN_HIGH 
PERR_BOX_THIN_UL 
PERR_BOX_THIN_UL_ROUNDED 
PERR_BOX_THIN_HORIZ 
PERR_BOX_THIN_BL 
PERR_BOX_THIN_BL_ROUNDED 
PERR_BOX_THIN_VERT 
PERR_BOX_MAX 

Definition at line 50 of file prettyerr.h.

50 {
60};
@ PERR_BOX_THIN_VERT
Definition prettyerr.h:58
@ PERR_BOX_THIN_UL_ROUNDED
Definition prettyerr.h:54
@ PERR_BOX_THICK_VERT
Definition prettyerr.h:51
@ PERR_BOX_THIN_BL
Definition prettyerr.h:56
@ PERR_BOX_THIN_BL_ROUNDED
Definition prettyerr.h:57
@ PERR_BOX_MAX
Definition prettyerr.h:59
@ PERR_BOX_THIN_HIGH
Definition prettyerr.h:52
@ PERR_BOX_THIN_UL
Definition prettyerr.h:53
@ PERR_BOX_THIN_HORIZ
Definition prettyerr.h:55

◆ libprettyerr_errtype

Enumerator
PERR_SUCCESS 
PERR_ERROR 
PERR_WARNING 
PERR_INFO 
PERR_HINT 

Definition at line 42 of file prettyerr.h.

42 {
43 PERR_SUCCESS, // bold green
44 PERR_ERROR, // bold red
45 PERR_WARNING, // red
46 PERR_INFO, // bold white
47 PERR_HINT // bold yellow
48};
@ PERR_INFO
Definition prettyerr.h:46
@ PERR_SUCCESS
Definition prettyerr.h:43
@ PERR_HINT
Definition prettyerr.h:47
@ PERR_WARNING
Definition prettyerr.h:45
@ PERR_ERROR
Definition prettyerr.h:44

Function Documentation

◆ perr_print_error()

PRETTYERR_EXPORT void perr_print_error ( const struct libprettyerr_printer * printer,
const struct libprettyerr_error * err )

◆ perr_print_line_number()

PRETTYERR_EXPORT void perr_print_line_number ( const struct libprettyerr_printer * printer,
const struct libprettyerr_error * err,
const char * color )

◆ perr_printer_init()

PRETTYERR_EXPORT void perr_printer_init ( struct libprettyerr_printer * printer,
FILE * stream,
const char * source,
bool utf8,
libprettyerr_runner_t style )

Definition at line 42 of file prettyerr.c.

43 {
44 printer->source = source;
45 printer->stream = stream;
46
47// Enables ANSI colors only in Unix terminals. False by default on Windows.
48#if defined(__unix__) || defined(__unix) || \
49 (defined(__APPLE__) && defined(__MACH__))
50 const int fd = fileno(stream);
51 // if (fd < 0) {
52 // perror("fileno");
53 // }
54 printer->color = isatty(fd);
55#else
56 printer->color = false;
57#endif
58
59 if ((printer->utf8 = utf8)) {
61 } else {
63 }
64 printer->runner = style;
65}
static char const * _utf8_box_lookup[8]
Definition prettyerr.c:36
static char const * _ascii_box_lookup[8]
Definition prettyerr.c:34
const char ** box_lookup
Definition prettyerr.h:94
libprettyerr_runner_t runner
Definition prettyerr.h:95
const char * source
Definition prettyerr.h:92

Variable Documentation

◆ perr_runner_basic_style

PRETTYERR_EXPORT perr_runner_t perr_runner_basic_style
extern

Definition at line 245 of file prettyerr.c.

◆ perr_runner_secondary_style

PRETTYERR_EXPORT perr_runner_t perr_runner_secondary_style
extern

Definition at line 246 of file prettyerr.c.