Tizen 2.0 Release
[external/libgnutls26.git] / doc / errcodes.c
1 /*
2  * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software
3  * Foundation, Inc.
4  * Author: Nikos Mavrogiannopoulos, Simon Josefsson
5  *
6  * This file is part of GnuTLS.
7  *
8  * GnuTLS is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * GnuTLS is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20  */
21
22 #ifdef HAVE_CONFIG_H
23 #include "config.h"
24 #endif
25
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <string.h>
29 #include <gnutls/gnutls.h>
30
31 typedef struct
32 {
33   char name[128];
34   int error_index;
35 } error_name;
36
37
38 static int
39 compar (const void *_n1, const void *_n2)
40 {
41   const error_name *n1 = (const error_name *) _n1,
42     *n2 = (const error_name *) _n2;
43   return strcmp (n1->name, n2->name);
44 }
45
46 int
47 main (int argc, char *argv[])
48 {
49   int i, j;
50   const char *desc;
51   const char *_name;
52   error_name names_to_sort[400];        /* up to 400 names  */
53
54   printf ("@table @code\n");
55
56   memset (names_to_sort, 0, sizeof (names_to_sort));
57   j = 0;
58   for (i = 0; i > -400; i--)
59     {
60       _name = gnutls_strerror_name (i);
61       if (_name == NULL)
62         continue;
63
64       strcpy (names_to_sort[j].name, _name);
65       names_to_sort[j].error_index = i;
66       j++;
67     }
68
69   qsort (names_to_sort, j, sizeof (error_name), compar);
70
71   for (i = 0; i < j; i++)
72     {
73       _name = names_to_sort[i].name;
74       desc = gnutls_strerror (names_to_sort[i].error_index);
75       if (desc == NULL || _name == NULL)
76         continue;
77
78       printf ("@item %s:\n%s\n\n", _name, desc);
79     }
80
81   printf ("@end table\n");
82
83   return 0;
84 }