diff options
author | WormHeamer | 2025-03-08 17:47:47 -0500 |
---|---|---|
committer | WormHeamer | 2025-03-08 17:47:47 -0500 |
commit | fe358325bd443a076732259bd2a50c97f12d7602 (patch) | |
tree | 24879dcbda4643aa9a1756a6cda5e79fbd8a5f2b /main.c | |
parent | eba555fed78e93743ab9381fb72d6bd751b936e4 (diff) |
support giving - argument to read from stdin
Diffstat (limited to 'main.c')
-rw-r--r-- | main.c | 36 |
1 files changed, 27 insertions, 9 deletions
diff --git a/main.c b/main.c index 8dc8a6e..17d0c7c 100644 --- a/main.c +++ b/main.c @@ -102,6 +102,8 @@ typedef enum { } LineMode; LineMode lm_chg(LineMode from, LineMode to, Str *out, Arena *a) { +#undef S +#define S(s) {s,sizeof(s)-1} static Str op[] = { [LINE_BLANK] = S(""), [LINE_PARA] = S("<p>"), @@ -141,6 +143,8 @@ LineMode lm_chg(LineMode from, LineMode to, Str *out, Arena *a) { [LINE_CODE] = S("\n"), [LINE_BQUOT] = S("<br>\n"), }; +#undef S +#define S(s) (Str){s,sizeof(s)-1} if (from == to) { str_cat(out, cont[from], a); } else { @@ -317,15 +321,24 @@ int main(int argc, const char **argv) { opts.hvarv[opts.hvarc++] = param; break; default: - opts.from_stdin = 0; - f = fopen(str_to_cstr(param, &scratch), "r/o"); - if (wdoc(f, &doc, &perm, &scratch)) { - fwrite(param.s, 1, param.n, stderr); - fprintf(stderr, ": %s\n", strerror(errno)); - return 1; + if (str_eql(param, S("-"))) { + if (wdoc(stdin, &doc, &perm, &scratch)) { + fprintf(stderr, "error reading document" + " from stdin: %s\n", + strerror(errno)); + return 1; + } + } else { + opts.from_stdin = 0; + f = fopen(str_to_cstr(param, &scratch), "r/o"); + if (wdoc(f, &doc, &perm, &scratch)) { + fwrite(param.s, 1, param.n, stderr); + fprintf(stderr, ": %s\n", strerror(errno)); + return 1; + } + fclose(f); + break; } - fclose(f); - break; } scratch = reset; } @@ -344,7 +357,12 @@ int main(int argc, const char **argv) { } if (opts.from_stdin) { - wdoc(stdin, &doc, &perm, &scratch); + if (wdoc(stdin, &doc, &perm, &scratch)) { + fprintf(stderr, "error reading document from stdin: " + "%s\n", strerror(errno)); + return 1; + + } } if (doc && opts.standalone) { |