File: extlconv.c

package info (click to toggle)
notion 4.0.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,656 kB
  • sloc: ansic: 47,365; sh: 2,093; makefile: 594; perl: 270
file content (134 lines) | stat: -rw-r--r-- 2,236 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*
 * ion/ioncore/extlconv.c
 *
 * Copyright (c) Tuomo Valkonen 1999-2007.
 *
 * See the included file LICENSE for details.
 */

#include <string.h>

#include <libextl/extl.h>
#include "common.h"
#include "extlconv.h"


/*{{{ Object list */


bool extl_iter_objlist_(ExtlFn fn, ObjIterator *iter, void *st)
{
    Obj *obj;

    while(1){
        obj=iter(st);
        if(obj==NULL)
            break;
        if(!extl_iter_obj(fn, obj))
            return FALSE;
    }

    return TRUE;
}


bool extl_iter_objlist(ExtlFn fn, ObjList *list)
{
    ObjListIterTmp tmp;

    objlist_iter_init(&tmp, list);

    return extl_iter_objlist_(fn, (ObjIterator*)objlist_iter, &tmp);
}


bool extl_iter_obj(ExtlFn fn, Obj *obj)
{
    bool ret1, ret2=FALSE;

    extl_protect(NULL);

    ret1=extl_call(fn, "o", "b", obj, &ret2);

    extl_unprotect(NULL);

    return (ret1 && ret2);
}


/*}}}*/


/*{{{ Booleans */


bool extl_table_is_bool_set(ExtlTab tab, const char *entry)
{
    bool b;

    if(extl_table_gets_b(tab, entry, &b))
        return b;
    return FALSE;
}


/*}}}*/


/*{{{ Rectangles */


bool extl_table_to_rectangle(ExtlTab tab, WRectangle *rectret)
{
    if(!extl_table_gets_i(tab, "x", &(rectret->x)) ||
       !extl_table_gets_i(tab, "y", &(rectret->y)) ||
       !extl_table_gets_i(tab, "w", &(rectret->w)) ||
       !extl_table_gets_i(tab, "h", &(rectret->h)))
       return FALSE;

    return TRUE;
}


ExtlTab extl_table_from_rectangle(const WRectangle *rect)
{
    ExtlTab tab=extl_create_table();

    extl_table_sets_i(tab, "x", rect->x);
    extl_table_sets_i(tab, "y", rect->y);
    extl_table_sets_i(tab, "w", rect->w);
    extl_table_sets_i(tab, "h", rect->h);

    return tab;
}


void extl_table_sets_rectangle(ExtlTab tab, const char *nam,
                               const WRectangle *rect)
{
    ExtlTab g=extl_table_from_rectangle(rect);
    extl_table_sets_t(tab, nam, g);
    extl_unref_table(g);
}


bool extl_table_gets_rectangle(ExtlTab tab, const char *nam,
                               WRectangle *rect)
{
    ExtlTab g;
    bool ok;

    if(!extl_table_gets_t(tab, nam, &g))
        return FALSE;

    ok=extl_table_to_rectangle(g, rect);

    extl_unref_table(g);

    return ok;
}


/*}}}*/