--- parser3/src/main/pa_common.C 2012/03/08 21:19:38 1.266 +++ parser3/src/main/pa_common.C 2013/03/09 23:34:15 1.269 @@ -1,7 +1,7 @@ /** @file Parser: commonly functions. - Copyright(c) 2001-2012 ArtLebedev Group (http://www.artlebedev.com) + Copyright (c) 2000-2012 Art. Lebedev Studio (http://www.artlebedev.com) Author: Alexandr Petrosian (http://paf.design.ru) * BASE64 part @@ -26,8 +26,6 @@ * */ -static const char * const IDENT_COMMON_C="$Date: 2012/03/08 21:19:38 $"; - #include "pa_common.h" #include "pa_exception.h" #include "pa_hash.h" @@ -38,6 +36,8 @@ static const char * const IDENT_COMMON_C #include "pcre.h" #include "pa_request.h" +volatile const char * IDENT_PA_COMMON_C="$Id: pa_common.C,v 1.269 2013/03/09 23:34:15 misha Exp $" IDENT_PA_COMMON_H IDENT_PA_HASH_H IDENT_PA_ARRAY_H IDENT_PA_STACK_H; + // some maybe-undefined constants #ifndef _O_TEXT @@ -509,7 +509,7 @@ static void rmdir(const String& file_spe }; } -bool file_delete(const String& file_spec, bool fail_on_problem) { +bool file_delete(const String& file_spec, bool fail_on_problem, bool keep_empty_dirs) { const char* fname=file_spec.taint_cstr(String::L_FILE_SPEC); if(unlink(fname)!=0) if(fail_on_problem) @@ -520,11 +520,13 @@ bool file_delete(const String& file_spec else return false; - rmdir(file_spec, 1); + if(!keep_empty_dirs) + rmdir(file_spec, 1); + return true; } -void file_move(const String& old_spec, const String& new_spec) { +void file_move(const String& old_spec, const String& new_spec, bool keep_empty_dirs) { const char* old_spec_cstr=old_spec.taint_cstr(String::L_FILE_SPEC); const char* new_spec_cstr=new_spec.taint_cstr(String::L_FILE_SPEC); @@ -536,7 +538,8 @@ void file_move(const String& old_spec, c "rename failed: %s (%d), actual filename '%s' to '%s'", strerror(errno), errno, old_spec_cstr, new_spec_cstr); - rmdir(old_spec, 1); + if(!keep_empty_dirs) + rmdir(old_spec, 1); } @@ -824,6 +827,26 @@ char* unescape_chars(const char* cp, int return s; } +char *search_stop(char*& current, char cstop_at) { + // sanity check + if(!current) + return 0; + + // skip leading WS + while(*current==' ' || *current=='\t') + current++; + if(!*current) + return current=0; + + char *result=current; + if(char *pstop_at=strchr(current, cstop_at)) { + *pstop_at=0; + current=pstop_at+1; + } else + current=0; + return result; +} + #ifdef WIN32 void back_slashes_to_slashes(char* s) { if(s)