home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / files / program / lynxlib / curses.c < prev    next >
C/C++ Source or Header  |  1993-10-23  |  29KB  |  1,397 lines

  1. /* #[curses: simple-minded implementation of the curses package                */
  2. /* #[intro: introduction                                                    */
  3. /*                                                                             */
  4. /* This source and resulting object may be modified, used or distributed by */
  5. /* anyone who so desires under the following conditions :                   */
  6. /*                                                                            */
  7. /*        1) This notice and the copyright notice shall not be removed or     */
  8. /*           changed.                                                            */
  9. /*        2) No credit shall be taken for this source and resulting objects   */
  10. /*        3) This source or resulting objects is not to be traded, sold or    */
  11. /*           used for personal gain or profit.                                */
  12. /*        4) Inclusion of this source or resulting objects in commercially    */
  13. /*           available packages is forbidden without written consent of the   */
  14. /*           author of this source.                                            */
  15. /*                                                                          */
  16. /* This source modified January 26, 1990 by Robert Fischer to:              */
  17. /*       Compile under LynxLib                                              */
  18. /*       Use Cconout instead of Bconout                                     */
  19. /* #]intro:                                                                    */
  20. /* #[include: include files                                                    */
  21.  
  22. #define CURSES_C
  23. #define CONOUT(x) Cconout(x)    /* Use GEMDOS */
  24. /*#define CONOUT(x) Bconout(2, x)    /* Use BIOS */
  25.  
  26. #include <osbind.h>
  27. #include <curses.h>
  28. /* #]include:                                                                */
  29. /* define supervisor mode entry forgotten in osbind.h                        */
  30. /* #define Supexec(a)    xbios(38,a) */
  31. /* terminal states : cooked, cbreak and raw                                    */
  32. #define COOKED 0
  33. #define CBREAK 1
  34. #define RAW    2
  35. /* define address of system-variable _conterm for kbshift return value        */
  36. #define CONTERM        (*((char *)0x484))
  37. /* #[globals: definition of global variables                                */
  38. /* #[curglob: define the following variables as external in curses.h        */
  39. WINDOW *curscr ;
  40. WINDOW *stdscr ;
  41. char    *Def_term = "AtariST" ;
  42. bool    My_term = FALSE ;
  43. char    *ttytype = "Atari ST-series computer, VT52/CURSES mode" ;
  44. int        LINES = 25 ;
  45. int        COLS = 80 ;
  46. int        ERR = 0 ;
  47. int        OK = 1 ;
  48. /* #]curglob:                                                                */
  49. bool   _doecho = FALSE ;
  50. bool   _nlmap = FALSE ;
  51. bool   _curini = FALSE ;
  52. BYTE    _modinp = 0 ; /* set input to Un*x compatability, i.e only char's    */
  53. BYTE    _csry = 0 ;
  54. BYTE    _csrx = 0 ;
  55. char *cpyrid = "Copyright, R. van't Veen. All rights reserved. 1987" ;
  56.  
  57. /* overlay "curses"    /* put in separate segment */
  58.  
  59. /* #]globals:                                                                */
  60. /* #[miscel: miscellaneous curses functions                                    */
  61. /* #[initscr: initialize the curses package                                    */
  62. initscr()
  63. {
  64.     WORD i,j ;
  65.     WINDOW *newwin() ;
  66.  
  67.     if ( _curini )
  68.         {
  69.         wrefresh(curscr) ;
  70.         if ( cpyrid == NULL )
  71.             Pterm(-12L) ;
  72.         ERR = 1 ;
  73.         OK = 0 ;
  74.         return ;
  75.         } ;
  76.     _curini = 1 ;
  77.     curscr = newwin(0,0,0,0) ;
  78.     if ( curscr == NULL )
  79.         {
  80.         ERR = 1 ;
  81.         OK = 0 ;
  82.         return ;
  83.         } ;
  84.     stdscr = newwin(0,0,0,0) ;
  85.     if ( stdscr == NULL )
  86.         {
  87.         ERR = 1 ;
  88.         OK = 0 ;
  89.         return ;
  90.         } ;
  91.     CONOUT('\033') ;
  92.     CONOUT('E') ;
  93.     CONOUT('\033') ;
  94.     CONOUT('w') ;
  95.     CONOUT('\033') ;
  96.     CONOUT('f') ;
  97.     _csry = 0 ;
  98.     _csrx = 0 ;
  99.     ERR = 0 ;
  100.     OK = 1 ;
  101. }
  102. /* #]initscr:                                                                */
  103. /* #[endwin: end of curses package                                            */
  104. endwin()
  105. {
  106.     if ( !_curini )
  107.         {
  108.         ERR = 1 ;
  109.         OK = 0 ;
  110.         return ;
  111.         } ;
  112.     _curini = 0 ;
  113.     delwin(stdscr) ;
  114.     delwin(curscr) ;
  115.     _movcur(LINES,0) ;
  116.     CONOUT('\033') ;
  117.     CONOUT('e') ;
  118.     ERR = 1 ;
  119.     OK = 0 ;
  120. }
  121. /* #]endwin:                                                                */
  122. /* #[newwin: create a new window for the user                                */
  123. WINDOW *newwin(l,c,by,bx)
  124. int l,c,bx,by ;
  125. {
  126.     WINDOW *tmp ;
  127.     WORD   i, j, nl, nc ;
  128.     char    *malloc() ;
  129.     
  130.     tmp = ( WINDOW * ) malloc(sizeof(WINDOW)) ;
  131.     if ( tmp == NULL )
  132.         {
  133.         ERR = 1 ;
  134.         OK = 0 ;
  135.         return(NULL) ;
  136.         } ;
  137.     tmp->_curx = 0 ;
  138.     tmp->_cury = 0 ;
  139.     tmp->_clear = 0 ;
  140.     tmp->_leave = 0 ;
  141.     tmp->_scroll = 0 ;
  142.     if ( l == 0 )
  143.         nl = LINES - by ;
  144.     else
  145.         nl = l ;
  146.     if ( c == 0 )
  147.         nc = COLS - bx ;
  148.     else
  149.         nc = c ;
  150.     if ( nl < 1 || nl > LINES || nc < 1 || nc > COLS )
  151.         {
  152.         free(tmp) ;
  153.         ERR = 1 ;
  154.         OK = 0 ;
  155.         return(NULL) ;
  156.         } ;
  157.     tmp->_maxy = nl - 1 ;
  158.     tmp->_maxx = nc - 1 ;
  159.     if ( nl == LINES && nc == COLS )
  160.         tmp->_flags = _FULLWIN ;
  161.     else
  162.         tmp->_flags = 0 ;
  163.     if ( by < 0 || by >= LINES || bx < 0 || bx >= COLS )
  164.         {
  165.         free(tmp) ;
  166.         ERR = 1 ;
  167.         OK = 0 ;
  168.         return(NULL) ;
  169.         } ;
  170.     tmp->_begy = by ;
  171.     tmp->_begx = bx ;
  172.     tmp->_y = ( WORD ** ) malloc(sizeof(WORD *)*(tmp->_maxy+1)) ;
  173.     if ( tmp->_y == NULL )
  174.         {
  175.         free(tmp) ;
  176.         ERR = 1 ;
  177.         OK = 0 ;
  178.         return(NULL) ;
  179.         } ;
  180.     tmp->_y[0] = ( WORD * ) malloc(sizeof(WORD)*(tmp->_maxy+1)*(tmp->_maxx+1)) ;
  181.     if ( tmp->_y[0] == NULL )
  182.         {
  183.         free(tmp->_y) ;
  184.         free(tmp) ;
  185.         ERR = 1 ;
  186.         OK = 0 ;
  187.         return(NULL) ;
  188.         } ;
  189.     for ( i = 1 ; i <= tmp->_maxy ; i++ )
  190.         tmp->_y[i] = tmp->_y[0] + i * ( tmp->_maxx + 1 ) ;
  191.     for ( i = 0 ; i <= tmp->_maxy ; i++ )
  192.         {
  193.         for ( j = 0 ; j <= tmp->_maxx ; j++ )
  194.             tmp->_y[i][j] = ' ' ;
  195.         } ;
  196. /* make everything changed on first update of tmp                            */
  197.     touchwin(tmp) ;
  198.     ERR = 0 ;
  199.     OK = 1 ;
  200.     return(tmp) ;
  201. }
  202. /* #]newwin:                                                                */
  203. /* #[delwin: delete a window                                                */
  204. delwin(w)
  205. WINDOW *w ;
  206. {
  207.     if ( w == NULL )
  208.         {
  209.         ERR = 1 ;
  210.         OK = 0 ;
  211.         return ;
  212.         } ;
  213.     if ( w->_flags & _SUBWIN )
  214.         free(w->_y) ;
  215.     else
  216.         {
  217.         free(w->_y[0]) ;
  218.         free(w->_y) ;
  219.         } ;
  220.     free(w) ;
  221.     ERR = 0 ;
  222.     OK = 1 ;
  223. }
  224. /* #]delwin:                                                                */
  225. /* #[mvwin: move window                                                        */
  226. mvwin(w,y,x)
  227. WINDOW *w ;
  228. int y,x ;
  229. {
  230.     if ( y < 0 || x < 0 || ( y + w->_maxy + 1 ) > LINES || ( x + w->_maxx + 1 ) > COLS )
  231.         {
  232.         ERR = 1 ;
  233.         OK = 0 ;
  234.         return ;
  235.         } ;
  236.     w->_begy = y ;
  237.     w->_begx = x ;
  238.     touchwin(w) ;
  239.     ERR = 0 ;
  240.     OK = 1 ;
  241. }
  242. /* #]mvwin:                                                                    */
  243. /* #[touchwin: touch a window                                                */
  244. touchwin(w)
  245. WINDOW *w ;
  246. {
  247.     WORD i,j ;
  248.     w->_firstch = w->_y[0] ;
  249.     w->_lastch = &(w->_y[w->_maxy][w->_maxx]) ;
  250.     for ( i = 0 ; i <= w->_maxy ; i++ )
  251.         for ( j = 0 ; j <= w->_maxx ; j++ )
  252.             w->_y[i][j] = w->_y[i][j] | TOUCHED ;
  253.     ERR = 0 ;
  254.     OK = 1 ;
  255. }
  256. /* #]touchwin:                                                                */
  257. /* #[subwin: create a sub-window                                            */
  258. WINDOW *subwin(w,l,c,by,bx)
  259. WINDOW *w ;
  260. int l,c,by,bx ;
  261. {
  262.     WINDOW *tmp ;
  263.     WORD   i, nl, nc ;
  264.     char    *malloc() ;
  265.     
  266. /* cannot take subwindows of curscr                                            */
  267.     if ( w == curscr )
  268.         {
  269.         ERR = 1 ;
  270.         OK = 0 ;
  271.         return(NULL) ;
  272.         } ;
  273.     tmp = ( WINDOW * ) malloc(sizeof(WINDOW)) ;
  274.     if ( tmp == NULL )
  275.         {
  276.         ERR = 1 ;
  277.         OK = 0 ;
  278.         return(NULL) ;
  279.         } ;
  280.     tmp->_curx = 0 ;
  281.     tmp->_cury = 0 ;
  282.     tmp->_clear = 0 ;
  283.     tmp->_leave = 0 ;
  284.     tmp->_scroll = 0 ;
  285.     if ( l == 0 )
  286.         nl = LINES - by ;
  287.     else
  288.         nl = l ;
  289.     if ( c == 0 )
  290.         nc = COLS - bx ;
  291.     else
  292.         nc = c ;
  293.     if ( l < 1 || l > (w->_maxy+1) || c < 1 || c > (w->_maxx+1) )
  294.         {
  295.         free(tmp) ;
  296.         ERR = 1 ;
  297.         OK = 0 ;
  298.         return(NULL) ;
  299.         } ;
  300.     tmp->_maxy = nl - 1 ;
  301.     tmp->_maxx = nc - 1 ;
  302.     if ( nl == LINES && nc == COLS )
  303.         tmp->_flags = _FULLWIN | _SUBWIN ;
  304.     else
  305.         tmp->_flags = _SUBWIN ;
  306.     if ( by < w->_begy || by >= (w->_maxy+w->_begy) ||
  307.          bx < w->_begx || bx >= (w->_maxx+w->_begx) )
  308.         {
  309.         free(tmp) ;
  310.         ERR = 1 ;
  311.         OK = 0 ;
  312.         return(NULL) ;
  313.         } ;
  314.     tmp->_begy = by ;
  315.     tmp->_begx = bx ;
  316.     tmp->_y = ( WORD ** ) malloc(sizeof(WORD *)*(tmp->_maxy+1)) ;
  317.     if ( tmp->_y == NULL )
  318.         {
  319.         free(tmp) ;
  320.         ERR = 1 ;
  321.         OK = 0 ;
  322.         return(NULL) ;
  323.         } ;
  324.     tmp->_y[0] = w->_y[0] + ( tmp->_begy - w->_begy ) * ( w->_maxx + 2 ) + ( tmp->_maxx - w->_maxx ) ;
  325.     for ( i = 1 ; i <= tmp->_maxy ; i++ )
  326.         tmp->_y[i] = tmp->_y[0] + i * ( w->_maxx + 2 ) ;
  327. /* make everything changed on first update of tmp                            */
  328.     touchwin(tmp) ;
  329.     ERR = 0 ;
  330.     OK = 1 ;
  331.     return(tmp) ;
  332. }
  333. /* #]subwin:                                                                */
  334. /* #[leaveok: tell curses where to leave the cursor after updating            */
  335. leaveok(w,f)
  336. WINDOW *w ;
  337. bool f ;
  338. {
  339.     w->_leave = f ;
  340.     ERR = 0 ;
  341.     OK = 1 ;
  342. }
  343. /* #]leaveok:                                                                */
  344. /* #[scrollok: tell curses it is ok to scroll the window                    */
  345. scrollok(w,f)
  346. WINDOW *w ;
  347. bool f ;
  348. {
  349.     w->_scroll = f ;
  350.     ERR = 0 ;
  351.     OK = 1 ;
  352. }
  353. /* #]scrollok:                                                                */
  354. /* #[nl: tell curses to map CR to CR,LF                                        */
  355. nl()
  356. {
  357.     _nlmap = 1 ;
  358.     ERR = 0 ;
  359.     OK = 1 ;
  360. }
  361. /* #]nl:                                                                    */
  362. /* #[nonl: tell curses not to map CR to CR,LF                                */
  363. nonl()
  364. {
  365.     _nlmap = 0 ;
  366.     ERR = 0 ;
  367.     OK = 1 ;
  368. }
  369. /* #]nonl:                                                                    */
  370. /* #[longname: return the full name of the terminal                         */
  371. /* always returns the contents of ttytype in name                            */
  372. longname(termbuf,name)
  373. char *termbuf, *name ;
  374. {
  375.     int i ;
  376.     
  377.     for ( i = 0 ; ttytype[i] != '\0' ; i++ )
  378.         name[i] = ttytype[i] ;
  379.     name[i] = '\0' ;
  380. }
  381. /* #]longname:                                                                */
  382. /* #]miscel:                                                                */
  383. /* #[output: output functions                                                */
  384. /* #[waddch: add a character to a window                                    */
  385. waddch(w,c)
  386. WINDOW *w ;
  387. char   c ;
  388. {
  389.     WORD i, tpos ;
  390.  
  391.     ERR = 0 ;
  392.     OK = 1 ;
  393.     if ( c >= 0x20 )
  394.         {
  395.         if ( w == curscr )
  396.             {
  397.             if ( ( w->_flags & _STANDOUT ))
  398.                 {
  399.                 w->_y[w->_cury][w->_curx] = c | STANDOUT | TOUCHED ;
  400.                 CONOUT('\033') ;
  401.                 CONOUT('p') ;
  402.                 CONOUT(c) ;
  403.                 CONOUT('\033') ;
  404.                 CONOUT('q') ;
  405.                 }
  406.             else
  407.                 {
  408.                 w->_y[w->_cury][w->_curx] = c | TOUCHED ;
  409.                 CONOUT(c) ;
  410.                 } ;
  411.             _csrx++ ;
  412.             }
  413.         else
  414.             {
  415.             if ( (w->_flags & _STANDOUT ))
  416.                 w->_y[w->_cury][w->_curx] = c | STANDOUT | TOUCHED ;
  417.             else
  418.                 w->_y[w->_cury][w->_curx] = c | TOUCHED ;
  419.             if ( w->_firstch == 0 )
  420.                 {
  421.                 w->_firstch = &(w->_y[w->_cury][w->_curx]) ;
  422.                 w->_lastch = w->_firstch ;
  423.                 }
  424.             else
  425.                 {
  426.                 if ( w->_firstch > &(w->_y[w->_cury][w->_curx]) )
  427.                     w->_firstch = &(w->_y[w->_cury][w->_curx]) ;
  428.                 else
  429.                     {
  430.                     if ( w->_lastch < &(w->_y[w->_cury][w->_curx]) )
  431.                         w->_lastch = &(w->_y[w->_cury][w->_curx]) ;
  432.                     } ;
  433.                 } ;
  434.             } ;
  435.         wmove(w,w->_cury,w->_curx+1) ;
  436.         }
  437.     else if ( c == '\n' )
  438.         {
  439.         wclrtoeol(w) ;
  440.         if ( _nlmap )
  441.             wmove(w,w->_cury+1,0) ;
  442.         else
  443.             wmove(w,w->_cury+1,w->_curx) ;
  444.         }
  445.     else if ( c == '\r' )
  446.         {
  447.         wmove(w,w->_cury,0) ;
  448.         }
  449.     else if ( c == '\t' )
  450.         {
  451.         tpos = ( w->_curx + w->_begx ) % 8 ;
  452.         tpos = ( tpos == 0 ) ? 8 : tpos ;
  453.         for ( i = 0 ; i < tpos ; i++ )
  454.             waddch(w,' ') ;
  455.         }
  456.     else
  457.         {
  458.         if ( w == curscr )
  459.             {
  460.             if ( ( w->_flags & _STANDOUT ))
  461.                 {
  462.                 w->_y[w->_cury][w->_curx] = c | STANDOUT | TOUCHED ;
  463.                 CONOUT('\033') ;
  464.                 CONOUT('p') ;
  465.                 CONOUT(c) ;
  466.                 CONOUT('\033') ;
  467.                 CONOUT('q') ;
  468.                 }
  469.             else
  470.                 {
  471.                 w->_y[w->_cury][w->_curx] = c | TOUCHED ;
  472.                 CONOUT(c) ;
  473.                 } ;
  474.             _csrx++ ;
  475.             }
  476.         else
  477.             {
  478.             if ( (w->_flags & _STANDOUT ))
  479.                 w->_y[w->_cury][w->_curx] = c | STANDOUT | TOUCHED ;
  480.             else
  481.                 w->_y[w->_cury][w->_curx] = c | TOUCHED ;
  482.             if ( w->_firstch == 0 )
  483.                 {
  484.                 w->_firstch = &(w->_y[w->_cury][w->_curx]) ;
  485.                 w->_lastch = w->_firstch ;
  486.                 }
  487.             else
  488.                 {
  489.                 if ( w->_firstch > &(w->_y[w->_cury][w->_curx]) )
  490.                     w->_firstch = &(w->_y[w->_cury][w->_curx]) ;
  491.                 else
  492.                     {
  493.                     if ( w->_lastch < &(w->_y[w->_cury][w->_curx]) )
  494.                         w->_lastch = &(w->_y[w->_cury][w->_curx]) ;
  495.                     } ;
  496.                 } ;
  497.             } ;
  498.         wmove(w,w->_cury,w->_curx+1) ;
  499.         } ;
  500. }
  501. /* #]waddch:                                                                */
  502. /* #[waddstr: add a string of characters to a window                        */
  503. waddstr(w,s)
  504. WINDOW *w ;
  505. char   *s ;
  506. {
  507.     WORD  i ;
  508.     
  509.     ERR = 0 ;
  510.     OK = 1 ;
  511.     for ( i = 0 ; s[i] != '\0' ; i++ )
  512.         waddch(w,s[i]) ;
  513. }
  514. /* #]waddstr:                                                                */
  515. /* #[box: draw a box around a window                                        */
  516. box(w,v,h)
  517. WINDOW *w ;
  518. char v,h ;
  519. {
  520.     WORD i ;
  521.     
  522.     ERR = 0 ;
  523.     OK = 1 ;
  524.     for ( i = 0 ; i <= w->_maxy ; i++ )
  525.         {
  526.         mvwaddch(w,i,0,v) ;
  527.         mvwaddch(w,i,w->_maxx,v) ;
  528.         } ;
  529.     for ( i = 1 ; i < w->_maxx ; i++ )
  530.         {
  531.         mvwaddch(w,0,i,h) ;
  532.         mvwaddch(w,w->_maxy,i,h) ;
  533.         } ;
  534. }
  535. /* #]box:                                                                    */
  536. /* #[wclear: clear a window                                                    */
  537. wclear(w)
  538. WINDOW *w ;
  539. {
  540.     ERR = 0 ;
  541.     OK = 1 ;
  542.     werase(w) ;
  543.     clearok(w,TRUE) ;
  544.     w->_curx = 0 ;
  545.     w->_cury = 0 ;
  546. }
  547. /* #]wclear:                                                                */
  548. /* #[wclrtobo: clear a window to the bottom                                    */
  549. wclrtobot(w)
  550. WINDOW *w ;
  551. {
  552.     WORD i,j ;
  553.  
  554.     ERR = 0 ;
  555.     OK = 1 ;
  556.     for ( i = w->_curx ; i <= w->_maxx ; i++ )
  557.         w->_y[w->_cury][i] = ' ' | TOUCHED ;
  558.     for ( i = w->_cury + 1 ; i <= w->_maxy ; i++ )
  559.         {
  560.         for ( j = 0 ; j <= w->_maxx ; j++ )
  561.             w->_y[i][j] = ' ' | TOUCHED ;
  562.         } ;
  563.     if ( w == curscr )
  564.         {
  565.         CONOUT('\033') ;
  566.         CONOUT('J') ;
  567.         }
  568.     else
  569.         {
  570.         if ( w->_firstch == 0 )
  571.             {
  572.             w->_firstch = &(w->_y[w->_cury][w->_curx]) ;
  573.             w->_lastch = &(w->_y[w->_maxy][w->_maxx]) ;
  574.             }
  575.         else
  576.             {
  577.             if ( w->_firstch > &(w->_y[w->_cury][w->_curx]) )
  578.                 w->_firstch = &(w->_y[w->_cury][w->_curx]) ;
  579.             w->_lastch = &(w->_y[w->_maxy][w->_maxx]) ;
  580.             } ;
  581.         } ;
  582. }
  583. /* #]wclrtobo:                                                                */
  584. /* #[wclrtoeo: clear a window to the end of the line                        */
  585. wclrtoeol(w)
  586. WINDOW *w ;
  587. {
  588.     WORD i ;
  589.  
  590.     ERR = 0 ;
  591.     OK = 1 ;
  592.     for ( i = w->_curx ; i <= w->_maxx ; i++ )
  593.         w->_y[w->_cury][i] = ' ' | TOUCHED ;
  594.     if ( w == curscr )
  595.         {
  596.         CONOUT('\033') ;
  597.         CONOUT('K') ;
  598.         }
  599.     else
  600.         {
  601.         if ( w->_firstch == 0 )
  602.             {
  603.             w->_firstch = &(w->_y[w->_cury][w->_curx]) ;
  604.             w->_lastch = &(w->_y[w->_cury][w->_maxx]) ;
  605.             }
  606.         else
  607.             {
  608.             if ( w->_firstch > &(w->_y[w->_cury][w->_curx]) )
  609.                 w->_firstch = &(w->_y[w->_cury][w->_curx]) ;
  610.             if ( w->_lastch < &(w->_y[w->_cury][w->_maxx]) )
  611.                 w->_lastch = &(w->_y[w->_cury][w->_maxx]) ;
  612.             } ;
  613.         } ;
  614. }
  615. /* #]wclrtoeo:                                                                */
  616. /* #[wdelch: delete a character on a window                                    */
  617. wdelch(w)
  618. WINDOW *w ;
  619. {
  620.     WORD ox, oy, i ;
  621.     
  622.     ERR = 0 ;
  623.     OK = 1 ;
  624.     ox = w->_curx ;
  625.     oy = w->_cury ;
  626.     for ( i = ox + 1 ; i <= w->_maxx ; i++ )
  627.         {
  628.         w->_y[oy][i-1] = w->_y[oy][i] | TOUCHED ;
  629.         } ;
  630.     w->_y[oy][w->_maxx] = ' ' | TOUCHED ;
  631.     w->_curx = ox ;
  632.     w->_cury = oy ;
  633.     if ( w == curscr )
  634.         {
  635.         CONOUT('\033') ;
  636.         CONOUT('K') ;
  637.         for ( i = w->_curx ; i <= w->_maxx ; i++ )
  638.             {
  639.             CONOUT((w->_y[w->_cury][i] & 0xff )) ;
  640.             _csrx++ ;
  641.             } ;
  642.         _movcur(w->_cury,w->_curx) ;
  643.         }
  644.     else
  645.         {
  646.         if ( w->_firstch == 0 )
  647.             {
  648.             w->_firstch = &(w->_y[w->_cury][w->_curx]) ;
  649.             w->_lastch = &(w->_y[w->_cury][w->_maxx]) ;
  650.             }
  651.         else
  652.             {
  653.             if ( w->_firstch > &(w->_y[w->_cury][w->_curx]) )
  654.                 w->_firstch = w->_y[w->_cury] ;
  655.             if ( w->_lastch < &(w->_y[w->_cury][w->_maxx]) )
  656.                 w->_lastch = &(w->_y[w->_cury][w->_maxx]) ;
  657.             } ;
  658.         } ;
  659. }
  660. /* #]wdelch:                                                                */
  661. /* #[wdeletel: delete a line from a window                                    */
  662. wdeleteln(w)
  663. WINDOW *w ;
  664. {
  665.     WORD i,j ;
  666.     
  667.     ERR = 0 ;
  668.     OK = 1 ;
  669.     for ( i = w->_cury + 1 ; i <= w->_maxy ; i++ )
  670.         {
  671.         for ( j = 0 ; j <= w->_maxx ; j++ )
  672.             w->_y[i-1][j] = w->_y[i][j] | TOUCHED ;
  673.         } ;
  674.     for ( j = 0 ; j <= w->_maxx ; j++ )
  675.         w->_y[w->_maxy][j] = ' ' | TOUCHED ;
  676.     if ( w == curscr )
  677.         {
  678.         CONOUT('\033') ;
  679.         CONOUT('M') ;
  680.         _csrx = 0 ;
  681.         _movcur(w->_cury,w->_curx) ;
  682.         }
  683.     else
  684.         {
  685.         if ( w->_firstch == 0 )
  686.             {
  687.             w->_firstch = w->_y[w->_cury] ;
  688.             w->_lastch = &(w->_y[w->_maxy][w->_maxx]) ;
  689.             }
  690.         else
  691.             {
  692.             if ( w->_firstch > w->_y[w->_cury] )
  693.                 w->_firstch = w->_y[w->_cury] ;
  694.             w->_lastch = &(w->_y[w->_maxy][w->_maxx]) ;
  695.             } ;
  696.         } ;
  697. }
  698. /* #]wdeletel:                                                                 */
  699. /* #[werase: erase a window                                                    */
  700. werase(w)
  701. WINDOW *w ;
  702. {
  703.     WORD i,j ;
  704.     
  705.     ERR = 0 ;
  706.     OK = 1 ;
  707.     for ( i = 0 ; i <= w->_maxy ; i++ )
  708.         {
  709.         for ( j = 0 ; j <= w->_maxx ; j++ )
  710.             w->_y[i][j] = ' ' | TOUCHED ;
  711.         } ;
  712.     if ( w == curscr )
  713.         {
  714.         CONOUT('\033') ;
  715.         CONOUT('E') ;
  716.         _csry = 0 ;
  717.         _csrx = 0 ;
  718.         _movcur(curscr->_cury,curscr->_curx) ;
  719.         }
  720.     else
  721.         {
  722.         w->_firstch = w->_y[0] ;
  723.         w->_lastch = &(w->_y[w->_maxy][w->_maxx]) ;
  724.         } ;
  725. }
  726. /* #]werase:                                                                */
  727. /* #[winsch: insert a character                                                */
  728. winsch(w,c)
  729. WINDOW *w ;
  730. char c ;
  731. {
  732.     WORD ox,oy,i ;
  733.     BYTE tstr[2] ;
  734.     
  735.     ERR = 0 ;
  736.     OK = 1 ;
  737.     ox = w->_curx ;
  738.     oy = w->_cury ;
  739.     for ( i = w->_maxx - 1 ; i >= ox ; --i )
  740.         {
  741.         w->_y[oy][i+1] = w->_y[oy][i] | TOUCHED ;
  742.         } ;
  743.     if ( w == curscr )
  744.         {
  745.         CONOUT('\033') ;
  746.         CONOUT('K') ;
  747.         for ( i = w->_curx ; i <= w->_maxx ; i++ )
  748.             {
  749.             CONOUT((w->_y[w->_cury][i] & 0xff )) ;
  750.             _csrx++ ;
  751.             } ;
  752.         _movcur(w->_cury,w->_curx) ;
  753.         }        
  754.     else
  755.         {
  756.         if ( w->_firstch == 0 )
  757.             {
  758.             w->_firstch = &(w->_y[w->_cury][w->_curx]) ;
  759.             w->_lastch = &(w->_y[w->_cury][w->_maxx]) ;
  760.             }
  761.         else
  762.             {
  763.             if ( w->_firstch > &(w->_y[w->_cury][w->_curx]) )
  764.                 w->_firstch = &(w->_y[w->_cury][w->_curx]) ;
  765.             if ( w->_lastch < &(w->_y[w->_cury][w->_maxx]) )
  766.                 w->_lastch = &(w->_y[w->_cury][w->_maxx]) ;
  767.             } ;
  768.         } ;
  769.     mvwaddch(w,oy,ox,c) ;
  770. }
  771. /* #]winsch:                                                                */
  772. /* #[winsertl: insert a line in a window                                    */
  773. winsertln(w)
  774. WINDOW *w ;
  775. {
  776.     WORD ox,oy,i,j ;
  777.     
  778.     ERR = 0 ;
  779.     OK = 1 ;
  780.     for ( i = w->_maxy - 1 ; i >= w->_cury ; --i )
  781.         {
  782.         for ( j = 0 ; j <= w->_maxx ; j++ )
  783.             w->_y[i+1][j] = w->_y[i][j] | TOUCHED ;
  784.         } ;
  785.     for ( j = 0 ; j <= w->_maxx ; j++ )
  786.         w->_y[w->_cury][j] = ' ' | TOUCHED ;
  787.     if ( w == curscr )
  788.         {
  789.         CONOUT('\033') ;
  790.         CONOUT('L') ;
  791.         _csrx = 0 ;
  792.         _movcur(w->_cury,w->_curx) ;
  793.         }
  794.     else
  795.         {
  796.         if ( w->_firstch == 0 )
  797.             w->_firstch = w->_y[w->_cury] ;
  798.         else
  799.             {
  800.             if ( w->_firstch > w->_y[w->_cury] )
  801.                 w->_firstch = w->_y[w->_cury] ;
  802.             } ;
  803.         w->_lastch = &(w->_y[w->_maxy][w->_maxx]) ;
  804.         } ;
  805. }
  806. /* #]winsertl:                                                                */
  807. /* #[wmove: move the cursor of the window to a location                        */
  808. wmove(w,y,x)
  809. WINDOW *w ;
  810. int y,x ;
  811. {
  812.     WORD i ;
  813.  
  814.     ERR = 0 ;
  815.     OK = 1 ;
  816.     if ( x < 0 )
  817.         {
  818.         w->_curx = 0 ;
  819.         ERR = 1 ;
  820.         OK = 0 ;
  821.         }
  822.     else
  823.         {
  824.         if ( x > w->_maxx )
  825.             {
  826.             w->_curx = w->_maxx ;
  827.             ERR = 1 ;
  828.             OK = 0 ;
  829.             }
  830.         else
  831.             w->_curx = x ;
  832.         } ;
  833.     if ( y < 0 )
  834.         {
  835.         w->_cury = 0 ;
  836.         ERR = 1 ;
  837.         OK = 0 ;
  838.         }
  839.     else
  840.         {
  841.         if ( y > w->_maxy )
  842.             {
  843.             if ( w->_scroll )
  844.                 {
  845.                 for ( i = w->_maxy ; i < y ; i++ )
  846.                     scroll(w) ;
  847.                 } ;
  848.             w->_cury = w->_maxy ;
  849.             ERR = 1 ;
  850.             OK = 0 ;
  851.             }
  852.         else
  853.             w->_cury = y ;
  854.         } ;
  855.     if ( w == curscr )
  856.         {
  857.         _movcur(curscr->_cury,curscr->_curx) ;
  858.         } ;
  859. }
  860. /* #]wmove:                                                                    */    
  861. /* #[woverlay: overlay two windows.                                            */
  862. woverlay(v,w)
  863. WINDOW *v, *w ;
  864. {
  865.     WORD i, j ;
  866.     
  867.     for ( i = 0 ; i <= w->_maxy && i <= v->_maxy ; i++ )
  868.         {
  869.         for ( j = 0 ; j <= w->_maxx && j <= v->_maxx ; j++ )
  870.             {
  871.             if ( ( v->_y[i][j] & 0xff ) == 0x20 )
  872.                 w->_y[i][j] = v->_y[i][j] | TOUCHED ;
  873.             } ;
  874.         } ;
  875.     if ( w == curscr )
  876.         wrefresh(curscr) ;
  877.     else
  878.         {
  879.         w->_firstch = w->_y[0] ;
  880.         w->_lastch = &(w->_y[w->_maxy][w->_maxx]) ;
  881.         } ;
  882. }
  883. /* #]woverlay:                                                                */
  884. /* #[overwrit: overwrite two windows.                                        */
  885. overwrite(v,w)
  886. WINDOW *v, *w ;
  887. {
  888.     WORD i, j ;
  889.     
  890.     for ( i = 0 ; i <= w->_maxy && i <= v->_maxy ; i++ )
  891.         {
  892.         for ( j = 0 ; j <= w->_maxx && j <= v->_maxx ; j++ )
  893.             {
  894.             w->_y[i][j] = v->_y[i][j] | TOUCHED ;
  895.             } ;
  896.         } ;
  897.     if ( w == curscr )
  898.         wrefresh(curscr) ;
  899.     else
  900.         {
  901.         w->_firstch = w->_y[0] ;
  902.         w->_lastch = &(w->_y[w->_maxy][w->_maxx]) ;
  903.         } ;
  904. }
  905. /* #]overwrit:                                                                */
  906. /* #[wstandou: set the standout flag for a window                            */
  907. wstandout(w)
  908. WINDOW *w ;
  909. {
  910.     w->_flags = w->_flags | _STANDOUT ;
  911.     ERR = 0 ;
  912.     OK = 1 ;
  913. }
  914. /* #]wstandou:                                                                */
  915. /* #[wstanden: end standout mode                                            */
  916. wstandend(w)
  917. WINDOW *w ;
  918. {
  919.     w->_flags = w->_flags & ( ~_STANDOUT) ;
  920.     ERR = 0 ;
  921.     OK = 1 ;
  922. }
  923. /* #]wstanden:                                                                */
  924. /* #]output:                                                                */
  925. /* #[input:    input functions                                                    */
  926. /* #[raw: set terminal in raw mode                                            */
  927. raw()
  928. {
  929. /*
  930.  * raw mode means : 
  931.  * when getting a character from the keyboard, return everything
  932.  * including keyboard shift state.
  933.  */
  934.   int    __sshft() ;
  935.   
  936.   if ( _modinp == RAW )
  937.       return ;
  938.   Supexec(__sshft) ;
  939.   _modinp = RAW ;
  940. }
  941. /* #]raw:                                                                    */
  942. /* #[noraw: reset terminal from raw mode into cooked mode                    */
  943. noraw()
  944. {
  945.     int __ushft() ;
  946.     if ( _modinp != RAW )
  947.         return ;
  948.     Supexec(__ushft) ;
  949.     _modinp = COOKED ;
  950. }
  951. /* #]noraw:                                                                    */
  952. /* #[__sshft: set terminal to return keyboard shift state                    */
  953. /* execute in supervisor mode only                                            */
  954. __sshft()
  955. {
  956.     int ov, nv ;
  957.     
  958.     ov = CONTERM ;
  959.     nv = ov | 0x08 ;
  960.     CONTERM = nv ;
  961. }
  962. /* #]__sshft:                                                                */
  963. /* #[__ushft: set terminal to not return keyboard shift state                */
  964. /* execute in supervisor mode only                                            */
  965. __ushft()
  966. {
  967.     int ov, nv ;
  968.     
  969.     ov = CONTERM ;
  970.     nv = ov & ~0x08 ;
  971.     CONTERM = nv ;
  972. }
  973. /* #]__ushft:                                                                */
  974. /* #[crmode: set terminal in cbreak mode                                    */
  975. /*
  976.  * cbreak mode means for the atari ;
  977.  * return both keyboard scan code as well as the character value.
  978.  * kill the process with a process terminate -1 as soons as a control C is met
  979.  * control D is also recognized to be the EOF.
  980.  */
  981. crmode()
  982. {
  983.     if ( _modinp == CBREAK )
  984.         return ;
  985.     if ( _modinp == RAW )
  986.         noraw() ;
  987.     _modinp = CBREAK ;
  988. }
  989. /* #]crmode:                                                                */
  990. /* #[nocrmode: reset terminal from cbreak into cooked mode                    */        
  991. nocrmode()
  992. {
  993.     if ( _modinp != CBREAK )
  994.         return ;
  995.     _modinp = COOKED ;
  996. }
  997. /* #]nocrmode:                                                                */
  998. /* #[echo: set curses to echo characters on input                            */
  999. echo()
  1000. {
  1001.     _doecho = TRUE ;
  1002.     ERR = 0 ;
  1003.     OK = 1 ;
  1004. }
  1005. /* #]echo:                                                                    */
  1006. /* #[noecho: set curses not to echo characters on input                        */
  1007. noecho()
  1008. {
  1009.     _doecho = FALSE ;
  1010.     ERR = 0 ;
  1011.     OK = 1 ;
  1012. }
  1013. /* #]noecho:                                                                */
  1014. /* #[wgetch: get a character from the terminal                                */
  1015. /* WARNING : wgetch returns a 32-bit value, not a char although only        */
  1016. /* the lowest 8 bits may actually be transmitted.                            */
  1017. wgetch(w)
  1018. WINDOW *w ;
  1019. {
  1020.     bool reset ;
  1021.     LONG    retval ;
  1022.  
  1023.     reset = FALSE ;
  1024.     if ( _modinp == COOKED && _doecho == TRUE )
  1025.         {
  1026.         reset = TRUE ;
  1027.         crmode() ;
  1028.         } ;
  1029.     CONOUT('\033') ;
  1030.     CONOUT('e') ;
  1031.     switch ( _modinp )
  1032.         {
  1033.         case COOKED:
  1034.             while ( !Cconis() ) ;
  1035.             retval = Cnecin() ;
  1036.             retval = retval & 0x00ff ;
  1037. /* kill process on control C                                                */
  1038.             if ( retval == 0x03 )
  1039.                 Pterm(-1L) ;
  1040.             break ;
  1041.         case CBREAK:
  1042.             while ( !Cconis() ) ;
  1043.             retval = Cnecin() ;
  1044. /* kill process on control C                                                */
  1045.             if ( ( retval & 0x00ff ) == 0x03 )
  1046.                 Pterm(-1L) ;
  1047.             break ;
  1048.         case RAW:
  1049.             while ( !Cconis() ) ;
  1050.             retval = Crawcin() ;
  1051.             break ;
  1052.         } ;
  1053.     CONOUT('\033') ;
  1054.     CONOUT('f') ;
  1055.     if ( _doecho )
  1056.         waddch(w,(char ) ( 0x00ff & retval )) ;
  1057.     if ( reset )
  1058.         nocrmode() ;
  1059.     return(retval) ;
  1060. }
  1061. /* #]wgetch:                                                                */
  1062. /* #[wgetstr: get a string from the terminal                                */
  1063. wgetstr(w,s)
  1064. WINDOW *w ;
  1065. char *s ;
  1066. {
  1067.     WORD ox, oy ;
  1068.     bool reset, end ;
  1069.     char c ;
  1070.     int i ;
  1071. /*    LONG wgetch() ; */
  1072.     
  1073.     reset = FALSE ;
  1074.     getyx(w,oy,ox) ;
  1075.     if ( _modinp == COOKED && _doecho == TRUE )
  1076.         {
  1077.         reset = TRUE ;
  1078.         _doecho = FALSE ;
  1079.         } ;
  1080.     i = 0 ;
  1081.     for ( end = FALSE ; !end ; i++ )
  1082.         { 
  1083.         wrefresh(w);
  1084.         switch ( _modinp )
  1085.             {
  1086.             case COOKED:
  1087.                 c = ( char ) wgetch(w) ;
  1088.                 if ( c == 0x0d || c == 0x0a || c == 0x04 || c == 0 )
  1089.                     {
  1090.                     s[i] = '\0' ;
  1091.                     end = TRUE ;
  1092.                     break ;
  1093.                     } ;
  1094. /* receive a backspace */
  1095.                 if ( c == 0x08 ) {
  1096.                     if ( i != 0 )
  1097.                         {
  1098.                         --i ;
  1099.                         s[i] = 0 ;
  1100.                         if ( reset ) {
  1101.                             int    x, y;
  1102.                             getyx(w, y, x);
  1103.                             mvwaddch(w,y,x-1,' ');
  1104.                             wmove(w, y, x-1);
  1105. /*
  1106.                             mvwaddstr(w,oy,ox,s) ;
  1107. */
  1108.                         }
  1109.                     }
  1110.                     i--;
  1111.                     break;
  1112.                 }
  1113. /* receive control U or line kill                                             */
  1114.                 if ( c == 0x13 )
  1115.                     {
  1116.                     i = 0 ;
  1117.                     if ( reset )
  1118.                         wmove(w,oy,ox) ;
  1119.                     break ;
  1120.                     } ;
  1121.                 s[i] = c ;
  1122.                 if (reset)
  1123.                     waddch(w,c) ;
  1124.                 break ;
  1125.             case CBREAK:
  1126.                 c = ( char ) wgetch(w) ;
  1127.                 if ( c == 0x0d || c == 0x0a || c == 0x04 || c == 0 )
  1128.                     {
  1129.                     s[i] = '\0' ;
  1130.                     end = TRUE ;
  1131.                     break ;
  1132.                     } ;
  1133.                 s[i] = c ;
  1134.                 break ;
  1135.             case RAW:
  1136.                 c = ( char ) wgetch(w) ;
  1137.                 if ( c == 0x0d || c == 0x0a || c == 0x04 || c == 0 )
  1138.                     {
  1139.                     s[i] = '\0' ;
  1140.                     end = TRUE ;
  1141.                     break ;
  1142.                     } ;
  1143.                 s[i] = c ;
  1144.                 break ;
  1145.             } ;
  1146.         } ;
  1147.     if ( reset )
  1148.         _doecho = TRUE ;
  1149. }
  1150. /* #]wgetstr:                                                                */
  1151. /* #]input:                                                                 */
  1152. /* #[wrefresh: refresh a window on the screen                                */
  1153. wrefresh(w)
  1154. WINDOW *w ;
  1155. {
  1156.     WORD i,j,k,l ;
  1157.     WORD c, *ptr ;
  1158.     
  1159.     ERR = 0 ;
  1160.     OK = 1 ;
  1161.     if ( w != curscr && curscr->_clear )
  1162.         {
  1163.         CONOUT('\033') ;
  1164.         CONOUT('E') ;
  1165.         _csry = 0 ;
  1166.         _csrx = 0 ;
  1167.         for ( i = 0 ; i < LINES ; i++ )
  1168.             {
  1169.             for ( j = 0 ; j < COLS ; j++ )
  1170.                 curscr->_y[i][j] = ' ' ;
  1171.             } ;
  1172.         curscr->_clear = 0 ;
  1173.         } ;
  1174.     if ( w->_clear )
  1175.         {
  1176.         if ( ( w->_flags & _FULLWIN ) )
  1177.             {
  1178.             CONOUT('\033') ;
  1179.             CONOUT('E') ;
  1180.             _csry = 0 ;
  1181.             _csrx = 0 ;
  1182.             for ( i = 0 ; i < LINES ; i++ )
  1183.                 {
  1184.                 for ( j = 0 ; j < COLS ; j++ )
  1185.                     curscr->_y[i][j] = ' ' ;
  1186.                 } ;
  1187.             } ;
  1188.         w->_firstch = w->_y[0] ;
  1189.         w->_lastch = &(w->_y[w->_maxy][w->_maxx]) ;
  1190.         w->_clear = 0 ;
  1191.         } ;
  1192.     if ( w != curscr )
  1193.         {
  1194.         if ( w->_firstch != 0 )
  1195.             {
  1196.             if ( w->_flags & _SUBWIN )
  1197.                 {
  1198.                 for ( i = 0 ; i <= w->_maxy ; i++ )
  1199.                     {
  1200.                     ptr = w->_y[i] ;
  1201.                     if ( ptr >= w->_firstch && ptr <= w->_lastch )
  1202.                         {
  1203.                         for ( j = 0 ; j <= w->_maxx ; j++ )
  1204.                             {
  1205.                             c = ptr[j] ;
  1206.                             k = i + w->_begy ;
  1207.                             l = j + w->_begx ;
  1208.                             if ( ( c & TOUCHED ) && ( k >= 0 && k < LINES && l >= 0 && l < COLS ) )
  1209.                                 {
  1210.                                 ptr[j] = c & ~TOUCHED ;
  1211.                                 if ( ( curscr->_y[k][l] & 0x01ff ) != ( c & 0x01ff ) )
  1212.                                     {
  1213.                                     curscr->_y[k][l] = c ;
  1214.                                     _movcur(k,l) ;
  1215.                                     if ( ( c & STANDOUT ) )
  1216.                                         {
  1217.                                         CONOUT('\033') ;
  1218.                                         CONOUT('p') ;
  1219.                                         CONOUT((c & 0xff)) ;
  1220.                                         CONOUT('\033') ;
  1221.                                         CONOUT('q') ;
  1222.                                         }
  1223.                                     else
  1224.                                         {
  1225.                                         CONOUT(( c & 0xff )) ;
  1226.                                         } ;
  1227.                                     _csry = k ;
  1228.                                     _csrx = l + 1 ;
  1229.                                     } ;
  1230.                                 } ;
  1231.                             } ;
  1232.                         } ;
  1233.                     } ;
  1234.                 }
  1235.             else
  1236.                 {
  1237.                 for ( ptr = w->_firstch ; ptr <= w->_lastch ; ptr++ )
  1238.                     {
  1239.                     c = *ptr ;
  1240.                     if ( c & TOUCHED )
  1241.                         {
  1242.                         k = ( WORD ) ( ptr - w->_y[0] ) ;
  1243.                         k = k / (  w->_maxx + 1 ) ;
  1244.                         l = ( WORD ) ( ptr - w->_y[k] ) + w->_begx ;
  1245.                         k = k + w->_begy ;
  1246.                         if ( k >= 0 && k < LINES && l >= 0 && l < COLS ) 
  1247.                             {
  1248.                             *ptr = c & ~TOUCHED ;
  1249.                             if ( ( curscr->_y[k][l] & 0x01ff ) != ( c & 0x01ff ) )
  1250.                                 {
  1251.                                 curscr->_y[k][l] = c ;
  1252.                                 _movcur(k,l) ;
  1253.                                 if ( ( c & STANDOUT ) )
  1254.                                     {
  1255.                                     CONOUT('\033') ;
  1256.                                     CONOUT('p') ;
  1257.                                     CONOUT((c & 0xff)) ;
  1258.                                     CONOUT('\033') ;
  1259.                                     CONOUT('q') ;
  1260.                                     }
  1261.                                 else
  1262.                                     {
  1263.                                     CONOUT(( c & 0xff )) ;
  1264.                                     } ;
  1265.                                 _csry = k ;
  1266.                                 _csrx = l + 1 ;
  1267.                                 } ;
  1268.                             } ;
  1269.                         } ;
  1270.                     } ;
  1271.                 } ;
  1272.             w->_firstch = 0 ;
  1273.             w->_lastch = 0 ;
  1274.             if ( w->_leave )
  1275.                 {
  1276.                 w->_curx = _csrx - w->_begx ;
  1277.                 w->_cury = _csry - w->_begy ;
  1278.                 curscr->_cury = _csry ;
  1279.                 curscr->_curx = _csrx ;
  1280.                 }
  1281.             else
  1282.                 {
  1283.                 curscr->_cury = w->_cury + w->_begy ;
  1284.                 curscr->_curx = w->_curx + w->_begx ;
  1285.                 _movcur(curscr->_cury, curscr->_curx) ;
  1286.                 } ;
  1287.             }
  1288.         else
  1289.             {
  1290.             curscr->_cury = w->_cury + w->_begy ;
  1291.             curscr->_curx = w->_curx + w->_begx ;
  1292.             _movcur(curscr->_cury, curscr->_curx) ;
  1293.             } ;
  1294.         }
  1295.     else
  1296.         {
  1297.         CONOUT('\033') ;
  1298.         CONOUT('H') ;
  1299.         _csry = 0 ;
  1300.         _csrx = 0 ;
  1301.         for ( i = 0 ; i < LINES ; i++ )
  1302.             {
  1303.             for ( j = 0 ; j < COLS ; j++ )
  1304.                 {
  1305.                 c = w->_y[i][j] ;
  1306.                 if ( ( c & STANDOUT ) )
  1307.                     {
  1308.                     CONOUT('\033') ;
  1309.                     CONOUT('p') ;
  1310.                     CONOUT((c & 0xff)) ;
  1311.                     CONOUT('\033') ;
  1312.                     CONOUT('q') ;
  1313.                     }
  1314.                 else
  1315.                     {
  1316.                     CONOUT((c & 0xff)) ;
  1317.                     } ;
  1318.                 _csrx++ ;
  1319.                 } ;
  1320.             _movcur(i+1,0) ;
  1321.             } ;
  1322.         _movcur( curscr->_cury, curscr->_curx) ; 
  1323.         } ;
  1324. }
  1325. /* #]wrefresh:                                                                */
  1326. /* #[detail: detail functions of curses                                        */
  1327. /* #[mvcur: move cursor in standard curses manner                            */
  1328. mvcur(ly,lx,ny,nx)
  1329. int ly,lx,ny,nx ;
  1330. {
  1331.     _movcur((WORD) ny,( WORD) nx) ;
  1332. }
  1333. /* #]mvcur:                                                                    */
  1334. /* #[_movcur: move cursor                                                    */
  1335. _movcur(y,x)
  1336. WORD y,x ;
  1337. {
  1338.     if ( _csry == y && _csrx == x )
  1339.         return ;
  1340.     CONOUT('\033') ;
  1341.     CONOUT('Y') ;
  1342.     CONOUT(y+' ') ;
  1343.     CONOUT(x+' ') ;
  1344.     _csry = y ;
  1345.     _csrx = x ;
  1346. }
  1347. /* #]_movcur:                                                                */
  1348. /* #[scroll: scroll a window upward one line                                */
  1349. scroll(w)
  1350. WINDOW *w ;
  1351. {
  1352.     WORD i,j ;
  1353.     
  1354.     ERR = 0 ;
  1355.     OK = 1 ;
  1356.     for ( i = 0 ; i < w->_maxy ; i++ )
  1357.         for ( j = 0 ; j <= w->_maxx ; j++ )
  1358.             w->_y[i][j] = w->_y[i+1][j] ;
  1359.     for ( i = 0 ; i <= w->_maxx ; i++ )
  1360.         w->_y[w->_maxy][i] = ' ' ;
  1361.     if ( w == curscr )
  1362.         wrefresh(curscr) ;
  1363.     else
  1364.         {
  1365.         w->_firstch = w->_y[0] ;
  1366.         w->_lastch = &(w->_y[w->_maxy][w->_maxx]) ;
  1367.         } ;
  1368. }
  1369. /* #]scroll:                                                                */
  1370. /* #]detail:                                                                */
  1371. /* #]curses:                                                                */
  1372.  
  1373. /*
  1374.  * Extra stuff added - tony
  1375.  */
  1376.  
  1377. printw(format, a1, a2, a3, a4, a5, a6, a7, a8, a9)
  1378. char    *format;
  1379. int    a1, a2, a3, a4, a5, a6, a7, a8, a9;
  1380. {
  1381.     char    lbuf[256];
  1382.  
  1383.     sprintf(lbuf, format, a1, a2, a3, a4, a5, a6, a7, a8, a9);
  1384.     addstr(lbuf);
  1385. }
  1386.  
  1387. scanw(format, a1, a2, a3, a4, a5, a6, a7, a8, a9)
  1388. char    *format;
  1389. int    a1, a2, a3, a4, a5, a6, a7, a8, a9;
  1390. {
  1391.     char    lbuf[256];
  1392.  
  1393.     echo();
  1394.     getstr(lbuf);
  1395.     sscanf(lbuf, format, a1, a2, a3, a4, a5, a6, a7, a8, a9);
  1396. }
  1397.