diff options
| author | Quentin Carbonneaux | 2014-09-12 14:29:16 -0400 |
|---|---|---|
| committer | Quentin Carbonneaux | 2014-09-12 14:29:16 -0400 |
| commit | 60bbcb9b1155cb0ccc9f003661f369e139e5840d (patch) | |
| tree | 90455522c7fde000ec0a386ea8a02710a3b956c5 | |
| parent | 257b85904fca63c5bdfe2e3d94e043b7cda5cbea (diff) | |
parse line addresses in ex_get
| -rw-r--r-- | exec.c | 42 | ||||
| -rw-r--r-- | exec.h | 2 | ||||
| -rw-r--r-- | main.c | 6 |
3 files changed, 24 insertions, 26 deletions
@@ -90,22 +90,32 @@ ex_look(W *w, Rune *s, unsigned n) } } -/* ex_get - Load the buffer [eb] from the file [file]. See ex_put - * for more information. +/* ex_get - Load the file [file] in the window [w]. See ex_put + * for more information on the path argument. */ int -ex_get(EBuf *eb, char *file) +ex_get(W *w, char *file) { int fd; struct stat st; - char *file1; + char *file1, *p; + EBuf *eb; + long ln; + ln = 1; + eb = w->eb; if (!file) file = eb->path; if (!file) { errstr = "no file to read from"; return 1; } + if ((p = strchr(file, ':'))) { + *p = 0; + ln = strtol(p+1, 0, 10); + if (ln > INT_MAX || ln < 0) + ln = 0; + } if (eb->path && strcmp(eb->path, file) != 0) if (eb->frev != eb_revision(eb)) { errstr = "file not written"; @@ -127,6 +137,7 @@ ex_get(EBuf *eb, char *file) eb->path = file1; eb->ftime = st.st_mtime; eb->frev = eb_revision(eb); + w->cu = buf_setlc(&eb->b, ln-1, 0); return 0; } @@ -231,8 +242,7 @@ lookup(Buf *b, unsigned p0, unsigned *p1) static char * buftobytes(Buf *b, unsigned p0, unsigned p1, unsigned *sz) { - char *s; - unsigned char *t; + unsigned char *s, *t; unsigned n, p; n = 0; @@ -242,10 +252,10 @@ buftobytes(Buf *b, unsigned p0, unsigned p1, unsigned *sz) *sz = n; s = malloc(n+1); assert(s); - for (t=(unsigned char *)s, p=p0; p<p1; p++) + for (t=s, p=p0; p<p1; p++) t += utf8_encode_rune(buf_get(b, p), t, 8); /* XXX 8 */ *t = 0; - return s; + return (char *)s; } @@ -254,30 +264,20 @@ buftobytes(Buf *b, unsigned p0, unsigned p1, unsigned *sz) static int get(W *w, EBuf *eb, unsigned p0) { - char *f, *p; + char *f; unsigned p1; int e; - long ln; f = 0; - ln = 1; p1 = 1 + skipb(&eb->b, buf_eol(&eb->b, p0) - 1, -1); - if (p0 < p1) { + if (p0 < p1) f = buftobytes(&eb->b, p0, p1, 0); - if ((p = strchr(f, ':'))) { - *p = 0; - ln = strtol(p+1, 0, 10); - if (ln > INT_MAX || ln < 0) - ln = 0; - } - } - e = ex_get(w->eb, f); + e = ex_get(w, f); free(f); if (e) { err(eb, p0, errstr); return 0; } - w->cu = buf_setlc(&w->eb->b, ln-1, 0); return 1; } @@ -1,4 +1,4 @@ int ex_run(W *, unsigned); int ex_look(W *, Rune *, unsigned); int ex_put(EBuf *, char *); -int ex_get(EBuf *, char *); +int ex_get(W *, char *); @@ -148,16 +148,14 @@ int main(int ac, char *av[]) { int guifd; - EBuf *eb; g = &gui_x11; guifd = g->init(); ev_register((Evnt){guifd, ERead, gev, 0}); win_init(g); - eb = eb_new(); + curwin = win_new(eb_new()); if (ac > 1) - ex_get(eb, av[1]); - curwin = win_new(eb); + ex_get(curwin, av[1]); gev(0, 0, 0); ev_loop(); } |
