Annotation of parser3/src/main/pa_uue.C, revision 1.1
1.1 ! paf 1: /** @file
! 2: Parser: uuencoding impl.
! 3:
! 4: Copyright(c) 2000,2001, 2002 ArtLebedev Group(http://www.artlebedev.com)
! 5: Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
! 6:
! 7: $Id: pa_exec.C,v 1.35 2002/04/16 09:38:49 paf Exp $
! 8:
! 9:
! 10: @todo setrlimit
! 11: */
! 12:
! 13: #include "pa_config_includes.h"
! 14:
! 15: #include "pa_uue.h"
! 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: };
! 27: void pa_uuencode(String& result, const char *file_name_cstr, const VFile& vfile) {
! 28: //header
! 29: result << "content-transfer-encoding: x-uuencode\n" << "\n";
! 30: result << "begin 644 " << file_name_cstr << "\n";
! 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:
! 43: char *buf=(char *)result.pool().malloc(MAX_STRING);
! 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
! 85: result.APPEND_AS_IS((const char *)uue_table, 1/* one char */, 0, 0) << "\n"
! 86: "end\n";
! 87: }
E-mail: