1 | /* |
1 | /* |
2 | * This file is part of uudeview, the simple and friendly multi-part multi- |
2 | * This file is part of uudeview, the simple and friendly multi-part multi- |
3 | * file uudecoder program (c) 1994 by Frank Pilhofer. The author may be |
3 | * file uudecoder program (c) 1994-2001 by Frank Pilhofer. The author may |
4 | * contacted by his email address, fp@informatik.uni-frankfurt.de |
4 | * be contacted at fp@fpx.de |
5 | * |
5 | * |
6 | * This program is free software; you can redistribute it and/or modify |
6 | * This program is free software; you can redistribute it and/or modify |
7 | * it under the terms of the GNU General Public License as published by |
7 | * it under the terms of the GNU General Public License as published by |
8 | * the Free Software Foundation; either version 2 of the License, or |
8 | * the Free Software Foundation; either version 2 of the License, or |
9 | * (at your option) any later version. |
9 | * (at your option) any later version. |
… | |
… | |
47 | #endif |
47 | #endif |
48 | #ifdef HAVE_ERRNO_H |
48 | #ifdef HAVE_ERRNO_H |
49 | #include <errno.h> |
49 | #include <errno.h> |
50 | #endif |
50 | #endif |
51 | |
51 | |
52 | #include <uulib.h> |
52 | #include <uudeview.h> |
53 | #include <uuint.h> |
53 | #include <uuint.h> |
54 | #include <fptools.h> |
54 | #include <fptools.h> |
55 | #include <uustring.h> |
55 | #include <uustring.h> |
56 | |
56 | |
57 | char * uunconc_id = "$Id: uunconc.c,v 1.1 2001/06/11 19:49:00 root Exp $"; |
57 | char * uunconc_id = "$Id: uunconc.c,v 1.2 2001/06/11 20:42:37 root Exp $"; |
58 | |
58 | |
59 | /* for braindead systems */ |
59 | /* for braindead systems */ |
60 | #ifndef SEEK_SET |
60 | #ifndef SEEK_SET |
61 | #ifdef L_BEGIN |
61 | #ifdef L_BEGIN |
62 | #define SEEK_SET L_BEGIN |
62 | #define SEEK_SET L_BEGIN |
… | |
… | |
163 | UUxlat['`'] = UUxlat[' ']; |
163 | UUxlat['`'] = UUxlat[' ']; |
164 | UUxlat['~'] = UUxlat['^']; |
164 | UUxlat['~'] = UUxlat['^']; |
165 | |
165 | |
166 | /* prepare line length table */ |
166 | /* prepare line length table */ |
167 | UUxlen[0] = 1; |
167 | UUxlen[0] = 1; |
168 | for(i = 1, j = 5; i <= 60; i += 3, j += 4) |
168 | for(i = 1, j = 5; i <= 61; i += 3, j += 4) |
169 | UUxlen[i] = UUxlen[i+1] = UUxlen[i+2] = j; |
169 | UUxlen[i] = UUxlen[i+1] = UUxlen[i+2] = j; |
170 | |
170 | |
171 | /* prepare other tables */ |
171 | /* prepare other tables */ |
172 | for (i=0; i<64; i++) { |
172 | for (i=0; i<64; i++) { |
173 | B64xlat[ACAST(B64EncodeTable[i])] = i; |
173 | B64xlat[ACAST(B64EncodeTable[i])] = i; |
… | |
… | |
241 | /* |
241 | /* |
242 | * First pass |
242 | * First pass |
243 | */ |
243 | */ |
244 | while (*p1) { |
244 | while (*p1) { |
245 | if (*p1 == '&') { |
245 | if (*p1 == '&') { |
246 | if (FP_strnicmp (p1, "&", 5) == 0) { p1+=5; *p2++='&'; } |
246 | if (FP_strnicmp (p1, "&", 5) == 0) { p1+=5; *p2++='&'; res=1; } |
247 | else if (FP_strnicmp (p1, "<", 4) == 0) { p1+=4; *p2++='<'; } |
247 | else if (FP_strnicmp (p1, "<", 4) == 0) { p1+=4; *p2++='<'; res=1; } |
248 | else if (FP_strnicmp (p1, ">", 4) == 0) { p1+=4; *p2++='>'; } |
248 | else if (FP_strnicmp (p1, ">", 4) == 0) { p1+=4; *p2++='>'; res=1; } |
249 | else *p2++ = *p1++; |
249 | else *p2++ = *p1++; |
250 | res = 1; |
250 | res = 1; |
251 | } |
251 | } |
252 | else *p2++ = *p1++; |
252 | else *p2++ = *p1++; |
253 | } |
253 | } |
… | |
… | |
448 | * lowercase characters at least accepts the special case of encoding |
448 | * lowercase characters at least accepts the special case of encoding |
449 | * 0 as `. The strchr() shouldn't be too expensive here as it's only |
449 | * 0 as `. The strchr() shouldn't be too expensive here as it's only |
450 | * evaluated if the first character is lowercase, which really shouldn't |
450 | * evaluated if the first character is lowercase, which really shouldn't |
451 | * be in uuencoded text. |
451 | * be in uuencoded text. |
452 | */ |
452 | */ |
453 | if (len != j && |
453 | if (len != j && |
454 | !(*ptr != 'M' && *ptr != 'h' && len > j && len <= UUxlen[UUxlat['M']])) { |
454 | ((ptr[0] == '-' && ptr[1] == '-' && strstr(ptr,"part")!=NULL) || |
|
|
455 | !(*ptr != 'M' && *ptr != 'h' && |
|
|
456 | len > j && len <= UUxlen[UUxlat['M']]))) { |
455 | if (encoding==UU_ENCODED) return 0; |
457 | if (encoding==UU_ENCODED) return 0; |
456 | goto _t_XX; /* bad length */ |
458 | goto _t_XX; /* bad length */ |
457 | } |
459 | } |
458 | |
460 | |
459 | if (len != j || islower (*ptr)) { |
461 | if (len != j || islower (*ptr)) { |
… | |
… | |
859 | * with a linebreak. Or, as the docs put it, "the CRLF preceding the |
861 | * with a linebreak. Or, as the docs put it, "the CRLF preceding the |
860 | * encapsulation line is conceptually attached to the boundary. |
862 | * encapsulation line is conceptually attached to the boundary. |
861 | * So if the part ends here, don't print a line break" |
863 | * So if the part ends here, don't print a line break" |
862 | */ |
864 | */ |
863 | if ((*ptr == '\012' || *ptr == '\015') && |
865 | if ((*ptr == '\012' || *ptr == '\015') && |
864 | (!feof (datain) && |
|
|
865 | (ftell(datain)<maxpos || flags&FL_TOEND || flags&FL_PARTIAL || |
866 | (ftell(datain)<maxpos || flags&FL_TOEND || flags&FL_PARTIAL || |
866 | (!(flags&FL_PROPER) && uu_fast_scanning)))) { |
867 | !boundary || (!(flags&FL_PROPER) && uu_fast_scanning))) { |
867 | *ptr = '\0'; |
868 | *ptr = '\0'; |
868 | fprintf (dataout, "%s\n", line); |
869 | fprintf (dataout, "%s\n", line); |
869 | } |
870 | } |
870 | else { |
871 | else { |
871 | *ptr = '\0'; |
872 | *ptr = '\0'; |
… | |
… | |
1149 | return UURET_NODATA; |
1150 | return UURET_NODATA; |
1150 | |
1151 | |
1151 | if (data->state & UUFILE_NOBEGIN && !uu_desperate) |
1152 | if (data->state & UUFILE_NOBEGIN && !uu_desperate) |
1152 | return UURET_NODATA; |
1153 | return UURET_NODATA; |
1153 | |
1154 | |
1154 | if (data->uudet == QP_ENCODED || data->uudet == PT_ENCODED) |
1155 | if (data->uudet == PT_ENCODED) |
1155 | mode = "wt"; /* open text files in text mode */ |
1156 | mode = "wt"; /* open text files in text mode */ |
1156 | else |
1157 | else |
1157 | mode = "wb"; /* otherwise in binary */ |
1158 | mode = "wb"; /* otherwise in binary */ |
1158 | |
1159 | |
1159 | if ((data->binfile = tempnam (NULL, "uu")) == NULL) { |
1160 | if ((data->binfile = tempnam (NULL, "uu")) == NULL) { |