home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0010 - 0019 / ibm0010-0019 / ibm0010.tar / ibm0010 / CODE4-4.ZIP / HDR_EXMP.ZIP / SOURCE.ZIP / W4.C
Encoding:
C/C++ Source or Header  |  1989-10-14  |  34.5 KB  |  1,455 lines

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