texerrors.h /size: 4409 b    last modification: 2024-01-16 10:22
1/*
2    See license.txt in the root of this project.
3*/
4
5# ifndef LMT_ERRORS_H
6# define LMT_ERRORS_H
7
8/*tex
9
10    The global variable |interaction| has four settings, representing increasing amounts of user
11    interaction:
12
13*/
14
15# define print_buffer_size 512 /*tex Watch out for alignment! Only used here. */
16
17typedef enum interaction_levels {
18    batch_mode,      /*tex omits all stops and omits terminal output */
19    nonstop_mode,    /*tex omits all stops */
20    scroll_mode,     /*tex omits error stops */
21    error_stop_mode, /*tex stops at every opportunity to interact */
22} interaction_levels;
23
24# define last_interaction_level error_stop_mode
25
26typedef struct error_state_info {
27    char        *last_error;
28    char        *last_lua_error;
29    char        *last_warning_tag;
30    char        *last_warning;
31    char        *last_error_context;
32    char        *help_text;         /*tex helps for the next |error| */
33 /* char         print_buffer[print_buffer_size]; */
34    int          intercept;         /*tex intercept error state */
35    int          last_intercept;    /*tex error state number / dimen scanner */
36    int          interaction;       /*tex current level of interaction */
37    int          default_exit_code; /*tex the exit code can be overloaded */
38    int          set_box_allowed;
39    int          history;
40    int          error_count;
41    int          saved_selector;
42    int          in_error;
43    int          long_help_seen;
44    int          context_indent;
45    int          padding;
46    limits_data  line_limits;       /*tex these might go some day */
47    limits_data  half_line_limits;  /*tex these might go some day */
48} error_state_info;
49
50extern error_state_info lmt_error_state;
51
52typedef enum error_states {
53    spotless,             /*tex |history| value when nothing has been amiss yet */
54    warning_issued,       /*tex |history| value when |begin_diagnostic| has been called */
55    error_message_issued, /*tex |history| value when |error| has been called */
56    fatal_error_stop,     /*tex |history| value when termination was premature */
57} error_states;
58
59extern void tex_initialize_errors (void);
60extern void tex_fixup_selector    (int log_opened);
61extern void tex_fatal_error       (const char *helpinfo);
62extern void tex_overflow_error    (const char *s, int n);
63extern int  tex_confusion         (const char *s);
64extern int  tex_normal_error      (const char *t, const char *p);
65extern void tex_normal_warning    (const char *t, const char *p);
66extern int  tex_formatted_error   (const char *t, const char *fmt, ...);
67extern void tex_formatted_warning (const char *t, const char *fmt, ...);
68extern void tex_emergency_message (const char *t, const char *fmt, ...);
69extern int  tex_emergency_exit    (void);
70extern int  tex_normal_exit       (void);
71
72/*tex A bit more detail. */
73
74# define error_string_clobbered(n)   "[clobbered "   LMT_TOSTRING(n) "]"
75# define error_string_bad(n)         "[bad "         LMT_TOSTRING(n) "]"
76# define error_string_impossible(n)  "[impossible "  LMT_TOSTRING(n) "]"
77# define error_string_nonexistent(n) "[nonexistent " LMT_TOSTRING(n) "]"
78
79/*tex
80*
81    We now have a template based error handler instead of more dan a dozen specific ones that took
82    an error type, a different set of variables, and the helptext. The template uses the (usual)
83    percent driven directives:
84
85    \starttabulate
86    \NC \type {s} \NC string \NC \NR
87    \NC \type {c} \NC char \NC \NR
88    \NC \type {q} \NC 'string' \NC \NR
89    \NC \type {i} \NC integer \NC \NR
90    \NC \type {e} \NC escape char \NC \NR
91    \NC \type {C} \NC cmd chr \NC \NR
92    \NC \type {E} \NC escaped string \NC \NR
93    \NC \type {S} \NC cs \NC \NR
94    \NC \type {T} \NC texstring \NC \NR
95    \stoptabulate
96
97    A placeholder starts with a percent sign. A double percent sign will print one. The last very
98    argument is the error message (or |NULL|). We flush on a per character basis but that happens
99    anyway and error messages are not really a bottleneck.
100
101 */
102
103typedef enum error_types {
104    normal_error_type,
105    back_error_type,
106    insert_error_type,
107    succumb_error_type, /* fatal error_type */
108    eof_error_type,
109    condition_error_type,
110    runaway_error_type,
111    warning_error_type,
112} error_types;
113
114extern void tex_handle_error              (error_types type, const char *format, ...);
115extern void tex_handle_error_message_only (const char *message);
116
117# endif
118