cld-ssg

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 93f949d3e9379c48debcc59e440f75d1d39f446a
parent bc5dd10526f6a333107b3098a45d4df0219c15c9
Author: Christopher Ray Langford <chris@hellocld.com>
Date:   Wed,  4 Sep 2019 21:51:14 -0400

Directory scanning and filtering for .md files implemented

Diffstat:
MMakefile | 2+-
Mmain.c | 29+++++++++++++++++++++++++++++
Atestdir/123 | 0
Atestdir/201909042150-boop.md | 0
Atestdir/201909042151-hello.md | 0
Atestdir/thing | 0
6 files changed, 30 insertions(+), 1 deletion(-)

diff --git a/Makefile b/Makefile @@ -1,5 +1,5 @@ CC = gcc -CFLAGS = -Wall -pedantic +CFLAGS = -g -Wall -pedantic CLIBS = -lcmark default: dirs main.c diff --git a/main.c b/main.c @@ -1,14 +1,43 @@ #include "cmark.h" +#include <dirent.h> #include <stdlib.h> #include <string.h> +int md_filter(const struct dirent *); + int main() { + + printf("*** cmark testing ***\n\n"); char *md = "This is a *test* of some `markdown`"; char *html = cmark_markdown_to_html(md, strlen(md), CMARK_OPT_DEFAULT); printf("%s\n", html); free(html); + printf("*** dirent testing ***\n\n"); + DIR *testdir = opendir("./testdir"); + struct dirent *tde; + while((tde = readdir(testdir)) != NULL) + printf("%ld\t%s\n", tde->d_ino, tde->d_name); + printf("\n\n"); + struct dirent **files; + int filecount = 0; + filecount = scandir("./testdir", &files, md_filter, alphasort); + printf("Found %d files\n", filecount); + + for( ; filecount > 0 ; filecount--) { + printf("%ld\t%s\n", (*files)->d_ino, (*files)->d_name); + files++; + } + return 0; +} + +/* returns non-zero if filename ends with ".md" */ +int md_filter(const struct dirent *d) +{ + /* if d->d_name doesn't end with ".md" we don't want it */ + if(strstr(d->d_name, ".md") != NULL) + return 1; return 0; } diff --git a/testdir/123 b/testdir/123 diff --git a/testdir/201909042150-boop.md b/testdir/201909042150-boop.md diff --git a/testdir/201909042151-hello.md b/testdir/201909042151-hello.md diff --git a/testdir/thing b/testdir/thing