]> git.decadent.org.uk Git - ion3.git/blobdiff - ioncore/sizepolicy.c
[svn-upgrade] Integrating new upstream version, ion3 (20070506)
[ion3.git] / ioncore / sizepolicy.c
index 7101da8b2632024ba6b340951e0d625458798f33..a99b7a3bc6243a33256a7351f134d9e79fec0d19 100644 (file)
@@ -3,10 +3,7 @@
  *
  * Copyright (c) Tuomo Valkonen 1999-2007. 
  *
- * Ion is free software; you can redistribute it and/or modify it under
- * the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; either version 2.1 of the License, or
- * (at your option) any later version.
+ * See the included file LICENSE for details.
  */
 
 #include <libtu/minmax.h>
@@ -283,14 +280,8 @@ void sizepolicy(WSizePolicy *szplcy, WRegion *reg,
 }
 
 
-struct szplcy_spec {
-    const char *spec;
-    int szplcy;
-};
-
-
 /* translation table for sizepolicy specifications */
-static struct szplcy_spec szplcy_specs[] = {
+static StringIntMap szplcy_specs[] = {
     {"default",         SIZEPOLICY_DEFAULT},
     {"full",            SIZEPOLICY_FULL_EXACT},
     {"full_bounds",     SIZEPOLICY_FULL_BOUNDS},
@@ -324,17 +315,21 @@ static struct szplcy_spec szplcy_specs[] = {
 
 bool string2sizepolicy(const char *szplcy, WSizePolicy *value)
 {
-    const struct szplcy_spec *sp;
+    int tmp;
     
-    *value=SIZEPOLICY_DEFAULT;
-
-    for(sp=szplcy_specs; sp->spec; ++sp){
-       if(strcasecmp(szplcy,sp->spec)==0){
-           *value=sp->szplcy;
-           return TRUE;
-        }
-    }
+    tmp=stringintmap_value(szplcy_specs, szplcy, -1);
     
-    return FALSE;
+    if(tmp==-1){
+        *value=SIZEPOLICY_DEFAULT;
+        return FALSE;
+    }else{
+        *value=tmp;
+        return TRUE;
+    }
 }
 
+
+const char *sizepolicy2string(WSizePolicy szplcy)
+{
+    return stringintmap_key(szplcy_specs, szplcy, NULL);
+}