Tcl Library Source Code

Check-in [b71e7a1a19]
Login
Bounty program for improvements to Tcl and certain Tcl packages.
Tcl 2019 Conference, Houston/TX, US, Nov 4-8
Send your abstracts to [email protected]
or submit via the online form by Sep 9.

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Fixed various documentation files. - Added missing requirements of the package itself, throwing off the validate command of sak. - Added some missing documentation files.
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: b71e7a1a19a23d14df371fe4ffa8b621cb5a1891
User & Date: andreask 2013-12-18 00:34:38
Context
2013-12-18
17:56
Merged pt work. check-in: 37f7976d5a user: aku tags: trunk
00:34
Fixed various documentation files. - Added missing requirements of the package itself, throwing off the validate command of sak. - Added some missing documentation files. check-in: b71e7a1a19 user: andreask tags: trunk
2013-12-17
21:28
Fixed various documentation files. - Added missing requirements of the package itself, throwing off the validate command of sak. - Added some missing documentation files. check-in: 1435afdcde user: andreask tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to modules/doctools2base/ChangeLog.





1
2
3
4
5
6
7



2013-02-01  Andreas Kupries  <[email protected]>

	*
	* Released and tagged Tcllib 1.15 ========================
	* 

2011-12-13  Andreas Kupries  <[email protected]>
>
>
>
>







1
2
3
4
5
6
7
8
9
10
11
2013-12-17  Andreas Kupries  <[email protected]>

	* tcl_parse.man: Fixed missing requirement of the package itself.

2013-02-01  Andreas Kupries  <[email protected]ge.net>

	*
	* Released and tagged Tcllib 1.15 ========================
	* 

2011-12-13  Andreas Kupries  <[email protected]>

Changes to modules/doctools2base/tcl_parse.man.

14
15
16
17
18
19
20

21
22
23
24
25
26
27
[require snit]
[require fileutil]
[require logger]
[require struct::list]
[require struct::stack]
[require struct::set]
[require treeql]

[description]

This package provides commands for parsing text with embedded Tcl
commands as accepted by the Tcl builtin command
[cmd {subst -novariables}]. The result of the parsing is an abstract
syntax tree.







>







14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
[require snit]
[require fileutil]
[require logger]
[require struct::list]
[require struct::stack]
[require struct::set]
[require treeql]
[require doctools::tcl::parse]
[description]

This package provides commands for parsing text with embedded Tcl
commands as accepted by the Tcl builtin command
[cmd {subst -novariables}]. The result of the parsing is an abstract
syntax tree.

Changes to modules/pt/ChangeLog.

1
2
3
4


5
6
7
8
9
10
11
2013-12-17  Andreas Kupries <[email protected]>

	* pt_parse_peg.man: Added missing documentation for the PEG parser
	  package.



2013-12-06  Andreas Kupries <[email protected]>

	* tools/regenerate_parsers.tcl: Ticket [f5155519e7]. Dropped use
	* ../../apps/pt: of bash. Switched to easier to read invokation
	  without all the shell tricks and magic.




>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
2013-12-17  Andreas Kupries <[email protected]>

	* pt_parse_peg.man: Added missing documentation for the PEG parser
	  package.
	* pt_peg_op.man: Added missing documentation for this utility package.
	* pt_peg_op.tcl: Exported 'minimize'.

2013-12-06  Andreas Kupries <[email protected]>

	* tools/regenerate_parsers.tcl: Ticket [f5155519e7]. Dropped use
	* ../../apps/pt: of bash. Switched to easier to read invokation
	  without all the shell tricks and magic.

Changes to modules/pt/pt_parse_peg.man.

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
This package provides a class whose instances are parsers for parsing
expression grammars in textual form.

[section {Class API}]

[list_begin definitions]
[call [cmd className] [opt [arg objectName]]]

The class command constructs parser instances, i.e. objects. The
result of the command is the fully-qualified name of the instance
command.

[para]

If no [arg objectName] is specified the class will generate and use an
automatic name. If the [arg objectName] was specified, but is not
fully qualified the command will be created in the curent namespace.

[list_end]

[section {Instances API}]

All parser instances provide at least the methods shown below:

[list_begin definitions]
[include include/std_parser_object_api.inc]
[list_end]

