History

core ejected

Ge Wang committed 9 years ago

Commit d38351c1 parent 74cf4d4158 files · +0 −196800Browse files

Showing the changes to src/scripts/hex2cpp.cpp (1 of 158 files). Show all

Unified · Split

src/scripts/hex2cpp.cpp+61−0
@@ -0,0 +1,61 @@
1+//-----------------------------------------------------------------------------
2+// name: hex2cpp.cpp
3+// desc: hexdump to cpp
4+//
5+// author: Ge Wang (gewang@cs.princeton.edu)
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+

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t