📄 cwebman.tex
字号:
put a short if--else construction on a single line.If you say `\.{\{@+}' at the beginning of a compound statementthat is the body of a function, the first declaration orstatement of the function will appear on the same line as theleft brace, and it will be indented by the same amount as thesecond declaration or statement on the next line.\@; [MC] This control code is treated like a semicolon, for formattingpurposes, except that it is invisible. You can use it, for example, aftera section name or macro when the \CEE/ text represented by that section or macrois a compound statement or endswith a semicolon. Consider constructions like$$\lpile{\.{if (condition) macro @;}\cr\.{else break;}\cr}$$where \\{macro} is defined to be a compound statement (enclosed in braces).This is a well-known infelicity of \CEE/ syntax.\@{[} [MC] See \.{@]}.\@] [MC] Place \.{@[...@]} brackets around program text that \.{CWEAVE} issupposed to format as an expression, if it doesn't already do so. (Thisoccasionally applies to unusual macro arguments.) Alsoinsert `\.{@[@]}' between a simple type name and a left parenthesiswhen declaring a pointer to a function, as in$$\.{int @[@] (*f)();}$$otherwise \.{CWEAVE} will confuse the first part of that declaration withthe \CPLUSPLUS/ expression `\&{int}($*f$)'. Another example, for peoplewho want to use low-level \.{\#define} commands in the midst of \CEE/ codeand the definition begins with a cast:$$\.{\#define foo @[(int)(bar)@]}$$\subsecThe remaining control codes govern the input that \.{CWEB} sees.\@{x @y @z}[\\{change\_file}]\.{CWEAVE} and \.{CTANGLE} are designed to work with two input files,called \\{web\_file} and \\{change\_file}, where \\{change\_file} containsdata that overrides selected portions of \\{web\_file}. The resulting mergedtext is actually what has been called the \.{CWEB} file elsewhere in thisreport.\more Here's how it works: The change file consists of zero or more ``changes,''where a change has the form `\.{@x}$\langle$old lines$\rangle$\.{@y}$\langle$%new lines$\rangle$\.{@z}'. The special control codes \.{@x}, \.{@y}, \.{@z},which are allowed only in change files, must appear at the beginning of a line;the remainder of such a line is ignored.The $\langle$old lines$\rangle$ represent material that exactly matchesconsecutive lines of the \\{web\_file}; the $\langle$new lines$\rangle$represent zero or more lines that are supposed to replace the old. Wheneverthe first ``old line'' of a change is found to match a line in the\\{web\_file}, all the other lines in that change must match too.\more Between changes, before the first change, and after the last change,the change file can have any number of lines that do not begin with`\.{@x}', `\.{@y}', or~`\.{@z}'. Such lines are bypassed and not used formatching purposes.\more This dual-input feature is useful when working with a master \.{CWEB}file that has been received from elsewhere (e.g., \.{tangle.w} or\.{weave.w} or \.{tex.web}), when changes are desirable to customize theprogram for your local computer system. You will be able to debug yoursystem-dependent changes without clobbering the master web file; and onceyour changes are working, you will be able to incorporate them readilyinto new releases of the master web file that you might receive from timeto time.\@i [\\{web\_file}]Furthermore the \\{web\_file} itself can be a combination ofseveral files. When either \.{CWEAVE} or \.{CTANGLE} is reading a file andencounters the control code \.{@i} at the beginning of a line, itinterrupts normal reading and starts looking at the file named after the\.{@i}, much as the \CEE/ preprocessor does when it encounters an \.{\#include}line. After the included file has been entirely read, the programgoes back to the next lineof the original file. The file name following \.{@i} can besurrounded by \." characters, but such delimiters areoptional. Include files can nest.\moreChange files can have lines starting with \.{@i}. In this wayyou can replace one included file with another. Conceptually, thereplacement mechanism described above does its work first, andits output is then checked for \.{@i} lines. If \.{@i} \.{foo}occurs between \.{@y} and \.{@z} in a change file, individual linesof file \.{foo} and files it includes are not changeable; but changescan be made to lines from files that were included by unchanged input.\more On UNIX systems (and others that support environment variables),if the environment variable \.{CWEBINPUTS} is set, or if the compiler flagof the same name was defined at compile time,\.{CWEB} will look for include files in the directory thus named, ifit cannot find them in the current directory.\section Additional features and caveats.1. In certain installations of \.{CWEB} that{\def\\#1#2{`{\tentex\char'#1#2}'}%have an extended character set, the characters\\13, \\01, \\31, \\32, \\34, \\35,\\36, \\37, \\04, \\20, and \\21}can be typed as abbreviations for `\.{++}', `\.{--}', `\.{->}',`\.{!=}', `\.{<=}', `\.{>=}', `\.{==}', `\.{\v\v}', `\.{\&\&}',`\.{<<}', and `\.{>>}',respectively.2. If you have an extended character set, you can use it with only minimalrestrictions, as discussed under the rules for \.{@l} above. But you shouldstick to standard ASCII characters if you want to write programs that willbe useful to all the poor souls out there who don't have extendedcharacter sets.3. The \TEX/ file output by \.{CWEAVE} is broken into lines having at most80 characters each. When\TEX/ text is being copied, the existing line breaks are copied as well.If you aren't doing anything too tricky, \.{CWEAVE} will recognize whena \TEX/ comment is being split across two or more lines, and it willappend `\.\%' to the beginning of such continued comments.4. \CEE/ text is translated by a ``bottom up'' procedure thatidentifies each token as a ``part of speech'' and combines parts of speechinto larger and larger phrases as much as possible according to a specialgrammar that is explained in the documentation of \.{CWEAVE}. It is easy tolearn the translation scheme for simple constructions like singleidentifiers and short expressions, just by looking at a few examples ofwhat \.{CWEAVE} does, but the general mechanism is somewhat complex becauseit must handle much more than \CEE/ itself. Furthermore the outputcontains embedded codes that cause \TEX/ to indent and break lines asnecessary, depending on the fonts used and the desired page width. Forbest results it is wise to avoid enclosing long \CEE/ texts in \pb, since theindentation and line breaking codes are omitted when the \pb\ text istranslated from \CEE/ to \TEX/. Stick to simple expressions orstatements. If a \CEE/ preprocessor command is enclosed in \pb,the \.\# that introduces it must be at the beginning of a line,or \.{CWEAVE} won't print it correctly.5. Comments are not permitted in \pb\ text. After a `\.|'signals the change from \TEX/ text to \CEE/ text, the next `\.|' that isnot part of a string or control text or section name ends the \CEE/ text.6. A comment must have properly nested occurrences of left and rightbraces, otherwise \.{CWEAVE} will complain. But itdoes try to balance the braces, so that \TEX/ won't foul up too much.7. When you're debugging a program and decide to omit some of your\CEE/ code, do NOT simply ``comment it out.'' Such comments are notin the spirit of \.{CWEB} documentation; they will appear to readersas if they were explanations of the uncommented-out instructions.Furthermore, comments of a program must be valid \TEX/ text; hence\.{CWEAVE} will get confused if you enclose \CEE/ statements in\.{/*...*/} instead of in \.{/*|...|*/}. If you must comment out\CEE/ code, you can surround it with preprocessor commandslike \.{\#if 0==1} and \.{\#endif}.8. The \.{@f} feature allows you to define one identifier to act likeanother, and these format definitions are carried out sequentially.In general, a given identifier has only one printed formatthroughout the entire document, and this format is used even beforethe \.{@f} that defines it. The reason is that \.{CWEAVE} operates in twopasses; it processes \.{@f}'s and cross-references on the first pass andit does the output on the second. (However, identifiers thatimplicitly get a boldface format, thanks to a \.{typedef} declaration,don't obey this rule; they are printed differently before and afterthe relevant \.{typedef}. This is unfortunate, but hard to fix. You canget around the restriction by saying, say, `\.{@s} \.{foo} \.{int}',before or after the \.{typedef}.)9. Sometimes it is desirable to insert spacing into formatted \CEE/ code thatis more general than the thin space provided by `\.{@,}'. The \.{@t} featurecan be used for this purpose; e.g., `\.{@t\\hskip 1in@>}' willleave one inch of blank space. Furthermore, `\.{@t\\4@>}' can beused to backspace by one unit of indentation, since the control sequence\.{\\4} is defined in \.{cwebmac} to be such a backspace. (Thiscontrol sequence is used, for example, at the beginning of lines thatcontain labeled statements, so that the label will stick out a little atthe left.) You can also use `\.{@t\}\\3\{-5@>}' to force a breakin the middle of an expression.10. Each identifier in \.{CWEB} has a single formatting convention. Thereforeyou shouldn't use the same identifier to denote, say, both a type name andpart of a \.{struct}, even though \CEE/ does allow this.\section Running the programs.The \UNIX/ command line for \.{CTANGLE} is$$\.{ctangle [options] web\_file[.w] [\{change\_file[.ch]|-\} [out\_file]]}$$and the same conventions apply to \.{CWEAVE}. If `\.-' or no change file isspecified, the change file is null. The extensions \.{.w} and \.{.ch}are appended only if the given file names contain no dot. If theweb file defined in this way cannot be found, the extension \.{.web}will be tried. For example, `\.{cweave} \.{cob}' will try to read\.{cob.w}; failing that, it will try \.{cob.web} before giving up.If no output file name is specified, the name of the \CEE/ file output by\.{CTANGLE} is obtained by appending the extension \.{.c};the name of the \TEX/ file output by \.{CWEAVE} gets the extension \.{.tex}.Index files output by \.{CWEAVE} replace \.{.tex} by \.{.idx} and \.{.scn}.Programmers who like terseness might choose to set up their operating shell so that `\.{wv}' expands to`\.{cweave -bhp}'; this will suppress most terminal output from \.{CWEAVE}except for error messages.Options are introduced either by a \.- sign, to turn an option off,or by a \.+ sign to turn one on. For example, `\.{-fb}' turns offoptions \.f and \.b; `\.{+s}' turns on option \.s. Options can bespecified before the file names, after the file names, or both. The followingoptions are currently implemented:\yskip\def\option#1 {\textindent{\.#1}\hangindent2\parindent}\option b Print a banner line at the beginning of execution. (Onby default.)\option e Enclose \CEE/ material formatted by \.{CWEAVE} inbrackets \.{\\PB\{...\}}, so that special hooks can be used.(Off by default; has no effect on \.{CTANGLE}.)\option f Force line breaks after each \CEE/ statement formattedby \.{CWEAVE}. (On by default; \.{-f} saves paper but looks less \CEE/-liketo some people.) (Has no effect on \.{CTANGLE}.)\option h Print a happy message at the conclusion of a successfulrun. (On by default.)\option p Give progress reports as the program runs. (On by default.)\option s Show statistics about memory usage after the programruns to completion. (Off by default.)If youhave large \.{CWEB} files or sections, you may need to seehow close you come to exceeding the capacity of \.{CTANGLE} and/or \.{CWEAVE}.\option x Include indexes and a table of contents in the \TEX/ fileoutput by \.{CWEAVE}. (On by default.) (Has no effect on \.{CTANGLE}.)\section Further details about formatting.You may not like the way \.{CWEAVE} handles certainsituations. If you're desperate, you can customize \.{CWEAVE}by changing its grammar. This means changing the source code,a task that you might find amusing. A table of grammar rulesappears in the \.{CWEAVE} source listing, and you can make a separatecopy of that table by copying the file \.{prod.w} found in the \.{CWEB}sources and saying `\.{cweave}~\.{-x}~\.{prod}', followed by`\.{tex}~\.{prod}'.You can see exactlyhow \.{CWEAVE} is parsing your \CEE/ code by precedingit with the line `\.{@ @c @2}'. (The control code `\.{@2}'turns on a ``peeping'' mode, and `\.{@0}' turns it off.)For example, if you run \.{CWEAVE} on the file\medskip\begingroup\verbatim@ @c @2main (argc,argv)char **argv;{ for (;argc>0;argc--) printf("%s\n",argv[argc-1]); }!endgroup\endgroup\medskip\noindentyou get the following gibberish on your screen:\medskip\begingroup\verbatim[...]4:*exp ( +exp+ )...11:*exp +exp+ int...5:*+exp+ int +unorbinop+...[...]60: +fn_decl+*+{+ -stmt- +}-55:*+fn_decl+ -stmt-52:*+function-[...]!endgroup\endgroup\medskip
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -