counter.anubis
2.77 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
*Project* Anubis
A counter for web pages.
read tools/basis.anubis
read web/making_a_web_site.anubis
*Public*
This is the counter to be inserted into a web page:
public define HTML_Off_Form
web_counter
(
String directory, // where the counter file will be located
String name, // name of counter
Int text_size // size of characters of counter
).
Below is the function to call to increment the counter.
public define One
increment_web_counter
(
String directory, // where the counter file will be located
String name // name of counter
).
In order to reset the counter to 0, just delete the file:
directory+"/"+name+".counter"
*Private*
define List(Word8)
zero_pad
(
List(Word8) l,
Int n
) =
if length(l) < n
then zero_pad(['0' . l],n)
else l.
define HTML_Off_Form
web_counter
(
Int n, // value of counter
Int text_size // size of text
) =
with black = rgb(0,0,0),
white = rgb(255,255,255),
table([border(1,0,1,black)],[row(
table([border(0,1,0,black),background_color(black)],[row(
[cell([background_color(black),width(2)],text([],"")) .
map((Word8 c) |-> cell([background_color(black),width(8),h_center],
text([size(truncate_to_Word32(text_size)),color(white),bold],""+(to_Word32(c)-'0'))),
zero_pad(explode(to_decimal(n)),8))]
)])
)]).
public define HTML_Off_Form
web_counter
(
String directory, // where the counter file will be located
String name, // name of counter
Int text_size // size of characters of counter
) =
if (RetrieveResult(Int))retrieve(directory+"/"+name+".counter") is
{
cannot_find_file then web_counter(0,text_size),
read_error then web_counter(0,text_size),
type_error then web_counter(0,text_size),
ok(n) then web_counter(n,text_size),
}.
public define One
increment_web_counter
(
String directory,
String name,
) =
with path = directory+"/"+name+".counter",
protect
if (RetrieveResult(Int))retrieve(path) is
{
cannot_find_file then forget(save((Int)1,path)),
read_error then unique,
type_error then unique,
ok(n) then forget(save((Int)(n+1),path))
}.