… | |
… | |
54 | #else |
54 | #else |
55 | #define SEEK_SET 0 |
55 | #define SEEK_SET 0 |
56 | #endif |
56 | #endif |
57 | #endif |
57 | #endif |
58 | |
58 | |
59 | char * uuencode_id = "$Id: uuencode.c,v 1.2 2001/06/11 20:42:37 root Exp $"; |
59 | char * uuencode_id = "$Id: uuencode.c,v 1.2.2.1 2002/03/31 19:51:29 root Exp $"; |
60 | |
60 | |
61 | #if 0 |
61 | #if 0 |
62 | /* |
62 | /* |
63 | * the End-Of-Line string. MIME enforces CRLF, so that's what we use. Some |
63 | * the End-Of-Line string. MIME enforces CRLF, so that's what we use. Some |
64 | * implementations of uudecode will complain about a missing end line, since |
64 | * implementations of uudecode will complain about a missing end line, since |
… | |
… | |
240 | */ |
240 | */ |
241 | |
241 | |
242 | static int |
242 | static int |
243 | UUEncodeStream (FILE *outfile, FILE *infile, int encoding, long linperfile) |
243 | UUEncodeStream (FILE *outfile, FILE *infile, int encoding, long linperfile) |
244 | { |
244 | { |
245 | uchar *itemp = (uchar *) uuestr_itemp; |
245 | unsigned char *itemp = (char *) uuestr_itemp; |
246 | uchar *otemp = (uchar *) uuestr_otemp; |
246 | unsigned char *otemp = (char *) uuestr_otemp; |
247 | unsigned char *optr, *table, *tptr; |
247 | unsigned char *optr, *table, *tptr; |
248 | int index, count; |
248 | int index, count; |
249 | long line=0; |
249 | long line=0; |
250 | size_t llen; |
250 | size_t llen; |
251 | |
251 | |
… | |
… | |
262 | * read line oriented. |
262 | * read line oriented. |
263 | */ |
263 | */ |
264 | |
264 | |
265 | if (encoding == PT_ENCODED || encoding == QP_ENCODED) { |
265 | if (encoding == PT_ENCODED || encoding == QP_ENCODED) { |
266 | while (!feof (infile) && (linperfile <= 0 || line < linperfile)) { |
266 | while (!feof (infile) && (linperfile <= 0 || line < linperfile)) { |
267 | if (FP_fgets (itemp, 255, infile) == NULL) { |
267 | if (_FP_fgets (itemp, 255, infile) == NULL) { |
268 | break; |
268 | break; |
269 | } |
269 | } |
270 | |
270 | |
271 | itemp[255] = '\0'; |
271 | itemp[255] = '\0'; |
272 | count = strlen (itemp); |
272 | count = strlen (itemp); |
… | |
… | |
576 | } |
576 | } |
577 | |
577 | |
578 | if (progress.fsize <= 0) |
578 | if (progress.fsize <= 0) |
579 | progress.fsize = -1; |
579 | progress.fsize = -1; |
580 | |
580 | |
581 | FP_strncpy (progress.curfile, (outfname)?outfname:infname, 256); |
581 | _FP_strncpy (progress.curfile, (outfname)?outfname:infname, 256); |
582 | |
582 | |
583 | progress.partno = 1; |
583 | progress.partno = 1; |
584 | progress.numparts = 1; |
584 | progress.numparts = 1; |
585 | progress.percent = 0; |
585 | progress.percent = 0; |
586 | progress.foffset = 0; |
586 | progress.foffset = 0; |
… | |
… | |
591 | * looking at the file's extension. If it is unknown, default to |
591 | * looking at the file's extension. If it is unknown, default to |
592 | * Application/Octet-Stream |
592 | * Application/Octet-Stream |
593 | */ |
593 | */ |
594 | |
594 | |
595 | if (mimetype == NULL) { |
595 | if (mimetype == NULL) { |
596 | if ((ptr = FP_strrchr ((outfname)?outfname:infname, '.'))) { |
596 | if ((ptr = _FP_strrchr ((outfname)?outfname:infname, '.'))) { |
597 | while (miter->extension && FP_stricmp (ptr+1, miter->extension) != 0) |
597 | while (miter->extension && _FP_stricmp (ptr+1, miter->extension) != 0) |
598 | miter++; |
598 | miter++; |
599 | mimetype = miter->mimetype; |
599 | mimetype = miter->mimetype; |
600 | } |
600 | } |
601 | } |
601 | } |
602 | |
602 | |
… | |
… | |
726 | thesize = (long) finfo.st_size; |
726 | thesize = (long) finfo.st_size; |
727 | } |
727 | } |
728 | theifile = infile; |
728 | theifile = infile; |
729 | } |
729 | } |
730 | |
730 | |
731 | FP_strncpy (progress.curfile, (outfname)?outfname:infname, 256); |
731 | _FP_strncpy (progress.curfile, (outfname)?outfname:infname, 256); |
732 | |
732 | |
733 | progress.totsize = (thesize>0) ? thesize : -1; |
733 | progress.totsize = (thesize>0) ? thesize : -1; |
734 | progress.partno = 1; |
734 | progress.partno = 1; |
735 | progress.numparts = numparts; |
735 | progress.numparts = numparts; |
736 | progress.percent = 0; |
736 | progress.percent = 0; |
… | |
… | |
741 | * looking at the file's extension. If it is unknown, default to |
741 | * looking at the file's extension. If it is unknown, default to |
742 | * Application/Octet-Stream |
742 | * Application/Octet-Stream |
743 | */ |
743 | */ |
744 | |
744 | |
745 | if (mimetype == NULL) { |
745 | if (mimetype == NULL) { |
746 | if ((ptr = FP_strrchr ((outfname)?outfname:infname, '.'))) { |
746 | if ((ptr = _FP_strrchr ((outfname)?outfname:infname, '.'))) { |
747 | while (miter->extension && FP_stricmp (ptr+1, miter->extension) != 0) |
747 | while (miter->extension && _FP_stricmp (ptr+1, miter->extension) != 0) |
748 | miter++; |
748 | miter++; |
749 | mimetype = miter->mimetype; |
749 | mimetype = miter->mimetype; |
750 | } |
750 | } |
751 | } |
751 | } |
752 | |
752 | |
… | |
… | |
905 | } |
905 | } |
906 | |
906 | |
907 | if (progress.fsize <= 0) |
907 | if (progress.fsize <= 0) |
908 | progress.fsize = -1; |
908 | progress.fsize = -1; |
909 | |
909 | |
910 | FP_strncpy (progress.curfile, (outfname)?outfname:infname, 256); |
910 | _FP_strncpy (progress.curfile, (outfname)?outfname:infname, 256); |
911 | |
911 | |
912 | progress.partno = 1; |
912 | progress.partno = 1; |
913 | progress.numparts = 1; |
913 | progress.numparts = 1; |
914 | progress.percent = 0; |
914 | progress.percent = 0; |
915 | progress.foffset = 0; |
915 | progress.foffset = 0; |
… | |
… | |
1014 | /* |
1014 | /* |
1015 | * optr points after the last dot, so that we can print the part number |
1015 | * optr points after the last dot, so that we can print the part number |
1016 | * there. |
1016 | * there. |
1017 | */ |
1017 | */ |
1018 | |
1018 | |
1019 | optr = FP_strrchr (oname, '.'); |
1019 | optr = _FP_strrchr (oname, '.'); |
1020 | if (optr==NULL || strchr (optr, '/')!=NULL || strchr (optr, '\\')!=NULL) { |
1020 | if (optr==NULL || strchr (optr, '/')!=NULL || strchr (optr, '\\')!=NULL) { |
1021 | optr = oname + strlen (oname); |
1021 | optr = oname + strlen (oname); |
1022 | *optr++ = '.'; |
1022 | *optr++ = '.'; |
1023 | } |
1023 | } |
1024 | else if (optr==oname || *(optr-1)=='/' || *(optr-1)=='\\') { |
1024 | else if (optr==oname || *(optr-1)=='/' || *(optr-1)=='\\') { |
… | |
… | |
1033 | if (infile==NULL) { |
1033 | if (infile==NULL) { |
1034 | if (stat (infname, &finfo) == -1) { |
1034 | if (stat (infname, &finfo) == -1) { |
1035 | UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, |
1035 | UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, |
1036 | uustring (S_NOT_STAT_FILE), |
1036 | uustring (S_NOT_STAT_FILE), |
1037 | infname, strerror (uu_errno=errno)); |
1037 | infname, strerror (uu_errno=errno)); |
1038 | FP_free (oname); |
1038 | _FP_free (oname); |
1039 | return UURET_IOERR; |
1039 | return UURET_IOERR; |
1040 | } |
1040 | } |
1041 | if ((theifile = fopen (infname, "rb")) == NULL) { |
1041 | if ((theifile = fopen (infname, "rb")) == NULL) { |
1042 | UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, |
1042 | UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, |
1043 | uustring (S_NOT_OPEN_FILE), |
1043 | uustring (S_NOT_OPEN_FILE), |
1044 | infname, strerror (uu_errno=errno)); |
1044 | infname, strerror (uu_errno=errno)); |
1045 | FP_free (oname); |
1045 | _FP_free (oname); |
1046 | return UURET_IOERR; |
1046 | return UURET_IOERR; |
1047 | } |
1047 | } |
1048 | if (linperfile <= 0) |
1048 | if (linperfile <= 0) |
1049 | numparts = 1; |
1049 | numparts = 1; |
1050 | else |
1050 | else |
… | |
… | |
1072 | progress.totsize = -1; |
1072 | progress.totsize = -1; |
1073 | } |
1073 | } |
1074 | theifile = infile; |
1074 | theifile = infile; |
1075 | } |
1075 | } |
1076 | |
1076 | |
1077 | FP_strncpy (progress.curfile, (outfname)?outfname:infname, 256); |
1077 | _FP_strncpy (progress.curfile, (outfname)?outfname:infname, 256); |
1078 | |
1078 | |
1079 | progress.totsize = (progress.totsize<=0) ? -1 : progress.totsize; |
1079 | progress.totsize = (progress.totsize<=0) ? -1 : progress.totsize; |
1080 | progress.numparts = numparts; |
1080 | progress.numparts = numparts; |
1081 | |
1081 | |
1082 | for (part=1; !feof (theifile); part++) { |
1082 | for (part=1; !feof (theifile); part++) { |
… | |
… | |
1162 | } |
1162 | } |
1163 | if (infile==NULL) fclose (theifile); |
1163 | if (infile==NULL) fclose (theifile); |
1164 | progress.action = 0; |
1164 | progress.action = 0; |
1165 | fclose (outfile); |
1165 | fclose (outfile); |
1166 | unlink (oname); |
1166 | unlink (oname); |
1167 | FP_free (oname); |
1167 | _FP_free (oname); |
1168 | return res; |
1168 | return res; |
1169 | } |
1169 | } |
1170 | if (feof (theifile) && |
1170 | if (feof (theifile) && |
1171 | (encoding == UU_ENCODED || encoding == XX_ENCODED)) { |
1171 | (encoding == UU_ENCODED || encoding == XX_ENCODED)) { |
1172 | fprintf (outfile, "%c%s", |
1172 | fprintf (outfile, "%c%s", |
… | |
… | |
1180 | fprintf (outfile, "%s", eolstring); |
1180 | fprintf (outfile, "%s", eolstring); |
1181 | fclose (outfile); |
1181 | fclose (outfile); |
1182 | } |
1182 | } |
1183 | if (infile==NULL) fclose (theifile); |
1183 | if (infile==NULL) fclose (theifile); |
1184 | progress.action = 0; |
1184 | progress.action = 0; |
1185 | FP_free (oname); |
1185 | _FP_free (oname); |
1186 | return UURET_OK; |
1186 | return UURET_OK; |
1187 | } |
1187 | } |
1188 | |
1188 | |
1189 | /* |
1189 | /* |
1190 | * Encode a MIME Mail message or Newsgroup posting and send to a |
1190 | * Encode a MIME Mail message or Newsgroup posting and send to a |
… | |
… | |
1229 | } |
1229 | } |
1230 | |
1230 | |
1231 | oname = UUFNameFilter ((outfname)?outfname:infname); |
1231 | oname = UUFNameFilter ((outfname)?outfname:infname); |
1232 | len = ((subject)?strlen(subject):0) + strlen(oname) + 40; |
1232 | len = ((subject)?strlen(subject):0) + strlen(oname) + 40; |
1233 | |
1233 | |
1234 | if ((ptr = FP_strrchr (oname, '.'))) { |
1234 | if ((ptr = _FP_strrchr (oname, '.'))) { |
1235 | while (miter->extension && FP_stricmp (ptr+1, miter->extension) != 0) |
1235 | while (miter->extension && _FP_stricmp (ptr+1, miter->extension) != 0) |
1236 | miter++; |
1236 | miter++; |
1237 | mimetype = miter->mimetype; |
1237 | mimetype = miter->mimetype; |
1238 | } |
1238 | } |
1239 | else |
1239 | else |
1240 | mimetype = NULL; |
1240 | mimetype = NULL; |
… | |
… | |
1279 | fprintf (outfile, "%s", eolstring); |
1279 | fprintf (outfile, "%s", eolstring); |
1280 | |
1280 | |
1281 | res = UUEncodeToStream (outfile, infile, infname, encoding, |
1281 | res = UUEncodeToStream (outfile, infile, infname, encoding, |
1282 | outfname, filemode); |
1282 | outfname, filemode); |
1283 | |
1283 | |
1284 | FP_free (subline); |
1284 | _FP_free (subline); |
1285 | return res; |
1285 | return res; |
1286 | } |
1286 | } |
1287 | |
1287 | |
1288 | int UUEXPORT |
1288 | int UUEXPORT |
1289 | UUE_PrepPartial (FILE *outfile, FILE *infile, |
1289 | UUE_PrepPartial (FILE *outfile, FILE *infile, |
… | |
… | |
1447 | res = UUEncodePartial (outfile, theifile, |
1447 | res = UUEncodePartial (outfile, theifile, |
1448 | infname, encoding, |
1448 | infname, encoding, |
1449 | (outfname)?outfname:infname, NULL, |
1449 | (outfname)?outfname:infname, NULL, |
1450 | themode, partno, linperfile); |
1450 | themode, partno, linperfile); |
1451 | |
1451 | |
1452 | FP_free (subline); |
1452 | _FP_free (subline); |
1453 | |
1453 | |
1454 | if (infile==NULL) { |
1454 | if (infile==NULL) { |
1455 | if (res != UURET_OK) { |
1455 | if (res != UURET_OK) { |
1456 | fclose (theifile); |
1456 | fclose (theifile); |
1457 | return res; |
1457 | return res; |