beaucham@uxh.cso.uiuc.edu (James Beauchamp) (06/20/91)
I have many occurences of 'printf(' which I would like to replace with 'fprintf(stderr,' in my C program. Is there a way to do this #define? #define printf( fprintf(sterr, definitely doesn't parse. Jim Beauchamp j-beauchamp@uiuc.edu ----------------------------- Everything should be possible (in C)
ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe) (06/20/91)
In article <1991Jun20.051827.23428@ux1.cso.uiuc.edu>, beaucham@uxh.cso.uiuc.edu (James Beauchamp) writes: > I have many occurences of 'printf(' which I would like to replace with > 'fprintf(stderr,' in my C program. Why not use a text editor? I'm serious. Using ed(1): 1,$s/printf(/fprintf(stderr, /g In ex(1) or vi(1), 1,$s/printf(/fprintf(stderr, /gc will ask you about each change. This is even easier to do in Emacs-like editors, such as micro-Emacs, Jove, and GNU Emacs. > #define printf( fprintf(sterr, > > definitely doesn't parse. Neither it should! Sending a boy on a man's errand, shameful! You might want to consider something like #ifdef OldStyle #define errlog stdout #else #define errlog stderr #endif replacing printf(...) by fprintf(errlog,...). But you have a very strange program if there are "many" things you want to write to stderr not _nothing_ you want to write to stdout. -- I agree with Jim Giles about many of the deficiencies of present UNIX.
dkeisen@leland.Stanford.EDU (Dave Eisen) (06/20/91)
In article <1991Jun20.051827.23428@ux1.cso.uiuc.edu> J-Beauchamp@uiuc.edu writes: >I have many occurences of 'printf(' which I would like to replace with >'fprintf(stderr,' in my C program. Is there a way to do this #define? > >#define printf( fprintf(sterr, > I agree with another poster that the best way to do this is with a text editor. Still, there is a solution along the lines of what you tried. No, you can't define printf to be fprintf(stderr. But you can do the following: #define printf fprintf_stderr int fprintf_stderr (const char *fmt, ...) { va_list args; int ret; va_start (args, fmt) ret = vfprintf (stderr, fmt, args); va_end (args); return ret; }
pckim@unisql.UUCP (Pyung-Chul Kim) (06/20/91)
In article <1991Jun20.051827.23428@ux1.cso.uiuc.edu> J-Beauchamp@uiuc.edu writes: >I have many occurences of 'printf(' which I would like to replace with >'fprintf(stderr,' in my C program. Is there a way to do this #define? > >#define printf( fprintf(sterr, > Why don't you use a shell program like following: % chngprintf * */* */*/* .... (specify all files you want to change) % cat chngprintf #!/bin/csh -f foreach f ($argv) echo "Editing file: $f" ed $f << END > /dev/null 1,\$s/printf(/fprintf(stderr,/g w q END end I hope it helps -- Pyung-Chul Kim UniSQL, Inc. 9390 Research Blvd., Kaleido II, Suite 220, Austin, TX 78759 Internet: execu!sequoia!unisql!pckim@cs.utexas.edu UUCP: {uunet, cs.utexas.edu!execu}!sequoia!unisql!pckim TEL: (512)343-7297 Ext. 332 FAX: (512)343-7383
Dave.Giunti@p0.f217.n914.z8.RBBS-NET.ORG (Dave Giunti) (06/24/91)
reply to: >From: beaucham@uxh.cso.uiuc.edu (James Beauchamp) >Date: 20 Jun 91 05:18:27 GMT >Organization: University of Illinois at Urbana >Message-ID: <1991Jun20.051827.23428@ux1.cso.uiuc.edu> >Newsgroups: comp.lang.c JB> JB>I have many occurences of 'printf(' which I would like to replace with JB>'fprintf(stderr,' in my C program. Is there a way to do this #define? JB> JB>#define printf( fprintf(sterr, JB> JB>definitely doesn't parse. Hi Jim, I just tried to redefine some curses calls in this manner; unfortunatly you can't use a single '(' in a #define : it's a couples only dance. And you can't do a variable parameter pass inside the finger-nails. Catch 22... To try and get a little more performence out of Gnu Chess I was willing to do a little thinking. Here is a solution I found that worked: #ifdef MSDOS /* pre #defined by Microsoft C*/ #define printz fprintf /* curses to whatever I needed to test */ #define STDER stderr, /* or any other stream */ #else #define STDER /* a null declaration */ #endif then something like printz( STDER "this could go anywhere"); /* can have meaning */ It might be more usefull to have a couple of classes of defined output for various chanels. I should point out that I didn't get faster output from this and it bloated the code so I junked it... but I am almost positive I got the comma past the troll of defines. Dave at Fidonet 1:125/98 (Uhura) BTW Is anyone else out there hacking on Gnu Chess, either inside or outside MS DOS? * EZ 1.33 * -- Dave Giunti - via RBBS-NET node 8:914/201 INTERNET: Dave.Giunti@p0.f217.n914.z8.RBBS-NET.ORG