devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
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 1/9] Split out is_printable_string() into util.c
Date: Wed, 6 Jul 2011 12:39:58 -0600	[thread overview]
Message-ID: <20110706183958.GA4871@ponder.secretlab.ca> (raw)
In-Reply-To: <1309892577-23828-2-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>

On Tue, Jul 05, 2011 at 12:02:49PM -0700, Simon Glass wrote:
> This useful function is split out so it will be available to programs
> other than ftdump.
> 
> Signed-off-by: Simon Glass <sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>

Acked-by: Grant Likely <grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>

> ---
>  Makefile.ftdump |    3 ++-
>  ftdump.c        |   28 +++-------------------------
>  util.c          |   28 ++++++++++++++++++++++++++++
>  util.h          |   11 +++++++++++
>  4 files changed, 44 insertions(+), 26 deletions(-)
> 
> diff --git a/Makefile.ftdump b/Makefile.ftdump
> index b70905a..2744a18 100644
> --- a/Makefile.ftdump
> +++ b/Makefile.ftdump
> @@ -5,7 +5,8 @@
>  #
>  
>  FTDUMP_SRCS = \
> -	ftdump.c
> +	ftdump.c \
> +	util.c
>  
>  FTDUMP_GEN_SRCS =
>  
> diff --git a/ftdump.c b/ftdump.c
> index bce6535..db932e3 100644
> --- a/ftdump.c
> +++ b/ftdump.c
> @@ -11,36 +11,14 @@
>  #include <fdt.h>
>  #include <libfdt_env.h>
>  
> +#include "util.h"
> +
>  #define FTDUMP_BUF_SIZE	65536
>  
>  #define ALIGN(x, a)	(((x) + ((a) - 1)) & ~((a) - 1))
>  #define PALIGN(p, a)	((void *)(ALIGN((unsigned long)(p), (a))))
>  #define GET_CELL(p)	(p += 4, *((const uint32_t *)(p-4)))
>  
> -static int is_printable_string(const void *data, int len)
> -{
> -	const char *s = data;
> -	const char *ss;
> -
> -	/* zero length is not */
> -	if (len == 0)
> -		return 0;
> -
> -	/* must terminate with zero */
> -	if (s[len - 1] != '\0')
> -		return 0;
> -
> -	ss = s;
> -	while (*s && isprint(*s))
> -		s++;
> -
> -	/* not zero, or not done yet */
> -	if (*s != '\0' || (s + 1 - ss) < len)
> -		return 0;
> -
> -	return 1;
> -}
> -
>  static void print_data(const char *data, int len)
>  {
>  	int i;
> @@ -50,7 +28,7 @@ static void print_data(const char *data, int len)
>  	if (len == 0)
>  		return;
>  
> -	if (is_printable_string(data, len)) {
> +	if (util_is_printable_string(data, len)) {
>  		printf(" = \"%s\"", (const char *)data);
>  	} else if ((len % 4) == 0) {
>  		printf(" = <");
> diff --git a/util.c b/util.c
> index d7ac27d..994436f 100644
> --- a/util.c
> +++ b/util.c
> @@ -1,6 +1,9 @@
>  /*
>   * Copyright 2008 Jon Loeliger, Freescale Semiconductor, Inc.
>   *
> + * util_is_printable_string contributed by
> + *	Pantelis Antoniou <pantelis.antoniou AT gmail.com>
> + *
>   * This program is free software; you can redistribute it and/or
>   * modify it under the terms of the GNU General Public License as
>   * published by the Free Software Foundation; either version 2 of the
> @@ -17,6 +20,7 @@
>   *                                                                   USA
>   */
>  
> +#include <ctype.h>
>  #include <stdio.h>
>  #include <stdlib.h>
>  #include <stdarg.h>
> @@ -57,3 +61,27 @@ char *join_path(const char *path, const char *name)
>  	memcpy(str+lenp, name, lenn+1);
>  	return str;
>  }
> +
> +int util_is_printable_string(const void *data, int len)
> +{
> +	const char *s = data;
> +	const char *ss;
> +
> +	/* zero length is not */
> +	if (len == 0)
> +		return 0;
> +
> +	/* must terminate with zero */
> +	if (s[len - 1] != '\0')
> +		return 0;
> +
> +	ss = s;
> +	while (*s && isprint(*s))
> +		s++;
> +
> +	/* not zero, or not done yet */
> +	if (*s != '\0' || (s + 1 - ss) < len)
> +		return 0;
> +
> +	return 1;
> +}
> diff --git a/util.h b/util.h
> index 9cead84..cc68933 100644
> --- a/util.h
> +++ b/util.h
> @@ -1,6 +1,8 @@
>  #ifndef _UTIL_H
>  #define _UTIL_H
>  
> +#include <stdarg.h>
> +
>  /*
>   * Copyright 2008 Jon Loeliger, Freescale Semiconductor, Inc.
>   *
> @@ -53,4 +55,13 @@ static inline void *xrealloc(void *p, size_t len)
>  extern char *xstrdup(const char *s);
>  extern char *join_path(const char *path, const char *name);
>  
> +/**
> + * Check a string of a given length to see if it is all printable and
> + * has a valid terminator.
> + *
> + * @param data	The string to check
> + * @param len	The string length including terminator
> + * @return 1 if a valid printable string, 0 if not */
> +int util_is_printable_string(const void *data, int len);
> +
>  #endif /* _UTIL_H */
> -- 
> 1.7.3.1
> 

  parent reply	other threads:[~2011-07-06 18:39 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 [this message]
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

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=20110706183958.GA4871@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).