--- parser3/src/main/pa_common.C 2001/04/03 07:32:46 1.37 +++ parser3/src/main/pa_common.C 2001/04/10 07:40:50 1.43 @@ -6,7 +6,7 @@ Author: Alexander Petrosyan (http://design.ru/paf) - $Id: pa_common.C,v 1.37 2001/04/03 07:32:46 paf Exp $ + $Id: pa_common.C,v 1.43 2001/04/10 07:40:50 paf Exp $ */ #include "pa_config_includes.h" @@ -16,6 +16,7 @@ #include #include #include +#include #include "pa_common.h" #include "pa_types.h" @@ -53,7 +54,7 @@ char *file_read_text(Pool& pool, const S bool file_read(Pool& pool, const String& file_spec, void*& data, size_t& size, bool as_text, bool fail_on_read_problem) { - char *fname=file_spec.cstr(); + char *fname=file_spec.cstr(String::UL_FILE_NAME); int f; struct stat finfo; @@ -94,12 +95,13 @@ bool file_read(Pool& pool, const String& return false; } +/// @test mkdirs void file_write(Pool& pool, const String& file_spec, const void *data, size_t size, bool as_text/*, bool exclusive*/) { - char *fname=file_spec.cstr(); + char *fname=file_spec.cstr(String::UL_FILE_NAME); int f; if(access(fname, F_OK)!=0) {/*no*/ if((f=open(fname, O_WRONLY|O_CREAT|_O_BINARY, 0666))>0) @@ -131,14 +133,17 @@ void file_write(Pool& pool, } void file_delete(Pool& pool, const String& file_spec) { - if(unlink(file_spec.cstr())!=0) + if(unlink(file_spec.cstr(String::UL_FILE_NAME))!=0) PTHROW(0, 0, &file_spec, "unlink failed: %s (#%d)", strerror(errno), errno); } bool file_readable(const String& file_spec) { - return access(file_spec.cstr(), R_OK)==0; + return access(file_spec.cstr(String::UL_FILE_NAME), R_OK)==0; +} +bool file_executable(const String& file_spec) { + return access(file_spec.cstr(String::UL_FILE_NAME), X_OK)==0; } char *getrow(char **row_ref, char delim) { @@ -253,29 +258,39 @@ const char *unescape_chars(Pool& pool, c return s; } +struct Attributed_meaning_info { + String::Untaint_lang lang; + String *header; +}; static void append_attribute_subattribute(const Hash::Key& akey, Hash::Val *avalue, void *info) { if(akey==VALUE_NAME) return; + Attributed_meaning_info& ami=*static_cast(info); + // ...; charset=windows1251 - String *string=static_cast(info); - string->APPEND_CONST("; "); - string->append(akey, String::UL_HEADER, true); - string->APPEND_CONST("="); - string->append(static_cast(avalue)->as_string(), - String::UL_HEADER, true); + if(ami.header->size()) + ami.header->APPEND_CONST("; "); + ami.header->append(akey, ami.lang, true); + ami.header->APPEND_CONST("="); + ami.header->append(static_cast(avalue)->as_string(), + ami.lang, true); } -const String& attributed_meaning_to_string(Value& meaning) { +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()) { // $value(value) $subattribute(subattribute value) if(Value *value=static_cast(hash->get(*value_name))) - result.append(value->as_string(), String::UL_HEADER, true); + result.append(value->as_string(), lang, true); - hash->for_each(append_attribute_subattribute, &result); + Attributed_meaning_info attributed_meaning_info={ + lang, + &result + }; + hash->for_each(append_attribute_subattribute, &attributed_meaning_info); } else // result value - result.append(meaning.as_string(), String::UL_HEADER, true); + result.append(meaning.as_string(), lang, true); return result; } @@ -287,4 +302,31 @@ void back_slashes_to_slashes(char *s) { if(*s=='\\') *s='/'; } +/* +void slashes_to_back_slashes(char *s) { + if(s) + for(; *s; s++) + if(*s=='/') + *s='\\'; +} +*/ #endif + +bool StrEqNc(const char *s1, const char *s2, bool strict) { + while(true) { + if(!(*s1)) { + if(!(*s2)) + return true; + else + return !strict; + } else if(!(*s2)) + return !strict; + if(isalpha(*s1)) { + if(tolower(*s1) !=tolower(*s2)) + return false; + } else if((*s1) !=(*s2)) + return false; + s1++; + s2++; + } +}