static bool parse_cli_options(int argc,char *argv[],cli_options_t *cli_options) { int opt, index; struct option options[] = { { "help", no_argument, 0, 'h' }, { "config-file", required_argument, 0, 'c' }, { "plugins-path", required_argument, 0, 'p' }, { "models-path", required_argument, 0, 'm' }, { 0,0,0,0 } }; for (;;) { opt = getopt_long(argc,argv,"hc:p:m:",options,&index); if (opt < 0) break; switch (opt) { case 'c': cli_options->config_file = optarg; break; case 'h': help_msg(argv[0]); return false; case 'p': cli_options->plugins_path = optarg; break; default: error_msg(argv[0]); return false; } } return true; }
static void do_recursive_merge(struct commit *base, struct commit *next, const char *base_label, const char *next_label, unsigned char *head, struct strbuf *msgbuf, char *defmsg) { struct merge_options o; struct tree *result, *next_tree, *base_tree, *head_tree; int clean, index_fd; static struct lock_file index_lock; index_fd = hold_locked_index(&index_lock, 1); read_cache(); init_merge_options(&o); o.ancestor = base ? base_label : "(empty tree)"; o.branch1 = "HEAD"; o.branch2 = next ? next_label : "(empty tree)"; head_tree = parse_tree_indirect(head); next_tree = next ? next->tree : empty_tree(); base_tree = base ? base->tree : empty_tree(); clean = merge_trees(&o, head_tree, next_tree, base_tree, &result); if (active_cache_changed && (write_cache(index_fd, active_cache, active_nr) || commit_locked_index(&index_lock))) die("%s: Unable to write new index file", me); rollback_lock_file(&index_lock); if (!clean) { int i; strbuf_addstr(msgbuf, "\nConflicts:\n\n"); for (i = 0; i < active_nr;) { struct cache_entry *ce = active_cache[i++]; if (ce_stage(ce)) { strbuf_addch(msgbuf, '\t'); strbuf_addstr(msgbuf, ce->name); strbuf_addch(msgbuf, '\n'); while (i < active_nr && !strcmp(ce->name, active_cache[i]->name)) i++; } } write_message(msgbuf, defmsg); fprintf(stderr, "Automatic %s failed.%s\n", me, help_msg()); rerere(allow_rerere_auto); exit(1); } write_message(msgbuf, defmsg); fprintf(stderr, "Finished one %s.\n", me); }
void FeInputSelMenu::get_options( FeConfigContext &ctx ) { ctx.set_style( FeConfigContext::EditList, "Configure / Controls" ); ctx.fe_settings.get_input_mappings( m_mappings ); std::vector < FeMapping >::iterator it; for ( it=m_mappings.begin(); it != m_mappings.end(); ++it ) { std::string setstr, help, orstr; ctx.fe_settings.get_resource( "OR", orstr ); std::string value; std::vector < std::string >::iterator iti; for ( iti=(*it).input_list.begin(); iti != (*it).input_list.end(); ++iti ) { if ( iti > (*it).input_list.begin() ) { value += " "; value += orstr; value += " "; } value += (*iti); } std::string help_msg( "_help_control_" ); help_msg += FeInputMap::commandStrings[(*it).command]; ctx.add_optl( Opt::SUBMENU, FeInputMap::commandDispStrings[(*it).command], value, help_msg ); } // Add the joystick and mouse threshold settings to this menu as well std::vector<std::string> thresh(21); thresh[0]="99"; for ( int i=0; i<19; i++ ) thresh[i+1] = as_str( 95 - ( i * 5 ) ); thresh[20]="1"; std::string setstr, help; ctx.add_optl( Opt::LIST, "Joystick Threshold", ctx.fe_settings.get_info( FeSettings::JoystickThreshold ), "_help_joystick_threshold" ); ctx.back_opt().append_vlist( thresh ); ctx.back_opt().opaque = 1; ctx.add_optl( Opt::LIST, "Mouse Threshold", ctx.fe_settings.get_info( FeSettings::MouseThreshold ), "_help_mouse_threshold" ); ctx.back_opt().append_vlist( thresh ); ctx.back_opt().opaque = 1; FeBaseConfigMenu::get_options( ctx ); }
int non_interactive_mode (PedDevice** dev, PedDisk **disk, Command* cmd_list[], int argc, char* argv[]) { int i; Command* cmd; commands = cmd_list; /* FIXME yucky, nasty, evil hack */ for (i = 0; i < argc; i++) command_line_push_line (argv [i], 1); while (command_line_get_word_count ()) { char* word; word = command_line_pop_word (); if (!word) break; cmd = command_get (commands, word); free (word); if (!cmd) { help_msg (); goto error; } if (!(cmd->non_interactive)) { fputs(_("This command does not make sense in " "non-interactive mode.\n"), stdout); exit(EXIT_FAILURE); goto error; } if (!command_run (cmd, dev, disk)) goto error; } return 1; error: return 0; }
int main(int argc, char **argv) { fprintf( stdout, header ); DEBUG(( stderr, "main: parsing command line\n" )); if( parse_cmdline( argc, argv, options, countof(options) ) ) goto bail_out; if( warnings && (linker_options & OPT_ABORT_ON_WARN) ) goto bail_out; if( linker_options & OPT_SHOW_HELP ) { help_msg( help_head, help_tail, options, countof(options) ); goto bail_out; } if( !root_obj ) { error( "no input files" ); goto bail_out; } if( arrange_sections() ) goto bail_out; if( warnings && (linker_options & OPT_ABORT_ON_WARN) ) goto bail_out; adjust_symbols_values(); register_symbols(); resolve_references(); if( warnings && (linker_options & OPT_ABORT_ON_WARN) ) goto bail_out; apply_relocations(); if( warnings && (linker_options & OPT_ABORT_ON_WARN) ) goto bail_out; if( !(linker_options & OPT_MAKE_ORB) ) generate_mt(); if( errors || warnings && (linker_options & OPT_ABORT_ON_WARN) ) goto bail_out; output_sections( output_filename ); if( !(linker_options & OPT_MAKE_ORB) ) output_metadata( output_filename ); if( warnings && (linker_options & OPT_ABORT_ON_WARN) ) goto bail_out; if( linker_options & OPT_XREF ) produce_xrefs( output_filename ); if( errors || (warnings && (linker_options & OPT_ABORT_ON_WARN))) remove(output_filename); else if( linker_options & OPT_VERBOSE ) { fprintf(stdout, "\n" "******************************************************\n" "** %s\n" "**\n", output_filename ); if( linker_options & OPT_MAKE_ORB ) fprintf( stdout, "** ORB generated as:\n" ); else fprintf( stdout, "** Component generated as:\n" ); fprintf(stdout, "** Text at 0x%08x, size 0x%08x\n" "** Data at 0x%08x, size 0x%08x\n" "** BSS at 0x%08x, size 0x%08x\n", comp.text.start, comp.text.size, comp.data.start, comp.data.size, comp.bss.start, comp.bss.size ); if( !(linker_options & OPT_MAKE_ORB) ) fprintf( stdout, "** MTbl at 0x%08x, size 0x%08x\n", comp.mt.start, comp.mt.size ); fprintf(stdout, "******************************************************\n" "\n" ); } bail_out: //global_destruction(); // who cares? we exit anyway... if( errors || warnings ) fprintf( stderr, "exiting with %d error(s), %d warning(s)\n", errors, warnings ); if( warnings && (linker_options & OPT_ABORT_ON_WARN) ) return errors + warnings; return errors; }
static int do_pick_commit(void) { unsigned char head[20]; struct commit *base, *next, *parent; const char *base_label, *next_label; struct commit_message msg = { NULL, NULL, NULL, NULL, NULL }; char *defmsg = NULL; struct strbuf msgbuf = STRBUF_INIT; if (no_commit) { /* * We do not intend to commit immediately. We just want to * merge the differences in, so let's compute the tree * that represents the "current" state for merge-recursive * to work on. */ if (write_cache_as_tree(head, 0, NULL)) die ("Your index file is unmerged."); } else { if (get_sha1("HEAD", head)) die ("You do not have a valid HEAD"); if (index_differs_from("HEAD", 0)) die_dirty_index(me); } discard_cache(); if (!commit->parents) { if (action == REVERT) die ("Cannot revert a root commit"); parent = NULL; } else if (commit->parents->next) { /* Reverting or cherry-picking a merge commit */ int cnt; struct commit_list *p; if (!mainline) die("Commit %s is a merge but no -m option was given.", sha1_to_hex(commit->object.sha1)); for (cnt = 1, p = commit->parents; cnt != mainline && p; cnt++) p = p->next; if (cnt != mainline || !p) die("Commit %s does not have parent %d", sha1_to_hex(commit->object.sha1), mainline); parent = p->item; } else if (0 < mainline) die("Mainline was specified but commit %s is not a merge.", sha1_to_hex(commit->object.sha1)); else parent = commit->parents->item; if (allow_ff && !hashcmp(parent->object.sha1, head)) return fast_forward_to(commit->object.sha1, head); if (parent && parse_commit(parent) < 0) die("%s: cannot parse parent commit %s", me, sha1_to_hex(parent->object.sha1)); if (get_message(commit->buffer, &msg) != 0) die("Cannot get commit message for %s", sha1_to_hex(commit->object.sha1)); /* * "commit" is an existing commit. We would want to apply * the difference it introduces since its first parent "prev" * on top of the current HEAD if we are cherry-pick. Or the * reverse of it if we are revert. */ defmsg = git_pathdup("MERGE_MSG"); if (action == REVERT) { base = commit; base_label = msg.label; next = parent; next_label = msg.parent_label; strbuf_addstr(&msgbuf, "Revert \""); strbuf_addstr(&msgbuf, msg.subject); strbuf_addstr(&msgbuf, "\"\n\nThis reverts commit "); strbuf_addstr(&msgbuf, sha1_to_hex(commit->object.sha1)); if (commit->parents->next) { strbuf_addstr(&msgbuf, ", reversing\nchanges made to "); strbuf_addstr(&msgbuf, sha1_to_hex(parent->object.sha1)); } strbuf_addstr(&msgbuf, ".\n"); } else { base = parent; base_label = msg.parent_label; next = commit; next_label = msg.label; set_author_ident_env(msg.message); add_message_to_msg(&msgbuf, msg.message); if (no_replay) { strbuf_addstr(&msgbuf, "(cherry picked from commit "); strbuf_addstr(&msgbuf, sha1_to_hex(commit->object.sha1)); strbuf_addstr(&msgbuf, ")\n"); } } if (!strategy || !strcmp(strategy, "recursive") || action == REVERT) do_recursive_merge(base, next, base_label, next_label, head, &msgbuf, defmsg); else { int res; struct commit_list *common = NULL; struct commit_list *remotes = NULL; write_message(&msgbuf, defmsg); commit_list_insert(base, &common); commit_list_insert(next, &remotes); res = try_merge_command(strategy, common, sha1_to_hex(head), remotes); free_commit_list(common); free_commit_list(remotes); if (res) { fprintf(stderr, "Automatic %s with strategy %s failed.%s\n", me, strategy, help_msg()); rerere(allow_rerere_auto); exit(1); } } free_message(&msg); /* * * If we are cherry-pick, and if the merge did not result in * hand-editing, we will hit this commit and inherit the original * author date and name. * If we are revert, or if our cherry-pick results in a hand merge, * we had better say that the current user is responsible for that. */ if (!no_commit) { /* 6 is max possible length of our args array including NULL */ const char *args[6]; int res; int i = 0; args[i++] = "commit"; args[i++] = "-n"; if (signoff) args[i++] = "-s"; if (!edit) { args[i++] = "-F"; args[i++] = defmsg; } args[i] = NULL; res = run_command_v_opt(args, RUN_GIT_CMD); free(defmsg); return res; } free(defmsg); return 0; }
std::map<std::string, std::string> parse_params(int argc, char** argv) { std::map<std::string, std::string> conf_map; char * file_name = new char [MAX_LEN_NAME]; char * app_dir = new char [MAX_LEN_NAME]; int slash_index = 0; for (int i (strlen(argv[0]) - 1); i > 0; i--) { if (argv[0][i] == '/' || argv[0][i] == '\\') { slash_index = i+1; break; } } for (int i(0); i < slash_index; ++i) { app_dir[i] = argv[0][i]; app_dir[i+1] = '\0'; } std::string input_path = app_dir; if (argc == 1) { strcat(app_dir, "input.conf"); strcpy(file_name, app_dir); } else { if (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help") || !strcmp(argv[1], "-help")) { help_msg(argv); exit(0); } else if (!strcmp(argv[1], "-conf")) { if (argc < 3) { std::cerr << "Error! You didn't pass file name!" << std::endl; exit(101); } else { slash_index = 0; char * in_dir = new char [MAX_LEN_NAME]; for (int i (strlen(argv[2]) - 1); i > 0; i--) { if (argv[2][i] == '/' || argv[2][i] == '\\') { slash_index = i+1; break; } } for (int i(0); i < slash_index; ++i) { in_dir[i] = argv[2][i]; in_dir[i+1] = '\0'; } input_path = in_dir; delete in_dir; strcpy(file_name, argv[2]); } } else { std::cerr << "Error! Unknown argument! Use: \"" << argv[0] << " -h\" for help." << std::endl; exit(102); } } char * buf = new char [MAX_LEN_NAME]; int count = readlink(file_name, buf, sizeof(char)*MAX_LEN_NAME); if (count >= 0) { buf[count] = '\0'; strcpy(file_name, buf); } delete buf; conf_map = parse_file(file_name); conf_map["input_path"] = input_path; delete file_name; delete app_dir; return conf_map; }
static int revert_or_cherry_pick(int argc, const char **argv) { unsigned char head[20]; struct commit *base, *next, *parent; int i; char *oneline, *reencoded_message = NULL; const char *message, *encoding; const char *defmsg = xstrdup(git_path("MERGE_MSG")); git_config(git_default_config); me = action == REVERT ? "revert" : "cherry-pick"; setenv(GIT_REFLOG_ACTION, me, 0); parse_args(argc, argv); /* this is copied from the shell script, but it's never triggered... */ if (action == REVERT && !no_replay) die("revert is incompatible with replay"); if (no_commit) { /* * We do not intend to commit immediately. We just want to * merge the differences in, so let's compute the tree * that represents the "current" state for merge-recursive * to work on. */ if (write_cache_as_tree(head, 0, NULL)) die ("Your index file is unmerged."); } else { if (get_sha1("HEAD", head)) die ("You do not have a valid HEAD"); if (read_cache() < 0) die("could not read the index"); if (index_is_dirty()) die ("Dirty index: cannot %s", me); discard_cache(); } if (!commit->parents) die ("Cannot %s a root commit", me); if (commit->parents->next) { /* Reverting or cherry-picking a merge commit */ int cnt; struct commit_list *p; if (!mainline) die("Commit %s is a merge but no -m option was given.", sha1_to_hex(commit->object.sha1)); for (cnt = 1, p = commit->parents; cnt != mainline && p; cnt++) p = p->next; if (cnt != mainline || !p) die("Commit %s does not have parent %d", sha1_to_hex(commit->object.sha1), mainline); parent = p->item; } else if (0 < mainline) die("Mainline was specified but commit %s is not a merge.", sha1_to_hex(commit->object.sha1)); else parent = commit->parents->item; if (!(message = commit->buffer)) die ("Cannot get commit message for %s", sha1_to_hex(commit->object.sha1)); /* * "commit" is an existing commit. We would want to apply * the difference it introduces since its first parent "prev" * on top of the current HEAD if we are cherry-pick. Or the * reverse of it if we are revert. */ msg_fd = hold_lock_file_for_update(&msg_file, defmsg, 1); encoding = get_encoding(message); if (!encoding) encoding = "utf-8"; if (!git_commit_encoding) git_commit_encoding = "utf-8"; if ((reencoded_message = reencode_string(message, git_commit_encoding, encoding))) message = reencoded_message; oneline = get_oneline(message); if (action == REVERT) { char *oneline_body = strchr(oneline, ' '); base = commit; next = parent; add_to_msg("Revert \""); add_to_msg(oneline_body + 1); add_to_msg("\"\n\nThis reverts commit "); add_to_msg(sha1_to_hex(commit->object.sha1)); add_to_msg(".\n"); } else { base = parent; next = commit; set_author_ident_env(message); add_message_to_msg(message); if (no_replay) { add_to_msg("(cherry picked from commit "); add_to_msg(sha1_to_hex(commit->object.sha1)); add_to_msg(")\n"); } } if (merge_recursive(sha1_to_hex(base->object.sha1), sha1_to_hex(head), "HEAD", sha1_to_hex(next->object.sha1), oneline) || write_cache_as_tree(head, 0, NULL)) { add_to_msg("\nConflicts:\n\n"); read_cache(); for (i = 0; i < active_nr;) { struct cache_entry *ce = active_cache[i++]; if (ce_stage(ce)) { add_to_msg("\t"); add_to_msg(ce->name); add_to_msg("\n"); while (i < active_nr && !strcmp(ce->name, active_cache[i]->name)) i++; } } if (commit_lock_file(&msg_file) < 0) die ("Error wrapping up %s", defmsg); fprintf(stderr, "Automatic %s failed.%s\n", me, help_msg(commit->object.sha1)); exit(1); } if (commit_lock_file(&msg_file) < 0) die ("Error wrapping up %s", defmsg); fprintf(stderr, "Finished one %s.\n", me); /* * * If we are cherry-pick, and if the merge did not result in * hand-editing, we will hit this commit and inherit the original * author date and name. * If we are revert, or if our cherry-pick results in a hand merge, * we had better say that the current user is responsible for that. */ if (!no_commit) { /* 6 is max possible length of our args array including NULL */ const char *args[6]; int i = 0; args[i++] = "commit"; args[i++] = "-n"; if (signoff) args[i++] = "-s"; if (!edit) { args[i++] = "-F"; args[i++] = defmsg; } args[i] = NULL; return execv_git_cmd(args); } free(reencoded_message); return 0; }