From 4fd7671e2d194ac982c8920c8d1af0a9ac4bda6b Mon Sep 17 00:00:00 2001 From: crc Date: Fri, 16 Oct 2020 13:52:16 +0000 Subject: [PATCH] retro-unu: add some comments FossilOrigin-Name: 29186ae8f2cc4cdcaa3c66458d5fe46868e389726dc4e0576acff420ec037dd3 --- RELEASE-NOTES | 3 +++ tools/retro-unu.c | 22 +++++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 579b5cc..19adc63 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -1,2 +1,5 @@ # RETRO 2021.1 +## Toolchain + +- retro-unu now supports user defined code and test block delimiters diff --git a/tools/retro-unu.c b/tools/retro-unu.c index 5ec0e20..b3bbadf 100644 --- a/tools/retro-unu.c +++ b/tools/retro-unu.c @@ -16,9 +16,10 @@ #include #include +typedef void (*Handler)(char *); + char code_start[33], code_end[33], test_start[33], test_end[33]; -typedef void (*Handler)(char *); void read_line(FILE *file, char *line_buffer) { int ch = getc(file); @@ -31,6 +32,11 @@ void read_line(FILE *file, char *line_buffer) { line_buffer[count] = '\0'; } + +/* Check to see if a line is a fence boundary. + This will check code blocks in all cases, and test blocks + if tests_enabled is set to a non-zero value. */ + int fence_boundary(char *buffer, int tests_enabled) { int flag = 1; if (strcmp(buffer, code_start) == 0) { flag = -1; } @@ -41,6 +47,14 @@ int fence_boundary(char *buffer, int tests_enabled) { return flag; } + +/* The actual guts of this are handled here. Pass in + a file name, a flag to indicate if you want to also + extract tests, and a Handler function pointer. The + Handler will be called once for each line in a block, + with the line being passed as a character array + pointer. */ + void unu(char *fname, int tests_enabled, Handler handler) { int inBlock = 0; char buffer[4096]; @@ -67,14 +81,20 @@ void unu(char *fname, int tests_enabled, Handler handler) { fclose(fp); } + +/* The default behavior for Unu is to display the line */ + void display(char *buffer) { printf("%s\n", buffer); } + +/* Just a readabilty aid for the command line processing */ int arg_is(char *arg, char *value) { return (strcmp(arg, value) == 0); } + int main(int argc, char **argv) { int tests = 0; int i = 1;