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

  1 mike  1.2 //%/////////////////////////////////////////////////////////////////////////////
  2           //
  3           // Copyright (c) 2000, 2001 BMC Software, Hewlett-Packard Company, IBM, 
  4           // The Open Group, Tivoli Systems
  5           //
  6           // Permission is hereby granted, free of charge, to any person obtaining a copy
  7           // of this software and associated documentation files (the "Software"), to 
  8           // deal in the Software without restriction, including without limitation the 
  9           // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 
 10           // sell copies of the Software, and to permit persons to whom the Software is
 11           // furnished to do so, subject to the following conditions:
 12           // 
 13           // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN 
 14           // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
 15           // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 16           // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 
 17           // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 
 18           // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 
 19           // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 20           // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 21           //
 22 mike  1.2 //==============================================================================
 23           //
 24           // Author: Mike Brasher (mbrasher@bmc.com)
 25           //
 26           // Modified By:
 27           //
 28           //%/////////////////////////////////////////////////////////////////////////////
 29           
 30           #include <Pegasus/Common/Config.h>
 31           #include <Pegasus/Common/Exception.h>
 32 mike  1.3 #include <Pegasus/Common/Destroyer.h>
 33 mike  1.2 #include <iostream>
 34           #include "WQLParser.h"
 35           #include "WQLParserState.h"
 36           
 37           PEGASUS_USING_STD;
 38           
 39           extern int WQL_parse();
 40           
 41           PEGASUS_NAMESPACE_BEGIN
 42           
 43           WQLParserState* globalParserState = 0;
 44           
 45           void WQLParser::parse(
 46 mike  1.3     const char* text,
 47 mike  1.2     WQLSelectStatement& statement)
 48           {
 49 mike  1.3     if (!text)
 50           	throw NullPointer();
 51           
 52               statement.clear();
 53 mike  1.2 
 54               globalParserState = new WQLParserState;
 55               globalParserState->error = false;
 56               globalParserState->text = text;
 57 mike  1.3     globalParserState->textSize = strlen(text) + 1;
 58 mike  1.2     globalParserState->offset = 0;
 59               globalParserState->statement = &statement;
 60           
 61               WQL_parse();
 62           
 63               if (globalParserState->error)
 64               {
 65           	String errorMessage = globalParserState->errorMessage;
 66           	cleanup();
 67           	delete globalParserState;
 68           	throw ParseError(errorMessage);
 69               }
 70           
 71               cleanup();
 72               delete globalParserState;
 73           }
 74           
 75 mike  1.3 void WQLParser::parse(
 76               const Array<Sint8>& text,
 77               WQLSelectStatement& statement)
 78           {
 79               if (text.size() == 0 || text[text.size() - 1] != '\0')
 80           	throw MissingNullTerminator();
 81           
 82               parse(text.getData(), statement);
 83           }
 84           
 85           void WQLParser::parse(
 86               const String& text,
 87               WQLSelectStatement& statement)
 88           {
 89               char* tmpText = text.allocateCString();
 90               ArrayDestroyer<char> destroyer(tmpText);
 91               parse(tmpText, statement);
 92           }
 93           
 94 mike  1.2 void WQLParser::cleanup()
 95           {
 96               Array<char*>& arr = globalParserState->outstandingStrings;
 97           
 98               for (Uint32 i = 0, n = arr.size(); i < n; i++)
 99           	delete [] arr[i];
100           
101               arr.clear();
102           }
103           
104           PEGASUS_NAMESPACE_END
105           
106           PEGASUS_USING_PEGASUS;
107           
108           int WQL_error(char* errorMessage)
109           {
110               globalParserState->error = true;
111               globalParserState->errorMessage = errorMessage;
112               return -1;
113           }
114           
115 mike  1.2 int WQLInput(char* buffer, int& numRead, int numRequested)
116           {
117               //
118               // Be sure to account for the null terminator (the size of the text will
119               // be one or more; this is fixed checked beforehand by WQLParser::parse()).
120               //
121           
122               int remaining = 
123 mike  1.3 	globalParserState->textSize - globalParserState->offset - 1;
124 mike  1.2 
125               if (remaining == 0)
126               {
127           	numRead = 0;
128           	return 0;
129               }
130           
131               if (remaining < numRequested)
132           	numRequested = remaining;
133           
134               memcpy(buffer, 
135 mike  1.3 	globalParserState->text + globalParserState->offset, 
136 mike  1.2 	numRequested);
137           
138               globalParserState->offset += numRequested;
139               numRead = numRequested;
140           
141               return numRead;
142           }

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2