summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorQuentin Carbonneaux2014-07-18 10:31:37 -0400
committerQuentin Carbonneaux2014-07-20 12:52:52 -0400
commit32a5400c7513914b0758670859ef29e649bb8f46 (patch)
treec405ded9425636679f8d2b386c2ac66990eddbfe
parent542e9ad357f69cb2af873f7c7ccb1d10270fa0da (diff)
skeleton for command runs
-rw-r--r--evnt.c12
-rw-r--r--evnt.h2
-rw-r--r--exec.c41
-rw-r--r--main.c3
4 files changed, 50 insertions, 8 deletions
diff --git a/evnt.c b/evnt.c
index 839532f..fa56e10 100644
--- a/evnt.c
+++ b/evnt.c
@@ -1,5 +1,6 @@
#include <assert.h>
#include <stdlib.h>
+#include <string.h>
#include <errno.h>
#include <sys/select.h>
@@ -47,14 +48,19 @@ ev_loop()
continue;
die("select error");
}
- for (e=elist; e-elist < ne; e++) {
+ for (e=elist; e-elist < ne;) {
flags = 0;
if (FD_ISSET(e->fd, &rfds))
flags |= ERead;
if (FD_ISSET(e->fd, &wfds))
flags |= EWrite;
- if (flags)
- e->f(flags, e->p);
+ if (flags == 0)
+ continue;
+ if (e->f(flags, e->p)) {
+ ne--;
+ memmove(e, e+1, (ne - (e-elist)) * sizeof(E));
+ } else
+ e++;
}
}
}
diff --git a/evnt.h b/evnt.h
index 20a797a..e224fd8 100644
--- a/evnt.h
+++ b/evnt.h
@@ -11,7 +11,7 @@ enum {
struct e {
int fd;
int flags;
- void (*f)(int, void *);
+ int (*f)(int, void *);
void *p;
};
diff --git a/exec.c b/exec.c
index 11c513d..94a72f5 100644
--- a/exec.c
+++ b/exec.c
@@ -16,13 +16,15 @@ struct ecmd {
};
static ECmd *lookup(Buf *, unsigned, unsigned *);
+static unsigned skipb(Buf *, unsigned, int);
static int get(W *, EBuf *, unsigned);
static int look(W *, EBuf *, unsigned);
+static int run(W *, EBuf *, unsigned);
ECmd etab[] = {
{ "Get", get },
{ "Look", look },
- { 0, 0 },
+ { 0, run },
};
@@ -42,7 +44,7 @@ ex_run(unsigned p0)
if (win_text(curwin) != curwin)
curwin = win_tag_toggle(curwin);
- return e != 0;
+ return 0;
}
/* ex_look - Look for a string [s] in window [w] and jump
@@ -104,7 +106,9 @@ lookup(Buf *b, unsigned p0, unsigned *p1)
(*p1)++;
} while (risascii(r) && r == (Rune)*s++);
}
- return 0;
+
+ *p1 = p0;
+ return e;
}
@@ -162,3 +166,34 @@ look(W *w, EBuf *eb, unsigned p0)
free(b.r);
return 1;
}
+
+struct Run {
+ EBuf *eb;
+ YBuf *o;
+ unsigned p;
+ unsigned no;
+};
+
+static int
+runev(int flag, void *data)
+{
+ struct Run *r;
+
+ r = data;
+
+ /* commit changes (if any) here */
+ /* set selection and commit changes if text was added */
+ return 0;
+}
+
+static int
+run(W *w, EBuf *eb, unsigned p0)
+{
+ /* clear (and possibly delete) selection, get the "insertion" position and set a mark for it in the edit buffer (Acme does not do this, it just stores an offset)
+
+ what happens when eb is deleted/changed during the command execution?
+ refcount ebs and make eb_free free the data and have eb contain simply the refcount
+ when a dummy eb is detected in the callback, just abort the IO operation
+ */
+ return 0;
+}
diff --git a/main.c b/main.c
index 05fef9c..52ea976 100644
--- a/main.c
+++ b/main.c
@@ -23,7 +23,7 @@ die(char *m)
exit(1);
}
-static void
+static int
gev(int flag, void *unused)
{
GEvent e;
@@ -61,6 +61,7 @@ gev(int flag, void *unused)
win_redraw_frame();
g->sync();
+ return 0;
}
int