OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [doc/] [html/] [cdl-guide/] [language.tcl.html] - Diff between revs 28 and 174

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 28 Rev 174
<!-- Copyright (C) 2003 Red Hat, Inc.                                -->
<!-- Copyright (C) 2003 Red Hat, Inc.                                -->
<!-- This material may be distributed only subject to the terms      -->
<!-- This material may be distributed only subject to the terms      -->
<!-- and conditions set forth in the Open Publication License, v1.0  -->
<!-- and conditions set forth in the Open Publication License, v1.0  -->
<!-- or later (the latest version is presently available at          -->
<!-- or later (the latest version is presently available at          -->
<!-- http://www.opencontent.org/openpub/).                           -->
<!-- http://www.opencontent.org/openpub/).                           -->
<!-- Distribution of the work or derivative of the work in any       -->
<!-- Distribution of the work or derivative of the work in any       -->
<!-- standard (paper) book form is prohibited unless prior           -->
<!-- standard (paper) book form is prohibited unless prior           -->
<!-- permission is obtained from the copyright holder.               -->
<!-- permission is obtained from the copyright holder.               -->
<HTML
<HTML
><HEAD
><HEAD
><TITLE
><TITLE
>An Introduction to Tcl</TITLE
>An Introduction to Tcl</TITLE
><meta name="MSSmartTagsPreventParsing" content="TRUE">
><meta name="MSSmartTagsPreventParsing" content="TRUE">
<META
<META
NAME="GENERATOR"
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+
CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+
"><LINK
"><LINK
REL="HOME"
REL="HOME"
TITLE="The eCos Component Writer's Guide"
TITLE="The eCos Component Writer's Guide"
HREF="cdl-guide.html"><LINK
HREF="cdl-guide.html"><LINK
REL="UP"
REL="UP"
TITLE="The CDL Language"
TITLE="The CDL Language"
HREF="language.html"><LINK
HREF="language.html"><LINK
REL="PREVIOUS"
REL="PREVIOUS"
TITLE="Option Naming Convention"
TITLE="Option Naming Convention"
HREF="language.naming.html"><LINK
HREF="language.naming.html"><LINK
REL="NEXT"
REL="NEXT"
TITLE="Values and Expressions"
TITLE="Values and Expressions"
HREF="language.values.html"></HEAD
HREF="language.values.html"></HEAD
><BODY
><BODY
CLASS="SECT1"
CLASS="SECT1"
BGCOLOR="#FFFFFF"
BGCOLOR="#FFFFFF"
TEXT="#000000"
TEXT="#000000"
LINK="#0000FF"
LINK="#0000FF"
VLINK="#840084"
VLINK="#840084"
ALINK="#0000FF"
ALINK="#0000FF"
><DIV
><DIV
CLASS="NAVHEADER"
CLASS="NAVHEADER"
><TABLE
><TABLE
SUMMARY="Header navigation table"
SUMMARY="Header navigation table"
WIDTH="100%"
WIDTH="100%"
BORDER="0"
BORDER="0"
CELLPADDING="0"
CELLPADDING="0"
CELLSPACING="0"
CELLSPACING="0"
><TR
><TR
><TH
><TH
COLSPAN="3"
COLSPAN="3"
ALIGN="center"
ALIGN="center"
>The <SPAN
>The <SPAN
CLASS="APPLICATION"
CLASS="APPLICATION"
>eCos</SPAN
>eCos</SPAN
> Component Writer's Guide</TH
> Component Writer's Guide</TH
></TR
></TR
><TR
><TR
><TD
><TD
WIDTH="10%"
WIDTH="10%"
ALIGN="left"
ALIGN="left"
VALIGN="bottom"
VALIGN="bottom"
><A
><A
HREF="language.naming.html"
HREF="language.naming.html"
ACCESSKEY="P"
ACCESSKEY="P"
>Prev</A
>Prev</A
></TD
></TD
><TD
><TD
WIDTH="80%"
WIDTH="80%"
ALIGN="center"
ALIGN="center"
VALIGN="bottom"
VALIGN="bottom"
>Chapter 3. The CDL Language</TD
>Chapter 3. The CDL Language</TD
><TD
><TD
WIDTH="10%"
WIDTH="10%"
ALIGN="right"
ALIGN="right"
VALIGN="bottom"
VALIGN="bottom"
><A
><A
HREF="language.values.html"
HREF="language.values.html"
ACCESSKEY="N"
ACCESSKEY="N"
>Next</A
>Next</A
></TD
></TD
></TR
></TR
></TABLE
></TABLE
><HR
><HR
ALIGN="LEFT"
ALIGN="LEFT"
WIDTH="100%"></DIV
WIDTH="100%"></DIV
><DIV
><DIV
CLASS="SECT1"
CLASS="SECT1"
><H1
><H1
CLASS="SECT1"
CLASS="SECT1"
><A
><A
NAME="LANGUAGE.TCL">An Introduction to Tcl</H1
NAME="LANGUAGE.TCL">An Introduction to Tcl</H1
><P
><P
>All <SPAN
>All <SPAN
CLASS="APPLICATION"
CLASS="APPLICATION"
>CDL</SPAN
>CDL</SPAN
> scripts are implemented as <SPAN
> scripts are implemented as <SPAN
CLASS="APPLICATION"
CLASS="APPLICATION"
>Tcl</SPAN
>Tcl</SPAN
> scripts, and are read in by
> scripts, and are read in by
running the data through a standard <SPAN
running the data through a standard <SPAN
CLASS="APPLICATION"
CLASS="APPLICATION"
>Tcl</SPAN
>Tcl</SPAN
> interpreter, extended with a
> interpreter, extended with a
small number of additional commands such as
small number of additional commands such as
<TT
<TT
CLASS="LITERAL"
CLASS="LITERAL"
>cdl_option</TT
>cdl_option</TT
> and <TT
> and <TT
CLASS="LITERAL"
CLASS="LITERAL"
>cdl_component</TT
>cdl_component</TT
>.
>.
Often it is not necessary to know the full details of <SPAN
Often it is not necessary to know the full details of <SPAN
CLASS="APPLICATION"
CLASS="APPLICATION"
>Tcl</SPAN
>Tcl</SPAN
> syntax.
> syntax.
Instead it is possible to copy an existing script, perform some copy
Instead it is possible to copy an existing script, perform some copy
and paste operations, and make appropriate changes to names and to
and paste operations, and make appropriate changes to names and to
various properties. However there are also cases where an
various properties. However there are also cases where an
understanding of <SPAN
understanding of <SPAN
CLASS="APPLICATION"
CLASS="APPLICATION"
>Tcl</SPAN
>Tcl</SPAN
> syntax is very desirable, for example:</P
> syntax is very desirable, for example:</P
><TABLE
><TABLE
BORDER="5"
BORDER="5"
BGCOLOR="#E0E0F0"
BGCOLOR="#E0E0F0"
WIDTH="70%"
WIDTH="70%"
><TR
><TR
><TD
><TD
><PRE
><PRE
CLASS="PROGRAMLISTING"
CLASS="PROGRAMLISTING"
>cdl_option CYGDAT_UITRON_MEMPOOLFIXED_EXTERNS {
>cdl_option CYGDAT_UITRON_MEMPOOLFIXED_EXTERNS {
    display       "Externs for initialization"
    display       "Externs for initialization"
    flavor        data
    flavor        data
    default_value {"static char fpool1[ 2000 ], \\\n\
    default_value {"static char fpool1[ 2000 ], \\\n\
                                fpool2[ 2000 ], \\\n\
                                fpool2[ 2000 ], \\\n\
                                fpool3[ 2000 ];"}
                                fpool3[ 2000 ];"}
    &#8230;
    &#8230;
}</PRE
}</PRE
></TD
></TD
></TR
></TR
></TABLE
></TABLE
><P
><P
>This causes the <TT
>This causes the <TT
CLASS="LITERAL"
CLASS="LITERAL"
>cdl_option</TT
>cdl_option</TT
> command to be executed, which in turn
> command to be executed, which in turn
evaluates its body in a recursive invocation of the <SPAN
evaluates its body in a recursive invocation of the <SPAN
CLASS="APPLICATION"
CLASS="APPLICATION"
>Tcl</SPAN
>Tcl</SPAN
> interpreter.
> interpreter.
When the <SPAN
When the <SPAN
CLASS="PROPERTY"
CLASS="PROPERTY"
>default_value</SPAN
>default_value</SPAN
> property is encountered the braces around the
> property is encountered the braces around the
value part are processed by the interpreter, stopping it from doing
value part are processed by the interpreter, stopping it from doing
further processing of the braced contents (except for backslash
further processing of the braced contents (except for backslash
processing at the end of a line, that is special). In particular it
processing at the end of a line, that is special). In particular it
prevents command substitution for
prevents command substitution for
<TT
<TT
CLASS="LITERAL"
CLASS="LITERAL"
>[&nbsp;2000&nbsp;]</TT
>[&nbsp;2000&nbsp;]</TT
>. A single argument will be
>. A single argument will be
passed to the <SPAN
passed to the <SPAN
CLASS="PROPERTY"
CLASS="PROPERTY"
>default_value</SPAN
>default_value</SPAN
> command which expects a <SPAN
> command which expects a <SPAN
CLASS="APPLICATION"
CLASS="APPLICATION"
>CDL</SPAN
>CDL</SPAN
>
>
expression, so the expression parsing code is passed the following:</P
expression, so the expression parsing code is passed the following:</P
><TABLE
><TABLE
BORDER="5"
BORDER="5"
BGCOLOR="#E0E0F0"
BGCOLOR="#E0E0F0"
WIDTH="70%"
WIDTH="70%"
><TR
><TR
><TD
><TD
><PRE
><PRE
CLASS="SCREEN"
CLASS="SCREEN"
>"static char fpool1[ 2000 ], \\\n fpool2[ 2000 ], \\\n fpool3[ 2000 ];"</PRE
>"static char fpool1[ 2000 ], \\\n fpool2[ 2000 ], \\\n fpool3[ 2000 ];"</PRE
></TD
></TD
></TR
></TR
></TABLE
></TABLE
><P
><P
>The <SPAN
>The <SPAN
CLASS="APPLICATION"
CLASS="APPLICATION"
>CDL</SPAN
>CDL</SPAN
> expression parsing code will treat this as a simple string
> expression parsing code will treat this as a simple string
constant, as opposed to a more complicated expression involving other
constant, as opposed to a more complicated expression involving other
options and various operators. The string parsing code will perform
options and various operators. The string parsing code will perform
the usual backslash substitutions so the actual default value will be:</P
the usual backslash substitutions so the actual default value will be:</P
><TABLE
><TABLE
BORDER="5"
BORDER="5"
BGCOLOR="#E0E0F0"
BGCOLOR="#E0E0F0"
WIDTH="70%"
WIDTH="70%"
><TR
><TR
><TD
><TD
><PRE
><PRE
CLASS="SCREEN"
CLASS="SCREEN"
>static char fpool1[ 2000 ], \
>static char fpool1[ 2000 ], \
 fpool2[ 2000 ], \
 fpool2[ 2000 ], \
 fpool3[ 2000 ];</PRE
 fpool3[ 2000 ];</PRE
></TD
></TD
></TR
></TR
></TABLE
></TABLE
><P
><P
>If the user does not modify the option's value then the following
>If the user does not modify the option's value then the following
will be generated in the appropriate configuration header file:</P
will be generated in the appropriate configuration header file:</P
><TABLE
><TABLE
BORDER="5"
BORDER="5"
BGCOLOR="#E0E0F0"
BGCOLOR="#E0E0F0"
WIDTH="70%"
WIDTH="70%"
><TR
><TR
><TD
><TD
><PRE
><PRE
CLASS="PROGRAMLISTING"
CLASS="PROGRAMLISTING"
>#define CYGDAT_UITRON_MEMPOOLFIXED_EXTERNS static char fpool1[ 2000 ], \
>#define CYGDAT_UITRON_MEMPOOLFIXED_EXTERNS static char fpool1[ 2000 ], \
 fpool2[ 2000 ], \
 fpool2[ 2000 ], \
 fpool3[ 2000 ];</PRE
 fpool3[ 2000 ];</PRE
></TD
></TD
></TR
></TR
></TABLE
></TABLE
><P
><P
>Getting this desired result usually requires an understanding of both
>Getting this desired result usually requires an understanding of both
<SPAN
<SPAN
CLASS="APPLICATION"
CLASS="APPLICATION"
>Tcl</SPAN
>Tcl</SPAN
> syntax and <SPAN
> syntax and <SPAN
CLASS="APPLICATION"
CLASS="APPLICATION"
>CDL</SPAN
>CDL</SPAN
> expression syntax. Sometimes it is possible to
> expression syntax. Sometimes it is possible to
substitute a certain amount of trial and error instead, but this may
substitute a certain amount of trial and error instead, but this may
prove frustrating. It is also worth pointing out that many <SPAN
prove frustrating. It is also worth pointing out that many <SPAN
CLASS="APPLICATION"
CLASS="APPLICATION"
>CDL</SPAN
>CDL</SPAN
>
>
scripts do not involve this level of complexity. On the other hand,
scripts do not involve this level of complexity. On the other hand,
some of the more advanced features of the <SPAN
some of the more advanced features of the <SPAN
CLASS="APPLICATION"
CLASS="APPLICATION"
>CDL</SPAN
>CDL</SPAN
> language involve
> language involve
fragments of <SPAN
fragments of <SPAN
CLASS="APPLICATION"
CLASS="APPLICATION"
>Tcl</SPAN
>Tcl</SPAN
> code, for example the <SPAN
> code, for example the <SPAN
CLASS="PROPERTY"
CLASS="PROPERTY"
>define_proc</SPAN
>define_proc</SPAN
> property. To
> property. To
use these component writers will need to know about the full <SPAN
use these component writers will need to know about the full <SPAN
CLASS="APPLICATION"
CLASS="APPLICATION"
>Tcl</SPAN
>Tcl</SPAN
>
>
language as well as the syntax.</P
language as well as the syntax.</P
><P
><P
>Although the current example may seem to suggest that <SPAN
>Although the current example may seem to suggest that <SPAN
CLASS="APPLICATION"
CLASS="APPLICATION"
>Tcl</SPAN
>Tcl</SPAN
> is rather
> is rather
complicated, it is actually a very simple yet powerful scripting
complicated, it is actually a very simple yet powerful scripting
language: the syntax is defined by just eleven rules. On occasion this
language: the syntax is defined by just eleven rules. On occasion this
simplicity means that Tcl's behavior is subtly different from other
simplicity means that Tcl's behavior is subtly different from other
languages, which can confuse newcomers.</P
languages, which can confuse newcomers.</P
><P
><P
>When the Tcl interpreter is passed some data such as
>When the Tcl interpreter is passed some data such as
<TT
<TT
CLASS="LITERAL"
CLASS="LITERAL"
>puts&nbsp;Hello</TT
>puts&nbsp;Hello</TT
>, it splits this data into a command
>, it splits this data into a command
and its arguments. The command will be terminated by a newline or by a
and its arguments. The command will be terminated by a newline or by a
semicolon, unless one of the quoting mechanisms is used. The command
semicolon, unless one of the quoting mechanisms is used. The command
and each of its arguments are separated by white space. So in the
and each of its arguments are separated by white space. So in the
following example:</P
following example:</P
><TABLE
><TABLE
BORDER="5"
BORDER="5"
BGCOLOR="#E0E0F0"
BGCOLOR="#E0E0F0"
WIDTH="70%"
WIDTH="70%"
><TR
><TR
><TD
><TD
><PRE
><PRE
CLASS="SCREEN"
CLASS="SCREEN"
>puts Hello
>puts Hello
set x 42</PRE
set x 42</PRE
></TD
></TD
></TR
></TR
></TABLE
></TABLE
><P
><P
>This will result in two separate commands being executed. The first
>This will result in two separate commands being executed. The first
command is <TT
command is <TT
CLASS="LITERAL"
CLASS="LITERAL"
>puts</TT
>puts</TT
> and is passed a single argument,
> and is passed a single argument,
<TT
<TT
CLASS="LITERAL"
CLASS="LITERAL"
>Hello</TT
>Hello</TT
>. The second command is <TT
>. The second command is <TT
CLASS="LITERAL"
CLASS="LITERAL"
>set</TT
>set</TT
>
>
and is passed two arguments, <TT
and is passed two arguments, <TT
CLASS="LITERAL"
CLASS="LITERAL"
>x</TT
>x</TT
> and
> and
<TT
<TT
CLASS="LITERAL"
CLASS="LITERAL"
>42</TT
>42</TT
>. The intervening newline character serves to
>. The intervening newline character serves to
terminate the first command, and a semi-colon separator could be used
terminate the first command, and a semi-colon separator could be used
instead: </P
instead: </P
><TABLE
><TABLE
BORDER="5"
BORDER="5"
BGCOLOR="#E0E0F0"
BGCOLOR="#E0E0F0"
WIDTH="70%"
WIDTH="70%"
><TR
><TR
><TD
><TD
><PRE
><PRE
CLASS="SCREEN"
CLASS="SCREEN"
>puts Hello;set x 42</PRE
>puts Hello;set x 42</PRE
></TD
></TD
></TR
></TR
></TABLE
></TABLE
><P
><P
>Any white space surrounding the semicolon is just ignored because it
>Any white space surrounding the semicolon is just ignored because it
does not serve to separate arguments.</P
does not serve to separate arguments.</P
><P
><P
>Now consider the following:</P
>Now consider the following:</P
><TABLE
><TABLE
BORDER="5"
BORDER="5"
BGCOLOR="#E0E0F0"
BGCOLOR="#E0E0F0"
WIDTH="70%"
WIDTH="70%"
><TR
><TR
><TD
><TD
><PRE
><PRE
CLASS="SCREEN"
CLASS="SCREEN"
>set x Hello world</PRE
>set x Hello world</PRE
></TD
></TD
></TR
></TR
></TABLE
></TABLE
><P
><P
>This is not valid <SPAN
>This is not valid <SPAN
CLASS="APPLICATION"
CLASS="APPLICATION"
>Tcl</SPAN
>Tcl</SPAN
>. It is an attempt to invoke the
>. It is an attempt to invoke the
<TT
<TT
CLASS="LITERAL"
CLASS="LITERAL"
>set</TT
>set</TT
> command with three arguments:
> command with three arguments:
<TT
<TT
CLASS="LITERAL"
CLASS="LITERAL"
>x</TT
>x</TT
>, <TT
>, <TT
CLASS="LITERAL"
CLASS="LITERAL"
>Hello</TT
>Hello</TT
>, and
>, and
<TT
<TT
CLASS="LITERAL"
CLASS="LITERAL"
>world</TT
>world</TT
>. The <TT
>. The <TT
CLASS="LITERAL"
CLASS="LITERAL"
>set</TT
>set</TT
> only takes two
> only takes two
arguments, a variable name and a value, so it is necessary to combine
arguments, a variable name and a value, so it is necessary to combine
the data into a single argument by quoting:</P
the data into a single argument by quoting:</P
><TABLE
><TABLE
BORDER="5"
BORDER="5"
BGCOLOR="#E0E0F0"
BGCOLOR="#E0E0F0"
WIDTH="70%"
WIDTH="70%"
><TR
><TR
><TD
><TD
><PRE
><PRE
CLASS="SCREEN"
CLASS="SCREEN"
>set x "Hello world"</PRE
>set x "Hello world"</PRE
></TD
></TD
></TR
></TR
></TABLE
></TABLE
><P
><P
>When the <SPAN
>When the <SPAN
CLASS="APPLICATION"
CLASS="APPLICATION"
>Tcl</SPAN
>Tcl</SPAN
> interpreter encounters the first quote character it
> interpreter encounters the first quote character it
treats all subsequent data up to but not including the closing quote
treats all subsequent data up to but not including the closing quote
as part of the current argument. The quote marks are removed by the
as part of the current argument. The quote marks are removed by the
interpreter, so the second argument passed to the
interpreter, so the second argument passed to the
<TT
<TT
CLASS="LITERAL"
CLASS="LITERAL"
>set</TT
>set</TT
> command is just <TT
> command is just <TT
CLASS="LITERAL"
CLASS="LITERAL"
>Hello world</TT
>Hello world</TT
>
>
without the quote characters. This can be significant in the context
without the quote characters. This can be significant in the context
of <SPAN
of <SPAN
CLASS="APPLICATION"
CLASS="APPLICATION"
>CDL</SPAN
>CDL</SPAN
> scripts. For example:</P
> scripts. For example:</P
><TABLE
><TABLE
BORDER="5"
BORDER="5"
BGCOLOR="#E0E0F0"
BGCOLOR="#E0E0F0"
WIDTH="70%"
WIDTH="70%"
><TR
><TR
><TD
><TD
><PRE
><PRE
CLASS="PROGRAMLISTING"
CLASS="PROGRAMLISTING"
>cdl_option CYG_HAL_STARTUP {
>cdl_option CYG_HAL_STARTUP {
    &#8230;
    &#8230;
    default_value "RAM"
    default_value "RAM"
}</PRE
}</PRE
></TD
></TD
></TR
></TR
></TABLE
></TABLE
><P
><P
>The <SPAN
>The <SPAN
CLASS="APPLICATION"
CLASS="APPLICATION"
>Tcl</SPAN
>Tcl</SPAN
> interpreter strips off the quote marks so the <SPAN
> interpreter strips off the quote marks so the <SPAN
CLASS="APPLICATION"
CLASS="APPLICATION"
>CDL</SPAN
>CDL</SPAN
>
>
expression parsing code sees <TT
expression parsing code sees <TT
CLASS="LITERAL"
CLASS="LITERAL"
>RAM</TT
>RAM</TT
> instead of
> instead of
<TT
<TT
CLASS="LITERAL"
CLASS="LITERAL"
>"RAM"</TT
>"RAM"</TT
>. It will treat this as a reference to
>. It will treat this as a reference to
some unknown option <TT
some unknown option <TT
CLASS="VARNAME"
CLASS="VARNAME"
>RAM</TT
>RAM</TT
> rather than as a string
> rather than as a string
constant, and the expression evaluation code will use a value of
constant, and the expression evaluation code will use a value of
<TT
<TT
CLASS="LITERAL"
CLASS="LITERAL"
>0</TT
>0</TT
> when it encounters an option that is not
> when it encounters an option that is not
currently loaded. Therefore the option
currently loaded. Therefore the option
<TT
<TT
CLASS="VARNAME"
CLASS="VARNAME"
>CYG_HAL_STARTUP</TT
>CYG_HAL_STARTUP</TT
> ends up with a default value of
> ends up with a default value of
<TT
<TT
CLASS="LITERAL"
CLASS="LITERAL"
>0</TT
>0</TT
>. Either braces or backslashes should be used to
>. Either braces or backslashes should be used to
avoid this, for example
avoid this, for example
<TT
<TT
CLASS="LITERAL"
CLASS="LITERAL"
>default_value&nbsp;{&nbsp;"RAM"&nbsp;}</TT
>default_value&nbsp;{&nbsp;"RAM"&nbsp;}</TT
>. </P
>. </P
><DIV
><DIV
CLASS="NOTE"
CLASS="NOTE"
><BLOCKQUOTE
><BLOCKQUOTE
CLASS="NOTE"
CLASS="NOTE"
><P
><P
><B
><B
>Note: </B
>Note: </B
>There are long-term plans to implement some sort of <SPAN
>There are long-term plans to implement some sort of <SPAN
CLASS="APPLICATION"
CLASS="APPLICATION"
>CDL</SPAN
>CDL</SPAN
> validation
> validation
utility <SPAN
utility <SPAN
CLASS="APPLICATION"
CLASS="APPLICATION"
>cdllint</SPAN
>cdllint</SPAN
> which
> which
could catch common errors like this one.</P
could catch common errors like this one.</P
></BLOCKQUOTE
></BLOCKQUOTE
></DIV
></DIV
><P
><P
>A quoted argument continues until the closing quote character is
>A quoted argument continues until the closing quote character is
encountered, which means that it can span multiple lines. Newline or
encountered, which means that it can span multiple lines. Newline or
semicolon characters do not terminate the current command in such
semicolon characters do not terminate the current command in such
cases. <SPAN
cases. <SPAN
CLASS="PROPERTY"
CLASS="PROPERTY"
>description</SPAN
>description</SPAN
> properties usually make use of this:</P
> properties usually make use of this:</P
><TABLE
><TABLE
BORDER="5"
BORDER="5"
BGCOLOR="#E0E0F0"
BGCOLOR="#E0E0F0"
WIDTH="70%"
WIDTH="70%"
><TR
><TR
><TD
><TD
><PRE
><PRE
CLASS="PROGRAMLISTING"
CLASS="PROGRAMLISTING"
>cdl_package CYGPKG_ERROR {
>cdl_package CYGPKG_ERROR {
    description   "
    description   "
        This package contains the common list of error and
        This package contains the common list of error and
        status codes. It is held centrally to allow
        status codes. It is held centrally to allow
        packages to interchange error codes and status
        packages to interchange error codes and status
        codes in a common way, rather than each package
        codes in a common way, rather than each package
        having its own conventions for error/status
        having its own conventions for error/status
        reporting. The error codes are modelled on the
        reporting. The error codes are modelled on the
        POSIX style naming e.g. EINVAL etc. This package
        POSIX style naming e.g. EINVAL etc. This package
        also provides the standard strerror() function to
        also provides the standard strerror() function to
        convert error codes to textual representation."
        convert error codes to textual representation."
    &#8230;
    &#8230;
}</PRE
}</PRE
></TD
></TD
></TR
></TR
></TABLE
></TABLE
><P
><P
>The <SPAN
>The <SPAN
CLASS="APPLICATION"
CLASS="APPLICATION"
>Tcl</SPAN
>Tcl</SPAN
> interpreter supports much the same forms of backslash
> interpreter supports much the same forms of backslash
substitution as other common programming languages. Some backslash
substitution as other common programming languages. Some backslash
sequences such as <TT
sequences such as <TT
CLASS="LITERAL"
CLASS="LITERAL"
>\n</TT
>\n</TT
> will be replaced by the
> will be replaced by the
appropriate character. The sequence <TT
appropriate character. The sequence <TT
CLASS="LITERAL"
CLASS="LITERAL"
>\\</TT
>\\</TT
> will be
> will be
replaced by a single backslash. A backslash at the very end of a line
replaced by a single backslash. A backslash at the very end of a line
will cause that backslash, the newline character, and any white space
will cause that backslash, the newline character, and any white space
at the start of the next line to be replaced by a single space. Hence
at the start of the next line to be replaced by a single space. Hence
the following two Tcl commands are equivalent:</P
the following two Tcl commands are equivalent:</P
><TABLE
><TABLE
BORDER="5"
BORDER="5"
BGCOLOR="#E0E0F0"
BGCOLOR="#E0E0F0"
WIDTH="70%"
WIDTH="70%"
><TR
><TR
><TD
><TD
><PRE
><PRE
CLASS="PROGRAMLISTING"
CLASS="PROGRAMLISTING"
>puts  "Hello\nworld\n"
>puts  "Hello\nworld\n"
puts \
puts \
"Hello
"Hello
world
world
"</PRE
"</PRE
></TD
></TD
></TR
></TR
></TABLE
></TABLE
><P
><P
>If a <SPAN
>If a <SPAN
CLASS="PROPERTY"
CLASS="PROPERTY"
>description</SPAN
>description</SPAN
> string needs to contain quote marks or other
> string needs to contain quote marks or other
special characters then backslash escapes can be used. In addition to
special characters then backslash escapes can be used. In addition to
quote and backslash characters, the Tcl interpreter treats square
quote and backslash characters, the Tcl interpreter treats square
brackets, the <TT
brackets, the <TT
CLASS="LITERAL"
CLASS="LITERAL"
>$</TT
>$</TT
> character, and braces specially.
> character, and braces specially.
Square brackets are used for command substitution, for example:</P
Square brackets are used for command substitution, for example:</P
><TABLE
><TABLE
BORDER="5"
BORDER="5"
BGCOLOR="#E0E0F0"
BGCOLOR="#E0E0F0"
WIDTH="70%"
WIDTH="70%"
><TR
><TR
><TD
><TD
><PRE
><PRE
CLASS="SCREEN"
CLASS="SCREEN"
>puts "The answer is [expr 6 * 9]"</PRE
>puts "The answer is [expr 6 * 9]"</PRE
></TD
></TD
></TR
></TR
></TABLE
></TABLE
><P
><P
>When the Tcl interpreter encounters the square brackets it will treat
>When the Tcl interpreter encounters the square brackets it will treat
the contents as another command that should be executed first, and the
the contents as another command that should be executed first, and the
result of executing that is used when continuing to process the
result of executing that is used when continuing to process the
script. In this case the Tcl interpreter will execute the command
script. In this case the Tcl interpreter will execute the command
<TT
<TT
CLASS="LITERAL"
CLASS="LITERAL"
>expr 6 * 9</TT
>expr 6 * 9</TT
>, yielding a result of 42
>, yielding a result of 42
<A
<A
NAME="AEN1270"
NAME="AEN1270"
HREF="#FTN.AEN1270"
HREF="#FTN.AEN1270"
>[1]</A
>[1]</A
>
>
and then the
and then the
Tcl interpreter will execute <TT
Tcl interpreter will execute <TT
CLASS="LITERAL"
CLASS="LITERAL"
>puts "The answer is 42"</TT
>puts "The answer is 42"</TT
>.
>.
It should be noted that the interpreter performs only one level
It should be noted that the interpreter performs only one level
of substitution: if the result of performing command substitution
of substitution: if the result of performing command substitution
performs further special characters such as square brackets then these
performs further special characters such as square brackets then these
will not be treated specially.</P
will not be treated specially.</P
><P
><P
>Command substitution will not prove useful for many <SPAN
>Command substitution will not prove useful for many <SPAN
CLASS="APPLICATION"
CLASS="APPLICATION"
>CDL</SPAN
>CDL</SPAN
> scripts,
> scripts,
except for e.g. a <SPAN
except for e.g. a <SPAN
CLASS="PROPERTY"
CLASS="PROPERTY"
>define_proc</SPAN
>define_proc</SPAN
> property which involves a fragment of
> property which involves a fragment of
<SPAN
<SPAN
CLASS="APPLICATION"
CLASS="APPLICATION"
>Tcl</SPAN
>Tcl</SPAN
> code. Potentially there are some interesting uses, for example
> code. Potentially there are some interesting uses, for example
to internationalize <SPAN
to internationalize <SPAN
CLASS="PROPERTY"
CLASS="PROPERTY"
>display</SPAN
>display</SPAN
> strings. However care does have to be
> strings. However care does have to be
taken to avoid unexpected command substitution, for example if an
taken to avoid unexpected command substitution, for example if an
option description involves square brackets then typically these would
option description involves square brackets then typically these would
require backslash-escapes.</P
require backslash-escapes.</P
><P
><P
>The <TT
>The <TT
CLASS="LITERAL"
CLASS="LITERAL"
>$</TT
>$</TT
> character is used in Tcl scripts to perform
> character is used in Tcl scripts to perform
variable substitution:</P
variable substitution:</P
><TABLE
><TABLE
BORDER="5"
BORDER="5"
BGCOLOR="#E0E0F0"
BGCOLOR="#E0E0F0"
WIDTH="70%"
WIDTH="70%"
><TR
><TR
><TD
><TD
><PRE
><PRE
CLASS="PROGRAMLISTING"
CLASS="PROGRAMLISTING"
>set x [expr 6 * 9]
>set x [expr 6 * 9]
puts "The answer is $x"</PRE
puts "The answer is $x"</PRE
></TD
></TD
></TR
></TR
></TABLE
></TABLE
><P
><P
>Variable substitution, like command substitution, is unlikely to
>Variable substitution, like command substitution, is unlikely to
prove useful for many <SPAN
prove useful for many <SPAN
CLASS="APPLICATION"
CLASS="APPLICATION"
>CDL</SPAN
>CDL</SPAN
> scripts except in the context of
> scripts except in the context of
<SPAN
<SPAN
CLASS="APPLICATION"
CLASS="APPLICATION"
>Tcl</SPAN
>Tcl</SPAN
> fragments. If it is necessary to have a <TT
> fragments. If it is necessary to have a <TT
CLASS="LITERAL"
CLASS="LITERAL"
>$</TT
>$</TT
>
>
character then a backslash escape may have to be used.</P
character then a backslash escape may have to be used.</P
><P
><P
>Braces are used to collect a sequence of characters into a single
>Braces are used to collect a sequence of characters into a single
argument, just like quotes. The difference is that variable, command
argument, just like quotes. The difference is that variable, command
and backslash substitution do not occur inside braces (with the
and backslash substitution do not occur inside braces (with the
sole exception of backslash substitution at the end of a line).
sole exception of backslash substitution at the end of a line).
Therefore given a line in a <SPAN
Therefore given a line in a <SPAN
CLASS="APPLICATION"
CLASS="APPLICATION"
>CDL</SPAN
>CDL</SPAN
> script such as:</P
> script such as:</P
><TABLE
><TABLE
BORDER="5"
BORDER="5"
BGCOLOR="#E0E0F0"
BGCOLOR="#E0E0F0"
WIDTH="70%"
WIDTH="70%"
><TR
><TR
><TD
><TD
><PRE
><PRE
CLASS="PROGRAMLISTING"
CLASS="PROGRAMLISTING"
>default_value {"RAM"}</PRE
>default_value {"RAM"}</PRE
></TD
></TD
></TR
></TR
></TABLE
></TABLE
><P
><P
>The braces are stripped off by the <SPAN
>The braces are stripped off by the <SPAN
CLASS="APPLICATION"
CLASS="APPLICATION"
>Tcl</SPAN
>Tcl</SPAN
> interpreter, leaving
> interpreter, leaving
<TT
<TT
CLASS="LITERAL"
CLASS="LITERAL"
>"RAM"</TT
>"RAM"</TT
> which will be handled as a string constant by
> which will be handled as a string constant by
the expression parsing code. The same effect could be achieved using
the expression parsing code. The same effect could be achieved using
one of the following:</P
one of the following:</P
><TABLE
><TABLE
BORDER="5"
BORDER="5"
BGCOLOR="#E0E0F0"
BGCOLOR="#E0E0F0"
WIDTH="70%"
WIDTH="70%"
><TR
><TR
><TD
><TD
><PRE
><PRE
CLASS="PROGRAMLISTING"
CLASS="PROGRAMLISTING"
>default_value \"RAM\"
>default_value \"RAM\"
default_value "\"RAM\""</PRE
default_value "\"RAM\""</PRE
></TD
></TD
></TR
></TR
></TABLE
></TABLE
><P
><P
>Generally the use of braces is less confusing. At this stage it is
>Generally the use of braces is less confusing. At this stage it is
worth noting that the basic format of <SPAN
worth noting that the basic format of <SPAN
CLASS="APPLICATION"
CLASS="APPLICATION"
>CDL</SPAN
>CDL</SPAN
> data makes use of
> data makes use of
braces:</P
braces:</P
><TABLE
><TABLE
BORDER="5"
BORDER="5"
BGCOLOR="#E0E0F0"
BGCOLOR="#E0E0F0"
WIDTH="70%"
WIDTH="70%"
><TR
><TR
><TD
><TD
><PRE
><PRE
CLASS="PROGRAMLISTING"
CLASS="PROGRAMLISTING"
>cdl_option &lt;name&gt; {
>cdl_option &lt;name&gt; {
     &#8230;
     &#8230;
};</PRE
};</PRE
></TD
></TD
></TR
></TR
></TABLE
></TABLE
><P
><P
>The <TT
>The <TT
CLASS="LITERAL"
CLASS="LITERAL"
>cdl_option</TT
>cdl_option</TT
> command is passed two arguments, a name and a body,
> command is passed two arguments, a name and a body,
where the body consists of everything inside the braces but not the
where the body consists of everything inside the braces but not the
braces themselves. This body can then be executed in a recursive
braces themselves. This body can then be executed in a recursive
invocation of the <SPAN
invocation of the <SPAN
CLASS="APPLICATION"
CLASS="APPLICATION"
>Tcl</SPAN
>Tcl</SPAN
> interpreter. If a <SPAN
> interpreter. If a <SPAN
CLASS="APPLICATION"
CLASS="APPLICATION"
>CDL</SPAN
>CDL</SPAN
> script contains
> script contains
mismatched braces then the interpreter is likely to get rather
mismatched braces then the interpreter is likely to get rather
confused and the resulting diagnostics may be difficult to understand. </P
confused and the resulting diagnostics may be difficult to understand. </P
><P
><P
>Comments in Tcl scripts are introduced by a hash character
>Comments in Tcl scripts are introduced by a hash character
<TT
<TT
CLASS="LITERAL"
CLASS="LITERAL"
>#</TT
>#</TT
>. However, a hash character only introduces a
>. However, a hash character only introduces a
comment if it occurs where a command is expected. Consider the
comment if it occurs where a command is expected. Consider the
following:</P
following:</P
><TABLE
><TABLE
BORDER="5"
BORDER="5"
BGCOLOR="#E0E0F0"
BGCOLOR="#E0E0F0"
WIDTH="70%"
WIDTH="70%"
><TR
><TR
><TD
><TD
><PRE
><PRE
CLASS="PROGRAMLISTING"
CLASS="PROGRAMLISTING"
># This is a comment
># This is a comment
puts "Hello" # world</PRE
puts "Hello" # world</PRE
></TD
></TD
></TR
></TR
></TABLE
></TABLE
><P
><P
>The first line is a valid comment, since the hash character occurs
>The first line is a valid comment, since the hash character occurs
right at the start where a command name is expected. The second line
right at the start where a command name is expected. The second line
does not contain a comment. Instead it is an attempt to invoke the
does not contain a comment. Instead it is an attempt to invoke the
<TT
<TT
CLASS="LITERAL"
CLASS="LITERAL"
>puts</TT
>puts</TT
> command with three arguments:
> command with three arguments:
<TT
<TT
CLASS="LITERAL"
CLASS="LITERAL"
>Hello</TT
>Hello</TT
>, <TT
>, <TT
CLASS="LITERAL"
CLASS="LITERAL"
>#</TT
>#</TT
> and
> and
<TT
<TT
CLASS="LITERAL"
CLASS="LITERAL"
>world</TT
>world</TT
>. These are not valid arguments for the
>. These are not valid arguments for the
<TT
<TT
CLASS="LITERAL"
CLASS="LITERAL"
>puts</TT
>puts</TT
> command so an error will be raised.
> command so an error will be raised.
If the second line was rewritten as:</P
If the second line was rewritten as:</P
><TABLE
><TABLE
BORDER="5"
BORDER="5"
BGCOLOR="#E0E0F0"
BGCOLOR="#E0E0F0"
WIDTH="70%"
WIDTH="70%"
><TR
><TR
><TD
><TD
><PRE
><PRE
CLASS="PROGRAMLISTING"
CLASS="PROGRAMLISTING"
>puts "Hello"; # world</PRE
>puts "Hello"; # world</PRE
></TD
></TD
></TR
></TR
></TABLE
></TABLE
><P
><P
>then this is a valid Tcl script. The semicolon identifies the end of
>then this is a valid Tcl script. The semicolon identifies the end of
the current command, so the hash character occurs at a point where the
the current command, so the hash character occurs at a point where the
next command would start and hence it is interpreted as the start of a
next command would start and hence it is interpreted as the start of a
comment.</P
comment.</P
><P
><P
>This handling of comments can lead to subtle behavior. Consider the
>This handling of comments can lead to subtle behavior. Consider the
following:</P
following:</P
><TABLE
><TABLE
BORDER="5"
BORDER="5"
BGCOLOR="#E0E0F0"
BGCOLOR="#E0E0F0"
WIDTH="70%"
WIDTH="70%"
><TR
><TR
><TD
><TD
><PRE
><PRE
CLASS="PROGRAMLISTING"
CLASS="PROGRAMLISTING"
>cdl_option WHATEVER {
>cdl_option WHATEVER {
# This is a comment }
# This is a comment }
    default_value 0
    default_value 0
    &#8230;
    &#8230;
}</PRE
}</PRE
></TD
></TD
></TR
></TR
></TABLE
></TABLE
><P
><P
>Consider the way the Tcl interpreter processes this. The command name
>Consider the way the Tcl interpreter processes this. The command name
and the first argument do not pose any special difficulties. The
and the first argument do not pose any special difficulties. The
opening brace is interpreted as the start of the next argument, which
opening brace is interpreted as the start of the next argument, which
continues until a closing brace is encountered. In this case the
continues until a closing brace is encountered. In this case the
closing brace occurs on the second line, so the second argument passed
closing brace occurs on the second line, so the second argument passed
to <TT
to <TT
CLASS="LITERAL"
CLASS="LITERAL"
>cdl_option</TT
>cdl_option</TT
> is
> is
<TT
<TT
CLASS="LITERAL"
CLASS="LITERAL"
>\n&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;This&nbsp;is&nbsp;a&nbsp;comment</TT
>\n&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;This&nbsp;is&nbsp;a&nbsp;comment</TT
>. This second argument is processed in a recursive
>. This second argument is processed in a recursive
invocation of the Tcl interpreter and does not contain any commands,
invocation of the Tcl interpreter and does not contain any commands,
just a comment. Top-level script processing then resumes, and the next
just a comment. Top-level script processing then resumes, and the next
command that is encountered is <TT
command that is encountered is <TT
CLASS="LITERAL"
CLASS="LITERAL"
>default_value</TT
>default_value</TT
>. Since
>. Since
the parser is not currently processing a configuration option this is
the parser is not currently processing a configuration option this is
an error. Later on the Tcl interpreter would encounter a closing brace
an error. Later on the Tcl interpreter would encounter a closing brace
by itself, which is also an error.</P
by itself, which is also an error.</P
><P
><P
>For component writers who need more information about <SPAN
>For component writers who need more information about <SPAN
CLASS="APPLICATION"
CLASS="APPLICATION"
>Tcl</SPAN
>Tcl</SPAN
>,
>,
especially about the language rather than the syntax, various
especially about the language rather than the syntax, various
resources are available. A reasonable starting point is the
resources are available. A reasonable starting point is the
<A
<A
HREF="http://www.tcl.tk/scripting/"
HREF="http://www.tcl.tk/scripting/"
TARGET="_top"
TARGET="_top"
>Scriptics developer
>Scriptics developer
web site</A
web site</A
>.</P
>.</P
></DIV
></DIV
><H3
><H3
CLASS="FOOTNOTES"
CLASS="FOOTNOTES"
>Notes</H3
>Notes</H3
><TABLE
><TABLE
BORDER="0"
BORDER="0"
CLASS="FOOTNOTES"
CLASS="FOOTNOTES"
WIDTH="100%"
WIDTH="100%"
><TR
><TR
><TD
><TD
ALIGN="LEFT"
ALIGN="LEFT"
VALIGN="TOP"
VALIGN="TOP"
WIDTH="5%"
WIDTH="5%"
><A
><A
NAME="FTN.AEN1270"
NAME="FTN.AEN1270"
HREF="language.tcl.html#AEN1270"
HREF="language.tcl.html#AEN1270"
>[1]</A
>[1]</A
></TD
></TD
><TD
><TD
ALIGN="LEFT"
ALIGN="LEFT"
VALIGN="TOP"
VALIGN="TOP"
WIDTH="95%"
WIDTH="95%"
><P
><P
>It is possible that some versions of the Tcl interpreter will instead
>It is possible that some versions of the Tcl interpreter will instead
produce a result of 54 when asked to multiply six by nine. Appropriate
produce a result of 54 when asked to multiply six by nine. Appropriate
<A
<A
HREF="http://www.douglasadams.com/creations/hhgg.html"
HREF="http://www.douglasadams.com/creations/hhgg.html"
TARGET="_top"
TARGET="_top"
>reference
>reference
documentation</A
documentation</A
> should be consulted for more information on why
> should be consulted for more information on why
42 is in fact the correct answer.</P
42 is in fact the correct answer.</P
></TD
></TD
></TR
></TR
></TABLE
></TABLE
><DIV
><DIV
CLASS="NAVFOOTER"
CLASS="NAVFOOTER"
><HR
><HR
ALIGN="LEFT"
ALIGN="LEFT"
WIDTH="100%"><TABLE
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
SUMMARY="Footer navigation table"
WIDTH="100%"
WIDTH="100%"
BORDER="0"
BORDER="0"
CELLPADDING="0"
CELLPADDING="0"
CELLSPACING="0"
CELLSPACING="0"
><TR
><TR
><TD
><TD
WIDTH="33%"
WIDTH="33%"
ALIGN="left"
ALIGN="left"
VALIGN="top"
VALIGN="top"
><A
><A
HREF="language.naming.html"
HREF="language.naming.html"
ACCESSKEY="P"
ACCESSKEY="P"
>Prev</A
>Prev</A
></TD
></TD
><TD
><TD
WIDTH="34%"
WIDTH="34%"
ALIGN="center"
ALIGN="center"
VALIGN="top"
VALIGN="top"
><A
><A
HREF="cdl-guide.html"
HREF="cdl-guide.html"
ACCESSKEY="H"
ACCESSKEY="H"
>Home</A
>Home</A
></TD
></TD
><TD
><TD
WIDTH="33%"
WIDTH="33%"
ALIGN="right"
ALIGN="right"
VALIGN="top"
VALIGN="top"
><A
><A
HREF="language.values.html"
HREF="language.values.html"
ACCESSKEY="N"
ACCESSKEY="N"
>Next</A
>Next</A
></TD
></TD
></TR
></TR
><TR
><TR
><TD
><TD
WIDTH="33%"
WIDTH="33%"
ALIGN="left"
ALIGN="left"
VALIGN="top"
VALIGN="top"
>Option Naming Convention</TD
>Option Naming Convention</TD
><TD
><TD
WIDTH="34%"
WIDTH="34%"
ALIGN="center"
ALIGN="center"
VALIGN="top"
VALIGN="top"
><A
><A
HREF="language.html"
HREF="language.html"
ACCESSKEY="U"
ACCESSKEY="U"
>Up</A
>Up</A
></TD
></TD
><TD
><TD
WIDTH="33%"
WIDTH="33%"
ALIGN="right"
ALIGN="right"
VALIGN="top"
VALIGN="top"
>Values and Expressions</TD
>Values and Expressions</TD
></TR
></TR
></TABLE
></TABLE
></DIV
></DIV
></BODY
></BODY
></HTML
></HTML
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.