Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1 | #ifndef _ASN1FIX_INTERNAL_H_ |
| 2 | #define _ASN1FIX_INTERNAL_H_ |
| 3 | |
Lev Walkin | 97bdee2 | 2004-06-28 21:21:24 +0000 | [diff] [blame] | 4 | #ifdef HAVE_CONFIG_H |
| 5 | #include <config.h> |
| 6 | #endif |
| 7 | |
Lev Walkin | f15320b | 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> |
Lev Walkin | 4efbfb7 | 2005-02-25 14:20:30 +0000 | [diff] [blame] | 13 | #include <stdarg.h> |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 14 | #include <string.h> |
| 15 | #include <ctype.h> /* isupper() */ |
| 16 | #include <errno.h> |
| 17 | #include <assert.h> |
| 18 | |
Lev Walkin | 4efbfb7 | 2005-02-25 14:20:30 +0000 | [diff] [blame] | 19 | #ifdef HAVE_UNISTD_H |
| 20 | #include <unistd.h> |
| 21 | #endif |
| 22 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 23 | #include <asn1parser.h> /* Our lovely ASN.1 parser module */ |
Lev Walkin | 4efbfb7 | 2005-02-25 14:20:30 +0000 | [diff] [blame] | 24 | #include "asn1fix.h" |
| 25 | |
| 26 | #ifdef WIN32 |
| 27 | #define EX_NOINPUT 66 |
| 28 | #define EX_DATAERR 65 |
| 29 | #define snprintf _snprintf |
| 30 | #define strcasecmp stricmp |
| 31 | #endif |
| 32 | |
| 33 | #ifndef ETOOMANYREFS |
| 34 | #define ETOOMANYREFS 144 |
| 35 | #endif |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 36 | |
| 37 | /* |
| 38 | * A definition of a function that will log error messages. |
| 39 | */ |
| 40 | typedef void (*error_logger_f)(int _is_fatal, const char *fmt, ...); |
| 41 | |
| 42 | /* |
| 43 | * Universal argument. |
| 44 | */ |
| 45 | typedef struct arg_s { |
| 46 | asn1p_t *asn; |
| 47 | asn1p_module_t *mod; |
| 48 | asn1p_expr_t *expr; |
| 49 | error_logger_f eh; |
| 50 | error_logger_f debug; |
| 51 | void *key; /* The next level key */ |
Lev Walkin | b45e067 | 2004-08-18 05:42:05 +0000 | [diff] [blame] | 52 | enum asn1f_flags flags; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 53 | } arg_t; |
| 54 | |
| 55 | /* |
| 56 | * Functions performing normalization of various types. |
| 57 | */ |
| 58 | #include "asn1fix_misc.h" /* Support functions */ |
| 59 | #include "asn1fix_value.h" /* Value processing */ |
| 60 | #include "asn1fix_cstring.h" /* Fix cstring values */ |
| 61 | #include "asn1fix_compat.h" /* Data compatibility */ |
| 62 | #include "asn1fix_constr.h" /* Constructed types */ |
| 63 | #include "asn1fix_class.h" /* CLASS support */ |
| 64 | #include "asn1fix_param.h" /* Parametrization */ |
| 65 | #include "asn1fix_retrieve.h" /* Data retrieval */ |
| 66 | #include "asn1fix_enum.h" /* Process ENUMERATED */ |
| 67 | #include "asn1fix_integer.h" /* Process INTEGER */ |
| 68 | #include "asn1fix_bitstring.h" /* Process BIT STRING */ |
| 69 | #include "asn1fix_dereft.h" /* Dereference types */ |
| 70 | #include "asn1fix_derefv.h" /* Dereference values */ |
| 71 | #include "asn1fix_tags.h" /* Tags-related stuff */ |
Lev Walkin | b45e067 | 2004-08-18 05:42:05 +0000 | [diff] [blame] | 72 | #include "asn1fix_constraint.h" /* Constraint manipulation */ |
| 73 | #include "asn1fix_crange.h" /* Constraint groking, exportable */ |
| 74 | #include "asn1fix_export.h" /* Exported functions */ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 75 | |
| 76 | |
| 77 | /* |
| 78 | * Merge the return value of the called function with the already |
| 79 | * partially computed return value of the current function. |
| 80 | */ |
| 81 | #define RET2RVAL(ret,rv) do { \ |
| 82 | int __ret = ret; \ |
| 83 | switch(__ret) { \ |
| 84 | case 0: break; \ |
| 85 | case 1: if(rv) break; \ |
| 86 | case -1: rv = __ret; break; \ |
| 87 | default: \ |
| 88 | assert(__ret >= -1 && __ret <= 1); \ |
| 89 | rv = -1; \ |
| 90 | } \ |
| 91 | } while(0) |
| 92 | |
| 93 | /* |
| 94 | * Temporary substitute module for the purposes of evaluating expression. |
| 95 | */ |
| 96 | #define WITH_MODULE(tmp_mod, expr) do { \ |
| 97 | void *_saved_mod = arg->mod; \ |
| 98 | arg->mod = tmp_mod; \ |
| 99 | do { expr; } while(0); \ |
| 100 | arg->mod = _saved_mod; \ |
| 101 | } while(0) |
| 102 | |
| 103 | #define LOG(code, fmt, args...) do { \ |
| 104 | int _save_errno = errno; \ |
| 105 | if(code < 0) { \ |
| 106 | if(arg->debug) \ |
Lev Walkin | 0385018 | 2005-03-10 10:02:50 +0000 | [diff] [blame] | 107 | arg->debug(code, \ |
| 108 | "%s: " fmt " in %s (%s:%d)", \ |
| 109 | __func__, ##args, \ |
Lev Walkin | 4d89c26 | 2005-03-10 09:36:03 +0000 | [diff] [blame] | 110 | arg->mod->source_file_name, \ |
| 111 | __FILE__, __LINE__); \ |
Lev Walkin | 906654e | 2004-09-10 15:49:15 +0000 | [diff] [blame] | 112 | } else if(arg->eh) { \ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 113 | arg->eh(code, fmt " in %s", ##args, \ |
| 114 | arg->mod->source_file_name); \ |
| 115 | } \ |
| 116 | errno = _save_errno; \ |
| 117 | } while(0) |
| 118 | |
| 119 | #define DEBUG(fmt, args...) LOG(-1, fmt, ##args) |
| 120 | #define FATAL(fmt, args...) LOG( 1, fmt, ##args) |
| 121 | #define WARNING(fmt, args...) LOG( 0, fmt, ##args) |
| 122 | |
| 123 | |
| 124 | /* |
| 125 | * Define the symbol corresponding to the name of the current function. |
| 126 | */ |
| 127 | #if __STDC_VERSION__ < 199901 |
| 128 | #if !(__GNUC__ == 2 && __GNUC_MINOR__ >= 7 || __GNUC__ >= 3) |
| 129 | #define __func__ (char *)0 /* Name of the current function */ |
| 130 | #endif /* GNUC */ |
| 131 | /* __func__ is supposed to be defined */ |
| 132 | #endif |
| 133 | |
| 134 | |
| 135 | #endif /* _ASN1FIX_INTERNAL_H_ */ |