You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by tn...@apache.org on 2001/10/19 21:02:43 UTC

cvs commit: xml-xerces/c/samples/StdInParse StdInParse.cpp

tng         01/10/19 12:02:43

  Modified:    c/samples/CreateDOMDocument CreateDOMDocument.cpp
               c/samples/DOMCount DOMCount.cpp
               c/samples/EnumVal EnumVal.cpp
               c/samples/IDOMCount IDOMCount.cpp
               c/samples/Redirect Redirect.cpp
               c/samples/SAX2Count SAX2Count.cpp
               c/samples/SAX2Print SAX2Print.cpp
               c/samples/SAXCount SAXCount.cpp
               c/samples/SAXPrint SAXPrint.cpp
               c/samples/StdInParse StdInParse.cpp
  Log:
  [Bug 3909] return non-zero an exit code when error was encounted.
  And other modification for consistent help display and return code across samples.
  
  Revision  Changes    Path
  1.6       +16 -8     xml-xerces/c/samples/CreateDOMDocument/CreateDOMDocument.cpp
  
  Index: CreateDOMDocument.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/samples/CreateDOMDocument/CreateDOMDocument.cpp,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- CreateDOMDocument.cpp	2000/03/02 19:53:39	1.5
  +++ CreateDOMDocument.cpp	2001/10/19 19:02:42	1.6
  @@ -1,7 +1,7 @@
   /*
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 1999-2000 The Apache Software Foundation.  All rights
  + * Copyright (c) 1999-2001 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -56,6 +56,10 @@
   
   /*
    * $Log: CreateDOMDocument.cpp,v $
  + * Revision 1.6  2001/10/19 19:02:42  tng
  + * [Bug 3909] return non-zero an exit code when error was encounted.
  + * And other modification for consistent help display and return code across samples.
  + *
    * Revision 1.5  2000/03/02 19:53:39  roddey
    * This checkin includes many changes done while waiting for the
    * 1.1.0 code to be finished. I can't list them all here, but a list is
  @@ -118,11 +122,13 @@
       // Watch for special case help request
       if (argC > 1)
       {
  -        cout << "\nUsage: CreateDOMDocument\n"
  -            "   This program creates a new DOM document from scratch in memory.\n"
  -            "   It then prints the count of elements in the tree.\n"
  -            <<  endl;
  -        return 0;
  +        cout << "\nUsage:\n"
  +                "    CreateDOMDocument\n\n"
  +                "This program creates a new DOM document from scratch in memory.\n"
  +                "It then prints the count of elements in the tree.\n"
  +             <<  endl;
  +        XMLPlatformUtils::Terminate();
  +        return 1;
       }
   
       //  The tree we create below is the same that the DOMParser would
  @@ -135,7 +141,7 @@
       // </company>
   
       DOM_DOMImplementation impl;
  -    
  +
       DOM_Document doc = impl.createDocument(
                   0,                    // root element namespace URI.
                   "company",            // root element name
  @@ -158,7 +164,7 @@
   
       DOM_Element  devByElem = doc.createElement("developedBy");
       rootElem.appendChild(devByElem);
  -    
  +
       DOM_Text    devByDataVal = doc.createTextNode("Apache Software Foundation");
       devByElem.appendChild(devByDataVal);
   
  @@ -174,6 +180,7 @@
       //  The DOM document and its contents are reference counted, and need
       //  no explicit deletion.
       //
  +    XMLPlatformUtils::Terminate();
       return 0;
   }
   
  
  
  
  1.19      +23 -20    xml-xerces/c/samples/DOMCount/DOMCount.cpp
  
  Index: DOMCount.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/samples/DOMCount/DOMCount.cpp,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- DOMCount.cpp	2001/08/15 12:41:04	1.18
  +++ DOMCount.cpp	2001/10/19 19:02:42	1.19
  @@ -55,7 +55,7 @@
    */
   
   /*
  - * $Id: DOMCount.cpp,v 1.18 2001/08/15 12:41:04 tng Exp $
  + * $Id: DOMCount.cpp,v 1.19 2001/10/19 19:02:42 tng Exp $
    */
   
   // ---------------------------------------------------------------------------
  @@ -82,16 +82,17 @@
   {
       cout << "\nUsage:\n"
               "    DOMCount [options] <XML file> | List file>\n\n"
  -            "This program invokes the XML4C DOM parser, builds\n"
  -            "the DOM tree, and then prints the number of elements\n"
  -            "found in the input XML file.\n\n"
  +            "This program invokes the DOM parser, builds the DOM tree,\n"
  +            "and then prints the number of elements found in each XML file.\n\n"
               "Options:\n"
  -            "    -l          Indicate the input file is a file that has a list of xml files.  Default: Input file is an XML file\n"
  -            "    -v=xxx      Validation scheme [always | never | auto*]\n"
  +            "    -l          Indicate the input file is a List File that has a list of xml files.\n"
  +            "                Default to off (Input file is an XML file).\n"
  +            "    -v=xxx      Validation scheme [always | never | auto*].\n"
               "    -n          Enable namespace processing. Defaults to off.\n"
               "    -s          Enable schema processing. Defaults to off.\n"
  -            "    -f          Enable full schema constraint checking. Defaults to off.\n\n"
  -            "  * = Default if not provided explicitly\n\n"
  +            "    -f          Enable full schema constraint checking. Defaults to off.\n"
  +		      "    -?          Show this help.\n\n"
  +            "  * = Default if not provided explicitly.\n"
            << endl;
   }
   
  @@ -115,6 +116,7 @@
       if (argC < 2)
       {
           usage();
  +        XMLPlatformUtils::Terminate();
           return 1;
       }
   
  @@ -126,23 +128,23 @@
       bool                     doList = false;
       bool                     errorOccurred = false;
   
  -    // See if non validating dom parser configuration is requested.
  -    if ((argC == 2) && !strcmp(argV[1], "-?"))
  -    {
  -        usage();
  -        return 2;
  -    }
  -
       int argInd;
       for (argInd = 1; argInd < argC; argInd++)
       {
  -        // Break out on first non-dash parameter
  +        // Break out on first parm not starting with a dash
           if (argV[argInd][0] != '-')
               break;
   
  -        if (!strncmp(argV[argInd], "-v=", 3)
  -        ||  !strncmp(argV[argInd], "-V=", 3))
  +        // Watch for special case help request
  +        if (!strcmp(argV[argInd], "-?"))
           {
  +            usage();
  +            XMLPlatformUtils::Terminate();
  +            return 2;
  +        }
  +         else if (!strncmp(argV[argInd], "-v=", 3)
  +              ||  !strncmp(argV[argInd], "-V=", 3))
  +        {
               const char* const parm = &argV[argInd][3];
   
               if (!strcmp(parm, "never"))
  @@ -222,8 +224,8 @@
       {
           char fURI[1000];
           //initialize the array to zeros
  -        memset(fURI,0,sizeof(fURI)); 
  -                
  +        memset(fURI,0,sizeof(fURI));
  +
           if (doList) {
               if (! fin.eof() ) {
                   fin.getline (fURI, sizeof(fURI));
  @@ -283,6 +285,7 @@
           if (errorHandler.getSawErrors())
           {
               cout << "\nErrors occured, no output available\n" << endl;
  +            errorOccurred = true;
           }
            else
           {
  
  
  
  1.13      +86 -74    xml-xerces/c/samples/EnumVal/EnumVal.cpp
  
  Index: EnumVal.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/samples/EnumVal/EnumVal.cpp,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- EnumVal.cpp	2001/05/11 13:24:54	1.12
  +++ EnumVal.cpp	2001/10/19 19:02:42	1.13
  @@ -56,6 +56,10 @@
   
   /*
    * $Log: EnumVal.cpp,v $
  + * Revision 1.13  2001/10/19 19:02:42  tng
  + * [Bug 3909] return non-zero an exit code when error was encounted.
  + * And other modification for consistent help display and return code across samples.
  + *
    * Revision 1.12  2001/05/11 13:24:54  tng
    * Copyright update.
    *
  @@ -171,10 +175,10 @@
   {
       cout << "\nUsage:\n"
               "    EnumVal <XML file>\n\n"
  -            "This program parses a file, then shows how to enumerate the\n"
  -            "contents of the validator pools. Essentially, shows how one can\n"
  -            "access the DTD information stored in internal data structures.\n\n"
  -            "  * = Default if not provided explicitly\n"
  +            "This program parses the specified XML file, then shows how to\n"
  +            "enumerate the contents of the validator pools. Essentially,\n"
  +            "shows how one can access the DTD information stored in internal\n"
  +            "data structures.\n"
            << endl;
   }
   
  @@ -207,11 +211,11 @@
       }
   
       // We only have one required parameter, which is the file to process
  -    if ((argC == 2) && (*(argV[1]) == '-'))
  +    if ((argC != 2) || (*(argV[1]) == '-'))
       {
           usage();
           XMLPlatformUtils::Terminate();
  -        return 2;
  +        return 1;
       }
   
       const char*              xmlFile   = argV[1];
  @@ -223,6 +227,7 @@
       //  we were told on the command line, set it to validate or not. He owns
       //  the validator, so we have to allocate it.
       //
  +    int errorCount = 0;
       DTDValidator* valToUse = new DTDValidator;
       SAXParser parser(valToUse);
       parser.setValidationScheme(valScheme);
  @@ -234,6 +239,7 @@
       try
       {
           parser.parse(xmlFile);
  +        errorCount = parser.getErrorCount();
       }
   
       catch (const XMLException& e)
  @@ -242,90 +248,97 @@
                << "Exception message is:  \n"
                << StrX(e.getMessage()) << "\n" << endl;
           XMLPlatformUtils::Terminate();
  -        return 3;
  +        return 4;
       }
   
  -    //
  -    //  Now we will get an enumerator for the element pool from the validator
  -    //  and enumerate the elements, printing them as we go. For each element
  -    //  we get an enumerator for its attributes and print them also.
  -    //
  -	DTDGrammar* grammar = (DTDGrammar*) valToUse->getGrammar();
  -    NameIdPoolEnumerator<DTDElementDecl> elemEnum = grammar->getElemEnumerator();
  -    if (elemEnum.hasMoreElements())
  -    {
  -        cout << "\nELEMENTS:\n----------------------------\n";
  -        while(elemEnum.hasMoreElements())
  +    if (!errorCount) {
  +        //
  +        //  Now we will get an enumerator for the element pool from the validator
  +        //  and enumerate the elements, printing them as we go. For each element
  +        //  we get an enumerator for its attributes and print them also.
  +        //
  +        DTDGrammar* grammar = (DTDGrammar*) valToUse->getGrammar();
  +        NameIdPoolEnumerator<DTDElementDecl> elemEnum = grammar->getElemEnumerator();
  +        if (elemEnum.hasMoreElements())
           {
  -            const DTDElementDecl& curElem = elemEnum.nextElement();
  -            cout << "  Name: " << StrX(curElem.getFullName()) << "\n";
  +            cout << "\nELEMENTS:\n----------------------------\n";
  +            while(elemEnum.hasMoreElements())
  +            {
  +                const DTDElementDecl& curElem = elemEnum.nextElement();
  +                cout << "  Name: " << StrX(curElem.getFullName()) << "\n";
   
  -            cout << "  Content Model: "
  -                 << StrX(curElem.getFormattedContentModel())
  -                 << "\n";
  +                cout << "  Content Model: "
  +                     << StrX(curElem.getFormattedContentModel())
  +                     << "\n";
   
  -            // Get an enumerator for this guy's attributes if any
  -            if (curElem.hasAttDefs())
  -            {
  -                cout << "  Attributes:\n";
  -                XMLAttDefList& attList = curElem.getAttDefList();
  -                while (attList.hasMoreElements())
  +                // Get an enumerator for this guy's attributes if any
  +                if (curElem.hasAttDefs())
                   {
  -                    const XMLAttDef& curAttDef = attList.nextElement();
  -                    cout << "    Name:" << StrX(curAttDef.getFullName())
  -                         << ", Type: ";
  -
  -                    // Get the type and display it
  -                    const XMLAttDef::AttTypes type = curAttDef.getType();
  -                    switch(type)
  +                    cout << "  Attributes:\n";
  +                    XMLAttDefList& attList = curElem.getAttDefList();
  +                    while (attList.hasMoreElements())
                       {
  -                        case XMLAttDef::CData :
  -                            cout << "CDATA";
  -                            break;
  -
  -                        case XMLAttDef::ID :
  -                            cout << "ID";
  -                            break;
  -
  -                        case XMLAttDef::IDRef :
  -                        case XMLAttDef::IDRefs :
  -                            cout << "IDREF(S)";
  -                            break;
  -
  -                        case XMLAttDef::Entity :
  -                        case XMLAttDef::Entities :
  -                            cout << "ENTITY(IES)";
  -                            break;
  -
  -                        case XMLAttDef::NmToken :
  -                        case XMLAttDef::NmTokens :
  -                            cout << "NMTOKEN(S)";
  -                            break;
  -
  -                        case XMLAttDef::Notation :
  -                            cout << "NOTATION";
  -                            break;
  -
  -                        case XMLAttDef::Enumeration :
  -                            cout << "ENUMERATION";
  -                            break;
  -                    }
  +                        const XMLAttDef& curAttDef = attList.nextElement();
  +                        cout << "    Name:" << StrX(curAttDef.getFullName())
  +                             << ", Type: ";
  +
  +                        // Get the type and display it
  +                        const XMLAttDef::AttTypes type = curAttDef.getType();
  +                        switch(type)
  +                        {
  +                            case XMLAttDef::CData :
  +                                cout << "CDATA";
  +                                break;
  +
  +                            case XMLAttDef::ID :
  +                                cout << "ID";
  +                                break;
  +
  +                            case XMLAttDef::IDRef :
  +                            case XMLAttDef::IDRefs :
  +                                cout << "IDREF(S)";
  +                                break;
  +
  +                            case XMLAttDef::Entity :
  +                            case XMLAttDef::Entities :
  +                                cout << "ENTITY(IES)";
  +                                break;
  +
  +                            case XMLAttDef::NmToken :
  +                            case XMLAttDef::NmTokens :
  +                                cout << "NMTOKEN(S)";
  +                                break;
  +
  +                            case XMLAttDef::Notation :
  +                                cout << "NOTATION";
  +                                break;
  +
  +                            case XMLAttDef::Enumeration :
  +                                cout << "ENUMERATION";
  +                                break;
  +                        }
   
  -                    cout << "\n";
  +                        cout << "\n";
  +                    }
                   }
  +                cout << endl;
               }
  -            cout << endl;
           }
  -    }
  -     else
  -    {
  -        cout << "The validator has no elements to display\n" << endl;
  +         else
  +        {
  +            cout << "The validator has no elements to display\n" << endl;
  +        }
       }
  +    else
  +        cout << "\nErrors occured, no output available\n" << endl;
   
       // And call the termination method
       XMLPlatformUtils::Terminate();
   
  -    return 0;
  +    if (errorCount > 0)
  +        return 4;
  +    else
  +        return 0;
   }
   
   
  
  
  
  1.11      +23 -18    xml-xerces/c/samples/IDOMCount/IDOMCount.cpp
  
  Index: IDOMCount.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/samples/IDOMCount/IDOMCount.cpp,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- IDOMCount.cpp	2001/10/17 17:19:38	1.10
  +++ IDOMCount.cpp	2001/10/19 19:02:42	1.11
  @@ -55,7 +55,7 @@
    */
   
   /*
  - * $Id: IDOMCount.cpp,v 1.10 2001/10/17 17:19:38 tng Exp $
  + * $Id: IDOMCount.cpp,v 1.11 2001/10/19 19:02:42 tng Exp $
    */
   
   // ---------------------------------------------------------------------------
  @@ -84,16 +84,17 @@
   {
       cout << "\nUsage:\n"
               "    IDOMCount [options] <XML file> | List file>\n\n"
  -            "This program invokes the XML4C DOM parser, builds\n"
  -            "the DOM tree, and then prints the number of elements\n"
  -            "found in the input XML file.\n\n"
  +            "This program invokes the IDOM parser, builds the DOM tree,\n"
  +            "and then prints the number of elements found in each XML file.\n\n"
               "Options:\n"
  -            "    -l          Indicate the input file is a file that has a list of xml files.  Default: Input file is an XML file\n"
  -            "    -v=xxx      Validation scheme [always | never | auto*]\n"
  +            "    -l          Indicate the input file is a List File that has a list of xml files.\n"
  +            "                Default to off (Input file is an XML file).\n"
  +            "    -v=xxx      Validation scheme [always | never | auto*].\n"
               "    -n          Enable namespace processing. Defaults to off.\n"
               "    -s          Enable schema processing. Defaults to off.\n"
  -            "    -f          Enable full schema constraint checking. Defaults to off.\n\n"
  -            "  * = Default if not provided explicitly\n\n"
  +            "    -f          Enable full schema constraint checking. Defaults to off.\n"
  +		      "    -?          Show this help.\n\n"
  +            "  * = Default if not provided explicitly.\n"
            << endl;
   }
   
  @@ -149,6 +150,7 @@
       if (argC < 2)
       {
           usage();
  +        XMLPlatformUtils::Terminate();
           return 1;
       }
   
  @@ -160,23 +162,23 @@
       bool                      doList = false;
       bool                      errorOccurred = false;
   
  -    // See if non validating dom parser configuration is requested.
  -    if ((argC == 2) && !strcmp(argV[1], "-?"))
  -    {
  -        usage();
  -        return 2;
  -    }
  -
       int argInd;
       for (argInd = 1; argInd < argC; argInd++)
       {
  -        // Break out on first non-dash parameter
  +        // Break out on first parm not starting with a dash
           if (argV[argInd][0] != '-')
               break;
   
  -        if (!strncmp(argV[argInd], "-v=", 3)
  -        ||  !strncmp(argV[argInd], "-V=", 3))
  +        // Watch for special case help request
  +        if (!strcmp(argV[argInd], "-?"))
           {
  +            usage();
  +            XMLPlatformUtils::Terminate();
  +            return 2;
  +        }
  +         else if (!strncmp(argV[argInd], "-v=", 3)
  +              ||  !strncmp(argV[argInd], "-V=", 3))
  +        {
               const char* const parm = &argV[argInd][3];
   
               if (!strcmp(parm, "never"))
  @@ -188,6 +190,7 @@
               else
               {
                   cerr << "Unknown -v= value: " << parm << endl;
  +                XMLPlatformUtils::Terminate();
                   return 2;
               }
           }
  @@ -225,6 +228,7 @@
       if (argInd != argC - 1)
       {
           usage();
  +        XMLPlatformUtils::Terminate();
           return 1;
       }
   
  @@ -318,6 +322,7 @@
           if (errorHandler.getSawErrors())
           {
               cout << "\nErrors occured, no output available\n" << endl;
  +            errorOccurred = true;
           }
            else
           {
  
  
  
  1.5       +26 -20    xml-xerces/c/samples/Redirect/Redirect.cpp
  
  Index: Redirect.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/samples/Redirect/Redirect.cpp,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Redirect.cpp	2000/05/31 18:53:15	1.4
  +++ Redirect.cpp	2001/10/19 19:02:42	1.5
  @@ -75,6 +75,10 @@
    * to read the contents of 'personal.dtd'.
    *
    * $Log: Redirect.cpp,v $
  + * Revision 1.5  2001/10/19 19:02:42  tng
  + * [Bug 3909] return non-zero an exit code when error was encounted.
  + * And other modification for consistent help display and return code across samples.
  + *
    * Revision 1.4  2000/05/31 18:53:15  rahulj
    * Removed extraneous command line arguments.
    *
  @@ -128,28 +132,21 @@
       }
       catch (const XMLException& toCatch)
       {
  -         cerr << "Error during initialization! Message:\n"
  -              << StrX(toCatch.getMessage()) << endl;
  -        XMLPlatformUtils::Terminate();
  -         return 1;
  +        cerr << "Error during initialization! Message:\n"
  +             << StrX(toCatch.getMessage()) << endl;
  +        return 1;
       }
   
       // We only have one parameter, which is the file to process
  -    if (argc < 2)
  +    // We only have one required parameter, which is the file to process
  +    if ((argc != 2) || (*(args[1]) == '-'))
       {
           usage();
           XMLPlatformUtils::Terminate();
           return 1;
       }
  -    const char*              xmlFile = args[1];
   
  -    // Check for some special cases values of the parameter
  -    if (xmlFile[0] == '-')
  -    {
  -        usage();
  -        XMLPlatformUtils::Terminate();
  -        return 0;
  -    }
  +    const char*              xmlFile = args[1];
   
       //
       //  Create a SAX parser object. Then, according to what we were told on
  @@ -171,12 +168,14 @@
       //  Catch any exceptions that might propogate out of it.
       //
       unsigned long duration;
  +    int errorCount = 0;
       try
       {
           const unsigned long startMillis = XMLPlatformUtils::getCurrentMillis();
           parser.parse(xmlFile);
           const unsigned long endMillis = XMLPlatformUtils::getCurrentMillis();
           duration = endMillis - startMillis;
  +        errorCount = parser.getErrorCount();
       }
   
       catch (const XMLException& e)
  @@ -184,16 +183,24 @@
           cerr << "\nError during parsing: '" << xmlFile << "'\n"
                   << "Exception message is:  \n"
                   << StrX(e.getMessage()) << "\n" << endl;
  -        return -1;
  +        XMLPlatformUtils::Terminate();
  +        return 4;
       }
   
       // Print out the stats that we collected and time taken.
  -    cout << xmlFile << ": " << duration << " ms ("
  -         << handler.getElementCount() << " elems, "
  -         << handler.getAttrCount() << " attrs, "
  -         << handler.getSpaceCount() << " spaces, "
  -         << handler.getCharacterCount() << " chars)" << endl;
  +    if (!errorCount) {
  +        cout << xmlFile << ": " << duration << " ms ("
  +             << handler.getElementCount() << " elems, "
  +             << handler.getAttrCount() << " attrs, "
  +             << handler.getSpaceCount() << " spaces, "
  +             << handler.getCharacterCount() << " chars)" << endl;
  +    }
   
  -    return 0;
  +    XMLPlatformUtils::Terminate();
  +
  +    if (errorCount > 0)
  +        return 4;
  +    else
  +        return 0;
   }
   
  
  
  
  1.11      +29 -20    xml-xerces/c/samples/SAX2Count/SAX2Count.cpp
  
  Index: SAX2Count.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/samples/SAX2Count/SAX2Count.cpp,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- SAX2Count.cpp	2001/08/15 12:41:04	1.10
  +++ SAX2Count.cpp	2001/10/19 19:02:43	1.11
  @@ -56,6 +56,10 @@
   
   /*
   * $Log: SAX2Count.cpp,v $
  +* Revision 1.11  2001/10/19 19:02:43  tng
  +* [Bug 3909] return non-zero an exit code when error was encounted.
  +* And other modification for consistent help display and return code across samples.
  +*
   * Revision 1.10  2001/08/15 12:41:04  tng
   * Initialize the fURI array to zeros, in case, some compilers like AIX xlC_r doesn't reset the memory.
   *
  @@ -106,16 +110,20 @@
   {
       cout << "\nUsage:\n"
               "    SAX2Count [options] <XML file> | List file>\n\n"
  +            "This program invokes the SAX2XMLReader, and then prints the\n"
  +            "number of elements, attributes, spaces and characters found\n"
  +            "in each XML file, using SAX2 API.\n\n"
               "Options:\n"
  -            "    -l          Indicate the input file is a file that has a list of xml files.  Default: Input file is an XML file\n"
  -            "    -v=xxx      Validation scheme [always | never | auto*]\n"
  +            "    -l          Indicate the input file is a List File that has a list of xml files.\n"
  +            "                Default to off (Input file is an XML file).\n"
  +            "    -v=xxx      Validation scheme [always | never | auto*].\n"
  +            "    -f          Enable full schema constraint checking processing. Defaults to off.\n"
               "    -n          Disable namespace processing. Defaults to on.\n"
  +            "                NOTE: THIS IS OPPOSITE FROM OTHER SAMPLES.\n"
               "    -s          Disable schema processing. Defaults to on.\n"
  -            "    -f          Enable full schema constraint checking processing. Defaults to off.\n\n"
  -            "This program prints the number of elements, attributes,\n"
  -            "white spaces and other non-white space characters in the "
  -            "input file.\n\n"
  -            "  * = Default if not provided explicitly\n"
  +            "                NOTE: THIS IS OPPOSITE FROM OTHER SAMPLES.\n"
  +		      "    -?          Show this help.\n\n"
  +            "  * = Default if not provided explicitly.\n"
            << endl;
   }
   
  @@ -154,24 +162,23 @@
       bool                         doList = false;
       bool                         errorOccurred = false;
   
  -    // See if non validating dom parser configuration is requested.
  -    if ((argC == 2) && !strcmp(argV[1], "-?"))
  -    {
  -        usage();
  -        XMLPlatformUtils::Terminate();
  -        return 2;
  -    }
  -
       int argInd;
       for (argInd = 1; argInd < argC; argInd++)
       {
  -        // Break out on first non-dash parameter
  +        // Break out on first parm not starting with a dash
           if (argV[argInd][0] != '-')
               break;
   
  -        if (!strncmp(argV[argInd], "-v=", 3)
  -        ||  !strncmp(argV[argInd], "-V=", 3))
  +        // Watch for special case help request
  +        if (!strcmp(argV[argInd], "-?"))
           {
  +            usage();
  +            XMLPlatformUtils::Terminate();
  +            return 2;
  +        }
  +         else if (!strncmp(argV[argInd], "-v=", 3)
  +              ||  !strncmp(argV[argInd], "-V=", 3))
  +        {
               const char* const parm = &argV[argInd][3];
   
               if (!strcmp(parm, "never"))
  @@ -183,6 +190,7 @@
               else
               {
                   cerr << "Unknown -v= value: " << parm << endl;
  +                XMLPlatformUtils::Terminate();
                   return 2;
               }
           }
  @@ -273,8 +281,8 @@
       {
           char fURI[1000];
           //initialize the array to zeros
  -        memset(fURI,0,sizeof(fURI)); 
  -                
  +        memset(fURI,0,sizeof(fURI));
  +
           if (doList) {
               if (! fin.eof() ) {
                   fin.getline (fURI, sizeof(fURI));
  @@ -330,6 +338,8 @@
                   << handler.getSpaceCount() << " spaces, "
                   << handler.getCharacterCount() << " chars)" << endl;
           }
  +        else
  +            errorOccurred = true;
       }
   
       if (doList)
  
  
  
  1.5       +37 -23    xml-xerces/c/samples/SAX2Print/SAX2Print.cpp
  
  Index: SAX2Print.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/samples/SAX2Print/SAX2Print.cpp,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- SAX2Print.cpp	2001/08/02 17:10:29	1.4
  +++ SAX2Print.cpp	2001/10/19 19:02:43	1.5
  @@ -56,6 +56,10 @@
   
   /*
    * $Log: SAX2Print.cpp,v $
  + * Revision 1.5  2001/10/19 19:02:43  tng
  + * [Bug 3909] return non-zero an exit code when error was encounted.
  + * And other modification for consistent help display and return code across samples.
  + *
    * Revision 1.4  2001/08/02 17:10:29  tng
    * Allow DOMCount/SAXCount/IDOMCount/SAX2Count to take a file that has a list of xml file as input.
    *
  @@ -115,22 +119,24 @@
   // ---------------------------------------------------------------------------
   static void usage()
   {
  -    cout <<  "\nUsage: SAX2Print [options] file\n"
  -             "This program prints the data returned by the various SAX2\n"
  -             "handlers for the specified input file. Options are NOT case\n"
  -             "sensitive.\n\n"
  -             "Options:\n"
  -             "    -u=xxx      Handle unrepresentable chars [fail | rep | ref*]\n"
  -             "    -v=xxx      Validation scheme [always | never | auto*]\n"
  +    cout << "\nUsage:\n"
  +            "    SAX2Print [options] <XML file>\n\n"
  +            "This program invokes the SAX2XMLReader, and then prints the\n"
  +            "data returned by the various SAX2 handlers for the specified\n"
  +            "XML file.\n\n"
  +            "Options:\n"
  +             "    -u=xxx      Handle unrepresentable chars [fail | rep | ref*].\n"
  +             "    -v=xxx      Validation scheme [always | never | auto*].\n"
                "    -e          Expand Namespace Alias with URI's.\n"
                "    -x=XXX      Use a particular encoding for output (LATIN1*).\n"
  +             "    -f          Enable full schema constraint checking processing. Defaults to off.\n"
                "    -s          Disable schema processing. Defaults to on.\n"
  -             "    -f          Enable full schema constraint checking processing. Defaults to off.\n\n"
  -             "    -?          Show this help\n\n"
  -             "  * = Default if not provided explicitly\n\n"
  +             "                NOTE: THIS IS OPPOSITE FROM OTHER SAMPLES.\n"
  +             "    -?          Show this help.\n\n"
  +             "  * = Default if not provided explicitly.\n\n"
                "The parser has intrinsic support for the following encodings:\n"
                "    UTF-8, USASCII, ISO8859-1, UTF-16[BL]E, UCS-4[BL]E,\n"
  -             "    WINDOWS-1252, IBM1140, IBM037\n"
  +             "    WINDOWS-1252, IBM1140, IBM037.\n"
            <<  endl;
   }
   
  @@ -162,14 +168,6 @@
           return 1;
       }
   
  -    // Watch for special case help request
  -    if ((argC == 2) && !strcmp(argV[1], "-?"))
  -    {
  -        usage();
  -        XMLPlatformUtils::Terminate();
  -        return 2;
  -    }
  -
       int parmInd;
       for (parmInd = 1; parmInd < argC; parmInd++)
       {
  @@ -177,9 +175,16 @@
           if (argV[parmInd][0] != '-')
               break;
   
  -        if (!strncmp(argV[parmInd], "-v=", 3)
  -        ||  !strncmp(argV[parmInd], "-V=", 3))
  +        // Watch for special case help request
  +        if (!strcmp(argV[parmInd], "-?"))
           {
  +            usage();
  +            XMLPlatformUtils::Terminate();
  +            return 2;
  +        }
  +         else if (!strncmp(argV[parmInd], "-v=", 3)
  +              ||  !strncmp(argV[parmInd], "-V=", 3))
  +        {
               const char* const parm = &argV[parmInd][3];
   
               if (!strcmp(parm, "never"))
  @@ -191,6 +196,7 @@
               else
               {
                   cerr << "Unknown -v= value: " << parm << endl;
  +                XMLPlatformUtils::Terminate();
                   return 2;
               }
           }
  @@ -219,6 +225,7 @@
               else
               {
                   cerr << "Unknown -u= value: " << parm << endl;
  +                XMLPlatformUtils::Terminate();
                   return 2;
               }
           }
  @@ -246,6 +253,7 @@
       if (parmInd + 1 != argC)
       {
           usage();
  +        XMLPlatformUtils::Terminate();
           return 1;
       }
       xmlFile = argV[parmInd];
  @@ -285,12 +293,15 @@
       //  handler for the parser. Then parse the file and catch any exceptions
       //  that propogate out
       //
  +
  +    int errorCount = 0;
       try
       {
           SAX2PrintHandlers handler(encodingName, unRepFlags, expandNamespaces);
           parser->setContentHandler(&handler);
           parser->setErrorHandler(&handler);
           parser->parse(xmlFile);
  +        errorCount = parser->getErrorCount();
       }
   
       catch (const XMLException& toCatch)
  @@ -298,12 +309,16 @@
           cerr << "\nAn error occured\n  Error: "
                << StrX(toCatch.getMessage())
                << "\n" << endl;
  -        return -1;
  +        XMLPlatformUtils::Terminate();
  +        return 4;
       }
   
       // And call the termination method
       XMLPlatformUtils::Terminate();
   
  -    return 0;
  +    if (errorCount > 0)
  +        return 4;
  +    else
  +        return 0;
   }
   
  
  
  
  1.17      +28 -13    xml-xerces/c/samples/SAXCount/SAXCount.cpp
  
  Index: SAXCount.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/samples/SAXCount/SAXCount.cpp,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- SAXCount.cpp	2001/08/15 12:41:04	1.16
  +++ SAXCount.cpp	2001/10/19 19:02:43	1.17
  @@ -56,6 +56,10 @@
   
   /*
   * $Log: SAXCount.cpp,v $
  +* Revision 1.17  2001/10/19 19:02:43  tng
  +* [Bug 3909] return non-zero an exit code when error was encounted.
  +* And other modification for consistent help display and return code across samples.
  +*
   * Revision 1.16  2001/08/15 12:41:04  tng
   * Initialize the fURI array to zeros, in case, some compilers like AIX xlC_r doesn't reset the memory.
   *
  @@ -132,16 +136,18 @@
   {
       cout << "\nUsage:\n"
               "    SAXCount [options] <XML file> | List file>\n\n"
  +            "This program invokes the SAX Parser, and then prints the\n"
  +            "number of elements, attributes, spaces and characters found\n"
  +            "in each XML file, using SAX API.\n\n"
               "Options:\n"
  -            "    -l          Indicate the input file is a file that has a list of xml files.  Default: Input file is an XML file\n"
  -            "    -v=xxx      Validation scheme [always | never | auto*]\n"
  +            "    -l          Indicate the input file is a List File that has a list of xml files.\n"
  +            "                Default to off (Input file is an XML file).\n"
  +            "    -v=xxx      Validation scheme [always | never | auto*].\n"
               "    -n          Enable namespace processing. Defaults to off.\n"
               "    -s          Enable schema processing. Defaults to off.\n"
  -            "    -f          Enable full schema constraint checking. Defaults to off.\n\n"
  -            "This program prints the number of elements, attributes,\n"
  -            "white spaces and other non-white space characters in the "
  -            "input file.\n\n"
  -            "  * = Default if not provided explicitly\n"
  +            "    -f          Enable full schema constraint checking. Defaults to off.\n"
  +		      "    -?          Show this help.\n\n"
  +            "  * = Default if not provided explicitly.\n"
            << endl;
   }
   
  @@ -184,12 +190,19 @@
       int argInd;
       for (argInd = 1; argInd < argC; argInd++)
       {
  -        // Break out on first non-dash parameter
  +        // Break out on first parm not starting with a dash
           if (argV[argInd][0] != '-')
               break;
   
  -        if (!strncmp(argV[argInd], "-v=", 3)
  -        ||  !strncmp(argV[argInd], "-V=", 3))
  +        // Watch for special case help request
  +        if (!strcmp(argV[argInd], "-?"))
  +        {
  +            usage();
  +            XMLPlatformUtils::Terminate();
  +            return 2;
  +        }
  +         else if (!strncmp(argV[argInd], "-v=", 3)
  +              ||  !strncmp(argV[argInd], "-V=", 3))
           {
               const char* const parm = &argV[argInd][3];
   
  @@ -202,6 +215,7 @@
               else
               {
                   cerr << "Unknown -v= value: " << parm << endl;
  +                XMLPlatformUtils::Terminate();
                   return 2;
               }
           }
  @@ -236,7 +250,7 @@
       //  There should at least one parameter left, and that
       //  should be the file name(s).
       //
  -    if (argInd == argC)
  +    if (argInd != argC - 1)
       {
           usage();
           XMLPlatformUtils::Terminate();
  @@ -279,8 +293,8 @@
       {
           char fURI[1000];
           //initialize the array to zeros
  -        memset(fURI,0,sizeof(fURI)); 
  -                
  +        memset(fURI,0,sizeof(fURI));
  +
           if (doList) {
               if (! fin.eof() ) {
                   fin.getline (fURI, sizeof(fURI));
  @@ -341,6 +355,8 @@
                   << handler.getSpaceCount() << " spaces, "
                   << handler.getCharacterCount() << " chars)" << endl;
           }
  +        else
  +            errorOccurred = true;
       }
   
       if (doList)
  
  
  
  1.16      +33 -21    xml-xerces/c/samples/SAXPrint/SAXPrint.cpp
  
  Index: SAXPrint.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/samples/SAXPrint/SAXPrint.cpp,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- SAXPrint.cpp	2001/08/01 19:11:01	1.15
  +++ SAXPrint.cpp	2001/10/19 19:02:43	1.16
  @@ -56,6 +56,10 @@
   
   /*
    * $Log: SAXPrint.cpp,v $
  + * Revision 1.16  2001/10/19 19:02:43  tng
  + * [Bug 3909] return non-zero an exit code when error was encounted.
  + * And other modification for consistent help display and return code across samples.
  + *
    * Revision 1.15  2001/08/01 19:11:01  tng
    * Add full schema constraint checking flag to the samples and the parser.
    *
  @@ -166,22 +170,23 @@
   // ---------------------------------------------------------------------------
   static void usage()
   {
  -    cout <<  "\nUsage: SAXPrint [options] file\n"
  -             "This program prints the data returned by the various SAX\n"
  -             "handlers for the specified input file. Options are NOT case\n"
  -             "sensitive.\n\n"
  -             "Options:\n"
  -             "    -u=xxx      Handle unrepresentable chars [fail | rep | ref*]\n"
  -             "    -v=xxx      Validation scheme [always | never | auto*]\n"
  +    cout << "\nUsage:\n"
  +            "    SAX2Print [options] <XML file>\n\n"
  +            "This program invokes the SAX Parser, and then prints the\n"
  +            "data returned by the various SAX handlers for the specified\n"
  +            "XML file.\n\n"
  +            "Options:\n"
  +             "    -u=xxx      Handle unrepresentable chars [fail | rep | ref*].\n"
  +             "    -v=xxx      Validation scheme [always | never | auto*].\n"
                "    -n          Enable namespace processing.\n"
                "    -s          Enable schema processing.\n"
                "    -f          Enable full schema constraint checking.\n"
                "    -x=XXX      Use a particular encoding for output (LATIN1*).\n"
  -             "    -?          Show this help\n\n"
  -             "  * = Default if not provided explicitly\n\n"
  +             "    -?          Show this help.\n\n"
  +             "  * = Default if not provided explicitly.\n\n"
                "The parser has intrinsic support for the following encodings:\n"
                "    UTF-8, USASCII, ISO8859-1, UTF-16[BL]E, UCS-4[BL]E,\n"
  -             "    WINDOWS-1252, IBM1140, IBM037\n"
  +             "    WINDOWS-1252, IBM1140, IBM037.\n"
            <<  endl;
   }
   
  @@ -213,14 +218,6 @@
           return 1;
       }
   
  -    // Watch for special case help request
  -    if ((argC == 2) && !strcmp(argV[1], "-?"))
  -    {
  -        usage();
  -        XMLPlatformUtils::Terminate();
  -        return 2;
  -    }
  -
       int parmInd;
       for (parmInd = 1; parmInd < argC; parmInd++)
       {
  @@ -228,8 +225,15 @@
           if (argV[parmInd][0] != '-')
               break;
   
  -        if (!strncmp(argV[parmInd], "-v=", 3)
  -        ||  !strncmp(argV[parmInd], "-V=", 3))
  +        // Watch for special case help request
  +        if (!strcmp(argV[parmInd], "-?"))
  +        {
  +            usage();
  +            XMLPlatformUtils::Terminate();
  +            return 2;
  +        }
  +         else if (!strncmp(argV[parmInd], "-v=", 3)
  +              ||  !strncmp(argV[parmInd], "-V=", 3))
           {
               const char* const parm = &argV[parmInd][3];
   
  @@ -242,6 +246,7 @@
               else
               {
                   cerr << "Unknown -v= value: " << parm << endl;
  +                XMLPlatformUtils::Terminate();
                   return 2;
               }
           }
  @@ -280,6 +285,7 @@
               else
               {
                   cerr << "Unknown -u= value: " << parm << endl;
  +                XMLPlatformUtils::Terminate();
                   return 2;
               }
           }
  @@ -297,9 +303,11 @@
       if (parmInd + 1 != argC)
       {
           usage();
  +        XMLPlatformUtils::Terminate();
           return 1;
       }
       xmlFile = argV[parmInd];
  +    int errorCount = 0;
   
       //
       //  Create a SAX parser object. Then, according to what we were told on
  @@ -322,6 +330,7 @@
           parser.setDocumentHandler(&handler);
           parser.setErrorHandler(&handler);
           parser.parse(xmlFile);
  +        errorCount = parser.getErrorCount();
       }
   
       catch (const XMLException& toCatch)
  @@ -329,12 +338,16 @@
           cerr << "\nAn error occured\n  Error: "
                << StrX(toCatch.getMessage())
                << "\n" << endl;
  +        XMLPlatformUtils::Terminate();
           return -1;
       }
   
       // And call the termination method
       XMLPlatformUtils::Terminate();
   
  -    return 0;
  +    if (errorCount > 0)
  +        return 4;
  +    else
  +        return 0;
   }
   
  
  
  
  1.11      +42 -20    xml-xerces/c/samples/StdInParse/StdInParse.cpp
  
  Index: StdInParse.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/samples/StdInParse/StdInParse.cpp,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- StdInParse.cpp	2001/08/01 19:11:01	1.10
  +++ StdInParse.cpp	2001/10/19 19:02:43	1.11
  @@ -56,6 +56,10 @@
   
   /*
    * $Log: StdInParse.cpp,v $
  + * Revision 1.11  2001/10/19 19:02:43  tng
  + * [Bug 3909] return non-zero an exit code when error was encounted.
  + * And other modification for consistent help display and return code across samples.
  + *
    * Revision 1.10  2001/08/01 19:11:01  tng
    * Add full schema constraint checking flag to the samples and the parser.
    *
  @@ -134,16 +138,18 @@
   void usage()
   {
       cout << "\nUsage:\n"
  -         << "    StdInParse [options]\n"
  -         << "    -v=xxx      Validation scheme [always | never | auto] \n"
  -         << "    -n          Enable namespace processing. [default is off]\n"
  -         << "    -s          Enable schema processing. [default is off]\n"
  -         << "    -f          Enable full schema constraint checking. [defaults is off]\n"
  -		   << "    -?          Show this help\n\n"
  -         << "  * = Default if not provided explicitly\n\n"
  -         << "This program allows you to redirect a file into the program\n"
  -         << "to be parsed. It will count the elements, characters, and \n"
  -         << "spaces and display these stats at the end\n"
  +            "    StdInParse [options] < <XML file>\n\n"
  +            "This program demonstrates streaming XML data from standard\n"
  +            "input.  It then uses the SAX Parser, and prints the\n"
  +            "number of elements, attributes, spaces and characters found\n"
  +            "in the input, using SAX API.\n\n"
  +            "Options:\n"
  +            "    -v=xxx      Validation scheme [always | never | auto*].\n"
  +            "    -n          Enable namespace processing. Defaults to off.\n"
  +            "    -s          Enable schema processing. Defaults to off.\n"
  +            "    -f          Enable full schema constraint checking. Defaults to off.\n"
  +		      "    -?          Show this help.\n\n"
  +            "  * = Default if not provided explicitly.\n"
            << endl;
   }
   
  @@ -169,13 +175,19 @@
       int parmInd;
       for (parmInd = 1; parmInd < argC; parmInd++)
       {
  +        // Break out on first parm not starting with a dash
  +        if (argV[parmInd][0] != '-')
  +            break;
  +
  +        // Watch for special case help request
           if (!strcmp(argV[parmInd], "-?"))
           {
               usage();
  -            return 1;
  +            XMLPlatformUtils::Terminate();
  +            return 2;
           }
  -        if (!strncmp(argV[parmInd], "-v=", 3)
  -        ||  !strncmp(argV[parmInd], "-V=", 3))
  +         else if (!strncmp(argV[parmInd], "-v=", 3)
  +              ||  !strncmp(argV[parmInd], "-V=", 3))
           {
               const char* const parm = &argV[parmInd][3];
   
  @@ -188,6 +200,7 @@
               else
               {
                   cerr << "Unknown -v= value: " << parm << endl;
  +                XMLPlatformUtils::Terminate();
                   return 2;
               }
           }
  @@ -239,6 +252,7 @@
       //  input input source and tell the parser to parse from that.
       //
       unsigned long duration;
  +    int errorCount = 0;
       StdInInputSource src;
       try
       {
  @@ -246,6 +260,7 @@
           parser.parse(src);
           const unsigned long endMillis = XMLPlatformUtils::getCurrentMillis();
           duration = endMillis - startMillis;
  +        errorCount = parser.getErrorCount();
       }
   
       catch (const XMLException& e)
  @@ -253,16 +268,24 @@
           cerr << "\nError during parsing: \n"
                << StrX(e.getMessage())
                << "\n" << endl;
  -        return -1;
  +        XMLPlatformUtils::Terminate();
  +        return 4;
       }
   
       // Print out the stats that we collected and time taken
  -    cout << StrX(src.getSystemId()) << ": " << duration << " ms ("
  -         << handler.getElementCount() << " elems, "
  -         << handler.getAttrCount() << " attrs, "
  -         << handler.getSpaceCount() << " spaces, "
  -         << handler.getCharacterCount() << " chars)" << endl;
  +    if (!errorCount) {
  +        cout << StrX(src.getSystemId()) << ": " << duration << " ms ("
  +             << handler.getElementCount() << " elems, "
  +             << handler.getAttrCount() << " attrs, "
  +             << handler.getSpaceCount() << " spaces, "
  +             << handler.getCharacterCount() << " chars)" << endl;
  +    }
  +
  +    XMLPlatformUtils::Terminate();
   
  -    return 0;
  +    if (errorCount > 0)
  +        return 4;
  +    else
  +        return 0;
   }
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org