Blame src/asn1c/constr_TYPE.c

Packit 728676
/*-
Packit 728676
 * Copyright (c) 2003, 2004 Lev Walkin <vlm@lionet.info>. All rights reserved.
Packit 728676
 * Redistribution and modifications are permitted subject to BSD license.
Packit 728676
 */
Packit 728676
#include <asn_internal.h>
Packit 728676
#include <constr_TYPE.h>
Packit 728676
#include <errno.h>
Packit 728676
Packit 728676
/*
Packit 728676
 * Version of the ASN.1 infrastructure shipped with compiler.
Packit 728676
 */
Packit 728676
int get_asn1c_environment_version() { return ASN1C_ENVIRONMENT_VERSION; }
Packit 728676
Packit 728676
static asn_app_consume_bytes_f _print2fp;
Packit 728676
Packit 728676
/*
Packit 728676
 * Return the outmost tag of the type.
Packit 728676
 */
Packit 728676
ber_tlv_tag_t
Packit 728676
asn_TYPE_outmost_tag(asn_TYPE_descriptor_t *type_descriptor,
Packit 728676
		const void *struct_ptr, int tag_mode, ber_tlv_tag_t tag) {
Packit 728676
Packit 728676
	if(tag_mode)
Packit 728676
		return tag;
Packit 728676
Packit 728676
	if(type_descriptor->tags_count)
Packit 728676
		return type_descriptor->tags[0];
Packit 728676
Packit 728676
	return type_descriptor->outmost_tag(type_descriptor, struct_ptr, 0, 0);
Packit 728676
}
Packit 728676
Packit 728676
/*
Packit 728676
 * Print the target language's structure in human readable form.
Packit 728676
 */
Packit 728676
int
Packit 728676
asn_fprint(FILE *stream, asn_TYPE_descriptor_t *td, const void *struct_ptr) {
Packit 728676
	if(!stream) stream = stdout;
Packit 728676
	if(!td || !struct_ptr) {
Packit 728676
		errno = EINVAL;
Packit 728676
		return -1;
Packit 728676
	}
Packit 728676
Packit 728676
	/* Invoke type-specific printer */
Packit 728676
	if(td->print_struct(td, struct_ptr, 1, _print2fp, stream))
Packit 728676
		return -1;
Packit 728676
Packit 728676
	/* Terminate the output */
Packit 728676
	if(_print2fp("\n", 1, stream))
Packit 728676
		return -1;
Packit 728676
Packit 728676
	return fflush(stream);
Packit 728676
}
Packit 728676
Packit 728676
/* Dump the data into the specified stdio stream */
Packit 728676
static int
Packit 728676
_print2fp(const void *buffer, size_t size, void *app_key) {
Packit 728676
	FILE *stream = (FILE *)app_key;
Packit 728676
Packit 728676
	if(fwrite(buffer, 1, size, stream) != size)
Packit 728676
		return -1;
Packit 728676
Packit 728676
	return 0;
Packit 728676
}
Packit 728676
Packit 728676
Packit 728676
/*
Packit 728676
 * Some compilers do not support variable args macros.
Packit 728676
 * This function is a replacement of ASN_DEBUG() macro.
Packit 728676
 */
Packit 728676
void ASN_DEBUG_f(const char *fmt, ...);
Packit 728676
void ASN_DEBUG_f(const char *fmt, ...) {
Packit 728676
	va_list ap;
Packit 728676
	va_start(ap, fmt);
Packit 728676
	vfprintf(stderr, fmt, ap);
Packit 728676
	fprintf(stderr, "\n");
Packit 728676
	va_end(ap);
Packit 728676
}