uucode.h File Reference

#include <ndb_global.h>

Go to the source code of this file.

Functions

int uudecode (FILE *input, char *outBuf, int bufLen)
int uudecode_mem (char *dst, int dst_len, const char *src)
void uuencode (const char *data, int dataLen, FILE *out)
int uuencode_mem (char *dst, const char *src, int src_len)


Function Documentation

int uudecode FILE *  input,
char *  outBuf,
int  bufLen
 

Definition at line 81 of file uucode.c.

References buf, DEC, n, and p.

00081                                                  {
00082   int n;
00083   char ch, *p, returnCode;
00084   char buf[255];
00085 
00086   returnCode = 0;
00087   /* search for header line */
00088   do {
00089     if (!fgets(buf, sizeof(buf), input)) {
00090       return 1;
00091     }
00092   } while (strncmp(buf, "begin", 5));
00093   
00094   /* for each input line */
00095   for (;;) {
00096     if (!fgets(p = buf, sizeof(buf), input)) {
00097       return 1;
00098     }
00099     /*
00100      * `n' is used to avoid writing out all the characters
00101      * at the end of the file.
00102      */
00103     if ((n = DEC(*p)) <= 0)
00104       break;
00105     if(n >= bufLen){
00106       returnCode = 1;
00107       break;
00108     }
00109     for (++p; n > 0; p += 4, n -= 3)
00110       if (n >= 3) {
00111         ch = DEC(p[0]) << 2 | DEC(p[1]) >> 4;
00112         * outBuf = ch; outBuf++; bufLen--;
00113         ch = DEC(p[1]) << 4 | DEC(p[2]) >> 2;
00114         * outBuf = ch; outBuf++; bufLen--;
00115         ch = DEC(p[2]) << 6 | DEC(p[3]);
00116         * outBuf = ch; outBuf++; bufLen--;
00117       } else {
00118         if (n >= 1) {
00119           ch = DEC(p[0]) << 2 | DEC(p[1]) >> 4;
00120           * outBuf = ch; outBuf++; bufLen--;
00121         }
00122         if (n >= 2) {
00123           ch = DEC(p[1]) << 4 | DEC(p[2]) >> 2;
00124           * outBuf = ch; outBuf++; bufLen--;
00125         }
00126         if (n >= 3) {
00127           ch = DEC(p[2]) << 6 | DEC(p[3]);
00128           * outBuf = ch; outBuf++; bufLen--;
00129         }
00130       }
00131   }
00132   if (!fgets(buf, sizeof(buf), input) || strcmp(buf, "end\n")) {
00133     return 1;
00134   }
00135   return returnCode;
00136 }

int uudecode_mem char *  dst,
int  dst_len,
const char *  src
 

Definition at line 192 of file uucode.c.

References DEC, n, and p.

00192                                                          {
00193   int n;
00194   char ch;
00195   int sz = 0;
00196   const char * p = src;
00197 
00198   /*
00199    * `n' is used to avoid writing out all the characters
00200    * at the end of the file.
00201    */
00202   if ((n = DEC(*p)) <= 0)
00203     return 0;
00204   if(n >= bufLen){
00205     return -1;
00206   }
00207   for (++p; n > 0; p += 4, n -= 3){
00208     if (n >= 3) {
00209       ch = DEC(p[0]) << 2 | DEC(p[1]) >> 4;
00210       * outBuf = ch; outBuf++; bufLen--; sz++;
00211       ch = DEC(p[1]) << 4 | DEC(p[2]) >> 2;
00212       * outBuf = ch; outBuf++; bufLen--; sz++;
00213       ch = DEC(p[2]) << 6 | DEC(p[3]);
00214       * outBuf = ch; outBuf++; bufLen--; sz++;
00215     } else {
00216       if (n >= 1) {
00217         ch = DEC(p[0]) << 2 | DEC(p[1]) >> 4;
00218         * outBuf = ch; outBuf++; bufLen--; sz++;
00219       }
00220       if (n >= 2) {
00221         ch = DEC(p[1]) << 4 | DEC(p[2]) >> 2;
00222         * outBuf = ch; outBuf++; bufLen--; sz++;
00223       }
00224       if (n >= 3) {
00225         ch = DEC(p[2]) << 6 | DEC(p[3]);
00226         * outBuf = ch; outBuf++; bufLen--; sz++;
00227       }
00228     }
00229   }
00230   return sz;
00231 }

