Beispiel #1
0
void safe_open(std::ifstream& f, const std::string& prompt, const std::string& default_name) {
  for (;;) {
    std::string file_name = prompt_string(prompt,default_name);
    f.open(file_name.c_str());
    if (!f.fail())
      break;
    std::cout << "Opening " << file_name << " failed." << std::endl;
  }
}
Beispiel #2
0
/*
 * Display the appropriate prompt.
 */
static void
prompt(void)
{
	const char *p;

	if (ungot != NULL) {
		/*
		 * No prompt necessary if commands are from
		 * ungotten chars rather than from the user.
		 */
		return;
	}

	/*
	 * Make sure the screen is displayed.
	 */
	make_display();
	bottompos = position(BOTTOM_PLUS_ONE);

	/*
	 * If we've hit EOF on the last file and the -E flag is set, quit.
	 */
	if (get_quit_at_eof() == OPT_ONPLUS &&
	    eof_displayed() && !(ch_getflags() & CH_HELPFILE) &&
	    next_ifile(curr_ifile) == NULL_IFILE)
		quit(QUIT_OK);

	/*
	 * If the entire file is displayed and the -F flag is set, quit.
	 */
	if (quit_if_one_screen &&
	    entire_file_displayed() && !(ch_getflags() & CH_HELPFILE) &&
	    next_ifile(curr_ifile) == NULL_IFILE)
		quit(QUIT_OK);

	/*
	 * Select the proper prompt and display it.
	 */
	/*
	 * If the previous action was a forward movement,
	 * don't clear the bottom line of the display;
	 * just print the prompt since the forward movement guarantees
	 * that we're in the right position to display the prompt.
	 * Clearing the line could cause a problem: for example, if the last
	 * line displayed ended at the right screen edge without a newline,
	 * then clearing would clear the last displayed line rather than
	 * the prompt line.
	 */
	if (!forw_prompt)
		clear_bot();
	clear_cmd();
	forw_prompt = 0;
	p = prompt_string();
	if (is_filtering())
		putstr("& ");
	if (p == NULL || *p == '\0') {
		putchr(':');
	} else {
		at_enter(AT_STANDOUT);
		putstr(p);
		at_exit();
	}
	clear_eol();
}
void process_commands(std::string preface) {
  for (;;) try {
    std::string command = menu_prompt(preface);

    if (command == "an") {
      std::string n = ics::prompt_string("  Enter node name");
      g.add_node(n);
    }

    else if (command == "ae") {
      std::string o = ics::prompt_string("  Enter origin      node name");
      std::string d = ics::prompt_string("  Enter destination node name");
      int v = ics::prompt_int           ("  Enter value for this edge  ");
      g.add_edge(o,d,v);
    }

    else if (command == "rn") {
      std::string n = ics::prompt_string("  Enter node name");
      g.remove_node(n);
    }

    else if (command == "re") {
      std::string o = ics::prompt_string("  Enter origin      node name");
      std::string d = ics::prompt_string("  Enter destination node name");
      g.remove_edge(o,d);
    }

    else if (command == "x")
      g.clear();

    else if (command == "=") {
      ics::HashGraph<int> g2(ics::prompt_graph());
      g = g2;
    }

    else if (command == "m")
      std::cout << "  empty() = " << g.empty() << std::endl;

    else if (command == "#n")
      std::cout << "  node_count() = " << g.node_count() << std::endl;

    else if (command == "#e")
      std::cout << "  edge_count() = " << g.edge_count() << std::endl;

    else if (command == "n") {
      std::string n = ics::prompt_string("  Enter node name");
      std::cout << "  has_node(...) = " << g.has_node(n) << std::endl;
    }

    else if (command == "e") {
      std::string o = ics::prompt_string("  Enter origin      node name");
      std::string d = ics::prompt_string("  Enter destination node name");
      std::cout << "  has_edge(...) = " << g.has_edge(o,d) << std::endl;
    }

    else if (command == "v") {
      std::string o = ics::prompt_string("  Enter origin      node name");
      std::string d = ics::prompt_string("  Enter destination node name");
      std::cout << "  edge_value(...) = " << g.edge_value(o,d) << std::endl;
    }

    else if (command == "i") {
      std::string n = ics::prompt_string("  Enter node name");
      std::cout << "  in_degree(...) = " << g.in_degree(n) << std::endl;
    }

    else if (command == "o") {
      std::string n = ics::prompt_string("  Enter node name");
      std::cout << "  out_degree(...) = " << g.out_degree(n) << std::endl;
    }

    else if (command == "d") {
      std::string n = ics::prompt_string("  Enter node name");
      std::cout << "  degree(...) = " << g.degree(n) << std::endl;
    }

    else if (command == "<")
      std::cout << preface+"  << = " << g << std::endl;

    else if (command == "r") {
      std::cout << "  g == g = " << (g == g) << std::endl;
      std::cout << "  g != g = " << (g != g) << std::endl;

      ics::HashGraph<int> g2(ics::prompt_graph());
      std::cout << "  g == g2 = " << (g == g2) << std::endl;
      std::cout << "  g != g2 = " << (g != g2) << std::endl;
    }

    else if (command == "l") {
      std::string separator = prompt_string("  Enter separator used in file");
      std::ifstream in_file;
      ics::safe_open(in_file,"  Enter file name to read graph from","graph.txt");
      g.load(in_file,separator);
    }

    else if (command == "s") {
      std::string separator = prompt_string("  Enter separator to use in file");
      std::ofstream out_file;
      out_file.open(ics::prompt_string("  Enter file name to store graph in").c_str());
      if (out_file.fail())
        std::cout << "  Illegal file name" << std :: endl;
      else
        g.store(out_file,separator);
    }

    else if (command == "q")
      break;

    else
      std::cout << preface+"\""+command+"\" is unknown command" << std::endl;

  } catch (ics::IcsError& e) {
    std::cout << preface+"  " << e.what() << std::endl;
  }

}
Beispiel #4
0
void *prompt_name(stegdisk_t *sctx)
{
	return prompt_string("name");
}
Beispiel #5
0
void *prompt_set(stegdisk_t *sctx)
{
	return prompt_string("set");
}
Beispiel #6
0
void *prompt_blocks(stegdisk_t *sctx)
{
	return prompt_string("blocks (number, or %%age of region)");
}