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