home *** CD-ROM | disk | FTP | other *** search
-
- /* w4.c (c)Copyright Sequiter Software Inc., 1987-1990. All rights reserved.
-
- Window Routines
- */
-
- #include "p4misc.h"
- #include "w4.h"
- #include "d4all.h"
- #include "g4char.h"
- #include "u4error.h"
-
- #ifndef UNIX
- #include <io.h>
- #include <dos.h>
- #endif
-
- #include <string.h>
- #include <stdlib.h>
-
- #ifdef VARARGS
- #include <varargs.h>
- #else
- #include <stdarg.h>
- #endif
-
- #define MAX_WINDOW_WIDTH 120
-
- GET *v4get = (GET *) 0 ;
- MENU *v4menu = (MENU *) 0 ;
- CB_WINDOW *v4window = (CB_WINDOW *) 0 ;
- CB_WINDOW *v4window_ptr = (CB_WINDOW *) 0 ;
- char v4default_date[] = "MMM/DD/YY" ;
-
- int v4screen_width = 0 ; /* Width in display characters */
- int v4screen_width2 ; /* Width in storage bytes */
- int v4screen_height = 0 ;
- int v4display_bytes ; /* Width in storage bytes */
- #ifdef UNIX
- int v4up_key = CTRL_Q ; /* The key to move up a single menu */
- #else
- int v4up_key = ESC ; /* The key to move up a single menu */
- #endif
- int v4exit_key = CTRL_C ; /* A key to exit; 0 - None; -1 - All */
- int v4return_start= 0 ; /* A range of characters to return */
- int v4return_end = 0 ;
-
- #ifdef UNIX
- int v4refresh_on = 1 ;
- int v4cursor_hide = 0 ;
- int v4cursor_row ;
- int v4cursor_col ;
- #else
- static int cga = 0 ;
- #endif
-
- #ifndef UNIX
- #ifndef OS2
- /* Points to Screen Memory */
- static union memory_ptr_st
- {
- char far *far_ptr ;
- struct ptr_st { int off ; short seg ; } p ;
- } memory_ptr ;
-
- #ifdef CPP
- extern "C" void far W4READ_ASM( char far *, char far *, int ) ;
- extern "C" void far W4WRITE_ASM( char far *, char far *, int ) ;
- extern "C" void far W4WRITE_ATT_ASM( char far *, char far *, int, int ) ;
- #else
- #ifdef MSC
- void far _cdecl W4READ_ASM( char far *, char far *, int ) ;
- void far _cdecl W4WRITE_ASM( char far *, char far *, int ) ;
- void far _cdecl W4WRITE_ATT_ASM( char far *, char far *, int, int ) ;
- #else
- void far W4READ_ASM( char far *, char far *, int ) ;
- void far W4WRITE_ASM( char far *, char far *, int ) ;
- void far W4WRITE_ATT_ASM( char far *, char far *, int, int ) ;
- #endif
- #endif
- #endif
- #endif
-
- /* The window chain is in order of activation for activated windows ! */
- int v4last_window = -1 ; /* The Last Window */
- int v4first_window= -1 ; /* The First Window */
- int v4cur_window = -1 ; /* The Selected Window */
-
- int v4default_window= -1;
-
-
- #ifdef OS2
- typedef struct cursor_data_st
- {
- int start_line ;
- int end_line ;
- int cursor_width ;
- unsigned int cursor_attr ;
- } CURSOR_DATA ;
-
- typedef struct vio_data_st
- {
- int stru_len ;
- char mode_info ;
- char num_colors ;
- int width ;
- int height ;
- int no_pix_cols ;
- int no_pix_rows ;
- char res1[40] ;
- } VIO_DATA ;
-
- extern far pascal VIOWRTCHARSTRATT(char far *, int, int, int, char far *, int) ;
- extern far pascal VIOGETMODE( VIO_DATA far *, int ) ;
- extern far pascal VIOGETCURTYPE( CURSOR_DATA far *, int ) ;
- extern far pascal VIOSETCURPOS( int, int, int ) ;
- extern far pascal VIOSETCURTYPE( CURSOR_DATA far *, int ) ;
- extern far pascal VIOSCROLLDN( int,int,int,int,int, char far *,int ) ;
- extern far pascal VIOSCROLLUP( int,int,int,int,int, char far *,int ) ;
- extern far pascal VIOWRTCELLSTR( char far *, int, int, int, int ) ;
- extern far pascal VIOREADCELLSTR( char far *, int far *, int, int, int ) ;
- #endif
-
- #ifdef UNIX
- void w4refresh_off()
- {
- v4refresh_on = 0 ;
- }
-
- void w4refresh_on()
- {
- v4refresh_on = 1 ;
- }
-
- void w4refresh( int w_ref )
- {
- if ( w_ref >= 0 )
- wnoutrefresh( v4window[w_ref].win ) ;
-
- if ( v4refresh_on )
- {
- if ( v4cursor_hide )
- move( v4screen_height-1, v4screen_width-1 ) ;
- else
- move( v4cursor_row, v4cursor_col ) ;
-
- wnoutrefresh( stdscr ) ;
- doupdate() ;
- }
- }
- #endif
-
- int w4init( int num_window, int num_get, int num_menu_item )
- {
- if ( v4window == (CB_WINDOW *) 0 )
- {
- #ifdef UNIX
- initscr() ;
- raw() ;
- noecho() ;
- keypad( stdscr, 1 ) ;
- refresh() ;
- #endif
-
- if ( num_window <= 0 ) num_window = 1 ;
-
- if ( h4create( (char **) &v4window, num_window, sizeof(CB_WINDOW), 5) < 0 ) return -1 ;
- v4default_window = w4define( 0,0, 24,79 ) ;
- }
-
- if ( num_get > 0 && v4get == (GET *) 0)
- if( h4create( (char **) &v4get, num_get, (int) sizeof(GET), 10) < 0 ) return -1 ;
-
- if ( num_menu_item > 0 && v4menu == (MENU *) 0)
- if( h4create( (char **) &v4menu, num_menu_item, (int) sizeof(MENU), 15) < 0 ) return -1 ;
-
- return 0 ;
- }
-
- w4define( int start_row, int start_col, int end_row, int end_col )
- {
- int ref ;
-
- #ifdef OS2
- VIO_DATA vio_data ;
- #else
- #ifndef UNIX
- union REGS regs ;
- #endif
- #endif
-
- if ( w4init(10,0,0) < 0 ) return -1 ;
-
- if ( (ref = h4get((char **) &v4window, -1)) < 0 ) return -1 ;
- v4first_window = h4add( (char **) &v4window, v4first_window, ref, 1 ) ;
-
- if ( v4last_window < 0 ) v4last_window = v4first_window ;
- w4select( v4first_window ) ;
-
- v4window_ptr->first_get = -1 ;
- v4window_ptr->last_get = -1 ;
- v4window_ptr->first_menu= -1 ;
- v4window_ptr->last_menu = -1 ;
- v4window_ptr->start_item= -1 ;
- v4window_ptr->hand = -1 ;
- v4window_ptr->get_attribute = B_WHITE ;
- v4window_ptr->menu_attribute = F_WHITE ;
- v4window_ptr->menu_att_active = B_WHITE ;
- v4window_ptr->attribute = F_WHITE ;
- v4window_ptr->release = -1 ;
- v4window_ptr->key_read = 1 ;
- v4window_ptr->ignore_case= 1 ;
- v4window_ptr->up_key = v4up_key ;
- v4window_ptr->exit_key = v4exit_key ;
- v4window_ptr->return_start= v4return_start ;
- v4window_ptr->return_end = v4return_end ;
-
- #ifdef OS2
- memset( (char *) &vio_data, 0, sizeof(vio_data) ) ;
- vio_data.stru_len = 0xE ;
-
- VIOGETMODE( (VIO_DATA far *) &vio_data, 0 ) ;
- if ( end_row < start_row )
- end_row = vio_data.height -1 ;
- if ( end_col < start_col )
- end_col = vio_data.width -1 ;
-
- v4screen_width = vio_data.width ;
- v4screen_width2= v4screen_width<<1 ;
- v4screen_height= vio_data.height ;
-
- cga = (int) (vio_data.mode_info & 1) ;
- #else
-
- #ifdef UNIX
- v4screen_width = COLS ;
- v4screen_width2 = v4screen_width<<1 ;
- v4screen_height = LINES ;
- #else
- regs.h.ah = 0xF ;
- #ifdef IS_386
- int386( 0x10, ®s, ®s ) ;
- #else
- int86( 0x10, ®s, ®s ) ;
- #endif
-
- if ( end_row < start_row )
- end_row = 24 ;
- if ( end_col < start_col )
- end_col = regs.h.ah -1 ;
- v4screen_width = regs.h.ah ;
- v4screen_width2 = v4screen_width << 1 ;
- v4screen_height = 25 ;
-
- memory_ptr.p.off = 0 ;
- #ifdef IS_386
- memory_ptr.p.seg = 0x1C ;
- #else
- if ( regs.h.al == 0x7 )
- {
- cga = 0 ; /* Monochrome */
- memory_ptr.p.seg = 0xB000 ;
- }
- else
- {
- if ( regs.h.al == 0 || regs.h.al == 2 )
- cga = 1 ; /* Color Graphics Board */
- memory_ptr.p.seg = 0xB800 ;
- }
- #endif
- #endif
- #endif
-
- v4window_ptr->start_row = start_row ;
- v4window_ptr->start_col = start_col ;
- v4window_ptr->height = end_row - start_row + 1 ;
- v4window_ptr->width = end_col - start_col + 1 ;
- #ifdef UNIX
- if ( v4window_ptr->width > MAX_WINDOW_WIDTH )
- v4window_ptr->width = MAX_WINDOW_WIDTH ;
-
- if ( start_row < 0 ) start_row = 0 ;
- if ( start_col < 0 ) start_col = 0 ;
- v4window_ptr->win = newwin( v4window_ptr->height, v4window_ptr->width,
- start_row, start_col ) ;
- if ( v4window_ptr->win == (WINDOW *) 0 )
- {
- u4error( E_MEMORY, (char *) 0 ) ;
- return -1 ;
- }
- #endif
- v4window_ptr->display_bytes = v4window_ptr->height*v4window_ptr->width*2 ;
-
- v4display_bytes = v4screen_width2 * v4screen_height ;
-
- return v4cur_window ;
- }
-
- void w4enlarge()
- {
- if ( v4window_ptr->border_chars != (char *) 0 )
- {
- #ifdef UNIX
- v4window_ptr->border_offset = 0 ;
- #endif
- /* Temporarily Enlarge the Window */
- v4window_ptr->start_row-- ;
- v4window_ptr->start_col-- ;
- v4window_ptr->height += 2 ;
- v4window_ptr->width += 2 ;
- v4window_ptr->display_bytes= v4window_ptr->height*v4window_ptr->width*2;
- }
- }
-
- void w4shrink()
- {
- if ( v4window_ptr->border_chars != (char *) 0 )
- {
- #ifdef UNIX
- v4window_ptr->border_offset = 1 ;
- #endif
- /* Temporarily Enlarge the Window */
- v4window_ptr->start_row++ ;
- v4window_ptr->start_col++ ;
- v4window_ptr->height -= 2 ;
- v4window_ptr->width -= 2 ;
- v4window_ptr->display_bytes= v4window_ptr->height*v4window_ptr->width*2;
- }
- }
-
-
- void w4( int row, int column, char *buffer )
- {
- w4num( row, column, buffer, (int) strlen(buffer) ) ;
- }
-
-
- long w4attribute( long attribute )
- {
- if ( attribute >= 0L )
- {
- v4window_ptr->attribute = attribute ;
- #ifdef UNIX
- wattrset( v4window_ptr->win, attribute ) ;
- #endif
- }
- return( v4window_ptr->attribute ) ;
- }
-
-
- void w4centre( int row, char *buffer )
- {
- int len ;
-
- len = (int) strlen(buffer) ;
- w4num( row, (v4window_ptr->width-len)/2, buffer, len ) ;
- }
-
- #ifndef UNIX
- static void w4do_scroll( int, int, int, int, int, long ) ;
-
- static void w4do_scroll( int start_row, int start_col,
- int end_row, int end_col, int n, long attr )
- {
- int height ;
-
- if ( n == 0 ) return ;
- height = end_row - start_row + 1 ;
-
- #ifdef OS2
- {
- unsigned char cell[2] ;
-
- cell[0] = ' ' ;
- cell[1] = (unsigned char) attr ;
-
- if ( n < 0 )
- {
- if ( -n >= height ) n = 1 ;
- VIOSCROLLDN(start_row,start_col,end_row,end_col,-n,(char far *)cell,0);
- }
- else
- {
- if ( n >= height ) n = -1 ;
- VIOSCROLLUP(start_row,start_col,end_row,end_col,n,(char far *)cell,0);
- }
- }
- #else
- {
- union REGS regs ;
-
- if ( n < 0 )
- {
- if ( -n >= height ) n = 0 ;
- regs.h.al = (unsigned char) -n ;
- regs.h.ah = 7 ;
- }
- else
- {
- if ( n >= height ) n = 0 ;
- regs.h.al = (unsigned char) n ;
- regs.h.ah = 6 ;
- }
-
- regs.h.bh = (unsigned char) attr ;
- regs.h.ch = (unsigned char) start_row ;
- regs.h.cl = (unsigned char) start_col ;
- regs.h.dh = (unsigned char) end_row ;
- regs.h.dl = (unsigned char) end_col ;
-
- #ifdef IS_386
- int386( 0x10, ®s, ®s ) ;
- #else
- int86( 0x10, ®s, ®s ) ;
- #endif
- }
- #endif
- }
- #endif
-
- void w4scroll( int n )
- {
- #ifdef UNIX
- scrollok( v4window_ptr->win, 1 ) ;
- if ( n <= 0 ) return ;
- while ( --n >= 0 ) scroll( v4window_ptr->win ) ;
- w4refresh( v4cur_window ) ;
- scrollok( v4window_ptr->win, 0 ) ;
- #else
- w4do_scroll( v4window_ptr->start_row, v4window_ptr->start_col,
- v4window_ptr->height+ v4window_ptr->start_row -1,
- v4window_ptr->width + v4window_ptr->start_col -1,
- n, v4window_ptr->attribute ) ;
- #endif
- }
-
-
- void w4clear( int start_line )
- {
- #ifdef UNIX
- if ( v4default_window < 0 )
- u4error( E_INTERNAL, "w4clear", (char *) 0 ) ;
- if ( start_line < 0 )
- {
- clear() ;
- touchwin( stdscr ) ;
- w4refresh(-1) ;
- }
- else
- {
- touchwin( v4window_ptr->win ) ;
- if ( start_line == 0 && v4window_ptr->border_chars == (char *) 0 )
- {
- wclear( v4window_ptr->win ) ;
- w4refresh( v4cur_window ) ;
-
- v4window_ptr->row = start_line ;
- v4window_ptr->col = 0 ;
- }
- else
- w4repeat( start_line, 0, ' ',
- v4window_ptr->width * (v4window_ptr->height- start_line) ) ;
- }
- #else
- if ( start_line < 0 ) /* Clear Entire Screen */
- {
- w4init(10,0,0) ;
- w4do_scroll( 0,0, v4screen_height-1, v4screen_width-1,
- v4screen_height, F_WHITE ) ;
- }
- else
- {
- if ( v4cur_window >= 0 )
- {
- w4do_scroll( v4window_ptr->start_row+start_line,
- v4window_ptr->start_col,
- v4window_ptr->height+ v4window_ptr->start_row -1,
- v4window_ptr->width + v4window_ptr->start_col -1,
- v4window_ptr->height, v4window_ptr->attribute ) ;
- v4window_ptr->row = (start_line < 0) ? 0 : start_line ;
- v4window_ptr->col = 0 ;
- }
- }
- #endif
- }
-
-
- void w4close( int w_ref )
- {
- CB_WINDOW *w_ptr ;
- int new_ref ;
-
- if ( w_ref < 0 )
- {
- if ( v4cur_window < 0 ) return ;
- w_ref = v4cur_window ;
- }
- w_ptr = v4window + w_ref ;
-
- #ifndef UNIX
- if ( w_ptr->data != (char *) 0 )
- h4free_memory( w_ptr->data ) ;
-
- if ( w_ptr->old_screen != (char *) 0 )
- h4free_memory( w_ptr->old_screen ) ;
- #endif
-
- h4free_chain( (char **) &v4menu, w_ptr->last_menu ) ;
- h4free_chain( (char **) &v4get, w_ptr->last_get ) ;
-
- new_ref = h4free((char **) &v4window, w_ref) ;
- if ( w_ref == v4first_window ) v4first_window = new_ref ;
- if ( w_ref == v4last_window ) v4last_window = new_ref ;
- if ( w_ref == v4cur_window )
- {
- v4cur_window = v4last_window ;
- v4window_ptr = v4window + new_ref ;
- }
-
- #ifdef UNIX
- delwin( w_ptr->win ) ;
- #endif
- }
-
-
- int w4col()
- {
- return( v4window_ptr->col ) ;
- }
-
- #ifdef OS2
- int v4cursor_hide = 1 ;
- #endif
-
- void w4cursor( int row, int col )
- {
- #ifdef OS2
- CURSOR_DATA cursor_data ;
-
- if ( v4cursor_hide || row < 0 || col < 0 )
- {
- VIOGETCURTYPE( (CURSOR_DATA far *) &cursor_data, 0 ) ;
- if ( row < 0 || col < 0 )
- {
- v4cursor_hide = 1 ;
- cursor_data.cursor_attr = 0xFFFF ;
- }
- else
- {
- v4cursor_hide = 0 ;
- cursor_data.cursor_attr = 0 ; /* Visible */
- }
- VIOSETCURTYPE( (CURSOR_DATA far *) &cursor_data, 0 ) ;
- }
-
- if ( row >= 0 && col >= 0 )
- VIOSETCURPOS( v4window_ptr->start_row+row, v4window_ptr->start_col+col, 0 ) ;
-
- #else
- #ifdef UNIX
- v4cursor_row = v4window_ptr->start_row+row ;
- v4cursor_col = v4window_ptr->start_col+col ;
-
- if ( row < 0 || col < 0 )
- v4cursor_hide = 1 ;
- else
- v4cursor_hide = 0 ;
-
- w4refresh(-1) ;
- #else
- union REGS regs ;
-
- if ( row < 0 || col < 0 ) row = -1000 ;
-
- regs.h.ah = 2 ;
- regs.h.bh = 0 ;
- regs.h.dh = (unsigned char) (v4window_ptr->start_row+ row) ;
- regs.h.dl = (unsigned char) (v4window_ptr->start_col+ col) ;
-
- #ifdef IS_386
- int386( 0x10, ®s, ®s ) ;
- #else
- int86( 0x10, ®s, ®s ) ;
- #endif
- #endif
- #endif
- }
-
-
- void w4cursor_size( int start_line, int end_line )
- {
- #ifdef OS2
- CURSOR_DATA cursor_data ;
-
- VIOGETCURTYPE( (CURSOR_DATA far *) &cursor_data, 0 ) ;
-
- if ( !cga )
- {
- /* Adjust Upward for Monochrome Screens */
- start_line = (start_line * 13) / 7 ;
- end_line = (end_line * 13) / 7 ;
- }
-
- cursor_data.start_line = start_line ;
- cursor_data.end_line = end_line ;
-
- VIOSETCURTYPE( (CURSOR_DATA far *) &cursor_data, 0 ) ;
-
- #else
- #ifndef UNIX
- union REGS regs ;
-
- if ( !cga )
- {
- /* Adjust Upward for Monochrome Screens */
- start_line = (start_line * 12) / 7 ;
- end_line = (end_line * 12) / 7 ;
- }
- regs.h.ah = 1 ;
- regs.h.ch = (unsigned char) start_line ;
- regs.h.cl = (unsigned char) end_line ;
-
- #ifdef IS_386
- int386( 0x10, ®s, ®s ) ;
- #else
- int86( 0x10, ®s, ®s ) ;
- #endif
- #endif
- #endif
- }
-
-
- void w4deactivate( int w_ref )
- {
- int old_cur_window ;
-
- #ifdef UNIX
- int save_refresh_on ;
- #else
- int is_last ;
- #endif
-
- old_cur_window = v4cur_window ;
- if ( w_ref < 0 )
- {
- if ( v4cur_window < 0 ) return ;
- w_ref = v4cur_window ;
- }
-
- if ( ! v4window[w_ref].active ) return ;
-
- #ifndef UNIX
- if ( w_ref == v4last_window )
- is_last = 1 ;
- else
- is_last = 0 ;
-
- w4select(v4last_window) ;
- if ( v4window_ptr->active && v4window_ptr->data != (char *) 0)
- {
- /* Save the contents of the last activated window */
- w4enlarge() ;
- w4read_window( v4last_window, v4window_ptr->data ) ;
- w4shrink() ;
- }
- #endif
-
- w4select( w_ref ) ;
- v4window_ptr->active = 0 ;
-
- if ( w_ref != v4first_window )
- {
- if ( w_ref == v4last_window )
- v4last_window = v4window[w_ref].prev ;
- h4remove( (char **) &v4window, w_ref ) ;
- h4add( (char **) &v4window, v4first_window, w_ref, 1 ) ;
- v4first_window = w_ref ;
- }
-
- #ifdef UNIX
- save_refresh_on = v4refresh_on ;
- v4refresh_on = 0 ;
- #else
- if ( is_last && v4window_ptr->old_screen != (char *) 0 )
- {
- /* Popup Window which was the last activated */
- w4enlarge() ;
- w4write_window( v4cur_window, v4window_ptr->old_screen ) ;
- w4shrink() ;
-
- if ( v4window[v4last_window].active )
- w4select( v4last_window ) ;
- else
- w4select( old_cur_window ) ;
-
- return ;
- }
- #endif
-
- w4enlarge() ;
- w4clear( 0 ) ;
- w4shrink() ;
-
- for( w4select(v4first_window);; w4select(v4window_ptr->next) )
- {
- #ifdef UNIX
- if ( v4window_ptr->active )
- {
- touchwin( v4window_ptr->win ) ;
- wnoutrefresh( v4window_ptr->win ) ;
- }
- #else
- if ( v4window_ptr->active && v4window_ptr->data != (char *) 0)
- {
- w4enlarge() ;
- w4write_window( v4cur_window, v4window_ptr->data ) ;
- w4shrink() ;
- }
- #endif
- if ( v4window_ptr->next < 0 ) break ;
- }
-
- if ( v4window[v4last_window].active )
- w4select( v4last_window ) ;
- else
- w4select( old_cur_window ) ;
-
- #ifdef UNIX
- v4refresh_on = save_refresh_on ;
- w4refresh( -1 ) ;
- #endif
- }
-
-
- void w4double( int row, int column, double double_value, int len, int dec )
- {
- char *ptr ;
-
- ptr = c4dtoa( double_value, len, dec ) ;
- w4num( row, column, ptr, len ) ;
- }
-
- #ifdef VARARGS
- w4display( title, va_alist )
- char *title ;
- va_dcl
- #else
- w4display( char * title, ... )
- #endif
- {
- char *ptr ;
- int n, max_width, len, w_ref, start_row, start_col, rc, save_window ;
- va_list arg_marker ;
-
- if ( title == (char *) 0 ) return -1 ;
-
- save_window = w4select( -1 ) ;
-
- max_width = (int) strlen(title ) ;
- n = 0 ;
-
- #ifdef VARARGS
- va_start( arg_marker ) ;
- #else
- va_start( arg_marker, title ) ;
- #endif
-
- for (ptr = title; ptr != (char *) 0; ptr = va_arg( arg_marker, char *) )
- {
- n++ ;
- len = (int) strlen(ptr) ;
- max_width = (len > max_width) ? len : max_width ;
- }
-
- if ( n == 1 ) return( w4display( "", title, (char *) 0) ) ;
-
- start_row = (v4screen_height-n-3)/2 ;
- start_col = (v4screen_width-max_width-5)/2 ;
-
- w_ref = w4define( start_row, start_col, start_row+n+2,start_col+max_width+5);
-
- w4title( 0,-1, title, F_WHITE | F_INTENSE ) ;
- w4border( DOUBLE, F_WHITE ) ;
- w4popup() ;
-
- w4cursor( -1,-1 ) ;
-
- w4activate( w_ref ) ;
-
- n = 0 ;
-
- #ifdef VARARGS
- va_start( arg_marker ) ;
- #else
- va_start( arg_marker, title ) ;
- #endif
- for ( ptr = va_arg( arg_marker, char *); ptr != (char *) 0;
- ptr = va_arg( arg_marker, char *) )
- {
- n++ ;
- w4( n,2, ptr ) ;
- }
-
- rc = g4char() ;
-
- w4deactivate( w_ref ) ;
- w4close( w_ref ) ;
-
- w4select( save_window ) ;
-
- return( rc ) ;
- }
-
-
- void w4eject()
- {
- write( v4window_ptr->hand, "\f", 1) ;
- v4window_ptr->row = 0 ;
- v4window_ptr->col = 0 ;
- }
-
-
- void w4exit(int rc)
- {
- w4select( v4default_window ) ;
- w4cursor(23,0) ;
-
- #ifdef UNIX
- endwin() ;
- #endif
-
- exit(rc) ;
- }
-
-
- w4handle( int hand )
- {
- int last_hand ;
-
- last_hand = v4window_ptr->hand ;
- if ( hand >= -1 )
- v4window_ptr->hand = hand ;
-
- return( last_hand ) ;
- }
-
-
- void w4int( int row, int column, int int_value, int len )
- {
- char buffer[18] ;
-
- c4ltoa( (long) int_value, buffer, len ) ;
- w4num( row, column, buffer, len ) ;
- }
-
-
- #ifndef UNIX
- void w4read( int row, int col, char *buffer, int len )
- {
- #ifdef OS2
- VIOREADCELLSTR( (char far *) buffer, (int far *) &len, row, col, 0 ) ;
- #else
- char far *ptr ;
- int offset ;
-
- offset = row*v4screen_width2 + (col<<1) ;
- if ( offset +len > v4display_bytes )
- {
- len = v4display_bytes - offset ;
- if ( len <= 0 ) return ;
- }
-
- ptr = memory_ptr.far_ptr + offset ;
-
- #ifndef IS_386
- if ( cga )
- W4READ_ASM( ptr, (char far *) buffer, len ) ;
- else
- #endif
- while ( --len >= 0 )
- *buffer++ = *ptr++ ;
- #endif
-
- return ;
- }
- #endif
-
- #ifndef UNIX
- void w4read_window( int window_ref, char *ptr )
- {
- int i, data_width ;
- CB_WINDOW *window_ptr ;
-
- if ( window_ref < 0 || ptr == (char *) 0 ) return ;
-
- window_ptr = v4window+ window_ref ;
- data_width = window_ptr->width*2 ;
-
- for ( i= 0; i < window_ptr->height; i++ )
- {
- w4read( window_ptr->start_row+i, window_ptr->start_col, ptr, data_width ) ;
- ptr += data_width ;
- }
- }
- #endif
-
- #ifndef UNIX
- void w4write( int row, int col, char *buffer, int len )
- {
- #ifdef OS2
- VIOWRTCELLSTR( (char far *) buffer, len, row, col, 0 ) ;
- #else
- char far *ptr ;
- int offset ;
-
- offset = row*v4screen_width2 + (col<<1) ;
- if ( offset +len > v4display_bytes )
- {
- len = v4display_bytes - offset ;
- if ( len <= 0 ) return ;
- }
-
- ptr = memory_ptr.far_ptr + offset ;
-
- #ifndef IS_386
- if ( cga )
- W4WRITE_ASM( ptr, (char far *) buffer, len ) ;
- else
- #endif
- while ( --len >= 0 )
- *ptr++ = *buffer++ ;
- #endif
- }
- #endif
-
- #ifndef UNIX
- void w4write_att( int row, int col, char *buffer, int len, long attribute_char )
- {
- #ifdef OS2
- VIOWRTCHARSTRATT( (char far *) buffer, len, row, col, (char far *) &attribute_char, 0 ) ;
- #else
-
- char far *ptr ;
- int offset ;
-
- offset = row*v4screen_width2 + (col<<1) ;
- if ( offset +(len<<1) > v4display_bytes )
- {
- len = (v4display_bytes - offset)/2 ;
- if ( len <= 0 ) return ;
- }
-
- ptr = memory_ptr.far_ptr + offset ;
-
- #ifndef IS_386
- if ( cga )
- W4WRITE_ATT_ASM( ptr, (char far *) buffer, len, (int) attribute_char ) ;
- else
- #endif
- while ( --len >= 0 )
- {
- *ptr++ = *buffer++ ;
- *ptr++ = (char) attribute_char ;
- }
-
- #endif
- }
- #endif
-
- #ifndef UNIX
- void w4write_window( int window_ref, char *ptr )
- {
- int i, data_width ;
- CB_WINDOW *window_ptr ;
-
- if ( window_ref < 0 || ptr == (char *) 0 ) return ;
-
- window_ptr = v4window+ window_ref ;
- data_width = window_ptr->width*2 ;
-
- for ( i= 0; i < window_ptr->height; i++ )
- {
- w4write( window_ptr->start_row+i,window_ptr->start_col,
- ptr, data_width ) ;
-
- ptr += data_width ;
- }
- }
- #endif
-
- void w4long( int row, int column, long long_value, int len )
- {
- char buffer[40] ;
-
- c4ltoa( (long) long_value, buffer, len ) ;
- w4num( row, column, buffer, len ) ;
- }
-
-
- void w4num( int row, int col, char *buffer, int len )
- {
- int cur_len, buffer_pos ;
- #ifdef UNIX
- unsigned char out_buffer[MAX_WINDOW_WIDTH+1] ;
-
- if ( len > MAX_WINDOW_WIDTH ) len = MAX_WINDOW_WIDTH ;
- #endif
-
- if ( row < 0 ) row = 0 ;
- if ( col < 0 ) col = 0 ;
-
- if ( col >= v4window_ptr->width )
- {
- row += col/v4window_ptr->width ;
- col %= v4window_ptr->width ;
- }
-
- buffer_pos = 0 ;
-
- if ( len == 0 )
- {
- /* In case the handle is >= 0 */
- w4position( row,col ) ;
- return ;
- }
-
- while ( len > 0 )
- {
- if ( col+len > v4window_ptr->width )
- cur_len = v4window_ptr->width - col ;
- else
- cur_len = len ;
-
- if ( v4window_ptr->hand >= 0 )
- {
- w4position( row, col ) ;
- write( v4window_ptr->hand, buffer+buffer_pos, cur_len ) ;
- }
- else
- {
- if ( row >= v4window_ptr->height )
- row %= v4window_ptr->height ;
-
- #ifdef UNIX
- {
- memcpy( out_buffer, buffer+buffer_pos, (size_t) cur_len ) ;
- out_buffer[cur_len] = '\000' ;
- mvwaddstr( v4window_ptr->win, row+ v4window_ptr->border_offset,
- col+ v4window_ptr->border_offset, out_buffer ) ;
- }
- #else
- w4write_att( v4window_ptr->start_row+row, v4window_ptr->start_col+col,
- buffer+buffer_pos, cur_len, v4window_ptr->attribute ) ;
- #endif
- }
- buffer_pos += cur_len ;
- len -= cur_len ;
- col += cur_len ;
- if ( col >= v4window_ptr->width )
- {
- row++ ;
- if ( row >= v4window_ptr->height && v4window_ptr->hand < 0 )
- row %= v4window_ptr->height ;
- col = 0 ;
- }
- }
- v4window_ptr->row = row ;
- v4window_ptr->col = col ;
-
- #ifdef UNIX
- w4refresh( v4cur_window ) ;
- #endif
- }
-
-
- void w4num_att( int row, int col, char *buffer, int len, long attribute )
- {
- long old_attribute ;
-
- old_attribute = v4window_ptr->attribute ;
- v4window_ptr->attribute = attribute ;
- #ifdef UNIX
- wattrset( v4window_ptr->win, attribute ) ;
- #endif
-
- w4num( row, col, buffer, len ) ;
-
- v4window_ptr->attribute = old_attribute ;
- #ifdef UNIX
- wattrset( v4window_ptr->win, old_attribute ) ;
- #endif
- }
-
-
- void w4out( char *buffer )
- {
- w4num( v4window_ptr->row, v4window_ptr->col, buffer, (int) strlen(buffer) ) ;
- }
-
- void w4position_set( int row, int col )
- {
- v4window_ptr->col = col ;
- v4window_ptr->row = row ;
- }
-
- void w4position( int row, int col )
- {
- if ( col >= v4window_ptr->width )
- {
- row += col/v4window_ptr->width ;
- col %= v4window_ptr->width ;
- }
-
- if ( v4window_ptr->hand < 0 )
- {
- if ( row >= v4window_ptr->height ) row %= v4window_ptr->height ;
- v4window_ptr->row = row ;
- v4window_ptr->col = col ;
- return ;
- }
-
- if ( row < v4window_ptr->row || row == v4window_ptr->row && col < v4window_ptr->col)
- w4eject() ;
-
- while ( v4window_ptr->row < row )
- {
- v4window_ptr->col = 0 ;
- v4window_ptr->row++ ;
- write( v4window_ptr->hand, "\r\n", 2 ) ;
- }
-
- while ( v4window_ptr->col < col )
- {
- char blanks[80] ;
-
- memset( blanks, (int) ' ', (size_t) sizeof(blanks) ) ;
- while ( col - v4window_ptr->col > sizeof(blanks) )
- {
- v4window_ptr->col += sizeof(blanks) ;
- write( v4window_ptr->hand, blanks, (unsigned int) sizeof(blanks) ) ;
- }
-
- write( v4window_ptr->hand, blanks, (unsigned int) (col - v4window_ptr->col) ) ;
- v4window_ptr->col = col ;
- }
- }
-
-
- void w4repeat( int row, int column, char chr, int num )
- {
- char buffer[MAX_WINDOW_WIDTH] ;
- #ifdef UNIX
- int old_refresh_on ;
-
- old_refresh_on = v4refresh_on ;
- v4refresh_on = 0 ;
- #endif
-
- if ( num < 0 ) return ;
-
- memset( buffer, (int) chr, (size_t) sizeof(buffer) ) ;
- w4num( row, column, buffer, 0 ) ; /* Position to (row,column) */
-
- for (;;)
- {
- if ( num < sizeof(buffer) )
- {
- w4num( v4window_ptr->row, v4window_ptr->col, buffer, num ) ;
- #ifdef UNIX
- v4refresh_on = old_refresh_on ;
- w4refresh( v4cur_window ) ;
- #endif
- return ;
- }
-
- w4num( v4window_ptr->row, v4window_ptr->col, buffer, sizeof(buffer) ) ;
- num -= sizeof(buffer) ;
- }
- }
-
-
- int w4row()
- {
- return( v4window_ptr->row ) ;
- }
-
-
- void w4activate( int window_ref )
- {
- int col ;
- long save_attribute ;
-
- if ( window_ref < 0 )
- window_ref = w4select( -1 ) ;
-
- w4select( window_ref ) ;
- if ( v4last_window == window_ref && v4window_ptr->active ||
- v4window_ptr->hand >= 0 ) return ;
-
- #ifndef UNIX
- if ( v4last_window >= 0 && v4window[v4last_window].active )
- {
- w4select( v4last_window ) ;
- w4enlarge() ;
- w4read_window( v4last_window, v4window[v4last_window].data ) ;
- w4shrink() ;
- w4select( window_ref ) ;
- }
- #endif
-
- w4enlarge() ;
- if ( v4window_ptr->start_row < 0 || v4window_ptr->start_col < 0 ||
- v4window_ptr->height < 0 || v4window_ptr->width < 0 )
- {
- if ( v4window_ptr->start_row < 0 ) v4window_ptr->start_row = 0 ;
- if ( v4window_ptr->start_col < 0 ) v4window_ptr->start_col = 0 ;
- if ( v4window_ptr->height < 0 )
- v4window_ptr->height = v4screen_height - v4window_ptr->start_row ;
- if ( v4window_ptr->width < 0 )
- v4window_ptr->width = v4screen_width - v4window_ptr->start_col ;
- #ifndef UNIX
- if ( v4window_ptr->data != (char *) 0 ) w4memory() ;
- if ( v4window_ptr->old_screen != (char *) 0 ) w4popup() ;
- #endif
- }
-
- #ifndef UNIX
- w4read_window( v4cur_window, v4window_ptr->old_screen ) ;
- #endif
-
- #ifdef UNIX
- if ( v4window_ptr->active )
- {
- touchwin( v4window_ptr->win ) ;
- w4refresh(v4cur_window) ;
- }
- #else
- if ( v4window_ptr->data != (char *) 0 && v4window_ptr->active )
- w4write_window( v4cur_window, v4window_ptr->data ) ;
- #endif
- else
- {
- #ifdef UNIX
- int old_refresh_on ;
-
- old_refresh_on = v4refresh_on ;
- v4refresh_on = 0 ;
- #endif
- /* Display the Border if one Exists */
- w4clear(0) ;
- if ( v4window_ptr->border_chars )
- {
- save_attribute = v4window_ptr->attribute ;
- v4window_ptr->attribute = v4window_ptr->border_attribute ;
- w4box( v4window_ptr->border_chars, 0,0,
- v4window_ptr->height-1, v4window_ptr->width-1 ) ;
- v4window_ptr->attribute = save_attribute ;
- }
-
- /* Add the Title */
- if ( v4window_ptr->title != (char *) 0 )
- {
- col = v4window_ptr->title_col ;
-
- if ( col < 0 )
- col = (v4window_ptr->width - (int) strlen(v4window_ptr->title)) / 2 ;
- else
- col = v4window_ptr->title_col ;
-
- w4num_att( v4window_ptr->title_row, col, v4window_ptr->title,
- (int) strlen(v4window_ptr->title), v4window_ptr->title_attribute ) ;
- }
- #ifdef UNIX
- v4refresh_on = old_refresh_on ;
- w4refresh( v4cur_window ) ;
- #endif
- }
-
- w4shrink() ;
-
- v4window_ptr->active = 1 ;
-
- /* Make the Current Window the Last Window */
- if ( v4cur_window == v4last_window ) return ;
- if ( v4first_window == v4cur_window )
- v4first_window = v4window[v4cur_window].next ;
-
- h4remove( (char **) &v4window, v4cur_window ) ;
- h4add( (char **) &v4window, v4last_window, v4cur_window, 0 ) ;
- v4last_window = v4cur_window ;
- }
-
-
- void w4border( char *box_chars, long attribute )
- {
- w4enlarge() ;
- v4window_ptr->border_chars = box_chars ;
- v4window_ptr->border_attribute = attribute ;
- w4shrink() ;
- }
-
-
- void w4box( char *box_chars, int start_row, int start_col, int end_row, int end_col )
- {
- int i ;
-
- #ifdef UNIX
- int old_refresh ;
-
- old_refresh = v4refresh_on ;
- v4refresh_on = 0 ;
- #endif
-
- w4repeat( start_row, start_col+1, box_chars[0], end_col-start_col-1 ) ;
- w4repeat( end_row, start_col+1, box_chars[1], end_col-start_col-1 ) ;
- for ( i= start_row+1; i< end_row; i++ )
- {
- w4num( i, start_col, box_chars+2, 1 ) ;
- w4num( i, end_col, box_chars+3, 1 ) ;
- }
- w4num( start_row, start_col, box_chars+4, 1 ) ;
- w4num( start_row, end_col, box_chars+5, 1 ) ;
- w4num( end_row, start_col, box_chars+6, 1 ) ;
- w4num( end_row, end_col, box_chars+7, 1 ) ;
-
- #ifdef UNIX
- v4refresh_on = old_refresh ;
- w4refresh( v4cur_window ) ;
- #endif
- }
-
-
- void w4memory()
- {
- #ifdef UNIX
- w4enlarge() ;
- if ( v4window_ptr->win == (WINDOW *) 0 )
- u4error( E_INTERNAL, "w4memory", (char *) 0 ) ;
-
- delwin( v4window_ptr->win ) ;
-
- if ( v4window->height > 0 && v4window_ptr->width > 0 &&
- v4window_ptr->start_row >= 0 && v4window_ptr->start_col >= 0 )
- v4window_ptr->win = newwin( v4window_ptr->height, v4window_ptr->width,
- v4window_ptr->start_row, v4window_ptr->start_col ) ;
- else
- v4window_ptr->win = newwin( 1,1,0,0 ) ;
-
- if ( v4window_ptr->win == (WINDOW *) 0 )
- u4error( E_MEMORY, (char *) 0 ) ;
-
- v4window_ptr->display_bytes= v4window_ptr->height * v4window_ptr->width*2;
- w4shrink() ;
- #else
- if ( v4window_ptr->data != (char *) 0 )
- {
- h4free_memory( v4window_ptr->data ) ;
- v4window_ptr->data = (char *) 0 ;
- }
- w4enlarge() ;
- v4window_ptr->display_bytes= v4window_ptr->height * v4window_ptr->width*2;
- if ( v4window_ptr->display_bytes > 0 )
- v4window_ptr->data = h4alloc( v4window_ptr->display_bytes ) ;
- w4shrink() ;
- #endif
- }
-
-
- void w4popup()
- {
- #ifdef UNIX
- w4memory() ;
- #else
- if (v4window_ptr->old_screen != (char *) 0)
- {
- h4free_memory( v4window_ptr->old_screen);
- v4window_ptr->old_screen = (char *) 0 ;
- }
- w4enlarge() ;
-
- /* v4window_ptr->display_bytes could have been changed by 'n4lotus', .. */
- v4window_ptr->display_bytes= v4window_ptr->height * v4window_ptr->width*2;
- if ( v4window_ptr->display_bytes > 0 )
- {
- v4window_ptr->old_screen = h4alloc( v4window_ptr->display_bytes ) ;
- }
- w4shrink() ;
- #endif
- }
-
-
- w4select( int window_ref )
- {
- int previous_ref ;
-
- previous_ref = v4cur_window ;
-
- if ( window_ref >= 0 )
- {
- v4cur_window = window_ref ;
- v4window_ptr = v4window+ window_ref ;
- }
- return previous_ref ;
- }
-
-
- void w4title( int row, int col, char *title, long attribute )
- {
- v4window_ptr->title_row = row ;
- v4window_ptr->title_col = col ;
- v4window_ptr->title = title ;
- v4window_ptr->title_attribute = attribute ;
- }
-
- int w4width( int new_width )
- {
- if ( new_width > 0 && new_width != v4window_ptr->width )
- {
- v4window_ptr->width = new_width ;
- #ifndef UNIX
- if ( v4window_ptr->old_screen != (char *) 0 ) w4popup() ;
- if ( v4window_ptr->data != (char *) 0 ) w4memory() ;
- #endif
- }
- return ( v4window_ptr->width ) ;
- }
-
- int w4height( int new_height )
- {
- if ( new_height > 0 && new_height != v4window_ptr->height )
- {
- v4window_ptr->height = new_height ;
- #ifndef UNIX
- if ( v4window_ptr->old_screen != (char *) 0 ) w4popup() ;
- if ( v4window_ptr->data != (char *) 0 ) w4memory() ;
- #endif
- }
- return ( v4window_ptr->height ) ;
- }
-
- /* This does not currently work.
- void w4silent( int r, int c, char *ptr )
- {
- int pos ;
-
- if ( v4window_ptr->data == (void *) 0 ) return ;
- pos = r*v4window_ptr->width + c ;
-
- for(;;)
- {
- if ( pos >= v4window_ptr->display_bytes ) break ;
- if ( *ptr == 0 ) break ;
- v4window_ptr->data[pos++] = *ptr++ ;
- v4window_ptr->data[pos++] = v4window_ptr->attribute ;
- }
- }
- */
-