home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / the25.zip / thesrc251.zip / comm1.c < prev    next >
C/C++ Source or Header  |  1998-06-08  |  79KB  |  2,512 lines

  1. /***********************************************************************/
  2. /* COMM1.C - Commands A-C                                              */
  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: comm1.c 2.1 1995/06/24 16:28:44 MH Rel MH $
  43. */
  44.  
  45. #include <the.h>
  46. #include <proto.h>
  47.  
  48. /*#define DEBUG 1*/
  49.  
  50. /*man-start*********************************************************************
  51.  
  52.  
  53. ========================================================================
  54. COMMAND REFERENCE
  55. ========================================================================
  56. **man-end**********************************************************************/
  57.  
  58. /*man-start*********************************************************************
  59. COMMAND
  60.      add - add blank line
  61.  
  62. SYNTAX
  63.      Add [n]
  64.  
  65. DESCRIPTION
  66.      The ADD command inserts 'n' blank lines after the <current line>,
  67.      if issued from the <command line> or after the <focus line>, 
  68.      if issued from the <filearea> or <prefix area>.
  69.  
  70.      If <SET NEWLINES> is set to ALIGNED, the cursor is positioned in
  71.      the column corresponding to the first column not containing a 
  72.      space in the line above.
  73.  
  74.      If <SET NEWLINES> is set to LEFT, the cursor is positioned in the
  75.      first column.
  76.  
  77. COMPATIBILITY
  78.      XEDIT: Compatible.
  79.      KEDIT: Compatible.
  80.  
  81. DEFAULT
  82.      1
  83.  
  84. SEE ALSO
  85.      <SOS ADDLINE>
  86.  
  87. STATUS
  88.      Complete
  89. **man-end**********************************************************************/
  90. #ifdef HAVE_PROTO
  91. short Add(CHARTYPE *params)
  92. #else
  93. short Add(params)
  94. CHARTYPE *params;
  95. #endif
  96. /***********************************************************************/
  97. {
  98. /*-------------------------- external data ----------------------------*/
  99.  extern bool curses_started;
  100. /*--------------------------- local data ------------------------------*/
  101. #define ADD_PARAMS  1
  102.  CHARTYPE *word[ADD_PARAMS+1];
  103.  CHARTYPE strip[ADD_PARAMS];
  104.  unsigned short num_params=0;
  105.  LINETYPE num_lines=0L;
  106. /*--------------------------- processing ------------------------------*/
  107. #ifdef TRACE
  108.  trace_function("comm1.c:   Add");
  109. #endif
  110. /*---------------------------------------------------------------------*/
  111. /* Validate the parameters that have been supplied. The one and only   */
  112. /* parameter should be a positive integer greater than zero.           */
  113. /* If no parameter is supplied, 1 is assumed.                          */
  114. /*---------------------------------------------------------------------*/
  115.  strip[0]=STRIP_BOTH;
  116.  num_params = param_split(params,word,ADD_PARAMS,WORD_DELIMS,TEMP_PARAM,strip,FALSE);
  117.  if (num_params == 0)
  118.    {
  119.     num_params = 1;
  120.     word[0] = (CHARTYPE *)"1";
  121.    }
  122.  if (num_params != 1)
  123.    {
  124.     display_error(1,word[1],FALSE);
  125. #ifdef TRACE
  126.     trace_return();
  127. #endif
  128.     return(RC_INVALID_OPERAND);
  129.    }
  130.  if (!valid_positive_integer(word[0]))
  131.    {
  132.     display_error(4,word[0],FALSE);
  133. #ifdef TRACE
  134.     trace_return();
  135. #endif
  136.     return(RC_INVALID_OPERAND);
  137.    }
  138.  num_lines = atol((DEFCHAR *)word[0]);
  139.  post_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line,(LINE *)NULL,TRUE);
  140.  insert_new_line((CHARTYPE *)"",0,num_lines,get_true_line(TRUE),FALSE,FALSE,TRUE,CURRENT_VIEW->display_low,TRUE,FALSE);
  141.  if (curses_started
  142.  && CURRENT_VIEW->current_window == WINDOW_COMMAND)
  143.     cursor_home(TRUE);
  144. #ifdef TRACE
  145.  trace_return();
  146. #endif
  147.  return(RC_OK);
  148. }
  149. /*man-start*********************************************************************
  150. COMMAND
  151.      all - select and display restricted set of lines
  152.  
  153. SYNTAX
  154.      ALL [rtarget]
  155.  
  156. DESCRIPTION
  157.      The ALL command allows for the selective display, and editting
  158.      (subject to <SET SCOPE>) of lines that match the specified target.
  159.      This target consists of any number of individual targets
  160.      seperated by '&' (logical and) or '|' (logical or). 
  161.  
  162.      For example, to display all lines in a file that contain the 
  163.      strings 'ball' and 'cat' on the same line or the named lines 
  164.      .fred or .bill, use the following command
  165.  
  166.      ALL /ball/ & /cat/ | .fred | .bill
  167.  
  168.      Logical operators act left to right, with no precedence for &.
  169.  
  170.      ALL without any arguments, is the equivalent of setting the
  171.      selection level of all lines in your file to 0 and running
  172.      <SET DISPLAY> 0 0.
  173.  
  174. COMPATIBILITY
  175.      XEDIT: Compatible.
  176.      KEDIT: Compatible.
  177.  
  178. SEE ALSO
  179.      <SET SCOPE>, <SET DISPLAY>, <SET SELECT>
  180.  
  181. STATUS
  182.      Complete.
  183. **man-end**********************************************************************/
  184. #ifdef HAVE_PROTO
  185. short All(CHARTYPE *params)
  186. #else
  187. short All(params)
  188. CHARTYPE *params;
  189. #endif
  190. /***********************************************************************/
  191. {
  192. /*-------------------------- external data ----------------------------*/
  193. /*--------------------------- local data ------------------------------*/
  194.  short rc=RC_OK;
  195.  LINE *curr=NULL;
  196.  bool target_found=FALSE;
  197.  short status=RC_OK;
  198.  short target_type=TARGET_NORMAL;
  199.  TARGET target;
  200.  LINETYPE line_number=0L;
  201.  unsigned short x=0,y=0;
  202.  bool save_scope=FALSE;
  203.  LINETYPE num_lines=0L;
  204. /*--------------------------- processing ------------------------------*/
  205. #ifdef TRACE
  206.  trace_function("comm1.c:   All");
  207. #endif
  208.  if (strlen((DEFCHAR *)params) == 0)
  209.    {
  210.     if (CURRENT_FILE->number_lines == 0L)
  211.       {
  212. #ifdef TRACE
  213.        trace_return();
  214. #endif
  215.        return(rc);
  216.       }
  217.     post_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line,(LINE *)NULL,TRUE);
  218.     curr = CURRENT_FILE->first_line->next;
  219.     while(1)
  220.       {
  221.        curr->select = 0;
  222.        curr = curr->next;
  223.        if (curr->next == NULL)
  224.           break;
  225.       }
  226.     CURRENT_VIEW->display_low = 0;
  227.     CURRENT_VIEW->display_high = 0;
  228.     build_screen(current_screen); 
  229.     display_screen(current_screen);
  230. #ifdef TRACE
  231.     trace_return();
  232. #endif
  233.     return(rc);
  234.    }
  235.  if (CURRENT_FILE->number_lines == 0L)
  236.    {
  237.     display_error(17,params,FALSE);
  238. #ifdef TRACE
  239.     trace_return();
  240. #endif
  241.     return(RC_TARGET_NOT_FOUND);
  242.    }
  243. /*---------------------------------------------------------------------*/
  244. /* Validate the parameters as valid targets...                         */
  245. /*---------------------------------------------------------------------*/
  246.  initialise_target(&target);
  247.  rc = parse_target(params,get_true_line(TRUE),&target,target_type,TRUE,TRUE,FALSE);
  248.  if (rc != RC_OK)
  249.    {
  250.     free_target(&target);
  251. #ifdef TRACE
  252.     trace_return();
  253. #endif
  254.     return(RC_INVALID_OPERAND);
  255.    }
  256. /*---------------------------------------------------------------------*/
  257. /* Save the select levels for all lines in case no target is found.    */
  258. /*---------------------------------------------------------------------*/
  259.  curr = CURRENT_FILE->first_line->next;
  260.  while(1)
  261.    {
  262.     curr->save_select = curr->select;
  263.     curr = curr->next;
  264.     if (curr->next == NULL)
  265.        break;
  266.    }
  267. /*---------------------------------------------------------------------*/
  268. /* Find all lines for the supplied target...                           */
  269. /*---------------------------------------------------------------------*/
  270.  curr = CURRENT_FILE->first_line;
  271.  status = FALSE;
  272.  save_scope = CURRENT_VIEW->scope_all;
  273.  CURRENT_VIEW->scope_all = TRUE;
  274.  for (line_number=0L;curr->next != NULL;line_number++)
  275.    {
  276.     status = find_rtarget_target(curr,&target,0L,line_number,&num_lines);
  277.     if (status == RC_OK) /* target found */
  278.       {
  279.        target_found = TRUE;
  280.        curr->select = 1;
  281.       }
  282.     else if (status == RC_TARGET_NOT_FOUND) /* target not found */
  283.        curr->select = 0;
  284.     else  /* error */
  285.        break;
  286.     curr = curr->next;
  287.    }
  288. /*---------------------------------------------------------------------*/
  289. /* If at least one line matches the target, set DISPLAY to 1 1,        */
  290. /* otherwise reset the select levels as they were before the command.  */
  291. /*---------------------------------------------------------------------*/
  292.  if (target_found)
  293.    {
  294.     post_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line,(LINE *)NULL,TRUE);
  295.     CURRENT_VIEW->display_low = 1;
  296.     CURRENT_VIEW->display_high = 1;
  297.     CURRENT_VIEW->scope_all = FALSE;
  298.     CURRENT_VIEW->current_line = find_next_in_scope(CURRENT_VIEW,CURRENT_FILE->first_line->next,1L,DIRECTION_FORWARD);
  299.     build_screen(current_screen); 
  300.     display_screen(current_screen);
  301.     CURRENT_VIEW->focus_line = calculate_focus_line(CURRENT_VIEW->focus_line,
  302.                                                     CURRENT_VIEW->current_line);
  303.     pre_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line,(LINE *)NULL);
  304.     if (CURRENT_VIEW->current_window != WINDOW_COMMAND)
  305.       {
  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.        wmove(CURRENT_WINDOW,y,x);
  310.       }
  311.    }
  312.   else
  313.    {
  314.     CURRENT_VIEW->scope_all = save_scope;
  315.     curr = CURRENT_FILE->first_line->next;
  316.     while(1)
  317.       {
  318.        curr->select = curr->save_select;
  319.        curr = curr->next;
  320.        if (curr->next == NULL)
  321.           break;
  322.       }
  323.     if (status == RC_TARGET_NOT_FOUND)
  324.       {
  325.        display_error(17,params,FALSE);
  326.        rc = RC_TARGET_NOT_FOUND;
  327.       }
  328.     else
  329.        rc = status;
  330.    }
  331.  free_target(&target);
  332. #ifdef TRACE
  333.  trace_return();
  334. #endif
  335.  return(rc);
  336. }
  337. /*man-start*********************************************************************
  338. COMMAND
  339.      backward - scroll backwards [n] screens
  340.  
  341. SYNTAX
  342.      BAckward [n|*]
  343.  
  344. DESCRIPTION
  345.      The BACKWARD command scrolls the file contents backwards through
  346.      the file 'n' or '*' screens.
  347.  
  348.      If 0 is specified as the number of screens to scroll, the last
  349.      line of the file becomes the <current line>.
  350.  
  351.      If the BACKWARD command is issued while the current line is
  352.      the <Top-of-File line>, the last line of the file becomes the
  353.      <current line>.
  354.  
  355. COMPATIBILITY
  356.      XEDIT: Compatible.
  357.      KEDIT: Does not support HALF or Lines options.
  358.  
  359. DEFAULT
  360.      1
  361.  
  362. SEE ALSO
  363.      <FORWARD>, <TOP>
  364.  
  365. STATUS
  366.      Complete
  367. **man-end**********************************************************************/
  368. #ifdef HAVE_PROTO
  369. short Backward(CHARTYPE *params)
  370. #else
  371. short Backward(params)
  372. CHARTYPE *params;
  373. #endif
  374. /***********************************************************************/
  375. {
  376. /*-------------------------- external data ----------------------------*/
  377. /*--------------------------- local data ------------------------------*/
  378. #define BAC_PARAMS  1
  379.  CHARTYPE *word[BAC_PARAMS+1];
  380.  CHARTYPE strip[BAC_PARAMS];
  381.  unsigned short num_params=0;
  382.  LINETYPE num_pages=0L;
  383.  short rc=RC_OK;
  384. /*--------------------------- processing ------------------------------*/
  385. #ifdef TRACE
  386.  trace_function("comm1.c:   Backward");
  387. #endif
  388. /*---------------------------------------------------------------------*/
  389. /* Validate parameters...                                              */
  390. /*---------------------------------------------------------------------*/
  391.  strip[0]=STRIP_BOTH;
  392.  num_params = param_split(params,word,BAC_PARAMS,WORD_DELIMS,TEMP_PARAM,strip,FALSE);
  393.  if (num_params == 0)
  394.     {
  395.      num_params = 1;
  396.      word[0] = (CHARTYPE *)"1";
  397.     }
  398.  if (num_params != 1)
  399.     {
  400.      display_error(1,(CHARTYPE *)word[1],FALSE);
  401. #ifdef TRACE
  402.     trace_return();
  403. #endif
  404.      return(RC_INVALID_OPERAND);
  405.     }
  406. /*---------------------------------------------------------------------*/
  407. /* If parameter is '*', set current line equal to "Top of File".       */
  408. /*---------------------------------------------------------------------*/
  409.  if (strcmp((DEFCHAR *)word[0],"*") == 0)
  410.    {
  411.     rc = Top((CHARTYPE *)"");
  412. #ifdef TRACE
  413.     trace_return();
  414. #endif
  415.     return(rc);
  416.    }
  417. /*---------------------------------------------------------------------*/
  418. /* If the parameter is not a valid integer, error.                     */
  419. /*---------------------------------------------------------------------*/
  420.  if (!valid_integer(word[0]))
  421.    {
  422.     display_error(1,(CHARTYPE *)word[0],FALSE);
  423. #ifdef TRACE
  424.     trace_return();
  425. #endif
  426.     return(RC_INVALID_OPERAND);
  427.    }
  428. /*---------------------------------------------------------------------*/
  429. /* Number of screens to scroll is set here.                            */
  430. /*---------------------------------------------------------------------*/
  431.  num_pages = atol((DEFCHAR *)word[0]);
  432. /*---------------------------------------------------------------------*/
  433. /* If the number specified is < 0, error...                            */
  434. /*---------------------------------------------------------------------*/
  435.  if (num_pages < 0L)
  436.    {
  437.     display_error(5,(CHARTYPE *)word[0],FALSE);
  438. #ifdef TRACE
  439.     trace_return();
  440. #endif
  441.     return(RC_INVALID_OPERAND);
  442.    }
  443. /*---------------------------------------------------------------------*/
  444. /* If the current line is already on "Top of File" or the parameter is */
  445. /* 0, go to the bottom of the file.                                    */
  446. /*---------------------------------------------------------------------*/
  447.  if (num_pages == 0
  448.  || CURRENT_TOF)
  449.    {
  450.     rc = Bottom((CHARTYPE *)"");
  451. #ifdef TRACE
  452.     trace_return();
  453. #endif
  454.     return(rc);
  455.    }
  456. /*---------------------------------------------------------------------*/
  457. /* Scroll the screen num_pages...                                      */
  458. /*---------------------------------------------------------------------*/
  459.  rc = scroll_page(DIRECTION_BACKWARD,num_pages,FALSE);
  460. #ifdef TRACE
  461.  trace_return();
  462. #endif
  463.  return(rc);
  464. }
  465. /*man-start*********************************************************************
  466. COMMAND
  467.      bottom - move to the bottom of the file
  468.  
  469. SYNTAX
  470.      Bottom
  471.  
  472. DESCRIPTION
  473.      The BOTTOM command moves to the very end of the current file.
  474.      The last line of the file is set to the <current line>.
  475.  
  476. COMPATIBILITY
  477.      XEDIT: Compatible.
  478.      KEDIT: Compatible.
  479.  
  480. SEE ALSO
  481.      <FORWARD>, <TOP>
  482.  
  483. STATUS
  484.      Complete
  485. **man-end**********************************************************************/
  486. #ifdef HAVE_PROTO
  487. short Bottom(CHARTYPE *params)
  488. #else
  489. short Bottom(params)
  490. CHARTYPE *params;
  491. #endif
  492. /***********************************************************************/
  493. {
  494. /*-------------------------- external data ----------------------------*/
  495.  extern bool curses_started;
  496. /*--------------------------- local data ------------------------------*/
  497.  short rc=RC_OK;
  498.  unsigned short x=0,y=0;
  499. /*--------------------------- processing ------------------------------*/
  500. #ifdef TRACE
  501.  trace_function("comm1.c:   Bottom");
  502. #endif
  503. /*---------------------------------------------------------------------*/
  504. /* No arguments are allowed; error if any are present.                 */
  505. /*---------------------------------------------------------------------*/
  506.  if (strcmp((DEFCHAR *)params,"") != 0)
  507.    {
  508.     display_error(1,(CHARTYPE *)params,FALSE);
  509. #ifdef TRACE
  510.     trace_return();
  511. #endif
  512.     return(RC_INVALID_OPERAND);
  513.    }
  514.  if (CURRENT_VIEW->scope_all)
  515.     CURRENT_VIEW->current_line = CURRENT_FILE->number_lines;
  516.  else
  517.     CURRENT_VIEW->current_line = find_next_in_scope(CURRENT_VIEW,CURRENT_FILE->last_line->prev,CURRENT_FILE->number_lines,DIRECTION_BACKWARD);
  518.  post_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line,(LINE *)NULL,TRUE);
  519.  build_screen(current_screen); 
  520.  if (!line_in_view(current_screen,CURRENT_VIEW->focus_line))
  521.     CURRENT_VIEW->focus_line = CURRENT_VIEW->current_line;
  522.  pre_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line,(LINE *)NULL);
  523.  if (curses_started)
  524.    {
  525.     if (CURRENT_VIEW->current_window == WINDOW_COMMAND)
  526.        getyx(CURRENT_PREV_WINDOW,y,x);
  527.     else
  528.        getyx(CURRENT_WINDOW,y,x);
  529.     display_screen(current_screen);
  530.     y = get_row_for_focus_line(current_screen,CURRENT_VIEW->focus_line,
  531.                                CURRENT_VIEW->current_row);
  532.     if (CURRENT_VIEW->current_window == WINDOW_COMMAND)
  533.        wmove(CURRENT_PREV_WINDOW,y,x);
  534.     else
  535.        wmove(CURRENT_WINDOW,y,x);
  536.    }
  537. #ifdef TRACE
  538.  trace_return();
  539. #endif
  540.  return(rc);
  541. }
  542. /*man-start*********************************************************************
  543. COMMAND
  544.      cancel - quit from all unaltered files in the ring
  545.  
  546. SYNTAX
  547.      CANcel
  548.  
  549. DESCRIPTION
  550.      The CANCEL command exits from THE quickly by executing a <QQUIT>
  551.      command for every file in the ring that does not have any 
  552.      outstanding alterations.
  553.  
  554. COMPATIBILITY
  555.      XEDIT: Compatible.
  556.      KEDIT: Compatible.
  557.  
  558. SEE ALSO
  559.      <CCANCEL>
  560.  
  561. STATUS
  562.      Complete.
  563. **man-end**********************************************************************/
  564. #ifdef HAVE_PROTO
  565. short Cancel(CHARTYPE *params)
  566. #else
  567. short Cancel(params)
  568. CHARTYPE *params;
  569. #endif
  570. /***********************************************************************/
  571. {
  572. /*-------------------------- external data ----------------------------*/
  573.  extern VIEW_DETAILS *vd_first;
  574.  extern bool curses_started;
  575.  extern CHARTYPE number_of_files;
  576.  extern CHARTYPE *temp_cmd;
  577. /*--------------------------- local data ------------------------------*/
  578.  VIEW_DETAILS *save_current_view=(VIEW_DETAILS *)NULL;
  579.  CHARTYPE save_number_of_files=number_of_files;
  580.  register int i=0;
  581. /*--------------------------- processing ------------------------------*/
  582. #ifdef TRACE
  583.  trace_function("comm1.c:   Cancel");
  584. #endif
  585. /*---------------------------------------------------------------------*/
  586. /* No arguments are allowed; error if any are present.                 */
  587. /*---------------------------------------------------------------------*/
  588.  if (strcmp((DEFCHAR *)params,"") != 0)
  589.    {
  590.     display_error(1,(CHARTYPE *)params,FALSE);
  591. #ifdef TRACE
  592.     trace_return();
  593. #endif
  594.     return(RC_INVALID_OPERAND);
  595.    }
  596.  post_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line,(LINE *)NULL,TRUE);
  597. #if 0
  598.  CURRENT_VIEW = vd_first;
  599.  while (CURRENT_VIEW != (VIEW_DETAILS *)NULL)
  600.    {
  601.     if (CURRENT_FILE->save_alt == 0)
  602.        free_view_memory(TRUE);
  603.     else
  604.       {
  605.        save_current_view = CURRENT_VIEW;
  606.        CURRENT_VIEW = CURRENT_VIEW->next;
  607.       }
  608.    }
  609. #else
  610.  for (i=0;i<save_number_of_files;i++)
  611.    {
  612.     if (CURRENT_FILE->save_alt == 0)
  613.        free_view_memory(TRUE,FALSE);
  614.     else
  615.       {
  616.        save_current_view = CURRENT_VIEW;
  617.        CURRENT_VIEW = CURRENT_VIEW->next;
  618.        if (CURRENT_VIEW == NULL)
  619.           CURRENT_VIEW = vd_first;
  620.       }
  621.    }
  622. #endif
  623.  if (save_current_view != (VIEW_DETAILS *)NULL)
  624.    {
  625.     CURRENT_VIEW = save_current_view;
  626.     CURRENT_SCREEN.screen_view = CURRENT_VIEW;
  627.     pre_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line,(LINE *)NULL);
  628.     build_screen(current_screen); 
  629.     display_screen(current_screen);
  630.     if (curses_started)
  631.       {
  632.        if (CURRENT_WINDOW_PREFIX != NULL)
  633.           touchwin(CURRENT_WINDOW_PREFIX);
  634.        if (CURRENT_WINDOW_COMMAND != NULL)
  635.           touchwin(CURRENT_WINDOW_COMMAND);
  636.        touchwin(CURRENT_WINDOW_FILEAREA);
  637.        touchwin(CURRENT_WINDOW);
  638.       }
  639.    }
  640.  if (number_of_files > 0)
  641.    {
  642.     sprintf((DEFCHAR *)temp_cmd,"%d file(s) remain with outstanding changes",number_of_files);
  643.     display_error(0,(CHARTYPE *)temp_cmd,TRUE);
  644.    }
  645. #ifdef TRACE
  646.  trace_return();
  647. #endif
  648.  return(QUIT);
  649. }
  650. /*man-start*********************************************************************
  651. COMMAND
  652.      cappend - append text after column pointer
  653.  
  654. SYNTAX
  655.      CAppend [text]
  656.  
  657. DESCRIPTION
  658.      The CAPPEND command moves the column pointer to the end of the
  659.      focus line and appends the specified 'text'.
  660.  
  661.      If no 'text' is specified, the column pointer moves to the first
  662.      trailing space.
  663.  
  664. COMPATIBILITY
  665.      XEDIT: Compatible.
  666.      KEDIT: Compatible.
  667.  
  668. SEE ALSO
  669.      <CLAST>
  670.  
  671. STATUS
  672.      Complete.
  673. **man-end**********************************************************************/
  674. #ifdef HAVE_PROTO
  675. short Cappend(CHARTYPE *params)
  676. #else
  677. short Cappend(params)
  678. CHARTYPE *params;
  679. #endif
  680. /***********************************************************************/
  681. {
  682. /*-------------------------- external data ----------------------------*/
  683. /*--------------------------- local data ------------------------------*/
  684.  short rc=RC_OK;
  685. /*--------------------------- processing ------------------------------*/
  686. #ifdef TRACE
  687.  trace_function("comm1.c:   Cappend");
  688. #endif
  689.  rc = column_command(params,COLUMN_CAPPEND);
  690. #ifdef TRACE
  691.  trace_return();
  692. #endif
  693.  return(rc);
  694. }
  695. /*man-start*********************************************************************
  696. COMMAND
  697.      ccancel - qquit from all files in the ring
  698.  
  699. SYNTAX
  700.      CCancel
  701.  
  702. DESCRIPTION
  703.      The CCANCEL command exits from THE quickly by executing the <QQUIT>
  704.      command for every file in the ring. Any changes made to any of 
  705.      the files since the last <SAVE> will be lost.
  706.  
  707. COMPATIBILITY
  708.      XEDIT: N/A
  709.      KEDIT: N/A
  710.  
  711. SEE ALSO
  712.      <CANCEL>
  713.  
  714. STATUS
  715.      Complete.
  716. **man-end**********************************************************************/
  717. #ifdef HAVE_PROTO
  718. short Ccancel(CHARTYPE *params)
  719. #else
  720. short Ccancel(params)
  721. CHARTYPE *params;
  722. #endif
  723. /***********************************************************************/
  724. {
  725. /*-------------------------- external data ----------------------------*/
  726.  extern VIEW_DETAILS *vd_first;
  727. /*--------------------------- local data ------------------------------*/
  728. /*--------------------------- processing ------------------------------*/
  729. #ifdef TRACE
  730.  trace_function("comm1.c:   Ccancel");
  731. #endif
  732. /*---------------------------------------------------------------------*/
  733. /* No arguments are allowed; error if any are present.                 */
  734. /*---------------------------------------------------------------------*/
  735.  if (strcmp((DEFCHAR *)params,"") != 0)
  736.    {
  737.     display_error(1,(CHARTYPE *)params,FALSE);
  738. #ifdef TRACE
  739.     trace_return();
  740. #endif
  741.     return(RC_INVALID_OPERAND);
  742.    }
  743.  CURRENT_VIEW = vd_first;
  744.  while (CURRENT_VIEW != (VIEW_DETAILS *)NULL)
  745.    {
  746.     free_view_memory(TRUE,FALSE);
  747.    }
  748. #ifdef TRACE
  749.  trace_return();
  750. #endif
  751.  return(QUIT);
  752. }
  753. /*man-start*********************************************************************
  754. COMMAND
  755.      cdelete - delete text starting at column pointer
  756.  
  757. SYNTAX
  758.      CDelete [column target]
  759.  
  760. DESCRIPTION
  761.      The CDELETE command deletes characters starting from the current
  762.      column pointer for the specified <'column target'>.
  763.  
  764.      If no <'column target'> is specified, the character at the column
  765.      pointer is deleted.
  766.  
  767. COMPATIBILITY
  768.      XEDIT: Compatible.
  769.      KEDIT: Compatible.
  770.  
  771. STATUS
  772.      Incomplete. No string targets.
  773. **man-end**********************************************************************/
  774. #ifdef HAVE_PROTO
  775. short Cdelete(CHARTYPE *params)
  776. #else
  777. short Cdelete(params)
  778. CHARTYPE *params;
  779. #endif
  780. /***********************************************************************/
  781. {
  782. /*-------------------------- external data ----------------------------*/
  783.  extern CHARTYPE *rec;
  784.  extern LENGTHTYPE rec_len;
  785. /*--------------------------- local data ------------------------------*/
  786.  short rc=RC_OK;
  787.  short target_type=TARGET_ABSOLUTE|TARGET_RELATIVE|TARGET_STRING|TARGET_BLANK;
  788.  TARGET target;
  789.  LENGTHTYPE start_col=0,del_start=0;
  790.  unsigned int y=0,x=0;
  791. /*--------------------------- processing ------------------------------*/
  792. #ifdef TRACE
  793.  trace_function("comm1.c:   Cdelete");
  794. #endif
  795. /*---------------------------------------------------------------------*/
  796. /* Validate the cursor position...                                     */
  797. /*---------------------------------------------------------------------*/
  798.  if (CURRENT_VIEW->current_window != WINDOW_COMMAND)
  799.    {
  800.     getyx(CURRENT_WINDOW,y,x);
  801.     rc = processable_line(CURRENT_VIEW,CURRENT_SCREEN.sl[y].line_number,CURRENT_SCREEN.sl[y].current);
  802.     switch(rc)
  803.       {
  804.        case LINE_SHADOW:
  805.             display_error(87,(CHARTYPE *)"",FALSE);
  806. #ifdef TRACE
  807.             trace_return();
  808. #endif
  809.             return(RC_INVALID_OPERAND);
  810.             break;
  811. /*       case LINE_TOF_EOF: MH12 */
  812.        case LINE_TOF:
  813.        case LINE_EOF:
  814.             display_error(36,(CHARTYPE *)"",FALSE);
  815. #ifdef TRACE
  816.             trace_return();
  817. #endif
  818.             return(RC_INVALID_OPERAND);
  819.             break;
  820.        default:
  821.             break;
  822.       }
  823.    }
  824. /*---------------------------------------------------------------------*/
  825. /* Determine at which column to start the search...                    */
  826. /*---------------------------------------------------------------------*/
  827.  switch (CURRENT_VIEW->current_window)
  828.    {
  829.     case WINDOW_FILEAREA:
  830.          start_col = (CURRENT_VIEW->verify_col) + x;
  831.          if (start_col > CURRENT_VIEW->zone_end)
  832.             start_col = min(max_line_length,CURRENT_VIEW->zone_end+1);
  833.          if (start_col < CURRENT_VIEW->zone_start)
  834.             start_col = max(1,CURRENT_VIEW->zone_start-1);
  835.          break;
  836.     case WINDOW_PREFIX:
  837.          start_col = max(CURRENT_VIEW->current_column,max(1,CURRENT_VIEW->zone_start));
  838.          break;
  839.     case WINDOW_COMMAND:
  840.          pre_process_line(CURRENT_VIEW,CURRENT_VIEW->current_line,(LINE *)NULL);
  841.          start_col = CURRENT_VIEW->current_column;
  842.          break;
  843.    }
  844. /*---------------------------------------------------------------------*/
  845. /* Validate the parameters as valid targets...                         */
  846. /*---------------------------------------------------------------------*/
  847.  initialise_target(&target);
  848.  rc = parse_target(params,(LINETYPE)start_col,&target,target_type,TRUE,TRUE,TRUE);
  849.  if (rc != RC_OK)
  850.    {
  851.     free_target(&target);
  852. #ifdef TRACE
  853.     trace_return();
  854. #endif
  855.     return(RC_INVALID_OPERAND);
  856.    }
  857. /*---------------------------------------------------------------------*/
  858. /* Find the valid column target. If found process the command...       */
  859. /*---------------------------------------------------------------------*/
  860.  if ((find_column_target(rec,rec_len,&target,start_col,TRUE,TRUE)) == RC_OK)
  861.    {
  862.     CURRENT_VIEW->current_column = start_col;
  863.     if (target.num_lines < 0)
  864.       {
  865.        if (start_col > CURRENT_VIEW->zone_end)
  866.          {
  867.           start_col--;
  868.           target.num_lines++;
  869.          }
  870.        del_start = start_col+target.num_lines;
  871.        (void)memdeln(rec,del_start,rec_len,-target.num_lines);
  872.        rec_len = calculate_rec_len(ADJUST_DELETE,rec_len,del_start,-target.num_lines);
  873. /*     rec_len += (rec_len>del_start)?target.num_lines:0;*/
  874.       }
  875.     else
  876.       {
  877.        if (start_col < CURRENT_VIEW->zone_start)
  878.          {
  879.           start_col++;
  880.           target.num_lines--;
  881.          }
  882.        del_start = start_col-1;
  883.        (void)memdeln(rec,del_start,rec_len,target.num_lines);
  884.        rec_len = calculate_rec_len(ADJUST_DELETE,rec_len,del_start,target.num_lines);
  885. /*       rec_len -= (rec_len>del_start)?target.num_lines:0;*/
  886.       }
  887.     if (CURRENT_VIEW->current_window == WINDOW_COMMAND)
  888.       {
  889.        post_process_line(CURRENT_VIEW,CURRENT_VIEW->current_line,(LINE *)NULL,TRUE);
  890.        pre_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line,(LINE *)NULL);
  891.       }
  892.     else
  893.       rc = cursor_column();
  894.     build_screen(current_screen);
  895.     display_screen(current_screen);
  896.    }
  897.  else
  898.    {
  899.     if (CURRENT_VIEW->current_window == WINDOW_COMMAND)
  900.       {
  901.        post_process_line(CURRENT_VIEW,CURRENT_VIEW->current_line,(LINE *)NULL,TRUE);
  902.        pre_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line,(LINE *)NULL);
  903.       }
  904.    }
  905.  free_target(&target);
  906. #ifdef TRACE
  907.  trace_return();
  908. #endif
  909.  return(rc);
  910. }
  911. /*man-start*********************************************************************
  912. COMMAND
  913.      cfirst - move column pointer to beginning of zone
  914.  
  915. SYNTAX
  916.      CFirst
  917.  
  918. DESCRIPTION
  919.      The CFIRST command moves the column pointer to the beginning of
  920.      the zone.
  921.  
  922. COMPATIBILITY
  923.      XEDIT: Compatible.
  924.      KEDIT: Compatible.
  925.  
  926. SEE ALSO
  927.      <SET ZONE>
  928.  
  929. STATUS
  930.      Complete.
  931. **man-end**********************************************************************/
  932. #ifdef HAVE_PROTO
  933. short Cfirst(CHARTYPE *params)
  934. #else
  935. short Cfirst(params)
  936. CHARTYPE *params;
  937. #endif
  938. /***********************************************************************/
  939. {
  940. /*-------------------------- external data ----------------------------*/
  941. /*--------------------------- local data ------------------------------*/
  942.  short rc=RC_OK;
  943.  bool need_to_redisplay=FALSE;
  944. /*--------------------------- processing ------------------------------*/
  945. #ifdef TRACE
  946.  trace_function("comm1.c:   Cfirst");
  947. #endif
  948. /*---------------------------------------------------------------------*/
  949. /* No arguments are allowed; error if any are present.                 */
  950. /*---------------------------------------------------------------------*/
  951.  if (strcmp((DEFCHAR *)params,"") != 0)
  952.    {
  953.     display_error(1,(CHARTYPE *)params,FALSE);
  954. #ifdef TRACE
  955.     trace_return();
  956. #endif
  957.     return(RC_INVALID_OPERAND);
  958.    }
  959.  if (column_in_view(current_screen,CURRENT_VIEW->current_column-1))
  960.     need_to_redisplay = TRUE;
  961.  CURRENT_VIEW->current_column = CURRENT_VIEW->zone_start;
  962.  if (column_in_view(current_screen,CURRENT_VIEW->current_column-1))
  963.     need_to_redisplay = TRUE;
  964.  if (need_to_redisplay)
  965.     display_screen(current_screen);
  966. #ifdef TRACE
  967.  trace_return();
  968. #endif
  969.  return(rc);
  970. }
  971. /*man-start*********************************************************************
  972. COMMAND
  973.      change - change one string to another
  974.  
  975. SYNTAX
  976.      Change [/string1/string2/ [target] [n] [m]]
  977.  
  978. DESCRIPTION
  979.      The CHANGE command changes one string of text to another.
  980.  
  981.      The first parameter to the change command is the old and new
  982.      string values, seperated by delimiters.
  983.      The first non alphabetic character after the 'change' command 
  984.      is the delimiter.
  985.  
  986.      <'target'> specifies how many lines are to be searched for 
  987.      occurrences of 'string1' to be changed.
  988.  
  989.      'n' determines how many occurrences of 'string1' are to be 
  990.      changed to 'string2' on each line. 'n' may be specified as
  991.      '*' which will result in all occurrences of 'string1' will
  992.      be changed.  '*' is equivalent to the current WIDTH of the
  993.      line.
  994.  
  995.      'm' determines from which occurrence of 'string1' on the line 
  996.      changes are to commence.
  997.  
  998.      If no arguments are supplied to the CHANGE command, the last
  999.      change command, if any, is re-executed.
  1000.  
  1001. COMPATIBILITY
  1002.      XEDIT: Compatible.
  1003.      KEDIT: Compatible.
  1004.  
  1005. DEFAULT
  1006.      1 1 1
  1007.  
  1008. SEE ALSO
  1009.      <SCHANGE>
  1010.  
  1011. STATUS
  1012.      Complete.
  1013. **man-end**********************************************************************/
  1014. #ifdef HAVE_PROTO
  1015. short Change(CHARTYPE *params)
  1016. #else
  1017. short Change(params)
  1018. CHARTYPE *params;
  1019. #endif
  1020. /***********************************************************************/
  1021. {
  1022. /*-------------------------- external data ----------------------------*/
  1023.  extern CHARTYPE last_change_command[MAX_COMMAND_LENGTH];
  1024. /*--------------------------- local data ------------------------------*/
  1025.  short rc=RC_OK;
  1026. /*--------------------------- processing ------------------------------*/
  1027. #ifdef TRACE
  1028.  trace_function("comm1.c:   Change");
  1029. #endif
  1030. /*---------------------------------------------------------------------*/
  1031. /* If no arguments have been supplied, pass the last change command    */
  1032. /* to be executed. If no last change command, return error 39.         */
  1033. /*---------------------------------------------------------------------*/
  1034.  if (blank_field(params))
  1035.    {
  1036.     if (blank_field(last_change_command))
  1037.       {
  1038.        display_error(39,(CHARTYPE *)params,FALSE);
  1039. #ifdef TRACE
  1040.        trace_return();
  1041. #endif
  1042.        return(RC_INVALID_OPERAND);
  1043.       }
  1044.     rc = execute_change_command(last_change_command,FALSE);
  1045. #ifdef TRACE
  1046.     trace_return();
  1047. #endif
  1048.     return(rc);
  1049.    }
  1050.  rc = execute_change_command(params,FALSE);
  1051. #ifdef TRACE
  1052.  trace_return();
  1053. #endif
  1054.  return(rc);
  1055. }
  1056. /*man-start*********************************************************************
  1057. COMMAND
  1058.      cinsert - insert text starting at the column pointer
  1059.  
  1060. SYNTAX
  1061.      CInsert text
  1062.  
  1063. DESCRIPTION
  1064.      The CINSERT command inserts 'text' starting at the column position.
  1065.  
  1066.      'text' can include leading or trailing space characters. Thus
  1067.      CINSERT immediatley followed by 5 spaces, will insert 4 space 
  1068.      characters. The first space character is the command seperator.
  1069.  
  1070. COMPATIBILITY
  1071.      XEDIT: Compatible.
  1072.      KEDIT: Compatible.
  1073.  
  1074. STATUS
  1075.      Complete.
  1076. **man-end**********************************************************************/
  1077. #ifdef HAVE_PROTO
  1078. short Cinsert(CHARTYPE *params)
  1079. #else
  1080. short Cinsert(params)
  1081. CHARTYPE *params;
  1082. #endif
  1083. /***********************************************************************/
  1084. {
  1085. /*-------------------------- external data ----------------------------*/
  1086. /*--------------------------- local data ------------------------------*/
  1087.  short rc=RC_OK;
  1088. /*--------------------------- processing ------------------------------*/
  1089. #ifdef TRACE
  1090.  trace_function("comm1.c:   Cinsert");
  1091. #endif
  1092.  rc = column_command(params,COLUMN_CINSERT);
  1093. #ifdef TRACE
  1094.  trace_return();
  1095. #endif
  1096.  return(rc);
  1097. }
  1098. /*man-start*********************************************************************
  1099. COMMAND
  1100.      clast - move the column pointer to end of zone
  1101.  
  1102. SYNTAX
  1103.      CLAst
  1104.  
  1105. DESCRIPTION
  1106.      The CLAST command moves the column pointer to the end of the
  1107.      zone.
  1108.  
  1109. COMPATIBILITY
  1110.      XEDIT: Compatible.
  1111.      KEDIT: Compatible.
  1112.  
  1113. SEE ALSO
  1114.      <SET ZONE>
  1115.  
  1116. STATUS
  1117.      Complete.
  1118. **man-end**********************************************************************/
  1119. #ifdef HAVE_PROTO
  1120. short Clast(CHARTYPE *params)
  1121. #else
  1122. short Clast(params)
  1123. CHARTYPE *params;
  1124. #endif
  1125. /***********************************************************************/
  1126. {
  1127. /*-------------------------- external data ----------------------------*/
  1128. /*--------------------------- local data ------------------------------*/
  1129.  short rc=RC_OK;
  1130.  bool need_to_redisplay=FALSE;
  1131. /*--------------------------- processing ------------------------------*/
  1132. #ifdef TRACE
  1133.  trace_function("comm1.c:   Clast");
  1134. #endif
  1135. /*---------------------------------------------------------------------*/
  1136. /* No arguments are allowed; error if any are present.                 */
  1137. /*---------------------------------------------------------------------*/
  1138.  if (strcmp((DEFCHAR *)params,"") != 0)
  1139.    {
  1140.     display_error(1,(CHARTYPE *)params,FALSE);
  1141. #ifdef TRACE
  1142.     trace_return();
  1143. #endif
  1144.     return(RC_INVALID_OPERAND);
  1145.    }
  1146.  if (column_in_view(current_screen,CURRENT_VIEW->current_column-1))
  1147.     need_to_redisplay = TRUE;
  1148.  CURRENT_VIEW->current_column = CURRENT_VIEW->zone_end;
  1149.  if (column_in_view(current_screen,CURRENT_VIEW->current_column-1))
  1150.     need_to_redisplay = TRUE;
  1151.  if (need_to_redisplay)
  1152.     display_screen(current_screen);
  1153. #ifdef TRACE
  1154.  trace_return();
  1155. #endif
  1156.  return(rc);
  1157. }
  1158. /*man-start*********************************************************************
  1159. COMMAND
  1160.      clocate - move the column pointer
  1161.  
  1162. SYNTAX
  1163.      CLocate column target
  1164.  
  1165. DESCRIPTION
  1166.      The CLOCATE command scans the file for the specified <'column target'>
  1167.      beginning with the column following (or preceding) the column pointer.
  1168.  
  1169.      Column targets can be specified as absolute targets, relative
  1170.      targets or string targets.
  1171.  
  1172. COMPATIBILITY
  1173.      XEDIT: Compatible.
  1174.      KEDIT: Compatible.
  1175.  
  1176. STATUS
  1177.      Incomplete. No string targets.
  1178. **man-end**********************************************************************/
  1179. #ifdef HAVE_PROTO
  1180. short Clocate(CHARTYPE *params)
  1181. #else
  1182. short Clocate(params)
  1183. CHARTYPE *params;
  1184. #endif
  1185. /***********************************************************************/
  1186. {
  1187. /*-------------------------- external data ----------------------------*/
  1188.  extern CHARTYPE *rec;
  1189.  extern LENGTHTYPE rec_len;
  1190.  extern short compatible_feel;
  1191. /*--------------------------- local data ------------------------------*/
  1192.  short rc=RC_OK;
  1193.  short target_type=TARGET_ABSOLUTE|TARGET_RELATIVE|TARGET_STRING|TARGET_BLANK;
  1194.  TARGET target;
  1195.  CHARTYPE *line=NULL;
  1196.  LINE *curr=NULL;
  1197.  LENGTHTYPE len=0,start_col=0;
  1198.  unsigned int y=0,x=0;
  1199. /*--------------------------- processing ------------------------------*/
  1200. #ifdef TRACE
  1201.  trace_function("comm1.c:   Clocate");
  1202. #endif
  1203. /*---------------------------------------------------------------------*/
  1204. /* Determine at which column to start the search...                    */
  1205. /*---------------------------------------------------------------------*/
  1206.  switch (CURRENT_VIEW->current_window)
  1207.    {
  1208.     case WINDOW_FILEAREA:
  1209.          if (compatible_feel == COMPAT_XEDIT)
  1210.            {
  1211.             curr = lll_find(CURRENT_FILE->first_line,CURRENT_FILE->last_line,CURRENT_VIEW->current_line,CURRENT_FILE->number_lines);
  1212.             line = curr->line;
  1213.             len = curr->length;
  1214.             start_col = CURRENT_VIEW->current_column;
  1215.            }
  1216.          else
  1217.            {
  1218.             line = rec;
  1219.             len = rec_len;
  1220.             getyx(CURRENT_WINDOW,y,x);
  1221.             start_col = (CURRENT_VIEW->verify_col) + x;
  1222.             if (start_col > CURRENT_VIEW->zone_end)
  1223.                start_col = min(max_line_length,CURRENT_VIEW->zone_end+1);
  1224.             if (start_col < CURRENT_VIEW->zone_start)
  1225.                start_col = max(1,CURRENT_VIEW->zone_start-1);
  1226.            }
  1227.          break;
  1228.     case WINDOW_PREFIX:
  1229.          line = rec;
  1230.          len = rec_len;
  1231.          start_col = max(CURRENT_VIEW->current_column,max(1,CURRENT_VIEW->zone_start));
  1232.          break;
  1233.     case WINDOW_COMMAND:
  1234.          curr = lll_find(CURRENT_FILE->first_line,CURRENT_FILE->last_line,CURRENT_VIEW->current_line,CURRENT_FILE->number_lines);
  1235.          line = curr->line;
  1236.          len = curr->length;
  1237.          start_col = CURRENT_VIEW->current_column;
  1238.          break;
  1239.    }
  1240. /*---------------------------------------------------------------------*/
  1241. /* Validate the parameters as valid targets...                         */
  1242. /*---------------------------------------------------------------------*/
  1243.  initialise_target(&target);
  1244.  rc = parse_target(params,(LINETYPE)start_col,&target,target_type,TRUE,TRUE,TRUE);
  1245.  if (rc != RC_OK)
  1246.    {
  1247.     free_target(&target);
  1248. #ifdef TRACE
  1249.     trace_return();
  1250. #endif
  1251.     return(RC_INVALID_OPERAND);
  1252.    }
  1253. /*---------------------------------------------------------------------*/
  1254. /* Find the valid column target. If found process the command...       */
  1255. /*---------------------------------------------------------------------*/
  1256.  if ((find_column_target(line,len,&target,start_col,TRUE,FALSE)) == RC_OK)
  1257.    {
  1258.     CURRENT_VIEW->current_column = start_col + target.num_lines;
  1259.     if (CURRENT_VIEW->current_window != WINDOW_COMMAND)
  1260.        rc = cursor_column();
  1261.     build_screen(current_screen);
  1262.     display_screen(current_screen);
  1263.    }
  1264.  free_target(&target);
  1265. #ifdef TRACE
  1266.  trace_return();
  1267. #endif
  1268.  return(rc);
  1269. }
  1270. /*man-start*********************************************************************
  1271. COMMAND
  1272.      cmatch - find matching bracket character
  1273.  
  1274. SYNTAX
  1275.      CMATCH
  1276.  
  1277. DESCRIPTION
  1278.      The CMATCH command searches for the matching bracket character to
  1279.      the character under the cursor.
  1280.  
  1281.      It handles nested sets of matching pairs.
  1282.      The matching character pairs are []{}<>().
  1283.  
  1284. COMPATIBILITY
  1285.      XEDIT: N/A
  1286.      KEDIT: Compatible.
  1287.  
  1288. STATUS
  1289.      Complete.
  1290. **man-end**********************************************************************/
  1291. #ifdef HAVE_PROTO
  1292. short Cmatch(CHARTYPE *params)
  1293. #else
  1294. short Cmatch(params)
  1295. CHARTYPE *params;
  1296. #endif
  1297. /***********************************************************************/
  1298. {
  1299. /*------------------------- external data -----------------------------*/
  1300.  extern CHARTYPE *rec;
  1301. /*--------------------------- local data ------------------------------*/
  1302.  static CHARTYPE *match = (CHARTYPE *)"[]{}<>()";
  1303.  unsigned short x=0,y=0,current_y=0;
  1304.  CHARTYPE ch=0,match_ch=0;
  1305.  register short i=0;
  1306.  short direction_backward=0;
  1307.  short matches=1,match_col=(-1),start_col=0,focus_column=0;
  1308.  LINETYPE offset=0L;
  1309.  LINE *curr=NULL;
  1310.  LINETYPE focus_line=0L;
  1311.  bool use_current=TRUE;
  1312. /*--------------------------- processing ------------------------------*/
  1313. #ifdef TRACE
  1314.  trace_function("comm1.c:   Cmatch");
  1315. #endif
  1316.  getyx(CURRENT_WINDOW,y,x);
  1317. /*---------------------------------------------------------------------*/
  1318. /* This command only allowed to be issued from with the MAIN window.   */
  1319. /*---------------------------------------------------------------------*/
  1320.  if (CURRENT_VIEW->current_window == WINDOW_FILEAREA)
  1321.    {
  1322.     current_y = get_row_for_focus_line(current_screen,CURRENT_VIEW->focus_line,
  1323.                             CURRENT_VIEW->current_row);
  1324.     focus_line = CURRENT_VIEW->focus_line;
  1325.     focus_column = CURRENT_VIEW->verify_col + x - 1;
  1326.     ch = rec[focus_column];
  1327.     use_current = FALSE;
  1328.    }
  1329.  else
  1330.    {
  1331.     current_y = CURRENT_VIEW->current_row;
  1332.     focus_line = CURRENT_VIEW->current_line;
  1333.     focus_column = CURRENT_VIEW->current_column - 1;
  1334.     ch = CURRENT_SCREEN.sl[current_y].contents[focus_column];
  1335.     use_current = TRUE;
  1336.    }
  1337. /*---------------------------------------------------------------------*/
  1338. /* This command cannot be issued on TOF or BOF.                        */
  1339. /*---------------------------------------------------------------------*/
  1340.  if (TOF(focus_line)
  1341.  ||  BOF(focus_line))
  1342.    {
  1343.     display_error(66,(CHARTYPE *)"",FALSE);
  1344. #ifdef TRACE
  1345.     trace_return();
  1346. #endif
  1347.     return(RC_TOF_EOF_REACHED);
  1348.    }
  1349. /*---------------------------------------------------------------------*/
  1350. /* This command cannot be entered on a shadow line.                    */
  1351. /*---------------------------------------------------------------------*/
  1352.  if (CURRENT_SCREEN.sl[y].line_type == LINE_SHADOW)
  1353.    {
  1354.     display_error(87,(CHARTYPE *)"",FALSE);
  1355. #ifdef TRACE
  1356.     trace_return();
  1357. #endif
  1358.     return(RC_TARGET_NOT_FOUND);
  1359.    }
  1360. /*---------------------------------------------------------------------*/
  1361. /* Check if the character under the cursor is a valid match character. */
  1362. /*---------------------------------------------------------------------*/
  1363.  match_ch = 0;
  1364.  for (i=0;i<strlen((DEFCHAR *)match);i++)
  1365.     if (ch == *(match+i))
  1366.       {
  1367.        direction_backward = (i % 2);
  1368.        match_ch = (direction_backward) ? *(match+i-1) : *(match+i+1);
  1369.        break;
  1370.       }
  1371.  if (match_ch == 0)
  1372.    {
  1373.     display_error(67,(CHARTYPE *)"",FALSE);
  1374. #ifdef TRACE
  1375.     trace_return();
  1376. #endif
  1377.     return(RC_INVALID_OPERAND);
  1378.    }
  1379. /*---------------------------------------------------------------------*/
  1380. /* Calculate the actual position of the character in the LINE.         */
  1381. /*---------------------------------------------------------------------*/
  1382.  start_col = focus_column + ((direction_backward) ? (-1) : 1);
  1383. /*---------------------------------------------------------------------*/
  1384. /* Find the focus line linked list entry.                              */
  1385. /*---------------------------------------------------------------------*/
  1386.  post_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line,(LINE *)NULL,TRUE);
  1387.  curr = lll_find(CURRENT_FILE->first_line,CURRENT_FILE->last_line,focus_line,CURRENT_FILE->number_lines);
  1388.  while (curr->next != NULL && curr->prev != NULL)
  1389.    {
  1390.     if (direction_backward)
  1391.       {
  1392.        for (i=start_col;i>(-1);i--)
  1393.           {
  1394.            if (*(curr->line+i) == ch)
  1395.              matches++;
  1396.            else
  1397.               if (*(curr->line+i) == match_ch)
  1398.                 matches--;
  1399.            if (matches == 0)       /* found matching one */
  1400.              {
  1401.               match_col = i;
  1402.               break;
  1403.              }
  1404.           }
  1405.        if (match_col != (-1))
  1406.          break;
  1407.        curr = curr->prev;
  1408.        offset--;
  1409.        start_col = curr->length;
  1410.       }
  1411.     else
  1412.       {
  1413.        for (i=start_col;i<curr->length;i++)
  1414.           {
  1415.            if (*(curr->line+i) == ch)
  1416.              matches++;
  1417.            else
  1418.               if (*(curr->line+i) == match_ch)
  1419.                 matches--;
  1420.            if (matches == 0)       /* found matching one */
  1421.              {
  1422.               match_col = i;
  1423.               break;
  1424.              }
  1425.           }
  1426.        if (match_col != (-1))
  1427.          break;
  1428.        curr = curr->next;
  1429.        offset++;
  1430.        start_col = 0;
  1431.       }
  1432.    }
  1433. /*---------------------------------------------------------------------*/
  1434. /* If no match found, return with error.                               */
  1435. /*---------------------------------------------------------------------*/
  1436.  if (match_col == (-1))  /* no match found */
  1437.    {
  1438.     display_error(68,(CHARTYPE *)"",FALSE);
  1439. #ifdef TRACE
  1440.     trace_return();
  1441. #endif
  1442.     return(RC_TARGET_NOT_FOUND);
  1443.    }
  1444. /*---------------------------------------------------------------------*/
  1445. /* If we get here, we have found the matching character, so we have to */
  1446. /*  move the cursor to the new column and/or line.                     */
  1447. /*---------------------------------------------------------------------*/
  1448.  if (offset == 0L)
  1449.    {
  1450.     if (use_current)
  1451.        CURRENT_VIEW->current_column = match_col+1;
  1452.     if (match_col >= CURRENT_VIEW->verify_col-1
  1453.     &&  match_col <= (CURRENT_SCREEN.cols[WINDOW_FILEAREA]+(CURRENT_VIEW->verify_col-1))-1)
  1454. /*---------------------------------------------------------------------*/
  1455. /* If the new cursor position is in the same panel and on the same line*/
  1456. /* just move the cursor there and get out.                             */
  1457. /*---------------------------------------------------------------------*/
  1458.       {
  1459.        if (use_current)
  1460.          {
  1461.           build_screen(current_screen); 
  1462.           display_screen(current_screen);
  1463.           wmove(CURRENT_WINDOW,y,x);
  1464.          }
  1465.        else
  1466.           wmove(CURRENT_WINDOW,y,match_col-(CURRENT_VIEW->verify_col-1));
  1467. #ifdef TRACE
  1468.        trace_return();
  1469. #endif
  1470.        return(RC_OK);
  1471.       }
  1472.    else
  1473.       {
  1474.        x = CURRENT_SCREEN.cols[WINDOW_FILEAREA] / 2;
  1475.        CURRENT_VIEW->verify_col = max(1,match_col-(short)x);
  1476.        build_screen(current_screen); 
  1477.        display_screen(current_screen);
  1478.        wmove(CURRENT_WINDOW,y,(match_col-(CURRENT_VIEW->verify_col-1)));
  1479. #ifdef TRACE
  1480.        trace_return();
  1481. #endif
  1482.        return(RC_OK);
  1483.       }
  1484.    }
  1485. /*---------------------------------------------------------------------*/
  1486. /* If a match IS found on a different line, further checks are required*/
  1487. /* for SCOPE.                                                          */
  1488. /*---------------------------------------------------------------------*/
  1489.  if (in_scope(CURRENT_VIEW,curr))
  1490.    {
  1491. /*---------------------------------------------------------------------*/
  1492. /* Set the cursor position for the matching character.                 */
  1493. /*---------------------------------------------------------------------*/
  1494.     if (use_current)
  1495.       {
  1496.        CURRENT_VIEW->current_column = match_col+1;
  1497.        CURRENT_VIEW->current_line += offset;
  1498.        if (line_in_view(current_screen,CURRENT_VIEW->focus_line))
  1499.           y = get_row_for_focus_line(current_screen,CURRENT_VIEW->focus_line,
  1500.                                   CURRENT_VIEW->current_row);
  1501.        else
  1502.          {
  1503.           CURRENT_VIEW->focus_line = CURRENT_VIEW->current_line;
  1504.           y = CURRENT_VIEW->current_row;
  1505.          }
  1506.        pre_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line,(LINE *)NULL);
  1507.       }
  1508.     else
  1509.       {
  1510.        CURRENT_VIEW->focus_line += offset;
  1511.        pre_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line,(LINE *)NULL);
  1512.        if (line_in_view(current_screen,CURRENT_VIEW->focus_line))
  1513.           y = get_row_for_focus_line(current_screen,CURRENT_VIEW->focus_line,
  1514.                                   CURRENT_VIEW->current_row);
  1515.        else
  1516.          {
  1517.           CURRENT_VIEW->current_line = CURRENT_VIEW->focus_line;
  1518.           y = CURRENT_VIEW->current_row;
  1519.          }
  1520.       }
  1521.    }
  1522.  else
  1523.     if (CURRENT_VIEW->scope_all)
  1524.       {
  1525.        curr->select = CURRENT_VIEW->display_low;
  1526.        if (use_current)
  1527.          {
  1528.           CURRENT_VIEW->current_column = match_col+1;
  1529.           CURRENT_VIEW->current_line += offset;
  1530.           CURRENT_VIEW->focus_line = CURRENT_VIEW->current_line;
  1531.          }
  1532.        else
  1533.          {
  1534.           CURRENT_VIEW->focus_line += offset;
  1535.           CURRENT_VIEW->current_line = CURRENT_VIEW->focus_line;
  1536.          }
  1537.        pre_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line,(LINE *)NULL);
  1538.        y = CURRENT_VIEW->current_row;
  1539.       }
  1540.     else
  1541.       {
  1542.        display_error(68,(CHARTYPE *)"",FALSE);
  1543. #ifdef TRACE
  1544.        trace_return();
  1545. #endif
  1546.        return(RC_TARGET_NOT_FOUND);
  1547.       }
  1548.  if (match_col >= CURRENT_VIEW->verify_col-1
  1549.  &&  match_col <= (CURRENT_SCREEN.cols[WINDOW_FILEAREA]+(CURRENT_VIEW->verify_col-1))-1)
  1550.     x = match_col-(CURRENT_VIEW->verify_col-1);
  1551.  else
  1552.    {
  1553.     x = CURRENT_SCREEN.cols[WINDOW_FILEAREA] / 2;
  1554.     CURRENT_VIEW->verify_col = max(1,match_col-(short)x);
  1555.     x = (match_col-(CURRENT_VIEW->verify_col-1));
  1556.    }
  1557.  
  1558.  build_screen(current_screen); 
  1559.  display_screen(current_screen);
  1560.  wmove(CURRENT_WINDOW,y,x);
  1561. #ifdef TRACE
  1562.  trace_return();
  1563. #endif
  1564.  return(RC_OK);
  1565. }
  1566. /*man-start*********************************************************************
  1567. COMMAND
  1568.      cmsg - display text on command line
  1569.  
  1570. SYNTAX
  1571.      CMSG [text]
  1572.  
  1573. DESCRIPTION
  1574.      The CMSG command, primarily used in macros, displays 'text' on the
  1575.      command line.
  1576.  
  1577. COMPATIBILITY
  1578.      XEDIT: Compatible.
  1579.      KEDIT: Compatible.
  1580.  
  1581. SEE ALSO
  1582.      <EMSG>, <MSG>
  1583.  
  1584. STATUS
  1585.      Complete.
  1586. **man-end**********************************************************************/
  1587. #ifdef HAVE_PROTO
  1588. short Cmsg(CHARTYPE *params)
  1589. #else
  1590. short Cmsg(params)
  1591. CHARTYPE *params;
  1592. #endif
  1593. /***********************************************************************/
  1594. {
  1595. /*------------------------- external data -----------------------------*/
  1596.  extern CHARTYPE *cmd_rec;
  1597.  extern LENGTHTYPE cmd_rec_len;
  1598.  extern bool clear_command;
  1599.  extern bool curses_started;
  1600. /*--------------------------- local data ------------------------------*/
  1601. /*--------------------------- processing ------------------------------*/
  1602. #ifdef TRACE
  1603.  trace_function("comm1.c:   Cmsg");
  1604. #endif
  1605.  memset(cmd_rec,' ',max_line_length);
  1606.  cmd_rec_len = strlen((DEFCHAR *)params);
  1607.  memcpy(cmd_rec,params,cmd_rec_len);
  1608.  if (curses_started
  1609.  &&  CURRENT_WINDOW_COMMAND != (WINDOW *)NULL)
  1610.    {
  1611.     wmove(CURRENT_WINDOW_COMMAND,0,0);
  1612.     my_wclrtoeol(CURRENT_WINDOW_COMMAND);
  1613.     put_string(CURRENT_WINDOW_COMMAND,0,0,cmd_rec,cmd_rec_len);
  1614.     clear_command = FALSE;
  1615.    }
  1616. #ifdef TRACE
  1617.  trace_return();
  1618. #endif
  1619.  return(RC_OK);
  1620. }
  1621. /*man-start*********************************************************************
  1622. COMMAND
  1623.      command - execute a command without translation
  1624.  
  1625. SYNTAX
  1626.      COMMAND command [options]
  1627.  
  1628. DESCRIPTION
  1629.      The COMMAND command executes the specified 'command' without
  1630.      synonym or macro translation. THE does not attempt to execute 
  1631.      the command as a <macro> even if <SET IMPMACRO> is ON. The 
  1632.      command will be passed to the operating system if <SET IMPOS> 
  1633.      is ON.
  1634.  
  1635. COMPATIBILITY
  1636.      XEDIT: Compatible.
  1637.      KEDIT: Compatible.
  1638.  
  1639. STATUS
  1640.      Complete.
  1641. **man-end**********************************************************************/
  1642. #ifdef HAVE_PROTO
  1643. short THECommand(CHARTYPE *params)
  1644. #else
  1645. short THECommand(params)
  1646. CHARTYPE *params;
  1647. #endif
  1648. /***********************************************************************/
  1649. {
  1650. /*------------------------- external data -----------------------------*/
  1651. /*--------------------------- local data ------------------------------*/
  1652.  short rc=RC_OK;
  1653. /*--------------------------- processing ------------------------------*/
  1654. #ifdef TRACE
  1655.  trace_function("comm1.c:   THECommand");
  1656. #endif
  1657.  rc = command_line(params,COMMAND_ONLY_TRUE);
  1658. #ifdef TRACE
  1659.  trace_return();
  1660. #endif
  1661.  return(rc);
  1662. }
  1663. /*man-start*********************************************************************
  1664. COMMAND
  1665.      compress - reduce spaces to tabs
  1666.  
  1667. SYNTAX
  1668.      COMPress [target]
  1669.  
  1670. DESCRIPTION
  1671.      The COMPRESS command reduces multiple occurrences of spaces and
  1672.      replaces them with tab characters in the <'target'> lines.  
  1673.      The current tab columns (set by <SET TABS>) are used in 
  1674.      determining where tab characters will replaces spaces.
  1675.  
  1676. COMPATIBILITY
  1677.      XEDIT: Compatible.
  1678.      KEDIT: Compatible.
  1679.  
  1680. SEE ALSO
  1681.      <EXPAND>, <SET TABS>
  1682.  
  1683. STATUS
  1684.      Complete.
  1685. **man-end**********************************************************************/
  1686. #ifdef HAVE_PROTO
  1687. short Compress(CHARTYPE *params)
  1688. #else
  1689. short Compress(params)
  1690. CHARTYPE *params;
  1691. #endif
  1692. /***********************************************************************/
  1693. {
  1694. /*------------------------- external data -----------------------------*/
  1695. /*--------------------------- local data ------------------------------*/
  1696.  short rc=RC_OK;
  1697. /*--------------------------- processing ------------------------------*/
  1698. #ifdef TRACE
  1699.  trace_function("comm1.c:   Compress");
  1700. #endif
  1701.  rc = execute_expand_compress(params,FALSE,TRUE,TRUE,TRUE);
  1702. #ifdef TRACE
  1703.  trace_return();
  1704. #endif
  1705.  return(rc);
  1706. }
  1707. /*man-start*********************************************************************
  1708. COMMAND
  1709.      controlchar - allow control characters to be entered
  1710.  
  1711. SYNTAX
  1712.      CONTROLChar
  1713.  
  1714. DESCRIPTION
  1715.      The CONTROLCHAR command prompts the user to enter a control 
  1716.      character; an ASCII character between 1 and 31 inclusive.
  1717.  
  1718. COMPATIBILITY
  1719.      XEDIT: N/A
  1720.      KEDIT: N/A
  1721.  
  1722. STATUS
  1723.      Complete.
  1724. **man-end**********************************************************************/
  1725. #ifdef HAVE_PROTO
  1726. short ControlChar(CHARTYPE *params)
  1727. #else
  1728. short ControlChar(params)
  1729. CHARTYPE *params;
  1730. #endif
  1731. /***********************************************************************/
  1732. {
  1733. /*------------------------- external data -----------------------------*/
  1734. /*--------------------------- local data ------------------------------*/
  1735.  unsigned short y=0,x=0;
  1736.  int key=0;
  1737. /*--------------------------- processing ------------------------------*/
  1738. #ifdef TRACE
  1739.  trace_function("comm1.c:   ControlChar");
  1740. #endif
  1741.  getyx(CURRENT_WINDOW,y,x);
  1742. /*---------------------------------------------------------------------*/
  1743. /* If in the MAIN window, this command can only be issued on a real    */
  1744. /* line.                                                               */
  1745. /*---------------------------------------------------------------------*/
  1746.  if (CURRENT_VIEW->current_window == WINDOW_FILEAREA)
  1747.    {
  1748.     if (CURRENT_SCREEN.sl[y].line_type != LINE_LINE)
  1749.       {
  1750.        display_error(38,(CHARTYPE *)"",FALSE);
  1751. #ifdef TRACE
  1752.        trace_return();
  1753. #endif
  1754.        return(RC_INVALID_ENVIRON);
  1755.       }
  1756.    }
  1757.  display_prompt((CHARTYPE *)"Press the character you require.");
  1758.  wmove(CURRENT_WINDOW,y,x);
  1759.  wrefresh(CURRENT_WINDOW);
  1760.  key = my_getch(CURRENT_WINDOW);
  1761.  clear_msgline();
  1762.  if (islower(key))
  1763.     key = toupper(key);
  1764.  if (key >= (int)'A'    /* was '@' for ASCII 0, but Text() command fails */
  1765.  &&  key <= (int)'_')
  1766.    {
  1767. #ifdef TRACE
  1768.     trace_return();
  1769. #endif
  1770.     return((RAW_KEY*2)+(short)key-(short)'@');
  1771.    }
  1772.  display_error(69,(CHARTYPE *)"- must be between 'A' and '_'",FALSE);
  1773. #ifdef TRACE
  1774.  trace_return();
  1775. #endif
  1776.  return(RC_INVALID_OPERAND);
  1777. }
  1778. /*man-start*********************************************************************
  1779. COMMAND
  1780.      copy - copies text from one position to another
  1781.  
  1782. SYNTAX
  1783.      COPY target1 target2
  1784.      COPY BLOCK [RESET]
  1785.  
  1786. DESCRIPTION
  1787.      With the first form of the COPY command, text is copied from
  1788.      'target1' to the line specified by 'target2'. Text can
  1789.      only be copied within the same view of the file.
  1790.  
  1791.      The second form of the COPY command copies text within the
  1792.      currently marked block to the current cursor position.
  1793.      The text can be in the same file or a different file.
  1794.  
  1795. COMPATIBILITY
  1796.      XEDIT: COPY BLOCK not available.
  1797.      KEDIT: Adds extra functionality with [RESET] option.
  1798.             With the cursor in the marked block this command in KEDIT
  1799.             acts like <DUPLICATE> BLOCK.
  1800.  
  1801. STATUS
  1802.      Complete.
  1803. **man-end**********************************************************************/
  1804. #ifdef HAVE_PROTO
  1805. short Copy(CHARTYPE *params)
  1806. #else
  1807. short Copy(params)
  1808. CHARTYPE *params;
  1809. #endif
  1810. /***********************************************************************/
  1811. {
  1812. /*-------------------------- external data ----------------------------*/
  1813.  extern VIEW_DETAILS *vd_mark;
  1814. /*--------------------------- local data ------------------------------*/
  1815.  CHARTYPE reset_block=SOURCE_UNKNOWN;
  1816.  short rc=RC_OK;
  1817.  LINETYPE start_line=0L,end_line=0L,true_line=0L,lines_affected=0L;
  1818.  VIEW_DETAILS *source_view=NULL,*dest_view=NULL;
  1819.  TARGET target1,target2;
  1820.  short target_type1=TARGET_NORMAL|TARGET_BLOCK_ANY|TARGET_ALL|TARGET_SPARE;
  1821.  short target_type2=TARGET_NORMAL;
  1822.  bool lines_based_on_scope=FALSE;
  1823. /*--------------------------- processing ------------------------------*/
  1824. #ifdef TRACE
  1825.  trace_function("comm1.c:   Copy");
  1826. #endif
  1827.  initialise_target(&target1);
  1828.  initialise_target(&target2);
  1829.  if ((rc = validate_target(params,&target1,target_type1,get_true_line(TRUE),TRUE,TRUE)) != RC_OK)
  1830.    {
  1831.     free_target(&target1);
  1832. #ifdef TRACE
  1833.     trace_return();
  1834. #endif
  1835.     return(rc);
  1836.    }
  1837. /*---------------------------------------------------------------------*/
  1838. /* If there is no second argument, the only valid target type for the  */
  1839. /* first argument then is BLOCK.                                       */
  1840. /*---------------------------------------------------------------------*/
  1841.  if (target1.spare == (-1))
  1842.    {
  1843.     if (target1.rt[0].target_type != TARGET_BLOCK_ANY
  1844.     &&  target1.rt[0].target_type != TARGET_BLOCK_CURRENT)
  1845.       {
  1846.        free_target(&target1);
  1847.        display_error(3,(CHARTYPE *)"",FALSE);
  1848. #ifdef TRACE
  1849.        trace_return();
  1850. #endif
  1851.        return(RC_INVALID_OPERAND);
  1852.       }
  1853.     else
  1854.        reset_block = SOURCE_BLOCK;
  1855.    }
  1856.  else
  1857.    {
  1858.     if (equal((CHARTYPE *)"reset",strtrunc(target1.rt[target1.spare].string),5))
  1859.        reset_block = SOURCE_BLOCK_RESET;
  1860.     else
  1861.        reset_block = SOURCE_COMMAND;
  1862.    }
  1863. /*---------------------------------------------------------------------*/
  1864. /* Validate the arguments following the target...                      */
  1865. /*---------------------------------------------------------------------*/
  1866.  switch(reset_block)
  1867.    {
  1868.     case SOURCE_BLOCK:
  1869.     case SOURCE_BLOCK_RESET:
  1870. /*---------------------------------------------------------------------*/
  1871. /* For box blocks, call the appropriate function...                    */
  1872. /*---------------------------------------------------------------------*/
  1873.          if (MARK_VIEW->mark_type != M_LINE)
  1874.            {
  1875.             free_target(&target1);
  1876.             box_operations(BOX_C,reset_block,FALSE,' ');
  1877. #ifdef TRACE
  1878.             trace_return();
  1879. #endif
  1880.             return(RC_OK);
  1881.            }
  1882.          source_view = MARK_VIEW;
  1883.          dest_view = CURRENT_VIEW;
  1884.          start_line = MARK_VIEW->mark_start_line;
  1885.          end_line = MARK_VIEW->mark_end_line;
  1886.          true_line = get_true_line(FALSE);
  1887.          lines_based_on_scope = FALSE;
  1888.          break;
  1889.     default:
  1890.          if ((rc = validate_target(target1.rt[target1.spare].string,&target2,target_type2,get_true_line(TRUE),TRUE,TRUE)) != RC_OK)
  1891.            {
  1892.             free_target(&target2);
  1893. #ifdef TRACE
  1894.             trace_return();
  1895. #endif
  1896.             return(rc);
  1897.            }
  1898.          source_view = CURRENT_VIEW;
  1899.          dest_view = CURRENT_VIEW;
  1900. #if 0
  1901.          if (TOF(target1.true_line))
  1902.            {
  1903.             target1.true_line = 1L;
  1904.             target1.num_lines--;
  1905.            }
  1906. #endif
  1907.          start_line = target1.true_line;
  1908.          end_line = (target1.true_line + target1.num_lines) - 1L;
  1909.          true_line = target2.true_line + target2.num_lines;
  1910.          lines_based_on_scope = TRUE;
  1911.          break;
  1912.    }
  1913.  free_target(&target1);
  1914.  free_target(&target2);
  1915. /*---------------------------------------------------------------------*/
  1916. /* If the destination line for the copy is the *** Bottom of File ***  */
  1917. /* line, then subtract 1 to ensure lines don't get copied below the    */
  1918. /* *** Bottom of File *** line.                                        */
  1919. /*---------------------------------------------------------------------*/
  1920.  if (BOF(true_line))
  1921.     true_line--;
  1922.  post_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line,(LINE *)NULL,TRUE);
  1923.  rc = rearrange_line_blocks(COMMAND_COPY,(CHARTYPE)reset_block,start_line,
  1924.                             end_line,true_line,1,source_view,dest_view,lines_based_on_scope,
  1925.                             &lines_affected);
  1926.  
  1927. #ifdef TRACE
  1928.  trace_return();
  1929. #endif
  1930.  return(rc);
  1931. }
  1932. /*man-start*********************************************************************
  1933. COMMAND
  1934.      coverlay - overlay text starting at the column pointer
  1935.  
  1936. SYNTAX
  1937.      COVerlay text
  1938.  
  1939. DESCRIPTION
  1940.      The COVERLAY command overlays the supplied 'text' onto the
  1941.      characters following the column position.
  1942.  
  1943.      Spaces in the 'text' do not destroy the existing characters.
  1944.  
  1945.      An underscore character "_" in the 'text' places a space in the
  1946.      corresponding character position. Therefore you cannot use the
  1947.      COVERLAY command to place underscores in a line.
  1948.  
  1949. COMPATIBILITY
  1950.      XEDIT: Compatible.
  1951.      KEDIT: Compatible.
  1952.  
  1953. STATUS
  1954.      Complete.
  1955. **man-end**********************************************************************/
  1956. #ifdef HAVE_PROTO
  1957. short Coverlay(CHARTYPE *params)
  1958. #else
  1959. short Coverlay(params)
  1960. CHARTYPE *params;
  1961. #endif
  1962. /***********************************************************************/
  1963. {
  1964. /*-------------------------- external data ----------------------------*/
  1965. /*--------------------------- local data ------------------------------*/
  1966.  short rc=RC_OK;
  1967. /*--------------------------- processing ------------------------------*/
  1968. #ifdef TRACE
  1969.  trace_function("comm1.c:   Coverlay");
  1970. #endif
  1971.  rc = column_command(params,COLUMN_COVERLAY);
  1972. #ifdef TRACE
  1973.  trace_return();
  1974. #endif
  1975.  return(rc);
  1976. }
  1977. /*man-start*********************************************************************
  1978. COMMAND
  1979.      creplace - replace text starting at the column pointer
  1980.  
  1981. SYNTAX
  1982.      CReplace text
  1983.  
  1984. DESCRIPTION
  1985.      The CREPLACE command replaces the current characters after the
  1986.      column pointer with the supplied 'text'.
  1987.  
  1988. COMPATIBILITY
  1989.      XEDIT: Compatible.
  1990.      KEDIT: Compatible.
  1991.  
  1992. STATUS
  1993.      Complete.
  1994. **man-end**********************************************************************/
  1995. #ifdef HAVE_PROTO
  1996. short Creplace(CHARTYPE *params)
  1997. #else
  1998. short Creplace(params)
  1999. CHARTYPE *params;
  2000. #endif
  2001. /***********************************************************************/
  2002. {
  2003. /*-------------------------- external data ----------------------------*/
  2004. /*--------------------------- local data ------------------------------*/
  2005.  short rc=RC_OK;
  2006. /*--------------------------- processing ------------------------------*/
  2007. #ifdef TRACE
  2008.  trace_function("comm1.c:   Creplace");
  2009. #endif
  2010.  rc = column_command(params,COLUMN_CREPLACE);
  2011. #ifdef TRACE
  2012.  trace_return();
  2013. #endif
  2014.  return(rc);
  2015. }
  2016. /*man-start*********************************************************************
  2017. COMMAND
  2018.      cursor - move cursor to specified position
  2019.  
  2020. SYNTAX
  2021.      CURsor Column
  2022.      CURsor Screen UP|DOWN|LEFT|RIGHT
  2023.      CURsor Screen row [col]
  2024.      CURsor [Escreen] UP|DOWN
  2025.      CURsor [Escreen|Kedit] LEFT|RIGHT
  2026.      CURsor [Escreen] row [col]
  2027.      CURsor CMdline [n]
  2028.      CURsor HOME [SAVE]
  2029.      CURsor File line [col]
  2030.      CURsor Mouse
  2031.  
  2032. DESCRIPTION
  2033.      The CURSOR command allows the user to specify where the cursor
  2034.      is to be positioned.
  2035.  
  2036.      CURSOR 'Column' moves the cursor to the current column of the
  2037.      <focus line>.
  2038.  
  2039.      CURSOR 'Screen' 'UP'|'DOWN'|'LEFT'|'RIGHT' moves the cursor in the
  2040.      indicated direction one line or column. If the cursor is
  2041.      positioned on the first or last line of the screen, the cursor
  2042.      wraps to the first or last enterable line. If the cursor is
  2043.      positioned on the left or right edges of the screen, the cursor
  2044.      moves to the left or right edge of the screen on the same line.
  2045.  
  2046.      CURSOR Screen 'row' ['col'] is similar to CURSOR 'Escreen'
  2047.      'row' ['col'], but all coordinates are relative the the top left 
  2048.      corner of the screen, not the top left corner of the
  2049.      <filearea>. Hence, 1,1 would be an invalid cursor position because 
  2050.      it would result in the cursor being moved to the <idline>.
  2051.      Specification of 'row' and/or 'col' outside the boundaries of the
  2052.      logical window is regarded as an error.
  2053.  
  2054.      CURSOR ['Escreen'] 'UP'|'DOWN'|'LEFT'|'RIGHT' is similar to CURSOR 
  2055.      'Screen' 'UP'|'DOWN'|'LEFT'|'RIGHT', except that where scrolling 
  2056.      of the window is possible, then scrolling will take place.
  2057.  
  2058.      CURSOR ['Escreen'] 'row' ['col'] moves the cursor to the specified
  2059.      'row'/'col' position within the <filearea>. The top left corner of
  2060.      the <filearea> is 1,1.
  2061.      'row' and 'col' may be specified as '=', which will default to the
  2062.      current row and/or column position.
  2063.      If 'row' or 'col' are greater than the maximum number of rows or
  2064.      columns in the <filearea>, the cursor will move to the last
  2065.      row/column available.
  2066.      If the specified 'row' is a <reserved line>, <scale line> or <tab line>
  2067.      an error will be displayed.
  2068.      If the 'row' specified is above the <Top-of-File line> or below the
  2069.      <Bottom-of-File line> the cursor will be placed on the closest
  2070.      one of these lines.
  2071.  
  2072.      CURSOR 'Kedit' 'LEFT'|'RIGHT' mimics the default behaviour of 
  2073.      CURL and CURR in KEDIT.
  2074.  
  2075.      CURSOR 'CMdline' moves the cursor to the indicated column of the
  2076.      <command line>.
  2077.  
  2078.      CURSOR 'HOME' moves the cursor to the first column of the <command line> 
  2079.      (if not on the command line), or to the last row/column of
  2080.      the <filearea> if on the command line. With the ['SAVE'] option,
  2081.      the cursor will move to the last row/column of the <filearea> or
  2082.      <prefix area> (which ever was the last position) if on the
  2083.      <command line>.
  2084.  
  2085.      CURSOR 'File' moves the cursor to the line and column of the file.
  2086.      If the line and/or column are not currently displayed, an error
  2087.      message is displayed.
  2088.  
  2089.      CURSOR 'Mouse' moves the cursor to the position where a mouse button
  2090.      was last activated.  This command is specific to THE.
  2091.  
  2092. COMPATIBILITY
  2093.      XEDIT: Compatible.
  2094.      KEDIT: Compatible.
  2095.  
  2096. STATUS
  2097.      Complete.
  2098. **man-end**********************************************************************/
  2099. #ifdef HAVE_PROTO
  2100. short Cursor(CHARTYPE *params)
  2101. #else
  2102. short Cursor(params)
  2103. CHARTYPE *params;
  2104. #endif
  2105. /***********************************************************************/
  2106. {
  2107. /*--------------------------- local data ------------------------------*/
  2108.  register short idx=0;
  2109. #define CUR_PARAMS  4
  2110.  CHARTYPE *word[CUR_PARAMS+1];
  2111.  CHARTYPE strip[CUR_PARAMS];
  2112.  unsigned short num_params=0;
  2113.  bool time_to_leave=FALSE;
  2114.  bool escreen=FALSE;
  2115.  short error_number=1;
  2116.  CHARTYPE *error_message=(CHARTYPE *)"";
  2117.  short colno=1;
  2118.  short rc=RC_OK;
  2119.  short state=CURSOR_START;
  2120.  short row=0,col=0;
  2121.  LINETYPE line=0L;
  2122. /*--------------------------- processing ------------------------------*/
  2123. #ifdef TRACE
  2124.  trace_function("comm1.c:   Cursor");
  2125. #endif
  2126.  strip[0]=STRIP_BOTH;
  2127.  strip[1]=STRIP_BOTH;
  2128.  strip[2]=STRIP_BOTH;
  2129.  strip[3]=STRIP_BOTH;
  2130.  num_params = param_split(params,word,CUR_PARAMS,WORD_DELIMS,TEMP_PARAM,strip,FALSE);
  2131.  if (num_params ==0)
  2132.    {
  2133.     display_error(3,(CHARTYPE *)"",FALSE);
  2134. #ifdef TRACE
  2135.     trace_return();
  2136. #endif
  2137.     return(RC_INVALID_OPERAND);
  2138.    }
  2139.  error_message = word[0];
  2140.  state = CURSOR_START;
  2141.  idx = 0;
  2142.  while(1)
  2143.    {
  2144.     switch(state)
  2145.       {
  2146.        case CURSOR_START:
  2147.             if (equal((CHARTYPE *)"escreen",word[idx],1))
  2148.               {
  2149.                state = CURSOR_ESCREEN;
  2150.                idx++;
  2151.                break;
  2152.               }
  2153.             if (equal((CHARTYPE *)"screen",word[idx],1))
  2154.               {
  2155.                state = CURSOR_SCREEN;
  2156.                idx++;
  2157.                break;
  2158.               }
  2159.             if (equal((CHARTYPE *)"left",word[idx],4))
  2160.               {
  2161.                if (num_params > 1)
  2162.                  {
  2163.                   state = CURSOR_ERROR;
  2164.                   error_message = word[idx];
  2165.                   error_number = 1;
  2166.                   break;
  2167.                  }
  2168.                rc = cursor_left(TRUE,FALSE);
  2169.                time_to_leave = TRUE;
  2170.                break;
  2171.               }
  2172.             if (equal((CHARTYPE *)"right",word[idx],5))
  2173.               {
  2174.                if (num_params > 1)
  2175.                  {
  2176.                   state = CURSOR_ERROR;
  2177.                   error_message = word[idx];
  2178.                   error_number = 1;
  2179.                   break;
  2180.                  }
  2181.                rc = cursor_right(TRUE,FALSE);
  2182.                time_to_leave = TRUE;
  2183.                break;
  2184.               }
  2185.             if (equal((CHARTYPE *)"up",word[idx],2))
  2186.               {
  2187.                if (num_params > 1)
  2188.                  {
  2189.                   state = CURSOR_ERROR;
  2190.                   error_message = word[idx];
  2191.                   error_number = 1;
  2192.                   break;
  2193.                  }
  2194.                rc = cursor_up(TRUE);
  2195.                time_to_leave = TRUE;
  2196.                break;
  2197.               }
  2198.             if (equal((CHARTYPE *)"down",word[idx],4))
  2199.               {
  2200.                if (num_params > 1)
  2201.                  {
  2202.                   state = CURSOR_ERROR;
  2203.                   error_message = word[idx];
  2204.                   error_number = 1;
  2205.                   break;
  2206.                  }
  2207.                rc = cursor_down(TRUE);
  2208.                time_to_leave = TRUE;
  2209.                break;
  2210.               }
  2211.             if (equal((CHARTYPE *)"home",word[idx],4))
  2212.               {
  2213.                state = CURSOR_HOME;
  2214.                idx++;
  2215.                break;
  2216.               }
  2217.             if (equal((CHARTYPE *)"column",word[idx],1))
  2218.               {
  2219.                state = CURSOR_COLUMN;
  2220.                idx++;
  2221.                break;
  2222.               }
  2223.             if (equal((CHARTYPE *)"cmdline",word[idx],2))
  2224.               {
  2225.                state = CURSOR_CMDLINE;
  2226.                idx++;
  2227.                break;
  2228.               }
  2229.             if (equal((CHARTYPE *)"file",word[idx],1))
  2230.               {
  2231.                state = CURSOR_FILE;
  2232.                idx++;
  2233.                break;
  2234.               }
  2235.             if (equal((CHARTYPE *)"kedit",word[idx],1))
  2236.               {
  2237.                state = CURSOR_KEDIT;
  2238.                idx++;
  2239.                break;
  2240.               }
  2241.             if (equal((CHARTYPE *)"mouse",word[idx],1))
  2242.               {
  2243.                state = CURSOR_MOUSE;
  2244.                idx++;
  2245.                break;
  2246.               }
  2247.             state = CURSOR_ESCREEN;
  2248.             break;
  2249.        case CURSOR_HOME:
  2250.             if (num_params > 2)
  2251.               {
  2252.                state = CURSOR_ERROR;
  2253.                error_message = word[idx];
  2254.                error_number = 1;
  2255.                break;
  2256.               }
  2257.             if (num_params == 2
  2258.             &&  !equal((CHARTYPE *)"save",word[1],4))
  2259.               {
  2260.                state = CURSOR_ERROR;
  2261.                error_number = 1;
  2262.                error_message = word[idx];
  2263.                break;
  2264.               }
  2265.             if (num_params == 2)
  2266.                rc = cursor_home(TRUE);
  2267.             else
  2268.                rc = cursor_home(FALSE);
  2269.             time_to_leave = TRUE;
  2270.             break;
  2271.        case CURSOR_COLUMN:
  2272.             if (num_params != 1)
  2273.               {
  2274.                state = CURSOR_ERROR;
  2275.                error_message = word[idx];
  2276.                error_number = 1;
  2277.                break;
  2278.               }
  2279.             rc = cursor_column();
  2280.             time_to_leave = TRUE;
  2281.             break;
  2282.        case CURSOR_FILE:
  2283.             if (num_params > 3)
  2284.               {
  2285.                state = CURSOR_ERROR;
  2286.                error_message = (CHARTYPE *)"";
  2287.                error_number = 2;
  2288.                break;
  2289.               }
  2290.             if (num_params < 2)
  2291.               {
  2292.                state = CURSOR_ERROR;
  2293.                error_message = (CHARTYPE *)"";
  2294.                error_number = 3;
  2295.                break;
  2296.               }
  2297.             if (!valid_positive_integer(word[1]))
  2298.               {
  2299.                state = CURSOR_ERROR;
  2300.                error_message = word[1];
  2301.                error_number = 4;
  2302.                break;
  2303.               }
  2304.             line = atol((DEFCHAR *)word[1]);
  2305.             if (num_params == 3)
  2306.               {
  2307.                if (!valid_positive_integer(word[2]))
  2308.                  {
  2309.                   state = CURSOR_ERROR;
  2310.                   error_message = word[2];
  2311.                   error_number = 4;
  2312.                   break;
  2313.                  }
  2314.                col = atoi((DEFCHAR *)word[2]);
  2315.               }
  2316.             else
  2317.                col = 0;
  2318.             rc = cursor_file(line,col);
  2319.             time_to_leave = TRUE;
  2320.             break;
  2321.        case CURSOR_MOUSE:
  2322.             if (num_params != 1)
  2323.               {
  2324.                state = CURSOR_ERROR;
  2325.                error_message = word[idx];
  2326.                error_number = 1;
  2327.                break;
  2328.               }
  2329.             rc = cursor_mouse();
  2330.             time_to_leave = TRUE;
  2331.             break;
  2332.        case CURSOR_CMDLINE:
  2333.             if (num_params > 2)
  2334.               {
  2335.                state = CURSOR_ERROR;
  2336.                error_message = word[idx];
  2337.                error_number = 1;
  2338.                break;
  2339.               }
  2340.             if (num_params == 2)
  2341.               {
  2342.                colno = atoi((DEFCHAR *)word[idx]);
  2343.                if (colno < 1)
  2344.                  {
  2345.                   state = CURSOR_ERROR;
  2346.                   error_message = word[idx];
  2347.                   error_number = 1;
  2348.                   break;
  2349.                  }
  2350.               }
  2351.             rc = cursor_cmdline(colno);
  2352.             time_to_leave = TRUE;
  2353.             break;
  2354.        case CURSOR_SCREEN:
  2355.        case CURSOR_ESCREEN:
  2356.             if (state == CURSOR_ESCREEN)
  2357.                escreen = TRUE;
  2358.             else
  2359.                escreen = FALSE;
  2360.             if (equal((CHARTYPE *)"left",word[idx],4))
  2361.               {
  2362.                if (num_params > 2)
  2363.                  {
  2364.                   state = CURSOR_ERROR;
  2365.                   error_message = word[idx];
  2366.                   error_number = 1;
  2367.                   break;
  2368.                  }
  2369.                rc = cursor_left(escreen,FALSE);
  2370.                time_to_leave = TRUE;
  2371.                break;
  2372.               }
  2373.             if (equal((CHARTYPE *)"right",word[idx],5))
  2374.               {
  2375.                if (num_params > 2)
  2376.                  {
  2377.                   state = CURSOR_ERROR;
  2378.                   error_message = word[idx];
  2379.                   error_number = 1;
  2380.                   break;
  2381.                  }
  2382.                rc = cursor_right(escreen,FALSE);
  2383.                time_to_leave = TRUE;
  2384.                break;
  2385.               }
  2386.             if (equal((CHARTYPE *)"up",word[idx],2))
  2387.               {
  2388.                if (num_params > 2)
  2389.                  {
  2390.                   state = CURSOR_ERROR;
  2391.                   error_message = word[idx];
  2392.                   error_number = 1;
  2393.                   break;
  2394.                  }
  2395.                rc = cursor_up(escreen);
  2396.                time_to_leave = TRUE;
  2397.                break;
  2398.               }
  2399.             if (equal((CHARTYPE *)"down",word[idx],4))
  2400.               {
  2401.                if (num_params > 2)
  2402.                  {
  2403.                   state = CURSOR_ERROR;
  2404.                   error_message = word[idx];
  2405.                   error_number = 1;
  2406.                   break;
  2407.                  }
  2408.                rc = cursor_down(escreen);
  2409.                time_to_leave = TRUE;
  2410.                break;
  2411.               }
  2412.              /* validate numbers */
  2413.             if (strcmp((DEFCHAR *)word[idx],"=") == 0)
  2414.                row = 0;
  2415.             else
  2416.               {
  2417.                if (!valid_positive_integer(word[idx]))
  2418.                  {
  2419.                   state = CURSOR_ERROR;
  2420.                   error_message = word[idx];
  2421.                   error_number = 4;
  2422.                   break;
  2423.                  }
  2424.                row = atoi((DEFCHAR *)word[idx]);
  2425.                if (row == 0)
  2426.                  {
  2427.                   state = CURSOR_ERROR;
  2428.                   error_message = word[idx];
  2429.                   error_number = 5;
  2430.                   break;
  2431.                  }
  2432.               }
  2433.             idx++;
  2434.             if (strcmp((DEFCHAR *)word[idx],"") == 0)
  2435.               {
  2436.                if (!escreen) /* MH 0501 - was if (escreen) */
  2437.                   col = 1;
  2438.                else
  2439.                   col = (CURRENT_VIEW->prefix&PREFIX_LOCATION_MASK) == PREFIX_LEFT ? CURRENT_VIEW->prefix_width + 1 : 1;
  2440.               }
  2441.             else
  2442.               {
  2443.                if (strcmp((DEFCHAR *)word[idx],"=") == 0)
  2444.                   col = 0;
  2445.                else
  2446.                  {
  2447.                   if (!valid_positive_integer(word[idx]))
  2448.                     {
  2449.                      state = CURSOR_ERROR;
  2450.                      error_message = word[idx];
  2451.                      error_number = 4;
  2452.                      break;
  2453.                     }
  2454.                   col = atoi((DEFCHAR *)word[idx]);
  2455.                   if (col == 0)
  2456.                     {
  2457.                      state = CURSOR_ERROR;
  2458.                      error_message = word[idx];
  2459.                      error_number = 5;
  2460.                      break;
  2461.                     }
  2462.                  }
  2463.               }
  2464.             rc = cursor_move((escreen)?FALSE:TRUE,row,col); /* MH 0501 - was just escreen */
  2465.             time_to_leave = TRUE;
  2466.             break;
  2467.        case CURSOR_KEDIT:
  2468.             if (equal((CHARTYPE *)"left",word[idx],4))
  2469.               {
  2470.                if (num_params > 2)
  2471.                  {
  2472.                   state = CURSOR_ERROR;
  2473.                   error_message = word[idx];
  2474.                   error_number = 1;
  2475.                   break;
  2476.                  }
  2477.                rc = cursor_left(TRUE,TRUE);
  2478.                time_to_leave = TRUE;
  2479.                break;
  2480.               }
  2481.             if (equal((CHARTYPE *)"right",word[idx],5))
  2482.               {
  2483.                if (num_params > 2)
  2484.                  {
  2485.                   state = CURSOR_ERROR;
  2486.                   error_message = word[idx];
  2487.                   error_number = 1;
  2488.                   break;
  2489.                  }
  2490.                rc = cursor_right(TRUE,TRUE);
  2491.                time_to_leave = TRUE;
  2492.                break;
  2493.               }
  2494.             state = CURSOR_ERROR;
  2495.             error_message = word[idx];
  2496.             error_number = 1;
  2497.             break;
  2498.        case CURSOR_ERROR:
  2499.             display_error(error_number,error_message,FALSE);
  2500.             rc = RC_INVALID_OPERAND;
  2501.             time_to_leave = TRUE;
  2502.             break;
  2503.       }
  2504.     if (time_to_leave)
  2505.        break;
  2506.    }
  2507. #ifdef TRACE
  2508.  trace_return();
  2509. #endif
  2510.  return(rc);
  2511. }
  2512.