summary refs log tree commit diff
path: root/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'main.c')
-rw-r--r--main.c36
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) {