|
|
1.1 ! root 1: /* ! 2: * Copyright (c) 1980 Regents of the University of California. ! 3: * All rights reserved. ! 4: * ! 5: * Redistribution and use in source and binary forms are permitted ! 6: * provided that: (1) source distributions retain this entire copyright ! 7: * notice and comment, and (2) distributions including binaries display ! 8: * the following acknowledgement: ``This product includes software ! 9: * developed by the University of California, Berkeley and its contributors'' ! 10: * in the documentation or other materials provided with the distribution ! 11: * and in all advertising materials mentioning features or use of this ! 12: * software. Neither the name of the University nor the names of its ! 13: * contributors may be used to endorse or promote products derived ! 14: * from this software without specific prior written permission. ! 15: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR ! 16: * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED ! 17: * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ! 18: */ ! 19: ! 20: #ifndef lint ! 21: char copyright[] = ! 22: "@(#) Copyright (c) 1980 Regents of the University of California.\n\ ! 23: All rights reserved.\n"; ! 24: #endif /* not lint */ ! 25: ! 26: #ifndef lint ! 27: static char sccsid[] = "@(#)rain.c 5.5 (Berkeley) 6/1/90"; ! 28: #endif /* not lint */ ! 29: ! 30: /* ! 31: * rain 11/3/1980 EPS/CITHEP ! 32: * cc rain.c -o rain -O -ltermlib ! 33: */ ! 34: ! 35: #include <sys/types.h> ! 36: #include <stdio.h> ! 37: #ifdef USG ! 38: #include <termio.h> ! 39: #else ! 40: #include <sgtty.h> ! 41: #endif ! 42: #include <signal.h> ! 43: ! 44: #define cursor(c, r) tputs(tgoto(CM, c, r), 1, fputchar) ! 45: ! 46: #ifdef USG ! 47: static struct termio sg, old_tty; ! 48: #else ! 49: static struct sgttyb sg, old_tty; ! 50: #endif ! 51: ! 52: int fputchar(); ! 53: char *LL, *TE, *tgoto(); ! 54: ! 55: main(argc, argv) ! 56: int argc; ! 57: char **argv; ! 58: { ! 59: extern short ospeed; ! 60: extern char *UP; ! 61: register int x, y, j; ! 62: register char *CM, *BC, *DN, *ND, *term; ! 63: char *TI, *tcp, *mp, tcb[100], ! 64: *malloc(), *getenv(), *strcpy(), *tgetstr(); ! 65: long cols, lines, random(); ! 66: int xpos[5], ypos[5], onsig(); ! 67: ! 68: if (!(term = getenv("TERM"))) { ! 69: fprintf(stderr, "%s: TERM: parameter not set\n", *argv); ! 70: exit(1); ! 71: } ! 72: if (!(mp = malloc((u_int)1024))) { ! 73: fprintf(stderr, "%s: out of space.\n", *argv); ! 74: exit(1); ! 75: } ! 76: if (tgetent(mp, term) <= 0) { ! 77: fprintf(stderr, "%s: %s: unknown terminal type\n", *argv, term); ! 78: exit(1); ! 79: } ! 80: tcp = tcb; ! 81: if (!(CM = tgetstr("cm", &tcp))) { ! 82: fprintf(stderr, "%s: terminal not capable of cursor motion\n", *argv); ! 83: exit(1); ! 84: } ! 85: if (!(BC = tgetstr("bc", &tcp))) ! 86: BC = "\b"; ! 87: if (!(DN = tgetstr("dn", &tcp))) ! 88: DN = "\n"; ! 89: if (!(ND = tgetstr("nd", &tcp))) ! 90: ND = " "; ! 91: if ((cols = tgetnum("co")) == -1) ! 92: cols = 80; ! 93: if ((lines = tgetnum("li")) == -1) ! 94: lines = 24; ! 95: cols -= 4; ! 96: lines -= 4; ! 97: TE = tgetstr("te", &tcp); ! 98: TI = tgetstr("ti", &tcp); ! 99: UP = tgetstr("up", &tcp); ! 100: if (!(LL = tgetstr("ll", &tcp))) { ! 101: if (!(LL = malloc((u_int)10))) { ! 102: fprintf(stderr, "%s: out of space.\n", *argv); ! 103: exit(1); ! 104: } ! 105: (void)strcpy(LL, tgoto(CM, 0, 23)); ! 106: } ! 107: #ifdef USG ! 108: ioctl(1, TCGETA, &sg); ! 109: ospeed = sg.c_cflag&CBAUD; ! 110: #else ! 111: gtty(1, &sg); ! 112: ospeed = sg.sg_ospeed; ! 113: #endif ! 114: (void)signal(SIGHUP, onsig); ! 115: (void)signal(SIGINT, onsig); ! 116: (void)signal(SIGQUIT, onsig); ! 117: (void)signal(SIGSTOP, onsig); ! 118: (void)signal(SIGTSTP, onsig); ! 119: (void)signal(SIGTERM, onsig); ! 120: #ifdef USG ! 121: ioctl(1, TCGETA, &old_tty); /* save tty bits for exit */ ! 122: ioctl(1, TCGETA, &sg); ! 123: sg.c_iflag &= ~ICRNL; ! 124: sg.c_oflag &= ~ONLCR; ! 125: sg.c_lflag &= ~ECHO; ! 126: ioctl(1, TCSETAW, &sg); ! 127: #else ! 128: gtty(1, &old_tty); /* save tty bits for exit */ ! 129: gtty(1, &sg); ! 130: sg.sg_flags &= ~(CRMOD|ECHO); ! 131: stty(1, &sg); ! 132: #endif ! 133: if (TI) ! 134: tputs(TI, 1, fputchar); ! 135: tputs(tgetstr("cl", &tcp), 1, fputchar); ! 136: (void)fflush(stdout); ! 137: for (j = 4; j >= 0; --j) { ! 138: xpos[j] = random() % cols + 2; ! 139: ypos[j] = random() % lines + 2; ! 140: } ! 141: for (j = 0;;) { ! 142: x = random() % cols + 2; ! 143: y = random() % lines + 2; ! 144: cursor(x, y); ! 145: fputchar('.'); ! 146: cursor(xpos[j], ypos[j]); ! 147: fputchar('o'); ! 148: if (!j--) ! 149: j = 4; ! 150: cursor(xpos[j], ypos[j]); ! 151: fputchar('O'); ! 152: if (!j--) ! 153: j = 4; ! 154: cursor(xpos[j], ypos[j] - 1); ! 155: fputchar('-'); ! 156: tputs(DN, 1, fputchar); ! 157: tputs(BC, 1, fputchar); ! 158: tputs(BC, 1, fputchar); ! 159: fputs("|.|", stdout); ! 160: tputs(DN, 1, fputchar); ! 161: tputs(BC, 1, fputchar); ! 162: tputs(BC, 1, fputchar); ! 163: fputchar('-'); ! 164: if (!j--) ! 165: j = 4; ! 166: cursor(xpos[j], ypos[j] - 2); ! 167: fputchar('-'); ! 168: tputs(DN, 1, fputchar); ! 169: tputs(BC, 1, fputchar); ! 170: tputs(BC, 1, fputchar); ! 171: fputs("/ \\", stdout); ! 172: cursor(xpos[j] - 2, ypos[j]); ! 173: fputs("| O |", stdout); ! 174: cursor(xpos[j] - 1, ypos[j] + 1); ! 175: fputs("\\ /", stdout); ! 176: tputs(DN, 1, fputchar); ! 177: tputs(BC, 1, fputchar); ! 178: tputs(BC, 1, fputchar); ! 179: fputchar('-'); ! 180: if (!j--) ! 181: j = 4; ! 182: cursor(xpos[j], ypos[j] - 2); ! 183: fputchar(' '); ! 184: tputs(DN, 1, fputchar); ! 185: tputs(BC, 1, fputchar); ! 186: tputs(BC, 1, fputchar); ! 187: fputchar(' '); ! 188: tputs(ND, 1, fputchar); ! 189: fputchar(' '); ! 190: cursor(xpos[j] - 2, ypos[j]); ! 191: fputchar(' '); ! 192: tputs(ND, 1, fputchar); ! 193: fputchar(' '); ! 194: tputs(ND, 1, fputchar); ! 195: fputchar(' '); ! 196: cursor(xpos[j] - 1, ypos[j] + 1); ! 197: fputchar(' '); ! 198: tputs(ND, 1, fputchar); ! 199: fputchar(' '); ! 200: tputs(DN, 1, fputchar); ! 201: tputs(BC, 1, fputchar); ! 202: tputs(BC, 1, fputchar); ! 203: fputchar(' '); ! 204: xpos[j] = x; ! 205: ypos[j] = y; ! 206: (void)fflush(stdout); ! 207: } ! 208: } ! 209: ! 210: static ! 211: onsig() ! 212: { ! 213: tputs(LL, 1, fputchar); ! 214: if (TE) ! 215: tputs(TE, 1, fputchar); ! 216: (void)fflush(stdout); ! 217: #ifdef USG ! 218: ioctl(1, TCSETAW, &old_tty); ! 219: #else ! 220: stty(1, &old_tty); ! 221: #endif ! 222: exit(0); ! 223: } ! 224: ! 225: static ! 226: fputchar(c) ! 227: char c; ! 228: { ! 229: putchar(c); ! 230: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.