Some small changes for od(1)
1) Move usage() down above main(). 2) Consistently use printaddress() across the code. 3) Use off_t instead of size_t for file offsets.
This commit is contained in:
parent
365f392d3c
commit
7132473947
36
od.c
36
od.c
|
@ -1,4 +1,5 @@
|
||||||
/* See LICENSE file for copyright and license details. */
|
/* See LICENSE file for copyright and license details. */
|
||||||
|
#include <inttypes.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
@ -9,21 +10,15 @@ static unsigned char radix = 'o';
|
||||||
static unsigned char type = 'o';
|
static unsigned char type = 'o';
|
||||||
|
|
||||||
static void
|
static void
|
||||||
usage(void)
|
printaddress(FILE *f, off_t addr)
|
||||||
{
|
{
|
||||||
eprintf("usage: %s [-A d|o|x|n] [-t a|c|d|o|u|x] [file ...]\n", argv0);
|
char fmt[] = "%07j# ";
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
printaddress(FILE *f, size_t addr)
|
|
||||||
{
|
|
||||||
char fmt[] = "%06z# ";
|
|
||||||
|
|
||||||
if (radix == 'n') {
|
if (radix == 'n') {
|
||||||
fputc(' ', f);
|
fputc(' ', f);
|
||||||
} else {
|
} else {
|
||||||
fmt[4] = radix;
|
fmt[4] = radix;
|
||||||
fprintf(f, fmt, addr);
|
fprintf(f, fmt, (intmax_t)addr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,13 +68,12 @@ printchar(FILE *f, unsigned char c)
|
||||||
static void
|
static void
|
||||||
od(FILE *in, char *in_name, FILE *out, char *out_name)
|
od(FILE *in, char *in_name, FILE *out, char *out_name)
|
||||||
{
|
{
|
||||||
|
off_t addr;
|
||||||
|
size_t i, chunklen;
|
||||||
unsigned char buf[BUFSIZ];
|
unsigned char buf[BUFSIZ];
|
||||||
char fmt[] = "\n%.6z#";
|
|
||||||
off_t addr, bread, i;
|
|
||||||
|
|
||||||
addr = 0;
|
for (addr = 0; (chunklen = fread(buf, 1, BUFSIZ, in)); ) {
|
||||||
for (; (bread = fread(buf, 1, BUFSIZ, in)); ) {
|
for (i = 0; i < chunklen; ++i, ++addr) {
|
||||||
for (i = 0; i < bread; ++i, ++addr) {
|
|
||||||
if ((addr % bytes_per_line) == 0) {
|
if ((addr % bytes_per_line) == 0) {
|
||||||
if (addr)
|
if (addr)
|
||||||
fputc('\n', out);
|
fputc('\n', out);
|
||||||
|
@ -90,11 +84,17 @@ od(FILE *in, char *in_name, FILE *out, char *out_name)
|
||||||
if (feof(in) || ferror(in) || ferror(out))
|
if (feof(in) || ferror(in) || ferror(out))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (radix != 'n') {
|
|
||||||
fmt[5] = radix;
|
|
||||||
fprintf(out, fmt, addr);
|
|
||||||
}
|
|
||||||
fputc('\n', out);
|
fputc('\n', out);
|
||||||
|
if (radix != 'n') {
|
||||||
|
printaddress(out, addr);
|
||||||
|
fputc('\n', out);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
usage(void)
|
||||||
|
{
|
||||||
|
eprintf("usage: %s [-A d|o|x|n] [-t a|c|d|o|u|x] [file ...]\n", argv0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
|
Loading…
Reference in New Issue
Block a user