Fixup fromcvs/togit conversion
[minix-pkgsrc.git] / misc / fep / patches / patch-ae
blob3a80c80a83acb66633b39532dea176299dc9874d
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
5 @@ -6,12 +6,26 @@
6 -#endif lint
7 +#endif /* lint */
8  
9  #include <stdio.h>
10  #include <sys/types.h>
11  #include <sys/stat.h>
12 +#include <sys/ioctl.h>
13 +#include <unistd.h>
14 +#include <sys/fcntl.h>
15 +#include <inttypes.h>
16 +#ifdef TERMIOS
17 +#include <termios.h>
18 +#ifdef __linux__
19 +#ifndef _POSIX_VDISABLE
20 +#define _POSIX_VDISABLE '\0'
21 +#endif
22 +#endif
23 +#else
24  #include <sgtty.h>
25 +#endif
26  #include <sys/time.h>
27 +#include <stdlib.h>
28  #include <ctype.h>
29 -#include <sys/dir.h>
30 +#include <dirent.h>
31  #include <sys/file.h>
32  #include <setjmp.h>
33  #include "fep_defs.h"
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[] = {
53  init_bind_table ()
54  {
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");
63         exit (1);
64      }
65 @@ -167,9 +181,9 @@ init_edit_params ()
66      /*
67       * Initialize command line buffer
68       */
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");
76         exit (1);
77      }
78 @@ -192,6 +206,30 @@ initEmacsBindings (cft, aft)
80  #define import(table,key,fn) if((int)key>0)table[(int)key]=fn
82 +#ifdef TERMIOS
83 +    /* Now, using cbreak mode
84 +    import (cft, initial_ttymode.c_cc[VSTART], ignore);
85 +    import (cft, initial_ttymode.c_cc[VSTOP], ignore);
86 +    */
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);
91 +    */
92 +#ifdef VSWTC
93 +    import (cft, initial_ttymode.c_cc[VSWTC], insert_and_flush);
94 +#endif
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);
98 +    */
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);
105 +#else
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);
113 +#endif
115  #undef import
117 @@ -227,7 +266,7 @@ initEmacsBindings (cft, aft)
118   * Main function of front end program
119   */
120  CHAR *
121 -getline()
122 +get_line()
124      int c;
125      CHAR *execute_command, *check_alias();
126 @@ -257,7 +296,7 @@ RETRY:
127          */
128         swallow_output();
130 -       if (fgets (CommandLine, MAXCOMLEN, redirect_fp)) {
131 +       if (fgets (CommandLine, MAXCMDLEN, redirect_fp)) {
132             ++redirect_line;
133             execute_command = CommandLine;
134             goto RETURN;            
135 @@ -301,7 +340,11 @@ RETRY:
136          * call send_eof
137          */
138         if (
139 +#ifdef TERMIOS
140 +           c == initial_ttymode.c_cc[VEOF]
141 +#else
142             c == tchars_buf.t_eofc
143 +#endif
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;
149  #ifdef KANJI
150      CHAR byte2;
151 -#endif KANJI
152 +#endif /* KANJI */
154      currentNull = strlen (CommandLine);
156 -    if (currentNull >= maxline) {
157 +    if (currentNull + 1 >= maxline) {
158          errorBell();
159         return (0);
160      }
161 @@ -441,7 +484,7 @@ self_insert(c)
162         nbyte = 2;
163      }
164      else
165 -#endif KANJI
166 +#endif /* KANJI */
167         putChar (c);
168      reverse_strcpy (
169         &CommandLine[CurrentPosition] + nbyte,
170 @@ -453,7 +496,7 @@ self_insert(c)
171      if (nbyte > 1) {
172         CommandLine[CurrentPosition - 1] = byte2;
173      }
174 -#endif KANJI
175 +#endif /* KANJI */
176      printS (&CommandLine [CurrentPosition]);
178      if (CommandLine[CurrentPosition] != '\0') {
179 @@ -557,7 +600,7 @@ moveto (position)
180  #ifdef KANJI
181             && !(CurrentPosition + 1 == position
182                     && iskanji (CommandLine[CurrentPosition]))
183 -#endif KANJI
184 +#endif /* KANJI */
185         )
186             (void) forward_n_character (1);
188 @@ -581,10 +624,10 @@ beginning_of_line()
189  #ifdef KANJI
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--;
192 -#else KANJI
193 +#else /* KANJI */
194  #define INC(i) i++
195  #define DEC(i) i--
196 -#endif KANJI
197 +#endif /* KANJI */
199  /*
200   * Move cursor to end of line
201 @@ -642,7 +685,7 @@ backward_n_character(n)
202             i--;
203         }
204         else
205 -#endif KANJI
206 +#endif /* KANJI */
207         putchar (BS);
208         i--;
209      }
210 @@ -697,7 +740,7 @@ backward_n_word (n)
211             nchars++;
212         }
213      }
214 -#else KANJI
215 +#else /* KANJI */
216      while (n--) {
217         i--, nchars++;
218         while (i > 0 && !iswordchar (CommandLine [i])) {
219 @@ -707,7 +750,7 @@ backward_n_word (n)
220             i--, nchars++;
221         }
222      }
223 -#endif KANJI
224 +#endif /* KANJI */
225      return (backward_n_character (nchars));
228 @@ -758,7 +801,7 @@ backward_n_Word (n)
229             nchars++;
230         }
231      }
232 -#else KANJI
233 +#else /* KANJI */
234      while (n--) {
235         i--, nchars++;
236         while (i > 0 && !isWordchar (CommandLine [i]))
237 @@ -766,7 +809,7 @@ backward_n_Word (n)
238         while (i > 0 && isWordchar (CommandLine [i - 1]))
239             i--, nchars++;
240      }
241 -#endif KANJI
242 +#endif /* KANJI */
243      return (backward_n_character (nchars));
246 @@ -804,7 +847,7 @@ forward_n_character(n)
247         (void) putchar (CommandLine[i++]);
248      }
249      else
250 -#endif KANJI
251 +#endif /* KANJI */
252      if (isctlchar(CommandLine[i])) {
253         (void) putchar (unctl (CommandLine [i]));
254         i++;
255 @@ -819,7 +862,7 @@ forward_n_character(n)
256             (void) putchar (CommandLine[i++]);
257         }
258         else
259 -#endif KANJI
260 +#endif /* KANJI */
261         putChar (CommandLine [i++]);
262      }
264 @@ -1000,9 +1043,9 @@ delete_previous_n_character(n)
265             i -= 2, nbyte += 2;
266         else
267             i -= 1, nbyte += 1;
268 -#else KANJI
269 +#else /* KANJI */
270      nbyte = n;
271 -#endif KANJI
272 +#endif /* KANJI */
274      deleteArea = howlong (&CommandLine[CurrentPosition - nbyte], nbyte);
275      restArea = howlong (&CommandLine[CurrentPosition], 0);
276 @@ -1075,7 +1118,7 @@ delete_previous_n_word(n)
277             nchars++;
278         }
279      }
280 -#else KANJI
281 +#else /* KANJI */
282      while (n--) {
283         i--, nchars++;
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]))
287             i--, nchars++;
288      }
289 -#endif KANJI
290 +#endif /* KANJI */
292      return (delete_previous_n_character (nchars));
294 @@ -1136,7 +1179,7 @@ delete_previous_n_Word(n)
295             nchars++;
296         }
297      }
298 -#else KANJI
299 +#else /* KANJI */
300      while (n--) {
301         i--, nchars++;
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]))
305             i--, nchars++;
306      }
307 -#endif KANJI
308 +#endif /* KANJI */
310      return (delete_previous_n_character (nchars));
312 @@ -1183,9 +1226,9 @@ delete_next_n_character (n)
313             else
314                 cp++, nbyte++;
315      }
316 -#else KANJI
317 +#else /* KANJI */
318      nbyte = n;
319 -#endif KANJI
320 +#endif /* KANJI */
322      deleteArea = howlong (&CommandLine[CurrentPosition], nbyte);
323      restArea = howlong (&CommandLine[CurrentPosition + nbyte], 0);
324 @@ -1481,7 +1524,11 @@ insert_and_flush(c)
325   */
326  send_eof()
328 +#ifdef TERMIOS
329 +    char c = initial_ttymode.c_cc[VEOF];
330 +#else
331      char c = tchars_buf.t_eofc;
332 +#endif
334      (void) self_insert (c);
335      if (isctlchar (c))
336 @@ -1698,7 +1745,7 @@ expand_file_name ()
337      char *fileList[256];
338      CHAR line[256];
339      DIR *dirp, *x_opendir();
340 -    struct direct *dp;
341 +    struct dirent *dp;
342      int found = 0;
343      int i;
344      int tilde_expanded = 0;
345 @@ -1737,11 +1784,11 @@ expand_file_name ()
346             char *fcp;
348  # ifdef ALLOCA
349 -           fcp = (char *) alloca (strlen (dp->d_name) + 1);
350 -# else ALLOCA
351 -           fcp = (char *) malloc (strlen (dp->d_name) + 1);
352 -# endif ALLOCA
353 -           if (fcp == 0) {
354 +           fcp = alloca (strlen (dp->d_name) + 1);
355 +# else /* ALLOCA */
356 +           fcp = malloc (strlen (dp->d_name) + 1);
357 +# endif /* ALLOCA */
358 +           if (fcp == NULL) {
359                 fputs ("\r\n", stdout);
360                 perror ("alloca:");
361                 reprint ();
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);
370         p = x_dirname (buf);
371 @@ -1801,7 +1848,7 @@ expand_file_name ()
372  # ifndef ALLOCA
373      for (i = 0; fileList [i]; i++)
374         free (fileList [i]);
375 -# endif ALLOCA
376 +# endif /* ALLOCA */
378      closedir(dirp);
379      return (0);
380 @@ -1903,7 +1950,7 @@ ls (dirp, prefixstring)
381      DIR *dirp;
382      char *prefixstring;
384 -    struct direct *dp;
385 +    struct dirent *dp;
386      char *fileList[MAXFILES + 1];
387      int i, j;
388      int maxlen = 0;
389 @@ -1928,11 +1975,11 @@ ls (dirp, prefixstring)
390             continue;
391         if (prefix (prefixstring, dp->d_name)) {
392  # ifdef ALLOCA
393 -           fcp = (char *) alloca (strlen (dp->d_name) + 1);
394 -# else ALLOCA
395 -           fcp = (char *) malloc (strlen (dp->d_name) + 1);
396 -# endif ALLOCA
397 -           if (fcp == 0) {
398 +           fcp = alloca (strlen (dp->d_name) + 1);
399 +# else /* ALLOCA */
400 +           fcp = malloc (strlen (dp->d_name) + 1);
401 +# endif /* ALLOCA */
402 +           if (fcp == NULL) {
403                 fputs ("\r\n", stdout);
404                 perror ("alloca:");
405                 reprint ();
406 @@ -1975,7 +2022,7 @@ BACK:
407  # ifndef ALLOCA
408      for (i = 0; fileList [i]; i++)
409         free (fileList [i]);
410 -# endif ALLOCA
411 +# endif /* ALLOCA */
412      return;
415 @@ -2022,7 +2069,7 @@ list_remote_file (host, pattern)
416         fputs ("\n", stdout);
417      }
419 -#endif RINFO
420 +#endif /* RINFO */
422  bind_key (ft, func, s, dfunc)
423      FUNC ft[];         /* Function table */
424 @@ -2032,7 +2079,7 @@ bind_key (ft, func, s, dfunc)
426      char tmps[16];
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]);
432         s = tmps;
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.
436       */
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]))) {
444             register int i;
446 -           nft = (FUNC *) calloc (sizeof (FUNC), 256);
447 +           nft = calloc (sizeof (FUNC), 256);
448             /*
449              * If failed in allocating, return 0.
450              */
451 -           if (nft == 0)
452 +           if (nft == NULL)
453                 return (0);
455             /*