Compare commits
2 commits
fa5095133a
...
4e8bb86ddd
Author | SHA1 | Date | |
---|---|---|---|
|
4e8bb86ddd | ||
|
733a013ee7 |
3 changed files with 22 additions and 17 deletions
7
Makefile
7
Makefile
|
@ -1,13 +1,14 @@
|
||||||
CFLAGS = -g -Wall -Wextra -Werror
|
CC = gcc
|
||||||
|
CFLAGS = -Og -Wall -Wextra -Werror
|
||||||
|
|
||||||
objects = main.o input.o output.o encode.o
|
objects = main.o input.o output.o encode.o
|
||||||
|
|
||||||
b64 : $(objects)
|
b64 : $(objects)
|
||||||
cc -o b64 $(objects)
|
$(CC) -o b64 $(objects)
|
||||||
|
|
||||||
main.o input.o : input.h
|
main.o input.o : input.h
|
||||||
main.o output.o : output.h
|
|
||||||
main.o encode.o : encode.h
|
main.o encode.o : encode.h
|
||||||
|
main.o output.o : output.h
|
||||||
|
|
||||||
.PHONY : clean
|
.PHONY : clean
|
||||||
clean :
|
clean :
|
||||||
|
|
31
main.c
31
main.c
|
@ -13,11 +13,12 @@ unsigned char sbuf[SXTETBUF];
|
||||||
int
|
int
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int c, n, l;
|
int c, n, last;
|
||||||
int dec, url, hlp, wrp;
|
int dec, url, hlp, wrp;
|
||||||
char *prog = *argv;
|
|
||||||
FILE *in, *out;
|
FILE *in, *out;
|
||||||
|
char *prog;
|
||||||
|
|
||||||
|
prog = *argv;
|
||||||
dec = url = hlp = wrp = 0;
|
dec = url = hlp = wrp = 0;
|
||||||
while (--argc > 0 && (*++argv)[0] == '-')
|
while (--argc > 0 && (*++argv)[0] == '-')
|
||||||
while ((c = *++argv[0]))
|
while ((c = *++argv[0]))
|
||||||
|
@ -42,6 +43,7 @@ main(int argc, char *argv[])
|
||||||
if (hlp) {
|
if (hlp) {
|
||||||
fprintf(stdout, "Usage: %s -duhw infile outfile\n", prog);
|
fprintf(stdout, "Usage: %s -duhw infile outfile\n", prog);
|
||||||
} else {
|
} else {
|
||||||
|
in = out = NULL;
|
||||||
if (argc >= 1 && (in = fopen(*argv, "r")) == NULL) {
|
if (argc >= 1 && (in = fopen(*argv, "r")) == NULL) {
|
||||||
fprintf(stderr, "%s: can't open %s\n", prog, *argv);
|
fprintf(stderr, "%s: can't open %s\n", prog, *argv);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
|
@ -51,22 +53,23 @@ main(int argc, char *argv[])
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
if (dec) {
|
if (dec) {
|
||||||
while ((n = getsxts((argc >= 1) ? in : stdin, sbuf))) {
|
while ((n = getsxts((in) ? in : stdin, sbuf))) {
|
||||||
n = decode(sbuf, n, obuf, url);
|
n = decode(sbuf, n, obuf, url);
|
||||||
fwrite(obuf, sizeof(*obuf), n, (argc == 2) ? out : stdout);
|
fwrite(obuf, sizeof(*obuf), n, (out) ? out : stdout);
|
||||||
}
|
}
|
||||||
|
} else if (wrp) {
|
||||||
|
last = 0;
|
||||||
|
while ((n = getocts((in) ? in : stdin, obuf))) {
|
||||||
|
n = encode(obuf, n, sbuf, url);
|
||||||
|
last = printw((out) ? out : stdout, sbuf, n);
|
||||||
|
}
|
||||||
|
if (last != '\n')
|
||||||
|
fprintf((out) ? out : stdout, "\n");
|
||||||
} else {
|
} else {
|
||||||
while ((n = getocts((argc >= 1) ? in : stdin, obuf))) {
|
while ((n = getocts((in) ? in : stdin, obuf))) {
|
||||||
if (wrp) {
|
encode(obuf, n, sbuf, url);
|
||||||
n = encode(obuf, n, sbuf, url);
|
fprintf((out) ? out : stdout, "%s", sbuf);
|
||||||
l = printw((argc == 2) ? out : stdout, sbuf, n);
|
|
||||||
} else {
|
|
||||||
encode(obuf, n, sbuf, url);
|
|
||||||
fprintf((argc == 2) ? out : stdout, "%s", sbuf);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (wrp && l != '\n')
|
|
||||||
fprintf((argc == 2) ? out : stdout, "\n");
|
|
||||||
}
|
}
|
||||||
if (in)
|
if (in)
|
||||||
fclose(in);
|
fclose(in);
|
||||||
|
|
1
output.c
1
output.c
|
@ -8,6 +8,7 @@ printw(FILE *fp, unsigned char *s, int slen)
|
||||||
static int col;
|
static int col;
|
||||||
int c;
|
int c;
|
||||||
|
|
||||||
|
c = '\n';
|
||||||
while (slen--) {
|
while (slen--) {
|
||||||
fputc((c = *s++), fp);
|
fputc((c = *s++), fp);
|
||||||
++col;
|
++col;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue