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

1.15      paf         1: /** @file
1.16      paf         2:        Parser: commonly used functions.
                      3: 
1.4       paf         4:        Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com)
1.60      paf         5:        Author: Alexander Petrosyan <paf@design.ru> (http://paf.design.ru)
1.4       paf         6: 
1.64    ! paf         7:        $Id: pa_common.h,v 1.63 2001/11/14 11:26:17 paf Exp $
1.1       paf         8: */
                      9: 
                     10: #ifndef PA_COMMON_H
                     11: #define PA_COMMON_H
                     12: 
1.21      paf        13: #include "pa_config_includes.h"
1.2       paf        14: #include "pa_pool.h"
1.33      paf        15: #include "pa_string.h"
1.1       paf        16: 
1.14      paf        17: class Value;
1.11      paf        18: 
1.64    ! paf        19: #if _MSC_VER
        !            20: // system one called "_snprintf"
        !            21: #else
        !            22: // remember system one
        !            23: inline int _snprintf(char *b, size_t s, const char *f, va_list l) { return snprintf(b, s, f, l); }
        !            24: #endif
        !            25: 
        !            26: // replace system s*nprintf with our versions
        !            27: #undef vsnpritnf
1.63      paf        28: int __vsnprintf(char *, size_t, const char *, va_list);
1.64    ! paf        29: #define vsnprintf __vsnprintf 
        !            30: #undef snprintf
1.63      paf        31: int __snprintf(char *, size_t, const char *, ...);
1.64    ! paf        32: #define snprintf __snprintf
1.63      paf        33: 
1.21      paf        34: #if _MSC_VER
1.56      paf        35: /*
                     36: inline int open( const char *filename, int oflag ) { return _open(filename, oflag); }
                     37: inline int close( int handle ) { return _close(handle); }
                     38: inline int read( int handle, void *buffer, unsigned int count ) { return _read(handle,buffer,count); }
                     39: inline int write( int handle, const void *buffer, unsigned int count ) { return _write(handle,buffer,count); }
                     40: inline int stat( const char *path, struct _stat *buffer ) { return _stat(path, buffer); }
                     41: inline long lseek( int handle, long offset, int origin ) { return _lseek(handle, offset, origin); }
                     42: */
1.17      paf        43: 
                     44: //access
                     45: #define F_OK 0
                     46: #define X_OK 1
                     47: #define W_OK 2
                     48: #define R_OK 4
                     49: 
1.20      paf        50: #ifndef strcasecmp
                     51: #      define strcasecmp _stricmp
                     52: #endif
                     53: #ifndef strncasecmp
                     54: #      define strncasecmp _strnicmp
                     55: #endif
                     56: #ifndef mkdir
                     57: #      define mkdir(path, mode) _mkdir(path)
                     58: #endif
1.17      paf        59: 
1.20      paf        60: #ifndef putenv
                     61: #      define putenv _putenv
1.1       paf        62: #endif
1.2       paf        63: 
1.17      paf        64: #endif
1.59      paf        65: 
1.61      paf        66: #ifdef HAVE_TRUNC
                     67: #      ifndef trunc
                     68: extern "C" double trunc(double);
                     69: #      endif
                     70: #else
1.59      paf        71: inline double trunc(double param) { return param > 0? floor(param) : ceil(param); }
                     72: #endif
1.61      paf        73: 
                     74: #ifdef HAVE_ROUND
                     75: #      ifndef round
                     76: extern "C" double round(double);
                     77: #      endif
                     78: #else
1.59      paf        79: inline double round(double param) { return floor(param+0.5); }
                     80: #endif
1.61      paf        81: #ifdef HAVE_SIGN
                     82: #      ifndef sign
                     83: extern "C" double sign(double);
                     84: #      endif
                     85: #else
1.59      paf        86: inline double sign(double param) { return param > 0 ? 1 : ( param < 0 ? -1 : 0 ); }
                     87: #endif
                     88: 
1.54      parser     89: 
                     90: /** under WIN32 "t" mode fixes DOS chars OK, 
                     91:        can't say that about other systems/ line break styles
                     92: */
1.57      paf        93: void fix_line_breaks(
1.62      paf        94:                                         char *buf,
                     95:                                         size_t& size ///< may change! used to speedup next actions
1.57      paf        96:                                         );
1.17      paf        97: 
1.15      paf        98: /**
1.19      paf        99:        read specified text file using pool, 
1.15      paf       100:        if fail_on_read_problem is true[default] throws an exception
                    101: */
