comparison src/cjr_print.sml @ 2046:ced78ef1c82f

New .urp directive: file
author Adam Chlipala <adam@chlipala.net>
date Thu, 31 Jul 2014 09:56:41 -0400
parents ac1be85e91ad
children 4d64af730e35
comparison
equal deleted inserted replaced
2045:534577e429e1 2046:ced78ef1c82f
1 (* Copyright (c) 2008-2012, Adam Chlipala 1 (* Copyright (c) 2008-2014, Adam Chlipala
2 * All rights reserved. 2 * All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met: 5 * modification, are permitted provided that the following conditions are met:
6 * 6 *
3291 val onError = ListUtil.search (fn (DOnError n, _) => SOME n | _ => NONE) ds 3291 val onError = ListUtil.search (fn (DOnError n, _) => SOME n | _ => NONE) ds
3292 3292
3293 val now = Time.now () 3293 val now = Time.now ()
3294 val nowD = Date.fromTimeUniv now 3294 val nowD = Date.fromTimeUniv now
3295 val rfcFmt = "%a, %d %b %Y %H:%M:%S GMT" 3295 val rfcFmt = "%a, %d %b %Y %H:%M:%S GMT"
3296
3297 fun hexifyByte (b : Word8.word) : string =
3298 let
3299 val s = Int.fmt StringCvt.HEX (Word8.toInt b)
3300 in
3301 "\\x" ^ (if size s < 2 then "0" else "") ^ s
3302 end
3303
3304 fun hexify (v : Word8Vector.vector) : string =
3305 String.concat (Word8Vector.foldr (fn (b, ls) =>
3306 hexifyByte b :: ls) [] v)
3296 in 3307 in
3297 box [string "#include \"", 3308 box [string "#include \"",
3298 string (OS.Path.joinDirFile {dir = !Settings.configInclude, 3309 string (OS.Path.joinDirFile {dir = !Settings.configInclude,
3299 file = "config.h"}), 3310 file = "config.h"}),
3300 string "\"", 3311 string "\"",
3474 string "return;", 3485 string "return;",
3475 newline], 3486 newline],
3476 string "}", 3487 string "}",
3477 newline, 3488 newline,
3478 newline, 3489 newline,
3479 string "uw_write_header(ctx, \"Content-type: text/javascript\\r\\n\");", 3490 string "uw_write_header(ctx, \"Content-Type: text/javascript\\r\\n\");",
3480 newline, 3491 newline,
3481 string ("uw_write_header(ctx, \"Last-modified: " ^ Date.fmt rfcFmt nowD ^ "\\r\\n\");"), 3492 string ("uw_write_header(ctx, \"Last-Modified: " ^ Date.fmt rfcFmt nowD ^ "\\r\\n\");"),
3482 newline, 3493 newline,
3483 string ("uw_write_header(ctx, \"Cache-Control: max-age=31536000, public\\r\\n\");"), 3494 string ("uw_write_header(ctx, \"Cache-Control: max-age=31536000, public\\r\\n\");"),
3484 newline, 3495 newline,
3485 string "uw_write(ctx, jslib);", 3496 string "uw_write(ctx, jslib);",
3486 newline, 3497 newline,
3487 string "return;", 3498 string "return;",
3488 newline], 3499 newline],
3489 string "}", 3500 string "}",
3501 newline,
3502 newline,
3503
3504 p_list_sep newline (fn r =>
3505 box [string "if (!strcmp(request, \"",
3506 string (String.toCString (#Uri r)),
3507 string "\")) {",
3508 newline,
3509 box [(case #ContentType r of
3510 NONE => box []
3511 | SOME ct => box [string "uw_write_header(ctx, \"Content-Type: ",
3512 string (String.toCString ct),
3513 string "\\r\\n\");",
3514 newline]),
3515 string ("uw_write_header(ctx, \"Last-Modified: " ^ Date.fmt rfcFmt (Date.fromTimeUniv (#LastModified r)) ^ "\\r\\n\");"),
3516 newline,
3517 string ("uw_write_header(ctx, \"Content-Length: " ^ Int.toString (Word8Vector.length (#Bytes r)) ^ "\\r\\n\");"),
3518 newline,
3519 string ("uw_write_header(ctx, \"Cache-Control: max-age=31536000, public\\r\\n\");"),
3520 newline,
3521 string "uw_replace_page(ctx, \"",
3522 string (hexify (#Bytes r)),
3523 string "\", ",
3524 string (Int.toString (Word8Vector.length (#Bytes r))),
3525 string ");",
3526 newline,
3527 string "return;",
3528 newline],
3529 string "};",
3530 newline]) (Settings.listFiles ()),
3531
3490 newline, 3532 newline,
3491 p_list_sep newline (fn x => x) pds', 3533 p_list_sep newline (fn x => x) pds',
3492 newline, 3534 newline,
3493 string "uw_clear_headers(ctx);", 3535 string "uw_clear_headers(ctx);",
3494 newline, 3536 newline,