Revive struct empfile callback init as oninit

Commit a71f0158 removed unused callback init.  Bring it back renamed
to oninit, and without the redundant first argument.
This commit is contained in:
Markus Armbruster 2008-09-07 11:27:18 -04:00
parent b22520d180
commit a1f20efd02
3 changed files with 21 additions and 13 deletions

View file

@ -60,6 +60,10 @@ struct empfile {
/* flags bit EFF_CUSTOM also varies */ /* flags bit EFF_CUSTOM also varies */
/* User callbacks, may all be null */ /* User callbacks, may all be null */
/*
* Called after element initialization. ELT is the element.
*/
void (*oninit)(void *elt);
/* /*
* Called after read. ID is the element id, and ELT is the * Called after read. ID is the element id, and ELT is the
* element read. May modify the element. Modifications are * element read. May modify the element. Modifications are

View file

@ -667,12 +667,14 @@ do_blank(struct empfile *ep, void *buf, int id, int count)
struct emptypedstr *elt; struct emptypedstr *elt;
memset(buf, 0, count * ep->size); memset(buf, 0, count * ep->size);
if (ep->flags & EFF_TYPED) {
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
elt = (struct emptypedstr *)((char *)buf + i * ep->size); elt = (struct emptypedstr *)((char *)buf + i * ep->size);
if (ep->flags & EFF_TYPED) {
elt->ef_type = ep->uid; elt->ef_type = ep->uid;
elt->uid = id + i; elt->uid = id + i;
} }
if (ep->oninit)
ep->oninit(elt);
} }
} }

View file

@ -62,28 +62,29 @@
/* Initializers for members flags... */ /* Initializers for members flags... */
/* Unmapped cache */ /* Unmapped cache */
#define UNMAPPED_CACHE(type, flags) \ #define UNMAPPED_CACHE(type, flags) \
sizeof(type), (flags), NULL, 0, 0, 0, 0, -1, NULL, NULL sizeof(type), (flags), NULL, 0, 0, 0, 0, -1, NULL, NULL, NULL
/* /*
* Mapped cache, array with known size. * Mapped cache, array with known size.
* Members cids, fids are not set. * Members cids, fids are not set.
*/ */
#define ARRAY_CACHE(array, flags) \ #define ARRAY_CACHE(array, flags) \
sizeof(*(array)), (flags), (char *)(array), \ sizeof(*(array)), (flags), (char *)(array), \
SZ((array)), 0, 0, 0, -1, NULL, NULL SZ((array)), 0, 0, 0, -1, NULL, NULL, NULL
/* /*
* Mapped cache, array with unknown size. * Mapped cache, array with unknown size.
* Members csize, cids, fids are not set. * Members csize, cids, fids are not set.
*/ */
#define PTR_CACHE(ptr, flags) \ #define PTR_CACHE(ptr, flags) \
sizeof(*(ptr)), (flags), (char *)(ptr), \ sizeof(*(ptr)), (flags), (char *)(ptr), \
0, 0, 0, 0, -1, NULL, NULL 0, 0, 0, 0, -1, NULL, NULL, NULL
/* /*
* Array-backed table. * Array-backed table.
* The array's last element is the sentinel. * The array's last element is the sentinel.
*/ */
#define ARRAY_TABLE(array, flags) \ #define ARRAY_TABLE(array, flags) \
sizeof(*(array)), (flags), (char *)(array), \ sizeof(*(array)), (flags), (char *)(array), \
SZ((array)), 0, SZ((array)) - 1, SZ((array)) - 1, -1, NULL, NULL SZ((array)), 0, SZ((array)) - 1, SZ((array)) - 1, -1, \
NULL, NULL, NULL
/* Common configuration table flags */ /* Common configuration table flags */
#define EFF_CFG (EFF_PRIVATE | EFF_MEM | EFF_STATIC | EFF_SENTINEL) #define EFF_CFG (EFF_PRIVATE | EFF_MEM | EFF_STATIC | EFF_SENTINEL)
@ -144,9 +145,9 @@ struct empfile empfile[] = {
{EF_LOAN, "loan", "loan", loan_ca, {EF_LOAN, "loan", "loan", loan_ca,
UNMAPPED_CACHE(struct lonstr, EFF_TYPED)}, UNMAPPED_CACHE(struct lonstr, EFF_TYPED)},
{EF_MAP, "map", "map", NULL, {EF_MAP, "map", "map", NULL,
0, 0, NULL, 0, 0, 0, 0, -1, NULL, NULL}, 0, 0, NULL, 0, 0, 0, 0, -1, NULL, NULL, NULL},
{EF_BMAP, "bmap", "bmap", NULL, {EF_BMAP, "bmap", "bmap", NULL,
0, 0, NULL, 0, 0, 0, 0, -1, NULL, NULL}, 0, 0, NULL, 0, 0, 0, 0, -1, NULL, NULL, NULL},
{EF_COMM, "commodity", "commodity", commodity_ca, {EF_COMM, "commodity", "commodity", commodity_ca,
UNMAPPED_CACHE(struct comstr, EFF_TYPED | EFF_OWNER)}, UNMAPPED_CACHE(struct comstr, EFF_TYPED | EFF_OWNER)},
{EF_LOST, "lost", "lostitems", lost_ca, {EF_LOST, "lost", "lostitems", lost_ca,
@ -196,7 +197,7 @@ struct empfile empfile[] = {
ARRAY_TABLE(empfile, EFF_CFG)}, ARRAY_TABLE(empfile, EFF_CFG)},
{EF_VERSION, "version", NULL, NULL, {EF_VERSION, "version", NULL, NULL,
sizeof(PACKAGE_STRING), EFF_STATIC, version, 1, 0, 1, 1, -1, sizeof(PACKAGE_STRING), EFF_STATIC, version, 1, 0, 1, 1, -1,
NULL, NULL}, NULL, NULL, NULL},
{EF_META, "meta", NULL, mdchr_ca, {EF_META, "meta", NULL, mdchr_ca,
PTR_CACHE(mdchr_ca, EFF_CFG)}, PTR_CACHE(mdchr_ca, EFF_CFG)},
@ -235,7 +236,8 @@ struct empfile empfile[] = {
UNMAPPED_CACHE(struct natstr, EFF_TYPED | EFF_OWNER)}, UNMAPPED_CACHE(struct natstr, EFF_TYPED | EFF_OWNER)},
/* Sentinel */ /* Sentinel */
{EF_BAD, NULL, NULL, NULL, 0, 0, NULL, 0, 0, 0, 0, -1, NULL, NULL}, {EF_BAD, NULL, NULL, NULL,
0, 0, NULL, 0, 0, 0, 0, -1, NULL, NULL, NULL},
}; };
static void static void