summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/gtkui/gtkui.c1
-rw-r--r--plugins/gtkui/gtkui_api.h9
-rw-r--r--plugins/gtkui/widgets.c104
-rw-r--r--plugins/gtkui/widgets.h6
-rw-r--r--plugins/libparser/parser.c24
-rw-r--r--plugins/libparser/parser.h6
6 files changed, 91 insertions, 59 deletions
diff --git a/plugins/gtkui/gtkui.c b/plugins/gtkui/gtkui.c
index 328181d0..9bdd930e 100644
--- a/plugins/gtkui/gtkui.c
+++ b/plugins/gtkui/gtkui.c
@@ -1755,7 +1755,6 @@ static ddb_gtkui_t plugin = {
.w_is_registered = w_is_registered,
.w_get_rootwidget = w_get_rootwidget,
.w_create = w_create,
- .w_set_name = w_set_name,
.w_destroy = w_destroy,
.w_append = w_append,
.w_replace = w_replace,
diff --git a/plugins/gtkui/gtkui_api.h b/plugins/gtkui/gtkui_api.h
index b6ac7f58..9dff7745 100644
--- a/plugins/gtkui/gtkui_api.h
+++ b/plugins/gtkui/gtkui_api.h
@@ -36,9 +36,16 @@
// this flag tells that the widget should be added to h/vboxes with expand=FALSE
#define DDB_GTKUI_WIDGET_FLAG_NON_EXPANDABLE 0x00000001
+// widget config string must look like that:
+// type key1=value1 key2=value2... { child widgets }
+//
+// the default widget loader will ignore all key-value pairs,
+// so it's your custom loader's responsibility to handle them
+// you can find out how to write custom loaders in gtkui sources,
+// look e.g. for the "w_splitter_load"
+
typedef struct ddb_gtkui_widget_s {
const char *type;
- char *name;
struct ddb_gtkui_widget_s *parent;
diff --git a/plugins/gtkui/widgets.c b/plugins/gtkui/widgets.c
index 364c5c58..d5056545 100644
--- a/plugins/gtkui/widgets.c
+++ b/plugins/gtkui/widgets.c
@@ -255,16 +255,6 @@ w_create_from_string (const char *s, ddb_gtkui_widget_t **parent) {
w_remove (w, w->children);
}
- // name
- s = gettoken (s, t);
- if (!s) {
- w_destroy (w);
- return NULL;
- }
- if (t[0]) {
- w_set_name (w, t);
- }
-
// load widget params
if (w->load) {
s = w->load (w, type, s);
@@ -273,18 +263,34 @@ w_create_from_string (const char *s, ddb_gtkui_widget_t **parent) {
return NULL;
}
}
-
- // {
- s = gettoken (s, t);
- if (!s) {
- w_destroy (w);
- return NULL;
- }
- if (strcmp (t, "{")) {
- w_destroy (w);
- return NULL;
+ else {
+ // skip all params (if any)
+ for (;;) {
+ s = gettoken_ext (s, t, "={}();");
+ if (!s) {
+ w_destroy (w);
+ return NULL;
+ }
+ if (!strcmp (t, "{")) {
+ break;
+ }
+ // match '='
+ char eq[MAX_TOKEN];
+ char val[MAX_TOKEN];
+ s = gettoken_ext (s, eq, "={}();");
+ if (!s || strcmp (eq, "=")) {
+ w_destroy (w);
+ return NULL;
+ }
+ s = gettoken_ext (s, eq, "={}();");
+ if (!s) {
+ w_destroy (w);
+ return NULL;
+ }
+ }
}
+ // we don't need to match '{' here, it's already done above
const char *back = s;
s = gettoken (s, t);
if (!s) {
@@ -358,9 +364,6 @@ static char paste_buffer[1000];
void
save_widget_to_string (char *str, int sz, ddb_gtkui_widget_t *w) {
strcat (str, w->type);
- strcat (str, " \"");
- strcat (str, w->name ? w->name : "");
- strcat (str, "\"");
if (w->save) {
w->save (w, str, sz);
}
@@ -650,17 +653,6 @@ w_create (const char *type) {
}
void
-w_set_name (ddb_gtkui_widget_t *w, const char *name) {
- if (w->name) {
- free (w->name);
- w->name = NULL;
- }
- if (name) {
- w->name = strdup (name);
- }
-}
-
-void
w_destroy (ddb_gtkui_widget_t *w) {
if (w->destroy) {
w->destroy (w);
@@ -668,9 +660,6 @@ w_destroy (ddb_gtkui_widget_t *w) {
if (w->widget) {
gtk_widget_destroy (w->widget);
}
- if (w->name) {
- free (w->name);
- }
free (w);
}
@@ -759,25 +748,44 @@ w_splitter_load (struct ddb_gtkui_widget_s *w, const char *type, const char *s)
if (strcmp (type, "vsplitter") && strcmp (type, "hsplitter")) {
return NULL;
}
+ printf ("loading splitter\n");
char t[MAX_TOKEN];
- s = gettoken (s, t);
- if (!s) {
- return NULL;
- }
- ((w_splitter_t *)w)->position = atoi (t);
- s = gettoken (s, t);
- if (!s) {
- return NULL;
+ for (;;) {
+ s = gettoken_ext (s, t, "={}();");
+ if (!s) {
+ return NULL;
+ }
+
+ if (!strcmp (t, "{")) {
+ break;
+ }
+
+ char val[MAX_TOKEN];
+ s = gettoken_ext (s, val, "={}();");
+ if (!s || strcmp (val, "=")) {
+ return NULL;
+ }
+ s = gettoken_ext (s, val, "={}();");
+ if (!s) {
+ return NULL;
+ }
+
+ if (!strcmp (t, "pos")) {
+ ((w_splitter_t *)w)->position = atoi (val);
+ }
+ else if (!strcmp (t, "locked")) {
+ ((w_splitter_t *)w)->locked = atoi (val);
+ }
}
- ((w_splitter_t *)w)->locked = atoi (t);
+
return s;
}
void
w_splitter_save (struct ddb_gtkui_widget_s *w, char *s, int sz) {
int pos = ((w_splitter_t *)w)->box ? ((w_splitter_t *)w)->position : gtk_paned_get_position (GTK_PANED(w->widget));
- char spos[10];
- snprintf (spos, sizeof (spos), " %d %d", pos, ((w_splitter_t *)w)->locked);
+ char spos[100];
+ snprintf (spos, sizeof (spos), " pos=%d locked=%d", pos, ((w_splitter_t *)w)->locked);
strncat (s, spos, sz);
}
diff --git a/plugins/gtkui/widgets.h b/plugins/gtkui/widgets.h
index ac26d071..ee8d7b05 100644
--- a/plugins/gtkui/widgets.h
+++ b/plugins/gtkui/widgets.h
@@ -21,9 +21,6 @@
#include "gtkui_api.h"
-// widget config string must look like that:
-// type key1=value1 key2=value2... { child widgets }
-
void
w_init (void);
@@ -54,9 +51,6 @@ w_is_registered (const char *type);
ddb_gtkui_widget_t *
w_create (const char *type);
-void
-w_set_name (ddb_gtkui_widget_t *w, const char *name);
-
const char *
w_create_from_string (const char *s, ddb_gtkui_widget_t **parent);
diff --git a/plugins/libparser/parser.c b/plugins/libparser/parser.c
index c49eeb72..54e94d55 100644
--- a/plugins/libparser/parser.c
+++ b/plugins/libparser/parser.c
@@ -46,12 +46,11 @@ skipws (const char *p) {
}
const char *
-gettoken (const char *p, char *tok) {
+gettoken_ext (const char *p, char *tok, const char *specialchars) {
const char *c;
assert (p);
assert (tok);
int n = MAX_TOKEN-1;
- char specialchars[] = "{}();";
if (!(p = skipws (p))) {
return NULL;
}
@@ -86,6 +85,26 @@ gettoken (const char *p, char *tok) {
}
const char *
+gettoken (const char *p, char *tok) {
+ char specialchars[] = "{}();";
+ return gettoken_ext (p, tok, specialchars);
+}
+
+const char *
+gettoken_keyvalue (const char *p, char *key, char *val) {
+ char specialchars[] = "{}();=";
+ p = gettoken_ext (p, key, specialchars);
+ if (!p) {
+ return NULL;
+ }
+ p = gettoken_ext (p, val, specialchars);
+ if (!p || *val != '=') {
+ return NULL;
+ }
+ return gettoken_ext (p, val, specialchars);
+}
+
+const char *
gettoken_warn_eof (const char *p, char *tok) {
p = gettoken (p, tok);
if (!p) {
@@ -104,4 +123,3 @@ gettoken_err_eof (const char *p, char *tok) {
return p;
}
-
diff --git a/plugins/libparser/parser.h b/plugins/libparser/parser.h
index b0f95169..5c7e5d83 100644
--- a/plugins/libparser/parser.h
+++ b/plugins/libparser/parser.h
@@ -31,6 +31,12 @@ const char *
gettoken (const char *p, char *tok);
const char *
+gettoken_ext (const char *p, char *tok, const char *specialchars);
+
+const char *
+gettoken_keyvalue (const char *p, char *key, char *val);
+
+const char *
gettoken_warn_eof (const char *p, char *tok);
const char *