]> git.pond.sub.org Git - empserver/blobdiff - src/lib/subs/whatitem.c
Update copyright notice.
[empserver] / src / lib / subs / whatitem.c
index 23e8a8de8bd89afcdb64d46b8ca7c39ffc35157b..255449cc4f8fc6484d6641029294ddc4e6caf6f6 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2000, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2007, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                           Ken Stevens, Steve McClure
  *
  *  This program is free software; you can redistribute it and/or modify
@@ -19,9 +19,9 @@
  *
  *  ---
  *
- *  See the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
- *  related information and legal notices. It is expected that any future
- *  projects/authors will amend these files as needed.
+ *  See files README, COPYING and CREDITS in the root of the source
+ *  tree for related information and legal notices.  It is expected
+ *  that future projects/authors will amend these files as needed.
  *
  *  ---
  *
  * 
  */
 
-#include "misc.h"
-#include "item.h"
+#include <config.h>
+
 #include "prototypes.h"
 
+/*
+ * Get item type argument.
+ * If INPUT is not empty, use it, else prompt for more input using PROMPT.
+ * Return item characteristics on success, else NULL.
+ */
 struct ichrstr *
-whatitem(s_char *ptr, s_char *prompt)
+whatitem(char *input, char *prompt)
 {
-    register s_char *p;
-    register struct ichrstr *ip;
-    s_char buf[1024];
+    char *p;
+    struct ichrstr *ip;
+    char buf[1024];
 
-    p = getstarg(ptr, prompt, buf);
+    p = getstarg(input, prompt, buf);
     if (p == 0 || *p == 0)
        return 0;
-    for (ip = &ichr[1]; ip->i_mnem != 0; ip++) {
-       if (*p == ip->i_mnem)
+    ip = item_by_name(p);
+    if (!ip)
+       pr("Unrecognized item \"%c\"\n", *p);
+    return ip;
+}
+
+/*
+ * Map item type name STR to item characteristics, NULL if not found.
+ */
+struct ichrstr *
+item_by_name(char *str)
+{
+    struct ichrstr *ip;
+
+    for (ip = ichr; ip->i_mnem != 0; ip++) {
+       /* FIXME check i_name if str[2]? */
+       if (*str == ip->i_mnem)
            return ip;
     }
-    pr("Unrecognized item \"%c\"\n", *p);
     return 0;
 }