forked from ermine/sulci
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugin_vocabulary.ml.old
56 lines (50 loc) · 1.35 KB
/
plugin_vocabulary.ml.old
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
(*
* (c) 2004, 2005 Anastasia Gornostaeva
*)
open Xml
open Common
open Dbm
let open_dbm () =
let name = get_attr_s Config.config ~path:["plugins"; "vocabulary"] "name" in
Dbm.opendbm "vocabulary" [Dbm_create; Dbm_rdwr] 0o644
let dfn text from event xml out =
try
let eq = String.index text '=' in
let w1 = trim (String.sub text 0 eq) in
let w2 = trim (string_after text (eq+1)) in
let db = open_dbm () in
let () =
try
Dbm.add db w1 w2
with Dbm_error _ ->
Dbm.replace db w1 w2
in
close db;
out (make_msg xml
(Lang.get_msg ~xml "plugin_vocabulary_wrote" []))
with Not_found ->
out (make_msg xml
(Lang.get_msg ~xml "plugin_vocabulary_invalid_syntax" []))
let wtf text event from xml out =
if text = "" then
out (make_msg xml
(Lang.get_msg ~xml "plugin_vocabulary_invalid_syntax" []))
else
let query =
try
let q = String.index text '?' in
String.sub text 0 q
with Not_found -> text in
let db = open_dbm () in
let () =
try
let reply = Dbm.find db query in
out (make_msg xml reply)
with Not_found ->
out (make_msg xml
(Lang.get_msg ~xml "plugin_vocabulary_not_found" []))
in
close db
let _ =
Hooks.register_handle (Hooks.Command ("wtf", wtf));
Hooks.register_handle (Hooks.Command ("dfn", dfn));