summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--Makefile6
-rw-r--r--TODO.gn2
-rw-r--r--TODO.html9
-rw-r--r--config.mk3
-rw-r--r--gn.c84
6 files changed, 68 insertions, 37 deletions
diff --git a/.gitignore b/.gitignore
index df09d44..198e6a0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,3 @@
gn
*.pdf
+*.html
diff --git a/Makefile b/Makefile
index ca69f8c..99547a7 100644
--- a/Makefile
+++ b/Makefile
@@ -1,8 +1,12 @@
-CFLAGS=-ggdb
+include config.mk
all: gn
gn: gn.c util.c output.c tokens.h util.h output.h
cc gn.c util.c output.c -o gn ${CFLAGS}
+
+install: gn
+ cp gn ${INSTALLPREFIX}/bin/
+
clean:
rm gn
diff --git a/TODO.gn b/TODO.gn
index 24aa57d..7ef24fb 100644
--- a/TODO.gn
+++ b/TODO.gn
@@ -1,4 +1,4 @@
-* Syntax checking * [2025.02.10] {done}
+* 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}
- Latex?
diff --git a/TODO.html b/TODO.html
deleted file mode 100644
index 86e0356..0000000
--- a/TODO.html
+++ /dev/null
@@ -1,9 +0,0 @@
-<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/config.mk b/config.mk
new file mode 100644
index 0000000..386e91e
--- /dev/null
+++ b/config.mk
@@ -0,0 +1,3 @@
+CFLAGS=-Os -ggdb
+
+INSTALLPREFIX=/usr/local
diff --git a/gn.c b/gn.c
index faae1f3..7405b9a 100644
--- a/gn.c
+++ b/gn.c
@@ -9,10 +9,11 @@
#include "util.h"
typedef enum mode {
- NONE,
- LIST,
- CHECK,
- OUTPUT,
+ NONE = 0,
+ LIST = 1,
+ CHECK = 2,
+ OUTPUT = 4,
+ PRETTY = 8,
} mode;
typedef enum outputformats {
@@ -28,6 +29,8 @@ mode m = NONE;
token tokens[1024];
int tokcount = 0;
+char *header = NULL, *footer = NULL;
+
char *stripwhitespace(char *expr) {
while (isblank(expr[0])) expr++;
@@ -77,18 +80,32 @@ 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) {
+ if (strcmp(argv[i], "-l") == 0) m |= LIST;
+ if (strcmp(argv[i], "-c") == 0) m |= CHECK;
+ if (strcmp(argv[i], "-o") == 0) {
i++;
+ if (!(i < argc)) eprint("expecet additional argument after -o!") ;
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;
+ m |= OUTPUT;
+ }
+ if (strcmp(argv[i], "-p") == 0) m |= PRETTY;
+ if (strcmp(argv[i], "-h") == 0) {
+ i++;
+ if (!(i < argc)) eprint("expecet additional argument after -h!");
+ header = argv[i];
}
+
+ if (strcmp(argv[i], "-f") == 0) {
+ i++;
+ if (!(i < argc)) eprint("expecet additional argument after -f!");
+ footer = argv[i];
+ }
}
+
char file[INT16_MAX];
int i;
char c;
@@ -104,28 +121,43 @@ int main(int argc, char **argv) {
case '[': i = readuntil(file, i, ']', DATE); break;
case '{': i = readuntil(file, i, '}', TODO); break;
case '-': i = readuntil(file, i, '\n', BULLET); break;
+ case ' ':
+ case '\n':
+ case '\t':
+ break;
+ default:
+ eprint("unknown char found!");
}
}
- switch (m) {
- case LIST:
- 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;
- }
+ if (header != NULL) printf("%s\n", header);
+
+ if ((m & LIST) == LIST) {
+ formatcheck();
+ for (int i = 0; i < tokcount; i++) {
+ if (tokens[i].type == HEADING) {
+ if ((m & PRETTY) == PRETTY)
+ printf("\e[1m%s\e[0m \e[4m%s\e[0m \e[2m%s\e[0m\n", tokens[i].data, tokens[i+1].data, tokens[i+2].data);
+ else
+ printf("%s %s %s\n", tokens[i].data, tokens[i+1].data, tokens[i+2].data);
+ i += 2;
}
-
- case NONE: return 0;
+ }
+ }
+ if ((m & CHECK) == CHECK) {
+ formatcheck();
+ }
+ if ((m & OUTPUT) == 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;
+ }
+ }
}
+
+ if (footer != NULL) printf("%s\n", footer);
return 0;
}