From 72cc0a39839a1b30d652590355198ed0877c0c2c Mon Sep 17 00:00:00 2001
From: Marc Zinnschlag <marc@zpages.de>
Date: Sun, 22 Aug 2010 09:17:05 +0200
Subject: [PATCH 01/32] fixed typo in documentation

---
 components/interpreter/docs/vmformat.txt | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/components/interpreter/docs/vmformat.txt b/components/interpreter/docs/vmformat.txt
index 40ce3535b6..291d1c490c 100644
--- a/components/interpreter/docs/vmformat.txt
+++ b/components/interpreter/docs/vmformat.txt
@@ -31,8 +31,8 @@ B: argument 1
 
 Segment 0:
 op  0: push arg0
-op  1: move pv ahead by arg0
-op  2: move pv back by arg0
+op  1: move pc ahead by arg0
+op  2: move pc back by arg0
 opcodes 3-31 unused
 opcodes 32-63 reserved for extensions
 
@@ -119,4 +119,3 @@ op  57: explicit reference = stack[0]; pop;
         replace stack[0] with distance between explicit reference and a reference of ID stack[0]
 opcodes 58-33554431 unused
 opcodes 33554432-67108863 reserved for extensions
-

From 276a9db6f7a4029215ba232ec5a1b7a1e05f07f8 Mon Sep 17 00:00:00 2001
From: Marc Zinnschlag <marc@zpages.de>
Date: Sun, 22 Aug 2010 11:14:14 +0200
Subject: [PATCH 02/32] added missing button implementation for MessageBox

---
 apps/openmw/mwgui/console.cpp          |  35 ++-
 components/compiler/generator.cpp      | 339 ++++++++++++-------------
 components/compiler/lineparser.cpp     | 185 ++++++++------
 components/compiler/lineparser.hpp     |  21 +-
 components/interpreter/miscopcodes.hpp | 134 +++++-----
 5 files changed, 367 insertions(+), 347 deletions(-)

diff --git a/apps/openmw/mwgui/console.cpp b/apps/openmw/mwgui/console.cpp
index d9148028f2..468cae456b 100644
--- a/apps/openmw/mwgui/console.cpp
+++ b/apps/openmw/mwgui/console.cpp
@@ -10,16 +10,16 @@ namespace MWGui
     class ConsoleInterpreterContext : public MWScript::InterpreterContext
     {
             Console& mConsole;
-            
+
         public:
-        
-            ConsoleInterpreterContext (Console& console, MWWorld::Environment& environment, 
+
+            ConsoleInterpreterContext (Console& console, MWWorld::Environment& environment,
                 MWWorld::Ptr reference);
 
             virtual void messageBox (const std::string& message,
-                const std::vector<std::string>& buttons);     
+                const std::vector<std::string>& buttons);
     };
-    
+
     ConsoleInterpreterContext::ConsoleInterpreterContext (Console& console,
         MWWorld::Environment& environment, MWWorld::Ptr reference)
     : MWScript::InterpreterContext (environment,
@@ -39,18 +39,18 @@ namespace MWGui
     bool Console::compile (const std::string& cmd, Compiler::Output& output)
     {
         try
-        {        
+        {
             ErrorHandler::reset();
-        
+
             std::istringstream input (cmd + '\n');
-        
+
             Compiler::Scanner scanner (*this, input, mCompilerContext.getExtensions());
-        
+
             Compiler::LineParser parser (*this, mCompilerContext, output.getLocals(),
                 output.getLiterals(), output.getCode(), true);
-        
+
             scanner.scan (parser);
-            
+
             return isGood();
         }
         catch (const Compiler::SourceException& error)
@@ -61,7 +61,7 @@ namespace MWGui
         {
             printError (std::string ("An exception has been thrown: ") + error.what());
         }
-                
+
         return false;
     }
 
@@ -69,7 +69,7 @@ namespace MWGui
     {
         std::ostringstream error;
         error << "column " << loc.mColumn << " (" << loc.mLiteral << "):";
-    
+
         printError (error.str());
         printError ((type==ErrorMessage ? "error: " : "warning: ") + message);
     }
@@ -78,7 +78,7 @@ namespace MWGui
     {
         printError ((type==ErrorMessage ? "error: " : "warning: ") + message);
     }
-                
+
     Console::Console(int w, int h, MWWorld::Environment& environment,
         const Compiler::Extensions& extensions)
       : Layout("openmw_console_layout.xml"),
@@ -100,7 +100,7 @@ namespace MWGui
         history->setOverflowToTheLeft(true);
         history->setEditStatic(true);
         history->setVisibleVScroll(true);
-      
+
         // compiler
         mCompilerContext.setExtensions (&extensions);
     }
@@ -196,7 +196,7 @@ namespace MWGui
         Compiler::Locals locals;
         Compiler::Output output (locals);
 
-        if (compile (cm, output))
+        if (compile (cm + "\n", output))
         {
             try
             {
@@ -205,7 +205,7 @@ namespace MWGui
                 MWScript::installOpcodes (interpreter);
                 std::vector<Interpreter::Type_Code> code;
                 output.getCode (code);
-                interpreter.run (&code[0], code.size());  
+                interpreter.run (&code[0], code.size());
             }
             catch (const std::exception& error)
             {
@@ -216,4 +216,3 @@ namespace MWGui
         command->setCaption("");
     }
 }
-
diff --git a/components/compiler/generator.cpp b/components/compiler/generator.cpp
index 0be2c41511..c5262616bc 100644
--- a/components/compiler/generator.cpp
+++ b/components/compiler/generator.cpp
@@ -9,46 +9,46 @@
 #include "literals.hpp"
 
 namespace
-{   
+{
     void opPushInt (Compiler::Generator::CodeContainer& code, int value)
     {
         code.push_back (Compiler::Generator::segment0 (0, value));
     }
-    
+
     void opFetchIntLiteral (Compiler::Generator::CodeContainer& code)
     {
         code.push_back (Compiler::Generator::segment5 (4));
     }
-    
+
     void opFetchFloatLiteral (Compiler::Generator::CodeContainer& code)
     {
         code.push_back (Compiler::Generator::segment5 (5));
     }
-    
+
     void opIntToFloat (Compiler::Generator::CodeContainer& code)
     {
-        code.push_back (Compiler::Generator::segment5 (3));    
+        code.push_back (Compiler::Generator::segment5 (3));
     }
-    
+
     void opFloatToInt (Compiler::Generator::CodeContainer& code)
     {
         code.push_back (Compiler::Generator::segment5 (6));
     }
-        
+
     void opStoreLocalShort (Compiler::Generator::CodeContainer& code)
     {
-        code.push_back (Compiler::Generator::segment5 (0));    
+        code.push_back (Compiler::Generator::segment5 (0));
     }
-    
+
     void opStoreLocalLong (Compiler::Generator::CodeContainer& code)
     {
         code.push_back (Compiler::Generator::segment5 (1));
     }
-    
+
     void opStoreLocalFloat (Compiler::Generator::CodeContainer& code)
     {
         code.push_back (Compiler::Generator::segment5 (2));
-    }        
+    }
 
     void opNegateInt (Compiler::Generator::CodeContainer& code)
     {
@@ -99,46 +99,46 @@ namespace
     {
         code.push_back (Compiler::Generator::segment5 (16));
     }
-    
+
     void opIntToFloat1 (Compiler::Generator::CodeContainer& code)
     {
-        code.push_back (Compiler::Generator::segment5 (17));    
+        code.push_back (Compiler::Generator::segment5 (17));
     }
-    
+
     void opFloatToInt1 (Compiler::Generator::CodeContainer& code)
     {
         code.push_back (Compiler::Generator::segment5 (18));
-    }    
+    }
 
     void opSquareRoot (Compiler::Generator::CodeContainer& code)
     {
         code.push_back (Compiler::Generator::segment5 (19));
-    }    
+    }
 
     void opReturn (Compiler::Generator::CodeContainer& code)
     {
         code.push_back (Compiler::Generator::segment5 (20));
-    }       
-    
+    }
+
     void opMessageBox (Compiler::Generator::CodeContainer& code, int buttons)
     {
         code.push_back (Compiler::Generator::segment3 (0, buttons));
     }
-    
+
     void opFetchLocalShort (Compiler::Generator::CodeContainer& code)
     {
-        code.push_back (Compiler::Generator::segment5 (21));    
+        code.push_back (Compiler::Generator::segment5 (21));
     }
-    
+
     void opFetchLocalLong (Compiler::Generator::CodeContainer& code)
     {
         code.push_back (Compiler::Generator::segment5 (22));
     }
-    
+
     void opFetchLocalFloat (Compiler::Generator::CodeContainer& code)
     {
         code.push_back (Compiler::Generator::segment5 (23));
-    }    
+    }
 
     void opJumpForward (Compiler::Generator::CodeContainer& code, int offset)
     {
@@ -149,176 +149,176 @@ namespace
     {
         code.push_back (Compiler::Generator::segment0 (2, offset));
     }
-    
+
     void opSkipOnZero (Compiler::Generator::CodeContainer& code)
     {
         code.push_back (Compiler::Generator::segment5 (24));
-    }      
-    
+    }
+
     void opSkipOnNonZero (Compiler::Generator::CodeContainer& code)
     {
         code.push_back (Compiler::Generator::segment5 (25));
-    }      
-    
+    }
+
     void opEqualInt (Compiler::Generator::CodeContainer& code)
     {
         code.push_back (Compiler::Generator::segment5 (26));
     }
-    
+
     void opNonEqualInt (Compiler::Generator::CodeContainer& code)
     {
-        code.push_back (Compiler::Generator::segment5 (27)); 
+        code.push_back (Compiler::Generator::segment5 (27));
     }
-    
+
     void opLessThanInt (Compiler::Generator::CodeContainer& code)
     {
-        code.push_back (Compiler::Generator::segment5 (28));     
+        code.push_back (Compiler::Generator::segment5 (28));
     }
-    
+
     void opLessOrEqualInt (Compiler::Generator::CodeContainer& code)
     {
-        code.push_back (Compiler::Generator::segment5 (29));     
+        code.push_back (Compiler::Generator::segment5 (29));
     }
-    
+
     void opGreaterThanInt (Compiler::Generator::CodeContainer& code)
     {
-        code.push_back (Compiler::Generator::segment5 (30));     
+        code.push_back (Compiler::Generator::segment5 (30));
     }
-    
+
     void opGreaterOrEqualInt (Compiler::Generator::CodeContainer& code)
     {
-        code.push_back (Compiler::Generator::segment5 (31));     
+        code.push_back (Compiler::Generator::segment5 (31));
     }
-    
+
     void opEqualFloat (Compiler::Generator::CodeContainer& code)
     {
         code.push_back (Compiler::Generator::segment5 (32));
     }
-    
+
     void opNonEqualFloat (Compiler::Generator::CodeContainer& code)
     {
-        code.push_back (Compiler::Generator::segment5 (33)); 
+        code.push_back (Compiler::Generator::segment5 (33));
     }
-    
+
     void opLessThanFloat (Compiler::Generator::CodeContainer& code)
     {
-        code.push_back (Compiler::Generator::segment5 (34));     
+        code.push_back (Compiler::Generator::segment5 (34));
     }
-    
+
     void opLessOrEqualFloat (Compiler::Generator::CodeContainer& code)
     {
-        code.push_back (Compiler::Generator::segment5 (35));     
+        code.push_back (Compiler::Generator::segment5 (35));
     }
-    
+
     void opGreaterThanFloat (Compiler::Generator::CodeContainer& code)
     {
-        code.push_back (Compiler::Generator::segment5 (36));     
+        code.push_back (Compiler::Generator::segment5 (36));
     }
-    
+
     void opGreaterOrEqualFloat (Compiler::Generator::CodeContainer& code)
     {
-        code.push_back (Compiler::Generator::segment5 (37));     
-    }    
+        code.push_back (Compiler::Generator::segment5 (37));
+    }
 
     void opMenuMode (Compiler::Generator::CodeContainer& code)
     {
-        code.push_back (Compiler::Generator::segment5 (38));     
-    }      
-    
+        code.push_back (Compiler::Generator::segment5 (38));
+    }
+
     void opStoreGlobalShort (Compiler::Generator::CodeContainer& code)
     {
-        code.push_back (Compiler::Generator::segment5 (39));    
+        code.push_back (Compiler::Generator::segment5 (39));
     }
-    
+
     void opStoreGlobalLong (Compiler::Generator::CodeContainer& code)
     {
         code.push_back (Compiler::Generator::segment5 (40));
     }
-    
+
     void opStoreGlobalFloat (Compiler::Generator::CodeContainer& code)
     {
         code.push_back (Compiler::Generator::segment5 (41));
-    }              
+    }
 
     void opFetchGlobalShort (Compiler::Generator::CodeContainer& code)
     {
-        code.push_back (Compiler::Generator::segment5 (42));    
+        code.push_back (Compiler::Generator::segment5 (42));
     }
-    
+
     void opFetchGlobalLong (Compiler::Generator::CodeContainer& code)
     {
         code.push_back (Compiler::Generator::segment5 (43));
     }
-    
+
     void opFetchGlobalFloat (Compiler::Generator::CodeContainer& code)
     {
         code.push_back (Compiler::Generator::segment5 (44));
-    }    
-    
+    }
+
     void opRandom (Compiler::Generator::CodeContainer& code)
     {
         code.push_back (Compiler::Generator::segment5 (45));
-    }    
-    
+    }
+
     void opScriptRunning (Compiler::Generator::CodeContainer& code)
     {
         code.push_back (Compiler::Generator::segment5 (46));
-    }     
-    
+    }
+
     void opStartScript (Compiler::Generator::CodeContainer& code)
     {
         code.push_back (Compiler::Generator::segment5 (47));
-    }     
-    
+    }
+
     void opStopScript (Compiler::Generator::CodeContainer& code)
     {
         code.push_back (Compiler::Generator::segment5 (48));
-    }     
-    
+    }
+
     void opGetDistance (Compiler::Generator::CodeContainer& code)
     {
         code.push_back (Compiler::Generator::segment5 (49));
-    }        
-   
+    }
+
     void opGetSecondsPassed (Compiler::Generator::CodeContainer& code)
     {
         code.push_back (Compiler::Generator::segment5 (50));
-    }       
+    }
 
     void opEnable (Compiler::Generator::CodeContainer& code)
     {
         code.push_back (Compiler::Generator::segment5 (51));
-    }       
+    }
 
     void opDisable (Compiler::Generator::CodeContainer& code)
     {
         code.push_back (Compiler::Generator::segment5 (52));
-    }       
+    }
 
     void opGetDisabled (Compiler::Generator::CodeContainer& code)
     {
         code.push_back (Compiler::Generator::segment5 (53));
-    }       
+    }
 
     void opEnableExplicit (Compiler::Generator::CodeContainer& code)
     {
         code.push_back (Compiler::Generator::segment5 (54));
-    }       
+    }
 
     void opDisableExplicit (Compiler::Generator::CodeContainer& code)
     {
         code.push_back (Compiler::Generator::segment5 (55));
-    }       
+    }
 
     void opGetDisabledExplicit (Compiler::Generator::CodeContainer& code)
     {
         code.push_back (Compiler::Generator::segment5 (56));
     }
-    
+
     void opGetDistanceExplicit (Compiler::Generator::CodeContainer& code)
     {
         code.push_back (Compiler::Generator::segment5 (57));
-    }            
+    }
 }
 
 namespace Compiler
@@ -327,31 +327,31 @@ namespace Compiler
     {
         void pushInt (CodeContainer& code, Literals& literals, int value)
         {
-            int index = literals.addInteger (value);               
+            int index = literals.addInteger (value);
             opPushInt (code, index);
-            opFetchIntLiteral (code);   
+            opFetchIntLiteral (code);
         }
-        
+
         void pushFloat (CodeContainer& code, Literals& literals, float value)
         {
-            int index = literals.addFloat (value);               
+            int index = literals.addFloat (value);
             opPushInt (code, index);
             opFetchFloatLiteral (code);
         }
-                
+
         void pushString (CodeContainer& code, Literals& literals, const std::string& value)
         {
-            int index = literals.addString (value);               
+            int index = literals.addString (value);
             opPushInt (code, index);
         }
-        
+
         void assignToLocal (CodeContainer& code, char localType,
             int localIndex, const CodeContainer& value, char valueType)
-        {               
+        {
             opPushInt (code, localIndex);
 
             std::copy (value.begin(), value.end(), std::back_inserter (code));
-            
+
             if (localType!=valueType)
             {
                 if (localType=='f' && valueType=='l')
@@ -363,26 +363,26 @@ namespace Compiler
                     opFloatToInt (code);
                 }
             }
-            
+
             switch (localType)
             {
                 case 'f':
-                
+
                     opStoreLocalFloat (code);
                     break;
-                
+
                 case 's':
 
                     opStoreLocalShort (code);
                     break;
-                
+
                 case 'l':
 
                     opStoreLocalLong (code);
                     break;
-            
+
                 default:
-                
+
                     assert (0);
             }
         }
@@ -392,21 +392,21 @@ namespace Compiler
             switch (valueType)
             {
                 case 'l':
-                
+
                     opNegateInt (code);
                     break;
-                
+
                 case 'f':
-                
+
                     opNegateFloat (code);
                     break;
-                
+
                 default:
-                
+
                     assert (0);
             }
         }
-        
+
         void add (CodeContainer& code, char valueType1, char valueType2)
         {
             if (valueType1=='l' && valueType2=='l')
@@ -420,7 +420,7 @@ namespace Compiler
 
                 if (valueType2=='l')
                     opIntToFloat (code);
-            
+
                 opAddFloat (code);
             }
         }
@@ -438,11 +438,11 @@ namespace Compiler
 
                 if (valueType2=='l')
                     opIntToFloat (code);
-            
+
                 opSubFloat (code);
             }
         }
-        
+
         void mul (CodeContainer& code, char valueType1, char valueType2)
         {
             if (valueType1=='l' && valueType2=='l')
@@ -456,11 +456,11 @@ namespace Compiler
 
                 if (valueType2=='l')
                     opIntToFloat (code);
-            
+
                 opMulFloat (code);
-            }        
-        }      
-        
+            }
+        }
+
         void div (CodeContainer& code, char valueType1, char valueType2)
         {
             if (valueType1=='l' && valueType2=='l')
@@ -474,11 +474,11 @@ namespace Compiler
 
                 if (valueType2=='l')
                     opIntToFloat (code);
-            
+
                 opDivFloat (code);
-            }        
+            }
         }
-        
+
         void convert (CodeContainer& code, char fromType, char toType)
         {
             if (fromType!=toType)
@@ -491,28 +491,26 @@ namespace Compiler
                     throw std::logic_error ("illegal type conversion");
             }
         }
-        
+
         void squareRoot (CodeContainer& code)
         {
             opSquareRoot (code);
         }
-        
+
         void exit (CodeContainer& code)
         {
             opReturn (code);
-        }        
-        
+        }
+
         void message (CodeContainer& code, Literals& literals, const std::string& message,
             int buttons)
         {
-            assert (buttons==0);
-
             int index = literals.addString (message);
-            
+
             opPushInt (code, index);
             opMessageBox (code, buttons);
         }
-        
+
         void fetchLocal (CodeContainer& code, char localType, int localIndex)
         {
             opPushInt (code, localIndex);
@@ -520,26 +518,26 @@ namespace Compiler
             switch (localType)
             {
                 case 'f':
-                
+
                     opFetchLocalFloat (code);
                     break;
-                
+
                 case 's':
 
                     opFetchLocalShort (code);
                     break;
-                
+
                 case 'l':
 
                     opFetchLocalLong (code);
                     break;
-            
+
                 default:
-                
+
                     assert (0);
-            }        
+            }
         }
-        
+
         void jump (CodeContainer& code, int offset)
         {
             if (offset>0)
@@ -549,27 +547,27 @@ namespace Compiler
             else
                 throw std::logic_error ("inifite loop");
         }
-                
+
         void jumpOnZero (CodeContainer& code, int offset)
         {
             opSkipOnNonZero (code);
-            
+
             if (offset<0)
                 --offset; // compensate for skip instruction
-            
+
             jump (code, offset);
         }
 
         void jumpOnNonZero (CodeContainer& code, int offset)
         {
             opSkipOnZero (code);
-            
+
             if (offset<0)
                 --offset; // compensate for skip instruction
-            
-            jump (code, offset);            
+
+            jump (code, offset);
         }
-        
+
         void compare (CodeContainer& code, char op, char valueType1, char valueType2)
         {
             if (valueType1=='l' && valueType2=='l')
@@ -582,9 +580,9 @@ namespace Compiler
                     case 'L': opLessOrEqualInt (code); break;
                     case 'g': opGreaterThanInt (code); break;
                     case 'G': opGreaterOrEqualInt (code); break;
-                
+
                     default:
-                    
+
                         assert (0);
                 }
             }
@@ -595,7 +593,7 @@ namespace Compiler
 
                 if (valueType2=='l')
                     opIntToFloat (code);
-            
+
                 switch (op)
                 {
                     case 'e': opEqualFloat (code); break;
@@ -604,28 +602,28 @@ namespace Compiler
                     case 'L': opLessOrEqualFloat (code); break;
                     case 'g': opGreaterThanFloat (code); break;
                     case 'G': opGreaterOrEqualFloat (code); break;
-                
+
                     default:
-                    
+
                         assert (0);
                 }
-            }          
+            }
         }
-        
+
         void menuMode (CodeContainer& code)
         {
             opMenuMode (code);
         }
-        
+
         void assignToGlobal (CodeContainer& code, Literals& literals, char localType,
             const std::string& name, const CodeContainer& value, char valueType)
         {
             int index = literals.addString (name);
-        
+
             opPushInt (code, index);
 
             std::copy (value.begin(), value.end(), std::back_inserter (code));
-            
+
             if (localType!=valueType)
             {
                 if (localType=='f' && valueType=='l')
@@ -637,30 +635,30 @@ namespace Compiler
                     opFloatToInt (code);
                 }
             }
-            
+
             switch (localType)
             {
                 case 'f':
-                
+
                     opStoreGlobalFloat (code);
                     break;
-                
+
                 case 's':
 
                     opStoreGlobalShort (code);
                     break;
-                
+
                 case 'l':
 
                     opStoreGlobalLong (code);
                     break;
-            
+
                 default:
-                
+
                     assert (0);
-            }        
+            }
         }
-            
+
         void fetchGlobal (CodeContainer& code, Literals& literals, char localType,
             const std::string& name)
         {
@@ -671,36 +669,36 @@ namespace Compiler
             switch (localType)
             {
                 case 'f':
-                
+
                     opFetchGlobalFloat (code);
                     break;
-                
+
                 case 's':
 
                     opFetchGlobalShort (code);
                     break;
-                
+
                 case 'l':
 
                     opFetchGlobalLong (code);
                     break;
-            
+
                 default:
-                
+
                     assert (0);
-            }            
+            }
         }
-        
+
         void random (CodeContainer& code)
         {
             opRandom (code);
         }
-        
+
         void scriptRunning (CodeContainer& code)
         {
             opScriptRunning (code);
         }
-        
+
         void startScript (CodeContainer& code)
         {
             opStartScript (code);
@@ -714,7 +712,7 @@ namespace Compiler
         void getDistance (CodeContainer& code, Literals& literals, const std::string id)
         {
             if (id.empty())
-            {        
+            {
                 opGetDistance (code);
             }
             else
@@ -722,14 +720,14 @@ namespace Compiler
                 int index = literals.addString (id);
                 opPushInt (code, index);
                 opGetDistanceExplicit (code);
-            }          
-        }        
-        
+            }
+        }
+
         void getSecondsPassed (CodeContainer& code)
         {
             opGetSecondsPassed (code);
         }
-        
+
         void getDisabled (CodeContainer& code, Literals& literals, const std::string id)
         {
             if (id.empty())
@@ -743,11 +741,11 @@ namespace Compiler
                 opGetDisabledExplicit (code);
             }
         }
-        
+
         void enable (CodeContainer& code, Literals& literals, const std::string id)
         {
             if (id.empty())
-            {        
+            {
                 opEnable (code);
             }
             else
@@ -755,13 +753,13 @@ namespace Compiler
                 int index = literals.addString (id);
                 opPushInt (code, index);
                 opEnableExplicit (code);
-            }     
+            }
         }
-        
+
         void disable (CodeContainer& code, Literals& literals, const std::string id)
         {
             if (id.empty())
-            {        
+            {
                 opDisable (code);
             }
             else
@@ -773,4 +771,3 @@ namespace Compiler
         }
     }
 }
-
diff --git a/components/compiler/lineparser.cpp b/components/compiler/lineparser.cpp
index 927990a328..b4c79c972e 100644
--- a/components/compiler/lineparser.cpp
+++ b/components/compiler/lineparser.cpp
@@ -14,32 +14,32 @@ namespace Compiler
     void LineParser::parseExpression (Scanner& scanner, const TokenLoc& loc)
     {
         mExprParser.reset();
-        
+
         if (!mExplicit.empty())
         {
             mExprParser.parseName (mExplicit, loc, scanner);
             mExprParser.parseSpecial (Scanner::S_ref, loc, scanner);
         }
-        
+
         scanner.scan (mExprParser);
-        
+
         char type = mExprParser.append (mCode);
-        mState = EndState; 
-        
+        mState = EndState;
+
         switch (type)
         {
             case 'l':
-            
-                Generator::message (mCode, mLiterals, "%g", 0);       
+
+                Generator::message (mCode, mLiterals, "%g", 0);
                 break;
-                
+
             case 'f':
-            
-                Generator::message (mCode, mLiterals, "%f", 0);                   
+
+                Generator::message (mCode, mLiterals, "%f", 0);
                 break;
-                
+
             default:
-                
+
                 throw std::runtime_error ("unknown expression result type");
         }
     }
@@ -52,14 +52,14 @@ namespace Compiler
     {}
 
     bool LineParser::parseInt (int value, const TokenLoc& loc, Scanner& scanner)
-    {   
+    {
         if (mAllowExpression && mState==BeginState)
         {
             scanner.putbackInt (value, loc);
             parseExpression (scanner, loc);
             return true;
         }
-    
+
         return Parser::parseInt (value, loc, scanner);
     }
 
@@ -71,7 +71,7 @@ namespace Compiler
             parseExpression (scanner, loc);
             return true;
         }
-            
+
         return Parser::parseFloat (value, loc, scanner);
     }
 
@@ -87,11 +87,11 @@ namespace Compiler
                 scanner.scan (skip);
                 return false;
             }
-         
+
             std::string name2 = toLower (name);
-            
+
             char type = mLocals.getType (name2);
-            
+
             if (type!=' ')
             {
                 getErrorHandler().error ("can't re-declare local variable", loc);
@@ -99,14 +99,14 @@ namespace Compiler
                 scanner.scan (skip);
                 return false;
             }
-            
+
             mLocals.declare (mState==ShortState ? 's' : (mState==LongState ? 'l' : 'f'),
                 name2);
-            
+
             mState = EndState;
             return true;
         }
-        
+
         if (mState==SetState)
         {
             std::string name2 = toLower (name);
@@ -119,7 +119,7 @@ namespace Compiler
                 mState = SetLocalVarState;
                 return true;
             }
-            
+
             type = getContext().getGlobalType (name2);
             if (type!=' ')
             {
@@ -127,18 +127,18 @@ namespace Compiler
                 mType = type;
                 mState = SetGlobalVarState;
                 return true;
-            }                        
-            
+            }
+
             getErrorHandler().error ("unknown variable", loc);
             SkipParser skip (getErrorHandler(), getContext());
             scanner.scan (skip);
-            return false;            
+            return false;
         }
-        
+
         if (mState==MessageState || mState==MessageCommaState)
         {
             std::string arguments;
-            
+
             for (std::size_t i=0; i<name.size(); ++i)
             {
                 if (name[i]=='%')
@@ -167,46 +167,52 @@ namespace Compiler
                 mExprParser.reset();
                 mExprParser.parseArguments (arguments, scanner, mCode, true);
             }
-            
-            // for now skip buttons
-           SkipParser skip (getErrorHandler(), getContext());
-           scanner.scan (skip);            
 
-            Generator::message (mCode, mLiterals, name, 0);
-            mState = EndState;
-            return false;
+            mName = name;
+            mButtons = 0;
+
+            mState = MessageButtonState;
+            return true;
         }
-        
+
+        if (mState==MessageButtonState || mState==MessageButtonCommaState)
+        {
+            Generator::pushString (mCode, mLiterals, name);
+            mState = MessageButtonState;
+            ++mButtons;
+            return true;
+        }
+
         if (mState==BeginState && mAllowExpression)
         {
             std::string name2 = toLower (name);
-            
+
             char type = mLocals.getType (name2);
-            
+
             if (type!=' ')
             {
                 scanner.putbackName (name, loc);
                 parseExpression (scanner, loc);
-                return true;               
+                return true;
             }
 
             type = getContext().getGlobalType (name2);
-            
+
             if (type!=' ')
             {
                 scanner.putbackName (name, loc);
                 parseExpression (scanner, loc);
-                return true;            
-            }        
+                return true;
+            }
         }
-        
+
         if (mState==BeginState && getContext().isId (name))
         {
             mState = PotentialExplicitState;
             mExplicit = toLower (name);
             return true;
         }
-        
+
         return Parser::parseName (name, loc, scanner);
     }
 
@@ -215,60 +221,60 @@ namespace Compiler
         if (mState==BeginState || mState==ExplicitState)
         {
             switch (keyword)
-            {        
+            {
                 case Scanner::K_enable:
-                
+
                     Generator::enable (mCode, mLiterals, mExplicit);
                     mState = EndState;
-                    return true;                           
-                    
+                    return true;
+
                 case Scanner::K_disable:
-                
+
                     Generator::disable (mCode, mLiterals, mExplicit);
                     mState = EndState;
-                    return true;          
+                    return true;
             }
-            
+
             // check for custom extensions
             if (const Extensions *extensions = getContext().getExtensions())
             {
                 std::string argumentType;
-                
+
                 if (extensions->isInstruction (keyword, argumentType, mState==ExplicitState))
                 {
                     mExprParser.parseArguments (argumentType, scanner, mCode, true);
-                    
+
                     extensions->generateInstructionCode (keyword, mCode, mLiterals, mExplicit);
                     mState = EndState;
                     return true;
                 }
-            }            
-            
+            }
+
             if (mAllowExpression)
             {
                 if (keyword==Scanner::K_getdisabled || keyword==Scanner::K_getdistance)
                 {
                     scanner.putbackKeyword (keyword, loc);
                     parseExpression (scanner, loc);
-                    return true;                 
+                    return true;
                 }
 
                 if (const Extensions *extensions = getContext().getExtensions())
                 {
                     char returnType;
                     std::string argumentType;
-                    
+
                     if (extensions->isFunction (keyword, returnType, argumentType,
                         !mExplicit.empty()))
                     {
                         scanner.putbackKeyword (keyword, loc);
                         parseExpression (scanner, loc);
-                        return true;                
+                        return true;
                     }
-                }            
+                }
             }
         }
-        
+
         if (mState==BeginState)
         {
             switch (keyword)
@@ -278,39 +284,39 @@ namespace Compiler
                 case Scanner::K_float: mState = FloatState; return true;
                 case Scanner::K_set: mState = SetState; return true;
                 case Scanner::K_messagebox: mState = MessageState; return true;
-                
+
                 case Scanner::K_return:
-                
+
                     Generator::exit (mCode);
                     mState = EndState;
                     return true;
-                    
+
                 case Scanner::K_startscript:
 
-                    mExprParser.parseArguments ("c", scanner, mCode, true);                   
+                    mExprParser.parseArguments ("c", scanner, mCode, true);
                     Generator::startScript (mCode);
                     mState = EndState;
-                    return true;                
-                    
+                    return true;
+
                 case Scanner::K_stopscript:
 
-                    mExprParser.parseArguments ("c", scanner, mCode, true);                   
+                    mExprParser.parseArguments ("c", scanner, mCode, true);
                     Generator::stopScript (mCode);
                     mState = EndState;
-                    return true;     
+                    return true;
             }
         }
         else if (mState==SetLocalVarState && keyword==Scanner::K_to)
         {
             mExprParser.reset();
             scanner.scan (mExprParser);
-            
+
             std::vector<Interpreter::Type_Code> code;
             char type = mExprParser.append (code);
-            
+
             Generator::assignToLocal (mCode, mLocals.getType (mName),
                 mLocals.getIndex (mName), code, type);
-                        
+
             mState = EndState;
             return true;
         }
@@ -318,16 +324,16 @@ namespace Compiler
         {
             mExprParser.reset();
             scanner.scan (mExprParser);
-            
+
             std::vector<Interpreter::Type_Code> code;
             char type = mExprParser.append (code);
-            
+
             Generator::assignToGlobal (mCode, mLiterals, mType, mName, code, type);
-                        
+
             mState = EndState;
             return true;
         }
-        
+
         if (mAllowExpression)
         {
             if (keyword==Scanner::K_getsquareroot || keyword==Scanner::K_menumode ||
@@ -336,10 +342,10 @@ namespace Compiler
             {
                 scanner.putbackKeyword (keyword, loc);
                 parseExpression (scanner, loc);
-                return true;                 
-            }        
+                return true;
+            }
         }
-                
+
         return Parser::parseKeyword (keyword, loc, scanner);
     }
 
@@ -347,30 +353,42 @@ namespace Compiler
     {
         if (code==Scanner::S_newline && (mState==EndState || mState==BeginState))
             return false;
-            
+
         if (code==Scanner::S_comma && mState==MessageState)
         {
             mState = MessageCommaState;
             return true;
         }
-        
+
         if (code==Scanner::S_ref && mState==PotentialExplicitState)
         {
             mState = ExplicitState;
             return true;
         }
-        
+
+        if (code==Scanner::S_newline && mState==MessageButtonState)
+        {
+            Generator::message (mCode, mLiterals, mName, mButtons);
+            return false;
+        }
+
+        if (code==Scanner::S_comma && mState==MessageButtonState)
+        {
+            mState = MessageButtonCommaState;
+            return true;
+        }
+
         if (mAllowExpression && mState==BeginState &&
             (code==Scanner::S_open || code==Scanner::S_minus))
         {
             scanner.putbackSpecial (code, loc);
             parseExpression (scanner, loc);
-            return true;        
+            return true;
         }
-            
+
         return Parser::parseSpecial (code, loc, scanner);
     }
-    
+
     void LineParser::reset()
     {
         mState = BeginState;
@@ -378,4 +396,3 @@ namespace Compiler
         mExplicit.clear();
     }
 }
-
diff --git a/components/compiler/lineparser.hpp b/components/compiler/lineparser.hpp
index c407d3b6b8..531b7762f0 100644
--- a/components/compiler/lineparser.hpp
+++ b/components/compiler/lineparser.hpp
@@ -12,9 +12,9 @@ namespace Compiler
 {
     class Locals;
     class Literals;
-    
+
     /// \brief Line parser, to be used in console scripts and as part of ScriptParser
-    
+
     class LineParser : public Parser
     {
             enum State
@@ -22,31 +22,32 @@ namespace Compiler
                 BeginState,
                 ShortState, LongState, FloatState,
                 SetState, SetLocalVarState, SetGlobalVarState,
-                MessageState, MessageCommaState,
+                MessageState, MessageCommaState, MessageButtonState, MessageButtonCommaState,
                 EndState,
                 PotentialExplicitState, ExplicitState
             };
 
-            Locals& mLocals;  
+            Locals& mLocals;
             Literals& mLiterals;
             std::vector<Interpreter::Type_Code>& mCode;
             State mState;
             std::string mName;
+            int mButtons;
             std::string mExplicit;
             char mType;
             ExprParser mExprParser;
             bool mAllowExpression;
-    
+
             void parseExpression (Scanner& scanner, const TokenLoc& loc);
-    
+
         public:
-        
+
             LineParser (ErrorHandler& errorHandler, Context& context, Locals& locals,
                 Literals& literals, std::vector<Interpreter::Type_Code>& code,
                 bool allowExpression = false);
             ///< \param allowExpression Allow lines consisting of a naked expression
             /// (result is send to the messagebox interface)
-    
+
             virtual bool parseInt (int value, const TokenLoc& loc, Scanner& scanner);
             ///< Handle an int token.
             /// \return fetch another token?
@@ -67,9 +68,9 @@ namespace Compiler
             virtual bool parseSpecial (int code, const TokenLoc& loc, Scanner& scanner);
             ///< Handle a special character token.
             /// \return fetch another token?
-            
+
             void reset();
-            ///< Reset parser to clean state.            
+            ///< Reset parser to clean state.
     };
 }
 
