+2000-05-18 Neil Booth <NeilB@earthling.net>
+
+ * cppinit.c (cpp_reader_init): Initialise col_adjust and
+ default tab stop size.
+ (no_num, OPT_ftabstop): New.
+ (handle_option): Handle "ftabstop=" command-line option.
+ (print_help): Document it.
+ * cpplex.c (COLUMN): Remove.
+ (handle_newline): Reset col_adjust.
+ (skip_whitespace): Update col_adjust as tabs encountered.
+ (_cpp_lex_line): Update to use col_adjust. Call
+ skip_whitespace for all whitespace.
+ * cpplib.h (struct cpp_options): New member tabstop.
+ (struct cpp_reader): New member col_adjust.
+ (CPP_BUF_COL): Update.
+ (CPP_BUF_COLUMN): New.
+ * cpp.texi: Document "-ftabstop=" command line option.
+
Wed May 17 18:19:41 2000 Philippe De Muyter <phdm@macqel.be>
* configure.in (NO_MINUS_C_MINUS_O): Macro made availabe for AC_OUTPUT
above. In a future release, this option will be replaced by
@samp{-flint} or @samp{-Wlint}; we are not sure which yet.
+@item -ftabstop=NUMBER
+@findex -ftabstop
+Indicates the distance between tabstops. This helps the preprocessor
+report correct column numbers in warnings or errors, even if tabs appear
+on the line. Values less than 1 or greater than 100 are ignored. The
+default is 8.
+
@item -$
@findex -$
Forbid the use of @samp{$} in identifiers. The C standard does not
CPP_OPTION (pfile, warn_import) = 1;
CPP_OPTION (pfile, discard_comments) = 1;
CPP_OPTION (pfile, show_column) = 1;
+ CPP_OPTION (pfile, tabstop) = 8;
CPP_OPTION (pfile, pending) =
(struct cpp_pending *) xcalloc (1, sizeof (struct cpp_pending));
#define no_fil N_("File name missing after %s")
#define no_mac N_("Macro name missing after %s")
#define no_pth N_("Path name missing after %s")
+#define no_num N_("Number missing after %s")
/* This is the list of all command line options, with the leading
"-" removed. It must be sorted in ASCII collating order. */
DEF_OPT("fno-show-column", 0, OPT_fno_show_column) \
DEF_OPT("fpreprocessed", 0, OPT_fpreprocessed) \
DEF_OPT("fshow-column", 0, OPT_fshow_column) \
+ DEF_OPT("ftabstop=", no_num, OPT_ftabstop) \
DEF_OPT("g", no_arg, OPT_g) /* arg optional */ \
DEF_OPT("h", 0, OPT_h) \
DEF_OPT("idirafter", no_dir, OPT_idirafter) \
case OPT_fno_show_column:
CPP_OPTION (pfile, show_column) = 0;
break;
+ case OPT_ftabstop:
+ /* Silently ignore empty string, non-longs and silly values. */
+ if (arg[0] != '\0')
+ {
+ char *endptr;
+ long tabstop = strtol (arg, &endptr, 10);
+ if (*endptr == '\0' && tabstop >= 1 && tabstop <= 100)
+ CPP_OPTION (pfile, tabstop) = tabstop;
+ }
+ break;
case OPT_w:
CPP_OPTION (pfile, inhibit_warnings) = 1;
break;
-dD Preserve macro definitions in output\n\
-dN As -dD except that only the names are preserved\n\
-dI Include #include directives in the output\n\
+ -ftabstop=<number> Distance between tab stops for column reporting\n\
-P Do not generate #line directives\n\
-$ Do not allow '$' in identifiers\n\
-remap Remap file names when including files.\n\
(name).text = (list)->namebuf + (list)->name_used;} while (0)
#define IS_DIRECTIVE(list) (TOK_TYPE (list, 0) == CPP_HASH)
-#define COLUMN(cur) ((cur) - buffer->line_base)
/* Maybe put these in the ISTABLE eventually. */
#define IS_HSPACE(c) ((c) == ' ' || (c) == '\t')
if ((cur) < (limit) && *(cur) == '\r' + '\n' - c) \
(cur)++; \
CPP_BUMP_LINE_CUR (pfile, (cur)); \
+ pfile->col_adjust = 0; \
} while (0)
#define IMMED_TOKEN() (!(cur_token->flags & PREV_WHITESPACE))
return multiline;
}
-/* Skips whitespace, stopping at next non-whitespace character. */
+/* Skips whitespace, stopping at next non-whitespace character.
+ Adjusts pfile->col_adjust to account for tabs. This enables tokens
+ to be assigned the correct column. */
static void
skip_whitespace (pfile, in_directive)
cpp_reader *pfile;
{
unsigned char c = *cur++;
+ if (c == '\t')
+ {
+ unsigned int col = CPP_BUF_COLUMN (buffer, cur - 1);
+ pfile->col_adjust += (CPP_OPTION (pfile, tabstop) - 1
+ - col % CPP_OPTION(pfile, tabstop));
+ }
if (IS_HSPACE(c)) /* FIXME: Fix ISTABLE. */
continue;
if (!is_space(c) || IS_NEWLINE (c)) /* Main loop handles newlines. */
register const unsigned char *cur = buffer->cur;
unsigned char flags = 0;
+ pfile->col_adjust = 0;
expanded:
token_limit = list->tokens + list->tokens_cap;
cur_token = list->tokens + list->tokens_used;
{
unsigned char c = *cur++;
- /* Optimize whitespace skipping, in particular the case of a
- single whitespace character, as every other token is probably
- whitespace. (' ' '\t' '\v' '\f' '\0'). */
+ /* Optimize whitespace skipping, as most tokens are probably
+ separated by whitespace. (' ' '\t' '\v' '\f' '\0'). */
+
if (is_hspace ((unsigned int) c))
{
- if (c == '\0' || (cur < buffer->rlimit && is_hspace (*cur)))
- {
- buffer->cur = cur - (c == '\0'); /* Get the null warning. */
- skip_whitespace (pfile, IS_DIRECTIVE (list));
- cur = buffer->cur;
- }
+ /* Step back to get the null warning and tab correction. */
+ buffer->cur = cur - 1;
+ skip_whitespace (pfile, IS_DIRECTIVE (list));
+ cur = buffer->cur;
+
flags = PREV_WHITESPACE;
if (cur == buffer->rlimit)
break;
}
/* Initialize current token. Its type is set in the switch. */
- cur_token->col = COLUMN (cur);
+ cur_token->col = CPP_BUF_COLUMN (buffer, cur);
cur_token->flags = flags;
flags = 0;
}
do_parse_string:
- /* Here c is one of ' " > or ). */
+ /* Here c is one of ' " or >. */
INIT_NAME (list, cur_token->val.name);
buffer->cur = cur;
parse_string2 (pfile, list, &cur_token->val.name, c);
const char *in_fname;
const char *out_fname;
+ /* Characters between tab stops. */
+ unsigned int tabstop;
+
/* Pending options - -D, -U, -A, -I, -ixxx. */
struct cpp_pending *pending;
struct if_stack *if_stack;
const unsigned char *potential_control_macro;
+ /* Token column position adjustment owing to tabs in whitespace. */
+ unsigned int col_adjust;
+
/* Buffer of -M output. */
struct deps *deps;
#define CPP_OPTION(PFILE, OPTION) ((PFILE)->opts.OPTION)
#define CPP_BUFFER(PFILE) ((PFILE)->buffer)
#define CPP_BUF_LINE(BUF) ((BUF)->lineno)
-#define CPP_BUF_COL(BUF) ((BUF)->cur - (BUF)->line_base)
+#define CPP_BUF_COLUMN(BUF, CUR) ((CUR) - (BUF)->line_base + pfile->col_adjust)
+#define CPP_BUF_COL(BUF) CPP_BUF_COLUMN(BUF, (BUF)->cur)
/* Name under which this program was invoked. */
extern const char *progname;