vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1 | /*- |
| 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 | |
| 8 | static asn_app_consume_bytes_f _print2fp; |
| 9 | |
| 10 | /* |
| 11 | * Return the outmost tag of the type. |
| 12 | */ |
| 13 | ber_tlv_tag_t |
| 14 | asn1_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 | */ |
| 29 | int |
| 30 | asn_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 */ |
| 49 | static int |
| 50 | _print2fp(const void *buffer, size_t size, void *app_key) { |
vlm | da67468 | 2004-08-11 09:07:36 +0000 | [diff] [blame] | 51 | FILE *stream = (FILE *)app_key; |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 52 | |
| 53 | if(fwrite(buffer, 1, size, stream) != size) |
| 54 | return -1; |
| 55 | |
| 56 | return 0; |
| 57 | } |
| 58 | |
vlm | f5202a5 | 2004-08-11 08:32:04 +0000 | [diff] [blame] | 59 | |
| 60 | /* |
| 61 | * Some compilers do not support variable args macros. |
| 62 | * This function is a replacement of ASN_DEBUG() macro. |
| 63 | */ |
| 64 | void ASN_DEBUG_f(const char *fmt, ...) { |
| 65 | va_list ap; |
| 66 | va_start(ap, fmt); |
| 67 | vfprintf(stderr, fmt, ap); |
| 68 | fprintf(stderr, "\n"); |
| 69 | va_end(ap); |
| 70 | } |