diff options
author | Chris Davis <cd.rattan@gmail.com> | 2014-07-18 13:35:14 -0700 |
---|---|---|
committer | Michael Adam <obnox@samba.org> | 2014-10-01 14:32:09 +0200 |
commit | 42df2e643f68f5ec19e6a41eade29199a3266035 (patch) | |
tree | 4314cd36ababa0ba2641a3f08bec1980a64341da /source3/utils/regedit_dialog.c | |
parent | c94c765f01dc145ee7f1abfe1379ed9c923f3d43 (diff) | |
download | samba-42df2e643f68f5ec19e6a41eade29199a3266035.tar.gz |
regedit: add padding to fit REG_MULTI_SZ to the text field
This fixes a bug loading REG_MULTI_SZ values into the editor dialog,
since ncurses fields don't handle newline characters.
Signed-off-by: Chris Davis <cd.rattan@gmail.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
Diffstat (limited to 'source3/utils/regedit_dialog.c')
-rw-r--r-- | source3/utils/regedit_dialog.c | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/source3/utils/regedit_dialog.c b/source3/utils/regedit_dialog.c index 944fcc8aeae..ce67065d8bc 100644 --- a/source3/utils/regedit_dialog.c +++ b/source3/utils/regedit_dialog.c @@ -642,22 +642,35 @@ static WERROR fill_value_buffer(struct edit_dialog *edit, break; } case REG_MULTI_SZ: { - const char **p, **a; + int rows, cols, max; + size_t padding, length, index; + const char **array, **arrayp; char *buf = NULL; - if (!pull_reg_multi_sz(edit, &vitem->data, &a)) { + dynamic_field_info(edit->field[FLD_DATA], &rows, &cols, &max); + if (!pull_reg_multi_sz(edit, &vitem->data, &array)) { return WERR_NOMEM; } - for (p = a; *p != NULL; ++p) { - if (buf == NULL) { - buf = talloc_asprintf(edit, "%s\n", *p); - } else { - buf = talloc_asprintf_append(buf, "%s\n", *p); - } + + /* try to fit each string on it's own line. each line + needs to be padded with whitespace manually, since + ncurses fields do not have newlines. */ + for (index = 0, arrayp = array; *arrayp != NULL; ++arrayp) { + length = MIN(strlen(*arrayp), cols); + padding = cols - length; + buf = talloc_realloc(edit, buf, char, + talloc_array_length(buf) + + length + padding + 1); if (buf == NULL) { return WERR_NOMEM; } + memcpy(&buf[index], *arrayp, length); + index += length; + memset(&buf[index], ' ', padding); + index += padding; + buf[index] = '\0'; } + set_field_buffer(edit->field[FLD_DATA], 0, buf); talloc_free(buf); } |