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

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2