descriptionCLI utility for printing ranges of lines are columns
owneralessio.chiapperini@nullbuffer.com
last changeFri, 2 Dec 2022 10:47:00 +0000 (2 11:47 +0100)
content tags
add:
README.md

line

The line utility reads from standard input, printing ranges of lines and columns to standard output.

Features

Limitations

Build dependencies

The only dependency is a toolchain supporting the following flags:

CFLAGS = -std=c99 -O2 -Wall -Wextra -Wpedantic \
        -Walloca -Wcast-qual -Wconversion -Wformat=2 -Wformat-security \
        -Wnull-dereference -Wstack-protector -Wvla -Warray-bounds \
        -Wbad-function-cast -Wconversion -Wshadow -Wstrict-overflow=4 -Wundef \
        -Wstrict-prototypes -Wswitch-default -Wfloat-equal -Wimplicit-fallthrough \
        -Wpointer-arith -Wswitch-enum \
        -D_FORTIFY_SOURCE=2 \
        -fstack-protector-strong -fPIE -fstack-clash-protection

LDFLAGS = -Wl,-z,relro -Wl,-z,now -Wl,-z,noexecstack -Wl,-z,separate-code

Otherwise you can just remove the security flags and compile it with

CFLAGS = -std=c99 -O2 -Wall -Wextra -Wpedantic
LDFLAGS =

or pass your own flags to make

make CC=gcc CFLAGS=... LDFLAGS=...

Installation

Clone this repository then

$ make PREFIX=/usr install

This will install the compiled binary under PREFIX (/usr/bin) in this case, if not specified PREFIX will default to /usr/local. For staged installs, DESTDIR is also supported. As the binary does not have any dependency it does not have to be installed before use.

Usage

The range parameter is used to express a range of lines or columns to be printed. The lower and upper bounds of the interval must be positive integer numbers. If the lower bound is equal to the upper bound, only one line (or column) will be printed. If the upper bound is greater than the amount of lines (or columns) the output stops at the last line (or column).

The options are as follows:

Examples

Print lines between 5 and 23 from standard input until it receives an EOF (^D) character

$ line '5,23'

Print, for each line, the characters between column 5 and 100

$ line -c "5,100"

Print only line 7

$ line '7,7'

Test suite

The test suite consists of a POSIX shell script called harness.sh contained in the test folder. It's output is similar to googletest's and it can be invoked with make test which, if everything is working should output something similar to

(cd test && ./harness.sh)
[----------] Test environment set-up.
[==========] Running 6 test cases.
[ RUN      ] should_handle_stdin
[       OK ] should_handle_stdin
[ RUN      ] should_handle_singleline
[       OK ] should_handle_singleline
[ RUN      ] should_handle_singlecolumn
[       OK ] should_handle_singlecolumn
[ RUN      ] should_handle_multiplelines
[       OK ] should_handle_multiplelines
[ RUN      ] should_handle_multiplecolumns
[       OK ] should_handle_multiplecolumns
[ RUN      ] should_handle_empty_string
[       OK ] should_handle_empty_string
[==========] 6 test cases ran.
[  PASSED  ] 6 tests.
[  FAILED  ] 0 tests.
[----------] Test environment teardown.

Static analysis

Static analysis on the code base is done by using clang's static analyzer run through scan-build.sh which wraps the scan-build utility. The checkers used are part of the Experimental Checkers (aka alpha checkers):

License

BSD 2-Clause FreeBSD License, see LICENSE.

shortlog
2022-12-02 Alessio ChiapperiniFix typo in README and manualmaster
2022-12-02 Alessio ChiapperiniInitial commit
heads
16 months ago master