File: external_bitmap.inc

package info (click to toggle)
critcl 3.3.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 9,680 kB
  • sloc: ansic: 41,058; tcl: 12,090; sh: 7,230; pascal: 3,456; asm: 3,058; ada: 1,681; cpp: 1,001; cs: 879; makefile: 333; perl: 104; xml: 95; f90: 10
file content (76 lines) | stat: -rw-r--r-- 2,320 bytes parent folder | download
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
[comment {-*- mode: tcl ; fill-column: 90 -*-}]

This section demonstrates how to convert from any kind of bit-mapped flags provided by an
external library to lists of Tcl strings, and the converse.

[list_begin enumerated]

[enum] For all that this is a part of how to
[sectref {Using External Libraries} {Use External Libraries}], for the demonstratation
only the basics are needed.

[enum][vset base][example {
    # http://man7.org/linux/man-pages/man7/inotify.7.html
    
    package require critcl::bitmap

    # critcl::cheaders - n/a, header is in system directories
    critcl::include sys/inotify.h
    
    critcl::bitmap::def tcl_inotify_events {
	accessed       IN_ACCESS
	all            IN_ALL_EVENTS
	attribute      IN_ATTRIB
	closed         IN_CLOSE
	closed-nowrite IN_CLOSE_NOWRITE
	closed-write   IN_CLOSE_WRITE
	created        IN_CREATE
	deleted        IN_DELETE
	deleted-self   IN_DELETE_SELF
	dir-only       IN_ONLYDIR
	dont-follow    IN_DONT_FOLLOW
	modified       IN_MODIFY
	move           IN_MOVE
	moved-from     IN_MOVED_FROM
	moved-self     IN_MOVE_SELF
	moved-to       IN_MOVED_TO
	oneshot        IN_ONESHOT
	open           IN_OPEN
	overflow       IN_Q_OVERFLOW
	unmount        IN_UNMOUNT
    } {
	all closed move oneshot
    }
    
    # encode: flag set to int
    critcl::cproc encode {tcl_inotify_events e} int {
	return e;
    }

    # decode: int to flag set
    critcl::cproc decode {int e} tcl_inotify_events {
	return e;
    }

}][vset rebuild]

[enum] The map converts between lists of the Tcl level strings listed on the left side to
the bit-union of the C values on the right side, and the reverse.

[para] It is noted that the four strings [const all], [const closed], [const move], and
[const oneshot] cannot be converted from C flags to list of strings, only from list to
bits.

[enum] It automatically generates [cmd critcl::argtype] and [cmd critcl::resulttype]
definitions.

[enum] [emph Attention] Like the default values for [cmd cproc] arguments, and the results
for [cmd cconst] definitions the values on the right side have to be proper C
rvalues. They have to match C type [type int].

[para] In other words, it is perfectly ok to use the symbolic names provided by the header
file of the external library. As shown.

[list_end]

[para] Packages: [term critcl::bitmap]