unoidl2

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

commit 32cbe730971e34badaa1b1fc62508c67aeacc7dd
parent 649573fccec8779e2fc33c3ada5eef4714880dfd
Author: Tomas Hlavaty <tom@logand.com>
Date:   Sat, 10 Dec 2011 13:53:57 +0100

javasplit added

Diffstat:
M.gitignore | 5+++++
MMakefile | 11++++++++++-
Ajavasplit.c | 99+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Munoidl2java.c | 43++++++++++++++++++++++++++-----------------
4 files changed, 140 insertions(+), 18 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -11,3 +11,8 @@ udkapi.list unoidl2ast unoidl2java unoidl2xml +javasplit +java.list +java/src/ +java/build/ + diff --git a/Makefile b/Makefile @@ -3,7 +3,7 @@ LIBO=/opt/libo CC=diet gcc CFLAGS=-std=c99 -O2 -ALL=unoidl2ast unoidl2xml unoidl2java +ALL=unoidl2ast unoidl2xml unoidl2java javasplit all: $(ALL) @@ -27,6 +27,9 @@ unoidl2xml: unoidl2xml.o unoidl2.o scan.o parse.o unoidl2java: unoidl2java.o unoidl2.o scan.o parse.o $(CC) -o$@ $< unoidl2.o scan.o parse.o strip $@ +javasplit: javasplit.o + $(CC) -o$@ $< + strip $@ offapi.list: find $(LIBO)/offapi/ -name '*.idl' >$@ @@ -38,6 +41,12 @@ 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 $< >$@ +java.list: allpp.idl + rm -rf java + mkdir -p java/src java/build + cat allpp.idl | ./unoidl2java | (cd java/src ; ../../javasplit) + (cd java/src ; find com -name '*.java') >java.list + (cd java/src ; javac -cp $(LIBO)/ridljar:. -d ../build @../../java.list) allpp.ast: allpp.idl cat $< | ./unoidl2ast >$@ diff --git a/javasplit.c b/javasplit.c @@ -0,0 +1,99 @@ +/* javasplit -- split output of unoidl2java into individual files */ + +#include <unistd.h> +#include <stdlib.h> +#include <string.h> +#include <fcntl.h> + +enum { + BLEN = 10240 +}; + +static inline void write_char(char x) { + write(1, &x, sizeof(char)); +} + +static inline void write_string(char *x) { + write(1, x, strlen(x)); +} + +static inline void panic(int code, char *msg) { + write(1, msg, strlen(msg)); + exit(code); +} + +static int line(char *buf, char *end) { + int n = 0; + while(buf < end) { + char c; + int m = read(0, &c, sizeof(char)); + if(m <= 0) break; + if(m != sizeof(char)) panic(1, "error reading line"); + if('\n' == c) break; + *buf++ = c; + n++; + } + *buf = 0; + return n; +} + +static int head(char *what, char *buf, char *end) { + while(*what && buf < end) { + if(*what++ != *buf++) return 0; + } + return !*what; +} + +static char *find(char what, char *buf, char *end) { + for(; buf < end; buf++) + if(what == *buf) return buf; + return NULL; +} + +static void concat2(char *buf, char *end, char *a, char *b) { + while(*a) { + if(end <= buf) goto panic; + *buf++ = *a++; + } + while(*b) { + if(end <= buf) goto panic; + *buf++ = *b++; + } + if(end <= buf) goto panic; + *buf = 0; + return; + panic: + panic(2, "buffer too small"); +} + +char *marker = "///--- "; + +int main() { + char buf[BLEN]; + char *end = buf + BLEN; + int fd = 1; + int n; + while(0 < (n = line(buf, end))) { + if(BLEN <= n + 1) + panic(3, "line too long"); + char *e = buf + n; + if(head(marker, buf, e)) { + char buf2[BLEN]; + char *end2 = buf2 + BLEN; + char *path = buf + 7; // strlen(marker) + concat2(buf2, end2, "mkdir -p ", path); + char *name = find(' ', buf2 + 9, end2); // strlen("mkdir -p ") + *name++ = 0; + system(buf2); + if(1 != fd) + close(fd); + char *space = find(' ', buf + 7, end); + *space = '/'; + fd = creat(path, 0644); + } else { + *e = '\n'; + write(fd, buf, n + 1); + } + } + return 0; +} diff --git a/unoidl2java.c b/unoidl2java.c @@ -15,26 +15,35 @@ static void pp(Any x); static void pp_list(Any x, char *sep) { for(int i = 0; !null(x); x = cdr(x), i++) { - if(!sep) { - pr("###"); print(car(x)); pl(""); - } - if(0 < i) pr(sep); + /* if(!sep) { */ + /* pr("###"); print(car(x)); pl(""); */ + /* } */ + if(sep && 0 < i) pr(sep); pp(car(x)); } } Any module; -static void pr_module(Any x, int dot) { +static void pr_module(Any x, char *sep, int dot) { if(!null(x)) { - pr_module(cdr(x), 1); + pr_module(cdr(x), sep, 1); pp(car(x)); - if(dot) pr("."); + if(dot) pr(sep); } } -static void pr_package() { - pr("package "); pr_module(module, 0); pl(";"); +static Any last(Any x) { + if(consp(x)) { + for(; !null(x); x = cdr(x)) + if(null(cdr(x))) return car(x); + return NIL; + } else return x; +} + +static void pr_package(Any class) { + pr("///--- "); pr_module(module, "/", 0); pr(" "); pp(last(class)); pl(".java"); // TODO only toplevel + pr("package "); pr_module(module, ".", 0); pl(";"); } static void pr_enum(Any x) { @@ -43,7 +52,7 @@ static void pr_enum(Any x) { Any values = cdddr(x); Any v0 = car(values); Any v0k = consp(v0) ? car(v0) : v0; - pr_package(); + pr_package(name); pr("public final class "); pp(name); pl(" extends com.sun.star.uno.Enum {"); pr(" private "); pp(name); pl("(int value) {"); pl(" super(value);"); @@ -62,7 +71,7 @@ static void pr_enum(Any x) { 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, "?"); + Any v = consp(value) ? cdr(value) : mk(INT, "?"); // TODO pr(" case "); pp(v); pr(": return "); pr(k); pl(";"); } pl(" }"); @@ -92,7 +101,7 @@ static void pr_struct(Any x) { Any published = caddr(x); Any super = cadddr(x); Any slots = cddddr(x); - pr_package(); + pr_package(name); pr("public class "); pp(name); if(!null(super)) {pr(" extends "); pp(super);} pl(" {"); @@ -133,7 +142,7 @@ static void pr_exception(Any x) { Any published = caddr(x); Any super = cadddr(x); Any body = cddddr(x); - pr_package(); + pr_package(name); pr("public class "); pp(name); if(!null(super)) { pr(" extends "); pp(super); @@ -157,7 +166,7 @@ static void pr_interface(Any x) { // TODO nesting Any published = caddr(x); Any super = cadddr(x); Any body = cddddr(x); - pr_package(); + pr_package(name); pr("public interface "); pp(name); if(!null(super)) {pr(" extends "); pp(super);} pl(" {"); @@ -191,7 +200,7 @@ static void pr_service(Any x) { Any published = caddr(x); Any super = cadddr(x); Any body = caddddr(x); - pr_package(); + pr_package(name); pr("public class "); pp(name); if(!null(super)) {pr(" extends "); pp(super);} pl(" {"); @@ -206,7 +215,7 @@ static void pr_constants(Any x) { Any name = cadr(x); Any published = caddr(x); Any body = cdddr(x); - pr_package(); + pr_package(name); pr("public final class "); pp(name); pl(" {"); pp_list(body, ""); pl("}"); @@ -288,7 +297,7 @@ static void pp(Any x) { //case PLUS: unary? //case MINUS: case NOT: pr("!"); pp(cadr(x)); break; - default: print(x); + default: pr("###"); print(x); } } else print(x);