]> git.cameronkatri.com Git - bsdgames-darwin.git/blob - countmail/countmail
uniq.
[bsdgames-darwin.git] / countmail / countmail
1 #!/bin/sh
2 # $NetBSD: countmail,v 1.5 2002/07/02 17:18:21 mycroft Exp $
3
4 #
5 # Copyright (c) 1998, 2002 The NetBSD Foundation, Inc.
6 # All rights reserved.
7 #
8 # This code is derived from software contributed to The NetBSD Foundation
9 # by Charles M. Hannum.
10 #
11 # Redistribution and use in source and binary forms, with or without
12 # modification, are permitted provided that the following conditions
13 # are met:
14 # 1. Redistributions of source code must retain the above copyright
15 # notice, this list of conditions and the following disclaimer.
16 # 2. Redistributions in binary form must reproduce the above copyright
17 # notice, this list of conditions and the following disclaimer in the
18 # documentation and/or other materials provided with the distribution.
19 # 3. All advertising materials mentioning features or use of this software
20 # must display the following acknowledgement:
21 # This product includes software developed by the NetBSD
22 # Foundation, Inc. and its contributors.
23 # 4. Neither the name of The NetBSD Foundation nor the names of its
24 # contributors may be used to endorse or promote products derived
25 # from this software without specific prior written permission.
26 #
27 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 # POSSIBILITY OF SUCH DAMAGE.
38 #
39
40 # Count the messages in your mailbox, using only POSIX shell builtins.
41 #
42 # Caveats:
43 #
44 # The read loop is horrendously slow on every implementation I've
45 # tried. I suggest using from(1) and wc(1) instead, though these are
46 # not shell builtins.
47
48 # for krb.
49 #set -- `from -t`
50 #v=$3
51 set -- `from | wc -l`
52 v=$1
53 #v=`from | wc -l`
54
55 #v=0
56 #exec 0</var/mail/$USER
57 #while read line; do
58 # case "$line" in
59 # "From "*) v=$(($v + 1)) ;;
60 # esac
61 #done
62 #exec 0<&-
63
64 set --
65 g=0
66 v=000$v
67
68 while :; do
69
70 case $v in
71 '' | 0 | 00) break ;;
72 *000) ;;
73 *)
74 case $g in
75 0) x= ;;
76 1) x=THOUSAND ;;
77 2) x=MILLION ;;
78 3) x=BILLION ;;
79 4) x=TRILLION ;;
80 5) x=QUADRILLION ;;
81 6) x=QUINTILLION ;;
82 7) x=SEXTILLION ;;
83 8) x=SEPTILLION ;;
84 *)
85 echo "YOU HAVE TOO MUCH MAIL!" 1>&2
86 exit 1
87 ;;
88 esac
89
90 case $v in
91 *10) y=TEN ;;
92 *11) y=ELEVEN ;;
93 *12) y=TWELVE ;;
94 *13) y=THIRTEEN ;;
95 *14) y=FOURTEEN ;;
96 *15) y=FIFTEEN ;;
97 *16) y=SIXTEEN ;;
98 *17) y=SEVENTEEN ;;
99 *18) y=EIGHTEEN ;;
100 *19) y=NINETEEN ;;
101 *2?) y=TWENTY ;;
102 *3?) y=THIRTY ;;
103 *4?) y=FORTY ;;
104 *5?) y=FIFTY ;;
105 *6?) y=SIXTY ;;
106 *7?) y=SEVENTY ;;
107 *8?) y=EIGHTY ;;
108 *9?) y=NINETY ;;
109 *) y= ;;
110 esac
111
112 case $v in
113 *[01]? | *?0) ;;
114 *) y=$y- ;;
115 esac
116
117 case $v in
118 *1?) ;;
119 *1) y=${y}ONE ;;
120 *2) y=${y}TWO ;;
121 *3) y=${y}THREE ;;
122 *4) y=${y}FOUR ;;
123 *5) y=${y}FIVE ;;
124 *6) y=${y}SIX ;;
125 *7) y=${y}SEVEN ;;
126 *8) y=${y}EIGHT ;;
127 *9) y=${y}NINE ;;
128 esac
129
130 case $v in
131 *1??) z=ONE ;;
132 *2??) z=TWO ;;
133 *3??) z=THREE ;;
134 *4??) z=FOUR ;;
135 *5??) z=FIVE ;;
136 *6??) z=SIX ;;
137 *7??) z=SEVEN ;;
138 *8??) z=EIGHT ;;
139 *9??) z=NINE ;;
140 *) z= ;;
141 esac
142
143 set $z ${z:+HUNDRED} $y $x $*
144 ;;
145 esac
146
147 g=$(($g + 1))
148 v=${v%%???}
149
150 done
151
152 p=S
153
154 case "$*" in
155 "") set ZERO ;;
156 ONE) p= ;;
157 esac
158
159 echo "$*!
160
161 $* NEW MAIL MESSAGE$p!
162
163 HAHAHAHAHA!"