monotone

monotone Mtn Source Tree

Root/txt2c.cc

1#include <iostream>
2#include <fstream>
3#include <string>
4
5using namespace std;
6int main(int argc, char **argv)
7{
8 if (argc != 3)
9 {
10 cerr << "usage: " << argv[0] << " <filename> <arrayname> " << endl;
11 exit(1);
12 }
13
14 ifstream fin(argv[1]);
15 string arr(argv[2]);
16
17 if (!fin)
18 {
19 cerr << "could not open " << argv[1] << " for reading" << endl;
20 exit(1);
21 }
22
23 char c;
24 string dat;
25 while(fin.get(c))
26 dat += c;
27
28 cout << "// DO NOT EDIT\n"
29 << "// this file is automatically generated from " << argv[1] << ",\n"
30 << "// any changes you make will be destroyed when it is regenerated\n"
31 << "\n\n"
32 << "static char const " << arr << "_constant[" << (dat.size() + 1) << "] = {\n";
33
34 for (unsigned int i = 0; i < dat.size(); ++i)
35 {
36 if (i == 0) cout << "\t";
37 else if (i % 20 == 0) cout << ",\n\t";
38 else cout << ", ";
39 cout << static_cast<int>(dat[i]);
40 }
41 cout << ", 0\n};\n";
42}

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status