Commit 3a942abd 3a942abdd8efce990f4c320d1ccf28488a2def1f by Sergey Poznyakoff

handle SIGWINCH

1 parent 6186938b
...@@ -23,22 +23,31 @@ static char *ml_command_generator __P((char *text, int state)); ...@@ -23,22 +23,31 @@ static char *ml_command_generator __P((char *text, int state));
23 static int _interrupt; 23 static int _interrupt;
24 24
25 static RETSIGTYPE 25 static RETSIGTYPE
26 sig_int(int signo) 26 sig_handler (int signo)
27 { 27 {
28 if (util_find_env("quit")->set) 28 switch (signo)
29 {
30 case SIGINT:
31 if (util_find_env ("quit")->set)
29 exit (0); 32 exit (0);
30 _interrupt++; 33 _interrupt++;
31 signal (signo, sig_int); 34 break;
35 #if defined (SIGWINCH)
36 case SIGWINCH:
37 break;
38 #endif
39 }
40 signal (signo, sig_handler);
32 } 41 }
33 42
34 void 43 void
35 ml_clear_interrupt() 44 ml_clear_interrupt ()
36 { 45 {
37 _interrupt = 0; 46 _interrupt = 0;
38 } 47 }
39 48
40 int 49 int
41 ml_got_interrupt() 50 ml_got_interrupt ()
42 { 51 {
43 int rc = _interrupt; 52 int rc = _interrupt;
44 _interrupt = 0; 53 _interrupt = 0;
...@@ -51,8 +60,19 @@ ml_getc (FILE *stream) ...@@ -51,8 +60,19 @@ ml_getc (FILE *stream)
51 { 60 {
52 unsigned char c; 61 unsigned char c;
53 62
63 while (1)
64 {
54 if (read (fileno (stream), &c, 1) == 1) 65 if (read (fileno (stream), &c, 1) == 1)
55 return c; 66 return c;
67 if (errno == EINTR)
68 {
69 if (_interrupt)
70 break;
71 /* keep going if we handled the signal */
72 }
73 else
74 break;
75 }
56 return EOF; 76 return EOF;
57 } 77 }
58 #endif 78 #endif
...@@ -68,7 +88,10 @@ ml_readline_init () ...@@ -68,7 +88,10 @@ ml_readline_init ()
68 rl_attempted_completion_function = (CPPFunction*)ml_command_completion; 88 rl_attempted_completion_function = (CPPFunction*)ml_command_completion;
69 rl_getc_function = ml_getc; 89 rl_getc_function = ml_getc;
70 #endif 90 #endif
71 signal(SIGINT, sig_int); 91 signal (SIGINT, sig_handler);
92 #if defined(SIGWINCH)
93 signal (SIGWINCH, sig_handler);
94 #endif
72 } 95 }
73 96
74 #ifdef WITH_READLINE 97 #ifdef WITH_READLINE
...@@ -76,23 +99,23 @@ ml_readline_init () ...@@ -76,23 +99,23 @@ ml_readline_init ()
76 static char *insert_text; 99 static char *insert_text;
77 100
78 static int 101 static int
79 ml_insert_hook() 102 ml_insert_hook ()
80 { 103 {
81 if (insert_text) 104 if (insert_text)
82 rl_insert_text(insert_text); 105 rl_insert_text (insert_text);
83 return 0; 106 return 0;
84 } 107 }
85 108
86 int 109 int
87 ml_reread(char *prompt, char **text) 110 ml_reread (char *prompt, char **text)
88 { 111 {
89 char *s; 112 char *s;
90 113
91 insert_text = *text; 114 insert_text = *text;
92 rl_startup_hook = ml_insert_hook; 115 rl_startup_hook = ml_insert_hook;
93 s = readline(prompt); 116 s = readline (prompt);
94 if (*text) 117 if (*text)
95 free(*text); 118 free (*text);
96 *text = s; 119 *text = s;
97 rl_startup_hook = NULL; 120 rl_startup_hook = NULL;
98 return 0; 121 return 0;
...@@ -139,13 +162,13 @@ ml_command_generator (char *text, int state) ...@@ -139,13 +162,13 @@ ml_command_generator (char *text, int state)
139 #else 162 #else
140 163
141 int 164 int
142 ml_reread(char *prompt, char **text) 165 ml_reread (char *prompt, char **text)
143 { 166 {
144 char *s; 167 char *s;
145 /*FIXME*/ 168 /*FIXME*/
146 s = readline(prompt); 169 s = readline (prompt);
147 if (*text) 170 if (*text)
148 free(*text); 171 free (*text);
149 *text = s; 172 *text = s;
150 return 0; 173 return 0;
151 } 174 }
......