⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 language.sgml

📁 ecos实时嵌入式操作系统
💻 SGML
📖 第 1 页 / 共 5 页
字号:
mentioning here. When the component framework generates aconfiguration header file for a given package, by default it will usea name derived from the package name (the &define-header; property canbe used to override this). The file name is constructed from thepackage name by removing everything up to and including the firstunderscore, converting the remainder of the name to lower case, andappending a <literal>.h</literal> suffix. For example the kernelpackage <varname>CYGPKG_KERNEL</varname> will involve a header file<filename class="headerfile">pkgconf/kernel.h</filename>. If aconfiguration contained some other package<varname>XYZPKG_KERNEL</varname> then this would attempt to use thesame configuration header file, with unfortunate effects. Casesensitivity could introduce problems as well, so a package<varname>xyzpkg_kernel</varname> would involve the same problem. Evenif the header file names preserved the case of the package name, notall file systems are case sensitive. There is no simple solution tothis problem. Changing the names of the generated configuration headerfiles would involve a major incompatible change to the interface, tosolve a problem which is essentially hypothetical in nature.</para></sect1><!-- }}} --><!-- {{{ Introduction to Tcl    --><sect1 id="language.tcl"><title>An Introduction to Tcl</title><para>All &CDL; scripts are implemented as &Tcl; scripts, and are read in byrunning the data through a standard &Tcl; interpreter, extended with asmall number of additional commands such as<literal>cdl_option</literal> and <literal>cdl_component</literal>.Often it is not necessary to know the full details of &Tcl; syntax.Instead it is possible to copy an existing script, perform some copyand paste operations, and make appropriate changes to names and tovarious properties. However there are also cases where anunderstanding of &Tcl; syntax is very desirable, for example:</para><programlisting width=72>cdl_option CYGDAT_UITRON_MEMPOOLFIXED_EXTERNS {    display       "Externs for initialization"    flavor        data    default_value {"static char fpool1[ 2000 ], \\\n\	                        fpool2[ 2000 ], \\\n\	                        fpool3[ 2000 ];"}    &hellip;}</programlisting><para>This causes the &cdl-option; command to be executed, which in turnevaluates its body in a recursive invocation of the &Tcl; interpreter.When the &default-value; property is encountered the braces around thevalue part are processed by the interpreter, stopping it from doingfurther processing of the braced contents (except for backslashprocessing at the end of a line, that is special). In particular itprevents command substitution for<literal>[&nbsp;2000&nbsp;]</literal>. A single argument will bepassed to the &default-value; command which expects a &CDL;expression, so the expression parsing code is passed the following:</para><screen width=72>"static char fpool1[ 2000 ], \\\n fpool2[ 2000 ], \\\n fpool3[ 2000 ];"</screen><para>The &CDL; expression parsing code will treat this as a simple stringconstant, as opposed to a more complicated expression involving otheroptions and various operators. The string parsing code will performthe usual backslash substitutions so the actual default value will be:</para><screen width=72>static char fpool1[ 2000 ], \ fpool2[ 2000 ], \ fpool3[ 2000 ];</screen><para>If the user does not modify the option's value then the followingwill be generated in the appropriate configuration header file:</para><programlisting width=72>#define CYGDAT_UITRON_MEMPOOLFIXED_EXTERNS static char fpool1[ 2000 ], \ fpool2[ 2000 ], \ fpool3[ 2000 ];</programlisting><para>Getting this desired result usually requires an understanding of both&Tcl; syntax and &CDL; expression syntax. Sometimes it is possible tosubstitute a certain amount of trial and error instead, but this mayprove frustrating. It is also worth pointing out that many &CDL;scripts do not involve this level of complexity. On the other hand,some of the more advanced features of the &CDL; language involvefragments of &Tcl; code, for example the &define-proc; property. Touse these component writers will need to know about the full &Tcl;language as well as the syntax.</para><para>Although the current example may seem to suggest that &Tcl; is rathercomplicated, it is actually a very simple yet powerful scriptinglanguage: the syntax is defined by just eleven rules. On occasion thissimplicity means that Tcl's behavior is subtly different from otherlanguages, which can confuse newcomers.</para><para>When the Tcl interpreter is passed some data such as<literal>puts&nbsp;Hello</literal>, it splits this data into a commandand its arguments. The command will be terminated by a newline or by asemicolon, unless one of the quoting mechanisms is used. The commandand each of its arguments are separated by white space. So in thefollowing example:</para><screen width=72>puts Helloset x 42</screen><para>This will result in two separate commands being executed. The firstcommand is <literal>puts</literal> and is passed a single argument,<literal>Hello</literal>. The second command is <literal>set</literal>and is passed two arguments, <literal>x</literal> and<literal>42</literal>. The intervening newline character serves toterminate the first command, and a semi-colon separator could be usedinstead: </para><screen width=72>puts Hello;set x 42</screen><para>Any white space surrounding the semicolon is just ignored because itdoes not serve to separate arguments.</para><para>Now consider the following:</para><screen width=72>set x Hello world</screen><para>This is not valid &Tcl;. It is an attempt to invoke the<literal>set</literal> command with three arguments:<literal>x</literal>, <literal>Hello</literal>, and<literal>world</literal>. The <literal>set</literal> only takes twoarguments, a variable name and a value, so it is necessary to combinethe data into a single argument by quoting:</para><screen width=72>set x "Hello world"</screen><para>When the &Tcl; interpreter encounters the first quote character ittreats all subsequent data up to but not including the closing quoteas part of the current argument. The quote marks are removed by theinterpreter, so the second argument passed to the<literal>set</literal> command is just <literal>Hello world</literal>without the quote characters. This can be significant in the contextof &CDL; scripts. For example:</para><programlisting width=72>cdl_option CYG_HAL_STARTUP {    &hellip;    default_value "RAM"}</programlisting><para>The &Tcl; interpreter strips off the quote marks so the &CDL;expression parsing code sees <literal>RAM</literal> instead of<literal>"RAM"</literal>. It will treat this as a reference tosome unknown option <varname>RAM</varname> rather than as a stringconstant, and the expression evaluation code will use a value of<literal>0</literal> when it encounters an option that is notcurrently loaded. Therefore the option<varname>CYG_HAL_STARTUP</varname> ends up with a default value of<literal>0</literal>. Either braces or backslashes should be used toavoid this, for example<literal>default_value&nbsp;{&nbsp;"RAM"&nbsp;}</literal>. </para><note><para>There are long-term plans to implement some sort of &CDL; validationutility <application class="software">cdllint</application> whichcould catch common errors like this one.</para></note><para>A quoted argument continues until the closing quote character isencountered, which means that it can span multiple lines. Newline orsemicolon characters do not terminate the current command in suchcases. &description; properties usually make use of this:</para><programlisting width=72>cdl_package CYGPKG_ERROR {    description   "        This package contains the common list of error and        status codes. It is held centrally to allow        packages to interchange error codes and status        codes in a common way, rather than each package        having its own conventions for error/status        reporting. The error codes are modelled on the        POSIX style naming e.g. EINVAL etc. This package        also provides the standard strerror() function to        convert error codes to textual representation."    &hellip;}</programlisting><para>The &Tcl; interpreter supports much the same forms of backslashsubstitution as other common programming languages. Some backslashsequences such as <literal>\n</literal> will be replaced by theappropriate character. The sequence <literal>\\</literal> will bereplaced by a single backslash. A backslash at the very end of a linewill cause that backslash, the newline character, and any white spaceat the start of the next line to be replaced by a single space. Hencethe following two Tcl commands are equivalent:</para><programlisting width=72>puts  "Hello\nworld\n"puts \"Helloworld"</programlisting><para>If a &description; string needs to contain quote marks or otherspecial characters then backslash escapes can be used. In addition toquote and backslash characters, the Tcl interpreter treats squarebrackets, the <literal>$</literal> character, and braces specially.Square brackets are used for command substitution, for example:</para><screen width=72>puts "The answer is [expr 6 * 9]"</screen><para>When the Tcl interpreter encounters the square brackets it will treatthe contents as another command that should be executed first, and theresult of executing that is used when continuing to process thescript. In this case the Tcl interpreter will execute the command<literal>expr 6 * 9</literal>, yielding a result of 42<footnote><para>It is possible that some versions of the Tcl interpreter will insteadproduce a result of 54 when asked to multiply six by nine. Appropriate<ulink url="http://www.douglasadams.com/creations/hhgg.html">referencedocumentation</ulink> should be consulted for more information on why42 is in fact the correct answer.</para></footnote>and then theTcl interpreter will execute <literal>puts "The answer is 42"</literal>.It should be noted that the interpreter performs only one levelof substitution: if the result of performing command substitutionperforms further special characters such as square brackets then thesewill not be treated specially.</para><para>Command substitution will not prove useful for many &CDL; scripts,except for e.g. a &define-proc; property which involves a fragment of&Tcl; code. Potentially there are some interesting uses, for exampleto internationalize &display; strings. However care does have to betaken to avoid unexpected command substitution, for example if anoption description involves square brackets then typically these wouldrequire backslash-escapes.</para><para>The <literal>$</literal> character is used in Tcl scripts to performvariable substitution:</para><programlisting width=72>set x [expr 6 * 9]puts "The answer is $x"</programlisting><para>Variable substitution, like command substitution, is unlikely toprove useful for many &CDL; scripts except in the context of&Tcl; fragments. If it is necessary to have a <literal>$</literal>character then a backslash escape may have to be used.</para><para>Braces are used to collect a sequence of characters into a singleargument, just like quotes. The difference is that variable, commandand backslash substitution do not occur inside braces (with thesole exception of backslash substitution at the end of a line).Therefore given a line in a &CDL; script such as:</para><programlisting width=72>default_value {"RAM"}</programlisting><para>The braces are stripped off by the &Tcl; interpreter, leaving<literal>"RAM"</literal> which will be handled as a string constant bythe expression parsing code. The same effect could be achieved usingone of the following:</para><programlisting width=72>default_value \"RAM\"default_value "\"RAM\""</programlisting><para>Generally the use of braces is less confusing. At this stage it isworth noting that the basic format of &CDL; data makes use ofbraces:</para><programlisting width=72>cdl_option &lt;name&gt; {     &hellip;};</programlisting><para>The &cdl-option; command is passed two arguments, a name and a body,where the body consists of everything inside the braces but not thebraces themselves. This body can then be executed in a recursiveinvocation of the &Tcl; interpreter. If a &CDL; script containsmismatched braces then the interpreter is likely to get ratherconfused and the resulting diagnostics may be difficult to understand. </para><para>Comments in Tcl scripts are introduced by a hash character<literal>#</literal>. However, a hash character only introduces acomment if

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -