Deleted Added
full compact
util.c (211364) util.c (211463)
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

--- 14 unchanged lines hidden (view full) ---

23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29
30#include <sys/cdefs.h>
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

--- 14 unchanged lines hidden (view full) ---

23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29
30#include <sys/cdefs.h>
31__FBSDID("$FreeBSD: head/usr.bin/grep/util.c 211364 2010-08-15 22:15:04Z gabor $");
31__FBSDID("$FreeBSD: head/usr.bin/grep/util.c 211463 2010-08-18 17:40:10Z gabor $");
32
33#include <sys/stat.h>
34#include <sys/types.h>
35
36#include <ctype.h>
37#include <err.h>
38#include <errno.h>
39#include <fnmatch.h>

--- 139 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);
32
33#include <sys/stat.h>
34#include <sys/types.h>
35
36#include <ctype.h>
37#include <err.h>
38#include <errno.h>
39#include <fnmatch.h>

--- 139 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 ---