2 /* Copyright (C) 1991 Free Software Foundation, Inc.
3 Written by James Clark (jjc@jclark.uucp)
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 1, 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 LICENSE. If not, write to the Free Software
19 Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
41 fprintf(stderr
, "usage: %s [-v] [-i XYZ] [-t N] database ...\n",
46 main(int argc
, char **argv
)
48 program_name
= argv
[0];
49 static char stderr_buf
[BUFSIZ
];
50 setbuf(stderr
, stderr_buf
);
52 while ((opt
= getopt(argc
, argv
, "vVi:t:")) != EOF
)
58 linear_ignore_fields
= optarg
;
63 long n
= strtol(optarg
, &ptr
, 10);
64 if (n
== 0 && ptr
== optarg
) {
65 error("bad integer `%1' in `t' option", optarg
);
70 linear_truncate_len
= int(n
);
75 extern const char *version_string
;
76 fprintf(stderr
, "GNU lookbib version %s\n", version_string
);
88 for (int i
= optind
; i
< argc
; i
++)
89 list
.add_file(argv
[i
]);
90 if (list
.nfiles() == 0)
91 fatal("no databases");
93 int interactive
= isatty(fileno(stdin
));
99 if (!fgets(line
, sizeof(line
), stdin
))
102 while (csspace(*ptr
))
106 search_list_iterator
iter(&list
, line
);
109 for (int count
= 0; iter
.next(&start
, &len
); count
++) {
110 if (fwrite(start
, 1, len
, stdout
) != len
)
111 fatal("write error on stdout: %1", strerror(errno
));
112 // Can happen for last reference in file.
113 if (start
[len
- 1] != '\n')
119 fprintf(stderr
, "%d found\n", count
);