| 1 |
INSTALLATION OF THE TCL LIBRARY |
| 2 |
|
| 3 |
Unfortunately, I haven't yet figured out how to incorporate |
| 4 |
the Tcl interface into the autoconfiguration system, so |
| 5 |
if you want the Tcl interface you'll need to use |
| 6 |
TclMakefile. The one thing you are likely to want to configure |
| 7 |
is the definition of TCLLIBDIR on the first line of the makefile. |
| 8 |
That is the directory into which you want to install the library. |
| 9 |
The makefile assumes that you have a typical Linux installation |
| 10 |
of the ActiveTcl distribution of Tcl. If that is not the case, |
| 11 |
find out where your Tcl libraries go and change the |
| 12 |
definition of TCLLIBDIR to reflect this. |
| 13 |
|
| 14 |
To find out where your Tcl installation looks for libraries |
| 15 |
execute the script FindTclLibDir.tcl included here: |
| 16 |
|
| 17 |
tclsh FindTclLibDir.tcl |
| 18 |
|
| 19 |
The result will be the search path that Tcl uses, that is, a list |
| 20 |
of directories that Tcl searches, in the order in which it searches them. |
| 21 |
Copying tcl_uninum.so into any of these directories (with the name |
| 22 |
libuninum.so) will enable Tcl to find it. Note that if you copy |
| 23 |
into a directory other than the first one, if you have installed |
| 24 |
a previous version of the library in an earlier directory, the |
| 25 |
older version will mask the new one, so you should either install |
| 26 |
the library in the first one or make sure to delete any old copies |
| 27 |
that may be in other directories in the path. |
| 28 |
|
| 29 |
If you do not intend to use the C API you need not |
| 30 |
install it, but you should go through the configuration |
| 31 |
and build sequence. Executing ./configure configures some |
| 32 |
aspects of the Tcl API as well as the C API. |
| 33 |
Furthermore, the Tcl API has the file uninum.o as one |
| 34 |
of its components. |
| 35 |
|
| 36 |
Then do: |
| 37 |
|
| 38 |
make -f TclMakefile |
| 39 |
|
| 40 |
to build the library and (most likely after becoming root): |
| 41 |
|
| 42 |
make -f TclMakefile install |
| 43 |
|
| 44 |
to install it. |
| 45 |
|
| 46 |
If you are using the ActiveTcl distribution, there is a good chance |
| 47 |
that tclsh is not in the root path. If this is the case, your |
| 48 |
attempt at installation will fail because make will try to |
| 49 |
execute a little Tcl script using tclsh and won't be able |
| 50 |
to find tclsh. The easiest thing is to add the directory |
| 51 |
containing tclsh to your path. Suppose, for concreteness, |
| 52 |
that tclsh is in /usr/local/ActiveTcl/bin. If your root |
| 53 |
shell is bash, do: |
| 54 |
|
| 55 |
PATH=$PATH:/usr/local/ActiveTcl/bin |
| 56 |
|
| 57 |
If your root shell is tcsh, do: |
| 58 |
|
| 59 |
path = ($path /usr/local/ActiveTcl/bin) |
| 60 |
|
| 61 |
Then do: |
| 62 |
|
| 63 |
make -f TclMakefile install |
| 64 |
|
| 65 |
again and it should succeed. |
| 66 |
|
| 67 |
|
| 68 |
USE OF THE TCL LIBRARY |
| 69 |
|
| 70 |
Before using the library you should give the following command |
| 71 |
to import it: |
| 72 |
|
| 73 |
package require uninum |
| 74 |
|
| 75 |
If you give this command interactively to tclsh, it will respond with |
| 76 |
the version number of the library, e.g.: |
| 77 |
|
| 78 |
2.4 |
| 79 |
|
| 80 |
The Tcl interface to this library exposes five functions |
| 81 |
and two global variables. |
| 82 |
|
| 83 |
The function for converting strings to numbers is: |
| 84 |
|
| 85 |
UNStrToWNStr <Numeric String> <Number System> |
| 86 |
|
| 87 |
UNStrToWNStr takes as input a Unicode string representing an integer |
| 88 |
and returns a plain ASCII string containing the integer as a decimal |
| 89 |
string using the usual Western (that is, Indo-Arabic) digits. |
| 90 |
For example, the Unicode string \u4E03\u5341\u4E94, consisting of the |
| 91 |
Chinese numerals "7 10 5", is returned as "75". |
| 92 |
|
| 93 |
The NumberSystem argument specifies the expected number system. |
| 94 |
Most of the valid values are the names of particular number systems, |
| 95 |
such as "Arabic" or "Gurmukhi". If the string is not recognized as |
| 96 |
a number in the specified number system, an exception is raised. |
| 97 |
|
| 98 |
The NumberSystem argument may also be "any" or "all". In this case |
| 99 |
the input may be in any number system. The library will attempt to |
| 100 |
identify the number system and perform the appropriate conversion. |
| 101 |
An exception is raised if it is unable to identify the number |
| 102 |
system. |
| 103 |
|
| 104 |
The second function exposed is: |
| 105 |
|
| 106 |
StrGuessNumberSystem <Numeric String> |
| 107 |
|
| 108 |
It takes as argument a Unicode string representing an integer and returns |
| 109 |
a plain ASCII string containing the name of the number system. |
| 110 |
If it is unable to identify the number system, it returns the string |
| 111 |
"Unknown". If it is unable to identify the number system uniquely |
| 112 |
because the string consists entirely of ASCII zeroes, it returns |
| 113 |
the string "All_Zero". |
| 114 |
|
| 115 |
The function for converting numbers to strings is: |
| 116 |
|
| 117 |
WNStrToUNStr <Number> <Number System> |
| 118 |
|
| 119 |
Note that here the number system is specified as a string, |
| 120 |
e.g. "Gurmukhi". |
| 121 |
|
| 122 |
UninumNumberSystemMaximumValue takes as argument the name of a number |
| 123 |
system and returns the maximum value representable in that writing system, |
| 124 |
or "unlimited" where there is no limit. |
| 125 |
|
| 126 |
The fourth function is Tcl_ListNumberSystems. If its argument is 0, |
| 127 |
it lists the specific number system names usable for conversion from string |
| 128 |
to number and from number to string. If its argument is 1, it lists |
| 129 |
the cover terms suitable only for conversion of string to number. |
| 130 |
It returns a string in which number system names are separated by |
| 131 |
spaces. To obtain a Tcl list of number system names, split this string, |
| 132 |
e.g. |
| 133 |
|
| 134 |
set NumberSystemList [lsort [split [Tcl_ListNumberSystems 0]]] |
| 135 |
|
| 136 |
The final function is uninum_version, which returns the |
| 137 |
library version number. |
| 138 |
|
| 139 |
The first global variable is uninum_err. This has the same function |
| 140 |
as the C variable of the same name. It is set to zero prior to every |
| 141 |
call and is set to a non-zero value, defined in nsdefs.h, on error. |
| 142 |
You should check this variable after every call to UNStrToWNStr |
| 143 |
and should only use the value returned if uninum_err is 0. |
| 144 |
|
| 145 |
In addition to the errors that may occur in the C API, |
| 146 |
there is one error unique to the Tcl API: |
| 147 |
|
| 148 |
NS_ERROR_OUTSIDE_BMP |
| 149 |
|
| 150 |
This error occurs when the string generated contains characters |
| 151 |
outside the Basic Monolingual Plane of Unicode, that is, outside |
| 152 |
the range representable in 16 bits. Since Tcl in its normal form |
| 153 |
does not yet support Unicode outside the BMP, any string to be |
| 154 |
passed to Tcl is first checked for characters outside the BMP. |
| 155 |
If any are found, the string is not returned and uninum_err |
| 156 |
is set to NS_OUTSIDE_BMP_ERROR. |
| 157 |
|
| 158 |
The second global variable is tcl_uninum_badchar, which corresponds to the |
| 159 |
C variable uninum_badchar. If UNStrToWNStr encounters an unexpected |
| 160 |
character, it sets uninum_err and stores the codepoint of the unexpected |
| 161 |
character in tcl_uninum_badchar. See TestStringToNumber.tcl for an example |
| 162 |
of testing for this error and using the information in tcl_uninum_badchar. |