Changeset View
Changeset View
Standalone View
Standalone View
bin/dd/args.c
Show All 35 Lines | |||||
#ifndef lint | #ifndef lint | ||||
#if 0 | #if 0 | ||||
static char sccsid[] = "@(#)args.c 8.3 (Berkeley) 4/2/94"; | static char sccsid[] = "@(#)args.c 8.3 (Berkeley) 4/2/94"; | ||||
#endif | #endif | ||||
#endif /* not lint */ | #endif /* not lint */ | ||||
#include <sys/cdefs.h> | #include <sys/cdefs.h> | ||||
__FBSDID("$FreeBSD$"); | __FBSDID("$FreeBSD$"); | ||||
#include <sys/types.h> | #include <sys/param.h> | ||||
#include <ctype.h> | #include <ctype.h> | ||||
#include <err.h> | #include <err.h> | ||||
#include <errno.h> | #include <errno.h> | ||||
#include <inttypes.h> | #include <inttypes.h> | ||||
#include <limits.h> | #include <limits.h> | ||||
#include <signal.h> | #include <signal.h> | ||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#include <string.h> | #include <string.h> | ||||
#include "dd.h" | #include "dd.h" | ||||
#include "extern.h" | #include "extern.h" | ||||
static int c_arg(const void *, const void *); | static int c_arg(const void *, const void *); | ||||
static int c_conv(const void *, const void *); | static int c_conv(const void *, const void *); | ||||
static int c_oflag(const void *, const void *); | |||||
static void f_bs(char *); | static void f_bs(char *); | ||||
static void f_cbs(char *); | static void f_cbs(char *); | ||||
static void f_conv(char *); | static void f_conv(char *); | ||||
static void f_count(char *); | static void f_count(char *); | ||||
static void f_files(char *); | static void f_files(char *); | ||||
static void f_fillchar(char *); | static void f_fillchar(char *); | ||||
static void f_ibs(char *); | static void f_ibs(char *); | ||||
static void f_if(char *); | static void f_if(char *); | ||||
static void f_obs(char *); | static void f_obs(char *); | ||||
static void f_of(char *); | static void f_of(char *); | ||||
static void f_oflag(char *); | |||||
static void f_seek(char *); | static void f_seek(char *); | ||||
static void f_skip(char *); | static void f_skip(char *); | ||||
static void f_speed(char *); | static void f_speed(char *); | ||||
static void f_status(char *); | static void f_status(char *); | ||||
static uintmax_t get_num(const char *); | static uintmax_t get_num(const char *); | ||||
static off_t get_off_t(const char *); | static off_t get_off_t(const char *); | ||||
static const struct arg { | static const struct arg { | ||||
const char *name; | const char *name; | ||||
void (*f)(char *); | void (*f)(char *); | ||||
uint64_t set, noset; | uint64_t set, noset; | ||||
} args[] = { | } args[] = { | ||||
{ "bs", f_bs, C_BS, C_BS|C_IBS|C_OBS|C_OSYNC }, | { "bs", f_bs, C_BS, C_BS|C_IBS|C_OBS|C_OSYNC }, | ||||
{ "cbs", f_cbs, C_CBS, C_CBS }, | { "cbs", f_cbs, C_CBS, C_CBS }, | ||||
{ "conv", f_conv, 0, 0 }, | { "conv", f_conv, 0, 0 }, | ||||
{ "count", f_count, C_COUNT, C_COUNT }, | { "count", f_count, C_COUNT, C_COUNT }, | ||||
{ "files", f_files, C_FILES, C_FILES }, | { "files", f_files, C_FILES, C_FILES }, | ||||
{ "fillchar", f_fillchar, C_FILL, C_FILL }, | { "fillchar", f_fillchar, C_FILL, C_FILL }, | ||||
{ "ibs", f_ibs, C_IBS, C_BS|C_IBS }, | { "ibs", f_ibs, C_IBS, C_BS|C_IBS }, | ||||
{ "if", f_if, C_IF, C_IF }, | { "if", f_if, C_IF, C_IF }, | ||||
{ "iseek", f_skip, C_SKIP, C_SKIP }, | { "iseek", f_skip, C_SKIP, C_SKIP }, | ||||
{ "obs", f_obs, C_OBS, C_BS|C_OBS }, | { "obs", f_obs, C_OBS, C_BS|C_OBS }, | ||||
{ "of", f_of, C_OF, C_OF }, | { "of", f_of, C_OF, C_OF }, | ||||
{ "oflag", f_oflag, 0, 0 }, | |||||
{ "oseek", f_seek, C_SEEK, C_SEEK }, | { "oseek", f_seek, C_SEEK, C_SEEK }, | ||||
{ "seek", f_seek, C_SEEK, C_SEEK }, | { "seek", f_seek, C_SEEK, C_SEEK }, | ||||
{ "skip", f_skip, C_SKIP, C_SKIP }, | { "skip", f_skip, C_SKIP, C_SKIP }, | ||||
{ "speed", f_speed, 0, 0 }, | { "speed", f_speed, 0, 0 }, | ||||
{ "status", f_status, C_STATUS,C_STATUS }, | { "status", f_status, C_STATUS,C_STATUS }, | ||||
}; | }; | ||||
static char *oper; | static char *oper; | ||||
▲ Show 20 Lines • Show All 242 Lines • ▼ Show 20 Lines | |||||
static void | static void | ||||
f_conv(char *arg) | f_conv(char *arg) | ||||
{ | { | ||||
struct conv *cp, tmp; | struct conv *cp, tmp; | ||||
while (arg != NULL) { | while (arg != NULL) { | ||||
tmp.name = strsep(&arg, ","); | tmp.name = strsep(&arg, ","); | ||||
cp = bsearch(&tmp, clist, sizeof(clist) / sizeof(struct conv), | cp = bsearch(&tmp, clist, nitems(clist), sizeof(struct conv), | ||||
sizeof(struct conv), c_conv); | c_conv); | ||||
if (cp == NULL) | if (cp == NULL) | ||||
errx(1, "unknown conversion %s", tmp.name); | errx(1, "unknown conversion %s", tmp.name); | ||||
if (ddflags & cp->noset) | if (ddflags & cp->noset) | ||||
errx(1, "%s: illegal conversion combination", tmp.name); | errx(1, "%s: illegal conversion combination", tmp.name); | ||||
ddflags |= cp->set; | ddflags |= cp->set; | ||||
if (cp->ctab) | if (cp->ctab) | ||||
ctab = cp->ctab; | ctab = cp->ctab; | ||||
} | } | ||||
} | } | ||||
static int | static int | ||||
c_conv(const void *a, const void *b) | c_conv(const void *a, const void *b) | ||||
{ | { | ||||
return (strcmp(((const struct conv *)a)->name, | return (strcmp(((const struct conv *)a)->name, | ||||
((const struct conv *)b)->name)); | ((const struct conv *)b)->name)); | ||||
} | |||||
static const struct oflag { | |||||
const char *name; | |||||
uint64_t set; | |||||
} olist[] = { | |||||
{ "fsync", C_OFSYNC }, | |||||
{ "sync", C_OFSYNC }, | |||||
}; | |||||
static void | |||||
f_oflag(char *arg) | |||||
{ | |||||
struct oflag *op, tmp; | |||||
while (arg != NULL) { | |||||
tmp.name = strsep(&arg, ","); | |||||
op = bsearch(&tmp, olist, nitems(olist), sizeof(struct oflag), | |||||
c_oflag); | |||||
if (op == NULL) | |||||
errx(1, "unknown open flag %s", tmp.name); | |||||
ddflags |= op->set; | |||||
} | |||||
} | |||||
static int | |||||
c_oflag(const void *a, const void *b) | |||||
{ | |||||
return (strcmp(((const struct oflag *)a)->name, | |||||
((const struct oflag *)b)->name)); | |||||
} | } | ||||
static intmax_t | static intmax_t | ||||
postfix_to_mult(const char expr) | postfix_to_mult(const char expr) | ||||
{ | { | ||||
intmax_t mult; | intmax_t mult; | ||||
mult = 0; | mult = 0; | ||||
▲ Show 20 Lines • Show All 139 Lines • Show Last 20 Lines |