Debian Codegraph @

doc/StdChannels.3

raw
1 '\"
2 '\" Copyright (c) 2001 ActiveState Corporation
3 '\"
4 '\" See the file "license.terms" for information on usage and redistribution
5 '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
6 '\"
7 .TH "Standard Channels" 3 7.5 Tcl "Tcl Library Procedures"
8 .so man.macros
9 .BS
10 '\" Note: do not modify the .SH NAME line immediately below!
11 .SH NAME
12 Tcl_StandardChannels \- How the Tcl library deals with the standard channels
13 .BE
14
15 .SH DESCRIPTION
16 .PP
17 This page explains the initialization and use of standard channels in
18 the Tcl library.
19 .PP
20 The term \fIstandard channels\fR comes out of the Unix world and
21 refers to the three channels automatically opened by the OS for
22 each new application. They are \fBstdin\fR, \fBstdout\fR and
23 \fBstderr\fR. The first is the standard input an application can read
24 from, the other two refer to writable channels, one for regular
25 output and the other for error messages.
26 .PP
27 Tcl generalizes this concept in a cross-platform way and
28 exposes standard channels to the script level.
29 .SS "APPLICATION PROGRAMMING INTERFACES"
30 .PP
31 The public API procedures dealing directly with standard channels are
32 \fBTcl_GetStdChannel\fR and \fBTcl_SetStdChannel\fR. Additional public
33 APIs to consider are \fBTcl_RegisterChannel\fR,
34 \fBTcl_CreateChannel\fR and \fBTcl_GetChannel\fR.
35 .SH "INITIALIZATION OF TCL STANDARD CHANNELS"
36 .PP
37 Standard channels are initialized by the Tcl library in three cases:
38 when explicitly requested, when implicitly required before returning
39 channel information, or when implicitly required during registration
40 of a new channel.
41 .PP
42 These cases differ in how they handle unavailable platform- specific
43 standard channels. (A channel is not
44 .QW available
45 if it could not be
46 successfully opened; for example, in a Tcl application run as a
47 Windows NT service.)
48 .TP
49 1)
50 A single standard channel is initialized when it is explicitly
51 specified in a call to \fBTcl_SetStdChannel\fR. The states of the
52 other standard channels are unaffected.
53 .RS
54 .PP
55 Missing platform-specific standard channels do not matter here. This
56 approach is not available at the script level.
57 .RE
58 .TP
59 2)
60 All uninitialized standard channels are initialized to
61 platform-specific default values:
62 .RS
63 .TP
64 (a)
65 when open channels are listed with \fBTcl_GetChannelNames\fR (or the
66 \fBfile channels\fR script command), or
67 .TP
68 (b)
69 when information about any standard channel is requested with a call
70 to \fBTcl_GetStdChannel\fR, or with a call to \fBTcl_GetChannel\fR
71 which specifies one of the standard names (\fBstdin\fR, \fBstdout\fR
72 and \fBstderr\fR).
73 .PP
74 In case of missing platform-specific standard channels, the Tcl
75 standard channels are considered as initialized and then immediately
76 closed. This means that the first three Tcl channels then opened by
77 the application are designated as the Tcl standard channels.
78 .RE
79 .TP
80 3)
81 All uninitialized standard channels are initialized to
82 platform-specific default values when a user-requested channel is
83 registered with \fBTcl_RegisterChannel\fR.
84 .PP
85 In case of unavailable platform-specific standard channels the channel
86 whose creation caused the initialization of the Tcl standard channels
87 is made a normal channel. The next three Tcl channels opened by the
88 application are designated as the Tcl standard channels. In other
89 words, of the first four Tcl channels opened by the application the
90 second to fourth are designated as the Tcl standard channels.
91 .SH "RE-INITIALIZATION OF TCL STANDARD CHANNELS"
92 .PP
93 Once a Tcl standard channel is initialized through one of the methods
94 above, closing this Tcl standard channel will cause the next call to
95 \fBTcl_CreateChannel\fR to make the new channel the new standard
96 channel, too. If more than one Tcl standard channel was closed
97 \fBTcl_CreateChannel\fR will fill the empty slots in the order
98 \fBstdin\fR, \fBstdout\fR and \fBstderr\fR.
99 .PP
100 \fBTcl_CreateChannel\fR will not try to reinitialize an empty slot if
101 that slot was not initialized before. It is this behavior which
102 enables an application to employ method 1 of initialization, i.e. to
103 create and designate their own Tcl standard channels.
104 .SH "SHELL-SPECIFIC DETAILS"
105 .SS tclsh
106 .PP
107 The Tcl shell (or rather the function \fBTcl_Main\fR, which forms the
108 core of the shell's implementation) uses method 2 to initialize
109 the standard channels.
110 .SS wish
111 .PP
112 The windowing shell (or rather the function \fBTk_MainEx\fR, which
113 forms the core of the shell's implementation) uses method 1 to
114 initialize the standard channels (See \fBTk_InitConsoleChannels\fR)
115 on non-Unix platforms. On Unix platforms, \fBTk_MainEx\fR implicitly
116 uses method 2 to initialize the standard channels.
117 .SH "SEE ALSO"
118 Tcl_CreateChannel(3), Tcl_RegisterChannel(3), Tcl_GetChannel(3), Tcl_GetStdChannel(3), Tcl_SetStdChannel(3), Tk_InitConsoleChannels(3), tclsh(1), wish(1), Tcl_Main(3), Tk_MainEx(3)
119 .SH KEYWORDS
120 standard channels