Beispiel #1
0
void interpret_command(ostream &out, istream &in, FrBool allow_bench)
{
   FrObject *cmd ;

   in >> cmd ;
   if (cmd && cmd->symbolp())
      {
      FrSymbol *cmdsym = (FrSymbol*)cmd ;
      FramepaC_bgproc() ;		// handle any asynchronous operations
      FrBool found = False ;
      for (CommandDef *def = commands ; def->name ; def++)
	 {
	 if (*cmdsym == def->name)
	    {
	    if (!allow_bench && strcmp(def->name,"BENCH") == 0)
	       break ;
	    found = True ;
	    def->func(out,in) ;
	    break ;
	    }
	 }
      if (!found)
	 {
	 if (cmdsym == findSymbol("BENCH") && allow_bench)
	    benchmarks_menu(out,in) ;
	 else if (cmdsym == findSymbol("?"))
	    list_commands(out,allow_bench) ;
	 else
	    {
	    out << cmd << " is an unknown command." << endl ;
	    list_commands(out,allow_bench) ;
	    }
	 }
      }
   else
      {
      out << cmd << " is not a valid command, because it is not a symbol."
	  << endl ;
      if (cmd) cmd->freeObject() ;
      FramepaC_bgproc() ;		// handle any asynchronous operations
      }
}
Beispiel #2
0
static void
syntax_error (char *err)
{
	if (err) {
		printf("Error: '%s'\n",err);
		exit(1);
	}
		
	printf ("Sytax:\n");
	printf (" ole <ole-file> [-i] [commands...]\n\n");
	printf (" -i: Interactive, queries for fresh commands\n\n");

	list_commands ();
	exit(1);
}
Beispiel #3
0
/*
 * m_help - HELP message handler
 *      parv[0] = sender prefix
 */
static void
m_help(struct Client *client_p, struct Client *source_p,
       int parc, char *parv[])
{
  static time_t last_used = 0;

  /* HELP is always local */
  if ((last_used + ConfigFileEntry.pace_wait_simple) > CurrentTime)
  {
    /* safe enough to give this on a local connect only */
    sendto_one(source_p,form_str(RPL_LOAD2HI),
               me.name, source_p->name);
    return;
  }
  else
    last_used = CurrentTime;

  list_commands(source_p);
}
Beispiel #4
0
static int do_help(int argc, char *argv[])
{
	const struct futil_cmd_t *cmd;
	const char *vstr = "";

	/* Help about a known command? */
	if (argc > 1) {
		cmd = find_command(argv[1]);
		if (cmd) {
			/* Let the command provide its own help */
			argv[0] = argv[1];
			argv[1] = "--help";
			return run_command(cmd, argc, argv);
		}
	}

	fputs(usage, stdout);

	if (vboot_version == VBOOT_VERSION_ALL)
		fputs(options, stdout);

	switch (vboot_version) {
	case VBOOT_VERSION_1_0:
		vstr = "version 1.0 ";
		break;
	case VBOOT_VERSION_2_1:
		vstr = "version 2.1 ";
		break;
	case VBOOT_VERSION_ALL:
		vstr = "";
		break;
	}
	printf("The following %scommands are built-in:\n\n", vstr);
	list_commands();
	printf("\nUse \"" MYNAME " help COMMAND\" for more information.\n\n");

	return 0;
}
Beispiel #5
0
static int do_help(int argc, char *argv[])
{
	const struct futil_cmd_t *cmd;
	const char *vstr;

	if (argc >= 2) {
		cmd = find_command(argv[1]);
		if (cmd) {
			printf("\n%s - %s\n", argv[1], cmd->shorthelp);
			if (cmd->longhelp)
				cmd->longhelp(argv[1]);
			return 0;
		}
	}

	fputs(usage, stdout);

	if (vboot_version == VBOOT_VERSION_ALL)
		fputs(options, stdout);

	switch (vboot_version) {
	case VBOOT_VERSION_1_0:
		vstr = "version 1.0 ";
		break;
	case VBOOT_VERSION_2_1:
		vstr = "version 2.1 ";
		break;
	case VBOOT_VERSION_ALL:
		vstr = "";
		break;
	}
	printf("The following %scommands are built-in:\n\n", vstr);
	list_commands();
	printf("\nUse \"" MYNAME " help COMMAND\" for more information.\n\n");

	return 0;
}
Beispiel #6
0
int
main (int argc, char **argv)
{
	MsOle *ole;
	int lp, exit = 0, interact = 0;
	char *buffer = g_new (char, 1024) ;

	if (argc<2)
		syntax_error(0);

	if (!g_strcasecmp (argv [1], "regression")) {
		do_regression_tests ();
		return 0;
	}

	printf ("Ole file '%s'\n", argv[1]);
	if (ms_ole_open_vfs (&ole, argv[1], TRUE, NULL)
	    != MS_OLE_ERR_OK) {
		printf ("Creating new file '%s'\n", argv[1]);
		if (ms_ole_create_vfs (&ole, argv[1], TRUE, NULL)
		    != MS_OLE_ERR_OK)
			syntax_error ("Can't open file or create new one");
	}

	if (argc<=2)
		syntax_error ("Need command or -i");

	if (argc>2 && argv[argc-1][0]=='-'
	    && argv[argc-1][1]=='i') 
		interact=1;
	else {
		char *str=g_strdup(argv[2]) ;
		for (lp=3;lp<argc;lp++)
			str = g_strconcat(str," ",argv[lp],NULL); /* FIXME Mega leak :-) */
		buffer = str; /* and again */
	}

	cur_dir = g_strdup ("/");

	do
	{
		char *ptr;

		if (interact) {
			fprintf (stdout,"> ");
			fflush (stdout);
			fgets (buffer, 1023, stdin);
		}

		arg_data = g_strsplit (g_strchomp (buffer), delim, -1);
		arg_cur  = 0;
		if (!arg_data && interact) continue;
		if (!interact)
			printf ("Command : '%s'\n", arg_data[0]);
		ptr = arg_data[arg_cur++];
		if (!ptr)
			continue;

		if (g_strcasecmp (ptr, "ls") == 0)
			list_files (ole);
		else if (g_strcasecmp (ptr, "cd") == 0)
			enter_dir (ole);
		else if (g_strcasecmp (ptr, "dump") == 0)
			do_dump (ole);
		else if (g_strcasecmp (ptr, "biff") == 0)
			do_biff (ole);
		else if (g_strcasecmp (ptr, "biffraw") == 0)
			do_biff_raw (ole);
		else if (g_strcasecmp (ptr, "get") == 0)
			do_get (ole);
		else if (g_strcasecmp (ptr, "put") == 0)
			do_put (ole);
		else if (g_strcasecmp (ptr, "copyin") == 0)
			do_copyin (ole);
		else if (g_strcasecmp (ptr, "copyout") == 0)
			do_copyout (ole);
		else if (g_strcasecmp (ptr, "summary") == 0)
			do_summary (ole);
		else if (g_strcasecmp (ptr, "docsummary") == 0)
			do_docsummary (ole);
		else if (g_strcasecmp (ptr, "debug") == 0)
			ms_ole_debug (ole, 1);
		else if (g_strcasecmp (ptr, "tree") == 0)
			ms_ole_debug (ole, 2);
		else if (g_strcasecmp (ptr, "vba") == 0)
			dump_vba (ole);
		else if (g_strcasecmp (ptr, "help") == 0 ||
			 g_strcasecmp (ptr, "?") == 0 ||
			 g_strcasecmp (ptr, "info") == 0 ||
			 g_strcasecmp (ptr, "man") == 0)
			list_commands ();
		else if (g_strcasecmp (ptr, "exit") == 0 ||
			 g_strcasecmp (ptr, "quit") == 0 ||
			 g_strcasecmp (ptr, "q") == 0 ||
			 g_strcasecmp (ptr, "bye") == 0)
			exit = 1;
	}
	while (!exit && interact);

	ms_ole_destroy (&ole);
	return 0;
}
Beispiel #7
0
/**
 * @brief   Shell thread function.
 *
 * @param[in] p         pointer to a @p BaseSequentialStream object
 * @return              Termination reason.
 * @retval RDY_OK       terminated by command.
 * @retval RDY_RESET    terminated by reset condition on the I/O channel.
 */
