2010-12-22 12:42:53 +03:00
|
|
|
/* $NetBSD: args.c,v 1.32 2010/12/22 09:42:53 enami Exp $ */
|
1995-03-21 12:01:59 +03:00
|
|
|
|
1993-05-04 11:08:38 +04:00
|
|
|
/*-
|
1994-09-22 13:24:46 +04:00
|
|
|
* Copyright (c) 1991, 1993, 1994
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
1993-05-04 11:08:38 +04:00
|
|
|
*
|
|
|
|
* This code is derived from software contributed to Berkeley by
|
|
|
|
* Keith Muller of the University of California, San Diego and Lance
|
|
|
|
* Visser of Convex Computer Corporation.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2003-08-07 13:05:01 +04:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
1993-05-04 11:08:38 +04:00
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
1997-07-21 01:58:35 +04:00
|
|
|
#include <sys/cdefs.h>
|
1993-05-04 11:08:38 +04:00
|
|
|
#ifndef lint
|
1995-03-21 12:01:59 +03:00
|
|
|
#if 0
|
|
|
|
static char sccsid[] = "@(#)args.c 8.3 (Berkeley) 4/2/94";
|
|
|
|
#else
|
2010-12-22 12:42:53 +03:00
|
|
|
__RCSID("$NetBSD: args.c,v 1.32 2010/12/22 09:42:53 enami Exp $");
|
1995-03-21 12:01:59 +03:00
|
|
|
#endif
|
1993-05-04 11:08:38 +04:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
2001-04-29 02:47:23 +04:00
|
|
|
#include <sys/time.h>
|
1994-09-22 13:24:46 +04:00
|
|
|
|
|
|
|
#include <err.h>
|
1993-05-04 11:08:38 +04:00
|
|
|
#include <errno.h>
|
1994-09-22 13:24:46 +04:00
|
|
|
#include <limits.h>
|
1993-05-04 11:08:38 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
1994-09-22 13:24:46 +04:00
|
|
|
|
1993-05-04 11:08:38 +04:00
|
|
|
#include "dd.h"
|
|
|
|
#include "extern.h"
|
|
|
|
|
2010-12-14 22:03:21 +03:00
|
|
|
#if !defined(SMALL) && defined(__NetBSD__)
|
|
|
|
#define _HAVE_RUMPOPS
|
|
|
|
|
2010-11-23 00:04:27 +03:00
|
|
|
#include <rump/rumpclient.h>
|
|
|
|
#endif
|
|
|
|
|
2001-11-25 09:53:48 +03:00
|
|
|
static int c_arg(const void *, const void *);
|
2001-11-25 09:57:55 +03:00
|
|
|
#ifndef NO_CONV
|
2001-11-25 09:53:48 +03:00
|
|
|
static int c_conv(const void *, const void *);
|
2001-11-25 09:57:55 +03:00
|
|
|
#endif
|
2001-11-25 09:53:48 +03:00
|
|
|
static void f_bs(char *);
|
|
|
|
static void f_cbs(char *);
|
|
|
|
static void f_conv(char *);
|
|
|
|
static void f_count(char *);
|
|
|
|
static void f_files(char *);
|
|
|
|
static void f_ibs(char *);
|
|
|
|
static void f_if(char *);
|
|
|
|
static void f_obs(char *);
|
|
|
|
static void f_of(char *);
|
|
|
|
static void f_seek(char *);
|
|
|
|
static void f_skip(char *);
|
|
|
|
static void f_progress(char *);
|
1993-05-04 11:08:38 +04:00
|
|
|
|
2010-12-14 22:03:21 +03:00
|
|
|
#ifdef _HAVE_RUMPOPS
|
2010-11-23 00:04:27 +03:00
|
|
|
static void f_rif(char *);
|
|
|
|
static void f_rof(char *);
|
|
|
|
#endif
|
|
|
|
|
1998-07-09 22:06:17 +04:00
|
|
|
static const struct arg {
|
2001-11-25 09:53:48 +03:00
|
|
|
const char *name;
|
|
|
|
void (*f)(char *);
|
1993-05-04 11:08:38 +04:00
|
|
|
u_int set, noset;
|
|
|
|
} args[] = {
|
1999-07-29 23:03:31 +04:00
|
|
|
/* the array needs to be sorted by the first column so
|
2001-11-26 03:56:33 +03:00
|
|
|
bsearch() can be used to find commands quickly */
|
1994-09-22 13:24:46 +04:00
|
|
|
{ "bs", f_bs, C_BS, C_BS|C_IBS|C_OBS|C_OSYNC },
|
|
|
|
{ "cbs", f_cbs, C_CBS, C_CBS },
|
|
|
|
{ "conv", f_conv, 0, 0 },
|
|
|
|
{ "count", f_count, C_COUNT, C_COUNT },
|
|
|
|
{ "files", f_files, C_FILES, C_FILES },
|
|
|
|
{ "ibs", f_ibs, C_IBS, C_BS|C_IBS },
|
2010-11-23 00:04:27 +03:00
|
|
|
{ "if", f_if, C_IF, C_IF|C_RIF },
|
2010-12-22 12:42:53 +03:00
|
|
|
{ "iseek", f_skip, C_SKIP, C_SKIP },
|
1994-09-22 13:24:46 +04:00
|
|
|
{ "obs", f_obs, C_OBS, C_BS|C_OBS },
|
2010-11-23 00:04:27 +03:00
|
|
|
{ "of", f_of, C_OF, C_OF|C_ROF },
|
2010-12-22 12:42:53 +03:00
|
|
|
{ "oseek", f_seek, C_SEEK, C_SEEK },
|
1999-07-29 23:03:31 +04:00
|
|
|
{ "progress", f_progress, 0, 0 },
|
2010-12-14 22:03:21 +03:00
|
|
|
#ifdef _HAVE_RUMPOPS
|
2010-11-23 00:04:27 +03:00
|
|
|
{ "rif", f_rif, C_RIF|C_RUMP, C_RIF|C_IF },
|
2010-12-06 02:35:59 +03:00
|
|
|
{ "rof", f_rof, C_ROF|C_RUMP, C_ROF|C_OF },
|
2010-11-23 00:04:27 +03:00
|
|
|
#endif
|
1994-09-22 13:24:46 +04:00
|
|
|
{ "seek", f_seek, C_SEEK, C_SEEK },
|
|
|
|
{ "skip", f_skip, C_SKIP, C_SKIP },
|
1993-05-04 11:08:38 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* args -- parse JCL syntax of dd.
|
|
|
|
*/
|
|
|
|
void
|
2001-11-25 09:53:48 +03:00
|
|
|
jcl(char **argv)
|
1993-05-04 11:08:38 +04:00
|
|
|
{
|
1994-09-22 13:24:46 +04:00
|
|
|
struct arg *ap, tmp;
|
- Use u_longlong_t instead of u_quad_t, u_long, or int for various buffer sizes
- Add strsuftoull(), which parses a number into a u_longlong_t, with
multiplication support, and support for 'g' (GB) and 't' (TB) suffices.
If an error occurs, print to stderr and exit.
Based on get_blk() from args.c and strsufto*() (in other programs)
- Add strsuftoullx(), which acts as per strsuftoull() but returns the
error in the supplied buffer instead (if the returned buffer != "", an
error occurred)
- Replace get_bsz() use with strsuftoull()
- Remove (now) unnecessary argument validation
- Remove unused {f,p,s,t}_stats fields in struct IO
2001-11-25 13:50:06 +03:00
|
|
|
char *oper, *arg;
|
1993-05-04 11:08:38 +04:00
|
|
|
|
|
|
|
in.dbsz = out.dbsz = 512;
|
|
|
|
|
1997-07-21 01:58:35 +04:00
|
|
|
while ((oper = *++argv) != NULL) {
|
2010-12-22 12:39:06 +03:00
|
|
|
if ((oper = strdup(oper)) == NULL) {
|
|
|
|
errx(EXIT_FAILURE,
|
|
|
|
"unable to allocate space for the argument %s",
|
|
|
|
*argv);
|
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
2003-08-05 02:31:21 +04:00
|
|
|
if ((arg = strchr(oper, '=')) == NULL) {
|
|
|
|
errx(EXIT_FAILURE, "unknown operand %s", oper);
|
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
1993-05-04 11:08:38 +04:00
|
|
|
*arg++ = '\0';
|
2003-08-05 02:31:21 +04:00
|
|
|
if (!*arg) {
|
|
|
|
errx(EXIT_FAILURE, "no value specified for %s", oper);
|
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
1993-05-04 11:08:38 +04:00
|
|
|
tmp.name = oper;
|
|
|
|
if (!(ap = (struct arg *)bsearch(&tmp, args,
|
|
|
|
sizeof(args)/sizeof(struct arg), sizeof(struct arg),
|
2003-08-05 02:31:21 +04:00
|
|
|
c_arg))) {
|
|
|
|
errx(EXIT_FAILURE, "unknown operand %s", tmp.name);
|
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
|
|
|
if (ddflags & ap->noset) {
|
|
|
|
errx(EXIT_FAILURE,
|
2001-11-25 09:53:48 +03:00
|
|
|
"%s: illegal argument combination or already set",
|
1993-05-04 11:08:38 +04:00
|
|
|
tmp.name);
|
2003-08-05 02:31:21 +04:00
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
1993-05-04 11:08:38 +04:00
|
|
|
ddflags |= ap->set;
|
|
|
|
ap->f(arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Final sanity checks. */
|
|
|
|
|
|
|
|
if (ddflags & C_BS) {
|
|
|
|
/*
|
|
|
|
* Bs is turned off by any conversion -- we assume the user
|
|
|
|
* just wanted to set both the input and output block sizes
|
|
|
|
* and didn't want the bs semantics, so we don't warn.
|
|
|
|
*/
|
2004-01-17 08:42:50 +03:00
|
|
|
if (ddflags & (C_BLOCK | C_LCASE | C_SWAB | C_UCASE |
|
2004-01-17 23:48:57 +03:00
|
|
|
C_UNBLOCK | C_OSYNC | C_ASCII | C_EBCDIC | C_SPARSE)) {
|
1993-05-04 11:08:38 +04:00
|
|
|
ddflags &= ~C_BS;
|
2004-01-17 08:42:50 +03:00
|
|
|
ddflags |= C_IBS|C_OBS;
|
|
|
|
}
|
1993-05-04 11:08:38 +04:00
|
|
|
|
|
|
|
/* Bs supersedes ibs and obs. */
|
|
|
|
if (ddflags & C_BS && ddflags & (C_IBS|C_OBS))
|
1994-09-22 13:24:46 +04:00
|
|
|
warnx("bs supersedes ibs and obs");
|
1993-05-04 11:08:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Ascii/ebcdic and cbs implies block/unblock.
|
|
|
|
* Block/unblock requires cbs and vice-versa.
|
|
|
|
*/
|
|
|
|
if (ddflags & (C_BLOCK|C_UNBLOCK)) {
|
2003-08-05 02:31:21 +04:00
|
|
|
if (!(ddflags & C_CBS)) {
|
|
|
|
errx(EXIT_FAILURE, "record operations require cbs");
|
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
1993-05-04 11:08:38 +04:00
|
|
|
cfunc = ddflags & C_BLOCK ? block : unblock;
|
|
|
|
} else if (ddflags & C_CBS) {
|
|
|
|
if (ddflags & (C_ASCII|C_EBCDIC)) {
|
|
|
|
if (ddflags & C_ASCII) {
|
|
|
|
ddflags |= C_UNBLOCK;
|
|
|
|
cfunc = unblock;
|
|
|
|
} else {
|
|
|
|
ddflags |= C_BLOCK;
|
|
|
|
cfunc = block;
|
|
|
|
}
|
2003-08-05 02:31:21 +04:00
|
|
|
} else {
|
|
|
|
errx(EXIT_FAILURE,
|
2001-11-25 09:53:48 +03:00
|
|
|
"cbs meaningless if not doing record operations");
|
2003-08-05 02:31:21 +04:00
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
1993-05-04 11:08:38 +04:00
|
|
|
} else
|
|
|
|
cfunc = def;
|
|
|
|
|
2001-11-26 03:56:33 +03:00
|
|
|
/* Read, write and seek calls take off_t as arguments.
|
1997-07-25 10:46:23 +04:00
|
|
|
*
|
|
|
|
* The following check is not done because an off_t is a quad
|
2001-11-26 03:56:33 +03:00
|
|
|
* for current NetBSD implementations.
|
1997-07-25 10:46:23 +04:00
|
|
|
*
|
|
|
|
* if (in.offset > INT_MAX/in.dbsz || out.offset > INT_MAX/out.dbsz)
|
|
|
|
* errx(1, "seek offsets cannot be larger than %d", INT_MAX);
|
|
|
|
*/
|
2010-11-23 00:04:27 +03:00
|
|
|
|
2010-12-14 22:03:21 +03:00
|
|
|
#ifdef _HAVE_RUMPOPS
|
2010-11-23 00:04:27 +03:00
|
|
|
if (ddflags & C_RUMP)
|
|
|
|
if (rumpclient_init() == -1)
|
|
|
|
err(1, "rumpclient init failed");
|
|
|
|
#endif
|
1993-05-04 11:08:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2001-11-25 09:53:48 +03:00
|
|
|
c_arg(const void *a, const void *b)
|
1993-05-04 11:08:38 +04:00
|
|
|
{
|
2001-11-25 09:53:48 +03:00
|
|
|
|
1998-07-28 07:47:14 +04:00
|
|
|
return (strcmp(((const struct arg *)a)->name,
|
|
|
|
((const struct arg *)b)->name));
|
1993-05-04 11:08:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-11-25 09:53:48 +03:00
|
|
|
f_bs(char *arg)
|
1993-05-04 11:08:38 +04:00
|
|
|
{
|
2001-11-25 09:53:48 +03:00
|
|
|
|
2002-11-29 16:11:10 +03:00
|
|
|
in.dbsz = out.dbsz = strsuftoll("block size", arg, 1, UINT_MAX);
|
1993-05-04 11:08:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-11-25 09:53:48 +03:00
|
|
|
f_cbs(char *arg)
|
1993-05-04 11:08:38 +04:00
|
|
|
{
|
2001-11-25 09:53:48 +03:00
|
|
|
|
2002-11-29 16:11:10 +03:00
|
|
|
cbsz = strsuftoll("conversion record size", arg, 1, UINT_MAX);
|
1993-05-04 11:08:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-11-25 09:53:48 +03:00
|
|
|
f_count(char *arg)
|
1993-05-04 11:08:38 +04:00
|
|
|
{
|
2001-11-25 09:53:48 +03:00
|
|
|
|
2002-11-29 16:11:10 +03:00
|
|
|
cpy_cnt = strsuftoll("block count", arg, 0, LLONG_MAX);
|
1993-05-04 11:08:38 +04:00
|
|
|
if (!cpy_cnt)
|
|
|
|
terminate(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-11-25 09:53:48 +03:00
|
|
|
f_files(char *arg)
|
1993-05-04 11:08:38 +04:00
|
|
|
{
|
2001-11-25 09:53:48 +03:00
|
|
|
|
2002-11-29 16:11:10 +03:00
|
|
|
files_cnt = (u_int)strsuftoll("file count", arg, 0, UINT_MAX);
|
- Use u_longlong_t instead of u_quad_t, u_long, or int for various buffer sizes
- Add strsuftoull(), which parses a number into a u_longlong_t, with
multiplication support, and support for 'g' (GB) and 't' (TB) suffices.
If an error occurs, print to stderr and exit.
Based on get_blk() from args.c and strsufto*() (in other programs)
- Add strsuftoullx(), which acts as per strsuftoull() but returns the
error in the supplied buffer instead (if the returned buffer != "", an
error occurred)
- Replace get_bsz() use with strsuftoull()
- Remove (now) unnecessary argument validation
- Remove unused {f,p,s,t}_stats fields in struct IO
2001-11-25 13:50:06 +03:00
|
|
|
if (!files_cnt)
|
|
|
|
terminate(0);
|
1993-05-04 11:08:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-11-25 09:53:48 +03:00
|
|
|
f_ibs(char *arg)
|
1993-05-04 11:08:38 +04:00
|
|
|
{
|
2001-11-25 09:53:48 +03:00
|
|
|
|
1993-05-04 11:08:38 +04:00
|
|
|
if (!(ddflags & C_BS))
|
2002-11-29 16:11:10 +03:00
|
|
|
in.dbsz = strsuftoll("input block size", arg, 1, UINT_MAX);
|
1993-05-04 11:08:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-11-25 09:53:48 +03:00
|
|
|
f_if(char *arg)
|
1993-05-04 11:08:38 +04:00
|
|
|
{
|
2001-11-25 09:53:48 +03:00
|
|
|
|
1993-05-04 11:08:38 +04:00
|
|
|
in.name = arg;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-11-25 09:53:48 +03:00
|
|
|
f_obs(char *arg)
|
1993-05-04 11:08:38 +04:00
|
|
|
{
|
2001-11-25 09:53:48 +03:00
|
|
|
|
1993-05-04 11:08:38 +04:00
|
|
|
if (!(ddflags & C_BS))
|
2002-11-29 16:11:10 +03:00
|
|
|
out.dbsz = strsuftoll("output block size", arg, 1, UINT_MAX);
|
1993-05-04 11:08:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-11-25 09:53:48 +03:00
|
|
|
f_of(char *arg)
|
1993-05-04 11:08:38 +04:00
|
|
|
{
|
2001-11-25 09:53:48 +03:00
|
|
|
|
1993-05-04 11:08:38 +04:00
|
|
|
out.name = arg;
|
|
|
|
}
|
|
|
|
|
2010-12-14 22:03:21 +03:00
|
|
|
#ifdef _HAVE_RUMPOPS
|
2010-11-23 00:04:27 +03:00
|
|
|
#include <rump/rump.h>
|
|
|
|
#include <rump/rump_syscalls.h>
|
|
|
|
|
|
|
|
static const struct ddfops ddfops_rump = {
|
|
|
|
.op_open = rump_sys_open,
|
|
|
|
.op_close = rump_sys_close,
|
|
|
|
.op_fcntl = rump_sys_fcntl,
|
|
|
|
.op_ioctl = rump_sys_ioctl,
|
|
|
|
.op_fstat = rump_sys_fstat,
|
|
|
|
.op_fsync = rump_sys_fsync,
|
|
|
|
.op_ftruncate = rump_sys_ftruncate,
|
|
|
|
.op_lseek = rump_sys_lseek,
|
|
|
|
.op_read = rump_sys_read,
|
|
|
|
.op_write = rump_sys_write,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
f_rif(char *arg)
|
|
|
|
{
|
|
|
|
|
|
|
|
in.name = arg;
|
|
|
|
in.ops = &ddfops_rump;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
f_rof(char *arg)
|
|
|
|
{
|
|
|
|
|
|
|
|
out.name = arg;
|
|
|
|
out.ops = &ddfops_rump;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1993-05-04 11:08:38 +04:00
|
|
|
static void
|
2001-11-25 09:53:48 +03:00
|
|
|
f_seek(char *arg)
|
1993-05-04 11:08:38 +04:00
|
|
|
{
|
2001-11-25 09:53:48 +03:00
|
|
|
|
2002-11-29 16:11:10 +03:00
|
|
|
out.offset = strsuftoll("seek blocks", arg, 0, LLONG_MAX);
|
1993-05-04 11:08:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-11-25 09:53:48 +03:00
|
|
|
f_skip(char *arg)
|
1993-05-04 11:08:38 +04:00
|
|
|
{
|
2001-11-25 09:53:48 +03:00
|
|
|
|
2002-11-29 16:11:10 +03:00
|
|
|
in.offset = strsuftoll("skip blocks", arg, 0, LLONG_MAX);
|
1993-05-04 11:08:38 +04:00
|
|
|
}
|
|
|
|
|
1999-07-29 23:03:31 +04:00
|
|
|
static void
|
2001-11-25 09:53:48 +03:00
|
|
|
f_progress(char *arg)
|
1999-07-29 23:03:31 +04:00
|
|
|
{
|
2001-11-25 09:53:48 +03:00
|
|
|
|
2006-01-09 13:17:05 +03:00
|
|
|
progress = strsuftoll("progress blocks", arg, 0, LLONG_MAX);
|
1999-07-29 23:03:31 +04:00
|
|
|
}
|
|
|
|
|
1995-10-09 02:01:22 +03:00
|
|
|
#ifdef NO_CONV
|
|
|
|
/* Build a small version (i.e. for a ramdisk root) */
|
|
|
|
static void
|
2001-11-25 09:53:48 +03:00
|
|
|
f_conv(char *arg)
|
1995-10-09 02:01:22 +03:00
|
|
|
{
|
2001-11-25 09:53:48 +03:00
|
|
|
|
2003-08-05 02:31:21 +04:00
|
|
|
errx(EXIT_FAILURE, "conv option disabled");
|
|
|
|
/* NOTREACHED */
|
1995-10-09 02:01:22 +03:00
|
|
|
}
|
|
|
|
#else /* NO_CONV */
|
|
|
|
|
1998-07-09 22:06:17 +04:00
|
|
|
static const struct conv {
|
2001-11-25 09:53:48 +03:00
|
|
|
const char *name;
|
1993-05-04 11:08:38 +04:00
|
|
|
u_int set, noset;
|
1996-02-20 22:29:01 +03:00
|
|
|
const u_char *ctab;
|
1993-05-04 11:08:38 +04:00
|
|
|
} clist[] = {
|
1994-09-22 13:24:46 +04:00
|
|
|
{ "ascii", C_ASCII, C_EBCDIC, e2a_POSIX },
|
|
|
|
{ "block", C_BLOCK, C_UNBLOCK, NULL },
|
|
|
|
{ "ebcdic", C_EBCDIC, C_ASCII, a2e_POSIX },
|
|
|
|
{ "ibm", C_EBCDIC, C_ASCII, a2ibm_POSIX },
|
|
|
|
{ "lcase", C_LCASE, C_UCASE, NULL },
|
|
|
|
{ "noerror", C_NOERROR, 0, NULL },
|
|
|
|
{ "notrunc", C_NOTRUNC, 0, NULL },
|
|
|
|
{ "oldascii", C_ASCII, C_EBCDIC, e2a_32V },
|
|
|
|
{ "oldebcdic", C_EBCDIC, C_ASCII, a2e_32V },
|
|
|
|
{ "oldibm", C_EBCDIC, C_ASCII, a2ibm_32V },
|
|
|
|
{ "osync", C_OSYNC, C_BS, NULL },
|
2004-01-17 23:48:57 +03:00
|
|
|
{ "sparse", C_SPARSE, 0, NULL },
|
1994-09-22 13:24:46 +04:00
|
|
|
{ "swab", C_SWAB, 0, NULL },
|
|
|
|
{ "sync", C_SYNC, 0, NULL },
|
|
|
|
{ "ucase", C_UCASE, C_LCASE, NULL },
|
|
|
|
{ "unblock", C_UNBLOCK, C_BLOCK, NULL },
|
2004-01-17 08:42:50 +03:00
|
|
|
/* If you add items to this table, be sure to add the
|
|
|
|
* conversions to the C_BS check in the jcl routine above.
|
|
|
|
*/
|
1993-05-04 11:08:38 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2001-11-25 09:53:48 +03:00
|
|
|
f_conv(char *arg)
|
1993-05-04 11:08:38 +04:00
|
|
|
{
|
1994-09-22 13:24:46 +04:00
|
|
|
struct conv *cp, tmp;
|
1993-05-04 11:08:38 +04:00
|
|
|
|
|
|
|
while (arg != NULL) {
|
|
|
|
tmp.name = strsep(&arg, ",");
|
|
|
|
if (!(cp = (struct conv *)bsearch(&tmp, clist,
|
|
|
|
sizeof(clist)/sizeof(struct conv), sizeof(struct conv),
|
2003-08-05 02:31:21 +04:00
|
|
|
c_conv))) {
|
|
|
|
errx(EXIT_FAILURE, "unknown conversion %s", tmp.name);
|
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
|
|
|
if (ddflags & cp->noset) {
|
2010-12-09 13:24:56 +03:00
|
|
|
errx(EXIT_FAILURE,
|
|
|
|
"%s: illegal conversion combination", tmp.name);
|
2003-08-05 02:31:21 +04:00
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
1993-05-04 11:08:38 +04:00
|
|
|
ddflags |= cp->set;
|
|
|
|
if (cp->ctab)
|
|
|
|
ctab = cp->ctab;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2001-11-25 09:53:48 +03:00
|
|
|
c_conv(const void *a, const void *b)
|
1993-05-04 11:08:38 +04:00
|
|
|
{
|
1994-09-22 13:24:46 +04:00
|
|
|
|
1998-07-28 07:47:14 +04:00
|
|
|
return (strcmp(((const struct conv *)a)->name,
|
|
|
|
((const struct conv *)b)->name));
|
1993-05-04 11:08:38 +04:00
|
|
|
}
|
|
|
|
|
1995-10-09 02:01:22 +03:00
|
|
|
#endif /* NO_CONV */
|