[include include/feedback.inc]
[manpage_end]






|









|













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
This package provides a class whose instances are parsers for parsing
expression grammars in textual form.

[section {Class API}]

[list_begin definitions]
[call [cmd pt::parse::peg] [opt [arg objectName]]]

The class command constructs parser instances, i.e. objects. The
result of the command is the fully-qualified name of the instance
command.

[para]

If no [arg objectName] is specified the class will generate and use an
automatic name. If the [arg objectName] was specified, but is not
fully qualified the command will be created in the current namespace.

[list_end]

[section {Instances API}]

All parser instances provide at least the methods shown below:

[list_begin definitions]
[include include/std_parser_object_api.inc]
[list_end]

[include include/feedback.inc]
[manpage_end]

Changes to modules/pt/pt_parser_api.man.

31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
result of the command is the fully-qualified name of the instance
command.

[para]

If no [arg objectName] is specified the class will generate and use an
automatic name. If the [arg objectName] was specified, but is not
fully qualified the command will be created in the curent namespace.

[list_end]

[section {Instance API}]

All parser instances provide at least the methods shown below:







|







31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
result of the command is the fully-qualified name of the instance
command.

[para]

If no [arg objectName] is specified the class will generate and use an
automatic name. If the [arg objectName] was specified, but is not
fully qualified the command will be created in the current namespace.

[list_end]

[section {Instance API}]

All parser instances provide at least the methods shown below:

Added modules/pt/pt_peg_op.man.






































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
[comment {-*- text -*- doctools manpage}]
[manpage_begin pt_peg_op i 1]
[include include/module.inc]
[titledesc {Parser Tools PE Grammar Utility Operations}]
[require pt::peg::op 1]
[description]
[include include/ref_intro.inc]

This package provides a number of utility commands manipulating a PE
grammar (container) in various ways.

[section API]

[list_begin definitions]
[comment ---------------------------------------------------------------------]
[call [cmd ::peg::peg::op] [method called] [arg container]]

This command determines the static call structure for the nonterminal
symbols of the grammar stored in the [arg container].

[para] The result of the command is a dictionary mapping from each
symbol to the symbols it calls. The empty string is the key used to
represent the start expression of the grammar.

[para] The grammar in the container is not modified.

[para] The [arg container] instance has to expose a method API as is
provided by the package [package pt::peg::container].

[comment ---------------------------------------------------------------------]
[call [cmd ::peg::peg::op] [method dechain] [arg container]]

This command simplifies all symbols which just chain to a different
symbol by inlining the right hand side of the called symbol in its
callers. This works if and only the modes match properly, per the
decision table below.

[para][example {
caller called | dechain | notes
--------------+---------+-----------------------
value  value  |  yes    |  value is passed
value  leaf   |  yes    |  value is passed
value  void   |  yes    |  caller is implied void
leaf   value  |  no     |  generated value was discarded, inlined would not. called may be implied void.
leaf   leaf   |  no     |  s.a.
leaf   void   |  no     |  s.a.
void   value  |  no     |  caller drops value, inlined would not.
void   leaf   |  no     |  s.a.
void   void   |  yes    |
}]

[para] The result of the command is the empty string.

[para] The grammar in the container is directly modified. If that is
not wanted, a copy of the original container has to be used.

[para] The [arg container] instance has to expose a method API as is
provided by the package [package pt::peg::container].

[comment ---------------------------------------------------------------------]
[call [cmd ::peg::peg::op] [method {drop unreachable}] [arg container]]

This command removes all symbols from the grammar which are not
[method reachable].

[para] The result of the command is the empty string.

[para] The grammar in the container is directly modified. If that is
not wanted, a copy of the original container has to be used.

[para] The [arg container] instance has to expose a method API as is
provided by the package [package pt::peg::container].

[comment ---------------------------------------------------------------------]
[call [cmd ::peg::peg::op] [method {drop unrealizable}] [arg container]]

This command removes all symbols from the grammar which are not
[method realizable].

[para] The result of the command is the empty string.

[para] The grammar in the container is directly modified. If that is
not wanted, a copy of the original container has to be used.

[para] The [arg container] instance has to expose a method API as is
provided by the package [package pt::peg::container].

