BSD 4.4 Lite Usr.bin Sources

This commit is contained in:
Rodney W. Grimes 1994-05-27 12:33:43 +00:00
parent efd31c5952
commit 9b50d90275
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/cvs2svn/branches/CHRISTOS/; revision=1590
1191 changed files with 259816 additions and 0 deletions

7
bin/chflags/Makefile Normal file
View file

@ -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>

123
bin/chflags/chflags.1 Normal file
View file

@ -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

180
bin/chflags/chflags.c Normal file
View file

@ -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);
}

View file

@ -0,0 +1,102 @@
# Towers of Hanoi in sed.
#
# @(#)hanoi.sed 8.1 (Berkeley) 6/6/93
#
#
# Ex:
# Run "sed -f hanoi.sed", and enter:
#
# :abcd: : :<CR><CR>
#
# note -- TWO carriage returns, a peculiarity of sed), this will output the
# sequence of states involved in moving 4 rings, the largest called "a" and
# the smallest called "d", from the first to the second of three towers, so
# that the rings on any tower at any time are in descending order of size.
# You can start with a different arrangement and a different number of rings,
# say :ce:b:ax: and it will give the shortest procedure for moving them all
# to the middle tower. The rules are: the names of the rings must all be
# lower-case letters, they must be input within 3 fields (representing the
# towers) and delimited by 4 colons, such that the letters within each field
# are in alphabetical order (i.e. rings are in descending order of size).
#
# For the benefit of anyone who wants to figure out the script, an "internal"
# line of the form
# b:0abx:1a2b3 :2 :3x2
# has the following meaning: the material after the three markers :1, :2,
# and :3 represents the three towers; in this case the current set-up is
# ":ab : :x :". The numbers after a, b and x in these fields indicate
# that the next time it gets a chance, it will move a to tower 2, move b
# to tower 3, and move x to tower 2. The string after :0 just keeps track
# of the alphabetical order of the names of the rings. The b at the
# beginning means that it is now dealing with ring b (either about to move
# it, or re-evaluating where it should next be moved to).
#
# Although this version is "limited" to 26 rings because of the size of the
# alphabet, one could write a script using the same idea in which the rings
# were represented by arbitrary [strings][within][brackets], and in place of
# the built-in line of the script giving the order of the letters of the
# alphabet, it would accept from the user a line giving the ordering to be
# assumed, e.g. [ucbvax][decvax][hplabs][foo][bar].
#
# George Bergman
# Math, UC Berkeley 94720 USA
# cleaning, diagnostics
s/ *//g
/^$/d
/[^a-z:]/{a\
Illegal characters: use only a-z and ":". Try again.
d
}
/^:[a-z]*:[a-z]*:[a-z]*:$/!{a\
Incorrect format: use\
\ : string1 : string2 : string3 :<CR><CR>\
Try again.
d
}
/\([a-z]\).*\1/{a\
Repeated letters not allowed. Try again.
d
}
# initial formatting
h
s/[a-z]/ /g
G
s/^:\( *\):\( *\):\( *\):\n:\([a-z]*\):\([a-z]*\):\([a-z]*\):$/:1\4\2\3:2\5\1\3:3\6\1\2:0/
s/[a-z]/&2/g
s/^/abcdefghijklmnopqrstuvwxyz/
:a
s/^\(.\).*\1.*/&\1/
s/.//
/^[^:]/ba
s/\([^0]*\)\(:0.*\)/\2\1:/
s/^[^0]*0\(.\)/\1&/
:b
# outputting current state without markers
h
s/.*:1/:/
s/[123]//gp
g
:c
# establishing destinations
/^\(.\).*\1:1/td
/^\(.\).*:1[^:]*\11/s/^\(.\)\(.*\1\([a-z]\).*\)\3./\3\2\31/
/^\(.\).*:1[^:]*\12/s/^\(.\)\(.*\1\([a-z]\).*\)\3./\3\2\33/
/^\(.\).*:1[^:]*\13/s/^\(.\)\(.*\1\([a-z]\).*\)\3./\3\2\32/
/^\(.\).*:2[^:]*\11/s/^\(.\)\(.*\1\([a-z]\).*\)\3./\3\2\33/
/^\(.\).*:2[^:]*\12/s/^\(.\)\(.*\1\([a-z]\).*\)\3./\3\2\32/
/^\(.\).*:2[^:]*\13/s/^\(.\)\(.*\1\([a-z]\).*\)\3./\3\2\31/
/^\(.\).*:3[^:]*\11/s/^\(.\)\(.*\1\([a-z]\).*\)\3./\3\2\32/
/^\(.\).*:3[^:]*\12/s/^\(.\)\(.*\1\([a-z]\).*\)\3./\3\2\31/
/^\(.\).*:3[^:]*\13/s/^\(.\)\(.*\1\([a-z]\).*\)\3./\3\2\33/
bc
# iterate back to find smallest out-of-place ring
:d
s/^\(.\)\(:0[^:]*\([^:]\)\1.*:\([123]\)[^:]*\1\)\4/\3\2\4/
td
# move said ring (right, resp. left)
s/^\(.\)\(.*\)\1\([23]\)\(.*:\3[^ ]*\) /\1\2 \4\1\3/
s/^\(.\)\(.*:\([12]\)[^ ]*\) \(.*\)\1\3/\1\2\1\3\4 /
tb
s/.*/Done! Try another, or end with ^D./p
d

View file

@ -0,0 +1,163 @@
#
# @(#)math.sed 8.1 (Berkeley) 6/6/93
#
# Addition and multiplication in sed.
# ++ for a limited time only do (expr) too!!!
#
# Kevin S Braunsdorf, PUCC UNIX Group, ksb@cc.purdue.edu.
#
# Ex:
# echo "4+7*3" | sed -f %f
# make sure the expression is well formed
s/[ ]//g
/[+*\/-]$/{
a\
poorly formed expression, operator on the end
q
}
/^[+*\/]/{
a\
poorly formed expression, leading operator
q
}
# fill hold space with done token
x
s/^.*/done/
x
# main loop, process operators (*, + and () )
: loop
/^\+/{
s///
b loop
}
/^\(.*\)(\([^)]*\))\(.*\)$/{
H
s//\2/
x
s/^\(.*\)\n\(.*\)(\([^()]*\))\(.*\)$/()\2@\4@\1/
x
b loop
}
/^[0-9]*\*/b mul
/^\([0-9]*\)\+\([0-9+*]*\*[0-9]*\)$/{
s//\2+\1/
b loop
}
/^[0-9]*\+/{
s/$/=/
b add
}
x
/^done$/{
x
p
d
}
/^()/{
s///
x
G
s/\(.*\)\n\([^@]*\)@\([^@]*\)@\(.*\)/\2\1\3/
x
s/[^@]*@[^@]*@\(.*\)/\1/
x
b loop
}
i\
help, stack problem
p
x
p
q
# turn mul into add until 1*x -> x
: mul
/^0*1\*/{
s///
b loop
}
/^\([0-9]*\)0\*/{
s/^\([0-9]*\)0\*\([0-9]*\)/\1*\20/
b mul
}
s/^\([0-9]*\)1\*/\10*/
s/^\([0-9]*\)2\*/\11*/
s/^\([0-9]*\)3\*/\12*/
s/^\([0-9]*\)4\*/\13*/
s/^\([0-9]*\)5\*/\14*/
s/^\([0-9]*\)6\*/\15*/
s/^\([0-9]*\)7\*/\16*/
s/^\([0-9]*\)8\*/\17*/
s/^\([0-9]*\)9\*/\18*/
s/\*\([0-9*]*\)/*\1+\1/
b mul
# get rid of a plus term until 0+x -> x
: add
/^\+\([0-9+*]*\)=/{
s//\1/
b loop
}
/^\([0-9*]*\)\+=/{
s//\1/
b loop
}
/^\([0-9]*\)\+\([0-9*+]*\)\+=/{
s//\2+\1/
b loop
}
/^\([0-9]*\)0\+\([0-9]*\)\([0-9]\)=/{
s//\1+\2=\3/
b add
}
/^\([0-9]*\)\([0-9]\)\+\([0-9]*\)0=/{
s//\1+\3=\2/
b add
}
/^\([0-9]*\)0\+\([0-9*+]*\)\+\([0-9]*\)\([0-9]\)=/{
s//\1+\2+\3=\4/
b add
}
/^\([0-9]*\)\([0-9]\)\+\([0-9*+]*\)\+\([0-9]*\)0=/{
s//\1+\3+\4=\2/
b add
}
s/^\([0-9]*\)1\+/\10+/
s/^\([0-9]*\)2\+/\11+/
s/^\([0-9]*\)3\+/\12+/
s/^\([0-9]*\)4\+/\13+/
s/^\([0-9]*\)5\+/\14+/
s/^\([0-9]*\)6\+/\15+/
s/^\([0-9]*\)7\+/\16+/
s/^\([0-9]*\)8\+/\17+/
s/^\([0-9]*\)9\+/\18+/
s/9=\([0-9]*\)$/_=\1/
s/8=\([0-9]*\)$/9=\1/
s/7=\([0-9]*\)$/8=\1/
s/6=\([0-9]*\)$/7=\1/
s/5=\([0-9]*\)$/6=\1/
s/4=\([0-9]*\)$/5=\1/
s/3=\([0-9]*\)$/4=\1/
s/2=\([0-9]*\)$/3=\1/
s/1=\([0-9]*\)$/2=\1/
/_/{
s//_0/
: inc
s/9_/_0/
s/8_/9/
s/7_/8/
s/6_/7/
s/5_/6/
s/4_/5/
s/3_/4/
s/2_/3/
s/1_/2/
s/0_/1/
s/\+_/+1/
/_/b inc
}
b add

View file

@ -0,0 +1,552 @@
#!/bin/sh -
#
# Copyright (c) 1992 Diomidis Spinellis.
# Copyright (c) 1992, 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.
#
# @(#)sed.test 8.1 (Berkeley) 6/6/93
#
# sed Regression Tests
#
# The following files are created:
# lines[1-4], script1, script2
# Two directories *.out contain the test results
main()
{
BASE=/usr/old/bin/sed
BASELOG=sed.out
TEST=../obj/sed
TESTLOG=nsed.out
DICT=/usr/share/dict/words
test_error | more
awk 'END { for (i = 1; i < 15; i++) print "l1_" i}' </dev/null >lines1
awk 'END { for (i = 1; i < 10; i++) print "l2_" i}' </dev/null >lines2
exec 4>&1 5>&2
# Set these flags to get messages about known problems
BSD=1
GNU=0
SUN=0
tests $BASE $BASELOG
BSD=0
GNU=0
SUN=0
tests $TEST $TESTLOG
exec 1>&4 2>&5
diff -c $BASELOG $TESTLOG | more
}
tests()
{
SED=$1
DIR=$2
rm -rf $DIR
mkdir $DIR
MARK=100
test_args
test_addr
echo Testing commands
test_group
test_acid
test_branch
test_pattern
test_print
test_subst
}
mark()
{
MARK=`expr $MARK + 1`
exec 1>&4 2>&5
exec >"$DIR/${MARK}_$1"
echo "Test $1:$MARK"
# Uncomment this line to match tests with sed error messages
echo "Test $1:$MARK" >&5
}
test_args()
{
mark '1.1'
echo Testing argument parsing
echo First type
if [ $SUN -eq 1 ] ; then
echo SunOS sed prints only with -n
else
$SED 's/^/e1_/p' lines1
fi
mark '1.2' ; $SED -n 's/^/e1_/p' lines1
mark '1.3'
if [ $SUN -eq 1 ] ; then
echo SunOS sed prints only with -n
else
$SED 's/^/e1_/p' <lines1
fi
mark '1.4' ; $SED -n 's/^/e1_/p' <lines1
echo Second type
mark '1.4.1'
if [ $SUN -eq 1 ] ; then
echo SunOS sed fails this
fi
$SED -e '' <lines1
echo 's/^/s1_/p' >script1
echo 's/^/s2_/p' >script2
mark '1.5'
if [ $SUN -eq 1 ] ; then
echo SunOS sed prints only with -n
else
$SED -f script1 lines1
fi
mark '1.6'
if [ $SUN -eq 1 ] ; then
echo SunOS sed prints only with -n
else
$SED -f script1 <lines1
fi
mark '1.7'
if [ $SUN -eq 1 ] ; then
echo SunOS sed prints only with -n
else
$SED -e 's/^/e1_/p' lines1
fi
mark '1.8'
if [ $SUN -eq 1 ] ; then
echo SunOS sed prints only with -n
else
$SED -e 's/^/e1_/p' <lines1
fi
mark '1.9' ; $SED -n -f script1 lines1
mark '1.10' ; $SED -n -f script1 <lines1
mark '1.11' ; $SED -n -e 's/^/e1_/p' lines1
mark '1.12'
if [ $SUN -eq 1 ] ; then
echo SunOS sed prints only with -n
else
$SED -n -e 's/^/e1_/p' <lines1
fi
mark '1.13'
if [ $SUN -eq 1 ] ; then
echo SunOS sed prints only with -n
else
$SED -e 's/^/e1_/p' -e 's/^/e2_/p' lines1
fi
mark '1.14'
if [ $SUN -eq 1 ] ; then
echo SunOS sed prints only with -n
else
$SED -f script1 -f script2 lines1
fi
mark '1.15'
if [ $GNU -eq 1 -o $SUN -eq 1 ] ; then
echo GNU and SunOS sed fail this following older POSIX draft
else
$SED -e 's/^/e1_/p' -f script1 lines1
fi
mark '1.16'
if [ $SUN -eq 1 ] ; then
echo SunOS sed prints only with -n
else
$SED -e 's/^/e1_/p' lines1 lines1
fi
# POSIX D11.2:11251
mark '1.17' ; $SED p <lines1 lines1
cat >script1 <<EOF
#n
# A comment
p
EOF
mark '1.18' ; $SED -f script1 <lines1 lines1
}
test_addr()
{
echo Testing address ranges
mark '2.1' ; $SED -n -e '4p' lines1
mark '2.2' ; $SED -n -e '20p' lines1 lines2
mark '2.3' ; $SED -n -e '$p' lines1
mark '2.4' ; $SED -n -e '$p' lines1 lines2
mark '2.5' ; $SED -n -e '$a\
hello' /dev/null
mark '2.6' ; $SED -n -e '$p' lines1 /dev/null lines2
# Should not print anything
mark '2.7' ; $SED -n -e '20p' lines1
mark '2.8' ; $SED -n -e '0p' lines1
mark '2.9' ; $SED -n '/l1_7/p' lines1
mark '2.10' ; $SED -n ' /l1_7/ p' lines1
mark '2.11'
if [ $BSD -eq 1 ] ; then
echo BSD sed fails this test
fi
if [ $GNU -eq 1 ] ; then
echo GNU sed fails this
fi
$SED -n '\_l1\_7_p' lines1
mark '2.12' ; $SED -n '1,4p' lines1
mark '2.13' ; $SED -n '1,$p' lines1 lines2
mark '2.14' ; $SED -n '1,/l2_9/p' lines1 lines2
mark '2.15' ; $SED -n '/4/,$p' lines1 lines2
mark '2.16' ; $SED -n '/4/,20p' lines1 lines2
mark '2.17' ; $SED -n '/4/,/10/p' lines1 lines2
mark '2.18' ; $SED -n '/l2_3/,/l1_8/p' lines1 lines2
mark '2.19'
if [ $GNU -eq 1 ] ; then
echo GNU sed fails this
fi
$SED -n '12,3p' lines1 lines2
mark '2.20'
if [ $GNU -eq 1 ] ; then
echo GNU sed fails this
fi
$SED -n '/l1_7/,3p' lines1 lines2
}
test_group()
{
echo Brace and other grouping
mark '3.1' ; $SED -e '
4,12 {
s/^/^/
s/$/$/
s/_/T/
}' lines1
mark '3.2' ; $SED -e '
4,12 {
s/^/^/
/6/,/10/ {
s/$/$/
/8/ s/_/T/
}
}' lines1
mark '3.3' ; $SED -e '
4,12 !{
s/^/^/
/6/,/10/ !{
s/$/$/
/8/ !s/_/T/
}
}' lines1
mark '3.4' ; $SED -e '4,12!s/^/^/' lines1
}
test_acid()
{
echo Testing a c d and i commands
mark '4.1' ; $SED -n -e '
s/^/before_i/p
20i\
inserted
s/^/after_i/p
' lines1 lines2
mark '4.2' ; $SED -n -e '
5,12s/^/5-12/
s/^/before_a/p
/5-12/a\
appended
s/^/after_a/p
' lines1 lines2
mark '4.3'
if [ $GNU -eq 1 ] ; then
echo GNU sed fails this
fi
$SED -n -e '
s/^/^/p
/l1_/a\
appended
8,10N
s/$/$/p
' lines1 lines2
mark '4.4' ; $SED -n -e '
c\
hello
' lines1
mark '4.5' ; $SED -n -e '
8c\
hello
' lines1
mark '4.6' ; $SED -n -e '
3,14c\
hello
' lines1
# SunOS and GNU sed behave differently. We follow POSIX
# mark '4.7' ; $SED -n -e '
#8,3c\
#hello
#' lines1
mark '4.8' ; $SED d <lines1
}
test_branch()
{
echo Testing labels and branching
mark '5.1' ; $SED -n -e '
b label4
:label3
s/^/label3_/p
b end
:label4
2,12b label1
b label2
:label1
s/^/label1_/p
b
:label2
s/^/label2_/p
b label3
:end
' lines1
mark '5.2'
if [ $BSD -eq 1 ] ; then
echo BSD sed fails this test
fi
$SED -n -e '
s/l1_/l2_/
t ok
b
:ok
s/^/tested /p
' lines1 lines2
# SunOS sed behaves differently here. Clarification needed.
# mark '5.3' ; $SED -n -e '
#5,8b inside
#1,5 {
# s/^/^/p
# :inside
# s/$/$/p
#}
#' lines1
# Check that t clears the substitution done flag
mark '5.4' ; $SED -n -e '
1,8s/^/^/
t l1
:l1
t l2
s/$/$/p
b
:l2
s/^/ERROR/
' lines1
# Check that reading a line clears the substitution done flag
mark '5.5'
if [ $BSD -eq 1 ] ; then
echo BSD sed fails this test
fi
$SED -n -e '
t l2
1,8s/^/^/p
2,7N
b
:l2
s/^/ERROR/p
' lines1
mark '5.6' ; $SED 5q lines1
mark '5.7' ; $SED -e '
5i\
hello
5q' lines1
# Branch across block boundary
mark '5.8' ; $SED -e '
{
:b
}
s/l/m/
tb' lines1
}
test_pattern()
{
echo Pattern space commands
# Check that the pattern space is deleted
mark '6.1' ; $SED -n -e '
c\
changed
p
' lines1
mark '6.2' ; $SED -n -e '
4d
p
' lines1
# SunOS sed refused to print here
# mark '6.3' ; $SED -e '
#N
#N
#N
#D
#P
#4p
#' lines1
mark '6.4' ; $SED -e '
2h
3H
4g
5G
6x
6p
6x
6p
' lines1
mark '6.5' ; $SED -e '4n' lines1
mark '6.6' ; $SED -n -e '4n' lines1
}
test_print()
{
echo Testing print and file routines
awk 'END {for (i = 1; i < 256; i++) printf("%c", i);print "\n"}' \
</dev/null >lines3
# GNU and SunOS sed behave differently here
mark '7.1'
if [ $BSD -eq 1 ] ; then
echo 'BSD sed drops core on this one; TEST SKIPPED'
else
$SED -n l lines3
fi
mark '7.2' ; $SED -e '/l2_/=' lines1 lines2
rm -f lines4
mark '7.3' ; $SED -e '3,12w lines4' lines1
echo w results
cat lines4
mark '7.4' ; $SED -e '4r lines2' lines1
mark '7.5' ; $SED -e '5r /dev/dds' lines1
mark '7.6' ; $SED -e '6r /dev/null' lines1
mark '7.7'
if [ $BSD -eq 1 -o $GNU -eq 1 -o $SUN -eq 1 ] ; then
echo BSD, GNU and SunOS cannot pass this one
else
sed '200q' $DICT | sed 's$.*$s/^/&/w tmpdir/&$' >script1
rm -rf tmpdir
mkdir tmpdir
$SED -f script1 lines1
cat tmpdir/*
rm -rf tmpdir
fi
mark '7.8'
if [ $BSD -eq 1 ] ; then
echo BSD sed cannot pass 7.7
else
echo line1 > lines3
echo "" >> lines3
$SED -n -e '$p' lines3 /dev/null
fi
}
test_subst()
{
echo Testing substitution commands
mark '8.1' ; $SED -e 's/./X/g' lines1
mark '8.2' ; $SED -e 's,.,X,g' lines1
# GNU and SunOS sed thinks we are escaping . as wildcard, not as separator
# mark '8.3' ; $SED -e 's.\..X.g' lines1
# POSIX does not say that this should work
# mark '8.4' ; $SED -e 's/[/]/Q/' lines1
mark '8.4' ; $SED -e 's/[\/]/Q/' lines1
mark '8.5' ; $SED -e 's_\__X_' lines1
mark '8.6' ; $SED -e 's/./(&)/g' lines1
mark '8.7' ; $SED -e 's/./(\&)/g' lines1
mark '8.8' ; $SED -e 's/\(.\)\(.\)\(.\)/x\3x\2x\1/g' lines1
mark '8.9' ; $SED -e 's/_/u0\
u1\
u2/g' lines1
mark '8.10'
if [ $BSD -eq 1 -o $GNU -eq 1 ] ; then
echo 'BSD/GNU sed do not understand digit flags on s commands'
fi
$SED -e 's/./X/4' lines1
rm -f lines4
mark '8.11' ; $SED -e 's/1/X/w lines4' lines1
echo s wfile results
cat lines4
mark '8.12' ; $SED -e 's/[123]/X/g' lines1
mark '8.13' ; $SED -e 'y/0123456789/9876543210/' lines1
mark '8.14' ;
if [ $BSD -eq 1 -o $GNU -eq 1 -o $SUN -eq 1 ] ; then
echo BSD/GNU/SUN sed fail this test
else
$SED -e 'y10\123456789198765432\101' lines1
fi
mark '8.15' ; $SED -e '1N;2y/\n/X/' lines1
mark '8.16'
if [ $BSD -eq 1 ] ; then
echo 'BSD sed does not handle branch defined REs'
else
echo 'eeefff' | $SED -e 'p' -e 's/e/X/p' -e ':x' \
-e 's//Y/p' -e '/f/bx'
fi
}
test_error()
{
exec 0>&3 4>&1 5>&2
exec 0</dev/null
exec 2>&1
set -x
$TEST -x && exit 1
$TEST -f && exit 1
$TEST -e && exit 1
$TEST -f /dev/dds && exit 1
$TEST p /dev/dds && exit 1
$TEST -f /bin/sh && exit 1
$TEST '{' && exit 1
$TEST '{' && exit 1
$TEST '/hello/' && exit 1
$TEST '1,/hello/' && exit 1
$TEST -e '-5p' && exit 1
$TEST '/jj' && exit 1
$TEST 'a hello' && exit 1
$TEST 'a \ hello' && exit 1
$TEST 'b foo' && exit 1
$TEST 'd hello' && exit 1
$TEST 's/aa' && exit 1
$TEST 's/aa/' && exit 1
$TEST 's/a/b' && exit 1
$TEST 's/a/b/c/d' && exit 1
$TEST 's/a/b/ 1 2' && exit 1
$TEST 's/a/b/ 1 g' && exit 1
$TEST 's/a/b/w' && exit 1
$TEST 'y/aa' && exit 1
$TEST 'y/aa/b/' && exit 1
$TEST 'y/aa/' && exit 1
$TEST 'y/a/b' && exit 1
$TEST 'y/a/b/c/d' && exit 1
$TEST '!' && exit 1
$TEST supercalifrangolisticexprialidociussupercalifrangolisticexcius
set +x
exec 0>&3 1>&4 2>&5
}
main

View file

@ -0,0 +1,552 @@
#!/bin/sh -
#
# Copyright (c) 1992 Diomidis Spinellis.
# Copyright (c) 1992, 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.
#
# @(#)sed.test 8.1 (Berkeley) 6/6/93
#
# sed Regression Tests
#
# The following files are created:
# lines[1-4], script1, script2
# Two directories *.out contain the test results
main()
{
BASE=/usr/old/bin/sed
BASELOG=sed.out
TEST=../obj/sed
TESTLOG=nsed.out
DICT=/usr/share/dict/words
test_error | more
awk 'END { for (i = 1; i < 15; i++) print "l1_" i}' </dev/null >lines1
awk 'END { for (i = 1; i < 10; i++) print "l2_" i}' </dev/null >lines2
exec 4>&1 5>&2
# Set these flags to get messages about known problems
BSD=1
GNU=0
SUN=0
tests $BASE $BASELOG
BSD=0
GNU=0
SUN=0
tests $TEST $TESTLOG
exec 1>&4 2>&5
diff -c $BASELOG $TESTLOG | more
}
tests()
{
SED=$1
DIR=$2
rm -rf $DIR
mkdir $DIR
MARK=100
test_args
test_addr
echo Testing commands
test_group
test_acid
test_branch
test_pattern
test_print
test_subst
}
mark()
{
MARK=`expr $MARK + 1`
exec 1>&4 2>&5
exec >"$DIR/${MARK}_$1"
echo "Test $1:$MARK"
# Uncomment this line to match tests with sed error messages
echo "Test $1:$MARK" >&5
}
test_args()
{
mark '1.1'
echo Testing argument parsing
echo First type
if [ $SUN -eq 1 ] ; then
echo SunOS sed prints only with -n
else
$SED 's/^/e1_/p' lines1
fi
mark '1.2' ; $SED -n 's/^/e1_/p' lines1
mark '1.3'
if [ $SUN -eq 1 ] ; then
echo SunOS sed prints only with -n
else
$SED 's/^/e1_/p' <lines1
fi
mark '1.4' ; $SED -n 's/^/e1_/p' <lines1
echo Second type
mark '1.4.1'
if [ $SUN -eq 1 ] ; then
echo SunOS sed fails this
fi
$SED -e '' <lines1
echo 's/^/s1_/p' >script1
echo 's/^/s2_/p' >script2
mark '1.5'
if [ $SUN -eq 1 ] ; then
echo SunOS sed prints only with -n
else
$SED -f script1 lines1
fi
mark '1.6'
if [ $SUN -eq 1 ] ; then
echo SunOS sed prints only with -n
else
$SED -f script1 <lines1
fi
mark '1.7'
if [ $SUN -eq 1 ] ; then
echo SunOS sed prints only with -n
else
$SED -e 's/^/e1_/p' lines1
fi
mark '1.8'
if [ $SUN -eq 1 ] ; then
echo SunOS sed prints only with -n
else
$SED -e 's/^/e1_/p' <lines1
fi
mark '1.9' ; $SED -n -f script1 lines1
mark '1.10' ; $SED -n -f script1 <lines1
mark '1.11' ; $SED -n -e 's/^/e1_/p' lines1
mark '1.12'
if [ $SUN -eq 1 ] ; then
echo SunOS sed prints only with -n
else
$SED -n -e 's/^/e1_/p' <lines1
fi
mark '1.13'
if [ $SUN -eq 1 ] ; then
echo SunOS sed prints only with -n
else
$SED -e 's/^/e1_/p' -e 's/^/e2_/p' lines1
fi
mark '1.14'
if [ $SUN -eq 1 ] ; then
echo SunOS sed prints only with -n
else
$SED -f script1 -f script2 lines1
fi
mark '1.15'
if [ $GNU -eq 1 -o $SUN -eq 1 ] ; then
echo GNU and SunOS sed fail this following older POSIX draft
else
$SED -e 's/^/e1_/p' -f script1 lines1
fi
mark '1.16'
if [ $SUN -eq 1 ] ; then
echo SunOS sed prints only with -n
else
$SED -e 's/^/e1_/p' lines1 lines1
fi
# POSIX D11.2:11251
mark '1.17' ; $SED p <lines1 lines1
cat >script1 <<EOF
#n
# A comment
p
EOF
mark '1.18' ; $SED -f script1 <lines1 lines1
}
test_addr()
{
echo Testing address ranges
mark '2.1' ; $SED -n -e '4p' lines1
mark '2.2' ; $SED -n -e '20p' lines1 lines2
mark '2.3' ; $SED -n -e '$p' lines1
mark '2.4' ; $SED -n -e '$p' lines1 lines2
mark '2.5' ; $SED -n -e '$a\
hello' /dev/null
mark '2.6' ; $SED -n -e '$p' lines1 /dev/null lines2
# Should not print anything
mark '2.7' ; $SED -n -e '20p' lines1
mark '2.8' ; $SED -n -e '0p' lines1
mark '2.9' ; $SED -n '/l1_7/p' lines1
mark '2.10' ; $SED -n ' /l1_7/ p' lines1
mark '2.11'
if [ $BSD -eq 1 ] ; then
echo BSD sed fails this test
fi
if [ $GNU -eq 1 ] ; then
echo GNU sed fails this
fi
$SED -n '\_l1\_7_p' lines1
mark '2.12' ; $SED -n '1,4p' lines1
mark '2.13' ; $SED -n '1,$p' lines1 lines2
mark '2.14' ; $SED -n '1,/l2_9/p' lines1 lines2
mark '2.15' ; $SED -n '/4/,$p' lines1 lines2
mark '2.16' ; $SED -n '/4/,20p' lines1 lines2
mark '2.17' ; $SED -n '/4/,/10/p' lines1 lines2
mark '2.18' ; $SED -n '/l2_3/,/l1_8/p' lines1 lines2
mark '2.19'
if [ $GNU -eq 1 ] ; then
echo GNU sed fails this
fi
$SED -n '12,3p' lines1 lines2
mark '2.20'
if [ $GNU -eq 1 ] ; then
echo GNU sed fails this
fi
$SED -n '/l1_7/,3p' lines1 lines2
}
test_group()
{
echo Brace and other grouping
mark '3.1' ; $SED -e '
4,12 {
s/^/^/
s/$/$/
s/_/T/
}' lines1
mark '3.2' ; $SED -e '
4,12 {
s/^/^/
/6/,/10/ {
s/$/$/
/8/ s/_/T/
}
}' lines1
mark '3.3' ; $SED -e '
4,12 !{
s/^/^/
/6/,/10/ !{
s/$/$/
/8/ !s/_/T/
}
}' lines1
mark '3.4' ; $SED -e '4,12!s/^/^/' lines1
}
test_acid()
{
echo Testing a c d and i commands
mark '4.1' ; $SED -n -e '
s/^/before_i/p
20i\
inserted
s/^/after_i/p
' lines1 lines2
mark '4.2' ; $SED -n -e '
5,12s/^/5-12/
s/^/before_a/p
/5-12/a\
appended
s/^/after_a/p
' lines1 lines2
mark '4.3'
if [ $GNU -eq 1 ] ; then
echo GNU sed fails this
fi
$SED -n -e '
s/^/^/p
/l1_/a\
appended
8,10N
s/$/$/p
' lines1 lines2
mark '4.4' ; $SED -n -e '
c\
hello
' lines1
mark '4.5' ; $SED -n -e '
8c\
hello
' lines1
mark '4.6' ; $SED -n -e '
3,14c\
hello
' lines1
# SunOS and GNU sed behave differently. We follow POSIX
# mark '4.7' ; $SED -n -e '
#8,3c\
#hello
#' lines1
mark '4.8' ; $SED d <lines1
}
test_branch()
{
echo Testing labels and branching
mark '5.1' ; $SED -n -e '
b label4
:label3
s/^/label3_/p
b end
:label4
2,12b label1
b label2
:label1
s/^/label1_/p
b
:label2
s/^/label2_/p
b label3
:end
' lines1
mark '5.2'
if [ $BSD -eq 1 ] ; then
echo BSD sed fails this test
fi
$SED -n -e '
s/l1_/l2_/
t ok
b
:ok
s/^/tested /p
' lines1 lines2
# SunOS sed behaves differently here. Clarification needed.
# mark '5.3' ; $SED -n -e '
#5,8b inside
#1,5 {
# s/^/^/p
# :inside
# s/$/$/p
#}
#' lines1
# Check that t clears the substitution done flag
mark '5.4' ; $SED -n -e '
1,8s/^/^/
t l1
:l1
t l2
s/$/$/p
b
:l2
s/^/ERROR/
' lines1
# Check that reading a line clears the substitution done flag
mark '5.5'
if [ $BSD -eq 1 ] ; then
echo BSD sed fails this test
fi
$SED -n -e '
t l2
1,8s/^/^/p
2,7N
b
:l2
s/^/ERROR/p
' lines1
mark '5.6' ; $SED 5q lines1
mark '5.7' ; $SED -e '
5i\
hello
5q' lines1
# Branch across block boundary
mark '5.8' ; $SED -e '
{
:b
}
s/l/m/
tb' lines1
}
test_pattern()
{
echo Pattern space commands
# Check that the pattern space is deleted
mark '6.1' ; $SED -n -e '
c\
changed
p
' lines1
mark '6.2' ; $SED -n -e '
4d
p
' lines1
# SunOS sed refused to print here
# mark '6.3' ; $SED -e '
#N
#N
#N
#D
#P
#4p
#' lines1
mark '6.4' ; $SED -e '
2h
3H
4g
5G
6x
6p
6x
6p
' lines1
mark '6.5' ; $SED -e '4n' lines1
mark '6.6' ; $SED -n -e '4n' lines1
}
test_print()
{
echo Testing print and file routines
awk 'END {for (i = 1; i < 256; i++) printf("%c", i);print "\n"}' \
</dev/null >lines3
# GNU and SunOS sed behave differently here
mark '7.1'
if [ $BSD -eq 1 ] ; then
echo 'BSD sed drops core on this one; TEST SKIPPED'
else
$SED -n l lines3
fi
mark '7.2' ; $SED -e '/l2_/=' lines1 lines2
rm -f lines4
mark '7.3' ; $SED -e '3,12w lines4' lines1
echo w results
cat lines4
mark '7.4' ; $SED -e '4r lines2' lines1
mark '7.5' ; $SED -e '5r /dev/dds' lines1
mark '7.6' ; $SED -e '6r /dev/null' lines1
mark '7.7'
if [ $BSD -eq 1 -o $GNU -eq 1 -o $SUN -eq 1 ] ; then
echo BSD, GNU and SunOS cannot pass this one
else
sed '200q' $DICT | sed 's$.*$s/^/&/w tmpdir/&$' >script1
rm -rf tmpdir
mkdir tmpdir
$SED -f script1 lines1
cat tmpdir/*
rm -rf tmpdir
fi
mark '7.8'
if [ $BSD -eq 1 ] ; then
echo BSD sed cannot pass 7.7
else
echo line1 > lines3
echo "" >> lines3
$SED -n -e '$p' lines3 /dev/null
fi
}
test_subst()
{
echo Testing substitution commands
mark '8.1' ; $SED -e 's/./X/g' lines1
mark '8.2' ; $SED -e 's,.,X,g' lines1
# GNU and SunOS sed thinks we are escaping . as wildcard, not as separator
# mark '8.3' ; $SED -e 's.\..X.g' lines1
# POSIX does not say that this should work
# mark '8.4' ; $SED -e 's/[/]/Q/' lines1
mark '8.4' ; $SED -e 's/[\/]/Q/' lines1
mark '8.5' ; $SED -e 's_\__X_' lines1
mark '8.6' ; $SED -e 's/./(&)/g' lines1
mark '8.7' ; $SED -e 's/./(\&)/g' lines1
mark '8.8' ; $SED -e 's/\(.\)\(.\)\(.\)/x\3x\2x\1/g' lines1
mark '8.9' ; $SED -e 's/_/u0\
u1\
u2/g' lines1
mark '8.10'
if [ $BSD -eq 1 -o $GNU -eq 1 ] ; then
echo 'BSD/GNU sed do not understand digit flags on s commands'
fi
$SED -e 's/./X/4' lines1
rm -f lines4
mark '8.11' ; $SED -e 's/1/X/w lines4' lines1
echo s wfile results
cat lines4
mark '8.12' ; $SED -e 's/[123]/X/g' lines1
mark '8.13' ; $SED -e 'y/0123456789/9876543210/' lines1
mark '8.14' ;
if [ $BSD -eq 1 -o $GNU -eq 1 -o $SUN -eq 1 ] ; then
echo BSD/GNU/SUN sed fail this test
else
$SED -e 'y10\123456789198765432\101' lines1
fi
mark '8.15' ; $SED -e '1N;2y/\n/X/' lines1
mark '8.16'
if [ $BSD -eq 1 ] ; then
echo 'BSD sed does not handle branch defined REs'
else
echo 'eeefff' | $SED -e 'p' -e 's/e/X/p' -e ':x' \
-e 's//Y/p' -e '/f/bx'
fi
}
test_error()
{
exec 0>&3 4>&1 5>&2
exec 0</dev/null
exec 2>&1
set -x
$TEST -x && exit 1
$TEST -f && exit 1
$TEST -e && exit 1
$TEST -f /dev/dds && exit 1
$TEST p /dev/dds && exit 1
$TEST -f /bin/sh && exit 1
$TEST '{' && exit 1
$TEST '{' && exit 1
$TEST '/hello/' && exit 1
$TEST '1,/hello/' && exit 1
$TEST -e '-5p' && exit 1
$TEST '/jj' && exit 1
$TEST 'a hello' && exit 1
$TEST 'a \ hello' && exit 1
$TEST 'b foo' && exit 1
$TEST 'd hello' && exit 1
$TEST 's/aa' && exit 1
$TEST 's/aa/' && exit 1
$TEST 's/a/b' && exit 1
$TEST 's/a/b/c/d' && exit 1
$TEST 's/a/b/ 1 2' && exit 1
$TEST 's/a/b/ 1 g' && exit 1
$TEST 's/a/b/w' && exit 1
$TEST 'y/aa' && exit 1
$TEST 'y/aa/b/' && exit 1
$TEST 'y/aa/' && exit 1
$TEST 'y/a/b' && exit 1
$TEST 'y/a/b/c/d' && exit 1
$TEST '!' && exit 1
$TEST supercalifrangolisticexprialidociussupercalifrangolisticexcius
set +x
exec 0>&3 1>&4 2>&5
}
main

38
usr.bin/Makefile Normal file
View file

@ -0,0 +1,38 @@
# @(#)Makefile 8.3 (Berkeley) 1/7/94
SUBDIR= apply apropos ar at banner basename bc bdes biff cal calendar \
cap_mkdb checknr chflags chpass cksum col colcrt colrm column \
comm compress cpp ctags cut dc deroff diction diff dirname du \
env error ex expand false file find finger fmt fold fpr from \
fsplit fstat ftp gcore gprof graph grep head hexdump id indent \
join jot kdump ktrace lam last lastcomm learn leave locate \
lock logger login logname lorder m4 mail make man mesg mkdep \
mkfifo mklocale mkstr more msgs mt netstat nfsstat nice nm nohup \
pagesize passwd paste patch plot pr printenv printf ptx quota \
ranlib rdist renice rev rlogin rs rsh ruptime rwho sccs \
script sed shar showmount size soelim sort spell spline split \
strings strip struct su talk tcopy tee telnet tftp time tip \
tn3270 touch tput tr true tset tsort tty ul uname unexpand \
unifdef uniq units unvis users uucp uudecode uuencode vacation \
vgrind vis w wall wc what whatis whereis who whois window write \
xargs xinstall xsend xstr yacc yes
# Cmp, look and tail all use mmap, so new-VM only.
# F77 and pascal are VAX/Tahoe only.
.if ${MACHINE} == "hp300"
SUBDIR+=cmp ld look systat tail vmstat
.elif ${MACHINE} == "i386"
SUBDIR+=cmp ld look systat tail vmstat
.elif ${MACHINE} == "luna68k"
SUBDIR+=cmp ld look systat tail vmstat
.elif ${MACHINE} == "mips"
SUBDIR+=cmp look systat tail vmstat
.elif ${MACHINE} == "sparc"
SUBDIR+=cmp ld look tail vmstat.sparc
.elif ${MACHINE} == "tahoe"
SUBDIR+=f77 pascal systat vmstat
.elif ${MACHINE} == "vax"
SUBDIR+=f77 pascal systat vmstat
.endif
.include <bsd.subdir.mk>

3
usr.bin/Makefile.inc Normal file
View file

@ -0,0 +1,3 @@
# @(#)Makefile.inc 8.1 (Berkeley) 6/6/93
BINDIR?= /usr/bin

5
usr.bin/apply/Makefile Normal file
View file

@ -0,0 +1,5 @@
# @(#)Makefile 8.1 (Berkeley) 6/6/93
PROG= apply
.include <bsd.prog.mk>

129
usr.bin/apply/apply.1 Normal file
View file

@ -0,0 +1,129 @@
.\" Copyright (c) 1983, 1990, 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.
.\"
.\" @(#)apply.1 8.2 (Berkeley) 4/4/94
.\"
.Dd April 4, 1994
.Dt APPLY 1
.Os BSD 4.2
.Sh NAME
.Nm apply
.Nd apply a command to a set of arguments
.Sh SYNOPSIS
.Nm apply
.Op Fl a Ns Ar c
.Op Fl Ns Ar #
.Ar command argument ...
.Sh DESCRIPTION
.Nm Apply
runs the named
.Ar command
on each
argument
.Ar argument
in turn.
.Pp
Character sequences of the form
.Dq Li \&%d
in
.Ar command ,
where
.Dq Li d
is a digit from 1 to 9, are replaced by the
.Li d Ns \'th
following unused
.Ar argument .
In this case, the largest digit number of arguments are discarded for
each execution of
.Ar command .
.Pp
The options are as follows:
.Bl -tag -width "-ac"
.It Fl Ns Ar #
Normally arguments are taken singly; the optional number
.Fl #
specifies the number of arguments to be passed to
.Ar command .
If the number is zero,
.Ar command
is run, without arguments, once for each
.Ar argument .
.Pp
If any sequences of
.Dq Li \&%d
occur in command, the
.Fl n
option is ignored.
.It Fl a Ns Ar c
The use of the character
.Dq Li %
as a magic character may be changed with the
.Fl a
option.
.El
.Sh ENVIRONMENT VARIABLES
The following environment variable affects the execution of
.Nm apply :
.Bl -tag -width SHELL
.It Ev SHELL
Pathname of shell to use.
If this variable is not defined, the Bourne shell is used.
.El
.Sh EXAMPLES
.Bl -tag -width apply -compact
.It Li "apply echo a*"
is similar to ls(1);
.It Li "apply \-2 cmp a1 b1 a2 b2 a3 b3"
compares the `a' files to the `b' files;
.It Li "apply \-0 who 1 2 3 4 5"
runs who(1) 5 times; and
.It Li "apply \'ln %1 /usr/joe\'" *
links all files in the current directory to the directory
.Pa /usr/joe .
.El
.Sh Files
.Bl -tag -width /bin/sh -compact
.It Pa /bin/sh
Default shell
.El
.Sh AUTHOR
Rob Pike
.Sh BUGS
Shell metacharacters in
.Ar command
may have bizarre effects; it is best to enclose complicated
commands in single quotes
.Pq Sq .
.Sh HISTORY
The
.Nm
command appeared in
.Bx 4.2 .

234
usr.bin/apply/apply.c Normal file
View file

@ -0,0 +1,234 @@
/*-
* Copyright (c) 1994
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Jan-Simon Pendry.
*
* 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 sccsid[] = "@(#)apply.c 8.4 (Berkeley) 4/4/94";
#endif /* not lint */
#include <sys/wait.h>
#include <ctype.h>
#include <err.h>
#include <paths.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
void usage __P((void));
int system __P((const char *));
int
main(argc, argv)
int argc;
char *argv[];
{
int ch, clen, debug, i, l, magic, n, nargs, rval;
char *c, *cmd, *p, *q;
debug = 0;
magic = '%'; /* Default magic char is `%'. */
nargs = -1;
while ((ch = getopt(argc, argv, "a:d0123456789")) != EOF)
switch (ch) {
case 'a':
if (optarg[1] != '\0')
errx(1,
"illegal magic character specification.");
magic = optarg[0];
break;
case 'd':
debug = 1;
break;
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
if (nargs != -1)
errx(1,
"only one -# argument may be specified.");
nargs = optopt - '0';
break;
default:
usage();
}
argc -= optind;
argv += optind;
if (argc < 2)
usage();
/*
* The command to run is argv[0], and the args are argv[1..].
* Look for %digit references in the command, remembering the
* largest one.
*/
for (n = 0, p = argv[0]; *p != '\0'; ++p)
if (p[0] == magic && isdigit(p[1]) && p[1] != '0') {
++p;
if (p[0] - '0' > n)
n = p[0] - '0';
}
/*
* If there were any %digit references, then use those, otherwise
* build a new command string with sufficient %digit references at
* the end to consume (nargs) arguments each time round the loop.
* Allocate enough space to hold the maximum command.
*/
if ((cmd = malloc(sizeof("exec ") - 1 +
strlen(argv[0]) + 9 * (sizeof(" %1") - 1) + 1)) == NULL)
err(1, NULL);
if (n == 0) {
/* If nargs not set, default to a single argument. */
if (nargs == -1)
nargs = 1;
p = cmd;
p += sprintf(cmd, "exec %s", argv[0]);
for (i = 1; i <= nargs; i++)
p += sprintf(p, " %c%d", magic, i);
/*
* If nargs set to the special value 0, eat a single
* argument for each command execution.
*/
if (nargs == 0)
nargs = 1;
} else {
(void)sprintf(cmd, "exec %s", argv[0]);
nargs = n;
}
/*
* Grab some space in which to build the command. Allocate
* as necessary later, but no reason to build it up slowly
* for the normal case.
*/
if ((c = malloc(clen = 1024)) == NULL)
err(1, NULL);
/*
* (argc) and (argv) are still offset by one to make it simpler to
* expand %digit references. At the end of the loop check for (argc)
* equals 1 means that all the (argv) has been consumed.
*/
for (rval = 0; argc > nargs; argc -= nargs, argv += nargs) {
/*
* Find a max value for the command length, and ensure
* there's enough space to build it.
*/
for (l = strlen(cmd), i = 0; i < nargs; i++)
l += strlen(argv[i]);
if (l > clen && (c = realloc(c, clen = l)) == NULL)
err(1, NULL);
/* Expand command argv references. */
for (p = cmd, q = c; *p != '\0'; ++p)
if (p[0] == magic && isdigit(p[1]) && p[1] != '0')
q += sprintf(q, "%s", argv[(++p)[0] - '0']);
else
*q++ = *p;
/* Terminate the command string. */
*q = '\0';
/* Run the command. */
if (debug)
(void)printf("%s\n", c);
else
if (system(c))
rval = 1;
}
if (argc != 1)
errx(1, "expecting additional argument%s after \"%s\"",
(nargs - argc) ? "s" : "", argv[argc - 1]);
exit(rval);
}
/*
* system --
* Private version of system(3). Use the user's SHELL environment
* variable as the shell to execute.
*/
int
system(command)
const char *command;
{
static char *name, *shell;
union wait pstat;
pid_t pid;
int omask;
sig_t intsave, quitsave;
if (shell == NULL) {
if ((shell = getenv("SHELL")) == NULL)
shell = _PATH_BSHELL;
if ((name = strrchr(shell, '/')) == NULL)
name = shell;
else
++name;
}
if (!command) /* just checking... */
return(1);
omask = sigblock(sigmask(SIGCHLD));
switch(pid = vfork()) {
case -1: /* error */
err(1, "fork");
case 0: /* child */
(void)sigsetmask(omask);
execl(shell, name, "-c", command, NULL);
err(1, "%s", shell);
}
intsave = signal(SIGINT, SIG_IGN);
quitsave = signal(SIGQUIT, SIG_IGN);
pid = waitpid(pid, (int *)&pstat, 0);
(void)sigsetmask(omask);
(void)signal(SIGINT, intsave);
(void)signal(SIGQUIT, quitsave);
return(pid == -1 ? -1 : pstat.w_status);
}
void
usage()
{
(void)fprintf(stderr,
"usage: apply [-a magic] [-0123456789] command arguments ...\n");
exit(1);
}

7
usr.bin/apropos/Makefile Normal file
View file

@ -0,0 +1,7 @@
# @(#)Makefile 8.1 (Berkeley) 6/6/93
PROG= apropos
SRCS= apropos.c config.c
.PATH: ${.CURDIR}/../man
.include <bsd.prog.mk>

120
usr.bin/apropos/apropos.1 Normal file
View file

@ -0,0 +1,120 @@
.\" Copyright (c) 1989, 1990, 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.
.\"
.\" @(#)apropos.1 8.1 (Berkeley) 6/29/93
.\"
.Dd June 29, 1993
.Dt APROPOS 1
.Os
.Sh NAME
.Nm apropos
.Nd locate commands by keyword lookup
.Sh SYNOPSIS
.Nm apropos
.Op Fl M Ar path
.Op Fl m Ar path
.Ar keyword ...
.Sh DESCRIPTION
.Nm Apropos
shows which manual pages contain instances of any of the given
.Ar keyword(s)
in their title line.
Each word is considered separately and case of letters is ignored.
Words which are part of other words are considered; when looking for
.Dq compile ,
.Nm apropos
will also list all instances of
.Dq compiler .
.Pp
If the line output by
.Nm apropos
starts
.Dq Li name(section) ...
you can enter
.Dq Li man section name
to get
its documentation.
.Pp
The options are as follows:
.Bl -tag -width flag
.It Fl M
Override the list of standard directories
.Nm apropos
searches for a database named
.Pa whatis.db .
The supplied
.Ar path
must be a colon
.Dq \&:
separated list of directories.
This search path may also be set using the environment variable
.Ev MANPATH .
.It Fl m
Augment the list of standard directories
.Nm apropos
searches for its database.
The supplied
.Ar path
must be a colon
.Dq \&:
separated list of directories.
These directories will be searched before the standard directories,
or the directories supplied with the
.Fl M
option or the
.Ev MANPATH
environment variable.
.Sh ENVIRONMENT
.Bl -tag -width MANPATH
.It Ev MANPATH
The standard search path used by
.Xr man 1
may be overridden by specifying a path in the
.Ev MANPATH
environment variable.
The format of the path is a colon
.Dq \&:
separated list of directories.
.El
.Sh FILES
.Bl -tag -width whatis.db -compact
.It Pa whatis.db
name of the apropos database
.El
.Sh SEE ALSO
.Xr man 1 ,
.Xr whatis 1 ,
.Xr whereis 1
.Sh HISTORY
The
.Nm apropos
command appeared in
.Bx 3.0 .

223
usr.bin/apropos/apropos.c Normal file
View file

@ -0,0 +1,223 @@
/*
* Copyright (c) 1987, 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) 1987, 1993, 1994\n\
The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */
#ifndef lint
static char sccsid[] = "@(#)apropos.c 8.7 (Berkeley) 4/2/94";
#endif /* not lint */
#include <sys/param.h>
#include <sys/queue.h>
#include <ctype.h>
#include <err.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "../man/config.h"
#include "../man/pathnames.h"
static int *found, foundman;
void apropos __P((char **, char *, int));
void lowstr __P((char *, char *));
int match __P((char *, char *));
void usage __P((void));
int
main(argc, argv)
int argc;
char *argv[];
{
ENTRY *ep;
TAG *tp;
int ch, rv;
char *conffile, **p, *p_augment, *p_path;
conffile = NULL;
p_augment = p_path = NULL;
while ((ch = getopt(argc, argv, "C:M:m:P:")) != EOF)
switch (ch) {
case 'C':
conffile = optarg;
break;
case 'M':
case 'P': /* backward compatible */
p_path = optarg;
break;
case 'm':
p_augment = optarg;
break;
case '?':
default:
usage();
}
argv += optind;
argc -= optind;
if (argc < 1)
usage();
if ((found = malloc((u_int)argc * sizeof(int))) == NULL)
err(1, NULL);
memset(found, 0, argc * sizeof(int));
for (p = argv; *p; ++p) /* convert to lower-case */
lowstr(*p, *p);
if (p_augment)
apropos(argv, p_augment, 1);
if (p_path || (p_path = getenv("MANPATH")))
apropos(argv, p_path, 1);
else {
config(conffile);
ep = (tp = getlist("_whatdb")) == NULL ?
NULL : tp->list.tqh_first;
for (; ep != NULL; ep = ep->q.tqe_next)
apropos(argv, ep->s, 0);
}
if (!foundman)
errx(1, "no %s file found", _PATH_WHATIS);
rv = 1;
for (p = argv; *p; ++p)
if (found[p - argv])
rv = 0;
else
(void)printf("%s: nothing appropriate\n", *p);
exit(rv);
}
void
apropos(argv, path, buildpath)
char **argv, *path;
int buildpath;
{
char *end, *name, **p;
char buf[LINE_MAX + 1], wbuf[LINE_MAX + 1];
for (name = path; name; name = end) { /* through name list */
if (end = strchr(name, ':'))
*end++ = '\0';
if (buildpath) {
char hold[MAXPATHLEN + 1];
(void)sprintf(hold, "%s/%s", name, _PATH_WHATIS);
name = hold;
}
if (!freopen(name, "r", stdin))
continue;
foundman = 1;
/* for each file found */
while (fgets(buf, sizeof(buf), stdin)) {
if (!strchr(buf, '\n')) {
warnx("%s: line too long", name);
continue;
}
lowstr(buf, wbuf);
for (p = argv; *p; ++p)
if (match(wbuf, *p)) {
(void)printf("%s", buf);
found[p - argv] = 1;
/* only print line once */
while (*++p)
if (match(wbuf, *p))
found[p - argv] = 1;
break;
}
}
}
}
/*
* match --
* match anywhere the string appears
*/
int
match(bp, str)
char *bp, *str;
{
int len;
char test;
if (!*bp)
return (0);
/* backward compatible: everything matches empty string */
if (!*str)
return (1);
for (test = *str++, len = strlen(str); *bp;)
if (test == *bp++ && !strncmp(bp, str, len))
return (1);
return (0);
}
/*
* lowstr --
* convert a string to lower case
*/
void
lowstr(from, to)
char *from, *to;
{
char ch;
while ((ch = *from++) && ch != '\n')
*to++ = isupper(ch) ? tolower(ch) : ch;
*to = '\0';
}
/*
* usage --
* print usage message and die
*/
void
usage()
{
(void)fprintf(stderr,
"usage: apropos [-C file] [-M path] [-m path] keyword ...\n");
exit(1);
}

16
usr.bin/ar/Makefile Normal file
View file

@ -0,0 +1,16 @@
# @(#)Makefile 8.1 (Berkeley) 6/6/93
PROG= ar
CFLAGS+=-I${.CURDIR}
SRCS= append.c ar.c archive.c contents.c delete.c extract.c misc.c \
move.c print.c replace.c
MAN1= ar.0
CLEANFILES=ar.5.0
ar.0: ar.5.0
afterinstall:
install -c -o ${MANOWN} -g ${MANGRP} -m ${MANMODE} ar.5.0 \
${DESTDIR}${MANDIR}5/ar.0
.include <bsd.prog.mk>

89
usr.bin/ar/append.c Normal file
View file

@ -0,0 +1,89 @@
/*-
* Copyright (c) 1990, 1993, 1994
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Hugh Smith at The University of Guelph.
*
* 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 sccsid[] = "@(#)append.c 8.3 (Berkeley) 4/2/94";
#endif /* not lint */
#include <sys/param.h>
#include <sys/stat.h>
#include <err.h>
#include <fcntl.h>
#include <unistd.h>
#include <dirent.h>
#include <stdio.h>
#include <string.h>
#include "archive.h"
#include "extern.h"
/*
* append --
* Append files to the archive - modifies original archive or creates
* a new archive if named archive does not exist.
*/
int
append(argv)
char **argv;
{
int afd, fd, eval;
char *file;
CF cf;
struct stat sb;
afd = open_archive(O_CREAT|O_RDWR);
if (lseek(afd, (off_t)0, SEEK_END) == (off_t)-1)
error(archive);
/* Read from disk, write to an archive; pad on write. */
SETCF(0, 0, afd, archive, WPAD);
for (eval = 0; file = *argv++;) {
if ((fd = open(file, O_RDONLY)) < 0) {
warn("%s", file);
eval = 1;
continue;
}
if (options & AR_V)
(void)printf("q - %s\n", file);
cf.rfd = fd;
cf.rname = file;
put_arobj(&cf, &sb);
(void)close(fd);
}
close_archive(afd);
return (eval);
}

257
usr.bin/ar/ar.1 Normal file
View file

@ -0,0 +1,257 @@
.\" Copyright (c) 1990, 1993
.\" The Regents of the University of California. All rights reserved.
.\"
.\" This code is derived from software contributed to Berkeley by
.\" Hugh Smith at The University of Guelph.
.\"
.\" 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.
.\"
.\" @(#)ar.1 8.1 (Berkeley) 6/29/93
.\"
.TH AR 1 "June 29, 1993"
.AT 3
.SH NAME
ar \- create and maintain library archives
.SH SYNOPSIS
.nf
.ft B
ar -d [-Tv] archive file ...
ar -m [-Tv] archive file ...
ar -m [-abiTv] position archive file ...
ar -p [-Tv] archive [file ...]
ar -q [-cTv] archive file ...
ar -r [-cuTv] archive file ...
ar -r [-abciuTv] position archive file ...
ar -t [-Tv] archive [file ...]
ar -x [-ouTv] archive [file ...]
.fi
.ft R
.SH DESCRIPTION
The
.I ar
utility creates and maintains groups of files combined into an archive.
Once an archive has been created, new files can be added and existing
files can be extracted, deleted, or replaced.
.PP
Files are named in the archive by a single component, i.e., if a file
referenced by a path containing a slash (``/'') is archived it will be
named by the last component of that path.
When matching paths listed on the command line against file names stored
in the archive, only the last component of the path will be compared.
.PP
All informational and error messages use the path listed on the command
line, if any was specified; otherwise the name in the archive is used.
If multiple files in the archive have the same name, and paths are listed
on the command line to ``select'' archive files for an operation, only the
.B first
file with a matching name will be selected.
.PP
The normal use of
.I ar
is for the creation and maintenance of libraries suitable for use with
the loader (see
.IR ld (1)),
although it is not restricted to this purpose.
The options are as follows:
.TP
\-a
A positioning modifier used with the options \-r and \-m.
The files are entered or moved
.B after
the archive member
.IR position ,
which must be specified.
.TP
\-b
A positioning modifier used with the options \-r and \-m.
The files are entered or moved
.B before
the archive member
.IR position ,
which must be specified.
.TP
\-c
Whenever an archive is created, an informational message to that effect
is written to standard error.
If the \-c option is specified,
.I ar
creates the archive silently.
.TP
\-d
Delete the specified archive files.
.TP
\-i
Identical to the \-b option.
.TP
\-m
Move the specified archive files within the archive.
If one of the options \-a, \-b or \-i is specified, the files are moved
before or after the
.I position
file in the archive.
If none of those options are specified, the files are moved
to the end of the archive.
.TP
\-o
Set the access and modification times of extracted files to the
modification time of the file when it was entered into the archive.
This will fail if the user is not the owner of the extracted file
or the super-user.
.TP
\-p
Write the contents of the specified archive files to the standard output.
If no files are specified, the contents of all the files in the archive
are written in the order they appear in the archive.
.TP
\-q
(Quickly) append the specified files to the archive.
If the archive does not exist a new archive file is created.
Much faster than the \-r option, when creating a large archive
piece-by-piece, as no checking is done to see if the files already
exist in the archive.
.TP
\-r
Replace or add the specified files to the archive.
If the archive does not exist a new archive file is created.
Files that replace existing files do not change the order of the files
within the archive.
New files are appended to the archive unless one of the options \-a, \-b
or \-i is specified.
.TP
\-T
Select and/or name archive members using only the first fifteen characters
of the archive member or command line file name.
The historic archive format had sixteen bytes for the name, but some
historic archiver and loader implementations were unable to handle names
that used the entire space.
This means that file names that are not unique in their first fifteen
characters can subsequently be confused.
A warning message is printed to the standard error output if any file
names are truncated.
(See
.IR ar (5)
for more information.)
.TP
\-t
List the specified files in the order in which they appear in the archive,
each on a separate line.
If no files are specified, all files in the archive are listed.
.TP
\-u
Update files.
When used with the \-r option, files in the archive will be replaced
only if the disk file has a newer modification time than the file in
the archive.
When used with the \-x option, files in the archive will be extracted
only if the archive file has a newer modification time than the file
on disk.
.TP
\-v
Provide verbose output.
When used with the \-d, \-m, \-q or \-x options,
.I ar
gives a file-by-file description of the archive modification.
This description consists of three, white-space separated fields: the
option letter, a dash (``-'') and the file name.
When used with the \-r option,
.I ar
displays the description as above, but the initial letter is an ``a'' if
the file is added to the archive and an ``r'' if the file replaces a file
already in the archive.
.IP
When used with the \-p option,
the name of each printed file,
enclosed in less-than (``<'') and greater-than (``>'') characters,
is written to the standard output before
the contents of the file;
it is preceded by a single newline character, and
followed by two newline characters.
.IP
When used with the \-t option,
.I ar
displays an ``ls -l'' style listing of information about the members of
the archive.
This listing consists of eight, white-space separated fields:
the file permissions (see
.IR strmode (3)),
the decimal user and group ID's separated by a single slash (``/''),
the file size (in bytes), the file modification time (in the
.IR date (1)
format ``%b %e %H:%M %Y''), and the name of the file.
.TP
\-x
Extract the specified archive members into the files named by the command
line arguments.
If no members are specified, all the members of the archive are extracted into
the current directory.
.IP
If the file does not exist, it is created; if it does exist, the owner
and group will be unchanged.
The file access and modification times are the time of the extraction
(but see the \-o option).
The file permissions will be set to those of the file when it was entered
into the archive; this will fail if the user is not the owner of the
extracted file or the super-user.
.PP
The
.I ar
utility exits 0 on success, and >0 if an error occurs.
.SH ENVIRONMENT
.TP
TMPDIR
The pathname of the directory to use when creating temporary files.
.SH FILES
.TP 14
/tmp
default temporary file directory
.TP 14
ar.XXXXXX
temporary file names
.SH COMPATIBILITY
By default,
.I ar
writes archives that may be incompatible with historic archives, as
the format used for storing archive members with names longer than
fifteen characters has changed.
This implementation of
.I ar
is backward compatible with previous versions of
.I ar
in that it can read and write (using the \-T option) historic archives.
The \-T option is provided for compatibility only, and will be deleted
in a future release.
See
.IR ar (5)
for more information.
.SH STANDARDS
The
.I ar
utility is expected to offer a superset of the POSIX 1003.2 functionality.
.SH "SEE ALSO"
ld(1), ranlib(1), strmode(3), ar(5)

257
usr.bin/ar/ar.1aout Normal file
View file

@ -0,0 +1,257 @@
.\" Copyright (c) 1990, 1993
.\" The Regents of the University of California. All rights reserved.
.\"
.\" This code is derived from software contributed to Berkeley by
.\" Hugh Smith at The University of Guelph.
.\"
.\" 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.
.\"
.\" @(#)ar.1 8.1 (Berkeley) 6/29/93
.\"
.TH AR 1 "June 29, 1993"
.AT 3
.SH NAME
ar \- create and maintain library archives
.SH SYNOPSIS
.nf
.ft B
ar -d [-Tv] archive file ...
ar -m [-Tv] archive file ...
ar -m [-abiTv] position archive file ...
ar -p [-Tv] archive [file ...]
ar -q [-cTv] archive file ...
ar -r [-cuTv] archive file ...
ar -r [-abciuTv] position archive file ...
ar -t [-Tv] archive [file ...]
ar -x [-ouTv] archive [file ...]
.fi
.ft R
.SH DESCRIPTION
The
.I ar
utility creates and maintains groups of files combined into an archive.
Once an archive has been created, new files can be added and existing
files can be extracted, deleted, or replaced.
.PP
Files are named in the archive by a single component, i.e., if a file
referenced by a path containing a slash (``/'') is archived it will be
named by the last component of that path.
When matching paths listed on the command line against file names stored
in the archive, only the last component of the path will be compared.
.PP
All informational and error messages use the path listed on the command
line, if any was specified; otherwise the name in the archive is used.
If multiple files in the archive have the same name, and paths are listed
on the command line to ``select'' archive files for an operation, only the
.B first
file with a matching name will be selected.
.PP
The normal use of
.I ar
is for the creation and maintenance of libraries suitable for use with
the loader (see
.IR ld (1)),
although it is not restricted to this purpose.
The options are as follows:
.TP
\-a
A positioning modifier used with the options \-r and \-m.
The files are entered or moved
.B after
the archive member
.IR position ,
which must be specified.
.TP
\-b
A positioning modifier used with the options \-r and \-m.
The files are entered or moved
.B before
the archive member
.IR position ,
which must be specified.
.TP
\-c
Whenever an archive is created, an informational message to that effect
is written to standard error.
If the \-c option is specified,
.I ar
creates the archive silently.
.TP
\-d
Delete the specified archive files.
.TP
\-i
Identical to the \-b option.
.TP
\-m
Move the specified archive files within the archive.
If one of the options \-a, \-b or \-i is specified, the files are moved
before or after the
.I position
file in the archive.
If none of those options are specified, the files are moved
to the end of the archive.
.TP
\-o
Set the access and modification times of extracted files to the
modification time of the file when it was entered into the archive.
This will fail if the user is not the owner of the extracted file
or the super-user.
.TP
\-p
Write the contents of the specified archive files to the standard output.
If no files are specified, the contents of all the files in the archive
are written in the order they appear in the archive.
.TP
\-q
(Quickly) append the specified files to the archive.
If the archive does not exist a new archive file is created.
Much faster than the \-r option, when creating a large archive
piece-by-piece, as no checking is done to see if the files already
exist in the archive.
.TP
\-r
Replace or add the specified files to the archive.
If the archive does not exist a new archive file is created.
Files that replace existing files do not change the order of the files
within the archive.
New files are appended to the archive unless one of the options \-a, \-b
or \-i is specified.
.TP
\-T
Select and/or name archive members using only the first fifteen characters
of the archive member or command line file name.
The historic archive format had sixteen bytes for the name, but some
historic archiver and loader implementations were unable to handle names
that used the entire space.
This means that file names that are not unique in their first fifteen
characters can subsequently be confused.
A warning message is printed to the standard error output if any file
names are truncated.
(See
.IR ar (5)
for more information.)
.TP
\-t
List the specified files in the order in which they appear in the archive,
each on a separate line.
If no files are specified, all files in the archive are listed.
.TP
\-u
Update files.
When used with the \-r option, files in the archive will be replaced
only if the disk file has a newer modification time than the file in
the archive.
When used with the \-x option, files in the archive will be extracted
only if the archive file has a newer modification time than the file
on disk.
.TP
\-v
Provide verbose output.
When used with the \-d, \-m, \-q or \-x options,
.I ar
gives a file-by-file description of the archive modification.
This description consists of three, white-space separated fields: the
option letter, a dash (``-'') and the file name.
When used with the \-r option,
.I ar
displays the description as above, but the initial letter is an ``a'' if
the file is added to the archive and an ``r'' if the file replaces a file
already in the archive.
.IP
When used with the \-p option,
the name of each printed file,
enclosed in less-than (``<'') and greater-than (``>'') characters,
is written to the standard output before
the contents of the file;
it is preceded by a single newline character, and
followed by two newline characters.
.IP
When used with the \-t option,
.I ar
displays an ``ls -l'' style listing of information about the members of
the archive.
This listing consists of eight, white-space separated fields:
the file permissions (see
.IR strmode (3)),
the decimal user and group ID's separated by a single slash (``/''),
the file size (in bytes), the file modification time (in the
.IR date (1)
format ``%b %e %H:%M %Y''), and the name of the file.
.TP
\-x
Extract the specified archive members into the files named by the command
line arguments.
If no members are specified, all the members of the archive are extracted into
the current directory.
.IP
If the file does not exist, it is created; if it does exist, the owner
and group will be unchanged.
The file access and modification times are the time of the extraction
(but see the \-o option).
The file permissions will be set to those of the file when it was entered
into the archive; this will fail if the user is not the owner of the
extracted file or the super-user.
.PP
The
.I ar
utility exits 0 on success, and >0 if an error occurs.
.SH ENVIRONMENT
.TP
TMPDIR
The pathname of the directory to use when creating temporary files.
.SH FILES
.TP 14
/tmp
default temporary file directory
.TP 14
ar.XXXXXX
temporary file names
.SH COMPATIBILITY
By default,
.I ar
writes archives that may be incompatible with historic archives, as
the format used for storing archive members with names longer than
fifteen characters has changed.
This implementation of
.I ar
is backward compatible with previous versions of
.I ar
in that it can read and write (using the \-T option) historic archives.
The \-T option is provided for compatibility only, and will be deleted
in a future release.
See
.IR ar (5)
for more information.
.SH STANDARDS
The
.I ar
utility is expected to offer a superset of the POSIX 1003.2 functionality.
.SH "SEE ALSO"
ld(1), ranlib(1), strmode(3), ar(5)

145
usr.bin/ar/ar.5.5 Normal file
View file

@ -0,0 +1,145 @@
.\" Copyright (c) 1990, 1991, 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.
.\"
.\" @(#)ar.5.5 8.1 (Berkeley) 6/9/93
.\"
.Dd June 9, 1993
.Dt AR 5
.Os
.Sh NAME
.Nm ar
.Nd archive (library) file format
.Sh SYNOPSIS
.Fd #include <ar.h>
.Sh DESCRIPTION
The archive command
.Nm ar
combines several files into one.
Archives are mainly used as libraries of object files intended to be
loaded using the link-editor
.Xr ld 1 .
.Pp
A file created with
.Nm ar
begins with the ``magic'' string "!<arch>\en".
The rest of the archive is made up of objects, each of which is composed
of a header for a file, a possible file name, and the file contents.
The header is portable between machine architectures, and, if the file
contents are printable, the archive is itself printable.
.Pp
The header is made up of six variable length
.Tn ASCII
fields, followed by a
two character trailer.
The fields are the object name (16 characters), the file last modification
time (12 characters), the user and group id's (each 6 characters), the file
mode (8 characters) and the file size (10 characters).
All numeric fields are in decimal, except for the file mode which is in
octal.
.Pp
The modification time is the file
.Fa st_mtime
field, i.e.,
.Dv CUT
seconds since
the epoch.
The user and group id's are the file
.Fa st_uid
and
.Fa st_gid
fields.
The file mode is the file
.Fa st_mode
field.
The file size is the file
.Fa st_size
field.
The two-byte trailer is the string "\`\en".
.Pp
Only the name field has any provision for overflow.
If any file name is more than 16 characters in length or contains an
embedded space, the string "#1/" followed by the
.Tn ASCII
length of the
name is written in the name field.
The file size (stored in the archive header) is incremented by the length
of the name.
The name is then written immediately following the archive header.
.Pp
Any unused characters in any of these fields are written as space
characters.
If any fields are their particular maximum number of characters in
length, there will be no separation between the fields.
.Pp
Objects in the archive are always an even number of bytes long; files
which are an odd number of bytes long are padded with a newline (``\en'')
character, although the size in the header does not reflect this.
.Sh SEE ALSO
.Xr ar 1 ,
.Xr stat 2
.Sh HISTORY
There have been at least four
.Nm ar
formats.
The first was denoted by the leading ``magic'' number 0177555 (stored as
type int).
These archives were almost certainly created on a 16-bit machine, and
contain headers made up of five fields.
The fields are the object name (8 characters), the file last modification
time (type long), the user id (type char), the file mode (type char) and
the file size (type unsigned int).
Files were padded to an even number of bytes.
.Pp
The second was denoted by the leading ``magic'' number 0177545 (stored as
type int).
These archives may have been created on either 16 or 32-bit machines, and
contain headers made up of six fields.
The fields are the object name (14 characters), the file last modification
time (type long), the user and group id's (each type char), the file mode
(type int) and the file size (type long).
Files were padded to an even number of bytes.
For more information on converting from this format see
.Xr arcv 8 .
.Pp
The current archive format (without support for long character names and
names with embedded spaces) was introduced in
.Bx 4.0 .
The headers were the same as the current format, with the exception that
names longer than 16 characters were truncated, and names with embedded
spaces (and often trailing spaces) were not supported.
It has been extended for these reasons,
as described above.
This format first appeared in 4.4BSD.
.Sh COMPATIBILITY
No archive format is currently specified by any standard.
.At V
has historically distributed archives in a different format from
all of the above.

237
usr.bin/ar/ar.c Normal file
View file

@ -0,0 +1,237 @@
/*-
* Copyright (c) 1990, 1993, 1994
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Hugh Smith at The University of Guelph.
*
* 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) 1990, 1993, 1994\n\
The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */
#ifndef lint
static char sccsid[] = "@(#)ar.c 8.3 (Berkeley) 4/2/94";
#endif /* not lint */
#include <sys/param.h>
#include <ar.h>
#include <dirent.h>
#include <err.h>
#include <paths.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "archive.h"
#include "extern.h"
CHDR chdr;
u_int options;
char *archive, *envtmp, *posarg, *posname;
static void badoptions __P((char *));
static void usage __P((void));
/*
* main --
* main basically uses getopt to parse options and calls the appropriate
* functions. Some hacks that let us be backward compatible with 4.3 ar
* option parsing and sanity checking.
*/
int
main(argc, argv)
int argc;
char **argv;
{
int c;
char *p;
int (*fcall) __P((char **));
if (argc < 3)
usage();
/*
* Historic versions didn't require a '-' in front of the options.
* Fix it, if necessary.
*/
if (*argv[1] != '-') {
if (!(p = malloc((u_int)(strlen(argv[1]) + 2))))
err(1, NULL);
*p = '-';
(void)strcpy(p + 1, argv[1]);
argv[1] = p;
}
while ((c = getopt(argc, argv, "abcdilmopqrTtuvx")) != EOF) {
switch(c) {
case 'a':
options |= AR_A;
break;
case 'b':
case 'i':
options |= AR_B;
break;
case 'c':
options |= AR_C;
break;
case 'd':
options |= AR_D;
fcall = delete;
break;
case 'l': /* not documented, compatibility only */
envtmp = ".";
break;
case 'm':
options |= AR_M;
fcall = move;
break;
case 'o':
options |= AR_O;
break;
case 'p':
options |= AR_P;
fcall = print;
break;
case 'q':
options |= AR_Q;
fcall = append;
break;
case 'r':
options |= AR_R;
fcall = replace;
break;
case 'T':
options |= AR_TR;
break;
case 't':
options |= AR_T;
fcall = contents;
break;
case 'u':
options |= AR_U;
break;
case 'v':
options |= AR_V;
break;
case 'x':
options |= AR_X;
fcall = extract;
break;
default:
usage();
}
}
argv += optind;
argc -= optind;
/* One of -dmpqrtx required. */
if (!(options & (AR_D|AR_M|AR_P|AR_Q|AR_R|AR_T|AR_X))) {
warnx("one of options -dmpqrtx is required");
usage();
}
/* Only one of -a and -bi allowed. */
if (options & AR_A && options & AR_B) {
warnx("only one of -a and -[bi] options allowed");
usage();
}
/* -ab require a position argument. */
if (options & (AR_A|AR_B)) {
if (!(posarg = *argv++)) {
warnx("no position operand specified");
usage();
}
posname = rname(posarg);
}
/* -d only valid with -Tv. */
if (options & AR_D && options & ~(AR_D|AR_TR|AR_V))
badoptions("-d");
/* -m only valid with -abiTv. */
if (options & AR_M && options & ~(AR_A|AR_B|AR_M|AR_TR|AR_V))
badoptions("-m");
/* -p only valid with -Tv. */
if (options & AR_P && options & ~(AR_P|AR_TR|AR_V))
badoptions("-p");
/* -q only valid with -cTv. */
if (options & AR_Q && options & ~(AR_C|AR_Q|AR_TR|AR_V))
badoptions("-q");
/* -r only valid with -abcuTv. */
if (options & AR_R && options & ~(AR_A|AR_B|AR_C|AR_R|AR_U|AR_TR|AR_V))
badoptions("-r");
/* -t only valid with -Tv. */
if (options & AR_T && options & ~(AR_T|AR_TR|AR_V))
badoptions("-t");
/* -x only valid with -ouTv. */
if (options & AR_X && options & ~(AR_O|AR_U|AR_TR|AR_V|AR_X))
badoptions("-x");
if (!(archive = *argv++)) {
warnx("no archive specified");
usage();
}
/* -dmqr require a list of archive elements. */
if (options & (AR_D|AR_M|AR_Q|AR_R) && !*argv) {
warnx("no archive members specified");
usage();
}
exit((*fcall)(argv));
}
static void
badoptions(arg)
char *arg;
{
warnx("illegal option combination for %s", arg);
usage();
}
static void
usage()
{
(void)fprintf(stderr, "usage: ar -d [-Tv] archive file ...\n");
(void)fprintf(stderr, "\tar -m [-Tv] archive file ...\n");
(void)fprintf(stderr, "\tar -m [-abiTv] position archive file ...\n");
(void)fprintf(stderr, "\tar -p [-Tv] archive [file ...]\n");
(void)fprintf(stderr, "\tar -q [-cTv] archive file ...\n");
(void)fprintf(stderr, "\tar -r [-cuTv] archive file ...\n");
(void)fprintf(stderr, "\tar -r [-abciuTv] position archive file ...\n");
(void)fprintf(stderr, "\tar -t [-Tv] archive [file ...]\n");
(void)fprintf(stderr, "\tar -x [-ouTv] archive [file ...]\n");
exit(1);
}

325
usr.bin/ar/archive.c Normal file
View file

@ -0,0 +1,325 @@
/*-
* Copyright (c) 1990, 1993, 1994
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Hugh Smith at The University of Guelph.
*
* 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 sccsid[] = "@(#)archive.c 8.3 (Berkeley) 4/2/94";
#endif /* not lint */
#include <sys/param.h>
#include <sys/stat.h>
#include <ar.h>
#include <dirent.h>
#include <err.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "archive.h"
#include "extern.h"
typedef struct ar_hdr HDR;
static char hb[sizeof(HDR) + 1]; /* real header */
int
open_archive(mode)
int mode;
{
int created, fd, nr;
char buf[SARMAG];
created = 0;
if (mode & O_CREAT) {
mode |= O_EXCL;
if ((fd = open(archive, mode, DEFFILEMODE)) >= 0) {
/* POSIX.2 puts create message on stderr. */
if (!(options & AR_C))
warnx("creating archive %s", archive);
created = 1;
goto opened;
}
if (errno != EEXIST)
error(archive);
mode &= ~O_EXCL;
}
if ((fd = open(archive, mode, DEFFILEMODE)) < 0)
error(archive);
/*
* Attempt to place a lock on the opened file - if we get an
* error then someone is already working on this library (or
* it's going across NFS).
*/
opened: if (flock(fd, LOCK_EX|LOCK_NB) && errno != EOPNOTSUPP)
error(archive);
/*
* If not created, O_RDONLY|O_RDWR indicates that it has to be
* in archive format.
*/
if (!created &&
((mode & O_ACCMODE) == O_RDONLY || (mode & O_ACCMODE) == O_RDWR)) {
if ((nr = read(fd, buf, SARMAG) != SARMAG)) {
if (nr >= 0)
badfmt();
error(archive);
} else if (bcmp(buf, ARMAG, SARMAG))
badfmt();
} else if (write(fd, ARMAG, SARMAG) != SARMAG)
error(archive);
return (fd);
}
void
close_archive(fd)
int fd;
{
(void)close(fd); /* Implicit unlock. */
}
/* Convert ar header field to an integer. */
#define AR_ATOI(from, to, len, base) { \
memmove(buf, from, len); \
buf[len] = '\0'; \
to = strtol(buf, (char **)NULL, base); \
}
/*
* get_arobj --
* read the archive header for this member
*/
int
get_arobj(fd)
int fd;
{
struct ar_hdr *hdr;
int len, nr;
char *p, buf[20];
nr = read(fd, hb, sizeof(HDR));
if (nr != sizeof(HDR)) {
if (!nr)
return (0);
if (nr < 0)
error(archive);
badfmt();
}
hdr = (struct ar_hdr *)hb;
if (strncmp(hdr->ar_fmag, ARFMAG, sizeof(ARFMAG) - 1))
badfmt();
/* Convert the header into the internal format. */
#define DECIMAL 10
#define OCTAL 8
AR_ATOI(hdr->ar_date, chdr.date, sizeof(hdr->ar_date), DECIMAL);
AR_ATOI(hdr->ar_uid, chdr.uid, sizeof(hdr->ar_uid), DECIMAL);
AR_ATOI(hdr->ar_gid, chdr.gid, sizeof(hdr->ar_gid), DECIMAL);
AR_ATOI(hdr->ar_mode, chdr.mode, sizeof(hdr->ar_mode), OCTAL);
AR_ATOI(hdr->ar_size, chdr.size, sizeof(hdr->ar_size), DECIMAL);
/* Leading spaces should never happen. */
if (hdr->ar_name[0] == ' ')
badfmt();
/*
* Long name support. Set the "real" size of the file, and the
* long name flag/size.
*/
if (!bcmp(hdr->ar_name, AR_EFMT1, sizeof(AR_EFMT1) - 1)) {
chdr.lname = len = atoi(hdr->ar_name + sizeof(AR_EFMT1) - 1);
if (len <= 0 || len > MAXNAMLEN)
badfmt();
nr = read(fd, chdr.name, len);
if (nr != len) {
if (nr < 0)
error(archive);
badfmt();
}
chdr.name[len] = 0;
chdr.size -= len;
} else {
chdr.lname = 0;
memmove(chdr.name, hdr->ar_name, sizeof(hdr->ar_name));
/* Strip trailing spaces, null terminate. */
for (p = chdr.name + sizeof(hdr->ar_name) - 1; *p == ' '; --p);
*++p = '\0';
}
return (1);
}
static int already_written;
/*
* put_arobj --
* Write an archive member to a file.
*/
void
put_arobj(cfp, sb)
CF *cfp;
struct stat *sb;
{
int lname;
char *name;
struct ar_hdr *hdr;
off_t size;
/*
* If passed an sb structure, reading a file from disk. Get stat(2)
* information, build a name and construct a header. (Files are named
* by their last component in the archive.) If not, then just write
* the last header read.
*/
if (sb) {
name = rname(cfp->rname);
(void)fstat(cfp->rfd, sb);
/*
* If not truncating names and the name is too long or contains
* a space, use extended format 1.
*/
lname = strlen(name);
if (options & AR_TR) {
if (lname > OLDARMAXNAME) {
(void)fflush(stdout);
warnx("warning: %s truncated to %.*s\n",
name, OLDARMAXNAME, name);
(void)fflush(stderr);
}
(void)sprintf(hb, HDR3, name, sb->st_mtimespec.ts_sec,
sb->st_uid, sb->st_gid, sb->st_mode, sb->st_size,
ARFMAG);
lname = 0;
} else if (lname > sizeof(hdr->ar_name) || strchr(name, ' '))
(void)sprintf(hb, HDR1, AR_EFMT1, lname,
sb->st_mtimespec.ts_sec, sb->st_uid, sb->st_gid,
sb->st_mode, sb->st_size + lname, ARFMAG);
else {
lname = 0;
(void)sprintf(hb, HDR2, name, sb->st_mtimespec.ts_sec,
sb->st_uid, sb->st_gid, sb->st_mode, sb->st_size,
ARFMAG);
}
size = sb->st_size;
} else {
lname = chdr.lname;
name = chdr.name;
size = chdr.size;
}
if (write(cfp->wfd, hb, sizeof(HDR)) != sizeof(HDR))
error(cfp->wname);
if (lname) {
if (write(cfp->wfd, name, lname) != lname)
error(cfp->wname);
already_written = lname;
}
copy_ar(cfp, size);
already_written = 0;
}
/*
* copy_ar --
* Copy size bytes from one file to another - taking care to handle the
* extra byte (for odd size files) when reading archives and writing an
* extra byte if necessary when adding files to archive. The length of
* the object is the long name plus the object itself; the variable
* already_written gets set if a long name was written.
*
* The padding is really unnecessary, and is almost certainly a remnant
* of early archive formats where the header included binary data which
* a PDP-11 required to start on an even byte boundary. (Or, perhaps,
* because 16-bit word addressed copies were faster?) Anyhow, it should
* have been ripped out long ago.
*/
void
copy_ar(cfp, size)
CF *cfp;
off_t size;
{
static char pad = '\n';
off_t sz;
int from, nr, nw, off, to;
char buf[8*1024];
if (!(sz = size))
return;
from = cfp->rfd;
to = cfp->wfd;
sz = size;
while (sz && (nr = read(from, buf, MIN(sz, sizeof(buf)))) > 0) {
sz -= nr;
for (off = 0; off < nr; nr -= off, off += nw)
if ((nw = write(to, buf + off, nr)) < 0)
error(cfp->wname);
}
if (sz) {
if (nr == 0)
badfmt();
error(cfp->rname);
}
if (cfp->flags & RPAD && size & 1 && (nr = read(from, buf, 1)) != 1) {
if (nr == 0)
badfmt();
error(cfp->rname);
}
if (cfp->flags & WPAD && (size + already_written) & 1 &&
write(to, &pad, 1) != 1)
error(cfp->wname);
}
/*
* skip_arobj -
* Skip over an object -- taking care to skip the pad bytes.
*/
void
skip_arobj(fd)
int fd;
{
off_t len;
len = chdr.size + (chdr.size + chdr.lname & 1);
if (lseek(fd, len, SEEK_CUR) == (off_t)-1)
error(archive);
}

105
usr.bin/ar/archive.h Normal file
View file

@ -0,0 +1,105 @@
/*-
* Copyright (c) 1991, 1993, 1994
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Hugh Smith at The University of Guelph.
*
* 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.
*
* @(#)archive.h 8.3 (Berkeley) 4/2/94
*/
/* Ar(1) options. */
#define AR_A 0x0001
#define AR_B 0x0002
#define AR_C 0x0004
#define AR_D 0x0008
#define AR_M 0x0010
#define AR_O 0x0020
#define AR_P 0x0040
#define AR_Q 0x0080
#define AR_R 0x0100
#define AR_T 0x0200
#define AR_TR 0x0400
#define AR_U 0x0800
#define AR_V 0x1000
#define AR_X 0x2000
extern u_int options;
/* Set up file copy. */
#define SETCF(from, fromname, to, toname, pad) { \
cf.rfd = from; \
cf.rname = fromname; \
cf.wfd = to; \
cf.wname = toname; \
cf.flags = pad; \
}
/* File copy structure. */
typedef struct {
int rfd; /* read file descriptor */
char *rname; /* read name */
int wfd; /* write file descriptor */
char *wname; /* write name */
#define NOPAD 0x00 /* don't pad */
#define RPAD 0x01 /* pad on reads */
#define WPAD 0x02 /* pad on writes */
u_int flags; /* pad flags */
} CF;
/* Header structure internal format. */
typedef struct {
off_t size; /* size of the object in bytes */
long date; /* date */
int lname; /* size of the long name in bytes */
int gid; /* group */
int uid; /* owner */
u_short mode; /* permissions */
char name[MAXNAMLEN + 1]; /* name */
} CHDR;
/* Header format strings. */
#define HDR1 "%s%-13d%-12ld%-6u%-6u%-8o%-10qd%2s"
#define HDR2 "%-16.16s%-12ld%-6u%-6u%-8o%-10qd%2s"
#define OLDARMAXNAME 15
#define HDR3 "%-16.15s%-12ld%-6u%-6u%-8o%-10qd%2s"
#include <sys/cdefs.h>
struct stat;
void close_archive __P((int));
void copy_ar __P((CF *, off_t));
int get_arobj __P((int));
int open_archive __P((int));
void put_arobj __P((CF *, struct stat *));
void skip_arobj __P((int));

96
usr.bin/ar/contents.c Normal file
View file

@ -0,0 +1,96 @@
/*-
* Copyright (c) 1990, 1993, 1994
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Hugh Smith at The University of Guelph.
*
* 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 sccsid[] = "@(#)contents.c 8.3 (Berkeley) 4/2/94";
#endif /* not lint */
#include <sys/param.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <ar.h>
#include <dirent.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <tzfile.h>
#include <unistd.h>
#include "archive.h"
#include "extern.h"
/*
* contents --
* Handles t[v] option - opens the archive and then reads headers,
* skipping member contents.
*/
int
contents(argv)
char **argv;
{
int afd, all;
struct tm *tp;
char *file, buf[25];
afd = open_archive(O_RDONLY);
for (all = !*argv; get_arobj(afd);) {
if (all)
file = chdr.name;
else if (!(file = files(argv)))
goto next;
if (options & AR_V) {
(void)strmode(chdr.mode, buf);
(void)printf("%s %6d/%-6d %8qd ",
buf + 1, chdr.uid, chdr.gid, chdr.size);
tp = localtime(&chdr.date);
(void)strftime(buf, sizeof(buf), "%b %e %H:%M %Y", tp);
(void)printf("%s %s\n", buf, file);
} else
(void)printf("%s\n", file);
if (!all && !*argv)
break;
next: skip_arobj(afd);
}
close_archive(afd);
if (*argv) {
orphans(argv);
return (1);
}
return (0);
}

96
usr.bin/ar/delete.c Normal file
View file

@ -0,0 +1,96 @@
/*-
* Copyright (c) 1990, 1993, 1994
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Hugh Smith at The University of Guelph.
*
* 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 sccsid[] = "@(#)delete.c 8.3 (Berkeley) 4/2/94";
#endif /* not lint */
#include <sys/param.h>
#include <sys/stat.h>
#include <ar.h>
#include <dirent.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include "archive.h"
#include "extern.h"
#include "pathnames.h"
/*-
* delete --
* Deletes named members from the archive.
*/
int
delete(argv)
char **argv;
{
CF cf;
off_t size;
int afd, tfd;
char *file;
afd = open_archive(O_RDWR);
tfd = tmp();
/* Read and write to an archive; pad on both. */
SETCF(afd, archive, tfd, tname, RPAD|WPAD);
while (get_arobj(afd)) {
if (*argv && (file = files(argv))) {
if (options & AR_V)
(void)printf("d - %s\n", file);
skip_arobj(afd);
continue;
}
put_arobj(&cf, (struct stat *)NULL);
}
size = lseek(tfd, (off_t)0, SEEK_CUR);
(void)lseek(tfd, (off_t)0, SEEK_SET);
(void)lseek(afd, (off_t)SARMAG, SEEK_SET);
SETCF(tfd, tname, afd, archive, NOPAD);
copy_ar(&cf, size);
(void)close(tfd);
(void)ftruncate(afd, size + SARMAG);
close_archive(afd);
if (*argv) {
orphans(argv);
return (1);
}
return (0);
}

54
usr.bin/ar/extern.h Normal file
View file

@ -0,0 +1,54 @@
/*-
* Copyright (c) 1991, 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.
*
* @(#)extern.h 8.3 (Berkeley) 4/2/94
*/
int append __P((char **));
void badfmt __P((void));
int compare __P((char *));
int contents __P((char **));
int delete __P((char **));
void error __P((char *));
int extract __P((char **));
char *files __P((char **argv));
int move __P((char **));
void orphans __P((char **argv));
int print __P((char **));
int replace __P((char **));
char *rname __P((char *));
int tmp __P((void));
extern char *archive;
extern char *posarg, *posname; /* positioning file name */
extern char *tname; /* temporary file "name" */
extern CHDR chdr; /* converted header */

128
usr.bin/ar/extract.c Normal file
View file

@ -0,0 +1,128 @@
/*-
* Copyright (c) 1990, 1993, 1994
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Hugh Smith at The University of Guelph.
*
* 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 sccsid[] = "@(#)extract.c 8.3 (Berkeley) 4/2/94";
#endif /* not lint */
#include <sys/param.h>
#include <sys/time.h>
#include <sys/stat.h>
#include <dirent.h>
#include <err.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include "archive.h"
#include "extern.h"
/*
* extract --
* Extract files from the named archive - if member names given only
* extract those members otherwise extract all members. If 'o' option
* selected modify date of newly created file to be same as archive
* members date otherwise date is time of extraction. Does not modify
* archive.
*/
int
extract(argv)
char **argv;
{
char *file;
int afd, all, eval, tfd;
struct timeval tv[2];
struct stat sb;
CF cf;
eval = 0;
tv[0].tv_usec = tv[1].tv_usec = 0;
afd = open_archive(O_RDONLY);
/* Read from an archive, write to disk; pad on read. */
SETCF(afd, archive, 0, 0, RPAD);
for (all = !*argv; get_arobj(afd);) {
if (all)
file = chdr.name;
else if (!(file = files(argv))) {
skip_arobj(afd);
continue;
}
if (options & AR_U && !stat(file, &sb) &&
sb.st_mtime > chdr.date)
continue;
if ((tfd = open(file, O_WRONLY|O_CREAT|O_TRUNC, S_IWUSR)) < 0) {
warn("%s", file);
skip_arobj(afd);
eval = 1;
continue;
}
if (options & AR_V)
(void)printf("x - %s\n", file);
cf.wfd = tfd;
cf.wname = file;
copy_ar(&cf, chdr.size);
if (fchmod(tfd, (short)chdr.mode)) {
warn("chmod: %s", file);
eval = 1;
}
if (options & AR_O) {
tv[0].tv_sec = tv[1].tv_sec = chdr.date;
if (utimes(file, tv)) {
warn("utimes: %s", file);
eval = 1;
}
}
(void)close(tfd);
if (!all && !*argv)
break;
}
close_archive(afd);
if (*argv) {
orphans(argv);
return (1);
}
return (0);
}

148
usr.bin/ar/misc.c Normal file
View file

@ -0,0 +1,148 @@
/*-
* Copyright (c) 1990, 1993, 1994
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Hugh Smith at The University of Guelph.
*
* 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 sccsid[] = "@(#)misc.c 8.3 (Berkeley) 4/2/94";
#endif /* not lint */
#include <sys/param.h>
#include <dirent.h>
#include <err.h>
#include <errno.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "archive.h"
#include "extern.h"
#include "pathnames.h"
char *tname = "temporary file"; /* temporary file "name" */
int
tmp()
{
extern char *envtmp;
sigset_t set, oset;
static int first;
int fd;
char path[MAXPATHLEN];
if (!first && !envtmp) {
envtmp = getenv("TMPDIR");
first = 1;
}
if (envtmp)
(void)sprintf(path, "%s/%s", envtmp, _NAME_ARTMP);
else
strcpy(path, _PATH_ARTMP);
sigfillset(&set);
(void)sigprocmask(SIG_BLOCK, &set, &oset);
if ((fd = mkstemp(path)) == -1)
error(tname);
(void)unlink(path);
(void)sigprocmask(SIG_SETMASK, &oset, NULL);
return (fd);
}
/*
* files --
* See if the current file matches any file in the argument list; if it
* does, remove it from the argument list.
*/
char *
files(argv)
char **argv;
{
char **list, *p;
for (list = argv; *list; ++list)
if (compare(*list)) {
p = *list;
for (; list[0] = list[1]; ++list)
continue;
return (p);
}
return (NULL);
}
void
orphans(argv)
char **argv;
{
for (; *argv; ++argv)
warnx("%s: not found in archive", *argv);
}
char *
rname(path)
char *path;
{
char *ind;
return ((ind = strrchr(path, '/')) ? ind + 1 : path);
}
int
compare(dest)
char *dest;
{
if (options & AR_TR)
return (!strncmp(chdr.name, rname(dest), OLDARMAXNAME));
return (!strcmp(chdr.name, rname(dest)));
}
void
badfmt()
{
errx(1, "%s: %s", archive, strerror(EFTYPE));
}
void
error(name)
char *name;
{
errx(1, "%s", name);
}

140
usr.bin/ar/move.c Normal file
View file

@ -0,0 +1,140 @@
/*-
* Copyright (c) 1990, 1993, 1994
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Hugh Smith at The University of Guelph.
*
* 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 sccsid[] = "@(#)move.c 8.3 (Berkeley) 4/2/94";
#endif /* not lint */
#include <sys/param.h>
#include <sys/stat.h>
#include <ar.h>
#include <dirent.h>
#include <err.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include "archive.h"
#include "extern.h"
#include "pathnames.h"
/*
* move --
* Change location of named members in archive - if 'b' or 'i' option
* selected then named members are placed before 'posname'. If 'a'
* option selected members go after 'posname'. If no options, members
* are moved to end of archive.
*/
int
move(argv)
char **argv;
{
CF cf;
off_t size, tsize;
int afd, curfd, mods, tfd1, tfd2, tfd3;
char *file;
afd = open_archive(O_RDWR);
mods = options & (AR_A|AR_B);
tfd1 = tmp(); /* Files before key file. */
tfd2 = tmp(); /* Files selected by user. */
tfd3 = tmp(); /* Files after key file. */
/*
* Break archive into three parts -- selected entries and entries
* before and after the key entry. If positioning before the key,
* place the key at the beginning of the after key entries and if
* positioning after the key, place the key at the end of the before
* key entries. Put it all back together at the end.
*/
/* Read and write to an archive; pad on both. */
SETCF(afd, archive, 0, tname, RPAD|WPAD);
for (curfd = tfd1; get_arobj(afd);) {
if (*argv && (file = files(argv))) {
if (options & AR_V)
(void)printf("m - %s\n", file);
cf.wfd = tfd2;
put_arobj(&cf, (struct stat *)NULL);
continue;
}
if (mods && compare(posname)) {
mods = 0;
if (options & AR_B)
curfd = tfd3;
cf.wfd = curfd;
put_arobj(&cf, (struct stat *)NULL);
if (options & AR_A)
curfd = tfd3;
} else {
cf.wfd = curfd;
put_arobj(&cf, (struct stat *)NULL);
}
}
if (mods) {
warnx("%s: archive member not found", posarg);
close_archive(afd);
return (1);
}
(void)lseek(afd, (off_t)SARMAG, SEEK_SET);
SETCF(tfd1, tname, afd, archive, NOPAD);
tsize = size = lseek(tfd1, (off_t)0, SEEK_CUR);
(void)lseek(tfd1, (off_t)0, SEEK_SET);
copy_ar(&cf, size);
tsize += size = lseek(tfd2, (off_t)0, SEEK_CUR);
(void)lseek(tfd2, (off_t)0, SEEK_SET);
cf.rfd = tfd2;
copy_ar(&cf, size);
tsize += size = lseek(tfd3, (off_t)0, SEEK_CUR);
(void)lseek(tfd3, (off_t)0, SEEK_SET);
cf.rfd = tfd3;
copy_ar(&cf, size);
(void)ftruncate(afd, tsize + SARMAG);
close_archive(afd);
if (*argv) {
orphans(argv);
return (1);
}
return (0);
}

40
usr.bin/ar/pathnames.h Normal file
View file

@ -0,0 +1,40 @@
/*-
* Copyright (c) 1991, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Hugh Smith at The University of Guelph.
*
* 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.
*
* @(#)pathnames.h 8.1 (Berkeley) 6/6/93
*/
#define _NAME_ARTMP "ar.XXXXXX"
#define _PATH_ARTMP "/tmp/ar.XXXXXX"

90
usr.bin/ar/print.c Normal file
View file

@ -0,0 +1,90 @@
/*-
* Copyright (c) 1990, 1993, 1994
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Hugh Smith at The University of Guelph.
*
* 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 sccsid[] = "@(#)print.c 8.3 (Berkeley) 4/2/94";
#endif /* not lint */
#include <sys/param.h>
#include <dirent.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include "archive.h"
#include "extern.h"
/*
* print --
* Prints archive members on stdout - if member names given only
* print those members, otherwise print all members.
*/
int
print(argv)
char **argv;
{
CF cf;
int afd, all;
char *file;
afd = open_archive(O_RDONLY);
/* Read from an archive, write to stdout; pad on read. */
SETCF(afd, archive, STDOUT_FILENO, "stdout", RPAD);
for (all = !*argv; get_arobj(afd);) {
if (all)
file = chdr.name;
else if (!(file = files(argv))) {
skip_arobj(afd);
continue;
}
if (options & AR_V) {
(void)printf("\n<%s>\n\n", file);
(void)fflush(stdout);
}
copy_ar(&cf, chdr.size);
if (!all && !*argv)
break;
}
close_archive(afd);
if (*argv) {
orphans(argv);
return (1);
}
return (0);
}

176
usr.bin/ar/replace.c Normal file
View file

@ -0,0 +1,176 @@
/*-
* Copyright (c) 1990, 1993, 1994
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Hugh Smith at The University of Guelph.
*
* 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 sccsid[] = "@(#)replace.c 8.3 (Berkeley) 4/2/94";
#endif /* not lint */
#include <sys/param.h>
#include <sys/stat.h>
#include <ar.h>
#include <dirent.h>
#include <err.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include "archive.h"
#include "extern.h"
/*
* replace --
* Replace or add named members to archive. Entries already in the
* archive are swapped in place. Others are added before or after
* the key entry, based on the a, b and i options. If the u option
* is specified, modification dates select for replacement.
*/
int
replace(argv)
char **argv;
{
char *file;
int afd, curfd, errflg, exists, mods, sfd, tfd1, tfd2;
struct stat sb;
CF cf;
off_t size, tsize;
errflg = 0;
/*
* If doesn't exist, simply append to the archive. There's
* a race here, but it's pretty short, and not worth fixing.
*/
exists = !stat(archive, &sb);
afd = open_archive(O_CREAT|O_RDWR);
if (!exists) {
tfd1 = -1;
tfd2 = tmp();
goto append;
}
tfd1 = tmp(); /* Files before key file. */
tfd2 = tmp(); /* Files after key file. */
/*
* Break archive into two parts -- entries before and after the key
* entry. If positioning before the key, place the key at the
* beginning of the after key entries and if positioning after the
* key, place the key at the end of the before key entries. Put it
* all back together at the end.
*/
mods = (options & (AR_A|AR_B));
for (curfd = tfd1; get_arobj(afd);) {
if (*argv && (file = files(argv))) {
if ((sfd = open(file, O_RDONLY)) < 0) {
errflg = 1;
warn("%s", file);
goto useold;
}
(void)fstat(sfd, &sb);
if (options & AR_U && sb.st_mtime <= chdr.date)
goto useold;
if (options & AR_V)
(void)printf("r - %s\n", file);
/* Read from disk, write to an archive; pad on write */
SETCF(sfd, file, curfd, tname, WPAD);
put_arobj(&cf, &sb);
(void)close(sfd);
skip_arobj(afd);
continue;
}
if (mods && compare(posname)) {
mods = 0;
if (options & AR_B)
curfd = tfd2;
/* Read and write to an archive; pad on both. */
SETCF(afd, archive, curfd, tname, RPAD|WPAD);
put_arobj(&cf, (struct stat *)NULL);
if (options & AR_A)
curfd = tfd2;
} else {
/* Read and write to an archive; pad on both. */
useold: SETCF(afd, archive, curfd, tname, RPAD|WPAD);
put_arobj(&cf, (struct stat *)NULL);
}
}
if (mods) {
warnx("%s: archive member not found", posarg);
close_archive(afd);
return (1);
}
/* Append any left-over arguments to the end of the after file. */
append: while (file = *argv++) {
if (options & AR_V)
(void)printf("a - %s\n", file);
if ((sfd = open(file, O_RDONLY)) < 0) {
errflg = 1;
warn("%s", file);
continue;
}
(void)fstat(sfd, &sb);
/* Read from disk, write to an archive; pad on write. */
SETCF(sfd, file,
options & (AR_A|AR_B) ? tfd1 : tfd2, tname, WPAD);
put_arobj(&cf, &sb);
(void)close(sfd);
}
(void)lseek(afd, (off_t)SARMAG, SEEK_SET);
SETCF(tfd1, tname, afd, archive, NOPAD);
if (tfd1 != -1) {
tsize = size = lseek(tfd1, (off_t)0, SEEK_CUR);
(void)lseek(tfd1, (off_t)0, SEEK_SET);
copy_ar(&cf, size);
} else
tsize = 0;
tsize += size = lseek(tfd2, (off_t)0, SEEK_CUR);
(void)lseek(tfd2, (off_t)0, SEEK_SET);
cf.rfd = tfd2;
copy_ar(&cf, size);
(void)ftruncate(afd, tsize + SARMAG);
close_archive(afd);
return (errflg);
}

6
usr.bin/banner/Makefile Normal file
View file

@ -0,0 +1,6 @@
# @(#)Makefile 8.1 (Berkeley) 6/6/93
PROG= banner
MAN6= banner.0
.include <bsd.prog.mk>

72
usr.bin/banner/banner.6 Normal file
View file

@ -0,0 +1,72 @@
.\" Copyright (c) 1980, 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.
.\"
.\" @(#)banner.6 8.1 (Berkeley) 6/6/93
.\"
.TH BANNER 6 "June 6, 1993"
.UC
.SH NAME
banner \- print large banner on printer
.SH SYNOPSIS
.B /usr/games/banner
[
.BI \-w n
]
message ...
.SH DESCRIPTION
.I Banner
prints a large, high quality banner on the standard output.
If the message is omitted, it prompts for and
reads one line of its standard input. If
.B \-w
is given, the output is scrunched down from a width of 132 to
.I n ,
suitable for a narrow terminal. If
.I n
is omitted, it defaults to 80.
.PP
The output should be printed on a hard-copy device, up to 132 columns wide,
with no breaks between the pages. The volume is great enough that you
may want
a printer or a fast hardcopy terminal, but if you are patient, a
decwriter or other 300 baud terminal will do.
.SH BUGS
Several ASCII characters are not defined, notably <, >, [, ], \\,
^, _, {, }, |, and ~. Also, the characters ", ', and & are funny
looking (but in a useful way.)
.PP
The
.B \-w
option is implemented by skipping some rows and columns.
The smaller it gets, the grainier the output.
Sometimes it runs letters together.
.SH AUTHOR
Mark Horton

1160
usr.bin/banner/banner.c Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,6 @@
# @(#)Makefile 8.1 (Berkeley) 6/6/93
PROG= basename
MLINKS= basename.1 dirname.1
.include <bsd.prog.mk>

View file

@ -0,0 +1,97 @@
.\" Copyright (c) 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.
.\"
.\" @(#)basename.1 8.2 (Berkeley) 4/18/94
.\"
.Dd April 18, 1994
.Dt BASENAME 1
.Os
.Sh NAME
.Nm basename , dirname
.Nd return filename or directory portion of pathname
.Sh SYNOPSIS
.Nm basename
.Ar string
.Op Ar suffix
.Nm dirname
.Ar string
.Sh DESCRIPTION
.Nm Basename
deletes any prefix ending with the last slash
.Ql \&/
character present in
.Ar string ,
and a
.Ar suffix ,
if given.
The resulting filename is written to the standard output.
If
.Ar string
ends in the slash character,
.Ql / ,
or is the same as the
.Ar suffix
argument,
a newline is output.
A non-existent suffix is ignored.
.Pp
.Nm Dirname
deletes the filename portion, beginning
with the last slash
.Ql \&/
character to the end of
.Ar string ,
and writes the result to the standard output.
.Sh EXAMPLES
The following line sets the shell variable
.Ev FOO
to
.Pa /usr/bin .
.Pp
.Dl FOO=`dirname /usr/bin/trail`
.Pp
Both the
.Nm basename
and
.Nm dirname
exit 0 on success, and >0 if an error occurs.
.Sh SEE ALSO
.Xr csh 1
.Xr sh 1
.Sh STANDARDS
The
.Nm basename
and
.Nm dirname
functions are expected to be POSIX 1003.2 compatible.

138
usr.bin/basename/basename.c Normal file
View file

@ -0,0 +1,138 @@
/*-
* Copyright (c) 1991, 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) 1991, 1993, 1994\n\
The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */
#ifndef lint
static char sccsid[] = "@(#)basename.c 8.3 (Berkeley) 4/2/94";
#endif /* not lint */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void usage __P((void));
int
main(argc, argv)
int argc;
char **argv;
{
char *p;
int ch;
while ((ch = getopt(argc, argv, "")) != EOF)
switch(ch) {
case '?':
default:
usage();
}
argc -= optind;
argv += optind;
if (argc != 1 && argc != 2)
usage();
/*
* (1) If string is // it is implementation defined whether steps (2)
* through (5) are skipped or processed.
*
* (2) If string consists entirely of slash characters, string shall
* be set to a single slash character. In this case, skip steps
* (3) through (5).
*/
for (p = *argv;; ++p) {
if (!*p) {
if (p > *argv)
(void)printf("/\n");
else
(void)printf("\n");
exit(0);
}
if (*p != '/')
break;
}
/*
* (3) If there are any trailing slash characters in string, they
* shall be removed.
*/
for (; *p; ++p)
continue;
while (*--p == '/')
continue;
*++p = '\0';
/*
* (4) If there are any slash characters remaining in string, the
* prefix of string up to an including the last slash character
* in string shall be removed.
*/
while (--p >= *argv)
if (*p == '/')
break;
++p;
/*
* (5) If the suffix operand is present, is not identical to the
* characters remaining in string, and is identical to a suffix
* of the characters remaining in string, the suffix suffix
* shall be removed from string.
*/
if (*++argv) {
int suffixlen, stringlen, off;
suffixlen = strlen(*argv);
stringlen = strlen(p);
if (suffixlen < stringlen) {
off = stringlen - suffixlen;
if (!strcmp(p + off, *argv))
p[off] = '\0';
}
}
(void)printf("%s\n", p);
exit(0);
}
void
usage()
{
(void)fprintf(stderr, "usage: basename string [suffix]\n");
exit(1);
}

5
usr.bin/bdes/Makefile Normal file
View file

@ -0,0 +1,5 @@
# @(#)Makefile 8.1 (Berkeley) 6/6/93
PROG= bdes
.include <bsd.prog.mk>

304
usr.bin/bdes/bdes.1 Normal file
View file

@ -0,0 +1,304 @@
.\" Copyright (c) 1991, 1993
.\" The Regents of the University of California. All rights reserved.
.\"
.\" This code is derived from software contributed to Berkeley by
.\" Matt Bishop of Dartmouth College.
.\"
.\" 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.
.\"
.\" @(#)bdes.1 8.1 (Berkeley) 6/29/93
.\"
.TH BDES 1 "June 29, 1993"
.UC 6
.SH NAME
bdes \- encrypt/decrypt using the Data Encryption Standard
.SH SYNOPSIS
.nf
.ft B
bdes [ \-abdp ] [ \-F N ] [ \-f N ] [ \-k key ]
.ti +5
[ \-m N ] [ \-o N ] [ \-v vector ]
.ft R
.fi
.SH DESCRIPTION
.I Bdes
implements all DES modes of operation described in FIPS PUB 81,
including alternative cipher feedback mode and both authentication
modes.
.I Bdes
reads from the standard input and writes to the standard output.
By default, the input is encrypted using cipher block chaining mode.
Using the same key for encryption and decryption preserves plain text.
.PP
All modes but the electronic code book mode require an initialization
vector; if none is supplied, the zero vector is used.
If no
.I key
is specified on the command line, the user is prompted for one (see
.IR getpass (3)
for more details).
.PP
The options are as follows:
.TP
\-a
The key and initialization vector strings are to be taken as ASCII,
suppressing the special interpretation given to leading ``0X'', ``0x'',
``0B'', and ``0b'' characters.
This flag applies to
.I both
the key and initialization vector.
.TP
\-b
Use electronic code book mode.
.TP
\-d
Decrypt the input.
.TP
\-F
Use
.IR N -bit
alternative cipher feedback mode.
Currently
.I N
must be a multiple of 7 between 7 and 56 inclusive (this does not conform
to the alternative CFB mode specification).
.TP
\-f
Use
.IR N -bit
cipher feedback mode.
Currently
.I N
must be a multiple of 8 between 8 and 64 inclusive (this does not conform
to the standard CFB mode specification).
.TP
\-k
Use
.I key
as the cryptographic key.
.TP
\-m
Compute a message authentication code (MAC) of
.I N
bits on the input.
The value of
.I N
must be between 1 and 64 inclusive; if
.I N
is not a multiple of 8, enough 0 bits will be added to pad the MAC length
to the nearest multiple of 8.
Only the MAC is output.
MACs are only available in cipher block chaining mode or in cipher feedback
mode.
.TP
\-o
Use
.IR N -bit
output feedback mode.
Currently
.I N
must be a multiple of 8 between 8 and 64 inclusive (this does not conform
to the OFB mode specification).
.TP
\-p
Disable the resetting of the parity bit.
This flag forces the parity bit of the key to be used as typed, rather than
making each character be of odd parity.
It is used only if the key is given in ASCII.
.TP
\-v
Set the initialization vector to
.IR vector ;
the vector is interpreted in the same way as the key.
The vector is ignored in electronic codebook mode.
.PP
The key and initialization vector are taken as sequences of ASCII
characters which are then mapped into their bit representations.
If either begins with ``0X'' or ``0x'',
that one is taken as a sequence of hexadecimal digits indicating the
bit pattern;
if either begins with ``0B'' or ``0b'',
that one is taken as a sequence of binary digits indicating the bit pattern.
In either case,
only the leading 64 bits of the key or initialization vector
are used,
and if fewer than 64 bits are provided, enough 0 bits are appended
to pad the key to 64 bits.
.PP
According to the DES standard, the low-order bit of each character in the
key string is deleted.
Since most ASCII representations set the high-order bit to 0, simply
deleting the low-order bit effectively reduces the size of the key space
from 2\u\s-356\s0\d to 2\u\s-348\s0\d keys.
To prevent this, the high-order bit must be a function depending in part
upon the low-order bit; so, the high-order bit is set to whatever value
gives odd parity.
This preserves the key space size.
Note this resetting of the parity bit is
.I not
done if the key is given in binary or hex, and can be disabled for ASCII
keys as well.
.PP
The DES is considered a very strong cryptosystem, and other than table lookup
attacks, key search attacks, and Hellman's time-memory tradeoff (all of which
are very expensive and time-consuming), no cryptanalytic methods for breaking
the DES are known in the open literature.
No doubt the choice of keys and key security are the most vulnerable aspect
of
.IR bdes .
.SH IMPLEMENTATION NOTES
For implementors wishing to write software compatible with this program,
the following notes are provided.
This software is believed to be compatible with the implementation of the
data encryption standard distributed by Sun Microsystems, Inc.
.PP
In the ECB and CBC modes, plaintext is encrypted in units of 64 bits (8 bytes,
also called a block).
To ensure that the plaintext file is encrypted correctly,
.I bdes
will (internally) append from 1 to 8 bytes, the last byte containing an
integer stating how many bytes of that final block are from the plaintext
file, and encrypt the resulting block.
Hence, when decrypting, the last block may contain from 0 to 7 characters
present in the plaintext file, and the last byte tells how many.
Note that if during decryption the last byte of the file does not contain an
integer between 0 and 7, either the file has been corrupted or an incorrect
key has been given.
A similar mechanism is used for the OFB and CFB modes, except that those
simply require the length of the input to be a multiple of the mode size,
and the final byte contains an integer between 0 and one less than the number
of bytes being used as the mode.
(This was another reason that the mode size must be a multiple of 8 for those
modes.)
.PP
Unlike Sun's implementation, unused bytes of that last block are not filled
with random data, but instead contain what was in those byte positions in
the preceding block.
This is quicker and more portable, and does not weaken the encryption
significantly.
.PP
If the key is entered in ASCII, the parity bits of the key characters are set
so that each key character is of odd parity.
Unlike Sun's implementation, it is possible to enter binary or hexadecimal
keys on the command line, and if this is done, the parity bits are
.I not
reset.
This allows testing using arbitrary bit patterns as keys.
.PP
The Sun implementation always uses an initialization vector of 0
(that is, all zeroes).
By default,
.I bdes
does too, but this may be changed from the command line.
.SH SEE ALSO
crypt(1), crypt(3), getpass(3)
.sp
.IR "Data Encryption Standard" ,
Federal Information Processing Standard #46,
National Bureau of Standards,
U.S. Department of Commerce,
Washington DC
(Jan. 1977)
.sp
.IR "DES Modes of Operation" ,
Federal Information Processing Standard #81,
National Bureau of Standards,
U.S. Department of Commerce
Washington DC
(Dec. 1980)
.sp
Dorothy Denning,
.IR "Cryptography and Data Security" ,
Addison-Wesley Publishing Co.,
Reading, MA
\(co1982.
.sp
Matt Bishop,
.IR "Implementation Notes on bdes(1)" ,
Technical Report PCS-TR-91-158,
Department of Mathematics and Computer Science,
Dartmouth College,
Hanover, NH 03755
(Apr. 1991).
.SH DISCLAIMER
.nf
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.
.fi
.SH BUGS
There is a controversy raging over whether the DES will still be secure
in a few years.
The advent of special-purpose hardware could reduce the cost of any of the
methods of attack named above so that they are no longer computationally
infeasible.
.PP
As the key or key schedule is stored in memory, the encryption can be
compromised if memory is readable.
Additionally, programs which display programs' arguments may compromise the
key and initialization vector, if they are specified on the command line.
To avoid this
.I bdes
overwrites its arguments, however, the obvious race cannot currently be
avoided.
.PP
Certain specific keys should be avoided because they introduce potential
weaknesses; these keys, called the
.I weak
and
.I semiweak
keys, are (in hex notation, where p is either 0 or 1, and P is either
e or f):
.sp
.nf
.in +10n
.ta \w'0x0p0p0p0p0p0p0p0p\0\0\0'u+5n
0x0p0p0p0p0p0p0p0p 0x0p1P0p1P0p0P0p0P
0x0pep0pep0pfp0pfp 0x0pfP0pfP0pfP0pfP
0x1P0p1P0p0P0p0P0p 0x1P1P1P1P0P0P0P0P
0x1Pep1Pep0Pfp0Pfp 0x1PfP1PfP0PfP0PfP
0xep0pep0pfp0pfp0p 0xep1Pep1pfp0Pfp0P
0xepepepepepepepep 0xepfPepfPfpfPfpfP
0xfP0pfP0pfP0pfP0p 0xfP1PfP1PfP0PfP0P
0xfPepfPepfPepfPep 0xfPfPfPfPfPfPfPfP
.fi
.in -10n
.sp
This is inherent in the DES algorithm (see Moore and Simmons,
\*(LqCycle structure of the DES with weak and semi-weak keys,\*(Rq
.I "Advances in Cryptology \- Crypto '86 Proceedings" ,
Springer-Verlag New York, \(co1987, pp. 9-32.)

1046
usr.bin/bdes/bdes.c Normal file

File diff suppressed because it is too large Load diff

2945
usr.bin/bdes/bdes.ps Normal file

File diff suppressed because it is too large Load diff

5
usr.bin/biff/Makefile Normal file
View file

@ -0,0 +1,5 @@
# @(#)Makefile 8.1 (Berkeley) 6/6/93
PROG= biff
.include <bsd.prog.mk>

86
usr.bin/biff/biff.1 Normal file
View file

@ -0,0 +1,86 @@
.\" Copyright (c) 1980, 1990, 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.
.\"
.\" @(#)biff.1 8.1 (Berkeley) 6/6/93
.\"
.Dd June 6, 1993
.Dt BIFF 1
.Os BSD 4
.Sh NAME
.Nm biff
.Nd "be notified if mail arrives and who it is from"
.Sh SYNOPSIS
.Nm biff
.Op Cm ny
.Sh DESCRIPTION
.Nm Biff
informs the system whether you want to be notified when mail arrives
during the current terminal session.
.Pp
Options supported by
.Nm biff :
.Bl -tag -width 4n
.It Cm n
Disables notification.
.It Cm y
Enables notification.
.El
.Pp
When mail notification is enabled, the header and first few lines of
the message will be printed on your screen whenever mail arrives.
A
.Dq Li biff y
command is often included in the file
.Pa \&.login
or
.Pa \&.profile
to be executed at each login.
.Pp
.Nm Biff
operates asynchronously.
For synchronous notification use the
.Ar MAIL
variable of
.Xr sh 1
or the
.Ar mail
variable of
.Xr csh 1 .
.Sh SEE ALSO
.Xr csh 1 ,
.Xr mail 1 ,
.Xr sh 1 ,
.Xr comsat 8
.Sh HISTORY
The
.Nm
command appeared in
.Bx 4.0 .

114
usr.bin/biff/biff.c Normal file
View file

@ -0,0 +1,114 @@
/*
* Copyright (c) 1980, 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) 1980, 1993\n\
The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */
#ifndef lint
static char sccsid[] = "@(#)biff.c 8.1 (Berkeley) 6/6/93";
#endif /* not lint */
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static void usage __P((void));
static void err __P((char *));
main(argc, argv)
int argc;
char *argv[];
{
struct stat sb;
int ch;
char *name;
while ((ch = getopt(argc, argv, "")) != EOF)
switch(ch) {
case '?':
default:
usage();
}
argc -= optind;
argv += optind;
if ((name = ttyname(STDERR_FILENO)) == NULL) {
(void)fprintf(stderr, "biff: unknown tty\n");
exit(2);
}
if (stat(name, &sb))
err(name);
if (*argv == NULL) {
(void)printf("is %s\n", sb.st_mode&0100 ? "y" : "n");
exit(sb.st_mode & 0100 ? 0 : 1);
}
switch(argv[0][0]) {
case 'n':
if (chmod(name, sb.st_mode & ~0100) < 0)
err(name);
break;
case 'y':
if (chmod(name, sb.st_mode | 0100) < 0)
err(name);
break;
default:
usage();
}
exit(sb.st_mode & 0100 ? 0 : 1);
}
static void
err(name)
char *name;
{
(void)fprintf(stderr, "biff: %s: %s\n", name, strerror(errno));
exit(2);
}
static void
usage()
{
(void)fprintf(stderr, "usage: biff [y | n]\n");
exit(2);
}

5
usr.bin/cal/Makefile Normal file
View file

@ -0,0 +1,5 @@
# @(#)Makefile 8.1 (Berkeley) 6/6/93
PROG= cal
.include <bsd.prog.mk>

42
usr.bin/cal/README Normal file
View file

@ -0,0 +1,42 @@
The cal(1) date routines were written from scratch, basically from first
principles. The algorithm for calculating the day of week from any
Gregorian date was "reverse engineered". This was necessary as most of
the documented algorithms have to do with date calculations for other
calendars (e.g. julian) and are only accurate when converted to gregorian
within a narrow range of dates.
1 Jan 1 is a Saturday because that's what cal says and I couldn't change
that even if I was dumb enough to try. From this we can easily calculate
the day of week for any date. The algorithm for a zero based day of week:
calculate the number of days in all prior years (year-1)*365
add the number of leap years (days?) since year 1
(not including this year as that is covered later)
add the day number within the year
this compensates for the non-inclusive leap year
calculation
if the day in question occurs before the gregorian reformation
(3 sep 1752 for our purposes), then simply return
(value so far - 1 + SATURDAY's value of 6) modulo 7.
if the day in question occurs during the reformation (3 sep 1752
to 13 sep 1752 inclusive) return THURSDAY. This is my
idea of what happened then. It does not matter much as
this program never tries to find day of week for any day
that is not the first of a month.
otherwise, after the reformation, use the same formula as the
days before with the additional step of subtracting the
number of days (11) that were adjusted out of the calendar
just before taking the modulo.
It must be noted that the number of leap years calculation is sensitive
to the date for which the leap year is being calculated. A year that occurs
before the reformation is determined to be a leap year if its modulo of
4 equals zero. But after the reformation, a year is only a leap year if
its modulo of 4 equals zero and its modulo of 100 does not. Of course,
there is an exception for these century years. If the modulo of 400 equals
zero, then the year is a leap year anyway. This is, in fact, what the
gregorian reformation was all about (a bit of error in the old algorithm
that caused the calendar to be inaccurate.)
Once we have the day in year for the first of the month in question, the
rest is trivial.

81
usr.bin/cal/cal.1 Normal file
View file

@ -0,0 +1,81 @@
.\" Copyright (c) 1989, 1990, 1993
.\" The Regents of the University of California. All rights reserved.
.\"
.\" This code is derived from software contributed to Berkeley by
.\" Kim Letkeman.
.\"
.\" 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.
.\"
.\" @(#)cal.1 8.1 (Berkeley) 6/6/93
.\"
.Dd June 6, 1993
.Dt CAL 1
.Os
.Sh NAME
.Nm cal
.Nd displays a calendar
.Sh SYNOPSIS
.Nm cal
.Op Fl jy
.Op Ar month Op Ar year
.Sh DESCRIPTION
.Nm Cal
displays a simple calendar.
If arguments are not specified,
the current month is displayed.
The options are as follows:
.Bl -tag -width Ds
.It Fl j
Display julian dates (days one-based, numbered from January 1).
.It Fl y
Display a calendar for the current year.
.El
.Pp
A single parameter specifies the year (1 - 9999) to be displayed;
note the year must be fully specified:
.Dq Li cal 89
will
.Em not
display a calendar for 1989.
Two parameters denote the month (1 - 12) and year.
If no parameters are specified, the current month's calendar is
displayed.
.Pp
A year starts on Jan 1.
.Pp
The Gregorian Reformation is assumed to have occurred in 1752 on the 3rd
of September.
By this time, most countries had recognized the reformation (although a
few did not recognize it until the early 1900's.)
Ten days following that date were eliminated by the reformation, so the
calendar for that month is a bit unusual.
.Sh HISTORY
A
.Nm
command appeared in Version 6 AT&T UNIX.

427
usr.bin/cal/cal.c Normal file
View file

@ -0,0 +1,427 @@
/*
* Copyright (c) 1989, 1993, 1994
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Kim Letkeman.
*
* 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) 1989, 1993, 1994\n\
The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */
#ifndef lint
static char sccsid[] = "@(#)cal.c 8.4 (Berkeley) 4/2/94";
#endif /* not lint */
#include <sys/types.h>
#include <ctype.h>
#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#define THURSDAY 4 /* for reformation */
#define SATURDAY 6 /* 1 Jan 1 was a Saturday */
#define FIRST_MISSING_DAY 639787 /* 3 Sep 1752 */
#define NUMBER_MISSING_DAYS 11 /* 11 day correction */
#define MAXDAYS 42 /* max slots in a month array */
#define SPACE -1 /* used in day array */
static int days_in_month[2][13] = {
{0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
{0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
};
int sep1752[MAXDAYS] = {
SPACE, SPACE, 1, 2, 14, 15, 16,
17, 18, 19, 20, 21, 22, 23,
24, 25, 26, 27, 28, 29, 30,
SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE,
SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE,
SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE,
}, j_sep1752[MAXDAYS] = {
SPACE, SPACE, 245, 246, 258, 259, 260,
261, 262, 263, 264, 265, 266, 267,
268, 269, 270, 271, 272, 273, 274,
SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE,
SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE,
SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE,
}, empty[MAXDAYS] = {
SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE,
SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE,
SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE,
SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE,
SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE,
SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE,
};
char *month_names[12] = {
"January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December",
};
char *day_headings = " S M Tu W Th F S";
char *j_day_headings = " S M Tu W Th F S";
/* leap year -- account for gregorian reformation in 1752 */
#define leap_year(yr) \
((yr) <= 1752 ? !((yr) % 4) : \
!((yr) % 4) && ((yr) % 100) || !((yr) % 400))
/* number of centuries since 1700, not inclusive */
#define centuries_since_1700(yr) \
((yr) > 1700 ? (yr) / 100 - 17 : 0)
/* number of centuries since 1700 whose modulo of 400 is 0 */
#define quad_centuries_since_1700(yr) \
((yr) > 1600 ? ((yr) - 1600) / 400 : 0)
/* number of leap years between year 1 and this year, not inclusive */
#define leap_years_since_year_1(yr) \
((yr) / 4 - centuries_since_1700(yr) + quad_centuries_since_1700(yr))
int julian;
void ascii_day __P((char *, int));
void center __P((char *, int, int));
void day_array __P((int, int, int *));
int day_in_week __P((int, int, int));
int day_in_year __P((int, int, int));
void j_yearly __P((int));
void monthly __P((int, int));
void trim_trailing_spaces __P((char *));
void usage __P((void));
void yearly __P((int));
int
main(argc, argv)
int argc;
char **argv;
{
struct tm *local_time;
time_t now;
int ch, month, year, yflag;
yflag = 0;
while ((ch = getopt(argc, argv, "jy")) != EOF)
switch(ch) {
case 'j':
julian = 1;
break;
case 'y':
yflag = 1;
break;
case '?':
default:
usage();
}
argc -= optind;
argv += optind;
month = 0;
switch(argc) {
case 2:
if ((month = atoi(*argv++)) < 1 || month > 12)
errx(1, "illegal month value: use 1-12");
/* FALLTHROUGH */
case 1:
if ((year = atoi(*argv)) < 1 || year > 9999)
errx(1, "illegal year value: use 1-9999");
break;
case 0:
(void)time(&now);
local_time = localtime(&now);
year = local_time->tm_year + 1900;
if (!yflag)
month = local_time->tm_mon + 1;
break;
default:
usage();
}
if (month)
monthly(month, year);
else if (julian)
j_yearly(year);
else
yearly(year);
exit(0);
}
#define DAY_LEN 3 /* 3 spaces per day */
#define J_DAY_LEN 4 /* 4 spaces per day */
#define WEEK_LEN 20 /* 7 * 3 - one space at the end */
#define J_WEEK_LEN 27 /* 7 * 4 - one space at the end */
#define HEAD_SEP 2 /* spaces between day headings */
#define J_HEAD_SEP 2
void
monthly(month, year)
int month, year;
{
int col, row, len, days[MAXDAYS];
char *p, lineout[30];
day_array(month, year, days);
len = sprintf(lineout, "%s %d", month_names[month - 1], year);
(void)printf("%*s%s\n%s\n",
((julian ? J_WEEK_LEN : WEEK_LEN) - len) / 2, "",
lineout, julian ? j_day_headings : day_headings);
for (row = 0; row < 6; row++) {
for (col = 0, p = lineout; col < 7; col++,
p += julian ? J_DAY_LEN : DAY_LEN)
ascii_day(p, days[row * 7 + col]);
*p = '\0';
trim_trailing_spaces(lineout);
(void)printf("%s\n", lineout);
}
}
void
j_yearly(year)
int year;
{
int col, *dp, i, month, row, which_cal;
int days[12][MAXDAYS];
char *p, lineout[80];
(void)sprintf(lineout, "%d", year);
center(lineout, J_WEEK_LEN * 2 + J_HEAD_SEP, 0);
(void)printf("\n\n");
for (i = 0; i < 12; i++)
day_array(i + 1, year, days[i]);
(void)memset(lineout, ' ', sizeof(lineout) - 1);
lineout[sizeof(lineout) - 1] = '\0';
for (month = 0; month < 12; month += 2) {
center(month_names[month], J_WEEK_LEN, J_HEAD_SEP);
center(month_names[month + 1], J_WEEK_LEN, 0);
(void)printf("\n%s%*s%s\n", j_day_headings, J_HEAD_SEP, "",
j_day_headings);
for (row = 0; row < 6; row++) {
for (which_cal = 0; which_cal < 2; which_cal++) {
p = lineout + which_cal * (J_WEEK_LEN + 2);
dp = &days[month + which_cal][row * 7];
for (col = 0; col < 7; col++, p += J_DAY_LEN)
ascii_day(p, *dp++);
}
*p = '\0';
trim_trailing_spaces(lineout);
(void)printf("%s\n", lineout);
}
}
(void)printf("\n");
}
void
yearly(year)
int year;
{
int col, *dp, i, month, row, which_cal;
int days[12][MAXDAYS];
char *p, lineout[80];
(void)sprintf(lineout, "%d", year);
center(lineout, WEEK_LEN * 3 + HEAD_SEP * 2, 0);
(void)printf("\n\n");
for (i = 0; i < 12; i++)
day_array(i + 1, year, days[i]);
(void)memset(lineout, ' ', sizeof(lineout) - 1);
lineout[sizeof(lineout) - 1] = '\0';
for (month = 0; month < 12; month += 3) {
center(month_names[month], WEEK_LEN, HEAD_SEP);
center(month_names[month + 1], WEEK_LEN, HEAD_SEP);
center(month_names[month + 2], WEEK_LEN, 0);
(void)printf("\n%s%*s%s%*s%s\n", day_headings, HEAD_SEP,
"", day_headings, HEAD_SEP, "", day_headings);
for (row = 0; row < 6; row++) {
for (which_cal = 0; which_cal < 3; which_cal++) {
p = lineout + which_cal * (WEEK_LEN + 2);
dp = &days[month + which_cal][row * 7];
for (col = 0; col < 7; col++, p += DAY_LEN)
ascii_day(p, *dp++);
}
*p = '\0';
trim_trailing_spaces(lineout);
(void)printf("%s\n", lineout);
}
}
(void)printf("\n");
}
/*
* day_array --
* Fill in an array of 42 integers with a calendar. Assume for a moment
* that you took the (maximum) 6 rows in a calendar and stretched them
* out end to end. You would have 42 numbers or spaces. This routine
* builds that array for any month from Jan. 1 through Dec. 9999.
*/
void
day_array(month, year, days)
int month, year;
int *days;
{
int day, dw, dm;
if (month == 9 && year == 1752) {
memmove(days,
julian ? j_sep1752 : sep1752, MAXDAYS * sizeof(int));
return;
}
memmove(days, empty, MAXDAYS * sizeof(int));
dm = days_in_month[leap_year(year)][month];
dw = day_in_week(1, month, year);
day = julian ? day_in_year(1, month, year) : 1;
while (dm--)
days[dw++] = day++;
}
/*
* day_in_year --
* return the 1 based day number within the year
*/
int
day_in_year(day, month, year)
int day, month, year;
{
int i, leap;
leap = leap_year(year);
for (i = 1; i < month; i++)
day += days_in_month[leap][i];
return (day);
}
/*
* day_in_week
* return the 0 based day number for any date from 1 Jan. 1 to
* 31 Dec. 9999. Assumes the Gregorian reformation eliminates
* 3 Sep. 1752 through 13 Sep. 1752. Returns Thursday for all
* missing days.
*/
int
day_in_week(day, month, year)
int day, month, year;
{
long temp;
temp = (long)(year - 1) * 365 + leap_years_since_year_1(year - 1)
+ day_in_year(day, month, year);
if (temp < FIRST_MISSING_DAY)
return ((temp - 1 + SATURDAY) % 7);
if (temp >= (FIRST_MISSING_DAY + NUMBER_MISSING_DAYS))
return (((temp - 1 + SATURDAY) - NUMBER_MISSING_DAYS) % 7);
return (THURSDAY);
}
void
ascii_day(p, day)
char *p;
int day;
{
int display, val;
static char *aday[] = {
"",
" 1", " 2", " 3", " 4", " 5", " 6", " 7",
" 8", " 9", "10", "11", "12", "13", "14",
"15", "16", "17", "18", "19", "20", "21",
"22", "23", "24", "25", "26", "27", "28",
"29", "30", "31",
};
if (day == SPACE) {
memset(p, ' ', julian ? J_DAY_LEN : DAY_LEN);
return;
}
if (julian) {
if (val = day / 100) {
day %= 100;
*p++ = val + '0';
display = 1;
} else {
*p++ = ' ';
display = 0;
}
val = day / 10;
if (val || display)
*p++ = val + '0';
else
*p++ = ' ';
*p++ = day % 10 + '0';
} else {
*p++ = aday[day][0];
*p++ = aday[day][1];
}
*p = ' ';
}
void
trim_trailing_spaces(s)
char *s;
{
char *p;
for (p = s; *p; ++p)
continue;
while (p > s && isspace(*--p))
continue;
if (p > s)
++p;
*p = '\0';
}
void
center(str, len, separate)
char *str;
int len;
int separate;
{
len -= strlen(str);
(void)printf("%*s%s%*s", len / 2, "", str, len / 2 + len % 2, "");
if (separate)
(void)printf("%*s", separate, "");
}
void
usage()
{
(void)fprintf(stderr, "usage: cal [-jy] [[month] year]\n");
exit(1);
}

View file

@ -0,0 +1,9 @@
# @(#)Makefile 8.1 (Berkeley) 6/6/93
PROG= calendar
beforeinstall:
install -c -o ${BINOWN} -g ${BINGRP} -m 444 \
${.CURDIR}/calendars/calendar.* ${DESTDIR}/usr/share/calendar
.include <bsd.prog.mk>

145
usr.bin/calendar/calendar.1 Normal file
View file

@ -0,0 +1,145 @@
.\" Copyright (c) 1989, 1990, 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.
.\"
.\" @(#)calendar.1 8.1 (Berkeley) 6/29/93
.\"
.Dd June 29, 1993
.Dt CALENDAR 1
.Os
.Sh NAME
.Nm calendar
.Nd reminder service
.Sh SYNOPSIS
.Nm calendar
.Op Fl a
.Sh DESCRIPTION
.Nm Calendar
checks the current directory for a file named
.Pa calendar
and displays lines that begin with either today's date
or tomorrow's.
On Fridays, events on Friday through Monday are displayed.
.Pp
The following options are available:
.Bl -tag -width Ds
.It Fl a
Process the ``calendar'' files of all users and mail the results
to them.
This requires super-user privileges.
.El
.Pp
Lines should begin with a month and day.
They may be entered in almost any format, either numeric or as character
strings.
A single asterisk (``*'') matches every month.
A day without a month matches that day of every week.
A month without a day matches the first of that month.
Two numbers default to the month followed by the day.
Lines with leading tabs default to the last entered date, allowing
multiple line specifications for a single date.
By convention, dates followed by an asterisk are not fixed, i.e., change
from year to year.
.Pp
The ``calendar'' file is preprocessed by
.Xr cpp 1 ,
allowing the inclusion of shared files such as company holidays or
meetings.
If the shared file is not referenced by a full pathname,
.Xr cpp 1
searches in the current (or home) directory first, and then in the
directory
.Pa /usr/share/calendar .
Empty lines and lines protected by the C commenting syntax
.Pq Li /* ... */
are ignored.
.Pp
Some possible calendar entries:
.Bd -unfilled -offset indent
#include <calendar.usholiday>
#include <calendar.birthday>
6/15 ... June 15 (if ambiguous, will default to month/day).
Jun. 15 ... June 15.
15 June ... June 15.
Thursday ... Every Thursday.
June ... Every June 1st.
15 * ... 15th of every month.
.Ed
.Sh FILES
The following default calendar files are provided:
.Pp
.Bl -tag -width calendar.christian -compact
.It Pa calendar.birthday
Births and deaths of famous (and not-so-famous) people.
.It Pa calendar.christian
Christian holidays.
This calendar should be updated yearly by the local system administrator
so that roving holidays are set correctly for the current year.
.It Pa calendar.computer
Days of special significance to computer people.
.It Pa calendar.history
Everything else, mostly U. S. historical events.
.It Pa calendar.holiday
Other holidays, including the not-well-known, obscure, and
.Em really
obscure.
.It Pa calendar.judaic
Jewish holidays.
This calendar should be updated yearly by the local system administrator
so that roving holidays are set correctly for the current year.
.It Pa calendar.music
Musical events, births, and deaths.
Strongly oriented toward rock 'n' roll.
.It Pa calendar.usholiday
U.S. holidays.
This calendar should be updated yearly by the local system administrator
so that roving holidays are set correctly for the current year.
.El
.Sh SEE ALSO
.Xr at 1 ,
.Xr cpp 1 ,
.Xr cron 8
.Xr mail 1 ,
.Sh COMPATIBILITY
The
.Nm calendar
program previously selected lines which had the correct date anywhere
in the line.
This is no longer true, the date is only recognized when it occurs
first on the line.
.Sh HISTORY
A
.Nm
command appeared in Version 7 AT&T UNIX.
.Sh BUGS
.Nm Calendar
doesn't handle events that move around from year to year, i.e.,
``the last Monday in April''.

411
usr.bin/calendar/calendar.c Normal file
View file

@ -0,0 +1,411 @@
/*
* Copyright (c) 1989, 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) 1989, 1993\n\
The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */
#ifndef lint
static char sccsid[] = "@(#)calendar.c 8.3 (Berkeley) 3/25/94";
#endif /* not lint */
#include <sys/param.h>
#include <sys/time.h>
#include <sys/stat.h>
#include <sys/uio.h>
#include <sys/wait.h>
#include <ctype.h>
#include <err.h>
#include <errno.h>
#include <fcntl.h>
#include <pwd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <tzfile.h>
#include <unistd.h>
#include "pathnames.h"
struct passwd *pw;
int doall;
void cal __P((void));
void closecal __P((FILE *));
int getday __P((char *));
int getfield __P((char *, char **, int *));
int getmonth __P((char *));
int isnow __P((char *));
FILE *opencal __P((void));
void settime __P((void));
void usage __P((void));
int
main(argc, argv)
int argc;
char *argv[];
{
extern int optind;
int ch;
while ((ch = getopt(argc, argv, "-a")) != EOF)
switch (ch) {
case '-': /* backward contemptible */
case 'a':
if (getuid()) {
errno = EPERM;
err(1, NULL);
}
doall = 1;
break;
case '?':
default:
usage();
}
argc -= optind;
argv += optind;
if (argc)
usage();
settime();
if (doall)
while ((pw = getpwent()) != NULL) {
(void)setegid(pw->pw_gid);
(void)seteuid(pw->pw_uid);
if (!chdir(pw->pw_dir))
cal();
(void)seteuid(0);
}
else
cal();
exit(0);
}
void
cal()
{
register int printing;
register char *p;
FILE *fp;
int ch;
char buf[2048 + 1];
if ((fp = opencal()) == NULL)
return;
for (printing = 0; fgets(buf, sizeof(buf), stdin) != NULL;) {
if ((p = strchr(buf, '\n')) != NULL)
*p = '\0';
else
while ((ch = getchar()) != '\n' && ch != EOF);
if (buf[0] == '\0')
continue;
if (buf[0] != '\t')
printing = isnow(buf) ? 1 : 0;
if (printing)
(void)fprintf(fp, "%s\n", buf);
}
closecal(fp);
}
struct iovec header[] = {
"From: ", 6,
NULL, 0,
" (Reminder Service)\nTo: ", 24,
NULL, 0,
"\nSubject: ", 10,
NULL, 0,
"'s Calendar\nPrecedence: bulk\n\n", 30,
};
/* 1-based month, 0-based days, cumulative */
int daytab[][14] = {
0, -1, 30, 58, 89, 119, 150, 180, 211, 242, 272, 303, 333, 364,
0, -1, 30, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365,
};
struct tm *tp;
int *cumdays, offset, yrdays;
char dayname[10];
void
settime()
{
time_t now;
(void)time(&now);
tp = localtime(&now);
if (isleap(tp->tm_year + 1900)) {
yrdays = DAYSPERLYEAR;
cumdays = daytab[1];
} else {
yrdays = DAYSPERNYEAR;
cumdays = daytab[0];
}
/* Friday displays Monday's events */
offset = tp->tm_wday == 5 ? 3 : 1;
header[5].iov_base = dayname;
header[5].iov_len = strftime(dayname, sizeof(dayname), "%A", tp);
}
/*
* Possible date formats include any combination of:
* 3-charmonth (January, Jan, Jan)
* 3-charweekday (Friday, Monday, mon.)
* numeric month or day (1, 2, 04)
*
* Any character may separate them, or they may not be separated. Any line,
* following a line that is matched, that starts with "whitespace", is shown
* along with the matched line.
*/
int
isnow(endp)
char *endp;
{
int day, flags, month, v1, v2;
#define F_ISMONTH 0x01
#define F_ISDAY 0x02
flags = 0;
/* didn't recognize anything, skip it */
if (!(v1 = getfield(endp, &endp, &flags)))
return (0);
if (flags & F_ISDAY || v1 > 12) {
/* found a day */
day = v1;
/* if no recognizable month, assume just a day alone */
if (!(month = getfield(endp, &endp, &flags)))
month = tp->tm_mon + 1;
} else if (flags & F_ISMONTH) {
month = v1;
/* if no recognizable day, assume the first */
if (!(day = getfield(endp, &endp, &flags)))
day = 1;
} else {
v2 = getfield(endp, &endp, &flags);
if (flags & F_ISMONTH) {
day = v1;
month = v2;
} else {
/* F_ISDAY set, v2 > 12, or no way to tell */
month = v1;
/* if no recognizable day, assume the first */
day = v2 ? v2 : 1;
}
}
if (flags & F_ISDAY)
day = tp->tm_mday + (((day - 1) - tp->tm_wday + 7) % 7);
day = cumdays[month] + day;
/* if today or today + offset days */
if (day >= tp->tm_yday && day <= tp->tm_yday + offset)
return (1);
/* if number of days left in this year + days to event in next year */
if (yrdays - tp->tm_yday + day <= offset)
return (1);
return (0);
}
int
getfield(p, endp, flags)
char *p, **endp;
int *flags;
{
int val;
char *start, savech;
for (; !isdigit(*p) && !isalpha(*p) && *p != '*'; ++p);
if (*p == '*') { /* `*' is current month */
*flags |= F_ISMONTH;
*endp = p+1;
return (tp->tm_mon + 1);
}
if (isdigit(*p)) {
val = strtol(p, &p, 10); /* if 0, it's failure */
for (; !isdigit(*p) && !isalpha(*p) && *p != '*'; ++p);
*endp = p;
return (val);
}
for (start = p; isalpha(*++p););
savech = *p;
*p = '\0';
if ((val = getmonth(start)) != 0)
*flags |= F_ISMONTH;
else if ((val = getday(start)) != 0)
*flags |= F_ISDAY;
else {
*p = savech;
return (0);
}
for (*p = savech; !isdigit(*p) && !isalpha(*p) && *p != '*'; ++p);
*endp = p;
return (val);
}
char path[MAXPATHLEN + 1];
FILE *
opencal()
{
int fd, pdes[2];
/* open up calendar file as stdin */
if (!freopen("calendar", "r", stdin)) {
if (doall)
return (NULL);
errx(1, "no calendar file.");
}
if (pipe(pdes) < 0)
return (NULL);
switch (vfork()) {
case -1: /* error */
(void)close(pdes[0]);
(void)close(pdes[1]);
return (NULL);
case 0:
/* child -- stdin already setup, set stdout to pipe input */
if (pdes[1] != STDOUT_FILENO) {
(void)dup2(pdes[1], STDOUT_FILENO);
(void)close(pdes[1]);
}
(void)close(pdes[0]);
execl(_PATH_CPP, "cpp", "-I.", _PATH_INCLUDE, NULL);
(void)fprintf(stderr,
"calendar: execl: %s: %s.\n", _PATH_CPP, strerror(errno));
_exit(1);
}
/* parent -- set stdin to pipe output */
(void)dup2(pdes[0], STDIN_FILENO);
(void)close(pdes[0]);
(void)close(pdes[1]);
/* not reading all calendar files, just set output to stdout */
if (!doall)
return (stdout);
/* set output to a temporary file, so if no output don't send mail */
(void)snprintf(path, sizeof(path), "%s/_calXXXXXX", _PATH_TMP);
if ((fd = mkstemp(path)) < 0)
return (NULL);
return (fdopen(fd, "w+"));
}
void
closecal(fp)
FILE *fp;
{
struct stat sbuf;
int nread, pdes[2], status;
char buf[1024];
if (!doall)
return;
(void)rewind(fp);
if (fstat(fileno(fp), &sbuf) || !sbuf.st_size)
goto done;
if (pipe(pdes) < 0)
goto done;
switch (vfork()) {
case -1: /* error */
(void)close(pdes[0]);
(void)close(pdes[1]);
goto done;
case 0:
/* child -- set stdin to pipe output */
if (pdes[0] != STDIN_FILENO) {
(void)dup2(pdes[0], STDIN_FILENO);
(void)close(pdes[0]);
}
(void)close(pdes[1]);
execl(_PATH_SENDMAIL, "sendmail", "-i", "-t", "-F",
"\"Reminder Service\"", "-f", "root", NULL);
(void)fprintf(stderr,
"calendar: %s: %s.\n", _PATH_SENDMAIL, strerror(errno));
_exit(1);
}
/* parent -- write to pipe input */
(void)close(pdes[0]);
header[1].iov_base = header[3].iov_base = pw->pw_name;
header[1].iov_len = header[3].iov_len = strlen(pw->pw_name);
writev(pdes[1], header, 7);
while ((nread = read(fileno(fp), buf, sizeof(buf))) > 0)
(void)write(pdes[1], buf, nread);
(void)close(pdes[1]);
done: (void)fclose(fp);
(void)unlink(path);
while (wait(&status) >= 0);
}
static char *months[] = {
"jan", "feb", "mar", "apr", "may", "jun",
"jul", "aug", "sep", "oct", "nov", "dec", NULL,
};
int
getmonth(s)
register char *s;
{
register char **p;
for (p = months; *p; ++p)
if (!strncasecmp(s, *p, 3))
return ((p - months) + 1);
return (0);
}
static char *days[] = {
"sun", "mon", "tue", "wed", "thu", "fri", "sat", NULL,
};
int
getday(s)
register char *s;
{
register char **p;
for (p = days; *p; ++p)
if (!strncasecmp(s, *p, 3))
return ((p - days) + 1);
return (0);
}
void
usage()
{
(void)fprintf(stderr, "usage: calendar [-a]\n");
exit(1);
}

View file

@ -0,0 +1,257 @@
01/01 J.D. Salinger born, 1919
01/01 Paul Revere born in Boston, 1735
01/02 Isaac Asimov born in Petrovichi, Russian SFSR (now part of USSR), 1920
01/04 George Washington Carver born in Missouri, 1864
01/04 Jakob Grimm born, 1785
01/04 Wilhelm Beer born, 1797, first astronomer to map Mars
01/05 DeWitt B. Brace born, 1859, inventor of spectrophotometer
01/10 Ethan Allen born, 1738
01/11 Alexander Hamilton born in Nevis, British West Indies, 1757?
01/12 "Long" John Baldry is born in London, 1941
01/13 Horatio Alger born, 1834
01/13 Sophie Tucker born, 1884
01/13 Wilhelm Wien born, 1864, Nobel prize for blackbody radiation laws
01/14 Albert Schweitzer born, 1875
01/15 Martin Luther King, Jr. born
01/17 Benjamin Franklin born in Boston, 1706
01/19 Edgar Allan Poe born in Boston, 1809
01/19 Robert Edward Lee born in Stratford Estate, Virginia, 1807
01/20 George Burns born, 1898
01/21 Lenin died, 1924
01/21 Thomas Jonathan "Stonewall" Jackson born in Clarksburg, VA, 1824
01/22 Sir Francis Bacon born, 1561
01/23 Ernst Abbe born, 1840, formulated diffraction theory
01/23 Humphrey Bogart born in New York City, 1899
01/23 John Hancock born, 1737
01/23 Joseph Hewes born, 1730
01/23 Samuel Barber died, 1981
01/24 John Belushi is born in Chicago, 1949
01/25 Robert Burns born, 1759
01/25 Virginia Woolf born, 1882
01/25 W. Somerset Maugham born, 1874
01/27 Samuel Gompers born, 1850
01/30 Franklin Delano Roosevelt born in Hyde Park, New York, 1882
01/31 Jackie Robinson born, 1919
02/03 Gertrude Stein born, 1874
02/05 Alex Harvey (SAHB) is born in Glasgow, Scotland, 1935
02/06 King George VI of UK dies; his daughter becomes Elizabeth II, 1952
02/07 Sinclair Lewis born, 1885
02/08 Friedleib F. Runge born, 1795, father of paper chromatography
02/08 Jules Verne born in Nantes, France, 1828
02/09 George Hartmann born, 1489, designed astrolabes, timepieces, etc.
02/10 Charles Lamb born, 1775
02/10 William Allen White born, 1868
02/11 Thos. Edison born, 1847
02/11 William Henry Fox Talbot born, 1489, photographic pioneer
02/12 Abraham Lincoln born, 1809
02/12 Charles Darwin born in Shrewsbury, England, 1809
02/15 Galileo Galilei born in Pisa, Italy, 1564
02/15 Susan B. Anthony born, 1820
02/16 Pierre Bouguer born, 1698, founder of photometry
02/17 Federick Eugene Ives born, 1856, pioneer of halftone
02/17 Marion Anderson born, 1902
02/17 T. J. Watson, Sr. born, 1874
02/18 Ernst Mach born, 1838, philosopher & optics pioneer
02/19 Nicolas Copernicus born in Thorn, Poland, 1473
02/20 Ludwig Boltzmann born, 1838, atomic physics pioneer
02/21 Alexis De Rochon born, 1838, developed the spyglass
02/22 George Washington born, 1732
02/22 Pierre Jules Cesar Janssen born, 1838, found hydrogen in the sun
02/23 W.E.B. DuBois born, 1868
02/24 Winslow Homer born, 1836
02/25 George Harrison born in Liverpool, England, 1943
02/25 Renoir born, 1841
02/26 Dominique Francois Jean Arago born, 1786;
observed "Poisson's spot" cf June 21
02/28 Michel de Mantaigne born, 1533
02/29 Herman Hollerith born, 1860
03/01 David Niven born, 1910
03/02 Dr. Seuss born, 1904
03/04 Casimir Pulaski born, 1747
03/05 John Belushi dies in Los Angeles, 1982
03/07 Aristotle died, 322BC
03/07 Sir John Frederick William Herschel born, 1792, astronomer
03/08 Alvan Clark born, 1804, astronomer & lens manufacturer
03/08 Howard Aiken born, 1900
03/11 Robert Treat Paine born, 1737
03/11 Vannevar Bush born, 1890
03/12 Gustav Robert Kirchhoff born, 1824, physicist
03/14 Albert Einstein born, 1879
03/14 Casey Jones born, 1864
03/14 Giovanni Virginia Schiaparelli born, 1835, astronomer;
named Mars "canals"
03/14 Jean Baptiste Joseph Fourier born, 1768, mathematician & physicist
03/16 George Clymer born, 1739
03/16 James Madison born, 1751
03/24 Harry Houdini born, 1874
03/26 Benjamin Thompson born, 1753, Count Rumford; physicist
03/27 Wilhelm Conrad Roentgen born, 1845, discoverer of X-rays
03/28 Pierre Simon de Laplace born, 1749, mathematician & astronomer
03/30 Francisco Jose de Goya born, 1746
03/30 Sean O'Casey born, 1880
03/30 Vincent Van Gogh born, 1853
03/31 Descartes born, 1596
03/31 Rene Descartes born, 1596, mathematician & philosopher
04/03 Washington Irving born, 1783
04/05 Thomas Hobbes born, 1588, philosopher
04/08 Buddha born, 563 BC
04/08 David Rittenhouse born, 1732, astronomer & mathematician
04/09 Edward Muybridge born, 1830, motion-picture pioneer
04/09 J. Presper Eckert born, 1919
04/10 Commodore Matthew Calbraith Perry born, 1854
04/10 William Booth born, 1829, founder of the Salvation Army
04/13 Thomas Jefferson born, 1743
04/14 Christian Huygen born, 1629, physicist & astronomer;
discovered Saturn's rings
04/15 Leonardo da Vinci born, 1452
04/16 Charles (Charlie) Chaplin (Sir) born in London, 1889
04/22 Kant born, 1724
04/27 Louis Victor de Broglie born, 1774, physicist
04/28 James Monroe born, 1758
04/29 Jules Henri Poincare born, 1854, founder of topology
04/29 William Randolph Hearst born in San Francisco, 1863
04/30 Karl Friedrich Gauss born, 1777, mathematician & astronomer
05/01 Little Walter (Marion Walter Jacobs) is born in Alexandria,
Louisiana, 1930
05/02 Dr. Benjamin Spock born, 1903
05/09 Pinza died, 1957
05/10 Fred Astaire (Frederick Austerlitz) born in Omaha, Nebraska, 1899
05/11 Johnny Appleseed born, 1768
05/12 Florence Nightingale born in Florence, Italy, 1820
05/13 Arthur S. Sullivan born, 1842
05/15 Mike Oldfield is born in Essex, England, 1953
05/19 Ho Chi Minh born, 1890
05/21 Plato (Aristocles) born in Athens(?), 427BC
05/27 Hubert H. Humphrey born, 1911
05/28 Dionne quintuplets born, 1934
05/29 Gilbert Keith Chesterton born, 1874
05/29 John Fitzgerald Kennedy born, 1917
05/29 Patrick Henry born, 1736
05/30 Mel (Melvin Jerome) Blanc born in San Francisco, 1908
06/01 Brigham Young born, 1801
06/01 Marilyn Monroe born, 1928
06/02 Edward Elgar (Sir) born in Worcester, England, 1857
06/03 Henry James born, 1811
06/07 (Eugene Henri) Paul Gaugin born, 1848
06/07 George Bryan "Beau" Brummel born, 1778
06/08 Frank Lloyd Wright born in Richland Center, Wisconsin, 1869
06/13 Alexander the Great dies (323BC)
06/15 Edward (Edvard Hagerup) Grieg born in Bergen, Norway, 1843
06/16 Hammurabi the Great dies, Babylon, 1686 bc
06/18 M.C. Escher born, 1898
06/22 Carl Hubbell born, 1903
06/22 Meryl Streep born in Summit, New Jersey, 1949
06/25 Eric Arthur Blair (a.k.a. George Orwell) born, 1903
06/27 Helen Keller born, 1880
07/03 Franz Kafka born, 1883
07/04 Nathaniel Hawthorne born in Salem, Massachusetts, 1804
07/06 (Helen) Beatrix Potter born, 1866
07/06 John Paul Jones born, 1747
07/07 P.T. Barnum dies, 1891
07/08 Count Ferdinand von Zeppelin born, 1838
07/10 John Calvin born, 1509
07/11 John Quincy Adams born, 1767
07/12 Henry David Thoreau born, 1817
07/15 Clement Clarke Moore born, 1779, author of "A Visit from
Saint Nicholas"
07/18 Brian Auger is born in London, 1939
07/25 Steve Goodman is born in Chicago, 1948
07/29 Mussolini born, 1883
07/30 Emily Bronte born, 1818
07/30 Henry Ford born, 1863
08/01 Herman Melville born, 1819
08/03 Lenny Bruce dies of a morphine overdose, 1966
08/08 Dustin Hoffman born in Los Angeles, 1937
08/13 Annie Oakley born, 1860
08/13 Fidel Castro born, 1927
08/17 Mae West born, 1892
08/18 Meriwether Lewis born, 1927
08/23 Gene Kelly born, 1912
08/27 Lyndon B. Johnson born, 1908
08/29 Oliver Wendell Holmes born, 1809, physician & father of the jurist
08/30 John W. Mauchly born, 1907
09/05 King Louis XIV of France born, 1638
09/05 Raquel Welch born, 1942
09/06 Word is received that Perry has reached the North Pole and died, 1909
09/07 James Fenimore Cooper born in Burlington, NJ, 1789
09/07 Queen Elizabeth I of England born, 1533
09/08 King Richard I of England born, 1157
09/08 Peter Sellers born in Southsea, England, 1925
09/09 Chinese Communist Party Chairman Mao Tse-Tung dies at age 82, 1976
09/12 Jesse Owens born, 1913
09/13 Walter Reed born, 1851
09/15 Agatha Christie born in Torquay, England, 1890
09/16 Allen Funt born in Brooklyn, NY, 1914
09/18 Greta Garbo born, 1905
09/18 Jimi Hendrix dies from an overdose, 1970
09/20 Upton (Beall) Sinclair born, 1878
09/21 H.G. (Herbert George) Wells born in Bromley, England, 1866
09/21 Louis Joliet born, 1645
09/22 President Garfield dies of wounds in Baltimore, 1881
09/23 Augustus (Gaius Octavius) Caesar born in Rome, 63 BC
09/23 Euripides born in Salamis, Greece, 480 BC
09/24 F. Scott Fitzgerald born, 1896
09/26 Johnny Appleseed born, 1774
09/26 T.S. (Thomas Stearns) Eliot born in St. Louis, 1888
09/27 Thomas Nast born, 1840
09/28 Michelangelo Buanarroti born in Caprese, Italy, 1573
09/28 Pompey (Gnaeus Pompeius Magnus) born in Rome, 106BC
09/28 Seymour Cray born, 1925
09/29 Gene Autry born, 1907
10/01 Jimmy Carter born, 1924
10/02 Aristotle dies of indigestion, 322 BC
10/02 Mohandas K. Gandhi born at Porbandar, Kathiawad, India, 1869
10/04 John V. Atanasoff born, 1903
10/05 Pablo Picasso born in Malaga, Spain, 1881
10/05 Ray Kroc (founder of McDonald's) born, 1902
10/13 Lenny Bruce is born in New York City, 1925
10/13 Virgil (Publius Vergilius Maro) born near Mantua, Italy, 70 BC
10/14 Dwight David Eisenhower born, 1890
10/14 William Penn born in London, 1644
10/15 Pelham Grenville Wodehouse born, 1881
10/16 Noah Webster born, 1758
10/16 Oscar (Fingal O'Flahertie Wills) Wilde born in Dublin, 1854
10/17 Richard Mentor Johnson born, 1780, 9th V.P. of U.S.
10/21 Alfred Nobel born in Stockholm, 1833
10/27 Gerald M. Weinberg born, 1933
10/27 James Cook is born, 1466
10/31 Chiang Kai-Shek born, 1887
10/31 Dale Evans born, 1912
11/02 Daniel Boone born near Reading, PA, 1734
11/04 King William III of Orange born, 1650
11/05 Roy Rogers born, 1912
11/09 Carl Sagan born, 1934
11/10 Martin Luther born in Eisleben, Germany, 1483
11/10 Soviet President Leonid Brezhnev dies at age 75, 1982
11/11 Kurt Vonnegut, Jr, born in Indianapolis, 1922
11/13 Robert Louis Stevenson born, 1850
11/13 St. Augustine of Hippo born in Numidia, Algeria, 354
11/18 Imogene Coca born, 1908
11/18 William S. Gilbert born, 1836
11/20 RFK born, 1925
11/26 Charles Schulz born in Minneapolis, 1922
11/26 Norbert Weiner born, 1894
11/29 John Mayall is born in Cheshire, England, 1933
11/30 Cleopatra died, 30 BC
11/30 Mark Twain (Samuel Clemmens) born in Florida, Missouri, 1835
12/01 Woody Allen (Allen Stuart Konigsberg) born in Brooklyn, NY, 1935
12/04 Tommy Bolin dies of a heroin overdose in Miami, 1976
12/05 Walt (Walter Elias) Disney born in Chicago, 1901
12/08 Horace (Quintus Horatius Flaccus) born in Venosa (Italy), 65BC
12/08 James (Grover) Thurber born in Columbus, Ohio, 1894
12/10 Emily Dickenson born, 1830
12/12 E.G. Robinson born, 1893
12/14 George Washington dies, 1799
12/17 William Safire (Safir) born, 1929
12/21 Benjamin Disraeli born, 1804
12/22 Giacomo Puccini born, 1858
12/23 Joseph Smith born, 1805
12/25 Isaac Newton (Sir) born in Grantham, England, 1642
12/26 Chas. Babbage born, 1791
12/28 John von Neumann born, 1903
03/15 J.J. Robert's Birthday in Liberia
03/15 Julius Caesar assassinated by Brutus; Ides of March, 44BC
07/04 John Adams and Thomas Jefferson die on same day, 1826
07/12 Thoreau's Birthday, 1817
08/12 Thomas Mann's Death, 1955
08/20 Leon Trotsky assassinated, 1940

View file

@ -0,0 +1,16 @@
01/06* Epiphany
02/11* Shrove Tuesday / Mardi Gras (day before Ash Wednesday)
02/08* Ash Wednesday (First day of Lent)
03/19* Palm Sunday (7 days before Easter)
03/23* Maundy Thursday (3 days before Easter)
03/24* Good Friday (2 days before Easter)
03/26* Easter Sunday
05/04* Ascension Day (10 days before Pentecost)
05/14* Pentecost (Whitsunday)
05/15* Whitmonday
05/21* Trinity Sunday (7 days after Pentecost)
05/25* Corpus Christi (11 days after Pentecost)
05/28* Rogation Sunday
10/18 Feast Day of St. Luke
12/03* First Sunday of Advent (4th Sunday before Christmas)
12/06 St. Nicholas' Day

View file

@ -0,0 +1,62 @@
01/01 AT&T officially divests its local Bell companies, 1984
01/01 The Epoch (Time 0 for UNIX systems, Midnight GMT, 1970)
01/03 Apple Computer founded, 1977
01/08 American Telephone and Telegraph loses antitrust case, 1982
01/08 Herman Hollerith patents first data processing computer, 1889
01/08 Justice Dept. drops IBM suit, 1982
01/10 First CDC 1604 delivered to Navy, 1960
01/16 Set uid bit patent issued, to Dennis Ritchie, 1979
01/17 Justice Dept. begins IBM anti-trust suit, 1969 (drops it, 01/08/82)
01/24 DG Nova introduced, 1969
01/25 First U.S. meeting of ALGOL definition committee, 1958
01/26 EDVAC demonstrated, 1952
01/31 Hewlett-Packard founded, 1939
02/11 Last day of JOSS service at RAND Corp., 1966
02/14 First micro-on-a-chip patented (TI), 1978
02/15 ENIAC demonstrated, 1946
03/01 First NPL (later PL/I) report published, 1964
03/04 First Cray-1 shipped to Los Alamos
03/09 "GOTO considered harmful" (E.J. Dikstra) published in CACM, 1968
03/14 LISP introduced, 1960
03/28 DEC announces PDP-11, 1970
03/31 Eckert-Mauchly Computer Corp. founded, Phila, 1946
04/01 Yourdon, Inc. founded, 1974 (It figures.)
04/03 IBM 701 introduced, 1953
04/04 Tandy Corp. acquires Radio Shack, 1963 (9 stores)
04/07 IBM announces System/360, 1964
04/09 ENIAC Project begun, 1943
04/28 Zilog Z-80 introduced
05/06 EDSAC demonstrated, 1949
05/01 First BASIC program run at Dartmouth, 1964
05/16 First report on SNOBOL distributed (within BTL), 1963
05/21 DEC announces PDP-8
05/22 Ethernet first described, 1973
05/27 First joint meeting of U.S. and European ALGOL definition cte., 1958
05/28 First meeting of COBOL definition cte. (eventually CODASYL), 1959
05/30 Colossus Mark II, 1944
06/02 First issue of Computerworld, 1967
06/10 First Apple II shipped, 1977
06/15 UNIVAC I delivered to the Census Bureau, 1951
06/16 First programming error at Census Bureau, 1951 (apocryphal)
06/23 IBM unbundles software, 1969
06/23 Turing's Birthday, 1912
06/30 First advanced degree on computer related topic: to H. Karamanian,
Temple Univ., Phila, 1948, for symbolic diffentiation on the ENIAC
07/08 Bell Telephone Co. formed (predecessor of AT&T), 1877
07/08 CDC incorporated, 1957
08/14 First Unix-based mallet created, 1954
08/14 IBM PC announced, 1981
08/22 CDC 6600 introduced, 1963
08/23 DEC founded, 1957
09/15 ACM founded, 1947
09/20 Harlan Herrick runs first FORTRAN program, 1954
10/02 First robotics-based CAM, 1939
10/06 First GPSS manual published, 1961
10/08 First VisiCalc prototype, 1978
10/12 Univac gives contract for SIMULA compiler to Nygaard and Dahl, 1962
10/14 British Computer Society founded, 1957
10/15 First FORTRAN Programmer's Reference Manual published
10/20 Zurich ALGOL report published, 1958
10/25 DEC announces VAX-11/780
11/04 UNIVAC I program predicts Eisenhower victory based on 7% of votes, 1952
12/08 First Ph.D. awarded by Computer Science Dept, Univ. of Penna, 1965

View file

@ -0,0 +1,486 @@
01/01 Anniversary of the Triumph of the Revolution in Cuba
01/01 Castro expells Cuban President Batista, 1959
01/01 Churchill delivers his "Iron Curtain" speech, 1947
01/01 First Rose Bowl; Michigan 49 - Stanford 0, 1902
01/04 Quadrantid meteor shower (look north)
01/05 -50 degrees F, Strawberry UT, 1913
01/05 Fellowship enters Moria (LOTR)
01/05 The FCC hears the first demonstration of FM radio, 1940
01/05 Twelfth night
01/06 Millard Fillmore's birthday (let's party!)
01/08 Battle of New Orleans
01/09 Fellowship reaches Lorien (LOTR)
01/09 Plough Monday
01/10 First meeting of United Nations General Assembly in London, 1946
01/10 Thomas Paine's Common Sense published, 1776
01/11 Anniversary of the Peoples Republic of Albania
01/11 De Hostos' Birthday in Puerto Rico
01/11 Milk delivered in bottles for first time, 1878
01/11 Prithvi Jayanti in Nepal
01/11 Surgeon General condemned cigarettes, 1964
01/11 The Whiskey-A-Go-Go opens on Sunset Boulevard in Los Angeles, 1963
01/14 The first "Be-In" is held in Golden Gate Park, 1967
01/16 Prohibition begins, 1920
01/17 Passing of Gandalf (LOTR)
01/18 Grey whale migration, California
01/20 St. Agnes Eve (Ah, bitter chill it was...)
01/24 Eskimo Pie patented by Christian Nelson, 1922
01/24 Gold discovered in California at Sutter's Mill, 1848
01/26 Sydney Aust. settled, 1778
01/27 Grissom, White and Chaffe burned to death in Apollo 1, 1967
01/27 Vietnam War cease-fire signed, 1973
01/28 First ski tow, Woodstock VT, 1914
01/28 Space Shuttle Challenger (51-L) explodes 74 seconds after liftoff
killing Scobee, Smith, McNair, Resnick, Jarvis, Onizuka and McAuliffe,
1986
01/30 Mohandas Gandhi assassinated in New Delhi by Hindu fanatic, 1948
01/30 Tet Offensive, 1968
01/31 "Ham" the chimpanzee soars into space aboard Mercury-Redstone 2, 1961
01/31 Explorer I launched, 1958. Van Allen Belt discovered
01/31 Irving Langmuir, 1881, invented tungsten filament lamp
02/01 First TV soap: Secret Storm, 1954
02/01 Forces lead by Khomeini take over Iran, 1979
02/04 Cybernet inaugurated, 1969
02/04 Patricia Hearst kidnapped by Symbionese Liberation Army, 1974
02/07 Fellowship leaves Lorien (LOTR)
02/08 1963 Revolution Anniversary in Iraq
02/09 -51 degrees F, Vanderbilt MI, 1934
02/12 Lincoln's real birthday
02/12 Santa Barbara oil leak, 1969
02/14 Bombing of Dresden, 1945
02/15 Chicago Seven convicted, 1970
02/16 Nylon patented, 1937
02/16 Stephen Decatur burns US frigate in Tripoli, 1804
02/17 Death of Boromir (LOTR)
02/18 Pluto discovered by Clyde Tombaugh, Lowell Observatory, AZ, 1930
02/19 US Marines land on Iwo Jima, 1945
02/20 John Glenn orbits the Earth 3 times, 1962
02/20 Meriadoc & Pippin meet Treebeard (LOTR)
02/21 Battle of Verdun begins, 1916 1M casualties
02/21 First telephone directory, New Haven, Connecticut, 1878
02/21 Malcom X shot to death in Harlem, 1965
02/22 Passing of King Ellesar (LOTR)
02/23 Lt. Calley confesses, implicates Cpt. Medina, 1971
02/24 Ents destroy Isengard (LOTR)
02/24 Impeachment proceedings against Andrew Johnson begin, 1868
02/26 Aragorn takes the Paths of the Dead (LOTR)
02/27 The Lionheart crowned, 1189
02/28 The "French Connection" drug bust occurs in Marseilles, 1972
02/29 French and Indian raid on Deerfield MA, 1704
03/01 Sarah Goode, Sarah Osborne, and Tituba arrested for witchcraft
in Salem, Massachusetts, 1692
03/02 Blackthorn winds (New England) (Does anyone know what this is?)
03/04 First meeting of Congress, 1789, in N.Y.C.
03/05 Frodo & Samwise encounter Shelob (LOTR)
03/06 Hindenburg explodes and burns upon landing at Lakehurst, NJ, 1939
03/08 Deaths of Denethor & Theoden (LOTR)
03/13 "Striptease" introduced, Paris, 1894
03/14 Teddy Roosevelt excludes Japanese laborers from continental US, 1907
03/15 Buzzards return to Hinckley OH
03/15 France assumes protectorate over Vietnam, 1874
03/15 Watts, Los Angeles, riots kill two, injure 25, 1966
03/16 First liquid-fuel-powered rocket flight, 1926
03/16 MyLai Massacre; 300 non-combatant villagers killed by U.S. infantrymen
03/16 Robert Goddard launches first liquid-fueled rocket, Auburn MA, 1926
03/17 Vanguard I launched, 1958. Earth proved pear-shaped
03/18 Aleksei Leonov performs first spacewalk, 1965
03/18 Destruction of the Ring (LOTR)
03/19 Swallows return to Capistrano
03/20 Radio Caroline, the original British pirate radio station, sinks, 1980
03/24 Construction of New York subway system begins, 1900
03/25 Triangle Shirt Waist Fire, 1911
03/26 Popeye statue unveiled, Crystal City TX Spinach Festival, 1937
03/27 Khrushchev becomes Premier of Soviet Union, 1958
03/28 Three Mile Island releases radioactive gas, 1979
03/29 Flowering of the Mallorn (LOTR)
03/29 Swedish settled Christiana (Wilmington) DE, 1638
03/30 Alaska purchased from Russia for $7.2 million, 1867
03/30 Five rings around Uranus discovered, 1977
03/30 Pencil with eraser patented, 1858
04/01 People of superb intelligence, savoir-faire, etc. born this day.
04/04 Gandalf visits Bilbo (LOTR)
04/04 Martin Luther King assassinated in Memphis, Tennessee, 1968
04/04 NATO Established, 1949
04/06 Joseph Smith founds Mormon Church, 1830
04/07 Albert Hofmann synthesizes LSD in Switzerland, 1943
04/07 Alewives run, Cape Cod
04/09 Lee surrenders to Grant at Appomattox Courthouse, 1865
04/12 Columbia launched, 1981
04/12 Confederate troops fire first shots of Civil War at Ft Sumter, 1861
04/12 Space Shuttle Columbia launched, 1981
04/12 Yuri Gagarin becomes the first man in space, 1961
04/13 Laotian New Year (3 days) in Laos
04/14 Lincoln shot, 1865
04/14 Titanic hits iceberg and sinks, 1912
04/15 Ray Kroc opens first McDonalds in Des Plaines, IL, 1955
04/16 Lincoln shot in Ford's Theatre by John Wilkes Booth, 1865
04/17 An unexpected party (LOTR)
04/17 Bay of Pigs invasion crushed by Castro forces, 1961
04/18 Einstein's Death, 1955
04/18 First Laundromat opens, Fort Worth Texas, 1934
04/18 San Francisco earthquake, 1906
04/19 Landing of the "33" in Uruguay
04/19 Warsaw Ghetto uprising, 1943
04/20 Supreme Court unanimously rules in favor of busing, 1971
04/21 Lyrid meteor shower
04/23 Crowning of King Ellesar (LOTR)
04/23 Hank Aaron hits his first home run, 1954
04/26 William Shakespeare baptised in Stratford-on-Avon, England, 1564,
birthdate unknown
04/27 Magellan killed in Phillippines, 1521
04/29 Zipper patented by Gideon Sindback, 1913
05/01 Beltaine; Feast of the god Bel, sun god
05/03 Anti-war protest disrupts business in Washington, 1971
05/04 Four Kent State students are shot down by the National Guard, 1970
05/05 John Scopes arrested for teaching evolution, Dayton, TN, 1925
05/07 Germany surrenders after WWII, 1945
05/08 Beginning of ostrich mating season
05/08 US institutes mining of Haiphong Harbor, 1972
05/09 94 degrees, New York, 1979
05/10 Germany invades Low Countries, 1940
05/10 Nazi bookburning, 1933
05/14 Beginning of Lewis and Clark Expedition, 1804
05/14 Nation of Israel proclaimed, 1948
05/15 Asylum for Inebriates founded, Binghamton NY, 1854
05/17 24" rain in 11 hours, Pearl River, S. China, 1982
05/17 Six SLA members killed in televised gun fight, 1974
05/18 Battle of Las Piedras in Uruguay
05/18 Napoleon crowned Emperor, 1804
05/19 Arwen leaves Lorian to wed King Ellesar (LOTR)
05/21 Battle of Iquique in Chile
05/21 US explodes first hydrogen bomb, 1956
05/22 US Civil War ends, 1865
05/23 Israeli raid into Argentina to capture Adolf Eichmann, 1960
05/23 Two Yetis sighted, Mt. Everest, 1953
05/24 Battle of Pinchincha in Ecuador
05/25 Oral Roberts sees 900 foot tall Jesus Christ, Tulsa OK, 1980
05/25 Successful test of the limelight in Purfleet, England, 1830
05/26 Congress sets first immigration quotas, 1924
05/27 Golden Gate Bridge opens, 1937
05/29 Edmund Hillary and Tenzing Norkay climb Mt. Everest, 1953
05/29 First food stamps issued, 1961
05/30 US Marines sent to Nicaragua, 1912
06/02 Native Americans "granted" citizenship, 1924
06/04 Roquefort cheese developed, 1070
06/05 Robert Kennedy assasinated, 1968
06/05 US leaves the Gold Standard, 1933
06/06 First drive-in movie, 1933
06/06 Normandy landing, 1944
06/10 Death of Alexander the Great, 323 B.C.
06/10 Denver police tear gas Jethro Tull and 2000 fans at Red Rocks, 1971
06/11 Greeks seize Troy, 1184BC
06/11 Sauron attacks Osgilliath (LOTR)
06/13 Bilbo returns to Bag End (LOTR)
06/13 Pioneer flies past Neptune, and therefore out of the Solar System
06/14 Sandpaper invented by I. Fischer, Jr., 1834
06/15 Ben Franklin's kite experiment, 1752
06/15 Magna Carta signed, 1215
06/15 Series of photographs by Edward Muggeridge prove to Leland Stanford
that all the hooves of a horse are off the ground during the gallop,
1878
06/16 "The Blues Brothers" premieres in Chicago, 1980
06/17 China explodes its first Hydrogen bomb, 1967
06/17 Watergate Democratic National Committee break-in, 1972
06/19 Julius and Ethel Rosenberg are executed in Sing-Sing prison, 1953
06/19 Lizzie Bordon acquitted, 1893
06/20 Victoria crowned, 1837
06/21 Berlin airlift begins, 1948
06/21 Sun rises over Heelstone at Stonehenge
06/22 Civil rights workers disappear in Mississippi, 1964
06/23 Slavery abolished in England, 1772
06/23 Wedding of Ellesar & Arwen (LOTR)
06/24 Senate repeals Gulf of Tonkin resolution, 1970
06/25 Custer's Last Stand at Little Big Horn, 1876
06/25 North Korea invades South Korea, 1950
06/26 Battle of Gettysburg, 1863
06/26 St. Lawrence Seaway dedicated by Eisenhower & Queen Elizabeth II, 1959
06/26 Toothbrush invented, 1498
06/27 100 degrees, Fort Yukon, 1915
06/27 Bill Graham closes the Fillmore East, 1971
06/28 Supreme Court decides in favor of Alan Bakke, 1978
06/30 "That" explosion in Siberia, 1908
06/30 China and Soviet Union announce split over ideology, 1960
07/01 Battle of Gettysburg begins, 1863
07/03 Dog days begin
07/04 Battles of Vicksburg and Gettysburg won by Union forces, 1863
07/04 Cloudy, 76 degrees, Philadelphia PA, 1776
07/04 Gandalf imprisoned by Saruman (LOTR)
07/04 New York abstains on Declaration of Independence vote, 1776
07/04 Thoreau enters woods, 1845
07/06 First `talkie' (talking motion picture) premiere in New York, 1928
07/06 Lawrence of Arabia captures Aqaba, 1917
07/07 First radio broadcast of "Dragnet", 1949
07/08 First public reading of the Declaration of Independence, 1776
07/08 Liberty Bell cracks while being rung at funeral of John Marshall, 1835
07/09 10-hour working day set by law, NH, 1847
07/10 134 degrees in Death Valley, 1913
07/12 Minimum wages established: 40 cents/hour, 1933
07/13 Women first compete in Olympic games, 1908
07/16 Detonation of the first atomic bomb at Alamagordo, NM, 1945
07/17 Disneyland opens, 1955
07/18 Ty Cobb gets 4000th base hit, 1927
07/19 Five Massachusetts women executed for witchcraft, 1692
07/20 Armstrong and Aldrin land on moon, 1969
07/21 First Train Robbery, Jesse James gets $3000 near Adair, Iowa, 1873
07/21 Vietnam divided at 17th parallel, 1954
07/23 Ice cream cone introduced, St. Louis MO, 1904
07/24 Scopes Monkey Trial, 1925
07/24 The ring comes to Bilbo (LOTR)
07/26 Bilbo rescued from Wargs by Eagles (LOTR)
07/30 "In God We Trust" made U.S. motto, 1956
07/31 Harry S. Truman dedicates N.Y. Int'l Airport @ Idlewild Field, 1948,
later JFK
08/01 Lughnasa; Feast of the god Lugh, a 30 day Celtic feast centers on
this day
08/03 Columbus sets sail for Cathay, 1492
08/03 Funeral of King Theoden (LOTR)
08/03 USS Nautilus crosses under north polar ice cap, 1958
08/04 Axe murder of Andrew and Abbey Borden, 1892
08/04 Bombing of N. Vietnam begins, 1964
08/04 Britain declares war on Germany starting World War I, 1914
08/06 Atomic bomb dropped on Hiroshima, 1945
08/06 Caricom in Barbados
08/06 Cy Young pitches first game, 1890
08/08 Atomic bomb dropped on Nagasaki, 1945
08/08 Montenegro declares war on Germany, 1914
08/08 Richard Nixon resigns the US presidency, 1974
08/08 The Great Train Robbery -- $7,368,000, 1963
08/09 Helter Skelter... the Charles Manson murders take place, 1969
08/09 Persia defeats Spartan King Leonidas at Thermopylae, 480 BC
08/09 US/Canada border defined in the Webster-Ashburton Treaty, 1842
08/10 Chicago incorporated as a village of 300 people, 1833
08/10 US and Panama agree to transfer the canal in the year 2000, 1977
08/11 Dog days end
08/11 France Ends War in Indochina, 1954
08/11 Perseid meteor shower (look north; three days)
08/12 First test flight of Space Shuttle "Enterprise" from 747, 1977
08/12 Last U.S. ground troops out of Vietnam, 1972
08/13 Berlin wall erected, 1961
08/13 Li'l Abner debut, 1934
08/14 Social Security begins in U.S., 1935
08/15 Gandhi's movement obtains independence for Pakistan and India, 1947
08/15 Hurricane hits Plimoth Plantation, 1635
08/16 Roller Coaster patented, 1898
08/17 First public bath opened in N.Y., 1891
08/18 Anti-Cigarette League of America formed
08/19 Air Force cargo plane snares payload from Discoverer 14 spy satellite,
marking start of practical military reconnaissance from space, 1960
08/19 Gail Borden patents condensed milk, 1856
08/22 Death of King Richard III, 1485, Last of the Plantagenets
08/22 Joe Walker sets X-15 all time altitude mark (67 miles), 1963
08/22 St. Columbia reports seeing monster in Loch Ness, 565
08/23 Sacco and Vanzetti executed, 1927
08/24 "Alice's Restaurant" premieres in New York and Los Angeles, 1969
08/24 -126.9 F at Vostok, Antarctica, 1960
08/24 British troops burn Washington, 1814
08/25 Gen. DeGaulle leads French forces into Paris, 1944
08/26 Women get the vote, 1920
08/27 "Tarzan of the Apes" published, 1912
08/27 Krakatoa, Java explodes with a force of 1,300 megatons, 1883
08/28 King leads over 200K in civil rights rally in Washington, DC, 1963
08/29 Star in Cygnus goes nova and becomes 4th brightest in sky, 1975;
Nova Cygni 1975.
08/29 Saruman enters the Shire (LOTR)
08/30 75 cents a pound tariff set on opium, 1842
08/30 Japan Stationery Co. sells first felt-tipped pen, 1960
08/30 St. Rose of Lima in Peru
08/30 Washington-to-Moscow hot line connected, 1963
08/31 269 people killed after Korean Airlines 747 shot down by USSR, 1983
08/31 Mary Anne Nichols becomes Jack the Ripper's first victim, 1888
08/31 Non-aggression pact signed by USSR and Afghanistan, 1926
09/01 Bobby Fischer defeats Boris Spassky in World Chess Match, 1972
09/01 Joshua A. Norton proclaims himself 'Emperor Norton I', 1859
09/02 Great Britain adopts Gregorian Calendar, 1752
09/02 Japan signs unconditional surrender on US battleship `Missouri', 1945
09/03 Anniversary of the Founding of the Republic in San Marino
09/05 Kennedy orders resumption of underground nuclear tests, 1961
09/05 The first Continental Congress was convened in Philadelphia, 1774
09/06 149 Pilgrims set forth from England aboard the Mayflower, 1620
09/06 First Star Trek episode (The Man Trap) aired 1966
09/06 Pres. McKinley shot, 1901
09/06 Somhlolo in Swaziland
09/08 "Star Trek" debuts on NBC (1966)
09/08 Jack the Ripper kills again, Annie Chapman is second victim, 1888
09/08 President Ford pardons Richard M. Nixon, 1974
09/09 California becomes the 31st state, 1850
09/09 United Colonies is renamed the United States, 1776
09/10 Gandalf escapes from Orthanc (LOTR)
09/10 Mountain Meadows Massacre. Mormons kill Gentile wagon train, 1857
09/12 German paratroopers rescue Mussolini from captivity in Rome, 1943
09/12 Germany annexes Sudentenland, 1938
09/13 136.4 F at el Azizia, Libya, 1922
09/13 British defeat the French at Abraham near Quebec City, 1788
09/13 Building of Hadrian's Wall begun, 122
09/13 Chiang Kai-Shek becomes president of China, 1943
09/14 Benjamin Franklin is sent to France as an American minister, 1778
09/14 Frodo & Bilbo's birthday (LOTR)
09/14 Salem, Massachusetts, is founded, 1629
09/14 The Selective Service Act establishes the first peacetime draft, 1940
09/15 Black riders enter the Shire (LOTR)
09/15 Soviet Premier Nikita Khrushchev begins his 13 day tour of the US, 1959
09/15 The U.S. Foreign Affairs Dept. becomes the U.S. State Department, 1789
09/16 The village of Shawmut, Massachusetts, becomes the city of Boston, 1630
09/17 Battle of Antietam, 1862
09/18 Frodo and company rescued by Bombadil (LOTR)
09/18 Victory of Uprona in Burundi
09/20 Equal Rights Party nominates Belva Lockwood for President, 1884
09/20 First meeting of the American Association for the Advancement of
Science, 1848
09/20 First meeting of the National Research Council, 1916
09/20 Magellan leaves Spain on the first Round the World passage, 1519
09/20 The Roxy Theater opens in Hollywood, 1973
09/22 Allied forces form the independent nation West Germany, 1953
09/22 President Lincoln issues the Emancipation Proclamation, 1862
09/22 Special prosecutor Leon Jeworski subpoenaes President Nixon, 1974
09/22 The first Soviet atomic bomb explodes, 1949
09/23 Phillippine President Ferdinand Marcos declares martial law, 1972
09/23 The New York Knickerbockers becomes the first U.S. Baseball club, 1845
09/23 V.P. Nixon denies campaign fund fraud with his "Checkers" speech, 1952
09/25 Sandra Day O'Connor becomes first woman on US Supreme Court, 1981
09/27 The first passenger was hauled in a locomotive in England, 1825
09/28 "Pilgrim's Progress" published, 1678
09/28 A Greek soldier runs 26+ miles after the Persian defeat at Marathon,
490BC
09/28 Frodo wounded at Weathertop (LOTR)
09/30 Red Jack kills 2, Elizabeth Stride (#3) and Catherine Eddowes (#4),
1888
09/30 The first tooth is extracted under anesthesia in Charleston, Mass, 1846
09/30 The verdicts of the Nuremberg trials are announced, 1946
10/01 NASA officially begins operations, 1958
10/02 Thurgood Marshall sworn as the first black Supreme Court Justice, 1967
10/04 Crimean war begins, 1853
10/04 First space vehicle, Sputnik I, launched, 1957
10/04 Sputnik 1, world's first orbiting satellite launched, 1957
10/05 Frodo crosses bridge of Mitheithel
10/06 Antioch College is the first public school to admit men and women, 1853
10/06 Egyptian President Anwar Sadat is assassinated in Cairo, 1981
10/06 Israel is attacked by the alliance of Egypt and Syria, 1973
10/07 Foundation of the GDR in 1949 in German Democratic Republic
10/07 Georgia Tech. beats Cumberland Univ. 222-0, 1916
10/07 Maryland Governor Marvin Mandel sent to prison on fraud charges, 1977
10/07 Mother Teresa of Calcutta awarded the Nobel Peace Prize, 1979
10/07 Police stop Wilbur Mills car, Fanne Fox jumps into water, 1974
10/08 Great Chicago Fire, 1871
10/09 First two-way telephone conversation, 1876
10/10 Beginning of the Wars for Independence in Cuba
10/10 Foundation of the Workers Party in North Korea
10/10 Mercury at Superior Conjunction with Sun. Moves into night sky. (1984)
10/10 Spiro T. Agnew resigns as Vice-President due to income tax fraud, 1973
10/11 "Saturday Night Live" premiers on NBC-TV, 1975
10/11 The Gang of Four are arrested in Peking, 1976
10/11 The first steam powered ferry ran between New York and Hoboken, 1811
10/11 The second Vatican Ecumenical Council opens in Rome, 1962
10/11 First broadcast of Saturday Night Live, 1975
10/12 Bahama Natives discover Columbus of Europe lost on their shores, 1492
10/12 Khrushchev pounds his desk with shoe during a speech to the UN, 1960
10/12 Man O'War's last race, 1920
10/12 Native Americans discover Columbus of Europe lost on their shores, 1492
10/13 Italy declares war on Germany, 1943
10/13 U.S. Navy born, 1775, authorized by the Second Continental Congress
10/14 Battle of Hastings won by William the Conqueror and the Normans, 1066
10/14 Chuck Yeager breaks sound barrier, 1947
10/15 First draft card burned, 1965
10/16 Boromir reaches Rivendell (LOTR)
10/17 Council of Elrond (LOTR)
10/18 Boston Shoemakers form first U.S. labor org., 1648
10/18 Soviets anounce their probe took photos of the Moon's far side, 1959
10/19 Mao Tse-tung establishes the People's Republic of China, 1949
10/19 Napoleon's beaten army begins the long retreat from Moscow, 1812
10/20 "Saturday Night Massacre", 1973
10/20 OPEC embargo, 1973
10/21 Edison makes the first practical incandescent lamp, 1879
10/21 Guggenheim Museum opens, 1959
10/23 Battle of Leyte Gulf begins, 1944
10/23 Earth created at 6:30 AM, 4004BC.
10/23 Swallows leave Capistrano
10/25 End of War of the Ring (LOTR)
10/25 The UN removes Taiwan and admits the People's Republic of China, 1971
10/26 UN's World Health Organization declares smallpox eradicated, 1978
10/27 New York's Boss Tweed is arrested on fraud charges, 1871
10/27 The first New York Subway is opened, 1904
10/28 Columbus discovers Cuba, 1492
10/28 Constantine's army defeats forces of Maxentius at Mulvian Bridge, 312
10/28 Harvard was founded in Massachusetts, 1636
10/28 Statue of Liberty was dedicated on Bedloe's Island, 1886
10/29 Stock Market Crash, 1929
10/30 Orson Welles' "War of the Worlds" broadcast, 1938
10/31 Luther nails 95 Theses to door of Castle Church, Wittenberg, 1517
11/01 Austria-Hungary become two seperate nations, 1918
11/01 Puerto Rican nationalists try to kill Truman at the Blair House, 1950
11/02 Luftwaffe completes 57 consecutive nights of bombing of London, 1940
11/02 Two Frenchmen make the first free hot air balloon flight, 1783
11/03 Beef rises to 3 cents a pound, IL, 1837
11/03 Linus Pauling wins Nobel Chemistry Prize, 1954
11/03 Sputnik II launched, 1957, bearing spacedog Laika
11/04 Iranian militants seize US embassy personnel in Teheran, 1979
11/04 Soviet forces crush the anti-communist revolt in Hungary, 1956
11/05 Guy Fawkes' Plot, 1605
11/06 Anniversary of the October Socialist Revolution (2 days) in U.S.S.R.
11/07 Abolitionist newspaperman Elijah P. Lovejoy murdered by mob, 1837
11/07 Lewis and Clark Expedition in sight of the Pacific Ocean, 1805
11/09 Blackout of New York, New England, and Eastern Canada, 1965
11/09 Giant panda discovered (?!), China, 1927
11/09 Jack the Ripper kills fifth and final victim, Jane Kelly, 1888
11/09 Margaret Sanger forms American Birth Control League, 1921
11/09 Roosevelt establishes the Civil Works Administration, 1933
11/10 41 Women arrested in suffragette demonstartions near White House, 1917
11/10 Cpt. Wirz, commandant of Andersonville Prison hanged, 1865
11/10 Henry Stanley asks David Livingston, "Dr. Livingston, I presume?", 1871
11/11 Washington becomes the 42nd state, 1889
11/12 Dr. Sun Yat-sen's Birthday in Taiwan
11/12 U.S. first exports oil to Europe, 1861
11/14 Quarter Pounder price raised from $0.53 to $0.55 in violation of Nixon
price controls (but okayed by Price Commission after formal request
from McDonald's), 1971
11/15 Niagara Falls power plant startup, 1896
11/16 Bilbo reaches the Lonely Mountain (LOTR)
11/16 Opening of the Suez Canal, 1869
11/17 46,000 meteoroids fall over AZ in 20 minutes, 1966
11/17 Richard Nixon says "I am not a crook.", 1973
11/18 First hydrogen bomb blasts Enewetok, 1952
11/18 Local standard time zones established for US, 1883
11/19 Gettysburg Address delivered, 1863
11/21 Announcement of 18 1/2 minute gap on Watergate tape, 1973
11/22 Kennedy shot in Dallas, Texas by Lee Harvey Oswald, 1963
11/23 First broadcast of Dr. Who (longest running TV series), 1963
11/24 Lee Harvey Oswald killed by Jack Ruby, 1963
11/25 Alfred Nobel invents dynamite, 1867
11/27 Alfred Nobel establishes Nobel Prize, 1895
11/27 Friction match invented, England, 1826
11/27 Hoosac Railroad Tunnel completed, 1873, in NW Massachusetts
11/29 King Tut's tomb opened, 1922
12/01 First national corn-husking championship, Alleman IA, 1924
12/01 Martin Luther King Jr., leads black boycott of Montgomery buses, 1955
12/01 Rosa Parks refuses to move to back of the bus (Montgomery, AL), 1953
12/03 First neon light display, Paris, 1910
12/03 First successful human heart transplant lead by Dr. Barnard, 1967
12/03 The Montreux Casino burns down during a Frank Zappa concert, 1971
12/04 Washington takes leave of his officers at Fraunce's Tavern, NYC, 1783
12/05 Death of Smaug (LOTR)
12/05 End of Prohibition, 1933 (at least the alcohol part)
12/05 Phi Beta Kappa founded, 1776
12/05 The Eighteenth Amendment repealed, ending Prohibition, 1933
12/07 Japan bombs Pearl Harbor, 1941
12/09 Ball-bearing roller skates patented, 1884
12/10 Metric system established in France, 1799
12/10 Nobel Peace Prize awarded each year
12/12 First wireless message sent across Atlantic by Marconi, 1901
12/13 Apollo 17 leaves the moon, with "last" men to walk on moon aboard, 1972
12/13 Dartmouth College chartered, 1769
12/13 Geminid meteor shower (look south)
12/15 Argo Merchant oil spill, 1976
12/15 Bill of Rights adopted, 1791
12/15 James Naismith invents basketball, Canada, 1891
12/15 Sitting Bull shot in head while submitting to arrest, 1890
12/16 Fellowship begins Quest (LOTR)
12/20 U.S. buys ~1,000,000 sq. miles of Louisiana for ~$20/sq.mi.
12/21 Phileas Fogg completes his trip around the world in less than 80 days
12/24 KKK formed in Pulaski, Tenn, 1865
12/26 DPMA founded, 1951
12/27 APT report published, 1956
12/27 Ether first used as anesthetic in childbirth, 1845
12/28 Comet Kohoutek at perihelion, 1973
12/29 Battle of Wounded knee, 1890
12/30 First Los Angeles freeway dedicated, 1940
12/31 St. Sylvester in Switzerland
12/31 Winterland closes its doors, 1978

View file

@ -0,0 +1,568 @@
01/01 Independence Day in Haiti, Sudan
01/01 Universal Fraternity Day in Mozambique
01/02 Ancestry Day in Haiti
01/02 St. Berchtold's Day in Switzerland
01/03 New Year's Holiday in Scotland
01/03 Revolution Day in Upper Volta
01/04 Independence Day in Burma
01/04 Martyrs Day in Zaire
01/06 Children's Day in Uruguay
01/06 Three Kings' Day in Puerto Rico
01/07 Christmas in Ethiopia
01/07 Pioneer's Day in Liberia
01/09 Day of the Martyrs in Panama
01/11 Armed Forces Day in Liberia
01/12 Zanzibar Revolution Day in Tanzania
01/13 National Liberation Day in Togo
01/15 Adults Day in Japan
01/15 Arbor Day in Jordan
01/16 Martyrs Day in Benin
01/18 Revolution Day in Tunisia
01/19 Confederate Heroes Day in Texas
01/19 Ethopian Epiphany in Ethiopia
01/19 Nameday of Archbishop Makarios in Cyprus
01/20 Army Day in Mali
01/20 National Heroes Day in Guinea-Bissau
01/20* Lee-Jackson Day in Virginia (3rd Monday)
01/20* Martin Luther King Day in New York (3rd Sunday)
01/20* Robert E. Lee's Birthday in Alabama & Mississippi (3rd Monday)
01/21 Our Lady of Altagracia in Dominican Republic
01/21* Lee-Jackson Day in Virginia (3rd Monday)
01/23 Feast of St. Ildefonsus
01/23 National Handwriting Day
01/24 Economic Liberation Day in Togo
01/26 Republic Day in India
01/30 Australia Day in Australia
02/01 Chinese New Year Holiday (3 days) in Taiwan
02/02 Candlemas
02/04 Independence Commemoration Day in Sri Lanka
02/05 Constitution Day in Mexico
02/06 New Zealand Day
02/07 Independence Day in Grenada
02/09 St. Maron's Day in Lebanon
02/10 Feast of St. Paul's Shipwreck, AD 60
02/11 National Foundation Day in Japan
02/12 Pyidaungsa Day in Burma
02/16 Makha Bucha Day in Thailand
02/18 Democracy Day in Nepal
02/18 Independence Day in The Gambia
02/23 Republic Day in Guyana
02/24 Gregorian Calendar Day
02/25 National Day in Kuwait
02/27 Independence Day in Dominican Republic
03/01 Samil Independence Movement Day in South Korea
03/01 St. David's Day, Cardiff
03/02 Peasants Day in Burma
03/02 Texas Independence day
03/02 Victory of Adowa in Ethiopia
03/03 Girl's Day in Japan
03/03 Throne Day in Morocco
03/04 Vermont Admission Day (admitted as 14th state in 1791)
03/05 Independence Day in Equatorial Guinea
03/06 Lantern Day, Bejing
03/07* Purim - Feast of Lots
03/08 First Annual International Women's Day, 1909
03/08 International Women's Day in U.S.S.R.
03/08 Syrian National Day in Libyan Arab Republic
03/08 Women's Day in Guinea-Bissau, Taiwan, Yemen Democratic Republic
03/08 Youth Day in Zambia
03/09 Decoration Day in Liberia
03/09 Falgun Purnima Day in Nepal
03/10 Labor Day in South Korea
03/11 Johnny Appleseed Day; anniversary of the death of John Chapman
03/12 Commonwealth Day in Swaziland
03/12 Independence Day in Mauritius
03/12 Moshoeshoe's Birthday in Lesotho
03/12 Renovation Day in Gabon
03/13 National Day in Grenada
03/16 Black Press Day; first Black newspaper founded in 1827
03/17 Evacuation Day in Suffolk County, Massachusetts
03/17 St. Patrick's Day
03/19 St. Joseph's Day in Colombia, Costa Rica, Holy See, Liechtenstein,
San Marino, Spain, Venezuela
03/19 Tree Planting Day in Lestho
03/20 Independence Day in Tunsia
03/20 Youth Day in Oklahoma
03/21 Afghan New Year in Afghanistan
03/21 Juarez' Birthday in Mexico
03/22 Abolition Day in Puerto Rico
03/23 Pakistan Day in Pakistan
03/25 Greek Independence Day in Cyprus
03/25 Lady Day (a.k.a. the Feast of the Annunciation)
03/25 Maryland Day in Maryland
03/25 National Holiday in Greece
03/25* Seward's Day in Alaska (last Monday)
03/26 Independence Day in Bangladesh
03/26 Prince Jonah Kuhio Kalanianaole Day in Hawaii
03/27 Armed Forces Day in Burma
03/29 Death of President Barthelemy Boganda in Central African Republic
03/29 Memorial Day in Madagascar
03/31 National Day in Malta
04/01 Youth Day in Benin
04/02 Malvinas Day in Argentina
04/02 Pascua Florida Day in Florida
04/04 Ching Ming Festival in Hong Kong
04/04 Liberation Day in Hungary
04/04 National Day in Senegal
04/05 Arbor Day in South Korea
04/05 Tomb Sweeping Day in Taiwan
04/06 Chakri Memorial Day in Thailand
04/06 Victory Day in Ethiopia
04/08 Fast and Prayer Day in Liberia
04/09 Martyrs Day in Tunisia
04/11 National Heroes Day in Costa Rica
04/13 National Day in Chad
04/13 Songkron Day in Thailand
04/14 Day of the Americas in Honduras
04/15 Bengali New Year in Bangladesh
04/15* Patriot's Day in Maine & Massachusetts (3rd Monday)
04/16 De Diego's Birthday (celebrated in Puerto Rico)
04/16 Holy Week (5 days) in Venezuela
04/16 Tourist Week (5 days) in Uruguay
04/17 Burmese New Year in Burma
04/18 Independence Day in Chile, Zimbabwe
04/19 Declaration of Independence in Venezuela
04/19 Republic Day in Sierra Leone
04/21 San Jacinto Day in Texas
04/22 Arbor Day in Nebraska & Delaware
04/22 Oklahoma Day in Oklahoma
04/24 Victory Day in Togo
04/24* Pesach - First Day of Passover - Festival of Freedom
04/25 Anzac Day in Australia, New Zealand, Tonga, Western Samoa
04/25 Liberation Day in Italy
04/25 National Flag Day in Swaziland
04/26 Confederate Memorial Day in Florida & Georgia
04/26 Union Day in Tanzania
04/27 Independence Day in Togo
04/28* Arbor Day in Wyoming (last Monday)
04/28* Confederate Memorial Day in Alabama & Mississippi (last Monday)
04/30 The Workers Day in Uruguay
05/01 Labor Day in many places
05/01 Law Day (decl. by Eisenhower)
05/01 May Day in many places
05/02 Constitution Day in Japan
05/04 Rhode Island Independence Day
05/05 Children's Day in Japan, South Korea
05/05 Coronation Day in Thailand
05/05 Liberation Day in Netherlands
05/06 Bataan Day in Philippines
05/06* Bank Holiday in UK
05/07 May Day in United Kingdom
05/08 Truman Day in Missouri
05/09 Liberation Day in Czechoslovakia
05/09 Victory Day in Poland, U.S.S.R.
05/10 Confederate Memorial Day in South Carolina
05/10 Mothers Day in Guatamala
05/11 Minnesota Day in Minnesota
05/14 Buddhist Holiday (Waisak 2528) in Indonesia
05/14 Independence Day (2 days) in Paraguay
05/14 Unification Day in Liberia
05/15 Kamuzu Day in Malawi
05/15 Vesak Day in Singapore, Malaysia
05/15 Visakha Bucha Day in Thailand
05/16 Discovery Day in Cayman Islands
05/17 Constitution Day in Nauru, Norway
05/18 Flag Day in Haiti
05/18 Prayer Day in Denmark
05/19 Youth and Sports Day in Turkey
05/19* Memorial Day in Michigan (3rd Monday)
05/20 Mecklenburg Independence Day in North Carolina
05/20 National Day in Cameroon
05/20 Victoria Day in Canada
05/20* Memorial Day in Michigan (3rd Monday)
05/22 National Heroes Day in Sri Lanka
05/23 Commonwealth Day in Jamaica, Belize
05/23 National Labor Day in Jamaica
05/24 Bermuda Day in Bermuda
05/24 Day of Slav Letters in Bulgaria
05/25 African Freedom Day in Zimbabwe
05/25 African Liberation Day in Chad, Mauritania, Zambia
05/25 Independence Day in Jordan
05/25 Memorial Day in New Mexico & Puerto Rico
05/26* First Day of Shavuot
05/27* Bank Holiday in UK
05/28 Mothers Day in Central African Republic
05/31 Pya Martyrs Day in Togo
05/31 Republic Day in South Africa
06/01 Independence Days (3 days) in Western Samoa
06/01 Madaraka Day in Kenya
06/01 Victory Day in Tunisia
06/03 Confederate Memorial Day in Kentucky & Louisiana
06/03 Labor Day in Bahamas
06/03* Bank Holiday in Rep. of Ireland
06/04 Emancipation Day in Tonga
06/05 Constitution Day in Denmark
06/05 Liberation Day in Seychelles
06/06 Memorial Day in South Korea
06/09 Senior Citizen's Day in Oklahoma
06/10 Camoes Day in Portugal
06/11 King Kamehameha I Day in Hawaii
06/12 Independence Day in Philippines
06/14 Flag Day
06/17 Bunker Hill Day in Suffolk County, Massachusetts
06/17 Independence Day in Iceland
06/17 National Day in Federal Republic of Germany
06/18 Evacuation Day in Egypt
06/19 Emancipation Day in Texas
06/19 Labor Day in Trinidad, Tobago
06/19 Revolution Day in Algeria
06/20 Flag Day in Argentina
06/20 West Virginia Day in West Virginia
06/22 National Sovereignty Day in Haiti
06/23 National Holiday in Luxembourg
06/24 Fisherman's Day in Madagascar, Mozambique, Somalia
06/24 Kings Day in Spain
06/24 Peasants Day in Peru
06/24 St. Jean-Baptiste Day in Quebec
06/28 Mothers Day in Central African Republic
06/29 Independence Day in Seychelles
06/29 Last Day of Ramadan* in Algeria, Oman
06/30 Day of the Army in Guatemala
07/01 Dominion Day in Canada
07/01 Freedom Day in Suriname
07/01 Independence Day in Burundi
07/01 National Day in Rwamda
07/01 Republic Day in Ghana
07/02 National Day in Kiribati
07/04 Caribbean Day in Guyana
07/04 Constitution Day in Cayman Islands
07/04 Family Day in Lesotho
07/04 Heroes Day in Zambia
07/04 Kadooment Day in Barbados
07/04 Philippine-American Friendship Day in the Philippines
07/04 Warriors Day (2 days) in Yugoslavia
07/05 Day of Peace and Unity in Rwanda
07/05 Independence Day in Algeria, Venezuela
07/07 National Day in Malawi
07/07 Saba Saba Day in Tanzania
07/09 Independence Day in Argentina
07/10 Independence Day in Bahamas
07/11 National Holiday in the Mongolian People's Republic
07/14 Bastille Day
07/14 National Holiday in Monaco
07/15 St. Swithin's Day
07/16 Presidents Day in Botswanna
07/17 Constitution Day in South Korea
07/17 Public Holiday in Botswanna
07/18 Constitution Day in Uruguay
07/18 Liberation Day in Nicaragua
07/19 Martyrs Day in Burma
07/20 Independence Day in Colombia
07/21 National Holiday in Belgium
07/22 National Day in Poland
07/23 Eqyptian National Day in Syrian Arab Republic
07/23 Remembrance Day in Papua, New Guinea
07/24 Pioneer Day in Utah
07/24 Simon Bolivar's Day in Ecuador, Venezuela
07/25 Constitution Day in Puerto Rico
07/25 National Rebellion Day (3 days) in Cuba
07/25 Republic Day in Tunisia
07/26 Independence Day in Liberia
07/26 National Day in Maldives
07/28 Independence Days (2 days) in Peru
07/29 Rain Day in Waynesburg, PA
07/31 Revolution Day in Congo
08/01 Discovery Day in Trinidad, Tobogo
08/01 Emancipation Day in Granada
08/01 Freedom Day in Guyana
08/01 National Day in Switzerland
08/01 National Holidays (5 days) in El Salvador
08/01 Parent's Day in Zaire
08/03 Independence Day in Jamaica, Niger
08/03 Memorial Day of Archbishop Makarios in Cyprus
08/04 Freedom Day in Guyana
08/05* Bank Holiday in Scotland and Northern Ireland
08/06 Bank Holiday in Australia, British Columbia, Fiji, Iceland, Ireland,
Ontario
08/06 Emancipation Day in Bahamas
08/06 Independence Day in Bolivia
08/09 National Day in Singapore
08/10 Independence Day in Ecuador
08/11 Heroes Day (2 days) in Zimbabwe
08/11 Independence Day in Chad
08/13 Women's Day in Tunisia
08/14 Independence Day in Pakistan
08/14 VJ Day, 1945
08/15 Independence Day in India
08/15 Liberation Day in South Korea
08/15 National Day in Congo
08/15* Admission Day in Hawaii, 1984 (3rd Friday)
08/16 Bennington Battle Day in Vermont
08/16 Independence Days (3 days) in Gabon
08/16 Restoration Day in Dominican Republic
08/17 Independence Day in Indonesia
08/19 Independence Day in Afghanistan
08/20 Constitution Day in Hungary
08/23 Liberation Days (2 days) in Romania
08/24 National Flag Day in Liberia
08/25 Constitution Day in Paragual
08/25 Independence Day in Uruguay
08/26 Susan B. Anthony Day in Massachussetts
08/26* Bank Holiday in England and Wales
08/27 Liberation Day in Hong Kong
08/28 Heroes Day in Philippines
08/30 Huey P. Long Day in Louisiana
08/30 Victory Day in Turkey
08/31 Independence Day in Trinidad, Tobago
08/31 National Day in Malaysia
08/31 Pashtoonian Day in Afghanistan
09/01 Army Day in Chile
09/03 Independence Day in Qatar
09/03 Memorial Day in Tunisia
09/06 Defense of Pakistan Day in Pakistan
09/06 Settlers Day in South Africa
09/07 Independence Day in Brazil
09/09 Admission Day in California
09/09 National Day in North Korea
09/10 Korean Thanksgiving Day (Chusuk) in South Korea
09/10 National Day in Belize
09/11 National Holiday in Chile
09/12 Defender's Day in Maryland
09/12 Revolution Day in Ethiopia
09/13 Barry Day commemorates the death of Commodore John Barry
09/15 Respect for the Aged Day in Japan
09/16 Cherokee Strip Day in Oklahoma
09/16 Independence Day in Mexico, Papua, New Guinea
09/17 National Heroes Day in Angola
09/18 Independence Day in Chile, Zimbabwe
09/19 Army Day in Chile
09/21 Independence Day in Belize
09/22 Independence Day in Mali
09/22 National Sovereignty Day in Haiti
09/24 Independence Day in Guinea-Bissau
09/24 National Day in Saudi Arabia
09/24 Republic Day in Trinidad, Tobago
09/25 Army Day in Mozambique
09/25 Referendum Day in Rwanda
09/26 National Day in Maldives, Yemem Deomcratic Republic
09/26 Revoluation Anniversary Day in Yemen Arab
09/28 Confucious' Day in Taiwan
09/30 Botswanna Day in Botswanna
09/30 First Day of Sukkot
10/01 Armed Forces Day in South Korea
10/01 Independence Day in Nigeria
10/01 Labor Day in Australia
10/01 National Liberation Day (2 days) in China
10/01 Public Holiday in Botswanna
10/03 National Foundation Day in South Korea
10/03 U.N. Day in Varbados
10/04 Independence Day in Lesotho
10/06 National Sports Day in Lesotho
10/07 National Heroes Day in Jamaica
10/08 Constitution Day in U.S.S.R
10/08 Fiji Day in Fiji
10/08 Thanksgiving Day in Canada
10/09 Independence Day in Uganda
10/09 Korean Alphabet Day in South Korea
10/09 Leif Erikson Day commemorates the discovery of North America in AD 1000
10/09 Republic Day in Khmer Republic
10/10 Fiji Day in Fiji
10/10 Health-Sports Day in Japan
10/10 National Day in Taiwan
10/10 Oklahoma Historical Day in Oklahoma
10/11 Day of the Revolution in Panama
10/11 Druger Day in South Africa
10/12 Day of the Race in Argentina
10/12 Discovery Day in Gahamas
10/12 National Day in Equatorial Guinea, Spain
10/12 Our Lady Aparecida Day in Brazil
10/12 Pan American Day in Belize
10/13 St. Edward's Day - Patron saint of England
10/14 National Day in Yemen Arab Repyblic
10/14 Young People's Day in Zaire
10/14* Thanksgiving Day in Canada
10/15 Evacuation Day in Tunisia
10/16 National Boss Day
10/17 Heroes Day in Jamaica
10/17 Mother's Day in Malawi
10/20 Kenyatta Day in Kenya
10/21 Armed Forces Day in Honduras
10/21 Revolution Days (2 days) in Somalia
10/23 Chulalongkron's Day in Thsailand
10/24 Independence Day in Zambia
10/24 United Nations Day
10/25 Labor Day in New Zealand
10/25 Taiwan Restoration Day in Taiwan
10/26 Agam Day in Nauru
10/26 Armed Forces Day in Benin, Rwanda
10/26 National Day in Austria
10/28 National Holiday in Greece
10/28 OHI Day in Cyprus
10/28* Bank Holiday in Rep. of Ireland
10/29 Republic Day in Turkey
10/31 Nevada Day in Nevada
11/01 All Saints Day
11/02 All Souls Day in Bolivia, Brazil, El Salvador, Uruguay
11/02 Memorial Day in Ecuador
11/03 Culture Day in Japan
11/03 Thanksgiving Day in Liberia
11/04 Flag Day in Panama
11/04 Will Rogers Day
11/06 Green March Day in Morocco
11/07 National Revolution Day
11/07 October Revolution Day in Hungary
11/11 Independence Day in Angola
11/11 Rememberance Day in Canada
11/11 Republic Day in Maldives
11/15 Dynasty Day in Belgium
11/17 Army Day in Zaire
11/18 Independence Day in Morocco
11/18 National Days (4 days) in Oman
11/19 Discovery Day in Puerto Rico
11/19 Feast Day of S.A.S. Prince Rainier in Monaco
11/20 Revolution Day in Mexico
11/21 Day of Prayer and Repentance in Federal Republic of Germany
11/22 Independence Day in Lebanon
11/23 Labor Thanksgiving Day in Japan
11/25 Independence Day in Suriname
11/28 Independence Day in Albania, Mauritania
11/29 Day of the Republic (2 days) in Yugoslavia
11/29 Goodwill Day in Liberia
11/29 Liberation Day in Albania
11/29 National Day in Burma
11/30 Independence Day in Barbados, Yemen Deomcratic Republic
11/30 National Day in Benin
11/30 National Heroes Day in Philippines
11/30 St. Andrew's Day
12/01 Independence Day in Central African Republic
12/02 National Holiday in United Arab Emirates
12/03 National Holiday in Laos
12/06 Independence Day in Finland
12/07 Delaware Day in Delaware
12/07 Independence Day in Ivory Coast, Panama
12/08 Mother's Day in Panama
12/09 Independence Day in Tanzania
12/10 Human Rights Day
12/10 Thai Constitution Day in Thailand
12/10 Wyoming Day in Wyoming
12/11 Independence Day in Upper Volta
12/12 Independence Day in Kenya
12/13 Republic Day in Malta
12/15 Statue Day in Netherlands Antilles
12/16 Constitution Day in Nepal
12/16 Day of the Covenant in South Africa
12/16 National Day in Bahrain
12/16 Victry Day in Bangladesh
12/17 National Day in Bhutan
12/18 Republic Day in Niger
12/23 Victory Day in Egypt
12/25 Children's Day in Congo
12/26 Bank Holiday in Canada, Rep. of Ireland, and UK
12/26 Boxing Day
12/26 Family Day in South Africa
12/26 St. Stephen's Day
12/26 Bank Holiday in Canada, Rep. of Ireland, and UK
12/27 Bank Holiday in Cayman Islands
12/27 Constitution Day in North Korea
12/27 Public Holiday in Lesotho, Zimbabwe
12/29 Civic Holidays (3 days) in Costa Rica
12/31 Bank Holiday in El Salvador, Honduras, Pakistan
12/31 Feed Yourself Day in Benin
04/21 Tiradentes in Brazil
04/25 Anniversary of the Revolution in Portugal
04/29 Emperor's Birthday in Japan
04/30 Queen's Birthday in Netherlands, Netherlands Antilles
05/01 Boy's day in Japan
05/02 King's Birthday in Lesotho
05/05 Battle of Puebla in Mexico
05/08 Buddha's Birthday in South Korea
05/08 Elections for the National Assembly in Philippines
05/14 Anniversary of the Founding of Guinean Deomcratic Party in Guinea
05/25 Anniversary of the Revolution of 1810 in Argentina
05/25 Revolution in the Sudan in Libyan Arab Republic
05/27 Afghanistan attains sovereignty, 1921
06/02 Corpus Christi in Paraguay
06/03 Jefferson Davis's Birthday in Alabama & Mississippi (1st Monday)
06/03 Jefferson Davis's Birthday in Florida, Georgia, & S. Carolina
06/04 Queen's Birthday in New Zealand
06/06 His Majesty, Yang Di-Pertuan Agong's Birthday in Malaysia
06/11 Queen's Birthday
06/12 Peace with Bolivia in Paraguay
06/13 Corrective Movement in Yemen Arab Republic
06/16 Bloomsday - Anniversary of Dublin events, 1904, in "Ulysses"
06/18 Queen's Birthday in Fiji
06/19 Artigas Birthday in Uruguay
06/22 Corrective Movement in Yermen Democratic Republic
06/22 Midsummer Eve in Finland, Sweden
06/24 Battle of Carabobob in Venezuela
07/01 Eid-Ul-Fitr* (2 days) in Pakistan
07/01 Union of the Somalia Republic in Somalia
07/07 Anniversary of the P.U.N. in Equatorial Guinea
07/12 Battle of Boyne celebrated in Northern Ireland
07/12 The Twelfth in Northern Ireland
07/13 Buddhist Lent in Thailand
07/14 Anniversary of the Revolution in Iraq
07/17 July Revolution in Iraq
07/17 Munoz Rivera's Birthday (celebrated in Puerto Rico)
07/22 King's Birthday in Swaziland
07/23 Anniversary of the Revolution in Egypt
07/25 St. James, Patron Saint in Spain
07/27 Barbosa's Birthday (celebrated in Puerto Rico)
07/29 Olsok Eve in Norway to commemorate Norway's Viking King St. Olav
08/01 Founding of Asuncion in Paraguay
08/02 Our Lady of Los Angeles in Costa Rica
08/03 Massacre du Pidjiguiti in Buinea-bissau
08/07 Battle of Boyaca in Colombia
08/11 King Hussein's Accession to the Throne in Jordan
08/12 Queen's Birthday in Thailand
08/13 Proclamation of Independence in Central African Republic
08/14 Waddi Dhahab in Morocco
08/15 Founding of Ascuncion in Paraguay
08/15 Santa Maria in Malta
08/17 Anniversary of the Death of General San Martin in Argentina
09/09 Anniversary of the Socialist Revolution (2 days) in Bulgaria
09/10 Moon Festival in Taiwan
09/11 Aniversary of military coup in Chile
09/11 Ethiopian New Year in Ethiopia
09/12 Amilcar Cabral's Birthday in Guinea-Bissau
09/14 Battle of San Jacinto in Nicaragua
09/15 Foundation of Panama in Panama
09/23 Grito de Lares in Puerto Rico
09/24 Anniversary of the Third Republic in Ghana
09/24 Our Lady of Mercedes in Dominican Republic
09/27 Feast of Finding the True Cross in Ethiopia
09/29 Battle of Boqueron in Paraquay
10/02 Anniversary of Guinean Independence in Guinea
10/03 Chung Yeung Festival in Hong Kong
10/03 Francisco Morazan's Birthday in Honduras
10/05 Anniversary of Proclamation of the Republic in Portugal
10/08 Battle of Agamos in Peru
10/09 Independence of Guayaquil in Ecuador
10/17 Dessaline's Death Anniversary in Haiti
10/20 Anniversary of the 1944 Revolution in Guatemala
11/01 Feast of All Saints in Portugal
11/01 Samhain; Beginning of the Celtic year and most important holiday.
11/03 Independence from Columbia in Panama
11/03 Independence of Cuenca in Ecuador
11/06 Prophet Mohammed's Birthday in Malaysia
11/07 Anniversary of Great October Revolution in Bulgaria
11/08 Her Majesty, the Queen's Birthday in Nepal
11/10 King's Birthday in Bhutan
11/11 Angola gains independence from Portugal, 1975
11/11 Independence of Cartagena in Colombia
11/12 Prince Charles' Birthday in Fiji
11/14 King Hussein's Birthday in Jordan
11/15 Proclamation of the Republic in Brazil
11/15 Thatlouang Festival in Laos
11/16 Oklahoma Heritage Week in Oklahoma
11/17 Corrective Movement in Syrian Arab Republic
11/18 Battle of Viertieres in Haiti
11/19 Anniversary of the 1968 Coup by the Army in Mali
11/19 Garifuna Settlement in Belize
11/19 Prince of Wales Birthday in Fiji
11/22 Anniversary of Portuguese Aggression in Guinea
11/24 Anniversary of the New Regime in Zaire
11/28 Independence from Spain in Panama
11/28 Proclamation of the Republic in Chad
12/01 Anniversary of the Restoration of Independence in Portugal
12/07 Prophet Mohammed's Birthday in Fiji
12/08 Blessing of the Water in Uruguay
12/08 Our Lady of the Cacupe in Paraguay
12/10 Foundation of Worker's Party in Angola
12/25 Birthday of Quaid-i-Azam in Pakistan
12/26 Feast of Our Theotokos in Greece
12/29 His Majesty, the King's Birthday in Nepal
12/30 Anniversary of the Democratic Republic of Madagascar in Madagascar
12/31 Proclamation of the Republic in Congo

View file

@ -0,0 +1,30 @@
03/08* Fast of Esther (Battle of Purim; 1 day before Purim; fast day)
03/11* Purim (Feast of Lots; 30 days before Pesach)
03/12* Purim (Feast of Lots)
04/10* Pesach (First Day of Passover; sabbatical)
04/11* Pesach (sabbatical)
04/16* Pesach (sabbatical)
04/17* Pesach (Last Day of Passover; 8th day of Pesach; sabbatical)
04/30* Yom HaAtzmaut (Israel Independence Day)
05/13* Lag Ba`omer (Commemoration of the Great Rebellion)
05/22* Yom Yerushalayim (Reunification of Jerusalem)
05/30* Shavuos (Festival of Weeks; 50 days after Pesach; sabbatical)
05/31* Shavuos (Festival of Weeks; sabbatical)
07/10* Fast of Shiv'a Asar B'Tammuz (Romans breach Wall of Jerusalem;
fast day)
07/31* Fast of Tish'a B'Av (Babylon/Rome destroys Holy Temple; fast day)
09/20* First Day of Rosh Hashanah (Jewish Lunar New Year; 5741 == 1980;
sabbatical)
09/21* Rosh Hashanah (sabbatical)
09/23* Fast of Gedalya (Murder of Gedalya and subsequent Exile; 1 day
after Rosh Hashanah; fast day)
09/29* Yom Kippur (Day of Atonement; 9 days after Rosh Hashanah;
sabbatical, fast day)
10/04* Succos (Festival of Tabernacles; 14 days after Rosh Hashanah;
sabbatical)
10/05* Succos (sabbatical)
10/10* Hoshanah Rabba (7th day of Succos)
10/11* Shmini Atzeres (8th Day of Gathering; 1 day after Succos; sabbatical)
10/12* Shmini Atzeres/Simchas Torah (Rejoicing of the Law; sabbatical)
12/12* First Day of Chanukah
12/27* Fast of Asara B'Tevet (Babylonians put siege on Jerusalem; fast day)

View file

@ -0,0 +1,178 @@
01/01 Country Joe McDonald is born in El Monte, California, 1942
01/03 Steven Stills is born in Dallas, 1945
01/04 Jazz great Charlie Mingus dies at 57 in Cuernavaca, Mexico, 1979
01/08 David Bowie (then David Robert Jones) is born in London, 1947
01/09 James Patrick Page (Led Zeppelin) is born in Middlesex, England, 1945
01/10 Blues guitarist Howlin' Wolf dies in Chicago, 1976
01/10 Jim Croce is born in Phildelphia, 1943
01/10 Pat Benatar is born in Long Island, 1952
01/10 Rod Stewart is born in Glasgow, Scotland, 1945
01/13 Eric Clapton plays the "Rainbow Concert" in London, 1973
01/17 Led Zeppelin's first album is released, 1969
01/19 Janis Joplin is born in Port Arthur, Texas, 1943
01/22 Sam Cooke is born in Chicago, 1935
01/24 Warren Zevon is born, 1947
01/25 Bob Dylan plays the second "Hurricane" benefit, in the Astrodome, 1978
01/27 Bobby "Blue" Bland (Robert Calvin Bland) is born in Tennessee, 1930
01/27 Wolfgang Amadeus Mozart born in Salzburg, 1756
01/28 Jimi Hendrix headlines Madison Square Garden, 1970
01/30 Lightnin' Hopkins, the most-recorded blues artist ever, dies, 1982
01/31 The Grateful Dead are busted in New Orleans, 1970
02/01 RCA Victor unveils the 45 rpm record playing system, 1949
02/02 Graham Nash is born in Lancashire, England, 1942
02/03 The Day The Music Died; Buddy Holly, Richie Valens, and the Big
Bopper are killed in a plane crash outside Mason City, Iowa, 1959
02/07 Beatles land at JFK airport to begin first U.S. tour, 1964
02/07 Steven Stills makes the first digitally recorded rock album, 1979
02/09 Carole King (Carole Klein) is born in Brooklyn, 1941
02/12 The Beatles play Carnegie Hall in New York City, 1964
02/17 Jazz great Thelonius Monk dies in Englewood, New Jersey, 1982
02/18 Yoko Ono Lennon is born in Tokyo, 1933
02/19 Paul McCartney's "Give Ireland Back to the Irish" is banned in
Britain, 1972
02/19 William "Smokey" Robinson is born in Detroit, 1940
02/20 J. Geils (J. Geils Band) is born, 1946
02/20 Yes sells out Madison Square Garden...without advertising, 1974
02/23 Handel born, 1685
02/23 Johnny Winter is born in Leland, Mississippi, 1944
02/29 Jimmy Dorsey born, 1904
03/01 Jim Morrison is busted for obscenity in Miami, 1969
03/02 Blues guitarist Rory Gallagher is born in Ballyshannon, Ireland, 1949
03/03 Buffalo Springfield is formed in Los Angeles, 1966
03/04 Antonio Vivaldi born in Venice, Italy, 1678
03/07 Last Gilbert & Sullivan opera produced, 1896
03/08 Ron "Pigpen" McKernan (Grateful Dead) dies in California, 1973
03/09 Robin Trower is born in London, 1945
03/13 The Allman Brothers record their live album at the Fillmore East, 1971
03/15 Sly Stone born, 1944
03/17 Paul Kantner (Jefferson Airplane) is born in San Francisco, 1942
03/21 J.S. Bach born, 1685
03/22 Ten Years After plays their last concert, 1974
03/25 Aretha Franklin is born in Detroit, 1943
03/26 Emerson, Lake, and Palmer record "Pictures at an Exhibition" live, 1971
03/29 Dr. Hook gets a group picture on the cover of "Rolling Stone", 1973
03/30 Eric Clapton is born in Surrey, England, 1945
04/02 Marvin Gaye is born in Washington, D.C., 1939
04/04 Muddy Waters (McKinley Morganfield) is born in Rolling Fork,
Mississippi, 1915
04/09 Paul Robeson born, 1898
04/10 Paul McCartney announces that he's quitting the Beatles, 1970
04/14 Ritchie Blackmore (Deep Purple, Rainbow) is born, 1945
04/18 Yes breaks up after 13 years, 1981
04/25 Blues guitarist Albert King is born, 1925
04/25 Ella Fitzgerald born, 1918
04/26 Carol Burnett born in San Antonio, Texas, 1933
04/29 "Hair" premiers on Broadway, 1968
05/01 Kate Smith born, 1909
05/03 Bob Seger is born in Ann Arbor, Michigan, 1945
05/07 Johannes Brahms born in Hamburg, 1833
05/07 Tchaikowsky born, 1840
05/10 Dave Mason is born in Worcester, England, 1945
05/11 Bob Marley dies in his sleep in Miami, 1981
05/12 Pink Floyd performs the first quadrophonic concert, 1977
05/18 Rick Wakeman is born in West London, England, 1949
05/19 Pete Townshend is born in London, 1945
05/20 The Jimi Hendrix Experience is signed by Reprise Records, 1967
05/22 Johann Sebastian Bach born in Eisenach, Germany, 1665
05/23 Blues great Elmore James dies, 1963
05/24 Bob Dylan (Robert Zimmerman) is born in Duluth, 1941
05/26 Al Jolson born, 1886
05/31 The Who perform the loudest concert ever -- 76,000 watts of PA, 1976
06/01 The Beatles release "Sgt. Pepper", 1967
06/06 "Rock Around The Clock" makes Billboard's #1 slot, 1955
06/07 Blind Faith debuts in concert at London's Hyde Park, 1969
06/09 Les Paul (Lester Polfus) is born in Waukesha, Wisconsin, 1923
06/10 Howlin' Wolf (Chester Burnett) is born in West Point, Mississippi, 1910
06/10 Judy Garlnad born, 1922
06/15 Harry Nilsson is born in Brooklyn, 1941
06/16 The Monterey Pop festival opens, 1967
06/18 Paul McCartney born in Liverpool, England, 1942
06/21 Columbia records announces the first mass production of LP's, 1948
06/22 Todd Rundgren is born in Upper Darby, Pennsylvania, 1948
06/24 Jeff Beck is born in Surrey, England, 1944
07/02 Felix Pappalardi and Leslie West form Mountain, 1969
07/03 Jim Morrison dies in Paris, 1971
07/06 The Jefferson Airplane is formed in San Francisco, 1965
07/07 Ringo Starr (Richard Starkey) born in Liverpool, England, 1940
07/12 Chicago DJ Steve Dahl holds "Disco Demolition" at Kamisky Park, 1979
07/14 Woodie Guthrie born, 1912
07/16 Cream forms in the U.K., 1966
07/16 Harry Chapin dies on Long Island Expressway, 1981
07/17 "Yellow Submarine" premieres at the London Pavilon, 1968
07/20 Carlos Santana is born in Autlan, Mexico, 1947
07/25 Bob Dylan goes electric at the Newport Folk Festival, 1965
07/25 Crosby, Stills, Nash & Young debut at the Fillmore East, 1969
07/26 Mick Jagger is born in Kent, England, 1943
07/28 Bach dies, 1750
07/28 The Watkins Glen "Summer Jam" opens, 1973
08/01 The Concert for Bangla Desh takes place at Madison Square Garden, 1971
08/04 John Lennon points out that "the Beatles are more popular than Jesus",
1966
08/10 Ian Anderson (Jethro Tull) is born in Edinburgh, Scotland, 1947
08/13 Dan Fogelberg is born in Peoria, Illinois, 1951
08/15 Beatles replace drummer Pete Best with Richard Starkey
08/15 The Beatles play Shea Stadium in New York, 1965
08/15 Woodstock Festival, Max Yasgur's farm, 1969
08/26 Jimi Hendrix gives his last performance at the Isle of Wight, 1970
08/26 Jimi Hendrix's Electric Ladyland Studios opens in New York, 1970
09/07 Keith Moon (The Who) dies in London of a drug overdose, 1978
09/08 Anton Dvorak born in Nelahozeves, Czechoslovakia, 1841
09/08 Ron "Pigpen" McKernan (Grateful Dead) is born in San Bruno,
California, 1945
09/14 Francis Scott Key writes words to "Star Spangled Banner", 1814
09/16 B.B. King is born in Itta Bena, Mississippi, 1925
09/19 Simon & Garfunkel reunite to play New York's Central Park, 1981
09/20 Jim Croce dies in a plane crash, 1973
09/23 "Paul is dead" rumors sweep the country, 1969
09/23 Bruce "The Boss" Springsteen is born in Freehold, New Jersey, 1949
09/25 John Bonham (Led Zeppelin) dies of alcohol poisoning, 1980
09/26 George Gershwin born in Brooklyn, NY
10/04 Janis Joplin O.D.s, 1970
10/04 Janis Joplin dies of a heroin overdose in Hollywood, 1970
10/05 Steve Miller is born in Dallas, 1943
10/07 First Bandstand (later, American Bandstand) broadcast, 1957
10/09 John Lennon born in Liverpool, England, 1940
10/10 John Prine is born in Maywood, Illinois, 1946
10/12 The Jimi Hendrix Experience is formed in London, 1966
10/16 Bob Weir (Grateful Dead) is born in San Francisco, 1947
10/17 "Hair" opens at New York's Public Theater, 1967
10/18 Chuck Berry is born in San Jose, California, 1926
10/20 Three members of Lynyrd Skynyrd die in a plane crash, 1977
10/22 Franz Liszt born, 1811
10/25 Jon Anderson (Yes) is born in Lancashire, England, 1944
10/25 The Rolling Stones appear on The Ed Sullivan Show, 1964
10/29 Duane Allman dies in motorcycle crash near Macon, Georgia, 1971
10/30 Grace Slick is born in Chicago, 1939
11/02 Jimi Hendrix's "Electric Ladyland" enters US charts at #1, 1968
11/02 Keith Emerson is born, 1944
11/03 James Taylor and Carly Simon are married in Manhattan, 1972
11/07 Joni Mitchell (Roberta Joan Anderson) is born in Alberta, Canada, 1943
11/08 Patti Page born, 1927
11/09 The first issue of "Rolling Stone" is published, 1967
11/10 Greg Lake is born in Bournemouth, England, 1948
11/12 Neil Young is born in Toronto, 1945
11/13 Paul Simon born, 1942
11/16 Bill Ham first demonstrates his psychedelic "Light Show", 1965
11/20 Duane Allman is born in Nashville, Tennessee, 1946
11/20 Joe Walsh is born in Cleveland, 1947
11/24 Scott Joplin born, 1868
11/25 "The Last Waltz" concert is played by The Band at Winterland, 1976
11/25 Johann Strauss, Jr., writes `On the Beautiful Blue Danube', 1867
11/26 Cream performs their farewell concert at Royal Albert Hall, 1968
11/27 Jimi Hendrix (Johnny Allen Hendrix) is born in Seattle, 1942
12/05 Mozart dies, 1791
12/06 First sound recording made by Thomas Edison, 1877
12/06 The Rolling Stones play Altamont Speedway near San Francisco, 1969
12/07 Harry Chapin is born in New York City, 1942
12/08 Jim Morrison is born in Melbourne, Florida, 1943
12/08 John Lennon is shot and killed in New York City, 1980
12/09 The Who's "Tommy" premieres in London, 1973
12/13 Ted Nugent, the motor city madman, born in Detroit, 1949
12/15 Thomas Edison receives patent on the phonograph, 1877
12/16 Beethoven born, 1770
12/16 Don McLean's "American Pie" is released, 1971
12/16 Ludwig von Beethoven christened in Bonn, Germany, 1770
12/21 Frank Zappa is born in Baltimore, 1940
12/23 First G&S collaboration, Thespis, 1871
12/28 Edgar Winter is born in Beaumont, Texas, 1946
12/31 Jimi Hendrix introduces the Band of Gypsies at the Fillmore East, 1969

View file

@ -0,0 +1,31 @@
01/01 New Year's Day
01/14 Julian Calendar New Year's Day
02/02 Groundhog Day
02/14 St. Valentine's Day
02/20* President's Day (3rd Monday of February)
03/05 Mother-in-Law Day
03/17 St. Patrick's Day
03/20* Vernal Equinox
04/01 April Fool's Day
04/15 Income Tax Day
04/03* Daylight Savings Time begins; clocks move forward (1st Sunday of April)
04/28* Arbor Day (varies from state to state)
05/14* Mother's Day (2nd Sunday of May)
05/20* Armed Forces Day (3rd Saturday of May)
05/29* Memorial Day (Last Monday of May)
06/18* Father's Day (3rd Sunday of June)
06/21* Summer Solstice
07/04 Independence Day
09/04* Labor Day (1st Monday of September)
09/09* Grandparent's Day (2nd Sunday of September; varies from state to state)
09/22* Autumnal Equinox
10/09* Columbus Day (2nd Monday of October)
10/29* Daylight Savings Time ends; clocks move back (Last Sunday in October)
10/31 All Hallows Eve (Halloween)
11/06* Election Day (1st Tuesday after 1st Monday for even years)
11/11 Veterans' Day
11/29 Thanksgiving Day (Last Thursday in November)
12/21* Winter Solstice
12/24 Christmas Eve
12/25 Christmas
12/31 New Year's Eve

View file

@ -0,0 +1,40 @@
/*
* Copyright (c) 1989, 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.
*
* @(#)pathnames.h 8.1 (Berkeley) 6/6/93
*/
#include <paths.h>
#define _PATH_CPP "/usr/bin/cpp"
/* XXX -- fix when cpp parses arguments rationally */
#define _PATH_INCLUDE "-I/usr/share/calendar"

View file

@ -0,0 +1,5 @@
# @(#)Makefile 8.1 (Berkeley) 6/6/93
PROG= cap_mkdb
.include <bsd.prog.mk>

101
usr.bin/cap_mkdb/cap_mkdb.1 Normal file
View file

@ -0,0 +1,101 @@
.\" Copyright (c) 1992, 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.
.\"
.\" @(#)cap_mkdb.1 8.1 (Berkeley) 6/6/93
.\"
.Dd "June 6, 1993"
.Dt CAP_MKDB 1
.Os
.Sh NAME
.Nm cap_mkdb
.Nd create capability database
.Pp
.Sh SYNOPSIS
.Nm cap_mkdb
.Op Fl v
.Op Fl f Ar outfile
.Ar file1
.Op Ar file2 ...
.Pp
.Sh DESCRIPTION
.Nm Cap_mkdb
builds a hashed database out of the
.Xr getcap 3
logical database constructed by the concatenation of the specified
files .
.Pp
The database is named by the basename of the first file argument and
the string
.Dq .db .
The
.Xr getcap 3
routines can access the database in this form much more quickly
than they can the original text file(s).
.Pp
The ``tc'' capabilities of the records are expanded before the
record is stored into the database.
.Pp
The options as as follows:
.Bl -tag -width XXXXXX -indent
.It Fl f Ar outfile
Specify a different database basename.
.It Fl v
Print out the number of capability records in the database.
.El
.Pp
.Sh FORMAT
Each record is stored in the database using two different types of keys.
.Pp
The first type is a key which consists of the first capability of
the record (not including the trailing colon (``:'')) with a data
field consisting of a special byte followed by the rest of the record.
The special byte is either a 0 or 1, where a 0 means that the record
is okay, and a 1 means that there was a ``tc'' capability in the record
that couldn't be expanded.
.Pp
The second type is a key which consists of one of the names from the
first capability of the record with a data field consisting a special
byte followed by the the first capability of the record.
The special byte is a 2.
.Pp
In normal operation names are looked up in the database, resulting
in a key/data pair of the second type.
The data field of this key/data pair is used to look up a key/data
pair of the first type which has the real data associated with the
name.
.Sh RETURN VALUE
The
.Nm cap_mkdb
utility exits 0 on success and >0 if an error occurs.
.Sh SEE ALSO
.Xr dbopen 3 ,
.Xr getcap 3 ,
.Xr termcap 5

250
usr.bin/cap_mkdb/cap_mkdb.c Normal file
View file

@ -0,0 +1,250 @@
/*-
* Copyright (c) 1992, 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) 1992, 1993\n\
The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */
#ifndef lint
static char sccsid[] = "@(#)cap_mkdb.c 8.1 (Berkeley) 6/6/93";
#endif /* not lint */
#include <sys/param.h>
#include <sys/stat.h>
#include <db.h>
#include <err.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
void db_build __P((char **));
void dounlink __P((void));
void usage __P((void));
DB *capdbp;
int verbose;
char *capdb, *capname, buf[8 * 1024];
/*
* Mkcapdb creates a capability hash database for quick retrieval of capability
* records. The database contains 2 types of entries: records and references
* marked by the first byte in the data. A record entry contains the actual
* capability record whereas a reference contains the name (key) under which
* the correct record is stored.
*/
int
main(argc, argv)
int argc;
char *argv[];
{
int c;
capname = NULL;
while ((c = getopt(argc, argv, "f:v")) != EOF) {
switch(c) {
case 'f':
capname = optarg;
break;
case 'v':
verbose = 1;
break;
case '?':
default:
usage();
}
}
argc -= optind;
argv += optind;
if (*argv == NULL)
usage();
/*
* The database file is the first argument if no name is specified.
* Make arrangements to unlink it if exit badly.
*/
(void)snprintf(buf, sizeof(buf), "%s.db", capname ? capname : *argv);
if ((capname = strdup(buf)) == NULL)
err(1, "");
if ((capdbp = dbopen(capname,
O_CREAT | O_TRUNC | O_RDWR, DEFFILEMODE, DB_HASH, NULL)) == NULL)
err(1, "%s", buf);
if (atexit(dounlink))
err(1, "atexit");
db_build(argv);
if (capdbp->close(capdbp) < 0)
err(1, "%s", capname);
capname = NULL;
exit(0);
}
void
dounlink()
{
if (capname != NULL)
(void)unlink(capname);
}
/*
* Any changes to these definitions should be made also in the getcap(3)
* library routines.
*/
#define RECOK (char)0
#define TCERR (char)1
#define SHADOW (char)2
/*
* Db_build() builds the name and capabilty databases according to the
* details above.
*/
void
db_build(ifiles)
char **ifiles;
{
DBT key, data;
recno_t reccnt;
size_t len, bplen;
int st;
char *bp, *p, *t;
data.data = NULL;
key.data = NULL;
for (reccnt = 0, bplen = 0; (st = cgetnext(&bp, ifiles)) > 0;) {
/*
* Allocate enough memory to store record, terminating
* NULL and one extra byte.
*/
len = strlen(bp);
if (bplen <= len + 2) {
bplen += MAX(256, len + 2);
if ((data.data = realloc(data.data, bplen)) == NULL)
err(1, "");
}
/* Find the end of the name field. */
if ((p = strchr(bp, ':')) == NULL) {
warnx("no name field: %.*s", MIN(len, 20), bp);
continue;
}
/* First byte of stored record indicates status. */
switch(st) {
case 1:
((char *)(data.data))[0] = RECOK;
break;
case 2:
((char *)(data.data))[0] = TCERR;
warnx("Record not tc expanded: %.*s", p - bp, bp);
break;
}
/* Create the stored record. */
memmove(&((u_char *)(data.data))[1], bp, len + 1);
data.size = len + 2;
/* Store the record under the name field. */
key.data = bp;
key.size = p - bp;
switch(capdbp->put(capdbp, &key, &data, R_NOOVERWRITE)) {
case -1:
err(1, "put");
/* NOTREACHED */
case 1:
warnx("ignored duplicate: %.*s",
key.size, (char *)key.data);
continue;
}
++reccnt;
/* If only one name, ignore the rest. */
if ((p = strchr(bp, '|')) == NULL)
continue;
/* The rest of the names reference the entire name. */
((char *)(data.data))[0] = SHADOW;
memmove(&((u_char *)(data.data))[1], key.data, key.size);
data.size = key.size + 1;
/* Store references for other names. */
for (p = t = bp;; ++p) {
if (p > t && (*p == ':' || *p == '|')) {
key.size = p - t;
key.data = t;
switch(capdbp->put(capdbp,
&key, &data, R_NOOVERWRITE)) {
case -1:
err(1, "put");
/* NOTREACHED */
case 1:
warnx("ignored duplicate: %.*s",
key.size, (char *)key.data);
}
t = p + 1;
}
if (*p == ':')
break;
}
}
switch(st) {
case -1:
err(1, "file argument");
/* NOTREACHED */
case -2:
errx(1, "potential reference loop detected");
/* NOTREACHED */
}
if (verbose)
(void)printf("cap_mkdb: %d capability records\n", reccnt);
}
void
usage()
{
(void)fprintf(stderr,
"usage: cap_mkdb [-v] [-f outfile] file1 [file2 ...]\n");
exit(1);
}

5
usr.bin/checknr/Makefile Normal file
View file

@ -0,0 +1,5 @@
# @(#)Makefile 8.1 (Berkeley) 6/6/93
PROG= checknr
.include <bsd.prog.mk>

159
usr.bin/checknr/checknr.1 Normal file
View file

@ -0,0 +1,159 @@
.\" Copyright (c) 1980, 1990, 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.
.\"
.\" @(#)checknr.1 8.1 (Berkeley) 6/6/93
.\"
.Dd June 6, 1993
.Dt CHECKNR 1
.Os BSD 4
.Sh NAME
.Nm checknr
.Nd check nroff/troff files
.Sh SYNOPSIS
.Nm checknr
.Op Fl a Ns Ar \&.x1.y1.x2.y2. ... \&.xn.yn
.Op Fl c Ns Ar \&.x1.x2.x3 ... \&.xn
.Op Fl s
.Op Fl f
.Ar file
.Sh DESCRIPTION
.Nm Checknr
checks a list of
.Xr nroff 1
or
.Xr troff 1
input files for certain kinds of errors
involving mismatched opening and closing delimiters
and unknown commands.
If no files are specified,
.Nm checknr
checks the standard input.
.Pp
Options:
.Bl -tag -width Ds
.It Fl a
Add additional pairs of macros to the list of known macros.
This must be followed by groups of six characters, each group defining
a pair of macros.
The six characters are
a period,
the first macro name,
another period,
and the second macro name.
For example, to define a pair .BS and .ES, use
.Sq Li \-a.BS.ES
.It Fl c
Define commands which would otherwise be complained about
as undefined.
.It Fl f
Request
.Nm checknr
to ignore
.Ql \ef
font changes.
.It Fl s
Ignore
.Ql \es
size changes.
.El
.Pp
Delimiters checked are:
.Bl -enum
.It
Font changes using \efx ... \efP.
.It
Size changes using \esx ... \es0.
.It
Macros that come in open ... close forms, for example,
the .TS and .TE macros which must always come in pairs.
.El
.Pp
.Nm Checknr
is intended for use on documents that are prepared with
.Nm checknr
in mind, much the same as
.Xr lint 1 .
It expects a certain document writing style for
.Ql \ef
and
.Ql \es
commands,
in that each
.Ql \efx
must be terminated with
.Ql \efP
and
each
.Ql \esx
must be terminated with
.Ql \es0 .
While it will work to directly go into the next font or explicitly
specify the original font or point size,
and many existing documents actually do this,
such a practice will produce complaints from
.Nm checknr .
Since it is probably better to use the
.Ql \efP
and
.Ql \es0
forms anyway,
you should think of this as a contribution to your document
preparation style.
.Pp
.Nm Checknr
knows about the
.Xr ms 7
and
.Xr me 7
macro packages.
.Sh SEE ALSO
.Xr nroff 1 ,
.Xr troff 1 ,
.Xr checkeq 1 ,
.Xr ms 7 ,
.Xr me 7
.Sh DIAGNOSTICS
.Bd -ragged -compact
Complaints about unmatched delimiters.
Complaints about unrecognized commands.
Various complaints about the syntax of commands.
.Ed
.Sh BUGS
There is no way to define a 1 character macro name using
.Fl a .
.Pp
Does not correctly recognize certain reasonable constructs,
such as conditionals.
.Sh HISTORY
The
.Nm
command appeared in
.Bx 4.0 .

586
usr.bin/checknr/checknr.c Normal file
View file

@ -0,0 +1,586 @@
/*
* Copyright (c) 1980, 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) 1980, 1993\n\
The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */
#ifndef lint
static char sccsid[] = "@(#)checknr.c 8.1 (Berkeley) 6/6/93";
#endif /* not lint */
/*
* checknr: check an nroff/troff input file for matching macro calls.
* we also attempt to match size and font changes, but only the embedded
* kind. These must end in \s0 and \fP resp. Maybe more sophistication
* later but for now think of these restrictions as contributions to
* structured typesetting.
*/
#include <stdio.h>
#include <ctype.h>
#define MAXSTK 100 /* Stack size */
#define MAXBR 100 /* Max number of bracket pairs known */
#define MAXCMDS 500 /* Max number of commands known */
/*
* The stack on which we remember what we've seen so far.
*/
struct stkstr {
int opno; /* number of opening bracket */
int pl; /* '+', '-', ' ' for \s, 1 for \f, 0 for .ft */
int parm; /* parm to size, font, etc */
int lno; /* line number the thing came in in */
} stk[MAXSTK];
int stktop;
/*
* The kinds of opening and closing brackets.
*/
struct brstr {
char *opbr;
char *clbr;
} br[MAXBR] = {
/* A few bare bones troff commands */
#define SZ 0
"sz", "sz", /* also \s */
#define FT 1
"ft", "ft", /* also \f */
/* the -mm package */
"AL", "LE",
"AS", "AE",
"BL", "LE",
"BS", "BE",
"DF", "DE",
"DL", "LE",
"DS", "DE",
"FS", "FE",
"ML", "LE",
"NS", "NE",
"RL", "LE",
"VL", "LE",
/* the -ms package */
"AB", "AE",
"BD", "DE",
"CD", "DE",
"DS", "DE",
"FS", "FE",
"ID", "DE",
"KF", "KE",
"KS", "KE",
"LD", "DE",
"LG", "NL",
"QS", "QE",
"RS", "RE",
"SM", "NL",
"XA", "XE",
"XS", "XE",
/* The -me package */
"(b", ")b",
"(c", ")c",
"(d", ")d",
"(f", ")f",
"(l", ")l",
"(q", ")q",
"(x", ")x",
"(z", ")z",
/* Things needed by preprocessors */
"EQ", "EN",
"TS", "TE",
/* Refer */
"[", "]",
0, 0
};
/*
* All commands known to nroff, plus macro packages.
* Used so we can complain about unrecognized commands.
*/
char *knowncmds[MAXCMDS] = {
"$c", "$f", "$h", "$p", "$s", "(b", "(c", "(d", "(f", "(l", "(q", "(t",
"(x", "(z", ")b", ")c", ")d", ")f", ")l", ")q", ")t", ")x", ")z", "++",
"+c", "1C", "1c", "2C", "2c", "@(", "@)", "@C", "@D", "@F", "@I", "@M",
"@c", "@e", "@f", "@h", "@m", "@n", "@o", "@p", "@r", "@t", "@z", "AB",
"AE", "AF", "AI", "AL", "AM", "AS", "AT", "AU", "AX", "B", "B1", "B2",
"BD", "BE", "BG", "BL", "BS", "BT", "BX", "C1", "C2", "CD", "CM", "CT",
"D", "DA", "DE", "DF", "DL", "DS", "DT", "EC", "EF", "EG", "EH", "EM",
"EN", "EQ", "EX", "FA", "FD", "FE", "FG", "FJ", "FK", "FL", "FN", "FO",
"FQ", "FS", "FV", "FX", "H", "HC", "HD", "HM", "HO", "HU", "I", "ID",
"IE", "IH", "IM", "IP", "IX", "IZ", "KD", "KE", "KF", "KQ", "KS", "LB",
"LC", "LD", "LE", "LG", "LI", "LP", "MC", "ME", "MF", "MH", "ML", "MR",
"MT", "ND", "NE", "NH", "NL", "NP", "NS", "OF", "OH", "OK", "OP", "P",
"P1", "PF", "PH", "PP", "PT", "PX", "PY", "QE", "QP", "QS", "R", "RA",
"RC", "RE", "RL", "RP", "RQ", "RS", "RT", "S", "S0", "S2", "S3", "SA",
"SG", "SH", "SK", "SM", "SP", "SY", "T&", "TA", "TB", "TC", "TD", "TE",
"TH", "TL", "TM", "TP", "TQ", "TR", "TS", "TX", "UL", "US", "UX", "VL",
"WC", "WH", "XA", "XD", "XE", "XF", "XK", "XP", "XS", "[", "[-", "[0",
"[1", "[2", "[3", "[4", "[5", "[<", "[>", "[]", "]", "]-", "]<", "]>",
"][", "ab", "ac", "ad", "af", "am", "ar", "as", "b", "ba", "bc", "bd",
"bi", "bl", "bp", "br", "bx", "c.", "c2", "cc", "ce", "cf", "ch", "cs",
"ct", "cu", "da", "de", "di", "dl", "dn", "ds", "dt", "dw", "dy", "ec",
"ef", "eh", "el", "em", "eo", "ep", "ev", "ex", "fc", "fi", "fl", "fo",
"fp", "ft", "fz", "hc", "he", "hl", "hp", "ht", "hw", "hx", "hy", "i",
"ie", "if", "ig", "in", "ip", "it", "ix", "lc", "lg", "li", "ll", "ln",
"lo", "lp", "ls", "lt", "m1", "m2", "m3", "m4", "mc", "mk", "mo", "n1",
"n2", "na", "ne", "nf", "nh", "nl", "nm", "nn", "np", "nr", "ns", "nx",
"of", "oh", "os", "pa", "pc", "pi", "pl", "pm", "pn", "po", "pp", "ps",
"q", "r", "rb", "rd", "re", "rm", "rn", "ro", "rr", "rs", "rt", "sb",
"sc", "sh", "sk", "so", "sp", "ss", "st", "sv", "sz", "ta", "tc", "th",
"ti", "tl", "tm", "tp", "tr", "u", "uf", "uh", "ul", "vs", "wh", "xp",
"yr", 0
};
int lineno; /* current line number in input file */
char line[256]; /* the current line */
char *cfilename; /* name of current file */
int nfiles; /* number of files to process */
int fflag; /* -f: ignore \f */
int sflag; /* -s: ignore \s */
int ncmds; /* size of knowncmds */
int slot; /* slot in knowncmds found by binsrch */
char *malloc();
main(argc, argv)
int argc;
char **argv;
{
FILE *f;
int i;
char *cp;
char b1[4];
/* Figure out how many known commands there are */
while (knowncmds[ncmds])
ncmds++;
while (argc > 1 && argv[1][0] == '-') {
switch(argv[1][1]) {
/* -a: add pairs of macros */
case 'a':
i = strlen(argv[1]) - 2;
if (i % 6 != 0)
usage();
/* look for empty macro slots */
for (i=0; br[i].opbr; i++)
;
for (cp=argv[1]+3; cp[-1]; cp += 6) {
br[i].opbr = malloc(3);
strncpy(br[i].opbr, cp, 2);
br[i].clbr = malloc(3);
strncpy(br[i].clbr, cp+3, 2);
addmac(br[i].opbr); /* knows pairs are also known cmds */
addmac(br[i].clbr);
i++;
}
break;
/* -c: add known commands */
case 'c':
i = strlen(argv[1]) - 2;
if (i % 3 != 0)
usage();
for (cp=argv[1]+3; cp[-1]; cp += 3) {
if (cp[2] && cp[2] != '.')
usage();
strncpy(b1, cp, 2);
addmac(b1);
}
break;
/* -f: ignore font changes */
case 'f':
fflag = 1;
break;
/* -s: ignore size changes */
case 's':
sflag = 1;
break;
default:
usage();
}
argc--; argv++;
}
nfiles = argc - 1;
if (nfiles > 0) {
for (i=1; i<argc; i++) {
cfilename = argv[i];
f = fopen(cfilename, "r");
if (f == NULL)
perror(cfilename);
else
process(f);
}
} else {
cfilename = "stdin";
process(stdin);
}
exit(0);
}
usage()
{
printf("Usage: checknr -s -f -a.xx.yy.xx.yy... -c.xx.xx.xx...\n");
exit(1);
}
process(f)
FILE *f;
{
register int i, n;
char mac[5]; /* The current macro or nroff command */
int pl;
stktop = -1;
for (lineno = 1; fgets(line, sizeof line, f); lineno++) {
if (line[0] == '.') {
/*
* find and isolate the macro/command name.
*/
strncpy(mac, line+1, 4);
if (isspace(mac[0])) {
pe(lineno);
printf("Empty command\n");
} else if (isspace(mac[1])) {
mac[1] = 0;
} else if (isspace(mac[2])) {
mac[2] = 0;
} else if (mac[0] != '\\' || mac[1] != '\"') {
pe(lineno);
printf("Command too long\n");
}
/*
* Is it a known command?
*/
checkknown(mac);
/*
* Should we add it?
*/
if (eq(mac, "de"))
addcmd(line);
chkcmd(line, mac);
}
/*
* At this point we process the line looking
* for \s and \f.
*/
for (i=0; line[i]; i++)
if (line[i]=='\\' && (i==0 || line[i-1]!='\\')) {
if (!sflag && line[++i]=='s') {
pl = line[++i];
if (isdigit(pl)) {
n = pl - '0';
pl = ' ';
} else
n = 0;
while (isdigit(line[++i]))
n = 10 * n + line[i] - '0';
i--;
if (n == 0) {
if (stk[stktop].opno == SZ) {
stktop--;
} else {
pe(lineno);
printf("unmatched \\s0\n");
}
} else {
stk[++stktop].opno = SZ;
stk[stktop].pl = pl;
stk[stktop].parm = n;
stk[stktop].lno = lineno;
}
} else if (!fflag && line[i]=='f') {
n = line[++i];
if (n == 'P') {
if (stk[stktop].opno == FT) {
stktop--;
} else {
pe(lineno);
printf("unmatched \\fP\n");
}
} else {
stk[++stktop].opno = FT;
stk[stktop].pl = 1;
stk[stktop].parm = n;
stk[stktop].lno = lineno;
}
}
}
}
/*
* We've hit the end and look at all this stuff that hasn't been
* matched yet! Complain, complain.
*/
for (i=stktop; i>=0; i--) {
complain(i);
}
}
complain(i)
{
pe(stk[i].lno);
printf("Unmatched ");
prop(i);
printf("\n");
}
prop(i)
{
if (stk[i].pl == 0)
printf(".%s", br[stk[i].opno].opbr);
else switch(stk[i].opno) {
case SZ:
printf("\\s%c%d", stk[i].pl, stk[i].parm);
break;
case FT:
printf("\\f%c", stk[i].parm);
break;
default:
printf("Bug: stk[%d].opno = %d = .%s, .%s",
i, stk[i].opno, br[stk[i].opno].opbr, br[stk[i].opno].clbr);
}
}
chkcmd(line, mac)
char *line;
char *mac;
{
register int i, n;
/*
* Check to see if it matches top of stack.
*/
if (stktop >= 0 && eq(mac, br[stk[stktop].opno].clbr))
stktop--; /* OK. Pop & forget */
else {
/* No. Maybe it's an opener */
for (i=0; br[i].opbr; i++) {
if (eq(mac, br[i].opbr)) {
/* Found. Push it. */
stktop++;
stk[stktop].opno = i;
stk[stktop].pl = 0;
stk[stktop].parm = 0;
stk[stktop].lno = lineno;
break;
}
/*
* Maybe it's an unmatched closer.
* NOTE: this depends on the fact
* that none of the closers can be
* openers too.
*/
if (eq(mac, br[i].clbr)) {
nomatch(mac);
break;
}
}
}
}
nomatch(mac)
char *mac;
{
register int i, j;
/*
* Look for a match further down on stack
* If we find one, it suggests that the stuff in
* between is supposed to match itself.
*/
for (j=stktop; j>=0; j--)
if (eq(mac,br[stk[j].opno].clbr)) {
/* Found. Make a good diagnostic. */
if (j == stktop-2) {
/*
* Check for special case \fx..\fR and don't
* complain.
*/
if (stk[j+1].opno==FT && stk[j+1].parm!='R'
&& stk[j+2].opno==FT && stk[j+2].parm=='R') {
stktop = j -1;
return;
}
/*
* We have two unmatched frobs. Chances are
* they were intended to match, so we mention
* them together.
*/
pe(stk[j+1].lno);
prop(j+1);
printf(" does not match %d: ", stk[j+2].lno);
prop(j+2);
printf("\n");
} else for (i=j+1; i <= stktop; i++) {
complain(i);
}
stktop = j-1;
return;
}
/* Didn't find one. Throw this away. */
pe(lineno);
printf("Unmatched .%s\n", mac);
}
/* eq: are two strings equal? */
eq(s1, s2)
char *s1, *s2;
{
return (strcmp(s1, s2) == 0);
}
/* print the first part of an error message, given the line number */
pe(lineno)
int lineno;
{
if (nfiles > 1)
printf("%s: ", cfilename);
printf("%d: ", lineno);
}
checkknown(mac)
char *mac;
{
if (eq(mac, "."))
return;
if (binsrch(mac) >= 0)
return;
if (mac[0] == '\\' && mac[1] == '"') /* comments */
return;
pe(lineno);
printf("Unknown command: .%s\n", mac);
}
/*
* We have a .de xx line in "line". Add xx to the list of known commands.
*/
addcmd(line)
char *line;
{
char *mac;
/* grab the macro being defined */
mac = line+4;
while (isspace(*mac))
mac++;
if (*mac == 0) {
pe(lineno);
printf("illegal define: %s\n", line);
return;
}
mac[2] = 0;
if (isspace(mac[1]) || mac[1] == '\\')
mac[1] = 0;
if (ncmds >= MAXCMDS) {
printf("Only %d known commands allowed\n", MAXCMDS);
exit(1);
}
addmac(mac);
}
/*
* Add mac to the list. We should really have some kind of tree
* structure here but this is a quick-and-dirty job and I just don't
* have time to mess with it. (I wonder if this will come back to haunt
* me someday?) Anyway, I claim that .de is fairly rare in user
* nroff programs, and the register loop below is pretty fast.
*/
addmac(mac)
char *mac;
{
register char **src, **dest, **loc;
if (binsrch(mac) >= 0){ /* it's OK to redefine something */
#ifdef DEBUG
printf("binsrch(%s) -> already in table\n", mac);
#endif DEBUG
return;
}
/* binsrch sets slot as a side effect */
#ifdef DEBUG
printf("binsrch(%s) -> %d\n", mac, slot);
#endif
loc = &knowncmds[slot];
src = &knowncmds[ncmds-1];
dest = src+1;
while (dest > loc)
*dest-- = *src--;
*loc = malloc(3);
strcpy(*loc, mac);
ncmds++;
#ifdef DEBUG
printf("after: %s %s %s %s %s, %d cmds\n", knowncmds[slot-2], knowncmds[slot-1], knowncmds[slot], knowncmds[slot+1], knowncmds[slot+2], ncmds);
#endif
}
/*
* Do a binary search in knowncmds for mac.
* If found, return the index. If not, return -1.
*/
binsrch(mac)
char *mac;
{
register char *p; /* pointer to current cmd in list */
register int d; /* difference if any */
register int mid; /* mid point in binary search */
register int top, bot; /* boundaries of bin search, inclusive */
top = ncmds-1;
bot = 0;
while (top >= bot) {
mid = (top+bot)/2;
p = knowncmds[mid];
d = p[0] - mac[0];
if (d == 0)
d = p[1] - mac[1];
if (d == 0)
return mid;
if (d < 0)
bot = mid + 1;
else
top = mid - 1;
}
slot = bot; /* place it would have gone */
return -1;
}

7
usr.bin/chflags/Makefile Normal file
View file

@ -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>

123
usr.bin/chflags/chflags.1 Normal file
View file

@ -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

180
usr.bin/chflags/chflags.c Normal file
View file

@ -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);
}

15
usr.bin/chpass/Makefile Normal file
View file

@ -0,0 +1,15 @@
# @(#)Makefile 8.2 (Berkeley) 4/2/94
PROG= chpass
SRCS= chpass.c edit.c field.c pw_copy.c pw_scan.c pw_util.c table.c util.c
BINOWN= root
BINMODE=4555
.PATH: ${.CURDIR}/../../usr.sbin/pwd_mkdb ${.CURDIR}/../../usr.sbin/vipw
CFLAGS+=-I${.CURDIR}/../../usr.sbin/pwd_mkdb -I${.CURDIR}/../../usr.sbin/vipw
LINKS= ${BINDIR}/chpass ${BINDIR}/chfn ${BINDIR}/chpass ${BINDIR}/chsh
MLINKS= chpass.1 chfn.1 chpass.1 chsh.1
afterinstall:
chflags schg /usr/bin/chpass
.include <bsd.prog.mk>

231
usr.bin/chpass/chpass.1 Normal file
View file

@ -0,0 +1,231 @@
.\" Copyright (c) 1988, 1990, 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.
.\"
.\" @(#)chpass.1 8.2 (Berkeley) 12/30/93
.\"
.Dd December 30, 1993
.Dt CHPASS 1
.Os
.Sh NAME
.Nm chpass
.Nd add or change user database information
.Sh SYNOPSIS
chpass
.Op Fl a Ar list
.Op Fl s Ar newshell
.Op user
.Sh DESCRIPTION
.Nm Chpass
allows editing of the user database information associated
with
.Ar user
or, by default, the current user.
The information is formatted and supplied to an editor for changes.
.Pp
Only the information that the user is allowed to change is displayed.
.Pp
The options are as follows:
.Bl -tag -width Ds
.It Fl a
The super-user is allowed to directly supply a user database
entry, in the format specified by
.Xr passwd 5 ,
as an argument.
This argument must be a colon (``:'') separated list of all the
user database fields, although they may be empty.
.It Fl s
The
.Fl s
option attempts to change the user's shell to
.Ar newshell .
.El
.Pp
Possible display items are as follows:
.Pp
.Bl -tag -width "Home Directory:" -compact -offset indent
.It Login:
user's login name
.It Password:
user's encrypted password
.It Uid:
user's login
.It Gid:
user's login group
.It Change:
password change time
.It Expire:
account expiration time
.It Class:
user's general classification
.It Home Directory:
user's home directory
.It Shell:
user's login shell
.It Full Name:
user's real name
.It Location:
user's normal location
.It Home Phone:
user's home phone
.It Office Phone:
user's office phone
.El
.Pp
The
.Ar login
field is the user name used to access the computer account.
.Pp
The
.Ar password
field contains the encrypted form of the user's password.
.Pp
The
.Ar uid
field is the number associated with the
.Ar login
field.
Both of these fields should be unique across the system (and often
across a group of systems) as they control file access.
.Pp
While it is possible to have multiple entries with identical login names
and/or identical user id's, it is usually a mistake to do so. Routines
that manipulate these files will often return only one of the multiple
entries, and that one by random selection.
.Pp
The
.Ar group
field is the group that the user will be placed in at login.
Since BSD supports multiple groups (see
.Xr groups 1 )
this field currently has little special meaning.
This field may be filled in with either a number or a group name (see
.Xr group 5 ) .
.Pp
The
.Ar change
field is the date by which the password must be changed.
.Pp
The
.Ar expire
field is the date on which the account expires.
.Pp
Both the
.Ar change
and
.Ar expire
fields should be entered in the form ``month day year'' where
.Ar month
is the month name (the first three characters are sufficient),
.Ar day
is the day of the month, and
.Ar year
is the year.
.Pp
The
.Ar class
field is currently unused. In the near future it will be a key to
a
.Xr termcap 5
style database of user attributes.
.Pp
The user's
.Ar home directory
is the full UNIX path name where the user
will be placed at login.
.Pp
The
.Ar shell
field is the command interpreter the user prefers.
If the
.Ar shell
field is empty, the Bourne shell,
.Pa /bin/sh ,
is assumed.
When altering a login shell, and not the super-user, the user
may not change from a non-standard shell or to a non-standard
shell.
Non-standard is defined as a shell not found in
.Pa /etc/shells .
.Pp
The last four fields are for storing the user's
.Ar full name , office location ,
and
.Ar home
and
.Ar work telephone
numbers.
.Pp
Once the information has been verified,
.Nm chpass
uses
.Xr pwd_mkdb 8
to update the user database.
.Sh ENVIRONMENT
The
.Xr vi 1
editor will be used unless the environment variable EDITOR is set to
an alternate editor.
When the editor terminates, the information is re-read and used to
update the user database itself.
Only the user, or the super-user, may edit the information associated
with the user.
.Sh FILES
.Bl -tag -width /etc/master.passwd -compact
.It Pa /etc/master.passwd
The user database
.It Pa /etc/passwd
A Version 7 format password file
.It Pa /etc/chpass.XXXXXX
Temporary copy of the password file
.It Pa /etc/shells
The list of approved shells
.El
.Sh SEE ALSO
.Xr login 1 ,
.Xr finger 1 ,
.Xr passwd 1 ,
.Xr getusershell 3 ,
.Xr passwd 5 ,
.Xr pwd_mkdb 8 ,
.Xr vipw 8
.Rs
.%A Robert Morris
and
.%A Ken Thompson
.%T "UNIX Password security"
.Re
.Sh BUGS
User information should (and eventually will) be stored elsewhere.
.Sh HISTORY
The
.Nm
command appeared in
.Bx 4.3 Reno .

192
usr.bin/chpass/chpass.c Normal file
View file

@ -0,0 +1,192 @@
/*-
* Copyright (c) 1988, 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) 1988, 1993, 1994\n\
The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */
#ifndef lint
static char sccsid[] = "@(#)chpass.c 8.4 (Berkeley) 4/2/94";
#endif /* not lint */
#include <sys/param.h>
#include <sys/stat.h>
#include <sys/signal.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <ctype.h>
#include <err.h>
#include <errno.h>
#include <fcntl.h>
#include <pwd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <pw_scan.h>
#include <pw_util.h>
#include "pw_copy.h"
#include "chpass.h"
#include "pathnames.h"
char *progname = "chpass";
char *tempname;
uid_t uid;
void baduser __P((void));
void usage __P((void));
int
main(argc, argv)
int argc;
char **argv;
{
enum { NEWSH, LOADENTRY, EDITENTRY } op;
struct passwd *pw, lpw;
int ch, pfd, tfd;
char *arg;
op = EDITENTRY;
while ((ch = getopt(argc, argv, "a:s:")) != EOF)
switch(ch) {
case 'a':
op = LOADENTRY;
arg = optarg;
break;
case 's':
op = NEWSH;
arg = optarg;
break;
case '?':
default:
usage();
}
argc -= optind;
argv += optind;
uid = getuid();
if (op == EDITENTRY || op == NEWSH)
switch(argc) {
case 0:
if (!(pw = getpwuid(uid)))
errx(1, "unknown user: uid %u", uid);
break;
case 1:
if (!(pw = getpwnam(*argv)))
errx(1, "unknown user: %s", *argv);
if (uid && uid != pw->pw_uid)
baduser();
break;
default:
usage();
}
if (op == NEWSH) {
/* protect p_shell -- it thinks NULL is /bin/sh */
if (!arg[0])
usage();
if (p_shell(arg, pw, (ENTRY *)NULL))
pw_error((char *)NULL, 0, 1);
}
if (op == LOADENTRY) {
if (uid)
baduser();
pw = &lpw;
if (!pw_scan(arg, pw))
exit(1);
}
/*
* The temporary file/file descriptor usage is a little tricky here.
* 1: We start off with two fd's, one for the master password
* file (used to lock everything), and one for a temporary file.
* 2: Display() gets an fp for the temporary file, and copies the
* user's information into it. It then gives the temporary file
* to the user and closes the fp, closing the underlying fd.
* 3: The user edits the temporary file some number of times.
* 4: Verify() gets an fp for the temporary file, and verifies the
* contents. It can't use an fp derived from the step #2 fd,
* because the user's editor may have created a new instance of
* the file. Once the file is verified, its contents are stored
* in a password structure. The verify routine closes the fp,
* closing the underlying fd.
* 5: Delete the temporary file.
* 6: Get a new temporary file/fd. Pw_copy() gets an fp for it
* file and copies the master password file into it, replacing
* the user record with a new one. We can't use the first
* temporary file for this because it was owned by the user.
* Pw_copy() closes its fp, flushing the data and closing the
* underlying file descriptor. We can't close the master
* password fp, or we'd lose the lock.
* 7: Call pw_mkdb() (which renames the temporary file) and exit.
* The exit closes the master passwd fp/fd.
*/
pw_init();
pfd = pw_lock();
tfd = pw_tmp();
if (op == EDITENTRY) {
display(tfd, pw);
edit(pw);
(void)unlink(tempname);
tfd = pw_tmp();
}
pw_copy(pfd, tfd, pw);
if (!pw_mkdb())
pw_error((char *)NULL, 0, 1);
exit(0);
}
void
baduser()
{
errx(1, "%s", strerror(EACCES));
}
void
usage()
{
(void)fprintf(stderr, "usage: chpass [-a list] [-s shell] [user]\n");
exit(1);
}

70
usr.bin/chpass/chpass.h Normal file
View file

@ -0,0 +1,70 @@
/*
* Copyright (c) 1988, 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.
*
* @(#)chpass.h 8.4 (Berkeley) 4/2/94
*/
struct passwd;
typedef struct _entry {
char *prompt;
int (*func)(), restricted, len;
char *except, *save;
} ENTRY;
/* Field numbers. */
#define E_BPHONE 8
#define E_HPHONE 9
#define E_LOCATE 10
#define E_NAME 7
#define E_SHELL 12
extern ENTRY list[];
extern uid_t uid;
int atot __P((char *, time_t *));
void display __P((int, struct passwd *));
void edit __P((struct passwd *));
char *ok_shell __P((char *));
int p_change __P((char *, struct passwd *, ENTRY *));
int p_class __P((char *, struct passwd *, ENTRY *));
int p_expire __P((char *, struct passwd *, ENTRY *));
int p_gecos __P((char *, struct passwd *, ENTRY *));
int p_gid __P((char *, struct passwd *, ENTRY *));
int p_hdir __P((char *, struct passwd *, ENTRY *));
int p_login __P((char *, struct passwd *, ENTRY *));
int p_login __P((char *, struct passwd *, ENTRY *));
int p_passwd __P((char *, struct passwd *, ENTRY *));
int p_shell __P((char *, struct passwd *, ENTRY *));
int p_uid __P((char *, struct passwd *, ENTRY *));
char *ttoa __P((time_t));
int verify __P((struct passwd *));

213
usr.bin/chpass/edit.c Normal file
View file

@ -0,0 +1,213 @@
/*-
* Copyright (c) 1990, 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 sccsid[] = "@(#)edit.c 8.3 (Berkeley) 4/2/94";
#endif /* not lint */
#include <sys/param.h>
#include <sys/stat.h>
#include <ctype.h>
#include <err.h>
#include <errno.h>
#include <paths.h>
#include <pwd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <pw_scan.h>
#include <pw_util.h>
#include "chpass.h"
extern char *tempname;
void
edit(pw)
struct passwd *pw;
{
struct stat begin, end;
for (;;) {
if (stat(tempname, &begin))
pw_error(tempname, 1, 1);
pw_edit(1);
if (stat(tempname, &end))
pw_error(tempname, 1, 1);
if (begin.st_mtime == end.st_mtime) {
warnx("no changes made");
pw_error(NULL, 0, 0);
}
if (verify(pw))
break;
pw_prompt();
}
}
/*
* display --
* print out the file for the user to edit; strange side-effect:
* set conditional flag if the user gets to edit the shell.
*/
void
display(fd, pw)
int fd;
struct passwd *pw;
{
FILE *fp;
char *bp, *p, *ttoa();
if (!(fp = fdopen(fd, "w")))
pw_error(tempname, 1, 1);
(void)fprintf(fp,
"#Changing user database information for %s.\n", pw->pw_name);
if (!uid) {
(void)fprintf(fp, "Login: %s\n", pw->pw_name);
(void)fprintf(fp, "Password: %s\n", pw->pw_passwd);
(void)fprintf(fp, "Uid [#]: %d\n", pw->pw_uid);
(void)fprintf(fp, "Gid [# or name]: %d\n", pw->pw_gid);
(void)fprintf(fp, "Change [month day year]: %s\n",
ttoa(pw->pw_change));
(void)fprintf(fp, "Expire [month day year]: %s\n",
ttoa(pw->pw_expire));
(void)fprintf(fp, "Class: %s\n", pw->pw_class);
(void)fprintf(fp, "Home directory: %s\n", pw->pw_dir);
(void)fprintf(fp, "Shell: %s\n",
*pw->pw_shell ? pw->pw_shell : _PATH_BSHELL);
}
/* Only admin can change "restricted" shells. */
else if (ok_shell(pw->pw_shell))
/*
* Make shell a restricted field. Ugly with a
* necklace, but there's not much else to do.
*/
(void)fprintf(fp, "Shell: %s\n",
*pw->pw_shell ? pw->pw_shell : _PATH_BSHELL);
else
list[E_SHELL].restricted = 1;
bp = pw->pw_gecos;
p = strsep(&bp, ",");
(void)fprintf(fp, "Full Name: %s\n", p ? p : "");
p = strsep(&bp, ",");
(void)fprintf(fp, "Location: %s\n", p ? p : "");
p = strsep(&bp, ",");
(void)fprintf(fp, "Office Phone: %s\n", p ? p : "");
p = strsep(&bp, ",");
(void)fprintf(fp, "Home Phone: %s\n", p ? p : "");
(void)fchown(fd, getuid(), getgid());
(void)fclose(fp);
}
int
verify(pw)
struct passwd *pw;
{
ENTRY *ep;
char *p;
struct stat sb;
FILE *fp;
int len;
char buf[LINE_MAX];
if (!(fp = fopen(tempname, "r")))
pw_error(tempname, 1, 1);
if (fstat(fileno(fp), &sb))
pw_error(tempname, 1, 1);
if (sb.st_size == 0) {
warnx("corrupted temporary file");
goto bad;
}
while (fgets(buf, sizeof(buf), fp)) {
if (!buf[0] || buf[0] == '#')
continue;
if (!(p = strchr(buf, '\n'))) {
warnx("line too long");
goto bad;
}
*p = '\0';
for (ep = list;; ++ep) {
if (!ep->prompt) {
warnx("unrecognized field");
goto bad;
}
if (!strncasecmp(buf, ep->prompt, ep->len)) {
if (ep->restricted && uid) {
warnx(
"you may not change the %s field",
ep->prompt);
goto bad;
}
if (!(p = strchr(buf, ':'))) {
warnx("line corrupted");
goto bad;
}
while (isspace(*++p));
if (ep->except && strpbrk(p, ep->except)) {
warnx(
"illegal character in the \"%s\" field",
ep->prompt);
goto bad;
}
if ((ep->func)(p, pw, ep)) {
bad: (void)fclose(fp);
return (0);
}
break;
}
}
}
(void)fclose(fp);
/* Build the gecos field. */
len = strlen(list[E_NAME].save) + strlen(list[E_BPHONE].save) +
strlen(list[E_HPHONE].save) + strlen(list[E_LOCATE].save) + 4;
if (!(p = malloc(len)))
err(1, NULL);
(void)sprintf(pw->pw_gecos = p, "%s,%s,%s,%s", list[E_NAME].save,
list[E_LOCATE].save, list[E_BPHONE].save, list[E_HPHONE].save);
if (snprintf(buf, sizeof(buf),
"%s:%s:%d:%d:%s:%ld:%ld:%s:%s:%s",
pw->pw_name, pw->pw_passwd, pw->pw_uid, pw->pw_gid, pw->pw_class,
pw->pw_change, pw->pw_expire, pw->pw_gecos, pw->pw_dir,
pw->pw_shell) >= sizeof(buf)) {
warnx("entries too long");
return (0);
}
return (pw_scan(buf, pw));
}

268
usr.bin/chpass/field.c Normal file
View file

@ -0,0 +1,268 @@
/*
* Copyright (c) 1988, 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 sccsid[] = "@(#)field.c 8.4 (Berkeley) 4/2/94";
#endif /* not lint */
#include <sys/param.h>
#include <ctype.h>
#include <err.h>
#include <errno.h>
#include <grp.h>
#include <pwd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "chpass.h"
#include "pathnames.h"
/* ARGSUSED */
int
p_login(p, pw, ep)
char *p;
struct passwd *pw;
ENTRY *ep;
{
if (!*p) {
warnx("empty login field");
return (1);
}
if (*p == '-') {
warnx("login names may not begin with a hyphen");
return (1);
}
if (!(pw->pw_name = strdup(p))) {
warnx("can't save entry");
return (1);
}
if (strchr(p, '.'))
warnx("\'.\' is dangerous in a login name");
for (; *p; ++p)
if (isupper(*p)) {
warnx("upper-case letters are dangerous in a login name");
break;
}
return (0);
}
/* ARGSUSED */
int
p_passwd(p, pw, ep)
char *p;
struct passwd *pw;
ENTRY *ep;
{
if (!*p)
pw->pw_passwd = ""; /* "NOLOGIN"; */
else if (!(pw->pw_passwd = strdup(p))) {
warnx("can't save password entry");
return (1);
}
return (0);
}
/* ARGSUSED */
int
p_uid(p, pw, ep)
char *p;
struct passwd *pw;
ENTRY *ep;
{
uid_t id;
char *np;
if (!*p) {
warnx("empty uid field");
return (1);
}
if (!isdigit(*p)) {
warnx("illegal uid");
return (1);
}
errno = 0;
id = strtoul(p, &np, 10);
if (*np || (id == ULONG_MAX && errno == ERANGE)) {
warnx("illegal uid");
return (1);
}
pw->pw_uid = id;
return (0);
}
/* ARGSUSED */
int
p_gid(p, pw, ep)
char *p;
struct passwd *pw;
ENTRY *ep;
{
struct group *gr;
gid_t id;
char *np;
if (!*p) {
warnx("empty gid field");
return (1);
}
if (!isdigit(*p)) {
if (!(gr = getgrnam(p))) {
warnx("unknown group %s", p);
return (1);
}
pw->pw_gid = gr->gr_gid;
return (0);
}
errno = 0;
id = strtoul(p, &np, 10);
if (*np || (id == ULONG_MAX && errno == ERANGE)) {
warnx("illegal gid");
return (1);
}
pw->pw_gid = id;
return (0);
}
/* ARGSUSED */
int
p_class(p, pw, ep)
char *p;
struct passwd *pw;
ENTRY *ep;
{
if (!*p)
pw->pw_class = "";
else if (!(pw->pw_class = strdup(p))) {
warnx("can't save entry");
return (1);
}
return (0);
}
/* ARGSUSED */
int
p_change(p, pw, ep)
char *p;
struct passwd *pw;
ENTRY *ep;
{
if (!atot(p, &pw->pw_change))
return (0);
warnx("illegal date for change field");
return (1);
}
/* ARGSUSED */
int
p_expire(p, pw, ep)
char *p;
struct passwd *pw;
ENTRY *ep;
{
if (!atot(p, &pw->pw_expire))
return (0);
warnx("illegal date for expire field");
return (1);
}
/* ARGSUSED */
int
p_gecos(p, pw, ep)
char *p;
struct passwd *pw;
ENTRY *ep;
{
if (!*p)
ep->save = "";
else if (!(ep->save = strdup(p))) {
warnx("can't save entry");
return (1);
}
return (0);
}
/* ARGSUSED */
int
p_hdir(p, pw, ep)
char *p;
struct passwd *pw;
ENTRY *ep;
{
if (!*p) {
warnx("empty home directory field");
return (1);
}
if (!(pw->pw_dir = strdup(p))) {
warnx("can't save entry");
return (1);
}
return (0);
}
/* ARGSUSED */
int
p_shell(p, pw, ep)
char *p;
struct passwd *pw;
ENTRY *ep;
{
char *t, *ok_shell();
if (!*p) {
pw->pw_shell = _PATH_BSHELL;
return (0);
}
/* only admin can change from or to "restricted" shells */
if (uid && pw->pw_shell && !ok_shell(pw->pw_shell)) {
warnx("%s: current shell non-standard", pw->pw_shell);
return (1);
}
if (!(t = ok_shell(p))) {
if (uid) {
warnx("%s: non-standard shell", p);
return (1);
}
}
else
p = t;
if (!(pw->pw_shell = strdup(p))) {
warnx("can't save entry");
return (1);
}
return (0);
}

View file

@ -0,0 +1,39 @@
/*
* Copyright (c) 1989, 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.
*
* @(#)pathnames.h 8.1 (Berkeley) 6/6/93
*/
#include <paths.h>
#undef _PATH_TMP
#define _PATH_TMP "/tmp/chpass.XXXXXX"

107
usr.bin/chpass/pw_copy.c Normal file
View file

@ -0,0 +1,107 @@
/*-
* Copyright (c) 1990, 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 sccsid[] = "@(#)pw_copy.c 8.4 (Berkeley) 4/2/94";
#endif /* not lint */
/*
* This module is used to copy the master password file, replacing a single
* record, by chpass(1) and passwd(1).
*/
#include <err.h>
#include <pwd.h>
#include <stdio.h>
#include <string.h>
#include <pw_util.h>
#include "pw_copy.h"
extern char *tempname;
void
pw_copy(ffd, tfd, pw)
int ffd, tfd;
struct passwd *pw;
{
FILE *from, *to;
int done;
char *p, buf[8192];
if (!(from = fdopen(ffd, "r")))
pw_error(_PATH_MASTERPASSWD, 1, 1);
if (!(to = fdopen(tfd, "w")))
pw_error(tempname, 1, 1);
for (done = 0; fgets(buf, sizeof(buf), from);) {
if (!strchr(buf, '\n')) {
warnx("%s: line too long", _PATH_MASTERPASSWD);
pw_error(NULL, 0, 1);
}
if (done) {
(void)fprintf(to, "%s", buf);
if (ferror(to))
goto err;
continue;
}
if (!(p = strchr(buf, ':'))) {
warnx("%s: corrupted entry", _PATH_MASTERPASSWD);
pw_error(NULL, 0, 1);
}
*p = '\0';
if (strcmp(buf, pw->pw_name)) {
*p = ':';
(void)fprintf(to, "%s", buf);
if (ferror(to))
goto err;
continue;
}
(void)fprintf(to, "%s:%s:%d:%d:%s:%ld:%ld:%s:%s:%s\n",
pw->pw_name, pw->pw_passwd, pw->pw_uid, pw->pw_gid,
pw->pw_class, pw->pw_change, pw->pw_expire, pw->pw_gecos,
pw->pw_dir, pw->pw_shell);
done = 1;
if (ferror(to))
goto err;
}
if (!done)
(void)fprintf(to, "%s:%s:%d:%d:%s:%ld:%ld:%s:%s:%s\n",
pw->pw_name, pw->pw_passwd, pw->pw_uid, pw->pw_gid,
pw->pw_class, pw->pw_change, pw->pw_expire, pw->pw_gecos,
pw->pw_dir, pw->pw_shell);
if (ferror(to))
err: pw_error(NULL, 1, 1);
(void)fclose(to);
}

36
usr.bin/chpass/pw_copy.h Normal file
View file

@ -0,0 +1,36 @@
/*
* Copyright (c) 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.
*
* @(#)pw_copy.h 8.1 (Berkeley) 4/2/94
*/
void pw_copy __P((int, int, struct passwd *));

60
usr.bin/chpass/table.c Normal file
View file

@ -0,0 +1,60 @@
/*-
* Copyright (c) 1990, 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 sccsid[] = "@(#)table.c 8.3 (Berkeley) 4/2/94";
#endif /* not lint */
#include <sys/types.h>
#include <stddef.h>
#include "chpass.h"
char e1[] = ": ";
char e2[] = ":,";
ENTRY list[] = {
{ "login", p_login, 1, 5, e1, },
{ "password", p_passwd, 1, 8, e1, },
{ "uid", p_uid, 1, 3, e1, },
{ "gid", p_gid, 1, 3, e1, },
{ "class", p_class, 1, 5, e1, },
{ "change", p_change, 1, 6, NULL, },
{ "expire", p_expire, 1, 6, NULL, },
{ "full name", p_gecos, 0, 9, e2, },
{ "office phone", p_gecos, 0, 12, e2, },
{ "home phone", p_gecos, 0, 10, e2, },
{ "location", p_gecos, 0, 8, e2, },
{ "home directory", p_hdir, 1, 14, e1, },
{ "shell", p_shell, 0, 5, e1, },
{ NULL, 0, },
};

145
usr.bin/chpass/util.c Normal file
View file

@ -0,0 +1,145 @@
/*-
* Copyright (c) 1988, 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 sccsid[] = "@(#)util.c 8.4 (Berkeley) 4/2/94";
#endif /* not lint */
#include <sys/types.h>
#include <ctype.h>
#include <pwd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <tzfile.h>
#include <unistd.h>
#include "chpass.h"
#include "pathnames.h"
static int dmsize[] =
{ -1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
static char *months[] =
{ "January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November",
"December", NULL };
char *
ttoa(tval)
time_t tval;
{
struct tm *tp;
static char tbuf[50];
if (tval) {
tp = localtime(&tval);
(void)sprintf(tbuf, "%s %d, %d", months[tp->tm_mon],
tp->tm_mday, tp->tm_year + TM_YEAR_BASE);
}
else
*tbuf = '\0';
return (tbuf);
}
int
atot(p, store)
char *p;
time_t *store;
{
static struct tm *lt;
char *t, **mp;
time_t tval;
int day, month, year;
if (!*p) {
*store = 0;
return (0);
}
if (!lt) {
unsetenv("TZ");
(void)time(&tval);
lt = localtime(&tval);
}
if (!(t = strtok(p, " \t")))
goto bad;
for (mp = months;; ++mp) {
if (!*mp)
goto bad;
if (!strncasecmp(*mp, t, 3)) {
month = mp - months + 1;
break;
}
}
if (!(t = strtok((char *)NULL, " \t,")) || !isdigit(*t))
goto bad;
day = atoi(t);
if (!(t = strtok((char *)NULL, " \t,")) || !isdigit(*t))
goto bad;
year = atoi(t);
if (day < 1 || day > 31 || month < 1 || month > 12 || !year)
goto bad;
if (year < 100)
year += TM_YEAR_BASE;
if (year <= EPOCH_YEAR)
bad: return (1);
tval = isleap(year) && month > 2;
for (--year; year >= EPOCH_YEAR; --year)
tval += isleap(year) ?
DAYSPERLYEAR : DAYSPERNYEAR;
while (--month)
tval += dmsize[month];
tval += day;
tval = tval * HOURSPERDAY * MINSPERHOUR * SECSPERMIN;
tval -= lt->tm_gmtoff;
*store = tval;
return (0);
}
char *
ok_shell(name)
char *name;
{
char *p, *sh;
setusershell();
while (sh = getusershell()) {
if (!strcmp(name, sh))
return (name);
/* allow just shell name, but use "real" path */
if ((p = strrchr(sh, '/')) && strcmp(name, p + 1) == 0)
return (sh);
}
return (NULL);
}

6
usr.bin/cksum/Makefile Normal file
View file

@ -0,0 +1,6 @@
# @(#)Makefile 8.1 (Berkeley) 6/6/93
PROG= cksum
SRCS= cksum.c crc.c print.c sum1.c sum2.c
.include <bsd.prog.mk>

164
usr.bin/cksum/cksum.1 Normal file
View file

@ -0,0 +1,164 @@
.\" Copyright (c) 1991, 1993
.\" 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.
.\"
.\" @(#)cksum.1 8.1 (Berkeley) 6/29/93
.\"
.Dd June 29, 1993
.Dt CKSUM 1
.Os BSD 4.4
.Sh NAME
.Nm cksum
.Nd display file checksums and block counts
.Sh SYNOPSIS
.Nm cksum
.Op Fl o Op \&1 \&| \&2
.Op Ar file ...
.Sh DESCRIPTION
The
.Nm cksum
utility writes to the standard output three whitespace separated
fields for each input file.
These fields are a checksum
.Tn CRC ,
the total number of octets in the file and the file name.
If no file name is specified, the standard input is used and no file name
is written.
.Pp
The options are as follows:
.Bl -tag -width indent
.It Fl o
Use historic algorithms instead of the (superior) default one.
.Pp
Algorithm 1 is the algorithm used by historic
.Bx
systems as the
.Xr sum 1
algorithm and by historic
.At V
systems as the
.Xr sum
algorithm when using the
.Fl r
option.
This is a 16-bit checksum, with a right rotation before each addition;
overflow is discarded.
.Pp
Algorithm 2 is the algorithm used by historic
.At V
systems as the
default
.Xr sum
algorithm.
This is a 32-bit checksum, and is defined as follows:
.Bd -unfilled -offset indent
s = sum of all bytes;
r = s % 2^16 + (s % 2^32) / 2^16;
cksum = (r % 2^16) + r / 2^16;
.Ed
.Pp
Both algorithm 1 and 2 write to the standard output the same fields as
the default algorithm except that the size of the file in bytes is
replaced with the size of the file in blocks.
For historic reasons, the block size is 1024 for algorithm 1 and 512
for algorithm 2.
Partial blocks are rounded up.
.El
.Pp
The default
.Tn CRC
used is based on the polynomial used for
.Tn CRC
error checking
in the networking standard
.St -iso8802-3
The
.Tn CRC
checksum encoding is defined by the generating polynomial:
.Pp
.Bd -unfilled -offset indent
G(x) = x^32 + x^26 + x^23 + x^22 + x^16 + x^12 +
x^11 + x^10 + x^8 + x^7 + x^5 + x^4 + x^2 + x + 1
.Ed
.Pp
Mathematically, the
.Tn CRC
value corresponding to a given file is defined by
the following procedure:
.Bd -filled -offset indent
The
.Ar n
bits to be evaluated are considered to be the coefficients of a mod 2
polynomial M(x) of degree
.Ar n Ns \-1 .
These
.Ar n
bits are the bits from the file, with the most significant bit being the most
significant bit of the first octet of the file and the last bit being the least
significant bit of the last octet, padded with zero bits (if necessary) to
achieve an integral number of octets, followed by one or more octets
representing the length of the file as a binary value, least significant octet
first.
The smallest number of octets capable of representing this integer are used.
.Pp
M(x) is multiplied by x^32 (i.e., shifted left 32 bits) and divided by
G(x) using mod 2 division, producing a remainder R(x) of degree <= 31.
.Pp
The coefficients of R(x) are considered to be a 32-bit sequence.
.Pp
The bit sequence is complemented and the result is the CRC.
.Ed
.Pp
The
.Nm cksum
utility exits 0 on success, and >0 if an error occurs.
.Sh SEE ALSO
The default calculation is identical to that given in pseudo-code
in the following
.Tn ACM
article.
.Rs
.%T "Computation of Cyclic Redundancy Checks Via Table Lookup"
.%A Dilip V. Sarwate
.%J "Communications of the \\*(tNACM\\*(sP"
.%D "August 1988"
.Re
.Sh STANDARDS
The
.Nm cksum
utility is expected to be POSIX 1003.2 compatible.
.Sh HISTORY
The
.Nm cksum
utility appears in
.Bx 4.4 .

124
usr.bin/cksum/cksum.c Normal file
View file

@ -0,0 +1,124 @@
/*-
* Copyright (c) 1991, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* James W. Williams of NASA Goddard Space Flight Center.
*
* 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) 1991, 1993\n\
The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */
#ifndef lint
static char sccsid[] = "@(#)cksum.c 8.1 (Berkeley) 6/6/93";
#endif /* not lint */
#include <sys/cdefs.h>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include "extern.h"
void usage __P((void));
int
main(argc, argv)
int argc;
char **argv;
{
extern int optind;
u_long len, val;
register int ch, fd, rval;
char *fn;
int (*cfncn) __P((int, unsigned long *, unsigned long *));
void (*pfncn) __P((char *, unsigned long, unsigned long));
cfncn = crc;
pfncn = pcrc;
while ((ch = getopt(argc, argv, "o:")) != EOF)
switch(ch) {
case 'o':
if (*optarg == '1') {
cfncn = csum1;
pfncn = psum1;
} else if (*optarg == '2') {
cfncn = csum2;
pfncn = psum2;
} else {
(void)fprintf(stderr,
"cksum: illegal argument to -o option\n");
usage();
}
break;
case '?':
default:
usage();
}
argc -= optind;
argv += optind;
fd = STDIN_FILENO;
fn = NULL;
rval = 0;
do {
if (*argv) {
fn = *argv++;
if ((fd = open(fn, O_RDONLY, 0)) < 0) {
(void)fprintf(stderr, "cksum: %s: %s\n",
fn, strerror(errno));
rval = 1;
continue;
}
}
if (cfncn(fd, &val, &len)) {
(void)fprintf(stderr, "cksum: %s: %s\n",
fn ? fn : "stdin", strerror(errno));
rval = 1;
} else
pfncn(fn, val, len);
(void)close(fd);
} while (*argv);
exit(rval);
}
void
usage()
{
(void)fprintf(stderr, "usage: cksum [-o 1 | 2] [file ...]\n");
exit(1);
}

140
usr.bin/cksum/crc.c Normal file
View file

@ -0,0 +1,140 @@
/*-
* Copyright (c) 1991, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* James W. Williams of NASA Goddard Space Flight Center.
*
* 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 sccsid[] = "@(#)crc.c 8.1 (Berkeley) 6/17/93";
#endif /* not lint */
#include <sys/types.h>
#include <unistd.h>
static u_long crctab[] = {
0x0,
0x04c11db7, 0x09823b6e, 0x0d4326d9, 0x130476dc, 0x17c56b6b,
0x1a864db2, 0x1e475005, 0x2608edb8, 0x22c9f00f, 0x2f8ad6d6,
0x2b4bcb61, 0x350c9b64, 0x31cd86d3, 0x3c8ea00a, 0x384fbdbd,
0x4c11db70, 0x48d0c6c7, 0x4593e01e, 0x4152fda9, 0x5f15adac,
0x5bd4b01b, 0x569796c2, 0x52568b75, 0x6a1936c8, 0x6ed82b7f,
0x639b0da6, 0x675a1011, 0x791d4014, 0x7ddc5da3, 0x709f7b7a,
0x745e66cd, 0x9823b6e0, 0x9ce2ab57, 0x91a18d8e, 0x95609039,
0x8b27c03c, 0x8fe6dd8b, 0x82a5fb52, 0x8664e6e5, 0xbe2b5b58,
0xbaea46ef, 0xb7a96036, 0xb3687d81, 0xad2f2d84, 0xa9ee3033,
0xa4ad16ea, 0xa06c0b5d, 0xd4326d90, 0xd0f37027, 0xddb056fe,
0xd9714b49, 0xc7361b4c, 0xc3f706fb, 0xceb42022, 0xca753d95,
0xf23a8028, 0xf6fb9d9f, 0xfbb8bb46, 0xff79a6f1, 0xe13ef6f4,
0xe5ffeb43, 0xe8bccd9a, 0xec7dd02d, 0x34867077, 0x30476dc0,
0x3d044b19, 0x39c556ae, 0x278206ab, 0x23431b1c, 0x2e003dc5,
0x2ac12072, 0x128e9dcf, 0x164f8078, 0x1b0ca6a1, 0x1fcdbb16,
0x018aeb13, 0x054bf6a4, 0x0808d07d, 0x0cc9cdca, 0x7897ab07,
0x7c56b6b0, 0x71159069, 0x75d48dde, 0x6b93dddb, 0x6f52c06c,
0x6211e6b5, 0x66d0fb02, 0x5e9f46bf, 0x5a5e5b08, 0x571d7dd1,
0x53dc6066, 0x4d9b3063, 0x495a2dd4, 0x44190b0d, 0x40d816ba,
0xaca5c697, 0xa864db20, 0xa527fdf9, 0xa1e6e04e, 0xbfa1b04b,
0xbb60adfc, 0xb6238b25, 0xb2e29692, 0x8aad2b2f, 0x8e6c3698,
0x832f1041, 0x87ee0df6, 0x99a95df3, 0x9d684044, 0x902b669d,
0x94ea7b2a, 0xe0b41de7, 0xe4750050, 0xe9362689, 0xedf73b3e,
0xf3b06b3b, 0xf771768c, 0xfa325055, 0xfef34de2, 0xc6bcf05f,
0xc27dede8, 0xcf3ecb31, 0xcbffd686, 0xd5b88683, 0xd1799b34,
0xdc3abded, 0xd8fba05a, 0x690ce0ee, 0x6dcdfd59, 0x608edb80,
0x644fc637, 0x7a089632, 0x7ec98b85, 0x738aad5c, 0x774bb0eb,
0x4f040d56, 0x4bc510e1, 0x46863638, 0x42472b8f, 0x5c007b8a,
0x58c1663d, 0x558240e4, 0x51435d53, 0x251d3b9e, 0x21dc2629,
0x2c9f00f0, 0x285e1d47, 0x36194d42, 0x32d850f5, 0x3f9b762c,
0x3b5a6b9b, 0x0315d626, 0x07d4cb91, 0x0a97ed48, 0x0e56f0ff,
0x1011a0fa, 0x14d0bd4d, 0x19939b94, 0x1d528623, 0xf12f560e,
0xf5ee4bb9, 0xf8ad6d60, 0xfc6c70d7, 0xe22b20d2, 0xe6ea3d65,
0xeba91bbc, 0xef68060b, 0xd727bbb6, 0xd3e6a601, 0xdea580d8,
0xda649d6f, 0xc423cd6a, 0xc0e2d0dd, 0xcda1f604, 0xc960ebb3,
0xbd3e8d7e, 0xb9ff90c9, 0xb4bcb610, 0xb07daba7, 0xae3afba2,
0xaafbe615, 0xa7b8c0cc, 0xa379dd7b, 0x9b3660c6, 0x9ff77d71,
0x92b45ba8, 0x9675461f, 0x8832161a, 0x8cf30bad, 0x81b02d74,
0x857130c3, 0x5d8a9099, 0x594b8d2e, 0x5408abf7, 0x50c9b640,
0x4e8ee645, 0x4a4ffbf2, 0x470cdd2b, 0x43cdc09c, 0x7b827d21,
0x7f436096, 0x7200464f, 0x76c15bf8, 0x68860bfd, 0x6c47164a,
0x61043093, 0x65c52d24, 0x119b4be9, 0x155a565e, 0x18197087,
0x1cd86d30, 0x029f3d35, 0x065e2082, 0x0b1d065b, 0x0fdc1bec,
0x3793a651, 0x3352bbe6, 0x3e119d3f, 0x3ad08088, 0x2497d08d,
0x2056cd3a, 0x2d15ebe3, 0x29d4f654, 0xc5a92679, 0xc1683bce,
0xcc2b1d17, 0xc8ea00a0, 0xd6ad50a5, 0xd26c4d12, 0xdf2f6bcb,
0xdbee767c, 0xe3a1cbc1, 0xe760d676, 0xea23f0af, 0xeee2ed18,
0xf0a5bd1d, 0xf464a0aa, 0xf9278673, 0xfde69bc4, 0x89b8fd09,
0x8d79e0be, 0x803ac667, 0x84fbdbd0, 0x9abc8bd5, 0x9e7d9662,
0x933eb0bb, 0x97ffad0c, 0xafb010b1, 0xab710d06, 0xa6322bdf,
0xa2f33668, 0xbcb4666d, 0xb8757bda, 0xb5365d03, 0xb1f740b4
};
/*
* Compute a POSIX 1003.2 checksum. This routine has been broken out so that
* other programs can use it. It takes a file descriptor to read from and
* locations to store the crc and the number of bytes read. It returns 0 on
* success and 1 on failure. Errno is set on failure.
*/
u_long crc_total = ~0; /* The crc over a number of files. */
int
crc(fd, cval, clen)
register int fd;
u_long *cval, *clen;
{
register u_char *p;
register int nr;
register u_long crc, len;
u_char buf[16 * 1024];
#define COMPUTE(var, ch) (var) = (var) << 8 ^ crctab[(var) >> 24 ^ (ch)]
crc = len = 0;
crc_total = ~crc_total;
while ((nr = read(fd, buf, sizeof(buf))) > 0)
for (len += nr, p = buf; nr--; ++p) {
COMPUTE(crc, *p);
COMPUTE(crc_total, *p);
}
if (nr < 0)
return (1);
*clen = len;
/* Include the length of the file. */
for (; len != 0; len >>= 8) {
COMPUTE(crc, len & 0xff);
COMPUTE(crc_total, len & 0xff);
}
*cval = ~crc;
crc_total = ~crc_total;
return (0);
}

45
usr.bin/cksum/extern.h Normal file
View file

@ -0,0 +1,45 @@
/*-
* Copyright (c) 1991, 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.
*
* @(#)extern.h 8.1 (Berkeley) 6/6/93
*/
#include <sys/cdefs.h>
__BEGIN_DECLS
int crc __P((int, unsigned long *, unsigned long *));
void pcrc __P((char *, unsigned long, unsigned long));
void psum1 __P((char *, unsigned long, unsigned long));
void psum2 __P((char *, unsigned long, unsigned long));
int csum1 __P((int, unsigned long *, unsigned long *));
int csum2 __P((int, unsigned long *, unsigned long *));
__END_DECLS

73
usr.bin/cksum/print.c Normal file
View file

@ -0,0 +1,73 @@
/*-
* Copyright (c) 1991, 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 sccsid[] = "@(#)print.c 8.1 (Berkeley) 6/6/93";
#endif /* not lint */
#include <sys/types.h>
#include <stdio.h>
#include "extern.h"
void
pcrc(fn, val, len)
char *fn;
u_long val, len;
{
(void)printf("%lu %lu", val, len);
if (fn)
(void)printf(" %s", fn);
(void)printf("\n");
}
void
psum1(fn, val, len)
char *fn;
u_long val, len;
{
(void)printf("%lu %lu", val, (len + 1023) / 1024);
if (fn)
(void)printf(" %s", fn);
(void)printf("\n");
}
void
psum2(fn, val, len)
char *fn;
u_long val, len;
{
(void)printf("%lu %lu", val, (len + 511) / 512);
if (fn)
(void)printf(" %s", fn);
(void)printf("\n");
}

69
usr.bin/cksum/sum1.c Normal file
View file

@ -0,0 +1,69 @@
/*-
* Copyright (c) 1991, 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 sccsid[] = "@(#)sum1.c 8.1 (Berkeley) 6/6/93";
#endif /* not lint */
#include <sys/types.h>
#include <unistd.h>
int
csum1(fd, cval, clen)
register int fd;
u_long *cval, *clen;
{
register u_long total;
register int nr;
register u_int crc;
register u_char *p;
u_char buf[8192];
/*
* 16-bit checksum, rotating right before each addition;
* overflow is discarded.
*/
crc = total = 0;
while ((nr = read(fd, buf, sizeof(buf))) > 0)
for (total += nr, p = buf; nr--; ++p) {
if (crc & 1)
crc |= 0x10000;
crc = ((crc >> 1) + *p) & 0xffff;
}
if (nr < 0)
return(1);
*cval = crc;
*clen = total;
return(0);
}

71
usr.bin/cksum/sum2.c Normal file
View file

@ -0,0 +1,71 @@
/*-
* Copyright (c) 1991, 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 sccsid[] = "@(#)sum2.c 8.1 (Berkeley) 6/6/93";
#endif /* not lint */
#include <sys/types.h>
#include <unistd.h>
int
csum2(fd, cval, clen)
register int fd;
u_long *cval, *clen;
{
register u_long crc, total;
register int nr;
register u_char *p;
u_char buf[8192];
/*
* Draft 8 POSIX 1003.2:
*
* s = sum of all bytes
* r = s % 2^16 + (s % 2^32) / 2^16
* crc = (r % 2^16) + r / 2^16
*/
crc = total = 0;
while ((nr = read(fd, buf, sizeof(buf))) > 0)
for (total += nr, p = buf; nr--; ++p)
crc += *p;
if (nr < 0)
return(1);
crc = (crc & 0xffff) + (crc >> 16);
crc = (crc & 0xffff) + (crc >> 16);
*cval = crc;
*clen = total;
return(0);
}

6
usr.bin/cmp/Makefile Normal file
View file

@ -0,0 +1,6 @@
# @(#)Makefile 8.1 (Berkeley) 6/6/93
PROG= cmp
SRCS= cmp.c misc.c regular.c special.c
.include <bsd.prog.mk>

107
usr.bin/cmp/cmp.1 Normal file
View file

@ -0,0 +1,107 @@
.\" Copyright (c) 1987, 1990, 1993
.\" 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.
.\"
.\" @(#)cmp.1 8.1 (Berkeley) 6/6/93
.\"
.Dd June 6, 1993
.Dt CMP 1
.Os
.Sh NAME
.Nm cmp
.Nd compare two files
.Sh SYNOPSIS
.Nm cmp
.Op Fl l | Fl s
.Ar file1 file2
.Op Ar skip1 Op Ar skip2
.Sh DESCRIPTION
The cmp utility compares two files of any type and writes the results
to the standard output.
By default,
.Nm
is silent if the files are the same; if they differ, the byte
and line number at which the first difference occurred is reported.
.Pp
Bytes and lines are numbered beginning with one.
.Pp
The following options are available:
.Bl -tag -width flag
.It Fl l
Print the byte number (decimal) and the differing
byte values (octal) for each difference.
.It Fl s
Print nothing for differing files; return exit
status only.
.El
.Pp
The optional arguments
.Ar skip1
and
.Ar skip2
are the byte offsets from the beginning of
.Ar file1
and
.Ar file2 ,
respectively, where the comparison will begin.
The offset is decimal by default, but may be expressed as an hexadecimal
or octal value by preceding it with a leading ``0x'' or ``0''.
.Pp
The
.Nm cmp
utility exits with one of the following values:
.Bl -tag -width 4n
.It 0
The files are identical.
.It 1
The files are different; this includes the case
where one file is identical to the first part of
the other.
In the latter case, if the
.Fl s
option has not been specified,
.Nm cmp
writes to standard output that EOF was reached in the shorter
file (before any differences were found).
.It >1
An error occurred.
.El
.Sh SEE ALSO
.Xr diff 1 ,
.Xr diff3 1
.Sh STANDARDS
The
.Nm cmp
utility is expected to be
.St -p1003.2
compatible.

146
usr.bin/cmp/cmp.c Normal file
View file

@ -0,0 +1,146 @@
/*
* Copyright (c) 1987, 1990, 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) 1987, 1990, 1993, 1994\n\
The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */
#ifndef lint
static char sccsid[] = "@(#)cmp.c 8.3 (Berkeley) 4/2/94";
#endif /* not lint */
#include <sys/types.h>
#include <sys/stat.h>
#include <err.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "extern.h"
int lflag, sflag;
static void usage __P((void));
int
main(argc, argv)
int argc;
char *argv[];
{
struct stat sb1, sb2;
off_t skip1, skip2;
int ch, fd1, fd2, special;
char *file1, *file2;
while ((ch = getopt(argc, argv, "-ls")) != EOF)
switch (ch) {
case 'l': /* print all differences */
lflag = 1;
break;
case 's': /* silent run */
sflag = 1;
break;
case '-': /* stdin (must be after options) */
--optind;
goto endargs;
case '?':
default:
usage();
}
endargs:
argv += optind;
argc -= optind;
if (lflag && sflag)
errx(ERR_EXIT, "only one of -l and -s may be specified");
if (argc < 2 || argc > 4)
usage();
/* Backward compatibility -- handle "-" meaning stdin. */
special = 0;
if (strcmp(file1 = argv[0], "-") == 0) {
special = 1;
fd1 = 0;
file1 = "stdin";
}
else if ((fd1 = open(file1, O_RDONLY, 0)) < 0)
err(ERR_EXIT, "%s", file1);
if (strcmp(file2 = argv[1], "-") == 0) {
if (special)
errx(ERR_EXIT,
"standard input may only be specified once");
special = 1;
fd2 = 0;
file2 = "stdin";
}
else if ((fd2 = open(file2, O_RDONLY, 0)) < 0)
err(ERR_EXIT, "%s", file2);
skip1 = argc > 2 ? strtol(argv[2], NULL, 10) : 0;
skip2 = argc == 4 ? strtol(argv[3], NULL, 10) : 0;
if (!special) {
if (fstat(fd1, &sb1))
err(ERR_EXIT, "%s", file1);
if (!S_ISREG(sb1.st_mode))
special = 1;
else {
if (fstat(fd2, &sb2))
err(ERR_EXIT, "%s", file2);
if (!S_ISREG(sb2.st_mode))
special = 1;
}
}
if (special)
c_special(fd1, file1, skip1, fd2, file2, skip2);
else
c_regular(fd1, file1, skip1, sb1.st_size,
fd2, file2, skip2, sb2.st_size);
exit(0);
}
static void
usage()
{
(void)fprintf(stderr,
"usage: cmp [-l | s] file1 file2 [skip1 [skip2]]\n");
exit(ERR_EXIT);
}

45
usr.bin/cmp/extern.h Normal file
View file

@ -0,0 +1,45 @@
/*-
* Copyright (c) 1991, 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.
*
* @(#)extern.h 8.3 (Berkeley) 4/2/94
*/
#define OK_EXIT 0
#define DIFF_EXIT 1
#define ERR_EXIT 2 /* error exit code */
void c_regular __P((int, char *, off_t, off_t, int, char *, off_t, off_t));
void c_special __P((int, char *, off_t, int, char *, off_t));
void diffmsg __P((char *, char *, off_t, off_t));
void eofmsg __P((char *));
extern int lflag, sflag;

64
usr.bin/cmp/misc.c Normal file
View file

@ -0,0 +1,64 @@
/*-
* Copyright (c) 1991, 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 sccsid[] = "@(#)misc.c 8.3 (Berkeley) 4/2/94";
#endif /* not lint */
#include <sys/types.h>
#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include "extern.h"
void
eofmsg(file)
char *file;
{
if (!sflag)
warnx("EOF on %s", file);
exit(DIFF_EXIT);
}
void
diffmsg(file1, file2, byte, line)
char *file1, *file2;
off_t byte, line;
{
if (!sflag)
(void)printf("%s %s differ: char %qd, line %qd\n",
file1, file2, byte, line);
exit(DIFF_EXIT);
}

98
usr.bin/cmp/regular.c Normal file
View file

@ -0,0 +1,98 @@
/*-
* Copyright (c) 1991, 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 sccsid[] = "@(#)regular.c 8.3 (Berkeley) 4/2/94";
#endif /* not lint */
#include <sys/param.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <err.h>
#include <limits.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "extern.h"
void
c_regular(fd1, file1, skip1, len1, fd2, file2, skip2, len2)
int fd1, fd2;
char *file1, *file2;
off_t skip1, len1, skip2, len2;
{
u_char ch, *p1, *p2;
off_t byte, length, line;
int dfound;
if (sflag && len1 != len2)
exit(1);
if (skip1 > len1)
eofmsg(file1);
len1 -= skip1;
if (skip2 > len2)
eofmsg(file2);
len2 -= skip2;
length = MIN(len1, len2);
if (length > SIZE_T_MAX)
return (c_special(fd1, file1, skip1, fd2, file2, skip2));
if ((p1 = (u_char *)mmap(NULL,
(size_t)length, PROT_READ, 0, fd1, skip1)) == (u_char *)-1)
err(ERR_EXIT, "%s", file1);
if ((p2 = (u_char *)mmap(NULL,
(size_t)length, PROT_READ, 0, fd2, skip2)) == (u_char *)-1)
err(ERR_EXIT, "%s", file2);
dfound = 0;
for (byte = line = 1; length--; ++p1, ++p2, ++byte) {
if ((ch = *p1) != *p2)
if (lflag) {
dfound = 1;
(void)printf("%6qd %3o %3o\n", byte, ch, *p2);
} else
diffmsg(file1, file2, byte, line);
/* NOTREACHED */
if (ch == '\n')
++line;
}
if (len1 != len2)
eofmsg (len1 > len2 ? file2 : file1);
if (dfound)
exit(DIFF_EXIT);
}

99
usr.bin/cmp/special.c Normal file
View file

@ -0,0 +1,99 @@
/*-
* Copyright (c) 1991, 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 sccsid[] = "@(#)special.c 8.3 (Berkeley) 4/2/94";
#endif /* not lint */
#include <sys/types.h>
#include <err.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "extern.h"
void
c_special(fd1, file1, skip1, fd2, file2, skip2)
int fd1, fd2;
char *file1, *file2;
off_t skip1, skip2;
{
int ch1, ch2;
off_t byte, line;
FILE *fp1, *fp2;
int dfound;
if ((fp1 = fdopen(fd1, "r")) == NULL)
err(ERR_EXIT, "%s", file1);
if ((fp2 = fdopen(fd2, "r")) == NULL)
err(ERR_EXIT, "%s", file2);
while (skip1--)
if (getc(fp1) == EOF)
goto eof;
while (skip2--)
if (getc(fp2) == EOF)
goto eof;
dfound = 0;
for (byte = line = 1;; ++byte) {
ch1 = getc(fp1);
ch2 = getc(fp2);
if (ch1 == EOF || ch2 == EOF)
break;
if (ch1 != ch2)
if (lflag) {
dfound = 1;
(void)printf("%6qd %3o %3o\n", byte, ch1, ch2);
} else
diffmsg(file1, file2, byte, line);
/* NOTREACHED */
if (ch1 == '\n')
++line;
}
eof: if (ferror(fp1))
err(ERR_EXIT, "%s", file1);
if (ferror(fp2))
err(ERR_EXIT, "%s", file2);
if (feof(fp1)) {
if (!feof(fp2))
eofmsg(file1);
} else
if (feof(fp2))
eofmsg(file2);
if (dfound)
exit(DIFF_EXIT);
}

5
usr.bin/col/Makefile Normal file
View file

@ -0,0 +1,5 @@
# @(#)Makefile 8.1 (Berkeley) 6/6/93
PROG= col
.include <bsd.prog.mk>

48
usr.bin/col/README Normal file
View file

@ -0,0 +1,48 @@
# @(#)README 8.1 (Berkeley) 6/6/93
col - filter out reverse line feeds.
Options are:
-b do not print any backspaces (last character written is printed)
-f allow half line feeds in output, by default characters between
lines are pushed to the line below
-x do not compress spaces into tabs.
-l num keep (at least) num lines in memory, 128 are kept by default
In the 32V source code to col(1) the default behavior was to NOT compress
spaces into tabs. There was a -h option which caused it to compress spaces
into tabs. There was no -x flag.
The 32V documentation, however, was consistent with the SVID (actually, V7
at the time) and documented a -x flag (as defined above) while making no
mention of a -h flag. Just before 4.3BSD went out, CSRG updated the manual
page to reflect the way the code worked. Suspecting that this was probably
the wrong way to go, this version adopts the SVID defaults, and no longer
documents the -h option.
The S5 -p flag is not supported because it isn't clear what it does (looks
like a kludge introduced for a particular printer).
Known differences between AT&T's col and this one (# is delimiter):
Input AT&T col this col
#\nabc\E7def\n# # def\nabc\r# # def\nabc\n#
#a# ## #a\n#
- last line always ends with at least one \n (or \E9)
#1234567 8\n# #1234567\t8\n# #1234567 8\n#
- single space not expanded to tab
-f #a\E8b\n# #ab\n# # b\E9\ra\n#
- can back up past first line (as far as you want) so you
*can* have a super script on the first line
#\E9_\ba\E8\nb\n# #\n_\bb\ba\n# #\n_\ba\bb\n#
- always print last character written to a position,
AT&T col claims to do this but doesn't.
If a character is to be placed on a line that has been flushed, a warning
is produced (the AT&T col is silent). The -l flag (not in AT&T col) can
be used to increase the number of lines buffered to avoid the problem.
General algorithm: a limited number of lines are buffered in a linked
list. When a printable character is read, it is put in the buffer of
the current line along with the column it's supposed to be in. When
a line is flushed, the characters in the line are sorted according to
column and then printed.

126
usr.bin/col/col.1 Normal file
View file

@ -0,0 +1,126 @@
.\" Copyright (c) 1990, 1993
.\" The Regents of the University of California. All rights reserved.
.\"
.\" This code is derived from software contributed to Berkeley by
.\" Michael Rendell.
.\"
.\" 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.
.\"
.\" @(#)col.1 8.1 (Berkeley) 6/29/93
.\"
.Dd June 29, 1993
.Dt COL 1
.Os
.Sh NAME
.Nm col
.Nd filter reverse line feeds from input
.Sh SYNOPSIS
.Nm col
.Op Fl bfx
.Op Fl l Ar num
.Sh DESCRIPTION
.Nm Col
filters out reverse (and half reverse) line feeds so that the output is
in the correct order with only forward and half forward line
feeds, and replaces white-space characters with tabs where possible.
This can be useful in processing the output of
.Xr nroff 1
and
.Xr tbl 1 .
.Pp
.Nm Col
reads from the standard input and writes to the standard output.
.Pp
The options are as follows:
.Bl -tag -width "-l num "
.It Fl b
Do not output any backspaces, printing only the last character
written to each column position.
.It Fl f
Forward half line feeds are permitted (``fine'' mode).
Normally characters printed on a half line boundary are printed
on the following line.
.It Fl x
Output multiple spaces instead of tabs.
.It Fl l Ar num
Buffer at least
.Ar num
lines in memory.
By default, 128 lines are buffered.
.El
.Pp
The control sequences for carriage motion that
.Nm col
understands and their decimal values are listed in the following
table:
.Pp
.Bl -tag -width "carriage return" -compact
.It ESC\-7
reverse line feed (escape then 7)
.It ESC\-8
half reverse line feed (escape then 8)
.It ESC\-9
half forward line feed (escape then 9)
.It backspace
moves back one column (8); ignored in the first column
.It carriage return
(13)
.It newline
forward line feed (10); also does carriage return
.It shift in
shift to normal character set (15)
.It shift out
shift to alternate character set (14)
.It space
moves forward one column (32)
.It tab
moves forward to next tab stop (9)
.It vertical tab
reverse line feed (11)
.El
.Pp
All unrecognized control characters and escape sequences are
discarded.
.Pp
.Nm Col
keeps track of the character set as characters are read and makes
sure the character set is correct when they are output.
.Pp
If the input attempts to back up to the last flushed line,
.Nm col
will display a warning message.
.Sh SEE ALSO
.Xr expand 1 ,
.Xr nroff 1 ,
.Xr tbl 1
.Sh HISTORY
A
.Nm col
command
appeared in Version 6 AT&T UNIX.

534
usr.bin/col/col.c Normal file
View file

@ -0,0 +1,534 @@
/*-
* Copyright (c) 1990, 1993, 1994
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Michael Rendell of the Memorial University of Newfoundland.
*
* 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) 1990, 1993, 1994\n\
The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */
#ifndef lint
static char sccsid[] = "@(#)col.c 8.3 (Berkeley) 4/2/94";
#endif /* not lint */
#include <ctype.h>
#include <err.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#define BS '\b' /* backspace */
#define TAB '\t' /* tab */
#define SPACE ' ' /* space */
#define NL '\n' /* newline */
#define CR '\r' /* carriage return */
#define ESC '\033' /* escape */
#define SI '\017' /* shift in to normal character set */
#define SO '\016' /* shift out to alternate character set */
#define VT '\013' /* vertical tab (aka reverse line feed) */
#define RLF '\007' /* ESC-07 reverse line feed */
#define RHLF '\010' /* ESC-010 reverse half-line feed */
#define FHLF '\011' /* ESC-011 forward half-line feed */
/* build up at least this many lines before flushing them out */
#define BUFFER_MARGIN 32
typedef char CSET;
typedef struct char_str {
#define CS_NORMAL 1
#define CS_ALTERNATE 2
short c_column; /* column character is in */
CSET c_set; /* character set (currently only 2) */
char c_char; /* character in question */
} CHAR;
typedef struct line_str LINE;
struct line_str {
CHAR *l_line; /* characters on the line */
LINE *l_prev; /* previous line */
LINE *l_next; /* next line */
int l_lsize; /* allocated sizeof l_line */
int l_line_len; /* strlen(l_line) */
int l_needs_sort; /* set if chars went in out of order */
int l_max_col; /* max column in the line */
};
LINE *alloc_line __P((void));
void dowarn __P((int));
void flush_line __P((LINE *));
void flush_lines __P((int));
void flush_blanks __P((void));
void free_line __P((LINE *));
void usage __P((void));
void wrerr __P((void));
void *xmalloc __P((void *, size_t));
CSET last_set; /* char_set of last char printed */
LINE *lines;
int compress_spaces; /* if doing space -> tab conversion */
int fine; /* if `fine' resolution (half lines) */
int max_bufd_lines; /* max # lines to keep in memory */
int nblank_lines; /* # blanks after last flushed line */
int no_backspaces; /* if not to output any backspaces */
#define PUTC(ch) \
if (putchar(ch) == EOF) \
wrerr();
int
main(argc, argv)
int argc;
char **argv;
{
int ch;
CHAR *c;
CSET cur_set; /* current character set */
LINE *l; /* current line */
int extra_lines; /* # of lines above first line */
int cur_col; /* current column */
int cur_line; /* line number of current position */
int max_line; /* max value of cur_line */
int this_line; /* line l points to */
int nflushd_lines; /* number of lines that were flushed */
int adjust, opt, warned;
max_bufd_lines = 128;
compress_spaces = 1; /* compress spaces into tabs */
while ((opt = getopt(argc, argv, "bfhl:x")) != EOF)
switch (opt) {
case 'b': /* do not output backspaces */
no_backspaces = 1;
break;
case 'f': /* allow half forward line feeds */
fine = 1;
break;
case 'h': /* compress spaces into tabs */
compress_spaces = 1;
break;
case 'l': /* buffered line count */
if ((max_bufd_lines = atoi(optarg)) <= 0) {
(void)fprintf(stderr,
"col: bad -l argument %s.\n", optarg);
exit(1);
}
break;
case 'x': /* do not compress spaces into tabs */
compress_spaces = 0;
break;
case '?':
default:
usage();
}
if (optind != argc)
usage();
/* this value is in half lines */
max_bufd_lines *= 2;
adjust = cur_col = extra_lines = warned = 0;
cur_line = max_line = nflushd_lines = this_line = 0;
cur_set = last_set = CS_NORMAL;
lines = l = alloc_line();
while ((ch = getchar()) != EOF) {
if (!isgraph(ch)) {
switch (ch) {
case BS: /* can't go back further */
if (cur_col == 0)
continue;
--cur_col;
continue;
case CR:
cur_col = 0;
continue;
case ESC: /* just ignore EOF */
switch(getchar()) {
case RLF:
cur_line -= 2;
break;
case RHLF:
cur_line--;
break;
case FHLF:
cur_line++;
if (cur_line > max_line)
max_line = cur_line;
}
continue;
case NL:
cur_line += 2;
if (cur_line > max_line)
max_line = cur_line;
cur_col = 0;
continue;
case SPACE:
++cur_col;
continue;
case SI:
cur_set = CS_NORMAL;
continue;
case SO:
cur_set = CS_ALTERNATE;
continue;
case TAB: /* adjust column */
cur_col |= 7;
++cur_col;
continue;
case VT:
cur_line -= 2;
continue;
}
continue;
}
/* Must stuff ch in a line - are we at the right one? */
if (cur_line != this_line - adjust) {
LINE *lnew;
int nmove;
adjust = 0;
nmove = cur_line - this_line;
if (!fine) {
/* round up to next line */
if (cur_line & 1) {
adjust = 1;
nmove++;
}
}
if (nmove < 0) {
for (; nmove < 0 && l->l_prev; nmove++)
l = l->l_prev;
if (nmove) {
if (nflushd_lines == 0) {
/*
* Allow backup past first
* line if nothing has been
* flushed yet.
*/
for (; nmove < 0; nmove++) {
lnew = alloc_line();
l->l_prev = lnew;
lnew->l_next = l;
l = lines = lnew;
extra_lines++;
}
} else {
if (!warned++)
dowarn(cur_line);
cur_line -= nmove;
}
}
} else {
/* may need to allocate here */
for (; nmove > 0 && l->l_next; nmove--)
l = l->l_next;
for (; nmove > 0; nmove--) {
lnew = alloc_line();
lnew->l_prev = l;
l->l_next = lnew;
l = lnew;
}
}
this_line = cur_line + adjust;
nmove = this_line - nflushd_lines;
if (nmove >= max_bufd_lines + BUFFER_MARGIN) {
nflushd_lines += nmove - max_bufd_lines;
flush_lines(nmove - max_bufd_lines);
}
}
/* grow line's buffer? */
if (l->l_line_len + 1 >= l->l_lsize) {
int need;
need = l->l_lsize ? l->l_lsize * 2 : 90;
l->l_line = (CHAR *)xmalloc((void *) l->l_line,
(unsigned) need * sizeof(CHAR));
l->l_lsize = need;
}
c = &l->l_line[l->l_line_len++];
c->c_char = ch;
c->c_set = cur_set;
c->c_column = cur_col;
/*
* If things are put in out of order, they will need sorting
* when it is flushed.
*/
if (cur_col < l->l_max_col)
l->l_needs_sort = 1;
else
l->l_max_col = cur_col;
cur_col++;
}
/* goto the last line that had a character on it */
for (; l->l_next; l = l->l_next)
this_line++;
flush_lines(this_line - nflushd_lines + extra_lines + 1);
/* make sure we leave things in a sane state */
if (last_set != CS_NORMAL)
PUTC('\017');
/* flush out the last few blank lines */
nblank_lines = max_line - this_line;
if (max_line & 1)
nblank_lines++;
else if (!nblank_lines)
/* missing a \n on the last line? */
nblank_lines = 2;
flush_blanks();
exit(0);
}
void
flush_lines(nflush)
int nflush;
{
LINE *l;
while (--nflush >= 0) {
l = lines;
lines = l->l_next;
if (l->l_line) {
flush_blanks();
flush_line(l);
}
nblank_lines++;
if (l->l_line)
(void)free((void *)l->l_line);
free_line(l);
}
if (lines)
lines->l_prev = NULL;
}
/*
* Print a number of newline/half newlines. If fine flag is set, nblank_lines
* is the number of half line feeds, otherwise it is the number of whole line
* feeds.
*/
void
flush_blanks()
{
int half, i, nb;
half = 0;
nb = nblank_lines;
if (nb & 1) {
if (fine)
half = 1;
else
nb++;
}
nb /= 2;
for (i = nb; --i >= 0;)
PUTC('\n');
if (half) {
PUTC('\033');
PUTC('9');
if (!nb)
PUTC('\r');
}
nblank_lines = 0;
}
/*
* Write a line to stdout taking care of space to tab conversion (-h flag)
* and character set shifts.
*/
void
flush_line(l)
LINE *l;
{
CHAR *c, *endc;
int nchars, last_col, this_col;
last_col = 0;
nchars = l->l_line_len;
if (l->l_needs_sort) {
static CHAR *sorted;
static int count_size, *count, i, save, sorted_size, tot;
/*
* Do an O(n) sort on l->l_line by column being careful to
* preserve the order of characters in the same column.
*/
if (l->l_lsize > sorted_size) {
sorted_size = l->l_lsize;
sorted = (CHAR *)xmalloc((void *)sorted,
(unsigned)sizeof(CHAR) * sorted_size);
}
if (l->l_max_col >= count_size) {
count_size = l->l_max_col + 1;
count = (int *)xmalloc((void *)count,
(unsigned)sizeof(int) * count_size);
}
memset((char *)count, 0, sizeof(int) * l->l_max_col + 1);
for (i = nchars, c = l->l_line; --i >= 0; c++)
count[c->c_column]++;
/*
* calculate running total (shifted down by 1) to use as
* indices into new line.
*/
for (tot = 0, i = 0; i <= l->l_max_col; i++) {
save = count[i];
count[i] = tot;
tot += save;
}
for (i = nchars, c = l->l_line; --i >= 0; c++)
sorted[count[c->c_column]++] = *c;
c = sorted;
} else
c = l->l_line;
while (nchars > 0) {
this_col = c->c_column;
endc = c;
do {
++endc;
} while (--nchars > 0 && this_col == endc->c_column);
/* if -b only print last character */
if (no_backspaces)
c = endc - 1;
if (this_col > last_col) {
int nspace = this_col - last_col;
if (compress_spaces && nspace > 1) {
int ntabs;
ntabs = this_col / 8 - last_col / 8;
nspace -= ntabs * 8;
while (--ntabs >= 0)
PUTC('\t');
}
while (--nspace >= 0)
PUTC(' ');
last_col = this_col;
}
last_col++;
for (;;) {
if (c->c_set != last_set) {
switch (c->c_set) {
case CS_NORMAL:
PUTC('\017');
break;
case CS_ALTERNATE:
PUTC('\016');
}
last_set = c->c_set;
}
PUTC(c->c_char);
if (++c >= endc)
break;
PUTC('\b');
}
}
}
#define NALLOC 64
static LINE *line_freelist;
LINE *
alloc_line()
{
LINE *l;
int i;
if (!line_freelist) {
l = (LINE *)xmalloc((void *)NULL, sizeof(LINE) * NALLOC);
line_freelist = l;
for (i = 1; i < NALLOC; i++, l++)
l->l_next = l + 1;
l->l_next = NULL;
}
l = line_freelist;
line_freelist = l->l_next;
memset(l, 0, sizeof(LINE));
return (l);
}
void
free_line(l)
LINE *l;
{
l->l_next = line_freelist;
line_freelist = l;
}
void *
xmalloc(p, size)
void *p;
size_t size;
{
if (!(p = (void *)realloc(p, size)))
err(1, NULL);
return (p);
}
void
usage()
{
(void)fprintf(stderr, "usage: col [-bfx] [-l nline]\n");
exit(1);
}
void
wrerr()
{
(void)fprintf(stderr, "col: write error.\n");
exit(1);
}
void
dowarn(line)
int line;
{
warnx("warning: can't back up %s",
line < 0 ? "past first line" : "-- line already flushed");
}

Some files were not shown because too many files have changed in this diff Show more