1 .\" Copyright (c) 1980, 1993
2 .\"	 The Regents of the University of California.  All rights reserved.
3 .\"
4 .\" %sccs.include.redist.roff%
5 .\"
6 .\"	@(#)twinkle2.c	8.1 (Berkeley) 06/08/93
7 .\"
8 extern int	_putchar();
9 
10 main()
11 {
12 	reg char	*sp;
13 
14 	srand(getpid());		/* initialize random sequence */
15 
16 	if (isatty(0)) {
17 	       gettmode();
18 	       if ((sp = getenv("TERM")) != NULL)
19 		       setterm(sp);
20 		signal(SIGINT, die);
21 	}
22 	else {
23 		printf("Need a terminal on %d\n", _tty_ch);
24 		exit(1);
25 	}
26 	_puts(TI);
27 	_puts(VS);
28 
29 	noecho();
30 	nonl();
31 	tputs(CL, NLINES, _putchar);
32 	for (;;) {
33 		makeboard();		/* make the board setup */
34 		puton('*');		/* put on '*'s */
35 		puton(' ');		/* cover up with ' 's */
36 	}
37 }
38 
39 puton(ch)
40 char	ch;
41 {
42 	reg LOCS	*lp;
43 	reg int		r;
44 	reg LOCS	*end;
45 	LOCS		temp;
46 	static int	lasty, lastx;
47 
48 	end = &Layout[Numstars];
49 	for (lp = Layout; lp < end; lp++) {
50 		r = rand() % Numstars;
51 		temp = *lp;
52 		*lp = Layout[r];
53 		Layout[r] = temp;
54 	}
55 
56 	for (lp = Layout; lp < end; lp++)
57 			/* prevent scrolling */
58 		if (!AM || (lp->y < NLINES - 1 || lp->x < NCOLS - 1)) {
59 			mvcur(lasty, lastx, lp->y, lp->x);
60 			putchar(ch);
61 			lasty = lp->y;
62 			if ((lastx = lp->x + 1) >= NCOLS)
63 				if (AM) {
64 					lastx = 0;
65 					lasty++;
66 				}
67 				else
68 					lastx = NCOLS - 1;
69 		}
70 }
71