*** empty log message ***
authorhachti <hachti>
Sun, 19 Nov 2006 05:34:50 +0000 (05:34 +0000)
committerhachti <hachti>
Sun, 19 Nov 2006 05:34:50 +0000 (05:34 +0000)
pc-tools/ldc2/src/data_block.cpp
pc-tools/ldc2/src/data_block.hh
pc-tools/ldc2/src/data_block_0.cpp
pc-tools/ldc2/src/data_block_0.hh
pc-tools/ldc2/src/discard_block.cpp [new file with mode: 0644]
pc-tools/ldc2/src/discard_block.hh [new file with mode: 0644]
pc-tools/ldc2/src/eot_block.cpp [new file with mode: 0644]
pc-tools/ldc2/src/eot_block.hh [new file with mode: 0644]
pc-tools/ldc2/src/tape_block.cpp
pc-tools/ldc2/src/tape_block.hh
pc-tools/ldc2/src/test.cpp

index 15702b56661acf21752c8287ddbda36175496ab8..f0c91538c0480daabbb430b16aa3fea01dc4b58e 100644 (file)
@@ -4,6 +4,9 @@
 #include "data_block.hh"
 #include "data_block_0.hh"
 
+#include <stdio.h>
+
+using namespace std;
 
 data_block::data_block(tape_block& idol)
   :tape_block(idol)
@@ -25,3 +28,34 @@ int data_block::get_subtype(){
     return (new data_block_0(*this))->get_subtype();
   else return 0;
 }
+
+/*!
+ *\brief Get the block's size in 16 bit words.
+ *\return The block's 16-bit data buffer's size including header and checksum.
+ */
+int data_block::get_word_size(){
+  return word_size;
+}
+
+/*!
+ *\brief Extract 6 byte symbol name from word memory.
+ *
+ *\param  startbyte the first byte of the desired symbol name
+ *\return a string containing the symbol name. 
+ *        Trailing spaces are included.
+ *\note The word_data is handled system-intependently big endian!
+ */
+string data_block::extract_string(int startbyte){
+  string result="";  // Start with empty string
+  
+  // We don't accept negative arguments!
+  if (startbyte<0) return result; 
+  
+  // We also don't want segmentation faults!
+  if (word_size<(startbyte/2+1)) return result; 
+  // Here we pick out the characters.
+  for (int posi=startbyte;posi<startbyte+6;posi++)
+    result+=(word_data[posi/2]>>(8*(1-posi%2)))&0x7f;
+  return result;
+}
index 8b44754a34fc380ffe7cd0097be87ff4e80e1e1b..f6047ffdfeca02a0806c4561035ad39649fbcdcc 100644 (file)
@@ -1,21 +1,26 @@
 #ifndef DATA_BLOCK_HH
 #define DATA_BLOCK_HH
 
+#include<string>
 #include "tape_block.hh"
 
+using namespace std;
+
 class data_block
   : public tape_block
 {
-  //private: 
-  //data_block(); // Private constructor!
+private: 
+  data_block();
+  
 public:
-   data_block(tape_block&);
+  data_block(tape_block&);
   ~data_block();
-
-virtual int get_type();
-virtual int get_subtype();
-
+  
+  virtual int get_type();
+  virtual int get_subtype();
+  int get_word_size();
+  //protected:
+  string extract_string(int startbyte);
 };
 
 
index 2fe8c5d4212488043e8d9797402a5461d495f975..dec8e9b3e0be665f774e229255801a4b25fe3685 100644 (file)
@@ -1,3 +1,5 @@
+#include <string>
+
 #include "data_block_0.hh"
 #include "data_block.hh"
 
@@ -18,3 +20,4 @@ int data_block_0::get_subtype(){
   return (word_data[0]&0x0fc0)>>6;
 }
 
+
index 7d42c9f475622725950193c992b5ffe2587d74ea..a29f68effb17d0c214209d79339a1e5848663e5f 100644 (file)
@@ -1,9 +1,12 @@
 #ifndef DATA_BLOCK_0_H
 #define DATA_BLOCK_0_H
 
+#include <string>
 #include "data_block.hh"
 
-
+/*!
+ *\brief Class for block type (0-*).
+ */
 class data_block_0
   : public data_block
 {
@@ -11,6 +14,7 @@ class data_block_0
   data_block_0(data_block&);
   virtual ~data_block_0();
   int get_subtype();
+protected:
 };
 
 #endif
