[net.sources] Sc 3.1

rgb@nscpdc.UUCP (01/27/87)

#	This is a shell archive.
#	Remove everything above and including the cut line.
#	Then run the rest of the file through sh.
#-----cut here-----cut here-----cut here-----cut here-----
#!/bin/sh
# shar:	Shell Archiver
#	Run the following text with /bin/sh to create:
#	README
#	sc.man
#	sc.doc
#	cmds.c
#	eres.sed
#	sres.sed
#	makefile
#	cvt.sed
# This archive created: Mon Jan 26 19:36:29 1987
# By:	Robert Bond (NSC Portland, Oregon)
echo shar: extracting README '(2477 characters)'
cat << \SHAR_EOF > README
This is a much modified version of the public domain spread sheet vc,
posted a year or two ago by Mark Weiser, orginally by James Gosling.

Changes since my last version:

1) Much linting for those who reported coredumps.  This version should
   be more portable.  On our 4.3 system, lint only complains about some
   functions whose values are always ignored.  On the 5.2 system it
   also complains about some hidden variables.  This is normal.  Yacc
   will complain about 14 shift reduce conflicts.  This is also normal.
2) The @avg bugs are fixed.
3) I added a "^" command to go to row 0
4) Trig and other math functions added.
5) Assorted bug fixes and cleanup.
6) Use crmode() instead of raw() for BSD
7) A couple of new region commands (erase and fill)
8) More cursor movement commands (goto and #)
9) All function names are unique within the first 7 characters.
10) More precision is retained in the saved files.

Due to some trademark name problems, I have changed the name back to
Gosling's original, sc.  I have modified the makefile to make it easy
for you to call it what you want (I saw at least five different names
in correspondence and on the net).  Just change "name=sc" to
"name=myfavoritename" and try "make myfavoritename".

Similarly, you can make the documentation with "make myfavoritename.man".
"make install" will make and install the code in EXDIR.  The
installation steps and documentation all key off of the name.  The
makefile even changes the name in the nroffable man page.  If you don't
have nroff, you will have to change sc.man yourself.

The code has been tested against a Vax running 4.2 and 4.3 and a National
ICM-3216 with system V.2.  The ICM has a National Semi 32016.  Just
check the makefile for the system flags.   I have heard reports of lots
of other machines which work.  I have added ifdefs for system III and for
Berkely 4.3.  If you have problems with lex.c, and don't care about arrow
keys, define SIMPLE (-DSIMPLE in the makefile).  SIMPLE causes the arrow
keys to not be used.

Many thanks to all of the kind souls who wrote with fixes and bug reports.
In particular, my "beta" testers, Kim Rochat and Dave Shanks, and to Eric
Goldman for the floating point stuff.

Disclaimer:

Sc is not a product of National Semiconductor.  It is supplied as is with
no warrenty, express or implied, as a service to Usenet readers.

					Bob Bond

    Robert Bond 			ihnp4!nsc!nscpdc!rgb
    National Semiconductor		tektronix!nscpdc!rgb
