descriptionFeed and consume input lines processed by utility
owneralessio.chiapperini@nullbuffer.com
last changeThu, 31 Mar 2022 07:10:20 +0000 (31 09:10 +0200)
content tags
add:
README.md

consume

The consume program splits input, feeds it into the given utility and consumes it if successful.

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

consume [-0ach] [-i file] [-v] [utility [argument ...]]

The consume program reads input from the file named by the file operand or from stdin if absent, and splits it when encountering the given delimiter (defaults to newline). It then invokes the utility repeatedly, feeding it the generated data as input. On success the given data is consumed (removed) from the input file, if any.

The options are as follows:

Examples

Count the number of words in each line of 'La Divina Commedia':

$ curl -s https://dmf.unicatt.it/~della/pythoncourse18/commedia.txt | consume wc -w

Find files named core in or below the directory /tmp and delete them. Before deleting each file the full command is printed to stderr:

$ find /tmp -name core -type f -print | consume -a -v /bin/rm -f

Consume all lines delimited by 0 in biglistoflinks.txt that wget has downloaded successfully:

$ consume -0 -a -i biglistoflinks.txt wget -qc

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 on the issue tracker.

License

BSD 2-Clause FreeBSD License, see LICENSE.

shortlog
2022-03-31 Alessio ChiapperiniUpdate mailing list linkmaster
2022-03-02 Alessio ChiapperiniRemove dead code
2022-03-02 Alessio ChiapperiniRework unecessary complex if
2022-03-02 Alessio ChiapperiniAdd remaining lines to input file
2022-03-02 Alessio ChiapperiniUpdate examples
2022-03-02 Alessio ChiapperiniAdd limitation about file names length
2022-03-01 Alessio ChiapperiniTest flag values explicitly
2022-03-01 Alessio ChiapperiniRefactor out execution code and implement -a flag
2022-02-28 Alessio ChiapperiniImplement core functionality (consume/consume_file)
2022-02-01 Alessio ChiapperiniAdd README.md
2022-01-31 Alessio ChiapperiniAdd manpage
2022-01-31 Alessio ChiapperiniChange name of input file
2022-01-30 Alessio ChiapperiniAdd -c flag
2022-01-29 Alessio ChiapperiniAdd readinput function
2022-01-29 Alessio ChiapperiniRemove -Werror from CFLAGS
2022-01-29 Alessio ChiapperiniChange command-line flags
...
heads
2 years ago master