devicetree-compiler.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Gibson <david-xT8FGy+AXnRB3Ne2BGzF6laj5H9X9Tb+@public.gmane.org>
To: Julia Lawall <Julia.Lawall-L2FTfq7BK8M@public.gmane.org>
Cc: devicetree-compiler-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [PATCH 3/5] annotations: short annotations
Date: Tue, 9 Jan 2018 22:21:30 +1100	[thread overview]
Message-ID: <20180109112130.GM2131@umbus.fritz.box> (raw)
In-Reply-To: <1515418607-26764-4-git-send-email-Julia.Lawall-L2FTfq7BK8M@public.gmane.org>

[-- Attachment #1: Type: text/plain, Size: 3872 bytes --]

On Mon, Jan 08, 2018 at 02:36:45PM +0100, Julia Lawall wrote:
> Based on the following patch by Frank Rowand (no changes):
> 
>
>https://www.mail-archive.com/devicetree-compiler-u79uwXL29TY76Z2rM5mHXA@public.gmane.org/msg00378.html

If there are no changes, then it should definitely have Frank's S-o-b.

> 
> Signed-off-by: Julia Lawall <Julia.Lawall-L2FTfq7BK8M@public.gmane.org>
> ---
>  srcpos.c     | 34 ++++++++++++++++++++++++++++++++++
>  srcpos.h     |  2 ++
>  treesource.c |  8 ++++----
>  3 files changed, 40 insertions(+), 4 deletions(-)
> 
> diff --git a/srcpos.c b/srcpos.c
> index 1a4db9c..85657c6 100644
> --- a/srcpos.c
> +++ b/srcpos.c
> @@ -317,6 +317,40 @@ out:
>  	return pos_str;
>  }
>  
> +static char *
> +srcpos_string_short(struct srcpos *pos, bool first_line)
> +{
> +	const char *fname = "<no-file>";
> +	char *pos_str;
> +	int rc;
> +
> +	if (pos) {
> +		fname = pos->file->name;
> +		rc = asprintf(&pos_str, "%s:%d", fname,

You can use xasprintf to avoid having to check for failure.

> +			      (first_line) ? pos->first_line: pos->last_line);
> +	}

else on the same line as }, please - dtc uses kernel coding style
(more or less).

