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