diff --git a/components/interpreter/miscopcodes.hpp b/components/interpreter/miscopcodes.hpp
index 8d05c58da6..7e7dcd18a7 100644
--- a/components/interpreter/miscopcodes.hpp
+++ b/components/interpreter/miscopcodes.hpp
@@ -6,6 +6,7 @@
 #include <vector>
 #include <string>
 #include <sstream>
+#include <algorithm>
 
 #include "opcodes.hpp"
 #include "runtime.hpp"
@@ -15,24 +16,33 @@ namespace Interpreter
     class OpMessageBox : public Opcode1
     {
         public:
-        
+
             virtual void execute (Runtime& runtime, unsigned int arg0)
             {
-                if (arg0!=0)
-                    throw std::logic_error ("message box buttons not implemented yet");
-                
-                // message    
+                // buttons
+                std::vector<std::string> buttons;
+
+                for (std::size_t i=0; i<arg0; ++i)
+                {
+                    int index = runtime[0].mInteger;
+                    runtime.pop();
+                    buttons.push_back (runtime.getStringLiteral (index));
+                }
+
+                std::reverse (buttons.begin(), buttons.end());
+
+                // message
                 int index = runtime[0].mInteger;
                 runtime.pop();
                 std::string message = runtime.getStringLiteral (index);
-                
+
                 // additional parameters
                 std::string formattedMessage;
-                
+
                 for (std::size_t i=0; i<message.size(); ++i)
                 {
                     char c = message[i];
-                    
+
                     if (c!='%')
                         formattedMessage += c;
                     else
@@ -41,7 +51,7 @@ namespace Interpreter
                         if (i<message.size())
                         {
                             c = message[i];
-                            
+
                             if (c=='S' || c=='s')
                             {
                                 int index = runtime[0].mInteger;
@@ -52,7 +62,7 @@ namespace Interpreter
                             {
                                 Type_Integer value = runtime[0].mInteger;
                                 runtime.pop();
-                                
+
                                 std::ostringstream out;
                                 out << value;
                                 formattedMessage += out.str();
@@ -63,10 +73,10 @@ namespace Interpreter
                                 {
                                     ++i;
                                 }
-                            
+
                                 float value = runtime[0].mFloat;
                                 runtime.pop();
-                                
+
                                 std::ostringstream out;
                                 out << value;
                                 formattedMessage += out.str();
@@ -75,135 +85,131 @@ namespace Interpreter
                                 formattedMessage += "%";
                             else
                             {
-                                formattedMessage += "%"; 
-                                formattedMessage += c;                    
+                                formattedMessage += "%";
+                                formattedMessage += c;
                             }
                         }
                     }
                 }
-                
-                // buttons (not implemented)
-                std::vector<std::string> buttons;
-                
+
                 runtime.getContext().messageBox (formattedMessage, buttons);
-            }     
-    };   
-            
+            }
+    };
+
     class OpMenuMode : public Opcode0
     {
         public:
-        
+
             virtual void execute (Runtime& runtime)
             {
                 runtime.push (runtime.getContext().menuMode());
-            }            
+            }
     };
-            
+
     class OpRandom : public Opcode0
     {
         public:
-        
+
             virtual void execute (Runtime& runtime)
             {
                 double r = static_cast<double> (std::rand()) / RAND_MAX; // [0, 1)
-                
+
                 Type_Integer limit = runtime[0].mInteger;
-                
+
                 if (limit<0)
                     throw std::runtime_error (
                         "random: argument out of range (Don't be so negative!)");
-                
+
                 Type_Integer value = static_cast<Type_Integer> (r*limit); // [o, limit)
-                
+
                 runtime[0].mInteger = value;
-            }    
-    };    
-                
+            }
+    };
+
     class OpGetSecondsPassed : public Opcode0
     {
         public:
-        
+
             virtual void execute (Runtime& runtime)
             {
                 Type_Float duration = runtime.getContext().getSecondsPassed();
-                
+
                 runtime.push (duration);
-            }            
+            }
     };
-    
+
     class OpEnable : public Opcode0
     {
         public:
-        
+
             virtual void execute (Runtime& runtime)
             {
                 runtime.getContext().enable();
-            }            
-    };    
-    
+            }
+    };
+
     class OpDisable : public Opcode0
     {
         public:
-        
+
             virtual void execute (Runtime& runtime)
             {
                 runtime.getContext().disable();
-            }            
-    };    
-    
+            }
+    };
+
     class OpGetDisabled : public Opcode0
     {
         public:
-        
+
             virtual void execute (Runtime& runtime)
             {
                 runtime.push (runtime.getContext().isDisabled());
-            }            
-    };       
-    
+            }
+    };
+
     class OpEnableExplicit : public Opcode0
     {
         public:
-        
+
             virtual void execute (Runtime& runtime)
             {
                 int index = runtime[0].mInteger;
                 runtime.pop();
                 std::string id = runtime.getStringLiteral (index);
-            
+
                 runtime.getContext().enable (id);
-            }            
-    };    
-    
+            }
+    };
+
     class OpDisableExplicit : public Opcode0
     {
         public:
-        
+
             virtual void execute (Runtime& runtime)
             {
                 int index = runtime[0].mInteger;
                 runtime.pop();
                 std::string id = runtime.getStringLiteral (index);
-            
+
                 runtime.getContext().disable (id);
-            }            
-    };    
-    
+            }
+    };
+
     class OpGetDisabledExplicit : public Opcode0
     {
         public:
-        
+
             virtual void execute (Runtime& runtime)
             {
                 int index = runtime[0].mInteger;
                 runtime.pop();
                 std::string id = runtime.getStringLiteral (index);
-            
+
                 runtime.push (runtime.getContext().isDisabled (id));
-            }            
-    };       
-   
+            }
+    };
+
 }
 
 #endif
-

From 09a258253ca84d767dafee1d39f86d5763dca93a Mon Sep 17 00:00:00 2001
From: Marc Zinnschlag <marc@zpages.de>
Date: Sun, 22 Aug 2010 11:17:19 +0200
Subject: [PATCH 03/32] removed custom messageBox implementation for console

---
 apps/openmw/mwgui/console.cpp | 12 ------------
 1 file changed, 12 deletions(-)

diff --git a/apps/openmw/mwgui/console.cpp b/apps/openmw/mwgui/console.cpp
index 468cae456b..471b2810b9 100644
--- a/apps/openmw/mwgui/console.cpp
+++ b/apps/openmw/mwgui/console.cpp
@@ -15,9 +15,6 @@ namespace MWGui
 
             ConsoleInterpreterContext (Console& console, MWWorld::Environment& environment,
                 MWWorld::Ptr reference);
-
-            virtual void messageBox (const std::string& message,
-                const std::vector<std::string>& buttons);
     };
 
     ConsoleInterpreterContext::ConsoleInterpreterContext (Console& console,
@@ -27,15 +24,6 @@ namespace MWGui
       mConsole (console)
     {}
 
-    void ConsoleInterpreterContext::messageBox (const std::string& message,
-        const std::vector<std::string>& buttons)
-    {
-        if (!buttons.empty())
-            mConsole.printError ("MessageBox doesn't support buttons while in console mode");
-        else
-            mConsole.printOK (message);
-    }
-
     bool Console::compile (const std::string& cmd, Compiler::Output& output)
     {
         try

From 17135a64035d1f26b8bdd6f7125254935b9067e8 Mon Sep 17 00:00:00 2001
From: Marc Zinnschlag <marc@zpages.de>
Date: Sun, 22 Aug 2010 11:22:10 +0200
Subject: [PATCH 04/32] routed message box output through window manager

---
 apps/openmw/mwgui/window_manager.cpp        | 9 +++++++++
 apps/openmw/mwgui/window_manager.hpp        | 3 +++
 apps/openmw/mwscript/interpretercontext.cpp | 5 +----
 3 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/apps/openmw/mwgui/window_manager.cpp b/apps/openmw/mwgui/window_manager.cpp
index 726cd5bd8d..ed4085ea8d 100644
--- a/apps/openmw/mwgui/window_manager.cpp
+++ b/apps/openmw/mwgui/window_manager.cpp
@@ -4,6 +4,7 @@
 #include "console.hpp"
 
 #include <assert.h>
+#include <iostream>
 
 using namespace MWGui;
 
@@ -95,3 +96,11 @@ void WindowManager::setValue (const std::string& id, const MWMechanics::DynamicS
     stats->setValue (id, value);
     hud->setValue (id, value);
 }
+
+void WindowManager::messageBox (const std::string& message, const std::vector<std::string>& buttons)
+{
+    std::cout << "message box: " << message << std::endl;
+
+    if (!buttons.empty())
+        std::cerr << "error: message box buttons not supported" << std::endl;
+}
diff --git a/apps/openmw/mwgui/window_manager.hpp b/apps/openmw/mwgui/window_manager.hpp
index a2e664d26d..ea2d87bc9c 100644
--- a/apps/openmw/mwgui/window_manager.hpp
+++ b/apps/openmw/mwgui/window_manager.hpp
@@ -11,6 +11,7 @@
  */
 
 #include <string>
+#include <vector>
 
 #include "../mwmechanics/stat.hpp"
 
@@ -144,6 +145,8 @@ namespace MWGui
 
     void setValue (const std::string& id, const MWMechanics::DynamicStat<int>& value);
     ///< Set value for the given ID.
+
+    void messageBox (const std::string& message, const std::vector<std::string>& buttons);
   };
 }
 #endif
diff --git a/apps/openmw/mwscript/interpretercontext.cpp b/apps/openmw/mwscript/interpretercontext.cpp
index 404aa69a68..22a5aaa702 100644
--- a/apps/openmw/mwscript/interpretercontext.cpp
+++ b/apps/openmw/mwscript/interpretercontext.cpp
@@ -105,10 +105,7 @@ namespace MWScript
     void InterpreterContext::messageBox (const std::string& message,
         const std::vector<std::string>& buttons)
     {
-        std::cout << "message box: " << message << std::endl;
-
-        if (!buttons.empty())
-            std::cerr << "error: message box buttons not supported" << std::endl;
+        mEnvironment.mWindowManager->messageBox (message, buttons);
     }
 
     bool InterpreterContext::menuMode()

From f4e79a48f05197734c1ae7860875a600e8fe4039 Mon Sep 17 00:00:00 2001
From: Marc Zinnschlag <marc@zpages.de>
Date: Sun, 22 Aug 2010 12:47:56 +0200
Subject: [PATCH 05/32] implemented optional arguments

---
 components/compiler/controlparser.cpp | 114 +++++-----
 components/compiler/exprparser.cpp    | 309 +++++++++++++++-----------
 components/compiler/exprparser.hpp    |  46 ++--
 components/compiler/fileparser.cpp    |  30 +--
 components/compiler/parser.cpp        |  48 +++-
 components/compiler/parser.hpp        |  17 +-
 components/compiler/stringparser.cpp  |  19 +-
 7 files changed, 344 insertions(+), 239 deletions(-)

diff --git a/components/compiler/controlparser.cpp b/components/compiler/controlparser.cpp
index 4715d3214c..2f5d5c4b60 100644
--- a/components/compiler/controlparser.cpp
+++ b/components/compiler/controlparser.cpp
@@ -17,21 +17,21 @@ namespace Compiler
         {
             std::pair<Codes, Codes> entry;
 
-            if (mState!=IfElseBodyState)             
+            if (mState!=IfElseBodyState)
                 mExprParser.append (entry.first);
 
             std::copy (mCodeBlock.begin(), mCodeBlock.end(),
                 std::back_inserter (entry.second));
-                
+
             mIfCode.push_back (entry);
 
             mCodeBlock.clear();
-            
+
             if (keyword==Scanner::K_endif)
             {
                 // store code for if-cascade
                 Codes codes;
-                
+
                 for (IfCodes::reverse_iterator iter (mIfCode.rbegin());
                     iter!=mIfCode.rend(); ++iter)
                 {
@@ -47,17 +47,17 @@ namespace Compiler
                             std::back_inserter (block));
                         Generator::jumpOnZero (block, iter->second.size()+1);
                     }
-                    
+
                     std::copy (iter->second.begin(), iter->second.end(),
                         std::back_inserter (block));
-                   
+
                    std::swap (codes, block);
-                   
+
                    std::copy (block.begin(), block.end(), std::back_inserter (codes));
                 }
-                
+
                 std::copy (codes.begin(), codes.end(), std::back_inserter (mCode));
-                
+
                 mIfCode.clear();
                 mState = IfEndifState;
             }
@@ -66,36 +66,36 @@ namespace Compiler
                 mExprParser.reset();
                 scanner.scan (mExprParser);
 
-                mState = IfElseifEndState;            
+                mState = IfElseifEndState;
             }
             else if (keyword==Scanner::K_else)
             {
-                mState = IfElseEndState;            
-            }                
-            
+                mState = IfElseEndState;
+            }
+
             return true;
         }
         else if (keyword==Scanner::K_if || keyword==Scanner::K_while)
         {
             // nested
             ControlParser parser (getErrorHandler(), getContext(), mLocals, mLiterals);
-            
+
             if (parser.parseKeyword (keyword, loc, scanner))
-                scanner.scan (parser);  
-                
-            parser.appendCode (mCodeBlock);                    
-                
+                scanner.scan (parser);
+
+            parser.appendCode (mCodeBlock);
+
             return true;
         }
         else
         {
             mLineParser.reset();
             if (mLineParser.parseKeyword (keyword, loc, scanner))
-                scanner.scan (mLineParser);      
-                
-            return true;      
-        }    
-        
+                scanner.scan (mLineParser);
+
+            return true;
+        }
+
         return false;
     }
 
@@ -104,24 +104,24 @@ namespace Compiler
         if (keyword==Scanner::K_endwhile)
         {
             Codes loop;
-            
+
             Codes expr;
             mExprParser.append (expr);
-            
+
             Generator::jump (loop, -mCodeBlock.size()-expr.size());
-        
+
             std::copy (expr.begin(), expr.end(), std::back_inserter (mCode));
 
             Codes skip;
-            
+
             Generator::jumpOnZero (skip, mCodeBlock.size()+loop.size()+1);
-            
+
             std::copy (skip.begin(), skip.end(), std::back_inserter (mCode));
-            
+
             std::copy (mCodeBlock.begin(), mCodeBlock.end(), std::back_inserter (mCode));
-            
+
             Codes loop2;
-        
+
             Generator::jump (loop2, -mCodeBlock.size()-expr.size()-skip.size());
 
             if (loop.size()!=loop2.size())
@@ -129,31 +129,31 @@ namespace Compiler
                     "internal compiler error: failed to generate a while loop");
 
             std::copy (loop2.begin(), loop2.end(), std::back_inserter (mCode));
-        
+
             mState = WhileEndwhileState;
-            return true;    
+            return true;
         }
         else if (keyword==Scanner::K_if || keyword==Scanner::K_while)
         {
             // nested
             ControlParser parser (getErrorHandler(), getContext(), mLocals, mLiterals);
-            
+
             if (parser.parseKeyword (keyword, loc, scanner))
-                scanner.scan (parser);  
-                
-            parser.appendCode (mCodeBlock);                    
-                
+                scanner.scan (parser);
+
+            parser.appendCode (mCodeBlock);
+
             return true;
         }
         else
         {
             mLineParser.reset();
             if (mLineParser.parseKeyword (keyword, loc, scanner))
-                scanner.scan (mLineParser);      
-                
-            return true;      
-        }            
-        
+                scanner.scan (mLineParser);
+
+            return true;
+        }
+
         return false;
     }
 
@@ -164,14 +164,14 @@ namespace Compiler
       mExprParser (errorHandler, context, locals, literals),
       mState (StartState)
     {
-    
+
     }
-  
+
     void ControlParser::appendCode (std::vector<Interpreter::Type_Code>& code) const
     {
         std::copy (mCode.begin(), mCode.end(), std::back_inserter (code));
     }
-    
+
     bool ControlParser::parseKeyword (int keyword, const TokenLoc& loc, Scanner& scanner)
     {
         if (mState==StartState)
@@ -190,20 +190,20 @@ namespace Compiler
                 scanner.scan (mExprParser);
 
                 mState = WhileEndState;
-                return true;            
+                return true;
             }
         }
         else if (mState==IfBodyState || mState==IfElseifBodyState || mState==IfElseBodyState)
         {
             if (parseIfBody (keyword, loc, scanner))
-                return true;            
+                return true;
         }
         else if (mState==WhileBodyState)
         {
             if ( parseWhileBody (keyword, loc, scanner))
                 return true;
         }
-        
+
         return Parser::parseKeyword (keyword, loc, scanner);
     }
 
@@ -218,24 +218,24 @@ namespace Compiler
                 case IfElseEndState: mState = IfElseBodyState; return true;
 
                 case WhileEndState: mState = WhileBodyState; return true;
-                
+
                 case IfBodyState:
                 case IfElseifBodyState:
                 case IfElseBodyState:
                 case WhileBodyState:
-                
+
                     return true; // empty line
-            
+
                 case IfEndifState:
                 case WhileEndwhileState:
-                
+
                     return false;
-                    
+
                 default: ;
             }
-        
+
         }
-    
+
         return Parser::parseSpecial (code, loc, scanner);
     }
 
@@ -245,6 +245,6 @@ namespace Compiler
         mCodeBlock.clear();
         mIfCode.clear();
         mState = StartState;
+        Parser::reset();
     }
 }
-
diff --git a/components/compiler/exprparser.cpp b/components/compiler/exprparser.cpp
index d0138078ee..484aea878f 100644
--- a/components/compiler/exprparser.cpp
+++ b/components/compiler/exprparser.cpp
@@ -22,33 +22,33 @@ namespace Compiler
         switch (op)
         {
             case '(':
-            
+
                 return 0;
-            
+
             case 'e': // ==
             case 'n': // !=
             case 'l': // <
             case 'L': // <=
             case 'g': // <
             case 'G': // >=
-            
+
                 return 1;
-            
+
             case '+':
             case '-':
-            
+
                 return 2;
-        
+
             case '*':
             case '/':
-            
+
                 return 3;
-                
+
             case 'm':
-            
+
                 return 4;
         }
-    
+
         return 0;
     }
 
@@ -59,7 +59,7 @@ namespace Compiler
         assert (Index<static_cast<int> (mOperands.size()));
         return mOperands[mOperands.size()-1-Index];
     }
-    
+
     char ExprParser::getOperator() const
     {
         assert (!mOperators.empty());
@@ -70,27 +70,27 @@ namespace Compiler
     {
         return std::find (mOperators.begin(), mOperators.end(), '(')!=mOperators.end();
     }
-            
+
     void ExprParser::popOperator()
     {
         assert (!mOperators.empty());
-        mOperators.resize (mOperators.size()-1);        
+        mOperators.resize (mOperators.size()-1);
     }
-    
+
     void ExprParser::popOperand()
     {
         assert (!mOperands.empty());
-        mOperands.resize (mOperands.size()-1);    
+        mOperands.resize (mOperands.size()-1);
     }
 
     void ExprParser::replaceBinaryOperands()
     {
         char t1 = getOperandType (1);
         char t2 = getOperandType();
-        
+
         popOperand();
         popOperand();
-        
+
         if (t1==t2)
             mOperands.push_back (t1);
         else if (t1=='f' || t2=='f')
@@ -102,59 +102,59 @@ namespace Compiler
     void ExprParser::pop()
     {
         char op = getOperator();
-        
+
         switch (op)
         {
             case 'm':
-            
+
                 Generator::negate (mCode, getOperandType());
                 popOperator();
                 break;
 
             case '+':
-                
+
                 Generator::add (mCode, getOperandType (1), getOperandType());
                 popOperator();
                 replaceBinaryOperands();
                 break;
 
             case '-':
-                
+
                 Generator::sub (mCode, getOperandType (1), getOperandType());
                 popOperator();
                 replaceBinaryOperands();
                 break;
-                
+
             case '*':
-                
+
                 Generator::mul (mCode, getOperandType (1), getOperandType());
                 popOperator();
                 replaceBinaryOperands();
-                break;                
-                
+                break;
+
             case '/':
-                
+
                 Generator::div (mCode, getOperandType (1), getOperandType());
                 popOperator();
                 replaceBinaryOperands();
                 break;
-                            
+
             case 'e':
             case 'n':
             case 'l':
             case 'L':
             case 'g':
             case 'G':
-            
+
                 Generator::compare (mCode, op, getOperandType (1), getOperandType());
                 popOperator();
                 popOperand();
                 popOperand();
                 mOperands.push_back ('l');
                 break;
-                            
+
             default:
-            
+
                 throw std::logic_error ("unknown operator");
         }
     }
@@ -165,36 +165,36 @@ namespace Compiler
         mOperands.push_back ('l');
         Generator::pushInt (mCode, mLiterals, value);
     }
-    
+
     void ExprParser::pushFloatLiteral (float value)
     {
         mNextOperand = false;
         mOperands.push_back ('f');
-        Generator::pushFloat (mCode, mLiterals, value);    
+        Generator::pushFloat (mCode, mLiterals, value);
     }
-            
+
     void ExprParser::pushBinaryOperator (char c)
     {
         while (!mOperators.empty() && getPriority (getOperator())>=getPriority (c))
             pop();
-    
+
         mOperators.push_back (c);
         mNextOperand = true;
     }
-            
+
     void ExprParser::close()
     {
         while (getOperator()!='(')
             pop();
-            
+
         popOperator();
     }
-    
-    void ExprParser::parseArguments (const std::string& arguments, Scanner& scanner)
+
+    int ExprParser::parseArguments (const std::string& arguments, Scanner& scanner)
     {
-        parseArguments (arguments, scanner, mCode);
+        return parseArguments (arguments, scanner, mCode);
     }
-            
+
     ExprParser::ExprParser (ErrorHandler& errorHandler, Context& context, Locals& locals,
         Literals& literals, bool argument)
     : Parser (errorHandler, context), mLocals (locals), mLiterals (literals),
@@ -205,11 +205,13 @@ namespace Compiler
     {
         if (!mExplicit.empty())
             return Parser::parseInt (value, loc, scanner);
-    
+
         mFirst = false;
-        
+
         if (mNextOperand)
-        {       
+        {
+            start();
+
             pushIntegerLiteral (value);
             mTokenLoc = loc;
             return true;
@@ -228,13 +230,15 @@ namespace Compiler
             return Parser::parseFloat (value, loc, scanner);
 
         mFirst = false;
-        
+
         if (mNextOperand)
-        {    
+        {
+            start();
+
             pushFloatLiteral (value);
             mTokenLoc = loc;
             return true;
-        }            
+        }
         else
         {
             // no comma was used between arguments
@@ -252,29 +256,31 @@ namespace Compiler
         mFirst = false;
 
         if (mNextOperand)
-        {   
+        {
+            start();
+
             std::string name2 = toLower (name);
-                   
+
             char type = mLocals.getType (name2);
-            
+
             if (type!=' ')
             {
                 Generator::fetchLocal (mCode, type, mLocals.getIndex (name2));
                 mNextOperand = false;
-                mOperands.push_back (type=='f' ? 'f' : 'l');    
-                return true;    
+                mOperands.push_back (type=='f' ? 'f' : 'l');
+                return true;
             }
-                 
+
             type = getContext().getGlobalType (name2);
-            
+
             if (type!=' ')
             {
                 Generator::fetchGlobal (mCode, mLiterals, type, name2);
                 mNextOperand = false;
-                mOperands.push_back (type=='f' ? 'f' : 'l');    
-                return true;                
+                mOperands.push_back (type=='f' ? 'f' : 'l');
+                return true;
             }
-            
+
             if (mExplicit.empty() && getContext().isId (name))
             {
                 mExplicit = name;
@@ -287,161 +293,183 @@ namespace Compiler
             scanner.putbackName (name, loc);
             return false;
         }
-        
+
         return Parser::parseName (name, loc, scanner);
     }
 
     bool ExprParser::parseKeyword (int keyword, const TokenLoc& loc, Scanner& scanner)
     {
         mFirst = false;
-    
+
         if (!mExplicit.empty())
         {
             if (mRefOp && mNextOperand)
             {
                 if (keyword==Scanner::K_getdisabled)
                 {
-                    mTokenLoc = loc;        
+                    start();
+
+                    mTokenLoc = loc;
 
                     Generator::getDisabled (mCode, mLiterals, mExplicit);
                     mOperands.push_back ('l');
                     mExplicit.clear();
                     mRefOp = false;
-                    
+
                     mNextOperand = false;
-                    return true;            
-                }            
+                    return true;
+                }
                 else if (keyword==Scanner::K_getdistance)
                 {
+                    start();
+
                     mTokenLoc = loc;
                     parseArguments ("c", scanner);
-                    
+
                     Generator::getDistance (mCode, mLiterals, mExplicit);
                     mOperands.push_back ('f');
                     mExplicit.clear();
                     mRefOp = false;
-                    
+
                     mNextOperand = false;
                     return true;
-                }                   
+                }
 
                 // check for custom extensions
                 if (const Extensions *extensions = getContext().getExtensions())
                 {
                     char returnType;
                     std::string argumentType;
-                    
+
                     if (extensions->isFunction (keyword, returnType, argumentType, true))
                     {
+                        start();
+
                         mTokenLoc = loc;
                         parseArguments (argumentType, scanner);
-                        
+
                         extensions->generateFunctionCode (keyword, mCode, mLiterals, mExplicit);
                         mOperands.push_back (returnType);
                         mExplicit.clear();
                         mRefOp = false;
-                    
+
                         mNextOperand = false;
                         return true;
                     }
                 }
             }
-        
+
             return Parser::parseKeyword (keyword, loc, scanner);
         }
-    
+
         if (mNextOperand)
-        {        
+        {
             if (keyword==Scanner::K_getsquareroot)
             {
-                mTokenLoc = loc;        
+                start();
+
+                mTokenLoc = loc;
                 parseArguments ("f", scanner);
 
                 Generator::squareRoot (mCode);
                 mOperands.push_back ('f');
-                
+
                 mNextOperand = false;
                 return true;
             }
             else if (keyword==Scanner::K_menumode)
             {
+                start();
+
                 mTokenLoc = loc;
-                
+
                 Generator::menuMode (mCode);
                 mOperands.push_back ('l');
-                
+
                 mNextOperand = false;
                 return true;
             }
             else if (keyword==Scanner::K_random)
             {
-                mTokenLoc = loc;        
+                start();
+
+                mTokenLoc = loc;
                 parseArguments ("l", scanner);
 
                 Generator::random (mCode);
                 mOperands.push_back ('l');
-                
+
                 mNextOperand = false;
-                return true;            
+                return true;
             }
             else if (keyword==Scanner::K_scriptrunning)
             {
+                start();
+
                 mTokenLoc = loc;
                 parseArguments ("c", scanner);
-                
+
                 Generator::scriptRunning (mCode);
                 mOperands.push_back ('l');
-                
+
                 mNextOperand = false;
                 return true;
-            }             
+            }
             else if (keyword==Scanner::K_getdistance)
             {
+                start();
+
                 mTokenLoc = loc;
                 parseArguments ("c", scanner);
-                
+
                 Generator::getDistance (mCode, mLiterals, "");
                 mOperands.push_back ('f');
-                
+
                 mNextOperand = false;
                 return true;
-            }                       
+            }
             else if (keyword==Scanner::K_getsecondspassed)
             {
-                mTokenLoc = loc;        
+                start();
+
+                mTokenLoc = loc;
 
                 Generator::getSecondsPassed (mCode);
                 mOperands.push_back ('f');
-                
+
                 mNextOperand = false;
-                return true;            
+                return true;
             }
             else if (keyword==Scanner::K_getdisabled)
             {
-                mTokenLoc = loc;        
+                start();
+
+                mTokenLoc = loc;
 
                 Generator::getDisabled (mCode, mLiterals, "");
                 mOperands.push_back ('l');
-                
+
                 mNextOperand = false;
-                return true;            
+                return true;
             }
             else
             {
                 // check for custom extensions
                 if (const Extensions *extensions = getContext().getExtensions())
                 {
+                    start();
+
                     char returnType;
                     std::string argumentType;
-                    
+
                     if (extensions->isFunction (keyword, returnType, argumentType, false))
                     {
                         mTokenLoc = loc;
                         parseArguments (argumentType, scanner);
-                        
+
                         extensions->generateFunctionCode (keyword, mCode, mLiterals, "");
                         mOperands.push_back (returnType);
-                        
+
                         mNextOperand = false;
                         return true;
                     }
@@ -454,7 +482,7 @@ namespace Compiler
             scanner.putbackKeyword (keyword, loc);
             return false;
         }
-        
+
         return Parser::parseKeyword (keyword, loc, scanner);
     }
 
@@ -467,10 +495,10 @@ namespace Compiler
                 mRefOp = true;
                 return true;
             }
-        
+
             return Parser::parseSpecial (code, loc, scanner);
         }
-    
+
         if (code==Scanner::S_comma)
         {
             mTokenLoc = loc;
@@ -481,14 +509,14 @@ namespace Compiler
                 mFirst = false;
                 return true;
             }
-            
+
             // end marker
             scanner.putbackSpecial (code, loc);
             return false;
         }
 
         mFirst = false;
-                
+
         if (code==Scanner::S_newline)
         {
             // end marker
@@ -496,7 +524,7 @@ namespace Compiler
             scanner.putbackSpecial (code, loc);
             return false;
         }
-        
+
         if (code==Scanner::S_minus && mNextOperand)
         {
             // unary
@@ -504,7 +532,7 @@ namespace Compiler
             mTokenLoc = loc;
             return true;
         }
-        
+
         if (code==Scanner::S_open)
         {
             if (mNextOperand)
@@ -520,7 +548,7 @@ namespace Compiler
                 return false;
             }
         }
-        
+
         if (code==Scanner::S_close && !mNextOperand)
         {
             if (isOpen())
@@ -528,17 +556,17 @@ namespace Compiler
                 close();
                 return true;
             }
-            
+
             mTokenLoc = loc;
             scanner.putbackSpecial (code, loc);
             return false;
         }
-        
+
         if (!mNextOperand)
         {
             mTokenLoc = loc;
             char c = 0; // comparison
-   
+
             switch (code)
             {
                 case Scanner::S_plus: pushBinaryOperator ('+'); return true;
@@ -552,7 +580,7 @@ namespace Compiler
                 case Scanner::S_cmpGT: c = 'g'; break;
                 case Scanner::S_cmpGE: c = 'G'; break;
             }
-            
+
             if (c)
             {
                 if (mArgument && !isOpen())
@@ -562,15 +590,15 @@ namespace Compiler
                     scanner.putbackSpecial (code, loc);
                     return false;
                 }
-            
+
                 pushBinaryOperator (c);
                 return true;
             }
         }
-        
+
         return Parser::parseSpecial (code, loc, scanner);
     }
-    
+
     void ExprParser::reset()
     {
         mOperands.clear();
@@ -580,8 +608,9 @@ namespace Compiler
         mFirst = true;
         mExplicit.clear();
         mRefOp = false;
+        Parser::reset();
     }
-    
+
     char ExprParser::append (std::vector<Interpreter::Type_Code>& code)
     {
         if (mOperands.empty() && mOperators.empty())
@@ -589,7 +618,7 @@ namespace Compiler
             getErrorHandler().error ("missing expression", mTokenLoc);
             return 'l';
         }
-            
+
         if (mNextOperand || mOperands.empty())
         {
             getErrorHandler().error ("syntax error in expression", mTokenLoc);
@@ -603,62 +632,90 @@ namespace Compiler
 
         assert (mOperands.size()==1);
         return mOperands[0];
-    }    
-            
-    void ExprParser::parseArguments (const std::string& arguments, Scanner& scanner,
+    }
+
+    int ExprParser::parseArguments (const std::string& arguments, Scanner& scanner,
         std::vector<Interpreter::Type_Code>& code, bool invert)
     {
+        bool optional = false;
+        bool optionalCount = 0;
+
         ExprParser parser (getErrorHandler(), getContext(), mLocals, mLiterals, true);
         StringParser stringParser (getErrorHandler(), getContext(), mLiterals);
-        
+
         std::stack<std::vector<Interpreter::Type_Code> > stack;
-        
+
         for (std::string::const_iterator iter (arguments.begin()); iter!=arguments.end();
             ++iter)
         {
-            if (*iter=='S' || *iter=='c')
+            if (*iter=='/')
+            {
+                optional = true;
+            }
+            else if (*iter=='S' || *iter=='c')
             {
                 stringParser.reset();
+
+                if (optional)
+                    stringParser.setOptional (true);
+
                 if (*iter=='c') stringParser.smashCase();
-                scanner.scan (stringParser);            
-                
+                scanner.scan (stringParser);
+
+                if (optional && stringParser.isEmpty())
+                    break;
+
                 if (invert)
                 {
                     std::vector<Interpreter::Type_Code> tmp;
                     stringParser.append (tmp);
-                    
+
                     stack.push (tmp);
                 }
                 else
                     stringParser.append (code);
+
+                if (optional)
+                    ++optionalCount;
             }
             else
             {
-                parser.reset();    
+                parser.reset();
+
+                if (optional)
+                    parser.setOptional (true);
+
                 scanner.scan (parser);
 
+                if (optional && parser.isEmpty())
+                    break;
+
                 std::vector<Interpreter::Type_Code> tmp;
 
                 char type = parser.append (tmp);
 
                 if (type!=*iter)
                     Generator::convert (tmp, type, *iter);
-                    
+
                 if (invert)
                     stack.push (tmp);
                 else
                     std::copy (tmp.begin(), tmp.end(), std::back_inserter (code));
+
+                if (optional)
+                    ++optionalCount;
             }
         }
-        
+
         while (!stack.empty())
         {
             std::vector<Interpreter::Type_Code>& tmp = stack.top();
-        
+
             std::copy (tmp.begin(), tmp.end(), std::back_inserter (code));
-        
+
             stack.pop();
         }
-    }    
-}
 
+        return optionalCount;
+    }
+}
diff --git a/components/compiler/exprparser.hpp b/components/compiler/exprparser.hpp
index 0dd8c871ac..87945c6280 100644
--- a/components/compiler/exprparser.hpp
+++ b/components/compiler/exprparser.hpp
@@ -15,7 +15,7 @@ namespace Compiler
 
     class ExprParser : public Parser
     {
-            Locals& mLocals;  
+            Locals& mLocals;
             Literals& mLiterals;
             std::vector<char> mOperands;
             std::vector<char> mOperators;
@@ -26,35 +26,35 @@ namespace Compiler
             bool mArgument;
             std::string mExplicit;
             bool mRefOp;
-            
+
             int getPriority (char op) const;
-            
-            char getOperandType (int Index = 0) const;           
+
+            char getOperandType (int Index = 0) const;
 
             char getOperator() const;
-                
+
             bool isOpen() const;
-                
+
             void popOperator();
-            
+
             void popOperand();
-            
+
             void replaceBinaryOperands();
-   
+
             void pop();
-            
+
             void pushIntegerLiteral (int value);
-            
+
             void pushFloatLiteral (float value);
-            
+
             void pushBinaryOperator (char c);
-                        
+
             void close();
- 
-            void parseArguments (const std::string& arguments, Scanner& scanner);                  
-                             
+
+            int parseArguments (const std::string& arguments, Scanner& scanner);
+
         public:
-    
+
             ExprParser (ErrorHandler& errorHandler, Context& context, Locals& locals,
                 Literals& literals, bool argument = false);
             ///< constructor
@@ -84,20 +84,22 @@ namespace Compiler
             virtual bool parseSpecial (int code, const TokenLoc& loc, Scanner& scanner);
             ///< Handle a special character token.
             /// \return fetch another token?
-            
+
             void reset();
             ///< Reset parser to clean state.
-            
+
             char append (std::vector<Interpreter::Type_Code>& code);
             ///< Generate code for parsed expression.
             /// \return Type ('l': integer, 'f': float)
- 
-            void parseArguments (const std::string& arguments, Scanner& scanner,
+
+            int parseArguments (const std::string& arguments, Scanner& scanner,
                 std::vector<Interpreter::Type_Code>& code, bool invert = false);
             ///< Parse sequence of arguments specified by \a arguments.
             /// \param arguments Each character represents one arguments ('l': integer,
-            /// 'f': float, 'S': string, 'c': string (case smashed))                
+            /// 'f': float, 'S': string, 'c': string (case smashed), '/': following arguments are
+            /// optional)
             /// \param invert Store arguments in reverted order.
+            /// \return number of optional arguments
     };
 }
 
