Adding initial code jy.oak@samsung.com
[ric-app/kpimon.git] / asn1c_defs / all-defs / constr_TYPE.c
1 /*-\r
2  * Copyright (c) 2003, 2004 Lev Walkin <vlm@lionet.info>. All rights reserved.\r
3  * Redistribution and modifications are permitted subject to BSD license.\r
4  */\r
5 #include <asn_internal.h>\r
6 #include <constr_TYPE.h>\r
7 #include <errno.h>\r
8 \r
9 /*\r
10  * Version of the ASN.1 infrastructure shipped with compiler.\r
11  */\r
12 int get_asn1c_environment_version() { return ASN1C_ENVIRONMENT_VERSION; }\r
13 \r
14 static asn_app_consume_bytes_f _print2fp;\r
15 \r
16 /*\r
17  * Return the outmost tag of the type.\r
18  */\r
19 ber_tlv_tag_t\r
20 asn_TYPE_outmost_tag(const asn_TYPE_descriptor_t *type_descriptor,\r
21                 const void *struct_ptr, int tag_mode, ber_tlv_tag_t tag) {\r
22 \r
23         if(tag_mode)\r
24                 return tag;\r
25 \r
26         if(type_descriptor->tags_count)\r
27                 return type_descriptor->tags[0];\r
28 \r
29         return type_descriptor->op->outmost_tag(type_descriptor, struct_ptr, 0, 0);\r
30 }\r
31 \r
32 /*\r
33  * Print the target language's structure in human readable form.\r
34  */\r
35 int\r
36 asn_fprint(FILE *stream, const asn_TYPE_descriptor_t *td,\r
37            const void *struct_ptr) {\r
38     if(!stream) stream = stdout;\r
39     if(!td || !struct_ptr) {\r
40         errno = EINVAL;\r
41         return -1;\r
42         }\r
43 \r
44         /* Invoke type-specific printer */\r
45     if(td->op->print_struct(td, struct_ptr, 1, _print2fp, stream)) {\r
46         return -1;\r
47     }\r
48 \r
49     /* Terminate the output */\r
50     if(_print2fp("\n", 1, stream)) {\r
51         return -1;\r
52     }\r
53 \r
54     return fflush(stream);\r
55 }\r
56 \r
57 /* Dump the data into the specified stdio stream */\r
58 static int\r
59 _print2fp(const void *buffer, size_t size, void *app_key) {\r
60         FILE *stream = (FILE *)app_key;\r
61 \r
62         if(fwrite(buffer, 1, size, stream) != size)\r
63                 return -1;\r
64 \r
65         return 0;\r
66 }\r
67 \r
68 \r
69 /*\r
70  * Some compilers do not support variable args macros.\r
71  * This function is a replacement of ASN_DEBUG() macro.\r
72  */\r
73 void ASN_DEBUG_f(const char *fmt, ...);\r
74 void ASN_DEBUG_f(const char *fmt, ...) {\r
75         va_list ap;\r
76         va_start(ap, fmt);\r
77         vfprintf(stderr, fmt, ap);\r
78         fprintf(stderr, "\n");\r
79         va_end(ap);\r
80 }\r