Consistency fixes
[notion.git] / ioncore / extlconv.c
blob065efda1a3f4630ce4652dd80953d2f0f667e992
1 /*
2 * ion/ioncore/extlconv.c
4 * Copyright (c) Tuomo Valkonen 1999-2009.
6 * See the included file LICENSE for details.
7 */
9 #include <string.h>
11 #include <libextl/extl.h>
12 #include "common.h"
13 #include "extlconv.h"
16 /*{{{ Object list */
19 bool extl_iter_objlist_(ExtlFn fn, ObjIterator *iter, void *st)
21 Obj *obj;
23 while(1){
24 obj=iter(st);
25 if(obj==NULL)
26 break;
27 if(!extl_iter_obj(fn, obj))
28 return FALSE;
31 return TRUE;
35 bool extl_iter_objlist(ExtlFn fn, ObjList *list)
37 ObjListIterTmp tmp;
39 objlist_iter_init(&tmp, list);
41 return extl_iter_objlist_(fn, (ObjIterator*)objlist_iter, &tmp);
45 bool extl_iter_obj(ExtlFn fn, Obj *obj)
47 bool ret1, ret2=FALSE;
49 extl_protect(NULL);
51 ret1=extl_call(fn, "o", "b", obj, &ret2);
53 extl_unprotect(NULL);
55 return (ret1 && ret2);
59 /*}}}*/
62 /*{{{ Booleans */
65 bool extl_table_is_bool_set(ExtlTab tab, const char *entry)
67 bool b;
69 if(extl_table_gets_b(tab, entry, &b))
70 return b;
71 return FALSE;
75 /*}}}*/
78 /*{{{ Rectangles */
81 bool extl_table_to_rectangle(ExtlTab tab, WRectangle *rectret)
83 if(!extl_table_gets_i(tab, "x", &(rectret->x)) ||
84 !extl_table_gets_i(tab, "y", &(rectret->y)) ||
85 !extl_table_gets_i(tab, "w", &(rectret->w)) ||
86 !extl_table_gets_i(tab, "h", &(rectret->h)))
87 return FALSE;
89 return TRUE;
93 ExtlTab extl_table_from_rectangle(const WRectangle *rect)
95 ExtlTab tab=extl_create_table();
97 extl_table_sets_i(tab, "x", rect->x);
98 extl_table_sets_i(tab, "y", rect->y);
99 extl_table_sets_i(tab, "w", rect->w);
100 extl_table_sets_i(tab, "h", rect->h);
102 return tab;
106 void extl_table_sets_rectangle(ExtlTab tab, const char *nam,
107 const WRectangle *rect)
109 ExtlTab g=extl_table_from_rectangle(rect);
110 extl_table_sets_t(tab, nam, g);
111 extl_unref_table(g);
115 bool extl_table_gets_rectangle(ExtlTab tab, const char *nam,
116 WRectangle *rect)
118 ExtlTab g;
119 bool ok;
121 if(!extl_table_gets_t(tab, nam, &g))
122 return FALSE;
124 ok=extl_table_to_rectangle(g, rect);
126 extl_unref_table(g);
128 return ok;
132 /*}}}*/
135 /*{{{ Size policy */
138 bool extl_table_gets_sizepolicy(ExtlTab tab, const char *nam,
139 WSizePolicy *szplcy)
141 char *tmpstr;
142 bool ret=FALSE;
144 if(extl_table_gets_s(tab, nam, &tmpstr)){
145 ret=string2sizepolicy(tmpstr, szplcy);
146 free(tmpstr);
149 return ret;
153 /*}}}*/