Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!bloom-beacon!gatech!udel!princeton!phoenix!pupthy2!lgy From: lgy@pupthy2.PRINCETON.EDU (Larry Yaffe) Newsgroups: comp.unix.wizards Subject: Re: #defines with variable # arguments Summary: m4 suggestion: close, but not perfect Message-ID: <2918@phoenix.Princeton.EDU> Date: 16 May 88 00:53:10 GMT References: <2855@phoenix.Princeton.EDU+ <2633@tekcrl.TEK.COM> <979@cresswell.quintus.UUCP> <980@cresswell.quintus.UUCP> Sender: news@phoenix.Princeton.EDU Reply-To: lgy@pupthy2.PRINCETON.EDU (Larry Yaffe) Distribution: na Organization: Physics Dept, Princeton Univ Lines: 31 Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!bloom-beacon!gatech!udel!princeton!phoenix!pupthy2!lgy From: lgy@pupthy2.PRINCETON.EDU (Larry Yaffe) Newsgroups: comp.unix.wizards Subject: Re: #defines with variable # arguments Summary: m4 suggestion: close, but not perfect Message-ID: <2918@phoenix.Princeton.EDU> Date: 16 May 88 00:53:10 GMT References: <2855@phoenix.Princeton.EDU+ <2633@tekcrl.TEK.COM> <979@cresswell.quintus.UUCP> <980@cresswell.quintus.UUCP> Sender: news@phoenix.Princeton.EDU Reply-To: lgy@pupthy2.PRINCETON.EDU (Larry Yaffe) Distribution: na Organization: Physics Dept, Princeton Univ In article <980@cresswell.quintus.UUCP> ok@quintus.UUCP (Richard A. O'Keefe) writes: [Using m4 to process macros with variable # arguments] -I should substantiate that. - -If you just want to make the BSD sprintf() look as though it returned an -integer, do - -cat >sprintflen.m4 <<'EOF' -define(sprintf,`strlen(`sprintf'($*))')dnl -EOF This was definitely a helpful suggestion - not being overly familiar with m4, I hadn't considered using it. However, the suggested m4 scripts suffer from two small problems: Whitespace between the "sprintf" and the following argument list must first be removed in order for m4 to process the arguments correctly. This is easily accomplished using 'sed'. Argument lists containing unmatched quoted parentheses, such as, sprintf (str,"= ("), produce horrible garbage. This is a real occurence in some of the source I'm dealing with. (However, having to edit a handful of special sprintf's by hand is a big improvement over having to edit hundreds.) ------------------------------------------------------------------------ Laurence G. Yaffe Internet: lgy@pupthy.princeton.edu Department of Physics Bitnet: lgy@pucc Princeton University UUCP: ...!princeton!pupthy!lgy PO Box 708, Princeton NJ 08544