|
|
| version 1.266, 2012/03/08 21:19:38 | version 1.270, 2013/04/21 21:59:07 |
|---|---|
| Line 1 | Line 1 |
| /** @file | /** @file |
| Parser: commonly functions. | 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 <paf@design.ru> (http://paf.design.ru) | Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru) |
| * BASE64 part | * BASE64 part |
| Line 26 | Line 26 |
| * | * |
| */ | */ |
| static const char * const IDENT_COMMON_C="$Date$"; | |
| #include "pa_common.h" | #include "pa_common.h" |
| #include "pa_exception.h" | #include "pa_exception.h" |
| #include "pa_hash.h" | #include "pa_hash.h" |
| Line 38 static const char * const IDENT_COMMON_C | Line 36 static const char * const IDENT_COMMON_C |
| #include "pcre.h" | #include "pcre.h" |
| #include "pa_request.h" | #include "pa_request.h" |
| volatile const char * IDENT_PA_COMMON_C="$Id$" IDENT_PA_COMMON_H IDENT_PA_HASH_H IDENT_PA_ARRAY_H IDENT_PA_STACK_H; | |
| // some maybe-undefined constants | // some maybe-undefined constants |
| #ifndef _O_TEXT | #ifndef _O_TEXT |
| Line 509 static void rmdir(const String& file_spe | Line 509 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); | const char* fname=file_spec.taint_cstr(String::L_FILE_SPEC); |
| if(unlink(fname)!=0) | if(unlink(fname)!=0) |
| if(fail_on_problem) | if(fail_on_problem) |
| Line 520 bool file_delete(const String& file_spec | Line 520 bool file_delete(const String& file_spec |
| else | else |
| return false; | return false; |
| rmdir(file_spec, 1); | if(!keep_empty_dirs) |
| rmdir(file_spec, 1); | |
| return true; | 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* old_spec_cstr=old_spec.taint_cstr(String::L_FILE_SPEC); |
| const char* new_spec_cstr=new_spec.taint_cstr(String::L_FILE_SPEC); | const char* new_spec_cstr=new_spec.taint_cstr(String::L_FILE_SPEC); |
| Line 536 void file_move(const String& old_spec, c | Line 538 void file_move(const String& old_spec, c |
| "rename failed: %s (%d), actual filename '%s' to '%s'", | "rename failed: %s (%d), actual filename '%s' to '%s'", |
| strerror(errno), errno, old_spec_cstr, new_spec_cstr); | strerror(errno), errno, old_spec_cstr, new_spec_cstr); |
| rmdir(old_spec, 1); | if(!keep_empty_dirs) |
| rmdir(old_spec, 1); | |
| } | } |
| Line 563 bool dir_exists(const String& file_spec) | Line 566 bool dir_exists(const String& file_spec) |
| const String* file_exist(const String& path, const String& name) { | const String* file_exist(const String& path, const String& name) { |
| String& result=*new String(path); | String& result=*new String(path); |
| result << "/"; | if(path.last_char() != '/') |
| result << "/"; | |
| result << name; | result << name; |
| return file_exist(result)?&result:0; | return file_exist(result)?&result:0; |
| } | } |
| Line 824 char* unescape_chars(const char* cp, int | Line 828 char* unescape_chars(const char* cp, int |
| return s; | 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 | #ifdef WIN32 |
| void back_slashes_to_slashes(char* s) { | void back_slashes_to_slashes(char* s) { |
| if(s) | if(s) |