]> git.cameronkatri.com Git - bsdgames-darwin.git/commitdiff
Add OBJ_AN flag to objflags so as to use "a" or "an" appropriately in
authorjsm <jsm@NetBSD.org>
Mon, 25 Sep 2000 14:08:08 +0000 (14:08 +0000)
committerjsm <jsm@NetBSD.org>
Mon, 25 Sep 2000 14:08:08 +0000 (14:08 +0000)
messages; avoids "a amulet", "a Elf".  Define and use macros to use
"a", "an", "the", "is", "are" appropriately.  Partly based on OpenBSD.

battlestar/com2.c
battlestar/com4.c
battlestar/extern.h
battlestar/globals.c

index 5aa0c0dd26c790a7f345a700ffd85b50a17f823b..ce8b21a7007a3ef59402d1d1e710a97a7b1c5cbf 100644 (file)
@@ -1,4 +1,4 @@
-/*     $NetBSD: com2.c,v 1.19 2000/09/25 00:28:54 jsm Exp $    */
+/*     $NetBSD: com2.c,v 1.20 2000/09/25 14:08:08 jsm Exp $    */
 
 /*
  * Copyright (c) 1983, 1993
@@ -38,7 +38,7 @@
 #if 0
 static char sccsid[] = "@(#)com2.c     8.2 (Berkeley) 4/28/95";
 #else
-__RCSID("$NetBSD: com2.c,v 1.19 2000/09/25 00:28:54 jsm Exp $");
+__RCSID("$NetBSD: com2.c,v 1.20 2000/09/25 14:08:08 jsm Exp $");
 #endif
 #endif                         /* not lint */
 
@@ -63,7 +63,8 @@ wearit()
                        return (firstnumber);
 
                default:
-                       printf("You can't wear%s%s!\n", (is_plural_object(value) ? " " : " a "), objsht[value]);
+                       printf("You can't wear %s%s!\n",
+                           A_OR_AN_OR_BLANK(value), objsht[value]);
                        return (firstnumber);
 
                case KNIFE:
@@ -91,9 +92,8 @@ wearit()
                                carrying -= objwt[value];
                                encumber -= objcumber[value];
                                ourtime++;
-                               printf("You are now wearing %s %s.\n",
-                                   (is_plural_object(value) ? "the"
-                                       : "a"), objsht[value]);
+                               printf("You are now wearing %s%s.\n",
+                                   A_OR_AN_OR_THE(value), objsht[value]);
                        } else
                                if (testbit(wear, value))
                                        printf("You are already wearing the %s.\n",
@@ -199,7 +199,8 @@ murder()
                                    wordvalue[wordnumber] == EVERYTHING)
                                        puts("You can't kill that!");
                                else
-                                       printf("You can't kill the %s!\n",
+                                       printf("You can't kill %s%s!\n",
+                                           A_OR_AN_OR_BLANK(wordvalue[wordnumber]),
                                            objsht[wordvalue[wordnumber]]);
                                break;
                        }
index b73e3d611921cdeaf2307d7f232fcb085dc1bc0e..467e2906c6738428f7a4289fb277622cb93f41d8 100644 (file)
@@ -1,4 +1,4 @@
-/*     $NetBSD: com4.c,v 1.17 2000/09/24 09:46:57 jsm Exp $    */
+/*     $NetBSD: com4.c,v 1.18 2000/09/25 14:08:08 jsm Exp $    */
 
 /*
  * Copyright (c) 1983, 1993
@@ -38,7 +38,7 @@
 #if 0
 static char sccsid[] = "@(#)com4.c     8.2 (Berkeley) 4/28/95";
 #else
-__RCSID("$NetBSD: com4.c,v 1.17 2000/09/24 09:46:57 jsm Exp $");
+__RCSID("$NetBSD: com4.c,v 1.18 2000/09/25 14:08:08 jsm Exp $");
 #endif
 #endif                         /* not lint */
 
@@ -75,18 +75,17 @@ take(from)
                                if (value == MEDALION)
                                        win--;
                        } else if (testbit(inven, value))
-                               printf("You're already holding%s%s.\n",
-                                   (is_plural_object(value) ? " " : " a "),
+                               printf("You're already holding %s%s.\n",
+                                   A_OR_AN_OR_BLANK(value),
                                    objsht[value]);
                        else if (!testbit(from, value))
                                printf("I don't see any %s around here.\n", objsht[value]);
                        else if (!heavy)
-                               printf("The %s %s too heavy.\n", objsht[value],
-                                   (is_plural_object(value) ? "are" : "is"));
+                               printf("The %s %stoo heavy.\n", objsht[value],
+                                   IS_OR_ARE(value));
                        else
-                               printf("The %s %s too cumbersome to hold.\n",
-                                   objsht[value],
-                                   (is_plural_object(value) ? "are" : "is"));
+                               printf("The %s %stoo cumbersome to hold.\n",
+                                   objsht[value], IS_OR_ARE(value));
                        if (wordnumber < wordcount - 1 && wordvalue[++wordnumber] == AND)
                                wordnumber++;
                        else
@@ -384,9 +383,8 @@ eat()
                        return (firstnumber);
 
                default:
-                       printf("You can't eat%s%s!\n",
-                           is_plural_object(value) ? " " : " a ",
-                           objsht[value]);
+                       printf("You can't eat %s%s!\n",
+                           A_OR_AN_OR_BLANK(value), objsht[value]);
                        return (firstnumber);
 
                case PAPAYAS:
index e03cdd39de76a09fb70772503780cf4d7a244c1f..0982ec16da8935b7481636f6094bc734ec16ca62 100644 (file)
@@ -1,4 +1,4 @@
-/*     $NetBSD: extern.h,v 1.25 2000/09/24 14:11:09 jsm Exp $ */
+/*     $NetBSD: extern.h,v 1.26 2000/09/25 14:08:08 jsm Exp $ */
 
 /*
  * Copyright (c) 1983, 1993
 
 /* Flags for objects.  */
 #define OBJ_PLURAL     1
+#define OBJ_AN         2
 
 struct room {
        const char   *name;
@@ -256,6 +257,14 @@ extern const int     objwt[NUMOFOBJECTS];
 extern const int     objcumber[NUMOFOBJECTS];
 extern const int     objflags[NUMOFOBJECTS];
 #define is_plural_object(n)    (objflags[(n)] & OBJ_PLURAL)
+/*
+ * These macros yield words to use with objects (followed but not preceded
+ * by spaces, or with no spaces if the expansion is the empty string).
+ */
+#define A_OR_AN(n)             (objflags[(n)] & OBJ_AN ? "an " : "a ")
+#define A_OR_AN_OR_THE(n)      (is_plural_object((n)) ? "the " : A_OR_AN((n)))
+#define A_OR_AN_OR_BLANK(n)    (is_plural_object((n)) ? "" : A_OR_AN((n)))
+#define IS_OR_ARE(n)           (is_plural_object((n)) ? "are " : "is ")
 
  /* current input line */
 #define WORDLEN        15
index 3938d5e3af104cfa6d162bc0e6717fe2aaa65a2f..072ce36dffaaea0348aff9d4647f190a0b9cf28a 100644 (file)
@@ -1,4 +1,4 @@
-/*     $NetBSD: globals.c,v 1.16 2000/09/24 14:11:09 jsm Exp $ */
+/*     $NetBSD: globals.c,v 1.17 2000/09/25 14:08:08 jsm Exp $ */
 
 /*
  * Copyright (c) 1983, 1993
@@ -38,7 +38,7 @@
 #if 0
 static char sccsid[] = "@(#)globals.c  8.2 (Berkeley) 4/28/95";
 #else
-__RCSID("$NetBSD: globals.c,v 1.16 2000/09/24 14:11:09 jsm Exp $");
+__RCSID("$NetBSD: globals.c,v 1.17 2000/09/25 14:08:08 jsm Exp $");
 #endif
 #endif                         /* not lint */
 
@@ -221,14 +221,14 @@ const int     objcumber[NUMOFOBJECTS] = {
 };
 
 const int objflags[NUMOFOBJECTS] = {
-       0, 0, 0, 0, 0, 0, 0, 0,
-       0, 0, 0, 0, 0, OBJ_PLURAL, 0, OBJ_PLURAL,
-       0, 0, 0, 0, 0, 0, 0, 0,
-       0, 0, 0, 0, OBJ_PLURAL, 0, 0, 0,
-       0, 0, 0, 0, OBJ_PLURAL, 0, 0, OBJ_PLURAL,
-       0, 0, OBJ_PLURAL, 0, 0, 0, 0, 0,
-       0, 0, 0, 0, 0, 0, 0, 0,
-       0, 0, 0, 0, 0, 0, 0, 0
+       0,      0,      0,      0,      0,      0,      0,      0,
+       0,      0,      0,      0,      0,  OBJ_PLURAL, 0,  OBJ_PLURAL,
+       0,    OBJ_AN,   0,      0,      0,      0,      0,      0,
+       0,      0,      0,      0,  OBJ_PLURAL, 0,      0,      0,
+       0,      0,    OBJ_AN,   0,  OBJ_PLURAL, 0,      0,  OBJ_PLURAL,
+       0,      0,  OBJ_PLURAL, 0,      0,      0,      0,      0,
+       0,      0,      0,      0,      0,      0,      0,      0,
+      OBJ_AN,  0,      0,      0,      0,      0,      0,      0
 };
 
 int     win = 1;