linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Christopher Li" <sparse@chrisli.org>
To: Hannes Eder <hannes@hanneseder.net>
Cc: linux-sparse@vger.kernel.org, Alexey Zaytsev <alexey.zaytsev@gmail.com>
Subject: Re: [PATCH] Add -ftabstop=WIDTH
Date: Wed, 31 Dec 2008 12:26:58 -0800	[thread overview]
Message-ID: <70318cbf0812311226gc18b63dld37072c3b7f41719@mail.gmail.com> (raw)
In-Reply-To: <20081231124108.10969.28189.stgit@vmbox.hanneseder.net>

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

On Wed, Dec 31, 2008 at 4:41 AM, Hannes Eder <hannes@hanneseder.net> wrote:
> Make tokenizer aware of tabstops and add the commandline option:
>
> -ftabstop=WIDTH
>    Set the distance between tab stops.  This helps sparse report correct
>    column numbers in warnings or errors.  If the value is less than 1 or
>    greater than 100, the option is ignored.  The default is 8.
>

I took the liberty to simplify the patch a little bit. See the attachment.

If there is no objections, I am going to apply the combined patch to
my repository:

git://git.kernel.org/pub/scm/devel/sparse/chrisl/sparse.git

Thanks,

Chris

[-- Attachment #2: 0001-Simplify-fstabstop-patch.patch --]
[-- Type: application/octet-stream, Size: 2683 bytes --]

From 247fe1aa9fec8e913b533fff28b1412fc6cbb941 Mon Sep 17 00:00:00 2001
From: Christopher Li <sparse@chrisli.org>
Date: Wed, 31 Dec 2008 12:13:11 -0800
Subject: [PATCH] Simplify -fstabstop patch

Signed-off-by: Christopher Li <sparse@chrisli.org>
---
 lib.c      |   29 +++++++----------------------
 token.h    |    2 +-
 tokenize.c |   10 +++++-----
 3 files changed, 13 insertions(+), 28 deletions(-)

diff --git a/lib.c b/lib.c
index 7bad451..de0b09a 100644
--- a/lib.c
+++ b/lib.c
@@ -532,33 +532,18 @@ static char **handle_switch_f(char *arg, char **next)
 
 	if (!strncmp (arg, "tabstop=", 8)) {
 		char *end;
-		long val;
+		unsigned long val;
 		arg += 8;
 
 		errno = 0;
-		val = strtol(arg, &end, 10);
+		val = strtoul(arg, &end, 10);
 
-		if ((errno == ERANGE && (val == LONG_MAX || val == LONG_MIN))
-		    || (errno != 0 && val == 0)) {
-			die("invalid argument for the -ftabstop= option: %s", strerror(errno));
-		}
-
-		if (end == arg) {
-			die("missing argument for the -ftabstop= option");
-		}
-
-		if (*end != '\0') {
-			/* further characters after number */
-			/* we just ignore them */
-		}
-
-		if (1 <= val && val <= 100)
-			tabstop_width = val;
-
-		return next;
-	}
+		if (!val || val > 100)
+			die("invalid argument for the -ftabstop= option: %ld", val);
+		printf("tabstop= %ld\n", val);
+		tabstop_width = val;
 
-	if (!strncmp(arg, "no-", 3)) {
+	} else if (!strncmp(arg, "no-", 3)) {
 		flag = 0;
 		arg += 3;
 	}
diff --git a/token.h b/token.h
index df7a80c..4c99887 100644
--- a/token.h
+++ b/token.h
@@ -48,7 +48,7 @@ struct stream {
 
 extern int input_stream_nr;
 extern struct stream *input_streams;
-extern int tabstop_width;
+extern unsigned int tabstop_width;
 
 struct ident {
 	struct ident *next;	/* Hash chain of identifiers */
diff --git a/tokenize.c b/tokenize.c
index 8b3ec2f..e6f9d13 100644
--- a/tokenize.c
+++ b/tokenize.c
@@ -25,7 +25,7 @@
 int input_stream_nr = 0;
 struct stream *input_streams;
 static int input_streams_allocated;
-int tabstop_width = 8;
+unsigned int tabstop_width = 8;
 
 #define BUFSIZE (8192)
 
@@ -207,7 +207,7 @@ static int nextchar_slow(stream_t *stream)
 	int offset = stream->offset;
 	int size = stream->size;
 	int c;
-	int spliced = 0, had_cr, had_backslash, complain;
+	int spliced = 0, had_cr, had_backslash, complain, delta;
 
 restart:
 	had_cr = had_backslash = complain = 0;
@@ -233,10 +233,10 @@ repeat:
 		goto repeat;
 	}
 
+	delta = 1;
 	if (c == '\t')
-		stream->pos = ((stream->pos - 1) / tabstop_width + 1) * tabstop_width;
-	else
-		stream->pos++;
+		delta = tabstop_width - stream->pos % tabstop_width;
+	stream->pos += delta;
 
 	if (c == '\n') {
 		stream->line++;
-- 
1.6.0.6


  parent reply	other threads:[~2008-12-31 20:27 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-12-31 12:41 [PATCH] Add -ftabstop=WIDTH Hannes Eder
2008-12-31 15:29 ` Alexey Zaytsev
2008-12-31 20:26 ` Christopher Li [this message]
2009-01-02 14:22   ` [PATCH v2] " Hannes Eder
2009-01-03 12:01     ` Junio C Hamano
2009-01-03 23:19       ` Christopher Li
2009-01-04  9:05         ` Junio C Hamano
2009-01-07  0:37           ` Christopher Li
2009-01-08 19:18         ` [PATCH v3] " Hannes Eder
2009-01-08 20:13           ` Christopher Li
2009-01-08 20:50             ` [PATCH] refactor handle_switch_f Hannes Eder
2009-01-09  4:25               ` Christopher Li
2009-01-03 22:41     ` [PATCH v2] Add -ftabstop=WIDTH Christopher Li

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=70318cbf0812311226gc18b63dld37072c3b7f41719@mail.gmail.com \
    --to=sparse@chrisli.org \
    --cc=alexey.zaytsev@gmail.com \
    --cc=hannes@hanneseder.net \
    --cc=linux-sparse@vger.kernel.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).