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