diff --git a/sc2/ChangeLog b/sc2/ChangeLog index ca62eb3e4..127f2d83f 100644 --- a/sc2/ChangeLog +++ b/sc2/ChangeLog @@ -1,4 +1,5 @@ Changes towards version 0.7: +- Added match_matchPatternOnce() - SvdB - Fixed a problem with blue ships after Avatar's tractor beam, along with some other fill-stamp situations; bug #929 - Alex - Added TFB_Canvas_Lock(), TFB_Canvas_Unlock() and TFB_Canvas_GetStride() diff --git a/sc2/src/sc2code/libs/uio/match.c b/sc2/src/sc2code/libs/uio/match.c index 898ec407d..03ce1614c 100644 --- a/sc2/src/sc2code/libs/uio/match.c +++ b/sc2/src/sc2code/libs/uio/match.c @@ -65,6 +65,16 @@ static inline void match_freeRegexContext(match_RegexContext *context); // *** General part *** +static inline match_MatchContext * +match_allocMatchContext(void) { + return uio_malloc(sizeof (match_MatchContext)); +} + +static inline void +match_freeMatchContext(match_MatchContext *context) { + uio_free(context); +} + // NB: Even if this function fails, *contextPtr contains a context // which needs to be freed. match_Result @@ -133,6 +143,7 @@ match_matchPattern(match_MatchContext *context, const char *string) { } } +// context may be NULL const char * match_errorString(match_MatchContext *context, match_Result result) { switch (result) { @@ -145,11 +156,15 @@ match_errorString(match_MatchContext *context, match_Result result) { case match_ENOTINIT: return "Uninitialised use"; case match_ECUSTOM: - // Depends on match type. + // Depends on match type. Printed below. break; default: return "Unknown error"; } + + if (context == NULL) + return "Unknown match-type specific error."; + // We can't be any more specific if no 'context' is supplied. switch (context->type) { #if 0 @@ -206,14 +221,21 @@ match_freeContext(match_MatchContext *context) { match_freeMatchContext(context); } -static inline match_MatchContext * -match_allocMatchContext(void) { - return uio_malloc(sizeof (match_MatchContext)); -} +match_Result +match_matchPatternOnce(const char *pattern, match_MatchType type, + const char *string) { + match_MatchContext *context; + match_Result result; -static inline void -match_freeMatchContext(match_MatchContext *context) { - uio_free(context); + result = match_prepareContext(pattern, &context, type); + if (result != match_OK) + goto out; + + result = match_matchPattern(context, string); + +out: + match_freeContext(context); + return result; } diff --git a/sc2/src/sc2code/libs/uio/match.h b/sc2/src/sc2code/libs/uio/match.h index fac4ef45d..1e20bcc33 100644 --- a/sc2/src/sc2code/libs/uio/match.h +++ b/sc2/src/sc2code/libs/uio/match.h @@ -70,6 +70,8 @@ match_Result match_matchPattern(match_MatchContext *context, const char *match_errorString(match_MatchContext *context, match_Result result); void match_freeContext(match_MatchContext *context); +match_Result match_matchPatternOnce(const char *pattern, match_MatchType type, + const char *string); /* *** Internal definitions follow *** */ diff --git a/sc2/src/sc2code/libs/uio/mounttree.h b/sc2/src/sc2code/libs/uio/mounttree.h index 04c5586fc..a99295be8 100644 --- a/sc2/src/sc2code/libs/uio/mounttree.h +++ b/sc2/src/sc2code/libs/uio/mounttree.h @@ -102,7 +102,7 @@ struct uio_MountInfo { char *dirName; /* The path inside the mounted fs leading to pDirHandle */ uio_PDirHandle *pDirHandle; - /* The pDirHandle belonging to this mount type */ + /* The pDirHandle belonging to this mount */ uio_MountTree *mountTree; /* The MountTree node for the mountpoint */ uio_AutoMount **autoMount;