diff options
author | obrien <obrien@FreeBSD.org> | 2000-04-15 04:41:27 +0000 |
---|---|---|
committer | obrien <obrien@FreeBSD.org> | 2000-04-15 04:41:27 +0000 |
commit | 4ad28cefef28ce6bdb44a0532cfe20a2076bc694 (patch) | |
tree | 7679c440a91912ee9586cee3ebab24596c0fe1c4 /contrib/tcsh/MAKESHAR | |
download | FreeBSD-src-4ad28cefef28ce6bdb44a0532cfe20a2076bc694.zip FreeBSD-src-4ad28cefef28ce6bdb44a0532cfe20a2076bc694.tar.gz |
Import the latest version of the 44BSD C-shell -- tcsh-6.09.
Diffstat (limited to 'contrib/tcsh/MAKESHAR')
-rwxr-xr-x | contrib/tcsh/MAKESHAR | 121 |
1 files changed, 121 insertions, 0 deletions
diff --git a/contrib/tcsh/MAKESHAR b/contrib/tcsh/MAKESHAR new file mode 100755 index 0000000..691690f --- /dev/null +++ b/contrib/tcsh/MAKESHAR @@ -0,0 +1,121 @@ +#!/bin/sh +# +# MAKESHAR.sh: Make a shar file for the sources +# +# $Id: MAKESHAR,v 3.1 1992/05/09 04:03:53 christos Exp $ + +AWK=/usr/bin/nawk # Must be nawk or gawk cause of 2D arrays +WC=/usr/ucb/wc +GREP=/usr/bin/egrep +SORT=/usr/bin/sort +SH=/bin/sh + +dirs= +name=kit +files= +verbose=0 +size=45000 + +for i +do + case $i in + -n) + name=;; + -v) + verbose=1;; + -d) + SH=/bin/cat;; + -s) + size=$1;; + *) + if [ -z "$name" ] + then + name=$i + elif [ -d $i ] + then + dirs="$dirs $i" + elif [ -f $i ] + then + files="$files $i" + else + echo "$0: File `$i' not found." 1>&2 + exit 1 + fi;; + esac +done + +if [ \( -z "$files" \) -a \( -z "$dirs" \) ] +then + echo "Usage: $0 [-n name] [-s size] [-vd] <files>." 1>&2 + exit 1 +fi + +$WC $files | $GREP -v total | $SORT +2 | $AWK ' + BEGIN { + i = 0; + seq = 1; + size = 0; + name = 1; + used = 2; + verbose='"$verbose"'; + tty = "/dev/tty"; + maxsize = '"$size"'; + dirs = "'"$dirs"'"; + }; + { + a[i, size] = $3; + a[i, name] = $4; + a[i, used] = 0; + i++; + }; + END { + for (maxi = i--; i >= 0; i--) { + idx = 0; + if (a[i, used] == 0) { + if (verbose && a[i, size] > maxsize) + printf("Warning: File %s is %d > %d\n", + a[i, name], a[i, size], maxsize) > tty; + s = a[i, size]; + a[i, used] = 1; + kit[seq, idx++] = i; + j = 0; + while (j < maxi) { + # Find the greatest file we can add + j = maxi; + for (k = 0; k < maxi; k++) + if (a[k, used] == 0 && a[k, size] + s < maxsize) + j = k; + if (j < maxi) { + s += a[j, size]; + a[j, used] = 1; + kit[seq, idx++] = j; + } + } + sizes[seq] = s; + kit[seq++, idx] = -1; + } + } + for (i = 1; i < seq; i++) { + printf("shar -n%d -e%d %s ", i, seq - 1, dirs); + if (verbose) { + printf("%3d of %3d: ", i, seq - 1) > tty; + len = 12; + } + for (j = 0; kit[i, j] != -1; j++) { + s = a[kit[i, j], name]; + if (verbose) { + clen = length(s) + 1; + len += clen; + if (len > 70) { + printf("\n ") > tty; + len = 12 + clen; + } + printf("%s ", s) > tty; + } + printf("%s ", s); + } + printf("> '"$name"'-%d.shar;", i); + if (verbose) + printf("= %5d\n", sizes[i]) > tty; + } + }' | $SH |