Delete usr.bin directory
This commit is contained in:
parent
a96803a698
commit
6598721502
|
|
@ -1,84 +0,0 @@
|
|||
# $NetBSD: Makefile,v 1.221 2015/06/03 14:32:16 christos Exp $
|
||||
# from: @(#)Makefile 8.3 (Berkeley) 1/7/94
|
||||
|
||||
.include <bsd.own.mk>
|
||||
|
||||
SUBDIR= asa \
|
||||
banner basename \
|
||||
bzip2 bzip2recover cal calendar \
|
||||
checknr chpass cksum cmp col colcrt colrm \
|
||||
column comm csplit ctags cut \
|
||||
deroff dirname du \
|
||||
env expand \
|
||||
false find finger flock fold fmt fpr from \
|
||||
fsplit ftp genassym gencat getent \
|
||||
getopt \
|
||||
head hexdump id indent infocmp ipcrm ipcs join jot \
|
||||
lam last ldd leave \
|
||||
locale lock logger login logname lorder m4 \
|
||||
machine make man menuc mesg \
|
||||
mkcsmapper mkdep mkesdb mkfifo mklocale mkstr mktemp \
|
||||
msgc \
|
||||
nbperf netstat newgrp nice nl nohup \
|
||||
pagesize passwd paste patch pathchk pr \
|
||||
printenv printf pwhash \
|
||||
renice rev rsh \
|
||||
\
|
||||
sdiff sed seq shar shlock \
|
||||
shuffle sort split stat su \
|
||||
tail tee telnet tic time touch \
|
||||
tput \
|
||||
tr true tsort tty ul uname unexpand unifdef \
|
||||
uniq units unvis unzip users \
|
||||
uudecode uuencode uuidgen vis \
|
||||
w \
|
||||
wall wc what whereis who whois \
|
||||
write xargs xinstall xstr yes
|
||||
|
||||
.if !defined(__MINIX)
|
||||
SUBDIR+= ../external/zlib/pigz/bin/pigz
|
||||
.endif # defined(__MINIX)
|
||||
|
||||
.if (${MKGROFF} == "no") || defined(__MINIX)
|
||||
SUBDIR+= soelim
|
||||
.endif
|
||||
|
||||
.if (${MKMAKEMANDB} == "no") || defined(__MINIX)
|
||||
SUBDIR+= apropos whatis
|
||||
.endif
|
||||
|
||||
.if (${MKRUMP} != "no")
|
||||
SUBDIR+= rump_allserver rump_dhcpclient rump_halt rump_server shmif_dumpbus \
|
||||
rump_wmd
|
||||
.endif
|
||||
|
||||
.if (${MKBSDGREP} != "no")
|
||||
SUBDIR+= grep
|
||||
.endif
|
||||
|
||||
.if (${MKPIGZGZIP} != "no")
|
||||
# nothing
|
||||
.else
|
||||
SUBDIR+= gzip
|
||||
.endif
|
||||
|
||||
.if (${MKHESIOD} != "no")
|
||||
SUBDIR+= hesinfo
|
||||
.endif
|
||||
|
||||
.if (${MKSKEY} != "no")
|
||||
SUBDIR+= skey skeyinfo skeyinit
|
||||
.endif
|
||||
|
||||
.if (${MKYP} != "no")
|
||||
SUBDIR+= ypcat ypmatch ypwhich
|
||||
.endif
|
||||
|
||||
.if (${MKCRYPTO} != "no")
|
||||
SUBDIR+= bdes
|
||||
.if !defined(__MINIX)
|
||||
SUBDIR+= nbsvtool
|
||||
.endif # defined(__MINIX)
|
||||
.endif
|
||||
|
||||
.include <bsd.subdir.mk>
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
# $NetBSD: Makefile.inc,v 1.10 2012/03/21 05:47:53 matt Exp $
|
||||
# from: @(#)Makefile.inc 8.1 (Berkeley) 6/6/93
|
||||
|
||||
WARNS?= 5
|
||||
BINDIR?=/usr/bin
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
# $NetBSD: Makefile,v 1.13 2009/04/14 22:15:17 lukem Exp $
|
||||
# @(#)Makefile 8.1 (Berkeley) 6/6/93
|
||||
|
||||
.include <bsd.own.mk>
|
||||
|
||||
MDIST= ${NETBSDSRCDIR}/usr.bin/man
|
||||
|
||||
PROG= apropos
|
||||
SRCS= apropos.c manconf.c
|
||||
|
||||
.PATH: ${MDIST}
|
||||
CPPFLAGS+=-I${MDIST}
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
|
|
@ -1,140 +0,0 @@
|
|||
.\" $NetBSD: apropos.1,v 1.11 2009/05/08 12:48:43 wiz Exp $
|
||||
.\"
|
||||
.\" 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. 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 May 7, 2009
|
||||
.Dt APROPOS 1
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm apropos
|
||||
.Nd locate commands by keyword lookup
|
||||
.Sh SYNOPSIS
|
||||
.Nm apropos
|
||||
.Op Fl C Ar path
|
||||
.Op Fl M Ar path
|
||||
.Op Fl m Ar path
|
||||
.Op Fl S Ar subsection
|
||||
.Op Fl s Ar section
|
||||
.Ar keyword ...
|
||||
.Sh DESCRIPTION
|
||||
.Nm
|
||||
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
|
||||
will also list all instances of
|
||||
.Dq compiler .
|
||||
.Pp
|
||||
If the line output by
|
||||
.Nm
|
||||
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 C
|
||||
Use different
|
||||
.Xr man 1
|
||||
configuration file than the default,
|
||||
.Pa /etc/man.conf .
|
||||
.It Fl M
|
||||
Override the list of standard directories
|
||||
.Nm
|
||||
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
|
||||
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.
|
||||
.It Fl S Ar subsection
|
||||
Restrict the search to pages for the specified machine architecture.
|
||||
By default, pages for all architectures are shown.
|
||||
.It Fl s Ar section
|
||||
Restrict the search to the specified section of the manual.
|
||||
By default, pages from all sections are shown.
|
||||
.El
|
||||
.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 /etc/man.conf1 -compact
|
||||
.It Pa whatis.db
|
||||
name of the apropos database
|
||||
.It Pa /etc/man.conf
|
||||
.Xr man 1
|
||||
configuration file, used to get location of whatis database if
|
||||
.Ev MANPATH
|
||||
is not set.
|
||||
.El
|
||||
.Sh SEE ALSO
|
||||
.Xr man 1 ,
|
||||
.Xr whatis 1 ,
|
||||
.Xr whereis 1 ,
|
||||
.Xr man.conf 5 ,
|
||||
.Xr makewhatis 8
|
||||
.Sh HISTORY
|
||||
The
|
||||
.Nm
|
||||
command appeared in
|
||||
.Bx 3.0 .
|
||||
|
|
@ -1,277 +0,0 @@
|
|||
/* $NetBSD: apropos.c,v 1.30 2009/05/08 12:48:43 wiz Exp $ */
|
||||
|
||||
/*
|
||||
* 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. 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.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
#ifndef lint
|
||||
__COPYRIGHT("@(#) Copyright (c) 1987, 1993, 1994\
|
||||
The Regents of the University of California. All rights reserved.");
|
||||
#endif /* not lint */
|
||||
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)apropos.c 8.8 (Berkeley) 5/4/95";
|
||||
#else
|
||||
__RCSID("$NetBSD: apropos.c,v 1.30 2009/05/08 12:48:43 wiz Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/queue.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <err.h>
|
||||
#include <glob.h>
|
||||
#include <limits.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "manconf.h" /* from ../man/ */
|
||||
#include "pathnames.h" /* from ../man/ */
|
||||
|
||||
static bool *found;
|
||||
static bool foundman = false;
|
||||
|
||||
#define MAXLINELEN 8192 /* max line handled */
|
||||
|
||||
static void apropos(char **, const char *, bool, const char *, const char *);
|
||||
static void lowstr(const char *, char *);
|
||||
static bool match(const char *, const char *);
|
||||
static void usage(void) __dead;
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
ENTRY *ep;
|
||||
TAG *tp;
|
||||
int ch, rv;
|
||||
char *conffile, *machine, **p, *p_augment, *p_path, *sflag;
|
||||
glob_t pg;
|
||||
|
||||
conffile = NULL;
|
||||
p_augment = p_path = NULL;
|
||||
machine = sflag = NULL;
|
||||
while ((ch = getopt(argc, argv, "C:M:m:P:S:s:")) != -1) {
|
||||
switch (ch) {
|
||||
case 'C':
|
||||
conffile = optarg;
|
||||
break;
|
||||
case 'M':
|
||||
case 'P': /* backward compatible */
|
||||
p_path = optarg;
|
||||
break;
|
||||
case 'm':
|
||||
p_augment = optarg;
|
||||
break;
|
||||
case 'S':
|
||||
machine = optarg;
|
||||
lowstr(machine, machine);
|
||||
break;
|
||||
case 's':
|
||||
sflag = optarg;
|
||||
lowstr(sflag, sflag);
|
||||
break;
|
||||
case '?':
|
||||
default:
|
||||
usage();
|
||||
}
|
||||
}
|
||||
argv += optind;
|
||||
argc -= optind;
|
||||
|
||||
if (argc < 1)
|
||||
usage();
|
||||
|
||||
if ((found = malloc(argc * sizeof(*found))) == NULL)
|
||||
err(EXIT_FAILURE, "malloc");
|
||||
(void)memset(found, 0, argc * sizeof(*found));
|
||||
|
||||
for (p = argv; *p; ++p) /* convert to lower-case */
|
||||
lowstr(*p, *p);
|
||||
|
||||
if (p_augment)
|
||||
apropos(argv, p_augment, true, sflag, machine);
|
||||
if (p_path || (p_path = getenv("MANPATH")))
|
||||
apropos(argv, p_path, true, sflag, machine);
|
||||
else {
|
||||
config(conffile);
|
||||
tp = gettag("_whatdb", 1);
|
||||
if (!tp)
|
||||
errx(EXIT_FAILURE, "malloc");
|
||||
TAILQ_FOREACH(ep, &tp->entrylist, q) {
|
||||
if ((rv = glob(ep->s, GLOB_BRACE | GLOB_NOSORT, NULL,
|
||||
&pg)) != 0) {
|
||||
if (rv == GLOB_NOMATCH)
|
||||
continue;
|
||||
else
|
||||
err(EXIT_FAILURE, "glob");
|
||||
}
|
||||
if (pg.gl_pathc)
|
||||
for (p = pg.gl_pathv; *p; p++)
|
||||
apropos(argv, *p, false, sflag,
|
||||
machine);
|
||||
globfree(&pg);
|
||||
}
|
||||
}
|
||||
|
||||
if (!foundman)
|
||||
errx(EXIT_FAILURE, "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);
|
||||
return rv;
|
||||
}
|
||||
|
||||
static void
|
||||
apropos(char **argv, const char *path, bool buildpath,
|
||||
const char *sflag, const char *machine)
|
||||
{
|
||||
char *end, **p;
|
||||
const char *name;
|
||||
char buf[MAXLINELEN + 1];
|
||||
char hold[MAXPATHLEN + 1];
|
||||
char wbuf[MAXLINELEN + 1];
|
||||
size_t slen = 0, mlen = 0;
|
||||
|
||||
if (sflag)
|
||||
slen = strlen(sflag);
|
||||
if (machine)
|
||||
mlen = strlen(machine);
|
||||
|
||||
for (name = path; name; name = end) { /* through name list */
|
||||
if ((end = strchr(name, ':')) != NULL)
|
||||
*end++ = '\0';
|
||||
|
||||
if (buildpath) {
|
||||
(void)snprintf(hold, sizeof(hold), "%s/%s", name,
|
||||
_PATH_WHATIS);
|
||||
name = hold;
|
||||
}
|
||||
|
||||
if (!freopen(name, "r", stdin))
|
||||
continue;
|
||||
|
||||
foundman = true;
|
||||
|
||||
/* for each file found */
|
||||
while (fgets(buf, (int)sizeof(buf), stdin)) {
|
||||
if (!strchr(buf, '\n')) {
|
||||
warnx("%s: line too long", name);
|
||||
continue;
|
||||
}
|
||||
lowstr(buf, wbuf);
|
||||
if (machine) {
|
||||
if ((strncmp(wbuf, machine, mlen) != 0) ||
|
||||
strlen(wbuf) <= mlen || wbuf[mlen] != '/')
|
||||
continue;
|
||||
}
|
||||
if (sflag) {
|
||||
char *s = strchr(wbuf, '(');
|
||||
|
||||
if (!s)
|
||||
continue;
|
||||
if (strncmp(s+1, sflag, slen) != 0)
|
||||
continue;
|
||||
}
|
||||
for (p = argv; *p; ++p) {
|
||||
if (match(wbuf, *p)) {
|
||||
(void)printf("%s", buf);
|
||||
found[p - argv] = true;
|
||||
|
||||
/* only print line once */
|
||||
while (*++p)
|
||||
if (match(wbuf, *p))
|
||||
found[p - argv] = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* match --
|
||||
* match anywhere the string appears
|
||||
*/
|
||||
static bool
|
||||
match(const char *bp, const char *str)
|
||||
{
|
||||
size_t len;
|
||||
char test;
|
||||
|
||||
if (!*bp)
|
||||
return false;
|
||||
/* backward compatible: everything matches empty string */
|
||||
if (!*str)
|
||||
return true;
|
||||
for (test = *str++, len = strlen(str); *bp;)
|
||||
if (test == *bp++ && !strncmp(bp, str, len))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* lowstr --
|
||||
* convert a string to lower case
|
||||
*/
|
||||
static void
|
||||
lowstr(const char *from, char *to)
|
||||
{
|
||||
char ch;
|
||||
|
||||
while ((ch = *from++) && ch != '\n')
|
||||
*to++ = tolower((unsigned char)ch);
|
||||
*to = '\0';
|
||||
}
|
||||
|
||||
/*
|
||||
* usage --
|
||||
* print usage message and die
|
||||
*/
|
||||
__dead
|
||||
static void
|
||||
usage(void)
|
||||
{
|
||||
|
||||
(void)fprintf(stderr,
|
||||
"usage: %s [-C file] [-M path] [-m path] "
|
||||
"[-S subsection] [-s section]\n"
|
||||
" keyword ...\n",
|
||||
getprogname());
|
||||
exit(1);
|
||||
}
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
# $NetBSD: Makefile,v 1.5 2009/04/14 22:15:17 lukem Exp $
|
||||
|
||||
PROG= asa
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
|
|
@ -1,86 +0,0 @@
|
|||
.\" $NetBSD: asa.1,v 1.12 2014/04/13 01:45:34 snj Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 1993 Winning Strategies, Inc.
|
||||
.\" 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 Winning Strategies, Inc.
|
||||
.\" 4. The name of the author may not be used to endorse or promote products
|
||||
.\" derived from this software without specific prior written permission
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
.\"
|
||||
.Dd September 23, 1993
|
||||
.Dt ASA 1
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm asa
|
||||
.Nd interpret carriage-control characters
|
||||
.Sh SYNOPSIS
|
||||
.Nm
|
||||
.Op Ar
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Nm
|
||||
utility reads files sequentially, mapping
|
||||
.Tn FORTRAN
|
||||
carriage-control characters to line-printer control sequences,
|
||||
and writes them to the standard output.
|
||||
.Pp
|
||||
The first character of each line is interpreted as a carriage-control
|
||||
character. The following characters are interpreted as follows:
|
||||
.Bl -tag -width "\*[Lt]space\*[Gt]"
|
||||
.It \*[Lt]space\*[Gt]
|
||||
Output the rest of the line without change.
|
||||
.It 0
|
||||
Output a \*[Lt]newline\*[Gt] character before printing the rest of the line.
|
||||
.It 1
|
||||
Output a \*[Lt]formfeed\*[Gt] character before printing the rest of the line.
|
||||
.It +
|
||||
The trailing \*[Lt]newline\*[Gt] of the previous line is replaced by a \*[Lt]carriage-return\*[Gt]
|
||||
before printing the rest of the line.
|
||||
.El
|
||||
.Pp
|
||||
Lines beginning with characters other than the above are treated as if they
|
||||
begin with \*[Lt]space\*[Gt].
|
||||
.Sh EXIT STATUS
|
||||
.Ex -std
|
||||
.Sh EXAMPLES
|
||||
To view a file containing the output of a
|
||||
.Tn FORTRAN
|
||||
program:
|
||||
.Dl asa file
|
||||
.Pp
|
||||
To format the output of a
|
||||
.Tn FORTRAN
|
||||
program and redirect it to a line-printer:
|
||||
.Dl a.out | asa | lpr
|
||||
.Sh SEE ALSO
|
||||
.Xr f77 1
|
||||
.Sh STANDARDS
|
||||
The
|
||||
.Nm
|
||||
utility conforms to
|
||||
.St -p1003.2-92
|
||||
and to
|
||||
.St -xcu5 .
|
||||
.Sh AUTHORS
|
||||
J.T. Conklin, Winning Strategies, Inc.
|
||||
|
|
@ -1,117 +0,0 @@
|
|||
/* $NetBSD: asa.c,v 1.16 2007/06/24 23:23:10 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1993,94 Winning Strategies, Inc.
|
||||
* 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 Winning Strategies, Inc.
|
||||
* 4. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
__RCSID("$NetBSD: asa.c,v 1.16 2007/06/24 23:23:10 christos Exp $");
|
||||
#endif
|
||||
|
||||
#include <err.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
static void asa(FILE *);
|
||||
int main(int, char *[]);
|
||||
|
||||
int
|
||||
/*ARGSUSED*/
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
FILE *fp;
|
||||
|
||||
/* skip progname */
|
||||
argv++;
|
||||
|
||||
if (*argv == NULL)
|
||||
asa(stdin);
|
||||
else
|
||||
do {
|
||||
if ((fp = fopen(*argv, "r")) == NULL) {
|
||||
warn("%s", *argv);
|
||||
continue;
|
||||
}
|
||||
asa(fp);
|
||||
(void)fclose(fp);
|
||||
} while (*++argv != NULL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
asa(FILE *f)
|
||||
{
|
||||
char *buf;
|
||||
size_t len;
|
||||
|
||||
if ((buf = fgetln(f, &len)) != NULL) {
|
||||
if (len > 0 && buf[len - 1] == '\n')
|
||||
buf[--len] = '\0';
|
||||
/* special case the first line */
|
||||
switch (buf[0]) {
|
||||
case '0':
|
||||
(void)putchar('\n');
|
||||
break;
|
||||
case '1':
|
||||
(void)putchar('\f');
|
||||
break;
|
||||
}
|
||||
|
||||
if (len > 1 && buf[0] && buf[1])
|
||||
(void)fwrite(buf + 1, 1, len - 1, stdout);
|
||||
|
||||
while ((buf = fgetln(f, &len)) != NULL) {
|
||||
if (len > 0 && buf[len - 1] == '\n')
|
||||
buf[--len] = '\0';
|
||||
switch (buf[0]) {
|
||||
default:
|
||||
case ' ':
|
||||
(void)putchar('\n');
|
||||
break;
|
||||
case '0':
|
||||
(void)putchar('\n');
|
||||
(void)putchar('\n');
|
||||
break;
|
||||
case '1':
|
||||
(void)putchar('\f');
|
||||
break;
|
||||
case '+':
|
||||
(void)putchar('\r');
|
||||
break;
|
||||
}
|
||||
|
||||
if (len > 1 && buf[0] && buf[1])
|
||||
(void)fwrite(buf + 1, 1, len - 1, stdout);
|
||||
}
|
||||
|
||||
(void)putchar('\n');
|
||||
}
|
||||
}
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
# $NetBSD: Makefile,v 1.4 2009/04/14 22:15:17 lukem Exp $
|
||||
|
||||
PROG= banner
|
||||
|
||||
SRCS= $(PROG).c chset.c
|
||||
|
||||
# if you want to make chars from the letter involved (like lpd), then
|
||||
# un-comment the following.
|
||||
#CPPFLAGS+= -DNOHASH_ONLY
|
||||
|
||||
# if you want to use the same char set that lpd uses then un-comment
|
||||
# the following. Lpd uses a much nicer character set but banner
|
||||
# output will not be the same as the real thing.
|
||||
#CPPFLAGS+= -DLPD_CHSET
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
|
||||
|
|
@ -1,63 +0,0 @@
|
|||
.\" $NetBSD: banner.1,v 1.9 2012/02/29 08:54:55 wiz Exp $
|
||||
.\"
|
||||
.\" @(#)Copyright (c) 1995, Simon J. Gerraty.
|
||||
.\"
|
||||
.\" This is free software. It comes with NO WARRANTY.
|
||||
.\" Permission to use, modify and distribute this source code
|
||||
.\" is granted subject to the following conditions.
|
||||
.\" 1/ that the above copyright notice and this notice
|
||||
.\" are preserved in all copies and that due credit be given
|
||||
.\" to the author.
|
||||
.\" 2/ that any changes to this code are clearly commented
|
||||
.\" as such so that the author does not get blamed for bugs
|
||||
.\" other than his own.
|
||||
.\"
|
||||
.\" Please send copies of changes and bug-fixes to:
|
||||
.\" sjg@zen.void.oz.au
|
||||
.\"
|
||||
.Dd February 26, 2012
|
||||
.Dt BANNER 1
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm banner
|
||||
.Nd print strings in large letters
|
||||
.Sh SYNOPSIS
|
||||
.Nm
|
||||
.Op Fl l
|
||||
.Op Fl b Ar bg
|
||||
.Op Fl f Ar fg
|
||||
.Ar string ...
|
||||
.Sh DESCRIPTION
|
||||
.Nm
|
||||
prints up to 10 chars of each
|
||||
.Ar string
|
||||
in large letters on the standard output.
|
||||
.Pp
|
||||
The options are:
|
||||
.Bl -tag -width Ds
|
||||
.It Fl b Ar bg
|
||||
Use
|
||||
.Ar bg
|
||||
as the background color (character) rather than the default
|
||||
.Dq \ .
|
||||
.It Fl f Ar fg
|
||||
Use
|
||||
.Ar fg
|
||||
as the foreground color (character) rather than the default
|
||||
.Dq # .
|
||||
If
|
||||
.Ar fg
|
||||
is
|
||||
.Dq - ,
|
||||
then the actual letter being printed is used as the
|
||||
foreground color in the same way that LPD does it.
|
||||
The results are quite variable.
|
||||
.It Fl l
|
||||
Use the more attractive LPD font instead of the traditional
|
||||
.Nm
|
||||
font.
|
||||
.El
|
||||
.Sh EXIT STATUS
|
||||
.Ex -std
|
||||
.Sh SEE ALSO
|
||||
.Xr banner 6
|
||||
|
|
@ -1,211 +0,0 @@
|
|||
/* $NetBSD: banner.c,v 1.15 2012/02/29 08:55:25 wiz Exp $ */
|
||||
|
||||
/*
|
||||
* Changes for banner(1)
|
||||
*
|
||||
* @(#)Copyright (c) 1995, Simon J. Gerraty.
|
||||
*
|
||||
* This is free software. It comes with NO WARRANTY.
|
||||
* Permission to use, modify and distribute this source code
|
||||
* is granted subject to the following conditions.
|
||||
* 1/ that the above copyright notice and this notice
|
||||
* are preserved in all copies and that due credit be given
|
||||
* to the author.
|
||||
* 2/ that any changes to this code are clearly commented
|
||||
* as such so that the author does not get blamed for bugs
|
||||
* other than his own.
|
||||
*
|
||||
* Please send copies of changes and bug-fixes to:
|
||||
* sjg@zen.void.oz.au
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 1983, 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. 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.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
__COPYRIGHT("@(#) Copyright (c) 1983, 1993\
|
||||
The Regents of the University of California. All rights reserved.");
|
||||
#endif /* not lint */
|
||||
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)printjob.c 8.2 (Berkeley) 4/16/94";
|
||||
#else
|
||||
__RCSID("$NetBSD: banner.c,v 1.15 2012/02/29 08:55:25 wiz Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "banner.h"
|
||||
|
||||
static long PW = LINELEN;
|
||||
/*
|
||||
* <sjg> lpd makes chars out of the letter in question.
|
||||
* the results are somewhat mixed. Sticking to '#' as
|
||||
* banner(1) does is more consistent.
|
||||
*/
|
||||
static int ForeGnd = '#';
|
||||
static int BackGnd = ' ';
|
||||
static int Drop = 0; /* 3 for the LPD font */
|
||||
|
||||
static int dropit (int);
|
||||
static void scan_out (int, char *, int);
|
||||
static char *scnline (int, char *, int);
|
||||
__dead static void usage(void);
|
||||
|
||||
/* the char gen code below is lifted from lpd */
|
||||
|
||||
static char *
|
||||
scnline(int key, char *p, int c)
|
||||
{
|
||||
int scnwidth;
|
||||
|
||||
if (ForeGnd)
|
||||
c = ForeGnd;
|
||||
|
||||
for (scnwidth = WIDTH; --scnwidth;) {
|
||||
key <<= 1;
|
||||
*p++ = key & 0200 ? c : BackGnd;
|
||||
}
|
||||
return (p);
|
||||
}
|
||||
|
||||
#define TRC(q) (((q)-' ')&0177)
|
||||
|
||||
|
||||
static int
|
||||
dropit(int c)
|
||||
{
|
||||
switch(c) {
|
||||
|
||||
case TRC('_'):
|
||||
case TRC(';'):
|
||||
case TRC(','):
|
||||
case TRC('g'):
|
||||
case TRC('j'):
|
||||
case TRC('p'):
|
||||
case TRC('q'):
|
||||
case TRC('y'):
|
||||
return (Drop);
|
||||
|
||||
default:
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
scan_out(int scfd, char *scsp, int dlm)
|
||||
{
|
||||
char *strp;
|
||||
int nchrs, j;
|
||||
char outbuf[LINELEN+1], *sp, c, cc;
|
||||
int d, scnhgt;
|
||||
|
||||
for (scnhgt = 0; scnhgt++ < HEIGHT+Drop; ) {
|
||||
strp = &outbuf[0];
|
||||
if (BackGnd != ' ')
|
||||
*strp++ = BackGnd;
|
||||
sp = scsp;
|
||||
for (nchrs = 0; *sp != dlm && *sp != '\0'; ) {
|
||||
cc = *sp++;
|
||||
if(cc < ' ' || ((int)cc) >= 0x7f)
|
||||
cc = ' ';
|
||||
d = dropit(c = TRC(cc));
|
||||
if ((!d && scnhgt > HEIGHT) || (scnhgt <= Drop && d))
|
||||
for (j = WIDTH; --j;)
|
||||
*strp++ = BackGnd;
|
||||
else if (Drop == 0)
|
||||
strp = scnline(
|
||||
scnkey_def[(int)c][scnhgt-1-d], strp, cc);
|
||||
else
|
||||
strp = scnline(
|
||||
scnkey_lpd[(int)c][scnhgt-1-d], strp, cc);
|
||||
if (nchrs++ >= PW/(WIDTH+1)-1)
|
||||
break;
|
||||
*strp++ = BackGnd;
|
||||
}
|
||||
if (BackGnd != ' ')
|
||||
*strp++ = BackGnd;
|
||||
else {
|
||||
while (*--strp == ' ' && strp >= outbuf)
|
||||
;
|
||||
strp++;
|
||||
}
|
||||
*strp++ = '\n';
|
||||
(void) write(scfd, outbuf, strp-outbuf);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* for each word, print up to 10 chars in big letters.
|
||||
*/
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
char word[10+1]; /* strings limited to 10 chars */
|
||||
int c;
|
||||
|
||||
while ((c = getopt(argc, argv, "b:f:l")) != -1) {
|
||||
switch (c) {
|
||||
case 'f':
|
||||
if (*optarg == '-')
|
||||
ForeGnd = 0;
|
||||
else
|
||||
ForeGnd = *optarg;
|
||||
break;
|
||||
case 'b':
|
||||
BackGnd = *optarg;
|
||||
break;
|
||||
case 'l':
|
||||
Drop = 3; /* for LPD font */
|
||||
break;
|
||||
default:
|
||||
usage();
|
||||
}
|
||||
}
|
||||
|
||||
for (; optind < argc; ++optind) {
|
||||
(void)strlcpy(word, argv[optind], sizeof (word));
|
||||
scan_out(STDOUT_FILENO, word, '\0');
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
|
||||
static void
|
||||
usage(void)
|
||||
{
|
||||
fprintf(stderr, "usage: %s [-l] [-b bg] [-f fg] string ...\n",
|
||||
getprogname());
|
||||
exit(1);
|
||||
}
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
/* $NetBSD: banner.h,v 1.4 2000/10/04 19:33:16 mjl Exp $ */
|
||||
|
||||
/*
|
||||
* Various defines needed for code lifted from lpd.
|
||||
*
|
||||
* @(#)Copyright (c) 1995, Simon J. Gerraty.
|
||||
*
|
||||
* This is free software. It comes with NO WARRANTY.
|
||||
* Permission to use, modify and distribute this source code
|
||||
* is granted subject to the following conditions.
|
||||
* 1/ that the above copyright notice and this notice
|
||||
* are preserved in all copies and that due credit be given
|
||||
* to the author.
|
||||
* 2/ that any changes to this code are clearly commented
|
||||
* as such so that the author does not get blamed for bugs
|
||||
* other than his own.
|
||||
*
|
||||
* Please send copies of changes and bug-fixes to:
|
||||
* sjg@zen.void.oz.au
|
||||
*/
|
||||
|
||||
#define LINELEN 132
|
||||
#define BACKGND ' '
|
||||
#define HEIGHT 9 /* height of characters */
|
||||
#define WIDTH 8 /* width of characters */
|
||||
|
||||
extern const char scnkey_lpd[][HEIGHT];
|
||||
extern const char scnkey_def[][HEIGHT];
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -1,7 +0,0 @@
|
|||
# $NetBSD: Makefile,v 1.6 2009/04/14 22:15:17 lukem Exp $
|
||||
# @(#)Makefile 8.1 (Berkeley) 6/6/93
|
||||
|
||||
PROG= basename
|
||||
MLINKS= basename.1 dirname.1
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
|
|
@ -1,92 +0,0 @@
|
|||
.\" $NetBSD: basename.1,v 1.17 2003/09/06 20:56:40 kleink Exp $
|
||||
.\"
|
||||
.\" 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. 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 ,
|
||||
.Nm dirname
|
||||
.Nd return filename or directory portion of pathname
|
||||
.Sh SYNOPSIS
|
||||
.Nm
|
||||
.Ar string
|
||||
.Op Ar suffix
|
||||
.Nm dirname
|
||||
.Ar string
|
||||
.Sh DESCRIPTION
|
||||
.Nm
|
||||
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.
|
||||
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 EXIT STATUS
|
||||
Both the
|
||||
.Nm
|
||||
and
|
||||
.Nm dirname
|
||||
utilities
|
||||
exit 0 on success, and \*[Gt]0 if an error occurs.
|
||||
.Sh EXAMPLES
|
||||
The following line sets the shell variable
|
||||
.Ev FOO
|
||||
to
|
||||
.Pa /usr/bin .
|
||||
.Pp
|
||||
.Dl FOO=`dirname /usr/bin/trail`
|
||||
.Sh SEE ALSO
|
||||
.Xr csh 1 ,
|
||||
.Xr sh 1 ,
|
||||
.Xr basename 3 ,
|
||||
.Xr dirname 3
|
||||
.Sh STANDARDS
|
||||
The
|
||||
.Nm
|
||||
and
|
||||
.Nm dirname
|
||||
utilities conform to
|
||||
.St -p1003.2-92 .
|
||||
|
|
@ -1,103 +0,0 @@
|
|||
/* $NetBSD: basename.c,v 1.15 2011/08/29 14:24:03 joerg Exp $ */
|
||||
|
||||
/*-
|
||||
* 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. 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.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
__COPYRIGHT("@(#) Copyright (c) 1991, 1993, 1994\
|
||||
The Regents of the University of California. All rights reserved.");
|
||||
#endif /* not lint */
|
||||
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)basename.c 8.4 (Berkeley) 5/4/95";
|
||||
#endif
|
||||
__RCSID("$NetBSD: basename.c,v 1.15 2011/08/29 14:24:03 joerg Exp $");
|
||||
#endif /* not lint */
|
||||
|
||||
#include <err.h>
|
||||
#include <libgen.h>
|
||||
#include <locale.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
__dead static void usage(void);
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
char *p;
|
||||
int ch;
|
||||
|
||||
setlocale(LC_ALL, "");
|
||||
|
||||
while ((ch = getopt(argc, argv, "")) != -1)
|
||||
switch (ch) {
|
||||
case '?':
|
||||
default:
|
||||
usage();
|
||||
}
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
if (argc != 1 && argc != 2)
|
||||
usage();
|
||||
|
||||
if (**argv == '\0') {
|
||||
(void)printf("\n");
|
||||
exit(0);
|
||||
}
|
||||
if ((p = basename(*argv)) == NULL)
|
||||
err(1, "%s", *argv);
|
||||
if (*++argv != '\0') {
|
||||
int suffixlen, stringlen, off;
|
||||
|
||||
suffixlen = strlen(*argv);
|
||||
stringlen = strlen(p);
|
||||
|
||||
if (suffixlen < stringlen) {
|
||||
off = stringlen - suffixlen;
|
||||
if (strcmp(p + off, *argv) == 0)
|
||||
p[off] = '\0';
|
||||
}
|
||||
}
|
||||
(void)printf("%s\n", p);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
static void
|
||||
usage(void)
|
||||
{
|
||||
|
||||
(void)fprintf(stderr, "usage: basename string [suffix]\n");
|
||||
exit(1);
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
# $NetBSD: Makefile,v 1.8 2013/08/11 06:47:38 dholland Exp $
|
||||
# @(#)Makefile 8.1 (Berkeley) 6/6/93
|
||||
|
||||
USE_FORT?= yes # cryptographic software
|
||||
|
||||
PROG= bdes
|
||||
|
||||
LDADD+= -lcrypt
|
||||
DPADD+= ${LIBCRYPT}
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
|
|
@ -1,366 +0,0 @@
|
|||
.\" $NetBSD: bdes.1,v 1.14 2010/01/15 19:40:17 joerg Exp $
|
||||
.\"
|
||||
.\" 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. 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
|
||||
.\"
|
||||
.Dd December 1, 2001
|
||||
.Dt BDES 1
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm bdes
|
||||
.Nd encrypt/decrypt using the Data Encryption Standard
|
||||
.Sh SYNOPSIS
|
||||
.Nm
|
||||
.Op Fl abdp
|
||||
.Op Fl F Ar N
|
||||
.Op Fl f Ar N
|
||||
.Op Fl k Ar key
|
||||
.Op Fl m Ar N
|
||||
.Op Fl o Ar N
|
||||
.Op Fl v Ar vector
|
||||
.Sh DESCRIPTION
|
||||
.Nm
|
||||
implements all DES modes of operation described in FIPS PUB 81,
|
||||
including alternative cipher feedback mode and both authentication
|
||||
modes.
|
||||
.Nm
|
||||
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
|
||||
.Ar key
|
||||
is specified on the command line, the user is prompted for one (see
|
||||
.Xr getpass 3
|
||||
for more details).
|
||||
.Pp
|
||||
The options are as follows:
|
||||
.Bl -tag -width "-v vector" -compact
|
||||
.It Fl a
|
||||
The key and initialization vector strings are to be taken as ASCII,
|
||||
suppressing the special interpretation given to leading
|
||||
.Dq 0X ,
|
||||
.Dq 0x ,
|
||||
.Dq 0B ,
|
||||
and
|
||||
.Dq 0b
|
||||
characters.
|
||||
This flag applies to
|
||||
.Em both
|
||||
the key and initialization vector.
|
||||
.It Fl b
|
||||
Use electronic code book mode.
|
||||
This is not recommended for messages
|
||||
longer than 8 bytes, as patterns in the input will show through to the
|
||||
output.
|
||||
.It Fl d
|
||||
Decrypt the input.
|
||||
.It Fl F Ar N
|
||||
Use
|
||||
.Ar N Ns -bit
|
||||
alternative cipher feedback mode.
|
||||
Currently
|
||||
.Ar N
|
||||
must be a multiple of 7 between 7 and 56 inclusive (this does not conform
|
||||
to the alternative CFB mode specification).
|
||||
.It Fl f Ar N
|
||||
Use
|
||||
.Ar N Ns -bit
|
||||
cipher feedback mode.
|
||||
Currently
|
||||
.Ar N
|
||||
must be a multiple of 8 between 8 and 64 inclusive (this does not conform
|
||||
to the standard CFB mode specification).
|
||||
.It Fl k Ar key
|
||||
Use
|
||||
.Ar key
|
||||
as the cryptographic key.
|
||||
.It Fl m Ar N
|
||||
Compute a message authentication code (MAC) of
|
||||
.Ar N
|
||||
bits on the input.
|
||||
The value of
|
||||
.Ar N
|
||||
must be between 1 and 64 inclusive; if
|
||||
.Ar 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.
|
||||
.It Fl o Ar N
|
||||
Use
|
||||
.Ar N Ns -bit
|
||||
output feedback mode.
|
||||
Currently
|
||||
.Ar N
|
||||
must be a multiple of 8 between 8 and 64 inclusive (this does not conform
|
||||
to the OFB mode specification).
|
||||
.It Fl 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.
|
||||
.It Fl v Ar vector
|
||||
Set the initialization vector to
|
||||
.Ar vector ;
|
||||
the vector is interpreted in the same way as the key.
|
||||
The vector is ignored in electronic codebook mode.
|
||||
For best security, a different
|
||||
initialization vector should be used for each file.
|
||||
.El
|
||||
.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
|
||||
.Dq 0X
|
||||
or
|
||||
.Dq 0x ,
|
||||
that one is taken as a sequence of hexadecimal digits indicating the
|
||||
bit pattern;
|
||||
if either begins with
|
||||
.Dq 0B
|
||||
or
|
||||
.Dq 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
|
||||
.if t 2\u\s-356\s0\d
|
||||
.if n 2**56
|
||||
to
|
||||
.if t 2\u\s-348\s0\d
|
||||
.if n 2**48
|
||||
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
|
||||
.Em 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 hobbled by a short
|
||||
key, 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 practical cryptanalytic methods for breaking the
|
||||
DES are known in the open literature.
|
||||
As of this writing, the best
|
||||
known cryptanalytic method is linear cryptanalysis, which requires an
|
||||
average of
|
||||
.if t 2\u\s-343\s0\d
|
||||
.if n 2**43
|
||||
known plaintext-ciphertext pairs to succeed.
|
||||
Unfortunately for the DES, key search attacks (requiring only
|
||||
a single known plaintext-ciphertext pair and trying
|
||||
.if t 2\u\s-355\s0\d
|
||||
.if n 2**55
|
||||
keys on average) are becoming practical.
|
||||
.Pp
|
||||
As with all cryptosystems, the choice of keys and
|
||||
key security remain the most vulnerable aspect of
|
||||
.Nm .
|
||||
.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,
|
||||
.Nm
|
||||
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
|
||||
.Em 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,
|
||||
.Nm
|
||||
does too, but this may be changed from the command line.
|
||||
.Sh SEE ALSO
|
||||
.Xr crypt 3 ,
|
||||
.Xr getpass 3
|
||||
.Rs
|
||||
.%T Data Encryption Standard
|
||||
.%R Federal Information Processing Standard #46
|
||||
.%Q National Bureau of Standards, U.S. Department of Commerce
|
||||
.\" should be .%C as soon as it's supported.
|
||||
.%O Washington DC
|
||||
.%D January 1977
|
||||
.Re
|
||||
.Rs
|
||||
.%T DES Modes of Operation
|
||||
.%R Federal Information Processing Standard #81
|
||||
.%Q National Bureau of Standards, U.S. Department of Commerce
|
||||
.\" should be .%C as soon as it's supported.
|
||||
.%O Washington DC
|
||||
.%D December 1980
|
||||
.Re
|
||||
.Rs
|
||||
.%A Dorothy Denning
|
||||
.%T Cryptography and Data Security
|
||||
.%I Addison-Wesley Publishing Co.
|
||||
.\" should be .%C as soon as it's supported.
|
||||
.%O Reading, MA
|
||||
.%D 1982
|
||||
.Re
|
||||
.Rs
|
||||
.%A Matt Bishop
|
||||
.%T Implementation Notes on bdes(1)
|
||||
.%R Technical Report PCS-TR-91-158
|
||||
.%Q Department of Mathematics and Computer Science, Dartmouth College
|
||||
.\" should be .%C as soon as it's supported.
|
||||
.%O Hanover, NH 03755
|
||||
.%D April 1991
|
||||
.Re
|
||||
.Rs
|
||||
.%A M.J. Wiener
|
||||
.%T Efficient DES Key Search
|
||||
.%R Technical Report 244
|
||||
.%Q School of Computer Science, Carleton University
|
||||
.%D May 1994
|
||||
.Re
|
||||
.Rs
|
||||
.%A Bruce Schneier
|
||||
.%T Applied Cryptography (2nd edition)
|
||||
.%I John Wiley \*[Am] Sons, Inc.
|
||||
.%O New York, NY
|
||||
.\" should be .%C as soon as it's supported.
|
||||
.%D 1996
|
||||
.Re
|
||||
.Rs
|
||||
.%A M. Matsui
|
||||
.%T Linear Cryptanalysis Method for DES Cipher
|
||||
.%R Advances in Cryptology -- Eurocrypt '93 Proceedings
|
||||
.%I Springer-Verlag
|
||||
.%D 1994
|
||||
.Re
|
||||
.Rs
|
||||
.%A Blaze
|
||||
.%A Diffie
|
||||
.%A Rivest
|
||||
.%A Schneier
|
||||
.%A Shimomura
|
||||
.%A Thompson
|
||||
.%A Wiener
|
||||
.%T Minimal Key Lengths for Symmetric Ciphers To Provide Adequate Commercial Security
|
||||
.%I Business Software Alliance
|
||||
.%U http://www.bsa.org/policy/encryption/cryptographers.html
|
||||
.%D January 1996
|
||||
.Re
|
||||
.Sh BUGS
|
||||
When this document was originally written, there was a controversy
|
||||
raging over whether the DES would still be secure in a few years.
|
||||
There is now near-universal consensus in the cryptographic community
|
||||
that the key length of the DES is far too short.
|
||||
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; in addition, the explosive growth in the number and speed
|
||||
of modern microprocessors as well as advances in programmable logic
|
||||
devices has brought an attack using only commodity hardware into the
|
||||
realm of possibility.
|
||||
Schneier and others currently recommend using
|
||||
cryptosystems with keys of at least 90 bits when long-term security is
|
||||
needed.
|
||||
.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
|
||||
.Nm
|
||||
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
|
||||
.Em weak
|
||||
and
|
||||
.Em semiweak
|
||||
keys, are (in hex notation, where p is either 0 or 1, and P is either
|
||||
e or f):
|
||||
.Bd -literal -offset indent
|
||||
0x0p0p0p0p0p0p0p0p 0x0p1P0p1P0p0P0p0P
|
||||
0x0pep0pep0pfp0pfp 0x0pfP0pfP0pfP0pfP
|
||||
0x1P0p1P0p0P0p0P0p 0x1P1P1P1P0P0P0P0P
|
||||
0x1Pep1Pep0Pfp0Pfp 0x1PfP1PfP0PfP0PfP
|
||||
0xep0pep0pfp0pfp0p 0xep1Pep1pfp0Pfp0P
|
||||
0xepepepepepepepep 0xepfPepfPfpfPfpfP
|
||||
0xfP0pfP0pfP0pfP0p 0xfP1PfP1PfP0PfP0P
|
||||
0xfPepfPepfPepfPep 0xfPfPfPfPfPfPfPfP
|
||||
.Ed
|
||||
.Pp
|
||||
This is inherent in the DES algorithm (see Moore and Simmons,
|
||||
.Do
|
||||
Cycle structure of the DES with weak and semi-weak keys
|
||||
.Dc ,
|
||||
.Em "Advances in Cryptology \- Crypto '86 Proceedings" ,
|
||||
Springer-Verlag New York, \(co1987, pp. 9-32.)
|
||||
1076
usr.bin/bdes/bdes.c
1076
usr.bin/bdes/bdes.c
File diff suppressed because it is too large
Load Diff
|
|
@ -1,30 +0,0 @@
|
|||
# $NetBSD: Makefile,v 1.12 2012/05/07 08:51:47 wiz Exp $
|
||||
|
||||
.include <bsd.own.mk> # for MKDYNAMICROOT definition
|
||||
|
||||
USE_FORT?= yes # data-driven bugs?
|
||||
|
||||
|
||||
PROG= bzip2
|
||||
LDDIR!= cd ${NETBSDSRCDIR}/lib/libbz2 && ${PRINTOBJDIR}
|
||||
LDADD+= -L${LDDIR} -lbz2
|
||||
DPADD+= ${LIBBZ2}
|
||||
|
||||
.if (${MKDYNAMICROOT} == "no")
|
||||
LDSTATIC?= -static
|
||||
.endif
|
||||
.ifdef SMALLPROG
|
||||
CPPFLAGS+= -DSMALL
|
||||
.endif
|
||||
|
||||
DIST= ${NETBSDSRCDIR}/external/bsd/bzip2/dist
|
||||
.PATH: ${DIST}
|
||||
|
||||
MLINKS+= bzip2.1 bunzip2.1\
|
||||
bzip2.1 bzcat.1\
|
||||
bzip2.1 bzip2recover.1
|
||||
|
||||
LINKS+= ${BINDIR}/bzip2 ${BINDIR}/bunzip2
|
||||
LINKS+= ${BINDIR}/bzip2 ${BINDIR}/bzcat
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
# $NetBSD: Makefile,v 1.10 2012/05/07 08:51:48 wiz Exp $
|
||||
|
||||
USE_FORT?= yes # data-driven bugs?
|
||||
NOMAN= # defined
|
||||
|
||||
.include <bsd.own.mk> # for MKDYNAMICROOT definition
|
||||
|
||||
PROG= bzip2recover
|
||||
|
||||
.if (${MKDYNAMICROOT} == "no")
|
||||
LDSTATIC?= -static
|
||||
.endif
|
||||
|
||||
DIST= ${NETBSDSRCDIR}/external/bsd/bzip2/dist
|
||||
.PATH: ${DIST}
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
# $NetBSD: Makefile,v 1.5 2010/02/03 15:34:45 roy Exp $
|
||||
# @(#)Makefile 8.1 (Berkeley) 6/6/93
|
||||
|
||||
PROG= cal
|
||||
LDADD+= -lterminfo
|
||||
DPADD+= ${LIBTERMINFO}
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
|
|
@ -1,42 +0,0 @@
|
|||
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.
|
||||
|
|
@ -1,165 +0,0 @@
|
|||
.\" $NetBSD: cal.1,v 1.21 2015/01/08 03:56:33 christos Exp $
|
||||
.\"
|
||||
.\" 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. 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.2 (Berkeley) 4/28/95
|
||||
.\"
|
||||
.Dd January 7, 2015
|
||||
.Dt CAL 1
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm cal
|
||||
.Nd displays a calendar
|
||||
.Sh SYNOPSIS
|
||||
.Nm
|
||||
.Op Fl 3hjry
|
||||
.Op Fl A Ar after
|
||||
.Op Fl B Ar before
|
||||
.Op Fl C Ar context
|
||||
.Op Fl d Ar day-of-week
|
||||
.Op Fl R Ar reform-spec
|
||||
.Op Oo Ar month Oc Ar year
|
||||
.Sh DESCRIPTION
|
||||
.Nm
|
||||
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 3
|
||||
Same as
|
||||
.Dq Fl A Ar 1 Fl B Ar 1 .
|
||||
.It Fl A Ar after
|
||||
Display
|
||||
.Ar after
|
||||
months after the specified month.
|
||||
.It Fl B Ar before
|
||||
Display
|
||||
.Ar before
|
||||
months before the specified month.
|
||||
.It Fl C Ar context
|
||||
Display
|
||||
.Ar context
|
||||
months before and after the specified month.
|
||||
.It Fl d Ar day-of-week
|
||||
Specifies the day of the week on which the calendar should start.
|
||||
Valid values are 0 through 6, presenting Sunday through Saturday,
|
||||
inclusively.
|
||||
The default output starts on Sundays.
|
||||
.It Fl h
|
||||
Highlight the current day, if present in the displayed calendar.
|
||||
If output is to a terminal, then the appropriate terminal sequences
|
||||
are used, otherwise overstriking is used.
|
||||
If more than one
|
||||
.Fl h
|
||||
is used and output is to a terminal, the current date will be
|
||||
highlighted in inverse video instead of bold.
|
||||
.It Fl j
|
||||
Display Julian dates (days one-based, numbered from January 1).
|
||||
.It Fl R Ar reform-spec
|
||||
Selects an alternate Gregorian reform point from the default of
|
||||
September 3rd, 1752.
|
||||
The
|
||||
.Ar reform-spec
|
||||
can be selected by one of the built-in names (see
|
||||
.Sx NOTES
|
||||
for a list) or by a date of the form YYYY/MM/DD.
|
||||
The date and month may be omitted, provided that what is specified
|
||||
uniquely selects a given built-in reform point.
|
||||
If an exact date is specified, then that date is taken to be the first
|
||||
missing date of the Gregorian Reform to be applied.
|
||||
.It Fl r
|
||||
Display the month in which the Gregorian Reform adjustment was
|
||||
applied, if no other
|
||||
.Ar month
|
||||
or
|
||||
.Ar year
|
||||
information is given.
|
||||
If used in conjunction with
|
||||
.Fl y ,
|
||||
then the entire year is displayed.
|
||||
.It Fl y
|
||||
Display a calendar for the current year.
|
||||
.El
|
||||
.Pp
|
||||
If no parameters are specified, the current month's calendar is
|
||||
displayed.
|
||||
A single parameter specifies the year and optionally the month
|
||||
in ISO format:
|
||||
.Dq Li cal 2007-12
|
||||
Two parameters denote the month (1 - 12) and year.
|
||||
Note that the century must be included in the year.
|
||||
.Pp
|
||||
A year starts on Jan 1.
|
||||
.Sh NOTES
|
||||
In the USA and Great Britain the Gregorian Reformation occurred in 1752.
|
||||
By this time, most countries had recognized the reformation (although a
|
||||
few did not recognize it until the 1900's.)
|
||||
Eleven days following September 2, 1752 were eliminated by the reformation,
|
||||
so the calendar for that month is a bit unusual.
|
||||
.Pp
|
||||
In view of the chaotic way the Gregorian calendar was adopted throughout
|
||||
the world in the years between 1582 and 1928 make sure to take into account
|
||||
the date of the Gregorian Reformation in your region if you are checking a
|
||||
calendar for a very old date.
|
||||
.Pp
|
||||
.Nm
|
||||
has a decent built-in list of Gregorian Reform dates and the names of
|
||||
the countries where the reform was adopted:
|
||||
.Pp
|
||||
.Bd -literal
|
||||
Italy Oct. 5, 1582 Denmark Feb. 19, 1700
|
||||
Spain Oct. 5, 1582 Great Britain Sep. 3, 1752
|
||||
Portugal Oct. 5, 1582 Sweden Feb. 18, 1753
|
||||
Poland Oct. 5, 1582 Finland Feb. 18, 1753
|
||||
France Dec. 12, 1582 Japan Dec. 20, 1872
|
||||
Luxembourg Dec. 22, 1582 China Nov. 7, 1911
|
||||
Netherlands Dec. 22, 1582 Bulgaria Apr. 1, 1916
|
||||
Bavaria Oct. 6, 1583 U.S.S.R. Feb. 1, 1918
|
||||
Austria Jan. 7, 1584 Serbia Jan. 19, 1919
|
||||
Switzerland Jan. 12, 1584 Romania Jan. 19, 1919
|
||||
Hungary Oct. 22, 1587 Greece Mar. 10, 1924
|
||||
Germany Feb. 19, 1700 Turkey Dec. 19, 1925
|
||||
Norway Feb. 19, 1700 Egypt Sep. 18, 1928
|
||||
.Ed
|
||||
.Pp
|
||||
The country known as
|
||||
.Em Great Britain
|
||||
can also be referred to as
|
||||
.Em England
|
||||
since that has less letters and no spaces in it.
|
||||
This is meant only as a measure of expediency, not as a possible
|
||||
slight to anyone involved.
|
||||
.Sh HISTORY
|
||||
A
|
||||
.Nm
|
||||
command appeared in
|
||||
.At v6 .
|
||||
|
|
@ -1,924 +0,0 @@
|
|||
/* $NetBSD: cal.c,v 1.29 2015/06/16 22:54:10 christos Exp $ */
|
||||
|
||||
/*
|
||||
* 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. 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.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
__COPYRIGHT("@(#) Copyright (c) 1989, 1993, 1994\
|
||||
The Regents of the University of California. All rights reserved.");
|
||||
#endif /* not lint */
|
||||
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)cal.c 8.4 (Berkeley) 4/2/94";
|
||||
#else
|
||||
__RCSID("$NetBSD: cal.c,v 1.29 2015/06/16 22:54:10 christos Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <term.h>
|
||||
#include <time.h>
|
||||
#include <tzfile.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define SATURDAY 6 /* 1 Jan 1 was a Saturday */
|
||||
|
||||
#define FIRST_MISSING_DAY reform->first_missing_day
|
||||
#define NUMBER_MISSING_DAYS reform->missing_days
|
||||
|
||||
#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},
|
||||
};
|
||||
|
||||
static int 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,
|
||||
};
|
||||
static int shift_days[2][4][MAXDAYS + 1];
|
||||
|
||||
static const char *month_names[12] = {
|
||||
"January", "February", "March", "April", "May", "June",
|
||||
"July", "August", "September", "October", "November", "December",
|
||||
};
|
||||
|
||||
static const char *day_headings = " S M Tu W Th F S";
|
||||
static const char *j_day_headings = " S M Tu W Th F S";
|
||||
|
||||
/* leap years according to the julian calendar */
|
||||
#define j_leap_year(y, m, d) \
|
||||
(((m) > 2) && \
|
||||
!((y) % 4))
|
||||
|
||||
/* leap years according to the gregorian calendar */
|
||||
#define g_leap_year(y, m, d) \
|
||||
(((m) > 2) && \
|
||||
((!((y) % 4) && ((y) % 100)) || \
|
||||
!((y) % 400)))
|
||||
|
||||
/* leap year -- account for gregorian reformation at some point */
|
||||
#define leap_year(yr) \
|
||||
((yr) <= reform->year ? j_leap_year((yr), 3, 1) : \
|
||||
g_leap_year((yr), 3, 1))
|
||||
|
||||
/* number of julian leap days that have passed by a given date */
|
||||
#define j_leap_days(y, m, d) \
|
||||
((((y) - 1) / 4) + j_leap_year(y, m, d))
|
||||
|
||||
/* number of gregorian leap days that have passed by a given date */
|
||||
#define g_leap_days(y, m, d) \
|
||||
((((y) - 1) / 4) - (((y) - 1) / 100) + (((y) - 1) / 400) + \
|
||||
g_leap_year(y, m, d))
|
||||
|
||||
/*
|
||||
* Subtracting the gregorian leap day count (for a given date) from
|
||||
* the julian leap day count (for the same date) describes the number
|
||||
* of days from the date before the shift to the next date that
|
||||
* appears in the calendar. Since we want to know the number of
|
||||
* *missing* days, not the number of days that the shift spans, we
|
||||
* subtract 2.
|
||||
*
|
||||
* Alternately...
|
||||
*
|
||||
* There's a reason they call the Dark ages the Dark Ages. Part of it
|
||||
* is that we don't have that many records of that period of time.
|
||||
* One of the reasons for this is that a lot of the Dark Ages never
|
||||
* actually took place. At some point in the first millenium A.D., a
|
||||
* ruler of some power decided that he wanted the number of the year
|
||||
* to be different than what it was, so he changed it to coincide
|
||||
* nicely with some event (a birthday or anniversary, perhaps a
|
||||
* wedding, or maybe a centennial for a largish city). One of the
|
||||
* side effects of this upon the Gregorian reform is that two Julian
|
||||
* leap years (leap days celebrated during centennial years that are
|
||||
* not quatro-centennial years) were skipped.
|
||||
*/
|
||||
#define GREGORIAN_MAGIC 2
|
||||
|
||||
/* number of centuries since the reform, not inclusive */
|
||||
#define centuries_since_reform(yr) \
|
||||
((yr) > reform->year ? ((yr) / 100) - (reform->year / 100) : 0)
|
||||
|
||||
/* number of centuries since the reform whose modulo of 400 is 0 */
|
||||
#define quad_centuries_since_reform(yr) \
|
||||
((yr) > reform->year ? ((yr) / 400) - (reform->year / 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_reform(yr) + quad_centuries_since_reform(yr))
|
||||
|
||||
static struct reform {
|
||||
const char *country;
|
||||
int ambiguity, year, month, date;
|
||||
long first_missing_day;
|
||||
int missing_days;
|
||||
/*
|
||||
* That's 2 for standard/julian display, 4 for months possibly
|
||||
* affected by the Gregorian shift, and MAXDAYS + 1 for the
|
||||
* days that get displayed, plus a crib slot.
|
||||
*/
|
||||
} *reform, reforms[] = {
|
||||
{ "DEFAULT", 0, 1752, 9, 3, 0, 0 },
|
||||
{ "Italy", 1, 1582, 10, 5, 0, 0 },
|
||||
{ "Spain", 1, 1582, 10, 5, 0, 0 },
|
||||
{ "Portugal", 1, 1582, 10, 5, 0, 0 },
|
||||
{ "Poland", 1, 1582, 10, 5, 0, 0 },
|
||||
{ "France", 2, 1582, 12, 10, 0, 0 },
|
||||
{ "Luxembourg", 2, 1582, 12, 22, 0, 0 },
|
||||
{ "Netherlands", 2, 1582, 12, 22, 0, 0 },
|
||||
{ "Bavaria", 0, 1583, 10, 6, 0, 0 },
|
||||
{ "Austria", 2, 1584, 1, 7, 0, 0 },
|
||||
{ "Switzerland", 2, 1584, 1, 12, 0, 0 },
|
||||
{ "Hungary", 0, 1587, 10, 22, 0, 0 },
|
||||
{ "Germany", 0, 1700, 2, 19, 0, 0 },
|
||||
{ "Norway", 0, 1700, 2, 19, 0, 0 },
|
||||
{ "Denmark", 0, 1700, 2, 19, 0, 0 },
|
||||
{ "Great Britain", 0, 1752, 9, 3, 0, 0 },
|
||||
{ "England", 0, 1752, 9, 3, 0, 0 },
|
||||
{ "America", 0, 1752, 9, 3, 0, 0 },
|
||||
{ "Sweden", 0, 1753, 2, 18, 0, 0 },
|
||||
{ "Finland", 0, 1753, 2, 18, 0, 0 },
|
||||
{ "Japan", 0, 1872, 12, 20, 0, 0 },
|
||||
{ "China", 0, 1911, 11, 7, 0, 0 },
|
||||
{ "Bulgaria", 0, 1916, 4, 1, 0, 0 },
|
||||
{ "U.S.S.R.", 0, 1918, 2, 1, 0, 0 },
|
||||
{ "Serbia", 0, 1919, 1, 19, 0, 0 },
|
||||
{ "Romania", 0, 1919, 1, 19, 0, 0 },
|
||||
{ "Greece", 0, 1924, 3, 10, 0, 0 },
|
||||
{ "Turkey", 0, 1925, 12, 19, 0, 0 },
|
||||
{ "Egypt", 0, 1928, 9, 18, 0, 0 },
|
||||
{ NULL, 0, 0, 0, 0, 0, 0 },
|
||||
};
|
||||
|
||||
static int julian;
|
||||
static int dow;
|
||||
static int hilite;
|
||||
static const char *md, *me;
|
||||
|
||||
static void init_hilite(void);
|
||||
static int getnum(const char *);
|
||||
static void gregorian_reform(const char *);
|
||||
static void reform_day_array(int, int, int *, int *, int *,int *,int *,int *);
|
||||
static int ascii_day(char *, int);
|
||||
static void center(const char *, int, int);
|
||||
static void day_array(int, int, int *);
|
||||
static int day_in_week(int, int, int);
|
||||
static int day_in_year(int, int, int);
|
||||
static void monthrange(int, int, int, int, int);
|
||||
static void trim_trailing_spaces(char *);
|
||||
__dead static void usage(void);
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
struct tm *local_time;
|
||||
time_t now;
|
||||
int ch, yflag;
|
||||
long month, year;
|
||||
int before, after, use_reform;
|
||||
int yearly = 0;
|
||||
char *when, *eoi;
|
||||
|
||||
before = after = 0;
|
||||
use_reform = yflag = year = 0;
|
||||
when = NULL;
|
||||
while ((ch = getopt(argc, argv, "A:B:C:d:hjR:ry3")) != -1) {
|
||||
switch (ch) {
|
||||
case 'A':
|
||||
after = getnum(optarg);
|
||||
if (after < 0)
|
||||
errx(1, "Argument to -A must be positive");
|
||||
break;
|
||||
case 'B':
|
||||
before = getnum(optarg);
|
||||
if (before < 0)
|
||||
errx(1, "Argument to -B must be positive");
|
||||
break;
|
||||
case 'C':
|
||||
after = before = getnum(optarg);
|
||||
if (after < 0)
|
||||
errx(1, "Argument to -C must be positive");
|
||||
break;
|
||||
case 'd':
|
||||
dow = getnum(optarg);
|
||||
if (dow < 0 || dow > 6)
|
||||
errx(1, "illegal day of week value: use 0-6");
|
||||
break;
|
||||
case 'h':
|
||||
init_hilite();
|
||||
break;
|
||||
case 'j':
|
||||
julian = 1;
|
||||
break;
|
||||
case 'R':
|
||||
when = optarg;
|
||||
break;
|
||||
case 'r':
|
||||
use_reform = 1;
|
||||
break;
|
||||
case 'y':
|
||||
yflag = 1;
|
||||
break;
|
||||
case '3':
|
||||
before = after = 1;
|
||||
break;
|
||||
case '?':
|
||||
default:
|
||||
usage();
|
||||
/* NOTREACHED */
|
||||
}
|
||||
}
|
||||
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
if (when != NULL)
|
||||
gregorian_reform(when);
|
||||
if (reform == NULL)
|
||||
gregorian_reform("DEFAULT");
|
||||
|
||||
month = 0;
|
||||
switch (argc) {
|
||||
case 2:
|
||||
month = strtol(*argv++, &eoi, 10);
|
||||
if (month < 1 || month > 12 || *eoi != '\0')
|
||||
errx(1, "illegal month value: use 1-12");
|
||||
year = strtol(*argv, &eoi, 10);
|
||||
if (year < 1 || year > 9999 || *eoi != '\0')
|
||||
errx(1, "illegal year value: use 1-9999");
|
||||
break;
|
||||
case 1:
|
||||
year = strtol(*argv, &eoi, 10);
|
||||
if (year < 1 || year > 9999 || (*eoi != '\0' && *eoi != '/' && *eoi != '-'))
|
||||
errx(1, "illegal year value: use 1-9999");
|
||||
if (*eoi != '\0') {
|
||||
month = strtol(eoi + 1, &eoi, 10);
|
||||
if (month < 1 || month > 12 || *eoi != '\0')
|
||||
errx(1, "illegal month value: use 1-12");
|
||||
}
|
||||
break;
|
||||
case 0:
|
||||
(void)time(&now);
|
||||
local_time = localtime(&now);
|
||||
if (use_reform)
|
||||
year = reform->year;
|
||||
else
|
||||
year = local_time->tm_year + TM_YEAR_BASE;
|
||||
if (!yflag) {
|
||||
if (use_reform)
|
||||
month = reform->month;
|
||||
else
|
||||
month = local_time->tm_mon + 1;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
usage();
|
||||
}
|
||||
|
||||
if (!month) {
|
||||
/* yearly */
|
||||
month = 1;
|
||||
before = 0;
|
||||
after = 11;
|
||||
yearly = 1;
|
||||
}
|
||||
|
||||
monthrange(month, year, before, after, yearly);
|
||||
|
||||
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
|
||||
#define MONTH_PER_ROW 3 /* how many monthes in a row */
|
||||
#define J_MONTH_PER_ROW 2
|
||||
|
||||
static void
|
||||
monthrange(int month, int year, int before, int after, int yearly)
|
||||
{
|
||||
int startmonth, startyear;
|
||||
int endmonth, endyear;
|
||||
int i, row;
|
||||
int days[3][MAXDAYS];
|
||||
char lineout[256];
|
||||
int inayear;
|
||||
int newyear;
|
||||
int day_len, week_len, head_sep;
|
||||
int month_per_row;
|
||||
int skip, r_off, w_off;
|
||||
|
||||
if (julian) {
|
||||
day_len = J_DAY_LEN;
|
||||
week_len = J_WEEK_LEN;
|
||||
head_sep = J_HEAD_SEP;
|
||||
month_per_row = J_MONTH_PER_ROW;
|
||||
}
|
||||
else {
|
||||
day_len = DAY_LEN;
|
||||
week_len = WEEK_LEN;
|
||||
head_sep = HEAD_SEP;
|
||||
month_per_row = MONTH_PER_ROW;
|
||||
}
|
||||
|
||||
month--;
|
||||
|
||||
startyear = year - (before + 12 - 1 - month) / 12;
|
||||
startmonth = 12 - 1 - ((before + 12 - 1 - month) % 12);
|
||||
endyear = year + (month + after) / 12;
|
||||
endmonth = (month + after) % 12;
|
||||
|
||||
if (startyear < 0 || endyear > 9999) {
|
||||
errx(1, "year should be in 1-9999");
|
||||
}
|
||||
|
||||
year = startyear;
|
||||
month = startmonth;
|
||||
inayear = newyear = (year != endyear || yearly);
|
||||
if (inayear) {
|
||||
skip = month % month_per_row;
|
||||
month -= skip;
|
||||
}
|
||||
else {
|
||||
skip = 0;
|
||||
}
|
||||
|
||||
do {
|
||||
if (newyear) {
|
||||
(void)snprintf(lineout, sizeof(lineout), "%d", year);
|
||||
center(lineout, week_len * month_per_row +
|
||||
head_sep * (month_per_row - 1), 0);
|
||||
(void)printf("\n\n");
|
||||
newyear = 0;
|
||||
}
|
||||
|
||||
for (i = 0; i < skip; i++)
|
||||
center("", week_len, head_sep);
|
||||
|
||||
for (; i < month_per_row; i++) {
|
||||
int sep;
|
||||
|
||||
if (year == endyear && month + i > endmonth)
|
||||
break;
|
||||
|
||||
sep = (i == month_per_row - 1) ? 0 : head_sep;
|
||||
day_array(month + i + 1, year, days[i]);
|
||||
if (inayear) {
|
||||
center(month_names[month + i], week_len, sep);
|
||||
}
|
||||
else {
|
||||
snprintf(lineout, sizeof(lineout), "%s %d",
|
||||
month_names[month + i], year);
|
||||
center(lineout, week_len, sep);
|
||||
}
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
for (i = 0; i < skip; i++)
|
||||
center("", week_len, head_sep);
|
||||
|
||||
for (; i < month_per_row; i++) {
|
||||
int sep;
|
||||
|
||||
if (year == endyear && month + i > endmonth)
|
||||
break;
|
||||
|
||||
sep = (i == month_per_row - 1) ? 0 : head_sep;
|
||||
if (dow) {
|
||||
printf("%s ", (julian) ?
|
||||
j_day_headings + 4 * dow :
|
||||
day_headings + 3 * dow);
|
||||
printf("%.*s", dow * (julian ? 4 : 3) - 1,
|
||||
(julian) ? j_day_headings : day_headings);
|
||||
} else
|
||||
printf("%s", (julian) ? j_day_headings : day_headings);
|
||||
printf("%*s", sep, "");
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
for (row = 0; row < 6; row++) {
|
||||
char *p = NULL;
|
||||
|
||||
memset(lineout, ' ', sizeof(lineout));
|
||||
for (i = 0; i < skip; i++) {
|
||||
/* nothing */
|
||||
}
|
||||
w_off = 0;
|
||||
for (; i < month_per_row; i++) {
|
||||
int col, *dp;
|
||||
|
||||
if (year == endyear && month + i > endmonth)
|
||||
break;
|
||||
|
||||
p = lineout + i * (week_len + 2) + w_off;
|
||||
dp = &days[i][row * 7];
|
||||
for (col = 0; col < 7;
|
||||
col++, p += day_len + r_off) {
|
||||
r_off = ascii_day(p, *dp++);
|
||||
w_off += r_off;
|
||||
}
|
||||
}
|
||||
*p = '\0';
|
||||
trim_trailing_spaces(lineout);
|
||||
(void)printf("%s\n", lineout);
|
||||
}
|
||||
|
||||
skip = 0;
|
||||
month += month_per_row;
|
||||
if (month >= 12) {
|
||||
month -= 12;
|
||||
year++;
|
||||
newyear = 1;
|
||||
}
|
||||
} while (year < endyear || (year == endyear && month <= endmonth));
|
||||
}
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
static void
|
||||
day_array(int month, int year, int *days)
|
||||
{
|
||||
int day, dw, dm;
|
||||
time_t t;
|
||||
struct tm *tm;
|
||||
|
||||
t = time(NULL);
|
||||
tm = localtime(&t);
|
||||
tm->tm_year += TM_YEAR_BASE;
|
||||
tm->tm_mon++;
|
||||
tm->tm_yday++; /* jan 1 is 1 for us, not 0 */
|
||||
|
||||
for (dm = month + year * 12, dw = 0; dw < 4; dw++) {
|
||||
if (dm == shift_days[julian][dw][MAXDAYS]) {
|
||||
memmove(days, shift_days[julian][dw],
|
||||
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--) {
|
||||
if (hilite && year == tm->tm_year &&
|
||||
(julian ? (day == tm->tm_yday) :
|
||||
(month == tm->tm_mon && day == tm->tm_mday)))
|
||||
days[dw++] = SPACE - day++;
|
||||
else
|
||||
days[dw++] = day++;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* day_in_year --
|
||||
* return the 1 based day number within the year
|
||||
*/
|
||||
static int
|
||||
day_in_year(int day, int month, int 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. Returns the day of the week of the first
|
||||
* missing day for any given Gregorian shift.
|
||||
*/
|
||||
static int
|
||||
day_in_week(int day, int month, int 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 - dow + 6 + SATURDAY) % 7);
|
||||
if (temp >= (FIRST_MISSING_DAY + NUMBER_MISSING_DAYS))
|
||||
return (((temp - dow + 6 + SATURDAY) - NUMBER_MISSING_DAYS) % 7);
|
||||
return ((FIRST_MISSING_DAY - dow + 6 + SATURDAY) % 7);
|
||||
}
|
||||
|
||||
static int
|
||||
ascii_day(char *p, int day)
|
||||
{
|
||||
int display, val, rc;
|
||||
char *b;
|
||||
static const 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 (0);
|
||||
}
|
||||
if (day < SPACE) {
|
||||
b = p;
|
||||
day = SPACE - day;
|
||||
} else
|
||||
b = NULL;
|
||||
if (julian) {
|
||||
if ((val = day / 100) != 0) {
|
||||
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];
|
||||
}
|
||||
|
||||
rc = 0;
|
||||
if (b != NULL) {
|
||||
const char *t;
|
||||
char h[64];
|
||||
int l;
|
||||
|
||||
l = p - b;
|
||||
memcpy(h, b, l);
|
||||
p = b;
|
||||
|
||||
if (md != NULL) {
|
||||
for (t = md; *t; rc++)
|
||||
*p++ = *t++;
|
||||
memcpy(p, h, l);
|
||||
p += l;
|
||||
for (t = me; *t; rc++)
|
||||
*p++ = *t++;
|
||||
} else {
|
||||
for (t = &h[0]; l--; t++) {
|
||||
*p++ = *t;
|
||||
rc++;
|
||||
*p++ = '\b';
|
||||
rc++;
|
||||
*p++ = *t;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*p = ' ';
|
||||
return (rc);
|
||||
}
|
||||
|
||||
static void
|
||||
trim_trailing_spaces(char *s)
|
||||
{
|
||||
char *p;
|
||||
|
||||
for (p = s; *p; ++p)
|
||||
continue;
|
||||
while (p > s && isspace((unsigned char)*--p))
|
||||
continue;
|
||||
if (p > s)
|
||||
++p;
|
||||
*p = '\0';
|
||||
}
|
||||
|
||||
static void
|
||||
center(const 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, "");
|
||||
}
|
||||
|
||||
/*
|
||||
* gregorian_reform --
|
||||
* Given a description of date on which the Gregorian Reform was
|
||||
* applied. The argument can be any of the "country" names
|
||||
* listed in the reforms array (case insensitive) or a date of
|
||||
* the form YYYY/MM/DD. The date and month can be omitted if
|
||||
* doing so would not select more than one different built-in
|
||||
* reform point.
|
||||
*/
|
||||
static void
|
||||
gregorian_reform(const char *p)
|
||||
{
|
||||
int year, month, date;
|
||||
int i, days, diw, diy;
|
||||
char c;
|
||||
|
||||
i = sscanf(p, "%d%*[/,-]%d%*[/,-]%d%c", &year, &month, &date, &c);
|
||||
switch (i) {
|
||||
case 4:
|
||||
/*
|
||||
* If the character was sscanf()ed, then there's more
|
||||
* stuff than we need.
|
||||
*/
|
||||
errx(1, "date specifier %s invalid", p);
|
||||
case 0:
|
||||
/*
|
||||
* Not a form we can sscanf(), so void these, and we
|
||||
* can try matching "country" names later.
|
||||
*/
|
||||
year = month = date = -1;
|
||||
break;
|
||||
case 1:
|
||||
month = 0;
|
||||
/*FALLTHROUGH*/
|
||||
case 2:
|
||||
date = 0;
|
||||
/*FALLTHROUGH*/
|
||||
case 3:
|
||||
/*
|
||||
* At last, some sanity checking on the values we were
|
||||
* given.
|
||||
*/
|
||||
if (year < 1 || year > 9999)
|
||||
errx(1, "%d: illegal year value: use 1-9999", year);
|
||||
if (i > 1 && (month < 1 || month > 12))
|
||||
errx(1, "%d: illegal month value: use 1-12", month);
|
||||
if ((i == 3 && date < 1) || date < 0 ||
|
||||
date > days_in_month[1][month])
|
||||
/*
|
||||
* What about someone specifying a leap day in
|
||||
* a non-leap year? Well...that's a tricky
|
||||
* one. We can't yet *say* whether the year
|
||||
* in question is a leap year. What if the
|
||||
* date given was, for example, 1700/2/29? is
|
||||
* that a valid leap day?
|
||||
*
|
||||
* So...we punt, and hope that saying 29 in
|
||||
* the case of February isn't too bad an idea.
|
||||
*/
|
||||
errx(1, "%d: illegal date value: use 1-%d", date,
|
||||
days_in_month[1][month]);
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
* A complete date was specified, so use the other pope.
|
||||
*/
|
||||
if (date > 0) {
|
||||
static struct reform Goestheveezl;
|
||||
|
||||
reform = &Goestheveezl;
|
||||
reform->country = "Bompzidaize";
|
||||
reform->year = year;
|
||||
reform->month = month;
|
||||
reform->date = date;
|
||||
}
|
||||
|
||||
/*
|
||||
* No date information was specified, so let's try to match on
|
||||
* country name.
|
||||
*/
|
||||
else if (year == -1) {
|
||||
for (reform = &reforms[0]; reform->year; reform++) {
|
||||
if (strcasecmp(p, reform->country) == 0)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* We have *some* date information, but not a complete date.
|
||||
* Let's see if we have enough to pick a single entry from the
|
||||
* list that's not ambiguous.
|
||||
*/
|
||||
else {
|
||||
for (reform = &reforms[0]; reform->year; reform++) {
|
||||
if ((year == 0 || year == reform->year) &&
|
||||
(month == 0 || month == reform->month) &&
|
||||
(date == 0 || month == reform->date))
|
||||
break;
|
||||
}
|
||||
|
||||
if (i <= reform->ambiguity)
|
||||
errx(1, "%s: ambiguous short reform date specification", p);
|
||||
}
|
||||
|
||||
/*
|
||||
* Oops...we reached the end of the list.
|
||||
*/
|
||||
if (reform->year == 0)
|
||||
errx(1, "reform name %s invalid", p);
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
reform->missing_days =
|
||||
j_leap_days(reform->year, reform->month, reform->date) -
|
||||
g_leap_days(reform->year, reform->month, reform->date) -
|
||||
GREGORIAN_MAGIC;
|
||||
|
||||
reform->first_missing_day =
|
||||
(reform->year - 1) * 365 +
|
||||
day_in_year(reform->date, reform->month, reform->year) +
|
||||
date +
|
||||
j_leap_days(reform->year, reform->month, reform->date);
|
||||
|
||||
/*
|
||||
* Once we know the day of the week of the first missing day,
|
||||
* skip back to the first of the month's day of the week.
|
||||
*/
|
||||
diw = day_in_week(reform->date, reform->month, reform->year);
|
||||
diw = (diw + 8 - (reform->date % 7)) % 7;
|
||||
diy = day_in_year(1, reform->month, reform->year);
|
||||
|
||||
/*
|
||||
* We might need all four of these (if you switch from Julian
|
||||
* to Gregorian at some point after 9900, you get a gap of 73
|
||||
* days, and that can affect four months), and it doesn't hurt
|
||||
* all that much to precompute them, so there.
|
||||
*/
|
||||
date = 1;
|
||||
days = 0;
|
||||
for (i = 0; i < 4; i++)
|
||||
reform_day_array(reform->month + i, reform->year,
|
||||
&days, &date, &diw, &diy,
|
||||
shift_days[0][i],
|
||||
shift_days[1][i]);
|
||||
}
|
||||
|
||||
/*
|
||||
* reform_day_array --
|
||||
* Pre-calculates the given month's calendar (in both "standard"
|
||||
* and "julian day" representations) with respect for days
|
||||
* skipped during a reform period.
|
||||
*/
|
||||
static void
|
||||
reform_day_array(int month, int year, int *done, int *date, int *diw, int *diy,
|
||||
int *scal, int *jcal)
|
||||
{
|
||||
int mdays;
|
||||
|
||||
/*
|
||||
* If the reform was in the month of october or later, then
|
||||
* the month number from the caller could "overflow".
|
||||
*/
|
||||
if (month > 12) {
|
||||
month -= 12;
|
||||
year++;
|
||||
}
|
||||
|
||||
/*
|
||||
* Erase months, and set crib number. The crib number is used
|
||||
* later to determine if the month to be displayed is here or
|
||||
* should be built on the fly with the generic routine
|
||||
*/
|
||||
memmove(scal, empty, MAXDAYS * sizeof(int));
|
||||
scal[MAXDAYS] = month + year * 12;
|
||||
memmove(jcal, empty, MAXDAYS * sizeof(int));
|
||||
jcal[MAXDAYS] = month + year * 12;
|
||||
|
||||
/*
|
||||
* It doesn't matter what the actual month is when figuring
|
||||
* out if this is a leap year or not, just so long as February
|
||||
* gets the right number of days in it.
|
||||
*/
|
||||
mdays = days_in_month[g_leap_year(year, 3, 1)][month];
|
||||
|
||||
/*
|
||||
* Bounce back to the first "row" in the day array, and fill
|
||||
* in any days that actually occur.
|
||||
*/
|
||||
for (*diw %= 7; (*date - *done) <= mdays; (*date)++, (*diy)++) {
|
||||
/*
|
||||
* "date" doesn't get reset by the caller across calls
|
||||
* to this routine, so we can actually tell that we're
|
||||
* looking at April the 41st. Much easier than trying
|
||||
* to calculate the absolute julian day for a given
|
||||
* date and then checking that.
|
||||
*/
|
||||
if (*date < reform->date ||
|
||||
*date >= reform->date + reform->missing_days) {
|
||||
scal[*diw] = *date - *done;
|
||||
jcal[*diw] = *diy;
|
||||
(*diw)++;
|
||||
}
|
||||
}
|
||||
*done += mdays;
|
||||
}
|
||||
|
||||
static int
|
||||
getnum(const char *p)
|
||||
{
|
||||
unsigned long result;
|
||||
char *ep;
|
||||
|
||||
errno = 0;
|
||||
result = strtoul(p, &ep, 10);
|
||||
if (p[0] == '\0' || *ep != '\0')
|
||||
goto error;
|
||||
if (errno == ERANGE && result == ULONG_MAX)
|
||||
goto error;
|
||||
if (result > INT_MAX)
|
||||
goto error;
|
||||
|
||||
return (int)result;
|
||||
|
||||
error:
|
||||
errx(1, "bad number: %s", p);
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
|
||||
static void
|
||||
init_hilite(void)
|
||||
{
|
||||
const char *term;
|
||||
int errret;
|
||||
|
||||
hilite++;
|
||||
|
||||
if (!isatty(fileno(stdout)))
|
||||
return;
|
||||
|
||||
term = getenv("TERM");
|
||||
if (term == NULL)
|
||||
term = "dumb";
|
||||
if (setupterm(term, fileno(stdout), &errret) != 0 && errret != 1)
|
||||
return;
|
||||
|
||||
if (hilite > 1)
|
||||
md = enter_reverse_mode;
|
||||
else
|
||||
md = enter_bold_mode;
|
||||
me = exit_attribute_mode;
|
||||
if (me == NULL || md == NULL)
|
||||
md = me = NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
usage(void)
|
||||
{
|
||||
|
||||
(void)fprintf(stderr,
|
||||
"usage: cal [-3hjry] [-A after] [-B before] [-C context] [-d day-of-week] "
|
||||
"[-R reform-spec]\n [[month] year]\n");
|
||||
exit(1);
|
||||
}
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
# $NetBSD: Makefile,v 1.14 2009/04/14 22:15:17 lukem Exp $
|
||||
# @(#)Makefile 8.1 (Berkeley) 6/6/93
|
||||
|
||||
.include <bsd.own.mk>
|
||||
|
||||
PROG= calendar
|
||||
.if ${MKSHARE} != "no"
|
||||
FILESDIR=/usr/share/calendar
|
||||
FILES!= echo ${.CURDIR}/calendars/calendar.*
|
||||
.endif
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
|
|
@ -1,728 +0,0 @@
|
|||
/* $NetBSD: calendar.c,v 1.52 2015/07/01 06:48:25 dholland Exp $ */
|
||||
|
||||
/*
|
||||
* 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. 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.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
__COPYRIGHT("@(#) Copyright (c) 1989, 1993\
|
||||
The Regents of the University of California. All rights reserved.");
|
||||
#endif /* not lint */
|
||||
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)calendar.c 8.4 (Berkeley) 1/7/95";
|
||||
#endif
|
||||
__RCSID("$NetBSD: calendar.c,v 1.52 2015/07/01 06:48:25 dholland Exp $");
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/uio.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <pwd.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <tzfile.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "pathnames.h"
|
||||
|
||||
/* flags used by calendar file parser */
|
||||
#define F_ISMONTH 0x01
|
||||
#define F_ISDAY 0x02
|
||||
#define F_ISDOW 0x04
|
||||
#define F_WILDMONTH 0x10
|
||||
#define F_WILDDAY 0x20
|
||||
|
||||
static unsigned short lookahead = 1;
|
||||
static unsigned short weekend = 2;
|
||||
static char *fname = NULL;
|
||||
static char *datestr = NULL;
|
||||
static const char *defaultnames[] = {"calendar", ".calendar", _PATH_SYSTEM_CALENDAR, NULL};
|
||||
static struct passwd *pw;
|
||||
static char path[MAXPATHLEN + 1];
|
||||
static bool doall = false;
|
||||
static bool cpp_restricted = false;
|
||||
|
||||
/* 1-based month, 0-based days, cumulative */
|
||||
static const 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 },
|
||||
};
|
||||
static struct tm *tp;
|
||||
static const int *cumdays;
|
||||
static int offset, yrdays;
|
||||
static char dayname[10];
|
||||
|
||||
static struct iovec header[] = {
|
||||
{ __UNCONST("From: "), 6 },
|
||||
{ NULL, 0 },
|
||||
{ __UNCONST(" (Reminder Service)\nTo: "), 24 },
|
||||
{ NULL, 0 },
|
||||
{ __UNCONST("\nSubject: "), 10 },
|
||||
{ NULL, 0 },
|
||||
{ __UNCONST("'s Calendar\nPrecedence: bulk\n\n"), 30 },
|
||||
};
|
||||
|
||||
static const char *days[] = {
|
||||
"sun", "mon", "tue", "wed", "thu", "fri", "sat", NULL,
|
||||
};
|
||||
|
||||
static const char *months[] = {
|
||||
"jan", "feb", "mar", "apr", "may", "jun",
|
||||
"jul", "aug", "sep", "oct", "nov", "dec", NULL,
|
||||
};
|
||||
|
||||
static void atodays(int, char *, unsigned short *);
|
||||
static void cal(void);
|
||||
static void closecal(FILE *);
|
||||
static void changeuser(void);
|
||||
static int getday(char *);
|
||||
static int getfield(char *, char **, int *);
|
||||
static void getmmdd(struct tm *, char *);
|
||||
static int getmonth(char *);
|
||||
static bool isnow(char *);
|
||||
static FILE *opencal(FILE **);
|
||||
static int tryopen(const char *, int);
|
||||
static void settime(void);
|
||||
static void usage(void) __dead;
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
int ch;
|
||||
const char *caldir;
|
||||
|
||||
(void)setprogname(argv[0]); /* for portability */
|
||||
|
||||
while ((ch = getopt(argc, argv, "-ad:f:l:w:x")) != -1) {
|
||||
switch (ch) {
|
||||
case '-': /* backward contemptible */
|
||||
case 'a':
|
||||
if (getuid()) {
|
||||
errno = EPERM;
|
||||
err(EXIT_FAILURE, NULL);
|
||||
}
|
||||
doall = true;
|
||||
break;
|
||||
case 'd':
|
||||
datestr = optarg;
|
||||
break;
|
||||
case 'f':
|
||||
fname = optarg;
|
||||
break;
|
||||
case 'l':
|
||||
atodays(ch, optarg, &lookahead);
|
||||
break;
|
||||
case 'w':
|
||||
atodays(ch, optarg, &weekend);
|
||||
break;
|
||||
case 'x':
|
||||
cpp_restricted = true;
|
||||
break;
|
||||
case '?':
|
||||
default:
|
||||
usage();
|
||||
}
|
||||
}
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
if (argc)
|
||||
usage();
|
||||
|
||||
settime();
|
||||
if (doall) {
|
||||
/*
|
||||
* XXX - This ignores the user's CALENDAR_DIR variable.
|
||||
* Run under user's login shell?
|
||||
*/
|
||||
if (setgroups(0, NULL) == -1) {
|
||||
err(EXIT_FAILURE, "setgroups");
|
||||
}
|
||||
while ((pw = getpwent()) != NULL) {
|
||||
if (setegid(pw->pw_gid) == -1) {
|
||||
warn("%s: setegid", pw->pw_name);
|
||||
continue;
|
||||
}
|
||||
if (seteuid(pw->pw_uid) == -1) {
|
||||
warn("%s: seteuid", pw->pw_name);
|
||||
continue;
|
||||
}
|
||||
if (chdir(pw->pw_dir) != -1) {
|
||||
cal();
|
||||
}
|
||||
if (seteuid(0) == -1) {
|
||||
warn("%s: seteuid back to 0", pw->pw_name);
|
||||
}
|
||||
}
|
||||
} else if ((caldir = getenv("CALENDAR_DIR")) != NULL) {
|
||||
if (chdir(caldir) != -1)
|
||||
cal();
|
||||
} else if ((pw = getpwuid(geteuid())) != NULL) {
|
||||
if (chdir(pw->pw_dir) != -1)
|
||||
cal();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
cal(void)
|
||||
{
|
||||
bool printing;
|
||||
FILE *fp, *in = NULL;
|
||||
char *line;
|
||||
|
||||
if ((fp = opencal(&in)) == NULL || in == NULL)
|
||||
return;
|
||||
printing = false;
|
||||
while ((line = fparseln(in,
|
||||
NULL, NULL, NULL, FPARSELN_UNESCCOMM)) != NULL) {
|
||||
if (line[0] == '\0')
|
||||
continue;
|
||||
if (line[0] != '\t')
|
||||
printing = isnow(line);
|
||||
if (printing)
|
||||
(void)fprintf(fp, "%s\n", line);
|
||||
free(line);
|
||||
|
||||
}
|
||||
closecal(fp);
|
||||
}
|
||||
|
||||
static void
|
||||
settime(void)
|
||||
{
|
||||
time_t now;
|
||||
|
||||
(void)time(&now);
|
||||
tp = localtime(&now);
|
||||
if (datestr)
|
||||
getmmdd(tp, datestr);
|
||||
|
||||
if (isleap(tp->tm_year + TM_YEAR_BASE)) {
|
||||
yrdays = DAYSPERLYEAR;
|
||||
cumdays = daytab[1];
|
||||
} else {
|
||||
yrdays = DAYSPERNYEAR;
|
||||
cumdays = daytab[0];
|
||||
}
|
||||
/* Friday displays Monday's events */
|
||||
offset = tp->tm_wday == 5 ? lookahead + weekend : lookahead;
|
||||
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.
|
||||
*/
|
||||
static bool
|
||||
isnow(char *endp)
|
||||
{
|
||||
int day;
|
||||
int flags;
|
||||
int month;
|
||||
int v1;
|
||||
int v2;
|
||||
|
||||
flags = 0;
|
||||
|
||||
/* didn't recognize anything, skip it */
|
||||
if (!(v1 = getfield(endp, &endp, &flags)))
|
||||
return false;
|
||||
|
||||
if ((flags & (F_ISDAY|F_ISDOW)) || v1 > 12) {
|
||||
/* found a day */
|
||||
day = v1;
|
||||
/* if no recognizable month, assume wildcard ('*') month */
|
||||
if ((month = getfield(endp, &endp, &flags)) == 0) {
|
||||
flags |= F_ISMONTH | F_WILDMONTH;
|
||||
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)) == 0)
|
||||
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 month is out of range, treat it as '*' */
|
||||
if (month < 1 || month > 12) {
|
||||
flags |= F_ISMONTH | F_WILDMONTH;
|
||||
month = tp->tm_mon + 1;
|
||||
}
|
||||
|
||||
if (flags & F_WILDMONTH && flags & F_WILDDAY)
|
||||
return true;
|
||||
|
||||
if (flags & F_WILDMONTH && flags & F_ISDAY && day == tp->tm_mday)
|
||||
return true;
|
||||
|
||||
if (flags & F_WILDMONTH && flags & F_ISDOW && day == tp->tm_wday + 1)
|
||||
return true;
|
||||
|
||||
if (flags & F_ISMONTH && flags & F_WILDDAY && month == tp->tm_mon + 1)
|
||||
return true;
|
||||
|
||||
if (flags & F_ISMONTH && flags & F_ISDOW && month == tp->tm_mon + 1 &&
|
||||
day == tp->tm_wday + 1)
|
||||
return true;
|
||||
|
||||
if (flags & F_ISDOW)
|
||||
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 true;
|
||||
|
||||
/* if number of days left in this year + days to event in next year */
|
||||
if (yrdays - tp->tm_yday + day <= offset)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static int
|
||||
getfield(char *p, char **endp, int *flags)
|
||||
{
|
||||
int val;
|
||||
char *start;
|
||||
char savech;
|
||||
|
||||
/*
|
||||
* note this macro has an arg that isn't used ... it is retained
|
||||
* (it is believed) to make the macro call look more "natural"
|
||||
* and suggest at the call site what is happening.
|
||||
*/
|
||||
#define FLDCHAR(a) (*p != '\0' && !isdigit((unsigned char)*p) && \
|
||||
!isalpha((unsigned char)*p) && *p != '*')
|
||||
|
||||
val = 0;
|
||||
for (/*EMPTY*/; FLDCHAR(*p); ++p)
|
||||
continue;
|
||||
if (*p == '*') { /* `*' is current month */
|
||||
if (!(*flags & F_ISMONTH)) {
|
||||
*flags |= F_ISMONTH | F_WILDMONTH;
|
||||
*endp = p + 1;
|
||||
return tp->tm_mon + 1;
|
||||
} else {
|
||||
*flags |= F_ISDAY | F_WILDDAY;
|
||||
*endp = p + 1;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
if (isdigit((unsigned char)*p)) {
|
||||
val = (int)strtol(p, &p, 10); /* if 0, it's failure */
|
||||
for (/*EMPTY*/; FLDCHAR(*p); ++p)
|
||||
continue;
|
||||
*endp = p;
|
||||
return val;
|
||||
}
|
||||
for (start = p; *p != '\0' && isalpha((unsigned char)*p); p++)
|
||||
continue;
|
||||
|
||||
savech = *p;
|
||||
if (p != start) {
|
||||
*p = '\0';
|
||||
if ((val = getmonth(start)) != 0)
|
||||
*flags |= F_ISMONTH;
|
||||
else if ((val = getday(start)) != 0)
|
||||
*flags |= F_ISDOW;
|
||||
else {
|
||||
*p = savech;
|
||||
*endp = start;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
for (*p = savech; FLDCHAR(*p); ++p)
|
||||
continue;
|
||||
*endp = p;
|
||||
return val;
|
||||
}
|
||||
|
||||
static FILE *
|
||||
opencal(FILE **in)
|
||||
{
|
||||
int fd = -1;
|
||||
int pdes[2];
|
||||
|
||||
/* open up calendar file as stdin */
|
||||
if (fname == NULL) {
|
||||
for (const char **name = defaultnames; *name != NULL; name++) {
|
||||
if ((fd = tryopen(*name, O_RDONLY)) == -1)
|
||||
continue;
|
||||
else
|
||||
break;
|
||||
}
|
||||
if (fd == -1) {
|
||||
if (doall)
|
||||
return NULL;
|
||||
err(EXIT_FAILURE, "Cannot open calendar file");
|
||||
}
|
||||
} else if ((fd = tryopen(fname, O_RDONLY)) == -1) {
|
||||
if (doall)
|
||||
return NULL;
|
||||
err(EXIT_FAILURE, "Cannot open `%s'", fname);
|
||||
}
|
||||
|
||||
if (pipe(pdes) == -1) {
|
||||
warn("Cannot open pipe");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
switch (fork()) {
|
||||
case -1:
|
||||
/* error */
|
||||
(void)close(pdes[0]);
|
||||
(void)close(pdes[1]);
|
||||
return NULL;
|
||||
case 0:
|
||||
/* child */
|
||||
/* set stdin to calendar file */
|
||||
if (fd != STDIN_FILENO) {
|
||||
(void)dup2(fd, STDIN_FILENO);
|
||||
(void)close(fd);
|
||||
}
|
||||
/* set stdout to pipe input */
|
||||
if (pdes[1] != STDOUT_FILENO) {
|
||||
(void)dup2(pdes[1], STDOUT_FILENO);
|
||||
(void)close(pdes[1]);
|
||||
}
|
||||
(void)close(pdes[0]);
|
||||
if (doall) {
|
||||
/* become the user properly */
|
||||
changeuser();
|
||||
}
|
||||
/* tell CPP to only open regular files */
|
||||
if(!cpp_restricted && setenv("CPP_RESTRICTED", "", 1) == -1)
|
||||
err(EXIT_FAILURE, "Cannot restrict cpp");
|
||||
cpp_restricted = true;
|
||||
|
||||
(void)execl(_PATH_CPP, "cpp", "-traditional", "-P", "-I.",
|
||||
"-I" _PATH_CALENDARS, NULL);
|
||||
err(EXIT_FAILURE, "Cannot exec `%s'", _PATH_CPP);
|
||||
/*NOTREACHED*/
|
||||
default:
|
||||
/* parent -- fdopen *in to pipe output */
|
||||
*in = fdopen(pdes[0], "r");
|
||||
(void)close(pdes[1]);
|
||||
|
||||
/* close calendar file */
|
||||
close(fd);
|
||||
|
||||
/* 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)) == -1) {
|
||||
warn("Cannot create temporary file");
|
||||
return NULL;
|
||||
}
|
||||
return fdopen(fd, "w+");
|
||||
}
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
|
||||
static int
|
||||
tryopen(const char *pathname, int flags)
|
||||
{
|
||||
int fd, serrno, zero;
|
||||
struct stat st;
|
||||
|
||||
/*
|
||||
* XXX: cpp_restricted has inverted sense; it is false by default,
|
||||
* and -x sets it to true. CPP_RESTRICTED is set in the environment
|
||||
* if cpp_restricted is false... go figure. This should be fixed
|
||||
* later.
|
||||
*/
|
||||
if (doall && cpp_restricted == false) {
|
||||
/*
|
||||
* We are running with the user's euid, so they can't
|
||||
* cause any mayhem (e.g. opening rewinding tape
|
||||
* devices) that they couldn't do easily enough on
|
||||
* their own. All we really need to worry about is opens
|
||||
* that hang, because that would DoS the calendar run.
|
||||
*/
|
||||
fd = open(pathname, flags | O_NONBLOCK);
|
||||
if (fd == -1) {
|
||||
return -1;
|
||||
}
|
||||
if (fstat(fd, &st) == -1) {
|
||||
serrno = errno;
|
||||
close(fd);
|
||||
errno = serrno;
|
||||
return -1;
|
||||
}
|
||||
if (S_ISCHR(st.st_mode) ||
|
||||
S_ISBLK(st.st_mode) ||
|
||||
S_ISFIFO(st.st_mode)) {
|
||||
close(fd);
|
||||
|
||||
/* Call shenanigans in the daily output */
|
||||
errno = EPERM;
|
||||
warn("%s: %s", pw->pw_name, pathname);
|
||||
|
||||
errno = EPERM;
|
||||
return -1;
|
||||
}
|
||||
if (S_ISDIR(st.st_mode)) {
|
||||
/* Don't warn about this */
|
||||
close(fd);
|
||||
errno = EISDIR;
|
||||
return -1;
|
||||
}
|
||||
if (!S_ISREG(st.st_mode)) {
|
||||
/* There shouldn't be other cases to go here */
|
||||
close(fd);
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
zero = 0;
|
||||
if (ioctl(fd, FIONBIO, &zero) == -1) {
|
||||
serrno = errno;
|
||||
warn("%s: %s: FIONBIO", pw->pw_name, pathname);
|
||||
close(fd);
|
||||
errno = serrno;
|
||||
return -1;
|
||||
}
|
||||
return fd;
|
||||
} else {
|
||||
return open(pathname, flags);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
closecal(FILE *fp)
|
||||
{
|
||||
struct stat sbuf;
|
||||
ssize_t nread;
|
||||
int pdes[2];
|
||||
int status;
|
||||
char buf[1024];
|
||||
|
||||
if (!doall)
|
||||
return;
|
||||
|
||||
(void)rewind(fp);
|
||||
if (fstat(fileno(fp), &sbuf) == -1 || sbuf.st_size == 0)
|
||||
goto done;
|
||||
if (pipe(pdes) == -1)
|
||||
goto done;
|
||||
|
||||
switch (fork()) {
|
||||
case -1:
|
||||
/* error */
|
||||
(void)close(pdes[0]);
|
||||
(void)close(pdes[1]);
|
||||
break;
|
||||
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]);
|
||||
if (doall) {
|
||||
/* become the user properly */
|
||||
changeuser();
|
||||
}
|
||||
(void)execl(_PATH_SENDMAIL, "sendmail", "-i", "-t", "-F",
|
||||
"\"Reminder Service\"", "-f", "root", NULL);
|
||||
err(EXIT_FAILURE, "Cannot exec `%s'", _PATH_SENDMAIL);
|
||||
/*NOTREACHED*/
|
||||
default:
|
||||
/* parent -- write to pipe input */
|
||||
(void)close(pdes[0]);
|
||||
|
||||
header[1].iov_base = header[3].iov_base = (void *)pw->pw_name;
|
||||
header[1].iov_len = header[3].iov_len = strlen(pw->pw_name);
|
||||
(void)writev(pdes[1], header, 7);
|
||||
while ((nread = read(fileno(fp), buf, sizeof(buf))) > 0)
|
||||
(void)write(pdes[1], buf, (size_t)nread);
|
||||
(void)close(pdes[1]);
|
||||
break;
|
||||
}
|
||||
|
||||
done: (void)fclose(fp);
|
||||
(void)unlink(path);
|
||||
while (wait(&status) != -1)
|
||||
continue;
|
||||
}
|
||||
|
||||
static void
|
||||
changeuser(void)
|
||||
{
|
||||
uid_t uid;
|
||||
gid_t gid;
|
||||
|
||||
uid = geteuid();
|
||||
gid = getegid();
|
||||
assert(uid == pw->pw_uid);
|
||||
assert(gid == pw->pw_gid);
|
||||
|
||||
if (seteuid(0) == -1) {
|
||||
err(EXIT_FAILURE, "%s: changing user: cannot reassert uid 0",
|
||||
pw->pw_name);
|
||||
}
|
||||
if (setgid(gid) == -1) {
|
||||
err(EXIT_FAILURE, "%s: cannot assume gid %d",
|
||||
pw->pw_name, (int)gid);
|
||||
}
|
||||
if (initgroups(pw->pw_name, gid) == -1) {
|
||||
err(EXIT_FAILURE, "%s: cannot initgroups", pw->pw_name);
|
||||
}
|
||||
if (setuid(uid) == -1) {
|
||||
err(EXIT_FAILURE, "%s: cannot assume uid %d",
|
||||
pw->pw_name, (int)uid);
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
getmonth(char *s)
|
||||
{
|
||||
const char **p;
|
||||
|
||||
for (p = months; *p; ++p)
|
||||
if (strncasecmp(s, *p, 3) == 0)
|
||||
return (int)(p - months) + 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
getday(char *s)
|
||||
{
|
||||
const char **p;
|
||||
|
||||
for (p = days; *p; ++p)
|
||||
if (strncasecmp(s, *p, 3) == 0)
|
||||
return (int)(p - days) + 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
atodays(int ch, char *arg, unsigned short *rvp)
|
||||
{
|
||||
int u;
|
||||
|
||||
u = atoi(arg);
|
||||
if (u < 0 || u > 366)
|
||||
warnx("-%c %d out of range 0-366, ignored.", ch, u);
|
||||
else
|
||||
*rvp = u;
|
||||
}
|
||||
|
||||
#define todigit(x) ((x) - '0')
|
||||
#define ATOI2(x) (todigit((x)[0]) * 10 + todigit((x)[1]))
|
||||
#define ISDIG2(x) (isdigit((unsigned char)(x)[0]) && isdigit((unsigned char)(x)[1]))
|
||||
|
||||
static void
|
||||
getmmdd(struct tm *ptm, char *ds)
|
||||
{
|
||||
bool ok = false;
|
||||
struct tm ttm;
|
||||
|
||||
ttm = *ptm;
|
||||
ttm.tm_isdst = -1;
|
||||
|
||||
if (ISDIG2(ds)) {
|
||||
ttm.tm_mon = ATOI2(ds) - 1;
|
||||
ds += 2;
|
||||
}
|
||||
if (ISDIG2(ds)) {
|
||||
ttm.tm_mday = ATOI2(ds);
|
||||
ds += 2;
|
||||
ok = true;
|
||||
}
|
||||
if (ok) {
|
||||
if (ISDIG2(ds) && ISDIG2(ds + 2)) {
|
||||
ttm.tm_year = ATOI2(ds) * 100 - TM_YEAR_BASE;
|
||||
ds += 2;
|
||||
ttm.tm_year += ATOI2(ds);
|
||||
} else if (ISDIG2(ds)) {
|
||||
ttm.tm_year = ATOI2(ds);
|
||||
if (ttm.tm_year < 69)
|
||||
ttm.tm_year += 2000 - TM_YEAR_BASE;
|
||||
else
|
||||
ttm.tm_year += 1900 - TM_YEAR_BASE;
|
||||
}
|
||||
}
|
||||
if (ok && mktime(&ttm) == -1)
|
||||
ok = false;
|
||||
|
||||
if (ok)
|
||||
*ptm = ttm;
|
||||
else {
|
||||
warnx("Can't convert `%s' to date, ignored.", ds);
|
||||
usage();
|
||||
}
|
||||
}
|
||||
|
||||
__dead
|
||||
static void
|
||||
usage(void)
|
||||
{
|
||||
(void)fprintf(stderr, "usage: %s [-ax] [-d MMDD[[YY]YY]"
|
||||
" [-f fname] [-l days] [-w days]\n", getprogname());
|
||||
exit(1);
|
||||
}
|
||||
|
|
@ -1,267 +0,0 @@
|
|||
01/01 J.D. Salinger born, 1919
|
||||
01/01 Paul Revere born in Boston, 1735
|
||||
01/01 Heinz Zemanek born in Vienna, Austria, 1920
|
||||
01/02 Isaac Asimov born in Petrovichi, Russian SFSR (now Russia), 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/08 Stephen Hawking born in Oxford, England, 1942
|
||||
01/10 Ethan Allen born, 1738
|
||||
01/11 Alexander Hamilton born in Nevis, British West Indies, 1757?
|
||||
01/12 "Long" John Baldry 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, 1929
|
||||
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 Buzz Aldrin born, 1930
|
||||
01/20 George Burns born, 1898
|
||||
01/21 Vladimir 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/24 John Belushi 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) 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 Thomas Edison born, 1847
|
||||
02/11 William Henry Fox Talbot born, 1800, 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 Frederick 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 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/11 Douglas Adams born, 1952
|
||||
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/15 Julius Caesar assassinated by Brutus; Ides of March, 44 BC
|
||||
03/15 J.J. Robert's Birthday in Liberia
|
||||
03/16 George Clymer born, 1739
|
||||
03/16 James Madison born, 1751
|
||||
03/23 Thomas Kelly, Father of the Lunar module, died, 2002
|
||||
03/24 Harry Houdini born, 1874
|
||||
03/26 Benjamin Thompson born, 1753, Count Rumford; physicist
|
||||
03/26 David Packard died, 1996; age of 83
|
||||
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/30 Queen Elizabeth, the Queen Mother, died at the age of 101, 2002
|
||||
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 Christiaan Huygens 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 Immanuel 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 Carl Friedrich Gauss born, 1777, mathematician & astronomer
|
||||
05/01 Little Walter (Marion Walter Jacobs) 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/11 Douglas Adams died, 2001
|
||||
05/12 Florence Nightingale born in Florence, Italy, 1820
|
||||
05/13 Arthur S. Sullivan born, 1842
|
||||
05/15 Mike Oldfield born in Essex, England, 1953
|
||||
05/19 Ho Chi Minh born, 1890
|
||||
05/21 Plato (Aristocles) born in Athens(?), 427 BC
|
||||
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/03 Henry James born, 1811
|
||||
06/07 (Eugene Henri) Paul Gaugin born, 1848
|
||||
06/07 George Bryan "Beau" Brummel born, 1778
|
||||
06/07 Alan Mathison Turing died, 1954
|
||||
06/08 Frank Lloyd Wright born in Richland Center, Wisconsin, 1869
|
||||
06/13 Alexander the Great dies (323 BC)
|
||||
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/22 Konrad Zuse born in Berlin, Germany, 1910
|
||||
06/23 Alan Mathison Turing born, 1912
|
||||
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/04 John Adams and Thomas Jefferson die on same day, 1826
|
||||
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 born in London, 1939
|
||||
07/25 Steve Goodman born in Chicago, 1948
|
||||
07/29 Benito 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/12 Thomas Mann's Death, 1955
|
||||
08/13 Annie Oakley born, 1860
|
||||
08/13 Fidel Castro born, 1927
|
||||
08/17 Mae West born, 1892
|
||||
08/18 Meriwether Lewis born, 1774, American explorer
|
||||
08/20 Leon Trotsky assassinated, 1940
|
||||
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/09 Dennis Ritchie born in Bronxville, New York, 1941
|
||||
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/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 Buonarroti born in Caprese, Italy, 1573
|
||||
09/28 Pompey (Gnaeus Pompeius Magnus) born in Rome, 106 BC
|
||||
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/08 Dennis Ritchie died in Murray Hill, New Jersey, 2011
|
||||
10/13 Lenny Bruce 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/16 Dr. Jonathan B. Postel dies at age 55, 1998
|
||||
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 born, 1728
|
||||
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 Robert Francis Kennedy (RFK) born in Boston, Massachusetts, 1925
|
||||
11/26 Charles Schulz born in Minneapolis, 1922
|
||||
11/26 Norbert Wiener born in Columbia, Missouri, 1894
|
||||
11/29 John Mayall born in Cheshire, England, 1933
|
||||
11/30 Cleopatra died, 30 BC
|
||||
11/30 Mark Twain (Samuel Clemens) 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), 65 BC
|
||||
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/18 Konrad Zuse died, 1995
|
||||
12/20 Carl Sagan died, 1996
|
||||
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
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
01/06* Epiphany
|
||||
02/09* Shrove Tuesday / Mardi Gras (day before Ash Wednesday)
|
||||
02/10* Ash Wednesday (First day of Lent)
|
||||
03/20* Palm Sunday (7 days before Easter)
|
||||
03/24* Maundy Thursday (3 days before Easter)
|
||||
03/25* Good Friday (2 days before Easter)
|
||||
03/27* Easter Sunday
|
||||
05/01* Rogation Sunday
|
||||
05/05* Ascension Day (10 days before Pentecost)
|
||||
05/15* Pentecost (Whitsunday)
|
||||
05/16* Whitmonday
|
||||
05/22* Trinity Sunday (7 days after Pentecost)
|
||||
05/26* Corpus Christi (11 days after Pentecost)
|
||||
10/18 Feast Day of St. Luke
|
||||
11/29* First Sunday of Advent (4th Sunday before Christmas)
|
||||
12/06 St. Nicholas' Day
|
||||
12/25 Feast of the Nativity (Christmas)
|
||||
|
|
@ -1,68 +0,0 @@
|
|||
01/01 The Epoch (Time 0 for UNIX systems, Midnight GMT, 1970)
|
||||
01/01 ARPANET converts from NCP to TCP/IP - the Internet is born, 1983
|
||||
01/01 AT&T officially divests its local Bell companies, 1984
|
||||
01/03 Apple Computer incorporated, 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/1982)
|
||||
01/22 Apple airs "1984" commercial during Superbowl XVIII, 1984
|
||||
01/24 Data General Nova introduced, 1969
|
||||
01/24 First Apple Macintosh released, 1984
|
||||
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, 1976
|
||||
03/09 "GOTO considered harmful" (E.J. Dijkstra) published in CACM, 1968
|
||||
03/14 LISP introduced, 1960
|
||||
03/21 NetBSD project born, 1993
|
||||
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/01 Apple Computer founded, 1976
|
||||
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/20 Apple announces the Apple ][ at the 1st West Coast Computer Faire, 1977
|
||||
04/28 Zilog Z-80 introduced, 1974
|
||||
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, 1965
|
||||
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/19 FreeBSD project born, 1993
|
||||
06/23 IBM unbundles software, 1969
|
||||
06/30 First advanced degree on computer related topic: to H. Karamanian,
|
||||
Temple Univ., Phila, 1948, for symbolic differentiation 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, 1978
|
||||
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
|
||||
|
|
@ -1,519 +0,0 @@
|
|||
01/01 Julian Calendar takes effect, 45 BC
|
||||
01/01 Haitian Independence Proclaimed, 1803
|
||||
01/01 Emancipation Proclamation enters effect, 1863
|
||||
01/01 United Nations created, 1942
|
||||
01/02 Reconquest of Spain completed, 1492
|
||||
01/02 Russian Fleet surrenders to Japan at Port Arthur, 1905
|
||||
01/03 Martin Luther excommunicated, 1521
|
||||
01/03 Emperor Meiji Restored to throne in Japan, 1868
|
||||
01/04 Single European Currency debuts, 1999
|
||||
01/04 New York Stock Exchange opens first permanent headquarters, 1865
|
||||
01/04 Burma becomes independent, 1948
|
||||
01/05 Prague Spring begins, 1968
|
||||
01/05 -50 degrees F, Strawberry UT, 1913
|
||||
01/05 The FCC hears the first demonstration of FM radio, 1940
|
||||
01/06 Harold Godwinson crowned King Harold II of England, 1066
|
||||
01/06 Electric Telegraph first tested by Samuel Morse, 1838
|
||||
01/07 Pol Pot overthrown, 1979
|
||||
01/07 Calais, last continental holding of England, falls to France, 1558
|
||||
01/08 Major General Andrew Jackson leads US troops to victory at
|
||||
Battle of New Orleans, 1815
|
||||
01/09 Cruise ship RMS Queen Elizabeth destroyed by fire, 1972
|
||||
01/10 First meeting of United Nations General Assembly in London, 1946
|
||||
01/10 Thomas Paine's Common Sense published, 1776
|
||||
01/10 League of Nations instituted, 1920
|
||||
01/10 Lend-Lease Act introduced, 1941
|
||||
01/11 Milk delivered in bottles for first time, 1878
|
||||
01/11 Amelia Earhart flies from Hawaii to California, 1935
|
||||
01/12 Zulu War begins, 1879
|
||||
01/12 Siege of Leningrad ends, 1943
|
||||
01/12 Santa Clara, California founded, 1777
|
||||
01/13 First live radio concert broadcast, by Enrico Caruso,
|
||||
broadcast from New York, 1910
|
||||
01/14 United Nations condemns Soviet invasion of Afghanistan, 1980
|
||||
01/14 Treaty of Paris ratified by Continental Congress, officially
|
||||
establishing independent United States, 1784
|
||||
01/15 Elizabeth I crowned Queen of England, 1559
|
||||
01/16 Prohibition takes effect, 1919
|
||||
01/16 Reza Shah Pallavi flees Iran, 1979
|
||||
01/16 First Persian Gulf War begins, 1991
|
||||
01/16 Chevy Corvette introduced, 1953
|
||||
01/17 Over $2 million stolen in "Great Brinks Robbery" in Boston, 1950
|
||||
01/18 James Cook discovers Hawaii, 1778
|
||||
01/18 Robert Falcon Scott reaches South Pole, 1912
|
||||
01/18 First Australian penal colony established, 1788
|
||||
01/19 Indira Ghandi becomes Prime Minister of India, 1966
|
||||
01/19 First college basketball game played, Chicago beats Iowa 15-12, 1896
|
||||
01/20 Hong Kong ceded to Britain, 1841
|
||||
01/20 US Hostages released from Iran, 1981
|
||||
01/21 First commercial flight of Concorde SST, 1976
|
||||
01/21 King Louis XVI executed, 1793
|
||||
01/22 First British colonists arrive in New Zealand, 1840
|
||||
01/22 First Russian Revolution begins, 1905
|
||||
01/22 Battle of Tobruk concludes, 1941
|
||||
01/23 USS Pueblo seized by North Korea, 1968
|
||||
01/23 First insulin injection for diabetes, 1922
|
||||
01/23 Peace treaty ending Vietnam war announced, 1973
|
||||
01/24 Eskimo Pie patented by Christian Nelson, 1922
|
||||
01/24 Joseph Marshall finds Gold at Sutter's Mill in California, 1848
|
||||
01/24 Last IJA soldier captured in Guam, 1972
|
||||
01/24 The Pleasure Garden, first Alfred Hitchcock film opens in London, 1927
|
||||
01/25 First Winter Olympics held in Charmonix, 1924
|
||||
01/25 Reporter Nellie Bly arrives in New York, completing
|
||||
circumnavigation of the globe in 72 days, 6 hours, 11
|
||||
minutes, 1890
|
||||
01/26 Republic of India founded, 1950
|
||||
01/26 Barcelona falls to Nationalist forces, 1939
|
||||
01/26 Auschwitz liberated, 1945
|
||||
01/26 Sydney settled, 1788
|
||||
01/27 Somali dictator Muhammad Siyad Barre flees country, 1991
|
||||
01/27 Grissom, White and Chaffe die in fire aboard Apollo I, 1967
|
||||
01/27 Paris Peace Accords signed, ending Vietnam War, 1973
|
||||
01/28 Space Shuttle Challenger (51-L) explodes 74 seconds after liftoff
|
||||
killing Scobee, Smith, McNair, Resnick, Jarvis, Onizuka and McAuliffe,
|
||||
1986
|
||||
01/29 Stanley Kubrick's Dr. Strangelove premieres, 1964
|
||||
01/30 Mohandas Gandhi assassinated in New Delhi, 1948
|
||||
01/30 King Charles I executed by Cromwell's forces, 1649
|
||||
01/30 Tet Offensive begins, 1968
|
||||
01/31 "Ham" the chimpanzee soars into space aboard Mercury-Redstone 2, 1961
|
||||
01/31 Explorer I launched, resulting in discovery of Van Allen Belt, 1958
|
||||
|
||||
02/01 "Secret Storm", first TV soap opera airs, 1954
|
||||
02/01 Forces lead by the Ayatollah Khomeini take over Iran, 1979
|
||||
02/01 Space Shuttle Columbia (STS-107) disintegrates over Texas
|
||||
during re-entry killing Husband, Anderson, Brown, Chawla,
|
||||
Clark, McCool, Ramon, 2003
|
||||
02/01 First session of the United States Supreme Court, 1790
|
||||
02/01 First automobile insurance policy issued by Travellers
|
||||
Insurance of Hartford, CT, 1898
|
||||
02/01 Land battle of Guadalcanal ends with Japanese evacuation after
|
||||
seven months of fighting, 1943
|
||||
02/02 Mexican-American war ends with signing of Treaty of Guadalupe
|
||||
Hidalgo, 1848
|
||||
02/02 Last German troops in Stalingrad surrender, 1943
|
||||
02/03 Soviet probe Lunik 9 makes first controlled landing on Moon, 1966
|
||||
02/03 Sixteenth Amendment to US Constitution, establishing first Federal
|
||||
Income Tax, takes effect, 1913
|
||||
02/04 George Washington elected first President of the United States, 1789
|
||||
02/04 Confederate States of America formed, 1861
|
||||
02/04 Roosevelt, Churchill, and Stalin meet at Yalta to determine
|
||||
shape of post-war Europe, 1945
|
||||
02/04 Cybernet inaugurated, 1969
|
||||
02/04 James Fenimore Cooper's The Last of the Mohicans published, 1826
|
||||
02/05 New Mexican Constitution proclaimed, founding modern nation
|
||||
of Mexico, 1917
|
||||
02/05 First Walk/Don't Walk sign installed, New York City, 1952
|
||||
02/05 Last Soviet troops pull out of Kabul, 1989
|
||||
02/06 John Steinbeck's Of Mice and Men published, 1937
|
||||
02/07 Beatles arrive in New York, 1964
|
||||
02/07 Great Baltimore Fire begins, 1904
|
||||
02/07 Bruce McCandless completes first untethered spacewalk, 1984
|
||||
02/07 Maastricht Treaty signed, establishing European Union, 1992
|
||||
02/07 Soviet Communist Party relinquishes monopoly on political power, 1990
|
||||
02/08 Mary Queen of Scots beheaded at Fotheringhay Castle, 1587
|
||||
02/08 Russo-Japanese war begins with surprise naval attack on
|
||||
Port Arthur by Japanese forces, 1904
|
||||
02/09 First US combat troops arrive in Vietnam, 1965
|
||||
02/09 -51 degrees F, Vanderbilt MI, 1934
|
||||
02/10 Seven Years' War ends, 1763
|
||||
02/11 Japan becomes fourth nation to complete successful space
|
||||
launch, 1970
|
||||
02/11 Nelson Mandela freed, 1990
|
||||
02/12 Last Emperor of China abdicates throne, 1912
|
||||
02/12 Anatoly Scharansky released from Soviet prison camp, 1986
|
||||
02/12 George Gershwin's Rhapsody in Blue debuts, 1924
|
||||
02/13 William and Mary proclaimed King and Queen of England after
|
||||
Glorious Revolution, 1689
|
||||
02/14 Sandinistas agree to free elections in Nicaragua, 1989
|
||||
02/14 Battle of the Kasserine Pass, 1943
|
||||
02/15 Singapore surrenders to Japanese forces, 1942
|
||||
02/15 USS Maine explodes in Havana harbor, leading to Spanish-American
|
||||
war, 1898
|
||||
02/15 Canadian Maple-Leaf Flag adopted, 1965
|
||||
02/16 Nylon patented, 1937
|
||||
02/16 Raiding party led by Stephen Decatur burns captured US
|
||||
frigate in Tripoli harbor, 1804
|
||||
02/16 Fidel Castro sworn in as Prime Minister of Cuba, 1959
|
||||
02/17 China invades Vietnam, resulting in nine days of fighting
|
||||
before Chinese retreat, 1979
|
||||
02/18 Charleston, SC surrendered to Union forces, 1865
|
||||
02/18 Pluto discovered by Clyde Tombaugh, Lowell Observatory, AZ, 1930
|
||||
02/19 US Marines land on Iwo Jima, 1945
|
||||
02/19 First prototype Ford Thunderbird completed, 1954
|
||||
02/19 Donner Party rescued after four months, 1847
|
||||
02/20 John Glenn orbits the Earth 3 times, 1962
|
||||
02/21 Battle of Verdun begins, 1916
|
||||
02/21 First telephone directory, New Haven, Connecticut, 1878
|
||||
02/21 Karl Marx's Communist Manifesto published, 1848
|
||||
02/21 Richard Nixon arrives in China for historic eight-day visit, 1972
|
||||
02/22 Walt Disney's Cinderella opens, 1950
|
||||
02/23 US Flag raised over Mount Suribachi on Iwo Jima, 1945
|
||||
02/24 Impeachment proceedings against Andrew Johnson begin, 1868
|
||||
02/24 Tet Offensive ends with recapture of Hue by US and South
|
||||
Vietnamese forces, 1968
|
||||
02/24 Ground offensive begins in first Gulf War, 1991
|
||||
02/25 Ferdinand Marcos flees the Philippines, 1986
|
||||
02/25 Bloodless coup leads to Communist government in Czechoslovakia, 1948
|
||||
02/26 World Trade Center bombed, killing 6, 1993
|
||||
02/26 Free elections held in Nicaragua, Sandinistas ousted, 1990
|
||||
02/27 Reichstag building burns, 1933
|
||||
02/27 Kuwait liberated, ending offensive ground operations in First Gulf War, 1991
|
||||
02/28 The "French Connection" drug bust occurs in Marseilles, 1972
|
||||
02/29 French and Indian raid on Deerfield MA kills 56 as part of
|
||||
Queen Anne's War, 1704
|
||||
|
||||
03/01 Yellowstone National Park established by President Grant, 1872
|
||||
03/01 Peace Corps established by President Kennedy, 1961
|
||||
03/01 Twenty-month-old son of Charles Lindbergh kidnapped and killed, 1932
|
||||
03/02 Texas declares independence from Mexico, 1836
|
||||
03/02 Importation of slaves into United States prohibited, 1807
|
||||
03/02 Pioneer 10 launched to explore Jupiter and beyond, 1973
|
||||
03/02 Soviet and Chinese troops clash along Ussuri river, 1969
|
||||
03/03 Treaty of Brest-Litovsk ends Russian participation in First
|
||||
World War, 1918
|
||||
03/03 Finland declares war on Germany, 1945
|
||||
03/04 United States Constitution takes effect, and Congress meets
|
||||
in New York, 1789
|
||||
03/05 British troops fire into snowball-throwing crowd in Boston
|
||||
Massacre, 1770
|
||||
03/06 Alamo falls to forces of Mexican General Santa Anna after
|
||||
13 days of siege, 1836
|
||||
03/06 Dutch Resistance ambush, kill SS Lt. General Hanns Rauter
|
||||
in Apeldoorn, 1945
|
||||
03/07 Nazi forces re-militarize Rheinland in violation of Treaty
|
||||
of Versailles and Locarno Pact, 1936
|
||||
03/07 Sheikh Mujib Rahman becomes first elected leader of
|
||||
Bangladesh, 1973
|
||||
03/08 `February Revolution' in Russia begins on February 23 of
|
||||
calendar then in use in Russia, 1917
|
||||
03/08 Dutch forces on Java surrender to the Japanese, 1942
|
||||
03/09 USS Monitor battles CSS Virginia (USS Merrimac) in world's
|
||||
first battle between ironclad warships, 1862
|
||||
03/09 Former Last Emperor of China becomes regent of Japanese
|
||||
puppet state of Manchukuo, 1932
|
||||
03/09 US forces land at Vera Cruz in largest amphibious landing
|
||||
before World War II, 1847
|
||||
03/10 Alexander Graham Bell conducts first successful telephone
|
||||
experiment, 1876
|
||||
03/10 Jan Masaryk dead in Czechoslovakia in reported suicide, 1948
|
||||
03/11 Lend-Lease Act signed, 1941
|
||||
03/11 Mikhail Gorbachev becomes Premier of USSR, 1985
|
||||
03/11 Lithuania declares independence from USSR, 1990
|
||||
03/12 Austria annexed by Germany, 1938
|
||||
03/12 Mahatma Ghandi begins march to sea in protest of British Salt Tax, 1930
|
||||
03/13 Uranus discovered by William Hershel, 1781
|
||||
03/13 Tsar Alexander II of Russia assassinated, 1881
|
||||
|
||||
|
||||
03/15 Tsar Nicholas II abdicates throne of Russia, 1917
|
||||
|
||||
|
||||
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/24 Construction of New York subway system begins, 1900
|
||||
03/26 Popeye statue unveiled, Crystal City TX Spinach Festival, 1937
|
||||
03/27 Khrushchev becomes Premier of Soviet Union, 1958
|
||||
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
|
||||
03/31 Pioneer 10 mission ends, having travelled 6 billion miles
|
||||
and provided close-up pictures of Jupiter and first data on
|
||||
interstellar space, 1997
|
||||
|
||||
04/04 Martin Luther King assassinated in Memphis, Tennessee, 1968
|
||||
04/04 NATO Established, 1949
|
||||
04/05 US nationalises Gold at a value of $20.67, 1933
|
||||
04/06 Joseph Smith founds Mormon Church, 1830
|
||||
04/09 Lee surrenders to Grant at Appomattox Courthouse, 1865
|
||||
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/14 Lincoln shot in Ford's Theatre by John Wilkes Booth, 1865
|
||||
04/14 Titanic hits iceberg and sinks, 1912
|
||||
04/15 Ray Kroc opens first McDonalds in Des Plaines, IL, 1955
|
||||
04/18 First Laundromat opens, Fort Worth Texas, 1934
|
||||
04/18 San Francisco earthquake, 1906
|
||||
04/19 Warsaw Ghetto uprising, 1943
|
||||
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 Philippines, 1521
|
||||
04/29 Zipper patented by Gideon Sindback, 1913
|
||||
|
||||
05/06 Hindenburg explodes and burns upon landing at Lakehurst, NJ, 1939
|
||||
05/07 Germany surrenders after WWII, 1945
|
||||
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/18 Battle of Las Piedras in Uruguay
|
||||
05/18 Napoleon crowned Emperor, 1804
|
||||
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/24 Battle of Pinchincha in Ecuador
|
||||
05/25 Successful test of the limelight in Purfleet, England, 1830
|
||||
05/27 Golden Gate Bridge opens, 1937
|
||||
05/29 Edmund Hillary and Tenzing Norkay climb Mt. Everest, 1953
|
||||
|
||||
06/04 Roquefort cheese developed, 1070
|
||||
06/05 Robert Kennedy assassinated, 1968
|
||||
08/15 US leaves the Gold Standard, 1971
|
||||
06/06 First drive-in movie, 1933
|
||||
06/06 Normandy landing, 1944
|
||||
06/10 Death of Alexander the Great, 323 B.C.
|
||||
06/13 Pioneer 10 flies past Neptune's orbit, the first human artifact
|
||||
to travel beyond the orbits of all known planets, 1983
|
||||
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/19 Lizzie Borden acquitted, 1893
|
||||
06/20 Victoria crowned, 1837
|
||||
06/21 Berlin airlift begins, 1948
|
||||
06/23 Slavery abolished in England, 1772
|
||||
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/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 290 people killed after Iran Airlines A300 shot down by USA, 1988
|
||||
07/04 Battles of Vicksburg and Gettysburg won by Union forces, 1863
|
||||
07/04 Cloudy, 76 degrees, Philadelphia PA, 1776
|
||||
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/13 Women first compete in Olympic games, 1908
|
||||
07/16 Detonation of the first atomic bomb at Alamogordo, NM, 1945
|
||||
07/17 Disneyland opens, 1955
|
||||
07/18 Ty Cobb gets 4000th base hit, 1927
|
||||
07/20 Armstrong and Aldrin land on moon, 1969
|
||||
07/21 First Train Robbery, Jesse James gets $3000 near Adair, Iowa, 1873
|
||||
07/23 Ice cream cone introduced, St. Louis MO, 1904
|
||||
07/24 Scopes Monkey Trial, 1925
|
||||
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/03 Columbus sets sail for Cathay, 1492
|
||||
08/03 USS Nautilus crosses under north polar ice cap, 1958
|
||||
08/04 Axe murder of Andrew and Abbey Borden, 1892
|
||||
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 France Ends War in Indochina, 1954
|
||||
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/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 right to vote, Nineteenth Amendment to US Constitution
|
||||
becomes law, 1920
|
||||
08/27 Edgar Rice Burroughs' "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/30 Japan Stationery Co. sells first felt-tipped pen, 1960
|
||||
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/05 The first Continental Congress was convened in Philadelphia, 1774
|
||||
09/06 149 Pilgrims set forth from England aboard the Mayflower, 1620
|
||||
09/06 Pres. McKinley shot, 1901
|
||||
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/11 Twin Towers fall in terrorist attacks, 2001
|
||||
09/12 German paratroopers rescue Mussolini from captivity in Rome, 1943
|
||||
09/12 Germany annexes Sudetenland, 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 Salem, Massachusetts, is founded, 1629
|
||||
09/14 The Selective Service Act establishes the first peacetime draft, 1940
|
||||
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/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 The first Soviet atomic bomb explodes, 1949
|
||||
09/23 Philippine President Ferdinand Marcos declares martial law, 1972
|
||||
09/23 The New York Knickerbockers becomes the first U.S. Baseball club, 1845
|
||||
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 John Bunyan's "Pilgrim's Progress" published, 1678
|
||||
09/28 A Greek soldier runs 26+ miles after the Persian defeat at Marathon,
|
||||
490BC
|
||||
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 in as the first black Supreme Court Justice, 1967
|
||||
10/04 Crimean war begins, 1853
|
||||
10/04 Sputnik 1, world's first orbiting satellite launched, 1957
|
||||
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 German Democratic Republic in 1949
|
||||
10/07 Georgia Tech. beats Cumberland Univ. 222-0, 1916
|
||||
10/07 Mother Teresa of Calcutta awarded the Nobel Peace Prize, 1979
|
||||
10/08 Great Chicago Fire, 1871
|
||||
10/09 First two-way telephone conversation, 1876
|
||||
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/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/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/18 Boston Shoemakers form first U.S. labor org., 1648
|
||||
10/18 Soviets announce 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 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/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 separate nations, 1918
|
||||
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 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 Roosevelt establishes the Civil Works Administration, 1933
|
||||
11/10 41 Women arrested in suffragette demonstrations near White House, 1917
|
||||
11/10 Cpt. Wirz, commandant of Andersonville Prison hanged, 1865
|
||||
11/10 Henry Morton Stanley asks David Livingstone, "Dr. Livingstone, 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/15 Niagara Falls power plant startup, 1896
|
||||
11/16 Opening of the Suez Canal, 1869
|
||||
11/17 46,000 meteoroids fall over AZ in 20 minutes, 1966
|
||||
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/22 Kennedy shot in Dallas, Texas by Lee Harvey Oswald, 1963
|
||||
11/23 First broadcast of Dr. Who, 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 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 led by Dr. Barnard, 1967
|
||||
12/04 Washington takes leave of his officers at Fraunce's Tavern, NYC, 1783
|
||||
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/05 Nelson Mandela dies aged 95, 2013
|
||||
12/07 Japan bombs Pearl Harbor, 1941
|
||||
12/09 Ball-bearing roller skates patented, 1884
|
||||
12/10 Metric system established in France, 1799
|
||||
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/15 Bill of Rights adopted, 1791
|
||||
12/15 James Naismith invents basketball, Canada, 1891
|
||||
12/16 Kazakhstan declares independence from USSR, 1991
|
||||
12/20 U.S. buys ~1,000,000 sq. miles of Louisiana for ~$20/sq.mi.
|
||||
12/27 Ether first used as anesthetic in childbirth, 1845
|
||||
12/28 Comet Kohoutek at perihelion, 1973
|
||||
12/29 Massacre at Wounded Knee, 1890
|
||||
12/30 First Los Angeles freeway dedicated, 1940
|
||||
|
|
@ -1,568 +0,0 @@
|
|||
01/01 New Year's Day
|
||||
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 Coming-of-Age Day (2nd Monday)
|
||||
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 Ethiopian 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/17* Martin Luther King Day in New York (3rd Sunday)
|
||||
01/18* Lee-Jackson Day in Virginia (3rd Monday)
|
||||
01/18* Robert E. Lee's Birthday in Alabama & Mississippi (3rd Monday)
|
||||
01/21 Our Lady of Altagracia in Dominican Republic
|
||||
01/23 Feast of St. Ildefonsus
|
||||
01/23 National Handwriting Day
|
||||
01/24 Economic Liberation Day in Togo
|
||||
01/26 Australia Day in Australia
|
||||
01/26 Republic Day in India
|
||||
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 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/23* 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/15 Day of the 1848 revolution in Hungary
|
||||
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 Tunisia
|
||||
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/28* 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 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 Songkran Day in Thailand
|
||||
04/14 Day of the Americas in Honduras
|
||||
04/15 Bengali New Year in Bangladesh
|
||||
04/18* 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
|
||||
03/23* 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/25* Arbor Day in Wyoming (last Monday)
|
||||
04/25* 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/03 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/02* Bank Holiday in UK (first Monday in May)
|
||||
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 Guatemala
|
||||
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/20 Mecklenburg Independence Day in North Carolina
|
||||
05/20 National Day in Cameroon
|
||||
05/16* Memorial Day in Michigan (3rd Monday)
|
||||
05/16* Victoria Day in Canada
|
||||
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/25 Towel Day, a tribute to Douglas Adams
|
||||
06/11* First Day of Shavuot
|
||||
05/30* Bank Holiday in UK (last Monday in May)
|
||||
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/06* Bank Holiday in Rep. of Ireland (first Monday in June)
|
||||
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 Rwanda
|
||||
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 Botswana
|
||||
07/17 Constitution Day in South Korea
|
||||
07/17 Public Holiday in Botswana
|
||||
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 Egyptian 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/01* Bank Holiday in Scotland and Northern Ireland (first Monday in August)
|
||||
08/01* Bank Holiday in Australia, British Columbia, Fiji, Iceland, Ireland,
|
||||
Ontario (first Monday in August)
|
||||
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/19* Admission Day in Hawaii, 1959 (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 and birthday of King St. Istvan
|
||||
08/23 Liberation Days (2 days) in Romania
|
||||
08/24 National Flag Day in Liberia
|
||||
08/25 Constitution Day in Paraguay
|
||||
08/25 Independence Day in Uruguay
|
||||
08/26 Susan B. Anthony Day in Massachusetts
|
||||
08/29* Bank Holiday in England and Wales (last Monday in August)
|
||||
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 Revolution Anniversary Day in Yemen Arab
|
||||
09/28 Confucius' Day in Taiwan
|
||||
09/30 Botswana Day in Botswana
|
||||
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 Botswana
|
||||
10/03 National Foundation Day in South Korea
|
||||
10/03 U.N. Day in Barbados
|
||||
10/03 German Reunification Day in Germany
|
||||
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/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 (2nd Monday)
|
||||
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 Republic
|
||||
10/14 Young People's Day in Zaire
|
||||
10/12* 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 Thailand
|
||||
10/23 Day of the 1956 revolution in Hungary
|
||||
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/26* Bank Holiday in Rep. of Ireland (last Monday in October)
|
||||
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/11 Independence Day in Angola
|
||||
11/11 Remembrance 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 Democratic 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/01 World AIDS Day
|
||||
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 Victory 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/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 Showa day in Japan (used to be Greenery day)
|
||||
05/04 Greenery day in Japan
|
||||
12/23 Emperor's Birthday in Japan
|
||||
04/30 Queen's Birthday in Netherlands, Netherlands Antilles
|
||||
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 Democratic 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 Yemen Democratic Republic
|
||||
06/22 Midsummer Eve in Finland, Sweden
|
||||
06/24 Battle of Carabobob in Venezuela
|
||||
07/01 Union of the Somalia Republic in Somalia
|
||||
07/06* Eid-ul-Fitr (2 days) in Muslim countries
|
||||
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 Guinea-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 Anniversary 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
|
||||
07/20 Ocean Day in Japan
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
01/25* Tu B'Shvat (Feast of Trees)
|
||||
03/23* Fast of Esther (Battle of Purim; 1 day before Purim; fast day)
|
||||
03/24* Purim (Feast of Lots; 30 days before Pesach)
|
||||
04/23* Pesach (First Day of Passover; sabbatical)
|
||||
04/24* Pesach (sabbatical)
|
||||
04/25* Pesach (sabbatical)
|
||||
04/26* Pesach (Last Day of Passover; 8th day of Pesach; sabbatical)
|
||||
05/12* Yom HaAtzma'ut (Israel Independence Day)
|
||||
05/26* Lag B'Omer (Commemoration of the Great Rebellion)
|
||||
06/04* Yom Yerushalayim (Reunification of Jerusalem)
|
||||
06/12* Shavuos (Festival of Weeks; 50 days after Pesach; sabbatical)
|
||||
07/24* Fast of Shiv'a Asar B'Tammuz (Tzom Tammuz) (Romans breach Wall of Jerusalem;
|
||||
fast day)
|
||||
08/14* Fast of Tish'a B'Av (Babylon/Rome destroys Holy Temple; fast day)
|
||||
10/03* First Day of Rosh Hashanah (Jewish Lunar New Year; 5767 == 2006;
|
||||
sabbatical)
|
||||
10/03* Rosh Hashanah (sabbatical)
|
||||
10/04* Fast of Gedalya (Murder of Gedalya and subsequent Exile; 1 day
|
||||
after Rosh Hashanah; fast day)
|
||||
10/12* Yom Kippur (Day of Atonement; 9 days after Rosh Hashanah;
|
||||
sabbatical, fast day)
|
||||
10/17* Succos (Festival of Tabernacles; 14 days after Rosh Hashanah;
|
||||
sabbatical)
|
||||
10/23* Hoshanah Rabba (7th day of Succos)
|
||||
10/24* Shmini Atzeres (8th Day of Gathering; 1 day after Succos; sabbatical)
|
||||
12/06* First Day of Chanukah
|
||||
12/22* Fast of Asara B'Tevet (Babylonians put siege on Jerusalem; fast day)
|
||||
|
|
@ -1,37 +0,0 @@
|
|||
01/05 Fellowship enters Moria (LOTR)
|
||||
01/09 Fellowship reaches Lorien (LOTR)
|
||||
01/17 Passing of Gandalf (LOTR)
|
||||
02/07 Fellowship leaves Lorien (LOTR)
|
||||
02/17 Death of Boromir (LOTR)
|
||||
02/20 Meriadoc & Pippin meet Treebeard (LOTR)
|
||||
02/22 Passing of King Elessar (LOTR)
|
||||
02/24 Ents destroy Isengard (LOTR)
|
||||
02/26 Aragorn takes the Paths of the Dead (LOTR)
|
||||
03/05 Frodo & Samwise encounter Shelob (LOTR)
|
||||
03/08 Deaths of Denethor & Theoden (LOTR)
|
||||
03/18 Destruction of the Ring (LOTR)
|
||||
03/29 Flowering of the Mallorn (LOTR)
|
||||
04/04 Gandalf visits Bilbo (LOTR)
|
||||
04/17 An unexpected party (LOTR)
|
||||
04/23 Crowning of King Elessar (LOTR)
|
||||
05/19 Arwen leaves Lorien to wed King Elessar (LOTR)
|
||||
06/11 Sauron attacks Osgilliath (LOTR)
|
||||
06/13 Bilbo returns to Bag End (LOTR)
|
||||
06/23 Wedding of Elessar & Arwen (LOTR)
|
||||
07/04 Gandalf imprisoned by Saruman (LOTR)
|
||||
07/24 The ring comes to Bilbo (LOTR)
|
||||
07/26 Bilbo rescued from Wargs by Eagles (LOTR)
|
||||
08/03 Funeral of King Theoden (LOTR)
|
||||
08/29 Saruman enters the Shire (LOTR)
|
||||
09/10 Gandalf escapes from Orthanc (LOTR)
|
||||
09/14 Frodo & Bilbo's birthday (LOTR)
|
||||
09/15 Black riders enter the Shire (LOTR)
|
||||
09/18 Frodo and company rescued by Bombadil (LOTR)
|
||||
09/28 Frodo wounded at Weathertop (LOTR)
|
||||
10/05 Frodo crosses bridge of Mitheithel (LOTR)
|
||||
10/16 Boromir reaches Rivendell (LOTR)
|
||||
10/17 Council of Elrond (LOTR)
|
||||
10/25 End of War of the Ring (LOTR)
|
||||
11/16 Bilbo reaches the Lonely Mountain (LOTR)
|
||||
12/05 Death of Smaug (LOTR)
|
||||
12/16 Fellowship begins Quest (LOTR)
|
||||
|
|
@ -1,185 +0,0 @@
|
|||
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 Philadelphia, 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/23 Samuel Barber died, 1981
|
||||
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/08 John Towner Williams born in New York City, 1932; composer
|
||||
well-known for his many motion picture and television scores
|
||||
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 George Frideric 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/09 Samuel Barber is born in West Chester, Pennsylvania, 1910
|
||||
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 Johann Sebastian Bach born in Eisenach, Germany, 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 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 Peter Ilyich Tchaikovsky 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 quadraphonic 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/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/02 Edward Elgar (Sir) born in Worcester, England, 1857
|
||||
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 Garland 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 LPs, 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 Comiskey 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 Birth of Jerome "Jerry" Garcia (Grateful Dead), 1942
|
||||
08/01 The Concert for Bangladesh takes place at Madison Square Garden, 1971
|
||||
08/04 John Lennon points out "the Beatles are more popular than Jesus", 1966
|
||||
08/09 Death of Jerome "Jerry" Garcia (Grateful Dead), 1995
|
||||
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, 1962
|
||||
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
|
||||
08/27 Stevie Ray Vaughan dies in a helicopter crash, 1990
|
||||
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/18 Jimi Hendrix dies of an overdose, 1970
|
||||
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, 1898
|
||||
10/03 Stevie Ray Vaughan born in Dallas, TX, 1954
|
||||
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 St. Louis, Missouri, 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/27 Lou Reed dies aged 71, 2013
|
||||
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 Ludwig van Beethoven born in Bonn, Germany, 1770
|
||||
12/16 Don McLean's "American Pie" is released, 1971
|
||||
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
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
01/01 New Year's Day
|
||||
01/14 Julian Calendar New Year's Day
|
||||
01/18* Martin Luther King Day (3rd Monday of January)
|
||||
02/02 Groundhog Day
|
||||
02/14 St. Valentine's Day
|
||||
02/15* President's Day (3rd Monday of February)
|
||||
03/05 Mother-in-Law Day
|
||||
03/13* Daylight Savings Time begins; clocks move forward (2nd Sunday of March)
|
||||
03/17 St. Patrick's Day
|
||||
03/20* Vernal Equinox
|
||||
04/01 April Fool's Day
|
||||
04/15 Income Tax Day
|
||||
04/22 Earth Day
|
||||
04/24* Arbor Day (varies from state to state)
|
||||
05/08* Mother's Day (2nd Sunday of May)
|
||||
05/21* Armed Forces Day (3rd Saturday of May)
|
||||
05/30* Memorial Day (Last Monday of May)
|
||||
06/19* Father's Day (3rd Sunday of June)
|
||||
06/20* Summer Solstice
|
||||
07/04 Independence Day
|
||||
09/05* Labor Day (1st Monday of September)
|
||||
09/10* Grandparent's Day (2nd Sunday of September; varies from state to state)
|
||||
09/22* Autumnal Equinox
|
||||
10/12* Columbus Day (2nd Monday of October)
|
||||
10/31 All Hallows Eve (Halloween)
|
||||
11/01* Daylight Savings Time ends; clocks move back (First Sunday in November)
|
||||
11/08* Election Day (1st Tuesday after 1st Monday)
|
||||
11/11 Veterans' Day
|
||||
11/26* Thanksgiving Day (Fourth Thursday in November)
|
||||
12/22* Winter Solstice
|
||||
12/24 Christmas Eve
|
||||
12/25 Christmas
|
||||
12/31 New Year's Eve
|
||||
|
|
@ -1,38 +0,0 @@
|
|||
/* $NetBSD: pathnames.h,v 1.6 2004/12/07 16:47:32 jwise Exp $ */
|
||||
|
||||
/*
|
||||
* 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. 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"
|
||||
#define _PATH_CALENDARS "/usr/share/calendar"
|
||||
#define _PATH_SYSTEM_CALENDAR "/etc/calendar"
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
# $NetBSD: Makefile,v 1.6 2013/08/11 06:39:47 dholland Exp $
|
||||
# @(#)Makefile 8.1 (Berkeley) 6/6/93
|
||||
|
||||
PROG= checknr
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
|
|
@ -1,168 +0,0 @@
|
|||
.\" $NetBSD: checknr.1,v 1.15 2004/07/09 11:40:00 wiz Exp $
|
||||
.\"
|
||||
.\" 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. 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 January 21, 2002
|
||||
.Dt CHECKNR 1
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm checknr
|
||||
.Nd check nroff/troff files
|
||||
.Sh SYNOPSIS
|
||||
.Nm
|
||||
.Op Fl fs
|
||||
.Op Fl a Ns Ar \&.x1.y1.x2.y2. ... \&.xn.yn
|
||||
.Op Fl c Ns Ar \&.x1.x2.x3 ... \&.xn
|
||||
.Ar file
|
||||
.Sh DESCRIPTION
|
||||
.Nm
|
||||
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
|
||||
checks the standard input.
|
||||
.Pp
|
||||
Recognized options are:
|
||||
.Bl -tag -width xxx -compact -offset indent
|
||||
.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
|
||||
to ignore
|
||||
.Ql \ef
|
||||
font changes.
|
||||
.It Fl s
|
||||
Ignore
|
||||
.Ql \es
|
||||
size changes.
|
||||
.El
|
||||
.Pp
|
||||
Delimiters checked are:
|
||||
.Bl -enum -compact -offset indent
|
||||
.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
|
||||
is intended for use on documents that are prepared with
|
||||
.Nm
|
||||
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 .
|
||||
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
|
||||
knows about the
|
||||
.Xr ms 7
|
||||
and
|
||||
.Xr me 7
|
||||
macro packages,
|
||||
as well as the macros from
|
||||
.Xr mdoc 7 .
|
||||
.Sh DIAGNOSTICS
|
||||
.Bd -ragged -compact
|
||||
Complaints about unmatched delimiters.
|
||||
Complaints about unrecognized commands.
|
||||
Various complaints about the syntax of commands.
|
||||
.Ed
|
||||
.Sh SEE ALSO
|
||||
.Xr nroff 1 ,
|
||||
.Xr troff 1 ,
|
||||
.Xr mdoc 7 ,
|
||||
.Xr me 7 ,
|
||||
.Xr ms 7
|
||||
.Sh HISTORY
|
||||
The
|
||||
.Nm
|
||||
command appeared in
|
||||
.Bx 4.0 .
|
||||
Basic
|
||||
.Xr mdoc 7
|
||||
support appeared in
|
||||
.Nx 1.6 .
|
||||
.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.
|
||||
.Pp
|
||||
.Xr mdoc 7
|
||||
macros that are not at the beginning of the line are not recognized.
|
||||
Among others, this results in too many
|
||||
.Ql Unmatched Zz
|
||||
errors.
|
||||
|
|
@ -1,644 +0,0 @@
|
|||
/* $NetBSD: checknr.c,v 1.24 2013/08/12 14:03:18 joerg Exp $ */
|
||||
|
||||
/*
|
||||
* 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. 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.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
__COPYRIGHT("@(#) Copyright (c) 1980, 1993\
|
||||
The Regents of the University of California. All rights reserved.");
|
||||
#endif /* not lint */
|
||||
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)checknr.c 8.1 (Berkeley) 6/6/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: checknr.c,v 1.24 2013/08/12 14:03:18 joerg Exp $");
|
||||
#endif
|
||||
#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 <ctype.h>
|
||||
#include <err.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.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.
|
||||
*/
|
||||
static 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];
|
||||
static int stktop;
|
||||
|
||||
/*
|
||||
* The kinds of opening and closing brackets.
|
||||
*/
|
||||
static struct brstr {
|
||||
const char *opbr;
|
||||
const 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"},
|
||||
/* The -mdoc package */
|
||||
{"Ao", "Ac"},
|
||||
{"Bd", "Ed"},
|
||||
{"Bk", "Ek"},
|
||||
{"Bo", "Bc"},
|
||||
{"Do", "Dc"},
|
||||
{"Fo", "Fc"},
|
||||
{"Oo", "Oc"},
|
||||
{"Po", "Pc"},
|
||||
{"Qo", "Qc"},
|
||||
{"Rs", "Re"},
|
||||
{"So", "Sc"},
|
||||
{"Xo", "Xc"},
|
||||
/* 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.
|
||||
*/
|
||||
static const char *knowncmds[MAXCMDS] = {
|
||||
"$c", "$f", "$h", "$p", "$s", "%A", "%B", "%C", "%D", "%I", "%J", "%N",
|
||||
"%O", "%P", "%Q", "%R", "%T", "%V", "(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", "Ac", "Ad", "An", "Ao", "Ap", "Aq", "Ar", "At", "B" , "B1",
|
||||
"B2", "BD", "BE", "BG", "BL", "BS", "BT", "BX", "Bc", "Bd", "Bf",
|
||||
"Bk", "Bl", "Bo", "Bq", "Bsx", "Bx", "C1", "C2", "CD", "CM", "CT",
|
||||
"Cd", "Cm", "D" , "D1", "DA", "DE", "DF", "DL", "DS", "DT", "Db", "Dc",
|
||||
"Dd", "Dl", "Do", "Dq", "Dt", "Dv", "EC", "EF", "EG", "EH", "EM",
|
||||
"EN", "EQ", "EX", "Ec", "Ed", "Ef", "Ek", "El", "Em", "Eo", "Er",
|
||||
"Ev", "FA", "FD", "FE", "FG", "FJ", "FK", "FL", "FN", "FO", "FQ",
|
||||
"FS", "FV", "FX", "Fa", "Fc", "Fd", "Fl", "Fn", "Fo", "Ft", "Fx",
|
||||
"H" , "HC", "HD", "HM", "HO", "HU", "I" , "ID", "IE", "IH", "IM",
|
||||
"IP", "IX", "IZ", "Ic", "In", "It", "KD", "KE", "KF", "KQ", "KS", "LB",
|
||||
"LC", "LD", "LE", "LG", "LI", "LP", "Lb", "Li", "MC", "ME", "MF",
|
||||
"MH", "ML", "MR", "MT", "ND", "NE", "NH", "NL", "NP", "NS", "Nd",
|
||||
"Nm", "No", "Ns", "Nx", "OF", "OH", "OK", "OP", "Oc", "Oo", "Op",
|
||||
"Os", "Ot", "Ox", "P" , "P1", "PF", "PH", "PP", "PT", "PX", "PY",
|
||||
"Pa", "Pc", "Pf", "Po", "Pp", "Pq", "QE", "QP", "QS", "Qc", "Ql",
|
||||
"Qo", "Qq", "R" , "RA", "RC", "RE", "RL", "RP", "RQ", "RS", "RT",
|
||||
"Re", "Rs", "S" , "S0", "S2", "S3", "SA", "SG", "SH", "SK", "SM",
|
||||
"SP", "SY", "Sc", "Sh", "Sm", "So", "Sq", "Ss", "St", "Sx", "Sy",
|
||||
"T&", "TA", "TB", "TC", "TD", "TE", "TH", "TL", "TM", "TP", "TQ",
|
||||
"TR", "TS", "TX", "Tn", "UL", "US", "UX", "Ud", "Ux", "VL", "Va", "Vt",
|
||||
"WC", "WH", "XA", "XD", "XE", "XF", "XK", "XP", "XS", "Xc", "Xo",
|
||||
"Xr", "[" , "[-", "[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
|
||||
};
|
||||
|
||||
static int lineno; /* current line number in input file */
|
||||
static const char *cfilename; /* name of current file */
|
||||
static int nfiles; /* number of files to process */
|
||||
static int fflag; /* -f: ignore \f */
|
||||
static int sflag; /* -s: ignore \s */
|
||||
static int ncmds; /* size of knowncmds */
|
||||
static int slot; /* slot in knowncmds found by binsrch */
|
||||
|
||||
static void addcmd(char *);
|
||||
static void addmac(const char *);
|
||||
static int binsrch(const char *);
|
||||
static void checkknown(const char *);
|
||||
static void chkcmd(const char *);
|
||||
static void complain(int);
|
||||
static int eq(const char *, const char *);
|
||||
static void nomatch(const char *);
|
||||
static void pe(int);
|
||||
static void process(FILE *);
|
||||
static void prop(int);
|
||||
static void usage(void) __dead;
|
||||
|
||||
int
|
||||
main(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) {
|
||||
char *tmp;
|
||||
|
||||
if (i >= MAXBR)
|
||||
errx(1, "too many pairs");
|
||||
if ((tmp = malloc(3)) == NULL)
|
||||
err(1, "malloc");
|
||||
strlcpy(tmp, cp, 3);
|
||||
br[i].opbr = tmp;
|
||||
if ((tmp = malloc(3)) == NULL)
|
||||
err(1, "malloc");
|
||||
strlcpy(tmp, cp+3, 3);
|
||||
br[i].clbr = tmp;
|
||||
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);
|
||||
fclose(f);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
cfilename = "stdin";
|
||||
process(stdin);
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
|
||||
static void
|
||||
usage(void)
|
||||
{
|
||||
(void)fprintf(stderr,
|
||||
"usage: %s [-fs] [-a.xx.yy.xx.yy...] [-c.xx.xx.xx...] file\n",
|
||||
getprogname());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
static void
|
||||
process(FILE *f)
|
||||
{
|
||||
int i, n;
|
||||
char line[256]; /* the current line */
|
||||
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((unsigned char)mac[0])) {
|
||||
pe(lineno);
|
||||
printf("Empty command\n");
|
||||
} else if (isspace((unsigned char)mac[1])) {
|
||||
mac[1] = 0;
|
||||
} else if (isspace((unsigned char)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(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((unsigned char)pl)) {
|
||||
n = pl - '0';
|
||||
pl = ' ';
|
||||
} else
|
||||
n = 0;
|
||||
while (isdigit((unsigned char)line[++i]))
|
||||
n = 10 * n + line[i] - '0';
|
||||
i--;
|
||||
if (n == 0) {
|
||||
if (stktop >= 0 &&
|
||||
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 (stktop >= 0 &&
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
complain(int i)
|
||||
{
|
||||
pe(stk[i].lno);
|
||||
printf("Unmatched ");
|
||||
prop(i);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
static void
|
||||
prop(int 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);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
chkcmd(const char *mac)
|
||||
{
|
||||
int i;
|
||||
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
nomatch(const char *mac)
|
||||
{
|
||||
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? */
|
||||
static int
|
||||
eq(const char *s1, const char *s2)
|
||||
{
|
||||
return strcmp(s1, s2) == 0;
|
||||
}
|
||||
|
||||
/* print the first part of an error message, given the line number */
|
||||
static void
|
||||
pe(int pelineno)
|
||||
{
|
||||
if (nfiles > 1)
|
||||
printf("%s: ", cfilename);
|
||||
printf("%d: ", pelineno);
|
||||
}
|
||||
|
||||
static void
|
||||
checkknown(const 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.
|
||||
*/
|
||||
static void
|
||||
addcmd(char *line)
|
||||
{
|
||||
char *mac;
|
||||
|
||||
/* grab the macro being defined */
|
||||
mac = line+4;
|
||||
while (isspace((unsigned char)*mac))
|
||||
mac++;
|
||||
if (*mac == 0) {
|
||||
pe(lineno);
|
||||
printf("illegal define: %s\n", line);
|
||||
return;
|
||||
}
|
||||
mac[2] = 0;
|
||||
if (isspace((unsigned char)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.
|
||||
*/
|
||||
static void
|
||||
addmac(const char *mac)
|
||||
{
|
||||
const 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--;
|
||||
if ((*loc = strdup(mac)) == NULL)
|
||||
err(1, "strdup");
|
||||
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.
|
||||
*/
|
||||
static int
|
||||
binsrch(const char *mac)
|
||||
{
|
||||
const char *p; /* pointer to current cmd in list */
|
||||
int d; /* difference if any */
|
||||
int mid; /* mid point in binary search */
|
||||
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;
|
||||
}
|
||||
|
|
@ -1,30 +0,0 @@
|
|||
# $NetBSD: Makefile,v 1.15 2007/05/28 12:06:25 tls Exp $
|
||||
# @(#)Makefile 8.2 (Berkeley) 4/2/94
|
||||
|
||||
.include <bsd.own.mk>
|
||||
|
||||
USE_FORT?= yes # setuid
|
||||
PROG= chpass
|
||||
SRCS= chpass.c edit.c field.c table.c util.c
|
||||
BINOWN= root
|
||||
BINMODE=4555
|
||||
.PATH: ${NETBSDSRCDIR}/lib/libc/gen
|
||||
LINKS= ${BINDIR}/chpass ${BINDIR}/chfn ${BINDIR}/chpass ${BINDIR}/chsh
|
||||
MLINKS= chpass.1 chfn.1 chpass.1 chsh.1
|
||||
|
||||
CPPFLAGS+=-I${NETBSDSRCDIR}/lib/libc/include
|
||||
|
||||
.if (${USE_YP} != "no")
|
||||
SRCS+= pw_yp.c
|
||||
CPPFLAGS+=-DYP
|
||||
DPADD+= ${LIBRPCSVC}
|
||||
LDADD+= -lrpcsvc
|
||||
.else
|
||||
SRCS+= getpwent.c
|
||||
CPPFLAGS.getpwent.c=-UYP
|
||||
.endif
|
||||
|
||||
DPADD+= ${LIBUTIL}
|
||||
LDADD+= -lutil
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
|
|
@ -1,268 +0,0 @@
|
|||
.\" $NetBSD: chpass.1,v 1.25 2012/04/21 12:27:29 roy Exp $
|
||||
.\"
|
||||
.\" 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. 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 April 5, 2012
|
||||
.Dt CHPASS 1
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm chpass ,
|
||||
.Nm chfn ,
|
||||
.Nm chsh
|
||||
.Nd add or change user database information
|
||||
.Sh SYNOPSIS
|
||||
.Nm
|
||||
.Op Fl a Ar list
|
||||
.Op Fl s Ar newshell
|
||||
.Op Fl l
|
||||
.Op user
|
||||
.Nm chpass
|
||||
.Op Fl a Ar list
|
||||
.Op Fl s Ar newshell
|
||||
.Op Fl y
|
||||
.Op user
|
||||
.Sh DESCRIPTION
|
||||
.Nm
|
||||
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
|
||||
.Pq Dq \&:
|
||||
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 .
|
||||
.It Fl l
|
||||
This option causes the password to be updated only in the local
|
||||
password file.
|
||||
When changing only the local password,
|
||||
.Xr pwd_mkdb 8
|
||||
is used to update the password databases.
|
||||
.It Fl y
|
||||
This forces the YP password database entry to be changed, even if
|
||||
the user has an entry in the local database.
|
||||
The
|
||||
.Xr rpc.yppasswdd 8
|
||||
daemon should be running on the YP master server.
|
||||
.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
|
||||
.Bx
|
||||
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
|
||||
.Dq 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 a key for a user's login class.
|
||||
Login classes are defined in
|
||||
.Xr login.conf 5 ,
|
||||
which is a
|
||||
.Xr capfile 5
|
||||
style database of user attributes, accounting, resource and
|
||||
environment settings.
|
||||
.Pp
|
||||
The user's
|
||||
.Ar home directory
|
||||
is the full
|
||||
.Ux
|
||||
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
|
||||
uses
|
||||
.Xr pwd_mkdb 8
|
||||
to update the user database.
|
||||
.Sh ENVIRONMENT
|
||||
The
|
||||
.Xr vi 1
|
||||
editor will be used unless the environment variable
|
||||
.Ev EDITOR
|
||||
is set to an alternative 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/ptmp
|
||||
Lock file for the passwd database
|
||||
.It Pa /tmp/pw.XXXXXX
|
||||
Temporary copy of the user passwd information
|
||||
.It Pa /etc/shells
|
||||
The list of approved shells
|
||||
.El
|
||||
.Sh SEE ALSO
|
||||
.Xr finger 1 ,
|
||||
.Xr login 1 ,
|
||||
.Xr passwd 1 ,
|
||||
.Xr pwhash 1 ,
|
||||
.Xr getusershell 3 ,
|
||||
.Xr passwd 5 ,
|
||||
.Xr passwd.conf 5 ,
|
||||
.Xr pwd_mkdb 8 ,
|
||||
.Xr vipw 8
|
||||
.Rs
|
||||
.%A Robert Morris
|
||||
.%A Ken Thompson
|
||||
.%T "UNIX Password Security"
|
||||
.Re
|
||||
.Sh HISTORY
|
||||
The
|
||||
.Nm
|
||||
command appeared in
|
||||
.Bx 4.3 Reno .
|
||||
.Sh BUGS
|
||||
This program's interface is poorly suited to cryptographic systems such as
|
||||
Kerberos, and consequently Kerberos password changing is not a feature of
|
||||
this program.
|
||||
.Pp
|
||||
User information should (and eventually will) be stored elsewhere.
|
||||
|
|
@ -1,316 +0,0 @@
|
|||
/* $NetBSD: chpass.c,v 1.35 2011/08/31 16:24:57 plunky Exp $ */
|
||||
|
||||
/*-
|
||||
* 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. 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.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
__COPYRIGHT("@(#) Copyright (c) 1988, 1993, 1994\
|
||||
The Regents of the University of California. All rights reserved.");
|
||||
#endif /* not lint */
|
||||
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)chpass.c 8.4 (Berkeley) 4/2/94";
|
||||
#else
|
||||
__RCSID("$NetBSD: chpass.c,v 1.35 2011/08/31 16:24:57 plunky Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/stat.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 <util.h>
|
||||
#include <libgen.h>
|
||||
|
||||
#include "chpass.h"
|
||||
#include "pathnames.h"
|
||||
|
||||
static char tempname[] = "/tmp/pw.XXXXXX";
|
||||
uid_t uid;
|
||||
int use_yp;
|
||||
|
||||
void (*Pw_error)(const char *, int, int);
|
||||
|
||||
#ifdef YP
|
||||
extern int _yp_check(char **); /* buried deep inside libc */
|
||||
#endif
|
||||
|
||||
__dead static void baduser(void);
|
||||
static void cleanup(void);
|
||||
__dead static void usage(void);
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
enum { NEWSH, LOADENTRY, EDITENTRY } op;
|
||||
struct passwd *pw, lpw, old_pw;
|
||||
int ch, dfd, pfd, tfd;
|
||||
#ifdef YP
|
||||
int yflag = 0;
|
||||
#endif
|
||||
char *arg, *username = NULL;
|
||||
|
||||
#ifdef __GNUC__
|
||||
pw = NULL; /* XXX gcc -Wuninitialized */
|
||||
arg = NULL;
|
||||
#endif
|
||||
#ifdef YP
|
||||
use_yp = _yp_check(NULL);
|
||||
#endif
|
||||
|
||||
op = EDITENTRY;
|
||||
while ((ch = getopt(argc, argv, "a:s:ly")) != -1)
|
||||
switch (ch) {
|
||||
case 'a':
|
||||
op = LOADENTRY;
|
||||
arg = optarg;
|
||||
break;
|
||||
case 's':
|
||||
op = NEWSH;
|
||||
arg = optarg;
|
||||
break;
|
||||
case 'l':
|
||||
use_yp = 0;
|
||||
break;
|
||||
case 'y':
|
||||
#ifdef YP
|
||||
if (!use_yp)
|
||||
errx(1, "YP not in use.");
|
||||
yflag = 1;
|
||||
#else
|
||||
errx(1, "YP support not compiled in.");
|
||||
#endif
|
||||
break;
|
||||
default:
|
||||
usage();
|
||||
}
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
uid = getuid();
|
||||
switch (argc) {
|
||||
case 0:
|
||||
/* nothing */
|
||||
break;
|
||||
|
||||
case 1:
|
||||
username = argv[0];
|
||||
break;
|
||||
|
||||
default:
|
||||
usage();
|
||||
}
|
||||
|
||||
#ifdef YP
|
||||
/*
|
||||
* We need to determine if we _really_ want to use YP.
|
||||
* If we defaulted to YP (i.e. were not given the -y flag),
|
||||
* and the master is not running rpc.yppasswdd, we check
|
||||
* to see if the user exists in the local passwd database.
|
||||
* If so, we use it, otherwise we error out.
|
||||
*/
|
||||
if (use_yp && yflag == 0) {
|
||||
if (check_yppasswdd()) {
|
||||
/*
|
||||
* We weren't able to contact rpc.yppasswdd.
|
||||
* Check to see if we're in the local
|
||||
* password database. If we are, use it.
|
||||
*/
|
||||
if (username != NULL)
|
||||
pw = getpwnam(username);
|
||||
else
|
||||
pw = getpwuid(uid);
|
||||
if (pw != NULL)
|
||||
use_yp = 0;
|
||||
else {
|
||||
warnx("master YP server not running yppasswd"
|
||||
" daemon.");
|
||||
errx(1, "Can't change password.");
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef YP
|
||||
if (use_yp)
|
||||
Pw_error = yppw_error;
|
||||
else
|
||||
#endif
|
||||
Pw_error = pw_error;
|
||||
|
||||
#ifdef YP
|
||||
if (op == LOADENTRY && use_yp)
|
||||
errx(1, "cannot load entry using YP.\n"
|
||||
"\tUse the -l flag to load local.");
|
||||
#endif
|
||||
|
||||
if (op == EDITENTRY || op == NEWSH) {
|
||||
if (username != NULL) {
|
||||
pw = getpwnam(username);
|
||||
if (pw == NULL)
|
||||
errx(1, "unknown user: %s", username);
|
||||
if (uid && uid != pw->pw_uid)
|
||||
baduser();
|
||||
} else {
|
||||
pw = getpwuid(uid);
|
||||
if (pw == NULL)
|
||||
errx(1, "unknown user: uid %u", uid);
|
||||
}
|
||||
|
||||
/* Make a copy for later verification */
|
||||
old_pw = *pw;
|
||||
old_pw.pw_gecos = strdup(old_pw.pw_gecos);
|
||||
if (!old_pw.pw_gecos) {
|
||||
err(1, "strdup");
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
}
|
||||
|
||||
if (op == NEWSH) {
|
||||
/* protect p_shell -- it thinks NULL is /bin/sh */
|
||||
if (!arg[0])
|
||||
usage();
|
||||
if (p_shell(arg, pw, NULL))
|
||||
(*Pw_error)(NULL, 0, 1);
|
||||
}
|
||||
|
||||
if (op == LOADENTRY) {
|
||||
if (uid)
|
||||
baduser();
|
||||
pw = &lpw;
|
||||
if (!pw_scan(arg, pw, NULL))
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* Edit the user passwd information if requested. */
|
||||
if (op == EDITENTRY) {
|
||||
struct stat sb;
|
||||
|
||||
dfd = mkstemp(tempname);
|
||||
if (dfd < 0 || fcntl(dfd, F_SETFD, 1) < 0)
|
||||
(*Pw_error)(tempname, 1, 1);
|
||||
if (atexit(cleanup)) {
|
||||
cleanup();
|
||||
errx(1, "couldn't register cleanup");
|
||||
}
|
||||
if (stat(dirname(tempname), &sb) == -1)
|
||||
err(1, "couldn't stat `%s'", dirname(tempname));
|
||||
if (!(sb.st_mode & S_ISTXT))
|
||||
errx(1, "temporary directory `%s' is not sticky",
|
||||
dirname(tempname));
|
||||
|
||||
display(tempname, dfd, pw);
|
||||
edit(tempname, pw);
|
||||
}
|
||||
|
||||
#ifdef YP
|
||||
if (use_yp) {
|
||||
if (pw_yp(pw, uid))
|
||||
yppw_error(NULL, 0, 1);
|
||||
else
|
||||
exit(0);
|
||||
/* Will not exit from this if. */
|
||||
}
|
||||
#endif /* YP */
|
||||
|
||||
|
||||
/*
|
||||
* Get the passwd lock file and open the passwd file for
|
||||
* reading.
|
||||
*/
|
||||
pw_init();
|
||||
tfd = pw_lock(0);
|
||||
if (tfd < 0) {
|
||||
if (errno != EEXIST)
|
||||
err(1, "%s", _PATH_MASTERPASSWD_LOCK);
|
||||
warnx("The passwd file is busy, waiting...");
|
||||
tfd = pw_lock(10);
|
||||
if (tfd < 0) {
|
||||
if (errno != EEXIST)
|
||||
err(1, "%s", _PATH_MASTERPASSWD_LOCK);
|
||||
errx(1, "The passwd file is still busy, "
|
||||
"try again later.");
|
||||
}
|
||||
}
|
||||
if (fcntl(tfd, F_SETFD, 1) < 0)
|
||||
pw_error(_PATH_MASTERPASSWD_LOCK, 1, 1);
|
||||
|
||||
pfd = open(_PATH_MASTERPASSWD, O_RDONLY, 0);
|
||||
if (pfd < 0 || fcntl(pfd, F_SETFD, 1) < 0)
|
||||
pw_error(_PATH_MASTERPASSWD, 1, 1);
|
||||
|
||||
/* Copy the passwd file to the lock file, updating pw. */
|
||||
pw_copy(pfd, tfd, pw, (op == LOADENTRY) ? NULL : &old_pw);
|
||||
|
||||
close(pfd);
|
||||
close(tfd);
|
||||
|
||||
/* Now finish the passwd file update. */
|
||||
if (pw_mkdb(username, 0) < 0)
|
||||
pw_error(NULL, 0, 1);
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
||||
static void
|
||||
baduser(void)
|
||||
{
|
||||
|
||||
errx(1, "%s", strerror(EACCES));
|
||||
}
|
||||
|
||||
static void
|
||||
usage(void)
|
||||
{
|
||||
|
||||
(void)fprintf(stderr,
|
||||
"usage: %s [-a list] [-s shell] [-l] [user]\n"
|
||||
" %s [-a list] [-s shell] [-y] [user]\n",
|
||||
getprogname(), getprogname());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
static void
|
||||
cleanup(void)
|
||||
{
|
||||
|
||||
(void)unlink(tempname);
|
||||
}
|
||||
|
|
@ -1,81 +0,0 @@
|
|||
/* $NetBSD: chpass.h,v 1.13 2011/08/29 14:08:39 joerg Exp $ */
|
||||
|
||||
/*
|
||||
* 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. 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 {
|
||||
const char *prompt;
|
||||
int (*func)(const char *, struct passwd *, struct _entry *), restricted, len;
|
||||
const char *except, *save;
|
||||
} ENTRY;
|
||||
|
||||
extern int use_yp;
|
||||
|
||||
/* 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(const char *, time_t *);
|
||||
void display(char *, int, struct passwd *);
|
||||
void edit(char *, struct passwd *);
|
||||
const char *
|
||||
ok_shell(const char *);
|
||||
int p_change(const char *, struct passwd *, ENTRY *);
|
||||
int p_class(const char *, struct passwd *, ENTRY *);
|
||||
int p_expire(const char *, struct passwd *, ENTRY *);
|
||||
int p_gecos(const char *, struct passwd *, ENTRY *);
|
||||
int p_gid(const char *, struct passwd *, ENTRY *);
|
||||
int p_hdir(const char *, struct passwd *, ENTRY *);
|
||||
int p_login(const char *, struct passwd *, ENTRY *);
|
||||
int p_passwd(const char *, struct passwd *, ENTRY *);
|
||||
int p_shell(const char *, struct passwd *, ENTRY *);
|
||||
int p_uid(const char *, struct passwd *, ENTRY *);
|
||||
char *ttoa(char *, size_t, time_t);
|
||||
int verify(char *, struct passwd *);
|
||||
|
||||
#ifdef YP
|
||||
int check_yppasswdd(void);
|
||||
int pw_yp(struct passwd *, uid_t);
|
||||
__dead void yppw_error(const char *name, int, int);
|
||||
void yppw_prompt(void);
|
||||
struct passwd *ypgetpwnam(const char *);
|
||||
struct passwd *ypgetpwuid(uid_t);
|
||||
#endif
|
||||
|
||||
extern void (*Pw_error)(const char *name, int, int);
|
||||
|
|
@ -1,222 +0,0 @@
|
|||
/* $NetBSD: edit.c,v 1.21 2011/08/31 16:24:57 plunky Exp $ */
|
||||
|
||||
/*-
|
||||
* 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. 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.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)edit.c 8.3 (Berkeley) 4/2/94";
|
||||
#else
|
||||
__RCSID("$NetBSD: edit.c,v 1.21 2011/08/31 16:24:57 plunky Exp $");
|
||||
#endif
|
||||
#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 <fcntl.h>
|
||||
#include <util.h>
|
||||
|
||||
#include "chpass.h"
|
||||
|
||||
void
|
||||
edit(char *tempname, struct passwd *pw)
|
||||
{
|
||||
struct stat begin, end;
|
||||
|
||||
for (;;) {
|
||||
if (stat(tempname, &begin))
|
||||
(*Pw_error)(tempname, 1, 1);
|
||||
pw_edit(1, tempname);
|
||||
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(tempname, pw))
|
||||
break;
|
||||
#ifdef YP
|
||||
if (use_yp)
|
||||
yppw_prompt();
|
||||
else
|
||||
#endif
|
||||
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(char *tempname, int fd, struct passwd *pw)
|
||||
{
|
||||
FILE *fp;
|
||||
char *bp, *p;
|
||||
char chgstr[256], expstr[256];
|
||||
|
||||
if (!(fp = fdopen(fd, "w")))
|
||||
(*Pw_error)(tempname, 1, 1);
|
||||
|
||||
(void)fprintf(fp,
|
||||
"#Changing user %sdatabase information for %s.\n",
|
||||
use_yp ? "YP " : "", 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(chgstr, sizeof chgstr, pw->pw_change));
|
||||
(void)fprintf(fp, "Expire [month day year]: %s\n",
|
||||
ttoa(expstr, sizeof expstr, 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 = strdup(pw->pw_gecos);
|
||||
if (!bp) {
|
||||
err(1, "strdup");
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
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(char *tempname, struct passwd *pw)
|
||||
{
|
||||
ENTRY *ep;
|
||||
char *p;
|
||||
struct stat sb;
|
||||
FILE *fp = NULL;
|
||||
int len, fd;
|
||||
static char buf[LINE_MAX];
|
||||
|
||||
if ((fd = open(tempname, O_RDONLY|O_NOFOLLOW)) == -1 ||
|
||||
(fp = fdopen(fd, "r")) == NULL)
|
||||
(*Pw_error)(tempname, 1, 1);
|
||||
if (fstat(fd, &sb))
|
||||
(*Pw_error)(tempname, 1, 1);
|
||||
if (sb.st_size == 0 || sb.st_nlink != 1) {
|
||||
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((unsigned char)*++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, "malloc");
|
||||
(void)snprintf(p, len, "%s,%s,%s,%s", list[E_NAME].save,
|
||||
list[E_LOCATE].save, list[E_BPHONE].save, list[E_HPHONE].save);
|
||||
pw->pw_gecos = p;
|
||||
|
||||
if (snprintf(buf, sizeof(buf),
|
||||
"%s:%s:%d:%d:%s:%lu:%lu:%s:%s:%s",
|
||||
pw->pw_name, pw->pw_passwd, pw->pw_uid, pw->pw_gid, pw->pw_class,
|
||||
(u_long)pw->pw_change, (u_long)pw->pw_expire, pw->pw_gecos,
|
||||
pw->pw_dir, pw->pw_shell) >= (int)sizeof(buf)) {
|
||||
warnx("entries too long");
|
||||
return (0);
|
||||
}
|
||||
return (pw_scan(buf, pw, NULL));
|
||||
}
|
||||
|
|
@ -1,253 +0,0 @@
|
|||
/* $NetBSD: field.c,v 1.12 2009/04/11 12:10:02 lukem Exp $ */
|
||||
|
||||
/*
|
||||
* 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. 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.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)field.c 8.4 (Berkeley) 4/2/94";
|
||||
#else
|
||||
__RCSID("$NetBSD: field.c,v 1.12 2009/04/11 12:10:02 lukem Exp $");
|
||||
#endif
|
||||
#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(const 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((unsigned char)*p)) {
|
||||
warnx("upper-case letters are dangerous in a login name");
|
||||
break;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* ARGSUSED */
|
||||
int
|
||||
p_passwd(const char *p, struct passwd *pw, ENTRY *ep)
|
||||
{
|
||||
|
||||
if (!(pw->pw_passwd = strdup(p))) {
|
||||
warnx("can't save password entry");
|
||||
return (1);
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* ARGSUSED */
|
||||
int
|
||||
p_uid(const char *p, struct passwd *pw, ENTRY *ep)
|
||||
{
|
||||
unsigned long id;
|
||||
char *np;
|
||||
|
||||
if (!*p) {
|
||||
warnx("empty uid field");
|
||||
return (1);
|
||||
}
|
||||
if (!isdigit((unsigned char)*p)) {
|
||||
warnx("illegal uid");
|
||||
return (1);
|
||||
}
|
||||
errno = 0;
|
||||
id = strtoul(p, &np, 10);
|
||||
/*
|
||||
* We don't need to check the return value of strtoul()
|
||||
* since ULONG_MAX is greater than UID_MAX.
|
||||
*/
|
||||
if (*np || id > UID_MAX) {
|
||||
warnx("illegal uid");
|
||||
return (1);
|
||||
}
|
||||
pw->pw_uid = (uid_t)id;
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* ARGSUSED */
|
||||
int
|
||||
p_gid(const char *p, struct passwd *pw, ENTRY *ep)
|
||||
{
|
||||
struct group *gr;
|
||||
unsigned long id;
|
||||
char *np;
|
||||
|
||||
if (!*p) {
|
||||
warnx("empty gid field");
|
||||
return (1);
|
||||
}
|
||||
if (!isdigit((unsigned char)*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);
|
||||
/*
|
||||
* We don't need to check the return value of strtoul()
|
||||
* since ULONG_MAX is greater than GID_MAX.
|
||||
*/
|
||||
if (*np || id > GID_MAX) {
|
||||
warnx("illegal gid");
|
||||
return (1);
|
||||
}
|
||||
pw->pw_gid = (gid_t)id;
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* ARGSUSED */
|
||||
int
|
||||
p_class(const char *p, struct passwd *pw, ENTRY *ep)
|
||||
{
|
||||
|
||||
if (!(pw->pw_class = strdup(p))) {
|
||||
warnx("can't save entry");
|
||||
return (1);
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* ARGSUSED */
|
||||
int
|
||||
p_change(const 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(const 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(const char *p, struct passwd *pw, ENTRY *ep)
|
||||
{
|
||||
|
||||
if (!(ep->save = strdup(p))) {
|
||||
warnx("can't save entry");
|
||||
return (1);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* ARGSUSED */
|
||||
int
|
||||
p_hdir(const 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(const char *p, struct passwd *pw, ENTRY *ep)
|
||||
{
|
||||
const char *t;
|
||||
|
||||
if (!*p) {
|
||||
if (!(pw->pw_shell = strdup(_PATH_BSHELL))) {
|
||||
warnx("can't save entry");
|
||||
return (1);
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
|
@ -1,37 +0,0 @@
|
|||
/* $NetBSD: pathnames.h,v 1.4 2003/08/07 11:13:19 agc Exp $ */
|
||||
|
||||
/*
|
||||
* 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. 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"
|
||||
|
|
@ -1,239 +0,0 @@
|
|||
/* $NetBSD: pw_yp.c,v 1.23 2015/06/17 00:01:59 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1988 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. 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.
|
||||
*/
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)pw_yp.c 1.0 2/2/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: pw_yp.c,v 1.23 2015/06/17 00:01:59 christos Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
#ifdef YP
|
||||
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <netdb.h>
|
||||
#include <pwd.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <rpc/rpc.h>
|
||||
#include <rpcsvc/yp_prot.h>
|
||||
#include <rpcsvc/ypclnt.h>
|
||||
|
||||
#define passwd yp_passwd_rec
|
||||
#include <rpcsvc/yppasswd.h>
|
||||
#undef passwd
|
||||
|
||||
#include "chpass.h"
|
||||
|
||||
static char *domain;
|
||||
|
||||
/*
|
||||
* Check if rpc.yppasswdd is running on the master YP server.
|
||||
* XXX this duplicates some code, but is much less complex
|
||||
* than the alternative.
|
||||
*/
|
||||
int
|
||||
check_yppasswdd(void)
|
||||
{
|
||||
char *master;
|
||||
int rpcport;
|
||||
|
||||
/*
|
||||
* Get local domain
|
||||
*/
|
||||
if (!domain && yp_get_default_domain(&domain) != 0)
|
||||
return (1);
|
||||
|
||||
/*
|
||||
* Find the host for the passwd map; it should be running
|
||||
* the daemon.
|
||||
*/
|
||||
master = NULL;
|
||||
if (yp_master(domain, "passwd.byname", &master) != 0) {
|
||||
if (master != NULL)
|
||||
free (master);
|
||||
return (1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Ask the portmapper for the port of the daemon.
|
||||
*/
|
||||
if ((rpcport = getrpcport(master, YPPASSWDPROG, YPPASSWDPROC_UPDATE,
|
||||
IPPROTO_UDP)) == 0)
|
||||
return (1);
|
||||
|
||||
/*
|
||||
* Successful contact with rpc.yppasswdd.
|
||||
*/
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
pw_yp(struct passwd *pw, uid_t ypuid)
|
||||
{
|
||||
char *master;
|
||||
int r, rpcport, status;
|
||||
struct yppasswd yppw;
|
||||
struct timeval tv;
|
||||
CLIENT *client;
|
||||
|
||||
/*
|
||||
* Get local domain
|
||||
*/
|
||||
if (!domain && (r = yp_get_default_domain(&domain)))
|
||||
errx(1, "can't get local YP domain. Reason: %s",
|
||||
yperr_string(r));
|
||||
|
||||
/*
|
||||
* Find the host for the passwd map; it should be running
|
||||
* the daemon.
|
||||
*/
|
||||
master = NULL;
|
||||
if ((r = yp_master(domain, "passwd.byname", &master)) != 0) {
|
||||
if (master)
|
||||
free (master);
|
||||
warnx("can't find the master YP server. Reason: %s",
|
||||
yperr_string(r));
|
||||
return (1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Ask the portmapper for the port of the daemon.
|
||||
*/
|
||||
if ((rpcport = getrpcport(master, YPPASSWDPROG, YPPASSWDPROC_UPDATE,
|
||||
IPPROTO_UDP)) == 0) {
|
||||
warnx("master YP server not running yppasswd daemon.\n\t%s",
|
||||
"Can't change password.");
|
||||
return (1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Be sure the port is privileged
|
||||
*/
|
||||
if (rpcport >= IPPORT_RESERVED) {
|
||||
warnx("yppasswd daemon is on an invalid port.");
|
||||
return (1);
|
||||
}
|
||||
|
||||
/* prompt for old password */
|
||||
memset(&yppw, 0, sizeof yppw);
|
||||
yppw.oldpass = getpass("Old password:");
|
||||
if (!yppw.oldpass) {
|
||||
warnx("Cancelled.");
|
||||
return (1);
|
||||
}
|
||||
|
||||
/* tell rpc.yppasswdd */
|
||||
yppw.newpw.pw_name = strdup(pw->pw_name);
|
||||
if (!yppw.newpw.pw_name) {
|
||||
err(1, "strdup");
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
yppw.newpw.pw_passwd = strdup(pw->pw_passwd);
|
||||
if (!yppw.newpw.pw_passwd) {
|
||||
err(1, "strdup");
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
yppw.newpw.pw_uid = pw->pw_uid;
|
||||
yppw.newpw.pw_gid = pw->pw_gid;
|
||||
yppw.newpw.pw_gecos = strdup(pw->pw_gecos);
|
||||
if (!yppw.newpw.pw_gecos) {
|
||||
err(1, "strdup");
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
yppw.newpw.pw_dir = strdup(pw->pw_dir);
|
||||
if (!yppw.newpw.pw_dir) {
|
||||
err(1, "strdup");
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
yppw.newpw.pw_shell = strdup(pw->pw_shell);
|
||||
if (!yppw.newpw.pw_shell) {
|
||||
err(1, "strdup");
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
|
||||
client = clnt_create(master, YPPASSWDPROG, YPPASSWDVERS, "udp");
|
||||
if (client == NULL) {
|
||||
warnx("cannot contact yppasswdd on %s: Reason: %s",
|
||||
master, yperr_string(YPERR_YPBIND));
|
||||
return (1);
|
||||
}
|
||||
client->cl_auth = authunix_create_default();
|
||||
tv.tv_sec = 5;
|
||||
tv.tv_usec = 0;
|
||||
r = clnt_call(client, YPPASSWDPROC_UPDATE,
|
||||
xdr_yppasswd, &yppw, xdr_int, &status, tv);
|
||||
if (r) {
|
||||
warnx("rpc to yppasswdd failed.");
|
||||
return (1);
|
||||
} else if (status)
|
||||
printf("Couldn't change YP password.\n");
|
||||
else
|
||||
printf("%s %s, %s\n",
|
||||
"The YP password information has been changed on",
|
||||
master, "the master YP passwd server.");
|
||||
return (0);
|
||||
}
|
||||
|
||||
void
|
||||
yppw_error(const char *name, int yperr, int eval)
|
||||
{
|
||||
|
||||
if (yperr) {
|
||||
if (name)
|
||||
warn("%s", name);
|
||||
else
|
||||
warn(NULL);
|
||||
}
|
||||
|
||||
errx(eval, "YP passwd information unchanged");
|
||||
}
|
||||
|
||||
void
|
||||
yppw_prompt(void)
|
||||
{
|
||||
int c;
|
||||
|
||||
(void)printf("re-edit the password file? [y]: ");
|
||||
(void)fflush(stdout);
|
||||
c = getchar();
|
||||
if (c != EOF && c != '\n')
|
||||
while (getchar() != '\n');
|
||||
if (c == 'n')
|
||||
yppw_error(NULL, 0, 0);
|
||||
}
|
||||
#endif /* YP */
|
||||
|
|
@ -1,63 +0,0 @@
|
|||
/* $NetBSD: table.c,v 1.7 2009/04/11 12:10:02 lukem Exp $ */
|
||||
|
||||
/*-
|
||||
* 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. 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.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)table.c 8.3 (Berkeley) 4/2/94";
|
||||
#else
|
||||
__RCSID("$NetBSD: table.c,v 1.7 2009/04/11 12:10:02 lukem Exp $");
|
||||
#endif
|
||||
#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, NULL },
|
||||
{ "password", p_passwd, 1, 8, e1, NULL },
|
||||
{ "uid", p_uid, 1, 3, e1, NULL },
|
||||
{ "gid", p_gid, 1, 3, e1, NULL },
|
||||
{ "class", p_class, 1, 5, e1, NULL },
|
||||
{ "change", p_change, 1, 6, NULL, NULL },
|
||||
{ "expire", p_expire, 1, 6, NULL, 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, NULL },
|
||||
{ "shell", p_shell, 0, 5, e1, NULL },
|
||||
{ NULL, NULL, 0, 0, NULL, NULL },
|
||||
};
|
||||
|
|
@ -1,113 +0,0 @@
|
|||
/* $NetBSD: util.c,v 1.12 2005/02/17 17:09:48 xtraeme Exp $ */
|
||||
|
||||
/*-
|
||||
* 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. 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.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)util.c 8.4 (Berkeley) 4/2/94";
|
||||
#else
|
||||
__RCSID("$NetBSD: util.c,v 1.12 2005/02/17 17:09:48 xtraeme Exp $");
|
||||
#endif
|
||||
#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"
|
||||
|
||||
char *
|
||||
ttoa(char *buf, size_t len, time_t tval)
|
||||
{
|
||||
|
||||
if (tval) {
|
||||
struct tm *tp = localtime(&tval);
|
||||
|
||||
(void) strftime(buf, len, "%B %d, %Y", tp);
|
||||
buf[len - 1] = '\0';
|
||||
}
|
||||
else if (len > 0)
|
||||
*buf = '\0';
|
||||
return (buf);
|
||||
}
|
||||
|
||||
int
|
||||
atot(const char *p, time_t *store)
|
||||
{
|
||||
static struct tm *lt;
|
||||
struct tm tm;
|
||||
char *t;
|
||||
time_t tval;
|
||||
|
||||
if (!*p) {
|
||||
*store = 0;
|
||||
return (0);
|
||||
}
|
||||
if (!lt) {
|
||||
unsetenv("TZ");
|
||||
(void)time(&tval);
|
||||
lt = localtime(&tval);
|
||||
}
|
||||
(void) memset(&tm, 0, sizeof(tm));
|
||||
while ((t = strchr(p, ',')) != NULL)
|
||||
*t = ' ';
|
||||
t = strptime(p, "%B %d %Y", &tm);
|
||||
if (t == NULL || (*t != '\0' && *t != '\n'))
|
||||
return 1;
|
||||
if ((*store = mktime(&tm)) == (time_t) -1)
|
||||
return 1;
|
||||
return (0);
|
||||
}
|
||||
|
||||
const char *
|
||||
ok_shell(const char *name)
|
||||
{
|
||||
char *p;
|
||||
const char *sh;
|
||||
|
||||
setusershell();
|
||||
while ((sh = getusershell()) != NULL) {
|
||||
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);
|
||||
}
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
# $NetBSD: Makefile,v 1.16 2009/04/14 22:15:18 lukem Exp $
|
||||
# @(#)Makefile 8.2 (Berkeley) 4/28/95
|
||||
|
||||
PROG= cksum
|
||||
SRCS= cksum.c crc.c md2.c md4.c md5.c sha1.c rmd160.c print.c sum1.c sum2.c
|
||||
SRCS+= sha256.c sha384.c sha512.c
|
||||
LINKS= ${BINDIR}/cksum ${BINDIR}/sum
|
||||
LINKS+= ${BINDIR}/cksum ${BINDIR}/md2
|
||||
LINKS+= ${BINDIR}/cksum ${BINDIR}/md4
|
||||
LINKS+= ${BINDIR}/cksum ${BINDIR}/md5
|
||||
LINKS+= ${BINDIR}/cksum ${BINDIR}/sha1
|
||||
LINKS+= ${BINDIR}/cksum ${BINDIR}/rmd160
|
||||
MLINKS= cksum.1 sum.1
|
||||
MLINKS+=cksum.1 md2.1
|
||||
MLINKS+=cksum.1 md4.1
|
||||
MLINKS+=cksum.1 md5.1
|
||||
MLINKS+=cksum.1 sha1.1
|
||||
MLINKS+=cksum.1 rmd160.1
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
|
|
@ -1,341 +0,0 @@
|
|||
.\" $NetBSD: cksum.1,v 1.47 2014/08/31 07:23:53 wiz Exp $
|
||||
.\"
|
||||
.\" 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. 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.2 (Berkeley) 4/28/95
|
||||
.\"
|
||||
.Dd August 31, 2014
|
||||
.Dt CKSUM 1
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm cksum ,
|
||||
.Nm md2 ,
|
||||
.Nm md4 ,
|
||||
.Nm md5 ,
|
||||
.Nm rmd160 ,
|
||||
.Nm sha1 ,
|
||||
.Nm sum
|
||||
.Nd display file checksums and block counts
|
||||
.Sh SYNOPSIS
|
||||
.Nm cksum
|
||||
.Op Fl n
|
||||
.Op Fl a Ar algorithm Oo Fl pqtx Oc Oo Fl s Ar string Oc
|
||||
.Op Fl o Ar 1 Ns | Ns Ar 2
|
||||
.Op Ar Li \&| Fl c Oo Fl w Oc Oo Ar sumfile Oc
|
||||
.Nm sum
|
||||
.Op Fl n
|
||||
.Op Fl a Ar algorithm Oo Fl pqtx Oc Oo Fl s Ar string Oc
|
||||
.Op Fl o Ar 1 Ns | Ns Ar 2
|
||||
.Op Ar Li \&| Fl c Oo Fl w Oc Oo Ar sumfile Oc
|
||||
.Nm md2
|
||||
.Op Fl npqtx
|
||||
.Op Fl s Ar string
|
||||
.Op Ar Li \&| Fl c Oo Fl w Oc Oo Ar sumfile Oc
|
||||
.Nm md4
|
||||
.Op Fl npqtx
|
||||
.Op Fl s Ar string
|
||||
.Op Ar Li \&| Fl c Oo Fl w Oc Oo Ar sumfile Oc
|
||||
.Nm md5
|
||||
.Op Fl npqtx
|
||||
.Op Fl s Ar string
|
||||
.Op Ar Li \&| Fl c Oo Fl w Oc Oo Ar sumfile Oc
|
||||
.Nm rmd160
|
||||
.Op Fl npqtx
|
||||
.Op Fl s Ar string
|
||||
.Op Ar Li \&| Fl c Oo Fl w Oc Oo Ar sumfile Oc
|
||||
.Nm sha1
|
||||
.Op Fl npqtx
|
||||
.Op Fl s Ar string
|
||||
.Op Ar Li \&| Fl c Oo Fl w Oc Oo Ar sumfile Oc
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Nm
|
||||
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
|
||||
.Nm sum
|
||||
utility is identical to the
|
||||
.Nm
|
||||
utility, except that it defaults to using historic algorithm 1, as
|
||||
described below.
|
||||
It is provided for compatibility only.
|
||||
.Pp
|
||||
The
|
||||
.Nm md2 ,
|
||||
.Nm md4 ,
|
||||
.Nm md5 ,
|
||||
.Nm sha1 ,
|
||||
and
|
||||
.Nm rmd160
|
||||
utilities compute cryptographic hash functions, and write to standard
|
||||
output the hexadecimal representation of the hash of their input.
|
||||
.Pp
|
||||
The options are as follows:
|
||||
.Bl -tag -width indent
|
||||
.It Fl a Ar algorithm
|
||||
When invoked as
|
||||
.Nm cksum ,
|
||||
use the specified
|
||||
.Ar algorithm .
|
||||
Valid algorithms are:
|
||||
.Bl -column -offset indent ".Sy Algorithm" ".Sy Bits" ".Sy Description"
|
||||
.It Sy Algorithm Ta Sy Bits Ta Sy Description
|
||||
.It Li CRC Ta 32 Ta Default CRC algorithm
|
||||
.It Li MD2 Ta 128 Ta MD2, per Li RFC1319
|
||||
.It Li MD4 Ta 128 Ta MD4, per Li RFC1320
|
||||
.It Li MD5 Ta 128 Ta MD5, per Li RFC1321
|
||||
.It Li RMD160 Ta 160 Ta RIPEMD-160
|
||||
.It Li SHA1 Ta 160 Ta SHA-1, per Li FIPS PUB 180-1
|
||||
.It Li SHA256 Ta 256 Ta SHA-2
|
||||
.It Li SHA384 Ta 384 Ta SHA-2
|
||||
.It Li SHA512 Ta 512 Ta SHA-2
|
||||
.It Li old1 Ta 16 Ta Algorithm 1, per Fl o Ar 1
|
||||
.It Li old2 Ta 16 Ta Algorithm 2, per Fl o Ar 2
|
||||
.El
|
||||
.It Fl c Op Ar sumfile
|
||||
Verify (check) files against a list of checksums.
|
||||
The list is read from
|
||||
.Ar sumfile ,
|
||||
or from stdin if no filename is given.
|
||||
E.g. first run
|
||||
.Dl Ic md5 *.tgz \*[Gt] MD5
|
||||
.Dl Ic sha1 *.tgz \*[Gt] SHA1
|
||||
to generate a list of MD5 checksums in
|
||||
.Pa MD5 ,
|
||||
then use the following command to verify them:
|
||||
.Dl Ic cat MD5 SHA1 | cksum -c
|
||||
If an error is found during checksum verification, an error
|
||||
message is printed, and the program returns an error code of 1.
|
||||
.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 1
|
||||
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 1
|
||||
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.
|
||||
.It Fl w
|
||||
Print warnings about malformed checksum files when verifying
|
||||
checksums with
|
||||
.Fl c .
|
||||
.El
|
||||
.Pp
|
||||
The following options apply only when using the one of the message
|
||||
digest algorithms:
|
||||
.Bl -tag -width indent
|
||||
.It Fl n
|
||||
Print the hash and the filename in the normal sum output form, with
|
||||
the hash at the left and the filename following on the right.
|
||||
.It Fl p
|
||||
Echo input from standard input to standard output, and append the
|
||||
selected message digest.
|
||||
.It Fl q
|
||||
Quiet mode \(em only the checksum is printed out.
|
||||
Overrides the
|
||||
.Fl n
|
||||
option.
|
||||
.It Fl s Ar string
|
||||
Print the hash of the given string
|
||||
.Ar string .
|
||||
.It Fl t
|
||||
Run a built-in message digest time trial.
|
||||
.It Fl x
|
||||
Run a built-in message digest test script.
|
||||
The tests that are run
|
||||
are supposed to encompass all the various tests in the suites that
|
||||
accompany the algorithms' descriptions with the exception of the
|
||||
last test for the SHA-1 algorithm and the RIPEMD-160 algorithm.
|
||||
The
|
||||
last test for these is one million copies of the lower letter a.
|
||||
.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 \*[Le] 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
|
||||
and
|
||||
.Nm sum
|
||||
utilities exit 0 on success, and \*[Gt]0 if an error occurs.
|
||||
.Sh SEE ALSO
|
||||
.Xr openssl 1 ,
|
||||
.Xr mtree 8
|
||||
.Pp
|
||||
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 ACM"
|
||||
.%D "August 1988"
|
||||
.Re
|
||||
.Rs
|
||||
.%A R. Rivest
|
||||
.%T The MD2 Message-Digest Algorithm
|
||||
.%O RFC 1319
|
||||
.Re
|
||||
.Rs
|
||||
.%A R. Rivest
|
||||
.%T The MD4 Message-Digest Algorithm
|
||||
.%O RFC 1186 and RFC 1320
|
||||
.Re
|
||||
.Rs
|
||||
.%A R. Rivest
|
||||
.%T The MD5 Message-Digest Algorithm
|
||||
.%O RFC 1321
|
||||
.Re
|
||||
.Rs
|
||||
.%A U.S. DOC/NIST
|
||||
.%T Secure Hash Standard
|
||||
.%O FIPS PUB 180-1
|
||||
.Re
|
||||
.Sh STANDARDS
|
||||
The
|
||||
.Nm
|
||||
utility is expected to conform to
|
||||
.St -p1003.1-2004 .
|
||||
.Sh HISTORY
|
||||
The
|
||||
.Nm
|
||||
utility appeared in
|
||||
.Bx 4.4 .
|
||||
.Nm md5
|
||||
was added in
|
||||
.Nx 1.3 .
|
||||
The functionality for
|
||||
.Nm md2 ,
|
||||
.Nm md4 ,
|
||||
.Nm sha1 ,
|
||||
and
|
||||
.Nm rmd160
|
||||
was added in
|
||||
.Nx 1.6 .
|
||||
Support for the SHA-2 algorithms
|
||||
.Po
|
||||
.Li SHA256 ,
|
||||
.Li SHA384 ,
|
||||
and
|
||||
.Li SHA512
|
||||
.Pc
|
||||
was added in
|
||||
.Nx 3.0 .
|
||||
The functionality to verify checksum stored in a file
|
||||
.Pq Fl c
|
||||
first appeared in
|
||||
.Nx 4.0 .
|
||||
Quiet mode
|
||||
.Pq Fl q
|
||||
was added in
|
||||
.Nx 7.0 .
|
||||
.\" .Pp
|
||||
.\" The
|
||||
.\" .Nm sum
|
||||
.\" utility appeared in
|
||||
.\" .Bx ?.?
|
||||
.\" and
|
||||
.\" .At V .
|
||||
|
|
@ -1,551 +0,0 @@
|
|||
/* $NetBSD: cksum.c,v 1.48 2015/06/16 22:54:10 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* 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. 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.
|
||||
*/
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1997 Jason R. Thorpe. 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.
|
||||
*/
|
||||
|
||||
#if HAVE_NBTOOL_CONFIG_H
|
||||
#include "nbtool_config.h"
|
||||
#endif
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(__COPYRIGHT) && !defined(lint)
|
||||
__COPYRIGHT("@(#) Copyright (c) 1991, 1993\
|
||||
The Regents of the University of California. All rights reserved.");
|
||||
#endif /* not lint */
|
||||
|
||||
#if defined(__RCSID) && !defined(lint)
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)cksum.c 8.2 (Berkeley) 4/28/95";
|
||||
#endif
|
||||
__RCSID("$NetBSD: cksum.c,v 1.48 2015/06/16 22:54:10 christos Exp $");
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <locale.h>
|
||||
#include <md2.h>
|
||||
#include <md4.h>
|
||||
#include <md5.h>
|
||||
#include <rmd160.h>
|
||||
#include <sha1.h>
|
||||
#include <sha2.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "extern.h"
|
||||
|
||||
#define PRINT_NORMAL 0x01
|
||||
#define PRINT_QUIET 0x02
|
||||
|
||||
typedef char *(*_filefunc)(const char *, char *);
|
||||
|
||||
const struct hash {
|
||||
const char *progname;
|
||||
const char *hashname;
|
||||
void (*stringfunc)(const char *);
|
||||
void (*timetrialfunc)(void);
|
||||
void (*testsuitefunc)(void);
|
||||
void (*filterfunc)(int);
|
||||
char *(*filefunc)(const char *, char *);
|
||||
} hashes[] = {
|
||||
{ "md2", "MD2",
|
||||
MD2String, MD2TimeTrial, MD2TestSuite,
|
||||
MD2Filter, MD2File },
|
||||
{ "md4", "MD4",
|
||||
MD4String, MD4TimeTrial, MD4TestSuite,
|
||||
MD4Filter, MD4File },
|
||||
{ "md5", "MD5",
|
||||
MD5String, MD5TimeTrial, MD5TestSuite,
|
||||
MD5Filter, MD5File },
|
||||
{ "rmd160", "RMD160",
|
||||
RMD160String, RMD160TimeTrial, RMD160TestSuite,
|
||||
RMD160Filter, (_filefunc) RMD160File },
|
||||
{ "sha1", "SHA1",
|
||||
SHA1String, SHA1TimeTrial, SHA1TestSuite,
|
||||
SHA1Filter, (_filefunc) SHA1File },
|
||||
{ "sha256", "SHA256",
|
||||
SHA256_String, SHA256_TimeTrial, SHA256_TestSuite,
|
||||
SHA256_Filter, (_filefunc) SHA256_File },
|
||||
{ "sha384", "SHA384",
|
||||
SHA384_String, SHA384_TimeTrial, SHA384_TestSuite,
|
||||
SHA384_Filter, (_filefunc) SHA384_File },
|
||||
{ "sha512", "SHA512",
|
||||
SHA512_String, SHA512_TimeTrial, SHA512_TestSuite,
|
||||
SHA512_Filter, (_filefunc) SHA512_File },
|
||||
{ .progname = NULL, },
|
||||
};
|
||||
|
||||
static int hash_digest_file(char *, const struct hash *, int);
|
||||
__dead static void requirehash(const char *);
|
||||
__dead static void usage(void);
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
int ch, fd, rval, pflag, nohashstdin;
|
||||
u_int32_t val;
|
||||
off_t len;
|
||||
char *fn;
|
||||
const char *progname;
|
||||
int (*cfncn) (int, u_int32_t *, off_t *);
|
||||
void (*pfncn) (char *, u_int32_t, off_t);
|
||||
const struct hash *hash;
|
||||
int i, check_warn, do_check;
|
||||
int print_flags;
|
||||
|
||||
cfncn = NULL;
|
||||
pfncn = NULL;
|
||||
pflag = nohashstdin = 0;
|
||||
check_warn = 0;
|
||||
do_check = 0;
|
||||
print_flags = 0;
|
||||
|
||||
setlocale(LC_ALL, "");
|
||||
|
||||
progname = getprogname();
|
||||
|
||||
for (hash = hashes; hash->hashname != NULL; hash++)
|
||||
if (strcmp(progname, hash->progname) == 0)
|
||||
break;
|
||||
|
||||
if (hash->hashname == NULL) {
|
||||
hash = NULL;
|
||||
|
||||
if (!strcmp(progname, "sum")) {
|
||||
cfncn = csum1;
|
||||
pfncn = psum1;
|
||||
} else {
|
||||
cfncn = crc;
|
||||
pfncn = pcrc;
|
||||
}
|
||||
}
|
||||
|
||||
while ((ch = getopt(argc, argv, "a:cno:pqs:twx")) != -1)
|
||||
switch(ch) {
|
||||
case 'a':
|
||||
if (hash) {
|
||||
warnx("illegal use of -a option");
|
||||
usage();
|
||||
}
|
||||
i = 0;
|
||||
while (hashes[i].hashname != NULL) {
|
||||
if (!strcasecmp(hashes[i].hashname, optarg)) {
|
||||
hash = &hashes[i];
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
if (hash == NULL) {
|
||||
if (!strcasecmp(optarg, "old1")) {
|
||||
cfncn = csum1;
|
||||
pfncn = psum1;
|
||||
} else if (!strcasecmp(optarg, "old2")) {
|
||||
cfncn = csum2;
|
||||
pfncn = psum2;
|
||||
} else if (!strcasecmp(optarg, "crc")) {
|
||||
cfncn = crc;
|
||||
pfncn = pcrc;
|
||||
} else {
|
||||
warnx("illegal argument to -a option");
|
||||
usage();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'c':
|
||||
do_check = 1;
|
||||
break;
|
||||
case 'n':
|
||||
print_flags |= PRINT_NORMAL;
|
||||
break;
|
||||
case 'o':
|
||||
if (hash) {
|
||||
warnx("%s mutually exclusive with sum",
|
||||
hash->hashname);
|
||||
usage();
|
||||
}
|
||||
if (!strcmp(optarg, "1")) {
|
||||
cfncn = csum1;
|
||||
pfncn = psum1;
|
||||
} else if (!strcmp(optarg, "2")) {
|
||||
cfncn = csum2;
|
||||
pfncn = psum2;
|
||||
} else {
|
||||
warnx("illegal argument to -o option");
|
||||
usage();
|
||||
}
|
||||
break;
|
||||
case 'p':
|
||||
if (hash == NULL)
|
||||
requirehash("-p");
|
||||
pflag = 1;
|
||||
break;
|
||||
case 'q':
|
||||
print_flags |= PRINT_QUIET;
|
||||
break;
|
||||
case 's':
|
||||
if (hash == NULL)
|
||||
requirehash("-s");
|
||||
nohashstdin = 1;
|
||||
hash->stringfunc(optarg);
|
||||
break;
|
||||
case 't':
|
||||
if (hash == NULL)
|
||||
requirehash("-t");
|
||||
nohashstdin = 1;
|
||||
hash->timetrialfunc();
|
||||
break;
|
||||
case 'w':
|
||||
check_warn = 1;
|
||||
break;
|
||||
case 'x':
|
||||
if (hash == NULL)
|
||||
requirehash("-x");
|
||||
nohashstdin = 1;
|
||||
hash->testsuitefunc();
|
||||
break;
|
||||
case '?':
|
||||
default:
|
||||
usage();
|
||||
}
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
if (do_check) {
|
||||
/*
|
||||
* Verify checksums
|
||||
*/
|
||||
FILE *f;
|
||||
char buf[BUFSIZ];
|
||||
char *s, *p_filename, *p_cksum;
|
||||
int l_filename, l_cksum;
|
||||
char filename[BUFSIZ];
|
||||
char cksum[BUFSIZ];
|
||||
int ok,cnt,badcnt;
|
||||
|
||||
rval = 0;
|
||||
cnt = badcnt = 0;
|
||||
|
||||
if (argc == 0) {
|
||||
f = fdopen(STDIN_FILENO, "r");
|
||||
} else {
|
||||
f = fopen(argv[0], "r");
|
||||
}
|
||||
if (f == NULL)
|
||||
err(1, "Cannot read %s",
|
||||
argc>0?argv[0]:"stdin");
|
||||
|
||||
while(fgets(buf, sizeof(buf), f) != NULL) {
|
||||
s = strrchr(buf, '\n');
|
||||
if (s)
|
||||
*s = '\0';
|
||||
|
||||
p_cksum = p_filename = NULL;
|
||||
|
||||
p_filename = strchr(buf, '(');
|
||||
if (p_filename) {
|
||||
/*
|
||||
* Assume 'normal' output if there's a '('
|
||||
*/
|
||||
p_filename += 1;
|
||||
print_flags &= ~(PRINT_NORMAL);
|
||||
|
||||
p_cksum = strrchr(p_filename, ')');
|
||||
if (p_cksum == NULL) {
|
||||
if (check_warn)
|
||||
warnx("bogus format: %s. "
|
||||
"Skipping...",
|
||||
buf);
|
||||
rval = 1;
|
||||
continue;
|
||||
}
|
||||
p_cksum += 4;
|
||||
|
||||
l_cksum = strlen(p_cksum);
|
||||
l_filename = p_cksum - p_filename - 4;
|
||||
|
||||
/* Sanity check, and find proper hash if
|
||||
* it's not the same as the current program
|
||||
*/
|
||||
if (hash == NULL ||
|
||||
strncmp(buf, hash->hashname,
|
||||
strlen(hash->hashname)) != 0) {
|
||||
/*
|
||||
* Search proper hash
|
||||
*/
|
||||
const struct hash *nhash;
|
||||
|
||||
for (nhash = hashes ;
|
||||
nhash->hashname != NULL;
|
||||
nhash++)
|
||||
if (strncmp(buf,
|
||||
nhash->hashname,
|
||||
strlen(nhash->hashname)) == 0)
|
||||
break;
|
||||
|
||||
|
||||
if (nhash->hashname == NULL) {
|
||||
if (check_warn)
|
||||
warnx("unknown hash: %s",
|
||||
buf);
|
||||
rval = 1;
|
||||
continue;
|
||||
} else {
|
||||
hash = nhash;
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
if (hash) {
|
||||
int nspaces;
|
||||
|
||||
/*
|
||||
* 'normal' output, no (ck)sum
|
||||
*/
|
||||
print_flags |= PRINT_NORMAL;
|
||||
nspaces = 1;
|
||||
|
||||
p_cksum = buf;
|
||||
p_filename = strchr(buf, ' ');
|
||||
if (p_filename == NULL) {
|
||||
if (check_warn)
|
||||
warnx("no filename in %s? "
|
||||
"Skipping...", buf);
|
||||
rval = 1;
|
||||
continue;
|
||||
}
|
||||
while (isspace((int)*++p_filename))
|
||||
nspaces++;
|
||||
l_filename = strlen(p_filename);
|
||||
l_cksum = p_filename - buf - nspaces;
|
||||
} else {
|
||||
/*
|
||||
* sum/cksum output format
|
||||
*/
|
||||
p_cksum = buf;
|
||||
s=strchr(p_cksum, ' ');
|
||||
if (s == NULL) {
|
||||
if (check_warn)
|
||||
warnx("bogus format: %s."
|
||||
" Skipping...",
|
||||
buf);
|
||||
rval = 1;
|
||||
continue;
|
||||
}
|
||||
l_cksum = s - p_cksum;
|
||||
|
||||
p_filename = strrchr(buf, ' ');
|
||||
if (p_filename == NULL) {
|
||||
if (check_warn)
|
||||
warnx("no filename in %s?"
|
||||
" Skipping...",
|
||||
buf);
|
||||
rval = 1;
|
||||
continue;
|
||||
}
|
||||
p_filename++;
|
||||
l_filename = strlen(p_filename);
|
||||
}
|
||||
}
|
||||
|
||||
strlcpy(filename, p_filename, l_filename+1);
|
||||
strlcpy(cksum, p_cksum, l_cksum+1);
|
||||
|
||||
if (hash) {
|
||||
if (access(filename, R_OK) == 0
|
||||
&& strcmp(cksum, hash->filefunc(filename, NULL)) == 0)
|
||||
ok = 1;
|
||||
else
|
||||
ok = 0;
|
||||
} else {
|
||||
if ((fd = open(filename, O_RDONLY, 0)) < 0) {
|
||||
if (check_warn)
|
||||
warn("%s", filename);
|
||||
rval = 1;
|
||||
ok = 0;
|
||||
} else {
|
||||
if (cfncn(fd, &val, &len))
|
||||
ok = 0;
|
||||
else {
|
||||
u_int32_t should_val;
|
||||
|
||||
should_val =
|
||||
strtoul(cksum, NULL, 10);
|
||||
if (val == should_val)
|
||||
ok = 1;
|
||||
else
|
||||
ok = 0;
|
||||
}
|
||||
close(fd);
|
||||
}
|
||||
}
|
||||
|
||||
if (! ok) {
|
||||
if (hash)
|
||||
printf("(%s) ", hash->hashname);
|
||||
printf("%s: FAILED\n", filename);
|
||||
badcnt++;
|
||||
}
|
||||
cnt++;
|
||||
|
||||
}
|
||||
fclose(f);
|
||||
|
||||
if (badcnt > 0)
|
||||
rval = 1;
|
||||
|
||||
} else {
|
||||
/*
|
||||
* Calculate checksums
|
||||
*/
|
||||
|
||||
fd = STDIN_FILENO;
|
||||
fn = NULL;
|
||||
rval = 0;
|
||||
do {
|
||||
if (*argv) {
|
||||
fn = *argv++;
|
||||
if (hash != NULL) {
|
||||
if (hash_digest_file(fn, hash, print_flags)) {
|
||||
warn("%s", fn);
|
||||
rval = 1;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if ((fd = open(fn, O_RDONLY, 0)) < 0) {
|
||||
warn("%s", fn);
|
||||
rval = 1;
|
||||
continue;
|
||||
}
|
||||
} else if (hash && !nohashstdin) {
|
||||
hash->filterfunc(pflag);
|
||||
}
|
||||
|
||||
if (hash == NULL) {
|
||||
if (cfncn(fd, &val, &len)) {
|
||||
warn("%s", fn ? fn : "stdin");
|
||||
rval = 1;
|
||||
} else
|
||||
pfncn(fn, val, len);
|
||||
(void)close(fd);
|
||||
}
|
||||
} while (*argv);
|
||||
}
|
||||
exit(rval);
|
||||
}
|
||||
|
||||
static int
|
||||
hash_digest_file(char *fn, const struct hash *hash, int flags)
|
||||
{
|
||||
char *cp;
|
||||
|
||||
cp = hash->filefunc(fn, NULL);
|
||||
if (cp == NULL)
|
||||
return 1;
|
||||
|
||||
if (flags & PRINT_QUIET)
|
||||
printf("%s\n", cp);
|
||||
else if (flags & PRINT_NORMAL)
|
||||
printf("%s %s\n", cp, fn);
|
||||
else
|
||||
printf("%s (%s) = %s\n", hash->hashname, fn, cp);
|
||||
|
||||
free(cp);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
requirehash(const char *flg)
|
||||
{
|
||||
warnx("%s flag requires `-a algorithm'", flg);
|
||||
usage();
|
||||
}
|
||||
|
||||
static void
|
||||
usage(void)
|
||||
{
|
||||
const char fileargs[] = "[file ... | -c [-w] [sumfile]]";
|
||||
const char sumargs[] = "[-n] [-a algorithm [-ptx] [-s string]] [-o 1|2]";
|
||||
const char hashargs[] = "[-nptx] [-s string]";
|
||||
|
||||
(void)fprintf(stderr, "usage: cksum %s\n %s\n",
|
||||
sumargs, fileargs);
|
||||
(void)fprintf(stderr, " sum %s\n %s\n",
|
||||
sumargs, fileargs);
|
||||
(void)fprintf(stderr, " md2 %s %s\n", hashargs, fileargs);
|
||||
(void)fprintf(stderr, " md4 %s %s\n", hashargs, fileargs);
|
||||
(void)fprintf(stderr, " md5 %s %s\n", hashargs, fileargs);
|
||||
(void)fprintf(stderr, " rmd160 %s %s\n", hashargs, fileargs);
|
||||
(void)fprintf(stderr, " sha1 %s %s\n", hashargs, fileargs);
|
||||
exit(1);
|
||||
}
|
||||
|
|
@ -1,162 +0,0 @@
|
|||
/* $NetBSD: crc.c,v 1.19 2014/10/29 18:09:35 uebayasi Exp $ */
|
||||
|
||||
/*-
|
||||
* 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. 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.
|
||||
*/
|
||||
|
||||
#if HAVE_NBTOOL_CONFIG_H
|
||||
#include "nbtool_config.h"
|
||||
#endif
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(__RCSID) && !defined(lint)
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)crc.c 8.1 (Berkeley) 6/17/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: crc.c,v 1.19 2014/10/29 18:09:35 uebayasi Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "extern.h"
|
||||
|
||||
static const u_int32_t 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.
|
||||
*/
|
||||
int
|
||||
crc(int fd, u_int32_t *cval, off_t *clen)
|
||||
{
|
||||
u_char *p;
|
||||
ssize_t nr;
|
||||
u_int32_t thecrc;
|
||||
off_t len;
|
||||
u_char buf[16 * 1024];
|
||||
|
||||
#define COMPUTE(var, ch) (var) = (var) << 8 ^ crctab[(var) >> 24 ^ (ch)]
|
||||
|
||||
thecrc = 0;
|
||||
len = 0;
|
||||
while ((nr = read(fd, buf, sizeof(buf))) > 0)
|
||||
for (len += nr, p = buf; nr--; ++p) {
|
||||
COMPUTE(thecrc, *p);
|
||||
}
|
||||
if (nr < 0)
|
||||
return 1;
|
||||
|
||||
*clen = len;
|
||||
|
||||
/* Include the length of the file. */
|
||||
for (; len != 0; len >>= 8) {
|
||||
COMPUTE(thecrc, len & 0xff);
|
||||
}
|
||||
|
||||
*cval = ~thecrc;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* These two are rather more useful to the outside world */
|
||||
|
||||
uint32_t
|
||||
crc_buf(uint32_t thecrc, const void *buf, size_t len)
|
||||
{
|
||||
const uint8_t *p = buf;
|
||||
|
||||
for (p = buf; len; p++, len--)
|
||||
COMPUTE(thecrc, *p);
|
||||
return thecrc;
|
||||
}
|
||||
|
||||
uint32_t
|
||||
crc_byte(uint32_t thecrc, unsigned int byte_val)
|
||||
{
|
||||
COMPUTE(thecrc, byte_val & 0xff);
|
||||
return thecrc;
|
||||
}
|
||||
|
|
@ -1,38 +0,0 @@
|
|||
/* $NetBSD: crc_extern.h,v 1.1 2006/09/04 20:01:10 dsl Exp $ */
|
||||
|
||||
/*-
|
||||
* 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. 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
|
||||
*/
|
||||
|
||||
__BEGIN_DECLS
|
||||
int crc(int, u_int32_t *, off_t *);
|
||||
uint32_t crc_buf(uint32_t, const void *, size_t);
|
||||
uint32_t crc_byte(uint32_t, unsigned int);
|
||||
__END_DECLS
|
||||
|
|
@ -1,88 +0,0 @@
|
|||
/* $NetBSD: extern.h,v 1.19 2006/09/04 20:01:10 dsl Exp $ */
|
||||
|
||||
/*-
|
||||
* 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. 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
|
||||
*/
|
||||
|
||||
#if HAVE_NBTOOL_CONFIG_H
|
||||
#include "nbtool_config.h"
|
||||
#endif
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#include "crc_extern.h"
|
||||
|
||||
__BEGIN_DECLS
|
||||
void pcrc(char *, u_int32_t, off_t);
|
||||
void psum1(char *, u_int32_t, off_t);
|
||||
void psum2(char *, u_int32_t, off_t);
|
||||
int csum1(int, u_int32_t *, off_t *);
|
||||
int csum2(int, u_int32_t *, off_t *);
|
||||
int md5(int, u_int32_t *, u_int32_t *);
|
||||
|
||||
void MD2String(const char *);
|
||||
void MD2TimeTrial(void);
|
||||
void MD2TestSuite(void);
|
||||
void MD2Filter(int);
|
||||
|
||||
void MD4String(const char *);
|
||||
void MD4TimeTrial(void);
|
||||
void MD4TestSuite(void);
|
||||
void MD4Filter(int);
|
||||
|
||||
void MD5String(const char *);
|
||||
void MD5TimeTrial(void);
|
||||
void MD5TestSuite(void);
|
||||
void MD5Filter(int);
|
||||
|
||||
void SHA1String(const char *);
|
||||
void SHA1TimeTrial(void);
|
||||
void SHA1TestSuite(void);
|
||||
void SHA1Filter(int);
|
||||
|
||||
void RMD160String(const char *);
|
||||
void RMD160TimeTrial(void);
|
||||
void RMD160TestSuite(void);
|
||||
void RMD160Filter(int);
|
||||
|
||||
void SHA256_String(const char *);
|
||||
void SHA256_TimeTrial(void);
|
||||
void SHA256_TestSuite(void);
|
||||
void SHA256_Filter(int);
|
||||
|
||||
void SHA384_String(const char *);
|
||||
void SHA384_TimeTrial(void);
|
||||
void SHA384_TestSuite(void);
|
||||
void SHA384_Filter(int);
|
||||
|
||||
void SHA512_String(const char *);
|
||||
void SHA512_TimeTrial(void);
|
||||
void SHA512_TestSuite(void);
|
||||
void SHA512_Filter(int);
|
||||
__END_DECLS
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
/* $NetBSD: md2.c,v 1.1 2001/03/20 18:46:26 atatat Exp $ */
|
||||
|
||||
#include <md2.h> /* this hash type */
|
||||
#include <md5.h> /* the hash we're replacing */
|
||||
|
||||
#define HASHTYPE "MD2"
|
||||
#define HASHLEN 32
|
||||
|
||||
#define MD5Filter MD2Filter
|
||||
#define MD5String MD2String
|
||||
#define MD5TestSuite MD2TestSuite
|
||||
#define MD5TimeTrial MD2TimeTrial
|
||||
|
||||
#define MD5Data MD2Data
|
||||
#define MD5Init MD2Init
|
||||
#define MD5Update MD2Update
|
||||
#define MD5End MD2End
|
||||
|
||||
#define MD5_CTX MD2_CTX
|
||||
|
||||
#include "md5.c"
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
/* $NetBSD: md4.c,v 1.1 2001/03/20 18:46:26 atatat Exp $ */
|
||||
|
||||
#include <md4.h> /* this hash type */
|
||||
#include <md5.h> /* the hash we're replacing */
|
||||
|
||||
#define HASHTYPE "MD4"
|
||||
#define HASHLEN 32
|
||||
|
||||
#define MD5Filter MD4Filter
|
||||
#define MD5String MD4String
|
||||
#define MD5TestSuite MD4TestSuite
|
||||
#define MD5TimeTrial MD4TimeTrial
|
||||
|
||||
#define MD5Data MD4Data
|
||||
#define MD5Init MD4Init
|
||||
#define MD5Update MD4Update
|
||||
#define MD5End MD4End
|
||||
|
||||
#define MD5_CTX MD4_CTX
|
||||
|
||||
#include "md5.c"
|
||||
|
|
@ -1,153 +0,0 @@
|
|||
/* $NetBSD: md5.c,v 1.10 2008/12/29 00:51:29 christos Exp $ */
|
||||
|
||||
/*
|
||||
* MDDRIVER.C - test driver for MD2, MD4 and MD5
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 1990-2, RSA Data Security, Inc. Created 1990. All
|
||||
* rights reserved.
|
||||
*
|
||||
* RSA Data Security, Inc. makes no representations concerning either
|
||||
* the merchantability of this software or the suitability of this
|
||||
* software for any particular purpose. It is provided "as is"
|
||||
* without express or implied warranty of any kind.
|
||||
*
|
||||
* These notices must be retained in any copies of any part of this
|
||||
* documentation and/or software.
|
||||
*/
|
||||
|
||||
#if HAVE_NBTOOL_CONFIG_H
|
||||
#include "nbtool_config.h"
|
||||
#endif
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(__RCSID) && !defined(lint)
|
||||
__RCSID("$NetBSD: md5.c,v 1.10 2008/12/29 00:51:29 christos Exp $");
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <err.h>
|
||||
#include <md5.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
void MD5Filter(int);
|
||||
void MD5String(const char *);
|
||||
void MD5TestSuite(void);
|
||||
void MD5TimeTrial(void);
|
||||
|
||||
#ifndef HASHTYPE
|
||||
#define HASHTYPE "MD5"
|
||||
#endif
|
||||
|
||||
#ifndef HASHLEN
|
||||
#define HASHLEN 32
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Length of test block, number of test blocks.
|
||||
*/
|
||||
#define TEST_BLOCK_LEN 1000
|
||||
#define TEST_BLOCK_COUNT 1000
|
||||
|
||||
/*
|
||||
* Digests a string and prints the result.
|
||||
*/
|
||||
void
|
||||
MD5String(const char *string)
|
||||
{
|
||||
unsigned int len = strlen(string);
|
||||
char buf[HASHLEN + 1];
|
||||
|
||||
printf("%s (\"%s\") = %s\n", HASHTYPE, string,
|
||||
MD5Data((const unsigned char *)string, len, buf));
|
||||
}
|
||||
|
||||
/*
|
||||
* Measures the time to digest TEST_BLOCK_COUNT TEST_BLOCK_LEN-byte blocks.
|
||||
*/
|
||||
void
|
||||
MD5TimeTrial(void)
|
||||
{
|
||||
MD5_CTX context;
|
||||
time_t endTime, startTime;
|
||||
unsigned char block[TEST_BLOCK_LEN];
|
||||
unsigned int i;
|
||||
char *p, buf[HASHLEN + 1];
|
||||
|
||||
printf("%s time trial. Digesting %d %d-byte blocks ...", HASHTYPE,
|
||||
TEST_BLOCK_LEN, TEST_BLOCK_COUNT);
|
||||
fflush(stdout);
|
||||
|
||||
/* Initialize block */
|
||||
for (i = 0; i < TEST_BLOCK_LEN; i++)
|
||||
block[i] = (unsigned char) (i & 0xff);
|
||||
|
||||
/* Start timer */
|
||||
time(&startTime);
|
||||
|
||||
/* Digest blocks */
|
||||
MD5Init(&context);
|
||||
for (i = 0; i < TEST_BLOCK_COUNT; i++)
|
||||
MD5Update(&context, block, TEST_BLOCK_LEN);
|
||||
p = MD5End(&context,buf);
|
||||
|
||||
/* Stop timer */
|
||||
time(&endTime);
|
||||
|
||||
printf(" done\n");
|
||||
printf("Digest = %s\n", p);
|
||||
printf("Time = %ld seconds\n", (long) (endTime - startTime));
|
||||
|
||||
/*
|
||||
* Be careful that endTime-startTime is not zero.
|
||||
* (Bug fix from Ric * Anderson, ric@Artisoft.COM.)
|
||||
*/
|
||||
printf("Speed = %lld bytes/second\n",
|
||||
(long long) TEST_BLOCK_LEN * TEST_BLOCK_COUNT /
|
||||
((endTime - startTime) != 0 ? (endTime - startTime) : 1));
|
||||
}
|
||||
|
||||
/*
|
||||
* Digests a reference suite of strings and prints the results.
|
||||
*/
|
||||
void
|
||||
MD5TestSuite(void)
|
||||
{
|
||||
printf("%s test suite:\n", HASHTYPE);
|
||||
|
||||
MD5String("");
|
||||
MD5String("a");
|
||||
MD5String("abc");
|
||||
MD5String("message digest");
|
||||
MD5String("abcdefghijklmnopqrstuvwxyz");
|
||||
MD5String("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq");
|
||||
MD5String
|
||||
("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");
|
||||
MD5String
|
||||
("1234567890123456789012345678901234567890\
|
||||
1234567890123456789012345678901234567890");
|
||||
}
|
||||
|
||||
/*
|
||||
* Digests the standard input and prints the result.
|
||||
*/
|
||||
void
|
||||
MD5Filter(int pipe)
|
||||
{
|
||||
MD5_CTX context;
|
||||
size_t len;
|
||||
unsigned char buffer[BUFSIZ];
|
||||
char buf[HASHLEN + 1];
|
||||
|
||||
MD5Init(&context);
|
||||
while ((len = fread(buffer, (size_t)1, (size_t)BUFSIZ, stdin)) > 0) {
|
||||
if (pipe && (len != fwrite(buffer, (size_t)1, len, stdout)))
|
||||
err(1, "stdout");
|
||||
MD5Update(&context, buffer, (unsigned int)len);
|
||||
}
|
||||
printf("%s\n", MD5End(&context,buf));
|
||||
}
|
||||
|
|
@ -1,76 +0,0 @@
|
|||
/* $NetBSD: print.c,v 1.11 2005/01/12 17:04:35 xtraeme Exp $ */
|
||||
|
||||
/*-
|
||||
* 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. 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.
|
||||
*/
|
||||
|
||||
#if HAVE_NBTOOL_CONFIG_H
|
||||
#include "nbtool_config.h"
|
||||
#endif
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(__RCSID) && !defined(lint)
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)print.c 8.1 (Berkeley) 6/6/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: print.c,v 1.11 2005/01/12 17:04:35 xtraeme Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdio.h>
|
||||
#include "extern.h"
|
||||
|
||||
void
|
||||
pcrc(char *fn, u_int32_t val, off_t len)
|
||||
{
|
||||
(void)printf("%lu %lld", (unsigned long)val, (long long)len);
|
||||
if (fn)
|
||||
(void)printf(" %s", fn);
|
||||
(void)printf("\n");
|
||||
}
|
||||
|
||||
void
|
||||
psum1(char *fn, u_int32_t val, off_t len)
|
||||
{
|
||||
(void)printf("%lu %lld", (unsigned long)val,
|
||||
(long long)(len + 1023) / 1024);
|
||||
if (fn)
|
||||
(void)printf(" %s", fn);
|
||||
(void)printf("\n");
|
||||
}
|
||||
|
||||
void
|
||||
psum2(char *fn, u_int32_t val, off_t len)
|
||||
{
|
||||
(void)printf("%lu %lld", (unsigned long)val,
|
||||
(long long)(len + 511) / 512);
|
||||
if (fn)
|
||||
(void)printf(" %s", fn);
|
||||
(void)printf("\n");
|
||||
}
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
/* $NetBSD: rmd160.c,v 1.3 2006/10/30 20:22:54 christos Exp $ */
|
||||
|
||||
#if HAVE_NBTOOL_CONFIG_H
|
||||
#include "nbtool_config.h"
|
||||
#endif
|
||||
|
||||
#include <rmd160.h> /* this hash type */
|
||||
#include <md5.h> /* the hash we're replacing */
|
||||
|
||||
#define HASHTYPE "RMD160"
|
||||
#define HASHLEN 40
|
||||
|
||||
#define MD5Filter RMD160Filter
|
||||
#define MD5String RMD160String
|
||||
#define MD5TestSuite RMD160TestSuite
|
||||
#define MD5TimeTrial RMD160TimeTrial
|
||||
|
||||
#define MD5Data RMD160Data
|
||||
#define MD5Init RMD160Init
|
||||
#define MD5Update RMD160Update
|
||||
#define MD5End RMD160End
|
||||
|
||||
#define MD5_CTX RMD160_CTX
|
||||
|
||||
#include "md5.c"
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
/* $NetBSD: sha1.c,v 1.1 2001/03/20 18:46:27 atatat Exp $ */
|
||||
|
||||
#include <sha1.h> /* this hash type */
|
||||
#include <md5.h> /* the hash we're replacing */
|
||||
|
||||
#define HASHTYPE "SHA1"
|
||||
#define HASHLEN 40
|
||||
|
||||
#define MD5Filter SHA1Filter
|
||||
#define MD5String SHA1String
|
||||
#define MD5TestSuite SHA1TestSuite
|
||||
#define MD5TimeTrial SHA1TimeTrial
|
||||
|
||||
#define MD5Data SHA1Data
|
||||
#define MD5Init SHA1Init
|
||||
#define MD5Update SHA1Update
|
||||
#define MD5End SHA1End
|
||||
|
||||
#define MD5_CTX SHA1_CTX
|
||||
|
||||
#include "md5.c"
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
/* $NetBSD: sha256.c,v 1.3 2006/10/30 20:22:54 christos Exp $ */
|
||||
|
||||
#if HAVE_NBTOOL_CONFIG_H
|
||||
#include "nbtool_config.h"
|
||||
#endif
|
||||
|
||||
#include <sha2.h> /* this hash type */
|
||||
#include <md5.h> /* the hash we're replacing */
|
||||
|
||||
#define HASHTYPE "SHA256"
|
||||
#define HASHLEN 64
|
||||
|
||||
#define MD5Filter SHA256_Filter
|
||||
#define MD5String SHA256_String
|
||||
#define MD5TestSuite SHA256_TestSuite
|
||||
#define MD5TimeTrial SHA256_TimeTrial
|
||||
|
||||
#define MD5Data SHA256_Data
|
||||
#define MD5Init SHA256_Init
|
||||
#define MD5Update SHA256_Update
|
||||
#define MD5End SHA256_End
|
||||
|
||||
#define MD5_CTX SHA256_CTX
|
||||
|
||||
#include "md5.c"
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
/* $NetBSD: sha384.c,v 1.3 2006/10/30 20:22:54 christos Exp $ */
|
||||
|
||||
#if HAVE_NBTOOL_CONFIG_H
|
||||
#include "nbtool_config.h"
|
||||
#endif
|
||||
|
||||
#include <sha2.h> /* this hash type */
|
||||
#include <md5.h> /* the hash we're replacing */
|
||||
|
||||
#define HASHTYPE "SHA384"
|
||||
#define HASHLEN 96
|
||||
|
||||
#define MD5Filter SHA384_Filter
|
||||
#define MD5String SHA384_String
|
||||
#define MD5TestSuite SHA384_TestSuite
|
||||
#define MD5TimeTrial SHA384_TimeTrial
|
||||
|
||||
#define MD5Data SHA384_Data
|
||||
#define MD5Init SHA384_Init
|
||||
#define MD5Update SHA384_Update
|
||||
#define MD5End SHA384_End
|
||||
|
||||
#define MD5_CTX SHA384_CTX
|
||||
|
||||
#include "md5.c"
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
/* $NetBSD: sha512.c,v 1.3 2006/10/30 20:22:54 christos Exp $ */
|
||||
|
||||
#if HAVE_NBTOOL_CONFIG_H
|
||||
#include "nbtool_config.h"
|
||||
#endif
|
||||
|
||||
#include <sha2.h> /* this hash type */
|
||||
#include <md5.h> /* the hash we're replacing */
|
||||
|
||||
#define HASHTYPE "SHA512"
|
||||
#define HASHLEN 128
|
||||
|
||||
#define MD5Filter SHA512_Filter
|
||||
#define MD5String SHA512_String
|
||||
#define MD5TestSuite SHA512_TestSuite
|
||||
#define MD5TimeTrial SHA512_TimeTrial
|
||||
|
||||
#define MD5Data SHA512_Data
|
||||
#define MD5Init SHA512_Init
|
||||
#define MD5Update SHA512_Update
|
||||
#define MD5End SHA512_End
|
||||
|
||||
#define MD5_CTX SHA512_CTX
|
||||
|
||||
#include "md5.c"
|
||||
|
|
@ -1,76 +0,0 @@
|
|||
/* $NetBSD: sum1.c,v 1.13 2005/02/05 00:13:34 simonb Exp $ */
|
||||
|
||||
/*-
|
||||
* 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. 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.
|
||||
*/
|
||||
|
||||
#if HAVE_NBTOOL_CONFIG_H
|
||||
#include "nbtool_config.h"
|
||||
#endif
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(__RCSID) && !defined(lint)
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)sum1.c 8.1 (Berkeley) 6/6/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: sum1.c,v 1.13 2005/02/05 00:13:34 simonb Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "extern.h"
|
||||
|
||||
int
|
||||
csum1(int fd, u_int32_t *cval, off_t *clen)
|
||||
{
|
||||
off_t total;
|
||||
int nr;
|
||||
u_int thecrc;
|
||||
u_char *p;
|
||||
u_char buf[8192];
|
||||
|
||||
/*
|
||||
* 16-bit checksum, rotating right before each addition;
|
||||
* overflow is discarded.
|
||||
*/
|
||||
thecrc = total = 0;
|
||||
while ((nr = read(fd, buf, sizeof(buf))) > 0)
|
||||
for (total += nr, p = buf; nr--; ++p) {
|
||||
if (thecrc & 1)
|
||||
thecrc |= 0x10000;
|
||||
thecrc = ((thecrc >> 1) + *p) & 0xffff;
|
||||
}
|
||||
if (nr < 0)
|
||||
return 1;
|
||||
|
||||
*cval = thecrc;
|
||||
*clen = total;
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1,80 +0,0 @@
|
|||
/* $NetBSD: sum2.c,v 1.13 2005/02/05 00:13:34 simonb Exp $ */
|
||||
|
||||
/*-
|
||||
* 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. 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.
|
||||
*/
|
||||
|
||||
#if HAVE_NBTOOL_CONFIG_H
|
||||
#include "nbtool_config.h"
|
||||
#endif
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(__RCSID) && !defined(lint)
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)sum2.c 8.1 (Berkeley) 6/6/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: sum2.c,v 1.13 2005/02/05 00:13:34 simonb Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "extern.h"
|
||||
|
||||
int
|
||||
csum2(int fd, u_int32_t *cval, off_t *clen)
|
||||
{
|
||||
u_int32_t thecrc;
|
||||
off_t total;
|
||||
int nr;
|
||||
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
|
||||
* thecrc = (r % 2^16) + r / 2^16
|
||||
*/
|
||||
thecrc = 0;
|
||||
total = 0;
|
||||
while ((nr = read(fd, buf, sizeof(buf))) > 0)
|
||||
for (total += nr, p = buf; nr--; ++p)
|
||||
thecrc += *p;
|
||||
if (nr < 0)
|
||||
return 1;
|
||||
|
||||
thecrc = (thecrc & 0xffff) + (thecrc >> 16);
|
||||
thecrc = (thecrc & 0xffff) + (thecrc >> 16);
|
||||
|
||||
*cval = thecrc;
|
||||
*clen = total;
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
# @(#)Makefile 8.1 (Berkeley) 6/6/93
|
||||
# $NetBSD: Makefile,v 1.4 1997/01/09 20:18:26 tls Exp $
|
||||
|
||||
PROG= cmp
|
||||
SRCS= cmp.c misc.c regular.c special.c
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
|
|
@ -1,105 +0,0 @@
|
|||
.\" $NetBSD: cmp.1,v 1.9 2003/08/07 11:13:21 agc Exp $
|
||||
.\"
|
||||
.\" 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. 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
|
||||
.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
|
||||
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
|
||||
writes to standard output that EOF was reached in the shorter
|
||||
file (before any differences were found).
|
||||
.It \*[Gt]1
|
||||
An error occurred.
|
||||
.El
|
||||
.Sh SEE ALSO
|
||||
.Xr diff 1 ,
|
||||
.Xr diff3 1
|
||||
.Sh STANDARDS
|
||||
The
|
||||
.Nm
|
||||
utility is expected to be
|
||||
.St -p1003.2
|
||||
compatible.
|
||||
|
|
@ -1,164 +0,0 @@
|
|||
/* $NetBSD: cmp.c,v 1.18 2011/08/29 14:14:11 joerg Exp $ */
|
||||
|
||||
/*
|
||||
* 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. 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.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
__COPYRIGHT("@(#) Copyright (c) 1987, 1990, 1993, 1994\
|
||||
The Regents of the University of California. All rights reserved.");
|
||||
#endif /* not lint */
|
||||
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)cmp.c 8.3 (Berkeley) 4/2/94";
|
||||
#else
|
||||
__RCSID("$NetBSD: cmp.c,v 1.18 2011/08/29 14:14:11 joerg Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <locale.h>
|
||||
|
||||
#include "extern.h"
|
||||
|
||||
int lflag, sflag;
|
||||
|
||||
__dead static void usage(void);
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
struct stat sb1, sb2;
|
||||
off_t skip1 = 0, skip2 = 0;
|
||||
int ch, fd1, fd2, special;
|
||||
const char *file1, *file2;
|
||||
|
||||
setlocale(LC_ALL, "");
|
||||
|
||||
while ((ch = getopt(argc, argv, "ls")) != -1)
|
||||
switch (ch) {
|
||||
case 'l': /* print all differences */
|
||||
lflag = 1;
|
||||
break;
|
||||
case 's': /* silent run */
|
||||
sflag = 1;
|
||||
break;
|
||||
case '?':
|
||||
default:
|
||||
usage();
|
||||
}
|
||||
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) {
|
||||
if (!sflag)
|
||||
warn("%s", file1);
|
||||
exit(ERR_EXIT);
|
||||
}
|
||||
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) {
|
||||
if (!sflag)
|
||||
warn("%s", file2);
|
||||
exit(ERR_EXIT);
|
||||
}
|
||||
|
||||
if (argc > 2) {
|
||||
char *ep;
|
||||
|
||||
errno = 0;
|
||||
skip1 = strtoq(argv[2], &ep, 0);
|
||||
if (errno || ep == argv[2])
|
||||
usage();
|
||||
|
||||
if (argc == 4) {
|
||||
skip2 = strtoq(argv[3], &ep, 0);
|
||||
if (errno || ep == argv[3])
|
||||
usage();
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
|
||||
(void)fprintf(stderr,
|
||||
"usage: cmp [-l | -s] file1 file2 [skip1 [skip2]]\n");
|
||||
exit(ERR_EXIT);
|
||||
}
|
||||
|
|
@ -1,44 +0,0 @@
|
|||
/* $NetBSD: extern.h,v 1.9 2011/08/29 14:14:11 joerg Exp $ */
|
||||
|
||||
/*-
|
||||
* 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. 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(int, const char *, off_t, off_t, int, const char *, off_t, off_t);
|
||||
void c_special(int, const char *, off_t, int, const char *, off_t);
|
||||
__dead void diffmsg(const char *, const char *, off_t, off_t);
|
||||
__dead void eofmsg(const char *, off_t, off_t);
|
||||
__dead void errmsg(const char *, off_t, off_t);
|
||||
|
||||
extern int lflag, sflag;
|
||||
|
|
@ -1,84 +0,0 @@
|
|||
/* $NetBSD: misc.c,v 1.12 2009/04/11 12:16:12 lukem Exp $ */
|
||||
|
||||
/*-
|
||||
* 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. 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.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)misc.c 8.3 (Berkeley) 4/2/94";
|
||||
#else
|
||||
__RCSID("$NetBSD: misc.c,v 1.12 2009/04/11 12:16:12 lukem Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <err.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "extern.h"
|
||||
|
||||
void
|
||||
errmsg(const char *file, off_t byte, off_t line)
|
||||
{
|
||||
if (lflag)
|
||||
err(ERR_EXIT, "%s: char %lld, line %lld", file,
|
||||
(long long)byte, (long long)line);
|
||||
else
|
||||
err(ERR_EXIT, "%s", file);
|
||||
}
|
||||
|
||||
void
|
||||
eofmsg(const char *file, off_t byte, off_t line)
|
||||
{
|
||||
if (!sflag) {
|
||||
if (!lflag)
|
||||
warnx("EOF on %s", file);
|
||||
else {
|
||||
if (line > 0)
|
||||
warnx("EOF on %s: char %lld, line %lld",
|
||||
file, (long long)byte, (long long)line);
|
||||
else
|
||||
warnx("EOF on %s: char %lld",
|
||||
file, (long long)byte);
|
||||
}
|
||||
}
|
||||
exit(DIFF_EXIT);
|
||||
}
|
||||
|
||||
void
|
||||
diffmsg(const char *file1, const char *file2, off_t byte, off_t line)
|
||||
{
|
||||
if (!sflag)
|
||||
(void)printf("%s %s differ: char %lld, line %lld\n",
|
||||
file1, file2, (long long)byte, (long long)line);
|
||||
exit(DIFF_EXIT);
|
||||
}
|
||||
|
|
@ -1,118 +0,0 @@
|
|||
/* $NetBSD: regular.c,v 1.24 2013/11/20 17:19:14 kleink Exp $ */
|
||||
|
||||
/*-
|
||||
* 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. 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.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)regular.c 8.3 (Berkeley) 4/2/94";
|
||||
#else
|
||||
__RCSID("$NetBSD: regular.c,v 1.24 2013/11/20 17:19:14 kleink Exp $");
|
||||
#endif
|
||||
#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 <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "extern.h"
|
||||
|
||||
void
|
||||
c_regular(int fd1, const char *file1, off_t skip1, off_t len1,
|
||||
int fd2, const char *file2, off_t skip2, off_t len2)
|
||||
{
|
||||
u_char ch, *p1, *p2;
|
||||
off_t byte, length, line;
|
||||
int dfound;
|
||||
size_t blk_sz, blk_cnt;
|
||||
|
||||
if (sflag && len1 != len2)
|
||||
exit(1);
|
||||
|
||||
if (skip1 > len1)
|
||||
eofmsg(file1, len1 + 1, 0);
|
||||
len1 -= skip1;
|
||||
if (skip2 > len2)
|
||||
eofmsg(file2, len2 + 1, 0);
|
||||
len2 -= skip2;
|
||||
|
||||
byte = line = 1;
|
||||
dfound = 0;
|
||||
length = MIN(len1, len2);
|
||||
for (blk_sz = 1024 * 1024; length != 0; length -= blk_sz) {
|
||||
if ((uintmax_t)blk_sz > (uintmax_t)length)
|
||||
blk_sz = length;
|
||||
p1 = mmap(NULL, blk_sz, PROT_READ, MAP_FILE|MAP_SHARED,
|
||||
fd1, skip1);
|
||||
if (p1 == MAP_FAILED)
|
||||
goto mmap_failed;
|
||||
|
||||
p2 = mmap(NULL, blk_sz, PROT_READ, MAP_FILE|MAP_SHARED,
|
||||
fd2, skip2);
|
||||
if (p2 == MAP_FAILED) {
|
||||
munmap(p1, blk_sz);
|
||||
goto mmap_failed;
|
||||
}
|
||||
|
||||
blk_cnt = blk_sz;
|
||||
for (; blk_cnt--; ++p1, ++p2, ++byte) {
|
||||
if ((ch = *p1) != *p2) {
|
||||
if (!lflag) {
|
||||
diffmsg(file1, file2, byte, line);
|
||||
/* NOTREACHED */
|
||||
}
|
||||
dfound = 1;
|
||||
(void)printf("%6lld %3o %3o\n",
|
||||
(long long)byte, ch, *p2);
|
||||
}
|
||||
if (ch == '\n')
|
||||
++line;
|
||||
}
|
||||
munmap(p1 - blk_sz, blk_sz);
|
||||
munmap(p2 - blk_sz, blk_sz);
|
||||
skip1 += blk_sz;
|
||||
skip2 += blk_sz;
|
||||
}
|
||||
|
||||
if (len1 != len2)
|
||||
eofmsg(len1 > len2 ? file2 : file1, byte, line);
|
||||
if (dfound)
|
||||
exit(DIFF_EXIT);
|
||||
return;
|
||||
|
||||
mmap_failed:
|
||||
c_special(fd1, file1, skip1, fd2, file2, skip2);
|
||||
}
|
||||
|
|
@ -1,111 +0,0 @@
|
|||
/* $NetBSD: special.c,v 1.14 2011/11/28 10:10:10 wiz Exp $ */
|
||||
|
||||
/*-
|
||||
* 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. 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.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)special.c 8.3 (Berkeley) 4/2/94";
|
||||
#else
|
||||
__RCSID("$NetBSD: special.c,v 1.14 2011/11/28 10:10:10 wiz Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <err.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "extern.h"
|
||||
|
||||
void
|
||||
c_special(int fd1, const char *file1, off_t skip1, int fd2, const char *file2, off_t skip2)
|
||||
{
|
||||
int ch1, ch2;
|
||||
off_t byte, line;
|
||||
FILE *fp1, *fp2;
|
||||
int dfound;
|
||||
|
||||
dfound = 0;
|
||||
if ((fp1 = fdopen(fd1, "r")) == NULL)
|
||||
err(ERR_EXIT, "%s", file1);
|
||||
if ((fp2 = fdopen(fd2, "r")) == NULL)
|
||||
err(ERR_EXIT, "%s", file2);
|
||||
|
||||
for (byte = line = 1; skip1--; byte++) {
|
||||
ch1 = getc(fp1);
|
||||
if (ch1 == EOF)
|
||||
goto eof;
|
||||
if (ch1 == '\n')
|
||||
line++;
|
||||
}
|
||||
for (byte = line = 1; skip2--; byte++) {
|
||||
ch2 = getc(fp2);
|
||||
if (ch2 == EOF)
|
||||
goto eof;
|
||||
if (ch2 == '\n')
|
||||
line++;
|
||||
}
|
||||
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("%6lld %3o %3o\n", (long long)byte,
|
||||
ch1, ch2);
|
||||
} else
|
||||
diffmsg(file1, file2, byte, line);
|
||||
/* NOTREACHED */
|
||||
}
|
||||
if (ch1 == '\n')
|
||||
++line;
|
||||
}
|
||||
|
||||
eof:
|
||||
if (ferror(fp1))
|
||||
errmsg(file1, byte, line);
|
||||
if (ferror(fp2))
|
||||
errmsg(file2, byte, line);
|
||||
if (feof(fp1)) {
|
||||
if (!feof(fp2))
|
||||
eofmsg(file1, byte, line);
|
||||
} else
|
||||
if (feof(fp2))
|
||||
eofmsg(file2, byte, line);
|
||||
(void)fclose(fp1);
|
||||
(void)fclose(fp2);
|
||||
if (dfound)
|
||||
exit(DIFF_EXIT);
|
||||
}
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
# $NetBSD: Makefile,v 1.5 2009/04/14 22:15:18 lukem Exp $
|
||||
# @(#)Makefile 8.1 (Berkeley) 6/6/93
|
||||
|
||||
PROG= col
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
|
|
@ -1,48 +0,0 @@
|
|||
# @(#)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.
|
||||
|
|
@ -1,138 +0,0 @@
|
|||
.\" $NetBSD: col.1,v 1.10 2012/03/22 07:58:18 wiz Exp $
|
||||
.\"
|
||||
.\" 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. 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 February 22, 1999
|
||||
.Dt COL 1
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm col
|
||||
.Nd filter reverse line feeds from input
|
||||
.Sh SYNOPSIS
|
||||
.Nm
|
||||
.Op Fl bfpx
|
||||
.Op Fl l Ar num
|
||||
.Sh DESCRIPTION
|
||||
.Nm
|
||||
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
|
||||
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 p
|
||||
Force unknown control sequences to be passed through unchanged.
|
||||
Normally,
|
||||
.Nm
|
||||
will filter out any control sequences from the input other than those
|
||||
recognized and interpreted by itself, which are listed below.
|
||||
.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
|
||||
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 alternative 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
|
||||
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
|
||||
will display a warning message.
|
||||
.Sh SEE ALSO
|
||||
.Xr expand 1 ,
|
||||
.Xr nroff 1 ,
|
||||
.Xr tbl 1
|
||||
.Sh STANDARDS
|
||||
The
|
||||
.Nm
|
||||
utility conforms to
|
||||
.St -xpg4.2 .
|
||||
The
|
||||
.Fl l
|
||||
option is an extension to the standard.
|
||||
.Sh HISTORY
|
||||
A
|
||||
.Nm
|
||||
command appeared in
|
||||
.At v6 .
|
||||
|
|
@ -1,542 +0,0 @@
|
|||
/* $NetBSD: col.c,v 1.18 2014/10/18 14:56:14 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* 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. 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.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
__COPYRIGHT("@(#) Copyright (c) 1990, 1993, 1994\
|
||||
The Regents of the University of California. All rights reserved.");
|
||||
#endif /* not lint */
|
||||
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)col.c 8.5 (Berkeley) 5/4/95";
|
||||
#endif
|
||||
__RCSID("$NetBSD: col.c,v 1.18 2014/10/18 14:56:14 christos Exp $");
|
||||
#endif /* not lint */
|
||||
|
||||
#include <ctype.h>
|
||||
#include <err.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.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 */
|
||||
};
|
||||
|
||||
static LINE *alloc_line(void);
|
||||
static void dowarn(int);
|
||||
static void flush_line(LINE *);
|
||||
static void flush_lines(int);
|
||||
static void flush_blanks(void);
|
||||
static void free_line(LINE *);
|
||||
__dead static void usage(void);
|
||||
__dead static void wrerr(void);
|
||||
static void *xmalloc(void *, size_t);
|
||||
|
||||
static CSET last_set; /* char_set of last char printed */
|
||||
static LINE *lines;
|
||||
static int compress_spaces; /* if doing space -> tab conversion */
|
||||
static int fine; /* if `fine' resolution (half lines) */
|
||||
static int max_bufd_lines; /* max # lines to keep in memory */
|
||||
static int nblank_lines; /* # blanks after last flushed line */
|
||||
static int no_backspaces; /* if not to output any backspaces */
|
||||
static int pass_unknown_seqs; /* whether to pass unknown control sequences */
|
||||
|
||||
#define PUTC(ch) \
|
||||
if (putchar(ch) == EOF) \
|
||||
wrerr();
|
||||
|
||||
int
|
||||
main(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 */
|
||||
pass_unknown_seqs = 0; /* remove unknown escape sequences */
|
||||
while ((opt = getopt(argc, argv, "bfhl:px")) != -1)
|
||||
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(EXIT_FAILURE);
|
||||
}
|
||||
break;
|
||||
case 'p': /* pass unknown control sequences */
|
||||
pass_unknown_seqs = 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;
|
||||
}
|
||||
if (!pass_unknown_seqs)
|
||||
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++;
|
||||
}
|
||||
if (max_line == 0)
|
||||
exit(EXIT_SUCCESS); /* no lines, so just exit */
|
||||
|
||||
/* 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(EXIT_SUCCESS);
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
static void
|
||||
flush_lines(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.
|
||||
*/
|
||||
static void
|
||||
flush_blanks(void)
|
||||
{
|
||||
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('\011');
|
||||
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.
|
||||
*/
|
||||
static void
|
||||
flush_line(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);
|
||||
}
|
||||
(void)memset(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 = ((last_col % 8) + nspace) / 8;
|
||||
if (ntabs) {
|
||||
nspace -= (ntabs * 8) - (last_col % 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;
|
||||
|
||||
static LINE *
|
||||
alloc_line(void)
|
||||
{
|
||||
LINE *l;
|
||||
int i;
|
||||
|
||||
if (!line_freelist) {
|
||||
l = (LINE *)xmalloc(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;
|
||||
|
||||
(void)memset(l, 0, sizeof(LINE));
|
||||
return (l);
|
||||
}
|
||||
|
||||
static void
|
||||
free_line(LINE *l)
|
||||
{
|
||||
|
||||
l->l_next = line_freelist;
|
||||
line_freelist = l;
|
||||
}
|
||||
|
||||
static void *
|
||||
xmalloc(void *p, size_t size)
|
||||
{
|
||||
void *q;
|
||||
|
||||
if (!(q = (void *)realloc(p, size)))
|
||||
err(EXIT_FAILURE, "realloc");
|
||||
p = q;
|
||||
return (p);
|
||||
}
|
||||
|
||||
static void
|
||||
usage(void)
|
||||
{
|
||||
|
||||
(void)fprintf(stderr, "usage: col [-bfpx] [-l nline]\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
static void
|
||||
wrerr(void)
|
||||
{
|
||||
|
||||
(void)fprintf(stderr, "col: write error.\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
static void
|
||||
dowarn(int line)
|
||||
{
|
||||
|
||||
warnx("warning: can't back up %s",
|
||||
line < 0 ? "past first line" : "-- line already flushed");
|
||||
}
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
# $NetBSD: Makefile,v 1.5 2009/04/14 22:15:18 lukem Exp $
|
||||
# @(#)Makefile 8.1 (Berkeley) 6/6/93
|
||||
|
||||
PROG= colcrt
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
|
|
@ -1,106 +0,0 @@
|
|||
.\" $NetBSD: colcrt.1,v 1.9 2012/05/12 14:52:57 reed Exp $
|
||||
.\"
|
||||
.\" 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. 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.
|
||||
.\"
|
||||
.\" @(#)colcrt.1 8.1 (Berkeley) 6/30/93
|
||||
.\"
|
||||
.Dd June 30, 1993
|
||||
.Dt COLCRT 1
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm colcrt
|
||||
.Nd filter nroff output for CRT previewing
|
||||
.Sh SYNOPSIS
|
||||
.Nm
|
||||
.Op Fl
|
||||
.Op Fl \&2
|
||||
.Op Ar
|
||||
.Sh DESCRIPTION
|
||||
.Nm
|
||||
provides virtual half-line and reverse line feed sequences
|
||||
for terminals without such capability, and on which overstriking
|
||||
is destructive.
|
||||
Half-line characters and underlining (changed to dashing `\-')
|
||||
are placed on new lines in between the normal output lines.
|
||||
.Pp
|
||||
Available options:
|
||||
.Bl -tag -width Ds
|
||||
.It Fl
|
||||
Suppress all underlining.
|
||||
This option is especially useful for previewing
|
||||
.Em allboxed
|
||||
tables from
|
||||
.Xr tbl 1 .
|
||||
.It Fl 2
|
||||
Causes all half-lines to be printed, effectively double spacing the output.
|
||||
Normally, a minimal space output format is used which will suppress empty
|
||||
lines.
|
||||
The program never suppresses two consecutive empty lines, however.
|
||||
The
|
||||
.Fl 2
|
||||
option is useful for sending output to the line printer when the output
|
||||
contains superscripts and subscripts which would otherwise be invisible.
|
||||
.El
|
||||
.Sh EXAMPLES
|
||||
A typical use of
|
||||
.Nm
|
||||
would be
|
||||
.Bd -literal
|
||||
tbl exum2.n \&| nroff \-ms \&| colcrt \- \&| more
|
||||
.Ed
|
||||
.Sh SEE ALSO
|
||||
.Xr col 1 ,
|
||||
.Xr more 1 ,
|
||||
.Xr nroff 1 ,
|
||||
.Xr troff 1 ,
|
||||
.Xr ul 1
|
||||
.Sh HISTORY
|
||||
The
|
||||
.Nm
|
||||
command appeared in
|
||||
.Bx 1 .
|
||||
.Sh BUGS
|
||||
Should fold underlines onto blanks even with the
|
||||
.Ql Fl
|
||||
option so that
|
||||
a true underline character would show.
|
||||
.Pp
|
||||
Can't back up more than 102 lines.
|
||||
.Pp
|
||||
General overstriking is lost;
|
||||
as a special case
|
||||
.Ql \&|
|
||||
overstruck with
|
||||
.Ql \-
|
||||
or underline becomes
|
||||
.Ql \&+ .
|
||||
.Pp
|
||||
Lines are trimmed to 132 characters.
|
||||
.Pp
|
||||
Some provision should be made for processing superscripts and subscripts
|
||||
in documents which are already double-spaced.
|
||||
|
|
@ -1,260 +0,0 @@
|
|||
/* $NetBSD: colcrt.c,v 1.8 2008/07/21 14:19:21 lukem Exp $ */
|
||||
|
||||
/*
|
||||
* 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. 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.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
__COPYRIGHT("@(#) Copyright (c) 1980, 1993\
|
||||
The Regents of the University of California. All rights reserved.");
|
||||
#endif /* not lint */
|
||||
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)colcrt.c 8.1 (Berkeley) 6/6/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: colcrt.c,v 1.8 2008/07/21 14:19:21 lukem Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
/*
|
||||
* colcrt - replaces col for crts with new nroff esp. when using tbl.
|
||||
* Bill Joy UCB July 14, 1977
|
||||
*
|
||||
* This filter uses a screen buffer, 267 half-lines by 132 columns.
|
||||
* It interprets the up and down sequences generated by the new
|
||||
* nroff when used with tbl and by \u \d and \r.
|
||||
* General overstriking doesn't work correctly.
|
||||
* Underlining is split onto multiple lines, etc.
|
||||
*
|
||||
* Option - suppresses all underlining.
|
||||
* Option -2 forces printing of all half lines.
|
||||
*/
|
||||
|
||||
char page[267][132];
|
||||
|
||||
int outline = 1;
|
||||
int outcol;
|
||||
|
||||
char suppresul;
|
||||
char printall;
|
||||
|
||||
char *progname;
|
||||
FILE *f;
|
||||
|
||||
void move(int, int);
|
||||
void pflush(int);
|
||||
int plus(char, char);
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int c;
|
||||
char *cp, *dp;
|
||||
|
||||
argc--;
|
||||
progname = *argv++;
|
||||
while (argc > 0 && argv[0][0] == '-') {
|
||||
switch (argv[0][1]) {
|
||||
case 0:
|
||||
suppresul = 1;
|
||||
break;
|
||||
case '2':
|
||||
printall = 1;
|
||||
break;
|
||||
default:
|
||||
printf("usage: %s [ - ] [ -2 ] [ file ... ]\n", progname);
|
||||
fflush(stdout);
|
||||
exit(1);
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
do {
|
||||
if (argc > 0) {
|
||||
close(0);
|
||||
if (!(f = fopen(argv[0], "r"))) {
|
||||
fflush(stdout);
|
||||
perror(argv[0]);
|
||||
exit (1);
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
for (;;) {
|
||||
c = getc(stdin);
|
||||
if (c == -1) {
|
||||
pflush(outline);
|
||||
fflush(stdout);
|
||||
break;
|
||||
}
|
||||
switch (c) {
|
||||
case '\n':
|
||||
if (outline >= 265)
|
||||
pflush(62);
|
||||
outline += 2;
|
||||
outcol = 0;
|
||||
continue;
|
||||
case '\016':
|
||||
case '\017':
|
||||
continue;
|
||||
case 033:
|
||||
c = getc(stdin);
|
||||
switch (c) {
|
||||
case '9':
|
||||
if (outline >= 266)
|
||||
pflush(62);
|
||||
outline++;
|
||||
continue;
|
||||
case '8':
|
||||
if (outline >= 1)
|
||||
outline--;
|
||||
continue;
|
||||
case '7':
|
||||
outline -= 2;
|
||||
if (outline < 0)
|
||||
outline = 0;
|
||||
continue;
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
case '\b':
|
||||
if (outcol)
|
||||
outcol--;
|
||||
continue;
|
||||
case '\t':
|
||||
outcol += 8;
|
||||
outcol &= ~7;
|
||||
outcol--;
|
||||
c = ' ';
|
||||
default:
|
||||
if (outcol >= 132) {
|
||||
outcol++;
|
||||
continue;
|
||||
}
|
||||
cp = &page[outline][outcol];
|
||||
outcol++;
|
||||
if (c == '_') {
|
||||
if (suppresul)
|
||||
continue;
|
||||
cp += 132;
|
||||
c = '-';
|
||||
}
|
||||
if (*cp == 0) {
|
||||
*cp = c;
|
||||
dp = cp - outcol;
|
||||
for (cp--; cp >= dp && *cp == 0; cp--)
|
||||
*cp = ' ';
|
||||
} else
|
||||
if (plus(c, *cp) || plus(*cp, c))
|
||||
*cp = '+';
|
||||
else if (*cp == ' ' || *cp == 0)
|
||||
*cp = c;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
} while (argc > 0);
|
||||
fflush(stdout);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
int
|
||||
plus(char c, char d)
|
||||
{
|
||||
|
||||
return ((c == '|' && d == '-') || d == '_');
|
||||
}
|
||||
|
||||
int first;
|
||||
|
||||
void
|
||||
pflush(int ol)
|
||||
{
|
||||
int i;
|
||||
char *cp;
|
||||
char lastomit;
|
||||
int l;
|
||||
|
||||
l = ol;
|
||||
lastomit = 0;
|
||||
if (l > 266)
|
||||
l = 266;
|
||||
else
|
||||
l |= 1;
|
||||
for (i = first | 1; i < l; i++) {
|
||||
move(i, i - 1);
|
||||
move(i, i + 1);
|
||||
}
|
||||
for (i = first; i < l; i++) {
|
||||
cp = page[i];
|
||||
if (printall == 0 && lastomit == 0 && *cp == 0) {
|
||||
lastomit = 1;
|
||||
continue;
|
||||
}
|
||||
lastomit = 0;
|
||||
printf("%s\n", cp);
|
||||
}
|
||||
memmove(page, page[ol], (267 - ol) * 132);
|
||||
memset(page[267- ol], 0, ol * 132);
|
||||
outline -= ol;
|
||||
outcol = 0;
|
||||
first = 1;
|
||||
}
|
||||
|
||||
void
|
||||
move(int l, int m)
|
||||
{
|
||||
char *cp, *dp;
|
||||
|
||||
for (cp = page[l], dp = page[m]; *cp; cp++, dp++) {
|
||||
switch (*cp) {
|
||||
case '|':
|
||||
if (*dp != ' ' && *dp != '|' && *dp != 0)
|
||||
return;
|
||||
break;
|
||||
case ' ':
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (*cp == 0) {
|
||||
for (cp = page[l], dp = page[m]; *cp; cp++, dp++)
|
||||
if (*cp == '|')
|
||||
*dp = '|';
|
||||
else if (*dp == 0)
|
||||
*dp = ' ';
|
||||
page[l][0] = 0;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
# $NetBSD: Makefile,v 1.5 2009/04/14 22:15:18 lukem Exp $
|
||||
# @(#)Makefile 8.1 (Berkeley) 6/6/93
|
||||
|
||||
PROG= colrm
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
|
|
@ -1,78 +0,0 @@
|
|||
.\" $NetBSD: colrm.1,v 1.8 2012/05/12 14:52:57 reed Exp $
|
||||
.\"
|
||||
.\" 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. 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.
|
||||
.\"
|
||||
.\" @(#)colrm.1 8.1 (Berkeley) 6/6/93
|
||||
.\"
|
||||
.Dd June 6, 1993
|
||||
.Dt COLRM 1
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm colrm
|
||||
.Nd remove columns from a file
|
||||
.Sh SYNOPSIS
|
||||
.Nm
|
||||
.Op Ar start Op Ar stop
|
||||
.Sh DESCRIPTION
|
||||
.Nm
|
||||
removes selected columns from the lines of a file.
|
||||
A column is defined as a single character in a line.
|
||||
Input is read from the standard input.
|
||||
Output is written to the standard output.
|
||||
.Pp
|
||||
If only the
|
||||
.Ar start
|
||||
column is specified, columns numbered less than the
|
||||
.Ar start
|
||||
column will be written.
|
||||
If both
|
||||
.Ar start
|
||||
and
|
||||
.Ar stop
|
||||
columns are specified, columns numbered less than the
|
||||
.Ar start
|
||||
column
|
||||
or greater than the
|
||||
.Ar stop
|
||||
column will be written.
|
||||
Column numbering starts with one, not zero.
|
||||
.Pp
|
||||
Tab characters increment the column count to the next multiple of eight.
|
||||
Backspace characters decrement the column count by one.
|
||||
.Sh SEE ALSO
|
||||
.Xr awk 1 ,
|
||||
.Xr column 1 ,
|
||||
.Xr cut 1 ,
|
||||
.Xr paste 1
|
||||
.Sh HISTORY
|
||||
The
|
||||
.Nm
|
||||
command appeared in
|
||||
.Bx 1 .
|
||||
It was completely rewritten for
|
||||
.Bx 4.4 .
|
||||
|
|
@ -1,137 +0,0 @@
|
|||
/* $NetBSD: colrm.c,v 1.9 2011/08/30 21:35:09 joerg Exp $ */
|
||||
|
||||
/*-
|
||||
* 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. 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.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
__COPYRIGHT("@(#) Copyright (c) 1991, 1993\
|
||||
The Regents of the University of California. All rights reserved.");
|
||||
#endif /* not lint */
|
||||
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)colrm.c 8.2 (Berkeley) 5/4/95";
|
||||
#endif
|
||||
__RCSID("$NetBSD: colrm.c,v 1.9 2011/08/30 21:35:09 joerg Exp $");
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define TAB 8
|
||||
|
||||
static void check(FILE *);
|
||||
__dead static void usage(void);
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
u_long column, start, stop;
|
||||
int ch;
|
||||
char *p;
|
||||
|
||||
while ((ch = getopt(argc, argv, "")) != -1)
|
||||
switch(ch) {
|
||||
case '?':
|
||||
default:
|
||||
usage();
|
||||
}
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
start = stop = 0;
|
||||
switch(argc) {
|
||||
case 2:
|
||||
stop = strtol(argv[1], &p, 10);
|
||||
if (stop <= 0 || *p)
|
||||
errx(1, "illegal column -- %s", argv[1]);
|
||||
/* FALLTHROUGH */
|
||||
case 1:
|
||||
start = strtol(argv[0], &p, 10);
|
||||
if (start <= 0 || *p)
|
||||
errx(1, "illegal column -- %s", argv[0]);
|
||||
break;
|
||||
case 0:
|
||||
break;
|
||||
default:
|
||||
usage();
|
||||
}
|
||||
|
||||
if (stop && start > stop)
|
||||
err(1, "illegal start and stop columns");
|
||||
|
||||
for (column = 0;;) {
|
||||
switch (ch = getchar()) {
|
||||
case EOF:
|
||||
check(stdin);
|
||||
break;
|
||||
case '\b':
|
||||
if (column)
|
||||
--column;
|
||||
break;
|
||||
case '\n':
|
||||
column = 0;
|
||||
break;
|
||||
case '\t':
|
||||
column = (column + TAB) & ~(TAB - 1);
|
||||
break;
|
||||
default:
|
||||
++column;
|
||||
break;
|
||||
}
|
||||
|
||||
if ((!start || column < start || (stop && column > stop)) &&
|
||||
putchar(ch) == EOF)
|
||||
check(stdout);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
check(FILE *stream)
|
||||
{
|
||||
if (feof(stream))
|
||||
exit(0);
|
||||
if (ferror(stream))
|
||||
err(1, "%s", stream == stdin ? "stdin" : "stdout");
|
||||
}
|
||||
|
||||
static void
|
||||
usage(void)
|
||||
{
|
||||
(void)fprintf(stderr, "usage: colrm [start [stop]]\n");
|
||||
exit(1);
|
||||
}
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
# $NetBSD: Makefile,v 1.7 2009/04/14 22:15:18 lukem Exp $
|
||||
# @(#)Makefile 8.1 (Berkeley) 6/6/93
|
||||
|
||||
PROG= column
|
||||
|
||||
LDADD+=-lutil
|
||||
DPADD+=${LIBUTIL}
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
|
|
@ -1,97 +0,0 @@
|
|||
.\" $NetBSD: column.1,v 1.9 2009/03/09 19:24:32 joerg Exp $
|
||||
.\"
|
||||
.\" 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. 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.
|
||||
.\"
|
||||
.\" @(#)column.1 8.1 (Berkeley) 6/6/93
|
||||
.\"
|
||||
.Dd March 9, 2008
|
||||
.Dt COLUMN 1
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm column
|
||||
.Nd columnate lists
|
||||
.Sh SYNOPSIS
|
||||
.Nm
|
||||
.Op Fl tx
|
||||
.Op Fl c Ar columns
|
||||
.Op Fl s Ar sep
|
||||
.Op Ar
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Nm
|
||||
utility formats its input into multiple columns.
|
||||
Rows are filled before columns.
|
||||
Input is taken from
|
||||
.Ar file
|
||||
operands, or, by default, from the standard input.
|
||||
Empty lines are ignored.
|
||||
.Pp
|
||||
The options are as follows:
|
||||
.Bl -tag -width Ds
|
||||
.It Fl c
|
||||
Output is formatted for a display
|
||||
.Ar columns
|
||||
wide.
|
||||
.It Fl s
|
||||
Specify a set of characters to be used to delimit columns for the
|
||||
.Fl t
|
||||
option.
|
||||
.It Fl t
|
||||
Determine the number of columns the input contains and create a table.
|
||||
Columns are delimited with whitespace, by default, or with the characters
|
||||
supplied using the
|
||||
.Fl s
|
||||
option.
|
||||
Useful for pretty-printing displays.
|
||||
.It Fl x
|
||||
Fill columns before filling rows.
|
||||
.El
|
||||
.Pp
|
||||
.Nm
|
||||
exits 0 on success, \*[Gt]0 if an error occurred.
|
||||
.Sh ENVIRONMENT
|
||||
.Bl -tag -width COLUMNS
|
||||
.It Ev COLUMNS
|
||||
The environment variable
|
||||
.Ev COLUMNS
|
||||
is used to determine the size of
|
||||
the screen if no other information is available.
|
||||
.El
|
||||
.Sh EXAMPLES
|
||||
.Dl (echo \&"PERM LINKS OWNER GROUP SIZE MONTH DAY HH:MM/YEAR NAME\&"\&;\ \&\e
|
||||
.Dl ls -l \&| sed 1d) \&| column -t
|
||||
.Sh SEE ALSO
|
||||
.Xr colrm 1 ,
|
||||
.Xr ls 1 ,
|
||||
.Xr paste 1 ,
|
||||
.Xr sort 1
|
||||
.Sh HISTORY
|
||||
The
|
||||
.Nm
|
||||
command appeared in
|
||||
.Bx 4.3 Reno .
|
||||
|
|
@ -1,307 +0,0 @@
|
|||
/* $NetBSD: column.c,v 1.21 2008/07/21 14:19:21 lukem Exp $ */
|
||||
|
||||
/*
|
||||
* 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. 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.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
__COPYRIGHT("@(#) Copyright (c) 1989, 1993, 1994\
|
||||
The Regents of the University of California. All rights reserved.");
|
||||
#endif /* not lint */
|
||||
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)column.c 8.4 (Berkeley) 5/4/95";
|
||||
#endif
|
||||
__RCSID("$NetBSD: column.c,v 1.21 2008/07/21 14:19:21 lukem Exp $");
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <err.h>
|
||||
#include <termios.h>
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <util.h>
|
||||
|
||||
#define TAB 8
|
||||
#define TABROUND(l) (((l) + TAB) & ~(TAB - 1))
|
||||
|
||||
static void c_columnate(void);
|
||||
static void input(FILE *);
|
||||
static void maketbl(void);
|
||||
static void print(void);
|
||||
static void r_columnate(void);
|
||||
static void usage(void) __dead;
|
||||
|
||||
static int termwidth = 80; /* default terminal width */
|
||||
|
||||
static int entries; /* number of records */
|
||||
static int eval; /* exit value */
|
||||
static int maxlength; /* longest record */
|
||||
static char **list; /* array of pointers to records */
|
||||
static const char *separator = "\t "; /* field separator for table option */
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
struct winsize win;
|
||||
FILE *fp;
|
||||
int ch, tflag, xflag;
|
||||
const char *p;
|
||||
|
||||
setprogname(*argv);
|
||||
|
||||
if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &win) == -1 || !win.ws_col) {
|
||||
if ((p = getenv("COLUMNS")) != NULL)
|
||||
termwidth = atoi(p);
|
||||
} else
|
||||
termwidth = win.ws_col;
|
||||
|
||||
tflag = xflag = 0;
|
||||
while ((ch = getopt(argc, argv, "c:s:tx")) != -1)
|
||||
switch(ch) {
|
||||
case 'c':
|
||||
termwidth = atoi(optarg);
|
||||
break;
|
||||
case 's':
|
||||
separator = optarg;
|
||||
break;
|
||||
case 't':
|
||||
tflag = 1;
|
||||
break;
|
||||
case 'x':
|
||||
xflag = 1;
|
||||
break;
|
||||
case '?':
|
||||
default:
|
||||
usage();
|
||||
}
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
if (!*argv)
|
||||
input(stdin);
|
||||
else for (; *argv; ++argv)
|
||||
if ((fp = fopen(*argv, "r")) != NULL) {
|
||||
input(fp);
|
||||
(void)fclose(fp);
|
||||
} else {
|
||||
warn("Cannot open `%s'", *argv);
|
||||
eval = 1;
|
||||
}
|
||||
|
||||
if (!entries)
|
||||
return eval;
|
||||
|
||||
maxlength = TABROUND(maxlength);
|
||||
if (tflag)
|
||||
maketbl();
|
||||
else if (maxlength >= termwidth)
|
||||
print();
|
||||
else if (xflag)
|
||||
c_columnate();
|
||||
else
|
||||
r_columnate();
|
||||
return eval;
|
||||
}
|
||||
|
||||
static void
|
||||
c_columnate(void)
|
||||
{
|
||||
int chcnt, col, cnt, endcol, numcols;
|
||||
char **lp;
|
||||
|
||||
numcols = termwidth / maxlength;
|
||||
endcol = maxlength;
|
||||
for (chcnt = col = 0, lp = list;; ++lp) {
|
||||
chcnt += printf("%s", *lp);
|
||||
if (!--entries)
|
||||
break;
|
||||
if (++col == numcols) {
|
||||
chcnt = col = 0;
|
||||
endcol = maxlength;
|
||||
(void)putchar('\n');
|
||||
} else {
|
||||
while ((cnt = TABROUND(chcnt)) <= endcol) {
|
||||
(void)putchar('\t');
|
||||
chcnt = cnt;
|
||||
}
|
||||
endcol += maxlength;
|
||||
}
|
||||
}
|
||||
if (chcnt)
|
||||
(void)putchar('\n');
|
||||
}
|
||||
|
||||
static void
|
||||
r_columnate(void)
|
||||
{
|
||||
int base, chcnt, cnt, col, endcol, numcols, numrows, row;
|
||||
|
||||
numcols = termwidth / maxlength;
|
||||
numrows = entries / numcols;
|
||||
if (entries % numcols)
|
||||
++numrows;
|
||||
|
||||
for (row = 0; row < numrows; ++row) {
|
||||
endcol = maxlength;
|
||||
for (base = row, chcnt = col = 0; col < numcols; ++col) {
|
||||
chcnt += printf("%s", list[base]);
|
||||
if ((base += numrows) >= entries)
|
||||
break;
|
||||
while ((cnt = TABROUND(chcnt)) <= endcol) {
|
||||
(void)putchar('\t');
|
||||
chcnt = cnt;
|
||||
}
|
||||
endcol += maxlength;
|
||||
}
|
||||
(void)putchar('\n');
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
print(void)
|
||||
{
|
||||
int cnt;
|
||||
char **lp;
|
||||
|
||||
for (cnt = entries, lp = list; cnt--; ++lp)
|
||||
(void)printf("%s\n", *lp);
|
||||
}
|
||||
|
||||
typedef struct _tbl {
|
||||
char **list;
|
||||
int cols, *len;
|
||||
} TBL;
|
||||
#define DEFCOLS 25
|
||||
|
||||
static void
|
||||
maketbl(void)
|
||||
{
|
||||
TBL *t;
|
||||
int coloff, cnt;
|
||||
char *p, **lp;
|
||||
int *lens, *nlens, maxcols;
|
||||
TBL *tbl;
|
||||
char **cols, **ncols;
|
||||
|
||||
t = tbl = ecalloc(entries, sizeof(*t));
|
||||
cols = ecalloc((maxcols = DEFCOLS), sizeof(*cols));
|
||||
lens = ecalloc(maxcols, sizeof(*lens));
|
||||
for (cnt = 0, lp = list; cnt < entries; ++cnt, ++lp, ++t) {
|
||||
for (coloff = 0, p = *lp;
|
||||
(cols[coloff] = strtok(p, separator)) != NULL; p = NULL)
|
||||
if (++coloff == maxcols) {
|
||||
ncols = erealloc(cols, (maxcols +
|
||||
DEFCOLS) * sizeof(*ncols));
|
||||
nlens = erealloc(lens, (maxcols +
|
||||
DEFCOLS) * sizeof(*nlens));
|
||||
cols = ncols;
|
||||
lens = nlens;
|
||||
(void)memset(cols + maxcols, 0,
|
||||
DEFCOLS * sizeof(*cols));
|
||||
(void)memset(lens + maxcols, 0,
|
||||
DEFCOLS * sizeof(*lens));
|
||||
maxcols += DEFCOLS;
|
||||
}
|
||||
t->list = ecalloc(coloff, sizeof(*(t->list)));
|
||||
t->len = ecalloc(coloff, sizeof(*(t->len)));
|
||||
for (t->cols = coloff; --coloff >= 0;) {
|
||||
t->list[coloff] = cols[coloff];
|
||||
t->len[coloff] = strlen(cols[coloff]);
|
||||
if (t->len[coloff] > lens[coloff])
|
||||
lens[coloff] = t->len[coloff];
|
||||
}
|
||||
}
|
||||
for (cnt = 0, t = tbl; cnt < entries; ++cnt, ++t) {
|
||||
for (coloff = 0; coloff < t->cols - 1; ++coloff)
|
||||
(void)printf("%s%*s", t->list[coloff],
|
||||
lens[coloff] - t->len[coloff] + 2, " ");
|
||||
(void)printf("%s\n", t->list[coloff]);
|
||||
}
|
||||
free(tbl);
|
||||
free(cols);
|
||||
free(lens);
|
||||
}
|
||||
|
||||
#define DEFNUM 1000
|
||||
|
||||
static void
|
||||
input(FILE *fp)
|
||||
{
|
||||
static int maxentry;
|
||||
int len;
|
||||
size_t blen;
|
||||
char *p, *buf;
|
||||
char **n;
|
||||
|
||||
if (!list)
|
||||
list = ecalloc((maxentry = DEFNUM), sizeof(*list));
|
||||
while ((buf = fgetln(fp, &blen)) != NULL) {
|
||||
buf = estrndup(buf, blen);
|
||||
for (p = buf; *p && isspace((unsigned char)*p); ++p);
|
||||
if (!*p) {
|
||||
free(buf);
|
||||
continue;
|
||||
}
|
||||
if (!(p = strchr(p, '\n'))) {
|
||||
warnx("line too long");
|
||||
eval = 1;
|
||||
free(buf);
|
||||
continue;
|
||||
}
|
||||
*p = '\0';
|
||||
len = p - buf;
|
||||
if (maxlength < len)
|
||||
maxlength = len;
|
||||
if (entries == maxentry) {
|
||||
n = erealloc(list, (maxentry + DEFNUM) * sizeof(*n));
|
||||
(void)memset(n + maxentry, 0, sizeof(*n) * DEFNUM);
|
||||
maxentry += DEFNUM;
|
||||
list = n;
|
||||
}
|
||||
list[entries++] = buf;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
usage(void)
|
||||
{
|
||||
|
||||
(void)fprintf(stderr,
|
||||
"Usage: %s [-tx] [-c columns] [-s sep] [file ...]\n",
|
||||
getprogname());
|
||||
exit(1);
|
||||
}
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
# $NetBSD: Makefile,v 1.3 1995/03/26 09:25:49 glass Exp $
|
||||
# @(#)Makefile 8.1 (Berkeley) 6/6/93
|
||||
|
||||
PROG= comm
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
|
|
@ -1,102 +0,0 @@
|
|||
.\" $NetBSD: comm.1,v 1.12 2014/04/13 01:45:34 snj Exp $
|
||||
.\"
|
||||
.\" 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
|
||||
.\" 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. 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.
|
||||
.\"
|
||||
.\" @(#)comm.1 8.1 (Berkeley) 6/6/93
|
||||
.\"
|
||||
.Dd June 6, 1993
|
||||
.Dt COMM 1
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm comm
|
||||
.Nd select or reject lines common to two files
|
||||
.Sh SYNOPSIS
|
||||
.Nm
|
||||
.Op Fl 123f
|
||||
.Ar file1 file2
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Nm
|
||||
utility reads
|
||||
.Ar file1
|
||||
and
|
||||
.Ar file2 ,
|
||||
which should be
|
||||
sorted lexically, and produces three text
|
||||
columns as output: lines only in
|
||||
.Ar file1 ;
|
||||
lines only in
|
||||
.Ar file2 ;
|
||||
and lines in both files.
|
||||
.Pp
|
||||
The filename ``-'' means the standard input.
|
||||
.Pp
|
||||
The following options are available:
|
||||
.Bl -tag -width Ds
|
||||
.It Fl 1
|
||||
Suppress printing of column 1.
|
||||
.It Fl 2
|
||||
Suppress printing of column 2.
|
||||
.It Fl 3
|
||||
Suppress printing of column 3.
|
||||
.It Fl f
|
||||
Fold case in line comparisons.
|
||||
.El
|
||||
.Pp
|
||||
Each column will have a number of tab characters prepended to it
|
||||
equal to the number of lower numbered columns that are being printed.
|
||||
For example, if column number two is being suppressed, lines printed
|
||||
in column number one will not have any tabs preceding them, and lines
|
||||
printed in column number three will have one.
|
||||
.Pp
|
||||
.Nm
|
||||
assumes that the files are lexically sorted; all characters
|
||||
participate in line comparisons.
|
||||
.\" .Sh ENVIRONMENT
|
||||
.\" .Bl -tag -width indent
|
||||
.\" .It Ev LANG
|
||||
.\" .It Ev LC_ALL
|
||||
.\" .It Ev LC_CTYPE
|
||||
.\" .It Ev LC_COLLATE
|
||||
.\" .It Ev LC_MESSAGES
|
||||
.\" .El
|
||||
.Sh EXIT STATUS
|
||||
.Ex -std
|
||||
.Sh SEE ALSO
|
||||
.Xr cmp 1 ,
|
||||
.Xr diff 1 ,
|
||||
.Xr sort 1 ,
|
||||
.Xr uniq 1
|
||||
.Sh STANDARDS
|
||||
The
|
||||
.Nm
|
||||
utility conforms to
|
||||
.St -p1003.2-92 .
|
||||
|
|
@ -1,213 +0,0 @@
|
|||
/* $NetBSD: comm.c,v 1.20 2012/09/05 04:01:23 simonb Exp $ */
|
||||
|
||||
/*
|
||||
* 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
|
||||
* Case Larsen.
|
||||
*
|
||||
* 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. 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.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
__COPYRIGHT("@(#) Copyright (c) 1989, 1993, 1994\
|
||||
The Regents of the University of California. All rights reserved.");
|
||||
#endif /* not lint */
|
||||
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)comm.c 8.4 (Berkeley) 5/4/95";
|
||||
#endif
|
||||
__RCSID("$NetBSD: comm.c,v 1.20 2012/09/05 04:01:23 simonb Exp $");
|
||||
#endif /* not lint */
|
||||
|
||||
#include <err.h>
|
||||
#include <limits.h>
|
||||
#include <locale.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define MAXLINELEN (LINE_MAX + 1)
|
||||
|
||||
static const char *tabs[] = { "", "\t", "\t\t" };
|
||||
|
||||
static FILE *file(const char *);
|
||||
static void show(FILE *, const char *, char *);
|
||||
__dead static void usage(void);
|
||||
static char *getnextln(char *buf, FILE *);
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
int comp, file1done, file2done, read1, read2;
|
||||
int ch, flag1, flag2, flag3;
|
||||
FILE *fp1, *fp2;
|
||||
const char *col1, *col2, *col3, **p;
|
||||
char line1[MAXLINELEN], line2[MAXLINELEN];
|
||||
int (*compare)(const char*,const char*);
|
||||
|
||||
(void)setlocale(LC_ALL, "");
|
||||
|
||||
file1done = file2done = 0;
|
||||
flag1 = flag2 = flag3 = 1;
|
||||
compare = strcoll;
|
||||
while ((ch = getopt(argc, argv, "123f")) != -1)
|
||||
switch(ch) {
|
||||
case '1':
|
||||
flag1 = 0;
|
||||
break;
|
||||
case '2':
|
||||
flag2 = 0;
|
||||
break;
|
||||
case '3':
|
||||
flag3 = 0;
|
||||
break;
|
||||
case 'f':
|
||||
compare = strcasecmp;
|
||||
break;
|
||||
case '?':
|
||||
default:
|
||||
usage();
|
||||
}
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
if (argc != 2)
|
||||
usage();
|
||||
|
||||
fp1 = file(argv[0]);
|
||||
fp2 = file(argv[1]);
|
||||
|
||||
/* for each column printed, add another tab offset */
|
||||
p = tabs;
|
||||
col1 = col2 = col3 = NULL;
|
||||
if (flag1)
|
||||
col1 = *p++;
|
||||
if (flag2)
|
||||
col2 = *p++;
|
||||
if (flag3)
|
||||
col3 = *p;
|
||||
|
||||
for (read1 = read2 = 1;;) {
|
||||
/* read next line, check for EOF */
|
||||
if (read1)
|
||||
file1done = !getnextln(line1, fp1);
|
||||
if (read2)
|
||||
file2done = !getnextln(line2, fp2);
|
||||
|
||||
/* if one file done, display the rest of the other file */
|
||||
if (file1done) {
|
||||
if (!file2done && col2)
|
||||
show(fp2, col2, line2);
|
||||
break;
|
||||
}
|
||||
if (file2done) {
|
||||
if (!file1done && col1)
|
||||
show(fp1, col1, line1);
|
||||
break;
|
||||
}
|
||||
|
||||
/* lines are the same */
|
||||
if (!(comp = compare(line1, line2))) {
|
||||
read1 = read2 = 1;
|
||||
if (col3)
|
||||
if (printf("%s%s\n", col3, line1) < 0)
|
||||
break;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* lines are different */
|
||||
if (comp < 0) {
|
||||
read1 = 1;
|
||||
read2 = 0;
|
||||
if (col1)
|
||||
if (printf("%s%s\n", col1, line1) < 0)
|
||||
break;
|
||||
} else {
|
||||
read1 = 0;
|
||||
read2 = 1;
|
||||
if (col2)
|
||||
if (printf("%s%s\n", col2, line2) < 0)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (ferror (stdout) || fclose (stdout) == EOF)
|
||||
err(1, "stdout");
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
||||
static void
|
||||
show(FILE *fp, const char *offset, char *buf)
|
||||
{
|
||||
while (printf("%s%s\n", offset, buf) >= 0 && getnextln(buf, fp))
|
||||
;
|
||||
}
|
||||
|
||||
static FILE *
|
||||
file(const char *name)
|
||||
{
|
||||
FILE *fp;
|
||||
|
||||
if (!strcmp(name, "-"))
|
||||
return (stdin);
|
||||
if ((fp = fopen(name, "r")) == NULL)
|
||||
err(1, "%s", name);
|
||||
return (fp);
|
||||
}
|
||||
|
||||
static void
|
||||
usage(void)
|
||||
{
|
||||
|
||||
(void)fprintf(stderr, "usage: comm [-123f] file1 file2\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
static char *
|
||||
getnextln(char *buf, FILE *fp)
|
||||
{
|
||||
size_t i = 0;
|
||||
int c;
|
||||
|
||||
while ((c = getc(fp)) != '\n' && c != EOF) {
|
||||
buf[i++] = c;
|
||||
|
||||
if (i >= MAXLINELEN)
|
||||
i--; /* consumes extra characters till newline */
|
||||
}
|
||||
|
||||
if (c == EOF && !i)
|
||||
return NULL;
|
||||
|
||||
buf[i] = 0;
|
||||
return buf;
|
||||
}
|
||||
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
# $NetBSD: Makefile,v 1.3 2009/04/14 22:15:19 lukem Exp $
|
||||
|
||||
PROG= csplit
|
||||
|
||||
DPADD+= ${LIBUTIL}
|
||||
LDADD+= -lutil
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
|
|
@ -1,163 +0,0 @@
|
|||
.\" $NetBSD: csplit.1,v 1.5 2014/02/04 19:48:48 wiz Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 2002 Tim J. Robbins.
|
||||
.\" 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.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
|
||||
.\"
|
||||
.\" $FreeBSD: src/usr.bin/csplit/csplit.1,v 1.11 2005/01/25 22:29:51 tjr Exp $
|
||||
.\"
|
||||
.Dd February 4, 2014
|
||||
.Dt CSPLIT 1
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm csplit
|
||||
.Nd split files based on context
|
||||
.Sh SYNOPSIS
|
||||
.Nm
|
||||
.Op Fl ks
|
||||
.Op Fl f Ar prefix
|
||||
.Op Fl n Ar number
|
||||
.Ar file args ...
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Nm
|
||||
utility splits
|
||||
.Ar file
|
||||
into pieces using the patterns
|
||||
.Ar args .
|
||||
If
|
||||
.Ar file
|
||||
is
|
||||
a dash
|
||||
.Pq Sq - ,
|
||||
.Nm
|
||||
reads from standard input.
|
||||
.Pp
|
||||
Files are created with a prefix of
|
||||
.Dq xx
|
||||
and two decimal digits.
|
||||
The size of each file is written to standard output
|
||||
as it is created.
|
||||
If an error occurs whilst files are being created,
|
||||
or a
|
||||
.Dv HUP ,
|
||||
.Dv INT ,
|
||||
or
|
||||
.Dv TERM
|
||||
signal is received,
|
||||
all files previously written are removed.
|
||||
.Pp
|
||||
The options are as follows:
|
||||
.Bl -tag -offset indent -width 10n
|
||||
.It Fl f Ar prefix
|
||||
Create file names beginning with
|
||||
.Ar prefix ,
|
||||
instead of
|
||||
.Dq xx .
|
||||
.It Fl k
|
||||
Do not remove previously created files if an error occurs or a
|
||||
.Dv HUP ,
|
||||
.Dv INT ,
|
||||
or
|
||||
.Dv TERM
|
||||
signal is received.
|
||||
.It Fl n Ar number
|
||||
Create file names beginning with
|
||||
.Ar number
|
||||
of decimal digits after the prefix,
|
||||
instead of 2.
|
||||
.It Fl s
|
||||
Do not write the size of each output file to standard output as it is
|
||||
created.
|
||||
.El
|
||||
.Pp
|
||||
The
|
||||
.Ar args
|
||||
operands may be a combination of the following patterns:
|
||||
.Bl -tag -offset indent -width 10n
|
||||
.It / Ns Ar regexp Ns / Ns Oo Oo Cm + Ns | Ns Cm - Oc Ns Ar offset Oc
|
||||
Create a file containing the input from the current line to (but not including)
|
||||
the next line matching the given basic regular expression.
|
||||
An optional
|
||||
.Ar offset
|
||||
from the line that matched may be specified.
|
||||
.It % Ns Ar regexp Ns % Ns Oo Oo Cm + Ns | Ns Cm - Oc Ns Ar offset Oc
|
||||
Same as above but a file is not created for the output.
|
||||
.It Ar line_no
|
||||
Create containing the input from the current line to (but not including)
|
||||
the specified line number.
|
||||
.It Brq Ar num
|
||||
Repeat the previous pattern the specified number of times.
|
||||
If it follows a line number pattern, a new file will be created for each
|
||||
.Ar line_no
|
||||
lines,
|
||||
.Ar num
|
||||
times.
|
||||
The first line of the file is line number 1 for historic reasons.
|
||||
.El
|
||||
.Pp
|
||||
After all the patterns have been processed, the remaining input data
|
||||
(if there is any) will be written to a new file.
|
||||
.Pp
|
||||
Requesting to split at a line before the current line number or past the
|
||||
end of the file will result in an error.
|
||||
.Sh ENVIRONMENT
|
||||
The
|
||||
.Ev LANG , LC_ALL , LC_COLLATE ,
|
||||
and
|
||||
.Ev LC_CTYPE
|
||||
environment variables affect the execution of
|
||||
.Nm
|
||||
as described in
|
||||
.Xr environ 7 .
|
||||
.Sh EXIT STATUS
|
||||
.Ex -std
|
||||
.Sh EXAMPLES
|
||||
Split the
|
||||
.Xr mdoc 7
|
||||
file
|
||||
.Pa foo.1
|
||||
into one file for each section (up to 21 plus one for the rest, if any):
|
||||
.Pp
|
||||
.Dl "$ csplit -k foo.1 '%^\e.Sh%' '/^\e.Sh/' '{20}'"
|
||||
.Pp
|
||||
Split standard input after the first 99 lines and every 100 lines thereafter:
|
||||
.Pp
|
||||
.Dl "$ csplit -k - 100 '{19}'"
|
||||
.Sh SEE ALSO
|
||||
.Xr sed 1 ,
|
||||
.Xr split 1 ,
|
||||
.Xr re_format 7
|
||||
.Sh STANDARDS
|
||||
The
|
||||
.Nm
|
||||
utility conforms to
|
||||
.St -p1003.1-2004 .
|
||||
.Sh HISTORY
|
||||
A
|
||||
.Nm
|
||||
command appeared in PWB UNIX.
|
||||
.Sh BUGS
|
||||
Input lines are limited to
|
||||
.Dv LINE_MAX
|
||||
(2048) bytes in length.
|
||||
|
|
@ -1,479 +0,0 @@
|
|||
/* $NetBSD: csplit.c,v 1.6 2011/08/31 13:35:46 joerg Exp $ */
|
||||
/* $FreeBSD: src/usr.bin/csplit/csplit.c,v 1.9 2004/03/22 11:15:03 tjr Exp$ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2002 Tim J. Robbins.
|
||||
* 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.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* csplit -- split files based on context
|
||||
*
|
||||
* This utility splits its input into numbered output files by line number
|
||||
* or by a regular expression. Regular expression matches have an optional
|
||||
* offset with them, allowing the split to occur a specified number of
|
||||
* lines before or after the match.
|
||||
*
|
||||
* To handle negative offsets, we stop reading when the match occurs and
|
||||
* store the offset that the file should have been split at, then use
|
||||
* this output file as input until all the "overflowed" lines have been read.
|
||||
* The file is then closed and truncated to the correct length.
|
||||
*
|
||||
* We assume that the output files can be seeked upon (ie. they cannot be
|
||||
* symlinks to named pipes or character devices), but make no such
|
||||
* assumption about the input.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
__RCSID("$NetBSD: csplit.c,v 1.6 2011/08/31 13:35:46 joerg Exp $");
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <locale.h>
|
||||
#include <regex.h>
|
||||
#include <signal.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <util.h>
|
||||
|
||||
static void cleanup(void);
|
||||
static void do_lineno(const char *);
|
||||
static void do_rexp(const char *);
|
||||
static char *get_line(void);
|
||||
static void handlesig(int);
|
||||
static FILE *newfile(void);
|
||||
static void toomuch(FILE *, long);
|
||||
static void usage(void) __dead;
|
||||
|
||||
/*
|
||||
* Command line options
|
||||
*/
|
||||
static const char *prefix; /* File name prefix */
|
||||
static long sufflen; /* Number of decimal digits for suffix */
|
||||
static int sflag; /* Suppress output of file names */
|
||||
static int kflag; /* Keep output if error occurs */
|
||||
|
||||
/*
|
||||
* Other miscellaneous globals (XXX too many)
|
||||
*/
|
||||
static long lineno; /* Current line number in input file */
|
||||
static long reps; /* Number of repetitions for this pattern */
|
||||
static long nfiles; /* Number of files output so far */
|
||||
static long maxfiles; /* Maximum number of files we can create */
|
||||
static char currfile[PATH_MAX]; /* Current output file */
|
||||
static const char *infn; /* Name of the input file */
|
||||
static FILE *infile; /* Input file handle */
|
||||
static FILE *overfile; /* Overflow file for toomuch() */
|
||||
static off_t truncofs; /* Offset this file should be truncated at */
|
||||
static int doclean; /* Should cleanup() remove output? */
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
struct sigaction sa;
|
||||
long i;
|
||||
int ch;
|
||||
const char *expr;
|
||||
char *ep, *p;
|
||||
FILE *ofp;
|
||||
|
||||
(void)setlocale(LC_ALL, "");
|
||||
|
||||
kflag = sflag = 0;
|
||||
prefix = "xx";
|
||||
sufflen = 2;
|
||||
while ((ch = getopt(argc, argv, "ksf:n:")) > 0) {
|
||||
switch (ch) {
|
||||
case 'f':
|
||||
prefix = optarg;
|
||||
break;
|
||||
case 'k':
|
||||
kflag = 1;
|
||||
break;
|
||||
case 'n':
|
||||
errno = 0;
|
||||
sufflen = strtol(optarg, &ep, 10);
|
||||
if (sufflen <= 0 || *ep != '\0' || errno != 0)
|
||||
errx(1, "%s: bad suffix length", optarg);
|
||||
break;
|
||||
case 's':
|
||||
sflag = 1;
|
||||
break;
|
||||
default:
|
||||
usage();
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
}
|
||||
|
||||
if (sufflen + strlen(prefix) >= PATH_MAX)
|
||||
errx(1, "name too long");
|
||||
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
if ((infn = *argv++) == NULL)
|
||||
usage();
|
||||
if (strcmp(infn, "-") == 0) {
|
||||
infile = stdin;
|
||||
infn = "stdin";
|
||||
} else if ((infile = fopen(infn, "r")) == NULL)
|
||||
err(1, "%s", infn);
|
||||
|
||||
if (!kflag) {
|
||||
doclean = 1;
|
||||
(void)atexit(cleanup);
|
||||
sa.sa_flags = 0;
|
||||
sa.sa_handler = handlesig;
|
||||
(void)sigemptyset(&sa.sa_mask);
|
||||
(void)sigaddset(&sa.sa_mask, SIGHUP);
|
||||
(void)sigaddset(&sa.sa_mask, SIGINT);
|
||||
(void)sigaddset(&sa.sa_mask, SIGTERM);
|
||||
(void)sigaction(SIGHUP, &sa, NULL);
|
||||
(void)sigaction(SIGINT, &sa, NULL);
|
||||
(void)sigaction(SIGTERM, &sa, NULL);
|
||||
}
|
||||
|
||||
lineno = 0;
|
||||
nfiles = 0;
|
||||
truncofs = 0;
|
||||
overfile = NULL;
|
||||
|
||||
/* Ensure 10^sufflen < LONG_MAX. */
|
||||
for (maxfiles = 1, i = 0; i < sufflen; i++) {
|
||||
if (maxfiles > LONG_MAX / 10)
|
||||
errx(1, "%ld: suffix too long (limit %ld)",
|
||||
sufflen, i);
|
||||
maxfiles *= 10;
|
||||
}
|
||||
|
||||
/* Create files based on supplied patterns. */
|
||||
while (nfiles < maxfiles - 1 && (expr = *argv++) != NULL) {
|
||||
/* Look ahead & see if this pattern has any repetitions. */
|
||||
if (*argv != NULL && **argv == '{') {
|
||||
errno = 0;
|
||||
reps = strtol(*argv + 1, &ep, 10);
|
||||
if (reps < 0 || *ep != '}' || errno != 0)
|
||||
errx(1, "%s: bad repetition count", *argv + 1);
|
||||
argv++;
|
||||
} else
|
||||
reps = 0;
|
||||
|
||||
if (*expr == '/' || *expr == '%') {
|
||||
do
|
||||
do_rexp(expr);
|
||||
while (reps-- != 0 && nfiles < maxfiles - 1);
|
||||
} else if (isdigit((unsigned char)*expr))
|
||||
do_lineno(expr);
|
||||
else
|
||||
errx(1, "%s: unrecognised pattern", expr);
|
||||
}
|
||||
|
||||
/* Copy the rest into a new file. */
|
||||
if (!feof(infile)) {
|
||||
ofp = newfile();
|
||||
while ((p = get_line()) != NULL && fputs(p, ofp) == 0)
|
||||
;
|
||||
if (!sflag)
|
||||
(void)printf("%jd\n", (intmax_t)ftello(ofp));
|
||||
if (fclose(ofp) != 0)
|
||||
err(1, "%s", currfile);
|
||||
}
|
||||
|
||||
toomuch(NULL, 0L);
|
||||
doclean = 0;
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static void
|
||||
usage(void)
|
||||
{
|
||||
|
||||
(void)fprintf(stderr,
|
||||
"Usage: %s [-ks] [-f prefix] [-n number] file args ...\n", getprogname());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
__dead static void
|
||||
handlesig(int sig)
|
||||
{
|
||||
char msg[BUFSIZ];
|
||||
size_t len;
|
||||
|
||||
len = snprintf(msg, sizeof(msg), "%s: Caught %s, cleaning up\n",
|
||||
getprogname(), strsignal(sig));
|
||||
if (len < sizeof(msg))
|
||||
(void)write(STDERR_FILENO, msg, len);
|
||||
cleanup();
|
||||
(void)raise_default_signal(sig);
|
||||
_exit(2);
|
||||
}
|
||||
|
||||
/* Create a new output file. */
|
||||
static FILE *
|
||||
newfile(void)
|
||||
{
|
||||
FILE *fp;
|
||||
|
||||
if ((size_t)snprintf(currfile, sizeof(currfile), "%s%0*ld", prefix,
|
||||
(int)sufflen, nfiles) >= sizeof(currfile))
|
||||
errx(1, "%s: %s", currfile, strerror(ENAMETOOLONG));
|
||||
if ((fp = fopen(currfile, "w+")) == NULL)
|
||||
err(1, "%s", currfile);
|
||||
nfiles++;
|
||||
|
||||
return (fp);
|
||||
}
|
||||
|
||||
/* Remove partial output, called before exiting. */
|
||||
static void
|
||||
cleanup(void)
|
||||
{
|
||||
char fnbuf[PATH_MAX];
|
||||
long i;
|
||||
|
||||
if (!doclean)
|
||||
return;
|
||||
|
||||
/*
|
||||
* NOTE: One cannot portably assume to be able to call snprintf()
|
||||
* from inside a signal handler. It does, however, appear to be safe
|
||||
* to do on FreeBSD and NetBSD. The solution to this problem is worse
|
||||
* than the problem itself.
|
||||
*/
|
||||
|
||||
for (i = 0; i < nfiles; i++) {
|
||||
(void)snprintf(fnbuf, sizeof(fnbuf), "%s%0*ld", prefix,
|
||||
(int)sufflen, i);
|
||||
(void)unlink(fnbuf);
|
||||
}
|
||||
}
|
||||
|
||||
/* Read a line from the input into a static buffer. */
|
||||
static char *
|
||||
get_line(void)
|
||||
{
|
||||
static char lbuf[LINE_MAX];
|
||||
FILE *src;
|
||||
|
||||
src = overfile != NULL ? overfile : infile;
|
||||
|
||||
again: if (fgets(lbuf, sizeof(lbuf), src) == NULL) {
|
||||
if (src == overfile) {
|
||||
src = infile;
|
||||
goto again;
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
if (ferror(src))
|
||||
err(1, "%s", infn);
|
||||
lineno++;
|
||||
|
||||
return (lbuf);
|
||||
}
|
||||
|
||||
/* Conceptually rewind the input (as obtained by get_line()) back `n' lines. */
|
||||
static void
|
||||
toomuch(FILE *ofp, long n)
|
||||
{
|
||||
char buf[BUFSIZ];
|
||||
size_t i, nread;
|
||||
|
||||
if (overfile != NULL) {
|
||||
/*
|
||||
* Truncate the previous file we overflowed into back to
|
||||
* the correct length, close it.
|
||||
*/
|
||||
if (fflush(overfile) != 0)
|
||||
err(1, "overflow");
|
||||
if (ftruncate(fileno(overfile), truncofs) != 0)
|
||||
err(1, "overflow");
|
||||
if (fclose(overfile) != 0)
|
||||
err(1, "overflow");
|
||||
overfile = NULL;
|
||||
}
|
||||
|
||||
if (n == 0)
|
||||
/* Just tidying up */
|
||||
return;
|
||||
|
||||
lineno -= n;
|
||||
|
||||
/*
|
||||
* Wind the overflow file backwards to `n' lines before the
|
||||
* current one.
|
||||
*/
|
||||
do {
|
||||
if (ftello(ofp) < (off_t)sizeof(buf))
|
||||
rewind(ofp);
|
||||
else
|
||||
(void)fseeko(ofp, -(off_t)sizeof(buf), SEEK_CUR);
|
||||
if (ferror(ofp))
|
||||
errx(1, "%s: can't seek", currfile);
|
||||
if ((nread = fread(buf, 1, sizeof(buf), ofp)) == 0)
|
||||
errx(1, "can't read overflowed output");
|
||||
if (fseeko(ofp, -(off_t)nread, SEEK_CUR) != 0)
|
||||
err(1, "%s", currfile);
|
||||
for (i = 1; i <= nread; i++)
|
||||
if (buf[nread - i] == '\n' && n-- == 0)
|
||||
break;
|
||||
if (ftello(ofp) == 0)
|
||||
break;
|
||||
} while (n > 0);
|
||||
if (fseeko(ofp, (off_t)nread - i + 1, SEEK_CUR) != 0)
|
||||
err(1, "%s", currfile);
|
||||
|
||||
/*
|
||||
* get_line() will read from here. Next call will truncate to
|
||||
* truncofs in this file.
|
||||
*/
|
||||
overfile = ofp;
|
||||
truncofs = ftello(overfile);
|
||||
}
|
||||
|
||||
/* Handle splits for /regexp/ and %regexp% patterns. */
|
||||
static void
|
||||
do_rexp(const char *expr)
|
||||
{
|
||||
regex_t cre;
|
||||
intmax_t nwritten;
|
||||
long ofs;
|
||||
int first;
|
||||
char *ecopy, *ep, *p, *pofs, *re;
|
||||
FILE *ofp;
|
||||
|
||||
if ((ecopy = strdup(expr)) == NULL)
|
||||
err(1, "strdup");
|
||||
|
||||
re = ecopy + 1;
|
||||
if ((pofs = strrchr(ecopy, *expr)) == NULL || pofs[-1] == '\\')
|
||||
errx(1, "%s: missing trailing %c", expr, *expr);
|
||||
*pofs++ = '\0';
|
||||
|
||||
if (*pofs != '\0') {
|
||||
errno = 0;
|
||||
ofs = strtol(pofs, &ep, 10);
|
||||
if (*ep != '\0' || errno != 0)
|
||||
errx(1, "%s: bad offset", pofs);
|
||||
} else
|
||||
ofs = 0;
|
||||
|
||||
if (regcomp(&cre, re, REG_BASIC|REG_NOSUB) != 0)
|
||||
errx(1, "%s: bad regular expression", re);
|
||||
|
||||
if (*expr == '/')
|
||||
/* /regexp/: Save results to a file. */
|
||||
ofp = newfile();
|
||||
else {
|
||||
/* %regexp%: Make a temporary file for overflow. */
|
||||
if ((ofp = tmpfile()) == NULL)
|
||||
err(1, "tmpfile");
|
||||
}
|
||||
|
||||
/* Read and output lines until we get a match. */
|
||||
first = 1;
|
||||
while ((p = get_line()) != NULL) {
|
||||
if (fputs(p, ofp) != 0)
|
||||
break;
|
||||
if (!first && regexec(&cre, p, 0, NULL, 0) == 0)
|
||||
break;
|
||||
first = 0;
|
||||
}
|
||||
|
||||
if (p == NULL)
|
||||
errx(1, "%s: no match", re);
|
||||
|
||||
if (ofs <= 0) {
|
||||
/*
|
||||
* Negative (or zero) offset: throw back any lines we should
|
||||
* not have read yet.
|
||||
*/
|
||||
if (p != NULL) {
|
||||
toomuch(ofp, -ofs + 1);
|
||||
nwritten = (intmax_t)truncofs;
|
||||
} else
|
||||
nwritten = (intmax_t)ftello(ofp);
|
||||
} else {
|
||||
/*
|
||||
* Positive offset: copy the requested number of lines
|
||||
* after the match.
|
||||
*/
|
||||
while (--ofs > 0 && (p = get_line()) != NULL)
|
||||
if (fputs(p, ofp) != 0)
|
||||
break;
|
||||
toomuch(NULL, 0L);
|
||||
nwritten = (intmax_t)ftello(ofp);
|
||||
if (fclose(ofp) != 0)
|
||||
err(1, "%s", currfile);
|
||||
}
|
||||
|
||||
if (!sflag && *expr == '/')
|
||||
(void)printf("%jd\n", nwritten);
|
||||
|
||||
regfree(&cre);
|
||||
free(ecopy);
|
||||
}
|
||||
|
||||
/* Handle splits based on line number. */
|
||||
static void
|
||||
do_lineno(const char *expr)
|
||||
{
|
||||
long lastline, tgtline;
|
||||
char *ep, *p;
|
||||
FILE *ofp;
|
||||
|
||||
errno = 0;
|
||||
tgtline = strtol(expr, &ep, 10);
|
||||
if (tgtline <= 0 || errno != 0 || *ep != '\0')
|
||||
errx(1, "%s: bad line number", expr);
|
||||
lastline = tgtline;
|
||||
if (lastline <= lineno)
|
||||
errx(1, "%s: can't go backwards", expr);
|
||||
|
||||
while (nfiles < maxfiles - 1) {
|
||||
ofp = newfile();
|
||||
while (lineno + 1 != lastline) {
|
||||
if ((p = get_line()) == NULL)
|
||||
errx(1, "%ld: out of range", lastline);
|
||||
if (fputs(p, ofp) != 0)
|
||||
break;
|
||||
}
|
||||
if (!sflag)
|
||||
(void)printf("%jd\n", (intmax_t)ftello(ofp));
|
||||
if (fclose(ofp) != 0)
|
||||
err(1, "%s", currfile);
|
||||
if (reps-- == 0)
|
||||
break;
|
||||
lastline += tgtline;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,573 +0,0 @@
|
|||
/* $NetBSD: C.c,v 1.19 2009/07/13 19:05:40 roy Exp $ */
|
||||
|
||||
/*
|
||||
* 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. 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.
|
||||
*/
|
||||
|
||||
#if HAVE_NBTOOL_CONFIG_H
|
||||
#include "nbtool_config.h"
|
||||
#endif
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(__RCSID) && !defined(lint)
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)C.c 8.4 (Berkeley) 4/2/94";
|
||||
#else
|
||||
__RCSID("$NetBSD: C.c,v 1.19 2009/07/13 19:05:40 roy Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
#include <limits.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "ctags.h"
|
||||
|
||||
static int func_entry(void);
|
||||
static void hash_entry(void);
|
||||
static void skip_string(int);
|
||||
static int str_entry(int);
|
||||
|
||||
/*
|
||||
* c_entries --
|
||||
* read .c and .h files and call appropriate routines
|
||||
*/
|
||||
void
|
||||
c_entries(void)
|
||||
{
|
||||
int c; /* current character */
|
||||
int level; /* brace level */
|
||||
int token; /* if reading a token */
|
||||
int t_def; /* if reading a typedef */
|
||||
int t_level; /* typedef's brace level */
|
||||
char *sp; /* buffer pointer */
|
||||
char tok[MAXTOKEN]; /* token buffer */
|
||||
|
||||
lineftell = ftell(inf);
|
||||
sp = tok; token = t_def = NO; t_level = -1; level = 0; lineno = 1;
|
||||
while (GETC(!=, EOF)) {
|
||||
switch (c) {
|
||||
/*
|
||||
* Here's where it DOESN'T handle: {
|
||||
* foo(a)
|
||||
* {
|
||||
* #ifdef notdef
|
||||
* }
|
||||
* #endif
|
||||
* if (a)
|
||||
* puts("hello, world");
|
||||
* }
|
||||
*/
|
||||
case '{':
|
||||
++level;
|
||||
goto endtok;
|
||||
case '}':
|
||||
/*
|
||||
* if level goes below zero, try and fix
|
||||
* it, even though we've already messed up
|
||||
*/
|
||||
if (--level < 0)
|
||||
level = 0;
|
||||
goto endtok;
|
||||
|
||||
case '\n':
|
||||
SETLINE;
|
||||
/*
|
||||
* the above 3 cases are similar in that they
|
||||
* are special characters that also end tokens.
|
||||
*/
|
||||
endtok: if (sp > tok) {
|
||||
*sp = EOS;
|
||||
token = YES;
|
||||
sp = tok;
|
||||
}
|
||||
else
|
||||
token = NO;
|
||||
continue;
|
||||
|
||||
/*
|
||||
* We ignore quoted strings and character constants
|
||||
* completely.
|
||||
*/
|
||||
case '"':
|
||||
case '\'':
|
||||
(void)skip_string(c);
|
||||
break;
|
||||
|
||||
/*
|
||||
* comments can be fun; note the state is unchanged after
|
||||
* return, in case we found:
|
||||
* "foo() XX comment XX { int bar; }"
|
||||
*/
|
||||
case '/':
|
||||
if (GETC(==, '*')) {
|
||||
skip_comment(c);
|
||||
continue;
|
||||
} else if (c == '/') {
|
||||
skip_comment(c);
|
||||
continue;
|
||||
}
|
||||
(void)ungetc(c, inf);
|
||||
c = '/';
|
||||
goto storec;
|
||||
|
||||
/* hash marks flag #define's. */
|
||||
case '#':
|
||||
if (sp == tok) {
|
||||
hash_entry();
|
||||
break;
|
||||
}
|
||||
goto storec;
|
||||
|
||||
/*
|
||||
* if we have a current token, parenthesis on
|
||||
* level zero indicates a function.
|
||||
*/
|
||||
case '(':
|
||||
do c = getc(inf);
|
||||
while (c != EOF && iswhite(c));
|
||||
if (c == '*')
|
||||
break;
|
||||
if (c != EOF)
|
||||
ungetc(c, inf);
|
||||
if (!level && token) {
|
||||
int curline;
|
||||
|
||||
if (sp != tok)
|
||||
*sp = EOS;
|
||||
/*
|
||||
* grab the line immediately, we may
|
||||
* already be wrong, for example,
|
||||
* foo\n
|
||||
* (arg1,
|
||||
*/
|
||||
get_line();
|
||||
curline = lineno;
|
||||
if (func_entry()) {
|
||||
++level;
|
||||
pfnote(tok, curline);
|
||||
}
|
||||
break;
|
||||
}
|
||||
goto storec;
|
||||
|
||||
/*
|
||||
* semi-colons indicate the end of a typedef; if we find a
|
||||
* typedef we search for the next semi-colon of the same
|
||||
* level as the typedef. Ignoring "structs", they are
|
||||
* tricky, since you can find:
|
||||
*
|
||||
* "typedef long time_t;"
|
||||
* "typedef unsigned int u_int;"
|
||||
* "typedef unsigned int u_int [10];"
|
||||
*
|
||||
* If looking at a typedef, we save a copy of the last token
|
||||
* found. Then, when we find the ';' we take the current
|
||||
* token if it starts with a valid token name, else we take
|
||||
* the one we saved. There's probably some reasonable
|
||||
* alternative to this...
|
||||
*/
|
||||
case ';':
|
||||
if (t_def && level == t_level) {
|
||||
t_def = NO;
|
||||
get_line();
|
||||
if (sp != tok)
|
||||
*sp = EOS;
|
||||
pfnote(tok, lineno);
|
||||
break;
|
||||
}
|
||||
goto storec;
|
||||
|
||||
/*
|
||||
* store characters until one that can't be part of a token
|
||||
* comes along; check the current token against certain
|
||||
* reserved words.
|
||||
*/
|
||||
default:
|
||||
storec: if (c == EOF)
|
||||
break;
|
||||
if (!intoken(c)) {
|
||||
if (sp == tok)
|
||||
break;
|
||||
*sp = EOS;
|
||||
if (tflag) {
|
||||
/* no typedefs inside typedefs */
|
||||
if (!t_def &&
|
||||
!memcmp(tok, "typedef",8)) {
|
||||
t_def = YES;
|
||||
t_level = level;
|
||||
break;
|
||||
}
|
||||
/* catch "typedef struct" */
|
||||
if ((!t_def || t_level <= level)
|
||||
&& (!memcmp(tok, "struct", 7)
|
||||
|| !memcmp(tok, "union", 6)
|
||||
|| !memcmp(tok, "enum", 5))) {
|
||||
/*
|
||||
* get line immediately;
|
||||
* may change before '{'
|
||||
*/
|
||||
get_line();
|
||||
if (str_entry(c))
|
||||
++level;
|
||||
break;
|
||||
/* } */
|
||||
}
|
||||
}
|
||||
sp = tok;
|
||||
}
|
||||
else if (sp != tok || begtoken(c)) {
|
||||
if (sp < tok + sizeof tok)
|
||||
*sp++ = c;
|
||||
token = YES;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
sp = tok;
|
||||
token = NO;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* func_entry --
|
||||
* handle a function reference
|
||||
*/
|
||||
static int
|
||||
func_entry(void)
|
||||
{
|
||||
int c; /* current character */
|
||||
int level = 0; /* for matching '()' */
|
||||
static char attribute[] = "__attribute__";
|
||||
char maybe_attribute[sizeof attribute + 1],
|
||||
*anext;
|
||||
|
||||
/*
|
||||
* Find the end of the assumed function declaration.
|
||||
* Note that ANSI C functions can have type definitions so keep
|
||||
* track of the parentheses nesting level.
|
||||
*/
|
||||
while (GETC(!=, EOF)) {
|
||||
switch (c) {
|
||||
case '\'':
|
||||
case '"':
|
||||
/* skip strings and character constants */
|
||||
skip_string(c);
|
||||
break;
|
||||
case '/':
|
||||
/* skip comments */
|
||||
if (GETC(==, '*'))
|
||||
skip_comment(c);
|
||||
else if (c == '/')
|
||||
skip_comment(c);
|
||||
break;
|
||||
case '(':
|
||||
level++;
|
||||
break;
|
||||
case ')':
|
||||
if (level == 0)
|
||||
goto fnd;
|
||||
level--;
|
||||
break;
|
||||
case '\n':
|
||||
SETLINE;
|
||||
}
|
||||
}
|
||||
return (NO);
|
||||
fnd:
|
||||
/*
|
||||
* we assume that the character after a function's right paren
|
||||
* is a token character if it's a function and a non-token
|
||||
* character if it's a declaration. Comments don't count...
|
||||
*/
|
||||
for (anext = maybe_attribute;;) {
|
||||
while (GETC(!=, EOF) && iswhite(c))
|
||||
if (c == '\n')
|
||||
SETLINE;
|
||||
if (c == EOF)
|
||||
return NO;
|
||||
/*
|
||||
* Recognize the gnu __attribute__ extension, which would
|
||||
* otherwise make the heuristic test DTWT
|
||||
*/
|
||||
if (anext == maybe_attribute) {
|
||||
if (intoken(c)) {
|
||||
*anext++ = c;
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
if (intoken(c)) {
|
||||
if (anext - maybe_attribute
|
||||
< (ptrdiff_t)(sizeof attribute - 1))
|
||||
*anext++ = c;
|
||||
else break;
|
||||
continue;
|
||||
} else {
|
||||
*anext++ = '\0';
|
||||
if (strcmp(maybe_attribute, attribute) == 0) {
|
||||
(void)ungetc(c, inf);
|
||||
return NO;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (intoken(c) || c == '{')
|
||||
break;
|
||||
if (c == '/' && GETC(==, '*'))
|
||||
skip_comment(c);
|
||||
else if (c == '/')
|
||||
skip_comment(c);
|
||||
else { /* don't ever "read" '/' */
|
||||
(void)ungetc(c, inf);
|
||||
return (NO);
|
||||
}
|
||||
}
|
||||
if (c != '{')
|
||||
(void)skip_key('{');
|
||||
return (YES);
|
||||
}
|
||||
|
||||
/*
|
||||
* hash_entry --
|
||||
* handle a line starting with a '#'
|
||||
*/
|
||||
static void
|
||||
hash_entry(void)
|
||||
{
|
||||
int c; /* character read */
|
||||
int curline; /* line started on */
|
||||
char *sp; /* buffer pointer */
|
||||
char tok[MAXTOKEN]; /* storage buffer */
|
||||
|
||||
curline = lineno;
|
||||
do if (GETC(==, EOF))
|
||||
return;
|
||||
while(c != '\n' && iswhite(c));
|
||||
ungetc(c, inf);
|
||||
for (sp = tok;;) { /* get next token */
|
||||
if (GETC(==, EOF))
|
||||
return;
|
||||
if (iswhite(c))
|
||||
break;
|
||||
if (sp < tok + sizeof tok)
|
||||
*sp++ = c;
|
||||
}
|
||||
if(sp >= tok + sizeof tok)
|
||||
--sp;
|
||||
*sp = EOS;
|
||||
if (memcmp(tok, "define", 6)) /* only interested in #define's */
|
||||
goto skip;
|
||||
for (;;) { /* this doesn't handle "#define \n" */
|
||||
if (GETC(==, EOF))
|
||||
return;
|
||||
if (!iswhite(c))
|
||||
break;
|
||||
}
|
||||
for (sp = tok;;) { /* get next token */
|
||||
if(sp < tok + sizeof tok)
|
||||
*sp++ = c;
|
||||
if (GETC(==, EOF))
|
||||
return;
|
||||
/*
|
||||
* this is where it DOESN'T handle
|
||||
* "#define \n"
|
||||
*/
|
||||
if (!intoken(c))
|
||||
break;
|
||||
}
|
||||
if(sp >= tok + sizeof tok)
|
||||
--sp;
|
||||
*sp = EOS;
|
||||
if (dflag || c == '(') { /* only want macros */
|
||||
get_line();
|
||||
pfnote(tok, curline);
|
||||
}
|
||||
skip: if (c == '\n') { /* get rid of rest of define */
|
||||
SETLINE
|
||||
if (*(sp - 1) != '\\')
|
||||
return;
|
||||
}
|
||||
(void)skip_key('\n');
|
||||
}
|
||||
|
||||
/*
|
||||
* str_entry --
|
||||
* handle a struct, union or enum entry
|
||||
*/
|
||||
static int
|
||||
str_entry(int c /* current character */)
|
||||
{
|
||||
int curline; /* line started on */
|
||||
char *sp; /* buffer pointer */
|
||||
char tok[LINE_MAX]; /* storage buffer */
|
||||
|
||||
curline = lineno;
|
||||
while (iswhite(c))
|
||||
if (GETC(==, EOF))
|
||||
return (NO);
|
||||
if (c == '{') /* it was "struct {" */
|
||||
return (YES);
|
||||
for (sp = tok;;) { /* get next token */
|
||||
*sp++ = c;
|
||||
if (GETC(==, EOF))
|
||||
return (NO);
|
||||
if (!intoken(c))
|
||||
break;
|
||||
}
|
||||
switch (c) {
|
||||
case '{': /* it was "struct foo{" */
|
||||
--sp;
|
||||
break;
|
||||
case '\n': /* it was "struct foo\n" */
|
||||
SETLINE;
|
||||
/*FALLTHROUGH*/
|
||||
default: /* probably "struct foo " */
|
||||
while (GETC(!=, EOF))
|
||||
if (!iswhite(c))
|
||||
break;
|
||||
if (c != '{') {
|
||||
(void)ungetc(c, inf);
|
||||
return (NO);
|
||||
}
|
||||
}
|
||||
*sp = EOS;
|
||||
pfnote(tok, curline);
|
||||
return (YES);
|
||||
}
|
||||
|
||||
/*
|
||||
* skip_comment --
|
||||
* skip over comment
|
||||
*/
|
||||
void
|
||||
skip_comment(int commenttype)
|
||||
{
|
||||
int c; /* character read */
|
||||
int star; /* '*' flag */
|
||||
|
||||
for (star = 0; GETC(!=, EOF);)
|
||||
switch(c) {
|
||||
/* comments don't nest, nor can they be escaped. */
|
||||
case '*':
|
||||
star = YES;
|
||||
break;
|
||||
case '/':
|
||||
if (commenttype == '*' && star)
|
||||
return;
|
||||
break;
|
||||
case '\n':
|
||||
if (commenttype == '/') {
|
||||
/*
|
||||
* we don't really parse C, so sometimes it
|
||||
* is necessary to see the newline
|
||||
*/
|
||||
ungetc(c, inf);
|
||||
return;
|
||||
}
|
||||
SETLINE;
|
||||
/*FALLTHROUGH*/
|
||||
default:
|
||||
star = NO;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* skip_string --
|
||||
* skip to the end of a string or character constant.
|
||||
*/
|
||||
void
|
||||
skip_string(int key)
|
||||
{
|
||||
int c,
|
||||
skip;
|
||||
|
||||
for (skip = NO; GETC(!=, EOF); )
|
||||
switch (c) {
|
||||
case '\\': /* a backslash escapes anything */
|
||||
skip = !skip; /* we toggle in case it's "\\" */
|
||||
break;
|
||||
case '\n':
|
||||
SETLINE;
|
||||
/*FALLTHROUGH*/
|
||||
default:
|
||||
if (c == key && !skip)
|
||||
return;
|
||||
skip = NO;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* skip_key --
|
||||
* skip to next char "key"
|
||||
*/
|
||||
int
|
||||
skip_key(int key)
|
||||
{
|
||||
int c,
|
||||
skip,
|
||||
retval;
|
||||
|
||||
for (skip = retval = NO; GETC(!=, EOF);)
|
||||
switch(c) {
|
||||
case '\\': /* a backslash escapes anything */
|
||||
skip = !skip; /* we toggle in case it's "\\" */
|
||||
break;
|
||||
case ';': /* special case for yacc; if one */
|
||||
case '|': /* of these chars occurs, we may */
|
||||
retval = YES; /* have moved out of the rule */
|
||||
break; /* not used by C */
|
||||
case '\'':
|
||||
case '"':
|
||||
/* skip strings and character constants */
|
||||
skip_string(c);
|
||||
break;
|
||||
case '/':
|
||||
/* skip comments */
|
||||
if (GETC(==, '*')) {
|
||||
skip_comment(c);
|
||||
break;
|
||||
} else if (c == '/') {
|
||||
skip_comment(c);
|
||||
break;
|
||||
}
|
||||
(void)ungetc(c, inf);
|
||||
c = '/';
|
||||
goto norm;
|
||||
case '\n':
|
||||
SETLINE;
|
||||
/*FALLTHROUGH*/
|
||||
default:
|
||||
norm:
|
||||
if (c == key && !skip)
|
||||
return (retval);
|
||||
skip = NO;
|
||||
}
|
||||
return (retval);
|
||||
}
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
# $NetBSD: Makefile,v 1.13 2012/08/10 12:10:27 joerg Exp $
|
||||
# @(#)Makefile 8.1 (Berkeley) 6/6/93
|
||||
|
||||
PROG= ctags
|
||||
CPPFLAGS+=-I${.CURDIR}
|
||||
SRCS= C.c ctags.c fortran.c lisp.c print.c tree.c yacc.c
|
||||
|
||||
.if !defined(HOSTPROGNAME)
|
||||
COPTS.ctags.c+= -Wno-pointer-sign
|
||||
.endif
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
|
|
@ -1,225 +0,0 @@
|
|||
.\" $NetBSD: ctags.1,v 1.17 2014/04/13 01:45:34 snj Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 1987, 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. 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.
|
||||
.\"
|
||||
.\" @(#)ctags.1 8.1 (Berkeley) 6/6/93
|
||||
.\"
|
||||
.Dd June 6, 1993
|
||||
.Dt CTAGS 1
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm ctags
|
||||
.Nd create a tags file
|
||||
.Sh SYNOPSIS
|
||||
.Nm
|
||||
.Op Fl BFadtuwvx
|
||||
.Op Fl f Ar tagsfile
|
||||
.Ar name ...
|
||||
.Sh DESCRIPTION
|
||||
.Nm
|
||||
makes a tags file for
|
||||
.Xr ex 1
|
||||
from the specified C,
|
||||
Pascal, Fortran,
|
||||
.Tn YACC ,
|
||||
lex, and lisp sources.
|
||||
A tags file gives the locations of specified objects in a group of files.
|
||||
Each line of the tags file contains the object name, the file in which it
|
||||
is defined, and a search pattern for the object definition, separated by
|
||||
white-space.
|
||||
Using the
|
||||
.Ar tags
|
||||
file,
|
||||
.Xr ex 1
|
||||
can quickly locate these object definitions.
|
||||
Depending upon the options provided to
|
||||
.Nm ,
|
||||
objects will consist of subroutines, typedefs, defines, structs,
|
||||
enums and unions.
|
||||
.Bl -tag -width Ds
|
||||
.It Fl B
|
||||
use backward searching patterns
|
||||
.Pq Li ?...? .
|
||||
.It Fl F
|
||||
use forward searching patterns
|
||||
.Pq Li /.../
|
||||
(the default).
|
||||
.It Fl a
|
||||
append to
|
||||
.Ar tags
|
||||
file.
|
||||
.It Fl d
|
||||
create tags for
|
||||
.Li #defines
|
||||
that don't take arguments;
|
||||
.Li #defines
|
||||
that take arguments are tagged automatically.
|
||||
.It Fl f
|
||||
Places the tag descriptions in a file called
|
||||
.Ar tagsfile .
|
||||
The default behaviour is to place them in a file called
|
||||
.Ar tags .
|
||||
.It Fl t
|
||||
create tags for typedefs, structs, unions, and enums.
|
||||
.It Fl u
|
||||
update the specified files in the
|
||||
.Ar tags
|
||||
file, that is, all
|
||||
references to them are deleted, and the new values are appended to the
|
||||
file.
|
||||
(Beware: this option is implemented in a way which is rather
|
||||
slow; it is usually faster to simply rebuild the
|
||||
.Ar tags
|
||||
file.)
|
||||
.It Fl v
|
||||
An index of the form expected by
|
||||
.Xr vgrind 1
|
||||
is produced on the standard output.
|
||||
This listing
|
||||
contains the object name, file name, and page number (assuming 64
|
||||
line pages).
|
||||
Since the output will be sorted into lexicographic order,
|
||||
it may be desired to run the output through
|
||||
.Xr sort 1 .
|
||||
Sample use:
|
||||
.Bd -literal -offset indent
|
||||
ctags \-v files \&| sort \-f \*[Gt] index
|
||||
vgrind \-x index
|
||||
.Ed
|
||||
.It Fl w
|
||||
suppress warning diagnostics.
|
||||
.It Fl x
|
||||
.Nm
|
||||
produces a list of object
|
||||
names, the line number and file name on which each is defined, as well
|
||||
as the text of that line and prints this on the standard output.
|
||||
This
|
||||
is a simple index which can be printed out as an off-line readable
|
||||
function index.
|
||||
.El
|
||||
.Pp
|
||||
Files whose names end in
|
||||
.Sq \&.c
|
||||
or
|
||||
.Sq \&.h
|
||||
are assumed to be C
|
||||
source files and are searched for C style routine and macro definitions.
|
||||
Files whose names end in
|
||||
.Sq \&.y
|
||||
are assumed to be
|
||||
.Tn YACC
|
||||
source files.
|
||||
Files whose names end in
|
||||
.Sq \&.l
|
||||
are assumed to be lisp files if their
|
||||
first non-blank character is
|
||||
.Sq \&; ,
|
||||
.Sq \&( ,
|
||||
or
|
||||
.Sq \&[ ,
|
||||
otherwise, they are
|
||||
treated as lex files.
|
||||
Other files are first examined to see if they
|
||||
contain any Pascal or Fortran routine definitions, and, if not, are
|
||||
searched for C style definitions.
|
||||
.Pp
|
||||
The tag
|
||||
.Li main
|
||||
is treated specially in C programs.
|
||||
The tag formed
|
||||
is created by prepending
|
||||
.Ar M
|
||||
to the name of the file, with the
|
||||
trailing
|
||||
.Sq \&.c
|
||||
and any leading pathname components removed.
|
||||
This
|
||||
makes use of
|
||||
.Nm
|
||||
practical in directories with more than one
|
||||
program.
|
||||
.Pp
|
||||
Yacc and lex files each have a special tag.
|
||||
.Ar Yyparse
|
||||
is the start
|
||||
of the second section of the yacc file, and
|
||||
.Ar yylex
|
||||
is the start of
|
||||
the second section of the lex file.
|
||||
.Sh FILES
|
||||
.Bl -tag -width tags -compact
|
||||
.It Pa tags
|
||||
default output tags file
|
||||
.El
|
||||
.Sh EXIT STATUS
|
||||
.Ex -std
|
||||
Duplicate objects are not considered errors.
|
||||
.Sh SEE ALSO
|
||||
.Xr ex 1 ,
|
||||
.Xr vi 1
|
||||
.Sh HISTORY
|
||||
The
|
||||
.Nm
|
||||
command appeared in
|
||||
.Bx 3.0 .
|
||||
.Sh BUGS
|
||||
Recognition of
|
||||
.Em functions ,
|
||||
.Em subroutines
|
||||
and
|
||||
.Em procedures
|
||||
for
|
||||
.Tn FORTRAN
|
||||
and Pascal is done in a very simpleminded way.
|
||||
No attempt
|
||||
is made to deal with block structure; if you have two Pascal procedures
|
||||
in different blocks with the same name you lose.
|
||||
.Nm
|
||||
doesn't
|
||||
understand about Pascal types.
|
||||
.Pp
|
||||
The method of deciding whether to look for C, Pascal or
|
||||
.Tn FORTRAN
|
||||
functions is a hack.
|
||||
.Pp
|
||||
.Nm
|
||||
relies on the input being well formed, and any syntactical
|
||||
errors will completely confuse it.
|
||||
It also finds some legal syntax
|
||||
confusing; for example, since it doesn't understand
|
||||
.Li #ifdef Ns 's
|
||||
(incidentally, that's a feature, not a bug), any code with unbalanced
|
||||
braces inside
|
||||
.Li #ifdef Ns 's
|
||||
will cause it to become somewhat disoriented.
|
||||
In a similar fashion, multiple line changes within a definition will
|
||||
cause it to enter the last line of the object, rather than the first, as
|
||||
the searching pattern.
|
||||
The last line of multiple line
|
||||
.Li typedef Ns 's
|
||||
will similarly be noted.
|
||||
|
|
@ -1,275 +0,0 @@
|
|||
/* $NetBSD: ctags.c,v 1.12 2008/07/21 14:19:22 lukem Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1987, 1993, 1994, 1995
|
||||
* 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. 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.
|
||||
*/
|
||||
|
||||
#if HAVE_NBTOOL_CONFIG_H
|
||||
#include "nbtool_config.h"
|
||||
#endif
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(__COPYRIGHT) && !defined(lint)
|
||||
__COPYRIGHT("@(#) Copyright (c) 1987, 1993, 1994, 1995\
|
||||
The Regents of the University of California. All rights reserved.");
|
||||
#endif /* not lint */
|
||||
|
||||
#if defined(__RCSID) && !defined(lint)
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)ctags.c 8.4 (Berkeley) 2/7/95";
|
||||
#endif
|
||||
__RCSID("$NetBSD: ctags.c,v 1.12 2008/07/21 14:19:22 lukem Exp $");
|
||||
#endif /* not lint */
|
||||
|
||||
#include <err.h>
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "ctags.h"
|
||||
|
||||
/*
|
||||
* ctags: create a tags file
|
||||
*/
|
||||
|
||||
NODE *head; /* head of the sorted binary tree */
|
||||
|
||||
/* boolean "func" (see init()) */
|
||||
bool _wht[256], _etk[256], _itk[256], _btk[256], _gd[256];
|
||||
|
||||
FILE *inf; /* ioptr for current input file */
|
||||
FILE *outf; /* ioptr for tags file */
|
||||
|
||||
long lineftell; /* ftell after getc( inf ) == '\n' */
|
||||
|
||||
int lineno; /* line number of current line */
|
||||
int dflag; /* -d: non-macro defines */
|
||||
int tflag; /* -t: create tags for typedefs */
|
||||
int vflag; /* -v: vgrind style index output */
|
||||
int wflag; /* -w: suppress warnings */
|
||||
int xflag; /* -x: cxref style output */
|
||||
|
||||
char *curfile; /* current input file name */
|
||||
char searchar = '/'; /* use /.../ searches by default */
|
||||
char lbuf[LINE_MAX];
|
||||
|
||||
void init(void);
|
||||
void find_entries(char *);
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
static const char *outfile = "tags"; /* output file */
|
||||
int aflag; /* -a: append to tags */
|
||||
int uflag; /* -u: update tags */
|
||||
int exit_val; /* exit value */
|
||||
int step; /* step through args */
|
||||
int ch; /* getopts char */
|
||||
char cmd[100]; /* too ugly to explain */
|
||||
|
||||
aflag = uflag = NO;
|
||||
while ((ch = getopt(argc, argv, "BFadf:tuwvx")) != -1)
|
||||
switch(ch) {
|
||||
case 'B':
|
||||
searchar = '?';
|
||||
break;
|
||||
case 'F':
|
||||
searchar = '/';
|
||||
break;
|
||||
case 'a':
|
||||
aflag++;
|
||||
break;
|
||||
case 'd':
|
||||
dflag++;
|
||||
break;
|
||||
case 'f':
|
||||
outfile = optarg;
|
||||
break;
|
||||
case 't':
|
||||
tflag++;
|
||||
break;
|
||||
case 'u':
|
||||
uflag++;
|
||||
break;
|
||||
case 'w':
|
||||
wflag++;
|
||||
break;
|
||||
case 'v':
|
||||
vflag++;
|
||||
case 'x':
|
||||
xflag++;
|
||||
break;
|
||||
case '?':
|
||||
default:
|
||||
goto usage;
|
||||
}
|
||||
argv += optind;
|
||||
argc -= optind;
|
||||
if (!argc) {
|
||||
usage: (void)fprintf(stderr,
|
||||
"usage: ctags [-BFadtuwvx] [-f tagsfile] file ...\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
init();
|
||||
|
||||
for (exit_val = step = 0; step < argc; ++step)
|
||||
if (!(inf = fopen(argv[step], "r"))) {
|
||||
warn("%s", argv[step]);
|
||||
exit_val = 1;
|
||||
}
|
||||
else {
|
||||
curfile = argv[step];
|
||||
find_entries(argv[step]);
|
||||
(void)fclose(inf);
|
||||
}
|
||||
|
||||
if (head) {
|
||||
if (xflag)
|
||||
put_entries(head);
|
||||
else {
|
||||
if (uflag) {
|
||||
for (step = 0; step < argc; step++) {
|
||||
(void)snprintf(cmd, sizeof(cmd),
|
||||
"mv %s OTAGS; fgrep -v '\t%s\t' OTAGS >%s; rm OTAGS",
|
||||
outfile, argv[step],
|
||||
outfile);
|
||||
system(cmd);
|
||||
}
|
||||
++aflag;
|
||||
}
|
||||
if (!(outf = fopen(outfile, aflag ? "a" : "w")))
|
||||
err(exit_val, "%s", outfile);
|
||||
put_entries(head);
|
||||
(void)fclose(outf);
|
||||
if (uflag) {
|
||||
(void)snprintf(cmd, sizeof(cmd),
|
||||
"sort -o %s %s", outfile, outfile);
|
||||
system(cmd);
|
||||
}
|
||||
}
|
||||
}
|
||||
exit(exit_val);
|
||||
}
|
||||
|
||||
/*
|
||||
* init --
|
||||
* this routine sets up the boolean psuedo-functions which work by
|
||||
* setting boolean flags dependent upon the corresponding character.
|
||||
* Every char which is NOT in that string is false with respect to
|
||||
* the pseudo-function. Therefore, all of the array "_wht" is NO
|
||||
* by default and then the elements subscripted by the chars in
|
||||
* CWHITE are set to YES. Thus, "_wht" of a char is YES if it is in
|
||||
* the string CWHITE, else NO.
|
||||
*/
|
||||
void
|
||||
init(void)
|
||||
{
|
||||
int i;
|
||||
unsigned const char *sp;
|
||||
|
||||
for (i = 0; i < 256; i++) {
|
||||
_wht[i] = _etk[i] = _itk[i] = _btk[i] = NO;
|
||||
_gd[i] = YES;
|
||||
}
|
||||
#define CWHITE " \f\t\n"
|
||||
for (sp = CWHITE; *sp; sp++) /* white space chars */
|
||||
_wht[*sp] = YES;
|
||||
#define CTOKEN " \t\n\"'#()[]{}=-+%*/&|^~!<>;,.:?"
|
||||
for (sp = CTOKEN; *sp; sp++) /* token ending chars */
|
||||
_etk[*sp] = YES;
|
||||
#define CINTOK "ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz0123456789"
|
||||
for (sp = CINTOK; *sp; sp++) /* valid in-token chars */
|
||||
_itk[*sp] = YES;
|
||||
#define CBEGIN "ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz"
|
||||
for (sp = CBEGIN; *sp; sp++) /* token starting chars */
|
||||
_btk[*sp] = YES;
|
||||
#define CNOTGD ",;"
|
||||
for (sp = CNOTGD; *sp; sp++) /* invalid after-function chars */
|
||||
_gd[*sp] = NO;
|
||||
}
|
||||
|
||||
/*
|
||||
* find_entries --
|
||||
* this routine opens the specified file and calls the function
|
||||
* which searches the file.
|
||||
*/
|
||||
void
|
||||
find_entries(char *file)
|
||||
{
|
||||
char *cp;
|
||||
|
||||
lineno = 0; /* should be 1 ?? KB */
|
||||
if ((cp = strrchr(file, '.')) != NULL) {
|
||||
if (cp[1] == 'l' && !cp[2]) {
|
||||
int c;
|
||||
|
||||
for (;;) {
|
||||
if (GETC(==, EOF))
|
||||
return;
|
||||
if (!iswhite(c)) {
|
||||
rewind(inf);
|
||||
break;
|
||||
}
|
||||
}
|
||||
#define LISPCHR ";(["
|
||||
/* lisp */ if (strchr(LISPCHR, c)) {
|
||||
l_entries();
|
||||
return;
|
||||
}
|
||||
/* lex */ else {
|
||||
/*
|
||||
* we search all 3 parts of a lex file
|
||||
* for C references. This may be wrong.
|
||||
*/
|
||||
toss_yysec();
|
||||
(void)strlcpy(lbuf, "%%$", sizeof(lbuf));
|
||||
pfnote("yylex", lineno);
|
||||
rewind(inf);
|
||||
}
|
||||
}
|
||||
/* yacc */ else if (cp[1] == 'y' && !cp[2]) {
|
||||
/*
|
||||
* we search only the 3rd part of a yacc file
|
||||
* for C references. This may be wrong.
|
||||
*/
|
||||
toss_yysec();
|
||||
(void)strlcpy(lbuf, "%%$", sizeof(lbuf));
|
||||
pfnote("yyparse", lineno);
|
||||
y_entries();
|
||||
}
|
||||
/* fortran */ else if ((cp[1] != 'c' && cp[1] != 'h') && !cp[2]) {
|
||||
if (PF_funcs())
|
||||
return;
|
||||
rewind(inf);
|
||||
}
|
||||
}
|
||||
/* C */ c_entries();
|
||||
}
|
||||
|
|
@ -1,92 +0,0 @@
|
|||
/* $NetBSD: ctags.h,v 1.9 2009/07/13 19:05:40 roy Exp $ */
|
||||
|
||||
/*
|
||||
* 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. 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.
|
||||
*
|
||||
* @(#)ctags.h 8.3 (Berkeley) 4/2/94
|
||||
*/
|
||||
|
||||
#if HAVE_NBTOOL_CONFIG_H
|
||||
#include "nbtool_config.h"
|
||||
#endif
|
||||
|
||||
#define bool char
|
||||
|
||||
#define YES 1
|
||||
#define NO 0
|
||||
#define EOS '\0'
|
||||
|
||||
#define ENDLINE 50 /* max length of pattern */
|
||||
#define MAXTOKEN 250 /* max size of single token */
|
||||
|
||||
#define SETLINE {++lineno;lineftell = ftell(inf);}
|
||||
#define GETC(op,exp) ((c = getc(inf)) op (int)exp)
|
||||
|
||||
#define iswhite(arg) (_wht[(unsigned)arg]) /* T if char is white */
|
||||
#define begtoken(arg) (_btk[(unsigned)arg]) /* T if char can start token */
|
||||
#define intoken(arg) (_itk[(unsigned)arg]) /* T if char can be in token */
|
||||
#define endtoken(arg) (_etk[(unsigned)arg]) /* T if char ends tokens */
|
||||
#define isgood(arg) (_gd[(unsigned)arg]) /* T if char can be after ')' */
|
||||
|
||||
typedef struct nd_st { /* sorting structure */
|
||||
struct nd_st *left,
|
||||
*right; /* left and right sons */
|
||||
char *entry, /* function or type name */
|
||||
*file, /* file name */
|
||||
*pat; /* search pattern */
|
||||
int lno; /* for -x option */
|
||||
bool been_warned; /* set if noticed dup */
|
||||
} NODE;
|
||||
|
||||
extern char *curfile; /* current input file name */
|
||||
extern NODE *head; /* head of the sorted binary tree */
|
||||
extern FILE *inf; /* ioptr for current input file */
|
||||
extern FILE *outf; /* ioptr for current output file */
|
||||
extern long lineftell; /* ftell after getc( inf ) == '\n' */
|
||||
extern int lineno; /* line number of current line */
|
||||
extern int dflag; /* -d: non-macro defines */
|
||||
extern int tflag; /* -t: create tags for typedefs */
|
||||
extern int vflag; /* -v: vgrind style index output */
|
||||
extern int wflag; /* -w: suppress warnings */
|
||||
extern int xflag; /* -x: cxref style output */
|
||||
extern bool _wht[], _etk[], _itk[], _btk[], _gd[];
|
||||
extern char lbuf[LINE_MAX];
|
||||
extern char *lbp;
|
||||
extern char searchar; /* ex search character */
|
||||
|
||||
extern int cicmp(const char *);
|
||||
extern void get_line(void);
|
||||
extern void pfnote(const char *, int);
|
||||
extern int skip_key(int);
|
||||
extern void put_entries(NODE *);
|
||||
extern void toss_yysec(void);
|
||||
extern void l_entries(void);
|
||||
extern void y_entries(void);
|
||||
extern int PF_funcs(void);
|
||||
extern void c_entries(void);
|
||||
extern void skip_comment(int);
|
||||
|
|
@ -1,174 +0,0 @@
|
|||
/* $NetBSD: fortran.c,v 1.11 2009/07/13 19:05:40 roy Exp $ */
|
||||
|
||||
/*
|
||||
* 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. 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.
|
||||
*/
|
||||
|
||||
#if HAVE_NBTOOL_CONFIG_H
|
||||
#include "nbtool_config.h"
|
||||
#endif
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(__RCSID) && !defined(lint)
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)fortran.c 8.3 (Berkeley) 4/2/94";
|
||||
#else
|
||||
__RCSID("$NetBSD: fortran.c,v 1.11 2009/07/13 19:05:40 roy Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
#include <ctype.h>
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "ctags.h"
|
||||
|
||||
static void takeprec(void);
|
||||
|
||||
char *lbp; /* line buffer pointer */
|
||||
|
||||
int
|
||||
PF_funcs(void)
|
||||
{
|
||||
bool pfcnt; /* pascal/fortran functions found */
|
||||
char *cp;
|
||||
char tok[MAXTOKEN];
|
||||
|
||||
for (pfcnt = NO;;) {
|
||||
lineftell = ftell(inf);
|
||||
if (!fgets(lbuf, sizeof(lbuf), inf))
|
||||
return (pfcnt);
|
||||
++lineno;
|
||||
lbp = lbuf;
|
||||
if (*lbp == '%') /* Ratfor escape to fortran */
|
||||
++lbp;
|
||||
for (; isspace((unsigned char)*lbp); ++lbp)
|
||||
continue;
|
||||
if (!*lbp)
|
||||
continue;
|
||||
switch (*lbp | ' ') { /* convert to lower-case */
|
||||
case 'c':
|
||||
if (cicmp("complex") || cicmp("character"))
|
||||
takeprec();
|
||||
break;
|
||||
case 'd':
|
||||
if (cicmp("double")) {
|
||||
for (; isspace((unsigned char)*lbp); ++lbp)
|
||||
continue;
|
||||
if (!*lbp)
|
||||
continue;
|
||||
if (cicmp("precision"))
|
||||
break;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
case 'i':
|
||||
if (cicmp("integer"))
|
||||
takeprec();
|
||||
break;
|
||||
case 'l':
|
||||
if (cicmp("logical"))
|
||||
takeprec();
|
||||
break;
|
||||
case 'r':
|
||||
if (cicmp("real"))
|
||||
takeprec();
|
||||
break;
|
||||
}
|
||||
for (; isspace((unsigned char)*lbp); ++lbp)
|
||||
continue;
|
||||
if (!*lbp)
|
||||
continue;
|
||||
switch (*lbp | ' ') {
|
||||
case 'f':
|
||||
if (cicmp("function"))
|
||||
break;
|
||||
continue;
|
||||
case 'p':
|
||||
if (cicmp("program") || cicmp("procedure"))
|
||||
break;
|
||||
continue;
|
||||
case 's':
|
||||
if (cicmp("subroutine"))
|
||||
break;
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
for (; isspace((unsigned char)*lbp); ++lbp)
|
||||
continue;
|
||||
if (!*lbp)
|
||||
continue;
|
||||
for (cp = lbp + 1; *cp && intoken(*cp); ++cp)
|
||||
continue;
|
||||
if ((cp = lbp + 1) != NULL)
|
||||
continue;
|
||||
*cp = EOS;
|
||||
(void)strlcpy(tok, lbp, sizeof(tok));
|
||||
get_line(); /* process line for ex(1) */
|
||||
pfnote(tok, lineno);
|
||||
pfcnt = YES;
|
||||
}
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
|
||||
/*
|
||||
* cicmp --
|
||||
* do case-independent strcmp
|
||||
*/
|
||||
int
|
||||
cicmp(const char *cp)
|
||||
{
|
||||
int len;
|
||||
char *bp;
|
||||
|
||||
for (len = 0, bp = lbp; *cp && (*cp &~ ' ') == (*bp++ &~ ' ');
|
||||
++cp, ++len)
|
||||
continue;
|
||||
if (!*cp) {
|
||||
lbp += len;
|
||||
return (YES);
|
||||
}
|
||||
return (NO);
|
||||
}
|
||||
|
||||
static void
|
||||
takeprec(void)
|
||||
{
|
||||
for (; isspace((unsigned char)*lbp); ++lbp)
|
||||
continue;
|
||||
if (*lbp == '*') {
|
||||
for (++lbp; isspace((unsigned char)*lbp); ++lbp)
|
||||
continue;
|
||||
if (!isdigit((unsigned char)*lbp))
|
||||
--lbp; /* force failure */
|
||||
else
|
||||
while (isdigit((unsigned char)*++lbp))
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,112 +0,0 @@
|
|||
/* $NetBSD: lisp.c,v 1.11 2009/07/13 19:05:40 roy Exp $ */
|
||||
|
||||
/*
|
||||
* 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. 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.
|
||||
*/
|
||||
|
||||
#if HAVE_NBTOOL_CONFIG_H
|
||||
#include "nbtool_config.h"
|
||||
#endif
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(__RCSID) && !defined(lint)
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)lisp.c 8.3 (Berkeley) 4/2/94";
|
||||
#else
|
||||
__RCSID("$NetBSD: lisp.c,v 1.11 2009/07/13 19:05:40 roy Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
#include <ctype.h>
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "ctags.h"
|
||||
|
||||
/*
|
||||
* lisp tag functions
|
||||
* just look for (def or (DEF
|
||||
*/
|
||||
void
|
||||
l_entries(void)
|
||||
{
|
||||
int special;
|
||||
char *cp;
|
||||
char savedc;
|
||||
char tok[MAXTOKEN];
|
||||
|
||||
for (;;) {
|
||||
lineftell = ftell(inf);
|
||||
if (!fgets(lbuf, sizeof(lbuf), inf))
|
||||
return;
|
||||
++lineno;
|
||||
lbp = lbuf;
|
||||
if (!cicmp("(def"))
|
||||
continue;
|
||||
special = NO;
|
||||
switch(*lbp | ' ') {
|
||||
case 'm':
|
||||
if (cicmp("method"))
|
||||
special = YES;
|
||||
break;
|
||||
case 'w':
|
||||
if (cicmp("wrapper") || cicmp("whopper"))
|
||||
special = YES;
|
||||
}
|
||||
for (; !isspace((unsigned char)*lbp); ++lbp)
|
||||
continue;
|
||||
for (; isspace((unsigned char)*lbp); ++lbp)
|
||||
continue;
|
||||
for (cp = lbp; *cp && *cp != '\n'; ++cp)
|
||||
continue;
|
||||
*cp = EOS;
|
||||
if (special) {
|
||||
if (!(cp = strchr(lbp, ')')))
|
||||
continue;
|
||||
for (; cp >= lbp && *cp != ':'; --cp)
|
||||
continue;
|
||||
if (cp < lbp)
|
||||
continue;
|
||||
lbp = cp;
|
||||
for (; *cp && *cp != ')' && *cp != ' '; ++cp)
|
||||
continue;
|
||||
}
|
||||
else
|
||||
for (cp = lbp + 1;
|
||||
*cp && *cp != '(' && *cp != ' '; ++cp)
|
||||
continue;
|
||||
savedc = *cp;
|
||||
*cp = EOS;
|
||||
(void)strlcpy(tok, lbp, sizeof(tok));
|
||||
*cp = savedc;
|
||||
get_line();
|
||||
pfnote(tok, lineno);
|
||||
}
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user