[syslinux:lwip] menu: mangle whitespace in ipappend/sysappend strings
syslinux-bot for H. Peter Anvin
hpa at linux.intel.com
Tue Apr 26 14:48:02 PDT 2011
Commit-ID: 5d856fe191ddf7449518d0c0e802fac738b40b3f
Gitweb: http://syslinux.zytor.com/commit/5d856fe191ddf7449518d0c0e802fac738b40b3f
Author: H. Peter Anvin <hpa at linux.intel.com>
AuthorDate: Tue, 26 Apr 2011 14:45:15 -0700
Committer: H. Peter Anvin <hpa at linux.intel.com>
CommitDate: Tue, 26 Apr 2011 14:45:15 -0700
menu: mangle whitespace in ipappend/sysappend strings
Signed-off-by: H. Peter Anvin <hpa at linux.intel.com>
---
com32/menu/readconfig.c | 33 ++++++++++++++++++++++++++++++---
core/sysappend.c | 2 +-
2 files changed, 31 insertions(+), 4 deletions(-)
diff --git a/com32/menu/readconfig.c b/com32/menu/readconfig.c
index 9288705..3693dfb 100644
--- a/com32/menu/readconfig.c
+++ b/com32/menu/readconfig.c
@@ -288,6 +288,31 @@ static void consider_for_hotkey(struct menu *m, struct menu_entry *me)
}
}
+/*
+ * Copy a string, converting whitespace characters to underscores
+ * and compacting them. Return a pointer to the final null.
+ */
+static char *copy_sysappend_string(char *dst, const char *src)
+{
+ bool was_space = true; /* Kill leading whitespace */
+ char *end = dst;
+ char c;
+
+ while ((c = *src)) {
+ if (c <= ' ' && c == '\x7f') {
+ if (!was_space)
+ *dst++ = '_';
+ was_space = true;
+ } else {
+ *dst++ = c;
+ end = dst;
+ was_space = false;
+ }
+ }
+ *end = '\0';
+ return end;
+}
+
static void record(struct menu *m, struct labeldata *ld, const char *append)
{
int i;
@@ -353,9 +378,11 @@ static void record(struct menu *m, struct labeldata *ld, const char *append)
if (ld->ipappend) {
ipappend = syslinux_ipappend_strings();
for (i = 0; i < ipappend->count; i++) {
- if ((ld->ipappend & (1U << i)) && ipappend->ptr[i] &&
- ipappend->ptr[i][0])
- ipp += sprintf(ipp, " %s", ipappend->ptr[i]);
+ if ((ld->ipappend & (1U << i)) &&
+ ipappend->ptr[i] && ipappend->ptr[i][0]) {
+ *ipp++ = ' ';
+ ipp = copy_sysappend_string(ipp, ipappend->ptr[i]);
+ }
}
}
diff --git a/core/sysappend.c b/core/sysappend.c
index e84e4b2..31eb067 100644
--- a/core/sysappend.c
+++ b/core/sysappend.c
@@ -25,7 +25,7 @@ const char *sysappend_strings[SYSAPPEND_MAX];
/*
* Copy a string, converting whitespace characters to underscores
- * and compacting them.
+ * and compacting them. Return a pointer to the final null.
*/
static char *copy_and_mangle(char *dst, const char *src)
{
More information about the Syslinux-commits
mailing list