+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.
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. */
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;