Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

main.cpp

Go to the documentation of this file.
00001 // $Id: main.cpp,v 1.1.1.1 2003/02/21 18:36:32 chad Exp $
00002 
00003 #include "ACEXML/common/FileCharStream.h"
00004 #include "ACEXML/common/StrCharStream.h"
00005 #include "ACEXML/parser/parser/Parser.h"
00006 #include "Svcconf_Handler.h"
00007 #include "ace/Get_Opt.h"
00008 #include "ace/Auto_Ptr.h"
00009 
00010 int
00011 ACE_TMAIN (int argc, ACE_TCHAR *argv[])
00012 {
00013   ACE_TCHAR *filename = 0;
00014 
00015   ACE_Get_Opt get_opt (argc, argv, ACE_TEXT ("f:"));
00016   ACE_TCHAR c;
00017 
00018   while ((c = get_opt ()) != -1)
00019     {
00020       switch (c)
00021         {
00022         case 'f':
00023           filename = get_opt.opt_arg ();
00024           break;
00025         default:
00026           ACE_ERROR_RETURN ((LM_ERROR,
00027                              ACE_TEXT ("Usage: %s [-f <filename>]\n")
00028                              ACE_TEXT ("  -f: Specify the svcconf filename\n"),
00029                              argv[0]),
00030                             -1);
00031         }
00032     };
00033 
00034   if (filename == 0)
00035     ACE_ERROR_RETURN ((LM_ERROR, "No filename specified\n"), -1);
00036 
00037   ACEXML_DefaultHandler *handler = 0;
00038   auto_ptr<ACEXML_DefaultHandler> cleanup_handler (handler);
00039     ACEXML_CharStream *stm = 0;
00040     ACEXML_FileCharStream *fstm = 0;
00041     ACE_NEW_RETURN (fstm,
00042                     ACEXML_FileCharStream (),
00043                     1);
00044 
00045     if (fstm->open (filename) != 0)
00046       ACE_ERROR_RETURN ((LM_ERROR,
00047                          ACE_TEXT ("Fail to open XML file: %s\n"),
00048                          filename),
00049                         -1);
00050     stm = fstm;
00051 
00052     ACE_NEW_RETURN (handler,
00053                     ACEXML_Svcconf_Handler (),
00054                     -1);
00055 
00056     ACEXML_Parser parser;
00057     ACEXML_InputSource input(stm);
00058 
00059     parser.setContentHandler (handler);
00060     parser.setDTDHandler (handler);
00061     parser.setErrorHandler (handler);
00062     parser.setEntityResolver (handler);
00063 
00064   ACEXML_TRY_NEW_ENV
00065     {
00066       parser.parse (&input ACEXML_ENV_ARG_PARAMETER);
00067       ACEXML_TRY_CHECK;
00068     }
00069   ACEXML_CATCH (ACEXML_SAXException, ex)
00070     {
00071       ex.print ();
00072       return -1;
00073   }
00074   ACEXML_ENDTRY;
00075   return 0;
00076 }

Generated on Mon Jun 16 13:23:22 2003 for ACEXML by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002