diff options
Diffstat (limited to 'usr.bin/fortune/tools')
-rw-r--r-- | usr.bin/fortune/tools/Do_spell | 7 | ||||
-rw-r--r-- | usr.bin/fortune/tools/Do_troff | 7 | ||||
-rw-r--r-- | usr.bin/fortune/tools/Troff.mac | 26 | ||||
-rw-r--r-- | usr.bin/fortune/tools/Troff.sed | 13 | ||||
-rw-r--r-- | usr.bin/fortune/tools/do_sort | 9 | ||||
-rw-r--r-- | usr.bin/fortune/tools/do_uniq.py | 67 |
6 files changed, 129 insertions, 0 deletions
diff --git a/usr.bin/fortune/tools/Do_spell b/usr.bin/fortune/tools/Do_spell new file mode 100644 index 000000000000..2c232ac0f263 --- /dev/null +++ b/usr.bin/fortune/tools/Do_spell @@ -0,0 +1,7 @@ +#!/bin/sh - + +F=_spell.$$ +echo $1 +spell < $1 > $F +sort $F $1.sp.ok | uniq -u | column +rm -f $F diff --git a/usr.bin/fortune/tools/Do_troff b/usr.bin/fortune/tools/Do_troff new file mode 100644 index 000000000000..7dd2ec3a6f83 --- /dev/null +++ b/usr.bin/fortune/tools/Do_troff @@ -0,0 +1,7 @@ +#!/bin/csh -f + +set file=$1 +shift +( echo ".ds Se $file" ; cat Troff.mac ; sed -f Troff.sed $file ) | \ + $* -me >& $file.tr +echo troff output in $file.tr diff --git a/usr.bin/fortune/tools/Troff.mac b/usr.bin/fortune/tools/Troff.mac new file mode 100644 index 000000000000..c2b433e1b213 --- /dev/null +++ b/usr.bin/fortune/tools/Troff.mac @@ -0,0 +1,26 @@ +.nr tp 8 +.nr hm 3v +.nr fm 2v +.nr tm 5v +.nr bm 4v +.cs R +.sc +.sz 6 +.ll +10n +.lt \n(.l +.de $h +.tl 'Fortune Database'\\*(Se'\*(td' +.. +.de $f +.tl ''- % -'' +.. +.2c +.nf +.ta +.ta 8n 16n 24n 32n 40n 48n 56n 64n 72n 80n +.de %% +.sp .3 +.ce +\(sq\|\(sq\|\(sq\|\(sq\|\(sq\|\(sq\|\(sq\|\(sq\|\(sq +.sp .2 +.. diff --git a/usr.bin/fortune/tools/Troff.sed b/usr.bin/fortune/tools/Troff.sed new file mode 100644 index 000000000000..321668123ad9 --- /dev/null +++ b/usr.bin/fortune/tools/Troff.sed @@ -0,0 +1,13 @@ +/^['.]/s//\\\&&/ +/^%%/s//.&/ +/--/s//\\*-/g +/_a-squared cos 2(phi)/s//\\fIa\\fP\\u2\\d cos 2\\(*f/ +/__**\([a-zA-Z]*\)/s//\\fI\1\\fP/g +/"\(.\)/s//\1\\*:/g +/`\(.\)/s//\1\\*`/g +/'\(.\)/s//\1\\*'/g +/~\(.\)/s//\1\\*~/g +/\^\(.\)/s//\1\\*^/g +/,\(.\)/s//\1\\*,/g +/\(.\)\(.\)/s//\\o_\1\2_/g +/*/s//\\(bs/g diff --git a/usr.bin/fortune/tools/do_sort b/usr.bin/fortune/tools/do_sort new file mode 100644 index 000000000000..a92d02755ecb --- /dev/null +++ b/usr.bin/fortune/tools/do_sort @@ -0,0 +1,9 @@ +#! /bin/sh +# an aggressive little script for sorting the fortune files +# depends on octal 02 and 03 not being anywhere in the files. + +sp="/usr/bin/sort -dfu -T /var/tmp" + +sed 's/^%$//' | tr '\12' '\3' | tr '\2' '\12' | + sed -e 's/^//' -e '/^$/d' -e 's/$/%/' | + $sp | tr '\3' '\12' diff --git a/usr.bin/fortune/tools/do_uniq.py b/usr.bin/fortune/tools/do_uniq.py new file mode 100644 index 000000000000..092d91bd0480 --- /dev/null +++ b/usr.bin/fortune/tools/do_uniq.py @@ -0,0 +1,67 @@ +#!/usr/local/bin/python +# +# +# an aggressive little script for trimming duplicate cookies +from __future__ import print_function +import argparse +import re + +wordlist = [ + 'hadnot', + 'donot', 'hadnt', + 'dont', 'have', 'more', 'will', 'your', + 'and', 'are', 'had', 'the', 'you', + 'am', 'an', 'is', 'll', 've', 'we', + 'a', 'd', 'i', 'm', 's', +] + + +def hash(fortune): + f = fortune + f = f.lower() + f = re.sub('[\W_]', '', f) + for word in wordlist: + f = re.sub(word, '', f) +# f = re.sub('[aeiouy]', '', f) +# f = re.sub('[^aeiouy]', '', f) + f = f[:30] +# f = f[-30:] + return f + + +def edit(datfile): + dups = {} + fortunes = [] + fortune = "" + with open(datfile, "r") as datfiledf: + for line in datfiledf: + if line == "%\n": + key = hash(fortune) + if key not in dups: + dups[key] = [] + dups[key].append(fortune) + fortunes.append(fortune) + fortune = "" + else: + fortune += line + for key in list(dups.keys()): + if len(dups[key]) == 1: + del dups[key] + with open(datfile + "~", "w") as o: + for fortune in fortunes: + key = hash(fortune) + if key in dups: + print('\n' * 50) + for f in dups[key]: + if f != fortune: + print(f, '%') + print(fortune, '%') + if input("Remove last fortune? ") == 'y': + del dups[key] + continue + o.write(fortune + "%\n") + +parser = argparse.ArgumentParser(description="trimming duplicate cookies") +parser.add_argument("filename", type=str, nargs=1) +args = parser.parse_args() +edit(args.filename[0]) |