static msg_t shell_thread(void *p) {
  int n;
  msg_t msg = RDY_OK;
  BaseSequentialStream *chp = ((ShellConfig *)p)->sc_channel;
  const ShellCommand *scp = ((ShellConfig *)p)->sc_commands;
  char *lp, *cmd, *tokp, line[SHELL_MAX_LINE_LENGTH];
  char *args[SHELL_MAX_ARGUMENTS + 1];

  chRegSetThreadName("shell");
  chprintf(chp, "\r\nChibiOS/RT Shell\r\n");
  while (TRUE) {
    chprintf(chp, "ch> ");
    if (shellGetLine(chp, line, sizeof(line))) {
      chprintf(chp, "\r\nlogout");
      break;
    }
    lp = _strtok(line, " \009", &tokp);
    cmd = lp;
    n = 0;
    while ((lp = _strtok(NULL, " \009", &tokp)) != NULL) {
      if (n >= SHELL_MAX_ARGUMENTS) {
        chprintf(chp, "too many arguments\r\n");
        cmd = NULL;
        break;
      }
      args[n++] = lp;
    }
    args[n] = NULL;
    if (cmd != NULL) {
      if (strcasecmp(cmd, "exit") == 0) {
        if (n > 0) {
          usage(chp, "exit");
          continue;
        }
        break;
      }
      else if (strcasecmp(cmd, "help") == 0) {
        if (n > 0) {
          usage(chp, "help");
          continue;
        }
        chprintf(chp, "Commands: help exit ");
        list_commands(chp, local_commands);
        if (scp != NULL)
          list_commands(chp, scp);
        chprintf(chp, "\r\n");
      }
      else if (cmdexec(local_commands, chp, cmd, n, args) &&
          ((scp == NULL) || cmdexec(scp, chp, cmd, n, args))) {
        chprintf(chp, "%s", cmd);
        chprintf(chp, " ?\r\n");
      }
    }
  }
  /* Atomically broadcasting the event source and terminating the thread,
     there is not a chSysUnlock() because the thread terminates upon return.*/
  chSysLock();
  chEvtBroadcastI(&shell_terminated);
  chThdExitS(msg);
  return 0; /* Never executed.*/
}
Beispiel #8
0
static void execute_user_command(client_t *c, int narg, char **args)
{
    const char *cmd;

    cmd = args[0];
    narg--;
    args++;

    switch (narg) {
    case 0:
        if      (!strcmp(cmd, "register"))   register_client(c);
        else if (!strcmp(cmd, "unregister")) unregister_client(c);
        else if (!strcmp(cmd, "exit"))       quit_mainloop(c, 0);
        else if (!strcmp(cmd, "quit"))       quit_mainloop(c, 0);
        else if (!strcmp(cmd, "help")) {
            print(c, "Available commands:");
            print(c, "  register                     - register to server");
            print(c, "  unregister                   - unregister from server");
            print(c, "  focus none|shared|exclusive  - request voice focus");
            print(c, "  add command <command>        - add new command");
            print(c, "  del command <command>        - delete a command");
            print(c, "  render tts '<msg>' \\        - request TTS of <msg>");
            print(c, "    [-voice:<voice>] \\");
            print(c, "    [-timeout:<timeout>]\\");
            print(c, "    [-events]");
            print(c, "  cancel tts '<id>'            - cancel given TTS "
                  "request");
            print(c, "  list commands                - list commands set");
            print(c, "  list voices                  - list available voices");
            print(c, "  help                         - show this help");
            print(c, "  exit                         - exit from client");
        }
        else
            print(c, "Unknown command '%s'.", cmd);
        break;

    case 1:
        if (!strcmp(cmd, "focus")) {
            if (strcmp(args[0], "none") &&
                strcmp(args[0], "shared") &&
                strcmp(args[0], "exclusive")) {
                print(c, "Invalid focus '%s', valid foci are: "
                      "none, shared, and exclusive.", args[0]);
            }
            else
                request_focus(c, args[0]);
        }
        else if (!strcmp(cmd, "reset") && !strcmp(args[0], "commands"))
            reset_commands(c);
        else if (!strcmp(cmd, "list" ) && !strcmp(args[0], "commands"))
            list_commands(c);
        else if (!strcmp(cmd, "list" ) && !strcmp(args[0], "voices"))
            query_voices(c, NULL);
        else if (!strcmp(cmd, "cancel" ) && !strcmp(args[0], "tts"))
            cancel_tts(c, 0, NULL);
        else
            print(c, "Invalid command.");
        break;

    case 2:
        if (!strcmp(cmd, "list" ) && !strcmp(args[0], "voices"))
            query_voices(c, args[1]);
        else if (!strcmp(cmd, "cancel"))
            cancel_tts(c, narg-1, args+1);
        else
            print(c, "Invalid command.");
        break;

    default:
        if (!strcmp(args[0], "command")) {
            if (!strcmp(cmd, "add" ))
                add_command(c, narg-1, args+1);
            else if (!strcmp(cmd, "del" ) || !strcmp(cmd, "delete"))
                del_command(c, narg-1, args+1);
            else
                print(c, "Invalid command.");
        }
        else if (!strcmp(args[0], "tts")) {
            if (!strcmp(cmd, "render"))
                request_tts(c, narg-1, args+1);
            else
                print(c, "Invalid TTS command.");
        }
        else
            print(c, "Invalid command.");
        break;
    }
}
Beispiel #9
0
int main(int argc, char** argv) {
    return parse_options(argc, argv) ||
            list_commands(get_config_file()) || show_gui(&argc, &argv);
}
Beispiel #10
0
/*
 * Parse command line arguments.
 *
 * Return 0 if OK, else -1
 */
