home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
misc
/
volume27
/
gcom
/
part07
< prev
next >
Wrap
Text File
|
1992-01-13
|
9KB
|
347 lines
Newsgroups: comp.sources.misc
From: murf@oakhill.sps.mot.com (Steve Murphy)
Subject: v27i078: gcom - GEDCOM genealogical database merge utility, v1, Part07/07
Message-ID: <1992Jan13.145754.25798@sparky.imd.sterling.com>
X-Md4-Signature: ce102a26752b877d5a4dc4bfb179477b
Date: Mon, 13 Jan 1992 14:57:54 GMT
Approved: kent@sparky.imd.sterling.com
Submitted-by: murf@oakhill.sps.mot.com (Steve Murphy)
Posting-number: Volume 27, Issue 78
Archive-name: gcom/part07
Environment: SunOS
---- Cut Here and unpack ----
#!/bin/sh
# This is part 07 of gcom
if touch 2>&1 | fgrep 'amc' > /dev/null
then TOUCH=touch
else TOUCH=true
fi
# ============= gedcom.b.tab.h ==============
echo "x - extracting gedcom.b.tab.h (Text)"
sed 's/^X//' << 'SHAR_EOF' > gedcom.b.tab.h &&
Xtypedef union
X{ int num;
X char *str;
X struct datplace *datplace;
X struct ordinance *ordinance;
X struct notelist *notelist;
X struct individ *individ;
X struct family *family;
X struct gheader *header;
X struct submitt *submit;
X struct child *child;
X struct submitt *submitt;
X struct comment *comment;
X struct stake *stake;
X struct address *address;
X} YYSTYPE;
X#define DIV 258
X#define LEV0 259
X#define LEV1 260
X#define LEV2 261
X#define LEV3 262
X#define ADDR 263
X#define BAPL 264
X#define CHAR 265
X#define COMM 266
X#define CONT 267
X#define DATE 268
X#define DEST 269
X#define ENDL 270
X#define FILE9 271
X#define FLAG 272
X#define NAME 273
X#define NOTE 274
X#define PHON 275
X#define PLAC 276
X#define QUAL 277
X#define REL 278
X#define SEX 279
X#define SOUR 280
X#define TEMP 281
X#define TITL 282
X#define REF 283
X#define BIC 284
X#define NUMB 285
X#define REFN 286
X#define SLGC 287
X#define SLGS 288
X#define BIRT 289
X#define BURI 290
X#define CHIL 291
X#define CHR 292
X#define DEAT 293
X#define FAM 294
X#define FAMC 295
X#define FAMS 296
X#define HEAD 297
X#define HUSB 298
X#define INDI 299
X#define MARR 300
X#define STAL 301
X#define TRLR 302
X#define WIFE 303
X#define SUBM 304
X
X
Xextern YYSTYPE yylval;
SHAR_EOF
$TOUCH -am 0103115092 gedcom.b.tab.h &&
chmod 0664 gedcom.b.tab.h ||
echo "restore of gedcom.b.tab.h failed"
set `wc -c gedcom.b.tab.h`;Wc_c=$1
if test "$Wc_c" != "1175"; then
echo original size 1175, current size $Wc_c
fi
# ============= alloca.c ==============
echo "x - extracting alloca.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > alloca.c &&
X/*
X alloca -- (mostly) portable public-domain implementation -- D A Gwyn
X
X last edit: 86/05/30 rms
X include config.h, since on VMS it renames some symbols.
X Use xmalloc instead of malloc.
X
X This implementation of the PWB library alloca() function,
X which is used to allocate space off the run-time stack so
X that it is automatically reclaimed upon procedure exit,
X was inspired by discussions with J. Q. Johnson of Cornell.
X
X It should work under any C implementation that uses an
X actual procedure stack (as opposed to a linked list of
X frames). There are some preprocessor constants that can
X be defined when compiling for your specific system, for
X improved efficiency; however, the defaults should be okay.
X
X The general concept of this implementation is to keep
X track of all alloca()-allocated blocks, and reclaim any
X that are found to be deeper in the stack than the current
X invocation. This heuristic does not reclaim storage as
X soon as it becomes invalid, but it will do so eventually.
X
X As a special case, alloca(0) reclaims storage without
X allocating any. It is a good idea to use alloca(0) in
X your main control loop, etc. to force garbage collection.
X*/
X#ifndef lint
Xstatic char SCCSid[] = "@(#)alloca.c 1.1"; /* for the "what" utility */
X#endif
X#include <stdio.h>
X/* Called if malloc returns zero */
Xmemory_full ()
X{
X while (1)
X fprintf (stderr, "Memory is exhausted!\n");
X}
X
X/* like malloc and realloc but check for no memory left */
X
Xlong *
Xxmalloc (size)
X int size;
X{
X register long *val;
X /* Avoid failure if malloc (0) returns 0. */
X if (size == 0)
X size = 1;
X val = (long *) malloc (size);
X if (!val) memory_full ();
X return val;
X}
X
X#ifdef emacs
X#include "config.h"
X#ifdef static
X/* actually, only want this if static is defined as ""
X -- this is for usg, in which emacs must undefine static
X in order to make unexec workable
X */
X#ifndef STACK_DIRECTION
Xyou
Xlose
X-- must know STACK_DIRECTION at compile-time
X#endif /* STACK_DIRECTION undefined */
X#endif static
X#endif emacs
X
X#ifdef X3J11
Xtypedef void *pointer; /* generic pointer type */
X#else
Xtypedef char *pointer; /* generic pointer type */
X#endif
X
X#define NULL 0 /* null pointer constant */
X
Xextern void free();
X
X
X/*
X Define STACK_DIRECTION if you know the direction of stack
X growth for your system; otherwise it will be automatically
X deduced at run-time.
X
X STACK_DIRECTION > 0 => grows toward higher addresses
X STACK_DIRECTION < 0 => grows toward lower addresses
X STACK_DIRECTION = 0 => direction of growth unknown
X*/
X
X#ifndef STACK_DIRECTION
X#define STACK_DIRECTION 0 /* direction unknown */
X#endif
X
X#if STACK_DIRECTION != 0
X
X#define STACK_DIR STACK_DIRECTION /* known at compile-time */
X
X#else /* STACK_DIRECTION == 0; need run-time code */
X
Xstatic int stack_dir; /* 1 or -1 once known */
X#define STACK_DIR stack_dir
X
Xstatic void
Xfind_stack_direction (/* void */)
X{
X static char *addr = NULL; /* address of first
X `dummy', once known */
X auto char dummy; /* to get stack address */
X
X if (addr == NULL)
X { /* initial entry */
X addr = &dummy;
X
X find_stack_direction (); /* recurse once */
X }
X else /* second entry */
X if (&dummy > addr)
X stack_dir = 1; /* stack grew upward */
X else
X stack_dir = -1; /* stack grew downward */
X}
X
X#endif /* STACK_DIRECTION == 0 */
X
X/*
X An "alloca header" is used to:
X (a) chain together all alloca()ed blocks;
X (b) keep track of stack depth.
X
X It is very important that sizeof(header) agree with malloc()
X alignment chunk size. The following default should work okay.
X*/
X
X#ifndef ALIGN_SIZE
X#define ALIGN_SIZE sizeof(double)
X#endif
X
Xtypedef union hdr
X{
X char align[ALIGN_SIZE]; /* to force sizeof(header) */
X struct
X {
X union hdr *next; /* for chaining headers */
X char *deep; /* for stack depth measure */
X } h;
X} header;
X
X/*
X alloca( size ) returns a pointer to at least `size' bytes of
X storage which will be automatically reclaimed upon exit from
X the procedure that called alloca(). Originally, this space
X was supposed to be taken from the current stack frame of the
X caller, but that method cannot be made to work for some
X implementations of C, for example under Gould's UTX/32.
X*/
X
Xstatic header *last_alloca_header = NULL; /* -> last alloca header */
X
Xpointer
Xalloca (size) /* returns pointer to storage */
X unsigned size; /* # bytes to allocate */
X{
X auto char probe; /* probes stack depth: */
X register char *depth = &probe;
X
X#if STACK_DIRECTION == 0
X if (STACK_DIR == 0) /* unknown growth direction */
X find_stack_direction ();
X#endif
X
X /* Reclaim garbage, defined as all alloca()ed storage that
X was allocated from deeper in the stack than currently. */
X
X {
X register header *hp; /* traverses linked list */
X
X for (hp = last_alloca_header; hp != NULL;)
X if (STACK_DIR > 0 && hp->h.deep > depth
X || STACK_DIR < 0 && hp->h.deep < depth)
X {
X register header *np = hp->h.next;
X
X free ((pointer) hp); /* collect garbage */
X
X hp = np; /* -> next header */
X }
X else
X break; /* rest are not deeper */
X
X last_alloca_header = hp; /* -> last valid storage */
X }
X
X if (size == 0)
X return NULL; /* no allocation required */
X
X /* Allocate combined header + user data storage. */
X
X {
X register pointer new = xmalloc (sizeof (header) + size);
X /* address of header */
X
X ((header *)new)->h.next = last_alloca_header;
X ((header *)new)->h.deep = depth;
X
X last_alloca_header = (header *)new;
X
X /* User storage begins just after header. */
X
X return (pointer)((char *)new + sizeof(header));
X }
X}
X
Xvoid bcopy(from,to,i)
Xchar *from;
Xchar *to;
Xint i;
X{
X if( from == to )
X return;
X if( from > to )
X {
X int x;
X for(x =0; x < i; x++)
X *to++ = *from++;
X }
X else
X {
X int x;
X from += i-1;
X to +=i-1;
X for(x=0 ; x< i; x++)
X *to-- = *from--;
X }
X}
SHAR_EOF
$TOUCH -am 0103111092 alloca.c &&
chmod 0664 alloca.c ||
echo "restore of alloca.c failed"
set `wc -c alloca.c`;Wc_c=$1
if test "$Wc_c" != "5850"; then
echo original size 5850, current size $Wc_c
fi
exit 0
exit 0 # Just in case...