#include /* perhaps stupidly, pscreen.h uses CHTYPE for a char + attribute, just like curses. curses.h should typedef 'chtype' to what it uses, so we #define CHTYPE to what pscreen callers are expecting. This also prevents attrib.h from being included and conflicting with attributes defined in curses.h. */ #define CHTYPE unsigned short #include int PSrows, PScols; /* physical screen size */ extern CHTYPE psatts[9]; static chtype convatt[512]; static chtype cuatts[9] = { A_STANDOUT, A_UNDERLINE, A_REVERSE, A_BLINK, A_DIM, A_BOLD, A_INVIS, A_ALTCHARSET }; static unsigned char vtmap[256]; void PSbegin(void) { static unsigned char pcmap[] = { 'h',0262,'a',0260,'f',0370,'g',0361,'j',0331,'k',0277,'l',0332,'m',0300, 'n',0305,'q',0304,'t',0303,'u',0264,'v',0301,'w',0302,'x',0263,'~',0371, '0',0333,047,0004,'b',0003,'c',0006,'d',0005 }; const unsigned char *p; int a; int i; initscr(); PSrows = LINES; PScols = COLS; /* setup attribute conversion table */ for (a = 0; a < 512; ++a) { int i; chtype ch = 0; for (i = 0; i < sizeof psatts; ++i) if (a & psatts[i]) ch |= cuatts[i]; convatt[a] = ch; } /* construct vt100 charset map. pscreen is based on the IBMPC character set (Cp437 in Java). Curses supports only a few special chars which we try to map from the IBMPC set. FIXME: map all line drawing chars to the single linedraw set supported by curses. */ for (i = 0; i < 128; ++i) vtmap[i] = i; memset(vtmap+128,'?',128); for (p = pcmap; p[0] && p[1]; p += 2) vtmap[p[1]] = acs_map[p[0]]; } /* convert char + attribute from pscreen to curses representation */ static chtype conv(CHTYPE c) { chtype ch = convatt[(c>>7)&0x1FF]; // convert attribute bits return ch | vtmap[c&0xFF]; } void PSend(void) { endwin(); } void PSsync(void) { refresh(); } void PSwrite(int row, int col, int ncols, const char *str, CHTYPE a) { /* clip to physical screen */ if (row < 0 || row >= PSrows || col >= PScols) return; if (col + ncols > PScols) ncols = PScols - col; if (col < 0) { ncols += col; col = 0; } move(row,col); while (ncols-- && *str) addch(conv(*str++|a)); } void PSwrtattr(int row, int col, int ncols, const CHTYPE far *buf) { /* clip to physical screen */ if (row < 0 || row >= PSrows || col >= PScols) return; if (col + ncols > PScols) ncols = PScols - col; if (col < 0) { ncols += col; col = 0; } move(row,col); while (ncols--) { addch(conv(*buf++)); } } /* fill rectangle with same char + attribute */ void PSfill(const RECT *rp, CHTYPE c) { RECT r; int row,col; chtype ch; if (!clip(rp,PSrows,PScols,&r)) return; ch = conv(c); for (row = r.r1; row <= r.r2; ++row) { move(row,r.c1); for (col = r.c1; col <= r.c2; ++col) addch(ch); } } /* slide rectangle */ bool PSslide(const RECT *r, enum dir d, int cnt) { /* FIXME: use insch/delch/insline/delline, punt for now */ return FALSE; } /* position cursor */ void PScurpos(int row, int col) { move(row,col); } /* set cursor type 0 = invisible >0 varies with terminfo but visible */ int PScurtype(int type) { return 1; } /* redraw screen */ void PSrefresh(void) { refresh(); } /* print screen */ /* argument is program to pipe ascii screen data into */ int PSprtscr(const char *prog) { /* punt */ return -1; } /* abandon screen update if called while PSsync is executing */ int PSquit(void) { return 0; } /* argument says what kind of noise/flash to make, 0 is "standard", other values terminfo dependent but do something */ void PSbeep(int type) { if (type) beep(); else flash(); } /* load font for a character if terminal supports it */ int PSfont(CHTYPE c, unsigned char glyph[16]) { return -1; } /* send characters to attached printer if any */ bool PSprint(const char *buf, int cnt) { return FALSE; } /* convert CHTYPEs from old (AT&T) format */ //void PSconv(CHTYPE *a,int n,CHTYPE mod); /* dropscrn() Temporarily return terminal to roll mode (i.e. shell mode). Should be called before running interactive programs. restscrn() restore full screen mode and screen contents */ void dropscrn(void) { /* hopefully not used for tuipeer */ } void restscrn(void) { /* hopefully not used for tuipeer */ } /* (internal) convert screen character to printable form */ int toprt(CHTYPE c) { return c & 0x7F; }