29 #define PGMNAME "asn1-gentables"
31 #if (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 5 ))
32 # define ATTR_PRINTF(a,b) __attribute__ ((format (printf,a,b)))
34 # define ATTR_PRINTF(a,b)
38 #define DEVNULL_NAME "nul"
40 #define DEVNULL_NAME "/dev/null"
68 va_start (arg_ptr, fmt);
70 vfprintf (stderr, fmt, arg_ptr);
93 for (n=0; item->
name[n]; n++)
96 off += strlen (item->
name) + 1;
112 const char *a = (*(
const struct name_list_s **)aptr)->name;
113 const char *b = (*(
const struct name_list_s **)bptr)->name;
115 const size_t len_a = strlen(a);
116 const size_t len_b = strlen(b);
137 array =
xcalloc (arraylen,
sizeof *array);
139 array[arraylen++] = item;
140 qsort (array, arraylen,
sizeof *array,
cmp_string);
145 for (i=0; i < arraylen; i++)
164 fputs (
"static const char string_table[] = {\n ", fp);
167 for (s=item->
name, pos=0; *s; s++)
170 fprintf (fp,
"%s ", pos>1?
"\n":
"");
171 fprintf (fp,
"'%c',", *s);
173 fputs (
"'\\0',\n", fp);
177 fprintf (fp,
" '\\0' };\n/* (%d strings) */\n", count);
186 const char *char_p, *slash_p, *dot_p;
191 while ((char_p = strchr (char_p,
'/')))
198 dot_p = file_name + strlen (file_name);
200 while ((char_p = strchr (char_p,
'.')))
206 structure_name =
xmalloc (
sizeof *structure_name + dot_p - slash_p + 100);
207 structure_name->
next = NULL;
208 memcpy (structure_name->
name, slash_p, dot_p - slash_p);
209 structure_name->
name[dot_p - slash_p] = 0;
211 fprintf (fp,
"static const static_asn %s_asn1_tab[] = {\n",
212 structure_name->
name);
226 fprintf (fp,
",%u", p->
type);
260 snprintf (numbuf,
sizeof numbuf,
"%ld", p->
value.
v_long);
265 snprintf (numbuf,
sizeof numbuf,
"%lu", p->
value.
v_ulong);
277 fprintf (fp,
" {0,0}\n};\n");
279 return structure_name;
301 "#include <config.h>\n"
302 "#include <stdio.h>\n"
303 "#include <string.h>\n"
304 "#include \"ksba.h\"\n"
305 "#include \"asn1-func.h\"\n"
322 if (!argc || (argc > 1 &&
323 (!strcmp (argv[1],
"--help") || !strcmp (argv[1],
"-h"))) )
325 fputs (
"usage: asn1-gentables [--check] [--dump[-expanded]] [files.asn]\n",
331 if (argc && !strcmp (*argv,
"--check"))
336 else if (argc && !strcmp (*argv,
"--dump"))
341 else if (argc && !strcmp (*argv,
"--dump-expanded"))
349 all_names =
one_file (
"-", &count, stdout);
361 for (i=0; i < argc; i++)
368 for (; argc; argc--, argv++)
370 nl =
one_file (*argv, &count, stdout);
373 nl->next = all_names;
385 printf (
"\n\nconst static_asn *\n"
386 "_ksba_asn_lookup_table (const char *name,"
387 " const char **stringtbl)\n"
389 " *stringtbl = string_table;\n"
391 for (nl=all_names; nl; nl = nl->
next)
392 printf (
" if (!strcmp (name, \"%s\"))\n"
393 " return %s_asn1_tab;\n", nl->name, nl->name);
394 printf (
"\n return NULL;\n}\n");
AsnNode _ksba_asn_walk_tree(AsnNode root, AsnNode node)
int main(int argc, char **argv)
static void write_string_table(FILE *fp)
static struct name_list_s * string_table
static struct name_list_s * create_static_structure(AsnNode pointer, const char *file_name, FILE *fp)
static void sort_string_table(void)
static int cmp_string(const void *aptr, const void *bptr)
static struct name_list_s ** string_table_tail
#define ATTR_PRINTF(a, b)
static size_t string_table_offset
static size_t insert_string(const char *name)
static struct name_list_s * one_file(const char *fname, int *count, FILE *fp)
static void print_error(const char *fmt,...)
const char * gpg_strerror(int err)
enum asn_value_type valuetype
struct name_list_s * next
#define ksba_asn_tree_dump
#define ksba_asn_parse_file