dwg file format(AutoCAD DWG 文件格式说明)
an attempt to specify the dwg (r12) file format using the bff grammar for
binary files. acknowledgements i would like to thank reini urban  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  |