diff options
Diffstat (limited to 'gmitohtml.c')
-rw-r--r-- | gmitohtml.c | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/gmitohtml.c b/gmitohtml.c new file mode 100644 index 0000000..611a96e --- /dev/null +++ b/gmitohtml.c @@ -0,0 +1,68 @@ +#include <sys/types.h> +#include <sys/stat.h> + +#include <err.h> +#include <fcntl.h> +#include <stdio.h> +#include <string.h> +#include <unistd.h> + +#include <gemtext.h> + +#define HEADER "<!DOCTYPE html><html><body>" +#define FOOTER "</body></html>" + +int +main(int argc, char *argv[]) +{ + int ch; + int infd; + int outfd; + char *in; + char *out; + struct gemtext **list; + + in = "/dev/stdin"; + out = "/dev/stdout"; + + while ((ch = getopt(argc, argv, "i:o:h")) != -1) { + switch (ch) { + case 'i': + in = optarg; + break; + case 'o': + out = optarg; + break; + case 'h': + fprintf(stderr, "Usage: %s [-h] [-i input] [-o output]\n", argv[0]); + return 0; + default: + fprintf(stderr, "Usage: %s [-h] [-i input] [-o output]\n", argv[0]); + return 1; + } + } + + infd = open(in, O_RDONLY); + if (infd == -1) + err(1, "open"); + + outfd = open(out, O_WRONLY|O_CREAT|O_TRUNC); + if (outfd == -1) + err(1, "open"); + + list = gemtext_list_decode_fd(infd); + if (list == NULL) + err(1, "gemtext_list_decode_fd"); + close(infd); + + if (write(outfd, HEADER, strlen(HEADER)) == -1) + err(1, "write"); + if (gemtext_list_encode_to_html_fd(list, outfd) == -1) + err(1, "gemtext_list_encode_to_html_fd"); + if (write(outfd, FOOTER, strlen(FOOTER)) == -1) + err(1, "write"); + + close(outfd); + gemtext_list_free(list); + return 0; +} |