#define smalloc malloc
#define srealloc realloc
#define sfree free
-#define mknew(type) ( (type *) smalloc (sizeof (type)) )
-#define mknewa(type, number) ( (type *) smalloc ((number) * sizeof (type)) )
-#define resize(array, len) ( srealloc ((array), (len) * sizeof (*(array))) )
+#define snew(type) ( (type *) smalloc (sizeof (type)) )
+#define snewn(number, type) ( (type *) smalloc ((number) * sizeof (type)) )
+#define sresize(array, len, type) \
+ ( (type *) srealloc ((array), (len) * sizeof (type)) )
#define lenof(array) ( sizeof(array) / sizeof(*(array)) )
char *dupstr(char *s) {
- char *r = mknewa(char, 1+strlen(s)); strcpy(r,s); return r;
+ char *r = snewn(1+strlen(s), char); strcpy(r,s); return r;
}
#endif
WHLP_TOPIC whlp_register_topic(WHLP h, char *context_name, char **clash)
{
- context *ctx = mknew(context);
+ context *ctx = snew(context);
context *otherctx;
/*
while ( (ctx = index234(h->pre_contexts, 0)) != NULL ) {
delpos234(h->pre_contexts, 0);
- ctx->name = mknewa(char, 20);
+ ctx->name = snewn(20, char);
do {
sprintf(ctx->name, "t%08d", ctx_num++);
ctx->hash = context_hash(ctx->name);
void whlp_begin_topic(WHLP h, WHLP_TOPIC topic, char *title, ...)
{
- struct topiclink *link = mknew(struct topiclink);
+ struct topiclink *link = snew(struct topiclink);
int len, slen;
char *macro;
va_list ap;
link->recordtype = 2; /* topic header */
link->len1 = 4*7; /* standard linkdata1 size */
- link->data1 = mknewa(unsigned char, link->len1);
+ link->data1 = snewn(link->len1, unsigned char);
slen = strlen(title);
assert(slen+1 <= TOPIC_BLKSIZE);
len--; /* lose the last \0 on the last macro */
link->len2 = len;
- link->data2 = mknewa(unsigned char, link->len2);
+ link->data2 = snewn(link->len2, unsigned char);
memcpy(link->data2, h->linkdata2, link->len2);
topic->title = dupstr(title);
if (alignment == WHLP_ALIGN_RIGHT)
tabstop |= 0x10000;
- p = mknew(int);
+ p = snew(int);
*p = tabstop;
add234(h->tabstops, p);
h->para_flags |= 0x0200;
void whlp_begin_para(WHLP h, int para_type)
{
- struct topiclink *link = mknew(struct topiclink);
+ struct topiclink *link = snew(struct topiclink);
int i;
/*
whlp_linkdata_cslong(h, 1, data1cut);
whlp_linkdata_cushort(h, 1, h->link->len2);
- h->link->data1 = mknewa(unsigned char, h->link->len1);
+ h->link->data1 = snewn(h->link->len1, unsigned char);
memcpy(h->link->data1, h->linkdata1 + data1cut, h->link->len1 - data1cut);
memcpy(h->link->data1 + h->link->len1 - data1cut, h->linkdata1, data1cut);
- h->link->data2 = mknewa(unsigned char, h->link->len2);
+ h->link->data2 = snewn(h->link->len2, unsigned char);
memcpy(h->link->data2, h->linkdata2, h->link->len2);
addpos234(h->text, h->link, count234(h->text));
/*
* Create a final TOPICLINK containing no usable data.
*/
- link = mknew(struct topiclink);
+ link = snew(struct topiclink);
link->nexttopic = NULL;
if (h->prevtopic)
h->prevtopic->nexttopic = link;
h->prevtopic = link;
- link->data1 = mknewa(unsigned char, 0x1c);
+ link->data1 = snewn(0x1c, unsigned char);
link->block_size = 0;
link->data2 = NULL;
link->len1 = 0x1c;
void whlp_index_term(WHLP h, char *index, WHLP_TOPIC topic)
{
- struct indexrec *idx = mknew(struct indexrec);
+ struct indexrec *idx = snew(struct indexrec);
idx->term = dupstr(index);
idx->topic = topic;
sfree(fontname);
}
- fontdesc = mknew(struct fontdesc);
+ fontdesc = snew(struct fontdesc);
fontdesc->font = font;
fontdesc->family = family;
fontdesc->halfpoints = halfpoints;
npages_this_level++;
if (npages >= pagessize) {
pagessize = npages + 32;
- page_elements = resize(page_elements, pagessize);
+ page_elements = sresize(page_elements, pagessize, void *);
}
page_elements[npages++] = element;
npages_this_level++;
if (npages >= pagessize) {
pagessize = npages + 32;
- page_elements = resize(page_elements, pagessize);
+ page_elements = sresize(page_elements, pagessize, void *);
}
page_elements[npages++] = page_elements[current];
static struct file *whlp_new_file(WHLP h, char *name)
{
struct file *f;
- f = mknew(struct file);
+ f = snew(struct file);
f->data = NULL;
f->pos = f->len = f->size = 0;
if (name) {
{
if (f->pos + len > f->size) {
f->size = f->pos + len + 1024;
- f->data = resize(f->data, f->size);
+ f->data = sresize(f->data, f->size, unsigned char);
}
memcpy(f->data + f->pos, data, len);
f->pos += len;
{
if (f->pos + len > f->size) {
f->size = f->pos + len + 1024;
- f->data = resize(f->data, f->size);
+ f->data = sresize(f->data, f->size, unsigned char);
}
memset(f->data + f->pos, 0, len);
f->pos += len;
WHLP ret;
struct file *f;
- ret = mknew(struct WHLP_tag);
+ ret = snew(struct WHLP_tag);
/*
* Internal B-trees.