20 #include <ndb_global.h>
24 #define ENC(c) ((c) ? ((c) & 077) + ' ': '`')
25 #define DEC(c) (((c) - ' ') & 077)
31 uuencode(
const char * data,
int dataLen, FILE * out)
36 fprintf(out,
"begin\n");
39 n = dataLen > 45 ? 45 : dataLen;
42 if (putc(ch, out) == EOF)
44 for (; n > 0; n -= 3, p += 3) {
58 if (putc(ch, out) == EOF)
60 ch = ((p_0 << 4) & 060) | ((p_1 >> 4) & 017);
62 if (putc(ch, out) == EOF)
64 ch = ((p_1 << 2) & 074) | ((p_2 >> 6) & 03);
66 if (putc(ch, out) == EOF)
70 if (putc(ch, out) == EOF)
73 if (putc(
'\n', out) == EOF)
79 fprintf(out,
"end\n");
83 uudecode(FILE * input,
char * outBuf,
int bufLen){
85 char ch, *p, returnCode;
91 if (!fgets(buf,
sizeof(buf), input)) {
94 }
while (strncmp(buf,
"begin", 5));
98 if (!fgets(p = buf,
sizeof(buf), input)) {
105 if ((n = DEC(*p)) <= 0)
111 for (++p; n > 0; p += 4, n -= 3)
113 ch = DEC(p[0]) << 2 | DEC(p[1]) >> 4;
114 * outBuf = ch; outBuf++; bufLen--;
115 ch = DEC(p[1]) << 4 | DEC(p[2]) >> 2;
116 * outBuf = ch; outBuf++; bufLen--;
117 ch = DEC(p[2]) << 6 | DEC(p[3]);
118 * outBuf = ch; outBuf++; bufLen--;
121 ch = DEC(p[0]) << 2 | DEC(p[1]) >> 4;
122 * outBuf = ch; outBuf++; bufLen--;
125 ch = DEC(p[1]) << 4 | DEC(p[2]) >> 2;
126 * outBuf = ch; outBuf++; bufLen--;
129 ch = DEC(p[2]) << 6 | DEC(p[3]);
130 * outBuf = ch; outBuf++; bufLen--;
134 if (!fgets(buf,
sizeof(buf), input) || strcmp(buf,
"end\n")) {
141 uuencode_mem(
char * dst,
const char * data,
int dataLen)
146 const char *p = data;
149 n = dataLen > 45 ? 45 : dataLen;
152 * dst = ch; dst++; sz++;
153 for (; n > 0; n -= 3, p += 3) {
167 * dst = ch; dst++; sz++;
169 ch = ((p_0 << 4) & 060) | ((p_1 >> 4) & 017);
171 * dst = ch; dst++; sz++;
173 ch = ((p_1 << 2) & 074) | ((p_2 >> 6) & 03);
175 * dst = ch; dst++; sz++;
179 * dst = ch; dst++; sz++;
182 * dst =
'\n'; dst++; sz++;
185 * dst = ch; dst++; sz++;
187 * dst =
'\n'; dst++; sz++;
188 * dst = 0; dst++; sz++;
194 uudecode_mem(
char * outBuf,
int bufLen,
const char * src){
198 const char * p = src;
204 if ((n = DEC(*p)) <= 0)
209 for (++p; n > 0; p += 4, n -= 3){
211 ch = DEC(p[0]) << 2 | DEC(p[1]) >> 4;
212 * outBuf = ch; outBuf++; bufLen--; sz++;
213 ch = DEC(p[1]) << 4 | DEC(p[2]) >> 2;
214 * outBuf = ch; outBuf++; bufLen--; sz++;
215 ch = DEC(p[2]) << 6 | DEC(p[3]);
216 * outBuf = ch; outBuf++; bufLen--; sz++;
219 ch = DEC(p[0]) << 2 | DEC(p[1]) >> 4;
220 * outBuf = ch; outBuf++; bufLen--; sz++;
223 ch = DEC(p[1]) << 4 | DEC(p[2]) >> 2;
224 * outBuf = ch; outBuf++; bufLen--; sz++;
227 ch = DEC(p[2]) << 6 | DEC(p[3]);
228 * outBuf = ch; outBuf++; bufLen--; sz++;