void uuencode const char *  data,
int  dataLen,
FILE *  out
 

Definition at line 29 of file uucode.c.

References ENC, n, and p.

00030 {
00031   int ch, n;
00032   const char *p = data;
00033 
00034   fprintf(out, "begin\n");
00035   
00036   while (dataLen > 0){
00037     n = dataLen > 45 ? 45 : dataLen;
00038     dataLen -= n;
00039     ch = ENC(n);
00040     if (putc(ch, out) == EOF)
00041       break;
00042     for (; n > 0; n -= 3, p += 3) {
00043       char p_0 = * p;
00044       char p_1 = 0;
00045       char p_2 = 0;
00046 
00047       if(n >= 2){
00048         p_1 = p[1];
00049       }
00050       if(n >= 3){
00051         p_2 = p[2];
00052       }
00053       
00054       ch = p_0 >> 2;
00055       ch = ENC(ch);
00056       if (putc(ch, out) == EOF)
00057         break;
00058       ch = ((p_0 << 4) & 060) | ((p_1 >> 4) & 017);
00059       ch = ENC(ch);
00060       if (putc(ch, out) == EOF)
00061         break;
00062       ch = ((p_1 << 2) & 074) | ((p_2 >> 6) & 03);
00063       ch = ENC(ch);
00064       if (putc(ch, out) == EOF)
00065         break;
00066       ch = p_2 & 077;
00067       ch = ENC(ch);
00068       if (putc(ch, out) == EOF)
00069         break;
00070     }
00071     if (putc('\n', out) == EOF)
00072       break;
00073   }
00074   ch = ENC('\0');
00075   putc(ch, out);
00076   putc('\n', out);
00077   fprintf(out, "end\n");
00078 }

int uuencode_mem char *  dst,
const char *  src,
int  src_len
 

Definition at line 139 of file uucode.c.

References ENC, n, and p.

Referenced by MgmApiSession::getConfig_common().

00140 {
00141   int sz = 0;
00142 
00143   int ch, n;
00144   const char *p = data;
00145   
00146   while (dataLen > 0){
00147     n = dataLen > 45 ? 45 : dataLen;
00148     dataLen -= n;
00149     ch = ENC(n);
00150     * dst = ch; dst++; sz++;
00151     for (; n > 0; n -= 3, p += 3) {
00152       char p_0 = * p;
00153       char p_1 = 0;
00154       char p_2 = 0;
00155 
00156       if(n >= 2){
00157         p_1 = p[1];
00158       }
00159       if(n >= 3){
00160         p_2 = p[2];
00161       }
00162       
00163       ch = p_0 >> 2;
00164       ch = ENC(ch);
00165       * dst = ch; dst++; sz++;
00166 
00167       ch = ((p_0 << 4) & 060) | ((p_1 >> 4) & 017);
00168       ch = ENC(ch);
00169       * dst = ch; dst++; sz++;
00170 
00171       ch = ((p_1 << 2) & 074) | ((p_2 >> 6) & 03);
00172       ch = ENC(ch);
00173       * dst = ch; dst++; sz++;
00174 
00175       ch = p_2 & 077;
00176       ch = ENC(ch);
00177       * dst = ch; dst++; sz++;
00178     }
00179     
00180     * dst = '\n'; dst++; sz++;
00181   }
00182   ch = ENC('\0');
00183   * dst = ch; dst++; sz++;
00184   
00185   * dst = '\n'; dst++; sz++;
00186   * dst = 0;    dst++; sz++;
00187   
00188   return sz;
00189 }


Generated on Wed Jul 20 21:09:35 2005 for MySQL 5.0.9 Beta by  doxygen 1.4.3