From owner-freebsd-questions@FreeBSD.ORG Fri Aug 27 19:13:32 2004 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 51C3516A4CE for ; Fri, 27 Aug 2004 19:13:32 +0000 (GMT) Received: from sccrmhc11.comcast.net (sccrmhc11.comcast.net [204.127.202.55]) by mx1.FreeBSD.org (Postfix) with ESMTP id EF1E543D2F for ; Fri, 27 Aug 2004 19:13:31 +0000 (GMT) (envelope-from cristjc@comcast.net) Received: from blossom.cjclark.org (c-24-6-187-112.client.comcast.net[24.6.187.112]) by comcast.net (sccrmhc11) with ESMTP id <20040827191331011008cuoqe>; Fri, 27 Aug 2004 19:13:31 +0000 Received: from blossom.cjclark.org (localhost. [127.0.0.1]) by blossom.cjclark.org (8.12.11/8.12.8) with ESMTP id i7RJDPZm059986 for ; Fri, 27 Aug 2004 12:13:25 -0700 (PDT) (envelope-from cristjc@comcast.net) Received: (from cjc@localhost) by blossom.cjclark.org (8.12.11/8.12.11/Submit) id i7RJDOF8059985 for questions@freebsd.org; Fri, 27 Aug 2004 12:13:24 -0700 (PDT) (envelope-from cristjc@comcast.net) X-Authentication-Warning: blossom.cjclark.org: cjc set sender to cristjc@comcast.net using -f Date: Fri, 27 Aug 2004 12:13:24 -0700 From: "Crist J. Clark" To: questions@freebsd.org Message-ID: <20040827191324.GA59475@blossom.cjclark.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4.2.1i X-URL: http://people.freebsd.org/~cjc/ Subject: m4 Problems X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: cjclark@alum.mit.edu List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 27 Aug 2004 19:13:32 -0000 I want to do something that I _think_ should be rather simple within m4(1). I want to test if a macro value has been set. If it is set, I want to modify it and continue. If it is not set, I want to produce an error message and bail out. However, it is not working. Here is an example of a test script, $ cat testerr.mc ifdef(`TEST', ``TEST' defined.', `TEST not defined.') ifdef(`TEST', define(`TEST', `NEW'TEST), errprint(`TEST not specified, exiting.') m4exit(1)) The value of `TEST' is TEST. Now I run it without "TEST" set, $ m4 testerr.mc TEST not defined. TEST not specified, exiting. $ echo $? 1 And it looks good. But now I try with "TEST" set, $ m4 -D TEST=test testerr.mc TEST defined. TEST not specified, exiting. $ echo $? 1 And it acts as if it is NOT set. It looks like the third argument of the second ifdef macro is getting evaluated even though the first argument is not set. So, I'll try this test script instead, ifdef(`TEST', ``TEST' defined.', `TEST not defined.') ifdef(`TEST', define(`TEST', `NEW'TEST), `errprint(`TEST not specified, exiting.') m4exit(1)') The value of `TEST' is TEST. And try the set case, $ m4 -D TEST=test testerr.mc TEST defined. The value of TEST is NEWtest. $ echo $? 0 And it works! OK, now check the case where it is not set, $ m4 testerr.mc TEST not defined. The value of TEST is NEWTEST. $ echo $? 0 So now this case doesn't work. What quoting scheme do I need to use here to get this to work correctly? Or is there some other trick to it? Can someone explain m4(1)'s order of evaluation and what actually gets evaluated in each case? -- Crist J. Clark | cjclark@alum.mit.edu | cjclark@jhu.edu http://people.freebsd.org/~cjc/ | cjc@freebsd.org