remove .ARPA hack; breaks with domain names
[unix-history] / usr / src / games / rain / rain.c
CommitLineData
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
8char 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
14static char sccsid[] = "@(#)rain.c 5.1 (Berkeley) %G%";
15#endif not lint
d5bda5f3
KM
16
17#include <stdio.h>
18#include <sgtty.h>
19#include <signal.h>
20/* rain 11/3/1980 EPS/CITHEP */
21/* cc rain.c -o rain -O -ltermlib */
22#define cursor(col,row) tputs(tgoto(CM,col,row),1,outc)
23outc(c)
24{
25 putchar(c);
26}
27extern char *UP;
28extern short ospeed;
29struct sgttyb old_tty;
30char *LL, *TE, *TI;
31main(argc,argv)
32int argc;
33char *argv[];
34{
35 extern fputchar();
36 char *malloc();
37 char *getenv();
38 char *tgetstr(), *tgoto();
39 float ranf();
40 int onsig();
41 register int x, y, j;
42 static int xpos[5], ypos[5];
43 register char *CM, *BC, *DN, *ND;
44 char *tcp;
45 register char *term;
46 char tcb[100];
47 struct sgttyb sg;
48 setbuf(stdout,malloc(BUFSIZ));
49 if (!(term=getenv("TERM"))) {
50 fprintf(stderr,"%s: TERM: parameter not set\n",*argv);
51 exit(1);
52 }
53 if (tgetent(malloc(1024),term)<=0) {
54 fprintf(stderr,"%s: %s: unknown terminal type\n",*argv,term);
55 exit(1);
56 }
57 tcp=tcb;
58 if (!(CM=tgetstr("cm",&tcp))) {
59 fprintf(stderr,"%s: terminal not capable of cursor motion\n",*argv);
60 exit(1);
61 }
62 if (!(BC=tgetstr("bc",&tcp))) BC="\b";
63 if (!(DN=tgetstr("dn",&tcp))) DN="\n";
64 if (!(ND=tgetstr("nd",&tcp))) ND=" ";
65 TE=tgetstr("te",&tcp);
66 TI=tgetstr("ti",&tcp);
67 UP=tgetstr("up",&tcp);
68 if (!(LL=tgetstr("ll",&tcp))) strcpy(LL=malloc(10),tgoto(CM,0,23));
69 gtty(1, &sg);
70 ospeed=sg.sg_ospeed;
71 for (j=SIGHUP;j<=SIGTERM;j++)
72 if (signal(j,SIG_IGN)!=SIG_IGN) signal(j,onsig);
73 gtty(1, &old_tty); /* save tty bits for exit */
74 gtty(1, &sg);
75 sg.sg_flags&=~(CRMOD|ECHO);
76 stty(1, &sg);
77 if (TI) fputs(TI,stdout);
78 tputs(tgetstr("cl",&tcp),1,fputchar);
79 fflush(stdout);
80 for (j=5;--j>=0;) {
81 xpos[j]=(int)(76.*ranf())+2;
82 ypos[j]=(int)(20.*ranf())+2;
83 }
84 for (j=0;;) {
85 x=(int)(76.*ranf())+2;
86 y=(int)(20.*ranf())+2;
87 cursor(x,y); fputchar('.');
88 cursor(xpos[j],ypos[j]); fputchar('o');
89 if (j==0) j=4; else --j;
90 cursor(xpos[j],ypos[j]); fputchar('O');
91 if (j==0) j=4; else --j;
92 cursor(xpos[j],ypos[j]-1);
93 fputchar('-');
94 fputs(DN,stdout); fputs(BC,stdout); fputs(BC,stdout);
95 fputs("|.|",stdout);
96 fputs(DN,stdout); fputs(BC,stdout); fputs(BC,stdout);
97 fputchar('-');
98 if (j==0) j=4; else --j;
99 cursor(xpos[j],ypos[j]-2); fputchar('-');
100 fputs(DN,stdout); fputs(BC,stdout); fputs(BC,stdout);
101 fputs("/ \\",stdout);
102 cursor(xpos[j]-2,ypos[j]);
103 fputs("| O |",stdout);
104 cursor(xpos[j]-1,ypos[j]+1);
105 fputs("\\ /",stdout);
106 fputs(DN,stdout); fputs(BC,stdout); fputs(BC,stdout);
107 fputchar('-');
108 if (j==0) j=4; else --j;
109 cursor(xpos[j],ypos[j]-2); fputchar(' ');
110 fputs(DN,stdout); fputs(BC,stdout); fputs(BC,stdout);
111 fputchar(' '); fputs(ND,stdout); fputchar(' ');
112 cursor(xpos[j]-2,ypos[j]);
113 fputchar(' '); fputs(ND,stdout); fputchar(' ');
114 fputs(ND,stdout); fputchar(' ');
115 cursor(xpos[j]-1,ypos[j]+1);
116 fputchar(' '); fputs(ND,stdout); fputchar(' ');
117 fputs(DN,stdout); fputs(BC,stdout); fputs(BC,stdout);
118 fputchar(' ');
119 xpos[j]=x; ypos[j]=y;
120 fflush(stdout);
121 }
122}
123onsig(n)
124int n;
125{
126 struct sgttyb sg;
127 fputs(LL, stdout);
128 if (TE) fputs(TE, stdout);
129 fflush(stdout);
130 stty(1, &old_tty);
131 kill(getpid(),n);
132 _exit(0);
133}
134fputchar(c)
135char c;
136{
137 putchar(c);
138}
139float ranf() {
140 return((float)rand()/2147483647.);
141}