Annotation of coherent/g/usr/lib/ncurses/lib_options.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: **     lib_options.c
        !            27: **
        !            28: **     The routines to handle option setting.
        !            29: **
        !            30: ** $Log:       RCS/lib_options.v $
        !            31:  * Revision 2.4  92/11/08  15:41:44  munk
        !            32:  * Correct definition of malloc() and
        !            33:  * usage of the cast operator
        !            34:  *
        !            35:  * Revision 2.3  91/12/03  21:51:11  munk
        !            36:  * Added KEY_LL in function init_keytry()
        !            37:  *
        !            38:  * Revision 2.2  91/04/20  21:29:33  munk
        !            39:  * Usage of register variables
        !            40:  *
        !            41:  * Revision 2.1  82/10/25  14:48:24  pavel
        !            42:  * Added Copyright Notice
        !            43:  * 
        !            44:  * Revision 2.0  82/10/25  13:47:45  pavel
        !            45:  * Beta-one Test Release
        !            46:  * 
        !            47: **
        !            48: */
        !            49: 
        !            50: #ifdef RCSHDR
        !            51: static char RCSid[] =
        !            52:        "$Header:   RCS/lib_options.v  Revision 2.2  91/04/20  21:29:33  munk   Exp$";
        !            53: #endif
        !            54: 
        !            55: #include "term.h"
        !            56: #include "curses.h"
        !            57: #include "curses.priv.h"
        !            58: 
        !            59: char   *malloc();
        !            60: 
        !            61: 
        !            62: static
        !            63: outc(ch)
        !            64: char   ch;
        !            65: {
        !            66:        putc(ch, SP->_ofp);
        !            67: }
        !            68: 
        !            69: 
        !            70: idlok(win, flag)
        !            71: WINDOW *win;
        !            72: int    flag;
        !            73: {
        !            74: #ifdef TRACE
        !            75:        if (_tracing)
        !            76:            _tracef("idlok(%o,%d) called", win, flag);
        !            77: #endif
        !            78: 
        !            79:        if ((insert_line  &&  delete_line)
        !            80: #ifdef UNIMPLEMENTED
        !            81:             ||  (change_scroll_region)
        !            82: #endif
        !            83:           )
        !            84:            curscr->_idlok = flag;
        !            85: }
        !            86: 
        !            87: 
        !            88: clearok(win, flag)
        !            89: WINDOW *win;
        !            90: int    flag;
        !            91: {
        !            92: #ifdef TRACE
        !            93:        if (_tracing)
        !            94:            _tracef("clearok(%o,%d) called", win, flag);
        !            95: #endif
        !            96: 
        !            97:        if (win == curscr)
        !            98:            newscr->_clear = flag;
        !            99:        else
        !           100:            win->_clear = flag;
        !           101: }
        !           102: 
        !           103: 
        !           104: leaveok(win, flag)
        !           105: WINDOW *win;
        !           106: int    flag;
        !           107: {
        !           108: #ifdef TRACE
        !           109:        if (_tracing)
        !           110:            _tracef("leaveok(%o,%d) called", win, flag);
        !           111: #endif
        !           112: 
        !           113:        win->_leave = flag;
        !           114: }
        !           115: 
        !           116: 
        !           117: scrollok(win, flag)
        !           118: WINDOW *win;
        !           119: int    flag;
        !           120: {
        !           121: #ifdef TRACE
        !           122:        if (_tracing)
        !           123:            _tracef("scrollok(%o,%d) called", win, flag);
        !           124: #endif
        !           125: 
        !           126:        win->_scroll = flag;
        !           127: }
        !           128: 
        !           129: 
        !           130: nodelay(win, flag)
        !           131: WINDOW *win;
        !           132: int    flag;
        !           133: {
        !           134: #ifdef TRACE
        !           135:        if (_tracing)
        !           136:            _tracef("nodelay(%o,%d) called", win, flag);
        !           137: #endif
        !           138: 
        !           139:        win->_nodelay = flag;
        !           140: }
        !           141: 
        !           142: 
        !           143: keypad(win, flag)
        !           144: WINDOW *win;
        !           145: int    flag;
        !           146: {
        !           147: #ifdef TRACE
        !           148:        if (_tracing)
        !           149:            _tracef("keypad(%o,%d) called", win, flag);
        !           150: #endif
        !           151: 
        !           152:        win->_use_keypad = flag;
        !           153: 
        !           154:        if (flag  &&  keypad_xmit)
        !           155:            tputs(keypad_xmit, 1, outc);
        !           156:        else if (! flag  &&  keypad_local)
        !           157:            tputs(keypad_local, 1, outc);
        !           158:            
        !           159:         if (SP->_keytry == UNINITIALISED)
        !           160:            init_keytry();
        !           161: }
        !           162: 
        !           163: 
        !           164: meta(win, flag)
        !           165: WINDOW *win;
        !           166: int    flag;
        !           167: {
        !           168: #ifdef TRACE
        !           169:        if (_tracing)
        !           170:            _tracef("meta(%o,%d) called", win, flag);
        !           171: #endif
        !           172: 
        !           173:        win->_use_meta = flag;
        !           174: 
        !           175:        if (flag  &&  meta_on)
        !           176:            tputs(meta_on, 1, outc);
        !           177:        else if (! flag  &&  meta_off)
        !           178:            tputs(meta_off, 1, outc);
        !           179: }
        !           180: 
        !           181: 
        !           182: /*
        !           183: **      init_keytry()
        !           184: **
        !           185: **      Construct the try for the current terminal's keypad keys.
        !           186: **
        !           187: */
        !           188: 
        !           189: static struct  try *newtry;
        !           190: 
        !           191: static
        !           192: init_keytry()
        !           193: {
        !           194:         newtry = NULL;
        !           195:        
        !           196:         add_to_try(key_backspace, KEY_BACKSPACE);
        !           197:         add_to_try(key_catab, KEY_CATAB);
        !           198:         add_to_try(key_clear, KEY_CLEAR);
        !           199:         add_to_try(key_ctab, KEY_CTAB);
        !           200:         add_to_try(key_dc, KEY_DC);
        !           201:         add_to_try(key_dl, KEY_DL);
        !           202:         add_to_try(key_down, KEY_DOWN);
        !           203:         add_to_try(key_eic, KEY_EIC);
        !           204:         add_to_try(key_eol, KEY_EOL);
        !           205:         add_to_try(key_eos, KEY_EOS);
        !           206:         add_to_try(key_f0, KEY_F(0));
        !           207:         add_to_try(key_f1, KEY_F(1));
        !           208:         add_to_try(key_f2, KEY_F(2));
        !           209:         add_to_try(key_f3, KEY_F(3));
        !           210:         add_to_try(key_f4, KEY_F(4));
        !           211:         add_to_try(key_f5, KEY_F(5));
        !           212:         add_to_try(key_f6, KEY_F(6));
        !           213:         add_to_try(key_f7, KEY_F(7));
        !           214:         add_to_try(key_f8, KEY_F(8));
        !           215:         add_to_try(key_f9, KEY_F(9));
        !           216:         add_to_try(key_f10, KEY_F(10));
        !           217:         add_to_try(key_home, KEY_HOME);
        !           218:        add_to_try(key_ll, KEY_LL);
        !           219:         add_to_try(key_ic, KEY_IC);
        !           220:         add_to_try(key_il, KEY_IL);
        !           221:         add_to_try(key_left, KEY_LEFT);
        !           222:         add_to_try(key_npage, KEY_NPAGE);
        !           223:         add_to_try(key_ppage, KEY_PPAGE);
        !           224:         add_to_try(key_right, KEY_RIGHT);
        !           225:         add_to_try(key_sf, KEY_SF);
        !           226:         add_to_try(key_sr, KEY_SR);
        !           227:         add_to_try(key_stab, KEY_STAB);
        !           228:         add_to_try(key_up, KEY_UP);
        !           229:        
        !           230:        SP->_keytry = newtry;
        !           231: }
        !           232: 
        !           233: 
        !           234: add_to_try(str, code)
        !           235: register char  *str;
        !           236: short          code;
        !           237: {
        !           238:        void                    free();
        !           239:         static bool            out_of_memory = FALSE;
        !           240:         register struct try    *ptr, *savedptr;
        !           241: 
        !           242:        if (! str  ||  out_of_memory)
        !           243:            return;
        !           244:        
        !           245:        if (newtry != NULL)    
        !           246:        {
        !           247:            ptr = newtry;
        !           248:            
        !           249:                    for (;;)
        !           250:            {
        !           251:                while (ptr->ch != *str  &&  ptr->sibling != NULL)
        !           252:                    ptr = ptr->sibling;
        !           253:            
        !           254:                if (ptr->ch == *str)
        !           255:                {
        !           256:                    if (*(++str))
        !           257:                    {
        !           258:                        if (ptr->child != NULL)
        !           259:                            ptr = ptr->child;
        !           260:                         else
        !           261:                            break;
        !           262:                    }
        !           263:                    else
        !           264:                    {
        !           265:                        ptr->value = code;
        !           266:                        return;
        !           267:                    }
        !           268:                }
        !           269:                else
        !           270:                {
        !           271:                    if ((ptr->sibling = (struct try *) malloc(sizeof *ptr)) == NULL)
        !           272:                    {
        !           273:                        out_of_memory = TRUE;
        !           274:                        return;
        !           275:                    }
        !           276:                    
        !           277:                    savedptr = ptr = ptr->sibling;
        !           278:                    ptr->child = ptr->sibling = NULL;
        !           279:                    ptr->ch = *str++;
        !           280:                    ptr->value = 0;
        !           281:                    
        !           282:                     break;
        !           283:                }
        !           284:            } /* end for (;;) */  
        !           285:        }
        !           286:        else    /* newtry == NULL :: First sequence to be added */
        !           287:        {
        !           288:            savedptr = ptr = newtry = (struct try *) malloc(sizeof *ptr);
        !           289:            
        !           290:            if (ptr == NULL)
        !           291:            {
        !           292:                out_of_memory = TRUE;
        !           293:                return;
        !           294:            }
        !           295:            
        !           296:            ptr->child = ptr->sibling = NULL;
        !           297:            ptr->ch = *(str++);
        !           298:            ptr->value = 0;
        !           299:        }
        !           300:        
        !           301:            /* at this point, we are adding to the try.  ptr->child == NULL */
        !           302:            
        !           303:        while (*str)
        !           304:        {
        !           305:            ptr->child = (struct try *) malloc(sizeof *ptr);
        !           306:            
        !           307:            ptr = ptr->child;
        !           308:            
        !           309:            if (ptr == NULL)
        !           310:            {
        !           311:                out_of_memory = TRUE;
        !           312:                
        !           313:                ptr = savedptr;
        !           314:                while (ptr != NULL) 
        !           315:                {
        !           316:                    savedptr = ptr->child;
        !           317:                    free(ptr);
        !           318:                    ptr = savedptr;
        !           319:                }
        !           320:                
        !           321:                return;
        !           322:            }
        !           323:            
        !           324:            ptr->child = ptr->sibling = NULL;
        !           325:            ptr->ch = *(str++);
        !           326:            ptr->value = 0;
        !           327:        }
        !           328:        
        !           329:        ptr->value = code;
        !           330:        return;
        !           331: }

unix.superglobalmegacorp.com

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