LINE - addresses in FRED.

The lines in every buffer are numbered sequentially beginning at 1. Every time a line is added or deleted, the line numbers in the buffer are adjusted to preserve sequential numbering.

FRED commands may require zero, one, or two line addresses. The simplest form of line address is the ordinary line number. For example, 5 refers to line number 5 (the fifth line in the buffer). There are also more complicated ways of specifying a line address, using patterns or special characters. A list of acceptable line address forms is given below. In all our descriptions, N stands for an unsigned integer number.

N
This is an ordinary line number referring to the Nth line of the buffer.
$
This special character refers to the last line of a buffer.
.
This refers to the current line of a buffer.
+N
When this form appears on its own or as the first address in a pair of addresses, it is shorthand for .+N. Thus, +10 stands for .+10. When this form appears as the second address in a pair of addresses, the given number is added to the first address. Thus 4,+10 is the same as 4,14.

If N is omitted, + stands for .+1.

-N
When this form appears on its own or as the first address in a pair of addresses, it is shorthand for .-N. Thus, -10 stands for .-10. When this form appears as the second address in a pair of addresses, the given number is subtracted from the first address. Thus 10,-2 is the same as 10,8 (which would result in an error with most commands due to address wraparound).

If N is omitted, - stands for .-1.

^
This is shorthand for .-1 (i.e. the line before the current one).
*
This is shorthand for 1,$. Thus * means every line from the beginning to the end of the buffer.
&
This generates the pair of addresses .+1,.+PAGESIZE. PAGESIZE is set by the O+P option. If PAGESIZE has not been specified, & will generate .+1,.+20.
/pattern/
This serves as the address of the next line after "." containing a string that matches the given pattern. The search for the pattern will begin at .+1 and will continue to the end of the buffer. If no match has been found by that time, the search will wrap around to the beginning of the buffer and continue looking for the pattern from line 1. The search will continue until the pattern is found or FRED gets back to ".". If no match is found in the entire buffer, an error is issued.
~/pattern/
This serves as the address of the first line after "." that does not contain a string matching the given pattern. The search for such a line proceeds in the same way as the search for /pattern/. (Although line 0 is technically a line which does not match any pattern, ~/pattern/ will not address line 0. This is true of all line address forms using the ~ character.)
-/pattern/
This serves as the address of the first line before "." containing a string that matches the given pattern. The search for this pattern begins at .-1 and goes backwards through the buffer, wrapping around from the first line to the last if necessary. The search will continue until the pattern is found or FRED gets back to ".". If no match is found in the entire buffer, an error is issued.
?pattern?
This is the same as -/pattern/.
-~/pattern/
This serves as the address of the first line before "." that does not contain a string matching the pattern. The search for such a line proceeds in the same way as the search for a line matching the pattern.
addr
We will use this symbol to refer to any of the valid line address forms above as well as addresses that can be formed using the rules below.
addr+N
This is the address of the Nth line after addr. For example, the line after addr is addr+1.
addrN
An address followed by a number N is the same as addr+N. For example, .5 is the same as .+5.
addr.
Putting a dot after an address is the same as addr+1. Thus .. refers to line .+1.
addr-N
This refers to the Nth line before addr. Thus the line immediately before addr is addr-1.
addr+/pattern/
This refers to the first line following addr containing a string that matches the pattern. The search for the pattern begins at addr+1, wraps around to the beginning of the buffer if necessary, and continues back to addr. An error is issued if the pattern is not found.
addr/pattern/
This is the same as addr+/pattern/.
addr~/pattern/
This refers to the first line following addr that does not contain a string matching the pattern. The search for such a line proceeds in the same way as a search for a line containing the pattern.
addr-/pattern/
This is the first line before addr that contains a string matching the pattern. The search for the pattern begins at addr-1 and continues backwards through the buffer, wrapping around from the top of the buffer to the bottom if necessary and continuing back to addr. An error is issued if the pattern is not found.
addr?pattern?
This is the same as addr-/pattern/.
addr-~/pattern/
This refers to the first line before addr that does not contain a string matching the pattern. The search for such a line proceeds in the same way as the search for a line containing the pattern.
addr^
This refers to addr-1. Thus ^^ is ^-1 or .-1-1, i.e. .-2.
addr*
This is shorthand for addr,$.
addr&
This generates the pair of addresses addr,addr+PAGESIZE.
addr-&
This represents the single address addr-PAGESIZE.

Note that ordinary line addresses can only appear as the first term in a complicated address as in 45-&+2. When FRED calculates one of the line addresses above, it does not automatically set "." to that address. Instead, it sets an internal pointer which points to the addressed line, and "." stays unchanged. Thus

/string/,./string/
/string/,/string/

are not the same. The effect of the first address in each above pair is to search for the first line after "." that contains string. Since "." remains unchanged, ./string/ in the first pair returns to "." and looks for string again. Thus

/string/,./string/

refers to the same line twice.

/string/,/string/

on the other hand searches for string, then searches for a second string. Thus it is likely to address two different lines.

As another example,

/str/,+1

refers to the next line containing str and the line immediately after that line.

/str/,.+1

refers to the next line containing str, and the line immediately after the current value of ".".

A buffer can be thought of as a circle of text. Line 0 is where the circle joins: it is the line before line 1 and the line after the last line.

For most FRED commands, line 0 is an illegal address. However, it is still possible to pass circularly through line 0 using the special characters . and ^. For example, $. refers to the line after the last line in the file (i.e. line 0) and $.. refers to the line after that (line 1). Thus while $. usually will produce an error, $.. will not. Similarly, 1^^ is the same as $.

The + and - addresses are special in that they may be strung together. For example, +++ is equivalent to .+3. As another example, -+- is equivalent to .-1 since the first -+ cancel each other out.

When you specify an address with +N or -N, FRED does the addition or subtraction and sees if the appropriate line number exists. If not, you will receive an error. This means that the following addresses are not equivalent.

$+1
$.

To get the first address, FRED adds 1 to the final line number, discovers that this line does not exist, and gives an error. If you specify the second address, FRED gives you the line that follows the final line (line 0). Similarly, if you specify -N, you could end up with a negative address and get an error; but if you use ^ to go backwards in the buffer, you will wrap around through line 0 from the top of the buffer to the bottom.

As stated previously, some commands can take two addresses, some only take one, and some take no addresses. If you specify more addresses than a particular command can take, as in 1,3,4p, FRED will issue an error message. Other errors in this vein include ** (which is expanded to 1,$,$) and &* (which is expanded to .+1,.+PAGESIZE,$). The form && is valid and stands for

.+PAGESIZE,.+PAGESIZE+PAGESIZE

All commands which accept addresses have defaults to be used when addresses are not supplied. Usually the default address is ".", though this is not true for every command. The default addresses for each command are given in the individual command descriptions later in this manual. A summary of these defaults appears in "expl fred commands".

Copyright © 1998, Thinkage Ltd.