/**************************************************************************
* Original Diku Mud copyright (C) 1990, 1991 by Sebastian Hammer, *
* Michael Seifert, Hans Henrik St{rfeldt, Tom Madsen, and Katja Nyboe. *
* *
* Merc Diku Mud improvements copyright (C) 1992, 1993 by Michael *
* Chastain, Michael Quan, and Mitchell Tse. *
* *
* In order to use any part of this Merc Diku Mud, you must comply with *
* both the original Diku license in 'license.doc' as well the Merc *
* license in 'license.txt'. In particular, you may not remove either of *
* these copyright notices. *
* *
* Much time and thought has gone into this software and you are *
* benefiting. We hope that you share your changes too. What goes *
* around, comes around. *
***************************************************************************
* ROM 2.4 is copyright 1993-1998 Russ Taylor *
* ROM has been brought to you by the ROM consortium *
* Russ Taylor (rtaylor@hypercube.org) *
* Gabrielle Taylor (gtaylor@hypercube.org) *
* Brian Moore (zump@rom.org) *
* By using this code, you have agreed to follow the terms of the *
* ROM license, in the file Rom24/doc/rom.license *
***************************************************************************
* 1stMUD ROM Derivative (c) 2001-2003 by Ryan Jennings *
* http://1stmud.dlmud.com/ <r-jenn@shaw.ca> *
***************************************************************************/
#if !defined(SAVE_H)
#define SAVE_H
/*
* Array of containers read for proper re-nesting of objects.
*/
#define MAX_NEST 100
#define FKEY_ARRAY( literal, array, max, def) \
if ( !str_cmp( word, literal ) ) \
{ \
fread_array(array, max, def); \
fMatch = TRUE; \
break; \
}
#define FKEY_IGNORE(literal) \
if ( !str_cmp(word, literal ) ) \
{ \
fread_to_eol(fp); \
fMatch = TRUE; \
break; \
}
#define FKEY_DO(literal, dothis) \
if (!str_cmp(word, literal ) ) \
{ \
dothis; \
fread_to_eol(fp); \
fMatch = TRUE; \
break; \
}
#define FKEYT( literal, field) \
if ( !str_cmp( word, literal ) ) \
{ \
fread_time(fp, &field); \
fMatch = TRUE; \
break; \
}
#define FKEY( literal, field, value ) \
if ( !str_cmp( word, literal ) ) \
{ \
field = value; \
fread_to_eol(fp); \
fMatch = TRUE; \
break; \
}
#define FKEYS( literal, field ) \
if ( !str_cmp( word, literal ) ) \
{ \
free_fread_string(field, fp); \
fread_to_eol(fp); \
fMatch = TRUE; \
break; \
}
#define FKEY_SFUN( literal, field, strfun ) \
if ( !str_cmp( word, literal ) ) \
{ \
const char *tmp = fread_string(fp); \
field = strfun(tmp); \
free_string(tmp); \
fMatch = TRUE; \
break; \
}
#define FKEYS_CPY( literal, field ) \
if ( !str_cmp( word, literal ) ) \
{ \
const char *tmp = fread_string(fp); \
strncpy(field, tmp, sizeof(field)); \
free_string(tmp); \
fread_to_eol(fp); \
fMatch = TRUE; \
break; \
}
#define KEY_ARRAY( literal, array, max, def ) \
if ( !str_cmp( word, literal ) ) \
{ \
read_array(array, max, def); \
fMatch = TRUE; \
break; \
}
#define KEY_IGNORE(literal) \
if ( !str_cmp(word, literal ) ) \
{ \
read_to_eol(fp); \
fMatch = TRUE; \
break; \
}
#define KEY_DO(literal, dothis) \
if (!str_cmp(word, literal ) ) \
{ \
dothis; \
read_to_eol(fp); \
fMatch = TRUE; \
break; \
}
#define KEYT( literal, field) \
if ( !str_cmp( word, literal ) ) \
{ \
read_time(str, &field); \
fMatch = TRUE; \
break; \
}
#define KEY( literal, field, value ) \
if ( !str_cmp( word, literal ) ) \
{ \
field = value; \
read_to_eol(fp); \
fMatch = TRUE; \
break; \
}
#define KEYS( literal, field ) \
if ( !str_cmp( word, literal ) ) \
{ \
free_read_string(field, fp); \
read_to_eol(fp); \
fMatch = TRUE; \
break; \
}
#define KEY_SFUN( literal, field, strfun ) \
if ( !str_cmp( word, literal ) ) \
{ \
const char *tmp = read_string(fp); \
field = strfun(tmp); \
free_string(tmp); \
fMatch = TRUE; \
break; \
}
#define KEYS_CPY( literal, field ) \
if ( !str_cmp( word, literal ) ) \
{ \
const char *tmp = read_string(fp); \
strncpy(field, tmp, sizeof(field)); \
free_string(tmp); \
read_to_eol(fp); \
fMatch = TRUE; \
break; \
}
#define fwrite_array(name, format, array, max) \
do { \
int tmp; \
if(IS_NULLSTR(name)) \
fprintf(fp, "%d", max); \
else \
fprintf(fp, "%s%s%d", name, format_tabs(strlen(name)), max); \
for(tmp = 0; tmp < max; tmp++) \
fprintf(fp, " " format, array[tmp]); \
if(!IS_NULLSTR(name)) \
fprintf(fp, "\n"); \
} while(0)
#define fread_array(array, max, def) \
do \
{ \
int tmp = 0, tmpmax = fread_number(fp); \
while(tmp < UMIN(max, tmpmax)) \
array[tmp++] = fread_number(fp); \
fread_to_eol(fp); \
while(tmp < max) \
array[tmp++] = def; \
} while(0)
#define read_array(array, max, def) \
do \
{ \
int tmp = 0, tmpmax = read_number(fp); \
while(tmp < UMIN(max, tmpmax)) \
array[tmp++] = read_number(fp); \
read_to_eol(fp); \
while(tmp < max) \
array[tmp++] = def; \
} while(0)
#define fwrite_int(fp, name, format, var, def) \
do { \
if(IS_NULLSTR(name)) \
fprintf((fp), format "\n", (var)); \
else if ((var) != (def)) \
fprintf((fp), "%s%s" format "\n", (name), \
format_tabs(strlen(name)), (var)); \
} while(0)
#define fread_enum(type, fp) (type)fread_number(fp)
#define read_enum(type, fp) (type)read_number(fp)
#define free_fread_string( point, fp ) do{ if(point != NULL) free_string(point); point = fread_string(fp); }while(0)
#define free_read_string( point, fp ) do{ if(point != NULL) free_string(point); point = read_string(fp); }while(0)
PROTOTYPE(void fwrite_string,
(FILE *, const char *, const char *, const char *));
PROTOTYPE(char *format_tabs, (int));
PROTOTYPE(void fwrite_word, (FILE *, const char *, const char *, const char *));
PROTOTYPE(void fwrite_bit, (FILE *, const char *, flag_t, flag_t));
PROTOTYPEF(void fwritef, (FILE *, const char *, const char *, ...), 3, 4);
PROTOTYPE(bool steof, (READ_DATA *));
PROTOTYPE(char stgetc, (READ_DATA *));
#endif