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

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

E-mail: