mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-21 12:10:26 +02:00
More explicit variable names in scm_i_scan_for_encoding
Note especially that the variable 'i' has two different uses in this function, and they get confused. * libguile/read.c (scm_i_scan_for_encoding): cleanup
This commit is contained in:
parent
63479112d6
commit
daedbca7de
1 changed files with 18 additions and 15 deletions
|
@ -1627,11 +1627,10 @@ char *
|
||||||
scm_i_scan_for_encoding (SCM port)
|
scm_i_scan_for_encoding (SCM port)
|
||||||
{
|
{
|
||||||
char header[SCM_ENCODING_SEARCH_SIZE+1];
|
char header[SCM_ENCODING_SEARCH_SIZE+1];
|
||||||
size_t bytes_read;
|
size_t bytes_read, encoding_length, i;
|
||||||
char *encoding = NULL;
|
char *encoding = NULL;
|
||||||
int utf8_bom = 0;
|
int utf8_bom = 0;
|
||||||
char *pos;
|
char *pos, *encoding_start;
|
||||||
int i;
|
|
||||||
int in_comment;
|
int in_comment;
|
||||||
|
|
||||||
if (SCM_FPORTP (port) && !SCM_FDES_RANDOM_P (SCM_FPORT_FDES (port)))
|
if (SCM_FPORTP (port) && !SCM_FDES_RANDOM_P (SCM_FPORT_FDES (port)))
|
||||||
|
@ -1669,46 +1668,50 @@ scm_i_scan_for_encoding (SCM port)
|
||||||
pos ++;
|
pos ++;
|
||||||
|
|
||||||
/* grab the next token */
|
/* grab the next token */
|
||||||
|
encoding_start = pos;
|
||||||
i = 0;
|
i = 0;
|
||||||
while (pos + i - header <= SCM_ENCODING_SEARCH_SIZE
|
while (encoding_start + i - header <= SCM_ENCODING_SEARCH_SIZE
|
||||||
&& pos + i - header < bytes_read
|
&& encoding_start + i - header < bytes_read
|
||||||
&& (isalnum ((int) pos[i]) || strchr ("_-.:/,+=()", pos[i]) != NULL))
|
&& (isalnum ((int) encoding_start[i])
|
||||||
|
|| strchr ("_-.:/,+=()", encoding_start[i]) != NULL))
|
||||||
i++;
|
i++;
|
||||||
|
|
||||||
if (i == 0)
|
encoding_length = i;
|
||||||
|
if (encoding_length == 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
encoding = scm_gc_strndup (pos, i, "encoding");
|
encoding = scm_gc_strndup (encoding_start, encoding_length, "encoding");
|
||||||
for (i = 0; i < strlen (encoding); i++)
|
for (i = 0; i < encoding_length; i++)
|
||||||
encoding[i] = toupper ((int) encoding[i]);
|
encoding[i] = toupper ((int) encoding[i]);
|
||||||
|
|
||||||
/* push backwards to make sure we were in a comment */
|
/* push backwards to make sure we were in a comment */
|
||||||
in_comment = 0;
|
in_comment = 0;
|
||||||
while (pos - i - header > 0)
|
pos = encoding_start;
|
||||||
|
while (pos >= header)
|
||||||
{
|
{
|
||||||
if (*(pos - i) == '\n')
|
if (*pos == '\n')
|
||||||
{
|
{
|
||||||
/* This wasn't in a semicolon comment. Check for a
|
/* This wasn't in a semicolon comment. Check for a
|
||||||
hash-bang comment. */
|
hash-bang comment. */
|
||||||
char *beg = strstr (header, "#!");
|
char *beg = strstr (header, "#!");
|
||||||
char *end = strstr (header, "!#");
|
char *end = strstr (header, "!#");
|
||||||
if (beg < pos && pos < end)
|
if (beg < encoding_start && encoding_start + encoding_length < end)
|
||||||
in_comment = 1;
|
in_comment = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (*(pos - i) == ';')
|
if (*pos == ';')
|
||||||
{
|
{
|
||||||
in_comment = 1;
|
in_comment = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
i ++;
|
pos --;
|
||||||
}
|
}
|
||||||
if (!in_comment)
|
if (!in_comment)
|
||||||
/* This wasn't in a comment */
|
/* This wasn't in a comment */
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (utf8_bom && strcmp(encoding, "UTF-8"))
|
if (utf8_bom && strcmp(encoding, "UTF-8"))
|
||||||
scm_misc_error (NULL,
|
scm_misc_error (NULL,
|
||||||
"the port input declares the encoding ~s but is encoded as UTF-8",
|
"the port input declares the encoding ~s but is encoded as UTF-8",
|
||||||
scm_list_1 (scm_from_locale_string (encoding)));
|
scm_list_1 (scm_from_locale_string (encoding)));
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue