PennMUSH Community

Changeset 834

Show
Ignore:
Timestamp:
05/08/07 21:53:01 (2 years ago)
Author:
shawnw
Message:

expr: #7321: Convert lmath to use gperf

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • 1.8.3/branches/experimental/hdrs/game.h

    r833 r834  
    1515/* hash table stuff */ 
    1616extern void init_func_hashtab(void);    /* eval.c */ 
    17 extern void init_math_hashtab(void);    /* funmath.c */ 
    1817extern void init_aname_table(void); /* atr_tab.c */ 
    1918extern void init_flagspaces(void);  /* flags.c */ 
  • 1.8.3/branches/experimental/src/Makefile.in

    r832 r834  
    151151htmltab.c: htmltab.gperf 
    152152    gperf --output-file htmltab.c htmltab.gperf 
     153 
     154lmath.c: lmath.gperf 
     155    gperf --output-file lmath.c lmath.gperf 
    153156 
    154157etags:  
     
    862865funmath.o: ../options.h 
    863866funmath.o: ../hdrs/mushtype.h 
    864 funmath.o: ../hdrs/htab.h 
    865867funmath.o: ../hdrs/externs.h 
    866868funmath.o: ../hdrs/compile.h 
     
    875877funmath.o: ../hdrs/sort.h 
    876878funmath.o: ../hdrs/parse.h 
     879funmath.o: lmath.c 
    877880funmisc.o: ../hdrs/copyrite.h 
    878881funmisc.o: ../config.h 
  • 1.8.3/branches/experimental/src/funmath.c

    r807 r834  
    1717#include "sort.h" 
    1818#include "parse.h" 
    19 #include "htab.h" 
    2019#include "confmagic.h" 
    2120 
     
    3635static NVAL find_median(NVAL *, int); 
    3736 
    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 *); 
    5437static NVAL angle_to_rad(NVAL angle, const char *from); 
    5538static NVAL rad_to_angle(NVAL angle, const char *to); 
    5639static double frac(double v, double *RESTRICT n, double *RESTRICT d, 
    5740           double error); 
    58 void init_math_hashtab(void); 
    5941 
    6042extern int format_long(long n, char *buff, char **bp, int maxlen, int base); 
    6143 
    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" 
    8346 
    8447/* ARGSUSED */ 
     
    23432306} 
    23442307 
    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 void 
    2404 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 void 
    2411 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  
    24202308static NVAL 
    24212309angle_to_rad(NVAL angle, const char *from) 
  • 1.8.3/branches/experimental/src/game.c

    r833 r834  
    726726  init_flag_table("POWER"); 
    727727  init_func_hashtab(); 
    728   init_math_hashtab(); 
    729728  init_ansi_codes(); 
    730729  init_aname_table(); 
     
    23242323extern HASHTAB htab_function; 
    23252324extern HASHTAB htab_user_function; 
    2326 extern HASHTAB htab_math; 
    23272325extern HASHTAB htab_player_list; 
    23282326extern HASHTAB htab_reserved_aliases; 
     
    23472345  hash_stats(player, &htab_function, "Functions"); 
    23482346  hash_stats(player, &htab_user_function, "@Functions"); 
    2349   hash_stats(player, &htab_math, "Math funs"); 
    23502347  hash_stats(player, &htab_player_list, "Players"); 
    23512348  hash_stats(player, &htab_reserved_aliases, "Aliases");