Back to index

texmacs  1.0.7.15
Classes | Defines | Typedefs | Functions
dpxutil.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  ht_entry
struct  ht_table
struct  ht_iter

Defines

#define MIN(a, b)   (((a) < (b)) ? (a) : (b))
#define MAX(a, b)   (((a) > (b)) ? (a) : (b))
#define ABS(a)   (((a) < 0) ? -(a) : (a))
#define is_space(c)
#define is_delim(c)
#define HASH_TABLE_SIZE   503
#define HT_NEW   0
#define HT_REPLACE   1
#define HT_KEEP   2
#define ht_append_table(ht, key, keylen, value)   ht_modify_table(ht, key, keylen, value, HT_NEW)
#define ht_insert_table(ht, key, keylen, value)   ht_modify_table(ht, key, keylen, value, HT_REPLACE)

Typedefs

typedef struct ht_table

Functions

void skip_white_spaces (unsigned char **s, unsigned char *endptr)
int xtoi (char c)
int getxpair (unsigned char **str)
int putxpair (unsigned char c, char **str)
int sputx (unsigned char c, char **buf, char *endptr)
unsigned char ostrtouc (unsigned char **inbuf, unsigned char *inbufend, unsigned char *valid)
unsigned char esctouc (unsigned char **inbuf, unsigned char *inbufend, unsigned char *valid)
void ht_init_table (struct ht_table *ht, void(*hval_free_fn)(void *))
void ht_clear_table (struct ht_table *ht)
long ht_table_size (struct ht_table *ht)
void * ht_lookup_table (struct ht_table *ht, const void *key, int keylen)
void ht_modify_table (struct ht_table *ht, const void *key, int keylen, void *value, int mode)
int ht_remove_table (struct ht_table *ht, const void *key, int keylen)
int ht_set_iter (struct ht_table *ht, struct ht_iter *iter)
void ht_clear_iter (struct ht_iter *iter)
char * ht_iter_getkey (struct ht_iter *iter, int *keylen)
void * ht_iter_getval (struct ht_iter *iter)
int ht_iter_next (struct ht_iter *iter)
char * parse_float_decimal (char **pp, char *endptr)
char * parse_c_string (char **pp, char *endptr)
char * parse_c_ident (char **pp, char *endptr)

Class Documentation

struct ht_entry

Definition at line 60 of file dpxutil.h.

Collaboration diagram for ht_entry:
Class Members
char * key
int keylen
struct ht_entry * next
void * value
struct ht_iter

Definition at line 97 of file dpxutil.h.

Collaboration diagram for ht_iter:
Class Members
void * curr
struct ht_table * hash
int index

Define Documentation

#define ABS (   a)    (((a) < 0) ? -(a) : (a))

Definition at line 33 of file dpxutil.h.

#define HASH_TABLE_SIZE   503

Definition at line 58 of file dpxutil.h.

#define ht_append_table (   ht,
  key,
  keylen,
  value 
)    ht_modify_table(ht, key, keylen, value, HT_NEW)

Definition at line 90 of file dpxutil.h.

#define ht_insert_table (   ht,
  key,
  keylen,
  value 
)    ht_modify_table(ht, key, keylen, value, HT_REPLACE)

Definition at line 92 of file dpxutil.h.

#define HT_KEEP   2

Definition at line 79 of file dpxutil.h.

#define HT_NEW   0

Definition at line 77 of file dpxutil.h.

#define HT_REPLACE   1

Definition at line 78 of file dpxutil.h.

#define is_delim (   c)
Value:
((c) == '(' || (c) == '/' || \
                     (c) == '<' || (c) == '>' || \
                   (c) == '[' || (c) == ']' || \
                     (c) == '{' || (c) == '}' || \
                     (c) == '%')

Definition at line 40 of file dpxutil.h.

#define is_space (   c)
Value:
((c) == ' '  || (c) == '\t' || (c) == '\f' || \
                   (c) == '\r' || (c) == '\n' || (c) == '\0')

Definition at line 36 of file dpxutil.h.

#define MAX (   a,
 
)    (((a) > (b)) ? (a) : (b))

Definition at line 31 of file dpxutil.h.

#define MIN (   a,
 
)    (((a) < (b)) ? (a) : (b))

