Commit | Line | Data |
---|---|---|
e0bbfbf9 DF |
1 | /* |
2 | * Copyright (c) 1980 Regents of the University of California. | |
3 | * All rights reserved. The Berkeley software License Agreement | |
4 | * specifies the terms and conditions for redistribution. | |
5 | */ | |
d5bda5f3 | 6 | |
e0bbfbf9 DF |
7 | #ifndef lint |
8 | char copyright[] = | |
9 | "@(#) Copyright (c) 1980 Regents of the University of California.\n\ | |
10 | All rights reserved.\n"; | |
11 | #endif not lint | |
12 | ||
13 | #ifndef lint | |
bd3e1287 | 14 | static char sccsid[] = "@(#)rain.c 5.3 (Berkeley) %G%"; |
e0bbfbf9 | 15 | #endif not lint |
d5bda5f3 | 16 | |
4334b5fc KM |
17 | #define BSD |
18 | ||
d5bda5f3 | 19 | #include <stdio.h> |
4334b5fc KM |
20 | #ifdef USG |
21 | #include <termio.h> | |
22 | #else | |
d5bda5f3 | 23 | #include <sgtty.h> |
4334b5fc | 24 | #endif |
d5bda5f3 KM |
25 | #include <signal.h> |
26 | /* rain 11/3/1980 EPS/CITHEP */ | |
27 | /* cc rain.c -o rain -O -ltermlib */ | |
4334b5fc | 28 | #define cursor(col,row) tputs(tgoto(CM,col,row),1,fputchar) |
d5bda5f3 KM |
29 | extern char *UP; |
30 | extern short ospeed; | |
4334b5fc KM |
31 | #ifdef USG |
32 | struct termio old_tty; | |
33 | #else | |
d5bda5f3 | 34 | struct sgttyb old_tty; |
4334b5fc | 35 | #endif |
d5bda5f3 KM |
36 | char *LL, *TE, *TI; |
37 | main(argc,argv) | |
38 | int argc; | |
39 | char *argv[]; | |
40 | { | |
41 | extern fputchar(); | |
42 | char *malloc(); | |
43 | char *getenv(); | |
44 | char *tgetstr(), *tgoto(); | |
45 | float ranf(); | |
46 | int onsig(); | |
47 | register int x, y, j; | |
48 | static int xpos[5], ypos[5]; | |
49 | register char *CM, *BC, *DN, *ND; | |
4334b5fc | 50 | int CO, LI; |
d5bda5f3 KM |
51 | char *tcp; |
52 | register char *term; | |
53 | char tcb[100]; | |
4334b5fc KM |
54 | #ifdef USG |
55 | struct termio sg; | |
56 | #else | |
d5bda5f3 | 57 | struct sgttyb sg; |
4334b5fc KM |
58 | #endif |
59 | float cols, lines; | |
60 | ||
d5bda5f3 KM |
61 | setbuf(stdout,malloc(BUFSIZ)); |
62 | if (!(term=getenv("TERM"))) { | |
63 | fprintf(stderr,"%s: TERM: parameter not set\n",*argv); | |
64 | exit(1); | |
65 | } | |
66 | if (tgetent(malloc(1024),term)<=0) { | |
67 | fprintf(stderr,"%s: %s: unknown terminal type\n",*argv,term); | |
68 | exit(1); | |
69 | } | |
70 | tcp=tcb; | |
71 | if (!(CM=tgetstr("cm",&tcp))) { | |
72 | fprintf(stderr,"%s: terminal not capable of cursor motion\n",*argv); | |
73 | exit(1); | |
74 | } | |
75 | if (!(BC=tgetstr("bc",&tcp))) BC="\b"; | |
76 | if (!(DN=tgetstr("dn",&tcp))) DN="\n"; | |
77 | if (!(ND=tgetstr("nd",&tcp))) ND=" "; | |
4334b5fc KM |
78 | if ((CO = tgetnum("co")) == -1) |
79 | CO = 80; | |
80 | if ((LI = tgetnum("li")) == -1) | |
81 | LI = 24; | |
82 | cols = CO - 4; | |
83 | lines = LI - 4; | |
d5bda5f3 KM |
84 | TE=tgetstr("te",&tcp); |
85 | TI=tgetstr("ti",&tcp); | |
86 | UP=tgetstr("up",&tcp); | |
87 | if (!(LL=tgetstr("ll",&tcp))) strcpy(LL=malloc(10),tgoto(CM,0,23)); | |
4334b5fc KM |
88 | #ifdef USG |
89 | ioctl(1, TCGETA, &sg); | |
90 | ospeed=sg.c_cflag&CBAUD; | |
91 | #else | |
d5bda5f3 KM |
92 | gtty(1, &sg); |
93 | ospeed=sg.sg_ospeed; | |
4334b5fc | 94 | #endif |
d5bda5f3 KM |
95 | for (j=SIGHUP;j<=SIGTERM;j++) |
96 | if (signal(j,SIG_IGN)!=SIG_IGN) signal(j,onsig); | |
4334b5fc KM |
97 | #ifdef USG |
98 | ioctl(1, TCGETA, &old_tty); /* save tty bits for exit */ | |
99 | ioctl(1, TCGETA, &sg); | |
100 | sg.c_iflag&=~ICRNL; | |
101 | sg.c_oflag&=~ONLCR; | |
102 | sg.c_lflag&=~ECHO; | |
103 | ioctl(1, TCSETAW, &sg); | |
104 | #else | |
d5bda5f3 KM |
105 | gtty(1, &old_tty); /* save tty bits for exit */ |
106 | gtty(1, &sg); | |
107 | sg.sg_flags&=~(CRMOD|ECHO); | |
108 | stty(1, &sg); | |
4334b5fc KM |
109 | #endif |
110 | if (TI) tputs(TI,1,fputchar); | |
d5bda5f3 KM |
111 | tputs(tgetstr("cl",&tcp),1,fputchar); |
112 | fflush(stdout); | |
113 | for (j=5;--j>=0;) { | |
4334b5fc KM |
114 | xpos[j]=(int)(cols*ranf())+2; |
115 | ypos[j]=(int)(lines*ranf())+2; | |
d5bda5f3 KM |
116 | } |
117 | for (j=0;;) { | |
4334b5fc KM |
118 | x=(int)(cols*ranf())+2; |
119 | y=(int)(lines*ranf())+2; | |
d5bda5f3 KM |
120 | cursor(x,y); fputchar('.'); |
121 | cursor(xpos[j],ypos[j]); fputchar('o'); | |
122 | if (j==0) j=4; else --j; | |
123 | cursor(xpos[j],ypos[j]); fputchar('O'); | |
124 | if (j==0) j=4; else --j; | |
125 | cursor(xpos[j],ypos[j]-1); | |
126 | fputchar('-'); | |
4334b5fc | 127 | tputs(DN,1,fputchar); tputs(BC,1,fputchar); tputs(BC,1,fputchar); |
d5bda5f3 | 128 | fputs("|.|",stdout); |
4334b5fc | 129 | tputs(DN,1,fputchar); tputs(BC,1,fputchar); tputs(BC,1,fputchar); |
d5bda5f3 KM |
130 | fputchar('-'); |
131 | if (j==0) j=4; else --j; | |
132 | cursor(xpos[j],ypos[j]-2); fputchar('-'); | |
4334b5fc | 133 | tputs(DN,1,fputchar); tputs(BC,1,fputchar); tputs(BC,1,fputchar); |
d5bda5f3 KM |
134 | fputs("/ \\",stdout); |
135 | cursor(xpos[j]-2,ypos[j]); | |
136 | fputs("| O |",stdout); | |
137 | cursor(xpos[j]-1,ypos[j]+1); | |
138 | fputs("\\ /",stdout); | |
4334b5fc | 139 | tputs(DN,1,fputchar); tputs(BC,1,fputchar); tputs(BC,1,fputchar); |
d5bda5f3 KM |
140 | fputchar('-'); |
141 | if (j==0) j=4; else --j; | |
142 | cursor(xpos[j],ypos[j]-2); fputchar(' '); | |
4334b5fc KM |
143 | tputs(DN,1,fputchar); tputs(BC,1,fputchar); tputs(BC,1,fputchar); |
144 | fputchar(' '); tputs(ND,1,fputchar); fputchar(' '); | |
d5bda5f3 | 145 | cursor(xpos[j]-2,ypos[j]); |
4334b5fc KM |
146 | fputchar(' '); tputs(ND,1,fputchar); fputchar(' '); |
147 | tputs(ND,1,fputchar); fputchar(' '); | |
d5bda5f3 | 148 | cursor(xpos[j]-1,ypos[j]+1); |
4334b5fc KM |
149 | fputchar(' '); tputs(ND,1,fputchar); fputchar(' '); |
150 | tputs(DN,1,fputchar); tputs(BC,1,fputchar); tputs(BC,1,fputchar); | |
d5bda5f3 KM |
151 | fputchar(' '); |
152 | xpos[j]=x; ypos[j]=y; | |
153 | fflush(stdout); | |
154 | } | |
155 | } | |
156 | onsig(n) | |
157 | int n; | |
158 | { | |
4334b5fc KM |
159 | #ifdef USG |
160 | struct termio sg; | |
161 | #else | |
d5bda5f3 | 162 | struct sgttyb sg; |
4334b5fc KM |
163 | #endif |
164 | tputs(LL, 1, fputchar); | |
165 | if (TE) tputs(TE, 1, fputchar); | |
d5bda5f3 | 166 | fflush(stdout); |
4334b5fc KM |
167 | #ifdef USG |
168 | ioctl(1, TCSETAW, &old_tty); | |
169 | #else | |
d5bda5f3 | 170 | stty(1, &old_tty); |
4334b5fc | 171 | #endif |
d5bda5f3 KM |
172 | kill(getpid(),n); |
173 | _exit(0); | |
174 | } | |
175 | fputchar(c) | |
176 | char c; | |
177 | { | |
178 | putchar(c); | |
179 | } | |
180 | float ranf() { | |
4334b5fc | 181 | #ifdef BSD |
d5bda5f3 | 182 | return((float)rand()/2147483647.); |
4334b5fc KM |
183 | #else |
184 | return((float)rand()/32767.); | |
185 | #endif | |
d5bda5f3 | 186 | } |