Check in remainder of groff 1.08
This commit is contained in:
parent
737517bce7
commit
64bef05a16
11
gnu/usr.bin/groff/lkbib/Makefile
Normal file
11
gnu/usr.bin/groff/lkbib/Makefile
Normal file
@ -0,0 +1,11 @@
|
||||
# Makefile for lkbib
|
||||
|
||||
PROG= lkbib
|
||||
SRCS= lkbib.cc
|
||||
CFLAGS+= -I$(.CURDIR)/../include
|
||||
LDADD+= $(LIBBIB) $(LIBGROFF) -lm
|
||||
DPADD+= $(LIBBIB) $(LIBGROFF) $(LIBMATH)
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
.include "../../Makefile.inc"
|
||||
.include "../Makefile.cfg"
|
2
gnu/usr.bin/groff/lkbib/Makefile.dep
Normal file
2
gnu/usr.bin/groff/lkbib/Makefile.dep
Normal file
@ -0,0 +1,2 @@
|
||||
lkbib.o : lkbib.cc ../include/lib.h ../include/errarg.h ../include/error.h \
|
||||
../include/defs.h ../include/refid.h ../include/search.h
|
90
gnu/usr.bin/groff/lkbib/lkbib.1
Normal file
90
gnu/usr.bin/groff/lkbib/lkbib.1
Normal file
@ -0,0 +1,90 @@
|
||||
.\" -*- nroff -*-
|
||||
.ds g \" empty
|
||||
.ds G \" empty
|
||||
.\" Like TP, but if specified indent is more than half
|
||||
.\" the current line-length - indent, use the default indent.
|
||||
.de Tp
|
||||
.ie \\n(.$=0:((0\\$1)*2u>(\\n(.lu-\\n(.iu)) .TP
|
||||
.el .TP "\\$1"
|
||||
..
|
||||
.TH LKBIB 1 "6 August 1992" "Groff Version 1.08"
|
||||
.SH NAME
|
||||
lkbib \- search bibliographic databases
|
||||
.SH SYNOPSIS
|
||||
.B lkbib
|
||||
[
|
||||
.B \-v
|
||||
]
|
||||
[
|
||||
.BI \-i fields
|
||||
]
|
||||
[
|
||||
.BI \-p filename
|
||||
]
|
||||
[
|
||||
.BI \-t n
|
||||
]
|
||||
.IR key \|.\|.\|.
|
||||
.SH DESCRIPTION
|
||||
.B lkbib
|
||||
searches bibliographic databases for references that contain the keys
|
||||
.IR key \|.\|.\|.
|
||||
and prints any references found on the standard output.
|
||||
.B lkbib
|
||||
will search any databases given by
|
||||
.B \-p
|
||||
options, and then a default database.
|
||||
The default database is taken from the
|
||||
.SB REFER
|
||||
environment variable if it is set,
|
||||
otherwise it is
|
||||
.BR /usr/share/dict/papers/Ind .
|
||||
For each database
|
||||
.I filename
|
||||
to be searched,
|
||||
if an index
|
||||
.IB filename .i
|
||||
created by
|
||||
.BR indxbib (1)
|
||||
exists, then it will be searched instead;
|
||||
each index can cover multiple databases.
|
||||
.SH OPTIONS
|
||||
.TP
|
||||
.B \-v
|
||||
Print the version number.
|
||||
.TP
|
||||
.BI \-p filename
|
||||
Search
|
||||
.IR filename .
|
||||
Multiple
|
||||
.B \-p
|
||||
options can be used.
|
||||
.TP
|
||||
.BI \-i string
|
||||
When searching files for which no index exists,
|
||||
ignore the contents of fields whose names are in
|
||||
.IR string .
|
||||
.TP
|
||||
.BI \-t n
|
||||
Only require the first
|
||||
.I n
|
||||
characters of keys to be given.
|
||||
Initially
|
||||
.I n
|
||||
is 6.
|
||||
.SH ENVIRONMENT
|
||||
.TP \w'\fBREFER'u+2n
|
||||
.SB REFER
|
||||
Default database.
|
||||
.SH FILES
|
||||
.Tp \w'\fB/usr/share/dict/papers/Ind'u+2n
|
||||
.B /usr/share/dict/papers/Ind
|
||||
Default database to be used if the
|
||||
.SB REFER
|
||||
environment variable is not set.
|
||||
.IB filename .i
|
||||
Index files.
|
||||
.SH "SEE ALSO"
|
||||
.BR refer (1),
|
||||
.BR lookbib (1),
|
||||
.BR indxbib (1)
|
122
gnu/usr.bin/groff/lkbib/lkbib.cc
Normal file
122
gnu/usr.bin/groff/lkbib/lkbib.cc
Normal file
@ -0,0 +1,122 @@
|
||||
// -*- C++ -*-
|
||||
/* Copyright (C) 1989, 1990, 1991, 1992 Free Software Foundation, Inc.
|
||||
Written by James Clark (jjc@jclark.com)
|
||||
|
||||
This file is part of groff.
|
||||
|
||||
groff is free software; you can redistribute it and/or modify it under
|
||||
the terms of the GNU General Public License as published by the Free
|
||||
Software Foundation; either version 2, or (at your option) any later
|
||||
version.
|
||||
|
||||
groff is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with groff; see the file COPYING. If not, write to the Free Software
|
||||
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "lib.h"
|
||||
#include "errarg.h"
|
||||
#include "error.h"
|
||||
|
||||
#include "defs.h"
|
||||
#include "refid.h"
|
||||
#include "search.h"
|
||||
|
||||
static void usage()
|
||||
{
|
||||
fprintf(stderr, "usage: %s [-nv] [-p database] [-i XYZ] [-t N] keys ...\n",
|
||||
program_name);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
program_name = argv[0];
|
||||
static char stderr_buf[BUFSIZ];
|
||||
setbuf(stderr, stderr_buf);
|
||||
int search_default = 1;
|
||||
search_list list;
|
||||
int opt;
|
||||
while ((opt = getopt(argc, argv, "nvVi:t:p:")) != EOF)
|
||||
switch (opt) {
|
||||
case 'V':
|
||||
verify_flag = 1;
|
||||
break;
|
||||
case 'n':
|
||||
search_default = 0;
|
||||
break;
|
||||
case 'i':
|
||||
linear_ignore_fields = optarg;
|
||||
break;
|
||||
case 't':
|
||||
{
|
||||
char *ptr;
|
||||
long n = strtol(optarg, &ptr, 10);
|
||||
if (n == 0 && ptr == optarg) {
|
||||
error("bad integer `%1' in `t' option", optarg);
|
||||
break;
|
||||
}
|
||||
if (n < 1)
|
||||
n = 1;
|
||||
linear_truncate_len = int(n);
|
||||
break;
|
||||
}
|
||||
case 'v':
|
||||
{
|
||||
extern const char *version_string;
|
||||
fprintf(stderr, "GNU lkbib version %s\n", version_string);
|
||||
fflush(stderr);
|
||||
break;
|
||||
}
|
||||
case 'p':
|
||||
list.add_file(optarg);
|
||||
break;
|
||||
case '?':
|
||||
usage();
|
||||
default:
|
||||
assert(0);
|
||||
}
|
||||
if (optind >= argc)
|
||||
usage();
|
||||
char *filename = getenv("REFER");
|
||||
if (filename)
|
||||
list.add_file(filename);
|
||||
else if (search_default)
|
||||
list.add_file(DEFAULT_INDEX, 1);
|
||||
if (list.nfiles() == 0)
|
||||
fatal("no databases");
|
||||
int total_len = 0;
|
||||
for (int i = optind; i < argc; i++)
|
||||
total_len += strlen(argv[i]);
|
||||
total_len += argc - optind - 1 + 1; // for spaces and '\0'
|
||||
char *buffer = new char[total_len];
|
||||
char *ptr = buffer;
|
||||
for (i = optind; i < argc; i++) {
|
||||
if (i > optind)
|
||||
*ptr++ = ' ';
|
||||
strcpy(ptr, argv[i]);
|
||||
ptr = strchr(ptr, '\0');
|
||||
}
|
||||
search_list_iterator iter(&list, buffer);
|
||||
const char *start;
|
||||
int len;
|
||||
for (int count = 0; iter.next(&start, &len); count++) {
|
||||
if (fwrite(start, 1, len, stdout) != len)
|
||||
fatal("write error on stdout: %1", strerror(errno));
|
||||
// Can happen for last reference in file.
|
||||
if (start[len - 1] != '\n')
|
||||
putchar('\n');
|
||||
putchar('\n');
|
||||
}
|
||||
exit(!count);
|
||||
}
|
11
gnu/usr.bin/groff/lookbib/Makefile
Normal file
11
gnu/usr.bin/groff/lookbib/Makefile
Normal file
@ -0,0 +1,11 @@
|
||||
# Makefile for lookbib
|
||||
|
||||
PROG= lookbib
|
||||
SRCS= lookbib.cc
|
||||
CFLAGS+= -I$(.CURDIR)/../include
|
||||
LDADD+= $(LIBBIB) $(LIBGROFF) -lm
|
||||
DPADD+= $(LIBBIB) $(LIBGROFF) $(LIBMATH)
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
.include "../../Makefile.inc"
|
||||
.include "../Makefile.cfg"
|
2
gnu/usr.bin/groff/lookbib/Makefile.dep
Normal file
2
gnu/usr.bin/groff/lookbib/Makefile.dep
Normal file
@ -0,0 +1,2 @@
|
||||
lookbib.o : lookbib.cc ../include/errarg.h ../include/error.h \
|
||||
../include/lib.h ../include/cset.h ../include/refid.h ../include/search.h
|
58
gnu/usr.bin/groff/lookbib/lookbib.1
Normal file
58
gnu/usr.bin/groff/lookbib/lookbib.1
Normal file
@ -0,0 +1,58 @@
|
||||
.\" -*- nroff -*-
|
||||
.TH LOOKBIB 1 "6 August 1992" "Groff Version 1.08"
|
||||
.SH NAME
|
||||
lookbib \- search bibliographic databases
|
||||
.SH SYNOPSIS
|
||||
.B lookbib
|
||||
[
|
||||
.B \-v
|
||||
]
|
||||
[
|
||||
.BI \-i string
|
||||
]
|
||||
[
|
||||
.BI \-t n
|
||||
]
|
||||
.IR filename \|.\|.\|.
|
||||
.SH DESCRIPTION
|
||||
lookbib prints a prompt on the standard error (unless the standard input is not a terminal),
|
||||
reads from the standard input a line containing a set of keywords,
|
||||
searches the bibliographic databases
|
||||
.IR filename \|.\|.\|.
|
||||
for references containing those keywords,
|
||||
prints any references found on the standard output,
|
||||
and repeats this process until the end of input.
|
||||
For each database
|
||||
.I filename
|
||||
to be searched,
|
||||
if an index
|
||||
.IB filename .i
|
||||
created by
|
||||
.BR indxbib (1)
|
||||
exists, then it will be searched instead;
|
||||
each index can cover multiple databases.
|
||||
.SH OPTIONS
|
||||
.TP
|
||||
.B \-v
|
||||
Print the version number.
|
||||
.TP
|
||||
.BI \-i string
|
||||
When searching files for which no index exists,
|
||||
ignore the contents of fields whose names are in
|
||||
.IR string .
|
||||
.TP
|
||||
.BI \-t n
|
||||
Only require the first
|
||||
.I n
|
||||
characters of keys to be given.
|
||||
Initially
|
||||
.I n
|
||||
is 6.
|
||||
.SH FILES
|
||||
.TP \w'\fIfilename\fB.i'u+2n
|
||||
.IB filename .i
|
||||
Index files.
|
||||
.SH "SEE ALSO"
|
||||
.BR refer (1),
|
||||
.BR lkbib (1),
|
||||
.BR indxbib (1)
|
127
gnu/usr.bin/groff/lookbib/lookbib.cc
Normal file
127
gnu/usr.bin/groff/lookbib/lookbib.cc
Normal file
@ -0,0 +1,127 @@
|
||||
// -*- C++ -*-
|
||||
/* Copyright (C) 1989, 1990, 1991, 1992 Free Software Foundation, Inc.
|
||||
Written by James Clark (jjc@jclark.com)
|
||||
|
||||
This file is part of groff.
|
||||
|
||||
groff is free software; you can redistribute it and/or modify it under
|
||||
the terms of the GNU General Public License as published by the Free
|
||||
Software Foundation; either version 2, or (at your option) any later
|
||||
version.
|
||||
|
||||
groff is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with groff; see the file COPYING. If not, write to the Free Software
|
||||
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "errarg.h"
|
||||
#include "error.h"
|
||||
#include "lib.h"
|
||||
#include "cset.h"
|
||||
|
||||
#include "refid.h"
|
||||
#include "search.h"
|
||||
|
||||
extern "C" {
|
||||
int isatty(int);
|
||||
}
|
||||
|
||||
static void usage()
|
||||
{
|
||||
fprintf(stderr, "usage: %s [-v] [-i XYZ] [-t N] database ...\n",
|
||||
program_name);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
program_name = argv[0];
|
||||
static char stderr_buf[BUFSIZ];
|
||||
setbuf(stderr, stderr_buf);
|
||||
int opt;
|
||||
while ((opt = getopt(argc, argv, "vVi:t:")) != EOF)
|
||||
switch (opt) {
|
||||
case 'V':
|
||||
verify_flag = 1;
|
||||
break;
|
||||
case 'i':
|
||||
linear_ignore_fields = optarg;
|
||||
break;
|
||||
case 't':
|
||||
{
|
||||
char *ptr;
|
||||
long n = strtol(optarg, &ptr, 10);
|
||||
if (n == 0 && ptr == optarg) {
|
||||
error("bad integer `%1' in `t' option", optarg);
|
||||
break;
|
||||
}
|
||||
if (n < 1)
|
||||
n = 1;
|
||||
linear_truncate_len = int(n);
|
||||
break;
|
||||
}
|
||||
case 'v':
|
||||
{
|
||||
extern const char *version_string;
|
||||
fprintf(stderr, "GNU lookbib version %s\n", version_string);
|
||||
fflush(stderr);
|
||||
break;
|
||||
}
|
||||
case '?':
|
||||
usage();
|
||||
default:
|
||||
assert(0);
|
||||
}
|
||||
if (optind >= argc)
|
||||
usage();
|
||||
search_list list;
|
||||
for (int i = optind; i < argc; i++)
|
||||
list.add_file(argv[i]);
|
||||
if (list.nfiles() == 0)
|
||||
fatal("no databases");
|
||||
char line[1024];
|
||||
int interactive = isatty(fileno(stdin));
|
||||
for (;;) {
|
||||
if (interactive) {
|
||||
fputs("> ", stderr);
|
||||
fflush(stderr);
|
||||
}
|
||||
if (!fgets(line, sizeof(line), stdin))
|
||||
break;
|
||||
char *ptr = line;
|
||||
while (csspace(*ptr))
|
||||
ptr++;
|
||||
if (*ptr == '\0')
|
||||
continue;
|
||||
search_list_iterator iter(&list, line);
|
||||
const char *start;
|
||||
int len;
|
||||
for (int count = 0; iter.next(&start, &len); count++) {
|
||||
if (fwrite(start, 1, len, stdout) != len)
|
||||
fatal("write error on stdout: %1", strerror(errno));
|
||||
// Can happen for last reference in file.
|
||||
if (start[len - 1] != '\n')
|
||||
putchar('\n');
|
||||
putchar('\n');
|
||||
}
|
||||
fflush(stdout);
|
||||
if (interactive) {
|
||||
fprintf(stderr, "%d found\n", count);
|
||||
fflush(stderr);
|
||||
}
|
||||
}
|
||||
if (interactive)
|
||||
putc('\n', stderr);
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user