ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Convert-UUlib/uulib/uuencode.c
(Generate patch)

Comparing Convert-UUlib/uulib/uuencode.c (file contents):
Revision 1.9 by root, Thu Dec 10 22:49:15 2020 UTC vs.
Revision 1.10 by root, Fri Dec 11 20:09:23 2020 UTC

55#else 55#else
56#define SEEK_SET 0 56#define SEEK_SET 0
57#endif 57#endif
58#endif 58#endif
59 59
60char * uuencode_id = "$Id: uuencode.c,v 1.9 2020/12/10 22:49:15 root Exp $"; 60char * uuencode_id = "$Id: uuencode.c,v 1.10 2020/12/11 20:09:23 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
264 * Special handling for plain text and quoted printable. Text is 264 * Special handling for plain text and quoted printable. Text is
265 * read line oriented. 265 * read line oriented.
266 */ 266 */
267 267
268 if (encoding == PT_ENCODED || encoding == QP_ENCODED) { 268 if (encoding == PT_ENCODED || encoding == QP_ENCODED) {
269 while (!feof (infile) && (linperfile <= 0 || line < linperfile)) { 269 while (!FP_feof (infile) && (linperfile <= 0 || line < linperfile)) {
270 if (_FP_fgets (itemp, 255, infile) == NULL) { 270 if (FP_fgets (itemp, 255, infile) == NULL) {
271 break; 271 break;
272 } 272 }
273 273
274 itemp[255] = '\0'; 274 itemp[255] = '\0';
275 count = strlen (itemp); 275 count = strlen (itemp);
411 411
412 if (encoding == YENC_ENCODED) { 412 if (encoding == YENC_ENCODED) {
413 llen = 0; 413 llen = 0;
414 optr = otemp; 414 optr = otemp;
415 415
416 while (!feof (infile) && (linperfile <= 0 || line < linperfile)) { 416 while (!FP_feof (infile) && (linperfile <= 0 || line < linperfile)) {
417 if ((count = fread (itemp, 1, 128, infile)) != 128) { 417 if ((count = fread (itemp, 1, 128, infile)) != 128) {
418 if (count == 0) { 418 if (count == 0) {
419 break; 419 break;
420 } 420 }
421 else if (ferror (infile)) { 421 else if (ferror (infile)) {
512 UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, 512 UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
513 uustring (S_PARM_CHECK), "UUEncodeStream()"); 513 uustring (S_PARM_CHECK), "UUEncodeStream()");
514 return UURET_ILLVAL; 514 return UURET_ILLVAL;
515 } 515 }
516 516
517 while (!feof (infile) && (linperfile <= 0 || line < linperfile)) { 517 while (!FP_feof (infile) && (linperfile <= 0 || line < linperfile)) {
518 if ((count = fread (itemp, 1, bpl[encoding], infile)) != bpl[encoding]) { 518 if ((count = fread (itemp, 1, bpl[encoding], infile)) != bpl[encoding]) {
519 if (count == 0) 519 if (count == 0)
520 break; 520 break;
521 else if (ferror (infile)) 521 else if (ferror (infile))
522 return UURET_IOERR; 522 return UURET_IOERR;
671 } 671 }
672 672
673 if (progress.fsize < 0) 673 if (progress.fsize < 0)
674 progress.fsize = -1; 674 progress.fsize = -1;
675 675
676 _FP_strncpy (progress.curfile, (outfname)?outfname:infname, 256); 676 FP_strncpy (progress.curfile, (outfname)?outfname:infname, 256);
677 677
678 progress.partno = 1; 678 progress.partno = 1;
679 progress.numparts = 1; 679 progress.numparts = 1;
680 progress.percent = 0; 680 progress.percent = 0;
681 progress.foffset = 0; 681 progress.foffset = 0;
686 * looking at the file's extension. If it is unknown, default to 686 * looking at the file's extension. If it is unknown, default to
687 * Application/Octet-Stream 687 * Application/Octet-Stream
688 */ 688 */
689 689
690 if (mimetype == NULL) { 690 if (mimetype == NULL) {
691 if ((ptr = _FP_strrchr ((outfname)?outfname:infname, '.'))) { 691 if ((ptr = FP_strrchr ((outfname)?outfname:infname, '.'))) {
692 while (miter->extension && _FP_stricmp (ptr+1, miter->extension) != 0) 692 while (miter->extension && FP_stricmp (ptr+1, miter->extension) != 0)
693 miter++; 693 miter++;
694 mimetype = miter->mimetype; 694 mimetype = miter->mimetype;
695 } 695 }
696 } 696 }
697 697
858 thesize = (long) finfo.st_size; 858 thesize = (long) finfo.st_size;
859 } 859 }
860 theifile = infile; 860 theifile = infile;
861 } 861 }
862 862
863 _FP_strncpy (progress.curfile, (outfname)?outfname:infname, 256); 863 FP_strncpy (progress.curfile, (outfname)?outfname:infname, 256);
864 864
865 progress.totsize = (thesize>=0) ? thesize : -1; 865 progress.totsize = (thesize>=0) ? thesize : -1;
866 progress.partno = 1; 866 progress.partno = 1;
867 progress.numparts = numparts; 867 progress.numparts = numparts;
868 progress.percent = 0; 868 progress.percent = 0;
873 * looking at the file's extension. If it is unknown, default to 873 * looking at the file's extension. If it is unknown, default to
874 * Application/Octet-Stream 874 * Application/Octet-Stream
875 */ 875 */
876 876
877 if (mimetype == NULL) { 877 if (mimetype == NULL) {
878 if ((ptr = _FP_strrchr ((outfname)?outfname:infname, '.'))) { 878 if ((ptr = FP_strrchr ((outfname)?outfname:infname, '.'))) {
879 while (miter->extension && _FP_stricmp (ptr+1, miter->extension) != 0) 879 while (miter->extension && FP_stricmp (ptr+1, miter->extension) != 0)
880 miter++; 880 miter++;
881 mimetype = miter->mimetype; 881 mimetype = miter->mimetype;
882 } 882 }
883 } 883 }
884 884
987 987
988 /* 988 /*
989 * print end line 989 * print end line
990 */ 990 */
991 991
992 if (feof (theifile) && 992 if (FP_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);
1007 } 1007 }
1008 else { 1008 else {
1009 fprintf (outfile, "=yend size=%ld", 1009 fprintf (outfile, "=yend size=%ld",
1010 progress.totsize); 1010 progress.totsize);
1011 } 1011 }
1012 if (feof (theifile)) 1012 if (FP_feof (theifile))
1013 fprintf (outfile, " crc32=%08lx", (long)*crcptr); 1013 fprintf (outfile, " crc32=%08lx", (long)*crcptr);
1014 fprintf (outfile, "%s", eolstring); 1014 fprintf (outfile, "%s", eolstring);
1015 } 1015 }
1016 1016
1017 /* 1017 /*
1026 if (res != UURET_OK) { 1026 if (res != UURET_OK) {
1027 progress.action = 0; 1027 progress.action = 0;
1028 fclose (theifile); 1028 fclose (theifile);
1029 return res; 1029 return res;
1030 } 1030 }
1031 if (feof (theifile)) { 1031 if (FP_feof (theifile)) {
1032 progress.action = 0; 1032 progress.action = 0;
1033 fclose (theifile); 1033 fclose (theifile);
1034 return UURET_OK; 1034 return UURET_OK;
1035 } 1035 }
1036 return UURET_CONT; 1036 return UURET_CONT;
1101 } 1101 }
1102 1102
1103 if (progress.fsize < 0) 1103 if (progress.fsize < 0)
1104 progress.fsize = -1; 1104 progress.fsize = -1;
1105 1105
1106 _FP_strncpy (progress.curfile, (outfname)?outfname:infname, 256); 1106 FP_strncpy (progress.curfile, (outfname)?outfname:infname, 256);
1107 1107
1108 progress.partno = 1; 1108 progress.partno = 1;
1109 progress.numparts = 1; 1109 progress.numparts = 1;
1110 progress.percent = 0; 1110 progress.percent = 0;
1111 progress.foffset = 0; 1111 progress.foffset = 0;
1244 /* 1244 /*
1245 * optr points after the last dot, so that we can print the part number 1245 * optr points after the last dot, so that we can print the part number
1246 * there. 1246 * there.
1247 */ 1247 */
1248 1248
1249 optr = _FP_strrchr (oname, '.'); 1249 optr = FP_strrchr (oname, '.');
1250 if (optr==NULL || strchr (optr, '/')!=NULL || strchr (optr, '\\')!=NULL) { 1250 if (optr==NULL || strchr (optr, '/')!=NULL || strchr (optr, '\\')!=NULL) {
1251 optr = oname + strlen (oname); 1251 optr = oname + strlen (oname);
1252 *optr++ = '.'; 1252 *optr++ = '.';
1253 } 1253 }
1254 else if (optr==oname || *(optr-1)=='/' || *(optr-1)=='\\') { 1254 else if (optr==oname || *(optr-1)=='/' || *(optr-1)=='\\') {
1263 if (infile==NULL) { 1263 if (infile==NULL) {
1264 if (stat (infname, &finfo) == -1) { 1264 if (stat (infname, &finfo) == -1) {
1265 UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, 1265 UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
1266 uustring (S_NOT_STAT_FILE), 1266 uustring (S_NOT_STAT_FILE),
1267 infname, strerror (uu_errno=errno)); 1267 infname, strerror (uu_errno=errno));
1268 _FP_free (oname); 1268 FP_free (oname);
1269 return UURET_IOERR; 1269 return UURET_IOERR;
1270 } 1270 }
1271 if ((theifile = fopen (infname, "rb")) == NULL) { 1271 if ((theifile = fopen (infname, "rb")) == NULL) {
1272 UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, 1272 UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
1273 uustring (S_NOT_OPEN_FILE), 1273 uustring (S_NOT_OPEN_FILE),
1274 infname, strerror (uu_errno=errno)); 1274 infname, strerror (uu_errno=errno));
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
1302 progress.totsize = -1; 1302 progress.totsize = -1;
1303 } 1303 }
1304 theifile = infile; 1304 theifile = infile;
1305 } 1305 }
1306 1306
1307 _FP_strncpy (progress.curfile, (outfname)?outfname:infname, 256); 1307 FP_strncpy (progress.curfile, (outfname)?outfname:infname, 256);
1308 1308
1309 progress.totsize = (progress.totsize<0) ? -1 : progress.totsize; 1309 progress.totsize = (progress.totsize<0) ? -1 : progress.totsize;
1310 progress.numparts = numparts; 1310 progress.numparts = numparts;
1311 1311
1312 for (part=1; !feof (theifile); part++) { 1312 for (part=1; !FP_feof (theifile); part++) {
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);
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);
1442 unlink (oname); 1442 unlink (oname);
1443 _FP_free (oname); 1443 FP_free (oname);
1444 return res; 1444 return res;
1445 } 1445 }
1446 1446
1447 if (feof (theifile) && 1447 if (FP_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);
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 (FP_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 /*
1476 fclose (outfile); 1476 fclose (outfile);
1477 } 1477 }
1478 1478
1479 if (infile==NULL) fclose (theifile); 1479 if (infile==NULL) fclose (theifile);
1480 progress.action = 0; 1480 progress.action = 0;
1481 _FP_free (oname); 1481 FP_free (oname);
1482 return UURET_OK; 1482 return UURET_OK;
1483} 1483}
1484 1484
1485/* 1485/*
1486 * Encode a MIME Mail message or Newsgroup posting and send to a 1486 * Encode a MIME Mail message or Newsgroup posting and send to a
1525 } 1525 }
1526 1526
1527 oname = UUFNameFilter ((outfname)?outfname:infname); 1527 oname = UUFNameFilter ((outfname)?outfname:infname);
1528 len = ((subject)?strlen(subject):0) + strlen(oname) + 40; 1528 len = ((subject)?strlen(subject):0) + strlen(oname) + 40;
1529 1529
1530 if ((ptr = _FP_strrchr (oname, '.'))) { 1530 if ((ptr = FP_strrchr (oname, '.'))) {
1531 while (miter->extension && _FP_stricmp (ptr+1, miter->extension) != 0) 1531 while (miter->extension && FP_stricmp (ptr+1, miter->extension) != 0)
1532 miter++; 1532 miter++;
1533 mimetype = miter->mimetype; 1533 mimetype = miter->mimetype;
1534 } 1534 }
1535 else 1535 else
1536 mimetype = NULL; 1536 mimetype = NULL;
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
1595int UUEXPORT 1595int UUEXPORT
1596UUE_PrepPartial (FILE *outfile, FILE *infile, 1596UUE_PrepPartial (FILE *outfile, FILE *infile,
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,
1779 themode, partno, linperfile, crcptr); 1779 themode, partno, linperfile, crcptr);
1780 1780
1781 _FP_free (subline); 1781 FP_free (subline);
1782 1782
1783 if (infile==NULL) { 1783 if (infile==NULL) {
1784 if (res != UURET_OK) { 1784 if (res != UURET_OK) {
1785 fclose (theifile); 1785 fclose (theifile);
1786 return res; 1786 return res;
1787 } 1787 }
1788 if (feof (theifile)) { 1788 if (FP_feof (theifile)) {
1789 fclose (theifile); 1789 fclose (theifile);
1790 return UURET_OK; 1790 return UURET_OK;
1791 } 1791 }
1792 return UURET_CONT; 1792 return UURET_CONT;
1793 } 1793 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines