1/*- 2 * Copyright (c) 1983, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 30 unchanged lines hidden (view full) --- 39 40#if 0 41#ifndef lint 42static char sccsid[] = "@(#)uudecode.c 8.2 (Berkeley) 4/2/94"; 43#endif /* not lint */ 44#endif 45 46#include <sys/cdefs.h> |
47__FBSDID("$FreeBSD: head/usr.bin/uudecode/uudecode.c 103203 2002-09-10 21:10:33Z fanf $"); |
48 49/* 50 * uudecode [file ...] 51 * 52 * create the specified file, decoding as you go. 53 * used with uuencode. 54 */ 55#include <sys/param.h> --- 12 unchanged lines hidden (view full) --- 68 69const char *filename; 70char *outfile; 71int cflag, iflag, oflag, pflag, sflag; 72 73static void usage(void); 74int decode(void); 75int decode2(void); |
76int base64_decode(const char *); |
77 78int 79main(int argc, char *argv[]) 80{ 81 int rval, ch; 82 83 while ((ch = getopt(argc, argv, "cio:ps")) != -1) { 84 switch(ch) { --- 151 unchanged lines hidden (view full) --- 236 stat(buffn, &st) < 0 || (S_ISREG(st.st_mode) && 237 fchmod(fileno(stdout), getmode(mode, 0) & 0666) < 0)) { 238 warn("%s: %s", filename, buffn); 239 return (1); 240 } 241 } 242 free(mode); 243 |
244 if (base64) 245 return (base64_decode(buffn)); 246 |
247 /* for each input line */ 248 for (;;) { 249 if (fgets(p = buf, sizeof(buf), stdin) == NULL) { 250 warnx("%s: short file", filename); 251 return (1); 252 } |
253 |
254#define DEC(c) (((c) - ' ') & 077) /* single character decode */ 255#define IS_DEC(c) ( (((c) - ' ') >= 0) && (((c) - ' ') <= 077 + 1) ) 256/* #define IS_DEC(c) (1) */ 257 258#define OUT_OF_RANGE \ 259{ \ 260 warnx( \ 261"\n\tinput file: %s\n\tencoded file: %s\n\tcharacter out of range: [%d-%d]", \ --- 48 unchanged lines hidden (view full) --- 310 (strcmp(buf, "end") && strcmp(buf, "end\n") && 311 strcmp(buf, "end\r\n"))) { 312 warnx("%s: no \"end\" line", filename); 313 return (1); 314 } 315 return (0); 316} 317 |
318int 319base64_decode(const char *outname) |
320{ |
321 int n; 322 char buf[MAXPATHLEN+1]; |
323 unsigned char out[MAXPATHLEN * 4]; |
324 |
325 for (;;) { 326 if (fgets(buf, sizeof(buf), stdin) == NULL) { 327 warnx("%s: short file", filename); 328 return (1); 329 } 330 if (strcmp(buf, "====") == 0 || 331 strcmp(buf, "====\n") == 0 || 332 strcmp(buf, "====\r\n") == 0) 333 return (0); 334 n = strlen(buf); 335 while (n > 0 && (buf[n-1] == '\n' || buf[n-1] == '\r')) 336 buf[--n] = '\0'; 337 n = b64_pton(buf, out, sizeof(out)); 338 if (n < 0) { 339 warnx("%s: %s: error decoding base64 input stream", filename, outname); 340 return (1); 341 } 342 fwrite(out, 1, n, stdout); 343 } |
344} 345 346static void 347usage(void) 348{ 349 (void)fprintf(stderr, 350"usage: uudecode [-cips] [file ...]\n" 351" uudecode [-i] -o output_file [file]\n" 352" b64decode [-cips] [file ...]\n" 353" b64decode [-i] -o output_file [file]\n"); 354 exit(1); 355} |