Make the handling of -i neater.
This commit is contained in:
parent
1e4cc34122
commit
279c15995c
@ -156,14 +156,14 @@ decode2(int flag)
|
|||||||
struct passwd *pw;
|
struct passwd *pw;
|
||||||
register int n;
|
register int n;
|
||||||
register char ch, *p;
|
register char ch, *p;
|
||||||
int base64, ignore, n1;
|
int base64, n1;
|
||||||
char buf[MAXPATHLEN+1];
|
char buf[MAXPATHLEN+1];
|
||||||
char buffn[MAXPATHLEN+1]; /* file name buffer */
|
char buffn[MAXPATHLEN+1]; /* file name buffer */
|
||||||
char *mode, *s;
|
char *mode, *s;
|
||||||
void *mode_handle;
|
void *mode_handle;
|
||||||
struct stat st;
|
struct stat st;
|
||||||
|
|
||||||
base64 = ignore = 0;
|
base64 = 0;
|
||||||
/* search for header line */
|
/* search for header line */
|
||||||
do {
|
do {
|
||||||
if (!fgets(buf, sizeof(buf), stdin)) {
|
if (!fgets(buf, sizeof(buf), stdin)) {
|
||||||
@ -239,8 +239,8 @@ decode2(int flag)
|
|||||||
if (mode_handle == NULL)
|
if (mode_handle == NULL)
|
||||||
err(1, "setmode()");
|
err(1, "setmode()");
|
||||||
if (iflag && !access(buf, F_OK)) {
|
if (iflag && !access(buf, F_OK)) {
|
||||||
(void)fprintf(stderr, "not overwritten: %s\n", buf);
|
warnx("not overwritten: %s", buf);
|
||||||
ignore++;
|
return(0);
|
||||||
} else if (freopen(buf, "w", stdout) == NULL ||
|
} else if (freopen(buf, "w", stdout) == NULL ||
|
||||||
stat(buf, &st) < 0 || (S_ISREG(st.st_mode) &&
|
stat(buf, &st) < 0 || (S_ISREG(st.st_mode) &&
|
||||||
fchmod(fileno(stdout), getmode(mode_handle, 0) & 0666))) {
|
fchmod(fileno(stdout), getmode(mode_handle, 0) & 0666))) {
|
||||||
@ -276,10 +276,6 @@ next:
|
|||||||
filename, buffn, 1 + ' ', 077 + ' ' + 1); \
|
filename, buffn, 1 + ' ', 077 + ' ' + 1); \
|
||||||
return(1); \
|
return(1); \
|
||||||
}
|
}
|
||||||
#define PUTCHAR(c) \
|
|
||||||
if (!ignore) \
|
|
||||||
putchar(c)
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* `n' is used to avoid writing out all the characters
|
* `n' is used to avoid writing out all the characters
|
||||||
@ -294,18 +290,18 @@ if (!ignore) \
|
|||||||
OUT_OF_RANGE
|
OUT_OF_RANGE
|
||||||
|
|
||||||
ch = DEC(p[0]) << 2 | DEC(p[1]) >> 4;
|
ch = DEC(p[0]) << 2 | DEC(p[1]) >> 4;
|
||||||
PUTCHAR(ch);
|
putchar(ch);
|
||||||
ch = DEC(p[1]) << 4 | DEC(p[2]) >> 2;
|
ch = DEC(p[1]) << 4 | DEC(p[2]) >> 2;
|
||||||
PUTCHAR(ch);
|
putchar(ch);
|
||||||
ch = DEC(p[2]) << 6 | DEC(p[3]);
|
ch = DEC(p[2]) << 6 | DEC(p[3]);
|
||||||
PUTCHAR(ch);
|
putchar(ch);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (n >= 1) {
|
if (n >= 1) {
|
||||||
if (!(IS_DEC(*p) && IS_DEC(*(p + 1))))
|
if (!(IS_DEC(*p) && IS_DEC(*(p + 1))))
|
||||||
OUT_OF_RANGE
|
OUT_OF_RANGE
|
||||||
ch = DEC(p[0]) << 2 | DEC(p[1]) >> 4;
|
ch = DEC(p[0]) << 2 | DEC(p[1]) >> 4;
|
||||||
PUTCHAR(ch);
|
putchar(ch);
|
||||||
}
|
}
|
||||||
if (n >= 2) {
|
if (n >= 2) {
|
||||||
if (!(IS_DEC(*(p + 1)) &&
|
if (!(IS_DEC(*(p + 1)) &&
|
||||||
@ -313,14 +309,14 @@ if (!ignore) \
|
|||||||
OUT_OF_RANGE
|
OUT_OF_RANGE
|
||||||
|
|
||||||
ch = DEC(p[1]) << 4 | DEC(p[2]) >> 2;
|
ch = DEC(p[1]) << 4 | DEC(p[2]) >> 2;
|
||||||
PUTCHAR(ch);
|
putchar(ch);
|
||||||
}
|
}
|
||||||
if (n >= 3) {
|
if (n >= 3) {
|
||||||
if (!(IS_DEC(*(p + 2)) &&
|
if (!(IS_DEC(*(p + 2)) &&
|
||||||
IS_DEC(*(p + 3))))
|
IS_DEC(*(p + 3))))
|
||||||
OUT_OF_RANGE
|
OUT_OF_RANGE
|
||||||
ch = DEC(p[2]) << 6 | DEC(p[3]);
|
ch = DEC(p[2]) << 6 | DEC(p[3]);
|
||||||
PUTCHAR(ch);
|
putchar(ch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user