]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - rain/rain.c
2 * Copyright (c) 1980 Regents of the University of California.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 "@(#) Copyright (c) 1980 Regents of the University of California.\n\
37 All rights reserved.\n";
41 /*static char sccsid[] = "from: @(#)rain.c 5.6 (Berkeley) 2/28/91";*/
42 static char rcsid
[] = "$Id: rain.c,v 1.3 1993/12/08 08:18:22 mycroft Exp $";
46 * rain 11/3/1980 EPS/CITHEP
47 * cc rain.c -o rain -O -ltermlib
50 #include <sys/types.h>
59 #define cursor(c, r) tputs(tgoto(CM, c, r), 1, fputchar)
62 static struct termio sg
, old_tty
;
64 static struct sgttyb sg
, old_tty
;
67 static void fputchar();
68 char *LL
, *TE
, *tgoto();
77 register char *CM
, *BC
, *DN
, *ND
, *term
;
78 char *TI
, *tcp
, *mp
, tcb
[100],
79 *malloc(), *getenv(), *strcpy(), *tgetstr();
80 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
)))
107 if ((cols
= tgetnum("co")) == -1)
109 if ((lines
= tgetnum("li")) == -1)
113 TE
= tgetstr("te", &tcp
);
114 TI
= tgetstr("ti", &tcp
);
115 UP
= tgetstr("up", &tcp
);
116 if (!(LL
= tgetstr("ll", &tcp
))) {
117 if (!(LL
= malloc((u_int
)10))) {
118 fprintf(stderr
, "%s: out of space.\n", *argv
);
121 (void)strcpy(LL
, tgoto(CM
, 0, 23));
124 ioctl(1, TCGETA
, &sg
);
125 ospeed
= sg
.c_cflag
&CBAUD
;
128 ospeed
= sg
.sg_ospeed
;
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
);
137 ioctl(1, TCGETA
, &old_tty
); /* save tty bits for exit */
138 ioctl(1, TCGETA
, &sg
);
139 sg
.c_iflag
&= ~ICRNL
;
140 sg
.c_oflag
&= ~ONLCR
;
142 ioctl(1, TCSETAW
, &sg
);
144 gtty(1, &old_tty
); /* save tty bits for exit */
146 sg
.sg_flags
&= ~(CRMOD
|ECHO
);
150 tputs(TI
, 1, fputchar
);
151 tputs(tgetstr("cl", &tcp
), 1, fputchar
);
152 (void)fflush(stdout
);
153 for (j
= 4; j
>= 0; --j
) {
154 xpos
[j
] = random() % cols
+ 2;
155 ypos
[j
] = random() % lines
+ 2;
158 x
= random() % cols
+ 2;
159 y
= random() % lines
+ 2;
162 cursor(xpos
[j
], ypos
[j
]);
166 cursor(xpos
[j
], ypos
[j
]);
170 cursor(xpos
[j
], ypos
[j
] - 1);
172 tputs(DN
, 1, fputchar
);
173 tputs(BC
, 1, fputchar
);
174 tputs(BC
, 1, fputchar
);
175 fputs("|.|", stdout
);
176 tputs(DN
, 1, fputchar
);
177 tputs(BC
, 1, fputchar
);
178 tputs(BC
, 1, fputchar
);
182 cursor(xpos
[j
], ypos
[j
] - 2);
184 tputs(DN
, 1, fputchar
);
185 tputs(BC
, 1, fputchar
);
186 tputs(BC
, 1, fputchar
);
187 fputs("/ \\", stdout
);
188 cursor(xpos
[j
] - 2, ypos
[j
]);
189 fputs("| O |", stdout
);
190 cursor(xpos
[j
] - 1, ypos
[j
] + 1);
191 fputs("\\ /", stdout
);
192 tputs(DN
, 1, fputchar
);
193 tputs(BC
, 1, fputchar
);
194 tputs(BC
, 1, fputchar
);
198 cursor(xpos
[j
], ypos
[j
] - 2);
200 tputs(DN
, 1, fputchar
);
201 tputs(BC
, 1, fputchar
);
202 tputs(BC
, 1, fputchar
);
204 tputs(ND
, 1, fputchar
);
206 cursor(xpos
[j
] - 2, ypos
[j
]);
208 tputs(ND
, 1, fputchar
);
210 tputs(ND
, 1, fputchar
);
212 cursor(xpos
[j
] - 1, ypos
[j
] + 1);
214 tputs(ND
, 1, fputchar
);
216 tputs(DN
, 1, fputchar
);
217 tputs(BC
, 1, fputchar
);
218 tputs(BC
, 1, fputchar
);
222 (void)fflush(stdout
);
229 tputs(LL
, 1, fputchar
);
231 tputs(TE
, 1, fputchar
);
232 (void)fflush(stdout
);
234 ioctl(1, TCSETAW
, &old_tty
);