fixed bug in jpeg2000 decoding
[swftools.git] / lib / log.c
index 2ca25a4..e75148f 100644 (file)
--- a/lib/log.c
+++ b/lib/log.c
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
-#ifdef __NT__
-#include "stdafx.h"
-#include <string.h>
 #include <stdlib.h>
+#include <string.h>
+#include <stdarg.h>
+#ifdef WIN32
+//#include "stdafx.h"
 #include <malloc.h>
 #if _MSC_VER > 1000
 #pragma once
 #endif // _MSC_VER > 1000
 #else
 #include <stdio.h>
-#include <stdlib.h>
-#include <stdarg.h>
-#include <string.h>
 #include <unistd.h>
 #endif
 
 #include "log.h"
 
-int screenloglevel = 1;
+static int screenloglevel = 1;
 static int fileloglevel = -1;
-static int maxloglevel = 1;
 static FILE *logFile = 0;
+static int maxloglevel = 1;
 
-void initLog(char* pLogName, int fileloglevel, char* s00, char* s01, int s02, int screenlevel)
+int getScreenLogLevel()
 {
-   screenloglevel = screenlevel;
-   fileloglevel = fileloglevel;
-
-   maxloglevel=screenloglevel;
-   if(fileloglevel>maxloglevel && pLogName)
-       maxloglevel=fileloglevel;
-
-   logFile = NULL;
+    return screenloglevel;
+}
+int getLogLevel()
+{
+    return maxloglevel;
+}
 
-   if (pLogName && fileloglevel>=0)
-    logFile = fopen(pLogName, "a+");
+void setConsoleLogging(int level)
+{
+    if(level>maxloglevel)
+        maxloglevel=level;
+    screenloglevel = level;
+}
+void setFileLogging(char*filename, int level, char append)
+{
+    if(level>maxloglevel)
+        maxloglevel=level;
+    if(logFile) {
+        fclose(logFile);logFile=0;
+    }
+    if(filename && level>=0) {
+        logFile = fopen(filename, append?"ab+":"wb");
+        fileloglevel = level;
+    } else {
+        logFile = 0;
+        fileloglevel = 0;
+    }
+}
+/* deprecated */
+void initLog(char* filename, int filelevel, char* s00, char* s01, int s02, int screenlevel)
+{
+    setFileLogging(filename, filelevel, 0);
+    setConsoleLogging(screenlevel);
 }
 
 void exitLog()
 {
    // close file
-   if(logFile != NULL)
+   if(logFile != NULL) {
      fclose(logFile);
+     logFile = 0;
+     fileloglevel = -1;
+     screenloglevel = 1;
+     maxloglevel = 1;
+   }
 }
 
 static char * logimportance[]= {"Fatal","Error","Warning","Notice","Verbose","Debug","Trace"};
 static int loglevels=7;
 static char * logimportance2[]= {"       ","FATAL  ","ERROR  ","WARNING","NOTICE ","VERBOSE","DEBUG  ", "TRACE  "};
 
-static inline void log(char* logString)
+static inline void log_str(const char* logString)
 {
    char timebuffer[32];
    char* logBuffer;
@@ -148,7 +173,7 @@ static inline void log(char* logString)
    {
        if (logFile != NULL)
        {
-         fprintf(logFile, "%s\n", logBuffer); 
+         fprintf(logFile, "%s\r\n", logBuffer); 
          fflush(logFile);
        }
    }
@@ -156,6 +181,16 @@ static inline void log(char* logString)
    free (logBuffer);
 }
 
+void msg_str(const char* buf)
+{
+    if(buf[0]=='<') {
+       char*z = "fewnvdt";
+       char*x = strchr(z,buf[1]);
+       if(x && (x-z)>maxloglevel)
+               return;
+    }
+    log_str(buf);
+}
 void msg(const char* format, ...)
 {
     char buf[1024];
@@ -170,9 +205,9 @@ void msg(const char* format, ...)
                return;
     }
 
-    vsprintf(buf, format, arglist);
+    vsnprintf(buf, sizeof(buf)-1, format, arglist);
        va_end(arglist);
     strcat(buf, "\n");
-    log(buf);
+    log_str(buf);
 }