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

  1 mike  1.2 //%/////////////////////////////////////////////////////////////////////////////
  2           //
  3 kumpf 1.6 // Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Company, IBM,
  4 mike  1.2 // The Open Group, Tivoli Systems
  5           //
  6           // Permission is hereby granted, free of charge, to any person obtaining a copy
  7 kumpf 1.6 // 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 mike  1.2 // 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 kumpf 1.6 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 14 mike  1.2 // 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 kumpf 1.6 // 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 mike  1.2 // 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           //==============================================================================
 23           //
 24           // Author: Mike Brasher (mbrasher@bmc.com)
 25           //
 26           // Modified By:
 27           //
 28           //%/////////////////////////////////////////////////////////////////////////////
 29           
 30           #include <Pegasus/Common/Config.h>
 31 kumpf 1.7 #include <Pegasus/Common/InternalException.h>
 32 mike  1.3 #include <Pegasus/Common/Destroyer.h>
 33 kumpf 1.4 #include <Pegasus/Common/Tracer.h>
 34 kumpf 1.5 #include <Pegasus/Common/PegasusVersion.h>
 35           
 36 mike  1.2 #include <iostream>
 37           #include "WQLParser.h"
 38           #include "WQLParserState.h"
 39           
 40           PEGASUS_USING_STD;
 41           
 42           extern int WQL_parse();
 43 mday  1.9.12.1 extern void WQL_restart (FILE *input_file);
 44 mike  1.2      
 45                PEGASUS_NAMESPACE_BEGIN
 46                
 47                WQLParserState* globalParserState = 0;
 48                
 49                void WQLParser::parse(
 50 mike  1.3          const char* text,
 51 mike  1.2          WQLSelectStatement& statement)
 52                {
 53 kumpf 1.4          PEG_METHOD_ENTER(TRC_WQL,"WQLParser::parse");
 54                
 55 mike  1.3          if (!text)
 56 kumpf 1.4          {
 57                        PEG_METHOD_EXIT();
 58 mike  1.3      	throw NullPointer();
 59 kumpf 1.4          }
 60 mike  1.3      
 61                    statement.clear();
 62 mike  1.2      
 63                    globalParserState = new WQLParserState;
 64                    globalParserState->error = false;
 65                    globalParserState->text = text;
 66 mike  1.3          globalParserState->textSize = strlen(text) + 1;
 67 mike  1.2          globalParserState->offset = 0;
 68                    globalParserState->statement = &statement;
 69                
 70                    WQL_parse();
 71                
 72                    if (globalParserState->error)
 73                    {
 74                	String errorMessage = globalParserState->errorMessage;
 75                	cleanup();
 76                	delete globalParserState;
 77 kumpf 1.4              PEG_METHOD_EXIT();
 78 mike  1.2      	throw ParseError(errorMessage);
 79                    }
 80                
 81                    cleanup();
 82                    delete globalParserState;
 83 kumpf 1.4          PEG_METHOD_EXIT();
 84 mike  1.2      }
 85                
 86 mike  1.3      void WQLParser::parse(
 87                    const Array<Sint8>& text,
 88                    WQLSelectStatement& statement)
 89                {
 90 kumpf 1.4          PEG_METHOD_ENTER(TRC_WQL,"WQLParser::parse");
 91                
 92 mike  1.3          if (text.size() == 0 || text[text.size() - 1] != '\0')
 93 kumpf 1.4          {
 94                        PEG_METHOD_EXIT();
 95 mike  1.3      	throw MissingNullTerminator();
 96 kumpf 1.4          }
 97 mike  1.3      
 98                    parse(text.getData(), statement);
 99 kumpf 1.4          PEG_METHOD_EXIT();
100 mike  1.3      }
101                
102                void WQLParser::parse(
103                    const String& text,
104                    WQLSelectStatement& statement)
105                {
106 kumpf 1.4          PEG_METHOD_ENTER(TRC_WQL,"WQLParser::parse");
107                
108 kumpf 1.9          parse(text.getCString(), statement);
109 kumpf 1.4      
110                    PEG_METHOD_EXIT();
111 mike  1.3      }
112                
113 mike  1.2      void WQLParser::cleanup()
114                {
115 kumpf 1.4          PEG_METHOD_ENTER(TRC_WQL,"WQLParser::cleanup");
116                
117 mike  1.2          Array<char*>& arr = globalParserState->outstandingStrings;
118                
119                    for (Uint32 i = 0, n = arr.size(); i < n; i++)
120                	delete [] arr[i];
121                
122                    arr.clear();
123 kumpf 1.4      
124                    PEG_METHOD_EXIT();
125 mike  1.2      }
126                
127                PEGASUS_NAMESPACE_END
128                
129                PEGASUS_USING_PEGASUS;
130                
131 kumpf 1.8      int WQL_error(const char* errorMessage)
132 mike  1.2      {
133 kumpf 1.4          PEG_METHOD_ENTER(TRC_WQL,"WQL_error");
134                
135 mike  1.2          globalParserState->error = true;
136                    globalParserState->errorMessage = errorMessage;
137 mday  1.9.12.1 
138                    //
139                    //  flex does not automatically flush the input buffer in case of error
140                    //
141                    WQL_restart (0);
142 kumpf 1.4      
143                    PEG_METHOD_EXIT();
144 mike  1.2          return -1;
145                }
146                
147                int WQLInput(char* buffer, int& numRead, int numRequested)
148                {
149 kumpf 1.4          PEG_METHOD_ENTER(TRC_WQL,"WQLInput");
150 mike  1.2          //
151                    // Be sure to account for the null terminator (the size of the text will
152                    // be one or more; this is fixed checked beforehand by WQLParser::parse()).
153                    //
154                
155                    int remaining = 
156 mike  1.3      	globalParserState->textSize - globalParserState->offset - 1;
157 mike  1.2      
158                    if (remaining == 0)
159                    {
160                	numRead = 0;
161 kumpf 1.4              PEG_METHOD_EXIT();
162 mike  1.2      	return 0;
163                    }
164                
165                    if (remaining < numRequested)
166                	numRequested = remaining;
167                
168                    memcpy(buffer, 
169 mike  1.3      	globalParserState->text + globalParserState->offset, 
170 mike  1.2      	numRequested);
171                
172                    globalParserState->offset += numRequested;
173                    numRead = numRequested;
174                
175 kumpf 1.4          PEG_METHOD_EXIT();
176 mike  1.2          return numRead;
177                }

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2