Print this page
| Split |
Close |
| Expand all |
| Collapse all |
--- old/parse.h
+++ new/parse.h
1 1 /*
2 2 * Copyright (c) 2012-2020 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
3 3 *
4 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 5 * of this software and associated documentation files (the "Software"), to deal
6 6 * in the Software without restriction, including without limitation the rights
7 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 8 * copies of the Software, and to permit persons to whom the Software is
9 9 * furnished to do so, subject to the following conditions:
10 10 *
11 11 * The above copyright notice and this permission notice shall be included in
12 12 * all copies or substantial portions of the Software.
13 13 *
14 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 20 * SOFTWARE.
21 21 */
22 22
23 23 #ifndef __PARSE_H
24 24 #define __PARSE_H
25 25
26 26 #include <jeffpc/error.h>
27 27 #include <jeffpc/sexpr.h>
28 28
29 29 #include "req.h"
30 30 #include "post.h"
31 31
32 32 struct parser_output {
33 33 struct req *req;
34 34 struct post *post;
35 35
36 36 void *scanner;
37 37 char *output;
38 38 struct str *stroutput;
39 39 struct val *valoutput;
40 40
41 41 const char *input;
42 42 size_t len;
43 43 size_t pos;
44 44 int lineno;
45 45
46 46 /* template related */
47 47 bool cond_stack[COND_STACK_DEPTH];
48 48 int cond_stack_use;
49 49
50 50 /* fmt3 */
51 51 int table_nesting;
52 52 int texttt_nesting;
53 53
54 54 /* fmt3 special commands */
55 55 struct str *sc_title;
56 56 struct str *sc_pub;
57 57 struct val *sc_tags;
58 58 struct val *sc_cats;
59 59 struct str *sc_twitter_img;
60 60 };
61 61
62 62 extern int fmt3_lex_destroy(void *yyscanner);
63 63 extern int tmpl_lex_destroy(void *yyscanner);
64 64 extern int fmt3_parse(struct parser_output *data);
65 65 extern int tmpl_parse(struct parser_output *data);
66 66 extern void fmt3_set_extra(void *user_defined, void *yyscanner);
67 67 extern void tmpl_set_extra(void *user_defined, void *yyscanner);
68 68 extern int fmt3_lex_init(void **scanner);
69 69 extern int tmpl_lex_init(void **scanner);
70 70
71 71 static inline bool cond_value(struct parser_output *data)
72 72 {
73 73 int i;
74 74
75 75 for (i = 0; i <= data->cond_stack_use; i++)
76 76 if (!data->cond_stack[i])
77 77 return false;
78 78
79 79 return true;
80 80 }
81 81
82 82 static inline void cond_if(struct parser_output *data, bool val)
83 83 {
84 84 ASSERT3S(data->cond_stack_use, <, COND_STACK_DEPTH);
85 85
86 86 data->cond_stack[++data->cond_stack_use] = val;
87 87 }
88 88
89 89 static inline void cond_else(struct parser_output *data)
90 90 {
91 91 ASSERT3S(data->cond_stack_use, >=, 0);
92 92
|
↓ open down ↓ |
92 lines elided |
↑ open up ↑ |
93 93 data->cond_stack[data->cond_stack_use] = !data->cond_stack[data->cond_stack_use];
94 94 }
95 95
96 96 static inline void cond_endif(struct parser_output *data)
97 97 {
98 98 ASSERT3S(data->cond_stack_use, >=, 0);
99 99
100 100 data->cond_stack_use--;
101 101 }
102 102
103 +/*
104 + * Format "4" (markdown) entry point:
105 + */
106 +extern struct str *fmt4_md_to_html(struct str *);
103 107 #endif
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX