69 static const
UI_METHOD *default_UI_meth=NULL;
126 static int allocate_string_stack(
UI *ui)
128 if (ui->strings == NULL)
131 if (ui->strings == NULL)
139 static UI_STRING *general_allocate_prompt(
UI *ui,
const char *prompt,
165 static int general_allocate_string(
UI *ui,
const char *prompt,
167 char *result_buf,
int minsize,
int maxsize,
const char *
test_buf)
170 UI_STRING *s = general_allocate_prompt(ui, prompt, prompt_freeable,
171 type, input_flags, result_buf);
175 if (allocate_string_stack(ui) >= 0)
190 static int general_allocate_boolean(
UI *ui,
200 if (ok_chars == NULL)
204 else if (cancel_chars == NULL)
210 for(p = ok_chars; *
p; p++)
212 if (strchr(cancel_chars, *p))
219 s = general_allocate_prompt(ui, prompt, prompt_freeable,
220 type, input_flags, result_buf);
224 if (allocate_string_stack(ui) >= 0)
244 char *result_buf,
int minsize,
int maxsize)
246 return general_allocate_string(ui, prompt, 0,
247 UIT_PROMPT, flags, result_buf, minsize, maxsize, NULL);
252 char *result_buf,
int minsize,
int maxsize)
254 char *prompt_copy=NULL;
259 if (prompt_copy == NULL)
266 return general_allocate_string(ui, prompt_copy, 1,
267 UIT_PROMPT, flags, result_buf, minsize, maxsize, NULL);
271 char *result_buf,
int minsize,
int maxsize,
const char *test_buf)
273 return general_allocate_string(ui, prompt, 0,
274 UIT_VERIFY, flags, result_buf, minsize, maxsize, test_buf);
278 char *result_buf,
int minsize,
int maxsize,
const char *test_buf)
280 char *prompt_copy=NULL;
285 if (prompt_copy == NULL)
292 return general_allocate_string(ui, prompt_copy, 1,
293 UIT_VERIFY, flags, result_buf, minsize, maxsize, test_buf);
297 const char *ok_chars,
const char *cancel_chars,
298 int flags,
char *result_buf)
300 return general_allocate_boolean(ui, prompt, action_desc,
301 ok_chars, cancel_chars, 0,
UIT_BOOLEAN, flags, result_buf);
305 const char *ok_chars,
const char *cancel_chars,
306 int flags,
char *result_buf)
308 char *prompt_copy = NULL;
309 char *action_desc_copy = NULL;
310 char *ok_chars_copy = NULL;
311 char *cancel_chars_copy = NULL;
316 if (prompt_copy == NULL)
326 if (action_desc_copy == NULL)
336 if (ok_chars_copy == NULL)
346 if (cancel_chars_copy == NULL)
353 return general_allocate_boolean(ui, prompt_copy, action_desc_copy,
354 ok_chars_copy, cancel_chars_copy, 1,
UIT_BOOLEAN, flags,
366 return general_allocate_string(ui, text, 0,
UIT_INFO, 0, NULL, 0, 0,
372 char *text_copy=NULL;
377 if (text_copy == NULL)
384 return general_allocate_string(ui, text_copy, 1,
UIT_INFO, 0, NULL,
390 return general_allocate_string(ui, text, 0,
UIT_ERROR, 0, NULL, 0, 0,
396 char *text_copy=NULL;
401 if (text_copy == NULL)
407 return general_allocate_string(ui, text_copy, 1,
UIT_ERROR, 0, NULL,
412 const char *object_name)
418 object_desc, object_name);
421 char prompt1[] =
"Enter ";
422 char prompt2[] =
" for ";
423 char prompt3[] =
":";
426 if (object_desc == NULL)
428 len =
sizeof(prompt1) - 1 + strlen(object_desc);
430 len +=
sizeof(prompt2) - 1 + strlen(object_name);
431 len +=
sizeof(prompt3) - 1;
473 static int print_error(
const char *str,
size_t len,
UI *ui)
477 memset(&uis, 0,
sizeof(uis));
496 (
int (*)(
const char *,
size_t,
void *))print_error,
549 int UI_ctrl(
UI *ui,
int cmd,
long i,
void *p,
void (*
f)(
void))
580 new_func, dup_func, free_func);
595 default_UI_meth=meth;
600 if (default_UI_meth == NULL)
604 return default_UI_meth;
625 memset(ui_method, 0,
sizeof(*ui_method));
637 ui_method->
name = NULL;
847 int l = strlen(result);
866 if (l < uis->
_.string_data.result_minsize)
871 number1,
" to ",number2,
" characters");
879 number1,
" to ",number2,
" characters");
904 for(p = result; *
p; p++)