00001
#include "MakeCSE_ExecutionT.h"
00002
#include "MakeCSE_FEManager.h"
00003
#include "ExceptionT.h"
00004
#include "ifstreamT.h"
00005
00006
using namespace Tahoe;
00007
00008 MakeCSE_ExecutionT::MakeCSE_ExecutionT (
void) :
00009 fProgram ("
MakeCSE"),
00010 fVersion ("v5.1 (Oct 2002)"),
00011 fInteractive (true)
00012 {
00013 cout <<
"\n Welcome to: " <<
fProgram <<
" " <<
fVersion;
00014 cout <<
"\n\n Build Date: " << __DATE__
" " << __TIME__ <<
"\n\n";
00015 }
00016
00017 void MakeCSE_ExecutionT::Run (
const sArrayT& lineoptions)
00018 {
00019
int index;
00020 lineoptions.
HasValue (
"-f", index);
00021
if (index > 0 && index < lineoptions.
Length())
00022 {
00023
ifstreamT in (
'#', lineoptions [index + 1]);
00024
if (!in.
is_open ())
00025 cout <<
"\n Unable to open -f file: " << lineoptions [index + 1] << endl;
00026
else
00027 {
00028
fInteractive =
false;
00029
RunBatchOrJob (in);
00030 }
00031 }
00032
else
00033
RunInteractive ();
00034 }
00035
00036
00037
00038 void MakeCSE_ExecutionT::RunInteractive (
void)
00039 {
00040
bool done =
false;
00041
while (!done)
00042 {
00043
StringT answer;
00044 cout <<
"\nEnter input file name: \n"
00045 <<
"(\"quit\" to exit or \"interactive\"): ";
00046 cin >> answer;
00047
00048
if (answer ==
"quit")
00049 {
00050 done =
true;
00051 }
00052
else if (answer ==
"interactive")
00053 {
00054
fInteractive =
true;
00055
ifstreamT in (
'#');
00056
RunJob (in);
00057 }
00058
else
00059 {
00060
fInteractive =
false;
00061
ifstreamT in (
'#', answer);
00062
if (!in.
is_open())
00063 cout <<
"\n Unable to open: " << answer << endl;
00064
else
00065
RunBatchOrJob (in);
00066 }
00067 }
00068 }
00069
00070 void MakeCSE_ExecutionT::RunBatchOrJob (
ifstreamT& in)
00071 {
00072
char filetype;
00073 in >> filetype;
00074
00075
if (filetype ==
'@')
00076 {
00077 cout <<
"\n\n\n Reading from batch file: " << in.
filename () <<
"\n";
00078
StringT nextfile;
00079 in >> nextfile;
00080
00081
while (in.good())
00082 {
00083
00084
00085
StringT path;
00086 path.
FilePath (in.
filename());
00087 nextfile.
Prepend (path);
00088
00089
ifstreamT in2 (
'#', nextfile);
00090
if (in2.good())
00091
RunBatchOrJob (in2);
00092
else
00093 {
00094 cout <<
"\n Error in batchfile: " << in.
filename ();
00095 cout <<
"\n Unable to open: " << nextfile << endl;
00096
return;
00097 }
00098 in >> nextfile;
00099 }
00100 }
00101
else if (filetype ==
'%')
00102
RunJob (in);
00103
else
00104 {
00105 cout <<
"\n Unrecognized file type character: " << filetype << endl;
00106
return;
00107 }
00108 }
00109
00110 void MakeCSE_ExecutionT::RunJob (
ifstreamT& in)
00111 {
00112
StringT outfile (81);
00113
if (
fInteractive)
00114 {
00115 cout <<
"\n Enter log file: ";
00116 cin >> outfile;
00117
StringT line (81);
00118 cin.getline (line.
Pointer(), 80,
'\n');
00119 }
00120
else
00121 {
00122 outfile = in.
filename();
00123 outfile.
Root();
00124 outfile.
Append (
".out");
00125 }
00126
00127 cout <<
"\n\n Running Job: " << in.
filename() <<
"\n\n";
00128 ofstream
log (outfile);
00129
log <<
"\n Welcome to: " <<
fProgram <<
" " <<
fVersion;
00130
log <<
"\n\n Build Date: " << __DATE__
" " << __TIME__ <<
"\n\n";
00131
00132
try
00133 {
00134
MakeCSE_FEManager maker (
log);
00135
00136
00137 maker.
InitializeInput (in,
fInteractive);
00138
00139
00140 maker.
InitializeOutput (in.
filename(),
fProgram, fVersion);
00141
00142
00143 maker.
CreateCSE ();
00144
00145
00146 maker.
WriteOutput ();
00147 }
00148
catch (ExceptionT::CodeT code)
00149 {
00150
ExceptionT temp;
00151 cout <<
"\n \"" << in.
filename() <<
"\" exit on exception: "
00152 << code <<
": " << temp.
ToString(code) <<
"\n\n";
00153
log <<
"\n \"" << in.
filename() <<
"\" exit on exception: "
00154 << code <<
": " << temp.
ToString(code) <<
"\n\n";
00155 }
00156 }