static int parse_args(int argc, char **argv)
{
	int opt, ret;
	char *user;

	if (argc < 2) {
		usage(stderr);
		clean_exit(EXIT_FAILURE);
	}

	while ((opt = getopt_long(argc, argv, "+Vhnvqg:m:", long_options, NULL)) != -1) {
		switch (opt) {
		case 'V':
			version(stdout);
			ret = 0;
			goto end;
		case 'h':
			usage(stdout);
			ret = 0;
			goto end;
		case 'v':
			/* There is only 3 possible level of verbosity. (-vvv) */
			if (lttng_opt_verbose < 3) {
				lttng_opt_verbose += 1;
			}
			break;
		case 'q':
			lttng_opt_quiet = 1;
			break;
		case 'm':
			lttng_opt_mi = mi_output_type(optarg);
			if (lttng_opt_mi < 0) {
				ret = lttng_opt_mi;
				goto error;
			}
			break;
		case 'g':
			lttng_set_tracing_group(optarg);
			break;
		case 'n':
			opt_no_sessiond = 1;
			break;
		case OPT_SESSION_PATH:
			opt_sessiond_path = strdup(optarg);
			break;
		case OPT_RELAYD_PATH:
			opt_relayd_path = strdup(optarg);
			break;
		case OPT_DUMP_OPTIONS:
			list_options(stdout);
			ret = 0;
			goto end;
		case OPT_DUMP_COMMANDS:
			list_commands(commands, stdout);
			ret = 0;
			goto end;
		default:
			usage(stderr);
			ret = 1;
			goto error;
		}
	}

	/* If both options are specified, quiet wins */
	if (lttng_opt_verbose && lttng_opt_quiet) {
		lttng_opt_verbose = 0;
	}

	/* Spawn session daemon if needed */
	if (opt_no_sessiond == 0 && check_args_no_sessiond(argc, argv) == 0 &&
			(check_sessiond() < 0)) {
		ret = 1;
		goto error;
	}

	/* No leftovers, print usage and quit */
	if ((argc - optind) == 0) {
		usage(stderr);
		ret = 1;
		goto error;
	}

	/* For Mathieu Desnoyers a.k.a. Dr. Tracing */
	user = getenv("USER");
	if (user != NULL && ((strncmp(progname, "drtrace", 7) == 0 ||
					strncmp("compudj", user, 7) == 0))) {
		MSG("%c[%d;%dmWelcome back Dr Tracing!%c[%dm\n", 27,1,33,27,0);
	}
	/* Thanks Mathieu */

	/* 
	 * Handle leftovers which is a first level command with the trailing
	 * options.
	 */
	ret = handle_command(argc - optind, argv + optind);
	switch (ret) {
	case CMD_WARNING:
		WARN("Some command(s) went wrong");
		break;
	case CMD_ERROR:
		ERR("Command error");
		break;
	case CMD_UNDEFINED:
		ERR("Undefined command");
		break;
	case CMD_FATAL:
		ERR("Fatal error");
		break;
	case CMD_UNSUPPORTED:
		ERR("Unsupported command");
		break;
	case -1:
		usage(stderr);
		ret = 1;
		break;
	case 0:
		break;
	default:
		if (ret < 0) {
			ret = -ret;
		}
		break;
	}

end:
error:
	return ret;
}
int		do_upcalls_help(void)
{
  puts("Upcalls commands list:\n");
  list_commands(upcalls_subcommands);
  return (0);
}
Beispiel #12
0
/*
 * mo_uhelp - HELP message handler
 * This is used so that opers can view the user help file without deopering
 *      parv[0] = sender prefix
 */
