descriptionCLI utility for printing sequences of numbers and characters in a given range
owneralessio.chiapperini@nullbuffer.com
last changeFri, 29 Apr 2022 22:13:21 +0000 (30 00:13 +0200)
content tags
add:
README.md

range

The range utility prints a sequence of numbers or characters in the range [first, last] in the given number of steps. Both the separator between each element of the sequence and the terminator can be specified.

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

range receives as input the bounds of the range and an optional increment (positive or negative). In case the increment is omitted it defaults either 1 or -1 depending on whether the lower bound is greater than the upper bound or viceversa.

The options are as follows:

Examples

$ range 0 2 20
0
2
4
6
8
10
12
14
16
18
20
$ range -s , 'a' 'z'
a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,
$ range 10 5
10
9
8
7
6
5
$ range -s "\t" -t "\n" 1 10
1       2       3       4       5       6       7       8       9       10

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 9 test cases.
[ RUN      ] should_handle_increasing_num_range
[       OK ] should_handle_increasing_num_range
[ RUN      ] should_handle_decreasing_num_range
[       OK ] should_handle_decreasing_num_range
[ RUN      ] should_handle_increasing_char_range
[       OK ] should_handle_increasing_char_range
[ RUN      ] should_handle_decreasing_char_range
[       OK ] should_handle_decreasing_char_range
[ RUN      ] should_handle_explicit_increment
[       OK ] should_handle_explicit_increment
[ RUN      ] should_handle_explicit_decrement
[       OK ] should_handle_explicit_decrement
[ RUN      ] should_handle_sflag
[       OK ] should_handle_sflag
[ RUN      ] should_handle_tflag
[       OK ] should_handle_tflag
[ RUN      ] should_handle_singleton
[       OK ] should_handle_singleton
[==========] 9 test cases ran.
[  PASSED  ] 9 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):

Contributing

Send patches on the mailing list, report bugs using git-bug.

License

BSD 2-Clause FreeBSD License, see LICENSE.

shortlog
2022-04-29 Alessio ChiapperiniFix shellcheck errors/warningsmaster
2022-04-22 Alessio ChiapperiniMake sflag test run on both GNU and BSD systems
2022-04-21 Alessio ChiapperiniUpdate mailing list link
2022-04-21 Alessio ChiapperiniFix harness issues on systems with GNU utilities
2022-04-20 Alessio ChiapperiniRemove extra escape
2022-04-20 Alessio ChiapperiniAdd range implementation
2022-04-15 Alessio ChiapperiniClean README.md
2022-04-15 Alessio ChiapperiniInitial commit
heads
23 months ago master