mirror of
https://https.git.savannah.gnu.org/git/gettext.git
synced 2026-01-26 07:37:57 +00:00
Support CR/LF line terminators in Python sources even on Unix.
This commit is contained in:
parent
d4661005c1
commit
ea9a855bf0
@ -1,3 +1,9 @@
|
||||
2013-04-22 Daiki Ueno <ueno@gnu.org>
|
||||
|
||||
Support CR/LF line terminators in Python sources even on Unix.
|
||||
* x-python.c (phase0_getc, phase0_ungetc): New functions.
|
||||
(phase1_getc): Use them instead of calling getc/ungetc directly.
|
||||
|
||||
2013-04-22 Daiki Ueno <ueno@gnu.org>
|
||||
|
||||
Support explicit string concatenation in Python.
|
||||
|
||||
@ -149,6 +149,46 @@ static int line_number;
|
||||
static FILE *fp;
|
||||
|
||||
|
||||
/* 0. Terminate line by \n, regardless whether the external
|
||||
representation of a line terminator is CR (Mac), and CR/LF
|
||||
(DOS/Windows), as Python treats them equally. */
|
||||
static int
|
||||
phase0_getc ()
|
||||
{
|
||||
int c;
|
||||
|
||||
c = getc (fp);
|
||||
if (c == EOF)
|
||||
{
|
||||
if (ferror (fp))
|
||||
error (EXIT_FAILURE, errno, _("error while reading \"%s\""),
|
||||
real_file_name);
|
||||
return EOF;
|
||||
}
|
||||
|
||||
if (c == '\r')
|
||||
{
|
||||
int c1 = getc (fp);
|
||||
|
||||
if (c1 != EOF && c1 != '\n')
|
||||
ungetc (c1, fp);
|
||||
|
||||
/* Seen line terminator CR or CR/LF. */
|
||||
return '\n';
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
/* Supports only one pushback character, and not '\n'. */
|
||||
static inline void
|
||||
phase0_ungetc (int c)
|
||||
{
|
||||
if (c != EOF)
|
||||
ungetc (c, fp);
|
||||
}
|
||||
|
||||
|
||||
/* 1. line_number handling. */
|
||||
|
||||
/* Maximum used, roughly a safer MB_LEN_MAX. */
|
||||
@ -165,17 +205,7 @@ phase1_getc ()
|
||||
if (phase1_pushback_length)
|
||||
c = phase1_pushback[--phase1_pushback_length];
|
||||
else
|
||||
{
|
||||
c = getc (fp);
|
||||
|
||||
if (c == EOF)
|
||||
{
|
||||
if (ferror (fp))
|
||||
error (EXIT_FAILURE, errno, _("error while reading \"%s\""),
|
||||
real_file_name);
|
||||
return EOF;
|
||||
}
|
||||
}
|
||||
c = phase0_getc ();
|
||||
|
||||
if (c == '\n')
|
||||
++line_number;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user