This way it is clear how ownership of the string is managed.
Signed-off-by: NeilBrown <neil@brown.name>
DEF_CMD(doc_attr_callback)
{
- struct call_return *cr = container_of(ci->comm, struct call_return , c);
+ struct call_return *cr = container_of(ci->comm, struct call_return, c);
cr->s = ci->str;
return 1;
}
return cr.s;
}
+DEF_CMD(doc_str_callback)
+{
+ struct call_return *cr = container_of(ci->comm, struct call_return, c);
+ cr->s = strdup(ci->str);
+ return 1;
+}
+
+char *doc_getstr(struct pane *from, struct mark *to)
+{
+ struct cmd_info ci = {0};
+ int ret;
+ struct call_return cr;
+
+ ci.key = "doc:get-str";
+ ci.focus = from;
+ ci.mark = to;
+ cr.c = doc_str_callback;
+ cr.s = NULL;
+ ci.comm2 = &cr.c;
+ ret = key_handle_focus(&ci);
+ if (!ret)
+ return NULL;
+ return cr.s;
+}
+
/* the 'docs' document type is special in that there can only ever
* be one instance - the list of documents.
* So there is no 'doctype' registered, just a document which can never
void doc_notify_change(struct doc *d, struct mark *m);
void doc_check_consistent(struct doc *d);
char *doc_attr(struct pane *dp, struct mark *m, bool forward, char *attr);
+char *doc_getstr(struct pane *from, struct mark *to);
void point_to_mark(struct mark *p, struct mark *m);
void mark_to_mark(struct mark *m, struct mark *target);
int mark_same(struct doc *d, struct mark *m1, struct mark *m2);
ci.key = "doc:load-file";
return key_handle_focus(&ci);
}
-static inline char *doc_getstr(struct pane *from, struct mark *to)
-{
- struct cmd_info ci = {0};
- int ret;
-
- ci.key = "doc:get-str";
- ci.focus = from;
- ci.mark = to;
- ret = key_handle_focus(&ci);
- if (!ret)
- return NULL;
- return ci.str;
-}
static inline int doc_set_attr(struct pane *p, struct mark *pt,
char *attr, char *val)
break;
}
ret[l] = 0;
- ci->str = ret;
+ comm_call(ci->comm2, "callback:get-str", ci->focus, 0, NULL, ret, 0);
+ free(ret);
return 1;
}