Utilities Manual
Utilities Manual
Utilities Manual
03-3196-01
April 1982
1 Z110g . 1
· .
! ~. '• . '-
El-0152-0l, Errata, ZEUS Operating System, Version 1.7
'. ~
main ()
{
}
gl234567x • 11
the two global variables are mapped into one
location named _g123456. ~he C compiler trun-
cates names after the first eight characters.
The only way around this problem now is not to
have external names that are identical in the
first seven characters.
Warning: This equipment generates, uses, and can radiate radio frequency energy and if not
installed and used in accordance with the instructions manual, may cause interference to
radio communications. As temporarily permitted by regulation it has not been tested for com-
pliance with the limits for Class A computing devices pursuant to Subpart J of Part 15 of FCC
Rules, which are designed to provide reasonable protection against such interference. Opera-
tion of this equipment in a residential area is likely to cause interference in which case the
user at his own expense will be required to take whatever measures may be required to cor-
rect the interference.
(
ZEUS UTILITIES
03-3196-01
PRELIMINARY VERSION
PREFACE
ii Zilog ii
ZEUS Utilities Zilog ZEUS Utlities
TABLE OF CONTENTS
f
iii Zilog iii
ZEUS Utilities Zilcg ZEUS Otlities
/
;
iv Zilog iv
INTRODUCTION Zilog INTRODUCTION
1 Zilog 1
INTRODUCTION Zilog INTRODUCTION
2 Zilog 2
ADB Zilog ADB
1 Zilog 1
ADB Zilog ADB
PREFACE
(
2 Zilog 2
ADB Zilog ADB
TABLE OF CONTENTS
3 Zilog 3
ADB Zilog ADB
SECTION 1
A QUICK SURVEY
4 Zilog 4
Zilog ADB
0126?i
sets dot to octal 126 and prints the instruction at that
address.
When used with the ? or / requests, the current address can
be advanced by typing a new line, and it can be decremented
by typing A.
1.4 Formats
To print data, specify a collection of letters and charac-
ters that describe the format of the printout. Typing a
request without a format causes the new printout to appear
in the previous format. The following are the most commonly
used format letter~:
b one byte in octal
c one byte as a character
o one word in octal
d one word in decimal
f two words in floating point
i Z8000 instruction
s a null terminated character string
a the value of dot
u one word as unsigned integer
n print a new line
r
A
print a blank space
backup dot
Format letters are also available for long values (for exam-
ple, D for long decimal and F for double floating pOint).
5 Zilog 5
~B Zilog ADB
6 Zilog 6
ADB Zilog ADB
SECTION 2
DEBUGGING C PROGRAMS
7 Zilog 7
ADB Zilog ADB
The request
$m
8 Zilog 8
ADB Zilog ADB
The request
,5$C
prints the five most recently called procedures.
Each function (~,g,h) has a counter of the number of times
it was called. The request
fcnt/d
prints the decimal value of the counter for the function L.
To print the the decimal value of X in the last call of the
function b, type
h.x/d
It is not currently possible to print the value of local
variables.
9 Zilog 9
~B Zilog ADB
10 Zilog 10
ADB Zilog ADB
11 Zilog 11
ADS Zilog ADS
settab:b settab,5?ia *
* Owing to a bug in early versions of ADS (including the
version distributed in Generic 3 ZEUS), these statements
must be written as:
settab:b settab,5?ia10
read,3:b main.c?C10
settab:b settab,5?ia10
The 10 sets dot to zero and stop at the breakpoint. To
request each occurrence of the breakpoint and stop after the
third occurrence, type:
read,3:b tabs/ax
This request prints the local variable & in the function
main at each occurrence of the breakpoint. The semicolon
separates multiple ADS requests on a single line.
NOTE
Setting a breakpoint causes the value of dot to be
changed. Executing the program under ADS does not
change dot. For example, the commands
settab:b .,5?ia
open:b
print the last value dot was set to (example ~)
n2t the current location (example settab) at
which the program is executing.
12 Zilog 12
ADB Zilog ADB
13 Zilog 13
ADS Zilog ADB
14 Zilog 14
ADB Zilog ADB
"
".
SECTION 3
MAPS
15 Zilog 15
-.
initialized by ADB:
b base address of data segment
d length of the data segment
s length of the stack
t length of the text
m execution type (E707 and E7ll)
In Example 9 those variables not present are zero. These
variables can be used by expressions such as
<b
in the address field. Similarly, the value of the variable
can be changed by an assignment request such a
02000>b
which sets b to octal 2000. These variables are useful to
know if the file under examination is an executable or core
image file.
ADS reads the header of the core image file to find the
values for these variables. If the second file specified is
not a core file, or if it is missing, the header of the exe-
cutable file is used.
16 Zilog 16
~B Zilog ADB
SECTION 4
~VANCED USAGE
4.1 General
It is possible with ADB to combine formatting requests to
provide elaborate displays. Several examples follow.
17 Zi10g 17
ADB . Zilog ADB
18 Zilog 18
ADB Zilog ADB
19 Zilog 19
ADB Zilog ADB
20 Zilog 20
ADB Zilog ADB
SECTION 5
PATCHING
21 Zilog 21
ADB . Zilog
22 Zilog 22
ADB Zilog ADB
SECTION 6
CAUTIONS
23 Zilog 23
ADB Zilog ADB
APPENDIX A
PROGRAM EXAMPLES
1
2 char *charp = "this is a sentence";
3
4 maine argc, argv
5 int argc;
6 char **argv;
7 {
8 int fd;
9 char cc;
10 if (argc < 2
11 {
12 printf("Input file missing\n");
13 exit(8);
14 }
15
16 if ( (fd = open(argv[l],O)}== -I}
17 {
18 printf("%s : nor found\n", argv[l]);
19 exit (8);
20 }
21 charp = "hello";
22 printf("debug 1 %s\n", charp };
23 while( charp++ )
24 write (fd, *charp, 1);
25 {
***1* **
Example 1
24 Zilog 24
ADB Zilog ADB
25 Zilog 25
ADB Zilog ADB
46 _end+%8c:
47 data address not found
48 ? charp/s
49 _charp:
50 ? main.argc/d
51 Sorry, local variable names not implemented
52 ? $q
***1* **
Example 2
!.i.
(
26 Zilog 26
ADB Zilog ADB.
Example 3
27 Zilog 27
ADB Zilog ADB
1 adb
2
3 ADB: S8000 1.1
4 ? $c
5 Stack backtracing not implemented
6 ? , 5 $C
7 Stack backtracing not implemented
8 ? fcnt/d
9 _fcnt: 2156
10 ? gcnt/d
11 _gent: 2156
12 ? bcnt/d
13 _bcnt: 2157
14 ? b. x/d
15 Sorry, local variable names not implemented
16 ? $q
***1* **
Example 4
28 Zilog 28
ADS Zi10g ADS
1 #define MAXLINE 80
2 #define YES 1
3 #define NO 0
4 #define TASSP 8
5
6 char input[] = "data";
7 int tabs[ MAXLINE ];
8
9 main ()
10 {
11 int fd;
12 int col, *ptab;
13 char c;
14
15 ptab = tabs;
16 settab(ptab);
17 col = 1;
18 if «fd = open(input, 0 » == -1 )
19 {
20 printf("%s : not found\n", input );
21 exit( 8 );
22 }
23
24 whi1e(read(fd, &c, 1) > 0 )
25 {
26 switch(c)
27 {
28 case I\t l :
29 whi1e(tabpos(co1) 1= YES)
30 {
31 putchar ( II );
32 co1++;
33 }
34 break;
35
36 case I \n I :
37 putchar (I\n I) ;
38 col = 1
39 break;
40
41 default:
42 putchar (c) ;
43 break;
44 }
45 }
46 }
47
48 tabpos(co1)
49 int col;
50 {
51 if (col > MAXLINE
52 return(YES);
29 Zi10g 29
ADB Zilog ADB
53 else
54 return(NO)i
55 }
56
57 settab(tabp)
58 int *tabpi
59 {
60 int ii
61
62 for ( i=Oi i <=MAXLINEi i++ )
63 (i % TABSP ) ? (tabs[i] = NO (tabs[i] = YES) i
64 }
***1* **
Example 5
~..
30 Zi10g 30
ADB Zi10g AOB
1 adb a.out -
2
3 ADB: 58000 1.1
4 ? settab:b
5 ? open:b
6 ? read:b
7 ? tabpos:b
8 ? $b
9 breakpoints
10 count bkpt command
11 1 _tabpos
12 1 _read
13 1 _open
14 1 _settab
15 ? settab, 5ia
16 _settab: jr _settab%48
17 _settab+%2: c1r %0002(sp)
18 _settab+%6: cp %0002(sp),#%0050
19 _settab+%c: jr gt,_settab+%44
20 _settab+%e: 1d r3,%0002(sp)
21 _settab+%12:
22 ? settab,5?i
23 _settab: jr _settab+%48
24 c1r %0002(sp)
25 cp %0002{sp),#%0050
26 jr gt,_settab+%44
27 1d r3,%0002(sp)
28 ? :r
29 figS: running
30 breakpoint _settab: jr _settab+%48
31 ? settab:d
32 ? :c
33 figS: running
34 breakpoint _open: 1d rO, r7
35 ? $C
36 Stack backtracing not implemented
37 ? tabs/8x
38 _tabs: %0001 %0000 %0000 %0000 %0000 %0000 %0000 %0000
39 %0001 %0000 %0000 %0000 %0000 %0000 %0000 %0000
40 %0001 %0000 %0000 %0000 %0000 %0000 %0000 %0000
41 ? :c
42 figS: running
43 breakpoint _read: 1d rO, r7
44 ? :c
45 figS: running
46 breakpoint _read: 1d rO, r7
47 ? tabpos:d
48 ? settab:b settab,5?ia
49 ? settab,5:b settab,5?ia; 0
50 ? read,3:b tabs/8x
51 ? $b
52 breakpoints
31 Zi10g 31
ADB Zilog ADB
Example 6
32 Zi10g 32
ADB Zilog ADB
1 adb ex3 -
2
3 ADB: S8000 1.1
4 ? h:b hcnt/d; h.hi/; h.hr/
5 ? g:b gcnt/d; g.gi/; f.fr/
7 ?: r
8 ex3: running
9 _fcnt: 0
10 Sorry, local variable names not implemented
11 ? f:b fcnt/d; f.a/"a = lid; f.h/"b = lid; f.fi/"fi = lid
12 ? g:b gnt/d; g.p/" p = lid; g.q/"q = lid; g.gi/"gi = lid
13 ? h:b hcnt/d; h.x/"x = lid; h.y/" y = lid; h.hi/"hi = lid
14 ?: r
15 ex3: running 0
17 Sorry, local variable names not implemented
18 ? $q
***1* **
Example 7
"' .. '
33 Zilog 33
ADB Zilog ADB
E707 files
Example 8
34 Zilog 34
ADB Zi10g ADB
Example 9
35 Zi10g 35
ADB Zilog ADB
Example 10
.4'
36 Zilog 36
ADB Zilog ADB
37 Zilog 37
ADB Zilog ADB
Example 11
38 Zilog 38
ADB Zilog ADB
1 adb dir -
2
3 ADB: 58000 1.1
4 ? =ntnlnodentnName n
5 ? 0,-1?ut14cn
6 Inode Name
7 %0000: 2
8 2
9 102 bin
10 101 usr
11 157 lib
12 164 dev
13 148 etc
14 197 pb.image
15 957 tmp
16 261 zeus3_1.2·
17 ? $q
18
19
20
21 adb /dev/src -
22
23 ADB: 58000 1.1
24 ??m 0 %1000000 1024
25 ? 0,-1?nf1ags"8tonn1inks,uid,gidn8t3dnnsizen8tDnn \
addr"8t20unBtimes"8t2Y2na
26 %0000: flags 100000
27 links, uid, gid 0 0 0
28 size 0
29 addr 0 0 0 0 0 0 0
30 0 0 0 0 0 0 0 0
31 0 0 0 0 0
32 times 1981 Feb 12 13:50:17 1981 Feb 12 13:50:17
33
34 1981 Feb 12 13:50:17
35
36 %0040: flags 040755
37 1inks,uid,gid 44 0 0
38 size 704
39 addr 3 9984 810 0 0 0 0
40 0 0 0 0 0 0 0
41 0 0 0 0 0
42 times 1981 Ju1 17 16:58:42 1981 Ju1 15 10:10:41
43
44 1981 Ju1 15 10:10:41
45
46 %0080: flags 100664
47 1inks,uid,gid 1 25 0
48 size 34
49 addr 52 12288 0 0 0 0 .. f\
50 0 0 0 0 0 0 0
51 0 0 0 0 0
39 Zi10g 39
ADS Zi10g ADS
Example 12
40 Zi10g 40
ADB Zilog ADB
APPENDIX B
ADB SUMMMARY
Command Summary.
$ Formatted Printing
? f~H:mat print from .a •.Q.U.t file according to ~
mat
/ format print from ~ file according to format
41 Zilog 41
ADB Zilog ADB
e Assignment to Variables
>nam.e assign dot to variable or register name
Format Summary
a the value of dot
b one byte in octal
c one byte as a character
d one word in decimal
f two words in floating point
i Z8000 instruction
0 one word in octal
n print a newline
r print a blank space
s a null terminated character string
nt move to next n space tab
u one word as unsigned integer
x hexadecimal
y date
,..
backup dot
" ... " print string
Expression Summary
e Expression Components
decimal integer for example 256
octal integer for example 0277
hexadecimal for example %ff
symbols for example flag _main main.argc
variables for example <b
registers for example <pc <rO
(expression) for example expression grouping
$ Dyadic Operators
+ add
subtract
* multiply
% integer division
& bitwise and
I bitwise or
# round up to the next multiple
$ Monadic Operators
not
* contents of location
integer negate
42 Zilog 42
AS Zilog AS
\'
USER GUIDE
1 Zilog 1
AS Zilog AS
PREFACE
2 Zilog 2
r
(
AS Zi10g AS
TABLE OF CONTENTS
3 Zilog 3
AS Zilog AS
SECTION 1
INTRODUCTION
1.2 Relocatability
Relocation refers to the ability to bind a program module
and its data to a particular memory area after the assembly
process. The output of the assembler is an object module
that contains enough information to allow a loader or linker
to assign a memory area to that module. Refer to the
description of the ZEUS linker/loader in ld(l) of the Z£US
Reference Manual.
4 Zilog 4
AS Zilog AS
SECTION 2
INPUT/OUTPUT
I,",
'~
5 Zilog 5
/
(
AS Zilog AS
SECTION 3
ASSEMBLER COMMAND LINE
3.2 Options
The following options are valid and can appear in any order,
separated by delimiters such as a blank or tab.
-d string in combination with the -1 option, specifies
a date (up to 19 characters) to be put in the
listing header.
-f allows assembly of floating point Extended
Processor Unit (EPU) instructions.
-i requests that the intermediate file the
assembler uses be saved. The file name for
the intermediate file is the input file name
with the .i extension.
-1 requests a listing file. The file name for
the listing file is the input file name with
the .1 extension. No listing is produced if
this option is not used.
-0 filename allows the user to name the output file. If
this option is not used, the default file
name is a.out or t.out (Section 7) •
-p prints the listing file to the user console
as it is being produced. Only source lines
containing errors are printed to the console
if this option is not specified.
-r requests that the relocation information file
be saved. The relocation file name is the
input file name with the .r extension.
6 Zilog 6
AS Zilog AS
7 Zilog 7
AS Zilog AS
SECTION 4
LISTING FORMAT
8 Zilog 8
AS Zilog AS
Zilog 9
AS Zilog AS
SECTION 5
MINIMAL PROGRAM REQUIREMENTS
EXAMPLE #1:
anyname MODULE
GLOBAL ! or INTERNAL depending on whether !
! intermodule linking is desired. !
somename PROCEDURE
ENTRY
! The program goes here
RET
END somename
END anyname
10 Zilog 10
AS Zilog AS
EXAMPLE #2:
anyname MODULE
CONSTANT ! Symbolic constants are declared here. !
one := 1
hexten := %10
11 Zilog 11
AS Zilog AS
SECTION 6
IMPLEMENTATION FEATURES AND LIMITATIONS
12 Zilog 12
,. ,
..
AS Zilog AS
SECTION 7
OBJECT CODE
13 Zilog 13
AS Zilog AS
14 Zilog 14
AS Zilog AS
CONTROL TAGS:
HEX
00 NOP Null operation
01 SEGMODULE Segmented module definition
02 NONSEGMODULE Nonsegmented module definition
03 ENDMODULE End module
04 SECTION Section definition
OS GLOB Global symbol definition
06 ABSGLOB Global symbol definition with
absolute offset
07 EXTERN External symbol definition
08 ENTRYPT Entry pOint with relocatable offset
09 ABSENTRYPT Entry point with absolute offset
OA DEBUG SYMBOL Debug symbol
OB DEBUG INFO Debug information
OC MESSAGE Variable length message
OD SETDATA Set current data section
OE SETPROG Set current program section
OF BEG SEC Begin section
10 LOCNT Relocatable program counter
11 ABSLOCNT Absolute program counter
12 MODULEDEF Module definition for z-code
13 MODULEREF Module reference used for z-code
machines
:(
IS Zilog IS
AS Zilog AS
ENTRY TAGS:
HEX
20 LDBYTE Load byte value
21 LDWORD Load word value
22 LDLONG Load long value
23 EXREF External reference
24 SECREF Section reference
25 SECADDR Section address
26 ZREF Z-code module reference
MODIFIER TAGS:
HEX
40 REP Repeat
41 SEQUENCE Sequence
42 REL Relocatable
43 RELDATA Relocatable with respect to current
data area
44 RELPROG Relocatable with respect to current
program area
45 DISP Displacement
46 *LOBYTE Low order byte of
47 *HIBYTE High order byte of
48 **SHORT Short segment address
49 **OFFSET Offset of
4A **SEGMENT Segment of
* Z8/Z-UPC
** Z8000
16 Zi10g 16
AS Zilog AS
SECTION 8
PLZ/ASM ERROR MESSAGES
ERROR EXPLANATION
WARNINGS
1 Missing delimiter between tokens
2 Array of zero elements
3 No fields in record declaration
4 Mismatched procedure names
5 Mismatched module names
8 Absolute address warning for System 8000
TOKEN ERRORS
10 Decimal number too large
11 Invalid operator
12 Invalid special character after %
13 Invalid hexadecimal digit
14 Character_sequence of zero length
15 Invalid character
16 Hexadecimal number too large
. DO LOOP ERRORS
20 Unmatched OD
21 OD expected
22 Invalid repeat statement
23 Invalid exit statement
24 Invalid FROM label
IF STATEMENT ERRORS
30 Unmatched FI
31 FI expected
32 THEN or CASE expected
33 Invalid selector record
SYMBOLS EXPECTED
40 ) expected
41 ( expected
42 1 expected
43 [ expected
44 := expected
18 Zilog 18
AS Zilog AS
ERROR EXPLANATION
INVALID VARIABLES
100 Invalid variable
101 Invalid operand for # or SIZEOF
102 Invalid field name
103 Subscripting of nonarray variable
104 Invalid use of period (.)
EXPRESSION ERRORS
110 Invalid arithmetic expression
III Invalid conditional expression
112 Invalid constant expression
113 Invalid select expression
114 Invalid index expression
115 Invalid expression in assignment
TYPE INCOMPATIBILITY
140 Character_sequence initializer used
with array [*] declaration where
component's base type is not 8 bits
141 TYPE incompatibility with initilization
SEGMENTATION ERRORS
170 Invalid operator in nonsegmented mode
171 Mismatched short address operator
172 Mismatched segment deSignator
DIRECTIVE ERRORS
180 Inconsistent area specifier
181 Invalid area specifier
182 Mismatched conditional assembly directives
183 Invalid conditional assembly expression
184 Attempt to mix segmented and nonsegmented code
185 Directive must appear alone on a single line
186 Invalid $CODE or $DATA directive
19 Zilog 19
AS Zilog AS
1r
ERROR EXPLANATION
FILE ERRORS
198 EOF expected
199 Unexpected EOF encountered in source--possible
unmatched 1 or I in source
IMPLEMENTATION RESTRICTIONS
224 Too many symbols--hash table full
226 Short segmented offset out of range
227 Object symbol table overflow
228 Relocation out of range (word overflow)
229 Unimplemented feature
230 Character_sequence of identifier too long
231 Too many symbols--symbol table full
234 Too many initialization values
235 Stack overflow
236 Operand too complicated
NOTE
Errors larger than 240 can occur. If there are no
other errors in the program preceding one of these
errors, this indicates an assembler bug that
should be reported to Zilog along with any per-
tinent information concerning its occurence.
20 Zilog 20
Zilog
1 Zilog 1
AWK Zilog AWK
TABLE OF CONTENTS
SECTION 1 INTRODUCT ION •••••••••••••••••••••••••••• 3
1.1 Usage ••••••••••••••••••••••••••••••• 3
1.2 Program Structure ••••••••••••••••••• 4
1.3 Records and Fields •••••••••••••••••• 4
SECTION 2 PATTERNS •••••••••••••••••••••••••••••••• 7
2 Zilog 2
Zilog AWK
SECTION 1
INTRODUCTION
~ is a programming language designed to make many common
information retrieval and text manipulation tasks easy to
state and to perform.
The basic operation of ~ is to scan a set of input lines
in order, searching for lines which match any of a set of
patterns which the user has specified. For each pattern, an
action can be specified; this action will be performed on
each line that matches the pattern.
Readers familiar with the ZEUS program ~ (see ZEUS Refer-
ence Manual, SectiQn 1) will recognize the approac~,
although in ~ the patterns may be more general than 1n
~, and the actions allowed are more involved than merely
printing the matching line. For example, the ~ program
{print $3, $2}
prints the third and second columns of a table in that
order. The program
$2 - /AIBIC/
3 Zilog 3
AWK Zilog AWK
4 Zilog 4
AWK Zilog AWK
file.
1.4. Printing
An action may have no pattern, in which case the action is
executed for all lines. The simplest action is to print
some or all of a record; this is accomplished by the ~
command print. The ~ program
{ print }
writes the first field, $1, on the file fool, and the second
field on file fo02. The» notation can also be used:
print $1 »"foo"
appends the output to the file foo. (In each case, the out-
put files are created if necessary.) The file name can be a
variable or a field as well as a constant; for example,
print $1 >$2
5 Zilog 5
AWK Zilog AWK
6 Zilog 6
Zilog AWK
SECTION 2
PATTERNS
A pattern in front of an action acts as a selector that
determines whether the action is to be executed. A variety
of expressions may be used as patterns: regular expressions,
arithmetic .relational expressions, string-valued expres-
sions, and arbitrary boolean combinations of these.
2.1. BEGIN and END
The special pattern BEGIN matches the beginning of the
input, before the first record is read. The pattern END
matches the end of the input, after the last record has been
processed. BEGIN and END thus provide a way t~ gain control
before and after processing, for initialization and wrapup.
As an example, the field separator can be set to a colon by
BEGIN { FS = ":" }
~ Qf program . ..
Or the input lines may be counted by
END {print NR }
7 Zilog 7
AWK Zilog AWK
will print all lines which contain any of the names "Aho, I I
"Weinberger" or "Kernighan," whether capitalized or not.
Regular expressions (with the extensions listed above) must
be enclosed in slashes, just as in ~ and~. Within a
regular expression, blanks and the regular expression meta-
characters are significant. To turn of the magic meaning of
one of the regular expression characters, precede it with a
backslash. An example is the pattern
/\/. *v/
which matches any string of characters enclosed in slashes.
One can also specify that any field or variable matches a
regular expression (or does not match it) with the operators
- and !-. The program
$1 - /[jJ]ohn/
8 Zilog 8
Zilog
NF % 2 -- 0
selects lines where the first field begins with "~Sf " but
is not "smith" && and I I guarantee that their operands
will be e~aluated from left to right1 evaluation stops as
soon as the truth or falsehood is determined.
2.5. Pattern Ranges
The "pattern" that selects an action may also consist of
two patterns separated by a comma, as in
patl, pat2 { ... }
9 Zilog 9
AWK Zilog AWK
does the action for lines 100 through 200 of the input.
10 Zilog 10
Zilog AWK
SECTION 3
ACTIONS
An ~ action is a sequence of action statements terminated
by newlines or semicolons. These action statements can be
used to do a variety of bookkeeping and string manipulating
tasks.
3.1. Built-in Functions
~ provides a "length" function to compute the length of
a string of characters. This program prints each record,
preceded by its length:
{print length, SO}
11 Zilog 11
Zilog
12 Zilog 12
AWK Zilog AWK
{ $1 = NR; print }
13 Zilog 13
AWK Zilog AWK
/
\
'.
returns'the length of the first three fields. Or in a print
statement,
n
pri,nt $1 is " $2
assigns the cur rent' input record to the NR-.tb element of the
array x. In fact, it is possible in principle (though
perhaps slow) to process the entire input in a random order
with the ~ program
{ x[NR] = $0 }
The first action merely records each input line in the array
x.
Array elements may be named by non-numeric values, which
gives ~ a capability rather like the associative memory of
Snobol tables. Suppose the input contains fields with
values like apple, orange, etc. Then the program
/apple/ {x ["apple"] ++ }
/orange/ {x["orange"]++}
END { print x["apple"], x["orange"] }
14 Zilog 14
AWK Zilog AWK
is optional.
The while statement is exactly like that of C. For example,
to print all input fields one per line,
i =1
while (i <= NF) {
print $i
++i
}
15 Zilog 15
AWK Zilog AWK
16 Zilog 16
AWK Zilog AWK
SECTION 4
DESIGN
The ZEUS system already provides several programs that
operate by passing input through a selection mechanism.
~, the first and simplest, merely prints all lines which
match a single specified pattern. Egrep provides more gen-
eral patterns, i.e., regular expressions in full generality;
fgrep searches for a set of keywords with a particularly
fast algorithm. ~ provides most of the editing facilities
of the editor ~, applied to a stream of input. None of
these programs provides numeric capabilities, logical rela-
tions, or variables.
~ provides general regular expression recognition capabil-
ities, and, by serving as a C program generator, is essen-
tially open-ended in its capabilities. The use of ~, how-
ever, requires a knowledge of C programming, and a ~ pro-
gram must be compiled and loaded before use, which
discourages its use for one-shot applications.
Alik is an attempt to fill in another part of the matrix of
possibilities. It provides general regular expression capa-
bilities and an implicit input/output loop. But it also
provides convenient numeric processing, variables, more gen-
eral selection, and control flow in the actions. It does
not require compilation or a knowledge of C. Finally, ~
provides a convenient way to access fields within lines; it
is unique in this respect.
~ also tries to integrate strings and numbers completely,
by treating all quantities as both string and numeric,
deciding which representation is appropriate as late as pos-
sible. In most cases the user can simply ignore the differ-
ences.
Most of the effort in developing ~ went into deciding what
~ should or should not do (for instance, it doesn't do
string substitution) and what the syntax should be (no
explicit operator for concatenation) rather than on writing
or debugging the code. The syntax is powerful but easy to
use and well adapted to scanning files. For example, the
absence of declarations and implicit initializations, while
probably a bad idea for a general-purpose programming
language, is desirable in a language that is meant to be
used for tiny programs that may even be composed on the com-
mand line.
In practice, ~ usage seems to fall into two broad
categories. One is what might be called "report genera-
tion" - processing an input to extract counts, sums, sub-
17 Zilog 17 .
AWK Zilog AWK
18 Zilog ·18
AWK Zilog AWK
SECTION 5
IMPLEMENTATION
The actual implementation of ~ uses the language develop-
ment tools available on the ZEUS operating system. The
grammar is specified with ~; the lexical analysis is done
by ~; the regular expression recognizers are deterministic
finite automata constructed directly from the expressions.
An ~ program is translated into a parse tree which is then
directly executed by a simple interpreter.
Alik was designed for ease of use rather than processing
speed; the delayed evaluation of variable types and the
necessity to break input into fields makes high speed diffi-
cult to achieve in any case. Nonetheless, the program has
not proven to be unworkably slow.
As might be expected, ~ is not as fast as the specialized
tools ~, ~, or the programs in the ~ family, but is
faster than the more general tool~. The tasks are about
as easy to express as ~ programs as programs in these
other languages; tasks involving fields are considerably
easier to express as ~ programs.
19 Zilog 19
-.
c Zilog c
1 Zilog 1
C Zilog C
PREFACE
2 Zilog 2
C Zi10g C
TABLE OF CONTENTS
3 Zi10g 3
C Zilog C
SECTION 1·
CONVERS ION OF PROGRA~1S TO ZEU 5
1.1 Introduction
Although the standard Version 7 UNIX runs on the 58000 sys-
tem and the 58000 C compiler accepts the C language, users
must be aware of machine dependencies that may be present in
their programs. This section describes the places for users
to look for machine dependencies in their programs when try-
ing to bring them up on the 58000 system.
4 Zilog 4
c Zilog c
/*
** This program allocates space for up to two
** string arguments and then copies them in
** the allocated space. The first argument
** (na) is the number of arguments and the
** second (ap) and the third (optional) argu-
** ments are the pointers to the strings to
** be copied. It returns a pointer to the
** location where the strings have been copied.
** have been copied.
*/
char *
copy (na, ap)
char *ap;
{
register char *p, *np;
char *onp:
register int n;
p = ap;
n = 0;
if (*p == 0)
return 0;
do
{
n++;
} while (*p++);
if (na > 1)
{
p = (&ap) [1] ;
while (*p++)
n++;
}
onp = np = alloc(n);
p= ap;
while (*np++ = *p++)
continue;
if (na > 1)
{
p = (&ap) [1]:
np--;
while (*np++ = *p++)
continue;
}
return onp;
}
5 Zilog 5
c Zilog c
char *
copy(na, apI, ap2)
char *apl, *ap2;
{
reg char *p, *np;
char *onp;
reg int n;.
p = apl;
n = 0;
if (*p == 0)
return 0;
do
{
n++;
} while (*p++);
if (na > 1)
{
p = ap2;
while (*p++)
n++;
}
onp = np = alloc(n);
p = apl;
while (*np++ = *p++)
continue;
if (na > 1)
{
p = ap2;
np--;
while (*np++ = *p++)
continue;
}
return onp;
}
6 Zilog 6
c Zilog c
7 Zilog 7
c Zilog c
printz(fmt,r6,rs,r4,r3,r2,stack)
register unsigned char *fmt; /* pointer to format string */
int r6,rs,r4,r3,r2; /* parameters passed in registers */
int stack; /* first parameter in the stack */
{
int pr6; /* storage for parameter register 6 */
int prs; /* the order of declaration of storage for */
int pr4; /* parameter registers has two effects: */
int pr3; /* first, long words have their words */
int pr2; /* exchanged; second, the pointer to
/* parameter storage can be incremented */
/* for parameters in registers and the stack */
int prcnt; /* number of parameters seen */
int i;
union{
int *ip;
long *lp;
} x;
/* save register parameters in storage */
pr6 = r6;
prs = rs;
pr4 = r4;
pr3 = r3;
pr2 = r2;
x.ip = &pr6;
prcnt = 0;
while (true)
{ /* once through for each format character */
i = *fmt++;
swi tch (i)
{
case' ': return; /* end of format */
case '%': i = *fmt++;
swi tch (i)
{
case 'd l : putint(*x.ip++);
break;
case 'D': if (prcnt < prmax)
zalign(&prcnt,&x.ip,&stack);
putlong(*x.lp++);
/*second word done below*/
prcnt++;
break;
case IC': putchar(*x.ip++);
break;
8 Zilog 8
c Zilog c
default: putchar('%');
putchar(i);
break;
}
prcnt++;
if (prcnt == prmax)
/* start using stack parameters */
x.ip = (int *)&stack;
break;
default: putchar(i);
break;
}
}
}
main ()
{
printz("%cO,'z');
printz("double: %DO,lL);
printz(Udecimal: %dO,69);
printz("%c%c%c%c%c%c%cO,'a','b','c','d','e','f','g');
printz("%D %D ~D %DO,100L,123456L,lL,98765432L);
printz("%D %d %c %dO,32L,10,'x',52);
}
9 Zilog 9
c Zilog c
(
10 Zilog 10
C Zilog C
11 Zilog 11
C Zilog C
12 Zilog 12
C Zilog C
SECTION 2
RECENT CHANGES TO C
2.1 General
A few extensions have been made to the C language described
in ~ ~ Programming Language. This section discusses these
extensions.
NOTE
There is a limitation to the C language in ZEUS
implementation of functions that return struc-
tures. If an interrupt occurs during the return
sequence and the same function is called again
during the interrupt, the value returned from the
first call can be "corrupted. The problem can
occur only in the presence of true interrupts, as
in an operating system or a user program that
makes significant use of signals. Ordinary recur-
sive calls are safe.
13 Zilog 13
c Zilog c
enum-list:
enumerator
enum-list, enumerator
enumerator:
identifier
identifier = constant-expression
The role of the identifier in the ~-specifier is similar
to the structure tag in a struct-specifier; it names a par-
ticular enumeration. For example,
enum color { chartreuse, burgundy, claret, winedark };
enum color *cp, col;
makes color the enumeration tag of a type describing various
colors, and then declares ~ as a pointer to an object of
that type and ~ as an object of that type.
The identifiers in the ~ ~ are declared as constants,
and can appear wherever constants are required. If no
enumerators appear with the equal sign (=), the values of
the constants begin at zero and increase by one as the
declaration is read from left to right. An enumerator with
the equal sign gives the associated identifier the value
indicated. Subsequent identifiers continue the progression
from the assigned value.
Enumeration tags and constants must be distinct and, unlike
structure tags and members, are drawn from the same set as
ordinary identifiers.
Objects with a given enumeration are "distinct from objects
of all other types. In ZEUS implementation, all enumeration
variables are treated as integers.
14 Zilog 14
COMM Zilog COMM
1 Zilog 1
COMJ.1 Zilog COMM
PREFACE
2 Zilog 2
COMM Zilog COMM
TABLE OF CONTENTS
3 Zi10g 3
COMM Zilog COMM
SECTION 1
INTRODUCTION
NOTE
This software package is not designed for communi-
cation between two ZEUS systems. For this capa~
bility, use the programs ~, YUK, and uulog.
(
4 Zilog 4
COMM Zilog COMM
SECTION 2
FUNCTIONAL DESCRIPTION
NOTE
If a duplicate file name exists on the target
system, the contents of pre-existing files are
automatically overwritten unless the [-q] option
is specified as part of the command (Section 3).
If the [-q] option is specified, the user is
queried for a replacement name.
Possible message is:
replace <filename> (yIn)?
6 Zilog 6
COMM Zilog COMM
SECTION 3
INVOCATION AND OPERATION
7 Zilog 7
COMM Zilog COMM
8 Zilog 8
COMM Zilog COMM
SECTION 4
TERMINATION
f
9 Zilog 9
CSB Zilog CSB
1 Zilog 1
CSH Zilog CSH
PREFACE
2 Zilog 2
CSH Zilog CSH
:
\.
TABLE OF CONTENTS
3 Zilog 3
CSH Zilog CSH
(
4 Zilog 4
CSH Zilog CSH
SECTION 1
INTERACTIVE USE OF THE C SHELL
1.1 Commands
A shell in ZEUS is, primarily, a medium through which other
commands are invoked. Csh has a set of built-in· commands
that it performs directly; however, most useful commands are
external to the shell. What distinguishes csh from command
interpreters of other systems is that it is a user program
that acts almost exclusively as a mechanism for invoking
other programs.
Commands in the ZEUS system expect a list of strings or
words as arguments. For example, the command
mail bill
consists of two words. The first word, mail, names the com-
mand to be executed (in this case the mail program that
sends messages to other users). Csh looks in a number of
directories for a file with the name mail, which contains
the mail program.
The rest of the words of the command are given to the com-
mand itself to execute. In this case, the word ~ is
interpreted by the mail program as the name of a user to
whom mail is to be sent. The mgil command is normally used
as follows:
% mail bill
I have a question about the csh documentation.
My document seems to be missing page five.
Does a page five exist?
Chuck
%
5 Zilog 5
CSH Zilog CSH
6 Zilog 6
CSH Zilog CSH
7 Zilog 7
CSH Zilog CSH
1.5.1 Pipelines
Csh can combine the standard output of one command with the
standard input of the next. This procedure runs the com-
mands in a sequence known as a pipeline. Commands separated
by a vertical bar (I) are connected together by csh: the
output of each is run into the input of the next. The left-
most command in a pipeline normally takes its standard input
from the terminal, and the rightmost places its standard
output on the terminal.
For example, the command
Is -s
produces a list of the files in the directory with the size
of each in blocks of 512 characters. Combining the ~ com-
mand with options of the ~ command sorts the directory
files by size rather than by name.
The -n option of ~ specifies a numeric sort rather than
an alphabetic sort. Combining this command with Is -s using
the pipe command (I)
Is -s I sort -n
8 Zilog 8
· ,
9 Zilog 9
CSH Zilog CSH
10 Zilog 10
esa Zilog esa
11 Zilog 11
CSH Zilog CSH
12 Zilog 12
CSH Zilog CSH
13 Zilog 13
CSH Zilog CSH
SECTION 2
DETAILS OF CSH OPERATION
14 Zilog 14
csa Zilog csa
set name=value
Csh variables can be used to store values that are to be
reintroduced into commands later through a substitution
mechanism. The csh variables most commonly referenced are
those referred to by csh itself. By changing the values of
these variables, it is possible to directly affect the
behavior of csh.
One of the most important variables is ggth, which contains
a sequence of directory names where the shell searches for
commands. The ~ command shows the value of all variables
currently defined in csh. The default value for ~ is
shown by ~ to be
% set
argv
horne /z/bill
path (. /bin /usr/bin)
prompt %
shell /bin/csh
jtatusO
%
15 Zilog 15
CSH Zilog CSH
unset ignoreeof
Both ~ and unset are built-in commands of csh.
Another built-in csh variable is noclobber, which prevents
files from being overwritten. The metasyntax
> filename
(which directs the output of a command) overwrites and des-
troys the previous contents of the named file. A file that
is valuable can be accidentally overwritten. To prevent csh
from overwriting files in this way, enter
set noclobber
in the .login file. Then, entering
.
date > now
causes a diagnostic if ~ already exists. The special
metasyntax >1 indicates that "clobbering" the file is allow-
able. Entering
date> 1 now
makes it possible to overwrite the contents of ~.
16 Zilog 16
CSH Zilog CSH
17 Zilog 17
· csa Zilog csa
* C Shell
*
* Bill Joy, UC Berkeley
* October, 1978
*/
char *pathlist[] = {SRCap
%
2.4 Aliases
The shell has an alias mechanism that makes transformations
on input commands by simplifying the commands typed, supply-
ing default arguments to commands, or performing transforma-
tions on commands and their arguments. The alias facility
is similar to the macro facility of many assemblers. ,/
18 Zilog 18
CSH Zilog CSH
19 Zilog 19
CSH Zilog CSH
Csh prints two process numbers and comes back very quickly
rather than waiting for the ~ and ~ commands to finish.
The numbers 5120 and 5121 are the process numbers assigned
by the system to the ~ and ~ commands.
Running commands in the background tends to slow down the
system and is not a good idea if the system is overloaded.
When overloaded, the system has a slower user response when
a large number of processes are run at once.
Severe complications can be expected if a command run in the
background is read from the user's terminal at the same time
as csh reads a command run from the terminal. To avoid this
problem, the default standard input for a command run in the
background is not the terminal but an empty file called
/dev/null. Commands run in the background are also unaf-
fected by interrupt and quit signals generated at the termi-
nal. (If a background command stops suddenly when INTERRUPT
or QUIT is pressed, a bug probably exists in the background
program. )
If it is necessary to log off the system before the command
completes, the command must be run immune to hangup signals.
This is done by placing the word nohup before each program
in the command. For example
20 Zilog 20
CSH Zilog CSH
21 Zilog 21
eSB Zilog eSB
% pwd
/z/bill
% mkdir newpaper
% chdir newpaper
% pwd
/z/bill/newpaper
%
22 Zilog 22
CSH Zilog CSH
23 Zilog 23
eSH Zilog eSH
24 Zilog 24
CSH zilog CSH
SECTION 3
CSH CONTROL STRUCTURES AND COMMAND SCRIPTS
3.1 Introduction
It is possible to place commands in files called shell
scripts and to invoke shells to read and execute commands
from these files. Those features of csh useful to the writ-
ers of such scripts are detailed in this section.
25 Zilog 25
CSH Zilog CSH
26 Zilog 26
csa Zilog csa
3.4 Expressions
To construct csh scripts,' it is necessary to evaluate
expressions in the shell based on the values of variables.
All the arithmetic operations of the language C are avail-
able in csh with the same precedence that they have in C.
The operations == and 1= compare strings, and the operators
&& and I I implement the boolean and/or operations.
27 Zilog 27
CSH Zilog CSH
28 Zilog 28
eSB Zilog eSB
cat copyc
i
# eopyc copies those e programs in the specified list
# to the directory -/backup if they differ from the files
# already in -/backup
#
set noglob
foreach i ($argv)
if ($i:r.c != $i) continue
# not a .c file so do nothing
if (1 -r -/backup/$i:t) then
echo $i:t not in backup ••• not cp\'ed
continue
endif
cmp -s $i -/backup/$i:t
# to set $status
if ($status 1= 0) then
echo new backup of $i
cp $i -/backup/$i:t
endif
end
This script uses the foreach command, which causes csh to
execute the commands between the foreach and the matching
~ for each of the values given between ( and )1 the named
variable (in this case, i) is set to successive values in
the list). Within this loop, it is possible to use the com-
mand break to stop execution of the loop, and continue to
prematurely terminate one iteration and begin the next.
After the foreach loop, the iteration variable retains the
value at the last iteration.
The variable noglob is set to prevent file name expansion of
the members of~. This is advisable if the arguments to
a shell script are file names that have already been
expanded or if the arguments can contain file name expansion
metacharacters. It is also possible to quote each use of a
$ variable expansion, but this is harder and less reliable.
The other control construct used here is a statement of the
form
if ( expression ) then
command
endif
...
The placement of the keywords here is not flexible due to
29 Zilog 29
CSH Zilog CSH
else
commands
endif
Another important mechanism used in csb scripts is colon (:)
modifiers. The modifier :r can be used to extract a root of
a file name. If the variable i has the value foo.bar, the
following example
% echo $i $i:r
foo.bar foo
%
30 Zilog 30
CSB Zilog CSB
substitution to 1. Thu~,
% echo $i $i:h:t
/a/b/c /a/b:t
%
31 Zilog 31
CSH Zilog CSH
The notation « IEOP' means that the standard input for the
~ command is to come from the text in the csh script file,
up to the next line consisting of IEOP'. The fact that the
EOP is enclosed in single quote (I) characters prevents csh
from performing variable sUbstitution on the intervening
lines. In general, if any part of the word following the «
(which the csh uses to terminate the text to be given to the
command) is quoted, these substitutions are performed. In
this case, since the form 1,$ was used in the editor script,
it is necessary to ensure that this $ is not variable sub-
stituted. It is also possible to ensure this by preceding
the $ with a \. Por example:
l,\$s/T[ ]*//
However, quoting the EOP terminator is a more reliable way
of achieving the same thing.
3.10 Make
Do not attempt to use shell scripts to perform taks that can
be handled by ~ (see ~ manual). The ~ program
maintains a group of related files or performs sets of
operations on related files. For instance, a large program
consisting of one or more files can have its dependencies
described in a makefile, which contains definitions of the
commands used to create these different files when changes
occur. Definitions of the means for printing listings,
cleaning up the directory in which the files reside, and
installing the resultant programs are easily placed in this
makefile. Using this format is preferable to maintaining a
group of shell procedures to maintain these files.
A makefile can be used for applications other than programs.
For example, a makefile can be created to define how dif-
ferent versions of a document are to be created and which
options of oroff or troff are appropriate.
33 Zilog 33
CSH Zilog CSH
SECTION 4
MISCELLANEOUS SHELL MECHANISMS
The shell prompts for input with ? when reading the body of
the loop.
Variables that contain lists of file names or other words
are useful with loops. For example,
% set a= ( 'Is')
% echo $a
esh.n esh.rm
% Is
esh.n
csh.rm
% echo $#a
2
%
34 Zilog 34
eSB Zilog eSB
35 Zilog 35
CSH Zilog CSH
36 Zilog 36
CSH Zilog CSH
APPENDIX A
SPECIAL CHARACTERS
37 Zilog 37
eSH Zilog eSH
38 Zilog . 38
CSB Zilog CSB
APPENDIX B
GLOSSARY
39 Zilog 39
CSH Zilog CSH
echo abc
consists of a command name ~ and three
argument words a, b, and c (1.1).
argv The list of arguments to a command written in
a shell script or shell procedure is stored
in a variable called ~ within the shell.
This name is taken from the conventional name
in the C programming language (3.4).
background A background command is a command that runs
while the shell executes other commands.
(2.5) •
40 Zilog 40
CSH Zilog CSH
command substitution
The replacement of a command enclosed in sin-
gle back quote (') characters by the text
output by that command is referred to as ~
msnd substitution (3.7, 4.2).
'-
41 Zilog 41
CSH Zilog CSH
42 Zilog 42
CSH Zilog CSH
43 Zilog 43
CSH Zilog CSH
44 Zilog 44
eSB Zilog eSB
45 Zilog 45
CSH Zilog CSH
46 Zilog 46
CSH Zilog CSH
47 Zilog 47
CSH Zilog CSH
48 Zilog 48
CSH Zilog CSH
•
of one command to become the standard input
of another 'command (1.5). Some commands do
not direct their output to the standard out-
put. The line printer command (~), for
example, diverts its output to the line
printer (2.3). The write command places its
output on another user's terminal (2.3).
Commands also have a diagnostic output where
they write their error messages. Normally,
these go to the terminal even if the standard
output has been sent to a file or another
command. However, it is possible to direct
error diagnostics along with standard output
using a special metanotation (2.5).
path The csh variable aath gives the names of the
directories in which it searches for the com-
mands it is given. It always checks first to
see if the named command is built into the
shell. If it is, it does not need to search
for the command, as it can perform it inter-
nally. If the command is not built in, csh
searches for a file with the name given in
each of the directories in the ~ variable,
left to right. Since the normal definition
of the ~ variable is
path (. /bin /usr/bin)
Csh normally looks in the current directory,
and then in the standard system directories,
/bin and /usr/bin, for the named command
(2.2) • If the command cannot be found, csh
prints an error diagnostic. Scripts of C
shell commands are executed using another
shell to interpret them if they have execute
bits set. This is normally true because a
command of the form
chmod 755 script
is executed to turn on these execute bits
(3.2) •
path name A list of names, separated'by slash (/) char-
acters forms a ~ ~. Each component
between successive / characters names a
directory in which the next component file
resides. Path names that begin with the
character / are interpreted relative to the
~ directory in the file system. Other
path names are interpreted relative to the
49 Zilog 49
CSH Zilog CSH
50 Zilog 50
CSH Zilog CSH
51 Zilog 51
CSH Zilog CSH
52 Zilog 52
csa Zilog csa
special character
See metacharacters and Appendix A of this
document.
standard The standard input and standard output of
commands are often referred to. See input
and output (1.3, 3.7).
status A command normally returns a status when it
finishes. By convention, a status of zero
indicates that the command succeeded. Com-
mands can return nonzero status to indicate
that some abnormal event has occurred. The
csh variable status is set to the status
returned by the last command. It is most
useful in shell commmand scripts (3.4, 3.5).
substitution Csh implements several substitutions where
sequences indicated by metacharacters are
replaced by other sequences. Examples of
this are history substitution keyed by the
metacharacter 1, and variable substitution
indicated by $. Substitutions are also
referred to as expansions (3.3).
switch The switch command of csh allows the shell to
select one of a number of sequences of com-
mands based on an argument string. It is
similar to the switch statement in the C
language (3.6).
termination When a command being executed finishes, it is
said to terminate. Commands normally ter-
minate when they read an EOF from their stan-
dard input. It is also possible to terminate
commands by sending them an interrupt or quit
signal (1.7). The kill program terminates
commands specified by their process numbers
(2.6) •
then The ~ command is part of csh's if-then-
else-endif control construct used in command
scripts (3.5)
time The ~ command measures the amount of CPU
and real time consumed by a specified command
(2.1, 2.6).
53 Zilog 53
i
I.
I
54 Zilog 54
eSH Zilog eSH
,(
55 Zilog 55
ED Zilog ED
f
1 Zilog 1
ED Zilog ED
PREFACE
2 Zilog 2
ED Zilog ED
TABLE OF CONTENTS
3 Zilog 3
ED Zilog ED
............................................................... 393939
14.1 Global S ~
...
14.2 Global Y..
14.3 Advanced Global Commands ••••••••••••••••
14.4 Advanced Multiline Global Commands •••••• 41
4 Zi10g 4
ED Zilog ED
f ;
5 Zilog 5
ED Zilog ED
SECTION 1
GETTING STARTED
•""."
I
6 Zilog 6
ED Zilog ED
SECTION 2
CREATING TEXT
7 Zilog 7
ED Zilog ED
SECTION 3
WRITING TEXT AS A FILE
To save text for later use, write the contents of the buffer
into a file. Use the write command
w
followed by the file name to be written on. This copies the
buffer's contents into the specified file and destroys any
previous information in the file. To save the text in a
file named junk, for example, type
w junk
Leave a space between ~ and the file name. EQ responds by
printing the number of characters it wrote out. In this
case, ~ responds with
68
Blanks and the return character at the end of each line are
included in the character count.
Writing a file makes a copy of the text. The contents of
the buffer are not disturbed, so lines can be added to it.
This is an important point. ~ always works on the buffer
copy of a file, not the file itself. No change in the con-
tents of a file takes place until ~ receives a ~ command.
Writing out the text to a file from time to time as it is
being created is a good idea. If the system crashes, only
the text in the buffer is lost, but any text written in a
file is safe.
8 Zilog 8
ED Zilog ED
SECTION 4
LEAVING THE EDITOR
which stands for SY.i..t. The shell responds with the prompt
character $ or %. At this point, the buffer with all its
text is no longer present. To protect the buffer from an
accidental erasure, ~ displays ? if it receives a quit com-
mand that was not preceded by a ~ command. At that point,
either write the file or type another g to get out of ed.
Exercise
Enter ~ and create some text using
a
... text •••
9 Zilog 9
ED Zilog ED
SECTION 5
READING TEXT FROM A FILE WITH "e"
Simply enter ~ from time to time; the file name used at the
beginning is updated with ~.
To find out what file name ~ is working on, type the file
command~. In this example, an .
f
prompts ~ to reply
junk
10 Zilog 10
ED Zilog ED
11 Zilog 11
\
I
ED Zilog ED
SECTION 6
Exercise
Experiment with the ~ command. Try reading and printing
various files. ~ may respond with ?name, where name is the
name of a file. This means that the file does not exist,
typically because the file name is spelled wrong, or reading
the file is not allowed. Try alternately reading and
appending to see that they work similarly. Verify that
ed filename
is equivalent to
ed
e filename
12 Zilog 12
ED Zilog ED
SECTION 7
PRINTING THE CONTENTS OF THE BUFFER
I~ $p
13 Zilog 13
ED Zilog ED
Exercise
Create some text using the .a command and experiment with the
~ command. Verify that line 0 or a line beyond the end of
the buffer cannot be printed and that attempts to print a
buffer in reverse order by typing
3,lp
also fail.
14 Zilog 14
ED Zilog ED
15 Zilog 15
ED Zilog ED
current line; that is, the line that dot refers to. If
there is one line number given with or without the letter ~,
it prints that line and sets dot there. If there are two
line numbers, it prints all the 'lines in that range and sets
dot to the last line printed. If two line numbers are
specified, the first cannot be bigger than the second (Exer-
cise 2).
Typing a single return prints the next line and is
equivalent to • ±is. Typing a - is equivalent to .=IR.
;'
16 Zilog 16
ED Zilog ED
SECTION 8
DELETING LINES
Exercise
Experiment with ~, ~, ~, ~, ~, and ~. Be sure to understand
how dot, $, and line numbers are used.
Next, try using line numbers with ~, ~, and ~ as well. Ver-
ify that:
$ ~ appends lines after the line number specified
rather than after dot
$ ~ reads a file in after the line number specified
and not the end of the buffer
$ ~ writes out exactly the lines specified, not the
whole buffer
These variations are sometimes handy. For instance, a file
can be inserted at the beginning of a buffer by entering
Or filename
17 Zilog 17
ED Zilog. ED
18 Zilog 18
ED Zilog ED
SECTION 9
MODIFYING TEXT
and get
Now is the time
Dot must have been set to the line where the sUbstitution
took place,· since the ~ command printed that line. Dot is
always set this way with the .a. command.
The general way to use the substitute command is
starting-~, ending-~ s/change ~tQ thisl
Whatever string of characters is between the first pair of
slashes is replaced by whatever is between the second pair,
in all the lines between starting-line and ending-line.
Only the first occurrence on each line is changed, however.
To change every occurrence, see Exercise 5. The rules for
line numbers are the same as those for ~, except that dot is
19 Zilog 19
ED Zilog ED
Exercise
Experiment with the substitute command. Verify that the
substitute command changes only the first occurrence of the
first string. For example, enter:
20 Zilog 20
ED Zilog ED
a
the other side of the coin
.
s/the/on the/p
to get
on the other side of the coin
To change all occurrences, add a g (for "global") to the ~
command, like this:
s/ ••• / ••• /gp
Try other characters instead of slashes to delimit the two
sets of characters in the ~ command. Any character except
blanks or tabs will work.
The following characters have special meanings:
... $ [ ] * \ &
21 Zilog 21
ED Zilog . ED
22 Zilog 22
ED Zilog ED
SECTION 10
CONTEXT SEARCHING
To search for the desired line and substitute with one com-
mand, enter
/their/s/their/the/p
which yields
to come to the aid of the party.
There are three parts to that command: context search for
the desired line, make the substitution, and print the line.
23 Zilog 23
ED Zilog ED
24 Zilog 24
ED Zilog ED
Exercise
Experiment with context searching. Try a body of text with
several occurrences of the same string of characters, and
scan through it using the same context search.
Use context searches as line numbers for the substitute,
print, and delete commands. Context searches are used less
frequently with ~, ~, and A, but try them.
Try context searching using ?~? instead of /~. This
scans lines in the buffer in reverse order (end to begin-
ning). This is useful when a desired string of characters
is passed while going forward.
Again, the following characters have special meaning:
[ ] * \ &
Read Section 13 for an explanation of their use.
25 Zilog 25
ED Zilog ED
SECTION 11
CHANGING AND INSERTING TEXT
The lines typed between the ~ command and the • take the
place of the original lines between start line and end line.
This is useful for replacing a line or several lines that
have errors in them. It is possible to replace a single
line with several lines.
If only one line is specified in the ~ command, just that
line is replaced. The dot ends the input and works like the
dot in the append command; it must appear by itself on a new
line. If no line number is given, line dot is replaced and
the value of dot is set to the last line typed in.
Insert (~) is similar to append. For instance
/string/i
••• type the lines to be inserted here •••
inserts the given text before the next line that contains
the string. The text between ~ and dot is inserted before
the specified line. If no line number is specified, dot is
used and dot is set to the last line inserted.
(
26 Zilog 26
ED Zilog ED
./
Exercise
The change command is rather like the combination delete
followed by insert. Experiment to verify that
27 Zilog 27
ED Zilog ED
start, ~ d
i
text •••
is like
start, ~ c
text •••
28 Zilog 28
,/
i
\
I
I.
I;
ED Zilog ED
SECTION 12
MOVING TEXT
29 Zilog 29
I'
I
"
ED Zilog ED
SECTION 13
USING SPECIAL CHARACTERS
13.1 General
The following characters have special meaning to ~ when
used in context searches and in the substitute command:
$ [] * \ &
13.2 Period
On the left side of a substitute command or in a search with
j ••• j, the period (.) stands for any single character.
Thus, the search
jx.yj
30 Zilog 30
ED Zilog ED
13.3 Backslash
The backslash (\) turns off any special meaning that the
next character might have. In particular, \. converts.
from a "match anything" into a period, so it can be used to
replace the period in
Now is the time.
with a question mark like this:
s/\./?/
The pair of characters \. is interpreted by ~ as a single
period.
The backslash can also search for lines that contain a spe- /
cial character. To look for a line that contains
31 Zilog 31
ED Zilog ED
• PP
the search
I.ppi
is not adequate, because it finds a line
THE APPLICATION OF
since the. matches the letter A. However, the command
I\.PPI
finds only lines that contain .PP.
The backslash can also turn off special meanings for charac-
ters other than period. For example, to find a line that
contains a backslash, precede one backslash with another as
in
I\V
Similarly, search for a forward slash (I) with
1\11
Exercise
Find two substitute commands to convert the line
\x\.\y
into the line
32 Zilog 32
ED Zilog ED
\x\y
Here are several solutions to verify.
s/\\\.11
six •• /xl
s/ •• y/yl
33 Zilog 33
ED Zilog ED
13.5 Circumflex
The circumflex (~) stands for the beginning of the line. To
look for a line that begins with ~, use
/Athe/
to narrow the context and arrive at the desired word more
easily.
The other use of ~ inserts text at the beginning of a line.
The command
s/~/ /
places a space at the beginning of the current line.
Special characters can be combined. To search for a line
that contains only the characters
.PP
use the command
/~\.PP$/
13.6 Asterisk
A character followed by an asterisk (*) stands for a vari-
able number of consecutive occurrences of that character. A
line can look like this:
~ x
34 Zilog 34
ED Zilog ED
the command
six *y/x y/
35 Zilog 35
ED Zilog ED
s/x*/y/g
when applied to the line
abcdef
produces
yaybycydyeyfy
This is because zero is a legal number of matches. There
are no XiS at the beginning of the line, and no-x gets con-
verted to a::l-. There are no XiS between.a and ,b, so the
non-x (zero characters) is converted into~. This process
continues down the string. To solve the problem, write
s/xx*/y/g
where xx* is one or more XiS.
13.7 Brackets
The brackets ([]) match any element of the character class
within them.
To delete any numbers that appear at the beginning of all
lines of a file, use the construction
[0123456789] *
This matches zero or more digits. Thus, the command
l,$s/A[0123456789]*//
deletes all digits from the beginning of all lines.
36 Zilog 36
ED Zilog ED
13.8 Ampersand
The ampersand (&) is used to save typing. Suppose the line
Now is the time
must be changed to
Now is the best time
The command
s/the/the best/
can be used, but it is redundant to repeat the~. The
ampersand eliminates that repetition. On the right side of
37 Zilog 37
ED Zilog ED
38 Zilog 38
ED Zilog ED
SECTION 14
USING GLOBAL COMMANDS
14.1 Global g
Global commands operate on the entire buffer instead of an
individual line.
The global command (g) executes one or more ~ commands on
all lines in the buffer that match some specified string.
For example
g/peling/p
prints all lines that contain peling. More usefully,
g/peling/s//pelling/gp
makes the substitution everywhere on the line, then prints
each corrected line. Compare this to
l,$s/peling/pelling/gp
which print~ only the last line substituted. Another
difference 1S that the g command does not give a? if it
does not find peling, but the ~ command does.
Use these examples to see the difference between the global
command g and the g following a substitute command. These
g's occur at different places in the command line and have
different meanings.
14.2 Global 2
The 2 command is the same as g, except that the commands are
executed on every line that does not match the string fol-
lowing 2. For example:
v/ /d
deletes every line that does not contain a blank.
39 Zilog 39
ED Zilog ED
40 Zilog 40
ED Zilog ED
Finally,
prints all the lines between lines beginning with .EO and
.EN formatting commands.
The g and ~ commands can also be preceded by line numbers to
search only those in the range specified.
(
41 Zilog 41
ED Zilog ED
SECTION 15
SUBSTITUTING NEW LINES
The command
s/ very /\
.ul\
very\
/
converts the line into four shorter lines, preceding the
word ~ by the line ~ and eliminating the spaces around
the ~.
When a new line is substituted, dot points at the last line
created.
42 Zilog 42
ED Zilog ED
SECTION 16
MANIPULATING LINES
43 Zilog 43
ED Zilog ED
,
The first \( ••• \) matches the last name (any string up to
the comma) and is referred to on the right side with ~.
The second \( ••• \) is whatever follows the comma and any
spaces, and is referred to as \2.
When this type of editing is performed, use the global com-
mands g or ~ followed by S to print each substitution as it
is made.
~.,~.,
44 Zilog 44
ED Zilog ED
SECTION 17
MANIPULATING ADDRESSES
45 Zi10g 45
ED Zilog ED
46 Zilog 46
ED Zilog ED
SECTION 18
DOING REPEATED SEARCHES
The construction
II
is a shorthand for "the previous thing that was searched
for," whatever it was. This can be repeated as many times
as necessary. The search can also go backwards. The com-
mand
??
47 Zilog 47
ED Zilog ED
SECTION 19
USING DEFAULT LINE REFERENCES
48 Zilog 48
ED Zilog ED
a
··.... botch
text •••
••• (minor error)
.
s/botch/correct/ (fix line)
a
••• more text •••
can be given without specifying any line number for the sub-
stitute command or for the second append command. Alterna-
tively, use
a
··.... text •••
horrible botch (major error)
c (replace entire line)
fixed line •••
The ~ command reads a file into the text being edited,
either at the end if no address is given, or after the
specified line if there is an address. In either case, dot
points at the last line read. Remember that ~ reads a file
in at the beginning of the text.
The ~ command writes the entire file. If the command is
preceded by one line number, that line is written. If it is
preceded by two line numbers, that range of lines is writ-
ten. The ~ command does not change dot; the current line
remains the same, regardless of what lines are written.
This is true even if there is a command such as
the command
-,+s/x/y/p
49 Zilog 49
ED Zilog ED
prints the third line, which is the last one changed. With
the three lines
xl
y2
y3
the same command changes and prints only the first line and
positions dot there.
50 Zilog 50
ED Zilog ED
SECTION 20
USING THE SEMICOLON
ab
.
bc
I
Starting at line 1, the command
\
/a/,/b/p
would be expected to print all the lines from the ~ to the
~. Instead, both searchs start from the same point and
they both find the line that contains~. The result is to
print a single line. Worse, if there had been a line with a
~ in it before the ~ line, the print command would be in
error, since the second line number would be less than the
first; it is illegal to try to print lines in reverse order.
The comma separator for line numbers does not set dot as
each address is processed. Instead, each search starts from
the same place. Thus, in this example, the command
/a/;/b/p
prints the ra~ge of lines from ~ to~. After the ~ is
found, dot ~s set to that line, then Q is searched for,
starting beyond that line.
To find the second occurrence of thing, enter
/thing/;//
51 Zilog 51
ED Zilog ED
52 Zilog 52
ED Zilog ED
SECTION 21
INTERRUPTING THE EDITOR
53 Zilog 53
ED Zilog ED
r SECTION 22
MANIPULATING FILES
22.1 General
In addition to editor commands, other commands exist to
manipulate files. Manipulating files includes changing the
name of a file, making a copy of a file somewhere else, mov-
ing a few lines from one place to another in a file, insert-
ing one file in the middle of another, splitting a file into
pieces, and splicing two or more files together.
mv oldname newname
This program moves the file from the old name to the new
name. For example, to change a file named ~ into one
called paper, enter
mv memo paper
NOTE
If there is already a file with the new name, its
present contents are overwritten by the informa-
tion from the old file. Also, a file cannot be
moved to itself. So
mv x x
is illegal.
(
54 Zilog 54
ED Zilog ED
55 Zilog 55
ED Zilog ED
56 Zilog 56
ED zilog ED
57 Zilog 57
ED Zilog ED
58 Zilog 58
ED Zilog ED
a
.......... x ••••••••• (long line)
j
t. (make a copy)
s/x/y/ (change it a bit)
t. (make third copy)
s/y/z/ (change it a bit)
and so on.
59 Zilog 59
ED Zilog ED
SECTION 23
SUPPORTING TOOLS
23.1 General
There are several tools and techniques based on the editor.
In this section are some introductory examples of these
tools.
23.2 Grep
To find all occurrences of some word or pattern in a set of
files, use the program ~. The search patterns described
in the document are often called "regular expressions," and
"grep" stands for
g/re/p (get / regular expression / print)
That describes exactly what ~ does--it prints every line
in a set of files that contains a particular pattern. Thus
grep 'thing' filel file2 file3
finds thing wherever it occurs in any of the files listed.
~ also indicates the file in which the line was found for
any further file manipulation.
The pattern represented by thing can be any pattern that can
be used in~. Always enclose the pattern in single quotes
if it contains any nonalphabetic characters. These charac-
ters carry special meaning in the ZEUS command interpreter
(Section 15) •
There is also a way to find lines that do not contain a pat-
tern. The command
grep -v 'thing' filel file2 ...
finds all lines that do not contain thing. The ~ must
occur in the position shown. Given ~ and ~ ~ it is
possible to do things like selecting all lines that contain
some. combination of patterns. For example, to get all lines
that contain X but not ~, use
grep x file ••• grep -v y
The notation I is a pipe command, which causes the output of
the first command to be used as input to the second command.
60 Zilog 60
ED Zilog ED
" .~. ,.
Now enter
ed filel <script
ed file2 <script
25.4 Sed
~ (stream editor) processes unlimited amounts of input.
~ copies its input to its output, applying one or more
editing commands to each line of input.
As an example, to change ~ to ~ as in' the previous
example without rewriting the files, use the command
sed • s/Zeus/ZEUS/g , filel file2 ...
This applies the command s/Zeus/ZEUS/g to all lines from the
files specified and copies all lines to the output. The
advantage of using ~ is that it handles input too large
for ~. All the output can be collected in one place, and
either saved in a file or piped into another program.
If the editing transformation is so complicated that more
than one editing command is needed, commands can be supplied
from a file with a slightly more complex syntax. To take
commands from a file, for example, use
sed -f cmdfile input-files •••
61 Zilog 61
ED Zilog ED
APPENDIX A
SUMMARY OF COMMANDS AND LINE NUMBERS
62 Zilog 62
ED Zilog ED
v/---/commands
executes commands on those lines that do not contain ,
which can be any context search expression.
~: Write out buffer onto a file. Dot is not changed •
• =: Print value of dot. The = by itself prints the value of
$•
63 Zilog 63
FSCK Zilog FSCK
1 Zilog 1
FSCK Zilog FSCK
PREFACE
2 Zilog 2
/
FSCK Zilog FSCK
TABLE OF CONTENTS
3 Zilog 3
FSCK Zilog FSCK
4 Zilog 4
I.
i
SECTION 1
INTRODUCTION
When the ZEUS Operating System is brought up, the file sys-
tem check program (fsck) must be run. Fsck is an interac-
tive file system progr.am that uses the redundant structural
information in the ZEUS file system to perform consistency
checks. Fsck detects file inconsistencies and reports them
to an operator who elects to fix or ignore them. This pre-
cautionary measure helps to ensure a reliable environment
for file storage on disk.
Every file activity (creation, modification, or deletion)
updates at least one of the five data blocks that ZEUS uses
to monitor files. Fsck checks for matches in the contents
of redundant fields among these blocks, and for matches
between information in the blocks and the files themselves.
When any error is found, fsck reports it to an operator.
Most errors allow for operator intervention to continue run-
ning fsck or to terminate it. Serious errors, such as ille-
gal options, cause fsck to terminate.
5 Zilog 5
FSCK Zilog FSCK
SECTION 2
UPDATE OF THE FILE SYSTEM
2.1 General
Every time a file is created, modified, or removed, the ZEUS
Operating System performs a series of file system updates on
the super-block, inodes, indirect blocks, data blocks
(directories and files), and free-list blocks. Update
requests are honored in a specific order to yield a con-
sistent file system. Knowing this order makes it easier to
understand what happens when a problem occurs, and to repair
a corrupted file system.
2.2 Super-Block
The super-block contains information about the size of the
file system, the size of the inode list, part of the free-
block list, the count of free blocks, the count of free
inodes, and part of the free-inode list.
The root file system is always mounted, and the super-block
of a mounted file system is written to the file system when-
ever the file system is unmounted or a sync command is
issued.
2.3 Inodes
An inode contains information about the type of inode
(directory, data, or special), the number of directory
entries linked to the inode, the list of blocks claimed by
the inode, and the size of the inode.
An inode is written to the file system on closure of the
file associated with the inode, and when a sync command is
issued.
6 Zilog 6
FSCK Zilog FSCK
7 Zilog 7
FSCK Zilog FSCK
SECTION 3
CORRUPTION OF THE FILE SYSTEM
3.1 General
The most common reasons for corruption of a file system are
improper shutdown and hardware failure.
8 Zilog 8
\"
FSCK Zilog FSCK
SECTION 4
DETECTION AND CORRECTION OF CORRUPTION
4.1 General
A quiescent file system (one that is unmounted and not being
written on) can be checked for structural integrity by per-
forming consistency checks of the redundant data that is
part of the file system. A quiescent state is important
during the file system check because of the multipass nature
of the fsck program. Fsck discovers each file incon-
sistency, reports it to the operator, and allows for
interactive corrective action.
This section discusses how to discover inconsistencies and
take corrective actions for super-blocks, inodes, indirect
blocks, data blocks containing directory entries, and free-
list blocks.
4.2 Super-Block
The super-block is most prone to corruption because every
change to the file system's block or inodes modifies the
super-block. Corruption most frequently occurs when the
computer is halted and the last command involving the output
of the file system was not a sync command.
Check the super-block for inconsistencies involving file-
system size, inode-list size, free-block list, free-block
count, and the free-inode count.
9 Zilog 9
FSCK Zilog FSCK
4.3 Inodes
A large quantity of active inodes increases the likelihood
of corruption. Fsck sequentially checks the list of inodes
for inconsistencies involving format and type, link count,
duplicate blocks, bad blocks, and inode size.
10 Zilog 10
FSCK Zilog FSCK
11 Zilog 11
FSCK Zilog FSCK
"' ....
12 Zilog 12
FSCK Zilog FSCK
f
13 Zilog 13
FSCK Zilog FSCK
14 Zilog 14
FSCK Zilog FSCK
APPENDIX A
FSCK ERROR CONDITIONS
A.l Conventions
Fsck is a multipass file system check program with each file
system pass invoking a different phase of the fsck program.
After the initial setup, fsck performs successive phases on
each file system, checks blocks and sizes, path names, con-
nectivity, reference counts, and the free-block list (which
might be rebuilt), and performs some cleanup.
When an inconsistency is detected, fsck reports it to the
operator. If a response is required, fsck prints a prompt
message and waits for a response. This appendix explains
the meaning of each error condition, the possible responses,
and the related error conditions.
The error conditions are organized by the phase of the fsck
program in which they occur. The error conditions that
occur in more than one phase are discussed in the Initiali-
zation Section.
A.2 Initialization
Before a file system check can be performed, certain tables
must be set up and certain files must be opened. This sec-
tion lists error conditions resulting from initializing
tables and opening files; specifically, it lists error con-
ditions resulting from command line options, memory
requests, opening of files, status of files, file system
size checks, and creation of the scratch file.
C OPTION ?
C is not a legal option of fsck; legal options are -y, -n,
-s, -S, and -t. Fsck terminates on this error condition
(!a£t(~» •
BAD -t OPTION
The -t option is not followed by a file name. Fsck ter-
minates on this error condition (!a£t(~».
15 Zilog 15
FSCK Zilog FSCK
CAN'T STAT F
Fsck's request for statistics about the file system F
failed. Fsck ignores this file system and continues check-
ing the next file system given. Check access modes of F.
16 Zilog 16
FSCK Zilog FSCK
CAN'T OPEN F
The file system F cannot be opened for reading. Fsck
ignores this file system and continues checking the next
file system given. Check access modes of F.
CAN'T CREATE F
Fsck's request to create a scratch file F failed. Fsck
ignores this file system and continues checking the next
file system given. Check access modes of F.
17 Zilog 17
FSCK Zilog FSCK
18 Zilog 18
FSCK Zilog FSCK
B BAD 1=1
Inode I contains block number B with a number lower than the
number of the first data block in the file system, or
greater than the number of the last block in the file sys-
tem. This error condition invokes the EXCESSIVE BAD BLKS
error condition in Phase 1 if inode I has too many block
numbers outside the file system range. This error condition
always invokes the BAD/DUP error condition in Phase 2 and
Phase 4. See Section 4.3.4.
19 Zilog 19
FSCK Zilog FSCK
B DUP I=I
Inode I contains block number B which is already claimed by
another inode. This error condition invokes the EXCESSIVE
DUP BLKS error condition in Phase 1 if inode I has too many
block numbers claimed by other inodes. This error condition
always invokes Phase IB and the BAD/DUP error condition in
Phase 2 and Phase 4 (Section 4.3.3) •
20 Zilog 20
FSCK Zilog FSCK
B DUP 1=1
Inode I contains block number B, which is already claimed by
another inode. This error condition always invokes the
BAD/DUP error condition in Phase 2. Inodes that have over-
21 Zilog 21
FSCK Zilog FSCK
22 Zilog 22
FSCK Zilog FSCK
23 Zilog 23
FSCK Zilog FSCK
24 Zilog 24
FSCK Zilog FSCK
(CLEAR?)
The inode mentioned in the immediately previous error condi-
tion cannot be reconnected (Section 4.3.2).
Possible responses to the CLEAR? prompt are:
YES Deallocate the inode mentioned in the immedi-
ately previous error condition by setting its
contents to zero.
NO Ignore this error condition.
26 Zilog 26
FSCK Zilog FSCK
\
LINK COUNT F 1=1 OWNER=O MODE=M SIZE=S MTIME=T COUNT=X
SHOULD BE Y (ADJUST?)
The link count for F inode I is X but should be Y. The name
F, owner 0, mode M, size S, and modify time T are printed
(Section 4.3.2).
Possible responses to the ADJUST? prompt are:
YES Replace the link count of inode I with Y.
NO Ignore this error condition.
27 Zilog 27
FSCK Zilog FSCK
28 Zilog 28
FSCK Zilog FSCK
29 Zilog 29
FSCK Zilog FSCK
x BLK(S) MISSING
X blocks unused by the file system were not found in the
free-block list. This error condition always invokes the
BAD FREE LIST condition in Phase 5 (Section 4.2.2).
30 Zilog 30
FSCK Zilog FSCK
A.lO Cleanup
Once a file system has been checked, cleanup functions are
performed. This section lists advisory messages about the
file system and modify status of the file system.
31 Zilog 31
FSCK Zilog FSCK
INDEX OF MESSAGES
(Alphabetically within each section)
INTIALIZATION
BAD -t OPTION •••••••••••••••••••••••••••••••••••• 15
C OPTION? •••••••••••••••••••••••••••••••••••••••• 15
CANNOT READ: BLK B (CONTINUE?) ••••••••••••••••••• 17
CANNOT SEEK: BLK B (CONTINUE?) ••••••••••••••••••• 17
CANNOT WRITE: BLK B (CONTINUE?) •••••••••••••••••• 18
CAN'T CREATE F ••••••••••••••••••••••••••••••••••• 17
CAN'T GET MEMORy ••••••••••••••••••••••••••••••••• 16
CAN'T OPEN CHECKLIST FILE: F ••••••••••••••••••••• 16
CAN'T OPEN F ••••••••••••••••••••••••••••••••••••• 1 7
CAN'T STAT F ••••••••••••••••••••••••••••••••••••• 16
CAN'T STAT ROOT •••••••••••••••••••••••••••••••••• 16
F IS NOT A BLOCK OR CHARACTER DEVICE ••••••••••••• 16
INCOMPATIBLE OPTIONS: -n and -s •••••••••••••••••• 16
INVALID -s ARGUMENT, DEFAULTS ASSUMED •••••••••••• 16
SIZE CHECK: FSIZE X ISIZE Y •••••••••••••••••••••• 17
32 Zilog 32
FSCK Zi10g FSCK
33 Zi10g 33
FSCK Zi10g FSCK
CLEANUP
*****BOOT ZEUS (NO SYNC!)***** ••••••••••••••••• 31
*****FILE SYSTEM WAS MODIFIED***** ••••••••••••• 31
X FILES Y BLOCKS Z FREE •••••••••••••••••••••••• 31
34 Zi10g 34
LEARN Zilog LEARN
LEARN
COMPUTER-AIDED INSTRUCTION ON ZEUS
1 Zilog 1
LEARN Zilog LEARN
PREFACE
2 Zilog 2
LEARN Zilog LEARN
TABLE OF CONTENTS
3 Zilog 3
I
j'
LEARN Zilog LEARN
SECTION 1
INTRODUCTION
The system that teaches computer skills has two main parts:
a driver called LEARN that interprets the scripts, and the
scripts themselves. At present, there are seven Computer
Aided Instruction (CAl) scripts:
1. first-time user introduction
2. basic file handling commands
3. ZEUS text editor (~)
4 Zilog 4
LEARN Zilog LEARN
SECTION 2
EDUCATIONAL ASSUMPTIONS AND DESIGN
5 Zilog 5
LEARN Zilog LEARN
6 Zilog 6
LEARN . Zilog LEARN
7 Zilog 7
LEARN Zilog LEARN
8 Zilog 8
j",
I
I
SECTION 3
SCRIPTS
9 Zilog 9
LEARN Zilog LEARN
10 Zilog 10
LEARN Zilog LEARN
SECTION 4
THE SCRIPT INTERPRETER
editor
...
(other courses)
log
11 Zilog 11
LEARN Zilog LEARN
4.3 Requirements
Each lesson must contain the following basic items:
e the text of the lesson
e the set-up commands to be executed before the user
gets control
e the data, if any, that the user is supposed to
edit, transform, or otherwise process
e the evaluating commands to be executed after the
user has finished the lesson, which decide whether
the answer is right
e a list of possible successor lessons
LEARN minimizes the work of bookkeeping and installation, so
that most of the effort involved in script production is in
planning lessons, writing tutorial paragraphs, and coding
tests of student performance.
12 Zilog 12
LEARN Zilog LEARN
13 Zilog 13
LEARN Zilog LEARN
:fI:copyin
:fI:uncopyin
is copied onto a file called .~. This allows for interro-
gation of the student's responses upon regaining control.
Between the commands
:fI:copyout
:fI:uncopyout
any material typed by the student for any program is copied
to the file .ocoPY. This allows interrogation of the effect
of what the student typed.
Normally the student's input and the script commands are fed
to the ZEUS command interpreter (the shell) one line at a
time. A sequence of editor commands does not work, since
the input to the editor must be handed to the editor, not to
the shell. Accordingly, the material between the commands
:fI:~ and :fI:unpipe is fed continuously through a pipe so that
such sequences work. If copyout is also desired, the copy-
out brackets must include the pipe brackets.
There are several commands for setting statu's after the stu-
dent has attempted the lesson.
:fI:cmp filel file2
is an in-line implementation of kmP that compares two files
for identity. Following the command
:fI:match stuff
the last line of the student's input is compared to stuff,
and the success or fail status is set according to this com-
parison. Extraneous things like the word answer are
stripped before the comparison is made. There can be
several :fI:match lines7 this provides a convenient mechanism
for handling multiple "right" answers. Any text up to a :fI:
on subsequent lines after a successful :fI:match is printed, as
shown next.
:fI:print
What command will move the current line
to the end of the file? Type
"answer COMMAND", where COMMAND is the command.
:fI:copyin
:fI:user
:fI:uncopyin
:fI:match m$
:fI:match .m$
"m$" is easier.
14 Zilog 14
LEARN Zilog LEARN
#log
#next
63.ld 10
#bad stuff
This is similar to #match, except that it corresponds to
specific failure answers; this produces hints for particular
wrong answers that have been anticipated by the script
writer. The commands
#succeed
#fail
print a message upon success or failure (as determined by
some other mechanism).
When the student types one of the "commands" ~, ~, nQ,
ready, or answer, the driver terminates the #~ command,
and evaluation of the studentrs work can begin. This can be
done either by the built-in commands, such as #match and
#~, or by status returned by normal ZEUS commands, typi-
cally ~ and~. The last command should return status
true (0) if the task is done successfully and false
(nonzero) otherwise; this status return tells the driver
whether or not the student has successfully passed the les-
son.
Performance can be logged:
#log file
writes the date, lesson, user name and speed rating, and a
success/failure indication on~. The command
#log
by itself writes the logging information in the logging
directory within the LEARN hierarchy, and is the normal
form. The commands
# cleanup
# nocleanup
are for directing the LEARN driver to clean up or ignore the
temporary files created in a lesson. By default, learn
cleans out the temporary files after each lesson. Specifi-
cally, all files that begin with a lowercase letter and are
not ".c" files are deleted before the next lesson. The
#nocleanup directive enables following lessons to depend on
files already created or changed by the user, and #cleanup
15 Zilog 15
LEARN Zilog LEARN
16 Zilog 16
LEARN Zilog LEARN
SECTION 5
CONCLUSIONS
17 Zilog 17
LEARN Zilog LEARN
18 Zilog 18
LEX Zilog LEX
LEX
A LEXICAL ANALYZER GENERATOR *
USER GUIDE
1 Zilog 1
LEX Zi10g LEX
PREFACE
2 Zi10g 2
LEX Zi10g LEX
TABLE OF CONTENTS
3 Zi10g 3
LEX Zi10g LEX
4 Zi10g 4
LEX Zilog LEX
SECTION I
INTRODUCTION
5 Zilog 5
LEX Zilog LEX
6 Zilog 6
LEX Zilog LEX
SECTION 2
LEX SOURCE
7 Zilog 7
LEX Zilog LEX
SECTION 3
LEX REGULAR EXPRESSIONS
3.1 Introduction
A regular expression specifies a set of strings to be
matched. It contains text characters that match the
corresponding characters in the strings being compared and
operator characters that specify repetitions, choices, and
other features.
The letters of the alphabet and the digits are always text
characters; thus, the regular expression
integer
matches the string integer wherever it appears, and the
expression
aS7D
looks for the string ~.
3.2 Operators
The operator characters are
" \ [ ] " - ? * + I ()$/{}%<>
When operators are used as text characters, an escape must
be used. The quotation mark operator (") indicates that any
characters contained between a pair of quotes should be
treated as text characters. Thus,
8 Zi10g 8
LEX Zilog LEX
9 Zilog 9
LEX Zilog LEX
10 Zilog 10
LEX Zilog LEX
[a-z]+
is all strings of lowercase letters. And
[A-Za-z] [A-Za-zO-9]*
indicates all alphanumeric strings with a leading alphabetic
character. This is a typical expression for recognizing
identifiers in computer languages.
11 Zilog 11
LEX Zilog LEX
<ONE>
Start conditions are explained more fully in Section 10.
12 Zilog 12
/
LEX Zilog LEX
SECTION 4
LEX ACTIONS
4.1 Introduction
When an expression is matched, Lex executes the correspond-
ing action. This section describes some features of Lex
that aid in writing actions. There is a default action,
which consists of copying the input to the output, that is
performed on all strings not otherwise matched. Thus, to
absorb the entire input without producing any output, rules
must be provided to match everything. When Lex is used with
Yacc, this is the normal situation. Actions are used
instead of copying the input to the output. A character
combination that is omitted from the rules but appears as
input is likely to be printed on the output, calling atten-
tion to the gap in the rules.
" "
"\t"
n\nn .,
with the same result. The quotes around \n and \t are not
required.
In more complex actions, it is often necessary to know the
actual text that matches some expression like [A-Z]+. Lex
leaves this text in an external character array named
yytext. To print the name found, use a rule like:
[a-z]+ printf(n%sn, yytext);
13 Zilog 13
LEX LEX
14 Zilog 14
LEX Zilog LEX
15 Zilog 15
LEX Zilog LEX /
16 Zilog 16
LEX Zilog LEX
17 Zilog 17
LEX Zilog LEX
SECTION 5
AMBIGUOUS SOURCE RULES
18 Zilog 18
LEX Zilog LEX
19 Zilog 19
LEX Zilog LEX
20 Zilog 20
LEX Zilog LEX
SECTION 6
LEX SOURCE DEFINITIONS
As Lex turns the source rules into a program, any source not
intercepted by Lex is copied into the generated program.
This happens in the following three cases:
1. Any line beginning with a blank or tab that is not
part of a Lex rule or action is copied into the Lex
generated program. Such source input prior to the
first %% delimiter is external to any function in
the code. If it appears immediately after the
first %%, it appears in an appropriate place for
declarations in the function written by Lex that
contains the actions. This material must look like
program fragments, and must precede the first Lex
rule.
As a side effect, lines beginning with a blank or
tab that contain a comment are passed through to
the generated program. This includes comments in
either the Lex source or the generated code. The
comments should follow the hOpt language conven-
tion.
2. Anything included between lines containing only %{
and %} is copied out as in the previous case. The
delimiters are discarded. This -format permits
entering text like preprocessor statements that
must begin in column 1, or copying lines that do
not look like programs.
3. Anything after the third %% delimiter, regardless
of format, is copied out after the Lex output.
In addition to the rules, options are required to define
variables used by Lex or by a user program.
Definitions intended for Lex are given before the first %%
delimiter. Any line in this section not contained between
%{ and %}, and beginning in column 1, is assumed to define
Lex sUbstitution strings. The format of such lines is
name translation
and it causes the string given as a translation to be asso-
ciated with the name. The name and translation must be
separated by at least one blank or tab, and the name must
begin with a letter. The translation can then be called out
21 Zilog 21
LEX Zilog LEX
22 Zilog 22
LEX Zilog LEX
SECTION 7
COMPILING LEX
23 Zilog 23
LEX Zilog LEX
SECTION 8
LEX AND YACC
24 Zilog 24
LEX Zilog LEX
,
SECTION 9
EXAMPLES
I
9.1 Copy with Simple Arithmetic Changes
The following Lex source program copies an input file while
adding three to every positive number divisible by seven.
%%
int k;
[0-9]+ {
sscanf(yytext, "%d", &k);
if (k%7 == 0)
printf("%d", k+3);
.. else
printf("%d",k);
}
25 Zilog 25
LEX Zilog LEX
int lengs[lOO];
%%
[a-z]+ lengs[yyleng]++;
• I
\n ;
%%
yywrap()
{
int i;
printf("Length No. words\n");
for(i=O; i<lOO; i++)
if (lengs[i] > 0)
printf("%5d%10d\n", i , lengs [i]) ;
return(l);
}
26 Zilog 26
LEX Zilog LEX
SECTION 10
LEFT CONTEXT SENSITIVITY
27 Zilog 27
LEX Zilog LEX
int flag7
%%
Aa {flag = 'a', ECHO,}
Ab {flag = 'b'; ECHO,}
AC {flag = 'c', ECHO,}
\n {flag = 0, ECHO;}
magic {
switch (flag)
{
case 'a': printf("first"), break,
case 'b': printf("second"), break;
case 'c': printf("third"); break;
default: ECHO; break,
}
}
To handle the same problem with start conditions, each start
condition must be introduced to Lex in the definitions sec-
tion with a line reading
%Start namel name2 •••
The conditions can be named in any order. The word start
can be abbreviated to ~ or~. The conditions can be refer-
enced at the head of a rule with brackets «».
The command
<namel>expression
is a rule that is only recognized when Lex is in the start
condition namel. To enter a start condition, execute the
action statement
BEGIN namel;
which changes the start condition to namel. To resume the
normal state, the command
BEGIN 0,
resets the initial condition of the Lex automaton inter-
preter. A rule can be active in several start conditions.
For example,
<namel,name2,name3>
is a legal prefix. Any rule not beginning with the <> pre-
fix operator is always active.
28 Zilog 28
LEX Zilog LEX
29 Zilog 29
LEX Zilog LEX
SECTION 11
CHARACTER SET
...
31
39
1
9
%T
1.1
I~
30 Zilog 30
LEX Zilog LEX
SECTION 12
SUMMARY OF SOURCE FORMAT
31 Zilog 31
LEX Zilog LEX
32 Zilog 32
LEX Zilog LEX
SECTION 13
CAUTIONS
33 Zilog 33
Zilog
:(
1 Zilog 1
LINT Zilog LINT
2 Zilog 2
LINT Zilog LINT
3 Zilog 3
LINT Zilog LINT
4 Zilog 4
LINT Zilog LINT
6. Function Values
Sometimes functions return values which are never used;
sometimes programs incorrectly use function "values" which
have never been returned. ~ addresses this problem in a
number of ways.
Locally, within a function definition, the appearance of
both
return( .e.xRI. );
and
return .,
statements is cause for alarm; lint will give the message
function .n.suns;, contains returnee) and return
The most serious difficulty with this is detecting when a
function return is implied by flow of control reaching the
end of the function. This can be seen with a simple exam-
ple:
f ( a ) {
if ( a ) return ( 3 );
9 ();
}
5 Zilog 5
LINT zilog LINT
7. Type Checking
Lint enforces the type checking rules of C more strictly
than the compilers do. The additional checking is in four
major areas: across certain binary operators and implied
assignments, at the structure selection operators, between
the definition and uses of functions, and in the use of
enumerations.
There are a number of operators which have an implied
balancing between types of the operands. The assignment,
conditional ( ?: ), and relational operators have this pro-
perty; the argument of a return statement, and expressions
used in initialization also suffer similar conversions. In
these operations, char, short, int, long, unsigned, float,
and double types may be freely intermixed. The types of
pointers must agree exactly, except that arrays of A's can,
of course, be intermixed with pOinters to Zls.
The type checking rules also require that, in structure
references, the left operand of the -) be a pointer to
structure, the left operand of the. be a structure, and
the right operand of these operators be a member of the
structure implied by the left operand. Similar checking is
done for references to unions.
Strict rules apply to function argument and return value
matching. The types float and double may be freely matched,
as may the types char, short, int, and unsigned. Also,
pointers can be matched with the associated arrays. Aside
from this, all actual arguments must agree in type with
their declared counterparts.
With enumerations, checks are made that enumeration vari-
ables or members are not mixed with other types, or other
enumerations, and that the only operations applied are =,
initialization, ==, 1=, and function arguments and return
values.
8. Type Casts
The type cast feature in C was introduced largely as an aid
to producing more portable programs. Consider the assign-
ment
p =I ;
6 Zilog 6
LINT LINT
7 Zilog 7
LINT Zilog LINT
the statement
*p++ ;
the * does nothing; this provokes the message "null
effect" from lint. The program fragment
unsigned x ;
if( x < 0 )
is clearly somewhat strange; the test will never succeed.
Similarly, the test
if( x > 0 ...
is equivalent to
if( x 1= 0 )
which may not be the intended action. Lint will say
"degenerate unsigned comparison" in these cases. If one
says
if( I 1= 0 ) ••.•
lint will report "constant in conditional context' " since
the comparison of I with 0 gives a constant result.
Another construction detected by lint involves operator pre-
cedence. Bugs. which arise from misunderstandings about the
precedence of operators can be accentuated by spacing and
formatting, making such bugs extremely hard to find. For
example, the statements
if{ x&077 == 0 )
or
x«2 + 40
8 Zilog 8
LINT Zilog LINT
9 Zilog 9
LINT Zilog LINT
15. Implementation
Lint consists of two programs and a driver. The first pro-
gram is a version of the Portable C Compiler which is the
basis of the 58000 and several other C compilers. This com-
piler does lexical and syntax analysis on the input text,
constructs and maintains symbol tables, and builds trees for
expressions. Instead of writing an intermediate file which
is passed to a code generator, as the other compilers do,
l.in.t. produces an intermediate file which consists of lines
of ascii text. Each line contains an external variable
name, an encoding of the context in which it was seen (use,
definition, declaration, etc.), a type specifier, and a
source file name and line number. The information about
variables local to a function or file is collected by
accessing the symbol table, and examining the expression
10 Zilog 10
LINT Zilog LINT
trees.
Comments about local problems are produced as detected. The
information about external names is collected onto an inter-
mediate file. After all the source files and library
descriptions have been collected, the intermediate file is
sorted to bring all information collected about a given
external name together. The second, rather small, program
then reads the lines from the intermediate file and compares
all of the definitions, declarations, and uses for con-
sistency.
The driver controls this process, and is also responsible
for making the options available to both passes of lint.
16. Portability
C is used in many installations, in part, to write system
code for the host operating system. This means that the
implementation of C tends to follow local conventions rather
than adhere strictly to anyone operating system's conven-
tions. Despite these differences, many C programs have been
successfully moved to various systems with little effort.
This section describes some of the differences among imple-
mentations, . and discusses the lint features which encourage
por tabil i ty •
Uninitialized external variables are treated differently in
different implementations of C. Suppose two files both con-
tain a declaration without initialization, such as
int a ~
11 Zilog 11
LINT Zilog LINT
12 Zilog 12
LINT Zilog LINT
/* NOSTRICT */
can be used; the situation reverts to the previous default
after the next expression. The -2 flag can be turned on for
one function by the directive
/* ARGSOSED */
Complaints about variable number of arguments in calls to a
function can be turned off by the directive
/* VARARGS */
preceding the function definition. In some cases, it is
desirable to check the first several arguments, and leave
the later arguments unchecked. This can be done by follow-
ing the VARARGS keyword immediately with a digit giving the
number of arguments which should be checked; thus,
/* VARARGS2 */
will cause the first two arguments to be checked, the others
unchecked. Finally, the directive
13 Zilog 13
LINT Zilog LINT
/* LINTLIBRARY */
at the head of a file identifies this file as a library
declaration file; this topic is worth a section by itself.
18. Library Declaration Files
Lint accepts certain library directives, such as
-ly
and tests the source files for compatibility with these
libraries. This is done by accessing library description
files whose names are constructed from the library direc-
tives. These files all begin with the directive
/* LINTLIBRARY */
which is followed by a series of dummy function definitions.
The critical parts of these definitions are the declaration
of the function return type, whether the dummy function
returns a value, and the number and types of arguments to
the function. The VARARGS and ARGSUSED directives can be
used to specify features of the library functions.
Lint library files are processed almost exactly like ordi-
nary source files. The only difference is that functions
which are defined on a library file, but are not used on a
source file, draw no complaints. Lint does not simula~e a
full library search algorithm, and complains if the source
files contain a redefinition of a library routine (this is a
feature!).
By default, lint checks the programs it is given against a
standard library file, which contains descriptions of the
programs which are normally loaded when a C program is run.
When the -R flag is in effect, another file is checked con-
taining descriptions of the standard I/O library routines
which are expected to be portable across various machines.
The -n flag can be used to suppress all library checking.
19. Bugs, etc.
A number of lint features remain to be further developed.
The checking of structures and arrays is rather inadequate;
size incompatibilities go unchecked, and no attempt is made
to match up structure and union declarations across files.
Some stricter checking of the use of the typedef is clearly
desirable, but what checking is appropriate, and how to
carry it out, is still to be determined.
Lint shares the preprocessor with the C compiler. At some
point it may be appropriate for a special version of the
14 Zilog 14
LINT Zilog LINT
IS Zilog 15
LINT Zilog LINT
16 Zilog 16
MAKE Zilog MAKE
MAKE *
.
1 Zilog 1
.
MAKE Zilog MAKE
PREFACE
2 Zilog 2
.
MAKE Zilog MAKE
TABLE OF CONTENTS
3 Zilog 3
MAKE Zilog MAKE
SECTION 1
INTRODUCTION
4 Zilog 4
.
MAKE Zilog MAKE
SECTION 2
BASIC FEATURES
5 Zilog 5
MAKE Zilog MAKE
6 Zilog 6
MAKE Zilog MAKE
The command
make
loads the three object files with the ~ library. The com-
mand
make nLIBES= -1m -lc n
loads them with both the math (-1m) and the standard (-lc)
libraries, since macro definitions on the command line over-
ride definitions in the description. (In ZEUS commands, it
is necessary to enclose arguments with embedded blanks in
quotes. )
7 Zilog 7
MAKE Zilog MAKE
8 Zilog 8
MAKE Zilog MAKE
9 Zilog 9
MAKE . Zilog MAKE
10 Zilog 10
MAKE Zilog MAKE
SECTION 3
COMMAND USAGE
3.1 Arguments
The ~ command takes four kinds of arguments: macro defin-
itions, flags, description file names, and target file
names.
make [ flags] [ macro definitions ] [ targets
The following summary of the operation of the command
explains how these arguments are interpreted.
First, all macro definition arguments (arguments with embed-
ded equal signs) are analyzed and the assignments made.
Command-line macros override corresponding definitions found
in the description files.
Next, the flag arguments are examined. The permissible
flags are:
.-d Debug mode. Print out detailed information on files
and times examined.
-f Description file name. The next argument is assumed to
be the name of a description file. The file name dash
(-) denotes the· standard input. If there are no -fl
arguments, the file named makefile (or Makefile) in the
current directory is read. The contents of the
description files override the built-in rules if they
are present.
-i Ignore error codes returned by invoked commands. This
mode is entered if the target name .IGNORE appears in
the description file.
-n No execute mode. Print commands, but do not execute
them. Even lines beginning with an @ sign are printed.
-p Print out the complete set of macro definitions and
target descriptions.
-q Question. The ~ command returns a zero or nonzero
status code depending on whether the target file is or
is not up to date.
-r Do not use the built-in rules.
·f
11 Zilog 11
MAKE Zilog MAKE
12 Zilog 12
MAKE Zilog MAKE
13 Zilog 13
MAKE Zil.og MAKE
PLZ=plz
PFLAGS=
.c.o :
$(CC) $ (CFLAGS) -c $<
.p.o :
$(PLZ) $ (PFLAGS) -c $<
.s.o :
$(AS) -0 $@ $<
.y.o :
$ (YACC) $ (YFLAGS) $<
$(CC) $ (CFLAGS) -c y.tab.c
rm y.tab.c
mv y.tab.o $@
.y.c :
$ (YACC) $ (YFLAGS) $<
mv y.tab.o $@
P = Ipr
FILES = Makefile version.c defs main.c doname.c misc.c
files.c dosys.c gram.y
OBJECTS = version.o main.o doname.o misc.o files.o
dosys.o gram.o
LIBES= -IS
LINT = lint -p
CFLAGS = -0
make: $ (OBJECTS)
cc $ (CFLAGS) $ (OBJECTS) $(LIBES) -0 make
size make
$(OBJECTS): defs
cleanup:
-rm *.0 gram.c
-du
install:
@size make /usr/bin/make
cp make /usr/bin/make ; rm make
14 Zilog 14
MAKE Zilog MAKE
15 Zilog 15
MAKE Zilog MAKE
the R macro:
"
make print "P = opr _spa
or
make print "p= cat >zapn
16 Zilog 16
MS Zilog l-IS
1 Zilog 1
MS Zilog MS
PREFACE
2 Zilog 2
MS Zi10g MS
TABLE OF CONTENTS
3 Zi10g 3
MS zilog MS
SECTION 1
PREPARING THE FILE
1.1 Text
Type normally, except that instead of indenting for para-
graphs, place the line
.PP
before each paragraph. This produces indenting after an
extra line space.
Alternatively, the command .LP produces a left-aligned
(block) paragraph. The paragraph spacing can be changed
(Section 1.16).
4 Zilog 4
MS Zilog MS
NOTE
Do not begin a document with a line of text. Some
-ms command must precede any text input. When in
doubt, use .LP to get proper initialization. The
commands .PP, .LP, .TL, .SH, and .NH are also
allowed.
5 Zilog 5
MS Zilog MS
6 Zilog 6
~lS Zilog MS
.NH
. Erie-Lackawanna
.NH 2
Morris and Essex Division
.NH 3
Gladstone Branch
.NH 3
Montclair Branch
.NH 2
Boonton Line
generates:
2. Erie-Lackawanna
7 Zilog 7
MS Zilog 1\1S
8 Zilog 8
11S Zilog
.IP 1.
Customer Corporation
.RS
.IP 1.1
Hurray Hill
.IP 1.2
Holmdel
.IF 1.3
Hhippany
.RS
.IP 1.3.1
r·~adison
.RE
.IP 1.4
Chester
.RE
.LP
resul ts in
1. Customer Corporation
1.2 Holmdel
1.3 Nhippany
1.3.1 Hac1ison
1.4 Chester
Example~. Right Indentation
P~llof these variations on .LP leave the right margin
untouched. Sometimes, for purposes such as setting off a
quotation, a paragraph indented on both right and left is
required.
A single paragraph like this is obtained
by preceding it \dth .QP. tiore compli-
cated material (several paragraphs) is
bracketed with .QS and .QE.
1.8 Emphasis
To produce italics on the typesetter or underlining on the
terminal, use
•I
as much text as you want
9 Zilog 9
MS Zilog MS
1.9 Footnotes
Material placed between lines with the commands .FS for
footnote and .FE for footnote end is collected and placed at
the bottom of the current page after an asterisk (*). By
default, footnotes are II/12th the length of normal text,
but this can be changed using the FL register (Section
1.16).
10 Zilog 10
MS Zilog MS
.DS
table lines, like the
examples here, are placed
between .DS and .DE
.DE
By default, lines between .DS and .DE are- indented and
left-adjusted. It is also possible to center lines, or
retain the left margin. Lines bracketed by .DS C and .DE
.commands are centered and not rearranged. Lines bracketed
by .DS Land .DE are left-adjusted, not indented, and not
rearranged. The command .DS is equivalent to .DS I, which
indents and left-adjusts. For example,
these lines were preceded
by .DS C and followed by
a .OE command;
whereas
These lines were preceded
by .DS L and followed by
a .DE command.
There is also a variant, .DS B, that makes the display into
a left-adjusted block of text, then centers that entire
block.
Normally, a display is kept on one page. To produce a long
display split across page boundaries, use .CD, .LD, or .ID
in place of the commands .DS C, .OS L, or .OS I, respec-
tively. An extra argument to the .DS I or .DS command
specifies the amount to indent. There is no command to
right-adjust lines.
11 Zilog 11
MS Zilog MS
1.14 Date
By default, documents produced on computer terminals have
the date at the bottom of each page, and documents produced
on the typesetter do not. To force the date, use the .DA
command. To force no date, use the .ND command. To force a
fixed date, enter the date after the .DA command; for exam-
ple,
.DA July 4, 1776
The command ".ND May 8, 1945" in .RP format places the
specified date on the cover sheet and nowhere else. Place
this line before the title.
12 Zilog 12
MS Zilog MS
1.16 Registers
Certain of the registers used by -ms can be altered to
change default settings using commands beginning with .nr.
For example,
.nr PS 9
makes the default point size 9 point. If the effect is
needed immediately, use the normal troff command in addition
to changing the number register.
1.17 Accents
To simplify typing certain foreign words, strings represent-
ing common accent marks are defined for use on photocomposi-
tion systems and terminals on which strikeover characters
have been defined.
13 Zilog 13
MS Zilog MS
Input Output
Character with:
\*'e accute accent
\*'e grave accent
\*:u umlaut (diaeresis)
\*"e circumflex
\*-a tilde
\*Ce hacek (wedge)
\*,c cedilla
14 Zilog 14
MS Zilog MS
SECTION 2
PRINTING THE DOCUMENT
15 Zilog 15
MS Zilog MS
SECTION 3
USING ADVANCED FORMAT OPTIONS
3.2 Tables
The macros .TS and .TE are defined to separate tables from
text with white space. A very long table with a heading can
be broken across pages by beginning it with .TS H instead of
.TS, and placing the line .TH in the table data to repeat
the heading. If the table has no heading repeated from page
to page, use the ordinary .TS and .TE macros.
16 Zilog 16
MS Zilog MS
APPENDIX A
LIST OF COMMANDS
17 Zilog 17
\
~
te~t
,
i?i?, Li?
•••
- \\
).9
MS Zilog MS
Register Names
The following register names are used by -rns internally.
Independent use of these names in one's own macros may pro-
duce incorrect output. No lowercase letters are used in any
-ms internal name.
, AI CS EM I LB OK RP TL
... AU CT EN Il LD PP RO TM
\ B D I2 LG PT RS
EO TO
BG DA EZ I3 LP PY RT TS
BT DE FA I4 ME OF SO TT
, C DS FE IS MF R Sl UL
lC Cl DW FJ ID MH Rl S2 WB
2C C2 DY FK IE MN R2 SG WH
Al CA El FN 1M MO R3 S8 WT
A2 CB E2 FO IP MR R4 SM XD
A3 CC E3 FO IZ ND Rs SN XF
A4 CD E4 FS KE NH RC SY XK
AS CF Es FV KF NL RE TA
AB CH EE FY KO NP RF TE
AE CM EL 80 KS OD RH TH
18 Zilog 18
NROFF/TROFF Zilog NROFF/TROFF
1 Zilog 1
'" .
NROFF/TROFF Zilog NROFF/TROFF
PREFACE
NOTE
The version of troff on ZEUS produces output for a
Graphic Systems Inc. C/A/T phototypesetter. This
device is not presently supported by ZEUS. Since
the device is not present, it will always appear
to be busy to troff.
2 Zilog 2
NROFF/TROFF Zilog NROFF/TROFF
TABLE OF CONTENTS
3 Zilog 3
NROFF/TROFF Zilog - NROFF/TROFF
4 Zilog 4
NROFF/TROFF Zilog NROFF/TROFF
5 Zilog 5
NROFF/TROFF Zilog NROFF/TROFF
SECTION 1
BASIC INFORMATION
1.1 Introduction
Nroff and troff are text processors under the ZEUS Time-
Sharing System that format text for typewriter-like termi-
nals and for phototypesetters, respectively. They accept
lines of text interspersed with lines of format control
information and format the text into a printable, paginated
document with a user-designed style. Nroff and troff offer
great freedom in document styling, including:
$ Arbitrarily styled headers and footers
$ Arbitrarily styled footnotes
$ Multiple automatic sequence numbering for para-
graphs, sections, etc.
$ Multiple column output
$ . Dynamic font and pOint-Size control
$ Arbitrary horizontal and vertical local motions at
any point
$ A family of automatic overstriking, bracket con-
struction, and line drawing functions
Nroff and troff are compatible with each other; it is pOSSi-
ble to prepare input acceptable to both. Conditional input
is provided that enables the user to embed input destined
for either program. Nroff can prepare output directly for a
variety of terminal types and is capable of utilizing the
full resolution of each terminal.
1.2 Usage
The general form of invoking nroff or troff at ZEUS command
level is
nroff options files (or troff options files)
where options represents any of a number of option arguments
and files represents the list of files containing th~ docu-
ment to be formatted. An argument conSisting of a single
minus (-) is taken to be a file riame corresponding to the
6 Zilog 6
NROFF/TROFF Zilog NROFF/TROFF
Option Effect
-o.l.i.a.t Print only pages whose page numbers appear in
a list that consists of comma-separated
numbers and number ranges. A number range
has the form N-M and means pages N through M:
an initial -N means from the beginning to
page N: a final N- means from N to the end.
-nN Number first generated page N.
-sN Stop every N pages. Nroff halts prior to
every N pages (default N=l) to allow paper
loading or changing, and resumes upon receipt
of a new line. Troff stops the photo-
typesetter every N pages, produces a trailer
to allow changing cassettes, and resumes
after the phototypesetter START button is
pressed.
-m.ruun.e. Prepends the macro file /usr/lib/tmac.nsm& to
the input files •.
-r..a.N Register ~ (one-character) is set to N.
-i Read standard input after the input files are
exhausted.
-q Invoke the simultaneous input-output mode of
the rd request.
NROFF ONLY
-T.n.run.e Specifies the name of the output terminal
type. Currently defined names are:
37 for the Model 37 Teletypewriter
TN300 (default) for the GE TermiNet 300 (or
any terminal without half-line capabilities),
300S for the DASI-300S,
300 for the DASI-300,
450 for the DASI-450 (Diablo Hyterm).
-e Produce equally-spaced words in adjusted
lines, using full terminal resolution.
7 Zilog 7
NROFF/TROFF Zilog NROFF/TROFF
TROFF ONLY
-t Direct output to the standard output instead
of the phototypesetter.
-f Refrain from feeding out paper and stopping
phototypesetter at the end of the run.
-b Troff reports whether the phototypesetter 1s
busy or available. No text processing is
done. (See NOTE in preface.)
-a Send a printable (ASCII) approximation of the
results to the standard output.
-pN Print all characters in point size N, while
retaining all prescribed spacings and
motions, to reduce phototypesetter elasped
time.
Each option is invoked as a separate argument; for example,
nroff -o~,a-~ -TlQQS -m~ filel file2
requests formatting of pages 4, 8, 9, and 10 of a document
contained in the files named filel and file2, specifies the
output terminal as a DASI-300S, and invokes the macro pack-
age ~.
8 Zilog 8
NROFF/TROFF Zilog NROFF/TROFF
in \n(xx.
9 Zilog 9
NROFF/TROFF Zilog NROFF/TROFF
10 Zilog 10
NROFF/TROFF Zilog NROFF/TROFF
SECTION 2
FONT AND CHARACTER SIZE CONTROL
2.2 Fonts
The default mounted fonts are Times Roman (R), Times Italic
(I), Times Bold (B), and the Special Mathematical Font (S)
on physical typesetter positions 1, 2, 3, and 4, respec-
tively. The current font can be changed (among the mounted
fonts) by use of the ft request, or by embedding at any
desired point either \fx, \f(xx, or \fN, where x or xx is
the name of a mounted font and N is a numerical font posi-
tion. It is not necessary to change to the special font;
characters on that font are automatically handled. A
11 Zilog 11
NROFF/TROFF Zilog NROFF/TROFF
12 Zilog 12
NROFF/TROFF Zilog NROFF/TROFF
Request Initial If No
Form Value Argument
• cs F N M off
Explanation: Constant character space (width) mode is set on
for font F (if mounted); the width of every character is
taken to be N/36 ems. If M is absent, the em is that of the
character's pOint size; if M is given, the em is M-points.
All affected characters are centered in this space, includ-
ing those with an actual width larger than this space. Spe-
cial Font· characters occurring while the current font is F
are also so treated. If N is absent, the mode is turned
off. The mode must be still or again in effect when the
characters are physically printed. Ignored in nroff.
Request Initial If No
Form Value Argument
.bd F N off
Explanation: The characters in font F are artificially made
boldface by printing each one twice, separated by NA-l basic
units. A reasonable value for N is 3 when the character
size is in the vicinity of 10 points. If N is missing the
bold mode is turned off. The mode must be still or again in
effect when the characters are physically printed. Ignored
in nroff.
Request Initial If No
Form Value Argument
• bd S F N off
Explanation: The characters in the Special Font are made
boldface whenever the current font is F. The mode must be
still or again in effect when the characters are physically
printed.
Request Initial If No
Form Value Argument
.ft F Roman previous
..
Explanation: Font changed to F. Alternatively, imbed \fF.
The font name P is reserved to mean the previous font.
Relevant parameters are a part of the current environment.
Request Initial If No
Form Value Argument
( .fp N F R,I,B,S ignored
13 Zilog 13
NROFF/TROFF Zilog NROFF/TROFF
\" / i
14 ~ilog 14
NROFF/TROFF Zilog NROFF/TROFF
SECTION 3
PAGE CONTROL
15 Zilog 15
NROFF/TROFF Zilog NROFF/TROFF
16 Zilog 16
NROFF/TROFF Zi10g NROFF/TROFF
17 Zilog 17
NROFF/TROFF Zilog NROFF/TROFF
SECTION 4
TEXT FILLING, ADJUSTING, AND CENTERING
18 Zilog 18
, ,
19 Zilog 19
NROFF/TROFF Zilog NROFF/TROFF
20 Zilog 20
NROFF/TROFF Zilog NROFF/TROFF
,
I SECTION 5
VERTICAL SPACING
21 Zilog 21
, .
NROFF/TROFF Zilog NROFF/TROFF
22 Zilog 22
NROFF/TROFF Zilog NROFF/TROFF
Request Initial If No
Form Value Argument
.ns space
Explanation: No-space mode turned on. When on, the no-space
mode inhibits sp requests and bp requests without a next
page number. The no-space mode is turned off when a line of
output occurs, or with rs. Relevant parameters are associ-
ated with the current diversion level.
Request Initial If No
Form Value Argument
.rs space
Explanation: Restore spacing. The no-space mode is turned
off. Relevant parameters are associated with the current
diversion level.
Request Initial If No
Form -Value Argument
Blank text line.
Explanation: Causes a break and output of a blank line
exactly like sp 1.
23 Zilog 23
NROFF/TROFF Zilog NROFF/TROFF
/'
24 Zilog 24
NROFF/TROFF Zilog NROFF/TROFF
SECTION 6
MACROS, STRINGS, DIVERSION, AND POSITION TRAPS
25 Zilog 25
NROFF/TROFF Zilog NROFF/TROFF
6.3 Arguments
When a macro is invoked by name, the remainder of the line
is taken to contain up to nine arguments. The argument
separator is the space character, and arguments can be sur-
rounded by double quotes to permit embedded space chaxac-
terse Pairs of double quotes can be embedded in double
quoted arguments to represent one double quote. If the
desired arguments do not fit on a line, a concealed new line
can be used to continue on the next line.
When a macro is invoked, the input level is pushed down and
any arguments available at the previous level become una-
vailable until the macro is completely read and the previous
level is restored. A macro's own arguments can be interpo-
lated at any pOint within the macro with \$N, which interpo-
lates the Nth argument (1~IN~9). If an invoked argument
does not exist, a null string results. For example, the
macro xx is defined by
.de xx \"begin definition
Today is \\$1 the \\$2.
\"end definition
and called by
.xx Monday 14th
to produce the text
Today is Monday the 14th.
Note that the \$ is concealed in the definition with a
prepended \. The number of currently available arguments is
in the .$ register.
No arguments are available at the top (nonmacro) level in
this implementation. Because string referencing is imple-
mented as an input-level push down, no arguments are avail-
able from within a string. No arguments are available
within a trap-invoked macro.
Arguments are copied in copy mode onto a stack where they
are available for reference. The mechanism does not allow
an argument to contain a direct reference to a long string
that is interpolated at copy time. It is advisable to
26 Zilog 26
NROFF/TROFF Zilog NROFF/TROFF
6.4 Diversions
Processed output can be diverted into a macro for purposes
such as footnote processing (Section 21.5) or determining
the horizontal and vertical size of some text for condi-
tional changing of pages or columns. A single diversion
trap can be set at a specified vertical position. The
number registers dn and dl contain the vertical and horizon-
tal size of the most recently ended diversion. Processed
text that is diverted into a macro retains the vertical size
of each of its lines when reread in nofill mode, regardless
of the current V. Constant-spaced (cs) or bold (bd) text
that is diverted can be reread correctly only if these modes
are again or still in effect at reread time. One way to do
this is to embed in the diversion the appropriate cs or bd
requests with the transparent mechanism described in Section
9.6.
Diversions can be nested, and certain parameters and regis-
ters are associated with the current diversion level. The
top nondiversion level can be thought of as the Oth diver-
sion level. These are the diversion trap and associated
macro, no-space mode, the internally-saved marked place (mk
and rt), the current vertical place (.d register), the
current text base-line (.h register), and the c.urrent diver-
sion name (.z register).
6.5 Traps
Three types of trap mechanisms are available: page traps, a
diversion trap,. and an input-line-count trap. Macro-
invocation traps can be planted using wh at any page posi-
tion including the top. This trap position is changed using
ch. Trap positions at or below the bottom of the page have
no effect unless or until moved within the page or rendered
effective by an increase in page length. Two traps can be
planted at the same position only by first planting them at
different positions and then moving one of the traps; the
first planted trap conceals the second unless and until the
first one is moved (Appendix). If the first one is moved
back, it again conceals the second trap. The macro associ-
ated with a page trap is automatically invoked when a line
of text is output whose vertical size reaches or sweeps past
the trap position. Reaching the bottom of a page springs
the top-of-page trap, if any, provided there is a next page.
The distance to the next trap position is available in the
.t register; if there are no traps between the current
27 Zilog 27
NROFF/TROFF Zilog NROFF/TROFF
28 Zilog 28
NROFF/TROFF Zilog NROFF/TROFF
( Request Initial If No
Form Value Argument
.rm xx ignored
Explanation: Remove request, macro, or string. The name xx
is removed from the name list and any related storage space
is freed. Subsequent references have no effect.
Request Initial If No
Form Value Argument
.rn xx yy - ignored
Explanation: Rename request, macro, or string xx to yy. If
yy exists, it is first removed.
Request Initial If No
Form Value Argument
.di xx end
Explanation: Divert output to macro xx. Normal text pro-
cessing occurs during diversion except that page offsetting
is not done. The diversion ends when the request di or da
is encountered without an argument; extraneous requests of
this type should not appear when nested diversions are being
used. Mode or relevant parameters are associated with the
current diversion level.
Request Initial If No
Form Value Argument
.da xx end
Explanation: Divert, appending· to xx (append version of di).
Mode or relevant parameters are associated with the current
diversion level.
Request Initial If No
Form Value Argument
.wh N xx
Explanation: Install a trap to invoke xx at page position; a
negative N is interpreted with respect to the page bottom.
Any macro previously planted at N is replaced by xx. A zero
N refers to the top of a page. In the absence of xx, the
first found trap at N, if any, is removed. The default
scale indicator is v (ignored if not specified).
29 Zilog 29
NROFF/TROFF Zilog NROFF/TROFF
Request Initial If No
Form Value Argument
.ch xx N
Explanation: Change the trap position for macro xx to be N.
In the absence of N, the trap, if any, is removed. The
default scale indicator is v (ignored if not specified).
Request Initial If No
Form Value Argument
.dt N xx off
Explanation: Install a diversion trap at position N in the
current diversion to invoke macro xx. Another dt redefines
the diversion trap. If no arguments are given, the diver-
sion trap is removed. Mode or relevant parameters are asso-
ciated with the current diversion level. The default scale
indicator is v (ignored if not specified).
Request Initial If No
Form Value Argument
.it N xx off
Explanation: Set an input-line-count trap to invoke the
macro xx after N lines of text input have been read (control
or request lines do not count). The text can be in-line
text or text interpolated by in-line or trap-invoked macros.
Relevant parameters are a part of the current environment.
Request Initial If No
Form Value Argument
.em xx none none
Explanation: The macro xx is invoked when all input has
ended. The effect is the same as if the contents of xx had
been at the end of the last file processed.
30 Zilog 30
NROFF/TROFF Zilog NROFF/TROFF
SECTION 7
NUMBER REGISTERS
31 Zilog 31
NROFF/TROFF Zilog NROFF/TROFF
Request Initial If No
Form Value Argument
.af R c arabic
Explanation: Assign format c to register R. The available
formats are:
Numbering
Format Sequence
1 0,1,2,3,4,5, •••
001 000,001,002,003,004,005, •••
i O,i,ii,iii,iv,v, •••
I O,I,II,III,IV,V, •••
a O,a,b,c, ••• ,z,aa,ab, ••• ,zz,aaa, •••
A O,A,B,C, ••• ,Z,AA,AB, ••• ,ZZ,AAA, •••
.
An arabic format having N digits specifies a field width of
N digits (second example above). The read-only registers
and the width function are always arabic.
Request Initial If No
Form Value Argument
.rr R ignored
Explanation: Remove register R. If many registers are being
created dynamically, it is necessary to remove unused regis-
ters to recaptu~e internal storage space for newer regis-
ters.
32 Zilog 32
NROFF/TROFF Zilog NROFF/TROFF
/'
SECTION 8
TABS, LEADERS, AND FIELDS
8.2 Fields
A field is contained between a pair of field delimiter char-
acters, and consists of substrings separated by padding
indicator characters. The field length is the distance on
the input line from the position where the field begins to
( the next tab stop. The difference between the total length
of all the substrings and the field length is incorporated
33 Zilog 33
NROFF/TROFF Zilog NROFF/TROFF
/'
-<;;-,
34 ZiJ,og 34
NROFF/TROFF Zilog NROFF/TROFF
SECTION 9
INPUT/OUTPUT CONVENTIONS AND CHARACTER TRANSLATIONS
9.2 Ligatures
Five ligatures are available in the current troff character
set: fi, fl, ff, ffi, and ffl. They are input by \(fi,
\(fl, \(ff, \(Fi, and \(Fl respectively. The ligature mode
is normally on in troff, and automatically invokes ligatures
during input.
Request Initial If No
Form Value Argument
.lg N off; on on
35 Zilog 35
NROFF/TROFF Zilog NROFF/TROFF
36 Zilog 36
NROFF/TROFF Zilog NROFF/TROFF
37 Zilog 37
NROFF/TROFF Zilog NROFF/TROFF
38 Zilog 38
NROFF/TROFF Zilog NROFF/TROFF
SECTION 10
LOCAL MOTIONS AND THE WIDTH FUNCTION
39 Zilog 39
NROFF/TROFF Zilog NROFF/TROFF
40 Zilog 40
NROFF/TROFF Zilog NROFF/TROFF
SECTION 11
OVERSTRIKE, LINE-DRAWING, AND ZERO-WIDTH FUNCTIONS
11.1 Overstriking
Automatically centered overstriking of up to nine characters
is provided by the overstrike function (\0 "string"). The
characters in string are overprinted with centers aligned~
the total width is that of the widest character. The string
must not contain local vertical motion. For example,
\o'e\" produces ~.
such that
.us "underlined words"
yields
underlined words •
The function \L'Nc' draws a vertical line consisting of the
(optional) character c stacked vertically apart lem (1 line
in nroff), with the first two characters overlapped, if
necessary, to form a continuous line. The default character
is the box rule / (\(br); the other suitable character is
the bold vertical / (\(bv). The line is begun without any
initial motion relative to the current base line. A posi-
tive N specifies a line drawn downward and a negative N
41 Zilog 41
NROFF/TROFF Zilog NROFF/TROFF
42 Zilog 42
NROFF/TROFF Zilog NROFF/TROFF
SECTION 12
HYPHENATION
43 Zilog 43
NROFF/TROFF Zilog NROFF/TROFF
Request Initial If No
Form Value Argument
.hw wordl ••• ignored
Explan~tion: Specify hyphenation points in words with embed-
ded m~nus signs. Versions of a word with terminal s are
implied; for example, dig-it implies dig-its. This list is
examined initially and after each suffix stripping. The
space available is small--about 128 characters.
44 Zilog 44
NROFF/TROFF Zilog NROFF/TROFF
SECTION 13
THREE-PART TITLES
45 Zilog 45
NROFF/TROFF Zilog NROFF/TROFF
5ECTION 14
OUTPUT LINE NUMBERING
46 Zilog 46
NROFF/TROFF Zilog NROFF/TROFF
SECTION 15
CONDITIONAL ACCEPTANCE OF INPUT
47 Zilog 47
NROFF/TROFF Zilog NROFF/TROFF
Request
Form
.if ' s tringl ' string2'anything
Explanation: If stringl is identical to string2, accept ~
thing.
Request
Form
.if !'stringl'string2 I anything
Explanation: If stringl is not identical to string2, accept
anything.
Request
Form
.ie c anything
Explanation: If portion of if-else; all above forms (like
if) • The default scale indicator is u (ignored if not
specified).
Request
Form
.el anything
Explanation: Else portion of if-else.
The built-in condition names are:
Condition
Name True If
o Current page number is odd
e Current page number is even
t Formatter is troff
n Formatter is nroff
If the condition c is true, or if the number N is greater
than zero, or if the strings compare identically (including
motions and character size and font), anything ~s accepted
as input. If a ! precedes the condition, number, or string
comparison, the sense of the acceptance is rev~rsed.
Any spaces between the condition and the beginning of ~
thing are skipped over. The anything is either a single
input line (for example, text or macro) or a number of input
lines. In the multiline case, the first line must begin
48 Zilog 48
NROFF /TROFF- Zilog NROFF/TROFF
with a left delimiter (\{) and the last line must end with a
right delimiter (\}).
The request ie (if-else) is identical to if, except that
the, acceptance state is remembered. A subsequent and
matching el (else) request then uses the reverse sense of
that state. iel-Iel pairs can be nested.
Some examples are:
.if e .tl 'Even Page %'"
which outputs a title if the page number is even; and
.ie \n%>l \{\
'sp O.Si
• tl 'Page %' I ,
'Sp Il.2i \}
.el .spI2.Si
which treats page 1 differently from other pages.
49 Zilog 49
NROFF/TROFF Zilog NROFF/TROFF
SECTION 16
ENVIRONMENT SWITCHING
50 Zilog 50
NROFF/TROFF Zilog - NROFF/TROFF
SECTION 17
INSERTIONS FROM THE STANDARD INPUT
51 Zilog 51
NROFF/TROFF Zilog NROFF/TROFF
SECTION 18
INPUT/OUTPUT FILE SWITCHING
Request Initial If No
Form Value Argument
.so filename
Explanation: Switch source file. The top input (file read-
ing) level is switched to filename. A ~ encountered in a
macro does not take effect until the input level returns to
the file level. When the new file ends, input is again
taken from the original file. ~'s can be nested.
Request Initial If No
Form Value Argument
.nx filename end-of-file
Explanation: Next file is filename. The current file is
considered ended, and the input is immediately switched to
filename.
Request Initial If No
Form Value Argument
.pi program
Explanation: Pipe output to program (nroff only) • This
request must occur before any printing occurs. No arguments
are transmitted to program.
52 Zilog 52
NROFF/TROFF Zilog NROFF/TROFF
SECTION 19
MISCELLANEOUS
Request Initial If No
Form Value Argument
.mc c N off
Explanation: Specifies that a margin character c appear a
distance N to the right of the right margin after each
nonempty text line (except those produced by tl). If the
output line is too long (as can happen in nofill mode) the
character is appended to the line. If N is not given, the
previous N is used. The initial N is 0.2 inches in nroff
and 1 em in troff. Relevant parameters are a part of the
current environment. The default scale indicator is m
(ignored if not specified).
Request Initial If No
Form Value Argument
.tm string newline
Explanation: After skipping initial blanks, string (rest of
the line) is read in copy mode and written on the user's
terminal.
Request Initial If No
Form Value Argument
.ig yy .yy= ••
Explanation: Ignor~ input lines. Ig behaves like de except
that the input 1S discarded. The input is read in copy
mode, and any auto-incremented registers are affected.
Request Initial If No
Form Value Argument
.pm t all
Explanation: Print macros. The names and sizes of all of
the defined macros and strings are printed on the user's
terminal; if t is given, only the total of the sizes is
printed. The size is given in blocks of 128 characters. ;
Request Initial If No
Form Value Argument
.fl
53 Zilog 53
NROFF/TROFF Zilog NROFF/TROFF
54 Zilog 54
NROFF/TROFF Zilog NROFF/TROFF
SECTION 20
OUTPUT.AND ERROR MESSAGES
The output from tm, pm, and the prompt from rd, as well as
various error messages are written onto the standard message
output. The standard message output is different from the
standard output, where nroff formatted output goes. By
default, both are written onto the user's terminal, but they
can be independently redirected.
Various error conditions can occur during the operation of
nroff and troff. Certain less serious errors that have only
local impact do not cause processing to terminate. Two
examples are word overflow, caused by a word that is too
large to fit into the word buffer (in fill mode), and line
overflow, caused by an output line that grows too large to
fit in the line buffer; in both cases, a message is printed,
the excess is discarded, and the affected word or line is
marked at the point of truncation with a * in nroff and a <=
in troff. Processing continues, if possible, since output
useful for debugging may be produced. If a serious error
occurs, processing terminates, and an appropriate message is
printed. Examples are the inability to create, read, or
write files, and the exceeding of certain internal limits
that make future output unlikely to be useful.
55 Zilog 55
NROFF/TROFF Zilog NROFF/TROFF
SECTION 21
EXAMPLES
21.1 Introduction
It is almost always necessary to prepare at least a small
set of macro definitions to describe most documents. Such
common formatting needs as page margins and footnotes are
deliberately not built into nroff and troff. Instead, the
macro and string definition, number register, diversion,
environment switching, page-position trap, and conditional
input mechanisms provide the basis for user-defined imple-
mentations. (Most documents can be prepared with either the
-mQ or -man macro sets.)
56 Zilog 56
NROFF/TROFF Zilog NROFF/TROFF
57 Zilog 57
NROFF/TROFF Zilog NROFF/TROFF
• nr s2 \ \n ( • s \"previous size
• \"rest of footer
••
• de hd
• \"header
.ps \\n(s2 \"restore previous size
.ps \\n(sl \"restore current size
58 Zilog 58
NROFF/TROFF Zilog NROFF/TROFF
59 Zilog / 59
NROFF/TROFF Zilog NROFF/TROFF
/
I., • el \ {\
.po \\nMu \"restore left margin
'bp \}
.11 3.1i \"column width
.nr M \ \n (.0 \"save left margin
Typically, a portion of the top of the first page contains
full-width text; the request for the narrower line length,
as well as another .mk is made where the two-column output
begins.
60 Zilog 60
NROFF/TROFF Zilog NROFF/TROFF
••
.de fn \"start footnote
.da FN \"divert (append) footnote
.ev 1 \"in environment 1
.if \\n+x=l .fs \"if first, include separator
.fi \"fill mode
••
• de ef \"end footnote
.br \"finish output
.nr z \\n(.v\"save spacing
.ev \"pop ev
.di \"end diversion
.nr y -\\n(dn \"new footer position,
.if \\nx=l .nr y -(\\n(.v-\\nz) \
\"uncertainty correction
.ch fo \\nyu \"y is negative
.if ( \\n(nl+lv) > (\\n(.p+\\ny) \
.ch fo \\n(nlu+lv \"it didn't fit
••
.de fs \"separator
\1'1 i' \"1 inch rule
.br
·.de. fz \"get leftover footnote
.fn
.nf \"retain vertical size
• fy \"where fx put it
.ef
·.nr•. b 1.Oi \"bottom margin size
.wh 0 hd \"header trap
.wh l2i fo \"footer trap, temp position
.wh -\\nbu fx \"fx at footer position
.ch fo -\\nbu \"conceal fx with fo
The header hd initializes a footnote count register x, and
sets both the current footer trap position register y and
the footer trap itself to a nominal position specified in
register b. In addition, if the register dn indicates a
leftover footnote, fz is invoked to reprocess it. The foot-
note start macro fn begins a diversion (append) in environ-
ment 1, and increments the count X1 if the count is one, the
footnote separator fs is interpolated. The separator is
kept in a separate macro to permit user" redefinition. The
footnote end macro ef restores the previous environment and
ends the diversion after saving the spacing size in register
z. y is then decremented by the size of the footnote,
available in dn; then on the first footnote, y is further
decremented by the difference in vertical base-line spacings
of the two environments to prevent the late triggering of
the footer trap from causing the last line of the combined
footnotes to overflow. The footer trap is then set to the ~
61 Zilog 61
NROFF/TROFF Zilog NROFF/TROFF
\
~
lower (on the page) of y or the current page position (nl)
plus one line, to allow for printing the reference line. If
indicated by x, the footer fo rereads the footnotes from FN
in nofill mode in environment 1, and deletes FN. If the
footnotes are too large to fit, the macro fx is trap-invoked
to redivert the overflow into fy, and the register dn later
indicates to the header whether fy is empty. Both fo and fx
are planted in the nominal footer trap position in an order
that causes fx to be concealed unless the fo trap is moved.
The.footer then terminates the overflow diversion, if neces-
sary, and zeros x to disable fx, because the uncertainty
correction together with a not-too-late triggering of the
footer can result in the footnote rereading and finishing
before reaching the fx trap.
A good exercise is to combine the multiple-column ana foot-
note mechanisms.
62 Zilog 62
NROFF/TROFF Zilog NROFF/TROFF
( APPENDIX A
SUM~mRY AND INDEX
A.l Summary
+ No effect in nroff.
1. General Explanation
63 Zilog 63
NROFF/TROFF Zilog NROFF/TROFF
3. Page Control
Request Initial If No
Form Value Argument Notes Explanation
.pl ±N llin llin v Page length.
.bp ±N N=l B,v Eject current
page; next page
number N.
.pn ±N N=l ignored Next page number
N.
• po ±N O;26/27in previous v Page offset •
.ne N N=lV D,v Need N ver-
tical space (V=ver-
tical spacing) •
• mk none internal D Mark current ver-
tical place in reg-
ister R.
.rt ±N none internal D,v Return (upward only)
to marked vertical
place.
5. Spacing
Request Initial If No
Form Value Argument Notes Explanation
.vs N 1/6in; previous E,p Vertical base line
12pts spacing (V).
.ls N N=l previous E Output N-l VS after
each text output
64 Zilog 64
NROFF/TROFF Zilog NROFF/TROFF
line.
.sp N N=lV B,v Space vertical
distance N in
either direction.
.sv N N=lV B,v Save vertical
distance N.
.os Output saved ver-
tical distance.
.ns space D Turn no-space
mode on.
.rs D Restore spacing;
turn no-space mode
off.
.11 ±N 6.5in previous E,m Line length.
• in +N N=O previous B,E,m Indent.
• ti ±N ignored B,E,m Temporary indent •
65 Zilog 65
NROFF/TROFF Zilog NROFF/TROFF
7. Number Registers
Request Initial If No
Form Value Argument Notes Explanation
.nr R +N M u Define and set
number register
Ri auto-increment
by M•
• af R c arabic Assign format to
register R (c=l,
i, I, at A).
• rr R Remove register R•
66 Zilog 66
NROFF/TROFF Zilog NROFF/TROFF
12. Hyphenation
Request Initial If No
Form Value Argument Notes Explanation
• nh hyphenate - E No hyphenation •
.hy N hyphenate hyphenate E Hyphenate; N =
mode.
.hc c \% \% - E Hyphenation indi-
cator character
c•
• hw wordl ••• ignored Exception words.
67 Zilog 67
NROFF/TROFF Zilog NROFF/TROFF
68 Zilog 68
NROFF/TROFF Zilog NROFF/TROFF
19. Miscellaneous
Request Initial If No
Form Value Argument Notes Explanation
.mc c N off E,m Set margin char-
acter c and sep-
aration N.
• tm str ing newline Print string on
terminal (ZEUS
stand ard message
output) •
.ig yy .yy= •• Ignore till call
of yy.
.pm t all Print macro names
and sizes; if t
present, print
only total of
sizes •
• fl B Flush output buf-
fer.
NOTES
B Request normally causes a break.
o Mode or relevant parameters associated with
current diversion level.
E Relevant parameters are a part of the current
environment.
o Must stay in effect until logical output.
69 Zilog 69
NROFF/TROFF Zilog NROFF/TROFF
~ ~
''\
70 Zi10g 70
NROFF/TROFF Zilog NROFF/TROFF
71 Zilog 71
NROFF/TROFF Zilog NROFF/TROFF
72 Zilog 72
NROFF/TROFF Zilog NROFF/TROFF
line
3 0 Current page offset
3 P Current page length
2.3 s Current pOint size
6.5 t Distance to the next trap
4.1 u Equal to 1 in fill mode and 0 in nofill mode
5.1 v Current vertical line spacing
10.2 w Width of previous character
x Reserved version-dependent register
y Reserved version-dependent register
6.4 z Name of current diversion
73 Zilog 73
NROFF/TROFF Zilog NROFF/TROFF
APPENDIX B
SUM~mRY OF RECENT CHANGES TO NROFF/TROFF
Options
-h (Nroff only) Output tabs used during horizontal
spacing to speeQ output as well as reduce output
byte count. Device tab settings are assumed to be
every eight nominal character widths. The default
settings of input (logical) tabs is also initial-
ized to every eight nominal character widths.
-z Efficiently suppresses formatted output. Only
message output occurs (from "tm"s and diagnos-
tics) •
Old Requests
.ad c The adjustment type indicator Pc" is now also a
number previously obtained from the ".j" register •
• so name The contents of file "name" are interpolated at
the point the "so" is encountered. Previously,
the interpolation was . done upon return to the
file-reading input level.
New Request
.ab text Prints "text" on the message output and terminates
without further processing. If "text" is missing,
"User Abort." is printed. Does not cause a break.
The output buffer is flushed.
.fz F N Forces font "F" to be in size N. N can have the
form N, +N, or -N. For example,
.fz 3 -2
74 Zilog 74
NROFF/TROFF Zilog NROFF/TROFF
./
75 Zilog 75
PGMG Zilog PGMG
ZEUS PROGRAMMING*
(
1 Zilog 1
..
PGMG Zilog PGMG
...
2 Zilog 2
PGMG Zilog PGMG
PREFACE
3 Zilog 3
PGMG Zilog PGMG
TABLE OF CONTENTS
4 Zilog 4
..
/' "
PGMG Zilog PGMG
SECTION 1
BASICS
5 Zilog 5
PGMG Zilog PGMG
otherprog I prog
provides the standard input for ~ from the standard out~
put of otherprog.
The function getchar returns ~ when it encounters the end
of file or an error on what is being read.
The function putchar(~) puts the character ~ on the standard
output. The output can be captured on a file by using >.
If ~ uses putchar,
prog > outfile
writes the standard output on outfile instead of on the ter-
minal. If outfile does not exist, it is created. If it
already exists, its previous contents are overwritten. A
pipe can be used.
prog I otherprog
puts the standard output of ~ into the standard input of
otherprog.
The function printf, which formats output in various ways,
uses the same mechanism as putchar. Therefore, calls to
printf and putchar can be intermixed in any order. The out-
put appears in the order of the calls.
Similarly, the function scanf provides formatted input
converS10n1 it reads the standard input and breaks it into
strings, numbers, and so on, as desired. The function scanf
uses the same mechanism as getchar, so calls to either can
be intermixed.
Many programs read only one input and write only one output.
For such programs, I/O with getchar, putchar, scaDf, and
printf can be adequate, and it is enough to get started.
This is particularly true if the ZEUS pipe facility is used
to connect the output of one program to the input of the
next. For example, the following program strips out all
ASCII control characters from its input (except for new line
and tab).
6 Zilog 6
PGMG Zilog PGMG
#include <stdio.h>
main () /* ccstrip: strip nongraphic characters */
{
int C1
while «c = getchar(» 1= EOF)
if «c >= ' , && c < 0177) II c == '\t' II c == '\n')
putchar(c};
exit(O);
}
The line
#include <stdio.h>
should appear at the beginning of each source file. It
causes the C compiler to read a file (/~include/stdio.h)
of standard routines and symbols that includes the defini-
tion of .EQf..
If it is necessary to treat multiple files, ~ can be used
to collect the files:
cat filel file2 ••• I ccstrip > output
thereby avoiding the necessity of learning. how to access
files from a program. The ~ at the end of the program is
not necessary, but it ensures that any caller of the program
sees a normal termination status (conventionally 0) from the
program when it completes. (Section 6 discusses status
returns in more detail.)
7 Zilog 7
.,.
PGMG Zilog PGMG
SECTION 2
THE STANDARD I/O LIBRARY
2.1 Introduction
The standard I/O library is a collection of routines provid-
ing efficient and portable I/O services for most C programs.
The standard I/O library is available on System 8000, which
supports C. Programs that confine their system interactions
to the library's facilities can be easily transported from
System 8000 to another system or from another system to Sys-
tem 8000.
The standard I/O library was designed with the following
goals in mind.
1. Maximal time and space efficiency so that it can be
used in all applications no matter how critical.
2. Simple to use and free from unexplained numbers and
calls that interfere with the understandability and
portability of many programs using older packages.
3. The interface provided is applicable on all machines,
whether or not the programs that implement it are
directly portable to other systems.
In Sections 2.2 through 2.4, the basics of the standard I/O
library are discussed. Sections 2.5, 2.6, and 2.7 contain a
more complete description of its capabilities.
8 Zilog 8
PGMG Zilog PGMG
9 Zilog 9
PGMG Zilog PGMG
10 Zilog 10
PGMG Zilog PGMG
11 Zilog 11
PGMG Zilog PGMG
2.6 Calls
ElLt *fopen(filename, ~) ~ *filename, *~;
13 Zilog 13
PGMG Zilog PGMG
14 Zilog 14
PGMG Zilog PGMG
getchar();
This call is identical to ~(stdin).
putchar(&) ~ &;
This call is identical to ~(&, stdout).
~ *fgets(~, n, ioptr) ~ *~; int n; ~ *1Qptr;
This call reads into the character pointer ,a, , up to
n-l characters from the stream iQptr. The read ter-
minates with a new line character, which is placed in
the buffer followed by a null character. The function
fgets returns the first argument or XULL if error or
.E.Qf occurred.
fputs(,a" 1Qptr) ~ *,a,; ~ *1optr;
This call writes the null-terminated string (character
array) ,a, on the stream 1Qptr. A new line is not
appended, and no value is returned.
ungetc(&, 1Qptr) ~ &; ~ *1Qptr;
The argument character & is pushed back on the input
stream named by 1Qptr. Only one character at a time can
be pushed back.
pr1ntf(fQrmat, Al, ••• ) ~ *fQrmat;
'fpr1ntf(1QPtr, fQrmat, Al, ••• ) ~ *iQptr; ~ *fQrmat;
sprintf(,a" fQrmat, al, .•• )~ *,a" *fQrmat;
The function pr1ntf writes on the standard output. The
function fpr1ntf writes on the named output stream, and
spr1ntf puts characters in the character array named by
~. The specifications are as described in printf(l) of
the ZEUS Reference Manual.
scanf(fQrmat, Al, ••• ) ~ *fQrmat;
fscanf(1QPtr, fQrmat, Al, ••• ) ~ *1Qptr; ~ *fQrmat;
sscanf(,a" fQrmat, Al, ... ) ~ *,a" *fQrmat;
The scanf function reads from the standard input;
fscanf reads from the named input stream; sscanf reads
from the character string supplied as ,a,; and scanf
reads characters, interprets them according to a for-
mat, and stores the results in its arguments. Each
routine expects, as arguments, a control string fQrmat
and a set of arguments, each of which must be a pointer
that indicates where the converted input is to be
stored. The function scanf returns the number of
15 Zilog 15
PGMG Zilog PGMG
16 Zilog 16
PGMG Zilog PGMG
17 Zilog 17
PGMG Zilog PGMG
2.7 Macros
The definitions of the following macros can be obtained by
including <ctype.h>.
isalpha CcJ
returns nonzero if the argument is alphabetic
isupper (~)
returns nonzero if the argument is upper-case alpha-
betic
islower (~)
returns nonzero if the argument is lower-case alpha-
betic
isdigit (~)
returns nonzero if the argument is a digit
isspace (~)
returns nonzero if the argument is a spacing character
(tab, new line, carriage return, vertical tab, form
feed, or space)
ispunct(~}
18 Zilog 18
PGMG Zilog PGMG
isalnum(k)
returns nonzero if the argument is alphanumeric
isprint (k)
returns nonzero if the argument is printable (a letter,
.digit, or punctuation character)
iscntrl (k)
returns nonzero if the argument is a control character
isascii <.~}
returns nonzero if the argument is an ASCII character
toupper(&)
returns the upper-case character corresponding to the
lower-case letter k
tolower (&)
returns the lower-case character corresponding to the
upper-case letter &
19 Zilog 19
PGMG Zilog PGMG
SECTION 3
LOW-LEVEL I/O
3.1 General
The bottom level of I/O on ZEUS is described in this sec-
tion, and it does not provide buffering or any other ser-
vices. It is a direct entry into the operating system. The
calls and usage are simple and the user has control over
what happens.
{
20 Zilog 20
PGMG Zilog PGMG
21 Zilog 21
PGMG Zilog PGMG
if (n == 0) { /* buffer is empty */
n = read(O, buf, BUFSIZE);
bufp = buf;
22 Zilog 22
PGMG Zilog PGMG
}
return«--n >= 0) ? *bufp++ & CMASK : EOF) 1
}
int fd:
fd = open(name, rwmode):
As with fopen, the name argument is a character string
corresponding to the external file name. The access mode
argument is different, however. The rwmode argument is 0
for read, 1 for write, and 2 for read and write access. If
any error occurs, ~ returns -11 otherwise, it returns a
valid file descriptor. .
Trying to open a file that does not exist results in an
error. The entry point creat is provided to create new
files or to rewrite old ones.
fd = creat(name, pmode):
returns a file descriptor if it was able to create the file
called nam&, and -1 if not. If the file already exists,
creat truncates it to zero length. It is not an error to
creat a file that already exists.
If the file is new, creat creates it with the protection
~ specified by the pmode argument. In the ZEUS file sys-
tem, there are nine bits of protection information associ-
ated with a file, controlling read, write, and execute per-
mission for the owner of the file, for the owner's group,
and for all others. A three-digit octal number is most con-
venient for specifying the permissions. For example, 0755
(octal) specifies read, write, and execute permission for
the owner, and read and execute permission for the group and
everyone else.
To illustrate, here is a simplified version of the ZEUS
utility~, a program that copies one file to another.
23 Zilog 23
PGMG Zilog PGMG
(This version copies only one file and does not permit the
second argument to be a directory.)
#define NULL 0
#define BUFSIZE 512
#define PMODE 0644 /* RW for owner, R for group, others */
main{argc, argv) /* cp: copy fl to f2 */
int argci
char *argv [] ;
{
int fl, f2, n;
char buf[BUFSIZE];
if (argc 1= 3)
error {"Usage: cp from to", NULL);
if {(f1 = open(argv[l] , a)} == -1)
error("cp: can't open %s", argv[l]);
if ({f2 = creat{argv[2], PMODE» == -1)
error("cp: can't create %s·, argv[2]);
while «n = read(fl, buf, BUFSIZE» > 0)
if (write(f2, buf, n) 1= n)
error(" cp : write error", NULL);
exit(O);
}
24 Zilog 24
PGMG ~ Zilog PGMG
25 Zilog 25
PGMG Zilog PGMG
26 Zilog 26
PGMG Zilog PGMG
SECTION 4
PROCESSES
27 Zilog 27
PGMG Zilog PGMG
The exec I call overlays the existing program with the new
one; it runs the new program and then exits. There is no
return to the original program.
It is more common, however, for a program to fall into two
or more phases that communicate only through temporary
files. If this happens, it is natural to make the second
pass simply an execl call from the first.
The one exception to the rule that the original program
never gets control back occurs when there is an error (for
example, if the file can1t be found or is not executable).
If the location of ~ is not known, enter
execl("/bin/date", "date", NULL);
execl("/usr/bin/date", "date", NULL);
fprintf(stderr, "Someone stole 'date'\n");
Use execy, a variant of execl, when the number of arguments
is not known in advance. The call is
execv(filename, argp);
where ALQR is an array of pointers to the arguments. The
last pointer in the array must be NULL so that execy can
tell where the list ends. As with execl, 'filename is the
file in which the program is found, and ALQR[~] is the name
of the program. (This arrangement is identical to the ~
array for program arguments.)
Because neither of these routines provides automatic search
of multiple directories, the location of the command must be
precisely known. The expansion of metacharacters like <, >,
*, ?, and [] in the argument list cannot be obtained. If
these metacharacters are desired, use execl to invoke the
shell (ab), which then does all the work. A string command-
line that contains the complete command as it would have
been typed at the terminal is constructed. Then enter:
execl("/bin/sh", ash", "_c n , commandline, NULL);
The shell is assumed to be at a fixed place, /hin/Qh. Its
argument -~ means that the next argument should be treated
as a whole command line. The only problem is in construct-
ing the right information in commandline.
28 Zilog 28
PGMG Zilog PGMG
29 Zilog 29
PGMG Zilog PGMG
4.4 Pipes
A ~ is an I/O channel used between two processes. One
process writes into the pipe, whil.e the other reads. The
system buffers the data and synchronizes the two processes.
Most pipes are created by the shell, as in:
Is I pr
which connects the standard output of la to the standard
input of ~. Sometimes, however, it is more convenient for a
process to set up its own commands.
The·system call ~ creates a pipe. Since a pipe is used
for both reading and writing, two file descriptors are
returned. The actual usage is like the following:
int fd[2];
stat = pipe(fd);
if (stat == -1)
/* there was an error ••• */
The !.d is an array of two file descriptors, where !.d[~] is
the read side of the pipe and !.d[ll is the write side.
These can be used in ~, write, and glose calls, just like
any other file descriptors.
If a process attempts to read a pipe that is empty, it waits
until data arrives. If a process attempts to write into a
pipe that is full, it waits until the pipe empties. If the
write side of the pipe is closed, a subsequent ~
encounters .£Q,[.
The following example illustrates the use of pipes. A func-
tion called popen(~, InQde) creates a process .kllUi and
returns a file descriptor that either reads or writes the
process, according to ~. That is, the call
fout = popen ("pr", WRITE);
30 Zilog 30
PGMG Zilog PGMG
i
\',
31 Zilog 31
PGMG Zilog PGMG
32 Zilog 32
PGMG Zilog PGMG
33 Zilog 33
PGMG Zilog PGMG
SECTION 5
SIGNALS·
5.1 General
This section discusses external signals and program faults.
Since nothing useful can be done within C about program
faults that arise from illegal memory references or from
execution of peculiar instructions, the following discussion
concerns only external signals:
$ interrupt: sent when the DEL character is typed
$ gyit: generated by control backslash
$ hangup: caused by hanging up the phone
$ terminate: generated by the kill command
When one of these events occurs, the signal is sent to all
processes that were started from the corresponding terminal.
Unless other arrangements have been made, the signal ter-
minates the process. In SYit, a core image file is written
for debuggin~ purposes.
34 Zilog 34
PGMG Zilog PGMG
onintr()
{
unlink(tempfile);
exit(l);
}
5.3 Interrupts
Signals like INTERRUPT are sent to all processes started
from a particular terminal. When a program is to be run
noninteractively (started by &), the shell pervents it from
rece1v1ng interrupts. If the program begins by announcing
that all interrupts are to be sent to the onintr routine,
this command cancels the shell's effort to protect it when
the program is run in the background.
The solution to this is to test the state of interrupt han-
dling and continue to ignore interrupts if they are already
being ignored. The program code depends on the fact that
signal returns the previous state of a particular signal.
If signals are already being ignored, the process continues
to ignore them1 otherwise, they are caught.
A more sop~isticated program can intercept an interrupt and
interpret the interrupt as a request for the program to stop
executing and return to its own command-processing loop. In
a text editor, interrupting a long printout should not cause
the editor to terminate and lose the work already done. The
outline of the code for this can be written as follows:
35 Zilog 35
PGMG Zilog PGMG
#include <signal.h>
#include <setret.h>
ret_buf sjbuf;
main ()
{
int (*istat) (), onintr () ;
istat = signal(SIGINT,
SIG_IGN);
/* save original status */
setret(sjbuf); /* save current stack position */
if (istat != SIG_IGN)
signal(SIGINT, onintr);
/* main processing loop */
}
onintr()
{
printf("OnterruptO);
longret(sjbuf); /* return to saved state */
}
36 Zilog 36
PGMG Zilog PGMG
37 Zilog 37
PGMG Zilog PGMG
. #include <signal.h>
system(s) /* run command string s */
ehar *s;
{
int status, pid, w;
register int (*istat) (), (*qstat) ();
if «pid = forkO) == 0) {
exeel("/bin/sh", "sh", "-e", s, 0);
_exit(127);
}
istat = signal(SIGINT, SIG_IGN)i
qstat = signal(SIGQUIT, SIG_IGN);
.
while «w = wait(&status» 1= pid && w 1= -1)
,
if (w == -1)
status = -1;
signal (SIGINT, istat);
signal (SIGQUIT, qstat);
return(status);
}
I
\,
c:
38 Zilog 38
PLZ/SYS Zilog PLZ/SYS
1 ZEUS 1
PLZ/SYS Zilog PLZ/SYS
PREFACE
2 ZEUS 2
.
PLZ/SYS Zi10g PLZ/SYS
TABLE OF CONTENTS
3 ZEUS 3
PLZ/SYS Zi10g PLZ/SYS
4 ZEUS 4
PLZ/SYS Zilog PLZ/SYS
LIST OF TABLES
Table
3-1 Evaluation of Constant Expressions •••••••••••••••••• 17
LIST OF ILLUSTRATIONS
Figure
1-1 Linking of PLZ/SYS and PLZ/ASM Source Code •••••••••• 9
5-1 Nonsegmented Run-Time Stack--General Layout ••••••••• 29
5-2 Segmented Run-Time Stack--General Layout •••••••••••• 31
6-1 Example 2: PLZ/ASM Module for the Nonsegemented
S8000 ••••.••••••••••••.••••••••••••••••••••••••••.•.. 36
6-2 Nonsegmented Run-Time Stack Detail After Entry
Sequence •••••••••••••••••••••••••••••••••••••••••••• 38
6-3 Nonsegmented Run-Time Stak Detail Before
Recursive Call •••••••••••••••••••••••••••••••••••••• 39
6-4 Example 3: PLZ/ASM Module for the Segmented
S8000. • • . • . • . • • . . • • • • • . • • • . • . . • • . • • . • • • . . • • . • . • . . • • .. 42
6-5 Segmented Run-Time Stack Detail After Entry
Sequence. • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • •• 44
6-6 Segmented Run-Time Stack Detail Before
Recursive Call ....................................... 45
5 ZEUS 5
PLZ/SYS Zilog PLZ/SYS
6 ZEUS 6
PLZ/SYS Zilog PLZ/SYS
SECTION 1
INTRODUCTION
7 ZEUS 7
PLZ/SYS Zilog PLZ/SYS
BLOCK DIAGRAM
TO BE SUPPLIED
8 ZEUS 8
PLZ/SYS Zilog PLZ/SYS
PLZ/SIS
SOURCE
Cpp
PLZ/SIS
JlTERMEDUT
SOURCE
PLZ SIS
Z-CODE PLZ/ASM
OBJECT SOURCE
MODULE
PLZCC AS
~A.CHIIE CODE ~fCHIIE CODE
pBJECT MODULI! BJECT MODULE PLZ C
II III LIBUIY· LIBRARY
zobj FORMAT a.out FORMAT
~
UIMAGE
tfCHIIIE COD~I
BJECT MODUL
1M
Ia.out FORMAT
II
LD
LIlltED
OBJECT
MODULE
- - ' ------- ------_.----- -- - - ----
9 ZEUS 9
PL.Z/SYS Zi10g PLZ/SYS
10 ZEUS 10
PLZ/SYS Zilog PLZ/SYS
SECTION 2
PLZ/SYS RUNNING UNDER ZEUS
2.1 Overview
PLZ/SYS source programs intended to run under ZEUS can be
compiled, code generated, and linked using the simplified
user interface, Rlz(~). Plz is a driver for the compiler and
code generator which, along with the assembler, C preproces-
sor, and ZEUS linker, are invoked automatically with default
command line options. Together they produce an object
module that is loaded and run by ZEUS.
The plz driver programs work similarly to ~(~) for C pro-
grams. To compile a plz source program composed of several
modules, a single command must be issued to produce a ZEUS-
loadable program. For example, a program consisting of
three PLZ/SYS modules, a.~, h.~, ~.~, and the PLZ/ASM
modules ~.a and ~.a is compiled by:
%plz a.p b.p c.p d.s e.s -0 program
leaving the output on the file program. Default output is
a.out. Several options are accepted by plz and are
explained in the Z£llS Reference Manual under ~(~) •
2.2 Limitations
The plz programs created with the plz driver program are
limited because they cannot contain z-code modules. This is
because the ZEUS linker cannot create the appropriate tables
to link z-code. (See ~(l) in the ZEUS Reference Manual.)
(
11 ZEUS 11
PLZ/SYS Zilog PLZ/SYS
NOTE
Releases of the PLZ/SYS compiler dated from Sep-
tember 30, 1981, will conform to the S8000 calling
conventions instead of those described in Sections
5 and" 6. Programs compiled under these releases
will be able to declare ZEUS Utilities and C func-
tions as external procedures and invoke them
directly. The library /lib/libp.a will no longer
be necessary.
12 ZEUS 12
PLZ/SYS Zilog PLZ/SYS
SECTION 3
PLZ/SYS COMPILER
3.1 Overview
The PLZ/SYS compiler translates source code modules into
intermediate code. The ZEUS editor is used to create
PLZ/SYS source modules. The source file name must end with
the file name extension .p.
With the -1 option, the PLZ/SYS compiler creates a listing
file with the default source file name with the extension .1
rather than .p, and an object file with the default exten-
sion .z. In creating the object file, plzsys uses a tem-
porary scratch file that is deleted when compilation is fin-
ished. The listing file contains the source code with line
numbers, statement numbers, and syntax error messages. The
messages consist of a pointer to each erroneous token, fol-
lowed by an error number for each pointer. The list of
error numbers in Appendix A can be used to determine the
corresponding compilation error. Occasionally, the pointer
does not point directly at the incorrect token. Error mes-
sages can be copied to a separate file with the error (-e)
option described in Section 3.2.
The object file contains z-code. The plzcg code generator
compiles z-code to zaooo machine code.
13 ZEUS 13
PLZ/SYS . Zi10g PLZ/SYS
Option Function
-1 Creates a listing file with .1 substituted
for the .p extension of ·source file. Default
is no listing.
-0 Assigns the name filename to the object file,
instead of the default source file name with
the extension .z. If no object is desired,
use /dev/nu11 for filename.
-e Copies error messages to the file whose name
is the same as the source file with extension
.e. If no errors occur, the error file is
deleted at the end of compilation.
-nd Omits symbol, type, constant, and statement
number information for a hypothetical
debugger. The default is to generate debug
symbols.
-nc Omits debug symbol information for any CON-
STANT names. The default is to generate
named constants when generating debug sym-
boIs.
-t zao Generates output suitable for the zao. Does
not allow extensions to p1zsys such as long
variables and structure comparison and
assignment. The output can run on MCZ only.
-t zaooos Generates output suitable for the segmented
zaooo. Treats pointers as four-byte objects,
instead of two-byte objects. Aligns word-
size data on even addresses. Allows long
variables and structure comparison and
assignment.
-t ZaOOOns Generates output suitable for the nonseg-
mented zaooo. Allows long variables and
structure comparison and assignment. This is
the default.
'-
14 ZEUS 14
PLZ/SYS Zilog PLZ/SYS
15 ZEUS 15
PLZ/SYS Zilog PLZ/SYS
16 ZEUS 16
PLZjSYS Zilog PLzjSYS
17 ZEUS 17
PLZ/SYS Zilog PLZ/SYS
18 ZEUS 18
PLZ/SYS Zilog PLZ/SYS
19 ZEUS 19
PLZ/SYS Zilog PLZ/SYS
20 ZEUS 20
PLZ/SYS Zilog PLZ/SYS
SECTION 4
CODE GENERATOR
4.1 Overview
PLZ/SYS compiler output is a z-code object module that can-
not be executed directly on the S8BOO. The z-code must be
processed by the code generator to produce a machine-code
object module.
This section describes how to invoke the code generator and
select from the available options. The Z8000 plz code gen-
erator accepts a file of intermediate z-code as input and
produces a file of Z8000 relocatable object code in Zobj
format as output. This output must be translated into a.out
format by uimage. The output of uimage is linked with other
a.out format modules to form the complete executable load
module .'
21 ZEUS 21
PLZ/SYS Zilog PLZ/SYS
22 ZEUS 22
PLZ/SYS Zilog PLZ/SYS
SECTION 5
PLZ/SYS IMPLEMENTATION CONVENTIONS FOR THE Z8000
NOTE
Refer to Section 2 for applicability of these con-
ventions to your release of PLZ/SYS and use of
library functions.
5.1 Overview
This section describes PLZ/SYS program conventions for the
Z8000. Included are details on data representation, data
alignment, data access methods, run-time storage administra-
tion, and register conventions. This section concludes with
a specification of the run-time environment required for
proper program execution. It is assumed that the reader is
familiar with the information in the Z800a H.ZiASM Assembly
Language Programming Manual.
SHORT_INTEGER
A SHORT_INTEGER value is an integer in the range -128
to 127 and is represented on the Z800a as a signed
eight-bit byte in twos-complement notation.
23 ZEUS 23
PLZ/SYS .Zilog PLZ/SYS
WORD
A WORD value is a nonnegative integer in the range 0 to
65535 (decimal) and is represented on the Z8000 as an
unsigned 16-bit word.
INTEGER
An INTEGER value is an integer in the range -32768 to
32767 and is represented on the Z8000 as a signed 16-
bit word in twos-complement notation.
LONG
A LONG value is a nonnegative integer in the range 0 to
4,294,967,295 (decimal) and is represented on the Z8000
as an unsigned 32-bit long word.
Pointer
Nonsegmented code:
A pointer value on the nonsegmented Z8000 is a storage
address represented as a 16-bit word. The dis-
tinguished value NIL is represented by the value zero
(0) •
Segmented code:
A pointer value on the segmented Z8000 is a storage
address composed of a seven-bit segment number and a
16-bit offset, represented as a 32-bit long word. The
value of the pointer literal NIL is the long value zero
(address 0): segment zero, offset zero.
NOTE
Because the size of a pointer is inherently
dependent on specific machine configurations,
programs that are to be easily transported
24 ZEUS 24
PLZ/SYS Zilog PLZ/SYS
RECORD
Fields within a record are stored in the order of
declaration, subject to the alignment rules in Section
5.3 •.
TYPE
PTREC TREC ! TREC defined above
A
INTERNAL
PTRT PTREC
A ARRAY [(SIZEOF TREC) BYTE1
26 ZEUS 26
PLZ/SYS Zilog PLZ/SYS
W WORD
PTRT := PTREC iA[O]
W := PTRT .F2
A
! Fails if A begins on odd address
27 ZEUS 27
PLZ/SYS Zilog PLZ/SYS
/ '
28 ZEUS 28
PLZ/SYS Zi10g PLZ/SYS
STACK
HIGH ORDER HIGHER ADDRES
<--BYTE--) <--BYTE--)
LOW ADDRESS 0
2 I I
\ STACK GROWS TOWARD \
\ LOWER ADDRESSES \
I
I
I
I
/ / __
/ \
I I
\.\
I
I
I
I
I I I I
I I_I I TOP STACK WORD
SP(R15)-----> I I
I INPUT PARAMETER I
I PASSING AREA I
I I
I I
I RETURN PARAMETER I
I RECEIVING AREA I
I I
I I
I TEMPORARY I
I EVALUATION AREA I
I I
I I
LB(R14)-----> I OLD LB I
I I
I I
I RETURN ADDRESS I
I I
I I
I LOCAL VARIABLES I
I I
I I
I INPUT PARAMETERS I
I FROM CALLER I
I I
I I
I RETURN PARAMETERS I
I TO CALLER I
I I
I I
\ \
\ \
FFFC I I
HIGH ADDRESS FFFE I I BASE STACK WORD
29 ZEUS 29
PLZ/SYS Zilog PLZ/SYS
30 ZEUS 30
PLZ/SYS Zilog PLZ/SYS
0 , , 0 , ,
\ \ \ STACK GROWS TOWARD \
LOWER ADDRESES \,
,,,
\ \ \
/ \ ,
/
/ __
,
\\ ,
,I , ,I I,
,,
,,I 1_'
LP(RR12)--) INPUT PARAMETER
PASSING AREA ,
I I
I I,
I RETURN PARAMETER
, RECEIVING AREA ,
STACK GROWS , ,
TOWARD
LOWER ADDRESSES ,I TEMPORARY
I
I
/
/ \
\ ,,, EVALUATION AREA
,,,
/_
,
,
, \
- ,, ----------)
,, LOCAL VARIABLES
,,,
I
, ,
CP (RR14)
1_' , ,, ,, INPUT PARAMETERS ,,
----- FIXED BASE ------, ,, FROM CALLERS
_'_I
,,
,
,
,,,
RETURN PARAMETERS
RETURN ADDRESS ---I
,, ,,, TO CALLER ,
,
,
\ \ \ \
FFFC
\,, \ ,, FFFC ,
\ ,,
\
FFFE HIGH ADDRESS'
FFFE
(
31 ZEUS 31
PLZ/SYS Zilog PLZ/SYS
The Local Stack Pointer (LP) addresses the top word on the
Local Stack and is maintained in register pair RR12. Param-
eters are passed by pushing them on the Local Stack; result
parameters are accessed by popping them off. Local vari-
ables are accessed relative to LP, using either Based or
Indexed Addressing modes. The local base address is not
maintained in a register as with nonsegmented code. The
displacement of local variables from LP varies during execu-
tion as temporaries or parameters are pushed and popped.
However, the movement of LP is predictable during code gen-
eration and offsets to local variables can be adjusted for
each reference.
The Control Stack Pointer (CP) addresses the top word of the
Control Stack and is maintained in register pair RR14. This
register is used by the Call and Return instructions to
deposit and restore the program counter. Before execution
of the procedure body, the location of the lowest-address
word of local storage is pushed on the Control Stack. This
address is not required for execution, but it is"useful for
run-time debugging since local and parameter data are diffi-
cult to locate, due to the transient nature of LP.
32 ZEUS 32
PLZ/SYS Zilog PLZ/SYS
33 ZEUS 33
PLZ/SYS Zilog PLZ/SYS
34 ZEUS 34
PLZ/SYS Zilog PLZ/SYS
SECTION 6
PLZ/SYS - PLZ/ASM INTERFACE EXAMPLE
NOTE
Refer to Section 2 for applicability of these con-
ventions to your release of PLZ/SYS and use of
library functions.
6.1 Purpose
This section presents an example module written in PLZ/SYS,
and shows equivalent modules written in PLZ/ASM for both
segmented and nonsegmented zaooo. The PLZ/ASM equivalents
conform to PLZ/SYS run-time conventions and can be substi-
tuted for the PLZ/SYS module as part of a larger program.
This example can be used as a model for writing PLZ/SYS-
compatible modules in PLZ/ASM.
The PLZ/SYS version is listed in Example #1. The module
declares the procedure Example, whose only statement is a
recursive call to itself. This example illustrates the
PLZ/SYS parameter passing conventions.
EXAMPLE #1:
PLZSYS 3.1
1 Example MODULE
2
3 1 Example PLZ/SYS module demonstrating procedure
4 1 calling conventions.
5
6 GLOBAL
7
a Example
9 PROCEDURE (inl: BYTE; in2: AByTE )
10 RETURNS (outl: BYTE; out2: WORD)
11 LOCAL
12 locall, loca12, loca13: BYTE
13 ENTRY
14 1 outl, out2 := Example (loca12, in2)
15 2 END Example
16
17 END Example
35 ZEUS 35
PLZ/SYS Zilog PLZ/SYS
Z8000ASM 2.0
LOC OBJ CODE STMT SOURCE STATEHENT
1 Example MODULE
2
3 ! Example module written in PLZ/ASM
4 ! for the nonsegmented Z8000
5
6 CONSTANT
7 ! Offsets from local base
8 out2 := 14
9 outl := 13
10 inl := 11
11 in2 := 8
12 loca13 := 6
13 loca12 := 5
14 locall := 4
15
16 GLOBAL
17
0000 18 Example
19 PROCEDURE
20 ENTRY
21 ! --- Entry Sequence --- !
0000 97FO 22 POP RO,@R15 ! Pop return address
0002 ASF3 23 DEC Rl5, #4 Allocate local variables!
0004 93FO 24 PUSH @R15,RO Replace return address 1.
0006 93FE 25 PUSH @R15,F~4 Save old Local Base
0008 AIFE 26 LD R14,R15 Establish new Local Base!
27
28 ! outl, out2 := Example (10ca12, in2) !
OOOA ASF3 29 DEC R15,'#4 Allocate return params
30
OOOC 30E8 0005 31 LOB RLO,Rl4(#loca12)
0010 93FO 32 PUSH @R15,RO Push 1st input param
33
0012 53FE 0008 34 PUSH @R15,in2(Rl4) Push 2nd input param
35
0016 DOOC 36 CALR Example
37
OOla 57FE OOOC 38 POP outl-l (Rl4) ,@R15 Pop 1st return param
39
OOIC 57 FE OOOE 40 POP out2 (Rl4) ,@R15 Pop 2nd return param
41
42 ! --- Exit Sequence
0020 97FE 43 POP Rl4, @Rl5 Restore old Local Base
0022 97Fl 44 POP Rl,@R15 Pop return address
0024 A9F7 45 INC Rl5, #8 Pop locals & input param!
0026 lE18 46 JP @Rl Resume calling procedure!
0028 47 END Example
48
49 END Example
a errors
Assembly complete
36 ZEUS 36
PLZ/SYS Zilog PLZ/SYS
37 ZEUS 37
PLZ/SYS Zilog PLZ/SYS
/"
STACK
HIGHER ORDER HIGHER ADDRESS
<--BYTE--> <--BYTE-->
LOW ADDRESS 0 I I
\ \
\ \
I I
I I
I I
I I
I I
I I
I I
I I
SP LB----->I OLD LB I
I I
I RETURN ADDRESS I
I I
I locall I local2 I
I I I
I local3 I unused I
I I I
I in2 I
I I
I unused I inl I
I I I
I unused I outl I
I I I
I out2 I
I I
I I
I I
I I
\ \
\ \
I I
HIGH ADDRESS FFFFE I I
38 ZEUS 38
PLZ/SYS Zilog PLZ/SYS
STACK
HIGHER ORDER HIGHER ADDRESS
<--BYTE--) <--BYTE--)
LOW ADDRESS 0 1 1
\ \
\ \
1 1
11____________________ 1
r{
39 ZEUS 39
PLZ/SYS Zilog PLZ/SYS
40 ZEUS 40
PLZ/SYS Zilog PLZ/SYS
41 ZEUS 41
PLZ/SYS Zilog PLZ/SYS
Z8000ASM 2.0
LOC OBJ CODE STMT SOURCE STATE~1ENT
1 Example MODULE
2
3 ! Example module written in PLZ/ASM
4 ! for the segmen~ed zaooo.
5
6 $SEGMENTED
7
8 CONSTANT
9 LSseg := 0 Local Stack Segment
10
11 ! Offsets from base of locals !
12 out2 := 12
13 outl := 11
14 inl := 9
15 in2 := 4
16 local3 := 2
17 local2 := 1
18 locall := a
19
20 GLOBAL
21
0000 22 Example
23 PROCEDURE
24 ENTRY
25 ! --- Entry Sequence --- !
0000 ABD3 26 DEC R13, #4 . ! Allocate local variables
0002 9lEC 27 PU SHL @RRl4, RRl2 ! Save Fixed Base (optional)
28
29 ! outl, out2 := Example (loca12, in2) !
0004 ABD3 30 DEC R13,#4 ! Allocate return parameters
31
0006 30C8 0005 32 LOB RLO,RRl2 (Uoca12+4)
OOOA 93CO 33 PUSH @RR12,RO Push 1st input parameter
34
OOOC 35CO OOOA 35 LOL RRO,RRl2(#in2+6)
0010 9lCO 36 PUSHL @RRl2,RRO Push 2nd input parameter
37
0012 DOOA 38 CALR Example
39
0014 57CD 00 OE 40 POP I «LSseg»outl-l+4 I (Rl3) ,@RRl2 1st result
41
0018 57CD 00 OE 42 POP I «LSseg»out2+2 I (Rl3) ,@RRl2 2nd result
43
44 ! --- Exit Sequence --- !
OOlC A909 45 INC Rl3,nO Pop locals & input params
OOlE A9F3 46 INC Rl5,i4 Pop fixed base
0020 9EOa 47 RET ! Resume calling procedure.
0022 48 END Example
49
50 END Example
o errors
Assembly complete
- - _. ____ - - " _ ' 0 - ' . ____ . _ " _ _ _ ._ .. _ .. _ .... ___ . __ .• ___ , _ _ _ _ _ _ _ _ _ _ . ___ ._ _ . __
42 ZEUS 42
PLZ/SYS Zilog PLZ/SYS
(
Figure 6-5 displays the portions of the two run-time stacks
visible to Example after execution of the entry sequence.
Parameters and local variables reside on the Local Stack.
Return addresses and Local Base addresses reside on the Con-
trol Stack. The size of parameter in2 is four bytes, since
segmented addresses occupy long words.
Lines 30 through 42 demonstrate a proper call to Example.
The sequence of events is identical to that of nonsegmented
code. Parameters are pushed on the Local Stack. The confi-
guration of the run-time stacks before execution of the call
instruction in line 38 is shown in Figure 6-6.
If Example returns from its recursive call, the Local Stack
Pointer register addresses the first return parameter. Pop-
ping it from the Local Stack exposes the second return
parameter. Popping the second parameter positions the Local
Stack Pointer register at the lowest-address word of local
storage.
The exit s~quence is shown in lines 45 through 47. Before
line 45 ~s executed, the Control and Local Stack Pointer
registers contain the same values they had after the entry
sequence. The local variables and input parameters are
deallocated by incrementing the Local Stack Pointer regis-
ter. This leaves the Local Stack Pointer register address-
ing the first return parameter. The' local storage base
address is removed from the Control Stack, and the return
instruction pops the return address from the Control Stack
and resumes the calling procedure. If no local variables or
input parameters are declared by Example, line 45 is omit-
ted.
43 ZEUS 43
PLZ/SYS Zilog PLZ/SYS
0 I I LOW ADDRESS 0 I 1
\ \ \ \
\ \ \ \
I I
I I
I I
I I
I I --------LP---) locall loca12
I I I
1 1 local3 unused
1 I
1 1
CP----) I I in2
FIXED BASE ---1_1
1 unused 1 inl
I I I
--RETURN ADDRESS---I unused I outl I
I I I
I out2 I
I 1
I 1
1 I
\ \ \ \
\ \ \ \
I I I I
FFFE I I HIGH ADDRESS I I
FFFE
44 ZEUS 44
PLZ/SYS Zilog PLZ/SYS
0 I I LOW ADDRESS 0 I I
\ \ \ \
\ \ \ \
I I I I
1 I I 1
I I I I
I I LP---->I I
1 1 I-- 2nd INPUT PARAM --I
I I 1
I 1 unused IlstIN PARA I
I I 1 1
I
I
.. I unused lIst RESULT 1
1 I I
1 1 2nd RESULT PARAM I
I I 1
I ------------>1 local 1 loca12 I
1 I 1 1
I I I loca13 unused 1
1 I I I
I I I I
CP---->1 I 1--- in2 ---I
1---- FIXED BASE 1 1 I
1 __ I 1 unused I inl I
1 I I I 1
I 1 1 unused 1 outl I
I---RETURN ADDRESS---I 1 1 1
I I I out2 I
1 I 1 1
1 1 1 I
1 1 1 1
\ \ \ \
\ \ \ \
FFFE 1 1 HIGH ADDRESS I 1
FFFE
(
45 ZEUS 45
PLZ/SYS Zilog PLZ/SYS
46 ZEUS 46
PLZ/SYS Zilog PLZ/SYS
I
.
APPENDIX A
PLZ/SYS ERROR MESSAGES
ERROR EXPLANATION
Warnings
o A minus sign (-) or a plus sign (+) treated as
binary operator
1 Missing delimiter between tokens
2 Array of zero elements
3 No fields in record declaration
4 Mismatched procedure names
5 Mismatched module names
6 constant out-of-range for type
8 Absolute address warning for System 8000
Token Errors
10 Decimal number too large
11 Invalid operator
12 Invalid special character after prompt (%)
13 Invalid hexadecimal digit
14 Character __ sequence of zero length
15 Invalid character
16 Hexadecimal number too large
DO Loop Errors
20 Unmatched OD
21 OD expected
22 Invalid repeat statement
23 Invalid exit statement
24 Invalid FROM label
IF Statement Errors
30 Unmatched FI
31 FI expected
32 THEN or CASE expected
( 33 Invalid selector record
47 ZEUS 47
PLZ/SYS Zilog PLZ/SYS
ERROR EXPLANATION
Symbols Expected
40 ) expected
41 ( expected
42 ] expected
43 [ expected
44 := expected
45 ~ expected
Undefined Names
50 Undefined identifier
51 Undefined procedure name
Declaration Errors
60 Type identifier expected
61 Invalid module declaration
62 Invalid declaration class
63 Invalid use of array [*] declaration
64 Uninitialized array [*] declaration
65 Invalid dimension size
66 Invalid array component type
67 Invalid record field declaration
68 Invalid type used in pointer declaration
Initialization Errors
48 ZEUS 48
PLZ/SYS Zilog PLZ/SYS
ERROR EXPLANATION
Special Errors
90 Invalid statement
91 Invalid instruction
92 Invalid operand
93 Operand too large
94 Relative address out of range
95 : expected
97 Duplicate record field name
98 Duplicate CASE constant
99 Multiple declaration of identifier
Invalid Variables
100 Invalid variable ~
101 Invalid operand for # or SIZEOF
102 Invalid field name
103 Subscripting of nonarray variable
104 Invalid use of ~eriod (.)
105 Invalid use of
Expression Errors
110 Invalid arithmetic expression
III Invalid conditional expression
112 Invalid constant expression
113 Invalid select expression
114 Invalid index expression
115 Invalid expression in assignment
49 ZEUS 49
PLZ/SYS Zilog PLZ/SYS
ERROR EXPLANATION
Type Incompatibility
140 Character __ sequence initializer used with
array [*] declaration where component's
base type is not 8 bits
141 Type incompatibility with initialization
150 Type incompatibility in arithmetic expression
151 Invalid operand type for unary operator
152 Invalid operand type for binary operator
153 Unassigned type
154 Invalid index type
156 Parameter type incompatible
157 Invalid actual parameter
158 Return parameter type incompatible
159 Return value must be address
160 Type incompatibility in assignment
161 Invalid operand type for relational operator
162 Type incompatibility in conditional expression
163 Invalid type conversion
164 Invalid relational operator for structures
File Errors
198 EOF expected
199 Unexpected EOF encountered in source--possible
unmatched ! or ' in source
Implementation Restrictions
230 Character __ sequence or identifier too long
231 Symbol table overflow
232 Procedure too large
233 Left hand side of assignment too complicated
234 Too many initialization values
235 Stack overflow
236 Too many constants in expression
237 Static data overflow
238 Program area overflow
239 Too many internal or global procedures
240 Long constants not implemented
NOTE
Errors larger than 240 can occur. If there are no
other errors in the program preceding "one of
these errors, contact Zilog.
50 ZEUS 50
PLZjSYS Zilog PLZjSYS
\ APPENDIX B
PLZCG ERROR NUMBERS
AND EXPLANATIONS
ERROR EXPLANATION
1 Inappropriate z-code format. The z-code file was
probably produced by an outdated version of the
PLZjSYS compiler. Recompile the source module
using the companion PLZjSYS compiler: specify the
Z8000 as the target machine.
2 Statement too large
3 Expression too large
4 Procedure call nesting too deep
5 Too many internal and global procedures defined
in module
6 Too many alternatives in select statement
7 Procedure too large
NOTE
Error numbers higher than 7 should be reported to
Zilog along with any pertinent information con-
cerning their occurrence.
(
51 ZEUS 51
SED Zilog SED
SED
A Noninteractive Text Editor*
1 Zilog 1
SED Zilog SED
PREFACE
2 Zilog 2
SED Zilog SED
TABLE OF CONTENTS
3 Zilog 3
SED Zilog SED
SECTION 1
INTRODUCTION
(
4 Zilog 4
SED Zilog SED
SECTION 2
COMMAND OPERATION
5 Zilog 5
SED Zilog SED
6 Zilog 6
SED Zilog SED
SECTION 3
LINE SELECTION
7 Zilog 7
SED Zilog SED
5. A period (.) matches any character except the ter- "' ...
minal new line of the pattern space.
6. A regular expression followed by an asterisk (*)
matches any number (including none) of adjacent
occurrences of the regular expression it follows.
7. A string of characters in square brackets ([ ])
matches any character in the string, and no others.
If the first character of the string is circumflex
(A), the regular expression matches any character
except the characters in the string and the termi-
nal new line of the pattern space.
8. A concatenation of regular expressions is itself a
regular expression. It matches the concatenation
of strings that match the components of the regular
expression.
9. A regular expression between the sequences \( and
\) is identical to the regular expression, but has
side-effects described in Section 4.3.
10. The expression \d means the same string of charac-
ters matched by an expression enclosed in \( and \)
earlier in the same pattern. Here g is a single
digit. The string specified begins with the gth
occurrence of \(, counting from the left. For
example, the expression A\{.*\)\l matches a line
beginning with two repeated occurrences of the same
string.
11. The null regular expression standing alone (for
example, II) is equivalent to the last regular
expression compiled.
To use one of the special characters:
*[ ]
\
I
as a literal to match an occurrence of itself in the input,
precede the special character with a backslash (\).
If a context address is to match the input, the whole pat-
tern within the address must match some portion of the pat-
tern space.
'"",- ./
8 Zilog 8
SED Zilog SED
Examples:
lanl matches lines 1, 3, 4 in the sample text
lan.*anl matches line 1
IAanl matches no lines
1.1 matches all lines
1\.1 matches line 5
Ir*anl matches lines 1,3, 4 (number = zero!)
I\(an\).*\ll matches line 1
9 Zilog 9
SED Zilog SED
SECTION 4
FUNCTIONS
10 Zilog 10
SED Zilog SED
, ./
11 Zilog 11
SED Zilog SED
NOTE
Within the text put in the output by these
functions, leading blanks and tabs will
disappear, as always in ~ commands. To
get leading blanks and tabs into the output,
precede the first desired blank or tab by a
backslash; the backslash will not appear-in
the output.
Example:
The list of editing commands:
n
a\
XXXX
d
applied to the standard input produces:
In Xanadu did Kubhla Khan
XXXX
Where Alph, the sacred river, ran
XXX X .
Down to a sunless sea.
In this particular case, the same effect is produced by
either of the two following command lists:
n n
i\ c\
XXX X XXXX
d
12 Zilog 12
SED Zilog SED
13 Zilog 13
SED Zilog SED
Examples:
Applied to the standard input, the following command,
s/to/by/w changes
produces, on the standard output:
In Xanadu did Kubhla Khan
A stately pleasure dome decree:
Where Alph, the sacred river, ran
Through caverns measureless by man
Down by a sunless sea.
and, on the file "changes":
Through caverns measureless by man
Down by a sunless sea.
If the nocopy option is in effect, the command:
s/[.,;?:]/*P&*/gp
produces:
A stately pleasure dome decree*P:*
Where Alph*P,* the sacred river*P,* ran
Down to a sunless sea*P.*
In nocopy mode, the command:
/X/s/an/AN/p
produces
In XANadu did Kubhla Khan
and the command:
/X/s/an/AN/gp
14 Zilog 14
SED Zilog SED
produces:
In XANadu did Kubhla KhAN
15 Zilog 15
SED Zilog SED
Examples:
Assume that the file notel has the following contents:
Note: Kubla Khan (more properly Kublai Khan; 1216-
1294) was the grandson and most eminent successor of
Genghiz (Chingiz) Khan, and founder of the Mongol
dynasty in China.
The following command:
/Kubla/r notel
produces:
In Xanadu did Kubla Khan
Note: Kubla Khan (more properly Kublai Khan;
1216-1294) was the grandson and most eminent suc-
cessor of Genghiz (Chingiz) Khan, and founder of
the Mongol dynasty in China.
A stately pleasure dome decree:
Where Alph, the sacred river, ran
Through caverns measureless to man
Down to a sunless sea.
16 Zilog 16
SED Zilog SED
Example:
The commands
Ih
lsi did.*//
Ix
G
s/\n/ :/
17 Zilog 17
SED Zilog SED
18 Zilog 18
SED Zilog SED
19 Zilog 19
SHELL Zilog SHELL
1 Zilog 1
.'
SHELL Zilog SHELL
PREFACE
2 Zilog 2
SHELL Zilog SHELL
TABLE OF CONTENTS
3 Zilog 3
SHELL Zilog SHELL
LIST OF ILLUSTRATIONS
Figure
2-1 A Version of the man Command ••••••••••••••••••••••• 24
3-1 ZEUS Signals ••••••••••••••••••••••••••••••••••••••• 32
3-2 The touch Command •••••••••••••••••••••••••••••••••• 34
3-3 The ~ Command ••••••••••••••••••••••••••••••••••• 34
4 Zi10g 4
SHELL Zilog SHELL
SECTION 1
BASIC TASKS
1.1 Introduction
The shell is a command programming language that provides an
interface to the .ZEUS Operating System. Its features
include control-flow primitives, parameter passing, vari-
ables, and string sUbstitution. Constructs such as while,
if-then-else, case, and for are available. Two-way communi-
cation is possible between the shell and commands. String-
valued parameters, typically file names or flags, can be
passed to a command. A return code that is set by commands
can be used to determine control flow, and the standard out-
put from a command can be used as shell input.
The shell modifies the environment in which commands run.
Input and output can be redirected to files, and processes
that communicate through pipes can be invoked. Commands are
found by searching directories in the file. Commands can be
read either from the terminal or from a file.
5 Zilog 5
SHELL. Zilog SHELL
cc pgm.c &
calls the C compiler to compile the file RSID.~. The trail-
ing & is an operator that instructs the shell to run the
command in the background. To help keep track of such a
process, the shell- reports its process number following its
creation. A list of currently active processes can be
obtained using the Ra command.
6 Zilog 6
SHELL Zilog SHELL
7 Zilog 7
SHELL Zilog SHELL
8 Zilog 8
SHELL Zilog SHELL
('
1.7 Quoting
Characters that have a special meaning to the shell, such as
<, >, *, 1, I, &, and, are called metacharacters. (A com-
plete list of metacharacters is given in Appendix B.) Any
character preceded by a backslash {\} is quoted and loses
its special meaning. The \ itself is not echoed, so
echo \1
echoes a single 1 and
echo \\
echoes a single \. To allow long strings to be continued
over more than one line, the sequence \new line is ignored.
The \ is convenient for quoting single characters, but
clumsy when more than one character needs quoting. A string
of characters can be quoted by enclosing the string between
single quotes. For example,
echo xx'****'xx
echoes
xx****xx
The quoted string can contain new lines, which are
preserved; it cannot contain a single quote. This quoting
mechanism is the simplest and is recommended.
A third quoting mechanism uses double quotes (Section 3.5).
1.8 Prompting
When the shell is used from a terminal, it issues a prompt
before reading a command. By default, this prompt 1S a dol-
lar sign ($); it can be changed by the PSI command. For
example,
PSl=yesdear
sets the prompt to be the string yesdear.
If a new line is typed and further input is needed, the
shell issues the > prompt. Sometimes this can be caused by
mistyping a quote mark. If it is unexpected, an interrupt
9 Zilog 9
SHELL Zilog SHELL
1.10 Summary
Is
Print the names of files in the current directory.
Is >file
Put the output from la into ~.
Is I wc -1
Print the number of files in the current directory.
Is I grep old
Print those file names containing the string ~.
Is I grep old I wc -1
Print the number of files whose names contain the string
~.
cc pgm.c &
Run ~ in the background.
10 Zilog 10
SHELL Zilog SHELL
SECTION 2
SHELL PROCEDURES
2.1 Introduction
The shell reads and executes commands contained in a file.
For example,
sh file args. •. ]
calls the shell to read commands from~. Such a file is
called a command procedure or shell procedure. Arguments
can be supplied with the call and are referred to in ~
using the positional parameters such as $1. For example, if
~the file ~ contains
who I grep $1
then
sh wg fred
is equivalent to
who I grep fred
ZEUS files have three independent attributes: read, write,
and execute. The ZEUS command chmod (1) can be used to make
a file executable. For example,
chmod +x wg
ensures that the file ~ has execute status. Following
this, the command
wg fred
is equivalent to
sh wg fred
This allows shell procedures and programs to be used inter-
changeably •. In either case, a new process is created to run
the command.
In addition to providing names for the positional parame-
ters, the number of pOSitional parameters in the call is
available as $#. The name of the file being executed is
available as $0.
11 Zilog 11
SHELL Zilog SHELL
12 Zilog 12
SHELL Zilog SHELL
esac
The shell attempts to match ~ with each pattern in the
order in which the patterns appear. If a match is found,
the associated command-liat is executed, and execution of
13 zilog 13
SHELL Zilog SHELL
esac
··..
*) • • • , ,
*) • • • , ,
14 Zilog 14
SHELL Zilog SHELL
The call
edg stringl string2 file
is then equivalent to the command
ed file «%
g/stringl/s//str~ng2/g
w
%
(~,,~
15 Zilog 15
SHELL Zilog SHELL
16 Zilog 16
SHELL Zilog SHELL
Except for $?, the following are set initially by the shell.
$? is set after executing each command.
$? The exit status (return code) of the last com-
mand executed as a decimal string. Most com-
mands return a zero exit status if they com-
plete successfully; otherwise, a nonzero exit
status is returned. Testing the value of
return codes is dealt with under if and while
commands.
$# The number of positional parameters in decimal.
Used, for example, in the append command to
check the number of parameters.
$$ The process number of this shell in decimal.
Since process numbers are unique among all
existing processes, this string is frequently
used to generate unique temporary file names.
For example,
ps a >/tmp/ps$$
...
rm /tmp/ps$$
17 Zilog 17
SHELL Zilog SHELL
18 Zilog 18
SHELL Zilog SHELL
19 Zilog 19
SHELL Zilog SHELL
for i
do •••
done
Shift is a shell command that renames the positional parame-
ters $2, $3 ••• as $1, $2... and loses $1.
Another use for the while/until loop is to wait until some
external event occurs and then run some commands. In an
until loop, the termination condition is reversed. For
example,
until test -f file
do sleep 300; done
commands
loops until ~ exists. Each time around the loop, it
waits for five minutes before trying again.
20 Zilog 20
SHELL Zilog SHELL
/
(
can be written using an extension of the ~ notation as,
if •••
then
elif •••
then •••
elif •••
fi
The following example is the touch command, which changes
the "last modified" time for a list of files. The command
can be used in conjunction with ~ (1) to force recompila-
tion of a list of files.
flag=
for i
do case $i in ..
-c) flag=N, ,
*) if test -f $i
then In $i junk$$; rm junk$$
elif test Sflag
then echo file \'$i\' does not exist
else >$i
fi
esac
done
The -c flag in this command forces subsequent files to be
created if they do not already exist. Otherwise, if the
file does not exist, an error message is printed. The shell
variable !lgg is set to some non-null string if the -c argu-
ment is encountered. The commands
In ••• ; rm •••
make a link to the file and then remove it, thus causing the
last modified date to be updated.
The sequence
if commandl
then command2
fi
can be written
commandl && command2
Conversely,
commandl I I command2
21 Zilog 21
SHELL Zilog SHELL
22 Zilog 22
SHELL Zilog SHELL
The command
set -x
produces an execution trace. Following parameter substitu-
tion, each, command is printed as it is executed. Both flags
can be turned off by entering
set -
The current setting of the shell flags is available as $-.
23 Zilog 23
SHELL Zi10g SHELL
cd /usr/man
: 'colon is the comment command'
: 'default is nroff ($N), section 1 ($s)'
N=n s=l
for i
do case $i in
[1-9*] s=$i ;;
-t) N=t; ;
-n) N=n;;
-*) echo unknown flag \'$i\' ;;
*) if test -f man$s/$i.$s
then ${N}roff manO/${N}aa man$s/$i.$s
else: 'look through all manual sections'
found=no
for j in 1 2 3 4 5 6 7 8 9
do if test -f man$j/$i.$j
then man $j $i
found=yes
fi
done
case $found in
no) echo 'Si: manual page not found'
esac
fi
esac
done
24 Zilog 24
SHELL Zilog SHELL
SECTION 3
KEYWORD PARAMETERS
3.1 Introduction
Shell variables are given values by assignment or by invok-
ing a shell procedure. An argument to a shell procedure of
the form ~=value that precedes the command name causes
value to be assigned to ~ before execution of the pro-
cedure begins. The value of ~ in the invoking shell is
not affected. For example,
user=fred command
executes command with~~ set to~. The -k flag causes
arguments of the form ~=yalue to be interpreted in this
way anywhere in the argument list. Such names are called
keyword parameters. If any arguments remain, they are
available as positional parameters $1, $2, and so on.
The ~ command can also be used to set positional parame-
ters from within a procedure. For example,
set - *
sets $1 to the first file name in the current directory, $2
to the next, and so on. The first argument (-) ensures
correct treatment when the first file name begins with a -
25 Zilog 25
SHELL Zilog SHELL
26 Zilog 26
. .
Colon (:) is a command built into the shell and does nothing
once its arguments have been evaluated. If any of the vari-
ables ~, ~, or Qin are not set, the shell abandons
execution of the procedure.
27 Zilog 27
SHELL Zilog SHELL
blank interpretation
Following the above substitutions, the resulting
characters are broken into nonblank words (blank
interpretation). For this purpose "blanks" are
the characters of the string $IFS. By default,
this string consists of blank, tab, and new line.
The null string is not regarded as a word unless
28 Zilog 28
SHELL Zilog SHELL
29 Zilog 29
SHELL Zilog SHELL
The command
echo "$@"
passes the positional parameters, unevaluated, to ~ and
is equivalent to
echo "$1" "$2" •••
The following chart gives, for each quoting mechanism, the
shell metacharacters that are evaluated.
metacharacter
,
\ $ * "
, n n n n n t
Y n n t n n
" y y n y t n
t terminator
y interpreted
n not interpreted
30 Zilog 30
SHELL Zilog SHELL
31 Zilog 31
SHELL Zilog SHELL
1 hangup
2 interrupt
3* quit
4* illegal instruction
5* trace trap
6* lOT system call
7* Unused (formerly EMT instruction)
8* floating point exception
9 kill (cannot be caught or ignored)
10* Unused (formerly bus error)
11* .segmentation violation
12* bad argument to system call
13 write on a pipe with no one to read it
14 alarm clock
15 software termination (from kill (1»
16 unassigned
32 Zilog 32
SHELL Zilog SHELL
33 Zilog 33
SHELL Zilog SHELL
flag=
trap 'rm -f junk$$; exit' 1 2 3 15
for i
do case $i in
-c) flag=N;;
*} if test -f $i
then In $i junk$$; rm junk$$
elif test $flag
then echo file \'$i\' does not exist
else >$i
esac
done
d='pwd'
for i in *
do if test -d $d/$i
then cd $d/$i
while echo "$i:"
trap exit 2
read x
do trap : 2; eval $x; done
fi
done
34 Zilog 34
.SHELL Zilog SHELL
35 Zilog 35
SHELL Zilo9 SHELL
36 Zilo9 36
SHELL Zilog SHELL
37 Zilog 37
..
SHELL Zilog SHELL
APPENDIX A
GRAMMAR
i.t9: ~
input-output
.n.am.e = value
simple-COmmand: i.t9
simple-command ~
command: simple-command
( command-.l.i.a.t )
{ command-.l.i.a.t }
for ~ do command-~ done
for ~ in ~ do command-.l.i.a.t done
while command-liat do command-.l.i.a.t done
until command-liat do command-~ done
case ~ in ~-~ ••• esac
if command-.l.i.a.t then command-.l.i.a.t ~-~ fi
pipeline: command
pipeline I I command
andor: pipeline
andor && pipeline
andor I I pipeline
command-~:· andor
command-~ ;
command-~ &
cornmand-~ ; andor
cornmand-~ & andor
input-output: >~
<~
»~
«~
~: ~
& digit
&-
~-~: pattern cornmand-.l.i.a.t;;
pattern: ~
pattern I ~
38 Zilog 38
, ,
empty:
~: a sequence of nonblank characters
~: a sequence of letters, digits, or under-
scores starting with a letter
digit: o 1 2 3 456 7 8 9
...
39 Zilog 39
SHELL Zilog SHELL
\. APPENDIX B
METACHARACTERS AND RESERVED WORDS
Syntactic
pipe symbol
&& "andf" symbol
II "orf" symbol
,. command separator
,.., case delimiter
& background commands
( ) command grouping
< input Eedirection
« input from a here document
> output creation
,
» output append
Patterns
Substitution
${ ••• } substitute shell variable
" ... " substitute command output
40 Zilog 40
SHELL Zilog SHELL
Quoting
\ quote the next character
••• ' quote the enclosed characters except for'
" ••• " quote the enclosed characters except
for $, " \, or n
Reserved Words
if then else elif fi
case in esac
for while until do done
{ }
41 Zilog 41
UUCP Zilog UUCP
UUCP INSTALLATION*
.
'\"
1 Zilog 1
UUCP Zilog UUCP
PREFACE
,(
l'-l
2 Zilog 2
UUCP Zi10g UUCP
TABLE OF CONTENTS
(
3 Zi10g 3
UUCP Zilog UUCP
4 Zilog 4
UUCP Zilog UUCP
SECTION 1
INTRODUCTION
1.1 General
Uucp is a series of programs that permits communication
between ZEUS systems using either dial-up or hardwired com-
munication lines. It is used for file transfers and remote
command execution.
Each system participating in the uucp network has a spool
directory that stores work to be done. There are three
types of files used for the execution of work: data files,
work files, and execution files. Data files contain data to
be transferred to remote systems. Work files contain the
directions for file transfers between systems. Execution
files contain the directions for ZEUS command executions
that involve the resources of one or more systems.
The uucp system consists of four primary and two secondary
programs. The following are primary programs:
uucp creates work files and gathers data files in the
spool directory for the transmission of files
uux creates work files, executes files, and gathers
data files for the remote execution of ZEUS com-
mands
uucico executes the work files for data transmission
uuxqt executes ZEUS execution files
The secondary programs are:
uulog updates the log file with new entries and reports
on the status of uucp requests
uuclean removes old files from the spool directory
1.2 Security
The uucp system, if left unrestricted, lets anyone execute
any command and copy in or out any file that is
readable/writable by the uucp login user. Necessary precau-
tions should be taken as required by the local implementa-
tion.
(
5 Zilog 5
UUCP Zilog UUCP
6 Zilog 6
UUCP Zilog UUCP
SECTION 2
THE UUCP PROGRAl<1S
2.1 Uucp
The uucp command is the primary interface with th~ system.
It sets up file copying and is similar to the ZEUS copy com-
mand, cp. Uucp is invoked by the command line
uucp [ option ] ... source ••• destination
where source and destination contain the prefix system name
specifying the system on which files reside-or the system on
which the files will be copied.
2.1.1 Options
The following options are valid for the uucp command:
-d Make directories when necessary for copying
the file.
-c Use the specified source for the transfer.
Do not copy source files to the spool direc-
tory.
-gletter Insert letter as the grade in the name of the
work file. This can be used to change the
order of work for a specified system.
-m Send mail on completion of the work.
The following options are used primarily for debugging:
-r Queue the job, but do not start the uucico
program.
-s.di.t. Use directory .diI. for the spool directory.
-xn,wn Rwn is the desired level of debugging output.
7 Zilog 7
UUCP Zilog UUCP
8 Zilog 8
UUCP Zilog UUCP
9 Zilog 9
UUCP Zilog UUCP
2.2 Uux
The uux command sets up the execution of a command if the
execution system and some of the files are remote. The syn-
tax of the uux command is
uux [ - ] [ option J ••• command-string
where commang-string is composed of one or more arguments.
All special shell characters such as <, >, I, and ~ must be
quoted, either by quoting the entire command string or by
quoting the character as a separate argument. Within
commang-string, the command and file names can contain a
system-name! prefix. All arguments must contain an exclama-
tion mark (!) if they are to be treated as files and to be
copied to the execution system. The minus sign (-) indi-
cates that the standard input for commang-string must be
from the standard input of the uux command. The options,
which are for debugging, are the following:
-r do not start uucico or uuxqt after queuing
the job
-xnym nYm is the level of debugging output desired
The command
pr abc I uux - usg!lpr
sets up the output of ~ ~ as standard input to a line
printer (lpr) command to be executed on system ~.
Uux generates an execute file containing the names of the
files required for execution, the user1s login name, the
destination of the standard output, and the command to be
executed. The execute file is placed in the spool directory
for local execution or is sent to the remote system using a
generated send command (Type 3 in Section 2.1.3).
Uux generates receive command files (Type 2) for files that
are not on the execution system. These command files are
placed on the execution machine and executed by the uucico
program if the local system has permission to place files in
the remote spool directory.
The execute file is processed by the uuxqt program on the
execution system. It is composed of several lines, each
containing an identification character and one or more argu-
ments. There is no set order for the lines and not all must
be present. Each line is described in the following sec-
tions.
10 Zilog 10
UUCP Zilog UUCP
,
r
(
11 Zilog 11
UUCP Zilog UUCP
2.3 Uucico
The copy in, copy out (uucico) program performs the follow-
ing communications functions between two systems:
$ scans the spool directory for work
$ places a call to a remote system
$ negotiates a line protocol to be used
$ executes all requests from both systems
$ logs work requests and work completions
Uucico can be started by a system daemon, by one of the
uucp, uux, uuxqt, or uucico programs, directly by the user,
or by a remote system. The uucico program must be specified
as the shell field in the /etc/passwd file for the uucp
logins.
When started by a remote system, the program is in SLAVE
mode. When started by any other method, the program is in
MASTER mode, and a connection is made to a remote system.
The MASTER mode operates in one of two ways. If a system
name is specified, that system is called and work is done
only for that system. If a system name is not specified,
the program scans the spool directory for systems to call.
12 Zilog 12
UUCP Zilog UUCP
13 Zilog 13
UUCP Zilog UUCP
14 Zilog 14
UUCP Zilog UUCP
15 Zilog 15
UUCP Zilog UUCP
2.4 Uuxqt
The uucp command execution (uuxqt) program executes execute
files generated by uux. The uuxqt program is started by
either theuucico or uux programs. The program scans the
spool directory for execute files (prefix X.). Each execute
file is checked to see if all the required files are avail-
able. If so, the command line or send line is executed.
Uuxqt is initiated by executing the shell with the -c option
after the appropriate standard input and standard output
have been opened. If the standard output is specified, the
program creates a send command or copies the output file as
designated.
2.5 Uulog
The uucp programs create individual log files for each pro-
gram invocation. Periodically, uulog can be executed to
prepend these files to the system log file. This method of
logging minimizes file locking of the log file during pro-
gram execution.
The uucp log inquiry (uulog) program merges the individual
log files and outputs specified log entries. The output
request is specified by the following options:
-s~ Print entries where ~ is the remote system
name.
-uJJ.an Print entries for user JJ.an.
16 Zilog 16
UUCP Zilog UUCP.
2.6 Uuclean
The uucp spool directory cleanup (uuclean) program is
started by the cron process once a day. It removes files
that are more than three days old from the spool directory.
These are usually files for work that could not be com-
pleted.
The uuclean program should be owned by uucp with the setuid
bit set (mode 4700).
The options available for uuclean are:
-d,dll The directory to be scanned is ~.
17 Zilog 17
UUCP Zilog UUCP
SECTION 3
UUCP INSTALLATION
3.1 General
Installing uucp under ZEUS requires little effort. The uucp
files and directories are described here to facilitate
tailoring uucp to a specific environment.
The following three directories are required for execution
{default values appear within parentheses}:
program {/usr/lib/uucp} This directory contains the
executable. system programs and the system
files.
spool {/usr/spool/uucp} This spool directory is
used during uucp execution.
xqtdir (/usr/spool/uucp/.XQTDIR) This directory is
used during execution of execute files.
The names program, spool, and xgtdir are used in this sec-
tion as a shorthand form to represent their corresponding
directory path names.
The modes of spool and xqtdir should be mode 0777, that is,
readable, writable, and executable by everyone •.
3.2.1 Myname
This file contains the name of the local system and is used
by uucico and mail to identify themselves to other systems.
This file should be owned by uccp and should be readable by
others (mode 0644).
18 Zilog 18
UUCP Zilog UUCP
3.2.2 L-Dev~ces
3.2.3 L-Dialcodes
This file contains entries with location abbreviations used
in the L.sys file (for example, py, mh, or boston). The
entry format is
abb dial-seq
where ~ is the abbreviation and ~-~ is the dial
sequence to call that location.
The line
py 165-
is set up so that entry py7777 sends 165-7777 to the dial-
unit.
19 Zilog 19
uuCP Zilog uUCP
3.3.1 Userfile
This file contains user accessibility information. It
specifies four types of constraints:
1. which files can be accessed by a normal user of the
local machine
2. which files can be accessed from a remote computer
3. which login name is used by a particular remote
computer
4. whether a remote computer should be called back in
order to confirm its identity
Each line in the file has the following format
login,sys [c] path name [path name] •••
where login is the login name for a user or the remote com-
puter, ~ is the system name for a remote computer, ~ is
the optional call-back required flag, and ~ ~ is a
path name prefix that is acceptable for ~.
The constraints are implemented as follows:
1. When the program is obeying a command stored on the
local machine (MASTER mode) the path names allowed
are those given for the first line in the user file-
that has a login name matching the login name of
the user who entered the command. If no such line
is found, the first line with a null login name is
used.
2. When the program is responding to a command from a
remote machine (SLAVE mode) the path names allowed
are those given for the first line in the file that
has a system name matching the system name of the
remote machine. If no such line is found, the
first one with a null system name is used.
3. When a remote computer logs in, the login name that
it uses must appear in the user file. There can be
several lines with the same login name, but one of
them must either have the name of the remote system
or must contain a null system name.
4. If the line matched contains a ~, the remote
machine is called back before any transactions take
place.
20 Zilog 20
UUCP Zilog UUCP
The line
u,m /usr/xyz
allows machine m to log in with name ~ and request the
transfer of files whose names start with /usr/xyz.
The line
dan, /usr/dan
allows the ordinary user, ~, to issue commands for files
whose names start with /usr/dan.
The lines
u,m /usr/xyz /usr/spool
u, /usr/spool
allow any remote machine to log in with name ~,. If its
system name is not m, it can only ask to transfer files
whose names start with /usr/spool.
The lines
zeus, /
, /usr
allow any user to transfer files beginning with /usr. The
user with login a.l.Ui can transfer any file.
3.3.2 L.sys
Each entry in this file represents one system that can be
called by the local uucp programs. The fields are described
below.
SYSTEM NAME
The name of the remote system.
TIME
This string indicates the days-of-week and times-of-day when
the system is called (for example, MoTuTh0800-1730). Alter-
natively, the string can be "passive" to show that only the
remote system can initiate a conversation. If the field is
passive, the remaining fields are ignored.
21 Zilog 21
UUCP Zilog UUCP
DEVICE
This is either ACU or the hardwired device to be used for
the call. For hardwired devices, the last part of the spe-
cial file name is used (for example, ttyO).
SPEED
This is the line speed for the call (for example, 300).
PHONE
The phone number is made up of an optional alphabetic abbre-
viation and a numeric part. The abbreviation is one that
appears in the L-dialcodes file (for example, mh5900, bos-
ton995-9980) •
For hardwired devices, this field contains the same string
as the device field.
LOGIN
The login information is given as a series of fields and
subfields in the format
expect send [expect send] ...
where expect is the string expected to be read and ~ is
the string to be sent when the expect string is received.
The expect field is made up of subfields of the form
expect[-send-expect] •••
where the ~ is sent if the prior expect is not success-
fully read and the expect following the ~ is the next
expected string.
(
22 Zilog 22
UUCP Zilog UUCP
23 Zilog 23
UUCP Zilog UUCP
SECTION 4
UUCP ADMINISTRATION
4.1 General
This section describes some events and files that must be
administered for the uucp system. Some administration can
be accomplished by shell files initiated by crontab entries.
Others require manual intervention. Some sample shell files
are given toward the end of this section.
(
24 Zilog 24
UUCP Zilog UUCP
25 Zilog 25
UUCP Zilog UUCP
26 Zilog 26
UUCP Ziiog UUCP
27 Zilog 27
VI Zilog VI
,4'tI~' .. '
I';
I"
i Zilog i
VI zilog VI
ii Zilog ii
VI Zilog VI
TABLE Op·CONTENTS
iv Zilog iv
VI Zilog VI
LIST OF TABLES
Table
5-1 File Manipulation Commands ••••••••••••••.••••••••• 40
6-1 Frequently Used Options ••.••••••••••.••••••••••••• 45
6-2 Magic Option Extended Operators •••••••••••••••••.. 48
B-1 Operators Used for Corrections and Changes ••.••••• 61
(
v Zilog v
VI Zilog VI
vi Zilog vi
VI Zilog VI
SECTION 1
INTRODUCTION
1.1 General
Vi (Visual) is a display oriented interactive text editor in
which the display acts as a window into the file being
edited. Changes are reflected in the display, and this sim-
plifies modifications. The regularity and the mnemonic
assignment of commands makes the editor command set easy to
remember and use. The full command set of the more tradi-
tional, line-oriented editor ex is available with vi, and it
is easy to switch between the two editing modes.
Vi can be used on a wide variety of display terminals. New
terminals are easily driven after editing a terminal
description file. While it is advantageous to have an
"intelligent" terminal that can insert and delete lines and
characters from the local display, the editor functions well
on "dumb" terminals with low-bandwidth telephone lines. The
editor optimizes response time by using a smaller window and
a different display updating algorithm. The command set of
vi can be used as a one-line-window editor on hard-copy ter-
minals, storage tubes, and "glass TTYs."
This document was written on the assumption that the system
being used is a Zilog S8000, that the system console is a
Lear Siegler ADM-31, and that the system software is Zilog
ZEUS, a super-set of UNIX.
1 Zilog 1
VI Zilog VI
2 Zilog 2
VI Zilog VI
(
\. , Character erase: the erase character is usually
CTRL-h
1.4 Invoking vi
When the system is up and running, set the terminal type, as
shown:
%setenv TERM <code> (RETURN)
where: % is the system prompt
setenv is the command for setting the environment
TERM is a required keyword
<code> is the terminal type code to be entered
For the Lear Siegler terminal, <code> is adm3l
(RETURN) is the RETURN key
For other terminals, and additional information relevant to
setting the terminal type, refer to Appendix A.
After the terminal type has been set, invoke vi. The com-
mand format is
% vi [-t <tag>] [-r[<filename>]] [+[<command>]]
[+<n>] [+/<string>] [-1] [<filename>] (RETURN)
where: % is the system prompt
3 Zilog 3
VI Zilog VI
NOTE
Do not include the square brackets ([1) and
the angle brackets «» in the command.
Examples:
1. The simplest vi command is to invoke vi for editing a
single file:
%vi <filename> <RETURN>
where: <filename> is the name of the file to be edited.
NOTE
All entries must be terminated by a RETURN. For
the remainder of this document, neither RETURN nor
the system prompt is shown in the system commands;
however, it is assumed that each command is ter-
minated by RETURN.
4 Zilog 4
VI Zilog VI
5 Zilog 5
VI Zilog VI
1.7 Leaving vi
To leave vi and return to the shell, use the command
ZZ
If changes have been made to the text, the contents of the
vi buffer are written back into the original file, and the
editor exits. If no changes have been made, the editor
exits.
It is also possible to write the changes to the file without
leaving vi b~ using the command
6 Zilog 6
VI Zilog VI
( :w
To exit vi (quit) without writing the ch~nges, use the com-
mand
:q!
1.8 vi and ex
Vi is one mode of editing within the line-oriented editor
ex. Some operations are easier in ex than in vi, such as
systematic changes in line-oriented material. Experienced
users often mix vi and ex commands to facilitate their work.
When vi is running, it is possible to escape to ex with the
command
Q
7 Zilog 7
VI Zilog VI
8 Zilog 8
VI Zilog VI
/
l
\
,
1.10 Uppercase Terminals
Vi can be used on uppercase-only terminals by using the nor-
mal terminal typing conventions. All characters are con-
verted to lowercase characters. However, each upper case
character must be preceded with a backslash (\). The combi-
nation "\character" does not echo until the backs lash is
followed by the second character.
The following characters are not available on uppercase-
only-terminals:
{ }
These characters can be entered as shown below:
For { use \(
For } use \}
For use \A
For ,I use \1
For use \'
1.12 Abbreviations
Vi has a number of short commands that abbreviate longer
commands that have been introduced above. These commands
are listed on the quick reference card.
9 Zilog 9
VI Zil,og VI
1.16 Counts
A count is an argument that affects the number of times the
command is executed, or the number of lines affected.
Several vi commands use a preceding count that affects the
operation of the command. Some of the most common are the
following:
10 Zilog 10
VI Zilog VI
11 Zilog 11
VI
Zilog VI
12
Zilog 12
VI Zilog VI
SECTION 2
vi DISPLAY CONTROL
NOTE
Certain "dumb" terminals cannot scroll up. In
this case, CTRL-U clears the display and refreshes
it with a line that is farther back in the file
(towards the top).
(-
13 Zilog 13
VI Zilog VI
14 Zilog 14
VI Zilog VI
15 Zilog 15
VI Zilog VI
16 Zilog 16
VI Zilog VI
To move the cursor to the end of the current line, use "$."
The command
[<n>]f<c>
moves the cursor to the nth subsequent occurrence of the
character <c>. The default is the next occurrence. Repeat
by using the semicolon (;). The inverse command is
[<n>]F<c>
This performs the same function, but moves the cursor back-
ward (into the preceding text). Repeat with a semicolon.
To move the cursor to the character preceding the nth
occurrence of the character <c>, enter:
[<n>]t<c>
To move the cursor backwards to the character following the
nth occurrence of the character <c>, enter:
[<n>]T<c>
(
17 Zilog 17
VI Zilog VI
2.5 Tags
It is possible to mark a position in the editor file with a
single letter tag, and then to return to any particular tag.
To tag a position in text, use the command
m<tag>
where the tag is any letter of the alphabet.
To return to the tag, use the command
'<tag>
When using operators (such as the delete operator) with a
tagged line, it may be convenient to operate on entire lines
(for example, to delete entire lines), rather than to the
exact position of the tag. In this case, use the form
'<tag>
rather than the form
'<tag>
18 Zilog 18
. .
VI Zilog VI
f
(,
For example, the command
d'<tag>
deletes entire lines from the position of the cursor to the
line with the tag.
19 Zilog 19
VI Zilog VI
20 Zilog 20
VI Zilog VI
..
\.
(
21 Zilog 21
VI Zilog VI
22 Zilog 22
VI Zilog VI
SECTION 3
EDIT COMMANDS
3.1 General
In general, the edit commands use text mode. Text mode is
initiated by entering of one of the various insert commands.
Following the entry of the insert command, all subsequent
keystrokes become text insertions. The text insert mode is
always terminated by striking the (ESC) key.
Many related editor commands are invoked by the same alpha
key and differ only in that one is given by a lowercase key,
and the other is given by an uppercase key. The uppercase
key usually aiffers from the lowercase key only in the sense
of direction: the uppercase key operates backward and/or up
and the lowercase key operates forward and/or down.
Using any of the text mode commands, it is possible to
insert one letter, or many lines of text. To insert more
than one line of text, strike the RETURN key in the middle
of the input. A new line is then created for text and the
insertion can continue. For slow or "dumb" terminals"the
editor may wait to redraw the tail of the screen. In this
case, the new text overwrites existing lines on the display.
This avoids delays that occur if the editor attempts to keep
the tail of the display up to date. The display is updated
correctly when text mode is terminated.
Those characters normally used at the system command level
for character or line deletion can also be used in text mode
(e.g., CTRL-h or #; and @, CTRL-x or CTRL-u, as appropri-
ate). CTRL-H always erases the last input character,
regardless of the erase character.
Backspacing (while in text mode) does not erase characters.
The cursor moves backwards, but the characters remain on the
display. This is useful for entering similar text. The
display is updated after the escape. To correct the display
immediately, use the ESC, and reenter text mode.
It is not possible to backspace around the end of a line.
To back up for a correction on a previous line, use ESC and
then move the cursor back to the previous line. Make the
correction, return and then reenter the appropriate text
command.
(
23 Zilog 23
VI Zilog VI
NOTES
The character CTRL-W erases a whole word and
leaves a space after the previous word. This is
useful for backing up quickly for an insert.
It is not possible to erase characters with CTRL-W
unless these characters were entered in text mode.
Following the "i" (or other insert mode operator), all sub-
sequent string of characters or text entered on the terminal
are inserted in the file, until insert mode is terminated.
To terminate insert mode, strike ESC (escape). On certain
"dumb" terminals, when text is inserted, the display appears
to overwrite the original text. When insert mode is ter-
minated, all inserted and previous text is displayed prop-
erly.
A variation of the "i" command is
Ai
24 Zilog 24
VI Zilog VI
is equivalent.
In general, most of the insert commands can have a preceding
count. For example, the command
5iapple
repeats the word "apple" five times:
appleappleappleappleapple
In the following description the preceding count is not
always shown.
The command
a ..
also enters the vi text mode. The difference between the
two commands is that with the command "i," text is inserted
before the cursor (to the left), whereas with "a," text is
inserted after the cursor (to the right). The command Ita II •
This opens the existing text and adds new text below the
current line. Similarly, the command
o
opens and adds new text above the current line. Both com-
mands are terminated with ESC. A preceding count opens n
lines.
It is also possible to insert non-printing characters in the
text. Refer to Section 8.2.
("
25 Zilog 25
VI Zilog VI
26 Zilog 26
VI Zilog VI
I
\
~ To delete a word backwards (to the left of the cursor),
enter
[<n>]db
or
d[<n>]b
The default is one word.
To delete n single characters, position the cursor on the
appropriate starting character, and enter the command
[<n>]d<space>
This is equivalent to the x command. The default is one
space.
A variation of the "d" command is
d$
o
The operator nco changes entire words. To change n words,
enter the command
[<n>]cw
When the commmand is entered, the end of the text to be
changed is marked with the symbol "$". Enter the replace-
ment text, and terminate text entry with ESC. The default
is one word.
A variation of the "c" command is
c$
which changes the rest of the text on the current line. An
equivalent command is
C
When operating on a line of text, it is often desirable to
delete the characters up to the "first instance of a charac-
ter. To do so, use the command
[<n>]df<x>
where f<x> locates the nth occurrence of the character <x>
following the cursor. The default is the first occurrence
of <x>. This command deletes the text up to--and
including--the character <x>. A variant is the command
[<n>]dt<x>
where the operator f is replaced by the t. In this
instance, the text is deleted up to--but not including--the
character <x>. The command
T
is similar, but it operates in the reverse of the t
operator--that is, it operates in the preceding text.
To delete n entire lines, use the delete operator twice:
[<n>1dd
The default is one line.
On a "dumb" terminal, the editor may sometimes erase the
entire line on the screen and replace it the symbol "@" at
the far left. This does not correspond to any line in the
28 Zilog 28
VI Zilog VI
( and
29 Zilog 29
VI Zilog VI
c/<string>/+n
In editing a document, it is usually easiest to edit in
terms of sentences, paragraphs and sections. The operators
n(n and n)n can be used with the delete operator. For
example, the command
[<n>]d)
deletes the rest of n sentences. The default is from the
cursor position to the end of the current sentence. Simi-
larly,
[<n>]d(
performs one of two deletions:
1. With the cursor at the beginning of a sentence, the
command deletes the previous n sentences, or
2. When the cursor is not at the beginning of a sen-
tence, the command deletes the text from the cursor
back to the beginning of n sentences. The default
is the beginning of the current sentence. The edi-
tor displays the extent of the change; it also
indicates when a change will affect text that is
not shown on the display.
To repeat the command more than once, use the period (.)
key.
that reverses the last change made. The undo command can
undo the preceding undo command--that is, the first undo
command can return the text to its original state, and the
second command can reinsert the change, but it can involve
several lines. The undo command reverses only a single
change. However, after having made more than one change to
a line, the line can be restored to its original state with
the command U.
Deleted text can be recovered even when the undo operator
does not recover it. Recovering lost text is discussed in a
separate section.
30 Zilog 30
VI Zilog VI
31 Zilog 31
VI Zilog VI
CTRL-X
CTRL-U
which erases all input on the current line. In general, the
kill character does not erase back around an end of line,
nor will it erase characters that were not inserted with
the current text mode command. To make corrections on the
previous line--after a new line"has been started--use the
following procedure:
1. Strike ESC to terminate input mode.
2. Move the cursor as appropriate to make the correc-
tion.
3. Return and continue in input mode. When continu-
ing, the operator "An is often convenient for
appending the current line.
32 Zilog 32
VI Zilog VI
SECTION 4
REARRANGING AND DUPLICATING TEXT
4.1 General
By definition, a sentence ends with a period (.), an excla-
mation point (1), or a question mark (?); and is followed by
either the end of a line, or two spaces. Any number of
closing parens, brackets, or quotation marks may appear
after the closing punctuation marks, but before the spaces
or new line.
The operators ( and ) move the cursor to the beginning and
the end of the previous and next sentences, respectively.
Similarly, the operators { and }, and the operators [[ and
J] move over paragraphs and sections, respectively. The
square bracket operators require a double operator entry
because they can move the cursor an appreciable distance.
While it is easy to return with the back quotation marks "
these commands could still be frustrating if they were easy
to execute accidentally.
By definition, a paragraph begins after each empty line, and
also at each of a set of paragraph macros. (Refer to the
NROFF and TROFF documentation in the ZEUS Programmer's
Manual.) The paragraph macros can be changed or extended by
assigning a different string to the the paragraphs option in
EXINIT. The sentence and paragraph commands can be given
counts to operate over groups of sentences and paragraphs.
Sections in the editor begin after each macro in the sec-
tions option. Section boundaries are always line and para-
graph boundaries.
It is possible to look through a large document by using the
section commands. It is also possible to use a preceding
count with each of the section and paragraph commands. The
section commands interpret a preceding count as a different
window size in which to redraw the screen display at the new
location. This window size is the base size for newly drawn
windows until another size is specified. This is useful
when looking for a particular section on a slow terminal.
It is possible to give the first section command a small
count, and then see each successive section heading in a
small window.
(
33 Zilog 33
VI Zilog VI
4.2 Buffers
Vi has the following buffers:
1. A single, unnamed buffer, where the last delete or
changed text is saved, and
2. A set of named buffers--a through z--that can be
used to save or move text, either within a file, or
between files.
The buffers are used by the "yank" and "put" operators
described in section 4.3.
34 Zilog 34
VI Zilog VI
fI
, Examples:
The command
yw
yanks the word on which the cursor is located. The command
4yw
yanks the word on which the cursor is located, and the fol-
lowing three words into the unnamed buffer. The command
"a12yw
yanks 12 words into buffer a.
An ordinary delete command saves the text in the unnamed
buffer, so that an ordinary put command (p or P, described
below) can move it elsewhere. However, the unnamed buffer
contents are lost when files are changed; therefore, to
change text from one file to another, be sure to use a named
buffer.
Text that has been yanked can be reinserted (put) in the
(, text with the operators p or P, where the command syntax is
"[<buffer>]p
where quotation marks and <buffer> indicate the buffername,
where the yanked text was stored. Tha operator "p" rein-
serts the yanked text after or below the cursor, and the
operator "P" reinserts the text before or above the cursor.
Command syntax is identical for both P and p operators. If
a buffer is not specified, the default is the unnamed
buffer.
The text being yanked can be part of a line, or an object
such as a sentence that spans more than one line. In this
case, when the text is replaced, it is replaced after (or
before) the cursor, depending on the command. If the text
forms whole lines, then it is returned in whole lines,
without changing the current line.
The command
I<n>JYP
yanks a copy of n lines, and then reinserts the same text
immediately prior to the current line. The result is that
there are two identical text lines and the cursor moves to
( the top line. The command
35 Zilog 35
VI Zilog VI
[<n>]Yp
is similar, but it copies n lines and places them after
(below) the current line, so that there are two identical
lines. For example, the command 3YP repeats the line of
text three times. The default is one line of text.
The yank command, like the delete and change commands, can
be used with a string search. The command
y/<string>/-<n>
yanks the characters from the cursor position to the nth
line preceding the string match. Similarly, the command
y/<string>/+<n>
yanks characters from the cursor to the nth line following
the string.
The same buffers can be used with the delete operators to
move blocks of text within the file or to another file.
Moving a block of text requires three operations:
1. delete & store n lines
2. move cursor to the new location
3. "put" the text.
Example:
Delete five lines of text and temporarily store them in
buffer a:
36 Zilog 36
VI Zilog VI
:e <filename>
where <filename> is the other file to be edited. (These
commands are described in a l'ater section.)
NOTE
37 Zilog 37
VI Zilog VI
38 Zilog 38
VI Zilog VI
( SECTION 5
FILE MANIPULATION
39 Zilog 39
VI Zilog VI
.,' ~
40 Zilog 40
VI Zilog VI
41 Zilog 41
VI Zilog VI
42 Zilog 42
VI Zilog VI
/
(
'- :r <name>
To edit a set of files in succession, first enter
all of the filenames as arguments in the command
:n <namel> <name2> .... <namex>
,then edit each one, in turn, using the command
:n
It is also possible to use the command ":n" and specify a pattern
to be expanded, such as with an asterisk (*) or a set of
characters to match. This can also be done with the initial vi
command.
The command
:ta
is very useful for editing large programs. It uses a data base
of function names and their locations (which can be created by the
program ctags(l).
See the ZEUS Programmer's Reference Manual) for
/'
finding a function with a name.
I
If the ":ta" command requires the editor to switch files, any current
work must be written to a file or abandoned prior to switching files.
To relocate a tag, repeat this command without any arguements.
To read in the output from a shell command, use an exclamation point
with a shell command <cmd>, as shown:
:!<cmd>
.(
43 Zilog 43
VI Zilog VI
44 Zilog 44
VI Zilog VI
SECTION 6
OPTIONS
6.1 General
As noted previously, the options in the editor ex are also
available and easy to use with Vi. The most useful ones are
listed in Table 6-1 below.
45 Zilog 45
VI Zilog VI
46 Zilog 46
VI Zilog VI
,::
(
invoked. (Note that all commands that start with a colon
are ex commands.) It is good practice to list these com-
mands on a single line.
It is possible to put any number of the option commands in
the environment variable EXINIT. When options are set in
the environment, then they are automatically set at each
entry to vi. For example, to set autoindent, autowrite and
terse, the command would be (using csh):
setenv EXINIT 'set ai aw terse'
(
47 Zilog 47
VI Zilog VI
48 Zilog 48
VI Zilog VI
I
\
Note that in the nomagic mode the primitives
and *
are used with a preceding "\".
49 Zilog 49
VI Zilog VI
50 Zilog 50
VI Zilog VI
52 Zilog 52
VI Zilog VI
6.13 Scroll
The amount of scroll when using the CTRL-d, CTRL-u and HZ"
commands can be altered by issuing
:se scroll=<val>
where: <val> is the amount of scroll (number of lines)
6.14 Terse
The error diagnostics can be shortened with the command
:se terse
and lengthened again with
:se noterse
This is desirable for the more experienced user.
6.15 Window
The number of lines in a text window can be altered with
this command
:se window=<val>
For slow terminals (600 baud or less), the window size is 8;
for medium terminals (1200 baud), the size is 16; and for
high speed terminals, the full screen size minus 1 is
assigned.
53 Zilog 53
VI Zilog VI
54 Zilog 54
VI Zilog VI
SECTION 7
RECOVERING LOST INPUT
55 Zilog 55
VI Zilog VI
56 Zilog 56
VI Zilog VI
SECTION 8
MISCELLANEOUS
(
57 Zilog 57
VI Zilog VI
58 Zilog 58
VI Zilog VI
APPENDIX A
SPECIFYING TERMINAL TYPE
Terminal
Hewlett-Packard 262lA/P 2621
Hewlett-Packard 264x 2645
Microterm ACT-IV act4 *
Microterm ACT-V actS *
Lear Siegler ADM-3a adm3a *
Lear Siegler ADM-3l adm3l
Human Design Concept 100 clOO
Datamedia 1520 dm1520 *
Datamedia 2500 dm2500
Datamedia 3025 dm3025
Perkin-Elmer Fox fox *
Hazeltine 1500 h1500
Heathkit h19 h19
Infoton 100 ilOO
Teleray 1061 tl06l
Dec VT-52 vt52 *
To enter the type of terminal, use the command
setenv TERM <code>
where <code> is the terminal type code listed above.
Example:
The terminal normally supplied with the Zilog System
8000 is the Lear Siegler ADM-3l. Use the following
command:
setenv TERM adm3l
59 Zilog 59
VI Zilog VI
60 Zilog 60
VI Zilog VI
APPENDIX B
vi CORRECTION CHARACTERS
Operator Function
CTRL-H Deletes the last character input
CTRL-W Deletes the last word input, as defined by
the operator lib"
erase your system erase character; same as CTRL-H
kill your system line delete character
\ Escapes a following erase, kill or CTRL-H
ESC Escape key; terminates "text mode
DEL Delete key; interrupts an text mode opera-
tion, terminating it abnormally
RETURN Carriage return, or more simply, RETURN;
starts a new line.
CTRL-D Backspaces over auto indent
OCTRL-D Kills all the auto indent
"'CTRL-D Same as above, but restores indent next line
CTRL-V Quotes the next non-printing character into
the file.
61 Zilog 61
VI Zilog VI
62 Zilog 62
VI Zilog VI
APPENDIX C
vi SYMBOL DICTIONARY
This appendix gives the uses the editor makes of each char-
acter. The characters are presented in their order in the
ASCII character set: Control characters come first, then
most special characters, then the digits, upper and then
lowercase characters.
The information for each character includes the meaning it
has as a command, and any meaning it has during an insert.
If it has only meaning as a command, then only this is dis-
cussed.
CTRL-@ Not a command character. If typed as the
first character of an insertion it is
replaced with the last text inserted, and the
insert terminates. Only 128 characters are
saved from the last insert; if more charac-
ters were inserted the mechanism is not
available. A A@ cannot be part of the file
due to the editor implementation.
CTRL-A Unused.
CTRL-B Backward window. A count specifies repeti-
tion. Two lines of continuity are kept if
possible.
CTRL-C Unused.
CTRL-D As a command, scrolls down a half-window of
text. A count gives the number of (logical)
lines to scroll, and is remembered for future
CTRL-D and CTRL-U commands. During an
insert, backtabs over autoindent white space
at the beginning of a line; this white space
cannot be backspaced over.
CTRL-E Unused.
CTRL-F Forward window. A count specifies repeti-
tion. Two lines of continuity are kept if
possible.
CTRL-G Equivalent to :fCR, printing the current file
name, whether it has been modified, the
current line number and the number of lines
in the file, and the percentage of the way
through the file that you are.
63 Zilog 63
VI Zilog VI
64 Zilog 64
VI Zilog VI
66 Zilog 66
VI Zilog VI
* Unused.
+ Same as RETURN when used as a command.
, Reverse of the last f F t or T command, look-
ing the other way in the current line. Espe-
cially useful after hitting too many ; char-
acters. A count repeats the search.
Retreats to the previous line at the first
non-white character. This is the inverse of
+ and RETURN. If the line moved to is not on
the screen, the screen is scrolled, or
cleared and redrawn if this is not possible.
If a large amount of scrolling would be
required the screen is also cleared and
( redrawn, with the current line at the center.
67 Zilog 67
VI Zilog VI
68 Zilog 68
VI Zilog VI
(.
69 Zilog 69
VI Zilog VI
70 Zilog 70
VI Zilog VI
(
\ Q Quits from vi to ex command mode. In this
mode, whole lines form commands, ending with
a RETURN. For all commands; the editor ex
prompts with the colon.
R Replaces characters on the screen with char-
acters you type (overlay fashion). Terminate
with (ESC).
S Changes whole lines, a synonym for cc. A
count substitutes for that many lines. The
lines are saved in the numeric buffers, and
erased on the screen before the sUbstitution
begins.
T Takes a single following character, locates
the character before the cursor in the
current line, and places the cursor just
after that character. A count <n> repeats
the effect n times. Most useful with opera-
tors such as d.
U Restores the current line to its state
before you started changing it.
V Unused.
w Moves forward to the beginning of a word in
the current line, where words are defined as
sequences of blank/non-blank characters. A
count <n> repeats the effect n times.
x Deletes the character before the cursor. A
count repeats the effect, but only characters
on the current line are deleted.
Y Yanks a copy of the current line into the
unnamed buffer, to be put back by a later p
or P; a very useful synonym for yy. Count
<n> yanks n lines. May be preceded by a
buffer name to put lines in that buffer.
ZZ Exits the editor (Same as :xRETURN). If any
changes have been made, the buffer is written
out to the current file. Then the editor
quits.
[[ Backs up to the previous section boundary. A
section begins at each macro in the sections
option, normally a ".NH" or ".SH" and also at
lines which start with a formfeed L• Lines
A
71 Zilog 71
VI Zilog VI
72 Zilog 72
VI Zilog VI
~
i
\, n objects. For example, both 3c) and c3)
change the following three sentences.
d An operator d deletes the following object;
an object is an operator like w. If more
than part of a line is affected, the text is
saved in the numeric buffers. A count <n>
affects n objects. Thus 3dw is the sames as
d3w.
e Advances to the end of the next word, defined
as for band w. A count <n> repeats the
effect n times.
f Finds the first instance of the next charac-
ter following the cursor on the current line.
A count <n> repeats n times.
g Unused.
and AN.
k Up arrow. Moves the cursor one line up.
is a synonym.
1 Right arrow. Moves the cursor one character
to the right. SPACE is a synonym.
m Marks the current position of the cursor in
the mark register, which is specified by the
next character a-z. Return to this position
or use with an operator using' or '.
n Repeats the last string search command.
(
73 Zilog 73
VI Zilog VI
74 Zilog 74
VI Zilog VI
75 Zilog 75
-.
VI Zilog VI
76 Zilog 76
VI Zilog VI
APPENDIX D
vi QUICK REFERENCE
File manipulation
:w write back changes
:wq write and quit
:q quit
: q! quit; discard changes
:e~ edit file ~
: e! reedit, discard changes
:e i edit alternate file (also CTRL-A)
:w ~ write file ~
:w I overwrite file ~
: lcmd run ~, then return
:n edit next file in arglist
:f show current file and line number (also CTRL-g)
:sh escape to shell (CTRL-d) for return)
77 Zilog 77
VI Zilog VI
Line positioning
H home window line
L last window line
M middle window line
+ next line, at first non-white
previous line, at first non-white
RETURN same as carriage return; moves cursor to
beginning of next line
-j next line, same column
k previous line, same column
78 Zilog 78
VI Zilog VI
Miscellaneous operations
C change rest of line
D delete rest of line
s substitute chars
S substitute lines
J join lines
x delete character at cursor
X delete character before cursor
y yank lines
79 Zilog 79
VI Zilog VI
\
Entering/leaving vi
%vi name edit ~ at top
ZZ exit from vi, saving changes
The display
Last line Error messages, echoing input to :/ ?
and 1, feed back about i/o and large
changes.
@lines On screen only, not in file (on dumb terminals)
-lines Lines past end of file
CTRL-x Control characters, CTRL-? is delete
tabs ~xpand to spaces, cursor at last
Simple Commands
dw delete a word
de delte a word, leave punctuation
dd delete a line
3dd delete 3 lines
i.t.eAt.ESC insert text ~
cw~ESC change word to ~
ea.s.ESC pluralize word
xp transpose characters
80 Zilog 80
YACC Zilog YACC
YACC*
YET ANOTHER COMPILER-COMPILER
c
1 Zilog 1
YACC Zilog YACC
PREFACE
2 Zilog 2
YACC Zilog YACC
TABLE OF CONTENTS
3 Zilog 3
YACC Zilog YACC
4 Zilog 4
YACC Zilog YACC
SECTION 1
INTRODUCTION
6 Zilog 6
YACC Zilog YACC
7 Zilog 7
YACC Zilog YACC
SECTION 2
BASIC SPECIFICATIONS
8 Zilog 8
YACC Zilog YACC
A
·· G ;
9 Zilog 9
YACC Zilog YACC
(
~.
i'
II' •
symbol is the left side of the first grammar rule in the
rules section. It is recommended to declare the start sym-
bol explicitly in the declarations section using the %start
keyword:
%start symbol
The end of the input to the parser is signaled by a special
token called the endmarker. If the tokens up to, but not
including, the endmarker form a structure that matches the
start symbol, the parser function returns to its caller
after the endmarker is seen and accepts the input. If the
endmarker is seen in any other context, it is an error.
It is the job of the user-supplied lexical analyzer to
return the endmarker when appropriate (Section 4). Usually,
the endmarker represents some I/O status, such as "end-of-
file" or "end-of-record."
10 Zilog 10
YACC Zilog YACC
SECTION 3
ACTIONS
11 Zilog 11
YACC Zilog YACC
A B $ACT C
{ x = $2; y = $3; }
;
12 Zilog 12
YACC Zilog YACC
node ( L, nl, n2 )
creates a node with label L, and descendants nl and n2, then
returns the index of the newly created node. The parse tree
is built by supplying actions such as:
expr : expr '+' expr
{ $$ = node( '+', $1, $3)~ }
in the specification.
Other variables can be defined for the actions. Declara-
tions and definitions can appear in the declarations sec-
tion, enclosed in the marks %{ and %}. These declarations
and definitions have global scope, so they are known to the
action statements and the lexical analyzer. For example,
%{ int variable = O~ %}
can be placed in the declarations section, making variable
accessible to all of the actions. The Yacc parser uses only
names beginning in "yy"~ such names must be avoided.
In these examples, all the values are integers. A discus-
sion of other value types is found in Section 11.
13 Zilog 13
YACC Zilog YACC
SECTION 4
LEXICAL ANALYSIS
14 Zilog 14
YACC Zilog YACC
15 Zilog 15
YACC Zilog YACC
( SECTION 5
HOW THE PARSER WORKS
16 Zilog 16
YACC Zilog YACC
• reduce 18
refers to grammar rule 18, while the action
IF shift 34
refers to ~tate 34.
Suppose the rule being reduced is
A x y z .,
The reduce action depends on the left symbol (A in this
case), and the number of symbols on the right side (three in
this case). To reduce, first pop off the top three states
from the stack. (The number of states popped equals the
number of symbols on the right side of the rule.) After pop-
ping these states, a state is uncovered that is the state
the parser was in before beginning to process the rule.
Using this uncovered state and the symbol on the left side
of the rule, perform what is in effect a shift of A. A new
state is obtained, pushed onto the stack, and parsing con-
tinues. There are significant differences between the pro-
cessing of the left symbol (called a goto action) and an
ordinary shift of a token. The lookahead token is cleared
by a shift, and is not affected by a goto. The uncovered
state contains an entry such as:
A goto 20
causing state 20 to be pushed onto the stack and become the
current state.
In effect, the reduce action "turns back the clock" in the
parser, popping the states off the stack to go back to the
state where the right side of the rule was first seen. The
parser then behaves as if it had seen the left side at that
time. If the right side of the rule is empty, no states are
popped off the stack~ the uncovered state is in fact the
current state.
The reduce action is also important in the treatment of
user-supplied actions and values. When a rule is reduced,
17 Zilog 17
YACC Zilog YACC
the code supplied with the rule is executed before the stack
is adjusted. In addition to the stack holding the states,
another stack, running in parallel with it, holds the values
returned from the lexical analyzer and the actions. When a
shift takes place, the external variable yylval is copied
onto the value stack. After the return from the user code,
the reduction is carried out. When the goto action is done,
the external variable yyval is copied onto the value stack.
The pseudovariables $1, $2, etc. refer to the value stack.
The other two parser actions are conceptually much simpler.
The accept action indicates that the entire input has been
seen and that it matches the specification. This action
appears only when the lookahead token is the endmarker, and
indicates that the parser has successfully done its job.
The error action, on the other hand, represents a place
where the parser can no longer continue parsing according to
the specification. The input tokens it has seen, together
with the lookahead token, cannot be followed by anything
that results in a legal input. The parser reports an error,
and attempts to recover and resume parsing. The error
recovery (as opposed to the detection of error) is discussed
in Section 8.
Consider the specification
%token DING DONG DELL
%% .
rhyme sound place
;
sound DING DONG
;
place DELL
;
Send a,ccept
• error
state 2
rhyme sound_place
DELL shift 5
error
place go to 4
state 3
sound : DING_DONG
DONG shift 6
• error
state 4
rhyme . sound place_ (1)
reduce 1
state 5
place DELL_ (3)
• reduce 3
state 6
sound DING DONG_ ( 2)
reduce 2
In addition to the actions for each state, there is a
description of the parsing rules being processed in each
state. The _ character indicates what has been seen and
what is yet to come in each rule. Suppose the input is
DING DONG DELL
It is instructive to follow the steps of the parser while
processing this input.
Initially, the current state is state O. The parser refers
to the input to select among the actions available in state
0, so the first token (DING) is read, becoming the lookahead
token. The action in state 0 on DING is Ashift 3,n so state
3 is pushed onto the stack, and the lookahead token is
cleared. State 3 becomes the current state. The next
token, DONG, is read, becoming the lookahead token. The
action in state 3 on the token DONG is nshift 6,A so state 6
is pushed onto the stack, and the lookahead is cleared. The
stack now contains 0, 3, and 6. In state 6, without even
19 Zi10g 19
YACC Zilog YACC
20 Zilog 20
YACC Zilog YACC
SECTION 6
AMBIGUITY AND CONFLICTS
21 Zilog 21
YACC Zilog YACC
22 Zilog 22
YACC Zilog YACC
'\
I
IF Cl IF ( C2 ) Sl
and is looking at the ~. It can immediately reduce by the
simple-if rule to get
IF Cl stat
and then read the remaining input,
ELSE S2
and reduce
IF Cl stat ELSE S2
by the if-else rule. This leads to the first of groupings
of the input.
On the other hand, the ~ can be shifted, S2 read, and
then the right hand portion of
IF Cl IF C2 Sl ELSE S2
is reduced by the if-else rule to get
IF Cl stat
which is reduced by the simple-if rule. This leads to the
second of the groupings of the input, which is usually
desired.
The parser can do two valid things--there is a shift/reduce
conflict. The application of Disambiguating Rule 1 tells
the parser to shift in this case, which leads to the desired
grouping.
This shift/reduce conflict arises only when there is a par-
ticular current input symbol,~, and particular inputs
already seen, such as
IF ( Cl IF C2 Sl
There can be many conflicts, each associated with an input
symbol and a set of previously read inputs. The previously
read inputs are characterized by the state of the parser.
The conflict messages of Yacc are best understood by examin-
ing the verbose (-v) option output file. For example, the
output corresponding to the conflict state is:
24 Zilog 24
YACC Zilog YACC
The first line describes the conflict, glvlng the state and
the input symbol. The ordinary state description follows,
giving the grammar rules active in the state, and the parser
actions. Recall that the underline marks the portion of the
grammar rules that has been seen. Here, in state 23, the
parser has seen input corresponding to
IF cond stat
and the two grammar rules shown are active at this time.
The parser can do two possible things. If the input symbol
is~, it shifts into state 45. State 45 has as part of
its description the line
stat IF cond stat ELSE_stat
since the ~ has been shifted in this state. Back in
state 23, the alternative action (described by.) is to be
done if the input symbol is not mentioned explicitly in the
above actions. In this case, if the input symbol is not
~, the parser reduces by Grammar Rule 18:
(
25 Zilog 25
YACC Zilog YACC
{ SECTION 7
PRECEDENCE
26 Zilog 26
YACC Zilog YACC
%right '='
%1 ef t ' +' ,- ,
%left '*' 'I'
%%
. expr expr '= , expr
expr '+ ' expr
expr '- , expr
expr ' *, expr
expr 'I' expr
NAME
1
27 Zilog 27
YACC Zilog YACC
(
28 Zilog 28
YACC Zilog YACC
SECTION 8
ERROR HANDLING
29 Zilog 29
YACC Zilog YACC
30 Zilog 30
YACC Zilog YACC
31 Zilog 31
YACC Zilog YACC
SECTION 9
THE YACC ENVIRONMENT
and
# include <stdio.h>
32 Zilog 32
YACC Zilog YACC
33 Zilog 33
YACC Zilog YACC
.,(,....
\ "
SECTION 10
HINTS FOR PREPARING SPECIFICATIONS
10.1 General
This section contains miscellaneous hints on preparing effi-
cient, easy to change, and clear specifications. The indi-
vidual subsections are independent.
34 Zilog 34
YACC Zilog YACC
and
seq item
., seq item
In each case, the first rule is reduced for the first item
only, the second rule is reduced for the second and all
succeeding items.
With right recursive rules such as
seq item
item seq
;
the parser is a bit bigger, and the items are seen and
reduced from right to left. An internal stack in the parser
is in danger of overflowing if a very long sequence is read.
Thus, left recursion must be used.
It is worth considering whether a sequence with zero ele-
ments has any meaning, and if so, consider writing the
sequence specification with an empty rule:
seq 1* empty *1
seq item
;
Once again, the first rule is always reduced once before the
first item is read, then the second rule is reduced once for
each item read. Permitting empty sequences often leads to
increased generality. However, conflicts arise if Yacc is
asked to decide which empty sequence it has seen when it has
not seen enough to know.
35 Zilog 35
YACC Zilog YACC
decls /* empty */
{ dflag = 1; }
decls declaration
;
stats /* empty */
{ dflag = 0; }
stats statement
;
36 Zilog 36
YACC Zilog YACC
SECTION 11
ADVANCED TOPICS
37 Zilog 37
YACC Zilog YACC
This declares the Yacc value stack and the external vari-
ables yylval and yyval to have type equal to this union. If
Yacc was invoked with the -d option, the union declaration
is copied onto the y.tab.h file. Alternatively, the union
can be declared in a header file, and a typedef can be used
to define the variable YYSTYPE to represent this union.
Thus, the header file can also contain:
typedef union {
body of union
} YYSTYPE;
...
The header file must be included in the declarations section
by use of %{ and %}.
Once YYSTYPE is defined, the union member names must be
associated with the various terminal and nonterminal names.
The construction
< name >
38 Zilog 38
YACC Zilog YACC
(
39 Zilog 39
YACC Zilog YACC
APPENDIX A
YACC INPUT SYNTAX
tail MARK {In this action, eat up the rest of the file}
/* empty: the second MARK is optional */
40 Zilog 40
YACC Zilog YACC
·
I
defs /* empty */
defs def
;
rword : TOKEN
I LEFT
I RIGHT
I NONASSOC
I TYPE
;
nlist : nmno
I nlist nmno
I nlist ',' nmno
·,
nmno IDENTIFIER
/* NOTE: literal illegal with %type */
IDENTIFIER NUMBER
/* NOTE: illegal with %type */
,•
/* rules section */
rules : C_IDENTIFIER rbody prec
I rules rule
·
I
rbody : /* empty */
I rbody IDENTIFIER
I rbody act
41 Zilog 41
YACC Zilog YACC
( prec : /* empty */
I PREC IDENTIFIER
I PREC IDENTIFIER act
prec I ,• I
.,
I
42 Zilog 42
.
YACC Zilog YACC
APPENDIX B
A SIMPLE EXAMPLE
%{
i include <stdio.h>
i include <ctype.h>
int regs[26];
int base1
%}
%start list
%token DIGIT LETTER
%left , I '
%left , &•
%left '+' 1_'
%left '*' 'I' 1%'
%left UMINUS
1* supplies precedence for unary minus *1
%% 1* beginning of rules section *1
list 1* empty *1
list stat '\n'
list error '\n'
{ yyerrok 1 }
43 Zilog 43
..
stat expr
{ printf ( "%d\n", $1 ); }
LETTER '=' expr
., { regs[$l) = $3; }
{
'/ . $$ =
expr
$$ =
$1
$1 /
* $3;
$3;
}
}
I expr '% ' expr
{ $$ = $1 % $3; }
expr '&' expr
{ $$ = $1 & $3; }
expr 'I' expr
{ $$ = $1 I $3; }
'-' expr %prec UMINUS
{ $$ = $2; }
LETTER
{$$ = regs[$l); }
number
;
number DIGIT
{ $$ = $1; base = ($1==0) ? 8 10; }
number DIGIT
{ $$ = base * $1 + $2; }
;
%% /* start of programs */
yylex() { /* lexical analysis routine */
/* returns LETTER for a lower case letter */
/* yylval = 0 through 25 */
/* return DIGIT for a digit */
/* yylval = 0 through 9 */
/* all other characters */
/* are returned immediately */
int c;
while( (c=getchar(» -- , , ) { /* skip blanks */ }
/* c is now nonblank */
44 Zilog 44
YACC Zilog YACC
if ( islower( c {
yylval = c I a I ;
return LETTER ) ;
}
if( isdigit( c {
yylval = c 10 I ;
return( DIGIT ) ;
}
return( c ) ;
}
(
45 Zilog 45
..
YACC Zilog YACC
(
~.
\' ". ~
APPENDIX C
AN ADVANCED EXAMPLE
46 Zilog 46
YACC Zilog YACC
2.5 + ( 3.5 , 4. )
The 2.5 is used in an interval valued expression in the
second example, but this fact is not known until the , is
read; by this time, 2.5 is finished, and the parser cannot
go back. More generally, it .might be necessary to look
ahead an arbitrary number of tokens to decide whether to
convert a scalar to an interval. This problem is evaded by
having two rules for each binary interval valued operator:
one when the left operand is a scalar, and one when the left
operand is an interval. In the second case, the right
operand must be an interval, so the conversion is applied
automatically. Despite this evasion, there are still many
cases where the conversion can be applied or not, leading to
conflicts. They are resolved by listing the rules that
yield scalars first in the specification file; in this way,
the conflicts are resolved in the direction of keeping
scalar valued expressions sca~ar valued until they are
forced to become intervals.
This way of handling multiple types is very instructive, but
not very general. If there are many kinds of expression
types instead of just two, the number of rules needed
increase dramatically, and the conflicts even more dramati-
cally. Thus, while this example is instructive, it is
better practice in a normal programming language environment
to keep the type information as part of the value, and not
as part of the grammar.
The only unusual feature in lexical analysis is the treat-
ment of floating point constants. The C library routine
~ is used to do the actual conversion from a character
string to a double-precision value. If the lexical analyzer
detects an error, it responds by returning a token that is
illegal in the grammar, provoking a syntax error in the
parser, and error recovery.
%{
i include <stdio.h>
i include <ctype.h>
typedef struct interval {
double 10, hi;
} INTERVAL;
INTERVAL vmul{) , vdiv{);
double atof () ;
double dreg[ 26 1;
47 Zilog 47
YACC Zilog YACC
( INTERVAL vreg[ 26 ] ;
%}
%start lines
%union {
int ivaI;
double dval;
INTERVAL vval;
}
lines . /* empty */
.,
I lines line
dexp CONST
DREG
{$$ = dreg[$l]; }
dexp '+ ' dexp
{ $$ = $1 + $3; }
C-- dexp '- , dexp
48 Zi10g 48
YACC Zi10g YACC
{ = $1
*
$$ $3; }
dexp 1 1 dexp
{ $$ = $1 * $3; }
dexp dexp
1/1
{ $$ = $1 / $3; }
1- 1
dexp %prec UMINUS
{ $$ = - $2; }
1 ( 1 dexp I) 1
$$ = $2; }
.
,
{
vexp dexp
{ $$.hi = $$.10 = $1; }
1 ( 1 dexp , , , dexp I) 1
{
$$.10 = $2;
$$.hi = $4;
if( $$.10 > $$.hi ) { ..
printf( " interval out of order\n" ) ;
YYERROR;
}
}
VREG
{ $$ = vreg[$l]; }
vexp + 1 vexp
1
49 Zi10g 49
YACC Zilog YACC
%%
# define BSZ 50
/* buffer size for floating point numbers */
/* lexical analysis */
yylex(){
register c;
while( (c=getchar(»
, , )
{ /* skip over blanks */ }
if( isupper( c ){
yy 1 v al • ivaI = c ' A' ;
return( VREG );
}
if( islower( c ){
yylval.ival = c 'a';
return( DREG );
}
*cp = c;
if( isdigit( c ) continue;
if( c == , , ){
/*
if( dot++ II exp return(
will cause syntax error */
,
. I
);
continue;
}
if ( c -- 'e' ) {
if( exp++ ) return( 'e' );
/* will cause syntax error */
continue;
}
/* end of number */
break;
}
*cp = '\0';
if ( (cp-buf) >= BSZ
printf( "constant too long: truncated\n" );
else ungetc( c, stdin );
/* push back last char read */
(
50 Zilog 50
YACC Zilog YACC
dcheck( ·V ) INTERVAL Vi {
if( v.hi >= O. && v.lo <= O. ) {
printf( "divisor interval contains O.\n" );
return( 1 ) ;
}
return( 0 );
}
51 Zilog 51
YACC Zilog YACC
APPENDIX D
OLD FEATURES
52 Zilog 52
ZEUS Zilog ZEUS
(
.
1 Zilog 1
\,
I
ZEUS Zilog ZEUS
( PREFACE
,
and the ZEUS utilities Manual.
2 Zilog 2
ZEUS Zilog ZEUS
TABLE OF CONTENTS
2.6
.......... ....... ......... ... . 18
Using Files Instead of Terminal Input
and Output ••
... ...
2.7
2.8
Pipes •••••••
The Shell ...•....
·.. ·..................... 1920
SECTION 3 DOCUMENT PREPARATION
. .. .. . . . .
.. ...... ··.... .......
3.1 Introduction 23
3.2
3.3
Formatting Programs
Supporting Tools
. . ...
.......... .....·.. ...... 23
24
3.4 Hints for Preparing Documents ·. 25
SECTION 4 PROGRAMMING
4.1 Introduction ............... ........... .. 26
4.2
4.3
Programming the Shell .•
Programming in C ••.••••
· ...... .
·.... ....... ...
27
27
3 Zilog 3
ZEUS Zilog ZEUS
SECTION 1
GETTING STARTED
1.1 Logging In
Terminals are connected to the system by a high-speed asyn-
chronous line. Log in when the message login: appears on
the terminal. If this message is not on the screen, press
the RETURN key. If the message still does not appear, con-
tact the System Administrator for assistance.
When login: is displayed, enter the login name in lowercase,
followed by a RETURN. For terminals that have only upper-
case, it is possible to type commands in uppercase. If the
login name is typed in uppercase, the entire terminal ses-
sion must be performed in uppercase. The system does not
respond until a RETURN is entered. If a password is
required, the message Password: appears. Enter the pass-
word, followed by a RETURN. The password, which protects
files from unauthorized access, is not echoed on the screen.
When a prompt character appears on the screen, the system is
ready to accept commands. The prompt character is usually a
dollar sign ($) or a percent sign (%). (Messages of the day
or notifications that mail is being held can appear on the
screen before the prompt character.)
4 Zilog 4
ZEUS Zilog ZEUS
5 Zi10g 5
ZEUS Zilog ZEUS
character.
The ~(~) command can be used to change the erase and kill
characters. Backspace can also be used as an erase charac-
ter, and control-x can be used as a kill character.
1.5 Read-Ahead
Read-ahead capability allows typing to be done as fast as
possible, even while the system is responding to a command.
If typing is done while the system is outputting text, the
input characters appear intermixed with the output charac-
ters; however, they are interpreted in the correct order.
Several commands can be typed one after another without
waiting for each one to execute.
1.8 Mail
After logging in, the message
you have mail.
may appear. ZEUS provides a postal system, allowing for
communication with other users on the system. To read the
mail, type the command
6 Zilog 6
ZEUS Zilog ZEUS
7 Zilog 7
ZEUS Zilog ZEUS
8 Zilog 8
zms Zilog ZEUS
( SECTION 2
DAY-TO-DAY USE
9 Zilog 9
ZEUS Zilog ZEUS
10 Zilog 10
ZEUS Zilog ZEUS
NOTE
If a file is moved to another file that already
exists, the already existing contents are lost
forever.
To make a copy of a file, use the ~ command.
cp stuff tempI
makes a duplicate copy of §tuff in tempI.
The ~ command removes (deletes) files from a directory.
For example,
rm temp tempI
deletes the files t&mp and tempI.
12 Zilog 12
zms Zilog ZEUS
NOTE
Be very careful when using the rm command.
Once files are removed with the rm command,
they no longer exist in the directory and
can never be recovered.
A warning is displayed if one of the named files does not
exist. Otherwise~, like most ZEUS commands, does its work
silently.
(
13 Zilog 13
ZEUS Zilog ZEUS
.~.
14 14
ZEUS Zilog ZEUS
15 Zilog 15
zms Zilog ZEUS
bin
dev
etc
lib
~p
usr
These are the basic directories of files--the root of the
tree.
The full name of the path to be followed from the root
through the tree of directories to get to a particular file
is the path name. The path name of the file jynk is
Iz/your-name/junk
It is a universal rule in the ZEUS system that anywhere an
ordinary file name can be used, a path name can be used.
Here is a picture of the tree used in this document:
(root)
11\
11\
11\
bin· etc z dev tmp
1 1'\1 1 \ 1 I \ 1 I \ 1 I \
1 I \
1 I \
adam eve mary
11\ \
1 \ junk
junk temp
Observe that mary's jynk file is unrelated to eve's jynk
file.
To obtain a listing of files in another user's directory,
type
Is Iz/neighbor-name
To copy of one of these files, type
cp Iz/your-neighbor/his-file yourfile
If users do not want other people examining these files,
privacy can be arranged. Each file and directory has read-
write-execute permissions for the owner, a group, and every-
one else, which control file access. (See ~(~) and
chmod(L) for details.) For an executable file, the owner
generally has read, write, and execute permission; other
16 Zilog 16
ZEUS Zilog ZEUS
2.5.3 Subdirectories
It is convenient to arrange files so that all files on a
related subject are in a directory that is separate from
other projects. For example, when writing a manual, it
might be helpful to keep the text in a directory called
bQQk. To make the directory, use the command
mkdir book
This creates the directory called hQQk. To go to that direc-
tory, type
17 Zilog 17
ZEUS Zilog zms
cd book
Separate files can now be established in this directory.
The path name of this directory is:
/z/your-name/book
To move back up to the login directory (one level up in the
tree), type
cd ••
The double period ( •• ) indicates the parent of the currently
accessed directory. A single period (.) is an alternate name
for the working directory.
To remove the directory ~, type
rm book/*
rmdir book
The first command removes all files from the directory, and
the second removes the empty directory.
The symbol » operates very much like > does. It means add
the listed files to the end of the file that follows the
symbol. That is,
18 Zilog 18
ZEUS Zilog ZEUS
(..-.-
. cat fl f2 f3 »temp
means to add il, 12, and ! l to the end of whatever is
already in ~ (instead of overwriting the existing con-
tents of ~). As with >, if ~ does not exist, it is
created.
The symbol < means take the input for a program from the
following file instead of from the terminal. For example,
it is possible to create a file called script containing a
group of editing commands that produces a specified set of
changes. Typing
ed file <script
causes the set of editing commands to be executed throughout
the file.
As another example, ~ can be used to prepare a letter in
the file ~. Then, the letter can be sent to several people
with
mail adam eve mary joe <let
( 2.7 Pipes
A ~ is a means of connecting the output of one program to
the input of another program so that the two run as a
sequence of processes. A command line that uses pipes is
called a pipeline.
For example,
pr f g h
displays the files ~, g, and h, beginning each on a new
page. It is possible to display them together without page
breaks by entering
cat f g h >temp
pr <temp
rm temp
A simpler way to do this is to take the output of ~ and
connect it to the input of ~ by using a pipe.
cat f g h 1 pr
The vertical bar (I), which is the pipe command, means take
the output from~, which would normally have gone to the
( terminal, and put it into ~ to be formatted.
19 Zilog 19
zms Zilog zms
The pipeline
Is I pr -3
displays a list of files in three columns.
Any program that reads from the terminal can also read from
a pipe. Any program that writes to the terminal can also
drive a pipe. Any number of elements can be used in a pipe-
line.
Many zms programs are written so that they can take their
input from one or more files if file arguments are given.
If no arguments are given, the programs read from the termi-
nal and can be used in pipelines. One example is ~.
pr -3 abc
prints files A, h, and ~ in order, in three-column format.
The command
cat abc I pr -3
produces the same output; ~ prints the information coming
down the pipeline in three-column format.
20 Zilog 20
zros Zilog ZEUS
( type
ed file <script )script.out &
which saves the output lines in a file called script.QYt.
When initiating a command with &, the system replies with a
number called the process number, which identifies the com-
mand so that it can be stopped later. To stop the command
from executing, type
kill process-number
If the process number is forgotten, the command ~ lists the
process numbers of everything that 1£ is running. (It is
possible to use the command kill ~, which kills all the user
processes that are running. This command should, of course,
be used with caution.) The command ~ -a lists all programs
in the system that are currently running.
The command
(command-I; command-2; command-3) &
can be used to start three commands in the background. A
background pipeline can be started with
command-l I command-2 &
Just as the editor or some similar program can take its
input from a file instead of from the terminal, the shell
can read a file to get commands. For instance, suppose the
tabs on the terminal are to be set, and the date and who is
on the system are to be displayed every time the user logs
in. The three necessary commands (~, ~, ~) can be
put into a file called startup. To run this program, type
sh startup
The shell then runs with the file startup as input. This
has the same effect as entering the contents of startup on
the terminal.
To eliminate the need to type ~ each time, use the command
chmod +x startup
The chmod command marks the file as executable; the shell
recognizes this and runs it as a sequence of commands.
Thereafter, type only
« startup
21 Zilog 21
ZEUS Zilog ZEUS
22 Zilog 22
ZEUS Zilog ZEUS
,{". SECTION 3
DOCUMENT PREPARATION
3.1 Introduction
The ZEUS system has two major formatting programs for docu-
ment preparation: nroff, which produces output on terminals
and line printers, and troff, which drives a photo-
typesetter.
23 Zilog 23
ZEUS Zilog ZEUS
24 Zilog 24
ZEUS Zilog ZEUS
(
25 Zilog 25
.
ZEUS Zilog ZEUS
SECTION 4
PROGRAMMING
4.1 Introduction
The ZEUS system is a productive programming environment
because it offers a rich set of programming tools. Facili-
ties such as pipes, I/O redirection, and the capabilities of
the shell make it possible to do a job by pasting together
programs that already exist instead of writing from scratch.
The pipe mechanism allows fabrication of complicated opera-
tions out of spare parts that already exist. For example,
an early version of the spell program was
ca t ••• I tr ••• I tr ••• I sor t I uniq I comm
where ~ collected the files, the first ~ put each word on
a new line, and the second ~ deleted punctuation. The
information was then sorted into dictionary order. The Ynig
command discarded duplicates, and ~ printed words that
were in the text but not found in the dictionary.
The editor can be made to do things that would normally
require special programs on other systems. For example, to
list the first and last lines for each· file in a set of
files, the following can be laboriously typed
ed
e chapl.l
Ip
$p
e chapl.2
Ip
$p
etc.
An easier way is to type
Is chap* >temp
This lists the file names in the ~ file. Then this file
can be edited to incorporate the necessary series of editing
commands (using the global commands of ~). When these com-
mands have been written into script, the command
ed <script
produces the same output as the laboriously typed list of
26 Zilog 26
ZEUS Zilog ZEUS
)
commands. Alternately, since the~hell performs loops, it
is possible to repeat a set of commands over and over again
for a set of arguments. For example,
for i in chap*
do
ed $i <script
done
sets the shell variable ~ to each file name in turn, then
does the command. This command can be typed at the terminal
or put in a file for later execution.
4.3 Programming in C
ZEUS and most of the programs that run on it are written in
C. C is an easy language to learn and use. It is intro-
duced and fully described in ~ ~ Programming Language by
B. W. Kernighan and D. M. Ritchie (Prentice-Hall, 1978).
See the ZEUS Reference Manual for additional information.
27 Zilog 27
( ...~.
Be"erl Com·eats
Your feedbaCk about this documel1t helps us ucertaiD your l1eeda aDd fulfill them ill the future. PI....
take the time to fill out this quatioI1aire Uld retum it to us. this iDforJDAti.cm will be helpful to us Uld, ill
lima, to future usen of Ziloq producta.
Y~Neme: _________________________________________________________
~Nua: _______________________________________________________
~: -------------------------------------------------------
Tltleoi thiadoc:ument: _____________________________________________
(.J~
t •••• O •.••••••••••••••••••••••••• ~ •••••••••••••••••••• •••••••••••••••••••••••••••••••••••••••••••••••••••••• :
NO POSTAGE
111111 NECESSARY
IF MAILED
IN THE
UNITED STATES
··
·
~
System. Publications
..ader'.eo··....
Your feedback about thlI dOCUJDeDt helps us ucertain your needs ud fulfill them in the iutue. PI....
take the time to fill out thlI que8tiouira ud ratum it to us. thlI illiormation will be helpful to us ud, in
time, to future uer8 of Zi10q product..
Y~Nu.: _________________________________________________________
~N __: ________________________________________________________
~ ----------------------------------------------------------
Tltleoi thisd.o!;:ument: . _________________________________________________
If you fouzad ay DUatak_ in this document, please let us know what and where they are: _ _ _ _ __
•••• 0 •••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
""II
NO POSTAGE
NECESSARY
IF MAILED
IN THE
UNITED STATES
Zilog
Systems PubllcatioDS
1315 Dell Avenue
Campbell. California 95008
Attn: Publicatiou Manager
GOOOOO • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • •
Zilog, Inc. 1315 Dell Ave ., Campbell, California 95008 Telephone (408)370-8000 TWX 910-338-7621