set (My_Project_Title "C-Template")
set (My_Project_Description "Boilerplate c project with cmake support, CuTest unit testing, and more.")
set (My_Project_Author "Fletcher T. Penney")
-set (My_Project_Revised_Date "2016-08-24")
+set (My_Project_Revised_Date "2016-12-02")
set (My_Project_Version_Major 1)
set (My_Project_Version_Minor 0)
-set (My_Project_Version_Patch 3)
+set (My_Project_Version_Patch 4)
set (My_Project_Version "${My_Project_Version_Major}.${My_Project_Version_Minor}.${My_Project_Version_Patch}")
# Utility source files will not be included in doxygen
set(src_utility_files
-# src/GLibFacade.c
+# src/d_string.c
)
set(header_utility_files
-# src/GLibFacade.h
+# src/d_string.h
${PROJECT_BINARY_DIR}/version.h
)
# if (NOT DEFINED TEST)
# add_executable(main
# src/main.c
-# src/GLibFacade.c
-# src/GLibFacade.h
+# src/d_string.c
+# src/d_string.h
# ${header_files}
# )
#
BUILD_DIR = build
+XCODE_BUILD_DIR = build-xcode
+XCODE_DEBUG_BUILD_DIR = build-xcode-debug
# The release target will perform additional optimization
.PHONY : release
# xcodebuild -configuration Debug
# xcodebuild -configuration Release
.PHONY : xcode
-xcode: $(BUILD_DIR)
- cd $(BUILD_DIR); \
+xcode: $(XCOD_BUILD_DIR)
+ cd $(XCOD_BUILD_DIR); \
cmake -G Xcode ..
+.PHONY : xcode-debug
+xcode-debug: $(XCODE_DEBUG_BUILD_DIR)
+ cd $(XCODE_DEBUG_BUILD_DIR); \
+ cmake -G Xcode -DTEST=1 ..
+
# Cross-compile for Windows using MinGW on *nix
.PHONY : windows
windows: $(BUILD_DIR)
-mkdir $(BUILD_DIR) 2>/dev/null
-cd $(BUILD_DIR); rm -rf *
+# Build xcode directories if they don't exist
+$(XCODE_BUILD_DIR):
+ -mkdir $(XCODE_BUILD_DIR) 2>/dev/null
+ -cd $(XCODE_BUILD_DIR); rm -rf *
+
+$(XCODE_DEBUG_BUILD_DIR):
+ -mkdir $(XCODE_DEBUG_BUILD_DIR) 2>/dev/null
+ -cd $(XCODE_DEBUG_BUILD_DIR); rm -rf *
+
# Generate a list of changes since last commit to 'master' branch
.PHONY : CHANGELOG
CHANGELOG:
| ---------- | ------------------------- |
| Title: | C-Template |
| Author: | Fletcher T. Penney |
-| Date: | 2016-08-24 |
+| Date: | 2016-12-02 |
| Copyright: | Copyright © 2015-2016 Fletcher T. Penney. |
-| Version: | 1.0.3 |
+| Version: | 1.0.4 |
## Introduction ##
+++ /dev/null
-/*
- * GLibFacade.h
- * MultiMarkdown
- *
- * Created by Daniel Jalkut on 7/26/11.
- * Modified by Fletcher T. Penney 9/15/11 - 5/6/16.
- * Changes Copyright 2011-2016
- * Modified by Dan Lowe on 1/3/12.
- *
- * License for original code by Daniel Jalkut:
- *
- * Copyright 2011 Daniel Jalkut. All rights reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy of
- * this software and associated documentation files (the “Software”), to deal in
- * the Software without restriction, including without limitation the rights to
- * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
- * of the Software, and to permit persons to whom the Software is furnished to do
- * so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-#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;
-
-/* This style of bool is used in shared source code */
-#if !defined(FALSE)
-#define FALSE false
-#endif
-#if !defined(TRUE)
-#define TRUE true
-#endif
-
-/* 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 */
- char* str;
-
- /* Where in the str buffer will we add new characters */
- /* or append new strings? */
- unsigned long currentStringBufferSize;
- unsigned long currentStringLength;
-} GString;
-
-GString* g_string_new(const char *startingString);
-char* g_string_free(GString* ripString, bool freeCharacterData);
-
-void g_string_append_c(GString* baseString, char appendedCharacter);
-void g_string_append_c_array(GString *baseString, char * appendedChars, size_t bytes);
-void g_string_append(GString* baseString, char *appendedString);
-
-void g_string_prepend(GString* baseString, char* prependedString);
-
-void g_string_append_printf(GString* baseString, char* format, ...);
-
-void g_string_insert(GString* baseString, size_t pos, char * insertedString);
-void g_string_insert_c(GString* baseString, size_t pos, char insertedCharacter);
-void g_string_insert_printf(GString* baseString, size_t pos, char* format, ...);
-
-void g_string_erase(GString* baseString, size_t pos, size_t len);
-
-/* Just implement a very simple singly linked list. */
-
-typedef struct _GSList
-{
- void* data;
- struct _GSList* next;
-} GSList;
-
-void g_slist_free(GSList* ripList);
-GSList* g_slist_prepend(GSList* targetElement, void* newElementData);
-GSList* g_slist_reverse(GSList* theList);
-
-#endif
+/**
+
+ Smart String -- Library to abstract smart typing features from MMD Composer
+
+ @file d_string.c
+
+ @brief Dynamic string -- refactoring of old GLibFacade
+
+
+ @author Daniel Jalkut, modified by Fletcher T. Penney and Dan Lowe
+ @bug
+
+**/
+
/*
- * GLibFacade.c
- * MultiMarkdown
- *
- * Created by Daniel Jalkut on 7/26/11.
- * Modified by Fletcher T. Penney 9/15/11 - 5/6/16.
- * Changes Copyright 2011-2016
- * Modified by Dan Lowe on 1/3/12.
- *
- * License for original code by Daniel Jalkut:
- *
- * Copyright 2011 Daniel Jalkut. All rights reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy of
- * this software and associated documentation files (the “Software”), to deal in
- * the Software without restriction, including without limitation the rights to
- * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
- * of the Software, and to permit persons to whom the Software is furnished to do
- * so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-#include "GLibFacade.h"
+ Copyright © 2011 Daniel Jalkut.
+ Modifications by Fletcher T. Penney, Copyright © 2011-2016 Fletcher T. Penney.
+ Modifications by Dan Lowe, Copyright © 2011 Dan Lowe.
+
+
+ The `c-template` project is released under the MIT License.
+
+ GLibFacade.c and GLibFacade.h are from the MultiMarkdown v4 project:
+
+ https://github.com/fletcher/MultiMarkdown-4/
+
+ MMD 4 is released under both the MIT License and GPL.
+
+
+ CuTest is released under the zlib/libpng license. See CuTest.c for the text
+ of the license.
+
+
+ ## The MIT License ##
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ THE SOFTWARE.
+
+*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
+#include "d_string.h"
+
+
/*
* The following section came from:
*
#endif
-/* GString */
+/* DString */
#define kStringBufferStartingSize 1024
#define kStringBufferGrowthMultiplier 2
-GString* g_string_new(const char *startingString)
+DString* d_string_new(const char *startingString)
{
- GString* newString = malloc(sizeof(GString));
+ DString* newString = malloc(sizeof(DString));
if (startingString == NULL) startingString = "";
return newString;
}
-char* g_string_free(GString* ripString, bool freeCharacterData)
+char* d_string_free(DString* ripString, bool freeCharacterData)
{
if (ripString == NULL)
return NULL;
return returnedString;
}
-static void ensureStringBufferCanHold(GString* baseString, size_t newStringSize)
+static void ensureStringBufferCanHold(DString* baseString, size_t newStringSize)
{
size_t newBufferSizeNeeded = newStringSize + 1;
if (newBufferSizeNeeded > baseString->currentStringBufferSize)
}
}
-void g_string_append(GString* baseString, char* appendedString)
+void d_string_append(DString* baseString, char* appendedString)
{
if ((appendedString != NULL) && (strlen(appendedString) > 0))
{
}
}
-void g_string_append_c(GString* baseString, char appendedCharacter)
+void d_string_append_c(DString* baseString, char appendedCharacter)
{
size_t newSizeNeeded = baseString->currentStringLength + 1;
ensureStringBufferCanHold(baseString, newSizeNeeded);
baseString->str[baseString->currentStringLength] = '\0';
}
-void g_string_append_c_array(GString *baseString, char * appendedChars, size_t bytes)
+void d_string_append_c_array(DString *baseString, const char * appendedChars, size_t bytes)
{
size_t newSizeNeeded = baseString->currentStringLength + bytes;
ensureStringBufferCanHold(baseString, newSizeNeeded);
baseString->str[baseString->currentStringLength] = '\0';
}
-void g_string_append_printf(GString* baseString, char* format, ...)
+void d_string_append_printf(DString* baseString, char* format, ...)
{
va_list args;
va_start(args, format);
vasprintf(&formattedString, format, args);
if (formattedString != NULL)
{
- g_string_append(baseString, formattedString);
+ d_string_append(baseString, formattedString);
free(formattedString);
}
va_end(args);
}
-void g_string_prepend(GString* baseString, char* prependedString)
+void d_string_prepend(DString* baseString, char* prependedString)
{
if ((prependedString != NULL) && (strlen(prependedString) > 0))
{
}
}
-void g_string_insert(GString* baseString, size_t pos, char * insertedString)
+void d_string_insert(DString* baseString, size_t pos, const char * insertedString)
{
if ((insertedString != NULL) && (strlen(insertedString) > 0))
{
}
}
-void g_string_insert_c(GString* baseString, size_t pos, char insertedCharacter)
+void d_string_insert_c(DString* baseString, size_t pos, char insertedCharacter)
{
if (pos > baseString->currentStringLength)
pos = baseString->currentStringLength;
}
-void g_string_insert_printf(GString* baseString, size_t pos, char* format, ...)
+void d_string_insert_printf(DString* baseString, size_t pos, char* format, ...)
{
va_list args;
va_start(args, format);
vasprintf(&formattedString, format, args);
if (formattedString != NULL)
{
- g_string_insert(baseString, pos, formattedString);
+ d_string_insert(baseString, pos, formattedString);
free(formattedString);
}
va_end(args);
}
-void g_string_erase(GString* baseString, size_t pos, size_t len)
+void d_string_erase(DString* baseString, size_t pos, size_t len)
{
if ((pos > baseString->currentStringLength) || (len <= 0))
return;
}
baseString->str[baseString->currentStringLength] = '\0';
}
-
-/* GSList */
-
-void g_slist_free(GSList* ripList)
-{
- GSList* thisListItem = ripList;
- while (thisListItem != NULL)
- {
- GSList* nextItem = thisListItem->next;
-
- /* 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 */
-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 */
- GSList* listWalker = theList;
- while (listWalker != NULL)
- {
- GSList* nextNode = listWalker->next;
- listWalker->next = lastNodeSeen;
- lastNodeSeen = listWalker;
- listWalker = nextNode;
- }
-
- return lastNodeSeen;
-}
-
-GSList* g_slist_prepend(GSList* targetElement, void* newElementData)
-{
- GSList* newElement = malloc(sizeof(GSList));
- newElement->data = newElementData;
- newElement->next = targetElement;
- return newElement;
-}
-
--- /dev/null
+/**
+
+ Smart String -- Library to abstract smart typing features from MMD Composer
+
+ @file d_string.h
+
+ @brief Dynamic string -- refactoring of old GLibFacade
+
+
+ @author Daniel Jalkut, modified by Fletcher T. Penney and Dan Lowe
+ @bug
+
+**/
+
+/*
+
+ Copyright © 2011 Daniel Jalkut.
+ Modifications by Fletcher T. Penney, Copyright © 2011-2016 Fletcher T. Penney.
+ Modifications by Dan Lowe, Copyright © 2011 Dan Lowe.
+
+
+ The `c-template` project is released under the MIT License.
+
+ GLibFacade.c and GLibFacade.h are from the MultiMarkdown v4 project:
+
+ https://github.com/fletcher/MultiMarkdown-4/
+
+ MMD 4 is released under both the MIT License and GPL.
+
+
+ CuTest is released under the zlib/libpng license. See CuTest.c for the text
+ of the license.
+
+
+ ## The MIT License ##
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ THE SOFTWARE.
+
+*/
+
+
+#ifndef D_STRING_SMART_STRING_H
+#define D_STRING_SMART_STRING_H
+
+#include <stdbool.h>
+
+/* WE implement minimal mirror implementations of GLib's GString
+ * 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 */
+ char* str;
+
+ /* Where in the str buffer will we add new characters */
+ /* or append new strings? */
+ unsigned long currentStringBufferSize;
+ unsigned long currentStringLength;
+} DString;
+
+DString* d_string_new(const char *startingString);
+
+char* d_string_free(DString* ripString, bool freeCharacterData);
+
+void d_string_append_c(DString* baseString, char appendedCharacter);
+void d_string_append_c_array(DString *baseString, const char * appendedChars, size_t bytes);
+void d_string_append(DString* baseString, char *appendedString);
+
+void d_string_prepend(DString* baseString, char* prependedString);
+
+void d_string_append_printf(DString* baseString, char* format, ...);
+
+void d_string_insert(DString* baseString, size_t pos, const char * insertedString);
+void d_string_insert_c(DString* baseString, size_t pos, char insertedCharacter);
+void d_string_insert_printf(DString* baseString, size_t pos, char* format, ...);
+
+void d_string_erase(DString* baseString, size_t pos, size_t len);
+
+
+#endif
#include <stdio.h>
#include <stdlib.h>
-#include "GLibFacade.h"
+#include "d_string.h"
#define kBUFFERSIZE 4096 // How many bytes to read at a time
-GString * stdin_buffer() {
+DString * stdin_buffer() {
/* Read from stdin and return a GString *
`buffer` will need to be freed elsewhere */
char chunk[kBUFFERSIZE];
size_t bytes;
- GString * buffer = g_string_new("");
+ DString * buffer = d_string_new("");
while ((bytes = fread(chunk, 1, kBUFFERSIZE, stdin)) > 0) {
- g_string_append_c_array(buffer, chunk, bytes);
+ d_string_append_c_array(buffer, chunk, bytes);
}
fclose(stdin);
return buffer;
}
-GString * scan_file(char * fname) {
+DString * scan_file(char * fname) {
/* Read from stdin and return a GString *
`buffer` will need to be freed elsewhere */
return NULL;
}
- GString * buffer = g_string_new("");
+ DString * buffer = d_string_new("");
while ((bytes = fread(chunk, 1, kBUFFERSIZE, file)) > 0) {
- g_string_append_c_array(buffer, chunk, bytes);
+ d_string_append_c_array(buffer, chunk, bytes);
}
fclose(file);