Tcl/Tk: Tables


Table of Contents

Tous ces tableaux sont repris du draft du livre de Brent Welch qui doit sortir en mai 95.

1.1 Les différentes séquences backslash spéciales (\ )

Backslash Sequences
\a             Bell.(0x7)

\b             Backspace.(0x8)

\f             Form feed.(0xc)

\n             Newline.(0xa)

\r             Carriage return.(0xd)

\t             Tab (0x9)

\v             Vertical tab.(0xb)

\<newline>     Replace newline and all leading whitespace on the following line
               with a single space.

\\             Backslash.('\')

\ooo           Octal specification of character code. 1,2, or 3 digits.

\xhh           Hexadecimal specification of character code. 1, or 2 digits.

\c             Replaced with literal c if c is not one of the cases listed above. In
               particular, \$,\",\{ and\[ are used to obtain these characters.

1.2 Les opérateurs arithmétiques

Arithmetic Operators from highest to lowest precedence
- ~ !        Unary minus, bitwise NOT, logical NOT.

* / %        Multiply, divide, remainder.

+ -          Add, substract.

« »          Left shift, right shift.

< > <= >=    Comparison: less, greater, less or equal, greater or equal.

== !=        Equal, not equal.

&            Bitwise AND.

^            Bitwise NOT.

|            Bitwise OR.

&&           Logical AND.

||           Logical OR.

x?y:z        If x then y else z.

1.3 Les fonctions mathématiques

Built-in Math functions
acos(x)           Arc-cosine of x.
asin(x)           Arc-sine of x.
atan(x)           Arc-tangent of x.
atan2(y,x)        Rectangular (x,y) to polar(r,th).atan2 gives th
ceil(x)           Least integral value greater than or equal to x.
cos(x)            Cosine of x.
cosh(x)           hyperbolic cosine of x.
exp(x)            Exponential, exp(x)
floor(x)          Greatest integral value less than or equal to x.
fmod(x,y)         Floating point remainder of x/y.
hypot(x,y)        Returns sqrt (x*x + y*y). r part of polar coordinates.
log(x)            Natural log of x.
log10(x)          Log base 10 of x.
pow(x,y)          x to the y power
sin(x)            Sine of x.
sinh(x)           Hyperbolic sine of x.
sqrt(x)           Square root of x.
tan(x)            Tangent of x.
tanh(x)           Hyperbolic tangent of x.
abs(x)            Absolute value of x.
double(x)         Promote x to floating point.
int(x)            Truncate x to an integer.
round(x)          Round x to an integer.

1.4 Les variables réservées

Variables defined by tclsh
argc                   The number of command line arguments.

argv                   A list of the command line arguments.

argv0                  The name of the script being executed. If being used interac-
                       tively, argv0 is the name of the shell program.

env                    An array of the environment variables. See page 38.

tcl_interactive        True (one) if the tclsh is prompting for commands.

tcl_prompt1            If defined, this is a command that outputs the prompt.

tcl_prompt2            If defined, this is a command that outputs the prompt if the
                       current command is not yet complete.

auto_path              The search path for script library directories. See page 90
                       of Welsh draft.

auto_index             A map from command name to a Tcl command that defines it.

auto_noload            If set, the library facility is disabled.

auto_noexec            If set, the auto execute facility is disabled.

geometry               (wish only). The value of the -geometry argument.

1.5 Les options de la commande info

The info command
info args procedure          A list of procedure's arguments.

info body procedure          The commands in the body of procedure.

info cmdcount                The number of commands executed so far.

info commands ?pattern?      A list of all commands, or those matching
                             pattern. Includes built-ins and Tcl procedures.

info complete string         True if string contains a complete Tcl command.

info default proc arg var    True if arg has a default parameter value in pro-
                             cedure proc. The default value is stored into var.

info exists variable         True if variable is defined.

info globals ?pattern?       A list of all global variables, or those matching
                             pattern.

info level                   The stack level of the current procedure, or 0 for
                             the global scope.

info level number            A list of the command and its arguments at the
                             specified level of the stack.

info library                 The pathname of the Tcl library directory.

info locals ?pattern?        A list of t all local variables, or those matching
                             pattern.

info patchlevel              The release patchlevel fot Tcl.

info procs ?pattern?         A list of all Tcl procedures, or those that match
                             pattern.

info script                  The name of the file being processed, or NULL.

info tclversion              The version number of Tcl.

info vars ?pattern?          A list of all visible variables, or those matching
                             pattern.

2.1 Les commandes concernant les listes

List-related commands
list arg1 arg2...               Creates a list out of all its arguments.

lindex list i                   Returns the i'th element from list.

llength list                    Returns the number of elements in list.

lrange list i j                 Returns the i'th through j'th elements
                                from list.

lappend listVar arg arg ...     Append a elements to the value of listVar.

linsert list index arg arg ...  Insert elements into list before the element at
                                position index. Returns a new list.

lreplace list i j arg arg ...   Replace elements i through j of list
                                with the args. Returns a new list.

lsearch mode list value         Return the index of the element in list that
                                matches the value according to the mode, which
                                is -exact, -glob, or -regexp. -glob is the
                                default. Return -1 if not found.

lsort switches list             Sort elements of the list according to the switches:
                                -ascii, -integer, -real, -increasing, -decreasing,
                                -command command. Returns a new list.

concat arg arg arg ...          Join multiple lists together into one list.

join list joinString            Merge the elements of a list together by separat-
                                ing them with joinString.

split string splitChars         Split a string up into list elements, using (and dis-
                                carding) the characters in splitChars as bound-
                                aries between list elements.

2.2 Les commandes concernant les arrays

The array command
array exists arr             Returns 1 if arr is an array variable.

array get arr                Returns a list that alternates between an index
                             and the corresponding array value.

array names arr?pattern?     Return the list of all indices defined for arr, or
                             those that match the string match pattern.

array set arr list           Initialize the array arr from list, which should
                             have the same form as the list returned by get.

array size arr               Return the number of indices defined for arr.

array startsearch arr        Return a search id key for a search through arr.

array nextelement arrid      Return the value of the next element in array in
                             the search identified by id. Returns an empty
                             string if no more elements remain in the search.

array anymore arr id         Returns 1 if more elements remain in the search.

array donesearch arr id      End the search identified by id.

3.1 Les options de la commande string

The string command
string compare str1 str2           Compare strings lexicographically.Returns 0 if
                                   equal, -1 if str1 sorts beforestr2, else 1.

string first str1 str2             Return the index in str2 of the first occurrence of
                                   str1, or -1 if str1 is not found.

string index string index          Return the character at the specified index.

string last str1 str2              Return the index in str2 of the last occurrence of
                                   str1, or -1 if str1 is not found.

string length string               Return the number of characters in string.

string match pattern str           Return 1 if str matches the pattern, else 0.
                                   Glob-style matching is used. See page 24.

string range str i j               Return the range of characters in str from i to j.

string tolower string              Return string in lower case.

string toupper string              Return string in upper case.

string trim string ?chars?         Trim the characters in chars from both ends of
                                   string.chars defaults to whitespace.

string trimleft string ?chars?     Trim the characters in chars from the beginning of
                                   string.charsdefaults to whitespace.

string trimright string ?chars?    Trim the characters in chars from the end of 
                                   string.chars defaults to whitespace.

string wordend str ix              Return the index in str of the character after the
                                   word containing the character at index ix.

string wordstart str ix            Return the index in str of the first character in
                                   the word containing the character at index ix.

3.2 La syntaxe des expressions régulières

Regular Expression Syntax
.          Matches any character.

*          Matches zero or more.

+          Matches one or more.

?          Matches zero or one.

()         Groups a sub-pattern. The repetition and alternation operators apply to
           the whole proceeding sub-pattern.

|          Alternation.

[]         Delimit a set of characters. Ranges are specified as [x-y]. If the first
           character in the set is ^, then there is a match if the remaining characters
           in the set are not present.

^          Anchor the pattern to the beginning of the string. Only when first.

$          Anchor the pattern to the end of the string. Only when last.

4.1 La syntaxe des redirections pour la commande exec

Summary of the exec syntax for I/O redirection
-keepnewline    (First arg only.) Do not discard trailing newline from the result.

|               Pipe standard output from one process into another.

|&              Pipe both standard output and standard error output.

< fileName      Take input from the named file.

<@ fileId       Take input from the I/O stream identified by fileId.

<< value        Take input from the given value.

> fileName      Overwrite fileName with standard output.

2> fileName     Overwrite fileName with standard error output.

>& fileName     Overwrite fileName with both standard error and standard out.

>> fileName     Append standard output to the named file.

2>> fileName    Append standard error to the named file.

>>& fileName    Append both standard error and standard output to the named file.

>@ fileId       Direct standard output to the I/O stream identified by fileId.

2>@ fileId      Direct standard error to the I/O stream identified by fileId.

>&@ fileId      Direct both standard error and standard output to the I/O stream.

&               As the last argument, indicates pipeline should run in background.

4.2 Les options de la commande file

The Tcl file command options
file atime name          Return access time as a decimal string.

file dirname name        Return parent directory of file name.

file executable name     Return 1 if name has execute permission, else 0.

file exists name         Return 1 if name exists, else 0.

file extension name      Return the part of name from the last dot '.' to the end.

file isdirectory name    Return 1 if name is a directory, else 0.

file isfile name         Return 1 if name is not a directory, symbolic link, or
                         device, else 0.

file lstat name var      Place stat results about the link name into var.

file mtime name          Return modify time of name as a decimal string.

file owned name          Return 1 if current user owns the file name, else 0.

file readable name       Return 1 if name has read permission, else 0.

file readlink name       Return the contents of the symbolic link name.

file rootname name       Return all but the extension ('.' and onwards) of name.

file size name           Return the number of bytes in name.

file stat name var       Place stat results about name into array var. The ele-
                         ments defined for var are: atime, ctime, dev, gid,
                         ino, mode, mtime, nlink, size, type, and uid.

file tail name           Return all characters after last '/' in name.

file type name           Return type identifier, which is one of: file,
                         directory, characterSpecial, blockSpecial, fifo,
                         link, or socket.

file writable name       Return 1 if name has write permission, else 0.

4.3 Les commandes concernant l'accès aux fichiers

Tcl commands used for file access
open what ?access? ?permissions?       Open a file or pipeline.

puts ?-nonewline? ?stream? string      Write a string.

gets stream ?varname?                  Read a line.

read ?-nonewline? stream ?numBytes?    Read bytes.

tell stream                            Return the seek offset.

seek stream offset ?origin?            Set the seek offset. origin is one of
                                       start, current, or end.

eof stream                             Query end-of-file status.

flush stream                           Write out buffers of a stream.

close stream                           Close an I/O stream.

Anne Possoz
Tricoté avec patience par Marielle Flutsch