Changeset 40 in projects
- Timestamp:
- Aug 25, 2009, 5:16:00 AM (15 years ago)
- Location:
- punch-card/lib
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
punch-card/lib/card.cc
r39 r40 29 29 out[0] 30 30 }*/ 31 } 32 33 bool Punch::Card::read(CardFormat format, std::istream& is) { 34 if(format == JONES_FORMAT) { 35 // At first, check the file prefix (magic bytes) 36 int char1 = is.get(); 37 int char2 = is.get(); 38 int char3 = is.get(); 39 if( (char1 == 'H') && (char2 == '8') && (char3 == '0') ) { 40 this.default_col_length = 80; 41 } else if ((char1 == 'H') && (char2 == '8') && (char3 == '2')) { 42 this.default_col_length = 82; 43 } else { 44 // Fehler spezifizieren...: 45 // Input file not a card file 46 return false; 47 } 48 49 // Process card deck 50 while( !is.eof() ) { 51 Punch::Card cur_card; 52 53 // Check header on card 54 int head1 = is.get(); 55 // check on EOF 56 if( is.eof() ) break; 57 58 // from now on, there may not be EOF 59 // until the end of the card 60 int head2 = is.get(); 61 int head3 = is.get(); 62 63 if( ((head1 & 0x08) == 0) 64 || ((head2 & 0x08) == 0) 65 || ((head3 & 0x08) == 0) 66 || is.eof() ) { 67 // Input corrupt (header corrupted) 68 return false 69 } 70 71 int cur_col, max_col; 72 /* The colum boundaries (depending on card format) */ 73 if(this.default_col_length == 80) { 74 cur_col = 1; 75 max_col = 80; 76 } else { /* ... == 82 */ 77 cur_col = 0; 78 max_col = 81; 79 } 80 81 /* This algorithm is based on the C algorithm 82 of Jones */ 83 while(cur_col < max_col) { 84 /* read in 3 bytes */ 85 int first = is.get(); 86 int second = is.get(); 87 int third = is.get(); 88 89 /* convert to 2 columns */ 90 int even_col = (first << 4) | (second >> 4); 91 int odd_col = ((second & 0017) << 8) | third; 92 93 /* save the columns in the card */ 94 cur_card[cur_col++] = even_col; 95 cur_card[cur_col++] = odd_col; 96 } 97 98 /* push card on the card deck*/ 99 this.cards.push_back(current); 100 } // while ! eof 101 } // if format == JONES 31 102 } 32 103 -
punch-card/lib/card.h
r39 r40 57 57 static const int word_length = 12; 58 58 Punch::CardBit bits[ word_length ]; 59 60 CardWord(int value) { 61 for(s=0; s<word_length; s++) { 62 set(s, (value << s) & 0x01); 63 } 64 } 65 59 66 60 67 // getters and setters … … 122 129 } 123 130 131 // cast word => int 132 operator int() const { 133 int ret = 0; 134 for(int s=0; s<word_length; s++) { 135 ret |= get(s) << s; 136 } 137 } 124 138 }; // class CardWord 125 /*126 class CardWordIterator {127 int current_index;128 CardWord* card;129 130 CardWordIterator next();131 CardWordIterator previous();132 }133 */134 139 135 140 class Card { … … 162 167 class CardFile { 163 168 public: 169 int default_col_length = 80; 170 164 171 public list<Punch::Card> cards; 165 172 void write(CardFormat format, std::ostream& os);
Note: See TracChangeset
for help on using the changeset viewer.