… | |
… | |
52 | #include <uudeview.h> |
52 | #include <uudeview.h> |
53 | #include <uuint.h> |
53 | #include <uuint.h> |
54 | #include <fptools.h> |
54 | #include <fptools.h> |
55 | #include <uustring.h> |
55 | #include <uustring.h> |
56 | |
56 | |
57 | char * uunconc_id = "$Id: uunconc.c,v 1.8 2002/04/06 01:53:30 root Exp $"; |
57 | char * uunconc_id = "$Id: uunconc.c,v 1.9 2002/04/06 02:28:35 root Exp $"; |
58 | |
58 | |
59 | /* for braindead systems */ |
59 | /* for braindead systems */ |
60 | #ifndef SEEK_SET |
60 | #ifndef SEEK_SET |
61 | #ifdef L_BEGIN |
61 | #ifdef L_BEGIN |
62 | #define SEEK_SET L_BEGIN |
62 | #define SEEK_SET L_BEGIN |
… | |
… | |
137 | B64xlat = (int *) uunconc_B64xlat; |
137 | B64xlat = (int *) uunconc_B64xlat; |
138 | XXxlat = (int *) uunconc_XXxlat; |
138 | XXxlat = (int *) uunconc_XXxlat; |
139 | BHxlat = (int *) uunconc_BHxlat; |
139 | BHxlat = (int *) uunconc_BHxlat; |
140 | |
140 | |
141 | save[0] = uunconc_save; |
141 | save[0] = uunconc_save; |
142 | save[1] = uunconc_save + 256; |
142 | save[1] = uunconc_save + 1200; |
143 | save[2] = uunconc_save + 512; |
143 | save[2] = uunconc_save + 2400; |
144 | |
144 | |
145 | /* prepare decoding translation table */ |
145 | /* prepare decoding translation table */ |
146 | for(i = 0; i < 256; i++) |
146 | for(i = 0; i < 256; i++) |
147 | UUxlat[i] = B64xlat[i] = XXxlat[i] = BHxlat[i] = -1; |
147 | UUxlat[i] = B64xlat[i] = XXxlat[i] = BHxlat[i] = -1; |
148 | |
148 | |
… | |
… | |
606 | |
606 | |
607 | if (s == NULL || d == NULL) { |
607 | if (s == NULL || d == NULL) { |
608 | leftover = 0; |
608 | leftover = 0; |
609 | return 0; |
609 | return 0; |
610 | } |
610 | } |
611 | |
|
|
612 | /* optionally skip .. */ |
|
|
613 | if (*s == '.' && uu_dotdot) |
|
|
614 | s++; |
|
|
615 | |
611 | |
616 | /* |
612 | /* |
617 | * To shut up gcc -Wall |
613 | * To shut up gcc -Wall |
618 | */ |
614 | */ |
619 | z1 = z2 = z3 = z4 = 0; |
615 | z1 = z2 = z3 = z4 = 0; |
… | |
… | |
651 | j -= 4; |
647 | j -= 4; |
652 | } |
648 | } |
653 | } |
649 | } |
654 | else if (method == B64ENCODED) { |
650 | else if (method == B64ENCODED) { |
655 | if (leftover) { |
651 | if (leftover) { |
656 | int len = strlen (s); |
|
|
657 | |
|
|
658 | if (len > 1200 - 1 - leftover) |
|
|
659 | len = 1200 - 1 - leftover; |
|
|
660 | |
|
|
661 | memcpy (uuncdl_fulline + leftover, s, len); |
652 | strcpy (uuncdl_fulline + leftover, s); |
662 | uuncdl_fulline[leftover + len] = 0; |
|
|
663 | |
653 | |
664 | leftover = 0; |
654 | leftover = 0; |
665 | s = uuncdl_fulline; |
655 | s = uuncdl_fulline; |
666 | } |
656 | } |
667 | |
657 | |
… | |
… | |
688 | while (B64xlat[ACAST(*s)] != -1) |
678 | while (B64xlat[ACAST(*s)] != -1) |
689 | uuncdl_fulline[leftover++] = *s++; |
679 | uuncdl_fulline[leftover++] = *s++; |
690 | } |
680 | } |
691 | else if (method == BH_ENCODED) { |
681 | else if (method == BH_ENCODED) { |
692 | if (leftover) { |
682 | if (leftover) { |
693 | int len = strlen (s); |
|
|
694 | |
|
|
695 | if (len > 1200 - 1 - leftover) |
|
|
696 | len = 1200 - 1 - leftover; |
|
|
697 | |
|
|
698 | memcpy (uuncdl_fulline + leftover, s, len); |
683 | strcpy (uuncdl_fulline + leftover, s); |
699 | uuncdl_fulline[leftover + len] = 0; |
|
|
700 | |
684 | |
701 | leftover = 0; |
685 | leftover = 0; |
702 | s = uuncdl_fulline; |
686 | s = uuncdl_fulline; |
703 | } |
687 | } |
704 | else if (*s == ':') |
688 | else if (*s == ':') |
… | |
… | |
915 | int |
899 | int |
916 | UUDecodePart (FILE *datain, FILE *dataout, int *state, |
900 | UUDecodePart (FILE *datain, FILE *dataout, int *state, |
917 | long maxpos, int method, int flags, |
901 | long maxpos, int method, int flags, |
918 | char *boundary) |
902 | char *boundary) |
919 | { |
903 | { |
920 | char *line=uugen_fnbuffer, *oline=uuncdp_oline; |
904 | char *line, *oline=uuncdp_oline; |
921 | int warning=0, vlc=0, lc[2], hadct=0; |
905 | int warning=0, vlc=0, lc[2], hadct=0; |
922 | int tc=0, tf=0, vflag, haddata=0, haddh=0; |
906 | int tc=0, tf=0, vflag, haddata=0, haddh=0; |
923 | long yefilesize=0, yepartends=0; |
907 | long yefilesize=0, yepartends=0; |
924 | static int bhflag=0; |
908 | static int bhflag=0; |
925 | size_t count=0; |
909 | size_t count=0; |
… | |
… | |
951 | } |
935 | } |
952 | |
936 | |
953 | while (!feof (datain) && *state != DONE && |
937 | while (!feof (datain) && *state != DONE && |
954 | (ftell(datain)<maxpos || flags&FL_TOEND || maxpos==-1 || |
938 | (ftell(datain)<maxpos || flags&FL_TOEND || maxpos==-1 || |
955 | (!(flags&FL_PROPER) && uu_fast_scanning))) { |
939 | (!(flags&FL_PROPER) && uu_fast_scanning))) { |
956 | if (_FP_fgets (line, 299, datain) == NULL) |
940 | if (_FP_fgets ((line = uugen_fnbuffer), 1200 - 5, datain) == NULL) |
957 | break; |
941 | break; |
|
|
942 | |
|
|
943 | /* optionally skip .. */ |
|
|
944 | if (*line == '.' && uu_dotdot) |
|
|
945 | line++; |
958 | |
946 | |
959 | if (ferror (datain)) { |
947 | if (ferror (datain)) { |
960 | UUMessage (uunconc_id, __LINE__, UUMSG_ERROR, |
948 | UUMessage (uunconc_id, __LINE__, UUMSG_ERROR, |
961 | uustring (S_SOURCE_READ_ERR), |
949 | uustring (S_SOURCE_READ_ERR), |
962 | strerror (uu_errno = errno)); |
950 | strerror (uu_errno = errno)); |
… | |
… | |
993 | |
981 | |
994 | /* |
982 | /* |
995 | * try to make sense of data |
983 | * try to make sense of data |
996 | */ |
984 | */ |
997 | |
985 | |
998 | line[299] = '\0'; /* For Safety of string functions */ |
986 | line[1200 - 1] = '\0'; /* For Safety of string functions */ |
999 | count = 0; |
987 | count = 0; |
1000 | |
988 | |
1001 | if (boundary && line[0]=='-' && line[1]=='-' && |
989 | if (boundary && line[0]=='-' && line[1]=='-' && |
1002 | strncmp (line+2, boundary, strlen (boundary)) == 0) { |
990 | strncmp (line+2, boundary, strlen (boundary)) == 0) { |
1003 | if (line[strlen(boundary)+2]=='-') |
991 | if (line[strlen(boundary)+2]=='-') |
1004 | uulboundary = 1; |
992 | uulboundary = 1; |
… | |
… | |
1056 | |
1044 | |
1057 | ptr = _FP_strstr (line, " size=") + 6; |
1045 | ptr = _FP_strstr (line, " size=") + 6; |
1058 | yefilesize = atoi (ptr); |
1046 | yefilesize = atoi (ptr); |
1059 | |
1047 | |
1060 | if (_FP_strstr (line, " part=") != NULL) { |
1048 | if (_FP_strstr (line, " part=") != NULL) { |
1061 | if (_FP_fgets (line, 299, datain) == NULL) { |
1049 | if (_FP_fgets (line, 1200 - 5, datain) == NULL) { |
1062 | break; |
1050 | break; |
1063 | } |
1051 | } |
1064 | |
1052 | |
1065 | if ((ptr = _FP_strstr (line, " end=")) == NULL) { |
1053 | if ((ptr = _FP_strstr (line, " end=")) == NULL) { |
1066 | break; |
1054 | break; |
… | |
… | |
1138 | } |
1126 | } |
1139 | lc[0] = 0; |
1127 | lc[0] = 0; |
1140 | lc[1] = 3; |
1128 | lc[1] = 3; |
1141 | } |
1129 | } |
1142 | else { |
1130 | else { |
1143 | _FP_strncpy (save[tc++], line, 256); |
1131 | _FP_strncpy (save[tc++], line, 1200); |
1144 | } |
1132 | } |
1145 | |
1133 | |
1146 | if (method == UU_ENCODED) |
1134 | if (method == UU_ENCODED) |
1147 | *state = (line[0] == 'M') ? DATA : END; |
1135 | *state = (line[0] == 'M') ? DATA : END; |
1148 | else if (method == XX_ENCODED) |
1136 | else if (method == XX_ENCODED) |