perlman@wanginst.UUCP (Gary Perlman) (08/12/85)
This seems to have had problems getting through before. It was advertised in net.math.stat. sample is an educational program for teaching about sampling distributions. It lets you provide a distribution from which it will graphically display the means of samples of sizes of your choice. Posted to net.sources is the source code for sample and a mildly instructive manual entry. I think the program might be useful for an introductory statistics course lab demonstration. A demonstration shell script, with some example distributions, are also included. As part of the distribution, I have included my tiny curses package. It looks like curses, but it's not. The nature of the sample display requires something without screen optimization, which gets in the way here. Tiny curses is pretty useful for screen handling without much redrawing or the need to keep track of what is on the screen. As a demonstration of its compatibility with real curses, you can compile sample with regular curses and compare the running times. Gary Perlman Wang Institute Tyngsboro, MA 01879 (617) 649-9731 UUCP: decvax!wanginst!perlman CSNET: perlman@wanginst #! /bin/sh # This is a shell archive, meaning: # 1. Remove everything above the #! /bin/sh line. # 2. Save the resulting text in a file. # 3. Execute the file with /bin/sh (not csh) to create the files: # sample.c # getword.c # tc.c # getopt.c # makefile # curses.h # sample.1 # tc.3 # sample.demo # dist.tri # dist.antitri # dist.skew # dist.uni # This archive created: Mon Aug 12 01:34:20 1985 # By: Gary Perlman (Wang Institute, Tyngsboro, MA 01879 USA) export PATH; PATH=/bin:/usr/bin:$PATH echo shar: "extracting 'sample.c'" '(4941 characters)' if test -f 'sample.c' then echo shar: "will not over-write existing file 'sample.c'" else sed 's/^ X//' << \SHAR_EOF > 'sample.c' X/* X sample: display random samples X*/ X#include "curses.h" X#include <math.h> X Xint BOTTOM; /* set to LINES-1 */ X X#define MAXCOLS 100 /* max # of columns on screen */ Xint Colcount[MAXCOLS]; /* current count in column bin */ Xint Sampsize = 1; /* sample size */ Xint Outline = 0; /* only show shape of distribution */ Xint Plotchar = '*'; /* histogram plotting character */ X Xtypedef double DATUM; X#define MAXDISTRIB 1000 /* max size of population distribution */ XDATUM Distrib[MAXDISTRIB]; /* population distribution */ Xint N = 0; /* population size */ XDATUM S1 = 0.0; /* sum of distribution values */ XDATUM S2 = 0.0; /* sum of squared distribution values */ XDATUM S3 = 0.0; /* sum of cubed distribution values */ XDATUM S4 = 0.0; /* sum of quarted distribution values */ XDATUM Max; /* distribution maximum */ XDATUM Min; /* distribution minimum */ X Xdouble sample (); X#define EPSILON .000000001 X#define scale(x) (((x)-Min)/(Max-Min+EPSILON)) /* in [0, 1) */ X#define fzero(x) (fabs(x) < EPSILON) X Xmain (argc, argv) char **argv; X { X double x; X double x2; X int n = 0; X double s1 = 0.0; X double s2 = 0.0; X double s3 = 0.0; X double s4 = 0.0; X readdata (); X initial (argc, argv); X for (;;) X { X if (Sampsize < 1) /* just dump out distribution */ X { X if (n == N) finish (); X x = Distrib[n]; X } X else x = sample (Sampsize, Distrib, N); X x2 = x * x; X n++; X s1 += x; X s2 += x2; X s3 += x2 * x; X s4 += x2 * x2; X if (plotdata (x, n, s1, s2, s3, s4) == 0) X if (Sampsize > 0) finish (); X else beep (); X } X } X Xreaddata () X { X DATUM x; X DATUM x2; X char string[100]; X while (getword (string, stdin)) X { X if (N == MAXDISTRIB) X { X fprintf (stderr, "sample: max # of values = %d\n", MAXDISTRIB); X exit (1); X } X x = atof (string); X if (N == 0) /* first time around */ X Min = Max = x; X else if (x > Max) X Max = x; X else if (x < Min) X Min = x; X Distrib[N++] = x; X S1 += x; X x2 = x * x; X S2 += x2; X S3 += x2 * x; X S4 += x2 * x2; X } X if (N == 0) X { X fprintf (stderr, "sample: missing input distribution\n"); X exit (2); X } X } X Xinitial (argc, argv) char **argv; X { X long time (); X extern char *optarg; X extern int optind; X int errflg = 0; X int C; X char *optstring = "c:n:o"; X char *usage = "[-o] [-c plotchar] [-n size]"; X while ((C = getopt (argc, argv, optstring)) != EOF) X switch (C) X { X case 'c': Plotchar = *optarg; break; X case 'n': Sampsize = atoi (optarg); break; X case 'o': Outline = 1; break; X default: errflg++; break; X } X if (errflg) X { X fprintf (stderr, "Usage: %s %s\n", argv[0], usage); X exit (1); X } X srandom (time (0) + getpid ()); X initscr (); X BOTTOM = LINES-1; X clear (); X bottomline (); X inform (0, N, S1, S2, S3, S4); X refresh (); X } X Xbottomline () X { X char buf[BUFSIZ]; X int width = 7; X move (BOTTOM, 0); X clrtoeol (); X standout (); X printw ("%-.2f", Min); X move (BOTTOM, COLS-width); X printw ("%*.2f", width-1, Max); X if (Sampsize > 0) X sprintf (buf, "Displaying samples of size %d", Sampsize); X else X sprintf (buf, "Displaying the base distribution"); X move (BOTTOM, (COLS-strlen(buf))/2); X printw (buf); X standend (); X } X Xfinish () X { X move (BOTTOM, 0); X clrtoeol (); X refresh (); X endwin (); X exit (0); X } X X/* X takes a sample of size "n" from a supplied vector X returns the mean of the sample X*/ Xdouble Xsample (n, distrib, size) Xint n; /* sample size */ XDATUM *distrib; /* vector of population values */ Xint size; /* size of population distribution */ X { X int trial; X DATUM s1 = 0.0; X if (n == 0 || size == 0) return (0.0); X for (trial = 0; trial < n; trial++) X s1 += distrib [ random () % size ]; X return (s1 / n); X } X Xplotdata (x, n, s1, s2, s3, s4) Xdouble x; Xint n; Xdouble s1; Xdouble s2; Xdouble s3; Xdouble s4; X { X int dindex = (int) (scale (x) * COLS); X int col = dindex; X int row; X Colcount[dindex]++; X if (Colcount[dindex] < BOTTOM) X { X inform (40, n, s1, s2, s3, s4); X row = LINES-Colcount[dindex]-1; X if (Outline && row < BOTTOM-1) X { X move (row+1, col); X addch (' '); X } X move (row, col); X addch (Plotchar); X refresh (); X return (1); X } X else return (0); X } X Xinform (column, n, s1, s2, s3, s4) Xint column; Xint n; Xdouble s1; Xdouble s2; Xdouble s3; Xdouble s4; X { X double M = 0.0; X double var = 0.0; X double sd = 0.0; X double skew; X double kurtosis; X double m2; X if (n > 0) X { X move (0, column); X M = s1/n; X printw ("#%-4d %5.2f ", n, M); X m2 = M * M; X if (n > 1) X { X var = (s2 - M*s1)/(n-1); X if (fzero (var)) kurtosis = skew = sd = var = 0.0; X else X { X sd = sqrt (var); X skew = (s3 - 3.0*M*s2 + 3.0*m2*s1 - m2*s1)/(n*var*sd); X kurtosis = (s4-4.*M*s3+6.*m2*s2-4.*m2*M*s1+n*m2*m2)/(n*var*var); X } X printw (" %5.2f", sd); X printw (" %5.2f", skew); X printw (" %5.2f", kurtosis); X clrtoeol (); X } X } X } SHAR_EOF if test 4941 -ne "`wc -c < 'sample.c'`" then echo shar: "error transmitting 'sample.c'" '(should have been 4941 characters)' fi fi echo shar: "extracting 'getword.c'" '(631 characters)' if test -f 'getword.c' then echo shar: "will not over-write existing file 'getword.c'" else sed 's/^ X//' << \SHAR_EOF > 'getword.c' X/* LINTLIBRARY */ X#include <stdio.h> X#include <ctype.h> X/* X getword(string,ioptr) is equivalent to fscanf(ioptr,"%s",string) X but much faster. It returns a NULL pointer on EOF or the end X of the string when one is found. The return result can be used X to find the length of the obtained string. X*/ X Xchar * Xgetword (string, ioptr) Xregister char *string; Xregister FILE *ioptr; X { X register int C; X while ((C = getc (ioptr)) != EOF && isspace (C)); X if (C == EOF) return (NULL); X do X { X *string++ = C; X } while ((C = getc (ioptr)) != EOF && !isspace (C)); X *string = '\0'; X return (string); /* pointer to the end of string */ X } SHAR_EOF if test 631 -ne "`wc -c < 'getword.c'`" then echo shar: "error transmitting 'getword.c'" '(should have been 631 characters)' fi fi echo shar: "extracting 'tc.c'" '(5913 characters)' if test -f 'tc.c' then echo shar: "will not over-write existing file 'tc.c'" else sed 's/^ X//' << \SHAR_EOF > 'tc.c' X/* LINTLIBRARY */ X/* X These are simple versions of the curses(3) screen handling functions. X Tiny curses does not support windows or screen optimization, X so they are simply a high level interface to the termcap(3) functions. X*/ X Xstatic char sccsid[] = "@(#) Tiny_Curses 1.0 (WangInst) Feb 24 85"; X#include "curses.h" X X#include <sgtty.h> Xstatic struct sgttyb Savetty; /* save tty state here */ Xstatic struct sgttyb Curtty; /* current tty state here */ X X#include <signal.h> X Xextern char *getenv (); Xextern char *tgetstr (); Xextern char *tgoto (); X Xstatic Xint Xoutchar (c) /* static fun used to output characters by termcap */ Xregister int c; X { X putc (c, stdout); X } X Xint LINES; /* number of lines */ Xint COLS; /* number of columns */ X X/* these external variables are used by termcap functions */ Xchar PC; /* padding character */ Xchar *BC; /* backspace */ Xchar *UP; /* up */ Xshort ospeed; /* output speed */ X X/* terminal capabilities strings stored for efficiency */ Xstatic char *CD; /* clear to end of display */ Xstatic char *CE; /* clear to end of line */ Xstatic char *CL; /* clear line */ Xstatic char *AL; /* add (insert) line */ Xstatic char *DL; /* delete line */ Xstatic char *CM; /* cursor movement */ Xstatic char *VB; /* visible bell */ Xstatic char *SO; /* stand out */ Xstatic char *SE; /* stand end */ Xstatic char *IC; /* insert char */ Xstatic char *IM; /* enter insert char mode */ Xstatic char *EI; /* end insert mode */ Xstatic char *DC; /* delete char */ Xstatic char *DM; /* enter delete char mode */ Xstatic char *ED; /* end delete mode */ Xstatic char *US; /* underscore */ Xstatic char *UE; /* underend */ X X/*FUN .FN void refresh () "flush output to screen */ Xvoid Xrefresh () X { X (void) fflush (stdout); X } X X/*FUN .FN void setterm "(char *name)" "set terminal capabilities */ Xvoid Xsetterm (name) Xchar *name; X { X char Termcap[1024]; /* termcap entry stored here */ X static char Abuf[BUFSIZ]; /* capabilities stored here */ X char *area = Abuf; X char *ptr; X if (name == NULL) return; X if (tgetent (Termcap, name) != 1) return; X BC = tgetstr ("bc", &area); X ptr = tgetstr ("pc", &area); X if (ptr && *ptr) PC = *ptr; X UP = tgetstr ("up", &area); X COLS = tgetnum ("co"); X LINES = tgetnum ("li"); X AL = tgetstr ("al", &area); X CD = tgetstr ("cd", &area); X CE = tgetstr ("ce", &area); X CL = tgetstr ("cl", &area); X CM = tgetstr ("cm", &area); X DC = tgetstr ("dc", &area); X DL = tgetstr ("dl", &area); X DM = tgetstr ("dm", &area); X ED = tgetstr ("ed", &area); X EI = tgetstr ("ei", &area); X IC = tgetstr ("ic", &area); X IM = tgetstr ("im", &area); X SE = tgetstr ("se", &area); X SO = tgetstr ("so", &area); X UE = tgetstr ("ue", &area); X US = tgetstr ("us", &area); X VB = tgetstr ("vb", &area); X } X X/*FUN .FN void crmode () "put tty in cbreak mode */ Xvoid Xcrmode () X { X Curtty.sg_flags |= CBREAK; X (void) stty (0, &Curtty); X } X X/*FUN .FN void nocrmode () "take tty out of cbreak mode */ Xnocrmode () /* out of cbreak mode */ X { X Curtty.sg_flags &= ~CBREAK; X (void) stty (0, &Curtty); X } X X/*FUN .FN void raw () "put tty in raw mode */ Xvoid Xraw () X { X Curtty.sg_flags |= RAW; X (void) stty (0, &Curtty); X } X X/*FUN .FN void noraw () "take tty out of raw mode */ Xvoid Xnoraw () X { X Curtty.sg_flags &= ~RAW; X (void) stty (0, &Curtty); X } X X/*FUN .FN void echo () "have tty echo input characters */ Xvoid Xecho () X { X Curtty.sg_flags |= ECHO; X (void) stty (0, &Curtty); X } X X/*FUN .FN void noecho () "have tty echo not input characters */ Xvoid Xnoecho () X { X Curtty.sg_flags &= ~ECHO; X (void) stty (0, &Curtty); X } X X/*FUN .FN void resetty () "reset tty to stored state */ Xvoid Xresetty () X { X (void) stty (0, &Savetty); X } X X/*FUN .FN void savetty () "save tty state */ Xvoid Xsavetty () X { X (void) gtty (0, &Savetty); X } X X/*FUN .FN void standout () "begin highlighted text */ Xvoid Xstandout () X { X tputs (SO, 1, outchar); X } X X/*FUN .FN void standend () "end highlighted text */ Xvoid Xstandend () X { X tputs (SE, 1, outchar); X } X X/*FUN .FN void underscore () "begin underscored text */ Xvoid Xunderscore () X { X tputs (US, 1, outchar); X } X X/*FUN .FN void underend () "end underscored text */ Xunderend () X { X tputs (UE, 1, outchar); X } X X/*FUN .FN void beep () "visible bell or at least beep */ Xvoid Xbeep () X { X if (VB && *VB) X tputs (VB, 1, outchar); X else outchar ('\007'); X } X X/*FUN .FN void clear () "clear screen */ Xvoid Xclear () X { X tputs (CL, LINES, outchar); X } X X/*FUN .FN void clrtoeol () "clear to end of line */ Xvoid Xclrtoeol () X { X tputs (CE, 1, outchar); X } X X/*FUN .FN void clrtobot () "clear to bottom of screen */ Xvoid Xclrtobot () X { X tputs (CD, LINES, outchar); X } X X/*FUN .FN void delch () "delete the character under the cursor */ Xvoid Xdelch () X { X tputs (DM, 1, outchar); X tputs (DC, 1, outchar); X tputs (ED, 1, outchar); X } X X/*FUN .FN void deleteln () "delete the current line */ Xvoid Xdeleteln () X { X tputs (DL, LINES, outchar); X } X X/*FUN .FN void insch "(int c)" "insert character */ Xvoid Xinsch (c) Xint c; X { X tputs (IM, 1, outchar); X tputs (IC, 1, outchar); X outchar (c); X tputs (EI, 1, outchar); X } X X/*FUN .FN void insertln () "insert line */ Xvoid Xinsertln () X { X tputs (AL, LINES, outchar); X } X X/*FUN .FN void move "(int y, x)" "move to line=y col=x (zero origin) */ Xvoid Xmove (y, x) Xregister int y; Xregister int x; X { X if (y < 0 || x < 0) return; X if (y >= LINES || x >= COLS) return; X tputs (tgoto(CM,x,y), 1, outchar); X } X X/*FUN .FN void endwin () "reset tty to old parameters */ Xvoid Xendwin () X { X (void) resetty (); X } X Xstatic Xdie () /* static function used to die gracefully */ X { X (void) signal (SIGINT, SIG_IGN); X beep (); X move (LINES-1, 0); X clrtoeol (); X endwin (); X exit (1); X } X X/*FUN .FN void initscr () "initialize screen */ Xvoid Xinitscr () X { X extern die (); X (void) savetty (); X (void) gtty (0, &Curtty); X Curtty.sg_flags &= ~XTABS; X (void) stty (0, &Curtty); X ospeed = Savetty.sg_ospeed; X (void) setterm (getenv ("TERM")); X (void) signal (SIGINT, die); X } SHAR_EOF if test 5913 -ne "`wc -c < 'tc.c'`" then echo shar: "error transmitting 'tc.c'" '(should have been 5913 characters)' fi fi echo shar: "extracting 'getopt.c'" '(2961 characters)' if test -f 'getopt.c' then echo shar: "will not over-write existing file 'getopt.c'" else sed 's/^ X//' << \SHAR_EOF > 'getopt.c' X/* X I got this off net.sources from Henry Spencer. X It is a public domain getopt(3) like in SYstem V. X I have made the following modifications: X X index(s,c) was added because too many people could X not compile getopt without it. X X A test main program was added, ifdeffed by STANDALONE. X This main program is a public domain implementation X of the getopt(1) program like in System V. The getopt X program can be used to standardize shell option handling. X e.g. cc -DSTANDALONE getopt.c -o getopt X*/ X#include <stdio.h> Xstatic char sccsfid[] = "@(#) getopt.c 5.0 (UTZoo) 1985"; X X#define ARGCH (int)':' X#define BADCH (int)'?' X#define EMSG "" X#define ENDARGS "--" X X/* this is included because index is not on some UNIX systems */ Xstatic Xchar * Xindex (s, c) Xregister char *s; Xregister int c; X { X while (*s) X if (c == *s) return (s); X else s++; X return (NULL); X } X X/* X * get option letter from argument vector X */ Xint opterr = 1, /* useless, never set or used */ X optind = 1, /* index into parent argv vector */ X optopt; /* character checked for validity */ Xchar *optarg; /* argument associated with option */ X X#define tell(s) fputs(*nargv,stderr);fputs(s,stderr); \ X fputc(optopt,stderr);fputc('\n',stderr);return(BADCH); X Xgetopt(nargc,nargv,ostr) Xint nargc; Xchar **nargv, X *ostr; X{ X static char *place = EMSG; /* option letter processing */ X register char *oli; /* option letter list index */ X char *index(); X X if(!*place) { /* update scanning pointer */ X if(optind >= nargc || *(place = nargv[optind]) != '-' || !*++place) return(EOF); X if (*place == '-') { /* found "--" */ X ++optind; X return(EOF); X } X } /* option letter okay? */ X if ((optopt = (int)*place++) == ARGCH || !(oli = index(ostr,optopt))) { X if(!*place) ++optind; X tell(": illegal option -- "); X } X if (*++oli != ARGCH) { /* don't need argument */ X optarg = NULL; X if (!*place) ++optind; X } X else { /* need an argument */ X if (*place) optarg = place; /* no white space */ X else if (nargc <= ++optind) { /* no arg */ X place = EMSG; X tell(": option requires an argument -- "); X } X else optarg = nargv[optind]; /* white space */ X place = EMSG; X ++optind; X } X return(optopt); /* dump back option letter */ X} X X#ifdef STANDALONE Xstatic char sccspid[] = "@(#) getopt.c 5.1 (WangInst) 6/15/85"; Xmain (argc, argv) char **argv; X { X char *optstring = argv[1]; X char *argv0 = argv[0]; X extern int optind; X extern char *optarg; X int opterr = 0; X int C; X char *opi; X if (argc == 1) X { X fprintf (stderr, "Usage: %s optstring args\n", argv0); X exit (1); X } X argv++; X argc--; X argv[0] = argv0; X while ((C = getopt (argc, argv, optstring)) != EOF) X { X if (C == BADCH) opterr++; X printf ("-%c ", C); X opi = index (optstring, C); X if (opi && opi[1] == ARGCH) X if (optarg) X printf ("\"%s\" ", optarg); X else opterr++; X } X printf ("%s", ENDARGS); X while (optind < argc) X printf (" \"%s\"", argv[optind++]); X putchar ('\n'); X exit (opterr); X } X X#endif SHAR_EOF if test 2961 -ne "`wc -c < 'getopt.c'`" then echo shar: "error transmitting 'getopt.c'" '(should have been 2961 characters)' fi fi echo shar: "extracting 'makefile'" '(669 characters)' if test -f 'makefile' then echo shar: "will not over-write existing file 'makefile'" else sed 's/^ X//' << \SHAR_EOF > 'makefile' X# NB if your system does not have the functions: random and srandom, X#then un-comment the next line X#DEFS=-Drandom=rand -Dsrandom=srand X X# NB if your system has getopt, then remove all references to getopt here XSRCS=sample.c getword.c tc.c getopt.c XOBJS=sample.o getword.o tc.o getopt.o X XDOCS=sample.1 tc.3 XHDRS=curses.h XDEMO=sample.demo dist.tri dist.antitri dist.skew dist.uni XARCS=$(SRCS) makefile $(DIST) $(HDRS) $(DOCS) $(DEMO) XLIBS=-ltermlib -lm XCFLAGS=-O X Xsample: $(OBJS) X cc $(CFLAGS) -o sample $(OBJS) $(LIBS) X Xsample.o: sample.c X cc $(CFLAGS) -c $(DEFS) sample.c X Xdemo: sample X sample.demo X Xarchive: $(ARCS) X shar -a $(ARCS) > archive X Xlint: X lint -h $(SRCS) SHAR_EOF if test 669 -ne "`wc -c < 'makefile'`" then echo shar: "error transmitting 'makefile'" '(should have been 669 characters)' fi fi echo shar: "extracting 'curses.h'" '(305 characters)' if test -f 'curses.h' then echo shar: "will not over-write existing file 'curses.h'" else sed 's/^ X//' << \SHAR_EOF > 'curses.h' X#ifndef TC_H X X#include <stdio.h> X X#define addch(c) putchar(c) X#define addstr(s) fputs(s, stdout) X#define printw printf X#define getch() getchar() X#define getstr(s) gets(s) X Xextern int LINES; /* number of lines in display */ Xextern int COLS; /* number of columns in display */ X X#define TC_H X#endif SHAR_EOF if test 305 -ne "`wc -c < 'curses.h'`" then echo shar: "error transmitting 'curses.h'" '(should have been 305 characters)' fi fi echo shar: "extracting 'sample.1'" '(2284 characters)' if test -f 'sample.1' then echo shar: "will not over-write existing file 'sample.1'" else sed 's/^ X//' << \SHAR_EOF > 'sample.1' X.TH SAMPLE 1WI "10 May 1985" "Wang Institute" "UNIX User's Manual" X.SH NAME Xsample \- take random samples from a statistical distribution X.SH SYNOPSIS X.B sample X[-c plotchar] [-n size] [-o] X.SH OPTIONS X.de OP X.TP X.B -\\$1 \\$2 X.. X.OP c plotchar Xset the histogram plotting character. X.OP n size Xset the sample size. XIf the sample size is less than or equal to zero, Xthen the input distribution is displayed. X.OP o Xshow only the outline of the distribution. XThis ends up looking like a race one might want to place bets on. X.SH DESCRIPTION X.PP X.I sample Xcan help develop intuitions about how statistics of samples from distributions Xare related to the distributions. X.I sample Xreads in a distribution of whitespace separated numbers from the standard input Xand randomly samples from that distribution, Xshowing statistics and a dynamic histogram of the sample means. X.SS "The Display X.PP XOn the top line of the display are Xstatistics about the parent distribution and the sampling Xdistribution of the mean of the specified sized samples. XThe statistics include: Xthe size, (grand) mean, standard deviation, skew, and kurtosis. XThe histogram of the sample means Xscales the values to fit in the width of the screen Xand grows until the screen would overflow. X.SS "Things to Watch For X.PP XThe expected value of the standard deviation of Xthe sampling distribution of the mean X(often called the standard error of the mean, or SE) Xis: X.ce XSE = SD / sqrt(N) Xwhere SD is the standard deviation of the parent distribution Xfrom which samples are being taken, Xand N is the sample size. XSo, if samples of size 25 are taken, Xthen the expected value of the standard error is one fifth Xof the standard deviation of the parent distribution. XThe expected value of the sample means (the mean of the means) Xis the mean of the parent distribution. X.PP XFor reference, Xnormal distributions have zero skew and kurtosis equal to 3.0. XIt is instructive to see that for any shaped parent distribution, Xthe sampling distribution of the mean approaches a normal distribution Xas the sample size increases. XThis is proven in the central limit theorem. X.SH EXAMPLE X.PP XThe following takes samples of size 100 from the distribution Xof numbers 1-10. X.ce Xecho "1 2 3 4 5 6 7 8 9 10" | sample -n 100 X.SH AUTHOR XGary Perlman SHAR_EOF if test 2284 -ne "`wc -c < 'sample.1'`" then echo shar: "error transmitting 'sample.1'" '(should have been 2284 characters)' fi fi echo shar: "extracting 'tc.3'" '(2597 characters)' if test -f 'tc.3' then echo shar: "will not over-write existing file 'tc.3'" else sed 's/^ X//' << \SHAR_EOF > 'tc.3' X.TH TC(3WI) X.SH NAME Xtiny curses \- screen functions without ``optimal'' cursor motion X.SH SYNOPSIS Xcc [flags] files tc.o -ltermlib [libraries] X.SH DESCRIPTION XThese routines give the programmer the high level Xcurses(3) interface to the termcap(3) functions Xwithout the overhead of the curses(3) screen optimization capabilities. XTiny curses is useful for simple screen formatting Xand is more efficient for displays that do not require Xsignificant redrawing. X.PP XTo use the routines, Xthe function X.I initscr() Xshould be called before any others. XThe routine X.I endwin() Xshould be called before exiting. X.PP XThe names of the functions are identical to those of curses(3) Xso that it is easy to move from Tiny curses to real curses(3). XThere are many functions provided by curses(3) that are not provided Xhere (e.g., windows), so the opposite translation is more difficult. X.SH AUTHOR XGary Perlman X.SH "SEE ALSO Xcurses(3), termcap(3), termcap(5) X.SH FILES X.nf X.ta 1.5i X#include "curses.h" definitions of variables and compatibility functions X/etc/termcap terminal capability database X.SH VARIABLES X.nf X.ta 1i Xint LINES; /* number of lines in display */ Xint COLS; /* number of columns in display */ X.SH FUNCTIONS X.SS "Basic X.nf X.ta 1i Xendwin () reset tty to old parameters Xinitscr () initialize screen Xmove (y, x) move to line=y column=x (zero origin) Xrefresh () flush output to screen (fflush(stdout)) X.SS "Clear Regions X.nf X.ta 1i Xclear () clear screen Xclrtobot () clear to bottom of screen Xclrtoeol () clear to end of line X.SS "Terminal Functions X.nf X.ta 1i Xcrmode () cbreak mode Xecho () echo characters Xnocrmode () out of cbreak mode Xnoecho () don't echo characters Xnoraw () no raw mode Xraw () raw mode Xresetty () reset tty to stored state Xsavetty () save tty state X.SS Highlighting X.nf X.ta 1i Xbeep () visible or at least audible bell Xstandend () don't highlight text Xstandout () highlight text Xunderend () end underscore mode Xunderscore () underscore characters X.SS "Editing Functions X.nf X.ta 1i Xdelch () delete the character under the cursor Xdeleteln () delete the current line Xinsch (c) insert character Xinsertln () insert line X.SH DIAGNOSTICS X.PP XTo be compatible with curses(3), Xthere are no diagnostics. X.SH NOTES X.PP XThe refresh() function is actually a call to fflush(stdout) Xto flush the output buffer. XThus, the tiny curses refresh() may be used Xto guarantee that some text is on the screen, Xbut it might go out sooner. X.PP XTiny curses assumes you want to catch interrupts, Xso initscr() sets things up so that an interrupt Xwill reset the tty, move to the bottom of the screen, Xand exit. SHAR_EOF if test 2597 -ne "`wc -c < 'tc.3'`" then echo shar: "error transmitting 'tc.3'" '(should have been 2597 characters)' fi fi echo shar: "extracting 'sample.demo'" '(240 characters)' if test -f 'sample.demo' then echo shar: "will not over-write existing file 'sample.demo'" else sed 's/^ X//' << \SHAR_EOF > 'sample.demo' X#! /bin/sh Xfor distribution in dist.skew dist.uni dist.tri dist.antitri Xdo X for size in 0 1 4 25 X do X /bin/echo -n "Type RETURN to see samples of size $size from $distribution: " X read junk X sample $* -n $size < $distribution X done Xdone SHAR_EOF if test 240 -ne "`wc -c < 'sample.demo'`" then echo shar: "error transmitting 'sample.demo'" '(should have been 240 characters)' fi chmod +x 'sample.demo' fi echo shar: "extracting 'dist.tri'" '(255 characters)' if test -f 'dist.tri' then echo shar: "will not over-write existing file 'dist.tri'" else sed 's/^ X//' << \SHAR_EOF > 'dist.tri' X1 X2 2 X3 3 3 X4 4 4 4 X5 5 5 5 5 X6 6 6 6 6 6 X7 7 7 7 7 7 7 X8 8 8 8 8 8 8 8 X9 9 9 9 9 9 9 9 9 X10 10 10 10 10 10 10 10 10 10 X11 11 11 11 11 11 11 11 11 X12 12 12 12 12 12 12 12 X13 13 13 13 13 13 13 X14 14 14 14 14 14 X15 15 15 15 15 X16 16 16 16 X17 17 17 X18 18 X19 SHAR_EOF if test 255 -ne "`wc -c < 'dist.tri'`" then echo shar: "error transmitting 'dist.tri'" '(should have been 255 characters)' fi fi echo shar: "extracting 'dist.antitri'" '(274 characters)' if test -f 'dist.antitri' then echo shar: "will not over-write existing file 'dist.antitri'" else sed 's/^ X//' << \SHAR_EOF > 'dist.antitri' X1 1 1 1 1 1 1 1 1 1 X2 2 2 2 2 2 2 2 2 X3 3 3 3 3 3 3 3 X4 4 4 4 4 4 4 X5 5 5 5 5 5 X6 6 6 6 6 X7 7 7 7 X8 8 8 X9 9 X10 X11 11 X12 12 12 X13 13 13 13 X14 14 14 14 14 X15 15 15 15 15 15 X16 16 16 16 16 16 16 X17 17 17 17 17 17 17 17 X18 18 18 18 18 18 18 18 18 X19 19 19 19 19 19 19 19 19 19 X SHAR_EOF if test 274 -ne "`wc -c < 'dist.antitri'`" then echo shar: "error transmitting 'dist.antitri'" '(should have been 274 characters)' fi fi echo shar: "extracting 'dist.skew'" '(2363 characters)' if test -f 'dist.skew' then echo shar: "will not over-write existing file 'dist.skew'" else sed 's/^ X//' << \SHAR_EOF > 'dist.skew' X X0 X0.693147 X1.09861 X1.38629 X1.60944 X1.79176 X1.94591 X2.07944 X2.19722 X2.30259 X2.3979 X2.48491 X2.56495 X2.63906 X2.70805 X2.77259 X2.83321 X2.89037 X2.94444 X2.99573 X3.04452 X3.09104 X3.13549 X3.17805 X3.21888 X3.2581 X3.29584 X3.3322 X3.3673 X3.4012 X3.43399 X3.46574 X3.49651 X3.52636 X3.55535 X3.58352 X3.61092 X3.63759 X3.66356 X3.68888 X3.71357 X3.73767 X3.7612 X3.78419 X3.80666 X3.82864 X3.85015 X3.8712 X3.89182 X3.91202 X3.93183 X3.95124 X3.97029 X3.98898 X4.00733 X4.02535 X4.04305 X4.06044 X4.07754 X4.09434 X4.11087 X4.12713 X4.14313 X4.15888 X4.17439 X4.18965 X4.20469 X4.21951 X4.23411 X4.2485 X4.26268 X4.27667 X4.29046 X4.30407 X4.31749 X4.33073 X4.34381 X4.35671 X4.36945 X4.38203 X4.39445 X4.40672 X4.41884 X4.43082 X4.44265 X4.45435 X4.46591 X4.47734 X4.48864 X4.49981 X4.51086 X4.52179 X4.5326 X4.54329 X4.55388 X4.56435 X4.57471 X4.58497 X4.59512 X4.60517 X4.61512 X4.62497 X4.63473 X4.64439 X4.65396 X4.66344 X4.67283 X4.68213 X4.69135 X4.70048 X4.70953 X4.7185 X4.72739 X4.7362 X4.74493 X4.75359 X4.76217 X4.77068 X4.77912 X4.78749 X4.79579 X4.80402 X4.81218 X4.82028 X4.82831 X4.83628 X4.84419 X4.85203 X4.85981 X4.86753 X4.8752 X4.8828 X4.89035 X4.89784 X4.90527 X4.91265 X4.91998 X4.92725 X4.93447 X4.94164 X4.94876 X4.95583 X4.96284 X4.96981 X4.97673 X4.98361 X4.99043 X4.99721 X5.00395 X5.01064 X5.01728 X5.02388 X5.03044 X5.03695 X5.04343 X5.04986 X5.05625 X5.0626 X5.0689 X5.07517 X5.0814 X5.0876 X5.09375 X5.09987 X5.10595 X5.11199 X5.11799 X5.12396 X5.1299 X5.1358 X5.14166 X5.14749 X5.15329 X5.15906 X5.16479 X5.17048 X5.17615 X5.18178 X5.18739 X5.19296 X5.1985 X5.20401 X5.20949 X5.21494 X5.22036 X5.22575 X5.23111 X5.23644 X5.24175 X5.24702 X5.25227 X5.2575 X5.26269 X5.26786 X5.273 X5.27811 X5.2832 X5.28827 X5.2933 X5.29832 X5.3033 X5.30827 X5.31321 X5.31812 X5.32301 X5.32788 X5.33272 X5.33754 X5.34233 X5.34711 X5.35186 X5.35659 X5.36129 X5.36598 X5.37064 X5.37528 X5.3799 X5.3845 X5.38907 X5.39363 X5.39816 X5.40268 X5.40717 X5.41165 X5.4161 X5.42053 X5.42495 X5.42935 X5.43372 X5.43808 X5.44242 X5.44674 X5.45104 X5.45532 X5.45959 X5.46383 X5.46806 X5.47227 X5.47646 X5.48064 X5.4848 X5.48894 X5.49306 X5.49717 X5.50126 X5.50533 X5.50939 X5.51343 X5.51745 X5.52146 X5.52545 X5.52943 X5.53339 X5.53733 X5.54126 X5.54518 X5.54908 X5.55296 X5.55683 X5.56068 X5.56452 X5.56834 X5.57215 X5.57595 X5.57973 X5.5835 X5.58725 X5.59099 X5.59471 X5.59842 X5.60212 X5.6058 X5.60947 X5.61313 X5.61677 X5.6204 X5.62402 X5.62762 X5.63121 X5.63479 X5.63835 X5.64191 X5.64545 X5.64897 X5.65249 X5.65599 X5.65948 X5.66296 X5.66643 X5.66988 X5.67332 X5.67675 X5.68017 X5.68358 X5.68698 X5.69036 X5.69373 X5.69709 X5.70044 X5.70378 SHAR_EOF if test 2363 -ne "`wc -c < 'dist.skew'`" then echo shar: "error transmitting 'dist.skew'" '(should have been 2363 characters)' fi fi echo shar: "extracting 'dist.uni'" '(229 characters)' if test -f 'dist.uni' then echo shar: "will not over-write existing file 'dist.uni'" else sed 's/^ X//' << \SHAR_EOF > 'dist.uni' X1 2 3 4 5 6 7 8 9 10 X11 12 13 14 15 16 17 18 19 20 X21 22 23 24 25 26 27 28 29 30 X31 32 33 34 35 36 37 38 39 40 X41 42 43 44 45 46 47 48 49 50 X51 52 53 54 55 56 57 58 59 60 X61 62 63 64 65 66 67 68 69 70 X71 72 73 74 75 76 77 78 79 SHAR_EOF if test 229 -ne "`wc -c < 'dist.uni'`" then echo shar: "error transmitting 'dist.uni'" '(should have been 229 characters)' fi fi exit 0 # End of shell archive -- Gary Perlman Wang Institute Tyngsboro, MA 01879 (617) 649-9731 UUCP: decvax!wanginst!perlman CSNET: perlman@wanginst