Browse Source

Removed unnecessary calling of static function via pointer in exposing the Log object to script.
Fixed trying to write into an unopened file in DocConverter.

Lasse Öörni 13 years ago
parent
commit
ab4a9d16c9
3 changed files with 30 additions and 32 deletions
  1. 8 8
      Engine/Engine/IOAPI.cpp
  2. 2 6
      Engine/IO/Log.cpp
  3. 20 18
      Tools/DocConverter/DocConverter.cpp

+ 8 - 8
Engine/Engine/IOAPI.cpp

@@ -71,29 +71,29 @@ static void Print(bool value, bool error)
     Log::WriteRaw(String(value) + "\n");
 }
 
-static void LogWrite(Log* ptr, const String& str, bool error)
+static void LogWrite(const String& str, bool error, Log* ptr)
 {
-    ptr->WriteRaw(str + "\n", error);
+    Log::WriteRaw(str + "\n", error);
 }
 
 static void LogDebug(const String& str, Log* ptr)
 {
-    ptr->Write(LOG_DEBUG, str);
+    Log::Write(LOG_DEBUG, str);
 }
 
 static void LogInfo(const String& str, Log* ptr)
 {
-    ptr->Write(LOG_INFO, str);
+    Log::Write(LOG_INFO, str);
 }
 
 static void LogWarning(const String& str, Log* ptr)
 {
-    ptr->Write(LOG_WARNING, str);
+    Log::Write(LOG_WARNING, str);
 }
 
 static void LogError(const String& str, Log* ptr)
 {
-    ptr->Write(LOG_ERROR, str);
+    Log::Write(LOG_ERROR, str);
 }
 
 #else
@@ -103,7 +103,7 @@ static void Print(int value, bool error) {}
 static void Print(unsigned value, bool error) {}
 static void Print(float value, bool error) {}
 static void Print(bool value, bool error) {}
-static void LogWrite(Log* ptr, const String& str, bool error) {}
+static void LogWrite(const String& str, bool error, Log* ptr) {}
 static void LogDebug(const String& str, Log* ptr) {}
 static void LogInfo(const String& str, Log* ptr) {}
 static void LogWarning(const String& str, Log* ptr) {}
@@ -120,7 +120,7 @@ static void RegisterLog(asIScriptEngine* engine)
     engine->RegisterGlobalProperty("const int LOG_NONE", (void*)&LOG_NONE);
     
     RegisterObject<Log>(engine, "Log");
-    engine->RegisterObjectMethod("Log", "void Write(const String&in, bool error = false)", asFUNCTION(LogWrite), asCALL_CDECL_OBJFIRST);
+    engine->RegisterObjectMethod("Log", "void Write(const String&in, bool error = false)", asFUNCTION(LogWrite), asCALL_CDECL_OBJLAST);
     engine->RegisterObjectMethod("Log", "void Debug(const String&in)", asFUNCTION(LogDebug), asCALL_CDECL_OBJLAST);
     engine->RegisterObjectMethod("Log", "void Info(const String&in)", asFUNCTION(LogInfo), asCALL_CDECL_OBJLAST);
     engine->RegisterObjectMethod("Log", "void Warning(const String&in)", asFUNCTION(LogWarning), asCALL_CDECL_OBJLAST);

+ 2 - 6
Engine/IO/Log.cpp

@@ -123,12 +123,8 @@ void Log::Write(int level, const String& message)
 {
     assert(level >= LOG_DEBUG && level < LOG_NONE);
     
-    // Check message level
-    if (level_ > level)
-        return;
-    
-    // Prevent recursion during log event
-    if (inWrite_)
+    // Do not log if message level excluded or if currently sending a log event
+    if (level_ > level || inWrite_)
         return;
     
     {

+ 20 - 18
Tools/DocConverter/DocConverter.cpp

@@ -54,6 +54,8 @@ void RemoveAutoLinks(String& line);
 bool IsPageName(const String& str, unsigned startIndex, unsigned endIndex);
 bool IsUpperCamelCase(const String& str, unsigned startIndex, unsigned endIndex);
 
+#define OUTPUTLINE(line) { if (outputFile.IsOpen()) outputFile.WriteLine(line); }
+
 int main(int argc, char** argv)
 {
     Vector<String> arguments;
@@ -94,7 +96,7 @@ void Run(const Vector<String>& arguments)
 
 void ScanPageNames(const String& fileName)
 {
-    PrintUnicodeLine("Scanning document file " + fileName + " for page names");
+    PrintLine("Scanning document file " + fileName + " for page names");
     
     File inputFile(context_, fileName);
     
@@ -104,7 +106,7 @@ void ScanPageNames(const String& fileName)
     
     if (!inputFile.IsOpen())
     {
-        PrintUnicodeLine("WARNING: Failed to open input file " + fileName + ", skipping");
+        PrintLine("WARNING: Failed to open input file " + fileName + ", skipping");
         return;
     }
     
@@ -120,7 +122,7 @@ void ScanPageNames(const String& fileName)
 
 void ProcessFile(const String& fileName)
 {
-    PrintUnicodeLine("Processing document file " + fileName);
+    PrintLine("Processing document file " + fileName);
     
     File inputFile(context_, fileName);
     
@@ -130,7 +132,7 @@ void ProcessFile(const String& fileName)
     
     if (!inputFile.IsOpen())
     {
-        PrintUnicodeLine("WARNING: Failed to open input file " + fileName + ", skipping");
+        PrintLine("WARNING: Failed to open input file " + fileName + ", skipping");
         return;
     }
     
@@ -200,7 +202,7 @@ void ProcessFile(const String& fileName)
                     }
                     else
                     {
-                        PrintUnicodeLine("WARNING: \\ref tag which could not be handled on line " + line);
+                        PrintLine("WARNING: \\ref tag which could not be handled on line " + line);
                         break;
                     }
                 }
@@ -218,40 +220,40 @@ void ProcessFile(const String& fileName)
             {
                 outputFileName = outDir_ + mainPageName_ + ".wiki";
                 if (!outputFile.Open(outputFileName, FILE_WRITE))
-                    PrintUnicodeLine("WARNING: Failed to open output file " + outputFileName);
-                outputFile.WriteLine("#labels featured");
-                outputFile.WriteLine("= " + AssembleString(tokens, 1) + " =");
+                    PrintLine("WARNING: Failed to open output file " + outputFileName);
+                OUTPUTLINE("#labels featured")
+                OUTPUTLINE("= " + AssembleString(tokens, 1) + " =")
             }
             else if (line.StartsWith("\\page") && tokens.Size() > 1)
             {
                 outputFileName = outDir_ + tokens[1] + ".wiki";
                 if (!outputFile.Open(outputFileName, FILE_WRITE))
-                    PrintUnicodeLine("WARNING: Failed to open output file " + outputFileName);
+                    PrintLine("WARNING: Failed to open output file " + outputFileName);
                 if (tokens.Size() > 2)
-                    outputFile.WriteLine("= " + AssembleString(tokens, 2) + " =");
+                    OUTPUTLINE("= " + AssembleString(tokens, 2) + " =")
                 else
-                    outputFile.WriteLine("= " + tokens[1] + " =");
+                    OUTPUTLINE("= " + tokens[1] + " =")
             }
             else if (line.StartsWith("\\section"))
             {
                 if (tokens.Size() > 2)
-                    outputFile.WriteLine("== " + AssembleString(tokens, 2) + " ==");
+                    OUTPUTLINE("== " + AssembleString(tokens, 2) + " ==")
                 else
-                    outputFile.WriteLine("== " + tokens[1] + " ==");
+                    OUTPUTLINE("== " + tokens[1] + " ==")
             }
             else if (line.StartsWith("\\verbatim") || line.StartsWith("\\code"))
             {
-                outputFile.WriteLine("{{{");
+                OUTPUTLINE("{{{")
                 inVerbatim = true;
             }
             else if (line.StartsWith("- "))
-                outputFile.WriteLine(" * " + line.Substring(2));
+                OUTPUTLINE(" * " + line.Substring(2))
             else if (line.StartsWith("  - "))
-                outputFile.WriteLine("   * " + line.Substring(4));
+                OUTPUTLINE("   * " + line.Substring(4))
             else if (line.StartsWith("-# "))
-                outputFile.WriteLine(" * " + line.Substring(3));
+                OUTPUTLINE(" * " + line.Substring(3))
             else
-                outputFile.WriteLine(line);
+                OUTPUTLINE(line)
             
         }
         else