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