]> git.pond.sub.org Git - empserver/blobdiff - src/lib/subs/whatitem.c
Update copyright notice.
[empserver] / src / lib / subs / whatitem.c
index e531739c41988d7bbebdfc8e8b0f7f9088acfa12..687cff32a2d52dd763dc6e9cb8579ee7e3a3d597 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-2004, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                           Ken Stevens, Steve McClure
  *
  *  This program is free software; you can redistribute it and/or modify
 #include "item.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);
-       if (p == 0 || *p == 0)
-               return 0;
-       for (ip = &ichr[1]; ip->i_mnem != 0; ip++) {
-               if (*p == ip->i_mnem)
-                       return ip;
-       }
-       pr("Unrecognized item \"%c\"\n", *p);
+    p = getstarg(input, prompt, buf);
+    if (p == 0 || *p == 0)
        return 0;
+    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[1]; ip->i_mnem != 0; ip++) {
+       /* FIXME check i_name if str[2]? */
+       if (*str == ip->i_mnem)
+           return ip;
+    }
+    return 0;
 }