vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1 | #ifndef _ASN1FIX_INTERNAL_H_ |
| 2 | #define _ASN1FIX_INTERNAL_H_ |
| 3 | |
vlm | d9cd3f9 | 2004-06-28 21:21:24 +0000 | [diff] [blame] | 4 | #ifdef HAVE_CONFIG_H |
| 5 | #include <config.h> |
| 6 | #endif |
| 7 | |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 8 | /* |
| 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 */ |
| 19 | |
| 20 | /* |
| 21 | * A definition of a function that will log error messages. |
| 22 | */ |
| 23 | typedef void (*error_logger_f)(int _is_fatal, const char *fmt, ...); |
| 24 | |
| 25 | /* |
| 26 | * Universal argument. |
| 27 | */ |
| 28 | typedef struct arg_s { |
| 29 | asn1p_t *asn; |
| 30 | asn1p_module_t *mod; |
| 31 | asn1p_expr_t *expr; |
| 32 | error_logger_f eh; |
| 33 | error_logger_f debug; |
| 34 | void *key; /* The next level key */ |
| 35 | } arg_t; |
| 36 | |
| 37 | /* |
| 38 | * Functions performing normalization of various types. |
| 39 | */ |
| 40 | #include "asn1fix_misc.h" /* Support functions */ |
| 41 | #include "asn1fix_value.h" /* Value processing */ |
| 42 | #include "asn1fix_cstring.h" /* Fix cstring values */ |
| 43 | #include "asn1fix_compat.h" /* Data compatibility */ |
| 44 | #include "asn1fix_constr.h" /* Constructed types */ |
| 45 | #include "asn1fix_class.h" /* CLASS support */ |
| 46 | #include "asn1fix_param.h" /* Parametrization */ |
| 47 | #include "asn1fix_retrieve.h" /* Data retrieval */ |
| 48 | #include "asn1fix_enum.h" /* Process ENUMERATED */ |
| 49 | #include "asn1fix_integer.h" /* Process INTEGER */ |
| 50 | #include "asn1fix_bitstring.h" /* Process BIT STRING */ |
| 51 | #include "asn1fix_dereft.h" /* Dereference types */ |
| 52 | #include "asn1fix_derefv.h" /* Dereference values */ |
| 53 | #include "asn1fix_tags.h" /* Tags-related stuff */ |
| 54 | |
| 55 | |
| 56 | /* |
| 57 | * Merge the return value of the called function with the already |
| 58 | * partially computed return value of the current function. |
| 59 | */ |
| 60 | #define RET2RVAL(ret,rv) do { \ |
| 61 | int __ret = ret; \ |
| 62 | switch(__ret) { \ |
| 63 | case 0: break; \ |
| 64 | case 1: if(rv) break; \ |
| 65 | case -1: rv = __ret; break; \ |
| 66 | default: \ |
| 67 | assert(__ret >= -1 && __ret <= 1); \ |
| 68 | rv = -1; \ |
| 69 | } \ |
| 70 | } while(0) |
| 71 | |
| 72 | /* |
| 73 | * Temporary substitute module for the purposes of evaluating expression. |
| 74 | */ |
| 75 | #define WITH_MODULE(tmp_mod, expr) do { \ |
| 76 | void *_saved_mod = arg->mod; \ |
| 77 | arg->mod = tmp_mod; \ |
| 78 | do { expr; } while(0); \ |
| 79 | arg->mod = _saved_mod; \ |
| 80 | } while(0) |
| 81 | |
| 82 | #define LOG(code, fmt, args...) do { \ |
| 83 | int _save_errno = errno; \ |
| 84 | if(code < 0) { \ |
| 85 | if(arg->debug) \ |
| 86 | arg->debug(code, fmt, ##args); \ |
| 87 | } else { \ |
| 88 | arg->eh(code, fmt " in %s", ##args, \ |
| 89 | arg->mod->source_file_name); \ |
| 90 | } \ |
| 91 | errno = _save_errno; \ |
| 92 | } while(0) |
| 93 | |
| 94 | #define DEBUG(fmt, args...) LOG(-1, fmt, ##args) |
| 95 | #define FATAL(fmt, args...) LOG( 1, fmt, ##args) |
| 96 | #define WARNING(fmt, args...) LOG( 0, fmt, ##args) |
| 97 | |
| 98 | |
| 99 | /* |
| 100 | * Define the symbol corresponding to the name of the current function. |
| 101 | */ |
| 102 | #if __STDC_VERSION__ < 199901 |
| 103 | #if !(__GNUC__ == 2 && __GNUC_MINOR__ >= 7 || __GNUC__ >= 3) |
| 104 | #define __func__ (char *)0 /* Name of the current function */ |
| 105 | #endif /* GNUC */ |
| 106 | /* __func__ is supposed to be defined */ |
| 107 | #endif |
| 108 | |
| 109 | |
| 110 | #endif /* _ASN1FIX_INTERNAL_H_ */ |