Commit c2cf08bb authored by rdubner's avatar rdubner

Make GetParameters a PARAMETERS method to avoid copy initialization of ifstream and ofstream

parent 6889ea65
......@@ -130,7 +130,7 @@ CreateSymc(PARAMETERS &params,
ss << "\"" << s << "\"" << endl;
}
ss << ";" << endl << endl;
*params.symc << ss.str();
params.symc << ss.str();
ss.str("");
bool in_copyright = true;
......@@ -201,40 +201,40 @@ CreateSymc(PARAMETERS &params,
s = ss.str();
*params.symc << "asm(" << endl;
*params.symc << "\".pushsection \\\".debug_gdb_scripts\\\", \\\"MS\\\",@progbits,1\\n\"" << endl;
*params.symc << "\".byte 4\\n\"" << endl;
*params.symc << "\".ascii \\\"gdb.inlined-script\\\\n\\\"\\n\"";
params.symc << "asm(" << endl;
params.symc << "\".pushsection \\\".debug_gdb_scripts\\\", \\\"MS\\\",@progbits,1\\n\"" << endl;
params.symc << "\".byte 4\\n\"" << endl;
params.symc << "\".ascii \\\"gdb.inlined-script\\\\n\\\"\\n\"";
int char_count = 0;
size_t i = 0;
while( i < s.size() ) {
if(char_count EQ 0) {
*params.symc << "\".ascii \\\"";
params.symc << "\".ascii \\\"";
char_count = 10 ;
}
if( char_count >= 120 ) {
*params.symc << "\"" << endl << "\"";
params.symc << "\"" << endl << "\"";
char_count = 1;
continue;
}
char ch = s[i++];
if( ch EQ '\n' ) {
*params.symc << "\\\\n\\\"\\n\"" << endl;
params.symc << "\\\\n\\\"\\n\"" << endl;
char_count = 0;
continue;
}
if( ch EQ '\\' OR ch EQ '\"' ) {
*params.symc << "\\\\\\";
params.symc << "\\\\\\";
char_count += 1;
}
*params.symc << ch;
params.symc << ch;
char_count += 1;
}
*params.symc << "\".byte 0\\n\"" << endl;
*params.symc << "\".popsection\\n\"" << endl;
*params.symc << ");" << endl;
params.symc << "\".byte 0\\n\"" << endl;
params.symc << "\".popsection\\n\"" << endl;
params.symc << ");" << endl;
}
return;
}
......@@ -245,7 +245,8 @@ main(int argc, char *argv[])
PROFILER;
// Decode the command line for our purposes.
PARAMETERS params = GetParameters(argc, argv);
PARAMETERS params;
params.GetParameters(argc, argv);
if(!params.quiet) {
cout << "cobst version " << VERSION << endl;
}
......@@ -273,7 +274,7 @@ main(int argc, char *argv[])
// a normalized rendition of the parsed STORAGE sections. We read that
// in, and build a COBOL identifier tree based on the various storage
// sections and the COBOL 77 01 02 03 data heirarchy.
variable_tree.ReadFromFile(*params.cbl_lst);
variable_tree.ReadFromFile(params.cbl_lst);
variable_tree.BuildCanonicalName();
#if defined(DUMPING)
//variable_tree.Dump();
......@@ -289,7 +290,7 @@ main(int argc, char *argv[])
);
// Scan the .c file for program identification and linkage information.
ScanForLinkage(*params.c,
ScanForLinkage(params.c_file,
params.c_filename.GetFname(),
program_labels,
cob_data,
......
......@@ -232,23 +232,22 @@ OpenOrFail(std::ofstream &ofs,const std::string &fname,std::ios_base::openmode m
}
}
PARAMETERS
GetParameters(int argc, char *argv[])
void
PARAMETERS::GetParameters(int argc, char *argv[])
{
if(argc < 2) {
Usage();
exit(1);
}
PARAMETERS retval;
retval.quiet = false;
quiet = false;
string input_parameter;
int c;
while ((c = getopt (argc, argv, "qv")) != -1) {
switch (c) {
case 'q':
retval.quiet = true;
quiet = true;
break;
case 'v':
cerr << "cobst: Cobol Symbol Table generator version: "
......@@ -266,18 +265,17 @@ GetParameters(int argc, char *argv[])
}
input_parameter = argv[optind];
retval.c_filename.Decode(input_parameter);
retval.basename = retval.c_filename.GetFname();
retval.c_filename.Decode(retval.c_filename.Stem() + ".c");
retval.cbl_lst_filename.Decode(retval.c_filename.Stem() + ".cbl.lst");
retval.symc_filename.Decode(retval.c_filename.Stem() + ".sym.c");
c_filename.Decode(input_parameter);
basename = c_filename.GetFname();
c_filename.Decode(c_filename.Stem() + ".c");
cbl_lst_filename.Decode(c_filename.Stem() + ".cbl.lst");
symc_filename.Decode(c_filename.Stem() + ".sym.c");
//OpenOrFail(retval.cbl,retval.cbl_filename.WholePath());
OpenOrFail(*retval.c,retval.c_filename.WholePath());
OpenOrFail(*retval.cbl_lst,retval.cbl_lst_filename.WholePath());
OpenOrFail(*retval.symc,retval.symc_filename.WholePath());
OpenOrFail(c_file,c_filename.WholePath());
OpenOrFail(cbl_lst,cbl_lst_filename.WholePath());
OpenOrFail(symc,symc_filename.WholePath());
return retval;
}
vector<string>
......
......@@ -118,11 +118,13 @@ public:
FILENAME symc_filename; // The source file for the .debug_gdb_scrips
// //
std::ifstream *cbl_lst;
std::ifstream *c;
std::ofstream *symc;
std::ifstream cbl_lst;
std::ifstream c_file;
std::ofstream symc;
bool quiet;
void GetParameters(int argc, char *argv[]);
};
std::vector<std::string> DirectoryScan(const std::string &path,
......@@ -134,4 +136,3 @@ void OpenOrFail(std::ifstream &ifs,
void OpenOrFail(std::ofstream &ofs,
const std::string &fname,
std::ios_base::openmode mode = std::ofstream::out);
PARAMETERS GetParameters(int argc, char *argv[]);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment