4 /* Copyright (C) 1989-1992, 2000, 2001, 2002, 2003
5 Free Software Foundation, Inc.
6 Written by James Clark (jjc@jclark.com)
8 This file is part of groff.
10 groff is free software; you can redistribute it and/or modify it under
11 the terms of the GNU General Public License as published by the Free
12 Software Foundation; either version 2, or (at your option) any later
15 groff is distributed in the hope that it will be useful, but WITHOUT ANY
16 WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 You should have received a copy of the GNU General Public License along
21 with groff; see the file COPYING. If not, write to the Free Software
22 Foundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */
42 const char *Version_string
;
45 static void usage(FILE *stream
)
47 fprintf(stream
, "usage: %s [-v] [-i XYZ] [-t N] database ...\n",
51 int main(int argc
, char **argv
)
53 program_name
= argv
[0];
54 static char stderr_buf
[BUFSIZ
];
55 setbuf(stderr
, stderr_buf
);
57 static const struct option long_options
[] = {
58 { "help", no_argument
, 0, CHAR_MAX
+ 1 },
59 { "version", no_argument
, 0, 'v' },
62 while ((opt
= getopt_long(argc
, argv
, "vVi:t:", long_options
, NULL
)) != EOF
)
68 linear_ignore_fields
= optarg
;
73 long n
= strtol(optarg
, &ptr
, 10);
74 if (n
== 0 && ptr
== optarg
) {
75 error("bad integer `%1' in `t' option", optarg
);
80 linear_truncate_len
= int(n
);
85 printf("GNU lookbib (groff) version %s\n", Version_string
);
89 case CHAR_MAX
+ 1: // --help
100 if (optind
>= argc
) {
105 for (int i
= optind
; i
< argc
; i
++)
106 list
.add_file(argv
[i
]);
107 if (list
.nfiles() == 0)
108 fatal("no databases");
110 int interactive
= isatty(fileno(stdin
));
116 if (!fgets(line
, sizeof(line
), stdin
))
119 while (csspace(*ptr
))
123 search_list_iterator
iter(&list
, line
);
127 for (count
= 0; iter
.next(&start
, &len
); count
++) {
128 if (fwrite(start
, 1, len
, stdout
) != (size_t)len
)
129 fatal("write error on stdout: %1", strerror(errno
));
130 // Can happen for last reference in file.
131 if (start
[len
- 1] != '\n')
137 fprintf(stderr
, "%d found\n", count
);