diff --git a/pc-tools/ldc2/src/discard_block.cpp b/pc-tools/ldc2/src/discard_block.cpp
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/pc-tools/ldc2/src/discard_block.hh b/pc-tools/ldc2/src/discard_block.hh
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/pc-tools/ldc2/src/eot_block.cpp b/pc-tools/ldc2/src/eot_block.cpp
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/pc-tools/ldc2/src/eot_block.hh b/pc-tools/ldc2/src/eot_block.hh
new file mode 100644 (file)
index 0000000..700e3a8
--- /dev/null
@@ -0,0 +1,25 @@
+
+#ifndef EOT_BLOCK_H
+#define EOT_BLOCK_H
+
+#include <string>
+using namespace std;
+
+class eot_block
+  : public tape_block
+{
+private: 
+  eot_block();
+  
+public:
+  eot_block(tape_block&);
+  ~eot_block();
+  
+  virtual int get_type();
+  virtual int get_subtype();
+  int get_word_size();
+  
+
+};
+
+#endif
index 8b29bc62d1a0008257d32712143d96379c9f9198..30f9819971a600528b7b68950a2ddcdd605c24d9 100644 (file)
@@ -2,6 +2,9 @@
 #include <unistd.h>
 #include <string.h>
 
+#include <string>
+#include <vector>
+
 #include "tape_block.hh"
 #include "data_block.hh"
 #include "data_block_0.hh"
 #include "silent_code.hh"
 #include "hw_constants.hh"
 
+using namespace std;
+
+/***************************************************************/
+/*!
+ *\brief Destructor.
+ */
+tape_block::~tape_block(){
+  free(raw_data);
+  free(word_data);
+}
+
+/***************************************************************/
+/*!
+ *\brief Copy constructor.
+ */
+tape_block::tape_block(tape_block & org){
+  operator=(org);
+}
+
+/***************************************************************/
+/*!
+ *\brief Assignment operator.
+ */
+void tape_block::operator=(tape_block &org){
+  block_type=org.block_type;
+  init_state=org.init_state;
+  data_read=org.data_read; 
+  raw_data=0;  
+  raw_size=org.raw_size;  
+  word_data=0;
+  word_size=org.word_size;              
+   if (raw_size){
+     raw_data=(unsigned char *)malloc(raw_size);
+     memcpy(raw_data,org.raw_data,raw_size);
+   }
+   if (word_size){
+     word_data=(unsigned short *)malloc(word_size*sizeof(unsigned short));
+     memcpy(word_data,org.word_data,word_size*sizeof(unsigned short));
+   }
+}
+
+/***************************************************************/
+/*!
+ *\brief Query the block's state.
+ *
+ * If the state is not TBS_OK, the block must be discarded.
+ *\return The block's initialisation state
+ */
+tape_block::tb_state_t tape_block::get_state(){
+  return init_state;
+}
 
