Annotation of sbbs/conio/curs_cio.c, revision 1.1

1.1     ! root        1: /* $Id: curs_cio.c,v 1.15 2004/09/22 21:55:32 rswindell Exp $ */
        !             2: 
        !             3: /****************************************************************************
        !             4:  * @format.tab-size 4          (Plain Text/Source Code File Header)                    *
        !             5:  * @format.use-tabs true       (see http://www.synchro.net/ptsc_hdr.html)              *
        !             6:  *                                                                                                                                                     *
        !             7:  * Copyright 2004 Rob Swindell - http://www.synchro.net/copyright.html         *
        !             8:  *                                                                                                                                                     *
        !             9:  * This library is free software; you can redistribute it and/or                       *
        !            10:  * modify it under the terms of the GNU Lesser General Public License          *
        !            11:  * as published by the Free Software Foundation; either version 2                      *
        !            12:  * of the License, or (at your option) any later version.                                      *
        !            13:  * See the GNU Lesser General Public License for more details: lgpl.txt or     *
        !            14:  * http://www.fsf.org/copyleft/lesser.html                                                                     *
        !            15:  *                                                                                                                                                     *
        !            16:  * Anonymous FTP access to the most recent released source is available at     *
        !            17:  * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net     *
        !            18:  *                                                                                                                                                     *
        !            19:  * Anonymous CVS access to the development source and modification history     *
        !            20:  * is available at cvs.synchro.net:/cvsroot/sbbs, example:                                     *
        !            21:  * cvs -d :pserver:[email protected]:/cvsroot/sbbs login                       *
        !            22:  *     (just hit return, no password is necessary)                                                     *
        !            23:  * cvs -d :pserver:[email protected]:/cvsroot/sbbs checkout src                *
        !            24:  *                                                                                                                                                     *
        !            25:  * For Synchronet coding style and modification guidelines, see                                *
        !            26:  * http://www.synchro.net/source.html                                                                          *
        !            27:  *                                                                                                                                                     *
        !            28:  * You are encouraged to submit any modifications (preferably in Unix diff     *
        !            29:  * format) via e-mail to [email protected]                                                                      *
        !            30:  *                                                                                                                                                     *
        !            31:  * Note: If this box doesn't appear square, then you need to fix your tabs.    *
        !            32:  ****************************************************************************/
        !            33: 
        !            34: #include <sys/time.h>
        !            35: #include <stdarg.h>
        !            36: #include <stdio.h>
        !            37: #include <stdlib.h>
        !            38: #include <unistd.h>
        !            39: 
        !            40: #include "gen_defs.h"  /* xpdev, for BOOL/TRUE/FALSE */
        !            41: 
        !            42: #include "ciolib.h"
        !            43: #include "curs_cio.h"
        !            44: #include "keys.h"
        !            45: #include "mouse.h"
        !            46: #include "vidmodes.h"
        !            47: 
        !            48: static unsigned char curs_nextgetch=0;
        !            49: const int curs_tabs[10]={9,17,25,33,41,49,57,65,73,80};
        !            50: 
        !            51: static int lastattr=0;
        !            52: static long mode;
        !            53: 
        !            54: short curses_color(short color)
        !            55: {
        !            56:        switch(color)
        !            57:        {
        !            58:                case 0 :
        !            59:                        return(COLOR_BLACK);
        !            60:                case 1 :
        !            61:                        return(COLOR_BLUE);
        !            62:                case 2 :
        !            63:                        return(COLOR_GREEN);
        !            64:                case 3 :
        !            65:                        return(COLOR_CYAN);
        !            66:                case 4 :
        !            67:                        return(COLOR_RED);
        !            68:                case 5 :
        !            69:                        return(COLOR_MAGENTA);
        !            70:                case 6 :
        !            71:                        return(COLOR_YELLOW);
        !            72:                case 7 :
        !            73:                        return(COLOR_WHITE);
        !            74:                case 8 :
        !            75:                        return(COLOR_BLACK);
        !            76:                case 9 :
        !            77:                        return(COLOR_BLUE);
        !            78:                case 10 :
        !            79:                        return(COLOR_GREEN);
        !            80:                case 11 :
        !            81:                        return(COLOR_CYAN);
        !            82:                case 12 :
        !            83:                        return(COLOR_RED);
        !            84:                case 13 :
        !            85:                        return(COLOR_MAGENTA);
        !            86:                case 14 :
        !            87:                        return(COLOR_YELLOW);
        !            88:                case 15 :
        !            89:                        return(COLOR_WHITE);
        !            90:        }
        !            91:        return(0);
        !            92: }
        !            93: 
        !            94: int curs_puttext(int sx, int sy, int ex, int ey, void *fillbuf)
        !            95: {
        !            96:        int x,y;
        !            97:        int fillpos=0;
        !            98:        unsigned char attr;
        !            99:        unsigned char fill_char;
        !           100:        unsigned char orig_attr;
        !           101:        int oldx, oldy;
        !           102:        struct text_info        ti;
        !           103:        unsigned char *fill;
        !           104: 
        !           105:        fill=fillbuf;
        !           106:        gettextinfo(&ti);
        !           107: 
        !           108:        if(                sx < 1
        !           109:                        || sy < 1
        !           110:                        || ex < 1
        !           111:                        || ey < 1
        !           112:                        || sx > ti.screenwidth
        !           113:                        || sy > ti.screenheight
        !           114:                        || sx > ex
        !           115:                        || sy > ey
        !           116:                        || ex > ti.screenwidth
        !           117:                        || ey > ti.screenheight
        !           118:                        || fill==NULL)
        !           119:                return(0);
        !           120: 
        !           121:        getyx(stdscr,oldy,oldx);
        !           122:        orig_attr=lastattr;
        !           123:        for(y=sy-1;y<=ey-1;y++)
        !           124:        {
        !           125:                for(x=sx-1;x<=ex-1;x++)
        !           126:                {
        !           127:                        fill_char=fill[fillpos++];
        !           128:                        attr=fill[fillpos++];
        !           129:                        textattr(attr);
        !           130:                        move(y, x);
        !           131:                        _putch(fill_char,FALSE);
        !           132:                }
        !           133:        }
        !           134:        textattr(orig_attr);
        !           135:        move(oldy, oldx);
        !           136:        refresh();
        !           137:        return(1);
        !           138: }
        !           139: 
        !           140: int curs_gettext(int sx, int sy, int ex, int ey, void *fillbuf)
        !           141: {
        !           142:        int x,y;
        !           143:        int fillpos=0;
        !           144:        chtype attr;
        !           145:        unsigned char attrib;
        !           146:        unsigned char colour;
        !           147:        int oldx, oldy;
        !           148:        unsigned char thischar;
        !           149:        int     ext_char;
        !           150:        struct text_info        ti;
        !           151:        unsigned char *fill;
        !           152: 
        !           153:        fill=fillbuf;
        !           154:        gettextinfo(&ti);
        !           155: 
        !           156:        if(                sx < 1
        !           157:                        || sy < 1
        !           158:                        || ex < 1
        !           159:                        || ey < 1
        !           160:                        || sx > ti.screenwidth
        !           161:                        || sy > ti.screenheight
        !           162:                        || sx > ex
        !           163:                        || sy > ey
        !           164:                        || ex > ti.screenwidth
        !           165:                        || ey > ti.screenheight
        !           166:                        || fill==NULL)
        !           167:                return(0);
        !           168: 
        !           169:        getyx(stdscr,oldy,oldx);
        !           170:        for(y=sy-1;y<=ey-1;y++)
        !           171:        {
        !           172:                for(x=sx-1;x<=ex-1;x++)
        !           173:                {
        !           174:                        attr=mvinch(y, x);
        !           175:                        if(attr&A_REVERSE) {
        !           176:                                thischar=attr&255-'A'+1;
        !           177:                        }
        !           178:                        else if(attr&A_ALTCHARSET) {
        !           179:                                if(!(mode==CIOLIB_MODE_CURSES_IBM)){
        !           180:                                        ext_char=A_ALTCHARSET|(attr&255);
        !           181:                                        /* likely ones */
        !           182:                                        if (ext_char == ACS_CKBOARD)
        !           183:                                        {
        !           184:                                                thischar=176;
        !           185:                                        }
        !           186:                                        else if (ext_char == ACS_BOARD)
        !           187:                                        {
        !           188:                                                thischar=177;
        !           189:                                        }
        !           190:                                        else if (ext_char == ACS_BSSB)
        !           191:                                        {
        !           192:                                                thischar=218;
        !           193:                                        }
        !           194:                                        else if (ext_char == ACS_SSBB)
        !           195:                                        {
        !           196:                                                thischar=192;
        !           197:                                        }
        !           198:                                        else if (ext_char == ACS_BBSS)
        !           199:                                        {
        !           200:                                                thischar=191;
        !           201:                                        }
        !           202:                                        else if (ext_char == ACS_SBBS)
        !           203:                                        {
        !           204:                                                thischar=217;
        !           205:                                        }
        !           206:                                        else if (ext_char == ACS_SBSS)
        !           207:                                        {
        !           208:                                                thischar=180;
        !           209:                                        }
        !           210:                                        else if (ext_char == ACS_SSSB)
        !           211:                                        {
        !           212:                                                thischar=195;
        !           213:                                        }
        !           214:                                        else if (ext_char == ACS_SSBS)
        !           215:                                        {
        !           216:                                                thischar=193;
        !           217:                                        }
        !           218:                                        else if (ext_char == ACS_BSSS)
        !           219:                                        {
        !           220:                                                thischar=194;
        !           221:                                        }
        !           222:                                        else if (ext_char == ACS_BSBS)
        !           223:                                        {
        !           224:                                                thischar=196;
        !           225:                                        }
        !           226:                                        else if (ext_char == ACS_SBSB)
        !           227:                                        {
        !           228:                                                thischar=179;
        !           229:                                        }
        !           230:                                        else if (ext_char == ACS_SSSS)
        !           231:                                        {
        !           232:                                                thischar=197;
        !           233:                                        }
        !           234:                                        else if (ext_char == ACS_BLOCK)
        !           235:                                        {
        !           236:                                                thischar=219;
        !           237:                                        }
        !           238:                                        else if (ext_char == ACS_UARROW)
        !           239:                                        {
        !           240:                                                thischar=30;
        !           241:                                        }
        !           242:                                        else if (ext_char == ACS_DARROW)
        !           243:                                        {
        !           244:                                                thischar=31;
        !           245:                                        }
        !           246: 
        !           247:                                        /* unlikely (Not in ncurses) */
        !           248:                                        else if (ext_char == ACS_SBSD)
        !           249:                                        {
        !           250:                                                thischar=181;
        !           251:                                        }
        !           252:                                        else if (ext_char == ACS_DBDS)
        !           253:                                        {
        !           254:                                                thischar=182;
        !           255:                                        }
        !           256:                                        else if (ext_char == ACS_BBDS)
        !           257:                                        {
        !           258:                                                thischar=183;
        !           259:                                        }
        !           260:                                        else if (ext_char == ACS_BBSD)
        !           261:                                        {
        !           262:                                                thischar=184;
        !           263:                                        }
        !           264:                                        else if (ext_char == ACS_DBDD)
        !           265:                                        {
        !           266:                                                thischar=185;
        !           267:                                        }
        !           268:                                        else if (ext_char == ACS_DBDB)
        !           269:                                        {
        !           270:                                                thischar=186;
        !           271:                                        }
        !           272:                                        else if (ext_char == ACS_BBDD)
        !           273:                                        {
        !           274:                                                thischar=187;
        !           275:                                        }
        !           276:                                        else if (ext_char == ACS_DBBD)
        !           277:                                        {
        !           278:                                                thischar=188;
        !           279:                                        }
        !           280:                                        else if (ext_char == ACS_DBBS)
        !           281:                                        {
        !           282:                                                thischar=189;
        !           283:                                        }
        !           284:                                        else if (ext_char == ACS_SBBD)
        !           285:                                        {
        !           286:                                                thischar=190;
        !           287:                                        }
        !           288:                                        else if (ext_char == ACS_SDSB)
        !           289:                                        {
        !           290:                                                thischar=198;
        !           291:                                        }
        !           292:                                        else if (ext_char == ACS_DSDB)
        !           293:                                        {
        !           294:                                                thischar=199;
        !           295:                                        }
        !           296:                                        else if (ext_char == ACS_DDBB)
        !           297:                                        {
        !           298:                                                thischar=200;
        !           299:                                        }
        !           300:                                        else if (ext_char == ACS_BDDB)
        !           301:                                        {
        !           302:                                                thischar=201;
        !           303:                                        }
        !           304:                                        else if (ext_char == ACS_DDBD)
        !           305:                                        {
        !           306:                                                thischar=202;
        !           307:                                        }
        !           308:                                        else if (ext_char == ACS_BDDD)
        !           309:                                        {
        !           310:                                                thischar=203;
        !           311:                                        }
        !           312:                                        else if (ext_char == ACS_DDDB)
        !           313:                                        {
        !           314:                                                thischar=204;
        !           315:                                        }
        !           316:                                        else if (ext_char == ACS_BDBD)
        !           317:                                        {
        !           318:                                                thischar=205;
        !           319:                                        }
        !           320:                                        else if (ext_char == ACS_DDDD)
        !           321:                                        {
        !           322:                                                thischar=206;
        !           323:                                        }
        !           324:                                        else if (ext_char == ACS_SDBD)
        !           325:                                        {
        !           326:                                                thischar=207;
        !           327:                                        }
        !           328:                                        else if (ext_char == ACS_DSBS)
        !           329:                                        {
        !           330:                                                thischar=208;
        !           331:                                        }
        !           332:                                        else if (ext_char == ACS_BDSD)
        !           333:                                        {
        !           334:                                                thischar=209;
        !           335:                                        }
        !           336:                                        else if (ext_char == ACS_BSDS)
        !           337:                                        {
        !           338:                                                thischar=210;
        !           339:                                        }
        !           340:                                        else if (ext_char == ACS_DSBB)
        !           341:                                        {
        !           342:                                                thischar=211;
        !           343:                                        }
        !           344:                                        else if (ext_char == ACS_SDBB)
        !           345:                                        {
        !           346:                                                thischar=212;
        !           347:                                        }
        !           348:                                        else if (ext_char == ACS_BDSB)
        !           349:                                        {
        !           350:                                                thischar=213;
        !           351:                                        }
        !           352:                                        else if (ext_char == ACS_BSDB)
        !           353:                                        {
        !           354:                                                thischar=214;
        !           355:                                        }
        !           356:                                        else if (ext_char == ACS_DSDS)
        !           357:                                        {
        !           358:                                                thischar=215;
        !           359:                                        }
        !           360:                                        else if (ext_char == ACS_SDSD)
        !           361:                                        {
        !           362:                                                thischar=216;
        !           363:                                        }
        !           364:                                        else
        !           365:                                        {
        !           366:                                                thischar=attr&255;
        !           367:                                        }
        !           368:                                }
        !           369:                                else {
        !           370:                                        if (ext_char == ACS_UARROW)
        !           371:                                        {
        !           372:                                                thischar=30;
        !           373:                                        }
        !           374:                                        else if (ext_char == ACS_DARROW)
        !           375:                                        {
        !           376:                                                thischar=31;
        !           377:                                        }
        !           378:                                        else
        !           379:                                        {
        !           380:                                                thischar=attr&255;
        !           381:                                        }
        !           382:                                }
        !           383:                        }
        !           384:                        else
        !           385:                                thischar=attr;
        !           386:                        fill[fillpos++]=(unsigned char)(thischar);
        !           387:                        attrib=0;
        !           388:                        if (attr & A_BOLD)
        !           389:                        {
        !           390:                                attrib |= 8;
        !           391:                        }
        !           392:                        if (attr & A_BLINK)
        !           393:                        {
        !           394:                                attrib |= 128;
        !           395:                        }
        !           396:                        colour=PAIR_NUMBER(attr&A_COLOR)-1;
        !           397:                        colour=((colour&56)<<1)|(colour&7);
        !           398:                        fill[fillpos++]=colour|attrib;
        !           399:                }
        !           400:        }
        !           401:        move(oldy, oldx);
        !           402:        return(1);
        !           403: }
        !           404: 
        !           405: void curs_textattr(int attr)
        !           406: {
        !           407:        chtype   attrs=A_NORMAL;
        !           408:        int     colour;
        !           409: 
        !           410:        if (lastattr==attr)
        !           411:                return;
        !           412: 
        !           413:        lastattr=attr;
        !           414:        
        !           415:        if (attr & 8)  {
        !           416:                attrs |= A_BOLD;
        !           417:        }
        !           418:        if (attr & 128)
        !           419:        {
        !           420:                attrs |= A_BLINK;
        !           421:        }
        !           422:        colour = COLOR_PAIR( ((attr&7)|((attr>>1)&56))+1 );
        !           423:        #ifdef NCURSES_VERSION_MAJOR
        !           424:        attrset(attrs);
        !           425:        color_set(colour,NULL);
        !           426:        #else
        !           427:        attrset(attrs|colour);
        !           428:        #endif
        !           429:        /* bkgdset(colour); */
        !           430:        bkgdset(colour);
        !           431: }
        !           432: 
        !           433: int curs_kbhit(void)
        !           434: {
        !           435:        struct timeval timeout;
        !           436:        fd_set  rfds;
        !           437: 
        !           438:        if(curs_nextgetch)
        !           439:                return(1);
        !           440:        if(mouse_pending())
        !           441:                return(1);
        !           442:        timeout.tv_sec=0;
        !           443:        timeout.tv_usec=0;
        !           444:        FD_ZERO(&rfds);
        !           445:        FD_SET(fileno(stdin),&rfds);
        !           446: 
        !           447:        return(select(fileno(stdin)+1,&rfds,NULL,NULL,&timeout));
        !           448: }
        !           449: 
        !           450: void curs_delay(long msec)
        !           451: {
        !           452:        usleep(msec*1000);
        !           453: }
        !           454: 
        !           455: int curs_wherey(void)
        !           456: {
        !           457:        int x,y;
        !           458:        getyx(stdscr,y,x);
        !           459:        return(y+1);
        !           460: }
        !           461: 
        !           462: int curs_wherex(void)
        !           463: {
        !           464:        int x,y;
        !           465:        getyx(stdscr,y,x);
        !           466:        return(x+1);
        !           467: }
        !           468: 
        !           469: int _putch(unsigned char ch, BOOL refresh_now)
        !           470: {
        !           471:        int             ret;
        !           472:        chtype  cha;
        !           473: 
        !           474:        if(!(mode==CIOLIB_MODE_CURSES_IBM))
        !           475:        {
        !           476:                switch(ch)
        !           477:                {
        !           478:                        case 30:
        !           479:                                cha=ACS_UARROW;
        !           480:                                break;
        !           481:                        case 31:
        !           482:                                cha=ACS_DARROW;
        !           483:                                break;
        !           484:                        case 176:
        !           485:                                cha=ACS_CKBOARD;
        !           486:                                break;
        !           487:                        case 177:
        !           488:                                cha=ACS_BOARD;
        !           489:                                break;
        !           490:                        case 178:
        !           491:                                cha=ACS_BOARD;
        !           492:                                break;
        !           493:                        case 179:
        !           494:                                cha=ACS_SBSB;
        !           495:                                break;
        !           496:                        case 180:
        !           497:                                cha=ACS_SBSS;
        !           498:                                break;
        !           499:                        case 181:
        !           500:                                cha=ACS_SBSD;
        !           501:                                break;
        !           502:                        case 182:
        !           503:                                cha=ACS_DBDS;
        !           504:                                break;
        !           505:                        case 183:
        !           506:                                cha=ACS_BBDS;
        !           507:                                break;
        !           508:                        case 184:
        !           509:                                cha=ACS_BBSD;
        !           510:                                break;
        !           511:                        case 185:
        !           512:                                cha=ACS_DBDD;
        !           513:                                break;
        !           514:                        case 186:
        !           515:                                cha=ACS_DBDB;
        !           516:                                break;
        !           517:                        case 187:
        !           518:                                cha=ACS_BBDD;
        !           519:                                break;
        !           520:                        case 188:
        !           521:                                cha=ACS_DBBD;
        !           522:                                break;
        !           523:                        case 189:
        !           524:                                cha=ACS_DBBS;
        !           525:                                break;
        !           526:                        case 190:
        !           527:                                cha=ACS_SBBD;
        !           528:                                break;
        !           529:                        case 191:
        !           530:                                cha=ACS_BBSS;
        !           531:                                break;
        !           532:                        case 192:
        !           533:                                cha=ACS_SSBB;
        !           534:                                break;
        !           535:                        case 193:
        !           536:                                cha=ACS_SSBS;
        !           537:                                break;
        !           538:                        case 194:
        !           539:                                cha=ACS_BSSS;
        !           540:                                break;
        !           541:                        case 195:
        !           542:                                cha=ACS_SSSB;
        !           543:                                break;
        !           544:                        case 196:
        !           545:                                cha=ACS_BSBS;
        !           546:                                break;
        !           547:                        case 197:
        !           548:                                cha=ACS_SSSS;
        !           549:                                break;
        !           550:                        case 198:
        !           551:                                cha=ACS_SDSB;
        !           552:                                break;
        !           553:                        case 199:
        !           554:                                cha=ACS_DSDB;
        !           555:                                break;
        !           556:                        case 200:
        !           557:                                cha=ACS_DDBB;
        !           558:                                break;
        !           559:                        case 201:
        !           560:                                cha=ACS_BDDB;
        !           561:                                break;
        !           562:                        case 202:
        !           563:                                cha=ACS_DDBD;
        !           564:                                break;
        !           565:                        case 203:
        !           566:                                cha=ACS_BDDD;
        !           567:                                break;
        !           568:                        case 204:
        !           569:                                cha=ACS_DDDB;
        !           570:                                break;
        !           571:                        case 205:
        !           572:                                cha=ACS_BDBD;
        !           573:                                break;
        !           574:                        case 206:
        !           575:                                cha=ACS_DDDD;
        !           576:                                break;
        !           577:                        case 207:
        !           578:                                cha=ACS_SDBD;
        !           579:                                break;
        !           580:                        case 208:
        !           581:                                cha=ACS_DSBS;
        !           582:                                break;
        !           583:                        case 209:
        !           584:                                cha=ACS_BDSD;
        !           585:                                break;
        !           586:                        case 210:
        !           587:                                cha=ACS_BSDS;
        !           588:                                break;
        !           589:                        case 211:
        !           590:                                cha=ACS_DSBB;
        !           591:                                break;
        !           592:                        case 212:
        !           593:                                cha=ACS_SDBB;
        !           594:                                break;
        !           595:                        case 213:
        !           596:                                cha=ACS_BDSB;
        !           597:                                break;
        !           598:                        case 214:
        !           599:                                cha=ACS_BSDB;
        !           600:                                break;
        !           601:                        case 215:
        !           602:                                cha=ACS_DSDS;
        !           603:                                break;
        !           604:                        case 216:
        !           605:                                cha=ACS_SDSD;
        !           606:                                break;
        !           607:                        case 217:
        !           608:                                cha=ACS_SBBS;
        !           609:                                break;
        !           610:                        case 218:
        !           611:                                cha=ACS_BSSB;
        !           612:                                break;
        !           613:                        case 219:
        !           614:                                cha=ACS_BLOCK;
        !           615:                                break;
        !           616:                        default:
        !           617:                                cha=ch;
        !           618:                }
        !           619:        }
        !           620:        else
        !           621:                cha=ch;
        !           622: 
        !           623:        if(!cha)
        !           624:                cha=' ';
        !           625:        if(cha == ' ')
        !           626:                ret=addch(A_BOLD|' ');
        !           627:        else if (cha<' ') {
        !           628:                attron(A_REVERSE);
        !           629:                ret=addch(cha+'A'-1);
        !           630:                attroff(A_REVERSE);
        !           631:        }
        !           632:        else
        !           633:                ret=addch(cha);
        !           634: 
        !           635:        if(refresh_now)
        !           636:                refresh();
        !           637: 
        !           638:        return(ret);
        !           639: }
        !           640: 
        !           641: void curs_gotoxy(int x, int y)
        !           642: {
        !           643:        move(y-1,x-1);
        !           644:        refresh();
        !           645: }
        !           646: 
        !           647: void call_endwin(void)
        !           648: {
        !           649:        endwin();
        !           650: }
        !           651: 
        !           652: int curs_initciolib(long inmode)
        !           653: {
        !           654:        short   fg, bg, pair=0;
        !           655: 
        !           656: #ifdef XCURSES
        !           657:        char    *argv[2]={"ciolib",NULL};
        !           658: 
        !           659:        Xinitscr(1,argv);
        !           660: #else
        !           661:        char *term;
        !           662:        SCREEN *tst;
        !           663: 
        !           664:        term=getenv("TERM");
        !           665:        if(term==NULL)
        !           666:                return(0);
        !           667:        tst=newterm(term,stdout,stdin);
        !           668:        if(tst==NULL)
        !           669:                return(0);
        !           670:        endwin();
        !           671:        initscr();
        !           672: #endif
        !           673:        start_color();
        !           674:        cbreak();
        !           675:        noecho();
        !           676:        nonl();
        !           677:        keypad(stdscr, TRUE);
        !           678:        scrollok(stdscr,FALSE);
        !           679:        raw();
        !           680:        halfdelay(1);
        !           681:        atexit(call_endwin);
        !           682: 
        !           683:        /* Set up color pairs */
        !           684:        for(bg=0;bg<8;bg++)  {
        !           685:                for(fg=0;fg<8;fg++) {
        !           686:                        init_pair(++pair,curses_color(fg),curses_color(bg));
        !           687:                }
        !           688:        }
        !           689:        mode = inmode;
        !           690:        #ifdef NCURSES_VERSION_MAJOR
        !           691:                if(mousemask(BUTTON1_PRESSED|BUTTON1_RELEASED|BUTTON2_PRESSED|BUTTON2_RELEASED|BUTTON3_PRESSED|BUTTON3_RELEASED|REPORT_MOUSE_POSITION,NULL)==BUTTON1_PRESSED|BUTTON1_RELEASED|BUTTON2_PRESSED|BUTTON2_RELEASED|BUTTON3_PRESSED|BUTTON3_RELEASED|REPORT_MOUSE_POSITION) {
        !           692:                        mouseinterval(0);
        !           693:                        cio_api.mouse=1;
        !           694:                }
        !           695:                else
        !           696:                        mousemask(0,NULL);
        !           697:        #endif
        !           698:        return(1);
        !           699: }
        !           700: 
        !           701: void curs_gettextinfo(struct text_info *info)
        !           702: {
        !           703:        getmaxyx(stdscr, info->screenheight, info->screenwidth);
        !           704:        if(has_colors())
        !           705:                info->currmode=COLOR_MODE;
        !           706:        else
        !           707:                info->currmode=MONO;
        !           708:        info->curx=wherex();
        !           709:        info->cury=wherey();
        !           710:        info->attribute=lastattr;
        !           711: }
        !           712: 
        !           713: void curs_setcursortype(int type) {
        !           714:        switch(type) {
        !           715:                case _NOCURSOR:
        !           716:                        curs_set(0);
        !           717:                        break;
        !           718:                
        !           719:                case _SOLIDCURSOR:
        !           720:                        curs_set(2);
        !           721:                        break;
        !           722:                
        !           723:                default:        /* Normal cursor */
        !           724:                        curs_set(1);
        !           725:                        break;
        !           726: 
        !           727:        }
        !           728:        refresh();
        !           729: }
        !           730: 
        !           731: int curs_putch(int c)
        !           732: {
        !           733:        struct text_info ti;
        !           734:        int             ret;
        !           735:        int             i;
        !           736: 
        !           737:        ret=c;
        !           738:        switch(c) {
        !           739:                case '\r':
        !           740:                        gotoxy(1,wherey());
        !           741:                        break;
        !           742:                case '\n':
        !           743:                        gettextinfo(&ti);
        !           744:                        if(wherey()==ti.winbottom-ti.wintop+1) {
        !           745:                                wscroll();
        !           746:                        }
        !           747:                        else {
        !           748:                                gotoxy(wherex(),wherey()+1);
        !           749:                        }
        !           750:                        break;
        !           751:                case 0x07:
        !           752:                        beep();
        !           753:                        break;
        !           754:                case 0x08:
        !           755:                        gotoxy(wherex()-1,wherey());
        !           756:                        _putch(' ',FALSE);
        !           757:                        gotoxy(wherex()-1,wherey());
        !           758:                        break;
        !           759:                case '\t':
        !           760:                        for(i=0;i<10;i++) {
        !           761:                                if(curs_tabs[i]>wherex()) {
        !           762:                                        while(wherex()<curs_tabs[i]) {
        !           763:                                                putch(' ');
        !           764:                                        }
        !           765:                                        break;
        !           766:                                }
        !           767:                        }
        !           768:                        if(i==10) {
        !           769:                                putch('\r');
        !           770:                                putch('\n');
        !           771:                        }
        !           772:                        break;
        !           773:                default:
        !           774:                        gettextinfo(&ti);
        !           775:                        if(wherey()==ti.winbottom-ti.wintop+1
        !           776:                                        && wherex()==ti.winright-ti.winleft+1) {
        !           777:                                if(_putch(c,TRUE)==ERR)
        !           778:                                        ret=EOF;
        !           779:                                else {
        !           780:                                        wscroll();
        !           781:                                        gotoxy(ti.winleft,ti.cury);
        !           782:                                }
        !           783:                        }
        !           784:                        else {
        !           785:                                if(wherex()==ti.winright-ti.winleft+1) {
        !           786:                                        if(_putch(c,TRUE)==ERR)
        !           787:                                                ret=EOF;
        !           788:                                        else
        !           789:                                                gotoxy(ti.winleft,ti.cury+1);
        !           790:                                }
        !           791:                                else {
        !           792:                                        if(_putch(c,TRUE)==ERR)
        !           793:                                                ret=EOF;
        !           794:                                        else
        !           795:                                                gotoxy(ti.curx+1,ti.cury);
        !           796:                                }
        !           797:                        }
        !           798:                        break;
        !           799:        }
        !           800: }
        !           801: 
        !           802: int curs_getch(void)
        !           803: {
        !           804:        int ch;
        !           805:        MEVENT mevnt;
        !           806: 
        !           807:        if(curs_nextgetch) {
        !           808:                ch=curs_nextgetch;
        !           809:                curs_nextgetch=0;
        !           810:        }
        !           811:        else {
        !           812:                while((ch=getch())==ERR && !mouse_pending());
        !           813:                if(mouse_pending()) {
        !           814:                        curs_nextgetch=CIO_KEY_MOUSE>>8;
        !           815:                        ch=CIO_KEY_MOUSE & 0xff;
        !           816:                }
        !           817:                else {
        !           818:                        if(ch > 255) {
        !           819:                                switch(ch) {
        !           820:                                        case KEY_DOWN:            /* Down-arrow */
        !           821:                                                curs_nextgetch=0x50;
        !           822:                                                ch=0;
        !           823:                                                break;
        !           824: 
        !           825:                                        case KEY_UP:            /* Up-arrow */
        !           826:                                                curs_nextgetch=0x48;
        !           827:                                                ch=0;
        !           828:                                                break;
        !           829: 
        !           830:                                        case KEY_LEFT:          /* Left-arrow */
        !           831:                                                curs_nextgetch=0x4b;
        !           832:                                                ch=0;
        !           833:                                                break;
        !           834: 
        !           835:                                        case KEY_RIGHT:            /* Right-arrow */
        !           836:                                                curs_nextgetch=0x4d;
        !           837:                                                ch=0;
        !           838:                                                break;
        !           839: 
        !           840:                                        case KEY_HOME:            /* Home key (upward+left arrow) */
        !           841:                                                curs_nextgetch=0x47;
        !           842:                                                ch=0;
        !           843:                                                break;
        !           844: 
        !           845:                                        case KEY_BACKSPACE:            /* Backspace (unreliable) */
        !           846:                                                ch=8;
        !           847:                                                break;
        !           848: 
        !           849:                                        case KEY_F(1):                  /* Function Key */
        !           850:                                                curs_nextgetch=0x3b;
        !           851:                                                ch=0;
        !           852:                                                break;
        !           853: 
        !           854:                                        case KEY_F(2):                  /* Function Key */
        !           855:                                                curs_nextgetch=0x3c;
        !           856:                                                ch=0;
        !           857:                                                break;
        !           858: 
        !           859:                                        case KEY_F(3):                  /* Function Key */
        !           860:                                                curs_nextgetch=0x3d;
        !           861:                                                ch=0;
        !           862:                                                break;
        !           863: 
        !           864:                                        case KEY_F(4):                  /* Function Key */
        !           865:                                                curs_nextgetch=0x3e;
        !           866:                                                ch=0;
        !           867:                                                break;
        !           868: 
        !           869:                                        case KEY_F(5):                  /* Function Key */
        !           870:                                                curs_nextgetch=0x3f;
        !           871:                                                ch=0;
        !           872:                                                break;
        !           873: 
        !           874:                                        case KEY_F(6):                  /* Function Key */
        !           875:                                                curs_nextgetch=0x40;
        !           876:                                                ch=0;
        !           877:                                                break;
        !           878: 
        !           879:                                        case KEY_F(7):                  /* Function Key */
        !           880:                                                curs_nextgetch=0x41;
        !           881:                                                ch=0;
        !           882:                                                break;
        !           883: 
        !           884:                                        case KEY_F(8):                  /* Function Key */
        !           885:                                                curs_nextgetch=0x42;
        !           886:                                                ch=0;
        !           887:                                                break;
        !           888: 
        !           889:                                        case KEY_F(9):                  /* Function Key */
        !           890:                                                curs_nextgetch=0x43;
        !           891:                                                ch=0;
        !           892:                                                break;
        !           893: 
        !           894:                                        case KEY_F(10):                 /* Function Key */
        !           895:                                                curs_nextgetch=0x44;
        !           896:                                                ch=0;
        !           897:                                                break;
        !           898: 
        !           899:                                        case KEY_F(11):                 /* Function Key */
        !           900:                                                curs_nextgetch=0x57;
        !           901:                                                ch=0;
        !           902:                                                break;
        !           903: 
        !           904:                                        case KEY_F(12):                 /* Function Key */
        !           905:                                                curs_nextgetch=0x58;
        !           906:                                                ch=0;
        !           907:                                                break;
        !           908: 
        !           909:                                        case KEY_DC:            /* Delete character */
        !           910:                                                curs_nextgetch=0x53;
        !           911:                                                ch=0;
        !           912:                                                break;
        !           913: 
        !           914:                                        case KEY_IC:            /* Insert char or enter insert mode */
        !           915:                                                curs_nextgetch=0x52;
        !           916:                                                ch=0;
        !           917:                                                break;
        !           918: 
        !           919:                                        case KEY_EIC:            /* Exit insert char mode */
        !           920:                                                curs_nextgetch=0x52;
        !           921:                                                ch=0;
        !           922:                                                break;
        !           923: 
        !           924:                                        case KEY_NPAGE:            /* Next page */
        !           925:                                                curs_nextgetch=0x51;
        !           926:                                                ch=0;
        !           927:                                                break;
        !           928: 
        !           929:                                        case KEY_PPAGE:            /* Previous page */
        !           930:                                                curs_nextgetch=0x49;
        !           931:                                                ch=0;
        !           932:                                                break;
        !           933: 
        !           934:                                        case KEY_ENTER:            /* Enter or send (unreliable) */
        !           935:                                                curs_nextgetch=0x0d;
        !           936:                                                ch=0;
        !           937:                                                break;
        !           938: 
        !           939:                                        case KEY_A1:            /* Upper left of keypad */
        !           940:                                                curs_nextgetch=0x47;
        !           941:                                                ch=0;
        !           942:                                                break;
        !           943: 
        !           944:                                        case KEY_A3:            /* Upper right of keypad */
        !           945:                                                curs_nextgetch=0x49;
        !           946:                                                ch=0;
        !           947:                                                break;
        !           948: 
        !           949:                                        case KEY_B2:            /* Center of keypad */
        !           950:                                                curs_nextgetch=0x4c;
        !           951:                                                ch=0;
        !           952:                                                break;
        !           953: 
        !           954:                                        case KEY_C1:            /* Lower left of keypad */
        !           955:                                                curs_nextgetch=0x4f;
        !           956:                                                ch=0;
        !           957:                                                break;
        !           958: 
        !           959:                                        case KEY_C3:            /* Lower right of keypad */
        !           960:                                                curs_nextgetch=0x51;
        !           961:                                                ch=0;
        !           962:                                                break;
        !           963: 
        !           964:                                        case KEY_BEG:           /* Beg (beginning) */
        !           965:                                                curs_nextgetch=0x47;
        !           966:                                                ch=0;
        !           967:                                                break;
        !           968: 
        !           969:                                        case KEY_CANCEL:                /* Cancel */
        !           970:                                                curs_nextgetch=0x03;
        !           971:                                                ch=0;
        !           972:                                                break;
        !           973: 
        !           974:                                        case KEY_END:           /* End */
        !           975:                                                curs_nextgetch=0x4f;
        !           976:                                                ch=0;
        !           977:                                                break;
        !           978: 
        !           979:                                        case KEY_SELECT:                /* Select  - Is "End" in X */
        !           980:                                                curs_nextgetch=0x4f;
        !           981:                                                ch=0;
        !           982:                                                break;
        !           983: 
        !           984:                                        case KEY_MOUSE:                 /* Mouse stuff */
        !           985:                                                if(getmouse(&mevnt)==OK) {
        !           986:                                                        int evnt=0;
        !           987:                                                        switch(mevnt.bstate) {
        !           988:                                                                case BUTTON1_PRESSED:
        !           989:                                                                        evnt=CIOLIB_BUTTON_1_PRESS;
        !           990:                                                                        break;
        !           991:                                                                case BUTTON1_RELEASED:
        !           992:                                                                        evnt=CIOLIB_BUTTON_1_RELEASE;
        !           993:                                                                        break;
        !           994:                                                                case BUTTON2_PRESSED:
        !           995:                                                                        evnt=CIOLIB_BUTTON_2_PRESS;
        !           996:                                                                        break;
        !           997:                                                                case BUTTON2_RELEASED:
        !           998:                                                                        evnt=CIOLIB_BUTTON_2_RELEASE;
        !           999:                                                                        break;
        !          1000:                                                                case BUTTON3_PRESSED:
        !          1001:                                                                        evnt=CIOLIB_BUTTON_3_PRESS;
        !          1002:                                                                        break;
        !          1003:                                                                case BUTTON3_RELEASED:
        !          1004:                                                                        evnt=CIOLIB_BUTTON_3_RELEASE;
        !          1005:                                                                        break;
        !          1006:                                                                case REPORT_MOUSE_POSITION:
        !          1007:                                                                        evnt=CIOLIB_MOUSE_MOVE;
        !          1008:                                                                        break;
        !          1009:                                                        }
        !          1010:                                                        ciomouse_gotevent(evnt, mevnt.x+1, mevnt.y+1);
        !          1011:                                                }
        !          1012:                                                break;
        !          1013: 
        !          1014:                                        default:
        !          1015:                                                curs_nextgetch=0xff;
        !          1016:                                                ch=0;
        !          1017:                                                break;
        !          1018:                                }
        !          1019:                        }
        !          1020:                }
        !          1021:        }
        !          1022:        return(ch);
        !          1023: }
        !          1024: 
        !          1025: int curs_getche(void)
        !          1026: {
        !          1027:        int ch;
        !          1028: 
        !          1029:        if(curs_nextgetch)
        !          1030:                return(curs_getch());
        !          1031:        ch=curs_getch();
        !          1032:        if(ch)
        !          1033:                putch(ch);
        !          1034:        return(ch);
        !          1035: }
        !          1036: 
        !          1037: void curs_textmode(int mode)
        !          1038: {
        !          1039:        return;
        !          1040: }
        !          1041: 
        !          1042: int curs_hidemouse(void)
        !          1043: {
        !          1044: /*
        !          1045:        #ifdef NCURSES_VERSION_MAJOR
        !          1046:                mousemask(0,NULL);
        !          1047:                return(0);
        !          1048:        #else
        !          1049:                return(-1);
        !          1050:        #endif
        !          1051: */
        !          1052: }
        !          1053: 
        !          1054: int curs_showmouse(void)
        !          1055: {
        !          1056: /*
        !          1057:        #ifdef NCURSES_VERSION_MAJOR
        !          1058:                if(mousemask(BUTTON1_PRESSED|BUTTON1_RELEASED|BUTTON2_PRESSED|BUTTON2_RELEASED|BUTTON3_PRESSED|BUTTON3_RELEASED|REPORT_MOUSE_POSITION,NULL)==BUTTON1_PRESSED|BUTTON1_RELEASED|BUTTON2_PRESSED|BUTTON2_RELEASED|BUTTON3_PRESSED|BUTTON3_RELEASED|REPORT_MOUSE_POSITION)
        !          1059:                        return(0);
        !          1060:        #endif
        !          1061:        return(-1);
        !          1062: */
        !          1063: }

unix.superglobalmegacorp.com

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