Geneal (part 1 of 3) (debugged version)

Terry L. Ridder tlr at umcp-cs.UUCP
Sat Sep 14 09:06:08 AEST 1985


#! /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:
#	pagemap.c
#	pagemap.h
#	pgmr.doc
#	pgmr.man
#	strsav.c
#	tprintf.c
#	vsprintf.c
#	xalloc.c
# This archive created: Thu Sep 12 22:18:35 1985
# By:	Terry L. Ridder (The Terry L. Ridder family)
export PATH; PATH=/bin:$PATH
echo shar: extracting "'pagemap.c'" '(1887 characters)'
if test -f 'pagemap.c'
then
	echo shar: will not over-write existing file "'pagemap.c'"
else
sed 's/^	X//' << \SHAR_EOF > 'pagemap.c'
	X/* pagemap - functions to manipulate a page of character data */
	X/* Written by Jim McBeath (jimmc) at SCI */
	X/* last edit 15-Sep-84 22:24:02 by jimmc (Jim McBeath) */
	X/* last edit 31-Aug-85 13:00:00 by tlr (Terry L. Ridder) */
	X
	X#include "pagemap.h"
	X#include <stdio.h>
	X
	XPagemp
	XpageInit(r, c)		/* make a new page of data */
	Xint r, c;		/* rows an columns desired in the page */
	X{
	XPagemp pp;
	Xint i, j;
	Xchar *ss;
	X
	X    pp = XALLOC(Pagem, 1, "pageInit");	/* get the top level structure */
	X    pp->rows = r;
	X    pp->cols = c;		/* put in his numbers */
	X    pp->data = XALLOC(char *, r, "pageInit rowpointers");
	X    for (i = 0; i < r; i++)
	X    {
	X	pp->data[i] = ss = XALLOC(char, c+2, "pageInit data");
	X	for (j = 0; j <= c; j++)
	X	{
	X	    ss[j]=' ';	/* fill with spaces */
	X	}
	X	ss[c+1] = 0;		/* null terminated */
	X    }
	X    return pp;			/* return the pointer to him */
	X}
	X
	X/*..........*/
	X
	XpagePuts(pp, r, c, ss)
	XPagemp pp;
	Xint r,c;
	Xchar *ss;
	X{
	Xchar *dd;
	Xint n;
	X
	X    dd = &pp->data[r][c];		/* where to put it */
	X    n = strlen(ss);			/* number of chars to move */
	X    if (pp->cols - c < n)
	X    {
	X	 n = pp->cols - c;	/* don't run off page */
	X    }
	X    for ( ; n > 0; n--)
	X    {
	X	 *(dd++) = *(ss++);	/* transfer string */
	X    }
	X}
	X
	X/*..........*/
	X
	XpagePrint(pp, f)		/* output the page */
	XPagemp pp;		/* pointer to the page to output */
	XFILE *f;		/* stream to output to */
	X{
	Xint r, c;
	Xint lastline;
	Xchar *ss;
	X
	X    lastline = -1;
	X    for (r = 0; r < pp->rows; r++)	/* for each row */
	X    {
	X	ss = pp->data[r];		/* faster access */
	X	for (c = pp->cols + 1; c >= 0; c--)
	X	{
	X	    if (ss[c] > ' ')
	X	    {
	X		 break;	/* strip trailing spaces and nulls */
	X	    }
	X	}
	X	ss[++c] = 0;			/* make it null terminated */
	X	if (c > 0)
	X	{
	X	    lastline = r;		/* remember where the last line is */
	X	}
	X    }
	X    for (r = 0; r <= lastline; r++)		/* now output the lines */
	X    {
	X	fprintf(f, "%s\n", pp->data[r]);
	X    }
	X}
	X
	X/* end */
SHAR_EOF
if test 1887 -ne "`wc -c < 'pagemap.c'`"
then
	echo shar: error transmitting "'pagemap.c'" '(should have been 1887 characters)'
