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