]> granicus.if.org Git - nethack/commitdiff
str_end_is()
authorPatR <rankin@nethack.org>
Sun, 1 Nov 2015 00:13:26 +0000 (17:13 -0700)
committerPatR <rankin@nethack.org>
Sun, 1 Nov 2015 00:13:26 +0000 (17:13 -0700)
Move this small utility routine to hacklib.c where other such things
live and where it's feasible to find them if you need the functionality
elsewhere.

include/extern.h
src/hacklib.c
src/options.c

index 22df5471bd3f6c6b1beab62dc0b843b72868f88e..d3754352e5c326fe8d3ac8e71a70a1435f1e8040 100644 (file)
@@ -1,4 +1,4 @@
-/* NetHack 3.6 extern.h        $NHDT-Date: 1445215014 2015/10/19 00:36:54 $  $NHDT-Branch: master $:$NHDT-Revision: 1.509 $ */
+/* NetHack 3.6 extern.h        $NHDT-Date: 1446336781 2015/11/01 00:13:01 $  $NHDT-Branch: master $:$NHDT-Revision: 1.511 $ */
 /* Copyright (c) Steve Creps, 1988.                              */
 /* NetHack may be freely redistributed.  See license for details. */
 
@@ -831,6 +831,7 @@ E char *FDECL(ucase, (char *));
 E char *FDECL(upstart, (char *));
 E char *FDECL(mungspaces, (char *));
 E char *FDECL(eos, (char *));
+E boolean FDECL(str_end_is, (const char *, const char *));
 E char *FDECL(strkitten, (char *, CHAR_P));
 E void FDECL(copynchars, (char *, const char *, int));
 E char FDECL(chrcasecpy, (int, int));
index 689266450245a4412506caedefef9ddc85673284..f7499decbcf2bb44661d165cd2be29b22da8153b 100644 (file)
@@ -1,6 +1,6 @@
-/* NetHack 3.6 hacklib.c       $NHDT-Date: 1432723746 2015/05/27 10:49:06 $  $NHDT-Branch: master $:$NHDT-Revision: 1.43 $ */
+/* NetHack 3.6 hacklib.c       $NHDT-Date: 1446336792 2015/11/01 00:13:12 $  $NHDT-Branch: master $:$NHDT-Revision: 1.44 $ */
 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
-/* Copyright (c) Robert Patrick Rankin, 1991             */
+/* Copyright (c) Robert Patrick Rankin, 1991                      */
 /* NetHack may be freely redistributed.  See license for details. */
 
 #include "hack.h" /* for config.h+extern.h */
@@ -19,6 +19,7 @@
         char *          upstart         (char *)
         char *          mungspaces      (char *)
         char *          eos             (char *)
+        boolean         str_end_is      (const char *, const char *)
         char *          strkitten       (char *,char)
         void            copynchars      (char *,const char *,int)
         char            chrcasecpy      (int,int)
@@ -167,6 +168,18 @@ register char *s;
     return s;
 }
 
+/* determine whether 'str' ends in 'chkstr' */
+boolean
+str_end_is(str, chkstr)
+const char *str, *chkstr;
+{
+    int clen = (int) strlen(chkstr);
+
+    if ((int) strlen(str) >= clen)
+        return (boolean) (!strncmp(eos((char *) str) - clen, chkstr, clen));
+    return FALSE;
+}
+
 /* append a character to a string (in place): strcat(s, {c,'\0'}); */
 char *
 strkitten(s, c)
@@ -203,8 +216,8 @@ chrcasecpy(oc, nc)
 int oc, nc;
 {
 #if 0 /* this will be necessary if we switch to <ctype.h> */
-    oc = (int)(unsigned char)oc;
-    nc = (int)(unsigned char)nc;
+    oc = (int) (unsigned char) oc;
+    nc = (int) (unsigned char) nc;
 #endif
     if ('a' <= oc && oc <= 'z') {
         /* old char is lower case; if new char is upper case, downcase it */
@@ -319,7 +332,9 @@ char *buf;
     return buf;
 }
 
-boolean onlyspace(s) /* is a string entirely whitespace? */
+/* is a string entirely whitespace? */
+boolean
+onlyspace(s)
 const char *s;
 {
     for (; *s; s++)
@@ -328,7 +343,9 @@ const char *s;
     return TRUE;
 }
 
-char *tabexpand(sbuf) /* expand tabs into proper number of spaces */
+/* expand tabs into proper number of spaces */
+char *
+tabexpand(sbuf)
 char *sbuf;
 {
     char buf[BUFSZ];
@@ -351,7 +368,9 @@ char *sbuf;
     return strcpy(sbuf, buf);
 }
 
-char *visctrl(c) /* make a displayable string from a character */
+/* make a displayable string from a character */
+char *
+visctrl(c)
 char c;
 {
     Static char ccc[3];
@@ -510,9 +529,10 @@ int x0, y0, x1, y1;
     return (boolean) (!dy || !dx || dy == dx || dy == -dx);
 }
 
-/* guts of pmatch(), pmatchi(), and pmatchz() */
+/* guts of pmatch(), pmatchi(), and pmatchz();
+   match a string against a pattern */
 static boolean
-pmatch_internal(patrn, strng, ci, sk) /* match a string against a pattern */
+pmatch_internal(patrn, strng, ci, sk)
 const char *patrn, *strng;
 boolean ci;     /* True => case-insensitive, False => case-sensitive */
 const char *sk; /* set of characters to skip */
index 7a24137b3178fdefdae2903dd17913f03ca3873f..7e1ac9420fcd47e00675bdae7c7e2169dec5eebb 100644 (file)
@@ -1,4 +1,4 @@
-/* NetHack 3.6 options.c       $NHDT-Date: 1445556879 2015/10/22 23:34:39 $  $NHDT-Branch: master $:$NHDT-Revision: 1.227 $ */
+/* NetHack 3.6 options.c       $NHDT-Date: 1446336796 2015/11/01 00:13:16 $  $NHDT-Branch: master $:$NHDT-Revision: 1.234 $ */
 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
 /* NetHack may be freely redistributed.  See license for details. */
 
@@ -5106,16 +5106,6 @@ const char *str;
     return;
 }
 
-boolean
-str_end_is(str, chkstr)
-char *str, *chkstr;
-{
-    int clen = strlen(chkstr);
-    if (strlen(str) >= clen)
-        return !strncmp(eos(str) - clen, chkstr, clen);
-    return FALSE;
-}
-
 /* Returns the fid of the fruit type; if that type already exists, it
  * returns the fid of that one; if it does not exist, it adds a new fruit
  * type to the chain and returns the new one.