fi
chmod +x 'pagemap.c'
fi # end of overwriting check
echo shar: extracting "'pagemap.h'" '(985 characters)'
if test -f 'pagemap.h'
then
	echo shar: will not over-write existing file "'pagemap.h'"
else
sed 's/^	X//' << \SHAR_EOF > 'pagemap.h'
	X/* pagemap.h - definition for the pagemap functions */
	X/* last edit 15-Sep-84 21:52:47 by jimmc (Jim McBeath) */
	X/* last edit 09-Sept-85 22:54:00 by tlr (Terry L. Ridder) */
	X
	Xextern char *xalloc();
	X
	X#define XALLOC(item, count, msg) (item *)xalloc(sizeof(item)*count,msg)
	X
	Xstruct pagem {
	X    int rows;		/* number of rows (lines) on the page */
	X    int cols;		/* number of columns on the page */
	X    char **data;	/* pointer to an array of char pointers */
	X    };
	X
	Xtypedef struct pagem Pagem, *Pagemp;
	X
	X/* data is stored in row major order; given the data pointer from the
	X * above structure, data[x] points to row x, and data[x][y] points to
	X * character y in row x.
	X *
	X * The number of columns is actually greater by two than the number
	X * x->cols indicates; this is to leave space for a newline and a null
	X * at the end.
	X */
	X
	X/* access macros */
	X#define pagePutc(pp,r,c,ch) ((pp)->data[r][c] = (ch))
	X#define pageGetc(pp,r,c)    ((pp)->data[r][c])
	X
	Xextern Pagemp pageInit();
	X
	X/* end */
SHAR_EOF
if test 985 -ne "`wc -c < 'pagemap.h'`"
then
	echo shar: error transmitting "'pagemap.h'" '(should have been 985 characters)'
fi
chmod +x 'pagemap.h'
fi # end of overwriting check
echo shar: extracting "'pgmr.doc'" '(7963 characters)'
if test -f 'pgmr.doc'
then
	echo shar: will not over-write existing file "'pgmr.doc'"
else
sed 's/^	X//' << \SHAR_EOF > 'pgmr.doc'
	X.DA Aug 29, 1985
	X.RP
	X.TL
	XProgrammer Documentation for geneal
	X.AU
	XJim McBeath (jimmc) at SCI
	XTerry L. Ridder 
	X.AI
	XSilcon Compilers Inc.
	XThe Terry L. Ridder Family
	X.AB
	XThis document describes some of the files used in geneal.  It is
	Xintended to assist someone who may want to fix a bug or improve the
	Xprogram, or perhaps use one of the general modules for another program.
	XIf you do any of the above, we would be interested in hearing about it.
	X.AE
	X.NH
	XBACKGROUND
	X.LP
	XThe geneal program is divided up into a number of general purpose files
	Xand some special files specifically for the geneal program.
	X.DS
	XThe general files include:
	X    dataman.c	Simple reader for formatted data file.
	X    errorman.c	Error message routines.
	X    index.c	Routines to manipulate large virtual 
	X		arrays.
	X    pagemap.c	Build up an image of a page in memory 
	X		and output it.
	X    strsav.c	Save a malloc'ed copy of a string.
	X    tprintf.c	sprintf into a malloc'ed string.
	X    vsprintf.c	sprintf with a vector of arguments.
	X    xalloc.c	allocate memory and die if no more.
	X.DE
	X.DS
	XThe geneal-specific files include:
	X    geneal.c	main program for geneal (switches etc).
	X    famgetdat.c	routines to generate one-line strings 
	X		of data.
	X    family.c	generate a page of info about a family.
	X    famtree.c	generate a family tree (incomplete!).
	X    gbrowse.c	browse through the data.
	X    indivs.c	generate info about an individual.
	X.DE
	X
	X.NH
	XGeneral files
	X.LP
	XMost of the general files are simple, and can be easily understood by
	Xinspection.  The ones which deserve more extensive comment are dataman,
	Xindex, and pagemap.
	X
	X.NH 2 
	XDataman
	X.R
	Xis the interface to the datafile.  The datafile is in a particular
	Xformat (records, lines, keywords/values) which is decsribed at the beginning
	Xof that file.  The routines in this module allow access to those data items,
	Xtypically given a record number and a keyword name. There were two primary
	Xconsiderations behind selecting the format used in the data file and the
	Xtechniques used to read that file: 
	X.IP 1) 
	X.RS
	XIt should be in a text format so that it can be edited by a text editor (I
	Xdidn't want to have to write a special datafile editor) and so that it is
	Xhuman readable (so it could be used even before all the output routines
	Xwere written for any particular program); 
	X.RE
	X.IP 2) 
	X.RS
	XThe program should be able to
	Xhandle extremely large files.
	X.RE
	X.LP
	XThe current implementation of DATAMAN works as follows: during initialization,
	Xit scans through the data file looking for the start of each record.  It
	Xthen reads in the record number (an arbitrary but unique integer) and records
	X(using the INDEX module) the seek location in the file for that record.
	XWhen an access request is processed, it seeks to the location for that record
	Xand then scans until it finds the requested keyword.  While this may not
	Xbe particularly fast, it does satisfy the above two requirements of simple
	Xtext file format and the ability to handle extremely large files.  It is
	Xtrue that the initialization phase would take much longer for a very large
	Xfile, but the access time for any given item should be independent of
	Xfile size.
	X.LP
	XThere are of course some optimizations and improvements which could be
	Xmade here.  The first two on my list are: 
	X.IP 1) 
	X.RS
	XAfter scanning through the
	Xdata file creating the list of indexes and seek positions, write that
	Xinformation out to a file - then the next time the program is run with
	Xthat same file, the dates can be checked, and the index file can be
	Xread in if it is still newer (i.e. the data file has not changed). This
	Xwould greatly improve the initialization time for larger data files.
	X.RE
	X.IP 2) 
	X.RS
	XCache the most recent records in memory (and perhaps sort the fields
	Xin them).  In those cases where a program goes back and forth between a
	Xfew records (as often happens in the genealogy program when following
	Xchild pointers, parent pointers, etc.), this would help to speed up
	Xthe accessing.  However, remember that unix alreadys caches some disk
	Xio, so this may not be as big a win as it seems at first.  (Try running
	Xthe geneal program - actually it's not all that slow, considering the
	Xway it reads the data file!)
	X.RE
	X
	X.NH 2 
	XIndex
	X.R
	Ximplements a large dynamic virtual array.  Each location in the
	Xarray is allowed to contain an integer (or a pointer, if you have more
	Xdata to store).  The routines allow you to set or get that value
	X(integer or pointer) for a specified index (conceptually the index
	Xinto a large table).  Internally, the data are stored in a number of
	Xsmaller tables, so that unused locations in the array need not take
	Xup memory space.  For example, if you needed an array with indexes of
	X1 and 1000000, the amount of storage needed would be something like
	X1K (due to chunk size).  The approach used works well for arrays with
	Xclusters of dense use, e.g. the number 1 to 1000, 1M to 1M+1000, 10M to
	X10M+1000, etc.  It does not work well for sparse but regular distributions,
	Xe.g. 1K, 2K, 3K, etc.
	X
	XThe index table is implemented by a multi-level table.  The bottom level
	Xtable contains N data items; the next level up contains N pointers to
	Xbottom level tables; the next level up contains N pointers to first
	Xlevel pointer tables, etc. as far as needed.  The number N can be selected
	Xin the initialization call for an array.  When the set routine is called,
	Xenough tables are built to access the requested index.  When the get
	Xroutine is called, those tables are then followed to get to the data.
	XThus the size of the table can grow as needed.
	X
	X.NH 2 
	XPagemap
	X.R
	Xis an embryonic module used to generate a page of character
	Xdata when it is desired to place things at particular locations on
	Xthe page.  The caller first initializes a page (giving the size), and
	Xthen calls routines to output strings and characters to particular
	Xlocations (row/column) on the page.  At the end, he calls a function
	Xto output the page.  This function was written in order to do the
	Xfamily tree part of geneal, but so far has not seen that use.
	X
	X
	X.NH 
	XGeneal specific files
	X.LP
	XThe geneal program has a number of non-general files intended only
	Xfor use in this program.  These were mentioned above and will be
	Xdiscussed in a little more detail here.
	X
	X.NH 2 
	XGeneal
	X.R
	Xis the main program.  It scans the command line for arguments
	Xand switches, calls any initialization functions, and dispatches to
	Xthe appropriate function for processing.
	X
	X.NH 2 
	XFamgetdat
	X.R
	Xis the basic interface to dataman.  It is used to read certain
	Xitems of data for a particular person and return a string.  For example,
	Xone of the functions reads the birth date and place, formats them into
	Xa string ("b: 12-Oct-1855, Arlington, VA") and returns a pointer to that
	Xstring.  This type of routine is used to build up a list of information
	Xabout someone, to be output in some particular format.
	X
	X.NH 2 
	XFamily
	X.R
	Xis a function to output information about a family in a particular
	Xformat.  This function is invoked by a switch on the command line.
	XThe family page consists of information about the parents, their children,
	Xand the children's spouses.  This function calls famgetdat a lot to collect
	Xits information, then formats it and outputs it.  Mostly pretty
	Xstraightforward code.
	X
	X.NH 2 
	XFamtree
	X.R
	Xis the routine which eventually will draw family trees.  At the
	Xmoment there is not very much there to that end.  It outputs the information
	Xfor one family in the format in which it will appear in the tree.  It
	Xuses pagemap to build up this picture, so you can take a look at it if
	Xyou want to see an example of its use.
	X
	X.NH 2 
	XGbrowse
	X.R
	Xis the module which controls browsing through the data.  This is
	Xa very simple control module at the moment, but should eventually grow to
	Xhave a much more sophisticated interface to allow searching of the data.
	X
	X.NH 2 
	XIndivs
	X.R
	Xcreates a short form data page for an individual.
	X
	XHave fun and send me your improvements!
	X
	X			-Jim McBeath
	X			 15-Jan-1985
	X			-Terry L. Ridder
	X			 29-Aug-1985
