diff options
author | Elliott Hughes <enh@google.com> | 2021-06-18 07:54:51 -0700 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2021-06-18 07:54:51 -0700 |
commit | af7700a67ed0c97d579d2c30a1623b7c6b432a9d (patch) | |
tree | ec290a75c8f4e46ebe03fb87accccb1789761689 | |
parent | 792621ac6fd9dde71aab6c38f899974ca4a4affa (diff) | |
parent | 29e7ed94a1fe2836d38960b9b3ab3e3b7e61c791 (diff) | |
download | toybox-af7700a67ed0c97d579d2c30a1623b7c6b432a9d.tar.gz |
Merge remote-tracking branch 'toybox/master' into HEAD
Change-Id: I718a1a14eaae74ee10a97d67b0335426cf535c29
-rw-r--r-- | lib/args.c | 3 | ||||
-rw-r--r-- | main.c | 34 | ||||
-rw-r--r-- | toys.h | 1 | ||||
-rw-r--r-- | toys/pending/vi.c | 19 |
4 files changed, 33 insertions, 24 deletions
@@ -426,6 +426,9 @@ void get_optflags(void) continue; } + if (CFG_TOYBOX_HELP_DASHDASH && !(toys.which->flags&TOYFLAG_NOHELP)) + check_help(toys.argv+gof.argc); + // do we match a known --longopt? for (lo = gof.longopts; lo; lo = lo->next) { if (!strncmp(gof.arg, lo->str, lo->len)) { @@ -67,6 +67,21 @@ static void unknown(char *name) help_exit("Unknown command %s", name); } +void check_help(char **arg) +{ + if (!strcmp(*arg, "--help")) { + if (CFG_TOYBOX && toys.which == toy_list && arg[1]) + if (!(toys.which = toy_find(arg[1]))) unknown(arg[1]); + show_help(stdout, 1); + xexit(); + } + + if (!strcmp(*arg, "--version")) { + xprintf("toybox %s\n", toybox_version); + xexit(); + } +} + // Setup toybox global state for this command. void toy_singleinit(struct toy_list *which, char *argv[]) { @@ -74,23 +89,12 @@ void toy_singleinit(struct toy_list *which, char *argv[]) toys.argv = argv; toys.toycount = ARRAY_LEN(toy_list); - // Parse --help and --version for (almost) all commands - if (CFG_TOYBOX_HELP_DASHDASH && !(which->flags & TOYFLAG_NOHELP) && argv[1]) { - if (!strcmp(argv[1], "--help")) { - if (CFG_TOYBOX && toys.which == toy_list && toys.argv[2]) - if (!(toys.which = toy_find(toys.argv[2]))) unknown(toys.argv[2]); - show_help(stdout, 1); - xexit(); - } - - if (!strcmp(argv[1], "--version")) { - xprintf("toybox %s\n", toybox_version); - xexit(); - } - } - if (NEED_OPTIONS && which->options) get_optflags(); else { + // Parse --help and --version for (almost) all commands + if (CFG_TOYBOX_HELP_DASHDASH && !(which->flags & TOYFLAG_NOHELP) && argv[1]) + check_help(argv+1); + toys.optargs = argv+1; for (toys.optc = 0; toys.optargs[toys.optc]; toys.optc++); } @@ -83,6 +83,7 @@ struct toy_list *toy_find(char *name); void toy_init(struct toy_list *which, char *argv[]); +void check_help(char **arg); void toy_singleinit(struct toy_list *which, char *argv[]); void toy_exec(char *argv[]); diff --git a/toys/pending/vi.c b/toys/pending/vi.c index 87c49d13..fc46f355 100644 --- a/toys/pending/vi.c +++ b/toys/pending/vi.c @@ -518,13 +518,16 @@ static int linelist_load(char *filename) if (filename) { int fd = open(filename, O_RDONLY); - size_t size; - char *data; + long long size; + + if (fd == -1 || !(size = fdlength(fd))) { + insert_str("", 0, 0, 0, STACK); + TT.filesize = 0; - if (fd == -1) return 0; - data = xmmap(0, size = fdlength(fd), PROT_READ, MAP_SHARED, fd, 0); + return 0; + } + insert_str(xmmap(0, size, PROT_READ, MAP_SHARED, fd, 0), 0, size,size,MMAP); xclose(fd); - insert_str(data, 0, size, size, MMAP); TT.filesize = text_filesize(); } @@ -556,7 +559,6 @@ static void write_file(char *filename) else chmod(toybuf, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH); xrename(toybuf, filename); linelist_load(filename); - } //jump into valid offset index @@ -1482,7 +1484,7 @@ static void draw_page() // TODO: the row,col display doesn't show the cursor column // TODO: real vi shows the percentage by lines, not bytes sprintf(toybuf, "%zu/%zuC %zu%% %d,%d", TT.cursor, TT.filesize, - (100*TT.cursor)/TT.filesize, TT.cur_row+1, TT.cur_col+1); + (100*TT.cursor)/(TT.filesize ? : 1), TT.cur_row+1, TT.cur_col+1); if (TT.cur_col != cx_scr) sprintf(toybuf+strlen(toybuf),"-%d", cx_scr+1); } tty_jump(TT.screen_width-strlen(toybuf), TT.screen_height); @@ -1508,12 +1510,11 @@ void vi_main(void) TT.il->alloc = 80, TT.yank.alloc = 128; linelist_load(0); - TT.screen = TT.cursor = 0; TT.vi_mov_flag = 0x20000000; TT.vi_mode = 1, TT.tabstop = 8; - TT.screen_width = 80, TT.screen_height = 24; + TT.screen_width = 80, TT.screen_height = 24; terminal_size(&TT.screen_width, &TT.screen_height); TT.screen_height -= 1; |