namespace.c 1.06 KB
Newer Older
1
#include <stdlib.h>
2
#include <stdio.h>
3
#include "cdi.h"
4
#include "namespace.h"
5
6
7
8
9
10
11

enum { MAX_NAMESPACES = 16 };

static int nNamespaces = 1;
static int activeNamespace;


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45

void namespaceShowbits ( int n, char *name )
{
  int i, bit = 0, andmask;

  fprintf (stdout, "%s: ", name );  
  for ( i = 0; i < 32; i++ )
    {
      andmask = 1 << i;
      bit = n & andmask;
      fprintf ( stdout, "%d", bit == 0 ? 0 : 1 );
    }
  fprintf (stdout, "\n" );
}


int namespaceIdxEncode ( namespaceTuple_t tin )
{
  
  return ( tin.nsp << 28 ) + tin.idx;
} 


namespaceTuple_t namespaceIdxDecode ( int code )
{
  namespaceTuple_t tin;

  tin.idx = code & ~( 15 << 28 );
  tin.nsp = ( code & ( 15 << 28 )) >> 28;

  return tin;
}


46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
void namespaceSetNumber ( int nspn )
{
  if ( nspn > MAX_NAMESPACES || nspn <= 1 )
    abort ();

  nNamespaces = nspn;
}

int namespaceGetNumber ()
{
  return nNamespaces;
}


void namespaceSetActive ( int nId )
{
  if ( nId >= nNamespaces || nId < 0 )
    abort ();

  activeNamespace = nId;
}

68

69
70
71
72
73
74
75
76
77
int namespaceGetActive ()
{
  return activeNamespace;
}