Annotation of coherent/g/usr/lib/ncurses/lib_setup.c, revision 1.1

1.1     ! root        1: /*********************************************************************
        !             2: *                         COPYRIGHT NOTICE                           *
        !             3: **********************************************************************
        !             4: *        This software is copyright (C) 1982 by Pavel Curtis         *
        !             5: *                                                                    *
        !             6: *        Permission is granted to reproduce and distribute           *
        !             7: *        this file by any means so long as no fee is charged         *
        !             8: *        above a nominal handling fee and so long as this            *
        !             9: *        notice is always included in the copies.                    *
        !            10: *                                                                    *
        !            11: *        Other rights are reserved except as explicitly granted      *
        !            12: *        by written permission of the author.                        *
        !            13: *                Pavel Curtis                                        *
        !            14: *                Computer Science Dept.                              *
        !            15: *                405 Upson Hall                                      *
        !            16: *                Cornell University                                  *
        !            17: *                Ithaca, NY 14853                                    *
        !            18: *                                                                    *
        !            19: *                Ph- (607) 256-4934                                  *
        !            20: *                                                                    *
        !            21: *                Pavel.Cornell@Udel-Relay   (ARPAnet)                *
        !            22: *                decvax!cornell!pavel       (UUCPnet)                *
        !            23: *********************************************************************/
        !            24: 
        !            25: /*
        !            26:  *     setupterm(termname, filedes, errret)
        !            27:  *
        !            28:  *     Find and read the appropriate object file for the terminal
        !            29:  *     Make cur_term point to the structure.
        !            30:  *     Turn off the XTABS bit in the tty structure if it was on
        !            31:  *     If XTABS was on, remove the tab and backtab capabilities.
        !            32:  *
        !            33:  *  $Log:      lib_setup.c,v $
        !            34:  * Revision 1.11  93/04/12  14:14:08  bin
        !            35:  * Udo: third color update
        !            36:  * 
        !            37:  * Revision 2.4  92/11/29  15:40:02  munk
        !            38:  * Conditional usage of termio
        !            39:  *
        !            40:  * Revision 2.3  92/10/27  22:23:15  munk
        !            41:  * Initialize alternate character set map
        !            42:  *
        !            43:  * Revision 1.5  92/06/02  12:05:36  bin
        !            44:  * *** empty log message ***
        !            45:  * 
        !            46:  * Revision 1.2  92/04/13  14:38:31  bin
        !            47:  * update by vlad
        !            48:  * 
        !            49:  * Revision 2.2  91/04/20  21:45:19  munk
        !            50:  * Usage of register variables
        !            51:  * Made the large arrays static
        !            52:  *
        !            53:  * Revision 2.1  82/10/25  14:49:09  pavel
        !            54:  * Added Copyright Notice
        !            55:  * 
        !            56:  * Revision 2.0  82/10/24  15:17:46  pavel
        !            57:  * Beta-one Test Release
        !            58:  * 
        !            59:  * Revision 1.5  82/08/23  22:30:35  pavel
        !            60:  * The REAL Alpha-one Release Version
        !            61:  * 
        !            62:  * Revision 1.4  82/08/20  15:12:24  pavel
        !            63:  * Fixed use of un-initialised cur_term.
        !            64:  * 
        !            65:  * Revision 1.3  82/08/19  19:22:09  pavel
        !            66:  * Alpha Test Release One
        !            67:  * 
        !            68:  * Revision 1.2  82/08/19  19:11:28  pavel
        !            69:  * Alpha Test Release One
        !            70:  * 
        !            71:  * Revision 1.1  82/08/12  18:45:07  pavel
        !            72:  * Initial revision
        !            73:  * 
        !            74:  *
        !            75:  */
        !            76: 
        !            77: #ifdef RCSHDR
        !            78: static char RCSid[] =
        !            79:        "$Header: /src386/usr/lib/ncurses/RCS/lib_setup.c,v 1.11 93/04/12 14:14:08 bin Exp Locker: bin $";
        !            80: #endif
        !            81: 
        !            82: #include <stdio.h>
        !            83: #include "curses.h"
        !            84: #include "curses.priv.h"
        !            85: #include "term.h"
        !            86: 
        !            87: /*
        !            88:  * The original sources have Unix brain damage in that they assumed that a
        !            89:  * non-initialized data declaration in the headers was OK and would define
        !            90:  * the space for all to see. Sorry, but we do C, not Fortran.
        !            91:  */
        !            92: 
        !            93: struct term   *        __cur_term;
        !            94: 
        !            95: #define ret_error(code, fmt, arg)      if (errret)\
        !            96:                                        {\
        !            97:                                            *errret = code;\
        !            98:                                            return(code);\
        !            99:                                        }\
        !           100:                                        else\
        !           101:                                        {\
        !           102:                                            fprintf(stderr, fmt, arg);\
        !           103:                                            exit(1);\
        !           104:                                        }
        !           105: 
        !           106: 
        !           107: chtype acs_map[128];
        !           108: char   ttytype[NAMESIZE];
        !           109: struct term _first_term;
        !           110: 
        !           111: int    _tracing;
        !           112: struct screen *SP = 0;
        !           113: 
        !           114: 
        !           115: setupterm(termname, filedes, errret)
        !           116: char   *termname;
        !           117: int    filedes;
        !           118: int    *errret;
        !           119: {
        !           120:        char            filename[1024];
        !           121:        char            *malloc(), *getenv(), *strncpy();
        !           122:        char            *terminfo;
        !           123:        struct term     *term_ptr;
        !           124:        int             got_code;
        !           125: 
        !           126: #ifdef TRACE
        !           127:        _init_trace();
        !           128:        if (_tracing)
        !           129:            _tracef("setupterm(%s,%d,%o) called", termname, filedes, errret);
        !           130: #endif
        !           131: 
        !           132:        if (termname == NULL)
        !           133:        {
        !           134:            termname = getenv("TERM");
        !           135:            if (termname == NULL)
        !           136:                ret_error(-1, "TERM environment variable not set.\n", "");
        !           137:        }
        !           138: 
        !           139:        if (cur_term == 0)
        !           140:            term_ptr = &_first_term;
        !           141:        else
        !           142:        {
        !           143:            term_ptr = (struct term *) malloc(sizeof(struct term));
        !           144: 
        !           145:            if (term_ptr == NULL)
        !           146:                ret_error(-1, "Not enough memory to create terminal structure.\n", "");
        !           147:        }
        !           148: 
        !           149:        got_code = -1;
        !           150:        if ((terminfo = getenv("TERMINFO")) != NULL) {
        !           151:            sprintf(filename, "%s/%c/%s", terminfo, termname[0], termname);
        !           152:            got_code = read_entry(filename, term_ptr);
        !           153:        }
        !           154:        if (got_code < 0) {
        !           155:            sprintf(filename, "%s/%c/%s", SRCDIR, termname[0], termname);
        !           156:            if (read_entry(filename, term_ptr) < 0)
        !           157:                ret_error(0, "'%s': Unknown terminal type.\n", termname);
        !           158:        }
        !           159: 
        !           160:        if (command_character  &&  getenv("CC"))
        !           161:            do_prototype();
        !           162: 
        !           163:        cur_term = term_ptr;
        !           164:        strncpy(ttytype, cur_term->term_names, NAMESIZE - 1);
        !           165:        ttytype[NAMESIZE - 1] = '\0';
        !           166:        cur_term->Filedes = filedes;
        !           167: #ifdef USE_TERMIO
        !           168:        ioctl(filedes, TCGETA, &cur_term->Otermio);
        !           169:        if ((cur_term->Otermio.c_oflag & TABDLY) == TAB3)
        !           170:            tab = back_tab = NULL;
        !           171: 
        !           172:        cur_term->Ntermio = cur_term->Otermio;
        !           173:        cur_term->Ntermio.c_oflag &= ~TAB3;
        !           174: #else
        !           175:        gtty(filedes, &cur_term->Ottyb);
        !           176:        if (cur_term->Ottyb.sg_flags & XTABS)
        !           177:            tab = back_tab = NULL;
        !           178: 
        !           179:        cur_term->Nttyb = cur_term->Ottyb;
        !           180:        cur_term->Nttyb.sg_flags &= ~XTABS;
        !           181: #endif
        !           182: 
        !           183:        setup_acs();
        !           184:        fixterm();
        !           185: 
        !           186:        if (errret)
        !           187:            *errret = 1;
        !           188:        
        !           189:        return(1);
        !           190: }
        !           191: 
        !           192: 
        !           193: /*
        !           194: **     do_prototype()
        !           195: **
        !           196: **     Take the real command character out of the CC environment variable
        !           197: **     and substitute it in for the prototype given in 'command_character'.
        !           198: **
        !           199: */
        !           200: 
        !           201: static
        !           202: do_prototype()
        !           203: {
        !           204:        register int    i, j;
        !           205:        char            CC;
        !           206:        char            proto;
        !           207: 
        !           208:        CC = *getenv("CC");
        !           209:        proto = *command_character;
        !           210: 
        !           211:        for (i=0; i < STRCOUNT; i++)
        !           212:        {
        !           213:            j = 0;
        !           214:            while (cur_term->Strings[i][j])
        !           215:            {
        !           216:                if (cur_term->Strings[i][j] == proto)
        !           217:                    cur_term->Strings[i][j] = CC;
        !           218:                j++;
        !           219:            }
        !           220:        }
        !           221: }

unix.superglobalmegacorp.com

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