2 The **line** utility reads from standard input, printing ranges of lines and columns to standard output.
6 * Compiled with security hardening flags.
7 * Static analysis integrated using clang's `scan-build` using checkers `alpha.security`, `alpha.core.CastSize`,
8 `alpha.core.CastToStruct`, `alpha.core.IdenticalExpr`, `alpha.core.PointerArithm`, `alpha.core.PointerSub`,
9 `alpha.core.SizeofPtr`, `alpha.core.TestAfterDivZero`, `alpha.unix`.
11 * Follows [FreeBSD coding style](https://www.freebsd.org/cgi/man.cgi?query=style&sektion=9).
13 * C99 compliant *and* may be built in an environment which provides POSIX.1-2001 system interfaces.
14 * Self-contained, no external dependencies
15 * Easy to compile and uses POSIX make.
18 * Input lines are limited to `LINE_MAX` bytes in length.
21 The only dependency is a toolchain supporting the following flags:
24 CFLAGS = -std=c99 -O2 -Wall -Wextra -Wpedantic \
25 -Walloca -Wcast-qual -Wconversion -Wformat=2 -Wformat-security \
26 -Wnull-dereference -Wstack-protector -Wvla -Warray-bounds \
27 -Wbad-function-cast -Wconversion -Wshadow -Wstrict-overflow=4 -Wundef \
28 -Wstrict-prototypes -Wswitch-default -Wfloat-equal -Wimplicit-fallthrough \
29 -Wpointer-arith -Wswitch-enum \
31 -fstack-protector-strong -fPIE -fstack-clash-protection
33 LDFLAGS = -Wl,-z,relro -Wl,-z,now -Wl,-z,noexecstack -Wl,-z,separate-code
36 Otherwise you can just remove the security flags and compile it with
38 CFLAGS = -std=c99 -O2 -Wall -Wextra -Wpedantic
42 or pass your own flags to make
44 make CC=gcc CFLAGS=... LDFLAGS=...
48 Clone this repository then
51 $ make PREFIX=/usr install
54 This will install the compiled binary under `PREFIX` (`/usr/bin`) in this case, if not specified `PREFIX` will default
55 to `/usr/local`. For staged installs, `DESTDIR` is also supported. As the binary does not have any dependency it does
56 not have to be installed before use.
59 The _range_ parameter is used to express a range of lines or columns to be printed. The lower and upper bounds of the
60 interval must be positive integer numbers. If the lower bound is equal to the upper bound, only one line (or column)
61 will be printed. If the upper bound is greater than the amount of lines (or columns) the output stops at the last line
64 The options are as follows:
66 * **-c** Interpret the specified range a range of columns. The result is that it prints the contents of the file within
68 * **-h** Print usage information and exit.
71 Print lines between 5 and 23 from standard input until it receives an EOF (`^D`) character
76 Print, for each line, the characters between column 5 and 100
87 The test suite consists of a POSIX shell script called `harness.sh` contained in the `test` folder. It's output is
88 similar to [googletest](https://github.com/google/googletest)'s and it can be invoked with `make test` which, if
89 everything is working should output something similar to
91 (cd test && ./harness.sh)
92 [----------] Test environment set-up.
93 [==========] Running 6 test cases.
94 [ RUN ] should_handle_stdin
95 [ OK ] should_handle_stdin
96 [ RUN ] should_handle_singleline
97 [ OK ] should_handle_singleline
98 [ RUN ] should_handle_singlecolumn
99 [ OK ] should_handle_singlecolumn
100 [ RUN ] should_handle_multiplelines
101 [ OK ] should_handle_multiplelines
102 [ RUN ] should_handle_multiplecolumns
103 [ OK ] should_handle_multiplecolumns
104 [ RUN ] should_handle_empty_string
105 [ OK ] should_handle_empty_string
106 [==========] 6 test cases ran.
109 [----------] Test environment teardown.
113 Static analysis on the code base is done by using clang's static analyzer run through `scan-build.sh` which wraps the
114 `scan-build` utility. The checkers used are part of the
115 [Experimental Checkers](https://releases.llvm.org/12.0.0/tools/clang/docs/analyzer/checkers.html#alpha-checkers)
116 (aka *alpha* checkers):
119 * `alpha.core.CastSize`
120 * `alpha.core.CastToStruct`
121 * `alpha.core.IdenticalExpr`
122 * `alpha.core.PointerArithm`
123 * `alpha.core.PointerSub`
124 * `alpha.core.SizeofPtr`
125 * `alpha.core.TestAfterDivZero`
129 BSD 2-Clause FreeBSD License, see LICENSE.