[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 03/11] diagnostics: extract boundary_compute from location_comput
From: |
Akim Demaille |
Subject: |
[PATCH 03/11] diagnostics: extract boundary_compute from location_compute |
Date: |
Sat, 21 Sep 2019 11:59:56 +0200 |
The handling of the contributions of the tabulations in the columns is
burried inside location_compute. We will soon be willing to use the
boundary part of the computation (to compute the current column number
each time we read a multibyte char).
* src/location.c (boundary_compute): New, extracted from...
(location_compute): here.
---
src/location.c | 28 +++++++++++++++++-----------
1 file changed, 17 insertions(+), 11 deletions(-)
diff --git a/src/location.c b/src/location.c
index 5b54e44d..593260a6 100644
--- a/src/location.c
+++ b/src/location.c
@@ -46,11 +46,8 @@ add_column_width (int column, char const *buf, size_t
bufsize)
return column <= INT_MAX - width ? column + width : INT_MAX;
}
-/* Set *LOC and adjust scanner cursor to account for token TOKEN of
- size SIZE. */
-
-void
-location_compute (location *loc, boundary *cur, char const *token, size_t size)
+static void
+boundary_compute (boundary *cur, char const *token, size_t size)
{
int line = cur->line;
int column = cur->column;
@@ -59,8 +56,6 @@ location_compute (location *loc, boundary *cur, char const
*token, size_t size)
char const *p = token;
char const *lim = token + size;
- loc->start = *cur;
-
for (p = token; p < lim; ++p)
switch (*p)
{
@@ -82,18 +77,29 @@ location_compute (location *loc, boundary *cur, char const
*token, size_t size)
byte += byte < INT_MAX;
break;
}
+ column = add_column_width (column, p0, p - p0);
cur->line = line;
- cur->column = column = add_column_width (column, p0, p - p0);
+ cur->column = column;
cur->byte = byte;
+}
+
+/* Set *LOC and adjust scanner cursor to account for token TOKEN of
+ size SIZE. */
+
+void
+location_compute (location *loc, boundary *cur, char const *token, size_t size)
+{
+ loc->start = *cur;
+ boundary_compute (cur, token, size);
loc->end = *cur;
- if (line == INT_MAX && loc->start.line != INT_MAX)
+ if (loc->end.line == INT_MAX && loc->start.line != INT_MAX)
complain (loc, Wother, _("line number overflow"));
- if (column == INT_MAX && loc->start.column != INT_MAX)
+ if (loc->end.column == INT_MAX && loc->start.column != INT_MAX)
complain (loc, Wother, _("column number overflow"));
- if (byte == INT_MAX && loc->start.byte != INT_MAX)
+ if (loc->end.byte == INT_MAX && loc->start.byte != INT_MAX)
complain (loc, Wother, _("byte number overflow"));
}
--
2.23.0
- [PATCH 00/11] diagnostics: truncate quoted sources to fit the screen width, Akim Demaille, 2019/09/21
- [PATCH 01/11] diagnostics: style: minor changes, Akim Demaille, 2019/09/21
- [PATCH 04/11] diagnostics: style: use a boundary to track the caret_info, Akim Demaille, 2019/09/21
- [PATCH 02/11] diagnostics: style: add caret_set_file, Akim Demaille, 2019/09/21
- [PATCH 07/11] diagnostics: truncate quoted sources to fit the screen, Akim Demaille, 2019/09/21
- [PATCH 03/11] diagnostics: extract boundary_compute from location_compute,
Akim Demaille <=
- [PATCH 06/11] diagnostics: learn how to count column number with multibyte chars, Akim Demaille, 2019/09/21
- [PATCH 05/11] diagnostics: style: rename member for clariy, Akim Demaille, 2019/09/21
- [PATCH 09/11] diagnostics: also show truncation at the end of line with "...", Akim Demaille, 2019/09/21
- [PATCH 10/11] diagnostics: don't print ellipsis on the caret line, Akim Demaille, 2019/09/21
- [PATCH 11/11] diagnostics: get the screen width from the terminal, Akim Demaille, 2019/09/21
- [PATCH 08/11] diagnostics: check that quoted lines are truncated, Akim Demaille, 2019/09/21
- [PATCH 11/11] diagnotics: get the screen width from the terminal, Akim Demaille, 2019/09/21