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

  1. /***********************************************************************/
  2. /* COMM5.C - Commands T-Z                                              */
  3. /* This file contains all commands that can be assigned to function    */
  4. /* keys or typed on the command line.                                  */
  5. /***********************************************************************/
  6. /*
  7.  * THE - The Hessling Editor. A text editor similar to VM/CMS xedit.
  8.  * Copyright (C) 1991-1997 Mark Hessling
  9.  *
  10.  * This program is free software; you can redistribute it and/or
  11.  * modify it under the terms of the GNU General Public License as
  12.  * published by the Free Software Foundation; either version 2 of
  13.  * the License, or any later version.
  14.  *
  15.  * This program is distributed in the hope that it will be useful,
  16.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18.  * General Public License for more details.
  19.  *
  20.  * You should have received a copy of the GNU General Public License
  21.  * along with this program; if not, write to:
  22.  *
  23.  *    The Free Software Foundation, Inc.
  24.  *    675 Mass Ave,
  25.  *    Cambridge, MA 02139 USA.
  26.  *
  27.  *
  28.  * If you make modifications to this software that you feel increases
  29.  * it usefulness for the rest of the community, please email the
  30.  * changes, enhancements, bug fixes as well as any and all ideas to me.
  31.  * This software is going to be maintained and enhanced as deemed
  32.  * necessary by the community.
  33.  *
  34.  * Mark Hessling                 Email:             M.Hessling@qut.edu.au
  35.  * PO Box 203                    Phone:                    +617 3802 0800
  36.  * Bellara                       http://www.gu.edu.au/gext/the/markh.html
  37.  * QLD 4507                      **** Maintainer PDCurses & REXX/SQL ****
  38.  * Australia                     ************* Author of THE ************
  39.  */
  40.  
  41. /*
  42. $Id: comm5.c 2.1 1995/06/24 16:28:59 MH Rel MH $
  43. */
  44.  
  45. #include <the.h>
  46. #include <proto.h>
  47.  
  48. /*#define DEBUG 1*/
  49. /*man-start*********************************************************************
  50. COMMAND
  51.      tabpre - switch between FILEAREA and PREFIX area
  52.  
  53. SYNTAX
  54.      tabpre
  55.  
  56. DESCRIPTION
  57.      The TABPRE command switches the focus of the editor from the
  58.      <filearea> to the <prefix area> and vice versa, depending
  59.      on which window is currently active.
  60.  
  61.      This command can only be used by assigning it to a function key.
  62.  
  63.      This command will be removed in a future version.
  64.  
  65. COMPATIBILITY
  66.      XEDIT: N/A
  67.      KEDIT: Equivalent of <SOS LEFTEDGE> and <SOS PREFIX>
  68.  
  69. SEE ALSO
  70.      <SOS LEFTEDGE>, <SOS PREFIX>
  71.  
  72. STATUS
  73.      Complete.
  74. **man-end**********************************************************************/
  75. #ifdef HAVE_PROTO
  76. short Tabpre(CHARTYPE *params)
  77. #else
  78. short Tabpre(params)
  79. CHARTYPE *params;
  80. #endif
  81. /***********************************************************************/
  82. {
  83. /*-------------------------- external data ----------------------------*/
  84. /*--------------------------- local data ------------------------------*/
  85.  short rc=RC_OK;
  86. /*--------------------------- processing ------------------------------*/
  87. #ifdef TRACE
  88.  trace_function("comm5.c:   Tabpre");
  89. #endif
  90. /*---------------------------------------------------------------------*/
  91. /* No arguments are allowed; error if any are present.                 */
  92. /*---------------------------------------------------------------------*/
  93.  if (strcmp((DEFCHAR *)params,"") != 0)
  94.    {
  95.     display_error(1,(CHARTYPE *)params,FALSE);
  96. #ifdef TRACE
  97.     trace_return();
  98. #endif
  99.     return(RC_INVALID_OPERAND);
  100.    }
  101. /*---------------------------------------------------------------------*/
  102. /* If the cursor is in the command line or there is no prefix on, exit.*/
  103. /*---------------------------------------------------------------------*/
  104.  if (CURRENT_VIEW->current_window == WINDOW_COMMAND
  105.  ||  !CURRENT_VIEW->prefix)
  106.    {
  107. #ifdef TRACE
  108.     trace_return();
  109. #endif
  110.     return(RC_OK);
  111.    }
  112.  if (CURRENT_VIEW->current_window == WINDOW_FILEAREA)
  113.     rc = Sos_prefix((CHARTYPE *)"");
  114.  else
  115.     rc = Sos_leftedge((CHARTYPE *)"");
  116. #ifdef TRACE
  117.  trace_return();
  118. #endif
  119.  return(rc);
  120. }
  121. /*man-start*********************************************************************
  122. COMMAND
  123.      text - simulate keyboard entry of characters
  124.  
  125. SYNTAX
  126.      TEXT text
  127.  
  128. DESCRIPTION
  129.      The TEXT command simulates the entry of 'text' from the
  130.      keyboard. This command is actually called when you enter text
  131.      from the keyboard.
  132.  
  133. COMPATIBILITY
  134.      XEDIT: N/A
  135.      KEDIT: Compatible.
  136.             Does not allow trailing spaces in text.
  137.  
  138. STATUS
  139.      Complete.
  140. **man-end**********************************************************************/
  141. #ifdef HAVE_PROTO
  142. short Text(CHARTYPE *params)
  143. #else
  144. short Text(params)
  145. CHARTYPE *params;
  146. #endif
  147. /***********************************************************************/
  148. {
  149. /*------------------------- external data -----------------------------*/
  150.  extern CHARTYPE *rec;
  151.  extern LENGTHTYPE rec_len;
  152.  extern CHARTYPE *cmd_rec;
  153.  extern unsigned short cmd_rec_len;
  154.  extern bool INSERTMODEx;
  155.  extern bool prefix_changed;
  156.  extern CHARTYPE *pre_rec;
  157.  extern unsigned short pre_rec_len;
  158.  extern bool readonly;
  159.  extern VIEW_DETAILS *vd_mark;
  160.  extern bool in_macro;
  161.  extern bool clear_command;
  162. /*--------------------------- local data ------------------------------*/
  163.  register short i=0;
  164.  CHARTYPE real_key=0;
  165.  chtype chtype_key=0;
  166.  LENGTHTYPE x=0;
  167.  unsigned short y=0;
  168.  short len_params=0;
  169.  short rc=RC_OK;
  170.  LENGTHTYPE offl=0,offr=0;
  171. #if defined(USE_EXTCURSES)
  172.  ATTR attr=0;
  173. #else
  174.  chtype attr=0;
  175. #endif
  176.  bool need_to_build_screen=FALSE;
  177.  bool save_in_macro=in_macro;
  178. /*--------------------------- processing ------------------------------*/
  179. #ifdef TRACE
  180.  trace_function("comm5.c:   Text");
  181. #endif
  182. /*---------------------------------------------------------------------*/
  183. /* If running in read-only mode, do not allow any text to be entered   */
  184. /* in the main window.                                                 */
  185. /*---------------------------------------------------------------------*/
  186.  if (readonly && CURRENT_VIEW->current_window == WINDOW_FILEAREA)
  187.    {
  188.     display_error(56,(CHARTYPE *)"",FALSE);
  189. #ifdef TRACE
  190.     trace_return();
  191. #endif
  192.     return(RC_INVALID_ENVIRON);
  193.    }
  194. /*---------------------------------------------------------------------*/
  195. /* If HEX mode is on, convert the hex string...                        */
  196. /*---------------------------------------------------------------------*/
  197.  if (CURRENT_VIEW->hex)
  198.    {
  199.     if ((len_params = convert_hex_strings(params)) == (-1))
  200.       {
  201.        display_error(32,params,FALSE);
  202. #ifdef TRACE
  203.        trace_return();
  204. #endif
  205.        return(RC_INVALID_OPERAND);
  206.       }
  207.    }
  208.  else
  209.    len_params = strlen((DEFCHAR *)params);
  210.  for (i=0;i<len_params;i++)
  211.    {
  212.     real_key = case_translate((CHARTYPE)*(params+i));
  213.     chtype_key = (chtype)(real_key & A_CHARTEXT);
  214.     getyx(CURRENT_WINDOW,y,x);
  215. #if defined(USE_EXTCURSES)
  216.     attr = CURRENT_WINDOW->_a[y][x];
  217.     wattrset(CURRENT_WINDOW,attr);
  218.     attr = 0;
  219. #else
  220.     attr = winch(CURRENT_WINDOW) & A_ATTRIBUTES;
  221. #endif
  222.     switch(CURRENT_VIEW->current_window)
  223.       {
  224.        case WINDOW_FILEAREA:
  225.             if (CURRENT_SCREEN.sl[y].line_type != LINE_LINE)
  226.                break;
  227.             if ((LENGTHTYPE)(x+CURRENT_VIEW->verify_start) > (LENGTHTYPE)(CURRENT_VIEW->verify_end))
  228.                break;
  229.             if (INSERTMODEx)
  230.               {
  231.                rec = meminschr(rec,real_key,CURRENT_VIEW->verify_col-1+x,
  232.                                max_line_length,rec_len);
  233.                put_char(CURRENT_WINDOW,chtype_key|attr,INSCHAR);
  234.               }
  235.             else
  236.               {
  237.                rec[CURRENT_VIEW->verify_col-1+x] = real_key;
  238.                if (x == CURRENT_SCREEN.cols[WINDOW_FILEAREA]-1)
  239.                   put_char(CURRENT_WINDOW,chtype_key|attr,INSCHAR);
  240.                else
  241.                   put_char(CURRENT_WINDOW,chtype_key|attr,ADDCHAR);
  242.               }
  243.             rc = memrevne(rec,' ',max_line_length);
  244.             if (rc == (-1))
  245.                rec_len = 0;
  246.             else
  247.                rec_len = rc+1;
  248.             /* check for the cursor moving past the right   */
  249.             /* margin when WORDWRAP is ON. If true, then    */
  250.             /* don't execute the cursor_right() function, as */
  251.             /* this could cause a window scroll.            */
  252.             if (CURRENT_VIEW->wordwrap
  253.             &&  rec_len > CURRENT_VIEW->margin_right)
  254.                execute_wrap_word(x+CURRENT_VIEW->verify_col);
  255.             else    
  256.                {
  257.                /* this is done here so that the show_page() in */
  258.                /* cursor_right() is executed AFTER we get the   */
  259.                /* new length of rec_len.                       */
  260. #if defined(USE_EXTCURSES)
  261.                if (x == CURRENT_SCREEN.cols[WINDOW_FILEAREA]-1)
  262.                  {
  263.                   wmove(CURRENT_WINDOW,y,x);
  264.      /*           wrefresh(CURRENT_WINDOW); */
  265.                   cursor_right(TRUE,FALSE);
  266.                  }
  267. #else
  268.                if (INSERTMODEx
  269.                || x == CURRENT_SCREEN.cols[WINDOW_FILEAREA]-1)
  270.                   cursor_right(TRUE,FALSE);
  271. #endif
  272.                }
  273. /*---------------------------------------------------------------------*/
  274. /* If HEXSHOW is on and we are on the current line, build screen...    */
  275. /*---------------------------------------------------------------------*/
  276.             if (CURRENT_VIEW->hexshow_on
  277.             &&  CURRENT_VIEW->focus_line == CURRENT_VIEW->current_line)
  278.                need_to_build_screen = TRUE;
  279.             break;
  280.        case WINDOW_COMMAND:
  281.             if (INSERTMODEx)
  282.               {
  283.                cmd_rec = (CHARTYPE *)meminschr((CHARTYPE *)cmd_rec,
  284.                                real_key,x,
  285.                                COLS,cmd_rec_len);
  286.                put_char(CURRENT_WINDOW,chtype_key,INSCHAR);
  287. #if !defined(USE_EXTCURSES)
  288.                cursor_right(TRUE,FALSE);
  289. #endif
  290. #ifndef OLD_CMD
  291.                cmd_rec_len++;
  292. #endif
  293.               }
  294.             else
  295.               {
  296.                cmd_rec[x] = real_key;
  297.                put_char(CURRENT_WINDOW,chtype_key,ADDCHAR);
  298. #ifndef OLD_CMD
  299.                cmd_rec_len = max(x+1,cmd_rec_len);
  300. #endif
  301.               }
  302. #ifdef OLD_CMD
  303.             rc = memrevne(cmd_rec,' ',COLS);
  304.             if (rc == (-1))
  305.                cmd_rec_len = 0;
  306.             else
  307.                cmd_rec_len = rc+1;
  308. #endif            
  309.             /*
  310.              * Ensure that the command line is not cleared if text is
  311.              * entered here
  312.              */
  313.             clear_command = FALSE;
  314.             break;
  315.        case WINDOW_PREFIX:
  316.             prefix_changed = TRUE;
  317.             if (pre_rec_len == 0)
  318.               {
  319.                x = 0;
  320.                wmove(CURRENT_WINDOW,y,x);
  321.                my_wclrtoeol(CURRENT_WINDOW);
  322.                wrefresh(CURRENT_WINDOW);
  323.               }
  324.             if (INSERTMODEx)
  325.               {
  326.                if (pre_rec_len == (CURRENT_VIEW->prefix_width-CURRENT_VIEW->prefix_gap))
  327.                   break;
  328.                pre_rec = (CHARTYPE *)meminschr((CHARTYPE *)pre_rec,
  329.                                real_key,x,CURRENT_VIEW->prefix_width-CURRENT_VIEW->prefix_gap,pre_rec_len);
  330.                put_char(CURRENT_WINDOW,chtype_key,INSCHAR);
  331.               }
  332.             else
  333.               {
  334.                pre_rec[x] = real_key;
  335.                put_char(CURRENT_WINDOW,chtype_key,ADDCHAR);
  336.               }
  337.             wmove(CURRENT_WINDOW,y,min(x+1,CURRENT_VIEW->prefix_width-CURRENT_VIEW->prefix_gap-1));
  338.             rc = memrevne(pre_rec,' ',CURRENT_VIEW->prefix_width);
  339.             if (rc == (-1))
  340.                pre_rec_len = 0;
  341.             else
  342.                pre_rec_len = rc+1;
  343.             break;
  344.       }
  345.    }
  346.  if (in_macro)
  347.     need_to_build_screen = TRUE;
  348. /*---------------------------------------------------------------------*/
  349. /* Set in_macro to FALSE to allow for the refreshing of the screen.    */
  350. /*---------------------------------------------------------------------*/
  351.  in_macro = FALSE;
  352. /*---------------------------------------------------------------------*/
  353. /* If text is being inserted on a line which is in the marked block,   */
  354. /* build and redisplay the window.                                     */
  355. /*---------------------------------------------------------------------*/
  356.  if (CURRENT_VIEW == MARK_VIEW
  357.  &&  CURRENT_VIEW->current_window == WINDOW_FILEAREA
  358.  &&  INSERTMODEx
  359.  &&  CURRENT_VIEW->focus_line >= MARK_VIEW->mark_start_line
  360.  &&  CURRENT_VIEW->focus_line <= MARK_VIEW->mark_end_line)
  361.      need_to_build_screen = TRUE;
  362.  if (need_to_build_screen)
  363.    {
  364.     build_screen(current_screen);
  365.     display_screen(current_screen);
  366.    }
  367. /*---------------------------------------------------------------------*/
  368. /* Set in_macro back to its original value...                          */
  369. /*---------------------------------------------------------------------*/
  370.  in_macro = save_in_macro;
  371. #ifdef TRACE
  372.  trace_return();
  373. #endif
  374.  return(RC_OK);
  375. }
  376. /*man-start*********************************************************************
  377. COMMAND
  378.      the - edit another file or switch to next file
  379.  
  380. SYNTAX
  381.      THE [filename]
  382.  
  383. DESCRIPTION
  384.      The THE command allows the user to edit another 'file'. The new file
  385.      is placed in the file <ring>. The previous file being edited remains
  386.      in memory and can be returned to by issuing a THE command without
  387.      any parameters. Several files can be edited at once, and all files
  388.      are arranged in a ring, with subsequent THE commands moving through
  389.      the ring, one file at a time.
  390.  
  391. COMPATIBILITY
  392.      XEDIT: Does not provide options switches.
  393.      KEDIT: Does not provide options switches.
  394.  
  395. SEE ALSO
  396.      <XEDIT>, <EDIT>
  397.  
  398. STATUS
  399.      Complete.
  400. **man-end**********************************************************************/
  401.  
  402. /*man-start*********************************************************************
  403. COMMAND
  404.      top - move to the top of the file
  405.  
  406. SYNTAX
  407.      TOP
  408.  
  409. DESCRIPTION
  410.      The TOP command moves to the very start of the current file.
  411.      The <Top-of-File line> is set to the <current line>.
  412.  
  413.      TOP is equivalent to <BACKWARD> *.
  414.  
  415. COMPATIBILITY
  416.      XEDIT: Compatible.
  417.      KEDIT: Compatible.
  418.  
  419. SEE ALSO
  420.      <BACKWARD>, <BOTTOM>
  421.  
  422. STATUS
  423.      Complete
  424. **man-end**********************************************************************/
  425. #ifdef HAVE_PROTO
  426. short Top(CHARTYPE *params)
  427. #else
  428. short Top(params)
  429. CHARTYPE *params;
  430. #endif
  431. /***********************************************************************/
  432. {
  433. /*-------------------------- external data ----------------------------*/
  434.  extern bool curses_started;
  435. /*--------------------------- local data ------------------------------*/
  436.  short rc=RC_TOF_EOF_REACHED;
  437.  unsigned short x=0,y=0;
  438. /*--------------------------- processing ------------------------------*/
  439. #ifdef TRACE
  440.  trace_function("comm5.c:   Top");
  441. #endif
  442. /*---------------------------------------------------------------------*/
  443. /* No arguments are allowed; error if any are present.                 */
  444. /*---------------------------------------------------------------------*/
  445.  if (strcmp((DEFCHAR *)params,"") != 0)
  446.    {
  447.     display_error(1,(CHARTYPE *)params,FALSE);
  448. #ifdef TRACE
  449.     trace_return();
  450. #endif
  451.     return(RC_INVALID_OPERAND);
  452.    }
  453.  CURRENT_VIEW->current_line = 0L;
  454.  post_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line,(LINE *)NULL,TRUE);
  455.  build_screen(current_screen); 
  456.  if (!line_in_view(current_screen,CURRENT_VIEW->focus_line))
  457.     CURRENT_VIEW->focus_line = 0L;
  458.  pre_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line,(LINE *)NULL);
  459.  if (curses_started)
  460.    {
  461.     if (CURRENT_VIEW->current_window == WINDOW_COMMAND)
  462.        getyx(CURRENT_PREV_WINDOW,y,x);
  463.     else
  464.        getyx(CURRENT_WINDOW,y,x);
  465.     display_screen(current_screen);
  466.     y = get_row_for_focus_line(current_screen,CURRENT_VIEW->focus_line,
  467.                                CURRENT_VIEW->current_row);
  468.     if (CURRENT_VIEW->current_window == WINDOW_COMMAND)
  469.        wmove(CURRENT_PREV_WINDOW,y,x);
  470.     else
  471.        wmove(CURRENT_WINDOW,y,x);
  472.    }
  473. #ifdef TRACE
  474.  trace_return();
  475. #endif
  476.  return(rc);
  477. }
  478. /*man-start*********************************************************************
  479. COMMAND
  480.      up - move backward in the file a number of lines
  481.  
  482. SYNTAX
  483.      Up [relative target]
  484.  
  485. DESCRIPTION
  486.      The UP command moves the <current line> backwards the number of
  487.      lines specified by the <relative target>. This <relative target> can
  488.      only be a positive integer or the character "*". 
  489.  
  490. COMPATIBILITY
  491.      XEDIT: Compatible.
  492.      KEDIT: Compatible.
  493.  
  494. DEFAULT
  495.      1
  496.  
  497. SEE ALSO
  498.      <NEXT>, <DOWN>
  499.  
  500. STATUS
  501.      Complete.
  502. **man-end**********************************************************************/
  503. #ifdef HAVE_PROTO
  504. short Up(CHARTYPE *params)
  505. #else
  506. short Up(params)
  507. CHARTYPE *params;
  508. #endif
  509. /***********************************************************************/
  510. {
  511. /*-------------------------- external data ----------------------------*/
  512. /*--------------------------- local data ------------------------------*/
  513.  short rc=RC_OK;
  514.  LINETYPE num_lines=0L,true_line=0L;
  515. /*--------------------------- processing ------------------------------*/
  516. #ifdef TRACE
  517.  trace_function("comm5.c:   Up");
  518. #endif
  519.  params = MyStrip(params,STRIP_BOTH,' ');
  520.  if (strcmp("",(DEFCHAR *)params) == 0)
  521.     params = (CHARTYPE *)"1";
  522.  true_line = get_true_line(TRUE);
  523.  if (strcmp("*",(DEFCHAR *)params) == 0)
  524.     num_lines = true_line + 1L;
  525.  else
  526.    {
  527.     if (!valid_integer(params))
  528.       {
  529.        display_error(4,params,FALSE);
  530. #ifdef TRACE
  531.        trace_return();
  532. #endif
  533.        return(RC_INVALID_OPERAND);
  534.       }
  535.     num_lines = atol((DEFCHAR *)params);
  536.     if (num_lines < 0L)
  537.       {
  538.        display_error(5,params,FALSE);
  539. #ifdef TRACE
  540.        trace_return();
  541. #endif
  542.        return(RC_INVALID_OPERAND);
  543.       }
  544.    }
  545.  rc = advance_current_or_focus_line(-num_lines);
  546. #ifdef TRACE
  547.  trace_return();
  548. #endif
  549.  return(rc);
  550. }
  551. /*man-start*********************************************************************
  552. COMMAND
  553.      uppercase - change lowercase characters to uppercase
  554.  
  555. SYNTAX
  556.      UPPercase [target]
  557.  
  558. DESCRIPTION
  559.      The UPPERCASE command changes all lowercase characters in all
  560.      lines up to the <'target'> line to uppercase. All other characters
  561.      remain untouched.
  562.  
  563. COMPATIBILITY
  564.      XEDIT: Equivalent of UPPERCAS
  565.      KEDIT: Compatible.
  566.  
  567. SEE ALSO
  568.      <LOWERCASE>
  569.  
  570. STATUS
  571.      Complete.
  572. **man-end**********************************************************************/
  573. #ifdef HAVE_PROTO
  574. short Uppercase(CHARTYPE *params)
  575. #else
  576. short Uppercase(params)
  577. CHARTYPE *params;
  578. #endif
  579. /***********************************************************************/
  580. {
  581. /*--------------------------- local data ------------------------------*/
  582.  short rc=RC_OK;
  583. /*--------------------------- processing ------------------------------*/
  584. #ifdef TRACE
  585.  trace_function("comm5.c:   Uppercase");
  586. #endif
  587.  rc = execute_change_case(params,CASE_UPPER);
  588. #ifdef TRACE
  589.  trace_return();
  590. #endif
  591.  return(rc);
  592. }
  593. /*man-start*********************************************************************
  594. COMMAND
  595.      xedit - edit another file or switch to next file
  596.  
  597. SYNTAX
  598.      Xedit [file]
  599.  
  600. DESCRIPTION
  601.      The XEDIT command allows the user to edit another 'file'. The new file
  602.      is placed in the file <ring>. The previous file being edited remains
  603.      in memory and can be returned to by issuing an XEDIT command without
  604.      any parameters. Several files can be edited at once, and all files
  605.      are arranged in a ring, with subsequent XEDIT commands moving through
  606.      the ring, one file at a time.
  607.  
  608. COMPATIBILITY
  609.      XEDIT: Does not provide options switches.
  610.      KEDIT: Does not provide options switches.
  611.  
  612. SEE ALSO
  613.      <EDIT>, <THE>
  614.  
  615. STATUS
  616.      Complete.
  617. **man-end**********************************************************************/
  618. #ifdef HAVE_PROTO
  619. short Xedit(CHARTYPE *params)
  620. #else
  621. short Xedit(params)
  622. CHARTYPE *params;
  623. #endif
  624. /***********************************************************************/
  625. {
  626. /*-------------------------- external data ----------------------------*/
  627.  extern CHARTYPE *cmd_rec;
  628.  extern unsigned short cmd_rec_len;
  629.  extern bool REPROFILEx;
  630.  extern CHARTYPE number_of_files;
  631.  extern CHARTYPE *prf_arg;
  632.  extern CHARTYPE *local_prf;
  633.  extern short file_start;
  634.  extern bool curses_started;
  635.  extern bool execute_profile;
  636.  extern bool in_profile;
  637.  extern bool in_reprofile;
  638.  extern int profile_file_executions;
  639.  extern CHARTYPE display_screens;
  640. /*--------------------------- local data ------------------------------*/
  641.  short rc=RC_OK,y=0,x=0;
  642.  VIEW_DETAILS *save_current_view=NULL;
  643.  VIEW_DETAILS *previous_current_view=NULL;
  644.  CHARTYPE save_prefix=0;
  645.  short save_gap=0;
  646.  ROWTYPE save_cmd_line=0;
  647.  bool save_id_line=0;
  648. /*--------------------------- processing ------------------------------*/
  649. #ifdef TRACE
  650.  trace_function("comm5.c:   Xedit");
  651. #endif
  652. /*---------------------------------------------------------------------*/
  653. /* With no arguments, edit the next file in the ring...                */
  654. /*---------------------------------------------------------------------*/
  655.  if (strcmp((DEFCHAR *)params,"") == 0)
  656.    {
  657.     rc = advance_view(NULL,DIRECTION_FORWARD);
  658. #ifdef TRACE
  659.     trace_return();
  660. #endif
  661.     return(rc);
  662.    }
  663. /*---------------------------------------------------------------------*/
  664. /* With "-" as argument, edit the previous file in the ring...         */
  665. /*---------------------------------------------------------------------*/
  666.  if (strcmp((DEFCHAR *)params,"-") == 0)
  667.    {
  668.     rc = advance_view(NULL,DIRECTION_BACKWARD);
  669. #ifdef TRACE
  670.     trace_return();
  671. #endif
  672.     return(rc);
  673.    }
  674. /*---------------------------------------------------------------------*/
  675. /* If there are still file(s) in the ring, clear the command line and  */
  676. /* save any changes to the focus line.                                 */
  677. /*---------------------------------------------------------------------*/
  678.  if (number_of_files > 0)
  679.    {
  680.     post_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line,(LINE *)NULL,TRUE);
  681.     memset(cmd_rec,' ',max_line_length);
  682.     cmd_rec_len = 0;
  683.    }
  684.  previous_current_view = CURRENT_VIEW;
  685. /*---------------------------------------------------------------------*/
  686. /* Save the position of the cursor for the current view before getting */
  687. /* the contents of the new file...                                     */
  688. /*---------------------------------------------------------------------*/
  689.  if (curses_started
  690.  &&  number_of_files > 0)
  691.    {
  692.     if (CURRENT_WINDOW_COMMAND != NULL)
  693.       {
  694.        wmove(CURRENT_WINDOW_COMMAND,0,0);
  695.        my_wclrtoeol(CURRENT_WINDOW_COMMAND);
  696.       }
  697.     getyx(CURRENT_WINDOW_FILEAREA,CURRENT_VIEW->y[WINDOW_FILEAREA],CURRENT_VIEW->x[WINDOW_FILEAREA]);
  698.     if (CURRENT_WINDOW_PREFIX != NULL)
  699.        getyx(CURRENT_WINDOW_PREFIX,CURRENT_VIEW->y[WINDOW_PREFIX],CURRENT_VIEW->x[WINDOW_PREFIX]);
  700.    }
  701.  if (number_of_files > 0)
  702.    {
  703.     save_prefix=CURRENT_VIEW->prefix;
  704.     save_gap=CURRENT_VIEW->prefix_gap;
  705.     save_cmd_line=CURRENT_VIEW->cmd_line;
  706.     save_id_line=CURRENT_VIEW->id_line;
  707.    }
  708. /*---------------------------------------------------------------------*/
  709. /* Read the contents of the new file into memory...                    */
  710. /*---------------------------------------------------------------------*/
  711.  if ((rc = get_file(strrmdup(strtrans(params,OSLASH,ISLASH),ISLASH))) != RC_OK)
  712.    {
  713. #ifdef TRACE
  714.     trace_return();
  715. #endif
  716.     return(rc);
  717.    }
  718. /*---------------------------------------------------------------------*/
  719. /* If more than one screen is displayed, sort out which view is to be  */
  720. /* displayed...                                                        */
  721. /*---------------------------------------------------------------------*/
  722.  if (display_screens > 1)
  723.    {
  724.     save_current_view = CURRENT_VIEW;
  725.     CURRENT_SCREEN.screen_view = CURRENT_VIEW = previous_current_view;
  726.     advance_view(save_current_view,DIRECTION_FORWARD);
  727.    }
  728.  else
  729.    {
  730.     if (number_of_files > 0)
  731.       {
  732. /*---------------------------------------------------------------------*/
  733. /* If the position of the prefix or command line for the new view is   */
  734. /* different from the previous view, rebuild the windows...            */
  735. /*---------------------------------------------------------------------*/
  736.        if ((save_prefix&PREFIX_LOCATION_MASK) != (CURRENT_VIEW->prefix&PREFIX_LOCATION_MASK)
  737.        ||  save_gap != CURRENT_VIEW->prefix_gap
  738.        ||  save_cmd_line != CURRENT_VIEW->cmd_line
  739.        ||  save_id_line != CURRENT_VIEW->id_line)
  740.          {
  741.           set_screen_defaults();
  742.           if (curses_started)
  743.             {
  744.              if (set_up_windows(current_screen) != RC_OK)
  745.                {
  746. #ifdef TRACE
  747.                 trace_return();
  748. #endif
  749.                 return(RC_OK);
  750.                }
  751.             }
  752.          }
  753.       }
  754. /*---------------------------------------------------------------------*/
  755. /* Re-calculate CURLINE for the new view in case the CURLINE is no     */
  756. /* longer in the display area.                                         */
  757. /*---------------------------------------------------------------------*/
  758.     prepare_view(current_screen);
  759.  }
  760.  pre_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line,(LINE *)NULL);
  761.  build_screen(current_screen);
  762. /*---------------------------------------------------------------------*/
  763. /* Position the cursor in the main window depending on the type of file*/
  764. /*---------------------------------------------------------------------*/
  765.  if (curses_started)
  766.    {
  767.     if (CURRENT_VIEW->in_ring)
  768.       {
  769.        wmove(CURRENT_WINDOW_FILEAREA,CURRENT_VIEW->y[WINDOW_FILEAREA],CURRENT_VIEW->x[WINDOW_FILEAREA]);
  770.        if (CURRENT_WINDOW_PREFIX != NULL)
  771.           wmove(CURRENT_WINDOW_PREFIX,CURRENT_VIEW->y[WINDOW_PREFIX],CURRENT_VIEW->x[WINDOW_PREFIX]);
  772.        getyx(CURRENT_WINDOW,y,x);
  773.        wmove(CURRENT_WINDOW,y,x);
  774.       }
  775.     else
  776.       {
  777.        if (CURRENT_FILE->pseudo_file == PSEUDO_DIR)
  778.           wmove(CURRENT_WINDOW_FILEAREA,CURRENT_VIEW->current_row,file_start-1);
  779.        else
  780.           wmove(CURRENT_WINDOW_FILEAREA,CURRENT_VIEW->current_row,0);
  781.       }
  782.    }
  783. /*---------------------------------------------------------------------*/
  784. /* Execute any profile file...                                         */
  785. /*---------------------------------------------------------------------*/
  786.  if (REPROFILEx || in_profile)
  787.    {
  788.     profile_file_executions++;
  789.     in_reprofile = TRUE;
  790.     if (execute_profile)
  791.       {
  792.        if (local_prf != (CHARTYPE *)NULL)
  793.           rc = get_profile(local_prf,prf_arg);
  794.       }
  795.     in_reprofile = FALSE;
  796.    }
  797. /*---------------------------------------------------------------------*/
  798. /* If the result of processing the profile file results in no files    */
  799. /* in the ring, we need to get out NOW.                                */
  800. /*---------------------------------------------------------------------*/
  801.  if (number_of_files == 0)
  802.    {
  803. #ifdef TRACE
  804.     trace_return();
  805. #endif
  806.     return(rc);
  807.    }
  808. /* pre_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line,(LINE *)NULL);*/
  809.  build_screen(current_screen);
  810. /*---------------------------------------------------------------------*/
  811. /* If curses hasn't started, don't try to use curses functions...      */
  812. /*---------------------------------------------------------------------*/
  813.  if (curses_started)
  814.    {
  815.     display_screen(current_screen);
  816.     if (CURRENT_WINDOW_COMMAND != NULL)
  817.        wmove(CURRENT_WINDOW_COMMAND,0,0);
  818.     if (CURRENT_WINDOW_PREFIX != NULL)
  819.        touchwin(CURRENT_WINDOW_PREFIX);
  820.     if (CURRENT_WINDOW_GAP != NULL)
  821.        touchwin(CURRENT_WINDOW_GAP);
  822.     if (CURRENT_WINDOW_COMMAND != NULL)
  823.        touchwin(CURRENT_WINDOW_COMMAND);
  824.     if (CURRENT_WINDOW_IDLINE != NULL)
  825.        touchwin(CURRENT_WINDOW_IDLINE);
  826.     touchwin(CURRENT_WINDOW_FILEAREA);
  827.     show_statarea();
  828.    }
  829. #ifdef TRACE
  830.  trace_return();
  831. #endif
  832.  return(rc);
  833. }
  834. /*man-start*********************************************************************
  835. COMMAND
  836.      ? - retrieve - return the next/prior command on the command line
  837.  
  838. SYNTAX
  839.      ?[+|?...]
  840.  
  841. DESCRIPTION
  842.      The ? command returns the next or prior command from the command
  843.      line ring and displays it on the command line.
  844.  
  845.      With the ['+'] argument, the next command in the command ring is
  846.      retrieved.
  847.  
  848.      With no arguments, the previous command entered on the command
  849.      line is retrieved.
  850.  
  851.      With multiple, concatenated ?s as argument, the pervious command
  852.      entered on the command line is retrieved corresponding to the
  853.      number of ?s entered.
  854.  
  855.      For Example:
  856.      The command; ????? will retrieve the fifth last command entered.
  857.  
  858. COMPATIBILITY
  859.      XEDIT: Compatible. Adds extra support for multiple ?s.
  860.      KEDIT: See below..
  861.      This command is bound to the up and down arrows when on the
  862.      command line depending on the setting of <SET CMDARROWS>.
  863.  
  864. SEE ALSO
  865.      <SET CMDARROWS>
  866.  
  867. STATUS
  868.      Complete.
  869. **man-end**********************************************************************/
  870. #ifdef HAVE_PROTO
  871. short Retrieve(CHARTYPE *params)
  872. #else
  873. short Retrieve(params)
  874. CHARTYPE *params;
  875. #endif
  876. /***********************************************************************/
  877. {
  878. /*-------------------------- external data ----------------------------*/
  879. /*--------------------------- local data ------------------------------*/
  880.  CHARTYPE *current_command=NULL;
  881.  CHARTYPE *save_params=NULL;
  882.  int param_len=0;
  883.  short direction=0;
  884. /*--------------------------- processing ------------------------------*/
  885. #ifdef TRACE
  886.  trace_function("comm5.c:   Retrieve");
  887. #endif
  888. /*
  889.  *---------------------------------------------------------------------
  890.  * No parameters, get the last command...
  891.  *---------------------------------------------------------------------
  892.  */
  893.  if (strcmp((DEFCHAR *)params,"") == 0)
  894.     current_command = get_next_command(DIRECTION_FORWARD,1);
  895.  else
  896.    {
  897.     /*
  898.      *---------------------------------------------------------------------
  899.      * Get a copy of the parameters, because we want to manipulate them,
  900.      * and also retain the orignal for error reporting.
  901.      *---------------------------------------------------------------------
  902.      */
  903.     if ((save_params = (CHARTYPE *)my_strdup(params)) == NULL)
  904.       {
  905.        display_error(30,(CHARTYPE *)"",FALSE);
  906. #ifdef TRACE
  907.        trace_return();
  908. #endif
  909.        return(RC_OUT_OF_MEMORY);
  910.       }
  911.     /*
  912.      *---------------------------------------------------------------------
  913.      * Strip all spaces from the parameters.  We want to be able to specify
  914.      * ?  ? ? - as a valid set of arguments, equivalent to ???-
  915.      *---------------------------------------------------------------------
  916.      */
  917.     save_params = MyStrip(save_params,STRIP_ALL,' ');
  918.     param_len = strlen((DEFCHAR *)save_params);
  919.     if (*(save_params+(param_len-1)) == (CHARTYPE)'+')
  920.       {
  921.        *(save_params+(param_len-1)) = '\0';
  922.        direction = DIRECTION_BACKWARD;
  923.       }
  924.     else
  925.       {
  926.        if (*(save_params+(param_len-1)) == (CHARTYPE)'-')
  927.          {
  928.           *(save_params+(param_len-1)) = '\0';
  929.           direction = DIRECTION_FORWARD;
  930.          }
  931.       }
  932.     if (strzne(save_params,(CHARTYPE)'?') != (-1))
  933.       {
  934.        display_error(1,params,FALSE);
  935. #ifdef TRACE
  936.        trace_return();
  937. #endif
  938.        return(RC_INVALID_OPERAND);
  939.       }
  940.     current_command = get_next_command(direction,strlen((DEFCHAR *)save_params)+1);
  941.    }
  942.  if (save_params)
  943.     (*the_free)(save_params);
  944.  wmove(CURRENT_WINDOW_COMMAND,0,0);
  945.  my_wclrtoeol(CURRENT_WINDOW_COMMAND);
  946.  if (current_command != (CHARTYPE *)NULL)
  947.     Cmsg(current_command);
  948. #ifdef TRACE
  949.  trace_return();
  950. #endif
  951.  return(RC_OK);
  952. }
  953. /*man-start*********************************************************************
  954. COMMAND
  955.      = - re-execute the last command issued on the command line
  956.  
  957. SYNTAX
  958.      =
  959.  
  960. DESCRIPTION
  961.      The = command retrieves the most recently issued command from
  962.      the <command line> and re-executes it.
  963.  
  964. COMPATIBILITY
  965.      XEDIT: Does not support optional [subcommand] option.
  966.      KEDIT: Does not support optional [command] option.
  967.  
  968. STATUS
  969.      Complete.
  970. **man-end**********************************************************************/
  971. #ifdef HAVE_PROTO
  972. short Reexecute(CHARTYPE *params)
  973. #else
  974. short Reexecute(params)
  975. CHARTYPE *params;
  976. #endif
  977. /***********************************************************************/
  978. {
  979. /*-------------------------- external data ----------------------------*/
  980.  extern CHARTYPE last_command_for_reexecute[MAX_COMMAND_LENGTH];
  981. /*--------------------------- local data ------------------------------*/
  982.  short rc=RC_OK;
  983. /*--------------------------- processing ------------------------------*/
  984. #ifdef TRACE
  985.  trace_function("comm5.c:   Reexecute");
  986. #endif
  987.  if (strcmp((DEFCHAR *)params,""))
  988.     {
  989.      display_error(1,params,FALSE);
  990. #ifdef TRACE
  991.      trace_return();
  992. #endif
  993.      return(RC_INVALID_OPERAND);
  994.     }
  995. /*---------------------------------------------------------------------*/
  996. /* Retrieve the last command and execute it.                           */
  997. /*---------------------------------------------------------------------*/
  998.  rc = command_line(last_command_for_reexecute,COMMAND_ONLY_FALSE);
  999. #ifdef TRACE
  1000.  trace_return();
  1001. #endif
  1002.  return(rc);
  1003. }
  1004. /*man-start*********************************************************************
  1005. COMMAND
  1006.      ! - execute an operating system command
  1007.  
  1008. SYNTAX
  1009.      ! [command]
  1010.  
  1011. DESCRIPTION
  1012.      The ! command executes the supplied operating system 'command'
  1013.      or runs an interactive shell if no 'command' is supplied.
  1014.  
  1015. COMPATIBILITY
  1016.      XEDIT: N/A
  1017.      KEDIT: Equivalent to DOS command.
  1018.  
  1019. SEE ALSO
  1020.      <DOS>, <OS>
  1021.  
  1022. STATUS
  1023.      Complete.
  1024. **man-end**********************************************************************/
  1025.  
  1026. /*man-start*********************************************************************
  1027. COMMAND
  1028.      & - execute and re-display command
  1029.  
  1030. SYNTAX
  1031.      &[command]
  1032.  
  1033. DESCRIPTION
  1034.      The & command executes the supplied 'command' in the normal
  1035.      way, but when the command completes, instead of clearing
  1036.      the THE command line, the command, and the & are 
  1037.      re-displayed.  This makes it easy to repeat the same
  1038.      command, or make changes to it.
  1039.  
  1040. COMPATIBILITY
  1041.      XEDIT: Compatible.
  1042.      KEDIT: Compatible.
  1043.  
  1044. STATUS
  1045.      Complete.
  1046. **man-end**********************************************************************/
  1047.