Commit 067c8262 authored by rswindell's avatar rswindell
Browse files

First pass at porting to Win32 - renamed conio.* to ciolib.*.

Renamed CIOWRAP to CIOLIB.
parent da16ab34
# Available Options:
# NEED_CURSES = Set flags suitable for building with the curses lib
# XCURSES = Use XCurses
# NEED_CIOWRAP = Set flage suitable for using with ciowrap lib
# NEED_CIOLIB = Set flage suitable for using with ciowrap lib
# NO_X = Don't use X version of ciowrap
# You really should set this first.
CONIO_SRC ?= $(XPDEV)../conio/
UIFC_SRC ?= $(XPDEV)../uifc/
CIOWRAP_CFLAGS += -I$(CONIO_SRC)
CIOLIB_CFLAGS += -I$(CONIO_SRC)
# ciowrap stuff
ifndef NO_X
X_DIR ?= /usr/X11R6/
CIOWRAP_CFLAGS += -I${X_DIR}/include
CIOWRAP_LDFLAGS += -L${X_DIR}/lib -lX11
CIOWRAP_OBJS += $(LIBODIR)/console.o $(LIBODIR)/x_cio.o
CIOLIB_CFLAGS += -I${X_DIR}/include
CIOLIB_LDFLAGS += -L${X_DIR}/lib -lX11
CIOLIB_OBJS += $(LIBODIR)/console.o $(LIBODIR)/x_cio.o
else
CIOWRAP_CFLAGS += -DNO_X
CIOLIB_CFLAGS += -DNO_X
endif
CIOWRAP_LDFLAGS += ${PTHREAD_LDFLAGS}
CIOWRAP_CFLAGS += $(PTHREAD_CFLAGS)
CIOWRAP_OBJS += $(LIBODIR)/ansi_cio.o $(LIBODIR)/threadwrap.o
CIOWRAP_OBJS += $(LIBODIR)/curs_cio.o $(LIBODIR)/conio.o
CIOWRAP_CFLAGS += -I$(UIFC_SRC)
CIOLIB_LDFLAGS += ${PTHREAD_LDFLAGS}
CIOLIB_CFLAGS += $(PTHREAD_CFLAGS)
CIOLIB_OBJS += $(LIBODIR)/ansi_cio.o $(LIBODIR)/threadwrap.o
CIOLIB_OBJS += $(LIBODIR)/curs_cio.o $(LIBODIR)/ciolib.o
CIOLIB_CFLAGS += -I$(UIFC_SRC)
# Curses Stuff
ifdef XCURSES
......@@ -38,18 +38,18 @@ else
endif
endif
CIOWRAP_CFLAGS += $(CURSES_CFLAGS)
CIOWRAP_LDFLAGS += $(CURSES_LDFLAGS)
CIOLIB_CFLAGS += $(CURSES_CFLAGS)
CIOLIB_LDFLAGS += $(CURSES_LDFLAGS)
ifdef NEED_CIOWRAP
CFLAGS += $(CIOWRAP_CFLAGS)
LDFLAGS += $(CIOWRAP_LDFLAGS)
OBJS += $(CIOWRAP_OBJS)
ifdef NEED_CIOLIB
CFLAGS += $(CIOLIB_CFLAGS)
LDFLAGS += $(CIOLIB_LDFLAGS)
OBJS += $(CIOLIB_OBJS)
endif
ifdef UIFC_NEED_CIOWRAP
UIFC_CFLAGS += $(CIOWRAP_CFLAGS)
UIFC_LDFLAGS += $(CIOWRAP_LDFLAGS)
UIFC_OBJS += $(CIOWRAP_OBJS)
ifdef UIFC_NEED_CIOLIB
UIFC_CFLAGS += $(CIOLIB_CFLAGS)
UIFC_LDFLAGS += $(CIOLIB_LDFLAGS)
UIFC_OBJS += $(CIOLIB_OBJS)
endif
ifdef NEED_CURSES
......
......@@ -8,7 +8,7 @@
#include <termios.h>
#endif
#include "conio.h"
#include "ciolib.h"
#include "ansi_cio.h"
WORD ansi_curr_attr=0x07<<8;
......
/* $Id$ */
#ifdef __unix__
#include "conio.h"
#include "ciolib.h"
#ifdef __cplusplus
extern "C" {
......@@ -26,4 +25,3 @@ void ansi_textmode(int mode);
}
#endif
#endif
#include <stdarg.h>
#include <stdio.h>
#define CIOLIB_NO_MACROS
#include "ciolib.h"
#ifndef _WIN32
#ifndef NO_X
#include "x_cio.h"
#endif
#include "curs_cio.h"
#undef getch
#endif
#include "ansi_cio.h"
cioapi_t cio_api;
static int ungotch;
static struct text_info cio_textinfo;
static int lastmode=3;
int _wscroll=1;
int directvideo=0;
static int initialized=0;
int ciolib_movetext(int sx, int sy, int ex, int ey, int dx, int dy);
char *ciolib_cgets(char *str);
int ciolib_cscanf (char *format , ...);
int ciolib_kbhit(void);
int ciolib_getch(void);
int ciolib_getche(void);
int ciolib_ungetch(int ch);
void ciolib_gettextinfo(struct text_info *info);
int ciolib_wherex(void);
int ciolib_wherey(void);
void ciolib_wscroll(void);
void ciolib_gotoxy(int x, int y);
void ciolib_clreol(void);
void ciolib_clrscr(void);
int ciolib_cputs(char *str);
int ciolib_cprintf(char *fmat, ...);
void ciolib_textbackground(int colour);
void ciolib_textcolor(int colour);
void ciolib_highvideo(void);
void ciolib_lowvideo(void);
void ciolib_normvideo(void);
int ciolib_puttext(int a,int b,int c,int d,unsigned char *e);
int ciolib_gettext(int a,int b,int c,int d,unsigned char *e);
void ciolib_textattr(unsigned char a);
void ciolib_delay(long a);
int ciolib_putch(unsigned char a);
void ciolib_setcursortype(int a);
void ciolib_textmode(int mode);
void ciolib_window(int sx, int sy, int ex, int ey);
void ciolib_delline(void);
void ciolib_insline(void);
char *ciolib_getpass(const char *prompt);
#ifndef _WIN32
#ifndef NO_X
int try_x_init(int mode)
{
if(!console_init()) {
cio_api.mode=CIOLIB_X_MODE;
cio_api.puttext=x_puttext;
cio_api.gettext=x_gettext;
cio_api.textattr=x_textattr;
cio_api.kbhit=x_kbhit;
cio_api.delay=x_delay;
cio_api.wherey=x_wherey;
cio_api.wherex=x_wherex;
cio_api.putch=x_putch;
cio_api.gotoxy=x_gotoxy;
cio_api.gettextinfo=x_gettextinfo;
cio_api.setcursortype=x_setcursortype;
cio_api.getch=x_getch;
cio_api.getche=x_getche;
cio_api.beep=x_beep;
cio_api.textmode=x_textmode;
return(1);
}
fprintf(stderr,"X init failed\n");
return(0);
}
#endif
int try_curses_init(int mode)
{
if(curs_initciolib(mode)) {
cio_api.mode=CIOLIB_CURSES_IBM_MODE;
cio_api.puttext=curs_puttext;
cio_api.gettext=curs_gettext;
cio_api.textattr=curs_textattr;
cio_api.kbhit=curs_kbhit;
cio_api.delay=curs_delay;
cio_api.wherey=curs_wherey;
cio_api.wherex=curs_wherex;
cio_api.putch=curs_putch;
cio_api.gotoxy=curs_gotoxy;
cio_api.gettextinfo=curs_gettextinfo;
cio_api.setcursortype=curs_setcursortype;
cio_api.getch=curs_getch;
cio_api.getche=curs_getche;
cio_api.beep=beep;
cio_api.textmode=curs_textmode;
return(1);
}
fprintf(stderr,"Curses init failed\n");
return(0);
}
#endif
int try_ansi_init(int mode)
{
if(ansi_initciolib(mode)) {
cio_api.mode=CIOLIB_ANSI_MODE;
cio_api.puttext=ansi_puttext;
cio_api.gettext=ansi_gettext;
cio_api.textattr=ansi_textattr;
cio_api.kbhit=ansi_kbhit;
cio_api.delay=ansi_delay;
cio_api.wherey=ansi_wherey;
cio_api.wherex=ansi_wherex;
cio_api.putch=ansi_putch;
cio_api.gotoxy=ansi_gotoxy;
cio_api.gettextinfo=ansi_gettextinfo;
cio_api.setcursortype=ansi_setcursortype;
cio_api.getch=ansi_getch;
cio_api.getche=ansi_getche;
cio_api.beep=ansi_beep;
cio_api.textmode=ansi_textmode;
return(1);
}
fprintf(stderr,"ANSI init failed\n");
return(0);
}
#ifdef _WIN32
int try_ciolib_init(int mode)
{
/* This should test for something or other */
if(1) {
cio_api.mode=CIOLIB_CIOLIB_MODE;
cio_api.puttext=puttext;
cio_api.gettext=gettext;
cio_api.textattr=textattr;
cio_api.kbhit=kbhit;
cio_api.delay=delay;
cio_api.wherey=wherey;
cio_api.wherex=wherex;
cio_api.putch=putch;
cio_api.gotoxy=gotoxy;
cio_api.gettextinfo=gettextinfo;
cio_api.setcursortype=setcursortype;
cio_api.getch=getch;
cio_api.getche=getche;
cio_api.beep=beep;
cio_api.textmode=textmode;
return(1);
}
fprintf(stderr,"CIOLIB init failed\n");
return(0);
}
#endif
int initciolib(int mode)
{
switch(mode) {
case CIOLIB_AUTO_MODE:
#ifdef _WIN32
if(!try_ciolib_init(mode))
#else
if(!try_x_init(mode))
if(!try_curses_init(mode))
#endif
try_ansi_init(mode);
break;
#ifdef _WIN32
case CIOLIB_ciolib_MODE:
try_ciolib_init(mode);
break;
#else
case CIOLIB_CURSES_MODE:
case CIOLIB_CURSES_IBM_MODE:
try_curses_init(mode);
break;
case CIOLIB_X_MODE:
try_x_init(mode);
break;
#endif
case CIOLIB_ANSI_MODE:
try_ansi_init(mode);
break;
}
if(cio_api.mode==CIOLIB_AUTO_MODE) {
fprintf(stderr,"CIOLIB initialization failed!");
return(-1);
}
initialized=1;
ciolib_gettextinfo(&cio_textinfo);
cio_textinfo.winleft=1;
cio_textinfo.wintop=1;
cio_textinfo.winright=cio_textinfo.screenwidth;
cio_textinfo.winbottom=cio_textinfo.screenheight;
cio_textinfo.normattr=7;
return(0);
}
int ciolib_kbhit(void)
{
if(!initialized)
initciolib(CIOLIB_AUTO_MODE);
if(ungotch)
return(1);
return(cio_api.kbhit());
}
int ciolib_getch(void)
{
int ch;
if(!initialized)
initciolib(CIOLIB_AUTO_MODE);
if(ungotch) {
ch=ungotch;
ungotch=0;
return(ch);
}
return(cio_api.getch());
}
int ciolib_getche(void)
{
int ch;
if(!initialized)
initciolib(CIOLIB_AUTO_MODE);
if(ungotch) {
ch=ungotch;
ungotch=0;
ciolib_putch(ch);
return(ch);
}
return(cio_api.getche());
}
int ciolib_ungetch(int ch)
{
if(!initialized)
initciolib(CIOLIB_AUTO_MODE);
if(ungotch)
return(EOF);
ungotch=ch;
return(ch);
}
int ciolib_movetext(int sx, int sy, int ex, int ey, int dx, int dy)
{
int width;
int height;
char *buf;
if(!initialized)
initciolib(CIOLIB_AUTO_MODE);
width=ex-sx;
height=ey-sy;
buf=(char *)malloc((width+1)*(height+1)*2);
if(buf==NULL)
return(0);
if(!ciolib_gettext(sx,sy,ex,ey,buf)) {
free(buf);
return(0);
}
if(!ciolib_puttext(dx,dy,dx+width,dy+height,buf)) {
free(buf);
return(0);
}
free(buf);
return(1);
}
char *ciolib_cgets(char *str)
{
int maxlen;
int len=0;
int chars;
int ch;
if(!initialized)
initciolib(CIOLIB_AUTO_MODE);
maxlen=*(unsigned char *)str;
while((ch=ciolib_getche())!='\n') {
switch(ch) {
case 0: /* Skip extended keys */
ch=ciolib_getche();
break;
case '\n':
str[len+2]=0;
*((unsigned char *)(str+1))=(unsigned char)len;
return(&str[2]);
case '\r': /* Skip \r (ToDo: Should this be treeated as a \n? */
break;
case '\b':
if(len==0) {
cio_api.beep();
break;
}
ciolib_putch('\b');
len--;
break;
default:
str[(len++)+2]=ch;
if(len==maxlen) {
str[len+2]=0;
*((unsigned char *)(str+1))=(unsigned char)len;
return(&str[2]);
}
break;
}
}
}
int ciolib_cscanf (char *format , ...)
{
char str[255];
va_list argptr;
int ret;
if(!initialized)
initciolib(CIOLIB_AUTO_MODE);
str[0]=-1;
va_start(argptr,format);
ret=vsscanf(ciolib_cgets(str),format,argptr);
va_end(argptr);
return(ret);
}
char *ciolib_getpass(const char *prompt)
{
static char pass[9];
int len=0;
int chars;
int ch;
if(!initialized)
initciolib(CIOLIB_AUTO_MODE);
while((ch=getch())!='\n') {
switch(ch) {
case 0: /* Skip extended keys */
ch=getch();
break;
case '\n':
pass[len]=0;
return(pass);
case '\r': /* Skip \r (ToDo: Should this be treeated as a \n? */
break;
case '\b':
if(len==0) {
cio_api.beep();
break;
}
len--;
break;
default:
if(len==8)
cio_api.beep();
else
pass[len++]=ch;
break;
}
}
}
void ciolib_gettextinfo(struct text_info *info)
{
if(!initialized)
initciolib(CIOLIB_AUTO_MODE);
else {
cio_api.gettextinfo(&cio_textinfo);
}
if(info!=&cio_textinfo) {
info->winleft=cio_textinfo.winleft; /* left window coordinate */
info->wintop=cio_textinfo.wintop; /* top window coordinate */
info->winright=cio_textinfo.winright; /* right window coordinate */
info->winbottom=cio_textinfo.winbottom; /* bottom window coordinate */
info->attribute=cio_textinfo.attribute; /* text attribute */
info->normattr=cio_textinfo.normattr; /* normal attribute */
info->currmode=cio_textinfo.currmode; /* current video mode:
BW40, BW80, C40, C80, or C4350 */
info->screenheight=cio_textinfo.screenheight; /* text screen's height */
info->screenwidth=cio_textinfo.screenwidth; /* text screen's width */
info->curx=cio_textinfo.curx; /* x-coordinate in current window */
info->cury=cio_textinfo.cury; /* y-coordinate in current window */
}
}
void ciolib_wscroll(void)
{
char *buf;
int os;
struct text_info ti;
if(!initialized)
initciolib(CIOLIB_AUTO_MODE);
ciolib_gettextinfo(&ti);
if(!_wscroll)
return;
ciolib_movetext(ti.winleft,ti.wintop+1,ti.winright,ti.winbottom,ti.winleft,ti.wintop);
ciolib_gotoxy(1,ti.winbottom-ti.winleft+1);
os=_wscroll;
_wscroll=0;
ciolib_cprintf("%*s",ti.winright-ti.winleft+1,"");
_wscroll=os;
ciolib_gotoxy(ti.curx,ti.cury);
}
int ciolib_wherex(void)
{
int x;
if(!initialized)
initciolib(CIOLIB_AUTO_MODE);
x=cio_api.wherex();
x=x-cio_textinfo.winleft+1;
return(x);
}
int ciolib_wherey(void)
{
int y;
if(!initialized)
initciolib(CIOLIB_AUTO_MODE);
y=cio_api.wherey();
y=y-cio_textinfo.wintop+1;
return(y);
}
void ciolib_gotoxy(int x, int y)
{
int nx;
int ny;
struct text_info ti;
if(!initialized)
initciolib(CIOLIB_AUTO_MODE);
ciolib_gettextinfo(&ti);
if( x < 1
|| x > ti.winright-ti.winleft+1
|| y < 1
|| y > ti.winbottom-ti.wintop+1)
return;
nx=x+ti.winleft-1;
ny=y+ti.wintop-1;
cio_api.gotoxy(nx,ny);
}
void ciolib_textmode(mode)
{
if(!initialized)
initciolib(CIOLIB_AUTO_MODE);
if(mode==-1) {
ciolib_gettextinfo(&cio_textinfo);
cio_api.textmode(lastmode);
lastmode=cio_textinfo.currmode;
}
else {
ciolib_gettextinfo(&cio_textinfo);
lastmode=cio_textinfo.currmode;
cio_api.textmode(mode);
}
ciolib_gettextinfo(&cio_textinfo);
cio_textinfo.winleft=1;
cio_textinfo.wintop=1;
cio_textinfo.winright=cio_textinfo.screenwidth;
cio_textinfo.winbottom=cio_textinfo.screenheight;
}
void ciolib_window(int sx, int sy, int ex, int ey)
{
if(!initialized)
initciolib(CIOLIB_AUTO_MODE);
ciolib_gettextinfo(&cio_textinfo);
if( sx < 1
|| sy < 1
|| ex < 1
|| ey < 1
|| sx > cio_textinfo.screenwidth
|| sy > cio_textinfo.screenheight
|| sx > ex
|| sy > ey
|| ex > cio_textinfo.screenwidth
|| ey > cio_textinfo.screenheight)
return;
cio_textinfo.winleft=sx;
cio_textinfo.wintop=sy;
cio_textinfo.winright=ex;
cio_textinfo.winbottom=ey;
ciolib_gotoxy(1,1);
}
void ciolib_clreol(void)
{
int os;
struct text_info ti;
if(!initialized)
initciolib(CIOLIB_AUTO_MODE);
ciolib_gettextinfo(&ti);
os=_wscroll;
_wscroll=0;
ciolib_cprintf("%*s",ti.winright-ti.curx+1,"");
_wscroll=os;
ciolib_gotoxy(ti.curx,ti.cury);
}
void ciolib_clrscr(void)
{
char *buf;
int i;
int width,height;
struct text_info ti;
if(!initialized)
initciolib(CIOLIB_AUTO_MODE);
ciolib_gettextinfo(&ti);
width=ti.winright-ti.winleft+1;
height=ti.winbottom-ti.wintop+1;
buf=(char *)malloc(width*height*2);
for(i=0;i<width*height*2;) {
buf[i++]=' ';
buf[i++]=ti.attribute;