Copyright (C) 1990 - 2000 Terry D. Boldt, All Rights Reserved
The document formatting utility formats documents using 'dot commands'. All commands start with a period as the first character of a line followed by two or more characters of the command. Each command performs a specific formatting task. All of the commands are listed below. Formatter internal variables or user defined variables may be imbedded in the text as "{variable_name}" and are replaced before dot commands are recognized.
The formatter is used to format documents as:
qtawk -f fmtdoc.exp document-source-1 document-source-2
The formatted documents are output to the standard output file and may be redirected or piped as desired or applicable. For example, under Linux, the 'lpr' utility is usually used to send output to a printer:
qtawk -f fmtdoc.exp document-source-1 | lpr
The available commands are:
| .* | .ad | .bm |
.br |
.cc |
.ce |
.ds |
.elif |
.else |
.endif |
.fo |
.fr |
.fs |
.hr |
.hs |
.h[0-9] |
.if |
.il |
.im |
.in |
.ll |
.pa |
.pl |
.pn |
| .pp |
.pt |
.px |
.se |
.sp |
.sr |
.ss |
.sx |
.tb |
.tc |
.td |
.tl |
.tm |
.us |
:li. |
:ol. |
:sl. |
:ul. |
:e[osu]l. |
| Blank input line | Breaks paragraph formation, Causes current line to be output and signals start of new paragraph. |
| .* | comment line. Any line beginning with this sequence will be ignored |
| .ad .sr |
.ad == Addressee's address. .sr == sender's address Tag each line as: .sr Jane Doe Line is added to sender's address array. Will be printed in upper left corner of envelope if envelope printed. Line reformatted as: ".tb xx addr" where 'xx' is replaced by the current value of the 'sender_tabs' variable. .ad John Doe Line is added to adressee's address array. Will be printed in center of envelope if the envelope is printed. Each Line reformatted as: ".br addr" |
| .cc | Output Control Codes to the printer. The control cdes
are specified on the same line. The form is:
.cc [i] "control string"; For example the control string to turn on compressed printing on most Epson printers is hexadecimal 0xf. This would sent to the printer as: .cc i "\x00f"; The optional 'i' commands the format utility to send the control string to the printer immediately. If the 'i' is not specified, the control string is prepended to the next word formatted and sent to the printer when the line containing the word is output. |
| .fo | turn formatting on or off or specify ragged right
or left margin. There are four forms of this command:
|
| .br | break command. Output current line and format any text on line |
| .ce Text | center line. Center the text speified on the line.
For example:
.ce This line centered This line centered |
| .il xx | indent line. Break and indent next output line xx spaces. If xx is not an integer, the current indentation is used. |
| .im | imbed file specified. May only imbed to a depth of
one level. Processing continues on current file at current location
at end of imbedded file. Files in the same directory as the current
input file may be imbedded with the simple command:
.im {FILEPATH}filename If the files to be imbedded are all in the same directory, which is different from the directory of the current imput file, then the following sequence of commands will find and imbed them: .se dir = "Desired_directory_path"; |
| .in [-+]xx | indent. Indent remaining lines at xx spaces. If xx is not an integer, the default left margin indentation is used, 0. If xx is prefixed by '+' or '-', the current indentaion is incremented/decremented the specified amount. |
| .ll | line length. Set line length to xx characters. If xx is not an integer, the default line length is used, 75. |
| .h[0-9] | Section header command. The form of the command is
(for a 1st level header):
.h1 Title Text The Section header title text is formatted with the number of the section header. The section headers are numbered consecutively starting with 1. All lower level sections numbers are reset to 1. Thus, the sequence of commands: .h0 Top level section Is formatted as: 1.0 Top level section If '0' is specified, a page eject is performed if the output is not currently at the top of a page. Also, another page eject is performed if the current page is then even. Also, if the internal variable 'reset_headr_0' is true, page numbering is reset to 1 for a '.h0' command. The valu eof the 'reset_headr_0' variable may be set with the '.se' command. It has a default value of zero, 0. The formatter variable 'header_0_text' is set equal to the text of "Title Text". This can then be used for headers and footers as well as including into other text, e.g., .fr even |Document Title|- # -|{header_0_text}|
All Section header commands insert the header title text into the Table of Contents. |
| .hr | page header. Set page header line. Forms are:
The default header line for even pages is: "||- # -||" and for odd pages is: "||- # -||" Note that the header text acts the same as the '.sx' command text. Note: the page header command does not take effect until the current page has been printed and before the next page is started. If the output is currently at the top of a page, e.g., immediately following a ".pa" command, then the page header command takes effect immediately. |
| .hs | header skip. Set page header skip. Forms are:
The header skip lines are output as blank lines after writing the page header. |
| .fr | page footer. Set page Footer line. Forms are:
The default footer line for even pages is: "||- # -||" and for odd pages is: "||- # -||" Note that the footer text acts the same as the '.sx' command text. Note: the page header command does not take effect until the current page has been printed and before the next page is started. If the output is currently at the top of a page, e.g., immediately following a ".pa" command, then the page header command takes effect immediately. |
| .fs | footer skip. Set page Footer skip. Forms are:
The footer skip lines are output as blank lines before writing the page footer. |
| .if .else .elif .endif |
The formatter supports conditional formatting of source
text. The 'if' conditional, 'elif' conditional, 'else' alternative conditional
and 'endif' commands are supported.
Note that it is possible to nest '.if' conditional commands within other '.if', '.elif' and '.else' conditional command line text. As an example of the '.if' conditional command, consider the situation
where you want a certain amount of text to be printed on the same page,
say 5 lines. If fewer than 5 lines are left on the current page, then
a page eject should be executed, otherwise a simple blank line is desired.
The following sequence of commands will accomplish this task: |
| .pl xx | page length. Set page length to xx lines. If xx not specified or not an integer, set to default value equal to the value of the formatter variable {d_page_length}, 66. The value of 'd_page_length' may be changed with the '.se' command. |
| .tm xx | Top Margin. Set top margin to xx lines. If xx not
specified or not an integer, set to default value, 0. The top margin
lines are blank lines output after the physical top of page and before
the page header text is output.
Note: the Top Margin command does not take effect until the current page has been printed and before the next page is started. If the output is currently at the top of a page, e.g., immediately following a ".pa" command, then the page header command takes effect immediately. |
| .bm xx | Bottom Margin. Set bottom margin to xx lines. If
xx not specified or not an integer, set to default value, 0. The bottom
margin lines are blank lines output after the page footer text is output
and before the physical end of page.
Note: the Bottom Margin command does not take effect until the current page has been printed and before the next page is started. If the output is currently at the top of a page, e.g., immediately following a ".pa" command, then the page header command takes effect immediately. |
| .pa xx | Page Eject. If xx specified, eject xx pages. If xx is not an integer, eject to the top of the next page only. |
| .pn | Page Number. Forms are:
|
| .pp | Print Page Command. Forms Are:
if 'T' or t' is specified, then use total page count, i.e., page count starting with first page and incrementing by one for each page. Otherwise use page number as optionally adjusted by '.pn' command |
| .ds | Double Space. Set line spacing to double space |
| .se | Set variable. Forms are:
|
| .ss | single space. Set line spacing to single space |
| .sp xx | space. Skip xx lines. If xx not specified or not an integer, 1 used |
| .sx | split text. Form of command:
.sx |Left field|center|Right field| Left field center Right field The blank space following the 'x' of the command is required. "Left Field" is positioned on the left margin, "Center" is positioned centered on the line and "Right Field" is positioned on the right margin. The first character after the blank character following 'x' is used as the field separater. The above .'sx' command could also be written as: .sx ~Left field~center~Right field~ or .sx xLeft fieldxcenterxRight fieldx The use of non-alphabetic characters makes the field separators stand out more. The value of the internal variable 'stx_chr' is used as the fill character between the three fields. The value of 'stx_chr' is a blank character by default, but may be changed to any other desired value. For example: .se stx_chr = '='; Left field===================center===================Right field |
| .tb xx text | tab "text' is positioned at the xx character position of the current line. If xx is not an integer, 0 is used. |
| Lists | Three kinds of lists are formatted:
Each item of any of the above list types is started with the command, ':li.'. For example the simple list above is: :sl. A list is halted with the commands:
Note: if blank lines are desired between list items, the blank lines must be present in the source document. The formatter does not auotmatically insert blank lines between list items. List items are formatted with second and higher lines of any list item indented four spaces in from the beginning character of the item. The indentation for succeeding lines of any list item is in the variable 'list_indent'. The value of this variable may be changed with the '.se' command: .se list_indent = 6; to change the indentation of all lines after the first for list items. There are several formatter variables used for formatting lists.
NOTE: the variables:
The fourth type of list is the Definition list, started with the ":dl." command. Starting a definition list with the ":dl." command outputs all text read thus far. Each item of the definition list consists of two parts:
The definition list is terminated with the ":edl." command. An example of a definition list is: Which would be formatted as: Leopard |
| .tc xx | Table of Contents. This command reserves xx pages for the table of contents. |
| .pt text | put table of contents command. This command puts 'text' into the Table of contents with the current page number. The current page number style used, arabic, alphabetic or roman. |
| .px | Define Extra Page Number. Forms are:
This command mimics the '.pn' command. The formatting utility updates the extra page numbers at the same time that the normal page number is updated. This allows the user to define, set and track page numbers for special sections within a document. n in the command can be any integer. The page numbers can be accessed and printed in headers and footers using the replacement symbols: &n where n is the extra page number The extra page number value may also be accessed within the document through the formatter variable: page_xtra[n][0] The formatting style (roman, alphabetic or arabic) may be accessed through the formatter variable: page_xtra[n][1] Where a value of: |
| Tables | Tables are supported and formatted using two commands
A table is defined as follows: .td ~ 1 10 20 30 40 50 The table is then started with the '.tl start' command. The following example demonstrates formatting a table. Note that empty table columns must be indicated with the column character followed by blank space. This allows for some columns to have text which overflows into following columns. .td ~ 1 10 20 30 40 50 This table formats as: col 1 col 2 col 3 col 4 col 5 col 6 |
| .us | underscore. Underscore text. This command has four
forms:
|
The following internal variables are maintained for formatting. The values of these variables are available using the variable replacement mechanism, namely enclosing the desired variable name within curly braces, "{}", within the text to be formatted. The '.se on' and '.se off' commands turn this replacement mechanism on/off as desired. Thus, {line_cnt} will be expanded into the current line number on the current page as: "1"
| adjust | specifies maximum number of padding characters to be used in justifying a line between the left and right margins. For example, if a line is composed of 10 words with a total length of 55 characters, there would be a minimum of 9 padding caracters between the 10 words for a total length of 64 characters. If the line length is 70 characters, then an additional 6 padding characters must be added between the words to justify them on the line. If 'adjust' is 5, then the words will not be justified. However, if 'adjust' is 6 or more, then the words will be justified and the additional padding characters added between the words. The default value of 'adjust' is 5. This variable may be set using the '.se' command. |
| break_on_blank_line | Specifies whether or not a blank input line will cause formatting of input to break, i.e., to stop adding words to current output line and output current output line. If variable TRUE, default value, a blank input line will cause formatting to break. A value of FALSE will cause a blank input line to be ignored. |
| line_cnt | current line number being formatted. Do not change the value of this variable. |
| page_length | page length of the printed page. This is the number of printed lines on the physical page. For example, 11 inch long paper, printed 6 line per inch yields a value of 66 for page_length. The value may be changed using the '.pl' command. Defaults to the value of 'd_page_length', which may be set via the '.se' command. |
| paper_output | TRUE/FALSE. TRUE if paper is output, FALSE otherwise.
If not set on the QTAwk command line via the QTAwk '-v'
option:
qtawk -v "paper_output=FALSE' the formatter sets the value to TRUE at initialization. The value may be set at any time in the source text using the command: '.se paper_output=FALSE;" |
| paginate | TRUE/FALSE. This variable determines whether or not
output is split into pages on output. On initialization, it is set
to TRUE if paper_output has a true value, FALSE otherwise. The value
may be changed with the '.se' command. During initialization, The default
values of the top margin, 'd_top_margin', the bottom margin, 'd_bot_margin',
page width, 'd_width', and left margin, 'd_left_m', are set according
to the value of 'paginate':
paginate d_top_margin d_bot_margin d_width d_left_m |
| top_margin | the number of blank lines alloted between the top of the physical page and the first header line or text line if no header is printed. Defaults to 'd_top_margin'. The value of 'd_top_margin' may be set with the '.se' command. |
| bot_margin | the number of blank lines alloted between the last line of the footer if printed or the last text line and the bottom of the physical page. Defaults to 'd_bot_margin'. The value of 'd_bot_margin' may be set with the '.se' command. |
| left_m | the number of character spaces used in the left margin. Default to the value of 'd_left_m', which may be set via the '.se' command. |
| width | the number of character spaces on the physical page. Defaults to 'd_width', which may be set via the '.se' command. |
| header | boolean value. If true, then a page header is printed. Set via the '.hr on/off' command. |
| footer | boolean value. If true, then a page footer is printed. Set via the '.fr on/off' command. |
| sender_tabs | the number of space characters used to align the senders address fields. May be set via the '.se' command. |
| page_num_sym | the character replaced by the current page number in header and footer lines. May be set via the '.se' command. |
| hdr_line_even | the text used for the header line on even numbered pages. The text acts the same as the text for the '.sx' command. Set via the '.hr even text' or '.hr text' commands. Defaults to the value of 'dhdr_line', which may be set via the '.se' command. |
| hdr_line_odd | the text used for the header line on odd numbered pages. The text acts the same as the text for the '.sx' command. Set via the '.hr odd text' or '.hr text' commands. Defaults to the value of 'dhdr_line', which may be set via the '.se' command. |
| ftr_line_even | the text used for the footer line on even numbered pages. The text acts the same as the text for the '.sx' command. Set via the '.fr even text' or '.fr text' commands. Defaults to the value of 'dhdr_line', which may be set via the '.se' command. |
| ftr_line_odd | the text used for the footer line on odd numbered pages. The text acts the same as the text for the '.sx' command. Set via the '.fr odd text' or '.fr text' commands. Defaults to the value of 'dhdr_line', which may be set via the '.se' command. |
| toc_hdr_line_even | the text used for the header line on even numbered Table of Contents pages. The text acts the same as the text for the '.sx' command. Set via the '.se ' command only. Defaults to the value of 'dhdr_line', which may be set via the '.se' command. |
| toc_hdr_line_odd | the text used for the header line on odd numbered Table of Contents pages. The text acts the same as the text for the '.sx' command. Set via the '.se ' command only. Defaults to the value of 'dhdr_line', which may be set via the '.se' command. |
| toc_ftr_line_even | the text used for the footer line on even numbered Table of Contents pages. The text acts the same as the text for the '.sx' command. Set via the '.se ' command only. Defaults to the value of 'dhdr_line', which may be set via the '.se' command. |
| toc_ftr_line_odd | the text used for the footer line on odd numbered Table of Contents pages. The text acts the same as the text for the '.sx' command. Set via the '.se ' command only. Defaults to the value of 'dhdr_line', which may be set via the '.se' command. |
| header_0_text | The text on the line with the last '.h0' command |
| hdr_lines | the number of lines in the header if printed. Defaults to 1. May be set via the '.se' command. |
| hdr_skip | the number of blank lines between the last line of the printed header and the first line of formatted text. May be set via the '.se' command. |
| ftr_lines | the number of lines in the footer if printed. Defaults to 1. May be set via the '.se' command. |
| ftr_skip | the number of blank lines between the last line of formatted text and the first line of the footer if printed. Defaults to 1. May be set via the '.se' command. |
| num_lines | the number of lines of formatted text on the printed
page. The value is computed as:
num_lines = page_length - top_margin - bot_margin If any one of the variables used in computing 'num_lines' is changed, then 'num_lines' is updated. Care should be excercised in changing 'hdr_lines' or 'hdr_skip' in the middle of a page. If the header has already been printed, changing the value of 'hdr_lines' or 'hdr_skip' will dynamically change the number of formatted text lines which may then exceed the physical page. This should probably be fixed at some time. |
| ttl_page_cnt | total page count. This number starts at 1 and is incremented for each page output. This number differs from the variable 'page_num' in that page numbering cannot change this variable. This variable should never be changed by the user with the '.se' command. |
| page_num | the page number of the current page being formatted. This number is the number actually used in replacing the value of 'page_num_sym' in header and footer lines. The value of this variable can be changed with the '.h0', '.pn' and '.tc' commands. |
| page_num_prefix | the text string prefixed to the current page number. After formatting the current value of 'page_num', the string value of this variable is prepended and the resulting string is used to replace the 'page_num_sym' in headers, footers and the Table of Contents pages. |
| left_margin | the number of scpace characters used for the left margin. |
| double_space | True/False value which determines if double line spacing is used for the formatted output. |
| roman_num | true if roman numerals used for page numbers. Set
via the .'pn' command.
Examples: 1999 = mcmxcix |
| alpha_num | true if alphabetic numbers used for page numbering.
Set via the .'pn' command.
Examples: 1999 = bxw |
| var_replace | true if variable replacement is done in input text. Set using the '.se on' or '.se off' commands. |
| sysyear | set to the current year at initialization. numeric value. |
| sysmonth | set to the current month of the year at initialization. Numeric value from 1 to 12. |
| sysdayofm | set to the current day of the month at initialization. Numeric value between 1 and 31. |
| sysdayofw | set to the current day of the week at initialization.
Numeric value between 0 and 6 inclusive.
|
| sysdayofy | set to the current day of the year at initialization.
Numeric value between 0 and 365.
January 1 == 0. |
| Document_date_Format | format string used to format the document date. The value of this variable may be set with the '.se' command. |
| Document_time_Format | format string used to format the document time. The value of this variable may be set with the '.se' command. |
| date | current date on which the document is being formatted. 'Document_date_Format' string used to format the date. |
| time | current time at which the document is started formatting. 'Document_time_Format' string used to format the time. |
| double_blank | True/False value. If true, then two space characters are formatted following words which end with a period, '.'. The value of this variable may be set with the '.se' command. |
| blst_odd | the graphic symbol used as a bullet to odd levels of unordered list items. The value of this variable may be set with the '.se' command. |
| blst_even | the graphic symbol used as a bullet to even levels of unordered list items. The value of this variable may be set with the '.se' command. |
| list_indent | the number of space characters by which lines of list items are indented after the first line of any item. The value of this variable may be set with the '.se' command. |
| reset_headr_0 | True/False value. If true, then 'page_num' is reset to 1 when a '.h0' command is formatted. The value of this variable may be set with the '.se' command. |
| hn_emphasize | true/false value. If true, text formatted with any section header command, '.h[0-9]' is output as emphasized. The value of this variable may be set with the '.se' command. |
| stx_chr | the character value of this variable is used as the padding character for the '.sx' command and the 'split_text' function described below. Initially set to the blank character. The value of this variable may be set with the '.se' command. |
| order_list_num |
The number of the current ordered list item |
| adjust | 5 |
| alpha_num | 0 |
| blst_even |
- |
| blst_odd | > |
| bot_margin | 6 |
| dftr_line | ||- # -|| |
| dhdr_line | ||- # -|| |
| Document_date_Format | %A, %B %d, %Y |
| Document_time_Format | %I:%M %p |
| double_space | 0 |
| d_bot_margin | 6 |
| d_left_m | 8 |
| d_page_length | 66 |
| d_top_margin | 6 |
| d_width | 65 |
| footer | 1 |
| ftr_lines | 1 |
| ftr_line_even | ||- # -|| |
| ftr_line_odd | ||- # -|| |
| ftr_skip | 2 |
| hdr_lines | 1 |
| hdr_line_even | ||- # -|| |
| hdr_line_odd | ||- # -|| |
| hdr_skip | 2 |
| header | 0 |
| hn_emphasize | 1 |
| left_m | 8 |
| left_margin | "" |
| list_indent | 4 |
| num_lines | 63 |
| order_list_num | 0 |
| page_length | 66 |
| page_num | 0 |
| page_num_prefix | "" |
| page_num_sym | # |
| paginate | 1 |
| paper_output | 1 |
| reset_headr_0 | 0 |
| roman_num | 0 |
| sender_tabs | 35 |
| stx_chr | " " |
| toc_ftr_line_even | ||- # -|| |
| toc_ftr_line_odd | ||- # -|| |
| toc_hdr_line_even | |||Table of Contents| |
| toc_hdr_line_odd | |Table of Contents||| |
| top_margin | 6 |
| var_replace | 1 |
| width | 65 |
The following functions have been defined in the formatter utility and may be used in '.se' commands in the document to be formatted.
| roman_numeral(num) | function returns integer value of 'num' as a
roman numeral string. For example, the '.se' command
.se yr = roman_numeral(1999); will yield the string "mcmxcix" for the value of 'yr'. |
| d_to_alpha(num) |
function returns integer value of 'num' as an alphabetic string. For example, the '.se' command .se yr = d_to_alpha(1999); will yield the string "bxw" for the value of 'yr'. |
| split_text(text,line_width,fill_chr) |
returns a string formed from the string value of 'text'. 'text'
is composed of three parts, the first character of 'text' is used
as the separator character for the three parts. The first part is justified
to the leftmost position on a line 'line_width' characters wide.
The second part is centered on the line and the third part is aligned to
the rightmost position of the line. The character positions between
the three parts are filled with the first character of the 'fill_chr'
parameter. This function is used to format the text of the '.sx' command
and all page headers and footers with 'fill_chr' equal to the 'stx_chr'
formatter variable. The commands: Will yield the following value for the variables 'splt' and 'ruler':
|
| set_pnum(pnum) |
returns a string with the current page number formatted according to the setting of 'roman_num' and 'alpha_num'. The value of the 'page_num_prefix' variable has been prepended to the formatted number in the returned string. |
| name_defined(name) |
returns a TRUE or FALSE value depending on whether a formatter internal variable has been defined with a name equal to the string value of 'name'. |
| addcomma(x,nfmt) |
returns a string with the numeric value of x formatted using the QTAwk 'sprintf' internal function using the string value of 'nfmt' as the formatting string. If 'nfmt' has a false value, i.e., is the null string or a zero numeric value, then the formatting string "%.16g" is used. The integer portion of the numeric value is then broken into units of three digits separated by the grouping symbol, e.g., ','. For example, the following commands will produce the strings shown: .se val1 = addcomma(12345678.8765,""); .se val2 = addcomma(12345678.8765,"%i"); |
| fmt_eng(n,r) |
returns a numeric formatted in engineering notation, 'r' specifies the maximum digits following the decimal point. 'n' is formatted as: abs(n) > 1 ==> [DD]D.DDDeN where first two digits are not both
zero and N is a multiple of 3. For example, the following commands will produce the string shown: .se val3 = fmt_eng(12345678.8765,9); .se val4 = fmt_eng(12345678.8765,5); |