feedback, comments on this php-delimiter scrubbing program?

Gary Kline kline at
Wed Jun 17 00:54:42 UTC 2009

On Tue, Jun 16, 2009 at 06:32:43PM -0500, Jeffrey Goldberg wrote:
> On Jun 16, 2009, at 12:02 PM, Gary Kline wrote:
> >	this works, but still gives a warning.  it's sloppy coding, but
> >	as a second version...
> You've got some superfluous tests for EOF in some places, and you may  
> also be missing some.
> Your approach has been to "look ahead" with an extra getc() when you  
> come across an interesting character.  I recommended that instead of  
> doing that you keep a variable "state" to keep track of where you are  
> (and have very recently been) instead of looking ahead.
> I haven't tried your code, but I suspect that it behaves incorrectly  
> with input
>   (1) that has a '<' as a final character
>   (2) that includes things like "<<<<?"
>   (3) that includes things like "??>"

	this is exactly why i asked here.  i've removed at least one of
	the EOF checks and will rewrite in my usual style of 

	while ((ch = getc(fp)) != EOF)

	as my next cut.  yes, i shamelessly cribbed this code from else.
	it originally deleted both C and C++ comments.  i think it was
	written in C# that i'm unfamiliar with.

	i'm most familiar with lokahead, not that familar with the STATE
	method.  when you have time could you say a few more words? or
	point me at a url?  ...i'm all but certain this kind of function
	has been invented and re-invented dozens of times. 

> There is a systematic (if a bit tedious) way to make sure that you  
> check every condition.  When you've worked enough on this, you can  
> peek at an answer which I've attached.

	you're right above with numbers two and three.  pretty sure that
	the first one passes.


> (For the rest of you, I know that it would be more efficient to make  
> the big switch on state instead of on input character, but for  
> pedagogical reasons I did it the other way around.  I deliberately  
> avoided other available tunings).
> The extensive comments in the code should make it clear what is going  
> on.  Once you understand the concepts here it should be very easy to  
> write code to do similar things in the future.
> -j
> -- 
> Jeffrey Goldberg              


 Gary Kline  kline at  Public Service Unix
       For FBSD list:
    The 4.98a release of Jottings:

More information about the freebsd-questions mailing list