1 /********************************************************************* 2 Copyright 2008, 2010 Sandia Corporation. Under the terms of Contract 3 DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government 4 retains certain rights in this software. 5 6 Redistribution and use in source and binary forms, with or without 7 modification, are permitted provided that the following conditions 8 are met: 9 10 * Redistributions of source code must retain the above copyright 11 notice, this list of conditions and the following disclaimer. 12 13 * Redistributions in binary form must reproduce the above copyright 14 notice, this list of conditions and the following disclaimer in the 15 documentation and/or other materials provided with the distribution. 16 17 * Neither the name of Sandia Corporation nor the names of its 18 contributors may be used to endorse or promote products derived from 19 this software without specific prior written permission. 20 21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 25 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 27 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 31 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 ***********************************************************************/ 33 34 /* nidr.h */ 35 36 #ifndef NIDR_H 37 #define NIDR_H 38 39 #include <stddef.h> /* for size_t; for pure C++, change to <cstddef> */ 40 typedef struct KeyWord KeyWord; /* for C compilation */ 41 typedef struct Values Values; /* for C compilation */ 42 43 typedef unsigned int Uint; 44 45 #ifdef NO_DOUBLE 46 typedef float Real; 47 #else 48 typedef double Real; 49 #endif 50 51 struct Values { 52 size_t n; /* for n = 0, pass (Values*)0 to the func. */ 53 Real *r; 54 int *i; 55 const char **s; 56 int rstate; /* for handling n*value and L:U and L:step:U */ 57 }; 58 59 typedef void (*Kwfunc)(const char *keyname, Values *val, void **g, void *v); 60 61 enum KeyWordKind { 62 KWKind_Void = 0, /* no associated value */ 63 KWKind_Int = 1, /* INTEGER */ 64 KWKind_Real = 2, /* REAL */ 65 KWKind_Str = 3, /* STRING */ 66 KWKind_Mask = 3, /* for use with (kind & KWKind_Mask) */ 67 /* The following may be or-ed into one of the above */ 68 KWKind_List = 4, /* INTEGERLIST, REALLIST, or STRINGLIST (not for KWKind_Void) */ 69 KWKind_primary = 0x08, /* primary in its group of aliases */ 70 KWKind_strictLb = 0x10, /* > value specified */ 71 KWKind_caneqLb = 0x20, /* >= value specified */ 72 KWKind_Lb = 0x30, /* Lb mask: > or >= specified */ 73 KWKind_strictUb = 0x40, /* < value specified */ 74 KWKind_caneqUb = 0x80, /* <= value specified */ 75 KWKind_Ub = 0xc0, /* Ub mask: < or <= specified */ 76 KWKind_01 = 0x100, /* a top-level keyword that can appear at most once */ 77 KWKind_1 = 0x200, /* a top-level keyword that must appear exactly once */ 78 KWKind_12 = 0x300, /* a top-level keyword that must appear at least once */ 79 KWtopshift = 8, 80 KWKind_init = 0x400, /* has := value */ 81 KWKind_Len1OK = 0x800, /* list of values can be one long */ 82 KWKind_Stacked = 0x1000, /* internal use (by nidrgen) */ 83 KWKind_Hashed = 0x2000, /* internal use */ 84 KWKind_Dynlib = 0x4000, /* The final value is NULL and the vf field names a */ 85 /* shared library that provides contained keywords */ 86 /* and any needed start and final routines. */ 87 KWKind_Loaded = 0x8000, /* We've loaded the library; vs points to the */ 88 /* substituted KeyWord. */ 89 KWKind_Dynmult = 0x10000, /* Library contains several keywords */ 90 KWKind_Extended = 0x20000, /* Library version of KeyWord: KeyWord */ 91 /* followed by extra GuiKeyWord fields */ 92 KWKind_Libname = 0x40000 /* LIBNAME specified: a string value in the */ 93 /* input specifies the name of a library to */ 94 /* load for contained keywords. */ 95 }; 96 97 typedef struct Comment Comment; 98 99 typedef struct KWfuncs { 100 Kwfunc start; 101 void *vs; /* v arg for start (e.g., pointer to member object) */ 102 Kwfunc final; 103 void *vf; /* v arg for final */ 104 } KWfuncs; 105 106 struct KeyWord { 107 const char *name; /* name of this keyword */ 108 Uint kind; /* see enum KeyWordKind */ 109 Uint nkw; /* number of keywords nested within this one */ 110 Uint alt; /* > 0 ==> this is in alternate group alt */ 111 Uint req; /* > 0 ==> this is required item number req */ 112 KeyWord *kw; /* the nkw keywords nested within this one */ 113 Real Lb, Ub; /* lower and upper bounds, strict or not according to kind */ 114 int paoff; /* offset to preferred alias */ 115 KWfuncs f; 116 Comment *comment; 117 KeyWord *kwnext; 118 }; 119 120 typedef struct GuiKeyWord GuiKeyWord; 121 struct GuiKeyWord { 122 const char *name; /* name of this keyword */ 123 Uint kind; /* see enum KeyWordKind */ 124 Uint nkw; /* number of keywords nested within this one */ 125 Uint alt; /* > 0 ==> this is in alternate group alt */ 126 Uint req; /* > 0 ==> this is required item number req */ 127 Uint agroup; /* alias group */ 128 GuiKeyWord *kw; /* the nkw keywords nested within this one */ 129 Real Lb, Ub; /* lower and upper bounds, strict or not according to kind */ 130 Real init; 131 const char *cinit; 132 const char *desc; 133 const char *group; /* display group */ 134 const char *alen; /* for array types, the keyword specifying the array length */ 135 const char *dylib; /* "library" containing more of this keyword */ 136 }; 137 138 typedef struct 139 KeyWordx { 140 KeyWord kw; 141 Uint seqno, agroup; 142 const char *funcs; 143 const char *desc; 144 const char *group; 145 const char *defname; 146 const char *alen; 147 const char *init; 148 const char *cinit; 149 } KeyWordx; 150 151 typedef struct KWinfo KWinfo; 152 struct 153 KWinfo { 154 KeyWord *kw, *kw1; 155 void *g; 156 KeyWord **alt, **req; 157 int *altct; 158 const char *name; 159 Uint needstart; 160 int nalt, nreq; 161 }; 162 163 /* stuff for dakreorder and nidrgen */ 164 165 typedef struct 166 KwpHead { 167 char id[16]; 168 double fpkind; 169 Uint bkind; 170 Uint nkw; 171 Uint strtab_offset; 172 Uint kw_offset; 173 Uint end_offset; 174 Uint pad; /* so we have an even number of Uint values */ 175 } KwpHead; 176 177 typedef struct 178 Kwpack { 179 Uint name; 180 Uint kind; 181 Uint nkw; 182 Uint alt; 183 Uint req; 184 Uint kw; 185 Uint Lb; 186 Uint Ub; 187 Uint dylib; 188 int poff; 189 } Kwpack; 190 191 typedef struct 192 Kwpack0 { 193 Uint name; 194 Uint kind; 195 Uint nkw; 196 Uint alt; 197 Uint req; 198 Uint kw; 199 Uint Lb; 200 Uint Ub; 201 int poff; 202 } Kwpack0; /* version to use when pad field of KwpHead is zero */ 203 204 typedef struct 205 NIDR_KWlib { 206 struct NIDR_KWlib *next; 207 char *libname; 208 void *h; /* library handle */ 209 KeyWord *kw0; /* replaced keyword */ 210 KeyWord *oldtop; 211 KeyWord kw; /* replacement */ 212 } NIDR_KWlib; 213 214 #ifdef __cplusplus 215 #define externC extern "C" 216 #else 217 #define externC extern 218 #endif 219 220 externC NIDR_KWlib* nidr_lib_record(void *h, const char *name); 221 externC NIDR_KWlib *NIDR_Libs; 222 #endif 223