diff --git a/components/compiler/fileparser.cpp b/components/compiler/fileparser.cpp
index 6e26f48d60..9b184f1ffb 100644
--- a/components/compiler/fileparser.cpp
+++ b/components/compiler/fileparser.cpp
@@ -8,7 +8,7 @@
 namespace Compiler
 {
     FileParser::FileParser (ErrorHandler& errorHandler, Context& context)
-    : Parser (errorHandler, context), 
+    : Parser (errorHandler, context),
       mScriptParser (errorHandler, context, mLocals, true),
       mState (BeginState)
     {}
@@ -17,12 +17,12 @@ namespace Compiler
     {
         return mName;
     }
-    
+
     void FileParser::getCode (std::vector<Interpreter::Type_Code>& code) const
     {
         mScriptParser.getCode (code);
     }
-    
+
     const Locals& FileParser::getLocals() const
     {
         return mLocals;
@@ -37,17 +37,17 @@ namespace Compiler
             mState = BeginCompleteState;
             return true;
         }
-        
+
         if (mState==EndNameState)
         {
             // optional repeated name after end statement
             if (mName!=name)
                 reportWarning ("Names for script " + mName + " do not match", loc);
-            
+
             mState = EndCompleteState;
             return true;
         }
-        
+
         return Parser::parseName (name, loc, scanner);
     }
 
@@ -58,7 +58,7 @@ namespace Compiler
             mState = NameState;
             return true;
         }
-        
+
         if (mState==NameState)
         {
             // keywords can be used as script names too. Thank you Morrowind for another
@@ -67,7 +67,7 @@ namespace Compiler
             mState = BeginCompleteState;
             return true;
         }
-        
+
         return Parser::parseKeyword (keyword, loc, scanner);
     }
 
@@ -80,25 +80,25 @@ namespace Compiler
                 // ignore empty lines
                 return true;
             }
-        
+
             if (mState==BeginCompleteState)
             {
                 // parse the script body
                 mScriptParser.reset();
-                
+
                 scanner.scan (mScriptParser);
-                
+
                 mState = EndNameState;
                 return true;
             }
-            
+
             if (mState==EndCompleteState || mState==EndNameState)
             {
                 // we are done here -> ignore the rest of the script
                 return false;
             }
         }
-        
+
         return Parser::parseSpecial (code, loc, scanner);
     }
 
@@ -107,12 +107,12 @@ namespace Compiler
         if (mState!=EndNameState && mState!=EndCompleteState)
             Parser::parseEOF (scanner);
     }
-    
+
     void FileParser::reset()
     {
         mState = BeginState;
         mName.clear();
         mScriptParser.reset();
+        Parser::reset();
     }
 }
-
diff --git a/components/compiler/parser.cpp b/components/compiler/parser.cpp
index ff5bf33ee6..73cadfeba1 100644
--- a/components/compiler/parser.cpp
+++ b/components/compiler/parser.cpp
@@ -57,15 +57,15 @@ namespace Compiler
     std::string Parser::toLower (const std::string& name)
     {
         std::string lowerCase;
-        
+
         std::transform (name.begin(), name.end(), std::back_inserter (lowerCase),
             (int(*)(int)) std::tolower);
-            
+
         return lowerCase;
     }
 
     Parser::Parser (ErrorHandler& errorHandler, Context& context)
-    : mErrorHandler (errorHandler), mContext (context)
+    : mErrorHandler (errorHandler), mContext (context), mOptional (false), mEmpty (true)
     {}
 
     // destructor
@@ -79,7 +79,9 @@ namespace Compiler
 
     bool Parser::parseInt (int value, const TokenLoc& loc, Scanner& scanner)
     {
-        reportSeriousError ("Unexpected numeric value", loc);
+        if (!(mOptional && mEmpty))
+            reportSeriousError ("Unexpected numeric value", loc);
+
         return false;
     }
 
@@ -90,7 +92,9 @@ namespace Compiler
 
     bool Parser::parseFloat (float value, const TokenLoc& loc, Scanner& scanner)
     {
-        reportSeriousError ("Unexpected floating point value", loc);
+        if (!(mOptional && mEmpty))
+            reportSeriousError ("Unexpected floating point value", loc);
+
         return false;
     }
 
@@ -102,7 +106,9 @@ namespace Compiler
     bool Parser::parseName (const std::string& name, const TokenLoc& loc,
         Scanner& scanner)
     {
-        reportSeriousError ("Unexpected name", loc);
+        if (!(mOptional && mEmpty))
+            reportSeriousError ("Unexpected name", loc);
+
         return false;
     }
 
@@ -113,7 +119,9 @@ namespace Compiler
 
     bool Parser::parseKeyword (int keyword, const TokenLoc& loc, Scanner& scanner)
     {
-        reportSeriousError ("Unexpected keyword", loc);
+        if (!(mOptional && mEmpty))
+            reportSeriousError ("Unexpected keyword", loc);
+
         return false;
     }
 
@@ -124,7 +132,9 @@ namespace Compiler
 
     bool Parser::parseSpecial (int code, const TokenLoc& loc, Scanner& scanner)
     {
-        reportSeriousError ("Unexpected special token", loc);
+        if (!(mOptional && mEmpty))
+            reportSeriousError ("Unexpected special token", loc);
+
         return false;
     }
 
@@ -136,5 +146,25 @@ namespace Compiler
     {
         reportEOF();
     }
-}
 
+    void Parser::reset()
+    {
+        mOptional = false;
+        mEmpty = true;
+    }
+
+    void Parser::setOptional (bool optional)
+    {
+        mOptional = optional;
+    }
+
+    void Parser::start()
+    {
+        mEmpty = false;
+    }
+
+    bool Parser::isEmpty() const
+    {
+        return mEmpty;
+    }
+}
diff --git a/components/compiler/parser.hpp b/components/compiler/parser.hpp
index a55f5a024e..221e7c2c9f 100644
--- a/components/compiler/parser.hpp
+++ b/components/compiler/parser.hpp
@@ -18,6 +18,8 @@ namespace Compiler
     {
             ErrorHandler& mErrorHandler;
             Context& mContext;
+            bool mOptional;
+            bool mEmpty;
 
         protected:
 
@@ -47,7 +49,7 @@ namespace Compiler
             ///< constructor
 
             virtual ~Parser();
-		    ///< destructor
+            ///< destructor
 
             virtual bool parseInt (int value, const TokenLoc& loc, Scanner& scanner);
             ///< Handle an int token.
@@ -84,6 +86,19 @@ namespace Compiler
             ///< Handle EOF token.
             ///
             /// - Default-implementation: Report an error.
+
+            virtual void reset();
+            ///< Reset parser to clean state.
+
+            void setOptional (bool optional);
+            ///< Optional mode: If nothign has been parsed yet and an unexpected token is delivered, stop
+            /// parsing without raising an exception (after a reset the parser is in non-optional mode).
+
+            void start();
+            ///< Mark parser as non-empty (at least one token has been parser).
+
+            bool isEmpty() const;
+            ///< Has anything been parsed?
     };
 }
 
diff --git a/components/compiler/stringparser.cpp b/components/compiler/stringparser.cpp
index 633b7eab44..396a88c786 100644
--- a/components/compiler/stringparser.cpp
+++ b/components/compiler/stringparser.cpp
@@ -12,7 +12,7 @@ namespace Compiler
     StringParser::StringParser (ErrorHandler& errorHandler, Context& context, Literals& literals)
     : Parser (errorHandler, context), mLiterals (literals), mState (StartState), mSmashCase (false)
     {
-    
+
     }
 
     bool StringParser::parseName (const std::string& name, const TokenLoc& loc,
@@ -20,14 +20,15 @@ namespace Compiler
     {
         if (mState==StartState || mState==CommaState)
         {
+            start();
             if (mSmashCase)
-                Generator::pushString (mCode, mLiterals, toLower (name)); 
-            else    
+                Generator::pushString (mCode, mLiterals, toLower (name));
+            else
                 Generator::pushString (mCode, mLiterals, name);
-                
+
             return false;
         }
-    
+
         return Parser::parseName (name, loc, scanner);
     }
 
@@ -38,10 +39,10 @@ namespace Compiler
             mState = CommaState;
             return true;
         }
-        
+
         return Parser::parseSpecial (code, loc, scanner);
     }
-    
+
     void StringParser::append (std::vector<Interpreter::Type_Code>& code)
     {
         std::copy (mCode.begin(), mCode.end(), std::back_inserter (code));
@@ -52,11 +53,11 @@ namespace Compiler
         mState = StartState;
         mCode.clear();
         mSmashCase = false;
+        Parser::reset();
     }
-    
+
     void StringParser::smashCase()
     {
         mSmashCase = true;
     }
 }
-

From 08d2b804344e3c41e2daf08588ab7dd76010adfb Mon Sep 17 00:00:00 2001
From: Marc Zinnschlag <marc@zpages.de>
Date: Sun, 22 Aug 2010 12:56:35 +0200
Subject: [PATCH 06/32] message box fix

---
 apps/openmw/mwgui/window_manager.cpp   |  7 ++++++-
 components/interpreter/miscopcodes.hpp | 10 +++++-----
 2 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/apps/openmw/mwgui/window_manager.cpp b/apps/openmw/mwgui/window_manager.cpp
index ed4085ea8d..1752743f7f 100644
--- a/apps/openmw/mwgui/window_manager.cpp
+++ b/apps/openmw/mwgui/window_manager.cpp
@@ -5,6 +5,7 @@
 
 #include <assert.h>
 #include <iostream>
+#include <iterator>
 
 using namespace MWGui;
 
@@ -102,5 +103,9 @@ void WindowManager::messageBox (const std::string& message, const std::vector<st
     std::cout << "message box: " << message << std::endl;
 
     if (!buttons.empty())
-        std::cerr << "error: message box buttons not supported" << std::endl;
+    {
+        std::cout << "buttons: ";
+        std::copy (buttons.begin(), buttons.end(), std::ostream_iterator<std::string> (std::cout, ", "));
+        std::cout << std::endl;
+    }
 }
diff --git a/components/interpreter/miscopcodes.hpp b/components/interpreter/miscopcodes.hpp
index 7e7dcd18a7..fbee0aa266 100644
--- a/components/interpreter/miscopcodes.hpp
+++ b/components/interpreter/miscopcodes.hpp
@@ -19,6 +19,11 @@ namespace Interpreter
 
             virtual void execute (Runtime& runtime, unsigned int arg0)
             {
+                // message
+                int index = runtime[0].mInteger;
+                runtime.pop();
+                std::string message = runtime.getStringLiteral (index);
+
                 // buttons
                 std::vector<std::string> buttons;
 
@@ -31,11 +36,6 @@ namespace Interpreter
 
                 std::reverse (buttons.begin(), buttons.end());
 
-                // message
-                int index = runtime[0].mInteger;
-                runtime.pop();
-                std::string message = runtime.getStringLiteral (index);
-
                 // additional parameters
                 std::string formattedMessage;
 

From b3cc3073a35ca4850a225abc41cce6a2d89ad533 Mon Sep 17 00:00:00 2001
From: Marc Zinnschlag <marc@zpages.de>
Date: Sun, 22 Aug 2010 13:15:56 +0200
Subject: [PATCH 07/32] changed encoding of segment 3 opcodes (increasing the
 number of opcodes, while reducing the width of the argument)

---
 apps/openmw/mwscript/docs/vmformat.txt   |   2 +-
 components/compiler/generator.cpp        |   5 ++
 components/compiler/generator.hpp        |  61 +++++++------
 components/interpreter/docs/vmformat.txt |   6 +-
 components/interpreter/interpreter.cpp   | 108 +++++++++++------------
 5 files changed, 93 insertions(+), 89 deletions(-)

diff --git a/apps/openmw/mwscript/docs/vmformat.txt b/apps/openmw/mwscript/docs/vmformat.txt
index 70e5fe8c2b..9813e2e2fd 100644
--- a/apps/openmw/mwscript/docs/vmformat.txt
+++ b/apps/openmw/mwscript/docs/vmformat.txt
@@ -14,7 +14,7 @@ opcodes 0x200-0x3ff unused
 
 Segment 3:
 (not implemented yet)
-opcodes 0x200-0x3ff unused
+opcodes 0x20000-0x3ffff unused
 
 Segment 4:
 (not implemented yet)
diff --git a/components/compiler/generator.cpp b/components/compiler/generator.cpp
index c5262616bc..3d3b21d650 100644
--- a/components/compiler/generator.cpp
+++ b/components/compiler/generator.cpp
@@ -505,6 +505,11 @@ namespace Compiler
         void message (CodeContainer& code, Literals& literals, const std::string& message,
             int buttons)
         {
+            assert (buttons>=0);
+
+            if (buttons>=256)
+                throw std::runtime_error ("A message box can't have more than 255 buttons");
+
             int index = literals.addString (message);
 
             opPushInt (code, index);
diff --git a/components/compiler/generator.hpp b/components/compiler/generator.hpp
index a7559f7e9c..5671949f20 100644
--- a/components/compiler/generator.hpp
+++ b/components/compiler/generator.hpp
@@ -36,8 +36,8 @@ namespace Compiler
 
         inline Interpreter::Type_Code segment3 (unsigned int c, unsigned int arg0)
         {
-            assert (c<1024);
-            return 0xc0000000 | (c<<20) | (arg0 & 0xffff);    
+            assert (c<262144);
+            return 0xc0000000 | (c<<8) | (arg0 & 0xff);
         }
 
         inline Interpreter::Type_Code segment4 (unsigned int c, unsigned int arg0,
@@ -52,72 +52,71 @@ namespace Compiler
             assert (c<67108864);
             return 0xc8000000 | c;
         }
-    
+
         void pushInt (CodeContainer& code, Literals& literals, int value);
 
         void pushFloat (CodeContainer& code, Literals& literals, float value);
-        
+
         void pushString (CodeContainer& code, Literals& literals, const std::string& value);
 
         void assignToLocal (CodeContainer& code, char localType,
             int localIndex, const CodeContainer& value, char valueType);
-            
+
         void negate (CodeContainer& code, char valueType);
-        
+
         void add (CodeContainer& code, char valueType1, char valueType2);
 
-        void sub (CodeContainer& code, char valueType1, char valueType2);        
-        
-        void mul (CodeContainer& code, char valueType1, char valueType2);        
-        
-        void div (CodeContainer& code, char valueType1, char valueType2);        
-        
+        void sub (CodeContainer& code, char valueType1, char valueType2);
+
+        void mul (CodeContainer& code, char valueType1, char valueType2);
+
+        void div (CodeContainer& code, char valueType1, char valueType2);
+
         void convert (CodeContainer& code, char fromType, char toType);
-        
+
         void squareRoot (CodeContainer& code);
 
-        void exit (CodeContainer& code);        
-        
+        void exit (CodeContainer& code);
+
         void message (CodeContainer& code, Literals& literals, const std::string& message,
             int buttons);
-            
+
         void fetchLocal (CodeContainer& code, char localType, int localIndex);
 
         void jump (CodeContainer& code, int offset);
-         
+
         void jumpOnZero (CodeContainer& code, int offset);
-        
+
         void jumpOnNonZero (CodeContainer& code, int offset);
 
         void compare (CodeContainer& code, char op, char valueType1, char valueType2);
-        
+
         void menuMode (CodeContainer& code);
-        
+
         void assignToGlobal (CodeContainer& code, Literals& literals, char localType,
-            const std::string& name, const CodeContainer& value, char valueType);        
-            
+            const std::string& name, const CodeContainer& value, char valueType);
+
         void fetchGlobal (CodeContainer& code, Literals& literals, char localType,
-            const std::string& name);            
-            
+            const std::string& name);
+
         void random (CodeContainer& code);
-        
+
         void scriptRunning (CodeContainer& code);
-        
+
         void startScript (CodeContainer& code);
 
         void stopScript (CodeContainer& code);
-        
+
         void getDistance (CodeContainer& code, Literals& literals, const std::string id);
 
         void getSecondsPassed (CodeContainer& code);
-        
+
         void getDisabled (CodeContainer& code, Literals& literals, const std::string id);
-        
+
         void enable (CodeContainer& code, Literals& literals, const std::string id);
-        
+
         void disable (CodeContainer& code, Literals& literals, const std::string id);
     }
 }
 
 #endif
-
diff --git a/components/interpreter/docs/vmformat.txt b/components/interpreter/docs/vmformat.txt
index 291d1c490c..6619fc30a1 100644
--- a/components/interpreter/docs/vmformat.txt
+++ b/components/interpreter/docs/vmformat.txt
@@ -19,7 +19,7 @@ Code bit-patterns:
 00ccccccAAAAAAAAAAAAAAAAAAAAAAAA segment 0: 64 opcodes, 1 24-bit argument
 01ccccccAAAAAAAAAAAABBBBBBBBBBBB segment 1: 64 opcodes, 2 12-bit arguments
 10ccccccccccAAAAAAAAAAAAAAAAAAAA segment 2: 1024 opcodes, 1 20-bit argument
-110000ccccccccccAAAAAAAAAAAAAAAA segment 3: 1024 opcodes, 1 16-bit argument
+110000ccccccccccccccccccAAAAAAAA segment 3: 262144 opcodes, 1 8-bit argument
 110001ccccccccccAAAAAAAABBBBBBBB segment 4: 1024 opcodes, 2 8-bit arguments
 110010cccccccccccccccccccccccccc segment 5: 67108864 opcodes, no arguments
 other bit-patterns reserved
@@ -50,8 +50,8 @@ op    0: show message box with message string literal index in stack[0];
          additional arguments (if any) in stack[arg0+n]..stack[arg0+1];
          n is determined according to the message string
          all arguments are removed from stack
-opcodes 1-511 unused
-opcodes 512-1023 reserved for extensions
+opcodes 1-131071 unused
+opcodes 131072-262143 reserved for extensions
 
 Segment 4:
 opcodes 0-511 unused
diff --git a/components/interpreter/interpreter.cpp b/components/interpreter/interpreter.cpp
index f3ebd97a7a..44f626aadb 100644
--- a/components/interpreter/interpreter.cpp
+++ b/components/interpreter/interpreter.cpp
@@ -13,131 +13,131 @@ namespace Interpreter
     void Interpreter::execute (Type_Code code)
     {
         unsigned int segSpec = code>>30;
-        
+
         switch (segSpec)
         {
             case 0:
             {
                 int opcode = code>>24;
                 unsigned int arg0 = code & 0xffffff;
-                
+
                 std::map<int, Opcode1 *>::iterator iter = mSegment0.find (opcode);
-                
+
                 if (iter==mSegment0.end())
                     abortUnknownCode (0, opcode);
-                
+
                 iter->second->execute (mRuntime, arg0);
-                
+
                 return;
             }
-                        
+
             case 1:
             {
                 int opcode = (code>>24) & 0x3f;
                 unsigned int arg0 = (code>>16) & 0xfff;
                 unsigned int arg1 = code & 0xfff;
-                
+
                 std::map<int, Opcode2 *>::iterator iter = mSegment1.find (opcode);
-                
+
                 if (iter==mSegment1.end())
                     abortUnknownCode (1, opcode);
-                
+
                 iter->second->execute (mRuntime, arg0, arg1);
-                
+
                 return;
             }
-                        
+
             case 2:
             {
                 int opcode = (code>>20) & 0x3ff;
                 unsigned int arg0 = code & 0xfffff;
-                
+
                 std::map<int, Opcode1 *>::iterator iter = mSegment2.find (opcode);
-                
+
                 if (iter==mSegment2.end())
                     abortUnknownCode (2, opcode);
-                
+
                 iter->second->execute (mRuntime, arg0);
-                
+
                 return;
-            }                    
+            }
         }
-        
+
         segSpec = code>>26;
-        
+
         switch (segSpec)
-        { 
+        {
             case 0x30:
             {
-                int opcode = (code>>16) & 0x3ff;
-                unsigned int arg0 = code & 0xffff;
-                
+                int opcode = (code>>8) & 0x3ffff;
+                unsigned int arg0 = code & 0xff;
+
                 std::map<int, Opcode1 *>::iterator iter = mSegment3.find (opcode);
-                
+
                 if (iter==mSegment3.end())
                     abortUnknownCode (3, opcode);
-                    
+
                 iter->second->execute (mRuntime, arg0);
-                
+
                 return;
-            }        
-        
+            }
+
             case 0x31:
             {
                 int opcode = (code>>16) & 0x3ff;
                 unsigned int arg0 = (code>>8) & 0xff;
                 unsigned int arg1 = code & 0xff;
-                
+
                 std::map<int, Opcode2 *>::iterator iter = mSegment4.find (opcode);
-                
+
                 if (iter==mSegment4.end())
                     abortUnknownCode (4, opcode);
-                
+
                 iter->second->execute (mRuntime, arg0, arg1);
-                
+
                 return;
-            }            
-            
+            }
+
             case 0x32:
             {
                 int opcode = code & 0x3ffffff;
-                
+
                 std::map<int, Opcode0 *>::iterator iter = mSegment5.find (opcode);
-                
+
                 if (iter==mSegment5.end())
                     abortUnknownCode (5, opcode);
-                    
+
                 iter->second->execute (mRuntime);
-                
+
                 return;
             }
         }
-        
+
         abortUnknownSegment (code);
     }
 
     void Interpreter::abortUnknownCode (int segment, int opcode)
     {
         std::ostringstream error;
-        
+
         error << "unknown opcode " << opcode << " in segment " << segment;
-        
+
         throw std::runtime_error (error.str());
     }
-    
+
     void Interpreter::abortUnknownSegment (Type_Code code)
     {
         std::ostringstream error;
-        
+
         error << "opcode outside of the allocated segment range: " << code;
-        
+
         throw std::runtime_error (error.str());
     }
-            
+
     Interpreter::Interpreter (Context& context)
     : mRuntime (context)
     {}
-    
+
     Interpreter::~Interpreter()
     {
         for (std::map<int, Opcode1 *>::iterator iter (mSegment0.begin());
@@ -159,12 +159,12 @@ namespace Interpreter
         for (std::map<int, Opcode2 *>::iterator iter (mSegment4.begin());
             iter!=mSegment4.end(); ++iter)
             delete iter->second;
-            
+
         for (std::map<int, Opcode0 *>::iterator iter (mSegment5.begin());
             iter!=mSegment5.end(); ++iter)
-            delete iter->second;            
+            delete iter->second;
     }
-    
+
     void Interpreter::installSegment0 (int code, Opcode1 *opcode)
     {
         mSegment0.insert (std::make_pair (code, opcode));
@@ -194,24 +194,24 @@ namespace Interpreter
     {
         mSegment5.insert (std::make_pair (code, opcode));
     }
-            
+
     void Interpreter::run (const Type_Code *code, int codeSize)
     {
         assert (codeSize>=4);
-        
+
         mRuntime.configure (code, codeSize);
-        
+
         int opcodes = static_cast<int> (code[0]);
-        
+
         const Type_Code *codeBlock = code + 4;
-        
+
         while (mRuntime.getPC()>=0 && mRuntime.getPC()<opcodes)
         {
             Type_Code code = codeBlock[mRuntime.getPC()];
             mRuntime.setPC (mRuntime.getPC()+1);
             execute (code);
         }
-        
+
         mRuntime.clear();
     }
 }

From c18e83d7c00ae68fd6bfc717e962dfb5110f6c8f Mon Sep 17 00:00:00 2001
From: Marc Zinnschlag <marc@zpages.de>
Date: Sun, 22 Aug 2010 14:00:30 +0200
Subject: [PATCH 08/32] extended scripting extensions to code segment 3
 (instructions and functions with optional arguments)

---
 components/compiler/exprparser.cpp |   9 +-
 components/compiler/extensions.cpp | 184 ++++++++++++++++++++---------
 components/compiler/extensions.hpp |  43 +++----
 components/compiler/lineparser.cpp |   4 +-
 4 files changed, 160 insertions(+), 80 deletions(-)

diff --git a/components/compiler/exprparser.cpp b/components/compiler/exprparser.cpp
index 484aea878f..06c3207e2d 100644
--- a/components/compiler/exprparser.cpp
+++ b/components/compiler/exprparser.cpp
@@ -346,9 +346,10 @@ namespace Compiler
                         start();
 
                         mTokenLoc = loc;
-                        parseArguments (argumentType, scanner);
+                        int optionals = parseArguments (argumentType, scanner);
 
-                        extensions->generateFunctionCode (keyword, mCode, mLiterals, mExplicit);
+                        extensions->generateFunctionCode (keyword, mCode, mLiterals, mExplicit,
+                            optionals);
                         mOperands.push_back (returnType);
                         mExplicit.clear();
                         mRefOp = false;
@@ -465,9 +466,9 @@ namespace Compiler
                     if (extensions->isFunction (keyword, returnType, argumentType, false))
                     {
                         mTokenLoc = loc;
-                        parseArguments (argumentType, scanner);
+                        int optionals = parseArguments (argumentType, scanner);
 
-                        extensions->generateFunctionCode (keyword, mCode, mLiterals, "");
+                        extensions->generateFunctionCode (keyword, mCode, mLiterals, "", optionals);
                         mOperands.push_back (returnType);
 
                         mNextOperand = false;
diff --git a/components/compiler/extensions.cpp b/components/compiler/extensions.cpp
index 78ae0fdfd3..3b1d180b1f 100644
--- a/components/compiler/extensions.cpp
+++ b/components/compiler/extensions.cpp
@@ -14,119 +14,197 @@ namespace Compiler
     int Extensions::searchKeyword (const std::string& keyword) const
     {
         std::map<std::string, int>::const_iterator iter = mKeywords.find (keyword);
-        
+
         if (iter==mKeywords.end())
             return 0;
-            
+
         return iter->second;
     }
-        
+
     bool Extensions::isFunction (int keyword, char& returnType, std::string& argumentType,
         bool explicitReference) const
     {
         std::map<int, Function>::const_iterator iter = mFunctions.find (keyword);
-        
+
         if (iter==mFunctions.end())
             return false;
-            
+
         if (explicitReference && iter->second.mCodeExplicit==-1)
             return false;
-            
+
         returnType = iter->second.mReturn;
         argumentType = iter->second.mArguments;
         return true;
     }
-        
+
     bool Extensions::isInstruction (int keyword, std::string& argumentType,
         bool explicitReference) const
     {
         std::map<int, Instruction>::const_iterator iter = mInstructions.find (keyword);
-        
+
         if (iter==mInstructions.end())
             return false;
 
         if (explicitReference && iter->second.mCodeExplicit==-1)
             return false;
-            
+
         argumentType = iter->second.mArguments;
         return true;
     }
-        
+
     void Extensions::registerFunction (const std::string& keyword, char returnType,
-        const std::string& argumentType, int segment5code, int segment5codeExplicit)
+        const std::string& argumentType, int code, int codeExplicit)
     {
-        assert (segment5code>=33554432 && segment5code<=67108863);
-    
-        int code = mNextKeywordIndex--;
-        
-        mKeywords.insert (std::make_pair (keyword, code));
-        
         Function function;
+
+        if (argumentType.find ('/')==std::string::npos)
+        {
+            function.mSegment = 5;
+            assert (code>=33554432 && code<=67108863);
+            assert (codeExplicit==-1 || (codeExplicit>=33554432 && codeExplicit<=67108863));
+        }
+        else
+        {
+            function.mSegment = 3;
+            assert (code>=0x20000 && code<=0x2ffff);
+            assert (codeExplicit==-1 || (codeExplicit>=0x20000 && codeExplicit<=0x2ffff));
+        }
+
+        int keywordIndex = mNextKeywordIndex--;
+
+        mKeywords.insert (std::make_pair (keyword, keywordIndex));
+
         function.mReturn = returnType;
         function.mArguments = argumentType;
-        function.mCode = segment5code;
-        function.mCodeExplicit = segment5codeExplicit;
-        
-        mFunctions.insert (std::make_pair (code, function));
+        function.mCode = code;
+        function.mCodeExplicit = codeExplicit;
+
+        mFunctions.insert (std::make_pair (keywordIndex, function));
     }
-        
+
     void Extensions::registerInstruction (const std::string& keyword,
-        const std::string& argumentType, int segment5code, int segment5codeExplicit)
+        const std::string& argumentType, int code, int codeExplicit)
     {
-        assert (segment5code>=33554432 && segment5code<=67108863);
-    
-        int code = mNextKeywordIndex--;
-        
-        mKeywords.insert (std::make_pair (keyword, code));
-        
         Instruction instruction;
+
+        if (argumentType.find ('/')==std::string::npos)
+        {
+            instruction.mSegment = 5;
+            assert (code>=33554432 && code<=67108863);
+            assert (codeExplicit==-1 || (codeExplicit>=33554432 && codeExplicit<=67108863));
+        }
+        else
+        {
+            instruction.mSegment = 3;
+            assert (code>=0x20000 && code<=0x2ffff);
+            assert (codeExplicit==-1 || (codeExplicit>=0x20000 && codeExplicit<=0x2ffff));
+        }
+
+        int keywordIndex = mNextKeywordIndex--;
+
+        mKeywords.insert (std::make_pair (keyword, keywordIndex));
+
         instruction.mArguments = argumentType;
-        instruction.mCode = segment5code;
-        instruction.mCodeExplicit = segment5codeExplicit;
-        
-        mInstructions.insert (std::make_pair (code, instruction));
+        instruction.mCode = code;
+        instruction.mCodeExplicit = codeExplicit;
+
+        mInstructions.insert (std::make_pair (keywordIndex, instruction));
     }
-        
+
     void Extensions::generateFunctionCode (int keyword, std::vector<Interpreter::Type_Code>& code,
-        Literals& literals, const std::string& id) const
+        Literals& literals, const std::string& id, int optionalArguments) const
     {
+        assert (optionalArguments>=0);
+
         std::map<int, Function>::const_iterator iter = mFunctions.find (keyword);
-        
+
         if (iter==mFunctions.end())
             throw std::logic_error ("unknown custom function keyword");
-            
+
+        if (optionalArguments && iter->second.mSegment!=3)
+            throw std::logic_error ("functions with optional arguments must be placed into segment 3");
+
         if (!id.empty())
         {
             if (iter->second.mCodeExplicit==-1)
                 throw std::logic_error ("explicit references not supported");
-        
+
             int index = literals.addString (id);
-            Generator::pushInt (code, literals, index);        
+            Generator::pushInt (code, literals, index);
+        }
+
+        switch (iter->second.mSegment)
+        {
+            case 3:
+
+                if (optionalArguments>=256)
+                    throw std::logic_error ("number of optional arguments is too large for segment 3");
+
+                code.push_back (Generator::segment3 (
+                    id.empty() ? iter->second.mCode : iter->second.mCodeExplicit,
+                    optionalArguments));
+
+                break;
+
+            case 5:
+
+                code.push_back (Generator::segment5 (
+                    id.empty() ? iter->second.mCode : iter->second.mCodeExplicit));
+
+                break;
+
+            default:
+
+                throw std::logic_error ("unsupported code segment");
         }
-            
-        code.push_back (Generator::segment5 (
-            id.empty() ? iter->second.mCode : iter->second.mCodeExplicit));
     }
-        
+
     void Extensions::generateInstructionCode (int keyword,
-        std::vector<Interpreter::Type_Code>& code, Literals& literals, const std::string& id)
-        const
+        std::vector<Interpreter::Type_Code>& code, Literals& literals, const std::string& id,
+        int optionalArguments) const
     {
+        assert (optionalArguments>=0);
+
         std::map<int, Instruction>::const_iterator iter = mInstructions.find (keyword);
-        
+
         if (iter==mInstructions.end())
             throw std::logic_error ("unknown custom instruction keyword");
-            
+
+        if (optionalArguments && iter->second.mSegment!=3)
+            throw std::logic_error ("instructions with optional arguments must be placed into segment 3");
+
         if (!id.empty())
         {
             if (iter->second.mCodeExplicit==-1)
                 throw std::logic_error ("explicit references not supported");
-        
+
             int index = literals.addString (id);
-            Generator::pushInt (code, literals, index);        
+            Generator::pushInt (code, literals, index);
         }
-                        
-        code.push_back (Generator::segment5 (
-            id.empty() ? iter->second.mCode : iter->second.mCodeExplicit));
-    }    
+
+        switch (iter->second.mSegment)
+        {
+            case 3:
+
+                if (optionalArguments>=256)
+                    throw std::logic_error ("number of optional arguments is too large for segment 3");
+
+                code.push_back (Generator::segment3 (
+                    id.empty() ? iter->second.mCode : iter->second.mCodeExplicit,
+                    optionalArguments));
+
+                break;
+
+            case 5:
+
+                code.push_back (Generator::segment5 (
+                    id.empty() ? iter->second.mCode : iter->second.mCodeExplicit));
+
+                break;
+
+            default:
+
+                throw std::logic_error ("unsupported code segment");
+        }
+    }
 }
diff --git a/components/compiler/extensions.hpp b/components/compiler/extensions.hpp
index 85a761951a..960cac1578 100644
--- a/components/compiler/extensions.hpp
+++ b/components/compiler/extensions.hpp
@@ -10,9 +10,9 @@
 namespace Compiler
 {
     class Literals;
-    
+
     /// \brief Collection of compiler extensions
-    
+
     class Extensions
     {
             struct Function
@@ -21,29 +21,31 @@ namespace Compiler
                 std::string mArguments;
                 int mCode;
                 int mCodeExplicit;
+                int mSegment;
             };
-            
+
             struct Instruction
             {
                 std::string mArguments;
-                int mCode;            
+                int mCode;
                 int mCodeExplicit;
+                int mSegment;
             };
-    
+
             int mNextKeywordIndex;
             std::map<std::string, int> mKeywords;
             std::map<int, Function> mFunctions;
             std::map<int, Instruction> mInstructions;
-        
+
         public:
-    
+
             Extensions();
-    
+
             int searchKeyword (const std::string& keyword) const;
             ///< Return extension keyword code, that is assigned to the string \a keyword.
             /// - if no match is found 0 is returned.
             /// - keyword must be all lower case.
-            
+
             bool isFunction (int keyword, char& returnType, std::string& argumentType,
                 bool explicitReference) const;
             ///< Is this keyword registered with a function? If yes, return return and argument
@@ -52,32 +54,31 @@ namespace Compiler
             bool isInstruction (int keyword, std::string& argumentType,
                 bool explicitReference) const;
             ///< Is this keyword registered with a function? If yes, return argument types.
-                        
+
             void registerFunction (const std::string& keyword, char returnType,
-                const std::string& argumentType, int segment5code, int segment5codeExplicit = -1);
+                const std::string& argumentType, int code, int codeExplicit = -1);
             ///< Register a custom function
             /// - keyword must be all lower case.
             /// - keyword must be unique
             /// - if explicit references are not supported, segment5codeExplicit must be set to -1
-            /// \note Currently only segment 5 opcodes are supported.
-            
+            /// \note Currently only segment 3 and segment 5 opcodes are supported.
+
             void registerInstruction (const std::string& keyword,
-                const std::string& argumentType, int segment5code, int segment5codeExplicit = -1);
+                const std::string& argumentType, int code, int codeExplicit = -1);
             ///< Register a custom instruction
             /// - keyword must be all lower case.
             /// - keyword must be unique
             /// - if explicit references are not supported, segment5codeExplicit must be set to -1
-            /// \note Currently only segment 5 opcodes are supported.
-            
+            /// \note Currently only segment 3 and segment 5 opcodes are supported.
+
             void generateFunctionCode (int keyword, std::vector<Interpreter::Type_Code>& code,
-                Literals& literals, const std::string& id) const;
+                Literals& literals, const std::string& id, int optionalArguments) const;
             ///< Append code for function to \a code.
-            
+
             void generateInstructionCode (int keyword, std::vector<Interpreter::Type_Code>& code,
-                Literals& literals, const std::string& id) const;
-            ///< Append code for function to \a code.            
+                Literals& literals, const std::string& id, int optionalArguments) const;
+            ///< Append code for function to \a code.
     };
 }
 
 #endif
-
diff --git a/components/compiler/lineparser.cpp b/components/compiler/lineparser.cpp
index b4c79c972e..3f80d671eb 100644
--- a/components/compiler/lineparser.cpp
+++ b/components/compiler/lineparser.cpp
@@ -242,9 +242,9 @@ namespace Compiler
 
                 if (extensions->isInstruction (keyword, argumentType, mState==ExplicitState))
                 {
-                    mExprParser.parseArguments (argumentType, scanner, mCode, true);
+                    int optionals = mExprParser.parseArguments (argumentType, scanner, mCode, true);
 
-                    extensions->generateInstructionCode (keyword, mCode, mLiterals, mExplicit);
+                    extensions->generateInstructionCode (keyword, mCode, mLiterals, mExplicit, optionals);
                     mState = EndState;
                     return true;
                 }

From 14cf007a3f8a494f10a6f0edf9b5d5b13fb96656 Mon Sep 17 00:00:00 2001
From: Marc Zinnschlag <marc@zpages.de>
Date: Sun, 22 Aug 2010 14:49:25 +0200
Subject: [PATCH 09/32] added first batch of AI-related instructions and
 functions (they don't do anything at this point)

---
 apps/openmw/CMakeLists.txt             |   2 +
 apps/openmw/mwscript/aiextensions.cpp  | 214 +++++++++++++++++++++++++
 apps/openmw/mwscript/aiextensions.hpp  |  25 +++
 apps/openmw/mwscript/docs/vmformat.txt |  11 +-
 apps/openmw/mwscript/extensions.cpp    |   3 +
 5 files changed, 252 insertions(+), 3 deletions(-)
 create mode 100644 apps/openmw/mwscript/aiextensions.cpp
 create mode 100644 apps/openmw/mwscript/aiextensions.hpp

diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt
index b5948aaeac..f0aafbbbca 100644
--- a/apps/openmw/CMakeLists.txt
+++ b/apps/openmw/CMakeLists.txt
@@ -60,6 +60,7 @@ set(GAMESCRIPT
     mwscript/skyextensions.cpp
     mwscript/statsextensions.cpp
     mwscript/containerextensions.cpp
+    mwscript/aiextensions.cpp
     mwscript/extensions.cpp
     mwscript/globalscripts.cpp
     )
@@ -75,6 +76,7 @@ set(GAMESCRIPT_HEADER
     mwscript/skyextensions.hpp
     mwscript/statsextensions.hpp
     mwscript/containerextensions.hpp
+    mwscript/aiextensions.hpp
     mwscript/extensions.hpp
     mwscript/globalscripts.hpp
     )
diff --git a/apps/openmw/mwscript/aiextensions.cpp b/apps/openmw/mwscript/aiextensions.cpp
new file mode 100644
index 0000000000..e1fdc1976f
--- /dev/null
+++ b/apps/openmw/mwscript/aiextensions.cpp
@@ -0,0 +1,214 @@
+
+#include "aiextensions.hpp"
+
+#include <components/compiler/extensions.hpp>
+
+#include <components/interpreter/interpreter.hpp>
+#include <components/interpreter/runtime.hpp>
+#include <components/interpreter/opcodes.hpp>
+
+#include "interpretercontext.hpp"
+
+#include <iostream>
+namespace MWScript
+{
+    namespace Ai
+    {
+        class OpAiTravel : public Interpreter::Opcode1
+        {
+            public:
+
+                virtual void execute (Interpreter::Runtime& runtime, unsigned int arg0)
+                {
+                    MWScript::InterpreterContext& context
+                        = static_cast<MWScript::InterpreterContext&> (runtime.getContext());
+
+                    MWWorld::Ptr ptr = context.getReference();
+
+                    Interpreter::Type_Float x = runtime[0].mInteger;
+                    runtime.pop();
+
+                    Interpreter::Type_Float y = runtime[0].mInteger;
+                    runtime.pop();
+
+                    Interpreter::Type_Float z = runtime[0].mInteger;
+                    runtime.pop();
+
+                    // discard additional arguments (reset), because we have no idea what they mean.
+                    for (unsigned int i=0; i<arg0; ++i) runtime.pop();
+
+                    std::cout << "AiTravel: " << x << ", " << y << ", " << z << std::endl;
+                }
+        };
+
+        class OpAiTravelExplicit : public Interpreter::Opcode1
+        {
+            public:
+
+                virtual void execute (Interpreter::Runtime& runtime, unsigned int arg0)
+                {
+                    MWScript::InterpreterContext& context
+                        = static_cast<MWScript::InterpreterContext&> (runtime.getContext());
+
+                    std::string id = runtime.getStringLiteral (runtime[0].mInteger);
+                    runtime.pop();
+
+                    MWWorld::Ptr ptr = context.getWorld().getPtr (id, false);
+
+                    Interpreter::Type_Float x = runtime[0].mInteger;
+                    runtime.pop();
+
+                    Interpreter::Type_Float y = runtime[0].mInteger;
+                    runtime.pop();
+
+                    Interpreter::Type_Float z = runtime[0].mInteger;
+                    runtime.pop();
+
+                    // discard additional arguments (reset), because we have no idea what they mean.
+                    for (unsigned int i=0; i<arg0; ++i) runtime.pop();
+
+                    std::cout << "AiTravel: " << x << ", " << y << ", " << z << std::endl;
+                }
+        };
+
+        class OpAiEscort : public Interpreter::Opcode1
+        {
+            public:
+
+                virtual void execute (Interpreter::Runtime& runtime, unsigned int arg0)
+                {
+                    MWScript::InterpreterContext& context
+                        = static_cast<MWScript::InterpreterContext&> (runtime.getContext());
+
+                    std::string id = runtime.getStringLiteral (runtime[0].mInteger);
+                    runtime.pop();
+
+                    MWWorld::Ptr ptr = context.getReference();
+
+                    std::string actor = runtime.getStringLiteral (runtime[0].mInteger);
+                    runtime.pop();
+
+                    Interpreter::Type_Float duration = runtime[0].mInteger;
+                    runtime.pop();
+
+                    Interpreter::Type_Float x = runtime[0].mInteger;
+                    runtime.pop();
+
+                    Interpreter::Type_Float y = runtime[0].mInteger;
+                    runtime.pop();
+
+                    Interpreter::Type_Float z = runtime[0].mInteger;
+                    runtime.pop();
+
+                    // discard additional arguments (reset), because we have no idea what they mean.
+                    for (unsigned int i=0; i<arg0; ++i) runtime.pop();
+
+                    std::cout << "AiEscort: " << x << ", " << y << ", " << z << ", " << duration
+                        << std::endl;
+                }
+        };
+
+        class OpAiEscortExplicit : public Interpreter::Opcode1
+        {
+            public:
+
+                virtual void execute (Interpreter::Runtime& runtime, unsigned int arg0)
+                {
+                    MWScript::InterpreterContext& context
+                        = static_cast<MWScript::InterpreterContext&> (runtime.getContext());
+
+                    std::string id = runtime.getStringLiteral (runtime[0].mInteger);
+                    runtime.pop();
+
+                    MWWorld::Ptr ptr = context.getWorld().getPtr (id, false);
+
+                    std::string actor = runtime.getStringLiteral (runtime[0].mInteger);
+                    runtime.pop();
+
+                    Interpreter::Type_Float duration = runtime[0].mInteger;
+                    runtime.pop();
+
+                    Interpreter::Type_Float x = runtime[0].mInteger;
+                    runtime.pop();
+
+                    Interpreter::Type_Float y = runtime[0].mInteger;
+                    runtime.pop();
+
+                    Interpreter::Type_Float z = runtime[0].mInteger;
+                    runtime.pop();
+
+                    // discard additional arguments (reset), because we have no idea what they mean.
+                    for (unsigned int i=0; i<arg0; ++i) runtime.pop();
+
+                    std::cout << "AiEscort: " << x << ", " << y << ", " << z << ", " << duration
+                        << std::endl;
+                }
+        };
+
+        class OpGetAiPackageDone : public Interpreter::Opcode0
+        {
+            public:
+
+                virtual void execute (Interpreter::Runtime& runtime)
+                {
+                    MWScript::InterpreterContext& context
+                        = static_cast<MWScript::InterpreterContext&> (runtime.getContext());
+
+                    MWWorld::Ptr ptr = context.getReference();
+
+                    Interpreter::Type_Integer value = 1;
+
+                    runtime.push (value);
+                }
+        };
+
+        class OpGetAiPackageDoneExplicit : public Interpreter::Opcode0
+        {
+            public:
+
+                virtual void execute (Interpreter::Runtime& runtime)
+                {
+                    MWScript::InterpreterContext& context
+                        = static_cast<MWScript::InterpreterContext&> (runtime.getContext());
+
+                    std::string id = runtime.getStringLiteral (runtime[0].mInteger);
+                    runtime.pop();
+
+                    MWWorld::Ptr ptr = context.getWorld().getPtr (id, false);
+
+                    Interpreter::Type_Integer value = 1;
+
+                    runtime.push (value);
+                }
+        };
+
+
+        const int opcodeAiTravel = 0x20000;
+        const int opcodeAiTravelExplicit = 0x20001;
+        const int opcodeAiEscort = 0x20002;
+        const int opcodeAiEscortExplicit = 0x20003;
+        const int opcodeGetAiPackageDone = 0x200007c;
+        const int opcodeGetAiPackageDoneExplicit = 0x200007d;
+
+        void registerExtensions (Compiler::Extensions& extensions)
+        {
+            extensions.registerInstruction ("aitravel", "cllll/l", opcodeAiTravel,
+                opcodeAiTravelExplicit);
+            extensions.registerInstruction ("aiescort", "cllll/l", opcodeAiEscort,
+                opcodeAiEscortExplicit);
+
+            extensions.registerFunction ("getaipackagedone", 'l', "", opcodeGetAiPackageDone,
+                opcodeGetAiPackageDoneExplicit);
+        }
+
+        void installOpcodes (Interpreter::Interpreter& interpreter)
+        {
+            interpreter.installSegment3 (opcodeAiTravel, new OpAiTravel);
+            interpreter.installSegment3 (opcodeAiTravelExplicit, new OpAiTravelExplicit);
+            interpreter.installSegment3 (opcodeAiEscort, new OpAiEscort);
+            interpreter.installSegment3 (opcodeAiEscortExplicit, new OpAiEscortExplicit);
+            interpreter.installSegment5 (opcodeGetAiPackageDone, new OpGetAiPackageDone);
+            interpreter.installSegment5 (opcodeGetAiPackageDoneExplicit, new OpGetAiPackageDoneExplicit);
+        }
+    }
+}
diff --git a/apps/openmw/mwscript/aiextensions.hpp b/apps/openmw/mwscript/aiextensions.hpp
new file mode 100644
index 0000000000..547341476e
--- /dev/null
+++ b/apps/openmw/mwscript/aiextensions.hpp
@@ -0,0 +1,25 @@
+#ifndef GAME_SCRIPT_AIEXTENSIONS_H
+#define GAME_SCRIPT_AIEXTENSIONS_H
+
+namespace Compiler
+{
+    class Extensions;
+}
+
+namespace Interpreter
+{
+    class Interpreter;
+}
+
+namespace MWScript
+{
+    /// \brief AI-related script functionality
+    namespace Ai
+    {
+        void registerExtensions (Compiler::Extensions& extensions);
+
+        void installOpcodes (Interpreter::Interpreter& interpreter);
+    }
+}
+
+#endif
diff --git a/apps/openmw/mwscript/docs/vmformat.txt b/apps/openmw/mwscript/docs/vmformat.txt
index 9813e2e2fd..88d3f59ac4 100644
--- a/apps/openmw/mwscript/docs/vmformat.txt
+++ b/apps/openmw/mwscript/docs/vmformat.txt
@@ -13,8 +13,11 @@ Segment 2:
 opcodes 0x200-0x3ff unused
 
 Segment 3:
-(not implemented yet)
-opcodes 0x20000-0x3ffff unused
+op 0x20000: AiTravel
+op 0x20001: AiTravel, explicit reference
+op 0x20002: AiEscort
+op 0x20003: AiEscort, explicit reference
+opcodes 0x20004-0x3ffff unused
 
 Segment 4:
 (not implemented yet)
@@ -83,4 +86,6 @@ op 0x2000078: GetItemCount
 op 0x2000079: GetItemCount, explicit reference
 op 0x200007a: RemoveItem
 op 0x200007b: RemoveItem, explicit reference
-opcodes 0x200007c-0x3ffffff unused
+op 0x200007c: GetAiPackageDone
+op 0x200007d: GetAiPackageDone, explicit reference
+opcodes 0x200007e-0x3ffffff unused
diff --git a/apps/openmw/mwscript/extensions.cpp b/apps/openmw/mwscript/extensions.cpp
index 1b3d3df14e..9b1e2dd45c 100644
--- a/apps/openmw/mwscript/extensions.cpp
+++ b/apps/openmw/mwscript/extensions.cpp
@@ -11,6 +11,7 @@
 #include "skyextensions.hpp"
 #include "statsextensions.hpp"
 #include "containerextensions.hpp"
+#include "aiextensions.hpp"
 
 namespace MWScript
 {
@@ -23,6 +24,7 @@ namespace MWScript
         Sky::registerExtensions (extensions);
         Stats::registerExtensions (extensions);
         Container::registerExtensions (extensions);
+        Ai::registerExtensions (extensions);
     }
 
     void installOpcodes (Interpreter::Interpreter& interpreter)
@@ -35,5 +37,6 @@ namespace MWScript
         Sky::installOpcodes (interpreter);
         Stats::installOpcodes (interpreter);
         Container::installOpcodes (interpreter);
+        Ai::installOpcodes (interpreter);
     }
 }

From 68a788b2c87abe5af73023a7e48ed0fbe1f035f6 Mon Sep 17 00:00:00 2001
From: Marc Zinnschlag <marc@zpages.de>
Date: Sun, 22 Aug 2010 15:11:40 +0200
Subject: [PATCH 10/32] added instructions for enabling/disabling player
 controls (they don't do anything yet)

---
 apps/openmw/CMakeLists.txt                 |  2 +
 apps/openmw/mwscript/controlextensions.cpp | 70 ++++++++++++++++++++++
 apps/openmw/mwscript/controlextensions.hpp | 25 ++++++++
 apps/openmw/mwscript/docs/vmformat.txt     |  4 +-
 apps/openmw/mwscript/extensions.cpp        |  3 +
 5 files changed, 103 insertions(+), 1 deletion(-)
 create mode 100644 apps/openmw/mwscript/controlextensions.cpp
 create mode 100644 apps/openmw/mwscript/controlextensions.hpp

diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt
index f0aafbbbca..6863b2e136 100644
--- a/apps/openmw/CMakeLists.txt
+++ b/apps/openmw/CMakeLists.txt
@@ -61,6 +61,7 @@ set(GAMESCRIPT
     mwscript/statsextensions.cpp
     mwscript/containerextensions.cpp
     mwscript/aiextensions.cpp
+    mwscript/controlextensions.cpp
     mwscript/extensions.cpp
     mwscript/globalscripts.cpp
     )
@@ -77,6 +78,7 @@ set(GAMESCRIPT_HEADER
     mwscript/statsextensions.hpp
     mwscript/containerextensions.hpp
     mwscript/aiextensions.hpp
+    mwscript/controlextensions.hpp
     mwscript/extensions.hpp
     mwscript/globalscripts.hpp
     )
diff --git a/apps/openmw/mwscript/controlextensions.cpp b/apps/openmw/mwscript/controlextensions.cpp
new file mode 100644
index 0000000000..e38ee7c2db
--- /dev/null
+++ b/apps/openmw/mwscript/controlextensions.cpp
@@ -0,0 +1,70 @@
+
+#include "statsextensions.hpp"
+
+#include <components/compiler/extensions.hpp>
+
+#include <components/interpreter/interpreter.hpp>
+#include <components/interpreter/runtime.hpp>
+#include <components/interpreter/opcodes.hpp>
+
+#include "interpretercontext.hpp"
+
+#include <iostream>
+
+namespace MWScript
+{
+    namespace Control
+    {
+        class OpSetControl : public Interpreter::Opcode0
+        {
+                std::string mControl;
+                bool mEnable;
+
+            public:
+
+                OpSetControl (const std::string& control, bool enable)
+                : mControl (control), mEnable (enable)
+                {}
+
+                virtual void execute (Interpreter::Runtime& runtime)
+                {
+                    if (mEnable)
+                        std::cout << "enable: " << mControl << std::endl;
+                    else
+                        std::cout << "disable: " << mControl << std::endl;
+                }
+        };
+
+        const int numberOfControls = 7;
+
+        const int opcodeEnable = 0x200007e;
+        const int opcodeDisable = 0x2000085;
+
+        const char *controls[numberOfControls] =
+        {
+            "playercontrols", "playerfighting", "playerjumping", "playerlooking", "playermagic",
+            "playerviewswitch", "vanitymode"
+        };
+
+        void registerExtensions (Compiler::Extensions& extensions)
+        {
+            std::string enable ("enable");
+            std::string disable ("disable");
+
+            for (int i=0; i<numberOfControls; ++i)
+            {
+                extensions.registerInstruction (enable + controls[i], "", opcodeEnable+i);
+                extensions.registerInstruction (disable + controls[i], "", opcodeDisable+i);
+            }
+        }
+
+        void installOpcodes (Interpreter::Interpreter& interpreter)
+        {
+            for (int i=0; i<numberOfControls; ++i)
+            {
+                interpreter.installSegment5 (opcodeEnable+i, new OpSetControl (controls[i], true));
+                interpreter.installSegment5 (opcodeDisable+i, new OpSetControl (controls[i], false));
+            }
+        }
+    }
+}
diff --git a/apps/openmw/mwscript/controlextensions.hpp b/apps/openmw/mwscript/controlextensions.hpp
new file mode 100644
index 0000000000..8e6111705f
--- /dev/null
+++ b/apps/openmw/mwscript/controlextensions.hpp
@@ -0,0 +1,25 @@
+#ifndef GAME_SCRIPT_CONTROLEXTENSIONS_H
+#define GAME_SCRIPT_CONTROLEXTENSIONS_H
+
+namespace Compiler
+{
+    class Extensions;
+}
+
+namespace Interpreter
+{
+    class Interpreter;
+}
+
+namespace MWScript
+{
+    /// \brief player controls-related script functionality
+    namespace Control
+    {
+        void registerExtensions (Compiler::Extensions& extensions);
+
+        void installOpcodes (Interpreter::Interpreter& interpreter);
+    }
+}
+
+#endif
diff --git a/apps/openmw/mwscript/docs/vmformat.txt b/apps/openmw/mwscript/docs/vmformat.txt
index 88d3f59ac4..47f883c8a9 100644
--- a/apps/openmw/mwscript/docs/vmformat.txt
+++ b/apps/openmw/mwscript/docs/vmformat.txt
@@ -88,4 +88,6 @@ op 0x200007a: RemoveItem
 op 0x200007b: RemoveItem, explicit reference
 op 0x200007c: GetAiPackageDone
 op 0x200007d: GetAiPackageDone, explicit reference
-opcodes 0x200007e-0x3ffffff unused
+op 0x200007e-0x2000084: Enable Controls
+op 0x2000085-0x200008b: Disable Controls
+opcodes 0x200008c-0x3ffffff unused
diff --git a/apps/openmw/mwscript/extensions.cpp b/apps/openmw/mwscript/extensions.cpp
index 9b1e2dd45c..15d482fc19 100644
--- a/apps/openmw/mwscript/extensions.cpp
+++ b/apps/openmw/mwscript/extensions.cpp
@@ -12,6 +12,7 @@
 #include "statsextensions.hpp"
 #include "containerextensions.hpp"
 #include "aiextensions.hpp"
+#include "controlextensions.hpp"
 
 namespace MWScript
 {
@@ -25,6 +26,7 @@ namespace MWScript
         Stats::registerExtensions (extensions);
         Container::registerExtensions (extensions);
         Ai::registerExtensions (extensions);
+        Control::registerExtensions (extensions);
     }
 
     void installOpcodes (Interpreter::Interpreter& interpreter)
@@ -38,5 +40,6 @@ namespace MWScript
         Stats::installOpcodes (interpreter);
         Container::installOpcodes (interpreter);
         Ai::installOpcodes (interpreter);
+        Control::installOpcodes (interpreter);
     }
 }

From f3bf46f1a9e13c065d880008bedc27535fbdfe68 Mon Sep 17 00:00:00 2001
From: Marc Zinnschlag <marc@zpages.de>
Date: Sun, 22 Aug 2010 15:16:11 +0200
Subject: [PATCH 11/32] fixed AiTravel and changed GetAiPackageDone to return 0
 (returning one would interfere with character creation testing at this point)

---
 apps/openmw/mwscript/aiextensions.cpp | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/apps/openmw/mwscript/aiextensions.cpp b/apps/openmw/mwscript/aiextensions.cpp
index e1fdc1976f..cd36eac9e1 100644
--- a/apps/openmw/mwscript/aiextensions.cpp
+++ b/apps/openmw/mwscript/aiextensions.cpp
@@ -10,6 +10,7 @@
 #include "interpretercontext.hpp"
 
 #include <iostream>
+
 namespace MWScript
 {
     namespace Ai
@@ -156,7 +157,7 @@ namespace MWScript
 
                     MWWorld::Ptr ptr = context.getReference();
 
-                    Interpreter::Type_Integer value = 1;
+                    Interpreter::Type_Integer value = 0;
 
                     runtime.push (value);
                 }
@@ -176,7 +177,7 @@ namespace MWScript
 
                     MWWorld::Ptr ptr = context.getWorld().getPtr (id, false);
 
-                    Interpreter::Type_Integer value = 1;
+                    Interpreter::Type_Integer value = 0;
 
                     runtime.push (value);
                 }
@@ -192,7 +193,7 @@ namespace MWScript
 
         void registerExtensions (Compiler::Extensions& extensions)
         {
-            extensions.registerInstruction ("aitravel", "cllll/l", opcodeAiTravel,
+            extensions.registerInstruction ("aitravel", "lll/l", opcodeAiTravel,
                 opcodeAiTravelExplicit);
             extensions.registerInstruction ("aiescort", "cllll/l", opcodeAiEscort,
                 opcodeAiEscortExplicit);

From cb6996a90e6229f145d016df5892a53e1e89aaeb Mon Sep 17 00:00:00 2001
From: Marc Zinnschlag <marc@zpages.de>
Date: Mon, 23 Aug 2010 18:25:50 +0200
Subject: [PATCH 12/32] doxygen setup fix

---
 .gitignore    |    1 +
 Docs/Doxyfile | 1318 ++++++++++++++++++++++++-------------------------
 2 files changed, 660 insertions(+), 659 deletions(-)

diff --git a/.gitignore b/.gitignore
index dee53c5377..b8383fd517 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,3 @@
 build
 *~
+Doxygen
diff --git a/Docs/Doxyfile b/Docs/Doxyfile
index 5adeea8712..0c1b7bc21d 100644
--- a/Docs/Doxyfile
+++ b/Docs/Doxyfile
@@ -14,76 +14,76 @@
 # Project related configuration options
 #---------------------------------------------------------------------------
 
-# This tag specifies the encoding used for all characters in the config file 
-# that follow. The default is UTF-8 which is also the encoding used for all 
-# text before the first occurrence of this tag. Doxygen uses libiconv (or the 
-# iconv built into libc) for the transcoding. See 
+# This tag specifies the encoding used for all characters in the config file
+# that follow. The default is UTF-8 which is also the encoding used for all
+# text before the first occurrence of this tag. Doxygen uses libiconv (or the
+# iconv built into libc) for the transcoding. See
 # http://www.gnu.org/software/libiconv for the list of possible encodings.
 
 DOXYFILE_ENCODING      = UTF-8
 
-# The PROJECT_NAME tag is a single word (or a sequence of words surrounded 
+# The PROJECT_NAME tag is a single word (or a sequence of words surrounded
 # by quotes) that should identify the project.
 
 PROJECT_NAME           = OpenMW
 
-# The PROJECT_NUMBER tag can be used to enter a project or revision number. 
-# This could be handy for archiving the generated documentation or 
+# The PROJECT_NUMBER tag can be used to enter a project or revision number.
+# This could be handy for archiving the generated documentation or
 # if some version control system is used.
 
-PROJECT_NUMBER         = 
+PROJECT_NUMBER         =
 
-# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) 
-# base path where the generated documentation will be put. 
-# If a relative path is entered, it will be relative to the location 
+# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute)
+# base path where the generated documentation will be put.
+# If a relative path is entered, it will be relative to the location
 # where doxygen was started. If left blank the current directory will be used.
 
 OUTPUT_DIRECTORY       = ../Doxygen
 
-# If the CREATE_SUBDIRS tag is set to YES, then doxygen will create 
-# 4096 sub-directories (in 2 levels) under the output directory of each output 
-# format and will distribute the generated files over these directories. 
-# Enabling this option can be useful when feeding doxygen a huge amount of 
-# source files, where putting all generated files in the same directory would 
+# If the CREATE_SUBDIRS tag is set to YES, then doxygen will create
+# 4096 sub-directories (in 2 levels) under the output directory of each output
+# format and will distribute the generated files over these directories.
+# Enabling this option can be useful when feeding doxygen a huge amount of
+# source files, where putting all generated files in the same directory would
 # otherwise cause performance problems for the file system.
 
 CREATE_SUBDIRS         = NO
 
-# The OUTPUT_LANGUAGE tag is used to specify the language in which all 
-# documentation generated by doxygen is written. Doxygen will use this 
-# information to generate all constant output in the proper language. 
-# The default language is English, other supported languages are: 
-# Afrikaans, Arabic, Brazilian, Catalan, Chinese, Chinese-Traditional, 
-# Croatian, Czech, Danish, Dutch, Farsi, Finnish, French, German, Greek, 
-# Hungarian, Italian, Japanese, Japanese-en (Japanese with English messages), 
-# Korean, Korean-en, Lithuanian, Norwegian, Macedonian, Persian, Polish, 
-# Portuguese, Romanian, Russian, Serbian, Serbian-Cyrilic, Slovak, Slovene, 
+# The OUTPUT_LANGUAGE tag is used to specify the language in which all
+# documentation generated by doxygen is written. Doxygen will use this
+# information to generate all constant output in the proper language.
+# The default language is English, other supported languages are:
+# Afrikaans, Arabic, Brazilian, Catalan, Chinese, Chinese-Traditional,
+# Croatian, Czech, Danish, Dutch, Farsi, Finnish, French, German, Greek,
+# Hungarian, Italian, Japanese, Japanese-en (Japanese with English messages),
+# Korean, Korean-en, Lithuanian, Norwegian, Macedonian, Persian, Polish,
+# Portuguese, Romanian, Russian, Serbian, Serbian-Cyrilic, Slovak, Slovene,
 # Spanish, Swedish, and Ukrainian.
 
 OUTPUT_LANGUAGE        = English
 
-# If the BRIEF_MEMBER_DESC tag is set to YES (the default) Doxygen will 
-# include brief member descriptions after the members that are listed in 
-# the file and class documentation (similar to JavaDoc). 
+# If the BRIEF_MEMBER_DESC tag is set to YES (the default) Doxygen will
+# include brief member descriptions after the members that are listed in
+# the file and class documentation (similar to JavaDoc).
 # Set to NO to disable this.
 
 BRIEF_MEMBER_DESC      = YES
 
-# If the REPEAT_BRIEF tag is set to YES (the default) Doxygen will prepend 
-# the brief description of a member or function before the detailed description. 
-# Note: if both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the 
+# If the REPEAT_BRIEF tag is set to YES (the default) Doxygen will prepend
+# the brief description of a member or function before the detailed description.
+# Note: if both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the
 # brief descriptions will be completely suppressed.
 
 REPEAT_BRIEF           = YES
 
-# This tag implements a quasi-intelligent brief description abbreviator 
-# that is used to form the text in various listings. Each string 
-# in this list, if found as the leading text of the brief description, will be 
-# stripped from the text and the result after processing the whole list, is 
-# used as the annotated text. Otherwise, the brief description is used as-is. 
-# If left blank, the following values are used ("$name" is automatically 
-# replaced with the name of the entity): "The $name class" "The $name widget" 
-# "The $name file" "is" "provides" "specifies" "contains" 
+# This tag implements a quasi-intelligent brief description abbreviator
+# that is used to form the text in various listings. Each string
+# in this list, if found as the leading text of the brief description, will be
+# stripped from the text and the result after processing the whole list, is
+# used as the annotated text. Otherwise, the brief description is used as-is.
+# If left blank, the following values are used ("$name" is automatically
+# replaced with the name of the entity): "The $name class" "The $name widget"
+# "The $name file" "is" "provides" "specifies" "contains"
 # "represents" "a" "an" "the"
 
 ABBREVIATE_BRIEF       = "The $name class" \
@@ -98,202 +98,202 @@ ABBREVIATE_BRIEF       = "The $name class" \
                          an \
                          the
 
-# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then 
-# Doxygen will generate a detailed section even if there is only a brief 
+# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then
+# Doxygen will generate a detailed section even if there is only a brief
 # description.
 
 ALWAYS_DETAILED_SEC    = NO
 
-# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all 
-# inherited members of a class in the documentation of that class as if those 
-# members were ordinary class members. Constructors, destructors and assignment 
+# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all
+# inherited members of a class in the documentation of that class as if those
+# members were ordinary class members. Constructors, destructors and assignment
 # operators of the base classes will not be shown.
 
 INLINE_INHERITED_MEMB  = NO
 
-# If the FULL_PATH_NAMES tag is set to YES then Doxygen will prepend the full 
-# path before files name in the file list and in the header files. If set 
+# If the FULL_PATH_NAMES tag is set to YES then Doxygen will prepend the full
+# path before files name in the file list and in the header files. If set
 # to NO the shortest path that makes the file name unique will be used.
 
 FULL_PATH_NAMES        = YES
 
-# If the FULL_PATH_NAMES tag is set to YES then the STRIP_FROM_PATH tag 
-# can be used to strip a user-defined part of the path. Stripping is 
-# only done if one of the specified strings matches the left-hand part of 
-# the path. The tag can be used to show relative paths in the file list. 
-# If left blank the directory from which doxygen is run is used as the 
+# If the FULL_PATH_NAMES tag is set to YES then the STRIP_FROM_PATH tag
+# can be used to strip a user-defined part of the path. Stripping is
+# only done if one of the specified strings matches the left-hand part of
+# the path. The tag can be used to show relative paths in the file list.
+# If left blank the directory from which doxygen is run is used as the
 # path to strip.
 
-STRIP_FROM_PATH        = 
+STRIP_FROM_PATH        =
 
-# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of 
-# the path mentioned in the documentation of a class, which tells 
-# the reader which header file to include in order to use a class. 
-# If left blank only the name of the header file containing the class 
-# definition is used. Otherwise one should specify the include paths that 
+# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of
+# the path mentioned in the documentation of a class, which tells
+# the reader which header file to include in order to use a class.
+# If left blank only the name of the header file containing the class
+# definition is used. Otherwise one should specify the include paths that
 # are normally passed to the compiler using the -I flag.
 
-STRIP_FROM_INC_PATH    = 
+STRIP_FROM_INC_PATH    =
 
-# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter 
-# (but less readable) file names. This can be useful is your file systems 
+# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter
+# (but less readable) file names. This can be useful is your file systems
 # doesn't support long names like on DOS, Mac, or CD-ROM.
 
 SHORT_NAMES            = NO
 
-# If the JAVADOC_AUTOBRIEF tag is set to YES then Doxygen 
-# will interpret the first line (until the first dot) of a JavaDoc-style 
-# comment as the brief description. If set to NO, the JavaDoc 
-# comments will behave just like regular Qt-style comments 
+# If the JAVADOC_AUTOBRIEF tag is set to YES then Doxygen
+# will interpret the first line (until the first dot) of a JavaDoc-style
+# comment as the brief description. If set to NO, the JavaDoc
+# comments will behave just like regular Qt-style comments
 # (thus requiring an explicit @brief command for a brief description.)
 
 JAVADOC_AUTOBRIEF      = NO
 
-# If the QT_AUTOBRIEF tag is set to YES then Doxygen will 
-# interpret the first line (until the first dot) of a Qt-style 
-# comment as the brief description. If set to NO, the comments 
-# will behave just like regular Qt-style comments (thus requiring 
+# If the QT_AUTOBRIEF tag is set to YES then Doxygen will
+# interpret the first line (until the first dot) of a Qt-style
+# comment as the brief description. If set to NO, the comments
+# will behave just like regular Qt-style comments (thus requiring
 # an explicit \brief command for a brief description.)
 
 QT_AUTOBRIEF           = NO
 
-# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make Doxygen 
-# treat a multi-line C++ special comment block (i.e. a block of //! or /// 
-# comments) as a brief description. This used to be the default behaviour. 
-# The new default is to treat a multi-line C++ comment block as a detailed 
+# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make Doxygen
+# treat a multi-line C++ special comment block (i.e. a block of //! or ///
+# comments) as a brief description. This used to be the default behaviour.
+# The new default is to treat a multi-line C++ comment block as a detailed
 # description. Set this tag to YES if you prefer the old behaviour instead.
 
 MULTILINE_CPP_IS_BRIEF = NO
 
-# If the INHERIT_DOCS tag is set to YES (the default) then an undocumented 
-# member inherits the documentation from any documented member that it 
+# If the INHERIT_DOCS tag is set to YES (the default) then an undocumented
+# member inherits the documentation from any documented member that it
 # re-implements.
 
 INHERIT_DOCS           = YES
 
-# If the SEPARATE_MEMBER_PAGES tag is set to YES, then doxygen will produce 
-# a new page for each member. If set to NO, the documentation of a member will 
+# If the SEPARATE_MEMBER_PAGES tag is set to YES, then doxygen will produce
+# a new page for each member. If set to NO, the documentation of a member will
 # be part of the file/class/namespace that contains it.
 
 SEPARATE_MEMBER_PAGES  = NO
 
-# The TAB_SIZE tag can be used to set the number of spaces in a tab. 
+# The TAB_SIZE tag can be used to set the number of spaces in a tab.
 # Doxygen uses this value to replace tabs by spaces in code fragments.
 
 TAB_SIZE               = 8
 
-# This tag can be used to specify a number of aliases that acts 
-# as commands in the documentation. An alias has the form "name=value". 
-# For example adding "sideeffect=\par Side Effects:\n" will allow you to 
-# put the command \sideeffect (or @sideeffect) in the documentation, which 
-# will result in a user-defined paragraph with heading "Side Effects:". 
+# This tag can be used to specify a number of aliases that acts
+# as commands in the documentation. An alias has the form "name=value".
+# For example adding "sideeffect=\par Side Effects:\n" will allow you to
+# put the command \sideeffect (or @sideeffect) in the documentation, which
+# will result in a user-defined paragraph with heading "Side Effects:".
 # You can put \n's in the value part of an alias to insert newlines.
 
-ALIASES                = 
+ALIASES                =
 
-# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C 
-# sources only. Doxygen will then generate output that is more tailored for C. 
-# For instance, some of the names that are used will be different. The list 
+# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C
+# sources only. Doxygen will then generate output that is more tailored for C.
+# For instance, some of the names that are used will be different. The list
 # of all members will be omitted, etc.
 
 OPTIMIZE_OUTPUT_FOR_C  = NO
 
-# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java 
-# sources only. Doxygen will then generate output that is more tailored for 
-# Java. For instance, namespaces will be presented as packages, qualified 
+# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java
+# sources only. Doxygen will then generate output that is more tailored for
+# Java. For instance, namespaces will be presented as packages, qualified
 # scopes will look different, etc.
 
 OPTIMIZE_OUTPUT_JAVA   = NO
 
-# Set the OPTIMIZE_FOR_FORTRAN tag to YES if your project consists of Fortran 
-# sources only. Doxygen will then generate output that is more tailored for 
+# Set the OPTIMIZE_FOR_FORTRAN tag to YES if your project consists of Fortran
+# sources only. Doxygen will then generate output that is more tailored for
 # Fortran.
 
 OPTIMIZE_FOR_FORTRAN   = NO
 
-# Set the OPTIMIZE_OUTPUT_VHDL tag to YES if your project consists of VHDL 
-# sources. Doxygen will then generate output that is tailored for 
+# Set the OPTIMIZE_OUTPUT_VHDL tag to YES if your project consists of VHDL
+# sources. Doxygen will then generate output that is tailored for
 # VHDL.
 
 OPTIMIZE_OUTPUT_VHDL   = NO
 
-# Doxygen selects the parser to use depending on the extension of the files it parses. 
-# With this tag you can assign which parser to use for a given extension. 
-# Doxygen has a built-in mapping, but you can override or extend it using this tag. 
-# The format is ext=language, where ext is a file extension, and language is one of 
-# the parsers supported by doxygen: IDL, Java, Javascript, C#, C, C++, D, PHP, 
-# Objective-C, Python, Fortran, VHDL, C, C++. For instance to make doxygen treat 
-# .inc files as Fortran files (default is PHP), and .f files as C (default is Fortran), 
+# Doxygen selects the parser to use depending on the extension of the files it parses.
+# With this tag you can assign which parser to use for a given extension.
+# Doxygen has a built-in mapping, but you can override or extend it using this tag.
+# The format is ext=language, where ext is a file extension, and language is one of
+# the parsers supported by doxygen: IDL, Java, Javascript, C#, C, C++, D, PHP,
+# Objective-C, Python, Fortran, VHDL, C, C++. For instance to make doxygen treat
+# .inc files as Fortran files (default is PHP), and .f files as C (default is Fortran),
 # use: inc=Fortran f=C
 
-EXTENSION_MAPPING      = 
+EXTENSION_MAPPING      =
 
-# If you use STL classes (i.e. std::string, std::vector, etc.) but do not want 
-# to include (a tag file for) the STL sources as input, then you should 
-# set this tag to YES in order to let doxygen match functions declarations and 
-# definitions whose arguments contain STL classes (e.g. func(std::string); v.s. 
-# func(std::string) {}). This also make the inheritance and collaboration 
+# If you use STL classes (i.e. std::string, std::vector, etc.) but do not want
+# to include (a tag file for) the STL sources as input, then you should
+# set this tag to YES in order to let doxygen match functions declarations and
+# definitions whose arguments contain STL classes (e.g. func(std::string); v.s.
+# func(std::string) {}). This also make the inheritance and collaboration
 # diagrams that involve STL classes more complete and accurate.
 
 BUILTIN_STL_SUPPORT    = NO
 
-# If you use Microsoft's C++/CLI language, you should set this option to YES to 
+# If you use Microsoft's C++/CLI language, you should set this option to YES to
 # enable parsing support.
 
 CPP_CLI_SUPPORT        = NO
 
-# Set the SIP_SUPPORT tag to YES if your project consists of sip sources only. 
-# Doxygen will parse them like normal C++ but will assume all classes use public 
+# Set the SIP_SUPPORT tag to YES if your project consists of sip sources only.
+# Doxygen will parse them like normal C++ but will assume all classes use public
 # instead of private inheritance when no explicit protection keyword is present.
 
 SIP_SUPPORT            = NO
 
-# For Microsoft's IDL there are propget and propput attributes to indicate getter 
-# and setter methods for a property. Setting this option to YES (the default) 
-# will make doxygen to replace the get and set methods by a property in the 
-# documentation. This will only work if the methods are indeed getting or 
-# setting a simple type. If this is not the case, or you want to show the 
+# For Microsoft's IDL there are propget and propput attributes to indicate getter
+# and setter methods for a property. Setting this option to YES (the default)
+# will make doxygen to replace the get and set methods by a property in the
+# documentation. This will only work if the methods are indeed getting or
+# setting a simple type. If this is not the case, or you want to show the
 # methods anyway, you should set this option to NO.
 
 IDL_PROPERTY_SUPPORT   = YES
 
-# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC 
-# tag is set to YES, then doxygen will reuse the documentation of the first 
-# member in the group (if any) for the other members of the group. By default 
+# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC
+# tag is set to YES, then doxygen will reuse the documentation of the first
+# member in the group (if any) for the other members of the group. By default
 # all members of a group must be documented explicitly.
 
 DISTRIBUTE_GROUP_DOC   = NO
 
-# Set the SUBGROUPING tag to YES (the default) to allow class member groups of 
-# the same type (for instance a group of public functions) to be put as a 
-# subgroup of that type (e.g. under the Public Functions section). Set it to 
-# NO to prevent subgrouping. Alternatively, this can be done per class using 
+# Set the SUBGROUPING tag to YES (the default) to allow class member groups of
+# the same type (for instance a group of public functions) to be put as a
+# subgroup of that type (e.g. under the Public Functions section). Set it to
+# NO to prevent subgrouping. Alternatively, this can be done per class using
 # the \nosubgrouping command.
 
 SUBGROUPING            = YES
 
-# When TYPEDEF_HIDES_STRUCT is enabled, a typedef of a struct, union, or enum 
-# is documented as struct, union, or enum with the name of the typedef. So 
-# typedef struct TypeS {} TypeT, will appear in the documentation as a struct 
-# with name TypeT. When disabled the typedef will appear as a member of a file, 
-# namespace, or class. And the struct will be named TypeS. This can typically 
-# be useful for C code in case the coding convention dictates that all compound 
+# When TYPEDEF_HIDES_STRUCT is enabled, a typedef of a struct, union, or enum
+# is documented as struct, union, or enum with the name of the typedef. So
+# typedef struct TypeS {} TypeT, will appear in the documentation as a struct
+# with name TypeT. When disabled the typedef will appear as a member of a file,
+# namespace, or class. And the struct will be named TypeS. This can typically
+# be useful for C code in case the coding convention dictates that all compound
 # types are typedef'ed and only the typedef is referenced, never the tag name.
 
 TYPEDEF_HIDES_STRUCT   = NO
 
-# The SYMBOL_CACHE_SIZE determines the size of the internal cache use to 
-# determine which symbols to keep in memory and which to flush to disk. 
-# When the cache is full, less often used symbols will be written to disk. 
-# For small to medium size projects (<1000 input files) the default value is 
-# probably good enough. For larger projects a too small cache size can cause 
-# doxygen to be busy swapping symbols to and from disk most of the time 
-# causing a significant performance penality. 
-# If the system has enough physical memory increasing the cache will improve the 
-# performance by keeping more symbols in memory. Note that the value works on 
-# a logarithmic scale so increasing the size by one will rougly double the 
-# memory usage. The cache size is given by this formula: 
-# 2^(16+SYMBOL_CACHE_SIZE). The valid range is 0..9, the default is 0, 
+# The SYMBOL_CACHE_SIZE determines the size of the internal cache use to
+# determine which symbols to keep in memory and which to flush to disk.
+# When the cache is full, less often used symbols will be written to disk.
+# For small to medium size projects (<1000 input files) the default value is
+# probably good enough. For larger projects a too small cache size can cause
+# doxygen to be busy swapping symbols to and from disk most of the time
+# causing a significant performance penality.
+# If the system has enough physical memory increasing the cache will improve the
+# performance by keeping more symbols in memory. Note that the value works on
+# a logarithmic scale so increasing the size by one will rougly double the
+# memory usage. The cache size is given by this formula:
+# 2^(16+SYMBOL_CACHE_SIZE). The valid range is 0..9, the default is 0,
 # corresponding to a cache size of 2^16 = 65536 symbols
 
 SYMBOL_CACHE_SIZE      = 0
@@ -302,295 +302,295 @@ SYMBOL_CACHE_SIZE      = 0
 # Build related configuration options
 #---------------------------------------------------------------------------
 
-# If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in 
-# documentation are documented, even if no documentation was available. 
-# Private class members and static file members will be hidden unless 
+# If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in
+# documentation are documented, even if no documentation was available.
+# Private class members and static file members will be hidden unless
 # the EXTRACT_PRIVATE and EXTRACT_STATIC tags are set to YES
 
 EXTRACT_ALL            = YES
 
-# If the EXTRACT_PRIVATE tag is set to YES all private members of a class 
+# If the EXTRACT_PRIVATE tag is set to YES all private members of a class
 # will be included in the documentation.
 
 EXTRACT_PRIVATE        = YES
 
-# If the EXTRACT_STATIC tag is set to YES all static members of a file 
+# If the EXTRACT_STATIC tag is set to YES all static members of a file
 # will be included in the documentation.
 
 EXTRACT_STATIC         = YES
 
-# If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs) 
-# defined locally in source files will be included in the documentation. 
+# If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs)
+# defined locally in source files will be included in the documentation.
 # If set to NO only classes defined in header files are included.
 
 EXTRACT_LOCAL_CLASSES  = YES
 
-# This flag is only useful for Objective-C code. When set to YES local 
-# methods, which are defined in the implementation section but not in 
-# the interface are included in the documentation. 
+# This flag is only useful for Objective-C code. When set to YES local
+# methods, which are defined in the implementation section but not in
+# the interface are included in the documentation.
 # If set to NO (the default) only methods in the interface are included.
 
 EXTRACT_LOCAL_METHODS  = YES
 
-# If this flag is set to YES, the members of anonymous namespaces will be 
-# extracted and appear in the documentation as a namespace called 
-# 'anonymous_namespace{file}', where file will be replaced with the base 
-# name of the file that contains the anonymous namespace. By default 
+# If this flag is set to YES, the members of anonymous namespaces will be
+# extracted and appear in the documentation as a namespace called
+# 'anonymous_namespace{file}', where file will be replaced with the base
+# name of the file that contains the anonymous namespace. By default
 # anonymous namespace are hidden.
 
 EXTRACT_ANON_NSPACES   = YES
 
-# If the HIDE_UNDOC_MEMBERS tag is set to YES, Doxygen will hide all 
-# undocumented members of documented classes, files or namespaces. 
-# If set to NO (the default) these members will be included in the 
-# various overviews, but no documentation section is generated. 
+# If the HIDE_UNDOC_MEMBERS tag is set to YES, Doxygen will hide all
+# undocumented members of documented classes, files or namespaces.
+# If set to NO (the default) these members will be included in the
+# various overviews, but no documentation section is generated.
 # This option has no effect if EXTRACT_ALL is enabled.
 
 HIDE_UNDOC_MEMBERS     = NO
 
-# If the HIDE_UNDOC_CLASSES tag is set to YES, Doxygen will hide all 
-# undocumented classes that are normally visible in the class hierarchy. 
-# If set to NO (the default) these classes will be included in the various 
+# If the HIDE_UNDOC_CLASSES tag is set to YES, Doxygen will hide all
+# undocumented classes that are normally visible in the class hierarchy.
+# If set to NO (the default) these classes will be included in the various
 # overviews. This option has no effect if EXTRACT_ALL is enabled.
 
 HIDE_UNDOC_CLASSES     = NO
 
-# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, Doxygen will hide all 
-# friend (class|struct|union) declarations. 
-# If set to NO (the default) these declarations will be included in the 
+# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, Doxygen will hide all
+# friend (class|struct|union) declarations.
+# If set to NO (the default) these declarations will be included in the
 # documentation.
 
 HIDE_FRIEND_COMPOUNDS  = NO
 
-# If the HIDE_IN_BODY_DOCS tag is set to YES, Doxygen will hide any 
-# documentation blocks found inside the body of a function. 
-# If set to NO (the default) these blocks will be appended to the 
+# If the HIDE_IN_BODY_DOCS tag is set to YES, Doxygen will hide any
+# documentation blocks found inside the body of a function.
+# If set to NO (the default) these blocks will be appended to the
 # function's detailed documentation block.
 
 HIDE_IN_BODY_DOCS      = NO
 
-# The INTERNAL_DOCS tag determines if documentation 
-# that is typed after a \internal command is included. If the tag is set 
-# to NO (the default) then the documentation will be excluded. 
+# The INTERNAL_DOCS tag determines if documentation
+# that is typed after a \internal command is included. If the tag is set
+# to NO (the default) then the documentation will be excluded.
 # Set it to YES to include the internal documentation.
 
 INTERNAL_DOCS          = NO
 
-# If the CASE_SENSE_NAMES tag is set to NO then Doxygen will only generate 
-# file names in lower-case letters. If set to YES upper-case letters are also 
-# allowed. This is useful if you have classes or files whose names only differ 
-# in case and if your file system supports case sensitive file names. Windows 
+# If the CASE_SENSE_NAMES tag is set to NO then Doxygen will only generate
+# file names in lower-case letters. If set to YES upper-case letters are also
+# allowed. This is useful if you have classes or files whose names only differ
+# in case and if your file system supports case sensitive file names. Windows
 # and Mac users are advised to set this option to NO.
 
 CASE_SENSE_NAMES       = YES
 
-# If the HIDE_SCOPE_NAMES tag is set to NO (the default) then Doxygen 
-# will show members with their full class and namespace scopes in the 
+# If the HIDE_SCOPE_NAMES tag is set to NO (the default) then Doxygen
+# will show members with their full class and namespace scopes in the
 # documentation. If set to YES the scope will be hidden.
 
 HIDE_SCOPE_NAMES       = NO
 
-# If the SHOW_INCLUDE_FILES tag is set to YES (the default) then Doxygen 
-# will put a list of the files that are included by a file in the documentation 
+# If the SHOW_INCLUDE_FILES tag is set to YES (the default) then Doxygen
+# will put a list of the files that are included by a file in the documentation
 # of that file.
 
 SHOW_INCLUDE_FILES     = YES
 
-# If the INLINE_INFO tag is set to YES (the default) then a tag [inline] 
+# If the INLINE_INFO tag is set to YES (the default) then a tag [inline]
 # is inserted in the documentation for inline members.
 
 INLINE_INFO            = YES
 
-# If the SORT_MEMBER_DOCS tag is set to YES (the default) then doxygen 
-# will sort the (detailed) documentation of file and class members 
-# alphabetically by member name. If set to NO the members will appear in 
+# If the SORT_MEMBER_DOCS tag is set to YES (the default) then doxygen
+# will sort the (detailed) documentation of file and class members
+# alphabetically by member name. If set to NO the members will appear in
 # declaration order.
 
 SORT_MEMBER_DOCS       = YES
 
-# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the 
-# brief documentation of file, namespace and class members alphabetically 
-# by member name. If set to NO (the default) the members will appear in 
+# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the
+# brief documentation of file, namespace and class members alphabetically
+# by member name. If set to NO (the default) the members will appear in
 # declaration order.
 
 SORT_BRIEF_DOCS        = NO
 
-# If the SORT_GROUP_NAMES tag is set to YES then doxygen will sort the 
-# hierarchy of group names into alphabetical order. If set to NO (the default) 
+# If the SORT_GROUP_NAMES tag is set to YES then doxygen will sort the
+# hierarchy of group names into alphabetical order. If set to NO (the default)
 # the group names will appear in their defined order.
 
 SORT_GROUP_NAMES       = NO
 
-# If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be 
-# sorted by fully-qualified names, including namespaces. If set to 
-# NO (the default), the class list will be sorted only by class name, 
-# not including the namespace part. 
-# Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES. 
-# Note: This option applies only to the class list, not to the 
+# If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be
+# sorted by fully-qualified names, including namespaces. If set to
+# NO (the default), the class list will be sorted only by class name,
+# not including the namespace part.
+# Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES.
+# Note: This option applies only to the class list, not to the
 # alphabetical list.
 
 SORT_BY_SCOPE_NAME     = NO
 
-# The GENERATE_TODOLIST tag can be used to enable (YES) or 
-# disable (NO) the todo list. This list is created by putting \todo 
+# The GENERATE_TODOLIST tag can be used to enable (YES) or
+# disable (NO) the todo list. This list is created by putting \todo
 # commands in the documentation.
 
 GENERATE_TODOLIST      = YES
 
-# The GENERATE_TESTLIST tag can be used to enable (YES) or 
-# disable (NO) the test list. This list is created by putting \test 
+# The GENERATE_TESTLIST tag can be used to enable (YES) or
+# disable (NO) the test list. This list is created by putting \test
 # commands in the documentation.
 
 GENERATE_TESTLIST      = YES
 
-# The GENERATE_BUGLIST tag can be used to enable (YES) or 
-# disable (NO) the bug list. This list is created by putting \bug 
+# The GENERATE_BUGLIST tag can be used to enable (YES) or
+# disable (NO) the bug list. This list is created by putting \bug
 # commands in the documentation.
 
 GENERATE_BUGLIST       = YES
 
-# The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or 
-# disable (NO) the deprecated list. This list is created by putting 
+# The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or
+# disable (NO) the deprecated list. This list is created by putting
 # \deprecated commands in the documentation.
 
 GENERATE_DEPRECATEDLIST= YES
 
-# The ENABLED_SECTIONS tag can be used to enable conditional 
+# The ENABLED_SECTIONS tag can be used to enable conditional
 # documentation sections, marked by \if sectionname ... \endif.
 
-ENABLED_SECTIONS       = 
+ENABLED_SECTIONS       =
 
-# The MAX_INITIALIZER_LINES tag determines the maximum number of lines 
-# the initial value of a variable or define consists of for it to appear in 
-# the documentation. If the initializer consists of more lines than specified 
-# here it will be hidden. Use a value of 0 to hide initializers completely. 
-# The appearance of the initializer of individual variables and defines in the 
-# documentation can be controlled using \showinitializer or \hideinitializer 
+# The MAX_INITIALIZER_LINES tag determines the maximum number of lines
+# the initial value of a variable or define consists of for it to appear in
+# the documentation. If the initializer consists of more lines than specified
+# here it will be hidden. Use a value of 0 to hide initializers completely.
+# The appearance of the initializer of individual variables and defines in the
+# documentation can be controlled using \showinitializer or \hideinitializer
 # command in the documentation regardless of this setting.
 
 MAX_INITIALIZER_LINES  = 30
 
-# Set the SHOW_USED_FILES tag to NO to disable the list of files generated 
-# at the bottom of the documentation of classes and structs. If set to YES the 
+# Set the SHOW_USED_FILES tag to NO to disable the list of files generated
+# at the bottom of the documentation of classes and structs. If set to YES the
 # list will mention the files that were used to generate the documentation.
 
 SHOW_USED_FILES        = YES
 
-# If the sources in your project are distributed over multiple directories 
-# then setting the SHOW_DIRECTORIES tag to YES will show the directory hierarchy 
+# If the sources in your project are distributed over multiple directories
+# then setting the SHOW_DIRECTORIES tag to YES will show the directory hierarchy
 # in the documentation. The default is NO.
 
 SHOW_DIRECTORIES       = NO
 
-# Set the SHOW_FILES tag to NO to disable the generation of the Files page. 
-# This will remove the Files entry from the Quick Index and from the 
+# Set the SHOW_FILES tag to NO to disable the generation of the Files page.
+# This will remove the Files entry from the Quick Index and from the
 # Folder Tree View (if specified). The default is YES.
 
 SHOW_FILES             = YES
 
-# Set the SHOW_NAMESPACES tag to NO to disable the generation of the 
-# Namespaces page.  This will remove the Namespaces entry from the Quick Index 
+# Set the SHOW_NAMESPACES tag to NO to disable the generation of the
+# Namespaces page.  This will remove the Namespaces entry from the Quick Index
 # and from the Folder Tree View (if specified). The default is YES.
 
 SHOW_NAMESPACES        = YES
 
-# The FILE_VERSION_FILTER tag can be used to specify a program or script that 
-# doxygen should invoke to get the current version for each file (typically from 
-# the version control system). Doxygen will invoke the program by executing (via 
-# popen()) the command <command> <input-file>, where <command> is the value of 
-# the FILE_VERSION_FILTER tag, and <input-file> is the name of an input file 
-# provided by doxygen. Whatever the program writes to standard output 
+# The FILE_VERSION_FILTER tag can be used to specify a program or script that
+# doxygen should invoke to get the current version for each file (typically from
+# the version control system). Doxygen will invoke the program by executing (via
+# popen()) the command <command> <input-file>, where <command> is the value of
+# the FILE_VERSION_FILTER tag, and <input-file> is the name of an input file
+# provided by doxygen. Whatever the program writes to standard output
 # is used as the file version. See the manual for examples.
 
-FILE_VERSION_FILTER    = 
+FILE_VERSION_FILTER    =
 
-# The LAYOUT_FILE tag can be used to specify a layout file which will be parsed by 
-# doxygen. The layout file controls the global structure of the generated output files 
-# in an output format independent way. The create the layout file that represents 
-# doxygen's defaults, run doxygen with the -l option. You can optionally specify a 
-# file name after the option, if omitted DoxygenLayout.xml will be used as the name 
+# The LAYOUT_FILE tag can be used to specify a layout file which will be parsed by
+# doxygen. The layout file controls the global structure of the generated output files
+# in an output format independent way. The create the layout file that represents
+# doxygen's defaults, run doxygen with the -l option. You can optionally specify a
+# file name after the option, if omitted DoxygenLayout.xml will be used as the name
 # of the layout file.
 
-LAYOUT_FILE            = 
+LAYOUT_FILE            =
 
 #---------------------------------------------------------------------------
 # configuration options related to warning and progress messages
 #---------------------------------------------------------------------------
 
-# The QUIET tag can be used to turn on/off the messages that are generated 
+# The QUIET tag can be used to turn on/off the messages that are generated
 # by doxygen. Possible values are YES and NO. If left blank NO is used.
 
 QUIET                  = NO
 
-# The WARNINGS tag can be used to turn on/off the warning messages that are 
-# generated by doxygen. Possible values are YES and NO. If left blank 
+# The WARNINGS tag can be used to turn on/off the warning messages that are
+# generated by doxygen. Possible values are YES and NO. If left blank
 # NO is used.
 
 WARNINGS               = YES
 
-# If WARN_IF_UNDOCUMENTED is set to YES, then doxygen will generate warnings 
-# for undocumented members. If EXTRACT_ALL is set to YES then this flag will 
+# If WARN_IF_UNDOCUMENTED is set to YES, then doxygen will generate warnings
+# for undocumented members. If EXTRACT_ALL is set to YES then this flag will
 # automatically be disabled.
 
 WARN_IF_UNDOCUMENTED   = NO
 
-# If WARN_IF_DOC_ERROR is set to YES, doxygen will generate warnings for 
-# potential errors in the documentation, such as not documenting some 
-# parameters in a documented function, or documenting parameters that 
+# If WARN_IF_DOC_ERROR is set to YES, doxygen will generate warnings for
+# potential errors in the documentation, such as not documenting some
+# parameters in a documented function, or documenting parameters that
 # don't exist or using markup commands wrongly.
 
 WARN_IF_DOC_ERROR      = YES
 
-# This WARN_NO_PARAMDOC option can be abled to get warnings for 
-# functions that are documented, but have no documentation for their parameters 
-# or return value. If set to NO (the default) doxygen will only warn about 
-# wrong or incomplete parameter documentation, but not about the absence of 
+# This WARN_NO_PARAMDOC option can be abled to get warnings for
+# functions that are documented, but have no documentation for their parameters
+# or return value. If set to NO (the default) doxygen will only warn about
+# wrong or incomplete parameter documentation, but not about the absence of
 # documentation.
 
 WARN_NO_PARAMDOC       = NO
 
-# The WARN_FORMAT tag determines the format of the warning messages that 
-# doxygen can produce. The string should contain the $file, $line, and $text 
-# tags, which will be replaced by the file and line number from which the 
-# warning originated and the warning text. Optionally the format may contain 
-# $version, which will be replaced by the version of the file (if it could 
+# The WARN_FORMAT tag determines the format of the warning messages that
+# doxygen can produce. The string should contain the $file, $line, and $text
+# tags, which will be replaced by the file and line number from which the
+# warning originated and the warning text. Optionally the format may contain
+# $version, which will be replaced by the version of the file (if it could
 # be obtained via FILE_VERSION_FILTER)
 
 WARN_FORMAT            = "$file:$line: $text"
 
-# The WARN_LOGFILE tag can be used to specify a file to which warning 
-# and error messages should be written. If left blank the output is written 
+# The WARN_LOGFILE tag can be used to specify a file to which warning
+# and error messages should be written. If left blank the output is written
 # to stderr.
 
-WARN_LOGFILE           = 
+WARN_LOGFILE           =
 
 #---------------------------------------------------------------------------
 # configuration options related to the input files
 #---------------------------------------------------------------------------
 
-# The INPUT tag can be used to specify the files and/or directories that contain 
-# documented source files. You may enter file names like "myfile.cpp" or 
-# directories like "/usr/src/myproject". Separate the files or directories 
+# The INPUT tag can be used to specify the files and/or directories that contain
+# documented source files. You may enter file names like "myfile.cpp" or
+# directories like "/usr/src/myproject". Separate the files or directories
 # with spaces.
 
-INPUT                  = ..\apps
-                         ..\components
-                         ..\libs
-                         ..\docs
+INPUT                  = ../apps
+                         ../components
+                         ../libs
+                         ../docs
 
-# This tag can be used to specify the character encoding of the source files 
-# that doxygen parses. Internally doxygen uses the UTF-8 encoding, which is 
-# also the default input encoding. Doxygen uses libiconv (or the iconv built 
-# into libc) for the transcoding. See http://www.gnu.org/software/libiconv for 
+# This tag can be used to specify the character encoding of the source files
+# that doxygen parses. Internally doxygen uses the UTF-8 encoding, which is
+# also the default input encoding. Doxygen uses libiconv (or the iconv built
+# into libc) for the transcoding. See http://www.gnu.org/software/libiconv for
 # the list of possible encodings.
 
 INPUT_ENCODING         = UTF-8
 
-# If the value of the INPUT tag contains directories, you can use the 
-# FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp 
-# and *.h) to filter out the source-files in the directories. If left 
-# blank the following patterns are tested: 
-# *.c *.cc *.cxx *.cpp *.c++ *.java *.ii *.ixx *.ipp *.i++ *.inl *.h *.hh *.hxx 
+# If the value of the INPUT tag contains directories, you can use the
+# FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp
+# and *.h) to filter out the source-files in the directories. If left
+# blank the following patterns are tested:
+# *.c *.cc *.cxx *.cpp *.c++ *.java *.ii *.ixx *.ipp *.i++ *.inl *.h *.hh *.hxx
 # *.hpp *.h++ *.idl *.odl *.cs *.php *.php3 *.inc *.m *.mm *.py *.f90
 
 FILE_PATTERNS          = *.c \
@@ -624,87 +624,87 @@ FILE_PATTERNS          = *.c \
                          *.vhd \
                          *.vhdl
 
-# The RECURSIVE tag can be used to turn specify whether or not subdirectories 
-# should be searched for input files as well. Possible values are YES and NO. 
+# The RECURSIVE tag can be used to turn specify whether or not subdirectories
+# should be searched for input files as well. Possible values are YES and NO.
 # If left blank NO is used.
 
 RECURSIVE              = YES
 
-# The EXCLUDE tag can be used to specify files and/or directories that should 
-# excluded from the INPUT source files. This way you can easily exclude a 
+# The EXCLUDE tag can be used to specify files and/or directories that should
+# excluded from the INPUT source files. This way you can easily exclude a
 # subdirectory from a directory tree whose root is specified with the INPUT tag.
 
-EXCLUDE                = 
+EXCLUDE                =
 
-# The EXCLUDE_SYMLINKS tag can be used select whether or not files or 
-# directories that are symbolic links (a Unix filesystem feature) are excluded 
+# The EXCLUDE_SYMLINKS tag can be used select whether or not files or
+# directories that are symbolic links (a Unix filesystem feature) are excluded
 # from the input.
 
 EXCLUDE_SYMLINKS       = NO
 
-# If the value of the INPUT tag contains directories, you can use the 
-# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude 
-# certain files from those directories. Note that the wildcards are matched 
-# against the file with absolute path, so to exclude all test directories 
+# If the value of the INPUT tag contains directories, you can use the
+# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude
+# certain files from those directories. Note that the wildcards are matched
+# against the file with absolute path, so to exclude all test directories
 # for example use the pattern */test/*
 
-EXCLUDE_PATTERNS       = 
+EXCLUDE_PATTERNS       =
 
-# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names 
-# (namespaces, classes, functions, etc.) that should be excluded from the 
-# output. The symbol name can be a fully qualified name, a word, or if the 
-# wildcard * is used, a substring. Examples: ANamespace, AClass, 
+# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names
+# (namespaces, classes, functions, etc.) that should be excluded from the
+# output. The symbol name can be a fully qualified name, a word, or if the
+# wildcard * is used, a substring. Examples: ANamespace, AClass,
 # AClass::ANamespace, ANamespace::*Test
 
-EXCLUDE_SYMBOLS        = 
+EXCLUDE_SYMBOLS        =
 
-# The EXAMPLE_PATH tag can be used to specify one or more files or 
-# directories that contain example code fragments that are included (see 
+# The EXAMPLE_PATH tag can be used to specify one or more files or
+# directories that contain example code fragments that are included (see
 # the \include command).
 
-EXAMPLE_PATH           = 
+EXAMPLE_PATH           =
 
-# If the value of the EXAMPLE_PATH tag contains directories, you can use the 
-# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp 
-# and *.h) to filter out the source-files in the directories. If left 
+# If the value of the EXAMPLE_PATH tag contains directories, you can use the
+# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp
+# and *.h) to filter out the source-files in the directories. If left
 # blank all files are included.
 
 EXAMPLE_PATTERNS       = *
 
-# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be 
-# searched for input files to be used with the \include or \dontinclude 
-# commands irrespective of the value of the RECURSIVE tag. 
+# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be
+# searched for input files to be used with the \include or \dontinclude
+# commands irrespective of the value of the RECURSIVE tag.
 # Possible values are YES and NO. If left blank NO is used.
 
 EXAMPLE_RECURSIVE      = NO
 
-# The IMAGE_PATH tag can be used to specify one or more files or 
-# directories that contain image that are included in the documentation (see 
+# The IMAGE_PATH tag can be used to specify one or more files or
+# directories that contain image that are included in the documentation (see
 # the \image command).
 
-IMAGE_PATH             = 
+IMAGE_PATH             =
 
-# The INPUT_FILTER tag can be used to specify a program that doxygen should 
-# invoke to filter for each input file. Doxygen will invoke the filter program 
-# by executing (via popen()) the command <filter> <input-file>, where <filter> 
-# is the value of the INPUT_FILTER tag, and <input-file> is the name of an 
-# input file. Doxygen will then use the output that the filter program writes 
-# to standard output.  If FILTER_PATTERNS is specified, this tag will be 
+# The INPUT_FILTER tag can be used to specify a program that doxygen should
+# invoke to filter for each input file. Doxygen will invoke the filter program
+# by executing (via popen()) the command <filter> <input-file>, where <filter>
+# is the value of the INPUT_FILTER tag, and <input-file> is the name of an
+# input file. Doxygen will then use the output that the filter program writes
+# to standard output.  If FILTER_PATTERNS is specified, this tag will be
 # ignored.
 
-INPUT_FILTER           = 
+INPUT_FILTER           =
 
-# The FILTER_PATTERNS tag can be used to specify filters on a per file pattern 
-# basis.  Doxygen will compare the file name with each pattern and apply the 
-# filter if there is a match.  The filters are a list of the form: 
-# pattern=filter (like *.cpp=my_cpp_filter). See INPUT_FILTER for further 
-# info on how filters are used. If FILTER_PATTERNS is empty, INPUT_FILTER 
+# The FILTER_PATTERNS tag can be used to specify filters on a per file pattern
+# basis.  Doxygen will compare the file name with each pattern and apply the
+# filter if there is a match.  The filters are a list of the form:
+# pattern=filter (like *.cpp=my_cpp_filter). See INPUT_FILTER for further
+# info on how filters are used. If FILTER_PATTERNS is empty, INPUT_FILTER
 # is applied to all files.
 
-FILTER_PATTERNS        = 
+FILTER_PATTERNS        =
 
-# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using 
-# INPUT_FILTER) will be used to filter the input files when producing source 
+# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using
+# INPUT_FILTER) will be used to filter the input files when producing source
 # files to browse (i.e. when SOURCE_BROWSER is set to YES).
 
 FILTER_SOURCE_FILES    = NO
@@ -713,53 +713,53 @@ FILTER_SOURCE_FILES    = NO
 # configuration options related to source browsing
 #---------------------------------------------------------------------------
 
-# If the SOURCE_BROWSER tag is set to YES then a list of source files will 
-# be generated. Documented entities will be cross-referenced with these sources. 
-# Note: To get rid of all source code in the generated output, make sure also 
+# If the SOURCE_BROWSER tag is set to YES then a list of source files will
+# be generated. Documented entities will be cross-referenced with these sources.
+# Note: To get rid of all source code in the generated output, make sure also
 # VERBATIM_HEADERS is set to NO.
 
 SOURCE_BROWSER         = NO
 
-# Setting the INLINE_SOURCES tag to YES will include the body 
+# Setting the INLINE_SOURCES tag to YES will include the body
 # of functions and classes directly in the documentation.
 
 INLINE_SOURCES         = NO
 
-# Setting the STRIP_CODE_COMMENTS tag to YES (the default) will instruct 
-# doxygen to hide any special comment blocks from generated source code 
+# Setting the STRIP_CODE_COMMENTS tag to YES (the default) will instruct
+# doxygen to hide any special comment blocks from generated source code
 # fragments. Normal C and C++ comments will always remain visible.
 
 STRIP_CODE_COMMENTS    = YES
 
-# If the REFERENCED_BY_RELATION tag is set to YES 
-# then for each documented function all documented 
+# If the REFERENCED_BY_RELATION tag is set to YES
+# then for each documented function all documented
 # functions referencing it will be listed.
 
 REFERENCED_BY_RELATION = NO
 
-# If the REFERENCES_RELATION tag is set to YES 
-# then for each documented function all documented entities 
+# If the REFERENCES_RELATION tag is set to YES
+# then for each documented function all documented entities
 # called/used by that function will be listed.
 
 REFERENCES_RELATION    = NO
 
-# If the REFERENCES_LINK_SOURCE tag is set to YES (the default) 
-# and SOURCE_BROWSER tag is set to YES, then the hyperlinks from 
-# functions in REFERENCES_RELATION and REFERENCED_BY_RELATION lists will 
+# If the REFERENCES_LINK_SOURCE tag is set to YES (the default)
+# and SOURCE_BROWSER tag is set to YES, then the hyperlinks from
+# functions in REFERENCES_RELATION and REFERENCED_BY_RELATION lists will
 # link to the source code.  Otherwise they will link to the documentation.
 
 REFERENCES_LINK_SOURCE = YES
 
-# If the USE_HTAGS tag is set to YES then the references to source code 
-# will point to the HTML generated by the htags(1) tool instead of doxygen 
-# built-in source browser. The htags tool is part of GNU's global source 
-# tagging system (see http://www.gnu.org/software/global/global.html). You 
+# If the USE_HTAGS tag is set to YES then the references to source code
+# will point to the HTML generated by the htags(1) tool instead of doxygen
+# built-in source browser. The htags tool is part of GNU's global source
+# tagging system (see http://www.gnu.org/software/global/global.html). You
 # will need version 4.8.6 or higher.
 
 USE_HTAGS              = NO
 
-# If the VERBATIM_HEADERS tag is set to YES (the default) then Doxygen 
-# will generate a verbatim copy of the header file for each class for 
+# If the VERBATIM_HEADERS tag is set to YES (the default) then Doxygen
+# will generate a verbatim copy of the header file for each class for
 # which an include is specified. Set to NO to disable this.
 
 VERBATIM_HEADERS       = YES
@@ -768,238 +768,238 @@ VERBATIM_HEADERS       = YES
 # configuration options related to the alphabetical class index
 #---------------------------------------------------------------------------
 
-# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index 
-# of all compounds will be generated. Enable this if the project 
+# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index
+# of all compounds will be generated. Enable this if the project
 # contains a lot of classes, structs, unions or interfaces.
 
 ALPHABETICAL_INDEX     = NO
 
-# If the alphabetical index is enabled (see ALPHABETICAL_INDEX) then 
-# the COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns 
+# If the alphabetical index is enabled (see ALPHABETICAL_INDEX) then
+# the COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns
 # in which this list will be split (can be a number in the range [1..20])
 
 COLS_IN_ALPHA_INDEX    = 5
 
-# In case all classes in a project start with a common prefix, all 
-# classes will be put under the same header in the alphabetical index. 
-# The IGNORE_PREFIX tag can be used to specify one or more prefixes that 
+# In case all classes in a project start with a common prefix, all
+# classes will be put under the same header in the alphabetical index.
+# The IGNORE_PREFIX tag can be used to specify one or more prefixes that
 # should be ignored while generating the index headers.
 
-IGNORE_PREFIX          = 
+IGNORE_PREFIX          =
 
 #---------------------------------------------------------------------------
 # configuration options related to the HTML output
 #---------------------------------------------------------------------------
 
-# If the GENERATE_HTML tag is set to YES (the default) Doxygen will 
+# If the GENERATE_HTML tag is set to YES (the default) Doxygen will
 # generate HTML output.
 
 GENERATE_HTML          = YES
 
-# The HTML_OUTPUT tag is used to specify where the HTML docs will be put. 
-# If a relative path is entered the value of OUTPUT_DIRECTORY will be 
+# The HTML_OUTPUT tag is used to specify where the HTML docs will be put.
+# If a relative path is entered the value of OUTPUT_DIRECTORY will be
 # put in front of it. If left blank `html' will be used as the default path.
 
 HTML_OUTPUT            = html
 
-# The HTML_FILE_EXTENSION tag can be used to specify the file extension for 
-# each generated HTML page (for example: .htm,.php,.asp). If it is left blank 
+# The HTML_FILE_EXTENSION tag can be used to specify the file extension for
+# each generated HTML page (for example: .htm,.php,.asp). If it is left blank
 # doxygen will generate files with .html extension.
 
 HTML_FILE_EXTENSION    = .html
 
-# The HTML_HEADER tag can be used to specify a personal HTML header for 
-# each generated HTML page. If it is left blank doxygen will generate a 
+# The HTML_HEADER tag can be used to specify a personal HTML header for
+# each generated HTML page. If it is left blank doxygen will generate a
 # standard header.
 
-HTML_HEADER            = 
+HTML_HEADER            =
 
-# The HTML_FOOTER tag can be used to specify a personal HTML footer for 
-# each generated HTML page. If it is left blank doxygen will generate a 
+# The HTML_FOOTER tag can be used to specify a personal HTML footer for
+# each generated HTML page. If it is left blank doxygen will generate a
 # standard footer.
 
-HTML_FOOTER            = 
+HTML_FOOTER            =
 
-# The HTML_STYLESHEET tag can be used to specify a user-defined cascading 
-# style sheet that is used by each HTML page. It can be used to 
-# fine-tune the look of the HTML output. If the tag is left blank doxygen 
-# will generate a default style sheet. Note that doxygen will try to copy 
-# the style sheet file to the HTML output directory, so don't put your own 
+# The HTML_STYLESHEET tag can be used to specify a user-defined cascading
+# style sheet that is used by each HTML page. It can be used to
+# fine-tune the look of the HTML output. If the tag is left blank doxygen
+# will generate a default style sheet. Note that doxygen will try to copy
+# the style sheet file to the HTML output directory, so don't put your own
 # stylesheet in the HTML output directory as well, or it will be erased!
 
-HTML_STYLESHEET        = 
+HTML_STYLESHEET        =
 
-# If the HTML_ALIGN_MEMBERS tag is set to YES, the members of classes, 
-# files or namespaces will be aligned in HTML using tables. If set to 
+# If the HTML_ALIGN_MEMBERS tag is set to YES, the members of classes,
+# files or namespaces will be aligned in HTML using tables. If set to
 # NO a bullet list will be used.
 
 HTML_ALIGN_MEMBERS     = YES
 
-# If the HTML_DYNAMIC_SECTIONS tag is set to YES then the generated HTML 
-# documentation will contain sections that can be hidden and shown after the 
-# page has loaded. For this to work a browser that supports 
-# JavaScript and DHTML is required (for instance Mozilla 1.0+, Firefox 
+# If the HTML_DYNAMIC_SECTIONS tag is set to YES then the generated HTML
+# documentation will contain sections that can be hidden and shown after the
+# page has loaded. For this to work a browser that supports
+# JavaScript and DHTML is required (for instance Mozilla 1.0+, Firefox
 # Netscape 6.0+, Internet explorer 5.0+, Konqueror, or Safari).
 
 HTML_DYNAMIC_SECTIONS  = NO
 
-# If the GENERATE_DOCSET tag is set to YES, additional index files 
-# will be generated that can be used as input for Apple's Xcode 3 
-# integrated development environment, introduced with OSX 10.5 (Leopard). 
-# To create a documentation set, doxygen will generate a Makefile in the 
-# HTML output directory. Running make will produce the docset in that 
-# directory and running "make install" will install the docset in 
-# ~/Library/Developer/Shared/Documentation/DocSets so that Xcode will find 
-# it at startup. 
+# If the GENERATE_DOCSET tag is set to YES, additional index files
+# will be generated that can be used as input for Apple's Xcode 3
+# integrated development environment, introduced with OSX 10.5 (Leopard).
+# To create a documentation set, doxygen will generate a Makefile in the
+# HTML output directory. Running make will produce the docset in that
+# directory and running "make install" will install the docset in
+# ~/Library/Developer/Shared/Documentation/DocSets so that Xcode will find
+# it at startup.
 # See http://developer.apple.com/tools/creatingdocsetswithdoxygen.html for more information.
 
 GENERATE_DOCSET        = NO
 
-# When GENERATE_DOCSET tag is set to YES, this tag determines the name of the 
-# feed. A documentation feed provides an umbrella under which multiple 
-# documentation sets from a single provider (such as a company or product suite) 
+# When GENERATE_DOCSET tag is set to YES, this tag determines the name of the
+# feed. A documentation feed provides an umbrella under which multiple
+# documentation sets from a single provider (such as a company or product suite)
 # can be grouped.
 
 DOCSET_FEEDNAME        = "Doxygen generated docs"
 
-# When GENERATE_DOCSET tag is set to YES, this tag specifies a string that 
-# should uniquely identify the documentation set bundle. This should be a 
-# reverse domain-name style string, e.g. com.mycompany.MyDocSet. Doxygen 
+# When GENERATE_DOCSET tag is set to YES, this tag specifies a string that
+# should uniquely identify the documentation set bundle. This should be a
+# reverse domain-name style string, e.g. com.mycompany.MyDocSet. Doxygen
 # will append .docset to the name.
 
 DOCSET_BUNDLE_ID       = org.doxygen.Project
 
-# If the GENERATE_HTMLHELP tag is set to YES, additional index files 
-# will be generated that can be used as input for tools like the 
-# Microsoft HTML help workshop to generate a compiled HTML help file (.chm) 
+# If the GENERATE_HTMLHELP tag is set to YES, additional index files
+# will be generated that can be used as input for tools like the
+# Microsoft HTML help workshop to generate a compiled HTML help file (.chm)
 # of the generated HTML documentation.
 
 GENERATE_HTMLHELP      = NO
 
-# If the GENERATE_HTMLHELP tag is set to YES, the CHM_FILE tag can 
-# be used to specify the file name of the resulting .chm file. You 
-# can add a path in front of the file if the result should not be 
+# If the GENERATE_HTMLHELP tag is set to YES, the CHM_FILE tag can
+# be used to specify the file name of the resulting .chm file. You
+# can add a path in front of the file if the result should not be
 # written to the html output directory.
 
-CHM_FILE               = 
+CHM_FILE               =
 
-# If the GENERATE_HTMLHELP tag is set to YES, the HHC_LOCATION tag can 
-# be used to specify the location (absolute path including file name) of 
-# the HTML help compiler (hhc.exe). If non-empty doxygen will try to run 
+# If the GENERATE_HTMLHELP tag is set to YES, the HHC_LOCATION tag can
+# be used to specify the location (absolute path including file name) of
+# the HTML help compiler (hhc.exe). If non-empty doxygen will try to run
 # the HTML help compiler on the generated index.hhp.
 
-HHC_LOCATION           = 
+HHC_LOCATION           =
 
-# If the GENERATE_HTMLHELP tag is set to YES, the GENERATE_CHI flag 
-# controls if a separate .chi index file is generated (YES) or that 
+# If the GENERATE_HTMLHELP tag is set to YES, the GENERATE_CHI flag
+# controls if a separate .chi index file is generated (YES) or that
 # it should be included in the master .chm file (NO).
 
 GENERATE_CHI           = NO
 
-# If the GENERATE_HTMLHELP tag is set to YES, the CHM_INDEX_ENCODING 
-# is used to encode HtmlHelp index (hhk), content (hhc) and project file 
+# If the GENERATE_HTMLHELP tag is set to YES, the CHM_INDEX_ENCODING
+# is used to encode HtmlHelp index (hhk), content (hhc) and project file
 # content.
 
-CHM_INDEX_ENCODING     = 
+CHM_INDEX_ENCODING     =
 
-# If the GENERATE_HTMLHELP tag is set to YES, the BINARY_TOC flag 
-# controls whether a binary table of contents is generated (YES) or a 
+# If the GENERATE_HTMLHELP tag is set to YES, the BINARY_TOC flag
+# controls whether a binary table of contents is generated (YES) or a
 # normal table of contents (NO) in the .chm file.
 
 BINARY_TOC             = NO
 
-# The TOC_EXPAND flag can be set to YES to add extra items for group members 
+# The TOC_EXPAND flag can be set to YES to add extra items for group members
 # to the contents of the HTML help documentation and to the tree view.
 
 TOC_EXPAND             = NO
 
-# If the GENERATE_QHP tag is set to YES and both QHP_NAMESPACE and QHP_VIRTUAL_FOLDER 
-# are set, an additional index file will be generated that can be used as input for 
-# Qt's qhelpgenerator to generate a Qt Compressed Help (.qch) of the generated 
+# If the GENERATE_QHP tag is set to YES and both QHP_NAMESPACE and QHP_VIRTUAL_FOLDER
+# are set, an additional index file will be generated that can be used as input for
+# Qt's qhelpgenerator to generate a Qt Compressed Help (.qch) of the generated
 # HTML documentation.
 
 GENERATE_QHP           = NO
 
-# If the QHG_LOCATION tag is specified, the QCH_FILE tag can 
-# be used to specify the file name of the resulting .qch file. 
+# If the QHG_LOCATION tag is specified, the QCH_FILE tag can
+# be used to specify the file name of the resulting .qch file.
 # The path specified is relative to the HTML output folder.
 
-QCH_FILE               = 
+QCH_FILE               =
 
-# The QHP_NAMESPACE tag specifies the namespace to use when generating 
-# Qt Help Project output. For more information please see 
+# The QHP_NAMESPACE tag specifies the namespace to use when generating
+# Qt Help Project output. For more information please see
 # http://doc.trolltech.com/qthelpproject.html#namespace
 
-QHP_NAMESPACE          = 
+QHP_NAMESPACE          =
 
-# The QHP_VIRTUAL_FOLDER tag specifies the namespace to use when generating 
-# Qt Help Project output. For more information please see 
+# The QHP_VIRTUAL_FOLDER tag specifies the namespace to use when generating
+# Qt Help Project output. For more information please see
 # http://doc.trolltech.com/qthelpproject.html#virtual-folders
 
 QHP_VIRTUAL_FOLDER     = doc
 
-# If QHP_CUST_FILTER_NAME is set, it specifies the name of a custom filter to add. 
-# For more information please see 
+# If QHP_CUST_FILTER_NAME is set, it specifies the name of a custom filter to add.
+# For more information please see
 # http://doc.trolltech.com/qthelpproject.html#custom-filters
 
-QHP_CUST_FILTER_NAME   = 
+QHP_CUST_FILTER_NAME   =
 
-# The QHP_CUST_FILT_ATTRS tag specifies the list of the attributes of the custom filter to add.For more information please see 
+# The QHP_CUST_FILT_ATTRS tag specifies the list of the attributes of the custom filter to add.For more information please see
 # <a href="http://doc.trolltech.com/qthelpproject.html#custom-filters">Qt Help Project / Custom Filters</a>.
 
-QHP_CUST_FILTER_ATTRS  = 
+QHP_CUST_FILTER_ATTRS  =
 
-# The QHP_SECT_FILTER_ATTRS tag specifies the list of the attributes this project's 
-# filter section matches. 
+# The QHP_SECT_FILTER_ATTRS tag specifies the list of the attributes this project's
+# filter section matches.
 # <a href="http://doc.trolltech.com/qthelpproject.html#filter-attributes">Qt Help Project / Filter Attributes</a>.
 
-QHP_SECT_FILTER_ATTRS  = 
+QHP_SECT_FILTER_ATTRS  =
 
-# If the GENERATE_QHP tag is set to YES, the QHG_LOCATION tag can 
-# be used to specify the location of Qt's qhelpgenerator. 
-# If non-empty doxygen will try to run qhelpgenerator on the generated 
+# If the GENERATE_QHP tag is set to YES, the QHG_LOCATION tag can
+# be used to specify the location of Qt's qhelpgenerator.
+# If non-empty doxygen will try to run qhelpgenerator on the generated
 # .qhp file.
 
-QHG_LOCATION           = 
+QHG_LOCATION           =
 
-# The DISABLE_INDEX tag can be used to turn on/off the condensed index at 
-# top of each HTML page. The value NO (the default) enables the index and 
+# The DISABLE_INDEX tag can be used to turn on/off the condensed index at
+# top of each HTML page. The value NO (the default) enables the index and
 # the value YES disables it.
 
 DISABLE_INDEX          = NO
 
-# This tag can be used to set the number of enum values (range [1..20]) 
+# This tag can be used to set the number of enum values (range [1..20])
 # that doxygen will group on one line in the generated HTML documentation.
 
 ENUM_VALUES_PER_LINE   = 4
 
-# The GENERATE_TREEVIEW tag is used to specify whether a tree-like index 
-# structure should be generated to display hierarchical information. 
-# If the tag value is set to FRAME, a side panel will be generated 
-# containing a tree-like index structure (just like the one that 
-# is generated for HTML Help). For this to work a browser that supports 
-# JavaScript, DHTML, CSS and frames is required (for instance Mozilla 1.0+, 
-# Netscape 6.0+, Internet explorer 5.0+, or Konqueror). Windows users are 
-# probably better off using the HTML help feature. Other possible values 
-# for this tag are: HIERARCHIES, which will generate the Groups, Directories, 
-# and Class Hierarchy pages using a tree view instead of an ordered list; 
-# ALL, which combines the behavior of FRAME and HIERARCHIES; and NONE, which 
-# disables this behavior completely. For backwards compatibility with previous 
-# releases of Doxygen, the values YES and NO are equivalent to FRAME and NONE 
+# The GENERATE_TREEVIEW tag is used to specify whether a tree-like index
+# structure should be generated to display hierarchical information.
+# If the tag value is set to FRAME, a side panel will be generated
+# containing a tree-like index structure (just like the one that
+# is generated for HTML Help). For this to work a browser that supports
+# JavaScript, DHTML, CSS and frames is required (for instance Mozilla 1.0+,
+# Netscape 6.0+, Internet explorer 5.0+, or Konqueror). Windows users are
+# probably better off using the HTML help feature. Other possible values
+# for this tag are: HIERARCHIES, which will generate the Groups, Directories,
+# and Class Hierarchy pages using a tree view instead of an ordered list;
+# ALL, which combines the behavior of FRAME and HIERARCHIES; and NONE, which
+# disables this behavior completely. For backwards compatibility with previous
+# releases of Doxygen, the values YES and NO are equivalent to FRAME and NONE
 # respectively.
 
 GENERATE_TREEVIEW      = NONE
 
-# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be 
-# used to set the initial width (in pixels) of the frame in which the tree 
+# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be
+# used to set the initial width (in pixels) of the frame in which the tree
 # is shown.
 
 TREEVIEW_WIDTH         = 250
 
-# Use this tag to change the font size of Latex formulas included 
-# as images in the HTML documentation. The default is 10. Note that 
-# when you change the font size after a successful doxygen run you need 
-# to manually remove any form_*.png images from the HTML output directory 
+# Use this tag to change the font size of Latex formulas included
+# as images in the HTML documentation. The default is 10. Note that
+# when you change the font size after a successful doxygen run you need
+# to manually remove any form_*.png images from the HTML output directory
 # to force them to be regenerated.
 
 FORMULA_FONTSIZE       = 10
@@ -1008,74 +1008,74 @@ FORMULA_FONTSIZE       = 10
 # configuration options related to the LaTeX output
 #---------------------------------------------------------------------------
 
-# If the GENERATE_LATEX tag is set to YES (the default) Doxygen will 
+# If the GENERATE_LATEX tag is set to YES (the default) Doxygen will
 # generate Latex output.
 
 GENERATE_LATEX         = NO
 
-# The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put. 
-# If a relative path is entered the value of OUTPUT_DIRECTORY will be 
+# The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put.
+# If a relative path is entered the value of OUTPUT_DIRECTORY will be
 # put in front of it. If left blank `latex' will be used as the default path.
 
 LATEX_OUTPUT           = latex
 
-# The LATEX_CMD_NAME tag can be used to specify the LaTeX command name to be 
+# The LATEX_CMD_NAME tag can be used to specify the LaTeX command name to be
 # invoked. If left blank `latex' will be used as the default command name.
 
 LATEX_CMD_NAME         = latex
 
-# The MAKEINDEX_CMD_NAME tag can be used to specify the command name to 
-# generate index for LaTeX. If left blank `makeindex' will be used as the 
+# The MAKEINDEX_CMD_NAME tag can be used to specify the command name to
+# generate index for LaTeX. If left blank `makeindex' will be used as the
 # default command name.
 
 MAKEINDEX_CMD_NAME     = makeindex
 
-# If the COMPACT_LATEX tag is set to YES Doxygen generates more compact 
-# LaTeX documents. This may be useful for small projects and may help to 
+# If the COMPACT_LATEX tag is set to YES Doxygen generates more compact
+# LaTeX documents. This may be useful for small projects and may help to
 # save some trees in general.
 
 COMPACT_LATEX          = NO
 
-# The PAPER_TYPE tag can be used to set the paper type that is used 
-# by the printer. Possible values are: a4, a4wide, letter, legal and 
+# The PAPER_TYPE tag can be used to set the paper type that is used
+# by the printer. Possible values are: a4, a4wide, letter, legal and
 # executive. If left blank a4wide will be used.
 
 PAPER_TYPE             = a4wide
 
-# The EXTRA_PACKAGES tag can be to specify one or more names of LaTeX 
+# The EXTRA_PACKAGES tag can be to specify one or more names of LaTeX
 # packages that should be included in the LaTeX output.
 
-EXTRA_PACKAGES         = 
+EXTRA_PACKAGES         =
 
-# The LATEX_HEADER tag can be used to specify a personal LaTeX header for 
-# the generated latex document. The header should contain everything until 
-# the first chapter. If it is left blank doxygen will generate a 
+# The LATEX_HEADER tag can be used to specify a personal LaTeX header for
+# the generated latex document. The header should contain everything until
+# the first chapter. If it is left blank doxygen will generate a
 # standard header. Notice: only use this tag if you know what you are doing!
 
-LATEX_HEADER           = 
+LATEX_HEADER           =
 
-# If the PDF_HYPERLINKS tag is set to YES, the LaTeX that is generated 
-# is prepared for conversion to pdf (using ps2pdf). The pdf file will 
-# contain links (just like the HTML output) instead of page references 
+# If the PDF_HYPERLINKS tag is set to YES, the LaTeX that is generated
+# is prepared for conversion to pdf (using ps2pdf). The pdf file will
+# contain links (just like the HTML output) instead of page references
 # This makes the output suitable for online browsing using a pdf viewer.
 
 PDF_HYPERLINKS         = YES
 
-# If the USE_PDFLATEX tag is set to YES, pdflatex will be used instead of 
-# plain latex in the generated Makefile. Set this option to YES to get a 
+# If the USE_PDFLATEX tag is set to YES, pdflatex will be used instead of
+# plain latex in the generated Makefile. Set this option to YES to get a
 # higher quality PDF documentation.
 
 USE_PDFLATEX           = YES
 
-# If the LATEX_BATCHMODE tag is set to YES, doxygen will add the \\batchmode. 
-# command to the generated LaTeX files. This will instruct LaTeX to keep 
-# running if errors occur, instead of asking the user for help. 
+# If the LATEX_BATCHMODE tag is set to YES, doxygen will add the \\batchmode.
+# command to the generated LaTeX files. This will instruct LaTeX to keep
+# running if errors occur, instead of asking the user for help.
 # This option is also used when generating formulas in HTML.
 
 LATEX_BATCHMODE        = NO
 
-# If LATEX_HIDE_INDICES is set to YES then doxygen will not 
-# include the index chapters (such as File Index, Compound Index, etc.) 
+# If LATEX_HIDE_INDICES is set to YES then doxygen will not
+# include the index chapters (such as File Index, Compound Index, etc.)
 # in the output.
 
 LATEX_HIDE_INDICES     = NO
@@ -1084,68 +1084,68 @@ LATEX_HIDE_INDICES     = NO
 # configuration options related to the RTF output
 #---------------------------------------------------------------------------
 
-# If the GENERATE_RTF tag is set to YES Doxygen will generate RTF output 
-# The RTF output is optimized for Word 97 and may not look very pretty with 
+# If the GENERATE_RTF tag is set to YES Doxygen will generate RTF output
+# The RTF output is optimized for Word 97 and may not look very pretty with
 # other RTF readers or editors.
 
 GENERATE_RTF           = NO
 
-# The RTF_OUTPUT tag is used to specify where the RTF docs will be put. 
-# If a relative path is entered the value of OUTPUT_DIRECTORY will be 
+# The RTF_OUTPUT tag is used to specify where the RTF docs will be put.
+# If a relative path is entered the value of OUTPUT_DIRECTORY will be
 # put in front of it. If left blank `rtf' will be used as the default path.
 
 RTF_OUTPUT             = rtf
 
-# If the COMPACT_RTF tag is set to YES Doxygen generates more compact 
-# RTF documents. This may be useful for small projects and may help to 
+# If the COMPACT_RTF tag is set to YES Doxygen generates more compact
+# RTF documents. This may be useful for small projects and may help to
 # save some trees in general.
 
 COMPACT_RTF            = NO
 
-# If the RTF_HYPERLINKS tag is set to YES, the RTF that is generated 
-# will contain hyperlink fields. The RTF file will 
-# contain links (just like the HTML output) instead of page references. 
-# This makes the output suitable for online browsing using WORD or other 
-# programs which support those fields. 
+# If the RTF_HYPERLINKS tag is set to YES, the RTF that is generated
+# will contain hyperlink fields. The RTF file will
+# contain links (just like the HTML output) instead of page references.
+# This makes the output suitable for online browsing using WORD or other
+# programs which support those fields.
 # Note: wordpad (write) and others do not support links.
 
 RTF_HYPERLINKS         = NO
 
-# Load stylesheet definitions from file. Syntax is similar to doxygen's 
-# config file, i.e. a series of assignments. You only have to provide 
+# Load stylesheet definitions from file. Syntax is similar to doxygen's
+# config file, i.e. a series of assignments. You only have to provide
 # replacements, missing definitions are set to their default value.
 
-RTF_STYLESHEET_FILE    = 
+RTF_STYLESHEET_FILE    =
 
-# Set optional variables used in the generation of an rtf document. 
+# Set optional variables used in the generation of an rtf document.
 # Syntax is similar to doxygen's config file.
 
-RTF_EXTENSIONS_FILE    = 
+RTF_EXTENSIONS_FILE    =
 
 #---------------------------------------------------------------------------
 # configuration options related to the man page output
 #---------------------------------------------------------------------------
 
-# If the GENERATE_MAN tag is set to YES (the default) Doxygen will 
+# If the GENERATE_MAN tag is set to YES (the default) Doxygen will
 # generate man pages
 
 GENERATE_MAN           = NO
 
-# The MAN_OUTPUT tag is used to specify where the man pages will be put. 
-# If a relative path is entered the value of OUTPUT_DIRECTORY will be 
+# The MAN_OUTPUT tag is used to specify where the man pages will be put.
+# If a relative path is entered the value of OUTPUT_DIRECTORY will be
 # put in front of it. If left blank `man' will be used as the default path.
 
 MAN_OUTPUT             = man
 
-# The MAN_EXTENSION tag determines the extension that is added to 
+# The MAN_EXTENSION tag determines the extension that is added to
 # the generated man pages (default is the subroutine's section .3)
 
 MAN_EXTENSION          = .3
 
-# If the MAN_LINKS tag is set to YES and Doxygen generates man output, 
-# then it will generate one additional man file for each entity 
-# documented in the real man page(s). These additional files 
-# only source the real man page, but without them the man command 
+# If the MAN_LINKS tag is set to YES and Doxygen generates man output,
+# then it will generate one additional man file for each entity
+# documented in the real man page(s). These additional files
+# only source the real man page, but without them the man command
 # would be unable to find the correct page. The default is NO.
 
 MAN_LINKS              = NO
@@ -1154,33 +1154,33 @@ MAN_LINKS              = NO
 # configuration options related to the XML output
 #---------------------------------------------------------------------------
 
-# If the GENERATE_XML tag is set to YES Doxygen will 
-# generate an XML file that captures the structure of 
+# If the GENERATE_XML tag is set to YES Doxygen will
+# generate an XML file that captures the structure of
 # the code including all documentation.
 
 GENERATE_XML           = NO
 
-# The XML_OUTPUT tag is used to specify where the XML pages will be put. 
-# If a relative path is entered the value of OUTPUT_DIRECTORY will be 
+# The XML_OUTPUT tag is used to specify where the XML pages will be put.
+# If a relative path is entered the value of OUTPUT_DIRECTORY will be
 # put in front of it. If left blank `xml' will be used as the default path.
 
 XML_OUTPUT             = xml
 
-# The XML_SCHEMA tag can be used to specify an XML schema, 
-# which can be used by a validating XML parser to check the 
+# The XML_SCHEMA tag can be used to specify an XML schema,
+# which can be used by a validating XML parser to check the
 # syntax of the XML files.
 
-XML_SCHEMA             = 
+XML_SCHEMA             =
 
-# The XML_DTD tag can be used to specify an XML DTD, 
-# which can be used by a validating XML parser to check the 
+# The XML_DTD tag can be used to specify an XML DTD,
+# which can be used by a validating XML parser to check the
 # syntax of the XML files.
 
-XML_DTD                = 
+XML_DTD                =
 
-# If the XML_PROGRAMLISTING tag is set to YES Doxygen will 
-# dump the program listings (including syntax highlighting 
-# and cross-referencing information) to the XML output. Note that 
+# If the XML_PROGRAMLISTING tag is set to YES Doxygen will
+# dump the program listings (including syntax highlighting
+# and cross-referencing information) to the XML output. Note that
 # enabling this will significantly increase the size of the XML output.
 
 XML_PROGRAMLISTING     = YES
@@ -1189,10 +1189,10 @@ XML_PROGRAMLISTING     = YES
 # configuration options for the AutoGen Definitions output
 #---------------------------------------------------------------------------
 
-# If the GENERATE_AUTOGEN_DEF tag is set to YES Doxygen will 
-# generate an AutoGen Definitions (see autogen.sf.net) file 
-# that captures the structure of the code including all 
-# documentation. Note that this feature is still experimental 
+# If the GENERATE_AUTOGEN_DEF tag is set to YES Doxygen will
+# generate an AutoGen Definitions (see autogen.sf.net) file
+# that captures the structure of the code including all
+# documentation. Note that this feature is still experimental
 # and incomplete at the moment.
 
 GENERATE_AUTOGEN_DEF   = NO
@@ -1201,334 +1201,334 @@ GENERATE_AUTOGEN_DEF   = NO
 # configuration options related to the Perl module output
 #---------------------------------------------------------------------------
 
-# If the GENERATE_PERLMOD tag is set to YES Doxygen will 
-# generate a Perl module file that captures the structure of 
-# the code including all documentation. Note that this 
-# feature is still experimental and incomplete at the 
+# If the GENERATE_PERLMOD tag is set to YES Doxygen will
+# generate a Perl module file that captures the structure of
+# the code including all documentation. Note that this
+# feature is still experimental and incomplete at the
 # moment.
 
 GENERATE_PERLMOD       = NO
 
-# If the PERLMOD_LATEX tag is set to YES Doxygen will generate 
-# the necessary Makefile rules, Perl scripts and LaTeX code to be able 
+# If the PERLMOD_LATEX tag is set to YES Doxygen will generate
+# the necessary Makefile rules, Perl scripts and LaTeX code to be able
 # to generate PDF and DVI output from the Perl module output.
 
 PERLMOD_LATEX          = NO
 
-# If the PERLMOD_PRETTY tag is set to YES the Perl module output will be 
-# nicely formatted so it can be parsed by a human reader.  This is useful 
-# if you want to understand what is going on.  On the other hand, if this 
-# tag is set to NO the size of the Perl module output will be much smaller 
+# If the PERLMOD_PRETTY tag is set to YES the Perl module output will be
+# nicely formatted so it can be parsed by a human reader.  This is useful
+# if you want to understand what is going on.  On the other hand, if this
+# tag is set to NO the size of the Perl module output will be much smaller
 # and Perl will parse it just the same.
 
 PERLMOD_PRETTY         = YES
 
-# The names of the make variables in the generated doxyrules.make file 
-# are prefixed with the string contained in PERLMOD_MAKEVAR_PREFIX. 
-# This is useful so different doxyrules.make files included by the same 
+# The names of the make variables in the generated doxyrules.make file
+# are prefixed with the string contained in PERLMOD_MAKEVAR_PREFIX.
+# This is useful so different doxyrules.make files included by the same
 # Makefile don't overwrite each other's variables.
 
-PERLMOD_MAKEVAR_PREFIX = 
+PERLMOD_MAKEVAR_PREFIX =
 
 #---------------------------------------------------------------------------
-# Configuration options related to the preprocessor   
+# Configuration options related to the preprocessor
 #---------------------------------------------------------------------------
 
-# If the ENABLE_PREPROCESSING tag is set to YES (the default) Doxygen will 
-# evaluate all C-preprocessor directives found in the sources and include 
+# If the ENABLE_PREPROCESSING tag is set to YES (the default) Doxygen will
+# evaluate all C-preprocessor directives found in the sources and include
 # files.
 
 ENABLE_PREPROCESSING   = YES
 
-# If the MACRO_EXPANSION tag is set to YES Doxygen will expand all macro 
-# names in the source code. If set to NO (the default) only conditional 
-# compilation will be performed. Macro expansion can be done in a controlled 
+# If the MACRO_EXPANSION tag is set to YES Doxygen will expand all macro
+# names in the source code. If set to NO (the default) only conditional
+# compilation will be performed. Macro expansion can be done in a controlled
 # way by setting EXPAND_ONLY_PREDEF to YES.
 
 MACRO_EXPANSION        = NO
 
-# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES 
-# then the macro expansion is limited to the macros specified with the 
+# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES
+# then the macro expansion is limited to the macros specified with the
 # PREDEFINED and EXPAND_AS_DEFINED tags.
 
 EXPAND_ONLY_PREDEF     = NO
 
-# If the SEARCH_INCLUDES tag is set to YES (the default) the includes files 
+# If the SEARCH_INCLUDES tag is set to YES (the default) the includes files
 # in the INCLUDE_PATH (see below) will be search if a #include is found.
 
 SEARCH_INCLUDES        = YES
 
-# The INCLUDE_PATH tag can be used to specify one or more directories that 
-# contain include files that are not input files but should be processed by 
+# The INCLUDE_PATH tag can be used to specify one or more directories that
+# contain include files that are not input files but should be processed by
 # the preprocessor.
 
-INCLUDE_PATH           = 
+INCLUDE_PATH           =
 
-# You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard 
-# patterns (like *.h and *.hpp) to filter out the header-files in the 
-# directories. If left blank, the patterns specified with FILE_PATTERNS will 
+# You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard
+# patterns (like *.h and *.hpp) to filter out the header-files in the
+# directories. If left blank, the patterns specified with FILE_PATTERNS will
 # be used.
 
-INCLUDE_FILE_PATTERNS  = 
+INCLUDE_FILE_PATTERNS  =
 
-# The PREDEFINED tag can be used to specify one or more macro names that 
-# are defined before the preprocessor is started (similar to the -D option of 
-# gcc). The argument of the tag is a list of macros of the form: name 
-# or name=definition (no spaces). If the definition and the = are 
-# omitted =1 is assumed. To prevent a macro definition from being 
-# undefined via #undef or recursively expanded use the := operator 
+# The PREDEFINED tag can be used to specify one or more macro names that
+# are defined before the preprocessor is started (similar to the -D option of
+# gcc). The argument of the tag is a list of macros of the form: name
+# or name=definition (no spaces). If the definition and the = are
+# omitted =1 is assumed. To prevent a macro definition from being
+# undefined via #undef or recursively expanded use the := operator
 # instead of the = operator.
 
-PREDEFINED             = 
+PREDEFINED             =
 
-# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then 
-# this tag can be used to specify a list of macro names that should be expanded. 
-# The macro definition that is found in the sources will be used. 
+# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then
+# this tag can be used to specify a list of macro names that should be expanded.
+# The macro definition that is found in the sources will be used.
 # Use the PREDEFINED tag if you want to use a different macro definition.
 
-EXPAND_AS_DEFINED      = 
+EXPAND_AS_DEFINED      =
 
-# If the SKIP_FUNCTION_MACROS tag is set to YES (the default) then 
-# doxygen's preprocessor will remove all function-like macros that are alone 
-# on a line, have an all uppercase name, and do not end with a semicolon. Such 
-# function macros are typically used for boiler-plate code, and will confuse 
+# If the SKIP_FUNCTION_MACROS tag is set to YES (the default) then
+# doxygen's preprocessor will remove all function-like macros that are alone
+# on a line, have an all uppercase name, and do not end with a semicolon. Such
+# function macros are typically used for boiler-plate code, and will confuse
 # the parser if not removed.
 
 SKIP_FUNCTION_MACROS   = YES
 
 #---------------------------------------------------------------------------
-# Configuration::additions related to external references   
+# Configuration::additions related to external references
 #---------------------------------------------------------------------------
 
-# The TAGFILES option can be used to specify one or more tagfiles. 
-# Optionally an initial location of the external documentation 
-# can be added for each tagfile. The format of a tag file without 
-# this location is as follows: 
-#   TAGFILES = file1 file2 ... 
-# Adding location for the tag files is done as follows: 
-#   TAGFILES = file1=loc1 "file2 = loc2" ... 
-# where "loc1" and "loc2" can be relative or absolute paths or 
-# URLs. If a location is present for each tag, the installdox tool 
-# does not have to be run to correct the links. 
-# Note that each tag file must have a unique name 
-# (where the name does NOT include the path) 
-# If a tag file is not located in the directory in which doxygen 
+# The TAGFILES option can be used to specify one or more tagfiles.
+# Optionally an initial location of the external documentation
+# can be added for each tagfile. The format of a tag file without
+# this location is as follows:
+#   TAGFILES = file1 file2 ...
+# Adding location for the tag files is done as follows:
+#   TAGFILES = file1=loc1 "file2 = loc2" ...
+# where "loc1" and "loc2" can be relative or absolute paths or
+# URLs. If a location is present for each tag, the installdox tool
+# does not have to be run to correct the links.
+# Note that each tag file must have a unique name
+# (where the name does NOT include the path)
+# If a tag file is not located in the directory in which doxygen
 # is run, you must also specify the path to the tagfile here.
 
-TAGFILES               = 
+TAGFILES               =
 
-# When a file name is specified after GENERATE_TAGFILE, doxygen will create 
+# When a file name is specified after GENERATE_TAGFILE, doxygen will create
 # a tag file that is based on the input files it reads.
 
-GENERATE_TAGFILE       = 
+GENERATE_TAGFILE       =
 
-# If the ALLEXTERNALS tag is set to YES all external classes will be listed 
-# in the class index. If set to NO only the inherited external classes 
+# If the ALLEXTERNALS tag is set to YES all external classes will be listed
+# in the class index. If set to NO only the inherited external classes
 # will be listed.
 
 ALLEXTERNALS           = NO
 
-# If the EXTERNAL_GROUPS tag is set to YES all external groups will be listed 
-# in the modules index. If set to NO, only the current project's groups will 
+# If the EXTERNAL_GROUPS tag is set to YES all external groups will be listed
+# in the modules index. If set to NO, only the current project's groups will
 # be listed.
 
 EXTERNAL_GROUPS        = YES
 
-# The PERL_PATH should be the absolute path and name of the perl script 
+# The PERL_PATH should be the absolute path and name of the perl script
 # interpreter (i.e. the result of `which perl').
 
 PERL_PATH              = /usr/bin/perl
 
 #---------------------------------------------------------------------------
-# Configuration options related to the dot tool   
+# Configuration options related to the dot tool
 #---------------------------------------------------------------------------
 
-# If the CLASS_DIAGRAMS tag is set to YES (the default) Doxygen will 
-# generate a inheritance diagram (in HTML, RTF and LaTeX) for classes with base 
-# or super classes. Setting the tag to NO turns the diagrams off. Note that 
-# this option is superseded by the HAVE_DOT option below. This is only a 
-# fallback. It is recommended to install and use dot, since it yields more 
+# If the CLASS_DIAGRAMS tag is set to YES (the default) Doxygen will
+# generate a inheritance diagram (in HTML, RTF and LaTeX) for classes with base
+# or super classes. Setting the tag to NO turns the diagrams off. Note that
+# this option is superseded by the HAVE_DOT option below. This is only a
+# fallback. It is recommended to install and use dot, since it yields more
 # powerful graphs.
 
 CLASS_DIAGRAMS         = YES
 
-# You can define message sequence charts within doxygen comments using the \msc 
-# command. Doxygen will then run the mscgen tool (see 
-# http://www.mcternan.me.uk/mscgen/) to produce the chart and insert it in the 
-# documentation. The MSCGEN_PATH tag allows you to specify the directory where 
-# the mscgen tool resides. If left empty the tool is assumed to be found in the 
+# You can define message sequence charts within doxygen comments using the \msc
+# command. Doxygen will then run the mscgen tool (see
+# http://www.mcternan.me.uk/mscgen/) to produce the chart and insert it in the
+# documentation. The MSCGEN_PATH tag allows you to specify the directory where
+# the mscgen tool resides. If left empty the tool is assumed to be found in the
 # default search path.
 
-MSCGEN_PATH            = 
+MSCGEN_PATH            =
 
-# If set to YES, the inheritance and collaboration graphs will hide 
-# inheritance and usage relations if the target is undocumented 
+# If set to YES, the inheritance and collaboration graphs will hide
+# inheritance and usage relations if the target is undocumented
 # or is not a class.
 
 HIDE_UNDOC_RELATIONS   = YES
 
-# If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is 
-# available from the path. This tool is part of Graphviz, a graph visualization 
-# toolkit from AT&T and Lucent Bell Labs. The other options in this section 
+# If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is
+# available from the path. This tool is part of Graphviz, a graph visualization
+# toolkit from AT&T and Lucent Bell Labs. The other options in this section
 # have no effect if this option is set to NO (the default)
 
 HAVE_DOT               = NO
 
-# By default doxygen will write a font called FreeSans.ttf to the output 
-# directory and reference it in all dot files that doxygen generates. This 
-# font does not include all possible unicode characters however, so when you need 
-# these (or just want a differently looking font) you can specify the font name 
-# using DOT_FONTNAME. You need need to make sure dot is able to find the font, 
-# which can be done by putting it in a standard location or by setting the 
-# DOTFONTPATH environment variable or by setting DOT_FONTPATH to the directory 
+# By default doxygen will write a font called FreeSans.ttf to the output
+# directory and reference it in all dot files that doxygen generates. This
+# font does not include all possible unicode characters however, so when you need
+# these (or just want a differently looking font) you can specify the font name
+# using DOT_FONTNAME. You need need to make sure dot is able to find the font,
+# which can be done by putting it in a standard location or by setting the
+# DOTFONTPATH environment variable or by setting DOT_FONTPATH to the directory
 # containing the font.
 
 DOT_FONTNAME           = FreeSans
 
-# The DOT_FONTSIZE tag can be used to set the size of the font of dot graphs. 
+# The DOT_FONTSIZE tag can be used to set the size of the font of dot graphs.
 # The default size is 10pt.
 
 DOT_FONTSIZE           = 10
 
-# By default doxygen will tell dot to use the output directory to look for the 
-# FreeSans.ttf font (which doxygen will put there itself). If you specify a 
-# different font using DOT_FONTNAME you can set the path where dot 
+# By default doxygen will tell dot to use the output directory to look for the
+# FreeSans.ttf font (which doxygen will put there itself). If you specify a
+# different font using DOT_FONTNAME you can set the path where dot
 # can find it using this tag.
 
-DOT_FONTPATH           = 
+DOT_FONTPATH           =
 
-# If the CLASS_GRAPH and HAVE_DOT tags are set to YES then doxygen 
-# will generate a graph for each documented class showing the direct and 
-# indirect inheritance relations. Setting this tag to YES will force the 
+# If the CLASS_GRAPH and HAVE_DOT tags are set to YES then doxygen
+# will generate a graph for each documented class showing the direct and
+# indirect inheritance relations. Setting this tag to YES will force the
 # the CLASS_DIAGRAMS tag to NO.
 
 CLASS_GRAPH            = YES
 
-# If the COLLABORATION_GRAPH and HAVE_DOT tags are set to YES then doxygen 
-# will generate a graph for each documented class showing the direct and 
-# indirect implementation dependencies (inheritance, containment, and 
+# If the COLLABORATION_GRAPH and HAVE_DOT tags are set to YES then doxygen
+# will generate a graph for each documented class showing the direct and
+# indirect implementation dependencies (inheritance, containment, and
 # class references variables) of the class with other documented classes.
 
 COLLABORATION_GRAPH    = YES
 
-# If the GROUP_GRAPHS and HAVE_DOT tags are set to YES then doxygen 
+# If the GROUP_GRAPHS and HAVE_DOT tags are set to YES then doxygen
 # will generate a graph for groups, showing the direct groups dependencies
 
 GROUP_GRAPHS           = YES
 
-# If the UML_LOOK tag is set to YES doxygen will generate inheritance and 
-# collaboration diagrams in a style similar to the OMG's Unified Modeling 
+# If the UML_LOOK tag is set to YES doxygen will generate inheritance and
+# collaboration diagrams in a style similar to the OMG's Unified Modeling
 # Language.
 
 UML_LOOK               = NO
 
-# If set to YES, the inheritance and collaboration graphs will show the 
+# If set to YES, the inheritance and collaboration graphs will show the
 # relations between templates and their instances.
 
 TEMPLATE_RELATIONS     = NO
 
-# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDE_GRAPH, and HAVE_DOT 
-# tags are set to YES then doxygen will generate a graph for each documented 
-# file showing the direct and indirect include dependencies of the file with 
+# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDE_GRAPH, and HAVE_DOT
+# tags are set to YES then doxygen will generate a graph for each documented
+# file showing the direct and indirect include dependencies of the file with
 # other documented files.
 
 INCLUDE_GRAPH          = YES
 
-# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDED_BY_GRAPH, and 
-# HAVE_DOT tags are set to YES then doxygen will generate a graph for each 
-# documented header file showing the documented files that directly or 
+# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDED_BY_GRAPH, and
+# HAVE_DOT tags are set to YES then doxygen will generate a graph for each
+# documented header file showing the documented files that directly or
 # indirectly include this file.
 
 INCLUDED_BY_GRAPH      = YES
 
-# If the CALL_GRAPH and HAVE_DOT options are set to YES then 
-# doxygen will generate a call dependency graph for every global function 
-# or class method. Note that enabling this option will significantly increase 
-# the time of a run. So in most cases it will be better to enable call graphs 
+# If the CALL_GRAPH and HAVE_DOT options are set to YES then
+# doxygen will generate a call dependency graph for every global function
+# or class method. Note that enabling this option will significantly increase
+# the time of a run. So in most cases it will be better to enable call graphs
 # for selected functions only using the \callgraph command.
 
 CALL_GRAPH             = NO
 
-# If the CALLER_GRAPH and HAVE_DOT tags are set to YES then 
-# doxygen will generate a caller dependency graph for every global function 
-# or class method. Note that enabling this option will significantly increase 
-# the time of a run. So in most cases it will be better to enable caller 
+# If the CALLER_GRAPH and HAVE_DOT tags are set to YES then
+# doxygen will generate a caller dependency graph for every global function
+# or class method. Note that enabling this option will significantly increase
+# the time of a run. So in most cases it will be better to enable caller
 # graphs for selected functions only using the \callergraph command.
 
 CALLER_GRAPH           = NO
 
-# If the GRAPHICAL_HIERARCHY and HAVE_DOT tags are set to YES then doxygen 
+# If the GRAPHICAL_HIERARCHY and HAVE_DOT tags are set to YES then doxygen
 # will graphical hierarchy of all classes instead of a textual one.
 
 GRAPHICAL_HIERARCHY    = YES
 
-# If the DIRECTORY_GRAPH, SHOW_DIRECTORIES and HAVE_DOT tags are set to YES 
-# then doxygen will show the dependencies a directory has on other directories 
-# in a graphical way. The dependency relations are determined by the #include 
+# If the DIRECTORY_GRAPH, SHOW_DIRECTORIES and HAVE_DOT tags are set to YES
+# then doxygen will show the dependencies a directory has on other directories
+# in a graphical way. The dependency relations are determined by the #include
 # relations between the files in the directories.
 
 DIRECTORY_GRAPH        = YES
 
-# The DOT_IMAGE_FORMAT tag can be used to set the image format of the images 
-# generated by dot. Possible values are png, jpg, or gif 
+# The DOT_IMAGE_FORMAT tag can be used to set the image format of the images
+# generated by dot. Possible values are png, jpg, or gif
 # If left blank png will be used.
 
 DOT_IMAGE_FORMAT       = png
 
-# The tag DOT_PATH can be used to specify the path where the dot tool can be 
+# The tag DOT_PATH can be used to specify the path where the dot tool can be
 # found. If left blank, it is assumed the dot tool can be found in the path.
 
-DOT_PATH               = 
+DOT_PATH               =
 
-# The DOTFILE_DIRS tag can be used to specify one or more directories that 
-# contain dot files that are included in the documentation (see the 
+# The DOTFILE_DIRS tag can be used to specify one or more directories that
+# contain dot files that are included in the documentation (see the
 # \dotfile command).
 
-DOTFILE_DIRS           = 
+DOTFILE_DIRS           =
 
-# The DOT_GRAPH_MAX_NODES tag can be used to set the maximum number of 
-# nodes that will be shown in the graph. If the number of nodes in a graph 
-# becomes larger than this value, doxygen will truncate the graph, which is 
-# visualized by representing a node as a red box. Note that doxygen if the 
-# number of direct children of the root node in a graph is already larger than 
-# DOT_GRAPH_MAX_NODES then the graph will not be shown at all. Also note 
+# The DOT_GRAPH_MAX_NODES tag can be used to set the maximum number of
+# nodes that will be shown in the graph. If the number of nodes in a graph
+# becomes larger than this value, doxygen will truncate the graph, which is
+# visualized by representing a node as a red box. Note that doxygen if the
+# number of direct children of the root node in a graph is already larger than
+# DOT_GRAPH_MAX_NODES then the graph will not be shown at all. Also note
 # that the size of a graph can be further restricted by MAX_DOT_GRAPH_DEPTH.
 
 DOT_GRAPH_MAX_NODES    = 50
 
-# The MAX_DOT_GRAPH_DEPTH tag can be used to set the maximum depth of the 
-# graphs generated by dot. A depth value of 3 means that only nodes reachable 
-# from the root by following a path via at most 3 edges will be shown. Nodes 
-# that lay further from the root node will be omitted. Note that setting this 
-# option to 1 or 2 may greatly reduce the computation time needed for large 
-# code bases. Also note that the size of a graph can be further restricted by 
+# The MAX_DOT_GRAPH_DEPTH tag can be used to set the maximum depth of the
+# graphs generated by dot. A depth value of 3 means that only nodes reachable
+# from the root by following a path via at most 3 edges will be shown. Nodes
+# that lay further from the root node will be omitted. Note that setting this
+# option to 1 or 2 may greatly reduce the computation time needed for large
+# code bases. Also note that the size of a graph can be further restricted by
 # DOT_GRAPH_MAX_NODES. Using a depth of 0 means no depth restriction.
 
 MAX_DOT_GRAPH_DEPTH    = 0
 
-# Set the DOT_TRANSPARENT tag to YES to generate images with a transparent 
-# background. This is disabled by default, because dot on Windows does not 
-# seem to support this out of the box. Warning: Depending on the platform used, 
-# enabling this option may lead to badly anti-aliased labels on the edges of 
+# Set the DOT_TRANSPARENT tag to YES to generate images with a transparent
+# background. This is disabled by default, because dot on Windows does not
+# seem to support this out of the box. Warning: Depending on the platform used,
+# enabling this option may lead to badly anti-aliased labels on the edges of
 # a graph (i.e. they become hard to read).
 
 DOT_TRANSPARENT        = NO
 
-# Set the DOT_MULTI_TARGETS tag to YES allow dot to generate multiple output 
-# files in one run (i.e. multiple -o and -T options on the command line). This 
-# makes dot run faster, but since only newer versions of dot (>1.8.10) 
+# Set the DOT_MULTI_TARGETS tag to YES allow dot to generate multiple output
+# files in one run (i.e. multiple -o and -T options on the command line). This
+# makes dot run faster, but since only newer versions of dot (>1.8.10)
 # support this, this feature is disabled by default.
 
 DOT_MULTI_TARGETS      = NO
 
-# If the GENERATE_LEGEND tag is set to YES (the default) Doxygen will 
-# generate a legend page explaining the meaning of the various boxes and 
+# If the GENERATE_LEGEND tag is set to YES (the default) Doxygen will
+# generate a legend page explaining the meaning of the various boxes and
 # arrows in the dot generated graphs.
 
 GENERATE_LEGEND        = YES
 
-# If the DOT_CLEANUP tag is set to YES (the default) Doxygen will 
-# remove the intermediate dot files that are used to generate 
+# If the DOT_CLEANUP tag is set to YES (the default) Doxygen will
+# remove the intermediate dot files that are used to generate
 # the various graphs.
 
 DOT_CLEANUP            = YES
@@ -1537,7 +1537,7 @@ DOT_CLEANUP            = YES
 # Options related to the search engine
 #---------------------------------------------------------------------------
 
-# The SEARCHENGINE tag specifies whether or not a search engine should be 
+# The SEARCHENGINE tag specifies whether or not a search engine should be
 # used. If set to NO the values of all tags below this one will be ignored.
 
 SEARCHENGINE           = NO

From 681761d875fa21807c6929c560d367d295d59388 Mon Sep 17 00:00:00 2001
From: Marc Zinnschlag <marc@zpages.de>
Date: Mon, 23 Aug 2010 18:32:26 +0200
Subject: [PATCH 13/32] more doxygen adjustments

---
 Docs/Doxyfile | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/Docs/Doxyfile b/Docs/Doxyfile
index 0c1b7bc21d..e2190a5066 100644
--- a/Docs/Doxyfile
+++ b/Docs/Doxyfile
@@ -1372,7 +1372,7 @@ HIDE_UNDOC_RELATIONS   = YES
 # toolkit from AT&T and Lucent Bell Labs. The other options in this section
 # have no effect if this option is set to NO (the default)
 
-HAVE_DOT               = NO
+HAVE_DOT               = YES
 
 # By default doxygen will write a font called FreeSans.ttf to the output
 # directory and reference it in all dot files that doxygen generates. This
@@ -1420,7 +1420,7 @@ GROUP_GRAPHS           = YES
 # collaboration diagrams in a style similar to the OMG's Unified Modeling
 # Language.
 
-UML_LOOK               = NO
+UML_LOOK               = YES
 
 # If set to YES, the inheritance and collaboration graphs will show the
 # relations between templates and their instances.

From d4bf916f1875cce6887bdd75216bc98da8714356 Mon Sep 17 00:00:00 2001
From: Marc Zinnschlag <marc@zpages.de>
Date: Sun, 29 Aug 2010 17:46:06 +0200
Subject: [PATCH 14/32] fixed uninitialized variable in engine

---
 apps/openmw/engine.cpp | 1 +
 1 file changed, 1 insertion(+)

diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp
index bcf2de40d7..bcb2d7f599 100644
--- a/apps/openmw/engine.cpp
+++ b/apps/openmw/engine.cpp
@@ -109,6 +109,7 @@ OMW::Engine::Engine()
   , mUseSound (true)
   , mScriptManager (0)
   , mScriptContext (0)
+  , mGuiManager (0)
 {
     MWClass::registerClasses();
 }

From a899a290c0d84f4ba9a500156261819763a3b6e6 Mon Sep 17 00:00:00 2001
From: Marc Zinnschlag <marc@zpages.de>
Date: Sun, 29 Aug 2010 23:40:59 +0200
Subject: [PATCH 15/32] modified code to avoid a warning on MSVC

---
 apps/openmw/mwscript/scriptmanager.cpp | 39 +++++++++++++-------------
 1 file changed, 19 insertions(+), 20 deletions(-)

diff --git a/apps/openmw/mwscript/scriptmanager.cpp b/apps/openmw/mwscript/scriptmanager.cpp
index 542bee1fba..727297a989 100644
--- a/apps/openmw/mwscript/scriptmanager.cpp
+++ b/apps/openmw/mwscript/scriptmanager.cpp
@@ -23,7 +23,7 @@ namespace MWScript
     : mErrorHandler (std::cerr), mStore (store), mVerbose (verbose),
       mCompilerContext (compilerContext), mParser (mErrorHandler, mCompilerContext)
     {}
-    
+
     bool ScriptManager::compile (const std::string& name)
     {
         mParser.reset();
@@ -32,22 +32,22 @@ namespace MWScript
         bool Success = true;
 
         if (const ESM::Script *script = mStore.scripts.find (name))
-        {             
+        {
             if (mVerbose)
                 std::cout << "compiling script: " << name << std::endl;
-            
+
             try
-            {        
+            {
                 std::istringstream input (script->scriptText);
-            
+
                 Compiler::Scanner scanner (mErrorHandler, input, mCompilerContext.getExtensions());
-            
+
                 scanner.scan (mParser);
-                
+
                 if (!mErrorHandler.isGood())
                     Success = false;
             }
-            catch (const std::exception& error)
+            catch (...)
             {
                 Success = false;
             }
@@ -59,20 +59,20 @@ namespace MWScript
                     << script->scriptText
                     << std::endl << std::endl;
             }
-            
+
             if (Success)
             {
                 std::vector<Interpreter::Type_Code> code;
                 mParser.getCode (code);
                 mScripts.insert (std::make_pair (name, code));
-                
+
                 // TODO sanity check on generated locals
-                
+
                 return true;
             }
         }
-        
-        return false;    
+
+        return false;
     }
 
     void ScriptManager::run (const std::string& name, Interpreter::Context& interpreterContext)
@@ -80,7 +80,7 @@ namespace MWScript
         // compile script
         std::map<std::string, std::vector<Interpreter::Type_Code> >::iterator iter =
             mScripts.find (name);
-            
+
         if (iter==mScripts.end())
         {
             if (!compile (name))
@@ -90,28 +90,27 @@ namespace MWScript
                 mScripts.insert (std::make_pair (name, empty));
                 return;
             }
-            
+
             iter = mScripts.find (name);
             assert (iter!=mScripts.end());
         }
-    
+
         // execute script
         if (!iter->second.empty())
             try
             {
                 Interpreter::Interpreter interpreter (interpreterContext);
                 installOpcodes (interpreter);
-                interpreter.run (&iter->second[0], iter->second.size());     
+                interpreter.run (&iter->second[0], iter->second.size());
             }
             catch (const std::exception& e)
             {
                 std::cerr << "exeution of script " << name << " failed." << std::endl;
-                    
+
                 if (mVerbose)
                     std::cerr << "(" << e.what() << ")" << std::endl;
-                    
+
                 iter->second.clear(); // don't execute again.
             }
     }
 }
-

From d955a0efc498fcdf2d3a35d2939aeff6ef59cec3 Mon Sep 17 00:00:00 2001
From: athile <athile.g@gmail.com>
Date: Mon, 30 Aug 2010 02:12:54 +0100
Subject: [PATCH 16/32] WIP Windows build

---
 .gitignore                             |  1 +
 CMakeLists.txt                         | 33 +++++++++++++++++++++++++-
 apps/openmw/mwworld/actionteleport.cpp |  2 +-
 3 files changed, 34 insertions(+), 2 deletions(-)

diff --git a/.gitignore b/.gitignore
index b8383fd517..774478e2b3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
 build
 *~
 Doxygen
+prebuilt
\ No newline at end of file
diff --git a/CMakeLists.txt b/CMakeLists.txt
index ca21824b6e..352f3c9507 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -8,6 +8,34 @@ option(USE_MPG123 "use mpg123 + libsndfile for sound" ON)
 # We probably support older versions than this.
 cmake_minimum_required(VERSION 2.6)
 
+
+#
+# Pre-built binaries being used?
+#
+IF(EXISTS "${CMAKE_SOURCE_DIR}/prebuilt/ogre_1_7_1")
+    message (STATUS "OpenMW pre-built binaries found.  Attempting to use pre-built binaries.")
+    
+    SET(ENV{OGRE_HOME} "${CMAKE_SOURCE_DIR}/prebuilt/ogre_1_7_1")
+    
+    SET(ENV{BOOST_ROOT} "${CMAKE_SOURCE_DIR}/prebuilt/boost_1_42_0")
+    set(Boost_USE_STATIC_LIBS   ON)
+    set(Boost_USE_MULTITHREADED ON)
+    set(ENV{BOOST_INCLUDEDIR} "${BOOST_ROOT}/include")
+    set(ENV{BOOST_LIBRARYDIR} "${BOOST_ROOT}/lib")
+    
+    set(ENV{FREETYPE_DIR} "${CMAKE_SOURCE_DIR}/prebuilt/freetype-2.3.5-1")
+    
+    set(USE_MPG123 OFF)
+    set(USE_AUDIERE ON)    
+    set(AUDIERE_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/prebuilt/audiere-1.9.4/include")
+    set(AUDIERE_LIBRARY "${CMAKE_SOURCE_DIR}/prebuilt/audiere-1.9.4/lib/audiere.lib")
+    
+    set(ENV{OPENALDIR} "${CMAKE_SOURCE_DIR}/prebuilt/OpenAL 1.1 SDK")
+    
+ELSE()
+    message (STATUS "OpenMW pre-built binaries not found.  Using standard locations.")
+ENDIF()
+
 # Add path for CMake scripts
 set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/)
 
@@ -166,6 +194,9 @@ if (WIN32)
 else (WIN32)
 set(PLATFORM_INCLUDE_DIR "")
 endif (WIN32)
+if (MSVC10)
+set(PLATFORM_INCLUDE_DIR "")
+endif()
 
 # Dependencies
 
@@ -180,10 +211,10 @@ include_directories("."
     ${CMAKE_HOME_DIRECTORY}/extern/caelum/include
     ${CMAKE_HOME_DIRECTORY}/extern/mygui_3.0.1/MyGUIEngine/include
     ${CMAKE_HOME_DIRECTORY}/extern/mygui_3.0.1/OgrePlatform/include
+    ${OPENAL_INCLUDE_DIR}
     ${LIBDIR}
 )
 
-
 link_directories(${Boost_LIBRARY_DIRS} ${OGRE_LIB_DIR})
 
 add_subdirectory( extern/caelum )
diff --git a/apps/openmw/mwworld/actionteleport.cpp b/apps/openmw/mwworld/actionteleport.cpp
index 4edc02c30a..f757b70be6 100644
--- a/apps/openmw/mwworld/actionteleport.cpp
+++ b/apps/openmw/mwworld/actionteleport.cpp
@@ -11,7 +11,7 @@ namespace MWWorld
     : mCellName (cellName), mPosition (position)
     {}
 
-    void ActionTeleportPlayer::ActionTeleportPlayer::execute (Environment& environment)
+    void ActionTeleportPlayer::execute (Environment& environment)
     {
         environment.mWorld->changeCell (mCellName, mPosition);
     }

From 72fbeb9b9a00db45df3748eca3806c1d1c1b053a Mon Sep 17 00:00:00 2001
From: athile <athile.g@gmail.com>
Date: Mon, 30 Aug 2010 02:41:09 +0100
Subject: [PATCH 17/32] Mangle update

---
 libs/mangle | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libs/mangle b/libs/mangle
index 3324f6494c..6ff6d7556c 160000
--- a/libs/mangle
+++ b/libs/mangle
@@ -1 +1 @@
-Subproject commit 3324f6494c021e3dc69cd76ace5ff25a52e4bcce
+Subproject commit 6ff6d7556c760bfb784249b63c5610e53f891a9e

From 9e2129c4b3b68947b9b0727bc2650bbc1155e3e6 Mon Sep 17 00:00:00 2001
From: athile <athile.g@gmail.com>
Date: Mon, 30 Aug 2010 10:34:13 +0100
Subject: [PATCH 18/32] WIP Windows build

---
 apps/openmw/CMakeLists.txt                     | 2 +-
 extern/mygui_3.0.1/OgrePlatform/CMakeLists.txt | 4 ++--
 libs/mangle                                    | 2 +-
 libs/platform/stdint.h                         | 8 ++++++++
 4 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt
index b5948aaeac..c3ba0b22ba 100644
--- a/apps/openmw/CMakeLists.txt
+++ b/apps/openmw/CMakeLists.txt
@@ -201,7 +201,7 @@ target_link_libraries(openmw
   ${SOUND_INPUT_LIBRARY}
   caelum
   MyGUIEngine
-  MyGUI.OgrePlatform
+  MyGUIOgrePlatform
 )
 
 if (APPLE)
diff --git a/extern/mygui_3.0.1/OgrePlatform/CMakeLists.txt b/extern/mygui_3.0.1/OgrePlatform/CMakeLists.txt
index 38c5c714a7..2fa38a242d 100644
--- a/extern/mygui_3.0.1/OgrePlatform/CMakeLists.txt
+++ b/extern/mygui_3.0.1/OgrePlatform/CMakeLists.txt
@@ -4,6 +4,6 @@ include_directories(
  ${OGRE_INCLUDE_DIR}
 )
 include(MyGUI.OgrePlatform.list)
-add_library(MyGUI.OgrePlatform ${HEADER_FILES} ${SOURCE_FILES})
-target_link_libraries(MyGUI.OgrePlatform ${OGRE_LIBRARIES})
+add_library(MyGUIOgrePlatform ${HEADER_FILES} ${SOURCE_FILES})
+target_link_libraries(MyGUIOgrePlatform ${OGRE_LIBRARIES})
 link_directories(${OGRE_LIB_DIR})
diff --git a/libs/mangle b/libs/mangle
index 6ff6d7556c..4a31f4e0f8 160000
--- a/libs/mangle
+++ b/libs/mangle
@@ -1 +1 @@
-Subproject commit 6ff6d7556c760bfb784249b63c5610e53f891a9e
+Subproject commit 4a31f4e0f874b6e0715b7c195a44f5a3975fdb7e
diff --git a/libs/platform/stdint.h b/libs/platform/stdint.h
index 499590da78..00af741b1e 100644
--- a/libs/platform/stdint.h
+++ b/libs/platform/stdint.h
@@ -2,6 +2,12 @@
 #ifndef _STDINT_WRAPPER_H
 #define _STDINT_WRAPPER_H
 
+#if (_MSC_VER >= 1600)
+
+#include <cstdint>
+
+#else
+
 #include <boost/cstdint.hpp>
 
 // Pull the boost names into the global namespace for convenience
@@ -11,3 +17,5 @@ using boost::int64_t;
 using boost::uint64_t;
 
 #endif
+
+#endif

From 459dd82896db01c81ffda318f49e8c00c21c2f56 Mon Sep 17 00:00:00 2001
From: Marc Zinnschlag <marc@zpages.de>
Date: Mon, 30 Aug 2010 11:56:55 +0200
Subject: [PATCH 19/32] implemented locking/unlocking for doors (can not be
 invoked by user interaction yet)

---
 apps/openmw/mwclass/door.cpp  | 16 ++++++++++++++++
 apps/openmw/mwclass/door.hpp  |  6 ++++++
 apps/openmw/mwworld/class.cpp | 10 ++++++++++
 apps/openmw/mwworld/class.hpp |  6 ++++++
 4 files changed, 38 insertions(+)

diff --git a/apps/openmw/mwclass/door.cpp b/apps/openmw/mwclass/door.cpp
index 12aeb9a5b9..d15a01e9f3 100644
--- a/apps/openmw/mwclass/door.cpp
+++ b/apps/openmw/mwclass/door.cpp
@@ -50,6 +50,9 @@ namespace MWClass
         ESMS::LiveCellRef<ESM::Door, MWWorld::RefData> *ref =
             ptr.get<ESM::Door>();
 
+        // TODO check lock
+        // TODO check trap
+
         if (ref->ref.teleport)
         {
             // teleport door
@@ -74,6 +77,19 @@ namespace MWClass
         }
     }
 
+    void Door::lock (const MWWorld::Ptr& ptr, int lockLevel) const
+    {
+        if (lockLevel<0)
+            lockLevel = 0;
+
+        ptr.getCellRef().lockLevel = lockLevel;
+    }
+
+    void Door::unlock (const MWWorld::Ptr& ptr) const
+    {
+        ptr.getCellRef().lockLevel = 0;
+    }
+
     std::string Door::getScript (const MWWorld::Ptr& ptr) const
     {
         ESMS::LiveCellRef<ESM::Door, MWWorld::RefData> *ref =
diff --git a/apps/openmw/mwclass/door.hpp b/apps/openmw/mwclass/door.hpp
index b6bf8808e5..aecb117d36 100644
--- a/apps/openmw/mwclass/door.hpp
+++ b/apps/openmw/mwclass/door.hpp
@@ -21,6 +21,12 @@ namespace MWClass
                 const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const;
             ///< Generate action for activation
 
+            virtual void lock (const MWWorld::Ptr& ptr, int lockLevel) const;
+            ///< Lock object
+
+            virtual void unlock (const MWWorld::Ptr& ptr) const;
+            ///< Unlock object
+
             virtual std::string getScript (const MWWorld::Ptr& ptr) const;
             ///< Return name of the script attached to ptr
 
diff --git a/apps/openmw/mwworld/class.cpp b/apps/openmw/mwworld/class.cpp
index e21e4908c1..1e9f25bbd1 100644
--- a/apps/openmw/mwworld/class.cpp
+++ b/apps/openmw/mwworld/class.cpp
@@ -77,6 +77,16 @@ namespace MWWorld
         throw std::runtime_error ("class does not support inserting into a container");
     }
 
