aboutsummaryrefslogtreecommitdiff
path: root/editors
diff options
context:
space:
mode:
Diffstat (limited to 'editors')
-rw-r--r--editors/awk.c18
-rw-r--r--editors/ed.c2
-rw-r--r--editors/vi.c17
3 files changed, 26 insertions, 11 deletions
diff --git a/editors/awk.c b/editors/awk.c
index 2c15f9e4e..b4f6a3741 100644
--- a/editors/awk.c
+++ b/editors/awk.c
@@ -2155,7 +2155,10 @@ static int fmt_num(char *b, int size, const char *format, double n, int int_as_i
}
/* formatted output into an allocated buffer, return ptr to buffer */
-static char *awk_printf(node *n)
+#if !ENABLE_FEATURE_AWK_GNU_EXTENSIONS
+# define awk_printf(a, b) awk_printf(a)
+#endif
+static char *awk_printf(node *n, int *len)
{
char *b = NULL;
char *fmt, *s, *f;
@@ -2209,6 +2212,10 @@ static char *awk_printf(node *n)
nvfree(v);
b = xrealloc(b, i + 1);
b[i] = '\0';
+#if ENABLE_FEATURE_AWK_GNU_EXTENSIONS
+ if (len)
+ *len = i;
+#endif
return b;
}
@@ -2666,6 +2673,7 @@ static var *evaluate(node *op, var *res)
case XC( OC_PRINT ):
case XC( OC_PRINTF ): {
FILE *F = stdout;
+ IF_FEATURE_AWK_GNU_EXTENSIONS(int len;)
if (op->r.n) {
rstream *rsm = newfile(R.s);
@@ -2703,8 +2711,12 @@ static var *evaluate(node *op, var *res)
fputs(getvar_s(intvar[ORS]), F);
} else { /* OC_PRINTF */
- char *s = awk_printf(op1);
+ char *s = awk_printf(op1, &len);
+#if ENABLE_FEATURE_AWK_GNU_EXTENSIONS
+ fwrite(s, len, 1, F);
+#else
fputs(s, F);
+#endif
free(s);
}
fflush(F);
@@ -2978,7 +2990,7 @@ static var *evaluate(node *op, var *res)
break;
case XC( OC_SPRINTF ):
- setvar_p(res, awk_printf(op1));
+ setvar_p(res, awk_printf(op1, NULL));
break;
case XC( OC_UNARY ): {
diff --git a/editors/ed.c b/editors/ed.c
index d3ae8da92..c50faeefa 100644
--- a/editors/ed.c
+++ b/editors/ed.c
@@ -553,7 +553,7 @@ static int printLines(int num1, int num2, int expandFlag)
fputc_printable(ch | PRINTABLE_META, stdout);
}
- fputs("$\n", stdout);
+ fputs_stdout("$\n");
setCurNum(num1++);
lp = lp->next;
diff --git a/editors/vi.c b/editors/vi.c
index 01597fa5e..458ca6293 100644
--- a/editors/vi.c
+++ b/editors/vi.c
@@ -522,7 +522,7 @@ static void show_help(void)
static void write1(const char *out)
{
- fputs(out, stdout);
+ fputs_stdout(out);
}
#if ENABLE_FEATURE_VI_WIN_RESIZE
@@ -3047,12 +3047,15 @@ static int find_range(char **start, char **stop, char c)
do_cmd(c); // execute movement cmd
dot_end(); // find NL
q = dot;
- } else {
- // nothing -- this causes any other values of c to
- // represent the one-character range under the
- // cursor. this is correct for ' ' and 'l', but
- // perhaps no others.
- //
+ } else /* if (c == ' ' || c == 'l') */ {
+ // forward motion by character
+ int tmpcnt = (cmdcnt ?: 1);
+ do_cmd(c); // execute movement cmd
+ // exclude last char unless range isn't what we expected
+ // this indicates we've hit EOL
+ if (tmpcnt == dot - p)
+ dot--;
+ q = dot;
}
if (q < p) {
t = q;