SHAR_EOF
if test 7963 -ne "`wc -c < 'pgmr.doc'`"
then
	echo shar: error transmitting "'pgmr.doc'" '(should have been 7963 characters)'
fi
chmod +x 'pgmr.doc'
fi # end of overwriting check
echo shar: extracting "'pgmr.man'" '(9652 characters)'
if test -f 'pgmr.man'
then
	echo shar: will not over-write existing file "'pgmr.man'"
else
sed 's/^	X//' << \SHAR_EOF > 'pgmr.man'
	X
	X
	X
	X
	X
	X
	X
	X
	X
	X            Programmer Documentation for geneal
	X
	X
	X                 Jim McBeath (jimmc) at SCI
	X                      Terry L. Ridder
	X
	X                   Silcon Compilers Inc.
	X                 The Terry L. Ridder Family
	X
	X
	X
	X                          _A_B_S_T_R_A_C_T
	X
	X          This document describes  some  of  the  files
	X     used  in geneal.  It is intended to assist someone
	X     who may want to fix a bug or improve the  program,
	X     or  perhaps  use  one  of  the general modules for
	X     another program.  If you do any of the  above,  we
	X     would be interested in hearing about it.
	X
	X
	X
	XAug 29, 1985
	X
	X
	X
	X
	X
	X
	X
	X
	X
	X
	X
	X
	X
	X
	X
	X
	X
	X
	X
	X
	X
	X
	X
	X
	X
	X
	X
	X
	X
	X
	X
	X
	X
	X
	X
	X
	X
	X
	X
	X
	X
	X
	X
	X            Programmer Documentation for geneal
	X
	X
	X                 Jim McBeath (jimmc) at SCI
	X                      Terry L. Ridder
	X
	X                   Silcon Compilers Inc.
	X                 The Terry L. Ridder Family
	X
	X
	X
	X_1.  _B_A_C_K_G_R_O_U_N_D
	X
	XThe geneal program is divided up into a  number  of  general
	Xpurpose  files  and  some special files specifically for the
	Xgeneal program.
	X
	X        The general files include:
	X            dataman.c   Simple reader for formatted data file.
	X            errorman.c  Error message routines.
	X            index.c     Routines to manipulate large virtual
	X                        arrays.
	X            pagemap.c   Build up an image of a page in memory
	X                        and output it.
	X            strsav.c    Save a malloc'ed copy of a string.
	X            tprintf.c   sprintf into a malloc'ed string.
	X            vsprintf.c  sprintf with a vector of arguments.
	X            xalloc.c    allocate memory and die if no more.
	X
	X
	X        The geneal-specific files include:
	X            geneal.c    main program for geneal (switches etc).
	X            famgetdat.c routines to generate one-line strings
	X                        of data.
	X            family.c    generate a page of info about a family.
	X            famtree.c   generate a family tree (incomplete!).
	X            gbrowse.c   browse through the data.
	X            indivs.c    generate info about an individual.
	X
	X
	X
	X_2.  _G_e_n_e_r_a_l _f_i_l_e_s
	X
	XMost of the general files are  simple,  and  can  be  easily
	Xunderstood  by  inspection.   The  ones  which  deserve more
	Xextensive comment are dataman, index, and pagemap.
	X
	X
	X
	X
	X
	X
	X
	X
	X                       Aug 29, 1985
	X
	X
	X
	X
	X
	X                           - 2 -
	X
	X
	X_2._1.   _D_a_t_a_m_a_n  is  the  interface  to  the  datafile.   The
	Xdatafile   is   in  a  particular  format  (records,  lines,
	Xkeywords/values) which is decsribed at the beginning of that
	Xfile.   The  routines  in  this module allow access to those
	Xdata items, typically given a record number  and  a  keyword
	Xname. There were two primary considerations behind selecting
	Xthe format used in the data file and the techniques used  to
	Xread that file:
	X
	X1)
	X          It should be in a text format so that  it  can  be
	X          edited  by a text editor (I didn't want to have to
	X          write a special datafile editor) and so that it is
	X          human  readable  (so  it could be used even before
	X          all the output routines were written for any  par-
	X          ticular program);
	X
	X2)
	X          The program should be  able  to  handle  extremely
	X          large files.
	X
	XThe current implementation of DATAMAN works as follows: dur-
	Xing  initialization,  it scans through the data file looking
	Xfor the start of each record.  It then reads in  the  record
	Xnumber  (an arbitrary but unique integer) and records (using
	Xthe INDEX module) the seek location in  the  file  for  that
	Xrecord.   When  an  access request is processed, it seeks to
	Xthe location for that record and then scans until  it  finds
	Xthe  requested  keyword.  While this may not be particularly
	Xfast, it does satisfy the above two requirements  of  simple
	Xtext  file  format and the ability to handle extremely large
	Xfiles.  It is true that the initialization phase would  take
	Xmuch  longer  for a very large file, but the access time for
	Xany given item should be independent of file size.
	X
	XThere are of  course  some  optimizations  and  improvements
	Xwhich could be made here.  The first two on my list are:
	X
	X1)
	X          After scanning through the data file creating  the
	X          list  of  indexes  and  seek positions, write that
	X          information out to a file - then the next time the
	X          program  is run with that same file, the dates can
	X          be checked, and the index file can be read  in  if
	X          it  is  still  newer  (i.e.  the data file has not
	X          changed). This would greatly improve the initiali-
	X          zation time for larger data files.
	X
	X2)
	X          Cache the  most  recent  records  in  memory  (and
	X          perhaps  sort the fields in them).  In those cases
	X          where a program goes back and forth between a  few
	X          records (as often happens in the genealogy program
	X          when following child  pointers,  parent  pointers,
	X
	X
	X
	X                       Aug 29, 1985
	X
	X
	X
	X
	X
	X                           - 3 -
	X
	X
	X          etc.),  this would help to speed up the accessing.
	X          However, remember that unix alreadys  caches  some
	X          disk  io,  so  this  may not be as big a win as it
	X          seems at first.  (Try running the geneal program -
	X          actually  it's  not all that slow, considering the
	X          way it reads the data file!)
	X
	X
	X_2._2.  _I_n_d_e_x implements a large dynamic virtual array.   Each
	Xlocation in the array is allowed to contain an integer (or a
	Xpointer, if you have more  data  to  store).   The  routines
	Xallow  you to set or get that value (integer or pointer) for
	Xa specified index  (conceptually  the  index  into  a  large
	Xtable).   Internally,  the  data  are  stored in a number of
	Xsmaller tables, so that unused locations in the  array  need
	Xnot  take  up  memory  space.  For example, if you needed an
	Xarray with indexes of 1 and 1000000, the amount  of  storage
	Xneeded  would be something like 1K (due to chunk size).  The
	Xapproach used works well for arrays with clusters  of  dense
	Xuse,  e.g.  the  number  1  to  1000,  1M to 1M+1000, 10M to
	X10M+1000, etc.  It does not work well for sparse but regular
	Xdistributions, e.g. 1K, 2K, 3K, etc.
	X
	XThe index table is implemented by a multi-level table.   The
	Xbottom  level table contains N data items; the next level up
	Xcontains N pointers to bottom level tables; the  next  level
	Xup  contains  N pointers to first level pointer tables, etc.
	Xas far as needed.  The number N can be selected in the  ini-
	Xtialization  call  for  an  array.   When the set routine is
	Xcalled, enough tables are  built  to  access  the  requested
	Xindex.   When  the  get  routine is called, those tables are
	Xthen followed to get to the data.   Thus  the  size  of  the
	Xtable can grow as needed.
	X
	X
	X_2._3.  _P_a_g_e_m_a_p is an embryonic module used to generate a page
	Xof character data when it is desired to place things at par-
	Xticular locations on the page.  The caller first initializes
	Xa  page (giving the size), and then calls routines to output
	Xstrings and characters to particular locations  (row/column)
	Xon  the page.  At the end, he calls a function to output the
	Xpage.  This function was written in order to do  the  family
	Xtree part of geneal, but so far has not seen that use.
	X
	X
	X
	X_3.  _G_e_n_e_a_l _s_p_e_c_i_f_i_c _f_i_l_e_s
	X
	XThe  geneal  program  has  a  number  of  non-general  files
	Xintended only for use in this program.  These were mentioned
	Xabove and will be discussed in a little more detail here.
	X
	X
	X
	X
	X
	X
	X                       Aug 29, 1985
	X
	X
	X
	X
	X
	X                           - 4 -
	X
	X
	X_3._1.  _G_e_n_e_a_l is the main program.  It scans the command line
	Xfor  arguments  and switches, calls any initialization func-
	Xtions, and dispatches to the appropriate function  for  pro-
	Xcessing.
	X
	X
	X_3._2.  _F_a_m_g_e_t_d_a_t is the basic interface to  dataman.   It  is
	Xused  to  read certain items of data for a particular person
	Xand return a string.  For  example,  one  of  the  functions
	Xreads  the  birth date and place, formats them into a string
	X("b: 12-Oct-1855, Arlington, VA") and returns a  pointer  to
	Xthat  string.   This  type  of routine is used to build up a
	Xlist of information about someone, to be output in some par-
	Xticular format.
	X
	X
	X_3._3.  _F_a_m_i_l_y is a function to  output  information  about  a
	Xfamily  in a particular format.  This function is invoked by
	Xa switch on the command line.  The family page  consists  of
	Xinformation  about  the  parents,  their  children,  and the
	Xchildren's spouses.  This function calls famgetdat a lot  to
	Xcollect  its  information,  then  formats it and outputs it.
	XMostly pretty straightforward code.
	X
	X
	X_3._4.  _F_a_m_t_r_e_e is the routine which eventually will draw fam-
	Xily  trees.   At  the moment there is not very much there to
	Xthat end.  It outputs the information for one family in  the
	Xformat in which it will appear in the tree.  It uses pagemap
	Xto build up this picture, so you can take a look  at  it  if
	Xyou want to see an example of its use.
	X
	X
	X_3._5.  _G_b_r_o_w_s_e is the module which controls browsing  through
	Xthe  data.   This  is  a  very  simple control module at the
	Xmoment, but should eventually  grow  to  have  a  much  more
	Xsophisticated interface to allow searching of the data.
	X
	X
	X_3._6.  _I_n_d_i_v_s creates a short form data page for  an  indivi-
	Xdual.
	X
	XHave fun and send me your improvements!
	X
	X               -Jim  McBeath                     15-Jan-1985
	X               -Terry L. Ridder                 29-Aug-1985
	X
	X
	X
	X
	X
	X
	X
	X
	X
	X
	X
	X                       Aug 29, 1985
	X
	X
SHAR_EOF
echo shar: 130 control characters may be missing from "'pgmr.man'"
if test 9652 -ne "`wc -c < 'pgmr.man'`"
then
	echo shar: error transmitting "'pgmr.man'" '(should have been 9652 characters)'
fi
chmod +x 'pgmr.man'
fi # end of overwriting check
echo shar: extracting "'strsav.c'" '(465 characters)'
if test -f 'strsav.c'
then
	echo shar: will not over-write existing file "'strsav.c'"
else
sed 's/^	X//' << \SHAR_EOF > 'strsav.c'
	X/* strsav - make a copy of a string and return a pointer to it */
	X/* Written by Jim McBeath (jimmc) at SCI */
	X/* last edit  6-Jan-85 22:21:20 by jimmc (Jim McBeath) */
	X/* last edit 31-Aug-85 13:00:00 by tlr (Terry L. Ridder) */
	X
	Xextern char *strcpy();
	Xextern char *xalloc();
	X
	Xchar *
	Xstrsav(ss)
	Xchar *ss;
	X{
	Xchar *dd;
	X
	X    dd = xalloc(strlen(ss) + 1, "strsav");
	X    strcpy(dd, ss);		/* make a copy of the string */
	X    return dd;			/* return the copy */
	X}
	X
	X/* end */
