示例#1
0
static int general_allocate_string(UI *ui, const char *prompt,
                                   int prompt_freeable,
                                   enum UI_string_types type, int input_flags,
                                   char *result_buf, int minsize, int maxsize,
                                   const char *test_buf)
{
    int ret = -1;
    UI_STRING *s = general_allocate_prompt(ui, prompt, prompt_freeable,
                                           type, input_flags, result_buf);

    if (s != NULL) {
        if (allocate_string_stack(ui) >= 0) {
            s->_.string_data.result_minsize = minsize;
            s->_.string_data.result_maxsize = maxsize;
            s->_.string_data.test_buf = test_buf;
            ret = sk_UI_STRING_push(ui->strings, s);
            /* sk_push() returns 0 on error.  Let's adapt that */
            if (ret <= 0) {
                ret--;
                free_string(s);
            }
        } else
            free_string(s);
    }
    return ret;
}
示例#2
0
static int general_allocate_boolean(UI *ui,
  const char *prompt, const char *action_desc,
  const char *ok_chars, const char *cancel_chars,
  int prompt_freeable, enum UI_string_types type, int input_flags,
  char *result_buf)
  {
  int ret = -1;
  UI_STRING *s;
  const char *p;

  if (ok_chars == NULL)
    {
    UIerr(UI_F_GENERAL_ALLOCATE_BOOLEAN,ERR_R_PASSED_NULL_PARAMETER);
    }
  else if (cancel_chars == NULL)
    {
    UIerr(UI_F_GENERAL_ALLOCATE_BOOLEAN,ERR_R_PASSED_NULL_PARAMETER);
    }
  else
    {
    for(p = ok_chars; *p; p++)
      {
      if (strchr(cancel_chars, *p))
        {
        UIerr(UI_F_GENERAL_ALLOCATE_BOOLEAN,
          UI_R_COMMON_OK_AND_CANCEL_CHARACTERS);
        }
      }

    s = general_allocate_prompt(ui, prompt, prompt_freeable,
      type, input_flags, result_buf);

    if (s)
      {
      if (allocate_string_stack(ui) >= 0)
        {
        s->_.boolean_data.action_desc = action_desc;
        s->_.boolean_data.ok_chars = ok_chars;
        s->_.boolean_data.cancel_chars = cancel_chars;
        ret=sk_UI_STRING_push(ui->strings, s);
        /* sk_push() returns 0 on error.
           Let's addapt that */
        if (ret <= 0) ret--;
        }
      else
        free_string(s);
      }
    }
  return ret;
  }