[freeciv-ai] Re: logging and ai explorer improvement patch
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
On Mon, 19 Aug 2002 rf13@xxxxxxxxxxxxxxxxxxxxxx wrote:
> On Sat, Aug 17, 2002 at 11:00:55AM +0000, Per I. Mathisen wrote:
> > This patch primarily improves logging by providing and using some logging
> > macros (defined in aitools.h).
>
> > These are rather inflexible in that they don't take varargs (ie no
> > "%s %d" messages),
>
> freelog is also a macro and got this right. Is there a reason which I
> overlooked?
>
> #define unitlog(level, punit, args...) do { \
> if ((level) != LOG_DEBUG) { \
> real_unitlog((level), (punit), args); } \
> } while(FALSE)
Yes, apparently the vararg cannot have zero arguments passed to it, so
either you require there to be at least one % thing inside the string, or
you include the last parameter in the vararg (as done above). We can't do
the latter in my patch because the last parameter in the macro definition
isn't the last parameter in the call in the macro implementation.
+#define UNIT_LOG(level, punit, msg) \
+ freelog(MIN(LOGLEVEL_UNIT, level), \
+ "%s's %s[%d] (%d,%d)->(%d,%d) " ##msg##, \
+ unit_owner(punit)->name, unit_type(punit)->name, \
+ punit->id, punit->x, punit->y, \
+ punit->goto_dest_x, punit->goto_dest_y);
We could fix this by adding string expansion, but I am not convinced it
would be worth it.
Yours
Per
|
|