2 /* Copyright (C) 1989, 1990, 1991, 1992 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, 675 Mass Ave, Cambridge, MA 02139, USA. */
37 fprintf(stderr
, "usage: %s [-nv] [-p database] [-i XYZ] [-t N] keys ...\n",
42 main(int argc
, char **argv
)
44 program_name
= argv
[0];
45 static char stderr_buf
[BUFSIZ
];
46 setbuf(stderr
, stderr_buf
);
47 int search_default
= 1;
50 while ((opt
= getopt(argc
, argv
, "nvVi:t:p:")) != EOF
)
59 linear_ignore_fields
= optarg
;
64 long n
= strtol(optarg
, &ptr
, 10);
65 if (n
== 0 && ptr
== optarg
) {
66 error("bad integer `%1' in `t' option", optarg
);
71 linear_truncate_len
= int(n
);
76 extern const char *version_string
;
77 fprintf(stderr
, "GNU lkbib version %s\n", version_string
);
82 list
.add_file(optarg
);
91 char *filename
= getenv("REFER");
93 list
.add_file(filename
);
94 else if (search_default
)
95 list
.add_file(DEFAULT_INDEX
, 1);
96 if (list
.nfiles() == 0)
97 fatal("no databases");
99 for (int i
= optind
; i
< argc
; i
++)
100 total_len
+= strlen(argv
[i
]);
101 total_len
+= argc
- optind
- 1 + 1; // for spaces and '\0'
102 char *buffer
= new char[total_len
];
104 for (i
= optind
; i
< argc
; i
++) {
107 strcpy(ptr
, argv
[i
]);
108 ptr
= strchr(ptr
, '\0');
110 search_list_iterator
iter(&list
, buffer
);
113 for (int count
= 0; iter
.next(&start
, &len
); count
++) {
114 if (fwrite(start
, 1, len
, stdout
) != len
)
115 fatal("write error on stdout: %1", strerror(errno
));
116 // Can happen for last reference in file.
117 if (start
[len
- 1] != '\n')