mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-21 02:03:03 +00:00
diagnostics: style: rename member for clariy
* src/location.c (caret_info): Now that we no longer have a 'file' member (see previous commit), rename 'source' as 'file'.
This commit is contained in:
@@ -166,11 +166,12 @@ location_print (location loc, FILE *out)
|
|||||||
static struct
|
static struct
|
||||||
{
|
{
|
||||||
/* Raw input file. */
|
/* Raw input file. */
|
||||||
FILE *source;
|
FILE *file;
|
||||||
/* The last file we tried to open. If non NULL, but SOURCE is NULL,
|
/* The position within the last file we quoted. If POS.FILE is non
|
||||||
it means this file is special and should not be quoted. */
|
NULL, but FILE is NULL, it means this file is special and should
|
||||||
|
not be quoted. */
|
||||||
boundary pos;
|
boundary pos;
|
||||||
/* Offset in SOURCE where line POS.LINE starts. */
|
/* Offset in FILE where line POS.LINE starts. */
|
||||||
size_t offset;
|
size_t offset;
|
||||||
} caret_info;
|
} caret_info;
|
||||||
|
|
||||||
@@ -178,7 +179,7 @@ static struct
|
|||||||
static bool
|
static bool
|
||||||
caret_set_file (const char *file)
|
caret_set_file (const char *file)
|
||||||
{
|
{
|
||||||
/* If a different source than before, close and let the rest open
|
/* If a different file than before, close and let the rest open
|
||||||
the new one. */
|
the new one. */
|
||||||
if (caret_info.pos.file && caret_info.pos.file != file)
|
if (caret_info.pos.file && caret_info.pos.file != file)
|
||||||
{
|
{
|
||||||
@@ -188,15 +189,15 @@ caret_set_file (const char *file)
|
|||||||
if (!caret_info.pos.file)
|
if (!caret_info.pos.file)
|
||||||
{
|
{
|
||||||
caret_info.pos.file = file;
|
caret_info.pos.file = file;
|
||||||
if ((caret_info.source = fopen (caret_info.pos.file, "r")))
|
if ((caret_info.file = fopen (caret_info.pos.file, "r")))
|
||||||
{
|
{
|
||||||
/* If the file is not regular (imagine #line 1 "/dev/stdin"
|
/* If the file is not regular (imagine #line 1 "/dev/stdin"
|
||||||
in the input file for instance), don't try to quote the
|
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
|
file. Keep caret_info.file set so that we don't try to
|
||||||
open it again, but leave caret_info.file NULL so that we
|
open it again, but leave caret_info.file NULL so that we
|
||||||
don't try to quote it. */
|
don't try to quote it. */
|
||||||
struct stat buf;
|
struct stat buf;
|
||||||
if (fstat (fileno (caret_info.source), &buf) == 0
|
if (fstat (fileno (caret_info.file), &buf) == 0
|
||||||
&& buf.st_mode & S_IFREG)
|
&& buf.st_mode & S_IFREG)
|
||||||
{
|
{
|
||||||
caret_info.pos.line = 1;
|
caret_info.pos.line = 1;
|
||||||
@@ -206,16 +207,16 @@ caret_set_file (const char *file)
|
|||||||
caret_free ();
|
caret_free ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return caret_info.source;
|
return caret_info.file;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
caret_free (void)
|
caret_free (void)
|
||||||
{
|
{
|
||||||
if (caret_info.source)
|
if (caret_info.file)
|
||||||
{
|
{
|
||||||
fclose (caret_info.source);
|
fclose (caret_info.file);
|
||||||
caret_info.source = NULL;
|
caret_info.file = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -223,7 +224,7 @@ caret_free (void)
|
|||||||
static int
|
static int
|
||||||
caret_getc (void)
|
caret_getc (void)
|
||||||
{
|
{
|
||||||
FILE *f = caret_info.source;
|
FILE *f = caret_info.file;
|
||||||
int res = getc (f);
|
int res = getc (f);
|
||||||
if (res == '\r')
|
if (res == '\r')
|
||||||
{
|
{
|
||||||
@@ -253,7 +254,7 @@ location_caret (location loc, const char *style, FILE *out)
|
|||||||
caret_info.pos.line = 1;
|
caret_info.pos.line = 1;
|
||||||
caret_info.offset = 0;
|
caret_info.offset = 0;
|
||||||
}
|
}
|
||||||
fseek (caret_info.source, caret_info.offset, SEEK_SET);
|
fseek (caret_info.file, caret_info.offset, SEEK_SET);
|
||||||
|
|
||||||
/* Advance to the line's position, keeping track of the offset. */
|
/* Advance to the line's position, keeping track of the offset. */
|
||||||
while (caret_info.pos.line < loc.start.line)
|
while (caret_info.pos.line < loc.start.line)
|
||||||
@@ -264,7 +265,7 @@ location_caret (location loc, const char *style, FILE *out)
|
|||||||
return;
|
return;
|
||||||
caret_info.pos.line += c == '\n';
|
caret_info.pos.line += c == '\n';
|
||||||
}
|
}
|
||||||
caret_info.offset = ftell (caret_info.source);
|
caret_info.offset = ftell (caret_info.file);
|
||||||
|
|
||||||
/* Read the actual line. Don't update the offset, so that we keep a pointer
|
/* Read the actual line. Don't update the offset, so that we keep a pointer
|
||||||
to the start of the line. */
|
to the start of the line. */
|
||||||
@@ -316,7 +317,7 @@ location_caret (location loc, const char *style, FILE *out)
|
|||||||
line. */
|
line. */
|
||||||
int len = single_line
|
int len = single_line
|
||||||
? loc.end.column
|
? loc.end.column
|
||||||
: ftell (caret_info.source) - caret_info.offset;
|
: ftell (caret_info.file) - caret_info.offset;
|
||||||
for (int i = loc.start.column + 1; i < len; ++i)
|
for (int i = loc.start.column + 1; i < len; ++i)
|
||||||
putc ('~', out);
|
putc ('~', out);
|
||||||
end_use_class (style, out);
|
end_use_class (style, out);
|
||||||
|
|||||||
Reference in New Issue
Block a user