dwg_file_format
an_attempt_to_specify_the_dwg_(r12)_file_format_using_the_bff_grammar_for
binary_files.
acknowledgements
i_would_like_to_thank_reini_urban_<[email protected]>_for_his
contributions.
definition_of_the_elementary_elements
typedef_word_word_:=
_ _ _byte_:_b1, byte_:_b2
_ _ _return_(word)f_|_((word)s_<<_8).
typedef_longword_longp_:=
_ _ _byte_:_b1, byte_:_b2, byte_:_b3, byte_:_b4
_ _ _return_(longword)b1_|_((longword)b2_<<_8)
_ _ _ _ _ |_((longword)b3_<<_16)_|_((longword)b4_<<_24).
typedef_longword_longword_:=
_ _ _byte_:_b1, byte_:_b2, byte_:_b3, byte_:_b4
_ _ _return_(longword)b1_|_((longword)b2_<<_8)
_ _ _ _ _ |_((longword)b3_<<_16)_|_((longword)b4_<<_24).
definition_of_the_whole_file
root_dwg_file_:=
_[begin_:_end](
_ char[12]_:_version,
_ byte, word, word, word, byte,
_ longp_:_p_entities, longp_:_p_entend,
_ longp_:_p_blocksec, byte[4], longp_:_p_bsend, byte[4],
_ tablepos_:_block_table,
_ tablepos_:_layer_table,
_ tablepos_:_style_table,
_ tablepos_:_ltype_table,
_ tablepos_:_view_table,
_ header, [cur_:_0x3ef]byte*,
_ tablepos_:_ucs_table, [cur_:_0x500]byte*,
_ tablepos_:_vport_table, byte[8],
_ tablepos_:_appid_table, byte[6],
_ tablepos_:_dimstyle_table, [cur_:_0x69f]byte*,
_ tablepos_:_p13_table, bytes[38],
_ [p_entities_:_p_entend]entities_:_ents, _byte[19],
_ [block_table.start_:_]blocks_:_block_table,
_ [layer_table.start_:_]layers_:_layer_table,
_ [style_table.start_:_]styles_:_style_table,
_ [ltype_table.start_:_]ltypes_:_ltype_table,
_ [view_table.start_:_]table_:_view_table,
_ [ucs_table.start_:_]table_:_ucs_table,
_ [vport_table.start_:_vport_table.end]table_:_vport_table,
_ [appid_table.start_:_]appids_:_appid_table,
_ [dimstyle_table.start_:_]table_:_dimstyle_table,
_ [p13_table.start_:_]table_:_p13_table,
_ [p_blocksec_:_p_bsend]entities_:_blocks, bytes[36],
_ longp_=_p_entities, longp_=_p_entend,
_ longp_=_blocksec, longp_=_bsend,
_ bytes[12],
_ bytes[6],
_ longp_=_block_table.start, _bytes[6],
_ longp_=_layer_table.start, _bytes[6],
_ longp_=_style_table.start, _bytes[6],
_ longp_=_ltype_table.start, _bytes[6]
_ longp_=_view_table.start, _bytes[6],
_ longp_=_ucs_table.start, _bytes[6],
_ longp_=_vport_table.start, _bytes[6],
_ longp_=_appid_table.start, _bytes[6],
_ longp_=_dimstyle_table.start, _bytes[6],
_ longp_=_p13_table.start, _bytes[6],
_ longp_ bytes*,
_).
a_table_position
tablepos_:=
_ _word_:_size,
_ _long_:_nr,
_ _long_:_start,
the_header
header_:=
_ _word,
_ _point(true)_:_inbase,
_ _point(true)_:_extmin,
_ _point(true)_:_extmax,
_ _point(false)_:_limmin,
_ _point(false)_:_limmax,
_ _double[4],
_ _byte[2],
_ _double[2],
_ _byte[56],
_ _double[3],
_ _byte[18],
_ _double_.
the_block_table
blocks_:=
_ (_[size](
_ _ _ byte_:_flag,
_ _ _ char[32]_:_name,
_ _ _ word_:_used,
_ _ _ byte, word, byte, word,
_ _ _ check_2
_ _ )
_ )[nr]_:_blocks_info,
_ check_32.
check_2_:=_byte[2].
check_32_:=_byte[32].
the_layer_table
layers_:=
_ (_[size](
_ _ _ byte_:_flag,
_ _ _ char[32]_:_name,
_ _ _ word_:_used,
_ _ _ word_:_color,
_ _ _ word_:_style,
_ _ _ check_2
_ _ )
_ )[nr]_:_layer_info,
_ check_32.
the_style_table
styles_:=
_ (_[size](
_ _ _ byte_:_flag,
_ _ _ char[32]_:_name,
_ _ _ word, double[3], byte, double, char[128],
_ _ _ check_2
_ _ )
_ )[nr]_:_style_info,
_ check_32.
the_line-type_table
ltypes_:=
_ (_[size](
_ _ _ byte_:_flag,
_ _ _ char[32]_:_name,
_ _ _ word, char[48], byte,
_ _ _ byte, double[13],
_ _ _ check_2
_ _ )
_ )[nr]_:_ltype_info,
_ check_32_.
the_application_identifier_table
appids_:=
_ (_[size](
_ _ _ byte_:_flag,
_ _ _ char[32]_:_name,
_ _ _ word,
_ _ _ check_2
_ _ )
_ )[nr]_:_appid_info,
_ check_32_.
the_other_tables
table_:=
_ (_[size](
_ _ _ byte_:_flag,
_ _ _ [size_-_3]byte*,
_ _ _ check_2
_ _ )
_ )[nr],
_ check_32_.
the_entities
(experimental)
entities_:=
_ (_byte_:_kind,
_ _ byte_:_flag,
_ _ word_:_length,
_ _ [length_-_4](
_ _ _ word_:_layer,
_ _ _ word_:_opts,
_ _ _ if_(flag_&_1)_then_byte_:_color_else_color_=_0_fi,
_ _ _ if_(flag_&_0x40)_then_byte_:_extra_else_extra_=_0_fi,
_ _ _ if_(extra_&_2)_then_xdata_fi,
_ _ _ if_(flag_&_2)_then_word_:_type_fi,
_ _ _ if_(flag_&_4_&&_kind_>_2_&&_kind_!=_22)_then_double_:_z_fi,
_ _ _ if_(flag_&_8)_then_double_:_th_fi,
_ _ _ if_(flag_&_0x20)_then_handle_fi,
_ _ _ if_(extra_&_4)_then_word_:_paper_fi,
_ _ _ switch_(kind)
_ _ _ case_1:_ /*_line_*/
_ _ _ _ point(!(flag_&_4))_:_l10,
_ _ _ _ point(!(flag_&_4))_:_l11,
_ _ _ _ if_(opts_&_1)_then_point(true)_:_l210_fi,
_ _ _ _ if_(opts_&_2)_then_double_:_l38_fi,
_ _ _ case_2:_ /*_point_*/
_ _ _ _ point(!(flag_&_4))_:_l10,
_ _ _ _ if_(opts_&_1)_then_point(true)_:_l210_fi,
_ _ _ _ if_(opts_&_2)_then_double_:_l38_fi,
_ _ _ case_3:_ /*_circle_*/
_ _ _ _ point(false)_:_l10,
_ _ _ _ double_:_l40,
_ _ _ _ if_(opts_&_1)_then_point(true)_:_l210_fi,
_ _ _ _ if_(opts_&_2)_then_double_:_l38_fi,
_ _ _ case_4:_ /*_shape_*/
_ _ _ _ point(false)_:_l10,
_ _ _ _ word_:_l2,
_ _ _ _ if_(opts_&_1)_then_point(true)_:_l210_fi,
_ _ _ _ if_(opts_&_2)_then_double_:_l38_fi,
_ _ _ case_7:_/*_text_*/
_ _ _ _ point(false)_:_l10,
_ _ _ _ double_:_l40,
_ _ _ _ string_:_l1,
_ _ _ _ if_(opts_&_1)_then_double_:_l50_fi,
_ _ _ _ if_(opts_&_2)_then_double_:_l41_fi,
_ _ _ _ if_(opts_&_4)_then_double_:_l51_fi, _ _ _ _ _ _/*?*/
_ _ _ _ if_(opts_&_8)_then_byte_:_l7_fi,
_ _ _ _ if_(opts_&_0x10)_then_byte_:_l71_fi,
_ _ _ _ if_(opts_&_0x20)_then_byte_:_l72_fi,
_ _ _ _ if_(opts_&_0x40)_then_point(false)_:_l11_fi,
_ _ _ _ if_(opts_&_0x100)_then_byte_:_l73_fi,
_ _ _ case_8:_ /*_arc_*/
_ _ _ _ point(false)_:_l10,
_ _ _ _ double_:_l40,
_ _ _ _ double_:_l50,
_ _ _ _ double_:_l51,
_ _ _ _ if_(opts_&_1)_then_point(true)_:_l210_fi,
_ _ _ _ if_(opts_&_2)_then_double_:_l38_fi,
_ _ _ case_9:_ _/*_trace_*/
_ _ _ _ point(false)_:_l10,
_ _ _ _ point(false)_:_l11,
_ _ _ _ point(false)_:_l12,
_ _ _ _ point(false)_:_l13,
_ _ _ _ if_(opts_&_1)_then_point(true)_:_l210_fi,
_ _ _ _ if_(opts_&_2)_then_double_:_l38_fi,
_ _ _ case_11:_ _/*_solid_*/
_ _ _ _ point(false)_:_l11,
_ _ _ _ point(false)_:_l12,
_ _ _ _ point(false)_:_l13,
_ _ _ _ point(false)_:_l14,
_ _ _ _ if_(opts_&_1)_then_point(true)_:_l210_fi,
_ _ _ _ if_(opts_&_2)_then_double_:_l38_fi
_ _ _ case_12:_ _/*_block_*/
_ _ _ _ point(false)_:_l10, _ _ _ _ _ _ _ /*?*/
_ _ _ _ string_:_l1, _ _ _ _ _ _ _ _ _ _ _/*_if_(opts_&_1)_then_?_*/
_ _ _ _ if_(opts_&_2)_then_string_:_l3_fi
_ _ _ case_13:_ /*_endblk_*/
_ _ _ case_14:_ _/*_insert_*/
_ _ _ _ word_:_l1,
_ _ _ _ point(false)_:_l10,
_ _ _ _ if_(opts_&_1)_then_double_:_l41_fi,
_ _ _ _ if_(opts_&_2)_then_double_:_l42_fi,
_ _ _ _ if_(opts_&_4)_then_double_:_l43_fi,
_ _ _ _ if_(opts_&_8)_then_double_:_l50_fi,
_ _ _ _ if_(opts_&_0x10)_then_byte_:_l70_fi, _ _ _ _ _ _ _ /*?*/
_ _ _ _ if_(opts_&_0x20)_then_byte_:_l71_fi, _ _ _ _ _ _ _ /*?*/
_ _ _ _ if_(opts_&_0x40)_then_double_:_l44_fi, _ _ _ _ _ _ /*?*/
_ _ _ _ if_(opts_&_0x80)_then_double_:_l45_fi_ _ _ _ _ _ _ /*?*/
_ _ _ case_15:_ _ /*_attdef_*/
_ _ _ _ point(false)_:_l10,
_ _ _ _ double_:_l40,
_ _ _ _ string_:_l1,
_ _ _ _ string_:_l3,
_ _ _ _ string_:_l2,
_ _ _ _ byte_:_l70,
_ _ _ _ if_(opts_&_1)_then_byte_:_l73_fi, _ _ _ _ _/*?*/
_ _ _ _ if_(opts_&_2)_then_double_:_l50_fi, _ _ _ _/*?*/
_ _ _ _ if_(opts_&_4)_then_double_:_l41_fi,
_ _ _ _ if_(opts_&_8)_then_double_:_l42_fi,
_ _ _ _ if_(opts_&_0x10)_then_byte_:_l7_fi,
_ _ _ _ if_(opts_&_0x20)_then_byte_:_l71_fi,
_ _ _ _ if_(opts_&_0x40)_then_byte_:_l72_fi,
_ _ _ _ if_(opts_&_0x80)_then_point(false)_:_l11_fi, _/*?*/
_ _ _ _ if_(opts_&_0x100)_then_point(true)_:_l210_fi,
_ _ _ _ if_(opts_&_0x200)_then_double_:_l38_fi_ _ _ _ /*?*/
_ _ _ case_16:_ _/*_attrib_*/
_ _ _ _ point(false)_:_l10,
_ _ _ _ double_:_l40,
_ _ _ _ string_:_l1,
_ _ _ _ string_:_l2,
_ _ _ _ byte_:_l70,
_ _ _ _ if_(opts_&_1)_then_byte_:_l73_fi, _ _ _ _ _/*?*/
_ _ _ _ if_(opts_&_2)_then_double_:_l50_fi, _ _ _ _/*?*/
_ _ _ _ if_(opts_&_4)_then_double_:_l41_fi,
_ _ _ _ if_(opts_&_8)_then_double_:_l42_fi,
_ _ _ _ if_(opts_&_0x10)_then_byte_:_l7_fi,
_ _ _ _ if_(opts_&_0x20)_then_byte_:_l71_fi,
_ _ _ _ if_(opts_&_0x40)_then_byte_:_l72_fi,
_ _ _ _ if_(opts_&_0x80)_then_point(false)_:_l11_fi, _/*?*/
_ _ _ _ if_(opts_&_0x100)_then_point(true)_:_l210_fi,
_ _ _ _ if_(opts_&_0x200)_then_double_:_l38_fi_ _ _ _ /*?*/
_ _ _ case_17:_ _/*_s/bend_*/
_ _ _ _ long
_ _ _ case_19:_ _/*_pline_*/
_ _ _ _ if_(opts_&_1)_then_byte_:_l70_fi,
_ _ _ _ if_(opts_&_2)_then_double_:_l40_fi, _ _ _ _ _ _ _ _ _/*?*/
_ _ _ _ if_(opts_&_4)_then_byte_:_l71_fi, _ _ _ _/*?*/
_ _ _ _ if_(opts_&_8)_then_byte_:_l72_fi, _ _ _ _/*?*/
_ _ _ _ if_(opts_&_0x10)_then_byte_:_l73_fi, _ _ _ _/*?*/
_ _ _ _ if_(opts_&_0x20)_then_byte_:_l74_fi, _ _ _ _/*?*/
_ _ _ _ if_(opts_&_0x40)_then_byte_:_l75_fi_ _ _ _ _/*?*/
_ _ _ case_20:_ _/*_vertex_*/
_ _ _ _ point(false)_:_l10,
_ _ _ _ if_(opts_&_1)_then_double_:_l40_fi, _ _ _ _ _/*?*/
_ _ _ _ if_(opts_&_2)_then_double_:_l41_fi, _ _ _ _ _/*?*/
_ _ _ _ if_(opts_&_4)_then_byte_:_l70_fi, _ _ _ _ _ _/*?*/
_ _ _ _ if_(opts_&_8)_then_double_:_l50_fi_ _ _ _ _ _/*?*/
_ _ _ case_22:_ _/*_3dface_*/
_ _ _ _ point(!(flag_&_4))_:_l10,
_ _ _ _ point(!(flag_&_4))_:_l11,
_ _ _ _ point(!(flag_&_4))_:_l12,
_ _ _ _ point(!(flag_&_4))_:_l13
_ _ _ case_23:_ _/*_dim_*/
_ _ _ _ word_:_l1,
_ _ _ _ point(true)_:_l10,
_ _ _ _ point(false)_:_l11, _/*?*/
_ _ _ _ if_(opts_&_2)_then_byte_:_l70_fi,
_ _ _ _ if_(opts_&_1)_then_point(true)_:_l12_fi, _ /*?*/
_ _ _ _ if_(opts_&_4)_then_string_:_l1_fi,
_ _ _ _ if_(opts_&_8)_then_point(true)_:_l13_fi,
_ _ _ _ if_(opts_&_0x10)_then_point(true)_:_l14_fi,
_ _ _ _ if_(opts_&_0x20)_then_point(true)_:_l15_fi,
_ _ _ _ if_(opts_&_0x40)_then_point(true)_:_l16_fi,
_ _ _ _ if_(opts_&_0x80)_then_double_:_l40_fi,
_ _ _ _ if_(opts_&_0x100)_then_double_:_l50_fi,
_ _ _ _ if_(opts_&_0x200)_then_double_:_l51_fi,
_ _ _ _ if_(opts_&_0x400)_then_double_:_l52_fi,
_ _ _ _ if_(opts_&_0x800)_then_double_:_l53_fi
_ _ _ case_24:_ _/*_vport_*/
_ _ _ _ point(true)_:_l10,
_ _ _ _ double_:_l40,
_ _ _ _ double_:_l41,
_ _ _ _ word_:_l68
_ _ _ endswitch
_ _ _ check_2
_ _ )
_ )*_:_entities.
_