SHAR_EOF
if test 465 -ne "`wc -c < 'strsav.c'`"
then
	echo shar: error transmitting "'strsav.c'" '(should have been 465 characters)'
fi
chmod +x 'strsav.c'
fi # end of overwriting check
echo shar: extracting "'tprintf.c'" '(582 characters)'
if test -f 'tprintf.c'
then
	echo shar: will not over-write existing file "'tprintf.c'"
else
sed 's/^	X//' << \SHAR_EOF > 'tprintf.c'
	X/* tprintf - do a sprintf into a temp buffer, then make a copy of the
	X * string and return a pointer to the copy */
	X/* Written by Jim McBeath (jimmc) at SCI */
	X/* last edit 19-Jan-85 08:59:43 by jimmc (Jim McBeath) */
	X/* last edit 11-Sept-85 22:17:00 by tlr (Terry L. Ridder) */
	X
	X#define BUFSIZ 1000
	X
	Xextern char *strsav();
	Xextern char *sprintf();
	X
	X/* VARARGS1 */
	Xchar *
	Xtprintf(fmt, arg1, arg2, arg3)
	Xchar *fmt;
	Xint  arg1, arg2, arg3;
	X{
	Xchar buf[BUFSIZ];
	X
	X    sprintf(buf, fmt, arg1, arg2, arg3);	/* printf the string */
	X    return strsav(buf);				/* return a copy */
	X}
	X
	X/* end */
