Exemplo n.º 1
0
/* Dispatch actions according to program flags (NOT commands or
 * command options).
 */
static void
cli_context_flag_dispatch (cli_context_t *ctx, gint in_argc, gchar **in_argv)
{
	command_t *cmd;
	gboolean check;

	GOptionEntry flagdefs[] = {
		{ "help",    'h', 0, G_OPTION_ARG_NONE, NULL,
		  _("Display this help and exit."), NULL },
		{ "version", 'v', 0, G_OPTION_ARG_NONE, NULL,
		  _("Output version information and exit."), NULL },
		{ NULL }
	};

	/* Include one command token as a workaround for the bug that
	 * the option parser does not parse commands starting with a
	 * flag properly (e.g. "-p foo arg1"). Will be skipped by the
	 * command utils. */
	cmd = command_new (flagdefs, in_argc + 1, in_argv - 1);

	if (!cmd) {
		/* An error message has already been printed, so we just return. */
		return;
	}

	if (command_flag_boolean_get (cmd, "help", &check) && check) {
		if (command_arg_count (cmd) >= 1) {
			help_command (ctx, cli_context_command_names (ctx),
			              command_argv_get (cmd), command_arg_count (cmd),
			              CMD_TYPE_COMMAND);
		} else {
			/* FIXME: explain -h and -v flags here (reuse help_command code?) */
			g_printf (_("usage: xmms2 [<command> [args]]\n\n"));
			g_printf (_("XMMS2 CLI, the awesome command-line XMMS2 client from the future, "
			            "v" XMMS_VERSION ".\n\n"));
			g_printf (_("If given a command, runs it inline and exit.\n"));
			g_printf (_("If not, enters a shell-like interface to execute commands.\n\n"));
			g_printf (_("Type 'help <command>' for detailed help about a command.\n"));
		}
	} else if (command_flag_boolean_get (cmd, "version", &check) && check) {
		g_printf (_("XMMS2 CLI version " XMMS_VERSION "\n"));
		g_printf (_("Copyright (C) 2008-2014 XMMS2 Team\n"));
		g_printf (_("This is free software; see the source for copying conditions.\n"));
		g_printf (_("There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A\n"
		            "PARTICULAR PURPOSE.\n"));
		/* FIXME: compiled against? use RL_READLINE_VERSION? */
		g_printf (_(" Using readline version %s\n"), rl_library_version);
	} else {
		/* Call help to print the "no such command" error */
		/* FIXME: Could be a more helpful "invalid flag"?*/
		help_command (ctx, cli_context_command_names (ctx),
		              in_argv, in_argc, CMD_TYPE_COMMAND);
	}

	command_free (cmd);
}
Exemplo n.º 2
0
static void
cli_context_command_dispatch (cli_context_t *ctx, gint in_argc, gchar **in_argv)
{
	command_action_t *action;
	command_trie_match_type_t match;
	gint argc;
	gchar *tmp_argv[in_argc+1];
	gchar **argv;

	/* The arguments will be updated by command_trie_find and
	 * init_context_from_args, so we make a copy. */
	memcpy (tmp_argv, in_argv, in_argc * sizeof (gchar *));
	tmp_argv[in_argc] = NULL;

	argc = in_argc;
	argv = tmp_argv;

	/* This updates argv and argc so that they start at the first non-command
	 * token. */
	match = cli_context_find_command (ctx, &argv, &argc, &action);
	if (match == COMMAND_TRIE_MATCH_ACTION) {
		gboolean help;
		gboolean need_io;
		command_t *cmd;

		/* Include one command token as a workaround for the bug that
		 * the option parser does not parse commands starting with a
		 * flag properly (e.g. "-p foo arg1"). Will be skipped by the
		 * command utils. */
		cmd = command_new (action->argdefs, argc + 1, argv - 1);

		if (cmd) {
			if (command_flag_boolean_get (cmd, "help", &help) && help) {
				/* Help flag passed, bypass action and show help */
				/* FIXME(g): select aliasnames list if it's an alias */
				help_command (ctx, cli_context_command_names (ctx),
				              in_argv, in_argc, CMD_TYPE_COMMAND);
			} else if (cli_context_command_runnable (ctx, action)) {
				/* All fine, run the command */
				command_name_set (cmd, action->name);
				cli_context_loop_suspend (ctx);
				need_io = action->callback (ctx, cmd);
				if (!need_io) {
					cli_context_loop_resume (ctx);
				}
			}

			command_free (cmd);
		}
	} else {
		/* Call help to print the "no such command" error */
		help_command (ctx, cli_context_command_names (ctx),
		              in_argv, in_argc, CMD_TYPE_COMMAND);
	}
}
Exemplo n.º 3
0
void
command_dispatch (cli_infos_t *infos, gint in_argc, gchar **in_argv)
{
	command_action_t *action;
	command_trie_match_type_t match;
	gint argc;
	gchar **argv;

	gboolean auto_complete;

	/* The arguments will be updated by command_trie_find. */
	argc = in_argc;
	argv = in_argv;
	auto_complete = configuration_get_boolean (infos->config,
	                                           "AUTO_UNIQUE_COMPLETE");
	match = command_trie_find (infos->commands, &argv, &argc,
	                            auto_complete, &action);

	if (match == COMMAND_TRIE_MATCH_ACTION) {

		gboolean help;
		gboolean need_io;
		command_context_t *ctx;

		/* Include one command token as a workaround for the bug that
		 * the option parser does not parse commands starting with a
		 * flag properly (e.g. "-p foo arg1"). Will be skipped by the
		 * command utils. */
		ctx = init_context_from_args (action->argdefs, argc + 1, argv - 1);
		ctx->name = g_strdup (action->name);

		if (command_flag_boolean_get (ctx, "help", &help) && help) {
			/* Help flag passed, bypass action and show help */
			/* FIXME(g): select aliasnames list if it's an alias */
			help_command (infos, infos->cmdnames, in_argv, in_argc, CMD_TYPE_COMMAND);
		} else if (command_runnable (infos, action)) {
			/* All fine, run the command */
			cli_infos_loop_suspend (infos);
			need_io = action->callback (infos, ctx);
			if (!need_io) {
				cli_infos_loop_resume (infos);
			}
		}

		command_context_free (ctx);
	} else {
		/* Call help to print the "no such command" error */
		help_command (infos, infos->cmdnames, in_argv, in_argc, CMD_TYPE_COMMAND);
	}
}
Exemplo n.º 4
0
Arquivo: xbox.cpp Projeto: RalfVB/mame
void xbox_base_state::xbox_debug_commands(int ref, int params, const char **param)
{
	if (params < 1)
		return;
	if (strcmp("dump_string", param[0]) == 0)
		dump_string_command(ref, params - 1, param + 1);
	else if (strcmp("dump_process", param[0]) == 0)
		dump_process_command(ref, params - 1, param + 1);
	else if (strcmp("dump_list", param[0]) == 0)
		dump_list_command(ref, params - 1, param + 1);
	else if (strcmp("dump_dpc", param[0]) == 0)
		dump_dpc_command(ref, params - 1, param + 1);
	else if (strcmp("dump_timer", param[0]) == 0)
		dump_timer_command(ref, params - 1, param + 1);
	else if (strcmp("curthread", param[0]) == 0)
		curthread_command(ref, params - 1, param + 1);
	else if (strcmp("irq", param[0]) == 0)
		generate_irq_command(ref, params - 1, param + 1);
	else if (strcmp("nv2a_combiners", param[0]) == 0)
		nv2a_combiners_command(ref, params - 1, param + 1);
	else if (strcmp("waitvblank", param[0]) == 0)
		waitvblank_command(ref, params - 1, param + 1);
	else if (strcmp("grab_texture", param[0]) == 0)
		grab_texture_command(ref, params - 1, param + 1);
	else if (strcmp("grab_vprog", param[0]) == 0)
		grab_vprog_command(ref, params - 1, param + 1);
	else if (strcmp("vprogdis", param[0]) == 0)
		vprogdis_command(ref, params - 1, param + 1);
	else
		help_command(ref, params - 1, param + 1);
}
Exemplo n.º 5
0
void options_parse(int argc, char *argv[])
{
  int option_index= 0;
  int option_rv;

  memcached_programs_help_st help_options[]=
  {
    {0},
  };

  static struct option long_options[]=
    {
      {(OPTIONSTRING)"version", no_argument, NULL, OPT_VERSION},
      {(OPTIONSTRING)"help", no_argument, NULL, OPT_HELP},
      {(OPTIONSTRING)"verbose", no_argument, &opt_verbose, OPT_VERBOSE},
      {(OPTIONSTRING)"debug", no_argument, &opt_verbose, OPT_DEBUG},
      {(OPTIONSTRING)"servers", required_argument, NULL, OPT_SERVERS},
      {(OPTIONSTRING)"flag", no_argument, &opt_displayflag, OPT_FLAG},
      {(OPTIONSTRING)"hash", required_argument, NULL, OPT_HASH},
      {(OPTIONSTRING)"binary", no_argument, NULL, OPT_BINARY},
      {0, 0, 0, 0},
    };

  while (1) 
  {
    option_rv= getopt_long(argc, argv, "Vhvds:", long_options, &option_index);
    if (option_rv == -1) break;
    switch (option_rv)
    {
    case 0:
      break;
    case OPT_BINARY:
      opt_binary = 1;
      break;
    case OPT_VERBOSE: /* --verbose or -v */
      opt_verbose = OPT_VERBOSE;
      break;
    case OPT_DEBUG: /* --debug or -d */
      opt_verbose = OPT_DEBUG;
      break;
    case OPT_VERSION: /* --version or -V */
      version_command(PROGRAM_NAME);
      break;
    case OPT_HELP: /* --help or -h */
      help_command(PROGRAM_NAME, PROGRAM_DESCRIPTION, long_options, help_options);
      break;
    case OPT_SERVERS: /* --servers or -s */
      opt_servers= strdup(optarg);
      break;
    case OPT_HASH:
      opt_hash= strdup(optarg);
      break;
    case '?':
      /* getopt_long already printed an error message. */
      exit(1);
    default:
      abort();
    }
  }
}
	void help()
	{
		//print command-specific help if available, otherwise list commands
		if (help_command(get_arg(1))) {
			return;
		}
		std::stringstream ss;
		bool show_unavail = show_unavailable_ || get_arg(1) == "all";
		for (typename command_map::value_type i : command_map_) {
			if (show_unavail || is_enabled(i.second)) {
				ss << i.first;
				//if (!i.second.usage.empty()) {
				//	ss << " " << i.second.usage;
				//}
				//uncomment the above to display usage information in command list
				//which might clutter it somewhat
				if (!i.second.flags.empty()) {
					ss << " (" << i.second.flags << ") ";
				}
				ss << "; ";
			}
		}
		utils::string_map symbols;
		symbols["flags_description"] = get_flags_description();
		symbols["list_of_commands"] = ss.str();
		symbols["help_command"] = cmd_prefix_ + "help";
		print(_("help"), VGETTEXT("Available commands $flags_description:\n$list_of_commands", symbols));
		print(_("help"), VGETTEXT("Type $help_command <command> for more info.", symbols));
	}