+/***************************************************************/
+/*!
+ *\brief Determine the block's type
+ *
+ * This routine returns the block's type.\\
+ *\retval TBT_DATA if it's a data block
+ *\retval TBT_EOT if it's an end of tape mark
+ *\retval TBR_DISCARD if the block is unusable
+ *
+ *\note This function is virtual. That means that if the tape block in
+ * question is of the subtype data_block which overwrites this method,
+ * it will return the block type contained in the upper 4 bits of the
+ * first data word! Try to avoid testing for TBT_DATA. \n
+ * Blocks generated by gen_from_fd should never have TBT_DATA.
+ */
+int tape_block::get_type(){
+  return block_type;
+}
+
+/***************************************************************/
+/*!
+ *\brief Determine the block's subtype
+ *
+ * Some data block types have a subtype.
+ *\note This is a virtual method and to be used in derived classes.
+ *\return Always 0
+ */
+int tape_block::get_subtype(){
+  return 0;
+}
+
+/***************************************************************/
+/*!
+ *\brief Get a cleartext description of the block.
+ *\return ldc style descriptive line for the block
+ */
+vector<string> tape_block:: get_description(){
+  char buffer[100];
+  sprintf(buffer,"           (%0o-%02o) Untyped tape block",
+         get_type(),get_subtype());
+  vector<string> result;
+  result.insert(result.end(),buffer);
+  return result;
+}
+
+/***************************************************************/
+/*!
+ *\brief Get size of the internal raw data buffer
+ *\return The size of the internal raw data buffer
+ */
+int tape_block::get_raw_size(){
+  return raw_size;
+}
+
+/***************************************************************/
+/*!
+ *\brief Access internal raw data buffer
+ *
+ * The raw data buffer contains all block data except the \    \
+ * block start delimiter and block end delimiter.
+ *\return Pointer to internal raw data buffer of the block
+ */
+unsigned char * tape_block::get_raw_data(){
+  return raw_data;
+}
+
+/***************************************************************/
+/*!
+ *\brief Static factory method with file descriptor support.
+ *
+ * This method creates a tape_block by using the private
+ * constructor with file descriptor support.\t
+ * It always returns a valid pointer, errors
+ * or exceptional conditions during creation are marked in the
+ * object's state.\n
+ * The factory method tries to determine the block's type and then
+ * looks for appropriate subclasses. If there's an appropriate
+ * subclass fitting the newly-created object, an
+ * object of the subclass will be created and a pointer to this
+ * object will be returned to the caller.\n
+ * This allows for easy use of the object using it's virtual
+ * interface methods or a cast of the pointer to a sub type pointer 
+ * according to the type information, and then using the subtype's
+ * methods not already present in tape_block.\t
+ * Objects of the  following subclasses are automagically generated:\t
+ * - eot_block
+ * - data_block
+ *     -data_block_0
+ *         -data_block_0_0
+ *         -data_block_0_1
+ *         -data_block_0_2
+ *         -data_block_0_3
+ *         -data_block_0_4
+ *         -data_block_0_10
+ *         -data_block_0_14
+ *         -data_block_0_24
+ *         -data_block_0_30
+ *         -data_block_0_50
+ *         -data_block_0_54
+ *         -data_block_0_60
+ *      -data_block_1
+ *      -data_block_2
+ *      -data_block_3
+ *      -data_block_4
+ *      -data_block_5
+ *      -data_block_6
+ *      -data_block_7
+ *
+ *\return Pointer to an object of type tape_block or a subclass.
+ *\param fd A file descriptor where the read is taken from.
+ *\param input_start A pointer to a function 
+ *       called before reading data from fd.
+ *\param input_stop A pointer to a function
+ *       called after reading data from fd.
+ * 
+ *\param start_stop_arg A pointer passed to input_start 
+ *       and input_stop(). Can be anything.
+ */
 tape_block * tape_block::gen_from_fd(int  fd,
                                     void(*input_start)(void *),
                                     void (*input_stop)(void *),
@@ -63,6 +235,7 @@ tape_block * tape_block::gen_from_fd(int  fd,
 //   case 030: d0_block=new data_block_0_30(d0_block); break;
 //   case 054: d0_block=new data_block_0_54(d0_block); break;
 //   case 060: d0_block=new data_block_0_60(d0_block); break;
+//   case 060: d0_block=new data_block_0_50(d0_block); break;
   default:
     return res_block;
   }
@@ -72,30 +245,14 @@ tape_block * tape_block::gen_from_fd(int  fd,
   return res_block;
 }
 
+/***************************************************************/
 /*!
  *\brief Default constructor.
  */
 tape_block::tape_block(){}
 
 
-tape_block::tape_block(tape_block & org){
-  block_type=org.block_type;
-  init_state=org.init_state;
-  data_read=org.data_read; 
-  raw_data=0;  
-  raw_size=org.raw_size;  
-  word_data=0;
-  word_size=org.word_size;              
-   if (raw_size){
-     raw_data=(unsigned char *)malloc(raw_size);
-     memcpy(raw_data,org.raw_data,raw_size);
-   }
-   if (word_size){
-     word_data=(unsigned short *)malloc(word_size*sizeof(unsigned short));
-     memcpy(word_data,org.word_data,word_size*sizeof(unsigned short));
-   }
-}
-
+/***************************************************************/
 /*!
  *\brief Automatic constructor with file descriptor support
  *
@@ -236,78 +393,12 @@ tape_block::tape_block (int  fd,
   init_state=TBS_OK;
 }
 
-/*!
- *\brief Default destructor.
- */
-tape_block::~tape_block(){
-  free(raw_data);
-  free(word_data);
-}
-
-/*!
- *\brief Query the block's state.
- *
- * If the state is not TBS_OK, the block must be discarded.
- *\return The block's initialisation state
- */
-tape_block::tb_state_t tape_block::get_state(){
-  return init_state;
-}
-
-
-/*!
- *\brief Get size of the internal raw data buffer
- *\return The size of the internal raw data buffer
- */
-int tape_block::get_raw_size(){
-  return raw_size;
-}
-
-/*!
- *\brief Access internal raw data buffer
- *
- * The raw data buffer contains all block data except the \    \
- * block start delimiter and block end delimiter.
- *\return Pointer to internal raw data buffer of the block
- */
-unsigned char * tape_block::get_raw_data(){
-  return raw_data;
-}
 
+/***************************************************************/
 /*!
- *\brief Determine the block's type
- *
- * This routine returns the block's type.\\
- *\retval TBT_DATA if it's a data block
- *\retval TBT_EOT if it's an end of tape mark
- *\retval TBR_DISCARD if the block is unusable
- *
- *\note This function is virtual. That means that if the tape block in
- * question is of the subtype data_block which overwrites this method,
- * it will return the block type contained in the upper 4 bits of the
- * first data word! Try to avoid testing for TBT_DATA. \n
- * Blocks generated by gen_from_fd should never have TBT_DATA.
- */
-int tape_block::get_type(){
-  return block_type;
-}
-
-/*!
- *\brief Determine the block's subtype
- *
- * Some data block types have a subtype.
- *\note This is to be used in derived classes.
- *\return Always 0
- */
-int tape_block::get_subtype(){
-  return 0;
-}
-
-
-/*!
- *\brief Initialize word representation of data
- *\retval 0 on success
- *\retval 1 on error
+ *\brief Initialize word representation of data.
+ *\retval 0 on success.
+ *\retval 1 on error.
  */
 int tape_block::init_words(){
   word_size=raw_size/3;
@@ -318,10 +409,11 @@ int tape_block::init_words(){
   return 0;
 }
 
+/***************************************************************/
 /*!
- *\brief Calculate and check checksum
- *\retval 0 on success
- *\retval 1 on error
+ *\brief Calculate and check checksum.
+ *\retval 0 on success.
+ *\retval 1 on error.
  */
 int tape_block::test_checksum(){
   unsigned short sum=0;
@@ -330,3 +422,4 @@ int tape_block::test_checksum(){
   if (sum==word_data[word_size-1]) return 0;
   else return 1;
 }
+
index 9f162df471d7b629ad397440a6f6e844c2b94109..f023ead0d05aa1dd6cbb38f3043599be1c82803a 100644 (file)
@@ -1,6 +1,11 @@
 #ifndef TAPE_BLOCK_H
 #define TAPE_BLOCK_H
 
+#include <string>
+#include <vector>
+
+using namespace std;
+
 /*!
  *\brief Tape data block base class.
  *
@@ -33,26 +38,23 @@ public: // types
   } tb_type_t;
 
 public: // methods
-
-  static tape_block * 
-  gen_from_fd(int  fd,
-             void(*input_start)(void *)=0,
-             void (*input_stop)(void *)=0,
-             void * start_stop_arg=0
-             );
-  
   virtual ~tape_block();
+  
+  tape_block(tape_block &);
+  void operator=(tape_block &);
+
   tb_state_t get_state();
-  int get_raw_size();
-  unsigned char * get_raw_data();
   virtual int get_type();
   virtual int get_subtype();
-
-protected: // methods
-  tape_block(tape_block &);
-
-private: // methods
-
+  virtual vector<string> get_description();
+  int get_raw_size();
+  unsigned char * get_raw_data();
+  
+  static tape_block * gen_from_fd(int  fd,
+                                 void(*input_start)(void *)=0,
+                                 void (*input_stop)(void *)=0,
+                                 void * start_stop_arg=0
+                                 );
  
 private:   // methods
   tape_block();
@@ -61,6 +63,7 @@ private:   // methods
              void (*input_stop)(void *)=0,
              void * start_stop_arg=0
              );
+  
   int init_words(void);
   int test_checksum(); 
 
@@ -72,8 +75,7 @@ protected: // members
   int raw_size;               //!< Size of the raw data.
   unsigned short * word_data; //!< Data organized in machine words.
   int word_size;              //!< Size of the blocks in machine words.
-
-}; // tape_block
+}; // class tape_block
 
 
 #endif
index 41d45cf348b33da214dbc234ea1ba6d51cc835ee..36cb22ed22c06fb9b1463f4e176cfb3073154f29 100644 (file)
@@ -3,6 +3,7 @@
 #include <unistd.h>
 
 #include "tape_block.hh"
+#include "data_block.hh"
 
 void tape_start(void* m){
   printf("tape_start\n");
@@ -17,7 +18,19 @@ int main(){
   do{
     if (myblock) delete myblock;
     myblock=tape_block::gen_from_fd(0);
-        printf ("Block type:%2o-%o\n",myblock->get_type(),myblock->get_subtype());
+
+    vector<string> desc=myblock->get_description();
+    for (vector<string>::iterator iter=desc.begin();
+        iter!=desc.end();iter++)
+      printf("%s\n",(*iter).c_str());
+
+
+//     if ((myblock->get_type()==0)&&(myblock->get_subtype()==050)){
+//       data_block * dp=(data_block *)myblock;
+//       printf ("0-50 symbol name: %s\n",dp->extract_string(4).c_str());
+//       printf ("0-50 symbol name: %s\n",dp->extract_string(11).c_str());
+//       printf ("Block size:%i\n",dp->get_word_size());
+//     }
   } while (myblock->get_state()==tape_block::TBS_OK);
   printf("---");
   printf("State:%i\n",myblock->get_state());