home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume27 / gcom / part07 < prev    next >
Text File  |  1992-01-13  |  9KB  |  347 lines

  1. Newsgroups: comp.sources.misc
  2. From: murf@oakhill.sps.mot.com (Steve Murphy)
  3. Subject:  v27i078:  gcom - GEDCOM genealogical database merge utility, v1, Part07/07
  4. Message-ID: <1992Jan13.145754.25798@sparky.imd.sterling.com>
  5. X-Md4-Signature: ce102a26752b877d5a4dc4bfb179477b
  6. Date: Mon, 13 Jan 1992 14:57:54 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: murf@oakhill.sps.mot.com (Steve Murphy)
  10. Posting-number: Volume 27, Issue 78
  11. Archive-name: gcom/part07
  12. Environment: SunOS
  13.  
  14. ---- Cut Here and unpack ----
  15. #!/bin/sh
  16. # This is part 07 of gcom
  17. if touch 2>&1 | fgrep 'amc' > /dev/null
  18.  then TOUCH=touch
  19.  else TOUCH=true
  20. fi
  21. # ============= gedcom.b.tab.h ==============
  22. echo "x - extracting gedcom.b.tab.h (Text)"
  23. sed 's/^X//' << 'SHAR_EOF' > gedcom.b.tab.h &&
  24. Xtypedef union
  25. X{     int num;
  26. X    char *str;
  27. X    struct datplace *datplace;
  28. X    struct ordinance *ordinance;
  29. X    struct notelist *notelist;
  30. X    struct individ *individ;
  31. X    struct family *family;
  32. X    struct gheader *header;
  33. X    struct submitt *submit;
  34. X    struct child *child;
  35. X    struct submitt *submitt;
  36. X    struct comment *comment;
  37. X    struct stake *stake;
  38. X    struct address *address;
  39. X} YYSTYPE;
  40. X#define    DIV    258
  41. X#define    LEV0    259
  42. X#define    LEV1    260
  43. X#define    LEV2    261
  44. X#define    LEV3    262
  45. X#define    ADDR    263
  46. X#define    BAPL    264
  47. X#define    CHAR    265
  48. X#define    COMM    266
  49. X#define    CONT    267
  50. X#define    DATE    268
  51. X#define    DEST    269
  52. X#define    ENDL    270
  53. X#define    FILE9    271
  54. X#define    FLAG    272
  55. X#define    NAME    273
  56. X#define    NOTE    274
  57. X#define    PHON    275
  58. X#define    PLAC    276
  59. X#define    QUAL    277
  60. X#define    REL    278
  61. X#define    SEX    279
  62. X#define    SOUR    280
  63. X#define    TEMP    281
  64. X#define    TITL    282
  65. X#define    REF    283
  66. X#define    BIC    284
  67. X#define    NUMB    285
  68. X#define    REFN    286
  69. X#define    SLGC    287
  70. X#define    SLGS    288
  71. X#define    BIRT    289
  72. X#define    BURI    290
  73. X#define    CHIL    291
  74. X#define    CHR    292
  75. X#define    DEAT    293
  76. X#define    FAM    294
  77. X#define    FAMC    295
  78. X#define    FAMS    296
  79. X#define    HEAD    297
  80. X#define    HUSB    298
  81. X#define    INDI    299
  82. X#define    MARR    300
  83. X#define    STAL    301
  84. X#define    TRLR    302
  85. X#define    WIFE    303
  86. X#define    SUBM    304
  87. X
  88. X
  89. Xextern YYSTYPE yylval;
  90. SHAR_EOF
  91. $TOUCH -am 0103115092 gedcom.b.tab.h &&
  92. chmod 0664 gedcom.b.tab.h ||
  93. echo "restore of gedcom.b.tab.h failed"
  94. set `wc -c gedcom.b.tab.h`;Wc_c=$1
  95. if test "$Wc_c" != "1175"; then
  96.     echo original size 1175, current size $Wc_c
  97. fi
  98. # ============= alloca.c ==============
  99. echo "x - extracting alloca.c (Text)"
  100. sed 's/^X//' << 'SHAR_EOF' > alloca.c &&
  101. X/*
  102. X    alloca -- (mostly) portable public-domain implementation -- D A Gwyn
  103. X
  104. X    last edit:    86/05/30    rms
  105. X       include config.h, since on VMS it renames some symbols.
  106. X       Use xmalloc instead of malloc.
  107. X
  108. X    This implementation of the PWB library alloca() function,
  109. X    which is used to allocate space off the run-time stack so
  110. X    that it is automatically reclaimed upon procedure exit, 
  111. X    was inspired by discussions with J. Q. Johnson of Cornell.
  112. X
  113. X    It should work under any C implementation that uses an
  114. X    actual procedure stack (as opposed to a linked list of
  115. X    frames).  There are some preprocessor constants that can
  116. X    be defined when compiling for your specific system, for
  117. X    improved efficiency; however, the defaults should be okay.
  118. X
  119. X    The general concept of this implementation is to keep
  120. X    track of all alloca()-allocated blocks, and reclaim any
  121. X    that are found to be deeper in the stack than the current
  122. X    invocation.  This heuristic does not reclaim storage as
  123. X    soon as it becomes invalid, but it will do so eventually.
  124. X
  125. X    As a special case, alloca(0) reclaims storage without
  126. X    allocating any.  It is a good idea to use alloca(0) in
  127. X    your main control loop, etc. to force garbage collection.
  128. X*/
  129. X#ifndef lint
  130. Xstatic char    SCCSid[] = "@(#)alloca.c    1.1";    /* for the "what" utility */
  131. X#endif
  132. X#include <stdio.h>
  133. X/* Called if malloc returns zero */
  134. Xmemory_full ()
  135. X{
  136. X  while (1)
  137. X    fprintf (stderr, "Memory is exhausted!\n");
  138. X}
  139. X
  140. X/* like malloc and realloc but check for no memory left */
  141. X
  142. Xlong *
  143. Xxmalloc (size)
  144. X     int size;
  145. X{
  146. X  register long *val;
  147. X  /* Avoid failure if malloc (0) returns 0.  */
  148. X  if (size == 0)
  149. X    size = 1;
  150. X  val = (long *) malloc (size);
  151. X  if (!val) memory_full ();
  152. X  return val;
  153. X}
  154. X
  155. X#ifdef emacs
  156. X#include "config.h"
  157. X#ifdef static
  158. X/* actually, only want this if static is defined as ""
  159. X   -- this is for usg, in which emacs must undefine static
  160. X   in order to make unexec workable
  161. X   */
  162. X#ifndef STACK_DIRECTION
  163. Xyou
  164. Xlose
  165. X-- must know STACK_DIRECTION at compile-time
  166. X#endif /* STACK_DIRECTION undefined */
  167. X#endif static
  168. X#endif emacs
  169. X
  170. X#ifdef X3J11
  171. Xtypedef void    *pointer;        /* generic pointer type */
  172. X#else
  173. Xtypedef char    *pointer;        /* generic pointer type */
  174. X#endif
  175. X
  176. X#define    NULL    0            /* null pointer constant */
  177. X
  178. Xextern void    free();
  179. X
  180. X
  181. X/*
  182. X    Define STACK_DIRECTION if you know the direction of stack
  183. X    growth for your system; otherwise it will be automatically
  184. X    deduced at run-time.
  185. X
  186. X    STACK_DIRECTION > 0 => grows toward higher addresses
  187. X    STACK_DIRECTION < 0 => grows toward lower addresses
  188. X    STACK_DIRECTION = 0 => direction of growth unknown
  189. X*/
  190. X
  191. X#ifndef STACK_DIRECTION
  192. X#define    STACK_DIRECTION    0        /* direction unknown */
  193. X#endif
  194. X
  195. X#if STACK_DIRECTION != 0
  196. X
  197. X#define    STACK_DIR    STACK_DIRECTION    /* known at compile-time */
  198. X
  199. X#else    /* STACK_DIRECTION == 0; need run-time code */
  200. X
  201. Xstatic int    stack_dir;        /* 1 or -1 once known */
  202. X#define    STACK_DIR    stack_dir
  203. X
  204. Xstatic void
  205. Xfind_stack_direction (/* void */)
  206. X{
  207. X  static char    *addr = NULL;    /* address of first
  208. X                   `dummy', once known */
  209. X  auto char    dummy;        /* to get stack address */
  210. X
  211. X  if (addr == NULL)
  212. X    {                /* initial entry */
  213. X      addr = &dummy;
  214. X
  215. X      find_stack_direction ();    /* recurse once */
  216. X    }
  217. X  else                /* second entry */
  218. X    if (&dummy > addr)
  219. X      stack_dir = 1;        /* stack grew upward */
  220. X    else
  221. X      stack_dir = -1;        /* stack grew downward */
  222. X}
  223. X
  224. X#endif    /* STACK_DIRECTION == 0 */
  225. X
  226. X/*
  227. X    An "alloca header" is used to:
  228. X    (a) chain together all alloca()ed blocks;
  229. X    (b) keep track of stack depth.
  230. X
  231. X    It is very important that sizeof(header) agree with malloc()
  232. X    alignment chunk size.  The following default should work okay.
  233. X*/
  234. X
  235. X#ifndef    ALIGN_SIZE
  236. X#define    ALIGN_SIZE    sizeof(double)
  237. X#endif
  238. X
  239. Xtypedef union hdr
  240. X{
  241. X  char    align[ALIGN_SIZE];    /* to force sizeof(header) */
  242. X  struct
  243. X    {
  244. X      union hdr *next;        /* for chaining headers */
  245. X      char *deep;        /* for stack depth measure */
  246. X    } h;
  247. X} header;
  248. X
  249. X/*
  250. X    alloca( size ) returns a pointer to at least `size' bytes of
  251. X    storage which will be automatically reclaimed upon exit from
  252. X    the procedure that called alloca().  Originally, this space
  253. X    was supposed to be taken from the current stack frame of the
  254. X    caller, but that method cannot be made to work for some
  255. X    implementations of C, for example under Gould's UTX/32.
  256. X*/
  257. X
  258. Xstatic header *last_alloca_header = NULL; /* -> last alloca header */
  259. X
  260. Xpointer
  261. Xalloca (size)            /* returns pointer to storage */
  262. X     unsigned    size;        /* # bytes to allocate */
  263. X{
  264. X  auto char    probe;        /* probes stack depth: */
  265. X  register char    *depth = &probe;
  266. X
  267. X#if STACK_DIRECTION == 0
  268. X  if (STACK_DIR == 0)        /* unknown growth direction */
  269. X    find_stack_direction ();
  270. X#endif
  271. X
  272. X                /* Reclaim garbage, defined as all alloca()ed storage that
  273. X                   was allocated from deeper in the stack than currently. */
  274. X
  275. X  {
  276. X    register header    *hp;    /* traverses linked list */
  277. X
  278. X    for (hp = last_alloca_header; hp != NULL;)
  279. X      if (STACK_DIR > 0 && hp->h.deep > depth
  280. X      || STACK_DIR < 0 && hp->h.deep < depth)
  281. X    {
  282. X      register header    *np = hp->h.next;
  283. X
  284. X      free ((pointer) hp);    /* collect garbage */
  285. X
  286. X      hp = np;        /* -> next header */
  287. X    }
  288. X      else
  289. X    break;            /* rest are not deeper */
  290. X
  291. X    last_alloca_header = hp;    /* -> last valid storage */
  292. X  }
  293. X
  294. X  if (size == 0)
  295. X    return NULL;        /* no allocation required */
  296. X
  297. X  /* Allocate combined header + user data storage. */
  298. X
  299. X  {
  300. X    register pointer    new = xmalloc (sizeof (header) + size);
  301. X    /* address of header */
  302. X
  303. X    ((header *)new)->h.next = last_alloca_header;
  304. X    ((header *)new)->h.deep = depth;
  305. X
  306. X    last_alloca_header = (header *)new;
  307. X
  308. X    /* User storage begins just after header. */
  309. X
  310. X    return (pointer)((char *)new + sizeof(header));
  311. X  }
  312. X}
  313. X
  314. Xvoid bcopy(from,to,i)
  315. Xchar *from;
  316. Xchar *to;
  317. Xint i;
  318. X{
  319. X    if( from == to )
  320. X        return;
  321. X    if( from > to )
  322. X    {
  323. X        int x;
  324. X        for(x =0; x < i; x++)
  325. X            *to++ = *from++;
  326. X    }
  327. X    else
  328. X    {
  329. X        int x;
  330. X        from += i-1;
  331. X        to +=i-1;
  332. X        for(x=0 ; x< i; x++)
  333. X            *to-- = *from--;
  334. X    }
  335. X}
  336. SHAR_EOF
  337. $TOUCH -am 0103111092 alloca.c &&
  338. chmod 0664 alloca.c ||
  339. echo "restore of alloca.c failed"
  340. set `wc -c alloca.c`;Wc_c=$1
  341. if test "$Wc_c" != "5850"; then
  342.     echo original size 5850, current size $Wc_c
  343. fi
  344. exit 0
  345.  
  346. exit 0 # Just in case...
  347.