From: Fletcher T. Penney Date: Fri, 21 Jul 2017 22:22:14 +0000 (-0400) Subject: UPDATED: Add astyle configuration to tidy c source files X-Git-Tag: 6.2.0^2~20 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c06801c34fce4ef75740e03f6f1df78b71f398df;p=multimarkdown UPDATED: Add astyle configuration to tidy c source files --- diff --git a/.astylerc b/.astylerc new file mode 100644 index 0000000..6acda5c --- /dev/null +++ b/.astylerc @@ -0,0 +1,19 @@ +# Brace style +--style=java + + +# Indents +--indent=tab=4 + +# Switch statements +--indent-switches + + +# Excludes +--exclude="Sources/libMultiMarkdown/scanners.c" +--exclude="Sources/libMultiMarkdown/parser.c" +--exclude="Sources/libMultiMarkdown/lexer.c" +--exclude="Sources/multimarkdown/argtable3.c" +--exclude="Sources/libMultiMarkdown/miniz.c" + +--ignore-exclude-errors diff --git a/Makefile b/Makefile index 0f9c979..93f4e23 100644 --- a/Makefile +++ b/Makefile @@ -125,3 +125,7 @@ $(XCODE_DEBUG_BUILD_DIR): CHANGELOG: -git log master..develop --format="* %s" | sort | uniq > CHANGELOG-UNRELEASED +# Use astyle +.PHONY : astyle +astyle: + astyle --options=.astylerc "Sources/libMultiMarkdown/*.c" "Sources/multimarkdown/*.c" diff --git a/Sources/libMultiMarkdown/aho-corasick.c b/Sources/libMultiMarkdown/aho-corasick.c index 44cedec..38020db 100644 --- a/Sources/libMultiMarkdown/aho-corasick.c +++ b/Sources/libMultiMarkdown/aho-corasick.c @@ -11,7 +11,7 @@ @author Fletcher T. Penney - @bug + @bug **/ @@ -21,30 +21,30 @@ 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 @@ -280,10 +280,9 @@ void ac_trie_node_prepare(trie * a, size_t s, char * buffer, unsigned short dept // Prepare children - for (int i = 0; i < 256; ++i) - { + for (int i = 0; i < 256; ++i) { if ((n->child[i] != 0) && - (n->child[i] != s)) { + (n->child[i] != s)) { buffer[depth] = i; ac_trie_node_prepare(a, n->child[i], buffer, depth + 1, last_match_state); @@ -294,8 +293,7 @@ void ac_trie_node_prepare(trie * a, size_t s, char * buffer, unsigned short dept /// Prepare trie for Aho-Corasick search algorithm by mapping failure connections void ac_trie_prepare(trie * a) { // Clear old pointers - for (size_t i = 0; i < a->size; ++i) - { + for (size_t i = 0; i < a->size; ++i) { a->node[i].ac_fail = 0; } @@ -401,7 +399,7 @@ match * ac_trie_search(trie * a, const char * source, size_t start, size_t len) m = result; } m = match_add(m, counter - a->node[temp_state].len, - a->node[temp_state].len, a->node[temp_state].match_type); + a->node[temp_state].len, a->node[temp_state].match_type); } // Iterate to find shorter matches @@ -442,8 +440,8 @@ int match_count(match * m) { void match_describe(match * m, const char * source) { - fprintf(stderr, "'%.*s'(%d) at %lu:%lu\n", (int)m->len, &source[m->start], - m->match_type, m->start, m->start + m->len); + fprintf(stderr, "'%.*s'(%d) at %lu:%lu\n", (int)m->len, &source[m->start], + m->match_type, m->start, m->start + m->len); } @@ -471,15 +469,15 @@ void match_set_filter_leftmost_longest(match * header) { continue; } - while (m->next && - m->next->start > m->start && - m->next->start < m->start + m->len) { + while (m->next && + m->next->start > m->start && + m->next->start < m->start + m->len) { // This match is "lefter" than next match_excise(m->next); } while (m->next && - m->next->start < m->start) { + m->next->start < m->start) { // Next match is "lefter" than us n = m; m = m->prev; @@ -488,8 +486,8 @@ void match_set_filter_leftmost_longest(match * header) { } while (m->prev && - m->prev->len && - m->prev->start >= m->start) { + m->prev->len && + m->prev->start >= m->start) { // We are "lefter" than previous n = m->prev; match_excise(n); @@ -564,8 +562,7 @@ void trie_node_to_graphviz(trie * a, size_t s) { if (n->match_type) fprintf(stderr, "\"%lu\" [shape=doublecircle]\n", s); - for (int i = 0; i < 256; ++i) - { + for (int i = 0; i < 256; ++i) { if (n->child[i]) { switch (i) { default: @@ -581,8 +578,7 @@ void trie_node_to_graphviz(trie * a, size_t s) { void trie_to_graphviz(trie * a) { fprintf(stderr, "digraph dfa {\n"); - for (int i = 0; i < a->size; ++i) - { + for (int i = 0; i < a->size; ++i) { trie_node_to_graphviz(a, i); } fprintf(stderr, "}\n"); diff --git a/Sources/libMultiMarkdown/beamer.c b/Sources/libMultiMarkdown/beamer.c index bb6d830..bf7a9fb 100644 --- a/Sources/libMultiMarkdown/beamer.c +++ b/Sources/libMultiMarkdown/beamer.c @@ -4,11 +4,11 @@ @file beamer.c - @brief + @brief @author Fletcher T. Penney - @bug + @bug **/ @@ -18,30 +18,30 @@ The `MultiMarkdown 6` 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 @@ -67,7 +67,7 @@ void mmd_outline_add_beamer(DString * out, token * current, scratch_pad * scratch) { token * t; short level; // Header level we are adding - short t_level; + short t_level; stack * s = scratch->outline_stack; if (current) { @@ -236,7 +236,7 @@ void mmd_export_token_beamer(DString * out, const char * source, token * t, scra temp_char = label_from_token(source, t); } printf("}\n\\label{%s}", temp_char); - + if (temp_char) free(temp_char); } @@ -281,8 +281,7 @@ void mmd_export_citation_list_beamer(DString * out, const char * source, scratch print_const("\\part{Bibliography}\n\\begin{frame}[allowframebreaks]\n\\frametitle{Bibliography}\n\\def\\newblock{}\n\\begin{thebibliography}{0}"); scratch->padded = 0; - for (int i = 0; i < scratch->used_citations->size; ++i) - { + for (int i = 0; i < scratch->used_citations->size; ++i) { // Export footnote pad(out, 2, scratch); diff --git a/Sources/libMultiMarkdown/char.c b/Sources/libMultiMarkdown/char.c index f9d1259..1f8b1f3 100644 --- a/Sources/libMultiMarkdown/char.c +++ b/Sources/libMultiMarkdown/char.c @@ -8,7 +8,7 @@ @author Fletcher T. Penney - @bug + @bug **/ @@ -18,30 +18,30 @@ The `MultiMarkdown 6` 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 @@ -59,22 +59,22 @@ /// Create this lookup table using char_lookup.c static unsigned char smart_char_type[256] = { - 16, 0, 0, 0, 0, 0, 0, 0, 0, 1, 16, 0, 0, 16, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 2, 2, 2, 2, 2, 2, - 2, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 2, 2, 2, 2, 2, - 2, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 2, 2, 2, 2, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + 16, 0, 0, 0, 0, 0, 0, 0, 0, 1, 16, 0, 0, 16, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 2, 2, 2, 2, 2, 2, + 2, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 2, 2, 2, 2, 2, + 2, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 2, 2, 2, 2, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; @@ -111,7 +111,7 @@ int char_is_windows_line_ending(char * c) { #ifdef TEST void Test_char_is_windows_line_ending(CuTest* tc) { char * test = "\r\n\n"; - + CuAssertIntEquals(tc, 1, char_is_windows_line_ending(&test[0])); CuAssertIntEquals(tc, 1, char_is_windows_line_ending(&test[1])); CuAssertIntEquals(tc, 0, char_is_windows_line_ending(&test[2])); @@ -120,22 +120,22 @@ void Test_char_is_windows_line_ending(CuTest* tc) { // Is character punctuation? int char_is_punctuation(char c) { - return smart_char_type[(unsigned char) c] & CHAR_PUNCTUATION; + return smart_char_type[(unsigned char) c] & CHAR_PUNCTUATION; } // Is character alpha? int char_is_alpha(char c) { - return smart_char_type[(unsigned char) c] & CHAR_ALPHA; + return smart_char_type[(unsigned char) c] & CHAR_ALPHA; } // Is character digit? int char_is_digit(char c) { - return smart_char_type[(unsigned char) c] & CHAR_DIGIT; + return smart_char_type[(unsigned char) c] & CHAR_DIGIT; } // Is character alphanumeric? int char_is_alphanumeric(char c) { - return smart_char_type[(unsigned char) c] & CHAR_ALPHANUMERIC; + return smart_char_type[(unsigned char) c] & CHAR_ALPHANUMERIC; } // Is character either whitespace or line ending? @@ -150,5 +150,5 @@ int char_is_whitespace_or_punctuation(char c) { // Is character either whitespace or line ending or punctuation? int char_is_whitespace_or_line_ending_or_punctuation(char c) { - return smart_char_type[(unsigned char) c] & CHAR_WHITESPACE_OR_LINE_ENDING_OR_PUNCTUATION; + return smart_char_type[(unsigned char) c] & CHAR_WHITESPACE_OR_LINE_ENDING_OR_PUNCTUATION; } diff --git a/Sources/libMultiMarkdown/char_lookup.c b/Sources/libMultiMarkdown/char_lookup.c index bcf59db..26799a8 100644 --- a/Sources/libMultiMarkdown/char_lookup.c +++ b/Sources/libMultiMarkdown/char_lookup.c @@ -8,7 +8,7 @@ @author Fletcher T. Penney - @bug + @bug **/ @@ -18,30 +18,30 @@ The `MultiMarkdown 6` 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 @@ -124,18 +124,15 @@ int main( int argc, char** argv ) { // Define digits - for (char i = '0'; i <= '9'; ++i) - { + for (char i = '0'; i <= '9'; ++i) { digit(i); } // Define alpha - for (char i = 'a'; i <= 'z'; ++i) - { + for (char i = 'a'; i <= 'z'; ++i) { alpha(i); } - for (char i = 'A'; i <= 'Z'; ++i) - { + for (char i = 'A'; i <= 'Z'; ++i) { alpha(i); } @@ -199,10 +196,8 @@ int main( int argc, char** argv ) { // Print output as 16 x 16 table - for (int i = 0; i < 16; ++i) - { - for (int j = 0; j < 16; ++j) - { + for (int i = 0; i < 16; ++i) { + for (int j = 0; j < 16; ++j) { fprintf(stdout, "%3d,", table[i * 16 + j]); } diff --git a/Sources/libMultiMarkdown/critic_markup.c b/Sources/libMultiMarkdown/critic_markup.c index 17457e7..61b2954 100644 --- a/Sources/libMultiMarkdown/critic_markup.c +++ b/Sources/libMultiMarkdown/critic_markup.c @@ -4,11 +4,11 @@ @file critic_markup.c - @brief + @brief @author Fletcher T. Penney - @bug + @bug **/ @@ -18,20 +18,20 @@ The `MultiMarkdown 6` 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 @@ -39,10 +39,10 @@ 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. @@ -50,7 +50,7 @@ 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. - + */ diff --git a/Sources/libMultiMarkdown/d_string.c b/Sources/libMultiMarkdown/d_string.c index d20ae46..eac5328 100644 --- a/Sources/libMultiMarkdown/d_string.c +++ b/Sources/libMultiMarkdown/d_string.c @@ -10,7 +10,7 @@ @author Daniel Jalkut, modified by Fletcher T. Penney and Dan Lowe - @bug + @bug **/ @@ -22,30 +22,30 @@ The `MultiMarkdown 6` 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 @@ -101,10 +101,9 @@ int vasprintf(char** strp, const char* fmt, va_list ap) { /// Create a new dynamic string -DString* d_string_new(const char * startingString) -{ +DString* d_string_new(const char * startingString) { DString* newString = malloc(sizeof(DString)); - + if (!newString) return NULL; @@ -112,11 +111,10 @@ DString* d_string_new(const char * startingString) size_t startingBufferSize = kStringBufferStartingSize; size_t startingStringSize = strlen(startingString); - while (startingBufferSize < (startingStringSize + 1)) - { + while (startingBufferSize < (startingStringSize + 1)) { startingBufferSize *= kStringBufferGrowthMultiplier; } - + newString->str = malloc(startingBufferSize); if (!newString->str) { @@ -128,59 +126,53 @@ DString* d_string_new(const char * startingString) strncpy(newString->str, startingString, startingStringSize); newString->str[startingStringSize] = '\0'; newString->currentStringLength = startingStringSize; - + return newString; } /// Free dynamic string -char* d_string_free(DString * ripString, bool freeCharacterData) -{ +char* d_string_free(DString * ripString, bool freeCharacterData) { if (ripString == NULL) return NULL; - + char* returnedString = ripString->str; - if (freeCharacterData) - { - if (ripString->str != NULL) - { + if (freeCharacterData) { + if (ripString->str != NULL) { free(ripString->str); } returnedString = NULL; } - + free(ripString); - + return returnedString; } /// Ensure that dynamic string has specified capacity -static void ensureStringBufferCanHold(DString * baseString, size_t newStringSize) -{ +static void ensureStringBufferCanHold(DString * baseString, size_t newStringSize) { size_t newBufferSizeNeeded = newStringSize + 1; - if (newBufferSizeNeeded > baseString->currentStringBufferSize) - { - size_t newBufferSize = baseString->currentStringBufferSize; + if (newBufferSizeNeeded > baseString->currentStringBufferSize) { + size_t newBufferSize = baseString->currentStringBufferSize; - while (newBufferSizeNeeded > newBufferSize) - { + while (newBufferSizeNeeded > newBufferSize) { if (newBufferSize > kStringBufferMaxIncrement) { newBufferSize += kStringBufferMaxIncrement; } else { newBufferSize *= kStringBufferGrowthMultiplier; } } - - char *temp; - temp = realloc(baseString->str, newBufferSize); - - if (temp == NULL) { - /* realloc failed */ - fprintf(stderr, "Error reallocating memory for d_string. Current buffer size %lu.\n",baseString->currentStringBufferSize); - - exit(1); - } + + char *temp; + temp = realloc(baseString->str, newBufferSize); + + if (temp == NULL) { + /* realloc failed */ + fprintf(stderr, "Error reallocating memory for d_string. Current buffer size %lu.\n",baseString->currentStringBufferSize); + + exit(1); + } baseString->str = temp; baseString->currentStringBufferSize = newBufferSize; } @@ -188,12 +180,10 @@ static void ensureStringBufferCanHold(DString * baseString, size_t newStringSize /// Append null-terminated string to end of dynamic string -void d_string_append(DString * baseString, const char * appendedString) -{ +void d_string_append(DString * baseString, const char * appendedString) { size_t appendedStringLength = strlen(appendedString); - if ((appendedString != NULL) && (appendedStringLength > 0)) - { + if ((appendedString != NULL) && (appendedStringLength > 0)) { size_t newStringLength = baseString->currentStringLength + appendedStringLength; ensureStringBufferCanHold(baseString, newStringLength); @@ -205,20 +195,18 @@ void d_string_append(DString * baseString, const char * appendedString) /// Append single character to end of dynamic string -void d_string_append_c(DString * 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] = appendedCharacter; - baseString->currentStringLength++; + baseString->currentStringLength++; baseString->str[baseString->currentStringLength] = '\0'; } /// Append array of characters to end of dynamic string -void d_string_append_c_array(DString * baseString, const 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); @@ -230,29 +218,25 @@ void d_string_append_c_array(DString * baseString, const char * appendedChars, s /// Append to end of dynamic string using format specifier -void d_string_append_printf(DString * baseString, const char * format, ...) -{ +void d_string_append_printf(DString * baseString, const char * format, ...) { va_list args; va_start(args, format); - + char* formattedString = NULL; vasprintf(&formattedString, format, args); - if (formattedString != NULL) - { + if (formattedString != NULL) { d_string_append(baseString, formattedString); free(formattedString); } va_end(args); -} +} /// Prepend null-terminated string to end of dynamic string -void d_string_prepend(DString * baseString, const char * prependedString) -{ +void d_string_prepend(DString * baseString, const char * prependedString) { size_t prependedStringLength = strlen(prependedString); - if ((prependedString != NULL) && (prependedStringLength > 0)) - { + if ((prependedString != NULL) && (prependedStringLength > 0)) { size_t newStringLength = baseString->currentStringLength + prependedStringLength; ensureStringBufferCanHold(baseString, newStringLength); @@ -265,18 +249,16 @@ void d_string_prepend(DString * baseString, const char * prependedString) /// Insert null-terminated string inside dynamic string -void d_string_insert(DString * baseString, size_t pos, const char * insertedString) -{ +void d_string_insert(DString * baseString, size_t pos, const char * insertedString) { size_t insertedStringLength = strlen(insertedString); - if ((insertedString != NULL) && (insertedStringLength > 0)) - { + if ((insertedString != NULL) && (insertedStringLength > 0)) { if (pos > baseString->currentStringLength) pos = baseString->currentStringLength; - + size_t newStringLength = baseString->currentStringLength + insertedStringLength; ensureStringBufferCanHold(baseString, newStringLength); - + /* Shift following string to 'right' */ memmove(baseString->str + pos + insertedStringLength, baseString->str + pos, baseString->currentStringLength - pos); strncpy(baseString->str + pos, insertedString, insertedStringLength); @@ -287,33 +269,30 @@ void d_string_insert(DString * baseString, size_t pos, const char * insertedStri /// Insert single character inside dynamic string -void d_string_insert_c(DString * 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; - + size_t newSizeNeeded = baseString->currentStringLength + 1; ensureStringBufferCanHold(baseString, newSizeNeeded); - + /* Shift following string to 'right' */ memmove(baseString->str + pos + 1, baseString->str + pos, baseString->currentStringLength - pos); - + baseString->str[pos] = insertedCharacter; - baseString->currentStringLength++; + baseString->currentStringLength++; baseString->str[baseString->currentStringLength] = '\0'; } /// Insert inside dynamic string using format specifier -void d_string_insert_printf(DString * baseString, size_t pos, const char * format, ...) -{ +void d_string_insert_printf(DString * baseString, size_t pos, const char * format, ...) { va_list args; va_start(args, format); - + char* formattedString = NULL; vasprintf(&formattedString, format, args); - if (formattedString != NULL) - { + if (formattedString != NULL) { d_string_insert(baseString, pos, formattedString); free(formattedString); } @@ -322,43 +301,42 @@ void d_string_insert_printf(DString * baseString, size_t pos, const char * forma /// Erase portion of dynamic string -void d_string_erase(DString * 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; - - if ((pos + len) >= baseString->currentStringLength) + + if ((pos + len) >= baseString->currentStringLength) len = -1; - + if (len == -1) { baseString->currentStringLength = pos; } else { memmove(baseString->str + pos, baseString->str + pos + len, baseString->currentStringLength - pos - len); baseString->currentStringLength -= len; } - + baseString->str[baseString->currentStringLength] = '\0'; } /// Copy a portion of dynamic string char * d_string_copy_substring(DString * d, size_t start, size_t len) { char * result; - + if (len == -1) { len = d->currentStringLength - start; } else { if (start + len > d->currentStringLength) { fprintf(stderr, "d_string: Asked to copy invalid substring range.\n"); fprintf(stderr, "start: %lu len: %lu string: %lu\n", start, len, - d->currentStringLength); + d->currentStringLength); return NULL; } } - + result = malloc(len + 1); strncpy(result, &d->str[start], len); result[len] = '\0'; - + return result; } diff --git a/Sources/libMultiMarkdown/epub.c b/Sources/libMultiMarkdown/epub.c index 5bd8302..e07bb99 100644 --- a/Sources/libMultiMarkdown/epub.c +++ b/Sources/libMultiMarkdown/epub.c @@ -4,11 +4,11 @@ @file epub.c - @brief + @brief @author Fletcher T. Penney - @bug + @bug **/ @@ -18,20 +18,20 @@ The `MultiMarkdown 6` 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 @@ -39,10 +39,10 @@ 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. @@ -50,7 +50,7 @@ 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. - + */ @@ -108,7 +108,7 @@ char * epub_container_xml(void) { char * result = container->str; d_string_free(container, false); - return result; + return result; } @@ -122,7 +122,7 @@ char * epub_package_document(scratch_pad * scratch) { // Metadata - d_string_append(out, "\n"); + d_string_append(out, "\n"); // Identifier HASH_FIND_STR(scratch->meta_hash, "uuid", m); @@ -197,7 +197,7 @@ char * epub_package_document(scratch_pad * scratch) { struct tm * today = localtime(&t); d_string_append_printf(out, "%d-%02d-%02d\n", - today->tm_year + 1900, today->tm_mon + 1, today->tm_mday); + today->tm_year + 1900, today->tm_mon + 1, today->tm_mday); } d_string_append(out, "\n"); @@ -205,13 +205,13 @@ char * epub_package_document(scratch_pad * scratch) { // Manifest d_string_append(out, "\n"); - d_string_append(out, "\n"); - d_string_append(out, "\n"); + d_string_append(out, "\n"); + d_string_append(out, "\n"); d_string_append(out, "\n"); // Spine d_string_append(out, "\n"); - d_string_append(out, ""); + d_string_append(out, ""); d_string_append(out, "\n"); d_string_append(out, "\n"); @@ -260,7 +260,7 @@ void epub_export_nav_entry(DString * out, const char * source, scratch_pad * scr (*counter)--; break; } - + // Increment counter (*counter)++; } @@ -292,7 +292,7 @@ char * epub_nav(mmd_engine * e, scratch_pad * scratch) { print_const("Untitled"); } print_const("\n\n"); - + print_const("\n