str_end_is()
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.
This commit is contained in:
+2
-1
@@ -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. */
|
/* Copyright (c) Steve Creps, 1988. */
|
||||||
/* NetHack may be freely redistributed. See license for details. */
|
/* 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(upstart, (char *));
|
||||||
E char *FDECL(mungspaces, (char *));
|
E char *FDECL(mungspaces, (char *));
|
||||||
E char *FDECL(eos, (char *));
|
E char *FDECL(eos, (char *));
|
||||||
|
E boolean FDECL(str_end_is, (const char *, const char *));
|
||||||
E char *FDECL(strkitten, (char *, CHAR_P));
|
E char *FDECL(strkitten, (char *, CHAR_P));
|
||||||
E void FDECL(copynchars, (char *, const char *, int));
|
E void FDECL(copynchars, (char *, const char *, int));
|
||||||
E char FDECL(chrcasecpy, (int, int));
|
E char FDECL(chrcasecpy, (int, int));
|
||||||
|
|||||||
+29
-9
@@ -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) 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. */
|
/* NetHack may be freely redistributed. See license for details. */
|
||||||
|
|
||||||
#include "hack.h" /* for config.h+extern.h */
|
#include "hack.h" /* for config.h+extern.h */
|
||||||
@@ -19,6 +19,7 @@
|
|||||||
char * upstart (char *)
|
char * upstart (char *)
|
||||||
char * mungspaces (char *)
|
char * mungspaces (char *)
|
||||||
char * eos (char *)
|
char * eos (char *)
|
||||||
|
boolean str_end_is (const char *, const char *)
|
||||||
char * strkitten (char *,char)
|
char * strkitten (char *,char)
|
||||||
void copynchars (char *,const char *,int)
|
void copynchars (char *,const char *,int)
|
||||||
char chrcasecpy (int,int)
|
char chrcasecpy (int,int)
|
||||||
@@ -167,6 +168,18 @@ register char *s;
|
|||||||
return 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'}); */
|
/* append a character to a string (in place): strcat(s, {c,'\0'}); */
|
||||||
char *
|
char *
|
||||||
strkitten(s, c)
|
strkitten(s, c)
|
||||||
@@ -203,8 +216,8 @@ chrcasecpy(oc, nc)
|
|||||||
int oc, nc;
|
int oc, nc;
|
||||||
{
|
{
|
||||||
#if 0 /* this will be necessary if we switch to <ctype.h> */
|
#if 0 /* this will be necessary if we switch to <ctype.h> */
|
||||||
oc = (int)(unsigned char)oc;
|
oc = (int) (unsigned char) oc;
|
||||||
nc = (int)(unsigned char)nc;
|
nc = (int) (unsigned char) nc;
|
||||||
#endif
|
#endif
|
||||||
if ('a' <= oc && oc <= 'z') {
|
if ('a' <= oc && oc <= 'z') {
|
||||||
/* old char is lower case; if new char is upper case, downcase it */
|
/* old char is lower case; if new char is upper case, downcase it */
|
||||||
@@ -319,7 +332,9 @@ char *buf;
|
|||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean onlyspace(s) /* is a string entirely whitespace? */
|
/* is a string entirely whitespace? */
|
||||||
|
boolean
|
||||||
|
onlyspace(s)
|
||||||
const char *s;
|
const char *s;
|
||||||
{
|
{
|
||||||
for (; *s; s++)
|
for (; *s; s++)
|
||||||
@@ -328,7 +343,9 @@ const char *s;
|
|||||||
return TRUE;
|
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 *sbuf;
|
||||||
{
|
{
|
||||||
char buf[BUFSZ];
|
char buf[BUFSZ];
|
||||||
@@ -351,7 +368,9 @@ char *sbuf;
|
|||||||
return strcpy(sbuf, buf);
|
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;
|
char c;
|
||||||
{
|
{
|
||||||
Static char ccc[3];
|
Static char ccc[3];
|
||||||
@@ -510,9 +529,10 @@ int x0, y0, x1, y1;
|
|||||||
return (boolean) (!dy || !dx || dy == dx || dy == -dx);
|
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
|
static boolean
|
||||||
pmatch_internal(patrn, strng, ci, sk) /* match a string against a pattern */
|
pmatch_internal(patrn, strng, ci, sk)
|
||||||
const char *patrn, *strng;
|
const char *patrn, *strng;
|
||||||
boolean ci; /* True => case-insensitive, False => case-sensitive */
|
boolean ci; /* True => case-insensitive, False => case-sensitive */
|
||||||
const char *sk; /* set of characters to skip */
|
const char *sk; /* set of characters to skip */
|
||||||
|
|||||||
+1
-11
@@ -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. */
|
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
|
||||||
/* NetHack may be freely redistributed. See license for details. */
|
/* NetHack may be freely redistributed. See license for details. */
|
||||||
|
|
||||||
@@ -5106,16 +5106,6 @@ const char *str;
|
|||||||
return;
|
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 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
|
* 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.
|
* type to the chain and returns the new one.
|
||||||
|
|||||||
Reference in New Issue
Block a user