GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
db/dbmi_base/token.c
Go to the documentation of this file.
1 #include <grass/dbmi.h>
2 
3 /* these routines manage a mapping between tokens (ints) and memory addresses */
4 #define NONE ( (dbAddress) NULL )
5 
6 static dbAddress *list = NONE;
7 static dbToken count = 0;
8 
15 dbAddress db_find_token(dbToken token)
16 {
17  if (token >= 0 && token < count)
18  return list[token];
19  return (NONE);
20 }
21 
28 void db_drop_token(dbToken token)
29 {
30  if (token >= 0 && token < count)
31  list[token] = NONE;
32 }
33 
40 dbToken db_new_token(dbAddress address)
41 {
42  dbToken token;
43  dbAddress *p;
44 
45  for (token = 0; token < count; token++)
46  if (list[token] == NONE) {
47  list[token] = address;
48  return token;
49  }
50 
51  p = (dbAddress *) db_realloc((void *)list, sizeof(*list) * (count + 1));
52  if (p == NULL)
53  return -1;
54 
55  list = p;
56  token = count++;
57  list[token] = address;
58  return (token);
59 }
dbAddress db_find_token(dbToken token)
void db_drop_token(dbToken token)
int count
dbToken db_new_token(dbAddress address)
void * db_realloc(void *s, int n)
return NULL
Definition: dbfopen.c:1394
#define NONE