]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - rain/rain.c
1 /* $NetBSD: rain.c,v 1.6 1995/04/22 10:26:09 cgd Exp $ */
4 * Copyright (c) 1980, 1993
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by the University of
18 * California, Berkeley and its contributors.
19 * 4. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 static char copyright
[] =
38 "@(#) Copyright (c) 1980, 1993\n\
39 The Regents of the University of California. All rights reserved.\n";
44 static char sccsid
[] = "@(#)rain.c 8.1 (Berkeley) 5/31/93";
46 static char rcsid
[] = "$NetBSD: rain.c,v 1.6 1995/04/22 10:26:09 cgd Exp $";
51 * rain 11/3/1980 EPS/CITHEP
52 * cc rain.c -o rain -O -ltermlib
55 #include <sys/types.h>
64 #define cursor(c, r) tputs(tgoto(CM, c, r), 1, fputchar)
67 static struct termio sg
, old_tty
;
69 static struct sgttyb sg
, old_tty
;
72 void fputchar
__P((int));
73 char *LL
, *TE
, *tgoto();
82 register char *CM
, *BC
, *DN
, *ND
, *term
;
83 char *TI
, *tcp
, *mp
, tcb
[100],
84 *malloc(), *getenv(), *strcpy(), *tgetstr();
85 long cols
, lines
, random();
92 if (!(term
= getenv("TERM"))) {
93 fprintf(stderr
, "%s: TERM: parameter not set\n", *argv
);
96 if (!(mp
= malloc((u_int
)1024))) {
97 fprintf(stderr
, "%s: out of space.\n", *argv
);
100 if (tgetent(mp
, term
) <= 0) {
101 fprintf(stderr
, "%s: %s: unknown terminal type\n", *argv
, term
);
105 if (!(CM
= tgetstr("cm", &tcp
))) {
106 fprintf(stderr
, "%s: terminal not capable of cursor motion\n", *argv
);
109 if (!(BC
= tgetstr("bc", &tcp
)))
111 if (!(DN
= tgetstr("dn", &tcp
)))
113 if (!(ND
= tgetstr("nd", &tcp
)))
116 if (ioctl(fileno(stdout
), TIOCGWINSZ
, &ws
) != -1 &&
117 ws
.ws_col
&& ws
.ws_row
) {
123 if ((cols
= tgetnum("co")) == -1)
125 if ((lines
= tgetnum("li")) == -1)
130 TE
= tgetstr("te", &tcp
);
131 TI
= tgetstr("ti", &tcp
);
132 UP
= tgetstr("up", &tcp
);
133 if (!(LL
= tgetstr("ll", &tcp
))) {
134 if (!(LL
= malloc((u_int
)10))) {
135 fprintf(stderr
, "%s: out of space.\n", *argv
);
138 (void)strcpy(LL
, tgoto(CM
, 0, 23));
141 ioctl(1, TCGETA
, &sg
);
142 ospeed
= sg
.c_cflag
&CBAUD
;
145 ospeed
= sg
.sg_ospeed
;
147 (void)signal(SIGHUP
, onsig
);
148 (void)signal(SIGINT
, onsig
);
149 (void)signal(SIGQUIT
, onsig
);
150 (void)signal(SIGSTOP
, onsig
);
151 (void)signal(SIGTSTP
, onsig
);
152 (void)signal(SIGTERM
, onsig
);
154 ioctl(1, TCGETA
, &old_tty
); /* save tty bits for exit */
155 ioctl(1, TCGETA
, &sg
);
156 sg
.c_iflag
&= ~ICRNL
;
157 sg
.c_oflag
&= ~ONLCR
;
159 ioctl(1, TCSETAW
, &sg
);
161 gtty(1, &old_tty
); /* save tty bits for exit */
163 sg
.sg_flags
&= ~(CRMOD
|ECHO
);
167 tputs(TI
, 1, fputchar
);
168 tputs(tgetstr("cl", &tcp
), 1, fputchar
);
169 (void)fflush(stdout
);
170 for (j
= 4; j
>= 0; --j
) {
171 xpos
[j
] = random() % cols
+ 2;
172 ypos
[j
] = random() % lines
+ 2;
175 x
= random() % cols
+ 2;
176 y
= random() % lines
+ 2;
179 cursor(xpos
[j
], ypos
[j
]);
183 cursor(xpos
[j
], ypos
[j
]);
187 cursor(xpos
[j
], ypos
[j
] - 1);
189 tputs(DN
, 1, fputchar
);
190 tputs(BC
, 1, fputchar
);
191 tputs(BC
, 1, fputchar
);
192 fputs("|.|", stdout
);
193 tputs(DN
, 1, fputchar
);
194 tputs(BC
, 1, fputchar
);
195 tputs(BC
, 1, fputchar
);
199 cursor(xpos
[j
], ypos
[j
] - 2);
201 tputs(DN
, 1, fputchar
);
202 tputs(BC
, 1, fputchar
);
203 tputs(BC
, 1, fputchar
);
204 fputs("/ \\", stdout
);
205 cursor(xpos
[j
] - 2, ypos
[j
]);
206 fputs("| O |", stdout
);
207 cursor(xpos
[j
] - 1, ypos
[j
] + 1);
208 fputs("\\ /", stdout
);
209 tputs(DN
, 1, fputchar
);
210 tputs(BC
, 1, fputchar
);
211 tputs(BC
, 1, fputchar
);
215 cursor(xpos
[j
], ypos
[j
] - 2);
217 tputs(DN
, 1, fputchar
);
218 tputs(BC
, 1, fputchar
);
219 tputs(BC
, 1, fputchar
);
221 tputs(ND
, 1, fputchar
);
223 cursor(xpos
[j
] - 2, ypos
[j
]);
225 tputs(ND
, 1, fputchar
);
227 tputs(ND
, 1, fputchar
);
229 cursor(xpos
[j
] - 1, ypos
[j
] + 1);
231 tputs(ND
, 1, fputchar
);
233 tputs(DN
, 1, fputchar
);
234 tputs(BC
, 1, fputchar
);
235 tputs(BC
, 1, fputchar
);
239 (void)fflush(stdout
);
246 tputs(LL
, 1, fputchar
);
248 tputs(TE
, 1, fputchar
);
249 (void)fflush(stdout
);
251 ioctl(1, TCSETAW
, &old_tty
);