]> git.pond.sub.org Git - empserver/commitdiff
(intmatch): Assumes that struct size is a multiple of sizeof(int), out
authorMarkus Armbruster <armbru@pond.sub.org>
Sat, 29 Oct 2005 07:15:14 +0000 (07:15 +0000)
committerMarkus Armbruster <armbru@pond.sub.org>
Sat, 29 Oct 2005 07:15:14 +0000 (07:15 +0000)
of laziness.  The assumption is true on any sane machine, due to
alignment constraints.  But the function doesn't provide enough value
to make me fix or document this.  Remove it.
(lookup): Replace it.

include/prototypes.h
src/lib/subs/mtch.c
src/lib/subs/show.c

index 7942246916e74d45c6ceb40212be06d92ae75da6..1bcfb1b20591e20b260a140acf3a4f8160c97249 100644 (file)
@@ -529,7 +529,6 @@ extern void msl_sel(struct emp_qelem *, coord, coord, natid, int,
 extern int msl_launch_mindam(struct emp_qelem *, coord, coord, int,
                             int, int, s_char *, int, int);
 /* mtch.c */
-extern int intmatch(register int, register int *, int);
 extern int comtch(register s_char *, struct cmndstr *, int, int);
 /* natarg.c */
 extern int natarg(s_char *, s_char *);
index f4f08c75b5c6e069bdb47cacb12c41501795183c..05bd032d91b377f5509408a8479747adefee4817 100644 (file)
  *  Known contributors to this file:
  *     (List known contributors to this file)
  */
-/*
- * XXX These routines gamble that structures are all longword-aligned.
- * If this is not true, they will BREAK!
- */
 
 #include "misc.h"
 #include "player.h"
 #include "match.h"
 #include "prototypes.h"
 
-/*
- * find a matching integer from a member of a structure.
- * Inspired by stmtch above.
- */
-int
-intmatch(register int value, register int *ptr, int size)
-{
-    register int i;
-
-    size /= sizeof(*ptr);
-    for (i = 0; *ptr; i++, ptr += size)
-       if (value == *ptr)
-           return i;
-    return -1;
-}
-
 /*
  * Search for COMMAND in COMS[], return its index.
  * Return M_NOTFOUND if there are no matches, M_NOTUNIQUE if there are
index 19a4588460091f8b25cb567129c7b98db7f2dcc7..c4e2f1cb0fa965c43f03c8c192db78569f913b32 100644 (file)
@@ -132,14 +132,16 @@ make_new_list(int tlev, int type)
     sort_lookup_list();
 }
 
-static s_char *
+static char *
 lookup(int key, struct lookup *table)
 {
-    int match;
+    int i;
+
+    for (i = 0; table[i].value; i++)
+       if (key == table[i].key)
+           return table[i].value;
 
-    if ((match = intmatch(key, &table->key, sizeof(*table))) < 0)
-       return 0;
-    return table[match].value;
+    return NULL;
 }
 
 void
@@ -219,7 +221,7 @@ show_nuke_capab(int tlev)
 {
     struct nchrstr *np;
     int i, j, n;
-    s_char *p;
+    char *p;
 
     if (opt_DRNUKE)
        pr("%13s blst dam lbs tech res $%7s abilities\n", "", "");
@@ -342,7 +344,7 @@ show_ship_capab(int tlev)
     int j;
     int scount;
     int n;
-    s_char *p;
+    char *p;
 
     pr("%25s cargos & capabilities\n", "");
 
@@ -402,7 +404,7 @@ show_plane_capab(int tlev)
     int i;
     int pcount;
     int n;
-    s_char *p;
+    char *p;
 
     pr("%25s capabilities\n", "");
     make_new_list(tlev, EF_PLANE);
@@ -467,7 +469,7 @@ show_land_capab(int tlev)
     int lcount;
     i_type i;
     int j, n;
-    s_char *p;
+    char *p;
 
     pr("%25s capabilities\n", "");