home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume44 / typhoon / part06 < prev    next >
Encoding:
Internet Message Format  |  1994-09-17  |  60.3 KB

  1. From: zeppelin@login.dknet.dk (Thomas B. Pedersen)
  2. Newsgroups: comp.sources.misc
  3. Subject: v44i062:  typhoon - Typhoon Relational Database Management System, Part06/09
  4. Date: 17 Sep 1994 21:45:44 -0500
  5. Organization: Sterling Software
  6. Sender: kent@sparky.sterling.com
  7. Approved: kent@sparky.sterling.com
  8. Message-ID: <35g9ko$oip@sparky.sterling.com>
  9. X-Md4-Signature: e908d2704b5a798817dd9a3cf6ae0dec
  10.  
  11. Submitted-by: zeppelin@login.dknet.dk (Thomas B. Pedersen)
  12. Posting-number: Volume 44, Issue 62
  13. Archive-name: typhoon/part06
  14. Environment: SCO UNIX, Tandem NonStop UNIX, Sun Solaris, AIX, Linux, OS/2
  15.  
  16. #! /bin/sh
  17. # This is a shell archive.  Remove anything before this line, then feed it
  18. # into a shell via "sh file" or similar.  To overwrite existing files,
  19. # type "sh file -c".
  20. # Contents:  typhoon/examples/demo.c typhoon/src/btree.h
  21. #   typhoon/src/cmpfuncs.c typhoon/src/h/typhoon.h
  22. #   typhoon/src/ty_repif.h typhoon/src/ty_repl.c typhoon/src/ty_util.c
  23. #   typhoon/src/util/exp.y typhoon/src/util/expspec.c
  24. #   typhoon/src/util/impspec.c
  25. # Wrapped by kent@sparky on Sat Sep 17 21:38:17 1994
  26. PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin:$PATH ; export PATH
  27. echo If this archive is complete, you will see the following message:
  28. echo '          "shar: End of archive 6 (of 9)."'
  29. if test -f 'typhoon/examples/demo.c' -a "${1}" != "-c" ; then 
  30.   echo shar: Will not clobber existing file \"'typhoon/examples/demo.c'\"
  31. else
  32.   echo shar: Extracting \"'typhoon/examples/demo.c'\" \(5303 characters\)
  33.   sed "s/^X//" >'typhoon/examples/demo.c' <<'END_OF_FILE'
  34. X/*----------------------------------------------------------------------------
  35. X * File    : demo.c
  36. X * OS      : UNIX
  37. X * Author  : Thomas B. Pedersen
  38. X *
  39. X * Copyright (c) 1994 Thomas B. Pedersen.  All rights reserved.
  40. X *
  41. X * Permission is hereby granted, without written agreement and without
  42. X * license or royalty fees, to use, copy, modify, and distribute this
  43. X * software and its documentation for any purpose, provided that the above
  44. X * copyright notice and the following two  paragraphs appear (1) in all 
  45. X * source copies of this software and (2) in accompanying documentation
  46. X * wherever the programatic interface of this software, or any derivative
  47. X * of it, is described.
  48. X *
  49. X * IN NO EVENT SHALL THOMAS B. PEDERSEN BE LIABLE TO ANY PARTY FOR DIRECT,
  50. X * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF
  51. X * THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF HE HAS BEEN 
  52. X * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  53. X *
  54. X * THOMAS B. PEDERSEN SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT
  55. X * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  56. X * A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" 
  57. X * BASIS, AND THOMAS B. PEDERSEN HAS NO OBLIGATION TO PROVIDE MAINTENANCE,
  58. X * SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  59. X *
  60. X * Description:
  61. X *   A small program that demonstrates some of the features of API.
  62. X *
  63. X * $Log: demo.c,v $
  64. X * Revision 1.2  1994/09/17  16:17:46  tbp
  65. X * typhoon.h is now included from <>.
  66. X *
  67. X * Revision 1.1  1994/09/13  21:29:45  tbp
  68. X * Added to repository.
  69. X *
  70. X * Added to repository.
  71. X * 
  72. X *
  73. X *--------------------------------------------------------------------------*/
  74. X
  75. Xstatic char rcsid[] = "$Id: demo.c,v 1.2 1994/09/17 16:17:46 tbp Exp $";
  76. X
  77. X#include <stdio.h>
  78. X#include <ctype.h>
  79. X#include <typhoon.h>
  80. X#include "demo.h"
  81. X
  82. Xtypedef enum {
  83. X    SHORT,
  84. X    INT,
  85. X    LONG,
  86. X    STRING
  87. X} field_type;
  88. X
  89. X
  90. Xmenu(options)
  91. Xchar *options;
  92. X{
  93. X    char s[10];
  94. X
  95. X    printf("%s: ", options);
  96. X    fflush(stdout);
  97. X    gets(s);
  98. X    
  99. X    return tolower(s[0]);
  100. X}
  101. X
  102. X
  103. Xvoid getfield(name, type, var)
  104. Xchar *name;
  105. Xfield_type type;
  106. Xvoid *var;
  107. X{
  108. X    char s[2048];
  109. X        
  110. X    printf("%s: ", name);
  111. X    fflush(stdout);
  112. X    gets(s);
  113. X    
  114. X    switch( type )
  115. X    {
  116. X        case SHORT:
  117. X            *(short *)var = atoi(s);
  118. X            break;
  119. X        case INT:
  120. X            *(int *)var = atoi(s);
  121. X            break;
  122. X        case LONG:
  123. X            *(long *)var = atol(s);
  124. X            break;
  125. X        case STRING:
  126. X            strcpy((char *)var, s);
  127. X            break;
  128. X    }
  129. X}
  130. X
  131. X
  132. Xvoid report(s)
  133. Xchar *s;
  134. X{
  135. X    printf("%s - db_status %d\n", s, db_status);
  136. X}
  137. X
  138. X
  139. Xvoid print_company(company)
  140. Xstruct company *company;
  141. X{
  142. X    printf("[id=%lu, name='%s']\n", company->id, company->name);
  143. X}
  144. X
  145. X
  146. Xvoid print_product(product)
  147. Xstruct product *product;
  148. X{
  149. X    printf("[company_id=%lu, name='%s', description='%s']\n",
  150. X        product->company_id,
  151. X        product->name,
  152. X        product->description);
  153. X}
  154. X
  155. X
  156. Xvoid find_menu()
  157. X{
  158. X    struct product product;
  159. X    struct company company;
  160. X    int stop = 0;
  161. X    int key = ID;
  162. X    int listall = 0;
  163. X
  164. X    while( !stop )
  165. X    {
  166. X        switch( menu("First  Last  Prev  Next  Delete  "
  167. X                     "Search  list All  Back") )    
  168. X        {
  169. X            case 'a':
  170. X                d_keyfrst(key);
  171. X                
  172. X                listall = 1;
  173. X                break;
  174. X            case 'f':
  175. X                d_keyfrst(key);
  176. X                break;
  177. X            case 'l':
  178. X                d_keylast(key);
  179. X                break;
  180. X            case 'p':
  181. X                d_keyprev(key);
  182. X                break;
  183. X            case 'n':
  184. X                d_keynext(key);
  185. X                break;
  186. X            case 's':
  187. X                switch( menu("Company  Product") )    
  188. X                {
  189. X                    case 'c':
  190. X                        getfield("Id", LONG,  &company.id);
  191. X                        d_keyfind(ID, &company.id);
  192. X                        key = ID;
  193. X                        break;
  194. X                    case 'p':
  195. X                        key = PRODUCT_NAME;
  196. X                        getfield("Name", STRING,  product.name);
  197. X                        d_keyfind(PRODUCT_NAME, product.name);
  198. X                        break;
  199. X                    default:
  200. X                        continue;
  201. X                }
  202. X                break;
  203. X            case 'd':
  204. X                if( db_status == S_OKAY )
  205. X                    if( d_delete() == S_OKAY )
  206. X                        puts("Deleted.");
  207. X                    else
  208. X                        report("Could not delete");
  209. X                continue;
  210. X            case 'b':
  211. X                stop++;
  212. X            default:
  213. X                continue;
  214. X        }
  215. X
  216. X        if( db_status == S_OKAY )
  217. X        {
  218. X            while( listall && db_status == S_OKAY )
  219. X            {
  220. X                switch( key )
  221. X                {
  222. X                    case ID:
  223. X                        d_recread(&company);
  224. X                        print_company(&company);
  225. X                        break;
  226. X                    case PRODUCT_NAME:
  227. X                        d_recread(&product);
  228. X                        print_product(&product);
  229. X                        break;
  230. X                }
  231. X
  232. X                if( listall )
  233. X                    d_keynext(key);
  234. X            }
  235. X        }            
  236. X        else
  237. X            puts("Not found");
  238. X
  239. X        listall = 0;
  240. X    }        
  241. X}
  242. X
  243. X
  244. X
  245. Xvoid create_menu()
  246. X{
  247. X    struct product product;
  248. X    struct company company ;
  249. X    int stop = 0;
  250. X    
  251. X    while( !stop )
  252. X    {
  253. X        switch( menu("Company  Product  Back") )    
  254. X        {
  255. X            case 'c':
  256. X                getfield("Id  ", LONG,  &company.id);
  257. X                getfield("Name", STRING, company.name);
  258. X                if( d_fillnew(COMPANY, &company) != S_OKAY )
  259. X                    report("Could not create company");
  260. X                break;
  261. X            case 'p':
  262. X                getfield("Company id  ", LONG,  &product.company_id);
  263. X                getfield("Product name", STRING, product.name);
  264. X                getfield("Description ", STRING, product.description);
  265. X                if( d_fillnew(PRODUCT, &product) != S_OKAY )
  266. X                    report("Could not create product");
  267. X                break;
  268. X            case 'b':
  269. X                stop++;
  270. X        }
  271. X    }            
  272. X}
  273. X
  274. X
  275. Xvoid main()
  276. X{
  277. X    int stop = 0;
  278. X    
  279. X    mkdir("data", 0777);
  280. X
  281. X    d_dbfpath("data");
  282. X    if( d_open("demo", "s") != S_OKAY )
  283. X    {
  284. X        fprintf(stderr, "Cannot open database (db_status %d)\n", db_status);
  285. X        exit(1);
  286. X    }
  287. X
  288. X    while( !stop )
  289. X    {
  290. X        switch( menu("Create  Find  Delete  Quit") )
  291. X        {
  292. X            case 'c':    create_menu();    break;
  293. X            case 'f':    find_menu();    break;
  294. X            case 'q':    stop++;
  295. X        }
  296. X    }
  297. X
  298. X    d_close();
  299. X}
  300. X
  301. X/* end-of-file */
  302. X
  303. END_OF_FILE
  304.   if test 5303 -ne `wc -c <'typhoon/examples/demo.c'`; then
  305.     echo shar: \"'typhoon/examples/demo.c'\" unpacked with wrong size!
  306.   fi
  307.   # end of 'typhoon/examples/demo.c'
  308. fi
  309. if test -f 'typhoon/src/btree.h' -a "${1}" != "-c" ; then 
  310.   echo shar: Will not clobber existing file \"'typhoon/src/btree.h'\"
  311. else
  312.   echo shar: Extracting \"'typhoon/src/btree.h'\" \(4959 characters\)
  313.   sed "s/^X//" >'typhoon/src/btree.h' <<'END_OF_FILE'
  314. X/*----------------------------------------------------------------------------
  315. X * File    : btree.h
  316. X * Library : typhoon
  317. X * OS      : UNIX, OS/2, DOS
  318. X * Author  : Thomas B. Pedersen
  319. X *
  320. X * Copyright (c) 1994 Thomas B. Pedersen.  All rights reserved.
  321. X *
  322. X * Permission is hereby granted, without written agreement and without
  323. X * license or royalty fees, to use, copy, modify, and distribute this
  324. X * software and its documentation for any purpose, provided that the above
  325. X * copyright notice and the following two  paragraphs appear (1) in all 
  326. X * source copies of this software and (2) in accompanying documentation
  327. X * wherever the programatic interface of this software, or any derivative
  328. X * of it, is described.
  329. X *
  330. X * IN NO EVENT SHALL THOMAS B. PEDERSEN BE LIABLE TO ANY PARTY FOR DIRECT,
  331. X * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF
  332. X * THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF HE HAS BEEN 
  333. X * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  334. X *
  335. X * THOMAS B. PEDERSEN SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT
  336. X * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  337. X * A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" 
  338. X * BASIS, AND THOMAS B. PEDERSEN HAS NO OBLIGATION TO PROVIDE MAINTENANCE,
  339. X * SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  340. X *
  341. X * Description:
  342. X *   Contains miscellaneous constants and macros used by B-tree functions.
  343. X *
  344. X * $Id: btree.h,v 1.1 1994/09/13 21:28:29 tbp Exp $
  345. X *
  346. X * $Log: btree.h,v $
  347. X * Revision 1.1  1994/09/13  21:28:29  tbp
  348. X * Added to repository.
  349. X * 
  350. X *
  351. X *--------------------------------------------------------------------------*/
  352. X
  353. X
  354. X/*--------------------------------------------------------------------------*/
  355. X/*                      miscellaneous constants                             */
  356. X/*--------------------------------------------------------------------------*/
  357. X#define KEYVERSION_ID    "KeyMan121"        /* Version ID                        */
  358. X#define KEYVERSION_NUM    121                /* Version number                    */
  359. X
  360. X#define NEWPOS          (ix_addr)-1        /* Indicates new pos for nodewrite    */
  361. X#define ROOT            1                /* Root is always node 1            */
  362. X
  363. Xtypedef ix_addr A_type;         /* node address type                        */
  364. Xtypedef long R_type;            /* record reference type                    */
  365. X#ifdef RISC
  366. Xtypedef long N_type;
  367. X#else
  368. Xtypedef short N_type;
  369. X#endif
  370. X
  371. X
  372. X/*
  373. X * The format of a node is illustrated below. <n> is the number of tuples in
  374. X * the node. We call the set [A,K,R] a tuple, since the reference is considered
  375. X * a part of the key.
  376. X *
  377. X *  +---+----+--------+----+----+--------+----+-- - -+------+---------+------+
  378. X *  | n ! A0 |   K0   | R0 | A1 |   K1   | R1 |      | An-1 |  Kn-1   | Rn-1 |
  379. X *  +---+----+--------+----+----+--------+----+-- - -+------+---------+------+
  380. X *
  381. X */
  382. X
  383. X/*
  384. X * The following macros are used to easily access the elements of a node. The
  385. X * macros KEY, CHILD and REF assume that a variable <I->node> points to the
  386. X * node operated on.
  387. X */
  388. X
  389. X#define NSIZE(N)    (*(N_type *)(N))
  390. X#define KEY(N,i)    (void   *)  (N+sizeof(N_type)+sizeof(A_type) + \
  391. X                    I->tsize * (i))
  392. X#define CHILD(N,i)  (*(A_type *)(N+sizeof(N_type) + I->tsize * (i)))
  393. X#define REF(N,i)    (*(R_type *) (N+sizeof(N_type)+sizeof(A_type) + \
  394. X                    I->aligned_keysize + I->tsize * (i)))
  395. X
  396. X
  397. X
  398. X/*
  399. X * The following macros are used to insert, delete and copy tuples in nodes.
  400. X *
  401. X * tupledel(N,i)            - Delete the i'th tuple of the node N.
  402. X * tupleins(N,i,n)            - Insert the tuple n in the i'th position in the
  403. X *                              node N.
  404. X * tuplecopy(N1,i1,N2,i2,n) - Copy n tuples starting from the i2'th position
  405. X *                              of node N2 to the i1'th position of the node N1.
  406. X * nodecopy(N1,N2)            - Copy node N2 to node N1.
  407. X * keycopy(N1,i1,N2,i2)        - Copy the i2'th key of node N2 to the i1'th key
  408. X *                              of N1.
  409. X */
  410. X
  411. X#define tupledel(N,i)            memmove(&CHILD(N,i), &CHILD(N,(i)+1), \
  412. X                                I->tsize * (NSIZE(N) - (i) - 1) + sizeof(A_type))
  413. X#define tupleins(N,i,n)         memmove(&CHILD(N,(i)+n), &CHILD(N,i), \
  414. X                                I->tsize * (NSIZE(N) - (i)) + sizeof(A_type))
  415. X#define tuplecopy(N1,i1,N2,i2,n)memcpy(&CHILD(N1,i1), &CHILD(N2,i2), I->tsize*(n))
  416. X#define nodecopy(N1,N2)            memcpy(N1, N2, sizeof(N_type) + sizeof(A_type) \
  417. X                                + (I->tsize * NSIZE(N2)))
  418. X#define keycopy(N1,i1,N2,i2)    memcpy(KEY(N1,i1),KEY(N2,i2),I->aligned_keysize + sizeof(R_type))
  419. X
  420. X
  421. X/*--------------------------------- bt_open --------------------------------*/
  422. Xvoid    db_keygetheader    PRM( (INDEX *);                                    )
  423. Xvoid    db_keyputheader    PRM( (INDEX *);                                    )
  424. Xint        nodesearch        PRM( (INDEX *, void *, int *);                    )
  425. Xint        d_search        PRM( (INDEX *, void *, ix_addr *, int *);        )
  426. X
  427. X/*--------------------------------- bt_io.c --------------------------------*/
  428. Xix_addr noderead        PRM( (INDEX *, char *, ix_addr);                )
  429. Xix_addr nodewrite       PRM( (INDEX *, char *, ix_addr);                )
  430. Xvoid    cache_clear     PRM( (INDEX *);                                 )
  431. X
  432. X
  433. X/* end-of-file */
  434. END_OF_FILE
  435.   if test 4959 -ne `wc -c <'typhoon/src/btree.h'`; then
  436.     echo shar: \"'typhoon/src/btree.h'\" unpacked with wrong size!
  437.   fi
  438.   # end of 'typhoon/src/btree.h'
  439. fi
  440. if test -f 'typhoon/src/cmpfuncs.c' -a "${1}" != "-c" ; then 
  441.   echo shar: Will not clobber existing file \"'typhoon/src/cmpfuncs.c'\"
  442. else
  443.   echo shar: Extracting \"'typhoon/src/cmpfuncs.c'\" \(5944 characters\)
  444.   sed "s/^X//" >'typhoon/src/cmpfuncs.c' <<'END_OF_FILE'
  445. X/*----------------------------------------------------------------------------
  446. X * File    : cmpfuncs.c
  447. X * Library : typhoon
  448. X * OS      : UNIX, OS/2, DOS
  449. X * Author  : Thomas B. Pedersen
  450. X *
  451. X * Copyright (c) 1994 Thomas B. Pedersen.  All rights reserved.
  452. X *
  453. X * Permission is hereby granted, without written agreement and without
  454. X * license or royalty fees, to use, copy, modify, and distribute this
  455. X * software and its documentation for any purpose, provided that the above
  456. X * copyright notice and the following two  paragraphs appear (1) in all 
  457. X * source copies of this software and (2) in accompanying documentation
  458. X * wherever the programatic interface of this software, or any derivative
  459. X * of it, is described.
  460. X *
  461. X * IN NO EVENT SHALL THOMAS B. PEDERSEN BE LIABLE TO ANY PARTY FOR DIRECT,
  462. X * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF
  463. X * THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF HE HAS BEEN 
  464. X * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  465. X *
  466. X * THOMAS B. PEDERSEN SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT
  467. X * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  468. X * A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" 
  469. X * BASIS, AND THOMAS B. PEDERSEN HAS NO OBLIGATION TO PROVIDE MAINTENANCE,
  470. X * SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  471. X *
  472. X * Description:
  473. X *   Contains comparison functions for all the key types supported by
  474. X *   Typhoon as well as compound keys.
  475. X *
  476. X * Functions:
  477. X *   ucharcmp(a,b)        - Compare two unsigned chars.
  478. X *   charcmp(a, b)        - Compare two chars.
  479. X *   ustrcmp(s1, s2)    - Compare two unsigned char strings.
  480. X *   shortcmp(a,b)        - Compare two shorts.
  481. X *   intcmp(a,b)        - Compare two ints.
  482. X *   longcmp(a,b)        - Compare two longs.
  483. X *   floatcmp(a,b)        - Compare two floats.
  484. X *   doublecmp(a,b)        - Compare two doubles.
  485. X *   ushortcmp(a,b)        - Compare two unsigned shorts.
  486. X *   uintcmp(a,b)        - Compare two unsigned ints.
  487. X *   ulongcmp(a,b)        - Compare two unsigned longs.
  488. X *   compoundkeycmp(a,b)- Compare two compound keys.
  489. X *   refentrycmp(a,b)    - Compare two REF_ENTRY items.
  490. X *
  491. X * $Log: cmpfuncs.c,v $
  492. X * Revision 1.2  1994/09/17  16:00:13  tbp
  493. X * typhoon.h and environ.h are now included from <>.
  494. X *
  495. X * Revision 1.1  1994/09/13  21:28:30  tbp
  496. X * Added to repository.
  497. X * 
  498. X *
  499. X *--------------------------------------------------------------------------*/
  500. X
  501. Xstatic char rcsid[] = "$Id: cmpfuncs.c,v 1.2 1994/09/17 16:00:13 tbp Exp $";
  502. X
  503. X#include <string.h>
  504. X#include <stdio.h>
  505. X#include <typhoon.h>
  506. X#include <ctype.h>
  507. X#include "ty_dbd.h"
  508. X#include "ty_type.h"
  509. X#include "ty_glob.h"
  510. X#include "ty_prot.h"
  511. X
  512. X#define CMP            return *a > *b ? 1 : *a < *b ? -1 : 0
  513. X
  514. X
  515. X/*--------------------------- Function prototypes --------------------------*/
  516. Xstatic int charcmp        PRM( (char *, char *); )
  517. Xstatic int shortcmp        PRM( (short *, short *); )
  518. Xstatic int intcmp        PRM( (int *, int *); )
  519. Xstatic int longcmp        PRM( (long *, long *); )
  520. Xstatic int ucharcmp    PRM( (uchar *, uchar *); )
  521. Xstatic int ushortcmp    PRM( (ushort *, ushort *); )
  522. Xstatic int uintcmp        PRM( (unsigned *, unsigned *); )
  523. Xstatic int ulongcmp        PRM( (ulong *, ulong *); )
  524. Xstatic int ustrcmp        PRM( (uchar *, uchar *); )
  525. Xstatic int floatcmp        PRM( (float *, float *); )
  526. Xstatic int doublecmp    PRM( (double *, double *); )
  527. X       int refentrycmp    PRM( (REF_ENTRY *, REF_ENTRY *); )
  528. X
  529. X
  530. XCMPFUNC keycmp[] = {
  531. X    NULL,
  532. X    (CMPFUNC)charcmp,
  533. X    (CMPFUNC)ustrcmp,            /* This should be strcmp, I think...        */
  534. X    (CMPFUNC)shortcmp,
  535. X    (CMPFUNC)intcmp,
  536. X    (CMPFUNC)longcmp,
  537. X    (CMPFUNC)floatcmp,
  538. X    (CMPFUNC)doublecmp,
  539. X    NULL,
  540. X    (CMPFUNC)refentrycmp,
  541. X    NULL,
  542. X    NULL,
  543. X    NULL,
  544. X    NULL,
  545. X    NULL,
  546. X    NULL,
  547. X    NULL,
  548. X    (CMPFUNC)ucharcmp,
  549. X    (CMPFUNC)ustrcmp,
  550. X    (CMPFUNC)ushortcmp,
  551. X    (CMPFUNC)uintcmp,
  552. X    (CMPFUNC)ulongcmp
  553. X};
  554. X
  555. X
  556. Xstatic charcmp(a, b)
  557. Xchar *a, *b;
  558. X{
  559. X    CMP;
  560. X}
  561. X
  562. X
  563. Xstatic ucharcmp(a, b)
  564. Xuchar *a, *b;
  565. X{
  566. X    CMP;
  567. X}
  568. X
  569. X
  570. Xty_ustrcmp(s1, s2)
  571. Xuchar *s1, *s2;
  572. X{
  573. X    return ustrcmp(s1, s2);
  574. X}
  575. X
  576. Xstatic ustrcmp(s1, s2)
  577. Xuchar *s1, *s2;
  578. X{
  579. X    uchar *sorttable = typhoon.db->header.sorttable;
  580. X
  581. X    while( *s1 )
  582. X    {
  583. X        if( sorttable[*s1] - sorttable[*s2] )
  584. X            break;
  585. X
  586. X        s1++;
  587. X        s2++;
  588. X    }
  589. X
  590. X    return sorttable[*s1] - sorttable[*s2];
  591. X}
  592. X
  593. X
  594. Xstatic shortcmp(a,b)
  595. Xshort *a, *b;
  596. X{
  597. X    CMP;
  598. X}
  599. X
  600. Xstatic intcmp(a,b)
  601. Xint *a, *b;
  602. X{
  603. X    CMP;
  604. X}
  605. X
  606. Xstatic longcmp(a,b)
  607. Xlong *a, *b;
  608. X{
  609. X    CMP;
  610. X}
  611. X
  612. Xstatic floatcmp(a,b)
  613. Xfloat *a, *b;
  614. X{
  615. X    CMP;
  616. X}
  617. X
  618. Xstatic doublecmp(a,b)
  619. Xdouble *a, *b;
  620. X{
  621. X    CMP;
  622. X}
  623. X
  624. Xstatic ushortcmp(a,b)
  625. Xushort *a, *b;
  626. X{
  627. X    CMP;
  628. X}
  629. X
  630. Xstatic uintcmp(a,b)
  631. Xunsigned *a, *b;
  632. X{
  633. X    CMP;
  634. X}
  635. X
  636. Xstatic ulongcmp(a,b)
  637. Xulong *a, *b;
  638. X{
  639. X    CMP;
  640. X}
  641. X
  642. X
  643. X/*----------------------------- compoundkeycmp -----------------------------*\
  644. X *
  645. X * Purpose : This function compares two compound keys. The global variable
  646. X *             <curr_key> is set to the ID of the keys being compared. This
  647. X *             is because the call to the key comparison function in the B-tree
  648. X *             functions only passes two pointers and not the type.
  649. X *
  650. X * Params  : a        - The first key
  651. X *             b        - The second key
  652. X *
  653. X * Returns : < 0    - a < b
  654. X *             0        - a = b
  655. X *             > 0    - a > 0
  656. X *
  657. X */
  658. X
  659. Xcompoundkeycmp(a, b)
  660. Xvoid *a, *b;
  661. X{
  662. X    Key *key        = typhoon.db->key + typhoon.curr_key;
  663. X    KeyField *keyfld= typhoon.db->keyfield + key->first_keyfield;
  664. X    int fields        = key->fields;
  665. X    int type, diff;
  666. X
  667. X    while( fields-- )
  668. X    {
  669. X        type = typhoon.db->field[ keyfld->field ].type & (FT_BASIC|FT_UNSIGNED);
  670. X
  671. X        if( diff = (*keycmp[type])((char *)a + keyfld->offset, (char *)b + keyfld->offset) )
  672. X            break;
  673. X
  674. X        keyfld++;
  675. X    }
  676. X
  677. X    /* If the field is sorted in descending order, invert the sign */
  678. X    if( !keyfld->asc )
  679. X        diff = -diff;
  680. X
  681. X    return diff;
  682. X}
  683. X
  684. X
  685. Xrefentrycmp(a, b)
  686. XREF_ENTRY *a, *b;
  687. X{
  688. X    if( a->parent          > b->parent )              return  1;
  689. X    if( a->parent          < b->parent )              return -1;
  690. X    if( a->dependent.recid > b->dependent.recid )    return  1;
  691. X    if( a->dependent.recid < b->dependent.recid )    return -1;
  692. X    if( a->dependent.recno > b->dependent.recno )    return  1;
  693. X    if( a->dependent.recno < b->dependent.recno )    return -1;
  694. X
  695. X    return 0;
  696. X}
  697. X
  698. X/* end-of-file */
  699. END_OF_FILE
  700.   if test 5944 -ne `wc -c <'typhoon/src/cmpfuncs.c'`; then
  701.     echo shar: \"'typhoon/src/cmpfuncs.c'\" unpacked with wrong size!
  702.   fi
  703.   # end of 'typhoon/src/cmpfuncs.c'
  704. fi
  705. if test -f 'typhoon/src/h/typhoon.h' -a "${1}" != "-c" ; then 
  706.   echo shar: Will not clobber existing file \"'typhoon/src/h/typhoon.h'\"
  707. else
  708.   echo shar: Extracting \"'typhoon/src/h/typhoon.h'\" \(6375 characters\)
  709.   sed "s/^X//" >'typhoon/src/h/typhoon.h' <<'END_OF_FILE'
  710. X/*----------------------------------------------------------------------------
  711. X * File    : typhoon.h
  712. X * Library : typhoon
  713. X * OS      : UNIX, OS/2, DOS
  714. X * Author  : Thomas B. Pedersen
  715. X *
  716. X * Copyright (c) 1994 Thomas B. Pedersen.  All rights reserved.
  717. X *
  718. X * Permission is hereby granted, without written agreement and without
  719. X * license or royalty fees, to use, copy, modify, and distribute this
  720. X * software and its documentation for any purpose, provided that the above
  721. X * copyright notice and the following two  paragraphs appear (1) in all 
  722. X * source copies of this software and (2) in accompanying documentation
  723. X * wherever the programatic interface of this software, or any derivative
  724. X * of it, is described.
  725. X *
  726. X * IN NO EVENT SHALL THOMAS B. PEDERSEN BE LIABLE TO ANY PARTY FOR DIRECT,
  727. X * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF
  728. X * THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF HE HAS BEEN 
  729. X * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  730. X *
  731. X * THOMAS B. PEDERSEN SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT
  732. X * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  733. X * A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" 
  734. X * BASIS, AND THOMAS B. PEDERSEN HAS NO OBLIGATION TO PROVIDE MAINTENANCE,
  735. X * SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  736. X *
  737. X * Description:
  738. X *   Header file for Typhoon library.
  739. X *
  740. X * $Id: typhoon.h,v 1.1 1994/09/17 15:59:13 tbp Exp $
  741. X *
  742. X * $Log: typhoon.h,v $
  743. X * Revision 1.1  1994/09/17  15:59:13  tbp
  744. X * Added to repository.
  745. X *
  746. X *
  747. X *--------------------------------------------------------------------------*/
  748. X
  749. X#ifndef _TYPHOON_INCLUDED
  750. X#define _TYPHOON_INCLUDED
  751. X
  752. X#ifndef _ENVIRON_INCLUDED
  753. X#include <environ.h>
  754. X#endif
  755. X
  756. X/*---------- Status codes --------------------------------------------------*/
  757. X#define S_NOCR                -2        /* No current record                       */
  758. X#define S_NOCD                -1        /* No current database                    */
  759. X
  760. X#define S_OKAY                0        /* Operation successful                 */
  761. X#define S_NOTFOUND            1        /* Key not found                        */
  762. X#define S_DUPLICATE            2        /* Duplicate key found                     */
  763. X#define S_DELETED            3        /* Record is deleted                    */
  764. X#define S_RESTRICT            4        /* Restrict rule encountered(db_subcode)*/
  765. X#define S_FOREIGN            5        /* No foreign key (db_subcode)            */
  766. X#define S_LOCKED            8        /* Record is locked                        */
  767. X#define S_UNLOCKED            9        /* Record is unlocked                    */
  768. X#define S_VERSION            10        /* B-tree or data file has wrong version*/
  769. X#define S_INVPARM            11        /* Invalid parameter                    */
  770. X
  771. X#define S_NOMEM                200        /* Out of memory                        */
  772. X#define S_NOTAVAIL            201        /* Database not available                */
  773. X#define S_IOFATAL            202        /* Fatal I/O operation                    */
  774. X#define S_FATAL                203        /* Fatal error - recover                */
  775. X#define S_MAXCLIENTS        500        /* Too many clients                        */
  776. X#define S_NOSERVER            501        /* No server is installed                */
  777. X
  778. X/*---------- User errors ---------------------------------------------------*/
  779. X#define S_INVDB                1000    /* Invalid database                        */
  780. X#define S_INVREC            1001    /* Invalid record                        */
  781. X#define S_INVFLD            1002    /* Invalid field name                    */
  782. X#define S_NOTKEY            1003    /* Field is not a key                    */
  783. X#define S_RECSIZE           1004    /* Variable length record has invalid sz*/
  784. X#define S_BADTYPE            1005    /* Bad parameter type                    */
  785. X#define S_INVKEY            1006    /* Invalid key                            */
  786. X#define S_INVADDR            1007    /* Invalid database address (rec number)*/
  787. X
  788. X/*---------- Lock types ----------------------------------------------------*/
  789. X#define LOCK_TEST            1        /* Test if a record is locked            */
  790. X#define LOCK_UPDATE            2        /* Lock a record for update                */
  791. X
  792. Xtypedef struct {
  793. X    ulong    recid;
  794. X    ulong    recno;
  795. X} DB_ADDR;
  796. X
  797. Xextern ulong curr_rec;
  798. Xextern int db_status;                    /* See S_... constants                */
  799. Xextern long db_subcode;
  800. X
  801. X#ifdef OS2
  802. X#    ifdef __BORLANDC__
  803. X#        define INCL_NOPMAPI
  804. X#    endif
  805. X#    ifdef __IBMC__
  806. X#        pragma map(db_status,  "_db_status")
  807. X#        pragma map(db_subcode, "_db_subcode")
  808. X#    endif
  809. X#    include <os2def.h>
  810. X#    define CL    APIRET EXPENTRY
  811. X#else
  812. X#    define CL    int
  813. X#endif
  814. X
  815. X/*---------- Function prototypes -------------------------------------------*/
  816. XCL d_block            PRM( (void);                                    )
  817. XCL d_unblock        PRM( (void);                                    )
  818. XCL d_setfiles        PRM( (int);                                        )
  819. XCL d_open            PRM( (char *, char *);                            )
  820. XCL d_close            PRM( (void);                                       )
  821. XCL d_destroy        PRM( (char *);                                  )
  822. XCL d_keyfind        PRM( (ulong, void *);                            )
  823. XCL d_keyfrst        PRM( (ulong);                                    )
  824. XCL d_keylast        PRM( (ulong);                                    )
  825. XCL d_keynext        PRM( (ulong);                                    )
  826. XCL d_keyprev        PRM( (ulong);                                    )
  827. XCL d_keyread        PRM( (void *);                                    )
  828. XCL d_fillnew        PRM( (ulong, void *);                            )
  829. XCL d_keystore        PRM( (ulong);                                    )
  830. XCL d_recwrite        PRM( (void *);                                    )
  831. XCL d_recread        PRM( (void *);                                    )
  832. XCL d_crread            PRM( (ulong, void *);                           )
  833. X
  834. XCL d_delete            PRM( (void);                                      )
  835. XCL d_recfrst           PRM( (ulong);                                         )
  836. XCL d_reclast           PRM( (ulong);                                         )
  837. XCL d_recnext           PRM( (ulong);                                         )
  838. XCL d_recprev           PRM( (ulong);                                         )
  839. X
  840. XCL d_crget            PRM( (DB_ADDR *);                                )
  841. XCL d_crset            PRM( (DB_ADDR *);                                )
  842. X
  843. XCL d_dbget            PRM( (int *); )
  844. XCL d_dbset            PRM( (int); )
  845. X
  846. XCL d_records        PRM( (ulong, ulong *);                            )
  847. XCL d_keys            PRM( (ulong);                                    )
  848. X
  849. XCL d_dbdpath        PRM( (char *);                                    )
  850. XCL d_dbfpath        PRM( (char *);                                    )
  851. X
  852. XCL d_reclock        PRM( (DB_ADDR *, int);                             )
  853. XCL d_recunlock        PRM( (DB_ADDR *);                                )
  854. X
  855. XCL d_keyfrst        PRM( (ulong);                                    )
  856. XCL d_keylast        PRM( (ulong);                                    )
  857. XCL d_keyprev        PRM( (ulong);                                    )
  858. XCL d_keynext        PRM( (ulong);                                    )
  859. X
  860. XCL d_recfrst        PRM( (ulong);                                    )
  861. XCL d_reclast        PRM( (ulong);                                    )
  862. XCL d_recprev        PRM( (ulong);                                    )
  863. XCL d_recnext        PRM( (ulong);                                    )
  864. X
  865. X
  866. XCL d_replicationlog    PRM( (int);                                        )
  867. XCL d_addsite        PRM( (ulong);                                    )
  868. XCL d_delsite        PRM( (ulong);                                    )
  869. XCL d_deltable        PRM( (ulong, ulong);                            )
  870. X   
  871. XCL d_getkeysize        PRM( (ulong, unsigned *);                        )
  872. XCL d_getrecsize        PRM( (ulong, unsigned *);                        )
  873. XCL d_getfieldtype    PRM( (ulong, unsigned *);                        )
  874. XCL ty_ustrcmp        PRM( (uchar *, uchar *);                        )
  875. XCL d_getkeyid        PRM( (ulong, ulong *);                            )
  876. XCL d_getforeignkeyid PRM( (ulong, ulong, ulong *);                    )
  877. XCL d_makekey        PRM( (ulong, void *, void *);                    )
  878. X
  879. XCL d_seterrfn        PRM( (void (*)(int, long));                        )
  880. X
  881. X
  882. X#undef CL
  883. X
  884. X#endif
  885. X
  886. X/* end-of-file */
  887. END_OF_FILE
  888.   if test 6375 -ne `wc -c <'typhoon/src/h/typhoon.h'`; then
  889.     echo shar: \"'typhoon/src/h/typhoon.h'\" unpacked with wrong size!
  890.   fi
  891.   # end of 'typhoon/src/h/typhoon.h'
  892. fi
  893. if test -f 'typhoon/src/ty_repif.h' -a "${1}" != "-c" ; then 
  894.   echo shar: Will not clobber existing file \"'typhoon/src/ty_repif.h'\"
  895. else
  896.   echo shar: Extracting \"'typhoon/src/ty_repif.h'\" \(5321 characters\)
  897.   sed "s/^X//" >'typhoon/src/ty_repif.h' <<'END_OF_FILE'
  898. X/*----------------------------------------------------------------------------
  899. X * File    : ty_repif.h
  900. X * Library : typhoon
  901. X * OS      : UNIX, OS/2, DOS
  902. X * Author  : Thomas B. Pedersen
  903. X *
  904. X * Copyright (c) 1994 Thomas B. Pedersen.  All rights reserved.
  905. X *
  906. X * Permission is hereby granted, without written agreement and without
  907. X * license or royalty fees, to use, copy, modify, and distribute this
  908. X * software and its documentation for any purpose, provided that the above
  909. X * copyright notice and the following two  paragraphs appear (1) in all 
  910. X * source copies of this software and (2) in accompanying documentation
  911. X * wherever the programatic interface of this software, or any derivative
  912. X * of it, is described.
  913. X *
  914. X * IN NO EVENT SHALL THOMAS B. PEDERSEN BE LIABLE TO ANY PARTY FOR DIRECT,
  915. X * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF
  916. X * THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF HE HAS BEEN 
  917. X * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  918. X *
  919. X * THOMAS B. PEDERSEN SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT
  920. X * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  921. X * A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" 
  922. X * BASIS, AND THOMAS B. PEDERSEN HAS NO OBLIGATION TO PROVIDE MAINTENANCE,
  923. X * SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  924. X *
  925. X * Description:
  926. X *   Contains structures used in the interface between the database and the
  927. X *   Replication Server.
  928. X *
  929. X * $Id: ty_repif.h,v 1.1 1994/09/13 21:28:38 tbp Exp $
  930. X *
  931. X * $Log: ty_repif.h,v $
  932. X * Revision 1.1  1994/09/13  21:28:38  tbp
  933. X * Added to repository.
  934. X * 
  935. X *
  936. X *--------------------------------------------------------------------------*/
  937. X
  938. X#ifndef _TY_REPIF_INCLUDED
  939. X#define _TY_REPIF_INCLUDED
  940. X
  941. X#define REPLLOG_NAME    "replserv.log"
  942. X
  943. X#define ACTION_UPDATE    'u'            /* Update or create a record            */
  944. X#define ACTION_DELETE    'd'            /* Delete a record                        */
  945. X#define ACTION_NEWSITE    'n'            /* Scan catalog for new site            */
  946. X#define ACTION_DELSITE    'e'            /* Remove a site from memory            */
  947. X#define ACTION_DELTABLE    't'            /* Remove a table fro memmory            */
  948. X
  949. Xtypedef struct {
  950. X    char        action;                /* See ACTION_...                        */
  951. X    char        prog_id;            /* Program ID                            */
  952. X    ulong        recid;                /* Record ID                            */
  953. X    union {
  954. X        DB_ADDR    addr;                /* action = UPDATE                        */
  955. X        char    key[KEYSIZE_MAX];    /* action = DELETE                        */
  956. X        ulong    site_id;            /* action = NEWSITE, DELSITE or DELTABLE*/
  957. X    } u;
  958. X} LOGENTRY;
  959. X
  960. X
  961. X/*--------------------------- Protocol block IDs ---------------------------*/
  962. X#define REPL_ACKNOWLEDGE    0       /* ID of acknowledge block              */
  963. X#define REPL_UPDATE         100     /* ID of update block                   */
  964. X#define REPL_DELETE         101     /* ID of delete block                   */
  965. X#define REPL_CLEARTABLE        102
  966. X#define REPL_ERROR            103
  967. X#define REPL_PROTBUF_SIZE   25000   /* Max buffer size passed               */
  968. X#define REPL_HEADER_SIZE    8
  969. X
  970. Xstruct repl_header {
  971. X    ulong        seqno;                /* Sequence number                        */
  972. X    ulong        len;                /* Length of rest of block                */
  973. X};
  974. X
  975. Xstruct repl_acknowledge {
  976. X    ulong        seqno;                /* Sequence number                        */
  977. X    ulong        len;                /* Length of rest of block                */
  978. X    uchar        id;                 /* Must be 0                            */
  979. X    uchar        spare[3];            /* Used to maintain dword alignment     */
  980. X    ulong        sequence;           /* Sequence number acknowledged         */
  981. X};
  982. X
  983. Xstruct repl_update {
  984. X    ulong        seqno;                /* Sequence number                        */
  985. X    ulong        len;                /* Length of rest of block                */
  986. X    uchar        id;                 /* Must be 100                            */
  987. X    uchar        prog_id;            /* Program ID                            */
  988. X    ushort        rec_len;            /* Number of bytes in rec[]                */
  989. X    ulong        recid;                /* Record ID                            */
  990. X    ulong        sequence;            /* Update sequence number                */
  991. X    uchar        rec[1];                /* Record buffer                        */
  992. X};
  993. X
  994. Xstruct repl_delete {
  995. X    ulong        seqno;                /* Sequence number                        */
  996. X    ulong        len;                /* Length of rest of block                */
  997. X    uchar        id;                 /* Must be 101                            */
  998. X    uchar        prog_id;            /* Program ID                            */
  999. X    ushort        key_len;            /* Number of bytes in buf[]                */
  1000. X    ulong        recid;                /* Record ID                            */
  1001. X    ulong        sequence;            /* Update sequence number                */
  1002. X    uchar        key[1];                /* Key buffer                            */
  1003. X};    
  1004. X
  1005. X
  1006. Xstruct repl_cleartable {
  1007. X    ulong       seqno;              /* Sequence number                      */
  1008. X    ulong       len;                /* Length of rest of block              */
  1009. X    uchar       id;                 /* Must be 102                          */
  1010. X    uchar        spare[3];
  1011. X    ulong        recid;                /* ID of table to clear                    */
  1012. X};
  1013. X
  1014. X
  1015. X
  1016. X/*--------------------------------------------------------------------------*\
  1017. X *
  1018. X * Block    : repl_error
  1019. X *
  1020. X * Purpose  : This protocol block is used to report an error to the
  1021. X *              Replication Server. 
  1022. X *
  1023. X * Direction: Site -> Replication Server.
  1024. X *
  1025. X */
  1026. Xstruct repl_error {
  1027. X    ulong       seqno;              /* Sequence number                      */
  1028. X    ulong       len;                /* Length of rest of block              */
  1029. X    uchar       id;                 /* Must be 103                          */
  1030. X    uchar        error;                /* 0=Record contains unknown reference    */
  1031. X                                    /* 1=Record is referenced by other rec    */
  1032. X    uchar       spare[2];           /* Used to maintain dword alignment     */
  1033. X    ulong        arg;                /* error=0: ID of referenced table        */
  1034. X    ulong       sequence;           /* Sequence number of erroneous block    */
  1035. X};
  1036. X
  1037. X#endif
  1038. X
  1039. X/* end-of-file */
  1040. X
  1041. END_OF_FILE
  1042.   if test 5321 -ne `wc -c <'typhoon/src/ty_repif.h'`; then
  1043.     echo shar: \"'typhoon/src/ty_repif.h'\" unpacked with wrong size!
  1044.   fi
  1045.   # end of 'typhoon/src/ty_repif.h'
  1046. fi
  1047. if test -f 'typhoon/src/ty_repl.c' -a "${1}" != "-c" ; then 
  1048.   echo shar: Will not clobber existing file \"'typhoon/src/ty_repl.c'\"
  1049. else
  1050.   echo shar: Extracting \"'typhoon/src/ty_repl.c'\" \(6049 characters\)
  1051.   sed "s/^X//" >'typhoon/src/ty_repl.c' <<'END_OF_FILE'
  1052. X/*----------------------------------------------------------------------------
  1053. X * File    : ty_repl.c
  1054. X * Library : typhoon
  1055. X * OS      : UNIX, OS/2, DOS
  1056. X * Author  : Thomas B. Pedersen
  1057. X *
  1058. X * Copyright (c) 1994 Thomas B. Pedersen.  All rights reserved.
  1059. X *
  1060. X * Permission is hereby granted, without written agreement and without
  1061. X * license or royalty fees, to use, copy, modify, and distribute this
  1062. X * software and its documentation for any purpose, provided that the above
  1063. X * copyright notice and the following two  paragraphs appear (1) in all 
  1064. X * source copies of this software and (2) in accompanying documentation
  1065. X * wherever the programatic interface of this software, or any derivative
  1066. X * of it, is described.
  1067. X *
  1068. X * IN NO EVENT SHALL THOMAS B. PEDERSEN BE LIABLE TO ANY PARTY FOR DIRECT,
  1069. X * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF
  1070. X * THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF HE HAS BEEN 
  1071. X * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  1072. X *
  1073. X * THOMAS B. PEDERSEN SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT
  1074. X * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  1075. X * A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" 
  1076. X * BASIS, AND THOMAS B. PEDERSEN HAS NO OBLIGATION TO PROVIDE MAINTENANCE,
  1077. X * SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  1078. X *
  1079. X * Description:
  1080. X *
  1081. X * Functions:
  1082. X *   Contains functions for logging updates and deletions.
  1083. X *
  1084. X * $Log: ty_repl.c,v $
  1085. X * Revision 1.2  1994/09/17  16:00:20  tbp
  1086. X * typhoon.h and environ.h are now included from <>.
  1087. X *
  1088. X * Revision 1.1  1994/09/13  21:28:38  tbp
  1089. X * Added to repository.
  1090. X * 
  1091. X *
  1092. X *--------------------------------------------------------------------------*/
  1093. X
  1094. Xstatic char rcsid[] = "$Id: ty_repl.c,v 1.2 1994/09/17 16:00:20 tbp Exp $";
  1095. X
  1096. X#ifdef UNIX
  1097. X#    include <unistd.h>
  1098. X#else
  1099. X#    include <sys\types.h>
  1100. X#    include <sys\stat.h>
  1101. X#    include <io.h>
  1102. X#endif
  1103. X#include <stdio.h>
  1104. X#include <string.h>
  1105. X#include <fcntl.h>
  1106. X#include <errno.h>
  1107. X#include <typhoon.h>
  1108. X#include "ty_dbd.h"
  1109. X#include "ty_type.h"
  1110. X#include "ty_glob.h"
  1111. X#include "ty_prot.h"
  1112. X#include "ty_repif.h"
  1113. X#include "catalog.h"
  1114. X
  1115. X/*-------------------------- Function prototypes ---------------------------*/
  1116. Xstatic int    read_distables        PRM( (void); )
  1117. Xstatic void    add_recid            PRM( (Id); )
  1118. Xstatic int    get_recid            PRM( (Id); )
  1119. Xstatic void write_logentry        PRM( (LOGENTRY *, unsigned); )
  1120. X
  1121. X/*---------------------------- Global variables ----------------------------*/
  1122. Xstatic int     dis_dbid = -1;                /* Distributed database ID            */
  1123. Xstatic int      dis_records = 0;            /* Number of entries in dis_record[]*/
  1124. Xstatic Id     dis_record[100];
  1125. X
  1126. X
  1127. Xstatic get_recid(id)
  1128. XId id;
  1129. X{
  1130. X    int i;
  1131. X    
  1132. X    for( i=0; i<dis_records; i++ )
  1133. X        if( dis_record[i] == id )
  1134. X            return i;
  1135. X
  1136. X    return -1;
  1137. X}
  1138. X
  1139. X
  1140. Xstatic void add_recid(id)
  1141. XId id;
  1142. X{
  1143. X    if( get_recid(id) == -1 )
  1144. X        dis_record[dis_records++] = id;
  1145. X}
  1146. X
  1147. X
  1148. Xstatic read_distables()
  1149. X{
  1150. X    struct sys_distab table;
  1151. X    ulong table_id;
  1152. X    int old_dbid;
  1153. X    int rc;
  1154. X    
  1155. X    d_dbget(&old_dbid);
  1156. X
  1157. X    if( d_open("catalog", "s") != S_OKAY )
  1158. X    {
  1159. X        d_dbset(old_dbid);
  1160. X        return -1;
  1161. X    }
  1162. X
  1163. X    dis_records = 0;
  1164. X    for( rc = d_recfrst(SYS_DISTAB); rc == S_OKAY; rc = d_recnext(SYS_DISTAB) )    
  1165. X    {
  1166. X        d_recread(&table);
  1167. X        add_recid(table.id);
  1168. X    }
  1169. X
  1170. X    d_close();
  1171. X    d_dbset(old_dbid);
  1172. X
  1173. X    return 0;
  1174. X}
  1175. X
  1176. X
  1177. X/*---------------------------- d_replicationlog ----------------------------*\
  1178. X *
  1179. X * Purpose     : Turn the replication log on/off.
  1180. X *
  1181. X * Parameters: on        - 1=On, 0=Off
  1182. X *
  1183. X * Returns     : S_OKAY    - The ID is not a key ID.
  1184. X *
  1185. X */
  1186. XFNCLASS d_replicationlog(on)
  1187. Xint on;
  1188. X{
  1189. X    DB->logging    = on;
  1190. X
  1191. X    if( on )
  1192. X    {
  1193. X        if( read_distables() == -1 )
  1194. X            RETURN S_IOFATAL;
  1195. X        dis_dbid = CURR_DB;
  1196. X    }
  1197. X    
  1198. X    RETURN S_OKAY;
  1199. X}
  1200. X
  1201. X
  1202. XFNCLASS d_addsite(id)
  1203. Xulong id;
  1204. X{
  1205. X    LOGENTRY entry;
  1206. X    
  1207. X    entry.action    = ACTION_NEWSITE;
  1208. X    entry.u.site_id    = id;
  1209. X
  1210. X    write_logentry(&entry, offsetof(LOGENTRY, u) + sizeof entry.u.site_id);
  1211. X    
  1212. X    RETURN S_OKAY;
  1213. X}
  1214. X
  1215. X
  1216. XFNCLASS d_delsite(id)
  1217. Xulong id;
  1218. X{
  1219. X    LOGENTRY entry;
  1220. X    
  1221. X    entry.action    = ACTION_DELSITE;
  1222. X    entry.u.site_id    = id;
  1223. X
  1224. X    write_logentry(&entry, offsetof(LOGENTRY, u) + sizeof entry.u.site_id);
  1225. X    
  1226. X    RETURN S_OKAY;
  1227. X}
  1228. X
  1229. X
  1230. XFNCLASS d_deltable(site_id, table_id)
  1231. Xulong site_id, table_id;
  1232. X{
  1233. X    LOGENTRY entry;
  1234. X    
  1235. X    entry.action    = ACTION_DELTABLE;
  1236. X    entry.recid        = table_id;
  1237. X    entry.u.site_id    = site_id;
  1238. X
  1239. X    write_logentry(&entry, offsetof(LOGENTRY, u) + sizeof entry.u.site_id);
  1240. X    
  1241. X    RETURN S_OKAY;
  1242. X}
  1243. X
  1244. X
  1245. X/*--------------------------------------------------------------------------*\
  1246. X *
  1247. X * Function  : ty_log
  1248. X *
  1249. X * Purpose   : Add an entry to the Replication Server log. If site_id == -1
  1250. X *               ty_log is called to add or delete a site.
  1251. X *
  1252. X * Parameters: action    - 'u'=Update, 'd'=delete.
  1253. X *
  1254. X * Returns   : Nothing.
  1255. X *
  1256. X */
  1257. Xvoid ty_log(action)
  1258. Xint action;
  1259. X{
  1260. X    LOGENTRY entry;
  1261. X    Id recid = INTERN_TO_RECID(CURR_RECID);
  1262. X    ushort size, keysize;
  1263. X    Record *rec = &DB->record[RECID_TO_INTERN(recid)];
  1264. X
  1265. X    /* Return if the current database is not distributed */
  1266. X    if( CURR_DB != dis_dbid )
  1267. X        return;
  1268. X
  1269. X    /* Return here if the record is not distributed */
  1270. X    if( get_recid(recid) == -1 )
  1271. X        return;
  1272. X    
  1273. X    entry.action= action;
  1274. X    entry.recid    = recid;
  1275. X    size        = offsetof(LOGENTRY, u);
  1276. X
  1277. X    switch( action )
  1278. X    {
  1279. X        case ACTION_UPDATE:
  1280. X            /* Store the database address of the modified record */
  1281. X            size += sizeof(entry.u.addr);
  1282. X            d_crget(&entry.u.addr);
  1283. X            break;
  1284. X        case ACTION_DELETE:
  1285. X            /* Store the primary key of the deleted record */
  1286. X            keysize = DB->key[ rec->first_key ].size;
  1287. X            
  1288. X            /* Copy the record's first key to <entry.buf> */
  1289. X            memcpy(entry.u.key,
  1290. X                   set_keyptr(&DB->key[ rec->first_key ], DB->recbuf),
  1291. X                   keysize);
  1292. X            size += keysize;
  1293. X            break;
  1294. X    }
  1295. X
  1296. X    write_logentry(&entry, size);
  1297. X}
  1298. X
  1299. X
  1300. X
  1301. Xstatic void write_logentry(entry, size)
  1302. XLOGENTRY *entry;
  1303. Xunsigned size;
  1304. X{
  1305. X    int fh;
  1306. X    short shsize;
  1307. X
  1308. X    if( (fh=open(REPLLOG_NAME, O_BINARY|O_CREAT|O_RDWR|O_APPEND, CREATMASK)) == -1 )
  1309. X    {
  1310. X#ifdef UNIX
  1311. X        printf("PANIC: cannot open '%s' (pid %d)\n\a", REPLLOG_NAME, getpid());
  1312. X#else
  1313. X        printf("PANIC: cannot open '%s'\n\a", REPLLOG_NAME);
  1314. X#endif
  1315. X        return;
  1316. X    }
  1317. X
  1318. X    shsize = size;
  1319. X    write(fh, &shsize, sizeof shsize);
  1320. X    write(fh, entry, size);
  1321. X
  1322. X    close(fh);
  1323. X}
  1324. X
  1325. X/* end-of-file */
  1326. END_OF_FILE
  1327.   if test 6049 -ne `wc -c <'typhoon/src/ty_repl.c'`; then
  1328.     echo shar: \"'typhoon/src/ty_repl.c'\" unpacked with wrong size!
  1329.   fi
  1330.   # end of 'typhoon/src/ty_repl.c'
  1331. fi
  1332. if test -f 'typhoon/src/ty_util.c' -a "${1}" != "-c" ; then 
  1333.   echo shar: Will not clobber existing file \"'typhoon/src/ty_util.c'\"
  1334. else
  1335.   echo shar: Extracting \"'typhoon/src/ty_util.c'\" \(5150 characters\)
  1336.   sed "s/^X//" >'typhoon/src/ty_util.c' <<'END_OF_FILE'
  1337. X/*----------------------------------------------------------------------------
  1338. X * File    : ty_util.c
  1339. X * Library : typhoon
  1340. X * OS      : UNIX, OS/2, DOS
  1341. X * Author  : Thomas B. Pedersen
  1342. X *
  1343. X * Copyright (c) 1994 Thomas B. Pedersen.  All rights reserved.
  1344. X *
  1345. X * Permission is hereby granted, without written agreement and without
  1346. X * license or royalty fees, to use, copy, modify, and distribute this
  1347. X * software and its documentation for any purpose, provided that the above
  1348. X * copyright notice and the following two  paragraphs appear (1) in all 
  1349. X * source copies of this software and (2) in accompanying documentation
  1350. X * wherever the programatic interface of this software, or any derivative
  1351. X * of it, is described.
  1352. X *
  1353. X * IN NO EVENT SHALL THOMAS B. PEDERSEN BE LIABLE TO ANY PARTY FOR DIRECT,
  1354. X * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF
  1355. X * THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF HE HAS BEEN 
  1356. X * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  1357. X *
  1358. X * THOMAS B. PEDERSEN SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT
  1359. X * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  1360. X * A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" 
  1361. X * BASIS, AND THOMAS B. PEDERSEN HAS NO OBLIGATION TO PROVIDE MAINTENANCE,
  1362. X * SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  1363. X *
  1364. X * Description:
  1365. X *
  1366. X * Functions:
  1367. X *
  1368. X * $Log: ty_util.c,v $
  1369. X * Revision 1.2  1994/09/17  16:00:21  tbp
  1370. X * typhoon.h and environ.h are now included from <>.
  1371. X *
  1372. X * Revision 1.1  1994/09/13  21:28:39  tbp
  1373. X * Added to repository.
  1374. X * 
  1375. X *
  1376. X *--------------------------------------------------------------------------*/
  1377. X
  1378. Xstatic char rcsid[] = "$Id: ty_util.c,v 1.2 1994/09/17 16:00:21 tbp Exp $";
  1379. X
  1380. X#ifdef UNIX
  1381. X#    include <unistd.h>
  1382. X#endif
  1383. X#include <string.h>
  1384. X#include <stdio.h>
  1385. X#include <typhoon.h>
  1386. X#include "ty_dbd.h"
  1387. X#include "ty_type.h"
  1388. X#include "ty_glob.h"
  1389. X#include "ty_prot.h"
  1390. X
  1391. X
  1392. X/*------------------------------ d_getkeysize ------------------------------*\
  1393. X *
  1394. X * Purpose     : Return the size of a key.
  1395. X *
  1396. X * Parameters: id        - Field ID or compound key ID.
  1397. X *               size        - Pointer to var in which size will be returned.
  1398. X *
  1399. X * Returns     : S_NOTKEY    - The ID is not a key ID.
  1400. X *               S_NOCD    - No current database.
  1401. X *
  1402. X */
  1403. X
  1404. XFNCLASS d_getkeysize(id, size)
  1405. XId id;
  1406. Xunsigned *size;
  1407. X{
  1408. X    Field *fld;
  1409. X    int rc;
  1410. X
  1411. X    /* Make sure that a database is open */
  1412. X    if( CURR_DB == -1 )
  1413. X        RETURN_RAP(S_NOCD);
  1414. X
  1415. X    /* Determine whether this id is a key id or a compound key id */
  1416. X    if( id < REC_FACTOR )
  1417. X    {
  1418. X        if( id >= DB->header.keys )
  1419. X            RETURN_RAP(S_NOTKEY);
  1420. X
  1421. X        *size = DB->key[id].size;
  1422. X    }
  1423. X    else
  1424. X    {
  1425. X        if( (rc = set_recfld(id, NULL, &fld)) != S_OKAY )
  1426. X            return rc;
  1427. X
  1428. X        if( !(fld->type & FT_KEY) )
  1429. X            RETURN_RAP(S_NOTKEY);
  1430. X
  1431. X        *size = DB->key[fld->keyid].size;
  1432. X    }
  1433. X
  1434. X    RETURN S_OKAY;
  1435. X}
  1436. X
  1437. X
  1438. X
  1439. XFNCLASS d_getfieldtype(id, type)
  1440. XId id;
  1441. Xunsigned *type;
  1442. X{
  1443. X    Field *fld;
  1444. X    int rc;
  1445. X
  1446. X    /* Make sure that a database is open */
  1447. X    if( CURR_DB == -1 )
  1448. X        RETURN_RAP(S_NOCD);
  1449. X
  1450. X    /* Determine whether this id is a key id or a compound key id */
  1451. X    if( id < REC_FACTOR )
  1452. X    {
  1453. X        if( id >= DB->header.keys )
  1454. X            RETURN_RAP(S_NOTKEY);
  1455. X    }
  1456. X    else
  1457. X    {
  1458. X        if( (rc = set_recfld(id, NULL, &fld)) != S_OKAY )
  1459. X            return rc;
  1460. X
  1461. X        id = fld->keyid;
  1462. X    }
  1463. X
  1464. X    *type = DB->field[ DB->keyfield[ DB->key[id].first_keyfield ].field ].type;
  1465. X
  1466. X    RETURN S_OKAY;
  1467. X}
  1468. X
  1469. X
  1470. X
  1471. X
  1472. X/*------------------------------ d_getrecsize ------------------------------*\
  1473. X *
  1474. X * Purpose     : Return the size of a record.
  1475. X *
  1476. X * Parameters: recid    - Record ID.
  1477. X *               size        - Pointer to var in which size will be returned.
  1478. X *
  1479. X * Returns     : S_NOTKEY    - The ID is not a record ID.
  1480. X *               S_NOCD    - No current database.
  1481. X *
  1482. X */
  1483. X
  1484. XFNCLASS d_getrecsize(recid, size)
  1485. XId recid;
  1486. Xunsigned *size;
  1487. X{
  1488. X    Record *rec;
  1489. X    int rc;
  1490. X
  1491. X    /* Make sure that a database is open */
  1492. X    if( CURR_DB == -1 )
  1493. X        RETURN_RAP(S_NOCD);
  1494. X
  1495. X    if( (rc = set_recfld(recid, &rec, NULL)) != S_OKAY )
  1496. X        return rc;
  1497. X    
  1498. X    *size = rec->size;
  1499. X
  1500. X    RETURN S_OKAY;
  1501. X}
  1502. X
  1503. X
  1504. X
  1505. X
  1506. XFNCLASS d_makekey(id, recbuf, keybuf)
  1507. XId id;
  1508. Xvoid *recbuf, *keybuf;
  1509. X{
  1510. X    KeyField *keyfld;
  1511. X    Key *key;
  1512. X    int n, rc;
  1513. X
  1514. X    /* Make sure that a database is open */
  1515. X    if( CURR_DB == -1 )
  1516. X        RETURN_RAP(S_NOCD);
  1517. X
  1518. X    if( (rc=aux_getkey(id, &key)) != S_OKAY )
  1519. X        return rc;
  1520. X
  1521. X    keyfld = DB->keyfield + key->first_keyfield;
  1522. X    n = key->fields;
  1523. X
  1524. X    /* Build compound key from record */
  1525. X    while( n-- )
  1526. X    {
  1527. X        memcpy((char *)keybuf + keyfld->offset,
  1528. X               (char *)recbuf + DB->field[ keyfld->field ].offset,
  1529. X                                DB->field[ keyfld->field ].size);
  1530. X        keyfld++;
  1531. X    }
  1532. X    
  1533. X    RETURN S_OKAY;
  1534. X}
  1535. X
  1536. X
  1537. XFNCLASS d_getkeyid(recid, keyid)
  1538. XId recid, *keyid;
  1539. X{
  1540. X    Record *rec;
  1541. X    int rc;
  1542. X    
  1543. X    if( (rc = set_recfld(recid, &rec, NULL)) != S_OKAY )
  1544. X        return rc;
  1545. X
  1546. X    *keyid = rec->first_key;
  1547. X
  1548. X    RETURN S_OKAY;
  1549. X}
  1550. X
  1551. X
  1552. X
  1553. XFNCLASS d_getforeignkeyid(recid, parent_table, keyid)
  1554. XId recid, parent_table, *keyid;
  1555. X{
  1556. X    Record *rec;
  1557. X    Key *key;
  1558. X    int rc, n;
  1559. X
  1560. X    if( (rc = set_recfld(recid, &rec, NULL)) != S_OKAY )
  1561. X        return rc;
  1562. X
  1563. X    parent_table= RECID_TO_INTERN(parent_table);
  1564. X    n            = rec->keys;
  1565. X    key            = DB->key + rec->first_key;
  1566. X    
  1567. X    while( n-- )
  1568. X    {
  1569. X        if( KEY_ISFOREIGN(key) && key->parent == parent_table )
  1570. X        {
  1571. X            *keyid = key - DB->key;
  1572. X            RETURN S_OKAY;
  1573. X        }
  1574. X        key++;
  1575. X    }
  1576. X    
  1577. X    RETURN S_NOTFOUND;
  1578. X}
  1579. X
  1580. X
  1581. X
  1582. X/* end-of-file */
  1583. END_OF_FILE
  1584.   if test 5150 -ne `wc -c <'typhoon/src/ty_util.c'`; then
  1585.     echo shar: \"'typhoon/src/ty_util.c'\" unpacked with wrong size!
  1586.   fi
  1587.   # end of 'typhoon/src/ty_util.c'
  1588. fi
  1589. if test -f 'typhoon/src/util/exp.y' -a "${1}" != "-c" ; then 
  1590.   echo shar: Will not clobber existing file \"'typhoon/src/util/exp.y'\"
  1591. else
  1592.   echo shar: Extracting \"'typhoon/src/util/exp.y'\" \(4986 characters\)
  1593.   sed "s/^X//" >'typhoon/src/util/exp.y' <<'END_OF_FILE'
  1594. X/*----------------------------------------------------------------------------
  1595. X * File    : exp.y
  1596. X * Program : tyexport
  1597. X * OS      : UNIX, OS/2, DOS
  1598. X * Author  : Thomas B. Pedersen
  1599. X *
  1600. X * Copyright (c) 1994 Thomas B. Pedersen.  All rights reserved.
  1601. X *
  1602. X * Permission is hereby granted, without written agreement and without
  1603. X * license or royalty fees, to use, copy, modify, and distribute this
  1604. X * software and its documentation for any purpose, provided that the above
  1605. X * copyright notice and the following two  paragraphs appear (1) in all 
  1606. X * source copies of this software and (2) in accompanying documentation
  1607. X * wherever the programatic interface of this software, or any derivative
  1608. X * of it, is described.
  1609. X *
  1610. X * IN NO EVENT SHALL THOMAS B. PEDERSEN BE LIABLE TO ANY PARTY FOR DIRECT,
  1611. X * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF
  1612. X * THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF HE HAS BEEN 
  1613. X * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  1614. X *
  1615. X * THOMAS B. PEDERSEN SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT
  1616. X * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  1617. X * A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" 
  1618. X * BASIS, AND THOMAS B. PEDERSEN HAS NO OBLIGATION TO PROVIDE MAINTENANCE,
  1619. X * SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  1620. X *
  1621. X * Description:
  1622. X *   Grammar for export specification.
  1623. X *
  1624. X * $Id: exp.y,v 1.2 1994/09/17 16:11:13 tbp Exp $
  1625. X *
  1626. X * $Log: exp.y,v $
  1627. X * Revision 1.2  1994/09/17  16:11:13  tbp
  1628. X * Added include directive.
  1629. X *
  1630. X * Added included directive.
  1631. X *
  1632. X * Added include directive.
  1633. X *
  1634. X * Revision 1.1  1994/09/13  21:28:54  tbp
  1635. X * Added to repository.
  1636. X *
  1637. X * Added to repository.
  1638. X * 
  1639. X *
  1640. X *--------------------------------------------------------------------------*/
  1641. X
  1642. X%{
  1643. X
  1644. X#include <string.h>
  1645. X#include <stdarg.h>
  1646. X#include <typhoon.h>
  1647. X#include "../ty_dbd.h"
  1648. X#include "../ty_type.h"
  1649. X#include "export.h"
  1650. X
  1651. X#define NEST_MAX    15
  1652. X
  1653. X/*--------------------------- Function prototypes --------------------------*/
  1654. XRecord        *GetRecord    PRM( (char *); )
  1655. XField        *GetField    PRM( (Structdef *, char *); )
  1656. XStructdef    *GetStruct    PRM( (Structdef *, char *); )
  1657. X
  1658. X/*---------------------------- Global variables ----------------------------*/
  1659. Xstatic Record        *cur_rec = NULL;        /* Current record                */
  1660. Xstatic Field        *cur_fld = NULL;        /* Current field                */
  1661. Xstatic Structdef    *cur_str = NULL;        /* Current structure            */
  1662. Xstatic Structdef    *strnest[NEST_MAX];        /* Pointers to structures        */
  1663. Xstatic int            cur_nest = -1;            /* Current nesting                */
  1664. X
  1665. X%}
  1666. X
  1667. X%union {
  1668. X    char      s[IDENT_LEN+1];
  1669. X}
  1670. X
  1671. X%start export_spec
  1672. X
  1673. X%token             T_EXPORT T_RECORD T_STRUCT T_UNION T_IN
  1674. X%token <s>        T_IDENT T_STRING
  1675. X%token             '{' '}' ';'
  1676. X
  1677. X%%
  1678. X
  1679. Xexport_spec        : T_EXPORT T_IDENT '{' record_list '}'
  1680. X                ;
  1681. X
  1682. Xrecord_list        : record
  1683. X                | record_list record
  1684. X                ;
  1685. X
  1686. Xrecord            : record_head '{' field_list '}'
  1687. X                    {
  1688. X                        cur_nest--;
  1689. X                    }
  1690. X                ;
  1691. X
  1692. Xrecord_head        : T_RECORD T_IDENT T_IN T_STRING 
  1693. X                    {
  1694. X                        if( cur_rec = GetRecord($2) )
  1695. X                        {
  1696. X                            cur_rec->aux = 1;
  1697. X                            cur_str = &dbd.structdef[cur_rec->structid];
  1698. X                        }
  1699. X                        else
  1700. X                            cur_str = NULL;
  1701. X                        strnest[++cur_nest] = cur_str;
  1702. X                    }
  1703. X                ;
  1704. X
  1705. Xfield_list        : field 
  1706. X                | field_list field 
  1707. X                ;
  1708. X    
  1709. Xfield            : T_IDENT ';'
  1710. X                    {
  1711. X                        if( cur_str )
  1712. X                            cur_fld = GetField(cur_str, $1);
  1713. X                    }
  1714. X
  1715. X                | struct_head '{' field_list '}' ';'
  1716. X                    {
  1717. X                        cur_str = strnest[--cur_nest];
  1718. X                    }
  1719. X                ;
  1720. X
  1721. Xstruct_head        : struct_or_union T_IDENT
  1722. X                    {
  1723. X                        if( cur_str )
  1724. X                            cur_str = GetStruct(cur_str, $2);
  1725. X                        strnest[++cur_nest] = cur_str;
  1726. X                    }
  1727. X                ;
  1728. X
  1729. Xstruct_or_union    : T_STRUCT
  1730. X                | T_UNION
  1731. X                ;
  1732. X
  1733. X
  1734. X%%
  1735. X
  1736. X
  1737. X#include <stdio.h>
  1738. X
  1739. Xextern errors;
  1740. X
  1741. Xyyerror(char *fmt ELLIPSIS)
  1742. X{
  1743. X    va_list ap;
  1744. X
  1745. X    printf("%s %d: ", spec_fname, lex_lineno);
  1746. X    va_start(ap, fmt);
  1747. X    vprintf(fmt, ap);
  1748. X    puts("");
  1749. X    va_end(ap);
  1750. X    errors++;
  1751. X    return 0;
  1752. X}
  1753. X
  1754. X
  1755. X
  1756. X
  1757. XRecord *GetRecord(name)
  1758. Xchar *name;
  1759. X{
  1760. X    int i;
  1761. X
  1762. X    for( i=0; i<dbd.header.records; i++ )
  1763. X        if( !strcmp(dbd.record[i].name, name) )
  1764. X            return &dbd.record[i];
  1765. X
  1766. X    yyerror("unknown record '%s'", name);
  1767. X    exit(1);
  1768. X    return NULL;
  1769. X}
  1770. X
  1771. X
  1772. X
  1773. XField *GetField(str, name)
  1774. XStructdef *str;
  1775. Xchar *name;
  1776. X{
  1777. X    Field *fld = &dbd.field[str->first_member];
  1778. X    int n = str->members;
  1779. X
  1780. X    while( n )
  1781. X    {
  1782. X        if( fld->nesting == cur_nest )
  1783. X        {
  1784. X            if( !strcmp(fld->name, name) )
  1785. X            {
  1786. X                fld->type |= FT_INCLUDE;
  1787. X                return fld;
  1788. X            }
  1789. X            n--;
  1790. X        }
  1791. X        fld++;
  1792. X    }
  1793. X
  1794. X    yyerror("'%s' is not a member of '%s'", name, str->name);
  1795. X    exit(1);
  1796. X    return NULL;
  1797. X}
  1798. X
  1799. X
  1800. XStructdef *GetStruct(str, name)
  1801. XStructdef *str;
  1802. Xchar *name;
  1803. X{
  1804. X    Field *fld;
  1805. X    Structdef *struc;
  1806. X
  1807. X    if( !(fld = GetField(str, name)) || 
  1808. X        FT_GETBASIC(fld->type) != FT_STRUCT )
  1809. X        return NULL;
  1810. X
  1811. X    struc = &dbd.structdef[fld->structid];
  1812. X
  1813. X    /* If the structure is a union the control field must also have been 
  1814. X     * specified
  1815. X     */
  1816. X    if( struc->is_union )
  1817. X    {
  1818. X        if( !(dbd.field[struc->control_field].type & FT_INCLUDE) )
  1819. X        {
  1820. X            yyerror("The control field of the union '%s' is not included",
  1821. X                name);
  1822. X            exit(1);
  1823. X        }
  1824. X    }
  1825. X
  1826. X    return struc;
  1827. X}
  1828. X
  1829. X/* end-of-file */
  1830. X
  1831. END_OF_FILE
  1832.   if test 4986 -ne `wc -c <'typhoon/src/util/exp.y'`; then
  1833.     echo shar: \"'typhoon/src/util/exp.y'\" unpacked with wrong size!
  1834.   fi
  1835.   # end of 'typhoon/src/util/exp.y'
  1836. fi
  1837. if test -f 'typhoon/src/util/expspec.c' -a "${1}" != "-c" ; then 
  1838.   echo shar: Will not clobber existing file \"'typhoon/src/util/expspec.c'\"
  1839. else
  1840.   echo shar: Extracting \"'typhoon/src/util/expspec.c'\" \(4624 characters\)
  1841.   sed "s/^X//" >'typhoon/src/util/expspec.c' <<'END_OF_FILE'
  1842. X/*----------------------------------------------------------------------------
  1843. X * File    : expspec.c
  1844. X * Program : tyexport
  1845. X * OS      : UNIX, OS/2, DOS
  1846. X * Author  : Thomas B. Pedersen
  1847. X *
  1848. X * Copyright (c) 1994 Thomas B. Pedersen.  All rights reserved.
  1849. X *
  1850. X * Permission is hereby granted, without written agreement and without
  1851. X * license or royalty fees, to use, copy, modify, and distribute this
  1852. X * software and its documentation for any purpose, provided that the above
  1853. X * copyright notice and the following two  paragraphs appear (1) in all 
  1854. X * source copies of this software and (2) in accompanying documentation
  1855. X * wherever the programatic interface of this software, or any derivative
  1856. X * of it, is described.
  1857. X *
  1858. X * IN NO EVENT SHALL THOMAS B. PEDERSEN BE LIABLE TO ANY PARTY FOR DIRECT,
  1859. X * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF
  1860. X * THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF HE HAS BEEN 
  1861. X * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  1862. X *
  1863. X * THOMAS B. PEDERSEN SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT
  1864. X * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  1865. X * A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" 
  1866. X * BASIS, AND THOMAS B. PEDERSEN HAS NO OBLIGATION TO PROVIDE MAINTENANCE,
  1867. X * SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  1868. X *
  1869. X * Description:
  1870. X *   Functions for reading and generating the specification.
  1871. X *
  1872. X * $Log: expspec.c,v $
  1873. X * Revision 1.2  1994/09/17  16:00:53  tbp
  1874. X * typhoon.h and environ.h are now included from <>.
  1875. X *
  1876. X * Revision 1.1  1994/09/13  21:28:56  tbp
  1877. X * Added to repository.
  1878. X *
  1879. X * Added to repository.
  1880. X * 
  1881. X *
  1882. X *--------------------------------------------------------------------------*/
  1883. X
  1884. Xstatic char rcsid[] = "$Id: expspec.c,v 1.2 1994/09/17 16:00:53 tbp Exp $";
  1885. X
  1886. X#include <stdio.h>
  1887. X#include <typhoon.h>
  1888. X#include "../ty_dbd.h"
  1889. X#include "../ty_type.h"
  1890. X#include "export.h"
  1891. X
  1892. X
  1893. X/*-------------------------- Function prototypes ---------------------------*/
  1894. Xstatic void Indent          PRM( (int); )
  1895. Xstatic int  PrintFields     PRM( (Structdef *, int); )
  1896. X
  1897. X
  1898. X/*---------------------------- Global variables ----------------------------*/
  1899. Xstatic FILE *outfile;
  1900. Xextern FILE *lex_file;
  1901. X
  1902. X
  1903. X
  1904. X/*----------------------------- ReadExportSpec -----------------------------*\
  1905. X *
  1906. X * Purpose   : This function reads an export specification.
  1907. X *
  1908. X * Parameters: exportspec_fname     - Output file name.
  1909. X *
  1910. X * Returns   : Nothing.
  1911. X *
  1912. X */
  1913. Xvoid ReadExportSpec(dbname)
  1914. Xchar *dbname;
  1915. X{
  1916. X    int i;
  1917. X    char exportspec_fname[256];
  1918. X
  1919. X    sprintf(exportspec_fname, "%s.exp", dbname);
  1920. X
  1921. X    if( !(lex_file = fopen(exportspec_fname, "r")) )
  1922. X        err_quit("Cannot open '%s'", exportspec_fname);
  1923. X
  1924. X    yyparse();
  1925. X
  1926. X    fclose(outfile);
  1927. X}
  1928. X
  1929. X
  1930. Xstatic void Indent(level)
  1931. Xint level;
  1932. X{
  1933. X    fprintf(outfile, "%*s", (level+2) * 4, "");
  1934. X}
  1935. X
  1936. X
  1937. Xstatic PrintFields(str, nest)
  1938. XStructdef *str;
  1939. Xint nest;
  1940. X{
  1941. X    Field *fld = dbd.field + str->first_member;
  1942. X    int fields = str->members;
  1943. X    int old_fields = fields;
  1944. X    int rc;
  1945. X
  1946. X    while( fields-- )
  1947. X    {
  1948. X        if( FT_GETBASIC(fld->type) == FT_STRUCT )
  1949. X        {
  1950. X            Structdef *struc = dbd.structdef + fld->structid;
  1951. X
  1952. X            Indent(nest);
  1953. X            fprintf(outfile, "%s %s {\n", struc->is_union ? "union" : "struct", fld->name);
  1954. X            rc = PrintFields(struc, nest+1);
  1955. X            Indent(nest);
  1956. X            fprintf(outfile, "};\n");
  1957. X            old_fields += rc;
  1958. X            fld += rc;
  1959. X        }
  1960. X        else if( fld->nesting == nest )
  1961. X        {
  1962. X            Indent(nest);
  1963. X            fprintf(outfile, "%s;\n", fld->name);
  1964. X        }
  1965. X
  1966. X        fld++;
  1967. X    }
  1968. X
  1969. X    return old_fields;
  1970. X}
  1971. X
  1972. X
  1973. X
  1974. X
  1975. X/*--------------------------- GenerateExportSpec ---------------------------*\
  1976. X *
  1977. X * Purpose   : This function automatically generates a full export 
  1978. X *          specification.
  1979. X *
  1980. X * Parameters: exprotspec_fname     - Output file name.
  1981. X *
  1982. X * Returns   : Nothing.
  1983. X *
  1984. X */
  1985. Xvoid GenerateExportSpec(dbname)
  1986. Xchar *dbname;
  1987. X{
  1988. X    char exportspec_fname[256];            
  1989. X    int i;
  1990. X    Record *rec = dbd.record;
  1991. X
  1992. X    printf("Generating export specification...");
  1993. X    fflush(stdout);
  1994. X
  1995. X    sprintf(exportspec_fname, "%s.exp", dbname);
  1996. X
  1997. X    if( !(outfile = fopen(exportspec_fname, "w")) )
  1998. X        err_quit("Cannot write to '%s'", exportspec_fname);
  1999. X
  2000. X    fprintf(outfile, "export %s {\n\n", dbname); 
  2001. X
  2002. X    for( i=0; i<dbd.header.records; i++, rec++ )
  2003. X    {
  2004. X        fprintf(outfile, "    record %s in \"%.8s.kom\" {\n", rec->name, rec->name);
  2005. X
  2006. X        PrintFields(&dbd.structdef[rec->structid], 0);
  2007. X
  2008. X        fprintf(outfile, "    }\n\n");
  2009. X    }
  2010. X
  2011. X    fprintf(outfile, "}\n");
  2012. X    fclose(outfile);
  2013. X
  2014. X    puts("done");
  2015. X}
  2016. X
  2017. X/* end-of-file */
  2018. END_OF_FILE
  2019.   if test 4624 -ne `wc -c <'typhoon/src/util/expspec.c'`; then
  2020.     echo shar: \"'typhoon/src/util/expspec.c'\" unpacked with wrong size!
  2021.   fi
  2022.   # end of 'typhoon/src/util/expspec.c'
  2023. fi
  2024. if test -f 'typhoon/src/util/impspec.c' -a "${1}" != "-c" ; then 
  2025.   echo shar: Will not clobber existing file \"'typhoon/src/util/impspec.c'\"
  2026. else
  2027.   echo shar: Extracting \"'typhoon/src/util/impspec.c'\" \(4630 characters\)
  2028.   sed "s/^X//" >'typhoon/src/util/impspec.c' <<'END_OF_FILE'
  2029. X/*----------------------------------------------------------------------------
  2030. X * File    : impspec.c
  2031. X * Program : tyimport
  2032. X * OS      : UNIX, OS/2, DOS
  2033. X * Author  : Thomas B. Pedersen
  2034. X *
  2035. X * Copyright (c) 1994 Thomas B. Pedersen.  All rights reserved.
  2036. X *
  2037. X * Permission is hereby granted, without written agreement and without
  2038. X * license or royalty fees, to use, copy, modify, and distribute this
  2039. X * software and its documentation for any purpose, provided that the above
  2040. X * copyright notice and the following two  paragraphs appear (1) in all 
  2041. X * source copies of this software and (2) in accompanying documentation
  2042. X * wherever the programatic interface of this software, or any derivative
  2043. X * of it, is described.
  2044. X *
  2045. X * IN NO EVENT SHALL THOMAS B. PEDERSEN BE LIABLE TO ANY PARTY FOR DIRECT,
  2046. X * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF
  2047. X * THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF HE HAS BEEN 
  2048. X * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  2049. X *
  2050. X * THOMAS B. PEDERSEN SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT
  2051. X * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  2052. X * A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" 
  2053. X * BASIS, AND THOMAS B. PEDERSEN HAS NO OBLIGATION TO PROVIDE MAINTENANCE,
  2054. X * SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  2055. X *
  2056. X * Description:
  2057. X *   Functions for reading and generating the specification.
  2058. X *
  2059. X * $Log: impspec.c,v $
  2060. X * Revision 1.2  1994/09/17  16:00:56  tbp
  2061. X * typhoon.h and environ.h are now included from <>.
  2062. X *
  2063. X * Revision 1.1  1994/09/13  21:28:59  tbp
  2064. X * Added to repository.
  2065. X *
  2066. X * Added to repository.
  2067. X * 
  2068. X *
  2069. X *--------------------------------------------------------------------------*/
  2070. X
  2071. Xstatic char rcsid[] = "$Id: impspec.c,v 1.2 1994/09/17 16:00:56 tbp Exp $";
  2072. X
  2073. X#include <stdio.h>
  2074. X#include <typhoon.h>
  2075. X#include "../ty_dbd.h"
  2076. X#include "../ty_type.h"
  2077. X#include "import.h"
  2078. X
  2079. X
  2080. X/*-------------------------- Function prototypes ---------------------------*/
  2081. Xstatic void Indent          PRM( (int); )
  2082. Xstatic int  PrintFields     PRM( (Structdef *, int); )
  2083. X
  2084. X
  2085. X/*---------------------------- Global variables ----------------------------*/
  2086. Xstatic FILE *outfile;
  2087. Xextern FILE *lex_file;
  2088. X
  2089. X/*----------------------------- ReadImportSpec -----------------------------*\
  2090. X *
  2091. X * Purpose   : This function reads an import specification.
  2092. X *
  2093. X * Parameters: importspec_fname     - Output file name.
  2094. X *
  2095. X * Returns   : Nothing.
  2096. X *
  2097. X */
  2098. Xvoid ReadImportSpec(dbname)
  2099. Xchar *dbname;
  2100. X{
  2101. X    int i;
  2102. X    char importspec_fname[256];
  2103. X
  2104. X    sprintf(importspec_fname, "%s.imp", dbname);
  2105. X
  2106. X    if( !(lex_file = fopen(importspec_fname, "r")) )
  2107. X        err_quit("Cannot open '%s'", importspec_fname);
  2108. X
  2109. X    yyparse();
  2110. X
  2111. X    fclose(outfile);
  2112. X}
  2113. X
  2114. X
  2115. X
  2116. Xstatic void Indent(level)
  2117. Xint level;
  2118. X{
  2119. X    fprintf(outfile, "%*s", (level+2) * 4, "");
  2120. X}
  2121. X
  2122. X
  2123. Xstatic PrintFields(str, nest)
  2124. XStructdef *str;
  2125. Xint nest;
  2126. X{
  2127. X    Field *fld = dbd.field + str->first_member;
  2128. X    int fields = str->members;
  2129. X    int old_fields = fields;
  2130. X    int rc;
  2131. X
  2132. X    while( fields-- )
  2133. X    {
  2134. X        if( FT_GETBASIC(fld->type) == FT_STRUCT )
  2135. X        {
  2136. X            Structdef *struc = dbd.structdef + fld->structid;
  2137. X
  2138. X            Indent(nest);
  2139. X            fprintf(outfile, "%s %s {\n", 
  2140. X                struc->is_union ? "union" : "struct", fld->name);
  2141. X            rc = PrintFields(struc, nest+1);
  2142. X            Indent(nest);
  2143. X            fprintf(outfile, "};\n");
  2144. X            old_fields += rc;
  2145. X            fld += rc;
  2146. X        }
  2147. X        else if( fld->nesting == nest )
  2148. X        {
  2149. X            Indent(nest);
  2150. X            fprintf(outfile, "%s;\n", fld->name);
  2151. X        }
  2152. X
  2153. X        fld++;
  2154. X    }
  2155. X
  2156. X    return old_fields;
  2157. X}
  2158. X
  2159. X
  2160. X
  2161. X
  2162. X/*--------------------------- GenerateImportSpec ---------------------------*\
  2163. X *
  2164. X * Purpose   : This function automatically generates a full import
  2165. X *             specification.
  2166. X *
  2167. X * Parameters: improtspec_fname     - Output file name.
  2168. X *
  2169. X * Returns   : Nothing.
  2170. X *
  2171. X */
  2172. Xvoid GenerateImportSpec(dbname)
  2173. Xchar *dbname;
  2174. X{
  2175. X    char importspec_fname[256];            
  2176. X    int i;
  2177. X    Record *rec = dbd.record;
  2178. X
  2179. X    printf("Generating import specification...");
  2180. X    fflush(stdout);
  2181. X
  2182. X    sprintf(importspec_fname, "%s.imp", dbname);
  2183. X
  2184. X    if( !(outfile = fopen(importspec_fname, "w")) )
  2185. X        err_quit("Cannot write to '%s'", importspec_fname);
  2186. X
  2187. X    fprintf(outfile, "import %s {\n\n", dbname); 
  2188. X
  2189. X    for( i=0; i<dbd.header.records; i++, rec++ )
  2190. X    {
  2191. X        fprintf(outfile, "    record %s in \"%.8s.kom\" {\n", rec->name, rec->name);
  2192. X
  2193. X        PrintFields(&dbd.structdef[rec->structid], 0);
  2194. X
  2195. X        fprintf(outfile, "    }\n\n");
  2196. X    }
  2197. X
  2198. X    fprintf(outfile, "}\n");
  2199. X    fclose(outfile);
  2200. X
  2201. X    puts("done");
  2202. X}
  2203. X
  2204. X/* end-of-file */
  2205. END_OF_FILE
  2206.   if test 4630 -ne `wc -c <'typhoon/src/util/impspec.c'`; then
  2207.     echo shar: \"'typhoon/src/util/impspec.c'\" unpacked with wrong size!
  2208.   fi
  2209.   # end of 'typhoon/src/util/impspec.c'
  2210. fi
  2211. echo shar: End of archive 6 \(of 9\).
  2212. cp /dev/null ark6isdone
  2213. MISSING=""
  2214. for I in 1 2 3 4 5 6 7 8 9 ; do
  2215.     if test ! -f ark${I}isdone ; then
  2216.     MISSING="${MISSING} ${I}"
  2217.     fi
  2218. done
  2219. if test "${MISSING}" = "" ; then
  2220.     echo You have unpacked all 9 archives.
  2221.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  2222. else
  2223.     echo You still must unpack the following archives:
  2224.     echo "        " ${MISSING}
  2225. fi
  2226. exit 0
  2227. exit 0 # Just in case...
  2228.