summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjtc <jtc@NetBSD.org>1994-11-14 20:11:58 +0000
committerjtc <jtc@NetBSD.org>1994-11-14 20:11:58 +0000
commit9636069c3eccd476cb2ee82b14bc228552921b27 (patch)
tree6f6821195d94e11d3c768ab18fa5a70af6f5bb26
parent423bfa0764d0420e248d94d744410bb1b35e1497 (diff)
imported from 4.4lite
-rw-r--r--usr.bin/chflags/Makefile7
-rw-r--r--usr.bin/chflags/chflags.1123
-rw-r--r--usr.bin/chflags/chflags.c180
-rw-r--r--usr.bin/jot/Makefile5
-rw-r--r--usr.bin/jot/jot.1195
-rw-r--r--usr.bin/jot/jot.c393
-rw-r--r--usr.bin/lam/Makefile5
-rw-r--r--usr.bin/lam/lam.1127
-rw-r--r--usr.bin/lam/lam.c233
9 files changed, 1268 insertions, 0 deletions
diff --git a/usr.bin/chflags/Makefile b/usr.bin/chflags/Makefile
new file mode 100644
index 00000000000..a432e5f7311
--- /dev/null
+++ b/usr.bin/chflags/Makefile
@@ -0,0 +1,7 @@
+# @(#)Makefile 8.1 (Berkeley) 6/6/93
+
+PROG= chflags
+SRCS= chflags.c stat_flags.c
+.PATH: ${.CURDIR}/../../bin/ls
+
+.include <bsd.prog.mk>
diff --git a/usr.bin/chflags/chflags.1 b/usr.bin/chflags/chflags.1
new file mode 100644
index 00000000000..79c1a72644c
--- /dev/null
+++ b/usr.bin/chflags/chflags.1
@@ -0,0 +1,123 @@
+.\" Copyright (c) 1989, 1990, 1993, 1994
+.\" The Regents of the University of California. All rights reserved.
+.\"
+.\" This code is derived from software contributed to Berkeley by
+.\" the Institute of Electrical and Electronics Engineers, Inc.
+.\"
+.\" 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.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed by the University of
+.\" California, Berkeley and its contributors.
+.\" 4. Neither the name of the University nor the names of its contributors
+.\" 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.
+.\"
+.\" @(#)chflags.1 8.2 (Berkeley) 3/31/94
+.\"
+.Dd March 31, 1994
+.Dt CHFLAGS 1
+.Os
+.Sh NAME
+.Nm chflags
+.Nd change file flags
+.Sh SYNOPSIS
+.Nm chflags
+.Oo
+.Fl R
+.Op Fl H | Fl L | Fl P
+.Oc
+.Ar flags
+.Ar file ...
+.Sh DESCRIPTION
+The
+.Nm chflags
+utility modifies the file flags of the listed files
+as specified by the
+.Ar flags
+operand.
+.Pp
+The options are as follows:
+.Bl -tag -width Ds
+.It Fl H
+If the
+.Fl R
+option is specified, symbolic links on the command line are followed.
+(Symbolic links encountered in the tree traversal are not followed.)
+.It Fl L
+If the
+.Fl R
+option is specified, all symbolic links are followed.
+.It Fl P
+If the
+.Fl R
+option is specified, no symbolic links are followed.
+.It Fl R
+Change the file flags for the file hierarchies rooted
+in the files instead of just the files themselves.
+.El
+.Pp
+Flags are a comma separated list of keywords.
+The following keywords are currently defined:
+.Bd -literal -offset indent compact
+.\"arch nothing yet.
+dump set the dump flag
+sappnd set the system append-only flag (super-user only)
+schg set the system immutable flag (super-user only)
+uappnd set the user append-only flag (owner or super-user only)
+uchg set the user immutable flag (owner or super-user only)
+.Ed
+.Pp
+Putting the letters
+.Dq no
+before an option causes the flag to be turned off.
+For example:
+.Bd -literal -offset indent compact
+nodump the file should never be dumped
+.Ed
+.Pp
+Symbolic links do not have flags, so unless the
+.Fl H
+or
+.Fl L
+option is set,
+.Nm chflags
+on a symbolic link always succeeds and has no effect.
+The
+.Fl H ,
+.Fl L
+and
+.Fl P
+options are ignored unless the
+.Fl R
+option is specified.
+In addition, these options override each other and the
+command's actions are determined by the last one specified.
+.Pp
+The
+.Nm chflags
+utility exits 0 on success, and >0 if an error occurs.
+.Sh SEE ALSO
+.Xr chflags 2 ,
+.Xr stat 2 ,
+.Xr fts 3 ,
+.Xr symlink 7
diff --git a/usr.bin/chflags/chflags.c b/usr.bin/chflags/chflags.c
new file mode 100644
index 00000000000..8abeee11883
--- /dev/null
+++ b/usr.bin/chflags/chflags.c
@@ -0,0 +1,180 @@
+/*
+ * Copyright (c) 1992, 1993, 1994
+ * The Regents of the University of California. All rights reserved.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * 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.
+ */
+
+#ifndef lint
+static char copyright[] =
+"@(#) Copyright (c) 1992, 1993, 1994\n\
+ The Regents of the University of California. All rights reserved.\n";
+#endif /* not lint */
+
+#ifndef lint
+static char sccsid[] = "@(#)chflags.c 8.5 (Berkeley) 4/1/94";
+#endif /* not lint */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <err.h>
+#include <errno.h>
+#include <fts.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+u_long string_to_flags __P((char **, u_long *, u_long *));
+void usage __P((void));
+
+int
+main(argc, argv)
+ int argc;
+ char *argv[];
+{
+ FTS *ftsp;
+ FTSENT *p;
+ u_long clear, set;
+ long val;
+ int Hflag, Lflag, Pflag, Rflag, ch, fts_options, oct, rval;
+ char *flags, *ep;
+
+ Hflag = Lflag = Pflag = Rflag = 0;
+ while ((ch = getopt(argc, argv, "HLPR")) != EOF)
+ switch (ch) {
+ case 'H':
+ Hflag = 1;
+ Lflag = Pflag = 0;
+ break;
+ case 'L':
+ Lflag = 1;
+ Hflag = Pflag = 0;
+ break;
+ case 'P':
+ Pflag = 1;
+ Hflag = Lflag = 0;
+ break;
+ case 'R':
+ Rflag = 1;
+ break;
+ case '?':
+ default:
+ usage();
+ }
+ argv += optind;
+ argc -= optind;
+
+ if (argc < 2)
+ usage();
+
+ fts_options = FTS_PHYSICAL;
+ if (Rflag) {
+ if (Hflag)
+ fts_options |= FTS_COMFOLLOW;
+ if (Lflag) {
+ fts_options &= ~FTS_PHYSICAL;
+ fts_options |= FTS_LOGICAL;
+ }
+ }
+
+ flags = *argv;
+ if (*flags >= '0' && *flags <= '7') {
+ errno = 0;
+ val = strtol(flags, &ep, 8);
+ if (val < 0)
+ errno = ERANGE;
+ if (errno)
+ err(1, "invalid flags: %s", flags);
+ if (*ep)
+ errx(1, "invalid flags: %s", flags);
+ set = val;
+ oct = 1;
+ } else {
+ if (string_to_flags(&flags, &set, &clear))
+ errx(1, "invalid flag: %s", flags);
+ clear = ~clear;
+ oct = 0;
+ }
+
+ if ((ftsp = fts_open(++argv, fts_options , 0)) == NULL)
+ err(1, NULL);
+
+ for (rval = 0; (p = fts_read(ftsp)) != NULL;) {
+ switch (p->fts_info) {
+ case FTS_D:
+ if (Rflag) /* Change it at FTS_DP. */
+ continue;
+ fts_set(ftsp, p, FTS_SKIP);
+ break;
+ case FTS_DNR: /* Warn, chflag, continue. */
+ warnx("%s: %s", p->fts_path, strerror(p->fts_errno));
+ rval = 1;
+ break;
+ case FTS_ERR: /* Warn, continue. */
+ case FTS_NS:
+ warnx("%s: %s", p->fts_path, strerror(p->fts_errno));
+ rval = 1;
+ continue;
+ case FTS_SL: /* Ignore. */
+ case FTS_SLNONE:
+ /*
+ * The only symlinks that end up here are ones that
+ * don't point to anything and ones that we found
+ * doing a physical walk.
+ */
+ continue;
+ default:
+ break;
+ }
+ if (oct) {
+ if (!chflags(p->fts_accpath, set))
+ continue;
+ } else {
+ p->fts_statp->st_flags |= set;
+ p->fts_statp->st_flags &= clear;
+ if (!chflags(p->fts_accpath, p->fts_statp->st_flags))
+ continue;
+ }
+ warn("%s", p->fts_path);
+ rval = 1;
+ }
+ if (errno)
+ err(1, "fts_read");
+ exit(rval);
+}
+
+void
+usage()
+{
+ (void)fprintf(stderr,
+ "usage: chflags [-R [-H | -L | -P]] flags file ...\n");
+ exit(1);
+}
diff --git a/usr.bin/jot/Makefile b/usr.bin/jot/Makefile
new file mode 100644
index 00000000000..83db4c00da1
--- /dev/null
+++ b/usr.bin/jot/Makefile
@@ -0,0 +1,5 @@
+# @(#)Makefile 8.1 (Berkeley) 6/6/93
+
+PROG= jot
+
+.include <bsd.prog.mk>
diff --git a/usr.bin/jot/jot.1 b/usr.bin/jot/jot.1
new file mode 100644
index 00000000000..c7dba585072
--- /dev/null
+++ b/usr.bin/jot/jot.1
@@ -0,0 +1,195 @@
+.\" Copyright (c) 1993
+.\" The Regents of the University of California. All rights reserved.
+.\"
+.\" 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.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed by the University of
+.\" California, Berkeley and its contributors.
+.\" 4. Neither the name of the University nor the names of its contributors
+.\" 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.
+.\"
+.\" @(#)jot.1 8.1 (Berkeley) 6/6/93
+.\"
+.TH JOT 1 "June 6, 1993"
+.UC 4
+.SH NAME
+jot \- print sequential or random data
+.SH SYNOPSIS
+.B jot [
+options
+.B ] [
+\fRreps \fB[\fP begin \fB[\fP end \fB[\fP s \fB] ] ] ]\fP
+.SH DESCRIPTION
+.I Jot
+is used to print out increasing, decreasing, random,
+or redundant data, usually numbers, one per line.
+The
+.I options
+are understood as follows.
+.IP \fB\-r\fP
+Generate random data instead of sequential data, the default.
+.IP \fB\-b\fP\ word
+Just print
+.I word
+repetitively.
+.IP \fB\-w\fP\ word
+Print
+.IR word
+with the generated data appended to it.
+Octal, hexadecimal, exponential, ASCII, zero padded,
+and right-adjusted representations
+are possible by using the appropriate
+.IR printf (3)
+conversion specification inside
+.IR word ,
+in which case the data are inserted rather than appended.
+.IP \fB\-c\fP
+This is an abbreviation for \fB\-w %c\fP.
+.IP \fB\-s\fP\ string
+Print data separated by
+.IR string .
+Normally, newlines separate data.
+.IP \fB\-n\fP
+Do not print the final newline normally appended to the output.
+.IP \fB\-p\fP\ precision
+Print only as many digits or characters of the data
+as indicated by the integer
+.IR precision .
+In the absence of
+.BR \-p ,
+the precision is the greater of the precisions of
+.I begin
+and
+.IR end .
+The
+.B \-p
+option is overridden by whatever appears in a
+.IR printf (3)
+conversion following
+.BR \-w .
+.PP
+The last four arguments indicate, respectively,
+the number of data, the lower bound, the upper bound,
+and the step size or, for random data, the seed.
+While at least one of them must appear,
+any of the other three may be omitted, and
+will be considered as such if given as
+.BR \- .
+Any three of these arguments determines the fourth.
+If four are specified and the given and computed values of
+.I reps
+conflict, the lower value is used.
+If fewer than three are specified, defaults are assigned
+left to right, except for
+.IR s ,
+which assumes its default unless both
+.I begin
+and
+.I end
+are given.
+.PP
+Defaults for the four arguments are, respectively,
+100, 1, 100, and 1, except that when random data are requested,
+.I s
+defaults to a seed depending upon the time of day.
+.I Reps
+is expected to be an unsigned integer,
+and if given as zero is taken to be infinite.
+.I Begin
+and
+.I end
+may be given as real numbers or as characters
+representing the corresponding value in ASCII.
+The last argument must be a real number.
+.PP
+Random numbers are obtained through
+.IR random (3).
+The name
+.I jot
+derives in part from
+.IR iota ,
+a function in APL.
+.SH EXAMPLES
+.de IC
+.IP
+.ss 36
+.ft B
+..
+.de NC
+.br
+.ss 12
+.PP
+..
+.PP
+The command
+.IC
+jot 21 \-1 1.00
+.NC
+prints 21 evenly spaced numbers increasing from \-1 to 1.
+The ASCII character set is generated with
+.IC
+jot \-c 128 0
+.NC
+and the strings xaa through xaz with
+.IC
+jot \-w xa%c 26 a
+.NC
+while 20 random 8-letter strings are produced with
+.IC
+jot \-r \-c 160 a z | rs \-g 0 8
+.NC
+Infinitely many
+.IR yes 's
+may be obtained through
+.IC
+jot \-b yes 0
+.NC
+and thirty
+.IR ed (1)
+substitution commands applying to lines 2, 7, 12, etc. is
+the result of
+.IC
+jot \-w %ds/old/new/ 30 2 \- 5
+.NC
+The stuttering sequence 9, 9, 8, 8, 7, etc. can be
+produced by suitable choice of precision and step size,
+as in
+.IC
+jot 0 9 \- \-.5
+.NC
+and a file containing exactly 1024 bytes is created with
+.IC
+jot \-b x 512 > block
+.NC
+Finally, to set tabs four spaces apart starting
+from column 10 and ending in column 132, use
+.IC
+expand \-\`jot \-s, \- 10 132 4\`
+.NC
+and to print all lines 80 characters or longer,
+.IC
+grep \`jot \-s "" \-b . 80\`
+.NC
+.SH SEE ALSO
+ed(1), expand(1), rs(1), yes(1), printf(3), random(3), expand(1)
diff --git a/usr.bin/jot/jot.c b/usr.bin/jot/jot.c
new file mode 100644
index 00000000000..442d08399f6
--- /dev/null
+++ b/usr.bin/jot/jot.c
@@ -0,0 +1,393 @@
+/*-
+ * Copyright (c) 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * 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.
+ */
+
+#ifndef lint
+static char copyright[] =
+"@(#) Copyright (c) 1993\n\
+ The Regents of the University of California. All rights reserved.\n";
+#endif /* not lint */
+
+#ifndef lint
+static char sccsid[] = "@(#)jot.c 8.1 (Berkeley) 6/6/93";
+#endif /* not lint */
+
+/*
+ * jot - print sequential or random data
+ *
+ * Author: John Kunze, Office of Comp. Affairs, UCB
+ */
+
+#include <ctype.h>
+#include <limits.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+
+#define REPS_DEF 100
+#define BEGIN_DEF 1
+#define ENDER_DEF 100
+#define STEP_DEF 1
+
+#define isdefault(s) (strcmp((s), "-") == 0)
+
+double begin;
+double ender;
+double s;
+long reps;
+int randomize;
+int infinity;
+int boring;
+int prec;
+int dox;
+int chardata;
+int nofinalnl;
+char *sepstring = "\n";
+char format[BUFSIZ];
+
+void error __P((char *, char *));
+void getargs __P((int, char *[]));
+void getformat __P((void));
+int getprec __P((char *));
+void putdata __P((double, long));
+
+int
+main(argc, argv)
+ int argc;
+ char *argv[];
+{
+ double xd, yd;
+ long id;
+ register double *x = &xd;
+ register double *y = &yd;
+ register long *i = &id;
+
+ getargs(argc, argv);
+ if (randomize) {
+ *x = (ender - begin) * (ender > begin ? 1 : -1);
+ srandom((int) s);
+ for (*i = 1; *i <= reps || infinity; (*i)++) {
+ *y = (double) random() / INT_MAX;
+ putdata(*y * *x + begin, reps - *i);
+ }
+ }
+ else
+ for (*i = 1, *x = begin; *i <= reps || infinity; (*i)++, *x += s)
+ putdata(*x, reps - *i);
+ if (!nofinalnl)
+ putchar('\n');
+ exit(0);
+}
+
+void
+getargs(ac, av)
+ int ac;
+ char *av[];
+{
+ register unsigned int mask = 0;
+ register int n = 0;
+
+ while (--ac && **++av == '-' && !isdefault(*av))
+ switch ((*av)[1]) {
+ case 'r':
+ randomize = 1;
+ break;
+ case 'c':
+ chardata = 1;
+ break;
+ case 'n':
+ nofinalnl = 1;
+ break;
+ case 'b':
+ boring = 1;
+ case 'w':
+ if ((*av)[2])
+ strcpy(format, *av + 2);
+ else if (!--ac)
+ error("Need context word after -w or -b", "");
+ else
+ strcpy(format, *++av);
+ break;
+ case 's':
+ if ((*av)[2])
+ strcpy(sepstring, *av + 2);
+ else if (!--ac)
+ error("Need string after -s", "");
+ else
+ strcpy(sepstring, *++av);
+ break;
+ case 'p':
+ if ((*av)[2])
+ prec = atoi(*av + 2);
+ else if (!--ac)
+ error("Need number after -p", "");
+ else
+ prec = atoi(*++av);
+ if (prec <= 0)
+ error("Bad precision value", "");
+ break;
+ default:
+ error("Unknown option %s", *av);
+ }
+
+ switch (ac) { /* examine args right to left, falling thru cases */
+ case 4:
+ if (!isdefault(av[3])) {
+ if (!sscanf(av[3], "%lf", &s))
+ error("Bad s value: %s", av[3]);
+ mask |= 01;
+ }
+ case 3:
+ if (!isdefault(av[2])) {
+ if (!sscanf(av[2], "%lf", &ender))
+ ender = av[2][strlen(av[2])-1];
+ mask |= 02;
+ if (!prec)
+ n = getprec(av[2]);
+ }
+ case 2:
+ if (!isdefault(av[1])) {
+ if (!sscanf(av[1], "%lf", &begin))
+ begin = av[1][strlen(av[1])-1];
+ mask |= 04;
+ if (!prec)
+ prec = getprec(av[1]);
+ if (n > prec) /* maximum precision */
+ prec = n;
+ }
+ case 1:
+ if (!isdefault(av[0])) {
+ if (!sscanf(av[0], "%ld", &reps))
+ error("Bad reps value: %s", av[0]);
+ mask |= 010;
+ }
+ break;
+ case 0:
+ error("jot - print sequential or random data", "");
+ default:
+ error("Too many arguments. What do you mean by %s?", av[4]);
+ }
+ getformat();
+ while (mask) /* 4 bit mask has 1's where last 4 args were given */
+ switch (mask) { /* fill in the 0's by default or computation */
+ case 001:
+ reps = REPS_DEF;
+ mask = 011;
+ break;
+ case 002:
+ reps = REPS_DEF;
+ mask = 012;
+ break;
+ case 003:
+ reps = REPS_DEF;
+ mask = 013;
+ break;
+ case 004:
+ reps = REPS_DEF;
+ mask = 014;
+ break;
+ case 005:
+ reps = REPS_DEF;
+ mask = 015;
+ break;
+ case 006:
+ reps = REPS_DEF;
+ mask = 016;
+ break;
+ case 007:
+ if (randomize) {
+ reps = REPS_DEF;
+ mask = 0;
+ break;
+ }
+ if (s == 0.0) {
+ reps = 0;
+ mask = 0;
+ break;
+ }
+ reps = (ender - begin + s) / s;
+ if (reps <= 0)
+ error("Impossible stepsize", "");
+ mask = 0;
+ break;
+ case 010:
+ begin = BEGIN_DEF;
+ mask = 014;
+ break;
+ case 011:
+ begin = BEGIN_DEF;
+ mask = 015;
+ break;
+ case 012:
+ s = (randomize ? time(0) : STEP_DEF);
+ mask = 013;
+ break;
+ case 013:
+ if (randomize)
+ begin = BEGIN_DEF;
+ else if (reps == 0)
+ error("Must specify begin if reps == 0", "");
+ begin = ender - reps * s + s;
+ mask = 0;
+ break;
+ case 014:
+ s = (randomize ? time(0) : STEP_DEF);
+ mask = 015;
+ break;
+ case 015:
+ if (randomize)
+ ender = ENDER_DEF;
+ else
+ ender = begin + reps * s - s;
+ mask = 0;
+ break;
+ case 016:
+ if (randomize)
+ s = time(0);
+ else if (reps == 0)
+ error("Infinite sequences cannot be bounded",
+ "");
+ else if (reps == 1)
+ s = 0.0;
+ else
+ s = (ender - begin) / (reps - 1);
+ mask = 0;
+ break;
+ case 017: /* if reps given and implied, */
+ if (!randomize && s != 0.0) {
+ long t = (ender - begin + s) / s;
+ if (t <= 0)
+ error("Impossible stepsize", "");
+ if (t < reps) /* take lesser */
+ reps = t;
+ }
+ mask = 0;
+ break;
+ default:
+ error("Bad mask", "");
+ }
+ if (reps == 0)
+ infinity = 1;
+}
+
+void
+putdata(x, notlast)
+ double x;
+ long notlast;
+{
+ long d = x;
+ register long *dp = &d;
+
+ if (boring) /* repeated word */
+ printf(format);
+ else if (dox) /* scalar */
+ printf(format, *dp);
+ else /* real */
+ printf(format, x);
+ if (notlast != 0)
+ fputs(sepstring, stdout);
+}
+
+void
+error(msg, s)
+ char *msg, *s;
+{
+ fprintf(stderr, "jot: ");
+ fprintf(stderr, msg, s);
+ fprintf(stderr,
+ "\nusage: jot [ options ] [ reps [ begin [ end [ s ] ] ] ]\n");
+ if (strncmp("jot - ", msg, 6) == 0)
+ fprintf(stderr, "Options:\n\t%s\t%s\t%s\t%s\t%s\t%s\t%s",
+ "-r random data\n",
+ "-c character data\n",
+ "-n no final newline\n",
+ "-b word repeated word\n",
+ "-w word context word\n",
+ "-s string data separator\n",
+ "-p precision number of characters\n");
+ exit(1);
+}
+
+int
+getprec(s)
+ char *s;
+{
+ register char *p;
+ register char *q;
+
+ for (p = s; *p; p++)
+ if (*p == '.')
+ break;
+ if (!*p)
+ return (0);
+ for (q = ++p; *p; p++)
+ if (!isdigit(*p))
+ break;
+ return (p - q);
+}
+
+void
+getformat()
+{
+ register char *p;
+
+ if (boring) /* no need to bother */
+ return;
+ for (p = format; *p; p++) /* look for '%' */
+ if (*p == '%' && *(p+1) != '%') /* leave %% alone */
+ break;
+ if (!*p && !chardata)
+ sprintf(p, "%%.%df", prec);
+ else if (!*p && chardata) {
+ strcpy(p, "%c");
+ dox = 1;
+ }
+ else if (!*(p+1))
+ strcat(format, "%"); /* cannot end in single '%' */
+ else {
+ while (!isalpha(*p))
+ p++;
+ switch (*p) {
+ case 'f': case 'e': case 'g': case '%':
+ break;
+ case 's':
+ error("Cannot convert numeric data to strings", "");
+ break;
+ /* case 'd': case 'o': case 'x': case 'D': case 'O': case 'X':
+ case 'c': case 'u': */
+ default:
+ dox = 1;
+ break;
+ }
+ }
+}
diff --git a/usr.bin/lam/Makefile b/usr.bin/lam/Makefile
new file mode 100644
index 00000000000..a24fc9219e7
--- /dev/null
+++ b/usr.bin/lam/Makefile
@@ -0,0 +1,5 @@
+# @(#)Makefile 8.1 (Berkeley) 6/6/93
+
+PROG= lam
+
+.include <bsd.prog.mk>
diff --git a/usr.bin/lam/lam.1 b/usr.bin/lam/lam.1
new file mode 100644
index 00000000000..660e5dc9712
--- /dev/null
+++ b/usr.bin/lam/lam.1
@@ -0,0 +1,127 @@
+.\" Copyright (c) 1993
+.\" The Regents of the University of California. All rights reserved.
+.\"
+.\" 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.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed by the University of
+.\" California, Berkeley and its contributors.
+.\" 4. Neither the name of the University nor the names of its contributors
+.\" 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.
+.\"
+.\" @(#)lam.1 8.1 (Berkeley) 6/6/93
+.\"
+.TH LAM 1 "June 6, 1993"
+.UC 4
+.SH NAME
+lam \- laminate files
+.SH SYNOPSIS
+.B lam [ \-[fp]
+min.max
+.B ] [ \-s
+sepstring
+.B ] [ \-t
+c
+.B ]
+file ...
+.SH DESCRIPTION
+.I Lam
+copies the named files side by side onto the standard output.
+The
+.IR n -th
+input lines from the input
+.IR file s
+are considered fragments of the single long
+.IR n -th
+output line into which they are assembled.
+The name `\fB\-\fP' means the standard input, and may be repeated.
+.PP
+Normally, each option affects only the
+.I file
+after it.
+If the option letter is capitalized it affects all subsequent files
+until it appears again uncapitalized.
+The options are described below.
+.IP \fB\-f\fP\ min.max
+Print line fragments according to the format string
+.IR min.max ,
+where
+.I min
+is the minimum field width and
+.I max
+the maximum field width.
+If
+.I min
+begins with a zero, zeros will be added to make up the field width,
+and if it begins with a `\-', the fragment will be left-adjusted
+within the field.
+.IP \fB\-p\fP\ min.max
+Like \fB\-f\fP,
+but pad this file's field when end-of-file is reached
+and other files are still active.
+.IP \fB\-s\fP\ sepstring
+Print
+.I sepstring
+before printing line fragments from the next file.
+This option may appear after the last file.
+.IP \fB\-t\fP\ c
+The input line terminator is
+.I c
+instead of a newline.
+The newline normally appended to each output line is omitted.
+.PP
+To print files simultaneously for easy viewing use
+.IR pr (1).
+.SH EXAMPLES
+.de IC
+.IP
+.ss 36
+.ft B
+..
+.de NC
+.br
+.ss 12
+.PP
+..
+.PP
+The command
+.IC
+lam file1 file2 file3 file4
+.NC
+joins 4 files together along each line.
+To merge the lines from four different files use
+.IC
+lam file1 \-S "\\
+.br
+" file2 file3 file4
+.NC
+Every 2 lines of a file may be joined on one line with
+.IC
+lam \- \- < file
+.NC
+and a form letter with substitutions keyed by `@' can be done with
+.IC
+lam \-t @ letter changes
+.NC
+.SH SEE ALSO
+join(1), pr(1), printf(3)
diff --git a/usr.bin/lam/lam.c b/usr.bin/lam/lam.c
new file mode 100644
index 00000000000..07d6abb1f7f
--- /dev/null
+++ b/usr.bin/lam/lam.c
@@ -0,0 +1,233 @@
+/*-
+ * Copyright (c) 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * 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.
+ */
+
+#ifndef lint
+static char copyright[] =
+"@(#) Copyright (c) 1993\n\
+ The Regents of the University of California. All rights reserved.\n";
+#endif /* not lint */
+
+#ifndef lint
+static char sccsid[] = "@(#)lam.c 8.1 (Berkeley) 6/6/93";
+#endif /* not lint */
+
+/*
+ * lam - laminate files
+ * Author: John Kunze, UCB
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#define MAXOFILES 20
+#define BIGBUFSIZ 5 * BUFSIZ
+
+struct openfile { /* open file structure */
+ FILE *fp; /* file pointer */
+ short eof; /* eof flag */
+ short pad; /* pad flag for missing columns */
+ char eol; /* end of line character */
+ char *sepstring; /* string to print before each line */
+ char *format; /* printf(3) style string spec. */
+} input[MAXOFILES];
+
+int morefiles; /* set by getargs(), changed by gatherline() */
+int nofinalnl; /* normally append \n to each output line */
+char line[BIGBUFSIZ];
+char *linep;
+
+void error __P((char *, char *));
+char *gatherline __P((struct openfile *));
+void getargs __P((char *[]));
+char *pad __P((struct openfile *));
+
+int
+main(argc, argv)
+ int argc;
+ char *argv[];
+{
+ register struct openfile *ip;
+
+ getargs(argv);
+ if (!morefiles)
+ error("lam - laminate files", "");
+ for (;;) {
+ linep = line;
+ for (ip = input; ip->fp != NULL; ip++)
+ linep = gatherline(ip);
+ if (!morefiles)
+ exit(0);
+ fputs(line, stdout);
+ fputs(ip->sepstring, stdout);
+ if (!nofinalnl)
+ putchar('\n');
+ }
+}
+
+void
+getargs(av)
+ char *av[];
+{
+ register struct openfile *ip = input;
+ register char *p;
+ register char *c;
+ static char fmtbuf[BUFSIZ];
+ char *fmtp = fmtbuf;
+ int P, S, F, T;
+
+ P = S = F = T = 0; /* capitalized options */
+ while ((p = *++av) != NULL) {
+ if (*p != '-' || !p[1]) {
+ morefiles++;
+ if (*p == '-')
+ ip->fp = stdin;
+ else if ((ip->fp = fopen(p, "r")) == NULL) {
+ perror(p);
+ exit(1);
+ }
+ ip->pad = P;
+ if (!ip->sepstring)
+ ip->sepstring = (S ? (ip-1)->sepstring : "");
+ if (!ip->format)
+ ip->format = ((P || F) ? (ip-1)->format : "%s");
+ if (!ip->eol)
+ ip->eol = (T ? (ip-1)->eol : '\n');
+ ip++;
+ continue;
+ }
+ switch (*(c = ++p) | 040) {
+ case 's':
+ if (*++p || (p = *++av))
+ ip->sepstring = p;
+ else
+ error("Need string after -%s", c);
+ S = (*c == 'S' ? 1 : 0);
+ break;
+ case 't':
+ if (*++p || (p = *++av))
+ ip->eol = *p;
+ else
+ error("Need character after -%s", c);
+ T = (*c == 'T' ? 1 : 0);
+ nofinalnl = 1;
+ break;
+ case 'p':
+ ip->pad = 1;
+ P = (*c == 'P' ? 1 : 0);
+ case 'f':
+ F = (*c == 'F' ? 1 : 0);
+ if (*++p || (p = *++av)) {
+ fmtp += strlen(fmtp) + 1;
+ if (fmtp > fmtbuf + BUFSIZ)
+ error("No more format space", "");
+ sprintf(fmtp, "%%%ss", p);
+ ip->format = fmtp;
+ }
+ else
+ error("Need string after -%s", c);
+ break;
+ default:
+ error("What do you mean by -%s?", c);
+ break;
+ }
+ }
+ ip->fp = NULL;
+ if (!ip->sepstring)
+ ip->sepstring = "";
+}
+
+char *
+pad(ip)
+ struct openfile *ip;
+{
+ register char *p = ip->sepstring;
+ register char *lp = linep;
+
+ while (*p)
+ *lp++ = *p++;
+ if (ip->pad) {
+ sprintf(lp, ip->format, "");
+ lp += strlen(lp);
+ }
+ return (lp);
+}
+
+char *
+gatherline(ip)
+ struct openfile *ip;
+{
+ char s[BUFSIZ];
+ register int c;
+ register char *p;
+ register char *lp = linep;
+ char *end = s + BUFSIZ;
+
+ if (ip->eof)
+ return (pad(ip));
+ for (p = s; (c = fgetc(ip->fp)) != EOF && p < end; p++)
+ if ((*p = c) == ip->eol)
+ break;
+ *p = '\0';
+ if (c == EOF) {
+ ip->eof = 1;
+ if (ip->fp == stdin)
+ fclose(stdin);
+ morefiles--;
+ return (pad(ip));
+ }
+ p = ip->sepstring;
+ while (*p)
+ *lp++ = *p++;
+ sprintf(lp, ip->format, s);
+ lp += strlen(lp);
+ return (lp);
+}
+
+void
+error(msg, s)
+ char *msg, *s;
+{
+ fprintf(stderr, "lam: ");
+ fprintf(stderr, msg, s);
+ fprintf(stderr,
+"\nUsage: lam [ -[fp] min.max ] [ -s sepstring ] [ -t c ] file ...\n");
+ if (strncmp("lam - ", msg, 6) == 0)
+ fprintf(stderr, "Options:\n\t%s\t%s\t%s\t%s\t%s",
+ "-f min.max field widths for file fragments\n",
+ "-p min.max like -f, but pad missing fragments\n",
+ "-s sepstring fragment separator\n",
+"-t c input line terminator is c, no \\n after output lines\n",
+ "Capitalized options affect more than one file.\n");
+ exit(1);
+}