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

  1. /***********************************************************************/
  2. /* COMM3.C - Commands K-O                                              */
  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/gwis/the/markh.html
  37.  * QLD 4507                      **** Maintainer PDCurses & REXX/SQL ****
  38.  * Australia                     ************* Author of THE ************
  39.  */
  40.  
  41. /*
  42. $Id: comm3.c 2.1 1995/06/24 16:28:52 MH Rel MH $
  43. */
  44.  
  45. #include <the.h>
  46. #include <proto.h>
  47.  
  48. /*#define DEBUG 1*/
  49.  
  50. /*man-start*********************************************************************
  51. COMMAND
  52.      left - scroll the screen to the left
  53.  
  54. SYNTAX
  55.      LEft [n|HALF]
  56.  
  57. DESCRIPTION
  58.      The LEFT command scrolls the screen to the left.
  59.  
  60.      If 'n' is supplied, the screen scrolls by that many columns.
  61.  
  62.      If 'HALF' is specified the screen is scrolled by half the number
  63.      of columns in the <filearea>.
  64.  
  65.      If 'FULL' is specified the screen is scrolled by the number
  66.      of columns in the <filearea>.
  67.  
  68.      If no parameter is supplied, the screen is scrolled by one
  69.      column. 
  70.  
  71. COMPATIBILITY
  72.      XEDIT: Compatible.
  73.      KEDIT: Compatible.
  74.  
  75. SEE ALSO
  76.      <RIGHT>, <RGTLEFT>
  77.  
  78. STATUS
  79.      Complete.
  80. **man-end**********************************************************************/
  81. #ifdef HAVE_PROTO
  82. short Left(CHARTYPE *params)
  83. #else
  84. short Left(params)
  85. CHARTYPE *params;
  86. #endif
  87. /***********************************************************************/
  88. {
  89. /*-------------------------- external data ----------------------------*/
  90. /*--------------------------- local data ------------------------------*/
  91.  short rc=RC_OK;
  92.  LINETYPE shift_val=1L;
  93. /*--------------------------- processing ------------------------------*/
  94. #ifdef TRACE
  95.  trace_function("comm3.c:   Left");
  96. #endif
  97. /*---------------------------------------------------------------------*/
  98. /* Validate only parameter, HALF or positive integer. 1 if no argument.*/
  99. /*---------------------------------------------------------------------*/
  100.  if (equal((CHARTYPE *)"half",params,4))
  101.     shift_val = -(CURRENT_SCREEN.cols[WINDOW_FILEAREA]/2);
  102.  if (equal((CHARTYPE *)"full",params,4))
  103.     shift_val = -(CURRENT_SCREEN.cols[WINDOW_FILEAREA]);
  104.  if (blank_field(params))
  105.     shift_val = (-1L);
  106.  if (shift_val == 1)                 /* argument not HALF or empty ... */
  107.    {
  108.     if (valid_positive_integer(params))
  109.       {
  110.        shift_val = atol((DEFCHAR *)params);
  111.        if (shift_val != 0)
  112.           shift_val = -shift_val;
  113.       }
  114.    }
  115.  if (shift_val == 1)                               /* invalid argument */
  116.    {
  117.     display_error(1,params,FALSE);
  118. #ifdef TRACE
  119.     trace_return();
  120. #endif
  121.     return(RC_INVALID_OPERAND);
  122.    }
  123. /*---------------------------------------------------------------------*/
  124. /* If the argument is 0, restore the original verify columns display.  */
  125. /*---------------------------------------------------------------------*/
  126.  if (shift_val == 0L)
  127.     CURRENT_VIEW->verify_col = CURRENT_VIEW->verify_start;
  128.  else
  129.     CURRENT_VIEW->verify_col = max(1,CURRENT_VIEW->verify_col+shift_val);
  130. #ifdef MSWIN
  131.  Win31HScroll(CURRENT_VIEW->verify_col);
  132. #endif
  133.  build_screen(current_screen);
  134.  display_screen(current_screen);
  135. #ifdef TRACE
  136.  trace_return();
  137. #endif
  138.  return(rc);
  139. }
  140. /*man-start*********************************************************************
  141. COMMAND
  142.      locate - search for a target
  143.  
  144. SYNTAX
  145.      [Locate] target [command]
  146.  
  147. DESCRIPTION
  148.      The LOCATE command searches for the next or previous occurrence 
  149.      of the specified <'target'>.  If no parameter is supplied, LOCATE
  150.      uses the the last target specified. If no prior target has been
  151.      specified, an error message is displayed. 
  152.  
  153.      With an optional 'command', this command is executed after finding
  154.      the <'target'>.
  155.  
  156. COMPATIBILITY
  157.      XEDIT: Compatible.
  158.      KEDIT: Compatible.
  159.  
  160. STATUS
  161.      Complete.
  162. **man-end**********************************************************************/
  163. #ifdef HAVE_PROTO
  164. short Locate(CHARTYPE *params)
  165. #else
  166. short Locate(params)
  167. CHARTYPE *params;
  168. #endif
  169. /***********************************************************************/
  170. {
  171. /*-------------------------- external data ----------------------------*/
  172.  extern CHARTYPE last_target[MAX_COMMAND_LENGTH];
  173. /*--------------------------- local data ------------------------------*/
  174.  short rc=RC_OK;
  175. /*--------------------------- processing ------------------------------*/
  176. #ifdef TRACE
  177.  trace_function("comm3.c:   Locate");
  178. #endif
  179. /*---------------------------------------------------------------------*/
  180. /* If no parameter is specified, use the last_target. If that doesn't  */
  181. /* exist, error.                                                       */
  182. /*---------------------------------------------------------------------*/
  183.  if (blank_field(params))
  184.    {
  185.     if (blank_field(last_target))
  186.       {
  187.        display_error(39,(CHARTYPE *)"",FALSE);
  188. #ifdef TRACE
  189.        trace_return();
  190. #endif
  191.        return(RC_INVALID_OPERAND);
  192.       }
  193.     rc = command_line(last_target,COMMAND_ONLY_FALSE);
  194. #ifdef TRACE
  195.     trace_return();
  196. #endif
  197.     return(rc);
  198.    }
  199.  rc = command_line(params,COMMAND_ONLY_FALSE);
  200. #ifdef TRACE
  201.  trace_return();
  202. #endif
  203.  return(rc);
  204. }
  205. /*man-start*********************************************************************
  206. COMMAND
  207.      lowercase - change uppercase characters to lowercase
  208.  
  209. SYNTAX
  210.      LOWercase [target]
  211.  
  212. DESCRIPTION
  213.      The LOWERCASE command changes all uppercase characters in all 
  214.      lines up to the <'target'> line to lowercase. All other characters
  215.      remain untouched.
  216.  
  217. COMPATIBILITY
  218.      XEDIT: Equivalent of LOWERCAS command.
  219.      KEDIT: Compatible.
  220.  
  221. SEE ALSO
  222.      <UPPERCASE>
  223.  
  224. STATUS
  225.      Complete.
  226. **man-end**********************************************************************/
  227. #ifdef HAVE_PROTO
  228. short Lowercase(CHARTYPE *params)
  229. #else
  230. short Lowercase(params)
  231. CHARTYPE *params;
  232. #endif
  233. /***********************************************************************/
  234. {
  235. /*--------------------------- local data ------------------------------*/
  236.  short rc=RC_OK;
  237. /*--------------------------- processing ------------------------------*/
  238. #ifdef TRACE
  239.  trace_function("comm3.c:   Lowercase");
  240. #endif
  241.  rc = execute_change_case(params,CASE_LOWER);
  242. #ifdef TRACE
  243.  trace_return();
  244. #endif
  245.  return(rc);
  246. }
  247. /*man-start*********************************************************************
  248. COMMAND
  249.      ls - list the specified directory as an editable file
  250.  
  251. SYNTAX
  252.      LS [file specification]
  253.  
  254. DESCRIPTION
  255.      The LS command displays all files matching the specified
  256.      'file specification'.
  257.  
  258.      When no parameter is supplied, all files in the current directory 
  259.      are displayed subject to any <SET DIRINCLUDE> restrictions.
  260.  
  261. COMPATIBILITY
  262.      XEDIT: N/A
  263.      KEDIT: Compatible.
  264.  
  265. SEE ALSO
  266.      <DIRECTORY>, <SET DIRINCLUDE>
  267.  
  268. STATUS
  269.      Complete.
  270. **man-end**********************************************************************/
  271.  
  272. /*man-start*********************************************************************
  273. COMMAND
  274.      macro - execute a macro command file
  275.  
  276. SYNTAX
  277.      MACRO filename [arguments ...]
  278.  
  279. DESCRIPTION
  280.      The MACRO command executes the contents of the specified 'filename'
  281.      as command line commands. The 'filename' can contain either a series
  282.      of THE commands, or can be a REXX program. The 'filename' is considered
  283.      a <macro>.
  284.  
  285.      REXX macros can be passed optional 'arguments'.
  286.  
  287.  
  288. COMPATIBILITY
  289.      XEDIT: Compatible.
  290.      KEDIT: Compatible.
  291.  
  292. STATUS
  293.      Complete.
  294. **man-end**********************************************************************/
  295. #ifdef HAVE_PROTO
  296. short Macro(CHARTYPE *params)
  297. #else
  298. short Macro(params)
  299. CHARTYPE *params;
  300. #endif
  301. /***********************************************************************/
  302. {
  303. /*-------------------------- external data ----------------------------*/
  304. /*--------------------------- local data ------------------------------*/
  305.  short rc=RC_OK;
  306.  short macrorc=0;
  307. /*--------------------------- processing ------------------------------*/
  308. #ifdef TRACE
  309.  trace_function("comm3.c:   Macro");
  310. #endif
  311.  rc = execute_macro(params,TRUE,¯orc);
  312. #ifdef TRACE
  313.  trace_return();
  314. #endif
  315.  return((rc==RC_SYSTEM_ERROR)?rc:macrorc);
  316. }
  317. /*man-start*********************************************************************
  318. COMMAND
  319.      mark - mark a portion of text
  320.  
  321. SYNTAX
  322.      MARK Line|Box|Stream|Word|Column
  323.  
  324. DESCRIPTION
  325.      The MARK command marks a portion of text for later processing
  326.      by a <COPY>, <MOVE> or <DELETE> command. This marked area is
  327.      known as a <block>.
  328.  
  329. COMPATIBILITY
  330.      XEDIT: N/A
  331.      KEDIT: Does not implement Stream.
  332.             Adds WORD option and COLUMN options.
  333.  
  334. STATUS
  335.      Complete.
  336. **man-end**********************************************************************/
  337. #ifdef HAVE_PROTO
  338. short Mark(CHARTYPE *params)
  339. #else
  340. short Mark(params)
  341. CHARTYPE *params;
  342. #endif
  343. /***********************************************************************/
  344. {
  345. /*-------------------------- external data ----------------------------*/
  346.  extern VIEW_DETAILS *vd_mark;
  347.  extern CHARTYPE *rec;
  348.  extern LENGTHTYPE rec_len;
  349.  extern CHARTYPE display_screens;
  350. /*--------------------------- local data ------------------------------*/
  351.  LINETYPE true_line=0L;
  352.  unsigned short y=0,x=0;
  353.  unsigned short real_col=0;
  354.  bool type_param=FALSE;
  355.  LENGTHTYPE first_col=0,last_col=0;
  356. /*--------------------------- processing ------------------------------*/
  357. #ifdef TRACE
  358.  trace_function("comm3.c:   Mark");
  359. #endif
  360. /*---------------------------------------------------------------------*/
  361. /* Marking text sets the following variables:                          */
  362. /* LINE:                                                               */
  363. /*         CURRENT_VIEW->marked_line:       TRUE                       */
  364. /*         CURRENT_VIEW->marked_start_line: line number of first line  */
  365. /*         CURRENT_VIEW->marked_end_line:   line number of last line   */
  366. /*         CURRENT_VIEW->marked_col:        FALSE                      */
  367. /*         CURRENT_VIEW->marked_start_col:  1 (ignored)                */
  368. /*         CURRENT_VIEW->marked_end_col:    max width of line(ignored) */
  369. /* BOX:                                                                */
  370. /* STREAM:                                                             */
  371. /* WORD:                                                               */
  372. /*         CURRENT_VIEW->marked_line:       TRUE                       */
  373. /*         CURRENT_VIEW->marked_start_line: line number of first line  */
  374. /*         CURRENT_VIEW->marked_end_line:   line number of last line   */
  375. /*         CURRENT_VIEW->marked_col:        TRUE                       */
  376. /*         CURRENT_VIEW->marked_start_col:  first column               */
  377. /*         CURRENT_VIEW->marked_end_col:    last column                */
  378. /* COLUMN:                                                             */
  379. /*         CURRENT_VIEW->marked_line:       FALSE                      */
  380. /*         CURRENT_VIEW->marked_start_line: (ignored)                  */
  381. /*         CURRENT_VIEW->marked_end_line:   (ignored)                  */
  382. /*         CURRENT_VIEW->marked_col:        TRUE                       */
  383. /*         CURRENT_VIEW->marked_start_col:  first column               */
  384. /*         CURRENT_VIEW->marked_end_col:    last column                */
  385. /*---------------------------------------------------------------------*/
  386. /* Validate the argument...                                            */
  387. /*---------------------------------------------------------------------*/
  388.  if (equal((CHARTYPE *)"line",params,1))
  389.     type_param = M_LINE;
  390.  if (equal((CHARTYPE *)"box",params,1))
  391.     type_param = M_BOX;
  392.  if (equal((CHARTYPE *)"word",params,1))
  393.     type_param = M_WORD;
  394.  if (equal((CHARTYPE *)"column",params,1))
  395.     type_param = M_COLUMN;
  396.  if (equal((CHARTYPE *)"stream",params,1))
  397.     type_param = M_STREAM;
  398.  if (type_param == 0)
  399.    {
  400.     display_error(1,params,FALSE);
  401. #ifdef TRACE
  402.     trace_return();
  403. #endif
  404.     return(RC_INVALID_OPERAND);
  405.    }
  406.  true_line = get_true_line(FALSE);
  407. /*---------------------------------------------------------------------*/
  408. /* If we are on 'Top of File' or 'Bottom of File' lines, error.        */
  409. /*---------------------------------------------------------------------*/
  410.  if (TOF(true_line) || BOF(true_line))
  411.    {
  412.     display_error(38,(CHARTYPE *)"",FALSE);
  413. #ifdef TRACE
  414.     trace_return();
  415. #endif
  416.     return(RC_INVALID_ENVIRON);
  417.    }
  418. /*---------------------------------------------------------------------*/
  419. /* If we are in the file area or prefix area and the focus line is not */
  420. /* a real line, error.                                                 */
  421. /*---------------------------------------------------------------------*/
  422.  getyx(CURRENT_WINDOW,y,x);
  423.  if (CURRENT_VIEW->current_window == WINDOW_FILEAREA
  424.  ||  CURRENT_VIEW->current_window == WINDOW_PREFIX)
  425.    {
  426.     if (CURRENT_SCREEN.sl[y].line_type != LINE_LINE)
  427.       {
  428.        display_error(38,(CHARTYPE *)"",FALSE);
  429. #ifdef TRACE
  430.        trace_return();
  431. #endif
  432.        return(RC_INVALID_ENVIRON);
  433.       }
  434.    }
  435. /*---------------------------------------------------------------------*/
  436. /* Reset the previous marked view...                                   */
  437. /*---------------------------------------------------------------------*/
  438.  if (MARK_VIEW != (VIEW_DETAILS *)NULL
  439.  &&  MARK_VIEW != CURRENT_VIEW)
  440.    {
  441.     MARK_VIEW->marked_line = MARK_VIEW->marked_col = FALSE;
  442.     if (display_screens > 1
  443.     &&  MARK_VIEW == OTHER_VIEW)
  444.       {
  445.        MARK_VIEW = (VIEW_DETAILS *)NULL;
  446.        build_screen(other_screen);
  447.        display_screen(other_screen);
  448.       }
  449.    }
  450.  MARK_VIEW = CURRENT_VIEW;
  451.  CURRENT_VIEW->mark_type = type_param;
  452. /*---------------------------------------------------------------------*/
  453. /* Set the new values for top and bottom lines marked.                 */
  454. /*---------------------------------------------------------------------*/
  455.  if (CURRENT_VIEW->marked_line)
  456.    {
  457.     if (true_line > CURRENT_VIEW->mark_end_line)
  458.        CURRENT_VIEW->mark_end_line = true_line;
  459.     if (true_line < CURRENT_VIEW->mark_start_line)
  460.        CURRENT_VIEW->mark_start_line = true_line;
  461.     if (true_line < CURRENT_VIEW->mark_end_line
  462.     &&  true_line > CURRENT_VIEW->mark_start_line)
  463.       {
  464.        if (true_line-CURRENT_VIEW->mark_end_line >
  465.            CURRENT_VIEW->mark_start_line-true_line)
  466.           CURRENT_VIEW->mark_end_line = true_line;
  467.        else
  468.           CURRENT_VIEW->mark_start_line = true_line;
  469.       }
  470.    }
  471.  else
  472.    {
  473.     CURRENT_VIEW->mark_start_line = CURRENT_VIEW->mark_end_line = true_line;
  474.    }
  475. /*---------------------------------------------------------------------*/
  476. /* Set the new values for first and last columns marked.               */
  477. /*---------------------------------------------------------------------*/
  478.  real_col = x + CURRENT_VIEW->verify_col;
  479.  if (CURRENT_VIEW->marked_col)
  480.    {
  481.     if ((real_col) > CURRENT_VIEW->mark_end_col)
  482.        CURRENT_VIEW->mark_end_col = (real_col);
  483.     if ((real_col) < CURRENT_VIEW->mark_start_col)
  484.        CURRENT_VIEW->mark_start_col = (real_col);
  485.     if ((real_col) < CURRENT_VIEW->mark_end_col
  486.     &&  (real_col) > CURRENT_VIEW->mark_start_col)
  487.       {
  488.        if ((real_col)-CURRENT_VIEW->mark_end_col > CURRENT_VIEW->mark_start_col-(real_col))
  489.           CURRENT_VIEW->mark_end_col = (real_col);
  490.        else
  491.           CURRENT_VIEW->mark_start_col = (real_col);
  492.       }
  493.    }
  494.  else
  495.    {
  496.     CURRENT_VIEW->mark_start_col = CURRENT_VIEW->mark_end_col = real_col;
  497.    }
  498. /*---------------------------------------------------------------------*/
  499. /* Set flags for various marked text types...                          */
  500. /*---------------------------------------------------------------------*/
  501.  switch(type_param)
  502.    {
  503.     case M_LINE:
  504.          CURRENT_VIEW->marked_col = FALSE;
  505.          CURRENT_VIEW->marked_line = TRUE;
  506.          CURRENT_VIEW->mark_start_col = 1;
  507.          CURRENT_VIEW->mark_end_col = max_line_length;
  508.          break;
  509.     case M_BOX:
  510.          CURRENT_VIEW->marked_col = TRUE;
  511.          CURRENT_VIEW->marked_line = TRUE;
  512.          break;
  513.     case M_WORD:
  514.          if (get_word(rec,rec_len,real_col-1,&first_col,&last_col) == 0)
  515.            {
  516.             CURRENT_VIEW->marked_line = CURRENT_VIEW->marked_col = FALSE;
  517.             MARK_VIEW = (VIEW_DETAILS *)NULL;
  518.             break;
  519.            }
  520.          CURRENT_VIEW->marked_col = TRUE;
  521.          CURRENT_VIEW->marked_line = TRUE;
  522.          CURRENT_VIEW->mark_start_line = CURRENT_VIEW->mark_end_line = true_line;
  523.          CURRENT_VIEW->mark_start_col = first_col+1;
  524.          CURRENT_VIEW->mark_end_col = last_col+1;
  525.          break;
  526.     case M_COLUMN:
  527.          CURRENT_VIEW->marked_line = FALSE;
  528.          CURRENT_VIEW->marked_col = TRUE;
  529.          CURRENT_VIEW->mark_start_line = 1L;
  530.          CURRENT_VIEW->mark_end_line = MAX_LONG;
  531.          break;
  532.     case M_STREAM:
  533.          CURRENT_VIEW->marked_col = TRUE;
  534.          CURRENT_VIEW->marked_line = TRUE;
  535.          break;
  536.    }
  537.  build_screen(current_screen); 
  538.  display_screen(current_screen);
  539.  wmove(CURRENT_WINDOW,y,x);
  540. #ifdef TRACE
  541.  trace_return();
  542. #endif
  543.  return(RC_OK);
  544. }
  545. /*man-start*********************************************************************
  546. COMMAND
  547.      modify - display current SET command for alteration
  548.  
  549. SYNTAX
  550.      MODify set-command
  551.  
  552. DESCRIPTION
  553.      The MODIFY command displays the current setting of a <SET> command
  554.      on the command line enabling the user to change that setting.
  555.  
  556. COMPATIBILITY
  557.      XEDIT: Compatible.
  558.      KEDIT: Compatible.
  559.  
  560. SEE ALSO
  561.      <SET>, <QUERY>
  562.  
  563. STATUS
  564.      Complete.
  565. **man-end**********************************************************************/
  566. #ifdef HAVE_PROTO
  567. short Modify(CHARTYPE *params)
  568. #else
  569. short Modify(params)
  570. CHARTYPE *params;
  571. #endif
  572. /***********************************************************************/
  573. {
  574. /*-------------------------- external data ----------------------------*/
  575.  extern CHARTYPE *temp_cmd;
  576. /*--------------------------- local data ------------------------------*/
  577.  short rc=RC_OK;
  578. /*--------------------------- processing ------------------------------*/
  579. #ifdef TRACE
  580.  trace_function("comm3.c:   Modify");
  581. #endif
  582.  if ((rc = execute_modify_command(params)) == RC_OK)
  583.     Cmsg(temp_cmd);
  584. #ifdef TRACE
  585.  trace_return();
  586. #endif
  587.  return(rc);
  588. }
  589. /*man-start*********************************************************************
  590. COMMAND
  591.      move - move a portion of text
  592.  
  593. SYNTAX
  594.      MOVE target1 target2
  595.      MOVE BLOCK [RESET]
  596.  
  597. DESCRIPTION
  598.      The MOVE command copies the contents of a portion of the file to
  599.      the same or a different file, and deletes the marked portion from 
  600.      the original file.
  601.  
  602.      The first form of the MOVE command, moves the portion of the file
  603.      specified by 'target1' to the line spcified by 'target2' in the
  604.      same file.
  605.  
  606.      The second form of the MOVE command moves the contents of the marked
  607.      <block> to the current cursor position. If the optional ['RESET']
  608.      argument is supplied, the marked block is reset as though a
  609.      <RESET> BLOCK command had been issued.
  610.  
  611. COMPATIBILITY
  612.      XEDIT: N/A
  613.      KEDIT: Adds extra functionality with [RESET] option.
  614.  
  615. STATUS
  616.      Incomplete. First form is not supported.
  617. **man-end**********************************************************************/
  618. #ifdef HAVE_PROTO
  619. short THEMove(CHARTYPE *params)
  620. #else
  621. short THEMove(params)
  622. CHARTYPE *params;
  623. #endif
  624. /***********************************************************************/
  625. {
  626. /*-------------------------- external data ----------------------------*/
  627.  extern VIEW_DETAILS *vd_mark;
  628. /*--------------------------- local data ------------------------------*/
  629. #define MOV_PARAMS 2
  630.  CHARTYPE *word[MOV_PARAMS+1];
  631.  CHARTYPE strip[MOV_PARAMS];
  632.  unsigned short num_params=0;
  633.  unsigned short y=0,x=0;
  634.  LINETYPE true_line=0L;
  635.  CHARTYPE reset_block=SOURCE_UNKNOWN;
  636.  CHARTYPE copy_command=0,delete_command=0;
  637.  short rc=RC_OK;
  638.  LINETYPE start_line=0L,end_line=0L,num_lines=0L,dest_line=0L,lines_affected=0L;
  639.  VIEW_DETAILS *old_mark_view=NULL;
  640. /*--------------------------- processing ------------------------------*/
  641. #ifdef TRACE
  642.  trace_function("comm3.c:   THEMove");
  643. #endif
  644.  strip[0]=STRIP_BOTH;
  645.  strip[1]=STRIP_BOTH;
  646.  num_params = param_split(params,word,MOV_PARAMS,WORD_DELIMS,TEMP_PARAM,strip,FALSE);
  647.  if (num_params == 0)
  648.     {
  649.      display_error(3,(CHARTYPE *)"",FALSE);
  650. #ifdef TRACE
  651.      trace_return();
  652. #endif
  653.      return(RC_INVALID_OPERAND);
  654.     }
  655.  if (num_params > 2)
  656.     {
  657.      display_error(2,(CHARTYPE *)"",FALSE);
  658. #ifdef TRACE
  659.      trace_return();
  660. #endif
  661.      return(RC_INVALID_OPERAND);
  662.     }
  663. /*---------------------------------------------------------------------*/
  664. /* Test for valid parameters...                                        */
  665. /*---------------------------------------------------------------------*/
  666.  if (num_params == 1
  667.  &&  equal((CHARTYPE *)"block",word[0],5))
  668.     reset_block = SOURCE_BLOCK;
  669.  if (num_params == 2
  670.  &&  equal((CHARTYPE *)"block",word[0],5)
  671.  &&  equal((CHARTYPE *)"reset",word[1],5))
  672.     reset_block = SOURCE_BLOCK_RESET;
  673.  if (reset_block == SOURCE_UNKNOWN)
  674.     {
  675.      display_error(1,params,FALSE);
  676. #ifdef TRACE
  677.      trace_return();
  678. #endif
  679.      return(RC_INVALID_OPERAND);
  680.     }
  681. /*---------------------------------------------------------------------*/
  682. /* Validate marked block, can be in any view.                          */
  683. /*---------------------------------------------------------------------*/
  684.  if (marked_block(FALSE) != RC_OK)
  685.    {
  686. #ifdef TRACE
  687.     trace_return();
  688. #endif
  689.     return(RC_INVALID_ENVIRON);
  690.    }
  691. /*---------------------------------------------------------------------*/
  692. /* If the cursor is in the marked block...error.                       */
  693. /*---------------------------------------------------------------------*/
  694.  if (MARK_VIEW == CURRENT_VIEW)
  695.    {
  696.     getyx(CURRENT_WINDOW_FILEAREA,y,x);
  697.     switch(MARK_VIEW->mark_type)
  698.       {
  699.        case M_LINE:
  700.        case M_WORD:
  701.        case M_COLUMN:
  702.        case M_BOX:
  703.                    if ((CURRENT_VIEW->focus_line >= MARK_VIEW->mark_start_line)
  704.                    &&  (CURRENT_VIEW->focus_line <= MARK_VIEW->mark_end_line)
  705.                    &&  (x + CURRENT_VIEW->verify_col >= MARK_VIEW->mark_start_col)
  706.                    &&  (x + CURRENT_VIEW->verify_col <= MARK_VIEW->mark_end_col))
  707.                      {
  708.                       display_error(50,(CHARTYPE *)"",FALSE);
  709. #ifdef TRACE
  710.                       trace_return();
  711. #endif
  712.                       return(RC_INVALID_ENVIRON);
  713.                      }
  714.                    break;
  715.        default:
  716.                    break;
  717.       }
  718.    }
  719. /*---------------------------------------------------------------------*/
  720. /* If block is a box, call its function.                               */
  721. /*---------------------------------------------------------------------*/
  722.  if (MARK_VIEW->mark_type == M_BOX
  723.  ||  MARK_VIEW->mark_type == M_WORD
  724.  ||  MARK_VIEW->mark_type == M_COLUMN)
  725.    {
  726.     box_operations(BOX_M,reset_block,FALSE,' ');/* don't reset and don't overlay */
  727. #ifdef TRACE
  728.     trace_return();
  729. #endif
  730.     return(RC_OK);
  731.    }
  732. /*---------------------------------------------------------------------*/
  733. /* Determine the target line. If on the command line, target is current*/
  734. /* line, else target line is focus line.                               */
  735. /*---------------------------------------------------------------------*/
  736.  true_line = get_true_line(FALSE);
  737. /*---------------------------------------------------------------------*/
  738. /* If the true  line is the bottom of file line, subtract 1 from it.   */
  739. /*---------------------------------------------------------------------*/
  740.  if (BOF(true_line))
  741.     true_line--;
  742.  
  743.  post_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line,(LINE *)NULL,TRUE);
  744.  start_line = MARK_VIEW->mark_start_line;
  745.  end_line = MARK_VIEW->mark_end_line;
  746.  num_lines = end_line - start_line + 1L;
  747.  dest_line = true_line;
  748.  old_mark_view = MARK_VIEW;
  749.  if (MARK_VIEW == CURRENT_VIEW)
  750.    {
  751.     copy_command = COMMAND_MOVE_COPY_SAME;
  752.     delete_command = COMMAND_MOVE_DELETE_SAME;
  753.    }
  754.  else
  755.    {
  756.     copy_command = COMMAND_MOVE_COPY_DIFF;
  757.     delete_command = COMMAND_MOVE_DELETE_DIFF;
  758.    }
  759.  
  760.  rc = rearrange_line_blocks(copy_command,reset_block,start_line,
  761.                             end_line,dest_line,1,MARK_VIEW,CURRENT_VIEW,FALSE,
  762.                             &lines_affected);
  763.  if (rc == RC_OK)
  764.    {
  765.     if (old_mark_view == CURRENT_VIEW)
  766.       {
  767.        if (dest_line < start_line)
  768.          {
  769.           start_line += num_lines;
  770.           end_line += num_lines;
  771.           dest_line += num_lines;
  772.          }
  773.       }
  774.     post_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line,(LINE *)NULL,TRUE);
  775.     rc = rearrange_line_blocks(delete_command,reset_block,start_line,
  776.                             end_line,start_line,1,old_mark_view,old_mark_view,FALSE,
  777.                             &lines_affected);
  778.    }
  779. #ifdef TRACE
  780.  trace_return();
  781. #endif
  782.  return(rc);
  783. }
  784. /*man-start*********************************************************************
  785. COMMAND
  786.      msg - display message on error line
  787.  
  788. SYNTAX
  789.      MSG [message]
  790.  
  791. DESCRIPTION
  792.      The MSG command displays a 'message' on the <message line>.
  793.      This command is usually issued from a macro file.
  794.      This is similar to <EMSG>, but MSG does not sound the bell if 
  795.      <SET BEEP> is on.
  796.  
  797. COMPATIBILITY
  798.      XEDIT: Compatible.
  799.      KEDIT: Compatible.
  800.  
  801. SEE ALSO
  802.      <CMSG>, <EMSG>
  803.  
  804. STATUS
  805.      Complete.
  806. **man-end**********************************************************************/
  807. #ifdef HAVE_PROTO
  808. short Msg(CHARTYPE *params)
  809. #else
  810. short Msg(params)
  811. CHARTYPE *params;
  812. #endif
  813. /***********************************************************************/
  814. {
  815. /*-------------------------- external data ----------------------------*/
  816. /*--------------------------- local data ------------------------------*/
  817. /*--------------------------- processing ------------------------------*/
  818. #ifdef TRACE
  819.  trace_function("comm3.c:   Msg");
  820. #endif
  821.  display_error(0,params,TRUE);
  822. #ifdef TRACE
  823.  trace_return();
  824. #endif
  825.  return(RC_OK);
  826. }
  827. /*man-start*********************************************************************
  828. COMMAND
  829.      next - move forward in the file a number of lines
  830.  
  831. SYNTAX
  832.      Next [relative target]
  833.  
  834. DESCRIPTION
  835.      The NEXT command moves the <current line> forwards the number of
  836.      lines specified by the <relative target>. This <relative target> can
  837.      only be a positive integer or the character "*". 
  838.  
  839. COMPATIBILITY
  840.      XEDIT: Compatible.
  841.      KEDIT: Compatible.
  842.  
  843. DEFAULT
  844.      1
  845.  
  846. SEE ALSO
  847.      <DOWN>, <UP>
  848.  
  849. STATUS
  850.      Complete.
  851. **man-end**********************************************************************/
  852. #ifdef HAVE_PROTO
  853. short THENext(CHARTYPE *params)
  854. #else
  855. short THENext(params)
  856. CHARTYPE *params;
  857. #endif
  858. /***********************************************************************/
  859. {
  860. /*-------------------------- external data ----------------------------*/
  861. /*--------------------------- local data ------------------------------*/
  862.  short rc=RC_OK;
  863.  LINETYPE num_lines=0L,true_line=0L;
  864. /*--------------------------- processing ------------------------------*/
  865. #ifdef TRACE
  866.  trace_function("comm3.c:   THENext");
  867. #endif
  868.  params = MyStrip(params,STRIP_BOTH,' ');
  869.  if (strcmp("",(DEFCHAR *)params) == 0)
  870.     params = (CHARTYPE *)"1";
  871.  true_line = get_true_line(TRUE);
  872.  if (strcmp("*",(DEFCHAR *)params) == 0)
  873.     num_lines = CURRENT_FILE->number_lines - true_line + 1L;
  874.  else
  875.    {
  876.     if (!valid_integer(params))
  877.       {
  878.        display_error(4,params,FALSE);
  879. #ifdef TRACE
  880.        trace_return();
  881. #endif
  882.        return(RC_INVALID_OPERAND);
  883.       }
  884.     num_lines = atol((DEFCHAR *)params);
  885.     if (num_lines < 0L)
  886.       {
  887.        display_error(5,params,FALSE);
  888. #ifdef TRACE
  889.        trace_return();
  890. #endif
  891.        return(RC_INVALID_OPERAND);
  892.       }
  893.    }
  894.  rc = advance_current_or_focus_line(num_lines);
  895. #ifdef TRACE
  896.  trace_return();
  897. #endif
  898.  return(rc);
  899. }
  900. /*man-start*********************************************************************
  901. COMMAND
  902.      nextwindow - switch focus of editing session to another file
  903.  
  904. SYNTAX
  905.      NEXTWindow
  906.  
  907. DESCRIPTION
  908.      The NEXTWINDOW command moves the focus of the editing session to
  909.      the other screen (if <SET SCREEN> 2 is in effect) or to the next file
  910.      in the <ring>.
  911.  
  912. COMPATIBILITY
  913.      XEDIT: N/A
  914.      KEDIT: N/A
  915.  
  916. SEE ALSO
  917.      <PREVWINDOW>, <EDIT>, <SET SCREEN>
  918.  
  919. STATUS
  920.      Complete.
  921. **man-end**********************************************************************/
  922. #ifdef HAVE_PROTO
  923. short Nextwindow(CHARTYPE *params)
  924. #else
  925. short Nextwindow(params)
  926. CHARTYPE *params;
  927. #endif
  928. /***********************************************************************/
  929. {
  930. /*-------------------------- external data ----------------------------*/
  931.  extern CHARTYPE display_screens;
  932.  extern bool horizontal;
  933.  extern WINDOW *statarea;
  934.  extern WINDOW *divider;
  935.  extern bool curses_started;
  936. /*--------------------------- local data ------------------------------*/
  937.  short rc=RC_OK;
  938. /*--------------------------- processing ------------------------------*/
  939. #ifdef TRACE
  940.  trace_function("comm3.c:   Nextwindow");
  941. #endif
  942.  if (strcmp((DEFCHAR *)params,"") != 0)
  943.    {
  944.     display_error(1,params,FALSE);
  945. #ifdef TRACE
  946.     trace_return();
  947. #endif
  948.     return(RC_INVALID_OPERAND);
  949.    }
  950.  if (display_screens == 1)
  951.    {
  952.     rc = Xedit((CHARTYPE *)"");
  953. #ifdef TRACE
  954.     trace_return();
  955. #endif
  956.     return(rc);
  957.    }
  958.  post_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line,(LINE *)NULL,TRUE);
  959.  current_screen = (current_screen == 0) ? 1 : 0;
  960.  CURRENT_VIEW = CURRENT_SCREEN.screen_view;
  961.  if (curses_started)
  962.    {
  963.     if (CURRENT_WINDOW_COMMAND != (WINDOW *)NULL)
  964.       {
  965.        wattrset(CURRENT_WINDOW_COMMAND,set_colour(CURRENT_FILE->attr+ATTR_CMDLINE));
  966.        touchwin(CURRENT_WINDOW_COMMAND);
  967.        wnoutrefresh(CURRENT_WINDOW_COMMAND);
  968.       }
  969.     if (CURRENT_WINDOW_ARROW != (WINDOW *)NULL)
  970.       {
  971.        wattrset(CURRENT_WINDOW_ARROW,set_colour(CURRENT_FILE->attr+ATTR_ARROW));
  972.        redraw_window(CURRENT_WINDOW_ARROW);
  973.        wnoutrefresh(CURRENT_WINDOW_ARROW);
  974.       }
  975.     if (statarea != (WINDOW *)NULL)
  976.       {
  977.        wattrset(statarea,set_colour(CURRENT_FILE->attr+ATTR_STATAREA));
  978.        redraw_window(statarea);
  979.       }
  980.     if (CURRENT_WINDOW_IDLINE != (WINDOW *)NULL)
  981.       {
  982.        wattrset(CURRENT_WINDOW_IDLINE,set_colour(CURRENT_FILE->attr+ATTR_IDLINE));
  983.        redraw_window(CURRENT_WINDOW_IDLINE);
  984.       }
  985.     if (display_screens > 1
  986.     &&  !horizontal)
  987.       {
  988.        wattrset(divider,set_colour(CURRENT_FILE->attr+ATTR_DIVIDER));
  989.        draw_divider();
  990.        wnoutrefresh(divider);
  991.       }
  992.    }
  993.  pre_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line,(LINE *)NULL);
  994.  build_screen(current_screen);
  995.  if (!line_in_view(current_screen,CURRENT_VIEW->focus_line))
  996.    {
  997.     CURRENT_VIEW->focus_line = CURRENT_VIEW->current_line;
  998.     build_screen(current_screen);
  999.    }
  1000.  display_screen(current_screen);
  1001.  
  1002. #ifdef TRACE
  1003.  trace_return();
  1004. #endif
  1005.  return(RC_OK);
  1006. }
  1007. /*man-start*********************************************************************
  1008. COMMAND
  1009.      nfind - locate forwards the line which does NOT begin with the supplied string
  1010.  
  1011. SYNTAX
  1012.      NFind string
  1013.  
  1014. DESCRIPTION
  1015.      The NFIND command attempts to locate a line towards the end of
  1016.      the file that does NOT begin with 'string'.
  1017.  
  1018.      'string' can contain two special characters:
  1019.  
  1020.           space - this will match any single character in the target line
  1021.           underscore - this will match any single space in the target line
  1022.  
  1023. COMPATIBILITY
  1024.      XEDIT: Compatible.
  1025.      KEDIT: Compatible.
  1026.  
  1027. SEE ALSO
  1028.      <FIND>, <FINDUP>, <NFINDUP>
  1029.  
  1030. STATUS
  1031.      Complete
  1032. **man-end**********************************************************************/
  1033. #ifdef HAVE_PROTO
  1034. short Nfind(CHARTYPE *params)
  1035. #else
  1036. short Nfind(params)
  1037. CHARTYPE *params;
  1038. #endif
  1039. /***********************************************************************/
  1040. {
  1041. /*-------------------------- external data ----------------------------*/
  1042. /*--------------------------- local data ------------------------------*/
  1043.  short rc=RC_OK;
  1044. /*--------------------------- processing ------------------------------*/
  1045. #ifdef TRACE
  1046.  trace_function("comm2.c:   Nfind");
  1047. #endif
  1048.  rc = execute_find_command(params,TARGET_NFIND);
  1049. #ifdef TRACE
  1050.  trace_return();
  1051. #endif
  1052.  return(rc);
  1053. }
  1054. /*man-start*********************************************************************
  1055. COMMAND
  1056.      nfindup - locate backwards the line which does NOT begin with the supplied string
  1057.  
  1058. SYNTAX
  1059.      NFINDUp string
  1060.      NFUp string
  1061.  
  1062. DESCRIPTION
  1063.      The NFINDUP command attempts to locate a line towards the start of
  1064.      the file that does NOT begin with 'string'.
  1065.  
  1066.      'string' can contain two special characters:
  1067.  
  1068.           space - this will match any single character in the target line
  1069.           underscore - this will match any single space in the target line
  1070.  
  1071. COMPATIBILITY
  1072.      XEDIT: Compatible.
  1073.      KEDIT: Compatible.
  1074.  
  1075. SEE ALSO
  1076.      <FIND>, <FINDUP>, <NFIND>
  1077.  
  1078. STATUS
  1079.      Complete
  1080. **man-end**********************************************************************/
  1081. #ifdef HAVE_PROTO
  1082. short Nfindup(CHARTYPE *params)
  1083. #else
  1084. short Nfindup(params)
  1085. CHARTYPE *params;
  1086. #endif
  1087. /***********************************************************************/
  1088. {
  1089. /*-------------------------- external data ----------------------------*/
  1090. /*--------------------------- local data ------------------------------*/
  1091.  short rc=RC_OK;
  1092. /*--------------------------- processing ------------------------------*/
  1093. #ifdef TRACE
  1094.  trace_function("comm2.c:   Nfindup");
  1095. #endif
  1096.  rc = execute_find_command(params,TARGET_NFINDUP);
  1097. #ifdef TRACE
  1098.  trace_return();
  1099. #endif
  1100.  return(rc);
  1101. }
  1102. /*man-start*********************************************************************
  1103. COMMAND
  1104.      nomsg - execute a command suppressing any messages 
  1105.  
  1106. SYNTAX
  1107.      NOMSG command [arguments]
  1108.  
  1109. DESCRIPTION
  1110.      The NOMSG command executes the supplied 'command' but suppresses
  1111.      messages that would normally be displayed as a result of the 
  1112.      command.
  1113.  
  1114.      Optional 'arguments' may be passed to the 'command'.
  1115.  
  1116. COMPATIBILITY
  1117.      XEDIT: N/A
  1118.      KEDIT: Compatible.
  1119.  
  1120. STATUS
  1121.      Complete.
  1122. **man-end**********************************************************************/
  1123. #ifdef HAVE_PROTO
  1124. short Nomsg(CHARTYPE *params)
  1125. #else
  1126. short Nomsg(params)
  1127. CHARTYPE *params;
  1128. #endif
  1129. /***********************************************************************/
  1130. {
  1131. /*-------------------------- external data ----------------------------*/
  1132.  extern bool in_nomsg;
  1133. /*--------------------------- local data ------------------------------*/
  1134.  short rc=RC_OK;
  1135. /*--------------------------- processing ------------------------------*/
  1136. #ifdef TRACE
  1137.  trace_function("comm3.c:   Nomsg");
  1138. #endif
  1139.  in_nomsg = TRUE;
  1140.  rc = command_line(params,COMMAND_ONLY_FALSE);
  1141.  in_nomsg = FALSE;
  1142. #ifdef TRACE
  1143.  trace_return();
  1144. #endif
  1145.  return(rc);
  1146. }
  1147. /*man-start*********************************************************************
  1148. COMMAND
  1149.      nop - no operation command
  1150.  
  1151. SYNTAX
  1152.      NOP
  1153.  
  1154. DESCRIPTION
  1155.      The NOP command does nothing. It is used as a means of turning
  1156.      off an assignment to a key.
  1157.  
  1158. COMPATIBILITY
  1159.      XEDIT: N/A
  1160.      KEDIT: N/A
  1161.  
  1162. SEE ALSO
  1163.      <DEFINE>
  1164.  
  1165. STATUS
  1166.      Complete.
  1167. **man-end**********************************************************************/
  1168. #ifdef HAVE_PROTO
  1169. short Nop(CHARTYPE *params)
  1170. #else
  1171. short Nop(params)
  1172. CHARTYPE *params;
  1173. #endif
  1174. /***********************************************************************/
  1175. {
  1176. /*--------------------------- local data ------------------------------*/
  1177. /*--------------------------- processing ------------------------------*/
  1178. #ifdef TRACE
  1179.  trace_function("comm3.c:   Nop");
  1180. #endif
  1181. /*---------------------------------------------------------------------*/
  1182. /* No arguments are allowed; error if any are present.                 */
  1183. /*---------------------------------------------------------------------*/
  1184.  if (strcmp((DEFCHAR *)params,"") != 0)
  1185.    {
  1186.     display_error(1,(CHARTYPE *)params,FALSE);
  1187. #ifdef TRACE
  1188.     trace_return();
  1189. #endif
  1190.     return(RC_INVALID_OPERAND);
  1191.    }
  1192. #ifdef TRACE
  1193.  trace_return();
  1194. #endif
  1195.  return(RC_OK);
  1196. }
  1197. /*man-start*********************************************************************
  1198. COMMAND
  1199.      os - execute an operating system command
  1200.  
  1201. SYNTAX
  1202.      OS [command]
  1203.  
  1204. DESCRIPTION
  1205.      The OS command executes the supplied operating system 'command'
  1206.      or runs an interactive shell if no 'command' is supplied.
  1207.  
  1208. COMPATIBILITY
  1209.      XEDIT: N/A
  1210.      KEDIT: Equivalent to DOS command.
  1211.  
  1212. SEE ALSO
  1213.      <DOS>, <!>
  1214.  
  1215. STATUS
  1216.      Complete.
  1217. **man-end**********************************************************************/
  1218. #ifdef HAVE_PROTO
  1219. short Os(CHARTYPE *params)
  1220. #else
  1221. short Os(params)
  1222. CHARTYPE *params;
  1223. #endif
  1224. /***********************************************************************/
  1225. {
  1226. /*--------------------------- local data ------------------------------*/
  1227.  short rc=RC_OK;
  1228. /*--------------------------- processing ------------------------------*/
  1229. #ifdef TRACE
  1230.  trace_function("comm3.c:   Os");
  1231. #endif
  1232. /*---------------------------------------------------------------------*/
  1233. /* Execute the supplied parameters as OS commands. Run with output     */
  1234. /* displayed and pause before redrawing the windows.                   */
  1235. /*---------------------------------------------------------------------*/
  1236.  rc = execute_os_command(params,FALSE,TRUE);
  1237. #ifdef TRACE
  1238.  trace_return();
  1239. #endif
  1240.  return(rc);
  1241. }
  1242. /*man-start*********************************************************************
  1243. COMMAND
  1244.      osnowait - execute an operating system command - no prompt
  1245.  
  1246. SYNTAX
  1247.      OSNowait command
  1248.  
  1249. DESCRIPTION
  1250.      The OSNOWAIT command executes the supplied operating system 
  1251.      'command' not waiting for the user to be prompted once the
  1252.      command has completed.
  1253.  
  1254. COMPATIBILITY
  1255.      XEDIT: N/A
  1256.      KEDIT: Equivalent of <DOSNOWAIT> command.
  1257.  
  1258. SEE ALSO
  1259.      <DOSNOWAIT>
  1260.  
  1261. STATUS
  1262.      Complete.
  1263. **man-end**********************************************************************/
  1264. #ifdef HAVE_PROTO
  1265. short Osnowait(CHARTYPE *params)
  1266. #else
  1267. short Osnowait(params)
  1268. CHARTYPE *params;
  1269. #endif
  1270. /***********************************************************************/
  1271. {
  1272. /*--------------------------- local data ------------------------------*/
  1273.  short rc=RC_OK;
  1274. /*--------------------------- processing ------------------------------*/
  1275. #ifdef TRACE
  1276.  trace_function("comm3.c:   Osnowait");
  1277. #endif
  1278. /*---------------------------------------------------------------------*/
  1279. /* Execute the supplied parameters as OS commands. Run with output     */
  1280. /* displayed but no pause before redrawing the windows.                */
  1281. /*---------------------------------------------------------------------*/
  1282.  if (strcmp((DEFCHAR *)params,"") == 0)          /* no params....error */
  1283.    {
  1284.     display_error(3,(CHARTYPE *)"",FALSE);
  1285. #ifdef TRACE
  1286.     trace_return();
  1287. #endif
  1288.     return(RC_INVALID_OPERAND);
  1289.    }
  1290.  rc = execute_os_command(params,FALSE,FALSE);
  1291. #ifdef TRACE
  1292.  trace_return();
  1293. #endif
  1294.  return(rc);
  1295. }
  1296. /*man-start*********************************************************************
  1297. COMMAND
  1298.      osquiet - execute an operating system command quietly
  1299.  
  1300. SYNTAX
  1301.      OSQuiet command
  1302.  
  1303. DESCRIPTION
  1304.      The OSQUIET command executes the supplied operating system 'command'
  1305.      as quietly as possible.
  1306.  
  1307. COMPATIBILITY
  1308.      XEDIT: N/A
  1309.      KEDIT: Equivalent of <DOSQUIET> command.
  1310.  
  1311. SEE ALSO
  1312.      <DOSQUIET>
  1313.  
  1314. STATUS
  1315.      Complete.
  1316. **man-end**********************************************************************/
  1317. #ifdef HAVE_PROTO
  1318. short Osquiet(CHARTYPE *params)
  1319. #else
  1320. short Osquiet(params)
  1321. CHARTYPE *params;
  1322. #endif
  1323. /***********************************************************************/
  1324. {
  1325. /*--------------------------- local data ------------------------------*/
  1326.  short rc=RC_OK;
  1327. /*--------------------------- processing ------------------------------*/
  1328. #ifdef TRACE
  1329.  trace_function("comm3.c:   Osquiet");
  1330. #endif
  1331. /*---------------------------------------------------------------------*/
  1332. /* Execute the supplied parameters as OS commands. Run with no output  */
  1333. /* displayed and no pause before redrawing the windows.                */
  1334. /*---------------------------------------------------------------------*/
  1335.  if (strcmp((DEFCHAR *)params,"") == 0)          /* no params....error */
  1336.    {
  1337.     display_error(3,(CHARTYPE *)"",FALSE);
  1338. #ifdef TRACE
  1339.     trace_return();
  1340. #endif
  1341.     return(RC_INVALID_OPERAND);
  1342.    }
  1343.  rc = execute_os_command(params,TRUE,FALSE);
  1344. #ifdef TRACE
  1345.  trace_return();
  1346. #endif
  1347.  return(rc);
  1348. }
  1349. /*man-start*********************************************************************
  1350. COMMAND
  1351.      osredir - execute an operating system command and capture output
  1352.  
  1353. SYNTAX
  1354.      OSRedir filename command [arguments ...]
  1355.  
  1356. DESCRIPTION
  1357.      The OSREDIR command executes the supplied operating system 'command'
  1358.      and redirects output destined for STDOUT and STDERR to the specified 
  1359.      'filename'.
  1360.  
  1361.      Optional 'arguments' may be supplied to the 'command'.
  1362.  
  1363. COMPATIBILITY
  1364.      XEDIT: N/A
  1365.      KEDIT: N/A
  1366.  
  1367. SEE ALSO
  1368.      <OS>, <OSQUIET>, <OSNOWAIT>
  1369.  
  1370. STATUS
  1371.      Complete.
  1372. **man-end**********************************************************************/
  1373. #ifdef HAVE_PROTO
  1374. short Osredir(CHARTYPE *params)
  1375. #else
  1376. short Osredir(params)
  1377. CHARTYPE *params;
  1378. #endif
  1379. /***********************************************************************/
  1380. {
  1381. /*--------------------------- local data ------------------------------*/
  1382.  short rc=RC_OK;
  1383. #define OSR_PARAMS 2
  1384.  CHARTYPE strip[OSR_PARAMS];
  1385.  CHARTYPE *word[OSR_PARAMS+1];
  1386.  unsigned short num_params=0;
  1387.  int save_stdout=0,save_stderr=0;
  1388.  int fd=0;
  1389. /*--------------------------- processing ------------------------------*/
  1390. #ifdef TRACE
  1391.  trace_function("comm3.c:   Osredir");
  1392. #endif
  1393. /*---------------------------------------------------------------------*/
  1394. /* Execute the supplied parameters as OS commands. Run with no output  */
  1395. /* displayed and no pause before redrawing the windows.                */
  1396. /*---------------------------------------------------------------------*/
  1397.  strip[0]=STRIP_BOTH;
  1398.  strip[1]=STRIP_BOTH;
  1399.  num_params = param_split(params,word,OSR_PARAMS,WORD_DELIMS,TEMP_PARAM,strip,FALSE);
  1400.  if (num_params == 0)
  1401.     {
  1402.      display_error(3,(CHARTYPE *)"",FALSE);
  1403. #ifdef TRACE
  1404.      trace_return();
  1405. #endif
  1406.      return(RC_INVALID_OPERAND);
  1407.     }
  1408.  if (num_params > 2)
  1409.     {
  1410.      display_error(2,(CHARTYPE *)"",FALSE);
  1411. #ifdef TRACE
  1412.      trace_return();
  1413. #endif
  1414.      return(RC_INVALID_OPERAND);
  1415.     }
  1416.  save_stdout = dup(fileno(stdout));
  1417.  save_stderr = dup(fileno(stderr));
  1418. #ifdef UNIX
  1419.  fd = open((DEFCHAR *)word[0],O_RDWR|O_CREAT|O_TRUNC);
  1420. #else
  1421.  fd = open((DEFCHAR *)word[0],O_RDWR|O_CREAT|O_TRUNC,S_IWRITE|S_IREAD);
  1422. #endif
  1423.  if (fd == (-1))
  1424.     {
  1425.      display_error(8,word[0],FALSE);
  1426. #ifdef TRACE
  1427.      trace_return();
  1428. #endif
  1429.      return(RC_INVALID_OPERAND);
  1430.     }
  1431. #ifdef UNIX
  1432.  chmod((DEFCHAR *)word[0],S_IWUSR|S_IRUSR);
  1433. #endif
  1434.  dup2(fd,fileno(stdout));
  1435.  dup2(fd,fileno(stderr));
  1436.  close(fd);
  1437.  system((DEFCHAR *)word[1]);
  1438.  dup2(save_stdout,fileno(stdout));
  1439.  dup2(save_stderr,fileno(stderr));
  1440.  close(save_stdout);
  1441.  close(save_stderr);
  1442. #ifdef TRACE
  1443.  trace_return();
  1444. #endif
  1445.  return(rc);
  1446. }
  1447. /*man-start*********************************************************************
  1448. COMMAND
  1449.      overlaybox - overlay marked block on current cursor position
  1450.  
  1451. SYNTAX
  1452.      OVERLAYBox
  1453.  
  1454. DESCRIPTION
  1455.      The OVERLAYBOX command overlays the contents of the marked <block>;
  1456.      <box block> or <line block>, over the characters or lines at the
  1457.      <focus line> and <focus column>.
  1458.  
  1459.      This command implies that only <box block>s are handled.  This used
  1460.      to be the case, and for compatibility reasons the name remains.
  1461.  
  1462. COMPATIBILITY
  1463.      XEDIT: N/A
  1464.      KEDIT: Compatible.
  1465.  
  1466. SEE ALSO
  1467.      <MOVE>, <COPY>
  1468.  
  1469. STATUS
  1470.      Complete.
  1471. **man-end**********************************************************************/
  1472. #ifdef HAVE_PROTO
  1473. short Overlaybox(CHARTYPE *params)
  1474. #else
  1475. short Overlaybox(params)
  1476. CHARTYPE *params;
  1477. #endif
  1478. /***********************************************************************/
  1479. {
  1480. /*-------------------------- external data ----------------------------*/
  1481.  extern VIEW_DETAILS *vd_mark;
  1482.  extern bool curses_started;
  1483. /*--------------------------- local data ------------------------------*/
  1484.  unsigned short y=0,x=0;
  1485.  LINETYPE true_line=0L,start_line=0L,end_line=0L,num_lines=0L,dest_line=0L,lines_affected=0L;
  1486.  VIEW_DETAILS *old_mark_view=NULL;
  1487.  short rc=RC_OK;
  1488.  LINE *curr=NULL;
  1489.  LINETYPE save_current_line=CURRENT_VIEW->current_line;
  1490. /*--------------------------- processing ------------------------------*/
  1491. #ifdef TRACE
  1492.  trace_function("comm3.c:   Overlaybox");
  1493. #endif
  1494. /*---------------------------------------------------------------------*/
  1495. /* Ensure there are no parameters.                                     */
  1496. /*---------------------------------------------------------------------*/
  1497.  if (strcmp((DEFCHAR *)params,"") != 0)
  1498.    {
  1499.     display_error(1,params,FALSE);
  1500. #ifdef TRACE
  1501.     trace_return();
  1502. #endif
  1503.     return(RC_INVALID_OPERAND);
  1504.    }
  1505. /*---------------------------------------------------------------------*/
  1506. /* Validate marked block, can be in any view.                          */
  1507. /*---------------------------------------------------------------------*/
  1508.  if (marked_block(FALSE) != RC_OK)
  1509.    {
  1510. #ifdef TRACE
  1511.     trace_return();
  1512. #endif
  1513.     return(RC_INVALID_ENVIRON);
  1514.    }
  1515. /*---------------------------------------------------------------------*/
  1516. /* Only allow command for box, column and word blocks.                 */
  1517. /*---------------------------------------------------------------------*/
  1518.  if (MARK_VIEW->mark_type != M_BOX
  1519.  &&  MARK_VIEW->mark_type != M_COLUMN
  1520.  &&  MARK_VIEW->mark_type != M_LINE
  1521.  &&  MARK_VIEW->mark_type != M_WORD)
  1522.    {
  1523.     display_error(47,(CHARTYPE *)"",FALSE);
  1524. #ifdef TRACE
  1525.     trace_return();
  1526. #endif
  1527.     return(RC_INVALID_ENVIRON);
  1528.    }
  1529. /*---------------------------------------------------------------------*/
  1530. /* If the command is executed from the filearea, the focus line must be*/
  1531. /* in scope...                                                         */
  1532. /*---------------------------------------------------------------------*/
  1533.  if (curses_started)
  1534.    {
  1535.     if (CURRENT_VIEW->current_window != WINDOW_COMMAND)
  1536.       {
  1537.        getyx(CURRENT_WINDOW,y,x);
  1538.        if (!in_scope(CURRENT_VIEW,CURRENT_SCREEN.sl[y].current)
  1539.        && !CURRENT_VIEW->scope_all)
  1540.          {
  1541.           display_error(87,(CHARTYPE *)"",FALSE);
  1542. #ifdef TRACE
  1543.           trace_return();
  1544. #endif
  1545.           return(RC_INVALID_ENVIRON);
  1546.          }
  1547.       }
  1548.    }
  1549. /*---------------------------------------------------------------------*/
  1550. /* If block is a box, call its function.                               */
  1551. /*---------------------------------------------------------------------*/
  1552.  if (MARK_VIEW->mark_type == M_BOX
  1553.  ||  MARK_VIEW->mark_type == M_WORD
  1554.  ||  MARK_VIEW->mark_type == M_COLUMN)
  1555.    {
  1556.     box_operations(BOX_C,SOURCE_BLOCK,TRUE,' ');  /* no reset, overlay */
  1557. #ifdef TRACE
  1558.     trace_return();
  1559. #endif
  1560.     return(RC_OK);
  1561.    }
  1562. /*---------------------------------------------------------------------*/
  1563. /* Determine the target line. If on the command line, target is current*/
  1564. /* line, else target line is focus line.                               */
  1565. /*---------------------------------------------------------------------*/
  1566.  true_line = get_true_line(TRUE);
  1567.  
  1568.  post_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line,(LINE *)NULL,TRUE);
  1569.  start_line = MARK_VIEW->mark_start_line;
  1570.  end_line = MARK_VIEW->mark_end_line;
  1571.  num_lines = end_line - start_line + 1L;
  1572.  dest_line = true_line-1L;
  1573.  old_mark_view = MARK_VIEW;
  1574.  
  1575.  rc = rearrange_line_blocks(COMMAND_OVERLAY_COPY,SOURCE_BLOCK,start_line,
  1576.                             end_line,dest_line,1,MARK_VIEW,CURRENT_VIEW,FALSE,
  1577.                             &lines_affected);
  1578.  if (rc == RC_OK
  1579.  &&  lines_affected != 0)
  1580.    {
  1581.     start_line = end_line = true_line + lines_affected;
  1582.     curr = lll_find(CURRENT_FILE->first_line,CURRENT_FILE->last_line,start_line,CURRENT_FILE->number_lines);
  1583.     while(1)
  1584.       {
  1585.        if (in_scope(CURRENT_VIEW,curr)
  1586.        || CURRENT_VIEW->scope_all)
  1587.           lines_affected--;
  1588.        curr = curr->next;
  1589.        if (curr == NULL
  1590.        ||  lines_affected == 0L
  1591.        ||  end_line == CURRENT_FILE->number_lines)
  1592.           break;
  1593.        end_line++;
  1594.       }
  1595.     dest_line = true_line;
  1596.     post_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line,(LINE *)NULL,TRUE);
  1597.     rc = rearrange_line_blocks(COMMAND_OVERLAY_DELETE,SOURCE_BLOCK,start_line,
  1598.                             end_line,dest_line,1,CURRENT_VIEW,CURRENT_VIEW,FALSE,
  1599.                             &lines_affected);
  1600.     if (old_mark_view != MARK_VIEW)
  1601.        old_mark_view->marked_line = old_mark_view->marked_col = FALSE;
  1602.    }
  1603.  CURRENT_VIEW->current_line = save_current_line;
  1604.  build_screen(current_screen);
  1605.  display_screen(current_screen);
  1606.  if (curses_started
  1607.  && CURRENT_VIEW->current_window != WINDOW_COMMAND)
  1608.    wmove(CURRENT_WINDOW,y,x);
  1609.  
  1610. #ifdef TRACE
  1611.  trace_return();
  1612. #endif
  1613.  return(rc);
  1614. }
  1615.