SHAR_EOF
if test 2477 -ne "`wc -c README`"
then
echo shar: error transmitting README '(should have been 2477 characters)'
fi
echo shar: extracting sc.man '(15996 characters)'
cat << \SHAR_EOF > sc.man



     SC(1)                       UNIX 3.0                        SC(1)



     NAME
          sc - spread sheet calculator

     SYNOPSIS
          sc [ _f_i_l_e ]


     DESCRIPTION
          The spread sheet calculator _s_c is based on rectangular
          tables, in much the same style as Visicalc or Lotus 123.
          When it is invoked it presents you with an empty table
          organized as rows and columns of cells.  Each cell may have
          a label string associated with it and an expression.  The
          expression may be a constant or it may compute something
          based on other entries.

          When _s_c is running, the screen is divided into four regions.
          The top line is for entering commands. The second line is
          for messages from _s_c.  The third line and the first four
          columns show the row and column numbers.  The rest of the
          screen forms a window looking at the table.  The screen has
          two cursors: a cell cursor (indicated by a '<' on the
          screen) and a character cursor (indicated by the terminal's
          hardware cursor).  The cell and character cursors are often
          the same.  They will differ when a command is being typed on
          the top line.

          Commands which use the terminal's control key such as ^N
          will work both when a command is being typed and when in
          normal mode.

          The cursor control commands and the row, column commands can
          be prefixed by a numeric argument indicating how many times
          the command is to be executed.  "^U" can be used before the
          number if the number is to be entered while a command is
          being typed into the command line.

          Cursor control commands:


          ^N   Move the cell cursor to the next row.


          ^P   Move the cell cursor to the previous row.


          ^F   Move the cell cursor forward one column.


          ^B   Move the cell cursor backward one column.





     Page 1                                          (printed 1/26/87)






     SC(1)                       UNIX 3.0                        SC(1)



          ^H   Backspace one character.


          h, j, k, l
               Alternate cursor controls (left, down, up, right).


          Arrow Keys
               The terminal's arrow keys provide another alternate set
               of cell cursor controls if they exist and are supported
               in the _t_e_r_m_c_a_p entry.  Some terminals have arrow keys
               which conflict with other control key codes.  For
               example, a terminal could send ^H when the back arrow
               key is depressed.  In these cases, the conflicting
               arrow key performs the same function as the key
               combination it mimics.


          0    Move the cell cursor to column 0 of the current row.


          $    Move the cell cursor to the last valid column in the
               current row.


          ^    Move the cell cursor to row 0 of the current column.


          #    Move the cell cursor to the last valid row in the
               current column.


          g    Go to a cell.  The program will prompt for the name of
               a cell.  Enter a cell number such as "a0" or "ae122".


          Cell entry and editing commands:


          =    Prompts for an expression which will be evaluated
               dynamically to produce a value for the cell pointed at
               by the cell cursor.  This may be used in conjunction
               with ^V to make one entries value be dependent on
               anothers.


          "    Enter a label for the current cell.


          <    Enter a label that will be flushed left against the
               left edge of the cell.




     Page 2                                          (printed 1/26/87)






     SC(1)                       UNIX 3.0                        SC(1)



          >    Enter a label that will be flushed right against the
               right edge of the cell.


          x    Clears the current cell.  You may prefix this command
               with a count of the number of cells on the current row
               to clear.  Cells cleared with this command may be
               recalled with any of the variations of the pull
               command.


          e    Edit the value associated with the current cell.  This
               is identical to '=' except that the command line starts
               out containing the old value or expression associated
               with the cell.


          E    Edit the string associated with the current cell.  This
               is the same as either "leftstring", "rightstring", or
               "label", with the additional fact that the command line
               starts out with the old string.


          m    Mark a cell to be used as the source for the copy
               command.


          c    Copy the last marked cell to the current cell, updating
               the row and column references.


          ^T   Toggle cell display.  The current cell's contents are
               displayed in line one when no command being entered or
               edited.  ^T turns the display on or off.


          File operations


          G    Get a new database from a file.


          P    Put the current database into a file.


          W    Write a listing of the current database in a form that
               matches its appearance on the screen.  This differs
               from the "put" command in that "put"s files are
               intended to be reloaded with "get", while "write"
               produces a file for people to look at.





     Page 3                                          (printed 1/26/87)






     SC(1)                       UNIX 3.0                        SC(1)



          T    Write a listing of the current database to a file, but
               put ":"s between each field.  This  is useful for
               tables that will be further formatted by the _t_b_l
               preprocessor of _n_r_o_f_f.


          M    Merges the database from the named file into the
               current database.  Values, expressions and names
               defined in the named file are written into the current
               file, overwriting the existing entries at those
               locations.


          Row and Column operations.  Members of this class of
          commands can be used on either rows or columns.  The second
          letter of the command is either a column designator (one of
          the characters c, j, k, ^N, ^p) or a row designator (one of
          r, l, h, ^B, ^F).  Commands which move or copy cells also
          modify the variable references in affected cell expressions.
          Variable references may be frozen by using the "fixed"
          operator.


          ar, ac
               Creates a new row (column) immediately following the
               current row (column).  It is initialized to be a copy
               of the current one.


          dr, dc
               Delete this row (column).


          pr, pc, pm
               Pull deleted rows (columns) back into the spread sheet.
               The last deleted set of cells is put back into the
               spread sheet at the current location.  _P_r inserts
               enough rows to hold the data.  _P_c inserts enough
               columns to hold the data.  _P_m (merge) does not insert
               rows or columns. It overwrites the cells beginning at
               the current cursor location.


          ir, ic
               Insert a new row (column) by moving the row (column)
               containing the cell cursor, and all following, down
               (right) one.  The new position will be empty.


          zr, zc
               Hide ("zap") the current row (column).  This keeps a
               row or column from being displayed but keeps it in the



     Page 4                                          (printed 1/26/87)






     SC(1)                       UNIX 3.0                        SC(1)



               data base.


          vr, vc
               Removes expressions from the affected rows (columns),
               leaving only the values which were in the cells before
               the command was executed.


          sr, sc
               Show hidden rows (columns).  Type in a range of rows or
               columns to be revealed.  The command default is the
               first range of rows or columns currently hidden.


          f    Sets the output format to be used for printing the
               numbers in each cell in the current column.  Type in
               two numbers which will be the width in characters of a
               column and the number of digits which will follow the
               decimal point.  Note that this command has only a
               column version and does have a second letter.


          Region Operations: Region commands affect a rectangular
          region on the screen. All of the commands in this class
          start with a slash; the second letter of the command
          indicates which command to do.  The program will prompt for
          needed paramters.  Phrases surrounded by square brackets in
          the prompt are informational only and may be erased with the
          backspace key.


          /x   Clear a region.  Cells cleared with this command may be
               recalled via any of the pull row or column commands.


          /c   Copy a region to the area starting at the current cell.


          /f   Fill a region with constant values.  The start and
               increment numbers may be positive or negative.


          Miscellaneous commands:


          q    Exit from _s_c.  If you were editing a file, and you
               modified it, then _s_c will ask about saving before
               exiting. If you aren't editing a file and haven't saved
               the data you entered, you will get a chance to save the
               data before you exit.




     Page 5                                          (printed 1/26/87)






     SC(1)                       UNIX 3.0                        SC(1)



          ^C   Alternate exit command.


          ?    Types a brief helpful message.


          ^G or ESC
               Abort entry of the current command.


          ^R or ^L
               Redraw the screen.


          ^V   Types, in the command line, the name of the cell
               referenced by the cell cursor.  This is used when
               typing in expressions which refer to entries in the
               table.


          ^E   Types, in the command line, the expression of the cell
               referenced by the cell cursor.


          ^A   Types, in the command line, the value of the cell
               referenced by the cell cursor.


          Expressions that are used with the '=' and 'e' commands have
          a fairly conventional syntax.  Terms may be variable names
          (from the ^V command), parenthesised expressions, negated
          terms, and constants. Rectangular regions of the screen may
          be operated upon with '@' functions such as sum (@sum),
          average (@avg) and product (@prod).  Terms may be combined
          using many binary operators.  Their precedences (from
          highest to lowest) are: ^; *,/; +,-; <,=,>,<=,>=; &; |; ?.


          e+e            Addition.


          e-e            Subtraction.


          e*e            Multiplication.


          e/e            Division.


          e^e            Exponentiation.




     Page 6                                          (printed 1/26/87)






     SC(1)                       UNIX 3.0                        SC(1)



          @sum(v:v)      Sum all valid (nonblank) entries in the
                         region whose two corners are defined by the
                         two variable (cell) names given.


          @avg(v:v)      Average all valid (nonblank) entries in the
                         region whose two corners are defined by the
                         two variable (cell) names given.


          @prod(v:v)     Multiply together all valid (nonblank)
                         entries in the region whose two corners are
                         defined by the two variable (cell) names
                         given.


          e?e:e          Conditional: If the first expression is true
                         then the value of the second is returned,
                         otherwise the value of the third is.


          <,=,>,<=,>=    Relationals: true iff the indicated relation
                         holds.


          &,|            Boolean connectives.


          fixed          To make a variable not change automatically
                         when a cell moves, put the word fixed in
                         front of the reference.  I.e.  B1*fixed C3


          Assorted math functions.  Most of these are standard system
          functions more fully described in _m_a_t_h(_3). All of them
          operate on floating point numbers (doubles); the trig
          functions operate with angles in radians.


          @exp(expr)     Returns exponential function of <expr>.


          @ln(expr)      Returns the natural logarithm of <expr>.


          @log(expr)     Returns the base 10 logarithm of <expr>.


          @pow(expr1,expr2)
                         Returns <expr1> raised to the power of
                         <expr2>.




     Page 7                                          (printed 1/26/87)






     SC(1)                       UNIX 3.0                        SC(1)



          @floor(expr)   Returns returns the largest integer not
                         greater than <expr>.


          @ceil(expr)    Returns the smallest integer not less than
                         <expr>.


          @hypot(x,y)    Returns SQRT(x*x+y*y), taking precautions
                         against unwarranted overflows.


          @fabs(expr)    Returns the absolute value |expr|.


          @sin(expr), @cos(expr), @tan(expr)
                         Return trigonometric functions of radian
                         arguments. The magnitude of the arguments are
                         not checked to assure meaningful results.


          @asin(expr)    Returns the arc sin in the range -pi/2 to
                         pi/2


          @acos(expr)    Returns the arc cosine in the range 0 to pi.


          @atan(expr)    Returns the arc tangent of <expr> in the
                         range -pi/2 to pi/2.


          @dtr(expr)     Converts <expr> in degrees to radians.


          @rtd(expr)     Converts <expr> in radians to degrees.


          pi             A constant quite close to pi.


          @max(expr1,expr2)
                         Returns the largest value of the two
                         expressions.


          @min(expr1,expr2)
                         Returns the smallest value of the two
                         expressions.


          @gamma(expr1)  Returns the natural log of the gamma



     Page 8                                          (printed 1/26/87)






     SC(1)                       UNIX 3.0                        SC(1)



                         function.


     SEE ALSO
          bc(1), dc(1)


     BUGS
          Expression reevaluation is done in the same top-to-bottom,
          left-to-right manner as is done in other spread sheet
          calculators.  This is silly.  A proper following of the
          dependency graph with (perhaps) recourse to relaxation
          should be implemented.

          At most 200 rows and 40 columns.








































     Page 9                                          (printed 1/26/87)



