|
|
1.1 ! root 1: /* ! 2: * Copyright (c) 1983 Regents of the University of California. ! 3: * All rights reserved. ! 4: * ! 5: * Redistribution and use in source and binary forms are permitted provided ! 6: * that: (1) source distributions retain this entire copyright notice and ! 7: * comment, and (2) distributions including binaries display the following ! 8: * acknowledgement: ``This product includes software developed by the ! 9: * University of California, Berkeley and its contributors'' in the ! 10: * documentation or other materials provided with the distribution and in ! 11: * all advertising materials mentioning features or use of this software. ! 12: * Neither the name of the University nor the names of its contributors may ! 13: * be used to endorse or promote products derived from this software without ! 14: * specific prior written permission. ! 15: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED ! 16: * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF ! 17: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ! 18: */ ! 19: ! 20: #ifndef lint ! 21: static char sccsid[] = "@(#)uuencode.c 5.9 (Berkeley) 6/1/90"; ! 22: #endif /* not lint */ ! 23: ! 24: /* ! 25: * uuencode [input] output ! 26: * ! 27: * Encode a file so it can be mailed to a remote system. ! 28: */ ! 29: #include <sys/types.h> ! 30: #include <sys/stat.h> ! 31: #include <stdio.h> ! 32: ! 33: main(argc, argv) ! 34: int argc; ! 35: char **argv; ! 36: { ! 37: extern int optind; ! 38: extern int errno; ! 39: struct stat sb; ! 40: int mode; ! 41: char *strerror(); ! 42: ! 43: while (getopt(argc, argv, "") != EOF) ! 44: usage(); ! 45: argv += optind; ! 46: argc -= optind; ! 47: ! 48: switch(argc) { ! 49: case 2: /* optional first argument is input file */ ! 50: if (!freopen(*argv, "r", stdin) || fstat(fileno(stdin), &sb)) { ! 51: (void)fprintf(stderr, "uuencode: %s: %s.\n", ! 52: *argv, strerror(errno)); ! 53: exit(1); ! 54: } ! 55: #define RWX (S_IRWXU|S_IRWXG|S_IRWXO) ! 56: mode = sb.st_mode & RWX; ! 57: ++argv; ! 58: break; ! 59: case 1: ! 60: #define RW (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH) ! 61: mode = RW & ~umask(RW); ! 62: break; ! 63: case 0: ! 64: default: ! 65: usage(); ! 66: } ! 67: ! 68: (void)printf("begin %o %s\n", mode, *argv); ! 69: encode(); ! 70: (void)printf("end\n"); ! 71: if (ferror(stdout)) { ! 72: (void)fprintf(stderr, "uuencode: write error.\n"); ! 73: exit(1); ! 74: } ! 75: exit(0); ! 76: } ! 77: ! 78: /* ENC is the basic 1 character encoding function to make a char printing */ ! 79: #define ENC(c) ((c) ? ((c) & 077) + ' ': '`') ! 80: ! 81: /* ! 82: * copy from in to out, encoding as you go along. ! 83: */ ! 84: encode() ! 85: { ! 86: register int ch, n; ! 87: register char *p; ! 88: char buf[80]; ! 89: ! 90: while (n = fread(buf, 1, 45, stdin)) { ! 91: ch = ENC(n); ! 92: if (putchar(ch) == EOF) ! 93: break; ! 94: for (p = buf; n > 0; n -= 3, p += 3) { ! 95: ch = *p >> 2; ! 96: ch = ENC(ch); ! 97: if (putchar(ch) == EOF) ! 98: break; ! 99: ch = (*p << 4) & 060 | (p[1] >> 4) & 017; ! 100: ch = ENC(ch); ! 101: if (putchar(ch) == EOF) ! 102: break; ! 103: ch = (p[1] << 2) & 074 | (p[2] >> 6) & 03; ! 104: ch = ENC(ch); ! 105: if (putchar(ch) == EOF) ! 106: break; ! 107: ch = p[2] & 077; ! 108: ch = ENC(ch); ! 109: if (putchar(ch) == EOF) ! 110: break; ! 111: } ! 112: if (putchar('\n') == EOF) ! 113: break; ! 114: } ! 115: if (ferror(stdin)) { ! 116: (void)fprintf(stderr, "uuencode: read error.\n"); ! 117: exit(1); ! 118: } ! 119: ch = ENC('\0'); ! 120: (void)putchar(ch); ! 121: (void)putchar('\n'); ! 122: } ! 123: ! 124: usage() ! 125: { ! 126: (void)fprintf(stderr,"usage: uuencode [infile] remotefile\n"); ! 127: exit(1); ! 128: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.