[comment ---------------------------------------------------------------------]
[call [cmd ::peg::peg::op] [method flatten] [arg container]]

This command flattens (see [package pt::pe::op]) all expressions in
the grammar, i.e. the start expression and the right hand sides of all
nonterminal symbols.

[para] The result of the command is the empty string.

[para] The grammar in the container is directly modified. If that is
not wanted, a copy of the original container has to be used.

[para] The [arg container] instance has to expose a method API as is
provided by the package [package pt::peg::container].

[comment ---------------------------------------------------------------------]
[call [cmd ::peg::peg::op] [method minimize] [arg container]]

This command reduces the provided grammar by applying most of the other methods of this package.

[para] After flattening the expressions it removes unreachable and
unrealizable symbols, flattens the expressions again, then optimizes
the symbol modes before collapsing symbol chains as much as possible.

[para] The result of the command is the empty string.

[para] The grammar in the container is directly modified. If that is
not wanted, a copy of the original container has to be used.

[para] The [arg container] instance has to expose a method API as is
provided by the package [package pt::peg::container].

[comment ---------------------------------------------------------------------]
[call [cmd ::peg::peg::op] [method modeopt] [arg container]]

This command optimizes the semantic modes of non-terminal symbols
according to the two rules below.

[list_begin enumerated]
[enum]  If a symbol X with mode [const value] calls no other symbols,
        i.e. uses only terminal symbols in whatever combination, then
	this can be represented simpler by using mode [const leaf].

[enum]	If a symbol X is only called from symbols with modes
	[const leaf] or [const void] then this symbol should have mode
	[const void] also, as any AST it could generate will be
	discarded anyway.
[list_end]

[para] The result of the command is the empty string.

[para] The grammar in the container is directly modified. If that is
not wanted, a copy of the original container has to be used.

[para] The [arg container] instance has to expose a method API as is
provided by the package [package pt::peg::container].

[comment ---------------------------------------------------------------------]
[call [cmd ::peg::peg::op] [method reachable] [arg container]]

This command computes the set of all nonterminal symbols which are
reachable from the start expression of the grammar. This is
essentially the transitive closure over [method called] and the
symbol's right hand sides, beginning with the start expression.

[para] The result of the command is the list of reachable symbols.

[para] The grammar in the container is not modified.

[para] The [arg container] instance has to expose a method API as is
provided by the package [package pt::peg::container].

[comment ---------------------------------------------------------------------]
[call [cmd ::peg::peg::op] [method realizable] [arg container]]

This command computes the set of all nonterminal symbols which are
realizable, i.e. can derive pure terminal phrases. This is done
iteratively, starting with state unrealizable for all and any, and
then updating all symbols which are realizable, propagating changes,
until nothing changes any more.

[para] The result of the command is the list of realizable symbols.

[para] The grammar in the container is not modified.

[para] The [arg container] instance has to expose a method API as is
provided by the package [package pt::peg::container].

[list_end]

[include include/feedback.inc]
[manpage_end]

Changes to modules/pt/pt_peg_op.tcl.

13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# # ## ### ##### ######## ############# #####################
##

namespace eval ::pt::peg::op {
    namespace export \
	flatten called reachable realizable \
	dechain drop modeopt

    namespace ensemble create

    namespace eval ::pt::peg::op::drop {
	namespace export \
	    unreachable unrealizable







|







13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# # ## ### ##### ######## ############# #####################
##

namespace eval ::pt::peg::op {
    namespace export \
	flatten called reachable realizable \
	dechain drop modeopt minimize

    namespace ensemble create

    namespace eval ::pt::peg::op::drop {
	namespace export \
	    unreachable unrealizable

Changes to modules/stooop/ChangeLog.






1
2
3
4
5
6
7




2013-02-01  Andreas Kupries  <[email protected]>

	*
	* Released and tagged Tcllib 1.15 ========================
	* 

2011-12-13  Andreas Kupries  <[email protected]>
>
>
>
>
>







1
2
3
4
5
6
7
8
9
10
11
12
2013-12-17  Andreas Kupries <[email protected]>

	* switched.man: Created a doctools-based manpage from the provided
	  HTML documentation.

2013-02-01  Andreas Kupries  <[email protected]>

