'\"
'\" Copyright (c) 2013 Tcl Core Team.
'\"
'\" See the file "license.terms" for information on usage and redistribution
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
'\"
.so man.macros
.TH Tcl_InitSubsystems 3 8.6.1 Tcl "Tcl Library Procedures"
.BS
.SH NAME
Tcl_InitSubsystems \- initialize the Tcl library.
.SH SYNOPSIS
.nf
\fB#include <tcl.h>\fR
.sp
Tcl_Interp *
\fBTcl_InitSubsystems\fR(\fIflags\fR, \fI...\fR)
.SH ARGUMENTS
.AS int flags
.AP int flags in
Any combination of flags which indicate whether an interpreter
is created and/or a custom initialization function will be executed.
The value 0 can be used if Tcl is used as utility library only.
.BE
.SH DESCRIPTION
.PP
The \fBTcl_InitSubsystems\fR procedure initializes the Tcl
library. This procedure is typically invoked as the very
first thing in the application's main program.
Its \fBflags\fR argument controls exactly what is initialized,
and what additional arguments are expected. The call
\fBTcl_InitSubsystems(0)\fR does the same as \fBTcl_FindExecutable(NULL)\fR.
.PP
If you supply one of the flags \fBTCL_INIT_CREATE\fR, \fBTCL_INIT_CREATE_UTF8\fR or
\fBTCL_INIT_CREATE_UNICODE\fR to \fBTcl_InitSubsystems\fR, the function
gets two additional parameters, argc and argv, immediatly following
the flags parameter. Then a Tcl interpreter will be created. If
argc > 0 then the variables \fBargc\fR and \fBargv\fR will be set
in this interpreter. The 3 variants assume a different encoding for
the arguments, except for \fIargv[0]\fR which is always assumed to
be in the system encoding.
.PP
If you supply the flag \fBTCL_INIT_CUSTOM\fR to \fBTcl_InitSubsystems\fR,
the function expects two additional arguments: ClientData and a
custom proc. The proc will be supplied two arguments, the Tcl interpreter
(or NULL if none of the \fBTCL_INIT_CREATE???\fR flags is set) and
ClientData. The custom function will be executed just before the encodings
are initialized. Remember that encodings other than UTF-8, unicode and
iso8859-1 are not yet available when the custom function is run, the system
encoding is not determined, and no variables are set in the interpreter
yet. This means that no libaries/packages can be found yet, it is typically
used only for calling functions like \fBTcl_SetEncodingSearchPath\fR
and \fBTcl_FSRegister\fR.
.PP
If multiple flags are combined, the \fBargc/argv\fR arguments always come
first, followed by clientData and the custom proc.
.PP
The reason for \fBargv[0]\fR always using the system encoding is that this way,
argv[0] can be derived directly from the main() (or mainw, on Windows)
arguments without any processing. \fBTCL_INIT_CREATE_UNICODE\fR is really only
useful on Windows. But on Windows, the argv[0] parameter is not used for
determining the value of [info executable] anyway. Modern UNIX system already
have UTF-8 as system encoding, so \fBTCL_INIT_CREATE_UTF8\fR would have the same
effect as \fBTCL_INIT_CREATE\fR, only slightly faster. Other parameters can be
preprocessed at will by the application, and if the application uses unicode
or UTF-8 internally there is no need to convert it back to the system encoding.
.SH KEYWORDS
binary, executable file