【更新】调整编译脚本和目录结构
This commit is contained in:
55
src/model2mem.cpp
Normal file
55
src/model2mem.cpp
Normal file
@@ -0,0 +1,55 @@
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <vector>
|
||||
using namespace std;
|
||||
|
||||
static int write_file(const std::string & fname, std::vector<char>& buf)
|
||||
{
|
||||
std::ofstream fs(fname, std::ios::binary | std::ios::out);
|
||||
if(!fs.good())
|
||||
{
|
||||
std::cerr<<fname<<" does not exist"<<std::endl;
|
||||
return -1;
|
||||
}
|
||||
for(char c : buf) {
|
||||
fs << (int)((unsigned char)c) << ",";
|
||||
}
|
||||
fs.close();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int load_file(const std::string & fname, std::vector<char>& buf)
|
||||
{
|
||||
std::ifstream fs(fname, std::ios::binary | std::ios::in);
|
||||
if(!fs.good())
|
||||
{
|
||||
std::cerr<<fname<<" does not exist"<<std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
fs.seekg(0, std::ios::end);
|
||||
int fsize=fs.tellg();
|
||||
|
||||
fs.seekg(0, std::ios::beg);
|
||||
buf.resize(fsize);
|
||||
fs.read(buf.data(),fsize);
|
||||
fs.close();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
if(argc < 3) {
|
||||
cout << "please input the model file and mem file name" << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
vector<char> content;
|
||||
load_file(argv[1], content);
|
||||
if(content.size() <= 0) {
|
||||
cout << "do not read any content" << endl;
|
||||
return -1;
|
||||
}
|
||||
write_file(argv[2], content);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user