File: clock.pike

package info (click to toggle)
roxen 1.2beta2-2
  • links: PTS
  • area: contrib
  • in suites: hamm
  • size: 16,948 kB
  • ctags: 8,589
  • sloc: ansic: 89,632; asm: 8,431; sh: 2,915; makefile: 1,787; cpp: 377
file content (58 lines) | stat: -rw-r--r-- 1,396 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// This is a Clock Module.

string cvs_version = "$Id: clock.pike,v 1.2 1996/12/01 19:18:48 per Exp $";
// One of the first modules written for Spinner, here for nostalgical
// reasons.  It could be used as an example of how to write a simple
// location module.

#include <module.h>

inherit "module";
inherit "roxenlib";

void create()
{
  defvar("modification", 0, "Time modification", TYPE_INT, 
	 "Time difference in seconds from system clock.");

  defvar("mountpoint", "/clock/", "Mount point", TYPE_LOCATION, 
	 "Clock location in filesystem.");
}

mixed *register_module()
{
  return ({ 
    MODULE_LOCATION,
    "Explicit clock", 
    "This is the Clock Module.",
    });
}

string query_location() { return query("mountpoint"); }

int my_time() {  return time(1)+query("modification"); }

mapping find_file( string f )
{
  if((int)f)
    return http_string_answer("<title>And the time is...</title>"+
			      "<h1>Local time: "+ctime((int)f)+
			      "</h1><h1>GMT: "+http_date((int)f)+"</h1>");

  return http_string_answer("<html><head><title>" + ctime(my_time())
			    +"</title></head><body><h1>"
			    +ctime(time(1))+"</h1></body></html>\n")
    + ([ "extra_heads":
	([
	  "Expires": http_date(time(1)+5),
	  "Refresh":5-time(1)%5,
	  "Last-Modified":http_date(time(1)-1)
	  ])
	]);
}

string query_name()
{
  return query("mountpoint")+" ("+ctime(my_time())[11..15]+")";
}