/*___________________________________________________________________________*
)()( DalekenMUD 1.12 (C) 2000 )()(
`][' by Martin Thomson, Lee Brooks, `]['
|| Ken Herbert and David Jacques ||
|| ----------------------------------------------------------------- ||
|| Envy Diku Mud improvements copyright (C) 1994 by Michael Quan, ||
|| David Love, Guilherme 'Willie' Arnold, and Mitchell Tse. ||
|| Merc Diku Mud improvments copyright (C) 1992, 1993 by Michael ||
|| Chastain, Michael Quan, and Mitchell Tse. ||
|| Original Diku Mud copyright (C) 1990, 1991 ||
|| by Sebastian Hammer, Michael Seifert, Hans Henrik St{rfeldt, ||
|| Tom Madsen, and Katja Nyboe. ||
|| ----------------------------------------------------------------- ||
|| Any use of this software must follow the licenses of the ||
|| creators. Much time and thought has gone into this software and ||
|| you are benefitting. We hope that you share your changes too. ||
|| What goes around, comes around. ||
|| ----------------------------------------------------------------- ||
|| db.h ||
|| Declarations of functions and structures used for loading/saving. ||
*_/<>\_________________________________________________________________/<>\_*/
/*
* This is taken from Erwin Andreasen's Generic Linked List Loading code.
* Copyright 1997 Erwin S. Andreasen <erwin@pip.dknet.dk>
* This expands to the first field of what the void* ptr points at, which
* is assumed to be a structure whose first field is the pointer to the
* next in the list. This is just to make the source more readable - the
* purpose of the cast may seem unclear.
*/
#define NEXT(ptr) (*(void**)(ptr))
/*
* The following defines are used for identifying what type of data
* is required or is present.
* This is all packed into the type field of the data_desc_type.
*
* Note that DTYPE_TIME isn't really needed, but this is a safety thing as
* the time_t type is likely to be one type that increases above 32 bit.
*/
#define DTYPE_STRING 0 /* "a string" */
#define DTYPE_NUMBER 1 /* 123|456 / 0xabc|123 / *
* (flag flag) / (<table> flag) *
* for a flag table, vector tables are *
* interpreted as vector values */
#define DTYPE_VECTOR 2 /* Same as DTYPE_NUMBER in all respects *
* except for its default value */
#define DTYPE_COMPLEX 3 /* Requires an entire table to read it. */
#define DTYPE_LLIST 4 /* Is a linked list (implies complex). */
#define DTYPE_TIME 5 /* Like number but more careful. */
#define DTYPE_BASIC (DTYPE_STRING|DTYPE_NUMBER|DTYPE_VECTOR \
|DTYPE_COMPLEX|DTYPE_LLIST|DTYPE_TIME)
#define DFLAG_MAND BIT_05 /* OR this, to specify manditory */
#define DFLAG_ARRAY BIT_06 /* OR this, for arrays */
#define DFLAG_SPECREAD BIT_07 /* value needs special read. */
#define DFLAG_SPECWRITE BIT_08 /* value needs special write. */
#define DFLAG_SPECIAL (DFLAG_SPECREAD|DFLAG_SPECWRITE)
#define DFLAG_CHKDEFAULT BIT_09 /* Use the RWF to check if a value is a default */
#define DFLAG_NEEDPARENT BIT_10 /* Needs values on the parent object for any
special read/write/chkdefault. */
#define DSHIFT_ARRAY 13 /* so type can hold the array size too */
/*
* DBACTION_* flags, used to specify an action type to a DB_RWF function.
*/
typedef enum
{
DBACTION_READ, /* Read data. */
DBACTION_FIX, /* Fill unfilled fields etc... */
DBACTION_ADDWORLD, /* Insert into the world. */
DBACTION_WRITE, /* Write to a file. */
DBACTION_CHKDEFAULT /* Check if the value is a default. */
} db_action;
/*
* DB_RWF.
*
* fp - input file.
* vo - pointer to data that is to be written.
* action - the DBACTION_* action type.
*
* returns: FALSE on error.
*/
typedef bool DB_RWF args( ( FILE *fp, void *vo, db_action action ) );
#define DECLARE_DBRWF( fun ) DB_RWF fun
/*
* data_desc_type
*
* This struct is used to describe complex sets of data so that it can
* be both read and written.
*/
struct data_desc_type
{
const char *name; /* The identifier. */
int type; /* Flags saying what to expect. */
void *target; /* A pointer to the data. */
union /* This is the default value. */
{
int number; /* - for a number. */
int vector[MAX_VECTOR]; /* - for a vector. */
const char *string; /* - for a character string. */
const struct top_data_type *table; /* - for complex types. */
} deflt;
const char *flag_table; /* For mapped values. */
DB_RWF *rwf; /* for special types/cases. */
};
/*
* top_data_type
*
* This is used to associate names and data with associated tables.
*/
struct top_data_type
{
const char *name;
struct data_desc_type *table;
void *data_ptr;
int data_size;
DB_RWF *rwf;
};
/*
* Miscellaneous functions.
*/
void init_data_desc_tables args( ( void ) );
/*
* Reading functions.
*/
void load_file_list args( ( const char *dirname, const char *listname ) );
bool load_file args( ( const char *name ) );
bool load_file_stream args( ( FILE *fp ) );
void *read_next_item args( ( FILE *fp, int *status ) );
void *load_complex_block args( ( FILE *fp, const struct top_data_type *block_desc ) );
bool load_single_field args( ( FILE *fp, const struct data_desc_type *entry ) );
bool load_array args( ( FILE *fp, const struct data_desc_type *entry ) );
bool ignore_unknown_field args( ( FILE *fp ) );
bool fread_number_ii args( ( FILE *fp, int *value, const char *def_table ) );
time_t fread_time args( ( FILE *fp, int *status ) );
/*
* Writing functions.
*/
bool write_next_item args( ( FILE *fp, const char *name, const void *value ) );
bool save_complex_block args( ( FILE *fp, const struct top_data_type *block_desc,
const void *value ) );
void fwrite_number args( ( FILE *fp, int value ) );
void fwrite_time args( ( FILE *fp, time_t value ) );
void fwrite_mapped_value args( ( FILE *fp, int *value, const char *table,
bool title ) );
void fwrite_quoted_string args( ( FILE *fp, const char *str ) );
/*
* Tables used.
*/
extern struct top_data_type global_data_table[];
extern struct data_desc_type affect_data_table[];
extern struct data_desc_type alias_data_table[];
extern struct data_desc_type area_data_table[];
extern struct data_desc_type char_data_table[];
extern struct data_desc_type clan_data_table[];
extern struct data_desc_type event_data_table[];
extern struct data_desc_type exdesc_data_table[];
extern struct data_desc_type exit_data_table[];
extern struct data_desc_type gprog_data_table[];
extern struct data_desc_type help_data_table[];
extern struct data_desc_type high_data_table[];
extern struct data_desc_type highent_data_table[];
extern struct data_desc_type mobile_data_table[];
extern struct data_desc_type mudprog_data_table[];
extern struct data_desc_type note_data_table[];
extern struct data_desc_type obj_data_table[];
extern struct data_desc_type object_data_table[];
extern struct data_desc_type pcdata_data_table[];
extern struct data_desc_type plane_data_table[];
extern struct data_desc_type pose_data_table[];
extern struct data_desc_type quest_data_table[];
extern struct data_desc_type room_data_table[];
extern struct data_desc_type religion_data_table[];
extern struct data_desc_type relskill_data_table[];
extern struct data_desc_type shop_data_table[];
extern struct data_desc_type social_data_table[];
extern struct data_desc_type sysinfo_data_table[];
/*
* These two variables are used in the versioning of files. They are made
* available to the FIX and ADDWORLD actions of the dbrwf functions.
*
* file_version should be set before opening a file for writing.
*/
extern int file_version;
extern time_t file_date;
/*
* Special Read/Write/Fix functions.
*/
DECLARE_DBRWF( dbrwf_affect );
DECLARE_DBRWF( dbrwf_alias );
DECLARE_DBRWF( dbrwf_all_affect );
DECLARE_DBRWF( dbrwf_all_clan );
DECLARE_DBRWF( dbrwf_all_religion );
DECLARE_DBRWF( dbrwf_area );
DECLARE_DBRWF( dbrwf_area_flags );
DECLARE_DBRWF( dbrwf_area_plane );
DECLARE_DBRWF( dbrwf_char );
DECLARE_DBRWF( dbrwf_char_in_room );
DECLARE_DBRWF( dbrwf_char_max_hit );
DECLARE_DBRWF( dbrwf_char_max_mana );
DECLARE_DBRWF( dbrwf_char_max_move );
DECLARE_DBRWF( dbrwf_char_obj );
DECLARE_DBRWF( dbrwf_char_parts );
DECLARE_DBRWF( dbrwf_char_played );
DECLARE_DBRWF( dbrwf_char_position );
DECLARE_DBRWF( dbrwf_char_race );
DECLARE_DBRWF( dbrwf_char_sex );
DECLARE_DBRWF( dbrwf_check_room );
DECLARE_DBRWF( dbrwf_clan );
DECLARE_DBRWF( dbrwf_event );
DECLARE_DBRWF( dbrwf_event_data );
DECLARE_DBRWF( dbrwf_event_when );
DECLARE_DBRWF( dbrwf_exdesc );
DECLARE_DBRWF( dbrwf_exit );
DECLARE_DBRWF( dbrwf_gprog );
DECLARE_DBRWF( dbrwf_help );
DECLARE_DBRWF( dbrwf_high );
DECLARE_DBRWF( dbrwf_highent );
DECLARE_DBRWF( dbrwf_high_entries );
DECLARE_DBRWF( dbrwf_magic_mana );
DECLARE_DBRWF( dbrwf_mob_index );
DECLARE_DBRWF( dbrwf_mob_parts );
DECLARE_DBRWF( dbrwf_mob_spec );
DECLARE_DBRWF( dbrwf_mudprog );
DECLARE_DBRWF( dbrwf_note );
DECLARE_DBRWF( dbrwf_obj );
DECLARE_DBRWF( dbrwf_obj_index );
DECLARE_DBRWF( dbrwf_obj_index_values );
DECLARE_DBRWF( dbrwf_obj_obj );
DECLARE_DBRWF( dbrwf_obj_values );
DECLARE_DBRWF( dbrwf_obj_vnum );
DECLARE_DBRWF( dbrwf_pcdata );
DECLARE_DBRWF( dbrwf_pcdata_board );
DECLARE_DBRWF( dbrwf_pcdata_multi_class );
DECLARE_DBRWF( dbrwf_pcdata_skills );
DECLARE_DBRWF( dbrwf_plane );
DECLARE_DBRWF( dbrwf_pose );
DECLARE_DBRWF( dbrwf_quest );
DECLARE_DBRWF( dbrwf_religion );
DECLARE_DBRWF( dbrwf_relskill );
DECLARE_DBRWF( dbrwf_room );
DECLARE_DBRWF( dbrwf_room_exits );
DECLARE_DBRWF( dbrwf_room_resets );
DECLARE_DBRWF( dbrwf_shop );
DECLARE_DBRWF( dbrwf_shop_trade );
DECLARE_DBRWF( dbrwf_social );
DECLARE_DBRWF( dbrwf_sysinfo );
/*
* Other functions.
*/
void save_clans args( ( void ) );
void save_planes args( ( void ) );
void save_religions args( ( void ) );
void save_socials args( ( void ) );
/*
* Stuff in db.c used in other db files.
*/
extern int top_affect;
extern int top_clan;
extern int top_ed;
extern int top_event;
extern int top_exit;
extern int top_help;
extern int top_mprog;
extern int top_mprog_global;
extern int top_pose;
extern int top_religion;
extern int top_reset;
extern int top_room;
extern int top_shop;
extern int top_social;
extern int top_text_block;
extern int size_text_block;
void assign_area_vnum args( ( int vnum ) );