*** empty log message ***
[h316.git] / pc-tools / ldc2 / src / tape_block.cpp
index 3de7bfb5af1155ff906e1e7ee6c05bcccba6269c..8ba9ddea5e37eb179b2520c33e711ffc319ee324 100644 (file)
@@ -1,4 +1,19 @@
-
+/******************************************************************************
+ * 
+ * LDC2 source code
+ *
+ * $Date: 2007/03/26 03:20:31 $
+ * $Author: hachti $
+ *
+ * $Log: tape_block.cpp,v $
+ * Revision 2.1  2007/03/26 03:20:31  hachti
+ * *** empty log message ***
+ *
+ * Revision 2.0  2007-03-26 01:00:40  hachti
+ * *** empty log message ***
+ *
+ *
+ ******************************************************************************/
 
 #include <string>
 #include <vector>
@@ -144,14 +159,85 @@ int tape_block::get_discarded_bytes(){
 /*!
  *\brief Access internal raw data buffer
  *
- * The raw data buffer contains all block data except the \    \
- * block start delimiter and block end delimiter.
+ * The raw data buffer contains all block data except the
+ * block start and end delimiters.
  *\return Pointer to internal raw data buffer of the block
  */
 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<string> tape_block::get_exported_symbols(){
+  vector<string> 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<string> tape_block::get_called_symbols(){
+  vector<string> 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 +321,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 +344,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;
   }
   
@@ -280,6 +368,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 +479,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 +503,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 +554,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<MINIMUM_DATA_BLOCK_WORDSIZE) return 1; // Block too short!
   word_data=(unsigned short *)malloc(word_size*sizeof(unsigned short));
   for (int pos=0; pos<word_size; pos++)
-    word_data[pos]=combine466(raw_data+3*pos);
+    word_data[pos]=combine466(raw_data+1+3*pos);
   return 0;
 }
 
@@ -542,7 +634,7 @@ eof_legal_exception(int bytes_consumed){
 /***************************************************************/
 /*!
  *\brief Get amount of consumed data before EOF came along.
- *\return Amound of bytes read from fd while looking for
+ *\return Amount of bytes read from fd while looking for
  *        new block or EOF.
  */
 int tape_block::eof_legal_exception::get_consumed(){