chiark / gitweb /
changelog: start 1.3.3
[chiark-tcl.git] / cdb / cdb.tct
1 # cdb, cdb-wr - Tcl bindings for tinycdb and a journalling write extension
2 # Copyright 2006-2012 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, see <http://www.gnu.org/licenses/>.
16
17
18 Table *cdbtoplevel TopLevel_Command
19         cdb
20                 dispatch(Cdb/_SubCommand, "cdb subcommand")
21         cdb-wr
22                 dispatch(Cdbwr/_SubCommand, "cdb-wr subcommand")
23
24 Table cdb Cdb_SubCommand
25         open
26                 path    string
27                 =>      iddata(&cdbtcl_databases)
28         lookup
29                 db      iddata(&cdbtcl_databases)
30                 key     obj
31                 ?def    obj
32                 =>      obj
33         lookup-hb
34                 db      iddata(&cdbtcl_databases)
35                 key     hb
36                 ?def    obj
37                 =>      obj
38         close
39                 db      iddata(&cdbtcl_databases)
40
41 Table cdbwr Cdbwr_SubCommand
42         create-empty 0
43                 pathb   string
44                 # files:
45                 #       <pathb>.main
46                 #       <pathb>.lock
47                 #       <pathb>.cdb
48                 #       <pathb>.jrn
49                 #       <pathb>.tmp (might be new .main or new .cdb)
50                 # invariants:
51                 #       .lock is an empty file
52                 #         which is locked with fcntl by open
53                 #       .main is a cdb native text file
54                 #         and always exists
55                 #       .cdb is a cdb database containing data
56                 #         equivalent to and at least as recent as .main
57                 #         (maybe not identical, because .cdb may
58                 #         have been updated with data from .jrn but
59                 #         .main not yet); if .jrn does not exist then
60                 #         they are identical)
61                 #       .cdb may not exist; in which case it is to
62                 #         be treated as if it existed and was empty
63                 #         but this is maximally early (so main must
64                 #         exist and be empty since .main is never
65                 #         newer than .cdb)
66                 #       if .jrn exists, it is a cdb native
67                 #         text file _without the trailing newline_;
68                 #         its contents override values from .main or .cdb
69                 #       if .main.tmp or .cdb.tmp exists it is irrelevant
70                 # zero length values mean record is deleted (in .jrn only;
71                 #  forbidden elsewhere)
72                 # while db is open:
73                 #       .lock is locked
74                 #       .jrn and open hash table contain same info
75         open 0
76                 pathb   string
77                 on_info obj
78                 ?on_lexminval obj
79                 # on_lexminval present and not empty list: provides a
80                 #  script which returns the current lexminval.  In
81                 #  this case, occasionally,
82                 #  on_lexminval will be called and then entries whose
83                 #  value is lexically strictly less than lexminval
84                 #  will be deleted automatically.  The comparison
85                 #  is bytewise on the UTF-8 representations.
86                 =>      iddata(&cdbtcl_rwdatabases)
87         open-okjunk RWSCF_OKJUNK
88                 pathb   string
89                 on_info obj
90                 ?on_lexminval obj
91                 =>      iddata(&cdbtcl_rwdatabases)
92                 # on_info <event> <xinfo>...:
93                 # on_info open-clean <statistics-info-string>
94                 # on_info open-dirty-start <statistics-info-string>
95                 # on_info open-dirty-junk <problem-info-string> \
96                 #               <problem-error-code-list>
97                 # on_info open-dirty-done <statistics-info-string>
98                 # on_info compact-start <statistics-info-string>
99                 # on_info compact-done <statistics-info-string>
100                 # on_info close <statistics-info-string>
101         lookup 0
102                 db      iddata(&cdbtcl_rwdatabases)
103                 key     string
104                 ?def    obj
105                 =>      obj
106         lookup-hb 0
107                 db      iddata(&cdbtcl_rwdatabases)
108                 key     string
109                 ?def    obj
110                 =>      obj
111         delete 0
112                 db      iddata(&cdbtcl_rwdatabases)
113                 key     string
114         update 0
115                 db      iddata(&cdbtcl_rwdatabases)
116                 key     string
117                 value   obj
118         update-hb 0
119                 db      iddata(&cdbtcl_rwdatabases)
120                 key     string
121                 value   hb
122         compact-force 0
123                 db      iddata(&cdbtcl_rwdatabases)
124         compact-check 0
125                 db      iddata(&cdbtcl_rwdatabases)
126         compact-auto 0
127                 # this is the default
128                 db      iddata(&cdbtcl_rwdatabases)
129         compact-explicit 0
130                 db      iddata(&cdbtcl_rwdatabases)
131         close 0
132                 db      iddata(&cdbtcl_rwdatabases)
133
134 EntryExtra Cdbwr_SubCommand
135         unsigned flags;