summaryrefslogtreecommitdiff
path: root/doc/errcodes.c
blob: f0d2d6e94e6d8a6ce33971139cf1bf4e4ec4b291 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/*
 * Copyright (C) 2004-2012 Free Software Foundation, Inc.
 * Author: Nikos Mavrogiannopoulos, Simon Josefsson
 *
 * This file is part of GnuTLS.
 *
 * GnuTLS is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * GnuTLS is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <gnutls/gnutls.h>

static void main_latex(void);
static int main_texinfo (void);

#define MAX_CODES 600

typedef struct
{
  char name[128];
  int error_index;
} error_name;


static int
compar (const void *_n1, const void *_n2)
{
  const error_name *n1 = (const error_name *) _n1,
    *n2 = (const error_name *) _n2;
  return strcmp (n1->name, n2->name);
}

static const char headers[] = "\\tablefirsthead{%\n"
	"\\hline\n"
	"\\multicolumn{1}{|c}{Code} &\n"
	"\\multicolumn{1}{c}{Name} &\n"
	"\\multicolumn{1}{c|}{Description} \\\\\n"
	"\\hline}\n"
#if 0
	"\\tablehead{%\n"
	"\\hline\n"
	"\\multicolumn{3}{|l|}{\\small\\sl continued from previous page}\\\\\n"
	"\\hline}\n"
	"\\tabletail{%\n"
	"\\hline\n"
	"\\multicolumn{3}{|r|}{\\small\\sl continued on next page}\\\\\n"
	"\\hline}\n"
#endif
	"\\tablelasttail{\\hline}\n"
	"\\bottomcaption{The error codes table}\n\n";

int
main (int argc, char *argv[])
{
  if (argc > 1)
    main_latex();
  else
    main_texinfo();
    
  return 0;
}

static char* escape_texi_string( const char* str, char* buffer, int buffer_size)
{
int i = 0, j = 0;


while( str[i] != 0 && j <buffer_size - 1) {
   if (str[i]=='_') {
      buffer[j++] = '_';
      buffer[j++] = '@';
      buffer[j++] = '-';
   } else {
      buffer[j++] = str[i];
   }
   i++;
};

buffer[j] = 0;

return buffer;

}

static int main_texinfo (void)
{
  int i, j;
  const char *desc;
  const char *_name;
  char buffer[500];
  error_name names_to_sort[MAX_CODES];        /* up to MAX_CODES names  */

  printf ("@multitable @columnfractions .15 .40 .37\n");

  memset (names_to_sort, 0, sizeof (names_to_sort));
  j = 0;
  for (i = 0; i > -MAX_CODES; i--)
    {
      _name = gnutls_strerror_name (i);
      if (_name == NULL)
        continue;

      desc = gnutls_strerror (i);

      printf ("@item %d @tab %s @tab %s\n", i, escape_texi_string(_name, buffer,sizeof(buffer)), desc);

      strcpy (names_to_sort[j].name, _name);
      names_to_sort[j].error_index = i;
      j++;
    }

  printf ("@end multitable\n");

  return 0;
}

static char* escape_string( const char* str, char* buffer, int buffer_size)
{
int i = 0, j = 0;


while( str[i] != 0 && j <buffer_size - 1) {
   if (str[i]=='_') {
      buffer[j++] = '\\';
      buffer[j++] = '_';
      buffer[j++] = '\\';
      buffer[j++] = '-';
   } else if (str[i]=='#') {
      buffer[j++] = '\\';
      buffer[j++] = '#';
   } else {
      buffer[j++] = str[i];
   }
   i++;
};

buffer[j] = 0;

return buffer;

}

static void main_latex(void)
{
int i, j;
static char buffer1[500];
static char buffer2[500];
const char* desc;
const char* _name;
error_name names_to_sort[MAX_CODES]; /* up to MAX_CODES names  */

puts( headers);

printf("\\begin{supertabular}{|p{.05\\linewidth}|p{.40\\linewidth}|p{.45\\linewidth}|}\n");

memset( names_to_sort, 0, sizeof(names_to_sort));
j=0;
for (i=0;i>-MAX_CODES;i--)
{
   _name = gnutls_strerror_name(i);
   if ( _name == NULL) continue;

   strcpy( names_to_sort[j].name, _name);
   names_to_sort[j].error_index = i;
   j++;
}

//qsort( names_to_sort, j, sizeof(error_name), compar);

for (i=0;i<j;i++)
{
   _name = names_to_sort[i].name;
   desc = gnutls_strerror( names_to_sort[i].error_index);
   if (desc == NULL || _name == NULL) continue;

   printf( "%d & {\\scriptsize{%s}} & %s", names_to_sort[i].error_index, escape_string(_name, buffer1, sizeof(buffer1)), escape_string(desc, buffer2, sizeof(buffer2)));
   printf( "\\\\\n");
}

printf("\\end{supertabular}\n\n");

return;

}