| git.druid.rocks | index | druid520 | ports | ports/ | coreutils/ | sbase/ | patches/ | 0001-sed-add-T-command.patch |
ports/coreutils/sbase/patches/0001-sed-add-T-command.patch
# sbase's sed never implemented gnu sed's "T" command (branch if s///
# has NOT succeeded, the inverse of the real "t" command it already
# has) -- a real, common construct (this tree's own toybox port needs
# it in its own generated-code sed scripts). mirrors cmd_t's own
# real, existing implementation almost exactly, just with the branch
# condition inverted.
--- a/sed.c 2026-09-11 21:58:22.310633288 +0000
+++ b/sed.c 2026-09-11 21:58:22.311114344 +0000
@@ -172,6 +172,7 @@
static void cmd_x(Cmd *c);
static void cmd_w(Cmd *c);
static void cmd_t(Cmd *c);
+static void cmd_T(Cmd *c);
static void cmd_s(Cmd *c);
static void cmd_r(Cmd *c);
static void cmd_q(Cmd *c);
@@ -250,6 +251,7 @@
['r'] = { cmd_r , get_r_arg , free_acir_arg , 1 }, /* write contents of file (unable to open/read treated as empty file) */
['s'] = { cmd_s , get_s_arg , free_s_arg , 2 }, /* find/replace/all that crazy s stuff */
['t'] = { cmd_t , get_bt_arg , NULL , 2 }, /* if s/// succeeded (since input or last t) branch to label (branch to end if no label) */
+ ['T'] = { cmd_T , get_bt_arg , NULL , 2 }, /* inverse of t: if s/// has NOT succeeded (since input or last t/T) branch to label */
['w'] = { cmd_w , get_w_arg , NULL , 2 }, /* append pattern space to file */
['x'] = { cmd_x , NULL , NULL , 2 }, /* exchange pattern and hold spaces */
['y'] = { cmd_y , get_y_arg , free_y_arg , 2 }, /* replace runes in set1 with runes in set2 */
@@ -1537,6 +1539,24 @@
}
static void
+cmd_T(Cmd *c)
+{
+ if (!in_range(c))
+ return;
+ if (gflags.s) {
+ /* a substitution DID happen: same "consumed" side effect as
+ * t's own branch-taken case, just without branching -- by
+ * the time either t or T returns, gflags.s is always 0. */
+ gflags.s = 0;
+ return;
+ }
+
+ /* if we jump backwards update to end, otherwise update to destination */
+ update_ranges(c + 1, c->u.jump > c ? c->u.jump : prog + pcap);
+ pc = c->u.jump;
+}
+
+static void
cmd_w(Cmd *c)
{
if (in_range(c))