blob: 040750df5f30e9cea944564dc12c1eb7cd326072 [file] [log] [blame]
Lev Walkinf15320b2004-06-03 03:38:44 +00001#ifndef _ASN1FIX_INTERNAL_H_
2#define _ASN1FIX_INTERNAL_H_
3
Lev Walkin97bdee22004-06-28 21:21:24 +00004#ifdef HAVE_CONFIG_H
5#include <config.h>
6#endif
7
Lev Walkinf15320b2004-06-03 03:38:44 +00008/*
9 * System headers required in various modules.
10 */
11#include <stdio.h>
12#include <stdlib.h>
13#include <string.h>
14#include <ctype.h> /* isupper() */
15#include <errno.h>
16#include <assert.h>
17
18#include <asn1parser.h> /* Our lovely ASN.1 parser module */
Lev Walkinb45e0672004-08-18 05:42:05 +000019#include <asn1fix.h>
Lev Walkinf15320b2004-06-03 03:38:44 +000020
21/*
22 * A definition of a function that will log error messages.
23 */
24typedef void (*error_logger_f)(int _is_fatal, const char *fmt, ...);
25
26/*
27 * Universal argument.
28 */
29typedef struct arg_s {
30 asn1p_t *asn;
31 asn1p_module_t *mod;
32 asn1p_expr_t *expr;
33 error_logger_f eh;
34 error_logger_f debug;
35 void *key; /* The next level key */
Lev Walkinb45e0672004-08-18 05:42:05 +000036 enum asn1f_flags flags;
Lev Walkinf15320b2004-06-03 03:38:44 +000037} arg_t;
38
39/*
40 * Functions performing normalization of various types.
41 */
42#include "asn1fix_misc.h" /* Support functions */
43#include "asn1fix_value.h" /* Value processing */
44#include "asn1fix_cstring.h" /* Fix cstring values */
45#include "asn1fix_compat.h" /* Data compatibility */
46#include "asn1fix_constr.h" /* Constructed types */
47#include "asn1fix_class.h" /* CLASS support */
48#include "asn1fix_param.h" /* Parametrization */
49#include "asn1fix_retrieve.h" /* Data retrieval */
50#include "asn1fix_enum.h" /* Process ENUMERATED */
51#include "asn1fix_integer.h" /* Process INTEGER */
52#include "asn1fix_bitstring.h" /* Process BIT STRING */
53#include "asn1fix_dereft.h" /* Dereference types */
54#include "asn1fix_derefv.h" /* Dereference values */
55#include "asn1fix_tags.h" /* Tags-related stuff */
Lev Walkinb45e0672004-08-18 05:42:05 +000056#include "asn1fix_constraint.h" /* Constraint manipulation */
57#include "asn1fix_crange.h" /* Constraint groking, exportable */
58#include "asn1fix_export.h" /* Exported functions */
Lev Walkinf15320b2004-06-03 03:38:44 +000059
60
61/*
62 * Merge the return value of the called function with the already
63 * partially computed return value of the current function.
64 */
65#define RET2RVAL(ret,rv) do { \
66 int __ret = ret; \
67 switch(__ret) { \
68 case 0: break; \
69 case 1: if(rv) break; \
70 case -1: rv = __ret; break; \
71 default: \
72 assert(__ret >= -1 && __ret <= 1); \
73 rv = -1; \
74 } \
75 } while(0)
76
77/*
78 * Temporary substitute module for the purposes of evaluating expression.
79 */
80#define WITH_MODULE(tmp_mod, expr) do { \
81 void *_saved_mod = arg->mod; \
82 arg->mod = tmp_mod; \
83 do { expr; } while(0); \
84 arg->mod = _saved_mod; \
85 } while(0)
86
87#define LOG(code, fmt, args...) do { \
88 int _save_errno = errno; \
89 if(code < 0) { \
90 if(arg->debug) \
91 arg->debug(code, fmt, ##args); \
Lev Walkin906654e2004-09-10 15:49:15 +000092 } else if(arg->eh) { \
Lev Walkinf15320b2004-06-03 03:38:44 +000093 arg->eh(code, fmt " in %s", ##args, \
94 arg->mod->source_file_name); \
95 } \
96 errno = _save_errno; \
97 } while(0)
98
99#define DEBUG(fmt, args...) LOG(-1, fmt, ##args)
100#define FATAL(fmt, args...) LOG( 1, fmt, ##args)
101#define WARNING(fmt, args...) LOG( 0, fmt, ##args)
102
103
104/*
105 * Define the symbol corresponding to the name of the current function.
106 */
107#if __STDC_VERSION__ < 199901
108#if !(__GNUC__ == 2 && __GNUC_MINOR__ >= 7 || __GNUC__ >= 3)
109#define __func__ (char *)0 /* Name of the current function */
110#endif /* GNUC */
111/* __func__ is supposed to be defined */
112#endif
113
114
115#endif /* _ASN1FIX_INTERNAL_H_ */