home *** CD-ROM | disk | FTP | other *** search
- From: zeppelin@login.dknet.dk (Thomas B. Pedersen)
- Newsgroups: comp.sources.misc
- Subject: v44i062: typhoon - Typhoon Relational Database Management System, Part06/09
- Date: 17 Sep 1994 21:45:44 -0500
- Organization: Sterling Software
- Sender: kent@sparky.sterling.com
- Approved: kent@sparky.sterling.com
- Message-ID: <35g9ko$oip@sparky.sterling.com>
- X-Md4-Signature: e908d2704b5a798817dd9a3cf6ae0dec
-
- Submitted-by: zeppelin@login.dknet.dk (Thomas B. Pedersen)
- Posting-number: Volume 44, Issue 62
- Archive-name: typhoon/part06
- Environment: SCO UNIX, Tandem NonStop UNIX, Sun Solaris, AIX, Linux, OS/2
-
- #! /bin/sh
- # This is a shell archive. Remove anything before this line, then feed it
- # into a shell via "sh file" or similar. To overwrite existing files,
- # type "sh file -c".
- # Contents: typhoon/examples/demo.c typhoon/src/btree.h
- # typhoon/src/cmpfuncs.c typhoon/src/h/typhoon.h
- # typhoon/src/ty_repif.h typhoon/src/ty_repl.c typhoon/src/ty_util.c
- # typhoon/src/util/exp.y typhoon/src/util/expspec.c
- # typhoon/src/util/impspec.c
- # Wrapped by kent@sparky on Sat Sep 17 21:38:17 1994
- PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin:$PATH ; export PATH
- echo If this archive is complete, you will see the following message:
- echo ' "shar: End of archive 6 (of 9)."'
- if test -f 'typhoon/examples/demo.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'typhoon/examples/demo.c'\"
- else
- echo shar: Extracting \"'typhoon/examples/demo.c'\" \(5303 characters\)
- sed "s/^X//" >'typhoon/examples/demo.c' <<'END_OF_FILE'
- X/*----------------------------------------------------------------------------
- X * File : demo.c
- X * OS : UNIX
- X * Author : Thomas B. Pedersen
- X *
- X * Copyright (c) 1994 Thomas B. Pedersen. All rights reserved.
- X *
- X * Permission is hereby granted, without written agreement and without
- X * license or royalty fees, to use, copy, modify, and distribute this
- X * software and its documentation for any purpose, provided that the above
- X * copyright notice and the following two paragraphs appear (1) in all
- X * source copies of this software and (2) in accompanying documentation
- X * wherever the programatic interface of this software, or any derivative
- X * of it, is described.
- X *
- X * IN NO EVENT SHALL THOMAS B. PEDERSEN BE LIABLE TO ANY PARTY FOR DIRECT,
- X * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF
- X * THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF HE HAS BEEN
- X * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- X *
- X * THOMAS B. PEDERSEN SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT
- X * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- X * A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS"
- X * BASIS, AND THOMAS B. PEDERSEN HAS NO OBLIGATION TO PROVIDE MAINTENANCE,
- X * SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
- X *
- X * Description:
- X * A small program that demonstrates some of the features of API.
- X *
- X * $Log: demo.c,v $
- X * Revision 1.2 1994/09/17 16:17:46 tbp
- X * typhoon.h is now included from <>.
- X *
- X * Revision 1.1 1994/09/13 21:29:45 tbp
- X * Added to repository.
- X *
- X * Added to repository.
- X *
- X *
- X *--------------------------------------------------------------------------*/
- X
- Xstatic char rcsid[] = "$Id: demo.c,v 1.2 1994/09/17 16:17:46 tbp Exp $";
- X
- X#include <stdio.h>
- X#include <ctype.h>
- X#include <typhoon.h>
- X#include "demo.h"
- X
- Xtypedef enum {
- X SHORT,
- X INT,
- X LONG,
- X STRING
- X} field_type;
- X
- X
- Xmenu(options)
- Xchar *options;
- X{
- X char s[10];
- X
- X printf("%s: ", options);
- X fflush(stdout);
- X gets(s);
- X
- X return tolower(s[0]);
- X}
- X
- X
- Xvoid getfield(name, type, var)
- Xchar *name;
- Xfield_type type;
- Xvoid *var;
- X{
- X char s[2048];
- X
- X printf("%s: ", name);
- X fflush(stdout);
- X gets(s);
- X
- X switch( type )
- X {
- X case SHORT:
- X *(short *)var = atoi(s);
- X break;
- X case INT:
- X *(int *)var = atoi(s);
- X break;
- X case LONG:
- X *(long *)var = atol(s);
- X break;
- X case STRING:
- X strcpy((char *)var, s);
- X break;
- X }
- X}
- X
- X
- Xvoid report(s)
- Xchar *s;
- X{
- X printf("%s - db_status %d\n", s, db_status);
- X}
- X
- X
- Xvoid print_company(company)
- Xstruct company *company;
- X{
- X printf("[id=%lu, name='%s']\n", company->id, company->name);
- X}
- X
- X
- Xvoid print_product(product)
- Xstruct product *product;
- X{
- X printf("[company_id=%lu, name='%s', description='%s']\n",
- X product->company_id,
- X product->name,
- X product->description);
- X}
- X
- X
- Xvoid find_menu()
- X{
- X struct product product;
- X struct company company;
- X int stop = 0;
- X int key = ID;
- X int listall = 0;
- X
- X while( !stop )
- X {
- X switch( menu("First Last Prev Next Delete "
- X "Search list All Back") )
- X {
- X case 'a':
- X d_keyfrst(key);
- X
- X listall = 1;
- X break;
- X case 'f':
- X d_keyfrst(key);
- X break;
- X case 'l':
- X d_keylast(key);
- X break;
- X case 'p':
- X d_keyprev(key);
- X break;
- X case 'n':
- X d_keynext(key);
- X break;
- X case 's':
- X switch( menu("Company Product") )
- X {
- X case 'c':
- X getfield("Id", LONG, &company.id);
- X d_keyfind(ID, &company.id);
- X key = ID;
- X break;
- X case 'p':
- X key = PRODUCT_NAME;
- X getfield("Name", STRING, product.name);
- X d_keyfind(PRODUCT_NAME, product.name);
- X break;
- X default:
- X continue;
- X }
- X break;
- X case 'd':
- X if( db_status == S_OKAY )
- X if( d_delete() == S_OKAY )
- X puts("Deleted.");
- X else
- X report("Could not delete");
- X continue;
- X case 'b':
- X stop++;
- X default:
- X continue;
- X }
- X
- X if( db_status == S_OKAY )
- X {
- X while( listall && db_status == S_OKAY )
- X {
- X switch( key )
- X {
- X case ID:
- X d_recread(&company);
- X print_company(&company);
- X break;
- X case PRODUCT_NAME:
- X d_recread(&product);
- X print_product(&product);
- X break;
- X }
- X
- X if( listall )
- X d_keynext(key);
- X }
- X }
- X else
- X puts("Not found");
- X
- X listall = 0;
- X }
- X}
- X
- X
- X
- Xvoid create_menu()
- X{
- X struct product product;
- X struct company company ;
- X int stop = 0;
- X
- X while( !stop )
- X {
- X switch( menu("Company Product Back") )
- X {
- X case 'c':
- X getfield("Id ", LONG, &company.id);
- X getfield("Name", STRING, company.name);
- X if( d_fillnew(COMPANY, &company) != S_OKAY )
- X report("Could not create company");
- X break;
- X case 'p':
- X getfield("Company id ", LONG, &product.company_id);
- X getfield("Product name", STRING, product.name);
- X getfield("Description ", STRING, product.description);
- X if( d_fillnew(PRODUCT, &product) != S_OKAY )
- X report("Could not create product");
- X break;
- X case 'b':
- X stop++;
- X }
- X }
- X}
- X
- X
- Xvoid main()
- X{
- X int stop = 0;
- X
- X mkdir("data", 0777);
- X
- X d_dbfpath("data");
- X if( d_open("demo", "s") != S_OKAY )
- X {
- X fprintf(stderr, "Cannot open database (db_status %d)\n", db_status);
- X exit(1);
- X }
- X
- X while( !stop )
- X {
- X switch( menu("Create Find Delete Quit") )
- X {
- X case 'c': create_menu(); break;
- X case 'f': find_menu(); break;
- X case 'q': stop++;
- X }
- X }
- X
- X d_close();
- X}
- X
- X/* end-of-file */
- X
- END_OF_FILE
- if test 5303 -ne `wc -c <'typhoon/examples/demo.c'`; then
- echo shar: \"'typhoon/examples/demo.c'\" unpacked with wrong size!
- fi
- # end of 'typhoon/examples/demo.c'
- fi
- if test -f 'typhoon/src/btree.h' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'typhoon/src/btree.h'\"
- else
- echo shar: Extracting \"'typhoon/src/btree.h'\" \(4959 characters\)
- sed "s/^X//" >'typhoon/src/btree.h' <<'END_OF_FILE'
- X/*----------------------------------------------------------------------------
- X * File : btree.h
- X * Library : typhoon
- X * OS : UNIX, OS/2, DOS
- X * Author : Thomas B. Pedersen
- X *
- X * Copyright (c) 1994 Thomas B. Pedersen. All rights reserved.
- X *
- X * Permission is hereby granted, without written agreement and without
- X * license or royalty fees, to use, copy, modify, and distribute this
- X * software and its documentation for any purpose, provided that the above
- X * copyright notice and the following two paragraphs appear (1) in all
- X * source copies of this software and (2) in accompanying documentation
- X * wherever the programatic interface of this software, or any derivative
- X * of it, is described.
- X *
- X * IN NO EVENT SHALL THOMAS B. PEDERSEN BE LIABLE TO ANY PARTY FOR DIRECT,
- X * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF
- X * THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF HE HAS BEEN
- X * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- X *
- X * THOMAS B. PEDERSEN SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT
- X * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- X * A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS"
- X * BASIS, AND THOMAS B. PEDERSEN HAS NO OBLIGATION TO PROVIDE MAINTENANCE,
- X * SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
- X *
- X * Description:
- X * Contains miscellaneous constants and macros used by B-tree functions.
- X *
- X * $Id: btree.h,v 1.1 1994/09/13 21:28:29 tbp Exp $
- X *
- X * $Log: btree.h,v $
- X * Revision 1.1 1994/09/13 21:28:29 tbp
- X * Added to repository.
- X *
- X *
- X *--------------------------------------------------------------------------*/
- X
- X
- X/*--------------------------------------------------------------------------*/
- X/* miscellaneous constants */
- X/*--------------------------------------------------------------------------*/
- X#define KEYVERSION_ID "KeyMan121" /* Version ID */
- X#define KEYVERSION_NUM 121 /* Version number */
- X
- X#define NEWPOS (ix_addr)-1 /* Indicates new pos for nodewrite */
- X#define ROOT 1 /* Root is always node 1 */
- X
- Xtypedef ix_addr A_type; /* node address type */
- Xtypedef long R_type; /* record reference type */
- X#ifdef RISC
- Xtypedef long N_type;
- X#else
- Xtypedef short N_type;
- X#endif
- X
- X
- X/*
- X * The format of a node is illustrated below. <n> is the number of tuples in
- X * the node. We call the set [A,K,R] a tuple, since the reference is considered
- X * a part of the key.
- X *
- X * +---+----+--------+----+----+--------+----+-- - -+------+---------+------+
- X * | n ! A0 | K0 | R0 | A1 | K1 | R1 | | An-1 | Kn-1 | Rn-1 |
- X * +---+----+--------+----+----+--------+----+-- - -+------+---------+------+
- X *
- X */
- X
- X/*
- X * The following macros are used to easily access the elements of a node. The
- X * macros KEY, CHILD and REF assume that a variable <I->node> points to the
- X * node operated on.
- X */
- X
- X#define NSIZE(N) (*(N_type *)(N))
- X#define KEY(N,i) (void *) (N+sizeof(N_type)+sizeof(A_type) + \
- X I->tsize * (i))
- X#define CHILD(N,i) (*(A_type *)(N+sizeof(N_type) + I->tsize * (i)))
- X#define REF(N,i) (*(R_type *) (N+sizeof(N_type)+sizeof(A_type) + \
- X I->aligned_keysize + I->tsize * (i)))
- X
- X
- X
- X/*
- X * The following macros are used to insert, delete and copy tuples in nodes.
- X *
- X * tupledel(N,i) - Delete the i'th tuple of the node N.
- X * tupleins(N,i,n) - Insert the tuple n in the i'th position in the
- X * node N.
- X * tuplecopy(N1,i1,N2,i2,n) - Copy n tuples starting from the i2'th position
- X * of node N2 to the i1'th position of the node N1.
- X * nodecopy(N1,N2) - Copy node N2 to node N1.
- X * keycopy(N1,i1,N2,i2) - Copy the i2'th key of node N2 to the i1'th key
- X * of N1.
- X */
- X
- X#define tupledel(N,i) memmove(&CHILD(N,i), &CHILD(N,(i)+1), \
- X I->tsize * (NSIZE(N) - (i) - 1) + sizeof(A_type))
- X#define tupleins(N,i,n) memmove(&CHILD(N,(i)+n), &CHILD(N,i), \
- X I->tsize * (NSIZE(N) - (i)) + sizeof(A_type))
- X#define tuplecopy(N1,i1,N2,i2,n)memcpy(&CHILD(N1,i1), &CHILD(N2,i2), I->tsize*(n))
- X#define nodecopy(N1,N2) memcpy(N1, N2, sizeof(N_type) + sizeof(A_type) \
- X + (I->tsize * NSIZE(N2)))
- X#define keycopy(N1,i1,N2,i2) memcpy(KEY(N1,i1),KEY(N2,i2),I->aligned_keysize + sizeof(R_type))
- X
- X
- X/*--------------------------------- bt_open --------------------------------*/
- Xvoid db_keygetheader PRM( (INDEX *); )
- Xvoid db_keyputheader PRM( (INDEX *); )
- Xint nodesearch PRM( (INDEX *, void *, int *); )
- Xint d_search PRM( (INDEX *, void *, ix_addr *, int *); )
- X
- X/*--------------------------------- bt_io.c --------------------------------*/
- Xix_addr noderead PRM( (INDEX *, char *, ix_addr); )
- Xix_addr nodewrite PRM( (INDEX *, char *, ix_addr); )
- Xvoid cache_clear PRM( (INDEX *); )
- X
- X
- X/* end-of-file */
- END_OF_FILE
- if test 4959 -ne `wc -c <'typhoon/src/btree.h'`; then
- echo shar: \"'typhoon/src/btree.h'\" unpacked with wrong size!
- fi
- # end of 'typhoon/src/btree.h'
- fi
- if test -f 'typhoon/src/cmpfuncs.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'typhoon/src/cmpfuncs.c'\"
- else
- echo shar: Extracting \"'typhoon/src/cmpfuncs.c'\" \(5944 characters\)
- sed "s/^X//" >'typhoon/src/cmpfuncs.c' <<'END_OF_FILE'
- X/*----------------------------------------------------------------------------
- X * File : cmpfuncs.c
- X * Library : typhoon
- X * OS : UNIX, OS/2, DOS
- X * Author : Thomas B. Pedersen
- X *
- X * Copyright (c) 1994 Thomas B. Pedersen. All rights reserved.
- X *
- X * Permission is hereby granted, without written agreement and without
- X * license or royalty fees, to use, copy, modify, and distribute this
- X * software and its documentation for any purpose, provided that the above
- X * copyright notice and the following two paragraphs appear (1) in all
- X * source copies of this software and (2) in accompanying documentation
- X * wherever the programatic interface of this software, or any derivative
- X * of it, is described.
- X *
- X * IN NO EVENT SHALL THOMAS B. PEDERSEN BE LIABLE TO ANY PARTY FOR DIRECT,
- X * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF
- X * THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF HE HAS BEEN
- X * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- X *
- X * THOMAS B. PEDERSEN SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT
- X * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- X * A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS"
- X * BASIS, AND THOMAS B. PEDERSEN HAS NO OBLIGATION TO PROVIDE MAINTENANCE,
- X * SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
- X *
- X * Description:
- X * Contains comparison functions for all the key types supported by
- X * Typhoon as well as compound keys.
- X *
- X * Functions:
- X * ucharcmp(a,b) - Compare two unsigned chars.
- X * charcmp(a, b) - Compare two chars.
- X * ustrcmp(s1, s2) - Compare two unsigned char strings.
- X * shortcmp(a,b) - Compare two shorts.
- X * intcmp(a,b) - Compare two ints.
- X * longcmp(a,b) - Compare two longs.
- X * floatcmp(a,b) - Compare two floats.
- X * doublecmp(a,b) - Compare two doubles.
- X * ushortcmp(a,b) - Compare two unsigned shorts.
- X * uintcmp(a,b) - Compare two unsigned ints.
- X * ulongcmp(a,b) - Compare two unsigned longs.
- X * compoundkeycmp(a,b)- Compare two compound keys.
- X * refentrycmp(a,b) - Compare two REF_ENTRY items.
- X *
- X * $Log: cmpfuncs.c,v $
- X * Revision 1.2 1994/09/17 16:00:13 tbp
- X * typhoon.h and environ.h are now included from <>.
- X *
- X * Revision 1.1 1994/09/13 21:28:30 tbp
- X * Added to repository.
- X *
- X *
- X *--------------------------------------------------------------------------*/
- X
- Xstatic char rcsid[] = "$Id: cmpfuncs.c,v 1.2 1994/09/17 16:00:13 tbp Exp $";
- X
- X#include <string.h>
- X#include <stdio.h>
- X#include <typhoon.h>
- X#include <ctype.h>
- X#include "ty_dbd.h"
- X#include "ty_type.h"
- X#include "ty_glob.h"
- X#include "ty_prot.h"
- X
- X#define CMP return *a > *b ? 1 : *a < *b ? -1 : 0
- X
- X
- X/*--------------------------- Function prototypes --------------------------*/
- Xstatic int charcmp PRM( (char *, char *); )
- Xstatic int shortcmp PRM( (short *, short *); )
- Xstatic int intcmp PRM( (int *, int *); )
- Xstatic int longcmp PRM( (long *, long *); )
- Xstatic int ucharcmp PRM( (uchar *, uchar *); )
- Xstatic int ushortcmp PRM( (ushort *, ushort *); )
- Xstatic int uintcmp PRM( (unsigned *, unsigned *); )
- Xstatic int ulongcmp PRM( (ulong *, ulong *); )
- Xstatic int ustrcmp PRM( (uchar *, uchar *); )
- Xstatic int floatcmp PRM( (float *, float *); )
- Xstatic int doublecmp PRM( (double *, double *); )
- X int refentrycmp PRM( (REF_ENTRY *, REF_ENTRY *); )
- X
- X
- XCMPFUNC keycmp[] = {
- X NULL,
- X (CMPFUNC)charcmp,
- X (CMPFUNC)ustrcmp, /* This should be strcmp, I think... */
- X (CMPFUNC)shortcmp,
- X (CMPFUNC)intcmp,
- X (CMPFUNC)longcmp,
- X (CMPFUNC)floatcmp,
- X (CMPFUNC)doublecmp,
- X NULL,
- X (CMPFUNC)refentrycmp,
- X NULL,
- X NULL,
- X NULL,
- X NULL,
- X NULL,
- X NULL,
- X NULL,
- X (CMPFUNC)ucharcmp,
- X (CMPFUNC)ustrcmp,
- X (CMPFUNC)ushortcmp,
- X (CMPFUNC)uintcmp,
- X (CMPFUNC)ulongcmp
- X};
- X
- X
- Xstatic charcmp(a, b)
- Xchar *a, *b;
- X{
- X CMP;
- X}
- X
- X
- Xstatic ucharcmp(a, b)
- Xuchar *a, *b;
- X{
- X CMP;
- X}
- X
- X
- Xty_ustrcmp(s1, s2)
- Xuchar *s1, *s2;
- X{
- X return ustrcmp(s1, s2);
- X}
- X
- Xstatic ustrcmp(s1, s2)
- Xuchar *s1, *s2;
- X{
- X uchar *sorttable = typhoon.db->header.sorttable;
- X
- X while( *s1 )
- X {
- X if( sorttable[*s1] - sorttable[*s2] )
- X break;
- X
- X s1++;
- X s2++;
- X }
- X
- X return sorttable[*s1] - sorttable[*s2];
- X}
- X
- X
- Xstatic shortcmp(a,b)
- Xshort *a, *b;
- X{
- X CMP;
- X}
- X
- Xstatic intcmp(a,b)
- Xint *a, *b;
- X{
- X CMP;
- X}
- X
- Xstatic longcmp(a,b)
- Xlong *a, *b;
- X{
- X CMP;
- X}
- X
- Xstatic floatcmp(a,b)
- Xfloat *a, *b;
- X{
- X CMP;
- X}
- X
- Xstatic doublecmp(a,b)
- Xdouble *a, *b;
- X{
- X CMP;
- X}
- X
- Xstatic ushortcmp(a,b)
- Xushort *a, *b;
- X{
- X CMP;
- X}
- X
- Xstatic uintcmp(a,b)
- Xunsigned *a, *b;
- X{
- X CMP;
- X}
- X
- Xstatic ulongcmp(a,b)
- Xulong *a, *b;
- X{
- X CMP;
- X}
- X
- X
- X/*----------------------------- compoundkeycmp -----------------------------*\
- X *
- X * Purpose : This function compares two compound keys. The global variable
- X * <curr_key> is set to the ID of the keys being compared. This
- X * is because the call to the key comparison function in the B-tree
- X * functions only passes two pointers and not the type.
- X *
- X * Params : a - The first key
- X * b - The second key
- X *
- X * Returns : < 0 - a < b
- X * 0 - a = b
- X * > 0 - a > 0
- X *
- X */
- X
- Xcompoundkeycmp(a, b)
- Xvoid *a, *b;
- X{
- X Key *key = typhoon.db->key + typhoon.curr_key;
- X KeyField *keyfld= typhoon.db->keyfield + key->first_keyfield;
- X int fields = key->fields;
- X int type, diff;
- X
- X while( fields-- )
- X {
- X type = typhoon.db->field[ keyfld->field ].type & (FT_BASIC|FT_UNSIGNED);
- X
- X if( diff = (*keycmp[type])((char *)a + keyfld->offset, (char *)b + keyfld->offset) )
- X break;
- X
- X keyfld++;
- X }
- X
- X /* If the field is sorted in descending order, invert the sign */
- X if( !keyfld->asc )
- X diff = -diff;
- X
- X return diff;
- X}
- X
- X
- Xrefentrycmp(a, b)
- XREF_ENTRY *a, *b;
- X{
- X if( a->parent > b->parent ) return 1;
- X if( a->parent < b->parent ) return -1;
- X if( a->dependent.recid > b->dependent.recid ) return 1;
- X if( a->dependent.recid < b->dependent.recid ) return -1;
- X if( a->dependent.recno > b->dependent.recno ) return 1;
- X if( a->dependent.recno < b->dependent.recno ) return -1;
- X
- X return 0;
- X}
- X
- X/* end-of-file */
- END_OF_FILE
- if test 5944 -ne `wc -c <'typhoon/src/cmpfuncs.c'`; then
- echo shar: \"'typhoon/src/cmpfuncs.c'\" unpacked with wrong size!
- fi
- # end of 'typhoon/src/cmpfuncs.c'
- fi
- if test -f 'typhoon/src/h/typhoon.h' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'typhoon/src/h/typhoon.h'\"
- else
- echo shar: Extracting \"'typhoon/src/h/typhoon.h'\" \(6375 characters\)
- sed "s/^X//" >'typhoon/src/h/typhoon.h' <<'END_OF_FILE'
- X/*----------------------------------------------------------------------------
- X * File : typhoon.h
- X * Library : typhoon
- X * OS : UNIX, OS/2, DOS
- X * Author : Thomas B. Pedersen
- X *
- X * Copyright (c) 1994 Thomas B. Pedersen. All rights reserved.
- X *
- X * Permission is hereby granted, without written agreement and without
- X * license or royalty fees, to use, copy, modify, and distribute this
- X * software and its documentation for any purpose, provided that the above
- X * copyright notice and the following two paragraphs appear (1) in all
- X * source copies of this software and (2) in accompanying documentation
- X * wherever the programatic interface of this software, or any derivative
- X * of it, is described.
- X *
- X * IN NO EVENT SHALL THOMAS B. PEDERSEN BE LIABLE TO ANY PARTY FOR DIRECT,
- X * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF
- X * THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF HE HAS BEEN
- X * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- X *
- X * THOMAS B. PEDERSEN SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT
- X * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- X * A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS"
- X * BASIS, AND THOMAS B. PEDERSEN HAS NO OBLIGATION TO PROVIDE MAINTENANCE,
- X * SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
- X *
- X * Description:
- X * Header file for Typhoon library.
- X *
- X * $Id: typhoon.h,v 1.1 1994/09/17 15:59:13 tbp Exp $
- X *
- X * $Log: typhoon.h,v $
- X * Revision 1.1 1994/09/17 15:59:13 tbp
- X * Added to repository.
- X *
- X *
- X *--------------------------------------------------------------------------*/
- X
- X#ifndef _TYPHOON_INCLUDED
- X#define _TYPHOON_INCLUDED
- X
- X#ifndef _ENVIRON_INCLUDED
- X#include <environ.h>
- X#endif
- X
- X/*---------- Status codes --------------------------------------------------*/
- X#define S_NOCR -2 /* No current record */
- X#define S_NOCD -1 /* No current database */
- X
- X#define S_OKAY 0 /* Operation successful */
- X#define S_NOTFOUND 1 /* Key not found */
- X#define S_DUPLICATE 2 /* Duplicate key found */
- X#define S_DELETED 3 /* Record is deleted */
- X#define S_RESTRICT 4 /* Restrict rule encountered(db_subcode)*/
- X#define S_FOREIGN 5 /* No foreign key (db_subcode) */
- X#define S_LOCKED 8 /* Record is locked */
- X#define S_UNLOCKED 9 /* Record is unlocked */
- X#define S_VERSION 10 /* B-tree or data file has wrong version*/
- X#define S_INVPARM 11 /* Invalid parameter */
- X
- X#define S_NOMEM 200 /* Out of memory */
- X#define S_NOTAVAIL 201 /* Database not available */
- X#define S_IOFATAL 202 /* Fatal I/O operation */
- X#define S_FATAL 203 /* Fatal error - recover */
- X#define S_MAXCLIENTS 500 /* Too many clients */
- X#define S_NOSERVER 501 /* No server is installed */
- X
- X/*---------- User errors ---------------------------------------------------*/
- X#define S_INVDB 1000 /* Invalid database */
- X#define S_INVREC 1001 /* Invalid record */
- X#define S_INVFLD 1002 /* Invalid field name */
- X#define S_NOTKEY 1003 /* Field is not a key */
- X#define S_RECSIZE 1004 /* Variable length record has invalid sz*/
- X#define S_BADTYPE 1005 /* Bad parameter type */
- X#define S_INVKEY 1006 /* Invalid key */
- X#define S_INVADDR 1007 /* Invalid database address (rec number)*/
- X
- X/*---------- Lock types ----------------------------------------------------*/
- X#define LOCK_TEST 1 /* Test if a record is locked */
- X#define LOCK_UPDATE 2 /* Lock a record for update */
- X
- Xtypedef struct {
- X ulong recid;
- X ulong recno;
- X} DB_ADDR;
- X
- Xextern ulong curr_rec;
- Xextern int db_status; /* See S_... constants */
- Xextern long db_subcode;
- X
- X#ifdef OS2
- X# ifdef __BORLANDC__
- X# define INCL_NOPMAPI
- X# endif
- X# ifdef __IBMC__
- X# pragma map(db_status, "_db_status")
- X# pragma map(db_subcode, "_db_subcode")
- X# endif
- X# include <os2def.h>
- X# define CL APIRET EXPENTRY
- X#else
- X# define CL int
- X#endif
- X
- X/*---------- Function prototypes -------------------------------------------*/
- XCL d_block PRM( (void); )
- XCL d_unblock PRM( (void); )
- XCL d_setfiles PRM( (int); )
- XCL d_open PRM( (char *, char *); )
- XCL d_close PRM( (void); )
- XCL d_destroy PRM( (char *); )
- XCL d_keyfind PRM( (ulong, void *); )
- XCL d_keyfrst PRM( (ulong); )
- XCL d_keylast PRM( (ulong); )
- XCL d_keynext PRM( (ulong); )
- XCL d_keyprev PRM( (ulong); )
- XCL d_keyread PRM( (void *); )
- XCL d_fillnew PRM( (ulong, void *); )
- XCL d_keystore PRM( (ulong); )
- XCL d_recwrite PRM( (void *); )
- XCL d_recread PRM( (void *); )
- XCL d_crread PRM( (ulong, void *); )
- X
- XCL d_delete PRM( (void); )
- XCL d_recfrst PRM( (ulong); )
- XCL d_reclast PRM( (ulong); )
- XCL d_recnext PRM( (ulong); )
- XCL d_recprev PRM( (ulong); )
- X
- XCL d_crget PRM( (DB_ADDR *); )
- XCL d_crset PRM( (DB_ADDR *); )
- X
- XCL d_dbget PRM( (int *); )
- XCL d_dbset PRM( (int); )
- X
- XCL d_records PRM( (ulong, ulong *); )
- XCL d_keys PRM( (ulong); )
- X
- XCL d_dbdpath PRM( (char *); )
- XCL d_dbfpath PRM( (char *); )
- X
- XCL d_reclock PRM( (DB_ADDR *, int); )
- XCL d_recunlock PRM( (DB_ADDR *); )
- X
- XCL d_keyfrst PRM( (ulong); )
- XCL d_keylast PRM( (ulong); )
- XCL d_keyprev PRM( (ulong); )
- XCL d_keynext PRM( (ulong); )
- X
- XCL d_recfrst PRM( (ulong); )
- XCL d_reclast PRM( (ulong); )
- XCL d_recprev PRM( (ulong); )
- XCL d_recnext PRM( (ulong); )
- X
- X
- XCL d_replicationlog PRM( (int); )
- XCL d_addsite PRM( (ulong); )
- XCL d_delsite PRM( (ulong); )
- XCL d_deltable PRM( (ulong, ulong); )
- X
- XCL d_getkeysize PRM( (ulong, unsigned *); )
- XCL d_getrecsize PRM( (ulong, unsigned *); )
- XCL d_getfieldtype PRM( (ulong, unsigned *); )
- XCL ty_ustrcmp PRM( (uchar *, uchar *); )
- XCL d_getkeyid PRM( (ulong, ulong *); )
- XCL d_getforeignkeyid PRM( (ulong, ulong, ulong *); )
- XCL d_makekey PRM( (ulong, void *, void *); )
- X
- XCL d_seterrfn PRM( (void (*)(int, long)); )
- X
- X
- X#undef CL
- X
- X#endif
- X
- X/* end-of-file */
- END_OF_FILE
- if test 6375 -ne `wc -c <'typhoon/src/h/typhoon.h'`; then
- echo shar: \"'typhoon/src/h/typhoon.h'\" unpacked with wrong size!
- fi
- # end of 'typhoon/src/h/typhoon.h'
- fi
- if test -f 'typhoon/src/ty_repif.h' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'typhoon/src/ty_repif.h'\"
- else
- echo shar: Extracting \"'typhoon/src/ty_repif.h'\" \(5321 characters\)
- sed "s/^X//" >'typhoon/src/ty_repif.h' <<'END_OF_FILE'
- X/*----------------------------------------------------------------------------
- X * File : ty_repif.h
- X * Library : typhoon
- X * OS : UNIX, OS/2, DOS
- X * Author : Thomas B. Pedersen
- X *
- X * Copyright (c) 1994 Thomas B. Pedersen. All rights reserved.
- X *
- X * Permission is hereby granted, without written agreement and without
- X * license or royalty fees, to use, copy, modify, and distribute this
- X * software and its documentation for any purpose, provided that the above
- X * copyright notice and the following two paragraphs appear (1) in all
- X * source copies of this software and (2) in accompanying documentation
- X * wherever the programatic interface of this software, or any derivative
- X * of it, is described.
- X *
- X * IN NO EVENT SHALL THOMAS B. PEDERSEN BE LIABLE TO ANY PARTY FOR DIRECT,
- X * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF
- X * THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF HE HAS BEEN
- X * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- X *
- X * THOMAS B. PEDERSEN SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT
- X * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- X * A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS"
- X * BASIS, AND THOMAS B. PEDERSEN HAS NO OBLIGATION TO PROVIDE MAINTENANCE,
- X * SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
- X *
- X * Description:
- X * Contains structures used in the interface between the database and the
- X * Replication Server.
- X *
- X * $Id: ty_repif.h,v 1.1 1994/09/13 21:28:38 tbp Exp $
- X *
- X * $Log: ty_repif.h,v $
- X * Revision 1.1 1994/09/13 21:28:38 tbp
- X * Added to repository.
- X *
- X *
- X *--------------------------------------------------------------------------*/
- X
- X#ifndef _TY_REPIF_INCLUDED
- X#define _TY_REPIF_INCLUDED
- X
- X#define REPLLOG_NAME "replserv.log"
- X
- X#define ACTION_UPDATE 'u' /* Update or create a record */
- X#define ACTION_DELETE 'd' /* Delete a record */
- X#define ACTION_NEWSITE 'n' /* Scan catalog for new site */
- X#define ACTION_DELSITE 'e' /* Remove a site from memory */
- X#define ACTION_DELTABLE 't' /* Remove a table fro memmory */
- X
- Xtypedef struct {
- X char action; /* See ACTION_... */
- X char prog_id; /* Program ID */
- X ulong recid; /* Record ID */
- X union {
- X DB_ADDR addr; /* action = UPDATE */
- X char key[KEYSIZE_MAX]; /* action = DELETE */
- X ulong site_id; /* action = NEWSITE, DELSITE or DELTABLE*/
- X } u;
- X} LOGENTRY;
- X
- X
- X/*--------------------------- Protocol block IDs ---------------------------*/
- X#define REPL_ACKNOWLEDGE 0 /* ID of acknowledge block */
- X#define REPL_UPDATE 100 /* ID of update block */
- X#define REPL_DELETE 101 /* ID of delete block */
- X#define REPL_CLEARTABLE 102
- X#define REPL_ERROR 103
- X#define REPL_PROTBUF_SIZE 25000 /* Max buffer size passed */
- X#define REPL_HEADER_SIZE 8
- X
- Xstruct repl_header {
- X ulong seqno; /* Sequence number */
- X ulong len; /* Length of rest of block */
- X};
- X
- Xstruct repl_acknowledge {
- X ulong seqno; /* Sequence number */
- X ulong len; /* Length of rest of block */
- X uchar id; /* Must be 0 */
- X uchar spare[3]; /* Used to maintain dword alignment */
- X ulong sequence; /* Sequence number acknowledged */
- X};
- X
- Xstruct repl_update {
- X ulong seqno; /* Sequence number */
- X ulong len; /* Length of rest of block */
- X uchar id; /* Must be 100 */
- X uchar prog_id; /* Program ID */
- X ushort rec_len; /* Number of bytes in rec[] */
- X ulong recid; /* Record ID */
- X ulong sequence; /* Update sequence number */
- X uchar rec[1]; /* Record buffer */
- X};
- X
- Xstruct repl_delete {
- X ulong seqno; /* Sequence number */
- X ulong len; /* Length of rest of block */
- X uchar id; /* Must be 101 */
- X uchar prog_id; /* Program ID */
- X ushort key_len; /* Number of bytes in buf[] */
- X ulong recid; /* Record ID */
- X ulong sequence; /* Update sequence number */
- X uchar key[1]; /* Key buffer */
- X};
- X
- X
- Xstruct repl_cleartable {
- X ulong seqno; /* Sequence number */
- X ulong len; /* Length of rest of block */
- X uchar id; /* Must be 102 */
- X uchar spare[3];
- X ulong recid; /* ID of table to clear */
- X};
- X
- X
- X
- X/*--------------------------------------------------------------------------*\
- X *
- X * Block : repl_error
- X *
- X * Purpose : This protocol block is used to report an error to the
- X * Replication Server.
- X *
- X * Direction: Site -> Replication Server.
- X *
- X */
- Xstruct repl_error {
- X ulong seqno; /* Sequence number */
- X ulong len; /* Length of rest of block */
- X uchar id; /* Must be 103 */
- X uchar error; /* 0=Record contains unknown reference */
- X /* 1=Record is referenced by other rec */
- X uchar spare[2]; /* Used to maintain dword alignment */
- X ulong arg; /* error=0: ID of referenced table */
- X ulong sequence; /* Sequence number of erroneous block */
- X};
- X
- X#endif
- X
- X/* end-of-file */
- X
- END_OF_FILE
- if test 5321 -ne `wc -c <'typhoon/src/ty_repif.h'`; then
- echo shar: \"'typhoon/src/ty_repif.h'\" unpacked with wrong size!
- fi
- # end of 'typhoon/src/ty_repif.h'
- fi
- if test -f 'typhoon/src/ty_repl.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'typhoon/src/ty_repl.c'\"
- else
- echo shar: Extracting \"'typhoon/src/ty_repl.c'\" \(6049 characters\)
- sed "s/^X//" >'typhoon/src/ty_repl.c' <<'END_OF_FILE'
- X/*----------------------------------------------------------------------------
- X * File : ty_repl.c
- X * Library : typhoon
- X * OS : UNIX, OS/2, DOS
- X * Author : Thomas B. Pedersen
- X *
- X * Copyright (c) 1994 Thomas B. Pedersen. All rights reserved.
- X *
- X * Permission is hereby granted, without written agreement and without
- X * license or royalty fees, to use, copy, modify, and distribute this
- X * software and its documentation for any purpose, provided that the above
- X * copyright notice and the following two paragraphs appear (1) in all
- X * source copies of this software and (2) in accompanying documentation
- X * wherever the programatic interface of this software, or any derivative
- X * of it, is described.
- X *
- X * IN NO EVENT SHALL THOMAS B. PEDERSEN BE LIABLE TO ANY PARTY FOR DIRECT,
- X * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF
- X * THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF HE HAS BEEN
- X * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- X *
- X * THOMAS B. PEDERSEN SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT
- X * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- X * A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS"
- X * BASIS, AND THOMAS B. PEDERSEN HAS NO OBLIGATION TO PROVIDE MAINTENANCE,
- X * SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
- X *
- X * Description:
- X *
- X * Functions:
- X * Contains functions for logging updates and deletions.
- X *
- X * $Log: ty_repl.c,v $
- X * Revision 1.2 1994/09/17 16:00:20 tbp
- X * typhoon.h and environ.h are now included from <>.
- X *
- X * Revision 1.1 1994/09/13 21:28:38 tbp
- X * Added to repository.
- X *
- X *
- X *--------------------------------------------------------------------------*/
- X
- Xstatic char rcsid[] = "$Id: ty_repl.c,v 1.2 1994/09/17 16:00:20 tbp Exp $";
- X
- X#ifdef UNIX
- X# include <unistd.h>
- X#else
- X# include <sys\types.h>
- X# include <sys\stat.h>
- X# include <io.h>
- X#endif
- X#include <stdio.h>
- X#include <string.h>
- X#include <fcntl.h>
- X#include <errno.h>
- X#include <typhoon.h>
- X#include "ty_dbd.h"
- X#include "ty_type.h"
- X#include "ty_glob.h"
- X#include "ty_prot.h"
- X#include "ty_repif.h"
- X#include "catalog.h"
- X
- X/*-------------------------- Function prototypes ---------------------------*/
- Xstatic int read_distables PRM( (void); )
- Xstatic void add_recid PRM( (Id); )
- Xstatic int get_recid PRM( (Id); )
- Xstatic void write_logentry PRM( (LOGENTRY *, unsigned); )
- X
- X/*---------------------------- Global variables ----------------------------*/
- Xstatic int dis_dbid = -1; /* Distributed database ID */
- Xstatic int dis_records = 0; /* Number of entries in dis_record[]*/
- Xstatic Id dis_record[100];
- X
- X
- Xstatic get_recid(id)
- XId id;
- X{
- X int i;
- X
- X for( i=0; i<dis_records; i++ )
- X if( dis_record[i] == id )
- X return i;
- X
- X return -1;
- X}
- X
- X
- Xstatic void add_recid(id)
- XId id;
- X{
- X if( get_recid(id) == -1 )
- X dis_record[dis_records++] = id;
- X}
- X
- X
- Xstatic read_distables()
- X{
- X struct sys_distab table;
- X ulong table_id;
- X int old_dbid;
- X int rc;
- X
- X d_dbget(&old_dbid);
- X
- X if( d_open("catalog", "s") != S_OKAY )
- X {
- X d_dbset(old_dbid);
- X return -1;
- X }
- X
- X dis_records = 0;
- X for( rc = d_recfrst(SYS_DISTAB); rc == S_OKAY; rc = d_recnext(SYS_DISTAB) )
- X {
- X d_recread(&table);
- X add_recid(table.id);
- X }
- X
- X d_close();
- X d_dbset(old_dbid);
- X
- X return 0;
- X}
- X
- X
- X/*---------------------------- d_replicationlog ----------------------------*\
- X *
- X * Purpose : Turn the replication log on/off.
- X *
- X * Parameters: on - 1=On, 0=Off
- X *
- X * Returns : S_OKAY - The ID is not a key ID.
- X *
- X */
- XFNCLASS d_replicationlog(on)
- Xint on;
- X{
- X DB->logging = on;
- X
- X if( on )
- X {
- X if( read_distables() == -1 )
- X RETURN S_IOFATAL;
- X dis_dbid = CURR_DB;
- X }
- X
- X RETURN S_OKAY;
- X}
- X
- X
- XFNCLASS d_addsite(id)
- Xulong id;
- X{
- X LOGENTRY entry;
- X
- X entry.action = ACTION_NEWSITE;
- X entry.u.site_id = id;
- X
- X write_logentry(&entry, offsetof(LOGENTRY, u) + sizeof entry.u.site_id);
- X
- X RETURN S_OKAY;
- X}
- X
- X
- XFNCLASS d_delsite(id)
- Xulong id;
- X{
- X LOGENTRY entry;
- X
- X entry.action = ACTION_DELSITE;
- X entry.u.site_id = id;
- X
- X write_logentry(&entry, offsetof(LOGENTRY, u) + sizeof entry.u.site_id);
- X
- X RETURN S_OKAY;
- X}
- X
- X
- XFNCLASS d_deltable(site_id, table_id)
- Xulong site_id, table_id;
- X{
- X LOGENTRY entry;
- X
- X entry.action = ACTION_DELTABLE;
- X entry.recid = table_id;
- X entry.u.site_id = site_id;
- X
- X write_logentry(&entry, offsetof(LOGENTRY, u) + sizeof entry.u.site_id);
- X
- X RETURN S_OKAY;
- X}
- X
- X
- X/*--------------------------------------------------------------------------*\
- X *
- X * Function : ty_log
- X *
- X * Purpose : Add an entry to the Replication Server log. If site_id == -1
- X * ty_log is called to add or delete a site.
- X *
- X * Parameters: action - 'u'=Update, 'd'=delete.
- X *
- X * Returns : Nothing.
- X *
- X */
- Xvoid ty_log(action)
- Xint action;
- X{
- X LOGENTRY entry;
- X Id recid = INTERN_TO_RECID(CURR_RECID);
- X ushort size, keysize;
- X Record *rec = &DB->record[RECID_TO_INTERN(recid)];
- X
- X /* Return if the current database is not distributed */
- X if( CURR_DB != dis_dbid )
- X return;
- X
- X /* Return here if the record is not distributed */
- X if( get_recid(recid) == -1 )
- X return;
- X
- X entry.action= action;
- X entry.recid = recid;
- X size = offsetof(LOGENTRY, u);
- X
- X switch( action )
- X {
- X case ACTION_UPDATE:
- X /* Store the database address of the modified record */
- X size += sizeof(entry.u.addr);
- X d_crget(&entry.u.addr);
- X break;
- X case ACTION_DELETE:
- X /* Store the primary key of the deleted record */
- X keysize = DB->key[ rec->first_key ].size;
- X
- X /* Copy the record's first key to <entry.buf> */
- X memcpy(entry.u.key,
- X set_keyptr(&DB->key[ rec->first_key ], DB->recbuf),
- X keysize);
- X size += keysize;
- X break;
- X }
- X
- X write_logentry(&entry, size);
- X}
- X
- X
- X
- Xstatic void write_logentry(entry, size)
- XLOGENTRY *entry;
- Xunsigned size;
- X{
- X int fh;
- X short shsize;
- X
- X if( (fh=open(REPLLOG_NAME, O_BINARY|O_CREAT|O_RDWR|O_APPEND, CREATMASK)) == -1 )
- X {
- X#ifdef UNIX
- X printf("PANIC: cannot open '%s' (pid %d)\n\a", REPLLOG_NAME, getpid());
- X#else
- X printf("PANIC: cannot open '%s'\n\a", REPLLOG_NAME);
- X#endif
- X return;
- X }
- X
- X shsize = size;
- X write(fh, &shsize, sizeof shsize);
- X write(fh, entry, size);
- X
- X close(fh);
- X}
- X
- X/* end-of-file */
- END_OF_FILE
- if test 6049 -ne `wc -c <'typhoon/src/ty_repl.c'`; then
- echo shar: \"'typhoon/src/ty_repl.c'\" unpacked with wrong size!
- fi
- # end of 'typhoon/src/ty_repl.c'
- fi
- if test -f 'typhoon/src/ty_util.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'typhoon/src/ty_util.c'\"
- else
- echo shar: Extracting \"'typhoon/src/ty_util.c'\" \(5150 characters\)
- sed "s/^X//" >'typhoon/src/ty_util.c' <<'END_OF_FILE'
- X/*----------------------------------------------------------------------------
- X * File : ty_util.c
- X * Library : typhoon
- X * OS : UNIX, OS/2, DOS
- X * Author : Thomas B. Pedersen
- X *
- X * Copyright (c) 1994 Thomas B. Pedersen. All rights reserved.
- X *
- X * Permission is hereby granted, without written agreement and without
- X * license or royalty fees, to use, copy, modify, and distribute this
- X * software and its documentation for any purpose, provided that the above
- X * copyright notice and the following two paragraphs appear (1) in all
- X * source copies of this software and (2) in accompanying documentation
- X * wherever the programatic interface of this software, or any derivative
- X * of it, is described.
- X *
- X * IN NO EVENT SHALL THOMAS B. PEDERSEN BE LIABLE TO ANY PARTY FOR DIRECT,
- X * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF
- X * THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF HE HAS BEEN
- X * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- X *
- X * THOMAS B. PEDERSEN SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT
- X * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- X * A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS"
- X * BASIS, AND THOMAS B. PEDERSEN HAS NO OBLIGATION TO PROVIDE MAINTENANCE,
- X * SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
- X *
- X * Description:
- X *
- X * Functions:
- X *
- X * $Log: ty_util.c,v $
- X * Revision 1.2 1994/09/17 16:00:21 tbp
- X * typhoon.h and environ.h are now included from <>.
- X *
- X * Revision 1.1 1994/09/13 21:28:39 tbp
- X * Added to repository.
- X *
- X *
- X *--------------------------------------------------------------------------*/
- X
- Xstatic char rcsid[] = "$Id: ty_util.c,v 1.2 1994/09/17 16:00:21 tbp Exp $";
- X
- X#ifdef UNIX
- X# include <unistd.h>
- X#endif
- X#include <string.h>
- X#include <stdio.h>
- X#include <typhoon.h>
- X#include "ty_dbd.h"
- X#include "ty_type.h"
- X#include "ty_glob.h"
- X#include "ty_prot.h"
- X
- X
- X/*------------------------------ d_getkeysize ------------------------------*\
- X *
- X * Purpose : Return the size of a key.
- X *
- X * Parameters: id - Field ID or compound key ID.
- X * size - Pointer to var in which size will be returned.
- X *
- X * Returns : S_NOTKEY - The ID is not a key ID.
- X * S_NOCD - No current database.
- X *
- X */
- X
- XFNCLASS d_getkeysize(id, size)
- XId id;
- Xunsigned *size;
- X{
- X Field *fld;
- X int rc;
- X
- X /* Make sure that a database is open */
- X if( CURR_DB == -1 )
- X RETURN_RAP(S_NOCD);
- X
- X /* Determine whether this id is a key id or a compound key id */
- X if( id < REC_FACTOR )
- X {
- X if( id >= DB->header.keys )
- X RETURN_RAP(S_NOTKEY);
- X
- X *size = DB->key[id].size;
- X }
- X else
- X {
- X if( (rc = set_recfld(id, NULL, &fld)) != S_OKAY )
- X return rc;
- X
- X if( !(fld->type & FT_KEY) )
- X RETURN_RAP(S_NOTKEY);
- X
- X *size = DB->key[fld->keyid].size;
- X }
- X
- X RETURN S_OKAY;
- X}
- X
- X
- X
- XFNCLASS d_getfieldtype(id, type)
- XId id;
- Xunsigned *type;
- X{
- X Field *fld;
- X int rc;
- X
- X /* Make sure that a database is open */
- X if( CURR_DB == -1 )
- X RETURN_RAP(S_NOCD);
- X
- X /* Determine whether this id is a key id or a compound key id */
- X if( id < REC_FACTOR )
- X {
- X if( id >= DB->header.keys )
- X RETURN_RAP(S_NOTKEY);
- X }
- X else
- X {
- X if( (rc = set_recfld(id, NULL, &fld)) != S_OKAY )
- X return rc;
- X
- X id = fld->keyid;
- X }
- X
- X *type = DB->field[ DB->keyfield[ DB->key[id].first_keyfield ].field ].type;
- X
- X RETURN S_OKAY;
- X}
- X
- X
- X
- X
- X/*------------------------------ d_getrecsize ------------------------------*\
- X *
- X * Purpose : Return the size of a record.
- X *
- X * Parameters: recid - Record ID.
- X * size - Pointer to var in which size will be returned.
- X *
- X * Returns : S_NOTKEY - The ID is not a record ID.
- X * S_NOCD - No current database.
- X *
- X */
- X
- XFNCLASS d_getrecsize(recid, size)
- XId recid;
- Xunsigned *size;
- X{
- X Record *rec;
- X int rc;
- X
- X /* Make sure that a database is open */
- X if( CURR_DB == -1 )
- X RETURN_RAP(S_NOCD);
- X
- X if( (rc = set_recfld(recid, &rec, NULL)) != S_OKAY )
- X return rc;
- X
- X *size = rec->size;
- X
- X RETURN S_OKAY;
- X}
- X
- X
- X
- X
- XFNCLASS d_makekey(id, recbuf, keybuf)
- XId id;
- Xvoid *recbuf, *keybuf;
- X{
- X KeyField *keyfld;
- X Key *key;
- X int n, rc;
- X
- X /* Make sure that a database is open */
- X if( CURR_DB == -1 )
- X RETURN_RAP(S_NOCD);
- X
- X if( (rc=aux_getkey(id, &key)) != S_OKAY )
- X return rc;
- X
- X keyfld = DB->keyfield + key->first_keyfield;
- X n = key->fields;
- X
- X /* Build compound key from record */
- X while( n-- )
- X {
- X memcpy((char *)keybuf + keyfld->offset,
- X (char *)recbuf + DB->field[ keyfld->field ].offset,
- X DB->field[ keyfld->field ].size);
- X keyfld++;
- X }
- X
- X RETURN S_OKAY;
- X}
- X
- X
- XFNCLASS d_getkeyid(recid, keyid)
- XId recid, *keyid;
- X{
- X Record *rec;
- X int rc;
- X
- X if( (rc = set_recfld(recid, &rec, NULL)) != S_OKAY )
- X return rc;
- X
- X *keyid = rec->first_key;
- X
- X RETURN S_OKAY;
- X}
- X
- X
- X
- XFNCLASS d_getforeignkeyid(recid, parent_table, keyid)
- XId recid, parent_table, *keyid;
- X{
- X Record *rec;
- X Key *key;
- X int rc, n;
- X
- X if( (rc = set_recfld(recid, &rec, NULL)) != S_OKAY )
- X return rc;
- X
- X parent_table= RECID_TO_INTERN(parent_table);
- X n = rec->keys;
- X key = DB->key + rec->first_key;
- X
- X while( n-- )
- X {
- X if( KEY_ISFOREIGN(key) && key->parent == parent_table )
- X {
- X *keyid = key - DB->key;
- X RETURN S_OKAY;
- X }
- X key++;
- X }
- X
- X RETURN S_NOTFOUND;
- X}
- X
- X
- X
- X/* end-of-file */
- END_OF_FILE
- if test 5150 -ne `wc -c <'typhoon/src/ty_util.c'`; then
- echo shar: \"'typhoon/src/ty_util.c'\" unpacked with wrong size!
- fi
- # end of 'typhoon/src/ty_util.c'
- fi
- if test -f 'typhoon/src/util/exp.y' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'typhoon/src/util/exp.y'\"
- else
- echo shar: Extracting \"'typhoon/src/util/exp.y'\" \(4986 characters\)
- sed "s/^X//" >'typhoon/src/util/exp.y' <<'END_OF_FILE'
- X/*----------------------------------------------------------------------------
- X * File : exp.y
- X * Program : tyexport
- X * OS : UNIX, OS/2, DOS
- X * Author : Thomas B. Pedersen
- X *
- X * Copyright (c) 1994 Thomas B. Pedersen. All rights reserved.
- X *
- X * Permission is hereby granted, without written agreement and without
- X * license or royalty fees, to use, copy, modify, and distribute this
- X * software and its documentation for any purpose, provided that the above
- X * copyright notice and the following two paragraphs appear (1) in all
- X * source copies of this software and (2) in accompanying documentation
- X * wherever the programatic interface of this software, or any derivative
- X * of it, is described.
- X *
- X * IN NO EVENT SHALL THOMAS B. PEDERSEN BE LIABLE TO ANY PARTY FOR DIRECT,
- X * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF
- X * THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF HE HAS BEEN
- X * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- X *
- X * THOMAS B. PEDERSEN SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT
- X * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- X * A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS"
- X * BASIS, AND THOMAS B. PEDERSEN HAS NO OBLIGATION TO PROVIDE MAINTENANCE,
- X * SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
- X *
- X * Description:
- X * Grammar for export specification.
- X *
- X * $Id: exp.y,v 1.2 1994/09/17 16:11:13 tbp Exp $
- X *
- X * $Log: exp.y,v $
- X * Revision 1.2 1994/09/17 16:11:13 tbp
- X * Added include directive.
- X *
- X * Added included directive.
- X *
- X * Added include directive.
- X *
- X * Revision 1.1 1994/09/13 21:28:54 tbp
- X * Added to repository.
- X *
- X * Added to repository.
- X *
- X *
- X *--------------------------------------------------------------------------*/
- X
- X%{
- X
- X#include <string.h>
- X#include <stdarg.h>
- X#include <typhoon.h>
- X#include "../ty_dbd.h"
- X#include "../ty_type.h"
- X#include "export.h"
- X
- X#define NEST_MAX 15
- X
- X/*--------------------------- Function prototypes --------------------------*/
- XRecord *GetRecord PRM( (char *); )
- XField *GetField PRM( (Structdef *, char *); )
- XStructdef *GetStruct PRM( (Structdef *, char *); )
- X
- X/*---------------------------- Global variables ----------------------------*/
- Xstatic Record *cur_rec = NULL; /* Current record */
- Xstatic Field *cur_fld = NULL; /* Current field */
- Xstatic Structdef *cur_str = NULL; /* Current structure */
- Xstatic Structdef *strnest[NEST_MAX]; /* Pointers to structures */
- Xstatic int cur_nest = -1; /* Current nesting */
- X
- X%}
- X
- X%union {
- X char s[IDENT_LEN+1];
- X}
- X
- X%start export_spec
- X
- X%token T_EXPORT T_RECORD T_STRUCT T_UNION T_IN
- X%token <s> T_IDENT T_STRING
- X%token '{' '}' ';'
- X
- X%%
- X
- Xexport_spec : T_EXPORT T_IDENT '{' record_list '}'
- X ;
- X
- Xrecord_list : record
- X | record_list record
- X ;
- X
- Xrecord : record_head '{' field_list '}'
- X {
- X cur_nest--;
- X }
- X ;
- X
- Xrecord_head : T_RECORD T_IDENT T_IN T_STRING
- X {
- X if( cur_rec = GetRecord($2) )
- X {
- X cur_rec->aux = 1;
- X cur_str = &dbd.structdef[cur_rec->structid];
- X }
- X else
- X cur_str = NULL;
- X strnest[++cur_nest] = cur_str;
- X }
- X ;
- X
- Xfield_list : field
- X | field_list field
- X ;
- X
- Xfield : T_IDENT ';'
- X {
- X if( cur_str )
- X cur_fld = GetField(cur_str, $1);
- X }
- X
- X | struct_head '{' field_list '}' ';'
- X {
- X cur_str = strnest[--cur_nest];
- X }
- X ;
- X
- Xstruct_head : struct_or_union T_IDENT
- X {
- X if( cur_str )
- X cur_str = GetStruct(cur_str, $2);
- X strnest[++cur_nest] = cur_str;
- X }
- X ;
- X
- Xstruct_or_union : T_STRUCT
- X | T_UNION
- X ;
- X
- X
- X%%
- X
- X
- X#include <stdio.h>
- X
- Xextern errors;
- X
- Xyyerror(char *fmt ELLIPSIS)
- X{
- X va_list ap;
- X
- X printf("%s %d: ", spec_fname, lex_lineno);
- X va_start(ap, fmt);
- X vprintf(fmt, ap);
- X puts("");
- X va_end(ap);
- X errors++;
- X return 0;
- X}
- X
- X
- X
- X
- XRecord *GetRecord(name)
- Xchar *name;
- X{
- X int i;
- X
- X for( i=0; i<dbd.header.records; i++ )
- X if( !strcmp(dbd.record[i].name, name) )
- X return &dbd.record[i];
- X
- X yyerror("unknown record '%s'", name);
- X exit(1);
- X return NULL;
- X}
- X
- X
- X
- XField *GetField(str, name)
- XStructdef *str;
- Xchar *name;
- X{
- X Field *fld = &dbd.field[str->first_member];
- X int n = str->members;
- X
- X while( n )
- X {
- X if( fld->nesting == cur_nest )
- X {
- X if( !strcmp(fld->name, name) )
- X {
- X fld->type |= FT_INCLUDE;
- X return fld;
- X }
- X n--;
- X }
- X fld++;
- X }
- X
- X yyerror("'%s' is not a member of '%s'", name, str->name);
- X exit(1);
- X return NULL;
- X}
- X
- X
- XStructdef *GetStruct(str, name)
- XStructdef *str;
- Xchar *name;
- X{
- X Field *fld;
- X Structdef *struc;
- X
- X if( !(fld = GetField(str, name)) ||
- X FT_GETBASIC(fld->type) != FT_STRUCT )
- X return NULL;
- X
- X struc = &dbd.structdef[fld->structid];
- X
- X /* If the structure is a union the control field must also have been
- X * specified
- X */
- X if( struc->is_union )
- X {
- X if( !(dbd.field[struc->control_field].type & FT_INCLUDE) )
- X {
- X yyerror("The control field of the union '%s' is not included",
- X name);
- X exit(1);
- X }
- X }
- X
- X return struc;
- X}
- X
- X/* end-of-file */
- X
- END_OF_FILE
- if test 4986 -ne `wc -c <'typhoon/src/util/exp.y'`; then
- echo shar: \"'typhoon/src/util/exp.y'\" unpacked with wrong size!
- fi
- # end of 'typhoon/src/util/exp.y'
- fi
- if test -f 'typhoon/src/util/expspec.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'typhoon/src/util/expspec.c'\"
- else
- echo shar: Extracting \"'typhoon/src/util/expspec.c'\" \(4624 characters\)
- sed "s/^X//" >'typhoon/src/util/expspec.c' <<'END_OF_FILE'
- X/*----------------------------------------------------------------------------
- X * File : expspec.c
- X * Program : tyexport
- X * OS : UNIX, OS/2, DOS
- X * Author : Thomas B. Pedersen
- X *
- X * Copyright (c) 1994 Thomas B. Pedersen. All rights reserved.
- X *
- X * Permission is hereby granted, without written agreement and without
- X * license or royalty fees, to use, copy, modify, and distribute this
- X * software and its documentation for any purpose, provided that the above
- X * copyright notice and the following two paragraphs appear (1) in all
- X * source copies of this software and (2) in accompanying documentation
- X * wherever the programatic interface of this software, or any derivative
- X * of it, is described.
- X *
- X * IN NO EVENT SHALL THOMAS B. PEDERSEN BE LIABLE TO ANY PARTY FOR DIRECT,
- X * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF
- X * THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF HE HAS BEEN
- X * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- X *
- X * THOMAS B. PEDERSEN SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT
- X * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- X * A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS"
- X * BASIS, AND THOMAS B. PEDERSEN HAS NO OBLIGATION TO PROVIDE MAINTENANCE,
- X * SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
- X *
- X * Description:
- X * Functions for reading and generating the specification.
- X *
- X * $Log: expspec.c,v $
- X * Revision 1.2 1994/09/17 16:00:53 tbp
- X * typhoon.h and environ.h are now included from <>.
- X *
- X * Revision 1.1 1994/09/13 21:28:56 tbp
- X * Added to repository.
- X *
- X * Added to repository.
- X *
- X *
- X *--------------------------------------------------------------------------*/
- X
- Xstatic char rcsid[] = "$Id: expspec.c,v 1.2 1994/09/17 16:00:53 tbp Exp $";
- X
- X#include <stdio.h>
- X#include <typhoon.h>
- X#include "../ty_dbd.h"
- X#include "../ty_type.h"
- X#include "export.h"
- X
- X
- X/*-------------------------- Function prototypes ---------------------------*/
- Xstatic void Indent PRM( (int); )
- Xstatic int PrintFields PRM( (Structdef *, int); )
- X
- X
- X/*---------------------------- Global variables ----------------------------*/
- Xstatic FILE *outfile;
- Xextern FILE *lex_file;
- X
- X
- X
- X/*----------------------------- ReadExportSpec -----------------------------*\
- X *
- X * Purpose : This function reads an export specification.
- X *
- X * Parameters: exportspec_fname - Output file name.
- X *
- X * Returns : Nothing.
- X *
- X */
- Xvoid ReadExportSpec(dbname)
- Xchar *dbname;
- X{
- X int i;
- X char exportspec_fname[256];
- X
- X sprintf(exportspec_fname, "%s.exp", dbname);
- X
- X if( !(lex_file = fopen(exportspec_fname, "r")) )
- X err_quit("Cannot open '%s'", exportspec_fname);
- X
- X yyparse();
- X
- X fclose(outfile);
- X}
- X
- X
- Xstatic void Indent(level)
- Xint level;
- X{
- X fprintf(outfile, "%*s", (level+2) * 4, "");
- X}
- X
- X
- Xstatic PrintFields(str, nest)
- XStructdef *str;
- Xint nest;
- X{
- X Field *fld = dbd.field + str->first_member;
- X int fields = str->members;
- X int old_fields = fields;
- X int rc;
- X
- X while( fields-- )
- X {
- X if( FT_GETBASIC(fld->type) == FT_STRUCT )
- X {
- X Structdef *struc = dbd.structdef + fld->structid;
- X
- X Indent(nest);
- X fprintf(outfile, "%s %s {\n", struc->is_union ? "union" : "struct", fld->name);
- X rc = PrintFields(struc, nest+1);
- X Indent(nest);
- X fprintf(outfile, "};\n");
- X old_fields += rc;
- X fld += rc;
- X }
- X else if( fld->nesting == nest )
- X {
- X Indent(nest);
- X fprintf(outfile, "%s;\n", fld->name);
- X }
- X
- X fld++;
- X }
- X
- X return old_fields;
- X}
- X
- X
- X
- X
- X/*--------------------------- GenerateExportSpec ---------------------------*\
- X *
- X * Purpose : This function automatically generates a full export
- X * specification.
- X *
- X * Parameters: exprotspec_fname - Output file name.
- X *
- X * Returns : Nothing.
- X *
- X */
- Xvoid GenerateExportSpec(dbname)
- Xchar *dbname;
- X{
- X char exportspec_fname[256];
- X int i;
- X Record *rec = dbd.record;
- X
- X printf("Generating export specification...");
- X fflush(stdout);
- X
- X sprintf(exportspec_fname, "%s.exp", dbname);
- X
- X if( !(outfile = fopen(exportspec_fname, "w")) )
- X err_quit("Cannot write to '%s'", exportspec_fname);
- X
- X fprintf(outfile, "export %s {\n\n", dbname);
- X
- X for( i=0; i<dbd.header.records; i++, rec++ )
- X {
- X fprintf(outfile, " record %s in \"%.8s.kom\" {\n", rec->name, rec->name);
- X
- X PrintFields(&dbd.structdef[rec->structid], 0);
- X
- X fprintf(outfile, " }\n\n");
- X }
- X
- X fprintf(outfile, "}\n");
- X fclose(outfile);
- X
- X puts("done");
- X}
- X
- X/* end-of-file */
- END_OF_FILE
- if test 4624 -ne `wc -c <'typhoon/src/util/expspec.c'`; then
- echo shar: \"'typhoon/src/util/expspec.c'\" unpacked with wrong size!
- fi
- # end of 'typhoon/src/util/expspec.c'
- fi
- if test -f 'typhoon/src/util/impspec.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'typhoon/src/util/impspec.c'\"
- else
- echo shar: Extracting \"'typhoon/src/util/impspec.c'\" \(4630 characters\)
- sed "s/^X//" >'typhoon/src/util/impspec.c' <<'END_OF_FILE'
- X/*----------------------------------------------------------------------------
- X * File : impspec.c
- X * Program : tyimport
- X * OS : UNIX, OS/2, DOS
- X * Author : Thomas B. Pedersen
- X *
- X * Copyright (c) 1994 Thomas B. Pedersen. All rights reserved.
- X *
- X * Permission is hereby granted, without written agreement and without
- X * license or royalty fees, to use, copy, modify, and distribute this
- X * software and its documentation for any purpose, provided that the above
- X * copyright notice and the following two paragraphs appear (1) in all
- X * source copies of this software and (2) in accompanying documentation
- X * wherever the programatic interface of this software, or any derivative
- X * of it, is described.
- X *
- X * IN NO EVENT SHALL THOMAS B. PEDERSEN BE LIABLE TO ANY PARTY FOR DIRECT,
- X * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF
- X * THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF HE HAS BEEN
- X * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- X *
- X * THOMAS B. PEDERSEN SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT
- X * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- X * A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS"
- X * BASIS, AND THOMAS B. PEDERSEN HAS NO OBLIGATION TO PROVIDE MAINTENANCE,
- X * SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
- X *
- X * Description:
- X * Functions for reading and generating the specification.
- X *
- X * $Log: impspec.c,v $
- X * Revision 1.2 1994/09/17 16:00:56 tbp
- X * typhoon.h and environ.h are now included from <>.
- X *
- X * Revision 1.1 1994/09/13 21:28:59 tbp
- X * Added to repository.
- X *
- X * Added to repository.
- X *
- X *
- X *--------------------------------------------------------------------------*/
- X
- Xstatic char rcsid[] = "$Id: impspec.c,v 1.2 1994/09/17 16:00:56 tbp Exp $";
- X
- X#include <stdio.h>
- X#include <typhoon.h>
- X#include "../ty_dbd.h"
- X#include "../ty_type.h"
- X#include "import.h"
- X
- X
- X/*-------------------------- Function prototypes ---------------------------*/
- Xstatic void Indent PRM( (int); )
- Xstatic int PrintFields PRM( (Structdef *, int); )
- X
- X
- X/*---------------------------- Global variables ----------------------------*/
- Xstatic FILE *outfile;
- Xextern FILE *lex_file;
- X
- X/*----------------------------- ReadImportSpec -----------------------------*\
- X *
- X * Purpose : This function reads an import specification.
- X *
- X * Parameters: importspec_fname - Output file name.
- X *
- X * Returns : Nothing.
- X *
- X */
- Xvoid ReadImportSpec(dbname)
- Xchar *dbname;
- X{
- X int i;
- X char importspec_fname[256];
- X
- X sprintf(importspec_fname, "%s.imp", dbname);
- X
- X if( !(lex_file = fopen(importspec_fname, "r")) )
- X err_quit("Cannot open '%s'", importspec_fname);
- X
- X yyparse();
- X
- X fclose(outfile);
- X}
- X
- X
- X
- Xstatic void Indent(level)
- Xint level;
- X{
- X fprintf(outfile, "%*s", (level+2) * 4, "");
- X}
- X
- X
- Xstatic PrintFields(str, nest)
- XStructdef *str;
- Xint nest;
- X{
- X Field *fld = dbd.field + str->first_member;
- X int fields = str->members;
- X int old_fields = fields;
- X int rc;
- X
- X while( fields-- )
- X {
- X if( FT_GETBASIC(fld->type) == FT_STRUCT )
- X {
- X Structdef *struc = dbd.structdef + fld->structid;
- X
- X Indent(nest);
- X fprintf(outfile, "%s %s {\n",
- X struc->is_union ? "union" : "struct", fld->name);
- X rc = PrintFields(struc, nest+1);
- X Indent(nest);
- X fprintf(outfile, "};\n");
- X old_fields += rc;
- X fld += rc;
- X }
- X else if( fld->nesting == nest )
- X {
- X Indent(nest);
- X fprintf(outfile, "%s;\n", fld->name);
- X }
- X
- X fld++;
- X }
- X
- X return old_fields;
- X}
- X
- X
- X
- X
- X/*--------------------------- GenerateImportSpec ---------------------------*\
- X *
- X * Purpose : This function automatically generates a full import
- X * specification.
- X *
- X * Parameters: improtspec_fname - Output file name.
- X *
- X * Returns : Nothing.
- X *
- X */
- Xvoid GenerateImportSpec(dbname)
- Xchar *dbname;
- X{
- X char importspec_fname[256];
- X int i;
- X Record *rec = dbd.record;
- X
- X printf("Generating import specification...");
- X fflush(stdout);
- X
- X sprintf(importspec_fname, "%s.imp", dbname);
- X
- X if( !(outfile = fopen(importspec_fname, "w")) )
- X err_quit("Cannot write to '%s'", importspec_fname);
- X
- X fprintf(outfile, "import %s {\n\n", dbname);
- X
- X for( i=0; i<dbd.header.records; i++, rec++ )
- X {
- X fprintf(outfile, " record %s in \"%.8s.kom\" {\n", rec->name, rec->name);
- X
- X PrintFields(&dbd.structdef[rec->structid], 0);
- X
- X fprintf(outfile, " }\n\n");
- X }
- X
- X fprintf(outfile, "}\n");
- X fclose(outfile);
- X
- X puts("done");
- X}
- X
- X/* end-of-file */
- END_OF_FILE
- if test 4630 -ne `wc -c <'typhoon/src/util/impspec.c'`; then
- echo shar: \"'typhoon/src/util/impspec.c'\" unpacked with wrong size!
- fi
- # end of 'typhoon/src/util/impspec.c'
- fi
- echo shar: End of archive 6 \(of 9\).
- cp /dev/null ark6isdone
- MISSING=""
- for I in 1 2 3 4 5 6 7 8 9 ; do
- if test ! -f ark${I}isdone ; then
- MISSING="${MISSING} ${I}"
- fi
- done
- if test "${MISSING}" = "" ; then
- echo You have unpacked all 9 archives.
- rm -f ark[1-9]isdone ark[1-9][0-9]isdone
- else
- echo You still must unpack the following archives:
- echo " " ${MISSING}
- fi
- exit 0
- exit 0 # Just in case...
-