netgen/rules/makerlsfile.cpp

70 lines
1.2 KiB
C++
Raw Permalink Normal View History

#include <stdlib.h>
#include <iostream>
#include <fstream>
2021-04-30 14:25:31 +05:00
#include <string>
using namespace std;
#define maxlen 1000
int main (int argc, char ** argv)
{
if (argc != 4)
{
cout << "use: makerlsfile infile outfile rulename" << endl;
exit(1);
}
2023-08-05 15:01:01 +05:00
char line[maxlen]; // , infile[maxlen], outfile[maxlen];
char ch;
2023-08-05 15:01:01 +05:00
int i;
/*
cout << "infile: ";
cin >> infile;
cout << "outfile: ";
cin >> outfile;
*/
ifstream inf (argv[1]);
ofstream outf (argv[2]);
string rulename = argv[3];
outf << "namespace netgen" << endl << '{' << endl;
outf << "const char * " << rulename << "[] = {" << endl;
while (inf.good())
{
i = 0;
inf.get(ch);
while (ch != '\n' && inf.good() && i < maxlen)
{
if (ch == '\"')
{
line[i] = '\\';
line[i+1] = '\"';
i+= 2;
}
else if (ch == '\\')
{
line[i] = '\\';
line[i+1] = '\\';
i+= 2;
}
else
{
line[i] = ch;
i++;
}
inf.get(ch);
}
line[i] = 0;
// cout << line << endl;
outf << "\"" << line << "\\n\",\\" << endl;
}
outf << "0};" << endl;
outf << '}' << endl;
return 0;
}