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

1.1     ! root        1: /* $Id: ciolib.c,v 1.30 2004/10/15 05:13:35 deuce 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 <stdarg.h>
        !            35: #include <stdlib.h>    /* malloc */
        !            36: #include <stdio.h>
        !            37: 
        !            38: #include <threadwrap.h>
        !            39: 
        !            40: #define CIOLIB_NO_MACROS
        !            41: #include "ciolib.h"
        !            42: 
        !            43: #ifdef _WIN32
        !            44:  #include "win32cio.h"
        !            45: #else
        !            46:  #ifndef NO_X
        !            47:   #include "x_cio.h"
        !            48:  #endif
        !            49:  #include "curs_cio.h"
        !            50:  #undef getch
        !            51: #endif
        !            52: 
        !            53: #include "ansi_cio.h"
        !            54: 
        !            55: cioapi_t       cio_api;
        !            56: 
        !            57: static int ungotch;
        !            58: static struct text_info cio_textinfo;
        !            59: static int lastmode=3;
        !            60: int _wscroll=1;
        !            61: int directvideo=0;
        !            62: int dont_move_cursor=0;
        !            63: static int initialized=0;
        !            64: 
        !            65: int ciolib_movetext(int sx, int sy, int ex, int ey, int dx, int dy);
        !            66: char *ciolib_cgets(char *str);
        !            67: int ciolib_cscanf (char *format , ...);
        !            68: int ciolib_kbhit(void);
        !            69: int ciolib_getch(void);
        !            70: int ciolib_getche(void);
        !            71: int ciolib_ungetch(int ch);
        !            72: void ciolib_gettextinfo(struct text_info *info);
        !            73: int ciolib_wherex(void);
        !            74: int ciolib_wherey(void);
        !            75: void ciolib_wscroll(void);
        !            76: void ciolib_gotoxy(int x, int y);
        !            77: void ciolib_clreol(void);
        !            78: void ciolib_clrscr(void);
        !            79: int ciolib_cputs(char *str);
        !            80: int    ciolib_cprintf(char *fmat, ...);
        !            81: void ciolib_textbackground(int colour);
        !            82: void ciolib_textcolor(int colour);
        !            83: void ciolib_highvideo(void);
        !            84: void ciolib_lowvideo(void);
        !            85: void ciolib_normvideo(void);
        !            86: int ciolib_puttext(int a,int b,int c,int d,unsigned char *e);
        !            87: int ciolib_gettext(int a,int b,int c,int d,unsigned char *e);
        !            88: void ciolib_textattr(int a);
        !            89: void ciolib_delay(long a);
        !            90: int ciolib_putch(int a);
        !            91: void ciolib_setcursortype(int a);
        !            92: void ciolib_textmode(int mode);
        !            93: void ciolib_window(int sx, int sy, int ex, int ey);
        !            94: void ciolib_delline(void);
        !            95: void ciolib_insline(void);
        !            96: char *ciolib_getpass(const char *prompt);
        !            97: 
        !            98: #define CIOLIB_INIT()          { if(!initialized) initciolib(CIOLIB_MODE_AUTO); }
        !            99: 
        !           100: #ifndef _WIN32
        !           101:  #ifndef NO_X
        !           102: int try_x_init(int mode)
        !           103: {
        !           104:        if(!console_init()) {
        !           105:                cio_api.mode=CIOLIB_MODE_X;
        !           106:                cio_api.mouse=1;
        !           107:                cio_api.puttext=x_puttext;
        !           108:                cio_api.gettext=x_gettext;
        !           109:                cio_api.textattr=x_textattr;
        !           110:                cio_api.kbhit=x_kbhit;
        !           111:                cio_api.delay=x_delay;
        !           112:                cio_api.wherey=x_wherey;
        !           113:                cio_api.wherex=x_wherex;
        !           114:                cio_api.putch=x_putch;
        !           115:                cio_api.gotoxy=x_gotoxy;
        !           116:                cio_api.gettextinfo=x_gettextinfo;
        !           117:                cio_api.setcursortype=x_setcursortype;
        !           118:                cio_api.getch=x_getch;
        !           119:                cio_api.getche=x_getche;
        !           120:                cio_api.textmode=x_textmode;
        !           121:                cio_api.showmouse=NULL;
        !           122:                cio_api.hidemouse=NULL;
        !           123:                cio_api.settitle=x_settitle;
        !           124:                return(1);
        !           125:        }
        !           126:        return(0);
        !           127: }
        !           128:  #endif
        !           129: 
        !           130: int try_curses_init(int mode)
        !           131: {
        !           132:        if(curs_initciolib(mode)) {
        !           133:                cio_api.mode=CIOLIB_MODE_CURSES_IBM;
        !           134:                cio_api.puttext=curs_puttext;
        !           135:                cio_api.gettext=curs_gettext;
        !           136:                cio_api.textattr=curs_textattr;
        !           137:                cio_api.kbhit=curs_kbhit;
        !           138:                cio_api.delay=curs_delay;
        !           139:                cio_api.wherey=curs_wherey;
        !           140:                cio_api.wherex=curs_wherex;
        !           141:                cio_api.putch=curs_putch;
        !           142:                cio_api.gotoxy=curs_gotoxy;
        !           143:                cio_api.gettextinfo=curs_gettextinfo;
        !           144:                cio_api.setcursortype=curs_setcursortype;
        !           145:                cio_api.getch=curs_getch;
        !           146:                cio_api.getche=curs_getche;
        !           147:                cio_api.textmode=curs_textmode;
        !           148:                cio_api.showmouse=curs_showmouse;
        !           149:                cio_api.hidemouse=curs_hidemouse;
        !           150:                cio_api.settitle=NULL;
        !           151:                return(1);
        !           152:        }
        !           153:        return(0);
        !           154: }
        !           155: #endif
        !           156: 
        !           157: int try_ansi_init(int mode)
        !           158: {
        !           159:        if(ansi_initciolib(mode)) {
        !           160:                cio_api.mode=CIOLIB_MODE_ANSI;
        !           161:                cio_api.mouse=0;
        !           162:                cio_api.puttext=ansi_puttext;
        !           163:                cio_api.gettext=ansi_gettext;
        !           164:                cio_api.textattr=ansi_textattr;
        !           165:                cio_api.kbhit=ansi_kbhit;
        !           166:                cio_api.delay=ansi_delay;
        !           167:                cio_api.wherey=ansi_wherey;
        !           168:                cio_api.wherex=ansi_wherex;
        !           169:                cio_api.putch=ansi_putch;
        !           170:                cio_api.gotoxy=ansi_gotoxy;
        !           171:                cio_api.gettextinfo=ansi_gettextinfo;
        !           172:                cio_api.setcursortype=ansi_setcursortype;
        !           173:                cio_api.getch=ansi_getch;
        !           174:                cio_api.getche=ansi_getche;
        !           175:                cio_api.textmode=ansi_textmode;
        !           176:                cio_api.showmouse=NULL;
        !           177:                cio_api.hidemouse=NULL;
        !           178:                cio_api.settitle=NULL;
        !           179:                return(1);
        !           180:        }
        !           181:        return(0);
        !           182: }
        !           183: 
        !           184: #ifdef _WIN32
        !           185: #if defined(__BORLANDC__)
        !           186:         #pragma argsused
        !           187: #endif
        !           188: int try_conio_init(int mode)
        !           189: {
        !           190:        /* This should test for something or other */
        !           191:        if(win32_initciolib(C80)) {
        !           192:                cio_api.mode=CIOLIB_MODE_CONIO;
        !           193:                cio_api.mouse=1;
        !           194:                cio_api.puttext=win32_puttext;
        !           195:                cio_api.gettext=win32_gettext;
        !           196:                cio_api.textattr=win32_textattr;
        !           197:                cio_api.kbhit=win32_kbhit;
        !           198:                cio_api.wherey=win32_wherey;
        !           199:                cio_api.wherex=win32_wherex;
        !           200:                cio_api.putch=win32_putch;
        !           201:                cio_api.gotoxy=win32_gotoxy;
        !           202:                cio_api.gettextinfo=win32_gettextinfo;
        !           203:                cio_api.setcursortype=win32_setcursortype;
        !           204:                cio_api.getch=win32_getch;
        !           205:                cio_api.getche=win32_getche;
        !           206:                cio_api.textmode=win32_textmode;
        !           207:                cio_api.showmouse=win32_showmouse;
        !           208:                cio_api.hidemouse=win32_hidemouse;
        !           209:                cio_api.settitle=win32_settitle;
        !           210:                return(1);
        !           211:        }
        !           212:        return(0);
        !           213: }
        !           214: #endif
        !           215: 
        !           216: int initciolib(int mode)
        !           217: {
        !           218:        switch(mode) {
        !           219:                case CIOLIB_MODE_AUTO:
        !           220: #ifdef _WIN32
        !           221:                        if(!try_conio_init(mode))
        !           222: #else
        !           223: #ifndef NO_X
        !           224:                        if(!try_x_init(mode))
        !           225: #endif
        !           226:                                if(!try_curses_init(mode))
        !           227: #endif
        !           228:                                        try_ansi_init(mode);
        !           229:                        break;
        !           230: #ifdef _WIN32
        !           231:                case CIOLIB_MODE_CONIO:
        !           232:                        try_conio_init(mode);
        !           233:                        break;
        !           234: #else
        !           235:                case CIOLIB_MODE_CURSES:
        !           236:                case CIOLIB_MODE_CURSES_IBM:
        !           237:                        try_curses_init(mode);
        !           238:                        break;
        !           239: 
        !           240:                case CIOLIB_MODE_X:
        !           241: #ifndef NO_X
        !           242:                        try_x_init(mode);
        !           243: #endif
        !           244:                        break;
        !           245: #endif
        !           246:                case CIOLIB_MODE_ANSI:
        !           247:                        try_ansi_init(mode);
        !           248:                        break;
        !           249:        }
        !           250:        if(cio_api.mode==CIOLIB_MODE_AUTO) {
        !           251:                fprintf(stderr,"CIOLIB initialization failed!\n");
        !           252:                return(-1);
        !           253:        }
        !           254: 
        !           255:        initialized=1;
        !           256:        ciolib_gettextinfo(&cio_textinfo);
        !           257:        cio_textinfo.winleft=1;
        !           258:        cio_textinfo.wintop=1;
        !           259:        cio_textinfo.winright=cio_textinfo.screenwidth;
        !           260:        cio_textinfo.winbottom=cio_textinfo.screenheight;
        !           261:        cio_textinfo.normattr=7;
        !           262:        _beginthread(ciolib_mouse_thread,0,NULL);
        !           263:        return(0);
        !           264: }
        !           265: 
        !           266: int ciolib_kbhit(void)
        !           267: {
        !           268:        CIOLIB_INIT();
        !           269:        if(ungotch)
        !           270:                return(1);
        !           271:        if(mouse_pending())
        !           272:                return(1);
        !           273:        return(cio_api.kbhit());
        !           274: }
        !           275: 
        !           276: int ciolib_getch(void)
        !           277: {
        !           278:        int ch;
        !           279: 
        !           280:        CIOLIB_INIT();
        !           281: 
        !           282:        if(ungotch) {
        !           283:                ch=ungotch;
        !           284:                ungotch=0;
        !           285:                return(ch);
        !           286:        }
        !           287:        return(cio_api.getch());
        !           288: }
        !           289: 
        !           290: int ciolib_getche(void)
        !           291: {
        !           292:        int ch;
        !           293: 
        !           294:        CIOLIB_INIT();
        !           295: 
        !           296:        if(ungotch) {
        !           297:                ch=ungotch;
        !           298:                ungotch=0;
        !           299:                ciolib_putch(ch);
        !           300:                return(ch);
        !           301:        }
        !           302:        return(cio_api.getche());
        !           303: }
        !           304: 
        !           305: int ciolib_ungetch(int ch)
        !           306: {
        !           307:        CIOLIB_INIT();
        !           308:        
        !           309:        if(ungotch)
        !           310:                return(EOF);
        !           311:        ungotch=ch;
        !           312:        return(ch);
        !           313: }
        !           314: 
        !           315: int ciolib_movetext(int sx, int sy, int ex, int ey, int dx, int dy)
        !           316: {
        !           317:        int width;
        !           318:        int height;
        !           319:        unsigned char *buf;
        !           320: 
        !           321:        CIOLIB_INIT();
        !           322:        
        !           323:        width=ex-sx;
        !           324:        height=ey-sy;
        !           325:        buf=(unsigned char *)malloc((width+1)*(height+1)*2);
        !           326:        if(buf==NULL)
        !           327:                return(0);
        !           328:        if(!ciolib_gettext(sx,sy,ex,ey,buf)) {
        !           329:                free(buf);
        !           330:                return(0);
        !           331:        }
        !           332:        if(!ciolib_puttext(dx,dy,dx+width,dy+height,buf)) {
        !           333:                free(buf);
        !           334:                return(0);
        !           335:        }
        !           336:        free(buf);
        !           337:        return(1);
        !           338: }
        !           339: 
        !           340: char *ciolib_cgets(char *str)
        !           341: {
        !           342:        int     maxlen;
        !           343:        int len=0;
        !           344:        int ch;
        !           345: 
        !           346:        CIOLIB_INIT();
        !           347:        
        !           348:        maxlen=*(unsigned char *)str;
        !           349:        while((ch=ciolib_getche())!='\n') {
        !           350:                switch(ch) {
        !           351:                        case 0: /* Skip extended keys */
        !           352:                                ciolib_getche();
        !           353:                                break;
        !           354:                        case '\r':      /* Skip \r (ToDo: Should this be treeated as a \n? */
        !           355:                                break;
        !           356:                        case '\b':
        !           357:                                if(len==0) {
        !           358:                                        ciolib_putch(7);
        !           359:                                        break;
        !           360:                                }
        !           361:                                ciolib_putch('\b');
        !           362:                                len--;
        !           363:                                break;
        !           364:                        default:
        !           365:                                str[(len++)+2]=ch;
        !           366:                                if(len==maxlen) {
        !           367:                                        str[len+2]=0;
        !           368:                                        *((unsigned char *)(str+1))=(unsigned char)len;
        !           369:                                        return(&str[2]);
        !           370:                                }
        !           371:                                break;
        !           372:                }
        !           373:        }
        !           374:        str[len+2]=0;
        !           375:        *((unsigned char *)(str+1))=(unsigned char)len;
        !           376:        return(&str[2]);
        !           377: }
        !           378: 
        !           379: #ifdef _MSC_VER        /* Use lame vsscanf() implementation */
        !           380: /* This is a way to do _vsscanf without using fancy stack tricks or using the
        !           381:  * "_input" method provided by Microsoft, which is no longer exported as of .NET.
        !           382:  * The function has a limit of 25 arguments (or less if you run out of stack space),
        !           383:  *  but how many arguments do you need?
        !           384:  */
        !           385: /* From "krabsheva" - http://www.codeguru.com/Cpp/Cpp/string/comments.php/c5631/?thread=1051 */
        !           386: int vsscanf( const char *buffer, const char *format, va_list arg_ptr )
        !           387: {
        !           388:        int i, ret;
        !           389:        void *arg_arr[25];
        !           390: 
        !           391:        // Do exception handling in case we go too far //
        !           392:        __try
        !           393:        {
        !           394:                for ( i = 0; i < 25; i++ )
        !           395:                        arg_arr[i] = va_arg( arg_ptr, void * );
        !           396:        }
        !           397:        __except( EXCEPTION_EXECUTE_HANDLER )
        !           398:        {
        !           399:        }
        !           400: 
        !           401:        /* This is lame, but the extra arguments won't be used by sscanf */
        !           402:        ret = sscanf( buffer, format, arg_arr[0], arg_arr[1], arg_arr[2], arg_arr[3],
        !           403:                arg_arr[4], arg_arr[5], arg_arr[6], arg_arr[7], arg_arr[8], arg_arr[9],
        !           404:                arg_arr[10], arg_arr[11], arg_arr[12], arg_arr[13], arg_arr[14],
        !           405:                arg_arr[15], arg_arr[16], arg_arr[17], arg_arr[18], arg_arr[19],
        !           406:                arg_arr[20], arg_arr[21], arg_arr[22], arg_arr[23], arg_arr[24] );
        !           407: 
        !           408:        return ret;
        !           409: }
        !           410: #endif
        !           411: 
        !           412: int ciolib_cscanf (char *format , ...)
        !           413: {
        !           414:        char str[255];
        !           415:     va_list argptr;
        !           416:        int ret;
        !           417: 
        !           418:        CIOLIB_INIT();
        !           419:        
        !           420:        str[0]=-1;
        !           421:        va_start(argptr,format);
        !           422:        ret=vsscanf(ciolib_cgets(str),format,argptr);
        !           423:        va_end(argptr);
        !           424:        return(ret);
        !           425: }
        !           426: 
        !           427: char *ciolib_getpass(const char *prompt)
        !           428: {
        !           429:        static char pass[9];
        !           430:        int len=0;
        !           431:        int ch;
        !           432: 
        !           433:        CIOLIB_INIT();
        !           434:        
        !           435:        ciolib_cputs((char *)prompt);
        !           436:        while((ch=ciolib_getch())!='\n') {
        !           437:                switch(ch) {
        !           438:                        case 0: /* Skip extended keys */
        !           439:                                ciolib_getch();
        !           440:                                break;
        !           441:                        case '\r':      /* Skip \r (ToDo: Should this be treeated as a \n? */
        !           442:                                break;
        !           443:                        case '\b':
        !           444:                                if(len==0) {
        !           445:                                        ciolib_putch(7);
        !           446:                                        break;
        !           447:                                }
        !           448:                                len--;
        !           449:                                break;
        !           450:                        default:
        !           451:                                if(len==8)
        !           452:                                        ciolib_putch(7);
        !           453:                                else
        !           454:                                        pass[len++]=ch;
        !           455:                                break;
        !           456:                }
        !           457:        }
        !           458:        pass[len]=0;
        !           459:        return(pass);
        !           460: }
        !           461: 
        !           462: void ciolib_gettextinfo(struct text_info *info)
        !           463: {
        !           464:        if(!initialized)
        !           465:                initciolib(CIOLIB_MODE_AUTO);
        !           466:        else {
        !           467:                cio_api.gettextinfo(&cio_textinfo);
        !           468:        }
        !           469:        if(info!=&cio_textinfo) {
        !           470:                info->winleft=cio_textinfo.winleft;        /* left window coordinate */
        !           471:                info->wintop=cio_textinfo.wintop;         /* top window coordinate */
        !           472:                info->winright=cio_textinfo.winright;       /* right window coordinate */
        !           473:                info->winbottom=cio_textinfo.winbottom;      /* bottom window coordinate */
        !           474:                info->attribute=cio_textinfo.attribute;      /* text attribute */
        !           475:                info->normattr=cio_textinfo.normattr;       /* normal attribute */
        !           476:                info->currmode=cio_textinfo.currmode;       /* current video mode:
        !           477:                                                         BW40, BW80, C40, C80, or C4350 */
        !           478:                info->screenheight=cio_textinfo.screenheight;   /* text screen's height */
        !           479:                info->screenwidth=cio_textinfo.screenwidth;    /* text screen's width */
        !           480:                info->curx=cio_textinfo.curx;           /* x-coordinate in current window */
        !           481:                info->cury=cio_textinfo.cury;           /* y-coordinate in current window */
        !           482:        }
        !           483: }
        !           484: 
        !           485: void ciolib_wscroll(void)
        !           486: {
        !           487:        int os;
        !           488:        struct text_info ti;
        !           489: 
        !           490:        CIOLIB_INIT();
        !           491:        
        !           492:        ciolib_gettextinfo(&ti);
        !           493:        if(!_wscroll)
        !           494:                return;
        !           495:        ciolib_movetext(ti.winleft,ti.wintop+1,ti.winright,ti.winbottom,ti.winleft,ti.wintop);
        !           496:        ciolib_gotoxy(1,ti.winbottom-ti.winleft+1);
        !           497:        os=_wscroll;
        !           498:        _wscroll=0;
        !           499:        /* ciolib_cprintf("%*s",ti.winright-ti.winleft+1,""); */
        !           500:        ciolib_clreol();
        !           501:        _wscroll=os;
        !           502:        ciolib_gotoxy(ti.curx,ti.cury);
        !           503: }
        !           504: 
        !           505: int ciolib_wherex(void)
        !           506: {
        !           507:        int x;
        !           508: 
        !           509:        CIOLIB_INIT();
        !           510:        
        !           511:        x=cio_api.wherex();
        !           512:        x=x-cio_textinfo.winleft+1;
        !           513:        return(x);
        !           514: }
        !           515: 
        !           516: int ciolib_wherey(void)
        !           517: {
        !           518:        int y;
        !           519: 
        !           520:        CIOLIB_INIT();
        !           521:        
        !           522:        y=cio_api.wherey();
        !           523:        y=y-cio_textinfo.wintop+1;
        !           524:        return(y);
        !           525: }
        !           526: 
        !           527: void ciolib_gotoxy(int x, int y)
        !           528: {
        !           529:        int nx;
        !           530:        int ny;
        !           531:        struct text_info ti;
        !           532: 
        !           533:        CIOLIB_INIT();
        !           534:        
        !           535:        ciolib_gettextinfo(&ti);
        !           536:        if(             x < 1
        !           537:                        || x > ti.winright-ti.winleft+1
        !           538:                        || y < 1
        !           539:                        || y > ti.winbottom-ti.wintop+1)
        !           540:                return;
        !           541:        nx=x+ti.winleft-1;
        !           542:        ny=y+ti.wintop-1;
        !           543:        cio_api.gotoxy(nx,ny);
        !           544: }
        !           545: 
        !           546: void ciolib_textmode(mode)
        !           547: {
        !           548:        CIOLIB_INIT();
        !           549:        
        !           550:        if(mode==-1) {
        !           551:                ciolib_gettextinfo(&cio_textinfo);
        !           552:                cio_api.textmode(lastmode);
        !           553:                lastmode=cio_textinfo.currmode;
        !           554:        }
        !           555:        else {
        !           556:                ciolib_gettextinfo(&cio_textinfo);
        !           557:                lastmode=cio_textinfo.currmode;
        !           558:                cio_api.textmode(mode);
        !           559:        }
        !           560:        ciolib_gettextinfo(&cio_textinfo);
        !           561:        cio_textinfo.winleft=1;
        !           562:        cio_textinfo.wintop=1;
        !           563:        cio_textinfo.winright=cio_textinfo.screenwidth;
        !           564:        cio_textinfo.winbottom=cio_textinfo.screenheight;
        !           565: }
        !           566: 
        !           567: void ciolib_window(int sx, int sy, int ex, int ey)
        !           568: {
        !           569:        CIOLIB_INIT();
        !           570:        
        !           571:        ciolib_gettextinfo(&cio_textinfo);
        !           572:        if(                sx < 1
        !           573:                        || sy < 1
        !           574:                        || ex < 1
        !           575:                        || ey < 1
        !           576:                        || sx > cio_textinfo.screenwidth
        !           577:                        || sy > cio_textinfo.screenheight
        !           578:                        || sx > ex
        !           579:                        || sy > ey
        !           580:                        || ex > cio_textinfo.screenwidth
        !           581:                        || ey > cio_textinfo.screenheight)
        !           582:                return;
        !           583:        cio_textinfo.winleft=sx;
        !           584:        cio_textinfo.wintop=sy;
        !           585:        cio_textinfo.winright=ex;
        !           586:        cio_textinfo.winbottom=ey;
        !           587:        ciolib_gotoxy(1,1);
        !           588: }
        !           589: 
        !           590: void ciolib_clreol(void)
        !           591: {
        !           592:        unsigned char *buf;
        !           593:        int i;
        !           594:        int width,height;
        !           595:        struct text_info ti;
        !           596: 
        !           597:        CIOLIB_INIT();
        !           598:        
        !           599:        ciolib_gettextinfo(&ti);
        !           600: 
        !           601:        width=ti.winright-ti.curx+1;
        !           602:        height=1;
        !           603:        buf=(unsigned char *)malloc(width*height*2);
        !           604:        for(i=0;i<width*height*2;) {
        !           605:                buf[i++]=' ';
        !           606:                buf[i++]=ti.attribute;
        !           607:        }
        !           608:        ciolib_puttext(ti.curx+ti.winleft-1,ti.cury+ti.wintop-1,ti.winright,ti.cury+ti.wintop-1,buf);
        !           609:        free(buf);
        !           610: }
        !           611: 
        !           612: void ciolib_clrscr(void)
        !           613: {
        !           614:        unsigned char *buf;
        !           615:        int i;
        !           616:        int width,height;
        !           617:        struct text_info ti;
        !           618: 
        !           619:        CIOLIB_INIT();
        !           620:        
        !           621:        ciolib_gettextinfo(&ti);
        !           622: 
        !           623:        width=ti.winright-ti.winleft+1;
        !           624:        height=ti.winbottom-ti.wintop+1;
        !           625:        buf=(unsigned char *)malloc(width*height*2);
        !           626:        for(i=0;i<width*height*2;) {
        !           627:                buf[i++]=' ';
        !           628:                buf[i++]=ti.attribute;
        !           629:        }
        !           630:        ciolib_puttext(ti.winleft,ti.wintop,ti.winright,ti.winbottom,buf);
        !           631:        free(buf);
        !           632: }
        !           633: 
        !           634: void ciolib_delline(void)
        !           635: {
        !           636:        struct text_info ti;
        !           637: 
        !           638:        CIOLIB_INIT();
        !           639:        
        !           640:        ciolib_gettextinfo(&ti);
        !           641: 
        !           642:        ciolib_movetext(ti.winleft,ti.cury+1,ti.winright,ti.winbottom,ti.winleft,ti.cury);
        !           643:        ciolib_gotoxy(1,ti.winbottom-ti.wintop+1);
        !           644:        ciolib_clreol();
        !           645:        ciolib_gotoxy(ti.curx,ti.cury);
        !           646: }
        !           647: 
        !           648: void ciolib_insline(void)
        !           649: {
        !           650:        struct text_info ti;
        !           651: 
        !           652:        CIOLIB_INIT();
        !           653:        
        !           654:        ciolib_gettextinfo(&ti);
        !           655: 
        !           656:        ciolib_movetext(ti.winleft,ti.cury,ti.winright,ti.winbottom,ti.winleft,ti.cury+1);
        !           657:        ciolib_gotoxy(1,ti.cury);
        !           658:        ciolib_clreol();
        !           659:        ciolib_gotoxy(ti.curx,ti.cury);
        !           660: }
        !           661: 
        !           662: int ciolib_cprintf(char *fmat, ...)
        !           663: {
        !           664:     va_list argptr;
        !           665:        int             ret;
        !           666: #ifdef _MSC_VER                /* Can't figure out a way to allocate a "big enough" buffer for Win32. */
        !           667:        char    str[16384];
        !           668: #else
        !           669:        char    *str;
        !           670: #endif
        !           671: 
        !           672:        CIOLIB_INIT();
        !           673: 
        !           674:     va_start(argptr,fmat);
        !           675: #ifdef _MSC_VER
        !           676:        ret=_vsnprintf(str,sizeof(str)-1,fmat,argptr);
        !           677: #else
        !           678:     ret=vsnprintf(NULL,0,fmat,argptr);
        !           679:        str=(char *)malloc(ret+1);
        !           680:        if(str==NULL)
        !           681:                return(EOF);
        !           682:        ret=vsprintf(str,fmat,argptr);
        !           683: #endif
        !           684:     va_end(argptr);
        !           685:        if(ret>=0)
        !           686:                ciolib_cputs(str);
        !           687:        else
        !           688:                ret=EOF;
        !           689: #ifndef _WIN32
        !           690:        free(str);
        !           691: #endif
        !           692:     return(ret);
        !           693: }
        !           694: 
        !           695: int ciolib_cputs(char *str)
        !           696: {
        !           697:        int             pos;
        !           698:        int             ret=0;
        !           699:        int             olddmc;
        !           700: 
        !           701:        CIOLIB_INIT();
        !           702: 
        !           703:        olddmc=dont_move_cursor;
        !           704:        dont_move_cursor=1;
        !           705:        for(pos=0;str[pos];pos++)
        !           706:        {
        !           707:                ret=str[pos];
        !           708:                if(str[pos]=='\n')
        !           709:                        ciolib_putch('\r');
        !           710:                ciolib_putch(str[pos]);
        !           711:        }
        !           712:        dont_move_cursor=olddmc;
        !           713:        ciolib_gotoxy(ciolib_wherex(),ciolib_wherey());
        !           714:        return(ret);
        !           715: }
        !           716: 
        !           717: void ciolib_textbackground(int colour)
        !           718: {
        !           719:        unsigned char attr;
        !           720: 
        !           721:        CIOLIB_INIT();
        !           722:        
        !           723:        ciolib_gettextinfo(&cio_textinfo);
        !           724:        attr=cio_textinfo.attribute;
        !           725:        attr&=143;
        !           726:        attr|=(colour<<4);
        !           727:        ciolib_textattr(attr);
        !           728: }
        !           729: 
        !           730: void ciolib_textcolor(int colour)
        !           731: {
        !           732:        unsigned char attr;
        !           733: 
        !           734:        CIOLIB_INIT();
        !           735:        
        !           736:        ciolib_gettextinfo(&cio_textinfo);
        !           737:        attr=cio_textinfo.attribute;
        !           738:        attr&=240;
        !           739:        attr|=colour;
        !           740:        ciolib_textattr(attr);
        !           741: }
        !           742: 
        !           743: void ciolib_highvideo(void)
        !           744: {
        !           745:        int attr;
        !           746: 
        !           747:        CIOLIB_INIT();
        !           748:        
        !           749:        ciolib_gettextinfo(&cio_textinfo);
        !           750:        attr=cio_textinfo.attribute;
        !           751:        attr |= 8;
        !           752:        ciolib_textattr(attr);
        !           753: }
        !           754: 
        !           755: void ciolib_lowvideo(void)
        !           756: {
        !           757:        int attr;
        !           758: 
        !           759:        CIOLIB_INIT();
        !           760:        
        !           761:        ciolib_gettextinfo(&cio_textinfo);
        !           762:        attr=cio_textinfo.attribute;
        !           763:        attr &= 0xf7;
        !           764:        ciolib_textattr(attr);
        !           765: }
        !           766: 
        !           767: void ciolib_normvideo(void)
        !           768: {
        !           769:        CIOLIB_INIT();
        !           770:        
        !           771:        ciolib_textattr(0x07);
        !           772: }
        !           773: 
        !           774: int ciolib_puttext(int a,int b,int c,int d,unsigned char *e)
        !           775: {
        !           776:        CIOLIB_INIT();
        !           777:        
        !           778:        return(cio_api.puttext(a,b,c,d,e));
        !           779: }
        !           780: 
        !           781: int ciolib_gettext(int a,int b,int c,int d,unsigned char *e)
        !           782: {
        !           783:        CIOLIB_INIT();
        !           784:        
        !           785:        return(cio_api.gettext(a,b,c,d,e));
        !           786: }
        !           787: 
        !           788: void ciolib_textattr(int a)
        !           789: {
        !           790:        CIOLIB_INIT();
        !           791:        
        !           792:        cio_api.textattr(a);
        !           793: }
        !           794: 
        !           795: void ciolib_delay(long a)
        !           796: {
        !           797:        CIOLIB_INIT();
        !           798:        
        !           799:        cio_api.delay(a);
        !           800: }
        !           801: 
        !           802: int ciolib_putch(int a)
        !           803: {
        !           804:        unsigned char a1=a;
        !           805:        CIOLIB_INIT();
        !           806: 
        !           807:        return(cio_api.putch(a1));
        !           808: }
        !           809: 
        !           810: void ciolib_setcursortype(int a)
        !           811: {
        !           812:        CIOLIB_INIT();
        !           813:        
        !           814:        cio_api.setcursortype(a);
        !           815: }
        !           816: 
        !           817: int ciolib_showmouse(void) {
        !           818:        CIOLIB_INIT();
        !           819: 
        !           820:        if(cio_api.showmouse!=NULL)
        !           821:                return(cio_api.showmouse());
        !           822:        return(-1);
        !           823: }
        !           824: 
        !           825: int ciolib_hidemouse(void) {
        !           826:        CIOLIB_INIT();
        !           827: 
        !           828:        if(cio_api.hidemouse!=NULL)
        !           829:                return(cio_api.hidemouse());
        !           830:        return(-1);
        !           831: }
        !           832: 
        !           833: void ciolib_settitle(const char *title) {
        !           834:        CIOLIB_INIT();
        !           835: 
        !           836:        if(cio_api.settitle!=NULL)
        !           837:                cio_api.settitle(title);
        !           838: }

unix.superglobalmegacorp.com

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