From a7fe016b2fedbef3358bb70b3386e3979d68df34 Mon Sep 17 00:00:00 2001
From: wrmr
Date: Fri, 4 Apr 2025 20:25:30 -0500
Subject: add --link option
---
main.c | 76 +++++++++++++++++++++++++++++++++++++++++-------------------------
1 file changed, 47 insertions(+), 29 deletions(-)
diff --git a/main.c b/main.c
index d0f6e04..e749d58 100644
--- a/main.c
+++ b/main.c
@@ -369,13 +369,15 @@ int hvar_calc(Str param, Str *name, Str *val, Str filename) {
void usage(const char *cmd) {
fprintf(stderr, "usage: %s -?\n"
- " %s [-s] [-c FILE] [-t TITLE] [-h NAME:ARG1[,ARG2,ARG3...]] [FILES...]\n"
+ " %s [-s] [[-l] -c FILE] [-t TITLE] [-h NAME:ARG1[,ARG2,ARG3...]] [FILES...]\n"
"\n"
" -? --help show this help text\n"
" -s --standalone prefix with html metadata\n"
" -h --hvar define a css variable (--name) with a random value,\n"
" selected by a hash of the document's title\n"
" -c --css embed the given file within a \n"), m);
}
+
+ if (o->stylesheet.s) {
+ if (o->csslink) {
+ str_cat(&h, S(""), m);
+ } else {
+ FILE *f = fopen(str_to_cstr(o->stylesheet, m), "r/o");
+ if (!f) {
+ str_putf(o->stylesheet, stderr);
+ fprintf(stderr, ": %s\n", strerror(errno));
+ exit(1);
+ }
+ Str css;
+ if (read_all(f, &css, l)) {
+ fprintf(stderr, "failed to read stylesheet: %s\n", strerror(errno));
+ exit(1);
+ }
+ str_cat(&h, S(""), m);
+ }
+ }
return h;
}
@@ -448,11 +462,12 @@ int main(int argc, const char **argv) {
Str param = { 0 };
opts.from_stdin = 1;
- while ((r = arg_get(&a, "?sc:h:t:", ¶m,
+ while ((r = arg_get(&a, "?slc:h:t:", ¶m,
"help", '?',
"standalone", 's',
":title", 't',
":css", 'c',
+ "link", 'l',
":hvar", 'h')) >= ARG_OK) {
Arena reset = scratch;
FILE *f;
@@ -466,6 +481,9 @@ int main(int argc, const char **argv) {
case 'c':
opts.stylesheet = param;
break;
+ case 'l':
+ opts.csslink = 1;
+ break;
case 't':
opts.title = param;
break;
--
cgit 1.4.1-2-gfad0