Fix compiler errors
[supertux.git] / src / lisp / lexer.cpp
index 451cb9a..cd4ab64 100644 (file)
@@ -1,12 +1,10 @@
-//  $Id$
-//
 //  SuperTux
 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
 //
-//  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 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 3 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
 //  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 <config.h>
+//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+#include "lisp/lexer.hpp"
 
+#include <string.h>
 #include <sstream>
-#include <cstring>
 #include <stdexcept>
-#include <iostream>
-
-#include "lexer.hpp"
-
-namespace lisp
-{
-
-Lexer::Lexer(std::istream& newstream)
-    : stream(newstream), eof(false), linenumber(0)
+#include <stdio.h>
+
+namespace lisp {
+
+Lexer::Lexer(std::istream& newstream) :
+  stream(newstream),
+  eof(false),
+  linenumber(0),
+  bufend(),
+  bufpos(),
+  c(),
+  token_string(),
+  token_length()
 {
   // trigger a refill of the buffer
   bufpos = NULL;
@@ -44,7 +46,7 @@ Lexer::~Lexer()
 void
 Lexer::nextChar()
 {
-  if(bufpos >= bufend) {
+  if(bufpos >= bufend || (bufpos == NULL && bufend == NULL) /* Initial refill trigger */) {
     if(eof) {
       c = EOF;
       return;
@@ -102,39 +104,40 @@ Lexer::getNextToken()
       return TOKEN_CLOSE_PAREN;
     case '"': {  // string
       int startline = linenumber;
-      nextChar();
       while(1) {
+        nextChar();
         switch(c) {
-        case '"':
-          nextChar();
-          goto string_finished;
-        case '\r':
-          continue;
-        case '\n':
-          break;
-        case '\\':
-          nextChar();
-          switch(c) {
-          case 'n':
-            c = '\n';
+          case '"':
+            nextChar();
+            goto string_finished;
+          case '\r':
+            continue;
+          case '\n':
             break;
-          case 't':
-            c = '\t';
+          case '\\':
+            nextChar();
+            switch(c) {
+              case 'n':
+                c = '\n';
+                break;
+              case 't':
+                c = '\t';
+                break;
+            }
             break;
+          case EOF: {
+            std::stringstream msg;
+            msg << "Parse error in line " << startline << ": "
+                << "EOF while parsing string.";
+            throw std::runtime_error(msg.str());
           }
-          break;
-        case EOF: {
-          std::stringstream msg;
-          msg << "Parse error in line " << startline << ": "
-              << "EOF while parsing string.";
-          throw std::runtime_error(msg.str());
-        }
-        default:
-          break;
+          default:
+            break;
         }
-        addChar();
+        if(token_length < MAX_TOKEN_LENGTH)
+          token_string[token_length++] = c;
       }
-string_finished:
+      string_finished:
       token_string[token_length] = 0;
       return TOKEN_STRING;
     }
@@ -203,3 +206,5 @@ string_finished:
 }
 
 } // end of namespace lisp
+
+/* EOF */