(file) Return to WQLParser.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / WQL

  1 karl  1.20 //%2006////////////////////////////////////////////////////////////////////////
  2 mike  1.2  //
  3 karl  1.12 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
  4            // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
  5            // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
  6 karl  1.11 // IBM Corp.; EMC Corporation, The Open Group.
  7 karl  1.12 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
  8            // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
  9 karl  1.16 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 10            // EMC Corporation; VERITAS Software Corporation; The Open Group.
 11 karl  1.20 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 12            // EMC Corporation; Symantec Corporation; The Open Group.
 13 mike  1.2  //
 14            // Permission is hereby granted, free of charge, to any person obtaining a copy
 15 kumpf 1.6  // of this software and associated documentation files (the "Software"), to
 16            // deal in the Software without restriction, including without limitation the
 17            // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 18 mike  1.2  // sell copies of the Software, and to permit persons to whom the Software is
 19            // furnished to do so, subject to the following conditions:
 20            // 
 21 kumpf 1.6  // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 22 mike  1.2  // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
 23            // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 24 kumpf 1.6  // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 25            // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 26            // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 27 mike  1.2  // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 28            // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 29            //
 30            //==============================================================================
 31            //
 32            // Author: Mike Brasher (mbrasher@bmc.com)
 33            //
 34 david.dillard 1.14 // Modified By: David Dillard, VERITAS Software Corp.
 35                    //                  (david.dillard@veritas.com)
 36 joyce.j       1.15 //                    Josephine Eskaline Joyce (jojustin@in.ibm.com) for PEP#101
 37 mike          1.2  //
 38                    //%/////////////////////////////////////////////////////////////////////////////
 39                    
 40                    #include <Pegasus/Common/Config.h>
 41 kumpf         1.7  #include <Pegasus/Common/InternalException.h>
 42 kumpf         1.4  #include <Pegasus/Common/Tracer.h>
 43 kumpf         1.5  #include <Pegasus/Common/PegasusVersion.h>
 44 mike          1.21 #include <Pegasus/Common/Mutex.h>
 45 mike          1.2  #include <iostream>
 46                    #include "WQLParser.h"
 47                    #include "WQLParserState.h"
 48                    
 49                    PEGASUS_USING_STD;
 50                    
 51                    extern int WQL_parse();
 52 kumpf         1.10 extern void WQL_restart (FILE *input_file);
 53 mike          1.2  
 54                    PEGASUS_NAMESPACE_BEGIN
 55                    
 56 karl          1.17 WQLParserState* globalParserState = 0; 
 57 humberto      1.13 static Mutex WQL_mutex;
 58 mike          1.2  
 59                    void WQLParser::parse(
 60 mike          1.3      const char* text,
 61 mike          1.2      WQLSelectStatement& statement)
 62                    {
 63 kumpf         1.4      PEG_METHOD_ENTER(TRC_WQL,"WQLParser::parse");
 64 humberto      1.13     
 65                    	 AutoMutex mtx(WQL_mutex);
 66 kumpf         1.4  
 67 mike          1.3      if (!text)
 68 kumpf         1.4      {
 69                            PEG_METHOD_EXIT();
 70 mike          1.3  	throw NullPointer();
 71 kumpf         1.4      }
 72 mike          1.3  
 73                        statement.clear();
 74 mike          1.2  
 75 karl          1.17     globalParserState = new WQLParserState;
 76 mike          1.2      globalParserState->error = false;
 77                        globalParserState->text = text;
 78 a.dunfey      1.22     globalParserState->textSize = (Uint32)(strlen(text) + 1);
 79 mike          1.2      globalParserState->offset = 0;
 80                        globalParserState->statement = &statement;
 81                    
 82                        WQL_parse();
 83                    
 84                        if (globalParserState->error)
 85                        {
 86                    	String errorMessage = globalParserState->errorMessage;
 87                    	cleanup();
 88 karl          1.17     delete globalParserState;
 89 kumpf         1.4          PEG_METHOD_EXIT();
 90 mike          1.2  	throw ParseError(errorMessage);
 91                        }
 92                    
 93                        cleanup();
 94 karl          1.17     delete globalParserState;
 95 kumpf         1.4      PEG_METHOD_EXIT();
 96 mike          1.2  }
 97                    
 98 mike          1.3  void WQLParser::parse(
 99 mike          1.19     const Buffer& text,
100 mike          1.3      WQLSelectStatement& statement)
101                    {
102 kumpf         1.4      PEG_METHOD_ENTER(TRC_WQL,"WQLParser::parse");
103                    
104 kumpf         1.23     parse(text.getData(), statement);
105 mike          1.3  
106 kumpf         1.4      PEG_METHOD_EXIT();
107 mike          1.3  }
108                    
109                    void WQLParser::parse(
110                        const String& text,
111                        WQLSelectStatement& statement)
112                    {
113 kumpf         1.4      PEG_METHOD_ENTER(TRC_WQL,"WQLParser::parse");
114                    
115 kumpf         1.9      parse(text.getCString(), statement);
116 kumpf         1.4  
117                        PEG_METHOD_EXIT();
118 mike          1.3  }
119                    
120 mike          1.2  void WQLParser::cleanup()
121                    {
122 kumpf         1.4      PEG_METHOD_ENTER(TRC_WQL,"WQLParser::cleanup");
123                    
124 mike          1.2      Array<char*>& arr = globalParserState->outstandingStrings;
125                    
126                        for (Uint32 i = 0, n = arr.size(); i < n; i++)
127                    	delete [] arr[i];
128                    
129                        arr.clear();
130 kumpf         1.4  
131                        PEG_METHOD_EXIT();
132 mike          1.2  }
133                    
134                    PEGASUS_NAMESPACE_END
135                    
136                    PEGASUS_USING_PEGASUS;
137                    
138 kumpf         1.8  int WQL_error(const char* errorMessage)
139 mike          1.2  {
140 kumpf         1.4      PEG_METHOD_ENTER(TRC_WQL,"WQL_error");
141                    
142 mike          1.2      globalParserState->error = true;
143                        globalParserState->errorMessage = errorMessage;
144 kumpf         1.10 
145                        //
146                        //  flex does not automatically flush the input buffer in case of error
147                        //
148                        WQL_restart (0);
149 kumpf         1.4  
150                        PEG_METHOD_EXIT();
151 mike          1.2      return -1;
152                    }
153                    
154                    int WQLInput(char* buffer, int& numRead, int numRequested)
155                    {
156 kumpf         1.4      PEG_METHOD_ENTER(TRC_WQL,"WQLInput");
157 mike          1.2      //
158                        // Be sure to account for the null terminator (the size of the text will
159                        // be one or more; this is fixed checked beforehand by WQLParser::parse()).
160                        //
161                    
162                        int remaining = 
163 mike          1.3  	globalParserState->textSize - globalParserState->offset - 1;
164 mike          1.2  
165                        if (remaining == 0)
166                        {
167                    	numRead = 0;
168 kumpf         1.4          PEG_METHOD_EXIT();
169 mike          1.2  	return 0;
170                        }
171                    
172                        if (remaining < numRequested)
173                    	numRequested = remaining;
174                    
175                        memcpy(buffer, 
176 mike          1.3  	globalParserState->text + globalParserState->offset, 
177 mike          1.2  	numRequested);
178                    
179                        globalParserState->offset += numRequested;
180                        numRead = numRequested;
181                    
182 kumpf         1.4      PEG_METHOD_EXIT();
183 mike          1.2      return numRead;
184                    }

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2