chiark / gitweb /
9754324ee88439840591b096ad2f3e4085315562
[chiark-tcl.git] / cdb / cdb.tct
1 # cdb, cdb-wr - Tcl bindings for tinycdb and a journalling write extension
2 # Copyright 2006 Ian Jackson
3 #
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License as
6 # published by the Free Software Foundation; either version 2 of the
7 # License, or (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 # General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this library; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
17 # 02110-1301, USA.
18
19
20 Table *cdbtoplevel TopLevel_Command
21         cdb
22                 subcmd  enum(Cdb/_SubCommand, "cdb subcommand")
23                 ...     obj
24         cdb-wr
25                 subcmd  enum(Cdbwr/_SubCommand, "cdb-wr subcommand")
26                 ...     obj
27
28 Table cdb Cdb_SubCommand
29         open
30                 path    string
31                 =>      iddata(&cdbtcl_databases)
32         lookup
33                 db      iddata(&cdbtcl_databases)
34                 key     obj
35                 ?def    obj
36                 =>      obj
37         lookup-hb
38                 db      iddata(&cdbtcl_databases)
39                 key     hb
40                 ?def    obj
41                 =>      obj
42         close
43                 db      iddata(&cdbtcl_databases)
44
45 Table cdbwr Cdbwr_SubCommand
46         create-empty 0
47                 pathb   string
48                 # files:
49                 #       <pathb>.main
50                 #       <pathb>.lock
51                 #       <pathb>.cdb
52                 #       <pathb>.jrn
53                 #       <pathb>.tmp (might be new .main or new .cdb)
54                 # invariants:
55                 #       .lock is an empty file
56                 #         which is locked with fcntl by open
57                 #       .main is a cdb native text file
58                 #         and always exists
59                 #       .cdb is a cdb database containing data
60                 #         equivalent to and at least as recent as .main
61                 #         (maybe not identical, because .cdb may
62                 #         have been updated with data from .jrn but
63                 #         .main not yet); if .jrn does not exist then
64                 #         they are identical)
65                 #       .cdb may not exist; in which case it is to
66                 #         be treated as if it existed and was empty
67                 #         but this is maximally early (so main must
68                 #         exist and be empty since .main is never
69                 #         newer than .cdb)
70                 #       if .jrn exists, it is a cdb native
71                 #         text file _without the trailing newline_;
72                 #         its contents override values from .main or .cdb
73                 #       if .main.tmp or .cdb.tmp exists it is irrelevant
74                 # zero length values mean record is deleted (in .jrn only;
75                 #  forbidden elsewhere)
76                 # while db is open:
77                 #       .lock is locked
78                 #       .jrn and open hash table contain same info
79         open 0
80                 pathb   string
81                 on_info obj
82                 ?on_lexminval obj
83                 # on_lexminval present and not empty list: provides a
84                 #  script which returns the current lexminval.  In
85                 #  this case, occasionally,
86                 #  on_lexminval will be called and then entries whose
87                 #  value is lexically strictly less than lexminval
88                 #  will be deleted automatically.  The comparison
89                 #  is bytewise on the UTF-8 representations.
90                 =>      iddata(&cdbtcl_rwdatabases)
91         open-okjunk RWSCF_OKJUNK
92                 pathb   string
93                 on_info obj
94                 ?on_lexminval obj
95                 =>      iddata(&cdbtcl_rwdatabases)
96                 # on_info <event> <xinfo>...:
97                 # on_info open-clean <statistics-info-string>
98                 # on_info open-dirty-start <statistics-info-string>
99                 # on_info open-dirty-junk <problem-info-string> \
100                 #               <problem-error-code-list>
101                 # on_info open-dirty-done <statistics-info-string>
102                 # on_info compact-start <statistics-info-string>
103                 # on_info compact-done <statistics-info-string>
104                 # on_info close <statistics-info-string>
105         lookup 0
106                 db      iddata(&cdbtcl_rwdatabases)
107                 key     string
108                 ?def    obj
109                 =>      obj
110         lookup-hb 0
111                 db      iddata(&cdbtcl_rwdatabases)
112                 key     string
113                 ?def    obj
114                 =>      obj
115         delete 0
116                 db      iddata(&cdbtcl_rwdatabases)
117                 key     string
118         update 0
119                 db      iddata(&cdbtcl_rwdatabases)
120                 key     string
121                 value   obj
122         update-hb 0
123                 db      iddata(&cdbtcl_rwdatabases)
124                 key     string
125                 value   hb
126         compact-force 0
127                 db      iddata(&cdbtcl_rwdatabases)
128         compact-check 0
129                 db      iddata(&cdbtcl_rwdatabases)
130         compact-auto 0
131                 # this is the default
132                 db      iddata(&cdbtcl_rwdatabases)
133         compact-explicit 0
134                 db      iddata(&cdbtcl_rwdatabases)
135         close 0
136                 db      iddata(&cdbtcl_rwdatabases)
137
138 EntryExtra Cdbwr_SubCommand
139         unsigned flags;