Annotation of 43BSDReno/share/doc/ps1/18.curses/twinkle2.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Copyright (c) 1980 The 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 the above copyright notice and this paragraph are
                      7:  * duplicated in all such forms and that any documentation,
                      8:  * advertising materials, and other materials related to such
                      9:  * distribution and use acknowledge that the software was developed
                     10:  * by the University of California, Berkeley.  The name of the
                     11:  * University may not be used to endorse or promote products derived
                     12:  * from this software without specific prior written permission.
                     13:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
                     14:  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
                     15:  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
                     16:  */
                     17: 
                     18: #ifndef lint
                     19: char copyright[] =
                     20: "@(#) Copyright (c) 1980 The Regents of the University of California.\n\
                     21:  All rights reserved.\n";
                     22: #endif /* not lint */
                     23: 
                     24: #ifndef lint
                     25: static char sccsid[] = "@(#)twinkle2.c 6.2 (Berkeley) 3/17/89";
                     26: #endif /* not lint */
                     27: 
                     28: extern int     _putchar();
                     29: 
                     30: main()
                     31: {
                     32:        reg char        *sp;
                     33: 
                     34:        srand(getpid());                /* initialize random sequence */
                     35: 
                     36:        if (isatty(0)) {
                     37:               gettmode();
                     38:               if ((sp = getenv("TERM")) != NULL)
                     39:                       setterm(sp);
                     40:                signal(SIGINT, die);
                     41:        }
                     42:        else {
                     43:                printf("Need a terminal on %d\n", _tty_ch);
                     44:                exit(1);
                     45:        }
                     46:        _puts(TI);
                     47:        _puts(VS);
                     48: 
                     49:        noecho();
                     50:        nonl();
                     51:        tputs(CL, NLINES, _putchar);
                     52:        for (;;) {
                     53:                makeboard();            /* make the board setup */
                     54:                puton('*');             /* put on '*'s */
                     55:                puton(' ');             /* cover up with ' 's */
                     56:        }
                     57: }
                     58: 
                     59: puton(ch)
                     60: char   ch;
                     61: {
                     62:        reg LOCS        *lp;
                     63:        reg int         r;
                     64:        reg LOCS        *end;
                     65:        LOCS            temp;
                     66:        static int      lasty, lastx;
                     67: 
                     68:        end = &Layout[Numstars];
                     69:        for (lp = Layout; lp < end; lp++) {
                     70:                r = rand() % Numstars;
                     71:                temp = *lp;
                     72:                *lp = Layout[r];
                     73:                Layout[r] = temp;
                     74:        }
                     75: 
                     76:        for (lp = Layout; lp < end; lp++)
                     77:                        /* prevent scrolling */
                     78:                if (!AM || (lp->y < NLINES - 1 || lp->x < NCOLS - 1)) {
                     79:                        mvcur(lasty, lastx, lp->y, lp->x);
                     80:                        putchar(ch);
                     81:                        lasty = lp->y;
                     82:                        if ((lastx = lp->x + 1) >= NCOLS)
                     83:                                if (AM) {
                     84:                                        lastx = 0;
                     85:                                        lasty++;
                     86:                                }
                     87:                                else
                     88:                                        lastx = NCOLS - 1;
                     89:                }
                     90: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.