X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=ioncore%2Fsizepolicy.c;fp=ioncore%2Fsizepolicy.c;h=a99b7a3bc6243a33256a7351f134d9e79fec0d19;hb=ae4260bb64817c11f9a7140324cd3e3ba113e297;hp=7101da8b2632024ba6b340951e0d625458798f33;hpb=de22e45179cb3bafa490294d31d47f361047a30a;p=ion3.git diff --git a/ioncore/sizepolicy.c b/ioncore/sizepolicy.c index 7101da8..a99b7a3 100644 --- a/ioncore/sizepolicy.c +++ b/ioncore/sizepolicy.c @@ -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 @@ -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); +}