gen_allocdefs.h
author tomas@localhost
Thu, 01 Nov 2007 14:46:11 +0100
changeset 0 c045670f36e9
permissions -rw-r--r--
Imported queue-fix-1.4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
     1
#ifndef GEN_ALLOC_DEFS_H
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
     2
#define GEN_ALLOC_DEFS_H
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
     3
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
     4
#define GEN_ALLOC_ready(ta,type,field,len,a,i,n,x,base,ta_ready) \
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
     5
int ta_ready(x,n) register ta *x; register unsigned int n; \
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
     6
{ register unsigned int i; \
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
     7
  if (x->field) { \
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
     8
    i = x->a; \
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
     9
    if (n > i) { \
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    10
      x->a = base + n + (n >> 3); \
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    11
      if (alloc_re(&x->field,i * sizeof(type),x->a * sizeof(type))) return 1; \
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    12
      x->a = i; return 0; } \
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    13
    return 1; } \
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    14
  x->len = 0; \
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    15
  return !!(x->field = (type *) alloc((x->a = n) * sizeof(type))); }
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    16
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    17
#define GEN_ALLOC_readyplus(ta,type,field,len,a,i,n,x,base,ta_rplus) \
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    18
int ta_rplus(x,n) register ta *x; register unsigned int n; \
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    19
{ register unsigned int i; \
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    20
  if (x->field) { \
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    21
    i = x->a; n += x->len; \
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    22
    if (n > i) { \
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    23
      x->a = base + n + (n >> 3); \
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    24
      if (alloc_re(&x->field,i * sizeof(type),x->a * sizeof(type))) return 1; \
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    25
      x->a = i; return 0; } \
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    26
    return 1; } \
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    27
  x->len = 0; \
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    28
  return !!(x->field = (type *) alloc((x->a = n) * sizeof(type))); }
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    29
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    30
#define GEN_ALLOC_append(ta,type,field,len,a,i,n,x,base,ta_rplus,ta_append) \
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    31
int ta_append(x,i) register ta *x; register type *i; \
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    32
{ if (!ta_rplus(x,1)) return 0; x->field[x->len++] = *i; return 1; }
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    33
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    34
#endif