Exemplo n.º 7
0
gboolean
cli_help (cli_context_t *ctx, command_t *cmd)
{
	cmd_type_t cmdtype;
	GList *names;
	gint num_args;
	gboolean alias;

	num_args = command_arg_count (cmd);

	if (command_flag_boolean_get (cmd, "alias", &alias) && alias) {
		names = cli_context_alias_names (ctx);
		cmdtype = CMD_TYPE_ALIAS;
	} else {
		names = cli_context_command_names (ctx);
		cmdtype = CMD_TYPE_COMMAND;
	}

	/* No argument, display the list of commands */
	if (num_args == 0) {
		help_list (names, NULL, cmdtype);
	} else {
		help_command (ctx, names, command_argv_get (cmd), num_args, cmdtype);
	}

	/* No data pending */
	return FALSE;
}
Exemplo n.º 8
0
int Reader(CommandBase* commands [], int num_commands, int argc, const char** argv)
{
	std::vector<const char*> inputs;
	CommandBase* last_command = NULL;
	CommandHelp help_command(commands,num_commands);

	int command_count = 0;
	bool command_chosen = false;
	for(int i=1; i<argc; i++) {
        double tmp;
		if(argv[i][0] == '-' && !string_is_double(argv[i],tmp)) { //command
            if(string_is_double(argv[i],tmp))
			command_chosen = false;
			//check for help queries first
			if(0 == strcmp("help",&argv[i][1])) {
				if(last_command != NULL) {
					int res = DoCommand(last_command,inputs);
					if(res <= 0) return res;
				}
				last_command = &help_command;
				command_count++;
				command_chosen = true;
			}
			//search through rest of commands
			for(int k=0; k<num_commands && !command_chosen; k++) {
				if(0 == strcmp(commands[k]->Name(),&argv[i][1])) {
					//we've found a command
					if(last_command != NULL) {
						int res = DoCommand(last_command,inputs);
						if(res <= 0) return res;
					}
					last_command = commands[k];
					command_chosen = true;
					command_count++;
				}
			}
			if(!command_chosen) {
				printf("Unknown command %s\n", argv[i]);
				PrintCommands(commands, num_commands);
				return -1;
			}
		}
		else {  //add an argument
			inputs.push_back(argv[i]);
			command_chosen = false;
		}
	}
	if(command_count == 0) {
		if(inputs.size() > 0)
			cout<<"Some stray elements were given on the command line"<<endl;
		PrintCommands(commands, num_commands);
	}
	else {
		assert(last_command != NULL);
		int res = DoCommand(last_command,inputs);
		if(res <= 0) return res;
	}
	return 0;
}
Exemplo n.º 9
0
static int_fast8_t help_cmd()
{

  if((data.cmdargtoken[1].type == 3)||(data.cmdargtoken[1].type == 4)||(data.cmdargtoken[1].type == 5))
    help_command(data.cmdargtoken[1].val.string);
  else
    list_commands();

  return 0;
}
Exemplo n.º 10
0
Arquivo: main.c Projeto: issey1022/os
/*!
 * @brief IRQハンドラ
 * @param[in] なし
 * @param[out] なし
 * @return なし
 * @note UART関連のレジスタであるIIRレジスタから割込みタイプの取得
 *       (IIRレジスタは下位5ビットで割込みタイプを保持している)
 *       シリアル受信割込み : 0x2
 *       タイムアウト割込み(シリアル受信割込みを有効化すると同時に有効化される) : 0x6
 */
void uart_handler(void)
{
  unsigned char c;
  static char buf[32];
  static int len;
  int it_type;

	it_type = (REG8_READ(UIIR) & 0x3E) >> 1;

  if (it_type == 2 || it_type == 6) {

		c = getc(); /* 受信FIFOからデータを読み出す事によって,割込み要因をクリア */

		if (c != '\n') {
			buf[len++] = c;
    }
    else {
			buf[len++] = '\0';
			/* echoコマンドの場合 */
    	if (!strncmp(buf, "echo ", 5)) {
      	echo_command(buf); /* echoコマンド(標準出力にテキストを出力する)呼び出し */
    	}
			/* helpコマンドの場合 */
   		else if (!strncmp(buf, "help", 4)) {
     		help_command(&buf[4]); /* helpコマンド呼び出し */
    	}
#ifdef TSK_LIBRARY
			/* runコマンドの場合 */
			else if (!strncmp(buf, "run", 3)) {
				run_command(&buf[3]); /* runコマンド(タスクセットの起動)呼び出し */
			}
#endif
			/* sendlogの場合 */
			else if (!strncmp(buf, "sendlog", 7)) {
      	sendlog_command(); /* sendlogコマンド(xmodem送信モード)呼び出し */
			}
			/* 本システムに存在しないコマンド */
    	else {
      	puts("command unknown.\n");
    	}
			puts("> ");
			len = 0;
    }
  }
	else {
		DEBUG_LEVEL1_OUTMSG(" not uart3 handler : uart_handler().\n");
	}
}
Exemplo n.º 11
0
void options_parse(int argc, char *argv[])
{
  int option_index= 0;
  int option_rv;

  memcached_programs_help_st help_options[]=
  {
    {0},
  };

  static struct option long_options[]=
    {
      {"version", no_argument, NULL, OPT_VERSION},
      {"help", no_argument, NULL, OPT_HELP},
      {"verbose", no_argument, &opt_verbose, OPT_VERBOSE},
      {"debug", no_argument, &opt_verbose, OPT_DEBUG},
      {0, 0, 0, 0},
    };

  while (1) 
  {
    option_rv= getopt_long(argc, argv, "Vhvds:", long_options, &option_index);
    if (option_rv == -1) break;
    switch (option_rv)
    {
    case 0:
      break;
    case OPT_VERBOSE: /* --verbose or -v */
      opt_verbose = OPT_VERBOSE;
      break;
    case OPT_DEBUG: /* --debug or -d */
      opt_verbose = OPT_DEBUG;
      break;
    case OPT_VERSION: /* --version or -V */
      version_command(PROGRAM_NAME);
      break;
    case OPT_HELP: /* --help or -h */
      help_command(PROGRAM_NAME, PROGRAM_DESCRIPTION, long_options, help_options);
      break;
    case '?':
      /* getopt_long already printed an error message. */
      exit(1);
    default:
      abort();
    }
  }
}
Exemplo n.º 12
0
static void options_parse(int argc, char *argv[])
{
  memcached_programs_help_st help_options[]=
  {
    {0},
  };

  int option_index= 0;
  int option_rv;

  while (1) 
  {
    option_rv= getopt_long(argc, argv, "Vhvds:a", long_options, &option_index);
    if (option_rv == -1) break;
    switch (option_rv)
    {
    case 0:
      break;
    case OPT_VERBOSE: /* --verbose or -v */
      opt_verbose = OPT_VERBOSE;
      break;
    case OPT_DEBUG: /* --debug or -d */
      opt_verbose = OPT_DEBUG;
      break;
    case OPT_VERSION: /* --version or -V */
      version_command(PROGRAM_NAME);
      break;
    case OPT_HELP: /* --help or -h */
      help_command(PROGRAM_NAME, PROGRAM_DESCRIPTION, long_options, help_options);
      break;
    case OPT_SERVERS: /* --servers or -s */
      opt_servers= strdup(optarg);
      break;
    case OPT_ANALYZE: /* --analyze or -a */
      opt_analyze= OPT_ANALYZE;
      break;
    case '?':
      /* getopt_long already printed an error message. */
      exit(1);
    default:
      abort();
    }
  }
}
Exemplo n.º 13
0
void options_parse(int argc, char *argv[])
{
  int option_index= 0;
  int option_rv;

  memcached_programs_help_st help_options[]=
  {
    {0},
  };

  static struct option long_options[]=
    {
      {"version", no_argument, NULL, OPT_VERSION},
      {"help", no_argument, NULL, OPT_HELP},
      {"verbose", no_argument, &opt_verbose, OPT_VERBOSE},
      {"debug", no_argument, &opt_verbose, OPT_DEBUG},
      {"servers", required_argument, NULL, OPT_SERVERS},
      {"flag", required_argument, NULL, OPT_FLAG},
      {"expire", required_argument, NULL, OPT_EXPIRE},
      {"set",  no_argument, NULL, OPT_SET},
      {"add",  no_argument, NULL, OPT_ADD},
      {"replace",  no_argument, NULL, OPT_REPLACE},
      {"hash", required_argument, NULL, OPT_HASH},
      {"binary", no_argument, NULL, OPT_BINARY},
      {0, 0, 0, 0},
    };

  while (1) 
  {
    option_rv= getopt_long(argc, argv, "Vhvds:", long_options, &option_index);

    if (option_rv == -1) break;

    switch (option_rv)
    {
    case 0:
      break;
    case OPT_BINARY:
      opt_binary = 1;
      break;
    case OPT_VERBOSE: /* --verbose or -v */
      opt_verbose = OPT_VERBOSE;
      break;
    case OPT_DEBUG: /* --debug or -d */
      opt_verbose = OPT_DEBUG;
      break;
    case OPT_VERSION: /* --version or -V */
      version_command(PROGRAM_NAME);
      break;
    case OPT_HELP: /* --help or -h */
      help_command(PROGRAM_NAME, PROGRAM_DESCRIPTION, long_options, help_options);
      break;
    case OPT_SERVERS: /* --servers or -s */
      opt_servers= strdup(optarg);
      break;
    case OPT_FLAG: /* --flag */
      opt_flags= (uint32_t)strtol(optarg, (char **)NULL, 16);
      break;
    case OPT_EXPIRE: /* --expire */
      opt_expires= (time_t)strtoll(optarg, (char **)NULL, 10);
      break;
    case OPT_SET:
      opt_method= OPT_SET;
      break;
    case OPT_REPLACE:
      opt_method= OPT_REPLACE;
      break;
    case OPT_ADD:
      opt_method= OPT_ADD;
    case OPT_HASH:
      opt_hash= strdup(optarg);
      break;
    case '?':
      /* getopt_long already printed an error message. */
      exit(1);
    default:
      abort();
    }
  }
}
Exemplo n.º 14
0
int main(int argc, char *argv[])
{
  memcached_return rc;
  memcached_st *memc;
  memcached_stat_st *stat;
  memcached_server_st *servers;
  memcached_server_st *server_list;
  memcached_analysis_st *report;

  options_parse(argc, argv);

  if (!opt_servers)
  {
    char *temp;

    if ((temp= getenv("MEMCACHED_SERVERS")))
      opt_servers= strdup(temp);
    else
    {
      fprintf(stderr, "No Servers provided\n\n");
      help_command(PROGRAM_NAME, PROGRAM_DESCRIPTION, long_options, 0);
      exit(1);
    }
  }

  memc= memcached_create(NULL);

  servers= memcached_servers_parse(opt_servers);
  memcached_server_push(memc, servers);
  memcached_server_list_free(servers);

  stat= memcached_stat(memc, NULL, &rc);

  if (rc != MEMCACHED_SUCCESS && rc != MEMCACHED_SOME_ERRORS)
  {
    printf("Failure to communicate with servers (%s)\n",
           memcached_strerror(memc, rc));
    exit(1);
  }

  server_list= memcached_server_list(memc);

  if (opt_analyze)
  {
    report= memcached_analyze(memc, stat, &rc);
    if (rc != MEMCACHED_SUCCESS || report == NULL)
    {
      printf("Failure to analyze servers (%s)\n",
             memcached_strerror(memc, rc));
      exit(1);
    }
    print_analysis_report(memc, report, server_list);
    free(report);
  }
  else
    print_server_listing(memc, stat, server_list);

  free(stat);
  free(opt_servers);

  memcached_free(memc);

  return 0;
}
Exemplo n.º 15
0
/**
 * \brief Main method
 */
