home *** CD-ROM | disk | FTP | other *** search
- MACRO version 5.5, 26-May-85
-
- Specifications:
-
- This macro processor resembles somewhat the one in Kernighan and Plauger's
- book Software Tools in Pascal. However, some additions and modifications have
- been made to allow it to be used with text files as well as programs. Many
- details of operation and implementation are also different.
-
- The macro processor scans its input file looking for macros. A macro
- is defined by a command of the form:
-
- %define(name,replacement)
-
- "Name" must contain only alphanumeric characters, and it must start with
- either a letter or a special character defined as MACROCHAR in the source
- (currently set to "%"). "Name" must not contain any embedded blanks. Whenever
- "name" is encountered in the input file, separated from other text by blanks or
- by non-alphabetic characters, it will be replaced by the string "replacement".
-
- Macros are allowed to have up to ten arguments, which may be included in
- the replacement text by specifying them as $1, $2, etc. (a la Kernighan and
- Plauger). If a carriage return immediately follows the end of a built-in that
- does not produce any output (such as %define) then the carriage return will not
- be written to the output file. Thus, lines containing only %define or similar
- statements produce no output. Text within special "quote" characters is copied
- literally to the output, without any macro expansions (the quote characters are
- stripped off). The default quote characters are "{" and "}".
-
- If the statement "%capsok(on)" appears in the source before the definition
- of a macro, then the macro processor will recognize the macro regardless of
- whether the first letter of its name is lower- or upper-case. If the macro name
- is found in the input file with an initial capital letter, then the replacement
- text will also be made to have an initial capital letter. If the macro appears
- with a small initial letter, the replacement text will also have a small
- initial letter. Without the "%capsok" option, macro names in the source must
- exactly match the name in the definition (including case of all letters) in
- order for replacement to occur. Note that the %capsok option is set at
- definition time, not at the time the macro is being evaluated. This option can
- be selectively disabled for some some macros by setting "%capsok(off)".
-
- Other built-ins:
-
- %append(filename)
-
- Following this command, all output from MACRO is tacked onto the end of
- the named file, instead of going to the normal output file. The file must
- already exist on the disk.
-
- %divert(filename)
-
- Following this command, all output from MACRO is written to the file name
- given. If the file does not already exist on the disk, it is created.
-
- %enddivert
-
- Marks the end of a diversion begun with %divert or %append, resumes
- writing to the standard output file.
-
- %expr(expr)
-
- Causes the current value of "expr" to be written to the output
- file as a decimal number. "Expr" is an expression consisting of
- register variables and/or integers (see %register for details).
-
- %fill(on) or %fill(off)
-
- Allows or disables filling of text (default is off). If filling is on, as
- many words are packed into output lines as will fit within the right and
- left margins (default 0 and 79). MACRO is fairly sophisticated in its handling
- of hyphens, slashes etc. "Hard hyphen" and "ghost hyphen" characters are
- recognized and treated appropriately (these can be changed with the %spchars
- built-in). Lines beginning with a space or a word-processor command character
- (user-settable) will be output without filling.
-
- %ifelse(a,b,c,d)
-
- If a=b, expands to c, otherwise expands to d. The carriage return
- following this statement is suppressed if it produces no output.
-
- %include(filename)
- %source(filename)
-
- Starts reading from "filename" instead of the original input file. Reading
- resumes from the input file after the end of file on "filename". "%source" is a
- synonym for "%include".
-
- %macros(on) or %macros(off)
-
- Turns on and off expansion of macros. Default is on. If %macros(off)
- is specified, built-ins are still evaluated, but macros defined with
- %define statements are treated as text and output without replacement.
-
- %margins(left,right)
-
- sets right and left margins
-
- %quotes(char1,char2)
-
- sets quote characters to char1 (left) and char2 (right).
-
- %register(#n,expr)
-
- Sets one of ten register variables (#0 to #9) to the value of "expr",
- which may be any expression containing register variables (prefixed by #),
- integer constants and the operations +, -, \ (integer division), *, and %
- (modulus).
-
- %spchars(macrochar,argsym,sepsym,wcmdchar,hardhy,ghosthy)
-
- sets MACRO to recognize the following special characters:
-
- macrochar non-alphanumeric character, can start a macro name
- (default "%")
- argsym identifies a macro argument in the replacement portion
- of a "%define" macro. Default "$".
- sepsym separator, can be used to set off a macro embedded within
- a word. It will not be copied to the output. Default "\".
- wcmdchar word-processor command character. Lines beginning with this
- character are not filled. Default "^".
- hardhy hard hyphen character, cannot be removed during filling as
- a regular hyphen can. Default is Control-Underline.
- ghosthy "ghost hyphen", may be embedded in words, is ignored by
- MACRO (but will be copied to the output, unless the word
- of which it is a part is a macro). Default "&".
-
- %trace(on) or %trace(off)
-
- If on, shows the expansion of each macro on the screen, plus other stats.
- Default is off.
-
- %translit(char1,char2)
-
- Causes char1 to be replaced by char2 everywhere in the output. Ranges of
- characters can be specified for both char1 and char2: for example,
- "%translit(a-z,A-Z)" maps all lower-case characters to upper-case. Trans-
- literation is always done after macro expansion. Consequently, using %translit
- to redefine any of the special characters, such as argsym or sepsym (see under
- %spchars for list) does not affect the operation of MACRO-- the same
- characters are still recognized as special, and will be transliterated
- only if they are inside quotes or are otherwise part of a string that would
- normally appear in the output file. If you want to specify the quote
- characters for either char1 or char2, I recommend the following way:
-
- %quotes(",') (set new quote characters)
- %translit("{',[) (translit { to [)
- %quotes({,}) (reset old quote characters)
-
- Known bugs/limitations:
-
- 1. A command of the form %define(x,x) or even %define(x,something x) causes
- an infinite loop. To avoid this, if the replacement string contains the name
- string as a substring, enclose the replacement string in 2 layers of quotes
- (the first gets stripped off during definition, the second gets stripped off at
- evaluation time). E.g.:
-
- %define(very,{{very, very}})
-
- 2. Because macros are evaluated immediately as they are encountered, be
- careful about using built-ins inside of an %ifelse macro. E.g. the statement:
-
- %ifelse(draft,true,%include(outline.txt))
-
- may cause an "argument too long" error, because MACRO will evaluate the
- %include macro and try to store the whole contents of "outline.txt" in its
- argument buffer (before even checking to see if draft=true!). This problem can
- be avoided by putting quote characters around the %include macro. Similarly, a
- statement like:
-
- %ifelse(draft,true,%trace(on))
-
- will always turn tracing on (because %trace is evaluated before %ifelse),
- unless the %trace macro is enclosed in quotes.
-
- 3. MACRO does not currently support nested %source, %divert or %append
- commands, but this may be added in a future version. The hooks are in the
- program, it is just not implemented (or tested).
-
- 4. Tab characters (^I) in the input are copied directly to the output. This
- will result in improperly spaced output if filling is enabled and the input
- file contains tabs. It is recommended that input files not contain tabs if
- filling is to be used.
-
- 5. The input file should be in ASCII format (i.e. lines should end with a
- carriage return or line feed or both). MACRO doesn't (yet) know what to do
- with WordStar-style "soft" carriage returns.
-
- 6. The text of all macros (name and replacement) is currently limited to
- 5500 characters. The total length of all arguments in a single macro
- call must not exceed 500 characters. Macros can be nested 15 deep.
- Input lines may be up to 132 characters long; output lines may be up to
- 160 characters. All of these limitations are set by constants defined
- in file "MACRO1.PAS".
-
-