diff --git a/os2/pdcclip.c b/os2/pdcclip.c index 53e6a0a4..d9ce73ee 100644 --- a/os2/pdcclip.c +++ b/os2/pdcclip.c @@ -18,10 +18,9 @@ *************************************************************************** */ - #define CURSES_LIBRARY 1 #ifdef HAVE_CONFIG_H -# include +# include #endif #if !defined(EMXVIDEO) # define INCL_DOS @@ -32,185 +31,190 @@ #include #ifdef PDCDEBUG -char *rcsid_PDCclip = "$Id: pdcclip.c,v 1.6 2006/01/03 07:34:43 wmcbrine Exp $"; +char *rcsid_PDCclip = "$Id: pdcclip.c,v 1.7 2006/01/08 11:53:42 wmcbrine Exp $"; #endif - /*man-start********************************************************************* PDC_getclipboard() - Gets the contents of the clipboard PDCurses Description: - This is a PDCurses only routine. + This is a PDCurses only routine. - Gets the textual contents of the system's clipboard. This - function returns the contents of the clipboard in the contents - argument. It is the responsibilitiy of the caller to free the - memory returned with the PDC_freeclipboard() call. The length of the - clipboard contents is returned in the length argument. + Gets the textual contents of the system's clipboard. This + function returns the contents of the clipboard in the contents + argument. It is the responsibilitiy of the caller to free the + memory returned with the PDC_freeclipboard() call. The length + of the clipboard contents is returned in the length argument. PDCurses Return Value: - indicator of success/failure of call. - PDC_CLIP_SUCCESS the call was successful - PDC_CLIP_ACCESS_ERROR an error occured while accessing the - clipboard - PDC_CLIP_MEMORY_ERROR unable to allocate sufficient memory for - the clipboard contents - PDC_CLIP_EMPTY the clipboard contains no text + indicator of success/failure of call. + PDC_CLIP_SUCCESS the call was successful + PDC_CLIP_ACCESS_ERROR an error occured while accessing the + clipboard + PDC_CLIP_MEMORY_ERROR unable to allocate sufficient memory for + the clipboard contents + PDC_CLIP_EMPTY the clipboard contains no text Portability: - PDCurses int PDC_getclipboard( char **contents, long *length ); + PDCurses int PDC_getclipboard(char **contents, long *length); **man-end**********************************************************************/ int PDC_CDECL PDC_getclipboard(char **contents, long *length) { #if !defined(EMXVIDEO) - HMQ hmq; - HAB hab; - PTIB ptib; - PPIB ppib; - ULONG ulRet; - long len=0; - int rc=0; + HMQ hmq; + HAB hab; + PTIB ptib; + PPIB ppib; + ULONG ulRet; + long len; + int rc; #endif - - PDC_LOG(("PDC_getclipboard() - called\n")); + PDC_LOG(("PDC_getclipboard() - called\n")); #if !defined(EMXVIDEO) - DosGetInfoBlocks( &ptib, &ppib ); - ppib->pib_ultype = 3; - hab = WinInitialize( 0 ); - hmq = WinCreateMsgQueue( hab, 0 ); + DosGetInfoBlocks(&ptib, &ppib); + ppib->pib_ultype = 3; + hab = WinInitialize(0); + hmq = WinCreateMsgQueue(hab, 0); - if ( !WinOpenClipbrd( hab ) ) - { - WinDestroyMsgQueue( hmq ); - WinTerminate( hab ); - return PDC_CLIP_ACCESS_ERROR; - } - ulRet = WinQueryClipbrdData( hab, CF_TEXT ); - if ( !ulRet ) - rc = PDC_CLIP_EMPTY; - else - { - len = strlen( (char *)ulRet ); - *contents = (char *)malloc( len+1 ); - if ( !*contents ) - { - rc = PDC_CLIP_MEMORY_ERROR; - } - else - { - strcpy( (char *)*contents, (char *)ulRet ); - *length = len; - rc = PDC_CLIP_SUCCESS; - } - } - WinCloseClipbrd( hab ); - WinDestroyMsgQueue( hmq ); - WinTerminate( hab ); - return( rc ); + if (!WinOpenClipbrd(hab)) + { + WinDestroyMsgQueue(hmq); + WinTerminate(hab); + return PDC_CLIP_ACCESS_ERROR; + } + + rc = PDC_CLIP_EMPTY; + + ulRet = WinQueryClipbrdData(hab, CF_TEXT); + + if (ulRet) + { + len = strlen((char *)ulRet); + *contents = (char *)malloc(len + 1); + + if (!*contents) + rc = PDC_CLIP_MEMORY_ERROR; + else + { + strcpy((char *)*contents, (char *)ulRet); + *length = len; + rc = PDC_CLIP_SUCCESS; + } + } + + WinCloseClipbrd(hab); + WinDestroyMsgQueue(hmq); + WinTerminate(hab); + + return rc; #else - return PDC_CLIP_ACCESS_ERROR; + return PDC_CLIP_ACCESS_ERROR; #endif } - /*man-start********************************************************************* PDC_setclipboard() - Sets the contents of the clipboard PDCurses Description: - This is a PDCurses only routine. + This is a PDCurses only routine. - Copies the supplied text into the system's clipboard, emptying - the clipboard prior to the copy. + Copies the supplied text into the system's clipboard, emptying + the clipboard prior to the copy. PDCurses Return Value: - indicator of success/failure of call. - PDC_CLIP_SUCCESS the call was successful - PDC_CLIP_ACCESS_ERROR an error occured while accessing the - clipboard + indicator of success/failure of call. + PDC_CLIP_SUCCESS the call was successful + PDC_CLIP_ACCESS_ERROR an error occured while accessing the + clipboard Portability: - PDCurses int PDC_getclipboard( char *contents, long length ); + PDCurses int PDC_getclipboard(char *contents, long length); **man-end**********************************************************************/ int PDC_CDECL PDC_setclipboard(char *contents, long length) { #if !defined(EMXVIDEO) - HAB hab; - PTIB ptib; - PPIB ppib; - ULONG ulRC; - PSZ szTextOut=NULL; - int rc=0; + HAB hab; + PTIB ptib; + PPIB ppib; + ULONG ulRC; + PSZ szTextOut = NULL; + int rc; #endif - - PDC_LOG(("PDC_setclipboard() - called\n")); + PDC_LOG(("PDC_setclipboard() - called\n")); #if !defined(EMXVIDEO) - DosGetInfoBlocks( &ptib, &ppib ); - ppib->pib_ultype = 3; - hab = WinInitialize( 0 ); + DosGetInfoBlocks(&ptib, &ppib); + ppib->pib_ultype = 3; + hab = WinInitialize(0); - if ( !WinOpenClipbrd( hab ) ) - { - WinTerminate( hab ); - return PDC_CLIP_ACCESS_ERROR; - } - ulRC = DosAllocSharedMem( (PVOID) &szTextOut, NULL, length+1, PAG_WRITE | PAG_COMMIT | OBJ_GIVEABLE ); - if (ulRC != 0) - { - rc = PDC_CLIP_MEMORY_ERROR; - } - else - { - strcpy( szTextOut, contents ); - WinEmptyClipbrd( hab ); - if ( WinSetClipbrdData( hab, (ULONG)szTextOut, CF_TEXT, CFI_POINTER ) ) - { - rc = PDC_CLIP_SUCCESS; - } - else - { - DosFreeMem( szTextOut ); - rc = PDC_CLIP_ACCESS_ERROR; - } - } - WinCloseClipbrd( hab ); - WinTerminate( hab ); - return( rc ); + if (!WinOpenClipbrd(hab)) + { + WinTerminate(hab); + return PDC_CLIP_ACCESS_ERROR; + } + + rc = PDC_CLIP_MEMORY_ERROR; + + ulRC = DosAllocSharedMem((PVOID)&szTextOut, NULL, length + 1, + PAG_WRITE | PAG_COMMIT | OBJ_GIVEABLE); + + if (ulRC == 0) + { + strcpy(szTextOut, contents); + WinEmptyClipbrd(hab); + + if (WinSetClipbrdData(hab, (ULONG)szTextOut, + CF_TEXT, CFI_POINTER)) + rc = PDC_CLIP_SUCCESS; + else + { + DosFreeMem(szTextOut); + rc = PDC_CLIP_ACCESS_ERROR; + } + } + + WinCloseClipbrd(hab); + WinTerminate(hab); + + return rc; #else - return PDC_CLIP_ACCESS_ERROR; + return PDC_CLIP_ACCESS_ERROR; #endif } /*man-start********************************************************************* - PDC_freeclipboard() - Frees the memory associated with the contents of the clipboard + PDC_freeclipboard() - Frees the memory associated with the contents + of the clipboard PDCurses Description: - This is a PDCurses only routine. + This is a PDCurses only routine. - Frees the memory allocated by PDC_getclipboard(). + Frees the memory allocated by PDC_getclipboard(). PDCurses Return Value: - Always returns PDC_CLIP_SUCCESS + Always returns PDC_CLIP_SUCCESS Portability: - PDCurses int PDC_freeclipboard( char *contents ); + PDCurses int PDC_freeclipboard(char *contents); **man-end**********************************************************************/ int PDC_CDECL PDC_freeclipboard(char *contents) { - PDC_LOG(("PDC_freeclipboard() - called\n")); + PDC_LOG(("PDC_freeclipboard() - called\n")); - if ( contents) free(contents); - return PDC_CLIP_SUCCESS; + if (contents) + free(contents); + + return PDC_CLIP_SUCCESS; } /*man-start********************************************************************* @@ -218,39 +222,39 @@ int PDC_CDECL PDC_freeclipboard(char *contents) PDC_clearclipboard() - Clears the contents of the clipboard PDCurses Description: - This is a PDCurses only routine. + This is a PDCurses only routine. - Clears the internal clipboard. + Clears the internal clipboard. PDCurses Return Value: - Always returns PDC_CLIP_SUCCESS + Always returns PDC_CLIP_SUCCESS Portability: - PDCurses int PDC_clearclipboard( void ); + PDCurses int PDC_clearclipboard(void); **man-end**********************************************************************/ -int PDC_CDECL PDC_clearclipboard( void ) +int PDC_CDECL PDC_clearclipboard(void) { #if !defined(EMXVIDEO) - HAB hab; - PTIB ptib; - PPIB ppib; + HAB hab; + PTIB ptib; + PPIB ppib; #endif - - PDC_LOG(("PDC_clearclipboard() - called\n")); + PDC_LOG(("PDC_clearclipboard() - called\n")); #if !defined(EMXVIDEO) - DosGetInfoBlocks( &ptib, &ppib ); - ppib->pib_ultype = 3; - hab = WinInitialize( 0 ); + DosGetInfoBlocks(&ptib, &ppib); + ppib->pib_ultype = 3; + hab = WinInitialize(0); - WinEmptyClipbrd( hab ); + WinEmptyClipbrd(hab); - WinCloseClipbrd( hab ); - WinTerminate( hab ); - return PDC_CLIP_SUCCESS; + WinCloseClipbrd(hab); + WinTerminate(hab); + + return PDC_CLIP_SUCCESS; #else - return PDC_CLIP_ACCESS_ERROR; + return PDC_CLIP_ACCESS_ERROR; #endif } diff --git a/os2/pdcdisp.c b/os2/pdcdisp.c index 55158498..07ae7d39 100644 --- a/os2/pdcdisp.c +++ b/os2/pdcdisp.c @@ -19,18 +19,18 @@ */ #define CURSES_LIBRARY 1 #ifdef HAVE_CONFIG_H -# include +# include #endif #include #include #ifdef HAVE_MEMORY_H -# include +# include #endif #ifdef PDCDEBUG -char *rcsid_PDCdisp = "$Id: pdcdisp.c,v 1.5 2006/01/03 19:54:29 wmcbrine Exp $"; +char *rcsid_PDCdisp = "$Id: pdcdisp.c,v 1.6 2006/01/08 11:53:42 wmcbrine Exp $"; #endif /*man-start********************************************************************* @@ -38,20 +38,20 @@ char *rcsid_PDCdisp = "$Id: pdcdisp.c,v 1.5 2006/01/03 19:54:29 wmcbrine Exp $" PDC_clr_update() - Updates the screen with a full redraw. PDCurses Description: - Updates the screen by clearing it and then redraw it in its - entirety. If SP->refrbrk is TRUE, and there is pending - input characters, the update will be prematurely terminated. + Updates the screen by clearing it and then redraw it in its + entirety. If SP->refrbrk is TRUE, and there is pending + input characters, the update will be prematurely terminated. PDCurses Return Value: - This routine returns ERR if it is unable to accomplish its task. + This routine returns ERR if it is unable to accomplish its task. - The return value OK is returned if there were no errors. + The return value OK is returned if there were no errors. PDCurses Errors: - No errors are defined for this function. + No errors are defined for this function. Portability: - PDCurses int PDC_clr_update( WINDOW* s ); + PDCurses int PDC_clr_update(WINDOW *s); **man-end**********************************************************************/ @@ -64,68 +64,76 @@ WINDOW *s; #endif /***********************************************************************/ { -register int i=0,j=0; - WINDOW* w=NULL; - unsigned short* ch; - bool rc=FALSE; + int i, j; + unsigned short *ch; extern unsigned char atrtab[MAX_ATRTAB]; -/* the next two variables have been changed from chtype to unsigned short */ -/* as this is the correct datatype for a physical character/attribute */ - unsigned short temp_line[256]; /* this should be enough for the maximum width of a screen. MH-920715 */ + /* the next two variables have been changed from chtype to + unsigned short as this is the correct datatype for a physical + character/attribute */ + + /* this should be enough for the maximum width of a screen. */ + + unsigned short temp_line[256]; unsigned short chr; PDC_LOG(("PDC_clr_update() - called\n")); - w = curscr; - if (w == (WINDOW *)NULL) - return( ERR ); -/* if (SP->full_redraw) - PDC_clr_scrn(s); *//* clear physical screen */ - + if (curscr == (WINDOW *)NULL) + return ERR; +#if 0 + if (SP->full_redraw) + PDC_clr_scrn(s); /* clear physical screen */ +#endif s->_clear = FALSE; + for (i = 0; i < LINES; i++) /* update physical screen */ { - if (s != w) /* copy s to curscr */ - memcpy(w->_y[i], s->_y[i], COLS * sizeof(chtype)); + /* copy s to curscr -- must be same size */ - ch = temp_line; /* now have ch pointing to area to contain real attributes. MH-920715 */ + if (s != curscr) + memcpy(curscr->_y[i], s->_y[i], COLS * sizeof(chtype)); - for (j=0;j_y[i][j] & A_CHARTEXT); temp_line[j] = chtype_attr(s->_y[i][j]) | chr; - } + } if (SP->direct_video) - { #ifdef EMXVIDEO - v_putline ((char *)ch, 0, i, COLS); + v_putline ((char *)ch, 0, i, COLS); #else - VioWrtCellStr ((PCH)ch, (USHORT)(COLS * sizeof(unsigned short)), (USHORT)i, 0, 0); + VioWrtCellStr((PCH)ch, + (USHORT)(COLS * sizeof(unsigned short)), + (USHORT)i, 0, 0); #endif - } else - { for (j = 0; j < COLS; j++) { PDC_gotoxy(i, j); - PDC_putc( (*ch & A_CHARTEXT), (*ch & A_ATTRIBUTES) >> 8 ); + PDC_putc((*ch & A_CHARTEXT), + (*ch & A_ATTRIBUTES) >> 8); ch++; } - } - if (SP->refrbrk && (SP->cbreak || SP->raw_inp)) - { - rc = PDC_breakout(); - if(rc) - break; - } - w->_firstch[i] = _NO_CHANGE; - w->_lastch[i] = _NO_CHANGE; + if (SP->refrbrk && (SP->cbreak || SP->raw_inp) + && PDC_breakout()) + break; + + curscr->_firstch[i] = _NO_CHANGE; + curscr->_lastch[i] = _NO_CHANGE; } - return( OK ); + + return OK; } /*man-start********************************************************************* @@ -133,13 +141,13 @@ register int i=0,j=0; PDC_cursor_on() - Turns on the hardware cursor. PDCurses Description: - Turns on the hardware curses, it does nothing if it is already on. + Turns on the hardware cursor; does nothing if it is already on. PDCurses Return Value: - Returns OK upon success, ERR upon failure. + Returns OK upon success, ERR upon failure. Portability: - PDCurses int PDC_cursor_on( void ); + PDCurses int PDC_cursor_on(void); **man-end**********************************************************************/ @@ -153,13 +161,14 @@ int PDC_cursor_on() { PDC_LOG(("PDC_cursor_on() - called\n")); - if (!SP->visible_cursor) + if (!SP->visible_cursor) { SP->visible_cursor = TRUE; PDC_set_cursor_mode((SP->cursor & 0xff00) >> 8, (SP->cursor & 0x00ff)); } - return( OK ); + + return OK; } /*man-start********************************************************************* @@ -167,17 +176,16 @@ int PDC_cursor_on() PDC_cursor_off() - Turns off the hardware cursor. PDCurses Description: - Turns off the hardware curses, it does nothing if it is already off. + Turns off the hardware cursor; does nothing if it is already off. PDCurses Return Value: - Returns OK upon success, ERR upon failure. + Returns OK upon success, ERR upon failure. PDCurses Errors: - ERR will be returned if the hardware cursor - can not be disabled. + ERR will be returned if the hardware cursor can not be disabled. Portability: - PDCurses int PDC_cursor_off( void ); + PDCurses int PDC_cursor_off(void); **man-end**********************************************************************/ @@ -191,39 +199,42 @@ int PDC_cursor_off() { PDC_LOG(("PDC_cursor_off() - called\n")); - if (SP->visible_cursor) + if (SP->visible_cursor) { SP->visible_cursor = FALSE; PDC_set_cursor_mode(32, 33); /* turn it off */ } - return( OK ); + + return OK; } /*man-start********************************************************************* - PDC_fix_cursor() - Fix the cursor start and stop scan lines (if necessary) + PDC_fix_cursor() - Fix the cursor start and stop scan lines + (if necessary) PDCurses Description: - This is a private PDCurses routine. + This is a private PDCurses routine. - This routine will fix the cursor shape for certain video adapters. - Normally, the values used are correct, but some adapters choke. - The most noticable choke is on a monochrome adapter. The "correct" - scan lines will result in the cursor being set in the middle of the - character cell, rather than at the bottom. + This routine will fix the cursor shape for certain video + adapters. Normally, the values used are correct, but some + adapters choke. The most noticable choke is on a monochrome + adapter. The "correct" scan lines will result in the cursor + being set in the middle of the character cell, rather than at + the bottom. - The passed flag indicates whether the cursor is visible or not. + The passed flag indicates whether the cursor is visible or not. - This only applies to the DOS platform. + This only applies to the DOS platform. PDCurses Return Value: - This function returns OK on success and ERR on error. + This function returns OK on success and ERR on error. PDCurses Errors: - No errors are defined for this function. + No errors are defined for this function. Portability: - PDCurses int PDC_fix_cursor( int flag ); + PDCurses int PDC_fix_cursor(int flag); **man-end**********************************************************************/ @@ -236,7 +247,7 @@ int flag; #endif /***********************************************************************/ { - return( OK ); + return OK; } /*man-start********************************************************************* @@ -244,20 +255,20 @@ int flag; PDC_gotoxy() - position hardware cursor at (x, y) PDCurses Description: - This is a private PDCurses routine. + This is a private PDCurses routine. - Moves the physical cursor to the desired address on the - screen. We don't optimize here -- on a PC, it takes more time - to optimize than to do things directly. + Moves the physical cursor to the desired address on the screen. + We don't optimize here -- on a PC, it takes more time to + optimize than to do things directly. PDCurses Return Value: - This function returns OK on success and ERR on error. + This function returns OK on success and ERR on error. PDCurses Errors: - No errors are defined for this function. + No errors are defined for this function. Portability: - PDCurses int PDC_gotoxy( int row, int col ); + PDCurses int PDC_gotoxy(int row, int col); **man-end**********************************************************************/ @@ -265,20 +276,20 @@ int flag; #ifdef HAVE_PROTO int PDC_gotoxy(int row, int col) #else -int PDC_gotoxy(row,col) +int PDC_gotoxy(row, col) int row; int col; #endif /***********************************************************************/ { - PDC_LOG(("PDC_gotoxy() - called: row %d col %d\n",row,col)); + PDC_LOG(("PDC_gotoxy() - called: row %d col %d\n", row, col)); #ifdef EMXVIDEO - v_gotoxy (col, row); + v_gotoxy(col, row); #else - VioSetCurPos (row, col, 0); + VioSetCurPos(row, col, 0); #endif - return(OK); + return OK; } /*man-start********************************************************************* @@ -286,49 +297,50 @@ int col; PDC_putc() - Output a character in the current attribute. PDCurses Description: - This is a private PDCurses routine. + This is a private PDCurses routine. - Outputs character 'chr' to screen in tty fashion. If a colour - mode is active, the character is written with colour 'colour'. + Outputs character 'chr' to screen in tty fashion. If a colour + mode is active, the character is written with colour 'colour'. PDCurses Return Value: - This function returns OK on success and ERR on error. + This function returns OK on success and ERR on error. PDCurses Errors: - No errors are defined for this function. + No errors are defined for this function. Portability: - PDCurses int PDC_putc( chtype character, chtype color ); + PDCurses int PDC_putc(chtype character, chtype color); **man-end**********************************************************************/ /***********************************************************************/ #ifdef HAVE_PROTO -int PDC_putc( chtype character, chtype color ) +int PDC_putc(chtype character, chtype color) #else -int PDC_putc(character,color) +int PDC_putc(character, color) chtype character; chtype color; #endif /***********************************************************************/ { - int curRow=0, curCol=0; + int curRow = 0, curCol = 0; #ifdef EMXVIDEO char Cell[2]; #endif - PDC_LOG(("PDC_putc() - called:char=%c attrib=0x%x color=0x%x\n",character & A_CHARTEXT,character & A_ATTRIBUTES,color)); + PDC_LOG(("PDC_putc() - called: char=%c attrib=0x%x color=0x%x\n", + character & A_CHARTEXT, character & A_ATTRIBUTES, color)); - PDC_get_cursor_pos (&curRow, &curCol); + PDC_get_cursor_pos(&curRow, &curCol); #ifdef EMXVIDEO Cell[0] = (char)character; Cell[1] = (char)color; - v_putline (Cell, curCol, curRow, 1); + v_putline(Cell, curCol, curRow, 1); #else - VioWrtTTY ((PCH)&character, 1, 0); - VioWrtNAttr ((PBYTE)&color, 1, (USHORT)curRow, (USHORT)curCol, 0); - PDC_gotoxy (curRow, curCol); + VioWrtTTY((PCH)&character, 1, 0); + VioWrtNAttr((PBYTE)&color, 1, (USHORT)curRow, (USHORT)curCol, 0); + PDC_gotoxy(curRow, curCol); #endif - return( OK ); + return OK; } /*man-start********************************************************************* @@ -336,30 +348,30 @@ chtype color; PDC_putctty() - Output a character and attribute in TTY fashion. PDCurses Description: - This is a private PDCurses routine. + This is a private PDCurses routine. - Outputs character 'chr' to screen in tty fashion. If a colour - mode is active, the character is written with colour 'colour'. + Outputs character 'chr' to screen in tty fashion. If a colour + mode is active, the character is written with colour 'colour'. - This function moves the physical cursor after writing so the - screen will scroll if necessary. + This function moves the physical cursor after writing so the + screen will scroll if necessary. PDCurses Return Value: - This function returns OK on success and ERR on error. + This function returns OK on success and ERR on error. PDCurses Errors: - No errors are defined for this function. + No errors are defined for this function. Portability: - PDCurses int PDC_putctty( chtype character, chtype color ); + PDCurses int PDC_putctty(chtype character, chtype color); **man-end**********************************************************************/ /***********************************************************************/ #ifdef HAVE_PROTO -int PDC_putctty( chtype character, chtype color ) +int PDC_putctty(chtype character, chtype color) #else -int PDC_putctty(character,color) +int PDC_putctty(character, color) chtype character; chtype color; #endif @@ -369,15 +381,15 @@ chtype color; PDC_LOG(("PDC_putctty() - called\n")); - PDC_get_cursor_pos (&curRow, &curCol); + PDC_get_cursor_pos(&curRow, &curCol); #ifdef EMXVIDEO - v_attrib (color); - v_putc (character); + v_attrib(color); + v_putc(character); #else - VioWrtTTY ((PCH)&character, 1, 0); - VioWrtNAttr ((PBYTE)&color, 1, (USHORT)curRow, (USHORT)curCol, 0); + VioWrtTTY((PCH)&character, 1, 0); + VioWrtNAttr((PBYTE)&color, 1, (USHORT)curRow, (USHORT)curCol, 0); #endif - return( OK ); + return OK; } /*man-start********************************************************************* @@ -385,27 +397,29 @@ chtype color; PDC_scroll() - low level screen scroll PDCurses Description: - Scrolls a window in the current page up or down. Urow, lcol, - lrow, rcol are the window coordinates. Lines is the number of - lines to scroll. If 0, clears the window, if < 0 scrolls down, - if > 0 scrolls up. Blanks areas that are left, and sets - character attributes to attr. If in a colour graphics mode, - fills them with the colour 'attr' instead. + Scrolls a window in the current page up or down. Urow, lcol, + lrow, rcol are the window coordinates. Lines is the number of + lines to scroll. If 0, clears the window, if < 0 scrolls down, + if > 0 scrolls up. Blanks areas that are left, and sets + character attributes to attr. If in a colour graphics mode, + fills them with the colour 'attr' instead. PDCurses Return Value: - The PDC_scroll() function returns OK on success otherwise ERR is returned. + The PDC_scroll() function returns OK on success otherwise ERR is + returned. Portability: - PDCurses int PDC_scroll( int urow, int lcol, int rcol, - int nlines, chtype attr ); + PDCurses int PDC_scroll(int urow, int lcol, int rcol, + int nlines, chtype attr); **man-end**********************************************************************/ /***********************************************************************/ #ifdef HAVE_PROTO -int PDC_scroll(int urow, int lcol, int lrow, int rcol, int nlines, chtype attr) +int PDC_scroll(int urow, int lcol, int lrow, int rcol, + int nlines, chtype attr) #else -int PDC_scroll(urow,lcol,lrow,rcol,nlines,attr) +int PDC_scroll(urow, lcol, lrow, rcol, nlines, attr) int urow; int lcol; int lrow; @@ -416,34 +430,37 @@ chtype attr; /***********************************************************************/ { extern unsigned char atrtab[MAX_ATRTAB]; - int phys_attr=chtype_attr(attr); + int phys_attr = chtype_attr(attr); #ifndef EMXVIDEO - USHORT ch=(phys_attr | SP->blank); + USHORT ch = (phys_attr | SP->blank); #endif - PDC_LOG(("PDC_scroll() - called: urow %d lcol %d lrow %d rcol %d nlines %d\n",urow,lcol,lrow,rcol,nlines)); + PDC_LOG(("PDC_scroll() - called: urow %d lcol %d lrow %d rcol %d nlines %d\n", + urow, lcol, lrow, rcol, nlines)); #ifdef EMXVIDEO - v_attrib (phys_attr); + v_attrib(phys_attr); + if (nlines > 0) - v_scroll (lcol, urow, rcol, lrow, nlines, V_SCROLL_UP); + v_scroll(lcol, urow, rcol, lrow, nlines, V_SCROLL_UP); else if (nlines < 0) - v_scroll (lcol, urow, rcol, lrow, -nlines, V_SCROLL_DOWN); + v_scroll(lcol, urow, rcol, lrow, -nlines, + V_SCROLL_DOWN); else /* this clears the whole screen */ - v_scroll (lcol, urow, rcol, lrow, -1, V_SCROLL_CLEAR); + v_scroll(lcol, urow, rcol, lrow, -1, V_SCROLL_CLEAR); #else if (nlines > 0) VioScrollUp(urow, lcol, lrow, rcol, nlines, (PBYTE)&ch, 0); else if (nlines < 0) - VioScrollDn(urow, lcol, lrow, rcol, nlines, (PBYTE)&ch, 0); - else -/* this clears the whole screen ?? */ + VioScrollDn(urow, lcol, lrow, rcol, nlines, + (PBYTE)&ch, 0); + else /* this clears the whole screen ?? */ VioScrollUp(0, 0, -1, -1, -1, (PBYTE)&ch, 0); #endif - return(OK); + return OK; } /*man-start********************************************************************* @@ -451,95 +468,91 @@ chtype attr; PDC_transform_line() - display a physical line of the screen PDCurses Description: - This is a private PDCurses function. + This is a private PDCurses function. - Updates the given physical line to look like the corresponding - line in _curscr. + Updates the given physical line to look like the corresponding + line in _curscr. PDCurses Return Value: - This routine returns TRUE if a premature refresh end - is allowed, and there is an input character pending. Otherwise, - FALSE is returned. + This routine returns TRUE if a premature refresh end is allowed, + and there is an input character pending. Otherwise, FALSE is + returned. PDCurses Errors: - No errors are defined for this routine. + No errors are defined for this routine. Portability: - PDCurses bool PDC_transform_line( int lineno ); + PDCurses bool PDC_transform_line(int lineno); **man-end**********************************************************************/ /***********************************************************************/ #ifdef HAVE_PROTO -bool PDC_transform_line(register int lineno) +bool PDC_transform_line(int lineno) #else bool PDC_transform_line(lineno) -register int lineno; +int lineno; #endif /***********************************************************************/ { -register chtype* dstp=NULL; -register chtype* srcp=NULL; + chtype *srcp; + int j, x, endx, len; - int x=0; - int endx=0; - int len=0; extern unsigned char atrtab[MAX_ATRTAB]; - unsigned short temp_line[256]; /* this should be enough for the maximum width of a screen. MH-920715 */ - unsigned short chr=0; - unsigned short* ch=NULL; + /* this should be enough for the maximum width of a screen. */ - register int j=0; - bool rc=FALSE; + unsigned short temp_line[256]; + unsigned short chr; + unsigned short *ch; - PDC_LOG(("PDC_transform_line() - called: line %d\n",lineno)); + PDC_LOG(("PDC_transform_line() - called: line %d\n", lineno)); if (curscr == (WINDOW *)NULL) - return( FALSE ); + return FALSE; x = curscr->_firstch[lineno]; endx = curscr->_lastch[lineno]; - dstp = curscr->_y[lineno] + x; srcp = curscr->_y[lineno] + x; - len = endx-x+1; + len = endx - x + 1; - ch = temp_line; /* now have ch pointing to area to contain real attributes. MH-920715 */ + /* now have ch pointing to area to contain real attributes. + MH-920715 */ -/* replace the attribute part of the chtype with the actual colour value */ -/* replacing the number that points to the actual colour value. */ + ch = temp_line; - for (j=0;jdirect_video) - { #ifdef EMXVIDEO - v_putline ((char*)ch, x, lineno, len); + v_putline((char*)ch, x, lineno, len); #else - VioWrtCellStr ((PCH)ch, (USHORT)(len*sizeof(unsigned short)), (USHORT)lineno, (USHORT)x, 0); + VioWrtCellStr((PCH)ch, (USHORT)(len * sizeof(unsigned short)), + (USHORT)lineno, (USHORT)x, 0); #endif - } else - { for (; x <= endx; x++) { PDC_gotoxy(lineno, x); - PDC_putc( (*ch & A_CHARTEXT),(*ch & A_ATTRIBUTES) >> 8 ); + PDC_putc((*ch & A_CHARTEXT), + (*ch & A_ATTRIBUTES) >> 8); ch++; } - } + curscr->_firstch[lineno] = _NO_CHANGE; curscr->_lastch[lineno] = _NO_CHANGE; - if (SP->refrbrk && (SP->cbreak || SP->raw_inp)) - { - rc = PDC_breakout(); - if(rc) - return(TRUE); - } - return(FALSE); + if (SP->refrbrk && (SP->cbreak || SP->raw_inp) && PDC_breakout()) + return TRUE; + + return FALSE; } diff --git a/os2/pdcgetsc.c b/os2/pdcgetsc.c index 9a0ca653..33590934 100644 --- a/os2/pdcgetsc.c +++ b/os2/pdcgetsc.c @@ -19,12 +19,12 @@ */ #define CURSES_LIBRARY 1 #ifdef HAVE_CONFIG_H -# include +# include #endif #include #ifdef PDCDEBUG -char *rcsid_PDCgetsc = "$Id: pdcgetsc.c,v 1.7 2006/01/03 19:54:29 wmcbrine Exp $"; +char *rcsid_PDCgetsc = "$Id: pdcgetsc.c,v 1.8 2006/01/08 11:53:42 wmcbrine Exp $"; #endif /*man-start********************************************************************* @@ -32,21 +32,21 @@ char *rcsid_PDCgetsc = "$Id: pdcgetsc.c,v 1.7 2006/01/03 19:54:29 wmcbrine Exp PDC_get_cursor_pos() - return current cursor position PDCurses Description: - This is a private PDCurses function + This is a private PDCurses function - Gets the cursor position in video page 0. 'row' and 'column' - are the cursor address. At this time, there is no support for - use of multiple screen pages. + Gets the cursor position in video page 0. 'row' and 'column' + are the cursor address. At this time, there is no support for + use of multiple screen pages. PDCurses Return Value: - This routine will return OK upon success and otherwise ERR will be - returned. + This routine will return OK upon success and otherwise ERR will + be returned. PDCurses Errors: - There are no defined errors for this routine. + There are no defined errors for this routine. Portability: - PDCurses int PDC_get_cursor_pos( int* row, int* col ); + PDCurses int PDC_get_cursor_pos(int *row, int *col); **man-end**********************************************************************/ @@ -54,14 +54,14 @@ char *rcsid_PDCgetsc = "$Id: pdcgetsc.c,v 1.7 2006/01/03 19:54:29 wmcbrine Exp int PDC_get_cursor_pos(int *row, int *col) /***********************************************************************/ { - PDC_LOG(("PDC_get_cursor_pos() - called\n")); + PDC_LOG(("PDC_get_cursor_pos() - called\n")); #ifdef EMXVIDEO - v_getxy (col, row); + v_getxy(col, row); #else - VioGetCurPos((PUSHORT)row,(PUSHORT)col,0); + VioGetCurPos((PUSHORT)row, (PUSHORT)col, 0); #endif - return( OK ); + return OK; } /*man-start********************************************************************* @@ -69,20 +69,20 @@ int PDC_get_cursor_pos(int *row, int *col) PDC_get_cur_col() - get current column position of cursor PDCurses Description: - This is a private PDCurses function + This is a private PDCurses function - This routine returns the current column position of the cursor on - screen. + This routine returns the current column position of the cursor + on screen. PDCurses Return Value: - This routine returns the current column position of the cursor. No - error is returned. + This routine returns the current column position of the cursor. + No error is returned. PDCurses Errors: - There are no defined errors for this routine. + There are no defined errors for this routine. Portability: - PDCurses int PDC_get_cur_col( void ); + PDCurses int PDC_get_cur_col(void); **man-end**********************************************************************/ @@ -91,19 +91,20 @@ int PDC_get_cur_col(void) /***********************************************************************/ { #ifdef EMXVIDEO - int curCol=0, curRow=0; + int curCol = 0, curRow = 0; #else - USHORT curCol=0, curRow=0; + USHORT curCol = 0, curRow = 0; #endif - PDC_LOG(("PDC_get_cur_col() - called\n")); + PDC_LOG(("PDC_get_cur_col() - called\n")); + + /* find the current cursor position */ - /* find the current cursor position */ #ifdef EMXVIDEO - v_getxy (&curCol, &curRow); + v_getxy(&curCol, &curRow); #else - VioGetCurPos ((PUSHORT) &curRow, (PUSHORT) &curCol, 0); + VioGetCurPos((PUSHORT)&curRow, (PUSHORT)&curCol, 0); #endif - return (curCol); + return curCol; } /*man-start********************************************************************* @@ -111,20 +112,20 @@ int PDC_get_cur_col(void) PDC_get_cur_row() - get current row position of cursor PDCurses Description: - This is a private PDCurses function + This is a private PDCurses function - This routine returns the current row position of the cursor on - screen. + This routine returns the current row position of the cursor on + screen. PDCurses Return Value: - This routine returns the current row position of the cursor. No - error is returned. + This routine returns the current row position of the cursor. No + error is returned. PDCurses Errors: - There are no defined errors for this routine. + There are no defined errors for this routine. Portability: - PDCurses int PDC_get_cur_row( void ); + PDCurses int PDC_get_cur_row(void); **man-end**********************************************************************/ @@ -133,19 +134,20 @@ int PDC_get_cur_row(void) /***********************************************************************/ { #ifdef EMXVIDEO - int curCol=0, curRow=0; + int curCol = 0, curRow = 0; #else - USHORT curCol=0, curRow=0; + USHORT curCol = 0, curRow = 0; #endif - PDC_LOG(("PDC_get_cur_row() - called\n")); + PDC_LOG(("PDC_get_cur_row() - called\n")); + + /* find the current cursor position */ - /* find the current cursor position */ #ifdef EMXVIDEO - v_getxy (&curCol, &curRow); + v_getxy(&curCol, &curRow); #else - VioGetCurPos ((PUSHORT) &curRow, (PUSHORT) &curCol, 0); + VioGetCurPos((PUSHORT)&curRow, (PUSHORT)&curCol, 0); #endif - return (curRow); + return curRow; } /*man-start********************************************************************* @@ -153,19 +155,20 @@ int PDC_get_cur_row(void) PDC_get_attribute() - Get attribute at current cursor PDCurses Description: - This is a private PDCurses function + This is a private PDCurses function - Return the current attr at current cursor position on the screen. + Return the current attr at current cursor position on the + screen. PDCurses Return Value: - This routine will return OK upon success and otherwise ERR will be - returned. + This routine will return OK upon success and otherwise ERR will + be returned. PDCurses Errors: - There are no defined errors for this routine. + There are no defined errors for this routine. Portability: - PDCurses int PDC_get_attribute( void ); + PDCurses int PDC_get_attribute(void); **man-end**********************************************************************/ @@ -174,20 +177,22 @@ int PDC_get_attribute(void) /***********************************************************************/ { #ifndef EMXVIDEO - USHORT cellLen = 2; + USHORT cellLen = 2; #endif - int curRow=0, curCol=0; - char Cell[4]; + int curRow = 0, curCol = 0; + char Cell[4]; - PDC_LOG(("PDC_get_attribute() - called\n")); + PDC_LOG(("PDC_get_attribute() - called\n")); + + PDC_get_cursor_pos(&curRow, &curCol); - PDC_get_cursor_pos(&curRow, &curCol); #ifdef EMXVIDEO - v_getline (Cell, curCol, curRow, 1); + v_getline(Cell, curCol, curRow, 1); #else - VioReadCellStr((PCH)&Cell, (PUSHORT)&cellLen, (USHORT)curRow, (USHORT)curCol, 0); + VioReadCellStr((PCH)&Cell, (PUSHORT)&cellLen, (USHORT)curRow, + (USHORT)curCol, 0); #endif - return ((int) Cell[1]); + return (int)Cell[1]; } /*man-start********************************************************************* @@ -195,19 +200,19 @@ int PDC_get_attribute(void) PDC_get_columns() - return width of screen/viewport. PDCurses Description: - This is a private PDCurses function + This is a private PDCurses function - This function will return the width of the current screen. + This function will return the width of the current screen. PDCurses Return Value: - This routine will return OK upon success and otherwise ERR will be - returned. + This routine will return OK upon success and otherwise ERR will + be returned. PDCurses Errors: - There are no defined errors for this routine. + There are no defined errors for this routine. Portability: - PDCurses int PDC_get_columns( void ); + PDCurses int PDC_get_columns(void); **man-end**********************************************************************/ @@ -216,32 +221,30 @@ int PDC_get_columns(void) /***********************************************************************/ { #ifdef EMXVIDEO - int rows=0; + int rows = 0; #else - VIOMODEINFO modeInfo={0}; + VIOMODEINFO modeInfo = {0}; #endif - int cols=0; - char *env_cols=NULL; + int cols = 0; + char *env_cols = NULL; - PDC_LOG(("PDC_get_columns() - called\n")); + PDC_LOG(("PDC_get_columns() - called\n")); #ifdef EMXVIDEO - v_dimen (&cols, &rows); + v_dimen(&cols, &rows); #else - modeInfo.cb = sizeof(modeInfo); - VioGetMode(&modeInfo, 0); - cols = modeInfo.col; + modeInfo.cb = sizeof(modeInfo); + VioGetMode(&modeInfo, 0); + cols = modeInfo.col; #endif + env_cols = (char *)getenv("COLS"); - env_cols = (char *)getenv("COLS"); - if (env_cols != (char *)NULL) - { - cols = min(atoi(env_cols),cols); - } + if (env_cols != (char *)NULL) + cols = min(atoi(env_cols), cols); - PDC_LOG(("PDC_get_columns() - returned: cols %d\n",cols)); + PDC_LOG(("PDC_get_columns() - returned: cols %d\n", cols)); - return(cols); + return cols; } /*man-start********************************************************************* @@ -249,17 +252,18 @@ int PDC_get_columns(void) PDC_get_cursor_mode() - Get the cursor start and stop scan lines. PDCurses Description: - Gets the cursor type to begin in scan line startrow and end in - scan line endrow. Both values should be 0-31. + Gets the cursor type to begin in scan line startrow and end in + scan line endrow. Both values should be in the range 0 through + 31. PDCurses Return Value: - This function returns OK on success and ERR on error. + This function returns OK on success and ERR on error. PDCurses Errors: - No errors are defined for this function. + No errors are defined for this function. Portability: - PDCurses int PDC_get_cursor_mode( void ); + PDCurses int PDC_get_cursor_mode(void); **man-end**********************************************************************/ @@ -268,23 +272,22 @@ int PDC_get_cursor_mode(void) /***********************************************************************/ { #ifdef EMXVIDEO - int curstart=0, curend=0; + int curstart = 0, curend = 0; #else - VIOCURSORINFO cursorInfo; + VIOCURSORINFO cursorInfo; #endif - short cmode=0; - - PDC_LOG(("PDC_get_cursor_mode() - called\n")); + PDC_LOG(("PDC_get_cursor_mode() - called\n")); #ifdef EMXVIDEO - v_getctype (&curstart, &curend); - cmode = ((curstart << 8) | (curend)); + v_getctype(&curstart, &curend); + return (curstart << 8) | curend; #else - VioGetCurType (&cursorInfo, 0); -/* I am not sure about this JGB */ - cmode = ((cursorInfo.yStart << 8) | (cursorInfo.cEnd)); + VioGetCurType (&cursorInfo, 0); + + /* I am not sure about this JGB */ + + return (cursorInfo.yStart << 8) | cursorInfo.cEnd; #endif - return(cmode); } /*man-start********************************************************************* @@ -292,19 +295,19 @@ int PDC_get_cursor_mode(void) PDC_get_font() - Get the current font size PDCurses Description: - This is a private PDCurses routine. + This is a private PDCurses routine. - This function returns the current font size. This function only - works if the #define FAST_VIDEO is true. + This function returns the current font size. This function only + works if the #define FAST_VIDEO is true. PDCurses Return Value: - This function returns OK on success and ERR on error. + This function returns OK on success and ERR on error. PDCurses Errors: - An ERR will be returned if FAST_VIDEO is not true. + An ERR will be returned if FAST_VIDEO is not true. Portability: - PDCurses int PDC_get_font( void ); + PDCurses int PDC_get_font(void); **man-end**********************************************************************/ @@ -313,21 +316,22 @@ int PDC_get_font(void) /***********************************************************************/ { #ifdef EMXVIDEO - int retval=0; + int retval; #else - VIOMODEINFO modeInfo={0}; + VIOMODEINFO modeInfo = {0}; #endif - - PDC_LOG(("PDC_get_font() - called\n")); + PDC_LOG(("PDC_get_font() - called\n")); #ifdef EMXVIDEO - retval = v_hardware(); - return (retval == V_MONOCHROME) ? 14 : (retval == V_COLOR_8) ? 8 : 12; + retval = v_hardware(); + return (retval == V_MONOCHROME) ? 14 : (retval == V_COLOR_8) ? 8 : 12; #else - modeInfo.cb = sizeof(modeInfo); - /* set most parameters of modeInfo */ - VioGetMode(&modeInfo, 0); - return ( modeInfo.vres / modeInfo.row); + modeInfo.cb = sizeof(modeInfo); + + /* set most parameters of modeInfo */ + + VioGetMode(&modeInfo, 0); + return (modeInfo.vres / modeInfo.row); #endif } @@ -336,19 +340,19 @@ int PDC_get_font(void) PDC_get_rows() - Return number of screen rows. PDCurses Description: - This is a private PDCurses routine. + This is a private PDCurses routine. - Returns the maximum number of rows supported by the display. - e.g. 25, 28, 43, 50, 60, 66... + Returns the maximum number of rows supported by the display. + e.g. 25, 28, 43, 50, 60, 66... PDCurses Return Value: - This function returns OK on success and ERR on error. + This function returns OK on success and ERR on error. PDCurses Errors: - No errors are defined for this function. + No errors are defined for this function. Portability: - PDCurses int PDC_get_rows( void ); + PDCurses int PDC_get_rows(void); **man-end**********************************************************************/ @@ -357,31 +361,33 @@ int PDC_get_rows(void) /***********************************************************************/ { #ifdef EMXVIDEO - int cols=0; + int cols = 0; #else - VIOMODEINFO modeInfo={0}; + VIOMODEINFO modeInfo = {0}; #endif - int rows=0; - char *env_rows=NULL; + int rows = 0; + char *env_rows = NULL; - PDC_LOG(("PDC_get_rows() - called\n")); + PDC_LOG(("PDC_get_rows() - called\n")); + + /* use the value from LINES environment variable, if set. MH 10-Jun-92 */ + /* and use the minimum of LINES and *ROWS. MH 18-Jun-92 */ -/* use the value from LINES environment variable, if set. MH 10-Jun-92 */ -/* and use the minimum of LINES and *ROWS. MH 18-Jun-92 */ #ifdef EMXVIDEO - v_dimen (&cols, &rows); + v_dimen(&cols, &rows); #else - modeInfo.cb = sizeof(modeInfo); - VioGetMode(&modeInfo, 0); - rows = modeInfo.row; + modeInfo.cb = sizeof(modeInfo); + VioGetMode(&modeInfo, 0); + rows = modeInfo.row; #endif - env_rows = (char *)getenv("LINES"); - if (env_rows != (char *)NULL) - rows = min(atoi(env_rows),rows); + env_rows = (char *)getenv("LINES"); - PDC_LOG(("PDC_get_rows() - returned: rows %d\n",rows)); + if (env_rows != (char *)NULL) + rows = min(atoi(env_rows), rows); - return(rows); + PDC_LOG(("PDC_get_rows() - returned: rows %d\n", rows)); + + return rows; } /*man-start********************************************************************* @@ -389,34 +395,35 @@ int PDC_get_rows(void) PDC_get_scrn_mode() - Return the current BIOS video mode PDCurses Description: - This is a private PDCurses routine. + This is a private PDCurses routine. PDCurses Return Value: - Returns the current BIOS Video Mode Number. + Returns the current BIOS Video Mode Number. PDCurses Errors: - The EMXVIDEO version of this routine returns an ERR. + The EMXVIDEO version of this routine returns an ERR. Portability: - PDCurses int PDC_get_scrn_mode( void ); + PDCurses int PDC_get_scrn_mode(void); **man-end**********************************************************************/ /***********************************************************************/ #if defined(EMXVIDEO) -int PDC_get_scrn_mode( void ) +int PDC_get_scrn_mode(void) #else -int PDC_get_scrn_mode( VIOMODEINFO *modeinfo ) +int PDC_get_scrn_mode(VIOMODEINFO *modeinfo) #endif /***********************************************************************/ { - PDC_LOG(("PDC_get_scrn_mode() - called\n")); + PDC_LOG(("PDC_get_scrn_mode() - called\n")); + #ifdef EMXVIDEO - return(ERR); + return ERR; #else - VioGetMode ( modeinfo, 0 ); - return(OK); + VioGetMode(modeinfo, 0); + return OK; #endif } @@ -425,38 +432,38 @@ int PDC_get_scrn_mode( VIOMODEINFO *modeinfo ) PDC_query_adapter_type() - Determine PC video adapter type PDCurses Description: - This is a private PDCurses routine. + This is a private PDCurses routine. - Thanks to Jeff Duntemann, K16RA for providing the impetus - (through the Dr. Dobbs Journal, March 1989 issue) for getting - the routines below merged into Bjorn Larsson's PDCurses 1.3... - -- frotz@dri.com 900730 + Thanks to Jeff Duntemann, K16RA for providing the impetus + (through the Dr. Dobbs Journal, March 1989 issue) for getting + the routines below merged into Bjorn Larsson's PDCurses 1.3... + -- frotz@dri.com 900730 PDCurses Return Value: - This function returns a macro identifier indicating the adapter - type. See the list of adapter types in CURSPRIV.H. + This function returns a macro identifier indicating the adapter + type. See the list of adapter types in CURSPRIV.H. PDCurses Errors: - No errors are defined for this function. + No errors are defined for this function. Portability: - PDCurses int PDC_query_adapter_type( void ); + PDCurses int PDC_query_adapter_type(void); **man-end**********************************************************************/ /***********************************************************************/ #if defined(EMXVIDEO) -int PDC_query_adapter_type( void ) +int PDC_query_adapter_type(void) #else -int PDC_query_adapter_type( VIOCONFIGINFO *configinfo ) +int PDC_query_adapter_type(VIOCONFIGINFO *configinfo) #endif /***********************************************************************/ { - PDC_LOG(("PDC_query_adapter_type() - called\n")); + PDC_LOG(("PDC_query_adapter_type() - called\n")); #ifdef EMXVIDEO - return (v_hardware() == V_MONOCHROME) ? _UNIX_MONO : _UNIX_COLOR; + return (v_hardware() == V_MONOCHROME) ? _UNIX_MONO : _UNIX_COLOR; #else - VioGetConfig( 0, configinfo, 0 ); - return(OK); + VioGetConfig(0, configinfo, 0); + return OK; #endif } diff --git a/os2/pdckbd.c b/os2/pdckbd.c index 6b64204c..f891df1e 100644 --- a/os2/pdckbd.c +++ b/os2/pdckbd.c @@ -33,121 +33,117 @@ #endif #ifdef PDCDEBUG -char *rcsid_PDCkbd = "$Id: pdckbd.c,v 1.9 2006/01/03 19:54:29 wmcbrine Exp $"; +char *rcsid_PDCkbd = "$Id: pdckbd.c,v 1.10 2006/01/08 11:53:42 wmcbrine Exp $"; #endif -/******************************************************************************* +/****************************************************************************** * Table for key code translation of function keys in keypad mode * These values are for strict IBM keyboard compatibles only -*******************************************************************************/ +******************************************************************************/ static int kptab[] = { - /* Normal Function Keys */ - 0x3b, KEY_F(1), 0x3c, KEY_F(2), 0x3d, KEY_F(3), 0x3e, KEY_F(4), - 0x3f, KEY_F(5), 0x40, KEY_F(6), 0x41, KEY_F(7), 0x42, KEY_F(8), - 0x43, KEY_F(9), 0x44, KEY_F(10), + /* Normal Function Keys */ + 0x3b, KEY_F(1), 0x3c, KEY_F(2), 0x3d, KEY_F(3), 0x3e, KEY_F(4), + 0x3f, KEY_F(5), 0x40, KEY_F(6), 0x41, KEY_F(7), 0x42, KEY_F(8), + 0x43, KEY_F(9), 0x44, KEY_F(10), - /* Normal Keypad */ - 0x47, KEY_HOME, 0x48, KEY_UP, 0x49, KEY_PPAGE, - 0x4b, KEY_LEFT, 0x4c, KEY_B2, 0x4d, KEY_RIGHT, - 0x4f, KEY_END, 0x50, KEY_DOWN, 0x51, KEY_NPAGE, - 0x52, KEY_IC, 0x53, KEY_DC, + /* Normal Keypad */ + 0x47, KEY_HOME, 0x48, KEY_UP, 0x49, KEY_PPAGE, 0x4b, KEY_LEFT, + 0x4c, KEY_B2, 0x4d, KEY_RIGHT, 0x4f, KEY_END, 0x50, KEY_DOWN, + 0x51, KEY_NPAGE, 0x52, KEY_IC, 0x53, KEY_DC, - /* Shifted Keypad */ - 0xb0, KEY_SHOME, 0xb1, KEY_SUP, 0xb2, KEY_SPREVIOUS, - 0xb3, KEY_SLEFT, 0xb4, KEY_SRIGHT, - 0xb5, KEY_SEND, 0xb6, KEY_SDOWN, 0xb7, KEY_SNEXT, - 0xb8, KEY_SIC, 0xb9, KEY_SDC, + /* Shifted Keypad */ + 0xb0, KEY_SHOME, 0xb1, KEY_SUP, 0xb2, KEY_SPREVIOUS, + 0xb3, KEY_SLEFT, 0xb4, KEY_SRIGHT, 0xb5, KEY_SEND, + 0xb6, KEY_SDOWN, 0xb7, KEY_SNEXT, 0xb8, KEY_SIC, 0xb9, KEY_SDC, - /* Shft-Function Keys */ - 0x54, KEY_F(13), 0x55, KEY_F(14), 0x56, KEY_F(15), 0x57, KEY_F(16), - 0x58, KEY_F(17), 0x59, KEY_F(18), 0x5a, KEY_F(19), 0x5b, KEY_F(20), - 0x5c, KEY_F(21), 0x5d, KEY_F(22), + /* Shft-Function Keys */ + 0x54, KEY_F(13), 0x55, KEY_F(14), 0x56, KEY_F(15), 0x57, KEY_F(16), + 0x58, KEY_F(17), 0x59, KEY_F(18), 0x5a, KEY_F(19), 0x5b, KEY_F(20), + 0x5c, KEY_F(21), 0x5d, KEY_F(22), - /* Ctl-Function Keys */ - 0x5e, KEY_F(25), 0x5f, KEY_F(26), 0x60, KEY_F(27), 0x61, KEY_F(28), - 0x62, KEY_F(29), 0x63, KEY_F(30), 0x64, KEY_F(31), 0x65, KEY_F(32), - 0x66, KEY_F(33), 0x67, KEY_F(34), + /* Ctl-Function Keys */ + 0x5e, KEY_F(25), 0x5f, KEY_F(26), 0x60, KEY_F(27), 0x61, KEY_F(28), + 0x62, KEY_F(29), 0x63, KEY_F(30), 0x64, KEY_F(31), 0x65, KEY_F(32), + 0x66, KEY_F(33), 0x67, KEY_F(34), - /* Alt-Function Keys */ - 0x68, KEY_F(37), 0x69, KEY_F(38), 0x6a, KEY_F(39), 0x6b, KEY_F(40), - 0x6c, KEY_F(41), 0x6d, KEY_F(42), 0x6e, KEY_F(43), 0x6f, KEY_F(44), - 0x70, KEY_F(45), 0x71, KEY_F(46), + /* Alt-Function Keys */ + 0x68, KEY_F(37), 0x69, KEY_F(38), 0x6a, KEY_F(39), 0x6b, KEY_F(40), + 0x6c, KEY_F(41), 0x6d, KEY_F(42), 0x6e, KEY_F(43), 0x6f, KEY_F(44), + 0x70, KEY_F(45), 0x71, KEY_F(46), - /* Control-Keypad */ - 0x77, CTL_HOME, 0x84, CTL_PGUP, - 0x73, CTL_LEFT, 0x74, CTL_RIGHT, - 0x75, CTL_END, 0x76, CTL_PGDN, + /* Control-Keypad */ + 0x77, CTL_HOME, 0x84, CTL_PGUP, 0x73, CTL_LEFT, + 0x74, CTL_RIGHT, 0x75, CTL_END, 0x76, CTL_PGDN, - /* Alt-Numbers */ - 0x78, ALT_1, 0x79, ALT_2, 0x7a, ALT_3, 0x7b, ALT_4, - 0x7c, ALT_5, 0x7d, ALT_6, 0x7e, ALT_7, 0x7f, ALT_8, - 0x80, ALT_9, 0x81, ALT_0, + /* Alt-Numbers */ + 0x78, ALT_1, 0x79, ALT_2, 0x7a, ALT_3, 0x7b, ALT_4, 0x7c, ALT_5, + 0x7d, ALT_6, 0x7e, ALT_7, 0x7f, ALT_8, 0x80, ALT_9, 0x81, ALT_0, - /* Extended codes */ - 0x85, KEY_F(11), 0x86, KEY_F(12), 0x87, KEY_F(23), 0x88, KEY_F(24), - 0x89, KEY_F(35), 0x8a, KEY_F(36), 0x8b, KEY_F(47), 0x8c, KEY_F(48), - 0x03, 0, /* NULL */ + /* Extended codes */ + 0x85, KEY_F(11), 0x86, KEY_F(12), 0x87, KEY_F(23), 0x88, KEY_F(24), + 0x89, KEY_F(35), 0x8a, KEY_F(36), 0x8b, KEY_F(47), 0x8c, KEY_F(48), + 0x03, 0, /* NULL */ #if defined(NUMKEYPAD) - 0xff, (int)'/', 0x0d, (int)'\n', - 0xfa, (int)'*', 0xfd, (int)'-', 0xfb, (int)'+', + 0xff, (int)'/', 0x0d, (int)'\n', + 0xfa, (int)'*', 0xfd, (int)'-', 0xfb, (int)'+', #else - 0xff, PADSLASH, 0x0d, PADENTER, - 0xfa, PADSTAR, 0xfd, PADMINUS, 0xfb, PADPLUS, + 0xff, PADSLASH, 0x0d, PADENTER, + 0xfa, PADSTAR, 0xfd, PADMINUS, 0xfb, PADPLUS, #endif - 0x0a, CTL_PADENTER, - 0xa6, ALT_PADENTER, 0x53, (int)'.', 0xfc, CTL_ENTER, - 0x93, CTL_DEL, 0x8f, CTL_PADCENTER, 0x90, CTL_PADPLUS, - 0x8e, CTL_PADMINUS, 0x95, CTL_PADSLASH, 0x96, CTL_PADSTAR, - 0x4e, ALT_PADPLUS, 0x4a, ALT_PADMINUS, 0xa4, ALT_PADSLASH, - 0x37, ALT_PADSTAR, 0x92, CTL_INS, 0xa2, ALT_INS, - 0xa3, ALT_DEL, 0x8d, CTL_UP, 0x91, CTL_DOWN, - 0x94, CTL_TAB, 0xa5, ALT_TAB, 0x82, ALT_MINUS, - 0x83, ALT_EQUAL, 0x99, ALT_PGUP, 0xa1, ALT_PGDN, - 0x9f, ALT_END, 0x98, ALT_UP, 0xa0, ALT_DOWN, - 0x9d, ALT_RIGHT, 0x9b, ALT_LEFT, 0x1c, ALT_ENTER, - 0x97, ALT_HOME, 0x01, ALT_ESC, 0x0e, ALT_BKSP, - 0x29, ALT_BQUOTE, 0x1a, ALT_LBRACKET, 0x1b, ALT_RBRACKET, - 0x27, ALT_SEMICOLON,0x28, ALT_FQUOTE, 0x33, ALT_COMMA, - 0x34, ALT_STOP, 0x35, ALT_FSLASH, 0x2b, ALT_BSLASH, + 0x0a, CTL_PADENTER, + 0xa6, ALT_PADENTER, 0x53, (int)'.', 0xfc, CTL_ENTER, + 0x93, CTL_DEL, 0x8f, CTL_PADCENTER, 0x90, CTL_PADPLUS, + 0x8e, CTL_PADMINUS, 0x95, CTL_PADSLASH, 0x96, CTL_PADSTAR, + 0x4e, ALT_PADPLUS, 0x4a, ALT_PADMINUS, 0xa4, ALT_PADSLASH, + 0x37, ALT_PADSTAR, 0x92, CTL_INS, 0xa2, ALT_INS, + 0xa3, ALT_DEL, 0x8d, CTL_UP, 0x91, CTL_DOWN, + 0x94, CTL_TAB, 0xa5, ALT_TAB, 0x82, ALT_MINUS, + 0x83, ALT_EQUAL, 0x99, ALT_PGUP, 0xa1, ALT_PGDN, + 0x9f, ALT_END, 0x98, ALT_UP, 0xa0, ALT_DOWN, + 0x9d, ALT_RIGHT, 0x9b, ALT_LEFT, 0x1c, ALT_ENTER, + 0x97, ALT_HOME, 0x01, ALT_ESC, 0x0e, ALT_BKSP, + 0x29, ALT_BQUOTE, 0x1a, ALT_LBRACKET, 0x1b, ALT_RBRACKET, + 0x27, ALT_SEMICOLON,0x28, ALT_FQUOTE, 0x33, ALT_COMMA, + 0x34, ALT_STOP, 0x35, ALT_FSLASH, 0x2b, ALT_BSLASH, - /* Alt-Alphabet */ - 0x1e, ALT_A, 0x30, ALT_B, 0x2e, ALT_C, 0x20, ALT_D, - 0x12, ALT_E, 0x21, ALT_F, 0x22, ALT_G, 0x23, ALT_H, - 0x17, ALT_I, 0x24, ALT_J, 0x25, ALT_K, 0x26, ALT_L, - 0x32, ALT_M, 0x31, ALT_N, 0x18, ALT_O, 0x19, ALT_P, - 0x10, ALT_Q, 0x13, ALT_R, 0x1f, ALT_S, 0x14, ALT_T, - 0x16, ALT_U, 0x2f, ALT_V, 0x11, ALT_W, 0x2d, ALT_X, - 0x15, ALT_Y, 0x2c, ALT_Z, - 0x0f, KEY_BTAB, - 0x100, (-1) + /* Alt-Alphabet */ + 0x1e, ALT_A, 0x30, ALT_B, 0x2e, ALT_C, 0x20, ALT_D, + 0x12, ALT_E, 0x21, ALT_F, 0x22, ALT_G, 0x23, ALT_H, + 0x17, ALT_I, 0x24, ALT_J, 0x25, ALT_K, 0x26, ALT_L, + 0x32, ALT_M, 0x31, ALT_N, 0x18, ALT_O, 0x19, ALT_P, + 0x10, ALT_Q, 0x13, ALT_R, 0x1f, ALT_S, 0x14, ALT_T, + 0x16, ALT_U, 0x2f, ALT_V, 0x11, ALT_W, 0x2d, ALT_X, + 0x15, ALT_Y, 0x2c, ALT_Z, 0x0f, KEY_BTAB, 0x100, -1 }; - /* End of kptab[] */ -static unsigned long pdc_key_modifiers=0L; +/* End of kptab[] */ + +static unsigned long pdc_key_modifiers = 0L; + MOUSE_STATUS Trapped_Mouse_status; /*man-start********************************************************************* - PDC_get_input_fd() - Get file descriptor used for PDCurses input + PDC_get_input_fd() - Get file descriptor used for PDCurses input PDCurses Description: - This is a private PDCurses routine. + This is a private PDCurses routine. - This routine will return the file descriptor that PDCurses reads - its input from. It can be used for select(). + This routine will return the file descriptor that PDCurses reads + its input from. It can be used for select(). PDCurses Return Value: - Returns a file descriptor. + Returns a file descriptor. PDCurses Errors: - No errors are defined for this function. + No errors are defined for this function. Portability: - PDCurses int PDC_get_input_fd( void ); + PDCurses int PDC_get_input_fd(void); **man-end**********************************************************************/ @@ -155,81 +151,92 @@ MOUSE_STATUS Trapped_Mouse_status; unsigned long PDC_get_input_fd(void) /***********************************************************************/ { - PDC_LOG(("PDC_get_input_fd() - called\n")); + PDC_LOG(("PDC_get_input_fd() - called\n")); - return (unsigned long)fileno(stdin); + return (unsigned long)fileno(stdin); } #ifndef EMXVIDEO /***********************************************************************/ -int PDC_get_keyboard_info( KBDINFO *kbdinfo ) +int PDC_get_keyboard_info(KBDINFO *kbdinfo) /***********************************************************************/ { - KBDINFO akbdinfo; + KBDINFO akbdinfo; - PDC_LOG(("PDC_get_keyboard_info() - called\n")); + PDC_LOG(("PDC_get_keyboard_info() - called\n")); - akbdinfo.cb = sizeof(akbdinfo); - KbdGetStatus( &akbdinfo, 0 ); - *kbdinfo = akbdinfo; + akbdinfo.cb = sizeof(akbdinfo); + KbdGetStatus(&akbdinfo, 0); + *kbdinfo = akbdinfo; - PDC_LOG(("PDC_get_keyboard_info(). cb: %x, fsMask: %x, chTurnAround: %x, fsInterim: %x, fsState: %x\n", kbdinfo->cb, kbdinfo->fsMask, kbdinfo->chTurnAround, kbdinfo->fsInterim, kbdinfo->fsState)); + PDC_LOG(("PDC_get_keyboard_info(). cb: %x, fsMask: %x, chTurnAround: %x, fsInterim: %x, fsState: %x\n", + kbdinfo->cb, kbdinfo->fsMask, kbdinfo->chTurnAround, + kbdinfo->fsInterim, kbdinfo->fsState)); - return OK; + return OK; } /***********************************************************************/ -int PDC_set_keyboard_binary( void ) +int PDC_set_keyboard_binary(void) /***********************************************************************/ { - KBDINFO kbdinfo; + KBDINFO kbdinfo; - PDC_LOG(("PDC_set_keyboard_binary() - called\n")); + PDC_LOG(("PDC_set_keyboard_binary() - called\n")); - kbdinfo.cb = sizeof(kbdinfo); - KbdGetStatus( &kbdinfo, 0); + kbdinfo.cb = sizeof(kbdinfo); + KbdGetStatus(&kbdinfo, 0); - PDC_LOG(("PDC_set_keyboard_binary() - before. cb: %x, fsMask: %x, chTurnAround: %x, fsInterim: %x, fsState: %x\n", kbdinfo.cb, kbdinfo.fsMask, kbdinfo.chTurnAround, kbdinfo.fsInterim, kbdinfo.fsState)); + PDC_LOG(("PDC_set_keyboard_binary() - before. cb: %x, fsMask: %x, chTurnAround: %x, fsInterim: %x, fsState: %x\n", + kbdinfo.cb, kbdinfo.fsMask, kbdinfo.chTurnAround, + kbdinfo.fsInterim, kbdinfo.fsState)); - kbdinfo.fsMask = (kbdinfo.fsMask & ~KEYBOARD_ASCII_MODE) | KEYBOARD_BINARY_MODE; - KbdSetStatus( &kbdinfo, 0 ); + kbdinfo.fsMask = (kbdinfo.fsMask & ~KEYBOARD_ASCII_MODE) | + KEYBOARD_BINARY_MODE; + KbdSetStatus(&kbdinfo, 0); - PDC_LOG(("PDC_set_keyboard_binary() - after. cb: %x, fsMask: %x, chTurnAround: %x, fsInterim: %x, fsState: %x\n", kbdinfo.cb, kbdinfo.fsMask, kbdinfo.chTurnAround, kbdinfo.fsInterim, kbdinfo.fsState)); + PDC_LOG(("PDC_set_keyboard_binary() - after. cb: %x, fsMask: %x, chTurnAround: %x, fsInterim: %x, fsState: %x\n", + kbdinfo.cb, kbdinfo.fsMask, kbdinfo.chTurnAround, + kbdinfo.fsInterim, kbdinfo.fsState)); - return OK; + return OK; } /***********************************************************************/ -int PDC_set_keyboard_default( void ) +int PDC_set_keyboard_default(void) /***********************************************************************/ { - PDC_LOG(("PDC_set_keyboard_default() - called\n")); + PDC_LOG(("PDC_set_keyboard_default() - called\n")); - PDC_LOG(("PDC_set_keyboard_default(). cb: %x, fsMask: %x, chTurnAround: %x, fsInterim: %x, fsState: %x\n", SP->kbdinfo.cb, SP->kbdinfo.fsMask, SP->kbdinfo.chTurnAround, SP->kbdinfo.fsInterim, SP->kbdinfo.fsState)); + PDC_LOG(("PDC_set_keyboard_default(). cb: %x, fsMask: %x, chTurnAround: %x, fsInterim: %x, fsState: %x\n", + SP->kbdinfo.cb, SP->kbdinfo.fsMask, + SP->kbdinfo.chTurnAround, SP->kbdinfo.fsInterim, + SP->kbdinfo.fsState)); - KbdSetStatus( &SP->kbdinfo, 0 ); - return OK; + KbdSetStatus(&SP->kbdinfo, 0); + + return OK; } -#endif +#endif /* ifndef EMXVIDEO */ /*man-start********************************************************************* PDC_check_bios_key() - Check BIOS key data area for input PDCurses Description: - This is a private PDCurses routine. + This is a private PDCurses routine. - This routine will check the BIOS for any indication that - keystrokes are pending. + This routine will check the BIOS for any indication that + keystrokes are pending. PDCurses Return Value: - Returns 1 if a keyboard character is available, 0 otherwise. + Returns 1 if a keyboard character is available, 0 otherwise. PDCurses Errors: - No errors are defined for this function. + No errors are defined for this function. Portability: - PDCurses bool PDC_check_bios_key( void ); + PDCurses bool PDC_check_bios_key(void); **man-end**********************************************************************/ @@ -238,25 +245,28 @@ bool PDC_check_bios_key(void) /***********************************************************************/ { #if !defined(MSC) && !defined(EMXVIDEO) - KBDKEYINFO keyInfo={0}; + KBDKEYINFO keyInfo = {0}; #endif - - PDC_LOG(("PDC_check_bios_key() - called\n")); + PDC_LOG(("PDC_check_bios_key() - called\n")); #ifdef EMXVIDEO - if (SP->tahead == -1) /* Nothing typed yet */ - { /* See if there's anything */ - SP->tahead = _read_kbd (0, 0, 0); - if (SP->tahead == 0) /* Read additional */ - SP->tahead = (_read_kbd (0, 1, 0) << 8); - } - return(SP->tahead != -1) ? 1 : 0; + if (SP->tahead == -1) /* Nothing typed yet */ + { + SP->tahead = _read_kbd(0, 0, 0); + + /* Read additional */ + + if (SP->tahead == 0) + SP->tahead = _read_kbd(0, 1, 0) << 8; + } + + return (SP->tahead != -1); #else # if !defined(MSC) - KbdPeek(&keyInfo, 0); /* peek at keyboard */ - return (keyInfo.fbStatus != 0); + KbdPeek(&keyInfo, 0); /* peek at keyboard */ + return (keyInfo.fbStatus != 0); # else - return(kbhit()); + return kbhit(); # endif #endif @@ -267,20 +277,20 @@ bool PDC_check_bios_key(void) PDC_get_bios_key() - Returns the next key available from the BIOS. PDCurses Description: - This is a private PDCurses routine. + This is a private PDCurses routine. - Returns the next key code struck at the keyboard. If the low 8 - bits are 0, the upper bits contain the extended character - code. If bit 0-7 are non-zero, the upper bits = 0. + Returns the next key code struck at the keyboard. If the low 8 + bits are 0, the upper bits contain the extended character + code. If bit 0-7 are non-zero, the upper bits = 0. PDCurses Return Value: - This function returns OK on success and ERR on error. + This function returns OK on success and ERR on error. PDCurses Errors: - No errors are defined for this function. + No errors are defined for this function. Portability: - PDCurses int PDC_get_bios_key( void ); + PDCurses int PDC_get_bios_key(void); **man-end**********************************************************************/ @@ -288,84 +298,104 @@ bool PDC_check_bios_key(void) int PDC_get_bios_key(void) /***********************************************************************/ { - int ascii=0,scan=0,key; + int ascii, scan, key; #ifndef EMXVIDEO - KBDKEYINFO keyInfo={0}; + KBDKEYINFO keyInfo = {0}; #endif - - PDC_LOG(("PDC_get_bios_key() - called\n")); + PDC_LOG(("PDC_get_bios_key() - called\n")); #ifdef EMXVIDEO - if (SP->tahead == -1) - { - SP->tahead = _read_kbd (0, 1, 0); - if (SP->tahead == 0) /* Read additional */ - SP->tahead = (_read_kbd (0, 1, 0) << 8); - } - ascii = SP->tahead & 0xff; - scan = SP->tahead >> 8; - pdc_key_modifiers = 0L; - SP->tahead = -1; + if (SP->tahead == -1) + { + SP->tahead = _read_kbd(0, 1, 0); + + /* Read additional */ + + if (SP->tahead == 0) + SP->tahead = _read_kbd(0, 1, 0) << 8; + } + + ascii = SP->tahead & 0xff; + scan = SP->tahead >> 8; + pdc_key_modifiers = 0L; + + SP->tahead = -1; #else -/* PDC_get_keyboard_info( &SP->kbdinfo ); - PDC_set_keyboard_binary(); */ - KbdCharIn(&keyInfo, IO_WAIT, 0); /* get a character */ -/* PDC_set_keyboard_default(); */ - ascii = keyInfo.chChar; - scan = keyInfo.chScan; - pdc_key_modifiers = 0L; - if (SP->save_key_modifiers) - { - if (keyInfo.fsState & KBDSTF_ALT) - pdc_key_modifiers |= PDC_KEY_MODIFIER_ALT; - if (keyInfo.fsState & KBDSTF_CONTROL) - pdc_key_modifiers |= PDC_KEY_MODIFIER_CONTROL; - if (keyInfo.fsState & KBDSTF_NUMLOCK_ON) - pdc_key_modifiers |= PDC_KEY_MODIFIER_NUMLOCK; - if (keyInfo.fsState & KBDSTF_LEFTSHIFT - || keyInfo.fsState & KBDSTF_RIGHTSHIFT) - pdc_key_modifiers |= PDC_KEY_MODIFIER_SHIFT; - } + /* PDC_get_keyboard_info(&SP->kbdinfo); + PDC_set_keyboard_binary(); */ + KbdCharIn(&keyInfo, IO_WAIT, 0); /* get a character */ + /* PDC_set_keyboard_default(); */ + + ascii = keyInfo.chChar; + scan = keyInfo.chScan; + pdc_key_modifiers = 0L; + + if (SP->save_key_modifiers) + { + if (keyInfo.fsState & KBDSTF_ALT) + pdc_key_modifiers |= PDC_KEY_MODIFIER_ALT; + + if (keyInfo.fsState & KBDSTF_CONTROL) + pdc_key_modifiers |= PDC_KEY_MODIFIER_CONTROL; + + if (keyInfo.fsState & KBDSTF_NUMLOCK_ON) + pdc_key_modifiers |= PDC_KEY_MODIFIER_NUMLOCK; + + if (keyInfo.fsState & KBDSTF_LEFTSHIFT + || keyInfo.fsState & KBDSTF_RIGHTSHIFT) + pdc_key_modifiers |= PDC_KEY_MODIFIER_SHIFT; + } #endif - if (scan == 0x1c && ascii == 0x0a) /* ^Enter */ - key = ((int) (0xfc00)); - else if ((scan == 0x03 && ascii == 0x00) /* ^@ - Null */ - || (scan == 0xe0 && ascii == 0x0d) /* PadEnter */ - || (scan == 0xe0 && ascii == 0x0a)) /* ^PadEnter */ - key = ((int) (ascii << 8)); - else if ((scan == 0x37 && ascii == 0x2a) /* Star */ - || (scan == 0x4a && ascii == 0x2d) /* Minus */ - || (scan == 0x4e && ascii == 0x2b) /* Plus */ - || (scan == 0xe0 && ascii == 0x2f)) /* Slash */ - key = ((int) ((ascii & 0x0f) | 0xf0) << 8); - else if (ascii == 0xe0 && scan == 0x47 && pdc_key_modifiers & PDC_KEY_MODIFIER_SHIFT) /* Shift Home */ - key = ((int) (0xb0 << 8)); - else if (ascii == 0xe0 && scan == 0x48 && pdc_key_modifiers & PDC_KEY_MODIFIER_SHIFT) /* Shift Up */ - key = ((int) (0xb1 << 8)); - else if (ascii == 0xe0 && scan == 0x49 && pdc_key_modifiers & PDC_KEY_MODIFIER_SHIFT) /* Shift PgUp */ - key = ((int) (0xb2 << 8)); - else if (ascii == 0xe0 && scan == 0x4b && pdc_key_modifiers & PDC_KEY_MODIFIER_SHIFT) /* Shift Left */ - key = ((int) (0xb3 << 8)); - else if (ascii == 0xe0 && scan == 0x4d && pdc_key_modifiers & PDC_KEY_MODIFIER_SHIFT) /* Shift Right */ - key = ((int) (0xb4 << 8)); - else if (ascii == 0xe0 && scan == 0x4f && pdc_key_modifiers & PDC_KEY_MODIFIER_SHIFT) /* Shift End */ - key = ((int) (0xb5 << 8)); - else if (ascii == 0xe0 && scan == 0x50 && pdc_key_modifiers & PDC_KEY_MODIFIER_SHIFT) /* Shift Down */ - key = ((int) (0xb6 << 8)); - else if (ascii == 0xe0 && scan == 0x51 && pdc_key_modifiers & PDC_KEY_MODIFIER_SHIFT) /* Shift PgDn */ - key = ((int) (0xb7 << 8)); - else if (ascii == 0xe0 && scan == 0x52 && pdc_key_modifiers & PDC_KEY_MODIFIER_SHIFT) /* Shift Ins */ - key = ((int) (0xb8 << 8)); - else if (ascii == 0xe0 && scan == 0x53 && pdc_key_modifiers & PDC_KEY_MODIFIER_SHIFT) /* Shift Del */ - key = ((int) (0xb9 << 8)); - else if (ascii == 0x00 || ascii == 0xe0) - key = ((int) (scan << 8)); - else - key = ((int) (ascii)); + if (scan == 0x1c && ascii == 0x0a) /* ^Enter */ + key = (int)0xfc00; + else if ((scan == 0x03 && ascii == 0x00) /* ^@ - Null */ + || (scan == 0xe0 && ascii == 0x0d) /* PadEnter */ + || (scan == 0xe0 && ascii == 0x0a)) /* ^PadEnter */ + key = ascii << 8; + else if ((scan == 0x37 && ascii == 0x2a) /* Star */ + || (scan == 0x4a && ascii == 0x2d) /* Minus */ + || (scan == 0x4e && ascii == 0x2b) /* Plus */ + || (scan == 0xe0 && ascii == 0x2f)) /* Slash */ + key = ((ascii & 0x0f) | 0xf0) << 8; + else if (ascii == 0xe0 && scan == 0x47 && pdc_key_modifiers & + PDC_KEY_MODIFIER_SHIFT) /* Shift Home */ + key = (int)0xb000; + else if (ascii == 0xe0 && scan == 0x48 && pdc_key_modifiers & + PDC_KEY_MODIFIER_SHIFT) /* Shift Up */ + key = (int)0xb100; + else if (ascii == 0xe0 && scan == 0x49 && pdc_key_modifiers & + PDC_KEY_MODIFIER_SHIFT) /* Shift PgUp */ + key = (int)0xb200; + else if (ascii == 0xe0 && scan == 0x4b && pdc_key_modifiers & + PDC_KEY_MODIFIER_SHIFT) /* Shift Left */ + key = (int)0xb300; + else if (ascii == 0xe0 && scan == 0x4d && pdc_key_modifiers & + PDC_KEY_MODIFIER_SHIFT) /* Shift Right */ + key = (int)0xb400; + else if (ascii == 0xe0 && scan == 0x4f && pdc_key_modifiers & + PDC_KEY_MODIFIER_SHIFT) /* Shift End */ + key = (int)0xb500; + else if (ascii == 0xe0 && scan == 0x50 && pdc_key_modifiers & + PDC_KEY_MODIFIER_SHIFT) /* Shift Down */ + key = (int)0xb600; + else if (ascii == 0xe0 && scan == 0x51 && pdc_key_modifiers & + PDC_KEY_MODIFIER_SHIFT) /* Shift PgDn */ + key = (int)0xb700; + else if (ascii == 0xe0 && scan == 0x52 && pdc_key_modifiers & + PDC_KEY_MODIFIER_SHIFT) /* Shift Ins */ + key = (int)0xb800; + else if (ascii == 0xe0 && scan == 0x53 && pdc_key_modifiers & + PDC_KEY_MODIFIER_SHIFT) /* Shift Del */ + key = (int)0xb900; + else if (ascii == 0x00 || ascii == 0xe0) + key = scan << 8; + else + key = ascii; - PDC_LOG(("PDC_get_bios_key() - returned: %d(0x%x), ascii: %d(0x%x) scan: %d(0x%x)\n", key, key, ascii, ascii, scan, scan)); + PDC_LOG(("PDC_get_bios_key() - returned: %d(0x%x), ascii: %d(0x%x) scan: %d(0x%x)\n", + key, key, ascii, ascii, scan, scan)); - return key; + return key; } /*man-start********************************************************************* @@ -373,77 +403,86 @@ int PDC_get_bios_key(void) PDC_get_ctrl_break() - return OS control break state PDCurses Description: - This is a private PDCurses routine. + This is a private PDCurses routine. - Returns the current OS Control Break Check state. + Returns the current OS Control Break Check state. PDCurses Return Value: - This function returns TRUE on if the Control Break - Check is enabled otherwise FALSE is returned. + This function returns TRUE if the Control Break Check is enabled + otherwise FALSE is returned. PDCurses Errors: - No errors are defined for this function. + No errors are defined for this function. Portability: - PDCurses bool PDC_get_ctrl_break( void ); + PDCurses bool PDC_get_ctrl_break(void); **man-end**********************************************************************/ /***********************************************************************/ -bool PDC_get_ctrl_break(void) +bool PDC_get_ctrl_break(void) /***********************************************************************/ { #if defined(CURSES__32BIT__) || defined(CSET2) || defined(TC) -# if defined(TC) - void __cdecl (*oldAction) (int); -# else - void (*oldAction) (int); -# endif +# if defined(TC) + void __cdecl (*oldAction) (int); +# else + void (*oldAction) (int); +# endif #endif - - PDC_LOG(("PDC_get_ctrl_break() - called\n")); + PDC_LOG(("PDC_get_ctrl_break() - called\n")); #if defined(CURSES__32BIT__) || defined(CSET2) || defined(TC) - oldAction = signal (SIGINT, SIG_DFL); - if (oldAction == SIG_ERR) return FALSE; - else signal (SIGINT, oldAction); - return (oldAction != SIG_IGN); + + oldAction = signal(SIGINT, SIG_DFL); + + if (oldAction == SIG_ERR) + return FALSE; + else + signal(SIGINT, oldAction); + + return (oldAction != SIG_IGN); #else - PFNSIGHANDLER oldHandler, oldHandler1; - USHORT oldAction, oldAction1; - /* get the current state, and set to ignore */ - DosSetSigHandler((PFNSIGHANDLER) NULL, &oldHandler, &oldAction, - SIGA_IGNORE, SIG_CTRLBREAK); - /* restore the previous state */ - DosSetSigHandler(oldHandler, &oldHandler1, &oldAction1, - oldAction, SIG_CTRLBREAK); - return(oldAction != SIGA_IGNORE); + PFNSIGHANDLER oldHandler, oldHandler1; + USHORT oldAction, oldAction1; + + /* get the current state, and set to ignore */ + + DosSetSigHandler((PFNSIGHANDLER) NULL, &oldHandler, &oldAction, + SIGA_IGNORE, SIG_CTRLBREAK); + + /* restore the previous state */ + + DosSetSigHandler(oldHandler, &oldHandler1, &oldAction1, + oldAction, SIG_CTRLBREAK); + + return (oldAction != SIGA_IGNORE); #endif } /*man-start********************************************************************* - PDC_rawgetch() - Returns the next uninterpreted character (if available). + PDC_rawgetch() - Returns the next uninterpreted character + (if available). PDCurses Description: - Gets a character without any interpretation at all and returns - it. If keypad mode is active for the designated window, - function key translation will be performed. Otherwise, - function keys are ignored. If nodelay mode is active in the - window, then PDC_rawgetch() returns -1 if no character is - available. + Gets a character without any interpretation at all and returns + it. If keypad mode is active for the designated window, function + key translation will be performed. Otherwise, function keys are + ignored. If nodelay mode is active in the window, then + PDC_rawgetch() returns -1 if no character is available. - WARNING: It is unknown whether the FUNCTION key translation - is performed at this level. --Frotz 911130 BUG + WARNING: It is unknown whether the FUNCTION key translation + is performed at this level. --Frotz 911130 BUG PDCurses Return Value: - This function returns OK on success and ERR on error. + This function returns OK on success and ERR on error. PDCurses Errors: - No errors are defined for this function. + No errors are defined for this function. Portability: - PDCurses int PDC_rawgetch( void ); + PDCurses int PDC_rawgetch(void); **man-end**********************************************************************/ @@ -451,42 +490,31 @@ bool PDC_get_ctrl_break(void) int PDC_rawgetch(void) /***********************************************************************/ { -extern WINDOW* _getch_win_; -/* extern WINDOW* w;*/ /* w defined in wgetch() as static - _getch_win_ */ - /* is the same window - all references to w changed*/ - /* to _getch_win_ - marked with @@ */ + extern WINDOW *_getch_win_; + int c, oldc; - int c=0; - int oldc=0; - bool return_immediately; + PDC_LOG(("PDC_rawgetch() - called\n")); - PDC_LOG(("PDC_rawgetch() - called\n")); + if (_getch_win_ == (WINDOW *)NULL) + return -1; - if (_getch_win_ == (WINDOW *)NULL) /* @@ */ - return( -1 ); + if ((SP->delaytenths || _getch_win_->_delayms || _getch_win_->_nodelay) + && !PDC_breakout()) + return -1; - if (SP->delaytenths || _getch_win_->_delayms || _getch_win_->_nodelay) - return_immediately = TRUE; - else - return_immediately = FALSE; + while (1) /* loop to get valid char */ + { + c = PDC_get_bios_key(); + oldc = c; - if (return_immediately && !PDC_breakout()) - return( -1 ); + /* return the key if it is not a special key */ - while (1) /* loop to get valid char */ - { - c = PDC_get_bios_key(); - oldc = c; - /* - * Return the key if it is not a special key. - */ - if ((c = PDC_validchar(c)) >= 0) - { /* get & check next char */ - return( c ); - } - if (_getch_win_->_use_keypad) - return( oldc ); - } + if ((c = PDC_validchar(c)) >= 0) + return c; + + if (_getch_win_->_use_keypad) + return oldc; + } } /*man-start********************************************************************* @@ -494,20 +522,20 @@ extern WINDOW* _getch_win_; PDC_set_ctrl_break() - Enables/Disables the host OS BREAK key check. PDCurses Description: - This is a private PDCurses routine. + This is a private PDCurses routine. - Enables/Disables the host OS BREAK key check. If the supplied setting - is TRUE, this enables CTRL/C and CTRL/BREAK to abort the process. - If FALSE, CTRL/C and CTRL/BREAK are ignored. + Enables/Disables the host OS BREAK key check. If the supplied + setting is TRUE, this enables CTRL/C and CTRL/BREAK to abort the + process. If FALSE, CTRL/C and CTRL/BREAK are ignored. PDCurses Return Value: - This function returns OK on success and ERR on error. + This function returns OK on success and ERR on error. PDCurses Errors: - No errors are defined for this function. + No errors are defined for this function. Portability: - PDCurses int PDC_set_ctrl_break( bool setting ); + PDCurses int PDC_set_ctrl_break(bool setting); **man-end**********************************************************************/ @@ -515,28 +543,28 @@ extern WINDOW* _getch_win_; int PDC_set_ctrl_break(bool setting) /***********************************************************************/ { - PDC_LOG(("PDC_set_ctrl_break() - called. Setting: %d\n",setting)); + PDC_LOG(("PDC_set_ctrl_break() - called. Setting: %d\n", setting)); -#if defined (CURSES__32BIT__) || defined (CSET2) || defined(TC) - signal (SIGINT, (setting?SIG_DFL:SIG_IGN)); - signal (SIGBREAK, (setting?SIG_DFL:SIG_IGN)); - return( OK ); +#if defined(CURSES__32BIT__) || defined(CSET2) || defined(TC) + signal(SIGINT, setting ? SIG_DFL : SIG_IGN); + signal(SIGBREAK, setting ? SIG_DFL : SIG_IGN); #else - PFNSIGHANDLER oldHandler; - USHORT oldAction, Action; + PFNSIGHANDLER oldHandler; + USHORT oldAction, Action; - /* turn off control C checking */ - if (setting) - Action = SIGA_KILL; - else - Action = SIGA_IGNORE; - DosSetSigHandler((PFNSIGHANDLER) NULL, &oldHandler, &oldAction, - Action, SIG_CTRLBREAK); - DosSetSigHandler((PFNSIGHANDLER) NULL, &oldHandler, &oldAction, - Action, SIG_CTRLC); - return( OK ); + /* turn off control C checking */ + + if (setting) + Action = SIGA_KILL; + else + Action = SIGA_IGNORE; + + DosSetSigHandler((PFNSIGHANDLER) NULL, &oldHandler, &oldAction, + Action, SIG_CTRLBREAK); + DosSetSigHandler((PFNSIGHANDLER) NULL, &oldHandler, &oldAction, + Action, SIG_CTRLC); #endif - + return OK; } /*man-start********************************************************************* @@ -544,23 +572,23 @@ int PDC_set_ctrl_break(bool setting) PDC_sysgetch() - Return a character using default system routines. PDCurses Description: - This is a private PDCurses function. + This is a private PDCurses function. - Gets a character without normal ^S, ^Q, ^P and ^C interpretation - and returns it. If keypad mode is active for the designated - window, function key translation will be performed. Otherwise, - function keys are ignored. If nodelay mode is active in the - window, then sysgetch() returns -1 if no character is - available. + Gets a character without normal ^S, ^Q, ^P and ^C interpretation + and returns it. If keypad mode is active for the designated + window, function key translation will be performed. Otherwise, + function keys are ignored. If nodelay mode is active in the + window, then sysgetch() returns -1 if no character is + available. PDCurses Return Value: - This function returns OK upon success otherwise ERR is returned. + This function returns OK upon success otherwise ERR is returned. PDCurses Errors: - No errors are defined for this routine. + No errors are defined for this routine. Portability: - PDCurses int PDC_sysgetch( void ); + PDCurses int PDC_sysgetch(void); **man-end**********************************************************************/ @@ -568,40 +596,30 @@ int PDC_set_ctrl_break(bool setting) int PDC_sysgetch(void) /***********************************************************************/ { -extern WINDOW* _getch_win_; -/* extern WINDOW* w;*/ /* w defined in wgetch() as static - _getch_win_ */ - /* is the same window - all references to w changed*/ - /* to _getch_win_ - marked with @@ */ + extern WINDOW *_getch_win_; + int c; - int c=0; - bool return_immediately; + PDC_LOG(("PDC_sysgetch() - called\n")); - PDC_LOG(("PDC_sysgetch() - called\n")); + if (_getch_win_ == (WINDOW *)NULL) + return -1; - if (_getch_win_ == (WINDOW *)NULL) /* @@ */ - return (-1); + if ((SP->delaytenths || _getch_win_->_delayms || _getch_win_->_nodelay) + && !PDC_breakout()) + return -1; - if (SP->delaytenths || _getch_win_->_delayms || _getch_win_->_nodelay) - return_immediately = TRUE; - else - return_immediately = FALSE; + while (1) + { + c = PDC_get_bios_key(); - if (return_immediately && !PDC_breakout()) - return (-1); + /* return the key if it is not a special key */ - while (1) - { - c = PDC_get_bios_key(); - /* - * Return the key if it is not a special key. - */ - if ((unsigned int)c < 256) - return(c); - if ((c = PDC_validchar(c)) >= 0) - { - return (c); /* get & check next char */ - } - } + if ((unsigned int)c < 256) + return c; + + if ((c = PDC_validchar(c)) >= 0) + return c; + } } /*man-start********************************************************************* @@ -609,94 +627,91 @@ extern WINDOW* _getch_win_; PDC_validchar() - validate/translate passed character PDCurses Description: - This is a private PDCurses function. + This is a private PDCurses function. - Checks that 'c' is a valid character, and if so returns it, - with function key translation applied if 'w' has keypad mode - set. If char is invalid, returns -1. + Checks that 'c' is a valid character, and if so returns it, + with function key translation applied if 'w' has keypad mode + set. If char is invalid, returns -1. PDCurses Return Value: - This function returns -1 if the passed character is invalid, or - the WINDOW* 'w' is NULL, or 'w's keypad is not active. + This function returns -1 if the passed character is invalid, or + the WINDOW* 'w' is NULL, or 'w's keypad is not active. - Otherwise, this function returns the PDCurses equivalent of the - passed character. See the function key and key macros in - + Otherwise, this function returns the PDCurses equivalent of the + passed character. See the function key and key macros in + PDCurses Errors: - There are no errors defined for this routine. + There are no errors defined for this routine. Portability: - PDCurses int PDC_validchar( int c ); + PDCurses int PDC_validchar(int c); **man-end**********************************************************************/ /***********************************************************************/ -int PDC_validchar(int c) +int PDC_validchar(int c) /***********************************************************************/ { -extern WINDOW* _getch_win_; -/* extern WINDOW* w;*/ /* w defined in wgetch() as static - _getch_win_ */ - /* is the same window - all references to w changed*/ - /* to _getch_win_ - marked with @@ */ + extern WINDOW *_getch_win_; + int *scanp; - int *scanp=NULL; + PDC_LOG(("PDC_validchar() - called. c: %d\n", c)); - PDC_LOG(("PDC_validchar() - called. c: %d\n",c)); + if (_getch_win_ == (WINDOW *)NULL) + return -1; - if (_getch_win_ == (WINDOW *)NULL) - return (-1); /* bad window pointer */ + /* normal character */ - if ((unsigned int)c < 256) return (c); /* normal character */ - if (!(_getch_win_->_use_keypad)) return (-1); /* skip if keys if !keypad mode */ + if ((unsigned int)c < 256) + return c; - /* - * Under DOS, extended keys are in the upper byte. Shift down for a - * comparison. - */ - c = (c >> 8) & 0xFF; + /* skip if keys if !keypad mode */ - scanp = kptab; - while (*scanp > 0) /* search for value */ - { /* (stops on table entry 0x100) */ - if (*scanp++ == c) - { - return (*scanp); /* found, return it */ - } - scanp++; - } - return( -1 ); /* not found, invalid */ + if (!_getch_win_->_use_keypad) + return -1; + + /* Under DOS, extended keys are in the upper byte. Shift down + for a comparison. */ + + c = (c >> 8) & 0xFF; + + for (scanp = kptab; *scanp > 0; scanp++) + if (*scanp++ == c) + return *scanp; + + return -1; /* not found, invalid */ } /*man-start********************************************************************* - PDC_get_key_modifiers() - Returns the keyboard modifier(s) at time of last getch() + PDC_get_key_modifiers() - Returns the keyboard modifier(s) at time + of last getch() PDCurses Description: - This is a private PDCurses routine. + This is a private PDCurses routine. - Returns the keyboard modifiers effective at the time of the last getch() - call only if PDC_save_key_modifiers(TRUE) has been called before the - getch(); - Use the macros; PDC_KEY_MODIFIER_* to determine which modifier(s) - were set. + Returns the keyboard modifiers effective at the time of the last + getch() call only if PDC_save_key_modifiers(TRUE) has been + called before the getch(). Use the macros; PDC_KEY_MODIFIER_* to + determine which modifier(s) were set. PDCurses Return Value: - This function returns the modifiers. + This function returns the modifiers. PDCurses Errors: - No errors are defined for this function. + No errors are defined for this function. Portability: - PDCurses int PDC_get_key_modifiers( void ); + PDCurses int PDC_get_key_modifiers(void); **man-end**********************************************************************/ /***********************************************************************/ -unsigned long PDC_get_key_modifiers(void) +unsigned long PDC_get_key_modifiers(void) /***********************************************************************/ { - PDC_LOG(("PDC_get_key_modifiers() - called\n")); + PDC_LOG(("PDC_get_key_modifiers() - called\n")); - return(pdc_key_modifiers); + return pdc_key_modifiers; } diff --git a/os2/pdcprint.c b/os2/pdcprint.c index 15dc6893..5177097b 100644 --- a/os2/pdcprint.c +++ b/os2/pdcprint.c @@ -19,42 +19,42 @@ */ #define CURSES_LIBRARY 1 #ifdef HAVE_CONFIG_H -# include +# include #endif #include #ifdef PDCDEBUG -char *rcsid_PDCprint = "$Id: pdcprint.c,v 1.4 2006/01/03 07:34:43 wmcbrine Exp $"; +char *rcsid_PDCprint = "$Id: pdcprint.c,v 1.5 2006/01/08 11:53:42 wmcbrine Exp $"; #endif -#if !defined (CURSES__32BIT__) && !defined(CSET2) && !defined(MSC) &&!defined(TC) -#define INCL_DOS -#include +#if !defined(CURSES__32BIT__) && !defined(CSET2) && !defined(MSC) &&!defined(TC) +# define INCL_DOS +# include #endif -char Printer[]="LPT1:"; +char Printer[] = "LPT1:"; /*man-start********************************************************************* PDC_print() - Provides primitive access to the BIOS printer functions PDCurses Description: - This is a private PDCurses routine. + This is a private PDCurses routine. - Implements write/init/read printer services at the BIOS level. + Implements write/init/read printer services at the BIOS level. - This provides the basic support that PDCurses needs to dump the - contents of windows or pads to the printer attached to the BIOS - printer port. + This provides the basic support that PDCurses needs to dump the + contents of windows or pads to the printer attached to the BIOS + printer port. PDCurses Return Value: - See the BIOS INT 0x17 specifications. + See the BIOS INT 0x17 specifications. PDCurses Errors: - See the BIOS INT 0x17 specifications. + See the BIOS INT 0x17 specifications. Portability: - PDCurses int PDC_print( int cmd, int byte, int port ); + PDCurses int PDC_print(int cmd, int byte, int port); **man-end**********************************************************************/ @@ -62,27 +62,30 @@ char Printer[]="LPT1:"; #ifdef HAVE_PROTO int PDC_print(int cmd, int byte, int port) #else -int PDC_print(cmd,byte,port) +int PDC_print(cmd, byte, port) int cmd; int byte; int port; #endif /***********************************************************************/ { -#if !defined (CURSES__32BIT__) && !defined(CSET2) && !defined(TC) +#if !defined(CURSES__32BIT__) && !defined(CSET2) && !defined(TC) HFILE Lpt; - USHORT Action=0; - USHORT NoWritten=0; + USHORT Action = 0; + USHORT NoWritten = 0; #endif PDC_LOG(("PDC_print() - called\n")); #if !defined (CURSES__32BIT__) && !defined(CSET2) && !defined(TC) - if (DosOpen((PSZ)Printer, &Lpt, &Action, 0,0,0,0,0) != 0) - return(ERR); - DosWrite(Lpt,&byte,1,&NoWritten); + + if (DosOpen((PSZ)Printer, &Lpt, &Action, 0, 0, 0, 0, 0) != 0) + return ERR; + + DosWrite(Lpt, &byte, 1, &NoWritten); DosClose(Lpt); - return(NoWritten == 1); + + return (NoWritten == 1); #else - return (OK); + return OK; #endif } diff --git a/os2/pdcscrn.c b/os2/pdcscrn.c index c15b41e9..af056743 100644 --- a/os2/pdcscrn.c +++ b/os2/pdcscrn.c @@ -19,23 +19,23 @@ */ #define CURSES_LIBRARY 1 #ifdef HAVE_CONFIG_H -# include +# include #endif #define INCL_DOSMISC #include #ifdef PDCDEBUG -char *rcsid_PDCscrn = "$Id: pdcscrn.c,v 1.6 2006/01/03 19:54:29 wmcbrine Exp $"; +char *rcsid_PDCscrn = "$Id: pdcscrn.c,v 1.7 2006/01/08 11:53:42 wmcbrine Exp $"; #endif #ifdef EMXVIDEO - static unsigned char *saved_screen = NULL; - static int saved_lines = 0; - static int saved_cols = 0; +static unsigned char *saved_screen = NULL; +static int saved_lines = 0; +static int saved_cols = 0; #else - static PCH saved_screen = NULL; - static USHORT saved_lines = 0; - static USHORT saved_cols = 0; +static PCH saved_screen = NULL; +static USHORT saved_lines = 0; +static USHORT saved_cols = 0; #endif /*man-start********************************************************************* @@ -43,16 +43,17 @@ char *rcsid_PDCscrn = "$Id: pdcscrn.c,v 1.6 2006/01/03 19:54:29 wmcbrine Exp $" PDC_scr_close() - Internal low-level binding to close the physical screen PDCurses Description: - This is a nop for the DOS platform. + This is a nop for the DOS platform. PDCurses Return Value: - This function returns OK on success, otherwise an ERR is returned. + This function returns OK on success, otherwise an ERR is + returned. PDCurses Errors: - The DOS platform will never fail. + The DOS platform will never fail. Portability: - PDCurses int PDC_scr_close( void ); + PDCurses int PDC_scr_close(void); **man-end**********************************************************************/ @@ -60,29 +61,31 @@ char *rcsid_PDCscrn = "$Id: pdcscrn.c,v 1.6 2006/01/03 19:54:29 wmcbrine Exp $" int PDC_scr_close(void) /***********************************************************************/ { - char *ptr; + char *ptr; - PDC_LOG(("PDC_scr_close() - called\n")); + PDC_LOG(("PDC_scr_close() - called\n")); #ifdef EMXVIDEO - ptr = getenv("PDC_RESTORE_SCREEN"); + ptr = getenv("PDC_RESTORE_SCREEN"); #else - if ( DosScanEnv( "PDC_RESTORE_SCREEN", (PSZ *)&ptr ) ) - ptr = NULL; + if (DosScanEnv("PDC_RESTORE_SCREEN", (PSZ *)&ptr)) + ptr = NULL; #endif - if (ptr != NULL) - { - if (saved_screen == NULL) - return( OK ); + if (ptr != NULL) + { + if (saved_screen == NULL) + return OK; #ifdef EMXVIDEO - v_putline(saved_screen,0,0,saved_lines*saved_cols); + v_putline(saved_screen, 0, 0, saved_lines * saved_cols); #else - VioWrtCellStr(saved_screen,saved_lines*saved_cols*2,0,0,(HVIO)NULL); + VioWrtCellStr(saved_screen, saved_lines * saved_cols * 2, + 0, 0, (HVIO)NULL); #endif - free(saved_screen); - saved_screen = NULL; - } - return( OK ); + free(saved_screen); + saved_screen = NULL; + } + + return OK; } /*man-start********************************************************************* @@ -90,39 +93,40 @@ int PDC_scr_close(void) PDC_scrn_modes_equal() - Decide if two screen modes are equal PDCurses Description: - Mainly required for OS/2. It decides if two screen modes - (VIOMODEINFO structure) are equal. Under DOS it just compares - two integers + Mainly required for OS/2. It decides if two screen modes + (VIOMODEINFO structure) are equal. Under DOS it just compares + two integers. PDCurses Return Value: - This function returns TRUE if equal else FALSe. + This function returns TRUE if equal else FALSE. PDCurses Errors: - No errors are defined for this function. + No errors are defined for this function. Portability: - PDCurses int PDC_scrn_modes_equal( int mode1, int mode2 ); - OS2 PDCurses int PDC_scrn_modes_equal( VIOMODEINFO mode1, VIOMODEINFO mode2 ); + PDCurses int PDC_scrn_modes_equal(int mode1, int mode2); + OS2 PDCurses int PDC_scrn_modes_equal(VIOMODEINFO mode1, + VIOMODEINFO mode2); **man-end**********************************************************************/ /***********************************************************************/ -#if !defined( EMXVIDEO ) +#if !defined(EMXVIDEO) bool PDC_scrn_modes_equal(VIOMODEINFO mode1, VIOMODEINFO mode2) #else bool PDC_scrn_modes_equal(int mode1, int mode2) #endif /***********************************************************************/ { - PDC_LOG(("PDC_scrn_modes_equal() - called\n")); + PDC_LOG(("PDC_scrn_modes_equal() - called\n")); -#if !defined( EMXVIDEO ) - return ((mode1.cb == mode2.cb) && (mode1.fbType == mode2.fbType) - && (mode1.color == mode2.color) && (mode1.col == mode2.col) - && (mode1.row == mode2.row) && (mode1.hres == mode2.vres) - && (mode1.vres == mode2.vres) ); +#if !defined(EMXVIDEO) + return ((mode1.cb == mode2.cb) && (mode1.fbType == mode2.fbType) + && (mode1.color == mode2.color) && (mode1.col == mode2.col) + && (mode1.row == mode2.row) && (mode1.hres == mode2.vres) + && (mode1.vres == mode2.vres)); #else - return (mode1 == mode2); + return (mode1 == mode2); #endif } @@ -131,16 +135,17 @@ bool PDC_scrn_modes_equal(int mode1, int mode2) PDC_scr_open() - Internal low-level binding to open the physical screen PDCurses Description: - This is a NOP for the DOS platform. + This is a NOP for the DOS platform. PDCurses Return Value: - This function returns OK on success, otherwise an ERR is returned. + This function returns OK on success, otherwise an ERR is + returned. PDCurses Errors: - The DOS platform will never fail. + The DOS platform will never fail. Portability: - PDCurses int PDC_scr_open( SCREEN* internal, bool echo ); + PDCurses int PDC_scr_open(SCREEN *internal, bool echo); **man-end**********************************************************************/ @@ -148,102 +153,107 @@ bool PDC_scrn_modes_equal(int mode1, int mode2) int PDC_scr_open(SCREEN *internal, bool echo) /***********************************************************************/ { - char *ptr; -#if !defined( EMXVIDEO ) - USHORT totchars=0; + char *ptr; +#if !defined(EMXVIDEO) + USHORT totchars; #endif - PDC_LOG(("PDC_scr_open() - called. internal: %x, echo: %d\n", internal, echo)); + PDC_LOG(("PDC_scr_open() - called. internal: %x, echo: %d\n", + internal, echo)); - internal->orig_attr = 0; - internal->orig_emulation = 0; - PDC_get_cursor_pos(&internal->cursrow, &internal->curscol); - internal->direct_video = TRUE; /* Assume that we can */ - internal->autocr = TRUE; /* lf -> crlf by default */ - internal->raw_out = FALSE; /* tty I/O modes */ - internal->raw_inp = FALSE; /* tty I/O modes */ - internal->cbreak = TRUE; - internal->save_key_modifiers = FALSE; - internal->return_key_modifiers = FALSE; - internal->echo = echo; - internal->refrbrk = FALSE; /* no premature end of refresh*/ - internal->video_page = 0; /* Current Video Page */ - internal->visible_cursor= TRUE; /* Assume that it is visible */ - internal->cursor = PDC_get_cursor_mode(); + internal->orig_attr = 0; + internal->orig_emulation = 0; + + PDC_get_cursor_pos(&internal->cursrow, &internal->curscol); + + internal->direct_video = TRUE; /* Assume that we can */ + internal->autocr = TRUE; /* lf -> crlf by default */ + internal->raw_out = FALSE; /* tty I/O modes */ + internal->raw_inp = FALSE; /* tty I/O modes */ + internal->cbreak = TRUE; + internal->save_key_modifiers = FALSE; + internal->return_key_modifiers = FALSE; + internal->echo = echo; + internal->refrbrk = FALSE; /* no premature end of refresh*/ + internal->video_page = 0; /* Current Video Page */ + internal->visible_cursor = TRUE; /* Assume that it is visible */ + internal->cursor = PDC_get_cursor_mode(); #if defined(EMXVIDEO) - internal->tahead = -1; + internal->tahead = -1; #endif #if !defined(EMXVIDEO) - (void)PDC_query_adapter_type( &internal->adapter ); - (void)PDC_get_scrn_mode( &internal->scrnmode ); - (void)PDC_get_keyboard_info( &internal->kbdinfo ); + PDC_query_adapter_type(&internal->adapter); + PDC_get_scrn_mode(&internal->scrnmode); + PDC_get_keyboard_info(&internal->kbdinfo); - PDC_LOG(("PDC_scr_open() - after PDC_get_keyboard_info(). cb: %x, fsMask: %x, chTurnAround: %x, fsInterim: %x, fsState: %x\n", SP->kbdinfo.cb, SP->kbdinfo.fsMask, SP->kbdinfo.chTurnAround, SP->kbdinfo.fsInterim, SP->kbdinfo.fsState)); + PDC_LOG(("PDC_scr_open() - after PDC_get_keyboard_info(). cb: %x, fsMask: %x, chTurnAround: %x, fsInterim: %x, fsState: %x\n", + SP->kbdinfo.cb, SP->kbdinfo.fsMask, + SP->kbdinfo.chTurnAround, SP->kbdinfo.fsInterim, + SP->kbdinfo.fsState)); - /* - * Now set the keyboard into binary mode - */ - (void)PDC_set_keyboard_binary(); -#else - internal->adapter = PDC_query_adapter_type(); - if ( internal->adapter == _UNIX_MONO ) - internal->mono = TRUE; -#endif + /* Now set the keyboard into binary mode */ - internal->orig_font = internal->font = PDC_get_font(); - internal->lines = PDC_get_rows(); - internal->cols = PDC_get_columns(); - internal->audible = TRUE; - internal->visibility = 1; - internal->orig_cursor = internal->cursor; - internal->orgcbr = PDC_get_ctrl_break(); - internal->blank = ' '; - internal->resized = FALSE; - internal->shell = FALSE; - internal->_trap_mbe = 0L; - internal->_map_mbe_to_key = 0L; - internal->linesrippedoff = 0; - internal->linesrippedoffontop = 0; - internal->delaytenths = 0; - internal->sizeable = TRUE; - /* - * This code for preserving the current screen... - */ -#ifdef EMXVIDEO - ptr = getenv("PDC_RESTORE_SCREEN"); + PDC_set_keyboard_binary(); #else - if ( DosScanEnv( "PDC_RESTORE_SCREEN", (PSZ *)&ptr ) ) - ptr = NULL; + internal->adapter = PDC_query_adapter_type(); + if (internal->adapter == _UNIX_MONO) + internal->mono = TRUE; #endif - if (ptr != NULL) - { - saved_lines = internal->lines; - saved_cols = internal->cols; -#ifdef EMXVIDEO - if ((saved_screen = (unsigned char*)malloc(2*saved_lines*saved_cols*sizeof(unsigned char))) == NULL) - return(ERR); - v_getline(saved_screen,0,0,saved_lines*saved_cols); -#else - if ((saved_screen = (PCH)malloc(2*saved_lines*saved_cols*sizeof(unsigned char))) == NULL) - return(ERR); - totchars = saved_lines*saved_cols*2; - VioReadCellStr((PCH)saved_screen,&totchars,0,0,(HVIO)NULL); -#endif - } + internal->orig_font = internal->font = PDC_get_font(); + internal->lines = PDC_get_rows(); + internal->cols = PDC_get_columns(); + internal->audible = TRUE; + internal->visibility = 1; + internal->orig_cursor = internal->cursor; + internal->orgcbr = PDC_get_ctrl_break(); + internal->blank = ' '; + internal->resized = FALSE; + internal->shell = FALSE; + internal->_trap_mbe = 0L; + internal->_map_mbe_to_key = 0L; + internal->linesrippedoff = 0; + internal->linesrippedoffontop = 0; + internal->delaytenths = 0; + internal->sizeable = TRUE; + + /* This code for preserving the current screen */ #ifdef EMXVIDEO - ptr = getenv("PDC_PRESERVE_SCREEN"); + ptr = getenv("PDC_RESTORE_SCREEN"); #else - if ( DosScanEnv( "PDC_PRESERVE_SCREEN", (PSZ *)&ptr ) ) - ptr = NULL; + if (DosScanEnv("PDC_RESTORE_SCREEN", (PSZ *)&ptr)) + ptr = NULL; #endif - if (ptr != NULL) - internal->_preserve = TRUE; - else - internal->_preserve = FALSE; + if (ptr != NULL) + { + saved_lines = internal->lines; + saved_cols = internal->cols; +#ifdef EMXVIDEO + if ((saved_screen = (unsigned char *)malloc(2 * saved_lines * + saved_cols * sizeof(unsigned char))) == NULL) + return ERR; - return( OK ); + v_getline(saved_screen, 0, 0, saved_lines * saved_cols); +#else + if ((saved_screen = (PCH)malloc(2 * saved_lines * + saved_cols * sizeof(unsigned char))) == NULL) + return ERR; + + totchars = saved_lines * saved_cols * 2; + VioReadCellStr((PCH)saved_screen, &totchars, 0, 0, (HVIO)NULL); +#endif + } + +#ifdef EMXVIDEO + ptr = getenv("PDC_PRESERVE_SCREEN"); +#else + if (DosScanEnv("PDC_PRESERVE_SCREEN", (PSZ *)&ptr)) + ptr = NULL; +#endif + internal->_preserve = (ptr != NULL); + + return OK; } /*man-start********************************************************************* @@ -251,19 +261,20 @@ int PDC_scr_open(SCREEN *internal, bool echo) PDC_resize_screen() - Internal low-level function to resize screen PDCurses Description: - This function provides a means for the application program to - resize the overall dimensions of the screen. Under DOS and OS/2 - the application can tell PDCurses what size to make the screen; - under X11, resizing is done by the user and this function simply - adjusts its internal structures to fit the new size. + This function provides a means for the application program to + resize the overall dimensions of the screen. Under DOS and OS/2 + the application can tell PDCurses what size to make the screen; + under X11, resizing is done by the user and this function simply + adjusts its internal structures to fit the new size. PDCurses Return Value: - This function returns OK on success, otherwise an ERR is returned. + This function returns OK on success, otherwise an ERR is + returned. PDCurses Errors: Portability: - PDCurses int PDC_resize_screen( int, int ); + PDCurses int PDC_resize_screen(int, int); **man-end**********************************************************************/ @@ -272,46 +283,53 @@ int PDC_resize_screen(int nlines, int ncols) /***********************************************************************/ { #ifndef EMXVIDEO - VIOMODEINFO modeInfo={0}; - USHORT result=0; + VIOMODEINFO modeInfo = {0}; + USHORT result; #endif - PDC_LOG(("PDC_resize_screen() - called. Lines: %d Cols: %d\n",nlines,ncols)); + PDC_LOG(("PDC_resize_screen() - called. Lines: %d Cols: %d\n", + nlines, ncols)); #ifdef EMXVIDEO - return (ERR); + return ERR; #else - modeInfo.cb = sizeof(modeInfo); - /* set most parameters of modeInfo */ - VioGetMode(&modeInfo, 0); - modeInfo.fbType = 1; - modeInfo.row = nlines; - modeInfo.col = ncols; - result = VioSetMode(&modeInfo, 0); - LINES = PDC_get_rows(); - COLS = PDC_get_columns(); - return ((result == 0) ? OK : ERR); + modeInfo.cb = sizeof(modeInfo); + + /* set most parameters of modeInfo */ + + VioGetMode(&modeInfo, 0); + modeInfo.fbType = 1; + modeInfo.row = nlines; + modeInfo.col = ncols; + result = VioSetMode(&modeInfo, 0); + + LINES = PDC_get_rows(); + COLS = PDC_get_columns(); + + return (result == 0) ? OK : ERR; #endif } #if !defined(EMXVIDEO) /***********************************************************************/ -int PDC_reset_shell_mode( void ) +int PDC_reset_shell_mode(void) /***********************************************************************/ { - PDC_LOG(("PDC_reset_shell_mode() - called.\n")); + PDC_LOG(("PDC_reset_shell_mode() - called.\n")); - PDC_set_keyboard_default(); - return OK; + PDC_set_keyboard_default(); + + return OK; } /***********************************************************************/ -int PDC_reset_prog_mode( void ) +int PDC_reset_prog_mode(void) /***********************************************************************/ { - PDC_LOG(("PDC_reset_prog_mode() - called.\n")); + PDC_LOG(("PDC_reset_prog_mode() - called.\n")); - PDC_set_keyboard_binary(); - return OK; + PDC_set_keyboard_binary(); + + return OK; } #endif diff --git a/os2/pdcsetsc.c b/os2/pdcsetsc.c index a1d71714..2f063b45 100644 --- a/os2/pdcsetsc.c +++ b/os2/pdcsetsc.c @@ -19,16 +19,16 @@ */ #define CURSES_LIBRARY 1 #ifdef HAVE_CONFIG_H -# include +# include #endif #include #ifdef HAVE_STRING_H -# include +# include #endif #ifdef PDCDEBUG -char *rcsid_PDCsetsc = "$Id: pdcsetsc.c,v 1.6 2006/01/03 19:54:29 wmcbrine Exp $"; +char *rcsid_PDCsetsc = "$Id: pdcsetsc.c,v 1.7 2006/01/08 11:53:42 wmcbrine Exp $"; #endif /*man-start********************************************************************* @@ -36,18 +36,19 @@ char *rcsid_PDCsetsc = "$Id: pdcsetsc.c,v 1.6 2006/01/03 19:54:29 wmcbrine Exp PDC_set_80x25() - force a known screen state: 80x25 text mode. PDCurses Description: - This is a private PDCurses function. + This is a private PDCurses function. - Forces the appropriate 80x25 alpha mode given the display adapter. + Forces the appropriate 80x25 alpha mode given the display + adapter. PDCurses Return Value: - This function returns OK upon success otherwise ERR is returned. + This function returns OK upon success otherwise ERR is returned. PDCurses Errors: - No errors are defined for this routine. + No errors are defined for this routine. Portability: - PDCurses int PDC_set_80x25( void ); + PDCurses int PDC_set_80x25(void); **man-end**********************************************************************/ @@ -56,18 +57,20 @@ int PDC_set_80x25(void) /***********************************************************************/ { #ifndef EMXVIDEO - VIOMODEINFO modeInfo={0}; + VIOMODEINFO modeInfo = {0}; #endif - PDC_LOG(("PDC_set_80x25() - called\n")); + PDC_LOG(("PDC_set_80x25() - called\n")); #ifndef EMXVIDEO - modeInfo.cb = sizeof(modeInfo); - /* set most parameters of modeInfo */ - VioGetMode(&modeInfo, 0); - modeInfo.fbType = 1; - VioSetMode(&modeInfo, 0); + modeInfo.cb = sizeof(modeInfo); + + /* set most parameters of modeInfo */ + + VioGetMode(&modeInfo, 0); + modeInfo.fbType = 1; + VioSetMode(&modeInfo, 0); #endif - return( OK ); + return OK; } /*man-start********************************************************************* @@ -75,41 +78,44 @@ int PDC_set_80x25(void) PDC_set_cursor_mode() - Set the cursor start and stop scan lines. PDCurses Description: - Sets the cursor type to begin in scan line startrow and end in - scan line endrow. Both values should be 0-31. + Sets the cursor type to begin in scan line startrow and end in + scan line endrow. Both values should be 0-31. PDCurses Return Value: - This function returns OK on success and ERR on error. + This function returns OK on success and ERR on error. PDCurses Errors: - No errors are defined for this function. + No errors are defined for this function. Portability: - PDCurses int PDC_set_cursor_mode( int startrow, int endrow ); + PDCurses int PDC_set_cursor_mode(int startrow, int endrow); **man-end**********************************************************************/ /***********************************************************************/ -int PDC_set_cursor_mode( int startrow, int endrow ) +int PDC_set_cursor_mode(int startrow, int endrow) /***********************************************************************/ { #ifndef EMXVIDEO - VIOCURSORINFO cursorInfo={0}; + VIOCURSORINFO cursorInfo = {0}; #endif - PDC_LOG(("PDC_set_cursor_mode() - called: startrow %d endrow %d\n",startrow,endrow)); + PDC_LOG(("PDC_set_cursor_mode() - called: startrow %d endrow %d\n", + startrow, endrow)); #ifdef EMXVIDEO - if (endrow <= startrow) - v_hidecursor(); - else - v_ctype (startrow, endrow); - return( OK ); + if (endrow <= startrow) + v_hidecursor(); + else + v_ctype(startrow, endrow); + + return OK; #else - cursorInfo.yStart = startrow; - cursorInfo.cEnd = endrow; - cursorInfo.cx = 1; - cursorInfo.attr = 0; - return (VioSetCurType (&cursorInfo, 0) == 0); + cursorInfo.yStart = startrow; + cursorInfo.cEnd = endrow; + cursorInfo.cx = 1; + cursorInfo.attr = 0; + + return (VioSetCurType(&cursorInfo, 0) == 0); #endif } @@ -118,22 +124,22 @@ int PDC_set_cursor_mode( int startrow, int endrow ) PDC_set_font() - sets the current font size PDCurses Description: - This is a private PDCurses function. + This is a private PDCurses function. - This routine sets the current font size, if the adapter allows - such a change. + This routine sets the current font size, if the adapter allows + such a change. PDCurses Return Value: - This function returns OK upon success otherwise ERR is returned. + This function returns OK upon success otherwise ERR is returned. PDCurses Errors: - It is an error to attempt to change the font size on a "bogus" - adapter. The reason for this is that we have a known video - adapter identity problem. e.g. Two adapters report the same - identifying characteristics. + It is an error to attempt to change the font size on a "bogus" + adapter. The reason for this is that we have a known video + adapter identity problem. e.g. Two adapters report the same + identifying characteristics. Portability: - PDCurses int PDC_set_font( int size ); + PDCurses int PDC_set_font(int size); **man-end**********************************************************************/ @@ -142,27 +148,31 @@ int PDC_set_font(int size) /***********************************************************************/ { #ifndef EMXVIDEO - VIOMODEINFO modeInfo={0}; + VIOMODEINFO modeInfo = {0}; #endif - PDC_LOG(("PDC_set_font() - called\n")); + PDC_LOG(("PDC_set_font() - called\n")); #ifndef EMXVIDEO - if (SP->sizeable && (SP->font != size)) - { - modeInfo.cb = sizeof(modeInfo); - /* set most parameters of modeInfo */ - VioGetMode(&modeInfo, 0); - modeInfo.cb = 8; /* ignore horiz an vert resolution */ - modeInfo.row = modeInfo.vres / size; - VioSetMode(&modeInfo, 0); - } - if (SP->visible_cursor) - PDC_cursor_on(); - else - PDC_cursor_off(); - SP->font = PDC_get_font(); + if (SP->sizeable && (SP->font != size)) + { + modeInfo.cb = sizeof(modeInfo); + + /* set most parameters of modeInfo */ + + VioGetMode(&modeInfo, 0); + modeInfo.cb = 8; /* ignore horiz an vert resolution */ + modeInfo.row = modeInfo.vres / size; + VioSetMode(&modeInfo, 0); + } + + if (SP->visible_cursor) + PDC_cursor_on(); + else + PDC_cursor_off(); + + SP->font = PDC_get_font(); #endif - return( OK ); + return OK; } /*man-start********************************************************************* @@ -170,22 +180,22 @@ int PDC_set_font(int size) PDC_set_rows() - sets the physical number of rows on screen PDCurses Description: - This is a private PDCurses function. + This is a private PDCurses function. - This routine attempts to set the number of rows on the physical - screen to the passed value. + This routine attempts to set the number of rows on the physical + screen to the passed value. PDCurses Return Value: - This function returns OK upon success otherwise ERR is returned. + This function returns OK upon success otherwise ERR is returned. PDCurses Errors: - It is an error to attempt to change the screen size on a "bogus" - adapter. The reason for this is that we have a known video - adapter identity problem. e.g. Two adapters report the same - identifying characteristics. + It is an error to attempt to change the screen size on a "bogus" + adapter. The reason for this is that we have a known video + adapter identity problem. e.g. Two adapters report the same + identifying characteristics. Portability: - PDCurses int PDC_set_rows( int rows ); + PDCurses int PDC_set_rows(int rows); **man-end**********************************************************************/ @@ -194,24 +204,28 @@ int PDC_set_rows(int rows) /***********************************************************************/ { #ifndef EMXVIDEO - VIOMODEINFO modeInfo={0}; - USHORT result=0; + VIOMODEINFO modeInfo = {0}; + USHORT result; #endif - PDC_LOG(("PDC_set_rows() - called\n")); + PDC_LOG(("PDC_set_rows() - called\n")); #ifdef EMXVIDEO - return (ERR); + return ERR; #else - modeInfo.cb = sizeof(modeInfo); - /* set most parameters of modeInfo */ - VioGetMode(&modeInfo, 0); - modeInfo.fbType = 1; - modeInfo.row = rows; - result = VioSetMode(&modeInfo, 0); - SP->font = PDC_get_font(); - LINES = PDC_get_rows(); - COLS = PDC_get_columns(); - return ((result == 0) ? OK : ERR); + modeInfo.cb = sizeof(modeInfo); + + /* set most parameters of modeInfo */ + + VioGetMode(&modeInfo, 0); + modeInfo.fbType = 1; + modeInfo.row = rows; + result = VioSetMode(&modeInfo, 0); + + SP->font = PDC_get_font(); + LINES = PDC_get_rows(); + COLS = PDC_get_columns(); + + return (result == 0) ? OK : ERR; #endif } @@ -220,94 +234,97 @@ int PDC_set_rows(int rows) PDC_set_scrn_mode() - Set BIOS Video Mode PDCurses Description: - Sets the BIOS Video Mode Number ONLY if it is different from - the current video mode. This routine is for DOS systems only. + Sets the BIOS Video Mode Number ONLY if it is different from + the current video mode. This routine is for DOS systems only. PDCurses Return Value: - This function returns OK on success and ERR on error. + This function returns OK on success and ERR on error. PDCurses Errors: - No errors are defined for this function. + No errors are defined for this function. Portability: - PDCurses int PDC_set_scrn_mode( int new_mode ); + PDCurses int PDC_set_scrn_mode(int new_mode); **man-end**********************************************************************/ /***********************************************************************/ -#if !defined( EMXVIDEO ) +#if !defined(EMXVIDEO) int PDC_set_scrn_mode(VIOMODEINFO new_mode) #else int PDC_set_scrn_mode(int new_mode) #endif /***********************************************************************/ { - PDC_LOG(("PDC_set_scrn_mode() - called\n")); + PDC_LOG(("PDC_set_scrn_mode() - called\n")); #ifdef EMXVIDEO - return ( OK ); + return OK; #else - if (VioSetMode (&new_mode, 0) != 0) - { - SP->font = PDC_get_font(); - memcpy((char *)&SP->scrnmode,(char *)&new_mode,sizeof(VIOMODEINFO)); - LINES = PDC_get_rows(); - COLS = PDC_get_columns(); - return( OK ); - } - else - return (ERR); + if (VioSetMode(&new_mode, 0) != 0) + { + SP->font = PDC_get_font(); + memcpy((char *)&SP->scrnmode, (char *)&new_mode, + sizeof(VIOMODEINFO)); + LINES = PDC_get_rows(); + COLS = PDC_get_columns(); + + return OK; + } + else + return ERR; #endif } + /***********************************************************************/ int PDC_curs_set(int visibility) /***********************************************************************/ { #ifndef EMXVIDEO - VIOCURSORINFO pvioCursorInfo; + VIOCURSORINFO pvioCursorInfo; #endif - int start=0,end=0; - int ret_vis=0,hidden=0; + int ret_vis, hidden = 0, start = 0, end = 0; - PDC_LOG(("PDC_curs_set() - called: visibility=%d\n",visibility)); + PDC_LOG(("PDC_curs_set() - called: visibility=%d\n", visibility)); - ret_vis = SP->visibility; - SP->visibility = visibility; + ret_vis = SP->visibility; + SP->visibility = visibility; - switch(visibility) - { - case 0: /* invisible */ + switch(visibility) + { + case 0: /* invisible */ #ifdef EMXVIDEO - start = end = 0; + start = end = 0; #else - start = SP->font / 4; - end = SP->font; + start = SP->font / 4; + end = SP->font; #endif - hidden = (-1); - break; - case 2: /* highly visible */ - start = 2; /* almost full-height block */ - end = SP->font-1; - break; - default: /* normal visibility */ - start = SP->font - (SP->font / 4); - end = SP->font-1; - break; - } + hidden = -1; + break; + + case 2: /* highly visible */ + start = 2; /* almost full-height block */ + end = SP->font - 1; + break; + + default: /* normal visibility */ + start = SP->font - (SP->font / 4); + end = SP->font - 1; + } #ifdef EMXVIDEO - if (!visibility) - v_hidecursor(); - else - v_ctype (start, end); + if (!visibility) + v_hidecursor(); + else + v_ctype(start, end); #else - pvioCursorInfo.yStart = (USHORT)start; - pvioCursorInfo.cEnd = (USHORT)end; - pvioCursorInfo.cx = (USHORT)1; - pvioCursorInfo.attr = hidden; - VioSetCurType((PVIOCURSORINFO)&pvioCursorInfo,0); + pvioCursorInfo.yStart = (USHORT)start; + pvioCursorInfo.cEnd = (USHORT)end; + pvioCursorInfo.cx = (USHORT)1; + pvioCursorInfo.attr = hidden; + VioSetCurType((PVIOCURSORINFO)&pvioCursorInfo, 0); #endif - return( ret_vis ); + return ret_vis; } /*man-start********************************************************************* @@ -315,24 +332,25 @@ int PDC_curs_set(int visibility) PDC_set_title() - Set window title PDCurses Description: - Sets the title of the window in which the curses program is running. - This function may not do anything on some platforms. + Sets the title of the window in which the curses program is + running. This function may not do anything on some platforms. PDCurses Return Value: - N/A + N/A PDCurses Errors: - No errors are defined for this function. + No errors are defined for this function. Portability: - PDCurses void PDC_set_title( char *title ); + PDCurses void PDC_set_title(char *title); **man-end**********************************************************************/ + /***********************************************************************/ void PDC_set_title(char *title) /***********************************************************************/ { - PDC_LOG(("PDC_set_title() - called:<%s>\n",title)); + PDC_LOG(("PDC_set_title() - called:<%s>\n", title)); - return; + return; } diff --git a/win32/pdcclip.c b/win32/pdcclip.c index 46fc326c..c2fb98e5 100644 --- a/win32/pdcclip.c +++ b/win32/pdcclip.c @@ -22,145 +22,148 @@ #include #ifdef PDCDEBUG -char *rcsid_PDCclip = "$Id: pdcclip.c,v 1.5 2006/01/03 07:34:43 wmcbrine Exp $"; +char *rcsid_PDCclip = "$Id: pdcclip.c,v 1.6 2006/01/08 11:53:43 wmcbrine Exp $"; #endif - /*man-start********************************************************************* PDC_getclipboard() - Gets the contents of the clipboard PDCurses Description: - This is a PDCurses only routine. + This is a PDCurses only routine. - Gets the textual contents of the system's clipboard. This - function returns the contents of the clipboard in the contents - argument. It is the responsibilitiy of the caller to free the - memory returned with the PDC_freeclipboard() call. The length of the - clipboard contents is returned in the length argument. + Gets the textual contents of the system's clipboard. This + function returns the contents of the clipboard in the contents + argument. It is the responsibilitiy of the caller to free the + memory returned with the PDC_freeclipboard() call. The length + of the clipboard contents is returned in the length argument. PDCurses Return Value: - indicator of success/failure of call. - PDC_CLIP_SUCCESS the call was successful - PDC_CLIP_ACCESS_ERROR an error occured while accessing the - clipboard - PDC_CLIP_MEMORY_ERROR unable to allocate sufficient memory for - the clipboard contents - PDC_CLIP_EMPTY the clipboard contains no text + indicator of success/failure of call. + PDC_CLIP_SUCCESS the call was successful + PDC_CLIP_ACCESS_ERROR an error occured while accessing the + clipboard + PDC_CLIP_MEMORY_ERROR unable to allocate sufficient memory for + the clipboard contents + PDC_CLIP_EMPTY the clipboard contains no text Portability: - PDCurses int PDC_getclipboard( char **contents, long *length ); + PDCurses int PDC_getclipboard(char **contents, long *length); **man-end**********************************************************************/ -int PDC_CDECL PDC_getclipboard(char **contents, long *length) +int PDC_CDECL PDC_getclipboard(char **contents, long *length) { - HANDLE handle; - long len; + HANDLE handle; + long len; - PDC_LOG(("PDC_getclipboard() - called\n")); + PDC_LOG(("PDC_getclipboard() - called\n")); - if (OpenClipboard(NULL) == 0) - { - return PDC_CLIP_ACCESS_ERROR; - } - handle = GetClipboardData( CF_TEXT ); - if (handle == NULL) - { - CloseClipboard(); - return PDC_CLIP_EMPTY; - } + if (OpenClipboard(NULL) == 0) + return PDC_CLIP_ACCESS_ERROR; - len = strlen((char *)handle); - *contents = (char *)GlobalAlloc(GMEM_FIXED,len+1); - if (!*contents) - { - CloseClipboard(); - return PDC_CLIP_MEMORY_ERROR; - } - strcpy((char *)*contents,(char *)handle); - *length = len; - CloseClipboard(); + handle = GetClipboardData(CF_TEXT); + if (handle == NULL) + { + CloseClipboard(); + return PDC_CLIP_EMPTY; + } - return( PDC_CLIP_SUCCESS ); + len = strlen((char *)handle); + *contents = (char *)GlobalAlloc(GMEM_FIXED, len + 1); + + if (!*contents) + { + CloseClipboard(); + return PDC_CLIP_MEMORY_ERROR; + } + + strcpy((char *)*contents, (char *)handle); + *length = len; + CloseClipboard(); + + return PDC_CLIP_SUCCESS; } - /*man-start********************************************************************* PDC_setclipboard() - Sets the contents of the clipboard PDCurses Description: - This is a PDCurses only routine. + This is a PDCurses-only routine. - Copies the supplied text into the system's clipboard, emptying - the clipboard prior to the copy. + Copies the supplied text into the system's clipboard, emptying + the clipboard prior to the copy. PDCurses Return Value: - indicator of success/failure of call. - PDC_CLIP_SUCCESS the call was successful - PDC_CLIP_ACCESS_ERROR an error occured while accessing the - clipboard + indicator of success/failure of call. + PDC_CLIP_SUCCESS the call was successful + PDC_CLIP_ACCESS_ERROR an error occured while accessing the + clipboard Portability: - PDCurses int PDC_getclipboard( char *contents, long length ); + PDCurses int PDC_getclipboard(char *contents, long length); **man-end**********************************************************************/ -int PDC_CDECL PDC_setclipboard(char *contents, long length) +int PDC_CDECL PDC_setclipboard(char *contents, long length) { - HGLOBAL ptr1; - LPTSTR ptr2; + HGLOBAL ptr1; + LPTSTR ptr2; - PDC_LOG(("PDC_setclipboard() - called\n")); + PDC_LOG(("PDC_setclipboard() - called\n")); - if (OpenClipboard(NULL) == 0) - { - return PDC_CLIP_ACCESS_ERROR; - } - ptr1 = GlobalAlloc(GMEM_MOVEABLE|GMEM_DDESHARE, (length+1)*sizeof(TCHAR) ); - if (!ptr1) - { - return PDC_CLIP_MEMORY_ERROR; - } + if (OpenClipboard(NULL) == 0) + return PDC_CLIP_ACCESS_ERROR; - ptr2 = GlobalLock(ptr1); - memcpy((char *)ptr2, (char *)contents, length+1 ); - GlobalUnlock(ptr1); - EmptyClipboard(); - if (SetClipboardData(CF_TEXT, ptr1) == NULL) - { - GlobalFree(ptr1); - return PDC_CLIP_ACCESS_ERROR; - } - CloseClipboard(); - GlobalFree(ptr1); - return PDC_CLIP_SUCCESS; + ptr1 = GlobalAlloc(GMEM_MOVEABLE|GMEM_DDESHARE, + (length + 1) * sizeof(TCHAR)); + + if (!ptr1) + return PDC_CLIP_MEMORY_ERROR; + + ptr2 = GlobalLock(ptr1); + + memcpy((char *)ptr2, (char *)contents, length + 1); + GlobalUnlock(ptr1); + EmptyClipboard(); + + if (SetClipboardData(CF_TEXT, ptr1) == NULL) + { + GlobalFree(ptr1); + return PDC_CLIP_ACCESS_ERROR; + } + + CloseClipboard(); + GlobalFree(ptr1); + + return PDC_CLIP_SUCCESS; } /*man-start********************************************************************* - PDC_freeclipboard() - Frees the memory associated with the contents of the clipboard + PDC_freeclipboard() - Frees the memory associated with the contents + of the clipboard PDCurses Description: - This is a PDCurses only routine. + This is a PDCurses only routine. - Frees the memory allocated by PDC_getclipboard(). + Frees the memory allocated by PDC_getclipboard(). PDCurses Return Value: - Always returns PDC_CLIP_SUCCESS + Always returns PDC_CLIP_SUCCESS Portability: - PDCurses int PDC_freeclipboard( char *contents ); + PDCurses int PDC_freeclipboard(char *contents); **man-end**********************************************************************/ -int PDC_CDECL PDC_freeclipboard(char *contents) +int PDC_CDECL PDC_freeclipboard(char *contents) { - PDC_LOG(("PDC_freeclipboard() - called\n")); + PDC_LOG(("PDC_freeclipboard() - called\n")); - GlobalFree(contents); - return PDC_CLIP_SUCCESS; + GlobalFree(contents); + return PDC_CLIP_SUCCESS; } /*man-start********************************************************************* @@ -168,24 +171,23 @@ int PDC_CDECL PDC_freeclipboard(char *contents) PDC_clearclipboard() - Clears the contents of the clipboard PDCurses Description: - This is a PDCurses only routine. + This is a PDCurses only routine. - Clears the internal clipboard. + Clears the internal clipboard. PDCurses Return Value: - Always returns PDC_CLIP_SUCCESS + Always returns PDC_CLIP_SUCCESS Portability: - PDCurses int PDC_clearclipboard( void ); + PDCurses int PDC_clearclipboard(void); **man-end**********************************************************************/ -int PDC_CDECL PDC_clearclipboard( void ) +int PDC_CDECL PDC_clearclipboard(void) { - PDC_LOG(("PDC_clearclipboard() - called\n")); + PDC_LOG(("PDC_clearclipboard() - called\n")); - EmptyClipboard(); + EmptyClipboard(); - return PDC_CLIP_SUCCESS; + return PDC_CLIP_SUCCESS; } - diff --git a/win32/pdcdisp.c b/win32/pdcdisp.c index 06b53dcb..ca7b588c 100644 --- a/win32/pdcdisp.c +++ b/win32/pdcdisp.c @@ -29,89 +29,87 @@ extern HANDLE hConOut; #ifdef PDCDEBUG -char *rcsid_PDCdisp = "$Id: pdcdisp.c,v 1.5 2006/01/03 19:54:29 wmcbrine Exp $"; +char *rcsid_PDCdisp = "$Id: pdcdisp.c,v 1.6 2006/01/08 11:53:43 wmcbrine Exp $"; #endif static CHAR_INFO ci[512]; + /*man-start********************************************************************* PDC_clr_update() - Updates the screen with a full redraw. PDCurses Description: - Updates the screen by clearing it and then redraw it in its - entirety. If SP->refrbrk is TRUE, and there is pending - input characters, the update will be prematurely terminated. + Updates the screen by clearing it and then redraw it in its + entirety. If SP->refrbrk is TRUE, and there is pending + input characters, the update will be prematurely terminated. PDCurses Return Value: - This routine returns ERR if it is unable to accomplish its task. + This routine returns ERR if it is unable to accomplish its task. - The return value OK is returned if there were no errors. + The return value OK is returned if there were no errors. PDCurses Errors: - No errors are defined for this function. + No errors are defined for this function. Portability: - PDCurses int PDC_clr_update( WINDOW* s ); + PDCurses int PDC_clr_update(WINDOW *s); **man-end**********************************************************************/ /***********************************************************************/ -int PDC_clr_update(WINDOW *s) +int PDC_clr_update(WINDOW *s) /***********************************************************************/ { - extern unsigned char atrtab[MAX_ATRTAB]; + extern unsigned char atrtab[MAX_ATRTAB]; - register int i, j; - register chtype *srcp; - WINDOW *w; - bool rc; - COORD bufSize, bufPos; - SMALL_RECT sr; + int i, j; + chtype *srcp; + COORD bufSize, bufPos; + SMALL_RECT sr; - PDC_LOG(("PDC_clr_update() - called\n")); + PDC_LOG(("PDC_clr_update() - called\n")); - w = curscr; - if (w == (WINDOW *)NULL) - return( ERR ); + if (curscr == (WINDOW *)NULL) + return ERR; #if 0 - if (SP->full_redraw) - PDC_clr_scrn(s); /* clear physical screen */ + if (SP->full_redraw) + PDC_clr_scrn(s); /* clear physical screen */ #endif + s->_clear = FALSE; + bufPos.X = bufPos.Y = 0; + bufSize.X = COLS; + bufSize.Y = 1; + sr.Left = 0; + sr.Right = COLS - 1; - s->_clear = FALSE; - bufPos.X = bufPos.Y = 0; - bufSize.X = COLS; - bufSize.Y = 1; - sr.Left = 0; - sr.Right = COLS - 1; - for (i = 0; i < LINES; i++) /* update physical screen */ - { - if (s != w) - memcpy(w->_y[i], s->_y[i], COLS * sizeof(chtype)); + for (i = 0; i < LINES; i++) /* update physical screen */ + { + if (s != curscr) + memcpy(curscr->_y[i], s->_y[i], COLS * sizeof(chtype)); - srcp = s->_y[i]; + srcp = s->_y[i]; - sr.Top = i; - sr.Bottom = i; + sr.Top = i; + sr.Bottom = i; - for (j = 0; j < COLS; j++) - { - ci[j].Char.AsciiChar = *(srcp+j) & A_CHARTEXT; - ci[j].Attributes = (chtype_attr(*(srcp+j)) & 0xFF00) >> 8 ; + for (j = 0; j < COLS; j++) + { + ci[j].Char.AsciiChar = srcp[j] & A_CHARTEXT; + ci[j].Attributes = + (chtype_attr(srcp[j]) & 0xFF00) >> 8; #ifdef HIDE_ATTR - ci[j].Attributes = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE; + ci[j].Attributes = COLOR_WHITE; #endif - } - WriteConsoleOutput(hConOut, ci, bufSize, bufPos, &sr); + } - if (SP->refrbrk && (SP->cbreak || SP->raw_inp)) - { - rc = PDC_breakout(); - if (rc) - break; - } - } - return( OK ); + WriteConsoleOutput(hConOut, ci, bufSize, bufPos, &sr); + + if (SP->refrbrk && (SP->cbreak || SP->raw_inp) + && PDC_breakout()) + break; + } + + return OK; } /*man-start********************************************************************* @@ -119,32 +117,33 @@ int PDC_clr_update(WINDOW *s) PDC_cursor_on() - Turns on the hardware cursor. PDCurses Description: - Turns on the hardware curses, it does nothing if it is already on. + Turns on the hardware cursor; does nothing if it is already on. PDCurses Return Value: - Returns OK upon success, ERR upon failure. + Returns OK upon success, ERR upon failure. Portability: - PDCurses int PDC_cursor_on( void ); + PDCurses int PDC_cursor_on(void); **man-end**********************************************************************/ /***********************************************************************/ -int PDC_cursor_on(void) +int PDC_cursor_on(void) /***********************************************************************/ { - CONSOLE_CURSOR_INFO cci; + CONSOLE_CURSOR_INFO cci; - PDC_LOG(("PDC_cursor_on() - called\n")); + PDC_LOG(("PDC_cursor_on() - called\n")); - if (!SP->visible_cursor) - { - SP->visible_cursor = TRUE; - GetConsoleCursorInfo(hConOut,&cci); - cci.bVisible = TRUE; - SetConsoleCursorInfo(hConOut,&cci); - } - return( OK ); + if (!SP->visible_cursor) + { + SP->visible_cursor = TRUE; + GetConsoleCursorInfo(hConOut, &cci); + cci.bVisible = TRUE; + SetConsoleCursorInfo(hConOut, &cci); + } + + return OK; } /*man-start********************************************************************* @@ -152,37 +151,36 @@ int PDC_cursor_on(void) PDC_cursor_off() - Turns off the hardware cursor. PDCurses Description: - Turns off the hardware curses, it does nothing if it is already off. + Turns off the hardware cursor; does nothing if it is already off. PDCurses Return Value: - Returns OK upon success, ERR upon failure. + Returns OK upon success, ERR upon failure. PDCurses Errors: - ERR will be returned if the hardware cursor - can not be disabled. + ERR will be returned if the hardware cursor can not be disabled. Portability: - PDCurses int PDC_cursor_off( void ); + PDCurses int PDC_cursor_off(void); **man-end**********************************************************************/ /***********************************************************************/ -int PDC_cursor_off(void) +int PDC_cursor_off(void) /***********************************************************************/ { - CONSOLE_CURSOR_INFO cci; + CONSOLE_CURSOR_INFO cci; - PDC_LOG(("PDC_cursor_off() - called\n")); + PDC_LOG(("PDC_cursor_off() - called\n")); - if (SP->visible_cursor) - { - SP->visible_cursor = FALSE; - GetConsoleCursorInfo(hConOut,&cci); - cci.bVisible = FALSE; - SetConsoleCursorInfo(hConOut,&cci); - } + if (SP->visible_cursor) + { + SP->visible_cursor = FALSE; + GetConsoleCursorInfo(hConOut, &cci); + cci.bVisible = FALSE; + SetConsoleCursorInfo(hConOut, &cci); + } - return( OK ); + return OK; } /*man-start********************************************************************* @@ -190,34 +188,35 @@ int PDC_cursor_off(void) PDC_fix_cursor() - Fix the cursor start and stop scan lines (if necessary) PDCurses Description: - This is a private PDCurses routine. + This is a private PDCurses routine. - This routine will fix the cursor shape for certain video adapters. - Normally, the values used are correct, but some adapters choke. - The most noticable choke is on a monochrome adapter. The "correct" - scan lines will result in the cursor being set in the middle of the - character cell, rather than at the bottom. + This routine will fix the cursor shape for certain video + adapters. Normally, the values used are correct, but some + adapters choke. The most noticable choke is on a monochrome + adapter. The "correct" scan lines will result in the cursor + being set in the middle of the character cell, rather than at + the bottom. - The passed flag indicates whether the cursor is visible or not. + The passed flag indicates whether the cursor is visible or not. - This only applies to the DOS platform. + This only applies to the DOS platform. PDCurses Return Value: - This function returns OK on success and ERR on error. + This function returns OK on success and ERR on error. PDCurses Errors: - No errors are defined for this function. + No errors are defined for this function. Portability: - PDCurses int PDC_fix_cursor( int flag ); + PDCurses int PDC_fix_cursor(int flag); **man-end**********************************************************************/ /***********************************************************************/ -int PDC_fix_cursor(int flag) +int PDC_fix_cursor(int flag) /***********************************************************************/ { - return(OK); + return OK; } /*man-start********************************************************************* @@ -225,36 +224,38 @@ int PDC_fix_cursor(int flag) PDC_gotoxy() - position hardware cursor at (x, y) PDCurses Description: - This is a private PDCurses routine. + This is a private PDCurses routine. - Moves the physical cursor to the desired address on the - screen. We don't optimize here -- on a PC, it takes more time - to optimize than to do things directly. + Moves the physical cursor to the desired address on the screen. + We don't optimize here -- on a PC, it takes more time to + optimize than to do things directly. PDCurses Return Value: - This function returns OK on success and ERR on error. + This function returns OK on success and ERR on error. PDCurses Errors: - No errors are defined for this function. + No errors are defined for this function. Portability: - PDCurses int PDC_gotoxy( int row, int col ); + PDCurses int PDC_gotoxy(int row, int col); **man-end**********************************************************************/ /***********************************************************************/ -int PDC_gotoxy(int row, int col) +int PDC_gotoxy(int row, int col) /***********************************************************************/ { - COORD coord; + COORD coord; - PDC_LOG(("PDC_gotoxy() - called: row %d col %d from row %d col %d\n", row, col, SP->cursrow, SP->curscol )); + PDC_LOG(("PDC_gotoxy() - called: row %d col %d from row %d col %d\n", + row, col, SP->cursrow, SP->curscol)); - coord.X = col; - coord.Y = row; + coord.X = col; + coord.Y = row; - SetConsoleCursorPosition(hConOut, coord); - return(OK); + SetConsoleCursorPosition(hConOut, coord); + + return OK; } /*man-start********************************************************************* @@ -262,44 +263,47 @@ int PDC_gotoxy(int row, int col) PDC_putc() - Output a character in the current attribute. PDCurses Description: - This is a private PDCurses routine. + This is a private PDCurses routine. - Outputs character 'chr' to screen in tty fashion. If a colour - mode is active, the character is written with colour 'colour'. + Outputs character 'chr' to screen in tty fashion. If a colour + mode is active, the character is written with colour 'colour'. PDCurses Return Value: - This function returns OK on success and ERR on error. + This function returns OK on success and ERR on error. PDCurses Errors: - No errors are defined for this function. + No errors are defined for this function. Portability: - PDCurses int PDC_putc( chtype character, chtype color ); + PDCurses int PDC_putc(chtype character, chtype color); **man-end**********************************************************************/ /***********************************************************************/ -int PDC_putc( chtype character, chtype color ) +int PDC_putc(chtype character, chtype color) /***********************************************************************/ { - int curRow, curCol; - WORD buffer[2]; - COORD coord; - DWORD written; + int curRow, curCol; + WORD buffer[2]; + COORD coord; + DWORD written; - PDC_LOG(("PDC_putc() - called:char=%c attrib=0x%x color=0x%x\n",character & A_CHARTEXT,character & A_ATTRIBUTES,color)); + PDC_LOG(("PDC_putc() - called:char=%c attrib=0x%x color=0x%x\n", + character & A_CHARTEXT, character & A_ATTRIBUTES, color)); - buffer[0] = color; - PDC_get_cursor_pos (&curRow, &curCol); + PDC_get_cursor_pos(&curRow, &curCol); - coord.X = curCol; - coord.Y = curRow; -// WriteConsoleOutputAttribute(hConOut, &buffer, 1, coord, &written); + coord.X = curCol; + coord.Y = curRow; +#if 0 + buffer[0] = color; + WriteConsoleOutputAttribute(hConOut, &buffer, 1, coord, &written); +#endif + buffer[0] = character; + WriteConsoleOutputCharacter(hConOut, (char*)&buffer[0], 1, + coord, &written); - buffer[0] = character; - WriteConsoleOutputCharacter(hConOut, (char*)&buffer[0], 1, coord, &written); - - return (OK); + return OK; } /*man-start********************************************************************* @@ -307,46 +311,49 @@ int PDC_putc( chtype character, chtype color ) PDC_putctty() - Output a character and attribute in TTY fashion. PDCurses Description: - This is a private PDCurses routine. + This is a private PDCurses routine. - Outputs character 'chr' to screen in tty fashion. If a colour - mode is active, the character is written with colour 'colour'. + Outputs character 'chr' to screen in tty fashion. If a colour + mode is active, the character is written with colour 'colour'. - This function moves the physical cursor after writing so the - screen will scroll if necessary. + This function moves the physical cursor after writing so the + screen will scroll if necessary. PDCurses Return Value: - This function returns OK on success and ERR on error. + This function returns OK on success and ERR on error. PDCurses Errors: - No errors are defined for this function. + No errors are defined for this function. Portability: - PDCurses int PDC_putctty( chtype character, chtype color ); + PDCurses int PDC_putctty(chtype character, chtype color); **man-end**********************************************************************/ /***********************************************************************/ -int PDC_putctty( chtype character, chtype color ) +int PDC_putctty(chtype character, chtype color) /***********************************************************************/ { - int curRow=0, curCol=0; - WORD buffer; - COORD coord; - DWORD written; + int curRow, curCol; + WORD buffer; + COORD coord; + DWORD written; - PDC_LOG(("PDC_putctty() - called\n")); + PDC_LOG(("PDC_putctty() - called\n")); - buffer = color; - PDC_get_cursor_pos (&curRow, &curCol); - coord.X = curCol; - coord.Y = curRow; -// WriteConsoleOutputAttribute(hConOut, &buffer, 1, coord, &written); + PDC_get_cursor_pos(&curRow, &curCol); - buffer = character; - WriteConsoleOutputCharacter(hConOut, (char*)&buffer, 1, coord, &written); + coord.X = curCol; + coord.Y = curRow; +#if 0 + buffer = color; + WriteConsoleOutputAttribute(hConOut, &buffer, 1, coord, &written); +#endif + buffer = character; + WriteConsoleOutputCharacter(hConOut, (char*)&buffer, 1, + coord, &written); - return (OK); + return OK; } /*man-start********************************************************************* @@ -354,29 +361,31 @@ int PDC_putctty( chtype character, chtype color ) PDC_scroll() - low level screen scroll PDCurses Description: - Scrolls a window in the current page up or down. Urow, lcol, - lrow, rcol are the window coordinates. Lines is the number of - lines to scroll. If 0, clears the window, if < 0 scrolls down, - if > 0 scrolls up. Blanks areas that are left, and sets - character attributes to attr. If in a colour graphics mode, - fills them with the colour 'attr' instead. + Scrolls a window in the current page up or down. Urow, lcol, + lrow, rcol are the window coordinates. Lines is the number of + lines to scroll. If 0, clears the window, if < 0 scrolls down, + if > 0 scrolls up. Blanks areas that are left, and sets + character attributes to attr. If in a colour graphics mode, + fills them with the colour 'attr' instead. PDCurses Return Value: - The PDC_scroll() function returns OK on success otherwise ERR is returned. + The PDC_scroll() function returns OK on success otherwise ERR is + returned. Portability: - PDCurses int PDC_scroll( int urow, int lcol, int rcol, - int nlines, chtype attr ); + PDCurses int PDC_scroll(int urow, int lcol, int rcol, + int nlines, chtype attr); **man-end**********************************************************************/ /***********************************************************************/ -int PDC_scroll(int urow, int lcol, int lrow, int rcol, int nlines, chtype attr) +int PDC_scroll(int urow, int lcol, int lrow, int rcol, int nlines, chtype attr) /***********************************************************************/ { - PDC_LOG(("PDC_scroll() - called: urow %d lcol %d lrow %d rcol %d nlines %d\n",urow,lcol,lrow,rcol,nlines)); + PDC_LOG(("PDC_scroll() - called: urow %d lcol %d lrow %d rcol %d nlines %d\n", + urow, lcol, lrow, rcol, nlines)); - return( OK ); + return OK; } /*man-start********************************************************************* @@ -384,80 +393,74 @@ int PDC_scroll(int urow, int lcol, int lrow, int rcol, int nlines, chtype attr PDC_transform_line() - display a physical line of the screen PDCurses Description: - This is a private PDCurses function. + This is a private PDCurses function. - Updates the given physical line to look like the corresponding - line in _curscr. + Updates the given physical line to look like the corresponding + line in _curscr. PDCurses Return Value: - This routine returns TRUE if a premature refresh end - is allowed, and there is an input character pending. Otherwise, - FALSE is returned. + This routine returns TRUE if a premature refresh end + is allowed, and there is an input character pending. Otherwise, + FALSE is returned. PDCurses Errors: - No errors are defined for this routine. + No errors are defined for this routine. Portability: - PDCurses bool PDC_transform_line( int lineno ); + PDCurses bool PDC_transform_line(int lineno); **man-end**********************************************************************/ /***********************************************************************/ -bool PDC_transform_line(register int lineno) +bool PDC_transform_line(int lineno) /***********************************************************************/ { - extern unsigned char atrtab[MAX_ATRTAB]; + extern unsigned char atrtab[MAX_ATRTAB]; - register int j; - register chtype *srcp; - int x; - int endx; - int len; - bool rc; - COORD bufSize, bufPos; - SMALL_RECT sr; + int j, x, endx, len; + chtype *srcp; + COORD bufSize, bufPos; + SMALL_RECT sr; - PDC_LOG(("PDC_transform_line() - called: lineno=%d\n",lineno)); + PDC_LOG(("PDC_transform_line() - called: lineno=%d\n", lineno)); - if (curscr == (WINDOW *)NULL) - return( FALSE ); + if (curscr == (WINDOW *)NULL) + return FALSE; - x = curscr->_firstch[lineno]; - endx = curscr->_lastch[lineno]; - srcp = curscr->_y[lineno] + x; - len = endx-x+1; + x = curscr->_firstch[lineno]; + endx = curscr->_lastch[lineno]; + srcp = curscr->_y[lineno] + x; + len = endx - x + 1; - bufPos.X = bufPos.Y = 0; + bufPos.X = bufPos.Y = 0; - bufSize.X = len; - bufSize.Y = 1; + bufSize.X = len; + bufSize.Y = 1; - sr.Top = lineno; - sr.Bottom = lineno; - sr.Left = x; - sr.Right = endx; + sr.Top = lineno; + sr.Bottom = lineno; + sr.Left = x; + sr.Right = endx; - for (j = 0; j < len; j++) - { - ci[j].Char.AsciiChar = *(srcp+j) & A_CHARTEXT; - ci[j].Attributes = (chtype_attr(*(srcp+j)) & 0xFF00) >> 8 ; + for (j = 0; j < len; j++) + { + ci[j].Char.AsciiChar = srcp[j] & A_CHARTEXT; + ci[j].Attributes = (chtype_attr(srcp[j]) & 0xFF00) >> 8; #ifdef HIDE_ATTR - ci[j].Attributes = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE; + ci[j].Attributes = COLOR_WHITE; #endif - } + } - WriteConsoleOutput(hConOut, ci, bufSize, bufPos, &sr); + WriteConsoleOutput(hConOut, ci, bufSize, bufPos, &sr); - curscr->_firstch[lineno] = _NO_CHANGE; - curscr->_lastch[lineno] = _NO_CHANGE; + curscr->_firstch[lineno] = _NO_CHANGE; + curscr->_lastch[lineno] = _NO_CHANGE; - if (SP->refrbrk && (SP->cbreak || SP->raw_inp)) - { - rc = PDC_breakout(); - if (rc) - return(TRUE); - } - return(FALSE); + if (SP->refrbrk && (SP->cbreak || SP->raw_inp) + && PDC_breakout()) + return(TRUE); + + return FALSE; } /*man-start********************************************************************* @@ -465,18 +468,18 @@ bool PDC_transform_line(register int lineno) PDC_doupdate() - display updated data in one call (Win32 only) PDCurses Description: - This is a private PDCurses function. + This is a private PDCurses function. - Updates the given physical screen to look like _curscr. + Updates the given physical screen to look like _curscr. PDCurses Return Value: - This routine returns nothing. + This routine returns nothing. PDCurses Errors: - No errors are defined for this routine. + No errors are defined for this routine. Portability: - PDCurses void PDC_doupdate( void ); + PDCurses void PDC_doupdate(void); **man-end**********************************************************************/ @@ -484,74 +487,79 @@ bool PDC_transform_line(register int lineno) void PDC_doupdate(void) /***********************************************************************/ { - extern unsigned char atrtab[MAX_ATRTAB]; + extern unsigned char atrtab[MAX_ATRTAB]; - register int i, j, k; - int starty = _NO_CHANGE, startx = _NO_CHANGE; - int size; - int endy = _NO_CHANGE, endx = _NO_CHANGE; - register chtype *srcp; - CHAR_INFO *ptr; - COORD bufSize, bufPos; - SMALL_RECT sr; + int i, j, k; + int starty = _NO_CHANGE, startx = _NO_CHANGE; + int size; + int endy = _NO_CHANGE, endx = _NO_CHANGE; + chtype *srcp; - PDC_LOG(("PDC_doupdate() - called:\n")); + CHAR_INFO *ptr; + COORD bufSize, bufPos; + SMALL_RECT sr; - if (curscr == (WINDOW *)NULL) - return; + PDC_LOG(("PDC_doupdate() - called:\n")); - for (i = 0; i < LINES; i++ ) - { - if (curscr->_firstch[i] != _NO_CHANGE) - { - if (starty == _NO_CHANGE) - starty = i; - endy = i; - if (startx == _NO_CHANGE - && curscr->_firstch[i] != _NO_CHANGE) - startx = curscr->_firstch[i]; - if (curscr->_firstch[i] < startx) - startx = curscr->_firstch[i]; - if (curscr->_lastch[i] > endx) - endx = curscr->_lastch[i]; - } - } - if (starty == _NO_CHANGE) /* nothing to do... */ - return; + if (curscr == (WINDOW *)NULL) + return; - size = ((endy - starty) + 1) * ((endx - startx) + 1); - ptr = (CHAR_INFO*)malloc(size*sizeof(CHAR_INFO)); - if (ptr == NULL) - return; + for (i = 0; i < LINES; i++) + if (curscr->_firstch[i] != _NO_CHANGE) + { + if (starty == _NO_CHANGE) + starty = i; - bufPos.X = bufPos.Y = 0; - bufSize.X = endx - startx + 1; - bufSize.Y = endy - starty + 1; + endy = i; - sr.Top = starty; - sr.Bottom = endy; - sr.Left = startx; - sr.Right = endx; + if (startx == _NO_CHANGE + && curscr->_firstch[i] != _NO_CHANGE) + startx = curscr->_firstch[i]; - k = 0; - for (i = starty; i <= endy; i++ ) - { - srcp = curscr->_y[i]; - for (j = startx; j <= endx; j++) - { - ptr[k].Char.AsciiChar = *(srcp+j) & A_CHARTEXT; - ptr[k].Attributes = (chtype_attr(*(srcp+j)) & 0xFF00) >> 8 ; + if (curscr->_firstch[i] < startx) + startx = curscr->_firstch[i]; + + if (curscr->_lastch[i] > endx) + endx = curscr->_lastch[i]; + } + + if (starty == _NO_CHANGE) /* nothing to do... */ + return; + + size = ((endy - starty) + 1) * ((endx - startx) + 1); + + ptr = (CHAR_INFO*)malloc(size * sizeof(CHAR_INFO)); + if (ptr == NULL) + return; + + bufPos.X = bufPos.Y = 0; + bufSize.X = endx - startx + 1; + bufSize.Y = endy - starty + 1; + + sr.Top = starty; + sr.Bottom = endy; + sr.Left = startx; + sr.Right = endx; + + k = 0; + + for (i = starty; i <= endy; i++) + { + srcp = curscr->_y[i]; + for (j = startx; j <= endx; j++) + { + ptr[k].Char.AsciiChar = srcp[j] & A_CHARTEXT; + ptr[k].Attributes = + (chtype_attr(srcp[j]) & 0xFF00) >> 8; #ifdef HIDE_ATTR - ptr[k].Attributes = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE; + ptr[k].Attributes = COLOR_WHITE; #endif - k++; - } - curscr->_firstch[i] = _NO_CHANGE; - curscr->_lastch[i] = _NO_CHANGE; - } + k++; + } + curscr->_firstch[i] = _NO_CHANGE; + curscr->_lastch[i] = _NO_CHANGE; + } - WriteConsoleOutput(hConOut, ptr, bufSize, bufPos, &sr); - free(ptr); - return; + WriteConsoleOutput(hConOut, ptr, bufSize, bufPos, &sr); + free(ptr); } - diff --git a/win32/pdcgetsc.c b/win32/pdcgetsc.c index 9c55f48a..c2a1af92 100644 --- a/win32/pdcgetsc.c +++ b/win32/pdcgetsc.c @@ -22,7 +22,7 @@ #include #ifdef PDCDEBUG -char *rcsid_PDCgetsc = "$Id: pdcgetsc.c,v 1.4 2006/01/03 19:54:29 wmcbrine Exp $"; +char *rcsid_PDCgetsc = "$Id: pdcgetsc.c,v 1.5 2006/01/08 11:53:43 wmcbrine Exp $"; #endif extern HANDLE hConOut, hConIn; @@ -33,32 +33,34 @@ extern CONSOLE_SCREEN_BUFFER_INFO scr; PDC_get_cursor_pos() - return current cursor position PDCurses Description: - This is a private PDCurses function + This is a private PDCurses function - Gets the cursor position in video page 0. 'row' and 'column' - are the cursor address. At this time, there is no support for - use of multiple screen pages. + Gets the cursor position in video page 0. 'row' and 'column' + are the cursor address. At this time, there is no support for + use of multiple screen pages. PDCurses Return Value: - This routine will return OK upon success and otherwise ERR will be - returned. + This routine will return OK upon success and otherwise ERR will + be returned. PDCurses Errors: - There are no defined errors for this routine. + There are no defined errors for this routine. Portability: - PDCurses int PDC_get_cursor_pos( int* row, int* col ); + PDCurses int PDC_get_cursor_pos(int *row, int *col); **man-end**********************************************************************/ -int PDC_get_cursor_pos(int *row, int *col) +int PDC_get_cursor_pos(int *row, int *col) { - PDC_LOG(("PDC_get_cursor_pos() - called\n")); + PDC_LOG(("PDC_get_cursor_pos() - called\n")); - GetConsoleScreenBufferInfo(hConOut, &scr); - *col = scr.dwCursorPosition.X; - *row = scr.dwCursorPosition.Y; - return(OK); + GetConsoleScreenBufferInfo(hConOut, &scr); + + *col = scr.dwCursorPosition.X; + *row = scr.dwCursorPosition.Y; + + return OK; } /*man-start********************************************************************* @@ -66,29 +68,30 @@ int PDC_get_cursor_pos(int *row, int *col) PDC_get_cur_col() - get current column position of cursor PDCurses Description: - This is a private PDCurses function + This is a private PDCurses function - This routine returns the current column position of the cursor on - screen. + This routine returns the current column position of the cursor + on screen. PDCurses Return Value: - This routine returns the current column position of the cursor. No - error is returned. + This routine returns the current column position of the cursor. + No error is returned. PDCurses Errors: - There are no defined errors for this routine. + There are no defined errors for this routine. Portability: - PDCurses int PDC_get_cur_col( void ); + PDCurses int PDC_get_cur_col(void); **man-end**********************************************************************/ -int PDC_get_cur_col(void) +int PDC_get_cur_col(void) { - PDC_LOG(("PDC_get_cur_col() - called\n")); + PDC_LOG(("PDC_get_cur_col() - called\n")); - GetConsoleScreenBufferInfo(hConOut, &scr); - return (scr.dwCursorPosition.X); + GetConsoleScreenBufferInfo(hConOut, &scr); + + return scr.dwCursorPosition.X; } /*man-start********************************************************************* @@ -96,60 +99,57 @@ int PDC_get_cur_col(void) PDC_get_cur_row() - get current row position of cursor PDCurses Description: - This is a private PDCurses function + This is a private PDCurses function - This routine returns the current row position of the cursor on - screen. + This routine returns the current row position of the cursor + on screen. PDCurses Return Value: - This routine returns the current row position of the cursor. No - error is returned. + This routine returns the current row position of the cursor. + No error is returned. PDCurses Errors: - There are no defined errors for this routine. + There are no defined errors for this routine. Portability: - PDCurses int PDC_get_cur_row( void ); + PDCurses int PDC_get_cur_row(void); **man-end**********************************************************************/ -int PDC_get_cur_row(void) +int PDC_get_cur_row(void) { - PDC_LOG(("PDC_get_cur_row() - called\n")); + PDC_LOG(("PDC_get_cur_row() - called\n")); - GetConsoleScreenBufferInfo(hConOut, &scr); - return (scr.dwCursorPosition.Y); + GetConsoleScreenBufferInfo(hConOut, &scr); + return scr.dwCursorPosition.Y; } -// Stopped Here... - /*man-start********************************************************************* PDC_get_attribute() - Get attribute at current cursor PDCurses Description: - This is a private PDCurses function + This is a private PDCurses function - Return the current attr at current cursor position on the screen. + Return the current attr at current cursor position on the screen. PDCurses Return Value: - This routine will return OK upon success and otherwise ERR will be - returned. + This routine will return OK upon success and otherwise ERR will + be returned. PDCurses Errors: - There are no defined errors for this routine. + There are no defined errors for this routine. Portability: - PDCurses int PDC_get_attribute( void ); + PDCurses int PDC_get_attribute(void); **man-end**********************************************************************/ -int PDC_get_attribute(void) +int PDC_get_attribute(void) { PDC_LOG(("PDC_get_attribute() - called\n")); -/* doesnt do anything !! */ - return(0); + return 0; } /*man-start********************************************************************* @@ -157,29 +157,32 @@ int PDC_get_attribute(void) PDC_get_cursor_mode() - Get the cursor start and stop scan lines. PDCurses Description: - Gets the cursor type to begin in scan line startrow and end in - scan line endrow. Both values should be 0-31. + Gets the cursor type to begin in scan line startrow and end in + scan line endrow. Both values should be in the range 0 through + 31. PDCurses Return Value: - This function returns OK on success and ERR on error. + This function returns OK on success and ERR on error. PDCurses Errors: - No errors are defined for this function. + No errors are defined for this function. Portability: - PDCurses int PDC_get_cursor_mode( void ); + PDCurses int PDC_get_cursor_mode(void); **man-end**********************************************************************/ -int PDC_get_cursor_mode(void) +int PDC_get_cursor_mode(void) { - CONSOLE_CURSOR_INFO ci; + CONSOLE_CURSOR_INFO ci; - PDC_LOG(("PDC_get_cursor_mode() - called\n")); + PDC_LOG(("PDC_get_cursor_mode() - called\n")); - GetConsoleCursorInfo(hConOut, &ci); -/* size is between 1 and 100, so convert it */ - return ((ci.dwSize * 32 / 100) - 1); + GetConsoleCursorInfo(hConOut, &ci); + + /* size is between 1 and 100, so convert it */ + + return ci.dwSize * 32 / 100 - 1; } /*man-start********************************************************************* @@ -187,27 +190,27 @@ int PDC_get_cursor_mode(void) PDC_get_font() - Get the current font size PDCurses Description: - This is a private PDCurses routine. + This is a private PDCurses routine. - This function returns the current font size. This function only - works if the #define FAST_VIDEO is true. + This function returns the current font size. This function only + works if the #define FAST_VIDEO is true. PDCurses Return Value: - This function returns OK on success and ERR on error. + This function returns OK on success and ERR on error. PDCurses Errors: - An ERR will be returned if FAST_VIDEO is not true. + An ERR will be returned if FAST_VIDEO is not true. Portability: - PDCurses int PDC_get_font( void ); + PDCurses int PDC_get_font(void); **man-end**********************************************************************/ -int PDC_get_font(void) +int PDC_get_font(void) { PDC_LOG(("PDC_get_font() - called\n")); - return(0); /* this is N/A */ + return 0; } /*man-start********************************************************************* @@ -215,31 +218,31 @@ int PDC_get_font(void) PDC_get_rows() - Return number of screen rows. PDCurses Description: - This is a private PDCurses routine. + This is a private PDCurses routine. - Returns the maximum number of rows supported by the display. - e.g. 25, 28, 43, 50, 60, 66... + Returns the maximum number of rows supported by the display. + e.g. 25, 28, 43, 50, 60, 66... PDCurses Return Value: - This function returns OK on success and ERR on error. + This function returns OK on success and ERR on error. PDCurses Errors: - No errors are defined for this function. + No errors are defined for this function. Portability: - PDCurses int PDC_get_rows( void ); + PDCurses int PDC_get_rows(void); **man-end**********************************************************************/ -int PDC_get_rows(void) +int PDC_get_rows(void) { - PDC_LOG(("PDC_get_rows() - called\n")); + PDC_LOG(("PDC_get_rows() - called\n")); - GetConsoleScreenBufferInfo(hConOut, &scr); + GetConsoleScreenBufferInfo(hConOut, &scr); #if FGC0 - return ( scr.dwSize.Y ); /* Allow the whole screen to be accessed */ + return scr.dwSize.Y; /* Allow the whole screen to be accessed */ #else - return (scr.srWindow.Bottom - scr.srWindow.Top + 1); + return scr.srWindow.Bottom - scr.srWindow.Top + 1; #endif } @@ -248,25 +251,26 @@ int PDC_get_rows(void) PDC_get_buffer_rows() - Return number of screen buffer rows. PDCurses Description: - This is a private PDCurses routine. + This is a private PDCurses routine. PDCurses Return Value: - Returns the maximum number of rows in the screen buffer. + Returns the maximum number of rows in the screen buffer. PDCurses Errors: - No errors are defined for this function. + No errors are defined for this function. Portability: - PDCurses int PDC_get_buffer_rows( void ); + PDCurses int PDC_get_buffer_rows(void); **man-end**********************************************************************/ -int PDC_get_buffer_rows(void) +int PDC_get_buffer_rows(void) { - PDC_LOG(("PDC_get_buffer_rows() - called\n")); + PDC_LOG(("PDC_get_buffer_rows() - called\n")); - GetConsoleScreenBufferInfo( hConOut, &scr ); - return ( scr.dwSize.Y ); + GetConsoleScreenBufferInfo(hConOut, &scr); + + return scr.dwSize.Y; } /*man-start********************************************************************* @@ -274,31 +278,31 @@ int PDC_get_buffer_rows(void) PDC_get_columns() - return width of screen/viewport. PDCurses Description: - This is a private PDCurses function + This is a private PDCurses function - This function will return the width of the current screen. + This function will return the width of the current screen. PDCurses Return Value: - This routine will return OK upon success and otherwise ERR will be - returned. + This routine will return OK upon success and otherwise ERR will + be returned. PDCurses Errors: - There are no defined errors for this routine. + There are no defined errors for this routine. Portability: - PDCurses int PDC_get_columns( void ); + PDCurses int PDC_get_columns(void); **man-end**********************************************************************/ -int PDC_get_columns(void) +int PDC_get_columns(void) { - PDC_LOG(("PDC_get_columns() - called\n")); + PDC_LOG(("PDC_get_columns() - called\n")); - GetConsoleScreenBufferInfo(hConOut, &scr); + GetConsoleScreenBufferInfo(hConOut, &scr); #if FGC0 - return ( scr.dwSize.X ); /* Allow the whole screen to be accessed */ + return scr.dwSize.X; /* Allow the whole screen to be accessed */ #else - return (scr.srWindow.Right - scr.srWindow.Left + 1); + return scr.srWindow.Right - scr.srWindow.Left + 1; #endif } @@ -307,22 +311,22 @@ int PDC_get_columns(void) PDC_get_scrn_mode() - Return the current BIOS video mode PDCurses Description: - This is a private PDCurses routine. + This is a private PDCurses routine. PDCurses Return Value: - Returns the current BIOS Video Mode Number. + Returns the current BIOS Video Mode Number. Portability: - PDCurses int PDC_get_scrn_mode( void ); + PDCurses int PDC_get_scrn_mode(void); **man-end**********************************************************************/ -int PDC_get_scrn_mode(void) +int PDC_get_scrn_mode(void) { PDC_LOG(("PDC_get_scrn_mode() - called\n")); - return(OK); + return OK; } /*man-start********************************************************************* @@ -330,35 +334,31 @@ int PDC_get_scrn_mode(void) PDC_query_adapter_type() - Determine PC video adapter type PDCurses Description: - This is a private PDCurses routine. + This is a private PDCurses routine. - Thanks to Jeff Duntemann, K16RA for providing the impetus - (through the Dr. Dobbs Journal, March 1989 issue) for getting - the routines below merged into Bjorn Larsson's PDCurses 1.3... - -- frotz@dri.com 900730 + Thanks to Jeff Duntemann, K16RA for providing the impetus + (through the Dr. Dobbs Journal, March 1989 issue) for getting + the routines below merged into Bjorn Larsson's PDCurses 1.3... + -- frotz@dri.com 900730 PDCurses Return Value: - This function returns a macro identifier indicating the adapter - type. See the list of adapter types in CURSPRIV.H. + This function returns a macro identifier indicating the adapter + type. See the list of adapter types in CURSPRIV.H. PDCurses Errors: - No errors are defined for this function. + No errors are defined for this function. Portability: - PDCurses int PDC_query_adapter_type( void ); + PDCurses int PDC_query_adapter_type(void); **man-end**********************************************************************/ -int PDC_query_adapter_type(void) +int PDC_query_adapter_type(void) { - int retval; - PDC_LOG(("PDC_query_adapter_type() - called\n")); SP->mono = FALSE; - retval = _VGACOLOR; - - return (retval); + return _VGACOLOR; } /*man-start********************************************************************* @@ -366,24 +366,24 @@ int PDC_query_adapter_type(void) PDC_sanity_check() - A video adapter identification sanity check PDCurses Description: - This is a private PDCurses routine. + This is a private PDCurses routine. - This routine will force sane values for various control flags. + This routine will force sane values for various control flags. PDCurses Return Value: - This function returns OK on success and ERR on error. + This function returns OK on success and ERR on error. PDCurses Errors: - No errors are defined for this function. + No errors are defined for this function. Portability: - PDCurses int PDC_sanity_check( int adapter ); + PDCurses int PDC_sanity_check(int adapter); **man-end**********************************************************************/ -int PDC_sanity_check(int adapter) +int PDC_sanity_check(int adapter) { - PDC_LOG(("PDC_sanity_check() - called: Adapter %d\n",adapter)); + PDC_LOG(("PDC_sanity_check() - called: Adapter %d\n", adapter)); - return (adapter); + return adapter; } diff --git a/win32/pdckbd.c b/win32/pdckbd.c index 3cc51f73..20b4f491 100644 --- a/win32/pdckbd.c +++ b/win32/pdckbd.c @@ -25,16 +25,15 @@ #include #ifdef PDCDEBUG -char *rcsid_PDCkbd = "$Id: pdckbd.c,v 1.23 2006/01/06 10:23:28 wmcbrine Exp $"; +char *rcsid_PDCkbd = "$Id: pdckbd.c,v 1.24 2006/01/08 11:53:43 wmcbrine Exp $"; #endif #define KEY_STATE TRUE #define MS_MOUSE_MOVED 1 -/* - * MingW32 header files are missing the following in some versions - * of the compiler - */ +/* MingW32 header files are missing the following in some versions + of the compiler */ + #ifndef DOUBLE_CLICK # define DOUBLE_CLICK 0x0002 #endif @@ -54,12 +53,12 @@ char *rcsid_PDCkbd = "$Id: pdckbd.c,v 1.23 2006/01/06 10:23:28 wmcbrine Exp $"; #ifndef RIGHTMOST_BUTTON_PRESSED # define RIGHTMOST_BUTTON_PRESSED 0x0002 #endif -/* - * These variables are used to store information about the next - * Input Event. - */ + +/* These variables are used to store information about the next + Input Event. */ + INPUT_RECORD save_ip; -static unsigned long pdc_key_modifiers=0L; +static unsigned long pdc_key_modifiers = 0L; extern HANDLE hConIn; @@ -74,24 +73,24 @@ static int keyCount = 0; static void win32_getch(void); static int win32_kbhit(int); -/******************************************************************************* +/****************************************************************************** * Table for key code translation of function keys in keypad mode * These values are for strict IBM keyboard compatibles only -*******************************************************************************/ +******************************************************************************/ typedef struct { - int normal; - int shift; - int control; - int alt; - int extended; + int normal; + int shift; + int control; + int alt; + int extended; } KPTAB; static KPTAB kptab[] = { {0, 0, 0, 0, 0 }, /* 0 */ - {0, 0, 0, 0, 0 }, /* 1 VK_LBUTTON */ + {0, 0, 0, 0, 0 }, /* 1 VK_LBUTTON */ {0, 0, 0, 0, 0 }, /* 2 VK_RBUTTON */ {0, 0, 0, 0, 0 }, /* 3 VK_CANCEL */ {0, 0, 0, 0, 0 }, /* 4 VK_MBUTTON */ @@ -335,7 +334,8 @@ static KPTAB ext_kptab[] = {KEY_DC, KEY_SDC, CTL_DEL, ALT_DEL }, /* 46 */ {PADSLASH, SHF_PADSLASH, CTL_PADSLASH,ALT_PADSLASH}, /* 191 */ }; - /* End of kptab[] */ + +/* End of kptab[] */ MOUSE_STATUS Trapped_Mouse_status; @@ -344,19 +344,19 @@ MOUSE_STATUS Trapped_Mouse_status; PDC_get_input_fd() - Get file descriptor used for PDCurses input PDCurses Description: - This is a private PDCurses routine. + This is a private PDCurses routine. - This routine will return the file descriptor that PDCurses reads - its input from. It can be used for WaitForMulitpleObjects() + This routine will return the file descriptor that PDCurses reads + its input from. It can be used for WaitForMulitpleObjects(). PDCurses Return Value: - Returns a HANDLE. + Returns a HANDLE. PDCurses Errors: - No errors are defined for this function. + No errors are defined for this function. Portability: - PDCurses int PDC_get_input_fd( void ); + PDCurses int PDC_get_input_fd(void); **man-end**********************************************************************/ @@ -368,12 +368,12 @@ unsigned long PDC_get_input_fd() #endif /***********************************************************************/ { - PDC_LOG(("PDC_get_input_fd() - called\n")); + PDC_LOG(("PDC_get_input_fd() - called\n")); #if defined(PDC_THREAD_BUILD) - return (unsigned long)hSemKeyCount; + return (unsigned long)hSemKeyCount; #else - return 0L; + return 0L; #endif } @@ -382,157 +382,155 @@ unsigned long PDC_get_input_fd() PDC_check_bios_key() - Check BIOS key data area for input PDCurses Description: - This is a private PDCurses routine. + This is a private PDCurses routine. - This routine will check the BIOS for any indication that - keystrokes are pending. + This routine will check the BIOS for any indication that + keystrokes are pending. PDCurses Return Value: - Returns 1 if a keyboard character is available, 0 otherwise. + Returns 1 if a keyboard character is available, 0 otherwise. PDCurses Errors: - No errors are defined for this function. + No errors are defined for this function. Portability: - PDCurses bool PDC_check_bios_key( void ); + PDCurses bool PDC_check_bios_key(void); **man-end**********************************************************************/ bool PDC_check_bios_key(void) { - return(win32_kbhit(0)); + return win32_kbhit(0); } -/* - * processKeyEvent returns -1 if the key in save_ip should be ignored for some - * reasons. Otherwise the keycode is returned which should be returned by - * PDC_get_bios_code. - * save_ip MUST BE A KEY_EVENT! - * - * The Unicode support has been disabled. See below for the reason. - * CTRL-ALT support has been disabled, when is it emitted plainly? - */ + /* processKeyEvent returns -1 if the key in save_ip should be ignored + for some reasons. Otherwise the keycode is returned which should be + returned by PDC_get_bios_code. save_ip MUST BE A KEY_EVENT! + + The Unicode support has been disabled. See below for the reason. + CTRL-ALT support has been disabled, when is it emitted plainly? */ + int processKeyEvent(void) { - CHAR ascii = save_ip.Event.KeyEvent.uChar.AsciiChar; + CHAR ascii = save_ip.Event.KeyEvent.uChar.AsciiChar; #if 0 - WCHAR unicode = save_ip.Event.KeyEvent.uChar.UnicodeChar; + WCHAR unicode = save_ip.Event.KeyEvent.uChar.UnicodeChar; #endif - WORD vk = save_ip.Event.KeyEvent.wVirtualKeyCode; - DWORD state = save_ip.Event.KeyEvent.dwControlKeyState; - unsigned long local_key_modifiers = 0L; - int idx; - BOOL enhanced; + WORD vk = save_ip.Event.KeyEvent.wVirtualKeyCode; + DWORD state = save_ip.Event.KeyEvent.dwControlKeyState; + unsigned long local_key_modifiers = 0L; + int idx; + BOOL enhanced; #if 0 - { - char buf[KL_NAMELENGTH]; - GetKeyboardLayoutName( buf ); - fprintf(stderr,"OS=%X, AsciiChar: %u=%02X Unicode: %u=%02X KeyCode: %d ScanCode: %d State: %x Name: %s\n", - SP->os_version, - (unsigned char) ascii, - (unsigned char) ascii, - unicode, - unicode, - vk, - save_ip.Event.KeyEvent.wVirtualScanCode, - state, - buf); - } + { + char buf[KL_NAMELENGTH]; + GetKeyboardLayoutName(buf); + + fprintf(stderr, + "OS=%X, AsciiChar: %u=%02X Unicode: %u=%02X KeyCode: %d ScanCode: %d State: %x Name: %s\n", + + SP->os_version, (unsigned char) ascii, + (unsigned char) ascii, unicode, unicode, vk, + save_ip.Event.KeyEvent.wVirtualScanCode, state, buf); + } #endif + pdc_key_modifiers = 0L; - pdc_key_modifiers = 0L; + /* Must calculate the key modifiers so that Alt keys work! Save the key + modifiers if required. Do this first to allow to detect e.g. a + pressed CTRL key after a hit of NUMLOCK. */ - /* - * Must calculate the key modifiers so that Alt keys work! - * Save the key modifiers if required. - * Do this first to allow to detect e.g. a pressed CTRL key - * after a hit of NUMLOCK. - */ - if (state & LEFT_ALT_PRESSED || state & RIGHT_ALT_PRESSED) - local_key_modifiers |= PDC_KEY_MODIFIER_ALT; - if (state & SHIFT_PRESSED) - local_key_modifiers |= PDC_KEY_MODIFIER_SHIFT; - if (state & LEFT_CTRL_PRESSED || state & RIGHT_CTRL_PRESSED) - local_key_modifiers |= PDC_KEY_MODIFIER_CONTROL; - if (state & NUMLOCK_ON) - local_key_modifiers |= PDC_KEY_MODIFIER_NUMLOCK; - pdc_key_modifiers = SP->save_key_modifiers ? local_key_modifiers : 0; + if (state & LEFT_ALT_PRESSED || state & RIGHT_ALT_PRESSED) + local_key_modifiers |= PDC_KEY_MODIFIER_ALT; + + if (state & SHIFT_PRESSED) + local_key_modifiers |= PDC_KEY_MODIFIER_SHIFT; + + if (state & LEFT_CTRL_PRESSED || state & RIGHT_CTRL_PRESSED) + local_key_modifiers |= PDC_KEY_MODIFIER_CONTROL; + + if (state & NUMLOCK_ON) + local_key_modifiers |= PDC_KEY_MODIFIER_NUMLOCK; + + pdc_key_modifiers = SP->save_key_modifiers ? local_key_modifiers : 0; - /* - * Handle modifier keys hit by themselves - */ + /* Handle modifier keys hit by themselves */ - switch (vk) - { - case VK_SHIFT: /* shift */ - if ( !SP->return_key_modifiers ) - return -1; - return KEY_SHIFT_R; + switch (vk) + { + case VK_SHIFT: /* shift */ + if (!SP->return_key_modifiers) + return -1; - case VK_CONTROL: /* control */ - if ( !SP->return_key_modifiers ) - return -1; - return (state & LEFT_CTRL_PRESSED) ? KEY_CONTROL_L : KEY_CONTROL_R; + return KEY_SHIFT_R; - case VK_MENU: /* alt */ - if ( !SP->return_key_modifiers ) - return -1; - return (state & LEFT_ALT_PRESSED) ? KEY_ALT_L : KEY_ALT_R; + case VK_CONTROL: /* control */ + if (!SP->return_key_modifiers) + return -1; - default: - break; - } + return (state & LEFT_CTRL_PRESSED) ? + KEY_CONTROL_L : KEY_CONTROL_R; + + case VK_MENU: /* alt */ + if (!SP->return_key_modifiers) + return -1; + + return (state & LEFT_ALT_PRESSED) ? + KEY_ALT_L : KEY_ALT_R; + } + + /* The system may emit Ascii or Unicode characters depending on whether + ReadConsoleInputA or ReadConsoleInputW is used. We use + ReadConsoleInputA in all cases currently, so we just check Ascii. + Unicode characters are very hard to implement, because our "special + keys" like KEY_F(1) is one of the unicode range. + + Now the ridiculous part of the processing. Normally, if ascii != 0 + then the system did the translation successfully. But this is not + true for LEFT_ALT (different to RIGHT_ALT) in case of LEFT_ALT we + get we get ascii != 0. So check for this first. */ + + if ((ascii != 0) && (((state & LEFT_ALT_PRESSED) == 0) || + (state & RIGHT_ALT_PRESSED))) + { + + /* This code should catch all keys returning a printable + character. Characters above 0x7F should be returned as + positive codes. But if'ndef NUMKEYPAD we have to return + extended keycodes for keypad codes. Test for it and don't + return an ascii code in case. */ - /* - * The system may emit Ascii or Unicode characters depending on whether - * ReadConsoleInputA or ReadConsoleInputW is used. We use ReadConsoleInputA - * in all cases currently, so we just check Ascii. Unicode characters - * are very hard to implement, because our "special keys" like KEY_F(1) - * is one of the unicode range. - * - * Now the ridiculous part of the processing. Normally, if ascii != 0 - * then the system did the translation successfully. But this is not true - * for LEFT_ALT (different to RIGHT_ALT) in case of LEFT_ALT we get - * we get ascii != 0. So check for this first. - */ - if ((ascii != 0) - && (((state & LEFT_ALT_PRESSED) == 0) || (state & RIGHT_ALT_PRESSED))) - { - /* - * This code should catch all keys returning a printable character. - * Characters above 0x7F should be returned as positive codes. - * But if'ndef NUMKEYPAD we have to return extended keycodes for - * keypad codes. Test for it and don't return an ascii code in case. - */ #ifndef NUMKEYPAD - if (kptab[vk].extended == 0) + if (kptab[vk].extended == 0) #endif - return (unsigned char) ascii; - } + return (unsigned char) ascii; + } + /* This case happens if a functional key has been entered. */ - /* - * This case happens if a functional key has been entered. - */ - if ((state & ENHANCED_KEY) && (kptab[vk].extended != 999)) - { - enhanced = TRUE; - idx = kptab[vk].extended; - } - else - { - enhanced = FALSE; - idx = vk; - } - if (state & SHIFT_PRESSED) - return((enhanced)?ext_kptab[idx].shift:kptab[idx].shift); - if (state & LEFT_CTRL_PRESSED || state & RIGHT_CTRL_PRESSED) - return((enhanced)?ext_kptab[idx].control:kptab[idx].control); - if (state & LEFT_ALT_PRESSED || state & RIGHT_ALT_PRESSED) - return((enhanced)?ext_kptab[idx].alt:kptab[idx].alt); - return((enhanced)?ext_kptab[idx].normal:kptab[idx].normal); + if ((state & ENHANCED_KEY) && (kptab[vk].extended != 999)) + { + enhanced = TRUE; + idx = kptab[vk].extended; + } + else + { + enhanced = FALSE; + idx = vk; + } + + if (state & SHIFT_PRESSED) + return enhanced ? ext_kptab[idx].shift : kptab[idx].shift; + + if (state & LEFT_CTRL_PRESSED || state & RIGHT_CTRL_PRESSED) + return enhanced ? ext_kptab[idx].control : kptab[idx].control; + + if (state & LEFT_ALT_PRESSED || state & RIGHT_ALT_PRESSED) + return enhanced ? ext_kptab[idx].alt : kptab[idx].alt; + + return enhanced ? ext_kptab[idx].normal : kptab[idx].normal; } @@ -541,244 +539,291 @@ int processKeyEvent(void) PDC_get_bios_key() - Returns the next key available from the BIOS. PDCurses Description: - This is a private PDCurses routine. + This is a private PDCurses routine. - Returns the next key code struck at the keyboard. If the low 8 - bits are 0, the upper bits contain the extended character - code. If bit 0-7 are non-zero, the upper bits = 0. + Returns the next key code struck at the keyboard. If the low 8 + bits are 0, the upper bits contain the extended character + code. If bit 0-7 are non-zero, the upper bits = 0. PDCurses Return Value: - See above. + See above. PDCurses Errors: - No errors are defined for this function. + No errors are defined for this function. Portability: - PDCurses int PDC_get_bios_key( void ); + PDCurses int PDC_get_bios_key(void); **man-end**********************************************************************/ -int PDC_get_bios_key(void) +int PDC_get_bios_key(void) { - MOUSE_STATUS Temp_Mouse_status; - static int last_button_no=0; - static MOUSE_STATUS Actual_Mouse_status; - int button_no=0; - bool trap_mouse=FALSE; - int key=0; - int retval; + MOUSE_STATUS Temp_Mouse_status; + static int last_button_no = 0; + static MOUSE_STATUS Actual_Mouse_status; + int button_no = 0; + bool trap_mouse = FALSE; + int key = 0; + int retval; - PDC_LOG(("PDC_get_bios_key() - called\n")); + PDC_LOG(("PDC_get_bios_key() - called\n")); - while(1) - { - win32_getch(); + while(1) + { + win32_getch(); - switch (save_ip.EventType) - { - case KEY_EVENT: - retval = processKeyEvent(); - if (retval == -1) /* ignore key? */ - continue; + switch (save_ip.EventType) + { + case KEY_EVENT: + retval = processKeyEvent(); + if (retval == -1) /* ignore key? */ + continue; #if 0 - fprintf(stderr,"KEY_EVENT returns 0x%X\n",retval); + fprintf(stderr, "KEY_EVENT returns 0x%X\n", retval); #endif - return retval; + return retval; - case MOUSE_EVENT: - memset((char*)&Temp_Mouse_status,0,sizeof(MOUSE_STATUS)); - /* - * Wheel has been scrolled - */ -/*fprintf(stderr,"%s %d: %x\n",__FILE__,__LINE__,save_ip.Event.MouseEvent.dwButtonState);*/ - if ( save_ip.Event.MouseEvent.dwEventFlags == MOUSE_WHEELED ) - { - if (save_ip.Event.MouseEvent.dwButtonState & 0xFF000000) - Temp_Mouse_status.changes = PDC_MOUSE_WHEEL_DOWN; - else - Temp_Mouse_status.changes = PDC_MOUSE_WHEEL_UP; - } - /* - * button press, release or double click ... - */ - else if (save_ip.Event.MouseEvent.dwEventFlags == 0 - || save_ip.Event.MouseEvent.dwEventFlags == DOUBLE_CLICK) - { - /* - * Check for Left-most button - always button 1 - */ - if (save_ip.Event.MouseEvent.dwButtonState & FROM_LEFT_1ST_BUTTON_PRESSED - && !(ACTUAL_BUTTON_STATUS(1) & BUTTON_RELEASED)) - { - button_no = 1; - TEMP_BUTTON_STATUS(button_no) = (save_ip.Event.MouseEvent.dwEventFlags)?BUTTON_DOUBLE_CLICKED:BUTTON_PRESSED; - if (TEMP_BUTTON_STATUS(button_no) == BUTTON_PRESSED - && (SP->_trap_mbe) & BUTTON1_PRESSED) - trap_mouse = TRUE; - if (TEMP_BUTTON_STATUS(button_no) == BUTTON_DOUBLE_CLICKED - && (SP->_trap_mbe) & BUTTON1_DOUBLE_CLICKED) - trap_mouse = TRUE; - break; - } - /* - * Check for Right-most button - always button 3 - */ - if (save_ip.Event.MouseEvent.dwButtonState & RIGHTMOST_BUTTON_PRESSED - && !(ACTUAL_BUTTON_STATUS(3) & BUTTON_RELEASED)) - { - button_no = 3; - TEMP_BUTTON_STATUS(button_no) = (save_ip.Event.MouseEvent.dwEventFlags)?BUTTON_DOUBLE_CLICKED:BUTTON_PRESSED; - if (TEMP_BUTTON_STATUS(button_no) == BUTTON_PRESSED - && (SP->_trap_mbe) & BUTTON3_PRESSED) - trap_mouse = TRUE; - if (TEMP_BUTTON_STATUS(button_no) == BUTTON_DOUBLE_CLICKED - && (SP->_trap_mbe) & BUTTON3_DOUBLE_CLICKED) - trap_mouse = TRUE; - break; - } - /* - * To get here we have a button release event or another button press - * while a current button is pressed. The latter, we throw away. - * We have to use the information from the previous mouse event to - * determine which button was released. - */ - if (last_button_no == 1 - && (ACTUAL_BUTTON_STATUS(1) & BUTTON_PRESSED - || ACTUAL_BUTTON_STATUS(1) & BUTTON_DOUBLE_CLICKED - || ACTUAL_MOUSE_MOVED) - && !(save_ip.Event.MouseEvent.dwButtonState & FROM_LEFT_1ST_BUTTON_PRESSED)) - { - button_no = 1; - TEMP_BUTTON_STATUS(button_no) = BUTTON_RELEASED; - if ((SP->_trap_mbe) & BUTTON1_RELEASED) - trap_mouse = TRUE; - break; - } - /* - * Check for Right-most button - always button 3 - */ - if (last_button_no == 3 - && (ACTUAL_BUTTON_STATUS(3) & BUTTON_PRESSED - || ACTUAL_BUTTON_STATUS(3) & BUTTON_DOUBLE_CLICKED - || ACTUAL_MOUSE_MOVED) - && !(save_ip.Event.MouseEvent.dwButtonState & RIGHTMOST_BUTTON_PRESSED)) - { - button_no = 3; - TEMP_BUTTON_STATUS(button_no) = BUTTON_RELEASED; - if ((SP->_trap_mbe) & BUTTON3_RELEASED) - trap_mouse = TRUE; - break; - } - /* - * Check for Middle button - button 2 only for 3 button mice - */ - if (save_ip.Event.MouseEvent.dwButtonState & FROM_LEFT_2ND_BUTTON_PRESSED - && !(ACTUAL_BUTTON_STATUS(2) & BUTTON_RELEASED)) - { - button_no = 2; - TEMP_BUTTON_STATUS(button_no) = (save_ip.Event.MouseEvent.dwEventFlags)?BUTTON_DOUBLE_CLICKED:BUTTON_PRESSED; - if (TEMP_BUTTON_STATUS(button_no) == BUTTON_PRESSED - && (SP->_trap_mbe) & BUTTON2_PRESSED) - trap_mouse = TRUE; - if (TEMP_BUTTON_STATUS(button_no) == BUTTON_DOUBLE_CLICKED - && (SP->_trap_mbe) & BUTTON2_DOUBLE_CLICKED) - trap_mouse = TRUE; - break; - } - if (last_button_no == 2 - && (ACTUAL_BUTTON_STATUS(2) & BUTTON_PRESSED - || ACTUAL_BUTTON_STATUS(2) & BUTTON_DOUBLE_CLICKED - || ACTUAL_MOUSE_MOVED) - && !(save_ip.Event.MouseEvent.dwButtonState & FROM_LEFT_2ND_BUTTON_PRESSED)) - { - button_no = 2; - TEMP_BUTTON_STATUS(button_no) = BUTTON_RELEASED; - if ((SP->_trap_mbe) & BUTTON2_RELEASED) - trap_mouse = TRUE; - break; - } - /* - * If we get here, then we don't know how to handle the event, so - * dispose of it - */ - break; - } - else /* button motion event */ - { - Temp_Mouse_status.changes |= PDC_MOUSE_MOVED; - button_no = last_button_no; - if (button_no == 1 - && (SP->_trap_mbe) & BUTTON1_MOVED) - trap_mouse = TRUE; - if (button_no == 2 - && (SP->_trap_mbe) & BUTTON2_MOVED) - trap_mouse = TRUE; - if (button_no == 3 - && (SP->_trap_mbe) & BUTTON3_MOVED) - trap_mouse = TRUE; - break; - } - break; - case WINDOW_BUFFER_SIZE_EVENT: - return(-1); - default: - break; - } - if (button_no != 0) - { - /* - * We have a button action, rather than a mouse movement or wheel action - */ - TEMP_MOUSE_X_POS = save_ip.Event.MouseEvent.dwMousePosition.X; - TEMP_MOUSE_Y_POS = save_ip.Event.MouseEvent.dwMousePosition.Y; - /* - * First thing is to check if the mouse has been clicked - * on a slk area. If the return value is > 0 (indicating the - * label number, return with the KEY_F(key) value. - * Only call this if we have set trap_mouse to TRUE above. - */ - if (trap_mouse - && (key = PDC_mouse_in_slk(TEMP_MOUSE_Y_POS,TEMP_MOUSE_X_POS))) - return(KEY_F(key)); + case MOUSE_EVENT: + memset((char*)&Temp_Mouse_status, 0, sizeof(MOUSE_STATUS)); - Temp_Mouse_status.changes |= (1 << (button_no-1)); - if (save_ip.Event.MouseEvent.dwControlKeyState & SHIFT_PRESSED) - TEMP_BUTTON_STATUS(button_no) |= BUTTON_SHIFT; - if (save_ip.Event.MouseEvent.dwControlKeyState & LEFT_CTRL_PRESSED) - TEMP_BUTTON_STATUS(button_no) |= BUTTON_CONTROL; - if (save_ip.Event.MouseEvent.dwControlKeyState & RIGHT_CTRL_PRESSED) - TEMP_BUTTON_STATUS(button_no) |= BUTTON_CONTROL; - if (save_ip.Event.MouseEvent.dwControlKeyState & RIGHT_ALT_PRESSED) - TEMP_BUTTON_STATUS(button_no) |= BUTTON_ALT; - if (save_ip.Event.MouseEvent.dwControlKeyState & LEFT_ALT_PRESSED) - TEMP_BUTTON_STATUS(button_no) |= BUTTON_ALT; - last_button_no = button_no; - /* - * We now have the current mouse status information for the last - * Mouse event. We need to save this in Actual_Mouse_status so - * we can use that when comparing against the next mouse event. - * We also need to determine if we need to set Trapped_Mouse_status - * based on the settings in SP->_trap_mbe. - */ - memcpy((char*)&Actual_Mouse_status,(char*)&Temp_Mouse_status,sizeof(MOUSE_STATUS)); - if (trap_mouse) - break; - } - if ( ( Temp_Mouse_status.changes & PDC_MOUSE_WHEEL_DOWN - || Temp_Mouse_status.changes & PDC_MOUSE_WHEEL_UP ) - && SP->_trap_mbe & MOUSE_WHEEL_SCROLL ) - { - TEMP_MOUSE_X_POS = -1; - TEMP_MOUSE_Y_POS = -1; - break; - } - } - /* - * To get here we have a mouse event that has been trapped by the - * user. Save it in the Trapped_Mouse_status structure. - */ - memcpy((char*)&Trapped_Mouse_status,(char*)&Temp_Mouse_status,sizeof(MOUSE_STATUS)); - return(KEY_MOUSE); + /* Wheel has been scrolled */ +#if 0 + fprintf(stderr, "%s %d: %x\n", __FILE__, __LINE__, + save_ip.Event.MouseEvent.dwButtonState); +#endif + if (save_ip.Event.MouseEvent.dwEventFlags == MOUSE_WHEELED) + { + if (save_ip.Event.MouseEvent.dwButtonState & 0xFF000000) + Temp_Mouse_status.changes = PDC_MOUSE_WHEEL_DOWN; + else + Temp_Mouse_status.changes = PDC_MOUSE_WHEEL_UP; + } + + /* button press, release or double click */ + + else if (save_ip.Event.MouseEvent.dwEventFlags == 0 || + save_ip.Event.MouseEvent.dwEventFlags == DOUBLE_CLICK) + { + /* Check for Left-most button - always button 1 */ + + if (save_ip.Event.MouseEvent.dwButtonState & + FROM_LEFT_1ST_BUTTON_PRESSED && + !(ACTUAL_BUTTON_STATUS(1) & BUTTON_RELEASED)) + { + button_no = 1; + + TEMP_BUTTON_STATUS(button_no) = + (save_ip.Event.MouseEvent.dwEventFlags) ? + BUTTON_DOUBLE_CLICKED : BUTTON_PRESSED; + + if (TEMP_BUTTON_STATUS(button_no) == + BUTTON_PRESSED && (SP->_trap_mbe) & + BUTTON1_PRESSED) + trap_mouse = TRUE; + + if (TEMP_BUTTON_STATUS(button_no) == + BUTTON_DOUBLE_CLICKED && (SP->_trap_mbe) & + BUTTON1_DOUBLE_CLICKED) + trap_mouse = TRUE; + + break; + } + + /* Check for Right-most button - always button 3 */ + + if (save_ip.Event.MouseEvent.dwButtonState & + RIGHTMOST_BUTTON_PRESSED && + !(ACTUAL_BUTTON_STATUS(3) & BUTTON_RELEASED)) + { + button_no = 3; + + TEMP_BUTTON_STATUS(button_no) = + (save_ip.Event.MouseEvent.dwEventFlags) ? + BUTTON_DOUBLE_CLICKED : BUTTON_PRESSED; + + if (TEMP_BUTTON_STATUS(button_no) == + BUTTON_PRESSED && (SP->_trap_mbe) & + BUTTON3_PRESSED) + trap_mouse = TRUE; + + if (TEMP_BUTTON_STATUS(button_no) == + BUTTON_DOUBLE_CLICKED && (SP->_trap_mbe) & + BUTTON3_DOUBLE_CLICKED) + trap_mouse = TRUE; + + break; + } + + /* To get here we have a button release event or + another button press while a current button is + pressed. The latter, we throw away. We have to + use the information from the previous mouse event + to determine which button was released. */ + + if (last_button_no == 1 && (ACTUAL_BUTTON_STATUS(1) & + BUTTON_PRESSED || ACTUAL_BUTTON_STATUS(1) & + BUTTON_DOUBLE_CLICKED || ACTUAL_MOUSE_MOVED) && + !(save_ip.Event.MouseEvent.dwButtonState & + FROM_LEFT_1ST_BUTTON_PRESSED)) + { + button_no = 1; + TEMP_BUTTON_STATUS(button_no) = BUTTON_RELEASED; + + if ((SP->_trap_mbe) & BUTTON1_RELEASED) + trap_mouse = TRUE; + break; + } + + /* Check for Right-most button - always button 3 */ + + if (last_button_no == 3 && (ACTUAL_BUTTON_STATUS(3) & + BUTTON_PRESSED || ACTUAL_BUTTON_STATUS(3) & + BUTTON_DOUBLE_CLICKED || ACTUAL_MOUSE_MOVED) && + !(save_ip.Event.MouseEvent.dwButtonState & + RIGHTMOST_BUTTON_PRESSED)) + { + button_no = 3; + TEMP_BUTTON_STATUS(button_no) = BUTTON_RELEASED; + + if ((SP->_trap_mbe) & BUTTON3_RELEASED) + trap_mouse = TRUE; + break; + } + + /* Check for Middle button - button 2 only for 3 + button mice */ + + if (save_ip.Event.MouseEvent.dwButtonState & + FROM_LEFT_2ND_BUTTON_PRESSED && + !(ACTUAL_BUTTON_STATUS(2) & BUTTON_RELEASED)) + { + button_no = 2; + TEMP_BUTTON_STATUS(button_no) = + (save_ip.Event.MouseEvent.dwEventFlags) ? + BUTTON_DOUBLE_CLICKED : BUTTON_PRESSED; + + if (TEMP_BUTTON_STATUS(button_no) == BUTTON_PRESSED + && (SP->_trap_mbe) & BUTTON2_PRESSED) + trap_mouse = TRUE; + + if (TEMP_BUTTON_STATUS(button_no) == + BUTTON_DOUBLE_CLICKED && (SP->_trap_mbe) & + BUTTON2_DOUBLE_CLICKED) + trap_mouse = TRUE; + + break; + } + + if (last_button_no == 2 && (ACTUAL_BUTTON_STATUS(2) & + BUTTON_PRESSED || ACTUAL_BUTTON_STATUS(2) & + BUTTON_DOUBLE_CLICKED || ACTUAL_MOUSE_MOVED) && + !(save_ip.Event.MouseEvent.dwButtonState & + FROM_LEFT_2ND_BUTTON_PRESSED)) + { + button_no = 2; + TEMP_BUTTON_STATUS(button_no) = BUTTON_RELEASED; + + if ((SP->_trap_mbe) & BUTTON2_RELEASED) + trap_mouse = TRUE; + break; + } + + /* If we get here, then we don't know how to handle + the event, so dispose of it */ + + break; + } + else /* button motion event */ + { + Temp_Mouse_status.changes |= PDC_MOUSE_MOVED; + button_no = last_button_no; + + if ((button_no == 1 && SP->_trap_mbe & BUTTON1_MOVED) + || (button_no == 2 && SP->_trap_mbe & BUTTON2_MOVED) + || (button_no == 3 && SP->_trap_mbe & BUTTON3_MOVED)) + trap_mouse = TRUE; + + break; + } + + break; + + case WINDOW_BUFFER_SIZE_EVENT: + return -1; + } + + if (button_no != 0) + { + /* We have a button action, rather than a mouse movement + or wheel action */ + + TEMP_MOUSE_X_POS = save_ip.Event.MouseEvent.dwMousePosition.X; + TEMP_MOUSE_Y_POS = save_ip.Event.MouseEvent.dwMousePosition.Y; + + /* First thing is to check if the mouse has been clicked + on a slk area. If the return value is > 0 (indicating + the label number), return with the KEY_F(key) value. + Only call this if we have set trap_mouse to TRUE above. */ + + if (trap_mouse && (key = PDC_mouse_in_slk(TEMP_MOUSE_Y_POS, + TEMP_MOUSE_X_POS))) + return KEY_F(key); + + Temp_Mouse_status.changes |= 1 << (button_no - 1); + + if (save_ip.Event.MouseEvent.dwControlKeyState & + SHIFT_PRESSED) + TEMP_BUTTON_STATUS(button_no) |= BUTTON_SHIFT; + + if (save_ip.Event.MouseEvent.dwControlKeyState & + LEFT_CTRL_PRESSED) + TEMP_BUTTON_STATUS(button_no) |= BUTTON_CONTROL; + + if (save_ip.Event.MouseEvent.dwControlKeyState & + RIGHT_CTRL_PRESSED) + TEMP_BUTTON_STATUS(button_no) |= BUTTON_CONTROL; + + if (save_ip.Event.MouseEvent.dwControlKeyState & + RIGHT_ALT_PRESSED) + TEMP_BUTTON_STATUS(button_no) |= BUTTON_ALT; + + if (save_ip.Event.MouseEvent.dwControlKeyState & + LEFT_ALT_PRESSED) + TEMP_BUTTON_STATUS(button_no) |= BUTTON_ALT; + + last_button_no = button_no; + + /* We now have the current mouse status information + for the last Mouse event. We need to save this in + Actual_Mouse_status so we can use that when comparing + against the next mouse event. We also need to + determine if we need to set Trapped_Mouse_status + based on the settings in SP->_trap_mbe. */ + + memcpy((char*)&Actual_Mouse_status, + (char*)&Temp_Mouse_status, sizeof(MOUSE_STATUS)); + + if (trap_mouse) + break; + } + + if ((Temp_Mouse_status.changes & PDC_MOUSE_WHEEL_DOWN || + Temp_Mouse_status.changes & PDC_MOUSE_WHEEL_UP) && + SP->_trap_mbe & MOUSE_WHEEL_SCROLL) + { + TEMP_MOUSE_X_POS = -1; + TEMP_MOUSE_Y_POS = -1; + break; + } + } + + /* To get here we have a mouse event that has been trapped by + the user. Save it in the Trapped_Mouse_status structure. */ + + memcpy((char*)&Trapped_Mouse_status, (char*)&Temp_Mouse_status, + sizeof(MOUSE_STATUS)); + + return KEY_MOUSE; } /*man-start********************************************************************* @@ -786,27 +831,27 @@ int PDC_get_bios_key(void) PDC_get_ctrl_break() - return OS control break state PDCurses Description: - This is a private PDCurses routine. + This is a private PDCurses routine. - Returns the current OS Control Break Check state. + Returns the current OS Control Break Check state. PDCurses Return Value: - This function returns TRUE if the Control Break - Check is enabled otherwise FALSE is returned. + This function returns TRUE if the Control Break Check is + enabled; otherwise, FALSE is returned. PDCurses Errors: - No errors are defined for this function. + No errors are defined for this function. Portability: - PDCurses bool PDC_get_ctrl_break( void ); + PDCurses bool PDC_get_ctrl_break(void); **man-end**********************************************************************/ -bool PDC_get_ctrl_break(void) +bool PDC_get_ctrl_break(void) { - PDC_LOG(("PDC_get_ctrl_break() - called\n")); + PDC_LOG(("PDC_get_ctrl_break() - called\n")); - return FALSE; + return FALSE; } /*man-start********************************************************************* @@ -814,64 +859,55 @@ bool PDC_get_ctrl_break(void) PDC_rawgetch() - Returns the next uninterpreted character (if available). PDCurses Description: - Gets a character without any interpretation at all and returns - it. If keypad mode is active for the designated window, - function key translation will be performed. Otherwise, - function keys are ignored. If nodelay mode is active in the - window, then PDC_rawgetch() returns -1 if no character is - available. + Gets a character without any interpretation at all and returns + it. If keypad mode is active for the designated window, function + key translation will be performed. Otherwise, function keys are + ignored. If nodelay mode is active in the window, then + PDC_rawgetch() returns -1 if no character is available. - WARNING: It is unknown whether the FUNCTION key translation - is performed at this level. --Frotz 911130 BUG + WARNING: It is unknown whether the FUNCTION key translation + is performed at this level. --Frotz 911130 BUG PDCurses Return Value: - This function returns OK on success and ERR on error. + This function returns OK on success and ERR on error. PDCurses Errors: - No errors are defined for this function. + No errors are defined for this function. Portability: - PDCurses int PDC_rawgetch( void ); + PDCurses int PDC_rawgetch(void); **man-end**********************************************************************/ -int PDC_rawgetch(void) +int PDC_rawgetch(void) { - extern WINDOW* _getch_win_; + extern WINDOW *_getch_win_; + int c, oldc; - int c; - int oldc; - bool return_immediately; + PDC_LOG(("PDC_rawgetch() - called\n")); - PDC_LOG(("PDC_rawgetch() - called\n")); + if (_getch_win_ == (WINDOW *)NULL) + return -1; - if (_getch_win_ == (WINDOW *)NULL) /* @@ */ - return( -1 ); + if ((SP->delaytenths || _getch_win_->_delayms || _getch_win_->_nodelay) + && !PDC_breakout()) + return -1; - if (SP->delaytenths || _getch_win_->_delayms || _getch_win_->_nodelay) - return_immediately = TRUE; - else - return_immediately = FALSE; + while (1) + { + c = PDC_get_bios_key(); + oldc = c; - if (return_immediately && !PDC_breakout()) - return( -1 ); + /* return the key if it is not a special key */ - while (1) /* loop to get valid char */ - { - c = PDC_get_bios_key(); - oldc = c; - /* - * Return the key if it is not a special key. - */ - if (c != KEY_MOUSE - && (c = PDC_validchar(c)) >= 0) - { /* get & check next char */ - return( c ); - } - if (_getch_win_->_use_keypad) - return( oldc ); - } - return( -1 ); + if (c != KEY_MOUSE && (c = PDC_validchar(c)) >= 0) + return c; + + if (_getch_win_->_use_keypad) + return oldc; + } + + return -1; } /*man-start********************************************************************* @@ -879,28 +915,28 @@ int PDC_rawgetch(void) PDC_set_ctrl_break() - Enables/Disables the host OS BREAK key check. PDCurses Description: - This is a private PDCurses routine. + This is a private PDCurses routine. - Enables/Disables the host OS BREAK key check. If the supplied setting - is TRUE, this enables CTRL/C and CTRL/BREAK to abort the process. - If FALSE, CTRL/C and CTRL/BREAK are ignored. + Enables/Disables the host OS BREAK key check. If the supplied + setting is TRUE, this enables CTRL/C and CTRL/BREAK to abort the + process. If FALSE, CTRL/C and CTRL/BREAK are ignored. PDCurses Return Value: - This function returns OK on success and ERR on error. + This function returns OK on success and ERR on error. PDCurses Errors: - No errors are defined for this function. + No errors are defined for this function. Portability: - PDCurses int PDC_set_ctrl_break( bool setting ); + PDCurses int PDC_set_ctrl_break(bool setting); **man-end**********************************************************************/ -int PDC_set_ctrl_break(bool setting) +int PDC_set_ctrl_break(bool setting) { - PDC_LOG(("PDC_set_ctrl_break() - called\n")); + PDC_LOG(("PDC_set_ctrl_break() - called\n")); - return(OK); + return OK; } /*man-start********************************************************************* @@ -908,329 +944,358 @@ int PDC_set_ctrl_break(bool setting) PDC_sysgetch() - Return a character using default system routines. PDCurses Description: - This is a private PDCurses function. + This is a private PDCurses function. - Gets a character without normal ^S, ^Q, ^P and ^C interpretation - and returns it. If keypad mode is active for the designated - window, function key translation will be performed. Otherwise, - function keys are ignored. If nodelay mode is active in the - window, then sysgetch() returns -1 if no character is - available. + Gets a character without normal ^S, ^Q, ^P and ^C interpretation + and returns it. If keypad mode is active for the designated + window, function key translation will be performed. Otherwise, + function keys are ignored. If nodelay mode is active in the + window, then sysgetch() returns -1 if no character is + available. PDCurses Return Value: - This function returns OK upon success otherwise ERR is returned. + This function returns OK upon success otherwise ERR is returned. PDCurses Errors: - No errors are defined for this routine. + No errors are defined for this routine. Portability: - PDCurses int PDC_sysgetch( void ); + PDCurses int PDC_sysgetch(void); **man-end**********************************************************************/ -int PDC_sysgetch(void) +int PDC_sysgetch(void) { - extern WINDOW* _getch_win_; + extern WINDOW *_getch_win_; + int c; - int c; - bool return_immediately; + PDC_LOG(("PDC_sysgetch() - called\n")); - PDC_LOG(("PDC_sysgetch() - called\n")); + if (_getch_win_ == (WINDOW *)NULL) + return -1; - if (_getch_win_ == (WINDOW *)NULL) /* @@ */ - return (-1); + if ((SP->delaytenths || _getch_win_->_delayms || _getch_win_->_nodelay) + && !PDC_breakout()) + return -1; - if (SP->delaytenths || _getch_win_->_delayms || _getch_win_->_nodelay) - return_immediately = TRUE; - else - return_immediately = FALSE; + while (1) + { + c = PDC_get_bios_key(); - if (return_immediately && !PDC_breakout()) - return (-1); + /* return the key if it is not a special key */ - while (1) - { - c = PDC_get_bios_key(); - /* - * Return the key if it is not a special key. - */ - if ((unsigned int)c < 256) - return(c); - if ((c = PDC_validchar(c)) >= 0) - { - return (c); /* get & check next char */ - } - } - return( -1 ); + if ((unsigned int)c < 256) + return c; + + if ((c = PDC_validchar(c)) >= 0) + return c; + } + + return -1; } - /*man-start********************************************************************* PDC_validchar() - validate/translate passed character PDCurses Description: - This is a private PDCurses function. + This is a private PDCurses function. - Checks that 'c' is a valid character, and if so returns it, - with function key translation applied if 'w' has keypad mode - set. If char is invalid, returns -1. + Checks that 'c' is a valid character, and if so returns it, + with function key translation applied if 'w' has keypad mode + set. If char is invalid, returns -1. PDCurses Return Value: - This function returns -1 if the passed character is invalid, or - the WINDOW* 'w' is NULL, or 'w's keypad is not active. + This function returns -1 if the passed character is invalid, or + the WINDOW *_getch_win_ is NULL, or _getch_win_'s keypad is not + active. - Otherwise, this function returns the PDCurses equivalent of the - passed character. See the function key and key macros in - + Otherwise, this function returns the PDCurses equivalent of the + passed character. See the function key and key macros in + . PDCurses Errors: - There are no errors defined for this routine. + There are no errors defined for this routine. Portability: - PDCurses int PDC_validchar( int c ); + PDCurses int PDC_validchar(int c); **man-end**********************************************************************/ -int PDC_validchar(int c) +int PDC_validchar(int c) { - extern WINDOW* _getch_win_; - int ch=c; + extern WINDOW *_getch_win_; - PDC_LOG(("PDC_validchar() - called\n")); + PDC_LOG(("PDC_validchar() - called\n")); - if (_getch_win_ == (WINDOW *)NULL) - ch = (-1); /* bad window pointer */ - else if ((unsigned int)c < 256) - ch = c; /* normal character */ - else if (!(_getch_win_->_use_keypad)) - ch = (-1); /* skip if keys if !keypad mode */ + /* skip special keys if !keypad mode */ - PDC_LOG(("PDC_validchar() - returned: %x\n",ch)); + if ((_getch_win_ == (WINDOW *)NULL) || + ((unsigned int)c >= 256 && !_getch_win_->_use_keypad)) + c = -1; - return(ch); + PDC_LOG(("PDC_validchar() - returned: %x\n", c)); + + return c; } /***********************************************************************/ -static int GetInterestingEvent( INPUT_RECORD *ip ) +static int GetInterestingEvent(INPUT_RECORD *ip) /***********************************************************************/ { - /* - * GetInterestingEvent returns 0 if *ip doesn't contain an event which - * should be passed back to the user. This function filters "useless" - * events. - * The function returns the number of events waiting. This may be > 1 - * if the repeation of real keys pressed so far are > 1. - * - * Keyboard: Returns 0 on NUMLOCK, CAPSLOCK, SCROLLLOCK. - * - * Returns 1 for SHIFT, ALT, CTRL only if no other key has been - * pressed in between; these are returned on keyup in opposite to - * normal keys. The overall flags for processing of SHIFT, ALT, - * CTRL (SP->return_key_modifiers) must have been set. - * FGC: CHANGED BEHAVIOUR: In previous version SHIFT etc had a - * chance to be returned on the first keydown, too. This - * was a bug, because return_key_modifiers were 0. - * - * Normal keys are returned on keydown only. The number of - * repeations are returned. Dead keys (diacritics) are omitted. - * See below for a description. - * - * The keypad entering of special keys is not supported. This - * feature can be built in by replacing "#ifdef NUMPAD_CHARS" - * with an intelligent code. - * - * Mouse: Returns > 0 only if SP->_trap_mbe is set. MOUSE_MOVE without - * a pressed mouse key are ignored. - * - * Window: Everything is ignored, including resize requests. In case - * of resize requests the global flag SP->resized is set. - * - * PLEASE DOCUMENT YOUR WORK! - * - * THIS FUNCTION IS NOT THREAD-SAFE. NEVER USE MORE THREADS THAN TO - * USE THIS FUNCTION. STATIC VARIABLES ARE USED HERE. - */ - int numKeys = 0, vk; - static int save_press; - static unsigned numpadChar = 0; + /* GetInterestingEvent returns 0 if *ip doesn't contain an event which + should be passed back to the user. This function filters "useless" + events. + + The function returns the number of events waiting. This may be > 1 + if the repeation of real keys pressed so far are > 1. + + Keyboard: Returns 0 on NUMLOCK, CAPSLOCK, SCROLLLOCK. + + Returns 1 for SHIFT, ALT, CTRL only if no other key has been + pressed in between; these are returned on keyup in opposite to + normal keys. The overall flags for processing of SHIFT, ALT, + CTRL (SP->return_key_modifiers) must have been set. + FGC: CHANGED BEHAVIOUR: In previous version SHIFT etc had a + chance to be returned on the first keydown, too. This + was a bug, because return_key_modifiers were 0. + + Normal keys are returned on keydown only. The number of + repeations are returned. Dead keys (diacritics) are omitted. + See below for a description. + + The keypad entering of special keys is not supported. This + feature can be built in by replacing "#ifdef NUMPAD_CHARS" + with an intelligent code. + + Mouse: Returns > 0 only if SP->_trap_mbe is set. MOUSE_MOVE without + a pressed mouse key are ignored. + + Window: Everything is ignored, including resize requests. In case + of resize requests the global flag SP->resized is set. + + THIS FUNCTION IS NOT THREAD-SAFE. NEVER USE MORE THREADS THAN TO + USE THIS FUNCTION. STATIC VARIABLES ARE USED HERE. + */ + int numKeys = 0, vk; + static int save_press; + static unsigned numpadChar = 0; + #ifdef PDCDEBUG #if defined(PDC_THREAD_BUILD) -# define PDC_DEBUG_THREADING1 "-->" -# define PDC_DEBUG_THREADING2 "THREADING" +# define PDC_DEBUG_THREADING1 "-->" +# define PDC_DEBUG_THREADING2 "THREADING" # else -# define PDC_DEBUG_THREADING1 "" -# define PDC_DEBUG_THREADING2 "" +# define PDC_DEBUG_THREADING1 "" +# define PDC_DEBUG_THREADING2 "" # endif - char *ptr=""; - PDC_LOG(("%sGetInterestingEvent(%s) - called\n",PDC_DEBUG_THREADING1,PDC_DEBUG_THREADING2)); + char *ptr = ""; + + PDC_LOG(("%sGetInterestingEvent(%s) - called\n", + PDC_DEBUG_THREADING1, PDC_DEBUG_THREADING2)); #endif - switch(ip->EventType) - { - case KEY_EVENT: - vk = ip->Event.KeyEvent.wVirtualKeyCode; - if (vk == VK_CAPITAL || vk == VK_NUMLOCK || vk == VK_SCROLL) - { + switch(ip->EventType) + { + case KEY_EVENT: + vk = ip->Event.KeyEvent.wVirtualKeyCode; + + /* throw away some modifiers */ + + if (vk == VK_CAPITAL || vk == VK_NUMLOCK || vk == VK_SCROLL) + { #ifdef PDCDEBUG - ptr = "KEY MODIFIERS"; + ptr = "KEY MODIFIERS"; #endif - numpadChar = 0; - save_press = 0; - break; /* throw away some modifiers */ - } - if (ip->Event.KeyEvent.bKeyDown == FALSE) - { - /* key up, the following check for VK_??? is paranoid hopefully */ - if ((vk == VK_SHIFT || vk == VK_CONTROL || vk == VK_MENU) - && vk == save_press - && SP->return_key_modifiers) - { + numpadChar = 0; + save_press = 0; + break; + } + + if (ip->Event.KeyEvent.bKeyDown == FALSE) + { + /* key up, the following check for VK_??? is paranoid + hopefully */ + + if ((vk == VK_SHIFT || vk == VK_CONTROL || vk == VK_MENU) + && vk == save_press && SP->return_key_modifiers) + { #ifdef PDCDEBUG - ptr = "KEYUP WANTED"; -#else - ; + ptr = "KEYUP WANTED"; #endif - /* - * Fall through and return this key. Still have to check the - * dead key condition. - */ - ip->Event.KeyEvent.wRepeatCount = 1; /* always limited */ - } - else if (vk == VK_MENU && numpadChar) - { - ip->Event.KeyEvent.uChar.AsciiChar = (CHAR) (unsigned char) numpadChar; - ip->Event.KeyEvent.dwControlKeyState &= ~LEFT_ALT_PRESSED; - ip->Event.KeyEvent.wRepeatCount = 1; /* always limited */ - ip->Event.KeyEvent.wVirtualKeyCode = VK_NUMPAD0; /* change ALT to something else */ - numpadChar = 0; - } - else - { + + /* Fall through and return this key. Still have to + check the dead key condition. */ + + /* always limited */ + + ip->Event.KeyEvent.wRepeatCount = 1; + } + else if (vk == VK_MENU && numpadChar) + { + ip->Event.KeyEvent.uChar.AsciiChar = + (CHAR) (unsigned char) numpadChar; + + ip->Event.KeyEvent.dwControlKeyState &= + ~LEFT_ALT_PRESSED; + + ip->Event.KeyEvent.wRepeatCount = 1; /* always limited */ + + /* change ALT to something else */ + + ip->Event.KeyEvent.wVirtualKeyCode = VK_NUMPAD0; + + numpadChar = 0; + } + else + { #ifdef PDCDEBUG - ptr = "KEYUP IGNORED"; + ptr = "KEYUP IGNORED"; #endif - break; /* throw away other KeyUp events */ - } - } - else - { - if (vk == VK_SHIFT || vk == VK_CONTROL || vk == VK_MENU) - { - /* - * These keys are returned on keyup only. - */ - save_press = (SP->return_key_modifiers) ? vk : 0; - numpadChar = 0; + break; /* throw away other KeyUp events */ + } + } + else + { + if (vk == VK_SHIFT || vk == VK_CONTROL || vk == VK_MENU) + { + /* These keys are returned on keyup only. */ + + save_press = (SP->return_key_modifiers) ? vk : 0; + numpadChar = 0; #ifdef PDCDEBUG - ptr = "KEYDOWN SAVED"; + ptr = "KEYDOWN SAVED"; #endif - break; /* throw away key press */ - } + break; /* throw away key press */ + } #ifdef NUMPAD_CHARS - { - if ((ip->Event.KeyEvent.dwControlKeyState & (LEFT_ALT_PRESSED | ENHANCED_KEY)) == LEFT_ALT_PRESSED) - { - switch (vk) - { - case VK_CLEAR: vk = VK_NUMPAD5; break; - case VK_PRIOR: vk = VK_NUMPAD9; break; - case VK_NEXT: vk = VK_NUMPAD3; break; - case VK_END: vk = VK_NUMPAD1; break; - case VK_HOME: vk = VK_NUMPAD7; break; - case VK_LEFT: vk = VK_NUMPAD4; break; - case VK_UP: vk = VK_NUMPAD8; break; - case VK_RIGHT: vk = VK_NUMPAD6; break; - case VK_DOWN: vk = VK_NUMPAD2; break; - case VK_INSERT: vk = VK_NUMPAD0; break; - default: - break; - } - } - if ((vk >= VK_NUMPAD0 && vk <= VK_NUMPAD9) - && ip->Event.KeyEvent.dwControlKeyState & LEFT_ALT_PRESSED) - { + if ((ip->Event.KeyEvent.dwControlKeyState & + (LEFT_ALT_PRESSED | ENHANCED_KEY)) == LEFT_ALT_PRESSED) + { + switch (vk) + { + case VK_CLEAR: + vk = VK_NUMPAD5; + break; + case VK_PRIOR: + vk = VK_NUMPAD9; + break; + case VK_NEXT: + vk = VK_NUMPAD3; + break; + case VK_END: + vk = VK_NUMPAD1; + break; + case VK_HOME: + vk = VK_NUMPAD7; + break; + case VK_LEFT: + vk = VK_NUMPAD4; + break; + case VK_UP: + vk = VK_NUMPAD8; + break; + case VK_RIGHT: + vk = VK_NUMPAD6; + break; + case VK_DOWN: + vk = VK_NUMPAD2; + break; + case VK_INSERT: + vk = VK_NUMPAD0; + } + + } + + if ((vk >= VK_NUMPAD0 && vk <= VK_NUMPAD9) && + ip->Event.KeyEvent.dwControlKeyState & LEFT_ALT_PRESSED) + { #ifdef PDCDEBUG - ptr = "NUMPAD ALTERNATE INPUT"; + ptr = "NUMPAD ALTERNATE INPUT"; #endif - numpadChar *= 10; - numpadChar += vk - VK_NUMPAD0; - break; - } - else - numpadChar = 0; - } + numpadChar *= 10; + numpadChar += vk - VK_NUMPAD0; + break; + } + else + numpadChar = 0; + #else /* NUMPAD_CHARS */ - { - numpadChar = 0; - } + numpadChar = 0; #endif - } - save_press = 0; - /* - * Check for diacritics. These are dead keys. Some locale have - * modified characters like umlaut-a, which is an "a" with two dots - * on it. In some locales you have to press a special key (the dead - * key) immediately followed by the "a" to get a composed umlaut-a. - * The special key may have a normal meaning with different modifiers. - */ - if (ip->Event.KeyEvent.uChar.AsciiChar == 0 && - (MapVirtualKey(ip->Event.KeyEvent.wVirtualKeyCode,2) & 0x80000000)) - { -#ifdef PDCDEBUG - ptr = "DIACRITIC IGNORED"; -#endif - break; /* Diacritic characters, ignore them */ - } -#ifdef PDCDEBUG - ptr = "KEY WANTED"; -#endif - numKeys = ip->Event.KeyEvent.wRepeatCount; - break; + } - case MOUSE_EVENT: - /* - * If we aren't trapping mouse events, then the "keyboard" hasn't - * been hit. Fix from stepheng@clearspeed.com - */ - if (!SP->_trap_mbe) - { -#ifdef PDCDEBUG - ptr = "MOUSE - NOT TRAPPED"; -#endif - break; - } - if (ip->Event.MouseEvent.dwEventFlags == MS_MOUSE_MOVED - && ip->Event.MouseEvent.dwButtonState == 0) - { -#ifdef PDCDEBUG - ptr = "MOUSE MOVE IGNORED"; -#endif - break; /* throw away plain MOUSE_MOVE events */ - } -#ifdef PDCDEBUG - ptr = "MOUSE MOVE WANTED"; -#endif - numKeys = 1; - break; + save_press = 0; - case WINDOW_BUFFER_SIZE_EVENT: - SP->resized = TRUE; -#ifdef PDCDEBUG - ptr = "BUFFER SIZE"; -#endif - break; + /* Check for diacritics. These are dead keys. Some locale + have modified characters like umlaut-a, which is an "a" + with two dots on it. In some locales you have to press a + special key (the dead key) immediately followed by the + "a" to get a composed umlaut-a. The special key may have + a normal meaning with different modifiers. */ - default: + if (ip->Event.KeyEvent.uChar.AsciiChar == 0 && + (MapVirtualKey(ip->Event.KeyEvent.wVirtualKeyCode, 2) & + 0x80000000)) + { #ifdef PDCDEBUG - ptr = "UNKNOWN"; + ptr = "DIACRITIC IGNORED"; #endif - break; - } - PDC_LOG(("%sGetInterestingEvent(%s) - returning: numKeys %d type %d: %s\n",PDC_DEBUG_THREADING1,PDC_DEBUG_THREADING2,numKeys,ip->EventType,ptr)); + break; /* Diacritic characters, ignore them */ + } +#ifdef PDCDEBUG + ptr = "KEY WANTED"; +#endif + numKeys = ip->Event.KeyEvent.wRepeatCount; + break; - return numKeys; + case MOUSE_EVENT: + /* If we aren't trapping mouse events, then the "keyboard" + hasn't been hit. Fix from stepheng@clearspeed.com */ + + if (!SP->_trap_mbe) + { +#ifdef PDCDEBUG + ptr = "MOUSE - NOT TRAPPED"; +#endif + break; + } + + if (ip->Event.MouseEvent.dwEventFlags == MS_MOUSE_MOVED + && ip->Event.MouseEvent.dwButtonState == 0) + { +#ifdef PDCDEBUG + ptr = "MOUSE MOVE IGNORED"; +#endif + break; /* throw away plain MOUSE_MOVE events */ + } + +#ifdef PDCDEBUG + ptr = "MOUSE MOVE WANTED"; +#endif + numKeys = 1; + break; + + case WINDOW_BUFFER_SIZE_EVENT: + SP->resized = TRUE; +#ifdef PDCDEBUG + ptr = "BUFFER SIZE"; +#endif + break; + + default: +#ifdef PDCDEBUG + ptr = "UNKNOWN"; +#endif + break; + } + + PDC_LOG(("%sGetInterestingEvent(%s) - returning: numKeys %d type %d: %s\n", + PDC_DEBUG_THREADING1, PDC_DEBUG_THREADING2, numKeys, + ip->EventType, ptr)); + + return numKeys; } #if defined(PDC_THREAD_BUILD) @@ -1238,64 +1303,67 @@ static int GetInterestingEvent( INPUT_RECORD *ip ) static int win32_kbhit(int timeout) /***********************************************************************/ { - DWORD read=0,avail=0,unread=0; - INPUT_RECORD ip; - - PDC_LOG(("win32_kbhit(THREADING) - called: timeout %d\n", timeout)); + DWORD read = 0, avail = 0, unread = 0; + INPUT_RECORD ip; + PDC_LOG(("win32_kbhit(THREADING) - called: timeout %d\n", + timeout)); #if 0 - if ( timeout == INFINITE ) - { - ReadFile( hPipeRead, &save_ip, sizeof(INPUT_RECORD), &read, NULL ); - return TRUE; - } - else - { - if ( WaitForSingleObject( hSemKeyCount, timeout ) != WAIT_OBJECT_0 ) - { - return FALSE; - } - if ( PeekNamedPipe( hPipeRead, &ip, sizeof(INPUT_RECORD), &read, &avail, &unread ) ) - { - PDC_LOG(("win32_kbhit(THREADING) - maybe key on pipe. read %d avail %d unread %d\n",read,avail,unread)); + if (timeout == INFINITE) + { + ReadFile(hPipeRead, &save_ip, sizeof(INPUT_RECORD), + &read, NULL); + return TRUE; + } + else + { + if (WaitForSingleObject(hSemKeyCount, timeout) != + WAIT_OBJECT_0) + return FALSE; - if ( read == sizeof(INPUT_RECORD) ) - return TRUE; - } - } + if (PeekNamedPipe(hPipeRead, &ip, sizeof(INPUT_RECORD), + &read, &avail, &unread)) + { + + PDC_LOG(("win32_kbhit(THREADING) - maybe key on pipe. read %d avail %d unread %d\n", + read, avail, unread)); + + if (read == sizeof(INPUT_RECORD)) + return TRUE; + } + } #else - if ( WaitForSingleObject( hSemKeyCount, timeout ) != WAIT_OBJECT_0 ) - { - return FALSE; - } - if ( timeout == INFINITE ) - { - ReadFile( hPipeRead, &save_ip, sizeof(INPUT_RECORD), &read, NULL ); - return TRUE; - } - else - { - if ( PeekNamedPipe( hPipeRead, &ip, sizeof(INPUT_RECORD), &read, &avail, &unread ) ) - { - PDC_LOG(("win32_kbhit(THREADING) - maybe key on pipe. read %d avail %d unread %d\n",read,avail,unread)); + if (WaitForSingleObject(hSemKeyCount, timeout) != WAIT_OBJECT_0) + return FALSE; - if ( read == sizeof(INPUT_RECORD) ) - return TRUE; - } - } + if (timeout == INFINITE) + { + ReadFile(hPipeRead, &save_ip, sizeof(INPUT_RECORD), + &read, NULL); + return TRUE; + } + else + { + if (PeekNamedPipe(hPipeRead, &ip, sizeof(INPUT_RECORD), + &read, &avail, &unread)) + { + PDC_LOG(("win32_kbhit(THREADING) - maybe key on pipe. read %d avail %d unread %d\n", + read, avail, unread)); + + if (read == sizeof(INPUT_RECORD)) + return TRUE; + } + } #endif - return FALSE; + return FALSE; } - /***********************************************************************/ static void win32_getch(void) /***********************************************************************/ { - while (win32_kbhit(INFINITE) == FALSE) - ; - - return; + while (win32_kbhit(INFINITE) == FALSE) + ; } #else @@ -1303,145 +1371,142 @@ static void win32_getch(void) static int win32_kbhit(int timeout) /***********************************************************************/ { - INPUT_RECORD ip; - DWORD read; - int rc=FALSE; + INPUT_RECORD ip; + DWORD read; + int rc = FALSE; - PDC_LOG(("win32_kbhit() - called: timeout %d keyCount %d\n", timeout, keyCount)); + PDC_LOG(("win32_kbhit() - called: timeout %d keyCount %d\n", + timeout, keyCount)); - if (keyCount > 0) - return TRUE; + if (keyCount > 0) + return TRUE; - if (WaitForSingleObject(hConIn, timeout) != WAIT_OBJECT_0) - { - return FALSE; - } + if (WaitForSingleObject(hConIn, timeout) != WAIT_OBJECT_0) + return FALSE; - PeekConsoleInput(hConIn, &ip, 1, &read); - if (read == 0) - return(FALSE); - ReadConsoleInput(hConIn, &ip, 1, &read); + PeekConsoleInput(hConIn, &ip, 1, &read); + if (read == 0) + return FALSE; - keyCount = GetInterestingEvent( &ip ); - if ( keyCount ) - { - /* - * To get here a recognised event has occurred; save it and return TRUE - */ - memcpy( (char*)&save_ip, (char*)&ip, sizeof(INPUT_RECORD) ); - rc = TRUE; - } - return(rc); + ReadConsoleInput(hConIn, &ip, 1, &read); + + keyCount = GetInterestingEvent(&ip); + if (keyCount) + { + /* To get here a recognised event has occurred; save it + and return TRUE */ + + memcpy((char*)&save_ip, (char*)&ip, sizeof(INPUT_RECORD)); + rc = TRUE; + } + + return rc; } /***********************************************************************/ static void win32_getch(void) /***********************************************************************/ { - while (win32_kbhit(INFINITE) == FALSE) - ; + while (win32_kbhit(INFINITE) == FALSE) + ; - keyCount --; - - return; + keyCount--; } #endif /*man-start********************************************************************* - PDC_get_key_modifiers() - Returns the keyboard modifier(s) at time of last getch() + PDC_get_key_modifiers() - Returns the keyboard modifier(s) at time + of last getch() PDCurses Description: - This is a private PDCurses routine. + This is a private PDCurses routine. - Returns the keyboard modifiers effective at the time of the last getch() - call only if PDC_save_key_modifiers(TRUE) has been called before the - getch(); - Use the macros; PDC_KEY_MODIFIER_* to determine which modifier(s) - were set. + Returns the keyboard modifiers effective at the time of the last + getch() call only if PDC_save_key_modifiers(TRUE) has been + called before the getch(). Use the macros; PDC_KEY_MODIFIER_* to + determine which modifier(s) were set. PDCurses Return Value: - This function returns the modifiers. + This function returns the modifiers. PDCurses Errors: - No errors are defined for this function. + No errors are defined for this function. Portability: - PDCurses int PDC_get_key_modifiers( void ); + PDCurses int PDC_get_key_modifiers(void); **man-end**********************************************************************/ /***********************************************************************/ #ifdef HAVE_PROTO -unsigned long PDC_get_key_modifiers(void) +unsigned long PDC_get_key_modifiers(void) #else -unsigned long PDC_get_key_modifiers() +unsigned long PDC_get_key_modifiers() #endif /***********************************************************************/ { - PDC_LOG(("PDC_get_key_modifiers() - called\n")); + PDC_LOG(("PDC_get_key_modifiers() - called\n")); - return(pdc_key_modifiers); + return pdc_key_modifiers; } - #if defined(PDC_THREAD_BUILD) /***********************************************************************/ -LONG InputThread( LPVOID lpThreadData ) +LONG InputThread(LPVOID lpThreadData) /***********************************************************************/ { - INPUT_RECORD ip; - DWORD read; - LONG prev; - int num_keys,i; + INPUT_RECORD ip; + DWORD read; + LONG prev; + int num_keys, i; - PDC_LOG(("-->InputThread() - called\n")); + PDC_LOG(("-->InputThread() - called\n")); - /* - * Create a semaphore on which the parent thread will wait... - */ - hSemKeyCount = CreateSemaphore( NULL, 0, 1024, NULL ); - if ( hSemKeyCount != NULL ) - { - for ( ; ; ) - { - ReadConsoleInput(hConIn, &ip, 1, &read); - /* - * Now that this thread has woken up we need to check if the - * key/mouse event is relevant to us. If so, write it to the - * anonymous pipe. - */ + /* Create a semaphore on which the parent thread will wait */ - PDC_LOG(("-->InputThread() - read %d character(s)\n",read)); + hSemKeyCount = CreateSemaphore(NULL, 0, 1024, NULL); + if (hSemKeyCount != NULL) + { + for (;;) + { + ReadConsoleInput(hConIn, &ip, 1, &read); - num_keys = GetInterestingEvent( &ip ); + /* Now that this thread has woken up we need to check if + the key/mouse event is relevant to us. If so, write + it to the anonymous pipe. */ - PDC_LOG(("-->InputThread() - got %d interesting keys\n",num_keys)); + PDC_LOG(("-->InputThread() - read %d character(s)\n", + read)); - for ( i = 0; i < num_keys; i++ ) - { - /* - * For each key written to the pipe, increment the semaphore... - */ - if ( ReleaseSemaphore( hSemKeyCount, 1, &prev ) ) - { - PDC_LOG(("-->InputThread() - writing to pipe; sem incremented from %d\n",prev)); + num_keys = GetInterestingEvent(&ip); - if ( !WriteFile( hPipeWrite, &ip, sizeof(INPUT_RECORD), &read, NULL ) ) - { - /* - * An error occured, we assume it is because the pipe broke; - * therefore the parent thread is shutting down; so will we. - */ - break; - } - } - } - } - } + PDC_LOG(("-->InputThread() - got %d interesting keys\n", + num_keys)); - PDC_LOG(("-->InputThread() - finished\n")); + /* For each key written to the pipe, increment the + semaphore */ - return 0; + for (i = 0; i < num_keys; i++) + if (ReleaseSemaphore(hSemKeyCount, 1, &prev)) + { + PDC_LOG(("-->InputThread() - writing to pipe; sem incremented from %d\n", + prev)); + + /* If an error occured, we assume it is because + the pipe broke; therefore the parent thread + is shutting down; so will we. */ + + if (!WriteFile(hPipeWrite, &ip, sizeof(INPUT_RECORD), + &read, NULL)) + /* break; */ + return 0; /* ? */ + } + } + } + + PDC_LOG(("-->InputThread() - finished\n")); + + return 0; } #endif diff --git a/win32/pdcprint.c b/win32/pdcprint.c index d217a73a..bfdc27de 100644 --- a/win32/pdcprint.c +++ b/win32/pdcprint.c @@ -21,37 +21,36 @@ #include #ifdef PDCDEBUG -char *rcsid_PDCprint = "$Id: pdcprint.c,v 1.2 2006/01/03 07:34:43 wmcbrine Exp $"; +char *rcsid_PDCprint = "$Id: pdcprint.c,v 1.3 2006/01/08 11:53:43 wmcbrine Exp $"; #endif - /*man-start********************************************************************* PDC_print() - Provides primitive access to the BIOS printer functions PDCurses Description: - This is a private PDCurses routine. + This is a private PDCurses routine. - Implements write/init/read printer services at the BIOS level. + Implements write/init/read printer services at the BIOS level. - This provides the basic support that PDCurses needs to dump the - contents of windows or pads to the printer attached to the BIOS - printer port. + This provides the basic support that PDCurses needs to dump the + contents of windows or pads to the printer attached to the BIOS + printer port. PDCurses Return Value: - See the BIOS INT 0x17 specifications. + See the BIOS INT 0x17 specifications. PDCurses Errors: - See the BIOS INT 0x17 specifications. + See the BIOS INT 0x17 specifications. Portability: - PDCurses int PDC_print( int cmd, int byte, int port ); + PDCurses int PDC_print(int cmd, int byte, int port); **man-end**********************************************************************/ -int PDC_print(int cmd, int byte, int port) +int PDC_print(int cmd, int byte, int port) { PDC_LOG(("PDC_print() - called\n")); - return( OK ); + return OK; } diff --git a/win32/pdcscrn.c b/win32/pdcscrn.c index 62401966..ea72fef6 100644 --- a/win32/pdcscrn.c +++ b/win32/pdcscrn.c @@ -22,7 +22,7 @@ #include #ifdef PDCDEBUG -char *rcsid_PDCscrn = "$Id: pdcscrn.c,v 1.15 2006/01/04 00:19:50 wmcbrine Exp $"; +char *rcsid_PDCscrn = "$Id: pdcscrn.c,v 1.16 2006/01/08 11:53:43 wmcbrine Exp $"; #endif #define PDC_RESTORE_NONE 0 @@ -35,7 +35,7 @@ HANDLE hConIn = INVALID_HANDLE_VALUE; HANDLE hPipeRead = INVALID_HANDLE_VALUE; HANDLE hPipeWrite = INVALID_HANDLE_VALUE; HANDLE hSemKeyCount = INVALID_HANDLE_VALUE; -extern LONG InputThread( LPVOID lpThreadData ); +extern LONG InputThread(LPVOID lpThreadData); #endif CONSOLE_SCREEN_BUFFER_INFO scr; @@ -50,64 +50,72 @@ static DWORD dwConsoleMode=0; PDC_scr_close() - Internal low-level binding to close the physical screen PDCurses Description: - This is a nop for the DOS platform. + This is a nop for the DOS platform. PDCurses Return Value: - This function returns OK on success, otherwise an ERR is returned. + This function returns OK on success, otherwise an ERR is + returned. PDCurses Errors: - The DOS platform will never fail. + The DOS platform will never fail. Portability: - PDCurses int PDC_scr_close( void ); + PDCurses int PDC_scr_close(void); **man-end**********************************************************************/ -int PDC_scr_close(void) +int PDC_scr_close(void) { - COORD origin; - SMALL_RECT rect; + COORD origin; + SMALL_RECT rect; - PDC_LOG(("PDC_scr_close() - called\n")); + PDC_LOG(("PDC_scr_close() - called\n")); - /* - * All of this code should probably go into DllMain() at DLL_PROCESS_DETACH - */ - SetConsoleScreenBufferSize(hConOut, orig_scr.dwSize); - SetConsoleWindowInfo(hConOut,TRUE,&orig_scr.srWindow); - SetConsoleScreenBufferSize(hConOut, orig_scr.dwSize); - SetConsoleWindowInfo(hConOut,TRUE,&orig_scr.srWindow); + /* All of this code should probably go into DllMain() at + DLL_PROCESS_DETACH */ - if (SP->_restore == PDC_RESTORE_WINDOW) - { - rect.Top = orig_scr.srWindow.Top; - rect.Left = orig_scr.srWindow.Left; - rect.Bottom = orig_scr.srWindow.Bottom; - rect.Right = orig_scr.srWindow.Right; - origin.X = origin.Y = 0; - if (!WriteConsoleOutput(hConOut,ciSaveBuffer,orig_scr.dwSize,origin,&rect)) - return(ERR); - } - else if (SP->_restore == PDC_RESTORE_BUFFER) - { - rect.Top = rect.Left = 0; - rect.Bottom = orig_scr.dwSize.Y - 1; - rect.Right = orig_scr.dwSize.X - 1; - origin.X = origin.Y = 0; - if (!WriteConsoleOutput(hConOut,ciSaveBuffer,orig_scr.dwSize,origin,&rect)) - return(ERR); - } + SetConsoleScreenBufferSize(hConOut, orig_scr.dwSize); + SetConsoleWindowInfo(hConOut,TRUE, &orig_scr.srWindow); + SetConsoleScreenBufferSize(hConOut, orig_scr.dwSize); + SetConsoleWindowInfo(hConOut, TRUE, &orig_scr.srWindow); + + if (SP->_restore == PDC_RESTORE_WINDOW) + { + rect.Top = orig_scr.srWindow.Top; + rect.Left = orig_scr.srWindow.Left; + rect.Bottom = orig_scr.srWindow.Bottom; + rect.Right = orig_scr.srWindow.Right; + + origin.X = origin.Y = 0; + + if (!WriteConsoleOutput(hConOut, ciSaveBuffer, + orig_scr.dwSize, origin, &rect)) + return ERR; + } + else if (SP->_restore == PDC_RESTORE_BUFFER) + { + rect.Top = rect.Left = 0; + rect.Bottom = orig_scr.dwSize.Y - 1; + rect.Right = orig_scr.dwSize.X - 1; + + origin.X = origin.Y = 0; + + if (!WriteConsoleOutput(hConOut, ciSaveBuffer, + orig_scr.dwSize, origin, &rect)) + return ERR; + } + + SetConsoleActiveScreenBuffer(hConOut); + SetConsoleMode(hConIn, dwConsoleMode); - SetConsoleActiveScreenBuffer(hConOut); - SetConsoleMode(hConIn, dwConsoleMode); #if defined(PDC_THREAD_BUILD) - if ( hPipeRead != INVALID_HANDLE_VALUE ) - CloseHandle( hPipeRead ); - if ( hPipeWrite != INVALID_HANDLE_VALUE ) - CloseHandle( hPipeWrite ); -#endif + if (hPipeRead != INVALID_HANDLE_VALUE) + CloseHandle(hPipeRead); - return( OK ); + if (hPipeWrite != INVALID_HANDLE_VALUE) + CloseHandle(hPipeWrite); +#endif + return OK; } /*man-start********************************************************************* @@ -115,27 +123,28 @@ int PDC_scr_close(void) PDC_scrn_modes_equal() - Decide if two screen modes are equal PDCurses Description: - Mainly required for OS/2. It decides if two screen modes - (VIOMODEINFO structure) are equal. Under DOS it just compares - two integers + Mainly required for OS/2. It decides if two screen modes + (VIOMODEINFO structure) are equal. Under DOS it just compares + two integers. PDCurses Return Value: - This function returns TRUE if equal else FALSe. + This function returns TRUE if equal else FALSe. PDCurses Errors: - No errors are defined for this function. + No errors are defined for this function. Portability: - PDCurses int PDC_scrn_modes_equal( int mode1, int mode2 ); - OS2 PDCurses int PDC_scrn_modes_equal( VIOMODEINFO mode1, VIOMODEINFO mode2 ); + PDCurses int PDC_scrn_modes_equal(int mode1, int mode2); + OS2 PDCurses int PDC_scrn_modes_equal(VIOMODEINFO mode1, + VIOMODEINFO mode2); **man-end**********************************************************************/ -bool PDC_scrn_modes_equal(int mode1, int mode2) +bool PDC_scrn_modes_equal(int mode1, int mode2) { - PDC_LOG(("PDC_scrn_modes_equal() - called\n")); + PDC_LOG(("PDC_scrn_modes_equal() - called\n")); - return (mode1 == mode2); + return (mode1 == mode2); } /*man-start********************************************************************* @@ -143,290 +152,335 @@ bool PDC_scrn_modes_equal(int mode1, int mode2) PDC_scr_open() - Internal low-level binding to open the physical screen PDCurses Description: - This is a NOP for the DOS platform. + This is a NOP for the DOS platform. PDCurses Return Value: - This function returns OK on success, otherwise an ERR is returned. + This function returns OK on success, otherwise an ERR is + returned. PDCurses Errors: - The DOS platform will never fail. + The DOS platform will never fail. Portability: - PDCurses int PDC_scr_open( SCREEN* internal, bool echo ); + PDCurses int PDC_scr_open(SCREEN *internal, bool echo); **man-end**********************************************************************/ -int PDC_scr_open(SCREEN *internal, bool echo) +int PDC_scr_open(SCREEN *internal, bool echo) { - COORD bufsize,origin; - SMALL_RECT rect; - char *str; - CONSOLE_SCREEN_BUFFER_INFO csbi; + COORD bufsize,origin; + SMALL_RECT rect; + char *str; + CONSOLE_SCREEN_BUFFER_INFO csbi; + #if defined(PDC_THREAD_BUILD) - HANDLE hThread; - DWORD dwThreadID; + HANDLE hThread; + DWORD dwThreadID; #endif + PDC_LOG(("PDC_scr_open() - called\n")); - PDC_LOG(("PDC_scr_open() - called\n")); + hConOut = GetStdHandle(STD_OUTPUT_HANDLE); + hConIn = GetStdHandle(STD_INPUT_HANDLE); - hConOut = GetStdHandle(STD_OUTPUT_HANDLE); - hConIn = GetStdHandle(STD_INPUT_HANDLE); + GetConsoleScreenBufferInfo(hConOut, &csbi); + GetConsoleScreenBufferInfo(hConOut, &orig_scr); + GetConsoleMode(hConIn, &dwConsoleMode); - GetConsoleScreenBufferInfo(hConOut, &csbi); - GetConsoleScreenBufferInfo(hConOut, &orig_scr); - GetConsoleMode(hConIn, &dwConsoleMode); + if ((str = getenv("LINES")) != NULL) + internal->lines = atoi(str); + else + internal->lines = PDC_get_rows(); - if ((str = getenv("LINES")) != NULL) - internal->lines = atoi(str); - else - internal->lines = PDC_get_rows(); + if ((str = getenv("COLS")) != NULL) + internal->cols = atoi(str); + else + internal->cols = PDC_get_columns(); - if ((str = getenv("COLS")) != NULL) - internal->cols = atoi(str); - else - internal->cols = PDC_get_columns(); + if (internal->lines < 2 || + internal->lines > csbi.dwMaximumWindowSize.Y) + { + fprintf(stderr, "LINES value must be >= 2 and <= %d: got %d\n", + csbi.dwMaximumWindowSize.Y, internal->lines); - if (internal->lines < 2 - || internal->lines > csbi.dwMaximumWindowSize.Y) - { - fprintf(stderr,"LINES value must be >= 2 and <= %d: got %d\n", - csbi.dwMaximumWindowSize.Y, - internal->lines); - return(ERR); - } + return ERR; + } - if (internal->cols < 2 - || internal->cols > csbi.dwMaximumWindowSize.X) - { - fprintf(stderr,"COLS value must be >= 2 and <= %d: got %d\n", - csbi.dwMaximumWindowSize.X, - internal->cols); - return(ERR); - } - if ( getenv( "PDC_ORIGINAL_COLORS" ) != NULL ) - { - chtype orig_back, orig_fore; - orig_fore = csbi.wAttributes & 0x0f; - orig_back = (csbi.wAttributes & 0xf0) >> 4; - internal->orig_attr = (orig_back << 16) | orig_fore; - } - else - { - internal->orig_attr = 0; - } + if (internal->cols < 2 || + internal->cols > csbi.dwMaximumWindowSize.X) + { + fprintf(stderr, "COLS value must be >= 2 and <= %d: got %d\n", + csbi.dwMaximumWindowSize.X, internal->cols); - internal->_restore = PDC_RESTORE_NONE; - if (getenv("PDC_RESTORE_SCREEN") != NULL) - { - /* - * Attempt to save the complete console buffer... - */ - if ((ciSaveBuffer = (CHAR_INFO*)malloc(orig_scr.dwSize.X*orig_scr.dwSize.Y*sizeof(CHAR_INFO))) == NULL) - { - PDC_LOG(("PDC_scr_open() - exiting at line %d\n",__LINE__)); + return ERR; + } - return(ERR); - } - bufsize.X = orig_scr.dwSize.X; - bufsize.Y = orig_scr.dwSize.Y; + if (getenv("PDC_ORIGINAL_COLORS") != NULL) + { + chtype orig_back, orig_fore; - origin.X = origin.Y = 0; + orig_fore = csbi.wAttributes & 0x0f; + orig_back = (csbi.wAttributes & 0xf0) >> 4; - rect.Top = rect.Left = 0; - rect.Bottom = orig_scr.dwSize.Y - 1; - rect.Right = orig_scr.dwSize.X - 1; - if (!ReadConsoleOutput(hConOut,ciSaveBuffer,bufsize,origin,&rect)) - { - /* - * We can't save the complete buffer, so try and save just the displayed window... - */ - free(ciSaveBuffer); - ciSaveBuffer = NULL; + internal->orig_attr = (orig_back << 16) | orig_fore; + } + else + internal->orig_attr = 0; - bufsize.X = orig_scr.srWindow.Right - orig_scr.srWindow.Left + 1; - bufsize.Y = orig_scr.srWindow.Bottom - orig_scr.srWindow.Top + 1; - if ((ciSaveBuffer = (CHAR_INFO*)malloc(bufsize.X*bufsize.Y*sizeof(CHAR_INFO))) == NULL) - { - CHAR LastError[256]; - ULONG last_error = GetLastError(); - FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM, NULL, last_error, MAKELANGID( LANG_NEUTRAL, SUBLANG_DEFAULT), LastError, 256, NULL ) ; + internal->_restore = PDC_RESTORE_NONE; - PDC_LOG(("PDC_scr_open() - exiting at line %d: %s\n",__LINE__,LastError)); + if (getenv("PDC_RESTORE_SCREEN") != NULL) + { + /* Attempt to save the complete console buffer */ - return(ERR); - } + if ((ciSaveBuffer = (CHAR_INFO*)malloc(orig_scr.dwSize.X * + orig_scr.dwSize.Y * sizeof(CHAR_INFO))) == NULL) + { + PDC_LOG(("PDC_scr_open() - exiting at line %d\n", + __LINE__)); - origin.X = origin.Y = 0; + return ERR; + } - rect.Top = orig_scr.srWindow.Top; - rect.Left = orig_scr.srWindow.Left; - rect.Bottom = orig_scr.srWindow.Bottom; - rect.Right = orig_scr.srWindow.Right; - if (!ReadConsoleOutput(hConOut,ciSaveBuffer,bufsize,origin,&rect)) - { - CHAR LastError[256]; - ULONG last_error = GetLastError(); - FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM, NULL, last_error, MAKELANGID( LANG_NEUTRAL, SUBLANG_DEFAULT), LastError, 256, NULL ) ; - free(ciSaveBuffer); - ciSaveBuffer = NULL; + bufsize.X = orig_scr.dwSize.X; + bufsize.Y = orig_scr.dwSize.Y; - PDC_LOG(("PDC_scr_open() - exiting at line %d: %s\n",__LINE__,LastError)); + origin.X = origin.Y = 0; - return(ERR); - } - internal->_restore = PDC_RESTORE_WINDOW; - } - else - internal->_restore = PDC_RESTORE_BUFFER; - } + rect.Top = rect.Left = 0; + rect.Bottom = orig_scr.dwSize.Y - 1; + rect.Right = orig_scr.dwSize.X - 1; - if (getenv("PDC_PRESERVE_SCREEN") != NULL) - { - bufsize.X = csbi.srWindow.Right - csbi.srWindow.Left + 1; - bufsize.Y = csbi.srWindow.Bottom - csbi.srWindow.Top + 1; - if ((save_ci = (CHAR_INFO*)malloc(bufsize.X*bufsize.Y*sizeof(CHAR_INFO))) == NULL) - { - CHAR LastError[256]; - ULONG last_error = GetLastError(); - FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM, NULL, last_error, MAKELANGID( LANG_NEUTRAL, SUBLANG_DEFAULT), LastError, 256, NULL ) ; + if (!ReadConsoleOutput(hConOut, ciSaveBuffer, bufsize, + origin, &rect)) + { + /* We can't save the complete buffer, so try and + save just the displayed window */ - PDC_LOG(("PDC_scr_open() - exiting at line %d: %s\n",__LINE__,LastError)); + free(ciSaveBuffer); + ciSaveBuffer = NULL; - return(ERR); - } + bufsize.X = orig_scr.srWindow.Right - + orig_scr.srWindow.Left + 1; + bufsize.Y = orig_scr.srWindow.Bottom - + orig_scr.srWindow.Top + 1; - origin.X = origin.Y = 0; + if ((ciSaveBuffer = (CHAR_INFO*)malloc(bufsize.X * + bufsize.Y * sizeof(CHAR_INFO))) == NULL) + { + CHAR LastError[256]; + ULONG last_error = GetLastError(); - rect.Top = csbi.srWindow.Top; - rect.Left = csbi.srWindow.Left; - rect.Bottom = csbi.srWindow.Bottom; - rect.Right = csbi.srWindow.Right; - if (!ReadConsoleOutput(hConOut,save_ci,bufsize,origin,&rect)) - { - CHAR LastError[256]; - ULONG last_error = GetLastError(); - FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM, NULL, last_error, MAKELANGID( LANG_NEUTRAL, SUBLANG_DEFAULT), LastError, 256, NULL ) ; - free(save_ci); - save_ci = NULL; + FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, + last_error, MAKELANGID(LANG_NEUTRAL, + SUBLANG_DEFAULT), LastError, 256, NULL); - PDC_LOG(("PDC_scr_open() - exiting at line %d: %s\n",__LINE__,LastError)); + PDC_LOG(("PDC_scr_open() - exiting at line %d: %s\n", + __LINE__, LastError)); - return(ERR); - } - internal->_preserve = TRUE; - } - else - internal->_preserve = FALSE; + return ERR; + } - bufsize.X = orig_scr.srWindow.Right - orig_scr.srWindow.Left + 1; - bufsize.Y = orig_scr.srWindow.Bottom - orig_scr.srWindow.Top + 1; - rect.Top = rect.Left = 0; - rect.Bottom = bufsize.Y - 1; - rect.Right = bufsize.X - 1; + origin.X = origin.Y = 0; - SetConsoleScreenBufferSize(hConOut, bufsize); - SetConsoleWindowInfo(hConOut,TRUE,&rect); - SetConsoleScreenBufferSize(hConOut, bufsize); - SetConsoleActiveScreenBuffer(hConOut); + rect.Top = orig_scr.srWindow.Top; + rect.Left = orig_scr.srWindow.Left; + rect.Bottom = orig_scr.srWindow.Bottom; + rect.Right = orig_scr.srWindow.Right; - PDC_reset_prog_mode(); + if (!ReadConsoleOutput(hConOut, ciSaveBuffer, + bufsize, origin, &rect)) + { + CHAR LastError[256]; + ULONG last_error = GetLastError(); - PDC_get_cursor_pos(&internal->cursrow, &internal->curscol); - internal->direct_video = TRUE; /* Assume that we can */ - internal->autocr = TRUE; /* lf -> crlf by default */ - internal->raw_out = FALSE; /* tty I/O modes */ - internal->raw_inp = FALSE; /* tty I/O modes */ - internal->cbreak = TRUE; - internal->save_key_modifiers = FALSE; - internal->return_key_modifiers = FALSE; - internal->echo = echo; - internal->refrbrk = FALSE; /* no premature end of refresh*/ - internal->video_seg = 0xb000; /* Base screen segment addr */ - internal->video_ofs = 0x0; /* Base screen segment ofs */ - internal->video_page = 0; /* Current Video Page */ - internal->visible_cursor= TRUE; /* Assume that it is visible */ - internal->cursor = PDC_get_cursor_mode(); + FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, + last_error, MAKELANGID(LANG_NEUTRAL, + SUBLANG_DEFAULT), LastError, 256, NULL); - internal->adapter = PDC_query_adapter_type(); - internal->scrnmode = PDC_get_scrn_mode(); + free(ciSaveBuffer); + ciSaveBuffer = NULL; - internal->audible = TRUE; - internal->visibility = 1; - internal->orig_cursor = internal->cursor; - internal->orgcbr = PDC_get_ctrl_break(); - internal->blank = ' '; - internal->resized = FALSE; - internal->shell = FALSE; - internal->_trap_mbe = 0L; - internal->_map_mbe_to_key = 0L; - internal->linesrippedoff = 0; - internal->linesrippedoffontop = 0; - internal->delaytenths = 0; + PDC_LOG(("PDC_scr_open() - exiting at line %d: %s\n", + __LINE__, LastError)); - internal->os_version = GetVersion(); + return ERR; + } + + internal->_restore = PDC_RESTORE_WINDOW; + } + else + internal->_restore = PDC_RESTORE_BUFFER; + } + + if (getenv("PDC_PRESERVE_SCREEN") != NULL) + { + bufsize.X = csbi.srWindow.Right - csbi.srWindow.Left + 1; + bufsize.Y = csbi.srWindow.Bottom - csbi.srWindow.Top + 1; + + if ((save_ci = (CHAR_INFO*)malloc(bufsize.X * bufsize.Y * + sizeof(CHAR_INFO))) == NULL) + { + CHAR LastError[256]; + ULONG last_error = GetLastError(); + + FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, + last_error, MAKELANGID(LANG_NEUTRAL, + SUBLANG_DEFAULT), LastError, 256, NULL); + + PDC_LOG(("PDC_scr_open() - exiting at line %d: %s\n", + __LINE__, LastError)); + + return ERR; + } + + origin.X = origin.Y = 0; + + rect.Top = csbi.srWindow.Top; + rect.Left = csbi.srWindow.Left; + rect.Bottom = csbi.srWindow.Bottom; + rect.Right = csbi.srWindow.Right; + + if (!ReadConsoleOutput(hConOut, save_ci, bufsize, + origin, &rect)) + { + CHAR LastError[256]; + ULONG last_error = GetLastError(); + + FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, + last_error, MAKELANGID(LANG_NEUTRAL, + SUBLANG_DEFAULT), LastError, 256, NULL); + + free(save_ci); + save_ci = NULL; + + PDC_LOG(("PDC_scr_open() - exiting at line %d: %s\n", + __LINE__, LastError)); + + return ERR; + } + + internal->_preserve = TRUE; + } + else + internal->_preserve = FALSE; + + bufsize.X = orig_scr.srWindow.Right - orig_scr.srWindow.Left + 1; + bufsize.Y = orig_scr.srWindow.Bottom - orig_scr.srWindow.Top + 1; + + rect.Top = rect.Left = 0; + rect.Bottom = bufsize.Y - 1; + rect.Right = bufsize.X - 1; + + SetConsoleScreenBufferSize(hConOut, bufsize); + SetConsoleWindowInfo(hConOut,TRUE, &rect); + SetConsoleScreenBufferSize(hConOut, bufsize); + SetConsoleActiveScreenBuffer(hConOut); + + PDC_reset_prog_mode(); + + PDC_get_cursor_pos(&internal->cursrow, &internal->curscol); + + internal->direct_video = TRUE; /* Assume that we can */ + internal->autocr = TRUE; /* lf -> crlf by default */ + internal->raw_out = FALSE; /* tty I/O modes */ + internal->raw_inp = FALSE; /* tty I/O modes */ + internal->cbreak = TRUE; + internal->save_key_modifiers = FALSE; + internal->return_key_modifiers = FALSE; + internal->echo = echo; + internal->refrbrk = FALSE; /* no premature end of refresh */ + internal->video_seg = 0xb000; /* Base screen segment addr */ + internal->video_ofs = 0; /* Base screen segment ofs */ + internal->video_page = 0; /* Current Video Page */ + internal->visible_cursor= TRUE; /* Assume that it is visible */ + + internal->cursor = PDC_get_cursor_mode(); + internal->adapter = PDC_query_adapter_type(); + internal->scrnmode = PDC_get_scrn_mode(); + + internal->audible = TRUE; + internal->visibility = 1; + internal->orig_cursor = internal->cursor; + + internal->orgcbr = PDC_get_ctrl_break(); + + internal->blank = ' '; + internal->resized = FALSE; + internal->shell = FALSE; + internal->_trap_mbe = 0L; + internal->_map_mbe_to_key = 0L; + internal->linesrippedoff = 0; + internal->linesrippedoffontop = 0; + internal->delaytenths = 0; + + internal->os_version = GetVersion(); #if defined(PDC_THREAD_BUILD) - /* - * Create the anonymous pipe and thread for handling input - */ - if ( !CreatePipe( &hPipeRead, // reading handle - &hPipeWrite, // writing handle - NULL, // handles not inherited - 0 ) ) // default buffer size - { - // error during pipe creation - fprintf( stderr, "Cannot create input pipe\n" ); - return( ERR ); - } - hThread = CreateThread( NULL, // security attributes - 0, // initial stack size - (LPTHREAD_START_ROUTINE) InputThread, - NULL, // argument - CREATE_SUSPENDED, // creation flag - &dwThreadID ); // new thread ID - if ( ! hThread ) - { - fprintf( stderr, "Cannot create input thread\n" ); - return( ERR ); - } - ResumeThread( hThread ); -#endif - return( OK ); + /* Create the anonymous pipe and thread for handling input */ + + if (!CreatePipe(&hPipeRead, /* reading handle */ + &hPipeWrite, /* writing handle */ + NULL, /* handles not inherited */ + 0)) /* default buffer size */ + { + /* error during pipe creation */ + + fprintf(stderr, "Cannot create input pipe\n"); + return ERR; + } + + hThread = CreateThread(NULL, /* security attributes */ + 0, /* initial stack size */ + (LPTHREAD_START_ROUTINE) InputThread, + NULL, /* argument */ + CREATE_SUSPENDED, /* creation flag */ + &dwThreadID); /* new thread ID */ + + if (!hThread) + { + fprintf(stderr, "Cannot create input thread\n"); + return ERR; + } + + ResumeThread(hThread); +#endif + return OK; } + /* Calls SetConsoleWindowInfo with the given parameters, but fits them + if a scoll bar shrinks the maximum possible value. The rectangle + must at least fit in a half-sized window. */ + static BOOL FitConsoleWindow(HANDLE hConOut, CONST SMALL_RECT *rect) -/* Calls SetConsoleWindowInfo with the given parameters but fits them if a - * scoll bar shrinks the maximum possible value. The rectangle must at least - * fit in a half-sized window. - */ { - SMALL_RECT run; - SHORT mx, my; + SMALL_RECT run; + SHORT mx, my; - if (SetConsoleWindowInfo(hConOut, TRUE, rect)) - return(TRUE); + if (SetConsoleWindowInfo(hConOut, TRUE, rect)) + return TRUE; - run = *rect; - run.Right /= 2; - run.Bottom /= 2; - mx = run.Right; - my = run.Bottom; + run = *rect; + run.Right /= 2; + run.Bottom /= 2; - if (!SetConsoleWindowInfo(hConOut, TRUE, &run)) - return(FALSE); - for (run.Right = rect->Right;run.Right >= mx;run.Right--) - { - if (SetConsoleWindowInfo(hConOut, TRUE, &run)) - break; - } - if (run.Right < mx) - return(FALSE); - for (run.Bottom = rect->Bottom;run.Bottom >= my;run.Bottom--) - { - if (SetConsoleWindowInfo(hConOut, TRUE, &run)) - return(TRUE); - } - return(FALSE); + mx = run.Right; + my = run.Bottom; + + if (!SetConsoleWindowInfo(hConOut, TRUE, &run)) + return(FALSE); + + for (run.Right = rect->Right; run.Right >= mx; run.Right--) + if (SetConsoleWindowInfo(hConOut, TRUE, &run)) + break; + + if (run.Right < mx) + return FALSE; + + for (run.Bottom = rect->Bottom; run.Bottom >= my; run.Bottom--) + if (SetConsoleWindowInfo(hConOut, TRUE, &run)) + return TRUE; + + return FALSE; } /*man-start********************************************************************* @@ -434,183 +488,212 @@ static BOOL FitConsoleWindow(HANDLE hConOut, CONST SMALL_RECT *rect) PDC_resize_screen() - Internal low-level function to resize screen PDCurses Description: - This function provides a means for the application program to - resize the overall dimensions of the screen. Under DOS and OS/2 - the application can tell PDCurses what size to make the screen; - under X11, resizing is done by the user and this function simply - adjusts its internal structures to fit the new size. - This function doesn't set LINES, COLS, SP->lines or SP->cols. This - must be done by resize_term. - If both arguments are 0 the function returns sucessfully. This - allows the calling routine to reset the SP->resized flag. - The functions fails if one of the arguments is less then 2. + This function provides a means for the application program to + resize the overall dimensions of the screen. Under DOS and OS/2 + the application can tell PDCurses what size to make the screen; + under X11, resizing is done by the user and this function simply + adjusts its internal structures to fit the new size. This + function doesn't set LINES, COLS, SP->lines or SP->cols. This + must be done by resize_term. If both arguments are 0 the + function returns sucessfully. This allows the calling routine to + reset the SP->resized flag. The functions fails if one of the + arguments is less then 2. PDCurses Return Value: - This function returns OK on success, otherwise an ERR is returned. - - PDCurses Errors: + This function returns OK on success, otherwise an ERR is + returned. Portability: - PDCurses int PDC_resize_screen( int, int ); + PDCurses int PDC_resize_screen(int, int); **man-end**********************************************************************/ /***********************************************************************/ #ifdef HAVE_PROTO -int PDC_resize_screen(int nlines, int ncols) +int PDC_resize_screen(int nlines, int ncols) #else -int PDC_resize_screen(nlines, ncols) -int nlines,ncols; +int PDC_resize_screen(nlines, ncols) +int nlines, ncols; #endif /***********************************************************************/ { -#ifdef MHES - COORD size, max; - SMALL_RECT rect,displayarea = {0,0,0,0}; - CONSOLE_SCREEN_BUFFER_INFO csbi; - int external_resized = SP->resized; +#if defined(MHES) - PDC_LOG(("PDC_resize_screen() - called. Lines: %d Cols: %d\n",nlines,ncols)); + COORD size, max; + SMALL_RECT rect, displayarea = {0,0,0,0}; + CONSOLE_SCREEN_BUFFER_INFO csbi; - SP->resized = FALSE; /* prevent endless loops in case of errors */ + int external_resized = SP->resized; - if (nlines == 0 - && ncols == 0) - return(OK); /* undocumented feature: let assign LINES and COLS - to current values by the calling - resize_term-function */ + PDC_LOG(("PDC_resize_screen() - called. Lines: %d Cols: %d\n", + nlines, ncols)); - if (nlines < 2 || ncols < 2) - return(ERR); + /* prevent endless loops in case of errors */ - if (!GetConsoleScreenBufferInfo(hConOut,&csbi)) /*needed for recovery*/ - return(ERR); - max = GetLargestConsoleWindowSize(hConOut); + SP->resized = FALSE; - size.X = ncols; - size.Y = nlines; + /* undocumented feature: let assign LINES and COLS to current + values by the calling resize_term-function */ - /* Fit window into allowed values */ - rect.Left = rect.Top = 0; - rect.Right = ncols - 1; - if (rect.Right >= max.X) - rect.Right = max.X; - rect.Bottom = rect.Top + nlines - 1; - if (rect.Bottom >= max.Y) - rect.Bottom = max.Y; - FitConsoleWindow(hConOut, &rect); /* helps to allow the BufferSize */ - displayarea.Right = rect.Right; - displayarea.Bottom = rect.Bottom; - if (!SetConsoleScreenBufferSize(hConOut, size) || - !FitConsoleWindow(hConOut, &rect) || - !SetConsoleWindowInfo(hConOut, TRUE, &displayarea)) - { - SetConsoleScreenBufferSize(hConOut, csbi.dwSize); - SetConsoleWindowInfo(hConOut, TRUE, &csbi.srWindow); - return( (external_resized) ? OK : ERR ); - } + if (nlines == 0 && ncols == 0) + return OK; + + if (nlines < 2 || ncols < 2) + return ERR; + + /* needed for recovery */ + + if (!GetConsoleScreenBufferInfo(hConOut, &csbi)) + return ERR; + + max = GetLargestConsoleWindowSize(hConOut); + + size.X = ncols; + size.Y = nlines; + + /* Fit window into allowed values */ + + rect.Left = rect.Top = 0; + rect.Right = ncols - 1; + + if (rect.Right >= max.X) + rect.Right = max.X; + + rect.Bottom = rect.Top + nlines - 1; + + if (rect.Bottom >= max.Y) + rect.Bottom = max.Y; + + /* helps to allow the BufferSize */ + + FitConsoleWindow(hConOut, &rect); + displayarea.Right = rect.Right; + displayarea.Bottom = rect.Bottom; + + if (!SetConsoleScreenBufferSize(hConOut, size) || + !FitConsoleWindow(hConOut, &rect) || + !SetConsoleWindowInfo(hConOut, TRUE, &displayarea)) + { + SetConsoleScreenBufferSize(hConOut, csbi.dwSize); + SetConsoleWindowInfo(hConOut, TRUE, &csbi.srWindow); + + return external_resized ? OK : ERR; + } + + SetConsoleActiveScreenBuffer(hConOut); + + return OK; - SetConsoleActiveScreenBuffer(hConOut); - return ( OK ); #elif defined(FGC) - int rc=OK; - COORD size; - SMALL_RECT rect; - PDC_LOG(("PDC_resize_screen() - called. Lines: %d Cols: %d\n",nlines,ncols)); + COORD size; + SMALL_RECT rect; - if (nlines < 2) - return(ERR); - SP->lines = LINES = nlines; + PDC_LOG(("PDC_resize_screen() - called. Lines: %d Cols: %d\n", + nlines, ncols)); - if (ncols < 2) - return(ERR); - SP->cols = COLS = ncols; + if (nlines < 2) + return ERR; - size.X = SP->cols; - size.Y = SP->lines; - rect.Top = rect.Left = 0; - rect.Bottom = SP->lines - 1; - rect.Right = SP->cols - 1; - SetConsoleScreenBufferSize(hConOut, size); - SetConsoleWindowInfo(hConOut,TRUE,&rect); - SetConsoleScreenBufferSize(hConOut, size); - SetConsoleWindowInfo(hConOut,TRUE,&rect); - SetConsoleActiveScreenBuffer(hConOut); - SP->resized = FALSE; - return ( rc ); + SP->lines = LINES = nlines; + + if (ncols < 2) + return ERR; + + SP->cols = COLS = ncols; + + size.X = SP->cols; + size.Y = SP->lines; + + rect.Top = rect.Left = 0; + rect.Bottom = SP->lines - 1; + rect.Right = SP->cols - 1; + + SetConsoleScreenBufferSize(hConOut, size); + SetConsoleWindowInfo(hConOut,TRUE, &rect); + SetConsoleScreenBufferSize(hConOut, size); + SetConsoleWindowInfo(hConOut,TRUE, &rect); + SetConsoleActiveScreenBuffer(hConOut); + + SP->resized = FALSE; + + return OK; #else - int rc=OK; - SMALL_RECT rect; - COORD size, max; + SMALL_RECT rect; + COORD size, max; - if (nlines < 2 || ncols < 2) - return(ERR); - max = GetLargestConsoleWindowSize(hConOut); + if (nlines < 2 || ncols < 2) + return ERR; - rect.Left = rect.Top = 0; - rect.Right = ncols - 1; - if (rect.Right >= max.X) - rect.Right = max.X; - rect.Bottom = nlines - 1; - if (rect.Bottom >= max.Y) - rect.Bottom = max.Y; - size.X = rect.Right + 1; - size.Y = rect.Bottom + 1; - FitConsoleWindow(hConOut, &rect); - SetConsoleScreenBufferSize(hConOut, size); - FitConsoleWindow(hConOut, &rect); - SetConsoleScreenBufferSize(hConOut, size); + max = GetLargestConsoleWindowSize(hConOut); + rect.Left = rect.Top = 0; + rect.Right = ncols - 1; - SetConsoleActiveScreenBuffer(hConOut); - SP->resized = FALSE; - return ( rc ); + if (rect.Right >= max.X) + rect.Right = max.X; + + rect.Bottom = nlines - 1; + + if (rect.Bottom >= max.Y) + rect.Bottom = max.Y; + + size.X = rect.Right + 1; + size.Y = rect.Bottom + 1; + + FitConsoleWindow(hConOut, &rect); + SetConsoleScreenBufferSize(hConOut, size); + FitConsoleWindow(hConOut, &rect); + SetConsoleScreenBufferSize(hConOut, size); + SetConsoleActiveScreenBuffer(hConOut); + + SP->resized = FALSE; + + return OK; #endif } /***********************************************************************/ #ifdef HAVE_PROTO -int PDC_reset_prog_mode(void) +int PDC_reset_prog_mode(void) #else -int PDC_reset_prog_mode() +int PDC_reset_prog_mode() #endif /***********************************************************************/ { - SetConsoleMode(hConIn, ENABLE_MOUSE_INPUT | ENABLE_WINDOW_INPUT); - return(OK); + SetConsoleMode(hConIn, ENABLE_MOUSE_INPUT | ENABLE_WINDOW_INPUT); + return OK; } /***********************************************************************/ #ifdef HAVE_PROTO -int PDC_reset_shell_mode(void) +int PDC_reset_shell_mode(void) #else -int PDC_reset_shell_mode() +int PDC_reset_shell_mode() #endif /***********************************************************************/ { - SetConsoleMode(hConIn, dwConsoleMode); - return(OK); + SetConsoleMode(hConIn, dwConsoleMode); + return OK; } #if defined(PDC_DLL_BUILD) -BOOL WINAPI DllMain( HINSTANCE hDLL, DWORD dwReason, LPVOID pReserved) +BOOL WINAPI DllMain(HINSTANCE hDLL, DWORD dwReason, LPVOID pReserved) { - switch( dwReason) - { - case DLL_PROCESS_ATTACH: -/* fprintf(stderr,"DLL_PROCESS_ATTACH\n"); */ - break; - case DLL_PROCESS_DETACH: -/* fprintf(stderr,"DLL_PROCESS_DETACH\n"); */ - break; - case DLL_THREAD_ATTACH: -/* fprintf(stderr,"DLL_THREAD_ATTACH\n"); */ - break; - case DLL_THREAD_DETACH: -/* fprintf(stderr,"DLL_THREAD_DETACH\n"); */ - break; - } - return(TRUE); + switch(dwReason) + { + case DLL_PROCESS_ATTACH: +/* fprintf(stderr, "DLL_PROCESS_ATTACH\n"); */ + break; + case DLL_PROCESS_DETACH: +/* fprintf(stderr, "DLL_PROCESS_DETACH\n"); */ + break; + case DLL_THREAD_ATTACH: +/* fprintf(stderr, "DLL_THREAD_ATTACH\n"); */ + break; + case DLL_THREAD_DETACH: +/* fprintf(stderr, "DLL_THREAD_DETACH\n"); */ + } + return TRUE; } #endif diff --git a/win32/pdcsetsc.c b/win32/pdcsetsc.c index 80111e20..43d9455d 100644 --- a/win32/pdcsetsc.c +++ b/win32/pdcsetsc.c @@ -22,7 +22,7 @@ #include #ifdef PDCDEBUG -char *rcsid_PDCsetsc = "$Id: pdcsetsc.c,v 1.5 2006/01/03 19:54:29 wmcbrine Exp $"; +char *rcsid_PDCsetsc = "$Id: pdcsetsc.c,v 1.6 2006/01/08 11:53:43 wmcbrine Exp $"; #endif extern HANDLE hConOut; @@ -32,26 +32,26 @@ extern HANDLE hConOut; PDC_set_80x25() - force a known screen state: 80x25 text mode. PDCurses Description: - This is a private PDCurses function. + This is a private PDCurses function. - Forces the appropriate 80x25 alpha mode given the display adapter. + Forces the appropriate 80x25 alpha mode given the display adapter. PDCurses Return Value: - This function returns OK upon success otherwise ERR is returned. + This function returns OK upon success otherwise ERR is returned. PDCurses Errors: - No errors are defined for this routine. + No errors are defined for this routine. Portability: - PDCurses int PDC_set_80x25( void ); + PDCurses int PDC_set_80x25(void); **man-end**********************************************************************/ -int PDC_set_80x25(void) +int PDC_set_80x25(void) { PDC_LOG(("PDC_set_80x25() - called\n")); - return(OK); + return OK; } /*man-start********************************************************************* @@ -59,25 +59,26 @@ int PDC_set_80x25(void) PDC_set_cursor_mode() - Set the cursor start and stop scan lines. PDCurses Description: - Sets the cursor type to begin in scan line startrow and end in - scan line endrow. Both values should be 0-31. + Sets the cursor type to begin in scan line startrow and end in + scan line endrow. Both values should be 0-31. PDCurses Return Value: - This function returns OK on success and ERR on error. + This function returns OK on success and ERR on error. PDCurses Errors: - No errors are defined for this function. + No errors are defined for this function. Portability: - PDCurses int PDC_set_cursor_mode( int startrow, int endrow ); + PDCurses int PDC_set_cursor_mode(int startrow, int endrow); **man-end**********************************************************************/ -int PDC_set_cursor_mode( int startrow, int endrow ) +int PDC_set_cursor_mode(int startrow, int endrow) { - PDC_LOG(("PDC_set_cursor_mode() - called: startrow %d endrow %d\n",startrow,endrow)); + PDC_LOG(("PDC_set_cursor_mode() - called: startrow %d endrow %d\n", + startrow, endrow)); - return(OK); + return OK; } /*man-start********************************************************************* @@ -85,30 +86,30 @@ int PDC_set_cursor_mode( int startrow, int endrow ) PDC_set_font() - sets the current font size PDCurses Description: - This is a private PDCurses function. + This is a private PDCurses function. - This routine sets the current font size, if the adapter allows - such a change. + This routine sets the current font size, if the adapter allows + such a change. PDCurses Return Value: - This function returns OK upon success otherwise ERR is returned. + This function returns OK upon success otherwise ERR is returned. PDCurses Errors: - It is an error to attempt to change the font size on a "bogus" - adapter. The reason for this is that we have a known video - adapter identity problem. e.g. Two adapters report the same - identifying characteristics. + It is an error to attempt to change the font size on a "bogus" + adapter. The reason for this is that we have a known video + adapter identity problem. e.g. Two adapters report the same + identifying characteristics. Portability: - PDCurses int PDC_set_font( int size ); + PDCurses int PDC_set_font(int size); **man-end**********************************************************************/ -int PDC_set_font(int size) +int PDC_set_font(int size) { PDC_LOG(("PDC_set_font() - called\n")); - return(OK); + return OK; } /*man-start********************************************************************* @@ -116,30 +117,30 @@ int PDC_set_font(int size) PDC_set_rows() - sets the physical number of rows on screen PDCurses Description: - This is a private PDCurses function. + This is a private PDCurses function. - This routine attempts to set the number of rows on the physical - screen to the passed value. + This routine attempts to set the number of rows on the physical + screen to the passed value. PDCurses Return Value: - This function returns OK upon success otherwise ERR is returned. + This function returns OK upon success otherwise ERR is returned. PDCurses Errors: - It is an error to attempt to change the screen size on a "bogus" - adapter. The reason for this is that we have a known video - adapter identity problem. e.g. Two adapters report the same - identifying characteristics. + It is an error to attempt to change the screen size on a "bogus" + adapter. The reason for this is that we have a known video + adapter identity problem. e.g. Two adapters report the same + identifying characteristics. Portability: - PDCurses int PDC_set_rows( int rows ); + PDCurses int PDC_set_rows(int rows); **man-end**********************************************************************/ -int PDC_set_rows(int rows) +int PDC_set_rows(int rows) { PDC_LOG(("PDC_set_rows() - called\n")); - return(0); + return OK; } /*man-start********************************************************************* @@ -161,17 +162,18 @@ int PDC_set_rows(int rows) **man-end**********************************************************************/ -int PDC_set_scrn_mode(int new_mode) +int PDC_set_scrn_mode(int new_mode) { PDC_LOG(("PDC_set_scrn_mode() - called\n")); - return(OK); /* this is N/A */ + return OK; } + /***********************************************************************/ #ifdef HAVE_PROTO -int PDC_curs_set(int visibility) +int PDC_curs_set(int visibility) #else -int PDC_curs_set(visibility) +int PDC_curs_set(visibility) int visibility; #endif /***********************************************************************/ @@ -179,7 +181,7 @@ int visibility; CONSOLE_CURSOR_INFO cci; int ret_vis; - PDC_LOG(("PDC_curs_set() - called: visibility=%d\n",visibility)); + PDC_LOG(("PDC_curs_set() - called: visibility=%d\n", visibility)); ret_vis = SP->visibility; @@ -188,17 +190,17 @@ int visibility; switch(visibility) { - case 0: /* invisible */ - cci.bVisible = FALSE; - break; - case 2: /* highly visible */ - cci.bVisible = TRUE; - cci.dwSize = 95; - break; - default: /* normal visibility */ - cci.bVisible = TRUE; - cci.dwSize = 25; - break; + case 0: /* invisible */ + cci.bVisible = FALSE; + break; + case 2: /* highly visible */ + cci.bVisible = TRUE; + cci.dwSize = 95; + break; + default: /* normal visibility */ + cci.bVisible = TRUE; + cci.dwSize = 25; + break; } if (SetConsoleCursorInfo(hConOut,&cci) == FALSE) @@ -213,29 +215,24 @@ int visibility; PDC_set_title() - Set window title PDCurses Description: - Sets the title of the window in which the curses program is running. - This function may not do anything on some platforms. - - PDCurses Return Value: - N/A - - PDCurses Errors: - No errors are defined for this function. + Sets the title of the window in which the curses program is + running. This function may not do anything on some platforms. Portability: - PDCurses void PDC_set_title( char *title ); + PDCurses void PDC_set_title(char *title); **man-end**********************************************************************/ + /***********************************************************************/ #ifdef HAVE_PROTO -void PDC_set_title(char *title) +void PDC_set_title(char *title) #else -void PDC_set_title(title) +void PDC_set_title(title) char *title; #endif /***********************************************************************/ { - PDC_LOG(("PDC_set_title() - called:<%s>\n",title)); + PDC_LOG(("PDC_set_title() - called:<%s>\n", title)); SetConsoleTitle(title); return;