int main(int argc, char *argv[]) {
	debug(LOG_DEBUG, DEBUG_LOG, 0, "mount utility");
	int	c;
	int	longindex;
	putenv((char *)"POSIXLY_CORRECT=1");	// cast to silence compiler
	while (EOF != (c = getopt_long(argc, argv, "c:dh", longopts,
		&longindex))) {
		switch (c) {
		case 'c':
			Configuration::set_default(std::string(optarg));
			break;
		case 'd':
			debuglevel = LOG_DEBUG;
			break;
		case 'h':
			usage(argv[0]);
			return EXIT_SUCCESS;
		case 'n':
			dryrun = true;
			break;
		case 'f':
			decimal = true;
			break;
		case 'w':
			await_completion = true;
			break;
		case 1:
			switch (longindex) {
			}
			break;
		}
	}

	// next argument must be the command
	if (argc <= optind) {
		throw std::runtime_error("missing command argument");
	}
	std::string	command(argv[optind++]);

	// call the command specific functions
	if (command == "help") {
		return help_command();
	}

	// the other commands need a repository
	astro::module::Repository	repository;
	astro::module::Devices	devices(repository);

	// list command
	if (command == "list") {
		return list_command(devices);
	}

	// other commands need a mount url 
	if (argc <= optind) {
		throw std::runtime_error("missing mount URL");
	}
	DeviceName	mountname(argv[optind++]);
	if (!mountname.hasType(DeviceName::Mount)) {
		throw std::runtime_error("not a mount device name");
	}
	debug(LOG_DEBUG, DEBUG_LOG, 0, "mount device name: %s",
		mountname.toString().c_str());

	// use the Devices class to get the mount associated with this name
	MountPtr	mount = devices.getMount(mountname);
	if (command == "get") {
		return get_command(mount);
	}
	if (command == "cancel") {
		return cancel_command(mount);
	}
	if (command == "wait") {
		return wait_command(mount, true);
	}
	if (command == "set") {
		if (argc < optind + 2) {
			throw std::runtime_error("two angle arguments missing");
		}
		RaDec	radec;
		radec.ra() = Angle::hms_to_angle(argv[optind++]);
		radec.dec() = Angle::dms_to_angle(argv[optind++]);
		return set_command(mount, radec);
	}

	throw std::runtime_error("unknown command");
}
Exemplo n.º 16
0
	void print_usage()
	{
		help_command(get_cmd());
	}
