2 * Copyright (C) 1994, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.1 1994-09-12 08:02:13 quinn
22 static int splitargs(const char *s, char *bf[], int max)
27 while (*s && isspace(*s))
35 log(LOG_WARN, "Ignoring extra args to is resource");
39 while (*s && !isspace(*s))
48 ISAM is_open(const char *name, int writeflag)
51 char *nm, *r, *pp[IS_MAX_BLOCKTYPES+1], m[2];
52 int num, size, rs, tmp, i;
54 log(LOG_DEBUG, "is_open(%s, %s)", name, writeflag ? "RW" : "RDONLY");
55 new = xmalloc(sizeof(*new));
56 new->writeflag = writeflag;
58 /* determine number and size of blocktypes */
59 if (!(r = res_get(common_resource, nm = strconcat(name, ".",
60 "blocktypes", 0))) || !(num = splitargs(r, pp, IS_MAX_BLOCKTYPES)))
62 log(LOG_FATAL, "Failed to locate resource %s", nm);
66 for (i = 0; i < num; i++)
68 if ((rs = sscanf(pp[i], "%d%1[bBkKmM]", &size, m)) < 1)
70 log(LOG_FATAL, "Error in resource %s: %s", r, pp[i]);
78 new->types[i].blocksize = size; break;
80 new->types[i].blocksize = size * 1024; break;
82 new->types[i].blocksize = size * 1048576; break;
84 log(LOG_FATAL, "Illegal size suffix: %c", *m);
89 if (!(new->types[i].bf = bf_open(strconcat(name, m, 0),
90 new->types[i].blocksize, writeflag)))
92 log(LOG_FATAL, "bf_open failed");
97 /* determine nice fill rates */
98 if (!(r = res_get(common_resource, nm = strconcat(name, ".",
99 "nicefill", 0))) || !(num = splitargs(r, pp, IS_MAX_BLOCKTYPES)))
101 log(LOG_FATAL, "Failed to locate resource %s", nm);
104 if (num < new->num_types)
106 log(LOG_FATAL, "Not enough elements in %s", nm);
109 for (i = 0; i < num; i++)
111 if ((rs = sscanf(pp[i], "%d", &tmp)) < 1)
113 log(LOG_FATAL, "Error in resource %s: %s", r, pp[i]);
116 new->types[i].nice_keys_block = tmp;
119 /* determine max keys/blocksize */
120 if (!(r = res_get(common_resource, nm = strconcat(name, ".",
121 "maxkeys", 0))) || !(num = splitargs(r, pp, IS_MAX_BLOCKTYPES)))
123 log(LOG_FATAL, "Failed to locate resource %s", nm);
126 if (num < new->num_types -1)
128 log(LOG_FATAL, "Not enough elements in %s", nm);
131 for (i = 0; i < num; i++)
133 if ((rs = sscanf(pp[i], "%d", &tmp)) < 1)
135 log(LOG_FATAL, "Error in resource %s: %s", r, pp[i]);
138 new->types[i].max_keys = tmp;
146 int is_close(ISAM is)
148 log(LOG_DEBUG, "is_close()");
149 log(LOG_LOG, "is_close needs to close individual files.");