-
Notifications
You must be signed in to change notification settings - Fork 74
/
Copy pathgenerate_add_callback_symbols.cc
43 lines (41 loc) · 1.17 KB
/
generate_add_callback_symbols.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <vector>
#include <iostream>
#include <sstream>
#include <fstream>
using namespace std;
int main(int argc, char *argv[]) {
string sfile = argv[1];
ifstream cfile(sfile.c_str());
vector<string> handlers;
string shandler;
string sprefix = "on_";
if(cfile.is_open()) {
string sbuffer;
while((cfile.rdstate() & std::ifstream::eofbit) == 0) {
std::getline(cfile, sbuffer);
for(size_t argi = 2; argi == 2 || argi < argc; argi++) {
if(argc > argi) sprefix = argv[argi];
string ssearch = "handler=\"";
ssearch += sprefix;
size_t i = sbuffer.find(ssearch);
if(i != string::npos) {
i += 9;
size_t i2 = sbuffer.find("\"", i);
shandler = sbuffer.substr(i, i2 - i);
bool b = false;
for(size_t i = 0; i < handlers.size(); i++) {
if(handlers[i] == shandler) {b = true; break;}
}
if(!b) handlers.push_back(shandler);
}
}
}
cfile.close();
}
cout << "gtk_builder_add_callback_symbols(" << sfile.substr(0, sfile.length() - 3) << "_builder" << ", ";
for(size_t i = 0; i < handlers.size(); i++) {
cout << "\"" << handlers[i] << "\", " << "G_CALLBACK(" << handlers[i] << "), ";
}
cout << "NULL);" << endl;
return 0;
}