1 /* uue - bulletproof version of uuencode */
3 /* Uue -- encode a file so that it's printable ascii, short lines
5 * Slightly modified from a version posted to net.sources a while back,
6 * and suitable for compilation on the IBM PC
8 * modified for Lattice C on the ST - 11.05.85 by MSD
9 * modified for ALCYON on the ST - 10-24-86 by RDR
10 * modified a little more for MWC... 02/09/87 by JPHD
11 * (An optional first argument of the form: -nnumber (e.g. -500), will
12 * produce a serie of files that long, linked by the include statement,
13 * such files are automatically uudecoded by the companion program.)
14 * More mods, - ... 05/06/87 by jphd
15 * Mods for TOPS 20, and more. 08/06/87 by jphd
16 * (remove freopen and rindex...change filename generation...)
17 * (A lot more to do about I/O speed, avoiding completely the stdio.h...)
18 * May be called as uuencode. Oct 2 1993 by Kees J. Bot
29 #define FILE_NAME 10 /* affects how long names are truncated */
31 /* ENC is the basic 1 character encoding function to make a char printing */
32 #define ENC(c) (((c) & 077) + ' ')
45 int part
= 'a', chap
= 'a';
53 int main(int argc
, char **argv
);
58 int fr(char *buf
, int cnt
);
68 prog_name
= argv
[0] + strlen(argv
[0]);
69 while (prog_name
> argv
[0] && prog_name
[-1] != '/') prog_name
--;
70 filter
= strcmp(prog_name
, "uuencode") == 0;
73 fprintf(stderr
, "Usage: %s [-n] inputfile [-]\n", prog_name
);
76 if (argv
[1][0] == '-') {
77 fileln
= -atoi(argv
[1]);
79 fprintf(stderr
, "Wrong file length arg.\n");
86 if (filter
) { /* old uuencode reads from standard input */
89 if ((fp
= fopen(argv
[1], READ
)) == NULL
) { /* binary input !!! */
90 fprintf(stderr
, "Cannot open %s\n", argv
[1]);
94 fname
= argv
[1] + strlen(argv
[1]);
95 while (fname
> argv
[1] && fname
[-1] != '/') fname
--;
96 strcpy(ofname
, fname
);
99 if (*fname
== '.') *fname
= '\0';
101 /* 10 char prefix + .uue -> 14 chars MAX */
102 lenofname
= strlen(ofname
);
103 if (lenofname
> FILE_NAME
) ofname
[FILE_NAME
] = '\0';
104 strcat(ofname
, ".uue");
105 lenofname
= strlen(ofname
);
106 if (!split
&& (filter
|| (argc
> 2) && (argv
[2][0] == '-'))) {
111 if ((outp
= fopen(ofname
, "w")) == NULL
) {
112 fprintf(stderr
, "Cannot open %s\n", ofname
);
117 fprintf(outp
, "begin %o %s\n", 0644, argv
[1]);
119 fprintf(outp
, "end\n");
124 /* Create ASCII table so a mailer can screw it up and the decode
125 * program can restore the error.
131 fputs("table\n", outp
);
132 for (i
= ' ', j
= 0; i
< '`'; j
++) {
133 if (j
== 32) putc('\n', outp
);
139 /* Generate the names needed for single and multiple part encoding. */
143 ofname
[lenofname
- 1] = part
;
144 ofname
[lenofname
- 2] = chap
;
148 /* Copy from in to out, encoding as you go along. */
159 for (i
= 0; i
< n
; i
+= 3) outdec(&buf
[i
]);
162 if (seqc
< SEQMIN
) seqc
= SEQMAX
;
165 if (split
&& (lines
> fileln
)) {
170 chap
= 'a'; /* loop ... */
175 fprintf(outp
, "include %s\n", ofname
);
177 if ((outp
= fopen(ofname
, "w")) == NULL
) {
178 fprintf(stderr
, "Cannot open %s\n", ofname
);
182 fprintf(outp
, "begin part %c %s\n", part
, ofname
);
189 /* Output one group of 3 bytes, pointed at by p, on file f. */
193 register int c1
, c2
, c3
, c4
;
196 c2
= ((*p
<< 4) & 060) | ((p
[1] >> 4) & 017);
197 c3
= ((p
[1] << 2) & 074) | ((p
[2] >> 6) & 03);
205 /* Fr: like read but stdio */
211 for (i
= 0; i
< cnt
; i
++) {
213 if (feof(fp
)) return(i
);