1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238
|
/*=========================================================================
Program: GCC-XML
Module: $RCSfile: gxFront.cxx,v $
Language: C++
Date: $Date: 2004-08-26 18:16:26 $
Version: $Revision: 1.29 $
Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
See Copyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#include "gxConfiguration.h"
#include "gxFlagsParser.h"
#include "gxDocumentation.h"
#include <gxsys/Process.h>
int main(int argc, char** argv)
{
gxConfiguration configuration;
// Do initial configuration.
if(!configuration.Configure(argc, argv))
{
std::cerr << "Error during configuration. Aborting.\n";
return 1;
}
// Check for any simple flags.
if(configuration.GetManFlag())
{
gxDocumentation::PrintManPage(std::cout);
return 0;
}
if(configuration.GetCopyrightFlag())
{
gxDocumentation::PrintCopyright(std::cout);
return 0;
}
if(configuration.GetHelpHTMLFlag())
{
gxDocumentation::PrintHelpHTML(std::cout);
return 0;
}
if(configuration.GetHelpFlag())
{
gxDocumentation::PrintHelp(std::cout);
return 0;
}
if(configuration.GetVersionFlag())
{
std::cout << "GCC-XML version " GCCXML_VERSION_FULL "\n";
return 0;
}
// Find the GCCXML_FLAGS setting.
bool cfr = configuration.ConfigureFlags();
// Print the configuration if it was requested.
if(configuration.GetPrintFlag())
{
std::cout << "GCC-XML version " GCCXML_VERSION_FULL "\n";
configuration.PrintConfiguration(std::cout);
return cfr? 0:1;
}
// Check if there is anything to do.
if(configuration.GetArguments().empty())
{
std::cout << "GCC-XML version " GCCXML_VERSION_FULL "\n";
std::cout
<< "No arguments given for GCC C++ parser. Not running it.\n";
gxDocumentation::PrintUsage(std::cout);
return 0;
}
// We have something to do. Make sure the GCCXML_FLAGS setting is
// valid.
if(!cfr)
{
return 1;
}
// Get the configuration settings.
std::string cGCCXML_EXECUTABLE = configuration.GetGCCXML_EXECUTABLE();
std::string cGCCXML_CPP = configuration.GetGCCXML_CPP();
std::string cGCCXML_FLAGS = configuration.GetGCCXML_FLAGS();
std::string cGCCXML_USER_FLAGS = configuration.GetGCCXML_USER_FLAGS();
// Parse the flags.
gxFlagsParser parser;
parser.Parse(cGCCXML_FLAGS.c_str());
parser.Parse(cGCCXML_USER_FLAGS.c_str());
// Create the set of flags.
std::vector<std::string> flags;
configuration.AddArguments(flags);
parser.AddParsedFlags(flags);
// List set of flags if debugging.
if(configuration.GetDebugFlag())
{
if(configuration.GetPreprocessFlag())
{
std::cout << "Using \"" << cGCCXML_CPP.c_str()
<< "\" as GCC-XML preprocessor." << std::endl
<< "Using the following arguments to GCC-XML preprocessor:"
<< std::endl;
}
else
{
std::cout << "Using \"" << cGCCXML_EXECUTABLE.c_str()
<< "\" as GCC-XML executable." << std::endl
<< "Using the following arguments to GCC-XML executable:"
<< std::endl;
}
for(std::vector<std::string>::const_iterator i = flags.begin();
i != flags.end(); ++i)
{
std::cout << " \"" << i->c_str() << "\"" << std::endl;
}
}
// Select a program to run and make sure it is available.
std::string cge;
if(configuration.GetPreprocessFlag())
{
if(cGCCXML_CPP.length() == 0)
{
std::cerr << "Could not determine GCCXML_CPP setting.\n";
return 1;
}
cge = cGCCXML_CPP;
}
else
{
if(cGCCXML_EXECUTABLE.length() == 0)
{
std::cerr << "Could not determine GCCXML_EXECUTABLE setting.\n";
return 1;
}
cge = cGCCXML_EXECUTABLE;
}
#if defined(_WIN32) && !defined(__CYGWIN__) && !defined(GCCXML_NATIVE_CC1PLUS)
// Make sure a cygwin1.dll is available.
std::string cyg = gxSystemTools::GetFilenamePath(cGCCXML_EXECUTABLE.c_str());
cyg += "/cygwin1.dll";
if((!gxSystemTools::FileExists(cyg.c_str())) &&
(gxSystemTools::FindProgram("cygwin1.dll").length() == 0))
{
// There is no cygwin1.dll in the directory with gccxml_cc1plus or
// in the system search path. Look for a cygwin installation.
// The registry key to use to find cygwin.
const char* cygwinRegistry =
"HKEY_LOCAL_MACHINE\\SOFTWARE\\Cygnus Solutions\\Cygwin\\mounts v2\\/usr/bin;native";
if(gxSystemTools::ReadRegistryValue(cygwinRegistry, cyg) &&
gxSystemTools::FileExists((cyg+"/cygwin1.dll").c_str()))
{
// Found the cygwin /usr/bin directory with cygwin1.dll. Add it
// to the end of the system search path.
std::string path = "PATH=";
path += gxSystemTools::GetEnv("PATH");
if(path[path.length()-1] != ';')
{
path += ";";
}
path += cyg;
_putenv(path.c_str());
}
else
{
std::cerr << "GCC-XML cannot find cygwin1.dll, so " << cge.c_str()
<< " will fail to run. Aborting.\n";
return 1;
}
}
#endif
// Prepare list of arguments for exec call.
std::vector<const char*> args;
args.push_back(cge.c_str());
for(unsigned int i=0; i < flags.size(); ++i)
{
args.push_back(flags[i].c_str());
}
args.push_back(0);
// Run the patched GCC C++ parser.
gxsysProcess* gp = gxsysProcess_New();
gxsysProcess_SetPipeShared(gp, gxsysProcess_Pipe_STDOUT, 1);
gxsysProcess_SetPipeShared(gp, gxsysProcess_Pipe_STDERR, 1);
gxsysProcess_SetCommand(gp, &*args.begin());
gxsysProcess_Execute(gp);
gxsysProcess_WaitForExit(gp, 0);
int result = 1;
switch(gxsysProcess_GetState(gp))
{
case gxsysProcess_State_Exited:
{
result = gxsysProcess_GetExitValue(gp);
} break;
case gxsysProcess_State_Error:
{
std::cerr << "Error: Could not run " << cge.c_str() << ":\n";
std::cerr << gxsysProcess_GetErrorString(gp) << "\n";
} break;
case gxsysProcess_State_Exception:
{
std::cerr << "Error: " << cge.c_str()
<< " terminated with an exception: "
<< gxsysProcess_GetExceptionString(gp) << "\n";
} break;
case gxsysProcess_State_Starting:
case gxsysProcess_State_Executing:
case gxsysProcess_State_Expired:
case gxsysProcess_State_Killed:
{
// Should not get here.
std::cerr << "Unexpected ending state after running " << cge.c_str()
<< std::endl;
} break;
}
gxsysProcess_Delete(gp);
return result;
}
|