Permalink
Fetching contributors…
Cannot retrieve contributors at this time
94 lines (65 sloc) 3.45 KB
#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