Removed direct access of interp->result.
1 | /* |
2 | * The contents of this file are subject to the AOLserver Public License |
3 | * Version 1.1 (the "License"); you may not use this file except in |
4 | * compliance with the License. You may obtain a copy of the License at |
5 | * http://aolserver.com/. |
6 | * |
7 | * Software distributed under the License is distributed on an "AS IS" |
8 | * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See |
9 | * the License for the specific language governing rights and limitations |
10 | * under the License. |
11 | * |
12 | * The Original Code is AOLserver Code and related documentation |
13 | * distributed by AOL. |
14 | * |
15 | * The Initial Developer of the Original Code is America Online, |
16 | * Inc. Portions created by AOL are Copyright (C) 1999 America Online, |
17 | * Inc. All Rights Reserved. |
18 | * |
19 | * Alternatively, the contents of this file may be used under the terms |
20 | * of the GNU General Public License (the "GPL"), in which case the |
21 | * provisions of GPL are applicable instead of those above. If you wish |
22 | * to allow use of your version of this file only under the terms of the |
23 | * GPL and not to allow others to use your version of this file under the |
24 | * License, indicate your decision by deleting the provisions above and |
25 | * replace them with the notice and other provisions required by the GPL. |
26 | * If you do not delete the provisions above, a recipient may use your |
27 | * version of this file under either the License or the GPL. |
28 | */ |
29 | |
30 | |
31 | /* |
32 | * tclconf.c -- |
33 | * |
34 | * Tcl commands for reading config file info. |
35 | */ |
36 | |
37 | static const char *RCSID = "@(#) $Header: /cvsroot-fuse/aolserver/aolserver/nsd/tclconf.c,v 1.7 2001/12/05 22:46:21 jgdavidson Exp $, compiled: " __DATE__ " " __TIME__; |
38 | |
39 | #include "nsd.h" |
40 | |
41 | |
42 | /* |
43 | *---------------------------------------------------------------------- |
44 | * |
45 | * <a href="/cvs/aolserver/aolserver/nsd/tclconf.c#A_NsTclConfigCmd">NsTclConfigCmd</a> -- |
46 | * |
47 | * Implements ns_config. |
48 | * |
49 | * Results: |
50 | * Tcl result. |
51 | * |
52 | * Side effects: |
53 | * See docs. |
54 | * |
55 | *---------------------------------------------------------------------- |
56 | */ |
57 | |
58 | int |
59 | <a href="/cvs/aolserver/aolserver/nsd/tclconf.c#A_NsTclConfigCmd">NsTclConfigCmd</a>(ClientData dummy, Tcl_Interp *interp, int argc, char **argv) |
60 | { |
61 | char *value; |
62 | int i; |
63 | int fHasDefault = NS_FALSE; |
64 | int defaultIndex = 0; |
65 | |
66 | if (argc < 3 || argc > 5) { |
67 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
68 | argv[0], " ?-exact | -bool | -int? section key ?default?\"", NULL); |
69 | return TCL_ERROR; |
70 | } |
71 | |
72 | if (argv[1][0] == '-') { |
73 | if (argc == 5) { |
74 | fHasDefault = NS_TRUE; |
75 | defaultIndex = 4; |
76 | } |
77 | } else if (argc == 4) { |
78 | fHasDefault = NS_TRUE; |
79 | defaultIndex = 3; |
80 | } |
81 | |
82 | if (STREQ(argv[1], "-exact")) { |
83 | value = <a href="/cvs/aolserver/aolserver/nsd/config.c#A_Ns_ConfigGetValueExact">Ns_ConfigGetValueExact</a>(argv[2], argv[3]); |
84 | |
85 | if (value == NULL && fHasDefault) { |
86 | value = argv[defaultIndex]; |
87 | } |
88 | } else if (STREQ(argv[1], "-int")) { |
89 | if (<a href="/cvs/aolserver/aolserver/nsd/config.c#A_Ns_ConfigGetInt">Ns_ConfigGetInt</a>(argv[2], argv[3], &i)) { |
90 | Tcl_SetObjResult(interp, Tcl_NewIntObj(i)); |
91 | return TCL_OK; |
92 | } else if (fHasDefault) { |
93 | if (Tcl_GetInt(interp, argv[defaultIndex], &i) != TCL_OK) { |
94 | return TCL_ERROR; |
95 | } |
96 | Tcl_SetObjResult(interp, Tcl_NewIntObj(i)); |
97 | return TCL_OK; |
98 | } |
99 | value = NULL; |
100 | } else if (STREQ(argv[1], "-bool")) { |
101 | int iValue; |
102 | |
103 | if (<a href="/cvs/aolserver/aolserver/nsd/config.c#A_Ns_ConfigGetBool">Ns_ConfigGetBool</a>(argv[2], argv[3], &iValue) == NS_FALSE) { |
104 | if (fHasDefault) { |
105 | if ( Tcl_GetBoolean(interp, argv[defaultIndex], &iValue) |
106 | != TCL_OK) { |
107 | return TCL_ERROR; |
108 | } |
109 | |
110 | value = (iValue) ? "1" : "0"; |
111 | |
112 | } else { |
113 | value = NULL; |
114 | } |
115 | } else { |
116 | value = (iValue) ? "1" : "0"; |
117 | } |
118 | } else if (argc == 3 || argc == 4) { |
119 | value = <a href="/cvs/aolserver/aolserver/nsd/config.c#A_Ns_ConfigGetValue">Ns_ConfigGetValue</a>(argv[1], argv[2]); |
120 | |
121 | if (value == NULL && fHasDefault) { |
122 | value = argv[defaultIndex]; |
123 | } |
124 | } else { |
125 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
126 | argv[0], " ?-exact | -bool | -int? section key ?default?\"", NULL); |
127 | return TCL_ERROR; |
128 | } |
129 | if (value != NULL) { |
130 | Tcl_SetResult(interp, value, TCL_STATIC); |
131 | } |
132 | return TCL_OK; |
133 | } |
134 | |
135 | |
136 | /* |
137 | *---------------------------------------------------------------------- |
138 | * |
139 | * <a href="/cvs/aolserver/aolserver/nsd/tclconf.c#A_NsTclConfigSectionCmd">NsTclConfigSectionCmd</a> -- |
140 | * |
141 | * Implements ns_configsection. |
142 | * |
143 | * Results: |
144 | * Tcl result. |
145 | * |
146 | * Side effects: |
147 | * See docs. |
148 | * |
149 | *---------------------------------------------------------------------- |
150 | */ |
151 | |
152 | int |
153 | <a href="/cvs/aolserver/aolserver/nsd/tclconf.c#A_NsTclConfigSectionCmd">NsTclConfigSectionCmd</a>(ClientData dummy, Tcl_Interp *interp, int argc, |
154 | char **argv) |
155 | { |
156 | Ns_Set *set; |
157 | |
158 | if (argc != 2) { |
159 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
160 | argv[0], " key\"", NULL); |
161 | return TCL_ERROR; |
162 | } |
163 | set = <a href="/cvs/aolserver/aolserver/nsd/config.c#A_Ns_ConfigGetSection">Ns_ConfigGetSection</a>(argv[1]); |
164 | if (set == NULL) { |
165 | Tcl_SetResult(interp, "", TCL_STATIC); |
166 | } else { |
167 | <a href="/cvs/aolserver/aolserver/nsd/tclset.c#A_Ns_TclEnterSet">Ns_TclEnterSet</a>(interp, set, NS_TCL_SET_STATIC); |
168 | } |
169 | return TCL_OK; |
170 | } |
171 | |
172 | |
173 | /* |
174 | *---------------------------------------------------------------------- |
175 | * |
176 | * <a href="/cvs/aolserver/aolserver/nsd/tclconf.c#A_NsTclConfigSectionsCmd">NsTclConfigSectionsCmd</a> -- |
177 | * |
178 | * Implements ns_configsections. |
179 | * |
180 | * Results: |
181 | * Tcl result. |
182 | * |
183 | * Side effects: |
184 | * See docs. |
185 | * |
186 | *---------------------------------------------------------------------- |
187 | */ |
188 | |
189 | int |
190 | <a href="/cvs/aolserver/aolserver/nsd/tclconf.c#A_NsTclConfigSectionsCmd">NsTclConfigSectionsCmd</a>(ClientData dummy, Tcl_Interp *interp, int argc, |
191 | char **argv) |
192 | { |
193 | Ns_Set **sets; |
194 | int i; |
195 | |
196 | if (argc != 1) { |
197 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
198 | argv[0], " key\"", NULL); |
199 | return TCL_ERROR; |
200 | } |
201 | sets = <a href="/cvs/aolserver/aolserver/nsd/config.c#A_Ns_ConfigGetSections">Ns_ConfigGetSections</a>(); |
202 | for (i = 0; sets[i] != NULL; i++) { |
203 | <a href="/cvs/aolserver/aolserver/nsd/tclset.c#A_Ns_TclEnterSet">Ns_TclEnterSet</a>(interp, sets[i], NS_TCL_SET_STATIC); |
204 | } |
205 | ns_free(sets); |
206 | return TCL_OK; |
207 | } |
Copyright © 2010 Geeknet, Inc. All rights reserved. Terms of Use