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