Top   Types   Functions   Classes   Index   Sources 

include/error/style.h


  1  /*-*- Mode: C -*-*/
  2  
  3  #ifndef HT_ERROR_STYLE_H
  4  #define HT_ERROR_STYLE_H
  5  
  6  #ifdef __cplusplus
  7  extern "C" {
  8  #endif
  9  
 10  /* Error styles */
 11  
 12  /* Printing an error works in two steps:
 13   *    a) Formatting
 14   *    b) Post-formatting (modification of line breaks, etc).
 15   *
 16   * Formatting:
 17   *    Prints an indentation toggle, a file, a line, a program name, a PID,
 18   *    a tag, a number, and a formatted message text into a string.
 19   *
 20   * Post-formatting:
 21   *    Converts a string into a string.  Usually this operation is empty,
 22   *    but may be used to change line breaks, etc.
 23   *
 24   */
 25  
 26  struct err_style_t {
 27       char const *name;
 28       void (*format) (
 29            err_formatted_stream_t * /*stream*/,
 30            err_v_char_t * /*target*/,
 31            int            /*tag*/,
 32            int            /*orig_tag*/,
 33            int            /*orig_num*/,
 34            err_msg_info_t /*info*/,
 35            err_location_t const * /*loc*/,
 36            char const *   /*progname*/,
 37            char const *   /*hostname*/,
 38            int            /*pid*/,
 39            char const *   /*text*/);
 40         /*
 41          * +-------------+--------------------------------------------------+
 42          * | stream      | stream to format for.  may be NULL if no stream  |
 43  	    * |             | is available.   Use this only for investigating  |
 44  	    * |             | the stream, but not to print into it!            |
 45          * +-------------+--------------------------------------------------+
 46  	    * | target      | destination of printing                          |
 47          * +-------------+--------------------------------------------------+
 48  	    * | tag         | the tag that resulted in this message (possibly  |
 49  	    * |             | C_TAG_MORE)                                      |
 50          * +-------------+--------------------------------------------------+
 51  	    * | orig_tag    | never == C_TAG_MORE.  If tag == C_TAG_MORE, this |
 52  	    * |             | will be the original tag that preceeded the      |
 53  	    * |             | C_TAG_MORE message.                              |
 54          * +-------------+--------------------------------------------------+
 55  	    * | orig_num    | the original number, even if tag == C_TAG_MORE   |
 56          * +-------------+--------------------------------------------------+
 57  	    * | info        | more information about the message (e.g. time)   |
 58          * +-------------+--------------------------------------------------+
 59  	    * | loc         | where the error occurred                         |
 60          * +-------------+--------------------------------------------------+
 61  	    * | progname    | may be NULL                                      |
 62          * +-------------+--------------------------------------------------+
 63  	    * | hostname    | hostname (only valid for Unix, otherwise NULL)   |
 64          * +-------------+--------------------------------------------------+
 65  	    * | pid         | only valid for Unix,                             |
 66  	    * |             | also invalid if progname == NULL                 |
 67          * +-------------+--------------------------------------------------+
 68  	    * | text        | the text to be formatted                         |
 69          * +-------------+--------------------------------------------------+
 70          */
 71  
 72       err_v_char_t *(*post_format) (
 73           err_formatted_stream_t *, int /*tag*/, int /*orig_tag*/, err_v_char_t const *);
 74           /* May modify a given string just be before finalisation.
 75            *
 76            * This may return NULL if the given string is not modified. */
 77  };
 78  
 79  /* ********************************************************************** */
 80  /* Style that prints nothing: */
 81  
 82  extern err_style_t const err_style_none_s;
 83  #define err_style_none (&err_style_none_s)
 84  
 85  extern void err_style_none_format (
 86      err_formatted_stream_t *,
 87      err_v_char_t *,
 88      int, int, int,
 89      err_msg_info_t,
 90      err_location_t const *,
 91      char const *, char const *, int,
 92      char const *);
 93  
 94  extern err_v_char_t *err_style_none_post_format (
 95      err_formatted_stream_t *, int, int, err_v_char_t const *);
 96  
 97  /* ********************************************************************** */
 98  /* Style that simply prints the text: */
 99  
100  extern err_style_t const err_style_simple_s;
101  #define err_style_simple (&err_style_simple_s)
102  
103  extern void err_style_simple_format (
104      err_formatted_stream_t *,
105      err_v_char_t *,
106      int, int, int,
107      err_msg_info_t,
108      err_location_t const *,
109      char const *, char const *, int,
110      char const *);
111  
112  extern err_v_char_t *err_style_simple_post_format (
113      err_formatted_stream_t *, int, int, err_v_char_t const *);
114  
115  /* ********************************************************************** */
116  /* Default style: */
117  
118  #define ERR_STYLE_DEFAULT 9999
119  #define ERR_STYLE_NONE    0
120  #define ERR_STYLE_SIMPLE  10
121  #define ERR_STYLE_PLAIN   20
122  #define ERR_STYLE_COLON   21
123  #define ERR_STYLE_QUOTES  22
124  #define ERR_STYLE_QT      30
125  #define ERR_STYLE_QT3     40
126  
127  extern int err_style_default_redirect;  /* = ERR_STYLE_PLAIN */
128  
129  extern err_style_t const err_style_default_s;
130  #define err_style_default (&err_style_default_s)
131    /* Note that for both err plain and qit style, plain style formatting
132     * is used.  Only the markup is different.  Therefore, you can change
133     * the style by using the err_style_plain_redirect variable. */
134  
135  extern void err_style_default_format (
136      err_formatted_stream_t *,
137      err_v_char_t *,
138      int, int, int,
139      err_msg_info_t,
140      err_location_t const *,
141      char const *, char const *, int,
142      char const *);
143  
144  extern err_v_char_t *err_style_default_post_format (
145      err_formatted_stream_t *, int, int, err_v_char_t const *);
146  
147  /* ********************************************************************** */
148  /* Structures for general markup: */
149  
150  #define ERR_MSG_COLOR_PREFIX    1
151  #define ERR_MSG_COLOR_SUFFIX    2
152  
153  #define ERR_MSG_PART_MIN        8 /* smallest number of real part */
154  #define ERR_MSG_PART_LOC        8
155  #define ERR_MSG_PART_PROGNAME   9
156  #define ERR_MSG_PART_TAG       10
157  #define ERR_MSG_PART_ADDRESS   11
158  #define ERR_MSG_PART_BODY      12
159  #define ERR_MSG_PART_TIME      13
160  #define ERR_MSG_PART_SPACE     15
161  #define ERR_MSG_PART_MAX       15 /* largest number of real part */
162  
163  #define ERR_MSG_COLOR_OFF      16
164     /* _OFF must be a free bit to be combinable with the rest.
165      * (We have 9 bits in total, so values my be 0..511.)
166      */
167  
168  struct err_markup_t {
169       int open_part;
170       int open_tag;
171  
172       char const *(*color) (
173            struct err_markup_t *,
174            int /*part*/,
175            int /*tag*/,
176            ERR_ERWIN_BOOL /*on*/);
177         /* part may have values of the ERR_MSG_* enum. */
178  
179       void (*begin_part) (
180            struct err_markup_t *,
181            err_formatted_stream_t * /*stream*/,
182            err_v_char_t * /*msg*/,
183            int /*part*/,
184            int /*orig_tag*/);
185  };
186  
187  typedef struct err_markup_t ErrMarkup;
188  #ifndef __cplusplus
189  typedef struct err_markup_t err_markup_t;
190  #endif
191  
192  extern void err_begin_part  (
193     err_markup_t *, err_formatted_stream_t *, err_v_char_t *, int part, int tag);
194  extern void err_open_markup (err_markup_t *, err_v_char_t *, int, int);
195  extern void err_end_part    (err_markup_t *, err_v_char_t *);
196  
197  extern err_markup_t *err_markup_none;
198  
199  extern char const *err_markup_none_color (err_markup_t *, int, int, ERR_ERWIN_BOOL);
200  
201  extern void err_markup_none_begin_part (
202      err_markup_t *,
203      err_formatted_stream_t *,
204      err_v_char_t *,
205      int,
206      int);
207  
208  /* ********************************************************************** */
209  
210  extern err_style_t const *err_style_from_int (int);
211     /* gets a style from a ERR_STYLE_DEFAULT constant */
212  
213  extern int err_style_from_string_to_int (char const *);
214  extern err_style_t const * err_style_from_string (char const *);
215  
216  /* extern void err_register_feature (err_init_t); */
217  
218  /* ********************************************************************** */
219  
220  extern int err_position_pieces (err_position_t const *);
221      /* Returns the number of valid pieces of the error position.  In detail:
222       *
223       * returns 0 if file is == NULL
224       * otherwise
225       * returns 1 if line is <= 0
226       * otherwise
227       * returns 2 if pos is <= 0
228       * otherwise
229       * returns 3.
230       */
231  
232  extern char const *err_tag_string (int /*tag*/);
233      /* Returns a string that describes a given color tag.  E.g. "Error" for
234       * C_TAG_ERROR.
235       * It returns NULL, if no tag is to be written */
236  
237  extern char const *err_tag_description (
238      ERR_BOOL * /*initial_vowel*/, int /*tag*/, ERR_BOOL /*plural*/);
239      /* Returns a description of a tag, e.g. "assertion" for C_TAG_ASSERTION.
240       * It can also return the plural form.
241       *
242       * This never returns NULL.
243       */
244  
245  extern err_symbol_t err_tag_abbreviation (int /*tag*/);
246      /* Returns a symbol of a tag, e.g. "assertion" for C_TAG_ASSERTION.
247       * In contrast to err_tag_description, these are not for humans but
248       * for computers: a simple one word tag name.  No spaces, to bells or
249       * whistles.
250       *
251       * This never returns NULL.
252       */
253  
254  /* The following variables controls how line breaks are automatically
255   * inserted.  Styles may use them. */
256  #define ERR_STYLE_LINE_BREAK_NEVER           0
257  #define ERR_STYLE_LINE_BREAK_ALWAYS          1
258  #define ERR_STYLE_LINE_BREAK_TOO_LONG        2  /* >= 79 characters */
259  #define ERR_STYLE_LINE_BREAK_LOCATION_GIVEN  3  /* if a location is given */
260  
261  /* Possibly the style supports colors: */
262  #define ERR_STYLE_COLOR_NEVER   0
263  #define ERR_STYLE_COLOR_ALWAYS  1
264  #define ERR_STYLE_COLOR_IF_TTY  2
265  
266  /* Time style: */
267  #define ERR_STYLE_TIME_NEVER    0
268  #define ERR_STYLE_TIME_ALWAYS   1
269  #define ERR_STYLE_TIME_PROGRESS 2
270  
271  #ifdef __cplusplus
272  }
273  #endif
274  
275  #endif /* !defined HT_ERROR_STYLE_H */

Index

Stoppt die Vorratsdatenspeicherung
November 26th, 2007
Comments? Suggestions? Corrections? You can drop me a line.
zpentrabvagiktu@theiling.de
Schwerpunktpraxis