int main(int argc, char *argv[]) { char *cmd_f = NULL; subcmd_f icmd = NULL; const char *cmd; int res = 0; init_cmds(); if ((cmd = extract_cmd(argc, argv)) == NULL && /* try the rewriter */ (icmd = rewrite_subcmd(argc, argv)) == NULL) { ute_cmd_help(argc, argv); res = 1; } else if (cmd != NULL && (cmd_f = build_cmd(cmd)) != NULL) { /* prepare the execve */ argv[0] = cmd_f; res = execv(cmd_f, argv); } else if (icmd != NULL || (icmd = get_subcmd(cmd)) != NULL) { /* call the internal command */ res = icmd(argc, argv); } else { fprintf(stderr, "ute subcommand `%s' invalid\n\n", cmd); ute_cmd_help(argc, argv); res = 1; } return res; }
void menu_run_command(const char cmd[]) { if(exec_command(cmd, view, CIT_COMMAND) < 0) { ui_sb_err("An error occurred while trying to execute command"); } init_cmds(0, &cmds_conf); }
void execute_cmdline_command(const char cmd[]) { if(exec_command(cmd, curr_view, CIT_COMMAND) < 0) { status_bar_error("An error occurred while trying to execute command"); } init_cmds(0, &cmds_conf); }
void init_commands(void) { if(cmds_conf.inner != NULL) { init_cmds(1, &cmds_conf); return; } /* We get here when init_commands() is called the first time. */ init_cmds(1, &cmds_conf); add_builtin_commands((const cmd_add_t *)&cmds_list, cmds_list_size); /* Initialize modules used by this one. */ init_bracket_notation(); init_variables(); vle_aucmd_set_expand_hook(&pattern_expand_hook); }
void init_menu_mode(void) { int ret_code; ret_code = add_cmds(builtin_cmds, ARRAY_LEN(builtin_cmds), MENU_MODE); assert(ret_code == 0); (void)ret_code; set_def_handler(MENU_MODE, key_handler); init_cmds(0, &cmds_conf); add_builtin_commands((const cmd_add_t *)&commands, ARRAY_LEN(commands)); }
void enter_menu_mode(menu_info *m, FileView *active_view) { if(curr_stats.load_stage < 2) return; assert(m->len > 0 && "Menu cannot be empty."); werase(status_bar); view = active_view; menu = m; vle_mode_set(MENU_MODE, VMT_PRIMARY); curr_stats.need_update = UT_FULL; was_redraw = 0; init_cmds(0, &cmds_conf); }
void menu_init_mode(void) { int ret_code; ret_code = vle_keys_add(builtin_cmds, ARRAY_LEN(builtin_cmds), MENU_MODE); assert(ret_code == 0); (void)ret_code; vle_keys_set_def_handler(MENU_MODE, &key_handler); /* Double initialization can happen in tests. */ if(cmds_conf.inner == NULL) { init_cmds(0, &cmds_conf); add_builtin_commands((const cmd_add_t *)&commands, ARRAY_LEN(commands)); } }
void realmain(int argc, char **argv) { char b[256]; struct stat statbuf; /* vars from oldmain */ buffer *buf = NULL; char path[1024]; int i; setlocale(LC_NUMERIC, "C"); common_init("Egon Animator %s. No Warranty"); sprintf(b, "%s/%ld", siag_basedir, (long)getpid()); mkdir(b, 0700); sprintf(b, "%s/egon.scm", siag_basedir); egonrc = MwStrdup(b); init_interpreters(); siod_interpreter = init_parser(argc, argv); init_python_parser(); init_guile_parser(); init_ruby_parser(); waitforchild(0); init_position(); init_cmds(); buf = new_buffer("noname.egon", "noname.egon"); sprintf(path, "%s/egon/egon.scm", datadir); if (stat(path, &statbuf)) { fprintf(stderr, "Can't find the runtime library (egon.scm).\n"); fprintf(stderr, "Expected it in %s\n", path); fprintf(stderr, "SIAGHOME (if set) is '%s'\n", datadir); fprintf(stderr, "Please read installation instructions.\n"); exit(EXIT_FAILURE); } setvar(cintern("libdir"), strcons(-1, libdir), NIL); setvar(cintern("datadir"), strcons(-1, datadir), NIL); setvar(cintern("docdir"), strcons(-1, docdir), NIL); /* load runtime library */ sprintf(b, "(load \"%s/egon/egon.scm\")", datadir); execute(b); init_windows(buf, &argc, argv); setlocale(LC_NUMERIC, "C"); /* possibly hosed by X */ /* load user customizations, if any */ if (!stat(egonrc, &statbuf)) { sprintf(b, "(load \"%s\")", egonrc); execute(b); } execute("(init-windows)"); execute("(create-menus)"); fileio_init(); for (i = 1; i < argc; i++) { if (argv[i][0] != '-') { strcpy(path, argv[i]); free_buffer(w_list->buf); buf = new_buffer(buffer_name(argv[i]), path); loadmatrix(path, buf, guess_file_format(path)); buf->change = FALSE; w_list->buf = buf; } } pr_scr_flag = TRUE; execute("(popup-editor)"); /* this works, for reasons beyond my comprehension */ execute("(print-version)"); execute("(print-version)"); activate_window(w_list); #ifdef HAVE_LIBTCL Tcl_Main(argc, argv, Tcl_AppInit); #else mainloop(); #endif }
/* Returns negative value in case of error */ static int execute_command(FileView *view, const char command[], int menu) { int id; int result; if(command == NULL) { flist_sel_stash_if_nonempty(view); return 0; } command = skip_to_cmd_name(command); if(command[0] == '"') return 0; if(command[0] == '\0' && !menu) { flist_sel_stash_if_nonempty(view); return 0; } if(!menu) { init_cmds(1, &cmds_conf); cmds_conf.begin = 0; cmds_conf.current = view->list_pos; cmds_conf.end = view->list_rows - 1; } id = get_cmd_id(command); if(!cmd_should_be_processed(id)) { return 0; } if(id == USER_CMD_ID) { char undo_msg[COMMAND_GROUP_INFO_LEN]; snprintf(undo_msg, sizeof(undo_msg), "in %s: %s", replace_home_part(flist_get_dir(view)), command); cmd_group_begin(undo_msg); cmd_group_end(); } keep_view_selection = 0; result = execute_cmd(command); if(result >= 0) return result; switch(result) { case CMDS_ERR_LOOP: status_bar_error("Loop in commands"); break; case CMDS_ERR_NO_MEM: status_bar_error("Unable to allocate enough memory"); break; case CMDS_ERR_TOO_FEW_ARGS: status_bar_error("Too few arguments"); break; case CMDS_ERR_TRAILING_CHARS: status_bar_error("Trailing characters"); break; case CMDS_ERR_INCORRECT_NAME: status_bar_error("Incorrect command name"); break; case CMDS_ERR_NEED_BANG: status_bar_error("Add bang to force"); break; case CMDS_ERR_NO_BUILTIN_REDEFINE: status_bar_error("Can't redefine builtin command"); break; case CMDS_ERR_INVALID_CMD: status_bar_error("Invalid command name"); break; case CMDS_ERR_NO_BANG_ALLOWED: status_bar_error("No ! is allowed"); break; case CMDS_ERR_NO_RANGE_ALLOWED: status_bar_error("No range is allowed"); break; case CMDS_ERR_NO_QMARK_ALLOWED: status_bar_error("No ? is allowed"); break; case CMDS_ERR_INVALID_RANGE: /* message dialog is enough */ break; case CMDS_ERR_NO_SUCH_UDF: status_bar_error("No such user defined command"); break; case CMDS_ERR_UDF_IS_AMBIGUOUS: status_bar_error("Ambiguous use of user-defined command"); break; case CMDS_ERR_ZERO_COUNT: status_bar_error("Zero count"); break; case CMDS_ERR_INVALID_ARG: status_bar_error("Invalid argument"); break; case CMDS_ERR_CUSTOM: /* error message is posted by command handler */ break; default: status_bar_error("Unknown error"); break; } if(!menu && vle_mode_is(NORMAL_MODE)) { flist_sel_stash_if_nonempty(view); } return -1; }