--- parser3/src/include/pa_common.h 2002/01/25 12:09:04 1.71 +++ parser3/src/include/pa_common.h 2002/11/25 14:57:33 1.86 @@ -1,19 +1,19 @@ /** @file Parser: commonly used functions. - Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) - Author: Alexander Petrosyan (http://paf.design.ru) - - $Id: pa_common.h,v 1.71 2002/01/25 12:09:04 paf Exp $ + Copyright (c) 2001, 2002 ArtLebedev Group (http://www.artlebedev.com) + Author: Alexandr Petrosian (http://paf.design.ru) */ #ifndef PA_COMMON_H #define PA_COMMON_H +static const char* IDENT_COMMON_H="$Date: 2002/11/25 14:57:33 $"; + #include "pa_pool.h" #include "pa_string.h" -class Value; +class Hash; // replace system s*nprintf with our versions #undef vsnprintf @@ -78,6 +78,8 @@ extern "C" double sign(double); inline double sign(double param) { return param > 0 ? 1 : ( param < 0 ? -1 : 0 ); } #endif +/// yields to OS for secs secs and usecs milliseconds +int pa_sleep(unsigned long secs, unsigned long usecs); /** under WIN32 "t" mode fixes DOS chars OK, can't say that about other systems/ line break styles @@ -87,34 +89,63 @@ void fix_line_breaks( size_t& size ///< may change! used to speedup next actions ); +typedef void (*File_read_action)(Pool& pool, + struct stat& finfo, + int f, + const String& file_spec, const char *fname, bool as_text, + void *context); + +/** + shared-lock specified file, + do actions under lock. + if fail_on_read_problem is true[default] throws an exception + + @returns true if read OK +*/ +bool file_read_action_under_lock(Pool& pool, const String& file_spec, + const char *action_name, File_read_action action, void *context, + bool as_text=false, + bool fail_on_read_problem=true); /** read specified text file using pool, if fail_on_read_problem is true[default] throws an exception + + @returns true if read OK */ char *file_read_text(Pool& pool, const String& file_spec, - bool fail_on_read_problem=true); + bool fail_on_read_problem=true, + Hash *options=0, Hash** out_fields=0); /** read specified file using pool, if fail_on_read_problem is true[default] throws an exception + + @returns true if read OK */ bool file_read(Pool& pool, const String& file_spec, void*& data, size_t& size, bool as_text, - bool fail_on_read_problem=true, - size_t offset=0, size_t limit=0); + Hash *options=0, Hash** out_fields=0, + bool fail_on_read_problem=true); + +typedef void (*File_write_action)(int f, void *context); /** lock specified file exclusively, do actions under lock. throws an exception in case of problems + + if block=false does non-blocking lock + @returns true if locked OK, or false if non-blocking locking failed */ -void file_action_under_lock( +bool file_write_action_under_lock( const String& file_spec, - const char *action_name, void (*action)(int, void *), void *context=0, + const char *action_name, File_write_action action, void *context, bool as_text=false, - bool do_append=false); + bool do_append=false, + bool do_block=true, + bool fail_on_lock_problem=true); /** write data to specified file, @@ -137,6 +168,8 @@ bool file_delete(const String& file_spec */ void file_move(const String& old_spec, const String& new_spec); +bool entry_exists(const char *fname, struct stat *afinfo=0); +bool entry_exists(const String& file_spec); bool file_readable(const String& file_spec); bool dir_readable(const String& file_spec); String *file_readable(const String& path, const String& name); @@ -156,28 +189,22 @@ bool file_stat(const String& file_spec, or to zero if no @a delim were found. */ char *getrow(char **row_ref,char delim='\n'); -//char *lsplit(char *string, char delim); +char *lsplit(char *string, char delim); char *lsplit(char **string_ref,char delim); char *rsplit(char *string, char delim); char *format(Pool& pool, double value, char *fmt); #ifndef max -inline int max(int a,int b) { return a>b?a:b; } -inline int min(int a,int b){ return ab?a:b; } +inline int min(int a, int b){ return ab?a:b; } +inline size_t min(size_t a, size_t b){ return a - content-type: text/html - $content-type[$value[text/html] charset[windows-1251]] -> - content-type: text/html; charset=windows-1251 -*/ -const String& attributed_meaning_to_string(Value& meaning, String::Untaint_lang lang); - #ifdef WIN32 void back_slashes_to_slashes(char *s); //void slashes_to_back_slashes(char *s);