aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
AgeCommit message (Collapse)AuthorFilesLines
2025-08-10allow messages to be of arbitrary length: fixes crashesRobin Haberkorn1-8/+3
* Messages can be arbitrarily long, e.g. the following could provoke crashes in interactive mode `1000<@I/X/> HX$` It's hard to turn into a test case, though, as you could always increase the buffer size in teco_interface_msg(). * The message length is now only limited by RAM. * This implementation is less effective, but code opting for efficience, including all programmable user messages, should not rely on the printf-API anyway but use teco_interface_msg_literal().
2025-08-09Win32: avoid any automatic LF to CRLF conversions when writing to stdoutRobin Haberkorn1-0/+19
* At least the MSVCRT does this by default, i.e. the translation mode of stdout is not _O_BINARY. * This broke piping through SciTECO with --stdin --stdout, as this relies on SciTECO's builtin EOL normalization. Instead, you would get DOS linebreaks on output even if the source stream contains only UNIX linebreaks. * It would also break binary filters. * It seems to be safe to print only LF also for regular stdio (help and error messages), so I simply disaply the stdout (and stdin and stderr) EOL translation globally. * Also fixes Troff warnings due to the .in preprocessor writing output with DOS linebreaks. * Added a test case. All future platforms shouldn't perform any unexpected EOL translations on output.
2025-08-06command-line arguments are no longer passed via the unnamed buffer, but via ↵Robin Haberkorn4-27/+25
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.
2025-08-03simplified the htbl.tes preprocessor and the SUBST_MACRO using new --quiet, ↵Robin Haberkorn1-0/+2
--stdin and --stdout options * htbl.tes now reads from stdin and writes to stdout. Allows avoiding temporary `*.htbl` files * grosciteco.tes still cannot be simplified since --stdin cannot be combined with passing command-line arguments (FIXME).
2025-08-03added --quiet, --stdin and --stdout for easier integration into UNIX pipelinesRobin Haberkorn5-1/+114
* In principle --stdin and --stdout could have been done in pure TECO code using the <^T> command. Having built-in command-line arguments however has several advantages: * Significantly faster than reading byte-wise with ^T. * Performs EOL normalization unless specifying --8bit of course. * Significantly shortens command-lines. `sciteco -qio` and `sciteco -qi` can be real replacements for sed and awk. * You can even place SciTECO into the middle of a pipeline while editing interactively: foo | sciteco -qio --no-profile | bar Unfortunately, this will not currently work when munging the profile as command-line parameters are also transmitted via the unnamed buffer. This should be changed to use special Q-registers (FIXME). * --quiet can help to improve the test suite (TODO). Should probably be the default in TE_CHECK(). * --stdin and --stdout allow to simplify many SciTECO scripts, avoiding temporary files, especially for womenpage generation (TODO). * For processing potentially infinite streams, you will still have to read using ^T.
2025-08-02fixed serious bug with certain alternative string termination chars in ↵Robin Haberkorn6-32/+45
commands with multiple string arguments * When `@`-modifying a command with several string arguments and choosing `{` as the alternative string termination character, the parser would get totally confused. Any sequence of `{` would be ignored and only the first non-`{` would become the termination character. Consequently you also couldn't choose a new terminator after the closing `}`. So even a documented code example from sciteco(7) wouldn't work. The same was true when using $ (escape) or ^A as the alternative termination character. * We can now correctly parse e.g. `@FR{foo}{bar}` or `@FR$foo$bar$` (even though the latter one is quite pointless). * has probably been broken forever (has been broken even before v2.0). * Whitespace is now ignored in front of alternative termination characters as in TECO-64, so we can also write `@S /foo/` or even ``` @^Um { !* blabla *! } ``` I wanted to disallow whitespace termination characters, so the alternative would have been to throw an error. The new implementation at least adds some functionality. * Avoid redundancies when parsing no-op characters via teco_is_noop(). I assume that this is inlined and drawn into any jump-table what would be generated for the switch-statement in teco_state_start_input(). * Alternative termination characters are still case-folded, even if they are Unicode glyphs, so `@IЖfooж` would work and insert `foo`. This should perhaps be restricted to ANSI characters?
2025-08-01implemented the ^W command for refreshing the screen in loops, for sleeping ↵Robin Haberkorn5-24/+96
and also the CTRL+L immediate editing command * ^W can be added to loops in order to view progress in interactive mode. It also sleeps for a given number of milliseconds (10ms by default). * In batch mode it is therefore the sleep command. * Since CTRL+W is an immediate editing command, you will usually type it Caret+W. ASCII 23 however will also be accepted. * While ^W only updates the screen, you can force a complete redraw by pressing CTRL+L. This is what most terminal applications use for redrawing. It will make it harder to insert ASCII 12, but this is seldom necessary since it is a form feed. ^L (ASCII 12 and the upcaret variant ) is still a whitespace character and therefore treated as a NOP. * DEC TECO had CTRL+W as the refresh immediate editing command. Video TECO uses <ET> as a regular command for refreshign in loops. I'd rather keep ET reserved as a potential terminal configuration command as in DEC TECO, though.
2025-07-31added -v/--version and <EO> commandRobin Haberkorn2-0/+29
* DEC TECO had an <EO> command. In contrast to DEC TECO's implementation, the value reported by <EO> encodes a major.minor.micro semantic version.
2025-07-31implemented ^H command for returning the current time since midnight: ↵Robin Haberkorn1-13/+29
partially replaces ^B * :^H and ::^H now return the timestamps, while ^B only returns the date. * Pressing CTRL+H will rubout, so you will usually write it in upcaret mode.
2025-07-31implemented ^T command: allows typing by code and getting characters from ↵Robin Haberkorn10-8/+301
stdin or the user * n:^T always prints bytes (cf. :^A) * ^T without arguments returns a codepoint or byte from stdin. In interactive mode, this currentply places a cursor in the message line and waits for a keypress.
2025-07-28`ED&2` can be used to access the program termination flag nowRobin Haberkorn5-14/+17
* `0,2ED` is roughly equivalent to `-EX` * `ED&2` can be used to query whether EX has been run. This is useful if macros can run EX. * `2,0ED` could be used to cancel the effect of EX. * But the real motivation is for implementing a REPL script.
2025-07-28=/==/===: fixed detection of execution from the end of the command-lineRobin Haberkorn2-14/+29
In particular, fixes the test case `3<255=>` which would print only one number in interactive mode.
2025-07-27fixed using the command-line replacement register (ESC) in batch mode: was ↵Robin Haberkorn1-2/+1
causing assertions when entering interactive mode Also added a regression test case.
2025-07-27fixed a,b,c^Uq...$: The arguments where written in the wrong (reverse) orderRobin Haberkorn1-11/+18
* When writing UTF-8, we must first peek in reverse order since we can only write from left to right. * When writing in raw ANSI, we can immediately pop the values from the stack but must write in reverse.
2025-07-26properly document some functions in expressions.c and simplified codeRobin Haberkorn9-93/+79
* Practically all calls to teco_expressions_args() must be preceded by teco_expressions_eval(). * In code paths where we know that teco_expressions_args() > 0, it is safe to call teco_expressions_pop_num(0) instead of teco_expressions_pop_num_calc(). This is both easier and faster. * teco_expressions_pop_num_calc() is for simple applications where you just want to get a command argument with default (implied) values. Since it includes teco_expressions_eval(), we can avoid superfluous calls. * -EC...$ turned out to be broken and is fixed now. A test case has been added.
2025-07-26implemented the <T> (typeout) command for printing to the terminal from the ↵Robin Haberkorn5-32/+108
current buffer * refactored some code that is common with Xq into teco_get_range_args().
2025-07-26support <:^A> to force raw ANSI outputRobin Haberkorn2-4/+16
* ^A uses the default code page without colon, just like ^U/EU. This is usually UTF8, unless you run with --8bit. It would make just as little sense to inherit the codepage from the current document. * Ensures that code like `:^A^E<0xFF>^A` really outputs byte 0xFF. * DEC TECO doesn't have the colon modifier, but it has a colon modifier for ^T to enforce raw output. In SciTECO, the ^T vs. :^T distinction will also be between default codepage and ANSI. It makes sense because ^T should treat its numeric arguments like <I> for consistency.
2025-07-26implemented <:Gq> for printing the Q-Register string as a message instead of ↵Robin Haberkorn2-2/+13
inserting it
2025-07-26use teco_interface_msg_literal() where we're printing raw stringsRobin Haberkorn1-1/+1
* There are some calls of teco_interface_msg() with constant strings, but these are not convenient to convert as the teco_interface_msg_literal() does not yet support -1 for the string length.
2025-07-26support :=/:==/:=== commands: print number without trailing linefeedRobin Haberkorn2-20/+31
2025-07-26implemented the <^A> command for printing arbitrary stringsRobin Haberkorn9-66/+108
* Greatly improved usability as a scripting language. * The command is in DEC TECO, but in contrast to DEC TECO, we also support string building constructs in ^A. * Required some refactoring: As we want it to write everything verbatim to stdout, the per-interface method is now teco_interface_msg_literal() and it has to deal with unprintable characters. When displaying in the UI, we use teco_curses_format_str() and TecoGtkLabel functions/widgets to deal with possible control codes. * Numbers printed with `=` have to be written with a trailing linefeed, which would also be visible as a reverse "LF" in the UI. Not sure whether this is acceptable - the alternative would be to strip the strings before displaying them. * Messages written to stdout are also auto-flushed at the moment. In the future we might want to put flushing under control of the language. Perhaps :^A could inhibit the flushing.
2025-07-23ncurses: support the window title on XTerm-like emulatorsRobin Haberkorn1-23/+47
* Many terminal emulators won't have the status-line terminfo capabilities but still support OSC-0 escape sequences for setting the window title. This affects the real XTerm, rxvt-based and many emulators that claim to be XTerm via $TERM (e.g. GNOME Console). * It seems we can safely assume that any emulator with $TERM beginning with "xterm" or "rxvt" does in fact have OSC-0 or at least ignores it. The number of whitelisted emulators might be extended later on. This way, we don't have to add another ED flag. * We still give precendence to the to_status_line/from_status_line capabilities if they are in terminfo.
2025-07-23if EX falis because of a dirty buffer, the buffer's id is now included in ↵Robin Haberkorn3-8/+13
the error message
2025-07-22refactored =/==/=== command into stdio-commands.cRobin Haberkorn5-210/+266
There will be a lot more commands for terminal/message input and output soon.
2025-07-21discriminate against interactive-only codepaths in the imlementation of =/==/===Robin Haberkorn2-2/+4
Small slow downs will not be noticable for interactively executed commands, so we can well discriminate (G_UNLIKELY) against such code paths.
2025-07-21support <==> and <===> for printing octal and hexadecimal numbersRobin Haberkorn4-47/+192
* These are famously in DEC TECO-11, but also in Video TECO. * The implementation is tricky. They need to use lookahead states, but this would be inacceptable during interactive execution. Therefore only if executing from the end of the command line `==` and `===` are allowed to print multiple values. The number is therefore also not popped form the stack immediately but only peeked. It's popped only when it has been decided that the command has ended. * This may break existing macros that use multiple `=` in a row to print multiple values from the stack. You will now e.g. have to insert whitespace to separate such `=` commands.
2025-07-20FreeBSD: enable dlmalloc by default (--enable-malloc-replacement)Robin Haberkorn1-5/+9
* After re-benchmarking the performance, I in fact detected a 20-25% speedup if memory limiting is active. Both using `time` and the builtin monotic timer ::^B. When memory limiting is disabled, there is no detectable difference to jemalloc. The following test case was used: sciteco -e '::^BUs 100000<@^U[^E\a]"^E\a" %a> ::^B-Qs=' * I also played around with getrusage(), but it doesn't seem to be a viable API for detecting the currently used RSS, i.e. it does not allow recovering from OOMs.
2025-07-20document bug: you cannot currently use `{` and `}` to insert anything after ↵Robin Haberkorn1-0/+3
$$ into the commandline
2025-07-19special Q-registers `$` (working directory) and the clipboard registers now ↵Robin Haberkorn1-24/+16
support the append operation (:Xq, :^Uq...) Works via a default implementation in the "external" Q-register "class" by first querying the string, appending and re-setting it.
2025-07-19fixed <EF> and <EW> with invalid buffer ids (was crashing)Robin Haberkorn2-2/+17
* regression introduced in 2baa14add6d9976c29b27cf4470bb458a0198694
2025-07-19<EW> now accepts a numeric argument to specify the buffer to saveRobin Haberkorn1-34/+46
* In this case we always save the given buffer and never the current Q-Register. * The current Q-Register is only saved without any numeric argument. The same semantics make sense for <EF> so that Q*EF closes the current buffer even when editing a Q-Register. * This variant is present in Video TECO.
2025-07-18revised command topicsRobin Haberkorn8-41/+41
* Added some keywords. * Consistently added command variants with all modifiers. In principle including modifiers in the topics is unnecessary - you can always strip the modifiers and look up the raw command. However, looking up a command with modifiers can speed up the process (compare looking up ?S<TAB> vs ?::S<TAB> * The `@` modifier is listed only for commands without string arguments.
2025-07-18<nEL> (set EOL mode) now sets the buffer's dirty flagRobin Haberkorn1-0/+7
* While it doesn't directly change the buffer's contents in bytes, a subsequent write would result in a different file on disk, so it is consequent to remind the user of saving or discarding changes. * Will also fix :EX after changing the EOL mode.
2025-07-18support <:]q> (pop Q-Register) for getting a success/failure booleanRobin Haberkorn2-4/+16
* Could be used to check whether the stack is currently empty, although peeking would be cumbersome: `:]q"S [q !...! | !...! '` * This is from DEC TECO-11.
2025-07-18make some array declarations real constantsRobin Haberkorn4-5/+5
* `static const char *p = "FOO"` is not a true constant since the variable p can still be changed. It has to be declared as `static const char *const p = "FOO"`, so that the pointer itself is constant. * In case of string constants, it's easier however to use `static const char p[] = "FOO"`.
2025-07-18fixed minor memory leaks of per-state data in teco_machine_main_tRobin Haberkorn6-27/+23
* These were leaked e.g. in case of end-of-macro errors, but also in case of syntax highlighting (teco_lexer_style()). I considered to solve this by overwriting more of the end_of_macro_cb, but it didn't turn out to be trivial always. * Considering that the union in teco_machine_main_t saved only 3 machine words of memory, I decided to sacrifice those for more robust memory management. * teco_machine_qregspec_t cannot be directly embedded into teco_machine_main_t due to recursive dependencies with teco_machine_stringbuilding_t. It could now and should perhaps be allocated only once in teco_machine_main_init(), but it would require more refactoring.
2025-07-16the primary clipboard is now chosen by the 10th bit in the ED flagsRobin Haberkorn5-62/+41
* `[q]~` was broken and resulted in crashes since it reset the clipboard character to 0. In fact, if we don't want to break the `[a]b` idiom we cannot use the numeric cell of register `~`. * Therefore we no longer use the numeric part of register `~`. Once the clipboard registers are initialized they completely replace any existing register with the same name that may have been set in the profile. So we still don't leak any memory. (But perhaps it would now be better to fail with an error if one of the clipboard registers already exist?) * Instead, bit 10 (1024) of ED is now used to change the default clipboard to the primary selection. The alternative might have been an EJ flag or even a special register containing the name of the default clipboard register. * partially reverses 8c6de6cc718debf44f6056a4c34c4fbb13bc5020
2025-07-13implemented <ER> command for reading a file into the current bufferRobin Haberkorn6-27/+89
* This command exists in Video TECO. In Video TECO it also supports reading multiple files with a glob pattern -- we do not support that as I am not convinced of its usefulness. * teco_view_load() has been extended, so it can read into dot without discarding the existing document.
2025-07-13allow changing the default clipboard by setting the `~` integerRobin Haberkorn5-34/+113
* It continues to default to 67 (C), which is the system clipboard. But you can now overwrite it e.g. by adding `^^PU~` to the profile. * This fixes a minor memory leak: If you set one of the clipboard registers in the profile (initializing them as plain registers), the clipboard register had been leaked. The clipboard registers now replace any existing register, while at the same time preserving the numeric part. * All remaining Q-Reg table insertions use a new function teco_qreg_table_insert_unique() which adds an assertion, so that we notice any future possible memory leaks.
2025-07-13minor documentation fix in parser.cRobin Haberkorn1-1/+1
2025-07-11<EF> supports a numeric buffer id nowRobin Haberkorn3-46/+77
* ED hooks are not executed in this case * <EF> is now allowed even when editing a Q-Reg, unless you try to close the current buffer
2025-07-04implemented <^B> for returning the current dateRobin Haberkorn1-0/+42
* It is encoded with the same formula as on VAX/VMS on TECO-11, on TECOC and TECO-64. * As an extension, when colon-modified it returns the number of seconds since the epoch. It might be even more useful to return the microseconds since the epoch, but that would require 64-bit integers, which can theoretically be disabled at build time.
2025-07-03implemented ^E<code> string building constructs for embedding bytes and ↵Robin Haberkorn2-30/+110
codepoints in a strtoul()-like manner
2025-07-01GTK: handle (smooth) scrolling with a scroll controllerRobin Haberkorn1-15/+42
* On interfaces, which only support smooth scrolling, we had to emulate discrete events. Moreover, once we enabled GDK_SMOOTH_SCROLL_MASK, systems that would previously report discrete UP/DOWN events, would suddenly report GDK_SCROLL_SMOOTH. * Converting from smooth scroll events to discrete scroll events turned out to be trickier than anticipated. Scrolling was therefore more sluggish than it used to be before 2f448c976889fe60aba8557b5aa4aa0a0d939281. * Scrolling is therefore now delegated to a GtkEventControllerScroll, which is used to synthesize a discrete GDK_SCROLL event that's fed into the usual event pipeline via teco_interface_input_cb().
2025-06-27fixed ^S/^Y for <Gq> and <EN>Robin Haberkorn2-8/+9
* We must call teco_interface_bytes2glyphs() only ever with byte offsets that already exist in the buffer. * regression, introduced in aaa1d51a4c85fcc627e88ef7cf5292d9c5f5f840
2025-06-27fixed an asterisk in the <EN> manpage entryRobin Haberkorn1-1/+1
* We have to avoid `/*` within comments, so one of the two characters will have to use a named glyph. \[**] is actually a special symbol, which wasn't noticed until supporting Unicode. There is no named glyph for the plain asterisk. Thus we now use \[sl] to escape the `/` character. `/\c*` might have also worked. * grosciteco now supports the `sl` glyph.
2025-06-15PDCurses/Wincon: disable hardware cursor after window resizeRobin Haberkorn1-0/+5
2025-06-15require and adapted to PDCurses v4.5.1Robin Haberkorn1-8/+12
* PDCurses is practically used only for Windows builds, which only I build presumably, so it should be okay to bump the version. * Older PDCurses versions had serious problems like not detecting BUTTONX_RELEASED events. This was worked around and is fixed now. Even the Wincon version behaves like ncurses now with regard to mouse events. * We no longer have to support processing BUTTONX_CLICKED events. On the downside the mouse mask had to be adapted. * See also https://github.com/Bill-Gray/PDCursesMod/issues/330 * We also no longer have to call resize_term(0,0).
2025-06-15Revert "PDCurses/Win: more or less fixed mouse support"Robin Haberkorn1-37/+6
This reverts commit 8cc704b897f33d6150156c77202a29222b9ee667. This is no longer necessary with PDCurses v4.5.1. Keeping compatibility with old PDCurses versions is not very important as only I currently build and provide Windows binaries. Also, the previous workaround decreases usability on PDcurses/wincon even with a newer PDCurses library.
2025-06-12GTK: fixed scrolling on systems that only support smooth scrollingRobin Haberkorn1-4/+12
* Apparently, we cannot disable smooth scrolling on a per-application basis, so I have to handle both discrete and smooth scrolling events. * Since SciTECO's scroll API (-EJ) is based on discrete scrolling, we now emulate discrete scroll events by accumulating the delta_y of smooth scroll events. The threshold value of 12 is chosen arbitrarily, but based on an example in the Gtk documentation.