bug-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: gettext fails at windows line end


From: Bruno Haible
Subject: Re: gettext fails at windows line end
Date: Tue, 14 Oct 2003 12:42:46 +0200
User-agent: KMail/1.5

Christoph Thielecke wrote:
> I try to extract strings from cpp files.
> It fails if the text is not in unix format...
> extract should also work if the line end is windows.

Thanks for reporting this. Here is a patch.

Bruno


*** gettext-0.12.1/gettext-tools/src/x-c.c.bak  2002-11-14 15:53:39.000000000 
+0100
--- gettext-0.12.1/gettext-tools/src/x-c.c      2003-10-14 00:34:05.000000000 
+0200
***************
*** 226,235 ****
  static FILE *fp;
  
  
! /* 1. Terminate line by \n, regardless of the external representation of
!    a text line.  Stdio does this for us, we just need to check that
!    there are no I/O errors, and cope with potentially 2 characters of
!    pushback, not just the one that ungetc can cope with.  */
  
  /* Maximum used guaranteed to be < 4.  */
  static unsigned char phase1_pushback[4];
--- 226,283 ----
  static FILE *fp;
  
  
! /* 0. Terminate line by \n, regardless whether the external representation of
!    a line terminator is LF (Unix), CR (Mac) or CR/LF (DOS/Windows).
!    It is debatable whether supporting CR/LF line terminators in C sources
!    on Unix is ISO C or POSIX compliant, but since GCC 3.3 now supports it
!    unconditionally, it must be OK.
!    The so-called "text mode" in stdio on DOS/Windows translates CR/LF to \n
!    automatically, but here we also need this conversion on Unix.  As a side
!    effect, on DOS/Windows we also parse CR/CR/LF into a single \n, but this
!    is not a problem.  */
! 
! 
! 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;
! }
! 
! 
! /* Only one pushback character supported, and not '\n'.  */
! static inline void
! phase0_ungetc (int c)
! {
!   if (c != EOF)
!     ungetc (c, fp);
! }
! 
! 
! /* 1. line_number handling.  Combine backslash-newline to nothing.
!    Cope with potentially 2 characters of pushback, not just the one that
!    ungetc can cope with.  */
  
  /* Maximum used guaranteed to be < 4.  */
  static unsigned char phase1_pushback[4];
***************
*** 250,282 ****
      }
    for (;;)
      {
!       c = getc (fp);
        switch (c)
        {
-       case EOF:
-         if (ferror (fp))
-           {
-           bomb:
-             error (EXIT_FAILURE, errno, _("\
- error while reading \"%s\""), real_file_name);
-           }
-         return EOF;
- 
        case '\n':
          ++line_number;
          return '\n';
  
        case '\\':
!         c = getc (fp);
!         if (c == EOF)
!           {
!             if (ferror (fp))
!               goto bomb;
!             return '\\';
!           }
          if (c != '\n')
            {
!             ungetc (c, fp);
              return '\\';
            }
          ++line_number;
--- 298,315 ----
      }
    for (;;)
      {
!       c = phase0_getc ();
        switch (c)
        {
        case '\n':
          ++line_number;
          return '\n';
  
        case '\\':
!         c = phase0_getc (fp);
          if (c != '\n')
            {
!             phase0_ungetc (c);
              return '\\';
            }
          ++line_number;





reply via email to

[Prev in Thread] Current Thread [Next in Thread]