dlb capacity (trunk only)

From the newsgroup:  if someone adds too many new special levels, dlb
creation during install will give a warning but still exit with success,
and the subsequent installation won't know that the excess files need to be
placed in the playground separately.  The result is that some files will
be missing when nethack tries to access them.  The newsgroup thread states
that slash'em increased dlb's default limit of 200 files to 300, and the
unnethack variant increased it to 250 and also changed the overflow message
into an error that causes 'make' to quit.  (The thread was initiated by
someone working on his own, not affiliated with either variant, who asked
for help figuring out why nethack couldn't find files at the end of the
alphabet.  My answer didn't help much; I thought he was working with
separate files rather than with a DLB container.)

     I started to go with the too-many-files-is-an-error fix, but instead
went the GNU route ("no arbitrary limits") and made the number of allowed
files become dynamic.  It starts at 200 and expands by increments of 40
when necessary.
This commit is contained in:
nethack.rankin
2012-01-16 03:56:08 +00:00
parent bf106e38f2
commit c0743f478a
2 changed files with 30 additions and 13 deletions

View File

@@ -431,6 +431,7 @@ platforms that support hangup: SAFERHANGUP to avoid losing objects in transit
X11: support dynamic switching of map mode via tiled_map option
X11: added support for hilite_pet to text map mode
tty: various bugfixes for very wide and/or tall screens
build-from-source: dlb utility can handle arbitrary number of files
General New Features

View File

@@ -1,5 +1,4 @@
/* NetHack 3.5 dlb_main.c $Date$ $Revision$ */
/* SCCS Id: @(#)dlb_main.c 3.5 2007/10/27 */
/* Copyright (c) Kenneth Lorber, Bethesda, Maryland, 1993. */
/* NetHack may be freely redistributed. See license for details. */
@@ -14,6 +13,7 @@
#include <string.h>
#endif
static void FDECL(grow_ld, (libdir **,int *,int));
static void FDECL(xexit, (int));
#ifdef DLB
@@ -49,7 +49,7 @@ static char origdir[255]="";
#define O_BINARY 0
#endif
#define MAX_DLB_FILES 200 /* max # of files we'll handle */
#define DLB_FILES_ALLOC 200 /* initial # of files we'll handle; can grow */
#define DLB_VERS 1 /* version of dlb file we will write */
/*
@@ -331,7 +331,8 @@ main(argc, argv)
case 'c': /* create archive */
{
libdir ld[MAX_DLB_FILES];
libdir *ld = 0;
int ldlimit = 0;
char buf[BUFSIZ];
int fd, out, nfiles = 0;
long dir_size, slen, flen, fsiz;
@@ -342,14 +343,13 @@ main(argc, argv)
* list. This does not do any duplicate checking
*/
grow_ld(&ld, &ldlimit, DLB_FILES_ALLOC);
/* get file name in argv list */
if (argv[ap]) {
for ( ; ap < argc; ap++, nfiles++) {
if (nfiles >= MAX_DLB_FILES) {
printf("Too many dlb files! Stopping at %d.\n",
MAX_DLB_FILES);
break;
}
if (nfiles == ldlimit)
grow_ld(&ld, &ldlimit, DLB_FILES_ALLOC / 5);
ld[nfiles].fname = (char *) alloc(strlen(argv[ap]) + 1);
Strcpy(ld[nfiles].fname, argv[ap]);
}
@@ -365,11 +365,8 @@ main(argc, argv)
/* get file names, one per line */
for ( ; fgets(buf, sizeof(buf), list); nfiles++) {
if (nfiles >= MAX_DLB_FILES) {
printf("Too many dlb files! Stopping at %d.\n",
MAX_DLB_FILES);
break;
}
if (nfiles == ldlimit)
grow_ld(&ld, &ldlimit, DLB_FILES_ALLOC / 5);
*(eos(buf)-1) = '\0'; /* strip newline */
ld[nfiles].fname = (char *) alloc(strlen(buf) + 1);
Strcpy(ld[nfiles].fname, buf);
@@ -454,6 +451,7 @@ main(argc, argv)
for (i = 0; i < nfiles; i++)
free((genericptr_t) ld[i].fname), ld[i].fname = 0;
free((genericptr_t)ld), ldlimit = 0;
(void) close(out);
xexit(EXIT_SUCCESS);
@@ -470,6 +468,24 @@ main(argc, argv)
#ifdef DLB
#ifdef DLBLIB
static void
grow_ld(ld_p, ldlimit_p, alloc_incr)
libdir **ld_p;
int *ldlimit_p;
int alloc_incr;
{
static libdir zerolibdir;
int i = 0, newlimit = *ldlimit_p + alloc_incr;
libdir *newld = (libdir *)alloc(newlimit * sizeof *newld);
if (*ld_p) {
for ( ; i < *ldlimit_p; ++i) newld[i] = (*ld_p)[i];
free((genericptr_t)*ld_p);
}
*ld_p = newld, *ldlimit_p = newlimit;
for ( ; i < *ldlimit_p; ++i) (*ld_p)[i] = zerolibdir;
}
static void
write_dlb_directory(out, nfiles, ld, slen, dir_size, flen)
int out, nfiles;