diff options
| author | WormHeamer | 2026-01-02 04:46:41 -0500 |
|---|---|---|
| committer | WormHeamer | 2026-01-02 04:46:41 -0500 |
| commit | 0031e70953bccc81eadb3d99960094b3d76138b2 (patch) | |
| tree | 266f7b35419736904268dbe607514947f53ef8aa | |
| parent | 0668f74c0ef68fcbb56b67d1e0806db0f955152a (diff) | |
improve argument parsing etc.
| -rw-r--r-- | main.c | 49 |
1 files changed, 31 insertions, 18 deletions
@@ -1090,14 +1090,40 @@ int str_to_u32(Str s, u32 *out) { void make_edit_args(Str *a) { for (u32 i = 0; i < e.bufn; i++) { - if (e.buf[i].type != ED_BUF_FILE) continue; + if (e.buf[i].type != ED_BUF_FILE && e.buf[i].type != ED_BUF_BIN_FILE) continue; if (i > 0) str_catc(a, ' ', &e.scratch); str_cat(a, e.buf[i].path, &e.scratch); str_cat(a, S("@"), &e.scratch); str_cat_u32(a, txt_ofs(e.buf[i].cur), &e.scratch); + if (i == e.bufi) str_cat(a, S(" -b"), &e.scratch); } } +int parse_edit_args(Editor *e, int argc, const char **argv) { + if (argc < 2) return 0; + u32 bufi = ed_buf_close(e, 0); /* close scratch buffer */ + for (int i = 1; i < argc; i++) { + Str s = str_from_cstr(argv[i]); + if (str_eql(s, S("-b"))) { + bufi = e->bufi; + continue; + } + Cut c = str_cut(s, '@'); + e->bufi = ed_buf_open(e, str_to_cstr(c.head, &e->scratch)); + if (c.tail.n > 0) { + EditBuf *eb = &e->buf[e->bufi]; + u32 ofs; + if (str_to_u32(c.tail, &ofs)) { + fprintf(stderr, "invalid byte offset in %s\n", argv[i]); + return 1; + } + eb->cur = txt_at(eb->txt, ofs); + } + } + e->bufi = bufi; + return 0; +} + static void run_file(Str path, int debugp) { path = normalize_path(path); if (is_wed_path(path)) { @@ -1360,6 +1386,8 @@ int select_func(Txt *t, TxtLoc *out) { return 1; } +/* TODO: int select_type(Txt *t, TxtLoc *out); */ + void yank_range(Editor *e, TxtLoc start, TxtLoc end) { if (txt_before(end, start)) { TxtLoc t = start; @@ -1675,23 +1703,8 @@ int main(int argc, const char **argv) { ed_init(&e); e.homedir = str_from_cstr(getenv("HOME")); - if (argc > 1) { - ed_buf_close(&e, 0); /* close scratch buffer */ - for (int i = 1; i < argc; i++) { - Str s = str_from_cstr(argv[i]); - Cut c = str_cut(s, '@'); - e.bufi = ed_buf_open(&e, str_to_cstr(c.head, &e.scratch)); - if (c.tail.n > 1) { - EditBuf *eb = &e.buf[e.bufi]; - u32 ofs; - if (str_to_u32(c.tail, &ofs)) { - fprintf(stderr, "invalid byte offset in %s\n", argv[i]); - return 1; - } - eb->cur = txt_at(eb->txt, ofs); - } - } - } + if (parse_edit_args(&e, argc, argv)) + return 1; vui_init(); vui_curs_vis(1); |
