--- parser3/src/main/pa_common.C 2001/10/31 14:01:45 1.80 +++ parser3/src/main/pa_common.C 2001/11/09 11:06:57 1.86 @@ -2,9 +2,9 @@ Parser: commonly functions. Copyright(c) 2001 ArtLebedev Group(http://www.artlebedev.com) - Author: Alexander Petrosyan (http://design.ru/paf) + Author: Alexander Petrosyan (http://paf.design.ru) - $Id: pa_common.C,v 1.80 2001/10/31 14:01:45 paf Exp $ + $Id: pa_common.C,v 1.86 2001/11/09 11:06:57 paf Exp $ */ #include "pa_common.h" @@ -16,15 +16,12 @@ #include "pa_hash.h" #include "pa_string.h" -#ifdef WIN32 -# ifndef _O_TEXT -# define _O_TEXT 0 -# endif -# ifndef _O_BINARY -# define _O_BINARY 0 -# endif +#ifndef _O_TEXT +# define _O_TEXT 0 +#endif +#ifndef _O_BINARY +# define _O_BINARY 0 #endif - #ifndef O_TRUNC # define O_TRUNC 0 #endif @@ -46,12 +43,22 @@ int __snprintf(char *b, size_t s, const #endif -void fix_line_breaks(char *cstr, size_t& size) { +static char *strnchr(char *buf, size_t size, char c) { + for(; size-->0; buf++) { + if(*buf==c) + return buf; + } + + return 0; +} + +void fix_line_breaks(char *buf, size_t& size) { + const char * const eob=buf+size; char *dest=cstr; // fix DOS: \r\n -> \n // fix Macintosh: \r -> \n char *bol=cstr; - while(char *eol=strchr(bol, '\r')) { + while(char *eol=strnchr(bol, eob -bol, '\r')) { size_t len=eol-bol; if(dest!=bol) memcpy(dest, bol, len); @@ -97,7 +104,11 @@ bool file_read(Pool& pool, const String& flock(f, LOCK_EX);*/ size_t max_size=limit?min(offset+limit, finfo.st_size)-offset:finfo.st_size; if(!max_size) { // eof - data=0; + if(as_text) { + data=pool.malloc(1); + *(char*)data=0; + } else + data=0; read_size=0; } else { data=pool.malloc(max_size+(as_text?1:0), 3); @@ -441,7 +452,7 @@ bool StrEqNc(const char *s1, const char } } -static int isLeap(int year) { +static bool isLeap(int year) { return !( (year % 4) || ((year % 400) && !(year % 100)) );