2 /* Copyright (C) 1989-1992, 2000, 2001 Free Software Foundation, Inc.
3 Written by James Clark (jjc@jclark.com)
5 This file is part of groff.
7 groff is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 groff is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License along
18 with groff; see the file COPYING. If not, write to the Free Software
19 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
37 const char *Version_string
;
40 static void usage(FILE *stream
)
42 fprintf(stream
, "usage: %s [-v] [-i XYZ] [-t N] database ...\n",
46 int main(int argc
, char **argv
)
48 program_name
= argv
[0];
49 static char stderr_buf
[BUFSIZ
];
50 setbuf(stderr
, stderr_buf
);
52 static const struct option long_options
[] = {
53 { "help", no_argument
, 0, CHAR_MAX
+ 1 },
54 { "version", no_argument
, 0, 'v' },
57 while ((opt
= getopt_long(argc
, argv
, "vVi:t:", long_options
, NULL
)) != EOF
)
63 linear_ignore_fields
= optarg
;
68 long n
= strtol(optarg
, &ptr
, 10);
69 if (n
== 0 && ptr
== optarg
) {
70 error("bad integer `%1' in `t' option", optarg
);
75 linear_truncate_len
= int(n
);
80 printf("GNU lookbib (groff) version %s\n", Version_string
);
84 case CHAR_MAX
+ 1: // --help
100 for (int i
= optind
; i
< argc
; i
++)
101 list
.add_file(argv
[i
]);
102 if (list
.nfiles() == 0)
103 fatal("no databases");
105 int interactive
= isatty(fileno(stdin
));
111 if (!fgets(line
, sizeof(line
), stdin
))
114 while (csspace(*ptr
))
118 search_list_iterator
iter(&list
, line
);
122 for (count
= 0; iter
.next(&start
, &len
); count
++) {
123 if (fwrite(start
, 1, len
, stdout
) != (size_t)len
)
124 fatal("write error on stdout: %1", strerror(errno
));
125 // Can happen for last reference in file.
126 if (start
[len
- 1] != '\n')
132 fprintf(stderr
, "%d found\n", count
);