unoidl2

Unnamed repository; edit this file to name it for gitweb.
git clone https://logand.com/git/unoidl2.git/
Log | Files | Refs

commit 0d0e2f75a27b2803e29821a5feb1056a8a1da406
parent 2ff5770c9538a9c02cabb9260f3a3e302ebfb725
Author: Tomas Hlavaty <tom@logand.com>
Date:   Tue, 17 Jan 2012 00:47:06 +0100

find accepts key argument

Diffstat:
Munoidl2.c | 10++++++----
Munoidl2.h | 6+++++-
Munoidl2java.c | 2+-
3 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/unoidl2.c b/unoidl2.c @@ -177,10 +177,10 @@ Any mapc(void *env, Any (*fn)(void *env, Any e), Any x) { return z; } -Any find(Any e, Any l, int (*eq)(Any e, Any x)) { - for(; NIL != l; l = cdr(l)) { - Any a = car(l); - if(eq(e, car(a))) return a; +Any find(Any elt, Any lst, Fn2 cmp, Fn1 key) { + for(; NIL != lst; lst = cdr(lst)) { + Any x = car(lst); + if(NIL != cmp(elt, key(x))) return x; } return NIL; } @@ -188,3 +188,5 @@ Any find(Any e, Any l, int (*eq)(Any e, Any x)) { Any reverse(Any x, Any a) { return NIL == x ? a : reverse(cdr(x), cons(car(x), a)); } + +Any id(Any x) {return x;} diff --git a/unoidl2.h b/unoidl2.h @@ -24,6 +24,9 @@ typedef enum yytokentype Kind; extern const Any NIL; extern const Any T; +typedef Any (*Fn1)(Any a); +typedef Any (*Fn2)(Any a, Any b); + Any cons(Any car, Any cdr); Any mk(Kind kind, char *token); Any mkinum(int n); @@ -58,5 +61,6 @@ Any equal(Any x, Any y); Any print(Any x); int some(void *env, int (*fn)(void *env, Any e), Any x); Any mapc(void *env, Any (*fn)(void *env, Any e), Any x); -Any find(Any e, Any l, int (*eq)(Any e, Any x)); +Any find(Any elt, Any lst, Fn2 cmp, Fn1 key); Any reverse(Any x, Any a); +Any id(Any x); diff --git a/unoidl2java.c b/unoidl2java.c @@ -514,7 +514,7 @@ static void pr_typedef(Any x) { typedefs = cons(cons(cons(cadr(x), module), cadddr(x)), typedefs); } -static Any resolve_typedef(Any x) {return find(x, typedefs, equal);} +static Any resolve_typedef(Any x) {return find(x, typedefs, equal, car);} static void pr_relative(Any x) { if(!use_XInterface && equal_(com_sun_star_uno_XInterface, cdr(x)))