]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/lib/lex.h
ebl add sql_escape to catalog messages
[bacula/bacula] / bacula / src / lib / lex.h
1 /*
2  *   lex.h
3  *
4  *    Lexical scanning of configuration files, used by parsers.
5  *
6  *   Kern Sibbald, MM
7  *
8  *   Version $Id$
9  *
10  */
11 /*
12    Copyright (C) 2000-2006 Kern Sibbald
13
14    This program is free software; you can redistribute it and/or
15    modify it under the terms of the GNU General Public License
16    version 2 as amended with additional clauses defined in the
17    file LICENSE in the main source directory.
18
19    This program is distributed in the hope that it will be useful,
20    but WITHOUT ANY WARRANTY; without even the implied warranty of
21    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
22    the file LICENSE for additional details.
23
24  */
25
26 #ifndef _LEX_H
27 #define _LEX_H
28
29 /* Lex get_char() return values */
30 #define L_EOF                         (-1)
31 #define L_EOL                         (-2)
32
33 /* Internal tokens */
34 #define T_NONE                        100
35
36 /* Tokens returned by get_token() */
37 #define T_EOF                         101
38 #define T_NUMBER                      102
39 #define T_IPADDR                      103
40 #define T_IDENTIFIER                  104
41 #define T_UNQUOTED_STRING             105
42 #define T_QUOTED_STRING               106
43 #define T_BOB                         108  /* begin block */
44 #define T_EOB                         109  /* end of block */
45 #define T_EQUALS                      110
46 #define T_COMMA                       111
47 #define T_EOL                         112
48 #define T_ERROR                       200
49 #define T_UNICODE_MARK                201
50
51 /*
52  * The following will be returned only if
53  * the appropriate expect flag has been set
54  */
55 #define T_SKIP_EOL                    113  /* scan through EOLs */
56 #define T_PINT32                      114  /* positive integer */
57 #define T_PINT32_RANGE                115  /* positive integer range */
58 #define T_INT32                       116  /* integer */
59 #define T_INT64                       117  /* 64 bit integer */
60 #define T_NAME                        118  /* name max 128 chars */
61 #define T_STRING                      119  /* string */
62
63 #define T_ALL                           0  /* no expectations */
64
65 /* Lexical state */
66 enum lex_state {
67    lex_none,
68    lex_comment,
69    lex_number,
70    lex_ip_addr,
71    lex_identifier,
72    lex_string,
73    lex_quoted_string,
74    lex_include,
75    lex_unicode_mark
76 };
77
78 /* Lex scan options */
79 #define LOPT_NO_IDENT            0x1  /* No Identifiers -- use string */
80 #define LOPT_STRING              0x2  /* Force scan for string */
81
82 /* Lexical context */
83 typedef struct s_lex_context {
84    struct s_lex_context *next;        /* pointer to next lexical context */
85    int options;                       /* scan options */
86    char *fname;                       /* filename */
87    FILE *fd;                          /* file descriptor */
88    char line[MAXSTRING];              /* input line */
89    char str[MAXSTRING];               /* string being scanned */
90    int str_len;                       /* length of string */
91    int line_no;                       /* file line number */
92    int col_no;                        /* char position on line */
93    int begin_line_no;                 /* line no of beginning of string */
94    enum lex_state state;              /* lex_state variable */
95    int ch;                            /* last char/L_VAL returned by get_char */
96    int token;
97    uint32_t pint32_val;
98    uint32_t pint32_val2;
99    int32_t int32_val;
100    int64_t int64_val;
101    void (*scan_error)(const char *file, int line, struct s_lex_context *lc, const char *msg, ...);
102    int err_type;                      /* message level for scan_error (M_..) */
103    void *caller_ctx;                  /* caller private data */
104 } LEX;
105
106 typedef void (LEX_ERROR_HANDLER)(const char *file, int line, LEX *lc, const char *msg, ...);
107
108 /* Lexical scanning errors in parsing conf files */
109 #define scan_err0(lc, msg) lc->scan_error(__FILE__, __LINE__, lc, msg)
110 #define scan_err1(lc, msg, a1) lc->scan_error(__FILE__, __LINE__, lc, msg, a1)
111 #define scan_err2(lc, msg, a1, a2) lc->scan_error(__FILE__, __LINE__, lc, msg, a1, a2)
112 #define scan_err3(lc, msg, a1, a2, a3) lc->scan_error(__FILE__, __LINE__, lc, msg, a1, a2, a3)
113 #define scan_err4(lc, msg, a1, a2, a3, a4) lc->scan_error(__FILE__, __LINE__, lc, msg, a1, a2, a3, a4)
114 #define scan_err5(lc, msg, a1, a2, a3, a4, a5) lc->scan_error(__FILE__, __LINE__, lc, msg, a1, a2, a3, a4, a5)
115 #define scan_err6(lc, msg, a1, a2, a3, a4, a5, a6) lc->scan_error(__FILE__, __LINE__, lc, msg, a1, a2, a3, a4, a5, a6)
116
117 void scan_to_eol(LEX *lc);
118 int scan_to_next_not_eol(LEX * lc);
119
120 #endif /* _LEX_H */