util.c (59218eb770e61b578f0ab296afbbfb381c211939) | util.c (3ed1008b891eb34df96a6ae4f87e5a3270be759c) |
---|---|
1/* $OpenBSD: util.c,v 1.39 2010/07/02 22:18:03 tedu Exp $ */ 2 3/*- 4 * Copyright (c) 1999 James Howard and Dag-Erling Co�dan Sm�rgrav 5 * Copyright (C) 2008-2010 Gabor Kovesdan <gabor@FreeBSD.org> 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 170 unchanged lines hidden (view full) --- 179 mode_t s; 180 int c, t; 181 182 if (mflag && (mcount <= 0)) 183 return (0); 184 185 if (strcmp(fn, "-") == 0) { 186 fn = label != NULL ? label : getstr(1); | 1/* $OpenBSD: util.c,v 1.39 2010/07/02 22:18:03 tedu Exp $ */ 2 3/*- 4 * Copyright (c) 1999 James Howard and Dag-Erling Co�dan Sm�rgrav 5 * Copyright (C) 2008-2010 Gabor Kovesdan <gabor@FreeBSD.org> 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 170 unchanged lines hidden (view full) --- 179 mode_t s; 180 int c, t; 181 182 if (mflag && (mcount <= 0)) 183 return (0); 184 185 if (strcmp(fn, "-") == 0) { 186 fn = label != NULL ? label : getstr(1); |
187 f = grep_stdin_open(); | 187 f = grep_open(NULL); |
188 } else { 189 if (!stat(fn, &sb)) { 190 /* Check if we need to process the file */ 191 s = sb.st_mode & S_IFMT; 192 if (s == S_IFDIR && dirbehave == DIR_SKIP) 193 return (0); 194 if ((s == S_IFIFO || s == S_IFCHR || s == S_IFBLK 195 || s == S_IFSOCK) && devbehave == DEV_SKIP) --- 14 unchanged lines hidden (view full) --- 210 ln.line_no = 0; 211 ln.len = 0; 212 linesqueued = 0; 213 tail = 0; 214 ln.off = -1; 215 216 for (c = 0; c == 0 || !(lflag || qflag); ) { 217 ln.off += ln.len + 1; | 188 } else { 189 if (!stat(fn, &sb)) { 190 /* Check if we need to process the file */ 191 s = sb.st_mode & S_IFMT; 192 if (s == S_IFDIR && dirbehave == DIR_SKIP) 193 return (0); 194 if ((s == S_IFIFO || s == S_IFCHR || s == S_IFBLK 195 || s == S_IFSOCK) && devbehave == DEV_SKIP) --- 14 unchanged lines hidden (view full) --- 210 ln.line_no = 0; 211 ln.len = 0; 212 linesqueued = 0; 213 tail = 0; 214 ln.off = -1; 215 216 for (c = 0; c == 0 || !(lflag || qflag); ) { 217 ln.off += ln.len + 1; |
218 if ((ln.dat = grep_fgetln(f, &ln.len)) == NULL) { | 218 if ((ln.dat = grep_fgetln(f, &ln.len)) == NULL || ln.len == 0) { |
219 if (ln.line_no == 0 && matchall) 220 exit(0); 221 else 222 break; 223 } 224 if (ln.len > 0 && ln.dat[ln.len - 1] == '\n') 225 --ln.len; 226 ln.line_no++; --- 276 unchanged lines hidden --- | 219 if (ln.line_no == 0 && matchall) 220 exit(0); 221 else 222 break; 223 } 224 if (ln.len > 0 && ln.dat[ln.len - 1] == '\n') 225 --ln.len; 226 ln.line_no++; --- 276 unchanged lines hidden --- |