home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c160 / 1.ddi / SOURCE / W4.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-11-19  |  35.6 KB  |  1,458 lines

  1.  
  2. /* w4.c    (c)Copyright Sequiter Software Inc., 1987-1990.  All rights reserved.
  3.  
  4.    Window Routines
  5. */
  6.  
  7. #include "p4misc.h"
  8. #include "w4.h"
  9. #include "d4all.h"
  10. #include "g4char.h"
  11. #include "u4error.h"
  12.  
  13. #ifndef UNIX
  14. #include <io.h>
  15. #include <dos.h>
  16. #endif
  17.  
  18. #include <string.h>
  19. #include <stdlib.h>
  20.  
  21. #ifdef VARARGS
  22.    #include <varargs.h>
  23. #else
  24.    #include <stdarg.h>
  25. #endif
  26.  
  27. #define   MAX_WINDOW_WIDTH  120
  28.  
  29. GET         *v4get        =  (GET *)  0 ;
  30. MENU        *v4menu       =  (MENU *) 0 ;
  31. CB_WINDOW   *v4window     =  (CB_WINDOW *) 0 ;
  32. CB_WINDOW   *v4window_ptr =  (CB_WINDOW *) 0 ;
  33. char         v4default_date[] =  "MMM/DD/YY" ;
  34.  
  35. int  v4screen_width  = 0 ;         /* Width in display characters */
  36. int  v4screen_width2 ;         /* Width in storage bytes */
  37. int  v4screen_height = 0 ;
  38. int  v4display_bytes ;         /* Width in storage bytes */
  39. #ifdef  UNIX
  40.    int  v4up_key =  CTRL_Q ;   /* The key to move up a single menu */
  41. #else
  42.    int  v4up_key =  ESC ;      /* The key to move up a single menu */
  43. #endif
  44. int  v4exit_key    =  CTRL_C ; /* A key to exit; 0 - None; -1 - All */
  45. int  v4return_start=  0 ;      /* A range of characters to return */
  46. int  v4return_end  =  0 ;
  47.  
  48. #ifdef UNIX
  49.    int  v4refresh_on  =  1 ;
  50.    int  v4cursor_hide =  0 ;
  51.    int  v4cursor_row ;
  52.    int  v4cursor_col ;
  53. #else
  54.    static int  cga =  0 ;
  55. #endif
  56.  
  57. #ifndef UNIX
  58. #ifndef OS2
  59.    /* Points to Screen Memory */
  60.    static   union  memory_ptr_st
  61.    {
  62.       char far  *far_ptr ;
  63.       struct ptr_st { int off ; short seg ; } p ;
  64.    }  memory_ptr ;
  65.  
  66.    #ifdef CPP
  67.       extern "C" void far W4READ_ASM( char far *, char far *, int ) ;
  68.       extern "C" void far W4WRITE_ASM( char far *, char far *, int ) ;
  69.       extern "C" void far W4WRITE_ATT_ASM( char far *, char far *, int, int ) ;
  70.    #else
  71.       #ifdef MSC
  72.          void far _cdecl W4READ_ASM( char far *, char far *, int ) ;
  73.          void far _cdecl W4WRITE_ASM( char far *, char far *, int ) ;
  74.          void far _cdecl W4WRITE_ATT_ASM( char far *, char far *, int, int ) ;
  75.       #else
  76.          void far W4READ_ASM( char far *, char far *, int ) ;
  77.          void far W4WRITE_ASM( char far *, char far *, int ) ;
  78.          void far W4WRITE_ATT_ASM( char far *, char far *, int, int ) ;
  79.       #endif
  80.    #endif
  81. #endif
  82. #endif
  83.  
  84. /* The window chain is in order of activation for activated windows ! */
  85. int   v4last_window = -1 ;  /* The Last Window */
  86. int   v4first_window= -1 ;  /* The First Window */
  87. int   v4cur_window  = -1 ;  /* The Selected Window */
  88.  
  89. int   v4default_window= -1;
  90.  
  91.  
  92. #ifdef OS2
  93.    typedef struct  cursor_data_st
  94.    {
  95.       int  start_line ;
  96.       int  end_line ;
  97.       int  cursor_width ;
  98.       unsigned int  cursor_attr ;
  99.    }  CURSOR_DATA ;
  100.  
  101.    typedef  struct  vio_data_st
  102.    {
  103.       int   stru_len ;
  104.       char  mode_info ;
  105.       char  num_colors ;
  106.       int   width ;
  107.       int   height ;
  108.       int   no_pix_cols ;
  109.       int   no_pix_rows ;
  110.       char  res1[40] ;
  111.    }  VIO_DATA ;
  112.  
  113.    extern far pascal VIOWRTCHARSTRATT(char far *, int, int, int, char far *, int) ;
  114.    extern far pascal VIOGETMODE( VIO_DATA far *, int ) ;
  115.    extern far pascal VIOGETCURTYPE( CURSOR_DATA far *, int ) ;
  116.    extern far pascal VIOSETCURPOS( int, int, int ) ;
  117.    extern far pascal VIOSETCURTYPE( CURSOR_DATA far *, int ) ;
  118.    extern far pascal VIOSCROLLDN( int,int,int,int,int, char far *,int ) ;
  119.    extern far pascal VIOSCROLLUP( int,int,int,int,int, char far *,int ) ;
  120.    extern far pascal VIOWRTCELLSTR( char far *, int, int, int, int ) ;
  121.    extern far pascal VIOREADCELLSTR( char far *, int far *, int, int, int ) ;
  122. #endif
  123.  
  124. #ifdef UNIX
  125.    void  w4refresh_off()
  126.    {
  127.       v4refresh_on =  0 ;
  128.    }
  129.  
  130.    void  w4refresh_on()
  131.    {
  132.       v4refresh_on =  1 ;
  133.    }
  134.  
  135.    void  w4refresh( int w_ref )
  136.    {
  137.       if ( w_ref >= 0 )
  138.      wnoutrefresh( v4window[w_ref].win ) ;
  139.  
  140.       if ( v4refresh_on )
  141.       {
  142.      if ( v4cursor_hide )
  143.         move( v4screen_height-1, v4screen_width-1 ) ;
  144.      else
  145.         move( v4cursor_row, v4cursor_col ) ;
  146.  
  147.      wnoutrefresh( stdscr ) ;
  148.      doupdate() ;
  149.       }
  150.    }
  151. #endif
  152.  
  153. int  w4init( int num_window, int num_get, int num_menu_item )  
  154. {
  155.    if ( v4window ==  (CB_WINDOW *) 0 )
  156.    {
  157.       #ifdef UNIX
  158.      initscr() ;
  159.      raw() ;
  160.      noecho() ;
  161.        keypad( stdscr, 1 ) ;
  162.      refresh() ;
  163.       #endif
  164.  
  165.       if ( num_window <= 0 )  num_window =  1 ;
  166.  
  167.       if ( h4create( (char **) &v4window, num_window, sizeof(CB_WINDOW), 5)  < 0 )  return -1 ;
  168.       v4default_window =  w4define( 0,0, 24,79 ) ;
  169.    }
  170.  
  171.    if ( num_get > 0 && v4get == (GET *) 0)
  172.       if(  h4create( (char **) &v4get, num_get, (int) sizeof(GET), 10) < 0 ) return -1 ;
  173.  
  174.    if ( num_menu_item > 0 && v4menu == (MENU *) 0)
  175.       if(  h4create( (char **) &v4menu, num_menu_item, (int) sizeof(MENU), 15) < 0 ) return -1 ;
  176.  
  177.    return  0 ;
  178. }
  179.  
  180. w4define( int start_row, int start_col, int end_row, int end_col )
  181. {
  182.    int  ref ;
  183.  
  184.    #ifdef OS2
  185.       VIO_DATA  vio_data ;
  186.    #else
  187.       #ifndef UNIX
  188.      union REGS  regs ;
  189.       #endif
  190.    #endif
  191.  
  192.    if ( w4init(10,0,0) < 0 )  return -1 ;
  193.  
  194.    if ( (ref = h4get((char **) &v4window, -1)) < 0 )  return -1 ;
  195.    v4first_window =  h4add( (char **) &v4window, v4first_window, ref, 1 ) ;
  196.  
  197.    if ( v4last_window < 0 )  v4last_window =  v4first_window ;
  198.    w4select( v4first_window ) ;
  199.  
  200.    v4window_ptr->first_get =  -1 ;
  201.    v4window_ptr->last_get  =  -1 ;
  202.    v4window_ptr->first_menu=  -1 ;
  203.    v4window_ptr->last_menu =  -1 ;
  204.    v4window_ptr->start_item=  -1 ;
  205.    v4window_ptr->hand      =  -1 ;
  206.    v4window_ptr->get_attribute    = B_WHITE ;
  207.    v4window_ptr->menu_attribute   = F_WHITE ;
  208.    v4window_ptr->menu_att_active  = B_WHITE ;
  209.    v4window_ptr->attribute      = F_WHITE ;
  210.    v4window_ptr->release    = -1 ;
  211.    v4window_ptr->key_read   =  1 ;
  212.    v4window_ptr->ignore_case=  1 ;
  213.    v4window_ptr->up_key     =  v4up_key ;
  214.    v4window_ptr->exit_key   =  v4exit_key ;
  215.    v4window_ptr->return_start= v4return_start ;
  216.    v4window_ptr->return_end =  v4return_end ;
  217.  
  218.    #ifdef OS2
  219.      memset( (char *) &vio_data, 0, sizeof(vio_data) ) ;
  220.      vio_data.stru_len =  0xE ;
  221.  
  222.      VIOGETMODE( (VIO_DATA far *) &vio_data, 0 ) ;
  223.      if ( end_row < start_row )
  224.     end_row =  vio_data.height -1 ;
  225.      if ( end_col < start_col )
  226.     end_col =  vio_data.width -1 ;
  227.  
  228.      v4screen_width =  vio_data.width ;
  229.      v4screen_width2=  v4screen_width<<1 ;
  230.      v4screen_height=  vio_data.height ;
  231.  
  232.      cga =   (int) (vio_data.mode_info & 1) ;
  233.    #else
  234.  
  235.    #ifdef UNIX
  236.       v4screen_width  =  COLS ;
  237.       v4screen_width2 =  v4screen_width<<1 ;
  238.       v4screen_height =  LINES ;
  239.    #else
  240.       regs.h.ah =  0xF ;
  241.       #ifdef IS_386
  242.          int386( 0x10, ®s, ®s ) ;
  243.       #else
  244.          int86( 0x10, ®s, ®s ) ;
  245.       #endif
  246.  
  247.       if ( end_row < start_row )
  248.      end_row =  24 ;
  249.       if ( end_col < start_col )
  250.      end_col =  regs.h.ah -1 ;
  251.       v4screen_width  =  regs.h.ah ;
  252.       v4screen_width2 =  v4screen_width << 1 ;
  253.       v4screen_height =  25 ;
  254.  
  255.       memory_ptr.p.off = 0 ;
  256.       #ifdef IS_386
  257.          memory_ptr.p.seg =  0x1C ;
  258.       #else
  259.          if ( regs.h.al == 0x7 )
  260.          {
  261.         cga = 0 ;  /* Monochrome */
  262.         memory_ptr.p.seg =  0xB000 ;
  263.          }
  264.          else
  265.          {
  266.             if ( regs.h.al == 0 || regs.h.al == 2 )
  267.            cga = 1 ;  /* Color Graphics Board */
  268.         memory_ptr.p.seg =  0xB800 ;
  269.          }
  270.       #endif
  271.    #endif
  272.    #endif
  273.  
  274.    v4window_ptr->start_row =  start_row ;
  275.    v4window_ptr->start_col =  start_col ;
  276.    v4window_ptr->height    =  end_row - start_row + 1 ;
  277.    v4window_ptr->width     =  end_col - start_col + 1 ;
  278.    #ifdef UNIX
  279.       if ( v4window_ptr->width > MAX_WINDOW_WIDTH )
  280.          v4window_ptr->width =  MAX_WINDOW_WIDTH ;
  281.  
  282.       if ( start_row < 0 )  start_row =  0 ;
  283.       if ( start_col < 0 )  start_col =  0 ;
  284.       v4window_ptr->win =  newwin( v4window_ptr->height, v4window_ptr->width,
  285.                                    start_row, start_col ) ;
  286.       if ( v4window_ptr->win == (WINDOW *) 0 )
  287.       {
  288.      u4error( E_MEMORY, (char *) 0 ) ;
  289.      return -1 ;
  290.       }
  291.    #endif
  292.    v4window_ptr->display_bytes =  v4window_ptr->height*v4window_ptr->width*2 ;
  293.  
  294.    v4display_bytes =  v4screen_width2 * v4screen_height ;
  295.  
  296.    return v4cur_window ;
  297. }
  298.  
  299. void  w4enlarge()
  300. {
  301.    if ( v4window_ptr->border_chars != (char *) 0 )
  302.    {
  303.       #ifdef UNIX
  304.      v4window_ptr->border_offset =  0 ;
  305.       #endif
  306.       /* Temporarily Enlarge the Window */
  307.       v4window_ptr->start_row-- ;
  308.       v4window_ptr->start_col-- ;
  309.       v4window_ptr->height += 2 ;
  310.       v4window_ptr->width  += 2 ;
  311.       v4window_ptr->display_bytes= v4window_ptr->height*v4window_ptr->width*2;
  312.    }
  313. }
  314.  
  315. void  w4shrink()
  316. {
  317.    if ( v4window_ptr->border_chars != (char *) 0 )
  318.    {
  319.       #ifdef UNIX
  320.      v4window_ptr->border_offset =  1 ;
  321.       #endif
  322.       /* Temporarily Enlarge the Window */
  323.       v4window_ptr->start_row++ ;
  324.       v4window_ptr->start_col++ ;
  325.       v4window_ptr->height -= 2 ;
  326.       v4window_ptr->width  -= 2 ;
  327.       v4window_ptr->display_bytes= v4window_ptr->height*v4window_ptr->width*2;
  328.    }
  329. }
  330.  
  331.  
  332. void  w4( int row, int column, char *buffer )
  333. {
  334.    w4num( row, column, buffer, (int) strlen(buffer) ) ;
  335. }
  336.  
  337.  
  338. long  w4attribute( long attribute )
  339. {
  340.    if ( attribute >= 0L )
  341.    {
  342.       v4window_ptr->attribute =  attribute ;
  343.       #ifdef UNIX
  344.      wattrset( v4window_ptr->win, attribute ) ;
  345.       #endif
  346.    }
  347.    return( v4window_ptr->attribute ) ;
  348. }
  349.  
  350.  
  351. void  w4centre( int row, char *buffer )
  352. {
  353.    int  len ;
  354.  
  355.    len =  (int) strlen(buffer) ;
  356.    w4num( row, (v4window_ptr->width-len)/2, buffer, len ) ;
  357. }
  358.  
  359. #ifndef UNIX
  360. static void  w4do_scroll( int, int, int, int, int, long ) ;
  361.  
  362. static void  w4do_scroll( int start_row, int start_col, 
  363.                           int end_row, int end_col, int n, long attr )
  364. {
  365.    int  height ;
  366.  
  367.    if ( n == 0 )  return ;
  368.    height =   end_row - start_row + 1 ;
  369.  
  370.    #ifdef OS2
  371.    {
  372.       unsigned char cell[2] ;
  373.  
  374.       cell[0] =  ' ' ;
  375.       cell[1] =  (unsigned char) attr ;
  376.  
  377.       if ( n < 0 )
  378.       {
  379.          if ( -n >= height )  n =  1 ;
  380.          VIOSCROLLDN(start_row,start_col,end_row,end_col,-n,(char far *)cell,0);
  381.       }
  382.       else
  383.       {
  384.          if ( n >= height )  n =  -1 ;
  385.          VIOSCROLLUP(start_row,start_col,end_row,end_col,n,(char far *)cell,0);
  386.       }
  387.    }
  388.    #else
  389.    {
  390.       union REGS regs ;
  391.  
  392.       if ( n < 0 )
  393.       {
  394.          if ( -n >= height )  n =  0 ;
  395.          regs.h.al = (unsigned char) -n ;
  396.          regs.h.ah =  7 ;
  397.       }
  398.       else
  399.       {
  400.          if ( n >= height )  n =   0 ;
  401.          regs.h.al =  (unsigned char) n ;
  402.          regs.h.ah =  6 ;
  403.       }
  404.  
  405.       regs.h.bh = (unsigned char) attr ;
  406.       regs.h.ch = (unsigned char) start_row ;
  407.       regs.h.cl = (unsigned char) start_col ;
  408.       regs.h.dh = (unsigned char) end_row ;
  409.       regs.h.dl = (unsigned char) end_col ;
  410.  
  411.       #ifdef IS_386
  412.          int386( 0x10, ®s, ®s ) ;
  413.       #else
  414.          int86( 0x10, ®s, ®s ) ;
  415.       #endif
  416.    }
  417.    #endif
  418. }
  419. #endif
  420.  
  421. void  w4scroll( int n )
  422. {
  423.    #ifdef UNIX
  424.       scrollok( v4window_ptr->win, 1 ) ;
  425.       if ( n <= 0 )  return ;
  426.       while ( --n >= 0 )  scroll( v4window_ptr->win ) ;
  427.       w4refresh( v4cur_window ) ;
  428.       scrollok( v4window_ptr->win, 0 ) ;
  429.    #else
  430.       w4do_scroll( v4window_ptr->start_row, v4window_ptr->start_col,
  431.                 v4window_ptr->height+ v4window_ptr->start_row -1,
  432.                 v4window_ptr->width + v4window_ptr->start_col -1,
  433.         n, v4window_ptr->attribute ) ;
  434.    #endif
  435. }
  436.  
  437.  
  438. void  w4clear( int start_line )
  439. {
  440.    #ifdef UNIX
  441.       if ( v4default_window < 0 )
  442.      u4error( E_INTERNAL, "w4clear", (char *) 0 ) ;
  443.       if ( start_line < 0 )
  444.       {
  445.      clear() ;
  446.      touchwin( stdscr ) ;
  447.      w4refresh(-1) ;
  448.       }
  449.       else
  450.       {
  451.      touchwin( v4window_ptr->win ) ;
  452.      if ( start_line == 0  &&  v4window_ptr->border_chars == (char *) 0 )
  453.      {
  454.         wclear( v4window_ptr->win ) ;
  455.         w4refresh( v4cur_window ) ;
  456.  
  457.         v4window_ptr->row =  start_line ;
  458.         v4window_ptr->col =  0 ;
  459.      }
  460.      else
  461.         w4repeat( start_line, 0, ' ',
  462.           v4window_ptr->width * (v4window_ptr->height- start_line) ) ;
  463.       }
  464.    #else
  465.       if ( start_line < 0 )   /* Clear Entire Screen */
  466.       {
  467.          w4init(10,0,0) ;
  468.      w4do_scroll( 0,0, v4screen_height-1, v4screen_width-1,
  469.               v4screen_height, F_WHITE ) ;
  470.       }
  471.       else
  472.       {
  473.      if ( v4cur_window >= 0 )
  474.      {
  475.         w4do_scroll( v4window_ptr->start_row+start_line,
  476.              v4window_ptr->start_col,
  477.              v4window_ptr->height+ v4window_ptr->start_row -1,
  478.              v4window_ptr->width + v4window_ptr->start_col -1,
  479.              v4window_ptr->height, v4window_ptr->attribute ) ;
  480.         v4window_ptr->row =  (start_line < 0)  ?  0 : start_line ;
  481.         v4window_ptr->col =  0 ;
  482.      }
  483.       }
  484.    #endif
  485. }
  486.  
  487.  
  488. void  w4close( int w_ref )
  489. {
  490.    CB_WINDOW  *w_ptr ;
  491.    int  new_ref ;
  492.  
  493.    if ( w_ref < 0 )
  494.    {
  495.       if ( v4cur_window < 0 )  return ;
  496.       w_ref =  v4cur_window ;
  497.    }
  498.    w_ptr =  v4window +  w_ref ;
  499.  
  500.    #ifndef UNIX
  501.       if ( w_ptr->data != (char *) 0 )
  502.      h4free_memory( w_ptr->data ) ;
  503.  
  504.       if ( w_ptr->old_screen != (char *) 0 )
  505.      h4free_memory( w_ptr->old_screen ) ;
  506.    #endif
  507.  
  508.    h4free_chain( (char **) &v4menu, w_ptr->last_menu ) ;
  509.    h4free_chain( (char **) &v4get,  w_ptr->last_get ) ;
  510.  
  511.    new_ref =  h4free((char **) &v4window, w_ref) ;
  512.    if ( w_ref == v4first_window )  v4first_window =  new_ref ;
  513.    if ( w_ref == v4last_window )   v4last_window  =  new_ref ;
  514.    if ( w_ref == v4cur_window )
  515.    {
  516.       v4cur_window = v4last_window ;
  517.       v4window_ptr = v4window +  new_ref ;
  518.    }
  519.  
  520.    #ifdef UNIX
  521.       delwin( w_ptr->win ) ;
  522.    #endif
  523. }
  524.  
  525.  
  526. int  w4col()
  527. {
  528.    return( v4window_ptr->col ) ;
  529. }
  530.  
  531. #ifdef OS2
  532.    int v4cursor_hide =  1 ;
  533. #endif
  534.  
  535. void  w4cursor( int row, int col )
  536. {
  537.    #ifdef OS2
  538.       CURSOR_DATA   cursor_data ;
  539.  
  540.       if ( v4cursor_hide || row < 0  || col < 0 )
  541.       {
  542.      VIOGETCURTYPE( (CURSOR_DATA far *) &cursor_data, 0 ) ;
  543.      if ( row < 0 || col < 0 )
  544.      {
  545.         v4cursor_hide =  1 ;
  546.         cursor_data.cursor_attr =  0xFFFF ;
  547.      }
  548.      else
  549.      {
  550.         v4cursor_hide =  0 ;
  551.         cursor_data.cursor_attr =  0 ;  /* Visible */
  552.      }
  553.      VIOSETCURTYPE( (CURSOR_DATA far *) &cursor_data, 0 ) ;
  554.       }
  555.  
  556.       if ( row >= 0  &&  col >= 0 )
  557.      VIOSETCURPOS( v4window_ptr->start_row+row, v4window_ptr->start_col+col, 0 ) ;
  558.  
  559.    #else
  560.    #ifdef UNIX
  561.       v4cursor_row =  v4window_ptr->start_row+row ;
  562.       v4cursor_col =  v4window_ptr->start_col+col ;
  563.  
  564.       if ( row < 0 ||  col < 0 )
  565.      v4cursor_hide =  1 ;
  566.       else
  567.      v4cursor_hide =  0 ;
  568.  
  569.       w4refresh(-1) ;
  570.    #else
  571.       union REGS regs ;
  572.  
  573.       if ( row < 0  ||  col < 0 )   row =  -1000 ;
  574.  
  575.       regs.h.ah =   2 ;
  576.       regs.h.bh =   0 ;
  577.       regs.h.dh =  (unsigned char) (v4window_ptr->start_row+ row) ;
  578.       regs.h.dl =  (unsigned char) (v4window_ptr->start_col+ col) ;
  579.  
  580.       #ifdef IS_386
  581.          int386( 0x10, ®s, ®s ) ;
  582.       #else
  583.          int86( 0x10, ®s, ®s ) ;
  584.       #endif
  585.    #endif
  586.    #endif
  587. }
  588.  
  589.  
  590. void  w4cursor_size( int start_line, int end_line )
  591. {
  592.    #ifdef OS2
  593.       CURSOR_DATA  cursor_data ;
  594.  
  595.       VIOGETCURTYPE( (CURSOR_DATA far *) &cursor_data, 0 ) ;
  596.  
  597.       if ( !cga )
  598.       {
  599.      /* Adjust Upward for Monochrome Screens */
  600.      start_line = (start_line * 13) / 7 ;
  601.      end_line   = (end_line   * 13) / 7 ;
  602.       }
  603.  
  604.       cursor_data.start_line =  start_line ;
  605.       cursor_data.end_line   =  end_line ;
  606.  
  607.       VIOSETCURTYPE( (CURSOR_DATA far *) &cursor_data, 0 ) ;
  608.  
  609.    #else
  610.    #ifndef UNIX
  611.       union REGS regs ;
  612.  
  613.       if ( !cga )
  614.       {
  615.      /* Adjust Upward for Monochrome Screens */
  616.      start_line = (start_line * 12) / 7 ;
  617.      end_line   = (end_line   * 12) / 7 ;
  618.       }
  619.       regs.h.ah =   1 ;
  620.       regs.h.ch =   (unsigned char) start_line ;
  621.       regs.h.cl =   (unsigned char) end_line ;
  622.  
  623.       #ifdef IS_386
  624.          int386( 0x10, ®s, ®s ) ;
  625.       #else
  626.          int86( 0x10, ®s, ®s ) ;
  627.       #endif
  628.    #endif
  629.    #endif
  630. }
  631.  
  632.  
  633. void  w4deactivate( int w_ref )
  634. {
  635.    int   old_cur_window ;
  636.  
  637.    #ifdef UNIX
  638.       int  save_refresh_on ;
  639.    #else
  640.       int is_last ;
  641.    #endif
  642.  
  643.    old_cur_window =  v4cur_window ;
  644.    if ( w_ref < 0 )
  645.    {
  646.       if ( v4cur_window < 0 )  return ;
  647.       w_ref =  v4cur_window ;
  648.    }
  649.  
  650.    if ( ! v4window[w_ref].active )  return ;
  651.  
  652.    #ifndef UNIX
  653.       if ( w_ref == v4last_window )
  654.      is_last =  1 ;
  655.       else
  656.      is_last =  0 ;
  657.  
  658.       w4select(v4last_window) ;
  659.       if ( v4window_ptr->active && v4window_ptr->data != (char *) 0)
  660.       {
  661.          /* Save the contents of the last activated window */
  662.          w4enlarge() ;
  663.          w4read_window( v4last_window, v4window_ptr->data ) ;
  664.          w4shrink() ;
  665.       }
  666.    #endif
  667.  
  668.    w4select( w_ref ) ;
  669.    v4window_ptr->active =  0 ;
  670.  
  671.    if ( w_ref != v4first_window )
  672.    {
  673.       if ( w_ref == v4last_window )
  674.      v4last_window =  v4window[w_ref].prev  ;
  675.       h4remove( (char **) &v4window, w_ref ) ;
  676.       h4add( (char **) &v4window, v4first_window, w_ref, 1 ) ;
  677.       v4first_window =  w_ref ;
  678.    }
  679.  
  680.    #ifdef UNIX
  681.       save_refresh_on =  v4refresh_on ;
  682.       v4refresh_on   =  0 ;
  683.    #else
  684.       if ( is_last && v4window_ptr->old_screen != (char *) 0 )
  685.       {
  686.          /* Popup Window which was the last activated */
  687.          w4enlarge() ;
  688.          w4write_window( v4cur_window, v4window_ptr->old_screen ) ;
  689.          w4shrink() ;
  690.  
  691.          if ( v4window[v4last_window].active )
  692.             w4select( v4last_window ) ;
  693.          else
  694.             w4select( old_cur_window ) ;
  695.  
  696.          return ;
  697.       }
  698.    #endif
  699.  
  700.    w4enlarge() ;
  701.    w4clear( 0 ) ;
  702.    w4shrink() ;
  703.  
  704.    for( w4select(v4first_window);; w4select(v4window_ptr->next) )
  705.    {
  706.       #ifdef UNIX
  707.      if ( v4window_ptr->active )
  708.      {
  709.         touchwin( v4window_ptr->win ) ;
  710.         wnoutrefresh( v4window_ptr->win ) ;
  711.      }
  712.       #else
  713.          if ( v4window_ptr->active && v4window_ptr->data != (char *) 0)
  714.          {
  715.         w4enlarge() ;
  716.         w4write_window( v4cur_window, v4window_ptr->data ) ;
  717.         w4shrink() ;
  718.          }
  719.       #endif
  720.       if ( v4window_ptr->next < 0 )  break ;
  721.    }
  722.  
  723.    if ( v4window[v4last_window].active )
  724.       w4select( v4last_window ) ;
  725.    else
  726.       w4select( old_cur_window ) ;
  727.  
  728.    #ifdef UNIX
  729.       v4refresh_on =  save_refresh_on ;
  730.       w4refresh( -1 ) ;
  731.    #endif
  732. }
  733.  
  734.  
  735. void  w4double( int row, int column, double double_value, int len, int dec )
  736. {
  737.    char *ptr ;
  738.  
  739.    ptr =  c4dtoa( double_value, len, dec ) ;
  740.    w4num( row, column, ptr, len ) ;
  741. }
  742.  
  743. #ifdef VARARGS
  744.    w4display( title, va_alist )
  745.    char *title ;
  746.    va_dcl
  747. #else
  748.    w4display( char * title, ... )
  749. #endif
  750. {
  751.    char    *ptr ;
  752.    int      n, max_width, len, w_ref, start_row, start_col, rc, save_window ;
  753.    va_list  arg_marker  ;
  754.  
  755.    if ( title == (char *) 0 )  return -1 ;
  756.  
  757.    save_window =  w4select( -1 ) ;
  758.  
  759.    max_width =  (int) strlen(title ) ;
  760.    n =  0 ;
  761.  
  762.    #ifdef VARARGS
  763.       va_start( arg_marker ) ;
  764.    #else
  765.       va_start( arg_marker, title ) ;
  766.    #endif
  767.  
  768.    for (ptr = title; ptr != (char *) 0; ptr =  va_arg( arg_marker, char *) )
  769.    {
  770.       n++ ;
  771.       len =  (int) strlen(ptr) ;
  772.       max_width =  (len > max_width)  ?  len : max_width ;
  773.    }
  774.  
  775.    if ( n == 1 )  return( w4display( "", title, (char *) 0) ) ;
  776.  
  777.    start_row =  (v4screen_height-n-3)/2 ;
  778.    start_col =  (v4screen_width-max_width-5)/2 ;
  779.  
  780.    w_ref =  w4define( start_row, start_col, start_row+n+2,start_col+max_width+5);
  781.  
  782.    w4title( 0,-1, title, F_WHITE | F_INTENSE ) ;
  783.    w4border( DOUBLE, F_WHITE ) ;
  784.    w4popup() ;
  785.  
  786.    w4cursor( -1,-1 ) ;
  787.  
  788.    w4activate( w_ref ) ;
  789.  
  790.    n =  0 ;
  791.  
  792.    #ifdef VARARGS
  793.       va_start( arg_marker ) ;
  794.    #else
  795.       va_start( arg_marker, title ) ;
  796.    #endif
  797.    for ( ptr =  va_arg( arg_marker, char *);  ptr != (char *) 0;
  798.      ptr =  va_arg( arg_marker, char *)  )
  799.    {
  800.       n++ ;
  801.       w4( n,2, ptr ) ;
  802.    }
  803.  
  804.    rc =  g4char() ;
  805.  
  806.    w4deactivate( w_ref ) ;
  807.    w4close( w_ref ) ;
  808.  
  809.    w4select( save_window ) ;
  810.  
  811.    return( rc ) ;
  812. }
  813.  
  814.  
  815. void  w4eject()
  816. {
  817.    write( v4window_ptr->hand, "\f", 1) ;
  818.    v4window_ptr->row =  0 ;
  819.    v4window_ptr->col =  0 ;
  820. }
  821.  
  822.  
  823. void  w4exit(int rc)
  824. {
  825.    w4select( v4default_window ) ;
  826.    w4cursor(23,0) ;
  827.  
  828.    #ifdef UNIX
  829.       endwin() ;
  830.    #endif
  831.  
  832.    exit(rc) ;
  833. }
  834.  
  835.  
  836. w4handle( int hand )
  837. {
  838.    int  last_hand ;
  839.  
  840.    last_hand =  v4window_ptr->hand ;
  841.    if ( hand >= -1 )
  842.       v4window_ptr->hand =      hand ;
  843.  
  844.    return( last_hand ) ;
  845. }
  846.  
  847.  
  848. void  w4int( int row, int column, int int_value, int len )
  849. {
  850.    char buffer[18] ;
  851.  
  852.    c4ltoa( (long) int_value, buffer, len ) ;
  853.    w4num( row, column, buffer, len ) ;
  854. }
  855.  
  856.  
  857. #ifndef UNIX
  858. void w4read( int row, int col, char *buffer, int len )
  859. {
  860.    #ifdef OS2
  861.       VIOREADCELLSTR( (char far *) buffer, (int far *) &len, row, col, 0 ) ;
  862.    #else
  863.       char far *ptr ;
  864.       int  offset ;
  865.    
  866.       offset =  row*v4screen_width2 + (col<<1) ;
  867.       if ( offset +len > v4display_bytes )
  868.       {
  869.          len =  v4display_bytes - offset ;
  870.          if ( len <= 0 )  return ;
  871.       }
  872.    
  873.       ptr =  memory_ptr.far_ptr + offset ;
  874.    
  875.       #ifndef IS_386
  876.       if ( cga )
  877.          W4READ_ASM( ptr, (char far *) buffer, len ) ;
  878.       else
  879.       #endif
  880.          while ( --len >= 0 )
  881.             *buffer++ =  *ptr++ ;
  882.    #endif
  883.  
  884.    return ;
  885. }
  886. #endif
  887.  
  888. #ifndef UNIX
  889. void  w4read_window( int window_ref, char *ptr )
  890. {
  891.    int     i, data_width ;
  892.    CB_WINDOW *window_ptr ;
  893.  
  894.    if ( window_ref < 0 || ptr == (char *) 0 )  return ;
  895.  
  896.    window_ptr =  v4window+ window_ref ;
  897.    data_width =  window_ptr->width*2 ;
  898.  
  899.    for ( i= 0;  i < window_ptr->height; i++ )
  900.    {
  901.       w4read( window_ptr->start_row+i, window_ptr->start_col, ptr, data_width ) ;
  902.       ptr +=  data_width ;
  903.    }
  904. }
  905. #endif
  906.  
  907. #ifndef UNIX
  908. void w4write( int row, int col, char *buffer, int len )
  909. {
  910.    #ifdef OS2
  911.       VIOWRTCELLSTR( (char far *) buffer, len, row, col, 0 ) ;
  912.    #else
  913.       char far *ptr ;
  914.       int  offset ;
  915.  
  916.       offset =  row*v4screen_width2 + (col<<1) ;
  917.       if ( offset +len > v4display_bytes )
  918.       {
  919.          len =  v4display_bytes - offset ;
  920.          if ( len <= 0 )  return ;
  921.       }
  922.  
  923.       ptr =  memory_ptr.far_ptr + offset ;
  924.  
  925.       #ifndef IS_386
  926.       if ( cga )
  927.          W4WRITE_ASM( ptr, (char far *) buffer, len ) ;
  928.       else
  929.       #endif
  930.          while ( --len >= 0 )
  931.         *ptr++ =  *buffer++ ;
  932.    #endif
  933. }
  934. #endif
  935.  
  936. #ifndef UNIX
  937. void w4write_att( int row, int col, char *buffer, int len, long attribute_char )
  938. {
  939.    #ifdef OS2
  940.       VIOWRTCHARSTRATT( (char far *) buffer, len, row, col, (char far *) &attribute_char, 0 ) ;
  941.    #else
  942.  
  943.    char far *ptr ;
  944.    int  offset ;
  945.  
  946.    offset =  row*v4screen_width2 + (col<<1) ;
  947.    if ( offset +(len<<1) > v4display_bytes )
  948.    {
  949.       len =  (v4display_bytes - offset)/2 ;
  950.       if ( len <= 0 )  return ;
  951.    }
  952.  
  953.    ptr =  memory_ptr.far_ptr + offset ;
  954.  
  955.    #ifndef IS_386
  956.    if ( cga )
  957.       W4WRITE_ATT_ASM( ptr, (char far *) buffer, len, (int) attribute_char ) ;
  958.    else
  959.    #endif
  960.       while ( --len >= 0 )
  961.       {
  962.      *ptr++ =  *buffer++ ;
  963.      *ptr++ =  (char) attribute_char ;
  964.       }
  965.  
  966.    #endif
  967. }
  968. #endif
  969.  
  970. #ifndef UNIX
  971. void  w4write_window( int window_ref, char *ptr )
  972. {
  973.    int     i, data_width ;
  974.    CB_WINDOW *window_ptr ;
  975.  
  976.    if ( window_ref < 0 || ptr == (char *) 0 )  return ;
  977.  
  978.    window_ptr =  v4window+ window_ref ;
  979.    data_width =  window_ptr->width*2 ;
  980.  
  981.    for ( i= 0; i < window_ptr->height; i++ )
  982.    {
  983.       w4write( window_ptr->start_row+i,window_ptr->start_col,
  984.              ptr, data_width ) ;
  985.  
  986.       ptr +=  data_width ;
  987.    }
  988. }
  989. #endif
  990.  
  991. void  w4long( int row, int column, long long_value, int len )
  992. {
  993.    char buffer[40] ;
  994.  
  995.    c4ltoa( (long) long_value, buffer, len ) ;
  996.    w4num( row, column, buffer, len ) ;
  997. }
  998.  
  999.  
  1000. void  w4num( int row, int col, char *buffer, int len )
  1001. {
  1002.    int  cur_len, buffer_pos ;
  1003.    #ifdef UNIX
  1004.       unsigned char  out_buffer[MAX_WINDOW_WIDTH+1] ;
  1005.  
  1006.       if ( len > MAX_WINDOW_WIDTH )  len =  MAX_WINDOW_WIDTH ;
  1007.    #endif
  1008.  
  1009.    if ( row < 0 )  row = 0 ;
  1010.    if ( col < 0 )  col = 0 ;
  1011.  
  1012.    if ( col >= v4window_ptr->width )
  1013.    {
  1014.       row +=  col/v4window_ptr->width ;
  1015.       col %=  v4window_ptr->width ;
  1016.    }
  1017.  
  1018.    buffer_pos =  0 ;
  1019.  
  1020.    if ( len == 0 )
  1021.    {
  1022.       /* In case the handle is >= 0 */
  1023.       w4position( row,col ) ;
  1024.       return ;
  1025.    }
  1026.  
  1027.    while ( len > 0 )
  1028.    {
  1029.       if ( col+len > v4window_ptr->width )
  1030.      cur_len =  v4window_ptr->width - col ;
  1031.       else
  1032.      cur_len =  len ;
  1033.  
  1034.       if ( v4window_ptr->hand >= 0 )
  1035.       {
  1036.      w4position( row, col ) ;
  1037.      write( v4window_ptr->hand, buffer+buffer_pos, cur_len ) ;
  1038.       }
  1039.       else
  1040.       {
  1041.      if ( row >= v4window_ptr->height )
  1042.         row %=  v4window_ptr->height ;
  1043.  
  1044.      #ifdef UNIX
  1045.      {
  1046.         memcpy( out_buffer, buffer+buffer_pos, (size_t) cur_len ) ;
  1047.         out_buffer[cur_len] =  '\000' ;
  1048.         mvwaddstr( v4window_ptr->win, row+ v4window_ptr->border_offset,
  1049.                col+ v4window_ptr->border_offset, out_buffer ) ;
  1050.      }
  1051.          #else
  1052.         w4write_att( v4window_ptr->start_row+row, v4window_ptr->start_col+col,
  1053.              buffer+buffer_pos, cur_len, v4window_ptr->attribute ) ;
  1054.          #endif
  1055.       }
  1056.       buffer_pos += cur_len ;
  1057.       len -=  cur_len ;
  1058.       col +=  cur_len ;
  1059.       if ( col >= v4window_ptr->width )
  1060.       {
  1061.      row++ ;
  1062.      if ( row >= v4window_ptr->height && v4window_ptr->hand < 0 )
  1063.           row %=  v4window_ptr->height ;
  1064.      col =  0 ;
  1065.       }
  1066.    }
  1067.    v4window_ptr->row =  row ;
  1068.    v4window_ptr->col =  col ;
  1069.  
  1070.    #ifdef UNIX
  1071.       w4refresh( v4cur_window ) ;
  1072.    #endif
  1073. }
  1074.  
  1075.  
  1076. void  w4num_att( int row, int col, char *buffer, int len, long attribute )
  1077. {
  1078.    long  old_attribute ;
  1079.  
  1080.    old_attribute =  v4window_ptr->attribute ;
  1081.    v4window_ptr->attribute =  attribute ;
  1082.    #ifdef UNIX
  1083.       wattrset( v4window_ptr->win, attribute ) ;
  1084.    #endif
  1085.  
  1086.    w4num( row, col, buffer, len ) ;
  1087.  
  1088.    v4window_ptr->attribute =  old_attribute ;
  1089.    #ifdef UNIX
  1090.       wattrset( v4window_ptr->win, old_attribute ) ;
  1091.    #endif
  1092. }
  1093.  
  1094.  
  1095. void  w4out( char *buffer )
  1096. {
  1097.    w4num( v4window_ptr->row, v4window_ptr->col, buffer, (int) strlen(buffer) ) ;
  1098. }
  1099.  
  1100. void  w4position_set( int row, int col ) 
  1101. {
  1102.    v4window_ptr->col =  col ;
  1103.    v4window_ptr->row =  row ;
  1104. }
  1105.  
  1106. void  w4position( int row, int col )
  1107. {
  1108.    if ( col >= v4window_ptr->width )
  1109.    {
  1110.       row +=  col/v4window_ptr->width ;
  1111.       col %=  v4window_ptr->width ;
  1112.    }
  1113.  
  1114.    if ( v4window_ptr->hand < 0 )
  1115.    {
  1116.       if ( row >= v4window_ptr->height )  row %=  v4window_ptr->height ;
  1117.       v4window_ptr->row =  row ;
  1118.       v4window_ptr->col =  col ;
  1119.       return ;
  1120.    }
  1121.  
  1122.    if ( row < v4window_ptr->row  ||  row == v4window_ptr->row && col < v4window_ptr->col)
  1123.       w4eject() ;
  1124.  
  1125.    while ( v4window_ptr->row < row )
  1126.    {
  1127.       v4window_ptr->col =  0 ;
  1128.       v4window_ptr->row++ ;
  1129.       write( v4window_ptr->hand, "\r\n", 2 ) ;
  1130.    }
  1131.  
  1132.    while ( v4window_ptr->col < col )
  1133.    {
  1134.       char blanks[80] ;
  1135.  
  1136.       memset( blanks, (int) ' ', (size_t) sizeof(blanks) ) ;
  1137.       while ( col - v4window_ptr->col > sizeof(blanks) )
  1138.       {
  1139.      v4window_ptr->col += sizeof(blanks) ;
  1140.      write( v4window_ptr->hand, blanks, (unsigned int) sizeof(blanks) ) ;
  1141.       }
  1142.  
  1143.       write( v4window_ptr->hand, blanks, (unsigned int) (col - v4window_ptr->col) ) ;
  1144.       v4window_ptr->col =  col ;
  1145.    }
  1146. }
  1147.  
  1148.  
  1149. void  w4repeat( int row, int column, char chr, int num )
  1150. {
  1151.    char buffer[MAX_WINDOW_WIDTH] ;
  1152.    #ifdef UNIX
  1153.       int  old_refresh_on ;
  1154.  
  1155.       old_refresh_on = v4refresh_on ;
  1156.       v4refresh_on =  0 ;
  1157.    #endif
  1158.  
  1159.    if ( num < 0 )  return ;
  1160.  
  1161.    memset( buffer, (int) chr, (size_t) sizeof(buffer) ) ;
  1162.    w4num( row, column, buffer, 0 ) ;  /* Position to (row,column) */
  1163.  
  1164.    for (;;)
  1165.    {
  1166.       if ( num < sizeof(buffer) )
  1167.       {
  1168.      w4num( v4window_ptr->row, v4window_ptr->col, buffer, num ) ;
  1169.      #ifdef UNIX
  1170.         v4refresh_on =  old_refresh_on ;
  1171.         w4refresh( v4cur_window ) ;
  1172.      #endif
  1173.      return ;
  1174.       }
  1175.  
  1176.       w4num( v4window_ptr->row, v4window_ptr->col, buffer, sizeof(buffer) ) ;
  1177.       num -=  sizeof(buffer) ;
  1178.    }
  1179. }
  1180.  
  1181.  
  1182. int  w4row()
  1183. {
  1184.    return( v4window_ptr->row ) ;
  1185. }
  1186.  
  1187.  
  1188. void  w4activate( int window_ref )
  1189. {
  1190.    int   col ;
  1191.    long  save_attribute ;
  1192.  
  1193.    if ( window_ref < 0 )
  1194.       window_ref =  w4select( -1 ) ;
  1195.  
  1196.    w4select( window_ref ) ;
  1197.    if ( v4last_window == window_ref && v4window_ptr->active  ||
  1198.     v4window_ptr->hand >= 0 )  return ;
  1199.  
  1200.    #ifndef UNIX
  1201.       if ( v4last_window >= 0  &&  v4window[v4last_window].active )
  1202.       {
  1203.          w4select( v4last_window ) ;
  1204.          w4enlarge() ;
  1205.          w4read_window( v4last_window, v4window[v4last_window].data ) ;
  1206.          w4shrink() ;
  1207.          w4select( window_ref ) ;
  1208.       }
  1209.    #endif
  1210.  
  1211.    w4enlarge() ;
  1212.    if ( v4window_ptr->start_row < 0 || v4window_ptr->start_col < 0 ||
  1213.     v4window_ptr->height < 0 || v4window_ptr->width < 0 )
  1214.    {
  1215.       if ( v4window_ptr->start_row < 0 )  v4window_ptr->start_row =  0 ;
  1216.       if ( v4window_ptr->start_col < 0 )  v4window_ptr->start_col =  0 ;
  1217.       if ( v4window_ptr->height < 0 )
  1218.      v4window_ptr->height =  v4screen_height - v4window_ptr->start_row ;
  1219.       if ( v4window_ptr->width < 0 )
  1220.      v4window_ptr->width  =  v4screen_width - v4window_ptr->start_col ;
  1221.       #ifndef UNIX
  1222.          if ( v4window_ptr->data != (char *) 0 )         w4memory() ;
  1223.          if ( v4window_ptr->old_screen != (char *) 0 )   w4popup() ;
  1224.       #endif
  1225.    }
  1226.  
  1227.    #ifndef UNIX
  1228.       w4read_window( v4cur_window, v4window_ptr->old_screen ) ;
  1229.    #endif
  1230.  
  1231.    #ifdef UNIX
  1232.       if ( v4window_ptr->active )
  1233.       {
  1234.      touchwin( v4window_ptr->win ) ;
  1235.      w4refresh(v4cur_window) ;
  1236.       }
  1237.    #else
  1238.       if ( v4window_ptr->data != (char *) 0  && v4window_ptr->active )
  1239.          w4write_window( v4cur_window, v4window_ptr->data ) ;
  1240.    #endif
  1241.       else
  1242.       {
  1243.      #ifdef UNIX
  1244.         int  old_refresh_on ;
  1245.  
  1246.         old_refresh_on =  v4refresh_on ;
  1247.         v4refresh_on =  0 ;
  1248.      #endif
  1249.          /* Display the Border if one Exists */
  1250.          w4clear(0) ;
  1251.          if ( v4window_ptr->border_chars )
  1252.          {
  1253.         save_attribute =  v4window_ptr->attribute ;
  1254.         v4window_ptr->attribute =  v4window_ptr->border_attribute ;
  1255.         w4box( v4window_ptr->border_chars, 0,0,
  1256.                   v4window_ptr->height-1, v4window_ptr->width-1 ) ;
  1257.         v4window_ptr->attribute =  save_attribute ;
  1258.          }
  1259.  
  1260.          /* Add the Title */
  1261.          if ( v4window_ptr->title != (char *) 0 )
  1262.          {
  1263.             col =  v4window_ptr->title_col ;
  1264.  
  1265.             if ( col < 0 )
  1266.            col =  (v4window_ptr->width - (int) strlen(v4window_ptr->title)) / 2 ;
  1267.             else
  1268.            col =  v4window_ptr->title_col ;
  1269.  
  1270.         w4num_att( v4window_ptr->title_row, col, v4window_ptr->title,
  1271.                   (int) strlen(v4window_ptr->title), v4window_ptr->title_attribute ) ;
  1272.      }
  1273.      #ifdef UNIX
  1274.         v4refresh_on =  old_refresh_on ;
  1275.         w4refresh( v4cur_window ) ;
  1276.      #endif
  1277.       }
  1278.  
  1279.    w4shrink() ;
  1280.  
  1281.    v4window_ptr->active =  1 ;
  1282.  
  1283.    /* Make the Current Window the Last Window */
  1284.    if ( v4cur_window == v4last_window )  return ;
  1285.    if ( v4first_window == v4cur_window )
  1286.       v4first_window =  v4window[v4cur_window].next ;
  1287.  
  1288.    h4remove( (char **) &v4window, v4cur_window ) ;
  1289.    h4add( (char **) &v4window, v4last_window, v4cur_window, 0 ) ;
  1290.    v4last_window =  v4cur_window ;
  1291. }
  1292.  
  1293.  
  1294. void  w4border( char *box_chars, long attribute )
  1295. {
  1296.    w4enlarge() ;
  1297.    v4window_ptr->border_chars =  box_chars ;
  1298.    v4window_ptr->border_attribute =  attribute ;
  1299.    w4shrink() ;
  1300. }
  1301.  
  1302.  
  1303. void  w4box( char *box_chars, int start_row, int start_col, int end_row, int end_col )
  1304. {
  1305.    int  i ;
  1306.  
  1307.    #ifdef UNIX
  1308.       int   old_refresh ; 
  1309.  
  1310.       old_refresh  =  v4refresh_on ;
  1311.       v4refresh_on =  0 ;
  1312.    #endif
  1313.  
  1314.    w4repeat( start_row, start_col+1, box_chars[0], end_col-start_col-1 ) ;
  1315.    w4repeat( end_row,   start_col+1, box_chars[1], end_col-start_col-1 ) ;
  1316.    for ( i= start_row+1; i< end_row; i++ )
  1317.    {
  1318.       w4num( i, start_col, box_chars+2, 1 ) ;
  1319.       w4num( i, end_col,   box_chars+3, 1 ) ;
  1320.    }
  1321.    w4num( start_row, start_col, box_chars+4, 1 ) ;
  1322.    w4num( start_row, end_col,   box_chars+5, 1 ) ;
  1323.    w4num( end_row, start_col,   box_chars+6, 1 ) ;
  1324.    w4num( end_row,   end_col,   box_chars+7, 1 ) ;
  1325.  
  1326.    #ifdef UNIX
  1327.       v4refresh_on =  old_refresh ;
  1328.       w4refresh( v4cur_window ) ;
  1329.    #endif
  1330. }
  1331.  
  1332.  
  1333. void  w4memory()
  1334. {
  1335.    #ifdef UNIX
  1336.       w4enlarge() ;
  1337.       if ( v4window_ptr->win == (WINDOW *) 0 )
  1338.          u4error( E_INTERNAL, "w4memory", (char *) 0 ) ;
  1339.  
  1340.       delwin( v4window_ptr->win ) ;
  1341.  
  1342.       if ( v4window->height > 0 && v4window_ptr->width > 0 &&
  1343.          v4window_ptr->start_row >= 0 && v4window_ptr->start_col >= 0 )
  1344.          v4window_ptr->win =  newwin( v4window_ptr->height, v4window_ptr->width,
  1345.                             v4window_ptr->start_row, v4window_ptr->start_col ) ;
  1346.       else
  1347.          v4window_ptr->win =  newwin( 1,1,0,0 ) ;
  1348.  
  1349.       if ( v4window_ptr->win == (WINDOW *) 0 )
  1350.          u4error( E_MEMORY, (char *) 0 ) ;
  1351.  
  1352.       v4window_ptr->display_bytes= v4window_ptr->height * v4window_ptr->width*2;
  1353.       w4shrink() ;
  1354.    #else
  1355.       if ( v4window_ptr->data != (char *) 0 )
  1356.       {
  1357.          h4free_memory( v4window_ptr->data ) ;
  1358.          v4window_ptr->data =  (char *) 0 ;
  1359.       }
  1360.       w4enlarge() ;
  1361.       v4window_ptr->display_bytes= v4window_ptr->height * v4window_ptr->width*2;
  1362.       if ( v4window_ptr->display_bytes > 0 )
  1363.          v4window_ptr->data =  h4alloc( v4window_ptr->display_bytes ) ;
  1364.       w4shrink() ;
  1365.    #endif
  1366. }
  1367.  
  1368.  
  1369. void  w4popup()
  1370. {
  1371.    #ifdef UNIX
  1372.       w4memory() ;
  1373.    #else
  1374.       if (v4window_ptr->old_screen != (char *) 0)
  1375.       {
  1376.          h4free_memory( v4window_ptr->old_screen);
  1377.          v4window_ptr->old_screen =  (char *) 0 ;
  1378.       }
  1379.       w4enlarge() ;
  1380.  
  1381.       /* v4window_ptr->display_bytes  could have been changed by 'n4lotus', .. */
  1382.       v4window_ptr->display_bytes= v4window_ptr->height * v4window_ptr->width*2;
  1383.       if ( v4window_ptr->display_bytes > 0 )
  1384.       {
  1385.          v4window_ptr->old_screen =  h4alloc( v4window_ptr->display_bytes ) ;
  1386.       }
  1387.       w4shrink() ;
  1388.    #endif
  1389. }
  1390.  
  1391.  
  1392. w4select( int window_ref )
  1393. {
  1394.    int  previous_ref ;
  1395.  
  1396.    previous_ref =  v4cur_window ;
  1397.  
  1398.    if ( window_ref >= 0 )
  1399.    {
  1400.       v4cur_window =  window_ref ;
  1401.       v4window_ptr =  v4window+  window_ref ;
  1402.    }
  1403.    return  previous_ref ;
  1404. }
  1405.  
  1406.  
  1407. void  w4title( int row, int col, char *title, long attribute )
  1408. {
  1409.    v4window_ptr->title_row =  row ;
  1410.    v4window_ptr->title_col =  col ;
  1411.    v4window_ptr->title =  title ;
  1412.    v4window_ptr->title_attribute =  attribute ;
  1413. }
  1414.  
  1415. int  w4width( int new_width )
  1416. {
  1417.    if ( new_width > 0  &&  new_width != v4window_ptr->width )
  1418.    {
  1419.       v4window_ptr->width =  new_width ;
  1420.       #ifndef UNIX
  1421.          if ( v4window_ptr->old_screen != (char *) 0 )   w4popup() ;
  1422.          if ( v4window_ptr->data != (char *) 0 )     w4memory() ;
  1423.       #endif
  1424.    }
  1425.    return ( v4window_ptr->width ) ;
  1426. }
  1427.  
  1428. int  w4height( int new_height )
  1429. {
  1430.    if ( new_height > 0  &&  new_height != v4window_ptr->height )
  1431.    {
  1432.       v4window_ptr->height =  new_height ;
  1433.       #ifndef UNIX
  1434.          if ( v4window_ptr->old_screen != (char *) 0 )  w4popup() ;
  1435.          if ( v4window_ptr->data != (char *) 0 )    w4memory() ;
  1436.       #endif
  1437.    }
  1438.    return ( v4window_ptr->height ) ;
  1439. }
  1440.  
  1441. /*  This does not currently work.
  1442. void  w4silent( int r, int c, char *ptr )
  1443. {
  1444.    int  pos ;
  1445.  
  1446.    if ( v4window_ptr->data == (void *) 0 )  return ;
  1447.    pos =  r*v4window_ptr->width + c ;
  1448.  
  1449.    for(;;)
  1450.    {
  1451.       if ( pos >= v4window_ptr->display_bytes )  break ;
  1452.       if ( *ptr == 0 )  break ;
  1453.       v4window_ptr->data[pos++] =  *ptr++ ;
  1454.       v4window_ptr->data[pos++] =  v4window_ptr->attribute ;
  1455.    }
  1456. }
  1457. */
  1458.