• make misc.c(gmatch.c):pat_scan() static and fix int → bool

This commit is contained in:
tg
2011-03-17 21:59:30 +00:00
parent d4e19b6624
commit a1a5922fc6
2 changed files with 11 additions and 10 deletions

18
misc.c
View File

@@ -29,11 +29,13 @@
#include <grp.h> #include <grp.h>
#endif #endif
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.154 2011/03/13 01:20:21 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/misc.c,v 1.155 2011/03/17 21:59:28 tg Exp $");
/* type bits for unsigned char */ /* type bits for unsigned char */
unsigned char chtypes[UCHAR_MAX + 1]; unsigned char chtypes[UCHAR_MAX + 1];
static const unsigned char *pat_scan(const unsigned char *,
const unsigned char *, bool);
static int do_gmatch(const unsigned char *, const unsigned char *, static int do_gmatch(const unsigned char *, const unsigned char *,
const unsigned char *, const unsigned char *); const unsigned char *, const unsigned char *);
static const unsigned char *cclass(const unsigned char *, int); static const unsigned char *cclass(const unsigned char *, int);
@@ -649,7 +651,7 @@ do_gmatch(const unsigned char *s, const unsigned char *se,
case 0x80|'+': case 0x80|'+':
/* matches zero or more times */ /* matches zero or more times */
case 0x80|'*': case 0x80|'*':
if (!(prest = pat_scan(p, pe, 0))) if (!(prest = pat_scan(p, pe, false)))
return (0); return (0);
s--; s--;
/* take care of zero matches */ /* take care of zero matches */
@@ -657,7 +659,7 @@ do_gmatch(const unsigned char *s, const unsigned char *se,
do_gmatch(s, se, prest, pe)) do_gmatch(s, se, prest, pe))
return (1); return (1);
for (psub = p; ; psub = pnext) { for (psub = p; ; psub = pnext) {
pnext = pat_scan(psub, pe, 1); pnext = pat_scan(psub, pe, true);
for (srest = s; srest <= se; srest++) { for (srest = s; srest <= se; srest++) {
if (do_gmatch(s, srest, psub, pnext - 2) && if (do_gmatch(s, srest, psub, pnext - 2) &&
(do_gmatch(srest, se, prest, pe) || (do_gmatch(srest, se, prest, pe) ||
@@ -676,7 +678,7 @@ do_gmatch(const unsigned char *s, const unsigned char *se,
case 0x80|'@': case 0x80|'@':
/* simile for @ */ /* simile for @ */
case 0x80|' ': case 0x80|' ':
if (!(prest = pat_scan(p, pe, 0))) if (!(prest = pat_scan(p, pe, false)))
return (0); return (0);
s--; s--;
/* Take care of zero matches */ /* Take care of zero matches */
@@ -684,7 +686,7 @@ do_gmatch(const unsigned char *s, const unsigned char *se,
do_gmatch(s, se, prest, pe)) do_gmatch(s, se, prest, pe))
return (1); return (1);
for (psub = p; ; psub = pnext) { for (psub = p; ; psub = pnext) {
pnext = pat_scan(psub, pe, 1); pnext = pat_scan(psub, pe, true);
srest = prest == pe ? se : s; srest = prest == pe ? se : s;
for (; srest <= se; srest++) { for (; srest <= se; srest++) {
if (do_gmatch(s, srest, psub, pnext - 2) && if (do_gmatch(s, srest, psub, pnext - 2) &&
@@ -698,14 +700,14 @@ do_gmatch(const unsigned char *s, const unsigned char *se,
/* matches none of the patterns */ /* matches none of the patterns */
case 0x80|'!': case 0x80|'!':
if (!(prest = pat_scan(p, pe, 0))) if (!(prest = pat_scan(p, pe, false)))
return (0); return (0);
s--; s--;
for (srest = s; srest <= se; srest++) { for (srest = s; srest <= se; srest++) {
int matched = 0; int matched = 0;
for (psub = p; ; psub = pnext) { for (psub = p; ; psub = pnext) {
pnext = pat_scan(psub, pe, 1); pnext = pat_scan(psub, pe, true);
if (do_gmatch(s, srest, psub, if (do_gmatch(s, srest, psub,
pnext - 2)) { pnext - 2)) {
matched = 1; matched = 1;
@@ -777,7 +779,7 @@ cclass(const unsigned char *p, int sub)
/* Look for next ) or | (if match_sep) in *(foo|bar) pattern */ /* Look for next ) or | (if match_sep) in *(foo|bar) pattern */
const unsigned char * const unsigned char *
pat_scan(const unsigned char *p, const unsigned char *pe, int match_sep) pat_scan(const unsigned char *p, const unsigned char *pe, bool match_sep)
{ {
int nest = 0; int nest = 0;

3
sh.h
View File

@@ -154,7 +154,7 @@
#endif #endif
#ifdef EXTERN #ifdef EXTERN
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.447 2011/03/17 21:58:38 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/sh.h,v 1.448 2011/03/17 21:59:30 tg Exp $");
#endif #endif
#define MKSH_VERSION "R39 2011/03/16" #define MKSH_VERSION "R39 2011/03/16"
@@ -1691,7 +1691,6 @@ int getn(const char *, int *);
int bi_getn(const char *, int *); int bi_getn(const char *, int *);
int gmatchx(const char *, const char *, bool); int gmatchx(const char *, const char *, bool);
int has_globbing(const char *, const char *); int has_globbing(const char *, const char *);
const unsigned char *pat_scan(const unsigned char *, const unsigned char *, int);
int xstrcmp(const void *, const void *); int xstrcmp(const void *, const void *);
void ksh_getopt_reset(Getopt *, int); void ksh_getopt_reset(Getopt *, int);
int ksh_getopt(const char **, Getopt *, const char *); int ksh_getopt(const char **, Getopt *, const char *);