summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--TODO.gn2
-rw-r--r--gn.c28
-rw-r--r--output.c11
-rw-r--r--output.h1
4 files changed, 33 insertions, 9 deletions
diff --git a/TODO.gn b/TODO.gn
index 7ef24fb..78ef2c1 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/gn.c b/gn.c
index 7405b9a..b56d934 100644
--- a/gn.c
+++ b/gn.c
@@ -20,6 +20,7 @@ typedef enum outputformats {
GOATNOTE,
HTML,
GROFF,
+ TEXT,
} outputformats;
outputformats outputformat;
@@ -78,31 +79,41 @@ int readuntil(char *file, int off, char end, types t) {
return off;
}
+void usage() {
+ fprintf(stderr,
+ "usage: gn [-l -c -o format -p -H header -F footer -h] < note.gn\n"
+ );
+ exit(1);
+}
+
int main(int argc, char **argv) {
- for (int i = 0; i < argc && argc != 1; i++) {
+ for (int i = 1; i < argc && argc != 1; i++) {
if (strcmp(argv[i], "-l") == 0) m |= LIST;
- if (strcmp(argv[i], "-c") == 0) m |= CHECK;
- if (strcmp(argv[i], "-o") == 0) {
+ else if (strcmp(argv[i], "-c") == 0) m |= CHECK;
+ else 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;
+ else if (strcmp(argv[i], "text") == 0) outputformat = TEXT;
m |= OUTPUT;
}
- if (strcmp(argv[i], "-p") == 0) m |= PRETTY;
- if (strcmp(argv[i], "-h") == 0) {
+ else if (strcmp(argv[i], "-p") == 0) m |= PRETTY;
+ else if (strcmp(argv[i], "-H") == 0) {
i++;
- if (!(i < argc)) eprint("expecet additional argument after -h!");
+ if (!(i < argc)) eprint("expecet additional argument after -H!");
header = argv[i];
}
- if (strcmp(argv[i], "-f") == 0) {
+ else if (strcmp(argv[i], "-F") == 0) {
i++;
- if (!(i < argc)) eprint("expecet additional argument after -f!");
+ if (!(i < argc)) eprint("expecet additional argument after -F!");
footer = argv[i];
}
+ else if (strcmp(argv[i], "-h") == 0) usage();
+ else usage();
}
@@ -154,6 +165,7 @@ int main(int argc, char **argv) {
case HTML: printashtml(tokens[i]); break;
case GOATNOTE: printasgn(tokens[i]); break;
case GROFF: printasgroff(tokens[i]); break;
+ case TEXT: printastext(tokens[i]); break;
}
}
}
diff --git a/output.c b/output.c
index 6f9b53b..fc7eb28 100644
--- a/output.c
+++ b/output.c
@@ -37,3 +37,14 @@ void printasgroff(token t) {
}
printf("%s%s%s", start, t.data, end);
}
+
+void printastext(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);
+}
diff --git a/output.h b/output.h
index 734968b..f33636b 100644
--- a/output.h
+++ b/output.h
@@ -3,3 +3,4 @@
void printashtml(token t);
void printasgn(token t);
void printasgroff(token t);
+void printastext(token t);