Sat, 19 Mar 2005 21:27:30 +0100
Added setparam.c.
Makefile | file | annotate | diff | comparison | revisions | |
misc.h | file | annotate | diff | comparison | revisions | |
setparam.c | file | annotate | diff | comparison | revisions | |
setparam.h | file | annotate | diff | comparison | revisions |
--- 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
--- 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.
--- /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 <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); +} \ No newline at end of file
--- /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 */