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

  1. From: zeppelin@login.dknet.dk (Thomas B. Pedersen)
  2. Newsgroups: comp.sources.misc
  3. Subject: v44i061:  typhoon - Typhoon Relational Database Management System, Part05/09
  4. Date: 17 Sep 1994 21:45:38 -0500
  5. Organization: Sterling Software
  6. Sender: kent@sparky.sterling.com
  7. Approved: kent@sparky.sterling.com
  8. Message-ID: <35g9ki$oi9@sparky.sterling.com>
  9. X-Md4-Signature: d73d96ed61a73ba445edf3b092f7997a
  10.  
  11. Submitted-by: zeppelin@login.dknet.dk (Thomas B. Pedersen)
  12. Posting-number: Volume 44, Issue 61
  13. Archive-name: typhoon/part05
  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/src/ty_dbd.h typhoon/src/ty_prot.h
  21. #   typhoon/src/ty_type.h typhoon/src/util/dbdview.c
  22. #   typhoon/src/util/fixlog.c typhoon/src/util/imp.y typhoon/src/vlr.c
  23. # Wrapped by kent@sparky on Sat Sep 17 21:38:17 1994
  24. PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin:$PATH ; export PATH
  25. echo If this archive is complete, you will see the following message:
  26. echo '          "shar: End of archive 5 (of 9)."'
  27. if test -f 'typhoon/src/ty_dbd.h' -a "${1}" != "-c" ; then 
  28.   echo shar: Will not clobber existing file \"'typhoon/src/ty_dbd.h'\"
  29. else
  30.   echo shar: Extracting \"'typhoon/src/ty_dbd.h'\" \(8076 characters\)
  31.   sed "s/^X//" >'typhoon/src/ty_dbd.h' <<'END_OF_FILE'
  32. X/*----------------------------------------------------------------------------
  33. X * File    : ty_dbd.h
  34. X * Library : typhoon
  35. X * OS      : UNIX, OS/2, DOS
  36. X * Author  : Thomas B. Pedersen
  37. X *
  38. X * Copyright (c) 1994 Thomas B. Pedersen.  All rights reserved.
  39. X *
  40. X * Permission is hereby granted, without written agreement and without
  41. X * license or royalty fees, to use, copy, modify, and distribute this
  42. X * software and its documentation for any purpose, provided that the above
  43. X * copyright notice and the following two  paragraphs appear (1) in all 
  44. X * source copies of this software and (2) in accompanying documentation
  45. X * wherever the programatic interface of this software, or any derivative
  46. X * of it, is described.
  47. X *
  48. X * IN NO EVENT SHALL THOMAS B. PEDERSEN BE LIABLE TO ANY PARTY FOR DIRECT,
  49. X * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF
  50. X * THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF HE HAS BEEN 
  51. X * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  52. X *
  53. X * THOMAS B. PEDERSEN SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT
  54. X * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  55. X * A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" 
  56. X * BASIS, AND THOMAS B. PEDERSEN HAS NO OBLIGATION TO PROVIDE MAINTENANCE,
  57. X * SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  58. X *
  59. X * Description:
  60. X *   Contains the definitions for the dbd-file.
  61. X *
  62. X * $Id: ty_dbd.h,v 1.1 1994/09/13 21:28:33 tbp Exp $
  63. X *
  64. X * $Log: ty_dbd.h,v $
  65. X * Revision 1.1  1994/09/13  21:28:33  tbp
  66. X * Added to repository.
  67. X * 
  68. X *
  69. X *--------------------------------------------------------------------------*/
  70. X
  71. X/*-------------------------------- Constants -------------------------------*/
  72. X#define DBD_VERSION    "Typhoon 2.02"
  73. X#define DBDVERSION_LEN    20        /* Version name of dbd-file                    */
  74. X#define DBNAME_LEN        8        /* Maximum database name length                */
  75. X#define IDENT_LEN        32        /* Identifier length                        */
  76. X#define FILENAME_LEN    12        /* OS dependent file name length            */
  77. X#define KEYSIZE_MAX     255     /* Maximum size of a key                    */
  78. X#define RECSIZE_MAX     64000   /* Maximum size of a record                 */
  79. X#define RECKEYS_MAX        32        /* Maximum number of keys per record        */
  80. X#define REC_FACTOR        1000L    /* rec 1 is 1000, rec 2 is 2000 etc.        */
  81. X#define SORTTABLE_SIZE    256        /* Number of entries in sort table            */
  82. X
  83. X/*------------------------------- Field types ------------------------------*/
  84. X#define FT_CHAR            0x01    /* The first three bits are for type        */
  85. X#define FT_CHARSTR        0x02    /*         char string                            */
  86. X#define FT_SHORT        0x03    /*         short                                */
  87. X#define FT_INT            0x04    /*         int                                     */
  88. X#define FT_LONG            0x05    /*         long                                */
  89. X#define FT_FLOAT        0x06    /*        float                                */
  90. X#define FT_DOUBLE        0x07    /*        double                                */
  91. X#define FT_LDOUBLE        0x08    /*        long double (not used)                */
  92. X#define FT_STRUCT        0x09    /* The type is a structure                    */
  93. X#define FT_UNSIGNED        0x10    /* Bit 4 is unsigned bit                    */
  94. X#define FT_KEY            0x20    /* Field is a key field                        */
  95. X#define FT_UNIQUE        0x40    /* Field is a unique key field                */
  96. X#define FT_VARIABLE        0x80    /* Field has variable length (only 1-arrays)*/
  97. X
  98. X#define FT_BASIC        0x0f    /* Bits occupied by integral types            */
  99. X#define FT_GETBASIC(f)    ((f)& FT_BASIC)    /* Extracts the integral type         */
  100. X#define FT_GETSIGNEDBASIC(f)  ((f) & (FT_BASIC|FT_UNSIGNED))
  101. X
  102. X/*-------------------------------- Key types -------------------------------*/
  103. X#define KT_PRIMARY        0x01    /* Primary key (preceedes alternate in key[]*/
  104. X#define KT_ALTERNATE    0x02    /* Alternate key (preceedes foreign in key[]*/
  105. X#define KT_FOREIGN        0x03    /* Foreign key                                */
  106. X#define KT_CASCADE        0x08    /* Used with KT_FOREIGN                        */
  107. X#define KT_RESTRICT        0x10    /* Used with KT_FOREIGN                        */
  108. X#define KT_OPTIONAL        0x20    /* Used with KT_FOREIGN and KT_ALTERNATE    */
  109. X#define KT_UNIQUE      FT_UNIQUE    /* Must be the same bit as FT_UNIQUE        */
  110. X
  111. X#define KT_BASIC        0x03    /* The bits occupied by basic types            */
  112. X#define KT_GETBASIC(k)    ((k)&KT_BASIC)    /* Extracts the type of the key         */
  113. X
  114. X
  115. X#define KEY_ISFOREIGN(key)        (KT_GETBASIC(key->type) == KT_FOREIGN)
  116. X#define KEY_ISALTERNATE(key)    (KT_GETBASIC(key->type) == KT_ALTERNATE)
  117. X#define KEY_ISOPTIONAL(key)        (key->type & KT_OPTIONAL)
  118. X
  119. X
  120. X#define RECID_TO_INTERN(id)        ((id)/REC_FACTOR-1)
  121. X#define INTERN_TO_RECID(id)        (((id)+1)*REC_FACTOR)
  122. X
  123. X
  124. Xtypedef unsigned long    Id;        /* Identifies an element in the dbd file    */
  125. X
  126. Xtypedef struct {
  127. X    uchar    version[DBDVERSION_LEN];    /* Version of dbd-file                */
  128. X    ushort    files;                /* Number of files in database                */
  129. X    ushort    keys;                /* Number of key definitions                */
  130. X    ushort    keyfields;            /* Number of key fields                     */
  131. X    ushort    records;            /* Number of records in database            */
  132. X    ushort    fields;                /* Number of fields in database                */
  133. X    ushort    structdefs;            /* Number of structdefs in database            */
  134. X    uchar    sorttable[SORTTABLE_SIZE];
  135. X    char    alignment;            /* Structure alignment                        */
  136. X    char    spare[19];            /* Not used                                    */
  137. X} Header;
  138. X
  139. Xtypedef struct {
  140. X    Id        fileid;                /* File id                                    */
  141. X    ushort    entry;                /* Entry in field[] or record[]                */
  142. X    ushort    line;                /* The line where it was defined            */
  143. X    char    type;                /* 'd'=data, 'k'=key, 'r'=ref                */
  144. X    char    record[IDENT_LEN+1];/* Record name                                */
  145. X    char    key[IDENT_LEN+1];    /* Key name. Only applicable if type is 'k' */
  146. X} Contains;
  147. X
  148. X
  149. Xtypedef struct {
  150. X    Id        id;                    /* Record/Key id                            */
  151. X    ushort    pagesize;            /* Page size                                */
  152. X    char    type;                /* 'd'=data, 'v'=vlr, 'k'=key, 'r'=ref file    */
  153. X    char    name[FILENAME_LEN+1];/* Name of file                            */
  154. X    char    spare[16];
  155. X} File;
  156. X
  157. Xtypedef struct {
  158. X    Id        recid;                /* The record it is a member of                */
  159. X    Id        keyid;                /* a) Key ID if field is a key                */
  160. X                                /* b) If the field is of variable length    */
  161. X                                /*      keyid denotes the size field (since a    */
  162. X                                /*      variable length field cannot be a key)*/
  163. X                                /*    field.type & FT_VARIABLE                */
  164. X    Id        structid;             /* ID of struct if type is FT_STRUCT        */
  165. X    ushort    offset;                /* Byte offset in record                    */
  166. X    ushort    size;                /* Size of field                            */
  167. X    ushort  elemsize;           /* Size of each element                     */
  168. X    ushort    type;                /* Field type. See FT_.. constants            */
  169. X    uchar    nesting;            /* Structure nesting. 0=first level            */
  170. X    uchar    spare2[4];
  171. X    char    name[IDENT_LEN+1];    /* Field name                                */
  172. X} Field;
  173. X
  174. Xtypedef struct {
  175. X    Id        fileid;
  176. X    Id        first_keyfield;        /* Index of KeyField                        */
  177. X    Id        parent;                /* Only applicable if type = KT_FOREIGN        */
  178. X    ushort    fields;                /* Number of fields in compound key            */
  179. X    ushort    size;                /* Total key size                            */
  180. X    ushort    null_indicator;        /* ID of null indicator field of FT_OPTIONAL*/
  181. X    uchar    spare[14];
  182. X    uchar    type;                /* See KT_... flags                            */
  183. X    char    name[IDENT_LEN+1];    /* Name of key                                */
  184. X} Key;
  185. X
  186. Xtypedef struct {
  187. X    Id        field;                /* Field id                                    */
  188. X    ushort    offset;             /* Offset in compound key                    */
  189. X    short    asc;                /* 1=ascending, '0'=descending                */
  190. X    uchar    spare[4];
  191. X} KeyField;
  192. X
  193. Xtypedef struct {
  194. X    Id        fileid;                /* Id of file record is contained in        */
  195. X    Id        first_field;        /* Id of first field                        */
  196. X    Id        first_key;            /* Id of first key                            */
  197. X    Id        first_foreign;        /* Id of first foreign key (-1 = no foreign)*/
  198. X    Id        ref_file;            /* Id of reference file (-1 = no ref file)    */
  199. X    Id        structid;            /* Id of structure defining record            */
  200. X    ushort    dependents;            /* Number of dependent tables                */
  201. X    ushort    fields;                /* Number of fields                            */
  202. X    ushort  keys;               /* Number of keys                           */
  203. X    ushort    size;                /* Size of record                            */
  204. X    ushort    preamble;            /* Number of bytes used preamble information*/
  205. X    uchar    aux;                /* Not used by Typhoon                        */
  206. X    uchar    spare[15];
  207. X    char    is_vlr;             /* Is record of variable length?            */
  208. X    char    name[IDENT_LEN+1];
  209. X} Record;
  210. X
  211. Xtypedef struct {
  212. X    Id        first_member;        /* First struct member (Field[])            */
  213. X    Id        members;            /* First struct member (Field[])            */
  214. X    Id        control_field;        /* If is_union this is the control field    */
  215. X    ushort    size;                /* Struct size                                */
  216. X    char    is_union;            /* Is the structure a union?                */
  217. X    char    name[IDENT_LEN+1];    /* Structure name                            */
  218. X} Structdef;
  219. X
  220. X/* end-of-file */
  221. END_OF_FILE
  222.   if test 8076 -ne `wc -c <'typhoon/src/ty_dbd.h'`; then
  223.     echo shar: \"'typhoon/src/ty_dbd.h'\" unpacked with wrong size!
  224.   fi
  225.   # end of 'typhoon/src/ty_dbd.h'
  226. fi
  227. if test -f 'typhoon/src/ty_prot.h' -a "${1}" != "-c" ; then 
  228.   echo shar: Will not clobber existing file \"'typhoon/src/ty_prot.h'\"
  229. else
  230.   echo shar: Extracting \"'typhoon/src/ty_prot.h'\" \(8130 characters\)
  231.   sed "s/^X//" >'typhoon/src/ty_prot.h' <<'END_OF_FILE'
  232. X/*----------------------------------------------------------------------------
  233. X * File    : ty_prot.h
  234. X * Library : typhoon
  235. X * OS      : UNIX, OS/2, DOS
  236. X * Author  : Thomas B. Pedersen
  237. X *
  238. X * Copyright (c) 1994 Thomas B. Pedersen.  All rights reserved.
  239. X *
  240. X * Permission is hereby granted, without written agreement and without
  241. X * license or royalty fees, to use, copy, modify, and distribute this
  242. X * software and its documentation for any purpose, provided that the above
  243. X * copyright notice and the following two  paragraphs appear (1) in all 
  244. X * source copies of this software and (2) in accompanying documentation
  245. X * wherever the programatic interface of this software, or any derivative
  246. X * of it, is described.
  247. X *
  248. X * IN NO EVENT SHALL THOMAS B. PEDERSEN BE LIABLE TO ANY PARTY FOR DIRECT,
  249. X * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF
  250. X * THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF HE HAS BEEN 
  251. X * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  252. X *
  253. X * THOMAS B. PEDERSEN SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT
  254. X * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  255. X * A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" 
  256. X * BASIS, AND THOMAS B. PEDERSEN HAS NO OBLIGATION TO PROVIDE MAINTENANCE,
  257. X * SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  258. X *
  259. X * Description:
  260. X *   Contains function prototypes.
  261. X *
  262. X * $Id: ty_prot.h,v 1.1 1994/09/13 21:28:37 tbp Exp $
  263. X *
  264. X * $Log: ty_prot.h,v $
  265. X * Revision 1.1  1994/09/13  21:28:37  tbp
  266. X * Added to repository.
  267. X * 
  268. X *
  269. X *--------------------------------------------------------------------------*/
  270. X
  271. X/*-------------------------------- Constants -------------------------------*/
  272. X#define UNCOMPRESS    0                    /* Command to compress_vlr()        */
  273. X#define COMPRESS    1                    /* Command to compress_vlr()        */
  274. X
  275. X/*------------------------------- ty_auxfn.c -------------------------------*/
  276. Xint         aux_getkey        PRM( (Id, Key **);                                )
  277. Xint         report_err        PRM( (int);                                        )
  278. Xvoid     set_subcode    PRM( (Key *);                                    )
  279. Xint         set_recfld        PRM( (Id, Record **, Field **);                    )
  280. Xvoid     *set_keyptr        PRM( (Key *, void *);                            )
  281. Xint         keyfind        PRM( (Key *, void *, ulong *);                    )
  282. Xint         keyadd            PRM( (Key *, void *, ulong);                    )
  283. Xint         keydel            PRM( (Key *, void *, ulong);                    )
  284. Xint         reckeycmp        PRM( (Key *, void *, void *);                    )
  285. Xint         compress_vlr    PRM( (int, Record *, void *, void *, unsigned *);)
  286. Xint         null_indicator    PRM( (Key *, void *);                            )
  287. Xint         update_recbuf  PRM( (void);                                    )
  288. X
  289. X
  290. X/*------------------------------- ty_refin.c -------------------------------*/
  291. Xvoid     update_foreign_keys    PRM( (Record *, int);                    )
  292. Xint         check_foreign_keys     PRM( (Record *, void *, int);            )
  293. Xvoid     delete_foreign_keys    PRM( (Record *);                        )
  294. Xint         check_dependent_tables PRM( (Record *, void *, int);             )
  295. X
  296. X
  297. X/*--------------------------------- ty_io.c --------------------------------*/
  298. Xint      ty_openfile    PRM( (File *, Fh *, int);                          )
  299. Xint      ty_closefile   PRM( (Fh *);                                      )
  300. Xint         ty_keyadd        PRM( (Key *, void *, ulong);                            )
  301. Xint      ty_keydel      PRM( (Key *, void *, ulong);                            )
  302. Xint         ty_keyfind        PRM( (Key *, void *, ulong *);                          )
  303. Xint         ty_keyread        PRM( (Key *, void *);                                 )
  304. Xint         ty_keyfrst        PRM( (Key *, ulong *);                                 )
  305. Xint         ty_keylast        PRM( (Key *, ulong *);                                    )
  306. Xint         ty_keynext        PRM( (Key *, ulong *);                                 )
  307. Xint         ty_keyprev        PRM( (Key *, ulong *);                                    )
  308. Xint         ty_recadd      PRM( (Record *, void *, ulong *);                  )
  309. Xint      ty_recwrite    PRM( (Record *, void *, ulong);                      )
  310. Xint      ty_recread     PRM( (Record *, void *, ulong);                      )
  311. Xint      ty_recread     PRM( (Record *, void *, ulong);                      )
  312. Xint      ty_recdelete   PRM( (Record *, ulong);                              )
  313. Xulong    ty_numrecords  PRM( (Record *, ulong *);                        )
  314. Xint      ty_recfrst     PRM( (Record *, void *);                        )
  315. Xint      ty_reclast     PRM( (Record *, void *);                        )
  316. Xint      ty_recnext     PRM( (Record *, void *);                        )
  317. Xint      ty_recprev     PRM( (Record *, void *);                        )
  318. Xint         ty_vlradd        PRM( (Record *, void *, unsigned, ulong *);        )
  319. Xint         ty_vlrwrite    PRM( (Record *, void *, unsigned, ulong);         )
  320. Xunsigned ty_vlrread        PRM( (Record *, void *, ulong, unsigned *);        )
  321. Xint         ty_vlrdel        PRM( (Record *, ulong);                            )
  322. Xint         ty_reccurr        PRM( (Record *, ulong *);                        )
  323. Xint         ty_closeafile    PRM( (void); )
  324. X
  325. Xvoid     ty_logerror    PRM( (char *, ...); )
  326. X
  327. X/*------------------------------- ty_repl.c --------------------------------*/
  328. Xvoid     ty_log            PRM( (int); )
  329. X
  330. X
  331. X/*--------------------------------- bt_open --------------------------------*/
  332. Xvoid    btree_getheader    PRM( (INDEX *);                                    )
  333. Xvoid    btree_putheader    PRM( (INDEX *);                                    )
  334. XINDEX  *btree_open        PRM( (char *, int, int, CMPFUNC, int, int);        )
  335. Xvoid    btree_close        PRM( (INDEX *);                                    )
  336. Xint        btree_dynopen    PRM( (INDEX *);                                    )
  337. Xint        keydynclose        PRM( (INDEX *);                                    )
  338. Xint        nodesearch        PRM( (INDEX *, void *, int *);                    )
  339. Xint        d_search        PRM( (INDEX *, void *, ix_addr *, int *);        )
  340. X
  341. X/*------------------------------- bt_fucns.c -------------------------------*/
  342. Xint        btree_add        PRM( (INDEX *, void *, ulong);                    )
  343. Xint        btree_find        PRM( (INDEX *, void *, ulong *);                )
  344. Xint        btree_read        PRM( (INDEX *, void *);                            )
  345. Xint        btree_write        PRM( (INDEX *, void *);                            )
  346. Xint        btree_delall    PRM( (INDEX *);                                    )
  347. Xint        btree_frst        PRM( (INDEX *, ulong *);                        )
  348. Xint        btree_last        PRM( (INDEX *, ulong *);                        )
  349. Xint        btree_next        PRM( (INDEX *, ulong *);                        )
  350. Xint        btree_prev        PRM( (INDEX *, ulong *);                        )
  351. Xint     btree_exist        PRM( (INDEX *, void *, ulong);                  )
  352. X
  353. X/*-------------------------------- bt_del.c --------------------------------*/
  354. Xint     btree_del        PRM( (INDEX *, void *, ulong);                    )
  355. X
  356. X/*--------------------------------- bt_io.c --------------------------------*/
  357. Xix_addr noderead        PRM( (INDEX *, char *, ix_addr);                )
  358. Xix_addr nodewrite       PRM( (INDEX *, char *, ix_addr);                )
  359. X
  360. X/*-------------------------------- record.c --------------------------------*/
  361. XRECORD  *rec_open         PRM( (char *, unsigned, int);                    )
  362. Xint      rec_close        PRM( (RECORD *);                                )
  363. Xint         rec_add          PRM( (RECORD *, void *, ulong *);                )
  364. Xint      rec_write        PRM( (RECORD *, void *, ulong);                    )
  365. Xint      rec_read         PRM( (RECORD *, void *, ulong);                    )
  366. Xint      rec_delete       PRM( (RECORD *, ulong);                            )
  367. Xint      rec_curr         PRM( (RECORD *, ulong *);                        )
  368. Xulong    rec_numrecords    PRM( (RECORD *, ulong *);                        )
  369. Xint      rec_frst         PRM( (RECORD *, void *);                        )
  370. Xint      rec_last         PRM( (RECORD *, void *);                        )
  371. Xint      rec_next         PRM( (RECORD *, void *);                        )
  372. Xint      rec_prev         PRM( (RECORD *, void *);                        )
  373. Xint         rec_lock        PRM( (RECORD *, ulong, int);                     )
  374. Xint         rec_unlock        PRM( (RECORD *, ulong);                            )
  375. X
  376. X/*---------------------------------- vlr.c ---------------------------------*/
  377. Xvoid     vlr_close        PRM( (VLR *);                                    )
  378. XVLR        *vlr_open        PRM( (char *, unsigned, int);                    )
  379. Xint         vlr_add        PRM( (VLR *, void *, unsigned, ulong *);        )
  380. Xint         vlr_write        PRM( (VLR *, void *, unsigned, ulong);            )
  381. Xint         vlr_read        PRM( (VLR *, void *, ulong, unsigned *);        )
  382. Xint         vlr_del        PRM( (VLR *, ulong);                            )
  383. X
  384. X/*---------------------------------- os.c ----------------------------------*/
  385. Xint        os_lock            PRM( (int, long, unsigned, int);                )
  386. Xint        os_unlock        PRM( (int, long, unsigned);                        )
  387. Xint        os_open            PRM( (char *, int, int);                        )
  388. Xint        os_close        PRM( (int); )
  389. X
  390. X
  391. X/*--------------------------------- osxxx.c --------------------------------*/
  392. Xint        ty_openlock        PRM( (void);                                    )
  393. Xint        ty_closelock    PRM( (void);                                    )
  394. Xint        ty_lock            PRM( (void);                                    )
  395. Xint        ty_unlock        PRM( (void);                                    )
  396. Xint        shm_alloc        PRM( (Dbentry *);                                )
  397. Xint        shm_free        PRM( (Dbentry *);                                )
  398. X
  399. X
  400. X/*------------------------------- cmpfuncs.c -------------------------------*/
  401. Xint     compoundkeycmp    PRM( (void *, void *);                            )
  402. Xint        refentrycmp        PRM( (REF_ENTRY *, REF_ENTRY *);                )
  403. Xvoid    InitLowerTable  PRM( (void);                                    )
  404. X
  405. X/* end-of-file */
  406. END_OF_FILE
  407.   if test 8130 -ne `wc -c <'typhoon/src/ty_prot.h'`; then
  408.     echo shar: \"'typhoon/src/ty_prot.h'\" unpacked with wrong size!
  409.   fi
  410.   # end of 'typhoon/src/ty_prot.h'
  411. fi
  412. if test -f 'typhoon/src/ty_type.h' -a "${1}" != "-c" ; then 
  413.   echo shar: Will not clobber existing file \"'typhoon/src/ty_type.h'\"
  414. else
  415.   echo shar: Extracting \"'typhoon/src/ty_type.h'\" \(9030 characters\)
  416.   sed "s/^X//" >'typhoon/src/ty_type.h' <<'END_OF_FILE'
  417. X/*----------------------------------------------------------------------------
  418. X * File    : ty_type.h
  419. X * Library : typhoon
  420. X * OS      : UNIX, OS/2, DOS
  421. X * Author  : Thomas B. Pedersen
  422. X *
  423. X * Copyright (c) 1994 Thomas B. Pedersen.  All rights reserved.
  424. X *
  425. X * Permission is hereby granted, without written agreement and without
  426. X * license or royalty fees, to use, copy, modify, and distribute this
  427. X * software and its documentation for any purpose, provided that the above
  428. X * copyright notice and the following two  paragraphs appear (1) in all 
  429. X * source copies of this software and (2) in accompanying documentation
  430. X * wherever the programatic interface of this software, or any derivative
  431. X * of it, is described.
  432. X *
  433. X * IN NO EVENT SHALL THOMAS B. PEDERSEN BE LIABLE TO ANY PARTY FOR DIRECT,
  434. X * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF
  435. X * THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF HE HAS BEEN 
  436. X * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  437. X *
  438. X * THOMAS B. PEDERSEN SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT
  439. X * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  440. X * A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" 
  441. X * BASIS, AND THOMAS B. PEDERSEN HAS NO OBLIGATION TO PROVIDE MAINTENANCE,
  442. X * SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  443. X *
  444. X * Description:
  445. X *   Contains file descriptor definition for the B-tree, record and vlr 
  446. X *   modules.
  447. X *
  448. X * $Id: ty_type.h,v 1.2 1994/09/17 16:00:20 tbp Exp $
  449. X *
  450. X * $Log: ty_type.h,v $
  451. X * Revision 1.2  1994/09/17  16:00:20  tbp
  452. X * typhoon.h and environ.h are now included from <>.
  453. X *
  454. X * Revision 1.1  1994/09/13  21:28:38  tbp
  455. X * Added to repository.
  456. X * 
  457. X *
  458. X *--------------------------------------------------------------------------*/
  459. X
  460. X#include <environ.h>
  461. X
  462. X/*---------- Internal constants --------------------------------------------*/
  463. X#define DB_MAX            10        /* Maximum number of concurrent databases    */
  464. X#define BTREE_DEPTH_MAX    10        /* Maximum B-tree depth                        */
  465. X#define BIT_DELETED        0x01
  466. X
  467. X/*---------- Macros --------------------------------------------------------*/
  468. X#define FREE(p)            if( p ) free(p)
  469. X#define RETURN          return db_status =
  470. X#define RETURN_RAP(v)    return report_err(v);
  471. X
  472. X/*---------- Structures ----------------------------------------------------*/
  473. Xtypedef ulong ix_addr;
  474. Xtypedef int (*CMPFUNC)PRM((void *, void *));
  475. Xtypedef struct {
  476. X    char    type;                      /* = 'k'                                */
  477. X    ulong    seqno;                    /* Sequence number                        */
  478. X    int     fh;                     /* File handle                          */
  479. X    char    fname[80];              /* File name                            */
  480. X    struct {                        /* Index file header                    */
  481. X        char    id[16];             /* Version id                           */
  482. X        ushort  version;            /* Version number                       */
  483. X        ix_addr first_deleted;      /* Pointer to first node in delete list */
  484. X        ushort  nodesize;           /* Node size                            */
  485. X        ushort  keysize;               /* Size of key in bytes                 */
  486. X        ushort  order;                  /* Node order                           */
  487. X        ushort  dups;               /* Duplicate keys allowed?              */
  488. X        ulong    keys;                /* Number of keys in index                */
  489. X        ulong    timestamp;            /* Timestamp. Changed by d_keyadd/del()    */
  490. X        char    spare[2];            /* Not used                                */
  491. X    } H;
  492. X    CMPFUNC cmpfunc;                /* Comparison function                  */
  493. X    struct {                        /* Path to current node and key            */
  494. X        ix_addr a;                  /* Node address                         */
  495. X        ushort  i;                  /* Node index                           */
  496. X    } path[BTREE_DEPTH_MAX+1];
  497. X    int        level;                  /* Path level                           */
  498. X    int        shared;                    /* Opened in shared mode?                */
  499. X    int        tsize;                  /* Tuple size                           */
  500. X    int        aligned_keysize;        /* Aligned keysize                        */
  501. X    int        curr;                   /* Do we have a current key?            */
  502. X    int        hold;                    /* Used by d_keynext and d_keyprev        */
  503. X    char   *curkey;                    /* 'current key' buffer                    */
  504. X    char    node[1];                /* This array is size nodesize          */
  505. X} INDEX;
  506. X
  507. Xtypedef struct {                    /* Record head (found in every record)    */
  508. X    ulong        prev;                /* Pointer to previous record           */
  509. X    ulong        next;                /* Pointer to next record               */
  510. X    char        flags;                /* Delete bit                            */
  511. X    char        data[1];            /* Record data. this field MUST be the  */
  512. X} RECORDHEAD;                        /* Last field in the RECORD structure   */
  513. X
  514. Xtypedef struct {
  515. X    char            type;            /* = 'd'                                */
  516. X    ulong            seqno;            /* Sequence number                        */
  517. X    int             fh;                /* File handle                            */
  518. X    char            fname[80];        /* File name                            */
  519. X    struct {
  520. X        char        id[16];         /* Version id                           */
  521. X        ushort      version;        /* Record file version number           */
  522. X        ulong       first_deleted;  /* Pointer to first deleted record      */
  523. X        ulong       first;          /* Pointer to first record in chain     */
  524. X        ulong       last;           /* Pointer to last record in chain      */
  525. X        ulong       numrecords;     /* Number of records in file            */
  526. X        ushort      datasize;       /* Size of data block                   */
  527. X        ushort      recsize;        /* Size of record (and chain)           */
  528. X    } H;
  529. X    int                first_possible_rec;    /* Record number of the first        */
  530. X                                    /* record in the file                    */
  531. X    int                share;            /* Opened in shared mode?                */
  532. X    ulong           recno;          /* Current record number. 0 = no current*/
  533. X    RECORDHEAD        rec;
  534. X} RECORD;
  535. X
  536. X/*--------------------------------------------------------------------------*/
  537. X/*                 Variable Length Record file structures                   */
  538. X/*--------------------------------------------------------------------------*/
  539. Xtypedef struct {
  540. X    ulong            nextblock;        /* Pointer to next block                */
  541. X    unsigned        recsize;        /* Size of record                        */
  542. X    char            data[1];        /* Data                                 */
  543. X} VLRBLOCK;
  544. X
  545. Xtypedef struct {
  546. X    char            type;            /* = 'v'                                */
  547. X    ulong            seqno;             /* Sequence number                        */
  548. X    int             fh;                /* File handle                            */
  549. X    char            fname[80];        /* File name                            */
  550. X    int                shared;            /* Opened in shared mode?                */
  551. X    unsigned        datasize;        /* Number of bytes in each block        */
  552. X    VLRBLOCK        *block;            /* Pointer to buffer                    */
  553. X    struct {
  554. X        char        version[32];    /* VLR version number                    */
  555. X        char        id[32];         /* User provided ID                     */
  556. X        unsigned    blocksize;        /* Block size                            */
  557. X        ulong        firstfree;        /* First free data block                */
  558. X        ulong        numrecords;        /* Number of records in file            */
  559. X    } header;
  560. X} VLR;
  561. X
  562. Xtypedef union {
  563. X    struct {
  564. X        char     type;                /* 'd' = data,, 'k' = key, 'v'=vlr file    */
  565. X        ulong    seqno;                /* Sequence number                        */
  566. X        int        fh;
  567. X    } *any;
  568. X    INDEX        *key;                /* Index File Descriptor                */
  569. X    RECORD        *rec;                /* Record File Descriptor                */
  570. X    VLR         *vlr;               /* Variable Length Record Descriptor    */
  571. X} Fh;
  572. X
  573. Xtypedef struct {
  574. X    int            use_count;            /* First remove shared memory when 0    */
  575. X    int            backup_active;
  576. X    int            restore_active;
  577. X    ulong        curr_recid;
  578. X    ulong        curr_recno;
  579. X    ulong        num_trans_active;
  580. X    char        spare[96];
  581. X} SharedMemory;
  582. X
  583. Xtypedef struct {                    /* Database table entry                    */
  584. X    char        name[15];            /* Database name                        */
  585. X    char        mode;                /* [s]hared, [o]ne user, e[x]clusive    */
  586. X    char        clients;            /* Number of clients using this database*/
  587. X    char        dbfpath[256];        /* Database file path                    */
  588. X    char        logging;            /* Is replication logging on?            */
  589. X    uchar        prog_id;            /* Program ID (used with logging)        */
  590. X    ulong        curr_rec;            /* These 4 fields hold curr_ variables    */
  591. X    ulong        curr_recid;            /* when the database is not the current    */
  592. X    ulong        curr_bufrec;
  593. X    ulong        curr_bufrecid;
  594. X    int            db_status;
  595. X    Header        header;
  596. X    void        *dbd;
  597. X    Fh            *fh;                /* Array [dbentry.files] of handles        */
  598. X    File        *file;
  599. X    Record        *record;
  600. X    Field        *field;
  601. X    Key         *key;
  602. X    KeyField    *keyfield;
  603. X    Structdef    *structdef;
  604. X    SharedMemory *shm;
  605. X    int            shm_id;
  606. X    char        *recbuf;            /* This points to where the actual data    */
  607. X                                    /* starts (bypassing foreign key refs)    */
  608. X    char          *real_recbuf;        /* This points to the real start of the    */
  609. X                                    /* buffer                                */
  610. X} Dbentry;
  611. X
  612. Xtypedef struct {
  613. X    ulong        parent;                /* Address of parent record                */
  614. X    DB_ADDR        dependent;            /* Address of dependent record            */
  615. X} REF_ENTRY;
  616. X
  617. X
  618. X
  619. Xtypedef struct {
  620. X    Dbentry     dbtab[DB_MAX];                    /* Database table                */
  621. X    Dbentry    *db;                            /* Current database                */
  622. X
  623. X    int         do_rebuild;                    /* Rebuild indexes on d_open()?    */
  624. X    int         dbs_open;
  625. X
  626. X    int         cur_open;                        /* Current number of open files    */
  627. X    int         max_open;                        /* Maximum number of open files    */
  628. X
  629. X    ulong     curr_keybuf[KEYSIZE_MAX/sizeof(long)];
  630. X
  631. X    Id         curr_key;                        /* Current key. It is            */
  632. X                                            /* used to tell compoundkeycmp    */
  633. X                                            /* which key is being compared    */
  634. X    int         curr_db;                        /* Current database             */
  635. X    void    (*ty_errfn)        PRM( (int,long); )
  636. X
  637. X    char      dbfpath[256];
  638. X    char      dbdpath[256];
  639. X} TyphoonGlobals;
  640. X
  641. X
  642. X/* end-of-file */
  643. X
  644. END_OF_FILE
  645.   if test 9030 -ne `wc -c <'typhoon/src/ty_type.h'`; then
  646.     echo shar: \"'typhoon/src/ty_type.h'\" unpacked with wrong size!
  647.   fi
  648.   # end of 'typhoon/src/ty_type.h'
  649. fi
  650. if test -f 'typhoon/src/util/dbdview.c' -a "${1}" != "-c" ; then 
  651.   echo shar: Will not clobber existing file \"'typhoon/src/util/dbdview.c'\"
  652. else
  653.   echo shar: Extracting \"'typhoon/src/util/dbdview.c'\" \(8730 characters\)
  654.   sed "s/^X//" >'typhoon/src/util/dbdview.c' <<'END_OF_FILE'
  655. X/*----------------------------------------------------------------------------
  656. X * File    : dbdview.c
  657. X * Program : dbdview
  658. X * OS      : UNIX, OS/2, DOS
  659. X * Author  : Thomas B. Pedersen
  660. X *
  661. X * Copyright (c) 1994 Thomas B. Pedersen.  All rights reserved.
  662. X *
  663. X * Permission is hereby granted, without written agreement and without
  664. X * license or royalty fees, to use, copy, modify, and distribute this
  665. X * software and its documentation for any purpose, provided that the above
  666. X * copyright notice and the following two  paragraphs appear (1) in all 
  667. X * source copies of this software and (2) in accompanying documentation
  668. X * wherever the programatic interface of this software, or any derivative
  669. X * of it, is described.
  670. X *
  671. X * IN NO EVENT SHALL THOMAS B. PEDERSEN BE LIABLE TO ANY PARTY FOR DIRECT,
  672. X * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF
  673. X * THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF HE HAS BEEN 
  674. X * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  675. X *
  676. X * THOMAS B. PEDERSEN SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT
  677. X * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  678. X * A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" 
  679. X * BASIS, AND THOMAS B. PEDERSEN HAS NO OBLIGATION TO PROVIDE MAINTENANCE,
  680. X * SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  681. X *
  682. X * Description:
  683. X *   Small utility that dumps a dbd-file.
  684. X *
  685. X * $Log: dbdview.c,v $
  686. X * Revision 1.2  1994/09/17  16:00:50  tbp
  687. X * typhoon.h and environ.h are now included from <>.
  688. X *
  689. X * Revision 1.1  1994/09/13  21:28:50  tbp
  690. X * Added to repository.
  691. X *
  692. X * Added to repository.
  693. X * 
  694. X *
  695. X *--------------------------------------------------------------------------*/
  696. X
  697. Xstatic char rcsid[] = "$Id: dbdview.c,v 1.2 1994/09/17 16:00:50 tbp Exp $";
  698. X
  699. X#ifdef UNIX
  700. X#  include <malloc.h>
  701. X#else
  702. X#  include <stdlib.h>
  703. X#  include <io.h>
  704. X#endif
  705. X#include <stdio.h>
  706. X#include <fcntl.h>
  707. X#include <string.h>
  708. X#include <environ.h>
  709. X#include "../ty_dbd.h"
  710. X#include "ddlp.h"
  711. X#define FREE(p)        if( p ) free(p)
  712. X
  713. X
  714. X/*-------------------------- Function prototypes ---------------------------*/
  715. Xstatic void            viewdbd     PRM( (int); )
  716. X
  717. X/*---------------------------- Global variables ----------------------------*/
  718. Xstatic Header         header;
  719. Xstatic Field        *fieldtab;
  720. Xstatic Record        *recordtab;
  721. Xstatic File            *filetab;
  722. Xstatic Key             *keytab;
  723. Xstatic KeyField        *keyfieldtab;
  724. Xstatic Structdef    *structtab;
  725. X
  726. X
  727. X
  728. X/*--------------------------------------------------------------------------*\
  729. X *
  730. X * Function  : strstr
  731. X *
  732. X * Purpose   : ANSI C strstr() implementation.
  733. X *
  734. X * Parameters: s1    - String to search.
  735. X *               s2    - String to search for.
  736. X *
  737. X * Returns   : A pointer to the found substring otherwise NULL.
  738. X *
  739. X */
  740. X#ifdef UNIX
  741. X#ifndef __STDC__
  742. Xstatic char *strstr(s1, s2)
  743. Xchar *s1, *s2;
  744. X{
  745. X    int len = strlen(s2);
  746. X
  747. X    while( *s1 )
  748. X    {
  749. X        if( *s2 == *s1 )
  750. X            if( !memcmp(*s1,s2,len) )
  751. X                return s1;
  752. X        s1++;
  753. X    }
  754. X    return NULL;
  755. X}
  756. X#endif
  757. X#endif
  758. X
  759. X
  760. X/*--------------------------------------------------------------------------*\
  761. X *
  762. X * Function  : viewdbd
  763. X *
  764. X * Purpose   : View the tables in the dbd-file.
  765. X *
  766. X * Parameters: dbdfile    - File handle.
  767. X *
  768. X * Returns   : Nothing.
  769. X *
  770. X */
  771. Xstatic void viewdbd(dbdfile)
  772. Xint dbdfile;
  773. X{
  774. X    static char *key_type[] = {
  775. X        "primary",
  776. X        "altern.",
  777. X        "foreign",
  778. X        "referen"
  779. X    };
  780. X    char type[50];
  781. X    int i, j, n;
  782. X    Key *key;
  783. X    Field *field;
  784. X    Record *record;
  785. X    Structdef *struc;
  786. X
  787. X    read(dbdfile, &header, sizeof header);
  788. X
  789. X    if( strcmp(header.version, DBD_VERSION) )
  790. X    {
  791. X        puts("Illegal version ID");
  792. X        return;
  793. X    }
  794. X
  795. X
  796. X    printf("%d files\n", header.files);
  797. X    printf("%d keys\n", header.keys);
  798. X    printf("%d keyfields\n", header.keyfields);
  799. X    printf("%d records\n", header.records);
  800. X    printf("%d fields\n", header.fields);
  801. X    printf("%d structdefs\n", header.structdefs);
  802. X
  803. X    /*---------- allocate memory for tables ----------*/
  804. X    filetab     = (void *)malloc(sizeof(File) * header.files);
  805. X    keytab        = (void *)malloc(sizeof(Key) * header.keys);
  806. X    keyfieldtab = (void *)malloc(sizeof(KeyField) * header.keyfields);
  807. X    fieldtab    = (void *)malloc(sizeof(Field) * header.fields);
  808. X    recordtab    = (void *)malloc(sizeof(Record) * header.records);
  809. X    structtab    = (void *)malloc(sizeof(Structdef) * header.structdefs);
  810. X
  811. X    if( (header.files        && !filetab)        ||
  812. X        (header.keys        && !keytab)            ||
  813. X        (header.keyfields    && !keyfieldtab)    ||
  814. X        (header.fields        && !fieldtab)        ||
  815. X        (header.records        && !recordtab)        ||
  816. X        (header.structdefs    && !structtab) )
  817. X    {
  818. X        puts("out of memory");
  819. X        FREE(filetab);
  820. X        FREE(fieldtab);
  821. X        FREE(recordtab);
  822. X        FREE(keytab);
  823. X        FREE(keyfieldtab);
  824. X        FREE(structtab);
  825. X        return;
  826. X    }    
  827. X
  828. X    /*---------- read tables ----------*/
  829. X    read(dbdfile, filetab,        sizeof(File)       * header.files);
  830. X    read(dbdfile, keytab,        sizeof(Key)          * header.keys);
  831. X    read(dbdfile, keyfieldtab,    sizeof(KeyField)  * header.keyfields);
  832. X    read(dbdfile, recordtab,    sizeof(Record)      * header.records);
  833. X    read(dbdfile, fieldtab,        sizeof(Field)      * header.fields);
  834. X    read(dbdfile, structtab,    sizeof(Structdef) * header.structdefs);
  835. X
  836. X    puts("----------------------------------- FILES -------------------------------------");
  837. X    printf(" ID NAME                 PGSIZE REC/KEY ID TYPE\n");
  838. X    for( i=0; i<header.files; i++ )
  839. X        printf("%3d %-20s %6u %10ld %4c\n",
  840. X            i,
  841. X            filetab[i].name,
  842. X            filetab[i].pagesize,
  843. X            filetab[i].id,
  844. X            filetab[i].type);
  845. X    printf("\n");
  846. X
  847. X    puts("----------------------------------- KEYS --------------------------------------");
  848. X    printf(" ID NAME                 TYPE               FILE SIZE 1ST_KEYFLD FIELDS PARENT\n");
  849. X    for( i=0, key=keytab; i<header.keys; i++, key++ )
  850. X    {
  851. X        strcpy(type, key_type[KT_GETBASIC(key->type)-1]);
  852. X
  853. X        if( key->type & KT_OPTIONAL )
  854. X            strcat(type, " opt");
  855. X
  856. X        if( KT_GETBASIC(key->type) == KT_ALTERNATE && (key->type & KT_UNIQUE) )
  857. X            strcat(type, " unique");
  858. X
  859. X        printf("%3d %-20s %-18s %4ld %4u %10ld %6d",
  860. X            i,
  861. X            key->name,
  862. X            type,
  863. X            key->fileid,
  864. X            key->size,
  865. X            key->first_keyfield,
  866. X            key->fields);
  867. X        if( KT_GETBASIC(key->type) == KT_FOREIGN )
  868. X            printf(" %d", key->parent);
  869. X        puts("");
  870. X    }
  871. X
  872. X    puts("");
  873. X    puts("--------------------------------- KEY FIELDS ----------------------------------");
  874. X    printf(" ID FIELD      OFFSET ASCENDING\n");
  875. X    for( i=0; i<header.keyfields; i++ )
  876. X    {
  877. X        printf("%3d %-5ld      %6u %s\n",
  878. X            i,
  879. X            keyfieldtab[i].field,
  880. X            keyfieldtab[i].offset,
  881. X            keyfieldtab[i].asc ? "Yes" : "No");
  882. X    }
  883. X
  884. X    puts("\n----------------------------------- RECORDS -----------------------------------");
  885. X    puts(" ID NAME                  SIZE VLR FILE 1ST_FLD FIELDS KEYS 1ST_KEY STR 1ST_FOR");
  886. X    for( i=0, record=recordtab; i<header.records; i++, record++ )
  887. X    {
  888. X        printf("%3d %-20s %5u %-3s %4ld %7ld %6u %4u %7ld %3d",
  889. X            i,
  890. X            record->name,
  891. X            record->size,
  892. X            record->is_vlr ? "Yes" : "No",
  893. X            record->fileid,
  894. X            record->first_field,
  895. X            record->fields,
  896. X            record->keys,
  897. X            record->first_key,
  898. X            record->structid);
  899. X        if( record->first_foreign != -1 )
  900. X            printf(" %10d", record->first_foreign);
  901. X        puts("");
  902. X    }
  903. X
  904. X    puts("\n----------------------------------- STRUCTS -----------------------------------");
  905. X    puts(" ID NAME                 SIZE 1ST_MEMBER MEMBERS UNION CONTROL");
  906. X    for( i=0, struc=structtab; i<header.structdefs; i++, struc++ )
  907. X    {
  908. X        printf("%3d %-20s %4u %10u %7u %5s",
  909. X            i,
  910. X            struc->name,
  911. X            struc->size,
  912. X            struc->first_member,
  913. X            struc->members,
  914. X            struc->is_union ? "yes" : "no");
  915. X
  916. X        if( struc->is_union )
  917. X            printf(" %7lu", struc->control_field);
  918. X
  919. X        puts("");
  920. X    }
  921. X
  922. X
  923. X    puts("\n----------------------------------- FIELDS ------------------------------------");
  924. X    puts(" ID NAME                 REC NEST OFFSET ELEMSZ  SIZE TYPE STRID KEYID SIZE_FLD");
  925. X    for( i=0, field=fieldtab; i<header.fields; i++, field++ )
  926. X    {
  927. X        printf("%3d %-20s %3ld %4u %6d %6d %5u %4X",
  928. X            i,
  929. X            field->name,
  930. X            field->recid,
  931. X            field->nesting,
  932. X            field->offset,
  933. X            field->elemsize,
  934. X            field->size,
  935. X            field->type);
  936. X
  937. X        if( field->type == FT_STRUCT )
  938. X            printf(" %5ld", field->structid);
  939. X        else
  940. X            printf("      ");
  941. X
  942. X        if( field->type & FT_KEY )
  943. X            printf(" %5ld", field->keyid);
  944. X        else
  945. X        if( fieldtab[i].type & FT_VARIABLE )
  946. X            printf("      %8u", field->keyid);
  947. X        puts("");
  948. X    }
  949. X
  950. X    free(filetab);
  951. X    free(fieldtab);
  952. X    free(recordtab);
  953. X    free(keytab);
  954. X    free(keyfieldtab);
  955. X    free(structtab);
  956. X}
  957. X
  958. X
  959. Xvoid main(argc, argv)
  960. Xchar *argv[];
  961. X{
  962. X    int dbdfile;
  963. X    char fname[80];
  964. X
  965. X    if( argc < 2 )
  966. X    {
  967. X        puts("Syntax: dbdview dbd-file");
  968. X        exit(1);
  969. X    }
  970. X
  971. X    /* check extension */
  972. X    strcpy(fname, argv[argc-1]);
  973. X    if( strstr(fname, ".dbd") == NULL )
  974. X        strcat(fname, ".dbd");
  975. X
  976. X    if( (dbdfile=open(fname, O_RDONLY|O_BINARY)) == -1 )
  977. X    {
  978. X        printf("cannot open %s\n", fname);
  979. X        exit(1);
  980. X    }
  981. X
  982. X    viewdbd(dbdfile);
  983. X
  984. X    close(dbdfile);
  985. X}
  986. X
  987. X/* end-of-file */
  988. X
  989. END_OF_FILE
  990.   if test 8730 -ne `wc -c <'typhoon/src/util/dbdview.c'`; then
  991.     echo shar: \"'typhoon/src/util/dbdview.c'\" unpacked with wrong size!
  992.   fi
  993.   # end of 'typhoon/src/util/dbdview.c'
  994. fi
  995. if test -f 'typhoon/src/util/fixlog.c' -a "${1}" != "-c" ; then 
  996.   echo shar: Will not clobber existing file \"'typhoon/src/util/fixlog.c'\"
  997. else
  998.   echo shar: Extracting \"'typhoon/src/util/fixlog.c'\" \(7892 characters\)
  999.   sed "s/^X//" >'typhoon/src/util/fixlog.c' <<'END_OF_FILE'
  1000. X/*----------------------------------------------------------------------------
  1001. X * File    : fixlog.c
  1002. X * Program : tyrestore
  1003. X * OS      : UNIX, OS/2, DOS
  1004. X * Author  : Thomas B. Pedersen
  1005. X *
  1006. X * Copyright (c) 1994 Thomas B. Pedersen.  All rights reserved.
  1007. X *
  1008. X * Permission is hereby granted, without written agreement and without
  1009. X * license or royalty fees, to use, copy, modify, and distribute this
  1010. X * software and its documentation for any purpose, provided that the above
  1011. X * copyright notice and the following two  paragraphs appear (1) in all 
  1012. X * source copies of this software and (2) in accompanying documentation
  1013. X * wherever the programatic interface of this software, or any derivative
  1014. X * of it, is described.
  1015. X *
  1016. X * IN NO EVENT SHALL THOMAS B. PEDERSEN BE LIABLE TO ANY PARTY FOR DIRECT,
  1017. X * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF
  1018. X * THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF HE HAS BEEN 
  1019. X * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  1020. X *
  1021. X * THOMAS B. PEDERSEN SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT
  1022. X * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  1023. X * A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" 
  1024. X * BASIS, AND THOMAS B. PEDERSEN HAS NO OBLIGATION TO PROVIDE MAINTENANCE,
  1025. X * SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  1026. X *
  1027. X * Description:
  1028. X *   Contains functions used to applying the log to the database after a
  1029. X *   restore.
  1030. X *
  1031. X * Functions:
  1032. X *
  1033. X * $Log: fixlog.c,v $
  1034. X * Revision 1.2  1994/09/17  16:00:54  tbp
  1035. X * typhoon.h and environ.h are now included from <>.
  1036. X *
  1037. X * Revision 1.1  1994/09/13  21:28:57  tbp
  1038. X * Added to repository.
  1039. X *
  1040. X * Added to repository.
  1041. X * 
  1042. X *
  1043. X *--------------------------------------------------------------------------*/
  1044. X
  1045. Xstatic char rcsid[] = "$Id: fixlog.c,v 1.2 1994/09/17 16:00:54 tbp Exp $";
  1046. X
  1047. X#include <fcntl.h>
  1048. X#include <stdio.h>
  1049. X#include <setjmp.h>
  1050. X#include <limits.h>
  1051. X#include <errno.h>
  1052. X#include <unistd.h>
  1053. X#include <typhoon.h>
  1054. X#include "../ty_dbd.h"
  1055. X#include "../ty_type.h"
  1056. X#include "../ty_glob.h"
  1057. X#include "../ty_prot.h"
  1058. X#include "../ty_log.h"
  1059. X
  1060. X
  1061. X
  1062. X/*------------------------------- Constants --------------------------------*/
  1063. X#define LOGBUF_SIZE        (64 * 1024)
  1064. X#define RECHEAD_SIZE    offsetof(RECORDHEAD, data[0])
  1065. X#define FILES_MAX        512
  1066. X
  1067. X
  1068. X/*-------------------------- Function prototypes ---------------------------*/
  1069. Xstatic void        *ReadLog                PRM( (ulong); )
  1070. Xstatic void        insert_in_lru            PRM( (ulong); )
  1071. Xstatic void        delete_from_lru            PRM( (ulong); )
  1072. Xstatic void        update_in_lru            PRM( (ulong); )
  1073. X
  1074. X/*---------------------------- Global variables ----------------------------*/
  1075. Xstatic char        *logbuf;                /* Log buffer                        */
  1076. Xstatic ulong    logbytes = 0;            /* Number of bytes in buffer        */
  1077. Xstatic ulong    logreadpos = 0;            /* Read position in log buffer        */
  1078. Xstatic int        log_fh;                    /* Log file handle                    */
  1079. Xstatic Dbentry    dbd;                    /* DBD-anchor                        */
  1080. Xextern jmp_buf    err_jmpbuf;
  1081. Xextern int        verbose;
  1082. Xextern char        *datapath;
  1083. X
  1084. Xstatic struct file_t {
  1085. X    int            fh;
  1086. X    unsigned    recsize;
  1087. X    unsigned    blocksize;
  1088. X    unsigned    preamble;
  1089. X    int            prev_in_lru;
  1090. X    int            next_in_lru;
  1091. X} file[FILES_MAX];
  1092. Xstatic int        mru_file = -1;
  1093. Xstatic int        lru_file = -1;
  1094. Xstatic int        r_cur_open = 0;
  1095. Xstatic int        r_max_open = 40;
  1096. X
  1097. X
  1098. X/*--------------------------------------------------------------------------*\
  1099. X *
  1100. X * Function  : ReadLog
  1101. X *
  1102. X * Purpose   : Returns a pointer to the next x bytes in the log.
  1103. X *
  1104. X * Parameters: bytes    - Number of bytes requested.
  1105. X *
  1106. X * Returns   : Nothing.
  1107. X *
  1108. X */
  1109. Xstatic void *ReadLog(bytes)
  1110. Xulong bytes;
  1111. X{
  1112. X    ulong    numread;
  1113. X    char    *p;
  1114. X
  1115. X    if( bytes > logbytes - logreadpos )
  1116. X    {
  1117. X        memmove(logbuf, logbuf+logreadpos, logbytes - logreadpos);
  1118. X        logbytes -= logreadpos;
  1119. X        logreadpos = 0;
  1120. X
  1121. X        numread = read(log_fh, logbuf + logbytes, LOGBUF_SIZE - logbytes);
  1122. X        
  1123. X        if( numread <= 0 )
  1124. X            return NULL;
  1125. X        
  1126. X        logbytes += numread;
  1127. X    }
  1128. X
  1129. X    p = logbuf + logreadpos;
  1130. X    logreadpos += bytes;
  1131. X
  1132. X    return p;
  1133. X}
  1134. X
  1135. X
  1136. Xstatic void insert_in_lru(id)
  1137. Xulong id;
  1138. X{
  1139. X    struct file_t *f = file + id;
  1140. X
  1141. X    f->prev_in_lru = -1;
  1142. X    
  1143. X    if( mru_file != -1 )
  1144. X    {
  1145. X        f->next_in_lru                = mru_file;
  1146. X        file[mru_file].prev_in_lru    = id;
  1147. X    }
  1148. X    else
  1149. X    {
  1150. X        lru_file        = id;
  1151. X        f->prev_in_lru    = -1;
  1152. X    }
  1153. X    
  1154. X    mru_file = id;
  1155. X}
  1156. X
  1157. Xstatic void delete_from_lru(id)
  1158. Xulong id;
  1159. X{
  1160. X    struct file_t *f = file + id;
  1161. X
  1162. X    if( f->next_in_lru != -1 )
  1163. X        file[f->next_in_lru].prev_in_lru = f->prev_in_lru;
  1164. X                    
  1165. X    if( f->prev_in_lru != -1 )
  1166. X        file[f->prev_in_lru].next_in_lru = f->next_in_lru;
  1167. X                                     
  1168. X    if( mru_file == id )
  1169. X        mru_file = f->next_in_lru;
  1170. X                                                      
  1171. X    if( lru_file == id )
  1172. X        lru_file = f->prev_in_lru;
  1173. X}
  1174. X
  1175. X
  1176. Xstatic void update_in_lru(id)
  1177. Xulong id;
  1178. X{
  1179. X    delete_from_lru(id);
  1180. X    insert_in_lru(id);
  1181. X}
  1182. X
  1183. X
  1184. X
  1185. Xstatic void CheckFile(fileid)
  1186. Xulong fileid;
  1187. X{
  1188. X    char fname[128];
  1189. X
  1190. X    if( file[fileid].fh == -1 )
  1191. X    {
  1192. X        if( r_cur_open == r_max_open )
  1193. X        {
  1194. X            /* Close least recently used file */
  1195. X            close(file[lru_file].fh);
  1196. X            file[lru_file].fh = -1;
  1197. X            
  1198. X            delete_from_lru(lru_file);
  1199. X            r_cur_open--;
  1200. X        }
  1201. X
  1202. X        sprintf(fname, "%s/%s", datapath, dbd.file[fileid].name);        
  1203. X        if( (file[fileid].fh = os_open(fname, O_RDWR, 0)) == -1 )
  1204. X        {
  1205. X            printf("Cannot open '%s' (errno %d)\n", dbd.file[fileid].name, errno);
  1206. X            longjmp(err_jmpbuf, 1);
  1207. X        }
  1208. X        
  1209. X        insert_in_lru(fileid);
  1210. X        r_cur_open++;
  1211. X    }
  1212. X}
  1213. X
  1214. X
  1215. X/*--------------------------------------------------------------------------*\
  1216. X *
  1217. X * Function  : FixLog
  1218. X *
  1219. X * Purpose   : Copies all the updates from the log to the database tables.
  1220. X *
  1221. X * Parameters: dbname        - Database name.
  1222. X *
  1223. X * Returns   : Nothing.
  1224. X *
  1225. X */
  1226. Xvoid FixLog(dbname)
  1227. Xchar *dbname;
  1228. X{
  1229. X    ushort        *logblock;
  1230. X    char        dbdname[DBNAME_LEN+5];
  1231. X    unsigned    i, fileid;
  1232. X    RECORDHEAD    recordhd = { 0 };
  1233. X    char        fname[128];
  1234. X
  1235. X    /* Open log file */
  1236. X    if( (log_fh = open(LOG_FNAME, O_RDONLY)) == -1 )
  1237. X    {
  1238. X        if( verbose )
  1239. X            puts("No log");
  1240. X        return;
  1241. X    }
  1242. X
  1243. X    if( verbose )
  1244. X        printf("Fixing log");
  1245. X
  1246. X    /* Read dbd-file */
  1247. X    sprintf(dbdname, "%s.dbd", dbname);
  1248. X    if( read_dbdfile(&dbd, dbdname) != S_OKAY )
  1249. X    {
  1250. X        printf("Cannot open '%s'\n", dbdname);
  1251. X        longjmp(err_jmpbuf, 1);
  1252. X    }
  1253. X
  1254. X    /* Allocate log buffer */    
  1255. X    if( !(logbuf = (char *)malloc(LOGBUF_SIZE)) )
  1256. X    {
  1257. X        puts("out of memory");
  1258. X        longjmp(err_jmpbuf, 1);
  1259. X    }
  1260. X
  1261. X    for( i=0; i<dbd.header.records; i++ )
  1262. X    {
  1263. X        ulong foreign_keys, preamble, datasize;
  1264. X        Record *rec = dbd.record + i;
  1265. X
  1266. X        if( rec->first_foreign == -1 )
  1267. X            foreign_keys = 0;
  1268. X        else
  1269. X            foreign_keys = rec->keys - (rec->first_foreign - rec->first_key);
  1270. X        preamble= sizeof(long) * foreign_keys;
  1271. X
  1272. X        fileid = dbd.record[i].fileid;
  1273. X        file[fileid].fh                = -1;
  1274. X        file[fileid].next_in_lru    = -1;
  1275. X        file[fileid].recsize        = dbd.record[i].size;
  1276. X        file[fileid].blocksize        = dbd.record[i].size + RECHEAD_SIZE + 
  1277. X                                      preamble;
  1278. X        file[fileid].preamble        = preamble;
  1279. X    }
  1280. X
  1281. X    while( logblock = (ushort *)ReadLog(sizeof *logblock) )
  1282. X    {
  1283. X        switch( *logblock )
  1284. X        {
  1285. X            case LOG_UPDATE: {
  1286. X                LogUpdate    *update = (void *)logblock;
  1287. X
  1288. X                /* Skip rest of LogUpdate structure and record */
  1289. X                ReadLog(update->len - sizeof(update->id));
  1290. X
  1291. X                fileid = dbd.record[update->recid].fileid;
  1292. X                CheckFile(fileid);
  1293. X
  1294. X                recordhd.flags = 0;
  1295. X
  1296. X                lseek(file[fileid].fh, update->recno * file[fileid].blocksize, SEEK_SET);
  1297. X                write(file[fileid].fh, &recordhd, RECHEAD_SIZE);
  1298. X                
  1299. X                lseek(file[fileid].fh, file[fileid].preamble, SEEK_CUR);
  1300. X                write(file[fileid].fh, update+1, file[fileid].recsize);
  1301. X                }
  1302. X                break;
  1303. X            
  1304. X            case LOG_DELETE: {
  1305. X                LogDelete    *delete = (void *)logblock;
  1306. X
  1307. X                /* Skip rest of LogDelete structure */
  1308. X                ReadLog(delete->len - sizeof(delete->id));
  1309. X
  1310. X                fileid = dbd.record[delete->recid].fileid;
  1311. X                CheckFile(fileid);
  1312. X
  1313. X                recordhd.flags = BIT_DELETED;
  1314. X
  1315. X                lseek(file[fileid].fh, delete->recno * file[fileid].blocksize, SEEK_SET);
  1316. X                write(file[fileid].fh, &recordhd, RECHEAD_SIZE);
  1317. X                }
  1318. X                break;
  1319. X        }    
  1320. X    }
  1321. X
  1322. X    close(log_fh);
  1323. X    free(logbuf);
  1324. X    free(dbd.dbd);
  1325. X
  1326. X    if( verbose )
  1327. X        puts("");
  1328. X}
  1329. X
  1330. X/* end-of-file */
  1331. END_OF_FILE
  1332.   if test 7892 -ne `wc -c <'typhoon/src/util/fixlog.c'`; then
  1333.     echo shar: \"'typhoon/src/util/fixlog.c'\" unpacked with wrong size!
  1334.   fi
  1335.   # end of 'typhoon/src/util/fixlog.c'
  1336. fi
  1337. if test -f 'typhoon/src/util/imp.y' -a "${1}" != "-c" ; then 
  1338.   echo shar: Will not clobber existing file \"'typhoon/src/util/imp.y'\"
  1339. else
  1340.   echo shar: Extracting \"'typhoon/src/util/imp.y'\" \(4986 characters\)
  1341.   sed "s/^X//" >'typhoon/src/util/imp.y' <<'END_OF_FILE'
  1342. X/*----------------------------------------------------------------------------
  1343. X * File    : imp.y
  1344. X * Program : tyimport
  1345. X * OS      : UNIX, OS/2, DOS
  1346. X * Author  : Thomas B. Pedersen
  1347. X *
  1348. X * Copyright (c) 1994 Thomas B. Pedersen.  All rights reserved.
  1349. X *
  1350. X * Permission is hereby granted, without written agreement and without
  1351. X * license or royalty fees, to use, copy, modify, and distribute this
  1352. X * software and its documentation for any purpose, provided that the above
  1353. X * copyright notice and the following two  paragraphs appear (1) in all 
  1354. X * source copies of this software and (2) in accompanying documentation
  1355. X * wherever the programatic interface of this software, or any derivative
  1356. X * of it, is described.
  1357. X *
  1358. X * IN NO EVENT SHALL THOMAS B. PEDERSEN BE LIABLE TO ANY PARTY FOR DIRECT,
  1359. X * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF
  1360. X * THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF HE HAS BEEN 
  1361. X * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  1362. X *
  1363. X * THOMAS B. PEDERSEN SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT
  1364. X * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  1365. X * A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" 
  1366. X * BASIS, AND THOMAS B. PEDERSEN HAS NO OBLIGATION TO PROVIDE MAINTENANCE,
  1367. X * SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  1368. X *
  1369. X * Description:
  1370. X *   Grammar for import specification.
  1371. X *
  1372. X * $Id: imp.y,v 1.2 1994/09/17 16:11:14 tbp Exp $
  1373. X *
  1374. X * $Log: imp.y,v $
  1375. X * Revision 1.2  1994/09/17  16:11:14  tbp
  1376. X * Added include directive.
  1377. X *
  1378. X * Added included directive.
  1379. X *
  1380. X * Added include directive.
  1381. X *
  1382. X * Revision 1.1  1994/09/13  21:28:57  tbp
  1383. X * Added to repository.
  1384. X *
  1385. X * Added to repository.
  1386. X * 
  1387. X *
  1388. X *--------------------------------------------------------------------------*/
  1389. X
  1390. X%{
  1391. X
  1392. X#include <string.h>
  1393. X#include <stdarg.h>
  1394. X#include <typhoon.h>
  1395. X#include "../ty_dbd.h"
  1396. X#include "../ty_type.h"
  1397. X#include "import.h"
  1398. X
  1399. X#define NEST_MAX    15
  1400. X
  1401. X/*--------------------------- Function prototypes --------------------------*/
  1402. XRecord        *GetRecord    PRM( (char *); )
  1403. XField        *GetField    PRM( (Structdef *, char *); )
  1404. XStructdef    *GetStruct    PRM( (Structdef *, char *); )
  1405. X
  1406. X/*---------------------------- Global variables ----------------------------*/
  1407. Xstatic Record        *cur_rec = NULL;        /* Current record                */
  1408. Xstatic Field        *cur_fld = NULL;        /* Current field                */
  1409. Xstatic Structdef    *cur_str = NULL;        /* Current structure            */
  1410. Xstatic Structdef    *strnest[NEST_MAX];        /* Pointers to structures        */
  1411. Xstatic int            cur_nest = -1;            /* Current nesting                */
  1412. X
  1413. X%}
  1414. X
  1415. X%union {
  1416. X    char      s[IDENT_LEN+1];
  1417. X}
  1418. X
  1419. X%start import_spec
  1420. X
  1421. X%token             T_IMPORT T_RECORD T_STRUCT T_UNION T_IN
  1422. X%token <s>        T_IDENT T_STRING
  1423. X%token             '{' '}' ';'
  1424. X
  1425. X%%
  1426. X
  1427. Ximport_spec        : T_IMPORT T_IDENT '{' record_list '}'
  1428. X                ;
  1429. X
  1430. Xrecord_list        : record
  1431. X                | record_list record
  1432. X                ;
  1433. X
  1434. Xrecord            : record_head '{' field_list '}'
  1435. X                    {
  1436. X                        cur_nest--;
  1437. X                    }
  1438. X                ;
  1439. X
  1440. Xrecord_head        : T_RECORD T_IDENT T_IN T_STRING 
  1441. X                    {
  1442. X                        if( cur_rec = GetRecord($2) )
  1443. X                        {
  1444. X                            cur_rec->aux = 1;
  1445. X                            cur_str = &dbd.structdef[cur_rec->structid];
  1446. X                        }
  1447. X                        else
  1448. X                            cur_str = NULL;
  1449. X                        strnest[++cur_nest] = cur_str;
  1450. X                    }
  1451. X                ;
  1452. X
  1453. Xfield_list        : field 
  1454. X                | field_list field 
  1455. X                ;
  1456. X    
  1457. Xfield            : T_IDENT ';'
  1458. X                    {
  1459. X                        if( cur_str )
  1460. X                            cur_fld = GetField(cur_str, $1);
  1461. X                    }
  1462. X
  1463. X                | struct_head '{' field_list '}' ';'
  1464. X                    {
  1465. X                        cur_str = strnest[--cur_nest];
  1466. X                    }
  1467. X                ;
  1468. X
  1469. Xstruct_head        : struct_or_union T_IDENT
  1470. X                    {
  1471. X                        if( cur_str )
  1472. X                            cur_str = GetStruct(cur_str, $2);
  1473. X                        strnest[++cur_nest] = cur_str;
  1474. X                    }
  1475. X                ;
  1476. X
  1477. Xstruct_or_union    : T_STRUCT
  1478. X                | T_UNION
  1479. X                ;
  1480. X
  1481. X
  1482. X%%
  1483. X
  1484. X
  1485. X#include <stdio.h>
  1486. X
  1487. Xextern errors;
  1488. X
  1489. Xyyerror(char *fmt ELLIPSIS)
  1490. X{
  1491. X    va_list ap;
  1492. X
  1493. X    printf("%s %d: ", spec_fname, lex_lineno);
  1494. X    va_start(ap, fmt);
  1495. X    vprintf(fmt, ap);
  1496. X    puts("");
  1497. X    va_end(ap);
  1498. X    errors++;
  1499. X    return 0;
  1500. X}
  1501. X
  1502. X
  1503. X
  1504. X
  1505. XRecord *GetRecord(name)
  1506. Xchar *name;
  1507. X{
  1508. X    int i;
  1509. X
  1510. X    for( i=0; i<dbd.header.records; i++ )
  1511. X        if( !strcmp(dbd.record[i].name, name) )
  1512. X            return &dbd.record[i];
  1513. X
  1514. X    yyerror("unknown record '%s'", name);
  1515. X    exit(1);
  1516. X    return NULL;
  1517. X}
  1518. X
  1519. X
  1520. X
  1521. XField *GetField(str, name)
  1522. XStructdef *str;
  1523. Xchar *name;
  1524. X{
  1525. X    Field *fld = &dbd.field[str->first_member];
  1526. X    int n = str->members;
  1527. X
  1528. X    while( n )
  1529. X    {
  1530. X        if( fld->nesting == cur_nest )
  1531. X        {
  1532. X            if( !strcmp(fld->name, name) )
  1533. X            {
  1534. X                fld->type |= FT_INCLUDE;
  1535. X                return fld;
  1536. X            }
  1537. X            n--;
  1538. X        }
  1539. X        fld++;
  1540. X    }
  1541. X
  1542. X    yyerror("'%s' is not a member of '%s'", name, str->name);
  1543. X    exit(1);
  1544. X    return NULL;
  1545. X}
  1546. X
  1547. X
  1548. XStructdef *GetStruct(str, name)
  1549. XStructdef *str;
  1550. Xchar *name;
  1551. X{
  1552. X    Field *fld;
  1553. X    Structdef *struc;
  1554. X
  1555. X    if( !(fld = GetField(str, name)) || 
  1556. X        FT_GETBASIC(fld->type) != FT_STRUCT )
  1557. X        return NULL;
  1558. X
  1559. X    struc = &dbd.structdef[fld->structid];
  1560. X
  1561. X    /* If the structure is a union the control field must also have been 
  1562. X     * specified
  1563. X     */
  1564. X    if( struc->is_union )
  1565. X    {
  1566. X        if( !(dbd.field[struc->control_field].type & FT_INCLUDE) )
  1567. X        {
  1568. X            yyerror("The control field of the union '%s' is not included",
  1569. X                name);
  1570. X            exit(1);
  1571. X        }
  1572. X    }
  1573. X
  1574. X    return struc;
  1575. X}
  1576. X
  1577. X/* end-of-file */
  1578. X
  1579. END_OF_FILE
  1580.   if test 4986 -ne `wc -c <'typhoon/src/util/imp.y'`; then
  1581.     echo shar: \"'typhoon/src/util/imp.y'\" unpacked with wrong size!
  1582.   fi
  1583.   # end of 'typhoon/src/util/imp.y'
  1584. fi
  1585. if test -f 'typhoon/src/vlr.c' -a "${1}" != "-c" ; then 
  1586.   echo shar: Will not clobber existing file \"'typhoon/src/vlr.c'\"
  1587. else
  1588.   echo shar: Extracting \"'typhoon/src/vlr.c'\" \(8439 characters\)
  1589.   sed "s/^X//" >'typhoon/src/vlr.c' <<'END_OF_FILE'
  1590. X/*----------------------------------------------------------------------------
  1591. X * File    : vlr.c
  1592. X * Library : typhoon
  1593. X * OS      : UNIX, OS/2, DOS
  1594. X * Author  : Thomas B. Pedersen
  1595. X *
  1596. X * Copyright (c) 1994 Thomas B. Pedersen.  All rights reserved.
  1597. X *
  1598. X * Permission is hereby granted, without written agreement and without
  1599. X * license or royalty fees, to use, copy, modify, and distribute this
  1600. X * software and its documentation for any purpose, provided that the above
  1601. X * copyright notice and the following two  paragraphs appear (1) in all 
  1602. X * source copies of this software and (2) in accompanying documentation
  1603. X * wherever the programatic interface of this software, or any derivative
  1604. X * of it, is described.
  1605. X *
  1606. X * IN NO EVENT SHALL THOMAS B. PEDERSEN BE LIABLE TO ANY PARTY FOR DIRECT,
  1607. X * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF
  1608. X * THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF HE HAS BEEN 
  1609. X * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  1610. X *
  1611. X * THOMAS B. PEDERSEN SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT
  1612. X * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  1613. X * A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" 
  1614. X * BASIS, AND THOMAS B. PEDERSEN HAS NO OBLIGATION TO PROVIDE MAINTENANCE,
  1615. X * SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  1616. X *
  1617. X * Description:
  1618. X *   Contains functions for Variable Length Records.
  1619. X *
  1620. X * Functions:
  1621. X *
  1622. X * $Log: vlr.c,v $
  1623. X * Revision 1.2  1994/09/17  16:00:22  tbp
  1624. X * typhoon.h and environ.h are now included from <>.
  1625. X *
  1626. X * Revision 1.1  1994/09/13  21:28:40  tbp
  1627. X * Added to repository.
  1628. X * 
  1629. X *
  1630. X *--------------------------------------------------------------------------*/
  1631. X
  1632. Xstatic char rcsid[] = "$Id: vlr.c,v 1.2 1994/09/17 16:00:22 tbp Exp $";
  1633. X
  1634. X#include <sys/types.h>
  1635. X#include <sys/stat.h>
  1636. X#include <fcntl.h>
  1637. X#include <errno.h>
  1638. X#ifdef UNIX
  1639. X#    include <unistd.h>
  1640. X#    ifdef __STDC__
  1641. X#        include <stdlib.h>
  1642. X#    endif
  1643. X#else
  1644. X#    include <io.h>
  1645. X#    include <stdlib.h>
  1646. X#endif
  1647. X#include <stdio.h>
  1648. X#include <string.h>
  1649. X#include <stddef.h>
  1650. X
  1651. X#include <typhoon.h>
  1652. X#include "ty_dbd.h"
  1653. X#include "ty_type.h"
  1654. X#include "ty_prot.h"
  1655. X#include "ty_glob.h"
  1656. X
  1657. X#define VLR_VERSION    "1.00"
  1658. X#define SEM_LEN     0
  1659. X
  1660. X#define _BLOCKSIZE        (vlr->header.blocksize)
  1661. X#define _FIRSTFREE        (vlr->header.firstfree)
  1662. X#define _NEXTBLOCK        (vlr->block->nextblock)
  1663. X#define _RECSIZE        (vlr->block->recsize)
  1664. X#define filelength(fd)    lseek(fd, 0, SEEK_END)
  1665. X
  1666. X
  1667. X/*-------------------------- Function prototypes ---------------------------*/
  1668. Xstatic void get_block        PRM( (VLR *, ulong); )
  1669. Xstatic void put_block        PRM( (VLR *, ulong); )
  1670. Xstatic ulong get_nextblock    PRM( (VLR *, ulong); )
  1671. Xstatic void get_header        PRM( (VLR *); )
  1672. Xstatic void put_header        PRM( (VLR *); )
  1673. X
  1674. X
  1675. X
  1676. Xstatic void get_block(vlr, blockno)
  1677. XVLR *vlr;
  1678. Xulong blockno;
  1679. X{
  1680. X    lseek(vlr->fh, blockno * vlr->header.blocksize, SEEK_SET);
  1681. X    read(vlr->fh, vlr->block, vlr->header.blocksize - SEM_LEN);
  1682. X}
  1683. X
  1684. Xstatic void put_block(vlr, blockno)
  1685. XVLR *vlr;
  1686. Xulong blockno;
  1687. X{
  1688. X    lseek(vlr->fh, blockno * vlr->header.blocksize, SEEK_SET);
  1689. X    write(vlr->fh, vlr->block, vlr->header.blocksize - SEM_LEN);
  1690. X}
  1691. X
  1692. X
  1693. Xstatic ulong get_nextblock(vlr, blockno)
  1694. XVLR *vlr;
  1695. Xulong blockno;
  1696. X{
  1697. X    ulong nextblock;
  1698. X
  1699. X    lseek(vlr->fh, blockno * vlr->header.blocksize, SEEK_SET);
  1700. X    read(vlr->fh, &nextblock, sizeof nextblock);
  1701. X
  1702. X    return nextblock;
  1703. X}
  1704. X
  1705. X
  1706. X/*------------------------------- get_header -------------------------------*\
  1707. X *
  1708. X * Read header from VLR file.
  1709. X *
  1710. X */
  1711. X
  1712. Xstatic void get_header(vlr)
  1713. XVLR *vlr;
  1714. X{
  1715. X    lseek(vlr->fh, 0, SEEK_SET);
  1716. X    read(vlr->fh, &vlr->header, sizeof vlr->header);
  1717. X}
  1718. X
  1719. X
  1720. X/*------------------------------- put_header -------------------------------*\
  1721. X *
  1722. X * Write header to VLR file.
  1723. X *
  1724. X */
  1725. X
  1726. Xstatic void put_header(vlr)
  1727. XVLR *vlr;
  1728. X{
  1729. X    lseek(vlr->fh, 0, SEEK_SET);
  1730. X    write(vlr->fh, &vlr->header, sizeof vlr->header);
  1731. X}
  1732. X
  1733. X
  1734. X/*------------------------------- vlr_close -------------------------------*\
  1735. X *
  1736. X * Write header to VLR file and close file.
  1737. X *
  1738. X */
  1739. X
  1740. Xvoid vlr_close(vlr)
  1741. XVLR *vlr;
  1742. X{
  1743. X    put_header(vlr);
  1744. X    free(vlr->block);
  1745. X    if( vlr->fh != -1 )
  1746. X        os_close(vlr->fh);
  1747. X    free(vlr);
  1748. X}
  1749. X
  1750. X
  1751. X/*------------------------------- vlr_open --------------------------------*\
  1752. X *
  1753. X * Open VRL file. If the file does not already exist it is created.
  1754. X *
  1755. X */
  1756. X
  1757. XVLR *vlr_open(fname, blocksize, shared)
  1758. Xchar *fname;
  1759. Xunsigned blocksize;
  1760. Xint shared;
  1761. X{
  1762. X    VLR *vlr;
  1763. X    int fh, isnew;
  1764. X
  1765. X    isnew = access(fname, 0);
  1766. X    if( (fh = os_open(fname, O_BINARY|O_CREAT|O_RDWR, CREATMASK)) == -1 )
  1767. X    {
  1768. X        db_status = S_IOFATAL;
  1769. X        return NULL;
  1770. X    }
  1771. X
  1772. X    if( !(vlr = (VLR *)calloc(sizeof *vlr, 1)) )
  1773. X    {
  1774. X        os_close(fh);
  1775. X        db_status = S_NOMEM;
  1776. X        return NULL;
  1777. X    }
  1778. X
  1779. X    vlr->fh = fh;
  1780. X
  1781. X    if( !(vlr->block = (VLRBLOCK *)malloc(blocksize)) )
  1782. X    {
  1783. X        os_close(fh);
  1784. X        free(vlr);
  1785. X        db_status = S_NOMEM;
  1786. X        return NULL;
  1787. X    }
  1788. X
  1789. X    if( isnew )
  1790. X    {
  1791. X        strcpy(vlr->header.version, VLR_VERSION);
  1792. X        vlr->header.id[0] = 0;
  1793. X        vlr->header.blocksize = blocksize;
  1794. X        vlr->header.firstfree = 1;
  1795. X        vlr->header.numrecords = 0;
  1796. X        put_header(vlr);
  1797. X        lseek(vlr->fh, blocksize-1L, SEEK_SET);
  1798. X        write(vlr->fh, "", 1);
  1799. X    }
  1800. X    else
  1801. X        get_header(vlr);
  1802. X
  1803. X    vlr->datasize = blocksize - offsetof(VLRBLOCK, data[0]) - SEM_LEN;
  1804. X    vlr->shared      = shared;
  1805. X    strcpy(vlr->fname, fname);
  1806. X
  1807. X    db_status = S_OKAY;
  1808. X
  1809. X    return vlr;
  1810. X}
  1811. X
  1812. X
  1813. Xvlr_dynclose(vlr)
  1814. XVLR *vlr;
  1815. X{
  1816. X    if( vlr->fh != -1 )
  1817. X    {
  1818. X        close(vlr->fh);
  1819. X        vlr->fh = -1;
  1820. X    }
  1821. X
  1822. X    RETURN S_OKAY;
  1823. X}
  1824. X
  1825. X
  1826. Xvlr_dynopen(vlr)
  1827. XVLR *vlr;
  1828. X{
  1829. X    if( vlr->fh == -1 )
  1830. X        if( (vlr->fh = os_open(vlr->fname, O_BINARY|O_CREAT|O_RDWR, CREATMASK)) == -1 )
  1831. X            RETURN S_IOFATAL;
  1832. X
  1833. X    RETURN S_OKAY;
  1834. X}
  1835. X
  1836. X
  1837. X
  1838. X/*------------------------------- vlr_add ---------------------------------*\
  1839. X *
  1840. X * Add a record to vlr file. If the delete-chain is non-empty, blocks are
  1841. X * taken from there, otherwise blocks are appended to the file.
  1842. X *
  1843. X */
  1844. X
  1845. Xvlr_add(vlr, buf, bufsize, recno)
  1846. XVLR *vlr;
  1847. Xvoid *buf;
  1848. Xunsigned bufsize;
  1849. Xulong *recno;
  1850. X{
  1851. X    unsigned    num_blocks, i;
  1852. X    ulong        old_firstfree = _FIRSTFREE;
  1853. X    ulong        tmp_firstfree = _FIRSTFREE;
  1854. X
  1855. X    get_header(vlr);
  1856. X
  1857. X    num_blocks = bufsize / vlr->datasize;
  1858. X
  1859. X    if( bufsize % vlr->datasize )
  1860. X        num_blocks++;
  1861. X
  1862. X    _RECSIZE = bufsize;
  1863. X
  1864. X    while( num_blocks-- )
  1865. X    {
  1866. X        memcpy(vlr->block->data, buf, vlr->datasize);    /* trap prone */
  1867. X
  1868. X        if( (vlr->header.firstfree) == filelength(vlr->fh)/vlr->header.blocksize )
  1869. X        {
  1870. X            _NEXTBLOCK = num_blocks ? filelength(vlr->fh) / _BLOCKSIZE + 1 : 0;
  1871. X            put_block(vlr, _FIRSTFREE);
  1872. X            _FIRSTFREE = filelength(vlr->fh)/_BLOCKSIZE;
  1873. X        }
  1874. X        else
  1875. X        {
  1876. X            tmp_firstfree = get_nextblock(vlr, _FIRSTFREE);
  1877. X            _NEXTBLOCK = num_blocks ? tmp_firstfree : 0;
  1878. X            put_block(vlr, _FIRSTFREE);
  1879. X            _FIRSTFREE = tmp_firstfree;
  1880. X        }
  1881. X        buf = (void *)((char *)buf + vlr->datasize);
  1882. X        _RECSIZE = 0;
  1883. X    }
  1884. X
  1885. X    vlr->header.numrecords++;
  1886. X    put_header(vlr);
  1887. X
  1888. X    *recno = old_firstfree;
  1889. X
  1890. X    return S_OKAY;
  1891. X}
  1892. X
  1893. X
  1894. X
  1895. X/*------------------------------- vlr_write -------------------------------*\
  1896. X *
  1897. X * Update a record. The record is first deleted then inserted. This is not
  1898. X * the most efficient way to do it, but it works!
  1899. X *
  1900. X */
  1901. X
  1902. Xvlr_write(vlr, buf, bufsize, blockno)
  1903. XVLR *vlr;
  1904. Xvoid *buf;
  1905. Xunsigned bufsize;
  1906. Xulong blockno;
  1907. X{
  1908. X    ulong dummy;
  1909. X
  1910. X    vlr_del(vlr, blockno);
  1911. X    vlr_add(vlr, buf, bufsize, &dummy);
  1912. X
  1913. X    RETURN S_OKAY;
  1914. X}
  1915. X
  1916. X
  1917. X/*------------------------------- vlr_read --------------------------------*\
  1918. X *
  1919. X * Read a record.
  1920. X *
  1921. X */
  1922. X
  1923. Xvlr_read(vlr, buf, blockno, sizeptr)
  1924. XVLR *vlr;
  1925. Xvoid *buf;
  1926. Xulong blockno;
  1927. Xunsigned *sizeptr;
  1928. X{
  1929. X    unsigned size = 0;
  1930. X
  1931. X    get_header(vlr);
  1932. X    _NEXTBLOCK = blockno;
  1933. X
  1934. X    if( (blockno+1) * _BLOCKSIZE > filelength(vlr->fh) )
  1935. X        return 0;
  1936. X
  1937. X    while( _NEXTBLOCK )
  1938. X    {
  1939. X        get_block(vlr, _NEXTBLOCK);
  1940. X
  1941. X        if( _RECSIZE > 0 )
  1942. X            size = _RECSIZE;
  1943. X
  1944. X        if( !size )
  1945. X            break;
  1946. X
  1947. X        memcpy(buf, vlr->block->data, _NEXTBLOCK ? vlr->datasize : size % vlr->datasize);
  1948. X        buf = (void *)((char *)buf + vlr->datasize);
  1949. X/*        (char *)buf += vlr->datasize;*/
  1950. X    }
  1951. X
  1952. X    *sizeptr = size;
  1953. X
  1954. X    RETURN S_OKAY;
  1955. X}
  1956. X
  1957. X/*-------------------------------- vlr_del --------------------------------*\
  1958. X *
  1959. X * Delete a record. The blocks used by the record deleted, are inserted in
  1960. X * front of the delete chain.
  1961. X *
  1962. X */
  1963. X
  1964. Xvlr_del(vlr, blockno)
  1965. XVLR *vlr;
  1966. Xulong blockno;
  1967. X{
  1968. X    ulong tmp_firstfree = _FIRSTFREE;
  1969. X    ulong cur_block = blockno;
  1970. X
  1971. X    get_header(vlr);
  1972. X
  1973. X    _FIRSTFREE = blockno;
  1974. X    get_block(vlr, blockno);
  1975. X
  1976. X    _RECSIZE = 0;
  1977. X    put_block(vlr, blockno);
  1978. X
  1979. X    while( _NEXTBLOCK > 0 )
  1980. X    {
  1981. X        cur_block = _NEXTBLOCK;
  1982. X        _NEXTBLOCK = get_nextblock(vlr, _NEXTBLOCK);
  1983. X    }
  1984. X
  1985. X    _NEXTBLOCK = tmp_firstfree;
  1986. X    put_block(vlr, cur_block);
  1987. X
  1988. X    vlr->header.numrecords--;
  1989. X    put_header(vlr);
  1990. X
  1991. X    RETURN S_OKAY;
  1992. X}
  1993. X
  1994. X/* end-of-file */
  1995. END_OF_FILE
  1996.   if test 8439 -ne `wc -c <'typhoon/src/vlr.c'`; then
  1997.     echo shar: \"'typhoon/src/vlr.c'\" unpacked with wrong size!
  1998.   fi
  1999.   # end of 'typhoon/src/vlr.c'
  2000. fi
  2001. echo shar: End of archive 5 \(of 9\).
  2002. cp /dev/null ark5isdone
  2003. MISSING=""
  2004. for I in 1 2 3 4 5 6 7 8 9 ; do
  2005.     if test ! -f ark${I}isdone ; then
  2006.     MISSING="${MISSING} ${I}"
  2007.     fi
  2008. done
  2009. if test "${MISSING}" = "" ; then
  2010.     echo You have unpacked all 9 archives.
  2011.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  2012. else
  2013.     echo You still must unpack the following archives:
  2014.     echo "        " ${MISSING}
  2015. fi
  2016. exit 0
  2017. exit 0 # Just in case...
  2018.