Giter VIP home page Giter VIP logo

endlines's Introduction

Version 1.9.2 Apache License 2.0

Did your source code get polluted by scattered ^M's ?

Endlines smartly converts text files from and to the following line ending conventions : Unix/Apple (LF), Windows (CRLF) and legacy Apple (CR).

endlines unix *
  • No need to know about the source files' convention. Multiple conventions can be mixed within a single file.
  • Straightforward syntax for multiple files and recursion into directories. Hidden files and directories are skipped by default (you don't want to mess with your .git, do you ?)
  • Binary files will be detected and skipped by default, according to a filter based on both file extension and file content.
  • Files' last access and last modified time stamps can be preserved.
  • UTF-8 files, UTF-16 with BOM as well as all single byte encodings will be treated well. However, UTF-32 is not supported (files will be seen as binary and left untouched).
  • Whether converting or checking, a report is given on the original state of line endings that were found.
    $ endlines check -r .
    endlines : dry run, scanning files

    endlines : 6431 files checked ; found :
                  - 142 No line ending
                  - 1 Legacy Mac (CR)
                  - 6250 Unix (LF)
                  - 37 Windows (CR-LF)
                  - 1 Mixed endings
               2403 binaries skipped
               480 hidden files skipped

Full help screen :

    endlines ACTION [OPTIONS] [FILES]
    
    ACTION can be :
      lf, unix, linux, osx    : convert all endings to LF.
      crlf, windows, win, dos : convert all endings to CR-LF.
      cr, oldmac              : convert all endings to CR.
      check                   : perform a dry run to check current conventions.
    
    If no files are specified, endlines converts from stdin to stdout.
    Supports UTF-8, UTF-16 with BOM, and all major single byte codesets.
    
    General   -f / --final    : add final EOL if none.
              -q / --quiet    : silence all but the error messages.
              -v / --verbose  : print more about what's going on.
              --version       : print version and license.
    
    Files     -b / --binaries : don't skip binary files.
              -h / --hidden   : process hidden files (/directories) too.
              -k / --keepdate : keep last modified and last access times.
              -r / --recurse  : recurse into directories.
    
    Examples  endlines check *.txt
              endlines linux -kr aFolder anotherFolder

Easy installation

The download page offers ready-to-eat options for Linux and Apple users.

Compile your own

  • Local install : make; make test ; if satisfied, move the endlines executable to your local path.
  • Global install : make; make test; sudo make install will put an endlines executable in /usr/local/bin.

Endlines is known to have been compiled and run out of the box on Apple OSX, several Linux distributions and IBM AIX. I provide support for all POSIX compliant operating sytems. I won't provide any support for Windows, but pull requests dealing with it will be welcome.

Credits

In particular to :

  • @imalic3 for reporting a bug in a early dev version
  • @hansaya for patiently guiding me towards AIX friendliness
  • @uuencode for finding a critical bug in 1.6.2
  • @ethicalbanker for spotting an inability to compile on OSX
  • @biziclop for providing an OSX binary

endlines's People

Contributors

mdolidon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

endlines's Issues

New Feature : --exclude

Hi!

Congratulation, it's really an useful tools! 👍 👍 👍
Can you plan to add a flag in order to specify list of directories to exclude?

$ endlines --exclude ./subdir1,/home/mdolidon/projects/ednlines/build,./subdir2

-x / --exclude            : doesn´t process sub-directories.

Thank's a lot.

Project outline

Here's a project outline I have in mind. Will submit pull requests. Let me know what you think, and we can edit this outline.

  • Use install command within makefile install target
  • Provide feedback within makefile install and uninstall targets
  • Move help to man file
  • Create AUR package
  • Create Ubuntu package
  • Create brew package
  • GitHub Actions CI/CD to deploy to package repositories on release
  • Remove binaries from repository
    • Compile time of endlines is almost instant. I see no benefit of providing a binary. If you wish to still provide a binary, it could be compiled within a GitHub action and stored as an artifact.

May not add final new-line

Reviewing the pre-conversion check function, it seems that if :

  • the file is already in the target convention
  • it does not have a final EOL
  • a final EOL is requested by the user
    the check may lead to that file being skipped.

To do : test and fix.

Output to STDOUT instead of STDERR

Is there any particular reason that output is written to STDERR and not STDOUT?

This gets broken:

$ endlines check -r -v . | less

Of course, this produces the expected result:

$ endlines check -r -v . 2>&1 | less

Also, on a side note, it is common to allow short flag collapsing, so I expected the below to also work:

$ endlines check -rv .

brew this!

Would love to be able to install/update this with brew. Handy tool that should be spread far and wide.

I've not created a Homebrew Formula myself, which is why I'm not creating a PR ... but here's the Homebrew Formula Cookbook

Picking an example Formula at random 😀 , here's the Formula for dos2unix.

Thanks for the great tool. 👍

(OSX) CLOCK_REALTIME undeclared

Building on a mac:

Apple LLVM version 8.0.0 (clang-800.0.42.1)
Target: x86_64-apple-darwin15.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

I get:

cc -O3 -Wall -std=c99 -c src/file_operations.c -o src/file_operations.o
cc -O3 -Wall -std=c99 -c src/walkers.c -o src/walkers.o
cc -O3 -Wall -std=c99 -c src/convert_stream.c -o src/convert_stream.o
cc -O3 -Wall -std=c99 -c src/main.c -o src/main.o
src/main.c:251:5: warning: implicit declaration of function 'clock_gettime' is invalid in C99 [-Wimplicit-function-declaration]
    clock_gettime(CLOCK_REALTIME, &res);
    ^
src/main.c:251:19: error: use of undeclared identifier 'CLOCK_REALTIME'
    clock_gettime(CLOCK_REALTIME, &res);
                  ^
1 warning and 1 error generated.
make: *** [src/main.o] Error 1

(1.6.2) (title changed) File lost when running on one physical drive while CWD is on another drive

Originally posted by @uuencode

I was unsure if I had to open a new issue. It compiled without errors. When I try to convert a file in a directory it says:

endlines linux -r /mnt/DATA/test
endlines : converting files to Unix (LF)
endlines : could not restore permissions for /mnt/DATA/test/aaa.txt
endlines : could not restore ownership for /mnt/DATA/test/aaa.txt

endlines : 1 file converted from :

  • 1 Windows (CR-LF)

and the file is deleted. With "sudo" the result is the same.

Thank you in advance!


My answer :

That's a new one, and might actually be an unknown and worrysome bug. I'll look into it.
Could you please show me an extract of ls -l for mnt, DATA, test and aaa.txt, so that I can attempt to reproduce it in a similar situation ?

Feature request: less-verbose

Hello! Absolutely great tool @mdolidon
I was hoping for a feature request, which I will gladly make a small condation for.

Lets be honest, most of us use this on Linux to find those pesky Windows CR-LF.
When I try and find files in verbose mode, it prints all the "LF" files, and theres a lot of them. I am really only looking for problematic CR-LF files.
So I was hoping for a less-verbose mode, that would only print

              - No line ending
              - Windows (CR-LF)
              - Mixed endings

And NOT print - Unix (LF)

An example output would be (what Im currently doing): grep -rIl -m 1 $'\r' which only finds the problematic files.

For more configuration, a toggle could be provided to choose between verbose (all) or verbose (some) and somehow choose which few line endings to scan for.

0.3.2 reduce stack volume to accomodate weak OSes

0.3.2 does not depend on dynamic memory allocation anymore. However buffered streams take up a total of 200Kb on the stack. Reduce buffer size to make sure the stack does not exceed 64Kb, to allow running this on OSes with very weak stacks (OpenBSD...). Suggestion : make buffer size be around 20 Kb.

(1.0) it made a .sh file non-executable

I just ran this on some files. Most are just text files but one is a shell script. After the endlines run, I found that the shell script had had its permissions changed so that it was no longer executable. I ran chmod +x on it and it was fine again.

Bug in handling certain filenames

Running endlines recursively as "endlines -r linux *" in a directory containing a file named -prj.ipr (starts with a dash), resulted in the error "Unknown option -p".

Renaming the file solved the problem.

cannot make install / ubuntu 16.04

Sorry to be a pain. I have successfully used endlines with Ubuntu 14.04, now on 16.04 it cannot compile. Here's the result of "sudo make install"

cc -o endlines src/walkers.o src/engine.o src/main.o
src/main.o: In function convert_one_file': main.c:(.text+0xab5): undefined reference toengine_run'
src/main.o: In function check_one_file': main.c:(.text+0xcdd): undefined reference toengine_run'
src/main.o: In function main': main.c:(.text.startup+0xc9): undefined reference toengine_run'
collect2: error: ld returned 1 exit status
makefile:10: recipe for target 'endlines' failed
make: *** [endlines] Error 1

Doesn't compile on Ubuntu 14.04

This tool looks really useful, but I can't use it if it doesn't compile :3.

$ sudo make install
cc -O3 -Wall -std=c99   -c -o src/walkers.o src/walkers.c
src/walkers.c: In function ‘walk_directory’:
src/walkers.c:203:35: error: ‘DT_DIR’ undeclared (first use in this function)
         } else if(pent->d_type == DT_DIR) {
                                   ^
src/walkers.c:203:35: note: each undeclared identifier is reported only once for each function it appears in
src/walkers.c:205:35: error: ‘DT_REG’ undeclared (first use in this function)
         } else if(pent->d_type == DT_REG) {
                                   ^
src/walkers.c:182:11: warning: variable ‘fake_filenames_array’ set but not used [-Wunused-but-set-variable]
     char* fake_filenames_array[1];              // this holder is a convenience
           ^
make: *** [src/walkers.o] Error 1

0.3.2 File opening errcodes aren't checked

Did a hasty refactor this morning, and missed a necessary check on a return value.
TODO :

  • main.c add return value check on open_streams
  • add a test case for non-existent files, or files that can't be written on

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.