Definition at line 29 of file dpxutil.h.


Typedef Documentation

typedef struct ht_table

Definition at line 75 of file dpxutil.h.


Function Documentation

unsigned char esctouc ( unsigned char **  inbuf,
unsigned char *  inbufend,
unsigned char *  valid 
)

Definition at line 113 of file dpxutil.c.

{
  unsigned char unescaped, escaped;

  escaped = **inbuf;
  *valid    = 1;
  switch (escaped) {
    /* Backslash, unbalanced paranthes */
  case '\\': case ')': case '(':
    unescaped = escaped;
    (*inbuf)++;
    break;
    /* Other escaped char */ 
  case 'n': unescaped = '\n'; (*inbuf)++; break;
  case 'r': unescaped = '\r'; (*inbuf)++; break;
  case 't': unescaped = '\t'; (*inbuf)++; break;
  case 'b': unescaped = '\b'; (*inbuf)++; break;
  case 'f': unescaped = '\f'; (*inbuf)++; break;
    /*
     * An end-of-line marker preceeded by backslash is not part of a
     * literal string
     */
  case '\r':
    unescaped = 0;
    *valid    = 0;
    *inbuf   += (*inbuf < inbufend - 1 && *(*inbuf+1) == '\n') ? 2 : 1;
    break;
  case '\n':
    unescaped = 0;
    *valid    = 0;
    (*inbuf)++;
    break;
    /* Possibly octal notion */ 
  default:
    unescaped = ostrtouc(inbuf, inbufend, valid);
  }

  return unescaped;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int getxpair ( unsigned char **  str)

Definition at line 65 of file dpxutil.c.

{
  int hi, lo;
  hi = xtoi(**s);
  if (hi < 0)
    return hi;
  (*s)++;
  lo = xtoi(**s);
  if (lo < 0)
    return lo;
  (*s)++;
  return ((hi << 4)| lo);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void ht_clear_iter ( struct ht_iter iter)

Definition at line 361 of file dpxutil.c.

{
  if (iter) {
    iter->index = HASH_TABLE_SIZE;
    iter->curr  = NULL;
    iter->hash  = NULL;
  }
}

Here is the caller graph for this function:

void ht_clear_table ( struct ht_table ht)

Definition at line 178 of file dpxutil.c.

{
  int   i;

  ASSERT(ht);

  for (i = 0; i < HASH_TABLE_SIZE; i++) {
    struct ht_entry *hent, *next;

    hent = ht->table[i];
    while (hent) {
      if (hent->value && ht->hval_free_fn) {
       ht->hval_free_fn(hent->value);
      }
      hent->value  = NULL;
      if (hent->key) {
       RELEASE(hent->key);
      }
      hent->key = NULL;
      next = hent->next;
      RELEASE(hent);
      hent = next;
    }
    ht->table[i] = NULL;
  }
  ht->count = 0;
  ht->hval_free_fn = NULL;
}

Here is the caller graph for this function:

void ht_init_table ( struct ht_table ht,
void(*)(void *)  hval_free_fn 
)

Definition at line 164 of file dpxutil.c.

{
  int  i;

  ASSERT(ht);

  for (i = 0; i < HASH_TABLE_SIZE; i++) {
    ht->table[i] = NULL;
  }
  ht->count = 0;
  ht->hval_free_fn = hval_free_fn;
}

Here is the caller graph for this function:

char* ht_iter_getkey ( struct ht_iter iter,
int *  keylen 
)

Definition at line 371 of file dpxutil.c.

{
  struct ht_entry *hent;

  hent = (struct ht_entry *) iter->curr;
  if (iter && hent) {
    *keylen = hent->keylen;
    return hent->key;
  } else {
    *keylen = 0;
    return NULL;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void* ht_iter_getval ( struct ht_iter iter)

Definition at line 386 of file dpxutil.c.

{
  struct ht_entry *hent;

  hent = (struct ht_entry *) iter->curr;
  if (iter && hent) {
    return hent->value;
  } else {
    return NULL;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

int ht_iter_next ( struct ht_iter iter)

Definition at line 399 of file dpxutil.c.

{
  struct ht_entry *hent;
  struct ht_table *ht;

  ASSERT(iter);

  ht   = iter->hash;
  hent = (struct ht_entry *) iter->curr;
  hent = hent->next;
  while (!hent &&
         ++iter->index < HASH_TABLE_SIZE) {
    hent = ht->table[iter->index];
  }
  iter->curr = hent;

  return (hent ? 0 : -1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void* ht_lookup_table ( struct ht_table ht,
const void *  key,
int  keylen 
)

Definition at line 228 of file dpxutil.c.

{
  struct ht_entry *hent;
  unsigned int     hkey;

  ASSERT(ht && key);

  hkey = get_hash(key, keylen);
  hent = ht->table[hkey];
  while (hent) {
    if (hent->keylen == keylen &&
       !memcmp(hent->key, key, keylen)) {
      return hent->value;
    }
    hent = hent->next;
  }

  return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void ht_modify_table ( struct ht_table ht,
const void *  key,
int  keylen,
void *  value,
int  mode 
)

Definition at line 291 of file dpxutil.c.

{
  struct ht_entry *hent, *prev;
  unsigned int     hkey;

  ASSERT(ht && key);

  hkey = get_hash(key, keylen);
  hent = ht->table[hkey];
  prev = NULL;
  while (hent) {
    if (hent->keylen == keylen &&
       !memcmp(hent->key, key, keylen)) {
      break;
    }
    prev = hent;
    hent = hent->next;
  }
  if (hent) {
    switch (mode) {
    case HT_NEW:
      ASSERT(0); /* duplicates not allowed in this mode */
      break;
    case HT_REPLACE: {
      if (hent->value && ht->hval_free_fn)
       ht->hval_free_fn(hent->value);
      hent->value  = value;
      break;
    }
    case HT_KEEP:
      ht->hval_free_fn(value);
      break;
    }
  } else {
    hent = NEW(1, struct ht_entry);
    hent->key = NEW(keylen, char);
    memcpy(hent->key, key, keylen);
    hent->keylen = keylen;
    hent->value  = value;
    hent->next   = NULL;
    if (prev) {
      prev->next      = hent;
    } else {
      ht->table[hkey] = hent;
    }
    ht->count++;
  }
}

Here is the call graph for this function:

int ht_remove_table ( struct ht_table ht,
const void *  key,
int  keylen 
)

Definition at line 249 of file dpxutil.c.

{
  struct ht_entry *hent, *prev;
  unsigned int     hkey;

  ASSERT(ht && key);

  hkey = get_hash(key, keylen);
  hent = ht->table[hkey];
  prev = NULL;
  while (hent) {
    if (hent->keylen == keylen &&
       !memcmp(hent->key, key, keylen)) {
      break;
    }
    prev = hent;
    hent = hent->next;
  }
  if (hent) {
    if (hent->key)
      RELEASE(hent->key);
    hent->key    = NULL;
    hent->keylen = 0;
    if (hent->value && ht->hval_free_fn) {
      ht->hval_free_fn(hent->value);
    }
    hent->value  = NULL;
    if (prev) {
      prev->next = hent->next;
    } else {
      ht->table[hkey] = hent->next;
    }
    RELEASE(hent);
    ht->count--;
    return 1;
  } else
    return 0;
}

Here is the call graph for this function:

int ht_set_iter ( struct ht_table ht,
struct ht_iter iter 
)

Definition at line 342 of file dpxutil.c.

{
  int    i;

  ASSERT(ht && ht->table && iter);

  for (i = 0; i < HASH_TABLE_SIZE; i++) {
    if (ht->table[i]) {
      iter->index = i;
      iter->curr  = ht->table[i];
      iter->hash  = ht;
      return 0;
    }
  }

  return -1;
}

Here is the caller graph for this function:

long ht_table_size ( struct ht_table ht)

Definition at line 207 of file dpxutil.c.

{
  ASSERT(ht);

  return ht->count;
}

Here is the caller graph for this function:

unsigned char ostrtouc ( unsigned char **  inbuf,
unsigned char *  inbufend,
unsigned char *  valid 
)

Definition at line 93 of file dpxutil.c.

{
  unsigned char *cur = *inbuf;
  unsigned int   val = 0;

  while (cur < inbufend && cur < *inbuf + 3 &&
        (*cur >= '0' && *cur <= '7')) {
    val = (val << 3) | (*cur - '0');
    cur++;
  }
  if (val > 255 || cur == *inbuf)
    *valid = 0;
  else
    *valid = 1;

  *inbuf = cur;
  return (unsigned char) val;
}

Here is the caller graph for this function:

char* parse_c_ident ( char **  pp,
char *  endptr 
)

Definition at line 567 of file dpxutil.c.

{
  char  *q = NULL;
  char  *p = *pp;
  int    n;

  if (p >= endptr || !ISCNONDIGITS(*p))
    return NULL;

  for (n = 0; p < endptr && ISCIDENTCHAR(*p); p++, n++);
  q = NEW(n + 1, char);
  memcpy(q, *pp, n); q[n] = '\0';

  *pp = p;
  return  q;
}

Here is the caller graph for this function:

char* parse_c_string ( char **  pp,
char *  endptr 
)

Definition at line 535 of file dpxutil.c.

{
  char  *q = NULL;
  char  *p = *pp;
  int    l = 0;

  if (p >= endptr || p[0] != C_QUOTE)
    return NULL;

  p++;
  l = read_c_litstrc(NULL, 0, &p, endptr);
  if (l >= 0) {
    q = NEW(l + 1, char);
    p = *pp + 1;
    l = read_c_litstrc(q, l + 1, &p, endptr);
  }

  *pp = p;
  return  q;
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* parse_float_decimal ( char **  pp,
char *  endptr 
)

Definition at line 585 of file dpxutil.c.

{
  char  *q = NULL;
  char  *p = *pp;
  int    s = 0, n = 0;

  if (p >= endptr)
    return NULL;

  if (p[0] == '+' || p[0] == '-')
    p++;

  /* 1. .01 001 001E-001 */
  for (s = 0, n = 0; p < endptr && s >= 0; ) {
    switch (p[0]) {
    case '+': case '-':
      if (s != 2)
        s = -1;
      else {
        s = 3; p++;
      }
      break;
    case '.':
      if (s > 0)
        s = -1;
      else {
        s =  1; p++;
      }
      break;
    case '0': case '1': case '2': case '3': case '4':
    case '5': case '6': case '7': case '8': case '9':
      n++; p++;
      break;
    case 'E': case 'e':
      if (n == 0 || s == 2)
        s = -1;
      else {
        s = 2; p++;
      }
      break;
    default:
      s = -1;
      break;
    }
  }

  if (n != 0) {
    n = (int) (p - *pp);
    q = NEW(n + 1, char);
    memcpy(q, *pp, n); q[n] = '\0';
  }

  *pp = p;
  return  q;
}

Here is the caller graph for this function:

int putxpair ( unsigned char  c,
char **  str 
)

Definition at line 80 of file dpxutil.c.

{
  char hi = (c >> 4), lo = c & 0x0f;

  **s = (hi < 10) ? hi + '0' : hi + '7';
  *(*s+1) = (lo < 10) ? lo + '0' : lo + '7';
  *s += 2;

  return 2;
}
void skip_white_spaces ( unsigned char **  s,
unsigned char *  endptr 
)

Definition at line 154 of file dpxutil.c.

{
  while (*s < endptr)
    if (!is_space(**s))
      break;
    else
      (*s)++;
}

Here is the caller graph for this function:

int sputx ( unsigned char  c,
char **  buf,
char *  endptr 
)

Definition at line 51 of file dpxutil.c.

{
  char hi = (c >> 4), lo = c & 0x0f;

  if (*s + 2 > end)
    ERROR("Buffer overflow.");
  **s = (hi < 10) ? hi + '0' : hi + '7';
  *(*s+1) = (lo < 10) ? lo + '0' : lo + '7';
  *s += 2;

  return 2;
}

Here is the caller graph for this function:

int xtoi ( char  c)

Definition at line 38 of file dpxutil.c.

{
  if (c >= '0' && c <= '9')
    return (c - '0');
  else if (c >= 'a' && c <= 'f')
    return (c - 'W');
  else if (c >= 'A' && c <= 'F')
    return (c - '7');
  else
    return -1;
}

Here is the caller graph for this function: