fixed a security bug in logging, added basic xml support to as3 compiler
[swftools.git] / lib / as3 / files.c
index 5cd1e2e..eaa5a8c 100644 (file)
@@ -25,6 +25,7 @@
 #include <memory.h>
 #include <errno.h>
 #include "files.h"
+#include "common.h"
 #include "tokenizer.h"
 
 static int verbose = 0;
@@ -36,7 +37,7 @@ static void dbg(const char*format, ...)
     if(!verbose)
        return;
     va_start(arglist, format);
-    vsprintf(buf, format, arglist);
+    vsnprintf(buf, sizeof(buf)-1, format, arglist);
     va_end(arglist);
     l = strlen(buf);
     while(l && buf[l-1]=='\n') {
@@ -53,6 +54,7 @@ int current_line=1;
 int current_column=0;
 char* current_filename=0;
 char* current_filename_short=0;
+char* current_filename_long=0;
 include_dir_t* current_include_dirs=0;
 
 #define MAX_INCLUDE_DEPTH 16
@@ -62,6 +64,7 @@ int line_stack[MAX_INCLUDE_DEPTH];
 int column_stack[MAX_INCLUDE_DEPTH];
 char* filename_stack[MAX_INCLUDE_DEPTH];
 char* shortfilename_stack[MAX_INCLUDE_DEPTH];
+char* longfilename_stack[MAX_INCLUDE_DEPTH];
 include_dir_t* includedir_stack[MAX_INCLUDE_DEPTH];
 int include_stack_ptr = 0;
 
@@ -201,7 +204,7 @@ char is_absolute(const char*filename)
     return 0;
 }
 
-char*find_file(const char*filename)
+char*find_file(const char*filename, char error)
 {
     include_dir_t*i = current_include_dirs;
     FILE*fi = 0;
@@ -212,7 +215,7 @@ char*find_file(const char*filename)
             return strdup(filename);
         }
     } else {
-        if(!i) {
+        if(!i && error) {
             as3_warning("Include directory stack is empty, while looking for file %s", filename);
         }
         while(i) {
@@ -227,6 +230,9 @@ char*find_file(const char*filename)
             i = i->next;
         }
     }
+    if(!error) {
+        return 0;
+    }
 
     as3_error("Couldn't find file %s", filename);
     i = current_include_dirs;
@@ -247,6 +253,7 @@ void enter_file(const char*name, const char*filename, void*state)
     line_stack[include_stack_ptr] = current_line;
     column_stack[include_stack_ptr] = current_column;
     shortfilename_stack[include_stack_ptr] = current_filename_short;
+    longfilename_stack[include_stack_ptr] = current_filename_long;
     filename_stack[include_stack_ptr] = current_filename;
     includedir_stack[include_stack_ptr] = current_include_dirs;
     
@@ -260,8 +267,9 @@ void enter_file(const char*name, const char*filename, void*state)
 
     current_line=1;
     current_column=0;
-    current_filename = strdup(filename);
+    current_filename = strdup(name);
     current_filename_short = strdup(name);
+    current_filename_long = strdup(filename);
 }
 
 FILE*enter_file2(const char*name, const char*filename, void*state)
@@ -282,6 +290,7 @@ void* leave_file()
     } else {
         free(current_filename);current_filename = filename_stack[include_stack_ptr];
         free(current_filename_short);current_filename_short = shortfilename_stack[include_stack_ptr];
+        free(current_filename_long);current_filename_long = longfilename_stack[include_stack_ptr];
         current_column = column_stack[include_stack_ptr];
         current_line = line_stack[include_stack_ptr];
         del_include_dirs(includedir_stack[include_stack_ptr], current_include_dirs);