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 | |
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')
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/core-commands.c | 2 | ||||
-rw-r--r-- | src/main.c | 36 | ||||
-rwxr-xr-x | src/symbols-extract.tes | 12 |
4 files changed, 25 insertions, 27 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index f22802b..ff2e86b 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -103,8 +103,6 @@ endif CLEANFILES = $(BUILT_SOURCES) \ symbols-scintilla.c symbols-scilexer.c -# FIXME: Perhaps symbols-extract.tes should work with --stdin/--stdout. -# Requires changing the command-line argument passing first. symbols-scintilla.c : @SCINTILLA_PATH@/include/Scintilla.h \ symbols-extract.tes $(SCITECO_MINIMAL) -8m -- @srcdir@/symbols-extract.tes \ diff --git a/src/core-commands.c b/src/core-commands.c index f384272..6d0a3dc 100644 --- a/src/core-commands.c +++ b/src/core-commands.c @@ -920,7 +920,7 @@ TECO_DEFINE_STATE_START(teco_state_start); * Immediately jumps to the current loop's start. * Also works from inside conditionals. * - * This command behaves exactly like \fB>\fP with regard to + * This command behaves exactly like \fB<\fP with regard to * colon-modifiers. * * Outside of loops \(em or in a macro without @@ -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 */ diff --git a/src/symbols-extract.tes b/src/symbols-extract.tes index da9c207..6c7ef05 100755 --- a/src/symbols-extract.tes +++ b/src/symbols-extract.tes @@ -11,18 +11,18 @@ EIQ[$SCITECOPATH]/string.tes !* read commandline arguments *! [getopt.p] -[optstring]p:n: M[getopt]"F (0/0) ' -LR 0X#ou 2LR 0X#in HK +[optstring]p:n: +M[getopt]U#ou Q#ou"< Invalid command-line^J 1 ' Q#ou+1U#in !* copy all defines in input file beginning with prefix *! -EBN#in <S#defineS[[Q[getopt.p]]M ]; 1:Xa 10:a> EF +EBN[\#in] <S#defineS[[Q[getopt.p]]M ]; 1:Xa 10:a> EF !* sort all defines *! Ga ZJB 0,.M[qsort] J !* format as C/C++ array *! I/* - * AUTOGENERATED FROM Q#in + * AUTOGENERATED FROM Q[\#in] * DO NOT EDIT */ #ifdef HAVE_CONFIG_H @@ -31,7 +31,7 @@ I/* #include <glib.h> -#include "Q#in" +#include "Q[\#in]" #include "sciteco.h" #include "symbols.h" @@ -56,6 +56,6 @@ teco_cmdline_cleanup(void) !* write output file *! -2EL EWQ#ou +2EL EWQ[\#ou] EX |