本文整理汇总了C++中command_free函数的典型用法代码示例。如果您正苦于以下问题:C++ command_free函数的具体用法?C++ command_free怎么用?C++ command_free使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了command_free函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: command_free
void
command_free(command_t *cmd)
{
int i;
// It's OK to command_free(NULL).
if (!cmd)
return;
/* Your code here. */
i=0;
while(cmd->argv[i]!=NULL&&i<MAXTOKENS+1){
free(cmd->argv[i++]);
}
i=0;
while(i<3){
if (cmd->redirect_filename[i]!=NULL)
{
free(cmd->redirect_filename[i]);
}
i++;
}
if(cmd->subshell!=NULL){
command_free(cmd->subshell);
}
if(cmd->next!=NULL){
command_free(cmd->next);
}
free(cmd);
}
开发者ID:TXing123,项目名称:prog1,代码行数:32,代码来源:cmdline.c
示例2: command_parse_args
static void
command_parse_args(command_t *self, int argc, char **argv) {
int literal = 0;
int i, j;
for (i = 1; i < argc; ++i) {
const char *arg = argv[i];
for (j = 0; j < self->option_count; ++j) {
command_option_t *option = &self->options[j];
// match flag
if (!strcmp(arg, option->small) || !strcmp(arg, option->large)) {
self->arg = NULL;
// required
if (option->required_arg) {
arg = argv[++i];
if (!arg || '-' == arg[0]) {
fprintf(stderr, "%s %s argument required\n", option->large, option->argname);
command_free(self);
exit(1);
}
self->arg = arg;
}
// optional
if (option->optional_arg) {
if (argv[i + 1] && '-' != argv[i + 1][0]) {
self->arg = argv[++i];
}
}
// invoke callback
option->cb(self);
goto match;
}
}
// --
if ('-' == arg[0] && '-' == arg[1] && 0 == arg[2]) {
literal = 1;
goto match;
}
// unrecognized
if ('-' == arg[0] && !literal) {
fprintf(stderr, "unrecognized flag %s\n", arg);
command_free(self);
exit(1);
}
int n = self->argc++;
if (n == COMMANDER_MAX_ARGS) {
command_free(self);
error("Maximum number of arguments exceeded");
}
self->argv[n] = (char *) arg;
match:;
}
}
开发者ID:Bactaria,项目名称:yetris,代码行数:60,代码来源:commander.c
示例3: execute
static void execute(char *buf)
{
struct command *cmd = command_new();
char *arg;
char *rest;
if (!cmd)
{
fprintf(stderr, "Memory exhausted\n");
return;
}
while (*buf && *buf == ' ')
buf++;
if (!*buf)
{
command_free(cmd);
return;
}
arg = strtok_r(buf, " ", &rest);
while (arg)
{
if (command_append(cmd, arg) < 0)
{
command_free(cmd);
fprintf(stderr, "Memory exhausted\n");
return;
}
while (*rest && *rest == ' ')
rest++;
arg = strtok_r(NULL, " ", &rest);
}
command_append(cmd, NULL);
command_execute(cmd);
command_free(cmd);
}
开发者ID:Nakrez,项目名称:zOS,代码行数:48,代码来源:main.c
示例4: sam_cmd
enum SamError sam_cmd(Vis *vis, const char *s) {
enum SamError err = SAM_ERR_OK;
if (!s)
return err;
Command *cmd = sam_parse(vis, s, &err);
if (!cmd) {
if (err == SAM_ERR_OK)
err = SAM_ERR_MEMORY;
return err;
}
Filerange range = text_range_empty();
sam_execute(vis, vis->win, cmd, NULL, &range);
if (vis->win) {
bool completed = true;
for (Cursor *c = view_cursors(vis->win->view); c; c = view_cursors_next(c)) {
Filerange sel = view_cursors_selection_get(c);
if (text_range_valid(&sel)) {
completed = false;
break;
}
}
vis_mode_switch(vis, completed ? VIS_MODE_NORMAL : VIS_MODE_VISUAL);
}
command_free(cmd);
return err;
}
开发者ID:ewqasd200g,项目名称:vis,代码行数:29,代码来源:sam.c
示例5: Fill3f
int Fill3f(Display *display, int r, int g, int b) {
/* There's probably more error checking to do here since
* changing the colorMode actually defines the max values
* acceptable here. Default is 1.0 so we'll start with that...
*/
if (r > 1.0 || g > 1.0 || b > 1.0) {
return -1;
}
Command *cmd = NULL;
Socket *socket = NULL;
socket = display->socket;
/* cmd = command_format("FI_F %f %f %f", r, g, b); */
cmd = command_format_json("FI_F", "%f %f %f", r, g, b);
if (cmd == NULL)
return -1;
if (command_send(cmd, socket) != 0) {
command_free(cmd);
return -1;
}
return 0;
}
开发者ID:cafiend,项目名称:W12,代码行数:25,代码来源:hlib.c
示例6: main
int
main(int argc, char **argv) {
int rc = 1;
opts.spaces = 2;
command_t cmd;
command_init(&cmd, argv[0], "1.0.0");
command_option(&cmd
, "-v"
, "--verbose"
, "enable verbose stuff"
, set_verbose);
command_option(&cmd
, "-s"
, "--spaces [count]"
, "optional number of spaces (defaults to 2)"
, set_spaces);
command_parse(&cmd, argc, argv);
for (int i = 0; i < cmd.argc; ++i) {
if (-1 == convert_file(cmd.argv[i])) goto cleanup;
}
rc = 0;
cleanup:
command_free(&cmd);
return rc;
}
开发者ID:stephenmathieson,项目名称:tabs-to-spaces,代码行数:29,代码来源:main.c
示例7: TextAreaSetCss
/*
* This is a general purpose way to call jquery from C.
*
* Just a front for $("#id").css("name", "value");
*/
int TextAreaSetCss(Display *display, const char *id, const char *name, const char *value)
{
Command *cmd = NULL;
Socket *socket = NULL;
socket = display->socket;
if (id == NULL)
return -1;
if (strlen(id) == 0 || strlen(name) == 0 || strlen(value) == 0)
return 0;
cmd = command_format_json("TXT_AREA_CSS", "\"%s\" \"%s\" \"%s\"", id, name, value);
if (cmd == NULL)
return -1;
if (command_send(cmd, socket) != 0) {
command_free(cmd);
return -1;
}
return 0;
}
开发者ID:cafiend,项目名称:W12,代码行数:30,代码来源:hlib.c
示例8: CreateTextArea
/* Create a text area over the canvas to receive text directly */
int CreateTextArea(Display *display, const char *id, int x, int y, int width, int height, int readonly)
{
Command *cmd = NULL;
Socket *socket = NULL;
socket = display->socket;
if (id == NULL)
return -1;
if (strlen(id) == 0)
return 0;
if (readonly != TRUE && readonly != FALSE)
return 0;
cmd = command_format_json("NEW_TXT_AREA", "\"%s\" %d %d %d %d %d", id, x, y, width, height, readonly);
if (cmd == NULL)
return -1;
if (command_send(cmd, socket) != 0) {
command_free(cmd);
return -1;
}
return 0;
}
开发者ID:cafiend,项目名称:W12,代码行数:28,代码来源:hlib.c
示例9: AppendTextArea
int AppendTextArea(Display *display, const char *target, const char *text)
{
Command *cmd = NULL;
Socket *socket = NULL;
socket = display->socket;
if (target == NULL || text == NULL)
return -1;
if (strlen(target) == 0)
return 0;
if (strlen(text) == 0)
return 0;
cmd = command_format_json("APPEND", "\"%s\" \"%s\"", target, text);
if (cmd == NULL)
return -1;
if (command_send(cmd, socket) != 0) {
command_free(cmd);
return -1;
}
return 0;
}
开发者ID:cafiend,项目名称:W12,代码行数:27,代码来源:hlib.c
示例10: assert
static struct command *command_new(struct command_context *cmd_ctx,
struct command *parent, const struct command_registration *cr)
{
assert(cr->name);
struct command *c = calloc(1, sizeof(struct command));
if (NULL == c)
return NULL;
c->name = strdup(cr->name);
if (cr->help)
c->help = strdup(cr->help);
if (cr->usage)
c->usage = strdup(cr->usage);
if (!c->name || (cr->help && !c->help) || (cr->usage && !c->usage))
goto command_new_error;
c->parent = parent;
c->handler = cr->handler;
c->jim_handler = cr->jim_handler;
c->jim_handler_data = cr->jim_handler_data;
c->mode = cr->mode;
command_add_child(command_list_for_parent(cmd_ctx, parent), c);
return c;
command_new_error:
command_free(c);
return NULL;
}
开发者ID:unnamet,项目名称:estick-jtag,代码行数:32,代码来源:command.c
示例11: SendText
/* TODO: remove this */
int SendText(Display *display, int x, int y, char *text)
{
Command *cmd = NULL;
Socket *socket = NULL;
int textlen = 0;
socket = display->socket;
if (text == NULL)
return -1;
textlen = strlen(text);
if (textlen == 0)
return 0;
//command_format("TXT %d %d %s", x, y, text);
cmd = command_format_json("TXT", "\"%s\" %d %d", text, x, y);
if (cmd == NULL)
return -1;
if (command_send(cmd, socket) != 0) {
command_free(cmd);
return -1;
}
return 0;
}
开发者ID:cafiend,项目名称:W12,代码行数:28,代码来源:hlib.c
示例12: sieve_pop_send_queue
static gint sieve_pop_send_queue(SieveSession *session)
{
SieveCommand *cmd;
GSList *send_queue = session->send_queue;
if (session->current_cmd) {
command_free(session->current_cmd);
session->current_cmd = NULL;
}
if (!send_queue)
return SE_OK;
cmd = (SieveCommand *)send_queue->data;
session->send_queue = g_slist_next(send_queue);
g_slist_free_1(send_queue);
log_send(session, cmd);
session->state = cmd->next_state;
session->current_cmd = cmd;
if (session_send_msg(SESSION(session), SESSION_SEND, cmd->msg) < 0)
return SE_ERROR;
return SE_OK;
}
开发者ID:buzz,项目名称:claws,代码行数:25,代码来源:managesieve.c
示例13: help
void help(command_t* self)
{
(void)(self);
std::cout <<
" _ __ _ __ _ ____ \n"
"| |\\ | ( (` | |\\ | / /\\ | |_/ | |_ \n"
"|_| \\| _)_) |_| \\| /_/--\\ |_| \\ |_|__ \n"
"v" VERSION " (built " DATE ")\n"
"\n"
"nsnake is the classical snake game on the\n"
"terminal.\n"
"It's settings and scores are stored at:\n"
" ~/.local/share/nsnake/\n"
"\n"
"Usage:\n"
" nsnake [options]\n"
"\n"
" -h, --help Show this message\n"
" -v, --version Show game version and contact info\n"
"\n"
"Thank you for playing this game :)\n";
command_free(self);
exit(EXIT_SUCCESS);
}
开发者ID:DovydasA,项目名称:nsnake,代码行数:26,代码来源:Arguments.cpp
示例14: SendKeyboardCallbackMsg
int SendKeyboardCallbackMsg(Display *display, char* type, char* list)
{
Command *cmd = NULL;
Socket *socket = NULL;
int i,size;
char *str, args[10];
socket = display->socket;
if (list == NULL) {
cmd = command_format_json(type, "\"%s\"", "ALL");
} else {
size = strlen(list);
str = calloc(size*5, sizeof(char));
for (i = 0; i < size; i ++) {
if (i != size -1) sprintf(args, "%hu,", list[i]);
else sprintf(args, "%hu", list[i]);
strcat(str, args);
}
cmd = command_format_json(type, "%s", str);
free(str);
}
if (cmd == NULL)
return -1;
if (command_send(cmd, socket) != 0) {
command_free(cmd);
return -1;
}
return 0;
}
开发者ID:cafiend,项目名称:W12,代码行数:33,代码来源:hlib.c
示例15: input_driver_deinit_command
void input_driver_deinit_command(void)
{
#ifdef HAVE_COMMAND
if (input_driver_command)
command_free(input_driver_command);
input_driver_command = NULL;
#endif
}
开发者ID:Skylark13,项目名称:RetroArch,代码行数:8,代码来源:input_driver.c
示例16: main
int
main(int argc, char *argv[])
{
int quiet = 0;
char input[BUFSIZ];
int r = 0;
// Check for '-q' option: be quiet -- print no prompts
if (argc > 1 && strcmp(argv[1], "-q") == 0)
quiet = 1;
signal(SIGCHLD,signal_handler);
while (!feof(stdin)) {
parsestate_t parsestate;
command_t *cmdlist;
// Print the prompt
if (!quiet) {
printf("prog1$ ");
fflush(stdout);
}
// Read a string, checking for error or EOF
if (fgets(input, BUFSIZ, stdin) == NULL) {
if (ferror(stdin))
// This function prints a description of the
// error, preceded by 'cs111_fall07: '.
perror("prog1");
break;
}
// TODO: invoke some function(s) in cmdline.c for parsing the read string.
parse_init(&parsestate,input);
cmdlist=command_line_parse(&parsestate,0);
if (!cmdlist) {
printf("Syntax error\n");
continue;
}
// print the command list
if (!quiet) {
// TODO: invoke some function(s) in cmdline.c for printing out the command for debugging.
command_print(cmdlist,1);
// why do we need to do this?
fflush(stdout);
}
// and run it!
int not_impotant=0;
waitpid(-1,¬_impotant,WNOHANG);//kill zombies
if (cmdlist)
command_line_exec(cmdlist);
if (cmdlist)
command_free(cmdlist);
}
return 0;
}
开发者ID:TXing123,项目名称:prog1,代码行数:58,代码来源:main-b.c
示例17: cli_context_flag_dispatch
/* 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);
}
开发者ID:randalboyle,项目名称:xmms2-devel,代码行数:59,代码来源:cli_context.c
示例18: OverwriteTextArea
/* This is partly controlled by the BUFSIZE (currently 128) in command.c and partly due to JSON overhead. */
int OverwriteTextArea(Display *display, const char *target, const char *text)
{
Command *cmd = NULL;
Socket *socket = NULL;
int i,j,count, len;
char *tmp;
socket = display->socket;
if (target == NULL || text == NULL || strchr(target, '\n') != NULL)
return -1;
if (strlen(target) == 0)
return 0;
len = strlen(text);
if (len == 0)
return 0;
if (strchr(text, '\n') || strchr(text, '\r')) {
/* at least one newline to deal with */
count = 0;
j = 0;
for(i = 0; i < len; i++) {
if (text[i] == '\n' || text[i] == '\r') count++;
}
tmp = calloc(len+count, sizeof(char));
for(i = 0; i < len; i++) {
if (text[i] == '\n') {
tmp[j++] = '\\';
tmp[j] = 'n';
} else if (text[i] == '\r') {
tmp[j++] = '\\';
tmp[j] = 'r';
} else {
tmp[j] = text[i];
}
j++;
}
cmd = command_format_json("OVERWRITE", "\"%s\" \"%s\"", target, tmp);
free(tmp);
} else {
cmd = command_format_json("OVERWRITE", "\"%s\" \"%s\"", target, text);
}
if (cmd == NULL)
return -1;
if (command_send(cmd, socket) != 0) {
command_free(cmd);
return -1;
}
return 0;
}
开发者ID:cafiend,项目名称:W12,代码行数:57,代码来源:hlib.c
示例19: cli_context_command_dispatch
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);
}
}
开发者ID:randalboyle,项目名称:xmms2-devel,代码行数:55,代码来源:cli_context.c
示例20: test_redirect
/* Function: test_redirect
Test commands with io redirect
*/
void test_redirect()
{
#ifdef DEBUG_TEST
printf("TEST: Checking I/O redirecting\n");
#endif
cmd = command_parse("a < b > c\n");
assert(cmd != NULL);
assert(cmd->token >= 1);
assert(strcmp(cmd->argv[0], "a") == 0);
assert(strcmp(cmd->infile, "b") == 0);
assert(strcmp(cmd->outfile, "c") == 0);
assert(cmd->fdmode == (O_RDWR|O_TRUNC));
command_free(cmd);
cmd = command_parse("a<b>> c\n");
assert(cmd != NULL);
assert(cmd->token >= 1);
assert(strcmp(cmd->argv[0], "a") == 0);
assert(strcmp(cmd->infile, "b") == 0);
assert(strcmp(cmd->outfile, "c") == 0);
assert(cmd->fdmode == (O_RDWR|O_APPEND));
command_free(cmd);
cmd = command_parse("a<b>c\n");
assert(cmd != NULL);
assert(cmd->token >= 1);
assert(strcmp(cmd->argv[0], "a") == 0);
assert(strcmp(cmd->infile, "b") == 0);
assert(strcmp(cmd->outfile, "c") == 0);
assert(cmd->fdmode == (O_RDWR|O_TRUNC));
command_free(cmd);
cmd = command_parse("a <b >>c\n");
assert(cmd != NULL);
assert(cmd->token >= 1);
assert(strcmp(cmd->argv[0], "a") == 0);
assert(strcmp(cmd->infile, "b") == 0);
assert(strcmp(cmd->outfile, "c") == 0);
assert(cmd->fdmode == (O_RDWR|O_APPEND));
command_free(cmd);
}
开发者ID:dzhou,项目名称:Shell-from-scratch,代码行数:45,代码来源:parser_test.c
注:本文中的command_free函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论