static void
mo_uhelp(struct Client *client_p, struct Client *source_p,
            int parc, char *parv[])
{
  list_commands(source_p);
}
int	do_drivers_help(void)
{
  puts("Drivers subcommands list:\n");
  list_commands(drivers_subcommands);
  return (0);
}
Beispiel #14
0
int
main(int argc, char* argv[])
{
	char *procd_address = NULL;
	myDistro->Init(argc, argv);

	if (argc < 2) {
		fprintf(stderr, 
			"Usage: %s <options w/arguments> <command> [<arg> ...]\n",
			argv[0]);
		list_commands();
		return 1;
	}

	config();
	Termlog = 1;
	dprintf_config("TOOL", get_param_functions());

	int cmd_argc = argc - 1;
	char** cmd_argv = argv + 1;

	// Process the first set of options.
	while(cmd_argv[0] != NULL && cmd_argv[0][0] == '-')
	{
		if (strcmp(cmd_argv[0], "-A") == MATCH) {
			cmd_argc--;
			cmd_argv++;
			if (cmd_argc == 0) {
				fprintf(stderr, "error: -A needs an argument\n");
				list_commands();
				return 1;
			}
			// store the argument to -A as the file we'll use.
			procd_address = cmd_argv[0];
			cmd_argc--;
			cmd_argv++;
			continue;
		} else if (strcmp(cmd_argv[0], "-h") == MATCH) {
			cmd_argc--;
			cmd_argv++;
			fprintf(stderr, 
				"Usage: %s <options w/arguments> <command> [<arg> ...]\n",
				argv[0]);
			list_commands();
			return 1;
			continue;
		}

		// This is the failure case if we manage to pass all checks above.
		fprintf(stderr, "error: Don't understand option %s\n", cmd_argv[0]);
		list_commands();
		return 1;
	}

	// If there are no command line arguments left, then there is no
	// command specified after the options, which is a failure.
	if (cmd_argc == 0) {
		fprintf(stderr, 
			"Please specify a command.\n"
			"Usage: %s <options w/arguments> <command> [<arg> ...]\n",
			argv[0]);
		list_commands();
		return 1;
	}

	// If a procd address wasn't specified on the command line, see if we
	// have an entry in a config file to use.
	if (procd_address == NULL) {
		procd_address = param("PROCD_ADDRESS");
		if (procd_address == NULL) {
			fprintf(stderr, "error: PROCD_ADDRESS not defined\n");
			return 1;
		}
	}

	
	ProcFamilyClient pfc;
	if (!pfc.initialize(procd_address)) {
		fprintf(stderr, "error: failed to initialize ProcD client\n");
		return 1;
	}

	// Process this single command we should be performing
	if (strcasecmp(cmd_argv[0], "REGISTER_FAMILY") == 0) {
		return register_family(pfc, cmd_argc, cmd_argv);
	}
	else if (strcasecmp(cmd_argv[0], "TRACK_BY_ASSOCIATED_GID") == 0) {
		return track_by_associated_gid(pfc, cmd_argc, cmd_argv);
	}
	else if (strcasecmp(cmd_argv[0], "TRACK_BY_ASSOCIATED_CGROUP") == 0) {
		return track_by_associated_cgroup(pfc, cmd_argc, cmd_argv);
	}
	else if (strcasecmp(cmd_argv[0], "GET_USAGE") == 0) {
		return get_usage(pfc, cmd_argc, cmd_argv);
	}
	else if (strcasecmp(cmd_argv[0], "DUMP") == 0) {
		return dump(pfc, cmd_argc, cmd_argv);
	}
	else if (strcasecmp(cmd_argv[0], "LIST") == 0) {
		return list(pfc, cmd_argc, cmd_argv);
	}
	else if (strcasecmp(cmd_argv[0], "SIGNAL_PROCESS") == 0) {
		return signal_process(pfc, cmd_argc, cmd_argv);
	}
	else if (strcasecmp(cmd_argv[0], "SUSPEND_FAMILY") == 0) {
		return suspend_family(pfc, cmd_argc, cmd_argv);
	}
	else if (strcasecmp(cmd_argv[0], "CONTINUE_FAMILY") == 0) {
		return continue_family(pfc, cmd_argc, cmd_argv);
	}
	else if (strcasecmp(cmd_argv[0], "KILL_FAMILY") == 0) {
		return kill_family(pfc, cmd_argc, cmd_argv);
	}
	else if (strcasecmp(cmd_argv[0], "UNREGISTER_FAMILY") == 0) {
		return unregister_family(pfc, cmd_argc, cmd_argv);
	}
	else if (strcasecmp(cmd_argv[0], "SNAPSHOT") == 0) {
		return snapshot(pfc, cmd_argc, cmd_argv);
	}
	else if (strcasecmp(cmd_argv[0], "QUIT") == 0) {
		return quit(pfc, cmd_argc, cmd_argv);
	}
	else {
		fprintf(stderr, "error: invalid command: %s\n", cmd_argv[0]);
		list_commands();
		return 1;
	}
}
Beispiel #15
0
int		do_video_help(void)
{
  puts("Video commands:\n");
  list_commands(video_subcommands);
  return (0);
}
Beispiel #16
0
/**
 * @brief   Shell thread function.
 *
 * @param[in] p         pointer to a @p BaseSequentialStream object
 */
