1 year ago

#377976

test-img

Axel B

How to make GNU indent support CRLF terminators?

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

c

shell

newline

auto-indent

gnu-indent

0 Answers

Your Answer

Accepted video resources