callback.c (136644) | callback.c (157184) |
---|---|
1/* callback.c -- functions to use readline as an X `callback' mechanism. */ 2 | 1/* callback.c -- functions to use readline as an X `callback' mechanism. */ 2 |
3/* Copyright (C) 1987, 1989, 1992 Free Software Foundation, Inc. | 3/* Copyright (C) 1987-2005 Free Software Foundation, Inc. |
4 5 This file is part of the GNU Readline Library, a library for 6 reading lines of text with interactive input and history editing. 7 8 The GNU Readline Library is free software; you can redistribute it 9 and/or modify it under the terms of the GNU General Public License 10 as published by the Free Software Foundation; either version 2, or 11 (at your option) any later version. --- 27 unchanged lines hidden (view full) --- 39 40#include <stdio.h> 41 42/* System-specific feature definitions and include files. */ 43#include "rldefs.h" 44#include "readline.h" 45#include "rlprivate.h" 46 | 4 5 This file is part of the GNU Readline Library, a library for 6 reading lines of text with interactive input and history editing. 7 8 The GNU Readline Library is free software; you can redistribute it 9 and/or modify it under the terms of the GNU General Public License 10 as published by the Free Software Foundation; either version 2, or 11 (at your option) any later version. --- 27 unchanged lines hidden (view full) --- 39 40#include <stdio.h> 41 42/* System-specific feature definitions and include files. */ 43#include "rldefs.h" 44#include "readline.h" 45#include "rlprivate.h" 46 |
47/* Private data for callback registration functions. See comments in 48 rl_callback_read_char for more details. */ 49_rl_callback_func_t *_rl_callback_func = 0; 50_rl_callback_generic_arg *_rl_callback_data = 0; 51 |
|
47/* **************************************************************** */ 48/* */ | 52/* **************************************************************** */ 53/* */ |
49/* Callback Readline Functions */ | 54/* Callback Readline Functions */ |
50/* */ 51/* **************************************************************** */ 52 53/* Allow using readline in situations where a program may have multiple 54 things to handle at once, and dispatches them via select(). Call 55 rl_callback_handler_install() with the prompt and a function to call 56 whenever a complete line of input is ready. The user must then 57 call rl_callback_read_char() every time some input is available, and --- 9 unchanged lines hidden (view full) --- 67_rl_callback_newline () 68{ 69 rl_initialize (); 70 71 if (in_handler == 0) 72 { 73 in_handler = 1; 74 | 55/* */ 56/* **************************************************************** */ 57 58/* Allow using readline in situations where a program may have multiple 59 things to handle at once, and dispatches them via select(). Call 60 rl_callback_handler_install() with the prompt and a function to call 61 whenever a complete line of input is ready. The user must then 62 call rl_callback_read_char() every time some input is available, and --- 9 unchanged lines hidden (view full) --- 72_rl_callback_newline () 73{ 74 rl_initialize (); 75 76 if (in_handler == 0) 77 { 78 in_handler = 1; 79 |
75 (*rl_prep_term_function) (_rl_meta_flag); | 80 if (rl_prep_term_function) 81 (*rl_prep_term_function) (_rl_meta_flag); |
76 77#if defined (HANDLE_SIGNALS) 78 rl_set_signals (); 79#endif 80 } 81 82 readline_internal_setup (); 83} 84 85/* Install a readline handler, set up the terminal, and issue the prompt. */ 86void 87rl_callback_handler_install (prompt, linefunc) 88 const char *prompt; 89 rl_vcpfunc_t *linefunc; 90{ 91 rl_set_prompt (prompt); | 82 83#if defined (HANDLE_SIGNALS) 84 rl_set_signals (); 85#endif 86 } 87 88 readline_internal_setup (); 89} 90 91/* Install a readline handler, set up the terminal, and issue the prompt. */ 92void 93rl_callback_handler_install (prompt, linefunc) 94 const char *prompt; 95 rl_vcpfunc_t *linefunc; 96{ 97 rl_set_prompt (prompt); |
98 RL_SETSTATE (RL_STATE_CALLBACK); |
|
92 rl_linefunc = linefunc; 93 _rl_callback_newline (); 94} 95 96/* Read one character, and dispatch to the handler if it ends the line. */ 97void 98rl_callback_read_char () 99{ 100 char *line; | 99 rl_linefunc = linefunc; 100 _rl_callback_newline (); 101} 102 103/* Read one character, and dispatch to the handler if it ends the line. */ 104void 105rl_callback_read_char () 106{ 107 char *line; |
101 int eof; | 108 int eof, jcode; 109 static procenv_t olevel; |
102 103 if (rl_linefunc == NULL) 104 { 105 fprintf (stderr, "readline: readline_callback_read_char() called with no handler!\r\n"); 106 abort (); 107 } 108 | 110 111 if (rl_linefunc == NULL) 112 { 113 fprintf (stderr, "readline: readline_callback_read_char() called with no handler!\r\n"); 114 abort (); 115 } 116 |
109 eof = readline_internal_char (); | 117 memcpy ((void *)olevel, (void *)readline_top_level, sizeof (procenv_t)); 118 jcode = setjmp (readline_top_level); 119 if (jcode) 120 { 121 (*rl_redisplay_function) (); 122 _rl_want_redisplay = 0; 123 memcpy ((void *)readline_top_level, (void *)olevel, sizeof (procenv_t)); 124 return; 125 } |
110 | 126 |
127 if (RL_ISSTATE (RL_STATE_ISEARCH)) 128 { 129 eof = _rl_isearch_callback (_rl_iscxt); 130 if (eof == 0 && (RL_ISSTATE (RL_STATE_ISEARCH) == 0) && RL_ISSTATE (RL_STATE_INPUTPENDING)) 131 rl_callback_read_char (); 132 133 return; 134 } 135 else if (RL_ISSTATE (RL_STATE_NSEARCH)) 136 { 137 eof = _rl_nsearch_callback (_rl_nscxt); 138 return; 139 } 140 else if (RL_ISSTATE (RL_STATE_NUMERICARG)) 141 { 142 eof = _rl_arg_callback (_rl_argcxt); 143 if (eof == 0 && (RL_ISSTATE (RL_STATE_NUMERICARG) == 0) && RL_ISSTATE (RL_STATE_INPUTPENDING)) 144 rl_callback_read_char (); 145 /* XXX - this should handle _rl_last_command_was_kill better */ 146 else if (RL_ISSTATE (RL_STATE_NUMERICARG) == 0) 147 _rl_internal_char_cleanup (); 148 149 return; 150 } 151 else if (RL_ISSTATE (RL_STATE_MULTIKEY)) 152 { 153 eof = _rl_dispatch_callback (_rl_kscxt); /* For now */ 154 while ((eof == -1 || eof == -2) && RL_ISSTATE (RL_STATE_MULTIKEY) && _rl_kscxt && (_rl_kscxt->flags & KSEQ_DISPATCHED)) 155 eof = _rl_dispatch_callback (_rl_kscxt); 156 if (RL_ISSTATE (RL_STATE_MULTIKEY) == 0) 157 { 158 _rl_internal_char_cleanup (); 159 _rl_want_redisplay = 1; 160 } 161 } 162 else if (_rl_callback_func) 163 { 164 /* This allows functions that simply need to read an additional character 165 (like quoted-insert) to register a function to be called when input is 166 available. _rl_callback_data is simply a pointer to a struct that has 167 the argument count originally passed to the registering function and 168 space for any additional parameters. */ 169 eof = (*_rl_callback_func) (_rl_callback_data); 170 /* If the function `deregisters' itself, make sure the data is cleaned 171 up. */ 172 if (_rl_callback_func == 0) 173 { 174 if (_rl_callback_data) 175 { 176 _rl_callback_data_dispose (_rl_callback_data); 177 _rl_callback_data = 0; 178 } 179 _rl_internal_char_cleanup (); 180 } 181 } 182 else 183 eof = readline_internal_char (); 184 185 if (rl_done == 0 && _rl_want_redisplay) 186 { 187 (*rl_redisplay_function) (); 188 _rl_want_redisplay = 0; 189 } 190 |
|
111 /* We loop in case some function has pushed input back with rl_execute_next. */ 112 for (;;) 113 { 114 if (rl_done) 115 { 116 line = readline_internal_teardown (eof); 117 | 191 /* We loop in case some function has pushed input back with rl_execute_next. */ 192 for (;;) 193 { 194 if (rl_done) 195 { 196 line = readline_internal_teardown (eof); 197 |
118 (*rl_deprep_term_function) (); | 198 if (rl_deprep_term_function) 199 (*rl_deprep_term_function) (); |
119#if defined (HANDLE_SIGNALS) 120 rl_clear_signals (); 121#endif 122 in_handler = 0; 123 (*rl_linefunc) (line); 124 125 /* If the user did not clear out the line, do it for him. */ 126 if (rl_line_buffer[0]) 127 _rl_init_line_state (); 128 129 /* Redisplay the prompt if readline_handler_{install,remove} 130 not called. */ 131 if (in_handler == 0 && rl_linefunc) 132 _rl_callback_newline (); 133 } | 200#if defined (HANDLE_SIGNALS) 201 rl_clear_signals (); 202#endif 203 in_handler = 0; 204 (*rl_linefunc) (line); 205 206 /* If the user did not clear out the line, do it for him. */ 207 if (rl_line_buffer[0]) 208 _rl_init_line_state (); 209 210 /* Redisplay the prompt if readline_handler_{install,remove} 211 not called. */ 212 if (in_handler == 0 && rl_linefunc) 213 _rl_callback_newline (); 214 } |
134 if (rl_pending_input || _rl_pushed_input_available ()) | 215 if (rl_pending_input || _rl_pushed_input_available () || RL_ISSTATE (RL_STATE_MACROINPUT)) |
135 eof = readline_internal_char (); 136 else | 216 eof = readline_internal_char (); 217 else |
137 break; | 218 break; |
138 } 139} 140 141/* Remove the handler, and make sure the terminal is in its normal state. */ 142void 143rl_callback_handler_remove () 144{ 145 rl_linefunc = NULL; | 219 } 220} 221 222/* Remove the handler, and make sure the terminal is in its normal state. */ 223void 224rl_callback_handler_remove () 225{ 226 rl_linefunc = NULL; |
227 RL_UNSETSTATE (RL_STATE_CALLBACK); |
|
146 if (in_handler) 147 { 148 in_handler = 0; | 228 if (in_handler) 229 { 230 in_handler = 0; |
149 (*rl_deprep_term_function) (); | 231 if (rl_deprep_term_function) 232 (*rl_deprep_term_function) (); |
150#if defined (HANDLE_SIGNALS) 151 rl_clear_signals (); 152#endif 153 } 154} 155 | 233#if defined (HANDLE_SIGNALS) 234 rl_clear_signals (); 235#endif 236 } 237} 238 |
239_rl_callback_generic_arg * 240_rl_callback_data_alloc (count) 241 int count; 242{ 243 _rl_callback_generic_arg *arg; 244 245 arg = (_rl_callback_generic_arg *)xmalloc (sizeof (_rl_callback_generic_arg)); 246 arg->count = count; 247 248 arg->i1 = arg->i2 = 0; 249 250 return arg; 251} 252 253void _rl_callback_data_dispose (arg) 254 _rl_callback_generic_arg *arg; 255{ 256 if (arg) 257 free (arg); 258} 259 |
|
156#endif | 260#endif |