I was looking for a simple utility that will work like dos2unix tool on Linux to convert endlines from DOS to UNIX. I was scraping some contents from a server running .NET and those ugly ^M characters appeared in vim.
I found this https://ccrma.stanford.edu/~craig/utility/flip/, downloaded the PPC binary and used it happily for a while.
That is until I upgraded to Lion. I am not an expert in Mac OS X yet, but since Lion took away Rosetta and PPC codes away I got this:
Launch of "flip" failed: the PowerPC architecture is no longer supported.
The “file” utility gave me this:
flip: Mach-O executable ppc
Since I have the old Xcode installed on my machine, I thought I’d try and build it since the source code (a single .cpp file) is provided at the URL above.
Here’s how I was able to build it:
g++ -ansi -O3 -o flip flip.cpp \ -I/Developer/SDKs/MacOSX10.6.sdk/usr/include/c++/4.2.1 \ -I/Developer/SDKs/MacOSX10.6.sdk/usr/include \ -I/Developer/SDKs/MacOSX10.6.sdk/usr/include/c++/4.2.1/x86_64-apple-darwin10 \ -L/Developer/SDKs/MacOSX10.6.sdk/usr/lib && strip flip
The three -I provided it with the include paths, and the -L provided the libraries for the binary to link to. To run the compilers, you need to add them to your PATH: /Developer/usr/bin
Now flip runs well:
Usage: ./flip [-t|-u|-d|-m] filename[s] Converts ASCII files between Unix, MS-DOS/Windows, or Macintosh newline formats Options: -u = convert file(s) to Unix newline format (newline) -d = convert file(s) to MS-DOS/Windows newline format (linefeed + newline) -m = convert file(s) to Macintosh newline format (linefeed) -t = display current file type, no file modifications
And “file” recognizes it as:
flip: Mach-O 64-bit executable x86_64
If you have the new Xcode 4.1 (the one that Apple just released for free in App Store), you might need to change certain paths. You’ll have to look at the errors and adjust your parameters.
I am not sure whether my development tool paths were removed as a result of Lion upgrade, but I am currently downloading Xcode 4.1 to the machine. Let’s see whether it’ll automatically set the INCLUDE, LIB, and add the development tools into my PATH.
If it does, then compiling might even be as easy as:
g++ -ansi -O3 -o flip flip.cpp && strip flip