> +	else {
> +		rc = asprintf(&pos_str, "%s:<no-line>", fname);
> +	}
> +
> +	if (rc == -1)
> +		die("Couldn't allocate in srcpos_string_short");
> +
> +	return pos_str;
> +}
> +
> +char *
> +srcpos_string_first(struct srcpos *pos)
> +{
> +	return srcpos_string_short(pos, true);
> +}
> +
> +char *
> +srcpos_string_last(struct srcpos *pos)
> +{
> +	return srcpos_string_short(pos, false);
> +}
> +
>  void srcpos_verror(struct srcpos *pos, const char *prefix,
>  		   const char *fmt, va_list va)
>  {
> diff --git a/srcpos.h b/srcpos.h
> index ec69d89..9281cba 100644
> --- a/srcpos.h
> +++ b/srcpos.h
> @@ -109,6 +109,8 @@ extern struct srcpos *srcpos_copy_all(struct srcpos *pos);
>  extern struct srcpos *srcpos_combine(struct srcpos *left_srcpos,
>  	 struct srcpos *right_srcpos);
>  extern char *srcpos_string(struct srcpos *pos);
> +extern char *srcpos_string_first(struct srcpos *pos);
> +extern char *srcpos_string_last(struct srcpos *pos);
>  
>  extern void PRINTF(3, 0) srcpos_verror(struct srcpos *pos, const char *prefix,
>  					const char *fmt, va_list va);
> diff --git a/treesource.c b/treesource.c
> index a99eca4..9a22b5e 100644
> --- a/treesource.c
> +++ b/treesource.c
> @@ -204,7 +204,7 @@ static void write_propval(FILE *f, struct property *prop)
>  
>  	if (len == 0) {
>  		if (annotate) {
> -			srcstr = srcpos_string(prop->srcpos);
> +			srcstr = srcpos_string_first(prop->srcpos);
>  			fprintf(f, "; /* %s */\n", srcstr);
>  			free(srcstr);
>  		} else {
> @@ -238,7 +238,7 @@ static void write_propval(FILE *f, struct property *prop)
>  	}
>  
>  	if (annotate) {
> -		srcstr = srcpos_string(prop->srcpos);
> +		srcstr = srcpos_string_first(prop->srcpos);
>  		fprintf(f, "; /* %s */\n", srcstr);
>  		free(srcstr);
>  	} else {
> @@ -262,7 +262,7 @@ static void write_tree_source_node(FILE *f, struct node *tree, int level)
>  		fprintf(f, "/ {");
>  
>  	if (annotate) {
> -		srcstr = srcpos_string(tree->srcpos);
> +		srcstr = srcpos_string_first(tree->srcpos);
>  		fprintf(f, " /* %s */\n", srcstr);
>  		free(srcstr);
>  	} else {
> @@ -282,7 +282,7 @@ static void write_tree_source_node(FILE *f, struct node *tree, int level)
>  	}
>  	write_prefix(f, level);
>  	if (annotate) {
> -		srcstr = srcpos_string(tree->srcpos);
> +		srcstr = srcpos_string_last(tree->srcpos);
>  		fprintf(f, "}; /* %s */\n", srcstr);
>  		free(srcstr);
>  	} else {

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  parent reply	other threads:[~2018-01-09 11:21 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-08 13:36 [PATCH 0/5] annotations Julia Lawall
     [not found] ` <1515418607-26764-1-git-send-email-Julia.Lawall-L2FTfq7BK8M@public.gmane.org>
2018-01-08 13:36   ` [PATCH 1/5] annotations: Check for NULL pos Julia Lawall
     [not found]     ` <1515418607-26764-2-git-send-email-Julia.Lawall-L2FTfq7BK8M@public.gmane.org>
2018-01-09 10:04       ` David Gibson
     [not found]         ` <20180109100400.GK2131-K0bRW+63XPQe6aEkudXLsA@public.gmane.org>
2018-01-09 10:32           ` Julia Lawall
2018-01-10  6:08       ` Frank Rowand
     [not found]         ` <d7cae26a-a92f-6a39-61ca-05fee9509722-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2018-01-10  6:29           ` Julia Lawall
2018-01-08 13:36   ` [PATCH 2/5] annotations: Add position information to various calls Julia Lawall
     [not found]     ` <1515418607-26764-3-git-send-email-Julia.Lawall-L2FTfq7BK8M@public.gmane.org>
2018-01-08 22:29       ` Rob Herring
     [not found]         ` <CAL_JsqKaXY+K9LKH1qL1i-OhTjX1Kqvb6F3FJywwrPNZzLCz4A-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2018-01-09  0:58           ` Frank Rowand
2018-01-09  6:16           ` Julia Lawall
2018-01-09 14:19             ` Rob Herring
2018-01-09 11:16       ` David Gibson
     [not found]         ` <20180109111614.GL2131-K0bRW+63XPQe6aEkudXLsA@public.gmane.org>
2018-01-09 12:27           ` Julia Lawall
2018-01-10  5:32             ` David Gibson
     [not found]               ` <20180110053255.GE19773-K0bRW+63XPQe6aEkudXLsA@public.gmane.org>
2018-01-10  6:26                 ` Julia Lawall
2018-01-10  6:34           ` Julia Lawall
2018-01-11 15:21           ` Julia Lawall
2018-01-15  7:36             ` David Gibson
     [not found]               ` <20180115073609.GA26066-K0bRW+63XPQe6aEkudXLsA@public.gmane.org>
2018-01-15  9:28                 ` Julia Lawall
2018-01-16  8:33                   ` David Gibson
     [not found]                     ` <20180116083334.GI30352-K0bRW+63XPQe6aEkudXLsA@public.gmane.org>
2018-01-16  8:37                       ` Julia Lawall
2018-01-10  6:25       ` Frank Rowand
     [not found]         ` <a0d1314a-8c1f-e553-dacc-62274c6b4cca-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2018-01-10  6:29           ` Frank Rowand
     [not found]             ` <bd068783-e34a-293c-ff03-d6dd37bff219-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2018-01-10  6:31               ` Julia Lawall
2018-01-10  6:30           ` Julia Lawall
2018-01-08 13:36   ` [PATCH 3/5] annotations: short annotations Julia Lawall
     [not found]     ` <1515418607-26764-4-git-send-email-Julia.Lawall-L2FTfq7BK8M@public.gmane.org>
2018-01-09 11:21       ` David Gibson [this message]
     [not found]         ` <20180109112130.GM2131-K0bRW+63XPQe6aEkudXLsA@public.gmane.org>
2018-01-09 21:01           ` Frank Rowand
2018-01-08 13:36   ` [PATCH 4/5] annotations: shorten file names Julia Lawall
     [not found]     ` <1515418607-26764-5-git-send-email-Julia.Lawall-L2FTfq7BK8M@public.gmane.org>
2018-01-10  5:44       ` David Gibson
     [not found]         ` <20180110054410.GF19773-K0bRW+63XPQe6aEkudXLsA@public.gmane.org>
2018-01-10  6:28           ` Julia Lawall
2018-01-08 13:36   ` [PATCH 5/5] annotations: add --annotate-full option Julia Lawall
     [not found]     ` <1515418607-26764-6-git-send-email-Julia.Lawall-L2FTfq7BK8M@public.gmane.org>
2018-01-10  6:32       ` Frank Rowand
     [not found]         ` <e249131c-5a60-f17c-a0ad-3a9aa3db8570-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2018-01-10  6:36           ` Julia Lawall
2018-01-10  8:50       ` David Gibson

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=20180109112130.GM2131@umbus.fritz.box \
    --to=david-xt8fgy+axnrb3ne2bgzf6laj5h9x9tb+@public.gmane.org \
    --cc=Julia.Lawall-L2FTfq7BK8M@public.gmane.org \
    --cc=devicetree-compiler-u79uwXL29TY76Z2rM5mHXA@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).