forked from jgm/peg-markdown
-
Notifications
You must be signed in to change notification settings - Fork 55
/
utility_functions.h
93 lines (65 loc) · 3.45 KB
/
utility_functions.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#ifndef UTILITY_FUNCTIONS_H
#define UTILITY_FUNCTIONS_H
#include <stdbool.h>
#include <glib.h>
#include "markdown_peg.h"
#include <time.h>
/* utility_functions.h - List manipulation functions, element
* constructors, and macro definitions for leg markdown parser. */
/* cons - cons an element onto a list, returning pointer to new head */
element * cons(element *new, element *list);
/* reverse - reverse a list, returning pointer to new list */
element *reverse(element *list);
/* concat_string_list - concatenates string contents of list of STR elements.
* Frees STR elements as they are added to the concatenation. */
GString *concat_string_list(element *list);
/**********************************************************************
Global variables used in parsing
***********************************************************************/
extern char *charbuf; /* Buffer of characters to be parsed. */
extern element *references; /* List of link references found. */
extern element *notes; /* List of footnotes found. */
extern element *parse_result; /* Results of parse. */
extern int syntax_extensions; /* Syntax extensions selected. */
extern element *labels; /* List of labels found in document. */
extern clock_t start_time; /* Used for ensuring we're not stuck in a loop */
extern bool parse_aborted; /* flag indicating we ran out of time */
/**********************************************************************
Auxiliary functions for parsing actions.
These make it easier to build up data structures (including lists)
in the parsing actions.
***********************************************************************/
/* mk_element - generic constructor for element */
element * mk_element(int key);
/* mk_str - constructor for STR element */
element * mk_str(char *string);
/* mk_str_from_list - makes STR element by concatenating a
* reversed list of strings, adding optional extra newline */
element * mk_str_from_list(element *list, bool extra_newline);
/* mk_list - makes new list with key 'key' and children the reverse of 'lst'.
* This is designed to be used with cons to build lists in a parser action.
* The reversing is necessary because cons adds to the head of a list. */
element * mk_list(int key, element *lst);
/* mk_link - constructor for LINK element */
element * mk_link(element *label, char *url, char *title, element *attr, char *id);
/* extension = returns true if extension is selected */
bool extension(int ext);
/* match_inlines - returns true if inline lists match (case-insensitive...) */
bool match_inlines(element *l1, element *l2);
/* find_reference - return true if link found in references matching label.
* 'link' is modified with the matching url and title. */
bool find_reference(link *result, element *label);
/* find_note - return true if note found in notes matching label.
if found, 'result' is set to point to matched note. */
bool find_note(element **result, char *label);
char *label_from_string(char *str, bool obfuscate);
void localize_typography(GString *out, int character, int language, int output);
void print_raw_element_list(GString *out, element *list);
void append_list(element *new, element *list);
bool find_label(link *result, element *label);
bool check_timeout();
void trim_trailing_whitespace(char *str);
char *label_from_element_list(element *list, bool obfuscate);
void print_raw_element_list(GString *out, element *list);
void print_raw_element(GString *out, element *elt);
#endif