released 3.1.2
[gnutls.git] / doc / errcodes.c
blob93f3a63a25876cd441fe9af5383f4446c008da96
1 /*
2 * Copyright (C) 2004-2012 Free Software Foundation, Inc.
3 * Author: Nikos Mavrogiannopoulos, Simon Josefsson
5 * This file is part of GnuTLS.
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.
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.
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/>.
21 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #endif
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
28 #include <gnutls/gnutls.h>
29 #include "common.h"
31 static void main_latex(void);
32 static int main_texinfo (void);
34 #define MAX_CODES 600
36 typedef struct
38 char name[128];
39 int error_index;
40 } error_name;
43 static int
44 compar (const void *_n1, const void *_n2)
46 const error_name *n1 = (const error_name *) _n1,
47 *n2 = (const error_name *) _n2;
48 return strcmp (n1->name, n2->name);
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";
70 int
71 main (int argc, char *argv[])
73 if (argc > 1)
74 main_latex();
75 else
76 main_texinfo();
78 return 0;
81 static int main_texinfo (void)
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 */
89 printf ("@multitable @columnfractions .15 .40 .37\n");
91 memset (names_to_sort, 0, sizeof (names_to_sort));
92 j = 0;
93 for (i = 0; i > -MAX_CODES; i--)
95 _name = gnutls_strerror_name (i);
96 if (_name == NULL)
97 continue;
99 desc = gnutls_strerror (i);
101 printf ("@item %d @tab %s @tab %s\n", i, escape_texi_string(_name, buffer,sizeof(buffer)), desc);
103 strcpy (names_to_sort[j].name, _name);
104 names_to_sort[j].error_index = i;
105 j++;
108 printf ("@end multitable\n");
110 return 0;
113 static void main_latex(void)
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 */
122 puts( headers);
124 printf("\\begin{supertabular}{|p{.05\\linewidth}|p{.40\\linewidth}|p{.45\\linewidth}|}\n");
126 memset( names_to_sort, 0, sizeof(names_to_sort));
127 j=0;
128 for (i=0;i>-MAX_CODES;i--)
130 _name = gnutls_strerror_name(i);
131 if ( _name == NULL) continue;
133 strcpy( names_to_sort[j].name, _name);
134 names_to_sort[j].error_index = i;
135 j++;
138 //qsort( names_to_sort, j, sizeof(error_name), compar);
140 for (i=0;i<j;i++)
142 _name = names_to_sort[i].name;
143 desc = gnutls_strerror( names_to_sort[i].error_index);
144 if (desc == NULL || _name == NULL) continue;
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");
150 printf("\\end{supertabular}\n\n");
152 return;