Imported Upstream version 3.0.30
[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 {
38   char name[128];
39   int error_index;
40 } error_name;
41
42
43 static int
44 compar (const void *_n1, const void *_n2)
45 {
46   const error_name *n1 = (const error_name *) _n1,
47     *n2 = (const error_name *) _n2;
48   return strcmp (n1->name, n2->name);
49 }
50
51 static const char headers[] = "\\tablefirsthead{%\n"
52         "\\hline\n"
53         "\\multicolumn{1}{|c}{Code} &\n"
54         "\\multicolumn{1}{c}{Name} &\n"
55         "\\multicolumn{1}{c|}{Description} \\\\\n"
56         "\\hline}\n"
57 #if 0
58         "\\tablehead{%\n"
59         "\\hline\n"
60         "\\multicolumn{3}{|l|}{\\small\\sl continued from previous page}\\\\\n"
61         "\\hline}\n"
62         "\\tabletail{%\n"
63         "\\hline\n"
64         "\\multicolumn{3}{|r|}{\\small\\sl continued on next page}\\\\\n"
65         "\\hline}\n"
66 #endif
67         "\\tablelasttail{\\hline}\n"
68         "\\bottomcaption{The error codes table}\n\n";
69
70 int
71 main (int argc, char *argv[])
72 {
73   if (argc > 1)
74     main_latex();
75   else
76     main_texinfo();
77     
78   return 0;
79 }
80
81 static int main_texinfo (void)
82 {
83   int i, j;
84   const char *desc;
85   const char *_name;
86   char buffer[500];
87   error_name names_to_sort[MAX_CODES];        /* up to MAX_CODES names  */
88
89   printf ("@multitable @columnfractions .15 .40 .37\n");
90
91   memset (names_to_sort, 0, sizeof (names_to_sort));
92   j = 0;
93   for (i = 0; i > -MAX_CODES; i--)
94     {
95       _name = gnutls_strerror_name (i);
96       if (_name == NULL)
97         continue;
98
99       desc = gnutls_strerror (i);
100
101       printf ("@item %d @tab %s @tab %s\n", i, escape_texi_string(_name, buffer,sizeof(buffer)), desc);
102
103       strcpy (names_to_sort[j].name, _name);
104       names_to_sort[j].error_index = i;
105       j++;
106     }
107
108   printf ("@end multitable\n");
109
110   return 0;
111 }
112
113 static void main_latex(void)
114 {
115 int i, j;
116 static char buffer1[500];
117 static char buffer2[500];
118 const char* desc;
119 const char* _name;
120 error_name names_to_sort[MAX_CODES]; /* up to MAX_CODES names  */
121
122 puts( headers);
123
124 printf("\\begin{supertabular}{|p{.05\\linewidth}|p{.40\\linewidth}|p{.45\\linewidth}|}\n");
125
126 memset( names_to_sort, 0, sizeof(names_to_sort));
127 j=0;
128 for (i=0;i>-MAX_CODES;i--)
129 {
130    _name = gnutls_strerror_name(i);
131    if ( _name == NULL) continue;
132
133    strcpy( names_to_sort[j].name, _name);
134    names_to_sort[j].error_index = i;
135    j++;
136 }
137
138 //qsort( names_to_sort, j, sizeof(error_name), compar);
139
140 for (i=0;i<j;i++)
141 {
142    _name = names_to_sort[i].name;
143    desc = gnutls_strerror( names_to_sort[i].error_index);
144    if (desc == NULL || _name == NULL) continue;
145
146    printf( "%d & {\\scriptsize{%s}} & %s", names_to_sort[i].error_index, escape_string(_name, buffer1, sizeof(buffer1)), escape_string(desc, buffer2, sizeof(buffer2)));
147    printf( "\\\\\n");
148 }
149
150 printf("\\end{supertabular}\n\n");
151
152 return;
153
154 }