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