Annotation of parser3/src/main/pa_uue.C, revision 1.11
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.11 ! misha 10: static const char * const IDENT_UUE_C="$Date: 2007/10/02 17:24:29 $";
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
1.5 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.10 misha 43: char *buf=new(PointerFreeGC) char[UUE_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.8 paf 85: result<< "`\n"
1.1 paf 86: "end\n";
87: }
E-mail: