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

  1 martin 1.25 //%LICENSE////////////////////////////////////////////////////////////////
  2 martin 1.26 //
  3 martin 1.25 // Licensed to The Open Group (TOG) under one or more contributor license
  4             // agreements.  Refer to the OpenPegasusNOTICE.txt file distributed with
  5             // this work for additional information regarding copyright ownership.
  6             // Each contributor licenses this file to you under the OpenPegasus Open
  7             // Source License; you may not use this file except in compliance with the
  8             // License.
  9 martin 1.26 //
 10 martin 1.25 // Permission is hereby granted, free of charge, to any person obtaining a
 11             // copy of this software and associated documentation files (the "Software"),
 12             // to deal in the Software without restriction, including without limitation
 13             // the rights to use, copy, modify, merge, publish, distribute, sublicense,
 14             // and/or sell copies of the Software, and to permit persons to whom the
 15             // Software is furnished to do so, subject to the following conditions:
 16 martin 1.26 //
 17 martin 1.25 // The above copyright notice and this permission notice shall be included
 18             // in all copies or substantial portions of the Software.
 19 martin 1.26 //
 20 martin 1.25 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 21 martin 1.26 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 22 martin 1.25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 23             // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 24             // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 25             // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 26             // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 27 martin 1.26 //
 28 martin 1.25 //////////////////////////////////////////////////////////////////////////
 29 mike   1.2  //
 30             //%/////////////////////////////////////////////////////////////////////////////
 31             
 32             #include <Pegasus/Common/Config.h>
 33 kumpf  1.7  #include <Pegasus/Common/InternalException.h>
 34 kumpf  1.4  #include <Pegasus/Common/Tracer.h>
 35 kumpf  1.5  #include <Pegasus/Common/PegasusVersion.h>
 36 mike   1.21 #include <Pegasus/Common/Mutex.h>
 37 mike   1.2  #include <iostream>
 38             #include "WQLParser.h"
 39             #include "WQLParserState.h"
 40             
 41             PEGASUS_USING_STD;
 42             
 43             extern int WQL_parse();
 44 kumpf  1.10 extern void WQL_restart (FILE *input_file);
 45 mike   1.2  
 46             PEGASUS_NAMESPACE_BEGIN
 47             
 48 kumpf  1.27 WQLParserState* globalParserState = 0;
 49 humberto 1.13 static Mutex WQL_mutex;
 50 mike     1.2  
 51               void WQLParser::parse(
 52 mike     1.3      const char* text,
 53 mike     1.2      WQLSelectStatement& statement)
 54               {
 55 kumpf    1.4      PEG_METHOD_ENTER(TRC_WQL,"WQLParser::parse");
 56 kumpf    1.27 
 57 karl     1.24      AutoMutex mtx(WQL_mutex);
 58 kumpf    1.4  
 59 mike     1.3      if (!text)
 60 kumpf    1.4      {
 61                       PEG_METHOD_EXIT();
 62 karl     1.24         throw NullPointer();
 63 kumpf    1.4      }
 64 mike     1.3  
 65                   statement.clear();
 66 mike     1.2  
 67 karl     1.17     globalParserState = new WQLParserState;
 68 mike     1.2      globalParserState->error = false;
 69                   globalParserState->text = text;
 70 a.dunfey 1.22     globalParserState->textSize = (Uint32)(strlen(text) + 1);
 71 mike     1.2      globalParserState->offset = 0;
 72                   globalParserState->statement = &statement;
 73               
 74                   WQL_parse();
 75               
 76                   if (globalParserState->error)
 77                   {
 78 karl     1.24         String errorMessage = globalParserState->errorMessage;
 79                       cleanup();
 80                       delete globalParserState;
 81 kumpf    1.4          PEG_METHOD_EXIT();
 82 karl     1.24         throw ParseError(errorMessage);
 83 mike     1.2      }
 84               
 85                   cleanup();
 86 karl     1.17     delete globalParserState;
 87 kumpf    1.4      PEG_METHOD_EXIT();
 88 mike     1.2  }
 89               
 90 mike     1.3  void WQLParser::parse(
 91 mike     1.19     const Buffer& text,
 92 mike     1.3      WQLSelectStatement& statement)
 93               {
 94 kumpf    1.4      PEG_METHOD_ENTER(TRC_WQL,"WQLParser::parse");
 95               
 96 kumpf    1.23     parse(text.getData(), statement);
 97 mike     1.3  
 98 kumpf    1.4      PEG_METHOD_EXIT();
 99 mike     1.3  }
100               
101               void WQLParser::parse(
102                   const String& text,
103                   WQLSelectStatement& statement)
104               {
105 kumpf    1.4      PEG_METHOD_ENTER(TRC_WQL,"WQLParser::parse");
106               
107 kumpf    1.9      parse(text.getCString(), statement);
108 kumpf    1.4  
109                   PEG_METHOD_EXIT();
110 mike     1.3  }
111               
112 mike     1.2  void WQLParser::cleanup()
113               {
114 kumpf    1.4      PEG_METHOD_ENTER(TRC_WQL,"WQLParser::cleanup");
115               
116 mike     1.2      Array<char*>& arr = globalParserState->outstandingStrings;
117               
118                   for (Uint32 i = 0, n = arr.size(); i < n; i++)
119 karl     1.24         delete [] arr[i];
120 mike     1.2  
121                   arr.clear();
122 kumpf    1.4  
123                   PEG_METHOD_EXIT();
124 mike     1.2  }
125               
126               PEGASUS_NAMESPACE_END
127               
128               PEGASUS_USING_PEGASUS;
129               
130 kumpf    1.8  int WQL_error(const char* errorMessage)
131 mike     1.2  {
132 kumpf    1.4      PEG_METHOD_ENTER(TRC_WQL,"WQL_error");
133               
134 mike     1.2      globalParserState->error = true;
135                   globalParserState->errorMessage = errorMessage;
136 kumpf    1.10 
137                   //
138                   //  flex does not automatically flush the input buffer in case of error
139                   //
140                   WQL_restart (0);
141 kumpf    1.4  
142                   PEG_METHOD_EXIT();
143 mike     1.2      return -1;
144               }
145               
146               int WQLInput(char* buffer, int& numRead, int numRequested)
147               {
148 kumpf    1.4      PEG_METHOD_ENTER(TRC_WQL,"WQLInput");
149 mike     1.2      //
150                   // Be sure to account for the null terminator (the size of the text will
151                   // be one or more; this is fixed checked beforehand by WQLParser::parse()).
152                   //
153               
154 kumpf    1.27     int remaining =
155 karl     1.24         globalParserState->textSize - globalParserState->offset - 1;
156 mike     1.2  
157                   if (remaining == 0)
158                   {
159 karl     1.24         numRead = 0;
160 kumpf    1.4          PEG_METHOD_EXIT();
161 karl     1.24         return 0;
162 mike     1.2      }
163               
164                   if (remaining < numRequested)
165 karl     1.24         numRequested = remaining;
166 mike     1.2  
167 kumpf    1.27     memcpy(buffer,
168                   globalParserState->text + globalParserState->offset,
169 karl     1.24     numRequested);
170 mike     1.2  
171                   globalParserState->offset += numRequested;
172                   numRead = numRequested;
173               
174 kumpf    1.4      PEG_METHOD_EXIT();
175 mike     1.2      return numRead;
176               }

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2