1.19      paf       102: char *file_read_text(Pool& pool, 
1.25      paf       103:                                         const String& file_spec, 
1.19      paf       104:                                         bool fail_on_read_problem=true);
1.17      paf       105: 
                    106: /**
1.29      paf       107:        read specified file using pool, 
                    108:        if fail_on_read_problem is true[default] throws an exception
                    109: */
                    110: bool file_read(Pool& pool, const String& file_spec, 
                    111:                           void*& data, size_t& size, 
                    112:                           bool as_text,
1.37      paf       113:                           bool fail_on_read_problem=true,
                    114:                           size_t offset=0, size_t limit=0);
1.29      paf       115: 
                    116: /**
1.17      paf       117:        write data to specified file using pool, 
                    118:        throws an exception in case of problems
                    119: */
                    120: void file_write(Pool& pool, 
1.25      paf       121:                                const String& file_spec,
1.29      paf       122:                                const void *data, size_t size, 
1.58      paf       123:                                bool as_text,
                    124:                                bool do_append=false/*,
1.20      paf       125:                                bool exclusive=false*/);
1.26      paf       126: 
                    127: /**
                    128:        delete specified file 
                    129:        throws an exception in case of problems
                    130: */
                    131: void file_delete(Pool& pool, const String& file_spec);
1.47      parser    132: /**
                    133:        move specified file 
                    134:        throws an exception in case of problems
                    135: */
                    136: void file_move(Pool& pool, const String& old_spec, const String& new_spec);
1.27      paf       137: 
                    138: bool file_readable(const String& file_spec);
1.41      paf       139: bool dir_readable(const String& file_spec);
1.49      parser    140: String *file_readable(const String& path, const String& name);
1.36      paf       141: bool file_executable(const String& file_spec);
1.37      paf       142: 
1.48      parser    143: bool file_stat(const String& file_spec, 
1.46      parser    144:                           size_t& rsize, 
                    145:                           time_t& ratime,
                    146:                           time_t& rmtime,
1.48      parser    147:                           time_t& rctime,
                    148:                           bool fail_on_read_problem=true);
1.15      paf       149: 
                    150: /**
1.18      paf       151:        scans for @a delim[default \n] in @a *row_ref, 
                    152:        @return piece of line before it or end of string, if no @a delim found
                    153:        assigns @a *row_ref to point right after delimiter if there were one
                    154:        or to zero if no @a delim were found.
1.15      paf       155: */
1.7       paf       156: char *getrow(char **row_ref,char delim='\n');
1.22      paf       157: //char *lsplit(char *string, char delim);
1.7       paf       158: char *lsplit(char **string_ref,char delim);
1.8       paf       159: char *rsplit(char *string, char delim);
1.9       paf       160: char *format(Pool& pool, double value, char *fmt);
1.10      paf       161: 
                    162: #ifndef max
                    163: inline int max(int a,int b) { return a>b?a:b; }
                    164: inline int min(int a,int b){ return a<b?a:b; }
                    165: #endif
                    166: 
1.30      paf       167: size_t stdout_write(const void *buf, size_t size);
1.14      paf       168: 
1.55      parser    169: char *unescape_chars(Pool& pool, const char *cp, int len);
1.14      paf       170: 
1.24      paf       171: /**
                    172:        $content-type[text/html] -> 
1.32      paf       173:                content-type: text/html
1.24      paf       174:        $content-type[$value[text/html] charset[windows-1251]] -> 
1.32      paf       175:                content-type: text/html; charset=windows-1251
1.24      paf       176: */
1.33      paf       177: const String& attributed_meaning_to_string(Value& meaning, String::Untaint_lang lang);
1.23      paf       178: 
                    179: #ifdef WIN32
                    180: void back_slashes_to_slashes(char *s);
1.35      paf       181: //void slashes_to_back_slashes(char *s);
1.23      paf       182: #endif
                    183: 
1.28      paf       184: #ifndef _qsort
                    185: #      define _qsort(names,cnt,sizeof_names,func_addr) \
                    186:                qsort(names,cnt,sizeof_names,func_addr)
                    187: #endif
1.34      paf       188: 
1.40      paf       189: bool StrEqNc(const char *s1, const char *s2, bool strict=true);
1.45      parser    190: 
                    191: #define SECS_PER_DAY (60*60*24)
                    192: int getMonthDays(int year, int month);
1.52      parser    193: 
                    194: void remove_crlf(char *start, char *end);
1.1       paf       195: 
                    196: #endif

E-mail: