aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gnu-taler-error-codes/.gitignore5
-rw-r--r--gnu-taler-error-codes/Makefile16
-rw-r--r--gnu-taler-error-codes/c-length.template9
-rw-r--r--gnu-taler-error-codes/c.footer33
-rw-r--r--gnu-taler-error-codes/c.header47
-rw-r--r--gnu-taler-error-codes/c.template5
-rw-r--r--gnu-taler-error-codes/h.footer10
-rw-r--r--gnu-taler-error-codes/registry.rec4
8 files changed, 127 insertions, 2 deletions
diff --git a/gnu-taler-error-codes/.gitignore b/gnu-taler-error-codes/.gitignore
index 9111c0f..4331786 100644
--- a/gnu-taler-error-codes/.gitignore
+++ b/gnu-taler-error-codes/.gitignore
@@ -1,8 +1,13 @@
1taler-error-codes.h 1taler-error-codes.h
2taler-error-codes.c
2taler-error-codes.ts 3taler-error-codes.ts
3taler-error-codes.kt 4taler-error-codes.kt
4 5
5combined.tmp 6combined.tmp
7combined-escaped.tmp
8length.tmp
6taler-error-codes.h.tmp 9taler-error-codes.h.tmp
10taler-error-codes.c.tmp
11taler-error-codes-length.c.tmp
7taler-error-codes.ts.tmp 12taler-error-codes.ts.tmp
8taler-error-codes.kt.tmp 13taler-error-codes.kt.tmp
diff --git a/gnu-taler-error-codes/Makefile b/gnu-taler-error-codes/Makefile
index c0bb208..2837753 100644
--- a/gnu-taler-error-codes/Makefile
+++ b/gnu-taler-error-codes/Makefile
@@ -1,4 +1,5 @@
1FILES=taler-error-codes.h \ 1FILES=taler-error-codes.h \
2 taler-error-codes.c \
2 taler-error-codes.ts \ 3 taler-error-codes.ts \
3 taler-error-codes.kt 4 taler-error-codes.kt
4all: check $(FILES) 5all: check $(FILES)
@@ -17,12 +18,27 @@ prep:
17combined.tmp: registry.rec prep 18combined.tmp: registry.rec prep
18 recsel -t TalerErrorCode -j HttpStatus -p Description,Name,Value,HttpStatus,HttpStatus.Value,HttpStatus.Identifier ../http-status-codes/registry.rec registry.rec > $@ 19 recsel -t TalerErrorCode -j HttpStatus -p Description,Name,Value,HttpStatus,HttpStatus.Value,HttpStatus.Identifier ../http-status-codes/registry.rec registry.rec > $@
19 20
21combined-escaped.tmp: combined.tmp
22 sed 's/"/\\"/g' $^ > $@
23
24length.tmp: combined.tmp
25 recsel -p "Count(Description):ECS_LENGTH" combined.tmp > $@
26
20taler-error-codes.h.tmp: combined.tmp h.template 27taler-error-codes.h.tmp: combined.tmp h.template
21 ../format.sh h.template < combined.tmp > $@ 28 ../format.sh h.template < combined.tmp > $@
22 29
23taler-error-codes.h: h.header taler-error-codes.h.tmp h.footer 30taler-error-codes.h: h.header taler-error-codes.h.tmp h.footer
24 cat $^ > $@ 31 cat $^ > $@
25 32
33taler-error-codes.c.tmp: combined-escaped.tmp c.template
34 ../format.sh c.template < combined-escaped.tmp > $@
35
36taler-error-codes-length.c.tmp: length.tmp c-length.template
37 ../format.sh c-length.template < length.tmp > $@
38
39taler-error-codes.c: c.header taler-error-codes.c.tmp taler-error-codes-length.c.tmp c.footer
40 cat $^ > $@
41
26taler-error-codes.ts.tmp: combined.tmp ts.template 42taler-error-codes.ts.tmp: combined.tmp ts.template
27 ../format.sh ts.template < combined.tmp > $@ 43 ../format.sh ts.template < combined.tmp > $@
28 44
diff --git a/gnu-taler-error-codes/c-length.template b/gnu-taler-error-codes/c-length.template
new file mode 100644
index 0000000..24e3e41
--- /dev/null
+++ b/gnu-taler-error-codes/c-length.template
@@ -0,0 +1,9 @@
1
2
3};
4
5
6/**
7 * The length of @e code_hint_pairs.
8 */
9static const unsigned int code_hint_pairs_length = {{ECS_LENGTH}};
diff --git a/gnu-taler-error-codes/c.footer b/gnu-taler-error-codes/c.footer
new file mode 100644
index 0000000..c348200
--- /dev/null
+++ b/gnu-taler-error-codes/c.footer
@@ -0,0 +1,33 @@
1
2
3
4/**
5 * Returns a hint for a given error code.
6 *
7 * @param ec the error code.
8 * @return the hint if it could be found, otherwise NULL.
9 */
10const char *
11TALER_ErrorCode_get_hint (enum TALER_ErrorCode ec)
12{
13 unsigned int lower = 0;
14 unsigned int upper = code_hint_pairs_length - 1;
15 unsigned int mid = upper / 2;
16 while (lower <= upper)
17 {
18 mid = (upper + lower) / 2;
19 if (code_hint_pairs[mid].ec < ec)
20 {
21 lower = mid + 1;
22 }
23 else if (code_hint_pairs[mid].ec > ec)
24 {
25 upper = mid - 1;
26 }
27 else
28 {
29 return code_hint_pairs[mid].hint;
30 }
31 }
32 return NULL;
33}
diff --git a/gnu-taler-error-codes/c.header b/gnu-taler-error-codes/c.header
new file mode 100644
index 0000000..434bcee
--- /dev/null
+++ b/gnu-taler-error-codes/c.header
@@ -0,0 +1,47 @@
1/*
2 This file is part of GNU Taler
3 Copyright (C) 2012-2020 Taler Systems SA
4
5 GNU Taler is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Lesser General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNU Taler is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: LGPL3.0-or-later
19
20 Note: the LGPL does not apply to all components of GNU Taler,
21 but it does apply to this file.
22 */
23#include "taler-error-codes.h"
24#include <stddef.h>
25
26
27/**
28 * A pair containing an error code and its hint.
29 */
30struct ErrorCodeAndHint
31{
32 /**
33 * The error code.
34 */
35 enum TALER_ErrorCode ec;
36
37 /**
38 * The hint.
39 */
40 const char *hint;
41};
42
43
44/**
45 * The list of all error codes with their hints.
46 */
47static const struct ErrorCodeAndHint code_hint_pairs[] = {
diff --git a/gnu-taler-error-codes/c.template b/gnu-taler-error-codes/c.template
new file mode 100644
index 0000000..02c39ed
--- /dev/null
+++ b/gnu-taler-error-codes/c.template
@@ -0,0 +1,5 @@
1
2 {
3 .ec = TALER_EC_{{Name}},
4 .hint = "{{Description}}"
5 },
diff --git a/gnu-taler-error-codes/h.footer b/gnu-taler-error-codes/h.footer
index 5d32ee9..1357a9e 100644
--- a/gnu-taler-error-codes/h.footer
+++ b/gnu-taler-error-codes/h.footer
@@ -3,6 +3,16 @@
3}; 3};
4 4
5 5
6/**
7 * Returns a hint for a given error code.
8 *
9 * @param ec the error code.
10 * @return the hint if it could be found, otherwise NULL.
11 */
12const char *
13TALER_ErrorCode_get_hint (enum TALER_ErrorCode ec);
14
15
6#if 0 /* keep Emacsens' auto-indent happy */ 16#if 0 /* keep Emacsens' auto-indent happy */
7{ 17{
8#endif 18#endif
diff --git a/gnu-taler-error-codes/registry.rec b/gnu-taler-error-codes/registry.rec
index 5fb2954..e7ca9e1 100644
--- a/gnu-taler-error-codes/registry.rec
+++ b/gnu-taler-error-codes/registry.rec
@@ -74,7 +74,7 @@ HttpStatus: 0
74 74
75Value: 10 75Value: 10
76Name: ENDPOINT_UNKNOWN 76Name: ENDPOINT_UNKNOWN
77Description: There is no endpoint defined for the URL provided by the client ( 77Description: There is no endpoint defined for the URL provided by the client.
78HttpStatus: 404 78HttpStatus: 404
79 79
80Value: 11 80Value: 11
@@ -84,7 +84,7 @@ HttpStatus: 414
84 84
85Value: 12 85Value: 12
86Name: WRONG_NUMBER_OF_SEGMENTS 86Name: WRONG_NUMBER_OF_SEGMENTS
87Description: The number of segments included in the URI does not match the number of segments expected by the endpoint. ( 87Description: The number of segments included in the URI does not match the number of segments expected by the endpoint.
88HttpStatus: 404 88HttpStatus: 404
89 89
90Value: 13 90Value: 13