[rrd-developers] [PATCH] Suggestion for API extension (rrd_dump)
Florian Forster
rrdtool at nospam.verplant.org
Mon Aug 17 11:44:28 CEST 2009
Hi,
On Mon, Aug 17, 2009 at 12:21:02AM +0200, Tobias Oetiker wrote:
> repeating the same string .... hmmm
>
> + cb("<!DOCTYPE rrd SYSTEM \"http://oss.oetiker.ch/rrdtool/rrdtool.dtd\">\n",
> + strlen("<!DOCTYPE rrd SYSTEM \"http://oss.oetiker.ch/rrdtool/rrdtool.dtd\">\n"), user);
>
> also the combination
>
> snprintf(somestring_buf, 255, ...)
> cb(somestring_buf, strlen(somestring_buf), ...)
>
> apears about 1000 times ...
> how about making a function or at least a #define to make this look
> a bit less repetitive ...
What about this:
-- 8< --
#define CBPUTS(cb_func, user, str) \
(*(cb_func)) (str, strlen (str), (user))
#define CBPRINTF(cb_func, user, ...) do { \
char buffer[256]; \
snprintf (buffer, sizeof (buffer), __VA_ARGS__); \
buffer[sizeof (buffer) - 1] = 0; \
CBPUTS (cb_func, user, buffer); \
} while (0)
-- >8 --
If you follow up with something like
$ sed -i -e 's/fprintf\s*(out_file,/CBPRINTF (cb, user,/'
I bet 80% of the work is done.
The code will then look somewhat like this:
-- 8< --
CBPRINTF (cb, user, "\t<step> %lu </step> <!-- Seconds -->\n",
rrd.stat_head->pdp_step);
-- >8 --
Regards,
-octo
--
Florian octo Forster
Hacker in training
GnuPG: 0x91523C3D
http://verplant.org/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://lists.oetiker.ch/pipermail/rrd-developers/attachments/20090817/aa2d8087/attachment-0001.pgp
More information about the rrd-developers
mailing list