/* Copyright (C) 2003 MySQL AB This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include "Parser.hpp" #include #include #include #undef DEBUG #define DEBUG(x) ndbout << x << endl; static void trim(char * str); class ParseInputStream : public InputStream { public: ParseInputStream(InputStream & in, bool trim = true, char eofComment = '#'); char* gets(char * buf, int bufLen); void push_back(const char *); private: InputStream & in; char * buffer; }; ParseInputStream::ParseInputStream(InputStream & _in, bool /* unused */, char /* unused */) : in(_in){ buffer = 0; } char* ParseInputStream::gets(char * buf, int bufLen){ if(buffer != 0){ strncpy(buf, buffer, bufLen); free(buffer); buffer = 0; return buf; } char *t = in.gets(buf, bufLen); return t; } void ParseInputStream::push_back(const char * str){ if(buffer != 0) abort(); buffer = strdup(str); } ParserImpl::ParserImpl(const DummyRow * rows, InputStream & in, bool b_cmd, bool b_empty, bool b_iarg) : m_rows(rows), input(* new ParseInputStream(in)) { m_breakOnCmd = b_cmd; m_breakOnEmpty = b_empty; m_breakOnInvalidArg = b_iarg; } ParserImpl::~ParserImpl(){ delete & input; } static bool Empty(const char * str){ if(str == 0) return true; const int len = strlen(str); if(len == 0) return false; for(int i = 0; i