#!/usr/bin/perl my $num = shift(@ARGV); print < */ #include "config.h" /* I could do that with variadic macros available: #define sdebug(me, s) fprintf(stderr, "[" me "] " s "\n") #define debug(me, s, ...) fprintf(stderr, "[" me "] " s "\n", __VA_ARGS__) Variadic macros are a C99 feature... Now just predefining stuff non-variadic for up to $num arguments. It's cumbersome to have them all with different names, though... */ #ifdef DEBUG #include EOT printdefs(1); print "#else\n"; printdefs(0); print "#endif\n"; sub printdefs { my $forreal = shift; my $i; while(++$i <= $num+1) { my @args, my $j; while(++$j < $i){ push(@args, chr(ord('a')+$j-1)); } unshift(@args, '') if(@args); print ' #define debug'.($i > 1 ? ($i-1) : '').'(s'; print join(', ', @args).') '; if($forreal){ print 'fprintf(stderr, "[" __FILE__ ":%i] " s "\n", __LINE__'.join(', ', @args).")\n"; } else{ print "{}\n"; } } }