Imported Upstream version 3.3.5
[platform/upstream/gnutls.git] / doc / errcodes.c
1 /*
2  * Copyright (C) 2004-2012 Free Software Foundation, Inc.
3  * Author: Nikos Mavrogiannopoulos, Simon Josefsson
4  *
5  * This file is part of GnuTLS.
6  *
7  * GnuTLS is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * GnuTLS is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19  */
20
21 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #endif
24
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
28 #include <gnutls/gnutls.h>
29 #include "common.h"
30
31 static void main_latex(void);
32 static int main_texinfo(void);
33
34 #define MAX_CODES 600
35
36 typedef struct {
37         char name[128];
38         int error_index;
39 } error_name;
40
41
42 static int compar(const void *_n1, const void *_n2)
43 {
44         const error_name *n1 = (const error_name *) _n1,
45             *n2 = (const error_name *) _n2;
46         return strcmp(n1->name, n2->name);
47 }
48
49 static const char headers[] = "\\tablefirsthead{%\n"
50     "\\hline\n"
51     "\\multicolumn{1}{|c}{Code} &\n"
52     "\\multicolumn{1}{c}{Name} &\n"
53     "\\multicolumn{1}{c|}{Description} \\\\\n" "\\hline}\n"
54 #if 0
55     "\\tablehead{%\n"
56     "\\hline\n"
57     "\\multicolumn{3}{|l|}{\\small\\sl continued from previous page}\\\\\n"
58     "\\hline}\n"
59     "\\tabletail{%\n"
60     "\\hline\n"
61     "\\multicolumn{3}{|r|}{\\small\\sl continued on next page}\\\\\n"
62     "\\hline}\n"
63 #endif
64     "\\tablelasttail{\\hline}\n"
65     "\\bottomcaption{The error codes table}\n\n";
66
67 int main(int argc, char *argv[])
68 {
69         if (argc > 1)
70                 main_latex();
71         else
72                 main_texinfo();
73
74         return 0;
75 }
76
77 static int main_texinfo(void)
78 {
79         int i, j;
80         const char *desc;
81         const char *_name;
82         char buffer[500];
83         error_name names_to_sort[MAX_CODES];    /* up to MAX_CODES names  */
84
85         printf("@multitable @columnfractions .15 .40 .37\n");
86
87         memset(names_to_sort, 0, sizeof(names_to_sort));
88         j = 0;
89         for (i = 0; i > -MAX_CODES; i--) {
90                 _name = gnutls_strerror_name(i);
91                 if (_name == NULL)
92                         continue;
93
94                 desc = gnutls_strerror(i);
95
96                 printf("@item %d @tab %s @tab %s\n", i,
97                        escape_texi_string(_name, buffer, sizeof(buffer)),
98                        desc);
99
100                 strcpy(names_to_sort[j].name, _name);
101                 names_to_sort[j].error_index = i;
102                 j++;
103         }
104
105         printf("@end multitable\n");
106
107         return 0;
108 }
109
110 static void main_latex(void)
111 {
112         int i, j;
113         static char buffer1[500];
114         static char buffer2[500];
115         const char *desc;
116         const char *_name;
117         error_name names_to_sort[MAX_CODES];    /* up to MAX_CODES names  */
118
119         puts(headers);
120
121         printf
122             ("\\begin{supertabular}{|p{.05\\linewidth}|p{.40\\linewidth}|p{.45\\linewidth}|}\n");
123
124         memset(names_to_sort, 0, sizeof(names_to_sort));
125         j = 0;
126         for (i = 0; i > -MAX_CODES; i--) {
127                 _name = gnutls_strerror_name(i);
128                 if (_name == NULL)
129                         continue;
130
131                 strcpy(names_to_sort[j].name, _name);
132                 names_to_sort[j].error_index = i;
133                 j++;
134         }
135
136 //qsort( names_to_sort, j, sizeof(error_name), compar);
137
138         for (i = 0; i < j; i++) {
139                 _name = names_to_sort[i].name;
140                 desc = gnutls_strerror(names_to_sort[i].error_index);
141                 if (desc == NULL || _name == NULL)
142                         continue;
143
144                 printf("%d & {\\scriptsize{%s}} & %s",
145                        names_to_sort[i].error_index, escape_string(_name,
146                                                                    buffer1,
147                                                                    sizeof
148                                                                    (buffer1)),
149                        escape_string(desc, buffer2, sizeof(buffer2)));
150                 printf("\\\\\n");
151         }
152
153         printf("\\end{supertabular}\n\n");
154
155         return;
156
157 }