# HG changeset patch # User Tuomo Valkonen # Date 1111264050 -3600 # Node ID daf2b3d79cb8f26ad8b69b593ddfbdb49c4b6aa8 # Parent 80b5394ff100da31d6887af5bfac62f16a07d409 Added setparam.c. diff -r 80b5394ff100 -r daf2b3d79cb8 Makefile --- a/Makefile Sat Mar 19 20:56:25 2005 +0100 +++ b/Makefile Sat Mar 19 21:27:30 2005 +0100 @@ -12,7 +12,7 @@ SOURCES=misc.c output.c util.c optparser.c parser.c tokenizer.c \ map.c obj.c objlist.c errorlog.c ptrlist.c rb.c \ - stringstore.c iterable.c + stringstore.c iterable.c setparam.c ifdef LIBTU_NO_ERRMSG DEFINES += -DLIBTU_NO_ERRMSG diff -r 80b5394ff100 -r daf2b3d79cb8 misc.h --- a/misc.h Sat Mar 19 20:56:25 2005 +0100 +++ b/misc.h Sat Mar 19 21:27:30 2005 +0100 @@ -1,7 +1,7 @@ /* * libtu/misc.h * - * Copyright (c) Tuomo Valkonen 1999-2002. + * Copyright (c) Tuomo Valkonen 1999-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. diff -r 80b5394ff100 -r daf2b3d79cb8 setparam.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/setparam.c Sat Mar 19 21:27:30 2005 +0100 @@ -0,0 +1,46 @@ +/* + * 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 + +#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); +} \ No newline at end of file diff -r 80b5394ff100 -r daf2b3d79cb8 setparam.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/setparam.h Sat Mar 19 21:27:30 2005 +0100 @@ -0,0 +1,26 @@ +/* + * libtu/setparam.h + * + * 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. + */ + +#ifndef LIBTU_SETPARAM_H +#define LIBTU_SETPARAM_H + +#include "types.h" + +enum{ + SETPARAM_UNKNOWN, + SETPARAM_SET, + SETPARAM_UNSET, + SETPARAM_TOGGLE +}; + +extern int libtu_string_to_setparam(const char *str); +extern bool libtu_do_setparam_str(const char *str, bool val); +extern bool libtu_do_setparam(int sp, bool val); + +#endif /* LIBTU_SETPARAM_H */