Annotation of parser3/src/include/pa_common.h, revision 1.89.2.13.2.10

1.15      paf         1: /** @file
1.16      paf         2:        Parser: commonly used functions.
                      3: 
1.89.2.7  paf         4:        Copyright (c) 2001-2003 ArtLebedev Group (http://www.artlebedev.com)
1.74      paf         5:        Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
1.1       paf         6: */
                      7: 
                      8: #ifndef PA_COMMON_H
                      9: #define PA_COMMON_H
1.78      paf        10: 
1.89.2.13.2.1  (paf       11:): static const char* IDENT_COMMON_H="$Date: 2003/04/02 10:10:00 $";
                     12:: 
1.1       paf        13: 
1.33      paf        14: #include "pa_string.h"
1.89.2.3  paf        15: #include "pa_hash.h"
1.1       paf        16: 
1.89.2.13.2.5  (paf       17:: class Value;
1.89.2.13.2.7  (paf       18:: typedef Hash<const StringBody , Value*> HashStringValue;
1.64      paf        19: 
                     20: // replace system s*nprintf with our versions
1.69      paf        21: #undef vsnprintf 
1.89.2.7  paf        22: int __vsnprintf(char *, size_t, const char* , va_list);
1.64      paf        23: #define vsnprintf __vsnprintf 
                     24: #undef snprintf
1.89.2.7  paf        25: int __snprintf(char *, size_t, const char* , ...);
1.64      paf        26: #define snprintf __snprintf
1.63      paf        27: 
1.21      paf        28: #if _MSC_VER
1.56      paf        29: /*
1.89.2.7  paf        30: inline int open( const char* filename, int oflag ) { return _open(filename, oflag); }
1.56      paf        31: inline int close( int handle ) { return _close(handle); }
                     32: inline int read( int handle, void *buffer, unsigned int count ) { return _read(handle,buffer,count); }
                     33: inline int write( int handle, const void *buffer, unsigned int count ) { return _write(handle,buffer,count); }
1.89.2.7  paf        34: inline int stat( const char* path, struct _stat *buffer ) { return _stat(path, buffer); }
1.56      paf        35: inline long lseek( int handle, long offset, int origin ) { return _lseek(handle, offset, origin); }
                     36: */
1.17      paf        37: 
                     38: //access
                     39: #define F_OK 0
                     40: #define X_OK 1
                     41: #define W_OK 2
                     42: #define R_OK 4
                     43: 
1.20      paf        44: #ifndef strcasecmp
                     45: #      define strcasecmp _stricmp
                     46: #endif
                     47: #ifndef strncasecmp
                     48: #      define strncasecmp _strnicmp
                     49: #endif
                     50: #ifndef mkdir
                     51: #      define mkdir(path, mode) _mkdir(path)
                     52: #endif
1.17      paf        53: 
1.20      paf        54: #ifndef putenv
                     55: #      define putenv _putenv
1.1       paf        56: #endif
1.2       paf        57: 
1.59      paf        58: #endif
1.87      paf        59: 
1.72      paf        60: /// yields to OS for secs secs and usecs milliseconds
                     61: int pa_sleep(unsigned long secs, unsigned long usecs);
1.54      parser     62: 
                     63: /** under WIN32 "t" mode fixes DOS chars OK, 
                     64:        can't say that about other systems/ line break styles
                     65: */
1.57      paf        66: void fix_line_breaks(
1.89.2.13.2.9  (paf       67::                    char *str,
                     68::                    size_t& length///< may change! used to speedup next actions
1.89.2.13.2.1  (paf       69::                    );
                     70:: 
                     71:: typedef void (*File_read_action)(
                     72::                                struct stat& finfo,
                     73::                                int f, 
                     74::                                const String& file_spec, const char* fname, bool as_text,
                     75::                                void *context);
1.83      paf        76: 
                     77: /**
                     78:        shared-lock specified file, 
                     79:        do actions under lock.
                     80:        if fail_on_read_problem is true[default] throws an exception
                     81:        
                     82:        @returns true if read OK
                     83: */
1.89.2.13.2.1  (paf       84:: bool file_read_action_under_lock(const String& file_spec, 
1.89.2.7  paf        85:                                const char* action_name, File_read_action action, void *context,
1.83      paf        86:                                bool as_text=false,
                     87:                                bool fail_on_read_problem=true);
1.15      paf        88: /**
1.89.2.13.2.3  (paf       89::       read specified text file using 
1.15      paf        90:        if fail_on_read_problem is true[default] throws an exception
1.83      paf        91: 
1.89.2.8  paf        92:        WARNING: charset is used for http header case conversion, it's not a charset of input file!
                     93: 
1.83      paf        94:        @returns true if read OK
1.15      paf        95: */
1.89.2.13.2.1  (paf       96:: char *file_read_text(Charset& charset, 
                     97::                                        const String& file_spec, 
1.85      paf        98:                                         bool fail_on_read_problem=true,
1.89.2.13.2.2  (paf       99::                                        HashStringValue* options=0/*, HashStringValue* * out_fields=0*/);
1.17      paf       100: 
1.89.2.4  paf       101: struct File_read_result {
                    102:        bool success;
1.89.2.13.2.4  (paf      103::       char* str; size_t length;
1.89.2.13.2.2  (paf      104::       HashStringValue* headers;
1.89.2.4  paf       105: };
                    106: 
1.17      paf       107: /**
1.89.2.13.2.3  (paf      108::       read specified file using 
1.29      paf       109:        if fail_on_read_problem is true[default] throws an exception
1.89.2.8  paf       110: 
                    111:        WARNING: charset is used for http header case conversion, it's not a charset of input file!
1.83      paf       112: 
                    113:        @returns true if read OK
1.29      paf       114: */
1.89.2.13.2.1  (paf      115:: File_read_result file_read(Charset& charset, 
                    116::                          const String& file_spec, 
1.29      paf       117:                           bool as_text,
1.89.2.9  paf       118:                           HashStringValue* options=0,
1.83      paf       119:                           bool fail_on_read_problem=true);
                    120: 
                    121: typedef void (*File_write_action)(int f, void *context);
1.29      paf       122: 
                    123: /**
1.71      paf       124:        lock specified file exclusively, 
                    125:        do actions under lock.
                    126:        throws an exception in case of problems
1.72      paf       127:        
                    128:        if block=false does non-blocking lock
                    129:        @returns true if locked OK, or false if non-blocking locking failed
1.71      paf       130: */
1.72      paf       131: bool file_write_action_under_lock(
1.89.2.13.2.1  (paf      132::                               const String& file_spec, 
1.89.2.7  paf       133:                                const char* action_name, File_write_action action, void *context,
1.71      paf       134:                                bool as_text=false,
1.72      paf       135:                                bool do_append=false,
1.77      paf       136:                                bool do_block=true,
                    137:                                bool fail_on_lock_problem=true);
1.71      paf       138: 
                    139: /**
                    140:        write data to specified file, 
1.17      paf       141:        throws an exception in case of problems
                    142: */
1.70      paf       143: void file_write(
1.89.2.13.2.1  (paf      144::                               const String& file_spec,
1.89.2.10  paf       145:                                const char* data, size_t size, 
1.58      paf       146:                                bool as_text,
1.67      paf       147:                                bool do_append=false);
1.26      paf       148: 
                    149: /**
                    150:        delete specified file 
                    151:        throws an exception in case of problems
                    152: */
1.89.2.13.2.1  (paf      153:: bool file_delete(const String& file_spec, bool fail_on_read_problem=true);
1.47      parser    154: /**
                    155:        move specified file 
                    156:        throws an exception in case of problems
                    157: */
1.89.2.13.2.1  (paf      158:: void file_move(const String& old_spec, const String& new_spec);
1.27      paf       159: 
1.89.2.7  paf       160: bool entry_exists(const char* fname, struct stat *afinfo=0);
1.89.2.13.2.1  (paf      161:: bool entry_exists(const String& file_spec);
                    162:: bool file_readable(const String& file_spec);
                    163:: bool dir_readable(const String& file_spec);
1.89.2.13.2.6  (paf      164:: const String* file_readable(const String& path, const String& name);
1.89.2.13.2.1  (paf      165:: bool file_executable(const String& file_spec);
1.37      paf       166: 
1.89.2.13.2.1  (paf      167:: bool file_stat(const String& file_spec, 
1.46      parser    168:                           size_t& rsize, 
                    169:                           time_t& ratime,
                    170:                           time_t& rmtime,
1.48      parser    171:                           time_t& rctime,
                    172:                           bool fail_on_read_problem=true);
1.15      paf       173: 
                    174: /**
1.18      paf       175:        scans for @a delim[default \n] in @a *row_ref, 
                    176:        @return piece of line before it or end of string, if no @a delim found
                    177:        assigns @a *row_ref to point right after delimiter if there were one
                    178:        or to zero if no @a delim were found.
1.15      paf       179: */
1.7       paf       180: char *getrow(char **row_ref,char delim='\n');
1.76      paf       181: char *lsplit(char *string, char delim);
1.7       paf       182: char *lsplit(char **string_ref,char delim);
1.8       paf       183: char *rsplit(char *string, char delim);
1.89.2.13.2.1  (paf      184:: const char* format(double value, char *fmt);
1.10      paf       185: 
                    186: #ifndef max
1.75      paf       187: inline int max(int a, int b) { return a>b?a:b; }
                    188: inline int min(int a, int b){ return a<b?a:b; }
                    189: inline size_t max(size_t a, size_t b) { return a>b?a:b; }
                    190: inline size_t min(size_t a, size_t b){ return a<b?a:b; }
1.10      paf       191: #endif
                    192: 
1.30      paf       193: size_t stdout_write(const void *buf, size_t size);
1.14      paf       194: 
1.89.2.13.2.1  (paf      195:: char *unescape_chars(const char* cp, int len);
1.23      paf       196: 
                    197: #ifdef WIN32
                    198: void back_slashes_to_slashes(char *s);
1.35      paf       199: //void slashes_to_back_slashes(char *s);
1.23      paf       200: #endif
                    201: 
1.28      paf       202: #ifndef _qsort
                    203: #      define _qsort(names,cnt,sizeof_names,func_addr) \
                    204:                qsort(names,cnt,sizeof_names,func_addr)
                    205: #endif
1.34      paf       206: 
1.89.2.7  paf       207: bool StrEqNc(const char* s1, const char* s2, bool strict=true);
1.45      parser    208: 
                    209: #define SECS_PER_DAY (60*60*24)
                    210: int getMonthDays(int year, int month);
1.52      parser    211: 
                    212: void remove_crlf(char *start, char *end);
1.89.2.13.2.1  (paf      213:): 
                    214:): #ifdef PA_SAFE_MODE 
                    215:): void check_safe_mode(stat finfo, const String& file_spec, const char* fname); 
                    216:): #endif 
1.89.2.9  paf       217: 
                    218: // globals
                    219: 
1.89.2.13.2.3  (paf      220:: extern const String file_status_name;
1.1       paf       221: 
                    222: #endif

E-mail: