Ejemplo n.º 1
0
Archivo: od.c Proyecto: nawawi/busybox
int od_main(int argc, char **argv)
{
	int ch;
	int first = 1;
	char *p;
	dumper_t *dumper = alloc_dumper();

	while ((ch = getopt(argc, argv, od_opts)) > 0) {
		if (ch == 'v') {
			dumper->dump_vflag = ALL;
		} else if (((p = strchr(od_opts, ch)) != NULL) && (*p != '\0')) {
			if (first) {
				first = 0;
				bb_dump_add(dumper, "\"%07.7_Ao\n\"");
				bb_dump_add(dumper, "\"%07.7_ao  \"");
			} else {
				bb_dump_add(dumper, "\"         \"");
			}
			bb_dump_add(dumper, add_strings[(int)od_o2si[(p - od_opts)]]);
		} else {  /* P, p, s, w, or other unhandled */
			bb_show_usage();
		}
	}
	if (!dumper->fshead) {
		bb_dump_add(dumper, "\"%07.7_Ao\n\"");
		bb_dump_add(dumper, "\"%07.7_ao  \" 8/2 \"%06o \" \"\\n\"");
	}

	argc -= optind;
	argv += optind;

	odoffset(dumper, argc, &argv);

	return bb_dump_dump(dumper, argv);
}
Ejemplo n.º 2
0
void
oldsyntax(int argc, char ***argvp)
{
	static char empty[] = "", padding[] = PADDING;
	int ch;
	char **argv, *end;

	/* Add initial (default) address format. -A may change it later. */
#define	TYPE_OFFSET	7
	add("\"%07.7_Ao\n\"");
	add("\"%07.7_ao  \"");

	odmode = 1;
	argv = *argvp;
	while ((ch = getopt(argc, argv, "A:aBbcDdeFfHhIij:LlN:Oost:vXx")) != -1)
		switch (ch) {
		case 'A':
			switch (*optarg) {
			case 'd': case 'o': case 'x':
				fshead->nextfu->fmt[TYPE_OFFSET] = *optarg;
				fshead->nextfs->nextfu->fmt[TYPE_OFFSET] =
				    *optarg;
				break;
			case 'n':
				fshead->nextfu->fmt = empty;
				fshead->nextfs->nextfu->fmt = padding;
				break;
			default:
				errx(1, "%s: invalid address base", optarg);
			}
			break;
		case 'a':
			odformat("a");
			break;
		case 'B':
		case 'o':
			odformat("o2");
			break;
		case 'b':
			odformat("o1");
			break;
		case 'c':
			odformat("c");
			break;
		case 'd':
			odformat("u2");
			break;
		case 'D':
			odformat("u4");
			break;
		case 'e':		/* undocumented in od */
		case 'F':
			odformat("fD");
			break;
		case 'f':
			odformat("fF");
			break;
		case 'H':
		case 'X':
			odformat("x4");
			break;
		case 'h':
		case 'x':
			odformat("x2");
			break;
		case 'I':
		case 'L':
		case 'l':
			odformat("dL");
			break;
		case 'i':
			odformat("dI");
			break;
		case 'j':
			errno = 0;
			skip = strtoll(optarg, &end, 0);
			if (*end == 'b')
				skip *= 512;
			else if (*end == 'k')
				skip *= 1024;
			else if (*end == 'm')
				skip *= 1048576L;
			if (errno != 0 || skip < 0 || strlen(end) > 1)
				errx(1, "%s: invalid skip amount", optarg);
			break;
		case 'N':
			if ((length = atoi(optarg)) <= 0)
				errx(1, "%s: invalid length", optarg);
			break;
		case 'O':
			odformat("o4");
			break;
		case 's':
			odformat("d2");
			break;
		case 't':
			odformat(optarg);
			break;
		case 'v':
			vflag = ALL;
			break;
		case '?':
		default:
			odusage();
		}

	if (fshead->nextfs->nextfs == NULL)
		odformat("oS");

	argc -= optind;
	*argvp += optind;

	if (argc)
		odoffset(argc, argvp);
}
Ejemplo n.º 3
0
int od_main(int argc, char **argv)
{
	int ch;
	extern enum _vflag vflag;
	vflag = FIRST;
	length = -1;

	while ((ch = getopt(argc, argv, "aBbcDdeFfHhIiLlOoPpswvXx")) != EOF)
		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':		/* undocumented in od */
		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:
			error_msg("od: od(1) has been deprecated for hexdump(1).\n");
			if (ch != '?') {
				error_msg("od: hexdump(1) compatibility doesn't support the -%c option%s\n",
				    ch, ch == 's' ? "; see strings(1)." : ".");
			}
			show_usage();
		}

	if (!fshead) {
		add("\"%07.7_Ao\n\"");
		add("\"%07.7_ao  \" 8/2 \"%06o \" \"\\n\"");
	}

	argc -= optind;
	argv += optind;

	odoffset(argc, &argv);

	return(dump(argv));
}
Ejemplo n.º 4
0
void
oldsyntax(int argc, char ***argvp)
{
	int ch;
	char *p, **argv;

	deprecated = 1;
	argv = *argvp;
	while ((ch = getopt(argc, argv,
	    "aBbcDdeFfHhIij:LlN:OoPpst:wvXx")) != -1)
		switch (ch) {
		case 'a':
			posixtypes("a");
			break;
		case 'B':
		case 'o':
			posixtypes("o2");
			break;
		case 'b':
			posixtypes("o1");
			break;
		case 'c':
			posixtypes("c");
			break;
		case 'd':
			posixtypes("u2");
			break;
		case 'D':
			posixtypes("u4");
			break;
		case 'e':		/* undocumented in od */
		case 'F':
			posixtypes("f8");
			break;
		case 'f':
			posixtypes("f4");
			break;
		case 'H':
		case 'X':
			posixtypes("x4");
			break;
		case 'h':
		case 'x':
			posixtypes("x2");
			break;
		case 'I':
		case 'L':
		case 'l':
			posixtypes("d4");
			break;
		case 'i':
			posixtypes("d2");
			break;
		case 'j':
			if ((skip = strtol(optarg, &p, 0)) < 0)
				errx(1, "%s: bad skip value", optarg);
			switch(*p) {
			case 'b':
				skip *= 512;
				break;
			case 'k':
				skip *= 1024;
				break;
			case 'm':
				skip *= 1048576;
				break;
			}
			break;
		case 'N':
			if ((length = atoi(optarg)) < 0)
				errx(1, "%s: bad length value", optarg);
			break;
		case 'O':
			posixtypes("o4");
			break;
		case 't':
			posixtypes(optarg);
			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);
}
Ejemplo n.º 5
0
void
odsyntax(int argc, char ***argvp)
{
	static char empty[] = "", padding[] = PADDING;
	int ch;
	char *p, **argv;

#define TYPE_OFFSET 7
	add("\"%07.7_Ao\n\"");
	add("\"%07.7_ao  \"");

	odmode = 1;
	argv = *argvp;
	while ((ch = getopt(argc, argv,
	    "A:aBbcDdeFfHhIij:LlN:Oot:vXx")) != -1)
		switch (ch) {
		case 'A':
			switch (*optarg) {
			case 'd': case 'o': case 'x':
				fshead->nextfu->fmt[TYPE_OFFSET] = *optarg;
				fshead->nextfs->nextfu->fmt[TYPE_OFFSET] =
					*optarg;
				break;
			case 'n':
				fshead->nextfu->fmt = empty;
				fshead->nextfs->nextfu->fmt = padding;
				break;
			default:
				errx(1, "%s: invalid address base", optarg);
			}
			break;
		case 'a':
			posixtypes("a");
			break;
		case 'B':
		case 'o':
			posixtypes("o2");
			break;
		case 'b':
			posixtypes("o1");
			break;
		case 'c':
			posixtypes("c");
			break;
		case 'd':
			posixtypes("u2");
			break;
		case 'D':
			posixtypes("u4");
			break;
		case 'e':		/* undocumented in od */
		case 'F':
			posixtypes("f8");
			break;
		case 'f':
			posixtypes("f4");
			break;
		case 'H':
		case 'X':
			posixtypes("x4");
			break;
		case 'h':
		case 'x':
			posixtypes("x2");
			break;
		case 'I':
		case 'L':
		case 'l':
			posixtypes("d4");
			break;
		case 'i':
			posixtypes("d2");
			break;
		case 'j':
			if ((skip = strtol(optarg, &p, 0)) < 0)
				errx(1, "%s: bad skip value", optarg);
			switch(*p) {
			case 'b':
				skip *= 512;
				break;
			case 'k':
				skip *= 1024;
				break;
			case 'm':
				skip *= 1048576;
				break;
			}
			break;
		case 'N':
			if ((length = atoi(optarg)) < 0)
				errx(1, "%s: bad length value", optarg);
			break;
		case 'O':
			posixtypes("o4");
			break;
		case 't':
			posixtypes(optarg);
			break;
		case 'v':
			vflag = ALL;
			break;
		case '?':
		default:
			usage();
		}

	if (fshead->nextfs->nextfs == NULL)
		posixtypes("oS");

	argc -= optind;
	*argvp += optind;

	if (argc)
		odoffset(argc, argvp);
}
Ejemplo n.º 6
0
void
oldsyntax(int argc, char ***argvp)
{
	static char empty[] = "", padding[] = PADDING;
	int ch;
	char *p, **argv;

#define	TYPE_OFFSET	7
	add("\"%07.7_Ao\n\"");
	add("\"%07.7_ao  \"");

	deprecated = 1;
	argv = *argvp;
	while ((ch = getopt(argc, argv,
	    "A:aBbcDdeFfHhIij:LlN:OoPpst:wvXx")) != -1)
		switch (ch) {
		case 'A':
			switch (*optarg) {
			case 'd': case 'o': case 'x':
				fshead->nextfu->fmt[TYPE_OFFSET] = *optarg;
				fshead->nextfs->nextfu->fmt[TYPE_OFFSET] =
				    *optarg;
				break;
			case 'n':
				fshead->nextfu->fmt = empty;
				fshead->nextfs->nextfu->fmt = padding;
				break;
			default:
				errx(1, "%s: invalid address base", optarg);
			}
			break;
		case 'a':
			odadd("16/1 \"%3_u \" \"\\n\"");
			break;
		case 'B':
		case 'o':
			odadd("8/2 \" %06o \" \"\\n\"");
			break;
		case 'b':
			odadd("16/1 \"%03o \" \"\\n\"");
			break;
		case 'c':
			odadd("16/1 \"%3_c \" \"\\n\"");
			break;
		case 'd':
			odadd("8/2 \"  %05u \" \"\\n\"");
			break;
		case 'D':
			odadd("4/4 \"     %010u \" \"\\n\"");
			break;
		case 'e':
		case 'F':
			odadd("2/8 \"          %21.14e \" \"\\n\"");
			break;
		case 'f':
			odadd("4/4 \" %14.7e \" \"\\n\"");
			break;
		case 'H':
		case 'X':
			odadd("4/4 \"       %08x \" \"\\n\"");
			break;
		case 'h':
		case 'x':
			odadd("8/2 \"   %04x \" \"\\n\"");
			break;
		case 'I':
		case 'L':
		case 'l':
			odadd("4/4 \"    %11d \" \"\\n\"");
			break;
		case 'i':
			odadd("8/2 \" %6d \" \"\\n\"");
			break;
		case 'j':
			if ((skip = strtol(optarg, &p, 0)) < 0)
				errx(1, "%s: bad skip value", optarg);
			switch(*p) {
			case 'b':
				skip *= 512;
				break;
			case 'k':
				skip *= 1024;
				break;
			case 'm':
				skip *= 1048576;
				break;
			}
			break;
		case 'N':
			if ((length = atoi(optarg)) < 0)
				errx(1, "%s: bad length value", optarg);
			break;
		case 'O':
			odadd("4/4 \"    %011o \" \"\\n\"");
			break;
		case 't':
			posixtypes(optarg);
			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",
				    ch, ch == 's' ? "; see strings(1)." : ".");
			oldusage();
		}

	if (fshead->nextfs->nextfs == NULL)
		odadd(" 8/2 \"%06o \" \"\\n\"");

	argc -= optind;
	*argvp += optind;

	if (argc)
		odoffset(argc, argvp);
}