template_parser.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * LuCI Template - Parser header
  3. *
  4. * Copyright (C) 2009 Jo-Philipp Wich <jow@openwrt.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. #ifndef _TEMPLATE_PARSER_H_
  19. #define _TEMPLATE_PARSER_H_
  20. #include <stdlib.h>
  21. #include <stdio.h>
  22. #include <stdint.h>
  23. #include <unistd.h>
  24. #include <fcntl.h>
  25. #include <sys/stat.h>
  26. #include <sys/mman.h>
  27. #include <string.h>
  28. #include <ctype.h>
  29. #include <errno.h>
  30. #include <lua.h>
  31. #include <lualib.h>
  32. #include <lauxlib.h>
  33. /* code types */
  34. #define T_TYPE_INIT 0
  35. #define T_TYPE_TEXT 1
  36. #define T_TYPE_COMMENT 2
  37. #define T_TYPE_EXPR 3
  38. #define T_TYPE_INCLUDE 4
  39. #define T_TYPE_I18N 5
  40. #define T_TYPE_I18N_RAW 6
  41. #define T_TYPE_CODE 7
  42. #define T_TYPE_EOF 8
  43. struct template_chunk {
  44. const char *s;
  45. const char *e;
  46. int type;
  47. int line;
  48. };
  49. /* parser state */
  50. struct template_parser {
  51. int fd;
  52. uint32_t size;
  53. char *data;
  54. char *off;
  55. char *gc;
  56. int line;
  57. int in_expr;
  58. int strip_before;
  59. int strip_after;
  60. struct template_chunk prv_chunk;
  61. struct template_chunk cur_chunk;
  62. const char *file;
  63. };
  64. struct template_parser * template_open(const char *file);
  65. struct template_parser * template_string(const char *str, uint32_t len);
  66. void template_close(struct template_parser *parser);
  67. const char *template_reader(lua_State *L, void *ud, size_t *sz);
  68. int template_error(lua_State *L, struct template_parser *parser);
  69. #endif