|
|
1.1 root 1: #include <stdio.h>
2: #include <sgtty.h>
3: #include <signal.h>
4: /* rain 11/3/1980 EPS/CITHEP */
5: /* cc rain.c -o rain -O -ltermlib */
6: #define cursor(col,row) fputs(tgoto(CM,col,row),stdout)
7: extern char *UP;
8: extern short ospeed;
9: struct sgttyb old_tty;
10: char *LL, *TE, *TI;
11: main(argc,argv)
12: int argc;
13: char *argv[];
14: {
15: extern fputchar();
16: char *malloc();
17: char *getenv();
18: char *tgetstr(), *tgoto();
19: float ranf();
20: int onsig();
21: register int x, y, j;
22: static int xpos[5], ypos[5];
23: register char *CM, *BC, *DN, *ND;
24: char *tcp;
25: register char *term;
26: char tcb[100];
27: struct sgttyb sg;
28: setbuf(stdout,malloc(BUFSIZ));
29: if (!(term=getenv("TERM"))) {
30: fprintf(stderr,"%s: TERM: parameter not set\n",*argv);
31: exit(1);
32: }
33: if (tgetent(malloc(1024),term)<=0) {
34: fprintf(stderr,"%s: %s: unknown terminal type\n",*argv,term);
35: exit(1);
36: }
37: tcp=tcb;
38: if (!(CM=tgetstr("cm",&tcp))) {
39: fprintf(stderr,"%s: terminal not capable of cursor motion\n",*argv);
40: exit(1);
41: }
42: if (!(BC=tgetstr("bc",&tcp))) BC="\b";
43: if (!(DN=tgetstr("dn",&tcp))) DN="\n";
44: if (!(ND=tgetstr("nd",&tcp))) ND=" ";
45: TE=tgetstr("te",&tcp);
46: TI=tgetstr("ti",&tcp);
47: UP=tgetstr("up",&tcp);
48: if (!(LL=tgetstr("ll",&tcp))) strcpy(LL=malloc(10),tgoto(CM,0,23));
49: gtty(1, &sg);
50: ospeed=sg.sg_ospeed;
51: for (j=SIGHUP;j<=SIGTERM;j++)
52: if (signal(j,SIG_IGN)!=SIG_IGN) signal(j,onsig);
53: gtty(1, &old_tty); /* save tty bits for exit */
54: gtty(1, &sg);
55: sg.sg_flags&=~(CRMOD|ECHO);
56: stty(1, &sg);
57: if (TI) fputs(TI,stdout);
58: tputs(tgetstr("cl",&tcp),1,fputchar);
59: fflush(stdout);
60: for (j=5;--j>=0;) {
61: xpos[j]=(int)(76.*ranf())+2;
62: ypos[j]=(int)(20.*ranf())+2;
63: }
64: for (j=0;;) {
65: x=(int)(76.*ranf())+2;
66: y=(int)(20.*ranf())+2;
67: cursor(x,y); fputchar('.');
68: cursor(xpos[j],ypos[j]); fputchar('o');
69: if (j==0) j=4; else --j;
70: cursor(xpos[j],ypos[j]); fputchar('O');
71: if (j==0) j=4; else --j;
72: cursor(xpos[j],ypos[j]-1);
73: fputchar('-');
74: fputs(DN,stdout); fputs(BC,stdout); fputs(BC,stdout);
75: fputs("|.|",stdout);
76: fputs(DN,stdout); fputs(BC,stdout); fputs(BC,stdout);
77: fputchar('-');
78: if (j==0) j=4; else --j;
79: cursor(xpos[j],ypos[j]-2); fputchar('-');
80: fputs(DN,stdout); fputs(BC,stdout); fputs(BC,stdout);
81: fputs("/ \\",stdout);
82: cursor(xpos[j]-2,ypos[j]);
83: fputs("| O |",stdout);
84: cursor(xpos[j]-1,ypos[j]+1);
85: fputs("\\ /",stdout);
86: fputs(DN,stdout); fputs(BC,stdout); fputs(BC,stdout);
87: fputchar('-');
88: if (j==0) j=4; else --j;
89: cursor(xpos[j],ypos[j]-2); fputchar(' ');
90: fputs(DN,stdout); fputs(BC,stdout); fputs(BC,stdout);
91: fputchar(' '); fputs(ND,stdout); fputchar(' ');
92: cursor(xpos[j]-2,ypos[j]);
93: fputchar(' '); fputs(ND,stdout); fputchar(' ');
94: fputs(ND,stdout); fputchar(' ');
95: cursor(xpos[j]-1,ypos[j]+1);
96: fputchar(' '); fputs(ND,stdout); fputchar(' ');
97: fputs(DN,stdout); fputs(BC,stdout); fputs(BC,stdout);
98: fputchar(' ');
99: xpos[j]=x; ypos[j]=y;
100: fflush(stdout);
101: }
102: }
103: onsig(n)
104: int n;
105: {
106: struct sgttyb sg;
107: fputs(LL, stdout);
108: if (TE) fputs(TE, stdout);
109: fflush(stdout);
110: stty(1, &old_tty);
111: kill(getpid(),n);
112: _exit(0);
113: }
114: fputchar(c)
115: char c;
116: {
117: putchar(c);
118: }
119: float ranf() {
120: return((float)lrand()/2147483647.);
121: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.