some patches here... not perfect yet :-P but feel free to push these to master, Pitanga. Because I think it is very close to the right way of doing these things. I just cant figure out what's wrong with it right now. Perhaps some of you guys can help me figure it out.
I am too sleepy. I need to go to bed now. Happy Hacking! Felipe "Juca" Sanches On Thu, Feb 11, 2010 at 12:22 AM, Felipe Sanches <[email protected]>wrote: > > > On Wed, Feb 10, 2010 at 9:41 PM, Wookey <[email protected]> wrote: > >> +++ Felipe Sanches [2010-02-10 16:25 -0200]: >> > hi, guys, >> > >> > The file attached to this bug report caught my attention to 2 bugs in >> our >> > description of the dwg spec. The patch attached fixes these 2 bugs and >> thus >> > results in the file being properly parsed by LibreDWG. >> >> Thanx for the marvellously quick fix. >> >> > As you can see in this part of the output I've got, all 14.778 objects >> of the >> > dwg file were properly parsed, but now we have another issue: a segfault >> in the >> > application itself (testSVG.c) instead of in the lib: >> >> Yep - I get the same here after applying the patch. >> >> Wookey >> > > actually I have another patch here that tries to solve this, but I am > facing some strange issues here. It SegFaults in a hard to predict pattern. > Sometimes it SegFaults, sometimes it dont. > > I have even got the tool to run once without segfaulting, which generated a > valid svg file here. But the file is not a good conversion of your dwg. It > seems that our SVG generator is still very poor. > > here it is: > http://bighead.poli.usp.br/~juca/tmp/23Nightingale.svg<http://bighead.poli.usp.br/%7Ejuca/tmp/23Nightingale.svg> > > If you look at it in a text editor you'll see some interesting strings in > there :-) > > --Felipe Sanches >
From 98486bf95b69b6415324af2f0561454e9691c8a7 Mon Sep 17 00:00:00 2001 From: Felipe Correa da Silva Sanches <[email protected]> Date: Wed, 10 Feb 2010 17:53:10 -0200 Subject: [PATCH] check if some pointers are not null --- examples/testSVG.c | 14 ++++++++++++-- 1 files changed, 12 insertions(+), 2 deletions(-) diff --git a/examples/testSVG.c b/examples/testSVG.c index 8881f10..bfa6032 100644 --- a/examples/testSVG.c +++ b/examples/testSVG.c @@ -192,10 +192,20 @@ output_object(Dwg_Object* obj){ void output_BLOCK_HEADER(Dwg_Object_Ref* ref) { Dwg_Object* obj; - Dwg_Object_BLOCK_HEADER* hdr; - hdr = ref->obj->tio.object->tio.BLOCK_HEADER; + if (!ref) + { + fprintf(stderr, "Found null object reference. Could not output an SVG symbol for this BLOCK_HEADER\n"); + return; + } + if (!ref->obj) + { + fprintf(stderr, "Found null ref->obj\n"); + return; + } + + hdr = ref->obj->tio.object->tio.BLOCK_HEADER; printf( "\t<g id=\"symbol-%lu\" >\n\t\t<!-- %s -->\n", ref->absolute_ref, hdr->entry_name); -- 1.6.0.4
From 21889ddc2fa53a8fff4dfa53728d5c6ad49ad728 Mon Sep 17 00:00:00 2001 From: Felipe Correa da Silva Sanches <[email protected]> Date: Wed, 10 Feb 2010 17:54:01 -0200 Subject: [PATCH] resolve object references after parsing r2004 and r2007 files --- src/decode.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-) diff --git a/src/decode.c b/src/decode.c index e9c2c6e..fb875e7 100644 --- a/src/decode.c +++ b/src/decode.c @@ -1722,7 +1722,7 @@ decode_R2004(Bit_Chain* dat, Dwg_Data * dwg) dwg->header.num_descriptions = 0; } - + resolve_objectref_vector(dwg); LOG_ERROR( "Decoding of DWG version R2004 header is not fully implemented yet. We are going to try\n") @@ -1837,6 +1837,7 @@ decode_R2007(Bit_Chain* dat, Dwg_Data * dwg) ///////////////////////////////////////// // incomplete implementation! ///////////////////////////////////////// + resolve_objectref_vector(dwg); LOG_ERROR( "Decoding of DWG version R2007 header is not fully implemented yet. we are going to try\n") -- 1.6.0.4
From 403812b454c50b1fa259b0cb37bf5f6f1f0dd226 Mon Sep 17 00:00:00 2001 From: Felipe Correa da Silva Sanches <[email protected]> Date: Thu, 11 Feb 2010 00:30:32 -0200 Subject: [PATCH] implement version dependant iterator for owned obects of a BLOCK_HEADER --- examples/testSVG.c | 10 ++++------ src/dwg.c | 30 ++++++++++++++++++++++++++++++ src/dwg.h | 7 +++++++ 3 files changed, 41 insertions(+), 6 deletions(-) diff --git a/examples/testSVG.c b/examples/testSVG.c index bfa6032..8640ffa 100644 --- a/examples/testSVG.c +++ b/examples/testSVG.c @@ -209,15 +209,13 @@ void output_BLOCK_HEADER(Dwg_Object_Ref* ref) printf( "\t<g id=\"symbol-%lu\" >\n\t\t<!-- %s -->\n", ref->absolute_ref, hdr->entry_name); - //TODO:still not quite right I think... - obj = hdr->first_entity->obj; - while(obj && obj != hdr->last_entity->obj) + obj = get_first_owned_object(ref->obj, hdr); + + while(obj) { output_object(obj); - obj = dwg_next_object(obj); + obj = get_next_owned_object(ref->obj, obj, hdr); } - //output the last one: - if (obj) output_object(obj); printf("\t</g>\n"); } diff --git a/src/dwg.c b/src/dwg.c index 254099f..b999e7a 100644 --- a/src/dwg.c +++ b/src/dwg.c @@ -347,6 +347,36 @@ dwg_get_object(Dwg_Object* obj, Dwg_Object_Ref* ref) return -1; } +Dwg_Object* get_first_owned_object(Dwg_Object* hdr_obj, Dwg_Object_BLOCK_HEADER* hdr){ + Bit_Chain *dat = hdr_obj->parent->bit_chain; + + VERSIONS(R_13, R_2000) + { + return hdr->first_entity->obj; + } + SINCE(R_2004) + { + hdr->__iterator = 0; + return hdr->entities[0]->obj; + } +} + +Dwg_Object* get_next_owned_object(Dwg_Object* hdr_obj, Dwg_Object* current, Dwg_Object_BLOCK_HEADER* hdr){ + Bit_Chain *dat = hdr_obj->parent->bit_chain; + + VERSIONS(R_13, R_2000) + { + if (current==hdr->last_entity->obj) return 0; + return dwg_next_object(current); + } + SINCE(R_2004) + { + hdr->__iterator++; + if (hdr->__iterator == hdr->owned_object_count) return 0; + return hdr->entities[hdr->__iterator]->obj; + } +} + void dwg_free(Dwg_Data * dwg) { diff --git a/src/dwg.h b/src/dwg.h index 94413d3..ea4abc2 100644 --- a/src/dwg.h +++ b/src/dwg.h @@ -1356,6 +1356,7 @@ typedef struct _dwg_object_BLOCK_CONTROL */ typedef struct _dwg_object_BLOCK_HEADER { + int __iterator; BITCODE_TV entry_name; BITCODE_B _64_flag; BITCODE_BS xrefindex_plus1; @@ -2836,6 +2837,12 @@ dwg_next_object(Dwg_Object* obj); int dwg_get_object(Dwg_Object* obj, Dwg_Object_Ref* ref); +Dwg_Object* +get_first_owned_object(Dwg_Object* hdr_obj, Dwg_Object_BLOCK_HEADER* hdr); + +Dwg_Object* +get_next_owned_object(Dwg_Object* hdr_obj, Dwg_Object* current, Dwg_Object_BLOCK_HEADER* hdr); + void dwg_print_object(Dwg_Object *obj); -- 1.6.0.4