SHAR_EOF
if test 582 -ne "`wc -c < 'tprintf.c'`"
then
	echo shar: error transmitting "'tprintf.c'" '(should have been 582 characters)'
fi
chmod +x 'tprintf.c'
fi # end of overwriting check
echo shar: extracting "'vsprintf.c'" '(875 characters)'
if test -f 'vsprintf.c'
then
	echo shar: will not over-write existing file "'vsprintf.c'"
else
sed 's/^	X//' << \SHAR_EOF > 'vsprintf.c'
	X/* @(#)sprintf.c	4.1 (Berkeley) 12/21/80 */
	X/* vsprintf from sprintf */
	X/* Created from unix sprintf by Jim McBeath (jimmc) at SCI */
	X/* last edit 19-Jan-85 09:00:15 by jimmc (Jim McBeath) */
	X/* last edit 11-Sept-85 22:00:00 by tlr (Terry L. Ridder) */
	X#include	<stdio.h>
	X
	X/* vsprintf is like sprintf, but instead of passing a list of arguments,
	X * the address of the list is passed.  This is typically used to implement
	X * a function which accepts a format string and list of arguments of
	X * its own.
	X */
	X
	X/* VARARGS2 */
	Xchar *vsprintf(str, fmt, argv)
	Xchar *str, *fmt;
	X{
	X#ifdef USG
	X	FILE _strbuf;
	X
	X	_strbuf._flag = _IOWRT + _IOLBF;
	X	_strbuf._ptr = (unsigned char *)str;
	X#else
	X	struct _iobuf _strbuf;
	X
	X	_strbuf._flag = _IOWRT + _IOSTRG;
	X	_strbuf._ptr = (unsigned char *)str;
	X#endif
	X	_strbuf._cnt = 32767;
	X	_doprnt(fmt, argv, &_strbuf);
	X	putc('\0', &_strbuf);
	X	return(str);
	X}
