| 1 | //----------------------------------------------------------------------------- |
| 2 | // name: hex2cpp.cpp |
| 3 | // desc: hexdump to cpp |
| 4 | // |
| 5 | // author: Ge Wang ([email protected]) |
| 6 | // data: Summer 2004 |
| 7 | //----------------------------------------------------------------------------- |
| 8 | #include <iostream> |
| 9 | #include <sstream> |
| 10 | #include <stdio.h> |
| 11 | #include <limits.h> |
| 12 | using namespace std; |
| 13 | |
| 14 | |
| 15 | // one of these days i will learn perl, or awk, or sed |
| 16 | int main( int argc, char ** argv ) |
| 17 | { |
| 18 | if( argc < 2 ) |
| 19 | { |
| 20 | cerr << "hex2cpp: too few arguments..." << endl; |
| 21 | exit( 1 ); |
| 22 | } |
| 23 | |
| 24 | string line; |
| 25 | int count = 0; |
| 26 | cout << "// data for " << argv[1] << ".raw..." << endl; |
| 27 | cout << "SAMPLE " << argv[1] << "_data[] = {" << endl; |
| 28 | |
| 29 | while( getline( cin, line ) ) |
| 30 | { |
| 31 | istringstream sin( line ); |
| 32 | string token, token2; |
| 33 | int c = 0; |
| 34 | short x = 0; |
| 35 | |
| 36 | // get rid of offset |
| 37 | sin >> token; |
| 38 | cout << " "; |
| 39 | |
| 40 | while( sin >> token >> token2 ) |
| 41 | { |
| 42 | x = (token2[0]-'0')*64 + (token2[1]-'0')*8 + (token2[2]-'0'); |
| 43 | x <<= 8; |
| 44 | x += (token[0]-'0')*64 + (token[1]-'0')*8 + (token[2]-'0'); |
| 45 | printf( "%.1ff,", (float)x ); |
| 46 | count++; |
| 47 | c++; |
| 48 | } |
| 49 | |
| 50 | if( c ) |
| 51 | cout << endl; |
| 52 | } |
| 53 | |
| 54 | cout << "0" << endl; |
| 55 | cout << "}; "; |
| 56 | cout << argv[1] << "_size = " << count << ";"; |
| 57 | cout << endl << endl; |
| 58 | |
| 59 | return 0; |
| 60 | } |
| 61 |