setparam.c

Wed, 20 Jun 2007 22:24:09 +0200

author
Tuomo Valkonen <tuomov@iki.fi>
date
Wed, 20 Jun 2007 22:24:09 +0200
changeset 112
ccc57312b8d0
parent 98
147a593d3ceb
permissions
-rw-r--r--

CF_NO_GETTEXT

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

mercurial