	*
	* Released and tagged Tcllib 1.15 ========================
	* 

2011-12-13  Andreas Kupries  <[email protected]>

Added modules/stooop/switched.man.
















































































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
[comment {-*- tcl -*- doctools manpage}]
[manpage_begin switched n 2.2.1]
[keywords C++]
[keywords class]
[keywords object]
[keywords {object oriented}]
[moddesc   {Simple Tcl Only Object Oriented Programming}]
[titledesc {switch/option management.}]
[category  {Programming tools}]
[require Tcl 8.3]
[require switched [opt 2.2.1]]
[description]
[para]

The [class switched] class serves as base class for user classes with
switch / option configuration procedures. It provides facilities for
managing options through a simple interface.

[para] For example:

[example {
set vehicle [new car -length 4.5 -width 2 -power 100 -fuel diesel]
puts "my car was running on [switched::cget $vehicle -fuel]"
switched::configure $vehicle -power 40 -fuel electricity
puts "but is now running on clean [switched::cget $vehicle -fuel]"
}]

[para] Of course, as you might have guessed, the [class car] class is
derived from the [class switched] class. Let us see how it works:

[example {
class car {
    proc car {this args} switched {$args} {
        # car specific initialization code here
        switched::complete $this
    }
    ...
}
}]

[para] The switched class constructor takes the optional configuration
option / value pairs as parameters.

The switched class layer then completely manages the switched options:
it checks their validity, stores their values and provides a clean
interface to the user layer configuration setting procedures.

[para] The switched class members available to the programmer are:

[list_begin definitions]

[comment ---------------------------------------------------------------------]
[call [cmd <switched>] [method complete] [arg this]]

This procedure is used to tell the switched layer that the derived
class object (a car in the examples) is completely built.

At that time, the initial configuration of the switched object occurs,
using default option values (see procedure [method options])
eventually overridden by construction time values, passed at the time
of the [method new] operator invocation.

This procedure must be called only once, usually around or at the end
of the derived class constructor.

([emph Note]: Also check the [var complete] data member later in this
chapter).

[comment ---------------------------------------------------------------------]
[call [cmd <switched>] [method options] [arg this]]

This procedure must return the configuration description for
[emph all] options that the switched object will accept.

It is a pure virtual member procedure and therefore its implementation
is [emph mandatory] in the derived class layer.

The procedure must return a list of lists.

Each list pertains to a single option and is composed of the switch
name, the default value for the option and an optional initial value.

For example:

[para][example {
class car {
    ...
    proc options {this} {
        return [list\
            [list -fuel petrol petrol]\
            [list -length {} {}]\
            [list -power {} {}]\
            [list -width {} {}]\
        ]
    }
    proc set-fuel {this value} {
        ...
    }
    ...
}
}]

[para] In this case, 4 options are specified:
[option fuel], [option length], [option power] and [option width].

The default and initial values for the [option fuel] option are
identical and set to [option petrol].

For the other options, values are all empty.

[para] For each option, there must be a corresponding
[method set-[option option]] procedure defined in the derived class
layer.

For example, since we defined a [option fuel] option, there is a
[method set-fuel] procedure in the car class.

The parameters always are the object identifier (since this is not a
static procedure, but rather a dynamically defined virtual one),
followed by the new value for the option.

A [method set-[option option]] procedure is only invoked if the new
value differs from the current one (a caching scheme for improving
performance), or if there is no initial value set in the
[method options] procedure for that option.

[para] In this procedure, if the initial value differs from the
default value or is omitted, then initial configuration is forced and
the corresponding [method set-[option option]] procedure is invoked by
the switched [method complete] procedure located at the end of the
derived class constructor.

For example:

[example {
class car {
    ...
    proc options {this} {
        return [list\
            [list -fuel petrol]\
            [list -length {} {}]\
            [list -power 100 50]\
            [list -width {} {}]\
        ]
    }
    ...
}
}]

In this case, configuration is forced on the [option fuel] and
[option power] options, that is the corresponding

[method set-[option option]] procedures will be invoked when the
switched object is constructed (see [method set-[option option]]
procedures documentation below).

[para] For the [option fuel] option, since there is no initial value,
the [method set-[option fuel]] procedure is called with the default
value ([const petrol]) as argument.

For the [option power] option, since the initial value differs from
the default value, the [method set-[option power]] procedure is called
with the initial value as argument ([const 50]).

[para] For the other options, since the initial values (last elements
of the option lists) are identical to their default values, the
corresponding [method set-[option option]] procedures will not be
invoked. It is the programmer's responsibility to insure that the
initial option values are correct.

[comment ---------------------------------------------------------------------]
[call [cmd <switched>] [method set-[option option]] [arg this] [arg value]]

These procedures may be viewed as dynamic virtual functions.

There must be one implementation per supported option, as returned by
the [method options] procedure.

For example:

[example {
class car {
    ...
    proc options {this} {
        return [list\
            ...
            [list -width {} {}]\
        ]
    }
    ...
    proc set-width {this value} {
        ...
    }
    ...
}
}]

Since the [option -width] option was listed in the [method options]
procedure, a [method set-width] procedure implementation is provided, which
of course would proceed to set the width of the car (and would modify
the looks of a graphical representation, for example).

[para] As you add a supported [option option] in the list returned by
the [method options] procedure, the corresponding

[method set-[option option]] procedure may be called as soon as the
switched object is complete, which occurs when the switched level
[method complete] procedure is invoked.

For example:

[para][example {
class car {
    proc car {this args} switched {args} {
        ...
        switched::complete $this
   }
    ...
    proc options {this} {
        return [list\
            [list -fuel petrol]\
            [list -length 4.5]\
            [list -power 350]\
            [list -width 1.8]\
        ]
    }
    proc set-fuel {this value} {
        ...
    }
    proc set-length {this value} {
        ...
    }
    proc set-power {this value} {
        ...
    }
    proc set-width {this value} {
        ...
    }
}

new car
}]

[para] In this case, a new car is created with no options, which
causes the car constructor to be called, which in turns calls the
switched level [method complete] procedure after the car object layer
is completely initialized.

At this point, since there are no initial values in any option list in
the options procedure, the [method set-fuel] procedure is called with
its default value of [const petrol] as parameter, followed by the
[method set-length] call with [const 4.5] value, [method set-power]
with [const 350] value and finally with [method set-width] with
[const 1.8] as parameter.

This is a good way to test the [method set-[option option]] procedures
when debugging, and when done, just fill-in the initial option values.

[para] The switched layer checks that an option is valid (that is,
listed in the [method options] procedure) but obviously does not check
the validity of the value passed to the [method set-[option option]]
procedure, which should throw an error (for example by using the Tcl
error command) if the value is invalid.

[para] The switched layer also keeps track of the options current
values, so that a [method set-[option option]] procedure is called
only when the corresponding option value passed as parameter is
different from the current value (see [variable -option] data members
description).

[def [variable -option]]

[para] The [variable -option] data member is an options current value.

There is one for each option listed in the options procedure. It is a
read-only value which the switched layer checks against when an option
is changed.

It is rarely used at the layer derived from switched, except in the
few cases, such as in the following example:

[para][example {
...
proc car::options {this} {
    return {
        ...
        {-manufacturer {} {}}
        ...
    }
}

proc car::set-manufacturer {this value} {}

proc car::printData {this} {
    puts "manufacturer: $switched::($this,-manufacturer)"
    ...
}
}]

[para] In this case, the manufacturer's name is stored at the switched
layer level (this is why the set-manufacturer procedure has nothing to
do) and later retrieved in the printData procedure.

[def [variable complete]]

[para] The [variable complete] data member (not to be confused with
the [method complete] procedure) is a boolean.

Its initial value is [const false] and it is set to [const true] at
the very end of the switched [method complete] procedure.

It becomes useful when some options should be set at construction time
only and not dynamically, as the following example shows:

[para][example {
proc car::set-width {this value} {
    if {$switched::($this,complete)} {
        error {option -width cannot be set dynamically}
    }
    ...
}
}]

[list_end]

[vset CATEGORY stooop]
[include ../doctools2base/include/feedback.inc]
[manpage_end]

Changes to modules/zip/ChangeLog.






1
2
3
4
5
6
7




2013-04-05  Andreas Kupries <[email protected]>

