Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!bloom-beacon!think!ames!amdahl!sri-unix!quintus!ok From: ok@quintus.UUCP (Richard A. O'Keefe) Newsgroups: comp.unix.wizards Subject: Re: #defines with variable # arguments Summary: here's m4 code Message-ID: <980@cresswell.quintus.UUCP> Date: 15 May 88 09:22:31 GMT References: <2855@phoenix.Princeton.EDU+ <2633@tekcrl.TEK.COM> <979@cresswell.quintus.UUCP> Distribution: na Organization: Quintus Computer Systems, Mountain View, CA Lines: 25 In article <979@cresswell.quintus.UUCP>, ok@quintus.UUCP (Richard A. O'Keefe) writes: > What I suggest is a one-time conversion: > sprintf(S,F) -> sprintf0(S,F) > sprintf(S,F,A) -> sprintf1(S,F,A) > ... > sprintf(S,F,A,B,C,D,E,F)-> sprintf6(S,F,A,B,C,D,E,F) > however many you need. This is easy enough to do with m4. I should substantiate that. cat >sprintf.m4 <<'EOF' define(sprintf,``sprintf'eval($#-2)($*)')dnl EOF This uses $# and $* which are in the System V and PD versions, but not in the BSD version, so you may have to do your conversion on System V. All it takes is m4 sprintf.m4 original.c >converted.c 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