File: GGStructSizes.c

package info (click to toggle)
ggobi 2.1.9~20091212-3
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 19,340 kB
  • ctags: 5,083
  • sloc: ansic: 57,242; xml: 30,604; cpp: 833; makefile: 355; java: 225; perl: 201; sh: 122; python: 23
file content (84 lines) | stat: -rw-r--r-- 1,776 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/* GGStructSizes.c */

#ifndef GGStructSizes_C
#define GGStructSizes_C

typedef struct
{
  unsigned int size;
  const char *const name;
} GGobi_StructSize;

#ifdef USE_DBMS
#include "dbms.h"
#endif

#define GG_StructEntry(type) {sizeof(type), #type}

static const GGobi_StructSize ggobiStructs[] = {
  GG_StructEntry (ggobid),
  GG_StructEntry (GGobiData),
  GG_StructEntry (displayd),
  GG_StructEntry (splotd),
  GG_StructEntry (vartabled),
  GG_StructEntry (GGobiOptions)
#ifdef USE_DBMS
    , GG_StructEntry (DBMSLoginInfo)
#endif
};

extern const GGobi_StructSize *GGOBI (getStructs) (int *n);

const GGobi_StructSize *
#ifdef GGOBI_MAIN
  GGOBI (getStructs) (int *n)
#else
  GGOBI (getGGobiStructs) (int *n)
#endif
{
  *n = sizeof (ggobiStructs) / sizeof (ggobiStructs[0]);
  return (ggobiStructs);
}


#ifndef GGOBI_MAIN

#include <string.h>

gboolean
checkGGobiStructSizes ()
{
  const GGobi_StructSize *local, *internal;
  int nlocal, ninternal;
  int i, j;
  gboolean ok = false;

  local = GGOBI (getStructs) (&nlocal);
  internal = GGOBI (getGGobiStructs) (&ninternal);

  if (nlocal != ninternal)
    g_printerr ("Different number of structures in table (%d != %d)!\n",
                nlocal, ninternal);

  for (i = 0; i < nlocal; i++) {
    for (j = 0; j < ninternal; j++)
      if (strcmp (local[i].name, internal[j].name) == 0) {
        if (local[i].size != internal[j].size) {
          g_printerr ("Inconsistent struct sizes for %s: %d != %d\n",
                      local[i].name, local[i].size, internal[j].size);
        }
        ok = true;
        break;
      }
    if (j == ninternal) {
      g_printerr ("No entry for `%s' struct in the internals\n",
                  local[i].name);
      ok = false;
    }
  }
  return (ok);
}
#endif


#endif