Exemplo n.º 17
0
static void options_parse(int argc, char *argv[])
{
  int option_index= 0;
  int option_rv;

  memcached_programs_help_st help_options[]=
  {
    {0},
  };

  static struct option long_options[]=
    {
      {(OPTIONSTRING)"version", no_argument, NULL, OPT_VERSION},
      {(OPTIONSTRING)"help", no_argument, NULL, OPT_HELP},
      {(OPTIONSTRING)"verbose", no_argument, &opt_verbose, OPT_VERBOSE},
      {(OPTIONSTRING)"debug", no_argument, &opt_verbose, OPT_DEBUG},
      {(OPTIONSTRING)"servers", required_argument, NULL, OPT_SERVERS},
      {(OPTIONSTRING)"flag", required_argument, NULL, OPT_FLAG},
      {(OPTIONSTRING)"expire", required_argument, NULL, OPT_EXPIRE},
      {(OPTIONSTRING)"set",  no_argument, NULL, OPT_SET},
      {(OPTIONSTRING)"add",  no_argument, NULL, OPT_ADD},
      {(OPTIONSTRING)"replace",  no_argument, NULL, OPT_REPLACE},
      {(OPTIONSTRING)"hash", required_argument, NULL, OPT_HASH},
      {(OPTIONSTRING)"binary", no_argument, NULL, OPT_BINARY},
      {(OPTIONSTRING)"username", required_argument, NULL, OPT_USERNAME},
      {(OPTIONSTRING)"password", required_argument, NULL, OPT_PASSWD},
      {0, 0, 0, 0},
    };

  while (1)
  {
    option_rv= getopt_long(argc, argv, "Vhvds:", long_options, &option_index);

    if (option_rv == -1) break;

    switch (option_rv)
    {
    case 0:
      break;
    case OPT_BINARY:
      opt_binary = 1;
      break;
    case OPT_VERBOSE: /* --verbose or -v */
      opt_verbose = OPT_VERBOSE;
      break;
    case OPT_DEBUG: /* --debug or -d */
      opt_verbose = OPT_DEBUG;
      break;
    case OPT_VERSION: /* --version or -V */
      version_command(PROGRAM_NAME);
      break;
    case OPT_HELP: /* --help or -h */
      help_command(PROGRAM_NAME, PROGRAM_DESCRIPTION, long_options, help_options);
      break;
    case OPT_SERVERS: /* --servers or -s */
      opt_servers= strdup(optarg);
      break;
    case OPT_FLAG: /* --flag */
      {
        bool strtol_error;
        opt_flags= (uint32_t)strtol_wrapper(optarg, 16, &strtol_error);
        if (strtol_error == true)
        {
          fprintf(stderr, "Bad value passed via --flag\n");
          exit(1);
        }
        break;
      }
    case OPT_EXPIRE: /* --expire */
      {
        bool strtol_error;
        opt_expires= (time_t)strtol_wrapper(optarg, 16, &strtol_error);
        if (strtol_error == true)
        {
          fprintf(stderr, "Bad value passed via --flag\n");
          exit(1);
        }
      }
    case OPT_SET:
      opt_method= OPT_SET;
      break;
    case OPT_REPLACE:
      opt_method= OPT_REPLACE;
      break;
    case OPT_ADD:
      opt_method= OPT_ADD;
      break;
    case OPT_HASH:
      opt_hash= strdup(optarg);
      break;
    case OPT_USERNAME:
      opt_username= optarg;
      break;
    case OPT_PASSWD:
      opt_passwd= optarg;
      break;
   case '?':
      /* getopt_long already printed an error message. */
      exit(1);
    default:
      abort();
    }
  }
}
Exemplo n.º 18
0
void options_parse(int argc, char *argv[])
{
  memcached_programs_help_st help_options[]=
  {
    {0},
  };

  static struct option long_options[]=
  {
    {(OPTIONSTRING)"version", no_argument, NULL, OPT_VERSION},
    {(OPTIONSTRING)"help", no_argument, NULL, OPT_HELP},
    {(OPTIONSTRING)"verbose", no_argument, &opt_verbose, OPT_VERBOSE},
    {(OPTIONSTRING)"debug", no_argument, &opt_verbose, OPT_DEBUG},
    {(OPTIONSTRING)"servers", required_argument, NULL, OPT_SERVERS},
    {(OPTIONSTRING)"expire", required_argument, NULL, OPT_EXPIRE},
    {(OPTIONSTRING)"binary", no_argument, NULL, OPT_BINARY},
    {(OPTIONSTRING)"username", required_argument, NULL, OPT_USERNAME},
    {(OPTIONSTRING)"password", required_argument, NULL, OPT_PASSWD},
    {0, 0, 0, 0},
  };
  int option_index= 0;
  int option_rv;

  while (1)
  {
    option_rv= getopt_long(argc, argv, "Vhvds:", long_options, &option_index);
    if (option_rv == -1) break;
    switch (option_rv)
    {
    case 0:
      break;
    case OPT_BINARY:
      opt_binary = 1;
      break;
    case OPT_VERBOSE: /* --verbose or -v */
      opt_verbose = OPT_VERBOSE;
      break;
    case OPT_DEBUG: /* --debug or -d */
      opt_verbose = OPT_DEBUG;
      break;
    case OPT_VERSION: /* --version or -V */
      version_command(PROGRAM_NAME);
      break;
    case OPT_HELP: /* --help or -h */
      help_command(PROGRAM_NAME, PROGRAM_DESCRIPTION, long_options, help_options);
      break;
    case OPT_SERVERS: /* --servers or -s */
      opt_servers= strdup(optarg);
      break;
    case OPT_EXPIRE: /* --expire */
      opt_expire= (time_t)strtoll(optarg, (char **)NULL, 10);
      break;
    case OPT_USERNAME:
      opt_username= optarg;
      break;
    case OPT_PASSWD:
      opt_passwd= optarg;
      break;
    case '?':
      /* getopt_long already printed an error message. */
      exit(1);
    default:
      abort();
    }
  }
}
Exemplo n.º 19
0
void options_parse(int argc, char *argv[])
{
  memcached_programs_help_st help_options[]=
  {
    {0},
  };

  static struct option long_options[]=
    {
      {"concurrency", required_argument, NULL, OPT_SLAP_CONCURRENCY},
      {"debug", no_argument, &opt_verbose, OPT_DEBUG},
      {"execute-number", required_argument, NULL, OPT_SLAP_EXECUTE_NUMBER},
      {"flag", no_argument, &opt_displayflag, OPT_FLAG},
      {"flush", no_argument, &opt_flush, OPT_FLUSH},
      {"help", no_argument, NULL, OPT_HELP},
      {"initial-load", required_argument, NULL, OPT_SLAP_INITIAL_LOAD}, /* Number to load initially */
      {"non-blocking", no_argument, &opt_non_blocking_io, OPT_SLAP_NON_BLOCK},
      {"servers", required_argument, NULL, OPT_SERVERS},
      {"tcp-nodelay", no_argument, &opt_tcp_nodelay, OPT_SLAP_TCP_NODELAY},
      {"test", required_argument, NULL, OPT_SLAP_TEST},
      {"verbose", no_argument, &opt_verbose, OPT_VERBOSE},
      {"version", no_argument, NULL, OPT_VERSION},
      {"binary", no_argument, NULL, OPT_BINARY},
      {0, 0, 0, 0},
    };

  int option_index= 0;
  int option_rv;

  while (1) 
  {
    option_rv= getopt_long(argc, argv, "Vhvds:", long_options, &option_index);
    if (option_rv == -1) break;
    switch (option_rv)
    {
    case 0:
      break;
    case OPT_BINARY:
      opt_binary = 1;
      break;
    case OPT_VERBOSE: /* --verbose or -v */
      opt_verbose = OPT_VERBOSE;
      break;
    case OPT_DEBUG: /* --debug or -d */
      opt_verbose = OPT_DEBUG;
      break;
    case OPT_VERSION: /* --version or -V */
      version_command(PROGRAM_NAME);
      break;
    case OPT_HELP: /* --help or -h */
      help_command(PROGRAM_NAME, PROGRAM_DESCRIPTION, long_options, help_options);
      break;
    case OPT_SERVERS: /* --servers or -s */
      opt_servers= strdup(optarg);
      break;
    case OPT_SLAP_TEST:
      if (!strcmp(optarg, "get"))
        opt_test= GET_TEST ;
      else if (!strcmp(optarg, "set"))
        opt_test= SET_TEST;
      else 
      {
        fprintf(stderr, "Your test, %s, is not a known test\n", optarg);
        exit(1);
      }
      break;
    case OPT_SLAP_CONCURRENCY:
      opt_concurrency= strtol(optarg, (char **)NULL, 10);
    case OPT_SLAP_EXECUTE_NUMBER:
      opt_execute_number= strtol(optarg, (char **)NULL, 10);
      break;
    case OPT_SLAP_INITIAL_LOAD:
      opt_createial_load= strtol(optarg, (char **)NULL, 10);
      break;
    case '?':
      /* getopt_long already printed an error message. */
      exit(1);
    default:
      abort();
    }
  }

  if (opt_test == GET_TEST && opt_createial_load == 0)
    opt_createial_load= DEFAULT_INITIAL_LOAD;

  if (opt_execute_number == 0)
    opt_execute_number= DEFAULT_EXECUTE_NUMBER;

  if (opt_concurrency == 0)
    opt_concurrency= DEFAULT_CONCURRENCY;
}
Exemplo n.º 20
0
/*
 * void execute_commands()
 *
 * Processes commands until the QUIT command is entered
 *
 */
