From: "Hannes Eder" <hannes@hanneseder.net>
To: Christopher Li <sparse@chrisli.org>
Cc: linux-sparse@vger.kernel.org, Alexey Zaytsev <alexey.zaytsev@gmail.com>
Subject: Re: [PATCH v2] Add -ftabstop=WIDTH
Date: Fri, 2 Jan 2009 15:22:28 +0100 [thread overview]
Message-ID: <154e089b0901020622u26848778q56d9510e6edc60ff@mail.gmail.com> (raw)
In-Reply-To: <70318cbf0812311226gc18b63dld37072c3b7f41719@mail.gmail.com>
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.
With simplifications suggested by Christopher Li.
Signed-off-by: Hannes Eder <hannes@hanneseder.net>
---
On Wed, Dec 31, 2008 at 9:26 PM, Christopher Li <sparse@chrisli.org> wrote:
> I took the liberty to simplify the patch a little bit. See the attachment.
I like the part in tokenizer.c, I even simplified it a bit further, to
use a ternary op, and
do not use a variable.
> If there is no objections, I am going to apply the combined patch to
> my repository:
I slightly modified to option parsing part, to be at least as relaxed
as GNU's CPP, where the option is from (see manpage), and to match the
description in sparse.1.
> With simplifications suggested by Christopher Li.
How should I acknowledge your contribution? Is this Ok?
Or shoul I send a patch relative to your patch?
lib.c | 17 ++++++++++++++++-
sparse.1 | 7 +++++++
token.h | 1 +
tokenize.c | 5 +++--
4 files changed, 27 insertions(+), 3 deletions(-)
diff --git a/lib.c b/lib.c
index 059ba3b..221e7b8 100644
--- a/lib.c
+++ b/lib.c
@@ -15,6 +15,8 @@
#include <string.h>
#include <unistd.h>
#include <assert.h>
+#include <limits.h>
+#include <errno.h>
#include <sys/types.h>
@@ -511,7 +513,20 @@ static char **handle_switch_f(char *arg, char **next)
int flag = 1;
arg++;
- if (!strncmp(arg, "no-", 3)) {
+
+ if (!strncmp(arg, "tabstop=", 8)) {
+ char *end;
+ unsigned long val;
+ arg += 8;
+
+ if (*arg == '\0')
+ die("error: missing argument to \"-ftabstop=\"");
+
+ /* we silently ignore silly values */
+ val = strtoul(arg, &end, 10);
+ if (*end == '\0' && 1 <= val && val <= 100)
+ tabstop = val;
+ } else if (!strncmp(arg, "no-", 3)) {
flag = 0;
arg += 3;
}
diff --git a/sparse.1 b/sparse.1
index d242dc7..a9e3397 100644
--- a/sparse.1
+++ b/sparse.1
@@ -287,6 +287,13 @@ However, this behavior can lead to subtle errors.
Sparse does not issue these warnings by default.
.
+.SH OTHER OPTIONS
+.TP
+.B \-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.
+.
.SH SEE ALSO
.BR cgcc (1)
.
diff --git a/token.h b/token.h
index ba7866d..44128f2 100644
--- a/token.h
+++ b/token.h
@@ -48,6 +48,7 @@ struct stream {
extern int input_stream_nr;
extern struct stream *input_streams;
+extern unsigned int tabstop;
struct ident {
struct ident *next; /* Hash chain of identifiers */
diff --git a/tokenize.c b/tokenize.c
index d154882..828a76f 100644
--- a/tokenize.c
+++ b/tokenize.c
@@ -25,6 +25,7 @@
int input_stream_nr = 0;
struct stream *input_streams;
static int input_streams_allocated;
+unsigned int tabstop = 8;
#define BUFSIZE (8192)
@@ -232,7 +233,7 @@ repeat:
goto repeat;
}
- stream->pos++;
+ stream->pos += (c == '\t') ? (tabstop - stream->pos % tabstop) : 1;
if (c == '\n') {
stream->line++;
@@ -291,7 +292,7 @@ static inline int nextchar(stream_t *stream)
if (offset < stream->size) {
int c = stream->buffer[offset++];
static const char special[256] = {
- ['\r'] = 1, ['\n'] = 1, ['\\'] = 1
+ ['\t'] = 1, ['\r'] = 1, ['\n'] = 1, ['\\'] = 1
};
if (!special[c]) {
stream->offset = offset;
next prev parent reply other threads:[~2009-01-02 14:22 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
2009-01-02 14:22 ` Hannes Eder [this message]
2009-01-03 12:01 ` [PATCH v2] " 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=154e089b0901020622u26848778q56d9510e6edc60ff@mail.gmail.com \
--to=hannes@hanneseder.net \
--cc=alexey.zaytsev@gmail.com \
--cc=linux-sparse@vger.kernel.org \
--cc=sparse@chrisli.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).