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

  1. /***********************************************************************/
  2. /* PREFIX.C - Prefix commands.                                         */
  3. /***********************************************************************/
  4. /*
  5.  * THE - The Hessling Editor. A text editor similar to VM/CMS xedit.
  6.  * Copyright (C) 1991-1997 Mark Hessling
  7.  *
  8.  * This program is free software; you can redistribute it and/or
  9.  * modify it under the terms of the GNU General Public License as
  10.  * published by the Free Software Foundation; either version 2 of
  11.  * the License, or any later version.
  12.  *
  13.  * This program is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16.  * General Public License for more details.
  17.  *
  18.  * You should have received a copy of the GNU General Public License
  19.  * along with this program; if not, write to:
  20.  *
  21.  *    The Free Software Foundation, Inc.
  22.  *    675 Mass Ave,
  23.  *    Cambridge, MA 02139 USA.
  24.  *
  25.  *
  26.  * If you make modifications to this software that you feel increases
  27.  * it usefulness for the rest of the community, please email the
  28.  * changes, enhancements, bug fixes as well as any and all ideas to me.
  29.  * This software is going to be maintained and enhanced as deemed
  30.  * necessary by the community.
  31.  *
  32.  * Mark Hessling                 Email:             M.Hessling@qut.edu.au
  33.  * PO Box 203                    Phone:                    +617 3802 0800
  34.  * Bellara                       http://www.gu.edu.au/gwis/the/markh.html
  35.  * QLD 4507                      **** Maintainer PDCurses & REXX/SQL ****
  36.  * Australia                     ************* Author of THE ************
  37.  */
  38.  
  39. /*
  40. $Id: prefix.c 2.1 1995/06/24 16:30:44 MH Rel MH $
  41. */
  42.  
  43. #include <the.h>
  44. #include <proto.h>
  45.  
  46. /*-------------------------- declarations -----------------------------*/
  47. #ifdef HAVE_PROTO
  48. static short parse_prefix_command(PPC *,CHARTYPE *,CHARTYPE *);
  49. static short invalidate_prefix(PPC *);
  50. static short prefix_makecurr(PPC *,short,LINETYPE);
  51. static short prefix_add(PPC *,short,LINETYPE);
  52. static short prefix_duplicate(PPC *,short,LINETYPE);
  53. static short prefix_copy(PPC *,short,LINETYPE);
  54. static short prefix_move(PPC *,short,LINETYPE);
  55. static short prefix_delete(PPC *,short,LINETYPE);
  56. static short prefix_shift_left(PPC *,short,LINETYPE);
  57. static short prefix_shift_right(PPC *,short,LINETYPE);
  58. static short prefix_tabline(PPC *,short,LINETYPE);
  59. static short prefix_scale(PPC *,short,LINETYPE);
  60. static short prefix_show(PPC *,short,LINETYPE);
  61. static short prefix_exclude(PPC *,short,LINETYPE);
  62. static short prefix_block_duplicate(PPC *,short,LINETYPE);
  63. static short prefix_block_copy(PPC *,short,LINETYPE);
  64. static short prefix_block_move(PPC *,short,LINETYPE);
  65. static short prefix_block_delete(PPC *,short,LINETYPE);
  66. static short prefix_block_shift_left(PPC *,short,LINETYPE);
  67. static short prefix_block_shift_right(PPC *,short,LINETYPE);
  68. static short prefix_block_exclude(PPC *,short,LINETYPE);
  69. static PPC *find_bottom_ppc(PPC *,short);
  70. static PPC *find_target_ppc(void);
  71. static PPC *calculate_target_line(void);
  72. static short try_rexx_prefix_macro(PPC *);
  73. static CHARTYPE *substr(CHARTYPE *, CHARTYPE *, short, short);
  74. static short post_prefix_add(PPC *,short,LINETYPE);
  75. #else
  76. static short parse_prefix_command();
  77. static short invalidate_prefix();
  78. static short prefix_makecurr();
  79. static short prefix_add();
  80. static short prefix_duplicate();
  81. static short prefix_copy();
  82. static short prefix_move();
  83. static short prefix_delete();
  84. static short prefix_shift_left();
  85. static short prefix_shift_right();
  86. static short prefix_tabline();
  87. static short prefix_scale();
  88. static short prefix_show();
  89. static short prefix_exclude();
  90. static short prefix_block_duplicate();
  91. static short prefix_block_copy();
  92. static short prefix_block_move();
  93. static short prefix_block_delete();
  94. static short prefix_block_shift_left();
  95. static short prefix_block_shift_right();
  96. static short prefix_block_exclude();
  97. static PPC *find_bottom_ppc();
  98. static PPC *find_target_ppc();
  99. static PPC *calculate_target_line();
  100. static short try_rexx_prefix_macro();
  101. static CHARTYPE *substr();
  102. static short post_prefix_add();
  103. #endif
  104. /*---------------------------------------------------------------------*/
  105. /* The following two are to specify the first and last items in the    */
  106. /* linked list for prefix synonyms.                                    */
  107. /*---------------------------------------------------------------------*/
  108. LINE *first_prefix_synonym=NULL;
  109. LINE *last_prefix_synonym=NULL;
  110. /*---------------------------------------------------------------------*/
  111.  
  112. #define PPC_NO_TARGET        (-1)
  113. #define PPC_NO_COMMAND       (-2)
  114. #define PPC_TARGET_PREVIOUS  0
  115. #define PPC_TARGET_FOLLOWING 1
  116. /* the above two defines correspond to the position in the pc[] array  */
  117. /* and should be changed if the position in pc[] array changes.        */
  118.  
  119. #define NUMBER_PREFIX_COMMANDS 22
  120.  static PREFIX_COMMAND pc[NUMBER_PREFIX_COMMANDS] =
  121.   {
  122.    {(CHARTYPE *)"p",1,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,TRUE,FALSE,NULL,1L,FALSE,FALSE,0,NULL},
  123.    {(CHARTYPE *)"f",1,FALSE,FALSE,FALSE,FALSE,FALSE,TRUE,FALSE,FALSE,NULL,1L,FALSE,FALSE,0,NULL},
  124.    {(CHARTYPE *)"tabl",4,TRUE,FALSE,FALSE,FALSE,FALSE,TRUE,TRUE,TRUE,prefix_tabline,1L,FALSE,FALSE,0,NULL},
  125.    {(CHARTYPE *)"scale",5,TRUE,FALSE,FALSE,FALSE,FALSE,TRUE,TRUE,TRUE,prefix_scale,1L,FALSE,FALSE,0,NULL},
  126.    {(CHARTYPE *)"\"\"",2,TRUE,TRUE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,prefix_block_duplicate,1L,FALSE,FALSE,40,NULL},
  127.    {(CHARTYPE *)"cc",2,TRUE,TRUE,FALSE,TRUE,TRUE,FALSE,FALSE,FALSE,prefix_block_copy,1L,FALSE,FALSE,30,NULL},
  128.    {(CHARTYPE *)"mm",2,TRUE,TRUE,FALSE,TRUE,TRUE,FALSE,FALSE,FALSE,prefix_block_move,1L,FALSE,FALSE,30,NULL},
  129.    {(CHARTYPE *)"dd",2,TRUE,TRUE,FALSE,TRUE,FALSE,FALSE,FALSE,FALSE,prefix_block_delete,1L,FALSE,FALSE,10,NULL},
  130.    {(CHARTYPE *)"xx",2,TRUE,TRUE,FALSE,TRUE,FALSE,FALSE,FALSE,FALSE,prefix_block_exclude,1L,FALSE,FALSE,30,NULL},
  131.    {(CHARTYPE *)"<<",2,TRUE,TRUE,FALSE,TRUE,FALSE,FALSE,FALSE,FALSE,prefix_block_shift_left,1L,FALSE,FALSE,30,NULL},
  132.    {(CHARTYPE *)">>",2,TRUE,TRUE,FALSE,TRUE,FALSE,FALSE,FALSE,FALSE,prefix_block_shift_right,1L,FALSE,FALSE,30,NULL},
  133.    {(CHARTYPE *)"\"",1,TRUE,TRUE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,prefix_duplicate,1L,FALSE,FALSE,40,NULL},
  134.    {(CHARTYPE *)"c",1,TRUE,TRUE,TRUE,FALSE,TRUE,FALSE,FALSE,FALSE,prefix_copy,1L,FALSE,FALSE,30,NULL},
  135.    {(CHARTYPE *)"m",1,TRUE,TRUE,TRUE,FALSE,TRUE,FALSE,FALSE,FALSE,prefix_move,1L,FALSE,FALSE,30,NULL},
  136.    {(CHARTYPE *)"d",1,TRUE,TRUE,TRUE,FALSE,FALSE,FALSE,FALSE,FALSE,prefix_delete,1L,FALSE,FALSE,10,NULL},
  137.    {(CHARTYPE *)"s",1,TRUE,TRUE,TRUE,FALSE,FALSE,FALSE,FALSE,FALSE,prefix_show,MAX_LONG,TRUE,TRUE,30,NULL},
  138.    {(CHARTYPE *)"x",1,TRUE,TRUE,TRUE,FALSE,FALSE,FALSE,FALSE,FALSE,prefix_exclude,1L,FALSE,FALSE,30,NULL},
  139.    {(CHARTYPE *)"<",1,TRUE,TRUE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,prefix_shift_left,1L,FALSE,FALSE,30,NULL},
  140.    {(CHARTYPE *)">",1,TRUE,TRUE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,prefix_shift_right,1L,FALSE,FALSE,30,NULL},
  141.    {(CHARTYPE *)"i",1,TRUE,TRUE,FALSE,FALSE,FALSE,TRUE,FALSE,FALSE,prefix_add,1L,FALSE,FALSE,60,post_prefix_add},
  142.    {(CHARTYPE *)"a",1,TRUE,TRUE,FALSE,FALSE,FALSE,TRUE,FALSE,FALSE,prefix_add,1L,FALSE,FALSE,60,post_prefix_add},
  143.    {(CHARTYPE *)"/",1,TRUE,TRUE,FALSE,FALSE,FALSE,TRUE,TRUE,TRUE,prefix_makecurr,1L,FALSE,FALSE,50,NULL},
  144.   };
  145.  
  146. LINETYPE prefix_current_line;
  147. bool in_prefix_macro=FALSE;     /* indicate if processing prefix macro */
  148. /***********************************************************************/
  149. #ifdef HAVE_PROTO
  150. short execute_prefix_commands(void)
  151. #else
  152. short execute_prefix_commands()
  153. #endif
  154. /***********************************************************************/
  155. {
  156. /*-------------------------- external data ----------------------------*/
  157.  extern bool readonly;
  158.  extern bool rexx_support;
  159.  extern CHARTYPE number_of_files;
  160.  extern bool curses_started;
  161. /*--------------------------- local data ------------------------------*/
  162.  short cmd_idx=0,rc=RC_OK;
  163.  CHARTYPE cmd[MAX_PREFIX_WIDTH+1];
  164.  CHARTYPE mult[MAX_PREFIX_WIDTH+1];
  165.  LINETYPE long_mult=0L;
  166.  short top_ppc=0,bot_ppc=0,target_ppc=0;
  167.  PPC *curr_ppc=NULL;
  168.  TARGET target;
  169.  short target_type=TARGET_NORMAL;
  170.  unsigned short y=0,x=0;
  171.  int top_priority_idx=0;
  172. /*--------------------------- processing ------------------------------*/
  173. #ifdef TRACE
  174.  trace_function("prefix.c:  execute_prefix_commands");
  175. #endif
  176.  post_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line,(LINE *)NULL,TRUE);
  177. /*---------------------------------------------------------------------*/
  178. /* Validate all pending prefix commands...                             */
  179. /*---------------------------------------------------------------------*/
  180.  curr_ppc = CURRENT_FILE->first_ppc;
  181.  while(1)
  182.    {
  183.     if (curr_ppc == NULL)
  184.        break;
  185. /*---------------------------------------------------------------------*/
  186. /* If a set point command, validate the name.                          */
  187. /*---------------------------------------------------------------------*/
  188.     if (*(curr_ppc->ppc_command) == '.')
  189.       {
  190.        if (isalpha(curr_ppc->ppc_command[1]))
  191.          {
  192.           if (execute_set_point(curr_ppc->ppc_command,curr_ppc->ppc_line_number,TRUE) != RC_OK)
  193.             {
  194.              invalidate_prefix(curr_ppc);
  195.              curr_ppc = curr_ppc->next;
  196.              continue;
  197.             }
  198.           clear_pending_prefix_command(curr_ppc,(LINE *)NULL);
  199.           curr_ppc = curr_ppc->next;
  200.           continue;
  201.          }
  202.        else
  203.          {
  204.           invalidate_prefix(curr_ppc);
  205.           curr_ppc = curr_ppc->next;
  206.           continue;
  207.          }
  208.       }
  209. /*---------------------------------------------------------------------*/
  210. /* If an invalid prefix command from last time, clear it.              */
  211. /*---------------------------------------------------------------------*/
  212.     if (*(curr_ppc->ppc_command) == '?')
  213.       {
  214.        clear_pending_prefix_command(curr_ppc,(LINE *)NULL);
  215.        curr_ppc = curr_ppc->next;
  216.        continue;
  217.       }
  218. /*---------------------------------------------------------------------*/
  219. /* To get here we have 'normal' prefix command.                        */
  220. /*---------------------------------------------------------------------*/
  221.     if (rexx_support)              /* if REXX support is in effect ... */
  222.       {
  223. /*---------------------------------------------------------------------*/
  224. /* first determine if the command is a prefix macro BEFORE looking for */
  225. /* standard prefix commands.                                           */
  226. /*---------------------------------------------------------------------*/
  227.        rc = try_rexx_prefix_macro(curr_ppc);
  228. /*---------------------------------------------------------------------*/
  229. /* If at this point there are no more files in the ring; we assume that*/
  230. /* this was caused by exitting the last file in the ring from a prefix */
  231. /* macro, exit and ignore any more prefix commands. This is messy !!!  */
  232. /*---------------------------------------------------------------------*/
  233.        if (number_of_files == 0)
  234.          {
  235. #ifdef TRACE
  236.           trace_return();
  237. #endif
  238.           return(RC_COMMAND_NO_FILES);
  239.          }
  240.        if (rc != RC_NOT_COMMAND)
  241.          {
  242.           curr_ppc = curr_ppc->next;
  243.           continue;
  244.          }
  245.       }
  246. /*---------------------------------------------------------------------*/
  247. /* if no prefix macro found for the prefix command, check to see if it */
  248. /* is a standard prefix command.                                       */
  249. /*---------------------------------------------------------------------*/
  250.     if ((cmd_idx = parse_prefix_command(curr_ppc,cmd,mult)) == PPC_NO_TARGET)
  251.       {
  252.        invalidate_prefix(curr_ppc);
  253.        curr_ppc = curr_ppc->next;
  254.        continue;
  255.       }
  256.     if (cmd_idx == PPC_NO_COMMAND)
  257.       {
  258.        curr_ppc = curr_ppc->next;
  259.        continue;
  260.       }
  261. /*---------------------------------------------------------------------*/
  262. /* If running in read-only mode and the function selected is not valid */
  263. /* display an error.                                                   */
  264. /*---------------------------------------------------------------------*/
  265.     if (readonly && !pc[cmd_idx].valid_in_readonly)
  266.       {
  267.        display_error(56,(CHARTYPE *)"",FALSE);
  268.        invalidate_prefix(curr_ppc);
  269.        continue;
  270.       }
  271. /*---------------------------------------------------------------------*/
  272. /* We now have a recognised command. We have to validate its parameters*/
  273. /* and find any associated pending commands.                           */
  274. /*---------------------------------------------------------------------*/
  275. /*---------------------------------------------------------------------*/
  276. /* Set the block_command flag for the current prefix command to the    */
  277. /* appropriate value for the prefix command.                           */
  278. /*---------------------------------------------------------------------*/
  279.     curr_ppc->ppc_block_command = pc[cmd_idx].block_prefix_command;
  280. /*---------------------------------------------------------------------*/
  281. /* If the command does not allow parameters and there are parameters,  */
  282. /* error.                                                              */
  283. /*---------------------------------------------------------------------*/
  284.     if (!pc[cmd_idx].multiples_allowed
  285.     && strcmp((DEFCHAR *)mult,"") != 0)
  286.       {
  287.        invalidate_prefix(curr_ppc);
  288.        curr_ppc = curr_ppc->next;
  289.        continue;
  290.       }
  291. /*---------------------------------------------------------------------*/
  292. /* If the command does allow parameters and there are no parameters,   */
  293. /* set to default...                                                   */
  294. /*---------------------------------------------------------------------*/
  295.     rc = RC_OK;
  296.     if (strcmp((DEFCHAR *)mult,"") == 0)
  297.        long_mult = pc[cmd_idx].default_target;
  298.     else
  299. /*---------------------------------------------------------------------*/
  300. /* ...otherwise validate the target supplied...                        */
  301. /*---------------------------------------------------------------------*/
  302.       {
  303.        if (pc[cmd_idx].multiples_allowed)
  304.          {
  305.           if (pc[cmd_idx].full_target_allowed)
  306.             {
  307.              initialise_target(&target);
  308.              target.ignore_scope = pc[cmd_idx].ignore_scope;
  309.              if (pc[cmd_idx].use_last_not_in_scope        /* S command */
  310.              && mult[0] == '-')
  311.                 rc = validate_target(mult,&target,target_type,find_last_not_in_scope(CURRENT_VIEW,NULL,curr_ppc->ppc_line_number,DIRECTION_FORWARD),TRUE,TRUE);
  312.              else
  313.                 rc = validate_target(mult,&target,target_type,curr_ppc->ppc_line_number,TRUE,TRUE);
  314.              if (target.num_lines == 0L)
  315.                 rc = RC_INVALID_OPERAND;
  316.              long_mult = target.num_lines;
  317.              free_target(&target);
  318.             }
  319.           else
  320.              if (!valid_positive_integer(mult))
  321.                 rc = RC_INVALID_OPERAND;
  322.              else
  323.                 long_mult = atol((DEFCHAR *)mult);
  324.          }
  325.       }
  326. /*---------------------------------------------------------------------*/
  327. /* If the target is invalid or not found, invalidate the command.      */
  328. /*---------------------------------------------------------------------*/
  329.     if (rc != RC_OK)
  330.       {
  331.        invalidate_prefix(curr_ppc);
  332.        curr_ppc = curr_ppc->next;
  333.        continue;
  334.       }
  335.     curr_ppc->ppc_cmd_param = long_mult;
  336.     curr_ppc = curr_ppc->next;
  337.    }
  338. /*---------------------------------------------------------------------*/
  339. /* For each valid pending  command for the current view, execute  the  */
  340. /* command.                                                            */
  341. /*---------------------------------------------------------------------*/
  342.  curr_ppc = CURRENT_FILE->first_ppc;
  343.  top_priority_idx=(-1);
  344.  while(curr_ppc != NULL)
  345.    {
  346.     top_ppc = bot_ppc = target_ppc = (-1);
  347. /*---------------------------------------------------------------------*/
  348. /* Execute the function associated with the prefix command...          */
  349. /*---------------------------------------------------------------------*/
  350.     cmd_idx = curr_ppc->ppc_cmd_idx;
  351.     long_mult = curr_ppc->ppc_cmd_param;
  352.     if (cmd_idx != (-1)
  353.     &&  cmd_idx != (-2)
  354.     &&  pc[cmd_idx].function != NULL)
  355.        rc = (*pc[cmd_idx].function)(curr_ppc,cmd_idx,long_mult);
  356.     curr_ppc = curr_ppc->next;
  357. /*---------------------------------------------------------------------*/
  358. /* Determine the prefix command with the highest priority and save it. */
  359. /*---------------------------------------------------------------------*/
  360.     if (cmd_idx >= 0)
  361.       {
  362.        if (top_priority_idx == (-1))
  363.           top_priority_idx = cmd_idx;
  364.        else
  365.          {
  366.           if (pc[cmd_idx].priority > pc[top_priority_idx].priority)
  367.              top_priority_idx = cmd_idx;
  368.          }
  369.       }
  370.    }
  371. /*---------------------------------------------------------------------*/
  372. /* The "cleared" pending prefix commands now need to be deleted from   */
  373. /* the linked list...                                                  */
  374. /*---------------------------------------------------------------------*/
  375.  curr_ppc = CURRENT_FILE->first_ppc;
  376.  while(curr_ppc != NULL)
  377.    {
  378.     if (curr_ppc->ppc_cmd_idx == (-1))
  379.        curr_ppc = delete_pending_prefix_command(curr_ppc,CURRENT_FILE,NULL);
  380.     else
  381.        curr_ppc = curr_ppc->next;
  382.    }
  383. /*---------------------------------------------------------------------*/
  384. /* Now that we are here, display the new version of the screen.        */
  385. /*---------------------------------------------------------------------*/
  386.  if (top_priority_idx != (-1))
  387.    {
  388.     if (pc[top_priority_idx].post_function != NULL)
  389.        rc = (*pc[top_priority_idx].post_function)(curr_ppc,cmd_idx,long_mult);
  390.    }
  391.  pre_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line,(LINE *)NULL);
  392.  build_screen(current_screen); 
  393.  display_screen(current_screen);
  394.  if (CURRENT_VIEW->current_window != WINDOW_COMMAND)
  395.    {
  396.     if (curses_started)
  397.        getyx(CURRENT_WINDOW,y,x);
  398.     CURRENT_VIEW->focus_line = get_focus_line_in_view(current_screen,CURRENT_VIEW->focus_line,y);
  399.     y = get_row_for_focus_line(current_screen,CURRENT_VIEW->focus_line,CURRENT_VIEW->current_row);
  400.     if (curses_started)
  401.        wmove(CURRENT_WINDOW,y,x);
  402.     pre_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line,(LINE *)NULL);
  403.    }
  404. #ifdef TRACE
  405.  trace_return();
  406. #endif
  407.  return(RC_OK);
  408. }
  409. /***********************************************************************/
  410. #ifdef HAVE_PROTO
  411. static short parse_prefix_command(PPC *curr_ppc,CHARTYPE *cmd,CHARTYPE *mult)
  412. #else
  413. static short parse_prefix_command(curr_ppc,cmd,mult)
  414. PPC *curr_ppc;
  415. CHARTYPE *cmd,*mult;
  416. #endif
  417. /***********************************************************************/
  418. {
  419. /*-------------------------- external data ----------------------------*/
  420. /*--------------------------- local data ------------------------------*/
  421.  register short i=0,j=0;
  422.  short len_pcmd=0;
  423.  CHARTYPE pcmd[MAX_PREFIX_WIDTH+1];
  424.  short pos=0,rc=RC_OK;
  425.  LINE *curr=NULL;
  426. /*--------------------------- processing ------------------------------*/
  427. #ifdef TRACE
  428.  trace_function("prefix.c:  parse_prefix_command");
  429. #endif
  430. /*---------------------------------------------------------------------*/
  431. /* For each pending prefix command for the current view, execute the   */
  432. /* appropriate command.                                                */
  433. /*---------------------------------------------------------------------*/
  434.  rc = PPC_NO_TARGET;
  435.  strcpy((DEFCHAR *)pcmd,(DEFCHAR *)curr_ppc->ppc_command); /* get our own copy to pull apart */
  436.  if (blank_field(pcmd))          /* if prefix command is blank, return */
  437.    {
  438. #ifdef TRACE
  439.     trace_return();
  440. #endif
  441.     return(PPC_NO_COMMAND);
  442.    }
  443.  len_pcmd = strlen((DEFCHAR *)pcmd);
  444. /*---------------------------------------------------------------------*/
  445. /* For each prefix synonym, determine if it exists somewhere in the    */
  446. /* entered prefix command.                                             */
  447. /*---------------------------------------------------------------------*/
  448.  curr = first_prefix_synonym;
  449.  while(1)
  450.    {
  451.     if (curr == NULL)
  452.        break;
  453.     pos = memfind(pcmd,curr->name,len_pcmd,strlen((DEFCHAR *)curr->name),TRUE,FALSE,' ',' ');
  454.     if (pos == (-1))
  455.       {
  456.        curr = curr->next;
  457.        continue;
  458.       }
  459. /*---------------------------------------------------------------------*/
  460. /* Now that a match on synonym is made, determine the original prefix  */
  461. /* command associated with that synonym...                             */
  462. /*---------------------------------------------------------------------*/
  463.     for (i=0;i<NUMBER_PREFIX_COMMANDS;i++)
  464.       {
  465.        if (strcmp((DEFCHAR *)pc[i].cmd,(DEFCHAR *)curr->line) == 0)
  466.          {
  467.           strcpy((DEFCHAR *)cmd,(DEFCHAR *)pc[i].cmd);
  468.           for (j=0;j<strlen((DEFCHAR *)curr->name);j++)
  469.              *(pcmd+pos+j) = ' ';
  470.           strtrunc(pcmd);
  471.           strcpy((DEFCHAR *)mult,(DEFCHAR *)pcmd);
  472.           curr_ppc->ppc_cmd_idx = i;
  473. #ifdef TRACE
  474.           trace_return();
  475. #endif
  476.           return(i);
  477.          }
  478.       }
  479. /*---------------------------------------------------------------------*/
  480. /* To get here we found a prefix synonym, but no matching original     */
  481. /* command, so return an error.                                        */
  482. /*---------------------------------------------------------------------*/
  483.     curr_ppc->ppc_cmd_idx = (-1);
  484. #ifdef TRACE
  485.     trace_return();
  486. #endif
  487.     return(rc);
  488.    }
  489. /*---------------------------------------------------------------------*/
  490. /* For each valid prefix command,  check to see if a valid command     */
  491. /* exists somewhere in the entered prefix command.                     */
  492. /*---------------------------------------------------------------------*/
  493.  for (i=0;i<NUMBER_PREFIX_COMMANDS;i++)
  494.    {
  495.     pos = memfind(pcmd,pc[i].cmd,len_pcmd,pc[i].cmd_len,TRUE,FALSE,' ',' ');
  496.     if (pos == (-1))
  497.        continue;
  498.     strcpy((DEFCHAR *)cmd,(DEFCHAR *)pc[i].cmd);
  499.     for (j=0;j<pc[i].cmd_len;j++)
  500.        *(pcmd+pos+j) = ' ';
  501.     strtrunc(pcmd);
  502.     strcpy((DEFCHAR *)mult,(DEFCHAR *)pcmd);
  503.     rc = i;
  504. /*---------------------------------------------------------------------*/
  505. /* Set a flag in ppc[] array to indicate which command is present.     */
  506. /*---------------------------------------------------------------------*/
  507.     curr_ppc->ppc_cmd_idx = i;
  508.     break;
  509.    }
  510. /*---------------------------------------------------------------------*/
  511. /* If command not found, set a flag in ppc[] array to indicate command */
  512. /* is invalid.                                                         */
  513. /*---------------------------------------------------------------------*/
  514.  if (rc == PPC_NO_TARGET)
  515.     curr_ppc->ppc_cmd_idx = (-1);
  516. #ifdef TRACE
  517.  trace_return();
  518. #endif
  519.  return(rc);
  520. }
  521. /***********************************************************************/
  522. #ifdef HAVE_PROTO
  523. static short prefix_makecurr(PPC *curr_ppc,short cmd_idx,LINETYPE number_lines)
  524. #else
  525. static short prefix_makecurr(curr_ppc,cmd_idx,number_lines)
  526. PPC *curr_ppc;
  527. short cmd_idx;
  528. LINETYPE number_lines;
  529. #endif
  530. /***********************************************************************/
  531. {
  532. /*-------------------------- external data ----------------------------*/
  533. /*--------------------------- local data ------------------------------*/
  534.  LINETYPE top_line = curr_ppc->ppc_line_number;
  535. /*--------------------------- processing ------------------------------*/
  536.  clear_pending_prefix_command(curr_ppc,(LINE *)NULL);
  537.  execute_makecurr(top_line);
  538.  if (number_lines != 0L)
  539.     CURRENT_VIEW->current_column = (LENGTHTYPE)number_lines;
  540.  return(0);
  541. }
  542. /***********************************************************************/
  543. #ifdef HAVE_PROTO
  544. static short prefix_tabline(PPC *curr_ppc,short cmd_idx,LINETYPE number_lines)
  545. #else
  546. static short prefix_tabline(curr_ppc,cmd_idx,number_lines)
  547. PPC *curr_ppc;
  548. short cmd_idx;
  549. LINETYPE number_lines;
  550. #endif
  551. /***********************************************************************/
  552. {
  553. /*-------------------------- external data ----------------------------*/
  554. /*--------------------------- local data ------------------------------*/
  555.  LINETYPE top_line = curr_ppc->ppc_line_number;
  556.  short tab_row = 0;
  557. /*--------------------------- processing ------------------------------*/
  558.  if ((tab_row = get_row_for_focus_line(current_screen,top_line,(-1))) != (-1))
  559.    {
  560.     CURRENT_VIEW->tab_base = POSITION_TOP;
  561.     CURRENT_VIEW->tab_off = tab_row+1;
  562.     CURRENT_VIEW->tab_on = TRUE;
  563.    }
  564.  clear_pending_prefix_command(curr_ppc,(LINE *)NULL);
  565.  return(0);
  566. }
  567. /***********************************************************************/
  568. #ifdef HAVE_PROTO
  569. static short prefix_scale(PPC *curr_ppc,short cmd_idx,LINETYPE number_lines)
  570. #else
  571. static short prefix_scale(curr_ppc,cmd_idx,number_lines)
  572. PPC *curr_ppc;
  573. short cmd_idx;
  574. LINETYPE number_lines;
  575. #endif
  576. /***********************************************************************/
  577. {
  578. /*-------------------------- external data ----------------------------*/
  579. /*--------------------------- local data ------------------------------*/
  580.  LINETYPE top_line = curr_ppc->ppc_line_number;
  581.  short scale_row = 0;
  582. /*--------------------------- processing ------------------------------*/
  583.  if ((scale_row = get_row_for_focus_line(current_screen,top_line,(-1))) != (-1))
  584.    {
  585.     CURRENT_VIEW->scale_base = POSITION_TOP;
  586.     CURRENT_VIEW->scale_off = scale_row+1;
  587.     CURRENT_VIEW->scale_on = TRUE;
  588.    }
  589.  clear_pending_prefix_command(curr_ppc,(LINE *)NULL);
  590.  return(0);
  591. }
  592. /***********************************************************************/
  593. #ifdef HAVE_PROTO
  594. static short prefix_show(PPC *curr_ppc,short cmd_idx,LINETYPE number_lines)
  595. #else
  596. static short prefix_show(curr_ppc,cmd_idx,number_lines)
  597. PPC *curr_ppc;
  598. short cmd_idx;
  599. LINETYPE number_lines;
  600. #endif
  601. /***********************************************************************/
  602. {
  603. /*-------------------------- external data ----------------------------*/
  604. /*--------------------------- local data ------------------------------*/
  605.  register int i=0;
  606.  short rc=RC_OK;
  607.  LINETYPE top_line = curr_ppc->ppc_line_number;
  608.  LINETYPE target_line=0L;
  609.  LINE *curr=NULL;
  610. /*--------------------------- processing ------------------------------*/
  611.  clear_pending_prefix_command(curr_ppc,(LINE *)NULL);
  612.  if (TOF(top_line)
  613.  ||  BOF(top_line))
  614.     return(-1);
  615. /*---------------------------------------------------------------------*/
  616. /* Find the current line from where we start showing...                */
  617. /*---------------------------------------------------------------------*/
  618.  curr = lll_find(CURRENT_FILE->first_line,CURRENT_FILE->last_line,top_line,CURRENT_FILE->number_lines);
  619. /*---------------------------------------------------------------------*/
  620. /* If the line that the show command was entered is in scope, then     */
  621. /* return with an error.                                               */
  622. /*---------------------------------------------------------------------*/
  623.  if (in_scope(CURRENT_VIEW,curr))
  624.    {
  625.     invalidate_prefix(curr_ppc);
  626.     return(-1);
  627.    }
  628. /*---------------------------------------------------------------------*/
  629. /* For a negative target, show the lines from the end of the excluded  */
  630. /* block.                                                              */
  631. /*---------------------------------------------------------------------*/
  632.  if (number_lines < 0)
  633.    {
  634.     target_line = find_last_not_in_scope(CURRENT_VIEW,curr,top_line,DIRECTION_FORWARD);
  635.     curr = lll_find(CURRENT_FILE->first_line,CURRENT_FILE->last_line,target_line,CURRENT_FILE->number_lines);
  636.     for(i=0;i>number_lines;i--)
  637.       {
  638.        curr->select = CURRENT_VIEW->display_high;
  639.        curr = curr->prev;
  640.        if (curr->prev == NULL
  641.        ||  in_scope(CURRENT_VIEW,curr))
  642.           break;
  643.       }
  644.    }
  645.  else
  646. /*---------------------------------------------------------------------*/
  647. /* For a positive target, show the lines from the start of the excluded*/
  648. /* block.                                                              */
  649. /*---------------------------------------------------------------------*/
  650.    {
  651.     for(i=0;i<number_lines;i++)
  652.       {
  653.        curr->select = CURRENT_VIEW->display_high;
  654.        curr = curr->next;
  655.        if (curr->next == NULL
  656.        ||  in_scope(CURRENT_VIEW,curr))
  657.           break;
  658.       }
  659.    }
  660.  return(rc);
  661. }
  662. /***********************************************************************/
  663. #ifdef HAVE_PROTO
  664. static short prefix_exclude(PPC *curr_ppc,short cmd_idx,LINETYPE number_lines)
  665. #else
  666. static short prefix_exclude(curr_ppc,cmd_idx,number_lines)
  667. PPC *curr_ppc;
  668. short cmd_idx;
  669. LINETYPE number_lines;
  670. #endif
  671. /***********************************************************************/
  672. {
  673. /*-------------------------- external data ----------------------------*/
  674. /*--------------------------- local data ------------------------------*/
  675.  short rc=RC_OK;
  676.  LINETYPE top_line = curr_ppc->ppc_line_number;
  677.  LINE *curr=NULL;
  678.  short direction=DIRECTION_FORWARD;
  679. /*--------------------------- processing ------------------------------*/
  680.  clear_pending_prefix_command(curr_ppc,(LINE *)NULL);
  681.  if (TOF(top_line)
  682.  ||  BOF(top_line))
  683.     return(-1);
  684. /*---------------------------------------------------------------------*/
  685. /* If the high value of SET DISPLAY is 255, we can't exclude any lines */
  686. /* so exit.                                                            */
  687. /*---------------------------------------------------------------------*/
  688.  if (CURRENT_VIEW->display_high == 255)
  689.     return(rc);
  690.  if (number_lines < 0)
  691.     direction = DIRECTION_BACKWARD;
  692.  else
  693.     direction = DIRECTION_FORWARD;
  694. /*---------------------------------------------------------------------*/
  695. /* Find the current line from where we start excluding...              */
  696. /*---------------------------------------------------------------------*/
  697.  curr = lll_find(CURRENT_FILE->first_line,CURRENT_FILE->last_line,top_line,CURRENT_FILE->number_lines);
  698. /*---------------------------------------------------------------------*/
  699. /* For the number of lines affected, change the select level if the    */
  700. /* line is in scope.                                                   */
  701. /*---------------------------------------------------------------------*/
  702.  while(number_lines != 0)
  703.    {
  704.     if (in_scope(CURRENT_VIEW,curr))
  705.        curr->select = (short)CURRENT_VIEW->display_high + 1;
  706.     if (direction == DIRECTION_FORWARD)
  707.        curr = curr->next;
  708.     else
  709.        curr = curr->prev;
  710.     number_lines -= direction;
  711.    }
  712. /*---------------------------------------------------------------------*/
  713. /* Determine if current line is now not in scope...                    */
  714. /*---------------------------------------------------------------------*/
  715.  curr = lll_find(CURRENT_FILE->first_line,CURRENT_FILE->last_line,CURRENT_VIEW->current_line,CURRENT_FILE->number_lines);
  716.  if (!in_scope(CURRENT_VIEW,curr))
  717.     CURRENT_VIEW->current_line = find_next_in_scope(CURRENT_VIEW,curr,CURRENT_VIEW->current_line,DIRECTION_FORWARD);
  718.  return(rc);
  719. }
  720. /***********************************************************************/
  721. #ifdef HAVE_PROTO
  722. static short prefix_add(PPC *curr_ppc,short cmd_idx,LINETYPE number_lines)
  723. #else
  724. static short prefix_add(curr_ppc,cmd_idx,number_lines)
  725. PPC *curr_ppc;
  726. short cmd_idx;
  727. LINETYPE number_lines;
  728. #endif
  729. /***********************************************************************/
  730. {
  731. /*-------------------------- external data ----------------------------*/
  732. /*--------------------------- local data ------------------------------*/
  733.  short rc=(-1);
  734.  LINETYPE top_line = curr_ppc->ppc_line_number;
  735. /*--------------------------- processing ------------------------------*/
  736.  if (top_line == CURRENT_FILE->number_lines+1)
  737.     top_line--;
  738.  clear_pending_prefix_command(curr_ppc,(LINE *)NULL);
  739.  rc = insert_new_line((CHARTYPE *)"",0,number_lines,
  740.                      top_line,FALSE,FALSE,TRUE,CURRENT_VIEW->display_low,FALSE,FALSE);
  741.  return(rc);
  742. }
  743. /***********************************************************************/
  744. #ifdef HAVE_PROTO
  745. static short prefix_duplicate(PPC *curr_ppc,short cmd_idx,LINETYPE number_occ)
  746. #else
  747. static short prefix_duplicate(curr_ppc,cmd_idx,number_occ)
  748. PPC *curr_ppc;
  749. short cmd_idx;
  750. LINETYPE number_occ;
  751. #endif
  752. /***********************************************************************/
  753. {
  754. /*-------------------------- external data ----------------------------*/
  755. /*--------------------------- local data ------------------------------*/
  756.  short rc=(-1);
  757.  LINETYPE top_line = curr_ppc->ppc_line_number;
  758.  LINETYPE lines_affected=0L;
  759. /*--------------------------- processing ------------------------------*/
  760.  clear_pending_prefix_command(curr_ppc,(LINE *)NULL);
  761.  if (top_line != 0L
  762.  &&  top_line != CURRENT_FILE->number_lines+1)
  763.     rc = rearrange_line_blocks(COMMAND_DUPLICATE,SOURCE_PREFIX,top_line,
  764.                               top_line,top_line,(short)number_occ,
  765.                               CURRENT_VIEW,CURRENT_VIEW,TRUE,&lines_affected);
  766.  return(rc);
  767. }
  768. /***********************************************************************/
  769. #ifdef HAVE_PROTO
  770. static short prefix_copy(PPC *curr_ppc,short cmd_idx,LINETYPE number_lines)
  771. #else
  772. static short prefix_copy(curr_ppc,cmd_idx,number_lines)
  773. PPC *curr_ppc;
  774. short cmd_idx;
  775. LINETYPE number_lines;
  776. #endif
  777. /***********************************************************************/
  778. {
  779. /*-------------------------- external data ----------------------------*/
  780. /*--------------------------- local data ------------------------------*/
  781.  LINETYPE bottom_line=0L,target_line=0L,lines_affected=0L;
  782.  LINETYPE top_line = curr_ppc->ppc_line_number;
  783.  PPC *target_ppc=NULL;
  784.  short rc=(-1);
  785. /*--------------------------- processing ------------------------------*/
  786.  if ((target_ppc = calculate_target_line()) == NULL)
  787.     return(rc);
  788.  target_line = target_ppc->ppc_line_number+target_ppc->ppc_cmd_param;
  789.  bottom_line = top_line + number_lines - ((number_lines < 0L) ? (-1L) : 1L);
  790.  clear_pending_prefix_command(curr_ppc,(LINE *)NULL);
  791.  if (top_line != 0L
  792.  &&  top_line != CURRENT_FILE->number_lines+1)
  793.     rc = rearrange_line_blocks(COMMAND_COPY,SOURCE_PREFIX,top_line,bottom_line,
  794.                               target_line,1,CURRENT_VIEW,CURRENT_VIEW,TRUE,
  795.                               &lines_affected);
  796.  return(rc);
  797. }
  798. /***********************************************************************/
  799. #ifdef HAVE_PROTO
  800. static short prefix_move(PPC *curr_ppc,short cmd_idx,LINETYPE number_lines)
  801. #else
  802. static short prefix_move(curr_ppc,cmd_idx,number_lines)
  803. PPC *curr_ppc;
  804. short cmd_idx;
  805. LINETYPE number_lines;
  806. #endif
  807. /***********************************************************************/
  808. {
  809. /*-------------------------- external data ----------------------------*/
  810. /*--------------------------- local data ------------------------------*/
  811.  LINETYPE bottom_line=0L,target_line=0L,lines_affected=0L;
  812.  LINETYPE top_line = curr_ppc->ppc_line_number;
  813.  PPC *target_ppc=NULL;
  814.  short rc=(-1);
  815. /*--------------------------- processing ------------------------------*/
  816.  if ((target_ppc = calculate_target_line()) == NULL)
  817.     return(rc);
  818.  target_line = target_ppc->ppc_line_number+target_ppc->ppc_cmd_param;
  819.  clear_pending_prefix_command(curr_ppc,(LINE *)NULL);
  820.  bottom_line = top_line + number_lines - ((number_lines < 0L) ? (-1L) : 1L);
  821.  
  822.  if (top_line != 0L
  823.  &&  top_line != CURRENT_FILE->number_lines+1)
  824.    {
  825.     if ((rc = rearrange_line_blocks(COMMAND_MOVE_COPY_SAME,SOURCE_PREFIX,
  826.          top_line,bottom_line,target_line,1,CURRENT_VIEW,CURRENT_VIEW,TRUE,&lines_affected)) != RC_OK)
  827.        return(rc);
  828.     if (target_line < top_line)
  829.       {
  830.        top_line += number_lines;
  831.        target_line += number_lines;
  832.        bottom_line += number_lines;
  833.       }
  834.     rc = rearrange_line_blocks(COMMAND_MOVE_DELETE_SAME,SOURCE_PREFIX,top_line,
  835.                               bottom_line,target_line,1,CURRENT_VIEW,CURRENT_VIEW,TRUE,
  836.                               &lines_affected);
  837.    }
  838.  return(rc);
  839. }
  840. /***********************************************************************/
  841. #ifdef HAVE_PROTO
  842. static short prefix_delete(PPC *curr_ppc,short cmd_idx,LINETYPE number_lines)
  843. #else
  844. static short prefix_delete(curr_ppc,cmd_idx,number_lines)
  845. PPC *curr_ppc;
  846. short cmd_idx;
  847. LINETYPE number_lines;
  848. #endif
  849. /***********************************************************************/
  850. {
  851. /*-------------------------- external data ----------------------------*/
  852. /*--------------------------- local data ------------------------------*/
  853.  short rc=(-1);
  854.  LINETYPE top_line = curr_ppc->ppc_line_number;
  855.  LINETYPE bottom_line=0L,target_line=0L,lines_affected=0L;
  856. /*--------------------------- processing ------------------------------*/
  857.  
  858.  clear_pending_prefix_command(curr_ppc,(LINE *)NULL);
  859.  if (!TOF(top_line)
  860.  &&  !BOF(top_line))
  861.    {
  862.     bottom_line = top_line + number_lines - ((number_lines < 0L) ? (-1L) : 1L);
  863.     target_line = (number_lines < 0L) ? (bottom_line) : (top_line);
  864.     rc = rearrange_line_blocks(COMMAND_DELETE,SOURCE_PREFIX,top_line,bottom_line,
  865.                               target_line,1,CURRENT_VIEW,CURRENT_VIEW,TRUE,
  866.                               &lines_affected);
  867.    }
  868.  return(rc);
  869. }
  870. /***********************************************************************/
  871. #ifdef HAVE_PROTO
  872. static short prefix_shift_left(PPC *curr_ppc,short cmd_idx,LINETYPE number_cols)
  873. #else
  874. static short prefix_shift_left(curr_ppc,cmd_idx,number_cols)
  875. PPC *curr_ppc;
  876. short cmd_idx;
  877. LINETYPE number_cols;
  878. #endif
  879. /***********************************************************************/
  880. {
  881. /*-------------------------- external data ----------------------------*/
  882. /*--------------------------- local data ------------------------------*/
  883.  LINETYPE top_line = curr_ppc->ppc_line_number;
  884. /*--------------------------- processing ------------------------------*/
  885.  clear_pending_prefix_command(curr_ppc,(LINE *)NULL);
  886.  if (top_line != 0L
  887.  &&  top_line != CURRENT_FILE->number_lines+1)
  888.    {
  889.     execute_shift_command(TRUE,(short)number_cols,top_line,1L,TRUE,TARGET_UNFOUND,FALSE);
  890.    }
  891.  return(0);
  892. }
  893. /***********************************************************************/
  894. #ifdef HAVE_PROTO
  895. static short prefix_shift_right(PPC *curr_ppc,short cmd_idx,LINETYPE number_cols)
  896. #else
  897. static short prefix_shift_right(curr_ppc,cmd_idx,number_cols)
  898. PPC *curr_ppc;
  899. short cmd_idx;
  900. LINETYPE number_cols;
  901. #endif
  902. /***********************************************************************/
  903. {
  904. /*-------------------------- external data ----------------------------*/
  905. /*--------------------------- local data ------------------------------*/
  906.  LINETYPE start_line = curr_ppc->ppc_line_number;
  907. /*--------------------------- processing ------------------------------*/
  908.  clear_pending_prefix_command(curr_ppc,(LINE *)NULL);
  909.  if (start_line != 0L
  910.  &&  start_line != CURRENT_FILE->number_lines+1)
  911.    {
  912.     execute_shift_command(FALSE,(short)number_cols,start_line,1L,TRUE,TARGET_UNFOUND,FALSE);
  913.    }
  914.  return(0);
  915. }
  916. /***********************************************************************/
  917. #ifdef HAVE_PROTO
  918. static short prefix_block_duplicate(PPC *curr_ppc,short cmd_idx,LINETYPE number_occ)
  919. #else
  920. static short prefix_block_duplicate(curr_ppc,cmd_idx,number_occ)
  921. PPC *curr_ppc;
  922. short cmd_idx;
  923. LINETYPE number_occ;
  924. #endif
  925. /***********************************************************************/
  926. {
  927. /*-------------------------- external data ----------------------------*/
  928. /*--------------------------- local data ------------------------------*/
  929.  short rc=(-1);
  930.  LINETYPE top_line=0L,bottom_line=0L,lines_affected=0L;
  931.  PPC *bottom_ppc=NULL;
  932. /*--------------------------- processing ------------------------------*/
  933.  if ((bottom_ppc = find_bottom_ppc(curr_ppc,cmd_idx)) == NULL)
  934.     return(rc);
  935.  top_line = min(curr_ppc->ppc_line_number,bottom_ppc->ppc_line_number);
  936.  bottom_line = max(curr_ppc->ppc_line_number,bottom_ppc->ppc_line_number);
  937.  top_line = (top_line == 0L) ? 1L : top_line;
  938.  bottom_line = (bottom_line == CURRENT_FILE->number_lines+1L) ? bottom_line-1L : bottom_line;
  939.  clear_pending_prefix_command(curr_ppc,(LINE *)NULL);
  940.  clear_pending_prefix_command(bottom_ppc,(LINE *)NULL);
  941.  rc = rearrange_line_blocks(COMMAND_DUPLICATE,SOURCE_PREFIX,top_line,bottom_line,
  942.                            bottom_line,(short)number_occ,CURRENT_VIEW,CURRENT_VIEW,FALSE,
  943.                            &lines_affected);
  944.  return(rc);
  945. }
  946. /***********************************************************************/
  947. #ifdef HAVE_PROTO
  948. static short prefix_block_copy(PPC *curr_ppc,short cmd_idx,LINETYPE number_lines)
  949. #else
  950. static short prefix_block_copy(curr_ppc,cmd_idx,number_lines)
  951. PPC *curr_ppc;
  952. short cmd_idx;
  953. LINETYPE number_lines;
  954. #endif
  955. /***********************************************************************/
  956. {
  957. /*-------------------------- external data ----------------------------*/
  958. /*--------------------------- local data ------------------------------*/
  959.  short rc=(-1);
  960.  LINETYPE top_line=0L,bottom_line=0L,target_line=0L,lines_affected=0L;
  961.  PPC *bottom_ppc=NULL;
  962.  PPC *target_ppc=NULL;
  963. /*--------------------------- processing ------------------------------*/
  964.  if ((bottom_ppc = find_bottom_ppc(curr_ppc,cmd_idx)) == NULL)
  965.     return(rc);
  966.  if ((target_ppc = calculate_target_line()) == NULL)
  967.     return(rc);
  968.  target_line = target_ppc->ppc_line_number+target_ppc->ppc_cmd_param;
  969.  top_line = min(curr_ppc->ppc_line_number,bottom_ppc->ppc_line_number);
  970.  bottom_line = max(curr_ppc->ppc_line_number,bottom_ppc->ppc_line_number);
  971.  top_line = (top_line == 0L) ? 1L : top_line;
  972.  bottom_line = (bottom_line == CURRENT_FILE->number_lines+1L) ? bottom_line-1L : bottom_line;
  973.  clear_pending_prefix_command(curr_ppc,(LINE *)NULL);
  974.  clear_pending_prefix_command(bottom_ppc,(LINE *)NULL);
  975.  rc = rearrange_line_blocks(COMMAND_COPY,SOURCE_PREFIX,top_line,bottom_line,
  976.                            target_line,1,CURRENT_VIEW,CURRENT_VIEW,FALSE,
  977.                            &lines_affected);
  978.  return(rc);
  979. }
  980. /***********************************************************************/
  981. #ifdef HAVE_PROTO
  982. static short prefix_block_move(PPC *curr_ppc,short cmd_idx,LINETYPE number_lines)
  983. #else
  984. static short prefix_block_move(curr_ppc,cmd_idx,number_lines)
  985. PPC *curr_ppc;
  986. short cmd_idx;
  987. LINETYPE number_lines;
  988. #endif
  989. /***********************************************************************/
  990. {
  991. /*-------------------------- external data ----------------------------*/
  992. /*--------------------------- local data ------------------------------*/
  993.  short rc=(-1);
  994.  LINETYPE top_line=0L,bottom_line=0L,target_line=0L,num_lines=0L,lines_affected=0L;
  995.  PPC *bottom_ppc=NULL;
  996.  PPC *target_ppc=NULL;
  997. /*--------------------------- processing ------------------------------*/
  998.  if ((bottom_ppc = find_bottom_ppc(curr_ppc,cmd_idx)) == NULL)
  999.     return(rc);
  1000.  if ((target_ppc = calculate_target_line()) == NULL)
  1001.     return(rc);
  1002.  target_line = target_ppc->ppc_line_number+target_ppc->ppc_cmd_param;
  1003.  top_line = min(curr_ppc->ppc_line_number,bottom_ppc->ppc_line_number);
  1004.  bottom_line = max(curr_ppc->ppc_line_number,bottom_ppc->ppc_line_number);
  1005.  top_line = (top_line == 0L) ? 1L : top_line;
  1006.  bottom_line = (bottom_line == CURRENT_FILE->number_lines+1L) ? bottom_line-1L : bottom_line;
  1007.  clear_pending_prefix_command(curr_ppc,(LINE *)NULL);
  1008.  clear_pending_prefix_command(bottom_ppc,(LINE *)NULL);
  1009.  if ((rc = rearrange_line_blocks(COMMAND_MOVE_COPY_SAME,SOURCE_PREFIX,
  1010.            top_line,bottom_line,target_line,1,CURRENT_VIEW,CURRENT_VIEW,FALSE,&lines_affected)) != RC_OK)
  1011.     return(rc);
  1012.  if (target_line < top_line)
  1013.    {
  1014.     num_lines = bottom_line - top_line + 1L;
  1015.     top_line += num_lines;
  1016.     bottom_line += num_lines;
  1017.     target_line += num_lines;
  1018.    }
  1019.  rc = rearrange_line_blocks(COMMAND_MOVE_DELETE_SAME,SOURCE_PREFIX,top_line,bottom_line,
  1020.                            target_line,1,CURRENT_VIEW,CURRENT_VIEW,FALSE,
  1021.                            &lines_affected);
  1022.  return(rc);
  1023. }
  1024. /***********************************************************************/
  1025. #ifdef HAVE_PROTO
  1026. static short prefix_block_delete(PPC *curr_ppc,short cmd_idx,LINETYPE number_lines)
  1027. #else
  1028. static short prefix_block_delete(curr_ppc,cmd_idx,number_lines)
  1029. PPC *curr_ppc;
  1030. short cmd_idx;
  1031. LINETYPE number_lines;
  1032. #endif
  1033. /***********************************************************************/
  1034. {
  1035. /*-------------------------- external data ----------------------------*/
  1036. /*--------------------------- local data ------------------------------*/
  1037.  short rc=(-1);
  1038.  LINETYPE top_line=0L,bottom_line=0L,lines_affected=0L;
  1039.  PPC *bottom_ppc=NULL;
  1040. /*--------------------------- processing ------------------------------*/
  1041.  if ((bottom_ppc = find_bottom_ppc(curr_ppc,cmd_idx)) == NULL)
  1042.     return(rc);
  1043.  top_line = min(curr_ppc->ppc_line_number,bottom_ppc->ppc_line_number);
  1044.  bottom_line = max(curr_ppc->ppc_line_number,bottom_ppc->ppc_line_number);
  1045.  top_line = (top_line == 0L) ? 1L : top_line;
  1046.  bottom_line = (bottom_line == CURRENT_FILE->number_lines+1L) ? bottom_line-1L : bottom_line;
  1047.  clear_pending_prefix_command(curr_ppc,(LINE *)NULL);
  1048.  clear_pending_prefix_command(bottom_ppc,(LINE *)NULL);
  1049.  rc = rearrange_line_blocks(COMMAND_DELETE,SOURCE_PREFIX,top_line,bottom_line,
  1050.                            bottom_line,1,CURRENT_VIEW,CURRENT_VIEW,FALSE,
  1051.                            &lines_affected);
  1052.  return(rc);
  1053. }
  1054. /***********************************************************************/
  1055. #ifdef HAVE_PROTO
  1056. static short prefix_block_shift_left(PPC *curr_ppc,short cmd_idx,LINETYPE number_cols)
  1057. #else
  1058. static short prefix_block_shift_left(curr_ppc,cmd_idx,number_cols)
  1059. PPC *curr_ppc;
  1060. short cmd_idx;
  1061. LINETYPE number_cols;
  1062. #endif
  1063. /***********************************************************************/
  1064. {
  1065. /*-------------------------- external data ----------------------------*/
  1066. /*--------------------------- local data ------------------------------*/
  1067.  LINETYPE top_line=0L,bottom_line=0L;
  1068.  PPC *bottom_ppc=NULL;
  1069. /*--------------------------- processing ------------------------------*/
  1070.  if ((bottom_ppc = find_bottom_ppc(curr_ppc,cmd_idx)) == NULL)
  1071.     return(-1);
  1072.  top_line = min(curr_ppc->ppc_line_number,bottom_ppc->ppc_line_number);
  1073.  bottom_line = max(curr_ppc->ppc_line_number,bottom_ppc->ppc_line_number);
  1074.  
  1075.  top_line = (top_line == 0L) ? 1L : top_line;
  1076.  bottom_line = (bottom_line == CURRENT_FILE->number_lines+1L) ? bottom_line-1L : bottom_line;
  1077.  clear_pending_prefix_command(curr_ppc,(LINE *)NULL);
  1078.  clear_pending_prefix_command(bottom_ppc,(LINE *)NULL);
  1079.  
  1080.  execute_shift_command(TRUE,(short)number_cols,top_line,bottom_line-top_line+1L,FALSE,TARGET_UNFOUND,FALSE);
  1081.  
  1082.  return(0);
  1083. }
  1084. /***********************************************************************/
  1085. #ifdef HAVE_PROTO
  1086. static short prefix_block_shift_right(PPC *curr_ppc,short cmd_idx,LINETYPE number_cols)
  1087. #else
  1088. static short prefix_block_shift_right(curr_ppc,cmd_idx,number_cols)
  1089. PPC *curr_ppc;
  1090. short cmd_idx;
  1091. LINETYPE number_cols;
  1092. #endif
  1093. /***********************************************************************/
  1094. {
  1095. /*-------------------------- external data ----------------------------*/
  1096. /*--------------------------- local data ------------------------------*/
  1097.  LINETYPE top_line=0L,bottom_line=0L;
  1098.  PPC *bottom_ppc=NULL;
  1099. /*--------------------------- processing ------------------------------*/
  1100.  if ((bottom_ppc = find_bottom_ppc(curr_ppc,cmd_idx)) == NULL)
  1101.     return(-1);
  1102.  top_line = min(curr_ppc->ppc_line_number,bottom_ppc->ppc_line_number);
  1103.  bottom_line = max(curr_ppc->ppc_line_number,bottom_ppc->ppc_line_number);
  1104.  
  1105.  top_line = (top_line == 0L) ? 1L : top_line;
  1106.  bottom_line = (bottom_line == CURRENT_FILE->number_lines+1L) ? bottom_line-1L : bottom_line;
  1107.  clear_pending_prefix_command(curr_ppc,(LINE *)NULL);
  1108.  clear_pending_prefix_command(bottom_ppc,(LINE *)NULL);
  1109.  
  1110.  execute_shift_command(FALSE,(short)number_cols,top_line,bottom_line-top_line+1L,FALSE,TARGET_UNFOUND,FALSE);
  1111.  
  1112.  return(0);
  1113. }
  1114. /***********************************************************************/
  1115. #ifdef HAVE_PROTO
  1116. static short prefix_block_exclude(PPC *curr_ppc,short cmd_idx,LINETYPE number_lines)
  1117. #else
  1118. static short prefix_block_exclude(curr_ppc,cmd_idx,number_lines)
  1119. PPC *curr_ppc;
  1120. short cmd_idx;
  1121. LINETYPE number_lines;
  1122. #endif
  1123. /***********************************************************************/
  1124. {
  1125. /*-------------------------- external data ----------------------------*/
  1126. /*--------------------------- local data ------------------------------*/
  1127.  short rc=RC_OK;
  1128.  LINETYPE top_line=0L,bottom_line=0L,num_lines=0L,i=0L;
  1129.  LINE *curr=NULL;
  1130.  PPC *bottom_ppc=NULL;
  1131. /*--------------------------- processing ------------------------------*/
  1132.  if ((bottom_ppc = find_bottom_ppc(curr_ppc,cmd_idx)) == NULL)
  1133.     return(-1);
  1134.  top_line = min(curr_ppc->ppc_line_number,bottom_ppc->ppc_line_number);
  1135.  bottom_line = max(curr_ppc->ppc_line_number,bottom_ppc->ppc_line_number);
  1136.  top_line = (top_line == 0L) ? 1L : top_line;
  1137.  bottom_line = (bottom_line == CURRENT_FILE->number_lines+1L) ? bottom_line-1L : bottom_line;
  1138.  num_lines = bottom_line-top_line+1L;
  1139.  clear_pending_prefix_command(curr_ppc,(LINE *)NULL);
  1140.  clear_pending_prefix_command(bottom_ppc,(LINE *)NULL);
  1141. /*---------------------------------------------------------------------*/
  1142. /* If the high value of SET DISPLAY is 255, we can't exclude any lines */
  1143. /* so exit.                                                            */
  1144. /*---------------------------------------------------------------------*/
  1145.  if (CURRENT_VIEW->display_high == 255)
  1146.     return(rc);
  1147. /*---------------------------------------------------------------------*/
  1148. /* Find the current line from where we start excluding...              */
  1149. /*---------------------------------------------------------------------*/
  1150.  curr = lll_find(CURRENT_FILE->first_line,CURRENT_FILE->last_line,top_line,CURRENT_FILE->number_lines);
  1151. /*---------------------------------------------------------------------*/
  1152. /* For the number of lines affected, change the select level if the    */
  1153. /* line is in scope.                                                   */
  1154. /*---------------------------------------------------------------------*/
  1155.  for (i=0;i<num_lines;i++)
  1156.    {
  1157.     if (in_scope(CURRENT_VIEW,curr))
  1158.        curr->select = (short)CURRENT_VIEW->display_high + 1;
  1159.     curr = curr->next;
  1160.    }
  1161. /*---------------------------------------------------------------------*/
  1162. /* Determine if current line is now not in scope...                    */
  1163. /*---------------------------------------------------------------------*/
  1164.  curr = lll_find(CURRENT_FILE->first_line,CURRENT_FILE->last_line,CURRENT_VIEW->current_line,CURRENT_FILE->number_lines);
  1165.  if (!in_scope(CURRENT_VIEW,curr))
  1166.     CURRENT_VIEW->current_line = find_next_in_scope(CURRENT_VIEW,curr,CURRENT_VIEW->current_line,DIRECTION_FORWARD);
  1167.  return(rc);
  1168. }
  1169. /***********************************************************************/
  1170. #ifdef HAVE_PROTO
  1171. static short invalidate_prefix(PPC *curr_ppc)
  1172. #else
  1173. static short invalidate_prefix(curr_ppc)
  1174. PPC *curr_ppc;
  1175. #endif
  1176. /***********************************************************************/
  1177. {
  1178. /*-------------------------- external data ----------------------------*/
  1179. /*--------------------------- local data ------------------------------*/
  1180.  short len=0;
  1181. /*--------------------------- processing ------------------------------*/
  1182.  if (*(curr_ppc->ppc_command) != '?')
  1183.    {
  1184.     len = strlen((DEFCHAR *)curr_ppc->ppc_command);
  1185.     meminschr(curr_ppc->ppc_command,'?',0,CURRENT_VIEW->prefix_width,len);
  1186.     *(curr_ppc->ppc_command+len+1) = '\0';
  1187.    }
  1188. /*---------------------------------------------------------------------*/
  1189. /* ensure that there is no chance that a 'real' prefix command can be  */
  1190. /* executed.                                                           */
  1191. /*---------------------------------------------------------------------*/
  1192.  curr_ppc->ppc_cmd_idx = (-2);
  1193.  return(RC_OK);
  1194. }
  1195. /***********************************************************************/
  1196. #ifdef HAVE_PROTO
  1197. void clear_pending_prefix_command(PPC *curr_ppc,LINE *curr_line)
  1198. #else
  1199. void clear_pending_prefix_command(curr_ppc,curr_line)
  1200. PPC *curr_ppc;
  1201. LINE *curr_line;
  1202. #endif
  1203. /***********************************************************************/
  1204. {
  1205. /*-------------------------- external data ----------------------------*/
  1206. /*--------------------------- local data ------------------------------*/
  1207.  LINE *curr=curr_line;
  1208. /*--------------------------- processing ------------------------------*/
  1209. /*---------------------------------------------------------------------*/
  1210. /* If curr_ppc == NULL, then do nothing.                               */
  1211. /*---------------------------------------------------------------------*/
  1212.  if (curr_ppc == NULL)
  1213.     return;
  1214.  if (curr == (LINE *)NULL)
  1215.     curr = lll_find(CURRENT_FILE->first_line,CURRENT_FILE->last_line,curr_ppc->ppc_line_number,CURRENT_FILE->number_lines);
  1216.  curr->pre = NULL;
  1217.  curr_ppc->ppc_cmd_idx = (-1);
  1218.  curr_ppc->ppc_block_command = FALSE;
  1219.  curr_ppc->ppc_shadow_line = FALSE;
  1220.  return;
  1221. }
  1222. /***********************************************************************/
  1223. #ifdef HAVE_PROTO
  1224. PPC *delete_pending_prefix_command(PPC *curr_ppc,FILE_DETAILS *curr_file,LINE *curr_line)
  1225. #else
  1226. PPC *delete_pending_prefix_command(curr_ppc,curr_file,curr_line)
  1227. PPC *curr_ppc;
  1228. FILE_DETAILS *curr_file;
  1229. LINE *curr_line;
  1230. #endif
  1231. /***********************************************************************/
  1232. {
  1233. /*-------------------------- external data ----------------------------*/
  1234. /*--------------------------- local data ------------------------------*/
  1235.  LINE *curr=curr_line;
  1236.  PPC *return_ppc=NULL;
  1237. /*--------------------------- processing ------------------------------*/
  1238. /*---------------------------------------------------------------------*/
  1239. /* If curr_ppc == NULL, then do nothing.                               */
  1240. /*---------------------------------------------------------------------*/
  1241.  if (curr_ppc == NULL)
  1242.     return(NULL);
  1243.  if (curr == (LINE *)NULL)
  1244.     curr = lll_find(curr_file->first_line,curr_file->last_line,curr_ppc->ppc_line_number,curr_file->number_lines);
  1245.  curr->pre = NULL;
  1246.  return_ppc = pll_del(&(curr_file->first_ppc),&(curr_file->last_ppc),curr_ppc,DIRECTION_FORWARD);
  1247.  return(return_ppc);
  1248. }
  1249. /***********************************************************************/
  1250. #ifdef HAVE_PROTO
  1251. static PPC *find_bottom_ppc(PPC *curr_ppc,short top_cmd_idx)
  1252. #else
  1253. static PPC *find_bottom_ppc(curr_ppc,top_cmd_idx)
  1254. PPC *curr_ppc;
  1255. short top_cmd_idx;
  1256. #endif
  1257. /***********************************************************************/
  1258. {
  1259. /*-------------------------- external data ----------------------------*/
  1260. /*--------------------------- local data ------------------------------*/
  1261.  PPC *bottom_ppc=curr_ppc;
  1262. /*--------------------------- processing ------------------------------*/
  1263.  while(bottom_ppc != NULL)
  1264.    {
  1265.     if (bottom_ppc != curr_ppc)
  1266.       {
  1267.        if (top_cmd_idx == bottom_ppc->ppc_cmd_idx)
  1268.           return(bottom_ppc);
  1269.       }
  1270.     bottom_ppc = bottom_ppc->next;
  1271.    }
  1272.  return(NULL);
  1273. }
  1274. /***********************************************************************/
  1275. #ifdef HAVE_PROTO
  1276. static PPC *find_target_ppc(void)
  1277. #else
  1278. static PPC *find_target_ppc()
  1279. #endif
  1280. /***********************************************************************/
  1281. {
  1282. /*-------------------------- external data ----------------------------*/
  1283. /*--------------------------- local data ------------------------------*/
  1284.  PPC *target_ppc=NULL;
  1285. /*--------------------------- processing ------------------------------*/
  1286.  target_ppc = CURRENT_FILE->first_ppc;
  1287.  while(target_ppc != NULL)
  1288.    {
  1289.     if (target_ppc->ppc_cmd_idx == PPC_TARGET_PREVIOUS
  1290.     ||  target_ppc->ppc_cmd_idx == PPC_TARGET_FOLLOWING)
  1291.        return(target_ppc);
  1292.     target_ppc = target_ppc->next;
  1293.    }
  1294.  return(NULL);
  1295. }
  1296. /***********************************************************************/
  1297. #ifdef HAVE_PROTO
  1298. static PPC *calculate_target_line(void)
  1299. #else
  1300. static PPC *calculate_target_line()
  1301. #endif
  1302. /***********************************************************************/
  1303. {
  1304. /*-------------------------- external data ----------------------------*/
  1305. /*--------------------------- local data ------------------------------*/
  1306.  PPC *target_ppc=NULL;
  1307. /*--------------------------- processing ------------------------------*/
  1308.  if ((target_ppc = find_target_ppc()) == NULL)
  1309.     return(NULL);
  1310.  target_ppc->ppc_cmd_param = 0L;
  1311. /*---------------------------------------------------------------------*/
  1312. /* If the target line is NOT top of file line and the target type is   */
  1313. /* PREVIOUS, subtract 1 from the target line.                          */
  1314. /*---------------------------------------------------------------------*/
  1315.  if (target_ppc->ppc_cmd_idx == PPC_TARGET_PREVIOUS
  1316.  && !TOF(target_ppc->ppc_line_number))
  1317.     target_ppc->ppc_cmd_param = (-1);
  1318. /*---------------------------------------------------------------------*/
  1319. /* If the target line is the bottom of file and the target type is     */
  1320. /* FOLLOWING, sutract 1 from the target line.                          */
  1321. /*---------------------------------------------------------------------*/
  1322.  if (target_ppc->ppc_cmd_idx == PPC_TARGET_FOLLOWING
  1323.  && BOF(target_ppc->ppc_line_number))
  1324.     target_ppc->ppc_cmd_param = (-1);
  1325.  clear_pending_prefix_command(target_ppc,(LINE *)NULL);
  1326.  return(target_ppc);
  1327. }
  1328. /***********************************************************************/
  1329. #ifdef HAVE_PROTO
  1330. static short try_rexx_prefix_macro(PPC *curr_ppc)
  1331. #else
  1332. static short try_rexx_prefix_macro(curr_ppc)
  1333. PPC *curr_ppc;
  1334. #endif
  1335. /***********************************************************************/
  1336. {
  1337. /*-------------------------- external data ----------------------------*/
  1338.  extern CHARTYPE *temp_cmd;
  1339. /*--------------------------- local data ------------------------------*/
  1340.  short ctr=0, parm_length=0, pmacro_rc=0, errnum = 0 ;
  1341.  bool found_left=FALSE, found_right=FALSE;
  1342.  LINETYPE line_number=0L;
  1343.  CHARTYPE pm_parms[(MAX_PREFIX_WIDTH*4)+1], t_area[MAX_PREFIX_WIDTH+1],
  1344.       parms[MAX_PREFIX_WIDTH+1], tmpstr[MAX_PREFIX_WIDTH+1],
  1345.       orig_cmd[MAX_PREFIX_WIDTH+1];
  1346.  short macrorc=0;
  1347. /*--------------------------- processing ------------------------------*/
  1348.  strcpy((DEFCHAR *)orig_cmd,(DEFCHAR *)curr_ppc->ppc_command);
  1349.  
  1350.  found_right = FALSE;
  1351.  found_left = FALSE;
  1352. /*---------------------------------------------------------------------*/
  1353. /* Scan 'orig_cmd' from right to left looking for an embedded macro    */
  1354. /* file name.                                                          */
  1355. /*---------------------------------------------------------------------*/
  1356.  for (ctr = strlen((DEFCHAR *)orig_cmd); ctr >= 0 && !found_right; ctr--)
  1357.    {
  1358.     substr(&tmpstr[0], orig_cmd, 1, ctr);
  1359.     strcpy((DEFCHAR *)t_area,(DEFCHAR *)tmpstr);
  1360. /*---------------------------------------------------------------------*/
  1361. /* First check if the prefix command is a synonym.                     */
  1362. /*---------------------------------------------------------------------*/
  1363. /* check for prefix synonym, if so use the macro name not the synonym */
  1364.     get_valid_macro_file_name(find_prefix_synonym(t_area),temp_cmd,&errnum);
  1365.  
  1366.     if (errnum == 0)
  1367.        found_right = TRUE;
  1368.    }
  1369.  
  1370. /*---------------------------------------------------------------------*/
  1371. /* No valid macro file name found ?                                    */
  1372. /*                                                                     */
  1373. /* Scan 'temp_cmd' from left to right looking for an embedded macro    */
  1374. /* file name.                                                          */
  1375. /*---------------------------------------------------------------------*/
  1376.  if (!found_right)
  1377.    for ( ctr = 0; ctr <= strlen((DEFCHAR *)orig_cmd) && !found_left; ctr++)
  1378.      {
  1379.       substr(&tmpstr[0], orig_cmd, ctr + 1, strlen((DEFCHAR *)temp_cmd) - ctr);
  1380.       strcpy((DEFCHAR *)t_area,(DEFCHAR *)tmpstr);
  1381. /*---------------------------------------------------------------------*/
  1382. /* First check if the prefix command is a synonym.                     */
  1383. /*---------------------------------------------------------------------*/
  1384. /* check for prefix synonym, if so use the macro name not the synonym */
  1385.       get_valid_macro_file_name(find_prefix_synonym(t_area),temp_cmd,&errnum);
  1386.  
  1387.       if (errnum == 0)
  1388.          found_left = TRUE;
  1389.      }
  1390. /*---------------------------------------------------------------------*/
  1391. /* We have a prefix macro...                                           */
  1392. /*---------------------------------------------------------------------*/
  1393.  if (found_right || found_left)
  1394.    {
  1395.     parm_length = strlen((DEFCHAR *)orig_cmd) - strlen((DEFCHAR *)t_area);
  1396.  
  1397.     if (found_right)
  1398.        substr(&tmpstr[0],orig_cmd,strlen((DEFCHAR *)t_area) + 1,parm_length);
  1399.     else
  1400.        substr(&tmpstr[0],orig_cmd,1,parm_length);
  1401.  
  1402.     strcpy((DEFCHAR *)parms,(DEFCHAR *)tmpstr);
  1403.     line_number = curr_ppc->ppc_line_number;
  1404. /*---------------------------------------------------------------------*/
  1405. /* If the prefix command was entered on a shadow line, pass this to    */
  1406. /* the prefix macro...                                                 */
  1407. /*---------------------------------------------------------------------*/
  1408.     if (curr_ppc->ppc_shadow_line)
  1409.        sprintf((DEFCHAR *)pm_parms," PREFIX %s SHADOW %ld %s",t_area,line_number,parms);
  1410.     else
  1411.        sprintf((DEFCHAR *)pm_parms," PREFIX %s SET %ld %s",t_area,line_number,parms);
  1412.     strcat((DEFCHAR *)temp_cmd,(DEFCHAR *)pm_parms);     /* add on the parameter list */
  1413.     prefix_current_line = line_number;
  1414.     in_prefix_macro = TRUE;
  1415. /*---------------------------------------------------------------------*/
  1416. /* Go and execute the prefix macro.                                    */
  1417. /*---------------------------------------------------------------------*/
  1418.     pmacro_rc = execute_macro(temp_cmd,TRUE,¯orc);
  1419.     in_prefix_macro = FALSE;
  1420.    }
  1421.  else
  1422.     pmacro_rc = RC_NOT_COMMAND;
  1423.  return(pmacro_rc);
  1424. }
  1425. /***********************************************************************/
  1426. #ifdef HAVE_PROTO
  1427. static CHARTYPE *substr(CHARTYPE *temp_string,CHARTYPE *string,short start,short length)
  1428. #else
  1429. static CHARTYPE *substr(temp_string, string, start, length)
  1430. CHARTYPE *temp_string, *string;
  1431. short start, length;
  1432. #endif
  1433. /***********************************************************************/
  1434. /* This function is like the REXX SUBSTR function, it returns a        */
  1435. /* pointer to a string containing the result.                          */
  1436. /* Note: The address of the beginning of a blank string is passed to be*/
  1437. /* modified by address: substr(&tmpstr[0],<string>,<start>,<length>);  */
  1438. /* ( In this case, the result is contained in 'tmpstr'  :-)            */
  1439. /***********************************************************************/
  1440. {
  1441. /*-------------------------- external data ----------------------------*/
  1442. /*--------------------------- local data ------------------------------*/
  1443.  register i=0, target_idx = 0;
  1444. /*--------------------------- processing ------------------------------*/
  1445.  for (i = start - 1; target_idx <= length - 1; i++)
  1446.     temp_string[target_idx++] = string[i];
  1447.  temp_string[target_idx] = '\0';   /*MH*/
  1448.  return(temp_string);
  1449. }
  1450. /***********************************************************************/
  1451. #ifdef HAVE_PROTO
  1452. void add_prefix_command(LINE *curr,LINETYPE line_number,bool block_command)
  1453. #else
  1454. void add_prefix_command(curr,line_number,block_command)
  1455. LINE *curr;
  1456. LINETYPE line_number;
  1457. bool block_command;
  1458. #endif
  1459. /***********************************************************************/
  1460. {
  1461. /*------------------------- external data -----------------------------*/
  1462.  extern bool prefix_changed;
  1463.  extern CHARTYPE *pre_rec;
  1464.  extern unsigned short pre_rec_len;
  1465. /*--------------------------- local data ------------------------------*/
  1466.  register short i=0;
  1467.  CHARTYPE temp_prefix_array[MAX_PREFIX_WIDTH+1];
  1468.  PPC *curr_ppc=NULL;
  1469.  bool redisplay_screen=FALSE;
  1470. /*--------------------------- processing ------------------------------*/
  1471. #ifdef TRACE
  1472.  trace_function("prefix.c:  add_prefix_command");
  1473. #endif
  1474.  prefix_changed = FALSE;
  1475. /*---------------------------------------------------------------------*/
  1476. /* Copy the contexts of the prefix record area into a temporary area.  */
  1477. /*---------------------------------------------------------------------*/
  1478.  for (i=0;i<pre_rec_len;i++)
  1479.      temp_prefix_array[i] = pre_rec[i];
  1480.  temp_prefix_array[pre_rec_len] = '\0';
  1481.  strtrunc(temp_prefix_array);
  1482. /*---------------------------------------------------------------------*/
  1483. /* If the prefix record area is blank, clear the pending prefix area.  */
  1484. /*---------------------------------------------------------------------*/
  1485.  if (blank_field(temp_prefix_array))
  1486.    {
  1487.     (void)delete_pending_prefix_command(curr->pre,CURRENT_FILE,curr);
  1488.     redisplay_screen = TRUE;
  1489.    }
  1490.  else
  1491.    {
  1492. /*---------------------------------------------------------------------*/
  1493. /* If the input line already points to an entry in the array, use the  */
  1494. /* existing entry in the array, otherwise add to the next entry.       */
  1495. /*---------------------------------------------------------------------*/
  1496.     curr_ppc = pll_find(CURRENT_FILE->first_ppc,line_number);
  1497.     if (curr_ppc == NULL)  /* not found */
  1498.       {
  1499.        CURRENT_FILE->last_ppc = pll_add(CURRENT_FILE->first_ppc,CURRENT_FILE->last_ppc,sizeof(PPC));
  1500.        if (CURRENT_FILE->last_ppc == NULL)
  1501.          {
  1502.           display_error(30,(CHARTYPE *)"",FALSE);
  1503. #ifdef TRACE
  1504.           trace_return();
  1505. #endif
  1506.           return;
  1507.          }
  1508.        if (CURRENT_FILE->first_ppc == NULL)
  1509.           CURRENT_FILE->first_ppc = CURRENT_FILE->last_ppc;
  1510.        curr_ppc = CURRENT_FILE->last_ppc;
  1511.       }
  1512.     curr->pre = curr_ppc;
  1513.     strcpy((DEFCHAR *)curr_ppc->ppc_command,(DEFCHAR *)temp_prefix_array);
  1514.     curr_ppc->ppc_line_number = line_number;
  1515.     curr_ppc->ppc_block_command = block_command;
  1516.     curr_ppc->ppc_cmd_idx = (-1);
  1517.     if (in_scope(CURRENT_VIEW,curr))
  1518.        curr_ppc->ppc_shadow_line = FALSE;
  1519.     else
  1520.        curr_ppc->ppc_shadow_line = TRUE;
  1521.    }
  1522. /*---------------------------------------------------------------------*/
  1523. /* Clear the pending prefix command line.                              */
  1524. /* This removed by MH 20/01/96 to ensure end() in PREFIX works         */
  1525. /*---------------------------------------------------------------------*/
  1526. #if 0
  1527.  memset(pre_rec,' ',MAX_PREFIX_WIDTH);
  1528.  pre_rec_len = 0;
  1529.  pre_rec[MAX_PREFIX_WIDTH] = '\0';
  1530. #endif
  1531.  
  1532.  if (redisplay_screen)
  1533.    {
  1534.     build_screen(current_screen);
  1535.     display_screen(current_screen);
  1536.    }
  1537. #ifdef TRACE
  1538.  trace_return();
  1539. #endif
  1540.  return;
  1541. }
  1542. /***********************************************************************/
  1543. #ifdef HAVE_PROTO
  1544. short add_prefix_synonym(CHARTYPE *synonym,CHARTYPE *macroname)
  1545. #else
  1546. short add_prefix_synonym(synonym,macroname)
  1547. CHARTYPE *synonym,*macroname;
  1548. #endif
  1549. /***********************************************************************/
  1550. /* Parameters:                                                         */
  1551. /*    synonym: synonym for prefix macro                                */
  1552. /*  macroname: name of REXX macro file                                 */
  1553. /***********************************************************************/
  1554. {
  1555. /*--------------------------- local data ------------------------------*/
  1556.  LINE *curr=NULL;
  1557. /*--------------------------- processing ------------------------------*/
  1558. #ifdef TRACE
  1559.  trace_function("prefix.c:  add_prefix_synonym");
  1560. #endif
  1561. /*---------------------------------------------------------------------*/
  1562. /* First thing is to delete any definitions that may exist for the     */
  1563. /* supplied synonym.                                                   */
  1564. /*---------------------------------------------------------------------*/
  1565.  curr = first_prefix_synonym;
  1566.  while(curr != NULL)
  1567.    {
  1568.     if (strcmp((DEFCHAR *)curr->name,(DEFCHAR *)synonym) == 0)
  1569.       {
  1570.        if (curr->name != NULL)
  1571.           (*the_free)(curr->name);
  1572.        if (curr->line != NULL)
  1573.           (*the_free)(curr->line);
  1574.        curr = lll_del(&first_prefix_synonym,&last_prefix_synonym,curr,DIRECTION_FORWARD);
  1575.       }
  1576.     else
  1577.        curr = curr->next;
  1578.    }
  1579. /*---------------------------------------------------------------------*/
  1580. /* Lastly append the synonym at the end of the linked list.            */
  1581. /*---------------------------------------------------------------------*/
  1582.  curr = lll_add(first_prefix_synonym,last_prefix_synonym,sizeof(LINE));
  1583.  if (curr == NULL)
  1584.    {
  1585.     display_error(30,(CHARTYPE *)"",FALSE);
  1586. #ifdef TRACE
  1587.     trace_return();
  1588. #endif
  1589.     return(RC_OUT_OF_MEMORY);
  1590.    }
  1591.  curr->line = (CHARTYPE *)(*the_malloc)((strlen((DEFCHAR *)macroname)+1)*sizeof(CHARTYPE));
  1592.  if (curr->line == NULL)
  1593.    {
  1594.     display_error(30,(CHARTYPE *)"",FALSE);
  1595. #ifdef TRACE
  1596.     trace_return();
  1597. #endif
  1598.     return(RC_OUT_OF_MEMORY);
  1599.    }
  1600.  strcpy((DEFCHAR *)curr->line,(DEFCHAR *)macroname);
  1601.  curr->name = (CHARTYPE *)(*the_malloc)((strlen((DEFCHAR *)synonym)+1)*sizeof(CHARTYPE));
  1602.  if (curr->name == NULL)
  1603.    {
  1604.     display_error(30,(CHARTYPE *)"",FALSE);
  1605. #ifdef TRACE
  1606.     trace_return();
  1607. #endif
  1608.     return(RC_OUT_OF_MEMORY);
  1609.    }
  1610.  strcpy((DEFCHAR *)curr->name,(DEFCHAR *)synonym);
  1611.  last_prefix_synonym = curr;
  1612.  if (first_prefix_synonym == NULL)
  1613.     first_prefix_synonym = last_prefix_synonym;
  1614. #ifdef TRACE
  1615.  trace_return();
  1616. #endif
  1617.  return(RC_OK);
  1618. }
  1619. /*man***************************************************************************
  1620. NAME
  1621.      find_prefix_synonym
  1622.  
  1623. SYNOPSIS
  1624.      CHARTYPE *find_prefix_synonym(synonym)
  1625.      CHARTYPE *synonym;
  1626.  
  1627. DESCRIPTION
  1628.      The find_prefix_synonym function finds a synonym for 'synonym'
  1629.      and returns that value. If no synonym exists, the 'synonym' is
  1630.      returned unchanged.
  1631.  
  1632.      This function is only available if REXX support is available.
  1633.      
  1634. RETURN VALUE
  1635.      Either the macroname associated with 'synonym' or 'synonym'.
  1636. *******************************************************************************/
  1637. #ifdef HAVE_PROTO
  1638. CHARTYPE *find_prefix_synonym(CHARTYPE *synonym)
  1639. #else
  1640. CHARTYPE *find_prefix_synonym(synonym)
  1641. CHARTYPE *synonym;
  1642. #endif
  1643. /***********************************************************************/
  1644. {
  1645. /*-------------------------- external data ----------------------------*/
  1646. /*--------------------------- local data ------------------------------*/
  1647.  LINE *curr=NULL;
  1648. /*--------------------------- processing ------------------------------*/
  1649. #ifdef TRACE
  1650.  trace_function("prefix.c:  find_prefix_synonym");
  1651. #endif
  1652.  curr = first_prefix_synonym;
  1653.  while(curr != NULL)
  1654.    {
  1655.     if (strcmp((DEFCHAR *)synonym,(DEFCHAR *)curr->name) == 0)
  1656.       {
  1657. #ifdef TRACE
  1658.        trace_return();
  1659. #endif
  1660.        return((CHARTYPE *)curr->line);
  1661.       }
  1662.     curr = curr->next;
  1663.    }
  1664. #ifdef TRACE
  1665.  trace_return();
  1666. #endif
  1667.  return(synonym);
  1668. }
  1669. /*man***************************************************************************
  1670. NAME
  1671.      find_prefix_oldname
  1672.  
  1673. SYNOPSIS
  1674.      CHARTYPE *find_prefix_oldname(oldname)
  1675.      CHARTYPE *oldname;
  1676.  
  1677. DESCRIPTION
  1678.      The find_prefix_oldname function finds the synonym for
  1679.      'oldname' and returns that value. If no synonym exists, the 
  1680.      'oldname' is returned unchanged.
  1681.  
  1682.      This function is only available if REXX support is available.
  1683.      
  1684. RETURN VALUE
  1685.      Either the synonym associated with 'oldname' or 'oldname'.
  1686. *******************************************************************************/
  1687. #ifdef HAVE_PROTO
  1688. CHARTYPE *find_prefix_oldname(CHARTYPE *oldname)
  1689. #else
  1690. CHARTYPE *find_prefix_oldname(oldname)
  1691. CHARTYPE *oldname;
  1692. #endif
  1693. /***********************************************************************/
  1694. {
  1695. /*-------------------------- external data ----------------------------*/
  1696. /*--------------------------- local data ------------------------------*/
  1697.  LINE *curr=NULL;
  1698. /*--------------------------- processing ------------------------------*/
  1699. #ifdef TRACE
  1700.  trace_function("prefix.c:  find_prefix_oldname");
  1701. #endif
  1702.  curr = first_prefix_synonym;
  1703.  while(curr != NULL)
  1704.    {
  1705.     if (strcmp((DEFCHAR *)oldname,(DEFCHAR *)curr->line) == 0)
  1706.       {
  1707. #ifdef TRACE
  1708.        trace_return();
  1709. #endif
  1710.        return(curr->name);
  1711.       }
  1712.     curr = curr->next;
  1713.    }
  1714. #ifdef TRACE
  1715.  trace_return();
  1716. #endif
  1717.  return(oldname);
  1718. }
  1719. /***********************************************************************/
  1720. #ifdef HAVE_PROTO
  1721. CHARTYPE *get_prefix_command(LINETYPE prefix_index)
  1722. #else
  1723. CHARTYPE *get_prefix_command(prefix_index)
  1724. LINETYPE prefix_index;
  1725. #endif
  1726. /***********************************************************************/
  1727. {
  1728. /*--------------------------- local data ------------------------------*/
  1729. /*--------------------------- processing ------------------------------*/
  1730. #ifdef TRACE
  1731.  trace_function("prefix.c:  get_prefix_command");
  1732. #endif
  1733. /*---------------------------------------------------------------------*/
  1734. /* Just return a pointer to the prefix command associated with the     */
  1735. /* supplied index.                                                     */
  1736. /*---------------------------------------------------------------------*/
  1737. #ifdef TRACE
  1738.  trace_return();
  1739. #endif
  1740.  return(pc[prefix_index].cmd);
  1741. }
  1742. /***********************************************************************/
  1743. #ifdef HAVE_PROTO
  1744. static short post_prefix_add(PPC *curr_ppc,short cmd_idx,LINETYPE number_lines)
  1745. #else
  1746. static short post_prefix_add(curr_ppc,cmd_idx,number_lines)
  1747. PPC *curr_ppc;
  1748. short cmd_idx;
  1749. LINETYPE number_lines;
  1750. #endif
  1751. /***********************************************************************/
  1752. {
  1753. /*-------------------------- external data ----------------------------*/
  1754. /*--------------------------- local data ------------------------------*/
  1755.  short rc=RC_OK;
  1756. /*--------------------------- processing ------------------------------*/
  1757.  rc = Sos_leftedge((CHARTYPE *)"");
  1758.  if (CURRENT_VIEW->current_window == WINDOW_FILEAREA)
  1759.    {
  1760.     if (!BOF((CURRENT_VIEW->focus_line)+1L))
  1761.        rc = cursor_down(TRUE);
  1762.    }
  1763.  return(rc);
  1764. }
  1765.