[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 04/11] diagnostics: style: use a boundary to track the caret_info
From: |
Akim Demaille |
Subject: |
[PATCH 04/11] diagnostics: style: use a boundary to track the caret_info |
Date: |
Sat, 21 Sep 2019 11:59:57 +0200 |
* src/location.c (caret_info): Replace file and line with pos, a
boundary. This will allow us to use features of the boundary type,
such as boundary_compute.
---
src/location.c | 29 ++++++++++++++---------------
1 file changed, 14 insertions(+), 15 deletions(-)
diff --git a/src/location.c b/src/location.c
index 593260a6..745d70d8 100644
--- a/src/location.c
+++ b/src/location.c
@@ -169,9 +169,8 @@ static struct
FILE *source;
/* The last file we tried to open. If non NULL, but SOURCE is NULL,
it means this file is special and should not be quoted. */
- uniqstr file;
- size_t line;
- /* Offset in SOURCE where line LINE starts. */
+ boundary pos;
+ /* Offset in SOURCE where line POS.LINE starts. */
size_t offset;
} caret_info;
@@ -181,26 +180,26 @@ caret_set_file (const char *file)
{
/* If a different source than before, close and let the rest open
the new one. */
- if (caret_info.file && caret_info.file != file)
+ if (caret_info.pos.file && caret_info.pos.file != file)
{
caret_free ();
- caret_info.file = NULL;
+ caret_info.pos.file = NULL;
}
- if (!caret_info.file)
+ if (!caret_info.pos.file)
{
- caret_info.file = file;
- if ((caret_info.source = fopen (caret_info.file, "r")))
+ caret_info.pos.file = file;
+ if ((caret_info.source = fopen (caret_info.pos.file, "r")))
{
/* If the file is not regular (imagine #line 1 "/dev/stdin"
in the input file for instance), don't try to quote the
source. Keep caret_info.file set so that we don't try to
- open it again, but leave caret_info.source NULL so that
- we don't try to quote it. */
+ open it again, but leave caret_info.file NULL so that we
+ don't try to quote it. */
struct stat buf;
if (fstat (fileno (caret_info.source), &buf) == 0
&& buf.st_mode & S_IFREG)
{
- caret_info.line = 1;
+ caret_info.pos.line = 1;
caret_info.offset = 0;
}
else
@@ -249,21 +248,21 @@ location_caret (location loc, const char *style, FILE
*out)
/* If the line we want to quote is seekable (the same line as the previous
location), just seek it. If it was a previous line, we lost track of it,
so return to the start of file. */
- if (loc.start.line < caret_info.line)
+ if (loc.start.line < caret_info.pos.line)
{
- caret_info.line = 1;
+ caret_info.pos.line = 1;
caret_info.offset = 0;
}
fseek (caret_info.source, caret_info.offset, SEEK_SET);
/* Advance to the line's position, keeping track of the offset. */
- while (caret_info.line < loc.start.line)
+ while (caret_info.pos.line < loc.start.line)
{
int c = caret_getc ();
if (c == EOF)
/* Something is wrong, that line number does not exist. */
return;
- caret_info.line += c == '\n';
+ caret_info.pos.line += c == '\n';
}
caret_info.offset = ftell (caret_info.source);
--
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 <=
- [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, 2019/09/21
- [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