]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/lib/lex.h
Basic Restore bootstrap implemented -- kes25Jun02
[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, 2001, 2002 Kern Sibbald and John Walker
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 as
16    published by the Free Software Foundation; either version 2 of
17    the License, or (at your option) any later version.
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 GNU
22    General Public License for more details.
23
24    You should have received a copy of the GNU General Public
25    License along with this program; if not, write to the Free
26    Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
27    MA 02111-1307, USA.
28
29  */
30
31 #ifndef _LEX_H
32 #define _LEX_H
33
34 /* Lex get_char() return values */
35 #define L_EOF                         (-1)
36 #define L_EOL                         (-2)
37
38 /* Internal tokens */
39 #define T_NONE                        100                              
40
41 /* Tokens returned by get_token() */
42 #define T_EOF                         101
43 #define T_NUMBER                      102
44 #define T_IPADDR                      103
45 #define T_IDENTIFIER                  104
46 #define T_UNQUOTED_STRING             105
47 #define T_QUOTED_STRING               106
48 #define T_BOB                         108  /* begin block */
49 #define T_EOB                         109  /* end of block */
50 #define T_EQUALS                      110
51 #define T_COMMA                       111
52 #define T_EOL                         112
53 #define T_SEMI                        113
54 #define T_ERROR                       200
55 /*
56  * The following will be returned only if
57  * the appropriate expect flag has been set   
58  */
59 #define T_PINT32                      114  /* positive integer */
60 #define T_PINT32_RANGE                115  /* positive integer range */
61 #define T_INT32                       116  /* integer */
62 #define T_INT64                       117  /* 64 bit integer */
63 #define T_NAME                        118  /* name max 128 chars */
64 #define T_STRING                      119  /* string */
65
66 #define T_ALL                           0  /* no expectations */
67
68 /* Lexical state */
69 enum lex_state {
70    lex_none,
71    lex_comment,
72    lex_number,
73    lex_ip_addr,
74    lex_identifier,
75    lex_string,
76    lex_quoted_string,
77    lex_include
78 };
79
80 /* Lex scan options */
81 #define LOPT_NO_IDENT            0x1  /* No Identifiers -- use string */
82
83 /* Lexical context */
84 typedef struct s_lex_context {
85    struct s_lex_context *next;        /* pointer to next lexical context */
86    int options;                       /* scan options */
87    char *fname;                       /* filename */
88    FILE *fd;                          /* file descriptor */
89    char line[MAXSTRING];              /* input line */
90    char str[MAXSTRING];               /* string being scanned */
91    int str_len;                       /* length of string */
92    int line_no;                       /* file line number */
93    int col_no;                        /* char position on line */
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)(char *file, int line, struct s_lex_context *lc, char *msg, ...);
102 } LEX;
103
104 typedef void (LEX_ERROR_HANDLER)(char *file, int line, LEX *lc, char *msg, ...);
105
106 /* Lexical scanning errors in parsing conf files */
107 #define scan_err0(lc, msg) lc->scan_error(__FILE__, __LINE__, lc, msg)
108 #define scan_err1(lc, msg, a1) lc->scan_error(__FILE__, __LINE__, lc, msg, a1)
109 #define scan_err2(lc, msg, a1, a2) lc->scan_error(__FILE__, __LINE__, lc, msg, a1, a2)
110 #define scan_err3(lc, msg, a1, a2, a3) lc->scan_error(__FILE__, __LINE__, lc, msg, a1, a2, a3)
111 #define scan_err4(lc, msg, a1, a2, a3, a4) lc->scan_error(__FILE__, __LINE__, lc, msg, a1, a2, a3, a4)
112 #define scan_err5(lc, msg, a1, a2, a3, a4, a5) lc->scan_error(__FILE__, __LINE__, lc, msg, a1, a2, a3, a4, a5)
113 #define scan_err6(lc, msg, a1, a2, a3, a4, a5, a6) lc->scan_error(__FILE__, __LINE__, lc, msg, a1, a2, a3, a4, a5, a6)
114
115 void scan_to_eol(LEX *lc);
116
117 #endif /* _LEX_H */