Changeset View
Changeset View
Standalone View
Standalone View
head/bin/dd/args.c
Show First 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | |||||
#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_iflag(const void *, const void *); | |||||
static int c_oflag(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_iflag(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_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 }, | ||||
{ "iflag", f_iflag, 0, 0 }, | |||||
{ "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 }, | { "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 }, | ||||
▲ Show 20 Lines • Show All 154 Lines • ▼ Show 20 Lines | |||||
static void | static void | ||||
f_if(char *arg) | f_if(char *arg) | ||||
{ | { | ||||
in.name = arg; | in.name = arg; | ||||
} | } | ||||
static const struct iflag { | |||||
const char *name; | |||||
uint64_t set, noset; | |||||
} ilist[] = { | |||||
{ "fullblock", C_IFULLBLOCK, C_SYNC }, | |||||
}; | |||||
static void | static void | ||||
f_iflag(char *arg) | |||||
{ | |||||
struct iflag *ip, tmp; | |||||
while (arg != NULL) { | |||||
tmp.name = strsep(&arg, ","); | |||||
ip = bsearch(&tmp, ilist, nitems(ilist), sizeof(struct iflag), | |||||
c_iflag); | |||||
if (ip == NULL) | |||||
errx(1, "unknown iflag %s", tmp.name); | |||||
if (ddflags & ip->noset) | |||||
errx(1, "%s: illegal conversion combination", tmp.name); | |||||
ddflags |= ip->set; | |||||
} | |||||
} | |||||
static int | |||||
c_iflag(const void *a, const void *b) | |||||
{ | |||||
return (strcmp(((const struct iflag *)a)->name, | |||||
((const struct iflag *)b)->name)); | |||||
} | |||||
static void | |||||
f_obs(char *arg) | f_obs(char *arg) | ||||
{ | { | ||||
uintmax_t res; | uintmax_t res; | ||||
if (!(ddflags & C_BS)) { | if (!(ddflags & C_BS)) { | ||||
res = get_num(arg); | res = get_num(arg); | ||||
if (res < 1 || res > SSIZE_MAX) | if (res < 1 || res > SSIZE_MAX) | ||||
errx(1, "obs must be between 1 and %zd", | errx(1, "obs must be between 1 and %zd", | ||||
▲ Show 20 Lines • Show All 63 Lines • ▼ Show 20 Lines | static const struct conv { | ||||
{ "oldibm", C_EBCDIC, C_ASCII, a2ibm_32V }, | { "oldibm", C_EBCDIC, C_ASCII, a2ibm_32V }, | ||||
{ "osync", C_OSYNC, C_BS, NULL }, | { "osync", C_OSYNC, C_BS, NULL }, | ||||
{ "pareven", C_PAREVEN, C_PARODD|C_PARSET|C_PARNONE, NULL}, | { "pareven", C_PAREVEN, C_PARODD|C_PARSET|C_PARNONE, NULL}, | ||||
{ "parnone", C_PARNONE, C_PARODD|C_PARSET|C_PAREVEN, NULL}, | { "parnone", C_PARNONE, C_PARODD|C_PARSET|C_PAREVEN, NULL}, | ||||
{ "parodd", C_PARODD, C_PAREVEN|C_PARSET|C_PARNONE, NULL}, | { "parodd", C_PARODD, C_PAREVEN|C_PARSET|C_PARNONE, NULL}, | ||||
{ "parset", C_PARSET, C_PARODD|C_PAREVEN|C_PARNONE, NULL}, | { "parset", C_PARSET, C_PARODD|C_PAREVEN|C_PARNONE, NULL}, | ||||
{ "sparse", C_SPARSE, 0, NULL }, | { "sparse", C_SPARSE, 0, NULL }, | ||||
{ "swab", C_SWAB, 0, NULL }, | { "swab", C_SWAB, 0, NULL }, | ||||
{ "sync", C_SYNC, 0, NULL }, | { "sync", C_SYNC, C_IFULLBLOCK, NULL }, | ||||
{ "ucase", C_UCASE, C_LCASE, NULL }, | { "ucase", C_UCASE, C_LCASE, NULL }, | ||||
{ "unblock", C_UNBLOCK, C_BLOCK, NULL }, | { "unblock", C_UNBLOCK, C_BLOCK, NULL }, | ||||
}; | }; | ||||
static void | static void | ||||
f_conv(char *arg) | f_conv(char *arg) | ||||
{ | { | ||||
struct conv *cp, tmp; | struct conv *cp, tmp; | ||||
▲ Show 20 Lines • Show All 199 Lines • Show Last 20 Lines |