📄 editing-an-ecos-savefile.html
字号:
><PRECLASS="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 avalid C string, complete with quote characters. If the savefilewas edited to: </P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="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 whenthe savefile is read back in, so the option’s value wouldnot have any quote marks and would not be a valid C string. Theconfiguration system is not yet able to perform the required validationso the following <TTCLASS="LITERAL">#define</TT> wouldbe generated in the configuration header file:</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="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<SPANCLASS="PRODUCTNAME">eCos</SPAN>.</P><P>A quoted argument continues until the closing quote characteris encountered, which means that it can span multiple lines. Thiscan also be encountered in <SPANCLASS="PRODUCTNAME">eCos</SPAN> savefiles, for instance, in the <TTCLASS="LITERAL">CYGDAT_UITRON_MEMPOOLVAR_EXTERNS</TT> examplementioned earlier. Newline or semicolon characters do not terminatethe current command in such cases.</P><P>The Tcl interpreter supports much the same forms of backslashsubstitution as other common programming languages. Some backslashsequences such as <TTCLASS="LITERAL">\n</TT> willbe replaced by the appropriate character. The sequence <TTCLASS="LITERAL">\\</TT> willbe replaced by a single backslash. A backslash at the very end ofa line will cause that backslash, the newline character, and anywhite space at the start of the next line to be replaced by a singlespace. Hence the following two Tcl commands are equivalent:</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">puts “Hello\nworld\n” puts \ “Hello world “</PRE></TD></TR></TABLE><P>In addition to quote and backslash characters, the Tcl interpretertreats square brackets, the <TTCLASS="LITERAL">$</TT> character,and braces specially. Square brackets are used for command substitution,for example:</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">puts “The answer is [expr 6 * 9]”</PRE></TD></TR></TABLE><P>When the Tcl interpreter encounters the square brackets itwill treat the contents as another command that should be executedfirst, and the result of executing that is used when continuingto process the script. In this case the Tcl interpreter will executethe command <TTCLASS="LITERAL">expr 6 * 9</TT>,yielding a result of 54, and then the Tcl interpreter will execute<TTCLASS="LITERAL">puts “The answer is 54”</TT>. It should be noted thatthe interpreter contains only one level of substitution: if theresult of performing command substitution performs further specialcharacters such as square brackets then these will not be treatedspecially.</P><P>Command line substitution is very unlikely to prove usefulin the context of an <SPANCLASS="PRODUCTNAME">eCos</SPAN> savefile, but it is part of the Tcl languageand hence cannot be easily suppressed while reading in a savefile.As a result care has to be taken when savefile data involves squarebrackets. Consider the following:</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="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 asan attempt at command substitution and hence it will attempt toexecute the command <TTCLASS="LITERAL">2000</TT> with noarguments. No such command is defined by the Tcl language or bythe savefile-related extensions provided by the configuration system,so this will result in an error when an attempt is made to readback the savefile. Instead it is necessary to backslash-escape thesquare brackets and thus suppress command substitution:</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING"> cdl_option CYGDAT_UITRON_MEMPOOLFIXED_EXTERNS { ... user_value \ “static char fpool1\[ 2000 \], fpool2\[ 2000 \];” ... }; </PRE></TD></TR></TABLE><P>Similarly the <TTCLASS="LITERAL">$</TT> characteris used in Tcl scripts to perform variable substitution:</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">set x [expr 6 * 9] puts “The answer is $x” </PRE></TD></TR></TABLE><P>Variable substitution, like command substitution, is veryunlikely to prove useful in the context of an <SPANCLASS="PRODUCTNAME">eCos</SPAN> savefile. Shouldit be necessary to have a <TTCLASS="LITERAL">$</TT> characterin configuration data then again a backslash escape needs to beused.</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">cdl_option FOODAT_MONITOR_PROMPT { ... user_value “\$ “ ... };</PRE></TD></TR></TABLE><P>Braces are used to collect a sequence of characters into asingle argument, just like quotes. The difference is that variable,command and backslash substitution do not occur inside braces (withthe sole exception of backslash substitution at the end of a line).So, for example, the <TTCLASS="LITERAL">CYGDAT_UITRON_MEMPOOL_EXTERNFIXED_EXTERNS</TT> valuecould be written as:</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="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 generatingsavefiles because for simple edits of a savefile by inexperiencedusers the use of brace characters is likely to be a little bit moreconfusing than the use of quotes.</P><P>At this stage it is worth noting that the basic format ofeach configuration option in the savefile makes use of braces:</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">cdl_option <name> { ... };</PRE></TD></TR></TABLE><P>The configuration system extends the Tcl language with a smallnumber of additional commands such as <TTCLASS="LITERAL">cdl_option</TT>.These commands take two arguments, a name and a body, where thebody consists of all the text between the braces. First a checkis 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 <TTCLASS="LITERAL">user_value</TT> and <TTCLASS="LITERAL">value_source</TT>.If, after editing, the braces are not correctly matched up thenthe savefile will no longer be a valid Tcl script and errors willbe reported when the savefile is loaded again.</P><P>Comments in Tcl scripts are introduced by a hash character <TTCLASS="LITERAL">#</TT>.However, a hash character only introduces a comment if it occurswhere a command is expected. Consider the following:</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING"># This is a comment puts “Hello” # world </PRE></TD></TR></TABLE><P>The first line is a valid comment, since the hash characteroccurs right at the start where a command name is expected. Thesecond line does not contain a comment. Instead it is an attemptto invoke the <TTCLASS="LITERAL">puts</TT> command withthree arguments: <TTCLASS="LITERAL">Hello</TT>, <TTCLASS="LITERAL">#</TT> and <TTCLASS="LITERAL">world</TT>.These are not valid arguments for the <TTCLASS="LITERAL">puts</TT> commandso an error will be raised.</P><P>If the second line was rewritten as:</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">puts “Hello”; # world</PRE></TD></TR></TABLE><P>then this is a valid Tcl script. The semicolon identifiesthe end of the current command, so the hash character occurs ata point where the next command would start and hence it is interpretedas the start of a comment.</P><P>This handling of comments can lead to subtle behaviour. Considerthe following:</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="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 commandname 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 casethe closing brace occurs on the second line, so the second argumentpassed to <TTCLASS="LITERAL">cdl_option</TT> is <TTCLASS="LITERAL">\n # This is a comment</TT> . This second argumentis processed in a recursive invocation of the Tcl interpreter anddoes not contain any commands, just a comment. Toplevel savefileprocessing then resumes, and the next command that is encounteredis <TTCLASS="LITERAL">user_value</TT>. Since therelevant savefile code is not currently processing a configurationoption this is an error. Later on the Tcl interpreter would encountera closing brace by itself, which is also an error. Fortunately thissequence of events is very unlikely to occur when editing generatedsavefiles.</P><P>This should be sufficient information about Tcl to allow forsafe editing of <SPANCLASS="PRODUCTNAME">eCos</SPAN> savefiles. Further information is availablefrom a wide variety of sources, for example the book <SPANCLASS="emphasis"><ICLASS="EMPHASIS">Tcland the Tk Toolkit </I></SPAN>by John K Ousterhout.</P></DIV></DIV><DIVCLASS="NAVFOOTER"><HRALIGN="LEFT"WIDTH="100%"><TABLESUMMARY="Footer navigation table"WIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top"><AHREF="fine-grained-configuration.html"ACCESSKEY="P">Prev</A></TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="ecos-user-guide.html"ACCESSKEY="H">Home</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top"><AHREF="editing-the-sources.html"ACCESSKEY="N">Next</A></TD></TR><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top">Fine-grained Configuration</TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="manual-configuration.html"ACCESSKEY="U">Up</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top">Editing the Sources</TD></TR></TABLE></DIV></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -