comparison src/c/lacweb.c @ 120:6230bdd122e7

Passing an argument to a web function
author Adam Chlipala <adamc@hcoop.net>
date Sun, 13 Jul 2008 20:07:10 -0400
parents 94856a3b4752
children b1cfe49ce692
comparison
equal deleted inserted replaced
119:7fdc146b2bc2 120:6230bdd122e7
122 lw_Basis_attrifyInt_w_unsafe(ctx, c); 122 lw_Basis_attrifyInt_w_unsafe(ctx, c);
123 lw_writec_unsafe(ctx, ';'); 123 lw_writec_unsafe(ctx, ';');
124 } 124 }
125 } 125 }
126 } 126 }
127
128
129 char *lw_Basis_urlifyInt(lw_Basis_int n) {
130 return "0";
131 }
132
133 char *lw_Basis_urlifyFloat(lw_Basis_float n) {
134 return "0.0";
135 }
136
137 char *lw_Basis_urlifyString(lw_Basis_string s) {
138 return "";
139 }
140
141 static void lw_Basis_urlifyInt_w_unsafe(lw_context ctx, lw_Basis_int n) {
142 int len;
143
144 sprintf(ctx->page_front, "%d%n", n, &len);
145 ctx->page_front += len;
146 }
147
148 void lw_Basis_urlifyInt_w(lw_context ctx, lw_Basis_int n) {
149 lw_check(ctx, INTS_MAX);
150 lw_Basis_urlifyInt_w_unsafe(ctx, n);
151 }
152
153 void lw_Basis_urlifyFloat_w(lw_context ctx, lw_Basis_float n) {
154 int len;
155
156 lw_check(ctx, FLOATS_MAX);
157 sprintf(ctx->page_front, "%g%n", n, &len);
158 ctx->page_front += len;
159 }
160
161 void lw_Basis_urlifyString_w(lw_context ctx, lw_Basis_string s) {
162 lw_check(ctx, strlen(s) * 3);
163
164 for (; *s; s++) {
165 char c = *s;
166
167 if (c == ' ')
168 lw_writec_unsafe(ctx, '+');
169 else if (isalnum(c))
170 lw_writec_unsafe(ctx, c);
171 else {
172 sprintf(ctx->page_front, "%%%02X", c);
173 ctx->page_front += 3;
174 }
175 }
176 }
177
178
179 lw_Basis_int lw_unurlifyInt(char **s) {
180 char *new_s = strchr(*s, '/');
181 int r;
182
183 if (new_s)
184 *new_s++ = 0;
185 else
186 new_s = strchr(*s, 0);
187
188 r = atoi(*s);
189 *s = new_s;
190 return r;
191 }
192
193 lw_Basis_float lw_unurlifyFloat(char **s) {
194 char *new_s = strchr(*s, '/');
195 int r;
196
197 if (new_s)
198 *new_s++ = 0;
199 else
200 new_s = strchr(*s, 0);
201
202 r = atof(*s);
203 *s = new_s;
204 return r;
205 }
206
207 lw_Basis_string lw_unurlifyString(char **s) {
208 return "";
209 }