unoidl2

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

commit 2f40e857f3b7f0bc73319f39ed2d67299b9dd06a
parent a969caba020ee439091cce26987d3fc2a39f8963
Author: Tomas Hlavaty <tom@logand.com>
Date:   Wed,  7 Dec 2011 01:28:36 +0100

first sketch of unoidl2xml and unoidl2java added

Diffstat:
MMakefile | 40+++++++++++++++++++++++++++++++++++++---
Mscan.ll | 2+-
Munoidl2.c | 71++++++++++++++++++++++-------------------------------------------------
Munoidl2.h | 10++++++++++
Munoidl2ast.c | 2+-
Aunoidl2java.c | 99+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aunoidl2xml.c | 40++++++++++++++++++++++++++++++++++++++++
7 files changed, 210 insertions(+), 54 deletions(-)

diff --git a/Makefile b/Makefile @@ -1,6 +1,9 @@ -CFLAGS=-std=c99 +LIBO=/opt/libo -ALL=unoidl2ast +CC=diet gcc +CFLAGS=-std=c99 -O2 + +ALL=unoidl2ast unoidl2xml unoidl2java all: $(ALL) @@ -17,6 +20,37 @@ unoidl2ast.o: parse.o unoidl2ast: unoidl2ast.o unoidl2.o scan.o parse.o $(CC) -o$@ $< unoidl2.o scan.o parse.o + strip $@ +unoidl2xml: unoidl2xml.o unoidl2.o scan.o parse.o + $(CC) -o$@ $< unoidl2.o scan.o parse.o + strip $@ +unoidl2java: unoidl2java.o unoidl2.o scan.o parse.o + $(CC) -o$@ $< unoidl2.o scan.o parse.o + strip $@ + +offapi.list: + find $(LIBO)/offapi/ -name '*.idl' >$@ +udkapi.list: + find $(LIBO)/udkapi/ -name '*.idl' >$@ +all.list: offapi.list udkapi.list + cat udkapi.list offapi.list >$@ +all.idl: all.list + sed -e "s@/opt/libo/udkapi/@@g" -e "s@/opt/libo/offapi/@@g" -e "s@.*@#include <&>@g" $< >$@ +allpp.idl: all.idl + cpp -P -I$(LIBO)/offapi -I$(LIBO)/udkapi $< >$@ + +allpp.ast: allpp.idl + cat $< | ./unoidl2ast >$@ +allpp.xml: allpp.idl + cat $< | ./unoidl2xml >$@ +allpp.java: allpp.idl + cat $< | ./unoidl2java >$@ +allpp.py: allpp.idl + cat $< | ./unoidl2py >$@ +allpp.js: allpp.idl + cat $< | ./unoidl2js >$@ +allpp.bas: allpp.idl + cat $< | ./unoidl2bas >$@ clean: - rm -rf $(ALL) scan.c parse.c.h parse.c *.o + rm -rf $(ALL) scan.c parse.c.h parse.c parse.output *.o *.list all.* allpp.* diff --git a/scan.ll b/scan.ll @@ -6,7 +6,7 @@ #include "parse.c.h" #include <stdio.h> -char *strdup(char *); +//char *strdup(char *); int yycolumn = 1; diff --git a/unoidl2.c b/unoidl2.c @@ -39,31 +39,14 @@ Any mk(Kind kind, char *token) { return x; } -int null(Any x) { - return NIL == x; -} - -int consp(Any x) { - return CONS == x->tag; -} - -Any car(Any x) { - return x->u.c.car; -} - -Any cdr(Any x) { - return x->u.c.cdr; -} - -Any cons3(Any a, Any b, Any c) -{ - return cons(a, cons(b, c)); -} - -Any cons4(Any a, Any b, Any c, Any d) -{ - return cons(a, cons(b, cons(c, d))); -} +int null(Any x) {return NIL == x;} +int consp(Any x) {return CONS == x->tag;} +Any car(Any x) {return x->u.c.car;} +Any cdr(Any x) {return x->u.c.cdr;} +Kind kind(Any x) {return x->u.t.kind;} +char *token(Any x) {return x->u.t.token;} +Any cons3(Any a, Any b, Any c) {return cons(a, cons(b, c));} +Any cons4(Any a, Any b, Any c, Any d) {return cons(a, cons(b, cons(c, d)));} Any cons5(Any a, Any b, Any c, Any d, Any e) { @@ -80,30 +63,11 @@ Any cons7(Any a, Any b, Any c, Any d, Any e, Any f, Any g) return cons(a, cons(b, cons(c, cons(d, cons(e, cons(f, g)))))); } -Any list1(Any a) -{ - return cons(a, NIL); -} - -Any list2(Any a, Any b) -{ - return cons3(a, b, NIL); -} - -Any list3(Any a, Any b, Any c) -{ - return cons4(a, b, c, NIL); -} - -Any list4(Any a, Any b, Any c, Any d) -{ - return cons5(a, b, c, d, NIL); -} - -Any list5(Any a, Any b, Any c, Any d, Any e) -{ - return cons6(a, b, c, d, e, NIL); -} +Any list1(Any a) {return cons(a, NIL);} +Any list2(Any a, Any b) {return cons3(a, b, NIL);} +Any list3(Any a, Any b, Any c) {return cons4(a, b, c, NIL);} +Any list4(Any a, Any b, Any c, Any d) {return cons5(a, b, c, d, NIL);} +Any list5(Any a, Any b, Any c, Any d, Any e) {return cons6(a, b, c, d, e, NIL);} Any list6(Any a, Any b, Any c, Any d, Any e, Any f) { @@ -120,6 +84,15 @@ Any nconc2(Any a, Any b) return a; } +Any cadr(Any x) {return car(cdr(x));} +Any cddr(Any x) {return cdr(cdr(x));} +Any caddr(Any x) {return car(cdr(cdr(x)));} +Any cdddr(Any x) {return cdr(cdr(cdr(x)));} +Any cadddr(Any x) {return car(cdr(cdr(cdr(x))));} +Any cddddr(Any x) {return cdr(cdr(cdr(cdr(x))));} +Any caddddr(Any x) {return car(cdr(cdr(cdr(cdr(x)))));} +Any cdddddr(Any x) {return cdr(cdr(cdr(cdr(cdr(x)))));} + void print(Any x) { if(null(x)) printf("NIL"); diff --git a/unoidl2.h b/unoidl2.h @@ -10,6 +10,8 @@ int null(Any x); int consp(Any x); Any car(Any x); Any cdr(Any x); +Kind kind(Any x); +char *token(Any x); Any cons3(Any a, Any b, Any c); Any cons4(Any a, Any b, Any c, Any d); Any cons5(Any a, Any b, Any c, Any d, Any e); @@ -22,4 +24,12 @@ Any list4(Any a, Any b, Any c, Any d); Any list5(Any a, Any b, Any c, Any d, Any e); Any list6(Any a, Any b, Any c, Any d, Any e, Any f); Any nconc2(Any a, Any b); +Any cadr(Any x); +Any cddr(Any x); +Any caddr(Any x); +Any cdddr(Any x); +Any cadddr(Any x); +Any cddddr(Any x); +Any caddddr(Any x); +Any cdddddr(Any x); void print(Any x); diff --git a/unoidl2ast.c b/unoidl2ast.c @@ -18,6 +18,6 @@ int main() { yyparse(); pr_all(ast); //print(ast); - printf("\n"); + //printf("\n"); return 0; } diff --git a/unoidl2java.c b/unoidl2java.c @@ -0,0 +1,99 @@ +#include "unoidl2.h" +#include "parse.c.h" + +#include <stdio.h> + +extern int yyparse(); + +extern const Any ast; +extern const Any NIL; + +static inline void pr(char *x) {printf("%s", x);} +static inline void pl(char *x) {printf("%s\n", x);} + +static void pr_exp(Any x) { // TODO + print(x); +} + +static void pr_module() // TODO +{ + char *name = "PACKAGE"; + pl("package "); pr(name); pl(";"); +} + +static void pr_enum(Any x) +{ + print(x); + char *name = token(cadr(x)); + Any published = caddr(x); + Any values = cdddr(x); + Any v0 = car(values); + Any v0k = consp(v0) ? car(v0) : v0; + pr_module(); + pl(""); + pr("public final class "); pr(name); pl(" extends com.sun.star.uno.Enum {"); + pl(""); + pr(" private "); pr(name); pl("(int value) {"); + pl(" super(value);"); + pl(" }"); + pl(""); + pr(" public static "); pr(name); pl(" getDefault() {"); + pr(" return "); print(v0k); pl(";"); + pl(" }"); + pl(""); + for(Any y = values; !null(y); y = cdr(y)) { + Any value = car(y); + char *k = token(consp(value) ? car(value) : value); + Any v = consp(value) ? cdr(value) : mk(INT, "?"); // TODO + pr(" public static final "); pr(name); pr(" "); pr(k); pr(" = new "); pr(name); pr("("); pr_exp(v); pl(");"); + } + pl(""); + pr(" public static "); pr(name); pl(" fromInt(int value) {"); + pl(" switch(value) {"); + for(Any y = values; !null(y); y = cdr(y)) { + Any value = car(y); + char *k = token(consp(value) ? car(value) : value); + Any v = consp(value) ? cdr(value) : mk(INT, "?"); + pr(" case "); pr_exp(v); pr(": return "); pr(k); pl(";"); + } + pl(" }"); + pr(" return "); print(v0k); pl(";"); + pl(" }"); + pl("}"); +} + +Any module; + +static void pp(Any x) { + if(x) { + if(consp(x)) { + Any a = car(x); + switch(kind(a)) { + case MODULE: + //module = cons(cadr(x), module); + print(module); + pp(caddr(x)); + break; + case ENUM: + pr_enum(x); + break; + /* default: */ + /* print(x); */ + } + } else + print(x); + } else + printf("NIL"); +} + +static void pp_list(Any x) { + for(; !null(x); x = cdr(x)) + pp(car(x)); +} + +int main() { + yyparse(); + module = NIL; + pp_list(ast); + return 0; +} diff --git a/unoidl2xml.c b/unoidl2xml.c @@ -0,0 +1,40 @@ +#include "unoidl2.h" +#include "parse.c.h" + +#include <stdio.h> + +extern int yyparse(); + +extern Any ast; + +void pr(Any x) { + if(x) { + if(consp(x)) { + printf("<"); + print(car(x)); + printf(">"); + Any d; + for(d = cdr(x); d; d = cdr(d)) { + printf(" "); + if(consp(d)) + pr(car(d)); + else { + printf(". "); + pr(d); + break; + } + } + printf("</"); + print(car(x)); + printf(">\n"); + } else + print(x); + } else + printf("NIL"); +} + +int main() { + yyparse(); + pr(ast); + return 0; +}