SHAR_EOF
if test 875 -ne "`wc -c < 'vsprintf.c'`"
then
	echo shar: error transmitting "'vsprintf.c'" '(should have been 875 characters)'
fi
chmod +x 'vsprintf.c'
fi # end of overwriting check
echo shar: extracting "'xalloc.c'" '(705 characters)'
if test -f 'xalloc.c'
then
	echo shar: will not over-write existing file "'xalloc.c'"
else
sed 's/^	X//' << \SHAR_EOF > 'xalloc.c'
	X/* xalloc - allocate memory, give error message and die if no more */
	X/* Written by Jim McBeath (jimmc) at SCI */
	X/* last edit 15-Sep-84 16:50:25 by jimmc (Jim McBeath) */
	X/* last edit 09-Sept-85 21:50:00 by tlr (Terry L. Ridder) */
	X
	X#include <stdio.h>
	X
	X#define ERROR_EXIT 1
	X
	Xstatic int totalused = 0;
	X
	Xchar *
	Xxalloc(size, msg)
	Xint size;		/* number of bytes to allocate */
	Xchar *msg;		/* error string */
	X{
	Xchar *x;
	X
	X    extern char *malloc();
	X	
	X    x = malloc((unsigned)size);
	X    if (x == 0)
	X    {
	X	fprintf(stderr, "\nNo more memory (%s)\n", msg);
	X	fprintf(stderr, "Previously used: %d; this request: %d\n",
	X			totalused, size);
	X	exit(ERROR_EXIT);
	X    }
	X    totalused += size;
	X    return x;
	X}
	X
	X/* end */
SHAR_EOF
if test 705 -ne "`wc -c < 'xalloc.c'`"
then
	echo shar: error transmitting "'xalloc.c'" '(should have been 705 characters)'
fi
chmod +x 'xalloc.c'
fi # end of overwriting check
#	End of shell archive
exit 0
-- 
	
  ===========================================================================
  | 									    |
  |UUCP:         /--- !neurad--\             /---!wiretap!{root, tlr}	    |
  |UUCP: seismo-<               >---!bilbo--<            		    |
  |UUCP:         \--- !umcp-cs-<     	     \---!{root, tlr}		    |
  | 			        \---!tlr				    |
  | 									    |
  |ARPA: tlr at maryland							    |
  | 									    |
  |U.S.SNAIL: Terry L. Ridder, 401 Cherry Lane E301, Laurel, Maryland 20707 |
  |									    |
  |Ma Bell: Home: 301-490-2248 Work: 301-859-6271 Work: 301-859-6642	    |
  |									    |
  ===========================================================================



More information about the Comp.sources.unix mailing list