C Macro question
David Kramer
david at thekramers.net
Sun Jun 16 08:51:17 EDT 2002
On Sat, 15 Jun 2002, Frank Ramsay wrote:
> I'm horrible with Macros in C does anyone know how to make a macro that w
>
> Now I have a ton of these so altering them manually would take much longer
> than I have. Does anyone know of a macro or function that takes var args for
> printf and re-formats them to a more logfile friendly format?
>
> ie
> printerror("file %d not found.\n",filename);
>
> but what I want is something like this is this
>
> Sat Jun 15 11:44:02 - ERROR: file greeting.vox not found.
Maybe the answer is not to use a C macro to change how the calls to
printerror() looks, but to use some tool (like perl) to automatically
change your source code to what you want as a one-time process.
Let's say you write your own error function lik Jerry suggested. The you
can do something like this (but put it all on one line):
find . -name '*.c' | xargs perl -p -i.bak -e
's/printerror\(\"file %d not found\.\\n\",(.*?)\);
/myprinterror("file %s not found",$1);/g'
and let myprinterror determine the formatting, so you can change it
anytime you want by just changing that one function.
Does that make sense?
----------------------------------------------------------------------------
DDDD David Kramer david at thekramers.net http://thekramers.net
DK KD
DKK D You are so clueless that if we stripped you naked, soaked you in
DK KD clue musk, and dropped you into a field full of horny clues, You
DDDD still would not have a clue.
More information about the Discuss
mailing list