Example #1
0
static char *
nogui_prompt_for (const char *msg, const char *default_string)
{
  char *answer;

  if (default_string)
    printf ("%s [%s] : ", msg, default_string);
  else
    printf ("%s : ", msg);

  answer = read_stdin_line ();
  if (answer == NULL)
    return strdup ((default_string != NULL) ? default_string : "");
  else
    return strdup (answer);
}
Example #2
0
/* FIXME - this could use some enhancement to actually use the other
   args */
static char *
nogui_fileselect (const char *title, const char *descr,
		  char *default_file, char *default_ext,
		  const char *history_tag, int flags)
{
  char *answer;

  if (default_file)
    printf ("%s [%s] : ", title, default_file);
  else
    printf ("%s : ", title);

  answer = read_stdin_line ();
  if (answer == NULL)
    return (default_file != NULL) ? strdup (default_file) : NULL;
  else
    return strdup (answer);
}
Example #3
0
static int
nogui_confirm_dialog (char *msg, ...)
{
  char *answer;
  int ret = 0;
  bool valid_answer = false;
  va_list args;

  do
    {
      va_start (args, msg);
      vprintf (msg, args);
      va_end (args);

      printf (" ? 0=cancel 1 = ok : ");

      answer = read_stdin_line ();

      if (answer == NULL)
        continue;

      if (answer[0] == '0' && answer[1] == '\0')
        {
          ret = 0;
          valid_answer = true;
        }

      if (answer[0] == '1' && answer[1] == '\0')
        {
          ret = 1;
          valid_answer = true;
        }

      free (answer);
    }
  while (!valid_answer);
  return ret;
}
Example #4
0
void run_commands_from_stdin()
{
    while (true) {
        Value line;
        read_stdin_line(&line);
        if (!is_string(&line))
            break;

        Value reply;
        do_admin_command(&line, &reply);

        if (is_null(&reply))
            ; // no op
        else if (is_string(&reply))
            std::cout << as_string(&reply) << std::endl;
        else
            std::cout << to_string(&reply) << std::endl;

        // We need to tell the stdout reader that we have finished. The proper
        // way to do this would probably be to format the entire output as an
        // escapted string. But, this is what we'll do for now:
        std::cout << ":done" << std::endl;
    }
}