Discussion:
[ast-developers] grep -C (context) not working
Wendy Lin
2013-04-13 14:05:17 UTC
Permalink
Dear ast-devel,

the grep -C from the latest ast-ksh (2013-04-09) does not work
compared to GNU grep 2.14

In GNU grep 2.14 I get this for the context option:

seq 200 >"????"
ksh -c '/usr/bin/grep --context=2 51 <"????"'
49
50
51
52
53
--
149
150
151
152
153

But I get this from grep from ast-ksh for the context option:

ksh -c 'builtin grep ; grep --context=2 51 <"????"'
51
151

Is this a bug or feature?

AFAIK the -C option in ast-ksh grep should work like this:
-C 2 gives 2 lines of context before and after the match
-C ,2 gives only 2 lines of context after the match
-C 2, gives only 2 lines of contetxt before the match

optionally AST grep should support these two long options for GNU grep
compatibility:

--before-context=NUM print NUM lines of leading context
--after-context=NUM print NUM lines of trailing context

What do you think?

Wendy
Wendy Lin
2013-04-16 09:05:10 UTC
Permalink
Post by Wendy Lin
Dear ast-devel,
the grep -C from the latest ast-ksh (2013-04-09) does not work
compared to GNU grep 2.14
seq 200 >"????"
ksh -c '/usr/bin/grep --context=2 51 <"????"'
49
50
51
52
53
--
149
150
151
152
153
ksh -c 'builtin grep ; grep --context=2 51 <"????"'
51
151
Is this a bug or feature?
-C 2 gives 2 lines of context before and after the match
-C ,2 gives only 2 lines of context after the match
-C 2, gives only 2 lines of contetxt before the match
optionally AST grep should support these two long options for GNU grep
--before-context=NUM print NUM lines of leading context
--after-context=NUM print NUM lines of trailing context
What do you think?
Was the bug report received?
Post by Wendy Lin
Wendy
Wendy
Glenn Fowler
2013-04-16 13:04:19 UTC
Permalink
thanks for the report
the work adding -C was apparently interrupted a while back
its on the todo list

this is not an easy fix for ast grep because the fast inner loop matches
buffers containing multiple lines and does not parse line structure until
a match is found

the only time single lines are matched is when lines cross buffer boundaries

mmap()ing the entire file (topic under discussion) would make it easy but
would not help the very common input from pipe case
Post by Wendy Lin
Post by Wendy Lin
Dear ast-devel,
the grep -C from the latest ast-ksh (2013-04-09) does not work
compared to GNU grep 2.14
seq 200 >"????????"
ksh -c '/usr/bin/grep --context=2 51 <"????????"'
49
50
51
52
53
--
149
150
151
152
153
ksh -c 'builtin grep ; grep --context=2 51 <"????????"'
51
151
Is this a bug or feature?
-C 2 gives 2 lines of context before and after the match
-C ,2 gives only 2 lines of context after the match
-C 2, gives only 2 lines of contetxt before the match
optionally AST grep should support these two long options for GNU grep
--before-context=NUM print NUM lines of leading context
--after-context=NUM print NUM lines of trailing context
What do you think?
Was the bug report received?
Post by Wendy Lin
Wendy
Wendy
_______________________________________________
ast-developers mailing list
ast-developers at lists.research.att.com
http://lists.research.att.com/mailman/listinfo/ast-developers
Wendy Lin
2013-04-19 17:05:40 UTC
Permalink
Post by Glenn Fowler
thanks for the report
the work adding -C was apparently interrupted a while back
its on the todo list
this is not an easy fix for ast grep because the fast inner loop matches
buffers containing multiple lines and does not parse line structure until
a match is found
the only time single lines are matched is when lines cross buffer boundaries
mmap()ing the entire file (topic under discussion) would make it easy but
would not help the very common input from pipe case
Post by Wendy Lin
Post by Wendy Lin
Dear ast-devel,
the grep -C from the latest ast-ksh (2013-04-09) does not work
compared to GNU grep 2.14
seq 200 >"????"
ksh -c '/usr/bin/grep --context=2 51 <"????"'
49
50
51
52
53
--
149
150
151
152
153
ksh -c 'builtin grep ; grep --context=2 51 <"????"'
51
151
Is this a bug or feature?
-C 2 gives 2 lines of context before and after the match
-C ,2 gives only 2 lines of context after the match
-C 2, gives only 2 lines of contetxt before the match
optionally AST grep should support these two long options for GNU grep
--before-context=NUM print NUM lines of leading context
--after-context=NUM print NUM lines of trailing context
What do you think?
Was the bug report received?
Post by Wendy Lin
Wendy
Glenn, how long will it take to get grep -C implemented?

Wendy
Glenn Fowler
2013-04-19 18:55:00 UTC
Permalink
this is on the todo list

there are some internal discussions on interactions with
sfreserve() and the possibilty of supporting multiple
active sfreserve() buffers

the idea being that if sfreserve() is mmap()ing one could
keep a chain of mmap() blocks large enough to cover a
context-sized window scrolling through the file with
data copies limited to lines that cross buffer boundaries

there's even some thought about generalizing the
lines-crossing-buffer-boundaries code (which is always a pain
to get right and is duplicated too many places in ast code)
for some of the contiguous string api's like regnexec()

