Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Refactoring to build on windows

all .c files now build as separate files.
code has been refactored to not depend on inclusion of .c files
functions in utility_functions.c are now extern
removed strdup and strcasecmp prototypes, now use .h files
fixed inconsistent linkages in markdown_output.c
  • Loading branch information...
commit 9815dc4ffdbd873a13ce2ec84437cd7928afcd2d 1 parent fbb17d1
Matt Tyson authored jgm committed
View
4 Makefile
@@ -6,8 +6,8 @@ endif
export X
PROGRAM=markdown$(X)
-CFLAGS ?= -Wall -O3 -ansi
-OBJS=markdown_parser.o markdown_output.o markdown_lib.o
+CFLAGS ?= -Wall -O3 -ansi -D_GNU_SOURCE -flto
+OBJS=markdown_parser.o markdown_output.o markdown_lib.o utility_functions.o parsing_functions.o odf.o
PEGDIR=peg-0.1.9
LEG=$(PEGDIR)/leg$(X)
PKG_CONFIG = pkg-config
View
5 markdown_lib.h
@@ -1,3 +1,6 @@
+#ifndef MARKDOWN_LIB_H
+#define MARKDOWN_LIB_H
+
#include <stdlib.h>
#include <stdio.h>
#include <glib.h>
@@ -20,3 +23,5 @@ GString * markdown_to_g_string(char *text, int extensions, int output_format);
char * markdown_to_string(char *text, int extensions, int output_format);
/* vim: set ts=4 sw=4 : */
+#endif
+
View
8 markdown_output.c
@@ -22,7 +22,7 @@
#include <assert.h>
#include <glib.h>
#include "markdown_peg.h"
-#include "odf.c"
+#include "odf.h"
static int extensions;
static int odf_type = 0;
@@ -63,7 +63,7 @@ static void pad(GString *out, int num) {
}
/* determine whether a certain element is contained within a given list */
-bool list_contains_key(element *list, int key) {
+static bool list_contains_key(element *list, int key) {
element *step = NULL;
step = list;
@@ -865,7 +865,7 @@ static void print_odf_string(GString *out, char *str) {
}
/* print_odf_element_list - print an element list as ODF */
-void print_odf_element_list(GString *out, element *list) {
+static void print_odf_element_list(GString *out, element *list) {
while (list != NULL) {
print_odf_element(out, list);
list = list->next;
@@ -873,7 +873,7 @@ void print_odf_element_list(GString *out, element *list) {
}
/* print_odf_element - print an element as ODF */
-void print_odf_element(GString *out, element *elt) {
+static void print_odf_element(GString *out, element *elt) {
int lev;
int old_type = 0;
switch (elt->key) {
View
34 markdown_parser.leg
@@ -18,7 +18,38 @@
#include <stdbool.h>
#include <assert.h>
#include "markdown_peg.h"
-#include "utility_functions.c"
+#include "utility_functions.h"
+
+
+
+/**********************************************************************
+
+ Definitions for leg parser generator.
+ YY_INPUT is the function the parser calls to get new input.
+ We take all new input from (static) charbuf.
+
+ ***********************************************************************/
+
+
+
+# define YYSTYPE element *
+#ifdef __DEBUG__
+# define YY_DEBUG 1
+#endif
+
+#define YY_INPUT(buf, result, max_size) \
+{ \
+ int yyc; \
+ if (charbuf && *charbuf != '\0') { \
+ yyc= *charbuf++; \
+ } else { \
+ yyc= EOF; \
+ } \
+ result= (EOF == yyc) ? 0 : (*(buf)= yyc, 1); \
+}
+
+#define YY_RULE(T) T
+
/**********************************************************************
@@ -736,5 +767,4 @@ RawNoteBlock = a:StartList
%%
-#include "parsing_functions.c"
View
6 markdown_peg.h
@@ -1,9 +1,10 @@
/* markdown_peg.h */
+#ifndef MARKDOWN_PEG_H
+#define MARKDOWN_PEG_H
+
#include "markdown_lib.h"
#include <glib.h>
-extern char *strdup(const char *string);
-
/* Information (label, URL and title) for a link. */
struct Link {
struct Element *label;
@@ -68,3 +69,4 @@ void free_element_list(element * elt);
void free_element(element *elt);
void print_element_list(GString *out, element *elt, int format, int exts);
+#endif
View
2  odf.c
@@ -14,6 +14,8 @@
***********************************************************************/
+#include "odf.h"
+
void print_odf_header(GString *out){
View
8 odf.h
@@ -1,3 +1,11 @@
+#ifndef ODF_H
+#define ODF_H
+
#include <stdlib.h>
#include <stdio.h>
#include <glib.h>
+
+void print_odf_header(GString *out);
+void print_odf_footer(GString *out);
+#endif
+
View
15 parsing_functions.c
@@ -1,7 +1,20 @@
/* parsing_functions.c - Functions for parsing markdown and
* freeing element lists. */
-int yyparse(void);
+/* These yy_* functions come from markdown_parser.c which is
+ * generated from markdown_parser.leg
+ * */
+typedef int (*yyrule)();
+
+extern int yyparse();
+extern int yyparsefrom(yyrule);
+extern int yy_References();
+extern int yy_Notes();
+extern int yy_Doc();
+
+#include "utility_functions.h"
+#include "parsing_functions.h"
+#include "markdown_peg.h"
static void free_element_contents(element elt);
View
17 parsing_functions.h
@@ -0,0 +1,17 @@
+#ifndef PARSING_FUNCTIONS_H
+#define PARSING_FUNCTIONS_H
+/* parsing_functions.c - Functions for parsing markdown and
+ * freeing element lists. */
+
+#include "markdown_peg.h"
+
+/* free_element_list - free list of elements recursively */
+void free_element_list(element * elt);
+/* free_element - free element and contents */
+void free_element(element *elt);
+
+element * parse_references(char *string, int extensions);
+element * parse_notes(char *string, int extensions, element *reference_list);
+element * parse_markdown(char *string, int extensions, element *reference_list, element *note_list);
+
+#endif
View
66 utility_functions.c
@@ -1,7 +1,12 @@
/* utility_functions.c - List manipulation functions, element
* constructors, and macro definitions for leg markdown parser. */
-extern int strcasecmp(const char *string1, const char *string2);
+#include "utility_functions.h"
+#include "markdown_peg.h"
+
+#include <string.h>
+#include <assert.h>
+
/**********************************************************************
@@ -10,14 +15,14 @@ extern int strcasecmp(const char *string1, const char *string2);
***********************************************************************/
/* cons - cons an element onto a list, returning pointer to new head */
-static element * cons(element *new, element *list) {
+element * cons(element *new, element *list) {
assert(new != NULL);
new->next = list;
return new;
}
/* reverse - reverse a list, returning pointer to new list */
-static element *reverse(element *list) {
+element *reverse(element *list) {
element *new = NULL;
element *next = NULL;
while (list != NULL) {
@@ -30,7 +35,7 @@ static 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. */
-static GString *concat_string_list(element *list) {
+GString *concat_string_list(element *list) {
GString *result;
element *next;
result = g_string_new("");
@@ -51,11 +56,11 @@ static GString *concat_string_list(element *list) {
***********************************************************************/
-static char *charbuf = ""; /* Buffer of characters to be parsed. */
-static element *references = NULL; /* List of link references found. */
-static element *notes = NULL; /* List of footnotes found. */
-static element *parse_result; /* Results of parse. */
-static int syntax_extensions; /* Syntax extensions selected. */
+char *charbuf = ""; /* Buffer of characters to be parsed. */
+element *references = NULL; /* List of link references found. */
+element *notes = NULL; /* List of footnotes found. */
+element *parse_result; /* Results of parse. */
+int syntax_extensions; /* Syntax extensions selected. */
/**********************************************************************
@@ -66,7 +71,7 @@ static int syntax_extensions; /* Syntax extensions selected. */
***********************************************************************/
/* mk_element - generic constructor for element */
-static element * mk_element(int key) {
+element * mk_element(int key) {
element *result = malloc(sizeof(element));
result->key = key;
result->children = NULL;
@@ -76,7 +81,7 @@ static element * mk_element(int key) {
}
/* mk_str - constructor for STR element */
-static element * mk_str(char *string) {
+element * mk_str(char *string) {
element *result;
assert(string != NULL);
result = mk_element(STR);
@@ -86,7 +91,7 @@ static element * mk_str(char *string) {
/* mk_str_from_list - makes STR element by concatenating a
* reversed list of strings, adding optional extra newline */
-static element * mk_str_from_list(element *list, bool extra_newline) {
+element * mk_str_from_list(element *list, bool extra_newline) {
element *result;
GString *c = concat_string_list(reverse(list));
if (extra_newline)
@@ -100,7 +105,7 @@ static 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. */
-static element * mk_list(int key, element *lst) {
+element * mk_list(int key, element *lst) {
element *result;
result = mk_element(key);
result->children = reverse(lst);
@@ -108,7 +113,7 @@ static element * mk_list(int key, element *lst) {
}
/* mk_link - constructor for LINK element */
-static element * mk_link(element *label, char *url, char *title) {
+element * mk_link(element *label, char *url, char *title) {
element *result;
result = mk_element(LINK);
result->contents.link = malloc(sizeof(link));
@@ -119,12 +124,12 @@ static element * mk_link(element *label, char *url, char *title) {
}
/* extension = returns true if extension is selected */
-static bool extension(int ext) {
+bool extension(int ext) {
return (syntax_extensions & ext);
}
/* match_inlines - returns true if inline lists match (case-insensitive...) */
-static bool match_inlines(element *l1, element *l2) {
+bool match_inlines(element *l1, element *l2) {
while (l1 != NULL && l2 != NULL) {
if (l1->key != l2->key)
return false;
@@ -168,7 +173,7 @@ static 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. */
-static bool find_reference(link *result, element *label) {
+bool find_reference(link *result, element *label) {
element *cur = references; /* pointer to walk up list of references */
link *curitem;
while (cur != NULL) {
@@ -186,7 +191,7 @@ static 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. */
-static bool find_note(element **result, char *label) {
+bool find_note(element **result, char *label) {
element *cur = notes; /* pointer to walk up list of notes */
while (cur != NULL) {
if (strcmp(label, cur->contents.str) == 0) {
@@ -199,28 +204,3 @@ static bool find_note(element **result, char *label) {
return false;
}
-/**********************************************************************
-
- Definitions for leg parser generator.
- YY_INPUT is the function the parser calls to get new input.
- We take all new input from (static) charbuf.
-
- ***********************************************************************/
-
-# define YYSTYPE element *
-#ifdef __DEBUG__
-# define YY_DEBUG 1
-#endif
-
-#define YY_INPUT(buf, result, max_size) \
-{ \
- int yyc; \
- if (charbuf && *charbuf != '\0') { \
- yyc= *charbuf++; \
- } else { \
- yyc= EOF; \
- } \
- result= (EOF == yyc) ? 0 : (*(buf)= yyc, 1); \
-}
-
-
View
74 utility_functions.h
@@ -0,0 +1,74 @@
+#ifndef UTILITY_FUNCTIONS_H
+#define UTILITY_FUNCTIONS_H
+
+#include <stdbool.h>
+#include <glib.h>
+
+#include "markdown_peg.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. */
+
+/**********************************************************************
+
+ 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);
+/* 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);
+
+#endif
+
Please sign in to comment.
Something went wrong with that request. Please try again.