--- parser3/src/main/pa_common.C 2001/10/16 07:51:07 1.72 +++ parser3/src/main/pa_common.C 2001/10/29 13:04:46 1.78 @@ -4,7 +4,7 @@ Copyright(c) 2001 ArtLebedev Group(http://www.artlebedev.com) Author: Alexander Petrosyan (http://design.ru/paf) - $Id: pa_common.C,v 1.72 2001/10/16 07:51:07 parser Exp $ + $Id: pa_common.C,v 1.78 2001/10/29 13:04:46 paf Exp $ */ #include "pa_common.h" @@ -42,8 +42,7 @@ int __snprintf(char *b, size_t s, const #endif -// under WIN32 "t" mode fixes DOS chars OK, can't say that about other systems/ line break styles -static void fix_line_breaks(char *src, size_t& size) { +void fix_line_breaks(char *src, size_t& size) { char *dest=src; // fix DOS: \r\n -> \n // fix Macintosh: \r -> \n @@ -97,7 +96,7 @@ bool file_read(Pool& pool, const String& data=0; read_size=0; } else { - data=pool.malloc(max_size+(as_text?1:0)); + data=pool.malloc(max_size+(as_text?1:0), 3); if(offset) lseek(f, offset, SEEK_SET); read_size=read(f, data, max_size); @@ -112,7 +111,7 @@ bool file_read(Pool& pool, const String& if(as_text) ((char*&)data)[read_size]=0; } else - PTHROW(0, 0, + throw Exception(0, 0, &file_spec, "read failed: actually read %d bytes count not in [0..%lu] valid range", read_size, (unsigned long)max_size); //never @@ -122,7 +121,7 @@ bool file_read(Pool& pool, const String& return true; } if(fail_on_read_problem) - PTHROW(0, 0, + throw Exception(0, 0, &file_spec, "read failed: %s (%d), actual filename '%s'", strerror(errno), errno, fname); @@ -171,7 +170,7 @@ void file_write(Pool& pool, return; } } - PTHROW(0, 0, + throw Exception(0, 0, &file_spec, "write failed: %s (%d), actual filename '%s'", strerror(errno), errno, fname); @@ -188,7 +187,7 @@ static void rmdir(const String& file_spe void file_delete(Pool& pool, const String& file_spec) { const char *fname=file_spec.cstr(String::UL_FILE_SPEC); if(unlink(fname)!=0) - PTHROW(0, 0, + throw Exception(0, 0, &file_spec, "unlink failed: %s (%d), actual filename '%s'", strerror(errno), errno, fname); @@ -202,7 +201,7 @@ void file_move(Pool& pool, const String& create_dir_for_file(new_spec); if(rename(old_spec_cstr, new_spec_cstr)!=0) - PTHROW(0, 0, + throw Exception(0, 0, &old_spec, "rename failed: %s (%d), actual filename '%s' to '%s'", strerror(errno), errno, old_spec_cstr, new_spec_cstr); @@ -215,7 +214,7 @@ static bool entry_readable(const String& const char *fname=file_spec.cstr(String::UL_FILE_SPEC); struct stat finfo; if(access(fname, R_OK)==0 && stat(fname, &finfo)==0) { - bool is_dir=(bool)(finfo.st_mode&S_IFDIR); + bool is_dir=finfo.st_mode&S_IFDIR != 0; return is_dir==need_dir; } return false; @@ -247,7 +246,7 @@ bool file_stat(const String& file_spec, struct stat finfo; if(stat(fname, &finfo)!=0) if(fail_on_read_problem) - PTHROW(0, 0, + throw Exception(0, 0, &file_spec, "getting file size failed: %s (%d), real filename '%s'", strerror(errno), errno, fname); @@ -303,7 +302,7 @@ char *rsplit(char *string, char delim) { /// @todo less stupid type detection char *format(Pool& pool, double value, char *fmt) { - char *result=(char *)pool.malloc(MAX_NUMBER); + char *result=(char *)pool.malloc(MAX_NUMBER, 4); if(fmt) if(strpbrk(fmt, "diouxX")) if(strpbrk(fmt, "ouxX")) @@ -334,8 +333,8 @@ size_t stdout_write(const void *buf, siz #endif } -const char *unescape_chars(Pool& pool, const char *cp, int len) { - char *s=(char *)pool.malloc(len + 1); +char *unescape_chars(Pool& pool, const char *cp, int len) { + char *s=(char *)pool.malloc(len + 1, 5); enum EscapeState { EscapeRest, EscapeFirst, @@ -393,7 +392,7 @@ static void append_attribute_subattribut const String& attributed_meaning_to_string(Value& meaning, String::Untaint_lang lang) { String &result=*new(meaning.pool()) String(meaning.pool()); - if(Hash *hash=meaning.get_hash()) { + if(Hash *hash=meaning.get_hash(0)) { // $value(value) $subattribute(subattribute value) if(Value *value=static_cast(hash->get(*value_name))) result.append(value->as_string(), lang, true); @@ -475,4 +474,4 @@ void remove_crlf(char *start, char *end) case '\n': *p='|'; break; case '\r': *p=' '; break; } -} \ No newline at end of file +}