CommandCode command_add_character(u08 in_char) { if( in_char != '#' ) { // if incoming char is not '#', just add it and return _append_char(in_char); if( strlen(command_str) == 1 ) { return CommandCodeFirstChar; } } else { // user pressed '#' if( strlen(command_str) <= 4 ) { CommandCode temp = atoi(command_str); command_init(); return temp; } else { command_init(); return CommandCodeInvalid; } } return CommandCodeIncomplete; }
int maintainer_script_alternative(struct pkginfo *pkg, const char *scriptname, const char *desc, const char *cidir, char *cidirrest, const char *ifok, const char *iffallback) { struct command cmd; const char *oldscriptpath; struct stat stab; char buf[100]; oldscriptpath = pkgadminfile(pkg, &pkg->installed, scriptname); sprintf(buf, _("old %s script"), desc); command_init(&cmd, oldscriptpath, buf); command_add_args(&cmd, scriptname, ifok, versiondescribe(&pkg->available.version, vdew_nonambig), NULL); if (stat(oldscriptpath,&stab)) { if (errno == ENOENT) { debug(dbg_scripts,"maintainer_script_alternative nonexistent %s `%s'", scriptname,oldscriptpath); command_destroy(&cmd); return 0; } warning(_("unable to stat %s '%.250s': %s"), cmd.name, oldscriptpath, strerror(errno)); } else { if (!do_script(pkg, &pkg->installed, &cmd, &stab, PROCWARN)) { command_destroy(&cmd); post_script_tasks(); return 1; } } fprintf(stderr, _("dpkg - trying script from the new package instead ...\n")); strcpy(cidirrest,scriptname); sprintf(buf, _("new %s script"), desc); command_destroy(&cmd); command_init(&cmd, cidir, buf); command_add_args(&cmd, scriptname, iffallback, versiondescribe(&pkg->installed.version, vdew_nonambig), NULL); if (stat(cidir,&stab)) { command_destroy(&cmd); if (errno == ENOENT) ohshit(_("there is no script in the new version of the package - giving up")); else ohshite(_("unable to stat %s `%.250s'"),buf,cidir); } do_script(pkg, &pkg->available, &cmd, &stab, 0); fprintf(stderr, _("dpkg: ... it looks like that went OK.\n")); command_destroy(&cmd); post_script_tasks(); return 1; }
/* * Get the cached artwork image for the given persistentid and maximum width/height * * If there is a cached entry for the given id and width/height, the parameter cached is set to 1. * In this case format and data contain the cached values. * * @param persistentid persistent songalbumid or songartistid * @param max_w maximum image width * @param max_h maximum image height * @param cached set by this function to 0 if no cache entry exists, otherwise 1 * @param format set by this function to the format of the cache entry * @param evbuf event buffer filled by this function with the scaled image * @return 0 if successful, -1 if an error occurred */ int cache_artwork_get(int64_t persistentid, int max_w, int max_h, int *cached, int *format, struct evbuffer *evbuf) { struct cache_command cmd; int ret; if (!g_initialized) return -1; command_init(&cmd); cmd.func = cache_artwork_get_impl; cmd.arg.peristentid = persistentid; cmd.arg.max_w = max_w; cmd.arg.max_h = max_h; cmd.arg.evbuf = evbuf; ret = sync_command(&cmd); *format = cmd.arg.format; *cached = cmd.arg.cached; command_deinit(&cmd); return ret; }
/* * Adds the given (scaled) artwork image to the artwork cache * * @param persistentid persistent songalbumid or songartistid * @param max_w maximum image width * @param max_h maximum image height * @param format ART_FMT_PNG for png, ART_FMT_JPEG for jpeg or 0 if no artwork available * @param filename the full path to the artwork file (could be an jpg/png image or a media file with embedded artwork) or empty if no artwork available * @param evbuf event buffer containing the (scaled) image * @return 0 if successful, -1 if an error occurred */ int cache_artwork_add(int64_t persistentid, int max_w, int max_h, int format, char *filename, struct evbuffer *evbuf) { struct cache_command cmd; int ret; if (!g_initialized) return -1; command_init(&cmd); cmd.func = cache_artwork_add_impl; cmd.arg.peristentid = persistentid; cmd.arg.max_w = max_w; cmd.arg.max_h = max_h; cmd.arg.format = format; cmd.arg.path = strdup(filename); cmd.arg.evbuf = evbuf; ret = sync_command(&cmd); command_deinit(&cmd); return ret; }
Command_t* select_command_new(Object_t *obj) { SelectCommand_t *command = g_new(SelectCommand_t, 1); command->obj = object_ref(obj); return command_init(&command->parent, _("Select"), &select_command_class); }
int command_parse(int argc, char** argv, Command* data_ptr) { int result = 0; if (data_ptr != NULL) { int i; command_init(argc, argv, data_ptr); result = 1; for (i = 0; i < argc; ++i) { char* p = argv[i]; if (p != NULL) { if (strcmp(p, "--help") == 0) { i += command_parse_help(argc, argv, data_ptr, i); } else if (strcmp(p, "--title") == 0 || strcmp(p, "-t") == 0) { i += command_parse_title(argc, argv, data_ptr, i); } else if (strcmp(p, "--action") == 0 || strcmp(p, "-a") == 0) { i += command_parse_action(argc, argv, data_ptr, i); } else if (strcmp(p, "--filter") == 0 || strcmp(p, "-f") == 0) { i += command_parse_filter(argc, argv, data_ptr, i); } } } } return result; }
Command_t* clear_command_new(ObjectList_t *list) { ClearCommand_t *command = g_new(ClearCommand_t, 1); command->list = list; return command_init(&command->parent, _("Clear"), &clear_command_class); }
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; }
static int vmaintainer_script_installed(struct pkginfo *pkg, const char *scriptname, const char *desc, va_list args) { struct command cmd; const char *scriptpath; struct stat stab; char buf[100]; scriptpath = pkgadminfile(pkg, &pkg->installed, scriptname); sprintf(buf, _("installed %s script"), desc); command_init(&cmd, scriptpath, buf); command_add_arg(&cmd, scriptname); command_add_argv(&cmd, args); if (stat(scriptpath,&stab)) { command_destroy(&cmd); if (errno == ENOENT) { debug(dbg_scripts, "vmaintainer_script_installed nonexistent %s", scriptname); return 0; } ohshite(_("unable to stat %s `%.250s'"), buf, scriptpath); } do_script(pkg, &pkg->installed, &cmd, &stab, 0); command_destroy(&cmd); return 1; }
static void DPKG_ATTR_SENTINEL fd_fd_filter(int fd_in, int fd_out, const char *desc, const char *delenv[], const char *file, ...) { va_list args; struct command cmd; pid_t pid; int i; pid = subproc_fork(); if (pid == 0) { if (fd_in != 0) { m_dup2(fd_in, 0); close(fd_in); } if (fd_out != 1) { m_dup2(fd_out, 1); close(fd_out); } for (i = 0; delenv[i]; i++) unsetenv(delenv[i]); command_init(&cmd, file, desc); command_add_arg(&cmd, file); va_start(args, file); command_add_argv(&cmd, args); va_end(args); command_exec(&cmd); } subproc_reap(pid, desc, 0); }
void execbackend(const char *const *argv) { struct command cmd; char *arg; command_init(&cmd, cipaction->parg, NULL); command_add_arg(&cmd, cipaction->parg); /* * Special case: dpkg-query takes the --admindir option, and if dpkg itself * was given a different admin directory, we need to pass it along to it. */ if (strcmp(cipaction->parg, DPKGQUERY) == 0 && strcmp(admindir, ADMINDIR) != 0) { arg = m_malloc((strlen("--admindir=") + strlen(admindir) + 1)); sprintf(arg, "--admindir=%s", admindir); command_add_arg(&cmd, arg); } arg = m_malloc(2 + strlen(cipaction->olong) + 1); sprintf(arg, "--%s", cipaction->olong); command_add_arg(&cmd, arg); /* Exlicitely separate arguments from options as any user-supplied * separator got stripped by the option parser */ command_add_arg(&cmd, "--"); command_add_argl(&cmd, (const char **)argv); command_exec(&cmd); }
int maintainer_script_new(struct pkginfo *pkg, const char *scriptname, const char *desc, const char *cidir, char *cidirrest, ...) { struct command cmd; struct stat stab; va_list args; char buf[100]; strcpy(cidirrest, scriptname); sprintf(buf, _("new %s script"), desc); va_start(args, cidirrest); command_init(&cmd, cidir, buf); command_add_arg(&cmd, scriptname); command_add_argv(&cmd, args); va_end(args); if (stat(cidir,&stab)) { command_destroy(&cmd); if (errno == ENOENT) { debug(dbg_scripts,"maintainer_script_new nonexistent %s `%s'",scriptname,cidir); return 0; } ohshite(_("unable to stat %s `%.250s'"), buf, cidir); } do_script(pkg, &pkg->available, &cmd, &stab, 0); command_destroy(&cmd); post_script_tasks(); return 1; }
int main(int argc, char** argv) { command_t cmd; command_init(&cmd, "dhcore-test", "1.0"); command_option_pos(&cmd, "test", "Choose unit test", TRUE, cmd_gettest); command_parse(&cmd, argc, argv, NULL); if (IS_FAIL(core_init(CORE_INIT_ALL))) { printf("core init error.\n"); return -1; } log_outputconsole(TRUE); if (g_testidx == -1) g_testidx = show_help(); if (g_testidx != -1) g_tests[g_testidx].test_fn(); #if defined(_DEBUG_) core_release(TRUE); #else core_release(FALSE); #endif return 1; }
Command_t* cut_command_new(ObjectList_t *list) { CutCommand_t *command = g_new(CutCommand_t, 1); command->list = list; command->paste_buffer = NULL; return command_init(&command->parent, _("Cut"), &cut_command_class); }
Command_t* move_up_command_new(ObjectList_t *list) { MoveUpCommand_t *command = g_new(MoveUpCommand_t, 1); command->list = list; command->add = FALSE; return command_init(&command->parent, _("Move Up"), &move_up_command_class); }
Command_t* select_next_command_new(ObjectList_t *list) { SelectNextCommand_t *command = g_new(SelectNextCommand_t, 1); command->list = list; return command_init(&command->parent, _("Select Next"), &select_next_command_class); }
Command_t* create_command_new(ObjectList_t *list, Object_t *obj) { CreateCommand_t *command = g_new(CreateCommand_t, 1); command->list = list; command->obj = object_ref(obj); return command_init(&command->parent, _("Create"), &create_command_class); }
Command_t* object_down_command_new(ObjectList_t *list, Object_t *obj) { ObjectDownCommand_t *command = g_new(ObjectDownCommand_t, 1); command->list = list; command->obj = object_ref(obj); return command_init(&command->parent, _("Move Down"), &object_down_command_class); }
// Initialise the risp system. static void init_risp(system_data_t *sysdata) { assert(sysdata); assert(sysdata->risp == NULL); sysdata->risp = risp_init(NULL); assert(sysdata->risp); command_init(sysdata->risp); }
Command_t* delete_command_new(ObjectList_t *list, Object_t *obj) { DeleteCommand_t *command = g_new(DeleteCommand_t, 1); command->list = list; command->obj = object_ref(obj); return command_init(&command->parent, _("Delete"), &delete_command_class); }
/** constructor(). */ void flipdown_init(struct flipdown *flipdown, struct light *light, int val) { _MY_TRACE_STR("flipdown_init()\n"); memset(flipdown, sizeof(*flipdown), 0); command_init(&flipdown->command); CLASS_OPS_INIT(flipdown->command.ops, command_ops); flipdown->_light = light; flipdown->_val = val; }
int ihome_command_init(output_fun_t output) { #define _run(fun) do{ if(fun != 0) return -1; } while(0) _run(command_init(&ihome_command_head)); command_set_output(ihome_command_head, output, NULL); _run(ihome_command_install()); return 0; #undef _run }
void weechat_init (int argc, char *argv[], void (*gui_init_cb)()) { weechat_first_start_time = time (NULL); /* initialize start time */ gettimeofday (&weechat_current_start_timeval, NULL); /* catch signals */ util_catch_signal (SIGINT, SIG_IGN); /* signal ignored */ util_catch_signal (SIGPIPE, SIG_IGN); /* signal ignored */ util_catch_signal (SIGSEGV, &debug_sigsegv); /* crash dump */ util_catch_signal (SIGHUP, &weechat_sighup); /* exit WeeChat */ util_catch_signal (SIGQUIT, &weechat_sigquit); /* exit WeeChat */ util_catch_signal (SIGTERM, &weechat_sigterm); /* exit WeeChat */ hdata_init (); /* initialize hdata */ hook_init (); /* initialize hooks */ debug_init (); /* hook signals for debug */ gui_color_init (); /* initialize colors */ gui_chat_init (); /* initialize chat */ command_init (); /* initialize WeeChat commands */ completion_init (); /* add core completion hooks */ gui_key_init (); /* init keys */ network_init_gcrypt (); /* init gcrypt */ if (!secure_init ()) /* init secured data options (sec.*)*/ weechat_shutdown (EXIT_FAILURE, 0); if (!config_weechat_init ()) /* init WeeChat options (weechat.*) */ weechat_shutdown (EXIT_FAILURE, 0); weechat_parse_args (argc, argv); /* parse command line args */ weechat_create_home_dir (); /* create WeeChat home directory */ log_init (); /* init log file */ plugin_api_init (); /* create some hooks (info,hdata,..)*/ secure_read (); /* read secured data options */ config_weechat_read (); /* read WeeChat options */ network_init_gnutls (); /* init GnuTLS */ if (gui_init_cb) (*gui_init_cb) (); /* init WeeChat interface */ if (weechat_upgrading) { upgrade_weechat_load (); /* upgrade with session file */ weechat_upgrade_count++; /* increase /upgrade count */ } weechat_startup_message (); /* display WeeChat startup message */ gui_chat_print_lines_waiting_buffer (NULL); /* display lines waiting */ weechat_term_check (); /* warning about wrong $TERM */ weechat_locale_check (); /* warning about wrong locale */ command_startup (0); /* command executed before plugins */ plugin_init (weechat_force_plugin_autoload, /* init plugin interface(s) */ argc, argv); command_startup (1); /* commands executed after plugins */ if (!weechat_upgrading) gui_layout_window_apply (gui_layout_current, -1); if (weechat_upgrading) upgrade_weechat_end (); /* remove .upgrade files + signal */ }
Command_t* move_selected_command_new(ObjectList_t *list, gint dx, gint dy) { MoveSelectedCommand_t *command = g_new(MoveSelectedCommand_t, 1); command->list = list; command->dx = dx; command->dy = dy; return command_init(&command->parent, _("Move Selected Objects"), &move_selected_command_class); }
int mintchip_end(struct mintchip * chip) { union command cmd; command_init(&cmd); cmd.h.ready = 0xFF; send_request(chip, &cmd); poll_for_response(chip, &cmd); return 0; }
// quality MUST be within the range of [0-3] // quality=3 indicates that the original payload can be sent int transcode_video(int infd, int quality) { // Raw not supported yet if(quality == QUALITY_RAW) { quality = 2; } GError* error = NULL; GstElement* pipeline = gst_parse_launch(VIDEO_RT_PIPELINE, &error); if(error != NULL) { fprintf(stderr, "Failed to initialize gstreamer pipeline: %s\n", error->message); return 1; } if(pipeline == NULL) { fprintf(stderr, "Failed to initialize gstreamer pipeline\n"); return 1; } GstElement* src = gst_bin_get_by_name(GST_BIN(pipeline), "src"); GstElement* video_enc = gst_bin_get_by_name(GST_BIN(pipeline), "video-enc"); GstElement* sink = gst_bin_get_by_name(GST_BIN(pipeline), "sink"); if(src == NULL || video_enc == NULL || sink == NULL) { fprintf(stderr, "Failed to select gstreamer elements\n"); return 1; } // Create our command input context struct command_ctx data; command_init(&data, pipeline, video_enc); data.set_quality = &movie_set_quality; // Configure the pipeline options g_object_set(G_OBJECT(src), "fd", infd, NULL); g_object_set(G_OBJECT(sink), "fd", STDOUT_FILENO, NULL); data.set_quality(&data, quality); // Create the GLib main loop GMainLoop* loop = g_main_loop_new(NULL, false); GstBus* bus = gst_pipeline_get_bus(GST_PIPELINE(pipeline)); gst_bus_add_watch(bus, bus_call, loop); gst_object_unref(bus); // Set up our command input watcher on stdin GIOChannel* command_channel = g_io_channel_unix_new(STDIN_FILENO); g_io_add_watch(command_channel, G_IO_IN, handle_stdin, &data); g_io_channel_unref(command_channel); // Let's roll gst_element_set_state(pipeline, GST_STATE_PLAYING); g_main_loop_run(loop); gst_element_set_state(pipeline, GST_STATE_NULL); return 0; }
void kmain(const multiboot_info_t* multi_boot_info, unsigned int multiboot_magic) { if (MULTIBOOT_BOOTLOADER_MAGIC != multiboot_magic) { return; } (void) multi_boot_info; serial_init(); printf("Welcome to the future!\n"); command_init(); command_loop(); }
void Arguments::parse(int argc, char* argv[]) { // commander internal data structure command_t cmd; command_init(&cmd, argv[0], VERSION); command_option(&cmd, "-v", "--version", "Show game version and build date", version); command_option(&cmd, "-h", "--help", "Show instructions", help); command_parse(&cmd, argc, argv); command_free(&cmd); }
int mintchip_begin(struct mintchip * chip) { // TODO add a chip->hasBegun union command cmd; command_init(&cmd); cmd.h.ready = 0xFD; send_request(chip, &cmd); poll_for_response(chip, &cmd); return 0; }
int command_main(int argc, char *argv[]) { char *p; int size; int num = 0; char *cmd[COMMAND_WORD_NUM]; int cmd_len = 0; int i, j; send_use(SERIAL_DEFAULT_DEVICE); command_init( cmd ); file_init(); while (1) { send_write("command> "); /* プロンプト表示 */ /* コマンド格納バッファを0クリアする */ for( j = 0; j < COMMAND_WORD_NUM; j++ ){ memset( cmd[j], 0, COMMAND_WORD_LENGTH ); } /* コンソールからの受信文字列を受け取る */ kz_recv(MSGBOX_ID_CONSINPUT, &size, &p); p[size] = '\0'; /* 入力文字列を分解する */ if( ( num = command_split( p, cmd ) ) == 0 ){ send_write("input nothing\n"); continue; } /* コマンドの実行 */ cmd_len = strlen( cmd[0] ); for( i = 0; command_table[i].cmd != NULL; i++ ){ if( !strncmp( cmd[0], command_table[i].cmd, (cmd_len>command_table[i].size?cmd_len:command_table[i].size) ) ){ command_table[i].func( num, cmd ); break; } } if( command_table[i].cmd == NULL ){ send_write("unknown.\n"); } kz_kmfree(p); } command_terminate( cmd ); return 0; }