Annotation of parser3/src/main/pa_uue.C, revision 1.10
1.1 paf 1: /** @file
2: Parser: uuencoding impl.
3:
1.9 paf 4: Copyright(c) 2000,2001-2005 ArtLebedev Group(http://www.artlebedev.com)
1.1 paf 5: Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
6:
7: @todo setrlimit
8: */
1.2 paf 9:
1.10 ! misha 10: static const char * const IDENT_UUE_C="$Date: 2005/08/09 08:14:52 $";
1.1 paf 11:
12: #include "pa_config_includes.h"
13:
14: #include "pa_uue.h"
15:
1.10 ! misha 16: #define UUE_MAX_STRING 0x40
! 17:
1.1 paf 18: static unsigned char uue_table[64] = {
19: '`', '!', '"', '#', '$', '%', '&', '\'',
20: '(', ')', '*', '+', ',', '-', '.', '/',
21: '0', '1', '2', '3', '4', '5', '6', '7',
22: '8', '9', ':', ';', '<', '=', '>', '?',
23: '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G',
24: 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
25: 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
26: 'X', 'Y', 'Z', '[', '\\',']', '^', '_'
27: };
1.5 paf 28: void pa_uuencode(String& result, const String& file_name, const VFile& vfile) {
1.1 paf 29: //header
30: result << "content-transfer-encoding: x-uuencode\n" << "\n";
1.5 paf 31: result << "begin 644 " << file_name << "\n";
1.1 paf 32:
33: //body
34: const unsigned char *in=(const unsigned char *)vfile.value_ptr();
35: size_t in_length=vfile.value_size();
36:
37: int count=45;
38: for(const unsigned char *itemp=in; itemp<(in+in_length); itemp+=count) {
39: int index;
40:
41: if((itemp+count)>(in+in_length))
42: count=in_length-(itemp-in);
43:
1.10 ! misha 44: char *buf=new(PointerFreeGC) char[UUE_MAX_STRING];
1.1 paf 45: char *optr=buf;
46:
47: /*
48: * for UU and XX, encode the number of bytes as first character
49: */
50: *optr++ = uue_table[count];
51:
52: for (index=0; index<=count-3; index+=3) {
53: *optr++ = uue_table[itemp[index] >> 2];
54: *optr++ = uue_table[((itemp[index ] & 0x03) << 4) | (itemp[index+1] >> 4)];
55: *optr++ = uue_table[((itemp[index+1] & 0x0f) << 2) | (itemp[index+2] >> 6)];
56: *optr++ = uue_table[ itemp[index+2] & 0x3f];
57: }
58:
59: /*
60: * Special handlitempg for itempcomplete litempes
61: */
62: if (index != count) {
63: if (count - index == 2) {
64: *optr++ = uue_table[itemp[index] >> 2];
65: *optr++ = uue_table[((itemp[index ] & 0x03) << 4) |
66: ( itemp[index+1] >> 4)];
67: *optr++ = uue_table[((itemp[index+1] & 0x0f) << 2)];
68: *optr++ = uue_table[0];
69: }
70: else if (count - index == 1) {
71: *optr++ = uue_table[ itemp[index] >> 2];
72: *optr++ = uue_table[(itemp[index] & 0x03) << 4];
73: *optr++ = uue_table[0];
74: *optr++ = uue_table[0];
75: }
76: }
77: /*
78: * end of line
79: */
80: *optr++ = '\n';
81: *optr = 0;
82: result << buf;
83: }
84:
85: //footer
1.8 paf 86: result<< "`\n"
1.1 paf 87: "end\n";
88: }
E-mail: