]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - rain/rain.c
1 /* $NetBSD: rain.c,v 1.9 1997/10/13 16:13:39 lukem 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
36 #include <sys/cdefs.h>
38 __COPYRIGHT("@(#) 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 __RCSID("$NetBSD: rain.c,v 1.9 1997/10/13 16:13:39 lukem Exp $");
51 * rain 11/3/1980 EPS/CITHEP
52 * cc rain.c -o rain -O -ltermlib
55 #include <sys/types.h>
56 #include <sys/ioctl.h>
64 #define cursor(c, r) tputs(tgoto(CM, c, r), 1, fputchar)
66 static struct termios sg
, old_tty
;
68 void fputchar
__P((int));
69 int main
__P((int, char **));
70 void onsig
__P((int));
82 char *CM
, *BC
, *DN
, *ND
, *term
;
83 char *TI
, *tcp
, *mp
, tcb
[100];
90 if (!(term
= getenv("TERM")))
91 errx(1, "TERM: parameter not set");
92 if (!(mp
= malloc((u_int
)1024)))
93 errx(1, "out of space");
94 if (tgetent(mp
, term
) <= 0)
95 errx(1, "unknown terminal type `%s'", term
);
97 if (!(CM
= tgetstr("cm", &tcp
)))
98 errx(1, "terminal not capable of cursor motion");
99 if (!(BC
= tgetstr("bc", &tcp
)))
101 if (!(DN
= tgetstr("dn", &tcp
)))
103 if (!(ND
= tgetstr("nd", &tcp
)))
106 if (ioctl(fileno(stdout
), TIOCGWINSZ
, &ws
) != -1 &&
107 ws
.ws_col
&& ws
.ws_row
) {
113 if ((cols
= tgetnum("co")) == -1)
115 if ((lines
= tgetnum("li")) == -1)
120 TE
= tgetstr("te", &tcp
);
121 TI
= tgetstr("ti", &tcp
);
122 UP
= tgetstr("up", &tcp
);
123 if (!(LL
= tgetstr("ll", &tcp
))) {
124 if (!(LL
= malloc((u_int
)10))) {
125 fprintf(stderr
, "%s: out of space.\n", *argv
);
128 (void)strcpy(LL
, tgoto(CM
, 0, 23));
130 (void)signal(SIGHUP
, onsig
);
131 (void)signal(SIGINT
, onsig
);
132 (void)signal(SIGQUIT
, onsig
);
133 (void)signal(SIGSTOP
, onsig
);
134 (void)signal(SIGTSTP
, onsig
);
135 (void)signal(SIGTERM
, onsig
);
138 sg
.c_iflag
&= ~ICRNL
;
139 sg
.c_oflag
&= ~ONLCR
;
141 tcsetattr(1, TCSADRAIN
, &sg
);
143 tputs(TI
, 1, fputchar
);
144 tputs(tgetstr("cl", &tcp
), 1, fputchar
);
145 (void)fflush(stdout
);
146 for (j
= 4; j
>= 0; --j
) {
147 xpos
[j
] = random() % cols
+ 2;
148 ypos
[j
] = random() % lines
+ 2;
151 x
= random() % cols
+ 2;
152 y
= random() % lines
+ 2;
155 cursor(xpos
[j
], ypos
[j
]);
159 cursor(xpos
[j
], ypos
[j
]);
163 cursor(xpos
[j
], ypos
[j
] - 1);
165 tputs(DN
, 1, fputchar
);
166 tputs(BC
, 1, fputchar
);
167 tputs(BC
, 1, fputchar
);
168 fputs("|.|", stdout
);
169 tputs(DN
, 1, fputchar
);
170 tputs(BC
, 1, fputchar
);
171 tputs(BC
, 1, fputchar
);
175 cursor(xpos
[j
], ypos
[j
] - 2);
177 tputs(DN
, 1, fputchar
);
178 tputs(BC
, 1, fputchar
);
179 tputs(BC
, 1, fputchar
);
180 fputs("/ \\", stdout
);
181 cursor(xpos
[j
] - 2, ypos
[j
]);
182 fputs("| O |", stdout
);
183 cursor(xpos
[j
] - 1, ypos
[j
] + 1);
184 fputs("\\ /", stdout
);
185 tputs(DN
, 1, fputchar
);
186 tputs(BC
, 1, fputchar
);
187 tputs(BC
, 1, fputchar
);
191 cursor(xpos
[j
], ypos
[j
] - 2);
193 tputs(DN
, 1, fputchar
);
194 tputs(BC
, 1, fputchar
);
195 tputs(BC
, 1, fputchar
);
197 tputs(ND
, 1, fputchar
);
199 cursor(xpos
[j
] - 2, ypos
[j
]);
201 tputs(ND
, 1, fputchar
);
203 tputs(ND
, 1, fputchar
);
205 cursor(xpos
[j
] - 1, ypos
[j
] + 1);
207 tputs(ND
, 1, fputchar
);
209 tputs(DN
, 1, fputchar
);
210 tputs(BC
, 1, fputchar
);
211 tputs(BC
, 1, fputchar
);
215 (void)fflush(stdout
);
223 tputs(LL
, 1, fputchar
);
225 tputs(TE
, 1, fputchar
);
226 (void)fflush(stdout
);
227 tcsetattr(1, TCSADRAIN
, &old_tty
);