From owner-freebsd-questions@FreeBSD.ORG Tue Jun 16 21:02:56 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 01BBA1065679 for ; Tue, 16 Jun 2009 21:02:56 +0000 (UTC) (envelope-from jeffrey@goldmark.org) Received: from out1.smtp.messagingengine.com (out1.smtp.messagingengine.com [66.111.4.25]) by mx1.freebsd.org (Postfix) with ESMTP id C9C918FC13 for ; Tue, 16 Jun 2009 21:02:55 +0000 (UTC) (envelope-from jeffrey@goldmark.org) Received: from compute1.internal (compute1.internal [10.202.2.41]) by out1.messagingengine.com (Postfix) with ESMTP id 5CC3236084D; Tue, 16 Jun 2009 17:02:55 -0400 (EDT) Received: from heartbeat1.messagingengine.com ([10.202.2.160]) by compute1.internal (MEProxy); Tue, 16 Jun 2009 17:02:55 -0400 X-Sasl-enc: 3fP0E5F7tg59dq+OfCM9XuNFmki+39nP32AMpVRegfRV 1245186175 Received: from hagrid.ewd.goldmark.org (n114.ewd.goldmark.org [72.64.118.114]) by mail.messagingengine.com (Postfix) with ESMTPSA id C3DCE16976; Tue, 16 Jun 2009 17:02:54 -0400 (EDT) Message-Id: From: Jeffrey Goldberg To: Gary Kline In-Reply-To: <20090616153040.GA40540@thought.org> Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit Mime-Version: 1.0 (Apple Message framework v935.3) Date: Tue, 16 Jun 2009 16:02:52 -0500 References: <20090616012114.GA38011@thought.org> <200906151857.45945.mel.flynn+fbsd.questions@mailing.thruhere.net> <20090616153040.GA40540@thought.org> X-Mailer: Apple Mail (2.935.3) 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: Tue, 16 Jun 2009 21:02:56 -0000 On Jun 16, 2009, at 10:30 AM, Gary Kline wrote: > I thought my initial getchar() != EOF would handle that. > But then there's that do-forever loop. As I said, the most common problem people had was failing to check of EOF in all the places it could occur, and so looping forever. Do not rely on the input being well formed. > I remember Jeffrey's > post and tried a case 'EOF' or case '-1'; thar gives me > compiler errors. Look at the man page for getchar() paying close attention to the type of what it returns. >> You should really take the pointers from Jeffrey Goldberg and >> record states >> and decide based on the state, rather then inlined switch >> statements, if only >> for readability. Even for a very simple task, the logic of your code is very very hard to read. Clarify the logic (using the idea of a "state") and you will find that this can be programmed very simply. -j -- Jeffrey Goldberg http://www.goldmark.org/jeff/