Add list parsing

This commit is contained in:
Romain de Laage 2021-02-12 18:44:52 +01:00
parent 65cf0357f2
commit 221ec20578
Signed by: rdelaage
GPG Key ID: 534845FADDF0C329
1 changed files with 65 additions and 11 deletions

View File

@ -10,7 +10,8 @@ void addH2 (const char *line);
void addH3 (const char *line);
void addLink (const char *url, const char *text);
void addCode (const char *meta, const char *code);
void addQuote (const char *line);
void addQuote (const char *text);
void addUList (const char *text);
// general functions
@ -115,21 +116,68 @@ parseFile (char *path)
do
{
if (fgets(codeline, 4096, fileToParse) == NULL)
if (fgets (codeline, 4096, fileToParse) == NULL)
break;
size = strlen(codeline);
size = strlen (codeline);
if (size < 3 || codeline[0] != '`' || codeline[1] != '`' || codeline[2] != '`')
strcat(code, codeline);
strcat (code, codeline);
}
while (codeline[0] != '`' || codeline[1] != '`' || codeline[2] != '`');
// Remove tailing '\n' for both meta and code
size = strlen(code);
size = strlen (code);
code[size - 1] = '\0';
addCode (line + 3, code);
}
else if (size > 1 && line[0] == '*')
{
char text[4096] = "";
do
{
char buffer[4096] = "";
int linePos = 1;
int bufferPos;
strcat (buffer, "");
bufferPos = strlen (buffer);
buffer[bufferPos++] = ' ';
// remove heading space
while (line[linePos] == ' ' && linePos < size)
linePos++;
while (line[linePos] != '\n' && linePos < size)
{
buffer[bufferPos] = line[linePos];
linePos++;
bufferPos++;
}
buffer[bufferPos] = '\n';
buffer[bufferPos + 1] = '\0';
strcat (text, buffer);
if (fgets (line, 4096, fileToParse) == NULL)
break;
size = strlen (line);
}
while (line[0] == '*');
//we seek the previous line
if (! feof (fileToParse))
fseek (fileToParse, -size, SEEK_CUR);
// Remove tailing '\n' for both meta and code
size = strlen(text);
text[size - 1] = '\0';
addUList (text);
}
else if (size > 1 && line[0] == '>')
{
int i = 1;
@ -168,21 +216,21 @@ main (int argc,
}
void
addH1 (const char *text)
addH1 (const char *line)
{
printf ("h1 {\n%s\n}\n", text);
printf ("h1 {\n%s\n}\n", line);
}
void
addH2 (const char *text)
addH2 (const char *line)
{
printf ("h2 {\n%s\n}\n", text);
printf ("h2 {\n%s\n}\n", line);
}
void
addH3 (const char *text)
addH3 (const char *line)
{
printf ("h3 {\n%s\n}\n", text);
printf ("h3 {\n%s\n}\n", line);
}
void
@ -207,4 +255,10 @@ addQuote (const char *text)
printf ("quote {\n%s\n}\n", text);
}
void
addUList (const char *text)
{
printf ("ulist {\n%s\n}\n", text);
}
#endif