Changeset 834
- Timestamp:
- 05/08/07 21:53:01 (2 years ago)
- Files:
-
- 1.8.3/branches/experimental/hdrs/game.h (modified) (1 diff)
- 1.8.3/branches/experimental/src/Makefile.in (modified) (3 diffs)
- 1.8.3/branches/experimental/src/funmath.c (modified) (3 diffs)
- 1.8.3/branches/experimental/src/game.c (modified) (3 diffs)
- 1.8.3/branches/experimental/src/lmath.c (added)
- 1.8.3/branches/experimental/src/lmath.gperf (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
1.8.3/branches/experimental/hdrs/game.h
r833 r834 15 15 /* hash table stuff */ 16 16 extern void init_func_hashtab(void); /* eval.c */ 17 extern void init_math_hashtab(void); /* funmath.c */18 17 extern void init_aname_table(void); /* atr_tab.c */ 19 18 extern void init_flagspaces(void); /* flags.c */ 1.8.3/branches/experimental/src/Makefile.in
r832 r834 151 151 htmltab.c: htmltab.gperf 152 152 gperf --output-file htmltab.c htmltab.gperf 153 154 lmath.c: lmath.gperf 155 gperf --output-file lmath.c lmath.gperf 153 156 154 157 etags: … … 862 865 funmath.o: ../options.h 863 866 funmath.o: ../hdrs/mushtype.h 864 funmath.o: ../hdrs/htab.h865 867 funmath.o: ../hdrs/externs.h 866 868 funmath.o: ../hdrs/compile.h … … 875 877 funmath.o: ../hdrs/sort.h 876 878 funmath.o: ../hdrs/parse.h 879 funmath.o: lmath.c 877 880 funmisc.o: ../hdrs/copyrite.h 878 881 funmisc.o: ../config.h 1.8.3/branches/experimental/src/funmath.c
r807 r834 17 17 #include "sort.h" 18 18 #include "parse.h" 19 #include "htab.h"20 19 #include "confmagic.h" 21 20 … … 36 35 static NVAL find_median(NVAL *, int); 37 36 38 /** Declaration macro for math functions */39 #define MATH_FUNC(func) static void func(char **ptr, int nptr, char *buff, char **bp)40 41 /** Prototype macro for math functions */42 #define MATH_PROTO(func) static void func (char **ptr, int nptr, char *buff, char **bp)43 44 HASHTAB htab_math; /**< Math function hash table */45 46 /** A math function. */47 typedef struct {48 const char *name; /**< Name of the function. */49 void (*func) (char **, int, char *, char **); /**< Pointer to function code. */50 } MATH;51 52 static void math_hash_insert(const char *, MATH *);53 static MATH *math_hash_lookup(char *);54 37 static NVAL angle_to_rad(NVAL angle, const char *from); 55 38 static NVAL rad_to_angle(NVAL angle, const char *to); 56 39 static double frac(double v, double *RESTRICT n, double *RESTRICT d, 57 40 double error); 58 void init_math_hashtab(void);59 41 60 42 extern int format_long(long n, char *buff, char **bp, int maxlen, int base); 61 43 62 MATH_PROTO(math_add); 63 MATH_PROTO(math_sub); 64 MATH_PROTO(math_mul); 65 MATH_PROTO(math_div); 66 MATH_PROTO(math_floordiv); 67 MATH_PROTO(math_remainder); 68 MATH_PROTO(math_modulo); 69 MATH_PROTO(math_min); 70 MATH_PROTO(math_max); 71 MATH_PROTO(math_and); 72 MATH_PROTO(math_nand); 73 MATH_PROTO(math_or); 74 MATH_PROTO(math_nor); 75 MATH_PROTO(math_xor); 76 MATH_PROTO(math_band); 77 MATH_PROTO(math_bor); 78 MATH_PROTO(math_bxor); 79 MATH_PROTO(math_fdiv); 80 MATH_PROTO(math_mean); 81 MATH_PROTO(math_median); 82 MATH_PROTO(math_stddev); 44 /* Generated by gperf */ 45 #include "lmath.c" 83 46 84 47 /* ARGSUSED */ … … 2343 2306 } 2344 2307 2345 /** A list of MATH_FUNCs that are suitable for lmath() */2346 MATH mlist[] = {2347 {"ADD", math_add}2348 ,2349 {"SUB", math_sub}2350 ,2351 {"MUL", math_mul}2352 ,2353 {"DIV", math_div}2354 ,2355 {"FLOORDIV", math_floordiv}2356 ,2357 {"MOD", math_modulo}2358 ,2359 {"MODULO", math_modulo}2360 ,2361 {"MODULUS", math_modulo}2362 ,2363 {"REMAINDER", math_remainder}2364 ,2365 {"MIN", math_min}2366 ,2367 {"MAX", math_max}2368 ,2369 {"AND", math_and}2370 ,2371 {"NAND", math_nand}2372 ,2373 {"OR", math_or}2374 ,2375 {"NOR", math_nor}2376 ,2377 {"XOR", math_xor}2378 ,2379 {"BAND", math_band}2380 ,2381 {"BOR", math_bor}2382 ,2383 {"BXOR", math_bxor}2384 ,2385 {"FDIV", math_fdiv}2386 ,2387 {"MEAN", math_mean}2388 ,2389 {"MEDIAN", math_median}2390 ,2391 {"STDDEV", math_stddev}2392 ,2393 {NULL, NULL}2394 };2395 2396 static MATH *2397 math_hash_lookup(char *name)2398 {2399 return (MATH *) hashfind(strupper(name), &htab_math);2400 }2401 2402 2403 static void2404 math_hash_insert(const char *name, MATH *func)2405 {2406 hashadd(name, (void *) func, &htab_math);2407 }2408 2409 /** Initialize the math function hash table. */2410 void2411 init_math_hashtab(void)2412 {2413 MATH *fp;2414 2415 hashinit(&htab_math, 32, sizeof(MATH));2416 for (fp = mlist; fp->name; fp++)2417 math_hash_insert(fp->name, (MATH *) fp);2418 }2419 2420 2308 static NVAL 2421 2309 angle_to_rad(NVAL angle, const char *from) 1.8.3/branches/experimental/src/game.c
r833 r834 726 726 init_flag_table("POWER"); 727 727 init_func_hashtab(); 728 init_math_hashtab();729 728 init_ansi_codes(); 730 729 init_aname_table(); … … 2324 2323 extern HASHTAB htab_function; 2325 2324 extern HASHTAB htab_user_function; 2326 extern HASHTAB htab_math;2327 2325 extern HASHTAB htab_player_list; 2328 2326 extern HASHTAB htab_reserved_aliases; … … 2347 2345 hash_stats(player, &htab_function, "Functions"); 2348 2346 hash_stats(player, &htab_user_function, "@Functions"); 2349 hash_stats(player, &htab_math, "Math funs");2350 2347 hash_stats(player, &htab_player_list, "Players"); 2351 2348 hash_stats(player, &htab_reserved_aliases, "Aliases");
