diff --git a/parsers/markdown.c b/parsers/markdown.c index 75a0a59f13..38e6122ef6 100644 --- a/parsers/markdown.c +++ b/parsers/markdown.c @@ -70,20 +70,20 @@ static NestingLevels *nestingLevels = NULL; * FUNCTION DEFINITIONS */ -static NestingLevel *getNestingLevel(const int kind, unsigned long adjustment_when_pop) +static NestingLevel *getNestingLevel (const int kind, unsigned long adjustmentWhenPop) { NestingLevel *nl; tagEntryInfo *e; - unsigned long line = getInputLineNumber(); + unsigned long line = getInputLineNumber (); - line = (line > adjustment_when_pop)? (line - adjustment_when_pop): 0; + line = (line > adjustmentWhenPop)? (line - adjustmentWhenPop): 0; while (1) { - nl = nestingLevelsGetCurrent(nestingLevels); + nl = nestingLevelsGetCurrent (nestingLevels); e = getEntryOfNestingLevel (nl); if ((nl && (e == NULL)) || (e && (e->kindIndex >= kind))) - nestingLevelsPopFull(nestingLevels, HT_UINT_TO_PTR((unsigned int)line)); + nestingLevelsPopFull (nestingLevels, HT_UINT_TO_PTR ((unsigned int)line)); else break; } @@ -91,27 +91,27 @@ static NestingLevel *getNestingLevel(const int kind, unsigned long adjustment_wh } -static int makeMarkdownTag (const vString* const name, const int kind, const bool two_line) +static int makeMarkdownTag (const vString* const name, const int kind, const bool twoLine) { int r = CORK_NIL; if (vStringLength (name) > 0) { - const NestingLevel *const nl = getNestingLevel(kind, two_line? 2: 1); + const NestingLevel *const nl = getNestingLevel (kind, twoLine? 2: 1); tagEntryInfo *parent = getEntryOfNestingLevel (nl); tagEntryInfo e; initTagEntry (&e, vStringValue (name), kind); - if (two_line) + if (twoLine) { /* we want the line before the '---' underline chars */ - const unsigned long line = getInputLineNumber(); + const unsigned long line = getInputLineNumber (); Assert (line > 0); if (line > 0) { e.lineNumber--; - e.filePosition = getInputFilePositionForLine(line - 1); + e.filePosition = getInputFilePositionForLine (line - 1); } } @@ -126,47 +126,47 @@ static int makeMarkdownTag (const vString* const name, const int kind, const boo static int makeSectionMarkdownTag (const vString* const name, const int kind, const char *marker) { - int r = makeMarkdownTag(name, kind, marker[0] != '#'); + int r = makeMarkdownTag (name, kind, marker[0] != '#'); attachParserFieldToCorkEntry (r, MarkdownFields [F_MARKER].ftype, marker); - nestingLevelsPush(nestingLevels, r); + nestingLevelsPush (nestingLevels, r); return r; } -static vString *get_heading(const int kind, const unsigned char *line, - const int line_len, bool *delimited) +static vString *getHeading (const int kind, const unsigned char *line, + const int lineLen, bool *delimited) { int pos = 0; int start = kind + 1; - int end = line_len - 1; - vString *name = vStringNew(); + int end = lineLen - 1; + vString *name = vStringNew (); Assert (kind >= 0 && kind < K_SECTION_COUNT); - Assert (line_len > start); + Assert (lineLen > start); *delimited = false; - while (isspace(line[pos])) ++pos; + while (isspace (line[pos])) ++pos; while (line[end] == line[pos] && end - 1 >= 0 && line[end - 1] != '\\') { --end; *delimited = true; } - while (isspace(line[start])) ++start; - while (isspace(line[end])) --end; + while (isspace (line[start])) ++start; + while (isspace (line[end])) --end; if (start <= end) - vStringNCatS(name, (const char*)(&(line[start])), end - start + 1); + vStringNCatS (name, (const char*)(&(line[start])), end - start + 1); return name; } -static int get_first_char_pos(const unsigned char *line, int line_len, bool *indented) +static int getFirstCharPos (const unsigned char *line, int lineLen, bool *indented) { int indent = 0; int i; - for (i = 0; i < line_len && isspace(line[i]); i++) + for (i = 0; i < lineLen && isspace (line[i]); i++) indent += line[i] == '\t' ? 4 : 1; *indented = indent >= 4; return i; @@ -178,30 +178,30 @@ static void fillEndField (NestingLevel *nl, void *ctxData) tagEntryInfo *e = getEntryOfNestingLevel (nl); if (e) { - unsigned long line = (unsigned long)(HT_PTR_TO_UINT(ctxData)); + unsigned long line = (unsigned long)(HT_PTR_TO_UINT (ctxData)); e->extensionFields.endLine = line; } } -static void findMarkdownTags(void) +static void findMarkdownTags (void) { - vString *prev_line = vStringNew(); - vString *codeLang = vStringNew(); + vString *prevLine = vStringNew (); + vString *codeLang = vStringNew (); const unsigned char *line; - char in_code_char = 0; + char inCodeChar = 0; long startSourceLineNumber = 0; long startLineNumber = 0; bool inPreambule = false; - nestingLevels = nestingLevelsNewFull(0, fillEndField); + nestingLevels = nestingLevelsNewFull (0, fillEndField); - while ((line = readLineFromInputFile()) != NULL) + while ((line = readLineFromInputFile ()) != NULL) { - int line_len = strlen((const char*) line); - bool line_processed = false; + int lineLen = strlen ((const char*) line); + bool lineProcessed = false; bool indented; - int pos = get_first_char_pos(line, line_len, &indented); + int pos = getFirstCharPos (line, lineLen, &indented); int lineNum = getInputLineNumber (); if (lineNum == 1 || inPreambule) @@ -217,97 +217,97 @@ static void findMarkdownTags(void) if (line[pos] == '`' || line[pos] == '~') { char c = line[pos]; - char other_c = c == '`' ? '~' : '`'; - int n_same; - for (n_same = pos + 1; line[n_same] == line[pos]; ++n_same); + char otherC = c == '`' ? '~' : '`'; + int nSame; + for (nSame = pos + 1; line[nSame] == line[pos]; ++nSame); - if (in_code_char != other_c && n_same >= 3) + if (inCodeChar != otherC && nSame >= 3) { - in_code_char = in_code_char ? 0 : c; - if (in_code_char == c && strstr((const char *)(line + pos + n_same), "```") != NULL) - in_code_char = 0; - else if (in_code_char) + inCodeChar = inCodeChar ? 0 : c; + if (inCodeChar == c && strstr ((const char *)(line + pos + nSame), "```") != NULL) + inCodeChar = 0; + else if (inCodeChar) { startSourceLineNumber = getSourceLineNumber (); startLineNumber = getInputLineNumber (); - vStringClear(codeLang); - vStringCatS(codeLang, (const char *)(line + pos + n_same)); - vStringStripLeading(codeLang); - vStringStripTrailing(codeLang); + vStringClear (codeLang); + vStringCatS (codeLang, (const char *)(line + pos + nSame)); + vStringStripLeading (codeLang); + vStringStripTrailing (codeLang); } else { long endLineNumber = getInputLineNumber () - 1; if (codeLang->size > 0) - makePromise (vStringValue(codeLang), startLineNumber, 0, + makePromise (vStringValue (codeLang), startLineNumber, 0, endLineNumber, 0, startSourceLineNumber); } - line_processed = true; + lineProcessed = true; } } /* code block */ - if (in_code_char) - line_processed = true; + if (inCodeChar) + lineProcessed = true; /* code block using indent */ else if (indented) - line_processed = true; + lineProcessed = true; /* if it's a title underline, or a delimited block marking character */ else if (line[pos] == '=' || line[pos] == '-' || line[pos] == '#' || line[pos] == '>') { - int n_same; - for (n_same = pos + 1; line[n_same] == line[pos]; ++n_same); + int nSame; + for (nSame = pos + 1; line[nSame] == line[pos]; ++nSame); /* quote */ if (line[pos] == '>') - ; /* just to make sure line_processed = true so it won't be in a heading */ + ; /* just to make sure lineProcessed = true so it won't be in a heading */ /* is it a two line title */ else if (line[pos] == '=' || line[pos] == '-') { char marker[2] = { line[pos], '\0' }; int kind = line[pos] == '=' ? K_CHAPTER : K_SECTION; - bool whitespace_terminated = true; + bool whitespaceTerminated = true; - for (int i = pos + n_same; i < line_len; i++) + for (int i = pos + nSame; i < lineLen; i++) { - if (!isspace(line[i])) + if (!isspace (line[i])) { - whitespace_terminated = false; + whitespaceTerminated = false; break; } } - vStringStripLeading(prev_line); - vStringStripTrailing(prev_line); - if (whitespace_terminated && vStringLength(prev_line) > 0) - makeSectionMarkdownTag(prev_line, kind, marker); + vStringStripLeading (prevLine); + vStringStripTrailing (prevLine); + if (whitespaceTerminated && vStringLength (prevLine) > 0) + makeSectionMarkdownTag (prevLine, kind, marker); } /* otherwise is it a one line title */ - else if (line[pos] == '#' && n_same <= K_SECTION_COUNT && isspace(line[n_same])) + else if (line[pos] == '#' && nSame <= K_SECTION_COUNT && isspace (line[nSame])) { - int kind = n_same - 1; + int kind = nSame - 1; bool delimited = false; - vString *name = get_heading(kind, line, line_len, &delimited); - if (vStringLength(name) > 0) - makeSectionMarkdownTag(name, kind, delimited ? "##" : "#"); - vStringDelete(name); + vString *name = getHeading (kind, line, lineLen, &delimited); + if (vStringLength (name) > 0) + makeSectionMarkdownTag (name, kind, delimited ? "##" : "#"); + vStringDelete (name); } - line_processed = true; + lineProcessed = true; } - vStringClear(prev_line); - if (!line_processed) - vStringCatS(prev_line, (const char*) line); + vStringClear (prevLine); + if (!lineProcessed) + vStringCatS (prevLine, (const char*) line); } - vStringDelete(prev_line); - vStringDelete(codeLang); + vStringDelete (prevLine); + vStringDelete (codeLang); { unsigned int line = (unsigned int)getInputLineNumber (); - nestingLevelsFreeFull(nestingLevels, HT_UINT_TO_PTR(line)); + nestingLevelsFreeFull (nestingLevels, HT_UINT_TO_PTR (line)); } } @@ -320,9 +320,9 @@ extern parserDefinition* MarkdownParser (void) def->extensions = extensions; def->useCork = CORK_QUEUE; def->kindTable = MarkdownKinds; - def->kindCount = ARRAY_SIZE(MarkdownKinds); + def->kindCount = ARRAY_SIZE (MarkdownKinds); def->fieldTable = MarkdownFields; - def->fieldCount = ARRAY_SIZE(MarkdownFields); + def->fieldCount = ARRAY_SIZE (MarkdownFields); def->defaultScopeSeparator = "\"\""; def->parser = findMarkdownTags;