EXTENDED MANUAL PAGES
SEC 9-6 EL VIS-A CLONE OF THE BERKELEY VI EDITOR 235 -DDATE
9.7. IC-INTEGER CALCULATOR
le is a simple RPN (Reverse Polish Notation) calculator. used for small calcula
tions and base conversions. All calculations are done using 32 bit integers. The standard input is usually a keyboard and the standard output requires a device with a
"termcap" entry. The program starts by interpreting any <args> as commands.
where the separation between arguments is considered to be the same as the ENTER key. For example.
ic 692 784+
After reading the arguments input is from the keyboard.
9.7.1. Stack Operations
The operation of this program is similar to an RPN calculator. A six level stack is used. The ENTER key pushes the stack up one level. For example. " ' 2+5" is entered as " 12 ENTER 5 +".
The top two entries on the stack are exchanged by the x command. and the stack
SEC. 9.7 le-INTEGER CALCULATOR 237 is rolled down one (popped) by the p key. The top of the stack may be cleared by pressing the back-space key. The whole stack and the registers are initialized by a z.
9.7.2. Numeric Entry
The input and output bases are initially decimal. but they may be changed using the i and 0 commands. The i command changes both bases. but the 0 command changes just the output base. These commands take a one character argument of h.
d. 0 or b to change to Hexadecimal. Decimal. Octal or Binary. While the input base is hexadecimal the letters a through J are used to represent the decimal values 1 0 through 15.
When the input base i s decimal: multiply. divide and remainder are signed. oth
erwise they are performed unsigned.
The output base may also be changed to ASCll (a). this causes the least significant 7 bits of a value to be displayed as a character. To input an ASCII value the translate (I) command may be used. it accepts one character as its argument.
9.7.3. Calculations
The arithmetic operations supported are: Negate ( " . "). Add (" + "). Subtract ("-"). Multiply ( ... .. ). Divide ("/"). and Remainder ("%"). The logical (Boolean) operations available are: NOT ( .. "). AND ( " &"). OR ( " I"). and EXCLUSIVE-OR (""").
After one of these operations the last top of stack value is saved. It may be restored by pressing I (L).
9.7.4. Saving Results
Ten temporary registers are available. The Store (s) command followed by a digit ( .. 0 ...... 9 .. ) will copy the top of the stack to the specified register. The Recall (r) command pushes the contents of a register onto the top of the stack.
If the Store command is followed by a "+" preceding the digit. then the top of the stack will be added to the specified "accumulator" register.
Values may also be written to a file. The w command writes the top of the stack.
using the current output base. to a file called "pad" in the current directory. If the user does not have write access to the current directory then the file Itmplpad,JUSER is used as the scratch pad. The scratch pad file is erased on the
first use of the w command within each new invocation of .. ic".
238 EXTENDED MANUAL PAGES CHAP. 9 9.7.5. Miscellaneous
The Quit (q) key causes an immediate exit. The m command temporarily leaves ie by invoking the shell as a sub-process. For help while using ie, hit the h key. If an erroneous key is pressed the bell will sound.
9.7.6. Command Summary
Write top of stack to scratch pad Exchange top of stack
le was written by Terrence W. Holm.
SEC. 9.8 INDENT -INDENT AND FORMAT e PROGRAMS 239 9.8. INDENT-INDENT AND FORMAT C PROGRAMS
Indent reads a C program in, rearranges the layout, and outputs a new C pro
gram that will compile to the same executable binary as the original one. The difference between the input and output is that the output is in a standard layout determined by a large number of options. For most of the options there are two choices, one that enables it and one that disables it.
If indent is called with no file files, it operates as a filter. If called with one file name, that file is reformatted and the result replaces the original file. A backup is created, however, with the suffix .BAK. If it is called with two file names, the first one is the input file and the second one is the output file. Only one file can be re for
matted at a time (e.g., one cannot call indent with *.c as argument; this is an error and will not work.).
9.8.1. Options
Many options are available. If you want to format a program to the "official"
MINIX format, use pretty, which calls indent with the proper options and then post
processes the output. The options listed below control the formatting style.
OPTION: -bad, -nbad
If -bad is specified, a blank line is forced after every block of declarations.
Default: -nbad.
OPTION: -bap, -nbap
If -bap is specified, a blank line is forced after every procedure body. Default:
-nbap.
OPTION: -bbb, -nbbb
If -bbb is specified, a blank line is forced before every block comment.
Default: -nbbb.
OPTION: -bc, -nbe
If -be is specified, then a newline is forced after each comma in a declaration.
-nbe turns off this option. The default is -nbe.
OPTION: -bl, -br
Specifying -bl lines up compound statements like this:
if ( ... ) [
code
240 EXTE:-.IDED MANUAL PAGES
Specifying -br (the default) makes them look like this:
if ( ... ) [ code
OPTION: -<n
The column in which comments on code start. The default is 33.
OPTION: -<dn
CHAP. 9
The column in which comments on declarations start. The default is for these comments to start in the same column as those on code.
OPTION: -<db, -ncdb
Enables (disables) the placement of comment delimiters on blank lines. With this option enabled, comments look like this:
f*
* this is a comment
*f
Rather than like this:
f* this is a comment *f
This only affects block comments, not comments to the right of code. The default is -<db.
OPTION: -<e, -nce
Enables (disables) forcing "else"s to cuddle up to the immediately preceding
" } " . The default is -<e.
OPTION: -<in
Sets the continuation indent to be n. Continuation lines will be indented that far from the beginning of the first line of the statement. Parenthesized expressions have extra indentation added to indicate the nesting, unless -Jp is in effect. -<i defaults to the same value as -i.
OPTION: -<Iin
Causes case labels to be indented n tab stops to the right of the containing switch statement. -<liO.S causes case labels to be indented half a tab stop. The default is -<liO. (This is the only option that takes a fractional argument.)
OPTION: -<In
Controls the placement of comments which are not to the right of code.
SEC. 9.8 INDENT-INDENT AND FORMAT C PROGRAMS 241 Specifying -d I means that such comments are placed one indentation level to the left of code. The default -dO lines up these comments with the code. See the sec
tion on comment indentation below.
OPTION: -din
Specifies the indentation, in character positions, from a declaration keyword to the following identifier. The default is -di 16.
OPTION: -dj, -ndj
-dj left justifies declarations. -ndj indents declarations the same as code. The default is -ndj.
OPTION: -ei, -nei
Enables (disables) special else-if processing. If enabled, ifs following elses will have the same indentation as the preceding if statement. The default is -ei.
OPTION: -fe l , -nfe l
Enables (disables) the formatting of comments that stan in column 1 . Often, comments whose leading ul" is in column I have been carefully hand formatted by the programmer. In such cases, -nfe I should be used. The default is -fe I .
OPTION: -in
The number of spaces for one indentation level. The default is 8.
OPTION: -ip, -nip
Enables (disables) the indentation of parameter declarations from the left mar
gin. The default is -ip.
OPTION: -In
Maximum length of an output line. The default is 78.
OPTION: -lp, -nip
Lines up code surrounded by parenthesis in continuation lines. If a line has a left paren which is not closed on that line, then continuation lines will be lined up to star! at the character position just after the left paren.
OPTION: -npro
Causes the profile files, .illdentpro in both the current directory and the user's home directory to be ignored.
OPTION: -pes, -npcs
If true (-pes) all procedure calls will have a space inserted between the name and the "(". The default i s -npcs.
242 EXTENDED MANUAL PAGES CHAP. 9 OPTION: -ps, -nps
If true (-ps) the pointer following operator "->" will be surrounded by spaces on either side. The default is -nps.
OPTION: -psI, -npsl
If true (-psI) the names of procedures being defined are placed in column I -their types, if any, will be left on the previous lines. The default is -psI.
OPTION: -se, -nse
Enables (disables) the placement of asterisks (*) at the left edge of all com
ments. The default is -se.
OPTION: -sob, -nsob
If -sob is specified, indent will swallow optional blank lines. You can use this to get rid of blank lines after declarations. The default is -nsob.
OPTION: -sI
Causes indent to take its input from stdin, and put its output to stdoUl.
OPTION: -Ttypename
Adds type name to the list of type keywords. Names accumulate: -T can be specified more than once. You need to specify all the typenames that appear in your program that are defined by #typedefs. Nothing will be harmed if you miss a few, but the program will not be formatted as nicely as it should. This sounds like a painful thing to have to do, but it is really a symptom of a problem in C: typedef causes a syntactic change in the language and indent cannot find all typedefs.
OPTION: -ITOff
Causes indent to format the program for processing by troff. It will produce a fancy listing in much the same spirit as vgrind. If the output file is not specified, the default is standard output, rather than formatting in place.
OPTION: -v, -nv
The -v flag turns on verbose mode; -nv turns it off. When in verbose mode,
indelll reports when it splits one line of input into two or more lines of output, and gives some size statistics at completion. The default is -nv.
9.8.2. User Profiles
You may set up your own profile of defaults to indent by creating a file called
.indent pro in either your login directory and/or the current directory and including whatever switches you like. Switches in .indent.pro in the current directory over
ride those in your login directory (with the exception of -T type definitions, which
SEC. 9 P.',1)D,I-INDENT AND FORMAT C PROGRAMS 243 just accumulate'. If indent is run and a profile file exists, then it is read to set up the program'S defaults. The switches should be separated by spaces, tabs or newlines.
Sv.,tches on the command line, however, override profile switches.
9.8.3. Comments
Indent assumes that any comment with a dash or star immediately after the start of comment (that is, "/*-" or "/*''') is a comment surrounded by a box of stars.
Each line of such a comment is left unchanged, except that its indentation may be adjusted to account for the change in indentation of the first line of the comment.
All other comments are treated as straight text. Indent fits as many words (separated by blanks, tabs, or newlines) on a line as possible. Blank lines break paragraphs.
If a comment is on a line with code it is started in the comment column, which is set by the �n command line parameter. Otherwise, the comment is started at n indentation levels less than where code is currently being placed, where n is specified by the -dn command line parameter. If the code on a line extends past the comment column, the comment starts further to the right, and the right margin may be automatically extended in extreme cases.
9.8.4. Preprocessor Lines
In general, indent leaves preprocessor lines alone. The only reformatting that it will do is to straighten up trailing comments. It leaves embedded comments alone.
Conditional compilation (#ifdef...#endif) is recognized and indent attempts to correctly compensate for the syntactic peculiarities introduced.
9.8.5. C Syntax
Indent understands a substantial amount about the syntax of C, but it has a for
giving parser. It attempts to cope with the usual sorts of incomplete and misforrned syntax. In particular, the use of macros like:
#define forever for(;;) is handled properly.