X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fas3%2Ffiles.c;h=8b951d9149a9a31362be65c82262f66e1eaf5952;hb=a07a14a5eafaeaea1d8881ffc364c55ab204878e;hp=4d8392b92b255b81eef10f72f337aaf8efa203a5;hpb=3b012c0865474708e41e35cd876412043f0a917d;p=swftools.git diff --git a/lib/as3/files.c b/lib/as3/files.c index 4d8392b..8b951d9 100644 --- a/lib/as3/files.c +++ b/lib/as3/files.c @@ -55,6 +55,7 @@ typedef struct _include_dir { int current_line=1; int current_column=0; char* current_filename=0; +char* current_filename_short=0; include_dir_t* current_include_dirs=0; #define MAX_INCLUDE_DEPTH 16 @@ -63,6 +64,7 @@ void*include_stack[MAX_INCLUDE_DEPTH]; int line_stack[MAX_INCLUDE_DEPTH]; int column_stack[MAX_INCLUDE_DEPTH]; char* filename_stack[MAX_INCLUDE_DEPTH]; +char* shortfilename_stack[MAX_INCLUDE_DEPTH]; include_dir_t* includedir_stack[MAX_INCLUDE_DEPTH]; int include_stack_ptr = 0; @@ -129,6 +131,9 @@ char*find_file(char*filename) } return 0; } + if(!i) { + as3_warning("Include directory stack is empty, while looking for file %s", filename); + } while(i) { char*p = concat_paths(i->path, filename); fi = fopen(p, "rb"); @@ -143,13 +148,15 @@ char*find_file(char*filename) char*enter_file(char*filename, void*state) { + filename = strdup(filename); + if(include_stack_ptr >= MAX_INCLUDE_DEPTH) { - syntaxerror("Includes nested too deeply"); + as3_error("Includes nested too deeply"); exit(1); } char*fullfilename = find_file(filename); if(!fullfilename) { - syntaxerror("Couldn't find file %s", filename); + as3_error("Couldn't find file %s", filename); include_dir_t*i = current_include_dirs; while(i) { fprintf(stderr, "include dir: %s\n", i->path); @@ -160,6 +167,7 @@ char*enter_file(char*filename, void*state) include_stack[include_stack_ptr] = state; line_stack[include_stack_ptr] = current_line; column_stack[include_stack_ptr] = current_column; + shortfilename_stack[include_stack_ptr] = current_filename_short; filename_stack[include_stack_ptr] = current_filename; includedir_stack[include_stack_ptr] = current_include_dirs; add_include_dir(get_path(fullfilename)); @@ -169,20 +177,21 @@ char*enter_file(char*filename, void*state) current_line=1; current_column=0; - current_filename=fullfilename; + current_filename = fullfilename; + current_filename_short = filename; return fullfilename; } void* leave_file() { dbg("leaving file %s", current_filename); - if(--include_stack_ptr<0) { + if(--include_stack_ptr<=0) { return 0; } else { + free(current_filename);current_filename = filename_stack[include_stack_ptr]; + free(current_filename_short);current_filename_short = shortfilename_stack[include_stack_ptr]; current_column = column_stack[include_stack_ptr]; current_line = line_stack[include_stack_ptr]; - free(current_filename);current_filename=0; - current_filename = filename_stack[include_stack_ptr]; current_include_dirs = includedir_stack[include_stack_ptr]; return include_stack[include_stack_ptr]; }