home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / thesrc15.zip / comm2.c < prev    next >
C/C++ Source or Header  |  1993-11-25  |  34KB  |  1,157 lines

  1. /***********************************************************************/
  2. /* COMM2.C - Commands E-J                                              */
  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-1993 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@gu.edu.au
  35.  * 36 David Road                     Phone: +61 7 849 7731
  36.  * Holland Park                      Fax:   +61 7 875 5314
  37.  * QLD 4121
  38.  * Australia
  39.  */
  40.  
  41. /*
  42. $Header: C:\THE\RCS\comm2.c 1.4 1993/09/01 16:25:38 MH Interim MH $
  43. */
  44.  
  45. #include <stdio.h>
  46.  
  47. #include "the.h"
  48. #include "proto.h"
  49.  
  50. /*#define DEBUG 1*/
  51.  
  52. /*-------------------------- external data ----------------------------*/
  53. extern LINE *next_line,*curr_line;
  54. extern VIEW_DETAILS *vd_current,*vd_first,*vd_mark;
  55. extern char current_screen;
  56. extern SCREEN_DETAILS screen[MAX_SCREENS];        /* screen structures */
  57. extern char current_file;         /* pointer to current file */
  58. extern WINDOW *foot,*error_window;
  59. extern bool error_on_screen;
  60. extern char *temp_cmd;
  61. extern char *cmd_rec;
  62. extern unsigned short cmd_rec_len;
  63. extern char *pre_rec;
  64. extern unsigned short pre_rec_len;
  65. extern char *rec;
  66. extern unsigned short rec_len;
  67. extern char mode_insert;        /* defines insert mode toggle */
  68. extern char in_profile;    /* indicates if processing profile */
  69. extern char in_macro;
  70. extern char *tempfilename;
  71. extern unsigned short file_start;
  72. extern char curr_path[MAX_FILE_NAME+1] ;
  73. extern char sp_path[MAX_FILE_NAME+1] ;
  74. extern char sp_fname[MAX_FILE_NAME+1] ;
  75. /*man-start*********************************************************************
  76. COMMAND
  77.      emsg - display error message
  78.  
  79. SYNTAX
  80.      EMSG [message]
  81.  
  82. DESCRIPTION
  83.      The EMSG command displays an error message on the error line.
  84.      This command is usually issued from a macro file.
  85.  
  86. COMPATIBILITY
  87.      XEDIT: Does not support [mmmnnns text] option
  88.      KEDIT: Compatible
  89.  
  90. SEE ALSO
  91.      EMSG
  92.  
  93. STATUS
  94.      Complete.
  95. **man-end**********************************************************************/
  96. #ifdef PROTO
  97. int Emsg(char *params)
  98. #else
  99. int Emsg(params)
  100. char *params;
  101. #endif
  102. /***********************************************************************/
  103. {
  104. /*-------------------------- external data ----------------------------*/
  105. /*--------------------------- local data ------------------------------*/
  106. /*--------------------------- processing ------------------------------*/
  107. #ifdef TRACE
  108.  trace_function("comm1.c:   Emsg");
  109. #endif
  110.  display_error(0,params);
  111. #ifdef TRACE
  112.  trace_return();
  113. #endif
  114.  return(RC_OK);
  115. }
  116. /*man-start*********************************************************************
  117. COMMAND
  118.      enter - execute a command
  119.  
  120. SYNTAX
  121.      ** effective only if bound to a key **
  122.  
  123. DESCRIPTION
  124.      The ENTER command executes the command currently displayed on the
  125.      command line, if the cursor is currently displayed there.
  126.      If the key associated with ENTER is pressed while in the main or
  127.      prefix window, then the cursor will move to the first column of the
  128.      next line. If the mode is currently in 'insert', then a new line
  129.      is added and the cursor placed at the first column of the new line.
  130.  
  131. COMPATIBILITY
  132.      XEDIT: N/A
  133.      KEDIT: N/A
  134.  
  135. STATUS
  136.      Complete.
  137. **man-end**********************************************************************/
  138. #ifdef PROTO
  139. int Enter(char *params)
  140. #else
  141. int Enter(params)
  142. char *params;
  143. #endif
  144. /***********************************************************************/
  145. {
  146. /*--------------------------- local data ------------------------------*/
  147.  unsigned short x,y;
  148.  short rc=RC_OK;
  149.  register int i;
  150.  static char first=TRUE;
  151.  static char number_of_commands=0;
  152.  WINDOW *w;
  153. /*--------------------------- processing ------------------------------*/
  154. #ifdef TRACE
  155.  trace_function("comm1.c:   Enter");
  156. #endif
  157.  switch(CURRENT_VIEW->current_window)
  158.    {
  159.     case WINDOW_COMMAND:
  160.          for (i=0;i<cmd_rec_len;i++)
  161.              temp_cmd[i] = cmd_rec[i];
  162.          temp_cmd[cmd_rec_len] = '\0';
  163.          strtrunc(temp_cmd);
  164.          add_command(temp_cmd);
  165.          rc = command_line(temp_cmd,COMMAND_ONLY_FALSE);
  166.          break;
  167.     case WINDOW_PREFIX:
  168.          Down_arrow((char *)"");
  169.          getyx(CURRENT_WINDOW,y,x);
  170.          wmove(CURRENT_WINDOW,y,0);
  171.          break;
  172.     case WINDOW_MAIN:
  173.                                        /* check for insert mode or not */
  174.          if (mode_insert)
  175.            {
  176.             post_process_line(CURRENT_VIEW->focus_line);
  177.             insert_new_line((char *)"",0,1,get_true_line(),FALSE,FALSE);
  178.            }
  179.          else
  180.            {
  181.             Down_arrow((char *)"");
  182.             getyx(CURRENT_WINDOW,y,x);
  183.             wmove(CURRENT_WINDOW,y,0);
  184.            }
  185.          break;
  186.    }
  187. #ifdef TRACE
  188.  trace_return();
  189. #endif
  190.  return(rc);
  191. }
  192. /*man-start*********************************************************************
  193. COMMAND
  194.      expand - expand tab characters to spaces
  195.  
  196. SYNTAX
  197.      EXPand [target]
  198.  
  199. DESCRIPTION
  200.      The EXPAND command converts all tab characters to spaces depending
  201.      on the size of a tab determined by [SET] TABS command.
  202.  
  203. COMPATIBILITY
  204.      XEDIT: Compatible.
  205.      KEDIT: Compatible.
  206.  
  207. STATUS
  208.      Complete.
  209. **man-end**********************************************************************/
  210. #ifdef PROTO
  211. int Expand(char *params)
  212. #else
  213. int Expand(params)
  214. char *params;
  215. #endif
  216. /***********************************************************************/
  217. {
  218. /*--------------------------- local data ------------------------------*/
  219. #define EXP_PARAMS  1
  220.  char *word[EXP_PARAMS+1];
  221.  char parm[EXP_PARAMS];
  222.  register int i;
  223.  unsigned short num_params;
  224.  long num_lines,true_line;
  225.  unsigned short x,y;
  226.  int direction;
  227.  LINE *curr;
  228. /*--------------------------- processing ------------------------------*/
  229. #ifdef TRACE
  230.  trace_function("comm3.c:   Expand");
  231. #endif
  232. /*---------------------------------------------------------------------*/
  233. /* Validate the parameters that have been supplied.                    */
  234. /* If no parameter is supplied, 1 is assumed.                          */
  235. /*---------------------------------------------------------------------*/
  236.  num_params = param_split(params,word,EXP_PARAMS,WORD_DELIMS,TEMP_PARAM);
  237.  if (num_params == 0)
  238.     {
  239.      num_params = 1;
  240.      word[0] = (char *)"1";
  241.     }
  242.     if (equal((char *)"all",word[0],3))
  243.        true_line = 1L;
  244.     else
  245.        true_line = get_true_line();
  246.  
  247.  if ((num_lines = valid_target(word[0],true_line)) == TARGET_ERROR)
  248.    {
  249.     display_error(4,(char *)word[0]);
  250. #ifdef TRACE
  251.     trace_return();
  252. #endif
  253.     return(RC_INVALID_OPERAND);
  254.    }
  255.  if (num_lines == TARGET_NOT_FOUND)
  256.    {
  257.     display_error(17,(char *)"");
  258. #ifdef TRACE
  259.     trace_return();
  260. #endif
  261.     return(RC_TARGET_NOT_FOUND);
  262.    }
  263. /*---------------------------------------------------------------------*/
  264. /* Determine in which direction we are working.                        */
  265. /*---------------------------------------------------------------------*/
  266.  if (num_lines < 0)
  267.    {
  268.     direction = DIRECTION_BACKWARD;
  269.     num_lines = num_lines * (-1L);
  270.    }
  271.  else
  272.    direction = DIRECTION_FORWARD;
  273. /*---------------------------------------------------------------------*/
  274. /* Check from which window the command was issued and make adjustments */
  275. /* as required.                                                        */
  276. /* Commands issued from the command window relate to the current line, */
  277. /* commands issued from either the prefix or main window relate to the */
  278. /* focus line.                                                         */
  279. /*---------------------------------------------------------------------*/
  280.  if (equal((char *)"all",word[0],3))
  281.     ;
  282.  else
  283.     if (CURRENT_VIEW->current_window == WINDOW_COMMAND
  284.     || in_profile)
  285.       {
  286.        if (TOF(true_line))
  287.          {
  288.           true_line++;
  289.           if (!valid_integer(word[0]))
  290.              num_lines--;
  291.          }
  292.        if (BOF(true_line))
  293.          {
  294.           true_line--;
  295.           if (!valid_integer(word[0]))
  296.              num_lines--;
  297.          }
  298.       }
  299.     else
  300.       {
  301.        if (TOF(true_line) || BOF(true_line))
  302.          {
  303.           display_error(38,(char *)"");
  304. #ifdef TRACE
  305.           trace_return();
  306. #endif
  307.           return(RC_INVALID_ENVIRON);
  308.          }
  309.        post_process_line(true_line);
  310.       }
  311. /*---------------------------------------------------------------------*/
  312. /* Find the current LINE pointer for the true_line.                    */
  313. /* This is the first line to change.                                   */
  314. /*---------------------------------------------------------------------*/
  315. #ifdef USE_VOID
  316.  curr = (LINE *)ll_find((void *)CURRENT_FILE->first_line,true_line);
  317. #else
  318.  curr = lll_find(CURRENT_FILE->first_line,true_line);
  319. #endif
  320. /*---------------------------------------------------------------------*/
  321. /* Convert all tabs in the current line to spaces.                     */
  322. /*---------------------------------------------------------------------*/
  323.  for (i=0;i<num_lines;i++)
  324.     {
  325.      add_to_recovery_list(curr->line,curr->length);
  326.      tabs_convert(curr,TRUE);
  327.      if (direction == DIRECTION_FORWARD)
  328.         curr = curr->next;
  329.      else
  330.         curr = curr->prev;
  331.     }
  332. /*---------------------------------------------------------------------*/
  333. /* If we are in the profile, then don't do any more processing.        */
  334. /*---------------------------------------------------------------------*/
  335.  if (in_profile)
  336.    {
  337.     pre_process_line(CURRENT_VIEW->focus_line);
  338. #ifdef TRACE
  339.     trace_return();
  340. #endif
  341.     if (CURRENT_TOF || CURRENT_BOF)
  342.        return(RC_TOF_EOF_REACHED);
  343.     else
  344.        return(RC_OK);
  345.    }
  346.  pre_process_line(CURRENT_VIEW->focus_line);
  347.  show_page();
  348.  if (CURRENT_VIEW->current_window != WINDOW_COMMAND)
  349.    {
  350.     getyx(CURRENT_WINDOW,y,x);
  351.     y = get_row_for_focus_line(CURRENT_VIEW->current_row,
  352.                                CURRENT_VIEW->focus_line,
  353.                                CURRENT_VIEW->current_line);
  354.     wmove(CURRENT_WINDOW,y,x);
  355.    }
  356.  
  357. #ifdef TRACE
  358.  trace_return();
  359. #endif
  360.  if (CURRENT_TOF || CURRENT_BOF)
  361.     return(RC_TOF_EOF_REACHED);
  362.  else
  363.     return(RC_OK);
  364. }
  365. /*man-start*********************************************************************
  366. COMMAND
  367.      extract - obtain setting information from THE
  368.  
  369. SYNTAX
  370.      EXTract /item/[...]
  371.  
  372. DESCRIPTION
  373.      The EXTRACT command is used to relay information about settings
  374.      within the from within a REXX macro. EXTRACT is only valid within
  375.      a REXX macro.
  376.  
  377. COMPATIBILITY
  378.      XEDIT: Only allows '/' as delimiter.
  379.      KEDIT: Only allows '/' as delimiter.
  380.  
  381. STATUS
  382.      Complete.
  383. **man-end**********************************************************************/
  384. #ifdef PROTO
  385. int Extract(char *params)
  386. #else
  387. int Extract(params)
  388. char *params;
  389. #endif
  390. /***********************************************************************/
  391. {
  392. /*--------------------------- extern data -----------------------------*/
  393. /*--------------------------- local data ------------------------------*/
  394.  register int i;
  395.  int rc,itemno,num_items=0,len;
  396.  char *orig_params;
  397.  int pos;
  398.  char *args;
  399.  bool invalid_item = FALSE;
  400. /*--------------------------- processing ------------------------------*/
  401. #ifdef TRACE
  402.  trace_function("comm1.c:   Extract");
  403. #endif
  404.  if (!in_macro)
  405.    {
  406.     display_error(53,(char *)"");
  407. #ifdef TRACE
  408.     trace_return();
  409. #endif
  410.     return(RC_INVALID_ENVIRON);
  411.    }
  412. #if !defined(NOREXX)
  413. /*---------------------------------------------------------------------*/
  414. /* Check that the first character of parameters is /.                  */
  415. /*---------------------------------------------------------------------*/
  416.  if (*(params) != '/')
  417.    {
  418.     display_error(1,params);
  419. #ifdef TRACE
  420.     trace_return();
  421. #endif
  422.     return(RC_INVALID_OPERAND);
  423.    }
  424.  params++;                               /* throw away first delimiter */
  425.  orig_params = params;
  426.  len = strlen(params);
  427. /*---------------------------------------------------------------------*/
  428. /* Check that we have an item to extract...                            */
  429. /*---------------------------------------------------------------------*/
  430.  if (len == 0)
  431.     invalid_item = TRUE;
  432.  else
  433.     if (len == 1 && (*(params) == '/'))
  434.        invalid_item = TRUE;
  435.  if (invalid_item)
  436.    {
  437.     display_error(1,params);
  438. #ifdef TRACE
  439.     trace_return();
  440. #endif
  441.     return(RC_INVALID_OPERAND);
  442.    }
  443. /*---------------------------------------------------------------------*/
  444. /* Allow for no trailing '/'...                                        */
  445. /*---------------------------------------------------------------------*/
  446.  if ((*(params+len-1) == '/'))
  447.     num_items = 0;
  448.  else
  449.     num_items = 1;
  450. /*---------------------------------------------------------------------*/
  451. /* Replace all \ with nul character to give us seperate strings.       */
  452. /*---------------------------------------------------------------------*/
  453.  for (i=0;i<len;i++)
  454.    {
  455.     if (*(params+i) == '/')
  456.       {
  457.        *(params+i) = '\0';
  458.        num_items++;
  459.       }
  460.    }
  461. /*---------------------------------------------------------------------*/
  462. /* For each item, extract its variables...                             */
  463. /*---------------------------------------------------------------------*/
  464.  for (i=0;i<num_items;i++)
  465.    {
  466. /*---------------------------------------------------------------------*/
  467. /* First check if the item has any arguments with it.                  */
  468. /*---------------------------------------------------------------------*/
  469.     pos = strzeq(params,' ');
  470.     if (pos == (-1))
  471.        args = "";
  472.     else
  473.       {
  474.        *(params+pos) = '\0';
  475.        args = strtrunc(params+pos+1);
  476.       }
  477. /*---------------------------------------------------------------------*/
  478. /* Find the item in the list of valid extract options...               */
  479. /*---------------------------------------------------------------------*/
  480.     if ((itemno = find_item(params,QUERY_EXTRACT)) == (-1))
  481.        {
  482.         display_error(1,params);
  483. #ifdef TRACE
  484.         trace_return();
  485. #endif
  486.         return(RC_INVALID_OPERAND);
  487.        }
  488. /*---------------------------------------------------------------------*/
  489. /* Get the current settings for the valid item...                      */
  490. /*---------------------------------------------------------------------*/
  491.     itemno = get_item_values(itemno,args,QUERY_EXTRACT,0L,NULL,0L);
  492. /*---------------------------------------------------------------------*/
  493. /* If the arguments to the item are invalid, return with an error.     */
  494. /*---------------------------------------------------------------------*/
  495.     if (itemno == EXTRACT_ARG_ERROR)
  496.        {
  497. #ifdef TRACE
  498.         trace_return();
  499. #endif
  500.         return(RC_INVALID_OPERAND);
  501.        }
  502. /*---------------------------------------------------------------------*/
  503. /* If the REXX variables have already been set, don't try to set them. */
  504. /*---------------------------------------------------------------------*/
  505.     if (itemno != EXTRACT_VARIABLES_SET)
  506.       {
  507.        rc = set_extract_variables(params);
  508.        if (rc == RC_SYSTEM_ERROR)
  509.           break;
  510.       }
  511.     params += strlen(params)+1;
  512.    }
  513. #endif
  514.  
  515. #ifdef TRACE
  516.  trace_return();
  517. #endif
  518.  return(rc);
  519. }
  520. /*man-start*********************************************************************
  521. COMMAND
  522.      ffile - force file the current file to disk
  523.  
  524. SYNTAX
  525.      FFile  [filename]
  526.  
  527. DESCRIPTION
  528.      The FFILE command writes the current file to disk to the current
  529.      file name or to the supplied filename.
  530.      Unlike the FILE command, if the optional filename exists, this
  531.      command will overwrite the file.
  532.  
  533. COMPATIBILITY
  534.      XEDIT: N/A
  535.      KEDIT: Compatible.
  536.  
  537. DEFAULT
  538.      With no parameters, the current file is written.
  539.  
  540. SEE ALSO
  541.      file,save,ssave
  542.  
  543. STATUS
  544.      Complete
  545. **man-end**********************************************************************/
  546. #ifdef PROTO
  547. int Ffile(char *params)
  548. #else
  549. int Ffile(params)
  550. char *params;
  551. #endif
  552. /***********************************************************************/
  553. {
  554. /*--------------------------- local data ------------------------------*/
  555.  int rc=RC_OK;
  556. /*--------------------------- processing ------------------------------*/
  557. #ifdef TRACE
  558.  trace_function("comm2.c:   Ffile");
  559. #endif
  560.  post_process_line(CURRENT_VIEW->focus_line);
  561.  if ((rc = save_file(CURRENT_FILE,params,YES,0L,0L,NO,0,max_line_length)) != RC_OK)
  562.    {
  563. #ifdef TRACE
  564.     trace_return();
  565. #endif
  566.     return(rc);
  567.    }
  568. /*---------------------------------------------------------------------*/
  569. /* If autosave is on at the time of FFiling, remove the .aus file...   */
  570. /*---------------------------------------------------------------------*/
  571.  if (CURRENT_FILE->autosave > 0)
  572.     rc = remove_aus_file(CURRENT_FILE);
  573.  free_view_memory();
  574. #ifdef TRACE
  575.  trace_return();
  576. #endif
  577.  return(rc);
  578. }
  579. /*man-start*********************************************************************
  580. COMMAND
  581.      file - file the current file to disk
  582.  
  583. SYNTAX
  584.      FILE  [filename]
  585.  
  586. DESCRIPTION
  587.      The FILE command writes the current file to disk to the current
  588.      file name or to the supplied filename.
  589.      Unlike the FFILE command, if the optional filename exists, this
  590.      command will not overwrite the file.
  591.  
  592. COMPATIBILITY
  593.      XEDIT: Compatible.
  594.      KEDIT: Compatible.
  595.  
  596. DEFAULT
  597.      With no parameters, the current file is written.
  598.  
  599. SEE ALSO
  600.      ffile,save,ssave
  601.  
  602. STATUS
  603.      Complete
  604. **man-end**********************************************************************/
  605. #ifdef PROTO
  606. int File(char *params)
  607. #else
  608. int File(params)
  609. char *params;
  610. #endif
  611. /***********************************************************************/
  612. {
  613. /*--------------------------- local data ------------------------------*/
  614.  int rc=RC_OK;
  615. /*--------------------------- processing ------------------------------*/
  616. #ifdef TRACE
  617.  trace_function("comm2.c:   File");
  618. #endif
  619.  post_process_line(CURRENT_VIEW->focus_line);
  620. /*---------------------------------------------------------------------*/
  621. /* If we are filing the current file with the same name AND the number */
  622. /* of alterations is zero, then quit the file.                         */
  623. /*---------------------------------------------------------------------*/
  624.  if (CURRENT_FILE->save_alt == 0 && strcmp(params,"") == 0)
  625.     Quit("");
  626.  else
  627.    {
  628.     if ((rc = save_file(CURRENT_FILE,params,NO,0L,0L,NO,0,max_line_length)) != RC_OK)
  629.       {
  630. #ifdef TRACE
  631.        trace_return();
  632. #endif
  633.        return(rc);
  634.       }
  635. /*---------------------------------------------------------------------*/
  636. /* If autosave is on at the time of Filing, remove the .aus file...    */
  637. /*---------------------------------------------------------------------*/
  638.     if (CURRENT_FILE->autosave > 0)
  639.        rc = remove_aus_file(CURRENT_FILE);
  640.     free_view_memory();
  641.    }
  642. #ifdef TRACE
  643.  trace_return();
  644. #endif
  645.  return(rc);
  646. }
  647. /*man-start*********************************************************************
  648. COMMAND
  649.      fillbox - fill the marked box block with a character
  650.  
  651. SYNTAX
  652.      FILLbox [c]
  653.  
  654. DESCRIPTION
  655.      The FILLBOX command fills the marked block with the specified
  656.      character. If no parameters are supplied and the command is run
  657.      from the command line, then the box will be filled with spaces.
  658.      If the command is not run from the command line, the user is
  659.      prompted for a character to fill the box.
  660.  
  661. COMPATIBILITY
  662.      XEDIT: N/A
  663.      KEDIT: Compatible.
  664.  
  665. STATUS
  666.      Complete
  667. **man-end**********************************************************************/
  668. #ifdef PROTO
  669. int Fillbox(char *params)
  670. #else
  671. int Fillbox(params)
  672. char *params;
  673. #endif
  674. /***********************************************************************/
  675. {
  676. /*--------------------------- local data ------------------------------*/
  677.  char chr;
  678.  int len_params;
  679. /*--------------------------- processing ------------------------------*/
  680. #ifdef TRACE
  681.  trace_function("comm2.c:   Fillbox");
  682. #endif
  683.  post_process_line(CURRENT_VIEW->focus_line);
  684. /*---------------------------------------------------------------------*/
  685. /* Validate the marked block.                  .                       */
  686. /*---------------------------------------------------------------------*/
  687.  if (marked_block(TRUE) != RC_OK)
  688.    {
  689. #ifdef TRACE
  690.     trace_return();
  691. #endif
  692.     return(RC_INVALID_ENVIRON);
  693.    }
  694. /*---------------------------------------------------------------------*/
  695. /* This function not valid for line blocks.                            */
  696. /*---------------------------------------------------------------------*/
  697.  if (MARK_VIEW->mark_type == M_LINE)
  698.    {
  699.     display_error(47,(char *)"");
  700. #ifdef TRACE
  701.     trace_return();
  702. #endif
  703.     return(RC_INVALID_ENVIRON);
  704.    }
  705. /*---------------------------------------------------------------------*/
  706. /* Check if hex on in effect and translate hex char if required...     */
  707. /*---------------------------------------------------------------------*/
  708.  if (CURRENT_VIEW->hex == ON)
  709.    {
  710.     if ((len_params = convert_hex_strings(params)) == (-1))
  711.       {
  712.        display_error(32,(char *)"");
  713. #ifdef TRACE
  714.        trace_return();
  715. #endif
  716.        return(RC_INVALID_OPERAND);
  717.       }
  718.    }
  719.  else
  720.    len_params = strlen(params);
  721. /*---------------------------------------------------------------------*/
  722. /* Whew, now do something...                                           */
  723. /*---------------------------------------------------------------------*/
  724.  if (len_params > 1)
  725.    {
  726.     display_error(1,params);
  727. #ifdef TRACE
  728.     trace_return();
  729. #endif
  730.     return(RC_INVALID_OPERAND);
  731.    }
  732.  if (len_params == 0)
  733.     chr = ' ';
  734.  else
  735.     chr = *(params);
  736.  if (CURRENT_VIEW->current_window != WINDOW_COMMAND
  737.  && len_params != 1) 
  738.    {
  739.     display_error(0,(char *)"Enter fill character...");
  740.     touchwin(error_window);
  741.     doupdate();
  742.     chr = (char)my_getch(CURRENT_WINDOW);
  743.     error_on_screen = FALSE;
  744.     touchwin(foot);
  745.    }
  746.  box_operations(BOX_F,SOURCE_BLOCK,TRUE,chr);
  747. #ifdef TRACE
  748.  trace_return();
  749. #endif
  750.  return(RC_OK);
  751. }
  752. /*man-start*********************************************************************
  753. COMMAND
  754.      forward - scroll forwards a number of screens
  755.  
  756. SYNTAX
  757.      FOrward [n]
  758.  
  759. DESCRIPTION
  760.      The FORWARD command scrolls the file contents forwards the number
  761.      of screens specified.
  762.  
  763. COMPATIBILITY
  764.      XEDIT: Compatible.
  765.      KEDIT: Does not support HALF or Lines options.
  766.  
  767. DEFAULT
  768.      With no parameters, 1 screen is scrolled.
  769.  
  770. SEE ALSO
  771.      backward,top
  772.  
  773. STATUS
  774.      Complete
  775. **man-end**********************************************************************/
  776. #ifdef PROTO
  777. int Forward(char *params)
  778. #else
  779. int Forward(params)
  780. char *params;
  781. #endif
  782. /***********************************************************************/
  783. {
  784. /*--------------------------- local data ------------------------------*/
  785. #define FOR_PARAMS  1
  786.  char *word[FOR_PARAMS+1];
  787.  char parm[FOR_PARAMS];
  788.  register int i;
  789.  unsigned short num_params;
  790.  long num_pages;
  791.  unsigned short x,y;
  792. /*--------------------------- processing ------------------------------*/
  793. #ifdef TRACE
  794.  trace_function("comm2.c:   Forward");
  795. #endif
  796.  num_params = param_split(params,word,FOR_PARAMS,WORD_DELIMS,TEMP_PARAM);
  797.  if (num_params == 0)
  798.    {
  799.     num_params = 1;
  800.     word[0] = (char *)"1";
  801.    }
  802.  if (num_params != 1)
  803.    {
  804.     display_error(1,word[1]);
  805. #ifdef TRACE
  806.     trace_return();
  807. #endif
  808.     return(RC_INVALID_OPERAND);
  809.    }
  810.  if (strcmp(word[0],"*") == 0)
  811.    {
  812.     CURRENT_VIEW->current_line = CURRENT_FILE->number_lines+1;
  813.     post_process_line(CURRENT_VIEW->focus_line);
  814.     CURRENT_VIEW->focus_line = CURRENT_FILE->number_lines+1;
  815.     pre_process_line(CURRENT_VIEW->focus_line);
  816.     if (!in_profile)
  817.       {
  818.        if (CURRENT_VIEW->current_window == WINDOW_COMMAND)
  819.           getyx(PREVIOUS_WINDOW,y,x);
  820.        else
  821.           getyx(CURRENT_WINDOW,y,x);
  822.        show_page();
  823.        y = get_row_for_focus_line(CURRENT_VIEW->current_row,
  824.                                CURRENT_VIEW->focus_line,
  825.                                CURRENT_VIEW->current_line);
  826.        if (CURRENT_VIEW->current_window == WINDOW_COMMAND)
  827.           wmove(PREVIOUS_WINDOW,y,x);
  828.        else
  829.           wmove(CURRENT_WINDOW,y,x);
  830.       }
  831. #ifdef TRACE
  832.     trace_return();
  833. #endif
  834.     if (CURRENT_TOF || CURRENT_BOF)
  835.        return(RC_TOF_EOF_REACHED);
  836.     else
  837.        return(RC_OK);
  838.    }
  839.  if ((num_pages = atol(word[0])) == 0L)
  840.    {
  841.     display_error(4,word[0]);
  842. #ifdef TRACE
  843.     trace_return();
  844. #endif
  845.     return(RC_INVALID_OPERAND);
  846.    }
  847.  
  848.  CURRENT_VIEW->current_line =
  849.     min(CURRENT_VIEW->current_line + (CURRENT_SCREEN.rows-1)*num_pages,
  850.         CURRENT_FILE->number_lines+1);
  851.  
  852.  post_process_line(CURRENT_VIEW->focus_line);
  853.  CURRENT_VIEW->focus_line = calculate_focus_line(CURRENT_VIEW->current_row,
  854.                                                 CURRENT_VIEW->focus_line,
  855.                                                 CURRENT_VIEW->current_line);
  856.  pre_process_line(CURRENT_VIEW->focus_line);
  857.  if (in_profile)
  858.    {
  859. #ifdef TRACE
  860.     trace_return();
  861. #endif
  862.     if (CURRENT_TOF || CURRENT_BOF)
  863.        return(RC_TOF_EOF_REACHED);
  864.     else
  865.        return(RC_OK);
  866.    }
  867.  getyx(CURRENT_WINDOW,y,x);
  868.  show_page();
  869.  if (CURRENT_VIEW->current_window != WINDOW_COMMAND)
  870.    {
  871.     y = get_row_for_focus_line(CURRENT_VIEW->current_row,
  872.                                CURRENT_VIEW->focus_line,
  873.                                CURRENT_VIEW->current_line);
  874.     wmove(CURRENT_WINDOW,y,x);
  875.    }
  876.  
  877. #ifdef TRACE
  878.  trace_return();
  879. #endif
  880.  if (CURRENT_TOF || CURRENT_BOF)
  881.     return(RC_TOF_EOF_REACHED);
  882.  else
  883.     return(RC_OK);
  884. }
  885. /*man-start*********************************************************************
  886. COMMAND
  887.      get - read another file into current file
  888.  
  889. SYNTAX
  890.      GET [fileid]
  891.  
  892. DESCRIPTION
  893.      The GET command reads a file into the current file, inserting
  894.      lines after the current line.
  895.      When no fileid is supplied the temporary file is used.
  896.  
  897. COMPATIBILITY
  898.      XEDIT: Does not support optional firstrec - numrecs
  899.      KEDIT: Does not support optional fromlines - forlines.
  900.  
  901. SEE ALSO
  902.      put,putd
  903.  
  904. STATUS
  905.      Complete
  906. **man-end**********************************************************************/
  907. #ifdef PROTO
  908. int Get(char *params)
  909. #else
  910. int Get(params)
  911. char *params;
  912. #endif
  913. /***********************************************************************/
  914. {
  915. /*--------------------------- local data ------------------------------*/
  916.  char *filename;
  917.  FILE *fp;
  918.  LINE *curr;
  919.  long old_number_lines,true_line;
  920.  int rc;
  921. /*--------------------------- processing ------------------------------*/
  922. #ifdef TRACE
  923.  trace_function("comm2.c:   Get");
  924. #endif
  925.  if (strcmp(params,"") == 0)   /* no fileid supplied */
  926.     filename = tempfilename;
  927.  else
  928.    {
  929.     if ((rc = splitpath(strtrans(params,OSLASH,ISLASH))) != RC_OK)
  930.       {
  931.        display_error(10,params);
  932. #ifdef TRACE
  933.        trace_return();
  934. #endif
  935.        return(rc);
  936.       }
  937.     strcpy(temp_cmd,sp_path);
  938.     strcat(temp_cmd,sp_fname);
  939.     filename = temp_cmd;
  940.    }
  941.  
  942.  post_process_line(CURRENT_VIEW->focus_line);
  943.  
  944.  if ((fp = fopen(filename,"r")) == NULL)
  945.    {
  946.     display_error(9,params);
  947. #ifdef TRACE
  948.     trace_return();
  949. #endif
  950.     return(RC_ACCESS_DENIED);
  951.    }
  952.  true_line = get_true_line();
  953. #ifdef USE_VOID
  954.  curr = (LINE *)ll_find((void *)CURRENT_FILE->first_line,true_line);
  955. #else
  956.  curr = lll_find(CURRENT_FILE->first_line,true_line);
  957. #endif
  958.  if (curr->next == NULL)   /* on bottom of file */
  959.     curr = curr->prev;
  960.  old_number_lines = CURRENT_FILE->number_lines;
  961.  if ((curr = read_file(fp,curr,filename)) == NULL)
  962.    {
  963. #ifdef TRACE
  964.     trace_return();
  965. #endif
  966.     return(RC_ACCESS_DENIED);
  967.    }
  968.  
  969.  fclose(fp);
  970.  pre_process_line(CURRENT_VIEW->focus_line);
  971. /*---------------------------------------------------------------------*/
  972. /* Fix the positioning of the marked block (if there is one and it is  */
  973. /* in the current view).                                               */
  974. /*---------------------------------------------------------------------*/
  975.  if (!in_profile)
  976.    {
  977.     adjust_marked_lines(TRUE,true_line,CURRENT_FILE->number_lines - old_number_lines);
  978.     adjust_pending_prefix(CURRENT_VIEW,TRUE,true_line,CURRENT_FILE->number_lines - old_number_lines);
  979.    }
  980. /*---------------------------------------------------------------------*/
  981. /* Increment the number of lines counter for the current file and the  */
  982. /* number of alterations.                                              */
  983. /*---------------------------------------------------------------------*/
  984.  if ((rc = increment_alt(CURRENT_FILE)) != RC_OK)
  985.    {
  986. #ifdef TRACE
  987.     trace_return();
  988. #endif
  989.     return(rc);
  990.    }
  991.  if (!in_profile)
  992.     show_page();
  993. #ifdef TRACE
  994.  trace_return();
  995. #endif
  996.  return(RC_OK);
  997. }
  998. /*man-start*********************************************************************
  999. COMMAND
  1000.      help - display help for the editor
  1001.  
  1002. SYNTAX
  1003.      HELP
  1004.  
  1005. DESCRIPTION
  1006.      The HELP command displays help for the editor.
  1007.      Uses THE_HELP environment variable to point to the help file.
  1008.  
  1009. COMPATIBILITY
  1010.      XEDIT: Similar in concept.
  1011.      KEDIT: Similar in concept.
  1012.  
  1013. STATUS
  1014.      Complete.
  1015. **man-end**********************************************************************/
  1016. #ifdef PROTO
  1017. int Help(char *params)
  1018. #else
  1019. int Help(params)
  1020. char *params;
  1021. #endif
  1022. /***********************************************************************/
  1023. {
  1024. /*------------------------- external data -----------------------------*/
  1025. extern char the_help_file[MAX_FILE_NAME+1];
  1026. /*--------------------------- local data ------------------------------*/
  1027. /*--------------------------- processing ------------------------------*/
  1028. #ifdef TRACE
  1029.  trace_function("comm2.c:   Help");
  1030. #endif
  1031.  if (!file_exists(the_help_file))
  1032.    {
  1033.     display_error(23,(char *)the_help_file);
  1034. #ifdef TRACE
  1035.     trace_return();
  1036. #endif
  1037.     return(RC_FILE_NOT_FOUND);
  1038.    }
  1039.  Xedit(the_help_file);
  1040. #ifdef TRACE
  1041.  trace_return();
  1042. #endif
  1043.  return(RC_OK);
  1044. }
  1045. /*man-start*********************************************************************
  1046. COMMAND
  1047.      input - insert the command line contents into the file
  1048.  
  1049. SYNTAX
  1050.      Input [line contents]
  1051.  
  1052. DESCRIPTION
  1053.      The INPUT command inserts the remainder of the command line into the
  1054.      file after the current line.
  1055.  
  1056. COMPATIBILITY
  1057.      XEDIT: Does not provide full input mode option.
  1058.      KEDIT: Does not provide full input mode option.
  1059.  
  1060. STATUS
  1061.      Complete.
  1062. **man-end**********************************************************************/
  1063. #ifdef PROTO
  1064. int Input(char *params)
  1065. #else
  1066. int Input(params)
  1067. char *params;
  1068. #endif
  1069. /***********************************************************************/
  1070. {
  1071. /*--------------------------- local data ------------------------------*/
  1072.  LINE *curr;
  1073.  unsigned long li;
  1074.  int len_params;
  1075. /*--------------------------- processing ------------------------------*/
  1076. #ifdef TRACE
  1077.  trace_function("comm2.c:   Input");
  1078. #endif
  1079.  post_process_line(CURRENT_VIEW->focus_line);
  1080.  if (CURRENT_VIEW->hex == ON)
  1081.    {
  1082.     if ((len_params = convert_hex_strings(params)) == (-1))
  1083.       {
  1084.        display_error(32,(char *)"");
  1085. #ifdef TRACE
  1086.        trace_return();
  1087. #endif
  1088.        return(RC_INVALID_OPERAND);
  1089.       }
  1090.    }
  1091.  else
  1092.    len_params = strlen(params);
  1093.  insert_new_line(params,len_params,1L,get_true_line(),TRUE,TRUE);
  1094. #ifdef TRACE
  1095.  trace_return();
  1096. #endif
  1097.  return(RC_OK);
  1098. }
  1099. /*man-start*********************************************************************
  1100. COMMAND
  1101.      join - join a line with the line following
  1102.  
  1103. SYNTAX
  1104.      Join [ALigned]
  1105.  
  1106. DESCRIPTION
  1107.      The JOIN command makes one line out of the focus line and the
  1108.      line following.
  1109.      If aligned is specified, any leading spaces in the following line
  1110.      are ignored. If aligned is not specified, all characters, including
  1111.      spaces are added.
  1112.  
  1113. COMPATIBILITY
  1114.      XEDIT: Compatible.
  1115.      KEDIT: Compatible.
  1116.  
  1117. STATUS
  1118.      Complete.
  1119. **man-end**********************************************************************/
  1120. #ifdef PROTO
  1121. int Join(char *params)
  1122. #else
  1123. int Join(params)
  1124. char *params;
  1125. #endif
  1126. /***********************************************************************/
  1127. {
  1128. /*--------------------------- local data ------------------------------*/
  1129.  int rc;
  1130.  bool aligned;
  1131. /*--------------------------- processing ------------------------------*/
  1132. #ifdef TRACE
  1133.  trace_function("comm2.c:   Join");
  1134. #endif
  1135. /*---------------------------------------------------------------------*/
  1136. /* Check here for parameter value of 'Aligned'.                        */
  1137. /*---------------------------------------------------------------------*/
  1138.  if (equal((char *)"aligned",params,2))
  1139.     aligned = ALIGNED_TRUE;
  1140.  else
  1141.     if (strcmp(params,"") == 0)
  1142.        aligned = ALIGNED_FALSE;
  1143.     else
  1144.       {
  1145.        display_error(1,(char *)params);
  1146. #ifdef TRACE
  1147.        trace_return();
  1148. #endif
  1149.        return(RC_INVALID_ENVIRON);
  1150.       }
  1151.  rc = execute_split_join(SPLIT_FALSE,aligned);
  1152. #ifdef TRACE
  1153.  trace_return();
  1154. #endif
  1155.  return(rc);
  1156. }
  1157.