luci-0.11: merge outstanding trunk changes
[project/luci.git] / libs / web / src / template_parser.h
1 /*
2 * LuCI Template - Parser header
3 *
4 * Copyright (C) 2009 Jo-Philipp Wich <xm@subsignal.org>
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19 #ifndef _TEMPLATE_PARSER_H_
20 #define _TEMPLATE_PARSER_H_
21
22 #include <stdlib.h>
23 #include <stdio.h>
24 #include <stdint.h>
25 #include <unistd.h>
26 #include <fcntl.h>
27 #include <sys/stat.h>
28 #include <sys/mman.h>
29 #include <string.h>
30 #include <ctype.h>
31 #include <errno.h>
32
33 #include <lua.h>
34 #include <lualib.h>
35 #include <lauxlib.h>
36
37
38 /* code types */
39 #define T_TYPE_INIT 0
40 #define T_TYPE_TEXT 1
41 #define T_TYPE_COMMENT 2
42 #define T_TYPE_EXPR 3
43 #define T_TYPE_INCLUDE 4
44 #define T_TYPE_I18N 5
45 #define T_TYPE_I18N_RAW 6
46 #define T_TYPE_CODE 7
47 #define T_TYPE_EOF 8
48
49
50 struct template_chunk {
51 const char *s;
52 const char *e;
53 int type;
54 int line;
55 };
56
57 /* parser state */
58 struct template_parser {
59 int fd;
60 uint32_t size;
61 char *mmap;
62 char *off;
63 char *gc;
64 int line;
65 int in_expr;
66 int strip_before;
67 int strip_after;
68 struct template_chunk prv_chunk;
69 struct template_chunk cur_chunk;
70 const char *file;
71 };
72
73 struct template_parser * template_open(const char *file);
74 void template_close(struct template_parser *parser);
75
76 const char *template_reader(lua_State *L, void *ud, size_t *sz);
77 int template_error(lua_State *L, struct template_parser *parser);
78
79 #endif