OSDN Git Service

upgrade to 3.6.7
[jnethack/source.git] / src / pager.c
index 6bfd8f6..d2086f6 100644 (file)
@@ -54,32 +54,37 @@ int c;
     return FALSE;
 }
 
-/*
- * Append new_str to the end of buf if new_str doesn't already exist as
- * a substring of buf.  Return 1 if the string was appended, 0 otherwise.
- * It is expected that buf is of size BUFSZ.
- */
+/* Append " or "+new_str to the end of buf if new_str doesn't already exist
+   as a substring of buf.  Return 1 if the string was appended, 0 otherwise.
+   It is expected that buf is of size BUFSZ. */
 STATIC_OVL int
 append_str(buf, new_str)
 char *buf;
 const char *new_str;
 {
-    int space_left; /* space remaining in buf */
-
+/*JP
+    static const char sep[] = " or ";
+*/
+    static const char sep[] = "\82Ü\82½\82Í";
+    size_t oldlen, space_left;
     if (strstri(buf, new_str))
-        return 0;
-
-    space_left = BUFSZ - strlen(buf) - 1;
-    if (space_left < 1)
-        return 0;
-#if 0 /*JP:T*/
-    (void) strncat(buf, " or ", space_left);
-    (void) strncat(buf, new_str, space_left - 4);
-#else
-    (void) strncat(buf, "\82Ü\82½\82Í", space_left);
-    (void) strncat(buf, new_str, space_left - 6);
-#endif
-    return 1;
+        return 0; /* already present */
+
+    oldlen = strlen(buf);
+    if (oldlen >= BUFSZ - 1) {
+        if (oldlen > BUFSZ - 1)
+            impossible("append_str: 'buf' contains %lu characters.",
+                       (unsigned long) oldlen);
+        return 0; /* no space available */
+    }
+    /* some space available, but not necessarily enough for full append */
+    space_left = BUFSZ - 1 - oldlen;  /* space remaining in buf */
+    (void) strncat(buf, sep, space_left);
+    if (space_left > sizeof sep - 1)
+        (void) strncat(buf, new_str, space_left - (sizeof sep - 1));
+    return 1; /* something was appended, possibly just part of " or " */
 }
 
 /* shared by monster probing (via query_objlist!) as well as lookat() */