home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / the25.zip / thesrc251.zip / column.c < prev    next >
C/C++ Source or Header  |  1997-09-10  |  8KB  |  232 lines

  1. /***********************************************************************/
  2. /* COLUMN.C - Column commands                                          */
  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: column.c 2.1 1995/06/24 16:28:41 MH Rel MH $
  43. */
  44.  
  45. #include <the.h>
  46. #include <proto.h>
  47.  
  48. /***********************************************************************/
  49. #ifdef HAVE_PROTO
  50. short column_command(CHARTYPE *cmd_text,int cmd_type)
  51. #else
  52. short column_command(cmd_text,cmd_type)
  53. CHARTYPE *cmd_text;
  54. int cmd_type;
  55. #endif
  56. /***********************************************************************/
  57. {
  58. /*-------------------------- external data ----------------------------*/
  59.  extern CHARTYPE *rec;
  60.  extern LENGTHTYPE rec_len;
  61.  extern short compatible_feel;
  62.  extern bool curses_started;
  63. /*--------------------------- local data ------------------------------*/
  64.  LENGTHTYPE i=0;
  65.  LINETYPE true_line=0L;
  66.  short rc=RC_OK;
  67.  short len_params=0;
  68.  unsigned short y=0,x=0;
  69. /*--------------------------- processing ------------------------------*/
  70. #ifdef TRACE
  71.  trace_function("column.c:  column_command");
  72. #endif
  73. /*---------------------------------------------------------------------*/
  74. /* All column commands under XEDIT compatibility refer to current line.*/
  75. /* ******* At this stage, revert to THE behaviour at all times ******* */
  76. /*---------------------------------------------------------------------*/
  77.  if (compatible_feel == COMPAT_XEDIT)
  78.     true_line = CURRENT_VIEW->current_line;
  79.  else
  80.     true_line = get_true_line(TRUE);
  81. /*---------------------------------------------------------------------*/
  82. /* If on TOF or BOF, exit with error.                                  */
  83. /*---------------------------------------------------------------------*/
  84.  if (TOF(true_line)
  85.  ||  BOF(true_line))
  86.    {
  87.     display_error(36,(CHARTYPE *)"",FALSE);
  88. #ifdef TRACE
  89.     trace_return();
  90. #endif
  91.     return(RC_NO_LINES_CHANGED);
  92.    }
  93. /*---------------------------------------------------------------------*/
  94. /* If HEX mode is on, convert the hex string...                        */
  95. /*---------------------------------------------------------------------*/
  96.  if (CURRENT_VIEW->hex)
  97.    {
  98.     if ((len_params = convert_hex_strings(cmd_text)) == (-1))
  99.       {
  100.        display_error(32,(CHARTYPE *)"",FALSE);
  101. #ifdef TRACE
  102.        trace_return();
  103. #endif
  104.        return(RC_INVALID_OPERAND);
  105.       }
  106.    }
  107.  else
  108.    len_params = strlen((DEFCHAR *)cmd_text);
  109. /*---------------------------------------------------------------------*/
  110. /* If on command line, copy current line into rec                      */
  111. /*---------------------------------------------------------------------*/
  112.  if (CURRENT_VIEW->current_window == WINDOW_COMMAND
  113.  ||  compatible_feel == COMPAT_XEDIT)
  114.    {
  115.     post_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line,(LINE *)NULL,TRUE);
  116.     pre_process_line(CURRENT_VIEW,CURRENT_VIEW->current_line,(LINE *)NULL);
  117.     x = CURRENT_VIEW->current_column-1;
  118.    }
  119.  else
  120.    {
  121.     if (CURRENT_VIEW->current_window == WINDOW_PREFIX)
  122.       {
  123.        if (cmd_type != COLUMN_CAPPEND)
  124.          {
  125.           display_error(36,(CHARTYPE *)"",FALSE);
  126. #ifdef TRACE
  127.           trace_return();
  128. #endif
  129.           return(RC_NO_LINES_CHANGED);
  130.          }
  131.       }
  132.     if (curses_started)
  133.        getyx(CURRENT_WINDOW,y,x);
  134.     x = CURRENT_VIEW->verify_col-1+x;
  135.    }
  136.  switch(cmd_type)
  137.    {
  138.     case COLUMN_CAPPEND:
  139.          CURRENT_VIEW->current_column = rec_len+1;
  140.          for (i=0;i<len_params;i++)
  141.            {
  142.             if (rec_len > max_line_length)
  143.                break;
  144.             rec[rec_len] = *(cmd_text+i);
  145.             rec_len++;
  146.            }
  147.          rec[rec_len] = '\0';
  148.          break;
  149.     case COLUMN_CINSERT:
  150.          if (x > rec_len)
  151.            {
  152.             rec_len = x;
  153.             for (i=0;i<len_params;i++)
  154.               {
  155.                if (rec_len > max_line_length)
  156.                   break;
  157.                rec[rec_len] = *(cmd_text+i);
  158.                rec_len++;
  159.               }
  160.             rec[rec_len] = '\0';
  161.            }
  162.          else
  163.            {
  164.             rec = meminsmem(rec,cmd_text,len_params,x,max_line_length,rec_len);
  165.             rec_len = min(max_line_length,rec_len+len_params);
  166.             rec[rec_len] = '\0';
  167.            }
  168.          break;
  169.     case COLUMN_COVERLAY:
  170.          for (i=0;i<len_params;i++)
  171.            {
  172.             if (x > max_line_length)
  173.                break;
  174.             switch(*(cmd_text+i))
  175.               {
  176.                case '_':
  177.                     rec[x] = ' ';
  178.                     break;
  179.                case ' ':
  180.                     break;
  181.                default:
  182.                     rec[x] = *(cmd_text+i);
  183.                     break;
  184.               }
  185.             x++;
  186.            }
  187.          rec_len = max(rec_len,x+1);
  188.          rec[rec_len] = '\0';
  189.          break;
  190.     case COLUMN_CREPLACE:
  191.          for (i=0;i<len_params;i++)
  192.            {
  193.             if (x > max_line_length)
  194.                break;
  195.             rec[x] = *(cmd_text+i);
  196.             x++;
  197.            }
  198.          rec_len = max(rec_len,x+1);
  199.          rec[rec_len] = '\0';
  200.          break;
  201.    }
  202.  if (CURRENT_VIEW->current_window == WINDOW_COMMAND
  203.  ||  compatible_feel == COMPAT_XEDIT)
  204.    {
  205.     post_process_line(CURRENT_VIEW,CURRENT_VIEW->current_line,(LINE *)NULL,TRUE);
  206.     pre_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line,(LINE *)NULL);
  207.    }
  208.  else
  209.    {
  210.     switch(cmd_type)
  211.       {
  212.        case COLUMN_CAPPEND:
  213.             if (CURRENT_VIEW->current_window == WINDOW_PREFIX)
  214.               {
  215.                CURRENT_VIEW->current_window = WINDOW_FILEAREA;
  216.                if (curses_started)
  217.                   wmove(CURRENT_WINDOW,y,0);
  218.               }
  219.             rc = execute_move_cursor(CURRENT_VIEW->current_column-1);
  220.             break;
  221.        case COLUMN_CINSERT:
  222.             break;
  223.       }
  224.    }
  225.  build_screen(current_screen);
  226.  display_screen(current_screen);
  227. #ifdef TRACE
  228.  trace_return();
  229. #endif
  230.  return(rc);
  231. }
  232.