--- parser3/src/include/pa_common.h 2001/11/09 11:06:57 1.62 +++ parser3/src/include/pa_common.h 2003/01/24 14:36:10 1.89.2.3 @@ -1,20 +1,29 @@ /** @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.62 2001/11/09 11:06:57 paf Exp $ + Copyright (c) 2001, 2003 ArtLebedev Group (http://www.artlebedev.com) + Author: Alexandr Petrosian (http://paf.design.ru) */ #ifndef PA_COMMON_H #define PA_COMMON_H -#include "pa_config_includes.h" +static const char* IDENT_COMMON_H="$Date: 2003/01/24 14:36:10 $"; + #include "pa_pool.h" #include "pa_string.h" +#include "pa_hash.h" +#include "pa_value.h" + +typedef Hash HashStringValue; -class Value; +// replace system s*nprintf with our versions +#undef vsnprintf +int __vsnprintf(char *, size_t, const char *, va_list); +#define vsnprintf __vsnprintf +#undef snprintf +int __snprintf(char *, size_t, const char *, ...); +#define snprintf __snprintf #if _MSC_VER /* @@ -26,15 +35,6 @@ inline int stat( const char *path, struc inline long lseek( int handle, long offset, int origin ) { return _lseek(handle, offset, origin); } */ -#ifndef vsnprintf -int __vsnprintf(char *, size_t, const char *, va_list); -# define vsnprintf __vsnprintf -#endif -#ifndef snprintf -int __snprintf(char *, size_t, const char *, ...); -# define snprintf __snprintf -#endif - //access #define F_OK 0 #define X_OK 1 @@ -80,6 +80,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 @@ -89,52 +91,94 @@ void fix_line_breaks( size_t& size ///< may change! used to speedup next actions ); +typedef void (*File_read_action)( + struct stat& finfo, + int f, + ConstStringPtr file_spec, CharPtr 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(ConstStringPtr 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); +char *file_read_text(Pool& pool, Charset& charset, + ConstStringPtr file_spec, + bool fail_on_read_problem=true, + HashStringValue* options=0, HashStringValue** 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 file_read(Pool& pool, Charset& charset, + ConstStringPtr file_spec, + void *& ptr, size_t& size, bool as_text, - bool fail_on_read_problem=true, - size_t offset=0, size_t limit=0); + HashStringValue* options=0, HashStringValue** out_fields=0, + bool fail_on_read_problem=true); + +typedef void (*File_write_action)(int f, void *context); /** - write data to specified file using pool, + 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 +*/ +bool file_write_action_under_lock( + ConstStringPtr file_spec, + const char *action_name, File_write_action action, void *context, + bool as_text=false, + bool do_append=false, + bool do_block=true, + bool fail_on_lock_problem=true); + +/** + write data to specified file, throws an exception in case of problems */ -void file_write(Pool& pool, - const String& file_spec, +void file_write( + ConstStringPtr file_spec, const void *data, size_t size, bool as_text, - bool do_append=false/*, - bool exclusive=false*/); + bool do_append=false); /** delete specified file throws an exception in case of problems */ -void file_delete(Pool& pool, const String& file_spec); +bool file_delete(ConstStringPtr file_spec, bool fail_on_read_problem=true); /** move specified file throws an exception in case of problems */ -void file_move(Pool& pool, const String& old_spec, const String& new_spec); +void file_move(ConstStringPtr old_spec, ConstStringPtr new_spec); -bool file_readable(const String& file_spec); -bool dir_readable(const String& file_spec); -String *file_readable(const String& path, const String& name); -bool file_executable(const String& file_spec); +bool entry_exists(const char *fname, struct stat *afinfo=0); +bool entry_exists(ConstStringPtr file_spec); +bool file_readable(ConstStringPtr file_spec); +bool dir_readable(ConstStringPtr file_spec); +String *file_readable(ConstStringPtr path, ConstStringPtr name); +bool file_executable(ConstStringPtr file_spec); -bool file_stat(const String& file_spec, +bool file_stat(ConstStringPtr file_spec, size_t& rsize, time_t& ratime, time_t& rmtime, @@ -148,27 +192,21 @@ 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); +char *format(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); +char *unescape_chars(const char *cp, int len); #ifdef WIN32 void back_slashes_to_slashes(char *s);