Import libtu instead of using submodules
[notion/jeffpc.git] / libtu / setparam.c
blob3b5e5eb18ae80f2d4013b576b41b5b06dbbfac1b
1 /*
2 * libtu/setparam.c
4 * Copyright (c) Tuomo Valkonen 2005.
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 */
10 #include <string.h>
12 #include "setparam.h"
14 int libtu_string_to_setparam(const char *str)
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;
25 return SETPARAM_UNKNOWN;
29 bool libtu_do_setparam(int sp, bool val)
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;
43 bool libtu_do_setparam_str(const char *str, bool val)
45 return libtu_do_setparam(libtu_string_to_setparam(str), val);
49 int libtu_setparam_invert(int sp)
51 switch(sp){
52 case SETPARAM_SET:
53 return SETPARAM_UNSET;
54 case SETPARAM_UNSET:
55 return SETPARAM_SET;
56 default:
57 return sp;