]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - rain/rain.c
1 /* $NetBSD: rain.c,v 1.7 1995/04/29 00:51:04 mycroft 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.7 1995/04/29 00:51:04 mycroft Exp $";
51 * rain 11/3/1980 EPS/CITHEP
52 * cc rain.c -o rain -O -ltermlib
55 #include <sys/types.h>
60 #define cursor(c, r) tputs(tgoto(CM, c, r), 1, fputchar)
62 static struct termios sg
, old_tty
;
64 void fputchar
__P((int));
65 char *LL
, *TE
, *tgoto();
71 extern speed_t ospeed
;
74 register char *CM
, *BC
, *DN
, *ND
, *term
;
75 char *TI
, *tcp
, *mp
, tcb
[100],
76 *malloc(), *getenv(), *strcpy(), *tgetstr();
77 long cols
, lines
, random();
84 if (!(term
= getenv("TERM"))) {
85 fprintf(stderr
, "%s: TERM: parameter not set\n", *argv
);
88 if (!(mp
= malloc((u_int
)1024))) {
89 fprintf(stderr
, "%s: out of space.\n", *argv
);
92 if (tgetent(mp
, term
) <= 0) {
93 fprintf(stderr
, "%s: %s: unknown terminal type\n", *argv
, term
);
97 if (!(CM
= tgetstr("cm", &tcp
))) {
98 fprintf(stderr
, "%s: terminal not capable of cursor motion\n", *argv
);
101 if (!(BC
= tgetstr("bc", &tcp
)))
103 if (!(DN
= tgetstr("dn", &tcp
)))
105 if (!(ND
= tgetstr("nd", &tcp
)))
108 if (ioctl(fileno(stdout
), TIOCGWINSZ
, &ws
) != -1 &&
109 ws
.ws_col
&& ws
.ws_row
) {
115 if ((cols
= tgetnum("co")) == -1)
117 if ((lines
= tgetnum("li")) == -1)
122 TE
= tgetstr("te", &tcp
);
123 TI
= tgetstr("ti", &tcp
);
124 UP
= tgetstr("up", &tcp
);
125 if (!(LL
= tgetstr("ll", &tcp
))) {
126 if (!(LL
= malloc((u_int
)10))) {
127 fprintf(stderr
, "%s: out of space.\n", *argv
);
130 (void)strcpy(LL
, tgoto(CM
, 0, 23));
132 (void)signal(SIGHUP
, onsig
);
133 (void)signal(SIGINT
, onsig
);
134 (void)signal(SIGQUIT
, onsig
);
135 (void)signal(SIGSTOP
, onsig
);
136 (void)signal(SIGTSTP
, onsig
);
137 (void)signal(SIGTERM
, onsig
);
140 ospeed
= cfgetospeed(&sg
);
141 sg
.c_iflag
&= ~ICRNL
;
142 sg
.c_oflag
&= ~ONLCR
;
144 tcsetattr(1, TCSADRAIN
, &sg
);
146 tputs(TI
, 1, fputchar
);
147 tputs(tgetstr("cl", &tcp
), 1, fputchar
);
148 (void)fflush(stdout
);
149 for (j
= 4; j
>= 0; --j
) {
150 xpos
[j
] = random() % cols
+ 2;
151 ypos
[j
] = random() % lines
+ 2;
154 x
= random() % cols
+ 2;
155 y
= random() % lines
+ 2;
158 cursor(xpos
[j
], ypos
[j
]);
162 cursor(xpos
[j
], ypos
[j
]);
166 cursor(xpos
[j
], ypos
[j
] - 1);
168 tputs(DN
, 1, fputchar
);
169 tputs(BC
, 1, fputchar
);
170 tputs(BC
, 1, fputchar
);
171 fputs("|.|", stdout
);
172 tputs(DN
, 1, fputchar
);
173 tputs(BC
, 1, fputchar
);
174 tputs(BC
, 1, fputchar
);
178 cursor(xpos
[j
], ypos
[j
] - 2);
180 tputs(DN
, 1, fputchar
);
181 tputs(BC
, 1, fputchar
);
182 tputs(BC
, 1, fputchar
);
183 fputs("/ \\", stdout
);
184 cursor(xpos
[j
] - 2, ypos
[j
]);
185 fputs("| O |", stdout
);
186 cursor(xpos
[j
] - 1, ypos
[j
] + 1);
187 fputs("\\ /", stdout
);
188 tputs(DN
, 1, fputchar
);
189 tputs(BC
, 1, fputchar
);
190 tputs(BC
, 1, fputchar
);
194 cursor(xpos
[j
], ypos
[j
] - 2);
196 tputs(DN
, 1, fputchar
);
197 tputs(BC
, 1, fputchar
);
198 tputs(BC
, 1, fputchar
);
200 tputs(ND
, 1, fputchar
);
202 cursor(xpos
[j
] - 2, ypos
[j
]);
204 tputs(ND
, 1, fputchar
);
206 tputs(ND
, 1, fputchar
);
208 cursor(xpos
[j
] - 1, ypos
[j
] + 1);
210 tputs(ND
, 1, fputchar
);
212 tputs(DN
, 1, fputchar
);
213 tputs(BC
, 1, fputchar
);
214 tputs(BC
, 1, fputchar
);
218 (void)fflush(stdout
);
225 tputs(LL
, 1, fputchar
);
227 tputs(TE
, 1, fputchar
);
228 (void)fflush(stdout
);
229 tcsetattr(1, TCSADRAIN
, &old_tty
);