#define PROG_NAME "jsuuencode" #define PROG_DESC "Jorge Stolfi's version of \"uuencode\"" #define PROG_VERS "1.1" /* Copyright © 1983 Regents of the University of California. */ /* See the copyright, authorship, and warranty notice at end of file. */ /* Last edited on 2009-01-08 03:58:04 by stolfi" */ #define PROG_HELP \ PROG_NAME " < INFILE > OUTFILE" #define PROG_INFO \ "NAME\n" \ " " PROG_NAME " - " PROG_DESC "\n" \ "\n" \ "SYNOPSIS\n" \ PROG_HELP "\n" \ "\n" \ "DESCRIPTION\n" \ " A simplified version of uuencode(1). Reads an arbitrary" \ " file from standard input. Writes to standard output the same" \ " file encoded as printable ASCII" \ " text.\n" \ "\n" \ "AUTHORS\n" \ " The author of uudecode(1) is unknown.\n" \ " Copyright © 1983 Regents of the University of California.\n" \ "\n" \ " Modified 12 April 1990 by Mark Adler.\n" \ "\n" \ " Modifed 13 February 1991 by Greg Roelofs.\n" \ "\n" \ " Modified 13 April 1991 by Gary Mussar.\n" \ "\n" \ " Radically simplified 19 March 2005 by Jorge Stolfi: for" \ " Linux-only, works strictly as a filter." #include #include #include void encode(FILE *in, FILE *out); /* Copy from in to out, encoding as you go along. */ void outdec(char *p, FILE *f); /* Output one group of 3 bytes, pointed at by p, on file f. */ /* ENC is the basic 1-character encoding function to make a char printing */ #define ENC(c) ((c) ? ((c) & 077) + ' ': '`') int main(int argc, char **argv) { FILE *in = stdin; FILE *out = stdout; /* Check command line args: */ if (argc > 1) { printf("Usage: %s %s\n", PROG_NAME, PROG_HELP); exit(1); } /* Fake begin line: */ fprintf(out, "begin 0777 somefile\n"); encode(in, out); fprintf(out, "end\n"); return 0; } void encode(FILE *in, FILE *out) { char buf[80]; register int i, n; for (;;) { /* 1 (up to) 45 character line */ n = fread(buf, 1, 45, in); putc(ENC(n), out); for (i=0; i> 2; c2 = ((*p << 4) & 060) | ((p[1] >> 4) & 017); c3 = ((p[1] << 2) & 074) | ((p[2] >> 6) & 03); c4 = p[2] & 077; putc(ENC(c1), f); putc(ENC(c2), f); putc(ENC(c3), f); putc(ENC(c4), f); } /* * Copyright (c) 1983 Regents of the University of California. * All rights reserved. * * Redistribution and use in source and binary forms are permitted * provided that the above copyright notice and this paragraph are * duplicated in all such forms and that any documentation, * advertising materials, and other materials related to such * distribution and use acknowledge that the software was developed * by the University of California, Berkeley. The name of the * University may not be used to endorse or promote products derived * from this software without specific prior written permission. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ /* * Modified 12 April 1990 by Mark Adler for use on MSDOS systems with * Microsoft C and Turbo C. Standard input problem fixed 29 April 1990 * as per suggestion by Steve Harrold. * * Modifed 13 February 1991 by Greg Roelofs for use on VMS systems. * Compile and link normally (but note that the shared-image link option * produces a binary only 6 blocks long, as opposed to the 152-block one * produced by an ordinary link). To set up the VMS symbol to run the * program ("run uuencode filename1 filename2 filename3" won't work), do: * uuencode :== "$disk:[directory]uuencode.exe" * and don't forget the leading "$" or it still won't work. The syntax * differs slightly from the Unix and MS-DOS versions since VMS has such * an awkward approach to redirection; run the program with no arguments * for the usage (or see USAGE below). The output file is in VMS "stream- * LF" format but should be readable by MAIL, ftp, or anything else. * * Modified 19 mar 2005 by Jorge Stolfi: radically simplified: for linux-only, * works strictly as a filter. */