int main()

in src/xalanc/Utils/MsgCreator/MsgCreator.cpp [325:511]


int main(int argC, char* argV[])
{
    
#if defined(XALAN_CRT_DEBUG)
    _CrtSetDbgFlag(_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG) | _CRTDBG_LEAK_CHECK_DF);
    
    _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE);
    _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);
#endif

    using namespace xalanc;

    CmdLineParams   theParams;

    int iReturnValue = 0;

    const char*     errorMessage = 0;

    if (getArgs(argC, argV, theParams, &errorMessage) == false)
    {
        if ( errorMessage != 0)
        {
            cerr << errorMessage;
        }

        usage();

        iReturnValue = 1;
    }
    else
    {
        try
        {
            XMLPlatformUtils::Initialize();
        }
        catch (const XMLException& toCatch)
        {
            cerr << "Error during initialization! : "
                << StrX(toCatch.getMessage()) << endl;

            iReturnValue = 2;
        }

        if (iReturnValue == 0)
        {
            
            {   //  Create a SAX parser object. 
                SAX2XMLReader* const    parser =
                    XMLReaderFactory::createXMLReader();

                parser->setFeature(XMLUni::fgSAX2CoreValidation, false);

                parser->setFeature(XMLUni::fgXercesDynamic, true);

                parser->setFeature(XMLUni::fgSAX2CoreNameSpaces, false);

                parser->setFeature(XMLUni::fgXercesSchema, true);

                parser->setFeature(XMLUni::fgXercesSchemaFullChecking, false);

                parser->setFeature(XMLUni::fgSAX2CoreNameSpacePrefixes, false);
                

                //  Create the handler object and install it as the document and error
                //  handler for the parser. Then parse the file and catch any exceptions
                //  that propogate out
                //
                XalanSize_t errorCount = 0;

                const char* const   fileName = theParams.inXMLFileName;

                char    OutputFileName[s_max_path];
                char    IndexFileName[s_max_path];

                buildOutputFileName(theParams, OutputFileName);
                buildIndexFileName(theParams, IndexFileName);

                SAX2Handler* handler = 0;

                try
                {
                    switch(theParams.enTypeOfLocaleMsg){
                    case CmdLineParams::ICU_LOCALMSG:
                        {
                            handler = new ICUResHandler(OutputFileName, IndexFileName);
                            break;
                        }
                    case CmdLineParams::INMEM_LOCALMSG:
                        {
                            handler = new InMemHandler(OutputFileName, IndexFileName);
                            break;
                        }
                    case CmdLineParams::NLS_LOCALMSG:
                        {
                            handler = new NLSHandler(OutputFileName, IndexFileName);
                            break;
                        }
                    default:
                        {
                            assert (0);
                        }
                    }
                }
                catch(const MsgFileOutputStream::OpenException&     e)
                {
                    cerr << "\nAn error occurred\n  Error: ";

                    if (e.m_message != 0)
                    {
                        cerr << e.m_message <<  endl;
                    }
                    else
                    {
                        cerr << "unknown (XalanFileOutputStreamOpenException) "  << endl;
                    }

                    iReturnValue = 4;   
                }
                catch(const MsgFileOutputStream::WriteException&    e)
                {
                    cerr << "\nAn error occurred\n  Error: ";

                    if (e.m_message != 0)
                    {
                        cerr << e.m_message << endl;
                    }
                    else
                    {
                        cerr << "unknown (MsgFileOutputStream::WriteException) " <<  endl;
                    }

                    iReturnValue = 5;   
                }
                catch (...)
                {
                    cerr << "Unknown error occured." << endl;

                    iReturnValue = 6;
                }

                // run the parser
                if (iReturnValue == 0)
                {
                    try
                    {               
                        handler->setLocale(theParams.localeName);

                        parser->setContentHandler(handler);

                        parser->setErrorHandler(handler);

                        parser->parse(fileName);

                        errorCount = parser->getErrorCount();
                    }
                    catch (const XMLException& toCatch)
                    {
                        cerr << "\nAn error occurred\n  Error: "
                            << StrX(toCatch.getMessage()) << endl;

                        iReturnValue = 7;
                    }
                    catch (...)
                    {   
                        cerr << endl << "General error occured." << endl;
                        iReturnValue = 8;
                    }
                }

                delete handler;

                //
                //  Delete the parser itself.  Must be done prior to calling Terminate, below.
                //
                delete parser;

                if (errorCount != 0)
                    iReturnValue = 9;
            }

            // And call the termination method
            XMLPlatformUtils::Terminate();
        }
    }

    return iReturnValue;
}