summaryrefslogtreecommitdiff
path: root/xC.c
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2023-05-22 04:35:00 +0200
committerPřemysl Eric Janouch <p@janouch.name>2023-05-22 04:44:01 +0200
commit3f9a365d366e8fed4f2d02bbb6f1a4e117593431 (patch)
treec5f6170f3a32726874d94b831b596a746cffec09 /xC.c
parent9932b35a1038d5ec945e7af2a95240dff7ca64d1 (diff)
downloadxK-3f9a365d366e8fed4f2d02bbb6f1a4e117593431.tar.gz
xK-3f9a365d366e8fed4f2d02bbb6f1a4e117593431.tar.xz
xK-3f9a365d366e8fed4f2d02bbb6f1a4e117593431.zip
xC: improve the --format mode
Avoid having formatting spill over the rest of the line, by placing the automatic formatting reset before newlines. Also handle longer lines properly.
Diffstat (limited to 'xC.c')
-rw-r--r--xC.c21
1 files changed, 18 insertions, 3 deletions
diff --git a/xC.c b/xC.c
index 200d159..fdf1325 100644
--- a/xC.c
+++ b/xC.c
@@ -16004,14 +16004,29 @@ show_logo (struct app_context *ctx)
static void
format_input_and_die (struct app_context *ctx)
{
- char buf[513];
- while (fgets (buf, sizeof buf, stdin))
+ // XXX: it might make sense to allow for redirection, using FLUSH_OPT_RAW
+ struct str s = str_make ();
+ int c = 0;
+ while ((c = fgetc (stdin)) != EOF)
{
+ if (c != '\n')
+ {
+ str_append_c (&s, c);
+ continue;
+ }
+
struct formatter f = formatter_make (ctx, NULL);
- formatter_add (&f, "#m", buf);
+ formatter_add (&f, "#m\n", s.str);
formatter_flush (&f, stdout, FLUSH_OPT_NOWRAP);
formatter_free (&f);
+ str_reset (&s);
}
+
+ struct formatter f = formatter_make (ctx, NULL);
+ formatter_add (&f, "#m", s.str);
+ formatter_flush (&f, stdout, FLUSH_OPT_NOWRAP);
+ formatter_free (&f);
+ str_free (&s);
exit (EXIT_SUCCESS);
}