src/Generic/commandLineInterface/CommandLineInterface.cpp
//=======================================================================
/** Run the standard SERIF command-line interface.  This is typically 
  * called by the main() method of each language-specific binary (such
  * as Serif_English/EnglishSerif.cpp). */
Run the standard SERIF command-line interface.  This is typically
called by the main() method of each language-specific binary (such
as Serif_English/EnglishSerif.cpp).
Run the standard SERIF command - line interface . This is typically called by the main () method of each language - specific binary ( such as Serif_English / EnglishSerif . cpp ) .
int runSerifFromCommandLine(int argc, const char **argv) {
	initializeLeakDetection();
	UTF8InputStream::startTrackingFileOpens();
	try {
		GenericTimer totalLoadTimer;
		totalLoadTimer.startTimer();
		string parfile;
		map<string,string> overrides;
		vector<string> unsets;
		string outdir;
		int verbosity;
		if (!parseCommandLine(argc, argv, parfile, overrides, unsets, outdir, verbosity))
			return -1;
		initializeParameters(parfile, overrides, unsets, verbosity);
		int open_file_retries = ParamReader::getOptionalIntParamWithDefaultValue("open_file_retries", 0);
		if (open_file_retries > 0)
			UTF8InputStream::setOpenFileRetries(open_file_retries);
		FeatureModule::load();
		if (verbosity < 0 || ParamReader::isParamTrue("run_subprocess_server"))
			quiet(outdir);
		displayVersionAndCopyright();
		if (!ParamReader::getOptionalTrueFalseParamWithDefaultVal("track_files_read", false))
			UTF8InputStream::stopTrackingFileOpens();
		BOOST_FOREACH(ModifyCommandLineHook_ptr hook, cliHooks()) {
			switch (hook->run(verbosity)) {
			case ModifyCommandLineHook::CONTINUE: continue;
			case ModifyCommandLineHook::SUCCESS: return 0;
			case ModifyCommandLineHook::FAILURE: return -1;
			case ModifyCommandLineHook::RESTART: restart(argc, argv);
			}
		}
		if (ParamReader::isParamTrue("run_tests")) {
			if (runTests() != 0) return -1;
		} else if (ParamReader::hasParam("queue_driver")) {
			std::string driverType = ParamReader::getParam("queue_driver");
			boost::scoped_ptr<QueueDriver> queueDriver(QueueDriver::build(driverType));
			queueDriver->processQueue();
		} else {
			runSerif(verbosity, totalLoadTimer);
		}
		BOOST_FOREACH(ModifyCommandLineHook_ptr hook, cliHooks()) {
			hook->cleanup(verbosity);
		}
	}
	catch (UnrecoverableException &e) {
		if (!e.isLogged())
			return reportError(e.getMessage(), e.getSource());
	}
	catch (exception &e) {
		return reportError(e.what());
	}
	catch (...) {
		return reportError("Unknown error");
	}
	xercesc::XMLPlatformUtils::Terminate();
	checkForLeaks();
	reportOpenedFiles();
	checkHeap("main(); About to exit after successful run");
	#ifdef _DEBUG
		cerr << "Press enter to exit..." << endl;
		getchar();
	#endif
	return 0;
}
int runSerifFromCommandLine ( int argc , const char * * argv ) { initializeLeakDetection ( ) ; UTF8InputStream :: startTrackingFileOpens ( ) ; try { GenericTimer totalLoadTimer ; totalLoadTimer . startTimer ( ) ; string parfile ; map < string , string > overrides ; vector < string > unsets ; string outdir ; int verbosity ; if ( ! parseCommandLine ( argc , argv , parfile , overrides , unsets , outdir , verbosity ) ) return -1 ; initializeParameters ( parfile , overrides , unsets , verbosity ) ; int open_file_retries = ParamReader :: getOptionalIntParamWithDefaultValue ( " " , 0 ) ; if ( open_file_retries > 0 ) UTF8InputStream :: setOpenFileRetries ( open_file_retries ) ; FeatureModule :: load ( ) ; if ( verbosity < 0 || ParamReader :: isParamTrue ( " " ) ) quiet ( outdir ) ; displayVersionAndCopyright ( ) ; if ( ! ParamReader :: getOptionalTrueFalseParamWithDefaultVal ( " " , false ) ) UTF8InputStream :: stopTrackingFileOpens ( ) ; BOOST_FOREACH ( ModifyCommandLineHook_ptr hook , cliHooks ( ) ) { switch ( hook -> run ( verbosity ) ) { case ModifyCommandLineHook :: CONTINUE : continue ; case ModifyCommandLineHook :: SUCCESS : return 0 ; case ModifyCommandLineHook :: FAILURE : return -1 ; case ModifyCommandLineHook :: RESTART : restart ( argc , argv ) ; } } if ( ParamReader :: isParamTrue ( " " ) ) { if ( runTests ( ) != 0 ) return -1 ; } else if ( ParamReader :: hasParam ( " " ) ) { std :: string driverType = ParamReader :: getParam ( " " ) ; boost :: scoped_ptr < QueueDriver > queueDriver ( QueueDriver :: build ( driverType ) ) ; queueDriver -> processQueue ( ) ; } else { runSerif ( verbosity , totalLoadTimer ) ; } BOOST_FOREACH ( ModifyCommandLineHook_ptr hook , cliHooks ( ) ) { hook -> cleanup ( verbosity ) ; } } catch ( UnrecoverableException & e ) { if ( ! e . isLogged ( ) ) return reportError ( e . getMessage ( ) , e . getSource ( ) ) ; } catch ( exception & e ) { return reportError ( e . what ( ) ) ; } catch ( ... ) { return reportError ( " " ) ; } xercesc :: XMLPlatformUtils :: Terminate ( ) ; checkForLeaks ( ) ; reportOpenedFiles ( ) ; checkHeap ( " " ) ; #ifdef _DEBUG cerr << " " << endl ; getchar ( ) ; #endif return 0 ; }
Run the standard SERIF command-line interface.
Run the standard SERIF command - line interface .
// If leak detection is enabled, then initialize it.
 // Load the parameters and initialize the document driver.  This
 // will load all of Serif's models.  Use a timer to keep track
 // of how long we spend.
 // Parse the command line arguments.
 // Read the parameter file.
 // Set the open-file-retries count, if we have one.
 // Load modules specified in the parameter file.
 // Be quiet, if requested
 // Let the user know what verison of serif they're using.
 // Run any command line hooks defined by feature modules.
 // Run serif.
 // Run any cleanup defined by feature modules
 // XMLPlatformUtils was initialized in XMLString.cpp
 // Cleanup here, so we don't pollute leak detection output with
 // the objects it creates.
 // If leak detection is enabled, then report any leaked memory.
