uu{encode,decode}: improve style
This commit is contained in:
parent
68700941c7
commit
d5d3f5dab2
@ -62,6 +62,7 @@ __FBSDID("$FreeBSD$");
|
||||
#include <libgen.h>
|
||||
#include <pwd.h>
|
||||
#include <resolv.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@ -69,7 +70,7 @@ __FBSDID("$FreeBSD$");
|
||||
|
||||
static const char *infile, *outfile;
|
||||
static FILE *infp, *outfp;
|
||||
static int base64, cflag, iflag, oflag, pflag, rflag, sflag;
|
||||
static bool base64, cflag, iflag, oflag, pflag, rflag, sflag;
|
||||
|
||||
static void usage(void);
|
||||
static int decode(void);
|
||||
@ -83,42 +84,42 @@ main(int argc, char *argv[])
|
||||
int rval, ch;
|
||||
|
||||
if (strcmp(basename(argv[0]), "b64decode") == 0)
|
||||
base64 = 1;
|
||||
base64 = true;
|
||||
|
||||
while ((ch = getopt(argc, argv, "cimo:prs")) != -1) {
|
||||
switch (ch) {
|
||||
case 'c':
|
||||
if (oflag || rflag)
|
||||
usage();
|
||||
cflag = 1; /* multiple uudecode'd files */
|
||||
cflag = true; /* multiple uudecode'd files */
|
||||
break;
|
||||
case 'i':
|
||||
iflag = 1; /* ask before override files */
|
||||
iflag = true; /* ask before override files */
|
||||
break;
|
||||
case 'm':
|
||||
base64 = 1;
|
||||
base64 = true;
|
||||
break;
|
||||
case 'o':
|
||||
if (cflag || pflag || rflag || sflag)
|
||||
usage();
|
||||
oflag = 1; /* output to the specified file */
|
||||
sflag = 1; /* do not strip pathnames for output */
|
||||
oflag = true; /* output to the specified file */
|
||||
sflag = true; /* do not strip pathnames for output */
|
||||
outfile = optarg; /* set the output filename */
|
||||
break;
|
||||
case 'p':
|
||||
if (oflag)
|
||||
usage();
|
||||
pflag = 1; /* print output to stdout */
|
||||
pflag = true; /* print output to stdout */
|
||||
break;
|
||||
case 'r':
|
||||
if (cflag || oflag)
|
||||
usage();
|
||||
rflag = 1; /* decode raw data */
|
||||
rflag = true; /* decode raw data */
|
||||
break;
|
||||
case 's':
|
||||
if (oflag)
|
||||
usage();
|
||||
sflag = 1; /* do not strip pathnames for output */
|
||||
sflag = true; /* do not strip pathnames for output */
|
||||
break;
|
||||
default:
|
||||
usage();
|
||||
@ -185,14 +186,14 @@ decode2(void)
|
||||
struct stat st;
|
||||
char buf[MAXPATHLEN + 1];
|
||||
|
||||
base64 = 0;
|
||||
base64 = false;
|
||||
/* search for header line */
|
||||
for (;;) {
|
||||
if (fgets(buf, sizeof(buf), infp) == NULL)
|
||||
return (EOF);
|
||||
p = buf;
|
||||
if (strncmp(p, "begin-base64 ", 13) == 0) {
|
||||
base64 = 1;
|
||||
base64 = true;
|
||||
p += 13;
|
||||
} else if (strncmp(p, "begin ", 6) == 0)
|
||||
p += 6;
|
||||
|
@ -58,6 +58,7 @@ __FBSDID("$FreeBSD$");
|
||||
#include <libgen.h>
|
||||
#include <resolv.h>
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
@ -68,18 +69,18 @@ static void usage(void);
|
||||
|
||||
static FILE *output;
|
||||
static int mode;
|
||||
static char raw = 0;
|
||||
static bool raw;
|
||||
static char **av;
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
struct stat sb;
|
||||
int base64;
|
||||
bool base64;
|
||||
int ch;
|
||||
const char *outfile;
|
||||
|
||||
base64 = 0;
|
||||
base64 = false;
|
||||
outfile = NULL;
|
||||
|
||||
if (strcmp(basename(argv[0]), "b64encode") == 0)
|
||||
@ -88,13 +89,13 @@ main(int argc, char *argv[])
|
||||
while ((ch = getopt(argc, argv, "mo:r")) != -1) {
|
||||
switch (ch) {
|
||||
case 'm':
|
||||
base64 = 1;
|
||||
base64 = true;
|
||||
break;
|
||||
case 'o':
|
||||
outfile = optarg;
|
||||
break;
|
||||
case 'r':
|
||||
raw = 1;
|
||||
raw = true;
|
||||
break;
|
||||
case '?':
|
||||
default:
|
||||
@ -104,7 +105,7 @@ main(int argc, char *argv[])
|
||||
argv += optind;
|
||||
argc -= optind;
|
||||
|
||||
switch(argc) {
|
||||
switch (argc) {
|
||||
case 2: /* optional first argument is input file */
|
||||
if (!freopen(*argv, "r", stdin) || fstat(fileno(stdin), &sb))
|
||||
err(1, "%s", *argv);
|
||||
@ -179,8 +180,8 @@ base64_encode(void)
|
||||
static void
|
||||
encode(void)
|
||||
{
|
||||
register int ch, n;
|
||||
register char *p;
|
||||
int ch, n;
|
||||
char *p;
|
||||
char buf[80];
|
||||
|
||||
if (!raw)
|
||||
|
Loading…
Reference in New Issue
Block a user