/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1998-2012 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* Glenn Fowler
* AT&T Research
*
*/
#include "uulib.h"
#include <ctype.h>
#include <error.h>
#include <ls.h>
#include <modex.h>
#include <sfdisc.h>
typedef struct
{
const char* name;
unsigned long flag;
} Option_t;
{
"text", UU_TEXT,
};
/*
* initialize the uu map from dp
*/
static unsigned char*
{
register int c;
register char* p;
register unsigned char* m;
int x;
p = map;
if (x)
{
p++;
}
return (unsigned char*)p;
}
/*
* grab uu header from input
*/
static int
{
register char* s;
register int c;
int n;
int k;
char* t;
c = *UU_BEGIN;
for (;;)
{
{
break;
}
{
while (*s == '-')
{
for (t = ++s; isalnum(*s); s++);
k = s - t;
for (n = 0; n < elementsof(options); n++)
{
break;
}
}
if (*s++ == ' ')
{
if (*t++ == ' ')
{
{
}
{
if (!(((Uudata_t*)uu->meth.data)->flags & UU_DEFAULT) && !streq(meth->id, uu->meth.id) && uu->disc->errorf)
}
return 0;
}
}
}
}
return -1;
}
/*
* uu encode input to output
*/
static int
{
register char* e;
register char* p;
register unsigned char* m;
register int c;
register int c1;
register int c2;
register int c3;
register unsigned long b;
int length;
int nl;
int pad;
int text;
{
c = 0644;
sfprintf(uu->op, "%s%s%s %03o %s\n", UU_BEGIN, uu->meth.id, text ? "-text" : "", c, uu->path ? uu->path : "-");
}
if (length)
nl = 0;
for (;;)
{
do {
if (nl)
{
nl = 0;
c1 = '\n';
goto get_2;
}
{
if (length)
goto eof;
}
{
c1 = '\r';
c2 = '\n';
goto get_3;
}
{
if (length)
*p++ = m[b >> 18];
*p++ = m[(b >> 12) & 077];
goto eof;
}
{
c2 = '\r';
c3 = '\n';
goto put_123;
}
{
if (length)
*p++ = m[b >> 18];
*p++ = m[(b >> 12) & 077];
*p++ = m[(b >> 6) & 077];
goto eof;
}
{
nl = 1;
c3 = '\r';
}
*p++ = m[b >> 18];
*p++ = m[(b >> 12) & 077];
*p++ = m[(b >> 6) & 077];
*p++ = m[b & 077];
} while (p < e);
*p++ = '\n';
}
eof:
{
*p++ = '\n';
}
if (length)
return 0;
}
/*
* uu decode input to output
*/
static int
{
register char* s;
register char* e;
register char* p;
register unsigned char* m;
register int c;
register unsigned long n;
int text;
int tl;
int x;
char* t;
if (uu->path && (uu->flags & UU_CLOSEOUT) && (dp->flags & uu->flags & UU_HEADER) && chmod(uu->path, uu->mode) && uu->disc->errorf)
(*uu->disc->errorf)(uu, uu->disc, ERROR_SYSTEM|2, "%s: cannot change mode to %s", uu->path, fmtperm(uu->mode));
{
while (((s = sfgetr(uu->ip, '\n', 0)) || (s = sfgetr(uu->ip, '\n', -1))) && ((n = sfvalue(uu->ip)) != tl || !strneq(s, t, tl - 1)))
if (c = m[*((unsigned char*)s++)])
{
if (c > sizeof(buf))
{
return -1;
}
p = buf;
while (s < e)
{
n = m[*((unsigned char*)s++)];
n = (n << 6) | ((s < e) ? m[*((unsigned char*)s++)] : 0);
n = (n << 6) | ((s < e) ? m[*((unsigned char*)s++)] : 0);
n = (n << 6) | ((s < e) ? m[*((unsigned char*)s++)] : 0);
if (text)
{
if ((x = (n >> 16) & 0xFF) == '\r')
c--;
else
*p++ = x;
if ((x = (n >> 8) & 0xFF) == '\r')
c--;
else
*p++ = x;
if ((x = n & 0xFF) == '\r')
c--;
else
*p++ = x;
}
else
{
*p++ = (n >> 16);
*p++ = (n >> 8);
*p++ = n;
}
}
}
}
else
{
for (;;)
{
if (c != UU_IGN)
goto pad;
n = c;
if (c != UU_IGN)
{
goto pad;
}
n = (n << 6) | c;
if (c != UU_IGN)
{
if (text)
{
if ((x = (n >> 4) & 0xFF) != '\r')
}
goto pad;
}
n = (n << 6) | c;
if (c != UU_IGN)
{
if (text)
{
if ((x = (n >> 10) & 0xFF) != '\r')
if ((x = (n >> 2) & 0xFF) != '\r')
}
else
{
}
goto pad;
}
n = (n << 6) | c;
if (text)
{
if ((x = (n >> 16) & 0xFF) != '\r')
if ((x = (n >> 8) & 0xFF) != '\r')
if ((x = n & 0xFF) != '\r')
}
else
{
}
}
pad:
n = c == UU_PAD;
break;
}
return 0;
}
/*
* quoted-printable encode input to output
*/
static int
{
register unsigned char* s;
register unsigned char* e;
register char* b;
register char* x;
register int c;
b = buf;
x = b + UULINE - 4;
while ((s = (unsigned char*)sfgetr(uu->ip, '\n', 0)) || (s = (unsigned char*)sfgetr(uu->ip, '\n', -1)))
{
switch (*s)
{
case 'F':
{
c = *s++;
goto quote;
}
break;
case '.':
if ((e - s) == 2)
{
c = *s++;
goto quote;
}
break;
}
while (s < e)
{
if ((c = *s++) == '\n')
{
*b++ = c;
b = buf;
break;
}
if (b >= x)
{
*b++ = '=';
*b++ = '\n';
b = buf;
}
if (c == ' ' || c == '\t')
{
if (s < e && *s != '\n')
{
*b++ = c;
continue;
}
}
{
*b++ = c;
continue;
}
*b++ = '=';
*b++ = hex[c & 0xF];
}
}
if (b > buf)
{
*b++ = '=';
*b++ = '\n';
}
return 0;
}
/*
* quoted-printable decode input to output
*/
static int
{
register unsigned char* s;
register unsigned char* b;
register unsigned char* x;
register int c;
register int d;
for (c = 0; c < elementsof(xeh); c++)
xeh[c] = -1;
{
{
while (b > s && ((c = *(b - 1)) == ' ' || c == '\t'))
b--;
*b = 0;
}
x = b = s;
for (;;)
{
switch (c = *s++)
{
case 0:
*b++ = '\n';
break;
case '=':
break;
*b++ = (c << 4) | d;
continue;
default:
*b++ = c;
continue;
}
break;
}
}
return 0;
}
/*
* binhex based on
*
* xbin Version 2.3 09/30/85
* Dave Johnson, Brown University Computer Science
*/
typedef struct
{
int col;
int eof;
int last;
int repeat;
unsigned long crc;
unsigned char* qp;
unsigned char* qe;
} Bx_t;
/*
* add c to the binhex Q format crc
*/
static int
{
register int i = 8;
register unsigned int k = c;
while (i--)
{
k <<= 1;
crc ^= k >> 8;
k &= 0xFF;
}
return c;
}
/*
* return next binhex Q format char
*/
static int
{
register int c;
register unsigned char* ip;
register unsigned char* ie;
register unsigned char* m;
int x;
unsigned long crc;
{
}
{
return EOF;
{
if (c != UU_IGN)
{
return EOF;
break;
}
*ip++ = c;
}
}
{
switch (x)
{
case EOF:
return EOF;
case 0:
c = BX_REPEAT;
break;
case 1:
break;
default:
break;
}
}
}
/*
* return binhex Q format n byte int
*/
static long
{
register long v = 0;
while (n--)
return v;
}
/*
* return binhex Q format buffer of size n
*/
static ssize_t
{
register int c;
register char* e;
e = s + n;
while (s < e)
{
return -1;
*s++ = c;
}
return n;
}
/*
* low level for bx_q_putc()
*/
static int
{
register unsigned char* p;
register unsigned char* m;
{
c = (p[0] << 16) | (p[1] << 8) | p[2];
{
}
}
return 0;
}
/*
* output binhex Q format char
*/
static int
{
{
{
}
{
}
}
else
{
{
}
if (c == BX_REPEAT)
{
}
{
}
else
{
}
}
return 0;
}
/*
* output binhex Q format n byte int
*/
static int
{
switch (n)
{
}
return 0;
}
/*
* grab binhex header from input
*/
static int
{
register int c;
register int bol;
register char* s;
register char* m;
unsigned long crc;
unsigned long crx;
do
{
{
return -1;
}
bol = 1;
for (;;)
{
{
case EOF:
return -1;
case '\n':
case '\r':
bol = 1;
break;
case ':':
if (bol)
{
/*
* Q format
*
* 1 n name length
* n s name
* 4 s type
* 4 s author
* 2 n flags
* 4 n data size
* 4 n resource size
* 2 n header checksum
*/
s['\n'] = UU_IGN;
s['\r'] = UU_IGN;
return -1;
return -1;
{
}
return -1;
return -1;
{
return -1;
}
return 0;
}
break;
case '#':
if (bol)
{
/*
* old format
*/
/*
* #<TYPE><AUTH>$<flag>
*/
return -1;
return 0;
}
break;
default:
bol = 0;
break;
}
}
}
/*
* old binhex line decode
*/
static int
{
register int c;
register int d;
register char* t = (char*)hex;
register unsigned char* s = (unsigned char*)buf;
for (c = 0; c < elementsof(hex); c++)
m[t[c]] = c;
n <= 2;
while (n--)
{
return -1;
crc += c = (c << 4) | d;
}
return 0;
}
/*
* old binhex compressed line decode
*/
static int
{
register int c;
register int oc;
register unsigned long crc;
char* e;
int ic;
if (ic > SF_BUFSIZE)
ic = SF_BUFSIZE;
if (n > SF_BUFSIZE)
n = SF_BUFSIZE;
s = buf + n;
while (s < e)
*s++ = ' ';
s = buf;
while ((oc -= 3) >= 0)
{
s += 4;
}
return 0;
}
/*
* binhex decode input to output
*/
static int
{
register off_t n;
register int c;
register char* s;
unsigned long crc;
crc = 0x10000;
{
c = 0;
if (*s++ == '*' && *s++ == '*' && *s++ == '*')
{
switch (*s)
{
case 'C':
switch (s[1])
{
case 'O':
continue;
continue;
case 'H':
continue;
break;
case 'R':
continue;
break;
default:
continue;
}
break;
case 'D':
continue;
{
break;
return -1;
}
break;
case 'R':
continue;
c = 1;
continue;
default:
continue;
}
break;
}
}
else
{
while (n--)
{
return -1;
}
/*
* check the header crc
*/
}
{
{
if (crc == 0x10000)
else
}
return -1;
}
return 0;
}
/*
* binhex encode input to output
*/
static int
{
register unsigned char* m;
register int c;
register int i;
m = (unsigned char*)"-";
if ((c = strlen((char*)m)) > 63)
c = 63;
for (i = 0; i < c; i++)
return 0;
}
/*
* cat input to output
*/
static int
{
}
{
"end",
0,
0,
0,
" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_"
};
{
"end",
0,
0156,
0,
"`!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_"
};
{
"====",
'=',
0,
0,
0,
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
};
{
0,
0,
0,
sizeof(Bx_t),
"!\"#$%&'()*+,-012345689@ABCDEFGHIJKLMNPQRSTUVXYZ[`abcdefhijklmpqr"
};
{
{
"posix", "uuencode", "",
},
{
"ucb", "bsd", "",
},
{
"mime", "base64", "-base64",
},
{
"quoted-printable", "qp", "",
},
{
"binhex", "mac-binhex", "",
},
{
"sevenbit", "7bit", "",
},
{ 0 }
};
/*
* list the method names/alternates on fp
*/
int
{
return 0;
}
/*
* return method pointer given name
*/
{
register int c;
register const char* v;
register int vl;
const char* np;
/*
* first entry is the default
*/
{
}
name += 2;
{
/*
* id prefix match
*/
if (c == '-')
}
else
{
c = *name;
/*
* exact name or alias match
*/
for (;;)
{
mp->alias && *mp->alias == c && (!strcasecmp(name, mp->alias) || vl && !strncasecmp(name, mp->alias, vl)))
break;
c = *(name += 2);
if (vl)
}
/*
* first char name match
*/
}
return 0;
}
/*
*/
Uu_t*
{
int extra;
else
extra = 0;
return 0;
return uu;
}
/*
*/
int
{
if (!uu)
return -1;
return 0;
}
/*
*/
static ssize_t
{
int n;
ssize_t r;
Sfoff_t p;
if (uu->count != SF_UNBOUND && ((p = sfseek(uu->ip, (Sfoff_t)0, SEEK_CUR)) < 0 || !(uu->ip = sfdcsubstream(NiL, uu->lp = uu->ip, p, uu->count))))
{
(*uu->disc->errorf)(uu, uu->disc, 2, "cannot initialize substream at %I*d for %I*d bytes", sizeof(p), p, sizeof(uu->count), uu->count);
return -1;
}
{
}
if (n < 0)
r = -1;
{
r = -1;
}
{
r = -1;
}
else
{
}
return r;
}
/*
* encode n bytes (or all if SF_UNBOUND) from ip to op
*/
{
{
return -1;
}
return -1;
}
/*
* decode n bytes (or all if SF_UNBOUND) from ip to op
*/
{
register char* s;
unsigned char* m;
int c;
int headerpath;
{
return -1;
}
return -1;
{
return -1;
headerpath = 1;
}
else
{
headerpath = 0;
{
{
break;
}
{
}
}
}
{
{
return -1;
}
else
{
{
*s = '_';
s[1] = '_';
}
{
return -1;
}
}
}
}