]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/lib/lex.h
Make bfgets handle very long lines
[bacula/bacula] / bacula / src / lib / lex.h
1 /*
2    Bacula® - The Network Backup Solution
3
4    Copyright (C) 2000-2012 Free Software Foundation Europe e.V.
5
6    The main author of Bacula is Kern Sibbald, with contributions from
7    many others, a complete list can be found in the file AUTHORS.
8    This program is Free Software; you can redistribute it and/or
9    modify it under the terms of version three of the GNU Affero General Public
10    License as published by the Free Software Foundation and included
11    in the file LICENSE.
12
13    This program is distributed in the hope that it will be useful, but
14    WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16    General Public License for more details.
17
18    You should have received a copy of the GNU Affero General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21    02110-1301, USA.
22
23    Bacula® is a registered trademark of Kern Sibbald.
24    The licensor of Bacula is the Free Software Foundation Europe
25    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
26    Switzerland, email:ftf@fsfeurope.org.
27 */
28 /*
29  *   lex.h
30  *
31  *    Lexical scanning of configuration files, used by parsers.
32  *
33  *   Kern Sibbald, MM
34  *
35  */
36
37 #ifndef _LEX_H
38 #define _LEX_H
39
40 /* Lex get_char() return values */
41 #define L_EOF                         (-1)
42 #define L_EOL                         (-2)
43
44 /* Internal tokens */
45 #define T_NONE                        100
46
47 /* Tokens returned by get_token() */
48 #define T_EOF                         101
49 #define T_NUMBER                      102
50 #define T_IPADDR                      103
51 #define T_IDENTIFIER                  104
52 #define T_UNQUOTED_STRING             105
53 #define T_QUOTED_STRING               106
54 #define T_BOB                         108  /* begin block */
55 #define T_EOB                         109  /* end of block */
56 #define T_EQUALS                      110
57 #define T_COMMA                       111
58 #define T_EOL                         112
59 #define T_ERROR                       200
60 #define T_UTF8_BOM                    201 /* File starts with a UTF-8 BOM*/
61 #define T_UTF16_BOM                   202 /* File starts with a UTF-16LE BOM*/
62
63 /*
64  * The following will be returned only if
65  * the appropriate expect flag has been set
66  */
67 #define T_SKIP_EOL                    113  /* scan through EOLs */
68 #define T_PINT32                      114  /* positive integer */
69 #define T_PINT32_RANGE                115  /* positive integer range */
70 #define T_INT32                       116  /* integer */
71 #define T_INT64                       117  /* 64 bit integer */
72 #define T_NAME                        118  /* name max 128 chars */
73 #define T_STRING                      119  /* string */
74 #define T_PINT64_RANGE                120  /* positive integer range */
75 #define T_PINT64                      121  /* positive integer range */
76
77 #define T_ALL                           0  /* no expectations */
78
79 /* Lexical state */
80 enum lex_state {
81    lex_none,
82    lex_comment,
83    lex_number,
84    lex_ip_addr,
85    lex_identifier,
86    lex_string,
87    lex_quoted_string,
88    lex_include_quoted_string,
89    lex_include,
90    lex_utf8_bom,      /* we are parsing out a utf8 byte order mark */ 
91    lex_utf16_le_bom   /* we are parsing out a utf-16 (little endian) byte order mark */
92 };
93
94 /* Lex scan options */
95 #define LOPT_NO_IDENT            0x1  /* No Identifiers -- use string */
96 #define LOPT_STRING              0x2  /* Force scan for string */
97 #define LOPT_NO_EXTERN           0x4  /* Don't follow @ command */
98
99 class BPIPE;                          /* forward reference */
100   
101 /* Lexical context */
102 typedef struct s_lex_context {
103    struct s_lex_context *next;        /* pointer to next lexical context */
104    int options;                       /* scan options */
105    char *fname;                       /* filename */
106    FILE *fd;                          /* file descriptor */
107    POOLMEM *line;                     /* input line */
108    char str[MAXSTRING];               /* string being scanned */
109    int str_len;                       /* length of string */
110    int line_no;                       /* file line number */
111    int col_no;                        /* char position on line */
112    int begin_line_no;                 /* line no of beginning of string */
113    enum lex_state state;              /* lex_state variable */
114    int ch;                            /* last char/L_VAL returned by get_char */
115    int token;
116    uint32_t pint32_val;
117    uint32_t pint32_val2;
118    int32_t int32_val;
119    int64_t int64_val;
120    uint64_t pint64_val;
121    uint64_t pint64_val2;
122    void (*scan_error)(const char *file, int line, struct s_lex_context *lc, const char *msg, ...);
123    int err_type;                      /* message level for scan_error (M_..) */
124    void *caller_ctx;                  /* caller private data */
125    BPIPE *bpipe;                      /* set if we are piping */
126 } LEX;
127
128 typedef void (LEX_ERROR_HANDLER)(const char *file, int line, LEX *lc, const char *msg, ...);
129
130 /* Lexical scanning errors in parsing conf files */
131 #define scan_err0(lc, msg) lc->scan_error(__FILE__, __LINE__, lc, msg)
132 #define scan_err1(lc, msg, a1) lc->scan_error(__FILE__, __LINE__, lc, msg, a1)
133 #define scan_err2(lc, msg, a1, a2) lc->scan_error(__FILE__, __LINE__, lc, msg, a1, a2)
134 #define scan_err3(lc, msg, a1, a2, a3) lc->scan_error(__FILE__, __LINE__, lc, msg, a1, a2, a3)
135 #define scan_err4(lc, msg, a1, a2, a3, a4) lc->scan_error(__FILE__, __LINE__, lc, msg, a1, a2, a3, a4)
136 #define scan_err5(lc, msg, a1, a2, a3, a4, a5) lc->scan_error(__FILE__, __LINE__, lc, msg, a1, a2, a3, a4, a5)
137 #define scan_err6(lc, msg, a1, a2, a3, a4, a5, a6) lc->scan_error(__FILE__, __LINE__, lc, msg, a1, a2, a3, a4, a5, a6)
138
139 void scan_to_eol(LEX *lc);
140 int scan_to_next_not_eol(LEX * lc);
141
142 #endif /* _LEX_H */