📄 editing-an-ecos-savefile.html
字号:
><PRE
CLASS="SCREEN"
> cdl_option CYGDAT_LIBC_STDIO_DEFAULT_CONSOLE {
# Flavor: data
# No user value, uncomment the following line to provide one.
# user_value “\”/dev/ttydiag\””
# value_source default
# Default value: “\”/dev/ttydiag\””
}; </PRE
></TD
></TR
></TABLE
><P
>The desired value of the configuration option should be a
valid C string, complete with quote characters. If the savefile
was edited to: </P
><TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="SCREEN"
> cdl_option CYGDAT_LIBC_STDIO_DEFAULT_CONSOLE {
# Flavor: data
user_value “/dev/ttydiag”
# value_source default
# Default value: “\”/dev/ttydiag\””
}; </PRE
></TD
></TR
></TABLE
><P
>then the Tcl interpreter would remove the quote marks when
the savefile is read back in, so the option’s value would
not have any quote marks and would not be a valid C string. The
configuration system is not yet able to perform the required validation
so the following <TT
CLASS="LITERAL"
>#define</TT
> would
be generated in the configuration header file:</P
><TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>#define CYGDAT_LIBC_STDIO_DEFAULT_CONSOLE /dev/ttydiag </PRE
></TD
></TR
></TABLE
><P
>This is likely to cause a compile-time failure when building
<SPAN
CLASS="PRODUCTNAME"
>eCos</SPAN
>.</P
><P
>A quoted argument continues until the closing quote character
is encountered, which means that it can span multiple lines. This
can also be encountered in <SPAN
CLASS="PRODUCTNAME"
>eCos</SPAN
> savefiles, for instance, in the <TT
CLASS="LITERAL"
>CYGDAT_UITRON_MEMPOOLVAR_EXTERNS</TT
> example
mentioned earlier. Newline or semicolon characters do not terminate
the current command in such cases.</P
><P
>The Tcl interpreter supports much the same forms of backslash
substitution as other common programming languages. Some backslash
sequences such as <TT
CLASS="LITERAL"
>\n</TT
> will
be replaced by the appropriate character. The sequence <TT
CLASS="LITERAL"
>\\</TT
> will
be 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 at the start of the next line to be replaced by a single
space. Hence the following two Tcl commands are equivalent:</P
><TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>puts “Hello\nworld\n”
puts \
“Hello
world
“</PRE
></TD
></TR
></TABLE
><P
>In addition to quote and backslash characters, the Tcl interpreter
treats square brackets, the <TT
CLASS="LITERAL"
>$</TT
> character,
and braces specially. Square brackets are used for command substitution,
for example:</P
><TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>puts “The answer is [expr 6 * 9]”</PRE
></TD
></TR
></TABLE
><P
>When the Tcl interpreter encounters the square brackets it
will treat the contents as another command that should be executed
first, and the result of executing that is used when continuing
to process the script. In this case the Tcl interpreter will execute
the command <TT
CLASS="LITERAL"
>expr 6 * 9</TT
>,
yielding a result of 54, and then the Tcl interpreter will execute
<TT
CLASS="LITERAL"
>puts “The answer is 54”</TT
>. It should be noted that
the interpreter contains only one level of substitution: if the
result of performing command substitution performs further special
characters such as square brackets then these will not be treated
specially.</P
><P
>Command line substitution is very unlikely to prove useful
in the context of an <SPAN
CLASS="PRODUCTNAME"
>eCos</SPAN
> savefile, but it is part of the Tcl language
and hence cannot be easily suppressed while reading in a savefile.
As a result care has to be taken when savefile data involves square
brackets. Consider the following:</P
><TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
> cdl_option CYGDAT_UITRON_MEMPOOLFIXED_EXTERNS {
...
user_value \
“static char fpool1[ 2000 ],
fpool2[ 2000 ];”
...
};</PRE
></TD
></TR
></TABLE
><P
>The Tcl interpreter will interpret the square brackets as
an attempt at command substitution and hence it will attempt to
execute the command <TT
CLASS="LITERAL"
>2000</TT
> with no
arguments. No such command is defined by the Tcl language or by
the savefile-related extensions provided by the configuration system,
so this will result in an error when an attempt is made to read
back the savefile. Instead it is necessary to backslash-escape the
square brackets and thus suppress command substitution:</P
><TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
> cdl_option CYGDAT_UITRON_MEMPOOLFIXED_EXTERNS {
...
user_value \
“static char fpool1\[ 2000 \],
fpool2\[ 2000 \];”
...
}; </PRE
></TD
></TR
></TABLE
><P
>Similarly the <TT
CLASS="LITERAL"
>$</TT
> character
is used in Tcl scripts to perform variable substitution:</P
><TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>set x [expr 6 * 9]
puts “The answer is $x” </PRE
></TD
></TR
></TABLE
><P
>Variable substitution, like command substitution, is very
unlikely to prove useful in the context of an <SPAN
CLASS="PRODUCTNAME"
>eCos</SPAN
> savefile. Should
it be necessary to have a <TT
CLASS="LITERAL"
>$</TT
> character
in configuration data then again a backslash escape needs to be
used.</P
><TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>cdl_option FOODAT_MONITOR_PROMPT {
...
user_value “\$ “
...
};</PRE
></TD
></TR
></TABLE
><P
>Braces are used to collect a sequence of characters into a
single argument, just like quotes. The difference is that variable,
command and backslash substitution do not occur inside braces (with
the sole exception of backslash substitution at the end of a line).
So, for example, the <TT
CLASS="LITERAL"
>CYGDAT_UITRON_MEMPOOL_EXTERNFIXED_EXTERNS</TT
> value
could be written as:</P
><TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>cdl_option CYGDAT_UITRON_MEMPOOLFIXED_EXTERNS {
...
user_value \
{static char fpool1[ 2000 ],
fpool2[ 2000 ];}
...
};</PRE
></TD
></TR
></TABLE
><P
>The configuration system does not use this when generating
savefiles because for simple edits of a savefile by inexperienced
users the use of brace characters is likely to be a little bit more
confusing than the use of quotes.</P
><P
>At this stage it is worth noting that the basic format of
each configuration option in the savefile makes use of braces:</P
><TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>cdl_option <name> {
...
};</PRE
></TD
></TR
></TABLE
><P
>The configuration system extends the Tcl language with a small
number of additional commands such as <TT
CLASS="LITERAL"
>cdl_option</TT
>.
These commands take two arguments, a name and a body, where the
body consists of all the text between the braces. First a check
is made that the specified option is actually present in the configuration.
Then the body is executed in a recursive invocation of the Tcl interpreter,
this time with additional commands such as <TT
CLASS="LITERAL"
>user_value</TT
> and <TT
CLASS="LITERAL"
>value_source</TT
>.
If, after editing, the braces are not correctly matched up then
the savefile will no longer be a valid Tcl script and errors will
be reported when the savefile is loaded again.</P
><P
>Comments in Tcl scripts are introduced by a hash character <TT
CLASS="LITERAL"
>#</TT
>.
However, a hash character only introduces a comment if it occurs
where a command is expected. Consider the following:</P
><TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
># This is a comment
puts “Hello” # world </PRE
></TD
></TR
></TABLE
><P
>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 does not contain a comment. Instead it is an attempt
to invoke the <TT
CLASS="LITERAL"
>puts</TT
> command with
three arguments: <TT
CLASS="LITERAL"
>Hello</TT
>, <TT
CLASS="LITERAL"
>#</TT
> and <TT
CLASS="LITERAL"
>world</TT
>.
These are not valid arguments for the <TT
CLASS="LITERAL"
>puts</TT
> command
so an error will be raised.</P
><P
>If the second line was rewritten as:</P
><TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>puts “Hello”; # world</PRE
></TD
></TR
></TABLE
><P
>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 next command would start and hence it is interpreted
as the start of a comment.</P
><P
>This handling of comments can lead to subtle behaviour. Consider
the following:</P
><TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>cdl_option WHATEVER {
# This is a comment }
user_value 42
...
}</PRE
></TD
></TR
></TABLE
><P
>Consider the way the Tcl interpreter processes this. The command
name and the first argument do not pose any special difficulties.
The opening brace is interpreted as the start of the next argument,
which continues until a closing brace is encountered. In this case
the closing brace occurs on the second line, so the second argument
passed to <TT
CLASS="LITERAL"
>cdl_option</TT
> is <TT
CLASS="LITERAL"
>\n # This is a comment</TT
> . This second argument
is processed in a recursive invocation of the Tcl interpreter and
does not contain any commands, just a comment. Toplevel savefile
processing then resumes, and the next command that is encountered
is <TT
CLASS="LITERAL"
>user_value</TT
>. Since the
relevant savefile code is not currently processing a configuration
option this is an error. Later on the Tcl interpreter would encounter
a closing brace by itself, which is also an error. Fortunately this
sequence of events is very unlikely to occur when editing generated
savefiles.</P
><P
>This should be sufficient information about Tcl to allow for
safe editing of <SPAN
CLASS="PRODUCTNAME"
>eCos</SPAN
> savefiles. Further information is available
from a wide variety of sources, for example the book <SPAN
CLASS="emphasis"
><I
CLASS="EMPHASIS"
>Tcl
and the Tk Toolkit </I
></SPAN
>by John K Ousterhout.</P
></DIV
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="fine-grained-configuration.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="ecos-user-guide.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="editing-the-sources.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>Fine-grained Configuration</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="manual-configuration.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>Editing the Sources</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -