1/* $NetBSD: util.c,v 1.9 2011/02/27 17:33:37 joerg Exp $ */
2/* $FreeBSD: head/usr.bin/grep/util.c 228093 2011-11-28 20:00:31Z gabor $ */
3/* $OpenBSD: util.c,v 1.39 2010/07/02 22:18:03 tedu Exp $ */
4
5/*-
6 * Copyright (c) 1999 James Howard and Dag-Erling Co��dan Sm��rgrav
7 * Copyright (C) 2008-2010 Gabor Kovesdan <gabor@FreeBSD.org>
8 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
--- 14 unchanged lines hidden (view full) ---
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31
32#include <sys/cdefs.h>
33__FBSDID("$FreeBSD: head/usr.bin/grep/util.c 228093 2011-11-28 20:00:31Z gabor $");
34
35#include <sys/stat.h>
36#include <sys/types.h>
37
38#include <ctype.h>
39#include <err.h>
40#include <errno.h>
41#include <fnmatch.h>
--- 199 unchanged lines hidden (view full) ---
241 grep_close(f);
242
243 if (cflag) {
244 if (!hflag)
245 printf("%s:", ln.file);
246 printf("%u\n", c);
247 }
248 if (lflag && !qflag && c != 0)
249 printf("%s%c", fn, nullflag ? 0 : '\n');
250 if (Lflag && !qflag && c == 0)
251 printf("%s%c", fn, nullflag ? 0 : '\n');
252 if (c && !cflag && !lflag && !Lflag &&
253 binbehave == BINFILE_BIN && f->binary && !qflag)
254 printf(getstr(8), fn);
255
256 free(ln.file);
257 free(f);
258 return (c);
259}
--- 175 unchanged lines hidden (view full) ---
435 */
436void
437printline(struct str *line, int sep, regmatch_t *matches, int m)
438{
439 size_t a = 0;
440 int i, n = 0;
441
442 if (!hflag) {
443 if (!nullflag) {
444 fputs(line->file, stdout);
445 ++n;
446 } else {
447 printf("%s", line->file);
448 putchar(0);
449 }
450 }
451 if (nflag) {
452 if (n > 0)
453 putchar(sep);
454 printf("%d", line->line_no);
455 ++n;
456 }
457 if (bflag) {
--- 35 unchanged lines hidden ---
2/* $FreeBSD: head/usr.bin/grep/util.c 228093 2011-11-28 20:00:31Z gabor $ */
3/* $OpenBSD: util.c,v 1.39 2010/07/02 22:18:03 tedu Exp $ */
4
5/*-
6 * Copyright (c) 1999 James Howard and Dag-Erling Co��dan Sm��rgrav
7 * Copyright (C) 2008-2010 Gabor Kovesdan <gabor@FreeBSD.org>
8 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
--- 14 unchanged lines hidden (view full) ---
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31
32#include <sys/cdefs.h>
33__FBSDID("$FreeBSD: head/usr.bin/grep/util.c 228093 2011-11-28 20:00:31Z gabor $");
34
35#include <sys/stat.h>
36#include <sys/types.h>
37
38#include <ctype.h>
39#include <err.h>
40#include <errno.h>
41#include <fnmatch.h>
--- 199 unchanged lines hidden (view full) ---
241 grep_close(f);
242
243 if (cflag) {
244 if (!hflag)
245 printf("%s:", ln.file);
246 printf("%u\n", c);
247 }
248 if (lflag && !qflag && c != 0)
249 printf("%s%c", fn, nullflag ? 0 : '\n');
250 if (Lflag && !qflag && c == 0)
251 printf("%s%c", fn, nullflag ? 0 : '\n');
252 if (c && !cflag && !lflag && !Lflag &&
253 binbehave == BINFILE_BIN && f->binary && !qflag)
254 printf(getstr(8), fn);
255
256 free(ln.file);
257 free(f);
258 return (c);
259}
--- 175 unchanged lines hidden (view full) ---
435 */
436void
437printline(struct str *line, int sep, regmatch_t *matches, int m)
438{
439 size_t a = 0;
440 int i, n = 0;
441
442 if (!hflag) {
443 if (!nullflag) {
444 fputs(line->file, stdout);
445 ++n;
446 } else {
447 printf("%s", line->file);
448 putchar(0);
449 }
450 }
451 if (nflag) {
452 if (n > 0)
453 putchar(sep);
454 printf("%d", line->line_no);
455 ++n;
456 }
457 if (bflag) {
--- 35 unchanged lines hidden ---