X-Git-Url: http://gitweb.hachti.de/?a=blobdiff_plain;f=pc-tools%2Fldc2%2Fsrc%2Ftape_block.cpp;h=b759a1266473f2d3606153ebf2fad0425c1079f6;hb=874a2bd89fd65e5a1763d88c218f066a424e0d04;hp=3de7bfb5af1155ff906e1e7ee6c05bcccba6269c;hpb=7880ae2dd0ed55ec671be0fc449487420a126626;p=h316.git diff --git a/pc-tools/ldc2/src/tape_block.cpp b/pc-tools/ldc2/src/tape_block.cpp index 3de7bfb..b759a12 100644 --- a/pc-tools/ldc2/src/tape_block.cpp +++ b/pc-tools/ldc2/src/tape_block.cpp @@ -152,6 +152,77 @@ unsigned char * tape_block::get_raw_data(){ return raw_data; } +/***************************************************************/ +/*! + *\brief Dump contents of the block to a file descriptor. + * + *\param fd A writable file descriptor. + *\return Always zero. + *\throw io_error_exception A write error occured. + */ +int tape_block::dump_to_fd(int fd){ + int to_write=raw_size; + unsigned char * dump_ptr=raw_data; + int written; + while (to_write) { + written=write(fd,dump_ptr,to_write); + if (written < 0) throw io_error_exception(); + to_write-=written; + dump_ptr+=written; + } + return 0; +} + +/***************************************************************/ +/*! + *\brief Determine if the block marks the end of an object + *\retval true The block marks the end of an object. + *\retval false The block does not mark the end of an object. + *\note This is only a virtual method returning always false. + * Classes which can be the legal last block of an object + * will overwrite this method so that it returns true. + */ +bool tape_block::is_endblock(){ + return false; +} + +/***************************************************************/ +/*! + *\brief Get exported symbols. + *\return A vector containing any symbols exported in this block. + *\note This is only a virtual method returning always an empty + * vector. Classes describing appropriate data blocks + * will override this method. + */ +vector tape_block::get_exported_symbols(){ + vector result; + return result; +} + +/***************************************************************/ +/*! + *\brief Get called symbols. + *\return A vector containing any symbols called in this block. + *\note This is only a virtual method returning always an empty + * vector. Classes describing appropriate data blocks + * will override this method. + */ +vector tape_block::get_called_symbols(){ + vector result; + return result; +} + +/***************************************************************/ +/*! + *\brief Determine if the block has a known type. + *\return true if type and subtype are known. + *\return false if the block type is not one of the valid end + * nodes of the type tree. + */ +bool tape_block::has_known_type(){ + return m_has_known_type; +} + /***************************************************************/ /*! *\brief Static factory method for tape blocks. @@ -235,6 +306,7 @@ tape_block * tape_block::gen_from_fd(int fd, case tape_block::TBT_EOT: n_eot_block=new eot_block(*n_tape_block); delete n_tape_block; + n_eot_block->m_has_known_type=true; return n_eot_block; default: // Unknown block, a bad thing! return n_tape_block; @@ -257,6 +329,7 @@ tape_block * tape_block::gen_from_fd(int fd, } if (n_data_block_0==0){ // So we must have found another one delete n_data_block; + n_data_block_x->m_has_known_type=true; return n_data_block_x; } @@ -266,7 +339,7 @@ tape_block * tape_block::gen_from_fd(int fd, case 001: n_data_block_0_x=new data_block_0_1(*n_data_block_0); break; case 002: n_data_block_0_x=new data_block_0_2(*n_data_block_0); break; case 003: n_data_block_0_x=new data_block_0_3(*n_data_block_0); break; - case 004: n_data_block_0_x=new data_block_0_4(*n_data_block_0); break; + // case 004: n_data_block_0_x=new data_block_0_4(*n_data_block_0); break; case 010: n_data_block_0_x=new data_block_0_10(*n_data_block_0); break; case 014: n_data_block_0_x=new data_block_0_14(*n_data_block_0); break; case 024: n_data_block_0_x=new data_block_0_24(*n_data_block_0); break; @@ -280,6 +353,7 @@ tape_block * tape_block::gen_from_fd(int fd, return n_data_block_0; } delete n_data_block_0; + n_data_block_0_x->m_has_known_type=true; return n_data_block_0_x; } @@ -390,11 +464,14 @@ tape_block::tape_block (int fd, break; } } while (buffer != (unsigned char) BLOCK_START_DELIMITER); - discarded_bytes--; // Dont want to declare the start delimiter discarded! + discarded_bytes--; // Don't want to declare the start delimiter discarded! raw_size=1; // But we want to account it here! - + /* Now input the block data */ block_complete = 0; + + raw_data[0]=buffer; // Put the start delimiter in! + do { retval = read (fd, &buffer, 1); @@ -411,12 +488,12 @@ tape_block::tape_block (int fd, /* sort in the new byte */ raw_size++; // Need more memory?? - if (raw_size==poolsize){ + if (raw_size>poolsize){ poolsize+=1024; raw_data=(unsigned char*)realloc(raw_data,poolsize); } - raw_data[raw_size-2]=buffer; + raw_data[raw_size-1]=buffer; /* Look for end ot block sequence */ switch(eob_needed){ @@ -462,11 +539,11 @@ tape_block::tape_block (int fd, *\retval 1 on error. */ int tape_block::init_words(){ - word_size=(raw_size-EOB_LENGTH)/3; + word_size=(raw_size-EOB_LENGTH-1)/3; if (word_size