added Parser::write() and output file name calculation logic

This commit is contained in:
Josh Holtrop 2010-04-27 13:40:20 -04:00
parent ed0754d4e7
commit 2cc33bde74
3 changed files with 33 additions and 5 deletions

View File

@ -1,8 +1,17 @@
#include "Parser.h"
#include <string>
#include <fstream>
using namespace std;
Parser::Parser()
{
}
void Parser::write(const string & fname)
{
ofstream ofs(fname.c_str());
ofs << "Content goes here" << endl;
ofs.close();
}

View File

@ -3,6 +3,7 @@
#define PARSER_H
#include <vector>
#include <string>
#include "refptr/refptr.h"
#include "TokenDefinition.h"
@ -20,6 +21,7 @@ class Parser
{
m_rules.push_back(rd);
}
void write(const std::string & fname);
protected:
std::vector< refptr< TokenDefinition > > m_tokens;

View File

@ -1,17 +1,19 @@
#include <getopt.h>
#include <iostream>
#include <fstream>
#include <getopt.h>
#include <iconv.h>
#include "refptr/refptr.h"
#include "parse-input.h"
using namespace std;
int main(int argc, char * argv[])
{
int longind = 1;
int opt;
const char * output_fname = "";
string output_fname;
static struct option longopts[] = {
/* name, has_arg, flag, val */
@ -29,8 +31,9 @@ int main(int argc, char * argv[])
}
}
string input_fname = argv[optind];
ifstream ifs;
ifs.open(argv[optind], ios::binary);
ifs.open(input_fname.c_str(), ios::binary);
if (!ifs.is_open())
{
cerr << "Error opening input file: '" << argv[optind] << "'";
@ -41,12 +44,26 @@ int main(int argc, char * argv[])
ifs.seekg(0, ios_base::beg);
char * buff = new char[size];
ifs.read(buff, size);
ifs.close();
Parser p;
parse_input(buff, size, p);
ifs.close();
if (output_fname == "")
{
size_t len = input_fname.length();
if (len > 2 && input_fname.substr(len - 2) == ".I")
{
output_fname = input_fname.substr(0, len - 2) + ".cc";
}
else
{
output_fname = input_fname + ".cc";
}
}
p.write(output_fname);
delete[] buff;
return 0;
}