SHAR_EOF
if test 15996 -ne "`wc -c sc.man`"
then
echo shar: error transmitting sc.man '(should have been 15996 characters)'
fi
echo shar: extracting sc.doc '(11360 characters)'
cat << \SHAR_EOF > sc.doc
.TH SC 1
.SH NAME
pname \- spread sheet calculator
.SH SYNOPSIS
.B pname
[
.I file
]

.SH DESCRIPTION
The spread sheet calculator
.I pname
is based on rectangular tables, in much the same style
as Visicalc or Lotus 123.  When it is invoked it presents you with an empty
table organized as rows and columns of cells.  Each cell may have a label
string associated with it and an expression.  The expression may be a
constant or it may compute something based on other entries.

When \fIpname\fR is running, the screen is divided into four regions. The top
line is for entering commands. The second line is for messages from
\fIpname\fR.
The third line and the first four columns show the row and column numbers.
The rest of the screen forms a window looking at the table.
The screen has two
cursors: a cell cursor (indicated by a '<' on the screen) and a character
cursor (indicated by the terminal's hardware cursor).  The cell and
character cursors are often the same.  They will differ when a command
is being typed on the top line.

Commands which use the terminal's control key
such as ^N will work both when a
command is being typed and when in normal mode.

The cursor control commands and the row, column commands can be 
prefixed by a numeric argument indicating how many times the command
is to be executed.  "^U" can be used before the number if
the number is to be entered while a command is being typed
into the command line.

Cursor control commands:

.IP ^N
Move the cell cursor to the next row.

.IP ^P
Move the cell cursor to the previous row.

.IP ^F
Move the cell cursor forward one column.

.IP ^B
Move the cell cursor backward one column.

.IP ^H
Backspace one character.

.IP "h, j, k, l"
Alternate cursor controls (left, down, up, right).

.IP "Arrow Keys"
The terminal's arrow keys provide another alternate set of cell
cursor controls if they exist and are supported in the
.I termcap
entry.
Some terminals have arrow keys which conflict
with other control key codes.  For example, a terminal could send ^H when the
back arrow key is depressed.  In these cases, the conflicting arrow key
performs the same function as the key combination it mimics.

.IP 0
Move the cell cursor to column 0 of the current row. 

.IP $
Move the cell cursor to the last valid column in the current row.

.IP ^
Move the cell cursor to row 0 of the current column.

.IP #
Move the cell cursor to the last valid row in the current column.

.IP g
Go to a cell.  The program will prompt for the name of a cell.
Enter a cell number such as "a0" or "ae122".

.PP
Cell entry and editing commands:

.IP =
Prompts for an expression which will be evaluated dynamically to produce a
value for the cell pointed at by the cell cursor.  This may be used in
conjunction with ^V to make one entries value be dependent on anothers.

.IP """
Enter a label for the current cell.

.IP <
Enter a label that will be flushed left against the
left edge of the cell.

.IP >
Enter a label that will be flushed right against the
right edge of the cell.

.IP x
Clears the current cell.  You may prefix this command with a count of
the number of cells on the current row to clear.  Cells cleared with
this command may be recalled with any of the variations of the pull
command.

.IP e
Edit the value associated with the current cell.  This is identical to '='
except that the command line starts out containing the old value or
expression associated with the cell.

.IP E
Edit the string associated with the current cell.  This is the same as
either "leftstring", "rightstring", or "label", with the additional
fact that the command line starts out with the old string.

.IP m 
Mark a cell to be used as the source for the copy command.

.IP c
Copy the last marked cell to the current cell, updating the row and
column references.

.IP ^T
Toggle cell display.  The current cell's contents are displayed in line
one when no command being entered or edited.  ^T turns the
display on or off.

.PP
File operations

.IP G
Get a new database from a file.

.IP P
Put the current database into a file.

.IP W
Write a listing of the current database in a form that matches its
appearance on the screen.  This differs from the "put" command in that
"put"s files are intended to be reloaded with "get", while "write" produces
a file for people to look at.

.IP T
Write a listing of the current database to a file, but put ":"s between
each field.  This  is useful for tables that will be further formatted
by the
.I tbl
preprocessor of
.I nroff.

.IP M
Merges the database from the named file into the current database.  Values,
expressions and names defined in the named file are written into the current
file, overwriting the existing entries at those locations.

.PP
Row and Column operations.  Members of this class of commands can be used
on either rows or columns.  The second letter of the command is either
a column designator (one of the characters c, j, k, ^N, ^p) or a 
row designator (one of r, l, h, ^B, ^F).
Commands which move or copy cells also modify the variable references 
in affected cell expressions.
Variable references may be frozen by using the "fixed" operator.

.IP "ar, ac"
Creates a new row (column) immediately following the current row (column).
It is initialized
to be a copy of the current one.

.IP "dr, dc"
Delete this row (column).

.IP "pr, pc, pm"
Pull deleted rows (columns) back into the spread sheet.  The last deleted
set of cells is put back into the spread sheet at the current location.
.I Pr
inserts enough rows to hold the data.
.I Pc
inserts enough columns to hold the data.
.I Pm
(merge) does not insert rows or columns. It overwrites the cells
beginning at the current cursor location.

.IP "ir, ic"
Insert a new row (column) by moving the row (column) containing the cell
cursor, and all
following, down (right) one.  The new position will be empty.

.IP "zr, zc"
Hide ("zap") the current row (column).  This keeps a row or column from being
displayed but keeps it in the data base.

.IP "vr, vc"
Removes expressions from the affected rows (columns), leaving only
the values which were in the cells before the command
was executed.

.IP "sr, sc"
Show hidden rows (columns).  Type in a range of rows or columns
to be revealed.  The command default is the first range of rows or
columns currently hidden.

.IP f
Sets the output format to be used for printing the numbers in each cell in
the current column.  Type in two numbers which will be the width in
characters of a column and the number of digits which will follow the
decimal point.  Note that this command has only a column version and
does have a second letter.

.PP
Region Operations:
Region commands
affect a rectangular region on the screen.  
All of the commands in this class start with a slash; the second
letter of the command indicates which command to do.
The program will prompt for needed paramters.  Phrases surrounded by
square brackets in the prompt are informational only and may be erased with
the backspace key. 

.IP "/x"
Clear a region.  Cells cleared with this command may be recalled
via any of the pull row or column commands.

.IP "/c"
Copy a region to the area starting at the current cell.

.IP "/f"
Fill a region with constant values.  The start and increment numbers
may be positive or negative.

.PP
Miscellaneous commands:

.IP q
Exit from \fIpname\fR.  If you were editing a file, and you modified
it, then
\fIpname\fR will ask about saving before exiting. 
If you aren't editing a file and haven't saved the data you
entered, you will get a chance to save the data
before you exit.

.IP ^C
Alternate exit command.

.IP ?
Types a brief helpful message.

.IP "^G or ESC"
Abort entry of the current command.

.IP "^R or ^L"
Redraw the screen.

.IP ^V
Types, in the command line, the name of the cell referenced by
the cell cursor.  This is used when typing in expressions which refer to
entries in the table.

.IP ^E
Types, in the command line, the expression of the cell referenced
by the cell cursor.

.IP ^A
Types, in the command line, the value of the cell referenced
by the cell cursor.

.PP
Expressions that are used with the '=' and 'e' commands have a fairly
conventional syntax.  Terms may be variable names (from the ^V command),
parenthesised expressions, negated terms, and constants. 
Rectangular regions of the screen may be operated upon with '@' functions
such as sum (@sum), average (@avg) and product (@prod).
Terms may be combined using many binary
operators.  Their precedences (from highest to lowest) are: ^; *,/; +,-;
<,=,>,<=,>=; &; |; ?.

.TP 15
e+e
Addition.

.TP 15
e-e
Subtraction.

.TP 15
e*e
Multiplication.

.TP 15
e/e
Division.

.TP 15
e^e
Exponentiation.

.TP 15
@sum(v:v)
Sum all valid (nonblank) entries in the region whose two corners are defined
by the two variable (cell) names given.

.TP 15
@avg(v:v)
Average all valid (nonblank) entries in the region whose two corners are defined
by the two variable (cell) names given.

.TP 15
@prod(v:v)
Multiply together all valid (nonblank) entries in the region whose two
corners are defined by the two variable (cell) names given.

.TP 15
e?e:e
Conditional: If the first expression is true then the value of the second is
returned, otherwise the value of the third is.

.TP 15
<,=,>,<=,>=
Relationals: true iff the indicated relation holds.

.TP 15
&,|
Boolean connectives.

.TP 15
fixed
To make a variable not change automatically when a cell moves,
put the word \*(lqfixed\*(rq in front of the reference.  I.e.
B1*fixed C3

.PP
Assorted math functions.  Most of these are standard system functions
more fully described in
.I math(3).
All of them operate on floating point numbers (doubles);
the trig functions operate with angles in radians.

.TP 15
@exp(expr)
Returns exponential function of <expr>.

.TP 15
@ln(expr)
Returns the natural logarithm of <expr>.

.TP 15
@log(expr)
Returns the base 10 logarithm of <expr>.

.TP 15
@pow(expr1,expr2)
Returns <expr1> raised to the power of <expr2>.

.TP 15
@floor(expr)
Returns returns the largest integer not greater than <expr>.

.TP 15
@ceil(expr)
Returns the smallest integer not less than <expr>.

.TP 15
@hypot(x,y)
Returns SQRT(x*x+y*y), taking precautions against unwarranted overflows.

.TP 15
@fabs(expr)
Returns the absolute value |expr|.

.TP 15
@sin(expr), @cos(expr), @tan(expr)
Return trigonometric functions of radian arguments. The magnitude of the
arguments are not checked to assure meaningful results.

.TP 15
@asin(expr)
Returns the arc sin in the range -pi/2 to pi/2

.TP 15
@acos(expr)
Returns the arc cosine in the range 0 to pi.

.TP 15
@atan(expr)
Returns the arc tangent of <expr> in the range -pi/2 to pi/2.

.TP 15
@dtr(expr)
Converts <expr> in degrees to radians.

.TP 15
@rtd(expr)
Converts <expr> in radians to degrees.

.TP 15
pi
A constant quite close to pi.

.TP 15
@max(expr1,expr2)
Returns the largest value of the two expressions.

.TP 15
@min(expr1,expr2)
Returns the smallest value of the two expressions.

.TP 15
@gamma(expr1)
Returns the natural log of the gamma function.

.SH SEE ALSO
bc(1), dc(1)

.SH BUGS

Expression reevaluation is done in the same top-to-bottom, left-to-right
manner as is done in other spread sheet calculators.  This is silly.  A
proper following of the dependency graph with (perhaps) recourse to
relaxation should be implemented.

At most 200 rows and 40 columns.
SHAR_EOF
if test 11360 -ne "`wc -c sc.doc`"
then
echo shar: error transmitting sc.doc '(should have been 11360 characters)'
fi
echo shar: extracting cmds.c '(8071 characters)'
cat << \SHAR_EOF > cmds.c
/*	SC	A Spreadsheet Calculator
 *		Main driver
 *
 *		original by James Gosling, September 1982
 *		modifications by Mark Weiser and Bruce Israel,
 *			University of Maryland
 *
 *              More mods Robert Bond, 12/86
 *
 */

#include <curses.h>
#include "sc.h"

#ifdef BSD42
#include <strings.h>
#else
#ifndef SYSIII
#include <string.h>
#endif
#endif

char *malloc();

duprow()
{
    if (currow >= MAXROWS - 1 || maxrow >= MAXROWS - 1) {
	error ("The table can't be any bigger");
	return;
    }
    modflg++;
    currow++;
    openrow (currow);
    for (curcol = 0; curcol <= maxcol; curcol++) {
	register struct ent *p = tbl[currow - 1][curcol];
	if (p) {
	    register struct ent *n;
	    n = lookat (currow, curcol);
	    n -> v = p -> v;
	    n -> flags = p -> flags;
	    n -> expr = copye (p -> expr, 1, 0);
	    n -> label = 0;
	    if (p -> label) {
		n -> label = malloc ((unsigned)(strlen (p -> label) + 1));
		strcpy (n -> label, p -> label);
	    }
	}
    }
    for (curcol = 0; curcol <= maxcol; curcol++) {
	register struct ent *p = tbl[currow][curcol];
	if (p && (p -> flags & is_valid) && !p -> expr)
	    break;
    }
    if (curcol > maxcol)
	curcol = 0;
}

dupcol() 
{
    if (curcol >= MAXCOLS - 1 || maxcol >= MAXCOLS - 1) {
	error ("The table can't be any wider");
	return;
    }
    modflg++;
    curcol++;
    opencol (curcol);
    for (currow = 0; currow <= maxrow; currow++) {
	register struct ent *p = tbl[currow][curcol - 1];
	if (p) {
	    register struct ent *n;
	    n = lookat (currow, curcol);
	    n -> v = p -> v;
	    n -> flags = p -> flags;
	    n -> expr = copye (p -> expr, 0, 1);
	    n -> label = 0;
	    if (p -> label) {
		n -> label = malloc ((unsigned)(strlen (p -> label) + 1));
		strcpy (n -> label, p -> label);
	    }
	}
    }
    for (currow = 0; currow <= maxrow; currow++) {
	register struct ent *p = tbl[currow][curcol];
	if (p && (p -> flags & is_valid) && !p -> expr)
	    break;
    }
    if (currow > maxrow)
	currow = 0;
}

insertrow(arg)
{
    while (--arg>=0) openrow (currow);
}

deleterow(arg)
{
    flush_saved();
    erase_area(currow, 0, currow + arg - 1, maxcol);
    currow += arg;
    while (--arg>=0) closerow (--currow);
    sync_refs();
}

insertcol(arg)
{
    while (--arg>=0) opencol(curcol);
}

deletecol(arg)
{
    flush_saved();
    erase_area(0, curcol, maxrow, curcol + arg - 1);
    curcol += arg;
    while (--arg>=0) closecol (--curcol);
    sync_refs();
}

rowvalueize(arg)
{
    valueize_area(currow, 0, currow + arg - 1, maxcol);
}

colvalueize(arg)
{
    valueize_area(0, curcol, maxrow, curcol + arg - 1);
}

erase_area(sr, sc, er, ec)
int sr, sc, er, ec;
{
    register int r, c;
    register struct ent **p;

    if (sr > er) {
	r = sr; sr = er; er= r;	
    }

    if (sc > ec) {
	c = sc; sc = ec; ec= c;	
    }

    if (sr < 0)
	sr = 0; 
    if (sc < 0)
	sc = 0;
    if (er >= MAXROWS)
	er = MAXROWS-1;
    if (ec >= MAXCOLS)
	ec = MAXCOLS-1;

    for (r = sr; r <= er; r++) {
	for (c = sc; c <= ec; c++) {
	    p = &tbl[r][c];
	    if (*p) {
		free_ent(*p);
		*p = 0;
	    }
	}
    }

}

valueize_area(sr, sc, er, ec)
int sr, sc, er, ec;
{
    register int r, c;
    register struct ent *p;

    if (sr > er) {
	r = sr; sr = er; er= r;	
    }

    if (sc > ec) {
	c = sc; sc = ec; ec= c;	
    }

    if (sr < 0)
	sr = 0; 
    if (sc < 0)
	sc = 0;
    if (er >= MAXROWS)
	er = MAXROWS-1;
    if (ec >= MAXCOLS)
	ec = MAXCOLS-1;

    for (r = sr; r <= er; r++) {
	for (c = sc; c <= ec; c++) {
	    p = tbl[r][c];
	    if (p && p->expr) {
		efree(p->expr);
		p->expr = 0;
	    }
	}
    }

}

pullcells(to_insert)
{
    register struct ent *p, *n;
    register int deltar, deltac;
    int minrow, mincol;
    int maxrow, maxcol;
    int numrows, numcols;

    if (!to_fix)
	return;

    switch (to_insert) {
    case 'm':
    case 'r':
    case 'c':
	break;
    default:
	error("Invalid pull command");
	return;
    }

    minrow = MAXROWS; 
    mincol = MAXCOLS;
    maxrow = 0;
    maxcol = 0;

    for (p = to_fix; p; p = p->next) {
	if (p->row < minrow)
	    minrow = p->row;
	if (p->row > maxrow)
	    maxrow = p->row;
	if (p->col < mincol)
	    mincol = p->col;
	if (p->col > maxcol)
	    maxcol = p->col;
    }

    numrows = maxrow - minrow + 1;
    numcols = maxcol - mincol + 1;
    deltar = currow - minrow;
    deltac = curcol - mincol;

    if (to_insert == 'r') {
	insertrow(numrows);
	deltac = 0;
    } else if (to_insert == 'c') {
	insertcol(numcols);
	deltar = 0;
    }

    FullUpdate++;
    modflg++;

    for (p = to_fix; p; p = p->next) {
	n = lookat (p->row + deltar, p->col + deltac);
	clearent(n);
	n -> flags = p -> flags & ~is_deleted;
	n -> v = p -> v;
	n -> expr = copye(p->expr, deltar, deltac);
	n -> label = 0;
	if (p -> label) {
	    n -> label = malloc((unsigned)(strlen(p->label)+1));
	    strcpy (n -> label, p -> label);
	}
    }
}

colshow_op()
{
    register int i,j;
    for (i=0; i<MAXCOLS; i++)
	if (hidden_col[i]) 
	    break;
    for(j=i; j<MAXCOLS; j++)
	if (!hidden_col[j])
	    break;
    j--;
    if (i<MAXCOLS) {
	sprintf(line,"show %s:", coltoa(i));
	sprintf(line + strlen(line),"%s",coltoa(j));
	linelim = strlen (line);
    }
}

rowshow_op()
{
    register int i,j;
    for (i=0; i<MAXROWS; i++)
	if (hidden_row[i]) 
	    break;
    for(j=i; j<MAXROWS; j++)
	if (!hidden_row[j]) {
	    break;
	}
    j--;
    if (i<MAXROWS) {
	sprintf(line,"show %d:%d", i, j);
        linelim = strlen (line);
    }
}

get_qual()
{
    register int c;

    c = nmgetch();
    switch (c) {
    case 'c':
    case 'j':
    case 'k':
    case ctl(p):
    case ctl(n):
	return('c');
    case 'r':
    case 'l':
    case 'h':
    case ctl(f):
    case ctl(b):
	return('r');
    default:
	return(c);
    }
    /*NOTREACHED*/
}

openrow (rs) {
    register    r;
    register struct ent **p;
    register    c;
    register	i;

    if (rs > maxrow) maxrow = rs;
    if (maxrow >= MAXROWS - 1 || rs > MAXROWS - 1) {
	error ("The table can't be any longer");
	return;
    }
    for (i = maxrow+1; i > rs; i--) {
	hidden_row[i] = hidden_row[i-1];
    }
    for (r = ++maxrow; r > rs; r--)
	for (c = maxcol + 1, p = &tbl[r][0]; --c >= 0; p++)
	    if (p[0] = p[-MAXCOLS])
		p[0] -> row++;
    p = &tbl[rs][0];
    for (c = maxcol + 1; --c >= 0;)
	*p++ = 0;
    FullUpdate++;
    modflg++;
}

closerow (r)
register r; {
    register struct ent **p;
    register c;
    register int i;

    if (r > maxrow) return;

    p = &tbl[r][0];
    for (c=maxcol+1; --c>=0; ) {
	if (*p)
	    free_ent(*p);
	*p++ = 0;
    }

    for (i = r; i < MAXROWS - 1; i++) {
	hidden_row[i] = hidden_row[i+1];
    }

    while (r<maxrow) {
	for (c = maxcol+1, p = &tbl[r][0]; --c>=0; p++)
	    if (p[0] = p[MAXCOLS])
		p[0]->row--;
	r++;
    }

    p = &tbl[maxrow][0];
    for (c=maxcol+1; --c>=0; ) *p++ = 0;
    maxrow--;
    FullUpdate++;
    modflg++;
}

opencol (cs) {
    register r;
    register struct ent **p;
    register c;
    register lim = maxcol-cs+1;
    int i;

    if (cs > maxcol) maxcol = cs;
    if (maxcol >= MAXCOLS - 1 || cs > MAXCOLS - 1) {
	error ("The table can't be any wider");
	return;
    }
    for (i = maxcol+1; i > cs; i--) {
	fwidth[i] = fwidth[i-1];
	precision[i] = precision[i-1];
	hidden_col[i] = hidden_col[i-1];
    }
    /* fwidth[cs] = DEFWIDTH;
    precision[i] =  DEFPREC;  */

    for (r=0; r<=maxrow; r++) {
	p = &tbl[r][maxcol+1];
	for (c=lim; --c>=0; p--)
	    if (p[0] = p[-1])
		p[0]->col++;
	p[0] = 0;
    }
    maxcol++;
    FullUpdate++;
    modflg++;
}

closecol (cs) {
    register r;
    register struct ent **p;
    register struct ent *q;
    register c;
    register lim = maxcol-cs;
    int i;

    if (lim < 0) return;

    for (r=0; r<=maxrow; r++)
	if (q = tbl[r][cs]) {
	    free_ent(q);
	}

    for (r=0; r<=maxrow; r++) {
	p = &tbl[r][cs];
	for (c=lim; --c>=0; p++)
	    if (p[0] = p[1])
		p[0]->col--;
	p[0] = 0;
    }

    for (i = cs; i < MAXCOLS - 1; i++) {
	fwidth[i] = fwidth[i+1];
	precision[i] = precision[i+1];
	hidden_col[i] = hidden_col[i+1];
    }

    maxcol--;
    FullUpdate++;
    modflg++;
}

SHAR_EOF
if test 8071 -ne "`wc -c cmds.c`"
then
echo shar: error transmitting cmds.c '(should have been 8071 characters)'
fi
echo shar: extracting eres.sed '(50 characters)'
cat << \SHAR_EOF > eres.sed
/%token.*K_/!d
/%token.*K_\(.*\)/s//	"\1",	K_\1,/
SHAR_EOF
if test 50 -ne "`wc -c eres.sed`"
then
echo shar: error transmitting eres.sed '(should have been 50 characters)'
fi
echo shar: extracting sres.sed '(50 characters)'
cat << \SHAR_EOF > sres.sed
/%token.*S_/!d
/%token.*S_\(.*\)/s//	"\1",	S_\1,/
SHAR_EOF
if test 50 -ne "`wc -c sres.sed`"
then
echo shar: error transmitting sres.sed '(should have been 50 characters)'
fi
echo shar: extracting makefile '(1845 characters)'
cat << \SHAR_EOF > makefile

# Specify the name of the program.
# All documentation and installation keys on this value.
# 
name=sc

EXDIR=/a/rgb/bin
MANDIR=/usr/man/man1
SRC1=sc.h sc.c lex.c gram.y interp.c
SRC2=cmds.c eres.sed sres.sed makefile cvt.sed
DOCS=README $(name).man $(name).doc

#Set SIMPLE for lex.c if you don't want arrow keys or lex.c blows up
#SIMPLE=-DSIMPLE

#Use this for system V.2
#CFLAGS= -O -DSYSV
#LIB=-lm -lcurses

#Use this for BSD 4.2
#CFLAGS= -O -DBSD42
#LIB=-lm -lcurses -ltermcap

#Use this for BSD 4.3
CFLAGS= -O -DBSD43
LIB=-lm -lcurses -ltermcap

#Use this for system III (XENIX)
#CFLAGS= -O -DSYSIII
#LIB=-lm -lcurses -ltermcap

#Use this for separate I and D space
#ID=-i
ID=

$(name):	sc.o lex.o gram.o interp.o cmds.o
	cc ${CFLAGS} ${ID} sc.o lex.o gram.o interp.o cmds.o ${LIB} -o $(name)

diff_to_sc:	diff_to_sc.c
	cc ${CFLAGS} -o dtv diff_to_sc.c

lex.o:	sc.h y.tab.h gram.o
	cc ${CFLAGS} ${SIMPLE} -c lex.c

interp.o:	sc.h

sc.o:	sc.h

gram.o:	sc.h y.tab.h

cmds.o: cmds.c sc.h

y.tab.h:	gram.y

gram.o:	sc.h y.tab.h gram.c
	cc ${CFLAGS} -c gram.c
	sed<gram.y >experres.h -f eres.sed;sed < gram.y > statres.h -f sres.sed

gram.c:	gram.y
	yacc -d gram.y; mv y.tab.c gram.c

clean:
	rm -f *.o *res.h y.tab.h $(name) debug core gram.c 

shar: ${SRC1} ${SRC2} ${DOCS}
	shar -v -c ${DOCS} ${SRC2} > sc.shar.1
	shar -v -c ${SRC1} > sc.shar.2

lint: sc.h sc.c lex.c gram.c interp.c cmds.c
	lint ${CFLAGS} ${SIMPLE } sc.c lex.c gram.c interp.c cmds.c -lcurses -lm

$(name).1:	sc.doc
	sed -e s/pname/$(name)/g sc.doc >  $(name).1

$(name).man:	$(name).1
	-mv $(name).man $(name).mold
	nroff -man $(name).1 > $(name).man

install: $(EXDIR)/$(name)

inst-man: $(MANDIR)/$(name).1

$(EXDIR)/$(name): $(name)
	mv $(EXDIR)/$(name) $(EXDIR)/$(name).old
	strip $(name)
	cp $(name) $(EXDIR)

$(MANDIR)/$(name).1: $(name).1
	cp $(name).1 $(MANDIR)
SHAR_EOF
if test 1845 -ne "`wc -c makefile`"
then
echo shar: error transmitting makefile '(should have been 1845 characters)'
fi
echo shar: extracting cvt.sed '(1420 characters)'
cat << \SHAR_EOF > cvt.sed
s!+/\(r.*c.*:r.*c[0-9]*\)!@sum(\1)!
s/\(r[0-9]*\)\(c[0-9]*\)/\2\1/g
s/c10/k/g
s/c11/l/g
s/c12/m/g
s/c13/n/g
s/c14/o/g
s/c15/p/g
s/c16/q/g
s/c17/r/g
s/c18/s/g
s/c19/t/g
s/c20/u/g
s/c21/v/g
s/c22/w/g
s/c23/x/g
s/c24/y/g
s/c25/z/g
s/c26/aa/g
s/c27/ab/g
s/c28/ac/g
s/c29/ad/g
s/c30/ae/g
s/c31/af/g
s/c32/ag/g
s/c33/ah/g
s/c34/ai/g
s/c35/aj/g
s/c36/ak/g
s/c37/al/g
s/c38/am/g
s/c39/an/g
s/c0/a/g
s/c1/b/g
s/c2/c/g
s/c3/d/g
s/c4/e/g
s/c5/f/g
s/c6/g/g
s/c7/h/g
s/c8/i/g
s/c9/j/g
s/r\([0-9][0-9]*\)/\1/g
s/format 10/format k/g
s/format 11/format l/g
s/format 12/format m/g
s/format 13/format n/g
s/format 14/format o/g
s/format 15/format p/g
s/format 16/format q/g
s/format 17/format r/g
s/format 18/format s/g
s/format 19/format t/g
s/format 20/format u/g
s/format 21/format v/g
s/format 22/format w/g
s/format 23/format x/g
s/format 24/format y/g
s/format 25/format z/g
s/format 26/format aa/g
s/format 27/format ab/g
s/format 28/format ac/g
s/format 29/format ad/g
s/format 30/format ae/g
s/format 31/format af/g
s/format 32/format ag/g
s/format 33/format ah/g
s/format 34/format ai/g
s/format 35/format aj/g
s/format 36/format ak/g
s/format 37/format al/g
s/format 38/format am/g
s/format 39/format an/g
s/format 0/format a/g
s/format 1/format b/g
s/format 2/format c/g
s/format 3/format d/g
s/format 4/format e/g
s/format 5/format f/g
s/format 6/format g/g
s/format 7/format h/g
s/format 8/format i/g
s/format 9/format j/g
SHAR_EOF
if test 1420 -ne "`wc -c cvt.sed`"
then
echo shar: error transmitting cvt.sed '(should have been 1420 characters)'
fi
#	End of shell archive
exit 0
-- 
    Robert Bond 			ihnp4!nsc!nscpdc!rgb
    National Semiconductor		tektronix!nscpdc!rgb