Below some code cleanup for ksh's emacs mode.
cheers,
natano
---
Get rid of left over null elements in x_ftab as NELEM() is used instead.
Index: emacs.c
===================================================================
RCS file: /cvs/src/bin/ksh/emacs.c,v
retrieving revision 1.48
diff -u -r1.48 emacs.c
--- emacs.c 17 Dec 2013 16:37:05 -0000 1.48
+++ emacs.c 4 Oct 2014 06:54:54 -0000
@@ -254,13 +254,9 @@
{ x_fold_upper, "upcase-word", XF_ARG },
{ x_set_arg, "set-arg", XF_NOBIND },
{ x_comment, "comment", 0 },
- { 0, 0, 0 },
#ifdef DEBUG
{ x_debug_info, "debug-info", 0 },
-#else
- { 0, 0, 0 },
#endif
- { 0, 0, 0 },
};
int
@@ -1397,10 +1393,7 @@
if (list) {
/* show all function names */
for (i = 0; i < NELEM(x_ftab); i++) {
- if (x_ftab[i].xf_name == NULL)
- continue;
- if (x_ftab[i].xf_name &&
- !(x_ftab[i].xf_flags & XF_NOBIND))
+ if (!(x_ftab[i].xf_flags & XF_NOBIND))
shprintf("%s\n", x_ftab[i].xf_name);
}
return (0);
@@ -1449,8 +1442,6 @@
/* set non macro binding */
for (i = 0; i < NELEM(x_ftab); i++) {
- if (x_ftab[i].xf_name == NULL)
- continue;
if (!strcmp(x_ftab[i].xf_name, a2)) {
/* delete old mapping */
TAILQ_FOREACH_SAFE(k, &kblist, entry, kb)
---
Simplify x_emacs_putbuf().
Index: emacs.c
===================================================================
RCS file: /cvs/src/bin/ksh/emacs.c,v
retrieving revision 1.48
diff -u -r1.48 emacs.c
--- emacs.c 17 Dec 2013 16:37:05 -0000 1.48
+++ emacs.c 4 Oct 2014 07:02:47 -0000
@@ -466,11 +466,7 @@
static int
x_emacs_putbuf(const char *s, size_t len)
{
- int rval;
-
- if ((rval = x_do_ins(s, len)) != 0)
- return (rval);
- return (rval);
+ return x_do_ins(s, len);
}
static int
---
Improve kb_add to not loop over the arguments twice. Let kb_add check
line boundaries; patch provided by Pedro Martelletto.
Index: emacs.c
===================================================================
RCS file: /cvs/src/bin/ksh/emacs.c,v
retrieving revision 1.48
diff -u -r1.48 emacs.c
--- emacs.c 17 Dec 2013 16:37:05 -0000 1.48
+++ emacs.c 4 Oct 2014 07:04:25 -0000
@@ -1351,19 +1351,18 @@
kb_add(void *func, void *args, ...)
{
va_list ap;
- int i, count;
char l[LINE + 1];
+ int i;
va_start(ap, args);
- count = 0;
- while (va_arg(ap, unsigned int) != 0)
- count++;
- va_end(ap);
-
- va_start(ap, args);
- for (i = 0; i <= count /* <= is correct */; i++)
+ for (i = 0; i < sizeof(l) - 1; i++) {
l[i] = (unsigned char)va_arg(ap, unsigned int);
+ if (l[i] == (unsigned char)'\0')
+ break;
+ }
va_end(ap);
+
+ l[i] = (unsigned char)'\0';
return (kb_add_string(func, args, l));
}
---
Let's relief emacs.c from it's identify crisis.
Index: emacs.c
===================================================================
RCS file: /cvs/src/bin/ksh/emacs.c,v
retrieving revision 1.48
diff -u -r1.48 emacs.c
--- emacs.c 17 Dec 2013 16:37:05 -0000 1.48
+++ emacs.c 4 Oct 2014 06:56:13 -0000
@@ -2160,4 +2160,4 @@
return (xlp);
}
-#endif /* EDIT */
+#endif /* EMACS */