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