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

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.61    ! paf         7:        $Id: pa_common.h,v 1.60 2001/11/05 11:46:23 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.21      paf        19: #if _MSC_VER
1.56      paf        20: /*
                     21: inline int open( const char *filename, int oflag ) { return _open(filename, oflag); }
                     22: inline int close( int handle ) { return _close(handle); }
                     23: inline int read( int handle, void *buffer, unsigned int count ) { return _read(handle,buffer,count); }
                     24: inline int write( int handle, const void *buffer, unsigned int count ) { return _write(handle,buffer,count); }
                     25: inline int stat( const char *path, struct _stat *buffer ) { return _stat(path, buffer); }
                     26: inline long lseek( int handle, long offset, int origin ) { return _lseek(handle, offset, origin); }
                     27: */
1.1       paf        28: 
1.20      paf        29: #ifndef vsnprintf
1.42      paf        30: int __vsnprintf(char *, size_t, const char *, va_list);
1.20      paf        31: #      define vsnprintf __vsnprintf 
                     32: #endif
                     33: #ifndef snprintf
1.42      paf        34: int __snprintf(char *, size_t, const char *, ...);
1.20      paf        35: #      define snprintf __snprintf
                     36: #endif
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.17      paf        58: #endif
1.59      paf        59: 
1.61    ! paf        60: #ifdef HAVE_TRUNC
        !            61: #      ifndef trunc
        !            62: extern "C" double trunc(double);
        !            63: #      endif
        !            64: #else
1.59      paf        65: inline double trunc(double param) { return param > 0? floor(param) : ceil(param); }
                     66: #endif
1.61    ! paf        67: 
        !            68: #ifdef HAVE_ROUND
        !            69: #      ifndef round
        !            70: extern "C" double round(double);
        !            71: #      endif
        !            72: #else
1.59      paf        73: inline double round(double param) { return floor(param+0.5); }
                     74: #endif
1.61    ! paf        75: #ifdef HAVE_SIGN
        !            76: #      ifndef sign
        !            77: extern "C" double sign(double);
        !            78: #      endif
        !            79: #else
1.59      paf        80: inline double sign(double param) { return param > 0 ? 1 : ( param < 0 ? -1 : 0 ); }
                     81: #endif
                     82: 
1.54      parser     83: 
                     84: /** under WIN32 "t" mode fixes DOS chars OK, 
                     85:        can't say that about other systems/ line break styles
                     86: */
1.57      paf        87: void fix_line_breaks(
                     88:                                         char *cstr,  ///< nevertheless must be 0 ended
                     89:                                         size_t& size ///< used to speedup next actions
                     90:                                         );
1.17      paf        91: 
1.15      paf        92: /**
1.19      paf        93:        read specified text file using pool, 
1.15      paf        94:        if fail_on_read_problem is true[default] throws an exception
                     95: */
1.19      paf        96: char *file_read_text(Pool& pool, 
1.25      paf        97:                                         const String& file_spec, 
1.19      paf        98:                                         bool fail_on_read_problem=true);
1.17      paf        99: 
                    100: /**
1.29      paf       101:        read specified file using pool, 
                    102:        if fail_on_read_problem is true[default] throws an exception
                    103: */
                    104: bool file_read(Pool& pool, const String& file_spec, 
                    105:                           void*& data, size_t& size, 
                    106:                           bool as_text,
1.37      paf       107:                           bool fail_on_read_problem=true,
                    108:                           size_t offset=0, size_t limit=0);
1.29      paf       109: 
                    110: /**
1.17      paf       111:        write data to specified file using pool, 
                    112:        throws an exception in case of problems
                    113: */
                    114: void file_write(Pool& pool, 
1.25      paf       115:                                const String& file_spec,
1.29      paf       116:                                const void *data, size_t size, 
1.58      paf       117:                                bool as_text,
                    118:                                bool do_append=false/*,
1.20      paf       119:                                bool exclusive=false*/);
1.26      paf       120: 
                    121: /**
                    122:        delete specified file 
                    123:        throws an exception in case of problems
                    124: */
                    125: void file_delete(Pool& pool, const String& file_spec);
1.47      parser    126: /**
                    127:        move specified file 
                    128:        throws an exception in case of problems
                    129: */
                    130: void file_move(Pool& pool, const String& old_spec, const String& new_spec);
1.27      paf       131: 
                    132: bool file_readable(const String& file_spec);
1.41      paf       133: bool dir_readable(const String& file_spec);
1.49      parser    134: String *file_readable(const String& path, const String& name);
1.36      paf       135: bool file_executable(const String& file_spec);
1.37      paf       136: 
1.48      parser    137: bool file_stat(const String& file_spec, 
1.46      parser    138:                           size_t& rsize, 
                    139:                           time_t& ratime,
                    140:                           time_t& rmtime,
1.48      parser    141:                           time_t& rctime,
                    142:                           bool fail_on_read_problem=true);
1.15      paf       143: 
                    144: /**
1.18      paf       145:        scans for @a delim[default \n] in @a *row_ref, 
                    146:        @return piece of line before it or end of string, if no @a delim found
                    147:        assigns @a *row_ref to point right after delimiter if there were one
                    148:        or to zero if no @a delim were found.
1.15      paf       149: */
1.7       paf       150: char *getrow(char **row_ref,char delim='\n');
1.22      paf       151: //char *lsplit(char *string, char delim);
1.7       paf       152: char *lsplit(char **string_ref,char delim);
1.8       paf       153: char *rsplit(char *string, char delim);
1.9       paf       154: char *format(Pool& pool, double value, char *fmt);
1.10      paf       155: 
                    156: #ifndef max
                    157: inline int max(int a,int b) { return a>b?a:b; }
                    158: inline int min(int a,int b){ return a<b?a:b; }
                    159: #endif
                    160: 
1.30      paf       161: size_t stdout_write(const void *buf, size_t size);
1.14      paf       162: 
1.55      parser    163: char *unescape_chars(Pool& pool, const char *cp, int len);
1.14      paf       164: 
1.24      paf       165: /**
                    166:        $content-type[text/html] -> 
1.32      paf       167:                content-type: text/html
1.24      paf       168:        $content-type[$value[text/html] charset[windows-1251]] -> 
1.32      paf       169:                content-type: text/html; charset=windows-1251
1.24      paf       170: */
1.33      paf       171: const String& attributed_meaning_to_string(Value& meaning, String::Untaint_lang lang);
1.23      paf       172: 
                    173: #ifdef WIN32
                    174: void back_slashes_to_slashes(char *s);
1.35      paf       175: //void slashes_to_back_slashes(char *s);
1.23      paf       176: #endif
                    177: 
1.28      paf       178: #ifndef _qsort
                    179: #      define _qsort(names,cnt,sizeof_names,func_addr) \
                    180:                qsort(names,cnt,sizeof_names,func_addr)
                    181: #endif
1.34      paf       182: 
1.40      paf       183: bool StrEqNc(const char *s1, const char *s2, bool strict=true);
1.45      parser    184: 
                    185: #define SECS_PER_DAY (60*60*24)
                    186: int getMonthDays(int year, int month);
1.52      parser    187: 
                    188: void remove_crlf(char *start, char *end);
1.1       paf       189: 
                    190: #endif

E-mail: