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