Intel XENIX 286 Programmers Guide (86) - Tenox.tc
Intel XENIX 286 Programmers Guide (86) - Tenox.tc Intel XENIX 286 Programmers Guide (86) - Tenox.tc
XENIX Programming m4: Macro Processor Manipulating Files You can include a new file in the input at any point by using the built-in macro include: include( filename) inserts the contents of filename in place of the include command. The contents of the file is often a set of definitions. The value of include (that is, its replacement text) is the contents of the file. It is a fatal error if the file named in include cannot be accessed. To gain some control over this situation, the alternate form sinclude can be used; sinclude (for "silent include") says nothing and continues if it can't access the file. You can divert the output of m4 to temporary files during processing and output the collected material upon command. m4 maintains nine of these diversions, nu mbered 1 through 9. If you use divert(n) all subsequent output is put onto the end of a temporary file referred to as "n". Diverting to this file is stopped by another divert command; in particular, divert or divert(O) resumes the normal output process. Diverted text is normally output all at once at the end of processing, with the diversions output in numeric order. However, you can bring back diversions at any time. undivert brings back all diversions in nu meric order, and undivert with argu ments brings back the selected diversions in the order given. The act of undiverting discards the diverted text, as does diverting into a diversion with a number not between 0 and 9 inclusive. The value of undivert is not the diverted text. Furthermore, the diverted material is not rescanned for macros. The built-in divnum returns the number of the currently active diversion. This is zero during normal processing. 11-7
m4: Macro Processor XENIX Programming Using System Commands You can run any program in the local operat ing system with the built-in macro syscmd. For example, syscmd(date) runs the date command. Normally, syscmd would be used to create a file for a subsequent include. To facilitate making unique file names, the built-in maketemp is provided, with specifications identical to the system function mktemp: a string of the form "XXXXX" in the argu ment is replaced by the process ID of the current process. Using Conditionals The built-in macro ifelse performs arbitrary conditional testing. In the simplest form, ifelse(a, b, c, d) compares the two strings a and b. If these are identical, ifelse returns the string c; otherwise it returns d. Thus, we might define a macro called compare that compares two strings and returns "yes" or "no" if they are the same or different. defi ne(compare, 'ifelse($1, $2, yes, no)') Note the quotation marks, which prevent premature evaluation of ifelse. If the fourth argument is missing, it is treated as empty. ifelse can have any number of arguments and provides a multi-way decision capability. In the input ifelse(a, b, c, d, e, f, g) if the string a matches the string b, the result is c. Otherwise, if d is the same as e, the result is f. Otherwise the result is g. If the final argument is omitted, the result is null, so ifelse(a, b, c) is c if a matches b, and null otherwise. 11-8
- Page 198 and 199: XENIX Programming lex: Lexical Anal
- Page 200 and 201: XENIX Programming The definitions s
- Page 202 and 203: CHAPTER 10 yacc: COMPILER-COMPILER
- Page 204 and 205: XENIX Programming yacc: Compiler-Co
- Page 206 and 207: XENIX Programming yacc: Compiler-Co
- Page 208 and 209: XENIX Programming yacc: Compiler-Co
- Page 210 and 211: XENIX Programming yacc: Compiler-Co
- Page 212 and 213: XENIX Programming yacc: Compiler-Co
- Page 214 and 215: XENIX Programming yacc: Compiler-Co
- Page 216 and 217: XENIX Programming yacc: Compiler-Co
- Page 218 and 219: XENIX Programming yacc: Compiler-Co
- Page 220 and 221: XENIX Programming yacc: Compiler-Co
- Page 222 and 223: XENIX Programming yacc: Compiler-Co
- Page 224 and 225: XENIX Programming yacc: Compiler-Co
- Page 226 and 227: XENIX Programming yacc: Compiler-Co
- Page 228 and 229: XENIX Programming yacc: Compiler-Co
- Page 230 and 231: XENIX Programming yacc: Compiler-Co
- Page 232 and 233: XENIX Programming yacc: Compiler-Co
- Page 234 and 235: XENIX Programming yacc: Compiler-Co
- Page 236 and 237: XENIX Programming %left %left %left
- Page 238 and 239: XENIX Programming I* lexical analys
- Page 240: XENIX Programming yacc: Compiler-Co
- Page 243 and 244: m4: Macro Processor XENIX Programmi
- Page 245 and 246: m4: Macro Processor XENIX Programmi
- Page 247: m4: Macro Processor XENIX Programm
- Page 251 and 252: m4: Macro Processor XENIX Programmi
- Page 253 and 254: C Language Portability XENIX Progra
- Page 255 and 256: C Language Portability XENIX Progra
- Page 257 and 258: C Language Portability XENIX Progra
- Page 259 and 260: C Language Portability XENIX Progra
- Page 261 and 262: C Language Portability XENIX Progra
- Page 263 and 264: C Language Portability XENIX Progra
- Page 266 and 267: APPENDIX B PROG RAMMING COMMANDS Th
- Page 268 and 269: XENIX Programming ad b (continued)
- Page 270 and 271: XENIX Programming Programming Comma
- Page 272 and 273: XENIX Programming Programming Comma
- Page 274 and 275: XENIX Programming Programming Comma
- Page 276 and 277: XENIX Programming Programming Comma
- Page 278 and 279: XENIX Programming Programming Comma
- Page 280 and 281: XENIX Programming Programming Comma
- Page 282 and 283: XENIX Programming Programming Comma
- Page 284 and 285: XENIX Programming as (continued) Fi
- Page 286 and 287: XENIX Programming Programming Comma
- Page 288 and 289: XENIX Programming Programming Comma
- Page 290 and 291: XENIX Programming Programm ing Comm
- Page 292 and 293: XENIX Programming Programming Comma
- Page 294 and 295: XENIX Programming Programming Comma
- Page 296 and 297: XENIX Programming Programm ing Comm
<strong>XENIX</strong> Programming m4: Macro Processor<br />
Manipulating Files<br />
You can include a new file in the input at any point by using the built-in macro include:<br />
include( filename)<br />
inserts the contents of filename in place of the include command. The contents of the<br />
file is often a set of definitions. The value of include (that is, its replacement text) is<br />
the contents of the file.<br />
It is a fatal error if the file named in include cannot be accessed. To gain some control<br />
over this situation, the alternate form sinclude can be used; sinclude (for "silent<br />
include") says nothing and continues if it can't access the file.<br />
You can divert the output of m4 to temporary files during processing and output the<br />
collected material upon command. m4 maintains nine of these diversions, nu mbered 1<br />
through 9. If you use<br />
divert(n)<br />
all subsequent output is put onto the end of a temporary file referred to as "n".<br />
Diverting to this file is stopped by another divert command; in particular, divert or<br />
divert(O) resumes the normal output process.<br />
Diverted text is normally output all at once at the end of processing, with the diversions<br />
output in numeric order. However, you can bring back diversions at any time.<br />
undivert<br />
brings back all diversions in nu meric order, and undivert with argu ments brings back the<br />
selected diversions in the order given. The act of undiverting discards the diverted text,<br />
as does diverting into a diversion with a number not between 0 and 9 inclusive.<br />
The value of undivert is not the diverted text. Furthermore, the diverted material is<br />
not rescanned for macros.<br />
The built-in divnum returns the number of the currently active diversion. This is zero<br />
during normal processing.<br />
11-7