main-file frame |
Top Previous Next |
Code generation > Code frames > main-file frame
A main function is produced per default for a console application with the following main file frame.
//---------------------------------------------------------- // ttmain_c.frm // TextTransformer C++ Support Frame // Copyright: Dr. Detlef Meyer-Eltz // http://www.texttransformer.de // http://www.texttransformer.com // dme@texttransformer.com // // June, 2009 Version 1.7.0 //----------------------------------------------------------
#ifdef __BORLANDC__ #pragma hdrstop #endif
#include "-->ParserHeaderName" -->XercesInclude
using namespace std; using namespace tetra; -->XercesUsingNamespace
typedef -->ParserClassName::string_type string_type;
void usage() { cout << "\nParameters:\n" " -s source file\n" " -t target file\n" << endl; }
int main(int argc, char* argv[]) { string_type sTest; const char* pSourceName = NULL; const char* pTargetName = NULL;
if (argc < 2) { usage(); return 1; }
int iParam; for(iParam = 1; iParam < argc; iParam++) { if(argv[iParam][0] != '-') { usage(); return 2; }
if(!strcmp(argv[iParam], "-s")) { if(++iParam < argc) pSourceName = argv[iParam]; }
if(!strcmp(argv[iParam], "-t")) { if(++iParam < argc) pTargetName = argv[iParam]; } }
if(pSourceName == NULL ) { usage(); return 3; }
if(pTargetName == NULL ) { usage(); return 4; }
if( !-->LoadFile ) { cout << "could not load source file: " << pSourceName; return 5; }
-->Ostream if(!fout) { cout << "could not open target file: " << pTargetName; return 6; }
-->PluginType plugin(fout); InitPluginPaths(plugin, pSourceName, pTargetName); plugin.UseExcept(true);
-->XercesInit -->ParserClassName Parser;
try { Parser.-->StartRuleName(sTest.begin(), sTest.end(), &plugin); } catch(CTT_ErrorExpected& xErr) { cout << "expected: " << xErr.GetWhat() << " in " << xErr.GetProduction() << "\n"; } catch(CTT_ErrorUnexpected& xErr) { cout << "unexpected token in: " << xErr.GetProduction() << "\n"; } catch(CTT_ParseError& xErr) { cout << xErr.GetWhat(); } catch(CTT_Message& xErr) { cout << xErr.what(); } /* catch(boost::system_error& xErr) { cout << xErr.what(); }*/ catch(exception& xErr) { cout << xErr.what(); } /* xerces catches catch (const OutOfMemoryException&) { cout << ccpXercesOutOfMemory; } catch (const DOMException& e) { cout << "xerces error code: " << e.code << endl; char *pMsg = XMLString::transcode(e.getMessage()); cout << pMsg; XMLString::release(&pMsg); } catch (XMLException& e) { char *pMsg = XMLString::transcode(e.getMessage()); cout << pMsg; XMLString::release(&pMsg); } */
if( plugin.HasMessage()) { -->PluginType::ctmmsg t, tEnd = plugin.MsgEnd(); for(t = plugin.MsgBegin(); t != tEnd; ++t) cout << (*t).what() << endl << endl; }
return 0; }
The program expects two parameters: one for the source path and one for the target path.
There are five new placeholders in the frame which are not in the other frames
XercesInclude XercesUsingNamespace XercesInit LoadFile OstreamType
The first three placeholders are deleted if dnode isn't used in the project.
-->LoadFile is substituated by:
load_file_binary( sTest, pSourceName)
for binary open mode of the source file or by
load_file( sTest, pSourceName)
-->Ostream is substituded either by ofstream or by wofstream, depending on the activation of the selected wide-char option and the flag ios::binary is set according to the open mode for the target file.
If dnode's are used, the plugin-type CTT_ParseStateDomPlugin has to be set.
-->XercesInclude includes tt_xerces.h
->XercesUsingNamespace inserts the following line:
using namespace xercesc;
-->XercesInit creates an instance of CTT_Xerces and passes a pointer to it to the plugin.
CTT_Xerces Xerces("root", "UTF-8", false, true, true, true); //Xerces.setDTDParams("", "", ""); plugin.SetXerces(&Xerces); Ctranslation_unitParser::dnode::SetDefaultLabel(L"default_label");
|
This page belongs to the TextTransformer Documentation |
Home Content German |