X-Git-Url: https://git.archive.openwrt.org/?p=project%2Fluci.git;a=blobdiff_plain;f=libs%2Fweb%2Fsrc%2Ftemplate_parser.h;fp=libs%2Fweb%2Fsrc%2Ftemplate_parser.h;h=42ebdff69dc19019834dc7ea0091aedc405e8e50;hp=0000000000000000000000000000000000000000;hb=80a2dd2cc27e2fc0c55f03f01a1d460a91954ab6;hpb=9cf0abcb073454cc405a4757b04446dcdc98d399 diff --git a/libs/web/src/template_parser.h b/libs/web/src/template_parser.h new file mode 100644 index 000000000..42ebdff69 --- /dev/null +++ b/libs/web/src/template_parser.h @@ -0,0 +1,81 @@ +/* + * LuCI Template - Parser header + * + * Copyright (C) 2009 Jo-Philipp Wich + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _TEMPLATE_PARSER_H_ +#define _TEMPLATE_PARSER_H_ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + + +#define T_READBUFSZ 1024 +#define T_OUTBUFSZ T_READBUFSZ * 3 + +/* parser states */ +#define T_STATE_TEXT_INIT 0 +#define T_STATE_TEXT_NEXT 1 +#define T_STATE_CODE_INIT 2 +#define T_STATE_CODE_NEXT 3 +#define T_STATE_SKIP 4 + +/* parser flags */ +#define T_FLAG_EOF 0x01 +#define T_FLAG_SKIPWS 0x02 + +/* tokens used in matching and expression generation */ +#define T_TOK_START "<%" +#define T_TOK_END "%>" +#define T_TOK_SKIPWS "-" +#define T_TOK_I18NSEP "\", \"" + +/* generator flags */ +#define T_GEN_START 0x01 +#define T_GEN_END 0x02 + +/* code types */ +#define T_TYPE_TEXT 0 +#define T_TYPE_COMMENT 1 +#define T_TYPE_EXPR 2 +#define T_TYPE_INCLUDE 3 +#define T_TYPE_I18N 4 +#define T_TYPE_CODE 5 + +/* parser state */ +struct template_parser { + int fd; + int bufsize; + int outsize; + int state; + int flags; + int type; + char buf[T_READBUFSZ]; + char out[T_OUTBUFSZ]; +}; + + +const char *template_reader(lua_State *L, void *ud, size_t *sz); + +#endif