blob: 68cc50fa842bb014ae3003786946e37fef464f3e [file] [log] [blame]
vlmfa67ddc2004-06-03 03:38:44 +00001/*-
2 * Copyright (c) 2003, 2004 Lev Walkin <vlm@lionet.info>. All rights reserved.
3 * Redistribution and modifications are permitted subject to BSD license.
4 */
5#include <constr_TYPE.h>
6#include <errno.h>
7
8static asn_app_consume_bytes_f _print2fp;
9
10/*
11 * Return the outmost tag of the type.
12 */
13ber_tlv_tag_t
14asn1_TYPE_outmost_tag(asn1_TYPE_descriptor_t *type_descriptor,
15 const void *struct_ptr, int tag_mode, ber_tlv_tag_t tag) {
16
17 if(tag_mode)
18 return tag;
19
20 if(type_descriptor->tags_count)
21 return type_descriptor->tags[0];
22
23 return type_descriptor->outmost_tag(type_descriptor, struct_ptr, 0, 0);
24}
25
26/*
27 * Print the target language's structure in human readable form.
28 */
29int
30asn_fprint(FILE *stream, asn1_TYPE_descriptor_t *td, const void *struct_ptr) {
31 if(!stream) stream = stdout;
32 if(!td || !struct_ptr) {
33 errno = EINVAL;
34 return -1;
35 }
36
37 /* Invoke type-specific printer */
38 if(td->print_struct(td, struct_ptr, 4, _print2fp, stream))
39 return -1;
40
41 /* Terminate the output */
42 if(_print2fp("\n", 1, stream))
43 return -1;
44
45 return fflush(stream);
46}
47
48/* Dump the data into the specified stdio stream */
49static int
50_print2fp(const void *buffer, size_t size, void *app_key) {
vlmda674682004-08-11 09:07:36 +000051 FILE *stream = (FILE *)app_key;
vlmfa67ddc2004-06-03 03:38:44 +000052
53 if(fwrite(buffer, 1, size, stream) != size)
54 return -1;
55
56 return 0;
57}
58
vlmf5202a52004-08-11 08:32:04 +000059
60/*
61 * Some compilers do not support variable args macros.
62 * This function is a replacement of ASN_DEBUG() macro.
63 */
vlmcd8575c2004-08-11 11:51:15 +000064void ASN_DEBUG_f(const char *fmt, ...);
vlmf5202a52004-08-11 08:32:04 +000065void ASN_DEBUG_f(const char *fmt, ...) {
66 va_list ap;
67 va_start(ap, fmt);
68 vfprintf(stderr, fmt, ap);
69 fprintf(stderr, "\n");
70 va_end(ap);
71}