Mercurial > urweb
comparison src/cjr_print.sml @ 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 | 7fdc146b2bc2 |
children | 91027db5a07c |
comparison
equal
deleted
inserted
replaced
119:7fdc146b2bc2 | 120:6230bdd122e7 |
---|---|
171 string ");"], | 171 string ");"], |
172 newline, | 172 newline, |
173 string "}"] | 173 string "}"] |
174 end | 174 end |
175 | 175 |
176 fun p_page env (s, n) = | 176 fun unurlify (t, loc) = |
177 box [string "if (!strcmp(request, \"", | 177 case t of |
178 TFfi ("Basis", "int") => string "lw_unurlifyInt(&request)" | |
179 | TFfi ("Basis", "float") => string "lw_unurlifyFloat(&request)" | |
180 | TFfi ("Basis", "string") => string "lw_unurlifyString(&request)" | |
181 | |
182 | TRecord 0 => string "lw_unit_v" | |
183 | |
184 | _ => (ErrorMsg.errorAt loc "Unable to choose a URL decoding function"; | |
185 space) | |
186 | |
187 fun p_page env (s, n, ts) = | |
188 box [string "if (!strncmp(request, \"", | |
178 string (String.toString s), | 189 string (String.toString s), |
179 string "\")) {", | 190 string "\", ", |
191 string (Int.toString (size s)), | |
192 string ")) {", | |
180 newline, | 193 newline, |
181 p_enamed env n, | 194 string "request += ", |
182 string "(ctx, lw_unit_v);", | 195 string (Int.toString (size s)), |
196 string ";", | |
183 newline, | 197 newline, |
184 string "return;", | 198 string "if (*request == '/') ++request;", |
185 newline, | 199 newline, |
186 string "}", | 200 box [string "{", |
187 newline] | 201 newline, |
202 box (ListUtil.mapi (fn (i, t) => box [p_typ env t, | |
203 space, | |
204 string "arg", | |
205 string (Int.toString i), | |
206 space, | |
207 string "=", | |
208 space, | |
209 unurlify t, | |
210 string ";", | |
211 newline]) ts), | |
212 p_enamed env n, | |
213 string "(", | |
214 p_list_sep (box [string ",", space]) | |
215 (fn x => x) | |
216 (string "ctx" :: ListUtil.mapi (fn (i, _) => string ("arg" ^ Int.toString i)) ts), | |
217 string ");", | |
218 newline, | |
219 string "return;", | |
220 newline, | |
221 string "}", | |
222 newline, | |
223 string "}"] | |
224 ] | |
188 | 225 |
189 fun p_file env (ds, ps) = | 226 fun p_file env (ds, ps) = |
190 let | 227 let |
191 val (pds, env) = ListUtil.foldlMap (fn (d, env) => | 228 val (pds, env) = ListUtil.foldlMap (fn (d, env) => |
192 (p_decl env d, | 229 (p_decl env d, |