From 679f307f013740c1bdc42859ea9a206508f6b811 Mon Sep 17 00:00:00 2001 From: reimar Date: Thu, 16 Jun 2005 09:08:07 +0000 Subject: helper functions for comparing strarg_t "strings". git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@15735 b3059339-0415-0410-9bf9-f77b7e298cf2 --- libvo/x11_common.c | 12 ++++++------ subopt-helper.c | 19 +++++++++++++++++++ subopt-helper.h | 3 +++ 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/libvo/x11_common.c b/libvo/x11_common.c index 6d455d8f48..66e1694f6a 100644 --- a/libvo/x11_common.c +++ b/libvo/x11_common.c @@ -2497,9 +2497,9 @@ int xv_test_ck( void * arg ) { strarg_t * strarg = (strarg_t *)arg; - if ( strncmp( "use", strarg->str, 3 ) == 0 || - strncmp( "set", strarg->str, 3 ) == 0 || - strncmp( "cur", strarg->str, 3 ) == 0 ) + if ( strargcmp( strarg, "use" ) == 0 || + strargcmp( strarg, "set" ) == 0 || + strargcmp( strarg, "cur" ) == 0 ) { return 1; } @@ -2511,9 +2511,9 @@ int xv_test_ckm( void * arg ) { strarg_t * strarg = (strarg_t *)arg; - if ( strncmp( "bg", strarg->str, 2 ) == 0 || - strncmp( "man", strarg->str, 3 ) == 0 || - strncmp( "auto", strarg->str, 4 ) == 0 ) + if ( strargcmp( strarg, "bg" ) == 0 || + strargcmp( strarg, "man" ) == 0 || + strargcmp( strarg, "auto" ) == 0 ) { return 1; } diff --git a/subopt-helper.c b/subopt-helper.c index 0356e036c4..9ae6669a05 100644 --- a/subopt-helper.c +++ b/subopt-helper.c @@ -292,3 +292,22 @@ int int_pos( int * i ) return 0; } + +/*** little helpers */ + +/** \brief compare the stings just as strcmp does */ +int strargcmp(strarg_t *arg, char *str) { + int res = strncmp(arg->str, str, arg->len); + if (!res && arg->len != strlen(str)) + res = arg->len - strlen(str); + return res; +} + +/** \brief compare the stings just as strcasecmp does */ +int strargcasecmp(strarg_t *arg, char *str) { + int res = strncasecmp(arg->str, str, arg->len); + if (!res && arg->len != strlen(str)) + res = arg->len - strlen(str); + return res; +} + diff --git a/subopt-helper.h b/subopt-helper.h index 9a8c828199..37ea6d6790 100644 --- a/subopt-helper.h +++ b/subopt-helper.h @@ -43,4 +43,7 @@ typedef struct strarg_s int int_non_neg( int * i ); int int_pos( int * i ); +int strargcmp(strarg_t *arg, char *str); +int strargcasecmp(strarg_t *arg, char *str); + #endif -- cgit v1.2.3