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