summaryrefslogtreecommitdiffstats
path: root/text-utils
diff options
context:
space:
mode:
authorKarel Zak2006-12-07 00:25:53 +0100
committerKarel Zak2006-12-07 00:25:53 +0100
commitffc4374869b9ac10539a3c18e13b29d1b0c64484 (patch)
tree1b8054e83f7f70e8fa77499fc9246d1cc16faa15 /text-utils
parentImported from util-linux-2.11n tarball. (diff)
downloadkernel-qcow2-util-linux-ffc4374869b9ac10539a3c18e13b29d1b0c64484.tar.gz
kernel-qcow2-util-linux-ffc4374869b9ac10539a3c18e13b29d1b0c64484.tar.xz
kernel-qcow2-util-linux-ffc4374869b9ac10539a3c18e13b29d1b0c64484.zip
Imported from util-linux-2.11o tarball.
Diffstat (limited to 'text-utils')
-rw-r--r--text-utils/Makefile2
-rw-r--r--text-utils/col.c2
-rw-r--r--text-utils/colrm.c6
-rw-r--r--text-utils/column.c4
-rw-r--r--text-utils/conv.c18
-rw-r--r--text-utils/display.c231
-rw-r--r--text-utils/hexdump.139
-rw-r--r--text-utils/hexdump.c2
-rw-r--r--text-utils/hexdump.h10
-rw-r--r--text-utils/hexsyntax.c26
-rw-r--r--text-utils/od.112
-rw-r--r--text-utils/odsyntax.c84
-rw-r--r--text-utils/parse.c187
-rw-r--r--text-utils/rev.c2
-rw-r--r--text-utils/ul.c4
15 files changed, 329 insertions, 300 deletions
diff --git a/text-utils/Makefile b/text-utils/Makefile
index 8609bacde..c8d32ad1a 100644
--- a/text-utils/Makefile
+++ b/text-utils/Makefile
@@ -46,7 +46,7 @@ else
ul:
@echo $@ not made since it requires ncurses
ifeq "$(HAVE_TERMCAP)" "yes"
-more: more.o
+more: more.o $(LIB)/xstrncpy.o
$(CC) $(CFLAGS) $(LDFLAGS) $^ -o $@ $(LIBTERMCAP)
else
more:
diff --git a/text-utils/col.c b/text-utils/col.c
index 0a875af3d..052d91e7a 100644
--- a/text-utils/col.c
+++ b/text-utils/col.c
@@ -117,8 +117,6 @@ int pass_unknown_seqs; /* whether to pass unknown control sequences */
int main(int argc, char **argv)
{
- extern int optind;
- extern char *optarg;
register wint_t ch;
CHAR *c;
CSET cur_set; /* current character set */
diff --git a/text-utils/colrm.c b/text-utils/colrm.c
index 9ef8af679..5e18a6ffa 100644
--- a/text-utils/colrm.c
+++ b/text-utils/colrm.c
@@ -70,7 +70,7 @@ start:
ct = 0;
loop1:
c = getwc(stdin);
- if (feof(stdin))
+ if (c == WEOF)
goto fin;
if (c == '\t')
w = ((ct + 8) & ~7) - ct;
@@ -96,7 +96,7 @@ loop1:
/* Loop getting rid of characters */
while (!last || ct < last) {
c = getwc(stdin);
- if (feof(stdin))
+ if (c == WEOF)
goto fin;
if (c == '\n') {
putwc(c, stdout);
@@ -119,7 +119,7 @@ loop1:
/* Output last of the line */
for (;;) {
c = getwc(stdin);
- if (feof(stdin))
+ if (c == WEOF)
break;
if (c == '\n') {
putwc(c, stdout);
diff --git a/text-utils/column.c b/text-utils/column.c
index 3a54fe054..22b4c120d 100644
--- a/text-utils/column.c
+++ b/text-utils/column.c
@@ -88,8 +88,6 @@ main(int argc, char **argv)
char *p;
#ifdef __linux__
- extern int optind;
- extern char *optarg;
extern char *__progname;
__progname = argv[0];
#endif
@@ -104,7 +102,7 @@ main(int argc, char **argv)
termwidth = win.ws_col;
tflag = xflag = 0;
- while ((ch = getopt(argc, argv, "c:s:tx")) != EOF)
+ while ((ch = getopt(argc, argv, "c:s:tx")) != -1)
switch(ch) {
case 'c':
termwidth = atoi(optarg);
diff --git a/text-utils/conv.c b/text-utils/conv.c
index 2a256fa23..8e0efa16d 100644
--- a/text-utils/conv.c
+++ b/text-utils/conv.c
@@ -36,10 +36,11 @@
#include <sys/types.h>
#include "hexdump.h"
-void conv_c(PR *pr, u_char *p)
+void
+conv_c(PR *pr, u_char *p)
{
- extern int deprecated;
- char buf[10], *str;
+ char buf[10];
+ char const *str;
switch(*p) {
case '\0':
@@ -78,16 +79,17 @@ void conv_c(PR *pr, u_char *p)
*pr->cchar = 'c';
(void)printf(pr->fmt, *p);
} else {
- (void)sprintf(str = buf, "%03o", (int)*p);
+ (void)sprintf(buf, "%03o", (int)*p);
+ str = buf;
strpr: *pr->cchar = 's';
(void)printf(pr->fmt, str);
}
}
-void conv_u(PR *pr, u_char *p)
+void
+conv_u(PR *pr, u_char *p)
{
- extern int deprecated;
- static char *list[] = {
+ static const char *list[] = {
"nul", "soh", "stx", "etx", "eot", "enq", "ack", "bel",
"bs", "ht", "lf", "vt", "ff", "cr", "so", "si",
"dle", "dcl", "dc2", "dc3", "dc4", "nak", "syn", "etb",
@@ -104,7 +106,7 @@ void conv_u(PR *pr, u_char *p)
} else if (*p == 0x7f) {
*pr->cchar = 's';
(void)printf(pr->fmt, "del");
- } else if (deprecated && *p == 0x20) { /* od replace space with sp */
+ } else if (deprecated && *p == 0x20) { /* od replaced space with sp */
*pr->cchar = 's';
(void)printf(pr->fmt, " sp");
} else if (isprint(*p)) {
diff --git a/text-utils/display.c b/text-utils/display.c
index 145508813..25d7f043a 100644
--- a/text-utils/display.c
+++ b/text-utils/display.c
@@ -41,7 +41,7 @@
#include <string.h>
#include "hexdump.h"
-static void doskip(char *, int);
+static void doskip(const char *, int);
static u_char *get(void);
#ifndef MIN
@@ -52,99 +52,116 @@ enum _vflag vflag = FIRST;
static off_t address; /* address/offset in stream */
static off_t eaddress; /* end address */
-static off_t savaddress; /* saved address/offset in stream */
-#define PRINT { \
- switch(pr->flags) { \
- case F_ADDRESS: \
- (void)printf(pr->fmt, address); \
- break; \
- case F_BPAD: \
- (void)printf(pr->fmt, ""); \
- break; \
- case F_C: \
- conv_c(pr, bp); \
- break; \
- case F_CHAR: \
- (void)printf(pr->fmt, *bp); \
- break; \
- case F_DBL: { \
- double dval; \
- float fval; \
- switch(pr->bcnt) { \
- case 4: \
- bcopy((char *)bp, (char *)&fval, sizeof(fval)); \
- (void)printf(pr->fmt, fval); \
- break; \
- case 8: \
- bcopy((char *)bp, (char *)&dval, sizeof(dval)); \
- (void)printf(pr->fmt, dval); \
- break; \
- } \
- break; \
- } \
- case F_INT: { \
- int ival; \
- short sval; \
- switch(pr->bcnt) { \
- case 1: \
- (void)printf(pr->fmt, (int)*bp); \
- break; \
- case 2: \
- bcopy((char *)bp, (char *)&sval, sizeof(sval)); \
- (void)printf(pr->fmt, (int)sval); \
- break; \
- case 4: \
- bcopy((char *)bp, (char *)&ival, sizeof(ival)); \
- (void)printf(pr->fmt, ival); \
- break; \
- } \
- break; \
- } \
- case F_P: \
- (void)printf(pr->fmt, isprint(*bp) ? *bp : '.'); \
- break; \
- case F_STR: \
- (void)printf(pr->fmt, (char *)bp); \
- break; \
- case F_TEXT: \
- (void)printf(pr->fmt); \
- break; \
- case F_U: \
- conv_u(pr, bp); \
- break; \
- case F_UINT: { \
- u_int ival; \
- u_short sval; \
- switch(pr->bcnt) { \
- case 1: \
- (void)printf(pr->fmt, (u_int)*bp); \
- break; \
- case 2: \
- bcopy((char *)bp, (char *)&sval, sizeof(sval)); \
- (void)printf(pr->fmt, (u_int)sval); \
- break; \
- case 4: \
- bcopy((char *)bp, (char *)&ival, sizeof(ival)); \
- (void)printf(pr->fmt, ival); \
- break; \
- } \
- break; \
- } \
- } \
+static inline void
+print(PR *pr, u_char *bp) {
+
+ switch(pr->flags) {
+ case F_ADDRESS:
+ (void)printf(pr->fmt, (quad_t)address);
+ break;
+ case F_BPAD:
+ (void)printf(pr->fmt, "");
+ break;
+ case F_C:
+ conv_c(pr, bp);
+ break;
+ case F_CHAR:
+ (void)printf(pr->fmt, *bp);
+ break;
+ case F_DBL:
+ {
+ double dval;
+ float fval;
+ switch(pr->bcnt) {
+ case 4:
+ memmove(&fval, bp, sizeof(fval));
+ (void)printf(pr->fmt, fval);
+ break;
+ case 8:
+ memmove(&dval, bp, sizeof(dval));
+ (void)printf(pr->fmt, dval);
+ break;
+ }
+ break;
+ }
+ case F_INT:
+ {
+ short sval; /* int16_t */
+ int ival; /* int32_t */
+ long long Lval; /* int64_t, quad_t */
+
+ switch(pr->bcnt) {
+ case 1:
+ (void)printf(pr->fmt, (quad_t)*bp);
+ break;
+ case 2:
+ memmove(&sval, bp, sizeof(sval));
+ (void)printf(pr->fmt, (quad_t)sval);
+ break;
+ case 4:
+ memmove(&ival, bp, sizeof(ival));
+ (void)printf(pr->fmt, (quad_t)ival);
+ break;
+ case 8:
+ memmove(&Lval, bp, sizeof(Lval));
+ (void)printf(pr->fmt, (quad_t)Lval);
+ break;
+ }
+ break;
+ }
+ case F_P:
+ (void)printf(pr->fmt, isprint(*bp) ? *bp : '.');
+ break;
+ case F_STR:
+ (void)printf(pr->fmt, (char *)bp);
+ break;
+ case F_TEXT:
+ (void)printf("%s", pr->fmt);
+ break;
+ case F_U:
+ conv_u(pr, bp);
+ break;
+ case F_UINT:
+ {
+ unsigned short sval; /* u_int16_t */
+ unsigned int ival; /* u_int32_t */
+ unsigned long long Lval;/* u_int64_t, u_quad_t */
+
+ switch(pr->bcnt) {
+ case 1:
+ (void)printf(pr->fmt, (u_quad_t)*bp);
+ break;
+ case 2:
+ memmove(&sval, bp, sizeof(sval));
+ (void)printf(pr->fmt, (u_quad_t)sval);
+ break;
+ case 4:
+ memmove(&ival, bp, sizeof(ival));
+ (void)printf(pr->fmt, (u_quad_t)ival);
+ break;
+ case 8:
+ memmove(&Lval, bp, sizeof(Lval));
+ (void)printf(pr->fmt, (u_quad_t)Lval);
+ break;
+ }
+ break;
+ }
+ }
}
static void bpad(PR *pr)
{
- static char *spec = " -0+#";
- register char *p1, *p2;
+ static const char *spec = " -0+#";
+ char *p1, *p2;
/*
* remove all conversion flags; '-' is the only one valid
* with %s, and it's not useful here.
*/
pr->flags = F_BPAD;
- *pr->cchar = 's';
+ pr->cchar[0] = 's';
+ pr->cchar[1] = 0;
for (p1 = pr->fmt; *p1 != '%'; ++p1);
for (p2 = ++p1; *p1 && index(spec, *p1); ++p1);
while ((*p2++ = *p1++) != 0) ;
@@ -152,7 +169,6 @@ static void bpad(PR *pr)
void display(void)
{
- extern FU *endfu;
register FS *fs;
register FU *fu;
register PR *pr;
@@ -177,7 +193,7 @@ void display(void)
savech = *pr->nospace;
*pr->nospace = '\0';
}
- PRINT;
+ print(pr, bp);
if (cnt == 1 && pr->nospace)
*pr->nospace = savech;
}
@@ -195,10 +211,10 @@ void display(void)
for (pr = endfu->nextpr; pr; pr = pr->nextpr)
switch(pr->flags) {
case F_ADDRESS:
- (void)printf(pr->fmt, eaddress);
+ (void)printf(pr->fmt, (quad_t)eaddress);
break;
case F_TEXT:
- (void)printf(pr->fmt);
+ (void)printf("%s", pr->fmt);
break;
}
}
@@ -209,21 +225,20 @@ static char **_argv;
static u_char *
get(void)
{
- extern int length;
static int ateof = 1;
static u_char *curp, *savp;
- register int n;
+ int n;
int need, nread;
u_char *tmpp;
if (!curp) {
- curp = (u_char *)emalloc(blocksize);
- savp = (u_char *)emalloc(blocksize);
+ curp = emalloc(blocksize);
+ savp = emalloc(blocksize);
} else {
tmpp = curp;
curp = savp;
savp = tmpp;
- address = savaddress += blocksize;
+ address += blocksize;
}
for (need = blocksize, nread = 0;;) {
/*
@@ -231,15 +246,16 @@ get(void)
* and no other files are available, zero-pad the rest of the
* block and set the end flag.
*/
- if (!length || (ateof && !next((char **)NULL))) {
+ if (!length || (ateof && !next(NULL))) {
if (need == blocksize)
- return((u_char *)NULL);
- if (vflag != ALL && !bcmp(curp, savp, nread)) {
+ return(NULL);
+ if (!need && vflag != ALL &&
+ !memcmp(curp, savp, nread)) {
if (vflag != DUP)
(void)printf("*\n");
- return((u_char *)NULL);
+ return(NULL);
}
- bzero((char *)curp + nread, need);
+ memset((char *)curp + nread, 0, need);
eaddress = address + nread;
return(curp);
}
@@ -257,7 +273,7 @@ get(void)
length -= n;
if (!(need -= n)) {
if (vflag == ALL || vflag == FIRST ||
- bcmp(curp, savp, blocksize)) {
+ memcmp(curp, savp, blocksize)) {
if (vflag == DUP || vflag == FIRST)
vflag = WAIT;
return(curp);
@@ -265,7 +281,7 @@ get(void)
if (vflag == WAIT)
(void)printf("*\n");
vflag = DUP;
- address = savaddress += blocksize;
+ address += blocksize;
need = blocksize;
nread = 0;
}
@@ -276,7 +292,6 @@ get(void)
int next(char **argv)
{
- extern int exitval;
static int done;
int statok;
@@ -310,7 +325,7 @@ int next(char **argv)
}
static void
-doskip(char *fname, int statok)
+doskip(const char *fname, int statok)
{
struct stat sbuf;
@@ -320,32 +335,30 @@ doskip(char *fname, int statok)
fname, strerror(errno));
exit(1);
}
- if ( ( ! (S_ISCHR(sbuf.st_mode) ||
- S_ISBLK(sbuf.st_mode) ||
- S_ISFIFO(sbuf.st_mode)) ) &&
- skip >= sbuf.st_size) {
+ if (S_ISREG(sbuf.st_mode) && skip >= sbuf.st_size) {
/* If size valid and skip >= size */
skip -= sbuf.st_size;
address += sbuf.st_size;
return;
}
}
+ /* sbuf may be undefined here - do not test it */
if (fseek(stdin, skip, SEEK_SET)) {
(void)fprintf(stderr, "hexdump: %s: %s.\n",
fname, strerror(errno));
exit(1);
}
- savaddress = address += skip;
+ address += skip;
skip = 0;
}
-char *
+void *
emalloc(int sz) {
- char *p;
+ void *p;
if (!(p = malloc((u_int)sz)))
nomem();
- bzero(p, sz);
+ memset(p, 0, sz);
return(p);
}
diff --git a/text-utils/hexdump.1 b/text-utils/hexdump.1
index 7161beb45..0a479f5ec 100644
--- a/text-utils/hexdump.1
+++ b/text-utils/hexdump.1
@@ -29,7 +29,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)hexdump.1 8.2 (Berkeley) 4/18/94
+.\" from: @(#)hexdump.1 8.2 (Berkeley) 4/18/94
.\"
.Dd April 18, 1994
.Dt HEXDUMP 1
@@ -38,15 +38,21 @@
.Nm hexdump
.Nd ascii, decimal, hexadecimal, octal dump
.Sh SYNOPSIS
-.Nm hexdump
-.Op Fl bcdovx
+.Nm ""
+.Op Fl bcCdovx
+.Bk -words
.Op Fl e Ar format_string
+.Ek
+.Bk -words
.Op Fl f Ar format_file
+.Ek
+.Bk -words
.Op Fl n Ar length
+.Ek
.Bk -words
.Op Fl s Ar skip
.Ek
-.Ar file ...
+.Ar file ...
.Sh DESCRIPTION
The hexdump utility is a filter which displays the specified files, or
the standard input, if no files are specified, in a user specified
@@ -64,8 +70,13 @@ in octal, per line.
Display the input offset in hexadecimal, followed by sixteen
space-separated, three column, space-filled, characters of input
data per line.
+.It Fl C
+.Em Canonical hex+ASCII display .
+Display the input offset in hexadecimal, followed by sixteen
+space-separated, two column, hexadecimal bytes, followed by the
+same sixteen bytes in %_p format enclosed in ``|'' characters.
.It Fl d
-.Em Two-byte decimal display.
+.Em Two-byte decimal display .
Display the input offset in hexadecimal, followed by eight
space-separated, five column, zero-filled, two-byte units
of input data, in unsigned decimal, per line.
@@ -81,7 +92,7 @@ Interpret only
.Ar length
bytes of input.
.It Fl o
-.Em Two-byte octal display.
+.Em Two-byte octal display .
Display the input offset in hexadecimal, followed by eight
space-separated, six column, zero-filled, two byte quantities of
input data, in octal, per line.
@@ -126,14 +137,14 @@ identical to the immediately preceding group of output lines (except
for the input offsets), are replaced with a line comprised of a
single asterisk.
.It Fl x
-.Em Two-byte hexadecimal display.
+.Em Two-byte hexadecimal display .
Display the input offset in hexadecimal, followed by eight, space
separated, four column, zero-filled, two-byte quantities of input
data, in hexadecimal, per line.
.El
.Pp
For each input file,
-.Nm hexdump
+.Nm
sequentially copies the input to standard output, transforming the
data according to the format strings specified by the
.Fl e
@@ -195,7 +206,7 @@ described in the C standard are supported:
.Ed
.El
.Pp
-Hexdump also supports the the following additional conversion strings:
+Hexdump also supports the following additional conversion strings:
.Bl -tag -width Fl
.It Cm \&_a Ns Op Cm dox
Display the input offset, cumulative across input files, of the
@@ -305,7 +316,7 @@ to specifying the
.Fl x
option.
.Pp
-.Nm hexdump
+.Nm
exits 0 on success and >0 if an error occurred.
.Sh EXAMPLES
Display the input in perusal format:
@@ -320,5 +331,9 @@ Implement the \-x option:
"%07.7_Ax\en"
"%07.7_ax " 8/2 "%04x " "\en"
.Ed
-.Sh SEE ALSO
-.Xr adb 1
+.Sh STANDARDS
+The
+.Nm
+utility is expected to be
+.St -p1003.2
+compatible.
diff --git a/text-utils/hexdump.c b/text-utils/hexdump.c
index 82eb4d512..68bb76ec5 100644
--- a/text-utils/hexdump.c
+++ b/text-utils/hexdump.c
@@ -48,7 +48,7 @@ int length = -1; /* max bytes to read */
int main(int argc, char **argv)
{
- register FS *tfs;
+ FS *tfs;
char *p;
setlocale(LC_ALL, "");
diff --git a/text-utils/hexdump.h b/text-utils/hexdump.h
index 445312231..f9e963bbe 100644
--- a/text-utils/hexdump.h
+++ b/text-utils/hexdump.h
@@ -73,13 +73,17 @@ typedef struct _fs { /* format strings */
extern FU *endfu;
extern FS *fshead; /* head of format strings list */
extern int blocksize; /* data block size */
-extern int deprecated;
+extern int deprecated; /* od compatibility */
+extern int exitval; /* final exit value */
+extern int length; /* max bytes to read */
extern off_t skip; /* bytes to skip */
+
enum _vflag { ALL, DUP, FIRST, WAIT }; /* -v values */
+extern enum _vflag vflag;
-char *emalloc(int);
+void *emalloc(int);
int size(FS *);
-void add(char *);
+void add(const char *);
void rewrite(FS *);
void addfile(char *);
void display(void);
diff --git a/text-utils/hexsyntax.c b/text-utils/hexsyntax.c
index 154289da5..f05043c72 100644
--- a/text-utils/hexsyntax.c
+++ b/text-utils/hexsyntax.c
@@ -44,17 +44,14 @@
off_t skip; /* bytes to skip */
-void newsyntax(int argc, char ***argvp)
+void
+newsyntax(int argc, char ***argvp)
{
- extern enum _vflag vflag;
- extern FS *fshead;
- extern char *optarg;
- extern int length, optind;
int ch;
char *p, **argv;
argv = *argvp;
- while ((ch = getopt(argc, argv, "bcde:f:n:os:vx")) != EOF)
+ while ((ch = getopt(argc, argv, "bcCde:f:n:os:vx")) != -1)
switch (ch) {
case 'b':
add("\"%07.7_Ax\n\"");
@@ -64,6 +61,11 @@ void newsyntax(int argc, char ***argvp)
add("\"%07.7_Ax\n\"");
add("\"%07.7_ax \" 16/1 \"%3_c \" \"\\n\"");
break;
+ case 'C':
+ add("\"%08.8_Ax\n\"");
+ add("\"%08.8_ax \" 8/1 \"%02x \" \" \" 8/1 \"%02x \" ");
+ add("\" |\" 16/1 \"%_p\" \"|\\n\"");
+ break;
case 'd':
add("\"%07.7_Ax\n\"");
add("\"%07.7_ax \" 8/2 \" %05u \" \"\\n\"");
@@ -76,7 +78,7 @@ void newsyntax(int argc, char ***argvp)
break;
case 'n':
if ((length = atoi(optarg)) < 0) {
- (void)fprintf(stderr,
+ fprintf(stderr,
_("hexdump: bad length value.\n"));
exit(1);
}
@@ -87,7 +89,7 @@ void newsyntax(int argc, char ***argvp)
break;
case 's':
if ((skip = strtol(optarg, &p, 0)) < 0) {
- (void)fprintf(stderr,
+ fprintf(stderr,
_("hexdump: bad skip value.\n"));
exit(1);
}
@@ -112,7 +114,6 @@ void newsyntax(int argc, char ***argvp)
break;
case '?':
usage();
- exit(1);
}
if (!fshead) {
@@ -123,9 +124,10 @@ void newsyntax(int argc, char ***argvp)
*argvp += optind;
}
-void usage()
+void
+usage()
{
- (void)fprintf(stderr,
-_("hexdump: [-bcdovx] [-e fmt] [-f fmt_file] [-n length] [-s skip] [file ...]\n"));
+ fprintf(stderr,
+_("hexdump: [-bcCdovx] [-e fmt] [-f fmt_file] [-n length] [-s skip] [file ...]\n"));
exit(1);
}
diff --git a/text-utils/od.1 b/text-utils/od.1
index dab6da732..5eba652c3 100644
--- a/text-utils/od.1
+++ b/text-utils/od.1
@@ -29,16 +29,16 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)od.1 8.1 (Berkeley) 6/6/93
+.\" from: @(#)od.1 8.1 (Berkeley) 6/6/93
.\"
-.Dd %Q
+.Dd June 8, 1998
.Os
.Dt OD 1
.Sh NAME
.Nm od
.Nd octal, decimal, hex, ascii dump
.Sh SYNOPSIS
-.Nm od
+.Nm ""
.Op Fl aBbcDdeFfHhIiLlOovXx
.Sm off
.Oo
@@ -49,13 +49,13 @@
.Oc
.Ar file
.Sh DESCRIPTION
-.Nm Od
+.Nm
has been deprecated in favor of
.Xr hexdump 1 .
.Pp
.Xr Hexdump ,
if called as
-.Nm od ,
+.Nm "" ,
provides compatibility for the options listed above.
.Pp
It does not provide compatibility for the
@@ -72,5 +72,3 @@ of the offset syntax.
.Sh SEE ALSO
.Xr hexdump 1 ,
.Xr strings 1
-.Sh BUGS
-Quite a few.
diff --git a/text-utils/odsyntax.c b/text-utils/odsyntax.c
index 13f7dfa7e..e7711f957 100644
--- a/text-utils/odsyntax.c
+++ b/text-utils/odsyntax.c
@@ -51,15 +51,12 @@ int deprecated;
void
oldsyntax(int argc, char ***argvp)
{
- extern enum _vflag vflag;
- extern FS *fshead;
- extern int optind;
int ch;
char **argv;
deprecated = 1;
argv = *argvp;
- while ((ch = getopt(argc, argv, "aBbcDdeFfHhIiLlOoPpswvXx")) != EOF)
+ while ((ch = getopt(argc, argv, "aBbcDdeFfHhIiLlOoPpswvXx")) != -1)
switch (ch) {
case 'a':
odprecede();
@@ -129,10 +126,10 @@ oldsyntax(int argc, char ***argvp)
case 'w':
case '?':
default:
- (void)fprintf(stderr,
+ fprintf(stderr,
_("od: od(1) has been deprecated for hexdump(1).\n"));
if (ch != '?')
- (void)fprintf(stderr,
+ fprintf(stderr,
_("od: hexdump(1) compatibility doesn't support the -%c option%s\n"),
ch, ch == 's' ? _("; see strings(1).") : ".");
usage();
@@ -146,7 +143,8 @@ _("od: hexdump(1) compatibility doesn't support the -%c option%s\n"),
argc -= optind;
*argvp += optind;
- odoffset(argc, argvp);
+ if (argc)
+ odoffset(argc, argvp);
}
#define ishexdigit(c) \
@@ -155,8 +153,7 @@ _("od: hexdump(1) compatibility doesn't support the -%c option%s\n"),
static void
odoffset(int argc, char ***argvp)
{
- extern off_t skip;
- register char *num, *p;
+ char *num, *p;
int base;
char *end;
@@ -170,11 +167,15 @@ odoffset(int argc, char ***argvp)
* multiplied the number by 512 or 1024 byte units. There was
* no way to assign a block count to a hex offset.
*
- * We assumes it's a file if the offset is bad.
+ * We assume it's a file if the offset is bad.
*/
- p = **argvp;
+ p = argc == 1 ? (*argvp)[0] : (*argvp)[1];
+ if (!p)
+ return;
+
if (*p != '+' && (argc < 2 ||
- (!isdigit(p[0]) && (p[0] != 'x' || !ishexdigit(p[1])))))
+ (!isdigit((unsigned char)p[0]) &&
+ (p[0] != 'x' || !ishexdigit(p[1])))))
return;
base = 0;
@@ -196,7 +197,7 @@ odoffset(int argc, char ***argvp)
if (base == 16)
for (num = p; ishexdigit(*p); ++p);
else
- for (num = p; isdigit(*p); ++p);
+ for (num = p; isdigit((unsigned char)*p); ++p);
/* check for no number */
if (num == p)
@@ -212,35 +213,42 @@ odoffset(int argc, char ***argvp)
skip = strtol(num, &end, base ? base : 8);
/* if end isn't the same as p, we got a non-octal digit */
- if (end != p)
+ if (end != p) {
skip = 0;
- else {
- if (*p) {
- if (*p == 'b')
- skip *= 512;
- else if (*p == 'B')
- skip *= 1024;
- ++p;
+ return;
+ }
+
+ if (*p) {
+ if (*p == 'B') {
+ skip *= 1024;
+ p++;
+ } else if (*p == 'b') {
+ skip *= 512;
+ p++;
}
- if (*p)
- skip = 0;
- else {
- ++*argvp;
- /*
- * If the offset uses a non-octal base, the base of
- * the offset is changed as well. This isn't pretty,
- * but it's easy.
- */
+ }
+
+ if (*p) {
+ skip = 0;
+ return;
+ }
+
+ /*
+ * If the offset uses a non-octal base, the base of
+ * the offset is changed as well. This isn't pretty,
+ * but it's easy.
+ */
#define TYPE_OFFSET 7
- if (base == 16) {
- fshead->nextfu->fmt[TYPE_OFFSET] = 'x';
- fshead->nextfs->nextfu->fmt[TYPE_OFFSET] = 'x';
- } else if (base == 10) {
- fshead->nextfu->fmt[TYPE_OFFSET] = 'd';
- fshead->nextfs->nextfu->fmt[TYPE_OFFSET] = 'd';
- }
- }
+ if (base == 16) {
+ fshead->nextfu->fmt[TYPE_OFFSET] = 'x';
+ fshead->nextfs->nextfu->fmt[TYPE_OFFSET] = 'x';
+ } else if (base == 10) {
+ fshead->nextfu->fmt[TYPE_OFFSET] = 'd';
+ fshead->nextfs->nextfu->fmt[TYPE_OFFSET] = 'd';
}
+
+ /* Terminate file list. */
+ (*argvp)[1] = NULL;
}
static void
diff --git a/text-utils/parse.c b/text-utils/parse.c
index ce57c071c..d7a302082 100644
--- a/text-utils/parse.c
+++ b/text-utils/parse.c
@@ -44,33 +44,33 @@
#include "hexdump.h"
#include "nls.h"
-static void escape(register char *p1);
-static void badcnt(char *s);
+static void escape(char *p1);
+static void badcnt(const char *s);
static void badsfmt(void);
-static void badfmt(char *fmt);
-static void badconv(char *ch);
+static void badfmt(const char *fmt);
+static void badconv(const char *ch);
FU *endfu; /* format at end-of-data */
void addfile(char *name)
{
- register char *p;
+ char *p;
FILE *fp;
int ch;
char buf[2048 + 1];
- if (!(fp = fopen(name, "r"))) {
+ if ((fp = fopen(name, "r")) == NULL) {
(void)fprintf(stderr, _("hexdump: can't read %s.\n"), name);
exit(1);
}
while (fgets(buf, sizeof(buf), fp)) {
- if (!(p = index(buf, '\n'))) {
+ if ((p = index(buf, '\n')) == NULL) {
(void)fprintf(stderr, _("hexdump: line too long.\n"));
while ((ch = getchar()) != '\n' && ch != EOF);
continue;
}
*p = '\0';
- for (p = buf; *p && isspace(*p); ++p);
+ for (p = buf; *p && isspace((unsigned char)*p); ++p);
if (!*p || *p == '#')
continue;
add(p);
@@ -78,17 +78,16 @@ void addfile(char *name)
(void)fclose(fp);
}
-void add(char *fmt)
+void add(const char *fmt)
{
- register char *p;
+ const char *p;
static FS **nextfs;
FS *tfs;
FU *tfu, **nextfu;
- char *savep;
+ const char *savep;
- /* start new linked list of format units */
- /* NOSTRICT */
- tfs = (FS *)emalloc(sizeof(FS));
+ /* Start new linked list of format units. */
+ tfs = emalloc(sizeof(FS));
if (!fshead)
fshead = tfs;
else
@@ -96,44 +95,43 @@ void add(char *fmt)
nextfs = &tfs->nextfs;
nextfu = &tfs->nextfu;
- /* take the format string and break it up into format units */
+ /* Take the format string and break it up into format units. */
for (p = fmt;;) {
- /* skip leading white space */
- for (; isspace(*p); ++p);
+ /* Skip leading white space. */
+ for (; isspace((unsigned char)*p); ++p);
if (!*p)
break;
- /* allocate a new format unit and link it in */
- /* NOSTRICT */
- tfu = (FU *)emalloc(sizeof(FU));
+ /* Allocate a new format unit and link it in. */
+ tfu = emalloc(sizeof(FU));
*nextfu = tfu;
nextfu = &tfu->nextfu;
tfu->reps = 1;
- /* if leading digit, repetition count */
- if (isdigit(*p)) {
- for (savep = p; isdigit(*p); ++p);
- if (!isspace(*p) && *p != '/')
+ /* If leading digit, repetition count. */
+ if (isdigit((unsigned char)*p)) {
+ for (savep = p; isdigit((unsigned char)*p); ++p);
+ if (!isspace((unsigned char)*p) && *p != '/')
badfmt(fmt);
/* may overwrite either white space or slash */
tfu->reps = atoi(savep);
tfu->flags = F_SETREP;
/* skip trailing white space */
- for (++p; isspace(*p); ++p);
+ for (++p; isspace((unsigned char)*p); ++p);
}
- /* skip slash and trailing white space */
+ /* Skip slash and trailing white space. */
if (*p == '/')
- while (isspace(*++p));
+ while (isspace((unsigned char)*++p));
/* byte count */
- if (isdigit(*p)) {
- for (savep = p; isdigit(*p); ++p);
- if (!isspace(*p))
+ if (isdigit((unsigned char)*p)) {
+ for (savep = p; isdigit((unsigned char)*p); ++p);
+ if (!isspace((unsigned char)*p))
badfmt(fmt);
tfu->bcnt = atoi(savep);
/* skip trailing white space */
- for (++p; isspace(*p); ++p);
+ for (++p; isspace((unsigned char)*p); ++p);
}
/* format */
@@ -151,13 +149,13 @@ void add(char *fmt)
}
}
-static char *spec = ".#-+ 0123456789";
+static const char *spec = ".#-+ 0123456789";
int size(FS *fs)
{
- register FU *fu;
- register int bcnt, cursize;
- register char *fmt;
+ FU *fu;
+ int bcnt, cursize;
+ char *fmt;
int prec;
/* figure out the data block size needed for each format unit */
@@ -174,9 +172,9 @@ int size(FS *fs)
* case it's a %s format.
*/
while (index(spec + 1, *++fmt));
- if (*fmt == '.' && isdigit(*++fmt)) {
+ if (*fmt == '.' && isdigit((unsigned char)*++fmt)) {
prec = atoi(fmt);
- while (isdigit(*++fmt));
+ while (isdigit((unsigned char)*++fmt));
}
switch(*fmt) {
case 'c':
@@ -208,29 +206,31 @@ int size(FS *fs)
void rewrite(FS *fs)
{
enum { NOTOKAY, USEBCNT, USEPREC } sokay;
- register PR *pr, **nextpr = NULL;
- register FU *fu;
- register char *p1, *p2;
- char savech, *fmtp;
- int nconv, prec = 0;
+ PR *pr, **nextpr;
+ FU *fu;
+ char *p1, *p2;
+ char savech, *fmtp, cs[3];
+ int nconv, prec;
+
+ nextpr = NULL;
+ prec = 0;
for (fu = fs->nextfu; fu; fu = fu->nextfu) {
/*
- * break each format unit into print units; each
+ * Break each format unit into print units; each
* conversion character gets its own.
*/
for (nconv = 0, fmtp = fu->fmt; *fmtp; nextpr = &pr->nextpr) {
- /* NOSTRICT */
- pr = (PR *)emalloc(sizeof(PR));
+ pr = emalloc(sizeof(PR));
if (!fu->nextpr)
fu->nextpr = pr;
else
*nextpr = pr;
- /* skip preceding text and up to the next % sign */
+ /* Skip preceding text and up to the next % sign. */
for (p1 = fmtp; *p1 && *p1 != '%'; ++p1);
- /* only text in the string */
+ /* Only text in the string. */
if (!*p1) {
pr->fmt = fmtp;
pr->flags = F_TEXT;
@@ -238,7 +238,7 @@ void rewrite(FS *fs)
}
/*
- * get precision for %s -- if have a byte count, don't
+ * Get precision for %s -- if have a byte count, don't
* need it.
*/
if (fu->bcnt) {
@@ -248,23 +248,25 @@ void rewrite(FS *fs)
} else {
/* skip any special chars, field width */
while (index(spec + 1, *++p1));
- if (*p1 == '.' && isdigit(*++p1)) {
+ if (*p1 == '.' &&
+ isdigit((unsigned char)*++p1)) {
sokay = USEPREC;
prec = atoi(p1);
- while (isdigit(*++p1));
- }
- else
+ while (isdigit((unsigned char)*++p1));
+ } else
sokay = NOTOKAY;
}
- p2 = p1 + 1; /* set end pointer */
+ p2 = p1 + 1; /* Set end pointer. */
+ cs[0] = *p1; /* Set conversion string. */
+ cs[1] = 0;
/*
- * figure out the byte count for each conversion;
+ * Figure out the byte count for each conversion;
* rewrite the format as necessary, set up blank-
* padding for end of data.
*/
- switch(*p1) {
+ switch(cs[0]) {
case 'c':
pr->flags = F_CHAR;
switch(fu->bcnt) {
@@ -278,26 +280,13 @@ void rewrite(FS *fs)
break;
case 'd': case 'i':
pr->flags = F_INT;
- goto sw1;
- case 'l':
- ++p2;
- switch(p1[1]) {
- case 'd': case 'i':
- ++p1;
- pr->flags = F_INT;
- goto sw1;
- case 'o': case 'u': case 'x': case 'X':
- ++p1;
- pr->flags = F_UINT;
- goto sw1;
- default:
- p1[2] = '\0';
- badconv(p1);
- }
- /* NOTREACHED */
+ goto isint;
case 'o': case 'u': case 'x': case 'X':
pr->flags = F_UINT;
-sw1: switch(fu->bcnt) {
+isint: cs[2] = '\0';
+ cs[1] = cs[0];
+ cs[0] = 'q';
+ switch(fu->bcnt) {
case 0: case 4:
pr->bcnt = 4;
break;
@@ -307,6 +296,9 @@ sw1: switch(fu->bcnt) {
case 2:
pr->bcnt = 2;
break;
+ case 8:
+ pr->bcnt = 8;
+ break;
default:
p1[1] = '\0';
badcnt(p1);
@@ -351,7 +343,9 @@ sw1: switch(fu->bcnt) {
++p2;
switch(p1[2]) {
case 'd': case 'o': case'x':
- *p1 = p1[2];
+ cs[0] = 'q';
+ cs[1] = p1[2];
+ cs[2] = '\0';
break;
default:
p1[3] = '\0';
@@ -360,16 +354,16 @@ sw1: switch(fu->bcnt) {
break;
case 'c':
pr->flags = F_C;
- /* *p1 = 'c'; set in conv_c */
- goto sw2;
+ /* cs[0] = 'c'; set in conv_c */
+ goto isint2;
case 'p':
pr->flags = F_P;
- *p1 = 'c';
- goto sw2;
+ cs[0] = 'c';
+ goto isint2;
case 'u':
pr->flags = F_U;
- /* *p1 = 'c'; set in conv_u */
-sw2: switch(fu->bcnt) {
+ /* cs[0] = 'c'; set in conv_u */
+isint2: switch(fu->bcnt) {
case 0: case 1:
pr->bcnt = 1;
break;
@@ -389,18 +383,19 @@ sw2: switch(fu->bcnt) {
}
/*
- * copy to PR format string, set conversion character
+ * Copy to PR format string, set conversion character
* pointer, update original.
*/
savech = *p2;
- p1[1] = '\0';
- if (!(pr->fmt = strdup(fmtp)))
- nomem();
+ p1[0] = '\0';
+ pr->fmt = emalloc(strlen(fmtp) + strlen(cs) + 1);
+ (void)strcpy(pr->fmt, fmtp);
+ (void)strcat(pr->fmt, cs);
*p2 = savech;
pr->cchar = pr->fmt + (p1 - fmtp);
fmtp = p2;
- /* only one conversion character if byte count */
+ /* Only one conversion character if byte count */
if (!(pr->flags&F_ADDRESS) && fu->bcnt && nconv++) {
(void)fprintf(stderr,
_("hexdump: byte count with multiple conversion characters.\n"));
@@ -408,7 +403,7 @@ sw2: switch(fu->bcnt) {
}
}
/*
- * if format unit byte count not specified, figure it out
+ * If format unit byte count not specified, figure it out
* so can adjust rep count later.
*/
if (!fu->bcnt)
@@ -416,15 +411,15 @@ sw2: switch(fu->bcnt) {
fu->bcnt += pr->bcnt;
}
/*
- * if the format string interprets any data at all, and it's
+ * If the format string interprets any data at all, and it's
* not the same as the blocksize, and its last format unit
* interprets any data at all, and has no iteration count,
* repeat it as necessary.
*
- * if, rep count is greater than 1, no trailing whitespace
+ * If rep count is greater than 1, no trailing whitespace
* gets output from the last iteration of the format unit.
*/
- for (fu = fs->nextfu;; fu = fu->nextfu) {
+ for (fu = fs->nextfu; fu; fu = fu->nextfu) {
if (!fu->nextfu && fs->bcnt < blocksize &&
!(fu->flags&F_SETREP) && fu->bcnt)
fu->reps += (blocksize - fs->bcnt) / fu->bcnt;
@@ -433,19 +428,17 @@ sw2: switch(fu->bcnt) {
if (!pr->nextpr)
break;
for (p1 = pr->fmt, p2 = NULL; *p1; ++p1)
- p2 = isspace(*p1) ? p1 : NULL;
+ p2 = isspace((unsigned char)*p1) ? p1 : NULL;
if (p2)
pr->nospace = p2;
}
- if (!fu->nextfu)
- break;
}
}
-static void escape(register char *p1)
+static void escape(char *p1)
{
- register char *p2;
+ char *p2;
/* alphabetic escape sequences have to be done in place */
for (p2 = p1;; ++p1, ++p2) {
@@ -484,7 +477,7 @@ static void escape(register char *p1)
}
}
-static void badcnt(char *s)
+static void badcnt(const char *s)
{
(void)fprintf(stderr,
_("hexdump: bad byte count for conversion character %s.\n"), s);
@@ -498,13 +491,13 @@ static void badsfmt(void)
exit(1);
}
-static void badfmt(char *fmt)
+static void badfmt(const char *fmt)
{
(void)fprintf(stderr, _("hexdump: bad format {%s}\n"), fmt);
exit(1);
}
-static void badconv(char *ch)
+static void badconv(const char *ch)
{
(void)fprintf(stderr, _("hexdump: bad conversion character %%%s.\n"), ch);
exit(1);
diff --git a/text-utils/rev.c b/text-utils/rev.c
index 29b8ee528..e3ac017a0 100644
--- a/text-utils/rev.c
+++ b/text-utils/rev.c
@@ -73,7 +73,7 @@ main(int argc, char *argv[])
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
- while ((ch = getopt(argc, argv, "")) != EOF)
+ while ((ch = getopt(argc, argv, "")) != -1)
switch(ch) {
case '?':
default:
diff --git a/text-utils/ul.c b/text-utils/ul.c
index fb0a697d1..6396f2dfe 100644
--- a/text-utils/ul.c
+++ b/text-utils/ul.c
@@ -114,8 +114,6 @@ int iflag;
int main(int argc, char **argv)
{
- extern int optind;
- extern char *optarg;
int c, ret;
char *termtype;
FILE *f;
@@ -127,7 +125,7 @@ int main(int argc, char **argv)
termtype = getenv("TERM");
if (termtype == NULL || (argv[0][0] == 'c' && !isatty(1)))
termtype = "lpr";
- while ((c=getopt(argc, argv, "it:T:")) != EOF)
+ while ((c = getopt(argc, argv, "it:T:")) != -1)
switch(c) {
case 't':