diff options
author | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2025-08-06 16:46:37 +0300 |
---|---|---|
committer | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2025-08-06 16:46:37 +0300 |
commit | 280cb9da39fc7b5357f6071926d511394f6d0152 (patch) | |
tree | cdca852694fd3e4cc9293c374d16ac69d9be01ea /src/main.c | |
parent | c5510d684e4879ab9a5295b4a1981888a4268627 (diff) | |
download | sciteco-280cb9da39fc7b5357f6071926d511394f6d0152.tar.gz |
command-line arguments are no longer passed via the unnamed buffer, but via special Q-registers ^Ax
* The unnamed buffer is also used for reading from --stdin, so you couldn't practically combine
--stdin with passing command-line arguments to macros.
* The old approach of passing command-line arguments via lines in the
unnamed buffer was flawed anyway as it wouldn't work with filenames containing LF.
This is just a very ancient feature, written when there weren't even long Q-reg names in SciTECO.
* You can now e.g. pipe into SciTECO and edit what was read interactively, e.g. `dmesg | sciteco -i`.
You can practically use SciTECO as a pager.
* htbl.tes is now a command-line filter (uses -qio).
* grosciteco.tes reads Troff intermediate code from stdin, so we no longer need
"*.intermediate" temporary files.
* added a getopt.tes test case to the testsuite.
* This change unfortunately breaks most macros accepting command-line arguments,
even if they used getopt.tes.
It also requires updating ~/.teco_ini - see fallback.teco_ini.
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 36 |
1 files changed, 18 insertions, 18 deletions
@@ -476,30 +476,30 @@ main(int argc, char **argv) * NOTE: The profile hasn't run yet, so it cannot guess the * documents encoding. This should therefore be done by the profile * for any preexisting unnamed buffer. - * - * FIXME: The unnamed buffer is also currently used for - * command-line parameters. - * Therefore you practically cannot pipe into SciTECO - * while using opener.tes. */ - if (teco_stdin && !teco_view_load_from_stdin(teco_ring_current->view, TRUE, &error)) - goto cleanup; + if (teco_stdin) { + if (!teco_view_load_from_stdin(teco_ring_current->view, TRUE, &error)) + goto cleanup; + + if (teco_interface_ssm(SCI_GETLENGTH, 0, 0) > 0) + teco_ring_dirtify(); + } /* - * Add remaining arguments to unnamed buffer. - * - * FIXME: This is not really robust since filenames may contain linefeeds. - * Also, the Unnamed Buffer should be kept empty for piping. - * Therefore, it would be best to store the arguments in Q-Regs, e.g. ^A0,^A1,^A2... + * Initialize the commandline-argument Q-registers (^Ax). */ - for (gint i = 1; argv_utf8[i]; i++) { - teco_interface_ssm(SCI_APPENDTEXT, strlen(argv_utf8[i]), (sptr_t)argv_utf8[i]); - teco_interface_ssm(SCI_APPENDTEXT, 1, (sptr_t)"\n"); + for (guint i = 0; argv_utf8[i]; i++) { + gchar buf[32+1]; + gint len = g_snprintf(buf, sizeof(buf), "\1%u", i); + g_assert(len < sizeof(buf)); + + teco_qreg_t *qreg = teco_qreg_plain_new(buf, len); + teco_qreg_table_insert_unique(&teco_qreg_table_globals, qreg); + if (!qreg->vtable->set_string(qreg, argv_utf8[i], strlen(argv_utf8[i]), + teco_default_codepage(), &error)) + goto cleanup; } - if (teco_interface_ssm(SCI_GETLENGTH, 0, 0) > 0) - teco_ring_dirtify(); - /* * Execute macro or mung file */ |