all in the hopes of doing it the right way
Post by Wendy Lin
Post by Glenn Fowler
thanks for the report
the work adding -C was apparently interrupted a while back
its on the todo list
this is not an easy fix for ast grep because the fast inner loop matches
buffers containing multiple lines and does not parse line structure until
a match is found
the only time single lines are matched is when lines cross buffer boundaries
mmap()ing the entire file (topic under discussion) would make it easy but
would not help the very common input from pipe case
Post by Wendy Lin
Post by Wendy Lin
Dear ast-devel,
the grep -C from the latest ast-ksh (2013-04-09) does not work
compared to GNU grep 2.14
seq 200 >"????????"
ksh -c '/usr/bin/grep --context=2 51 <"????????"'
49
50
51
52
53
--
149
150
151
152
153
ksh -c 'builtin grep ; grep --context=2 51 <"????????"'
51
151
Is this a bug or feature?
-C 2 gives 2 lines of context before and after the match
-C ,2 gives only 2 lines of context after the match
-C 2, gives only 2 lines of contetxt before the match
optionally AST grep should support these two long options for GNU grep
--before-context=NUM print NUM lines of leading context
--after-context=NUM print NUM lines of trailing context
What do you think?
Was the bug report received?
Post by Wendy Lin
Wendy
Glenn, how long will it take to get grep -C implemented?
Wendy
Wendy Lin
2013-07-10 07:11:59 UTC
Permalink
Post by Glenn Fowler
this is on the todo list
there are some internal discussions on interactions with
sfreserve() and the possibilty of supporting multiple
active sfreserve() buffers
the idea being that if sfreserve() is mmap()ing one could
keep a chain of mmap() blocks large enough to cover a
context-sized window scrolling through the file with
data copies limited to lines that cross buffer boundaries
there's even some thought about generalizing the
lines-crossing-buffer-boundaries code (which is always a pain
to get right and is duplicated too many places in ast code)
for some of the contiguous string api's like regnexec()
all in the hopes of doing it the right way
grep -C works now, but have the proposed api changes be implemented?
Post by Glenn Fowler
Post by Wendy Lin
Post by Glenn Fowler
thanks for the report
the work adding -C was apparently interrupted a while back
its on the todo list
this is not an easy fix for ast grep because the fast inner loop matches
buffers containing multiple lines and does not parse line structure until
a match is found
the only time single lines are matched is when lines cross buffer boundaries
mmap()ing the entire file (topic under discussion) would make it easy but
would not help the very common input from pipe case
Post by Wendy Lin
Post by Wendy Lin
Dear ast-devel,
the grep -C from the latest ast-ksh (2013-04-09) does not work
compared to GNU grep 2.14
seq 200 >"????"
ksh -c '/usr/bin/grep --context=2 51 <"????"'
49
50
51
52
53
--
149
150
151
152
153
ksh -c 'builtin grep ; grep --context=2 51 <"????"'
51
151
Is this a bug or feature?
-C 2 gives 2 lines of context before and after the match
-C ,2 gives only 2 lines of context after the match
-C 2, gives only 2 lines of contetxt before the match
optionally AST grep should support these two long options for GNU grep
--before-context=NUM print NUM lines of leading context
--after-context=NUM print NUM lines of trailing context
What do you think?
Was the bug report received?
Post by Wendy Lin
Wendy
Glenn, how long will it take to get grep -C implemented?
Wendy
Wendy
Glenn Fowler
2013-07-18 14:34:51 UTC
Permalink
if you look at the source you'll see the beginnings of an api in
src/lib/libcmd
context.h
context.c
right now its only used by grep and is private to libcmd
if it were to be used by other ast utils it would probably move to libast
Post by Wendy Lin
Post by Glenn Fowler
this is on the todo list
there are some internal discussions on interactions with
sfreserve() and the possibilty of supporting multiple
active sfreserve() buffers
the idea being that if sfreserve() is mmap()ing one could
keep a chain of mmap() blocks large enough to cover a
context-sized window scrolling through the file with
data copies limited to lines that cross buffer boundaries
there's even some thought about generalizing the
lines-crossing-buffer-boundaries code (which is always a pain
to get right and is duplicated too many places in ast code)
for some of the contiguous string api's like regnexec()
all in the hopes of doing it the right way
grep -C works now, but have the proposed api changes be implemented?
Post by Glenn Fowler
Post by Wendy Lin
Post by Glenn Fowler
thanks for the report
the work adding -C was apparently interrupted a while back
its on the todo list
this is not an easy fix for ast grep because the fast inner loop matches
buffers containing multiple lines and does not parse line structure until
a match is found
the only time single lines are matched is when lines cross buffer boundaries
mmap()ing the entire file (topic under discussion) would make it easy but
would not help the very common input from pipe case
Post by Wendy Lin
Post by Wendy Lin
Dear ast-devel,
the grep -C from the latest ast-ksh (2013-04-09) does not work
compared to GNU grep 2.14
seq 200 >"????????"
ksh -c '/usr/bin/grep --context=2 51 <"????????"'
49
50
51
52
53
--
149
150
151
152
153
ksh -c 'builtin grep ; grep --context=2 51 <"????????"'
51
151
Is this a bug or feature?
-C 2 gives 2 lines of context before and after the match
-C ,2 gives only 2 lines of context after the match
-C 2, gives only 2 lines of contetxt before the match
optionally AST grep should support these two long options for GNU grep
--before-context=NUM print NUM lines of leading context
--after-context=NUM print NUM lines of trailing context
What do you think?
Was the bug report received?
Post by Wendy Lin
Wendy
Glenn, how long will it take to get grep -C implemented?
Wendy
Wendy
Loading...