--- parser3/src/main/pa_uue.C 2004/02/11 15:33:16 1.7 +++ parser3/src/main/pa_uue.C 2009/09/27 23:40:07 1.13 @@ -1,13 +1,13 @@ /** @file Parser: uuencoding impl. - Copyright(c) 2000,2001-2004 ArtLebedev Group(http://www.artlebedev.com) + Copyright(c) 2000-2009 ArtLebedev Group(http://www.artlebedev.com) Author: Alexandr Petrosian (http://paf.design.ru) @todo setrlimit */ -static const char * const IDENT_UUE_C="$Date: 2004/02/11 15:33:16 $"; +static const char * const IDENT_UUE_C="$Date: 2009/09/27 23:40:07 $"; #include "pa_config_includes.h" @@ -23,15 +23,24 @@ static unsigned char uue_table[64] = { 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '[', '\\',']', '^', '_' }; -void pa_uuencode(String& result, const String& file_name, const VFile& vfile) { - //header - result << "content-transfer-encoding: x-uuencode\n" << "\n"; - result << "begin 644 " << file_name << "\n"; - //body +const char* pa_uuencode(const String& file_name, const VFile& vfile) { const unsigned char *in=(const unsigned char *)vfile.value_ptr(); size_t in_length=vfile.value_size(); + const char* file_name_cstr = file_name.cstr(); + + size_t new_size=((in_length / 3 + 1) * 4); + new_size += 2 * new_size / 60/*chars in line + new lines*/ + 2; + new_size += strlen(file_name_cstr) + 11/*header*/ + 6/*footer*/ + 1/*zero terminator*/; + + const char* result=new(PointerFreeGC) char[new_size]; + char* optr=(char*)result; + + //header + optr += sprintf(optr, "begin 644 %s\n", file_name_cstr); + + //body int count=45; for(const unsigned char *itemp=in; itemp<(in+in_length); itemp+=count) { int index; @@ -39,9 +48,6 @@ void pa_uuencode(String& result, const S if((itemp+count)>(in+in_length)) count=in_length-(itemp-in); - char *buf=new(PointerFreeGC) char[MAX_STRING]; - char *optr=buf; - /* * for UU and XX, encode the number of bytes as first character */ @@ -76,11 +82,15 @@ void pa_uuencode(String& result, const S * end of line */ *optr++ = '\n'; - *optr = 0; - result << buf; } //footer - result.append_know_length((const char* )uue_table, 1/* one char */, String::L_AS_IS) << "\n" - "end\n"; -} + optr += sprintf(optr, "`\nend\n"); + + *optr = 0; + + //throw Exception(PARSER_RUNTIME, 0, "%d %d %d", in_length, new_size, (size_t)(optr-result)); + assert((size_t)(optr-result) < new_size); + + return result; +} \ No newline at end of file