Permalink
Browse files

manually incorporate Daniel's changes

  • Loading branch information...
1 parent 32e66ee commit 58bdceb1b3a4471b79f71f72e0cec7e7c50eeda8 @fletcher committed Aug 3, 2011
Showing with 85 additions and 111 deletions.
  1. +33 −18 GLibFacade.h
  2. +19 −15 GLibFacade.m
  3. +27 −16 Makefile
  4. +2 −1 glib.h
  5. +4 −61 markdown.c
View
51 GLibFacade.h
@@ -1,30 +1,43 @@
-//
-// GLibFacade.h
-// MultiMarkdown
-//
-// Created by Daniel Jalkut on 7/26/11.
-// Copyright 2011 __MyCompanyName__. All rights reserved.
-//
+/*
+ * GLibFacade.h
+ * MultiMarkdown
+ *
+ * Created by Daniel Jalkut on 7/26/11.
+ * Copyright 2011 __MyCompanyName__. All rights reserved.
+ */
-#import <Foundation/Foundation.h>
+#ifndef __MARKDOWN_GLIB_FACADE__
+#define __MARKDOWN_GLIB_FACADE__
+
+/* peg_markdown uses the link symbol for its own purposes */
+#define link MARKDOWN_LINK_IGNORED
+#include <unistd.h>
+#undef link
+
+#include <stdbool.h>
+#include <ctype.h>
typedef int gboolean;
typedef char gchar;
-// WE implement minimal mirror implementations of GLib's GString and GSList
-// sufficient to cover the functionality required by MultiMarkdown.
-//
-// NOTE: THese are 100% clean, from-scratch implementations using only the
-// GLib function prototype as guide for behavior.
-//
+/* This style of bool is used in shared source code */
+#define FALSE false
+#define TRUE true
+
+/* WE implement minimal mirror implementations of GLib's GString and GSList
+ * sufficient to cover the functionality required by MultiMarkdown.
+ *
+ * NOTE: THese are 100% clean, from-scratch implementations using only the
+ * GLib function prototype as guide for behavior.
+ */
typedef struct
{
- // Current UTF8 byte stream this string represents
+ /* Current UTF8 byte stream this string represents */
char* str;
- // Where in the str buffer will we add new characters
- // or append new strings?
+ /* Where in the str buffer will we add new characters */
+ /* or append new strings? */
int currentStringBufferSize;
int currentStringLength;
} GString;
@@ -39,7 +52,7 @@ void g_string_prepend(GString* baseString, char* prependedString);
void g_string_append_printf(GString* baseString, char* format, ...);
-// Just implement a very simple singly linked list.
+/* Just implement a very simple singly linked list. */
typedef struct _GSList
{
@@ -50,3 +63,5 @@ typedef struct _GSList
void g_slist_free(GSList* ripList);
GSList* g_slist_prepend(GSList* targetElement, void* newElementData);
GSList* g_slist_reverse(GSList* theList);
+
+#endif
View
34 GLibFacade.m
@@ -1,15 +1,19 @@
-//
-// GLibFacade.m
-// MultiMarkdown
-//
-// Created by Daniel Jalkut on 7/26/11.
-// Copyright 2011 __MyCompanyName__. All rights reserved.
-//
+/*
+ * GLibFacade.m
+ * MultiMarkdown
+ *
+ * Created by Daniel Jalkut on 7/26/11.
+ * Copyright 2011 __MyCompanyName__. All rights reserved.
+ */
-#import <Foundation/Foundation.h>
-#import "GLibFacade.h"
+#include "GLibFacade.h"
-// GString
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdarg.h>
+
+/* GString */
#define kStringBufferStartingSize 1024
#define kStringBufferGrowthMultiplier 2
@@ -78,7 +82,7 @@ void g_string_append(GString* baseString, char* appendedString)
size_t newStringLength = baseString->currentStringLength + appendedStringLength;
ensureStringBufferCanHold(baseString, newStringLength);
- // We already know where the current string ends, so pass that as the starting address for strncat
+ /* We already know where the current string ends, so pass that as the starting address for strncat */
strncat(baseString->str + baseString->currentStringLength, appendedString, appendedStringLength);
baseString->currentStringLength = newStringLength;
}
@@ -123,7 +127,7 @@ void g_string_prepend(GString* baseString, char* prependedString)
}
}
-// GSList
+/* GSList */
void g_slist_free(GSList* ripList)
{
@@ -132,19 +136,19 @@ void g_slist_free(GSList* ripList)
{
GSList* nextItem = thisListItem->next;
- // I guess we don't release the data? Non-retained memory management is hard... let's figure it out later.
+ /* I guess we don't release the data? Non-retained memory management is hard... let's figure it out later. */
free(thisListItem);
thisListItem = nextItem;
}
}
-// Currently only used for markdown_output.c endnotes printing
+/* Currently only used for markdown_output.c endnotes printing */
GSList* g_slist_reverse(GSList* theList)
{
GSList* lastNodeSeen = NULL;
- // Iterate the list items, tacking them on to our new reversed List as we find them
+ /* Iterate the list items, tacking them on to our new reversed List as we find them */
GSList* listWalker = theList;
while (listWalker != NULL)
{
View
43 Makefile
@@ -4,24 +4,35 @@ VERSION=3.1b1
PROGRAM=multimarkdown
-# If you used fink to install gib2-dev, it might have been compiled for
-# the i386 architecture, causing an error. Can try adding -arch i686 to
-# CFLAGS
-
-CFLAGS ?= -Wall -O3 -ansi
-
-OBJS=markdown_parser.o markdown_output.o markdown_lib.o
+UNAME=$(shell uname)
+
+ifeq ($(UNAME), Darwin)
+define FINALNOTES
+ ***\n\
+*** WARNING: Since you are on Darwin, you probably meant to use the Xcode version instead.\n\
+*** It does lots of nice magic like producing a version of the binary that is capable\n\
+*** of running on multiple versions of Mac OS X and with a variety of CPU architectures.\n\
+***
+endef
+else
+ FINALNOTES=Build complete.
+endif
+
+CFLAGS ?= -Wall -O3 -ansi -include GLibFacade.h -I ./ -D MD_USE_GET_OPT=1
+
+OBJS=markdown_parser.o markdown_output.o markdown_lib.o GLibFacade.o
PEGDIR=peg-0.1.4
LEG=$(PEGDIR)/leg
$(LEG):
CC=gcc make -C $(PEGDIR)
%.o : %.c markdown_peg.h
- $(CC) -c $(CFLAGS) -o $@ $<
+ $(CC) -c $(CFLAGS) -o $@ $<
$(PROGRAM) : markdown.c $(OBJS)
- $(CC) $(CFLAGS) -o $@ $(OBJS) $<
+ $(CC) $(CFLAGS) -o $@ $(OBJS) $<
+ @echo "$(FINALNOTES)"
markdown_parser.c : markdown_parser.leg $(LEG) markdown_peg.h parsing_functions.c utility_functions.c
$(LEG) -o $@ $<
@@ -41,25 +52,25 @@ clean:
distclean: clean
make -C $(PEGDIR) spotless
-test: # $(PROGRAM)
+test: $(PROGRAM)
cd MarkdownTest; \
- ./MarkdownTest.pl --Script=../$(PROGRAM) --Tidy --Flags="-c"
+ ./MarkdownTest.pl --Script=../$(PROGRAM) --Tidy --Flags="--compatibility"
-mmdtest: # $(PROGRAM)
+mmdtest: $(PROGRAM)
cd MarkdownTest; \
./MarkdownTest.pl --Script=../$(PROGRAM) --testdir=MultiMarkdownTests
-compattest: # $(PROGRAM)
+compattest: $(PROGRAM)
cd MarkdownTest; \
- ./MarkdownTest.pl --Script=../$(PROGRAM) --Tidy --testdir=CompatibilityTests --Flags="-c"
+ ./MarkdownTest.pl --Script=../$(PROGRAM) --testdir=CompatibilityTests --Flags="--compatibility"
-latextest: # $(PROGRAM)
+latextest: $(PROGRAM)
cd MarkdownTest; \
./MarkdownTest.pl --Script=../$(PROGRAM) --testdir=MultiMarkdownTests --Flags="-t latex" --ext=".tex"; \
./MarkdownTest.pl --Script=../$(PROGRAM) --testdir=BeamerTests --Flags="-t latex" --ext=".tex"; \
./MarkdownTest.pl --Script=../$(PROGRAM) --testdir=MemoirTests --Flags="-t latex" --ext=".tex"
-xslttest: # $(PROGRAM)
+xslttest: $(PROGRAM)
cd MarkdownTest; \
./MarkdownTest.pl --Script=/bin/cat --testdir=MultiMarkdownTests \
--TrailFlags="| ../Support/bin/mmd2tex-xslt" --ext=".tex"; \
View
3 glib.h
@@ -7,4 +7,5 @@
*
*/
-// Just a dummy file to keep the glib-dependent sources compiling as we would hope
+/* Just a dummy file to keep the glib-dependent sources compiling as we would hope */
+#include "GLibFacade.h"
View
65 markdown.c
@@ -22,6 +22,7 @@
#include <stdlib.h>
#include <string.h>
#include <assert.h>
+#include <getopt.h>
#include <glib.h>
#include "markdown_peg.h"
@@ -36,11 +37,10 @@ static int extensions;
***********************************************************************/
-#define VERSION "3.1b1-glibfree"
+#define VERSION "3.1b1-redsweater"
#define COPYRIGHT "portions Copyright (c) 2010-2011 Fletcher T. Penney.\n" \
"portions Copyright (c) 2011 Daniel Jalkut, MIT licensed.\n" \
"original Copyright (c) 2008-2009 John MacFarlane. License GPLv2+ or MIT.\n" \
- "GlibCocoaBridge code Copyright (c) 2011 Daniel Jalkut.\n" \
"This is free software: you are free to change and redistribute it.\n" \
"There is NO WARRANTY, to the extent permitted by law."
@@ -53,31 +53,10 @@ void version(const char *progname)
COPYRIGHT);
}
-// We like to use getopt on the standalone Mac version, because
-// it rids us of dependency on GLib's GOptions parser. But you
-// might want to use this on other platforms that support getopt, too.
-#ifndef MD_USE_GET_OPT
-#if STANDALONE_MAC_VERSION
-#define MD_USE_GET_OPT 1
-#else
-#define MD_USE_GET_OPT 0
-#endif
-#endif
-
-// These are a bit hacky - note that the supplied arguments are not used to the fullest in the getopt case. For
-// example we aren't able to use the specified description or in the case of strings, any specified output
-// variables for the resulting string, we have to just catch those at processing time and create the strings.
-#if MD_USE_GET_OPT
-#include <getopt.h>
#define MD_ARGUMENT_FLAG(name, flagChar, flagValue, outPointer, desc, argPlaceholder) { name, no_argument, outPointer, outPointer ? flagValue : flagChar }
#define MD_ARGUMENT_STRING(name, flagChar, outPointer, desc, argPlaceholder) { name, required_argument, NULL, flagChar }
-#else
-#define MD_ARGUMENT_FLAG(name, flagChar, outPointer, desc, argPlaceholder) { name, flagChar, 0, G_OPTION_ARG_NONE, outPointer, desc, argPlaceholder }
-#define MD_ARGUMENT_STRING(name, flagChar, outPointer, desc, argPlaceholder) { name, flagChar, 0, G_OPTION_ARG_STRING, outPointer, desc, argPlaceholder }
-#endif
-// With getopt we don't get the same fancy automatic usage (I don't think?) so for
-// now we're faking it ...
+/* With getopt we don't get the same fancy automatic usage (I don't think?) so for now we're faking it ... */
static void printUsage() {
printf("Usage:\
multimarkdown [OPTION...] [FILE...]\n\
@@ -140,14 +119,9 @@ int main(int argc, char * argv[]) {
static gchar *opt_extract_meta = FALSE;
static gboolean opt_no_labels = FALSE;
-#if MD_USE_GET_OPT
static struct option entries[] =
{
MD_ARGUMENT_FLAG( "help", 'h', 1, NULL, "Show help options", NULL ),
-#else
- static GOptionEntry entries[] =
- {
-#endif
MD_ARGUMENT_FLAG( "version", 'v', 1, &opt_version, "print version and exit", NULL ),
MD_ARGUMENT_STRING( "output", 'o', &opt_output, "send output to FILE (default is stdout)", "FILE" ),
MD_ARGUMENT_STRING( "to", 't', &opt_to, "convert to FORMAT (default is html)", "FORMAT" ),
@@ -157,25 +131,14 @@ int main(int argc, char * argv[]) {
MD_ARGUMENT_FLAG( "compatibility", 'c', 1, &opt_compatibility, "markdown compatibility mode", NULL ),
MD_ARGUMENT_FLAG( "batch", 'b', 1, &opt_batchmode, "process multiple files automatically", NULL ),
MD_ARGUMENT_STRING( "extract", 'e', &opt_extract_meta, "extract and display specified metadata", NULL ),
-// For GOptions, the arguments are split into two groups
-#if !MD_USE_GET_OPT
- { NULL }
- };
-
- /* Options to active syntax extensions. These appear separately in --help. */
- static GOptionEntry ext_entries[] =
- {
-#endif
MD_ARGUMENT_FLAG( "smart", 0, 1, &opt_smart, "use smart typography extension (on by default)", NULL ),
MD_ARGUMENT_FLAG( "nosmart", 0, 1, &opt_no_smart, "do not use smart typography extension", NULL ),
MD_ARGUMENT_FLAG( "notes", 0, 1, &opt_notes, "use notes extension (on by default)", NULL ),
MD_ARGUMENT_FLAG( "nonotes", 0, 1, &opt_no_notes, "do not use notes extension", NULL ),
MD_ARGUMENT_FLAG( "process-html", 0, 1, &opt_process_html, "process MultiMarkdown inside of raw HTML", NULL ),
- MD_ARGUMENT_FLAG( "nolabels", 0, 1, &opt_no_labels, "do not look for possible cross-references - improves speed", NULL ),
{ NULL }
};
-#if MD_USE_GET_OPT
char ch;
while ((ch = getopt_long(argc, argv, "hvo:t:xcbe:", entries, NULL)) != -1) {
switch (ch) {
@@ -213,30 +176,10 @@ int main(int argc, char * argv[]) {
argc -= optind;
argv += optind;
- // We expect argc and argv to still point just one below the start of remaining args
+ /* We expect argc and argv to still point just one below the start of remaining args */
argc++;
argv--;
-#else
- GError *error = NULL;
- GOptionContext *context;
- GOptionGroup *ext_group;
-
- context = g_option_context_new ("[FILE...]");
- g_option_context_add_main_entries (context, entries, NULL);
- ext_group = g_option_group_new ("extensions", "Syntax extensions", "show available syntax extensions", NULL, NULL);
- g_option_group_add_entries (ext_group, ext_entries);
- g_option_context_add_group (context, ext_group);
- g_option_context_set_description (context, "Converts text in specified files (or stdin) from markdown to FORMAT.\n"
- "Available FORMATs: html, latex, memoir, beamer, odf, opml");
- if (!g_option_context_parse (context, &argc, &argv, &error)) {
- g_print ("option parsing failed: %s\n", error->message);
- exit (1);
- }
- g_option_context_free(context);
-
-#endif
-
/* Process command-line options and arguments. */
if (opt_version) {

0 comments on commit 58bdceb

Please sign in to comment.