0

A set of (DOS) ANSI-C text files (click here to download) was copied to a OSX High Sierra laptop. I would like to ensure that the CR\LF is not an obstacle to to compiling the files. The files seem to be displayed correctly by Sublime and vi.

The three terminators are:

  1. The Mac, by default, uses a single carriage return (CR), represented as \r.
  2. Unix, on the other hand, uses a single linefeed (LF), \n.
  3. Windows goes one step further and uses both, creating a (CRLF) combination, \r\n.

dos2unix was installed:

brew install dos2unix

attempts to process the ANSI-C files returns an errors:

$ dos2unix *.h
dos2unix: Binary symbol 0x1A found at line 75
dos2unix: Skipping binary file error.h
dos2unix: Binary symbol 0x1A found at line 156
dos2unix: Skipping binary file random.h
dos2unix: Binary symbol 0x1A found at line 49
dos2unix: Skipping binary file resource.h
dos2unix: Binary symbol 0x1A found at line 107
dos2unix: Skipping binary file results.h
dos2unix: Binary symbol 0x1A found at line 261
dos2unix: Skipping binary file sim_lib.h
dos2unix: Binary symbol 0x1A found at line 27
dos2unix: Skipping binary file stats.h

.c files

$ dos2unix *.c
dos2unix: Binary symbol 0x1A found at line 110
dos2unix: Skipping binary file error.c
dos2unix: Binary symbol 0x1A found at line 780
dos2unix: Skipping binary file random.c
dos2unix: Binary symbol 0x1A found at line 79
dos2unix: Skipping binary file resource.c
dos2unix: Binary symbol 0x1A found at line 582
dos2unix: Skipping binary file results.c
dos2unix: Binary symbol 0x1A found at line 1755
dos2unix: Skipping binary file sim_lib.c
dos2unix: Binary symbol 0x1A found at line 102
dos2unix: Skipping binary file stats.c

QUESTIONS

What are the steps required to ensure that the correct terminator is applied?

How can one visualize (verify) which terminator is engaged? (CR \ LF \ CRLF)

Update

The -f (force) flag will ignore the 0x1A and process the file. Recursively find .c files:

user@hostname:~/csim$ find . -name '*.c' | xargs dos2unix -f
gatorback
  • 1,384
  • 23
  • 48
  • Should you post an example of the relevant error lines (in hex with od for example)? –  Jan 27 '20 at 23:19
  • 2
    You may want to have a look at some or all of those files to figure out what role that 0x1a character is playing in each of them. It seems unrelated to line termination. – Kusalananda Jan 27 '20 at 23:21
  • Answers do not go in questions. – JdeBP Jan 28 '20 at 11:38

1 Answers1

1

Here is a simple test :

~/tmp$ printf "\x1Aabc\r\n" > test
~/tmp$ od -a test
0000000  sub   a   b   c  cr  nl                                        
0000006
~/tmp$ dos2unix test
dos2unix: Binary symbol 0x1A found at line 1
dos2unix: Skipping binary file test
~/tmp$ dos2unix -f test
dos2unix: converting file test to Unix format...
~/tmp$ od -a test
0000000  sub   a   b   c  nl                                            
0000005

. Use dos2unix -f to force conversion

. Use od -a to view binary file

. Terminator on Mac is LF as well.

Philippe
  • 1,435