From: Martin Mares Date: Wed, 5 Feb 2003 18:15:24 +0000 (+0000) Subject: Tried to use libm for calculating logarithmic frequencies of words, X-Git-Tag: holmes-import~1283 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=fa8903dc5bda17a564aa3348780a20e6df04fa11;p=libucw.git Tried to use libm for calculating logarithmic frequencies of words, but ran into problems with function name collisions. Damn the C's flat namespace! Renamed our log to log_msg, but keep the original name as a macro expanding to the new one. Also renamed log2 (which is currently not used anywhere) to fls (find last set, akin to ffs). Introduced lib/math.h which is a wrapper around handling name collisions by clever macro tricks. --- diff --git a/lib/lib.h b/lib/lib.h index abd536d5..6ed45a9a 100644 --- a/lib/lib.h +++ b/lib/lib.h @@ -1,7 +1,7 @@ /* * Sherlock Library -- Miscellaneous Functions * - * (c) 1997--2001 Martin Mares + * (c) 1997--2003 Martin Mares * * This software may be freely distributed and used according to the terms * of the GNU Lesser General Public License. @@ -48,7 +48,8 @@ #define L_ERROR_R 'e' #define L_FATAL '!' /* die() */ -void log(unsigned int cat, const char *msg, ...) __attribute__((format(printf,2,3))); +void log_msg(unsigned int cat, const char *msg, ...) __attribute__((format(printf,2,3))); +#define log log_msg void die(byte *, ...) NONRET; void log_init(byte *); void log_file(byte *); @@ -102,7 +103,7 @@ int match_ct_patt(byte *, byte *); /* log2.c */ -int log2(u32); +int fls(u32); /* wordsplit.c */ diff --git a/lib/log.c b/lib/log.c index 3ab60eb4..3bf3d285 100644 --- a/lib/log.c +++ b/lib/log.c @@ -105,7 +105,7 @@ vlog(unsigned int cat, const char *msg, va_list args) } void -log(unsigned int cat, const char *msg, ...) +log_msg(unsigned int cat, const char *msg, ...) { va_list args; diff --git a/lib/log2.c b/lib/log2.c index a40ba069..08b27bcf 100644 --- a/lib/log2.c +++ b/lib/log2.c @@ -9,10 +9,8 @@ #include "lib/lib.h" -#undef log2 - int -log2(u32 x) +fls(u32 x) { uns l; diff --git a/lib/math.h b/lib/math.h new file mode 100644 index 00000000..4bd52b90 --- /dev/null +++ b/lib/math.h @@ -0,0 +1,16 @@ +/* + * Sherlock Library -- Stub for including math.h, avoiding name collisions + * + * (c) 2003 Martin Mares + * + * This software may be freely distributed and used according to the terms + * of the GNU Lesser General Public License. + */ + +#undef log +#define log libm_log +#define exception math_exception +#include +#undef log +#define log log_msg +#undef exception