THD_FUNCTION(shellThread, p) {
  int n;
  ShellConfig *scfg = p;
  BaseSequentialStream *chp = scfg->sc_channel;
  const ShellCommand *scp = scfg->sc_commands;
  char *lp, *cmd, *tokp, line[SHELL_MAX_LINE_LENGTH];
  char *args[SHELL_MAX_ARGUMENTS + 1];

#if SHELL_USE_HISTORY == TRUE
  *(scfg->sc_histbuf) = 0;
  ShellHistory hist = {
                       scfg->sc_histbuf,
                       scfg->sc_histsize,
                       0,
                       0,
                       0
  };
  ShellHistory *shp = &hist;
#else
  ShellHistory *shp = NULL;
#endif

  chprintf(chp, SHELL_NEWLINE_STR);
  chprintf(chp, "ChibiOS/RT Shell"SHELL_NEWLINE_STR);
  while (true) {
    chprintf(chp, SHELL_PROMPT_STR);
    if (shellGetLine(scfg, line, sizeof(line), shp)) {
#if (SHELL_CMD_EXIT_ENABLED == TRUE) && !defined(_CHIBIOS_NIL_)
      chprintf(chp, SHELL_NEWLINE_STR);
      chprintf(chp, "logout");
      break;
#else
      /* Putting a delay in order to avoid an endless loop trying to read
         an unavailable stream.*/
      osalThreadSleepMilliseconds(100);
#endif
    }
    lp = parse_arguments(line, &tokp);
    cmd = lp;
    n = 0;
    while ((lp = parse_arguments(NULL, &tokp)) != NULL) {
      if (n >= SHELL_MAX_ARGUMENTS) {
        chprintf(chp, "too many arguments"SHELL_NEWLINE_STR);
        cmd = NULL;
        break;
      }
      args[n++] = lp;
    }
    args[n] = NULL;
    if (cmd != NULL) {
      if (strcmp(cmd, "help") == 0) {
        if (n > 0) {
          shellUsage(chp, "help");
          continue;
        }
        chprintf(chp, "Commands: help ");
        list_commands(chp, shell_local_commands);
        if (scp != NULL)
          list_commands(chp, scp);
        chprintf(chp, SHELL_NEWLINE_STR);
      }
      else if (cmdexec(shell_local_commands, chp, cmd, n, args) &&
          ((scp == NULL) || cmdexec(scp, chp, cmd, n, args))) {
        chprintf(chp, "%s", cmd);
        chprintf(chp, " ?"SHELL_NEWLINE_STR);
      }
    }
  }
  shellExit(MSG_OK);
}
Beispiel #17
0
void load_plugins( string path, map<string, Command_Rights>& plugins, list<Plugin*>& liste)
{

    void(*sendMsg)(void(*)(const string, const string));
    void(*setColor)(string(*)(const string, const string));
    void(*setRegister)(void(*)(ScheduleDetails));
    void(*setGenerate)(ScheduleDetails(*)(vector<string>));
    void(*setCall)(void(*)(string,vector<string>, string));
    void(*setSay)(void(*)(string));
    void(*setCreateTable)(bool(*)(string));
    void(*setSqlCmd)(bool(*)(string));
    struct dirent* dp;

    DIR* dir = opendir( path.c_str());
    if( !dir)
    {
        cout << "opendir() failure; terminating" << endl;
        return;
    }

    while( (dp = readdir(  dir)) != nullptr)
    {
        if( !strcmp( &dp->d_name[strlen(dp->d_name)-3], ".so") || !strcmp( &dp->d_name[strlen(dp->d_name)-4], ".dll"))
        {
            string name = path;
            name += dp->d_name;

            cout << "Loading: " << name << endl;
            void* lib_handle = dlopen( name.c_str(), RTLD_LAZY);
            
            if( !lib_handle)
            {
               cerr << dlerror() << endl;
               exit(1);
            }

            char* error;
            PluginDetails* info;
            info = reinterpret_cast<PluginDetails*>(dlsym(lib_handle, "exports"));
           
            if( (error = dlerror()) != NULL)
            {
                cerr << error << endl;
                exit(2);
            }
            
            *(void**)(&sendMsg) = dlsym(lib_handle, "set_send_msg");
            if( !sendMsg)
            {
                cerr << dlerror() << endl;
                exit(3);
            }
            sendMsg(send_msg);

            *(void**)(&setColor) = dlsym(lib_handle, "set_add_color");
            if( !setColor)
            {
                cerr << dlerror() << endl;
                exit(3);
            }
            setColor( add_color);

            *(void**)(&setRegister) = dlsym(lib_handle, "set_add_reg_task");
            if( !setRegister)
            {
                cerr << dlerror() << endl;
                exit(3);
            }
            setRegister( register_task);

            *(void**)(&setGenerate) = dlsym(lib_handle, "set_generate_schedule");
            if( !setGenerate)
            {
                cerr << dlerror() << endl;
                exit(3);
            }
            setGenerate( generate_task);

            *(void**)(&setCall) = dlsym(lib_handle, "set_call");
            if( !setCall)
            {
                cerr << dlerror() << endl;
                exit(3);
            }
            setCall( call);

            *(void**)(&setSay) = dlsym(lib_handle, "set_say");
            if( !setSay)
            {
                cerr << dlerror() << endl;
                exit(3);
            }
            setSay( say);

            *(void**)(&setCreateTable) = dlsym(lib_handle, "set_create_table");
            if( !setCreateTable)
            {
                cerr << dlerror() << endl;
                exit(3);
            }
            setCreateTable( create_table);

            *(void**)(&setSqlCmd) = dlsym(lib_handle, "set_sql");
            if( !setSqlCmd)
            {
                cerr << dlerror() << endl;
                exit(3);
            }
            setSqlCmd( sql_command);

            cout << "Plugin info: " << "\nFile Name: " << info->file_name << endl;
            cout << "Class name: " << info->class_name << endl;
            cout << "plugin name: " << info->plugin_name << endl;
            cout << "Command: " << info->command << endl;

            Plugin* pl = info->initFunc();
            pl->set_handle(lib_handle);

            list_commands( info->command, pl, plugins,liste);

        }
    }
}
Beispiel #18
0
int	do_fs_help(void)
{
  puts("Filesystems commands list:\n");
  list_commands(fs_subcommands);
  return (0);
}
Beispiel #19
0
/***********************
        Main
 **********************/
int
main(int argc, char *argv[])
{
    setup_home();

    int g = 0;
    int x = 0;
    int V = 0;
    int c = 0;
    int l = 0;
    int e = 0;
    int d = 0;
    int u = 0;
    int h = 0;
    int G = 0;
    int T = 0;
    int C = 0;
    int M = 0;
    int N = 0;
    char * group;
    char * label;
    char * content;
    int opt ;
    while((opt= getopt(argc,argv, "V(verbose)g:x(execute)c(create)l(list)e(echo):d(drop):u(edit):h(help)G(group):T(template):C(command)::M(macro)::N(note)::"))!= -1)
    {
        switch(opt)
        {
        case 'g':
            g=1;
            group = optarg;
            break;
        case 'V':
            V = 1;
            break;
        case 'x':
            x = 1;
            break;
        case 'c':
            c = 1;
            break;
        case 'l':
            l = 1;
            break;
        case 'e':
            e = 1;
            label = argv[optind];
            break;
        case 'd':
            d = 1;
            label = argv[optind];
            break;
        case 'u':
            u = 1;
            label = argv[optind];
            break;
        case 'h':
            h = 1;
            break;
        case 'G':
            G = 1;
            label = argv[optind];
            break;
        case 'T':
            T = 1;
            label = argv[optind];
            break;
        case 'C':
            C = 1;
            label = argv[optind];
            content = argv[optind+1];
            break;
        case 'N':
            N = 1;
            label = argv[optind];
            content = argv[optind+1];
            break;
        default:
            puts("test");
            break;


        }
    }
    if(g == 1)
    {
        if(c == 1)
        {
            if(G ==1)
            {
                create_group(label);
                //break;
            }
            else if(N == 1)
            {
                create_note(group, label, content);
                //break;
            }

            else if(C == 1)
            {
                create_command(label,group,content);
                //break;
            }
            else if(T == 1)
            {
                create_template_from_current(group,label);
                //break;
            }
            else
            {
                puts("Invalid Command");
                return -1;
            }
        }

        if(e == 1)
        {
            if(N == 1)
            {
                echo_note(group,label);
            }
            else if( C == 1)
            {
                echo_command(label, group);
            }
            else if (T == 1)
            {
                echo_template(label, group);
            }
        }
        else if(l == 1)
        {
            if(N == 1)
            {
                list_notes(group);
                //break;
            }
            else if(C == 1)
            {
                list_commands(group);
                //break;
            }
            else if(T == 1)
            {
                list_templates(group);
            }
            else
            {
                puts("Invalid Command");
                return -1;
            }
        }
        else if(x == 1)
        {
            if(C == 1)
            {
                execute_command(group,label);
                //break;
            }
            else if(T == 1)
            {
                execute_template(group,label);
            }
            else
            {
                puts("Invalid Command");
                return -1;
            }
        }

    }
    else if(c == 1)
    {
        if(G == 1)
        {
            create_group(label);
            //break;
        }
        else
        {
            puts("Invalid Command");
            return -1;
        }
    }
    else if(e == 1)
    {
        if(G == 1)
        {
            echo_group(label);
        }
    }




    return 0;
}
Beispiel #20
0
/*
 * The 'snapshot <cmd> <options>' first level command
 */
int cmd_snapshot(int argc, const char **argv)
{
	int opt, ret = CMD_SUCCESS, command_ret = CMD_SUCCESS, success = 1;
	char *session_name = NULL;
	static poptContext pc;

	pc = poptGetContext(NULL, argc, argv, snapshot_opts, 0);
	poptReadDefaultConfig(pc, 0);

	/* Mi check */
	if (lttng_opt_mi) {
		writer = mi_lttng_writer_create(fileno(stdout), lttng_opt_mi);
		if (!writer) {
			ret = -LTTNG_ERR_NOMEM;
			goto end;
		}

		/* Open command element */
		ret = mi_lttng_writer_command_open(writer,
				mi_lttng_element_command_snapshot);
		if (ret) {
			ret = CMD_ERROR;
			goto end;
		}

		/* Open output element */
		ret = mi_lttng_writer_open_element(writer,
				mi_lttng_element_command_output);
		if (ret) {
			ret = CMD_ERROR;
			goto end;
		}
	}

	while ((opt = poptGetNextOpt(pc)) != -1) {
		switch (opt) {
		case OPT_HELP:
			usage(stdout);
			goto end;
		case OPT_LIST_OPTIONS:
			list_cmd_options(stdout, snapshot_opts);
			goto end;
		case OPT_LIST_COMMANDS:
			list_commands(actions, stdout);
			goto end;
		case OPT_MAX_SIZE:
		{
			uint64_t val;
			const char *opt = poptGetOptArg(pc);

			if (utils_parse_size_suffix((char *) opt, &val) < 0) {
				ERR("Unable to handle max-size value %s", opt);
				ret = CMD_ERROR;
				goto end;
			}

			opt_max_size = val;

			break;
		}
		default:
			usage(stderr);
			ret = CMD_UNDEFINED;
			goto end;
		}
	}

	if (!opt_session_name) {
		session_name = get_session_name();
		if (session_name == NULL) {
			ret = CMD_ERROR;
			goto end;
		}
		current_session_name = session_name;
	} else {
		current_session_name = opt_session_name;
	}

	command_ret = handle_command(poptGetArgs(pc));
	if (command_ret) {
		switch (-command_ret) {
		case LTTNG_ERR_EPERM:
			ERR("The session needs to be set in no output mode (--no-output)");
			break;
		case LTTNG_ERR_SNAPSHOT_NODATA:
			WARN("%s", lttng_strerror(command_ret));
			break;
		default:
			ERR("%s", lttng_strerror(command_ret));
			break;
		}
		success = 0;
	}

	if (lttng_opt_mi) {
		/* Close output element */
		ret = mi_lttng_writer_close_element(writer);
		if (ret) {
			ret = CMD_ERROR;
			goto end;
		}

		/* Success ? */
		ret = mi_lttng_writer_write_element_bool(writer,
				mi_lttng_element_command_success, success);
		if (ret) {
			ret = CMD_ERROR;
			goto end;
		}

		/* Command element close */
		ret = mi_lttng_writer_command_close(writer);
		if (ret) {
			ret = CMD_ERROR;
			goto end;
		}
	}

end:
	/* Mi clean-up */
	if (writer && mi_lttng_writer_destroy(writer)) {
		/* Preserve original error code */
		ret = ret ? ret : -LTTNG_ERR_MI_IO_FAIL;
	}

	if (!opt_session_name) {
		free(session_name);
	}

	/* Overwrite ret if an error occured during handle_command */
	ret = command_ret ? command_ret : ret;
	poptFreeContext(pc);
	return ret;
}
Beispiel #21
0
int		do_help(void)
{
  puts("Command list:\n");
  list_commands(commands);
  return (0);
}
int
main (int argc, char **argv)
{
	int exit = 0;
	char *buffer = g_new (char, 1024) ;
	GIOChannel *ioc;
	guint watch_id = 0;
	GOptionContext *ctx = NULL;
	GError *error = NULL;

	/* default to interactive on a terminal */
	interactive = isatty (0);

	ctx = g_option_context_new("test-vfs");
	g_option_context_add_main_entries(ctx, options, NULL);

	if (!g_option_context_parse(ctx, &argc, &argv, &error)) {
		g_printerr("main: %s\n", error->message);

		g_error_free(error);
		g_option_context_free(ctx);
		return 1;
	}

	g_option_context_free(ctx);

	files = g_hash_table_new (g_str_hash, g_str_equal);

	if (noninteractive)
		interactive = FALSE;

	if (interactive)
		vfserr = stderr;
	else
		vfserr = stdout;

	if (!mate_vfs_init ()) {
		fprintf (vfserr, "Cannot initialize mate-vfs.\n");
		return 1;
	}
	mate_vfs_module_callback_push
		(MATE_VFS_MODULE_CALLBACK_AUTHENTICATION,
		 authentication_callback, NULL, NULL);

	if (argc == 1)
		cur_dir = g_get_current_dir ();
	else
		cur_dir = g_strdup(argv[1]);

	if (cur_dir && !G_IS_DIR_SEPARATOR (cur_dir [strlen (cur_dir) - 1]))
		cur_dir = g_strconcat (cur_dir, G_DIR_SEPARATOR_S, NULL);

	if (interactive == TRUE) {
		main_loop = g_main_loop_new (NULL, TRUE);
		ioc = g_io_channel_unix_new (0 /* stdin */);
		g_io_channel_set_encoding (ioc, NULL, NULL);
		g_io_channel_set_buffered (ioc, FALSE);
		watch_id = g_io_add_watch (ioc,
					   G_IO_IN | G_IO_HUP | G_IO_ERR,
					   callback, buffer);
		g_io_channel_unref (ioc);
	}

	while (!exit) {
		char *ptr;

		if (interactive) {
			fprintf (stdout,"\n%s > ", cur_dir);
			fflush (stdout);

			strcpy (buffer, "");
			g_main_loop_run (main_loop);
		} else {
			/* In non-interactive mode we just do this evil
			 * thingie */
			buffer[0] = '\0';
			fgets (buffer, 1023, stdin);
			if (!buffer [0]) {
				exit = 1;
				continue;
			}
		}

		if (!buffer || buffer [0] == '#')
			continue;

		arg_data = g_strsplit (g_strchomp (buffer), delim, -1);
		arg_cur  = 0;
		if ((!arg_data || !arg_data[0]) && interactive) continue;
		if (!interactive)
			printf ("Command : '%s'\n", arg_data [0]);
		ptr = arg_data[arg_cur++];
		if (!ptr)
			continue;

		if (g_ascii_strcasecmp (ptr, "ls") == 0)
			do_ls ();
		else if (g_ascii_strcasecmp (ptr, "cd") == 0)
			do_cd ();
		else if (g_ascii_strcasecmp (ptr, "dump") == 0)
			do_dump ();
		else if (g_ascii_strcasecmp (ptr, "type") == 0 ||
			 g_ascii_strcasecmp (ptr, "cat") == 0)
			do_cat ();
		else if (g_ascii_strcasecmp (ptr, "cp") == 0)
			do_cp ();
		else if (g_ascii_strcasecmp (ptr, "rm") == 0)
			do_rm ();
		else if (g_ascii_strcasecmp (ptr, "mkdir") == 0)
			do_mkdir ();
		else if (g_ascii_strcasecmp (ptr, "rmdir") == 0)
			do_rmdir ();
		else if (g_ascii_strcasecmp (ptr, "mv") == 0)
			do_mv ();
		else if (g_ascii_strcasecmp (ptr, "info") == 0 ||
			 g_ascii_strcasecmp (ptr, "stat") == 0)
			do_info ();
		else if (g_ascii_strcasecmp (ptr, "findtrash") == 0)
			do_findtrash ();
		else if (g_ascii_strcasecmp (ptr, "ssl") == 0)
			do_ssl ();
		else if (g_ascii_strcasecmp (ptr, "sync") == 0)
			fprintf (vfserr, "a shell is like a boat, it lists or syncs (RMS)\n");
		else if (g_ascii_strcasecmp (ptr,"help") == 0 ||
			 g_ascii_strcasecmp (ptr,"?")    == 0 ||
			 g_ascii_strcasecmp (ptr,"info") == 0 ||
			 g_ascii_strcasecmp (ptr,"man")  == 0)
			list_commands ();
		else if (g_ascii_strcasecmp (ptr,"exit") == 0 ||
			 g_ascii_strcasecmp (ptr,"quit") == 0 ||
			 g_ascii_strcasecmp (ptr,"q")    == 0 ||
			 g_ascii_strcasecmp (ptr,"bye") == 0)
			exit = 1;

		/* File ops */
		else if (g_ascii_strcasecmp (ptr, "open") == 0)
			do_open ();
		else if (g_ascii_strcasecmp (ptr, "create") == 0)
			do_create ();
		else if (g_ascii_strcasecmp (ptr, "close") == 0)
			do_close ();
		else if (g_ascii_strcasecmp (ptr, "handleinfo") == 0)
			do_handleinfo ();
		else if (g_ascii_strcasecmp (ptr, "read") == 0)
			do_read ();
		else if (g_ascii_strcasecmp (ptr, "seek") == 0)
			do_seek ();
		
		else
			fprintf (vfserr, "Unknown command '%s'", ptr);

		g_strfreev (arg_data);
		arg_data = NULL;
	}

	if (interactive) {
		g_source_remove (watch_id);
		g_main_loop_unref (main_loop);
		main_loop = NULL;
	}

	g_free (buffer);
	g_free (cur_dir);

	close_files ();

	return 0;
}
Beispiel #23
0
/*
 * Parse command line arguments.
 *
 * Return 0 if OK, else -1
 */
static int parse_args(int argc, char **argv)
{
	int opt, ret;

	if (argc < 2) {
		usage(stderr);
		clean_exit(EXIT_FAILURE);
	}

	while ((opt = getopt_long(argc, argv, "+Vhnvqg:", long_options, NULL)) != -1) {
		switch (opt) {
		case 'V':
			version(stdout);
			ret = 0;
			goto end;
		case 'h':
			usage(stdout);
			ret = 0;
			goto end;
		case 'v':
			lttng_opt_verbose += 1;
			break;
		case 'q':
			lttng_opt_quiet = 1;
			break;
		case 'g':
			lttng_set_tracing_group(optarg);
			break;
		case 'n':
			opt_no_sessiond = 1;
			break;
		case OPT_SESSION_PATH:
			opt_sessiond_path = strdup(optarg);
			break;
		case OPT_DUMP_OPTIONS:
			list_options(stdout);
			ret = 0;
			goto end;
		case OPT_DUMP_COMMANDS:
			list_commands(commands, stdout);
			ret = 0;
			goto end;
		default:
			usage(stderr);
			ret = 1;
			goto error;
		}
	}

	/* If both options are specified, quiet wins */
	if (lttng_opt_verbose && lttng_opt_quiet) {
		lttng_opt_verbose = 0;
	}

	/* Spawn session daemon if needed */
	if (opt_no_sessiond == 0 && check_args_no_sessiond(argc, argv) == 0 &&
			(check_sessiond() < 0)) {
		ret = 1;
		goto error;
	}

	/* No leftovers, print usage and quit */
	if ((argc - optind) == 0) {
		usage(stderr);
		ret = 1;
		goto error;
	}

	/* 
	 * Handle leftovers which is a first level command with the trailing
	 * options.
	 */
	ret = handle_command(argc - optind, argv + optind);
	switch (ret) {
	case CMD_WARNING:
		WARN("Some command(s) went wrong");
		break;
	case CMD_ERROR:
		ERR("Command error");
		break;
	case CMD_UNDEFINED:
		ERR("Undefined command");
		break;
	case CMD_FATAL:
		ERR("Fatal error");
		break;
	case CMD_UNSUPPORTED:
		ERR("Unsupported command");
		break;
	case -1:
		usage(stderr);
		ret = 1;
		break;
	case 0:
		break;
	default:
		if (ret < 0) {
			ret = -ret;
		}
		break;
	}

end:
error:
	return ret;
}
Beispiel #24
0
/*
 * Parse command line arguments.
 *
 * Return 0 if OK, else -1
 */
