retro-unu: add some comments
FossilOrigin-Name: 29186ae8f2cc4cdcaa3c66458d5fe46868e389726dc4e0576acff420ec037dd3
This commit is contained in:
parent
3c4343ce41
commit
4fd7671e2d
2 changed files with 24 additions and 1 deletions
|
@ -1,2 +1,5 @@
|
|||
# RETRO 2021.1
|
||||
|
||||
## Toolchain
|
||||
|
||||
- retro-unu now supports user defined code and test block delimiters
|
||||
|
|
|
@ -16,9 +16,10 @@
|
|||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
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;
|
||||
|
|
Loading…
Reference in a new issue