summaryrefslogtreecommitdiff
path: root/usr/src/cmd/valtools
diff options
context:
space:
mode:
Diffstat (limited to 'usr/src/cmd/valtools')
-rw-r--r--usr/src/cmd/valtools/Makefile114
-rw-r--r--usr/src/cmd/valtools/ckdate.c250
-rw-r--r--usr/src/cmd/valtools/ckgid.c232
-rw-r--r--usr/src/cmd/valtools/ckint.c217
-rw-r--r--usr/src/cmd/valtools/ckitem.c367
-rw-r--r--usr/src/cmd/valtools/ckkeywd.c184
-rw-r--r--usr/src/cmd/valtools/ckpath.c310
-rw-r--r--usr/src/cmd/valtools/ckrange.c263
-rw-r--r--usr/src/cmd/valtools/ckstr.c271
-rw-r--r--usr/src/cmd/valtools/cktime.c257
-rw-r--r--usr/src/cmd/valtools/ckuid.c235
-rw-r--r--usr/src/cmd/valtools/ckyorn.c228
-rw-r--r--usr/src/cmd/valtools/puttext.c110
-rw-r--r--usr/src/cmd/valtools/usage.h42
14 files changed, 3080 insertions, 0 deletions
diff --git a/usr/src/cmd/valtools/Makefile b/usr/src/cmd/valtools/Makefile
new file mode 100644
index 0000000000..1f89eb691f
--- /dev/null
+++ b/usr/src/cmd/valtools/Makefile
@@ -0,0 +1,114 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+#ident "%Z%%M% %I% %E% SMI"
+#
+# Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+# cmd/valtools/Makefile
+#
+
+PROG= ckint ckitem ckpath ckrange ckstr ckyorn \
+ ckkeywd ckdate cktime ckuid ckgid
+
+POFILES= ckdate.po ckgid.po ckint.po ckitem.po \
+ ckkeywd.po ckpath.po ckrange.po ckstr.po \
+ cktime.po ckuid.po ckyorn.po puttext.po
+
+include ../Makefile.cmd
+
+LIBADMDIR= ../../lib/libadm/inc
+CPPFLAGS += -I$(LIBADMDIR)
+CFLAGS += $(CCVERBOSE)
+LDLIBS += -ladm
+POFILE= valtools.po
+CLOBBERFILES += puttext $(POFILES) $(POFILE)
+CLEANFILES += puttext
+
+VCKS= valint helpint errint \
+ helpitem erritem \
+ valpath helppath errpath \
+ valrange helprange errange \
+ valstr helpstr errstr \
+ valyorn helpyorn erryorn \
+ valtime helptime errtime \
+ valdate helpdate errdate \
+ dispuid valuid helpuid erruid \
+ dispgid valgid helpgid errgid
+
+DISPS= dispuid dispgid
+
+ROOTSADMDIR= $(ROOT)/usr/sadm/bin
+
+ROOTPUTTEXT= $(ROOTSADMDIR)/puttext
+ROOTVCKS= $(VCKS:%=$(ROOTSADMDIR)/%)
+ROOTDISPS= $(DISPS:%=$(ROOTBIN)/%)
+
+
+# valtool install rules
+$(ROOTSADMDIR)/%: %
+ $(INS.file)
+
+# there is a special case here for errange
+#
+$(ROOTSADMDIR)/disp% \
+$(ROOTSADMDIR)/val% \
+$(ROOTSADMDIR)/help% \
+$(ROOTSADMDIR)/err% \
+$(ROOTSADMDIR)/er% \
+$(ROOTBIN)/disp%: $(ROOTBIN)/ck%
+ $(RM) $@; $(LN) $< $@
+
+
+.KEEP_STATE:
+
+.PARALLEL: $(PROG) puttext
+
+all: $(PROG) puttext
+
+install: all $(ROOTSADMDIR) $(ROOTPROG) $(ROOTPUTTEXT) $(ROOTVCKS) $(ROOTDISPS)
+
+$(ROOTSADMDIR):
+ $(INS.dir)
+
+$(POFILE): $(POFILES)
+ $(RM) $@
+ cat $(POFILES) > $@
+
+clean:
+
+lint:
+ $(LINT.c) ckint.c $(LDLIBS)
+ $(LINT.c) ckitem.c $(LDLIBS)
+ $(LINT.c) ckpath.c $(LDLIBS)
+ $(LINT.c) ckrange.c $(LDLIBS)
+ $(LINT.c) ckstr.c $(LDLIBS)
+ $(LINT.c) ckyorn.c $(LDLIBS)
+ $(LINT.c) ckkeywd.c $(LDLIBS)
+ $(LINT.c) ckdate.c $(LDLIBS)
+ $(LINT.c) cktime.c $(LDLIBS)
+ $(LINT.c) ckuid.c $(LDLIBS)
+ $(LINT.c) ckgid.c $(LDLIBS)
+ $(LINT.c) puttext.c $(LDLIBS)
+
+include ../Makefile.targ
diff --git a/usr/src/cmd/valtools/ckdate.c b/usr/src/cmd/valtools/ckdate.c
new file mode 100644
index 0000000000..e72b7e3209
--- /dev/null
+++ b/usr/src/cmd/valtools/ckdate.c
@@ -0,0 +1,250 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/*
+ * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#pragma ident "%Z%%M% %I% %E% SMI"
+
+#include <stdio.h>
+#include <string.h>
+#include <signal.h>
+#include <stdlib.h>
+#include <locale.h>
+#include <libintl.h>
+#include <limits.h>
+#include "usage.h"
+#include "libadm.h"
+
+#define BADPID (-2)
+
+static char *prog;
+static char *deflt = NULL, *prompt = NULL, *error = NULL, *help = NULL;
+static int signo = 0;
+static int kpid = BADPID;
+static char *fmt = NULL;
+
+static const char vusage[] = "f";
+static const char husage[] = "fWh";
+static const char eusage[] = "fWe";
+
+#define MYFMT "%s:ERROR:invalid format\n" \
+ "valid format descriptors are:\n" \
+ "\t%%b #abbreviated month name\n" \
+ "\t%%B #full month name\n" \
+ "\t%%d #day of month (01-31)\n" \
+ "\t%%D #date as %%m/%%d/%%y or %%m-%%d-%%y (default)\n" \
+ "\t%%e #day of month (1-31)\n" \
+ "\t%%m #month of year (01-12)\n" \
+ "\t%%y #year within century (YY)\n" \
+ "\t%%Y #year as CCYY\n"
+
+static void
+usage(void)
+{
+ switch (*prog) {
+ default:
+ (void) fprintf(stderr,
+ gettext("usage: %s [options] [-f format]\n"), prog);
+ (void) fprintf(stderr, gettext(OPTMESG));
+ (void) fprintf(stderr, gettext(STDOPTS));
+ break;
+
+ case 'v':
+ (void) fprintf(stderr,
+ gettext("usage: %s [-f format] input\n"), prog);
+ break;
+
+ case 'h':
+ (void) fprintf(stderr,
+ gettext("usage: %s [options] [-f format]\n"), prog);
+ (void) fprintf(stderr, gettext(OPTMESG));
+ (void) fprintf(stderr,
+ gettext("\t-W width\n\t-h help\n"));
+ break;
+
+ case 'e':
+ (void) fprintf(stderr,
+ gettext("usage: %s [options] [-f format]\n"), prog);
+ (void) fprintf(stderr, gettext(OPTMESG));
+ (void) fprintf(stderr,
+ gettext("\t-W width\n\t-h error\n"));
+ break;
+ }
+ exit(1);
+}
+
+/*
+ * Given argv[0], return a pointer to the basename of the program.
+ */
+static char *
+prog_name(char *arg0)
+{
+ char *str;
+
+ /* first strip trailing '/' characters (exec() allows these!) */
+ str = arg0 + strlen(arg0);
+ while (str > arg0 && *--str == '/')
+ *str = '\0';
+ if ((str = strrchr(arg0, '/')) != NULL)
+ return (str + 1);
+ return (arg0);
+}
+
+int
+main(int argc, char **argv)
+{
+ int c, n;
+ char *date;
+ size_t len;
+
+ (void) setlocale(LC_ALL, "");
+
+#if !defined(TEXT_DOMAIN)
+#define TEXT_DOMAIN "SYS_TEST"
+#endif
+ (void) textdomain(TEXT_DOMAIN);
+
+ prog = prog_name(argv[0]);
+
+ while ((c = getopt(argc, argv, "f:d:p:e:h:k:s:QW:?")) != EOF) {
+ /* check for invalid option */
+ if ((*prog == 'v') && !strchr(vusage, c))
+ usage();
+ if ((*prog == 'e') && !strchr(eusage, c))
+ usage();
+ if ((*prog == 'h') && !strchr(husage, c))
+ usage();
+
+ switch (c) {
+ case 'Q':
+ ckquit = 0;
+ break;
+
+ case 'W':
+ ckwidth = atoi(optarg);
+ if (ckwidth < 0) {
+ (void) fprintf(stderr,
+ gettext("%s: ERROR: negative display width specified\n"),
+ prog);
+ exit(1);
+ }
+ break;
+
+ case 'f':
+ fmt = optarg;
+ break;
+
+ case 'd':
+ deflt = optarg;
+ break;
+
+ case 'p':
+ prompt = optarg;
+ break;
+
+ case 'e':
+ error = optarg;
+ break;
+
+ case 'h':
+ help = optarg;
+ break;
+
+ case 'k':
+ kpid = atoi(optarg);
+ break;
+
+ case 's':
+ signo = atoi(optarg);
+ break;
+
+ default:
+ usage();
+ }
+ }
+
+ if (signo) {
+ if (kpid == BADPID)
+ usage();
+ } else
+ signo = SIGTERM;
+
+ if (*prog == 'v') {
+ if (argc != (optind + 1))
+ usage();
+ n = (ckdate_val(fmt, argv[optind]));
+ if (n == 4)
+ (void) fprintf(stderr, gettext(MYFMT), prog);
+ exit(n);
+ }
+
+ if (optind != argc)
+ usage();
+
+ if (*prog == 'e') {
+ ckindent = 0;
+ if (ckdate_err(fmt, error)) {
+ (void) fprintf(stderr, gettext(MYFMT), prog);
+ exit(4);
+ } else
+ exit(0);
+
+ } else if (*prog == 'h') {
+ ckindent = 0;
+ if (ckdate_hlp(fmt, help)) {
+ (void) fprintf(stderr, gettext(MYFMT), prog);
+ exit(4);
+ } else
+ exit(0);
+
+ }
+
+ if (deflt) {
+ len = strlen(deflt) + 1;
+ if (len < MAX_INPUT)
+ len = MAX_INPUT;
+ } else {
+ len = MAX_INPUT;
+ }
+ date = (char *)malloc(len);
+ if (!date) {
+ (void) fprintf(stderr,
+ gettext("Not enough memory\n"));
+ exit(1);
+ }
+ n = ckdate(date, fmt, deflt, error, help, prompt);
+ if (n == 3) {
+ if (kpid > -2)
+ (void) kill(kpid, signo);
+ (void) puts("q");
+ } else if (n == 0)
+ (void) printf("%s", date);
+ if (n == 4)
+ (void) fprintf(stderr, gettext(MYFMT), prog);
+ return (n);
+}
diff --git a/usr/src/cmd/valtools/ckgid.c b/usr/src/cmd/valtools/ckgid.c
new file mode 100644
index 0000000000..8305c8f159
--- /dev/null
+++ b/usr/src/cmd/valtools/ckgid.c
@@ -0,0 +1,232 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/*
+ * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#pragma ident "%Z%%M% %I% %E% SMI"
+
+#include <stdio.h>
+#include <string.h>
+#include <signal.h>
+#include <stdlib.h>
+#include <locale.h>
+#include <libintl.h>
+#include <limits.h>
+#include "usage.h"
+#include "libadm.h"
+
+#define BADPID (-2)
+
+static char *prog;
+static char *deflt = NULL, *error = NULL, *help = NULL, *prompt = NULL;
+static int kpid = BADPID;
+static int signo, disp;
+
+static const char eusage[] = "mWe";
+static const char husage[] = "mWh";
+
+static void
+usage(void)
+{
+ switch (*prog) {
+ default:
+ (void) fprintf(stderr,
+ gettext("usage: %s [options] [-m]\n"), prog);
+ (void) fprintf(stderr, gettext(OPTMESG));
+ (void) fprintf(stderr, gettext(STDOPTS));
+ break;
+
+ case 'd':
+ (void) fprintf(stderr,
+ gettext("usage: %s\n"), prog);
+ break;
+
+ case 'v':
+ (void) fprintf(stderr,
+ gettext("usage: %s input\n"), prog);
+ break;
+
+ case 'h':
+ (void) fprintf(stderr,
+ gettext("usage: %s [options] [-m]\n"), prog);
+ (void) fprintf(stderr, gettext(OPTMESG));
+ (void) fprintf(stderr,
+ gettext("\t-W width\n\t-h help\n"));
+ break;
+
+ case 'e':
+ (void) fprintf(stderr,
+ gettext("usage: %s [options] [-m]\n"), prog);
+ (void) fprintf(stderr, gettext(OPTMESG));
+ (void) fprintf(stderr,
+ gettext("\t-W width\n\t-e error\n"));
+ break;
+ }
+ exit(1);
+}
+
+/*
+ * Given argv[0], return a pointer to the basename of the program.
+ */
+static char *
+prog_name(char *arg0)
+{
+ char *str;
+
+ /* first strip trailing '/' characters (exec() allows these!) */
+ str = arg0 + strlen(arg0);
+ while (str > arg0 && *--str == '/')
+ *str = '\0';
+ if ((str = strrchr(arg0, '/')) != NULL)
+ return (str + 1);
+ return (arg0);
+}
+
+int
+main(int argc, char **argv)
+{
+ int c, n;
+ char *gid;
+ size_t len;
+
+ (void) setlocale(LC_ALL, "");
+
+#if !defined(TEXT_DOMAIN)
+#define TEXT_DOMAIN "SYS_TEST"
+#endif
+ (void) textdomain(TEXT_DOMAIN);
+
+ prog = prog_name(argv[0]);
+
+ while ((c = getopt(argc, argv, "md:p:e:h:k:s:QW:?")) != EOF) {
+ /* check for invalid option */
+ if ((*prog == 'v') || (*prog == 'd'))
+ usage(); /* no valid options */
+ if ((*prog == 'e') && !strchr(eusage, c))
+ usage();
+ if ((*prog == 'h') && !strchr(husage, c))
+ usage();
+
+ switch (c) {
+ case 'Q':
+ ckquit = 0;
+ break;
+
+ case 'W':
+ ckwidth = atoi(optarg);
+ if (ckwidth < 0) {
+ (void) fprintf(stderr,
+ gettext("%s: ERROR: negative display width specified\n"),
+ prog);
+ exit(1);
+ }
+ break;
+
+ case 'm':
+ disp = 1;
+ break;
+
+ case 'd':
+ deflt = optarg;
+ break;
+
+ case 'p':
+ prompt = optarg;
+ break;
+
+ case 'e':
+ error = optarg;
+ break;
+
+ case 'h':
+ help = optarg;
+ break;
+
+ case 'k':
+ kpid = atoi(optarg);
+ break;
+
+ case 's':
+ signo = atoi(optarg);
+ break;
+
+ default:
+ usage();
+ }
+ }
+
+ if (signo) {
+ if (kpid == BADPID)
+ usage();
+ } else
+ signo = SIGTERM;
+
+ if (*prog == 'v') {
+ if (argc != (optind+1))
+ usage();
+ exit(ckgid_val(argv[optind]));
+ }
+
+ if (argc != optind)
+ usage();
+
+
+ if (*prog == 'e') {
+ ckindent = 0;
+ ckgid_err(disp, error);
+ exit(0);
+ } else if (*prog == 'h') {
+ ckindent = 0;
+ ckgid_hlp(disp, help);
+ exit(0);
+ } else if (*prog == 'd') {
+ exit(ckgid_dsp());
+ }
+
+ if (deflt) {
+ len = strlen(deflt) + 1;
+ if (len < MAX_INPUT)
+ len = MAX_INPUT;
+ } else {
+ len = MAX_INPUT;
+ }
+ gid = (char *)malloc(len);
+ if (!gid) {
+ (void) fprintf(stderr,
+ gettext("Not enough memory\n"));
+ exit(1);
+ }
+ n = ckgid(gid, disp, deflt, error, help, prompt);
+ if (n == 3) {
+ if (kpid > -2)
+ (void) kill(kpid, signo);
+ (void) puts("q");
+ } else if (n == 0)
+ (void) fputs(gid, stdout);
+ return (n);
+}
diff --git a/usr/src/cmd/valtools/ckint.c b/usr/src/cmd/valtools/ckint.c
new file mode 100644
index 0000000000..32d8bf9f7b
--- /dev/null
+++ b/usr/src/cmd/valtools/ckint.c
@@ -0,0 +1,217 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/*
+ * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#pragma ident "%Z%%M% %I% %E% SMI"
+
+#include <stdio.h>
+#include <string.h>
+#include <signal.h>
+#include <stdlib.h>
+#include <locale.h>
+#include <libintl.h>
+#include "usage.h"
+#include "libadm.h"
+
+#define BADPID (-2)
+
+static char *prog;
+static char *deflt, *prompt, *error, *help;
+static int kpid = BADPID;
+static int signo;
+static short base;
+
+static const char vusage[] = "b";
+static const char husage[] = "bWh";
+static const char eusage[] = "bWe";
+
+static void
+usage(void)
+{
+ switch (*prog) {
+ default:
+ (void) fprintf(stderr,
+ gettext("usage: %s [options] [-b base]\n"), prog);
+ (void) fprintf(stderr, gettext(OPTMESG));
+ (void) fprintf(stderr, gettext(STDOPTS));
+ break;
+
+ case 'v':
+ (void) fprintf(stderr,
+ gettext("usage: %s [-b base] input\n"), prog);
+ break;
+
+ case 'h':
+ (void) fprintf(stderr,
+ gettext("usage: %s [options] [-b base]\n"), prog);
+ (void) fprintf(stderr, gettext(OPTMESG));
+ (void) fprintf(stderr,
+ gettext("\t-W width\n\t-h help\n"));
+ break;
+
+ case 'e':
+ (void) fprintf(stderr,
+ gettext("usage: %s [options] [-b base]\n"), prog);
+ (void) fprintf(stderr, gettext(OPTMESG));
+ (void) fprintf(stderr,
+ gettext("\t-W width\n\t-e error\n"));
+ break;
+ }
+ exit(1);
+}
+
+/*
+ * Given argv[0], return a pointer to the basename of the program.
+ */
+static char *
+prog_name(char *arg0)
+{
+ char *str;
+
+ /* first strip trailing '/' characters (exec() allows these!) */
+ str = arg0 + strlen(arg0);
+ while (str > arg0 && *--str == '/')
+ *str = '\0';
+ if ((str = strrchr(arg0, '/')) != NULL)
+ return (str + 1);
+ return (arg0);
+}
+
+int
+main(int argc, char **argv)
+{
+ int c, n;
+ long intval;
+
+ (void) setlocale(LC_ALL, "");
+
+#if !defined(TEXT_DOMAIN)
+#define TEXT_DOMAIN "SYS_TEST"
+#endif
+ (void) textdomain(TEXT_DOMAIN);
+
+ prog = prog_name(argv[0]);
+
+ while ((c = getopt(argc, argv, "b:d:p:e:h:k:s:QW:?")) != EOF) {
+ /* check for invalid option */
+ if ((*prog == 'v') && !strchr(vusage, c))
+ usage(); /* no valid options */
+ if ((*prog == 'e') && !strchr(eusage, c))
+ usage();
+ if ((*prog == 'h') && !strchr(husage, c))
+ usage();
+
+ switch (c) {
+ case 'Q':
+ ckquit = 0;
+ break;
+
+ case 'W':
+ ckwidth = atoi(optarg);
+ if (ckwidth < 0) {
+ (void) fprintf(stderr,
+ gettext("%s: ERROR: negative display width specified\n"),
+ prog);
+ exit(1);
+ }
+ break;
+
+ case 'b':
+ base = atoi(optarg);
+ if ((base < 2) || (base > 36)) {
+ (void) fprintf(stderr,
+ gettext("%s: ERROR: base must be between 2 and 36\n"),
+ prog);
+ exit(1);
+ }
+ break;
+
+ case 'd':
+ deflt = optarg;
+ break;
+
+ case 'p':
+ prompt = optarg;
+ break;
+
+ case 'e':
+ error = optarg;
+ break;
+
+ case 'h':
+ help = optarg;
+ break;
+
+ case 'k':
+ kpid = atoi(optarg);
+ break;
+
+ case 's':
+ signo = atoi(optarg);
+ break;
+
+ default:
+ usage();
+ }
+ }
+
+ if (signo) {
+ if (kpid == BADPID)
+ usage();
+ } else
+ signo = SIGTERM;
+
+ if (*prog == 'v') {
+ if (argc != (optind + 1))
+ usage();
+ exit(ckint_val(argv[optind], base));
+ }
+
+ if (optind != argc)
+ usage();
+
+ if (*prog == 'e') {
+ ckindent = 0;
+ ckint_err(base, error);
+ exit(0);
+ } else if (*prog == 'h') {
+ ckindent = 0;
+ ckint_hlp(base, help);
+ exit(0);
+ }
+
+ n = ckint(&intval, base, deflt, error, help, prompt);
+ if (n == 3) {
+ if (kpid > -2)
+ (void) kill(kpid, signo);
+ (void) puts("q");
+ } else if (n == 0)
+ (void) printf("%ld", intval);
+ return (n);
+}
diff --git a/usr/src/cmd/valtools/ckitem.c b/usr/src/cmd/valtools/ckitem.c
new file mode 100644
index 0000000000..c56794f50d
--- /dev/null
+++ b/usr/src/cmd/valtools/ckitem.c
@@ -0,0 +1,367 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/*
+ * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#pragma ident "%Z%%M% %I% %E% SMI"
+
+#include <stdio.h>
+#include <ctype.h>
+#include <string.h>
+#include <signal.h>
+#include <valtools.h>
+#include <stdlib.h>
+#include <locale.h>
+#include <libintl.h>
+#include <limits.h>
+#include <wchar.h>
+#include "usage.h"
+#include "libadm.h"
+
+#define BADPID (-2)
+#define INVISMAXSIZE 36
+
+static char *prog;
+static char *deflt = NULL, *prompt = NULL, *error = NULL, *help = NULL;
+static int kpid = BADPID;
+static int signo;
+
+static char *label, **invis;
+static int ninvis = 0;
+static int max = 1;
+static int attr = CKALPHA;
+
+#define MAXSIZE 128
+#define LSIZE 1024
+#define INTERR \
+ "%s: ERROR: internal error occurred while attempting menu setup\n"
+#define MYOPTS \
+ "\t-f file #file containing choices\n" \
+ "\t-l label #menu label\n" \
+ "\t-i invis [, ...] #invisible menu choices\n" \
+ "\t-m max #maximum choices user may select\n" \
+ "\t-n #do not sort choices alphabetically\n" \
+ "\t-o #don't prompt if only one choice\n" \
+ "\t-u #unnumbered choices\n"
+
+static const char husage[] = "Wh";
+static const char eusage[] = "We";
+
+static void
+usage(void)
+{
+ switch (*prog) {
+ default:
+ (void) fprintf(stderr,
+ gettext("usage: %s [options] [choice [...]]\n"), prog);
+ (void) fprintf(stderr, gettext(OPTMESG));
+ (void) fprintf(stderr, gettext(MYOPTS));
+ (void) fprintf(stderr, gettext(STDOPTS));
+ break;
+
+ case 'h':
+ (void) fprintf(stderr,
+ gettext("usage: %s [options] [choice [...]]\n"), prog);
+ (void) fprintf(stderr, gettext(OPTMESG));
+ (void) fprintf(stderr,
+ gettext("\t-W width\n\t-h help\n"));
+ break;
+
+ case 'e':
+ (void) fprintf(stderr,
+ gettext("usage: %s [options] [choice [...]]\n"), prog);
+ (void) fprintf(stderr, gettext(OPTMESG));
+ (void) fprintf(stderr,
+ gettext("\t-W width\n\t-e error\n"));
+ break;
+ }
+ exit(1);
+}
+
+/*
+ * Given argv[0], return a pointer to the basename of the program.
+ */
+static char *
+prog_name(char *arg0)
+{
+ char *str;
+
+ /* first strip trailing '/' characters (exec() allows these!) */
+ str = arg0 + strlen(arg0);
+ while (str > arg0 && *--str == '/')
+ *str = '\0';
+ if ((str = strrchr(arg0, '/')) != NULL)
+ return (str + 1);
+ return (arg0);
+}
+
+int
+main(int argc, char **argv)
+{
+ CKMENU *mp;
+ FILE *fp = NULL;
+ int c, i;
+ char **item;
+ char temp[LSIZE * MB_LEN_MAX];
+ size_t mmax;
+ size_t invismaxsize = INVISMAXSIZE;
+ size_t n, r;
+ wchar_t wline[LSIZE], wtemp[LSIZE];
+
+ (void) setlocale(LC_ALL, "");
+
+#if !defined(TEXT_DOMAIN)
+#define TEXT_DOMAIN "SYS_TEST"
+#endif
+ (void) textdomain(TEXT_DOMAIN);
+
+ prog = prog_name(argv[0]);
+
+ invis = (char **)calloc(invismaxsize, sizeof (char *));
+ if (!invis) {
+ (void) fprintf(stderr,
+ gettext("Not enough memory\n"));
+ exit(1);
+ }
+ while ((c = getopt(argc, argv, "m:oni:l:f:ud:p:e:h:k:s:QW:?")) != EOF) {
+ /* check for invalid option */
+ if ((*prog == 'e') && !strchr(eusage, c))
+ usage(); /* no valid options */
+ if ((*prog == 'h') && !strchr(husage, c))
+ usage();
+
+ switch (c) {
+ case 'Q':
+ ckquit = 0;
+ break;
+
+ case 'W':
+ ckwidth = atol(optarg);
+ if (ckwidth < 0) {
+ (void) fprintf(stderr,
+ gettext("%s: ERROR: negative display width specified\n"),
+ prog);
+ exit(1);
+ }
+ break;
+
+ case 'm':
+ max = atoi(optarg);
+ if (max > SHRT_MAX || max < SHRT_MIN) {
+ (void) fprintf(stderr,
+ gettext("%s: ERROR: too large or too small max value specified\n"),
+ prog);
+ exit(1);
+ }
+ break;
+
+ case 'o':
+ attr |= CKONEFLAG;
+ break;
+
+ case 'n':
+ attr &= ~CKALPHA;
+ break;
+
+ case 'i':
+ invis[ninvis++] = optarg;
+ if (ninvis == invismaxsize) {
+ invismaxsize += INVISMAXSIZE;
+ invis = (char **)realloc(invis,
+ invismaxsize * sizeof (char *));
+ if (!invis) {
+ (void) fprintf(stderr,
+ gettext("Not enough memory\n"));
+ exit(1);
+ }
+ (void) memset(invis + ninvis, 0,
+ (invismaxsize - ninvis) *
+ sizeof (char *));
+ }
+ break;
+
+ case 'l':
+ label = optarg;
+ break;
+
+ case 'f':
+ if ((fp = fopen(optarg, "r")) == NULL) {
+ (void) fprintf(stderr,
+ gettext("%s: ERROR: can't open %s\n"),
+ prog, optarg);
+ exit(1);
+ }
+ break;
+
+ case 'u':
+ attr |= CKUNNUM;
+ break;
+
+ case 'd':
+ deflt = optarg;
+ break;
+
+ case 'p':
+ prompt = optarg;
+ break;
+
+ case 'e':
+ error = optarg;
+ break;
+
+ case 'h':
+ help = optarg;
+ break;
+
+ case 'k':
+ kpid = atoi(optarg);
+ break;
+
+ case 's':
+ signo = atoi(optarg);
+ break;
+
+ default:
+ usage();
+ }
+ }
+
+ if (signo) {
+ if (kpid == BADPID)
+ usage();
+ } else
+ signo = SIGTERM;
+
+ mp = allocmenu(label, attr);
+ if (fp) {
+ *wtemp = L'\0';
+ while (fgetws(wline, LSIZE, fp)) {
+ /*
+ * Skip comment lines, those beginning with '#'.
+ * Note: AT&T forgot this & needs the next 2 lines.
+ */
+ if (*wline == L'#')
+ continue;
+ n = wcslen(wline);
+ if ((n != 0) && (wline[n - 1] == L'\n'))
+ wline[n - 1] = L'\0';
+ /*
+ * if the line begins with a space character,
+ * this is a continuous line to the previous line.
+ */
+ if (iswspace(*wline)) {
+ (void) wcscat(wtemp, L"\n");
+ (void) wcscat(wtemp, wline);
+ } else {
+ if (*wtemp) {
+ n = wcslen(wtemp);
+ r = wcstombs(temp, wtemp,
+ n * MB_LEN_MAX);
+ if (r == (size_t)-1) {
+ (void) fprintf(stderr,
+ gettext("Invalid character in the menu definition.\n"));
+ exit(1);
+ }
+ if (setitem(mp, temp)) {
+ (void) fprintf(stderr,
+ gettext(INTERR), prog);
+ exit(1);
+ }
+ }
+ (void) wcscpy(wtemp, wline);
+ }
+ }
+ if (*wtemp) {
+ n = wcslen(wtemp);
+ r = wcstombs(temp, wtemp, n * MB_LEN_MAX);
+ if (r == (size_t)-1) {
+ (void) fprintf(stderr,
+ gettext("Invalid character in the menu definition.\n"));
+ exit(1);
+ }
+ if (setitem(mp, temp)) {
+ (void) fprintf(stderr, gettext(INTERR), prog);
+ exit(1);
+ }
+ }
+ }
+
+ while (optind < argc) {
+ if (setitem(mp, argv[optind++])) {
+ (void) fprintf(stderr, gettext(INTERR), prog);
+ exit(1);
+ }
+ }
+
+ for (n = 0; n < ninvis; ) {
+ if (setinvis(mp, invis[n++])) {
+ (void) fprintf(stderr, gettext(INTERR), prog);
+ exit(1);
+ }
+ }
+
+ if (*prog == 'e') {
+ ckindent = 0;
+ ckitem_err(mp, error);
+ exit(0);
+ } else if (*prog == 'h') {
+ ckindent = 0;
+ ckitem_hlp(mp, help);
+ exit(0);
+ }
+
+ if (max < 1) {
+ mmax = mp->nchoices;
+ } else {
+ mmax = max;
+ }
+
+/*
+ * if -o option is specified, mp->nchoices is 1, and if no invisible
+ * item is specified, ckitem() will consume two entries of item,
+ * even though 'max' is set to 1. So to take care of that problem, we
+ * allocate one extra element for item
+ */
+ item = (char **)calloc(mmax+1, sizeof (char *));
+ if (!item) {
+ (void) fprintf(stderr,
+ gettext("Not enough memory\n"));
+ exit(1);
+ }
+ n = ckitem(mp, item, max, deflt, error, help, prompt);
+ if (n == 3) {
+ if (kpid > -2)
+ (void) kill(kpid, signo);
+ (void) puts("q");
+ } else if (n == 0) {
+ i = 0;
+ while (item[i])
+ (void) puts(item[i++]);
+ }
+ return (n);
+}
diff --git a/usr/src/cmd/valtools/ckkeywd.c b/usr/src/cmd/valtools/ckkeywd.c
new file mode 100644
index 0000000000..6b0e670d58
--- /dev/null
+++ b/usr/src/cmd/valtools/ckkeywd.c
@@ -0,0 +1,184 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/*
+ * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#pragma ident "%Z%%M% %I% %E% SMI"
+
+#include <stdio.h>
+#include <string.h>
+#include <signal.h>
+#include <stdlib.h>
+#include <locale.h>
+#include <libintl.h>
+#include <limits.h>
+#include "usage.h"
+#include "libadm.h"
+
+#define BADPID (-2)
+
+static char *prog;
+static char *deflt = NULL, *prompt = NULL, *error = NULL, *help = NULL;
+static int kpid = BADPID;
+static int signo;
+
+static char **keyword;
+static int nkeyword = 0;
+
+static void
+usage(void)
+{
+ (void) fprintf(stderr,
+ gettext("usage: %s [options] keyword [...]\n"), prog);
+ (void) fprintf(stderr, gettext(OPTMESG));
+ (void) fprintf(stderr, gettext(STDOPTS));
+ exit(1);
+}
+
+/*
+ * Given argv[0], return a pointer to the basename of the program.
+ */
+static char *
+prog_name(char *arg0)
+{
+ char *str;
+
+ /* first strip trailing '/' characters (exec() allows these!) */
+ str = arg0 + strlen(arg0);
+ while (str > arg0 && *--str == '/')
+ *str = '\0';
+ if ((str = strrchr(arg0, '/')) != NULL)
+ return (str + 1);
+ return (arg0);
+}
+
+int
+main(int argc, char **argv)
+{
+ int c, n;
+ int i;
+ char *strval;
+ size_t len;
+
+ (void) setlocale(LC_ALL, "");
+
+#if !defined(TEXT_DOMAIN)
+#define TEXT_DOMAIN "SYS_TEST"
+#endif
+ (void) textdomain(TEXT_DOMAIN);
+
+ prog = prog_name(argv[0]);
+
+
+ while ((c = getopt(argc, argv, "d:p:e:h:k:s:QW:?")) != EOF) {
+ switch (c) {
+ case 'Q':
+ ckquit = 0;
+ break;
+
+ case 'W':
+ ckwidth = atoi(optarg);
+ if (ckwidth < 0) {
+ (void) fprintf(stderr,
+ gettext("%s: ERROR: negative display width specified\n"),
+ prog);
+ exit(1);
+ }
+ break;
+
+ case 'd':
+ deflt = optarg;
+ break;
+
+ case 'p':
+ prompt = optarg;
+ break;
+
+ case 'e':
+ error = optarg;
+ break;
+
+ case 'h':
+ help = optarg;
+ break;
+
+ case 'k':
+ kpid = atoi(optarg);
+ break;
+
+ case 's':
+ signo = atoi(optarg);
+ break;
+
+ default:
+ usage();
+ }
+ }
+
+ if (signo) {
+ if (kpid == BADPID)
+ usage();
+ } else
+ signo = SIGTERM;
+
+ if (optind >= argc)
+ usage(); /* must be at least one keyword */
+
+ nkeyword = argc - optind;
+ keyword = (char **)malloc(sizeof (char *) * (nkeyword + 1));
+ if (!keyword) {
+ (void) fprintf(stderr,
+ gettext("Not enough memory\n"));
+ exit(1);
+ }
+ for (i = 0; i < nkeyword; i++)
+ keyword[i] = argv[optind++];
+ keyword[nkeyword] = NULL;
+
+ if (deflt) {
+ len = strlen(deflt) + 1;
+ if (len < MAX_INPUT)
+ len = MAX_INPUT;
+ } else {
+ len = MAX_INPUT;
+ }
+ strval = (char *)malloc(len);
+ if (!strval) {
+ (void) fprintf(stderr,
+ gettext("Not enough memory\n"));
+ exit(1);
+ }
+ n = ckkeywd(strval, keyword, deflt, error, help, prompt);
+ if (n == 3) {
+ if (kpid > -2)
+ (void) kill(kpid, signo);
+ (void) puts("q");
+ } else if (n == 0)
+ (void) fputs(strval, stdout);
+ return (n);
+}
diff --git a/usr/src/cmd/valtools/ckpath.c b/usr/src/cmd/valtools/ckpath.c
new file mode 100644
index 0000000000..263df139e2
--- /dev/null
+++ b/usr/src/cmd/valtools/ckpath.c
@@ -0,0 +1,310 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/*
+ * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#pragma ident "%Z%%M% %I% %E% SMI"
+
+#include <stdio.h>
+#include <string.h>
+#include <signal.h>
+#include <valtools.h>
+#include <stdlib.h>
+#include <locale.h>
+#include <libintl.h>
+#include <limits.h>
+#include "usage.h"
+#include "libadm.h"
+
+#define BADPID (-2)
+
+static char *prog;
+static char *deflt = NULL, *prompt = NULL, *error = NULL, *help = NULL;
+static int kpid = BADPID;
+static int signo, pflags;
+
+static const char vusage[] = "abcfglrtwxyzno";
+static const char eusage[] = "abcfglrtwxyznoWe";
+static const char husage[] = "abcfglrtwxyznoWh";
+
+#define USAGE "[-[a|l][b|c|f|y][n|[o|z]]rtwx]"
+#define MYOPTS \
+ "\t-a #absolute path\n" \
+ "\t-b #block special device\n" \
+ "\t-c #character special device\n" \
+ "\t-f #ordinary file\n" \
+ "\t-l #relative path\n" \
+ "\t-n #must not exist (new)\n" \
+ "\t-o #must exist (old)\n" \
+ "\t-r #read permission\n" \
+ "\t-t #permission to create (touch)\n" \
+ "\t-w #write permission\n" \
+ "\t-x #execute permisiion\n" \
+ "\t-y #directory\n" \
+ "\t-z #non-zero length\n"
+
+static void
+usage(void)
+{
+ switch (*prog) {
+ default:
+ (void) fprintf(stderr,
+ gettext("usage: %s [options] %s\n"),
+ prog, USAGE);
+ (void) fprintf(stderr, gettext(MYOPTS));
+ (void) fprintf(stderr, gettext(OPTMESG));
+ (void) fprintf(stderr, gettext(STDOPTS));
+ break;
+
+ case 'v':
+ (void) fprintf(stderr,
+ gettext("usage: %s %s input\n"),
+ prog, USAGE);
+ (void) fprintf(stderr, gettext(OPTMESG));
+ (void) fprintf(stderr, gettext(MYOPTS));
+ break;
+
+ case 'h':
+ (void) fprintf(stderr,
+ gettext("usage: %s [options] %s\n"),
+ prog, USAGE);
+ (void) fprintf(stderr, gettext(MYOPTS));
+ (void) fprintf(stderr, gettext(OPTMESG));
+ (void) fprintf(stderr,
+ gettext("\t-W width\n\t-h help\n"));
+ break;
+
+ case 'e':
+ (void) fprintf(stderr,
+ gettext("usage: %s [options] %s [input]\n"),
+ prog, USAGE);
+ (void) fprintf(stderr, gettext(MYOPTS));
+ (void) fprintf(stderr, gettext(OPTMESG));
+ (void) fprintf(stderr,
+ gettext("\t-W width\n\t-e error\n"));
+ break;
+ }
+ exit(1);
+}
+
+/*
+ * Given argv[0], return a pointer to the basename of the program.
+ */
+static char *
+prog_name(char *arg0)
+{
+ char *str;
+
+ /* first strip trailing '/' characters (exec() allows these!) */
+ str = arg0 + strlen(arg0);
+ while (str > arg0 && *--str == '/')
+ *str = '\0';
+ if ((str = strrchr(arg0, '/')) != NULL)
+ return (str + 1);
+ return (arg0);
+}
+
+int
+main(int argc, char **argv)
+{
+ int c, n;
+ char *pathval;
+ size_t len;
+
+ (void) setlocale(LC_ALL, "");
+
+#if !defined(TEXT_DOMAIN)
+#define TEXT_DOMAIN "SYS_TEST"
+#endif
+ (void) textdomain(TEXT_DOMAIN);
+
+ prog = prog_name(argv[0]);
+
+ while ((c = getopt(argc, argv, "abcfglrtwxyznod:p:e:h:k:s:QW:?"))
+ != EOF) {
+ /* check for invalid option */
+ if ((*prog == 'v') && !strchr(vusage, c))
+ usage();
+ if ((*prog == 'e') && !strchr(eusage, c))
+ usage();
+ if ((*prog == 'h') && !strchr(husage, c))
+ usage();
+
+ switch (c) {
+ case 'Q':
+ ckquit = 0;
+ break;
+
+ case 'W':
+ ckwidth = atoi(optarg);
+ if (ckwidth < 0) {
+ (void) fprintf(stderr,
+ gettext("%s: ERROR: negative display width specified\n"),
+ prog);
+ exit(1);
+ }
+ break;
+
+ case 'a':
+ pflags |= P_ABSOLUTE;
+ break;
+
+ case 'b':
+ pflags |= P_BLK;
+ break;
+
+ case 'c':
+ pflags |= P_CHR;
+ break;
+
+ case 'f':
+ case 'g': /* outdated */
+ pflags |= P_REG;
+ break;
+
+ case 'l':
+ pflags |= P_RELATIVE;
+ break;
+
+ case 'n':
+ pflags |= P_NEXIST;
+ break;
+
+ case 'o':
+ pflags |= P_EXIST;
+ break;
+
+ case 't':
+ pflags |= P_CREAT;
+ break;
+
+ case 'r':
+ pflags |= P_READ;
+ break;
+
+ case 'w':
+ pflags |= P_WRITE;
+ break;
+
+ case 'x':
+ pflags |= P_EXEC;
+ break;
+
+ case 'y':
+ pflags |= P_DIR;
+ break;
+
+ case 'z':
+ pflags |= P_NONZERO;
+ break;
+
+ case 'd':
+ deflt = optarg;
+ break;
+
+ case 'p':
+ prompt = optarg;
+ break;
+
+ case 'e':
+ error = optarg;
+ break;
+
+ case 'h':
+ help = optarg;
+ break;
+
+ case 'k':
+ kpid = atoi(optarg);
+ break;
+
+ case 's':
+ signo = atoi(optarg);
+ break;
+
+ default:
+ usage();
+ }
+ }
+
+ if (signo) {
+ if (kpid == BADPID)
+ usage();
+ } else
+ signo = SIGTERM;
+
+ if (ckpath_stx(pflags)) {
+ (void) fprintf(stderr,
+ gettext("%s: ERROR: mutually exclusive options used\n"),
+ prog);
+ exit(4);
+ }
+
+ if (*prog == 'v') {
+ if (argc != (optind+1))
+ usage(); /* too many paths listed */
+ exit(ckpath_val(argv[optind], pflags));
+ } else if (*prog == 'e') {
+ if (argc > (optind+1))
+ usage();
+ ckindent = 0;
+ ckpath_err(pflags, error, argv[optind]);
+ exit(0);
+ }
+
+ if (optind != argc)
+ usage();
+
+ if (*prog == 'h') {
+ ckindent = 0;
+ ckpath_hlp(pflags, help);
+ exit(0);
+ }
+
+ if (deflt) {
+ len = strlen(deflt) + 1;
+ if (len < MAX_INPUT)
+ len = MAX_INPUT;
+ } else {
+ len = MAX_INPUT;
+ }
+ pathval = (char *)malloc(len);
+ if (!pathval) {
+ (void) fprintf(stderr,
+ gettext("Not enough memory\n"));
+ exit(1);
+ }
+ n = ckpath(pathval, pflags, deflt, error, help, prompt);
+ if (n == 3) {
+ if (kpid > -2)
+ (void) kill(kpid, signo);
+ (void) puts("q");
+ } else if (n == 0)
+ (void) fputs(pathval, stdout);
+ return (n);
+}
diff --git a/usr/src/cmd/valtools/ckrange.c b/usr/src/cmd/valtools/ckrange.c
new file mode 100644
index 0000000000..6857e7bea5
--- /dev/null
+++ b/usr/src/cmd/valtools/ckrange.c
@@ -0,0 +1,263 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/*
+ * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#pragma ident "%Z%%M% %I% %E% SMI"
+
+#include <stdio.h>
+#include <limits.h>
+#include <string.h>
+#include <signal.h>
+#include <stdlib.h>
+#include <locale.h>
+#include <libintl.h>
+#include "usage.h"
+#include "libadm.h"
+
+#define BADPID (-2)
+
+static char *prog;
+static char *deflt = NULL, *prompt = NULL, *error = NULL, *help = NULL;
+static int kpid = BADPID;
+static int signo;
+static int base = 10;
+static char *upper;
+static char *lower;
+
+static const char vusage[] = "bul";
+static const char husage[] = "bulWh";
+static const char eusage[] = "bulWe";
+
+#define USAGE "[-l lower] [-u upper] [-b base]"
+
+static void
+usage(void)
+{
+ switch (*prog) {
+ default:
+ (void) fprintf(stderr,
+ gettext("usage: %s [options] %s\n"),
+ prog, USAGE);
+ (void) fprintf(stderr, gettext(OPTMESG));
+ (void) fprintf(stderr, gettext(STDOPTS));
+ break;
+
+ case 'v':
+ (void) fprintf(stderr,
+ gettext("usage: %s %s input\n"), prog, USAGE);
+ break;
+
+ case 'h':
+ (void) fprintf(stderr,
+ gettext("usage: %s [options] %s\n"),
+ prog, USAGE);
+ (void) fprintf(stderr, gettext(OPTMESG));
+ (void) fprintf(stderr,
+ gettext("\t-W width\n\t-h help\n"));
+ break;
+
+ case 'e':
+ (void) fprintf(stderr,
+ gettext("usage: %s [options] %s\n"),
+ prog, USAGE);
+ (void) fprintf(stderr, gettext(OPTMESG));
+ (void) fprintf(stderr,
+ gettext("\t-W width\n\t-e error\n"));
+ break;
+ }
+ exit(1);
+}
+
+/*
+ * Given argv[0], return a pointer to the basename of the program.
+ */
+static char *
+prog_name(char *arg0)
+{
+ char *str;
+
+ /* first strip trailing '/' characters (exec() allows these!) */
+ str = arg0 + strlen(arg0);
+ while (str > arg0 && *--str == '/')
+ *str = '\0';
+ if ((str = strrchr(arg0, '/')) != NULL)
+ return (str + 1);
+ return (arg0);
+}
+
+int
+main(int argc, char **argv)
+{
+ int c, n;
+ long lvalue, uvalue, intval;
+ char *ptr = 0;
+
+ (void) setlocale(LC_ALL, "");
+
+#if !defined(TEXT_DOMAIN)
+#define TEXT_DOMAIN "SYS_TEST"
+#endif
+ (void) textdomain(TEXT_DOMAIN);
+
+ prog = prog_name(argv[0]);
+
+ while ((c = getopt(argc, argv, "l:u:b:d:p:e:h:k:s:QW:?")) != EOF) {
+ /* check for invalid option */
+ if ((*prog == 'v') && !strchr(vusage, c))
+ usage();
+ if ((*prog == 'e') && !strchr(eusage, c))
+ usage();
+ if ((*prog == 'h') && !strchr(husage, c))
+ usage();
+
+ switch (c) {
+ case 'Q':
+ ckquit = 0;
+ break;
+
+ case 'W':
+ ckwidth = atoi(optarg);
+ if (ckwidth < 0) {
+ (void) fprintf(stderr,
+ gettext("%s: ERROR: negative display width specified\n"),
+ prog);
+ exit(1);
+ }
+ break;
+
+ case 'b':
+ base = atoi(optarg);
+ if ((base < 2) || (base > 36)) {
+ (void) fprintf(stderr,
+ gettext("%s: ERROR: base must be between 2 and 36\n"),
+ prog);
+ exit(1);
+ }
+ break;
+
+ case 'u':
+ upper = optarg;
+ break;
+
+ case 'l':
+ lower = optarg;
+ break;
+
+ case 'd':
+ deflt = optarg;
+ break;
+
+ case 'p':
+ prompt = optarg;
+ break;
+
+ case 'e':
+ error = optarg;
+ break;
+
+ case 'h':
+ help = optarg;
+ break;
+
+ case 'k':
+ kpid = atoi(optarg);
+ break;
+
+ case 's':
+ signo = atoi(optarg);
+ break;
+
+ default:
+ usage();
+ }
+ }
+
+ if (signo) {
+ if (kpid == BADPID)
+ usage();
+ } else
+ signo = SIGTERM;
+
+ if (upper) {
+ uvalue = strtol(upper, &ptr, base);
+ if (ptr == upper) {
+ (void) fprintf(stderr,
+ gettext("%s: ERROR: invalid upper value specification\n"),
+ prog);
+ exit(1);
+ }
+ } else
+ uvalue = LONG_MAX;
+ if (lower) {
+ lvalue = strtol(lower, &ptr, base);
+ if (ptr == lower) {
+ (void) fprintf(stderr,
+ gettext("%s: ERROR: invalid lower value specification\n"),
+ prog);
+ exit(1);
+ }
+ } else
+ lvalue = LONG_MIN;
+
+ if (uvalue < lvalue) {
+ (void) fprintf(stderr,
+ gettext("%s: ERROR: upper value is less than lower value\n"),
+ prog);
+ exit(1);
+ }
+
+ if (*prog == 'v') {
+ if (argc != (optind+1))
+ usage();
+ exit(ckrange_val(lvalue, uvalue, base, argv[optind]));
+ }
+
+ if (optind != argc)
+ usage();
+
+ if (*prog == 'e') {
+ ckindent = 0;
+ ckrange_err(lvalue, uvalue, base, error);
+ exit(0);
+ } else if (*prog == 'h') {
+ ckindent = 0;
+ ckrange_hlp(lvalue, uvalue, base, help);
+ exit(0);
+ }
+
+ n = ckrange(&intval, lvalue, uvalue, (short)base,
+ deflt, error, help, prompt); /* libadm interface */
+ if (n == 3) {
+ if (kpid > -2)
+ (void) kill(kpid, signo);
+ (void) puts("q");
+ } else if (n == 0)
+ (void) printf("%ld", intval);
+ return (n);
+}
diff --git a/usr/src/cmd/valtools/ckstr.c b/usr/src/cmd/valtools/ckstr.c
new file mode 100644
index 0000000000..1036f4bc33
--- /dev/null
+++ b/usr/src/cmd/valtools/ckstr.c
@@ -0,0 +1,271 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/*
+ * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#pragma ident "%Z%%M% %I% %E% SMI"
+
+#include <stdio.h>
+#include <string.h>
+#include <signal.h>
+#include <stdlib.h>
+#include <locale.h>
+#include <libintl.h>
+#include <limits.h>
+#include "usage.h"
+#include "libadm.h"
+
+#define BADPID (-2)
+#define MAXREGEXP 128
+
+static char *prog;
+static char *deflt = NULL, *prompt = NULL, *error = NULL, *help = NULL;
+static int kpid = BADPID;
+static int signo, length;
+
+static const char vusage[] = "rl";
+static const char husage[] = "rlWh";
+static const char eusage[] = "rlWe";
+
+#define USAGE "[-l length] [[-r regexp] [...]]"
+
+static void
+usage(void)
+{
+ switch (*prog) {
+ default:
+ (void) fprintf(stderr,
+ gettext("usage: %s [options] %s\n"),
+ prog, USAGE);
+ (void) fprintf(stderr, gettext(OPTMESG));
+ (void) fprintf(stderr, gettext(STDOPTS));
+ break;
+
+ case 'v':
+ (void) fprintf(stderr,
+ gettext("usage: %s %s input\n"), prog, USAGE);
+ break;
+
+ case 'h':
+ (void) fprintf(stderr,
+ gettext("usage: %s [options] %s\n"),
+ prog, USAGE);
+ (void) fprintf(stderr, gettext(OPTMESG));
+ (void) fprintf(stderr,
+ gettext("\t-W width\n\t-h help\n"));
+ break;
+
+ case 'e':
+ (void) fprintf(stderr,
+ gettext("usage: %s [options] %s\n"),
+ prog, USAGE);
+ (void) fprintf(stderr, gettext(OPTMESG));
+ (void) fprintf(stderr,
+ gettext("\t-W width\n\t-e error\n"));
+ break;
+ }
+ exit(1);
+}
+
+/*
+ * Given argv[0], return a pointer to the basename of the program.
+ */
+static char *
+prog_name(char *arg0)
+{
+ char *str;
+
+ /* first strip trailing '/' characters (exec() allows these!) */
+ str = arg0 + strlen(arg0);
+ while (str > arg0 && *--str == '/')
+ *str = '\0';
+ if ((str = strrchr(arg0, '/')) != NULL)
+ return (str + 1);
+ return (arg0);
+}
+
+int
+main(int argc, char **argv)
+{
+ int c, n;
+ char *strval;
+ char **regexp;
+ size_t len;
+ size_t maxregexp = MAXREGEXP;
+ size_t nregexp = 0;
+
+ (void) setlocale(LC_ALL, "");
+
+#if !defined(TEXT_DOMAIN)
+#define TEXT_DOMAIN "SYS_TEST"
+#endif
+ (void) textdomain(TEXT_DOMAIN);
+
+ prog = prog_name(argv[0]);
+
+ regexp = (char **)calloc(maxregexp, sizeof (char *));
+ if (!regexp) {
+ (void) fprintf(stderr,
+ gettext("Not enough memory\n"));
+ exit(1);
+ }
+ while ((c = getopt(argc, argv, "r:l:d:p:e:h:k:s:QW:?")) != EOF) {
+ /* check for invalid option */
+ if ((*prog == 'v') && !strchr(vusage, c))
+ usage();
+ if ((*prog == 'e') && !strchr(eusage, c))
+ usage();
+ if ((*prog == 'h') && !strchr(husage, c))
+ usage();
+
+ switch (c) {
+ case 'Q':
+ ckquit = 0;
+ break;
+
+ case 'W':
+ ckwidth = atoi(optarg);
+ if (ckwidth < 0) {
+ (void) fprintf(stderr,
+ gettext("%s: ERROR: negative display width specified\n"),
+ prog);
+ exit(1);
+ }
+ break;
+
+ case 'r':
+ regexp[nregexp++] = optarg;
+ if (nregexp == maxregexp) {
+ maxregexp += MAXREGEXP;
+ regexp = (char **)realloc(regexp,
+ maxregexp * sizeof (char *));
+ if (!regexp) {
+ (void) fprintf(stderr,
+ gettext("Not enough memory\n"));
+ exit(1);
+ }
+ (void) memset(regexp + nregexp, 0,
+ (maxregexp - nregexp) *
+ sizeof (char *));
+ }
+ break;
+
+ case 'l':
+ length = atoi(optarg);
+ if ((length <= 0) || (length > 128)) {
+ (void) fprintf(stderr,
+ gettext("%s: ERROR: length must be between 1 and 128\n"),
+ prog);
+ exit(1);
+ }
+ break;
+
+ case 'd':
+ deflt = optarg;
+ break;
+
+ case 'p':
+ prompt = optarg;
+ break;
+
+ case 'e':
+ error = optarg;
+ break;
+
+ case 'h':
+ help = optarg;
+ break;
+
+ case 'k':
+ kpid = atoi(optarg);
+ break;
+
+ case 's':
+ signo = atoi(optarg);
+ break;
+
+ default:
+ usage();
+ }
+ }
+
+ if (signo) {
+ if (kpid == BADPID)
+ usage();
+ } else
+ signo = SIGTERM;
+
+ if (*prog == 'v') {
+ if (argc != (optind+1))
+ usage();
+ if (ckstr_val(regexp, length, argv[optind]))
+ exit(1);
+ exit(0);
+ }
+
+ if (*prog == 'e') {
+ if (argc > (optind+1))
+ usage(); /* too many args */
+ ckindent = 0;
+ ckstr_err(regexp, length, error, argv[optind]);
+ exit(0);
+ }
+
+ if (optind != argc)
+ usage();
+
+ if (*prog == 'h') {
+ ckindent = 0;
+ ckstr_hlp(regexp, length, help);
+ exit(0);
+ }
+
+ regexp[nregexp] = NULL;
+
+ if (deflt) {
+ len = strlen(deflt) + 1;
+ if (len < MAX_INPUT)
+ len = MAX_INPUT;
+ } else {
+ len = MAX_INPUT;
+ }
+ strval = (char *)malloc(len);
+ if (!strval) {
+ (void) fprintf(stderr,
+ gettext("Not enough memory\n"));
+ exit(1);
+ }
+ n = ckstr(strval, regexp, length, deflt, error, help, prompt);
+ if (n == 3) {
+ if (kpid > -2)
+ (void) kill(kpid, signo);
+ (void) puts("q");
+ } else if (n == 0)
+ (void) fputs(strval, stdout);
+ return (n);
+}
diff --git a/usr/src/cmd/valtools/cktime.c b/usr/src/cmd/valtools/cktime.c
new file mode 100644
index 0000000000..338ea33f2c
--- /dev/null
+++ b/usr/src/cmd/valtools/cktime.c
@@ -0,0 +1,257 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/*
+ * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#pragma ident "%Z%%M% %I% %E% SMI"
+
+#include <stdio.h>
+#include <string.h>
+#include <signal.h>
+#include <stdlib.h>
+#include <locale.h>
+#include <libintl.h>
+#include <limits.h>
+#include "usage.h"
+#include "libadm.h"
+
+#define BADPID (-2)
+
+static char *prog;
+static char *deflt = NULL, *prompt = NULL, *error = NULL, *help = NULL;
+static int kpid = BADPID;
+static int signo;
+static char *fmt;
+
+static const char vusage[] = "f";
+static const char husage[] = "fWh";
+static const char eusage[] = "fWe";
+
+#define MYFMT \
+ "%s:ERROR:invalid format\n" \
+ "valid format descriptors are:\n" \
+ "\t%%H #hour (00-23)\n" \
+ "\t%%I #hour (00-12)\n" \
+ "\t%%M #minute (00-59)\n" \
+ "\t%%p #AM, PM, am or pm\n" \
+ "\t%%r #time as %%I:%%M:%%S %%p\n" \
+ "\t%%R #time as %%H:%%M (default)\n" \
+ "\t%%S #seconds (00-59)\n" \
+ "\t%%T #time as %%H:%%M:%%S\n"
+
+static void
+usage(void)
+{
+ switch (*prog) {
+ default:
+ (void) fprintf(stderr,
+ gettext("usage: %s [options] [-f format]\n"),
+ prog);
+ (void) fprintf(stderr, gettext(OPTMESG));
+ (void) fprintf(stderr, gettext(STDOPTS));
+ break;
+
+ case 'v':
+ (void) fprintf(stderr,
+ gettext("usage: %s [-f format] input\n"), prog);
+ break;
+
+ case 'h':
+ (void) fprintf(stderr,
+ gettext("usage: %s [options] [-f format]\n"),
+ prog);
+ (void) fprintf(stderr, gettext(OPTMESG));
+ (void) fprintf(stderr,
+ gettext("\t-W width\n\t-h help\n"));
+ break;
+
+ case 'e':
+ (void) fprintf(stderr,
+ gettext("usage: %s [options] [-f format]\n"),
+ prog);
+ (void) fprintf(stderr, gettext(OPTMESG));
+ (void) fprintf(stderr,
+ gettext("\t-W width\n\t-e error\n"));
+ break;
+ }
+ exit(1);
+}
+
+/*
+ * Given argv[0], return a pointer to the basename of the program.
+ */
+static char *
+prog_name(char *arg0)
+{
+ char *str;
+
+ /* first strip trailing '/' characters (exec() allows these!) */
+ str = arg0 + strlen(arg0);
+ while (str > arg0 && *--str == '/')
+ *str = '\0';
+ if ((str = strrchr(arg0, '/')) != NULL)
+ return (str + 1);
+ return (arg0);
+}
+
+int
+main(int argc, char **argv)
+{
+ int c, n;
+ char *tod;
+ size_t len;
+
+ (void) setlocale(LC_ALL, "");
+
+#if !defined(TEXT_DOMAIN)
+#define TEXT_DOMAIN "SYS_TEST"
+#endif
+ (void) textdomain(TEXT_DOMAIN);
+
+ prog = prog_name(argv[0]);
+
+ while ((c = getopt(argc, argv, "f:d:p:e:h:k:s:QW:?")) != EOF) {
+ /* check for invalid option */
+ if ((*prog == 'v') && !strchr(vusage, c))
+ usage();
+ if ((*prog == 'e') && !strchr(eusage, c))
+ usage();
+ if ((*prog == 'h') && !strchr(husage, c))
+ usage();
+
+ switch (c) {
+ case 'Q':
+ ckquit = 0;
+ break;
+
+ case 'W':
+ ckwidth = atoi(optarg);
+ if (ckwidth < 0) {
+ (void) fprintf(stderr,
+ gettext("%s: ERROR: negative display width specified\n"),
+ prog);
+ exit(1);
+ }
+ break;
+
+ case 'f':
+ fmt = optarg;
+ break;
+
+ case 'd':
+ deflt = optarg;
+ break;
+
+ case 'p':
+ prompt = optarg;
+ break;
+
+ case 'e':
+ error = optarg;
+ break;
+
+ case 'h':
+ help = optarg;
+ break;
+
+ case 'k':
+ kpid = atoi(optarg);
+ break;
+
+ case 's':
+ signo = atoi(optarg);
+ break;
+
+ default:
+ usage();
+ }
+ }
+
+ if (signo) {
+ if (kpid == BADPID)
+ usage();
+ } else
+ signo = SIGTERM;
+
+ if (*prog == 'v') {
+ if (argc != (optind+1))
+ usage();
+ n = cktime_val(fmt, argv[optind]);
+ /*
+ * TRANSLATION_NOTE
+ * In the below, "AM", "PM", "am", and "pm" are
+ * keywords. So, do not translate them.
+ */
+ if (n == 4)
+ (void) fprintf(stderr, gettext(MYFMT), prog);
+ exit(n);
+ }
+
+ if (optind != argc)
+ usage();
+
+ if (*prog == 'e') {
+ ckindent = 0;
+ if (cktime_err(fmt, error)) {
+ (void) fprintf(stderr, gettext(MYFMT), prog);
+ exit(4);
+ } else
+ exit(0);
+ } else if (*prog == 'h') {
+ ckindent = 0;
+ if (cktime_hlp(fmt, help)) {
+ (void) fprintf(stderr, gettext(MYFMT), prog);
+ exit(4);
+ } else
+ exit(0);
+ }
+
+ if (deflt) {
+ len = strlen(deflt) + 1;
+ if (len < MAX_INPUT)
+ len = MAX_INPUT;
+ } else {
+ len = MAX_INPUT;
+ }
+ tod = (char *)malloc(len);
+ if (!tod) {
+ (void) fprintf(stderr,
+ gettext("Not enough memory\n"));
+ exit(1);
+ }
+ n = cktime(tod, fmt, deflt, error, help, prompt);
+ if (n == 3) {
+ if (kpid > -2)
+ (void) kill(kpid, signo);
+ (void) puts("q");
+ } else if (n == 0)
+ (void) fputs(tod, stdout);
+ if (n == 4)
+ (void) fprintf(stderr, gettext(MYFMT), prog);
+ return (n);
+}
diff --git a/usr/src/cmd/valtools/ckuid.c b/usr/src/cmd/valtools/ckuid.c
new file mode 100644
index 0000000000..fa7957301c
--- /dev/null
+++ b/usr/src/cmd/valtools/ckuid.c
@@ -0,0 +1,235 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/*
+ * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#pragma ident "%Z%%M% %I% %E% SMI"
+
+#include <stdio.h>
+#include <string.h>
+#include <signal.h>
+#include <stdlib.h>
+#include <locale.h>
+#include <libintl.h>
+#include <limits.h>
+#include "usage.h"
+#include "libadm.h"
+
+#define BADPID (-2)
+
+static char *prog;
+static char *deflt = NULL, *prompt = NULL, *error = NULL, *help = NULL;
+static int kpid = BADPID;
+static int signo;
+
+static const char husage[] = "mWh";
+static const char eusage[] = "mWe";
+
+static void
+usage(void)
+{
+ switch (*prog) {
+ default:
+ (void) fprintf(stderr,
+ gettext("usage: %s [options] [-m]\n"),
+ prog);
+ (void) fprintf(stderr, gettext(OPTMESG));
+ (void) fprintf(stderr, gettext(STDOPTS));
+ break;
+
+ case 'd':
+ (void) fprintf(stderr,
+ gettext("usage: %s\n"), prog);
+ break;
+
+ case 'v':
+ (void) fprintf(stderr,
+ gettext("usage: %s input\n"), prog);
+ break;
+
+ case 'h':
+ (void) fprintf(stderr,
+ gettext("usage: %s [options] [-m]\n"),
+ prog);
+ (void) fprintf(stderr, gettext(OPTMESG));
+ (void) fprintf(stderr,
+ gettext("\t-W width\n\t-h help\n"));
+ break;
+
+ case 'e':
+ (void) fprintf(stderr,
+ gettext("usage: %s [options] [-m]\n"),
+ prog);
+ (void) fprintf(stderr, gettext(OPTMESG));
+ (void) fprintf(stderr,
+ gettext("\t-W width\n\t-e error\n"));
+ break;
+ }
+ exit(1);
+}
+
+/*
+ * Given argv[0], return a pointer to the basename of the program.
+ */
+static char *
+prog_name(char *arg0)
+{
+ char *str;
+
+ /* first strip trailing '/' characters (exec() allows these!) */
+ str = arg0 + strlen(arg0);
+ while (str > arg0 && *--str == '/')
+ *str = '\0';
+ if ((str = strrchr(arg0, '/')) != NULL)
+ return (str + 1);
+ return (arg0);
+}
+
+int
+main(int argc, char **argv)
+{
+ int c, n;
+ char *strval;
+ size_t len;
+ int disp = 0; /* display set to no-display */
+
+ (void) setlocale(LC_ALL, "");
+
+#if !defined(TEXT_DOMAIN)
+#define TEXT_DOMAIN "SYS_TEST"
+#endif
+ (void) textdomain(TEXT_DOMAIN);
+
+ prog = prog_name(argv[0]);
+
+ while ((c = getopt(argc, argv, "md:p:e:h:k:s:QW:?")) != EOF) {
+ /* check for invalid option */
+ if ((*prog == 'v') || (*prog == 'd'))
+ usage();
+ if ((*prog == 'e') && !strchr(eusage, c))
+ usage();
+ if ((*prog == 'h') && !strchr(husage, c))
+ usage();
+
+ switch (c) {
+ case 'Q':
+ ckquit = 0;
+ break;
+
+ case 'W':
+ ckwidth = atoi(optarg);
+ if (ckwidth < 0) {
+ (void) fprintf(stderr,
+ gettext("%s: ERROR: negative display width specified\n"),
+ prog);
+ exit(1);
+ }
+ break;
+
+ case 'm':
+ disp = 1;
+ break;
+
+ case 'd':
+ deflt = optarg;
+ break;
+
+ case 'p':
+ prompt = optarg;
+ break;
+
+ case 'e':
+ error = optarg;
+ break;
+
+ case 'h':
+ help = optarg;
+ break;
+
+ case 'k':
+ kpid = atoi(optarg);
+ break;
+
+ case 's':
+ signo = atoi(optarg);
+ break;
+
+ default:
+ usage();
+ }
+ }
+
+ if (signo) {
+ if (kpid == BADPID)
+ usage();
+ } else
+ signo = SIGTERM;
+
+ if (*prog == 'v') {
+ if (argc != (optind+1))
+ usage();
+ exit(ckuid_val(argv[optind]));
+ }
+
+ if (optind != argc)
+ usage();
+
+ if (*prog == 'e') {
+ ckindent = 0;
+ ckuid_err(disp, error);
+ exit(0);
+ } else if (*prog == 'h') {
+ ckindent = 0;
+ ckuid_hlp(disp, help);
+ exit(0);
+ } else if (*prog == 'd') {
+ exit(ckuid_dsp());
+ }
+
+ if (deflt) {
+ len = strlen(deflt) + 1;
+ if (len < MAX_INPUT)
+ len = MAX_INPUT;
+ } else {
+ len = MAX_INPUT;
+ }
+ strval = (char *)malloc(len);
+ if (!strval) {
+ (void) fprintf(stderr,
+ gettext("Not enough memory\n"));
+ exit(1);
+ }
+ n = ckuid(strval, disp, deflt, error, help, prompt);
+ if (n == 3) {
+ if (kpid > -2)
+ (void) kill(kpid, signo);
+ (void) puts("q");
+ } else if (n == 0)
+ (void) fputs(strval, stdout);
+ return (n);
+}
diff --git a/usr/src/cmd/valtools/ckyorn.c b/usr/src/cmd/valtools/ckyorn.c
new file mode 100644
index 0000000000..983967565b
--- /dev/null
+++ b/usr/src/cmd/valtools/ckyorn.c
@@ -0,0 +1,228 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/*
+ * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#pragma ident "%Z%%M% %I% %E% SMI"
+
+#include <stdio.h>
+#include <string.h>
+#include <signal.h>
+#include <stdlib.h>
+#include <locale.h>
+#include <libintl.h>
+#include <limits.h>
+#include "usage.h"
+#include "libadm.h"
+
+#define BADPID (-2)
+
+static char *prog;
+static char *deflt, *prompt, *error, *help;
+static int kpid = BADPID;
+static int signo;
+
+static const char husage[] = "Wh";
+static const char eusage[] = "We";
+
+static void
+usage(void)
+{
+ switch (*prog) {
+ default:
+ (void) fprintf(stderr,
+ gettext("usage: %s [options]\n"), prog);
+ (void) fprintf(stderr, gettext(OPTMESG));
+ (void) fprintf(stderr, gettext(STDOPTS));
+ break;
+
+ case 'v':
+ (void) fprintf(stderr,
+ gettext("usage: %s input\n"), prog);
+ break;
+
+ case 'h':
+ (void) fprintf(stderr,
+ gettext("usage: %s [options]\n"), prog);
+ (void) fprintf(stderr, gettext(OPTMESG));
+ (void) fprintf(stderr,
+ gettext("\t-W width\n\t-h help\n"));
+ break;
+
+ case 'e':
+ (void) fprintf(stderr,
+ gettext("usage: %s [options]\n"), prog);
+ (void) fprintf(stderr, gettext(OPTMESG));
+ (void) fprintf(stderr,
+ gettext("\t-W width\n\t-e error\n"));
+ break;
+ }
+ exit(1);
+}
+
+/*
+ * Given argv[0], return a pointer to the basename of the program.
+ */
+static char *
+prog_name(char *arg0)
+{
+ char *str;
+
+ /* first strip trailing '/' characters (exec() allows these!) */
+ str = arg0 + strlen(arg0);
+ while (str > arg0 && *--str == '/')
+ *str = '\0';
+ if ((str = strrchr(arg0, '/')) != NULL)
+ return (str + 1);
+ return (arg0);
+}
+
+int
+main(int argc, char **argv)
+{
+ int c, n;
+ char *ynval;
+ size_t len;
+
+ (void) setlocale(LC_ALL, "");
+
+#if !defined(TEXT_DOMAIN)
+#define TEXT_DOMAIN "SYS_TEST"
+#endif
+ (void) textdomain(TEXT_DOMAIN);
+
+ prog = prog_name(argv[0]);
+
+ while ((c = getopt(argc, argv, "d:p:e:h:k:s:QW:?")) != EOF) {
+ /* check for invalid option */
+ if (*prog == 'v')
+ usage();
+ if ((*prog == 'e') && !strchr(eusage, c))
+ usage();
+ if ((*prog == 'h') && !strchr(husage, c))
+ usage();
+
+ switch (c) {
+ case 'Q':
+ ckquit = 0;
+ break;
+
+ case 'W':
+ ckwidth = atoi(optarg);
+ if (ckwidth < 0) {
+ (void) fprintf(stderr,
+ gettext("%s: ERROR: negative display width specified\n"),
+ prog);
+ exit(1);
+ }
+ break;
+
+ case 'd':
+ deflt = optarg;
+ break;
+
+ case 'p':
+ prompt = optarg;
+ break;
+
+ case 'e':
+ error = optarg;
+ break;
+
+ case 'h':
+ help = optarg;
+ break;
+
+ case 'k':
+ kpid = atoi(optarg);
+ break;
+
+ case 's':
+ signo = atoi(optarg);
+ break;
+
+ default:
+ usage();
+ }
+ }
+
+ if (signo) {
+ if (kpid == BADPID)
+ usage();
+ } else
+ signo = SIGTERM;
+
+ if (*prog == 'v') {
+ if (argc != (optind + 1))
+ usage();
+ if (ckyorn_val(argv[optind]))
+ exit(1);
+ else
+ exit(0);
+ }
+
+ if (optind != argc)
+ usage();
+
+ if (*prog == 'e') {
+ ckindent = 0;
+ ckyorn_err(error);
+ exit(0);
+ } else if (*prog == 'h') {
+ ckindent = 0;
+ ckyorn_hlp(help);
+ exit(0);
+ }
+
+ if (deflt) {
+ len = strlen(deflt) + 1;
+ if (len < MAX_INPUT)
+ len = MAX_INPUT;
+ } else {
+ len = MAX_INPUT;
+ }
+ ynval = (char *)malloc(len);
+ if (!ynval) {
+ (void) fprintf(stderr,
+ gettext("Not enough memory\n"));
+ exit(1);
+ }
+ n = ckyorn(ynval, deflt, error, help, prompt);
+ if (n == 3) {
+ if (kpid > -2) {
+ if (kill(kpid, signo)) {
+ (void) fprintf(stderr,
+ gettext("Failed to send signal %d to process %d\n"),
+ signo, kpid);
+ }
+ }
+ (void) puts("q");
+ } else if (n == 0)
+ (void) fputs(ynval, stdout);
+ return (n);
+}
diff --git a/usr/src/cmd/valtools/puttext.c b/usr/src/cmd/valtools/puttext.c
new file mode 100644
index 0000000000..11e6e046d3
--- /dev/null
+++ b/usr/src/cmd/valtools/puttext.c
@@ -0,0 +1,110 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/*
+ * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#pragma ident "%Z%%M% %I% %E% SMI"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <locale.h>
+#include <libintl.h>
+#include "libadm.h"
+
+static char *prog;
+static int nflag;
+static int lmarg, rmarg;
+
+static void
+usage(void)
+{
+ (void) fprintf(stderr,
+ gettext("usage: %s [-r rmarg] [-l lmarg] string\n"),
+ prog);
+ exit(1);
+}
+
+/*
+ * Given argv[0], return a pointer to the basename of the program.
+ */
+static char *
+prog_name(char *arg0)
+{
+ char *str;
+
+ /* first strip trailing '/' characters (exec() allows these!) */
+ str = arg0 + strlen(arg0);
+ while (str > arg0 && *--str == '/')
+ *str = '\0';
+ if ((str = strrchr(arg0, '/')) != NULL)
+ return (str + 1);
+ return (arg0);
+}
+
+int
+main(int argc, char **argv)
+{
+ int c;
+
+ (void) setlocale(LC_ALL, "");
+
+#if !defined(TEXT_DOMAIN)
+#define TEXT_DOMAIN "SYS_TEST"
+#endif
+ (void) textdomain(TEXT_DOMAIN);
+
+ prog = prog_name(argv[0]);
+
+ while ((c = getopt(argc, argv, "nr:l:?")) != EOF) {
+ switch (c) {
+ case 'n':
+ nflag++;
+ break;
+
+ case 'r':
+ rmarg = atoi(optarg);
+ break;
+
+ case 'l':
+ lmarg = atoi(optarg);
+ break;
+
+ default:
+ usage();
+ }
+ }
+
+ if ((optind + 1) != argc)
+ usage();
+
+ (void) puttext(stdout, argv[optind], lmarg, rmarg);
+ if (!nflag)
+ (void) fputc('\n', stdout);
+ return (0);
+}
diff --git a/usr/src/cmd/valtools/usage.h b/usr/src/cmd/valtools/usage.h
new file mode 100644
index 0000000000..40394ca39f
--- /dev/null
+++ b/usr/src/cmd/valtools/usage.h
@@ -0,0 +1,42 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/*
+ * Copyright (c) 1999 by Sun Microsystems, Inc.
+ * All rights reserved.
+ */
+
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+#define OPTMESG "where options may include:\n"
+
+#define STDOPTS \
+ "\t-Q #quit not allowed\n" \
+ "\t-W width\n" \
+ "\t-d default\n" \
+ "\t-e error\n" \
+ "\t-h help\n" \
+ "\t-k pid [-s signo]\n" \
+ "\t-p prompt\n"