/home/dcp1990/prog/fakedbfs/include/fakedbfs/dbspecdata.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2005, Dan Ponte
00003  *
00004  * dbspecdata.h - data structures used for db spec building
00005  * 
00006  * Redistribution and use in source and binary forms, with or without
00007  * modification, are permitted provided that the following conditions
00008  * are met:
00009  * 1. Redistributions of source code must retain the above copyright
00010  *    notice, this list of conditions and the following disclaimer.
00011  * 2. Redistributions in binary form must reproduce the above copyright
00012  *    notice, this list of conditions and the following disclaimer in the
00013  *    documentation and/or other materials provided with the distribution.
00014  * 4. Neither the name of the University nor the names of its contributors
00015  *    may be used to endorse or promote products derived from this software
00016  *    without specific prior written permission.
00017  *
00018  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
00019  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00020  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00021  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
00022  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00023  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00024  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00025  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00026  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00027  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00028  * SUCH DAMAGE.
00029  */
00030 /* $Amigan: fakedbfs/include/fakedbfs/dbspecdata.h,v 1.11 2006/04/19 19:58:22 dcp1990 Exp $ */
00031 #ifndef HAVE_DBSPECDATA_H
00032 #define HAVE_DBSPECDATA_H 1
00033 #include <fakedbfs/types.h>
00034 #define MAXLINE 2048
00035 #define ALLSUBSTART 6500 /* defining more than this number-1 of subelements leads to
00036                           * undefined behaviour. avoid doing so (not like you will anyway)
00037                           */
00038 typedef struct {
00039         struct CatalogueHead *cathead;
00040         struct EnumHead *enumhead;
00041         struct CatalogueHead *lastcath;
00042         struct EnumHead *lastenumh;
00043         struct CatalogueHead *curcath;
00044         struct EnumHead *curenumh;
00045         /* from DB (for collision detection) */
00046         struct CatalogueHead *db_cath;
00047         struct EnumHead *db_enumh;
00048         /* elements */
00049         struct CatElem *catelemhead;
00050         struct EnumElem *enumelemhead;
00051         struct CatElem *lastcatel;
00052         struct EnumElem *lastenumel;
00053         struct CatElem *curcatel;
00054         struct EnumElem *curenumel;
00055         /* subelements */
00056         struct EnumSubElem *subelhead;
00057         struct EnumSubElem *lastsubel;
00058         /* allsubs */
00059         struct EnumSubElem *allsubelhead;
00060         struct EnumSubElem *lastallsubel;
00061         /* counters */
00062         unsigned int lastevalue;
00063         unsigned int lastsubval;
00064         unsigned int lastallsubval; /* should start at a high number, such as 6500 */
00065         int err;
00066         void *instance;
00067 } Heads;
00068 /*
00069  * note that any fmtname could also point to that structure's name;
00070  * one must check if the fc (First letter Capitalize) flag is set and
00071  * act accordingly. This is to save some memory. (only applies to stuff with
00072  * alias capability, not ENUM block names)
00073  * If alias == name with no fc set, this means that no alias was defined.
00074  */
00075 
00076 /* Enum stuff */
00077 
00078 #if 0
00079 this isn't really necessary...
00080 struct EnumSubHead {
00081         struct EnumElem *father;
00082         struct EnumSubElem *headsub;
00083         short int hasSelf;
00084 };
00085 #endif
00086 
00087 /* NB: *ALL* name/alias-type fields (basically anything not a const char*) *MUST* be allocated dynamically (or at the very least located
00088  * in writeable memory, but this will fuck up free_() functions), or strange segfaults will result.
00089  */
00090 #define SUBE_IS_SELF 0x1
00091 #define SUBE_IS_SAMEAS 0x2
00092 #define SUBE_IS_ALLSUB 0x4
00093 struct EnumSubElem {
00094         char *name;
00095         /* Not necessary: char *fmtname; */
00096         unsigned int value;
00097         struct EnumElem *father;
00098         int flags; /* bit 1 is "is self" 2 means "don't free strings" */
00099         struct EnumSubElem *next;
00100 };
00101 
00102 struct EnumElem {
00103         char *name;
00104         char *fmtname;
00105         unsigned int value;
00106         short int other;
00107         enum DataType othertype; /* CANNOT BE another enum */
00108         struct EnumSubElem *subhead;
00109         struct EnumElem *next;
00110 };
00111 #define ENUMH_FROM_DB 0x1 /* if this flag is set, DO NOT write back out to DB; it is for collision detection (reading from DB.
00112                              For more info, see dbinit.c's enums_from_db(). */
00113 struct EnumHead {
00114         char *name;
00115         int flags;
00116         struct EnumSubElem *allsubs;
00117         struct EnumElem *headelem;
00118         struct EnumElem *otherelem;
00119         struct EnumHead *next;
00120 };
00121 
00122 /* catalogue stuff */
00123 #define CATE_USES_FC 0x1
00124 struct CatElem {
00125         char *name;
00126         char *alias; /* analogous to fmtname... */
00127         enum DataType type;
00128         struct EnumHead *enumptr;
00129         struct CatElem *subcatel; /* only set if type == oenumsub */
00130         int flags; /* bit 1 is "uses <fc> param" */
00131         struct CatElem *next;
00132 };
00133 #define CATH_USES_FC 0x1
00134 #define CATH_FROM_DB 0x2 /* if this flag is set, DO NOT write back out to DB; it is for collision detection (reading from DB.
00135                              For more info, see dbinit.c's cats_from_db(). */
00136 struct CatalogueHead {
00137         char *name;
00138         char *fmtname;
00139         int flags; /* just like elem as of now */
00140         struct CatElem *headelem;
00141         struct CatalogueHead *next; /* God only knows if we will use this... */
00142 };
00143 
00151 struct EnumElem* fdbfs_find_elem_by_name(struct EnumElem *h, const char *name);
00152 
00160 struct CatElem* fdbfs_find_catelem_enum(struct CatElem *h, struct EnumHead *en);
00161 
00170 char* fdbfs_get_enum_string_by_value(struct EnumElem *h, unsigned int val, short int fmted);
00171 
00179 struct EnumSubElem* fdbfs_get_subhead_by_enval(struct EnumElem *h, unsigned int val);
00180 
00188 char* fdbfs_get_enum_sub_string_by_value(struct EnumSubElem *h, unsigned int val);
00189 
00197 struct CatalogueHead* fdbfs_find_cathead_by_name(struct CatalogueHead *h, const char *name);
00198 
00206 struct CatElem* fdbfs_find_catelem_by_name(struct CatElem *h, const char *name);
00207 
00215 struct EnumHead* fdbfs_find_enumhead_by_name(struct EnumHead *h, const char *name);
00216 
00227 struct EnumSubElem* fdbfs_copy_sub_list(
00228                 struct EnumSubElem *from,
00229                 struct EnumSubElem *to,
00230                 struct EnumElem *fajah,
00231                 int *lastval
00232                 );
00233 
00243 struct EnumElem* fdbfs_enumelems_from_dbtab(fdbfs_t *f, const char *table, struct EnumHead *e);
00244 
00251 struct EnumHead* fdbfs_enums_from_db(fdbfs_t *f);
00252 
00261 struct CatElem* fdbfs_catelems_from_dbtab(fdbfs_t *f, const char *table, struct EnumHead *enumhead);
00262 
00270 struct CatalogueHead* fdbfs_cats_from_db(fdbfs_t *f, struct EnumHead *enumhead);
00271 
00279 struct EnumSubElem* fdbfs_free_enum_sub_elem(struct EnumSubElem *e, short int allsub); /* returns next */
00280 
00287 void fdbfs_free_enum_sub_elem_list(struct EnumSubElem *head, short int allsub);
00288 
00295 struct EnumElem* fdbfs_free_enum_elem(struct EnumElem *e);
00296 
00302 void fdbfs_free_enum_elem_list(struct EnumElem *head);
00303 
00310 struct EnumHead* fdbfs_free_enum_head(struct EnumHead *e);
00311 
00317 void fdbfs_free_enum_head_list(struct EnumHead *head);
00318 
00325 struct CatElem* fdbfs_free_cat_elem(struct CatElem *e);
00326 
00332 void fdbfs_free_cat_elem_list(struct CatElem *head);
00333 
00340 struct CatalogueHead* fdbfs_free_cat_head(struct CatalogueHead *e);
00341 
00347 void fdbfs_free_cat_head_list(struct CatalogueHead *head);
00348 
00355 void fdbfs_free_head_members(Heads *hd);
00356 
00366 int fdbfs_dbspec_parse(fdbfs_t *f, const char *filename);
00367 
00373 void fdbfs_actcats_free(actcat_t *h);
00374 
00382 actcat_t* fdbfs_catalogues_from_db(fdbfs_t *f, struct CatalogueHead *cathead);
00383 
00384 #define CAT_TABLE_PREFIX "c_"
00385 #define CAT_FIELD_TABLE_PREFIX "cft_"
00386 #define ENUM_TABLE_PREFIX "endef_"
00387 #define OTHER_ELEM_PREFIX "oth_" /* do not prefix anything else with this */
00388 #endif

Generated on Wed Apr 19 16:26:23 2006 for fakedbfs by  doxygen 1.4.6