1
0
Fork 0

more cleaning!!!

This commit is contained in:
dtb 2022-09-17 23:29:31 -04:00
parent 1aed01279b
commit fbdaf55d1c
10 changed files with 32 additions and 191 deletions

24
.gitignore vendored
View File

@ -1,23 +1,5 @@
bin/echo
bin/false
bin/id
bin/lowercase
bin/nonzero
bin/nutshell
bin/pscat
bin/retval
bin/rldecode
bin/rlencode
bin/roll
bin/rot13
bin/simexec
bin/sleep
bin/str
bin/streq
bin/sysexits
build/*
include/sysexits.h
lib/*.o
dist/
echo/echo
roll/roll
rot13/rot13
src/*.o
str/str

3
arraylen.h Normal file
View File

@ -0,0 +1,3 @@
#ifndef ARRAYLEN
# define ARRAYLEN(a) sizeof(a) / sizeof *(a)
#endif

View File

@ -4,6 +4,11 @@
# define Use_of_this_function_is_not_permitted(a) invalid_token
# define BAN(a) Use_of_this_function_is_not_permitted(a)
# undef fscanf
# define fscanf(...) BAN(fscanf)
# undef scanf
# define scanf(...) BAN(scanf)
# undef strcat
# define strcat(a,b) BAN(strcat)

View File

@ -1,61 +0,0 @@
#!/bin/sh
length=10 # default length
# core [input] [output] [length]
core() {
sed $3q <"$1" >"$2"
}
usage() {
printf "Usage: %b [-h] [-n number]\n" "$1"
exit 1
}
argc=$#
argv0="$0"
output="/dev/stdout"
while getopts 'hn:' c; do
case $c in
(h) usage "$0";;
(n)
stris uint "$OPTARG" \
&& length=$OPTARG \
|| usage "$argv0"
;;
(:)
printf "%b: \"-$OPTARG\" requires an argument (number)\n" "$argv0" >/dev/stderr
exit 1;;
(?)
stris uint $OPTOPT >/dev/null \
&& printf "%b: This program doesn't support -[number] arguments as they're not POSIX\n" "$argv0" >/dev/stderr \
|| usage "$argv0"
exit 1;;
esac
done
if eq $OPTIND $(add $argc 1); then # no file specified, assume stdin
core /dev/stdin "$output" $length
exit 0
fi
shift $OPTIND
temp0="$0"
while true; do
! [ -e "$0" ] \
&& printf "%b: %b: File does not exist\n" "$argv0" "$0" >/dev/stderr \
&& exit 1
[ -n "$1" ] && ! streq "$0" "$temp0" \
&& printf "\n" >"$output"
[ -n "$1" ] \
&& printf "==> %b <==\n" "$0" >"$output"
core "$0" "$output" $length
[ -n "$1" ] && shift 1 || break
done
exit 0

87
bin/man
View File

@ -1,87 +0,0 @@
#!/bin/sh
argv0="$0"
die() { printf "$*" >/dev/stderr && exit 1; }
# A lot of these break convention when recording errors because this tries to
# imitate other implementations.
[ -n "$1" ] || die "What manual page do you want?\nFor example, try 'man man'.\n"
[ -n "$LANG" ] || LANG="C"
[ -n "$MANPATH" ] || MANPATH="/usr/share/man"
[ -d "$MANPATH" ] || die "$0: \$MANPATH: $MANPATH: Does not exist\n"
[ -n "$MANSECTIONS" ] \
&& default_mansections="$MANSECTIONS" \
|| default_mansections="1nl830254967"
[ -d "$MANPATH"/"$LANG" ] \
&& MANDIR="$MANPATH/$LANG" \
|| MANDIR="$MANPATH"
if [ -z "$PAGER" ]; then
for prog in $(printf "
less
more
cat
dd
"); do
if which "$prog" >/dev/null 2>&1; then
PAGER="$prog"
break
fi
done
fi
man() {
eq $# 2 || die "$argv0: man() called with $# arguments. Expected 2. This is a programmer error\n"
MANSECTIONS="$1"
NAME="$2"
# the way manpages are laid out SUCKS
# so, yeah, each man section is one character. which means it's totally
# bueno to just iterate over the string like this. but $MANDIR/man1 can
# have both man.1.gz AND man.1p.gz. ARGH!!!!
for SECTION in $(printf "$MANSECTIONS" | sed 's/\(.\)/\1\n/g'); do
PAGE="$(find "$MANDIR/man$SECTION" -type f 2>/dev/null | grep "\/$NAME\.\|\/$NAME$" | sed q)"
[ -z "$PAGE" ] || break
done
! [ -n "$PAGE" ] \
&& printf "No manual entry for $NAME\n" \
&& return 1
case "$(file -bir --no-buffer "$PAGE")" in
("text/"*)
COMMAND="cat" ;;
("application/gzip"*)
COMMAND="zcat" ;;
(*)
die "$argv0: $PAGE: Unknown file type.\n" ;;
esac
$COMMAND "$PAGE" | nroff -man | $PAGER
}
# this seems to be what the popular man does
# so like `man foo -k bar` will show the manpages for foo, -k, and bar
# expected behavior imo would be manpage for foo, then gist for bar
# but let's not break things
if streq "$1" "-k"; then # -k
printf "Not yet implemented\n" && exit 1
else # not -k
while gt $# 0; do
if eq $(fdivide $# 2) 0 && gt 1 $# || ! stris int "$1"; then
MANSECTIONS="$default_mansections"
NAME="$1"
SHIFTING=1
elif gt 1 $(fdivide $# 2); then
MANSECTIONS="$1"
NAME="$2"
SHIFTING=2
else exit 0 # no more args
fi
man "$MANSECTIONS" "$NAME"
shift $SHIFTING
done
fi

1
dotfiles/.nethackrc Normal file
View File

@ -0,0 +1 @@
OPTIONS=!autopickup

View File

@ -1,13 +0,0 @@
#ifndef _STDBOOL_H
# define _STDBOOL_H
# define bool _Bool
# define false 0
# define true 1
# define __bool_true_false_are_defined 1
/* "dirtbag boolean"
* - ideally the compiler would keep all the booleans in [x] number of unsigned
* [type]s so it could squeeze eight booleans out of one byte.
* alas, the simplest thing tends to be best, and it's nice to not waste 20
* cycles (figure made up) on applying a bitmask to an int to read a bool */
# define _Bool unsigned char
#endif /* ifndef _STDBOOL_H */

View File

@ -1,9 +0,0 @@
/* #include <stddef.h>
* - Needed for NULL in NOARGVZERO
* #include <sysexits.h>
* - Needed for EX_OSERR in NOARGVZERO
* #include <unistd.h>
* - Needed for write(2) in NOARGVZERO */
#define ARRAYLEN(a) sizeof((a)) / sizeof(*(a))
#define NOARGVZERO(a) if(*(a) == NULL) { write(2, "argv[0] is NULL; OS error, exiting...\n", 38); return EX_OSERR; }

16
irc/irc.c Normal file
View File

@ -0,0 +1,16 @@
#include <stdio.h>
#include <stdlib.h>
/* RFC 1459 1.2
* 9 characters + nul terminator */
static int nickname[9 + 1];
/* RFC 1459 1.3
* 200 characters + nul terminator */
static int channel[200 + 1];
/* RFC 1459 1.3
* channel names cannot contain these characters */
static int channel_restricted[] = { 0x07, ' ', ',', '\0' };

4
irc/irc.h Normal file
View File

@ -0,0 +1,4 @@
#ifndef _IRC_H
# define _IRC_H
#endif /* ifndef _IRC_H */