I wrote some testcase on a yellow-pad while on the bus-ride home.
I'll try and rework those notes into an email when I get time (possibly
tomorrow night).
The normal case that bugged me the most on the way home was a single
matching line.
That case works with the exception of one more case when to
print_if_needed. That case is when we have matches to print and we have
reached the EOF. (It's probably an obvious enough case that it would be
caught when programming the notes below, but I want to call it out just
to be sure.
--
Bob
On Tue, Jul 15, 2008 at 10:29 PM, Bill Ricker wrote:
We did some specs for new main loop.
I/O is slow
print rarely,
print late;
read early too!
temporarily assume:
prepopulate [q{},q{}]xB
requirement: print '--' unless first
side case: if stdout is autoflush, do so also
invariant: match is set iff there is a match in the buffer someplace
our buffer structure is:
a print buffer and B + A + 1 entries
(which are supposed to be line references to not copy)
and we will also include a prefix string
[[prefix(), \$_,] ... ]
struct of prefix() @TBD -- may include \$Filename as well as $., ':' or
'-'.
Defer output formatting to printbuf-appender
if in_matched_context, append shift of line buf onto printbuf
else discard shift of line buf
endif
append current_line to line buf
with prefix() struct or whatnot struct'ed with it
if the current_line matches
we set in_matched_context =true
and count_not_matched=0
else
++count_not_matched
and if count_not_matched == B
start print
else
## if(count_not_matched == (A + B + 1))
if(count_not_matched > (A + B + 1)) ## fix off by one
set_separator()
in_matched_context=0; # clear_matched()
end if
end if
###FLUSH BUFF THING -- no flush logic anymore.
we need the logic for when you shift onto the print buffer:
if match is true, we print only iff we can start print
## DROPPED the print flag (formerly thought separate )
## also DROPPED when a+b+1, stop_print()
concern: if we have match, match, match ...
concern: if we have match, line, match, line, match ...
did we solve that?
if EOF (and in_matched_context) , shift everything to print buffer and
print
_______________________________________________
Boston-pm mailing list
[email protected] <mailto:[email protected]>
<mailto:[email protected]>
http://mail.pm.org/mailman/listinfo/boston-pm
<http://mail.pm.org/mailman/listinfo/boston-pm>
<http://mail.pm.org/mailman/listinfo/boston-pm>
_______________________________________________
Boston-pm mailing list
[email protected]
http://mail.pm.org/mailman/listinfo/boston-pm