description | CLI utility for printing sequences of numbers and characters in a given range |
owner | alessio.chiapperini@nullbuffer.com |
last change | Tue, 28 May 2024 10:06:17 +0000 (28 12:06 +0200) |
URL | git://repo.or.cz/range.git |
https://repo.or.cz/range.git | |
push URL | ssh://repo.or.cz/range.git |
https://repo.or.cz/range.git (learn more) | |
bundle info | range.git downloadable bundles |
content tags |
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.
scan-build
using checkers alpha.security
, alpha.core.CastSize
,
alpha.core.CastToStruct
, alpha.core.IdenticalExpr
, alpha.core.PointerArithm
, alpha.core.PointerSub
,
alpha.core.SizeofPtr
, alpha.core.TestAfterDivZero
, alpha.unix
.first
, last
and increment
parameters are INT_MIN
and INT_MAX
respectively.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=...
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.
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:
'\n'
is used.$ 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
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 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):
alpha.security
alpha.core.CastSize
alpha.core.CastToStruct
alpha.core.IdenticalExpr
alpha.core.PointerArithm
alpha.core.PointerSub
alpha.core.SizeofPtr
alpha.core.TestAfterDivZero
alpha.unix
Send patches on the mailing list, report bugs using git-bug.
BSD 2-Clause FreeBSD License, see LICENSE.
10 days ago | Alessio Chiapperini | Explicitly write out inference rule for .c.omaster | commitcommitdifftreesnapshot (tar.gz zip) |
2022-04-29 | Alessio Chiapperini | Fix shellcheck errors/warnings | commitcommitdifftreesnapshot (tar.gz zip) |
2022-04-22 | Alessio Chiapperini | Make sflag test run on both GNU and BSD systems | commitcommitdifftreesnapshot (tar.gz zip) |
2022-04-21 | Alessio Chiapperini | Update mailing list link | commitcommitdifftreesnapshot (tar.gz zip) |
2022-04-21 | Alessio Chiapperini | Fix harness issues on systems with GNU utilities | commitcommitdifftreesnapshot (tar.gz zip) |
2022-04-20 | Alessio Chiapperini | Remove extra escape | commitcommitdifftreesnapshot (tar.gz zip) |
2022-04-20 | Alessio Chiapperini | Add range implementation | commitcommitdifftreesnapshot (tar.gz zip) |
2022-04-15 | Alessio Chiapperini | Clean README.md | commitcommitdifftreesnapshot (tar.gz zip) |
2022-04-15 | Alessio Chiapperini | Initial commit | commitcommitdifftreesnapshot (tar.gz zip) |
10 days ago | master | logtree |