Annotation of parser3/src/main/pa_uue.C, revision 1.8.14.1

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

E-mail: