4 #ifndef OHCOUNT_PARSER_MACROS_H
5 #define OHCOUNT_PARSER_MACROS_H
72 if (!item) printf(
"Failed to allocate memory for enqueued callback.\n");
81 if (!callback_list_head) {
82 callback_list_head = item;
83 callback_list_tail = item;
85 callback_list_tail->
next = item;
86 callback_list_tail = item;
98 callback_list_head = NULL;
99 callback_list_tail = NULL;
109 line_start = last_line_start; \
110 line_contains_code = last_line_contains_code; \
111 whole_line_comment = last_whole_line_comment; \
120 if (inqueue) { dequeue; } \
121 if (!line_start) line_start = ts; \
131 if (inqueue) { dequeue; } \
132 if (!line_contains_code && !line_start) line_start = ts; \
133 line_contains_code = 1; \
142 if (inqueue) { dequeue; } \
143 if (!line_contains_code) { \
144 whole_line_comment = 1; \
145 if (!line_start) line_start = ts; \
157 #define saw(lang) { \
159 whole_line_comment = 0; \
160 line_contains_code = 0; \
169 #define std_internal_newline(lang) { \
170 if (callback && p > line_start) { \
171 if (line_contains_code) { \
173 enqueue(lang, "lcode", cint(line_start), cint(p), userdata); \
175 callback(lang, "lcode", cint(line_start), cint(p), userdata); \
176 } else if (whole_line_comment) { \
178 enqueue(lang, "lcomment", cint(line_start), cint(p), userdata); \
180 callback(lang, "lcomment", cint(line_start), cint(p), userdata); \
183 enqueue(lang, "lblank", cint(line_start), cint(p), userdata); \
185 callback(lang, "lblank", cint(line_start), cint(p), userdata); \
188 whole_line_comment = 0; \
189 line_contains_code = 0; \
201 #define emb_internal_newline(lang) { \
202 if (seen && seen != lang) \
203 std_internal_newline(seen) \
205 std_internal_newline(lang) \
215 #define std_newline(lang) {\
216 if (inqueue) { dequeue; } \
217 if (callback && te > line_start) { \
218 if (line_contains_code) \
219 callback(lang, "lcode", cint(line_start), cint(te), userdata); \
220 else if (whole_line_comment) \
221 callback(lang, "lcomment", cint(line_start), cint(te), userdata); \
223 callback(lang, "lblank", cint(ts), cint(te), userdata); \
225 whole_line_comment = 0; \
226 line_contains_code = 0; \
238 #define emb_newline(lang) { \
239 if (seen && seen != lang) \
253 #define process_last_line(lang) {\
254 if ((whole_line_comment || line_contains_code) && callback) { \
255 if (line_contains_code) \
256 callback(lang, "lcode", cint(line_start), cint(pe), userdata); \
257 else if (whole_line_comment) \
258 callback(lang, "lcomment", cint(line_start), cint(pe), userdata); \
272 while (*pos !=
'\n' && *pos !=
'\r' && *pos !=
'\f') {
273 if (*pos !=
'\t' && *pos !=
' ')
return 0;
276 if (*pos ==
'\r' && *(pos+1) ==
'\n') pos++;
291 #define check_blank_entry(lang) { \
292 if (is_blank_entry(&p)) { \
312 #define INTERNAL_NL -2
321 #define CHECK_BLANK_ENTRY -3
359 #define cint(c) ((int) (c - buffer_start))
419 pe = buffer + length; \
422 buffer_start = buffer; \
423 whole_line_comment = 0; \
424 line_contains_code = 0; \