… | |
… | |
28 | #include <sys/types.h> |
28 | #include <sys/types.h> |
29 | #include <sys/stat.h> |
29 | #include <sys/stat.h> |
30 | #include <ctype.h> |
30 | #include <ctype.h> |
31 | #include <stdio.h> |
31 | #include <stdio.h> |
32 | #include <time.h> |
32 | #include <time.h> |
33 | |
|
|
34 | #ifdef STDC_HEADERS |
|
|
35 | #include <stdlib.h> |
33 | #include <stdlib.h> |
36 | #include <string.h> |
34 | #include <string.h> |
37 | #endif |
35 | #include <errno.h> |
|
|
36 | |
38 | #ifdef HAVE_UNISTD_H |
37 | #ifdef HAVE_UNISTD_H |
39 | #include <unistd.h> |
38 | #include <unistd.h> |
40 | #endif |
|
|
41 | #ifdef HAVE_ERRNO_H |
|
|
42 | #include <errno.h> |
|
|
43 | #endif |
39 | #endif |
44 | |
40 | |
45 | #include <uudeview.h> |
41 | #include <uudeview.h> |
46 | #include <uuint.h> |
42 | #include <uuint.h> |
47 | #include <fptools.h> |
43 | #include <fptools.h> |
… | |
… | |
54 | #define SEEK_SET L_BEGIN |
50 | #define SEEK_SET L_BEGIN |
55 | #else |
51 | #else |
56 | #define SEEK_SET 0 |
52 | #define SEEK_SET 0 |
57 | #endif |
53 | #endif |
58 | #endif |
54 | #endif |
59 | |
|
|
60 | char * uuencode_id = "$Id: uuencode.c,v 1.2.2.5 2004/04/18 19:55:46 root Exp $"; |
|
|
61 | |
55 | |
62 | #if 0 |
56 | #if 0 |
63 | /* |
57 | /* |
64 | * the End-Of-Line string. MIME enforces CRLF, so that's what we use. Some |
58 | * 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 |
59 | * implementations of uudecode will complain about a missing end line, since |
… | |
… | |
133 | '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', |
127 | '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', |
134 | 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', |
128 | 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', |
135 | 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', |
129 | 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', |
136 | 'X', 'Y', 'Z', '[', '\\',']', '^', '_' |
130 | 'X', 'Y', 'Z', '[', '\\',']', '^', '_' |
137 | }; |
131 | }; |
138 | |
132 | |
139 | |
133 | |
140 | unsigned char B64EncodeTable[64] = { |
134 | unsigned char B64EncodeTable[64] = { |
141 | 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', |
135 | 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', |
142 | 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', |
136 | 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', |
143 | 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', |
137 | 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', |
… | |
… | |
160 | }; |
154 | }; |
161 | |
155 | |
162 | unsigned char BHEncodeTable[64] = { |
156 | unsigned char BHEncodeTable[64] = { |
163 | '!', '"', '#', '$', '%', '&', '\'', '(', |
157 | '!', '"', '#', '$', '%', '&', '\'', '(', |
164 | ')', '*', '+', ',', '-', '0', '1', '2', |
158 | ')', '*', '+', ',', '-', '0', '1', '2', |
165 | '3', '4', '5', '6', '8', '9', '@', 'A', |
159 | '3', '4', '5', '6', '8', '9', '@', 'A', |
166 | 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', |
160 | 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', |
167 | 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', |
161 | 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', |
168 | 'S', 'T', 'U', 'V', 'X', 'Y', 'Z', '[', |
162 | 'S', 'T', 'U', 'V', 'X', 'Y', 'Z', '[', |
169 | '`', 'a', 'b', 'c', 'd', 'e', 'f', 'h', |
163 | '`', 'a', 'b', 'c', 'd', 'e', 'f', 'h', |
170 | 'i', 'j', 'k', 'l', 'm', 'p', 'q', 'r' |
164 | 'i', 'j', 'k', 'l', 'm', 'p', 'q', 'r' |
171 | }; |
165 | }; |
172 | |
166 | |
173 | unsigned char HexEncodeTable[16] = { |
167 | unsigned char HexEncodeTable[16] = { |
174 | '0', '1', '2', '3', '4', '5', '6', '7', |
168 | '0', '1', '2', '3', '4', '5', '6', '7', |
… | |
… | |
240 | |
234 | |
241 | /* |
235 | /* |
242 | * Encode one part of the data stream |
236 | * Encode one part of the data stream |
243 | */ |
237 | */ |
244 | |
238 | |
245 | static int |
239 | static int |
246 | UUEncodeStream (FILE *outfile, FILE *infile, int encoding, long linperfile, crc32_t *crc, crc32_t *pcrc) |
240 | UUEncodeStream (FILE *outfile, FILE *infile, int encoding, long linperfile, crc32_t *crc, crc32_t *pcrc) |
247 | { |
241 | { |
248 | unsigned char *itemp = (char *) uuestr_itemp; |
242 | uchar *itemp = (uchar *) uuestr_itemp; |
249 | unsigned char *otemp = (char *) uuestr_otemp; |
243 | uchar *otemp = (uchar *) uuestr_otemp; |
250 | unsigned char *optr, *table, *tptr; |
244 | unsigned char *optr, *table, *tptr; |
251 | int index, count; |
245 | int index, count; |
252 | long line=0; |
246 | long line=0; |
253 | size_t llen; |
247 | size_t llen; |
254 | |
248 | |
255 | if (outfile==NULL || infile==NULL || |
249 | if (outfile==NULL || infile==NULL || |
256 | (encoding!=UU_ENCODED&&encoding!=XX_ENCODED&&encoding!=B64ENCODED&& |
250 | (encoding!=UU_ENCODED&&encoding!=XX_ENCODED&&encoding!=B64ENCODED&& |
257 | encoding!=PT_ENCODED&&encoding!=QP_ENCODED&&encoding!=YENC_ENCODED)) { |
251 | encoding!=PT_ENCODED&&encoding!=QP_ENCODED&&encoding!=YENC_ENCODED)) { |
258 | UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, |
252 | UUMessage (UUMSG_ERROR, uustring (S_PARM_CHECK), "UUEncodeStream()"); |
259 | uustring (S_PARM_CHECK), "UUEncodeStream()"); |
|
|
260 | return UURET_ILLVAL; |
253 | return UURET_ILLVAL; |
261 | } |
254 | } |
262 | |
255 | |
263 | /* |
256 | /* |
264 | * Special handling for plain text and quoted printable. Text is |
257 | * Special handling for plain text and quoted printable. Text is |
265 | * read line oriented. |
258 | * read line oriented. |
266 | */ |
259 | */ |
267 | |
260 | |
268 | if (encoding == PT_ENCODED || encoding == QP_ENCODED) { |
261 | if (encoding == PT_ENCODED || encoding == QP_ENCODED) { |
269 | while (!feof (infile) && (linperfile <= 0 || line < linperfile)) { |
262 | while (!FP_feof (infile) && (linperfile <= 0 || line < linperfile)) { |
270 | if (_FP_fgets (itemp, 255, infile) == NULL) { |
263 | if (FP_fgets (itemp, 255, infile) == NULL) { |
271 | break; |
264 | break; |
272 | } |
265 | } |
273 | |
266 | |
274 | itemp[255] = '\0'; |
267 | itemp[255] = '\0'; |
275 | count = strlen (itemp); |
268 | count = strlen (itemp); |
… | |
… | |
278 | optr = otemp; |
271 | optr = otemp; |
279 | |
272 | |
280 | /* |
273 | /* |
281 | * Busy Callback |
274 | * Busy Callback |
282 | */ |
275 | */ |
283 | |
276 | |
284 | if (UUBUSYPOLL(ftell(infile)-progress.foffset,progress.fsize)) { |
277 | if (UUBUSYPOLL(ftell(infile)-progress.foffset,progress.fsize)) { |
285 | UUMessage (uuencode_id, __LINE__, UUMSG_NOTE, |
278 | UUMessage (UUMSG_NOTE, uustring (S_ENCODE_CANCEL)); |
286 | uustring (S_ENCODE_CANCEL)); |
|
|
287 | return UURET_CANCEL; |
279 | return UURET_CANCEL; |
288 | } |
280 | } |
289 | |
281 | |
290 | if (encoding == PT_ENCODED) { |
282 | if (encoding == PT_ENCODED) { |
291 | /* |
283 | /* |
… | |
… | |
384 | (itemp[index+1] >= 62 && itemp[index+1] <= 126)) && |
376 | (itemp[index+1] >= 62 && itemp[index+1] <= 126)) && |
385 | llen >= 73))) { |
377 | llen >= 73))) { |
386 | |
378 | |
387 | *optr++ = '='; |
379 | *optr++ = '='; |
388 | llen++; |
380 | llen++; |
389 | |
381 | |
390 | if (fwrite (otemp, 1, llen, outfile) != llen || |
382 | if (fwrite (otemp, 1, llen, outfile) != llen || |
391 | fwrite ((char *) eolstring, 1, |
383 | fwrite ((char *) eolstring, 1, |
392 | strlen(eolstring), outfile) != strlen (eolstring)) { |
384 | strlen(eolstring), outfile) != strlen (eolstring)) { |
393 | return UURET_IOERR; |
385 | return UURET_IOERR; |
394 | } |
386 | } |
395 | |
387 | |
396 | optr = otemp; |
388 | optr = otemp; |
397 | llen = 0; |
389 | llen = 0; |
398 | } |
390 | } |
399 | } |
391 | } |
400 | } |
392 | } |
… | |
… | |
411 | |
403 | |
412 | if (encoding == YENC_ENCODED) { |
404 | if (encoding == YENC_ENCODED) { |
413 | llen = 0; |
405 | llen = 0; |
414 | optr = otemp; |
406 | optr = otemp; |
415 | |
407 | |
416 | while (!feof (infile) && (linperfile <= 0 || line < linperfile)) { |
408 | while (!FP_feof (infile) && (linperfile <= 0 || line < linperfile)) { |
417 | if ((count = fread (itemp, 1, 128, infile)) != 128) { |
409 | if ((count = fread (itemp, 1, 128, infile)) != 128) { |
418 | if (count == 0) { |
410 | if (count == 0) { |
419 | break; |
411 | break; |
420 | } |
412 | } |
421 | else if (ferror (infile)) { |
413 | else if (ferror (infile)) { |
422 | return UURET_IOERR; |
414 | return UURET_IOERR; |
423 | } |
415 | } |
424 | } |
416 | } |
425 | |
417 | |
426 | if (pcrc) |
418 | if (pcrc) |
427 | *pcrc = crc32(*pcrc, itemp, count); |
419 | *pcrc = uu_crc32(*pcrc, itemp, count); |
428 | if (crc) |
420 | if (crc) |
429 | *crc = crc32(*crc, itemp, count); |
421 | *crc = uu_crc32(*crc, itemp, count); |
430 | |
422 | |
431 | line++; |
423 | line++; |
432 | |
424 | |
433 | /* |
425 | /* |
434 | * Busy Callback |
426 | * Busy Callback |
435 | */ |
427 | */ |
436 | |
428 | |
437 | if (UUBUSYPOLL(ftell(infile)-progress.foffset,progress.fsize)) { |
429 | if (UUBUSYPOLL(ftell(infile)-progress.foffset,progress.fsize)) { |
438 | UUMessage (uuencode_id, __LINE__, UUMSG_NOTE, |
430 | UUMessage (UUMSG_NOTE, uustring (S_ENCODE_CANCEL)); |
439 | uustring (S_ENCODE_CANCEL)); |
|
|
440 | return UURET_CANCEL; |
431 | return UURET_CANCEL; |
441 | } |
432 | } |
442 | |
433 | |
443 | for (index=0; index<count; index++) { |
434 | for (index=0; index<count; index++) { |
444 | if (llen > 127) { |
435 | if (llen > 127) { |
… | |
… | |
507 | */ |
498 | */ |
508 | |
499 | |
509 | table = etables[encoding]; |
500 | table = etables[encoding]; |
510 | |
501 | |
511 | if (table==NULL || bpl[encoding]==0) { |
502 | if (table==NULL || bpl[encoding]==0) { |
512 | UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, |
|
|
513 | uustring (S_PARM_CHECK), "UUEncodeStream()"); |
503 | UUMessage (UUMSG_ERROR, uustring (S_PARM_CHECK), "UUEncodeStream()"); |
514 | return UURET_ILLVAL; |
504 | return UURET_ILLVAL; |
515 | } |
505 | } |
516 | |
506 | |
517 | while (!feof (infile) && (linperfile <= 0 || line < linperfile)) { |
507 | while (!FP_feof (infile) && (linperfile <= 0 || line < linperfile)) { |
518 | if ((count = fread (itemp, 1, bpl[encoding], infile)) != bpl[encoding]) { |
508 | if ((count = fread (itemp, 1, bpl[encoding], infile)) != bpl[encoding]) { |
519 | if (count == 0) |
509 | if (count == 0) |
520 | break; |
510 | break; |
521 | else if (ferror (infile)) |
511 | else if (ferror (infile)) |
522 | return UURET_IOERR; |
512 | return UURET_IOERR; |
… | |
… | |
528 | /* |
518 | /* |
529 | * Busy Callback |
519 | * Busy Callback |
530 | */ |
520 | */ |
531 | |
521 | |
532 | if (UUBUSYPOLL(ftell(infile)-progress.foffset,progress.fsize)) { |
522 | if (UUBUSYPOLL(ftell(infile)-progress.foffset,progress.fsize)) { |
533 | UUMessage (uuencode_id, __LINE__, UUMSG_NOTE, |
523 | UUMessage (UUMSG_NOTE, uustring (S_ENCODE_CANCEL)); |
534 | uustring (S_ENCODE_CANCEL)); |
|
|
535 | return UURET_CANCEL; |
524 | return UURET_CANCEL; |
536 | } |
525 | } |
537 | |
526 | |
538 | /* |
527 | /* |
539 | * for UU and XX, encode the number of bytes as first character |
528 | * for UU and XX, encode the number of bytes as first character |
… | |
… | |
561 | |
550 | |
562 | if (index != count) { |
551 | if (index != count) { |
563 | if (encoding == B64ENCODED) { |
552 | if (encoding == B64ENCODED) { |
564 | if (count - index == 2) { |
553 | if (count - index == 2) { |
565 | *optr++ = table[itemp[index] >> 2]; |
554 | *optr++ = table[itemp[index] >> 2]; |
566 | *optr++ = table[((itemp[index ] & 0x03) << 4) | |
555 | *optr++ = table[((itemp[index ] & 0x03) << 4) | |
567 | ((itemp[index+1] & 0xf0) >> 4)]; |
556 | ((itemp[index+1] & 0xf0) >> 4)]; |
568 | *optr++ = table[((itemp[index+1] & 0x0f) << 2)]; |
557 | *optr++ = table[((itemp[index+1] & 0x0f) << 2)]; |
569 | *optr++ = '='; |
558 | *optr++ = '='; |
570 | } |
559 | } |
571 | else if (count - index == 1) { |
560 | else if (count - index == 1) { |
… | |
… | |
577 | llen += 4; |
566 | llen += 4; |
578 | } |
567 | } |
579 | else if (encoding == UU_ENCODED || encoding == XX_ENCODED) { |
568 | else if (encoding == UU_ENCODED || encoding == XX_ENCODED) { |
580 | if (count - index == 2) { |
569 | if (count - index == 2) { |
581 | *optr++ = table[itemp[index] >> 2]; |
570 | *optr++ = table[itemp[index] >> 2]; |
582 | *optr++ = table[((itemp[index ] & 0x03) << 4) | |
571 | *optr++ = table[((itemp[index ] & 0x03) << 4) | |
583 | ( itemp[index+1] >> 4)]; |
572 | ( itemp[index+1] >> 4)]; |
584 | *optr++ = table[((itemp[index+1] & 0x0f) << 2)]; |
573 | *optr++ = table[((itemp[index+1] & 0x0f) << 2)]; |
585 | *optr++ = table[0]; |
574 | *optr++ = table[0]; |
586 | } |
575 | } |
587 | else if (count - index == 1) { |
576 | else if (count - index == 1) { |
… | |
… | |
628 | FILE *theifile; |
617 | FILE *theifile; |
629 | char *ptr; |
618 | char *ptr; |
630 | crc32_t crc; |
619 | crc32_t crc; |
631 | crc32_t *crcptr=NULL; |
620 | crc32_t *crcptr=NULL; |
632 | |
621 | |
633 | if (outfile==NULL || |
622 | if (outfile==NULL || |
634 | (infile == NULL && infname==NULL) || |
623 | (infile == NULL && infname==NULL) || |
635 | (outfname==NULL && infname==NULL) || |
624 | (outfname==NULL && infname==NULL) || |
636 | (encoding!=UU_ENCODED&&encoding!=XX_ENCODED&&encoding!=B64ENCODED&& |
625 | (encoding!=UU_ENCODED&&encoding!=XX_ENCODED&&encoding!=B64ENCODED&& |
637 | encoding!=PT_ENCODED&&encoding!=QP_ENCODED&&encoding!=YENC_ENCODED)) { |
626 | encoding!=PT_ENCODED&&encoding!=QP_ENCODED&&encoding!=YENC_ENCODED)) { |
638 | UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, |
627 | UUMessage (UUMSG_ERROR, uustring (S_PARM_CHECK), "UUEncodeMulti()"); |
639 | uustring (S_PARM_CHECK), "UUEncodeMulti()"); |
|
|
640 | return UURET_ILLVAL; |
628 | return UURET_ILLVAL; |
641 | } |
629 | } |
642 | |
630 | |
643 | progress.action = 0; |
631 | progress.action = 0; |
644 | |
632 | |
645 | if (infile==NULL) { |
633 | if (infile==NULL) { |
646 | if (stat (infname, &finfo) == -1) { |
634 | if (stat (infname, &finfo) == -1) { |
647 | UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, |
635 | UUMessage (UUMSG_ERROR, |
648 | uustring (S_NOT_STAT_FILE), |
636 | uustring (S_NOT_STAT_FILE), |
649 | infname, strerror (uu_errno=errno)); |
637 | infname, strerror (uu_errno=errno)); |
650 | return UURET_IOERR; |
638 | return UURET_IOERR; |
651 | } |
639 | } |
652 | if ((theifile = fopen (infname, "rb")) == NULL) { |
640 | if ((theifile = fopen (infname, "rb")) == NULL) { |
653 | UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, |
641 | UUMessage (UUMSG_ERROR, |
654 | uustring (S_NOT_OPEN_FILE), |
642 | uustring (S_NOT_OPEN_FILE), |
655 | infname, strerror (uu_errno=errno)); |
643 | infname, strerror (uu_errno=errno)); |
656 | return UURET_IOERR; |
644 | return UURET_IOERR; |
657 | } |
645 | } |
658 | themode = (filemode) ? filemode : ((int) finfo.st_mode & 0777); |
646 | themode = (filemode) ? filemode : ((int) finfo.st_mode & 0777); |
… | |
… | |
671 | } |
659 | } |
672 | |
660 | |
673 | if (progress.fsize < 0) |
661 | if (progress.fsize < 0) |
674 | progress.fsize = -1; |
662 | progress.fsize = -1; |
675 | |
663 | |
676 | _FP_strncpy (progress.curfile, (outfname)?outfname:infname, 256); |
664 | FP_strncpy (progress.curfile, (outfname)?outfname:infname, 256); |
677 | |
665 | |
678 | progress.partno = 1; |
666 | progress.partno = 1; |
679 | progress.numparts = 1; |
667 | progress.numparts = 1; |
680 | progress.percent = 0; |
668 | progress.percent = 0; |
681 | progress.foffset = 0; |
669 | progress.foffset = 0; |
… | |
… | |
686 | * looking at the file's extension. If it is unknown, default to |
674 | * looking at the file's extension. If it is unknown, default to |
687 | * Application/Octet-Stream |
675 | * Application/Octet-Stream |
688 | */ |
676 | */ |
689 | |
677 | |
690 | if (mimetype == NULL) { |
678 | if (mimetype == NULL) { |
691 | if ((ptr = _FP_strrchr ((outfname)?outfname:infname, '.'))) { |
679 | if ((ptr = FP_strrchr ((outfname)?outfname:infname, '.'))) { |
692 | while (miter->extension && _FP_stricmp (ptr+1, miter->extension) != 0) |
680 | while (miter->extension && FP_stricmp (ptr+1, miter->extension) != 0) |
693 | miter++; |
681 | miter++; |
694 | mimetype = miter->mimetype; |
682 | mimetype = miter->mimetype; |
695 | } |
683 | } |
696 | } |
684 | } |
697 | |
685 | |
… | |
… | |
715 | } |
703 | } |
716 | |
704 | |
717 | if (encoding == UU_ENCODED || encoding == XX_ENCODED) { |
705 | if (encoding == UU_ENCODED || encoding == XX_ENCODED) { |
718 | fprintf (outfile, "begin %o %s%s", |
706 | fprintf (outfile, "begin %o %s%s", |
719 | (themode) ? themode : 0644, |
707 | (themode) ? themode : 0644, |
720 | UUFNameFilter ((outfname)?outfname:infname), |
708 | UUFNameFilter ((outfname)?outfname:infname), |
721 | eolstring); |
709 | eolstring); |
722 | } |
710 | } |
723 | else if (encoding == YENC_ENCODED) { |
711 | else if (encoding == YENC_ENCODED) { |
724 | crc = crc32(0L, Z_NULL, 0); |
712 | crc = CRC32_INIT; |
725 | crcptr = &crc; |
713 | crcptr = &crc; |
726 | if (progress.fsize == -1) { |
714 | if (progress.fsize == -1) { |
727 | fprintf (outfile, "=ybegin line=128 name=%s%s", |
715 | fprintf (outfile, "=ybegin line=128 name=%s%s", |
728 | UUFNameFilter ((outfname)?outfname:infname), |
716 | UUFNameFilter ((outfname)?outfname:infname), |
729 | eolstring); |
717 | eolstring); |
730 | } |
718 | } |
731 | else { |
719 | else { |
732 | fprintf (outfile, "=ybegin line=128 size=%ld name=%s%s", |
720 | fprintf (outfile, "=ybegin line=128 size=%ld name=%s%s", |
733 | progress.fsize, |
721 | progress.fsize, |
734 | UUFNameFilter ((outfname)?outfname:infname), |
722 | UUFNameFilter ((outfname)?outfname:infname), |
735 | eolstring); |
723 | eolstring); |
736 | } |
724 | } |
737 | } |
725 | } |
738 | |
726 | |
739 | if ((res = UUEncodeStream (outfile, theifile, encoding, 0, crcptr, NULL)) != UURET_OK) { |
727 | if ((res = UUEncodeStream (outfile, theifile, encoding, 0, crcptr, NULL)) != UURET_OK) { |
740 | if (res != UURET_CANCEL) { |
728 | if (res != UURET_CANCEL) { |
741 | UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, |
729 | UUMessage (UUMSG_ERROR, |
742 | uustring (S_ERR_ENCODING), |
730 | uustring (S_ERR_ENCODING), |
743 | UUFNameFilter ((infname)?infname:outfname), |
731 | UUFNameFilter ((infname)?infname:outfname), |
744 | (res==UURET_IOERR)?strerror(uu_errno):UUstrerror(res)); |
732 | (res==UURET_IOERR)?strerror(uu_errno):UUstrerror(res)); |
745 | } |
733 | } |
746 | progress.action = 0; |
734 | progress.action = 0; |
747 | return res; |
735 | return res; |
748 | } |
736 | } |
749 | |
737 | |
750 | if (encoding == UU_ENCODED || encoding == XX_ENCODED) { |
738 | if (encoding == UU_ENCODED || encoding == XX_ENCODED) { |
751 | fprintf (outfile, "%c%s", |
739 | fprintf (outfile, "%c%s", |
752 | (encoding==UU_ENCODED) ? UUEncodeTable[0] : XXEncodeTable[0], |
740 | (encoding==UU_ENCODED) ? UUEncodeTable[0] : XXEncodeTable[0], |
753 | eolstring); |
741 | eolstring); |
754 | fprintf (outfile, "end%s", eolstring); |
742 | fprintf (outfile, "end%s", eolstring); |
755 | } |
743 | } |
756 | else if (encoding == YENC_ENCODED) { |
744 | else if (encoding == YENC_ENCODED) { |
757 | if (progress.fsize == -1) { |
745 | if (progress.fsize == -1) { |
758 | fprintf (outfile, "=yend crc32=%08lx%s", |
746 | fprintf (outfile, "=yend crc32=%08lx%s", |
759 | crc, |
747 | (long)crc, |
760 | eolstring); |
748 | eolstring); |
761 | } |
749 | } |
762 | else { |
750 | else { |
763 | fprintf (outfile, "=yend size=%ld crc32=%08lx%s", |
751 | fprintf (outfile, "=yend size=%ld crc32=%08lx%s", |
764 | progress.fsize, |
752 | progress.fsize, |
765 | crc, |
753 | (long)crc, |
766 | eolstring); |
754 | eolstring); |
767 | } |
755 | } |
768 | } |
756 | } |
769 | |
757 | |
770 | /* |
758 | /* |
… | |
… | |
803 | |
791 | |
804 | if ((outfname==NULL&&infname==NULL) || partno<=0 || |
792 | if ((outfname==NULL&&infname==NULL) || partno<=0 || |
805 | (infile == NULL&&infname==NULL) || outfile==NULL || |
793 | (infile == NULL&&infname==NULL) || outfile==NULL || |
806 | (encoding!=UU_ENCODED&&encoding!=XX_ENCODED&&encoding!=B64ENCODED&& |
794 | (encoding!=UU_ENCODED&&encoding!=XX_ENCODED&&encoding!=B64ENCODED&& |
807 | encoding!=PT_ENCODED&&encoding!=QP_ENCODED&&encoding!=YENC_ENCODED)) { |
795 | encoding!=PT_ENCODED&&encoding!=QP_ENCODED&&encoding!=YENC_ENCODED)) { |
808 | UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, |
796 | UUMessage (UUMSG_ERROR, uustring (S_PARM_CHECK), "UUEncodePartial()"); |
809 | uustring (S_PARM_CHECK), "UUEncodePartial()"); |
|
|
810 | return UURET_ILLVAL; |
797 | return UURET_ILLVAL; |
811 | } |
798 | } |
812 | |
799 | |
813 | /* |
800 | /* |
814 | * The first part needs a set of headers |
801 | * The first part needs a set of headers |
… | |
… | |
817 | progress.action = 0; |
804 | progress.action = 0; |
818 | |
805 | |
819 | if (partno == 1) { |
806 | if (partno == 1) { |
820 | if (infile==NULL) { |
807 | if (infile==NULL) { |
821 | if (stat (infname, &finfo) == -1) { |
808 | if (stat (infname, &finfo) == -1) { |
822 | UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, |
809 | UUMessage (UUMSG_ERROR, |
823 | uustring (S_NOT_STAT_FILE), |
810 | uustring (S_NOT_STAT_FILE), |
824 | infname, strerror (uu_errno=errno)); |
811 | infname, strerror (uu_errno=errno)); |
825 | return UURET_IOERR; |
812 | return UURET_IOERR; |
826 | } |
813 | } |
827 | if ((theifile = fopen (infname, "rb")) == NULL) { |
814 | if ((theifile = fopen (infname, "rb")) == NULL) { |
828 | UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, |
815 | UUMessage (UUMSG_ERROR, |
829 | uustring (S_NOT_OPEN_FILE), |
816 | uustring (S_NOT_OPEN_FILE), |
830 | infname, strerror (uu_errno=errno)); |
817 | infname, strerror (uu_errno=errno)); |
831 | return UURET_IOERR; |
818 | return UURET_IOERR; |
832 | } |
819 | } |
833 | if (linperfile <= 0) |
820 | if (linperfile <= 0) |
834 | numparts = 1; |
821 | numparts = 1; |
835 | else |
822 | else |
836 | numparts = (int) (((long)finfo.st_size+(linperfile*bpl[encoding]-1))/ |
823 | numparts = (int) (((long)finfo.st_size+(linperfile*bpl[encoding]-1))/ |
837 | (linperfile*bpl[encoding])); |
824 | (linperfile*bpl[encoding])); |
838 | |
825 | |
839 | themode = (filemode) ? filemode : ((int) finfo.st_mode & 0777); |
826 | themode = (filemode) ? filemode : ((int) finfo.st_mode & 0777); |
840 | thesize = (long) finfo.st_size; |
827 | thesize = (long) finfo.st_size; |
841 | } |
828 | } |
842 | else { |
829 | else { |
843 | if (fstat (fileno (infile), &finfo) != 0) { |
830 | if (fstat (fileno (infile), &finfo) != 0) { |
844 | UUMessage (uuencode_id, __LINE__, UUMSG_WARNING, |
831 | UUMessage (UUMSG_WARNING, uustring (S_STAT_ONE_PART)); |
845 | uustring (S_STAT_ONE_PART)); |
|
|
846 | numparts = 1; |
832 | numparts = 1; |
847 | themode = (filemode)?filemode:0644; |
833 | themode = (filemode)?filemode:0644; |
848 | thesize = -1; |
834 | thesize = -1; |
849 | } |
835 | } |
850 | else { |
836 | else { |
… | |
… | |
858 | thesize = (long) finfo.st_size; |
844 | thesize = (long) finfo.st_size; |
859 | } |
845 | } |
860 | theifile = infile; |
846 | theifile = infile; |
861 | } |
847 | } |
862 | |
848 | |
863 | _FP_strncpy (progress.curfile, (outfname)?outfname:infname, 256); |
849 | FP_strncpy (progress.curfile, (outfname)?outfname:infname, 256); |
864 | |
850 | |
865 | progress.totsize = (thesize>=0) ? thesize : -1; |
851 | progress.totsize = (thesize>=0) ? thesize : -1; |
866 | progress.partno = 1; |
852 | progress.partno = 1; |
867 | progress.numparts = numparts; |
853 | progress.numparts = numparts; |
868 | progress.percent = 0; |
854 | progress.percent = 0; |
… | |
… | |
873 | * looking at the file's extension. If it is unknown, default to |
859 | * looking at the file's extension. If it is unknown, default to |
874 | * Application/Octet-Stream |
860 | * Application/Octet-Stream |
875 | */ |
861 | */ |
876 | |
862 | |
877 | if (mimetype == NULL) { |
863 | if (mimetype == NULL) { |
878 | if ((ptr = _FP_strrchr ((outfname)?outfname:infname, '.'))) { |
864 | if ((ptr = FP_strrchr ((outfname)?outfname:infname, '.'))) { |
879 | while (miter->extension && _FP_stricmp (ptr+1, miter->extension) != 0) |
865 | while (miter->extension && FP_stricmp (ptr+1, miter->extension) != 0) |
880 | miter++; |
866 | miter++; |
881 | mimetype = miter->mimetype; |
867 | mimetype = miter->mimetype; |
882 | } |
868 | } |
883 | } |
869 | } |
884 | |
870 | |
… | |
… | |
900 | fprintf (outfile, "Content-Disposition: attachment; filename=\"%s\"%s", |
886 | fprintf (outfile, "Content-Disposition: attachment; filename=\"%s\"%s", |
901 | UUFNameFilter ((outfname)?outfname:infname), eolstring); |
887 | UUFNameFilter ((outfname)?outfname:infname), eolstring); |
902 | } |
888 | } |
903 | |
889 | |
904 | fprintf (outfile, "%s", eolstring); |
890 | fprintf (outfile, "%s", eolstring); |
905 | |
891 | |
906 | /* |
892 | /* |
907 | * for the first part of UU or XX messages, print a begin line |
893 | * for the first part of UU or XX messages, print a begin line |
908 | */ |
894 | */ |
909 | |
895 | |
910 | if (encoding == UU_ENCODED || encoding == XX_ENCODED) { |
896 | if (encoding == UU_ENCODED || encoding == XX_ENCODED) { |
… | |
… | |
912 | (themode) ? themode : ((filemode)?filemode:0644), |
898 | (themode) ? themode : ((filemode)?filemode:0644), |
913 | UUFNameFilter ((outfname)?outfname:infname), eolstring); |
899 | UUFNameFilter ((outfname)?outfname:infname), eolstring); |
914 | } |
900 | } |
915 | } |
901 | } |
916 | if (encoding == YENC_ENCODED) { |
902 | if (encoding == YENC_ENCODED) { |
917 | pcrc = crc32(0L, Z_NULL, 0); |
903 | pcrc = CRC32_INIT; |
918 | pcrcptr = &pcrc; |
904 | pcrcptr = &pcrc; |
919 | if (numparts != 1) { |
905 | if (numparts != 1) { |
920 | if (progress.totsize == -1) { |
906 | if (progress.totsize == -1) { |
921 | fprintf (outfile, "=ybegin part=%d line=128 name=%s%s", |
907 | fprintf (outfile, "=ybegin part=%d line=128 name=%s%s", |
922 | partno, |
908 | partno, |
923 | UUFNameFilter ((outfname)?outfname:infname), |
909 | UUFNameFilter ((outfname)?outfname:infname), |
924 | eolstring); |
910 | eolstring); |
925 | } |
911 | } |
926 | else { |
912 | else { |
927 | fprintf (outfile, "=ybegin part=%d line=128 size=%ld name=%s%s", |
913 | fprintf (outfile, "=ybegin part=%d line=128 size=%ld name=%s%s", |
928 | partno, |
914 | partno, |
929 | progress.totsize, |
915 | progress.totsize, |
930 | UUFNameFilter ((outfname)?outfname:infname), |
916 | UUFNameFilter ((outfname)?outfname:infname), |
931 | eolstring); |
917 | eolstring); |
932 | } |
918 | } |
933 | |
919 | |
934 | fprintf (outfile, "=ypart begin=%d end=%d%s", |
920 | fprintf (outfile, "=ypart begin=%ld end=%ld%s", |
935 | (partno-1)*linperfile*128+1, |
921 | (partno - 1) * linperfile * 128 + 1, |
936 | (partno*linperfile*128) < progress.totsize ? |
922 | (partno * linperfile * 128) < progress.totsize |
937 | (partno*linperfile*128) : progress.totsize, |
923 | ? partno * linperfile * 128 |
|
|
924 | : progress.totsize, |
938 | eolstring); |
925 | eolstring); |
939 | } |
926 | } |
940 | else { |
927 | else { |
941 | if (progress.totsize == -1) { |
928 | if (progress.totsize == -1) { |
942 | fprintf (outfile, "=ybegin line=128 name=%s%s", |
929 | fprintf (outfile, "=ybegin line=128 name=%s%s", |
943 | UUFNameFilter ((outfname)?outfname:infname), |
930 | UUFNameFilter ((outfname)?outfname:infname), |
944 | eolstring); |
931 | eolstring); |
945 | } |
932 | } |
946 | else { |
933 | else { |
947 | fprintf (outfile, "=ybegin line=128 size=%ld name=%s%s", |
934 | fprintf (outfile, "=ybegin line=128 size=%ld name=%s%s", |
948 | progress.totsize, |
935 | progress.totsize, |
949 | UUFNameFilter ((outfname)?outfname:infname), |
936 | UUFNameFilter ((outfname)?outfname:infname), |
950 | eolstring); |
937 | eolstring); |
951 | } |
938 | } |
952 | } |
939 | } |
953 | } |
940 | } |
954 | |
941 | |
… | |
… | |
973 | |
960 | |
974 | if ((res = UUEncodeStream (outfile, theifile, encoding, linperfile, |
961 | if ((res = UUEncodeStream (outfile, theifile, encoding, linperfile, |
975 | crcptr, pcrcptr)) != UURET_OK) { |
962 | crcptr, pcrcptr)) != UURET_OK) { |
976 | if (infile==NULL) fclose (theifile); |
963 | if (infile==NULL) fclose (theifile); |
977 | if (res != UURET_CANCEL) { |
964 | if (res != UURET_CANCEL) { |
978 | UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, |
965 | UUMessage (UUMSG_ERROR, |
979 | uustring (S_ERR_ENCODING), |
966 | uustring (S_ERR_ENCODING), |
980 | UUFNameFilter ((outfname)?outfname:infname), |
967 | UUFNameFilter ((outfname)?outfname:infname), |
981 | (res==UURET_IOERR)?strerror(uu_errno):UUstrerror (res)); |
968 | (res==UURET_IOERR)?strerror(uu_errno):UUstrerror (res)); |
982 | } |
969 | } |
983 | progress.action = 0; |
970 | progress.action = 0; |
… | |
… | |
986 | |
973 | |
987 | /* |
974 | /* |
988 | * print end line |
975 | * print end line |
989 | */ |
976 | */ |
990 | |
977 | |
991 | if (feof (theifile) && |
978 | if (FP_feof (theifile) && |
992 | (encoding == UU_ENCODED || encoding == XX_ENCODED)) { |
979 | (encoding == UU_ENCODED || encoding == XX_ENCODED)) { |
993 | fprintf (outfile, "%c%s", |
980 | fprintf (outfile, "%c%s", |
994 | (encoding==UU_ENCODED) ? UUEncodeTable[0] : XXEncodeTable[0], |
981 | (encoding==UU_ENCODED) ? UUEncodeTable[0] : XXEncodeTable[0], |
995 | eolstring); |
982 | eolstring); |
996 | fprintf (outfile, "end%s", eolstring); |
983 | fprintf (outfile, "end%s", eolstring); |
997 | } |
984 | } |
998 | else if (encoding == YENC_ENCODED) { |
985 | else if (encoding == YENC_ENCODED) { |
999 | if (numparts != 1) { |
986 | if (numparts != 1) { |
1000 | fprintf (outfile, "=yend size=%d part=%d pcrc32=%08lx", |
987 | fprintf (outfile, "=yend size=%ld part=%d pcrc32=%08lx", |
1001 | (partno*linperfile*128) < progress.totsize ? |
988 | (partno * linperfile * 128) < progress.totsize |
1002 | linperfile*128 : (progress.totsize-(partno-1)*linperfile*128), |
989 | ? linperfile * 128 |
|
|
990 | : (progress.totsize - (partno - 1) * linperfile * 128), |
1003 | partno, |
991 | partno, |
1004 | pcrc); |
992 | (long)pcrc); |
1005 | } |
993 | } |
1006 | else { |
994 | else { |
1007 | fprintf (outfile, "=yend size=%d", |
995 | fprintf (outfile, "=yend size=%ld", |
1008 | progress.totsize); |
996 | progress.totsize); |
1009 | } |
997 | } |
1010 | if (feof (theifile)) |
998 | if (FP_feof (theifile)) |
1011 | fprintf (outfile, " crc32=%08lx", *crcptr); |
999 | fprintf (outfile, " crc32=%08lx", (long)*crcptr); |
1012 | fprintf (outfile, "%s", eolstring); |
1000 | fprintf (outfile, "%s", eolstring); |
1013 | } |
1001 | } |
1014 | |
1002 | |
1015 | /* |
1003 | /* |
1016 | * empty line at end does no harm |
1004 | * empty line at end does no harm |
… | |
… | |
1024 | if (res != UURET_OK) { |
1012 | if (res != UURET_OK) { |
1025 | progress.action = 0; |
1013 | progress.action = 0; |
1026 | fclose (theifile); |
1014 | fclose (theifile); |
1027 | return res; |
1015 | return res; |
1028 | } |
1016 | } |
1029 | if (feof (theifile)) { |
1017 | if (FP_feof (theifile)) { |
1030 | progress.action = 0; |
1018 | progress.action = 0; |
1031 | fclose (theifile); |
1019 | fclose (theifile); |
1032 | return UURET_OK; |
1020 | return UURET_OK; |
1033 | } |
1021 | } |
1034 | return UURET_CONT; |
1022 | return UURET_CONT; |
… | |
… | |
1060 | if (outfile==NULL || |
1048 | if (outfile==NULL || |
1061 | (infile == NULL&&infname==NULL) || |
1049 | (infile == NULL&&infname==NULL) || |
1062 | (outfname==NULL&&infname==NULL) || |
1050 | (outfname==NULL&&infname==NULL) || |
1063 | (encoding!=UU_ENCODED&&encoding!=XX_ENCODED&&encoding!=B64ENCODED&& |
1051 | (encoding!=UU_ENCODED&&encoding!=XX_ENCODED&&encoding!=B64ENCODED&& |
1064 | encoding!=PT_ENCODED&&encoding!=QP_ENCODED&&encoding!=YENC_ENCODED)) { |
1052 | encoding!=PT_ENCODED&&encoding!=QP_ENCODED&&encoding!=YENC_ENCODED)) { |
1065 | UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, |
1053 | UUMessage (UUMSG_ERROR, uustring (S_PARM_CHECK), "UUEncodeToStream()"); |
1066 | uustring (S_PARM_CHECK), "UUEncodeToStream()"); |
|
|
1067 | return UURET_ILLVAL; |
1054 | return UURET_ILLVAL; |
1068 | } |
1055 | } |
1069 | |
1056 | |
1070 | progress.action = 0; |
1057 | progress.action = 0; |
1071 | |
1058 | |
1072 | if (infile==NULL) { |
1059 | if (infile==NULL) { |
1073 | if (stat (infname, &finfo) == -1) { |
1060 | if (stat (infname, &finfo) == -1) { |
1074 | UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, |
1061 | UUMessage (UUMSG_ERROR, |
1075 | uustring (S_NOT_STAT_FILE), |
1062 | uustring (S_NOT_STAT_FILE), |
1076 | infname, strerror (uu_errno=errno)); |
1063 | infname, strerror (uu_errno=errno)); |
1077 | return UURET_IOERR; |
1064 | return UURET_IOERR; |
1078 | } |
1065 | } |
1079 | if ((theifile = fopen (infname, "rb")) == NULL) { |
1066 | if ((theifile = fopen (infname, "rb")) == NULL) { |
1080 | UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, |
1067 | UUMessage (UUMSG_ERROR, |
1081 | uustring (S_NOT_OPEN_FILE), |
1068 | uustring (S_NOT_OPEN_FILE), |
1082 | infname, strerror (uu_errno=errno)); |
1069 | infname, strerror (uu_errno=errno)); |
1083 | return UURET_IOERR; |
1070 | return UURET_IOERR; |
1084 | } |
1071 | } |
1085 | themode = (filemode) ? filemode : ((int) finfo.st_mode & 0777); |
1072 | themode = (filemode) ? filemode : ((int) finfo.st_mode & 0777); |
… | |
… | |
1099 | } |
1086 | } |
1100 | |
1087 | |
1101 | if (progress.fsize < 0) |
1088 | if (progress.fsize < 0) |
1102 | progress.fsize = -1; |
1089 | progress.fsize = -1; |
1103 | |
1090 | |
1104 | _FP_strncpy (progress.curfile, (outfname)?outfname:infname, 256); |
1091 | FP_strncpy (progress.curfile, (outfname)?outfname:infname, 256); |
1105 | |
1092 | |
1106 | progress.partno = 1; |
1093 | progress.partno = 1; |
1107 | progress.numparts = 1; |
1094 | progress.numparts = 1; |
1108 | progress.percent = 0; |
1095 | progress.percent = 0; |
1109 | progress.foffset = 0; |
1096 | progress.foffset = 0; |
1110 | progress.action = UUACT_ENCODING; |
1097 | progress.action = UUACT_ENCODING; |
1111 | |
1098 | |
1112 | if (encoding == UU_ENCODED || encoding == XX_ENCODED) { |
1099 | if (encoding == UU_ENCODED || encoding == XX_ENCODED) { |
1113 | fprintf (outfile, "begin %o %s%s", |
1100 | fprintf (outfile, "begin %o %s%s", |
1114 | (themode) ? themode : 0644, |
1101 | (themode) ? themode : 0644, |
1115 | UUFNameFilter ((outfname)?outfname:infname), |
1102 | UUFNameFilter ((outfname)?outfname:infname), |
1116 | eolstring); |
1103 | eolstring); |
1117 | } |
1104 | } |
1118 | else if (encoding == YENC_ENCODED) { |
1105 | else if (encoding == YENC_ENCODED) { |
1119 | crc = crc32(0L, Z_NULL, 0); |
1106 | crc = CRC32_INIT; |
1120 | crcptr = &crc; |
1107 | crcptr = &crc; |
1121 | if (progress.fsize == -1) { |
1108 | if (progress.fsize == -1) { |
1122 | fprintf (outfile, "=ybegin line=128 name=%s%s", |
1109 | fprintf (outfile, "=ybegin line=128 name=%s%s", |
1123 | UUFNameFilter ((outfname)?outfname:infname), |
1110 | UUFNameFilter ((outfname)?outfname:infname), |
1124 | eolstring); |
1111 | eolstring); |
1125 | } |
1112 | } |
1126 | else { |
1113 | else { |
1127 | fprintf (outfile, "=ybegin line=128 size=%ld name=%s%s", |
1114 | fprintf (outfile, "=ybegin line=128 size=%ld name=%s%s", |
1128 | progress.fsize, |
1115 | progress.fsize, |
1129 | UUFNameFilter ((outfname)?outfname:infname), |
1116 | UUFNameFilter ((outfname)?outfname:infname), |
1130 | eolstring); |
1117 | eolstring); |
1131 | } |
1118 | } |
1132 | } |
1119 | } |
1133 | |
1120 | |
1134 | if ((res = UUEncodeStream (outfile, theifile, encoding, 0, crcptr, NULL)) != UURET_OK) { |
1121 | if ((res = UUEncodeStream (outfile, theifile, encoding, 0, crcptr, NULL)) != UURET_OK) { |
1135 | if (res != UURET_CANCEL) { |
1122 | if (res != UURET_CANCEL) { |
1136 | UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, |
1123 | UUMessage (UUMSG_ERROR, |
1137 | uustring (S_ERR_ENCODING), |
1124 | uustring (S_ERR_ENCODING), |
1138 | UUFNameFilter ((infname)?infname:outfname), |
1125 | UUFNameFilter ((infname)?infname:outfname), |
1139 | (res==UURET_IOERR)?strerror(uu_errno):UUstrerror (res)); |
1126 | (res==UURET_IOERR)?strerror(uu_errno):UUstrerror (res)); |
1140 | } |
1127 | } |
1141 | progress.action = 0; |
1128 | progress.action = 0; |
1142 | return res; |
1129 | return res; |
1143 | } |
1130 | } |
1144 | |
1131 | |
1145 | if (encoding == UU_ENCODED || encoding == XX_ENCODED) { |
1132 | if (encoding == UU_ENCODED || encoding == XX_ENCODED) { |
1146 | fprintf (outfile, "%c%s", |
1133 | fprintf (outfile, "%c%s", |
1147 | (encoding==UU_ENCODED) ? UUEncodeTable[0] : XXEncodeTable[0], |
1134 | (encoding==UU_ENCODED) ? UUEncodeTable[0] : XXEncodeTable[0], |
1148 | eolstring); |
1135 | eolstring); |
1149 | fprintf (outfile, "end%s", eolstring); |
1136 | fprintf (outfile, "end%s", eolstring); |
1150 | } |
1137 | } |
1151 | else if (encoding == YENC_ENCODED) { |
1138 | else if (encoding == YENC_ENCODED) { |
1152 | if (progress.fsize == -1) { |
1139 | if (progress.fsize == -1) { |
1153 | fprintf (outfile, "=yend crc32=%08lx%s", |
1140 | fprintf (outfile, "=yend crc32=%08lx%s", |
1154 | crc, |
1141 | (long)crc, |
1155 | eolstring); |
1142 | eolstring); |
1156 | } |
1143 | } |
1157 | else { |
1144 | else { |
1158 | fprintf (outfile, "=yend size=%ld crc32=%08lx%s", |
1145 | fprintf (outfile, "=yend size=%ld crc32=%08lx%s", |
1159 | progress.fsize, |
1146 | progress.fsize, |
1160 | crc, |
1147 | (long)crc, |
1161 | eolstring); |
1148 | eolstring); |
1162 | } |
1149 | } |
1163 | } |
1150 | } |
1164 | |
1151 | |
1165 | /* |
1152 | /* |
… | |
… | |
1191 | |
1178 | |
1192 | if ((diskname==NULL&&infname==NULL) || |
1179 | if ((diskname==NULL&&infname==NULL) || |
1193 | (outfname==NULL&&infname==NULL) || (infile==NULL&&infname==NULL) || |
1180 | (outfname==NULL&&infname==NULL) || (infile==NULL&&infname==NULL) || |
1194 | (encoding!=UU_ENCODED&&encoding!=XX_ENCODED&&encoding!=B64ENCODED&& |
1181 | (encoding!=UU_ENCODED&&encoding!=XX_ENCODED&&encoding!=B64ENCODED&& |
1195 | encoding!=PT_ENCODED&&encoding!=QP_ENCODED&&encoding!=YENC_ENCODED)) { |
1182 | encoding!=PT_ENCODED&&encoding!=QP_ENCODED&&encoding!=YENC_ENCODED)) { |
1196 | UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, |
1183 | UUMessage (UUMSG_ERROR, uustring (S_PARM_CHECK), "UUEncodeToFile()"); |
1197 | uustring (S_PARM_CHECK), "UUEncodeToFile()"); |
|
|
1198 | return UURET_ILLVAL; |
1184 | return UURET_ILLVAL; |
1199 | } |
1185 | } |
1200 | |
1186 | |
1201 | if (diskname) { |
1187 | if (diskname) { |
1202 | if ((ptr = strchr (diskname, '/')) == NULL) |
1188 | if ((ptr = strchr (diskname, '/')) == NULL) |
1203 | ptr = strchr (diskname, '\\'); |
1189 | ptr = strchr (diskname, '\\'); |
1204 | if (ptr) { |
1190 | if (ptr) { |
1205 | len = strlen (diskname) + ((uuencodeext)?strlen(uuencodeext):3) + 5; |
1191 | len = strlen (diskname) + ((uuencodeext)?strlen(uuencodeext):3) + 5; |
1206 | |
1192 | |
1207 | if ((oname = malloc (len)) == NULL) { |
1193 | if ((oname = malloc (len)) == NULL) { |
1208 | UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, |
1194 | UUMessage (UUMSG_ERROR, uustring (S_OUT_OF_MEMORY), len); |
1209 | uustring (S_OUT_OF_MEMORY), len); |
|
|
1210 | return UURET_NOMEM; |
1195 | return UURET_NOMEM; |
1211 | } |
1196 | } |
1212 | sprintf (oname, "%s", diskname); |
1197 | sprintf (oname, "%s", diskname); |
1213 | } |
1198 | } |
1214 | else { |
1199 | else { |
1215 | len = ((uusavepath)?strlen(uusavepath):0) + strlen (diskname) |
1200 | len = ((uusavepath)?strlen(uusavepath):0) + strlen (diskname) |
1216 | + ((uuencodeext)?strlen(uuencodeext):0) + 5; |
1201 | + ((uuencodeext)?strlen(uuencodeext):0) + 5; |
1217 | |
1202 | |
1218 | if ((oname = malloc (len)) == NULL) { |
1203 | if ((oname = malloc (len)) == NULL) { |
1219 | UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, |
1204 | UUMessage (UUMSG_ERROR, uustring (S_OUT_OF_MEMORY), len); |
1220 | uustring (S_OUT_OF_MEMORY), len); |
|
|
1221 | return UURET_NOMEM; |
1205 | return UURET_NOMEM; |
1222 | } |
1206 | } |
1223 | sprintf (oname, "%s%s", (uusavepath)?uusavepath:"", diskname); |
1207 | sprintf (oname, "%s%s", (uusavepath)?uusavepath:"", diskname); |
1224 | } |
1208 | } |
1225 | } |
1209 | } |
1226 | else { |
1210 | else { |
1227 | len = ((uusavepath) ? strlen (uusavepath) : 0) + |
1211 | len = ((uusavepath) ? strlen (uusavepath) : 0) + |
1228 | strlen(UUFNameFilter(infname)) + |
1212 | strlen(UUFNameFilter(infname)) + |
1229 | ((uuencodeext)?strlen(uuencodeext):0) + 5; |
1213 | ((uuencodeext)?strlen(uuencodeext):0) + 5; |
1230 | |
1214 | |
1231 | if ((oname = malloc (len)) == NULL) { |
1215 | if ((oname = malloc (len)) == NULL) { |
1232 | UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, |
1216 | UUMessage (UUMSG_ERROR, uustring (S_OUT_OF_MEMORY), len); |
1233 | uustring (S_OUT_OF_MEMORY), len); |
|
|
1234 | return UURET_NOMEM; |
1217 | return UURET_NOMEM; |
1235 | } |
1218 | } |
1236 | optr = UUFNameFilter (infname); |
1219 | optr = UUFNameFilter (infname); |
1237 | sprintf (oname, "%s%s", |
1220 | sprintf (oname, "%s%s", |
1238 | (uusavepath)?uusavepath:"", |
1221 | (uusavepath)?uusavepath:"", |
1239 | (*optr=='.')?optr+1:optr); |
1222 | (*optr=='.')?optr+1:optr); |
1240 | } |
1223 | } |
1241 | |
1224 | |
1242 | /* |
1225 | /* |
1243 | * optr points after the last dot, so that we can print the part number |
1226 | * optr points after the last dot, so that we can print the part number |
1244 | * there. |
1227 | * there. |
1245 | */ |
1228 | */ |
1246 | |
1229 | |
1247 | optr = _FP_strrchr (oname, '.'); |
1230 | optr = FP_strrchr (oname, '.'); |
1248 | if (optr==NULL || strchr (optr, '/')!=NULL || strchr (optr, '\\')!=NULL) { |
1231 | if (optr==NULL || strchr (optr, '/')!=NULL || strchr (optr, '\\')!=NULL) { |
1249 | optr = oname + strlen (oname); |
1232 | optr = oname + strlen (oname); |
1250 | *optr++ = '.'; |
1233 | *optr++ = '.'; |
1251 | } |
1234 | } |
1252 | else if (optr==oname || *(optr-1)=='/' || *(optr-1)=='\\') { |
1235 | else if (optr==oname || *(optr-1)=='/' || *(optr-1)=='\\') { |
… | |
… | |
1258 | |
1241 | |
1259 | progress.action = 0; |
1242 | progress.action = 0; |
1260 | |
1243 | |
1261 | if (infile==NULL) { |
1244 | if (infile==NULL) { |
1262 | if (stat (infname, &finfo) == -1) { |
1245 | if (stat (infname, &finfo) == -1) { |
1263 | UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, |
1246 | UUMessage (UUMSG_ERROR, |
1264 | uustring (S_NOT_STAT_FILE), |
1247 | uustring (S_NOT_STAT_FILE), |
1265 | infname, strerror (uu_errno=errno)); |
1248 | infname, strerror (uu_errno=errno)); |
1266 | _FP_free (oname); |
1249 | FP_free (oname); |
1267 | return UURET_IOERR; |
1250 | return UURET_IOERR; |
1268 | } |
1251 | } |
1269 | if ((theifile = fopen (infname, "rb")) == NULL) { |
1252 | if ((theifile = fopen (infname, "rb")) == NULL) { |
1270 | UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, |
1253 | UUMessage (UUMSG_ERROR, |
1271 | uustring (S_NOT_OPEN_FILE), |
1254 | uustring (S_NOT_OPEN_FILE), |
1272 | infname, strerror (uu_errno=errno)); |
1255 | infname, strerror (uu_errno=errno)); |
1273 | _FP_free (oname); |
1256 | FP_free (oname); |
1274 | return UURET_IOERR; |
1257 | return UURET_IOERR; |
1275 | } |
1258 | } |
1276 | if (linperfile <= 0) |
1259 | if (linperfile <= 0) |
1277 | numparts = 1; |
1260 | numparts = 1; |
1278 | else |
1261 | else |
1279 | numparts = (int) (((long)finfo.st_size + (linperfile*bpl[encoding]-1)) / |
1262 | numparts = (int) (((long)finfo.st_size + (linperfile*bpl[encoding]-1)) / |
1280 | (linperfile*bpl[encoding])); |
1263 | (linperfile*bpl[encoding])); |
1281 | |
1264 | |
1282 | filemode = (int) finfo.st_mode & 0777; |
1265 | filemode = (int) finfo.st_mode & 0777; |
1283 | progress.totsize = (long) finfo.st_size; |
1266 | progress.totsize = (long) finfo.st_size; |
… | |
… | |
1300 | progress.totsize = -1; |
1283 | progress.totsize = -1; |
1301 | } |
1284 | } |
1302 | theifile = infile; |
1285 | theifile = infile; |
1303 | } |
1286 | } |
1304 | |
1287 | |
1305 | _FP_strncpy (progress.curfile, (outfname)?outfname:infname, 256); |
1288 | FP_strncpy (progress.curfile, (outfname)?outfname:infname, 256); |
1306 | |
1289 | |
1307 | progress.totsize = (progress.totsize<0) ? -1 : progress.totsize; |
1290 | progress.totsize = (progress.totsize<0) ? -1 : progress.totsize; |
1308 | progress.numparts = numparts; |
1291 | progress.numparts = numparts; |
1309 | |
1292 | |
1310 | for (part=1; !feof (theifile); part++) { |
1293 | for (part=1; !FP_feof (theifile); part++) { |
1311 | /* |
1294 | /* |
1312 | * Attach extension |
1295 | * Attach extension |
1313 | */ |
1296 | */ |
1314 | if (progress.numparts==1 && progress.totsize!=-1 && uuencodeext!=NULL) |
1297 | if (progress.numparts==1 && progress.totsize!=-1 && uuencodeext!=NULL) |
1315 | strcpy (optr, uuencodeext); |
1298 | strcpy (optr, uuencodeext); |
1316 | else |
1299 | else |
1317 | sprintf (optr, "%03d", part); |
1300 | sprintf (optr, "%03d", part); |
1318 | |
1301 | |
1319 | /* |
1302 | /* |
1320 | * check if target file exists |
1303 | * check if target file exists |
1321 | */ |
1304 | */ |
1322 | |
1305 | |
1323 | if (!uu_overwrite) { |
1306 | if (!uu_overwrite) { |
1324 | if (stat (oname, &finfo) == 0) { |
1307 | if (stat (oname, &finfo) == 0) { |
1325 | UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, |
1308 | UUMessage (UUMSG_ERROR, uustring (S_TARGET_EXISTS), oname); |
1326 | uustring (S_TARGET_EXISTS), oname); |
|
|
1327 | if (infile==NULL) fclose (theifile); |
1309 | if (infile==NULL) fclose (theifile); |
1328 | progress.action = 0; |
1310 | progress.action = 0; |
1329 | free (oname); |
1311 | free (oname); |
1330 | return UURET_EXISTS; |
1312 | return UURET_EXISTS; |
1331 | } |
1313 | } |
… | |
… | |
1350 | progress.fsize = linperfile*bpl[encoding]; |
1332 | progress.fsize = linperfile*bpl[encoding]; |
1351 | |
1333 | |
1352 | progress.action = UUACT_ENCODING; |
1334 | progress.action = UUACT_ENCODING; |
1353 | |
1335 | |
1354 | if ((outfile = fopen (oname, "w")) == NULL) { |
1336 | if ((outfile = fopen (oname, "w")) == NULL) { |
1355 | UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, |
1337 | UUMessage (UUMSG_ERROR, |
1356 | uustring (S_NOT_OPEN_TARGET), |
1338 | uustring (S_NOT_OPEN_TARGET), |
1357 | oname, strerror (uu_errno = errno)); |
1339 | oname, strerror (uu_errno = errno)); |
1358 | if (infile==NULL) fclose (theifile); |
1340 | if (infile==NULL) fclose (theifile); |
1359 | progress.action = 0; |
1341 | progress.action = 0; |
1360 | free (oname); |
1342 | free (oname); |
… | |
… | |
1378 | } |
1360 | } |
1379 | |
1361 | |
1380 | if (part==1 && (encoding == UU_ENCODED || encoding == XX_ENCODED)) { |
1362 | if (part==1 && (encoding == UU_ENCODED || encoding == XX_ENCODED)) { |
1381 | fprintf (outfile, "begin %o %s%s", |
1363 | fprintf (outfile, "begin %o %s%s", |
1382 | (filemode)?filemode : 0644, |
1364 | (filemode)?filemode : 0644, |
1383 | UUFNameFilter ((outfname)?outfname:infname), |
1365 | UUFNameFilter ((outfname)?outfname:infname), |
1384 | eolstring); |
1366 | eolstring); |
1385 | } |
1367 | } |
1386 | else if (encoding == YENC_ENCODED) { |
1368 | else if (encoding == YENC_ENCODED) { |
1387 | if (!crcptr) { |
1369 | if (!crcptr) { |
1388 | crc = crc32(0L, Z_NULL, 0); |
1370 | crc = CRC32_INIT; |
1389 | crcptr = &crc; |
1371 | crcptr = &crc; |
1390 | } |
1372 | } |
1391 | pcrc = crc32(0L, Z_NULL, 0); |
1373 | pcrc = CRC32_INIT; |
1392 | pcrcptr = &pcrc; |
1374 | pcrcptr = &pcrc; |
1393 | if (numparts != 1) { |
1375 | if (numparts != 1) { |
1394 | if (progress.totsize == -1) { |
1376 | if (progress.totsize == -1) { |
1395 | fprintf (outfile, "=ybegin part=%d line=128 name=%s%s", |
1377 | fprintf (outfile, "=ybegin part=%d line=128 name=%s%s", |
1396 | part, |
1378 | part, |
1397 | UUFNameFilter ((outfname)?outfname:infname), |
1379 | UUFNameFilter ((outfname)?outfname:infname), |
1398 | eolstring); |
1380 | eolstring); |
1399 | } |
1381 | } |
1400 | else { |
1382 | else { |
1401 | fprintf (outfile, "=ybegin part=%d line=128 size=%ld name=%s%s", |
1383 | fprintf (outfile, "=ybegin part=%d line=128 size=%ld name=%s%s", |
1402 | part, |
1384 | part, |
1403 | progress.totsize, |
1385 | progress.totsize, |
1404 | UUFNameFilter ((outfname)?outfname:infname), |
1386 | UUFNameFilter ((outfname)?outfname:infname), |
1405 | eolstring); |
1387 | eolstring); |
1406 | } |
1388 | } |
1407 | |
1389 | |
1408 | fprintf (outfile, "=ypart begin=%d end=%d%s", |
1390 | fprintf (outfile, "=ypart begin=%ld end=%ld%s", |
1409 | (part-1)*linperfile*128+1, |
1391 | (part-1)*linperfile*128+1, |
1410 | (part*linperfile*128) < progress.totsize ? |
1392 | (part*linperfile*128) < progress.totsize ? |
1411 | (part*linperfile*128) : progress.totsize, |
1393 | (part*linperfile*128) : progress.totsize, |
1412 | eolstring); |
1394 | eolstring); |
1413 | } |
1395 | } |
1414 | else { |
1396 | else { |
1415 | if (progress.totsize == -1) { |
1397 | if (progress.totsize == -1) { |
1416 | fprintf (outfile, "=ybegin line=128 name=%s%s", |
1398 | fprintf (outfile, "=ybegin line=128 name=%s%s", |
1417 | UUFNameFilter ((outfname)?outfname:infname), |
1399 | UUFNameFilter ((outfname)?outfname:infname), |
1418 | eolstring); |
1400 | eolstring); |
1419 | } |
1401 | } |
1420 | else { |
1402 | else { |
1421 | fprintf (outfile, "=ybegin line=128 size=%ld name=%s%s", |
1403 | fprintf (outfile, "=ybegin line=128 size=%ld name=%s%s", |
1422 | progress.totsize, |
1404 | progress.totsize, |
1423 | UUFNameFilter ((outfname)?outfname:infname), |
1405 | UUFNameFilter ((outfname)?outfname:infname), |
1424 | eolstring); |
1406 | eolstring); |
1425 | } |
1407 | } |
1426 | } |
1408 | } |
1427 | } |
1409 | } |
1428 | |
1410 | |
1429 | if ((res = UUEncodeStream (outfile, theifile, |
1411 | if ((res = UUEncodeStream (outfile, theifile, |
1430 | encoding, linperfile, crcptr, pcrcptr)) != UURET_OK) { |
1412 | encoding, linperfile, crcptr, pcrcptr)) != UURET_OK) { |
1431 | if (res != UURET_CANCEL) { |
1413 | if (res != UURET_CANCEL) { |
1432 | UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, |
1414 | UUMessage (UUMSG_ERROR, |
1433 | uustring (S_ERR_ENCODING), |
1415 | uustring (S_ERR_ENCODING), |
1434 | UUFNameFilter ((infname)?infname:outfname), |
1416 | UUFNameFilter ((infname)?infname:outfname), |
1435 | (res==UURET_IOERR)?strerror(uu_errno):UUstrerror (res)); |
1417 | (res==UURET_IOERR)?strerror(uu_errno):UUstrerror (res)); |
1436 | } |
1418 | } |
1437 | if (infile==NULL) fclose (theifile); |
1419 | if (infile==NULL) fclose (theifile); |
1438 | progress.action = 0; |
1420 | progress.action = 0; |
1439 | fclose (outfile); |
1421 | fclose (outfile); |
1440 | unlink (oname); |
1422 | unlink (oname); |
1441 | _FP_free (oname); |
1423 | FP_free (oname); |
1442 | return res; |
1424 | return res; |
1443 | } |
1425 | } |
1444 | |
1426 | |
1445 | if (feof (theifile) && |
1427 | if (FP_feof (theifile) && |
1446 | (encoding == UU_ENCODED || encoding == XX_ENCODED)) { |
1428 | (encoding == UU_ENCODED || encoding == XX_ENCODED)) { |
1447 | fprintf (outfile, "%c%s", |
1429 | fprintf (outfile, "%c%s", |
1448 | (encoding==UU_ENCODED) ? UUEncodeTable[0] : XXEncodeTable[0], |
1430 | (encoding==UU_ENCODED) ? UUEncodeTable[0] : XXEncodeTable[0], |
1449 | eolstring); |
1431 | eolstring); |
1450 | fprintf (outfile, "end%s", eolstring); |
1432 | fprintf (outfile, "end%s", eolstring); |
1451 | } |
1433 | } |
1452 | else if (encoding == YENC_ENCODED) { |
1434 | else if (encoding == YENC_ENCODED) { |
1453 | if (numparts != 1) { |
1435 | if (numparts != 1) { |
1454 | fprintf (outfile, "=yend size=%d part=%d pcrc32=%08lx", |
1436 | fprintf (outfile, "=yend size=%ld part=%d pcrc32=%08lx", |
1455 | (part*linperfile*128) < progress.totsize ? |
1437 | (part*linperfile*128) < progress.totsize ? |
1456 | linperfile*128 : (progress.totsize-(part-1)*linperfile*128), |
1438 | linperfile*128 : (progress.totsize-(part-1)*linperfile*128), |
1457 | part, |
1439 | part, |
1458 | pcrc); |
1440 | (long)pcrc); |
1459 | } |
1441 | } |
1460 | else { |
1442 | else { |
1461 | fprintf (outfile, "=yend size=%d", |
1443 | fprintf (outfile, "=yend size=%ld", |
1462 | progress.totsize); |
1444 | progress.totsize); |
1463 | } |
1445 | } |
1464 | if (feof (theifile)) |
1446 | if (FP_feof (theifile)) |
1465 | fprintf (outfile, " crc32=%08lx", crc); |
1447 | fprintf (outfile, " crc32=%08lx", (long)crc); |
1466 | fprintf (outfile, "%s", eolstring); |
1448 | fprintf (outfile, "%s", eolstring); |
1467 | } |
1449 | } |
1468 | |
1450 | |
1469 | /* |
1451 | /* |
1470 | * empty line at end does no harm |
1452 | * empty line at end does no harm |
… | |
… | |
1474 | fclose (outfile); |
1456 | fclose (outfile); |
1475 | } |
1457 | } |
1476 | |
1458 | |
1477 | if (infile==NULL) fclose (theifile); |
1459 | if (infile==NULL) fclose (theifile); |
1478 | progress.action = 0; |
1460 | progress.action = 0; |
1479 | _FP_free (oname); |
1461 | FP_free (oname); |
1480 | return UURET_OK; |
1462 | return UURET_OK; |
1481 | } |
1463 | } |
1482 | |
1464 | |
1483 | /* |
1465 | /* |
1484 | * Encode a MIME Mail message or Newsgroup posting and send to a |
1466 | * Encode a MIME Mail message or Newsgroup posting and send to a |
… | |
… | |
1515 | int res, len; |
1497 | int res, len; |
1516 | |
1498 | |
1517 | if ((outfname==NULL&&infname==NULL) || (infile==NULL&&infname==NULL) || |
1499 | if ((outfname==NULL&&infname==NULL) || (infile==NULL&&infname==NULL) || |
1518 | (encoding!=UU_ENCODED&&encoding!=XX_ENCODED&&encoding!=B64ENCODED&& |
1500 | (encoding!=UU_ENCODED&&encoding!=XX_ENCODED&&encoding!=B64ENCODED&& |
1519 | encoding!=PT_ENCODED&&encoding!=QP_ENCODED&&encoding!=YENC_ENCODED)) { |
1501 | encoding!=PT_ENCODED&&encoding!=QP_ENCODED&&encoding!=YENC_ENCODED)) { |
1520 | UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, |
1502 | UUMessage (UUMSG_ERROR, uustring (S_PARM_CHECK), "UUE_PrepSingle()"); |
1521 | uustring (S_PARM_CHECK), "UUE_PrepSingle()"); |
|
|
1522 | return UURET_ILLVAL; |
1503 | return UURET_ILLVAL; |
1523 | } |
1504 | } |
1524 | |
1505 | |
1525 | oname = UUFNameFilter ((outfname)?outfname:infname); |
1506 | oname = UUFNameFilter ((outfname)?outfname:infname); |
1526 | len = ((subject)?strlen(subject):0) + strlen(oname) + 40; |
1507 | len = ((subject)?strlen(subject):0) + strlen(oname) + 40; |
1527 | |
1508 | |
1528 | if ((ptr = _FP_strrchr (oname, '.'))) { |
1509 | if ((ptr = FP_strrchr (oname, '.'))) { |
1529 | while (miter->extension && _FP_stricmp (ptr+1, miter->extension) != 0) |
1510 | while (miter->extension && FP_stricmp (ptr+1, miter->extension) != 0) |
1530 | miter++; |
1511 | miter++; |
1531 | mimetype = miter->mimetype; |
1512 | mimetype = miter->mimetype; |
1532 | } |
1513 | } |
1533 | else |
1514 | else |
1534 | mimetype = NULL; |
1515 | mimetype = NULL; |
… | |
… | |
1536 | if (mimetype == NULL && (encoding == PT_ENCODED || encoding == QP_ENCODED)) { |
1517 | if (mimetype == NULL && (encoding == PT_ENCODED || encoding == QP_ENCODED)) { |
1537 | mimetype = "text/plain"; |
1518 | mimetype = "text/plain"; |
1538 | } |
1519 | } |
1539 | |
1520 | |
1540 | if ((subline = (char *) malloc (len)) == NULL) { |
1521 | if ((subline = (char *) malloc (len)) == NULL) { |
1541 | UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, |
1522 | UUMessage (UUMSG_ERROR, uustring (S_OUT_OF_MEMORY), len); |
1542 | uustring (S_OUT_OF_MEMORY), len); |
|
|
1543 | return UURET_NOMEM; |
1523 | return UURET_NOMEM; |
1544 | } |
1524 | } |
1545 | |
1525 | |
1546 | if (encoding == YENC_ENCODED) { |
1526 | if (encoding == YENC_ENCODED) { |
1547 | if (subject) |
1527 | if (subject) |
… | |
… | |
1583 | |
1563 | |
1584 | fprintf (outfile, "%s", eolstring); |
1564 | fprintf (outfile, "%s", eolstring); |
1585 | |
1565 | |
1586 | res = UUEncodeToStream (outfile, infile, infname, encoding, |
1566 | res = UUEncodeToStream (outfile, infile, infname, encoding, |
1587 | outfname, filemode); |
1567 | outfname, filemode); |
1588 | |
1568 | |
1589 | _FP_free (subline); |
1569 | FP_free (subline); |
1590 | return res; |
1570 | return res; |
1591 | } |
1571 | } |
1592 | |
1572 | |
1593 | int UUEXPORT |
1573 | int UUEXPORT |
1594 | UUE_PrepPartial (FILE *outfile, FILE *infile, |
1574 | UUE_PrepPartial (FILE *outfile, FILE *infile, |
… | |
… | |
1627 | crc32_t *crcptr=NULL; |
1607 | crc32_t *crcptr=NULL; |
1628 | |
1608 | |
1629 | if ((outfname==NULL&&infname==NULL) || (infile==NULL&&infname==NULL) || |
1609 | if ((outfname==NULL&&infname==NULL) || (infile==NULL&&infname==NULL) || |
1630 | (encoding!=UU_ENCODED&&encoding!=XX_ENCODED&&encoding!=B64ENCODED&& |
1610 | (encoding!=UU_ENCODED&&encoding!=XX_ENCODED&&encoding!=B64ENCODED&& |
1631 | encoding!=PT_ENCODED&&encoding!=QP_ENCODED&&encoding!=YENC_ENCODED)) { |
1611 | encoding!=PT_ENCODED&&encoding!=QP_ENCODED&&encoding!=YENC_ENCODED)) { |
1632 | UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, |
1612 | UUMessage (UUMSG_ERROR, uustring (S_PARM_CHECK), "UUE_PrepPartial()"); |
1633 | uustring (S_PARM_CHECK), "UUE_PrepPartial()"); |
|
|
1634 | return UURET_ILLVAL; |
1613 | return UURET_ILLVAL; |
1635 | } |
1614 | } |
1636 | |
1615 | |
1637 | oname = UUFNameFilter ((outfname)?outfname:infname); |
1616 | oname = UUFNameFilter ((outfname)?outfname:infname); |
1638 | len = ((subject)?strlen(subject):0) + strlen (oname) + 40; |
1617 | len = ((subject)?strlen(subject):0) + strlen (oname) + 40; |
… | |
… | |
1642 | */ |
1621 | */ |
1643 | |
1622 | |
1644 | if (partno == 1) { |
1623 | if (partno == 1) { |
1645 | if (infile==NULL) { |
1624 | if (infile==NULL) { |
1646 | if (stat (infname, &finfo) == -1) { |
1625 | if (stat (infname, &finfo) == -1) { |
1647 | UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, |
1626 | UUMessage (UUMSG_ERROR, |
1648 | uustring (S_NOT_STAT_FILE), |
1627 | uustring (S_NOT_STAT_FILE), |
1649 | infname, strerror (uu_errno=errno)); |
1628 | infname, strerror (uu_errno=errno)); |
1650 | return UURET_IOERR; |
1629 | return UURET_IOERR; |
1651 | } |
1630 | } |
1652 | if ((theifile = fopen (infname, "rb")) == NULL) { |
1631 | if ((theifile = fopen (infname, "rb")) == NULL) { |
1653 | UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, |
1632 | UUMessage (UUMSG_ERROR, |
1654 | uustring (S_NOT_OPEN_FILE), |
1633 | uustring (S_NOT_OPEN_FILE), |
1655 | infname, strerror (uu_errno=errno)); |
1634 | infname, strerror (uu_errno=errno)); |
1656 | return UURET_IOERR; |
1635 | return UURET_IOERR; |
1657 | } |
1636 | } |
1658 | if (linperfile <= 0) |
1637 | if (linperfile <= 0) |
1659 | numparts = 1; |
1638 | numparts = 1; |
1660 | else |
1639 | else |
1661 | numparts = (int) (((long)finfo.st_size+(linperfile*bpl[encoding]-1))/ |
1640 | numparts = (int) (((long)finfo.st_size+(linperfile*bpl[encoding]-1))/ |
1662 | (linperfile*bpl[encoding])); |
1641 | (linperfile*bpl[encoding])); |
1663 | |
1642 | |
1664 | themode = (filemode) ? filemode : ((int) finfo.st_mode & 0777); |
1643 | themode = (filemode) ? filemode : ((int) finfo.st_mode & 0777); |
1665 | thesize = (long) finfo.st_size; |
1644 | thesize = (long) finfo.st_size; |
1666 | } |
1645 | } |
1667 | else { |
1646 | else { |
1668 | if (fstat (fileno (infile), &finfo) != 0) { |
1647 | if (fstat (fileno (infile), &finfo) != 0) { |
1669 | if (filesize <= 0) { |
1648 | if (filesize <= 0) { |
1670 | UUMessage (uuencode_id, __LINE__, UUMSG_WARNING, |
1649 | UUMessage (UUMSG_WARNING, uustring (S_STAT_ONE_PART)); |
1671 | uustring (S_STAT_ONE_PART)); |
|
|
1672 | numparts = 1; |
1650 | numparts = 1; |
1673 | themode = (filemode)?filemode:0644; |
1651 | themode = (filemode)?filemode:0644; |
1674 | thesize = -1; |
1652 | thesize = -1; |
1675 | } |
1653 | } |
1676 | else { |
1654 | else { |
… | |
… | |
1716 | (long) time(NULL), thesize, |
1694 | (long) time(NULL), thesize, |
1717 | (strlen(oname)>16)?"oops":oname); |
1695 | (strlen(oname)>16)?"oops":oname); |
1718 | } |
1696 | } |
1719 | |
1697 | |
1720 | if ((subline = (char *) malloc (len)) == NULL) { |
1698 | if ((subline = (char *) malloc (len)) == NULL) { |
1721 | UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, |
1699 | UUMessage (UUMSG_ERROR, uustring (S_OUT_OF_MEMORY), len); |
1722 | uustring (S_OUT_OF_MEMORY), len); |
|
|
1723 | if (infile==NULL) fclose (theifile); |
1700 | if (infile==NULL) fclose (theifile); |
1724 | return UURET_NOMEM; |
1701 | return UURET_NOMEM; |
1725 | } |
1702 | } |
1726 | |
1703 | |
1727 | |
1704 | |
1728 | if (encoding == YENC_ENCODED) { |
1705 | if (encoding == YENC_ENCODED) { |
1729 | if (partno == 1) |
1706 | if (partno == 1) |
1730 | crc = crc32(0L, Z_NULL, 0); |
1707 | crc = CRC32_INIT; |
1731 | crcptr = &crc; |
1708 | crcptr = &crc; |
1732 | if (subject) |
1709 | if (subject) |
1733 | sprintf (subline, "- %s - %s (%03d/%03d)", oname, subject, |
1710 | sprintf (subline, "- %s - %s (%03d/%03d)", oname, subject, |
1734 | partno, numparts); |
1711 | partno, numparts); |
1735 | else |
1712 | else |
1736 | sprintf (subline, "- %s - (%03d/%03d)", oname, |
1713 | sprintf (subline, "- %s - (%03d/%03d)", oname, |
1737 | partno, numparts); |
1714 | partno, numparts); |
1738 | } |
1715 | } |
1739 | else { |
1716 | else { |
1740 | if (subject) |
1717 | if (subject) |
1741 | sprintf (subline, "%s (%03d/%03d) - [ %s ]", |
1718 | sprintf (subline, "%s (%03d/%03d) - [ %s ]", |
1742 | subject, partno, numparts, oname); |
1719 | subject, partno, numparts, oname); |
1743 | else |
1720 | else |
1744 | sprintf (subline, "[ %s ] (%03d/%03d)", |
1721 | sprintf (subline, "[ %s ] (%03d/%03d)", |
1745 | oname, partno, numparts); |
1722 | oname, partno, numparts); |
1746 | } |
1723 | } |
… | |
… | |
1766 | fprintf (outfile, "Content-Type: Message/Partial; number=%d; total=%d;%s", |
1743 | fprintf (outfile, "Content-Type: Message/Partial; number=%d; total=%d;%s", |
1767 | partno, numparts, eolstring); |
1744 | partno, numparts, eolstring); |
1768 | fprintf (outfile, "\tid=\"%s\"%s", |
1745 | fprintf (outfile, "\tid=\"%s\"%s", |
1769 | mimeid, eolstring); |
1746 | mimeid, eolstring); |
1770 | } |
1747 | } |
1771 | |
1748 | |
1772 | fprintf (outfile, "%s", eolstring); |
1749 | fprintf (outfile, "%s", eolstring); |
1773 | |
1750 | |
1774 | res = UUEncodePartial (outfile, theifile, |
1751 | res = UUEncodePartial (outfile, theifile, |
1775 | infname, encoding, |
1752 | infname, encoding, |
1776 | (outfname)?outfname:infname, NULL, |
1753 | (outfname)?outfname:infname, NULL, |
1777 | themode, partno, linperfile, crcptr); |
1754 | themode, partno, linperfile, crcptr); |
1778 | |
1755 | |
1779 | _FP_free (subline); |
1756 | FP_free (subline); |
1780 | |
1757 | |
1781 | if (infile==NULL) { |
1758 | if (infile==NULL) { |
1782 | if (res != UURET_OK) { |
1759 | if (res != UURET_OK) { |
1783 | fclose (theifile); |
1760 | fclose (theifile); |
1784 | return res; |
1761 | return res; |
1785 | } |
1762 | } |
1786 | if (feof (theifile)) { |
1763 | if (FP_feof (theifile)) { |
1787 | fclose (theifile); |
1764 | fclose (theifile); |
1788 | return UURET_OK; |
1765 | return UURET_OK; |
1789 | } |
1766 | } |
1790 | return UURET_CONT; |
1767 | return UURET_CONT; |
1791 | } |
1768 | } |