From: Grant Likely <grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>
To: Simon Glass <sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
Cc: Devicetree Discuss
<devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org>
Subject: Re: [PATCH 9/9] dtput: Support adding strings with spaces
Date: Wed, 6 Jul 2011 12:47:45 -0600 [thread overview]
Message-ID: <20110706184745.GH4871@ponder.secretlab.ca> (raw)
In-Reply-To: <1309892577-23828-10-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
On Tue, Jul 05, 2011 at 12:02:57PM -0700, Simon Glass wrote:
> Previously dtput would use sscanf() to read the string from the command line,
> even if no format string was provided. Thus it would split up words at
> whitespace boundaries, and put a \0 between each.
>
> This changes that behavior. Previously:
>
> $ ../dtput dtget-test.dtb -ts /compatible this is a test
>
> $ ../dtget dtget-test.dtb /compatible
> 116 104 105 115 0 105 115 0 97 110 111 116 104 101 114 0 116 101 115 116 0
>
> and you have to use the -ts flag to see this as a list of strings
>
> $ ../dtget dtget-test.dtb -ts /compatible
> this is a test
>
> Now:
>
> $ ../dtput dtget-test.dtb -ts /compatible "this is another test"
>
> $ ../dtget dtget-test.dtb /compatible this is another test
> this is another test
>
> $ ../dtget dtget-test.dtb /compatible -tb
> 116 104 105 115 32 105 115 32 97 110 111 116 104 101 114 32 116 101 115 116 0
>
> Note that the \0 terminators are gone.
>
> Signed-off-by: Simon Glass <sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
This would be squashed in with the dtput patch too.
g.
> ---
> dtput.c | 7 ++++++-
> tests/run_tests.sh | 4 +++-
> 2 files changed, 9 insertions(+), 2 deletions(-)
>
> diff --git a/dtput.c b/dtput.c
> index 48e3c75..d02e6ab 100644
> --- a/dtput.c
> +++ b/dtput.c
> @@ -55,7 +55,12 @@ static int encode_value(char **arg, int arg_count, const char *format,
> for (; arg_count > 0; arg++, arg_count--, upto += len) {
> /* assume integer unless told otherwise */
> if (type == 's') {
> - sscanf(*arg, format ? format : "%s", value);
> + if (format)
> + sscanf(*arg, format, value);
> + else {
> + strncpy(value, *arg, MAX_VALUE_SIZE - 1);
> + value[MAX_VALUE_SIZE - 1] = '\0';
> + }
> len = strlen(value) + 1;
> if (verbose)
> fprintf(stderr, "\tstring: '%s'\n", value);
> diff --git a/tests/run_tests.sh b/tests/run_tests.sh
> index d95d1fe..71cfab3 100755
> --- a/tests/run_tests.sh
> +++ b/tests/run_tests.sh
> @@ -434,10 +434,12 @@ dtput_tests () {
> file=dtget-test.dtb
> $DTC -O dtb -o $file ${file%.dtb}.dts 2>/dev/null
>
> - # run_dtput_test <test-name> <expected-result> <file> <key> <value>
> + # run_dtput_test <test-name> <expected-result> <file> <key> <value> <flags>
> run_dtput_test "Simple string" "a_model" $file "/model" "a_model" -ts
>
> run_dtput_test "Multiple string s" "board1 board2" \
> + $file "/compatible" "board1 board2" -ts -f%s
> + run_dtput_test "Single string with spaces" "board1 board2" \
> $file "/compatible" "board1 board2" -ts
> run_dtput_test "Integer" "32768" $file "/cpus/PowerPC,970@1/d-cache-size" \
> "32768"
> --
> 1.7.3.1
>
prev parent reply other threads:[~2011-07-06 18:47 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-07-05 19:02 [PATCH 0/9] Add dtget and dtput for access to fdt from build system Simon Glass
[not found] ` <1309892577-23828-1-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
2011-07-05 19:02 ` [PATCH 1/9] Split out is_printable_string() into util.c Simon Glass
[not found] ` <1309892577-23828-2-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
2011-07-06 18:39 ` Grant Likely
2011-07-16 5:44 ` David Gibson
[not found] ` <20110716054447.GE4368-787xzQ0H9iQXU02nzanrWNbf9cGiqdzd@public.gmane.org>
2011-07-17 12:43 ` Jon Loeliger
2011-07-05 19:02 ` [PATCH 2/9] Add dtget utility to read property values from device tree Simon Glass
[not found] ` <1309892577-23828-3-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
2011-07-06 18:41 ` Grant Likely
2011-07-19 3:34 ` David Gibson
[not found] ` <20110719033437.GB6399-787xzQ0H9iQXU02nzanrWNbf9cGiqdzd@public.gmane.org>
2011-07-28 12:22 ` Simon Glass
[not found] ` <CAPnjgZ3GgOx-Sja2Lq2WzYy+FYv3oyUF9vzdZ8RPYE-Hsmjf0Q-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2011-09-02 17:54 ` Simon Glass
[not found] ` <CAPnjgZ1mSifP1rSSCZgDCDQvd-PR3Q++Qr_TovJVPW_BrH3fgA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2011-09-03 14:33 ` David Gibson
[not found] ` <20110903143355.GB12965-787xzQ0H9iQXU02nzanrWNbf9cGiqdzd@public.gmane.org>
2011-09-04 3:18 ` Simon Glass
[not found] ` <CAPnjgZ3hB_nfGqVA_4+wQfxuanUn7nhVQMboEFSODK0UvsNqmg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2011-09-04 11:14 ` David Gibson
[not found] ` <20110904111448.GA30278-787xzQ0H9iQXU02nzanrWNbf9cGiqdzd@public.gmane.org>
2011-09-04 21:18 ` Simon Glass
2011-07-05 19:02 ` [PATCH 3/9] Add basic tests for dtget Simon Glass
[not found] ` <1309892577-23828-4-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
2011-07-06 18:42 ` Grant Likely
2011-07-19 5:40 ` David Gibson
2011-07-05 19:02 ` [PATCH 4/9] Add missing tests to .gitignore Simon Glass
[not found] ` <1309892577-23828-5-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
2011-07-06 18:42 ` Grant Likely
2011-07-16 5:49 ` David Gibson
[not found] ` <20110716054944.GF4368-787xzQ0H9iQXU02nzanrWNbf9cGiqdzd@public.gmane.org>
2011-07-17 12:45 ` Jon Loeliger
2011-07-05 19:02 ` [PATCH 5/9] Add utilfdt for common functions, adjust dtget Simon Glass
[not found] ` <1309892577-23828-6-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
2011-07-06 18:43 ` Grant Likely
2011-07-05 19:02 ` [PATCH 6/9] Add new dtput utility to write values to fdt Simon Glass
[not found] ` <1309892577-23828-7-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
2011-07-06 18:46 ` Grant Likely
[not found] ` <20110706184626.GF4871-e0URQFbLeQY2iJbIjFUEsiwD8/FfD2ys@public.gmane.org>
2011-09-04 3:23 ` Simon Glass
2011-07-05 19:02 ` [PATCH 7/9] Add some tests for dtput Simon Glass
2011-07-05 19:02 ` [PATCH 8/9] Add dtput to .gitignore Simon Glass
[not found] ` <1309892577-23828-9-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
2011-07-06 18:46 ` Grant Likely
2011-07-05 19:02 ` [PATCH 9/9] dtput: Support adding strings with spaces Simon Glass
[not found] ` <1309892577-23828-10-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
2011-07-06 18:47 ` Grant Likely [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20110706184745.GH4871@ponder.secretlab.ca \
--to=grant.likely-s3s/wqlpoipyb63q8fvjnq@public.gmane.org \
--cc=devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org \
--cc=sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).