(stmtch, mineq): Document. Move declaration from prototypes.h to
match.h. Use plain char instead of s_char. The code has several thousand type errors due to s_char vs plain char; s_char must go. (stmtch): Rewrite for clarity.
This commit is contained in:
parent
520baaf867
commit
844b654d44
3 changed files with 31 additions and 21 deletions
|
@ -34,6 +34,8 @@
|
||||||
#ifndef _MATCH_H_
|
#ifndef _MATCH_H_
|
||||||
#define _MATCH_H_
|
#define _MATCH_H_
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
/* returned by stmtch() */
|
/* returned by stmtch() */
|
||||||
#define M_IGNORE -3
|
#define M_IGNORE -3
|
||||||
#define M_NOTUNIQUE -2
|
#define M_NOTUNIQUE -2
|
||||||
|
@ -45,4 +47,7 @@
|
||||||
#define ME_PARTIAL 1
|
#define ME_PARTIAL 1
|
||||||
#define ME_EXACT 2
|
#define ME_EXACT 2
|
||||||
|
|
||||||
|
extern int stmtch(char *, void *, ptrdiff_t, size_t);
|
||||||
|
extern int mineq(char *, char *);
|
||||||
|
|
||||||
#endif /* _MATCH_H_ */
|
#endif /* _MATCH_H_ */
|
||||||
|
|
|
@ -174,8 +174,7 @@ extern void snxtsct_all(struct nstr_sect *);
|
||||||
extern void snxtsct_rewind(struct nstr_sect *);
|
extern void snxtsct_rewind(struct nstr_sect *);
|
||||||
extern void snxtsct_dist(register struct nstr_sect *, coord, coord, int);
|
extern void snxtsct_dist(register struct nstr_sect *, coord, coord, int);
|
||||||
/* stmtch.c */
|
/* stmtch.c */
|
||||||
extern int stmtch(register s_char *, s_char *, int, int);
|
/* in match.h */
|
||||||
extern int mineq(register s_char *, register s_char *);
|
|
||||||
/* type.c */
|
/* type.c */
|
||||||
extern int typematch(s_char *, int);
|
extern int typematch(s_char *, int);
|
||||||
/* vlist.c */
|
/* vlist.c */
|
||||||
|
|
|
@ -40,30 +40,36 @@
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* find a matching string from a member string pointer
|
* Find NEEDLE in array HAYSTACK[], return its index.
|
||||||
* in a structure "str". Pointer is incremented by
|
* Return M_NOTFOUND if there are no matches, M_NOTUNIQUE if there are
|
||||||
* the (passed) size of the structure.
|
* several.
|
||||||
|
* Each array element has a pointer to its name stored at offset OFFS.
|
||||||
|
* Search stops when this name is a null pointer or empty. NEEDLE is
|
||||||
|
* compared to element names with mineq().
|
||||||
|
* ELT_SIZE gives the size of an array element.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
stmtch(register s_char *obj, s_char *base, int off, int size)
|
stmtch(char *needle, void *haystack, ptrdiff_t offs, size_t elt_size)
|
||||||
{
|
{
|
||||||
register s_char *str;
|
#define ELT_NAME(i) (*(char **)((char *)haystack + (i)*elt_size + offs))
|
||||||
register int stat2;
|
int i, res;
|
||||||
register int i;
|
|
||||||
register int n;
|
|
||||||
|
|
||||||
stat2 = M_NOTFOUND;
|
res = M_NOTFOUND;
|
||||||
str = base + off;
|
for (i = 0; ELT_NAME(i) && ELT_NAME(i)[0] != 0; ++i) {
|
||||||
for (i = 0; *(s_char **)str; i++, str += size) {
|
switch (mineq(needle, ELT_NAME(i))) {
|
||||||
if ((n = mineq(obj, *(s_char **)str)) == ME_MISMATCH)
|
case ME_MISMATCH:
|
||||||
continue;
|
break;
|
||||||
if (n == ME_EXACT)
|
case ME_PARTIAL:
|
||||||
|
if (res != M_NOTFOUND)
|
||||||
|
return M_NOTUNIQUE;
|
||||||
|
res = i;
|
||||||
|
break;
|
||||||
|
case ME_EXACT:
|
||||||
return i;
|
return i;
|
||||||
if (stat2 != M_NOTFOUND)
|
}
|
||||||
return M_NOTUNIQUE;
|
|
||||||
stat2 = i;
|
|
||||||
}
|
}
|
||||||
return stat2;
|
return res;
|
||||||
|
#undef ELT_NAME
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -75,7 +81,7 @@ stmtch(register s_char *obj, s_char *base, int off, int size)
|
||||||
* terminating 0.
|
* terminating 0.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
mineq(register s_char *a, register s_char *b)
|
mineq(char *a, char *b)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue