Commit from LuCI Translation Portal by user jow.: 850 of 850 messages translated...
[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 <unistd.h>
25 #include <fcntl.h>
26 #include <string.h>
27 #include <ctype.h>
28
29 #include <lua.h>
30 #include <lualib.h>
31 #include <lauxlib.h>
32
33
34 #define T_READBUFSZ 1024
35 #define T_OUTBUFSZ T_READBUFSZ * 3
36
37 /* parser states */
38 #define T_STATE_TEXT_INIT 0
39 #define T_STATE_TEXT_NEXT 1
40 #define T_STATE_CODE_INIT 2
41 #define T_STATE_CODE_NEXT 3
42 #define T_STATE_SKIP 4
43
44 /* parser flags */
45 #define T_FLAG_EOF 0x01
46 #define T_FLAG_SKIPWS 0x02
47
48 /* tokens used in matching and expression generation */
49 #define T_TOK_START "<%"
50 #define T_TOK_END "%>"
51 #define T_TOK_SKIPWS "-"
52
53 /* generator flags */
54 #define T_GEN_START 0x01
55 #define T_GEN_END 0x02
56
57 /* code types */
58 #define T_TYPE_TEXT 0
59 #define T_TYPE_COMMENT 1
60 #define T_TYPE_EXPR 2
61 #define T_TYPE_INCLUDE 3
62 #define T_TYPE_I18N 4
63 #define T_TYPE_I18N_RAW 5
64 #define T_TYPE_CODE 6
65
66 /* parser state */
67 struct template_parser {
68 int fd;
69 int bufsize;
70 int outsize;
71 int state;
72 int flags;
73 int type;
74 char buf[T_READBUFSZ];
75 char out[T_OUTBUFSZ];
76 };
77
78
79 const char *template_reader(lua_State *L, void *ud, size_t *sz);
80
81 #endif