static int parse_args(int argc, char **argv)
{
	int opt, ret;

	if (lttng_is_setuid_setgid()) {
		ERR("'%s' is not allowed to be executed as a setuid/setgid binary for security reasons. Aborting.", argv[0]);
		clean_exit(EXIT_FAILURE);
	}

	if (argc < 2) {
		show_basic_help();
		clean_exit(EXIT_FAILURE);
	}

	while ((opt = getopt_long(argc, argv, "+Vhnvqg:m:", long_options, NULL)) != -1) {
		switch (opt) {
		case 'V':
			version(stdout);
			ret = 0;
			goto end;
		case 'h':
			ret = utils_show_man_page(1, "lttng");

			if (ret) {
				ERR("Cannot view man page lttng(1)");
				perror("exec");
			}
			goto end;
		case 'v':
			/* There is only 3 possible level of verbosity. (-vvv) */
			if (lttng_opt_verbose < 3) {
				lttng_opt_verbose += 1;
			}
			break;
		case 'q':
			lttng_opt_quiet = 1;
			break;
		case 'm':
			lttng_opt_mi = mi_output_type(optarg);
			if (lttng_opt_mi < 0) {
				ret = lttng_opt_mi;
				goto error;
			}
			break;
		case 'g':
			lttng_set_tracing_group(optarg);
			break;
		case 'n':
			opt_no_sessiond = 1;
			break;
		case OPT_SESSION_PATH:
			free(opt_sessiond_path);
			opt_sessiond_path = strdup(optarg);
			if (!opt_sessiond_path) {
				ret = -1;
				goto error;
			}
			break;
		case OPT_RELAYD_PATH:
			free(opt_relayd_path);
			opt_relayd_path = strdup(optarg);
			if (!opt_relayd_path) {
				ret = -1;
				goto error;
			}
			break;
		case OPT_DUMP_OPTIONS:
			list_options(stdout);
			ret = 0;
			goto end;
		case OPT_DUMP_COMMANDS:
			list_commands(commands, stdout);
			ret = 0;
			goto end;
		default:
			ret = 1;
			goto error;
		}
	}

	/* If both options are specified, quiet wins */
	if (lttng_opt_verbose && lttng_opt_quiet) {
		lttng_opt_verbose = 0;
	}

	/* No leftovers, quit */
	if ((argc - optind) == 0) {
		ret = 1;
		goto error;
	}

	/*
	 * Handle leftovers which is a first level command with the trailing
	 * options.
	 */
	ret = handle_command(argc - optind, argv + optind);
	switch (ret) {
	case CMD_WARNING:
		WARN("Some command(s) went wrong");
		break;
	case CMD_ERROR:
		ERR("Command error");
		break;
	case CMD_UNDEFINED:
		ERR("Undefined command or invalid arguments");
		break;
	case CMD_FATAL:
		ERR("Fatal error");
		break;
	case CMD_UNSUPPORTED:
		ERR("Unsupported command");
		break;
	case -1:
		ret = 1;
		break;
	case 0:
		break;
	default:
		if (ret < 0) {
			ret = -ret;
		}
		break;
	}

end:
error:
	return ret;
}
Beispiel #25
0
void command_display_help(int argc, char* argv[]) {
	if (argc < 2) {
		printf(" _____   _____   __    \n"); 
		printf("| __\\ \\ / / _ \\ / _|___\n");
		printf("| _| \\ V / (_) |  _(_-<\n");
		printf("|___| \\_/ \\___/|_| /__/\n");
		printf("EVOfs toolbox version 0\n\n");
		
		toolbox_spew();
		
		list_commands();
		
		printf("Commands with an asterisk after them are potentially destructive, and require\n");
		printf("at minimum the parameter \"confirm\" to be passed to them to be used (a notice\n");
		printf("about the confirm parameter will be printed if you run the command without it.\n\n");
		return;
	}
	
	if (!strcmp(argv[1], "terse")) {
		list_commands();
		return;
	}
	
	if (!strcmp(argv[1], "help") || !strcmp(argv[1], "?")) {
		printf("help - prints help for the toolbox and its commands.\n\n");
		
		printf("Passing a command name to help (like you've just done) will display help for\n");
		printf("that command. Alternately, passing \"terse\" to the help command will display\n");
		printf("just a list of commands.\n\n");
		return;
	}
	
	if (!strcmp(argv[1], "quit") || !strcmp(argv[1], "exit") || !strcmp(argv[1], "ex")) {
		printf("quit - exits the toolbox.\n\n");
		
		printf("The quit command has no options.\n\n");
		return;
	}
	
	if (!strcmp(argv[1], "list") || !strcmp(argv[1], "l")) {
		printf("list - displays a list of partitions on the disk.\n\n");
		
		printf("The list command has no options.\n\n");
		return;
	}
	
	if (!strcmp(argv[1], "select")) {
		printf("select - Selects a partition to operate on.\n\n");
		
		printf("The select command, without any parameters, deselects the current partition.\n");
		printf("Passing the number of a valid (non-empty) partition as reported by the list\n");
		printf("command will select that partition for operation. The select command will not\n");
		printf("warn the user about any potential data on the partition being selected.\n\n");
		return;
	}
	
	if (!strcmp(argv[1], "create")) {
		printf("create - Creates an EVOfs filesystem on the selected partition.\n\n");
		
		printf("This command is potentially the most destructive of the commands in the toolbox\n");
		printf("and, as a result, requires either \"confirm\" or \"test\" parameters (but not both)\n");
		printf("to be passed to it. \"confirm\" will go ahead with the creation and write to the\n");
		printf("partition. \"test\" will execute a \"dry run\" of the creation, doing all the math\n");
		printf("and memory allocations/frees but without actually modifying the data on the\n");
		printf("partition. You can also pass \"verbose\" after either command to see the really\n");
		printf("technical behind-the-scenes stuff going on.\n\n");
		return;
	}
	
	printf("No help available for %s (experiment at your own risk).\n", argv[1]);
}