home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sources.misc
- From: Jeff Buhrt <prslnk!buhrt@cs.indiana.edu>
- Subject: v20i041: sc - The SC Spreadsheet, release 6.16, Part07/07
- Message-ID: <1991Jun5.172904.12368@sparky.IMD.Sterling.COM>
- X-Md4-Signature: cc484f48731c14dbcb951c230a939d4c
- Date: Wed, 5 Jun 1991 17:29:04 GMT
- Approved: kent@sparky.imd.sterling.com
-
- Submitted-by: Jeff Buhrt <prslnk!buhrt@cs.indiana.edu>
- Posting-number: Volume 20, Issue 41
- Archive-name: sc/part07
-
- #! /bin/sh
- # into a shell via "sh file" or similar. To overwrite existing files,
- # type "sh file -c".
- # The tool that generated this appeared in the comp.sources.unix newsgroup;
- # send mail to comp-sources-unix@uunet.uu.net if you want that tool.
- # Contents: VMS_NOTES crypt.c psc.doc tutorial.sc vmtbl.c xmalloc.c
- # Wrapped by kent@sparky on Wed Jun 5 09:22:20 1991
- PATH=/bin:/usr/bin:/usr/ucb ; export PATH
- echo If this archive is complete, you will see the following message:
- echo ' "shar: End of archive 7 (of 7)."'
- if test -f 'VMS_NOTES' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'VMS_NOTES'\"
- else
- echo shar: Extracting \"'VMS_NOTES'\" \(4341 characters\)
- sed "s/^X//" >'VMS_NOTES' <<'END_OF_FILE'
- XFrom: ihnp4!gargoyle!oddjob!noao!arizona!naucse!jdc (John Campbell)
- XTo: arizona!noao!oddjob!gargoyle!ihnp4!nsc!nscpdc!rgb
- XSubject: VMS SC
- X
- XVMS USERS:
- X
- XBob Bond has been generous enough to give me free rein in adding what I
- Xthink is needed to make SC run on VMS. Any problems with VMS should be
- Xdirected to me--they are not Bob's fault.
- X
- XThe VMS SC is "SIMPLE" for the most part, except that the arrow keys
- X(instead of hjkl) will move you around the cells. The VMS version of SC
- Xwill not interact with the Bourne shell (obviously), which means that CRYPT
- Xand EXTERNAL FUNCTIONS will not be available.
- X
- XIf you have a 'C' compiler and GNU Bison then you should be able to get
- XSC running on VMS by following the instructions below.
- X
- XStep 1: Get all the files
- X
- XI've heard of a few sites that can unpack unix shar files directly on
- XVMS. Most people, however, will need access to a unix machine to get
- Xthe original distribution unpacked. At this time you should also build
- Xexperres.h and statres.h and perhaps run the man pages off if you need
- Xto port the documentation. To build the two "missing" hearder files:
- X sed <gram.y >experres.h -f eres.sed
- X sed <gram.y >statres.h -f sres.sed
- X
- XStep 2: Cut out BUILD.COM and GETOPT.C
- X
- XAt the end of this file are two other pieces: BUILD.COM and GETOPT.C. After
- Xyou've moved everything to VMS, cut BUILD.COM and GETOPT.C out of here and
- Xput them in the same directory as the rest of the SC distribution.
- X
- XStep 3: Build it
- X
- XTheoretically all you now need to do is @BUILD and SC (as well as PSC)
- Xwill be running on VMS. If you have problems feel free to contact me
- Xat ...!arizona!naucse!jdc (or even call at 602-523-6259).
- X
- X---------------------cut here for BUILD.COM--------------------------
- X$! VMS command file to build SC and PSC (requires bison)
- X$! SC:
- X$ bison -d gram.y
- X$ ren gram_tab.c gram.c
- X$ cc /define=("SIMPLE","SIGVOID") sc.c
- X$ cc /define=("SIMPLE","SIGVOID") gram.c
- X$ cc /define=("SIMPLE","SIGVOID") lex.c
- X$ cc /define=("SIMPLE","SIGVOID") interp
- X$ cc /define=("SIMPLE","SIGVOID") cmds
- X$ cc /define=("SIMPLE","SIGVOID") xmalloc
- X$ cc /define=("SIMPLE","SIGVOID") range
- X$ cc /define=("SIMPLE","SIGVOID") help
- X$ link sc.obj,lex.obj,gram.obj,interp.obj,cmds.obj,xmalloc.obj,-
- X range.obj,help.obj,sys$library:vaxcrtl.olb/lib
- X$ !
- X$ ! Create VMS foreign command symbol to test SC
- X$ !
- X$ sc == "$" + f$logical("SYS$DISK") + f$directory() + "SC.EXE"
- X$!
- X$! Now PSC
- X$!
- X$ cc psc.c
- X$ cc getopt.c
- X$ link psc,getopt,sys$library:vaxcrtl.olb/lib
- X$ !
- X$ ! Create VMS foreign command symbol to test PSC (Note that
- X$ ! PSC reads SYS$INPUT and writes to SYS$OUTPUT, so use
- X$ ! DEFINE/USER to redirect.)
- X$ !
- X$ psc == "$" + f$logical("SYS$DISK") + f$directory() + "PSC.EXE"
- X
- X---------------------cut here for GETOPT.C------------------------
- X/*
- X * getopt - get option letter from argv
- X * This software is in the public domain
- X * Originally written by Henry Spencer at the U. of Toronto
- X */
- X
- X#include <stdio.h>
- X
- Xchar *optarg; /* Global argument pointer. */
- Xint optind = 0; /* Global argv index. */
- X
- Xstatic char *scan = NULL; /* Private scan pointer. */
- X
- X/* extern char *index(); obsolete, used strchr (JDC). */
- X
- Xint
- Xgetopt(argc, argv, optstring)
- Xint argc;
- Xchar *argv[];
- Xchar *optstring;
- X{
- X register char c;
- X register char *place;
- X
- X optarg = NULL;
- X
- X if (scan == NULL || *scan == '\0') {
- X if (optind == 0)
- X optind++;
- X
- X if (optind >= argc || argv[optind][0] != '-' || argv[optind][1] == '\0')
- X return(EOF);
- X if (strcmp(argv[optind], "--")==0) {
- X optind++;
- X return(EOF);
- X }
- X
- X scan = argv[optind]+1;
- X optind++;
- X }
- X
- X c = *scan++;
- X place = strchr(optstring, c);
- X
- X if (place == NULL || c == ':') {
- X fprintf(stderr, "%s: unknown option -%c\n", argv[0], c);
- X return('?');
- X }
- X
- X place++;
- X if (*place == ':') {
- X if (*scan != '\0') {
- X optarg = scan;
- X scan = NULL;
- X } else {
- X optarg = argv[optind];
- X optind++;
- X }
- X }
- X
- X return(c);
- X}
- END_OF_FILE
- if test 4341 -ne `wc -c <'VMS_NOTES'`; then
- echo shar: \"'VMS_NOTES'\" unpacked with wrong size!
- fi
- # end of 'VMS_NOTES'
- fi
- if test -f 'crypt.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'crypt.c'\"
- else
- echo shar: Extracting \"'crypt.c'\" \(3897 characters\)
- sed "s/^X//" >'crypt.c' <<'END_OF_FILE'
- X/*
- X * Encryption utilites
- X * Bradley Williams
- X * {allegra,ihnp4,uiucdcs,ctvax}!convex!williams
- X * $Revision: 6.16 $
- X */
- X
- X#include <stdio.h>
- X#include <curses.h>
- X
- X#if defined(BSD42) || defined(BSD43)
- X#include <sys/types.h>
- X#include <sys/file.h>
- X#else
- X#include <fcntl.h>
- X#endif
- X
- X#include "sc.h"
- X
- Xchar *strcpy();
- Xchar *getpass();
- X
- X#ifdef SYSV3
- Xvoid exit();
- X#endif
- X
- Xint Crypt = 0;
- X#define MAXKEYWORDSIZE 30
- Xchar KeyWord[MAXKEYWORDSIZE] = {""};
- X
- Xvoid
- Xcreadfile (save, eraseflg)
- Xchar *save;
- Xint eraseflg;
- X{
- X register FILE *f;
- X int pipefd[2];
- X int fildes;
- X int pid;
- X
- X if (eraseflg && strcmp(save, curfile) && modcheck(" first")) return;
- X
- X if ((fildes = open(findhome(save), O_RDONLY, 0)) < 0)
- X {
- X error ("Can't read file \"%s\"", save);
- X return;
- X }
- X
- X if (eraseflg) erasedb ();
- X
- X if (pipe(pipefd) < 0) {
- X error("Can't make pipe to child");
- X return;
- X }
- X
- X deraw();
- X (void) strcpy(KeyWord, getpass("Enter key:"));
- X goraw();
- X
- X if ((pid=fork()) == 0) /* if child */
- X {
- X (void) close (0); /* close stdin */
- X (void) close (1); /* close stdout */
- X (void) close (pipefd[0]); /* close pipe input */
- X (void) dup (fildes); /* standard in from file */
- X (void) dup (pipefd[1]); /* connect to pipe */
- X (void) fprintf (stderr, " ");
- X (void) execl (CRYPT_PATH, "crypt", KeyWord, 0);
- X
- X exit (-127);
- X }
- X else /* else parent */
- X {
- X (void) close (fildes);
- X (void) close (pipefd[1]); /* close pipe output */
- X if ((f = fdopen (pipefd[0], "r")) == (FILE *)0)
- X {
- X (void) kill (pid, -9);
- X error ("Can't fdopen file \"%s\"", save);
- X (void) close (pipefd[0]);
- X return;
- X }
- X }
- X
- X loading++;
- X while (fgets(line,sizeof line,f)) {
- X linelim = 0;
- X if (line[0] != '#') (void) yyparse ();
- X }
- X --loading;
- X (void) fclose (f);
- X (void) close (pipefd[0]);
- X while (pid != wait(&fildes)) /**/;
- X linelim = -1;
- X modflg++;
- X if (eraseflg) {
- X (void) strcpy (curfile, save);
- X modflg = 0;
- X }
- X EvalAll();
- X}
- X
- Xint
- Xcwritefile (fname, r0, c0, rn, cn)
- Xchar *fname;
- Xint r0, c0, rn, cn;
- X{
- X register FILE *f;
- X int pipefd[2];
- X int fildes;
- X int pid;
- X char save[PATHLEN];
- X char *fn;
- X char *busave;
- X
- X if (*fname == '\0') fname = &curfile[0];
- X
- X fn = fname;
- X while (*fn && (*fn == ' ')) /* Skip leading blanks */
- X fn++;
- X
- X if ( *fn == '|' ) {
- X error ("Can't have encrypted pipe");
- X return(-1);
- X }
- X
- X (void) strcpy(save,fname);
- X
- X busave = findhome(save);
- X#ifdef DOBACKUPS
- X if (!backup_file(busave) &&
- X (yn_ask("Could not create backup copy, Save anyhow?: (y,n)") != 1))
- X return(0);
- X#endif
- X if ((fildes = open (busave, O_TRUNC|O_WRONLY|O_CREAT, 0600)) < 0)
- X {
- X error ("Can't create file \"%s\"", save);
- X return(-1);
- X }
- X
- X if (pipe (pipefd) < 0) {
- X error ("Can't make pipe to child\n");
- X return(-1);
- X }
- X
- X if (KeyWord[0] == '\0') {
- X deraw();
- X (void) strcpy(KeyWord, getpass("Enter key:"));
- X goraw();
- X }
- X
- X if ((pid=fork()) == 0) /* if child */
- X {
- X (void) close (0); /* close stdin */
- X (void) close (1); /* close stdout */
- X (void) close (pipefd[1]); /* close pipe output */
- X (void) dup (pipefd[0]); /* connect to pipe input */
- X (void) dup (fildes); /* standard out to file */
- X (void) fprintf (stderr, " ");
- X (void) execl (CRYPT_PATH, "crypt", KeyWord, 0);
- X exit (-127);
- X }
- X else /* else parent */
- X {
- X (void) close (fildes);
- X (void) close (pipefd[0]); /* close pipe input */
- X f = fdopen (pipefd[1], "w");
- X if (f == 0)
- X {
- X (void) kill (pid, -9);
- X error ("Can't fdopen file \"%s\"", save);
- X (void) close (pipefd[1]);
- X return(-1);
- X }
- X }
- X
- X write_fd(f, r0, c0, rn, cn);
- X
- X (void) fclose (f);
- X (void) close (pipefd[1]);
- X while (pid != wait(&fildes)) /**/;
- X (void) strcpy(curfile,save);
- X
- X modflg = 0;
- X error ("File \"%s\" written (encrypted).", curfile);
- X return(0);
- X}
- X
- END_OF_FILE
- if test 3897 -ne `wc -c <'crypt.c'`; then
- echo shar: \"'crypt.c'\" unpacked with wrong size!
- fi
- # end of 'crypt.c'
- fi
- if test -f 'psc.doc' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'psc.doc'\"
- else
- echo shar: Extracting \"'psc.doc'\" \(2314 characters\)
- sed "s/^X//" >'psc.doc' <<'END_OF_FILE'
- X.\" $Revision $
- X.TH PPNAME 1
- X.SH NAME
- Xppname \- prepare pname files
- X.SH SYNOPSIS
- X.B ppname
- X[
- X.I -fLkrSPv
- X]
- X[
- X.I -s cell
- X]
- X[
- X.I -R n
- X]
- X[
- X.I -C n
- X]
- X[
- X.I -n n
- X]
- X[
- X.I -d c
- X]
- X
- X.SH DESCRIPTION
- X.I Ppname
- Xis used to prepare data for input to the spread sheet calculator
- X.I pname(1).
- XIt accepts normal ascii data on standard input. Standard output
- Xis a
- X.I pname
- Xfile.
- XWith no options,
- X.I ppname
- Xstarts the spread sheet in cell A0. Strings are right justified.
- XAll data on a line is entered on the same row; new input lines
- Xcause the output row number to increment by one. The default delimiters
- Xare tab and space. The column formats are set to one larger
- Xthan the number of columns required to hold the largest value
- Xin the column.
- X
- XOptions:
- X
- X.IP "\-f"
- XOmit column width calculations. This option is for preparing
- Xdata to be merged with an existing spreadsheet. If the option is not
- Xspecified, the column widths calculated for the data read by
- X.I ppname
- Xwill override those already set in the existing spreadsheet.
- X
- X.IP "\-L"
- XLeft justify strings.
- X
- X.IP "\-k"
- XKeep all delimiters. This option causes the output cell to change on
- Xeach new delimiter encountered in the input stream. The default
- Xaction is to condense multiple delimters to one, so that the cell only
- Xchanges once per input data item.
- X
- X.IP "\-r"
- XOutput the data by row first then column. For input consisting of a single
- Xcolumn, this
- Xoption will result in output of one row with multiple columns
- Xinstead of a single
- Xcolumn spread sheet.
- X
- X.IP "\-s cell"
- XStart the top left corner of the spread sheet in
- X.I cell.
- XFor example,
- X.I "-s B33"
- Xwill arrange the output data so that the
- Xspread sheet starts in column B, row 33.
- X
- X.IP "\-R n"
- XIncrement by
- X.I n
- Xon each new output row.
- X
- X.IP "\-C n"
- XIncrement by
- X.I n
- Xon each new output column.
- X
- X.IP "\-n n"
- XOutput
- X.I n
- Xrows before advancing to the next column. This option is used when
- Xthe input is arranged in a single column and the spread sheet is to
- Xhave multiple columns, each of which is to be length
- X.I n.
- X
- X.IP "\-d c"
- XUse the single character
- X.I c
- Xas the delimiter between input fields.
- X
- X.IP "\-P"
- XPlain numbers only.
- XA field is a number only when there is no imbeded [-+eE].
- X
- X.IP "\-S"
- XAll numbers are strings.
- X
- X.IP "\-v"
- XPrint the version of
- Xppname
- X
- X.SH SEE ALSO
- Xpname(1)
- X
- X.SH AUTHOR
- X
- XRobert Bond
- END_OF_FILE
- if test 2314 -ne `wc -c <'psc.doc'`; then
- echo shar: \"'psc.doc'\" unpacked with wrong size!
- fi
- # end of 'psc.doc'
- fi
- if test -f 'tutorial.sc' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'tutorial.sc'\"
- else
- echo shar: Extracting \"'tutorial.sc'\" \(4327 characters\)
- sed "s/^X//" >'tutorial.sc' <<'END_OF_FILE'
- X# This data file was generated by the Spreadsheet Calculator.
- X# You almost certainly shouldn't edit it.
- X
- Xdefine "page5" A89
- Xdefine "page1" A9
- Xdefine "page2" A29
- Xdefine "page3" A49
- Xdefine "page4" A70
- Xleftstring A1 = "This is a brief sc tutorial."
- Xleftstring A3 = "Cells are named by their column and row number. For example,"
- Xleftstring A4 = "Cell A4"
- Xleftstring B4 = "Cell B4"
- Xleftstring C4 = "Cell C4"
- Xleftstring A5 = "Cell A5"
- Xleftstring A6 = "Cell A6"
- Xleftstring C6 = "Cell C6"
- Xleftstring A7 = "Cells range from A0 to ZZ(some number depending on free memory)."
- Xleftstring A8 = "Cells can also be named by the user. See 'range names' in the manual."
- Xleftstring page1 = "You can move the cursor a couple of different ways:"
- Xleftstring A11 = "^n, j and the <DOWN> arrow key go down"
- Xleftstring A12 = "^p, k and the <UP> arrow key go up"
- Xleftstring A13 = "^b, h and the <LEFT> arrow key go left"
- Xleftstring A14 = "^f, l and the <RIGHT> arrow key go right"
- Xleftstring A15 = "You can go directly to a cell by typing 'g' and the cell name. "
- Xleftstring A16 = "'g c6' will take you to cell c6."
- Xleftstring A18 = "Cells can contain numbers, formulas, or text."
- Xleftstring A19 = "Most of the cells on this page contain text."
- Xleftstring C20 = "<Type 'g page2' to continue>"
- Xleftstring A22 = "Cell d22 contains text"
- Xleftstring D22 = "Text "
- Xleftstring A23 = "Cell d23 contains a number"
- Xlet D23 = 123.34
- Xleftstring A24 = "Cell d24 contains a formula"
- Xlet D24 = D23+88
- Xleftstring A26 = "To see what the cell contains, just move the cursor"
- Xleftstring A27 = "onto the cell. The contents will show up on line 1 in the brackets."
- Xleftstring page2 = "You can enter data into cells like this:"
- Xleftstring B30 = "'<text' enters left justified text."
- Xleftstring B31 = "'>text' enters right justified text."
- Xleftstring B32 = "'=number' enters a number"
- Xleftstring B33 = "'=formula' enters a formula."
- Xleftstring A35 = "Try duplicating d22 through d24 in e22 though e24."
- Xleftstring A37 = "You erase a cell by typing 'x' with the cursor on the cell."
- Xleftstring C40 = "<Type 'g page3' to continue>"
- Xleftstring A42 = "Here is a typical use for numbers and formulas:"
- Xlet A44 = 10.3
- Xlet B44 = 1877.5
- Xlet C44 = 234.7
- Xlet E44 = @sum(A44:C44)
- Xlet A45 = 44.56
- Xlet B45 = 44.3
- Xlet C45 = -3
- Xlet E45 = @sum(A45:C45)
- Xlet A46 = 88.74
- Xlet B46 = 8000
- Xlet C46 = -9
- Xlet E46 = @sum(A46:C46)
- Xlet A47 = 99.2
- Xlet B47 = -88
- Xlet C47 = -44.6
- Xlet E47 = @sum(A47:C47)
- Xlet page3 = @sum(A44:A47)
- Xlet B49 = @sum(B44:B47)
- Xlet C49 = @sum(C44:C47)
- Xlet E49 = @sum(A44:C47)
- Xleftstring A51 = "The data is entered in a44 through c47."
- Xleftstring A52 = "Cells a49, b49 and c49 sum their respective columns."
- Xleftstring A53 = "Cells e44, e45, e46, and e47 sum their respective rows."
- Xleftstring A54 = "Cell E49 is a grand total."
- Xleftstring A55 = "Try changing some of the data cells and watch the sums change."
- Xleftstring A57 = "You can also edit cells by putting the cursor on the cell and typing:"
- Xleftstring B58 = "'e' to edit the numeric portion."
- Xleftstring B59 = "'E' to edit the string portion."
- Xleftstring C60 = "<Type 'g page4' to continue>"
- Xleftstring A62 = "Since you are reading this, you know that you can load "
- Xleftstring A63 = "a data base from a file by typing the file name as an"
- Xleftstring A64 = "argument to the program. You can also load or save a "
- Xleftstring A65 = "data base using the file commands:"
- Xleftstring B67 = "'G file'"
- Xleftstring C67 = "Gets the data from an sc file."
- Xleftstring B68 = "'P file'"
- Xleftstring C68 = "Puts the data from the spreadsheet into a file."
- Xleftstring page4 = "Try 'P foo.sc' to write this to the file foo.sc"
- Xleftstring A71 = "The Get command erases the current spreadsheet. "
- Xleftstring A72 = "To merge a spreadsheet with the one currently in"
- Xleftstring A73 = "the machine, use:"
- Xleftstring B75 = "'M file'"
- Xleftstring C75 = "Merge the data from a saved sc file."
- Xleftstring A77 = "You can also get human readable versions of the data"
- Xleftstring A78 = "by using the Write command:"
- Xleftstring C80 = "<Type 'g page5' to continue>"
- Xleftstring A82 = "Try 'W tut.txt' for a clear text version of the tutorial."
- Xleftstring A85 = "This is the end of the tutorial. We have explored"
- Xleftstring A86 = "The basic commands. Much more detail is available"
- Xleftstring A87 = "in the man page."
- Xleftstring D91 = "GOOD LUCK!"
- END_OF_FILE
- if test 4327 -ne `wc -c <'tutorial.sc'`; then
- echo shar: \"'tutorial.sc'\" unpacked with wrong size!
- fi
- # end of 'tutorial.sc'
- fi
- if test -f 'vmtbl.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'vmtbl.c'\"
- else
- echo shar: Extracting \"'vmtbl.c'\" \(5294 characters\)
- sed "s/^X//" >'vmtbl.c' <<'END_OF_FILE'
- X/* SC A Spreadsheet Calculator
- X * Spreadsheet 'tbl' creation
- X *
- X * original by James Gosling, September 1982
- X * modifications by Mark Weiser and Bruce Israel,
- X * University of Maryland
- X *
- X * More mods Robert Bond, 12/86
- X * More mods by Alan Silverstein, 3-4/88, see list of changes.
- X * Currently supported by sequent!sawmill!buhrt (Jeff Buhrt)
- X * $Revision: 6.16 $
- X *
- X */
- X#ifdef PSC
- X# include <stdio.h>
- X#else /* PSC */
- X# include <curses.h>
- X#endif /* PSC */
- X
- X#include "sc.h"
- X
- X/*
- X * check to see if *rowp && *colp are currently allocated, if not expand the
- X * current size if we can.
- X */
- X#ifndef PSC
- Xvoid
- Xcheckbounds(rowp, colp)
- Xint *rowp;
- Xint *colp;
- X{
- X if (*rowp < 0)
- X *rowp = 0;
- X else if (*rowp >= maxrows)
- X { if (*colp >= maxcols)
- X { if (!growtbl(GROWBOTH, *rowp, *colp))
- X { *rowp = maxrows -1;
- X *colp = maxcols -1;
- X }
- X return;
- X }
- X else
- X { if (!growtbl(GROWROW, *rowp, 0))
- X *rowp = maxrows-1;
- X return;
- X }
- X }
- X if (*colp < 0)
- X *colp = 0;
- X else if (*colp >= maxcols)
- X { if (!growtbl(GROWCOL, 0, *colp))
- X *colp = maxcols-1;
- X }
- X}
- X#endif /* !PSC */
- X
- X/* xrealloc will just xmalloc if oldptr is == NULL */
- X#define GROWALLOC(newptr, oldptr, nelem, type, msg) \
- X newptr = (type *)xrealloc((char *)oldptr, \
- X (unsigned)(nelem*sizeof(type))); \
- X if (newptr == (type *)NULL) \
- X { error(msg); \
- X return(FALSE); \
- X } \
- X oldptr = newptr /* wait incase we can't alloc */
- X
- Xstatic char nolonger[] = "The table can't be any longer";
- Xstatic char nowider[] = "The table can't be any wider";
- X
- X/*
- X * grow the main && auxiliary tables (reset maxrows/maxcols as needed)
- X * toprow &&/|| topcol tell us a better guess of how big to become.
- X * we return TRUE if we could grow, FALSE if not....
- X */
- Xint
- Xgrowtbl(rowcol, toprow, topcol)
- Xint rowcol;
- Xint toprow, topcol;
- X{
- X struct ent ***tbl2;
- X struct ent ** nullit;
- X int cnt;
- X int *fwidth2;
- X int *precision2;
- X int *realfmt2;
- X char *col_hidden2;
- X char *row_hidden2;
- X int newrows, newcols;
- X int i;
- X
- X#ifndef PSC
- X newrows = maxrows;
- X#endif /* !PSC */
- X
- X newcols = maxcols;
- X if (rowcol == GROWNEW)
- X {
- X#ifndef PSC
- X maxrows = toprow = 0;
- X /* when we first start up, fill the screen w/ cells */
- X { int startval;
- X startval = LINES - RESROW;
- X newrows = startval > MINROWS ? startval : MINROWS;
- X startval = ((COLS) - RESCOL) / DEFWIDTH;
- X newcols = startval > MINCOLS ? startval : MINCOLS;
- X }
- X#else
- X newcols = MINCOLS;
- X#endif /* !PSC */
- X maxcols = topcol = 0;
- X }
- X#ifndef PSC
- X /* set how much to grow */
- X if ((rowcol == GROWROW) || (rowcol == GROWBOTH))
- X { if (toprow > maxrows)
- X newrows = GROWAMT + toprow;
- X else
- X newrows += GROWAMT;
- X }
- X#endif /* !PSC */
- X if ((rowcol == GROWCOL) || (rowcol == GROWBOTH))
- X { if ((rowcol == GROWCOL) && ((maxcols == ABSMAXCOLS) ||
- X (topcol >= ABSMAXCOLS)))
- X { error(nowider);
- X return(FALSE);
- X }
- X
- X if (topcol > maxcols)
- X newcols = GROWAMT + topcol;
- X else
- X newcols += GROWAMT;
- X
- X if (newcols > ABSMAXCOLS)
- X newcols = ABSMAXCOLS;
- X }
- X
- X#ifndef PSC
- X if ((rowcol == GROWROW) || (rowcol == GROWBOTH) || (rowcol == GROWNEW))
- X {
- X struct ent *** lnullit;
- X int lcnt;
- X
- X GROWALLOC(row_hidden2, row_hidden, newrows, char, nolonger);
- X memset(row_hidden+maxrows, 0, (newrows-maxrows)*sizeof(char));
- X
- X /*
- X * alloc tbl row pointers, per net.lang.c, calloc does not
- X * necessarily fill in NULL pointers
- X */
- X GROWALLOC(tbl2, tbl, newrows, struct ent **, nolonger);
- X for(lnullit = tbl+maxrows, lcnt = 0; lcnt < newrows-maxrows;
- X lcnt++, lnullit++)
- X *lnullit = (struct ent **)NULL;
- X/* memset(tbl+maxrows, (char *)NULL, (newrows-maxrows)*(sizeof(struct ent **)));*/
- X }
- X#endif /* !PSC */
- X
- X if ((rowcol == GROWCOL) || (rowcol == GROWBOTH) || (rowcol == GROWNEW))
- X {
- X GROWALLOC(fwidth2, fwidth, newcols, int, nowider);
- X GROWALLOC(precision2, precision, newcols, int, nowider);
- X GROWALLOC(realfmt2, realfmt, newcols, int, nowider);
- X#ifdef PSC
- X memset(fwidth+maxcols, 0, (newcols-maxcols)*sizeof(int));
- X memset(precision+maxcols, 0, (newcols-maxcols)*sizeof(int));
- X memset(realfmt+maxcols, 0, (newcols-maxcols)*sizeof(int));
- X }
- X#else
- X GROWALLOC(col_hidden2, col_hidden, newcols, char, nowider);
- X memset(col_hidden+maxcols, 0, (newcols-maxcols)*sizeof(char));
- X for (i = maxcols; i < newcols; i++) {
- X fwidth[i] = DEFWIDTH;
- X precision[i] = DEFPREC;
- X realfmt[i]= DEFREFMT;
- X }
- X
- X /* [re]alloc the space for each row */
- X for (i = 0; i < maxrows; i++)
- X {
- X if ((tbl[i] = (struct ent **)xrealloc((char *)tbl[i],
- X (unsigned)(newcols * sizeof(struct ent **)))) == (struct ent **)0)
- X { error(nowider);
- X return(FALSE);
- X }
- X for(nullit = ATBL(tbl, i, maxcols), cnt = 0;
- X cnt < newcols-maxcols; cnt++, nullit++)
- X *nullit = (struct ent *)NULL;
- X/* memset((char *)ATBL(tbl,i, maxcols), 0,
- X (newcols-maxcols)*sizeof(struct ent **));
- X*/
- X }
- X }
- X else
- X i = maxrows;
- X
- X /* fill in the bottom of the table */
- X for (; i < newrows; i++)
- X { if ((tbl[i] = (struct ent **)xmalloc((unsigned)(newcols *
- X sizeof(struct ent **)))) == (struct ent **)0)
- X { error(nowider);
- X return(FALSE);
- X }
- X for(nullit = tbl[i], cnt = 0; cnt < newcols; cnt++, nullit++)
- X *nullit = (struct ent *)NULL;
- X/* memset((char *)tbl[i], 0, newcols*sizeof(struct ent **));*/
- X }
- X
- X FullUpdate++;
- X maxrows = newrows;
- X#endif /* PSC */
- X
- X maxcols = newcols;
- X return(TRUE);
- X}
- END_OF_FILE
- if test 5294 -ne `wc -c <'vmtbl.c'`; then
- echo shar: \"'vmtbl.c'\" unpacked with wrong size!
- fi
- # end of 'vmtbl.c'
- fi
- if test -f 'xmalloc.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'xmalloc.c'\"
- else
- echo shar: Extracting \"'xmalloc.c'\" \(1356 characters\)
- sed "s/^X//" >'xmalloc.c' <<'END_OF_FILE'
- X/*
- X * A safer saner malloc, for careless programmers
- X * $Revision: 6.16 $
- X */
- X
- X#include <stdio.h>
- X#include <curses.h>
- X#include "sc.h"
- X
- Xextern char *malloc();
- Xextern char *realloc();
- Xextern void free();
- Xvoid fatal();
- X
- X#ifdef SYSV3
- Xextern void free();
- Xextern void exit();
- X#endif
- X
- X#define MAGIC (double)1234567890.1234456789
- X
- Xchar *
- Xxmalloc(n)
- Xunsigned n;
- X{
- X register char *ptr;
- X
- X if ((ptr = malloc(n + sizeof(double))) == NULL)
- X fatal("xmalloc: no memory");
- X *((double *) ptr) = MAGIC; /* magic number */
- X return(ptr + sizeof(double));
- X}
- X
- X/* we make sure realloc will do a malloc if needed */
- Xchar *
- Xxrealloc(ptr, n)
- Xchar *ptr;
- Xunsigned n;
- X{
- X if (ptr == NULL)
- X return(xmalloc(n));
- X
- X ptr -= sizeof(double);
- X if (*((double *) ptr) != MAGIC)
- X fatal("xrealloc: storage not xmalloc'ed");
- X
- X if ((ptr = realloc(ptr, n + sizeof(double))) == NULL)
- X fatal("xmalloc: no memory");
- X *((double *) ptr) = MAGIC; /* magic number */
- X return(ptr + sizeof(double));
- X}
- X
- Xvoid
- Xxfree(p)
- Xchar *p;
- X{
- X if (p == NULL)
- X fatal("xfree: NULL");
- X p -= sizeof(double);
- X if (*((double *) p) != MAGIC)
- X fatal("xfree: storage not malloc'ed");
- X free(p);
- X}
- X
- X#ifdef PSC
- Xvoid
- Xfatal(str)
- Xchar *str;
- X{
- X (void) fprintf(stderr,"%s\n", str);
- X exit(1);
- X}
- X#else
- Xvoid
- Xfatal(str)
- Xchar *str;
- X{
- X deraw();
- X (void) fprintf(stderr,"%s\n", str);
- X diesave();
- X exit(1);
- X}
- X#endif /* PSC */
- END_OF_FILE
- if test 1356 -ne `wc -c <'xmalloc.c'`; then
- echo shar: \"'xmalloc.c'\" unpacked with wrong size!
- fi
- # end of 'xmalloc.c'
- fi
- echo shar: End of archive 7 \(of 7\).
- cp /dev/null ark7isdone
- MISSING=""
- for I in 1 2 3 4 5 6 7 ; do
- if test ! -f ark${I}isdone ; then
- MISSING="${MISSING} ${I}"
- fi
- done
- if test "${MISSING}" = "" ; then
- echo You have unpacked all 7 archives.
- rm -f ark[1-9]isdone
- else
- echo You still must unpack the following archives:
- echo " " ${MISSING}
- fi
- exit 0
- exit 0 # Just in case...
- --
- Kent Landfield INTERNET: kent@sparky.IMD.Sterling.COM
- Sterling Software, IMD UUCP: uunet!sparky!kent
- Phone: (402) 291-8300 FAX: (402) 291-4362
- Please send comp.sources.misc-related mail to kent@uunet.uu.net.
-