	* encode.tcl: Extended the errors thrown by the packages with
	* decode.tcl: error codes usable by try/trap. Bumped versions
	  to 0.4 and 0.3 respectively.

2013-02-14  Andreas Kupries  <[email protected]>
>
>
>
>
>







1
2
3
4
5
6
7
8
9
10
11
12
2013-12-17  Andreas Kupries <[email protected]>

	* decode.man: Documented the zip archive decoder package.
	* encode.man: Documented the zip archive generator package.

2013-04-05  Andreas Kupries <[email protected]>

	* encode.tcl: Extended the errors thrown by the packages with
	* decode.tcl: error codes usable by try/trap. Bumped versions
	  to 0.4 and 0.3 respectively.

2013-02-14  Andreas Kupries  <[email protected]>

Added modules/zip/decode.man.






























































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
[comment {-*- tcl -*- doctools manpage}]
[manpage_begin zipfile::encode n 0.3]
[keywords decompression zip]
[copyright {2008-2012 Andreas Kupries}]
[moddesc {Zip archive handling}]
[titledesc {Access to zip archives}]
[category  File]
[require Tcl 8.4]
[require fileutil::magic::mimetype]
[require fileutil::decode 0.2]
[require Trf]
[require zlibtcl]
[require zipfile::decode [opt 0.4]]
[description]
[para]

This package provides commands to decompress and access the contents
of zip archives.

[section API]

[list_begin definitions]
[comment ---------------------------------------------------------------------]
[call [cmd ::zipfile::decode::archive]]

This command decodes the last opened (and not yet closed) zip archive
file.

The result of the command is a dictionary describing the contents of
the archive. The structure of this dictionary is not public. Proper
access should be made through the provided accessor command of this
package.

[comment { -- TODO? -- dictionary contents -- }]

[comment ---------------------------------------------------------------------]
[call [cmd ::zipfile::decode::close]]

This command releases all state associated with the last call of
[cmd ::zipfile::decode::open].

The result of the command is the empty string.

[comment ---------------------------------------------------------------------]
[call [cmd ::zipfile::decode::comment] [arg adict]]

This command takes a dictionary describing the currently open zip
archive file, as returned by [cmd ::zipfile::decode::archive], and
returns the global comment of the archive.

[comment ---------------------------------------------------------------------]
[call [cmd ::zipfile::decode::content] [arg archive]]

This is a convenience command which decodes the specified zip
[arg archive] file and returns the list of paths found in it as its
result.

[comment ---------------------------------------------------------------------]
[call [cmd ::zipfile::decode::copyfile] [arg adict] [arg path] [arg dst]]

This command takes a dictionary describing the currently open zip
archive file, as returned by [cmd ::zipfile::decode::archive], and
copies the decompressed contents of the file [arg path] in the archive
to the the file [arg dst].

An error is thrown if the file is not found in the archive.

[comment ---------------------------------------------------------------------]
[call [cmd ::zipfile::decode::files] [arg adict]]

This command takes a dictionary describing the currently open zip
archive file, as returned by [cmd ::zipfile::decode::archive], and
returns the list of files found in the archive.

[comment ---------------------------------------------------------------------]
[call [cmd ::zipfile::decode::getfile] [arg zdict] [arg path]]

This command takes a dictionary describing the currently open zip
archive file, as returned by [cmd ::zipfile::decode::archive], and
returns the decompressed contents of the file [arg path] in the archive.

An error is thrown if the file is not found in the archive.

[comment ---------------------------------------------------------------------]
[call [cmd ::zipfile::decode::hasfile] [arg adict] [arg path]]

This command takes a dictionary describing the currently open zip
archive file, as returned by [cmd ::zipfile::decode::archive], and
check if the specified [arg path] is found in the archive.

The result of the command is a boolean flag, [const true] if the path
is found, and [const false] otherwise.

[comment ---------------------------------------------------------------------]
[call [cmd ::zipfile::decode::open] [arg archive]]

This command takes the path of a zip [arg archive] file and prepares
it for decoding.

The result of the command is the empty string.

All important information is stored in global state.  If multiple open
calls are made one after the other only the state of the last call is
available to the other commands.

[comment ---------------------------------------------------------------------]
[call [cmd ::zipfile::decode::unzip] [arg adict] [arg dstdir]]

This command takes a dictionary describing the currently open zip
archive file, as returned by [cmd ::zipfile::decode::archive], and
unpacks the archive in the given destination directory [arg dstdir].

The result of the command is the empty string.

[comment ---------------------------------------------------------------------]
[call [cmd ::zipfile::decode::unzipfile] [arg archive] [arg dstdir]]

This is a convenience command which unpacks the specified zip
[arg archive] file in the given destination directory [arg dstdir].

[para] The result of the command is the empty string.

[list_end]

[vset CATEGORY zipfile]
[include ../doctools2base/include/feedback.inc]
[manpage_end]

Changes to modules/zip/decode.tcl.

115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
...
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
	CopyFile $src fd [file join $dst $src]

