]>
Commit | Line | Data |
---|---|---|
e81957b7 | 1 | #include "util.h" |
2 | ||
3 | extern char** environ; | |
4 | ||
5 | /* aaaack but it's fast and const should make it shared text page. */ | |
6 | const int pr2six[256]={ | |
7 | 64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64, | |
8 | 64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,62,64,64,64,63, | |
9 | 52,53,54,55,56,57,58,59,60,61,64,64,64,64,64,64,64,0,1,2,3,4,5,6,7,8,9, | |
10 | 10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,64,64,64,64,64,64,26,27, | |
11 | 28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51, | |
12 | 64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64, | |
13 | 64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64, | |
14 | 64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64, | |
15 | 64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64, | |
16 | 64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64, | |
17 | 64,64,64,64,64,64,64,64,64,64,64,64,64 | |
18 | }; | |
19 | ||
20 | char *uudecode(char *bufcoded) { | |
21 | int nbytesdecoded; | |
22 | register unsigned char *bufin; | |
23 | register char *bufplain; | |
24 | register unsigned char *bufout; | |
25 | register int nprbytes; | |
26 | ||
27 | /* Strip leading whitespace. */ | |
28 | ||
29 | while(*bufcoded==' ' || *bufcoded == '\t') bufcoded++; | |
30 | ||
31 | /* Figure out how many characters are in the input buffer. | |
32 | * Allocate this many from the per-transaction pool for the result. | |
33 | */ | |
34 | bufin = (unsigned char *)bufcoded; | |
35 | while(pr2six[*(bufin++)] <= 63); | |
36 | nprbytes = (char *)bufin - bufcoded - 1; | |
37 | nbytesdecoded = ((nprbytes+3)/4) * 3; | |
38 | ||
39 | bufplain = xmalloc(nbytesdecoded + 1); | |
40 | if (bufplain == NULL) | |
41 | return(NULL); | |
42 | bufout = (unsigned char *)bufplain; | |
43 | ||
44 | bufin = (unsigned char *)bufcoded; | |
45 | ||
46 | while (nprbytes > 0) { | |
47 | *(bufout++) = | |
48 | (unsigned char) (pr2six[*bufin] << 2 | pr2six[bufin[1]] >> 4); | |
49 | *(bufout++) = | |
50 | (unsigned char) (pr2six[bufin[1]] << 4 | pr2six[bufin[2]] >> 2); | |
51 | *(bufout++) = | |
52 | (unsigned char) (pr2six[bufin[2]] << 6 | pr2six[bufin[3]]); | |
53 | bufin += 4; | |
54 | nprbytes -= 4; | |
55 | } | |
56 | ||
57 | if(nprbytes & 03) { | |
58 | if(pr2six[bufin[-2]] > 63) | |
59 | nbytesdecoded -= 2; | |
60 | else | |
61 | nbytesdecoded -= 1; | |
62 | } | |
63 | bufplain[nbytesdecoded] = '\0'; | |
64 | return bufplain; | |
65 | } |