~fginther/geis/geis-2.2.9.1-precise

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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/**
 * @file libgeis/geis_error.c
 * @brief implementation of the GEIS v2.0 API error reporting module
 *
 * Copyright 2010 Canonical Ltd.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 3 of the License, or (at your option) any
 * later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
 * details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
 */
#include "geis_config.h"
#include "geis_error.h"

#include "geis_logging.h"
#include "geis_private.h"
#include <stdlib.h>


static GeisErrorStack g_error_stack = { 0, 0, 0 };


static void
geis_error_stack_clear(GeisErrorStack *error_stack)
{
  error_stack->error_count = 0;
}


static void
geis_error_stack_push(GeisErrorStack *error_stack, GeisStatus code)
{
  if (error_stack->error_count < error_stack->store_size)
  {
    error_stack->store[error_stack->error_count++] = code;
  }
  else
  {
    error_stack->store_size += 2;
    error_stack->store = realloc(error_stack->store,
                                 error_stack->store_size * sizeof(GeisErrorStack
));
    if (!error_stack->store)
    {
      geis_error("error_stack realloc failed for size %zu",
                 error_stack->store_size);
      return;
    }
    error_stack->store[error_stack->error_count++] = code;
  }
}


static GeisStatus
geis_error_stack_get(GeisErrorStack *error_stack, GeisSize index)
{
  if (index < error_stack->error_count)
  {
    return error_stack->store[index];
  }
  return GEIS_STATUS_BAD_ARGUMENT;
}


void
geis_error_clear(Geis geis)
{
  if (geis)
  {
    geis_error_stack_clear(geis_error_stack(geis));
  }
  else
  {
    geis_error_stack_clear(&g_error_stack);
  }
}


void
geis_error_push(Geis geis, GeisStatus code)
{
  if (geis)
  {
    geis_error_stack_push(geis_error_stack(geis), code);
  }
  else
  {
    geis_error_stack_push(&g_error_stack, code);
  }
}


GeisSize
geis_error_count(Geis geis)
{
  if (geis)
  {
    return geis_error_stack(geis)->error_count;
  }
  else
  {
    return g_error_stack.error_count;
  }
}


GeisStatus
geis_error_code(Geis geis, GeisSize index)
{
  GeisStatus status = GEIS_STATUS_UNKNOWN_ERROR;
  if (geis)
  {
    status = geis_error_stack_get(geis_error_stack(geis), index);
  }
  else
  {
    status = geis_error_stack_get(&g_error_stack, index);
  }
  return status;
}


GeisString
geis_error_message(Geis geis, GeisSize index GEIS_UNUSED)
{
  GeisString message = "";
  if (geis)
  {
  }
  else
  {
  }
  return message;
}