summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile4
-rw-r--r--TODO.gn4
-rw-r--r--TODO.html9
-rw-r--r--gn.c78
-rw-r--r--output.c39
-rw-r--r--output.h5
-rw-r--r--test.gn10
-rw-r--r--tmp.pdfbin0 -> 11706 bytes
-rw-r--r--tokens.h16
-rw-r--r--util.c7
-rw-r--r--util.h1
11 files changed, 133 insertions, 40 deletions
diff --git a/Makefile b/Makefile
index 56da911..ca69f8c 100644
--- a/Makefile
+++ b/Makefile
@@ -2,7 +2,7 @@ CFLAGS=-ggdb
all: gn
-gn: gn.c
- cc gn.c -o gn ${CFLAGS}
+gn: gn.c util.c output.c tokens.h util.h output.h
+ cc gn.c util.c output.c -o gn ${CFLAGS}
clean:
rm gn
diff --git a/TODO.gn b/TODO.gn
index 3292ba5..24aa57d 100644
--- a/TODO.gn
+++ b/TODO.gn
@@ -1,5 +1,5 @@
-* Syntax checking * {2025.02.10} {todo}
+* Syntax checking * [2025.02.10] {done}
- loop through tokens and find if they are in the right order
-* More output formats * {2025.02.10} {todo}
+* More output formats * [2025.02.10] {todo}
- Latex?
- Groff?
diff --git a/TODO.html b/TODO.html
new file mode 100644
index 0000000..86e0356
--- /dev/null
+++ b/TODO.html
@@ -0,0 +1,9 @@
+<h1>Syntax checking</h1>
+<h2>2025.02.10</h2>
+<h3>done</h3>
+<p>loop through tokens and find if they are in the right order</p>
+<h1>More output formats</h1>
+<h2>2025.02.10</h2>
+<h3>todo</h3>
+<p>Latex?</p>
+<p>Groff?</p>
diff --git a/gn.c b/gn.c
index 58b5296..faae1f3 100644
--- a/gn.c
+++ b/gn.c
@@ -4,43 +4,29 @@
#include <string.h>
#include <stdlib.h>
+#include "tokens.h"
+#include "output.h"
+#include "util.h"
+
typedef enum mode {
NONE,
LIST,
+ CHECK,
+ OUTPUT,
} mode;
-typedef enum types {
- HEADING,
- DATE,
- TODO,
- BULLET,
-} types;
+typedef enum outputformats {
+ GOATNOTE,
+ HTML,
+ GROFF,
+} outputformats;
-typedef struct token {
- char data[256];
- types type;
-} token;
+outputformats outputformat;
mode m = NONE;
token tokens[1024];
int tokcount = 0;
-
-void eprint(char *msg) {
- fprintf(stderr, "error: %s\n", msg);
- exit(1);
-}
-
-void printashtml(token t) {
- char *start, *end;
- switch (t.type) {
- case HEADING: start = "<h1>"; end = "</h1>"; break;
- case DATE: start = "<h2>"; end = "</h2>"; break;
- case TODO: start = "<h3>"; end = "</h3>"; break;
- case BULLET: start = "<p>"; end = "</p>"; break;
- }
- printf("%s%s%s\n", start, t.data, end);
-}
char *stripwhitespace(char *expr) {
while (isblank(expr[0])) expr++;
@@ -50,6 +36,24 @@ char *stripwhitespace(char *expr) {
return expr;
}
+void formatcheck() {
+ types prev = NIL;
+ for (int i = 0; i < tokcount; i++) {
+ switch (prev) {
+ case NIL:
+ if (tokens[i].type != HEADING) eprint("Expected heading!");
+ break;
+ case HEADING:
+ if (tokens[i].type != DATE) eprint("Expected date");
+ break;
+ case DATE:
+ if (tokens[i].type != TODO) eprint("Expected todo|done marker");
+ break;
+ }
+ prev = tokens[i].type;
+ }
+}
+
int readuntil(char *file, int off, char end, types t) {
int j = 0;
char tok[256];
@@ -74,6 +78,15 @@ int readuntil(char *file, int off, char end, types t) {
int main(int argc, char **argv) {
for (int i = 0; i < argc && argc != 1; i++) {
if (strcmp(argv[i], "-l") == 0) m = LIST;
+ else if (strcmp(argv[i], "-c") == 0) m = CHECK;
+ else if (strcmp(argv[i], "-o") == 0) {
+ i++;
+ if (strcmp(argv[i], "goatnote") == 0) outputformat = GOATNOTE;
+ else if (strcmp(argv[i], "html") == 0) outputformat = HTML;
+ else if (strcmp(argv[i], "groff") == 0) outputformat = GROFF;
+
+ m = OUTPUT;
+ }
}
char file[INT16_MAX];
@@ -99,6 +112,19 @@ int main(int argc, char **argv) {
for (int i = 0; i < tokcount; i++)
if (tokens[i].type == HEADING) printf("%s\n", tokens[i].data);
break;
+ case CHECK:
+ formatcheck();
+ break;
+ case OUTPUT:
+ formatcheck();
+ for (int i = 0; i < tokcount; i++){
+ switch (outputformat) {
+ case HTML: printashtml(tokens[i]); break;
+ case GOATNOTE: printasgn(tokens[i]); break;
+ case GROFF: printasgroff(tokens[i]); break;
+ }
+ }
+
case NONE: return 0;
}
return 0;
diff --git a/output.c b/output.c
new file mode 100644
index 0000000..6f9b53b
--- /dev/null
+++ b/output.c
@@ -0,0 +1,39 @@
+#include <stdio.h>
+
+#include "tokens.h"
+
+extern token tokens[1024];
+extern int tokcount;
+
+void printashtml(token t) {
+ char *start, *end;
+ switch (t.type) {
+ case HEADING: start = "<h1>"; end = "</h1>\n"; break;
+ case DATE: start = "<h2>"; end = "</h2>\n"; break;
+ case TODO: start = "<h3>"; end = "</h3>\n"; break;
+ case BULLET: start = "<p>"; end = "</p>\n"; break;
+ }
+ printf("%s%s%s", start, t.data, end);
+}
+
+void printasgn(token t) {
+ char *start, *end;
+ switch (t.type) {
+ case HEADING: start = "* "; end = " *"; break;
+ case DATE: start = " ["; end = "]"; break;
+ case TODO: start = " {"; end = "}\n"; break;
+ case BULLET: start = "- "; end = "\n"; break;
+ }
+ printf("%s%s%s", start, t.data, end);
+}
+
+void printasgroff(token t) {
+ char *start, *end;
+ switch (t.type) {
+ case HEADING: start = ".NH\n"; end = "\n"; break;
+ case DATE: start = ".LP\n"; end = "\n"; break;
+ case TODO: start = ".LP\n"; end = "\n"; break;
+ case BULLET: start = ".PP\n"; end = "\n"; break;
+ }
+ printf("%s%s%s", start, t.data, end);
+}
diff --git a/output.h b/output.h
new file mode 100644
index 0000000..734968b
--- /dev/null
+++ b/output.h
@@ -0,0 +1,5 @@
+#include "tokens.h"
+
+void printashtml(token t);
+void printasgn(token t);
+void printasgroff(token t);
diff --git a/test.gn b/test.gn
deleted file mode 100644
index 054d660..0000000
--- a/test.gn
+++ /dev/null
@@ -1,10 +0,0 @@
-* my awsome note * [2025.02.09] {done}
-- sub point
-- sub point two
-* my awsome note * [2025.02.09] {done}
-* my awsome note * [2025.02.09] {done}
-* my awsome note * [2025.02.09] {done}
-* my awsome note * [2025.02.09] {done}
-* my awsome note * [2025.02.09] {done}
-* my awsome note * [2025.02.09] {done}
-* my awsome note * [2025.02.09] {done}
diff --git a/tmp.pdf b/tmp.pdf
new file mode 100644
index 0000000..46e280b
--- /dev/null
+++ b/tmp.pdf
Binary files differ
diff --git a/tokens.h b/tokens.h
new file mode 100644
index 0000000..c3305fc
--- /dev/null
+++ b/tokens.h
@@ -0,0 +1,16 @@
+#ifndef __TOKENS_H
+#define __TOKENS_H
+
+typedef enum types {
+ NIL,
+ HEADING,
+ DATE,
+ TODO,
+ BULLET,
+} types;
+
+typedef struct token {
+ char data[256];
+ types type;
+} token;
+#endif
diff --git a/util.c b/util.c
new file mode 100644
index 0000000..a46f853
--- /dev/null
+++ b/util.c
@@ -0,0 +1,7 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+void eprint(char *msg) {
+ fprintf(stderr, "error: %s\n", msg);
+ exit(1);
+}
diff --git a/util.h b/util.h
new file mode 100644
index 0000000..11961cc
--- /dev/null
+++ b/util.h
@@ -0,0 +1 @@
+void eprint(char *msg);