changeset 15734:7e4fa8fc255c

helper functions for comparing strarg_t "strings".
author reimar
date Thu, 16 Jun 2005 09:08:07 +0000
parents e678e306068e
children e8b0a1742428
files libvo/x11_common.c subopt-helper.c subopt-helper.h
diffstat 3 files changed, 28 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/libvo/x11_common.c	Thu Jun 16 09:03:11 2005 +0000
+++ b/libvo/x11_common.c	Thu Jun 16 09:08:07 2005 +0000
@@ -2497,9 +2497,9 @@
 {
   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 @@
 {
   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;
   }
--- a/subopt-helper.c	Thu Jun 16 09:03:11 2005 +0000
+++ b/subopt-helper.c	Thu Jun 16 09:08:07 2005 +0000
@@ -292,3 +292,22 @@
 
   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;
+}
+
--- a/subopt-helper.h	Thu Jun 16 09:03:11 2005 +0000
+++ b/subopt-helper.h	Thu Jun 16 09:08:07 2005 +0000
@@ -43,4 +43,7 @@
 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