+    void Class::lock (const Ptr& ptr, int lockLevel) const
+    {
+        throw std::runtime_error ("class does not support locking");
+    }
+
+    void Class::unlock (const Ptr& ptr) const
+    {
+        throw std::runtime_error ("class does not support unlocking");
+    }
+
     std::string Class::getScript (const Ptr& ptr) const
     {
         return "";
diff --git a/apps/openmw/mwworld/class.hpp b/apps/openmw/mwworld/class.hpp
index c3f4bff14d..5153d74684 100644
--- a/apps/openmw/mwworld/class.hpp
+++ b/apps/openmw/mwworld/class.hpp
@@ -98,6 +98,12 @@ namespace MWWorld
             ///< Insert into a container or throw an exception, if class does not support inserting into
             /// a container.
 
+            virtual void lock (const Ptr& ptr, int lockLevel) const;
+            ///< Lock object (default implementation: throw an exception)
+
+            virtual void unlock (const Ptr& ptr) const;
+            ///< Unlock object (default implementation: throw an exception)
+
             virtual std::string getScript (const Ptr& ptr) const;
             ///< Return name of the script attached to ptr (default implementation: return an empty
             /// string).

From 61c4fa0630225201c4f1649f96e6086cb0afe4b1 Mon Sep 17 00:00:00 2001
From: Marc Zinnschlag <marc@zpages.de>
Date: Mon, 30 Aug 2010 12:02:47 +0200
Subject: [PATCH 20/32] blocked using of locked doors (keys are not considered
 yet)

---
 apps/openmw/mwclass/door.cpp | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/apps/openmw/mwclass/door.cpp b/apps/openmw/mwclass/door.cpp
index d15a01e9f3..c22b8005e4 100644
--- a/apps/openmw/mwclass/door.cpp
+++ b/apps/openmw/mwclass/door.cpp
@@ -15,6 +15,8 @@
 
 #include "../mwrender/cellimp.hpp"
 
+#include <iostream>
+
 namespace MWClass
 {
     void Door::insertObj (const MWWorld::Ptr& ptr, MWRender::CellRenderImp& cellRender,
@@ -50,7 +52,14 @@ namespace MWClass
         ESMS::LiveCellRef<ESM::Door, MWWorld::RefData> *ref =
             ptr.get<ESM::Door>();
 
-        // TODO check lock
+        if (ptr.getCellRef().lockLevel>0)
+        {
+            // TODO check for key
+            // TODO report failure to player (message, sound?). Look up behaviour of original MW.
+            std::cout << "Locked!" << std::endl;
+            return boost::shared_ptr<MWWorld::Action> (new MWWorld::NullAction);
+        }
+
         // TODO check trap
 
         if (ref->ref.teleport)

From 336fb1636c7fca44f6b1b371e16125b87bf27651 Mon Sep 17 00:00:00 2001
From: athile <athile.g@gmail.com>
Date: Mon, 30 Aug 2010 11:19:45 +0100
Subject: [PATCH 21/32] Windows fixes

---
 CMakeLists.txt                       | 17 +++++++++--------
 apps/openmw/mwgui/window_manager.cpp |  4 ++--
 libs/mangle                          |  2 +-
 libs/openengine                      |  2 +-
 4 files changed, 13 insertions(+), 12 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 352f3c9507..beed450848 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -12,25 +12,26 @@ cmake_minimum_required(VERSION 2.6)
 #
 # Pre-built binaries being used?
 #
-IF(EXISTS "${CMAKE_SOURCE_DIR}/prebuilt/ogre_1_7_1")
-    message (STATUS "OpenMW pre-built binaries found.  Attempting to use pre-built binaries.")
+IF(EXISTS "${CMAKE_SOURCE_DIR}/prebuilt/vc100-mt-gd/ogre_1_7_1")
+    set(PREBUILT_DIR "${CMAKE_SOURCE_DIR}/prebuilt/vc100-mt-gd")
+    message (STATUS "OpenMW pre-built binaries found at ${PREBUILT_DIR}.")
     
-    SET(ENV{OGRE_HOME} "${CMAKE_SOURCE_DIR}/prebuilt/ogre_1_7_1")
+    SET(ENV{OGRE_HOME} "${PREBUILT_DIR}/ogre_1_7_1")
     
-    SET(ENV{BOOST_ROOT} "${CMAKE_SOURCE_DIR}/prebuilt/boost_1_42_0")
+    SET(ENV{BOOST_ROOT} "${PREBUILT_DIR}/boost_1_42_0")
     set(Boost_USE_STATIC_LIBS   ON)
     set(Boost_USE_MULTITHREADED ON)
     set(ENV{BOOST_INCLUDEDIR} "${BOOST_ROOT}/include")
     set(ENV{BOOST_LIBRARYDIR} "${BOOST_ROOT}/lib")
     
-    set(ENV{FREETYPE_DIR} "${CMAKE_SOURCE_DIR}/prebuilt/freetype-2.3.5-1")
+    set(ENV{FREETYPE_DIR} "${PREBUILT_DIR}/freetype-2.3.5-1")
     
     set(USE_MPG123 OFF)
     set(USE_AUDIERE ON)    
-    set(AUDIERE_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/prebuilt/audiere-1.9.4/include")
-    set(AUDIERE_LIBRARY "${CMAKE_SOURCE_DIR}/prebuilt/audiere-1.9.4/lib/audiere.lib")
+    set(AUDIERE_INCLUDE_DIR "${PREBUILT_DIR}/audiere-1.9.4/include")
+    set(AUDIERE_LIBRARY "${PREBUILT_DIR}/audiere-1.9.4/lib/audiere.lib")
     
-    set(ENV{OPENALDIR} "${CMAKE_SOURCE_DIR}/prebuilt/OpenAL 1.1 SDK")
+    set(ENV{OPENALDIR} "${PREBUILT_DIR}/OpenAL 1.1 SDK")
     
 ELSE()
     message (STATUS "OpenMW pre-built binaries not found.  Using standard locations.")
diff --git a/apps/openmw/mwgui/window_manager.cpp b/apps/openmw/mwgui/window_manager.cpp
index 726cd5bd8d..74adfe2063 100644
--- a/apps/openmw/mwgui/window_manager.cpp
+++ b/apps/openmw/mwgui/window_manager.cpp
@@ -13,8 +13,8 @@ WindowManager::WindowManager(MyGUI::Gui *_gui, MWWorld::Environment& environment
 {
   // Get size info from the Gui object
   assert(gui);
-  int w = gui->getViewWidth();
-  int h = gui->getViewHeight();
+  int w = gui->getViewSize().width;
+  int h = gui->getViewSize().height;
 
   hud = new HUD(w,h);
   menu = new MainMenu(w,h);
diff --git a/libs/mangle b/libs/mangle
index 4a31f4e0f8..2407f21c47 160000
--- a/libs/mangle
+++ b/libs/mangle
@@ -1 +1 @@
-Subproject commit 4a31f4e0f874b6e0715b7c195a44f5a3975fdb7e
+Subproject commit 2407f21c47abe218b9347df0fc9e8e9aebc02e3f
diff --git a/libs/openengine b/libs/openengine
index 2e2f8e9725..85cb75631b 160000
--- a/libs/openengine
+++ b/libs/openengine
@@ -1 +1 @@
-Subproject commit 2e2f8e9725fd1a27a82d0ad5c6c0e296e715eb60
+Subproject commit 85cb75631b1efbde312e65937ad059754fb835b6

From 147dd57162bc3aafb05b7cd431a6835322960663 Mon Sep 17 00:00:00 2001
From: Marc Zinnschlag <marc@zpages.de>
Date: Mon, 30 Aug 2010 12:30:34 +0200
Subject: [PATCH 22/32] added Lock and Unlock instructions

---
 apps/openmw/mwscript/docs/vmformat.txt  |  8 ++-
 apps/openmw/mwscript/miscextensions.cpp | 95 +++++++++++++++++++++++++
 2 files changed, 101 insertions(+), 2 deletions(-)

diff --git a/apps/openmw/mwscript/docs/vmformat.txt b/apps/openmw/mwscript/docs/vmformat.txt
index 47f883c8a9..0556450e64 100644
--- a/apps/openmw/mwscript/docs/vmformat.txt
+++ b/apps/openmw/mwscript/docs/vmformat.txt
@@ -17,7 +17,9 @@ op 0x20000: AiTravel
 op 0x20001: AiTravel, explicit reference
 op 0x20002: AiEscort
 op 0x20003: AiEscort, explicit reference
-opcodes 0x20004-0x3ffff unused
+op 0x20004: Lock
+op 0x20005: Lock, explicit reference
+opcodes 0x20006-0x3ffff unused
 
 Segment 4:
 (not implemented yet)
@@ -90,4 +92,6 @@ op 0x200007c: GetAiPackageDone
 op 0x200007d: GetAiPackageDone, explicit reference
 op 0x200007e-0x2000084: Enable Controls
 op 0x2000085-0x200008b: Disable Controls
-opcodes 0x200008c-0x3ffffff unused
+op 0x200008c: Unlock
+op 0x200008d: Unlock, explicit reference
+opcodes 0x200008e-0x3ffffff unused
diff --git a/apps/openmw/mwscript/miscextensions.cpp b/apps/openmw/mwscript/miscextensions.cpp
index 1ecfd0c57b..9cb65dcd7f 100644
--- a/apps/openmw/mwscript/miscextensions.cpp
+++ b/apps/openmw/mwscript/miscextensions.cpp
@@ -9,6 +9,8 @@
 
 #include "interpretercontext.hpp"
 
+#include "../mwworld/class.hpp"
+
 namespace MWScript
 {
     namespace Misc
@@ -53,15 +55,104 @@ namespace MWScript
                 }
         };
 
+        class OpLock : public Interpreter::Opcode1
+        {
+            public:
+
+                virtual void execute (Interpreter::Runtime& runtime, unsigned int arg0)
+                {
+                    InterpreterContext& context =
+                        static_cast<InterpreterContext&> (runtime.getContext());
+
+                    MWWorld::Ptr ptr = context.getReference();
+
+                    Interpreter::Type_Integer lockLevel = 100;
+
+                    if (arg0==1)
+                    {
+                        lockLevel = runtime[0].mInteger;
+                        runtime.pop();
+                    }
+
+                    MWWorld::Class::get (ptr).lock (ptr, lockLevel);
+                }
+        };
+
+        class OpLockExplicit : public Interpreter::Opcode1
+        {
+            public:
+
+                virtual void execute (Interpreter::Runtime& runtime, unsigned int arg0)
+                {
+                    InterpreterContext& context =
+                        static_cast<InterpreterContext&> (runtime.getContext());
+
+                    std::string id = runtime.getStringLiteral (runtime[0].mInteger);
+                    runtime.pop();
+
+                    MWWorld::Ptr ptr = context.getWorld().getPtr (id, false);
+
+                    Interpreter::Type_Integer lockLevel = 100;
+
+                    if (arg0==1)
+                    {
+                        lockLevel = runtime[0].mInteger;
+                        runtime.pop();
+                    }
+
+                    MWWorld::Class::get (ptr).lock (ptr, lockLevel);
+                }
+        };
+
+        class OpUnlock : public Interpreter::Opcode0
+        {
+            public:
+
+                virtual void execute (Interpreter::Runtime& runtime)
+                {
+                    InterpreterContext& context =
+                        static_cast<InterpreterContext&> (runtime.getContext());
+
+                    MWWorld::Ptr ptr = context.getReference();
+
+                    MWWorld::Class::get (ptr).unlock (ptr);
+                }
+        };
+
+        class OpUnlockExplicit : public Interpreter::Opcode0
+        {
+            public:
+
+                virtual void execute (Interpreter::Runtime& runtime)
+                {
+                    InterpreterContext& context =
+                        static_cast<InterpreterContext&> (runtime.getContext());
+
+                    std::string id = runtime.getStringLiteral (runtime[0].mInteger);
+                    runtime.pop();
+
+                    MWWorld::Ptr ptr = context.getWorld().getPtr (id, false);
+
+                    MWWorld::Class::get (ptr).unlock (ptr);
+                }
+        };
+
+
         const int opcodeXBox = 0x200000c;
         const int opcodeOnActivate = 0x200000d;
         const int opcodeActivate = 0x2000075;
+        const int opcodeLock = 0x20004;
+        const int opcodeLockExplicit = 0x20005;
+        const int opcodeUnlock = 0x200008c;
+        const int opcodeUnlockExplicit = 0x200008d;
 
         void registerExtensions (Compiler::Extensions& extensions)
         {
             extensions.registerFunction ("xbox", 'l', "", opcodeXBox);
             extensions.registerFunction ("onactivate", 'l', "", opcodeOnActivate);
             extensions.registerInstruction ("activate", "", opcodeActivate);
+            extensions.registerInstruction ("lock", "/l", opcodeLock, opcodeLockExplicit);
+            extensions.registerInstruction ("unlock", "", opcodeUnlock, opcodeUnlockExplicit);
         }
 
         void installOpcodes (Interpreter::Interpreter& interpreter)
@@ -69,6 +160,10 @@ namespace MWScript
             interpreter.installSegment5 (opcodeXBox, new OpXBox);
             interpreter.installSegment5 (opcodeOnActivate, new OpOnActivate);
             interpreter.installSegment5 (opcodeActivate, new OpActivate);
+            interpreter.installSegment3 (opcodeLock, new OpLock);
+            interpreter.installSegment3 (opcodeLockExplicit, new OpLockExplicit);
+            interpreter.installSegment5 (opcodeUnlock, new OpUnlock);
+            interpreter.installSegment5 (opcodeUnlockExplicit, new OpUnlockExplicit);
         }
     }
 }

From 044bf0ab4871b9631eb3ecf0284eb50518fcf20a Mon Sep 17 00:00:00 2001
From: Marc Zinnschlag <marc@zpages.de>
Date: Mon, 30 Aug 2010 14:44:23 +0200
Subject: [PATCH 23/32] fixed parsing explicit references in the body of
 control structures

---
 components/compiler/controlparser.cpp | 14 ++++++++++++++
 components/compiler/controlparser.hpp | 24 ++++++++++++++----------
 components/compiler/lineparser.cpp    | 14 +++++++-------
 3 files changed, 35 insertions(+), 17 deletions(-)

diff --git a/components/compiler/controlparser.cpp b/components/compiler/controlparser.cpp
index 2f5d5c4b60..c255154b5a 100644
--- a/components/compiler/controlparser.cpp
+++ b/components/compiler/controlparser.cpp
@@ -172,6 +172,20 @@ namespace Compiler
         std::copy (mCode.begin(), mCode.end(), std::back_inserter (code));
     }
 
+    bool ControlParser::parseName (const std::string& name, const TokenLoc& loc, Scanner& scanner)
+    {
+        if (mState==IfBodyState || mState==IfElseifBodyState || mState==IfElseBodyState ||
+            mState==WhileBodyState)
+        {
+            scanner.putbackName (name, loc);
+            mLineParser.reset();
+            scanner.scan (mLineParser);
+            return true;
+        }
+
+        return Parser::parseName (name, loc, scanner);
+    }
+
     bool ControlParser::parseKeyword (int keyword, const TokenLoc& loc, Scanner& scanner)
     {
         if (mState==StartState)
diff --git a/components/compiler/controlparser.hpp b/components/compiler/controlparser.hpp
index 17b3137c71..50fd2d1f9e 100644
--- a/components/compiler/controlparser.hpp
+++ b/components/compiler/controlparser.hpp
@@ -13,9 +13,9 @@ namespace Compiler
 {
     class Locals;
     class Literals;
-    
+
     // Control structure parser
-    
+
     class ControlParser : public Parser
     {
             enum State
@@ -28,31 +28,36 @@ namespace Compiler
                 WhileEndState, WhileBodyState,
                 WhileEndwhileState
             };
-            
+
             typedef std::vector<Interpreter::Type_Code> Codes;
             typedef std::vector<std::pair<Codes, Codes> > IfCodes;
-            
-            Locals& mLocals;  
-            Literals& mLiterals;    
+
+            Locals& mLocals;
+            Literals& mLiterals;
             Codes mCode;
             Codes mCodeBlock;
             IfCodes mIfCode; // condition, body
             LineParser mLineParser;
             ExprParser mExprParser;
             State mState;
-                
+
             bool parseIfBody (int keyword, const TokenLoc& loc, Scanner& scanner);
 
             bool parseWhileBody (int keyword, const TokenLoc& loc, Scanner& scanner);
-                
+
         public:
-        
+
             ControlParser (ErrorHandler& errorHandler, Context& context, Locals& locals,
                 Literals& literals);
 
             void appendCode (std::vector<Interpreter::Type_Code>& code) const;
             ///< store generated code in \æ code.
 
+            virtual bool parseName (const std::string& name, const TokenLoc& loc,
+                Scanner& scanner);
+            ///< Handle a name token.
+            /// \return fetch another token?
+
             virtual bool parseKeyword (int keyword, const TokenLoc& loc, Scanner& scanner);
             ///< Handle a keyword token.
             /// \return fetch another token?
@@ -67,4 +72,3 @@ namespace Compiler
 }
 
 #endif
-
diff --git a/components/compiler/lineparser.cpp b/components/compiler/lineparser.cpp
index 3f80d671eb..5462f77886 100644
--- a/components/compiler/lineparser.cpp
+++ b/components/compiler/lineparser.cpp
@@ -183,6 +183,13 @@ namespace Compiler
             return true;
         }
 
+        if (mState==BeginState && getContext().isId (name))
+        {
+            mState = PotentialExplicitState;
+            mExplicit = toLower (name);
+            return true;
+        }
+
         if (mState==BeginState && mAllowExpression)
         {
             std::string name2 = toLower (name);
@@ -206,13 +213,6 @@ namespace Compiler
             }
         }
 
-        if (mState==BeginState && getContext().isId (name))
-        {
-            mState = PotentialExplicitState;
-            mExplicit = toLower (name);
-            return true;
-        }
-
         return Parser::parseName (name, loc, scanner);
     }
 

From e123fc1107bcee5171d83d515c0af913d15b696c Mon Sep 17 00:00:00 2001
From: Nicolay Korslund <korslund@gmail.com>
Date: Thu, 2 Sep 2010 12:35:53 +0200
Subject: [PATCH 24/32] OpenEngine update (fixed crash bug)

---
 libs/openengine | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libs/openengine b/libs/openengine
index 2e2f8e9725..b486f12a5f 160000
--- a/libs/openengine
+++ b/libs/openengine
@@ -1 +1 @@
-Subproject commit 2e2f8e9725fd1a27a82d0ad5c6c0e296e715eb60
+Subproject commit b486f12a5f1126457f375a5c7170164d7729cce5

From ca13c092092835692bb312b4f3478aa96bd568ee Mon Sep 17 00:00:00 2001
From: Nicolay Korslund <korslund@gmail.com>
Date: Thu, 2 Sep 2010 12:53:35 +0200
Subject: [PATCH 25/32] Merged in athile's changes to mangle and openengine

---
 libs/mangle     | 2 +-
 libs/openengine | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/libs/mangle b/libs/mangle
index 3324f6494c..2407f21c47 160000
--- a/libs/mangle
+++ b/libs/mangle
@@ -1 +1 @@
-Subproject commit 3324f6494c021e3dc69cd76ace5ff25a52e4bcce
+Subproject commit 2407f21c47abe218b9347df0fc9e8e9aebc02e3f
diff --git a/libs/openengine b/libs/openengine
index b486f12a5f..377e7d71ce 160000
--- a/libs/openengine
+++ b/libs/openengine
@@ -1 +1 @@
-Subproject commit b486f12a5f1126457f375a5c7170164d7729cce5
+Subproject commit 377e7d71ceea5a1ca166b8df9a03a5b68df83bc5

From d32563063b3b0f0ddf387a29e69a1fb250084970 Mon Sep 17 00:00:00 2001
From: Nicolay Korslund <korslund@gmail.com>
Date: Thu, 2 Sep 2010 14:12:48 +0200
Subject: [PATCH 26/32] Alternative fix to mesh crash bug

---
 components/nifogre/ogre_nif_loader.cpp | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/components/nifogre/ogre_nif_loader.cpp b/components/nifogre/ogre_nif_loader.cpp
index 5053fbd7d5..4c0277f898 100644
--- a/components/nifogre/ogre_nif_loader.cpp
+++ b/components/nifogre/ogre_nif_loader.cpp
@@ -767,14 +767,20 @@ void NIFLoader::handleNode(Nif::Node *node, int flags,
 
         if (!skel.isNull())     //if there is a skeleton
         {
-            bone = skel->createBone(node->name.toString());
+            std::string name = node->name.toString();
+            // Quick-n-dirty workaround for the fact that several
+            // bones may have the same name.
+            if(!skel->hasBone(name))
+            {
+                bone = skel->createBone(name);
 
-            if (parentBone)
-                parentBone->addChild(bone);
+                if (parentBone)
+                  parentBone->addChild(bone);
 
-            bone->setInheritOrientation(true);
-            bone->setPosition(convertVector3(node->trafo->pos));
-            bone->setOrientation(convertRotation(node->trafo->rotation));
+                bone->setInheritOrientation(true);
+                bone->setPosition(convertVector3(node->trafo->pos));
+                bone->setOrientation(convertRotation(node->trafo->rotation));
+            }
         }
     }
 

From c5d3a40fdefa3766f1fb96eb31c2f866d51ac291 Mon Sep 17 00:00:00 2001
From: Nicolay Korslund <korslund@gmail.com>
Date: Thu, 2 Sep 2010 14:57:26 +0200
Subject: [PATCH 27/32] Fixed ESM bug (quest records).

---
 apps/esmtool/CMakeLists.txt  |   1 +
 components/esm/load_impl.cpp | 109 +++++++++++++++++++++++++++++++++++
 components/esm/loadinfo.hpp  | 109 +----------------------------------
 3 files changed, 111 insertions(+), 108 deletions(-)

diff --git a/apps/esmtool/CMakeLists.txt b/apps/esmtool/CMakeLists.txt
index 5b2f846e20..583f1fabd1 100644
--- a/apps/esmtool/CMakeLists.txt
+++ b/apps/esmtool/CMakeLists.txt
@@ -10,6 +10,7 @@ add_executable(esmtool
   ${ESMTOOL}
   ${MISC} ${MISC_HEADER}
   ${TO_UTF8}
+  ${ESM}
 )
 
 target_link_libraries(esmtool
diff --git a/components/esm/load_impl.cpp b/components/esm/load_impl.cpp
index 28ae402ded..8857c1ae80 100644
--- a/components/esm/load_impl.cpp
+++ b/components/esm/load_impl.cpp
@@ -45,4 +45,113 @@ namespace ESM
 
     esm.skipRecord();
   }
+
+  void DialInfo::load(ESMReader &esm)
+  {
+    id = esm.getHNString("INAM");
+    prev = esm.getHNString("PNAM");
+    next = esm.getHNString("NNAM");
+
+    // Not present if deleted
+    if(esm.isNextSub("DATA"))
+      esm.getHT(data, 12);
+
+    // What follows is somewhat spaghetti-ish, but it's worth if for
+    // an extra speedup. INFO is by far the most common record type.
+
+    // subName is a reference to the original, so it changes whenever
+    // a new sub name is read. esm.isEmptyOrGetName() will get the
+    // next name for us, or return true if there are no more records.
+    esm.getSubName();
+    const NAME &subName = esm.retSubName();
+
+    if(subName.val == REC_ONAM)
+      {
+        actor = esm.getHString();
+	if(esm.isEmptyOrGetName()) return;
+      }
+    if(subName.val == REC_RNAM)
+      {
+        race = esm.getHString();
+	if(esm.isEmptyOrGetName()) return;
+      }
+    if(subName.val == REC_CNAM)
+      {
+        clas = esm.getHString();
+	if(esm.isEmptyOrGetName()) return;
+      }
+
+    factionLess = false;
+    if(subName.val == REC_FNAM)
+      {
+        npcFaction = esm.getHString();
+	if(npcFaction == "FFFF") factionLess = true;
+	if(esm.isEmptyOrGetName()) return;
+      }
+    if(subName.val == REC_ANAM)
+      {
+	cell = esm.getHString();
+	if(esm.isEmptyOrGetName()) return;
+      }
+    if(subName.val == REC_DNAM)
+      {
+        pcFaction = esm.getHString();
+	if(esm.isEmptyOrGetName()) return;
+      }
+    if(subName.val == REC_SNAM)
+      {
+        sound = esm.getHString();
+	if(esm.isEmptyOrGetName()) return;
+      }
+    if(subName.val == REC_NAME)
+      {
+	response = esm.getHString();
+	if(esm.isEmptyOrGetName()) return;
+      }
+
+    while(subName.val == REC_SCVR)
+      {
+        SelectStruct ss;
+
+        ss.selectRule = esm.getHString();
+        esm.isEmptyOrGetName();
+
+        if(subName.val == REC_INTV)
+          {
+            ss.type = VT_Int;
+            esm.getHT(ss.i);
+          }
+        else if(subName.val == REC_FLTV)
+          {
+            ss.type = VT_Float;
+            esm.getHT(ss.f);
+          }
+        else
+          esm.fail("INFO.SCVR must precede INTV or FLTV, not "
+		   + subName.toString());
+
+        selects.push_back(ss);
+
+	if(esm.isEmptyOrGetName()) return;
+      }
+
+    if(subName.val == REC_BNAM)
+      {
+	resultScript = esm.getHString();
+	if(esm.isEmptyOrGetName()) return;
+      }
+
+    questStatus = QS_None;
+
+    if     (subName.val == REC_QSTN) questStatus = QS_Name;
+    else if(subName.val == REC_QSTF) questStatus = QS_Finished;
+    else if(subName.val == REC_QSTR) questStatus = QS_Restart;
+    else if(subName.val == REC_DELE) questStatus = QS_Deleted;
+    else
+      esm.fail("Don't know what to do with " + subName.toString() + " in INFO " + id);
+
+    if(questStatus != QS_None)
+      // Skip rest of record
+      esm.skipRecord();
+  }
 }
diff --git a/components/esm/loadinfo.hpp b/components/esm/loadinfo.hpp
index 787e6424ec..480deda737 100644
--- a/components/esm/loadinfo.hpp
+++ b/components/esm/loadinfo.hpp
@@ -96,114 +96,7 @@ struct DialInfo
       REC_DELE = 0x454c4544
     };
 
-  void load(ESMReader &esm)
-  {
-    id = esm.getHNString("INAM");
-    prev = esm.getHNString("PNAM");
-    next = esm.getHNString("NNAM");
-
-    // Not present if deleted
-    if(esm.isNextSub("DATA"))
-      esm.getHT(data, 12);
-
-    // What follows is somewhat spaghetti-ish, but it's worth if for
-    // an extra speedup. INFO is by far the most common record type.
-
-    // subName is a reference to the original, so it changes whenever
-    // a new sub name is read. esm.isEmptyOrGetName() will get the
-    // next name for us, or return true if there are no more records.
-    esm.getSubName();
-    const NAME &subName = esm.retSubName();
-
-    if(subName.val == REC_ONAM)
-      {
-        actor = esm.getHString();
-	if(esm.isEmptyOrGetName()) return;
-      }
-    if(subName.val == REC_RNAM)
-      {
-        race = esm.getHString();
-	if(esm.isEmptyOrGetName()) return;
-      }
-    if(subName.val == REC_CNAM)
-      {
-        clas = esm.getHString();
-	if(esm.isEmptyOrGetName()) return;
-      }
-
-    factionLess = false;
-    if(subName.val == REC_FNAM)
-      {
-        npcFaction = esm.getHString();
-	if(npcFaction == "FFFF") factionLess = true;
-	if(esm.isEmptyOrGetName()) return;
-      }
-    if(subName.val == REC_ANAM)
-      {
-	cell = esm.getHString();
-	if(esm.isEmptyOrGetName()) return;
-      }
-    if(subName.val == REC_DNAM)
-      {
-        pcFaction = esm.getHString();
-	if(esm.isEmptyOrGetName()) return;
-      }
-    if(subName.val == REC_SNAM)
-      {
-        sound = esm.getHString();
-	if(esm.isEmptyOrGetName()) return;
-      }
-    if(subName.val == REC_NAME)
-      {
-	response = esm.getHString();
-	if(esm.isEmptyOrGetName()) return;
-      }
-
-    while(subName.val == REC_SCVR)
-      {
-        SelectStruct ss;
-
-        ss.selectRule = esm.getHString();
-        esm.isEmptyOrGetName();
-
-        if(subName.val == REC_INTV)
-          {
-            ss.type = VT_Int;
-            esm.getHT(ss.i);
-          }
-        else if(subName.val == REC_FLTV)
-          {
-            ss.type = VT_Float;
-            esm.getHT(ss.f);
-          }
-        else 
-          esm.fail("INFO.SCVR must precede INTV or FLTV, not "
-		   + subName.toString());
-
-        selects.push_back(ss);
-
-	if(esm.isEmptyOrGetName()) return;
-      }
-
-    if(subName.val == REC_BNAM)
-      {
-	resultScript = esm.getHString();
-	if(esm.isEmptyOrGetName()) return;
-      }
-
-    questStatus = QS_None;
-    int skip = 1;
-
-    if     (subName.val == REC_QSTN) questStatus = QS_Name;
-    else if(subName.val == REC_QSTF) questStatus = QS_Finished;
-    else if(subName.val == REC_QSTR) questStatus = QS_Restart;
-    else if(subName.val == REC_DELE) {questStatus = QS_Deleted; skip = 4;}
-    else
-      esm.fail("Don't know what to do with " + subName.toString() + " in INFO " + id);
-
-    if(questStatus != QS_None)
-      esm.skip(skip);
-  }
+  void load(ESMReader &esm);
 };
 
 /*

From e30306f7c35240140ac83a0392ca617763cd3cc8 Mon Sep 17 00:00:00 2001
From: Nicolay Korslund <korslund@gmail.com>
Date: Thu, 2 Sep 2010 22:30:39 +0200
Subject: [PATCH 28/32] Removed redundant custom exception class

---
 components/bsa/bsa_file.cpp         | 4 ++--
 components/esm/esm_reader.hpp       | 4 ++--
 components/esm_store/cell_store.hpp | 7 +++----
 components/misc/slice_array.hpp     | 2 ++
 components/nif/nif_file.hpp         | 4 ++--
 libs/mangle                         | 2 +-
 6 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/components/bsa/bsa_file.cpp b/components/bsa/bsa_file.cpp
index acd63a4bc4..e37d38bb2d 100644
--- a/components/bsa/bsa_file.cpp
+++ b/components/bsa/bsa_file.cpp
@@ -25,8 +25,8 @@
 
 #include <libs/mangle/stream/servers/file_stream.hpp>
 #include <libs/mangle/stream/filters/slice_stream.hpp>
-#include <libs/mangle/tools/str_exception.hpp>
 
+#include <stdexcept>
 #include <stdlib.h>
 #include <assert.h>
 
@@ -36,7 +36,7 @@ using namespace Mangle::Stream;
 /// Error handling
 void BSAFile::fail(const string &msg)
 {
-  throw str_exception("BSA Error: " + msg + "\nArchive: " + filename);
+  throw std::runtime_error("BSA Error: " + msg + "\nArchive: " + filename);
 }
 
 /// Read header information from the input source
diff --git a/components/esm/esm_reader.hpp b/components/esm/esm_reader.hpp
index 6e214e1bd7..76df4b5dc9 100644
--- a/components/esm/esm_reader.hpp
+++ b/components/esm/esm_reader.hpp
@@ -7,10 +7,10 @@
 #include <vector>
 #include <sstream>
 #include <string.h>
+#include <stdexcept>
 
 #include <libs/mangle/stream/stream.hpp>
 #include <libs/mangle/stream/servers/file_stream.hpp>
-#include <libs/mangle/tools/str_exception.hpp>
 #include <components/misc/stringops.hpp>
 
 #include <components/to_utf8/to_utf8.hpp>
@@ -626,7 +626,7 @@ public:
       ss << "\n  Subrecord: " << c.subName.toString();
       if(esm != NULL)
         ss << "\n  Offset: 0x" << hex << esm->tell();
-      throw str_exception(ss.str());
+      throw std::runtime_error(ss.str());
     }
 
 private:
diff --git a/components/esm_store/cell_store.hpp b/components/esm_store/cell_store.hpp
index d4d7cc2f83..a150ec3d38 100644
--- a/components/esm_store/cell_store.hpp
+++ b/components/esm_store/cell_store.hpp
@@ -13,11 +13,10 @@
 #include "store.hpp"
 #include "components/esm/records.hpp"
 #include "components/esm/loadcell.hpp"
-#include <libs/mangle/tools/str_exception.hpp>
 #include <list>
 
 #include <iostream>
-#include "libs/mangle/tools/str_exception.hpp"
+#include <stdexcept>
 
 namespace ESMS
 {
@@ -55,7 +54,7 @@ namespace ESMS
     {
       const X* obj = recList.find(ref.refID);
       if(obj == NULL)
-        throw str_exception("Error resolving cell reference " + ref.refID);
+        throw std::runtime_error("Error resolving cell reference " + ref.refID);
 
       LiveRef lr;
       lr.ref = ref;
@@ -116,7 +115,7 @@ namespace ESMS
         cell = store.cells.findInt(name);
 
         if(cell == NULL)
-            throw str_exception("Cell not found - " + name);
+            throw std::runtime_error("Cell not found - " + name);
 
         loadRefs(store, esm);
     }
diff --git a/components/misc/slice_array.hpp b/components/misc/slice_array.hpp
index 4dde8143b2..f7e2ffeffb 100644
--- a/components/misc/slice_array.hpp
+++ b/components/misc/slice_array.hpp
@@ -27,6 +27,8 @@
 // A simple array implementation containing a pointer and a
 // length. Used for holding slices into a data buffer.
 #include <string.h>
+#include <string>
+
 template <class T>
 struct SliceArray
 {
diff --git a/components/nif/nif_file.hpp b/components/nif/nif_file.hpp
index 72fb7c4b6a..ebf1fe4a45 100644
--- a/components/nif/nif_file.hpp
+++ b/components/nif/nif_file.hpp
@@ -26,9 +26,9 @@
 
 #include <libs/mangle/stream/stream.hpp>
 #include <libs/mangle/stream/filters/buffer_stream.hpp>
-#include <libs/mangle/tools/str_exception.hpp>
 #include <components/misc/slice_array.hpp>
 
+#include <stdexcept>
 #include <vector>
 #include <string>
 #include <assert.h>
@@ -69,7 +69,7 @@ class NIFFile
     {
       std::string err = "NIFFile Error: " + msg;
       err += "\nFile: " + filename;
-      throw str_exception(err);
+      throw std::runtime_error(err);
     }
 
   /// Open a NIF stream. The name is used for error messages.
diff --git a/libs/mangle b/libs/mangle
index 2407f21c47..053074babb 160000
--- a/libs/mangle
+++ b/libs/mangle
@@ -1 +1 @@
-Subproject commit 2407f21c47abe218b9347df0fc9e8e9aebc02e3f
+Subproject commit 053074babb1445993ec40f72f60755de8d8ee5b7

From 5552c447536163774eb3eca67cfe1a72dc39c29b Mon Sep 17 00:00:00 2001
From: Nicolay Korslund <korslund@gmail.com>
Date: Tue, 7 Sep 2010 10:40:00 +0200
Subject: [PATCH 29/32] Cleaned up strnlen in esm_reader. Added -Werror switch
 to g++.

---
 CMakeLists.txt                |  2 +-
 components/esm/esm_reader.hpp | 12 +-----------
 libs/platform/string.h        | 14 ++++++++++++++
 3 files changed, 16 insertions(+), 12 deletions(-)
 create mode 100644 libs/platform/string.h

diff --git a/CMakeLists.txt b/CMakeLists.txt
index beed450848..a1cc058ce4 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -247,7 +247,7 @@ endif (APPLE)
 
 # Compiler settings
 if (CMAKE_COMPILER_IS_GNUCC)
-    add_definitions (-Wall)
+    add_definitions (-Wall -Werror)
 endif (CMAKE_COMPILER_IS_GNUCC)
 
 # Apple bundling
diff --git a/components/esm/esm_reader.hpp b/components/esm/esm_reader.hpp
index 76df4b5dc9..64e0861b58 100644
--- a/components/esm/esm_reader.hpp
+++ b/components/esm/esm_reader.hpp
@@ -3,10 +3,10 @@
 
 #include <string>
 #include <libs/platform/stdint.h>
+#include <libs/platform/string.h>
 #include <assert.h>
 #include <vector>
 #include <sstream>
-#include <string.h>
 #include <stdexcept>
 
 #include <libs/mangle/stream/stream.hpp>
@@ -15,16 +15,6 @@
 
 #include <components/to_utf8/to_utf8.hpp>
 
-#ifdef __APPLE__
-// need our own implementation of strnlen
-static size_t strnlen(const char *s, size_t n)
-{
-  const char *p = (const char *)memchr(s, 0, n);
-  return(p ? p-s : n);
-}
-
-#endif
-
 namespace ESM {
 
 enum Version
diff --git a/libs/platform/string.h b/libs/platform/string.h
new file mode 100644
index 0000000000..dc25279fe9
--- /dev/null
+++ b/libs/platform/string.h
@@ -0,0 +1,14 @@
+// Wrapper for string.h on Mac
+#ifndef _STRING_WRAPPER_H
+#define _STRING_WRAPPER_H
+
+#include <string.h>
+#ifdef __APPLE__
+// need our own implementation of strnlen
+static size_t strnlen(const char *s, size_t n)
+{
+  const char *p = (const char *)memchr(s, 0, n);
+  return(p ? p-s : n);
+}
+#endif
+#endif

From 11d0eb0bf20c77c70a19b6385b474d81b6196ce1 Mon Sep 17 00:00:00 2001
From: athile <athile.g@gmail.com>
Date: Tue, 7 Sep 2010 15:20:39 +0100
Subject: [PATCH 30/32] submodule updates

---
 libs/mangle | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libs/mangle b/libs/mangle
index 053074babb..b08c2f78dc 160000
--- a/libs/mangle
+++ b/libs/mangle
@@ -1 +1 @@
-Subproject commit 053074babb1445993ec40f72f60755de8d8ee5b7
+Subproject commit b08c2f78dc24f05f67a998114880200518602690

From 11022f15204d361c886843627cef98f83e0a0631 Mon Sep 17 00:00:00 2001
From: athile <athile.g@gmail.com>
Date: Tue, 7 Sep 2010 15:21:38 +0100
Subject: [PATCH 31/32] Fix crash at shutdown.  updater() is still referenced
 by OGRE after it is deleted, since the SoundImpl is deleted by ~Engine before
 mRoot is deleted.

---
 apps/openmw/mwsound/soundmanager.cpp | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/apps/openmw/mwsound/soundmanager.cpp b/apps/openmw/mwsound/soundmanager.cpp
index 2e160f5c20..012222c315 100644
--- a/apps/openmw/mwsound/soundmanager.cpp
+++ b/apps/openmw/mwsound/soundmanager.cpp
@@ -104,6 +104,12 @@ namespace MWSound
       root->addFrameListener(&updater);
     }
 
+    SoundImpl::~SoundImpl()
+    {
+        Ogre::Root::getSingleton().removeFrameListener(&updater);
+        cameraTracker.unfollowCamera();
+    }
+
     std::string toMp3(const std::string &str)
     {
       std::string wav = str;
@@ -147,10 +153,10 @@ namespace MWSound
       const ESM::Sound *snd = store.sounds.search(soundId);
       if(snd == NULL) return "";
 
-      volume *= snd->data.volume / 255.0;
+      volume *= snd->data.volume / 255.0f;
       // These factors are not very fine tuned.
-      min = snd->data.minRange * 7;
-      max = snd->data.maxRange * 2000;
+      min = snd->data.minRange * 7.0f;
+      max = snd->data.maxRange * 2000.0f;
       return convertPath(snd->sound);
     }
 

From 93ef530c93171a4202d92f84edccf73b803765ed Mon Sep 17 00:00:00 2001
From: Nicolay Korslund <korslund@gmail.com>
Date: Tue, 7 Sep 2010 19:52:54 +0200
Subject: [PATCH 32/32] Minor fix on the last commit

---
 apps/openmw/mwsound/soundmanager.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/apps/openmw/mwsound/soundmanager.cpp b/apps/openmw/mwsound/soundmanager.cpp
index 012222c315..2bac0da591 100644
--- a/apps/openmw/mwsound/soundmanager.cpp
+++ b/apps/openmw/mwsound/soundmanager.cpp
@@ -104,7 +104,7 @@ namespace MWSound
       root->addFrameListener(&updater);
     }
 
-    SoundImpl::~SoundImpl()
+    ~SoundImpl()
     {
         Ogre::Root::getSingleton().removeFrameListener(&updater);
         cameraTracker.unfollowCamera();