| 1 | /****************************************************************************** |
| 2 | * |
| 3 | * LDC2 source code |
| 4 | * |
| 5 | * $Date: 2007/12/23 15:25:11 $ |
| 6 | * $Author: hachti $ |
| 7 | * |
| 8 | * $Log: tape_block.hh,v $ |
| 9 | * Revision 2.1 2007/12/23 15:25:11 hachti |
| 10 | * *** empty log message *** |
| 11 | * |
| 12 | * Revision 2.0 2007-03-26 01:00:40 hachti |
| 13 | * *** empty log message *** |
| 14 | * |
| 15 | * |
| 16 | ******************************************************************************/ |
| 17 | |
| 18 | #ifndef TAPE_BLOCK_HH |
| 19 | #define TAPE_BLOCK_HH |
| 20 | |
| 21 | using namespace std; |
| 22 | |
| 23 | /*! |
| 24 | *\brief Tape data block base class. |
| 25 | * |
| 26 | * This class represents a Honeywell paper tape block. |
| 27 | * That may be some kind of data block or a end of tape mark. |
| 28 | */ |
| 29 | class tape_block{ |
| 30 | |
| 31 | public: // types |
| 32 | |
| 33 | /*! |
| 34 | * Tape block types. |
| 35 | */ |
| 36 | typedef enum { |
| 37 | TBT_DATA=0x10, //!< Data block |
| 38 | TBT_EOT, //!< End of tape block |
| 39 | TBT_BROKEN, //!< A broken block |
| 40 | } tb_type_t; |
| 41 | |
| 42 | /*! |
| 43 | *\brief Local base class for exceptions. |
| 44 | */ |
| 45 | class exception { |
| 46 | protected: |
| 47 | exception(); |
| 48 | public: |
| 49 | virtual ~exception(); |
| 50 | tape_block * get_block(); |
| 51 | protected: |
| 52 | tape_block * m_broken_block; |
| 53 | }; |
| 54 | |
| 55 | /*! |
| 56 | *\brief Checksum error exception. |
| 57 | */ |
| 58 | class checksum_error_exception |
| 59 | : public exception { |
| 60 | public: |
| 61 | checksum_error_exception(tape_block * block); |
| 62 | }; |
| 63 | |
| 64 | /*! |
| 65 | *\brief EOF while reading block exception. |
| 66 | */ |
| 67 | class eof_illegal_exception |
| 68 | : public exception { |
| 69 | public: |
| 70 | eof_illegal_exception(tape_block * block); |
| 71 | }; |
| 72 | |
| 73 | /*! |
| 74 | *\brief EOF after reading block exception. |
| 75 | */ |
| 76 | class eof_legal_exception |
| 77 | : public exception { |
| 78 | public: |
| 79 | eof_legal_exception(int bytes_consumed); |
| 80 | int get_consumed(); |
| 81 | private: |
| 82 | int bytes_consumed; |
| 83 | tape_block * get_block(); |
| 84 | }; |
| 85 | |
| 86 | /*! |
| 87 | *\brief IO error exception. |
| 88 | */ |
| 89 | class io_error_exception |
| 90 | : exception { |
| 91 | public: |
| 92 | io_error_exception(); |
| 93 | private: |
| 94 | tape_block * get_block(); |
| 95 | }; |
| 96 | |
| 97 | public: // methods |
| 98 | virtual ~tape_block(); |
| 99 | |
| 100 | tape_block(tape_block &); |
| 101 | void operator=(tape_block &); |
| 102 | |
| 103 | virtual int get_type(); |
| 104 | virtual int get_subtype(); |
| 105 | virtual vector<string> get_description(); |
| 106 | int get_raw_size(); |
| 107 | int get_discarded_bytes(); |
| 108 | unsigned char * get_raw_data(); |
| 109 | virtual int dump_to_fd(int fd); |
| 110 | virtual bool is_endblock(); |
| 111 | virtual vector<string> get_exported_symbols(); |
| 112 | virtual vector<string> get_called_symbols(); |
| 113 | virtual vector<string> dump_contents(); |
| 114 | virtual bool has_known_type(); |
| 115 | |
| 116 | static tape_block * gen_from_fd(int fd, |
| 117 | void(*input_start)(void *)=0, |
| 118 | void (*input_stop)(void *)=0, |
| 119 | void * start_stop_arg=0 |
| 120 | ); |
| 121 | |
| 122 | protected: // methods |
| 123 | tape_block(); |
| 124 | string get_typestring(); |
| 125 | |
| 126 | private: // methods |
| 127 | tape_block (int fd_p, |
| 128 | void(*input_start)(void *)=0, |
| 129 | void (*input_stop)(void *)=0, |
| 130 | void * start_stop_arg=0 |
| 131 | ); |
| 132 | |
| 133 | int init_words(void); |
| 134 | int test_checksum(); |
| 135 | |
| 136 | protected: // members |
| 137 | int block_type; //!< Type of this block. |
| 138 | bool m_has_known_type; //!< Block is of a documented type. |
| 139 | int discarded_bytes; //!< Amount of bytes discarded before beginning. |
| 140 | unsigned char * raw_data; //!< Raw block data in bytes. |
| 141 | int raw_size; //!< Size of the raw data. |
| 142 | unsigned short * word_data; //!< Data organized in machine words. |
| 143 | int word_size; //!< Size of the blocks in machine words. |
| 144 | int poolsize; //!< Amount of data malloc'ed |
| 145 | }; // class tape_block |
| 146 | |
| 147 | #endif |