#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)odsyntax.c 8.2 (Berkeley) 5/4/95";
#else
__RCSID("$NetBSD: odsyntax.c,v 1.9 1998/08/25 20:59:37 ross Exp $");
#endif
#endif
#include <sys/types.h>
#include <ctype.h>
#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "hexdump.h"
int deprecated;
static void odoffset __P((int, char ***));
static void odprecede __P((void));
void
oldsyntax(argc, argvp)
int argc;
char ***argvp;
{
int ch;
char **argv;
deprecated = 1;
argv = *argvp;
while ((ch = getopt(argc, argv, "aBbcDdeFfHhIiLlOoPpswvXx")) != -1)
switch (ch) {
case 'a':
odprecede();
add("16/1 \"%3_u \" \"\\n\"");
break;
case 'B':
case 'o':
odprecede();
add("8/2 \" %06o \" \"\\n\"");
break;
case 'b':
odprecede();
add("16/1 \"%03o \" \"\\n\"");
break;
case 'c':
odprecede();
add("16/1 \"%3_c \" \"\\n\"");
break;
case 'd':
odprecede();
add("8/2 \" %05u \" \"\\n\"");
break;
case 'D':
odprecede();
add("4/4 \" %010u \" \"\\n\"");
break;
case 'e':
case 'F':
odprecede();
add("2/8 \" %21.14e \" \"\\n\"");
break;
case 'f':
odprecede();
add("4/4 \" %14.7e \" \"\\n\"");
break;
case 'H':
case 'X':
odprecede();
add("4/4 \" %08x \" \"\\n\"");
break;
case 'h':
case 'x':
odprecede();
add("8/2 \" %04x \" \"\\n\"");
break;
case 'I':
case 'L':
case 'l':
odprecede();
add("4/4 \" %11d \" \"\\n\"");
break;
case 'i':
odprecede();
add("8/2 \" %6d \" \"\\n\"");
break;
case 'O':
odprecede();
add("4/4 \" %011o \" \"\\n\"");
break;
case 'v':
vflag = ALL;
break;
case 'P':
case 'p':
case 's':
case 'w':
case '?':
default:
warnx("od(1) has been deprecated for hexdump(1).");
if (ch != '?')
warnx(
"hexdump(1) compatibility doesn't support the -%c option%s\n",
ch, ch == 's' ? "; see strings(1)." : ".");
usage();
}
if (!fshead) {
add("\"%07.7_Ao\n\"");
add("\"%07.7_ao \" 8/2 \"%06o \" \"\\n\"");
}
argc -= optind;
*argvp += optind;
if (argc)
odoffset(argc, argvp);
}
static void
odoffset(argc, argvp)
int argc;
char ***argvp;
{
char *num, *p;
int base;
char *end;
p = argc == 1 ? (*argvp)[0] : (*argvp)[1];
if (!p)
return;
if (*p != '+' && (argc < 2 ||
(!isdigit(p[0]) && (p[0] != 'x' || !isxdigit(p[1])))))
return;
base = 0;
if (p[0] == '+')
++p;
if (p[0] == 'x' && isxdigit(p[1])) {
++p;
base = 16;
} else if (p[0] == '0' && p[1] == 'x') {
p += 2;
base = 16;
}
if (base == 16)
for (num = p; isxdigit(*p); ++p);
else
for (num = p; isdigit(*p); ++p);
if (num == p)
return;
if (*p == '.') {
if (base)
return;
base = 10;
}
skip = strtoll(num, &end, base ? base : 8);
if (end != p) {
skip = 0;
return;
}
if (*p) {
if (*p == 'B') {
skip *= 1024;
++p;
} else if (*p == 'b') {
skip *= 512;
++p;
}
}
if (*p) {
skip = 0;
return;
}
#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';
}
(*argvp)[1] = NULL;
}
static void
odprecede()
{
static int first = 1;
if (first) {
first = 0;
add("\"%07.7_Ao\n\"");
add("\"%07.7_ao \"");
} else
add("\" \"");
}