1

I tried to use GNU indent (v 2.2.12) on a source file that has CRLF terminators, with unexpected errors that I could not understand from the source code. The output file was like randomly indented.

Then I converted the file to regular Unix file with only LF terminators, and it removed the errors. The output file was indented as expected.

I could not find anything about this, so do you know anything as to the regular/expected behaviour of GNU indent regarding line terminators ?

Do you know how to make indent behave properly with any C source file ?

Here is the (commented and indented) terminal log of what I saw :

user@pc:~$ file main.c
    main.c: C source, ASCII text, with CRLF line terminators

user@pc:~$ indent main.c > output.c                     # ERRORS
    indent: main.c:1187: Error:Stmt nesting error.
    indent: main.c:1306: Error:Stmt nesting error.
    indent: main.c:1468: Error:Unmatched 'else'
    indent: main.c:1645: Error:Unexpected end of file

user@pc:~$ sed -i s.$'\r'..g main.c     # Changing CRLF to LF
user@pc:~$ file main.c
    main.c: C source, ASCII text

user@pc:~$ indent main.c > output.c     # NO ERROR
Axel B
  • 111
  • 3
  • I wonder if, like `bash`, `indent` assumes/requires POSIX line endings. If so, the carriage returns aren't treated as whitespace. – chepner Apr 05 '22 at 14:35
  • 1
    See https://github.com/msys2/MINGW-packages/issues/7223 and https://github.com/msys2/MINGW-packages/pull/8841 for some recent `indent` bugs with CR-LF files. Those all post-date the release of 2.2.12. – Andrew Henle Apr 05 '22 at 14:37
  • You're right, I saw that a fix was submitted on the MINGW version of ``indent`` almost a year ago, I will try to check in ``GNU indent``'s repo – Axel B Apr 06 '22 at 13:15

0 Answers0