descriptionThe pp (prepend) utility takes the content of the file named by the source operand and inserts or prepends it above the first line of the file named by the target operand.
owneralessio.chiapperini@nullbuffer.com
last changeTue, 3 May 2022 15:38:40 +0000 (3 17:38 +0200)
content tags
add:
README.md

pp (prepend)

The pp (prepend) utility takes the content of the file named by the source operand and inserts or prepends it above the first line of the file named by the target operand. The file operands are processed in command-line order. If the source file is a single dash (‘-’) or absent, pp reads from the standard input.

So, essentially, if I have a CSV file without a header and I want to quickly insert the header from a file, I would run:

$ pp header.txt spreadsheet.csv

and it would be functionally equivalent to

$ cat header.txt spreadsheet.csv > temp
$ mv temp spreadsheet.csv

Features

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

Using pp is quite simple, you just specify the source file and target file

$ pp source target

The source file however, can be omitted, in this case the program takes the input from the standard input until EOF or ^D is reached

$ pp target

this behavior can also be achieved by using ‘-’ as source file

$ pp - target

Compilation

In order to build on any Unix-like system, simply run make. Since the binary does not have any dependencies, it can just be copied into your PATH.

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

./test/harness.sh
[----------] Test environment set-up.
[==========] Running 7 test cases.
[ RUN      ] empty_source
[       OK ] empty_source
[ RUN      ] empty_destination
[       OK ] empty_destination
[ RUN      ] trivial_test
[       OK ] trivial_test
[ RUN      ] stdin_source
[       OK ] stdin_source
[ RUN      ] utf8_source
[       OK ] utf8_source
[ RUN      ] filename_dash
[       OK ] filename_dash
[ RUN      ] opt_source
[       OK ] opt_source
[==========] 7 test cases ran.
[  PASSED  ] 7 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 on the issue tracker.

License

BSD 2-Clause FreeBSD License, see LICENSE.

shortlog
2022-05-03 Alessio ChiapperiniUpdate scan-build wrapper scriptmaster
2022-05-03 Alessio ChiapperiniFix shellcheck errors/warnings
2022-04-01 Alessio ChiapperiniUpdate mailing list
2021-12-03 Alessio ChiapperiniAdd Contributing and License sections in README.md
2021-11-15 Alessio ChiapperiniMerge branch 'master' of git.sr.ht:~spidernet/pp
2021-11-15 Alessio ChiapperiniUse common (gcc/clang) security flags
2021-11-14 Alessio ChiapperiniUpdate license headers to conform to BSD 2-clause
2021-10-26 Alessio ChiapperiniAdd gitignore
2021-09-28 spidernetAdd SPDX License identifier
2021-09-27 spidernetChange $() expansion to ${} [1bbf2b30978]
2021-09-26 spidernetAdd explanation on how to provide own make flags
2021-09-26 spidernetChange CC to clang
2021-09-26 spidernetUpdate Makefile flags
2021-09-15 spidernetIgnore return values of fprintf and fclose
2021-09-15 spidernetFix bullet list in README
2021-09-15 spidernetUpdate README.md
...
heads
23 months ago master