	unset fd
    }
    return
}

proc zipfile::decode::CopyFile {src fdv dst} {
    upvar 1 $fdv fd

    file mkdir [file dirname $dst]

    if {[string match */ $src]} {
	# Entry is a directory. Just create.
	file mkdir $dst
................................................................................

    # FUTURE: Run crc checksum on created file and compare to the
    # ......: stored information.

    return
}

proc zipfile::decode::GetFile {src fdv} {
    upvar 1 $fdv fd

    # Entry is a directory.
    if {[string match */ $src]} {return {}}

    # Empty files are a special case, we have
    # nothing to decompress.






|







 







|







115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
...
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
	CopyFile $src fd [file join $dst $src]

	unset fd
    }
    return
}

proc ::zipfile::decode::CopyFile {src fdv dst} {
    upvar 1 $fdv fd

    file mkdir [file dirname $dst]

    if {[string match */ $src]} {
	# Entry is a directory. Just create.
	file mkdir $dst
................................................................................

    # FUTURE: Run crc checksum on created file and compare to the
    # ......: stored information.

    return
}

proc ::zipfile::decode::GetFile {src fdv} {
    upvar 1 $fdv fd

    # Entry is a directory.
    if {[string match */ $src]} {return {}}

    # Empty files are a special case, we have
    # nothing to decompress.

Added modules/zip/encode.man.






























































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
[comment {-*- tcl -*- doctools manpage}]
[manpage_begin zipfile::encode n 0.3]
[keywords compression zip]
[copyright {2008-2009 Andreas Kupries}]
[moddesc {Zip archive handling}]
[titledesc {Generation of zip archives}]
[category  File]
[require Tcl 8.4]
[require logger]
[require Trf]
[require crc32]
[require snit]
[require zlibtcl]
[require fileutil]
[require zipfile::encode [opt 0.3]]
[description]
[para]

This package provides a class for the generation of zip archives.

[section {Class API}]

[list_begin definitions]
[call [cmd ::zipfile::encode] [opt [arg objectName]]]

The class command constructs encoder instances, i.e. objects. The
result of the command is the fully-qualified name of the instance
command.

[para]

If no [arg objectName] is specified the class will generate and use an
automatic name. If the [arg objectName] was specified, but is not
fully qualified the command will be created in the current namespace.

[list_end]

[section {Instance API}]

[list_begin definitions]

[comment ---------------------------------------------------------------------]
[call [cmd <encoder>] [method comment:] [arg text]]

This method specifies the text of the global comment for the archive.

The result of the method is the empty string.

In case of multiple calls to this method for the same encoder the data
from the last call prevails over all previous texts.

[comment ---------------------------------------------------------------------]
[call [cmd <encoder>] [method file:] [arg dst] [arg owned] [arg src]]

This method adds a new file to the archive.

The contents of the file are found in the filesystem at [arg src], and
will be stored in the archive under path [arg dst].

If the file is declared as [arg owned] by the archive the original
file will be deleted when the archive is constructed and written.

The result of the method is an empty string.

[comment ---------------------------------------------------------------------]
[call [cmd <encoder>] [method write] [arg archive]]

This method takes the global comment and all added files, encodes them
as a zip archive and stores the result at path [arg archive] in the
filesystem.

All added files which were owned by the archive are deleted at this
point.

[list_end]

[vset CATEGORY zipfile]
[include ../doctools2base/include/feedback.inc]
[manpage_end]