Wed, 20 Jun 2007 22:24:09 +0200
CF_NO_GETTEXT
| 97 | 1 | /* |
| 2 | * libtu/setparam.c | |
| 3 | * | |
| 4 | * Copyright (c) Tuomo Valkonen 2005. | |
| 5 | * | |
| 6 | * You may distribute and modify this library under the terms of either | |
| 7 | * the Clarified Artistic License or the GNU LGPL, version 2.1 or later. | |
| 8 | */ | |
| 9 | ||
| 10 | #include <string.h> | |
| 11 | ||
| 12 | #include "setparam.h" | |
| 13 | ||
| 14 | int libtu_string_to_setparam(const char *str) | |
| 15 | { | |
| 16 | if(str!=NULL){ | |
| 17 | if(strcmp(str, "set")==0 || strcmp(str, "true")==0) | |
| 18 | return SETPARAM_SET; | |
| 19 | else if(strcmp(str, "unset")==0 || strcmp(str, "false")==0) | |
| 20 | return SETPARAM_UNSET; | |
| 21 | else if(strcmp(str, "toggle")==0) | |
| 22 | return SETPARAM_TOGGLE; | |
| 23 | } | |
| 24 | ||
| 25 | return SETPARAM_UNKNOWN; | |
| 26 | } | |
| 27 | ||
| 28 | ||
| 29 | bool libtu_do_setparam(int sp, bool val) | |
| 30 | { | |
| 31 | switch(sp){ | |
| 32 | case SETPARAM_SET: | |
| 33 | return TRUE; | |
| 34 | case SETPARAM_UNSET: | |
| 35 | return FALSE; | |
| 36 | case SETPARAM_TOGGLE: | |
| 37 | return (val==FALSE); | |
| 38 | default: | |
| 39 | return val; | |
| 40 | } | |
| 41 | } | |
| 42 | ||
| 43 | bool libtu_do_setparam_str(const char *str, bool val) | |
| 44 | { | |
| 45 | return libtu_do_setparam(libtu_string_to_setparam(str), val); | |
| 98 | 46 | } |
| 47 | ||
| 48 | ||
| 49 | int libtu_setparam_invert(int sp) | |
| 50 | { | |
| 51 | switch(sp){ | |
| 52 | case SETPARAM_SET: | |
| 53 | return SETPARAM_UNSET; | |
| 54 | case SETPARAM_UNSET: | |
| 55 | return SETPARAM_SET; | |
| 56 | default: | |
| 57 | return sp; | |
| 58 | } | |
| 59 | } | |
| 60 |