void execute_commands() {
  char buffer[MAX_INPUT_STRING];
  int num_chars = 0;

  while ( TRUE ) {
	
	printf( PROMPT );

	scanf("%s", buffer);
	num_chars = strlen(buffer);
	if ( is_valid_number( buffer ) ) {
	  push( atoi(buffer) );
	  continue;
	}

	if ( num_chars > 1 ) {
	  printf( BAD_INPUT_MSG );
	  continue;
	}

	if ( tolower( buffer[0] ) == QUIT ) return;

	/* Remove the TODO_MSG as you implement and test commands */
	switch( tolower( buffer[0] ) ){
	case ADD:
	  add_command();
	  break;
	case SUB:
	  sub_command();
	  break;
	case MULT:
	  mult_command();
	  break;
	case DIV:
	  div_command();
	  break;
	case MOD:
	  mod_command();
	  break;
	case AND:
	  and_command();
	  break;
	case OR:
	  or_command();
	  break;
	case XOR:
	  xor_command();
	  break;
	case NOT:
	  not_command();
	  break;
	case FACTORIAL:
	  factorial_command();
	  break;
	case TOGGLE_HEX:
	  toggle_hex();
	  break;
	case TOGGLE_BUG:
	  toggle_bug();
	  break;
	case PRINT_STACK:
	  print_stack();
	  break;
	case PRINT_TOP:
	  print_top();
	  break;
	case CLEAR:
	  clear_command();
	  break;
	case EXCHANGE:
	  exchange_command();
	  break;
	case POP:
	  pop();
	  break;
	case HELP:
	  help_command();
	  break;
	default:
	  printf( BAD_INPUT_MSG );
	}
  }
}