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