… | |
… | |
55 | #else |
55 | #else |
56 | #define SEEK_SET 0 |
56 | #define SEEK_SET 0 |
57 | #endif |
57 | #endif |
58 | #endif |
58 | #endif |
59 | |
59 | |
60 | char * uuencode_id = "$Id: uuencode.c,v 1.8 2020/02/27 06:14:29 root Exp $"; |
60 | char * uuencode_id = "$Id: uuencode.c,v 1.9 2020/12/10 22:49:15 root Exp $"; |
61 | |
61 | |
62 | #if 0 |
62 | #if 0 |
63 | /* |
63 | /* |
64 | * the End-Of-Line string. MIME enforces CRLF, so that's what we use. Some |
64 | * the End-Of-Line string. MIME enforces CRLF, so that's what we use. Some |
65 | * implementations of uudecode will complain about a missing end line, since |
65 | * implementations of uudecode will complain about a missing end line, since |
… | |
… | |
133 | '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', |
133 | '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', |
134 | 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', |
134 | 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', |
135 | 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', |
135 | 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', |
136 | 'X', 'Y', 'Z', '[', '\\',']', '^', '_' |
136 | 'X', 'Y', 'Z', '[', '\\',']', '^', '_' |
137 | }; |
137 | }; |
138 | |
138 | |
139 | |
139 | |
140 | unsigned char B64EncodeTable[64] = { |
140 | unsigned char B64EncodeTable[64] = { |
141 | 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', |
141 | 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', |
142 | 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', |
142 | 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', |
143 | 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', |
143 | 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', |
… | |
… | |
160 | }; |
160 | }; |
161 | |
161 | |
162 | unsigned char BHEncodeTable[64] = { |
162 | unsigned char BHEncodeTable[64] = { |
163 | '!', '"', '#', '$', '%', '&', '\'', '(', |
163 | '!', '"', '#', '$', '%', '&', '\'', '(', |
164 | ')', '*', '+', ',', '-', '0', '1', '2', |
164 | ')', '*', '+', ',', '-', '0', '1', '2', |
165 | '3', '4', '5', '6', '8', '9', '@', 'A', |
165 | '3', '4', '5', '6', '8', '9', '@', 'A', |
166 | 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', |
166 | 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', |
167 | 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', |
167 | 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', |
168 | 'S', 'T', 'U', 'V', 'X', 'Y', 'Z', '[', |
168 | 'S', 'T', 'U', 'V', 'X', 'Y', 'Z', '[', |
169 | '`', 'a', 'b', 'c', 'd', 'e', 'f', 'h', |
169 | '`', 'a', 'b', 'c', 'd', 'e', 'f', 'h', |
170 | 'i', 'j', 'k', 'l', 'm', 'p', 'q', 'r' |
170 | 'i', 'j', 'k', 'l', 'm', 'p', 'q', 'r' |
171 | }; |
171 | }; |
172 | |
172 | |
173 | unsigned char HexEncodeTable[16] = { |
173 | unsigned char HexEncodeTable[16] = { |
174 | '0', '1', '2', '3', '4', '5', '6', '7', |
174 | '0', '1', '2', '3', '4', '5', '6', '7', |
… | |
… | |
240 | |
240 | |
241 | /* |
241 | /* |
242 | * Encode one part of the data stream |
242 | * Encode one part of the data stream |
243 | */ |
243 | */ |
244 | |
244 | |
245 | static int |
245 | static int |
246 | UUEncodeStream (FILE *outfile, FILE *infile, int encoding, long linperfile, crc32_t *crc, crc32_t *pcrc) |
246 | UUEncodeStream (FILE *outfile, FILE *infile, int encoding, long linperfile, crc32_t *crc, crc32_t *pcrc) |
247 | { |
247 | { |
248 | uchar *itemp = (uchar *) uuestr_itemp; |
248 | uchar *itemp = (uchar *) uuestr_itemp; |
249 | uchar *otemp = (uchar *) uuestr_otemp; |
249 | uchar *otemp = (uchar *) uuestr_otemp; |
250 | unsigned char *optr, *table, *tptr; |
250 | unsigned char *optr, *table, *tptr; |
… | |
… | |
278 | optr = otemp; |
278 | optr = otemp; |
279 | |
279 | |
280 | /* |
280 | /* |
281 | * Busy Callback |
281 | * Busy Callback |
282 | */ |
282 | */ |
283 | |
283 | |
284 | if (UUBUSYPOLL(ftell(infile)-progress.foffset,progress.fsize)) { |
284 | if (UUBUSYPOLL(ftell(infile)-progress.foffset,progress.fsize)) { |
285 | UUMessage (uuencode_id, __LINE__, UUMSG_NOTE, |
285 | UUMessage (uuencode_id, __LINE__, UUMSG_NOTE, |
286 | uustring (S_ENCODE_CANCEL)); |
286 | uustring (S_ENCODE_CANCEL)); |
287 | return UURET_CANCEL; |
287 | return UURET_CANCEL; |
288 | } |
288 | } |
… | |
… | |
384 | (itemp[index+1] >= 62 && itemp[index+1] <= 126)) && |
384 | (itemp[index+1] >= 62 && itemp[index+1] <= 126)) && |
385 | llen >= 73))) { |
385 | llen >= 73))) { |
386 | |
386 | |
387 | *optr++ = '='; |
387 | *optr++ = '='; |
388 | llen++; |
388 | llen++; |
389 | |
389 | |
390 | if (fwrite (otemp, 1, llen, outfile) != llen || |
390 | if (fwrite (otemp, 1, llen, outfile) != llen || |
391 | fwrite ((char *) eolstring, 1, |
391 | fwrite ((char *) eolstring, 1, |
392 | strlen(eolstring), outfile) != strlen (eolstring)) { |
392 | strlen(eolstring), outfile) != strlen (eolstring)) { |
393 | return UURET_IOERR; |
393 | return UURET_IOERR; |
394 | } |
394 | } |
395 | |
395 | |
396 | optr = otemp; |
396 | optr = otemp; |
397 | llen = 0; |
397 | llen = 0; |
398 | } |
398 | } |
399 | } |
399 | } |
400 | } |
400 | } |
… | |
… | |
431 | line++; |
431 | line++; |
432 | |
432 | |
433 | /* |
433 | /* |
434 | * Busy Callback |
434 | * Busy Callback |
435 | */ |
435 | */ |
436 | |
436 | |
437 | if (UUBUSYPOLL(ftell(infile)-progress.foffset,progress.fsize)) { |
437 | if (UUBUSYPOLL(ftell(infile)-progress.foffset,progress.fsize)) { |
438 | UUMessage (uuencode_id, __LINE__, UUMSG_NOTE, |
438 | UUMessage (uuencode_id, __LINE__, UUMSG_NOTE, |
439 | uustring (S_ENCODE_CANCEL)); |
439 | uustring (S_ENCODE_CANCEL)); |
440 | return UURET_CANCEL; |
440 | return UURET_CANCEL; |
441 | } |
441 | } |
… | |
… | |
561 | |
561 | |
562 | if (index != count) { |
562 | if (index != count) { |
563 | if (encoding == B64ENCODED) { |
563 | if (encoding == B64ENCODED) { |
564 | if (count - index == 2) { |
564 | if (count - index == 2) { |
565 | *optr++ = table[itemp[index] >> 2]; |
565 | *optr++ = table[itemp[index] >> 2]; |
566 | *optr++ = table[((itemp[index ] & 0x03) << 4) | |
566 | *optr++ = table[((itemp[index ] & 0x03) << 4) | |
567 | ((itemp[index+1] & 0xf0) >> 4)]; |
567 | ((itemp[index+1] & 0xf0) >> 4)]; |
568 | *optr++ = table[((itemp[index+1] & 0x0f) << 2)]; |
568 | *optr++ = table[((itemp[index+1] & 0x0f) << 2)]; |
569 | *optr++ = '='; |
569 | *optr++ = '='; |
570 | } |
570 | } |
571 | else if (count - index == 1) { |
571 | else if (count - index == 1) { |
… | |
… | |
577 | llen += 4; |
577 | llen += 4; |
578 | } |
578 | } |
579 | else if (encoding == UU_ENCODED || encoding == XX_ENCODED) { |
579 | else if (encoding == UU_ENCODED || encoding == XX_ENCODED) { |
580 | if (count - index == 2) { |
580 | if (count - index == 2) { |
581 | *optr++ = table[itemp[index] >> 2]; |
581 | *optr++ = table[itemp[index] >> 2]; |
582 | *optr++ = table[((itemp[index ] & 0x03) << 4) | |
582 | *optr++ = table[((itemp[index ] & 0x03) << 4) | |
583 | ( itemp[index+1] >> 4)]; |
583 | ( itemp[index+1] >> 4)]; |
584 | *optr++ = table[((itemp[index+1] & 0x0f) << 2)]; |
584 | *optr++ = table[((itemp[index+1] & 0x0f) << 2)]; |
585 | *optr++ = table[0]; |
585 | *optr++ = table[0]; |
586 | } |
586 | } |
587 | else if (count - index == 1) { |
587 | else if (count - index == 1) { |
… | |
… | |
628 | FILE *theifile; |
628 | FILE *theifile; |
629 | char *ptr; |
629 | char *ptr; |
630 | crc32_t crc; |
630 | crc32_t crc; |
631 | crc32_t *crcptr=NULL; |
631 | crc32_t *crcptr=NULL; |
632 | |
632 | |
633 | if (outfile==NULL || |
633 | if (outfile==NULL || |
634 | (infile == NULL && infname==NULL) || |
634 | (infile == NULL && infname==NULL) || |
635 | (outfname==NULL && infname==NULL) || |
635 | (outfname==NULL && infname==NULL) || |
636 | (encoding!=UU_ENCODED&&encoding!=XX_ENCODED&&encoding!=B64ENCODED&& |
636 | (encoding!=UU_ENCODED&&encoding!=XX_ENCODED&&encoding!=B64ENCODED&& |
637 | encoding!=PT_ENCODED&&encoding!=QP_ENCODED&&encoding!=YENC_ENCODED)) { |
637 | encoding!=PT_ENCODED&&encoding!=QP_ENCODED&&encoding!=YENC_ENCODED)) { |
638 | UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, |
638 | UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, |
… | |
… | |
715 | } |
715 | } |
716 | |
716 | |
717 | if (encoding == UU_ENCODED || encoding == XX_ENCODED) { |
717 | if (encoding == UU_ENCODED || encoding == XX_ENCODED) { |
718 | fprintf (outfile, "begin %o %s%s", |
718 | fprintf (outfile, "begin %o %s%s", |
719 | (themode) ? themode : 0644, |
719 | (themode) ? themode : 0644, |
720 | UUFNameFilter ((outfname)?outfname:infname), |
720 | UUFNameFilter ((outfname)?outfname:infname), |
721 | eolstring); |
721 | eolstring); |
722 | } |
722 | } |
723 | else if (encoding == YENC_ENCODED) { |
723 | else if (encoding == YENC_ENCODED) { |
724 | crc = CRC32_INIT; |
724 | crc = CRC32_INIT; |
725 | crcptr = &crc; |
725 | crcptr = &crc; |
726 | if (progress.fsize == -1) { |
726 | if (progress.fsize == -1) { |
727 | fprintf (outfile, "=ybegin line=128 name=%s%s", |
727 | fprintf (outfile, "=ybegin line=128 name=%s%s", |
728 | UUFNameFilter ((outfname)?outfname:infname), |
728 | UUFNameFilter ((outfname)?outfname:infname), |
729 | eolstring); |
729 | eolstring); |
730 | } |
730 | } |
731 | else { |
731 | else { |
732 | fprintf (outfile, "=ybegin line=128 size=%ld name=%s%s", |
732 | fprintf (outfile, "=ybegin line=128 size=%ld name=%s%s", |
733 | progress.fsize, |
733 | progress.fsize, |
734 | UUFNameFilter ((outfname)?outfname:infname), |
734 | UUFNameFilter ((outfname)?outfname:infname), |
735 | eolstring); |
735 | eolstring); |
736 | } |
736 | } |
737 | } |
737 | } |
738 | |
738 | |
739 | if ((res = UUEncodeStream (outfile, theifile, encoding, 0, crcptr, NULL)) != UURET_OK) { |
739 | if ((res = UUEncodeStream (outfile, theifile, encoding, 0, crcptr, NULL)) != UURET_OK) { |
… | |
… | |
746 | progress.action = 0; |
746 | progress.action = 0; |
747 | return res; |
747 | return res; |
748 | } |
748 | } |
749 | |
749 | |
750 | if (encoding == UU_ENCODED || encoding == XX_ENCODED) { |
750 | if (encoding == UU_ENCODED || encoding == XX_ENCODED) { |
751 | fprintf (outfile, "%c%s", |
751 | fprintf (outfile, "%c%s", |
752 | (encoding==UU_ENCODED) ? UUEncodeTable[0] : XXEncodeTable[0], |
752 | (encoding==UU_ENCODED) ? UUEncodeTable[0] : XXEncodeTable[0], |
753 | eolstring); |
753 | eolstring); |
754 | fprintf (outfile, "end%s", eolstring); |
754 | fprintf (outfile, "end%s", eolstring); |
755 | } |
755 | } |
756 | else if (encoding == YENC_ENCODED) { |
756 | else if (encoding == YENC_ENCODED) { |
757 | if (progress.fsize == -1) { |
757 | if (progress.fsize == -1) { |
… | |
… | |
830 | infname, strerror (uu_errno=errno)); |
830 | infname, strerror (uu_errno=errno)); |
831 | return UURET_IOERR; |
831 | return UURET_IOERR; |
832 | } |
832 | } |
833 | if (linperfile <= 0) |
833 | if (linperfile <= 0) |
834 | numparts = 1; |
834 | numparts = 1; |
835 | else |
835 | else |
836 | numparts = (int) (((long)finfo.st_size+(linperfile*bpl[encoding]-1))/ |
836 | numparts = (int) (((long)finfo.st_size+(linperfile*bpl[encoding]-1))/ |
837 | (linperfile*bpl[encoding])); |
837 | (linperfile*bpl[encoding])); |
838 | |
838 | |
839 | themode = (filemode) ? filemode : ((int) finfo.st_mode & 0777); |
839 | themode = (filemode) ? filemode : ((int) finfo.st_mode & 0777); |
840 | thesize = (long) finfo.st_size; |
840 | thesize = (long) finfo.st_size; |
… | |
… | |
900 | fprintf (outfile, "Content-Disposition: attachment; filename=\"%s\"%s", |
900 | fprintf (outfile, "Content-Disposition: attachment; filename=\"%s\"%s", |
901 | UUFNameFilter ((outfname)?outfname:infname), eolstring); |
901 | UUFNameFilter ((outfname)?outfname:infname), eolstring); |
902 | } |
902 | } |
903 | |
903 | |
904 | fprintf (outfile, "%s", eolstring); |
904 | fprintf (outfile, "%s", eolstring); |
905 | |
905 | |
906 | /* |
906 | /* |
907 | * for the first part of UU or XX messages, print a begin line |
907 | * for the first part of UU or XX messages, print a begin line |
908 | */ |
908 | */ |
909 | |
909 | |
910 | if (encoding == UU_ENCODED || encoding == XX_ENCODED) { |
910 | if (encoding == UU_ENCODED || encoding == XX_ENCODED) { |
… | |
… | |
918 | pcrcptr = &pcrc; |
918 | pcrcptr = &pcrc; |
919 | if (numparts != 1) { |
919 | if (numparts != 1) { |
920 | if (progress.totsize == -1) { |
920 | if (progress.totsize == -1) { |
921 | fprintf (outfile, "=ybegin part=%d line=128 name=%s%s", |
921 | fprintf (outfile, "=ybegin part=%d line=128 name=%s%s", |
922 | partno, |
922 | partno, |
923 | UUFNameFilter ((outfname)?outfname:infname), |
923 | UUFNameFilter ((outfname)?outfname:infname), |
924 | eolstring); |
924 | eolstring); |
925 | } |
925 | } |
926 | else { |
926 | else { |
927 | fprintf (outfile, "=ybegin part=%d line=128 size=%ld name=%s%s", |
927 | fprintf (outfile, "=ybegin part=%d line=128 size=%ld name=%s%s", |
928 | partno, |
928 | partno, |
929 | progress.totsize, |
929 | progress.totsize, |
930 | UUFNameFilter ((outfname)?outfname:infname), |
930 | UUFNameFilter ((outfname)?outfname:infname), |
931 | eolstring); |
931 | eolstring); |
932 | } |
932 | } |
933 | |
933 | |
934 | fprintf (outfile, "=ypart begin=%ld end=%ld%s", |
934 | fprintf (outfile, "=ypart begin=%ld end=%ld%s", |
935 | (partno - 1) * linperfile * 128 + 1, |
935 | (partno - 1) * linperfile * 128 + 1, |
… | |
… | |
939 | eolstring); |
939 | eolstring); |
940 | } |
940 | } |
941 | else { |
941 | else { |
942 | if (progress.totsize == -1) { |
942 | if (progress.totsize == -1) { |
943 | fprintf (outfile, "=ybegin line=128 name=%s%s", |
943 | fprintf (outfile, "=ybegin line=128 name=%s%s", |
944 | UUFNameFilter ((outfname)?outfname:infname), |
944 | UUFNameFilter ((outfname)?outfname:infname), |
945 | eolstring); |
945 | eolstring); |
946 | } |
946 | } |
947 | else { |
947 | else { |
948 | fprintf (outfile, "=ybegin line=128 size=%ld name=%s%s", |
948 | fprintf (outfile, "=ybegin line=128 size=%ld name=%s%s", |
949 | progress.totsize, |
949 | progress.totsize, |
950 | UUFNameFilter ((outfname)?outfname:infname), |
950 | UUFNameFilter ((outfname)?outfname:infname), |
951 | eolstring); |
951 | eolstring); |
952 | } |
952 | } |
953 | } |
953 | } |
954 | } |
954 | } |
955 | |
955 | |
… | |
… | |
989 | * print end line |
989 | * print end line |
990 | */ |
990 | */ |
991 | |
991 | |
992 | if (feof (theifile) && |
992 | if (feof (theifile) && |
993 | (encoding == UU_ENCODED || encoding == XX_ENCODED)) { |
993 | (encoding == UU_ENCODED || encoding == XX_ENCODED)) { |
994 | fprintf (outfile, "%c%s", |
994 | fprintf (outfile, "%c%s", |
995 | (encoding==UU_ENCODED) ? UUEncodeTable[0] : XXEncodeTable[0], |
995 | (encoding==UU_ENCODED) ? UUEncodeTable[0] : XXEncodeTable[0], |
996 | eolstring); |
996 | eolstring); |
997 | fprintf (outfile, "end%s", eolstring); |
997 | fprintf (outfile, "end%s", eolstring); |
998 | } |
998 | } |
999 | else if (encoding == YENC_ENCODED) { |
999 | else if (encoding == YENC_ENCODED) { |
1000 | if (numparts != 1) { |
1000 | if (numparts != 1) { |
… | |
… | |
1112 | progress.action = UUACT_ENCODING; |
1112 | progress.action = UUACT_ENCODING; |
1113 | |
1113 | |
1114 | if (encoding == UU_ENCODED || encoding == XX_ENCODED) { |
1114 | if (encoding == UU_ENCODED || encoding == XX_ENCODED) { |
1115 | fprintf (outfile, "begin %o %s%s", |
1115 | fprintf (outfile, "begin %o %s%s", |
1116 | (themode) ? themode : 0644, |
1116 | (themode) ? themode : 0644, |
1117 | UUFNameFilter ((outfname)?outfname:infname), |
1117 | UUFNameFilter ((outfname)?outfname:infname), |
1118 | eolstring); |
1118 | eolstring); |
1119 | } |
1119 | } |
1120 | else if (encoding == YENC_ENCODED) { |
1120 | else if (encoding == YENC_ENCODED) { |
1121 | crc = CRC32_INIT; |
1121 | crc = CRC32_INIT; |
1122 | crcptr = &crc; |
1122 | crcptr = &crc; |
1123 | if (progress.fsize == -1) { |
1123 | if (progress.fsize == -1) { |
1124 | fprintf (outfile, "=ybegin line=128 name=%s%s", |
1124 | fprintf (outfile, "=ybegin line=128 name=%s%s", |
1125 | UUFNameFilter ((outfname)?outfname:infname), |
1125 | UUFNameFilter ((outfname)?outfname:infname), |
1126 | eolstring); |
1126 | eolstring); |
1127 | } |
1127 | } |
1128 | else { |
1128 | else { |
1129 | fprintf (outfile, "=ybegin line=128 size=%ld name=%s%s", |
1129 | fprintf (outfile, "=ybegin line=128 size=%ld name=%s%s", |
1130 | progress.fsize, |
1130 | progress.fsize, |
1131 | UUFNameFilter ((outfname)?outfname:infname), |
1131 | UUFNameFilter ((outfname)?outfname:infname), |
1132 | eolstring); |
1132 | eolstring); |
1133 | } |
1133 | } |
1134 | } |
1134 | } |
1135 | |
1135 | |
1136 | if ((res = UUEncodeStream (outfile, theifile, encoding, 0, crcptr, NULL)) != UURET_OK) { |
1136 | if ((res = UUEncodeStream (outfile, theifile, encoding, 0, crcptr, NULL)) != UURET_OK) { |
1137 | if (res != UURET_CANCEL) { |
1137 | if (res != UURET_CANCEL) { |
1138 | UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, |
1138 | UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, |
1139 | uustring (S_ERR_ENCODING), |
1139 | uustring (S_ERR_ENCODING), |
1140 | UUFNameFilter ((infname)?infname:outfname), |
1140 | UUFNameFilter ((infname)?infname:outfname), |
1141 | (res==UURET_IOERR)?strerror(uu_errno):UUstrerror (res)); |
1141 | (res==UURET_IOERR)?strerror(uu_errno):UUstrerror (res)); |
1142 | } |
1142 | } |
1143 | progress.action = 0; |
1143 | progress.action = 0; |
1144 | return res; |
1144 | return res; |
1145 | } |
1145 | } |
1146 | |
1146 | |
1147 | if (encoding == UU_ENCODED || encoding == XX_ENCODED) { |
1147 | if (encoding == UU_ENCODED || encoding == XX_ENCODED) { |
1148 | fprintf (outfile, "%c%s", |
1148 | fprintf (outfile, "%c%s", |
1149 | (encoding==UU_ENCODED) ? UUEncodeTable[0] : XXEncodeTable[0], |
1149 | (encoding==UU_ENCODED) ? UUEncodeTable[0] : XXEncodeTable[0], |
1150 | eolstring); |
1150 | eolstring); |
1151 | fprintf (outfile, "end%s", eolstring); |
1151 | fprintf (outfile, "end%s", eolstring); |
1152 | } |
1152 | } |
1153 | else if (encoding == YENC_ENCODED) { |
1153 | else if (encoding == YENC_ENCODED) { |
1154 | if (progress.fsize == -1) { |
1154 | if (progress.fsize == -1) { |
… | |
… | |
1212 | return UURET_NOMEM; |
1212 | return UURET_NOMEM; |
1213 | } |
1213 | } |
1214 | sprintf (oname, "%s", diskname); |
1214 | sprintf (oname, "%s", diskname); |
1215 | } |
1215 | } |
1216 | else { |
1216 | else { |
1217 | len = ((uusavepath)?strlen(uusavepath):0) + strlen (diskname) |
1217 | len = ((uusavepath)?strlen(uusavepath):0) + strlen (diskname) |
1218 | + ((uuencodeext)?strlen(uuencodeext):0) + 5; |
1218 | + ((uuencodeext)?strlen(uuencodeext):0) + 5; |
1219 | |
1219 | |
1220 | if ((oname = malloc (len)) == NULL) { |
1220 | if ((oname = malloc (len)) == NULL) { |
1221 | UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, |
1221 | UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, |
1222 | uustring (S_OUT_OF_MEMORY), len); |
1222 | uustring (S_OUT_OF_MEMORY), len); |
… | |
… | |
1224 | } |
1224 | } |
1225 | sprintf (oname, "%s%s", (uusavepath)?uusavepath:"", diskname); |
1225 | sprintf (oname, "%s%s", (uusavepath)?uusavepath:"", diskname); |
1226 | } |
1226 | } |
1227 | } |
1227 | } |
1228 | else { |
1228 | else { |
1229 | len = ((uusavepath) ? strlen (uusavepath) : 0) + |
1229 | len = ((uusavepath) ? strlen (uusavepath) : 0) + |
1230 | strlen(UUFNameFilter(infname)) + |
1230 | strlen(UUFNameFilter(infname)) + |
1231 | ((uuencodeext)?strlen(uuencodeext):0) + 5; |
1231 | ((uuencodeext)?strlen(uuencodeext):0) + 5; |
1232 | |
1232 | |
1233 | if ((oname = malloc (len)) == NULL) { |
1233 | if ((oname = malloc (len)) == NULL) { |
1234 | UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, |
1234 | UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, |
1235 | uustring (S_OUT_OF_MEMORY), len); |
1235 | uustring (S_OUT_OF_MEMORY), len); |
1236 | return UURET_NOMEM; |
1236 | return UURET_NOMEM; |
1237 | } |
1237 | } |
1238 | optr = UUFNameFilter (infname); |
1238 | optr = UUFNameFilter (infname); |
1239 | sprintf (oname, "%s%s", |
1239 | sprintf (oname, "%s%s", |
1240 | (uusavepath)?uusavepath:"", |
1240 | (uusavepath)?uusavepath:"", |
1241 | (*optr=='.')?optr+1:optr); |
1241 | (*optr=='.')?optr+1:optr); |
1242 | } |
1242 | } |
1243 | |
1243 | |
1244 | /* |
1244 | /* |
… | |
… | |
1275 | _FP_free (oname); |
1275 | _FP_free (oname); |
1276 | return UURET_IOERR; |
1276 | return UURET_IOERR; |
1277 | } |
1277 | } |
1278 | if (linperfile <= 0) |
1278 | if (linperfile <= 0) |
1279 | numparts = 1; |
1279 | numparts = 1; |
1280 | else |
1280 | else |
1281 | numparts = (int) (((long)finfo.st_size + (linperfile*bpl[encoding]-1)) / |
1281 | numparts = (int) (((long)finfo.st_size + (linperfile*bpl[encoding]-1)) / |
1282 | (linperfile*bpl[encoding])); |
1282 | (linperfile*bpl[encoding])); |
1283 | |
1283 | |
1284 | filemode = (int) finfo.st_mode & 0777; |
1284 | filemode = (int) finfo.st_mode & 0777; |
1285 | progress.totsize = (long) finfo.st_size; |
1285 | progress.totsize = (long) finfo.st_size; |
… | |
… | |
1313 | /* |
1313 | /* |
1314 | * Attach extension |
1314 | * Attach extension |
1315 | */ |
1315 | */ |
1316 | if (progress.numparts==1 && progress.totsize!=-1 && uuencodeext!=NULL) |
1316 | if (progress.numparts==1 && progress.totsize!=-1 && uuencodeext!=NULL) |
1317 | strcpy (optr, uuencodeext); |
1317 | strcpy (optr, uuencodeext); |
1318 | else |
1318 | else |
1319 | sprintf (optr, "%03d", part); |
1319 | sprintf (optr, "%03d", part); |
1320 | |
1320 | |
1321 | /* |
1321 | /* |
1322 | * check if target file exists |
1322 | * check if target file exists |
1323 | */ |
1323 | */ |
… | |
… | |
1380 | } |
1380 | } |
1381 | |
1381 | |
1382 | if (part==1 && (encoding == UU_ENCODED || encoding == XX_ENCODED)) { |
1382 | if (part==1 && (encoding == UU_ENCODED || encoding == XX_ENCODED)) { |
1383 | fprintf (outfile, "begin %o %s%s", |
1383 | fprintf (outfile, "begin %o %s%s", |
1384 | (filemode)?filemode : 0644, |
1384 | (filemode)?filemode : 0644, |
1385 | UUFNameFilter ((outfname)?outfname:infname), |
1385 | UUFNameFilter ((outfname)?outfname:infname), |
1386 | eolstring); |
1386 | eolstring); |
1387 | } |
1387 | } |
1388 | else if (encoding == YENC_ENCODED) { |
1388 | else if (encoding == YENC_ENCODED) { |
1389 | if (!crcptr) { |
1389 | if (!crcptr) { |
1390 | crc = CRC32_INIT; |
1390 | crc = CRC32_INIT; |
… | |
… | |
1394 | pcrcptr = &pcrc; |
1394 | pcrcptr = &pcrc; |
1395 | if (numparts != 1) { |
1395 | if (numparts != 1) { |
1396 | if (progress.totsize == -1) { |
1396 | if (progress.totsize == -1) { |
1397 | fprintf (outfile, "=ybegin part=%d line=128 name=%s%s", |
1397 | fprintf (outfile, "=ybegin part=%d line=128 name=%s%s", |
1398 | part, |
1398 | part, |
1399 | UUFNameFilter ((outfname)?outfname:infname), |
1399 | UUFNameFilter ((outfname)?outfname:infname), |
1400 | eolstring); |
1400 | eolstring); |
1401 | } |
1401 | } |
1402 | else { |
1402 | else { |
1403 | fprintf (outfile, "=ybegin part=%d line=128 size=%ld name=%s%s", |
1403 | fprintf (outfile, "=ybegin part=%d line=128 size=%ld name=%s%s", |
1404 | part, |
1404 | part, |
1405 | progress.totsize, |
1405 | progress.totsize, |
1406 | UUFNameFilter ((outfname)?outfname:infname), |
1406 | UUFNameFilter ((outfname)?outfname:infname), |
1407 | eolstring); |
1407 | eolstring); |
1408 | } |
1408 | } |
1409 | |
1409 | |
1410 | fprintf (outfile, "=ypart begin=%ld end=%ld%s", |
1410 | fprintf (outfile, "=ypart begin=%ld end=%ld%s", |
1411 | (part-1)*linperfile*128+1, |
1411 | (part-1)*linperfile*128+1, |
1412 | (part*linperfile*128) < progress.totsize ? |
1412 | (part*linperfile*128) < progress.totsize ? |
1413 | (part*linperfile*128) : progress.totsize, |
1413 | (part*linperfile*128) : progress.totsize, |
1414 | eolstring); |
1414 | eolstring); |
1415 | } |
1415 | } |
1416 | else { |
1416 | else { |
1417 | if (progress.totsize == -1) { |
1417 | if (progress.totsize == -1) { |
1418 | fprintf (outfile, "=ybegin line=128 name=%s%s", |
1418 | fprintf (outfile, "=ybegin line=128 name=%s%s", |
1419 | UUFNameFilter ((outfname)?outfname:infname), |
1419 | UUFNameFilter ((outfname)?outfname:infname), |
1420 | eolstring); |
1420 | eolstring); |
1421 | } |
1421 | } |
1422 | else { |
1422 | else { |
1423 | fprintf (outfile, "=ybegin line=128 size=%ld name=%s%s", |
1423 | fprintf (outfile, "=ybegin line=128 size=%ld name=%s%s", |
1424 | progress.totsize, |
1424 | progress.totsize, |
1425 | UUFNameFilter ((outfname)?outfname:infname), |
1425 | UUFNameFilter ((outfname)?outfname:infname), |
1426 | eolstring); |
1426 | eolstring); |
1427 | } |
1427 | } |
1428 | } |
1428 | } |
1429 | } |
1429 | } |
1430 | |
1430 | |
1431 | if ((res = UUEncodeStream (outfile, theifile, |
1431 | if ((res = UUEncodeStream (outfile, theifile, |
1432 | encoding, linperfile, crcptr, pcrcptr)) != UURET_OK) { |
1432 | encoding, linperfile, crcptr, pcrcptr)) != UURET_OK) { |
1433 | if (res != UURET_CANCEL) { |
1433 | if (res != UURET_CANCEL) { |
1434 | UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, |
1434 | UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, |
1435 | uustring (S_ERR_ENCODING), |
1435 | uustring (S_ERR_ENCODING), |
1436 | UUFNameFilter ((infname)?infname:outfname), |
1436 | UUFNameFilter ((infname)?infname:outfname), |
1437 | (res==UURET_IOERR)?strerror(uu_errno):UUstrerror (res)); |
1437 | (res==UURET_IOERR)?strerror(uu_errno):UUstrerror (res)); |
1438 | } |
1438 | } |
1439 | if (infile==NULL) fclose (theifile); |
1439 | if (infile==NULL) fclose (theifile); |
1440 | progress.action = 0; |
1440 | progress.action = 0; |
1441 | fclose (outfile); |
1441 | fclose (outfile); |
… | |
… | |
1444 | return res; |
1444 | return res; |
1445 | } |
1445 | } |
1446 | |
1446 | |
1447 | if (feof (theifile) && |
1447 | if (feof (theifile) && |
1448 | (encoding == UU_ENCODED || encoding == XX_ENCODED)) { |
1448 | (encoding == UU_ENCODED || encoding == XX_ENCODED)) { |
1449 | fprintf (outfile, "%c%s", |
1449 | fprintf (outfile, "%c%s", |
1450 | (encoding==UU_ENCODED) ? UUEncodeTable[0] : XXEncodeTable[0], |
1450 | (encoding==UU_ENCODED) ? UUEncodeTable[0] : XXEncodeTable[0], |
1451 | eolstring); |
1451 | eolstring); |
1452 | fprintf (outfile, "end%s", eolstring); |
1452 | fprintf (outfile, "end%s", eolstring); |
1453 | } |
1453 | } |
1454 | else if (encoding == YENC_ENCODED) { |
1454 | else if (encoding == YENC_ENCODED) { |
1455 | if (numparts != 1) { |
1455 | if (numparts != 1) { |
1456 | fprintf (outfile, "=yend size=%ld part=%d pcrc32=%08lx", |
1456 | fprintf (outfile, "=yend size=%ld part=%d pcrc32=%08lx", |
1457 | (part*linperfile*128) < progress.totsize ? |
1457 | (part*linperfile*128) < progress.totsize ? |
1458 | linperfile*128 : (progress.totsize-(part-1)*linperfile*128), |
1458 | linperfile*128 : (progress.totsize-(part-1)*linperfile*128), |
1459 | part, |
1459 | part, |
1460 | (long)pcrc); |
1460 | (long)pcrc); |
1461 | } |
1461 | } |
1462 | else { |
1462 | else { |
1463 | fprintf (outfile, "=yend size=%ld", |
1463 | fprintf (outfile, "=yend size=%ld", |
1464 | progress.totsize); |
1464 | progress.totsize); |
1465 | } |
1465 | } |
1466 | if (feof (theifile)) |
1466 | if (feof (theifile)) |
1467 | fprintf (outfile, " crc32=%08lx", (long)crc); |
1467 | fprintf (outfile, " crc32=%08lx", (long)crc); |
1468 | fprintf (outfile, "%s", eolstring); |
1468 | fprintf (outfile, "%s", eolstring); |
1469 | } |
1469 | } |
1470 | |
1470 | |
1471 | /* |
1471 | /* |
1472 | * empty line at end does no harm |
1472 | * empty line at end does no harm |
… | |
… | |
1585 | |
1585 | |
1586 | fprintf (outfile, "%s", eolstring); |
1586 | fprintf (outfile, "%s", eolstring); |
1587 | |
1587 | |
1588 | res = UUEncodeToStream (outfile, infile, infname, encoding, |
1588 | res = UUEncodeToStream (outfile, infile, infname, encoding, |
1589 | outfname, filemode); |
1589 | outfname, filemode); |
1590 | |
1590 | |
1591 | _FP_free (subline); |
1591 | _FP_free (subline); |
1592 | return res; |
1592 | return res; |
1593 | } |
1593 | } |
1594 | |
1594 | |
1595 | int UUEXPORT |
1595 | int UUEXPORT |
… | |
… | |
1657 | infname, strerror (uu_errno=errno)); |
1657 | infname, strerror (uu_errno=errno)); |
1658 | return UURET_IOERR; |
1658 | return UURET_IOERR; |
1659 | } |
1659 | } |
1660 | if (linperfile <= 0) |
1660 | if (linperfile <= 0) |
1661 | numparts = 1; |
1661 | numparts = 1; |
1662 | else |
1662 | else |
1663 | numparts = (int) (((long)finfo.st_size+(linperfile*bpl[encoding]-1))/ |
1663 | numparts = (int) (((long)finfo.st_size+(linperfile*bpl[encoding]-1))/ |
1664 | (linperfile*bpl[encoding])); |
1664 | (linperfile*bpl[encoding])); |
1665 | |
1665 | |
1666 | themode = (filemode) ? filemode : ((int) finfo.st_mode & 0777); |
1666 | themode = (filemode) ? filemode : ((int) finfo.st_mode & 0777); |
1667 | thesize = (long) finfo.st_size; |
1667 | thesize = (long) finfo.st_size; |
… | |
… | |
1738 | sprintf (subline, "- %s - (%03d/%03d)", oname, |
1738 | sprintf (subline, "- %s - (%03d/%03d)", oname, |
1739 | partno, numparts); |
1739 | partno, numparts); |
1740 | } |
1740 | } |
1741 | else { |
1741 | else { |
1742 | if (subject) |
1742 | if (subject) |
1743 | sprintf (subline, "%s (%03d/%03d) - [ %s ]", |
1743 | sprintf (subline, "%s (%03d/%03d) - [ %s ]", |
1744 | subject, partno, numparts, oname); |
1744 | subject, partno, numparts, oname); |
1745 | else |
1745 | else |
1746 | sprintf (subline, "[ %s ] (%03d/%03d)", |
1746 | sprintf (subline, "[ %s ] (%03d/%03d)", |
1747 | oname, partno, numparts); |
1747 | oname, partno, numparts); |
1748 | } |
1748 | } |
… | |
… | |
1768 | fprintf (outfile, "Content-Type: Message/Partial; number=%d; total=%d;%s", |
1768 | fprintf (outfile, "Content-Type: Message/Partial; number=%d; total=%d;%s", |
1769 | partno, numparts, eolstring); |
1769 | partno, numparts, eolstring); |
1770 | fprintf (outfile, "\tid=\"%s\"%s", |
1770 | fprintf (outfile, "\tid=\"%s\"%s", |
1771 | mimeid, eolstring); |
1771 | mimeid, eolstring); |
1772 | } |
1772 | } |
1773 | |
1773 | |
1774 | fprintf (outfile, "%s", eolstring); |
1774 | fprintf (outfile, "%s", eolstring); |
1775 | |
1775 | |
1776 | res = UUEncodePartial (outfile, theifile, |
1776 | res = UUEncodePartial (outfile, theifile, |
1777 | infname, encoding, |
1777 | infname, encoding, |
1778 | (outfname)?outfname:infname, NULL, |
1778 | (outfname)?outfname:infname, NULL, |