Revision 9006,
2.1 KB
checked in by ghudson, 28 years ago
(diff) |
This commit was generated by cvs2svn to compensate for changes in r9005,
which included commits to RCS files with non-trunk default branches.
|
-
Property svn:executable set to
*
|
Line | |
---|
1 | #!/bin/sh |
---|
2 | # |
---|
3 | # MAKESHAR.sh: Make a shar file for the sources |
---|
4 | # |
---|
5 | # $Id: MAKESHAR,v 1.1.1.1 1996-10-02 06:09:30 ghudson Exp $ |
---|
6 | |
---|
7 | AWK=/usr/bin/nawk # Must be nawk or gawk cause of 2D arrays |
---|
8 | WC=/usr/ucb/wc |
---|
9 | GREP=/usr/bin/egrep |
---|
10 | SORT=/usr/bin/sort |
---|
11 | SH=/bin/sh |
---|
12 | |
---|
13 | dirs= |
---|
14 | name=kit |
---|
15 | files= |
---|
16 | verbose=0 |
---|
17 | size=45000 |
---|
18 | |
---|
19 | for i |
---|
20 | do |
---|
21 | case $i in |
---|
22 | -n) |
---|
23 | name=;; |
---|
24 | -v) |
---|
25 | verbose=1;; |
---|
26 | -d) |
---|
27 | SH=/bin/cat;; |
---|
28 | -s) |
---|
29 | size=$1;; |
---|
30 | *) |
---|
31 | if [ -z "$name" ] |
---|
32 | then |
---|
33 | name=$i |
---|
34 | elif [ -d $i ] |
---|
35 | then |
---|
36 | dirs="$dirs $i" |
---|
37 | elif [ -f $i ] |
---|
38 | then |
---|
39 | files="$files $i" |
---|
40 | else |
---|
41 | echo "$0: File `$i' not found." 1>&2 |
---|
42 | exit 1 |
---|
43 | fi;; |
---|
44 | esac |
---|
45 | done |
---|
46 | |
---|
47 | if [ \( -z "$files" \) -a \( -z "$dirs" \) ] |
---|
48 | then |
---|
49 | echo "Usage: $0 [-n name] [-s size] [-vd] <files>." 1>&2 |
---|
50 | exit 1 |
---|
51 | fi |
---|
52 | |
---|
53 | $WC $files | $GREP -v total | $SORT +2 | $AWK ' |
---|
54 | BEGIN { |
---|
55 | i = 0; |
---|
56 | seq = 1; |
---|
57 | size = 0; |
---|
58 | name = 1; |
---|
59 | used = 2; |
---|
60 | verbose='"$verbose"'; |
---|
61 | tty = "/dev/tty"; |
---|
62 | maxsize = '"$size"'; |
---|
63 | dirs = "'"$dirs"'"; |
---|
64 | }; |
---|
65 | { |
---|
66 | a[i, size] = $3; |
---|
67 | a[i, name] = $4; |
---|
68 | a[i, used] = 0; |
---|
69 | i++; |
---|
70 | }; |
---|
71 | END { |
---|
72 | for (maxi = i--; i >= 0; i--) { |
---|
73 | idx = 0; |
---|
74 | if (a[i, used] == 0) { |
---|
75 | if (verbose && a[i, size] > maxsize) |
---|
76 | printf("Warning: File %s is %d > %d\n", |
---|
77 | a[i, name], a[i, size], maxsize) > tty; |
---|
78 | s = a[i, size]; |
---|
79 | a[i, used] = 1; |
---|
80 | kit[seq, idx++] = i; |
---|
81 | j = 0; |
---|
82 | while (j < maxi) { |
---|
83 | # Find the greatest file we can add |
---|
84 | j = maxi; |
---|
85 | for (k = 0; k < maxi; k++) |
---|
86 | if (a[k, used] == 0 && a[k, size] + s < maxsize) |
---|
87 | j = k; |
---|
88 | if (j < maxi) { |
---|
89 | s += a[j, size]; |
---|
90 | a[j, used] = 1; |
---|
91 | kit[seq, idx++] = j; |
---|
92 | } |
---|
93 | } |
---|
94 | sizes[seq] = s; |
---|
95 | kit[seq++, idx] = -1; |
---|
96 | } |
---|
97 | } |
---|
98 | for (i = 1; i < seq; i++) { |
---|
99 | printf("shar -n%d -e%d %s ", i, seq - 1, dirs); |
---|
100 | if (verbose) { |
---|
101 | printf("%3d of %3d: ", i, seq - 1) > tty; |
---|
102 | len = 12; |
---|
103 | } |
---|
104 | for (j = 0; kit[i, j] != -1; j++) { |
---|
105 | s = a[kit[i, j], name]; |
---|
106 | if (verbose) { |
---|
107 | clen = length(s) + 1; |
---|
108 | len += clen; |
---|
109 | if (len > 70) { |
---|
110 | printf("\n ") > tty; |
---|
111 | len = 12 + clen; |
---|
112 | } |
---|
113 | printf("%s ", s) > tty; |
---|
114 | } |
---|
115 | printf("%s ", s); |
---|
116 | } |
---|
117 | printf("> '"$name"'-%d.shar;", i); |
---|
118 | if (verbose) |
---|
119 | printf("= %5d\n", sizes[i]) > tty; |
---|
120 | } |
---|
121 | }' | $SH |
---|
Note: See
TracBrowser
for help on using the repository browser.