utilities
This commit is contained in:
parent
3a6762e153
commit
3334b25b77
99
Makefile
Normal file
99
Makefile
Normal file
@ -0,0 +1,99 @@
|
||||
CC=cc
|
||||
CFLAGS=-I include/ -I lib/ -Wall -Werror
|
||||
RM=rm -f
|
||||
|
||||
all: libraries programs
|
||||
|
||||
cleanall: clean cleanlibraries cleanprograms
|
||||
|
||||
clean:
|
||||
$(RM) src/*.o
|
||||
|
||||
cleanlibraries:
|
||||
$(RM) lib/libshell.o
|
||||
$(RM) lib/libstr.o
|
||||
|
||||
cleanprograms:
|
||||
$(RM) bin/add
|
||||
$(RM) bin/cut
|
||||
$(RM) bin/echo
|
||||
$(RM) bin/eq
|
||||
$(RM) bin/false
|
||||
$(RM) bin/fdivide
|
||||
$(RM) bin/gt
|
||||
$(RM) bin/lowercase
|
||||
$(RM) bin/lt
|
||||
$(RM) bin/mm
|
||||
$(RM) bin/multiply
|
||||
$(RM) bin/nonzero
|
||||
$(RM) bin/simexec
|
||||
$(RM) bin/sleep
|
||||
$(RM) bin/streq
|
||||
$(RM) bin/stris
|
||||
$(RM) bin/substitute
|
||||
$(RM) bin/tail
|
||||
|
||||
libraries: libshell libstr stdbool sysexits
|
||||
|
||||
libshell: lib/libshell.c lib/libshell.h
|
||||
$(CC) $(CFLAGS) -o lib/libshell.o -c lib/libshell.c
|
||||
|
||||
libstr: lib/libstr.c lib/libstr.h
|
||||
$(CC) $(CFLAGS) -o lib/libstr.o -c lib/libstr.c
|
||||
|
||||
stdbool: include/stdbool.h
|
||||
|
||||
sysexits: src/sysexits.c
|
||||
$(CC) $(CFLAGS) -o bin/sysexits src/sysexits.c
|
||||
bin/sysexits >include/sysexits.h
|
||||
|
||||
programs: echo false nonzero simexec sleep streq stris
|
||||
|
||||
calculate: libstr sysexits src/calculate.c
|
||||
$(CC) $(CFLAGS) -o src/calculate.o -c src/calculate.c
|
||||
$(CC) $(CFLAGS) -o bin/calculate lib/libstr.o src/calculate.o
|
||||
|
||||
echo: sysexits src/echo.c
|
||||
$(CC) $(CFLAGS) -o bin/echo src/echo.c
|
||||
|
||||
false: src/false.c
|
||||
$(CC) $(CFLAGS) -o bin/false src/false.c
|
||||
|
||||
id: stdbool sysexits src/id.c
|
||||
$(CC) $(CFLAGS) -o bin/id src/id.c
|
||||
|
||||
levenshtein: src/levenshtein.c
|
||||
$(CC) $(CFLAGS) -o bin/levenshtein src/levenshtein.c
|
||||
|
||||
lowercase: sysexits src/lowercase.c
|
||||
$(CC) $(CFLAGS) -o bin/lowercase src/lowercase.c
|
||||
|
||||
nonzero: src/nonzero.c
|
||||
$(CC) $(CFLAGS) -o bin/nonzero src/nonzero.c
|
||||
|
||||
runlength: noargvzero sysexits src/runlength.c
|
||||
$(CC) $(CFLAGS) -o bin/runlength src/runlength.c
|
||||
|
||||
simexec: noargvzero sysexits src/simexec.c
|
||||
$(CC) $(CFLAGS) -o bin/simexec src/simexec.c
|
||||
|
||||
streq: noargvzero sysexits src/streq.c
|
||||
$(CC) $(CFLAGS) -o bin/streq src/streq.c
|
||||
|
||||
stris: libstr src/stris.c
|
||||
$(CC) $(CFLAGS) -c -o src/stris.o src/stris.c
|
||||
$(CC) $(CFLAGS) -o bin/stris lib/libstr.o src/stris.o
|
||||
|
||||
sleep: libstr noargvzero sysexits src/sleep.c
|
||||
$(CC) $(CFLAGS) -c -o src/sleep.o src/sleep.c
|
||||
$(CC) $(CFLAGS) -o bin/sleep lib/libstr.o src/sleep.o
|
||||
|
||||
substitute: stdbool src/substitute.c
|
||||
$(CC) $(CFLAGS) -c -o src/substitute.o src/substitute.c
|
||||
$(CC) $(CFLAGS) -o bin/substitute src/substitute.o
|
||||
|
||||
which: libshell src/which.c
|
||||
$(CC) $(CFLAGS) -c -o src/which.o src/which.c
|
||||
$(CC) $(CFLAGS) -o bin/which lib/libshell.o src/which.o
|
||||
|
||||
.PHONY: all clean cleanlibraries cleanprograms noargvzero stdbool sysexits
|
93
man/utilities.md
Normal file
93
man/utilities.md
Normal file
@ -0,0 +1,93 @@
|
||||
# utilities
|
||||
|
||||
This project seeks to replicate all standard system utilities on UNIX-like system, implementing the features defined in [POSIX.1-2017](https://pubs.opengroup.org/onlinepubs/9699919799/).
|
||||
Much of this project's layout is opinionated.
|
||||
|
||||
For a user installation, place `PATH="$HOME/bin/:"$PATH` in your `$HOME/.bashrc`, `mkdir -p $HOME/bin`, and then copy the desired utilities into that binaries folder.
|
||||
(Yes, this doesn't work for all system configurations (it doesn't work for mine), but it works for nearly all configurations beginners would have; if you know what you're doing you don't have to refer to this).
|
||||
This doesn't require root permissions and you can bypass these utilities with `/bin/[desired utility]`.
|
||||
|
||||
System-wide installation of these utilities isn't recommended whatsoever.
|
||||
|
||||
## building
|
||||
|
||||
You can just read the Makefile, it's a pretty simple one.
|
||||
|
||||
`make cleanall` - cleans
|
||||
|
||||
`make programs` - builds all stable utilities
|
||||
|
||||
`make [utility]` - builds a specific utility
|
||||
|
||||
It's not necessary to `make libraries` as the Makefile knows on which libraries each program depends and will build those specific libraries when needed.
|
||||
|
||||
## included utilities
|
||||
|
||||
All not mentioned in this README have proper manual pages provided in `man/`.
|
||||
|
||||
### abs
|
||||
|
||||
Not in POSIX.
|
||||
Shellscript that returns the absolute value of an integer argument.
|
||||
Relies on *eq*(1), *lt*(1), *multiply*(1), *printf*(1), and *stris*(1).
|
||||
|
||||
### ++
|
||||
|
||||
Shellscript that sums 1 with the first argument using *add*(1).
|
||||
|
||||
### --
|
||||
|
||||
Shellscript that subtracts 1 from the first argument using *subtract*(1).
|
||||
|
||||
### subtract
|
||||
|
||||
Shellscript that subtracts the second argument from the first.
|
||||
Relies on *add*(1), *eq*(1), *multiply*(1), *printf*(1), and *stris*(1).
|
||||
|
||||
### cat
|
||||
|
||||
*cat*(1) written in POSIX shell.
|
||||
Relies on *dd*(1) and *test*(1).
|
||||
|
||||
### eq
|
||||
|
||||
Compares integer arguments and exits with 0 if they're all equal or 1 if some aren't equal.
|
||||
Equivalent to `test -eq`.
|
||||
|
||||
### fdivide
|
||||
|
||||
Not in POSIX.
|
||||
Performs **floor division** on two **integers**.
|
||||
This does not, as the name suggests, divide floating-point numbers.
|
||||
|
||||
### gt
|
||||
|
||||
Compares integer arguments and exits with 0 if the arguments are arranged in descending order.
|
||||
Exits with 1 if an argument is equal or greater to a previous argument.
|
||||
Equivalent to `test -gt`.
|
||||
|
||||
### head
|
||||
|
||||
An implementation of *head*(1) written in POSIX shell.
|
||||
Relies on *cat*(1), *printf*(1), *sed*(1), and *stris*(1).
|
||||
WIP.
|
||||
|
||||
### lt
|
||||
|
||||
Compares integer arguments and exits with 0 if the arguments are arranged in ascending order.
|
||||
Exits with 1 if an argument is equal or lesser to a previous argument.
|
||||
Equivalent to `test -lt`.
|
||||
|
||||
### man
|
||||
|
||||
Barebones implementation of *man*(1) written in POSIX shell.
|
||||
|
||||
### mod
|
||||
|
||||
Not in POSIX.
|
||||
Prints the remainder of the first argument divided by the second to stdout.
|
||||
Written in POSIX shell, relies on *eq*(1), *fdivide*(1), *multiply*(1), *printf*(1), *subtract*(1), *stris*(1).
|
||||
|
||||
### tail
|
||||
|
||||
An implementation of *tail*(1). WIP.
|
Loading…
Reference in New Issue
Block a user