| 1 | '\" | 
|---|
| 2 | '\" Copyright (c) 2002 Andreas Kupries <andreas_kupries@users.sourceforge.net> | 
|---|
| 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 | '\" RCS: @(#) $Id: RegConfig.3,v 1.8 2007/12/13 15:22:31 dgp Exp $ | 
|---|
| 8 | .so man.macros | 
|---|
| 9 | .TH Tcl_RegisterConfig 3 8.4 Tcl "Tcl Library Procedures" | 
|---|
| 10 | .BS | 
|---|
| 11 | '\" Note:  do not modify the .SH NAME line immediately below! | 
|---|
| 12 | .SH NAME | 
|---|
| 13 | Tcl_RegisterConfig \- procedures to register embedded configuration information | 
|---|
| 14 | .SH SYNOPSIS | 
|---|
| 15 | .nf | 
|---|
| 16 | \fB#include <tcl.h>\fR | 
|---|
| 17 | .sp | 
|---|
| 18 | void | 
|---|
| 19 | \fBTcl_RegisterConfig\fR(\fIinterp, pkgName, configuration, valEncoding\fR) | 
|---|
| 20 | .sp | 
|---|
| 21 | .SH ARGUMENTS | 
|---|
| 22 | .AS Tcl_Interp *configuration | 
|---|
| 23 | .AP Tcl_Interp *interp in | 
|---|
| 24 | Refers to the interpreter the embedded configuration information is | 
|---|
| 25 | registered for. Must not be NULL. | 
|---|
| 26 | .AP "const char" *pkgName in | 
|---|
| 27 | Contains the name of the package registering the embedded | 
|---|
| 28 | configuration as ASCII string. This means that this information is in | 
|---|
| 29 | UTF-8 too. Must not be NULL. | 
|---|
| 30 | .AP Tcl_Config *configuration in | 
|---|
| 31 | Refers to an array of Tcl_Config entries containing the information | 
|---|
| 32 | embedded in the binary library. Must not be NULL. The end of the array | 
|---|
| 33 | is signaled by either a key identical to NULL, or a key referring to | 
|---|
| 34 | the empty string. | 
|---|
| 35 | .AP "const char" *valEncoding in | 
|---|
| 36 | Contains the name of the encoding used to store the configuration | 
|---|
| 37 | values as ASCII string. This means that this information is in UTF-8 | 
|---|
| 38 | too. Must not be NULL. | 
|---|
| 39 | .BE | 
|---|
| 40 |  | 
|---|
| 41 | .SH DESCRIPTION | 
|---|
| 42 | .PP | 
|---|
| 43 | The function described here has its base in TIP 59 and provides | 
|---|
| 44 | extensions with support for the embedding of configuration | 
|---|
| 45 | information into their binary library and the generation of a | 
|---|
| 46 | Tcl-level interface for querying this information. | 
|---|
| 47 | .PP | 
|---|
| 48 | To embed configuration information into their binary library an | 
|---|
| 49 | extension has to define a non-volatile array of Tcl_Config entries in | 
|---|
| 50 | one if its source files and then call \fBTcl_RegisterConfig\fR to | 
|---|
| 51 | register that information. | 
|---|
| 52 | .PP | 
|---|
| 53 | \fBTcl_RegisterConfig\fR takes four arguments; first, a reference to | 
|---|
| 54 | the interpreter we are registering the information with, second, the | 
|---|
| 55 | name of the package registering its configuration information, third, | 
|---|
| 56 | a pointer to an array of structures, and fourth a string declaring the | 
|---|
| 57 | encoding used by the configuration values. | 
|---|
| 58 | .PP | 
|---|
| 59 | The string \fIvalEncoding\fR contains the name of an encoding known to | 
|---|
| 60 | Tcl.  All these names are use only characters in the ASCII subset of | 
|---|
| 61 | UTF-8 and are thus implicitly in the UTF-8 encoding. It is expected | 
|---|
| 62 | that keys are legible English text and therefore using the ASCII | 
|---|
| 63 | subset of UTF-8. In other words, they are expected to be in UTF-8 | 
|---|
| 64 | too. The values associated with the keys can be any string | 
|---|
| 65 | however. For these the contents of \fIvalEncoding\fR define which | 
|---|
| 66 | encoding was used to represent the characters of the strings. | 
|---|
| 67 | .PP | 
|---|
| 68 | Each element of the \fIconfiguration\fR array refers to two strings | 
|---|
| 69 | containing the key and the value associated with that key. The end of | 
|---|
| 70 | the array is signaled by either an empty key or a key identical to | 
|---|
| 71 | NULL. The function makes \fBno\fR copy of the \fIconfiguration\fR | 
|---|
| 72 | array. This means that the caller has to make sure that the memory | 
|---|
| 73 | holding this array is never released. This is the meaning behind the | 
|---|
| 74 | word \fBnon-volatile\fR used earlier. The easiest way to accomplish | 
|---|
| 75 | this is to define a global static array of Tcl_Config entries. See the file | 
|---|
| 76 | .QW generic/tclPkgConfig.c | 
|---|
| 77 | in the sources of the Tcl core for an example. | 
|---|
| 78 | .PP | 
|---|
| 79 | When called \fBTcl_RegisterConfig\fR will | 
|---|
| 80 | .IP (1) | 
|---|
| 81 | create a namespace having the provided \fIpkgName\fR, if not yet | 
|---|
| 82 | existing. | 
|---|
| 83 | .IP (2) | 
|---|
| 84 | create the command \fBpkgconfig\fR in that namespace and link it to | 
|---|
| 85 | the provided information so that the keys from _configuration_ and | 
|---|
| 86 | their associated values can be retrieved through calls to | 
|---|
| 87 | \fBpkgconfig\fR. | 
|---|
| 88 | .PP | 
|---|
| 89 | The command \fBpkgconfig\fR will provide two subcommands, \fBlist\fR | 
|---|
| 90 | and \fBget\fR: | 
|---|
| 91 | .RS | 
|---|
| 92 | .TP | 
|---|
| 93 | ::\fIpkgName\fR::\fBpkgconfig\fR list | 
|---|
| 94 | Returns a list containing the names of all defined keys. | 
|---|
| 95 | .TP | 
|---|
| 96 | ::\fIpkgName\fR::\fBpkgconfig\fR get \fIkey\fR | 
|---|
| 97 | Returns the configuration value associated with the specified | 
|---|
| 98 | \fIkey\fR. | 
|---|
| 99 | .RE | 
|---|
| 100 | .SH TCL_CONFIG | 
|---|
| 101 | .PP | 
|---|
| 102 | The \fBTcl_Config\fR structure contains the following fields: | 
|---|
| 103 | .PP | 
|---|
| 104 | .CS | 
|---|
| 105 | typedef struct Tcl_Config { | 
|---|
| 106 | const char* key; | 
|---|
| 107 | const char* value; | 
|---|
| 108 | } Tcl_Config; | 
|---|
| 109 | .CE | 
|---|
| 110 | .\" No cross references yet. | 
|---|
| 111 | .\" .SH "SEE ALSO" | 
|---|
| 112 | .SH KEYWORDS | 
|---|
| 113 | embedding, configuration, bianry library | 
|---|