2002-08-11 05:56:25 +00:00
|
|
|
///////////////////////////////////////////////////////////////
|
|
|
|
//Generates forwarding headers using the information
|
|
|
|
//in the header.lst & vendor.lst files
|
|
|
|
//
|
|
|
|
//To create a header list from an existing directory of headers
|
|
|
|
//dir *.h /b > headers.lst
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <fstream>
|
|
|
|
#include <string>
|
|
|
|
#include <sstream>
|
|
|
|
#include <vector>
|
2002-08-29 05:54:43 +00:00
|
|
|
#include <ctime>
|
2002-08-11 05:56:25 +00:00
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
struct Compiler
|
|
|
|
{
|
|
|
|
Compiler() {}
|
|
|
|
Compiler(const string& VersionTest, const string& SubDir) :
|
|
|
|
version_test(VersionTest), subdir(SubDir)
|
|
|
|
{}
|
|
|
|
string version_test;
|
|
|
|
string subdir;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef vector<Compiler> cv_t;
|
|
|
|
|
|
|
|
int main(int argc, char* argv[])
|
|
|
|
{
|
|
|
|
if(argc < 2)
|
|
|
|
{
|
2002-09-08 22:43:44 +00:00
|
|
|
cout <<"Usage: <Header List> [Version/Vendor List]"<<endl;
|
2002-08-11 05:56:25 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
cv_t vendors;
|
|
|
|
char buf[1024];
|
|
|
|
string check;
|
|
|
|
string subdir;
|
|
|
|
fstream vendor_file;
|
|
|
|
if(argc >= 3)
|
|
|
|
{
|
|
|
|
vendor_file.open(argv[2], ios::in);
|
|
|
|
if(!vendor_file.is_open())
|
|
|
|
{
|
|
|
|
cout << "Unable to open vendor file: " << argv[2] << endl;
|
|
|
|
return -2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
vendors.reserve(10);
|
|
|
|
while(!vendor_file.eof())
|
|
|
|
{
|
|
|
|
check = "";
|
|
|
|
subdir = "";
|
|
|
|
vendor_file.getline(buf, 1024, '\n');
|
|
|
|
check = buf;
|
|
|
|
vendor_file.getline(buf, 1024, '\n');
|
|
|
|
subdir = buf;
|
|
|
|
vendor_file.getline(buf, 1024, '\n');
|
|
|
|
if(!(check.empty() || subdir.empty()))
|
|
|
|
vendors.push_back(Compiler(check, subdir));
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cout << "Error parsing vendors, check:" << check << "\tsubdir:" << subdir << endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else //if(vendors.empty())
|
|
|
|
{
|
2002-08-29 05:54:43 +00:00
|
|
|
cout << "No vendor file provided, using defaults\n";
|
2002-08-11 05:56:25 +00:00
|
|
|
vendors.reserve(10);
|
|
|
|
vendors.push_back(Compiler("(_MSC_VER >= 1300)", "MSVC\\1300"));
|
2002-08-29 05:54:43 +00:00
|
|
|
vendors.push_back(Compiler("(__BORLANDC__)", "Borland"));
|
|
|
|
vendors.push_back(Compiler("( (__GNUC__ > 2) || ((__GNUC__ == 2) && (__GNUC_MINOR__ > 95)) )", "Reference"));
|
2002-08-11 05:56:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fstream header_list(argv[1]);
|
|
|
|
string header;
|
|
|
|
stringstream ss;
|
|
|
|
|
|
|
|
if(!header_list.is_open())
|
|
|
|
{
|
|
|
|
cout << "Invalid header list file, " << argv[1] << endl;
|
|
|
|
return -3;
|
|
|
|
}
|
|
|
|
while(!header_list.eof())
|
|
|
|
{
|
|
|
|
header_list >> header;
|
|
|
|
cout << header << endl;
|
|
|
|
fstream header_file(header.c_str(), ios::out);
|
|
|
|
if(!header_file.is_open())
|
|
|
|
{
|
|
|
|
cout << "Unable to open header file for output: " << header << endl;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ss.str("");
|
|
|
|
ss << "//Generated header: " << header << endl;
|
|
|
|
size_t n = ss.str().size();
|
|
|
|
for(size_t i=0; i<n; ++i)
|
|
|
|
header_file << "/";
|
|
|
|
header_file << endl;
|
|
|
|
header_file << ss.str();
|
2002-08-29 05:54:43 +00:00
|
|
|
header_file << "//Forwards to the appropriate code\n";
|
|
|
|
header_file << "// that works on the detected compiler\n";
|
|
|
|
time_t rawtime; time(&rawtime);
|
|
|
|
header_file << "//Generated on " << ctime(&rawtime);
|
2002-08-11 05:56:25 +00:00
|
|
|
header_file << endl << endl;
|
|
|
|
|
|
|
|
cv_t::iterator it=vendors.begin(), itEnd = vendors.end();
|
|
|
|
|
2002-08-29 05:54:43 +00:00
|
|
|
header_file << "#ifdef LOKI_USE_REFERENCE\n";
|
2002-09-04 02:46:49 +00:00
|
|
|
header_file << "#\tinclude \"./Reference/" << header << "\"\n";
|
|
|
|
//header_file << "#\tinclude \".\\Reference\\" << header << "\"\n";
|
2002-08-29 05:54:43 +00:00
|
|
|
header_file << "#else\n";
|
2002-08-11 05:56:25 +00:00
|
|
|
|
|
|
|
header_file << "#\tif " << it->version_test << endl;
|
2002-09-04 02:46:49 +00:00
|
|
|
//header_file << "#\t\tinclude \".\\" << it->subdir;
|
|
|
|
header_file << "#\t\tinclude \"./" << it->subdir;
|
|
|
|
//header_file << "\\" << header << "\"\n";
|
|
|
|
header_file << "/" << header << "\"\n";
|
2002-08-11 05:56:25 +00:00
|
|
|
++it;
|
|
|
|
for(; it!=itEnd; ++it)
|
|
|
|
{
|
2002-08-29 05:54:43 +00:00
|
|
|
header_file << "#\telif " << it->version_test << endl;
|
2002-09-04 02:46:49 +00:00
|
|
|
//header_file << "#\t\tinclude \".\\" << it->subdir;
|
2002-09-08 22:43:44 +00:00
|
|
|
header_file << "#\t\tinclude \"./" << it->subdir;
|
2002-09-04 02:46:49 +00:00
|
|
|
//header_file << "\\" << header << "\"\n";
|
|
|
|
header_file << "/" << header << "\"\n";
|
2002-08-11 05:56:25 +00:00
|
|
|
}
|
2002-08-29 05:54:43 +00:00
|
|
|
header_file << "#\telse\n";
|
|
|
|
header_file << "\t\t//Define LOKI_USE_REFERENCE and get back to us on the results\n";
|
|
|
|
header_file << "#\t\terror Compiler not tested with Loki, #define LOKI_USE_REFERENCE\n";
|
|
|
|
header_file << "#\tendif\n";
|
|
|
|
header_file << "#endif\n";
|
2002-08-11 05:56:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
system("PAUSE");
|
|
|
|
#endif
|
|
|
|
return 0;
|
2002-09-04 02:46:49 +00:00
|
|
|
}
|