1 $NetBSD: patch-ae,v 1.9 2012/03/01 22:00:44 hans Exp $
3 --- fep_edit.c.orig 1995-01-20 08:16:37.000000000 +0000
4 +++ fep_edit.c 2011-09-29 20:19:55.000000000 +0000
10 #include <sys/types.h>
12 +#include <sys/ioctl.h>
14 +#include <sys/fcntl.h>
15 +#include <inttypes.h>
19 +#ifndef _POSIX_VDISABLE
20 +#define _POSIX_VDISABLE '\0'
34 @@ -25,7 +39,7 @@ int MarkPosition = -1; /* Marked positi
35 EDITMODE editmode = NOTYET; /* edtimode EMACS, VI */
36 EDITSTATUS editstatus = NOTEDITING;/* EDITING, NOTEDITING */
38 -int maxline = MAXCOMLEN; /* maximum length of command line */
39 +int maxline = MAXCMDLEN; /* maximum length of command line */
40 int NeedNewLine; /* add new line flag */
41 int NeedSave; /* need to save to history */
42 int Transparency = OFF; /* transparent flag */
43 @@ -86,7 +100,7 @@ BINDENT emacsBindings[] = {
44 /* ^X-^V */ {"\\^X\\^V", view_buffer},
45 /* ^X-^K */ {"\\^X\\^K", kill_to_top_of_line},
46 /* ^X-^L */ {"\\^X\\^L", fep_repaint},
47 - /* ^X-^C */ {"\\^X\\^C", terminate},
48 + /* ^X-^C */ {"\\^X\\^C", (FUNC)terminate},
49 /* ^X-^D */ {"\\^X\\^D", send_eof},
50 /* ^X-( */ {"\\^X(", fep_start_script},
51 /* ^X-) */ {"\\^X)", fep_end_script},
52 @@ -99,9 +113,9 @@ BINDENT emacsBindings[] = {
56 - curFuncTab = (FUNC *) calloc (sizeof (FUNC), 256);
57 - altFuncTab = (FUNC *) calloc (sizeof (FUNC), 256);
58 - if (curFuncTab == 0 || altFuncTab == 0) {
59 + curFuncTab = calloc (sizeof (FUNC), 256);
60 + altFuncTab = calloc (sizeof (FUNC), 256);
61 + if (curFuncTab == NULL || altFuncTab == NULL) {
62 printf ("Can't allocate space for function table\n");
65 @@ -167,9 +181,9 @@ init_edit_params ()
67 * Initialize command line buffer
69 - CommandLine = (CHAR *) calloc (maxline, 1);
70 - KillBuffer = (CHAR *) calloc (maxline, 1);
71 - if (CommandLine == 0 || KillBuffer == 0) {
72 + CommandLine = calloc (maxline, 1);
73 + KillBuffer = calloc (maxline, 1);
74 + if (CommandLine == NULL || KillBuffer == NULL) {
75 perror ("Edit line buffer");
78 @@ -192,6 +206,30 @@ initEmacsBindings (cft, aft)
80 #define import(table,key,fn) if((int)key>0)table[(int)key]=fn
83 + /* Now, using cbreak mode
84 + import (cft, initial_ttymode.c_cc[VSTART], ignore);
85 + import (cft, initial_ttymode.c_cc[VSTOP], ignore);
87 + import (cft, initial_ttymode.c_cc[VINTR], insert_and_flush);
88 + import (cft, initial_ttymode.c_cc[VQUIT], insert_and_flush);
89 + /* Now, EOF will be sent on empty line.
90 + import (cft, initial_ttymode.c_cc[VEOF], send_eof);
93 + import (cft, initial_ttymode.c_cc[VSWTC], insert_and_flush);
95 + import (cft, initial_ttymode.c_cc[VSUSP], insert_and_flush);
96 + /* ^Y is used for yank-from-kill-buffer
97 + import (cft, initial_ttymode.c_cc[VDSUSP], self_insert);
99 + import (cft, initial_ttymode.c_cc[VREPRINT], reprint);
100 + import (cft, initial_ttymode.c_cc[VDISCARD], self_insert);
101 + import (cft, initial_ttymode.c_cc[VWERASE], delete_previous_word);
102 + import (cft, initial_ttymode.c_cc[VLNEXT], literal_next);
103 + import (cft, initial_ttymode.c_cc[VERASE], delete_previous_character);
104 + import (cft, initial_ttymode.c_cc[VKILL], delete_line);
106 /* Now, using cbreak mode
107 import (cft, tchars_buf.t_startc, ignore);
108 import (cft, tchars_buf.t_stopc, ignore);
109 @@ -212,6 +250,7 @@ initEmacsBindings (cft, aft)
110 import (cft, ltchars_buf.t_lnextc, literal_next);
111 import (cft, initial_ttymode.sg_erase, delete_previous_character);
112 import (cft, initial_ttymode.sg_kill, delete_line);
117 @@ -227,7 +266,7 @@ initEmacsBindings (cft, aft)
118 * Main function of front end program
125 CHAR *execute_command, *check_alias();
126 @@ -257,7 +296,7 @@ RETRY:
130 - if (fgets (CommandLine, MAXCOMLEN, redirect_fp)) {
131 + if (fgets (CommandLine, MAXCMDLEN, redirect_fp)) {
133 execute_command = CommandLine;
135 @@ -301,7 +340,11 @@ RETRY:
140 + c == initial_ttymode.c_cc[VEOF]
142 c == tchars_buf.t_eofc
144 && curFuncTab[c] != send_eof
145 && ! look_var ("ignore-eof")
146 && CommandLine [0] == '\0'
147 @@ -422,11 +465,11 @@ self_insert(c)
148 register int i, nbyte = 1, currentNull;
154 currentNull = strlen (CommandLine);
156 - if (currentNull >= maxline) {
157 + if (currentNull + 1 >= maxline) {
161 @@ -441,7 +484,7 @@ self_insert(c)
169 &CommandLine[CurrentPosition] + nbyte,
170 @@ -453,7 +496,7 @@ self_insert(c)
172 CommandLine[CurrentPosition - 1] = byte2;
176 printS (&CommandLine [CurrentPosition]);
178 if (CommandLine[CurrentPosition] != '\0') {
179 @@ -557,7 +600,7 @@ moveto (position)
181 && !(CurrentPosition + 1 == position
182 && iskanji (CommandLine[CurrentPosition]))
186 (void) forward_n_character (1);
188 @@ -581,10 +624,10 @@ beginning_of_line()
190 #define INC(i) if(iskanji(CommandLine[i])) i+=2; else i++;
191 #define DEC(i) if(i>=2 && iskanji_in_string(CommandLine, i-2)) i-=2; else i--;
200 * Move cursor to end of line
201 @@ -642,7 +685,7 @@ backward_n_character(n)
210 @@ -697,7 +740,7 @@ backward_n_word (n)
218 while (i > 0 && !iswordchar (CommandLine [i])) {
219 @@ -707,7 +750,7 @@ backward_n_word (n)
225 return (backward_n_character (nchars));
228 @@ -758,7 +801,7 @@ backward_n_Word (n)
236 while (i > 0 && !isWordchar (CommandLine [i]))
237 @@ -766,7 +809,7 @@ backward_n_Word (n)
238 while (i > 0 && isWordchar (CommandLine [i - 1]))
243 return (backward_n_character (nchars));
246 @@ -804,7 +847,7 @@ forward_n_character(n)
247 (void) putchar (CommandLine[i++]);
252 if (isctlchar(CommandLine[i])) {
253 (void) putchar (unctl (CommandLine [i]));
255 @@ -819,7 +862,7 @@ forward_n_character(n)
256 (void) putchar (CommandLine[i++]);
261 putChar (CommandLine [i++]);
264 @@ -1000,9 +1043,9 @@ delete_previous_n_character(n)
274 deleteArea = howlong (&CommandLine[CurrentPosition - nbyte], nbyte);
275 restArea = howlong (&CommandLine[CurrentPosition], 0);
276 @@ -1075,7 +1118,7 @@ delete_previous_n_word(n)
284 while (i > 0 && !iswordchar (CommandLine [i]))
285 @@ -1083,7 +1126,7 @@ delete_previous_n_word(n)
286 while (i > 0 && iswordchar (CommandLine [i - 1]))
292 return (delete_previous_n_character (nchars));
294 @@ -1136,7 +1179,7 @@ delete_previous_n_Word(n)
302 while (i > 0 && !isWordchar (CommandLine [i]))
303 @@ -1144,7 +1187,7 @@ delete_previous_n_Word(n)
304 while (i > 0 && isWordchar (CommandLine [i - 1]))
310 return (delete_previous_n_character (nchars));
312 @@ -1183,9 +1226,9 @@ delete_next_n_character (n)
322 deleteArea = howlong (&CommandLine[CurrentPosition], nbyte);
323 restArea = howlong (&CommandLine[CurrentPosition + nbyte], 0);
324 @@ -1481,7 +1524,11 @@ insert_and_flush(c)
329 + char c = initial_ttymode.c_cc[VEOF];
331 char c = tchars_buf.t_eofc;
334 (void) self_insert (c);
336 @@ -1698,7 +1745,7 @@ expand_file_name ()
339 DIR *dirp, *x_opendir();
344 int tilde_expanded = 0;
345 @@ -1737,11 +1784,11 @@ expand_file_name ()
349 - fcp = (char *) alloca (strlen (dp->d_name) + 1);
351 - fcp = (char *) malloc (strlen (dp->d_name) + 1);
354 + fcp = alloca (strlen (dp->d_name) + 1);
356 + fcp = malloc (strlen (dp->d_name) + 1);
357 +# endif /* ALLOCA */
359 fputs ("\r\n", stdout);
362 @@ -1754,7 +1801,7 @@ expand_file_name ()
363 fileList [i] = (char *) 0;
365 if (*start_expand == '~' && look_var ("expand-tilde")) {
366 - char *buf [256], *p;
367 + char buf [256], *p;
369 strcpy (buf, start_expand);
371 @@ -1801,7 +1848,7 @@ expand_file_name ()
373 for (i = 0; fileList [i]; i++)
376 +# endif /* ALLOCA */
380 @@ -1903,7 +1950,7 @@ ls (dirp, prefixstring)
386 char *fileList[MAXFILES + 1];
389 @@ -1928,11 +1975,11 @@ ls (dirp, prefixstring)
391 if (prefix (prefixstring, dp->d_name)) {
393 - fcp = (char *) alloca (strlen (dp->d_name) + 1);
395 - fcp = (char *) malloc (strlen (dp->d_name) + 1);
398 + fcp = alloca (strlen (dp->d_name) + 1);
400 + fcp = malloc (strlen (dp->d_name) + 1);
401 +# endif /* ALLOCA */
403 fputs ("\r\n", stdout);
406 @@ -1975,7 +2022,7 @@ BACK:
408 for (i = 0; fileList [i]; i++)
411 +# endif /* ALLOCA */
415 @@ -2022,7 +2069,7 @@ list_remote_file (host, pattern)
416 fputs ("\n", stdout);
422 bind_key (ft, func, s, dfunc)
423 FUNC ft[]; /* Function table */
424 @@ -2032,7 +2079,7 @@ bind_key (ft, func, s, dfunc)
428 - if (s[0] == '\\' && s[1] == '^' && s[2] != NULL) {
429 + if (s[0] == '\\' && s[1] == '^' && s[2] != '\0') {
430 tmps[0] = toctrl (s[2]);
431 strcpy (&tmps[1], &s[3]);
433 @@ -2042,7 +2089,7 @@ bind_key (ft, func, s, dfunc)
434 * If the string contain only one character, put the function to
435 * appropriate position in the table.
437 - if (*(s+1) == NULL) {
438 + if (*(s+1) == '\0') {
439 if (isIndirect (ft[(int) *s]))
440 free (maskIndirect (ft[(int) *s]));
442 @@ -2059,11 +2106,11 @@ bind_key (ft, func, s, dfunc)
443 if (! (isIndirect (ft[(int) *s]))) {
446 - nft = (FUNC *) calloc (sizeof (FUNC), 256);
447 + nft = calloc (sizeof (FUNC), 256);
449 * If failed in allocating, return 0.