home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / the25.zip / thesrc251.zip / cursor.c < prev    next >
C/C++ Source or Header  |  1998-07-24  |  70KB  |  1,822 lines

  1. /***********************************************************************/
  2. /* CURSOR.C - CURSOR commands                                          */
  3. /* This file contains all commands that can be assigned to function    */
  4. /* keys or typed on the command line.                                  */
  5. /***********************************************************************/
  6. /*
  7.  * THE - The Hessling Editor. A text editor similar to VM/CMS xedit.
  8.  * Copyright (C) 1991-1997 Mark Hessling
  9.  *
  10.  * This program is free software; you can redistribute it and/or
  11.  * modify it under the terms of the GNU General Public License as
  12.  * published by the Free Software Foundation; either version 2 of
  13.  * the License, or any later version.
  14.  *
  15.  * This program is distributed in the hope that it will be useful,
  16.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18.  * General Public License for more details.
  19.  *
  20.  * You should have received a copy of the GNU General Public License
  21.  * along with this program; if not, write to:
  22.  *
  23.  *    The Free Software Foundation, Inc.
  24.  *    675 Mass Ave,
  25.  *    Cambridge, MA 02139 USA.
  26.  *
  27.  *
  28.  * If you make modifications to this software that you feel increases
  29.  * it usefulness for the rest of the community, please email the
  30.  * changes, enhancements, bug fixes as well as any and all ideas to me.
  31.  * This software is going to be maintained and enhanced as deemed
  32.  * necessary by the community.
  33.  *
  34.  * Mark Hessling                 Email:             M.Hessling@qut.edu.au
  35.  * PO Box 203                    Phone:                    +617 3802 0800
  36.  * Bellara                       http://www.gu.edu.au/gext/the/markh.html
  37.  * QLD 4507                      **** Maintainer PDCurses & REXX/SQL ****
  38.  * Australia                     ************* Author of THE ************
  39.  */
  40.  
  41. /*
  42. $Id: cursor.c 2.1 1995/06/24 16:29:25 MH Rel MH $
  43. */
  44.  
  45. #include <the.h>
  46. #include <proto.h>
  47.  
  48. /***********************************************************************/
  49. #ifdef HAVE_PROTO
  50. short cursor_cmdline(short col)
  51. #else
  52. short cursor_cmdline(col)
  53. short col;
  54. #endif
  55. /***********************************************************************/
  56. {
  57. /*-------------------------- external data ----------------------------*/
  58.  extern bool in_readv;
  59. /*--------------------------- local data ------------------------------*/
  60.  short rc=RC_OK;
  61. /*--------------------------- processing ------------------------------*/
  62. #ifdef TRACE
  63.  trace_function("cursor.c:  cursor_cmdline");
  64. #endif
  65. /*---------------------------------------------------------------------*/
  66. /* If in READV CMDLINE, return without doing anything                  */
  67. /*---------------------------------------------------------------------*/
  68.  if (in_readv)
  69.    {
  70. #ifdef TRACE
  71.     trace_return();
  72. #endif
  73.     return(RC_OK);
  74.    }
  75. /*---------------------------------------------------------------------*/
  76. /* If CMDLINE is OFF return without doing anything.                    */
  77. /*---------------------------------------------------------------------*/
  78.  if (CURRENT_WINDOW_COMMAND == (WINDOW *)NULL)
  79.    {
  80. #ifdef TRACE
  81.     trace_return();
  82. #endif
  83.     return(rc);
  84.    }
  85.  if (CURRENT_VIEW->current_window != WINDOW_COMMAND)
  86.    {
  87.     CURRENT_VIEW->previous_window = CURRENT_VIEW->current_window;
  88.     post_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line,(LINE *)NULL,TRUE);
  89.     CURRENT_VIEW->current_window = WINDOW_COMMAND;
  90.    }
  91.  wmove(CURRENT_WINDOW,0,col-1);
  92.  
  93. #ifdef TRACE
  94.  trace_return();
  95. #endif
  96.  return(rc);
  97. }
  98. /***********************************************************************/
  99. #ifdef HAVE_PROTO
  100. short cursor_column(void)
  101. #else
  102. short cursor_column()
  103. #endif
  104. /***********************************************************************/
  105. {
  106. /*------------------------- external data -----------------------------*/
  107.  extern bool in_readv;
  108. /*--------------------------- local data ------------------------------*/
  109.  short rc=RC_OK;
  110.  unsigned short x=0,y=0;
  111. /*--------------------------- processing ------------------------------*/
  112. #ifdef TRACE
  113.  trace_function("cursor.c:  cursor_column");
  114. #endif
  115. /*---------------------------------------------------------------------*/
  116. /* If in READV CMDLINE, return without doing anything                  */
  117. /*---------------------------------------------------------------------*/
  118.  if (in_readv)
  119.    {
  120. #ifdef TRACE
  121.     trace_return();
  122. #endif
  123.     return(RC_OK);
  124.    }
  125.  switch(CURRENT_VIEW->current_window)
  126.    {
  127.     case WINDOW_COMMAND:
  128.          rc = cursor_home(FALSE);
  129.          break;
  130.     case WINDOW_PREFIX:
  131.          getyx(CURRENT_WINDOW,y,x);
  132.          CURRENT_VIEW->current_window = WINDOW_FILEAREA;
  133.          wmove(CURRENT_WINDOW,y,0);
  134.          break;
  135.    }
  136.  rc = execute_move_cursor(CURRENT_VIEW->current_column-1);
  137. #ifdef TRACE
  138.  trace_return();
  139. #endif
  140.  return(rc);
  141. }
  142. /***********************************************************************/
  143. #ifdef HAVE_PROTO
  144. short cursor_down(bool escreen)
  145. #else
  146. short cursor_down(escreen)
  147. bool escreen;
  148. #endif
  149. /***********************************************************************/
  150. {
  151. /*------------------------- external data -----------------------------*/
  152.  extern CHARTYPE CMDARROWSTABCMDx;
  153.  extern bool in_readv;
  154. /*--------------------------- local data ------------------------------*/
  155.  short rc=RC_OK;
  156. /*--------------------------- processing ------------------------------*/
  157. #ifdef TRACE
  158.  trace_function("cursor.c:  cursor_down");
  159. #endif
  160. /*---------------------------------------------------------------------*/
  161. /* If in READV CMDLINE, return without doing anything                  */
  162. /*---------------------------------------------------------------------*/
  163.  if (in_readv)
  164.    {
  165. #ifdef TRACE
  166.     trace_return();
  167. #endif
  168.     return(RC_OK);
  169.    }
  170.  switch(CURRENT_VIEW->current_window)
  171.    {
  172.     case WINDOW_PREFIX:
  173.     case WINDOW_FILEAREA:
  174.          rc = scroll_line(DIRECTION_FORWARD,1L,FALSE,escreen);
  175.          break;
  176.     case WINDOW_COMMAND:
  177. /*---------------------------------------------------------------------*/
  178. /* Cycle forward  through the command list or tab to first line.       */
  179. /*---------------------------------------------------------------------*/
  180.          if (CMDARROWSTABCMDx)
  181.             rc = Sos_topedge((CHARTYPE *)"");
  182.          else
  183.             rc = Retrieve((CHARTYPE *)"+");
  184.          break;
  185.     default:
  186.          display_error(2,(CHARTYPE *)"",FALSE);
  187.          break;
  188.    }
  189. #ifdef TRACE
  190.  trace_return();
  191. #endif
  192.  return(rc);
  193. }
  194. /***********************************************************************/
  195. #ifdef HAVE_PROTO
  196. short cursor_file(LINETYPE line,LENGTHTYPE col)
  197. #else
  198. short cursor_file(line,col)
  199. LINETYPE line;
  200. LENGTHTYPE col;
  201. #endif
  202. /***********************************************************************/
  203. {
  204. /*-------------------------- external data ----------------------------*/
  205.  extern bool in_readv;
  206. /*--------------------------- local data ------------------------------*/
  207.  short rc=RC_OK;
  208.  unsigned short y=0,x=0;
  209. /*--------------------------- processing ------------------------------*/
  210. #ifdef TRACE
  211.  trace_function("cursor.c:  cursor_file");
  212. #endif
  213. /*---------------------------------------------------------------------*/
  214. /* If in READV CMDLINE, return without doing anything                  */
  215. /*---------------------------------------------------------------------*/
  216.  if (in_readv)
  217.    {
  218. #ifdef TRACE
  219.     trace_return();
  220. #endif
  221.     return(RC_OK);
  222.    }
  223. /*---------------------------------------------------------------------*/
  224. /* If line is not in display, error.                                   */
  225. /*---------------------------------------------------------------------*/
  226.  if (!line_in_view(current_screen,line))
  227.    {
  228.     display_error(63,(CHARTYPE *)"",FALSE);
  229. #ifdef TRACE
  230.     trace_return();
  231. #endif
  232.     return(RC_INVALID_OPERAND);
  233.    }
  234. /*---------------------------------------------------------------------*/
  235. /* If column is not 0 and not in display, error.                       */
  236. /*---------------------------------------------------------------------*/
  237.  if (col == 0)
  238.     x = 1;
  239.  else
  240.    {
  241.     if (!column_in_view(current_screen,col-1))
  242.       {
  243.        display_error(63,(CHARTYPE *)"",FALSE);
  244. #ifdef TRACE
  245.        trace_return();
  246. #endif
  247.        return(RC_INVALID_OPERAND);
  248.       }
  249.     x = (LENGTHTYPE)((LINETYPE)col - (LINETYPE)CURRENT_VIEW->verify_col + 1);
  250.    }
  251.  y = get_row_for_focus_line(current_screen,line,CURRENT_VIEW->current_line);
  252.  rc = cursor_move(FALSE,y+1,x);
  253. #ifdef TRACE
  254.  trace_return();
  255. #endif
  256.  return(rc);
  257. }
  258. /***********************************************************************/
  259. #ifdef HAVE_PROTO
  260. short cursor_home(bool save)
  261. #else
  262. short cursor_home(save)
  263. bool save;
  264. #endif
  265. /***********************************************************************/
  266. {
  267. /*-------------------------- external data ----------------------------*/
  268.  extern bool in_readv;
  269. /*--------------------------- local data ------------------------------*/
  270.  CHARTYPE last_win=0;
  271.  unsigned short x=0,y=0;
  272.  short rc=RC_OK;
  273. /*--------------------------- processing ------------------------------*/
  274. #ifdef TRACE
  275.  trace_function("cursor.c:  cursor_home");
  276. #endif
  277. /*---------------------------------------------------------------------*/
  278. /* If CMDLINE is OFF or in READV CMDLINE, return without doing anything*/
  279. /*---------------------------------------------------------------------*/
  280.  if (CURRENT_WINDOW_COMMAND == (WINDOW *)NULL
  281.  ||  in_readv)
  282.    {
  283. #ifdef TRACE
  284.     trace_return();
  285. #endif
  286.     return(rc);
  287.    }
  288.  last_win = CURRENT_VIEW->previous_window;
  289.  CURRENT_VIEW->previous_window =
  290.               CURRENT_VIEW->current_window;
  291.  if (CURRENT_VIEW->current_window != WINDOW_COMMAND)
  292.    {
  293.     post_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line,(LINE *)NULL,TRUE);
  294.     CURRENT_VIEW->current_window = WINDOW_COMMAND;
  295.     wmove(CURRENT_WINDOW,0,0);
  296.    }
  297.  else
  298.    {
  299.     if (!line_in_view(current_screen,CURRENT_VIEW->focus_line))
  300.        CURRENT_VIEW->focus_line = CURRENT_VIEW->current_line;
  301.     pre_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line,(LINE *)NULL);
  302.     if (save)
  303.        CURRENT_VIEW->current_window = last_win;
  304.     else
  305.        CURRENT_VIEW->current_window = WINDOW_FILEAREA;
  306.     getyx(CURRENT_WINDOW,y,x);
  307.     y = get_row_for_focus_line(current_screen,CURRENT_VIEW->focus_line,
  308.                                CURRENT_VIEW->current_row);
  309. #if 0
  310.     if (CURRENT_VIEW->current_window == WINDOW_PREFIX
  311.     &&  (CURRENT_VIEW->prefix&PREFIX_LOCATION_MASK) == PREFIX_RIGHT
  312.     &&  x < CURRENT_VIEW->prefix_gap)
  313.        x = CURRENT_VIEW->prefix_gap;
  314.     if (CURRENT_VIEW->current_window == WINDOW_PREFIX
  315.     &&  (CURRENT_VIEW->prefix&PREFIX_LOCATION_MASK) == PREFIX_LEFT
  316.     &&  x > CURRENT_VIEW->prefix_width-CURRENT_VIEW->prefix_gap-1)
  317.        x = CURRENT_VIEW->prefix_width-CURRENT_VIEW->prefix_gap-1;
  318. #endif
  319.     wmove(CURRENT_WINDOW,y,x);
  320.    }
  321.  build_screen(current_screen);
  322. #ifdef TRACE
  323.  trace_return();
  324. #endif
  325.  return(rc);
  326. }
  327. /***********************************************************************/
  328. #ifdef HAVE_PROTO
  329. short cursor_left(bool escreen,bool kedit_defaults)
  330. #else
  331. short cursor_left(escreen,kedit_defaults)
  332. bool escreen,kedit_defaults;
  333. #endif
  334. /***********************************************************************/
  335. {
  336. /*------------------------- external data -----------------------------*/
  337. /*--------------------------- local data ------------------------------*/
  338.  unsigned short x=0,y=0;
  339.  short col=0,old_col=0;
  340.  short rc=RC_OK;
  341. /*--------------------------- processing ------------------------------*/
  342. #ifdef TRACE
  343.  trace_function("cursor.c:  cursor_left");
  344. #endif
  345. /*---------------------------------------------------------------------*/
  346. /* The following should be a temporary fix for KEDIT compatability...  */
  347. /*---------------------------------------------------------------------*/
  348.  if (CURRENT_VIEW->prefix
  349.  &&  kedit_defaults)
  350.     escreen = FALSE;
  351.  getyx(CURRENT_WINDOW,y,x);
  352. /*---------------------------------------------------------------------*/
  353. /* For all windows, if we are not at left column, move 1 pos to left.  */
  354. /*---------------------------------------------------------------------*/
  355.  if (x > 0)
  356.    {
  357.     wmove(CURRENT_WINDOW,y,x-1);
  358. #ifdef TRACE
  359.     trace_return();
  360. #endif
  361.     return(RC_OK);
  362.    }
  363. /*---------------------------------------------------------------------*/
  364. /* For all windows, determine if CMDARROWSTABLRx is set for tabbing or */
  365. /* scrolling and act accordingly.                                      */
  366. /*---------------------------------------------------------------------*/
  367.  switch(CURRENT_VIEW->current_window)
  368.    {
  369.     case WINDOW_FILEAREA:
  370.          if (!escreen)
  371.            {
  372.             if (CURRENT_VIEW->prefix)
  373.                rc = Sos_prefix((CHARTYPE *)"");
  374.             rc = Sos_lastcol((CHARTYPE *)"");
  375.            }
  376.          else
  377.            {
  378. #ifdef VERSHIFT
  379.             if (CURRENT_VIEW->verify_col != 1)
  380.               {
  381.                rc = execute_move_cursor(CURRENT_VIEW->verify_col-2);
  382. #else
  383. /*           if (CURRENT_VIEW->verify_start != CURRENT_VIEW->verify_col)*/
  384.             if (CURRENT_VIEW->verify_col != 1)
  385.               {
  386.                old_col = (CURRENT_VIEW->verify_col-1);
  387.                x = min(CURRENT_SCREEN.cols[WINDOW_FILEAREA],CURRENT_VIEW->verify_end-CURRENT_VIEW->verify_start+1) / 2;
  388.                col = max(1,old_col - (short)x);
  389.                CURRENT_VIEW->verify_col = col;
  390.                build_screen(current_screen);
  391.                display_screen(current_screen);
  392.                x = old_col - (CURRENT_VIEW->verify_col-1);
  393.                wmove(CURRENT_WINDOW,y,x-1);
  394. #endif
  395.  
  396.               }
  397.             else
  398.               {
  399.                extern short compatible_feel;
  400.                if (compatible_feel == COMPAT_KEDIT)
  401.                  {
  402.                   if (CURRENT_VIEW->prefix)
  403.                      if ((CURRENT_VIEW->prefix&PREFIX_LOCATION_MASK) == PREFIX_LEFT)
  404.                         rc = Sos_prefix((CHARTYPE *)"");
  405.                   rc = Sos_lastcol((CHARTYPE *)"");
  406.                  }
  407.               }
  408.            }
  409.          break;
  410.     case WINDOW_PREFIX:
  411.     case WINDOW_COMMAND:
  412.          if ((escreen
  413.          &&  (CURRENT_VIEW->prefix&PREFIX_LOCATION_MASK) == PREFIX_RIGHT)
  414.          ||  !escreen)
  415.              rc = Sos_rightedge((CHARTYPE *)"");
  416.          break;
  417.     default:
  418.          break;
  419.    }
  420. #ifdef TRACE
  421.  trace_return();
  422. #endif
  423.  return(rc);
  424. }
  425. /***********************************************************************/
  426. #ifdef HAVE_PROTO
  427. short cursor_right(bool escreen,bool kedit_defaults)
  428. #else
  429. short cursor_right(escreen,kedit_defaults)
  430. bool escreen,kedit_defaults;
  431. #endif
  432. /***********************************************************************/
  433. {
  434. /*------------------------- external data -----------------------------*/
  435. /*--------------------------- local data ------------------------------*/
  436.  unsigned short x=0,y=0,tempx=0;
  437.  short right_column=0;
  438.  short rc=RC_OK;
  439. /*--------------------------- processing ------------------------------*/
  440. #ifdef TRACE
  441.  trace_function("cursor.c:  cursor_right");
  442. #endif
  443. /*---------------------------------------------------------------------*/
  444. /* The following should be a temporary fix for KEDIT compatability...  */
  445. /*---------------------------------------------------------------------*/
  446.  if (CURRENT_VIEW->prefix
  447.  &&  kedit_defaults)
  448.     escreen = FALSE;
  449.  getyx(CURRENT_WINDOW,y,x);
  450. /*---------------------------------------------------------------------*/
  451. /* Check for going past end of line - max_line_length                  */
  452. /*---------------------------------------------------------------------*/
  453.  if (CURRENT_VIEW->verify_col+x+1 > max_line_length)
  454.    {
  455. #ifdef TRACE
  456.     trace_return();
  457. #endif
  458.     return(RC_OK);
  459.    }
  460.  right_column = getmaxx(CURRENT_WINDOW)-1;
  461. /*---------------------------------------------------------------------*/
  462. /* For all windows, if we are not at right column, move 1 pos to right.*/
  463. /*---------------------------------------------------------------------*/
  464.  if (x < right_column)
  465.    {
  466.     wmove(CURRENT_WINDOW,y,x+1);
  467. #ifdef TRACE
  468.     trace_return();
  469. #endif
  470.     return(RC_OK);
  471.    }
  472. /*---------------------------------------------------------------------*/
  473. /* For all windows, determine if CMDARROWSTABLRx is set for tabbing or */
  474. /* scrolling and act accordingly.                                      */
  475. /*---------------------------------------------------------------------*/
  476.  switch(CURRENT_VIEW->current_window)
  477.    {
  478.     case WINDOW_FILEAREA:
  479.          if (!escreen)
  480.            {
  481.             if (CURRENT_VIEW->prefix)
  482.                rc = Sos_prefix((CHARTYPE *)"");
  483.             else
  484.                wmove(CURRENT_WINDOW,y,0); /* this should move down a line too */
  485.            }
  486.          else
  487.            {
  488. #ifdef VERSHIFT
  489.             rc = execute_move_cursor(right_column+1);
  490. #else
  491.             tempx = getmaxx(CURRENT_WINDOW);
  492.             if (x == tempx-1)
  493.               {
  494.                x = (tempx / 2);
  495.                CURRENT_VIEW->verify_col += x;
  496.                build_screen(current_screen);
  497.                display_screen(current_screen);
  498.                wmove(CURRENT_WINDOW,y,x+(tempx % 2));
  499.               }
  500. #endif
  501.  
  502.            }
  503.          break;
  504.     case WINDOW_PREFIX:
  505.     case WINDOW_COMMAND:
  506.          if (!escreen)
  507.             rc = Sos_leftedge((CHARTYPE *)"");
  508.          else 
  509.             if ((CURRENT_VIEW->prefix&PREFIX_LOCATION_MASK) == PREFIX_LEFT)
  510.                Tabpre((CHARTYPE *)"");
  511.          break;
  512.     default:
  513.          break;
  514.    }
  515. #ifdef TRACE
  516.  trace_return();
  517. #endif
  518.  return(rc);
  519. }
  520. /***********************************************************************/
  521. #ifdef HAVE_PROTO
  522. short cursor_up(bool escreen)
  523. #else
  524. short cursor_up(escreen)
  525. bool escreen;
  526. #endif
  527. /***********************************************************************/
  528. {
  529. /*------------------------- external data -----------------------------*/
  530.  extern CHARTYPE CMDARROWSTABCMDx;
  531.  extern bool in_readv;
  532. /*--------------------------- local data ------------------------------*/
  533.  short rc=RC_OK;
  534.  CHARTYPE *current_command=NULL;
  535. /*--------------------------- processing ------------------------------*/
  536. #ifdef TRACE
  537.  trace_function("cursor.c:  cursor_up");
  538. #endif
  539. /*---------------------------------------------------------------------*/
  540. /* If in READV CMDLINE, return without doing anything                  */
  541. /*---------------------------------------------------------------------*/
  542.  if (in_readv)
  543.    {
  544. #ifdef TRACE
  545.     trace_return();
  546. #endif
  547.     return(RC_OK);
  548.    }
  549.  switch(CURRENT_VIEW->current_window)
  550.    {
  551.     case WINDOW_FILEAREA:
  552.     case WINDOW_PREFIX:
  553.          rc = scroll_line(DIRECTION_BACKWARD,1L,FALSE,escreen);
  554.          break;
  555.     case WINDOW_COMMAND:
  556. /*---------------------------------------------------------------------*/
  557. /* Cycle backward through the command list or tab to last line.        */
  558. /*---------------------------------------------------------------------*/
  559.          if (CMDARROWSTABCMDx)
  560.             rc = Sos_bottomedge((CHARTYPE *)"");
  561.          else
  562.            {
  563.             current_command = get_next_command(DIRECTION_FORWARD,1);
  564.             wmove(CURRENT_WINDOW_COMMAND,0,0);
  565.             my_wclrtoeol(CURRENT_WINDOW_COMMAND);
  566.             if (current_command != (CHARTYPE *)NULL)
  567.                Cmsg(current_command);
  568.            }
  569.          break;
  570.     default:
  571.          display_error(2,(CHARTYPE *)"",FALSE);
  572.          rc = RC_INVALID_OPERAND;
  573.          break;
  574.    }
  575. #ifdef TRACE
  576.  trace_return();
  577. #endif
  578.  return(rc);
  579. }
  580. /***********************************************************************/
  581. #ifdef HAVE_PROTO
  582. short cursor_move(bool escreen,short row,short col)
  583. #else
  584. short cursor_move(escreen,row,col)
  585. bool escreen;
  586. short row,col;
  587. #endif
  588. /***********************************************************************/
  589. {
  590. /*------------------------- external data -----------------------------*/
  591. /*--------------------------- local data ------------------------------*/
  592.  register int i=0;
  593.  short rc=RC_OK;
  594.  unsigned short x=0,y=0;
  595.  unsigned short max_row=0,min_row=0,max_col=0;
  596.  short idx=(-1);
  597. /*--------------------------- processing ------------------------------*/
  598. #ifdef TRACE
  599.  trace_function("cursor.c:  cursor_move");
  600. #endif
  601.  getyx(CURRENT_WINDOW_FILEAREA,y,x);
  602.  post_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line,(LINE *)NULL,TRUE);
  603.  if (!escreen)
  604.    {
  605.     if (find_last_focus_line(&max_row) != RC_OK)
  606.       {
  607. #ifdef TRACE
  608.        trace_return();
  609. #endif
  610.        return(rc);
  611.       }
  612.     if (find_first_focus_line(&min_row) != RC_OK)
  613.       {
  614. #ifdef TRACE
  615.        trace_return();
  616. #endif
  617.        return(rc);
  618.       }
  619.     if (row == 0)
  620.        row = y;
  621.     else
  622.       {
  623.        if (row > max_row)
  624.           row = max_row;
  625.        else
  626.          {
  627.           if (row < min_row)
  628.              row = min_row;
  629.           else
  630.             {
  631.              if (CURRENT_SCREEN.sl[row-1].main_enterable)
  632.                 row--;
  633.              else
  634.                {
  635.                 display_error(63,(CHARTYPE *)"",FALSE);
  636. #ifdef TRACE
  637.                 trace_return();
  638. #endif
  639.                 return(RC_TOF_EOF_REACHED);/* this is a strange RC :-( */
  640.                }
  641.             }
  642.          }
  643.       }
  644.     max_col = CURRENT_SCREEN.cols[WINDOW_FILEAREA];
  645.     if (col == 0)
  646.        col = x;
  647.     else
  648.        if (col > max_col)
  649.           col = max_col - 1;
  650.        else
  651.           col--;
  652.     switch(CURRENT_VIEW->current_window)
  653.       {
  654.        case WINDOW_COMMAND:
  655.             rc = cursor_home(FALSE);
  656.             break;
  657.        case WINDOW_PREFIX:
  658.             CURRENT_VIEW->current_window = WINDOW_FILEAREA;
  659.             break;
  660.       }
  661.     wmove(CURRENT_WINDOW_FILEAREA,row,col);
  662.     CURRENT_VIEW->focus_line = CURRENT_SCREEN.sl[row].line_number;
  663.     pre_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line,(LINE *)NULL);
  664.    }
  665.  else
  666. /*---------------------------------------------------------------------*/
  667. /* For CURSOR ESCREEN...                                               */
  668. /*---------------------------------------------------------------------*/
  669.    {
  670. /*---------------------------------------------------------------------*/
  671. /* Convert supplied row/col to 0 based offset...                       */
  672. /*---------------------------------------------------------------------*/
  673.     if (row == 0)
  674.        row = CURRENT_SCREEN.start_row[CURRENT_VIEW->current_window] + y;
  675.     else
  676.        row--;
  677.     if (col == 0)
  678.        col = CURRENT_SCREEN.start_col[CURRENT_VIEW->current_window] + x;
  679.     else
  680.        col--;
  681.     max_row = CURRENT_SCREEN.screen_rows - 1;
  682.     max_col = CURRENT_SCREEN.screen_cols - 1;
  683. /*---------------------------------------------------------------------*/
  684. /* If row/col outside maximum screen size, exit...                     */
  685. /*---------------------------------------------------------------------*/
  686.     if (row > max_row
  687.     ||  col > max_col)
  688.       {
  689.        display_error(63,(CHARTYPE *)"",FALSE);
  690. #ifdef TRACE
  691.        trace_return();
  692. #endif
  693.        return(RC_TOF_EOF_REACHED);/* this is a strange RC :-( */
  694.       }
  695. /*---------------------------------------------------------------------*/
  696. /* Determine which window the cursor will end up in...                 */
  697. /*---------------------------------------------------------------------*/
  698.     for (i=0;i<VIEW_WINDOWS;i++)
  699.       {
  700.        int top_int_row = CURRENT_SCREEN.start_row[i] - CURRENT_SCREEN.screen_start_row;
  701.        int bot_int_row = CURRENT_SCREEN.start_row[i] - CURRENT_SCREEN.screen_start_row + CURRENT_SCREEN.rows[i] - 1;
  702.        if (row >= top_int_row
  703.        &&  row <= bot_int_row
  704.        &&  col >= (CURRENT_SCREEN.start_col[i]  - CURRENT_SCREEN.screen_start_col)
  705.        &&  col <= (CURRENT_SCREEN.start_col[i] + CURRENT_SCREEN.cols[i] - 1 - CURRENT_SCREEN.screen_start_col))
  706.          {
  707.           idx = i;
  708.           break;
  709.          }
  710.       }
  711.     row = row - (CURRENT_SCREEN.start_row[idx] - CURRENT_SCREEN.screen_start_row);
  712.     col = col - (CURRENT_SCREEN.start_col[idx] - CURRENT_SCREEN.screen_start_col);
  713.     switch(idx)
  714.       {
  715.        case WINDOW_FILEAREA:
  716.             row = get_row_for_tof_eof(row,current_screen);
  717.             if (!CURRENT_SCREEN.sl[row].main_enterable)
  718.               {
  719.                display_error(63,(CHARTYPE *)"",FALSE);
  720. #ifdef TRACE
  721.                trace_return();
  722. #endif
  723.                return(RC_TOF_EOF_REACHED);/* this is a strange RC :-( */
  724.               }
  725.             rc = Sos_current((CHARTYPE *)"");
  726.             wmove(CURRENT_WINDOW_FILEAREA,row,col);
  727.             CURRENT_VIEW->focus_line = CURRENT_SCREEN.sl[row].line_number;
  728.             pre_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line,(LINE *)NULL);
  729.             break;
  730.        case WINDOW_PREFIX:
  731.             row = get_row_for_tof_eof(row,current_screen);
  732.             if (!CURRENT_SCREEN.sl[row].prefix_enterable)
  733.               {
  734.                display_error(63,(CHARTYPE *)"",FALSE);
  735. #ifdef TRACE
  736.                trace_return();
  737. #endif
  738.                return(RC_TOF_EOF_REACHED);/* this is a strange RC :-( */
  739.               }
  740. #if 0
  741.             if ((CURRENT_VIEW->prefix&PREFIX_LOCATION_MASK) == PREFIX_LEFT
  742.             &&  col >= CURRENT_VIEW->prefix_width-CURRENT_VIEW->prefix_gap)
  743.               {
  744.                display_error(63,(CHARTYPE *)"",FALSE);
  745. #ifdef TRACE
  746.                trace_return();
  747. #endif
  748.                return(RC_TOF_EOF_REACHED);/* this is a strange RC :-( */
  749.               }
  750.             if ((CURRENT_VIEW->prefix&PREFIX_LOCATION_MASK) == PREFIX_RIGHT
  751.             &&  col < CURRENT_VIEW->prefix_gap)
  752.               {
  753.                display_error(63,(CHARTYPE *)"",FALSE);
  754. #ifdef TRACE
  755.                trace_return();
  756. #endif
  757.                return(RC_TOF_EOF_REACHED);/* this is a strange RC :-( */
  758.               }
  759. #endif
  760.             rc = Sos_current((CHARTYPE *)"");
  761.             rc = Sos_prefix((CHARTYPE *)"");
  762.             wmove(CURRENT_WINDOW_PREFIX,row,col);
  763.             CURRENT_VIEW->focus_line = CURRENT_SCREEN.sl[row].line_number;
  764.             pre_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line,(LINE *)NULL);
  765.             break;
  766.        case WINDOW_COMMAND:
  767.             rc = cursor_cmdline(col+1);
  768.             break;
  769.        default:
  770.             display_error(63,(CHARTYPE *)"",FALSE);
  771. #ifdef TRACE
  772.             trace_return();
  773. #endif
  774.             return(RC_TOF_EOF_REACHED);/* this is a strange RC :-( */
  775.             break;
  776.       }
  777.    }
  778. #ifdef TRACE
  779.  trace_return();
  780. #endif
  781.  return(rc);
  782. }
  783. /***********************************************************************/
  784. #ifdef HAVE_PROTO
  785. short cursor_mouse(void)
  786. #else
  787. short cursor_mouse()
  788. #endif
  789. /***********************************************************************/
  790. {
  791. #define MOUSE_Y (MOUSE_Y_POS+1-screen[scrn].screen_start_row)
  792. #define MOUSE_X (MOUSE_X_POS+1-screen[scrn].screen_start_col)
  793. /*------------------------- external data -----------------------------*/
  794.  extern bool in_readv;
  795. /*--------------------------- local data ------------------------------*/
  796.  int w=0;
  797.  CHARTYPE scrn=0;
  798.  short rc=RC_OK;
  799. /*--------------------------- processing ------------------------------*/
  800. #ifdef TRACE
  801.  trace_function("cursor.c:  cursor_mouse");
  802. #endif
  803.  
  804. #if defined(MOUSE_SUPPORT_ENABLED)
  805. /*---------------------------------------------------------------------*/
  806. /* If in READV CMDLINE, return without doing anything                  */
  807. /*---------------------------------------------------------------------*/
  808.  if (in_readv)
  809.    {
  810. #ifdef TRACE
  811.     trace_return();
  812. #endif
  813.     return(RC_OK);
  814.    }
  815. /*---------------------------------------------------------------------*/
  816. /* First determine in which window the mouse is...                     */
  817. /*---------------------------------------------------------------------*/
  818.  which_window_is_mouse_in(&scrn,&w);
  819.  if (w == (-1)) /* shouldn't happen! */
  820.    {
  821. #ifdef TRACE
  822.     trace_return();
  823. #endif
  824.     return(RC_INVALID_ENVIRON);
  825.    }
  826. /*---------------------------------------------------------------------*/
  827. /* If the mouse is in a different screen to the current one, move there*/
  828. /*---------------------------------------------------------------------*/
  829.  if (current_screen != scrn)
  830.    {
  831.     (void)Nextwindow((CHARTYPE *)"");
  832.    }
  833. /*---------------------------------------------------------------------*/
  834. /* Move the cursor to the correct screen coordinates...                */
  835. /*---------------------------------------------------------------------*/
  836.  rc = cursor_move(TRUE,MOUSE_Y,MOUSE_X);
  837. #endif
  838.  
  839. #ifdef TRACE
  840.  trace_return();
  841. #endif
  842.  return(rc);
  843. }
  844. /***********************************************************************/
  845. #ifdef HAVE_PROTO
  846. long where_now(void)
  847. #else
  848. long where_now()
  849. #endif
  850. /***********************************************************************/
  851. {
  852. /*------------------------- external data -----------------------------*/
  853.  extern CHARTYPE display_screens;
  854. /*--------------------------- local data ------------------------------*/
  855.  long rc=0L;
  856.  unsigned short x=0,y=0;
  857. /*--------------------------- processing ------------------------------*/
  858. #ifdef TRACE
  859.  trace_function("cursor.c:  where_now");
  860. #endif
  861.  getyx(CURRENT_WINDOW,y,x);
  862.  switch(CURRENT_VIEW->current_window)
  863.    {
  864.     case WINDOW_FILEAREA:
  865.          rc |= WHERE_WINDOW_FILEAREA;
  866.          break;
  867.     case WINDOW_PREFIX:
  868.          if ((CURRENT_VIEW->prefix & PREFIX_LOCATION_MASK) == PREFIX_LEFT)
  869.             rc |= WHERE_WINDOW_PREFIX_LEFT;
  870.          else
  871.             rc |= WHERE_WINDOW_PREFIX_RIGHT;
  872.          break;
  873.     case WINDOW_COMMAND:
  874.          if (CURRENT_VIEW->cmd_line == 'B')
  875.             rc |= WHERE_WINDOW_CMDLINE_BOTTOM;
  876.          else
  877.             rc |= WHERE_WINDOW_CMDLINE_TOP;
  878.          break;
  879.    }
  880.  if (display_screens == 1)
  881.     rc |= WHERE_SCREEN_ONLY;
  882.  else
  883.    {
  884.     if (current_screen == 0)
  885.        rc |= WHERE_SCREEN_FIRST;
  886.     else
  887.        rc |= WHERE_SCREEN_LAST;
  888.    }
  889.  rc |= (long)y;
  890. #ifdef TRACE
  891.  trace_return();
  892. #endif
  893.  return(rc);
  894. }
  895. /***********************************************************************/
  896. #ifdef HAVE_PROTO
  897. long what_current_now(void)
  898. #else
  899. long what_current_now()
  900. #endif
  901. /***********************************************************************/
  902. {
  903. /*------------------------- external data -----------------------------*/
  904. /*--------------------------- local data ------------------------------*/
  905.  long rc=0;
  906. /*--------------------------- processing ------------------------------*/
  907. #ifdef TRACE
  908.  trace_function("cursor.c:  what_current_now");
  909. #endif
  910.  if (CURRENT_WINDOW_PREFIX != NULL)
  911.    {
  912.     if ((CURRENT_VIEW->prefix & PREFIX_LOCATION_MASK) == PREFIX_LEFT)
  913.        rc |= WHERE_WINDOW_PREFIX_LEFT;
  914.     else
  915.        rc |= WHERE_WINDOW_PREFIX_RIGHT;
  916.    }
  917.  if (CURRENT_VIEW->cmd_line == 'B')
  918.     rc |= WHERE_WINDOW_CMDLINE_BOTTOM;
  919.  else
  920.     if (CURRENT_VIEW->cmd_line == 'T')
  921.        rc |= WHERE_WINDOW_CMDLINE_TOP;
  922. #ifdef TRACE
  923.  trace_return();
  924. #endif
  925.  return(rc);
  926. }
  927. /***********************************************************************/
  928. #ifdef HAVE_PROTO
  929. long what_other_now(void)
  930. #else
  931. long what_other_now()
  932. #endif
  933. /***********************************************************************/
  934. {
  935. /*------------------------- external data -----------------------------*/
  936.  extern CHARTYPE display_screens;
  937. /*--------------------------- local data ------------------------------*/
  938.  long rc=0L;
  939. /*--------------------------- processing ------------------------------*/
  940. #ifdef TRACE
  941.  trace_function("cursor.c:  what_other_now");
  942. #endif
  943. if (display_screens == 1)
  944.   {
  945. #ifdef TRACE
  946.    trace_return();
  947. #endif
  948.    return(rc);
  949.   }
  950.  if (OTHER_SCREEN.win[WINDOW_PREFIX] != NULL)
  951.    {
  952.     if ((OTHER_SCREEN.screen_view->prefix & PREFIX_LOCATION_MASK) == PREFIX_LEFT)
  953.        rc |= WHERE_WINDOW_PREFIX_LEFT;
  954.     else
  955.        rc |= WHERE_WINDOW_PREFIX_RIGHT;
  956.    }
  957.  if (OTHER_SCREEN.screen_view->cmd_line == 'B')
  958.     rc |= WHERE_WINDOW_CMDLINE_BOTTOM;
  959.  else
  960.     if (OTHER_SCREEN.screen_view->cmd_line == 'T')
  961.        rc |= WHERE_WINDOW_CMDLINE_TOP;
  962. #ifdef TRACE
  963.  trace_return();
  964. #endif
  965.  return(rc);
  966. }
  967. /***********************************************************************/
  968. #ifdef HAVE_PROTO
  969. long where_next(long where,long what_current,long what_other)
  970. #else
  971. long where_next(where,what_current,what_other)
  972. long where,what_current,what_other;
  973. #endif
  974. /***********************************************************************/
  975. {
  976. /*------------------------- external data -----------------------------*/
  977. /*--------------------------- local data ------------------------------*/
  978.  long where_row=0L,where_window=0L,where_screen=0L;
  979.  long what_current_window=0L;
  980.  long what_other_window=0L;
  981.  long rc=0L;
  982.  unsigned short current_top_row=0,current_bottom_row=0;
  983. /*--------------------------- processing ------------------------------*/
  984.  where_row = where & WHERE_ROW_MASK;
  985.  where_window = where & WHERE_WINDOW_MASK;
  986.  where_screen = where & WHERE_SCREEN_MASK;
  987.  what_current_window = what_current & WHERE_WINDOW_MASK;
  988.  what_other_window = what_other & WHERE_WINDOW_MASK;
  989.  find_first_focus_line(¤t_top_row);
  990.  find_last_focus_line(¤t_bottom_row);
  991.  
  992.  switch(where_window)
  993.    {
  994.     case WHERE_WINDOW_FILEAREA:
  995. /*---------------------------------------------------------------------*/
  996. /* In filearea.                                                        */
  997. /*---------------------------------------------------------------------*/
  998.          if (what_current_window & WHERE_WINDOW_PREFIX_RIGHT)
  999. /*---------------------------------------------------------------------*/
  1000. /* In filearea and there is prefix on right.                           */
  1001. /* Result: same row,same screen,go to prefix.                          */
  1002. /*---------------------------------------------------------------------*/
  1003.             return(where_row | where_screen | WHERE_WINDOW_PREFIX_RIGHT);
  1004.          switch(where_screen)
  1005.            {
  1006.             case WHERE_SCREEN_FIRST:
  1007.             case WHERE_SCREEN_LAST:
  1008.                      /* the two cases above will be separate in future */
  1009.             case WHERE_SCREEN_ONLY:
  1010. /*---------------------------------------------------------------------*/
  1011. /* In filearea and only screen.                                        */
  1012. /*---------------------------------------------------------------------*/
  1013.                  if (where_row == (long)current_bottom_row)
  1014.                    {
  1015. /*---------------------------------------------------------------------*/
  1016. /* In filearea, prefix on left or off, on bottom line.                 */
  1017. /*---------------------------------------------------------------------*/
  1018.                     if (what_current_window & WHERE_WINDOW_CMDLINE_TOP)
  1019. /*---------------------------------------------------------------------*/
  1020. /* In filearea,prefix on left or off, on bottom line.                  */
  1021. /* Result: row irrelevant,same screen,go to cmdline.                   */
  1022. /*---------------------------------------------------------------------*/
  1023.                        return(where_row | where_screen | WHERE_WINDOW_CMDLINE_TOP);
  1024.                     if (what_current_window & WHERE_WINDOW_CMDLINE_BOTTOM)
  1025. /*---------------------------------------------------------------------*/
  1026. /* In filearea,prefix on left or off, on bottom line.                  */
  1027. /* Result: row irrelevant,same screen,go to cmdline.                   */
  1028. /*---------------------------------------------------------------------*/
  1029.                        return(where_row | where_screen | WHERE_WINDOW_CMDLINE_BOTTOM);
  1030. /*---------------------------------------------------------------------*/
  1031. /******************* To get here, there is no cmdline. *****************/
  1032. /*---------------------------------------------------------------------*/
  1033.                     if (what_current_window & WHERE_WINDOW_PREFIX_LEFT)
  1034. /*---------------------------------------------------------------------*/
  1035. /* In filearea,prefix on left or off, on bottom line.                  */
  1036. /* Result: first row,same screen,go to prefix.                         */
  1037. /*---------------------------------------------------------------------*/
  1038.                        return((long)current_top_row | where_screen | WHERE_WINDOW_PREFIX_LEFT);
  1039.                    }
  1040. /*---------------------------------------------------------------------*/
  1041. /******************* To get here, we are not on last row. **************/
  1042. /*---------------------------------------------------------------------*/
  1043.                  if (what_current_window & WHERE_WINDOW_PREFIX_LEFT)
  1044. /*---------------------------------------------------------------------*/
  1045. /* In filearea, prefix on left, not on bottom line.                    */
  1046. /* Result: next row,same screen,go to prefix.                          */
  1047. /*---------------------------------------------------------------------*/
  1048.                     return((where_row+1L) | where_screen | WHERE_WINDOW_PREFIX_LEFT);
  1049. /*---------------------------------------------------------------------*/
  1050. /* In filearea, no prefix, not on bottom line.                         */
  1051. /* Result: next row,same screen,same window.                           */
  1052. /*---------------------------------------------------------------------*/
  1053.                  return((where_row+1L) | where_screen | WHERE_WINDOW_FILEAREA);
  1054.                  break;
  1055.            }
  1056.          break;
  1057.     case WHERE_WINDOW_PREFIX_LEFT:
  1058.          rc = where_row | where_screen | WHERE_WINDOW_FILEAREA;
  1059.          break;
  1060.     case WHERE_WINDOW_PREFIX_RIGHT:
  1061.          switch(where_screen)
  1062.            {
  1063.             case WHERE_SCREEN_FIRST:
  1064.             case WHERE_SCREEN_LAST:
  1065.                      /* the two cases above will be separate in future */
  1066.             case WHERE_SCREEN_ONLY:
  1067. /*---------------------------------------------------------------------*/
  1068. /* In right prefix and only screen.                                    */
  1069. /*---------------------------------------------------------------------*/
  1070.                  if (where_row != (long)current_bottom_row)
  1071. /*---------------------------------------------------------------------*/
  1072. /* In right prefix and not on bottom line.                             */
  1073. /* Result: next row,same screen,go to filearea.                        */
  1074. /*---------------------------------------------------------------------*/
  1075.                     return((where_row+1L) | where_screen | WHERE_WINDOW_FILEAREA);
  1076.                  if (what_current_window & WHERE_WINDOW_CMDLINE_BOTTOM)
  1077. /*---------------------------------------------------------------------*/
  1078. /* In right prefix, cmdline on bottom, on bottom line.                 */
  1079. /* Result: row irrelevant,same screen,go to cmdline.                   */
  1080. /*---------------------------------------------------------------------*/
  1081.                     return(where_row | where_screen | WHERE_WINDOW_CMDLINE_BOTTOM);
  1082.                  if (what_current_window & WHERE_WINDOW_CMDLINE_TOP)
  1083. /*---------------------------------------------------------------------*/
  1084. /* In right prefix, cmdline on top, on bottom line.                    */
  1085. /* Result: row irrelevant,same screen,go to cmdline.                   */
  1086. /*---------------------------------------------------------------------*/
  1087.                     return(where_row | where_screen | WHERE_WINDOW_CMDLINE_TOP);
  1088. /*---------------------------------------------------------------------*/
  1089. /* In right prefix, no cmdline, on bottom line.                        */
  1090. /* Result: first row,same screen,go to filearea.                       */
  1091. /*---------------------------------------------------------------------*/
  1092.                  return((long)current_top_row | where_screen | WHERE_WINDOW_FILEAREA);
  1093.                  break;
  1094.            }
  1095.          break;
  1096.     case WHERE_WINDOW_CMDLINE_TOP:
  1097.          switch(where_screen)
  1098.            {
  1099.             case WHERE_SCREEN_FIRST:
  1100.             case WHERE_SCREEN_LAST:
  1101.                      /* the two cases above will be separate in future */
  1102.             case WHERE_SCREEN_ONLY:
  1103. /*---------------------------------------------------------------------*/
  1104. /* In cmdline, and only screen.                                        */
  1105. /*---------------------------------------------------------------------*/
  1106.                  if (what_current_window & WHERE_WINDOW_PREFIX_LEFT)
  1107. /*---------------------------------------------------------------------*/
  1108. /* In cmdline, and only screen and prefix on left.                     */
  1109. /* Result: first row, same screen, go to prefix.                       */
  1110. /*---------------------------------------------------------------------*/
  1111.                     return((long)current_top_row | where_screen | WHERE_WINDOW_PREFIX_LEFT);
  1112. /*---------------------------------------------------------------------*/
  1113. /* In cmdline, and prefix on right or none.                            */
  1114. /* Result: first row, same screen, go to filearea.                     */
  1115. /*---------------------------------------------------------------------*/
  1116.                  return((long)current_top_row | where_screen | WHERE_WINDOW_FILEAREA);
  1117.                  break;
  1118.            }
  1119.          break;
  1120.     case WHERE_WINDOW_CMDLINE_BOTTOM:
  1121.          switch(where_screen)
  1122.            {
  1123.             case WHERE_SCREEN_FIRST:
  1124.             case WHERE_SCREEN_LAST:
  1125.                      /* the two cases above will be separate in future */
  1126.             case WHERE_SCREEN_ONLY:
  1127. /*---------------------------------------------------------------------*/
  1128. /* In cmdline, and only screen.                                        */
  1129. /*---------------------------------------------------------------------*/
  1130.                  if (what_current_window & WHERE_WINDOW_PREFIX_LEFT)
  1131. /*---------------------------------------------------------------------*/
  1132. /* In cmdline, and only screen and prefix on left.                     */
  1133. /* Result: first row, same screen, go to prefix.                       */
  1134. /*---------------------------------------------------------------------*/
  1135.                     return((long)current_top_row | where_screen | WHERE_WINDOW_PREFIX_LEFT);
  1136. /*---------------------------------------------------------------------*/
  1137. /* In cmdline, and prefix on right or none.                            */
  1138. /* Result: first row, same screen, go to filearea.                     */
  1139. /*---------------------------------------------------------------------*/
  1140.                  return((long)current_top_row | where_screen | WHERE_WINDOW_FILEAREA);
  1141.                  break;
  1142.            }
  1143.          break;
  1144.    }
  1145.  return(rc);
  1146. }
  1147. /***********************************************************************/
  1148. #ifdef HAVE_PROTO
  1149. long where_before(long where,long what_current,long what_other)
  1150. #else
  1151. long where_before(where,what_current,what_other)
  1152. long where,what_current,what_other;
  1153. #endif
  1154. /***********************************************************************/
  1155. {
  1156. /*------------------------- external data -----------------------------*/
  1157. /*--------------------------- local data ------------------------------*/
  1158.  long where_row=0L,where_window=0L,where_screen=0L;
  1159.  long what_current_window=0L;
  1160.  long what_other_window=0L;
  1161.  long rc=0L;
  1162.  unsigned short current_top_row=0,current_bottom_row=0;
  1163. /*--------------------------- processing ------------------------------*/
  1164.  where_row = where & WHERE_ROW_MASK;
  1165.  where_window = where & WHERE_WINDOW_MASK;
  1166.  where_screen = where & WHERE_SCREEN_MASK;
  1167.  what_current_window = what_current & WHERE_WINDOW_MASK;
  1168.  what_other_window = what_other & WHERE_WINDOW_MASK;
  1169.  find_first_focus_line(¤t_top_row);
  1170.  find_last_focus_line(¤t_bottom_row);
  1171.  
  1172.  switch(where_window)
  1173.    {
  1174.     case WHERE_WINDOW_FILEAREA:
  1175. /*---------------------------------------------------------------------*/
  1176. /* In filearea.                                                        */
  1177. /*---------------------------------------------------------------------*/
  1178.          if (what_current_window & WHERE_WINDOW_PREFIX_LEFT)
  1179. /*---------------------------------------------------------------------*/
  1180. /* In filearea and there is prefix on left.                            */
  1181. /* Result: same row,same screen,go to prefix.                          */
  1182. /*---------------------------------------------------------------------*/
  1183.             return(where_row | where_screen | WHERE_WINDOW_PREFIX_LEFT);
  1184.          switch(where_screen)
  1185.            {
  1186.             case WHERE_SCREEN_FIRST:
  1187.             case WHERE_SCREEN_LAST:
  1188.                      /* the two cases above will be separate in future */
  1189.             case WHERE_SCREEN_ONLY:
  1190. /*---------------------------------------------------------------------*/
  1191. /* In filearea and only screen.                                        */
  1192. /*---------------------------------------------------------------------*/
  1193.                  if (where_row == (long)current_top_row)
  1194.                    {
  1195. /*---------------------------------------------------------------------*/
  1196. /* In filearea, prefix on right or off, on top    line.                */
  1197. /*---------------------------------------------------------------------*/
  1198.                     if (what_current_window & WHERE_WINDOW_CMDLINE_BOTTOM)
  1199. /*---------------------------------------------------------------------*/
  1200. /* In filearea,prefix on right or off, on top    line.                 */
  1201. /* Result: row irrelevant,same screen,go to cmdline.                   */
  1202. /*---------------------------------------------------------------------*/
  1203.                        return(where_row | where_screen | WHERE_WINDOW_CMDLINE_BOTTOM);
  1204.                     if (what_current_window & WHERE_WINDOW_CMDLINE_TOP)
  1205. /*---------------------------------------------------------------------*/
  1206. /* In filearea,prefix on right or off, on top    line.                 */
  1207. /* Result: row irrelevant,same screen,go to cmdline.                   */
  1208. /*---------------------------------------------------------------------*/
  1209.                        return(where_row | where_screen | WHERE_WINDOW_CMDLINE_TOP);
  1210. /*---------------------------------------------------------------------*/
  1211. /******************* To get here, there is no cmdline. *****************/
  1212. /*---------------------------------------------------------------------*/
  1213.                     if (what_current_window & WHERE_WINDOW_PREFIX_RIGHT)
  1214. /*---------------------------------------------------------------------*/
  1215. /* In filearea,prefix on right or off, on top    line.                 */
  1216. /* Result: last  row,same screen,go to prefix.                         */
  1217. /*---------------------------------------------------------------------*/
  1218.                        return((long)current_bottom_row | where_screen | WHERE_WINDOW_PREFIX_RIGHT);
  1219.                    }
  1220. /*---------------------------------------------------------------------*/
  1221. /******************* To get here, we are not on top  row. **************/
  1222. /*---------------------------------------------------------------------*/
  1223.                  if (what_current_window & WHERE_WINDOW_PREFIX_RIGHT)
  1224. /*---------------------------------------------------------------------*/
  1225. /* In filearea, prefix on right, not on top    line.                   */
  1226. /* Result: prior row,same screen,go to prefix.                         */
  1227. /*---------------------------------------------------------------------*/
  1228.                     return((where_row-1L) | where_screen | WHERE_WINDOW_PREFIX_RIGHT);
  1229. /*---------------------------------------------------------------------*/
  1230. /* In filearea, no prefix, not on top    line.                         */
  1231. /* Result: prior row,same screen,same window.                          */
  1232. /*---------------------------------------------------------------------*/
  1233.                  return((where_row-1L) | where_screen | WHERE_WINDOW_FILEAREA);
  1234.                  break;
  1235.            }
  1236.          break;
  1237.     case WHERE_WINDOW_PREFIX_RIGHT:
  1238.          rc = where_row | where_screen | WHERE_WINDOW_FILEAREA;
  1239.          break;
  1240.     case WHERE_WINDOW_PREFIX_LEFT:
  1241.          switch(where_screen)
  1242.            {
  1243.             case WHERE_SCREEN_FIRST:
  1244.             case WHERE_SCREEN_LAST:
  1245.                      /* the two cases above will be separate in future */
  1246.             case WHERE_SCREEN_ONLY:
  1247. /*---------------------------------------------------------------------*/
  1248. /* In left  prefix and only screen.                                    */
  1249. /*---------------------------------------------------------------------*/
  1250.                  if (where_row != (long)current_top_row)
  1251. /*---------------------------------------------------------------------*/
  1252. /* In left  prefix and not on top    line.                             */
  1253. /* Result: prior row,same screen,go to filearea.                       */
  1254. /*---------------------------------------------------------------------*/
  1255.                     return((where_row-1L) | where_screen | WHERE_WINDOW_FILEAREA);
  1256.                  if (what_current_window & WHERE_WINDOW_CMDLINE_BOTTOM)
  1257. /*---------------------------------------------------------------------*/
  1258. /* In left  prefix, cmdline on bottom, on top    line.                 */
  1259. /* Result: row irrelevant,same screen,go to cmdline.                   */
  1260. /*---------------------------------------------------------------------*/
  1261.                     return(where_row | where_screen | WHERE_WINDOW_CMDLINE_BOTTOM);
  1262.                  if (what_current_window & WHERE_WINDOW_CMDLINE_TOP)
  1263. /*---------------------------------------------------------------------*/
  1264. /* In left  prefix, cmdline on top, on top    line.                    */
  1265. /* Result: row irrelevant,same screen,go to cmdline.                   */
  1266. /*---------------------------------------------------------------------*/
  1267.                     return(where_row | where_screen | WHERE_WINDOW_CMDLINE_TOP);
  1268. /*---------------------------------------------------------------------*/
  1269. /* In left  prefix, no cmdline, on top    line.                        */
  1270. /* Result: last  row,same screen,go to filearea.                       */
  1271. /*---------------------------------------------------------------------*/
  1272.                  return((long)current_bottom_row | where_screen | WHERE_WINDOW_FILEAREA);
  1273.                  break;
  1274.            }
  1275.          break;
  1276.     case WHERE_WINDOW_CMDLINE_TOP:
  1277.          switch(where_screen)
  1278.            {
  1279.             case WHERE_SCREEN_FIRST:
  1280.             case WHERE_SCREEN_LAST:
  1281.                      /* the two cases above will be separate in future */
  1282.             case WHERE_SCREEN_ONLY:
  1283. /*---------------------------------------------------------------------*/
  1284. /* In cmdline, and only screen.                                        */
  1285. /*---------------------------------------------------------------------*/
  1286.                  if (what_current_window & WHERE_WINDOW_PREFIX_RIGHT)
  1287. /*---------------------------------------------------------------------*/
  1288. /* In cmdline, and only screen and prefix on right.                    */
  1289. /* Result: last  row, same screen, go to prefix.                       */
  1290. /*---------------------------------------------------------------------*/
  1291.                     return((long)current_bottom_row | where_screen | WHERE_WINDOW_PREFIX_RIGHT);
  1292. /*---------------------------------------------------------------------*/
  1293. /* In cmdline, and prefix on left  or none.                            */
  1294. /* Result: last  row, same screen, go to filearea.                     */
  1295. /*---------------------------------------------------------------------*/
  1296.                  return((long)current_bottom_row | where_screen | WHERE_WINDOW_FILEAREA);
  1297.                  break;
  1298.            }
  1299.          break;
  1300.     case WHERE_WINDOW_CMDLINE_BOTTOM:
  1301.          switch(where_screen)
  1302.            {
  1303.             case WHERE_SCREEN_FIRST:
  1304.             case WHERE_SCREEN_LAST:
  1305.                      /* the two cases above will be separate in future */
  1306.             case WHERE_SCREEN_ONLY:
  1307. /*---------------------------------------------------------------------*/
  1308. /* In cmdline, and only screen.                                        */
  1309. /*---------------------------------------------------------------------*/
  1310.                  if (what_current_window & WHERE_WINDOW_PREFIX_RIGHT)
  1311. /*---------------------------------------------------------------------*/
  1312. /* In cmdline, and only screen and prefix on right.                    */
  1313. /* Result: last  row, same screen, go to prefix.                       */
  1314. /*---------------------------------------------------------------------*/
  1315.                     return((long)current_bottom_row | where_screen | WHERE_WINDOW_PREFIX_RIGHT);
  1316. /*---------------------------------------------------------------------*/
  1317. /* In cmdline, and prefix on left  or none.                            */
  1318. /* Result: last  row, same screen, go to filearea.                     */
  1319. /*---------------------------------------------------------------------*/
  1320.                  return((long)current_bottom_row | where_screen | WHERE_WINDOW_FILEAREA);
  1321.                  break;
  1322.            }
  1323.          break;
  1324.    }
  1325.  return(rc);
  1326. }
  1327. /***********************************************************************/
  1328. #ifdef HAVE_PROTO
  1329. bool enterable_field(long where)
  1330. #else
  1331. bool enterable_field(where)
  1332. long where;
  1333. #endif
  1334. /***********************************************************************/
  1335. {
  1336. /*------------------------- external data -----------------------------*/
  1337. /*--------------------------- local data ------------------------------*/
  1338.  bool rc=TRUE;
  1339.  ROWTYPE row=0;
  1340.  long where_screen=0L;
  1341.  CHARTYPE scrn=0;
  1342. /*--------------------------- processing ------------------------------*/
  1343. #ifdef TRACE
  1344.  trace_function("cursor.c:  enterable_field");
  1345. #endif
  1346.  where_screen = where & WHERE_SCREEN_MASK;
  1347.  row = (ROWTYPE)(where & WHERE_ROW_MASK);
  1348.  scrn = (where_screen == WHERE_SCREEN_LAST) ? 1 : 0;
  1349.  switch(where & WHERE_WINDOW_MASK)
  1350.    {
  1351.     case WHERE_WINDOW_FILEAREA:
  1352.          if (!screen[scrn].sl[row].main_enterable)
  1353.             rc = FALSE;
  1354.          break;
  1355.     case WHERE_WINDOW_PREFIX_LEFT:
  1356.     case WHERE_WINDOW_PREFIX_RIGHT:
  1357.          if (!screen[scrn].sl[row].prefix_enterable)
  1358.             rc = FALSE;
  1359.          break;
  1360.     case WHERE_WINDOW_CMDLINE_TOP:
  1361.     case WHERE_WINDOW_CMDLINE_BOTTOM:
  1362.          break;
  1363.    }
  1364. #ifdef TRACE
  1365.  trace_return();
  1366. #endif
  1367.  return(rc);
  1368. }
  1369. /***********************************************************************/
  1370. #ifdef HAVE_PROTO
  1371. short go_to_new_field(long save_where,long where)
  1372. #else
  1373. short go_to_new_field(save_where,where)
  1374. long save_where,where;
  1375. #endif
  1376. /***********************************************************************/
  1377. {
  1378. /*------------------------- external data -----------------------------*/
  1379. /*--------------------------- local data ------------------------------*/
  1380.  short rc=RC_OK;
  1381.  long save_where_screen=0L,where_screen=0L;
  1382.  long save_where_window=0L,where_window=0L;
  1383.  unsigned short x=0;
  1384.  ROWTYPE where_row=0;
  1385. /*--------------------------- processing ------------------------------*/
  1386. #ifdef TRACE
  1387.  trace_function("cursor.c:  go_to_new_field");
  1388. #endif
  1389.  save_where_screen = save_where & WHERE_SCREEN_MASK;
  1390.  where_screen = where & WHERE_SCREEN_MASK;
  1391.  save_where_window = save_where & WHERE_WINDOW_MASK;
  1392.  where_window = where & WHERE_WINDOW_MASK;
  1393.  where_row = (ROWTYPE)(where & WHERE_ROW_MASK);
  1394.  if (save_where_screen != where_screen)
  1395.    {
  1396.    }
  1397.  if (save_where_window == where_window)
  1398. /*---------------------------------------------------------------------*/
  1399. /* No change to screen or window...                                    */
  1400. /*---------------------------------------------------------------------*/
  1401.     CURRENT_VIEW->focus_line = CURRENT_SCREEN.sl[where_row].line_number;
  1402.  else
  1403.    {
  1404.     switch(save_where_window)
  1405.       {
  1406.        case WHERE_WINDOW_FILEAREA:
  1407.             switch(where_window)
  1408.               {
  1409.                case WHERE_WINDOW_PREFIX_LEFT:
  1410.                case WHERE_WINDOW_PREFIX_RIGHT:
  1411.                     CURRENT_VIEW->current_window = WINDOW_PREFIX;
  1412.                     CURRENT_VIEW->focus_line = CURRENT_SCREEN.sl[where_row].line_number;
  1413.                     break;
  1414.                case WHERE_WINDOW_CMDLINE_TOP:
  1415.                case WHERE_WINDOW_CMDLINE_BOTTOM:
  1416.                     CURRENT_VIEW->previous_window = CURRENT_VIEW->current_window;
  1417.                     CURRENT_VIEW->current_window = WINDOW_COMMAND;
  1418.                     where_row = 0;
  1419.                     break;
  1420.               }
  1421.             break;
  1422.        case WHERE_WINDOW_PREFIX_LEFT:
  1423.        case WHERE_WINDOW_PREFIX_RIGHT:
  1424.             switch(where_window)
  1425.               {
  1426.                case WHERE_WINDOW_FILEAREA:
  1427.                     CURRENT_VIEW->current_window = WINDOW_FILEAREA;
  1428.                     CURRENT_VIEW->focus_line = CURRENT_SCREEN.sl[where_row].line_number;
  1429.                     break;
  1430.                case WHERE_WINDOW_CMDLINE_TOP:
  1431.                case WHERE_WINDOW_CMDLINE_BOTTOM:
  1432.                     CURRENT_VIEW->previous_window = CURRENT_VIEW->current_window;
  1433.                     CURRENT_VIEW->current_window = WINDOW_COMMAND;
  1434.                     where_row = 0;
  1435.                     break;
  1436.               }
  1437.             break;
  1438.        case WHERE_WINDOW_CMDLINE_TOP:
  1439.        case WHERE_WINDOW_CMDLINE_BOTTOM:
  1440.             switch(where_window)
  1441.               {
  1442.                case WHERE_WINDOW_PREFIX_LEFT:
  1443.                case WHERE_WINDOW_PREFIX_RIGHT:
  1444.                     CURRENT_VIEW->current_window = WINDOW_PREFIX;
  1445.                     CURRENT_VIEW->focus_line = CURRENT_SCREEN.sl[where_row].line_number;
  1446.                     break;
  1447.                case WHERE_WINDOW_FILEAREA:
  1448.                     CURRENT_VIEW->current_window = WINDOW_FILEAREA;
  1449.                     CURRENT_VIEW->focus_line = CURRENT_SCREEN.sl[where_row].line_number;
  1450.                     break;
  1451.               }
  1452.             break;
  1453.       }
  1454.    }
  1455. #if 0
  1456.  if (CURRENT_VIEW->current_window == WINDOW_PREFIX
  1457.  &&  (CURRENT_VIEW->prefix&PREFIX_LOCATION_MASK) == PREFIX_RIGHT)
  1458.     x = CURRENT_VIEW->prefix_gap;
  1459.  else
  1460.     x = 0;
  1461.  wmove(CURRENT_WINDOW,where_row,x);
  1462. #else
  1463.  wmove(CURRENT_WINDOW,where_row,0);
  1464. #endif
  1465. #ifdef TRACE
  1466.  trace_return();
  1467. #endif
  1468.  return(rc);
  1469. }
  1470. /***********************************************************************/
  1471. #ifdef HAVE_PROTO
  1472. void get_cursor_position(LINETYPE *screen_line,LINETYPE *screen_column,LINETYPE *file_line,LINETYPE *file_column)
  1473. #else
  1474. void get_cursor_position(screen_line,screen_column,file_line,file_column)
  1475. LINETYPE *screen_line,*screen_column,*file_line,*file_column;
  1476. #endif
  1477. /***********************************************************************/
  1478. {
  1479. /*------------------------- external data -----------------------------*/
  1480.  extern bool curses_started;
  1481. /*--------------------------- local data ------------------------------*/
  1482.  unsigned short y=0,x=0;
  1483.  unsigned short begy=0,begx=0;
  1484. /*--------------------------- processing ------------------------------*/
  1485. #ifdef TRACE
  1486.  trace_function("cursor.c:  get_cursor_position");
  1487. #endif
  1488.  if (curses_started)
  1489.    {
  1490.     getyx(CURRENT_WINDOW,y,x);
  1491.     getbegyx(CURRENT_WINDOW,begy,begx);
  1492.     *screen_line = (LINETYPE)(y + begy + 1L);
  1493.     *screen_column = (LINETYPE)(x + begx + 1L);
  1494.    }
  1495.  else
  1496.     *screen_line = *screen_column = (-1L);
  1497.  switch(CURRENT_VIEW->current_window)
  1498.    {
  1499.     case WINDOW_FILEAREA:
  1500.          *file_line = CURRENT_VIEW->focus_line;
  1501.          *file_column = (LINETYPE)x + (LINETYPE)CURRENT_VIEW->verify_col;
  1502.          break;
  1503.     case WINDOW_PREFIX:
  1504.          *file_line = CURRENT_VIEW->focus_line;
  1505.          *file_column = (-1L);
  1506.          break;
  1507.     default:   /* command line */
  1508.          *file_line = *file_column = (-1L);
  1509.          break;
  1510.    }
  1511. #ifdef TRACE
  1512.  trace_return();
  1513. #endif
  1514.  return;
  1515. }
  1516. /***********************************************************************/
  1517. #ifdef HAVE_PROTO
  1518. short advance_focus_line(LINETYPE num_lines)
  1519. #else
  1520. short advance_focus_line(num_lines)
  1521. LINETYPE num_lines;
  1522. #endif
  1523. /***********************************************************************/
  1524. {
  1525. /*------------------------- external data -----------------------------*/
  1526.  extern bool curses_started;
  1527. /*--------------------------- local data ------------------------------*/
  1528.  unsigned short y=0,x=0;
  1529.  LINE *curr=NULL;
  1530.  LINETYPE actual_lines=num_lines;
  1531.  short direction=DIRECTION_FORWARD;
  1532. /*--------------------------- processing ------------------------------*/
  1533. #ifdef TRACE
  1534.  trace_function("cursor.c:  advance_focus_line");
  1535. #endif
  1536.  if (num_lines < 0L)
  1537.    {
  1538.     actual_lines = -num_lines;
  1539.     direction = DIRECTION_BACKWARD;
  1540.    }
  1541.  post_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line,(LINE *)NULL,TRUE);
  1542.  curr = lll_find(CURRENT_FILE->first_line,CURRENT_FILE->last_line,CURRENT_VIEW->focus_line,CURRENT_FILE->number_lines);
  1543.  while(actual_lines>0)
  1544.     {
  1545.      if (direction == DIRECTION_BACKWARD)
  1546.         curr = curr->prev;
  1547.      else
  1548.         curr = curr->next;
  1549.      if (curr == NULL)
  1550.         break;
  1551.      CURRENT_VIEW->focus_line += (LINETYPE)direction;
  1552.      if (in_scope(CURRENT_VIEW,curr)
  1553.      || CURRENT_VIEW->scope_all)
  1554.         actual_lines--;
  1555.     }
  1556.  if (!line_in_view(current_screen,CURRENT_VIEW->focus_line))
  1557.     CURRENT_VIEW->current_line = CURRENT_VIEW->focus_line;
  1558.  pre_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line,(LINE *)NULL);
  1559.  build_screen(current_screen);
  1560.  display_screen(current_screen);
  1561.  if (curses_started)
  1562.    {
  1563.     getyx(CURRENT_WINDOW,y,x);
  1564.     y = get_row_for_focus_line(current_screen,CURRENT_VIEW->focus_line,
  1565.                                CURRENT_VIEW->current_row);
  1566.     wmove(CURRENT_WINDOW,y,x);
  1567.    }
  1568. #ifdef TRACE
  1569.  trace_return();
  1570. #endif
  1571.  if (FOCUS_TOF || FOCUS_BOF)
  1572.     return(RC_TOF_EOF_REACHED);
  1573.  else
  1574.     return(RC_OK);
  1575. }
  1576. /***********************************************************************/
  1577. #ifdef HAVE_PROTO
  1578. short advance_current_line(LINETYPE num_lines)
  1579. #else
  1580. short advance_current_line(num_lines)
  1581. LINETYPE num_lines;
  1582. #endif
  1583. /***********************************************************************/
  1584. {
  1585. /*------------------------- external data -----------------------------*/
  1586.  extern short compatible_feel;
  1587.  extern bool curses_started;
  1588. /*--------------------------- local data ------------------------------*/
  1589.  LINE *curr=NULL;
  1590.  LINETYPE actual_lines=num_lines;
  1591.  short direction=DIRECTION_FORWARD;
  1592.  short y=0,x=0;
  1593. /*--------------------------- processing ------------------------------*/
  1594. #ifdef TRACE
  1595.  trace_function("cursor.c:  advance_current_line");
  1596. #endif
  1597.  if (num_lines < 0L)
  1598.    {
  1599.     actual_lines = -num_lines;
  1600.     direction = DIRECTION_BACKWARD;
  1601.    }
  1602.  post_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line,(LINE *)NULL,TRUE);
  1603.  curr = lll_find(CURRENT_FILE->first_line,CURRENT_FILE->last_line,CURRENT_VIEW->current_line,CURRENT_FILE->number_lines);
  1604.  while(actual_lines>0)
  1605.     {
  1606.      if (direction == DIRECTION_BACKWARD)
  1607.         curr = curr->prev;
  1608.      else
  1609.         curr = curr->next;
  1610.      if (curr == NULL)
  1611.         break;
  1612.      CURRENT_VIEW->current_line += (LINETYPE)direction;
  1613.      if (in_scope(CURRENT_VIEW,curr)
  1614.      || CURRENT_VIEW->scope_all)
  1615.         actual_lines--;
  1616.     }
  1617.  build_screen(current_screen);
  1618.  if (!line_in_view(current_screen,CURRENT_VIEW->focus_line))
  1619.    {
  1620.     if (compatible_feel == COMPAT_XEDIT)
  1621.        cursor_cmdline(1);
  1622.     CURRENT_VIEW->focus_line = CURRENT_VIEW->current_line;
  1623.    }
  1624.  if (CURRENT_VIEW->current_window != WINDOW_COMMAND
  1625.  &&  line_in_view(current_screen,CURRENT_VIEW->focus_line)
  1626.  &&  compatible_feel == COMPAT_XEDIT)
  1627.    {
  1628.     if (CURRENT_VIEW->current_window == WINDOW_FILEAREA)
  1629.        getyx(CURRENT_WINDOW,y,x);
  1630.     y = get_row_for_focus_line(current_screen,CURRENT_VIEW->focus_line,CURRENT_VIEW->current_line);
  1631.     cursor_move(FALSE,y+1,x+1);
  1632.    }
  1633.  pre_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line,(LINE *)NULL);
  1634.  build_screen(current_screen);
  1635.  display_screen(current_screen);
  1636. #ifdef TRACE
  1637.  trace_return();
  1638. #endif
  1639.  if (CURRENT_TOF || CURRENT_BOF)
  1640.     return(RC_TOF_EOF_REACHED);
  1641.  else
  1642.     return(RC_OK);
  1643. }
  1644. /***********************************************************************/
  1645. #ifdef HAVE_PROTO
  1646. short advance_current_or_focus_line(LINETYPE num_lines)
  1647. #else
  1648. short advance_current_or_focus_line(num_lines)
  1649. LINETYPE num_lines;
  1650. #endif
  1651. /***********************************************************************/
  1652. {
  1653. /*------------------------- external data -----------------------------*/
  1654.  extern short compatible_feel;
  1655. /*--------------------------- local data ------------------------------*/
  1656.  short rc=RC_OK;
  1657. /*--------------------------- processing ------------------------------*/
  1658. #ifdef TRACE
  1659.  trace_function("cursor.c:  advance_current_or_focus_line");
  1660. #endif
  1661.  if (CURRENT_VIEW->current_window == WINDOW_COMMAND
  1662.  ||  compatible_feel == COMPAT_XEDIT)
  1663.     rc = advance_current_line(num_lines);
  1664.  else
  1665.     rc = advance_focus_line(num_lines);
  1666. #ifdef TRACE
  1667.  trace_return();
  1668. #endif
  1669.  return(rc);
  1670. }
  1671. /*man***************************************************************************
  1672. NAME
  1673.      resolve_current_and_focus_lines
  1674.  
  1675. SYNOPSIS
  1676.      void resolve_current_and_focus_lines(view,num_lines,direction,respect_stay)
  1677.      VIEW_DETAILS *view;
  1678.      LINETYPE true_line;
  1679.      LINETYPE num_lines;
  1680.      short direction;
  1681.      bool respect_stay;
  1682.  
  1683. DESCRIPTION
  1684.      This function determines the value of current_line and focus_line
  1685.      from the existing values of these variables, using the number of
  1686.      actual lines offset and direction passed as parameters.
  1687.  
  1688.      The num_lines parameter is the offset from either the focus or 
  1689.      current line expressed in file lines (ie ignores scope - SCOPE ALL)
  1690.      The true_line parameter is the value of either focus or current lien.
  1691.  
  1692.      This function determines what the new values for focus_line and 
  1693.      current_line are to be based on the status of STAY and of the
  1694.      current compatibility mode.  On return from this function, the
  1695.      screen will have been displayed with the correct positioning of
  1696.      the focus and current lines and the position of the cursor.
  1697.  
  1698.      If respect_stay is FALSE, then SET STAY is ignored (ie for PUT
  1699.      command).
  1700.  
  1701.      If sos is TRUE, then this function was called from a SOS command.
  1702.      All SOS commands should result in cursor movement as for THE
  1703.      compatibility mode.
  1704.  
  1705. RETURN VALUE
  1706.      void
  1707. *******************************************************************************/
  1708. #ifdef HAVE_PROTO
  1709. void resolve_current_and_focus_lines(VIEW_DETAILS *view, LINETYPE true_line, LINETYPE num_lines, short direction,bool respect_stay,bool sos)
  1710. #else
  1711. void resolve_current_and_focus_lines(view,true_line,num_lines,direction,respect_stay,sos)
  1712. VIEW_DETAILS *view;
  1713. LINETYPE true_line,num_lines;
  1714. short direction;
  1715. bool respect_stay;
  1716. bool sos;
  1717. #endif
  1718. /***********************************************************************/
  1719. {
  1720. /*------------------------- external data -----------------------------*/
  1721.  extern short compatible_feel;
  1722.  extern bool curses_started;
  1723. /*--------------------------- local data ------------------------------*/
  1724.  short rc=RC_OK;
  1725.  short y=0,x=0;
  1726.  short save_compatible_feel=compatible_feel;
  1727. /*--------------------------- processing ------------------------------*/
  1728. #ifdef TRACE
  1729.  trace_function("cursor.c:  resolve_current_and_focus_lines");
  1730. #endif
  1731. /*---------------------------------------------------------------------*/
  1732. /* If no lines to move, don't do anything...                           */
  1733. /*---------------------------------------------------------------------*/
  1734.  if (num_lines == 0)
  1735.    {
  1736.     build_screen(current_screen);
  1737.     display_screen(current_screen);
  1738. #ifdef TRACE
  1739.     trace_return();
  1740. #endif
  1741.     return;
  1742.    }
  1743. /*---------------------------------------------------------------------*/
  1744. /* Set the internal compatibility mode to THE for sos = TRUE.          */
  1745. /*---------------------------------------------------------------------*/
  1746.  if (sos)
  1747.     save_compatible_feel = COMPAT_THE;
  1748. /*---------------------------------------------------------------------*/
  1749. /* If STAY is ON, and we are respecting it, don't do anything...       */
  1750. /*---------------------------------------------------------------------*/
  1751.  if (view->stay
  1752.  && (respect_stay || compatible_feel != COMPAT_XEDIT))
  1753.    {
  1754.     build_screen(current_screen);
  1755.     display_screen(current_screen);
  1756. #ifdef TRACE
  1757.     trace_return();
  1758. #endif
  1759.     return;
  1760.    }
  1761. /*---------------------------------------------------------------------*/
  1762. /* If we are on the command line, all actions are the same irrespective*/
  1763. /* of the compatibility mode in place.                                 */
  1764. /*---------------------------------------------------------------------*/
  1765.  if (view->current_window == WINDOW_COMMAND)
  1766.    {
  1767.     view->current_line = true_line+num_lines-(LINETYPE)direction;
  1768.     build_screen(current_screen);
  1769.     display_screen(current_screen);
  1770. #ifdef TRACE
  1771.     trace_return();
  1772. #endif
  1773.     return;
  1774.    }
  1775. /*---------------------------------------------------------------------*/
  1776. /* From here down is applicable to the cursor being in the FILEAREA or */
  1777. /* PREFIX...                                                           */
  1778. /*---------------------------------------------------------------------*/
  1779.  switch(save_compatible_feel)
  1780.    {
  1781.     case COMPAT_THE:
  1782.     case COMPAT_KEDIT:
  1783.          view->focus_line = true_line+num_lines-(LINETYPE)direction;
  1784.          build_screen(current_screen);
  1785.          if (!line_in_view(current_screen,view->focus_line))
  1786.             view->current_line = view->focus_line;
  1787.          pre_process_line(view,view->focus_line,(LINE *)NULL);
  1788.          build_screen(current_screen);
  1789.          display_screen(current_screen);
  1790.          if (curses_started)
  1791.            {
  1792.             getyx(SCREEN_WINDOW(current_screen),y,x);
  1793.             y = get_row_for_focus_line(current_screen,view->focus_line,
  1794.                                view->current_row);
  1795.             wmove(SCREEN_WINDOW(current_screen),y,x);
  1796.            }
  1797.          break;
  1798.     case COMPAT_XEDIT:
  1799.          view->current_line = true_line+num_lines-(LINETYPE)direction;
  1800.          pre_process_line(view,view->focus_line,(LINE *)NULL);
  1801.          build_screen(current_screen);
  1802.          if (!line_in_view(current_screen,view->focus_line))
  1803.             cursor_cmdline(1);
  1804.          else
  1805.            {
  1806.             if (curses_started)
  1807.               {
  1808.                if (view->current_window == WINDOW_FILEAREA)
  1809.                   getyx(SCREEN_WINDOW(current_screen),y,x);
  1810.                y = get_row_for_focus_line(current_screen,view->focus_line,view->current_line);
  1811.                cursor_move(FALSE,y+1,x+1);
  1812.               }
  1813.            }
  1814.          display_screen(current_screen);
  1815.          break;
  1816.    }
  1817. #ifdef TRACE
  1818.  trace_return();
  1819. #endif
  1820.  return;
  1821. }
  1822.