From owner-freebsd-questions@FreeBSD.ORG Wed Jun 17 00:54:42 2009 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id EBE1A1065714 for ; Wed, 17 Jun 2009 00:54:41 +0000 (UTC) (envelope-from kline@thought.org) Received: from aristotle.thought.org (aristotle.thought.org [209.180.213.210]) by mx1.freebsd.org (Postfix) with ESMTP id 810188FC20 for ; Wed, 17 Jun 2009 00:54:41 +0000 (UTC) (envelope-from kline@thought.org) Received: from thought.org (tao.thought.org [10.47.0.250]) (authenticated bits=0) by aristotle.thought.org (8.14.2/8.14.2) with ESMTP id n5H0sabk029765; Tue, 16 Jun 2009 17:54:37 -0700 (PDT) (envelope-from kline@thought.org) Received: by thought.org (nbSMTP-1.00) for uid 1002 kline@thought.org; Tue, 16 Jun 2009 17:54:36 -0700 (PDT) Date: Tue, 16 Jun 2009 17:54:36 -0700 From: Gary Kline To: Jeffrey Goldberg Message-ID: <20090617005435.GA42176@thought.org> References: <20090616012114.GA38011@thought.org> <200906151857.45945.mel.flynn+fbsd.questions@mailing.thruhere.net> <20090616153040.GA40540@thought.org> <20090616170244.GA40934@thought.org> <57E07CDA-AA9E-4A8F-91BC-3BF90177CA3A@goldmark.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <57E07CDA-AA9E-4A8F-91BC-3BF90177CA3A@goldmark.org> User-Agent: Mutt/1.4.2.3i X-Organization: Thought Unlimited. Public service Unix since 1986. X-Of_Interest: With 22++ years of service to the Unix community. X-Spam-Status: No, score=-4.4 required=3.6 tests=ALL_TRUSTED,BAYES_00 autolearn=ham version=3.2.3 X-Spam-Checker-Version: SpamAssassin 3.2.3 (2007-08-08) on aristotle.thought.org Cc: FreeBSD Questions Subject: Re: feedback, comments on this php-delimiter scrubbing program? X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 17 Jun 2009 00:54:42 -0000 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. gary > > (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 http://www.goldmark.org/jeff/ > > > -- Gary Kline kline@thought.org http://www.thought.org Public Service Unix http://jottings.thought.org http://transfinite.thought.org For FBSD list: http://transfinite.thought.org/slicejourney.php The 4.98a release of Jottings: http://jottings.thought.org/index.php