Boston Linux & Unix (BLU) Home | Calendar | Mail Lists | List Archives | Desktop SIG | Hardware Hacking SIG
Wiki | Flickr | PicasaWeb | Video | Maps & Directions | Installfests | Keysignings
Linux Cafe | Meeting Notes | Linux Links | Bling | About BLU

BLU Discuss list archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

C Macro question



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.







BLU is a member of BostonUserGroups
BLU is a member of BostonUserGroups
We also thank MIT for the use of their facilities.

Valid HTML 4.01! Valid CSS!



Boston Linux & Unix / webmaster@blu.org