| 1 |
/* |
| 2 |
genidl - Generate interface defintion language listing from a |
| 3 |
Portable Executable. |
| 4 |
Copyright (C) 2009-2016 mingw-w64 project |
| 5 |
|
| 6 |
This program is free software: you can redistribute it and/or modify |
| 7 |
it under the terms of the GNU General Public License as published by |
| 8 |
the Free Software Foundation, either version 3 of the License, or |
| 9 |
(at your option) any later version. |
| 10 |
|
| 11 |
This program is distributed in the hope that it will be useful, |
| 12 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
GNU General Public License for more details. |
| 15 |
|
| 16 |
You should have received a copy of the GNU General Public License |
| 17 |
along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 |
*/ |
| 19 |
|
| 20 |
#define _CRT_SECURE_NO_WARNINGS |
| 21 |
#include "genidl_cfg.h" |
| 22 |
#include "genidl_typeinfo.h" |
| 23 |
#include "genidl_typinfo.h" |
| 24 |
|
| 25 |
static void |
| 26 |
fill_typb (sTI2TypLib *tl, sTI2TypeBase *tb, size_t off, unsigned char *dsrc, unsigned char *tdta, uint32_t length); |
| 27 |
static void |
| 28 |
print_typb_options (FILE *fp, sTI2TypLib *tl, sTI2TypeBase *tb, const char *prefix, const char *dllname); |
| 29 |
static void |
| 30 |
printInterfaceFuncVars (FILE *fp, sTI2TypLib *tl, sTI2TypeBase *tb, const char *prefix); |
| 31 |
static void |
| 32 |
printArgFlags (FILE *fp, uint32_t aflags); |
| 33 |
static void |
| 34 |
printFuncOption (FILE *fp, uint32_t flags, uint32_t id, uint32_t defid, |
| 35 |
uint32_t funcKind, const char **fctPrefix, const char *prefix, |
| 36 |
uint32_t invokeKind); |
| 37 |
static void |
| 38 |
printVarOption (FILE *fp, uint32_t flags, uint32_t id, uint32_t defid, |
| 39 |
uint32_t varKind, const char **varPrefix, |
| 40 |
const char *prefix); |
| 41 |
static void |
| 42 |
printEnum (FILE *fp, sTI2TypLib *tl, sTI2TypeBase *tb, const char *prefix_); |
| 43 |
|
| 44 |
void |
| 45 |
TI2_typlib_dest (sTI2TypLib *tl) |
| 46 |
{ |
| 47 |
if (!tl) |
| 48 |
return; |
| 49 |
TI_dest_typs (&tl->ti2_typs); |
| 50 |
if (tl->guid) |
| 51 |
free (tl->guid); |
| 52 |
if (tl->helpstring) |
| 53 |
free (tl->helpstring); |
| 54 |
if (tl->helpfile) |
| 55 |
free (tl->helpfile); |
| 56 |
if (tl->name) |
| 57 |
free (tl->name); |
| 58 |
if (tl->typinfos_hash) |
| 59 |
free (tl->typinfos_hash); |
| 60 |
if (tl->typb) |
| 61 |
{ |
| 62 |
size_t i; |
| 63 |
for (i=0;i<tl->nr_typinfos;i++) |
| 64 |
{ |
| 65 |
; /* Clean typb */ |
| 66 |
} |
| 67 |
free (tl->typb); |
| 68 |
} |
| 69 |
free (tl); |
| 70 |
} |
| 71 |
|
| 72 |
sTI2TypLib * |
| 73 |
TI2_typlib_init (unsigned char *dta, size_t len) |
| 74 |
{ |
| 75 |
sTI2TypLib *tl = NULL; |
| 76 |
sTypeLibMSFT *t = (sTypeLibMSFT *) dta; |
| 77 |
sSegMSFT *segs; |
| 78 |
unsigned char *d; |
| 79 |
int32_t *typeinfos; |
| 80 |
int i = 0; |
| 81 |
|
| 82 |
if (!len || !dta || t->magic1 != TYPELIB_MSFT_MAGIC) |
| 83 |
return NULL; |
| 84 |
tl = (sTI2TypLib *) malloc (sizeof (sTI2TypLib)); |
| 85 |
memset (tl, 0, sizeof (sTI2TypLib)); |
| 86 |
TI_init_typs (&tl->ti2_typs); |
| 87 |
|
| 88 |
i = 0; |
| 89 |
if (t->var_flags & 0x100) |
| 90 |
i++; |
| 91 |
typeinfos = (int32_t *) &t->dta[i]; |
| 92 |
d = (unsigned char *) &typeinfos[t->nr_typeinfos]; |
| 93 |
segs = (sSegMSFT *) d; |
| 94 |
d = (unsigned char *) &segs[eSegMSFT_MAX]; |
| 95 |
|
| 96 |
/* Initialize constants pools. */ |
| 97 |
TI2_import_name (&tl->ti2_typs,dta + segs[eSegMSFT_NAME].offset, segs[eSegMSFT_NAME].length); |
| 98 |
TI2_import_string (&tl->ti2_typs,dta + segs[eSegMSFT_STRING].offset, segs[eSegMSFT_STRING].length); |
| 99 |
TI2_import_guid (&tl->ti2_typs,dta + segs[eSegMSFT_GUID].offset, segs[eSegMSFT_GUID].length); |
| 100 |
TI2_import_importlibs (&tl->ti2_typs, dta + segs[eSegMSFT_IMPORTFILES].offset, segs[eSegMSFT_IMPORTFILES].length); |
| 101 |
TI2_import_importref (&tl->ti2_typs, dta + segs[eSegMSFT_IMPORTINFO].offset, segs[eSegMSFT_IMPORTINFO].length); |
| 102 |
TI2_import_typinfo_names (&tl->ti2_typs, |
| 103 |
dta + segs[eSegMSFT_TYPEINFO].offset, segs[eSegMSFT_TYPEINFO].length); |
| 104 |
TI2_import_typedesc (&tl->ti2_typs,dta + segs[eSegMSFT_TYPEDESC].offset, segs[eSegMSFT_TYPEDESC].length); |
| 105 |
TI2_import_customdata (&tl->ti2_typs, dta + segs[eSegMSFT_CUSTDATA].offset, segs[eSegMSFT_CUSTDATA].length); |
| 106 |
TI2_import_array (&tl->ti2_typs, dta + segs[eSegMSFT_ARRAYDESC].offset, segs[eSegMSFT_ARRAYDESC].length); |
| 107 |
TI2_import_ref (&tl->ti2_typs, dta + segs[eSegMSFT_REFERENCES].offset, segs[eSegMSFT_REFERENCES].length); |
| 108 |
TI2_import_customdataguid (&tl->ti2_typs, dta + segs[eSegMSFT_CUSTDATAGUID].offset, segs[eSegMSFT_CUSTDATAGUID].length); |
| 109 |
|
| 110 |
tl->ver_major = t->ver_major; |
| 111 |
tl->ver_minor = t->ver_minor; |
| 112 |
tl->version = t->version; |
| 113 |
tl->lcid1 = t->lcid; |
| 114 |
tl->lcid2 = t->lcid2; |
| 115 |
if (t->pos_guid != -1) |
| 116 |
tl->guid = TI_get_typ_name (&tl->ti2_typs, t->pos_guid, TITYP_GUIDS, ""); |
| 117 |
tl->flags = t->flags; |
| 118 |
tl->setFlags = t->var_flags; |
| 119 |
tl->helpstringctx = t->helpstringcontext; |
| 120 |
tl->helpctx = t->helpcontext; |
| 121 |
if (t->helpstring != -1) |
| 122 |
tl->helpstring = TI_get_typ_name (&tl->ti2_typs, t->helpstring, TITYP_STR, ""); |
| 123 |
if (t->helpfile != -1) |
| 124 |
tl->helpfile = TI_get_typ_name (&tl->ti2_typs, t->helpfile, TITYP_STR, ""); |
| 125 |
if (t->name_offset != -1) |
| 126 |
{ |
| 127 |
tl->name = TI_get_typ_name (&tl->ti2_typs, t->name_offset, TITYP_NAME, ""); |
| 128 |
genidl_strlwr (tl->name); |
| 129 |
} |
| 130 |
tl->dispatch = t->dispatchpos; |
| 131 |
tl->nr_typinfos = t->nr_typeinfos; |
| 132 |
tl->nr_impinfos = t->nr_impinfos; |
| 133 |
if (tl->nr_typinfos > 0) |
| 134 |
{ |
| 135 |
size_t ii; |
| 136 |
tl->typinfos_hash = (uint32_t *) malloc (sizeof (uint32_t) * tl->nr_typinfos); |
| 137 |
memcpy (tl->typinfos_hash, typeinfos, sizeof (uint32_t) * tl->nr_typinfos); |
| 138 |
tl->typb = (sTI2TypeBase *) malloc (sizeof (sTI2TypeBase) * tl->nr_typinfos); |
| 139 |
memset (tl->typb, 0, sizeof (sTI2TypeBase) * tl->nr_typinfos); |
| 140 |
for (ii = 0;ii < tl->nr_typinfos; ii++) |
| 141 |
{ |
| 142 |
fill_typb (tl, &tl->typb[ii], ii, dta, dta + segs[eSegMSFT_TYPEINFO].offset, segs[eSegMSFT_TYPEINFO].length); |
| 143 |
} |
| 144 |
} |
| 145 |
return tl; |
| 146 |
} |
| 147 |
|
| 148 |
static void |
| 149 |
fill_typb (sTI2TypLib *tl, sTI2TypeBase *tb, size_t off, unsigned char *dsrc, unsigned char *tdta, uint32_t length) |
| 150 |
{ |
| 151 |
sMSFT_TypeInfoBase *t = (sMSFT_TypeInfoBase *) &tdta[off * sizeof (sMSFT_TypeInfoBase)]; |
| 152 |
if (length <= (off * sizeof (sMSFT_TypeInfoBase))) |
| 153 |
return; |
| 154 |
tb->kind = (t->typekind & 0xf); |
| 155 |
tb->kflags = (t->typekind >> 4) & 0xfff; |
| 156 |
tb->flags= t->flags; |
| 157 |
tb->cFuncs = t->cElement & 0xffff; |
| 158 |
tb->cVars = (t->cElement >> 16) & 0xffff; |
| 159 |
tb->name = TI_get_typ_name (&tl->ti2_typs, (uint32_t) (off * sizeof (sMSFT_TypeInfoBase)), |
| 160 |
TITYP_TYPINFO_NAMES, ""); |
| 161 |
if (t->posguid != -1) |
| 162 |
tb->guid = TI_get_typ_name (&tl->ti2_typs, (uint32_t) t->posguid, TITYP_GUIDS, ""); |
| 163 |
if (t->docstringoffs != -1) |
| 164 |
tb->docstr = TI_get_typ_name (&tl->ti2_typs, (uint32_t) t->docstringoffs, TITYP_STR, ""); |
| 165 |
if (t->oCustData != -1) |
| 166 |
tb->custData = TI_get_typ_name (&tl->ti2_typs, (uint32_t) t->oCustData, |
| 167 |
TITYP_CUSTOMDATA, ""); |
| 168 |
tb->version = t->version; |
| 169 |
if (t->datatype1 != -1) |
| 170 |
{ |
| 171 |
switch (tb->kind) |
| 172 |
{ |
| 173 |
case TKIND_COCLASS: |
| 174 |
tb->dataType = |
| 175 |
TI_get_typ_name (&tl->ti2_typs, (uint32_t) t->datatype1, TITYP_REF, ""); |
| 176 |
break; |
| 177 |
case TKIND_MODULE: |
| 178 |
tb->dataType = |
| 179 |
TI_get_typ_name (&tl->ti2_typs, (uint32_t) t->datatype1, TITYP_STR, ""); |
| 180 |
break; |
| 181 |
case TKIND_INTERFACE: |
| 182 |
case TKIND_DISPATCH: |
| 183 |
tb->dataType = |
| 184 |
getTypeBOrImpRef (&tl->ti2_typs, (uint32_t) t->datatype1,""); |
| 185 |
break; |
| 186 |
default: |
| 187 |
tb->dataType = |
| 188 |
TI_getVTorDref (&tl->ti2_typs, (uint32_t) t->datatype1, "", 0); |
| 189 |
break; |
| 190 |
} |
| 191 |
} |
| 192 |
tb->tib = t; |
| 193 |
if (tb->cFuncs || tb->cVars) |
| 194 |
{ |
| 195 |
sMSFT_memblob *b = (sMSFT_memblob *) &dsrc[t->memoffset]; |
| 196 |
uint32_t *doff = (uint32_t *) &b->dta[b->size]; |
| 197 |
uint32_t offs = 0; |
| 198 |
size_t cf = tb->cFuncs; |
| 199 |
size_t cv = tb->cVars; |
| 200 |
size_t idx = 0; |
| 201 |
tb->mem.count = cf + cv; |
| 202 |
tb->mem.items = (sTI2TypeBaseMemItem *) |
| 203 |
malloc ( sizeof (sTI2TypeBaseMemItem) * tb->mem.count); |
| 204 |
memset (tb->mem.items, 0, sizeof (sTI2TypeBaseMemItem) * tb->mem.count); |
| 205 |
while (offs < b->size) |
| 206 |
{ |
| 207 |
tb->mem.items[idx].mem = &b->dta[offs]; |
| 208 |
if (cf > 0) |
| 209 |
{ |
| 210 |
sMSFT_FuncParam *params; |
| 211 |
sMSFT_func *func; |
| 212 |
uint32_t oVars = 0, *pData, *pCustomData = NULL; |
| 213 |
|
| 214 |
func = (sMSFT_func *) &b->dta[offs]; |
| 215 |
oVars = func->rlen - (func->nrArgs * 12); |
| 216 |
params = (sMSFT_FuncParam *) &b->dta[offs + oVars]; |
| 217 |
pData = func->data; |
| 218 |
pCustomData = NULL; |
| 219 |
if (func->f.hasParamDefValue) |
| 220 |
pCustomData = (uint32_t *) &b->dta[offs + oVars-func->nrArgs*4]; |
| 221 |
tb->mem.items[idx].customData = pCustomData; |
| 222 |
tb->mem.items[idx].funcParam = params; |
| 223 |
tb->mem.items[idx].extData = doff; |
| 224 |
tb->mem.items[idx].max = tb->mem.count; |
| 225 |
tb->mem.items[idx].beFunc = 1; |
| 226 |
offs += func->rlen; |
| 227 |
--cf; |
| 228 |
} |
| 229 |
else if (cv > 0) |
| 230 |
{ |
| 231 |
sMSFT_var *var = (sMSFT_var *) &b->dta[offs]; |
| 232 |
offs += var->rlen; |
| 233 |
tb->mem.items[idx].extData = doff; |
| 234 |
tb->mem.items[idx].max = tb->mem.count; |
| 235 |
} |
| 236 |
else |
| 237 |
abort (); |
| 238 |
doff++; |
| 239 |
idx++; |
| 240 |
} |
| 241 |
} |
| 242 |
} |
| 243 |
|
| 244 |
static void |
| 245 |
TI2_update_config (sTI2TypLib *tl, const char *orgfname) |
| 246 |
{ |
| 247 |
size_t no = tl->nr_typinfos; |
| 248 |
size_t i; |
| 249 |
char *tlbname; |
| 250 |
char *sec = NULL; |
| 251 |
|
| 252 |
genidl_add_lib (tl->name); |
| 253 |
sec = (char *) malloc (strlen (orgfname) + 5); |
| 254 |
/* Do we have a .tlb input file? If so add alias of name. */ |
| 255 |
strcpy (sec, orgfname); |
| 256 |
if (strrchr (sec, '.') != NULL) |
| 257 |
{ |
| 258 |
if (strcmp (strrchr (sec, '.'), ".tlb") != 0) |
| 259 |
strcpy (strrchr (sec, '.'), ".tlb"); |
| 260 |
} |
| 261 |
else |
| 262 |
{ |
| 263 |
strcat (sec, ".tlb"); |
| 264 |
} |
| 265 |
genidl_add_lib_alias (sec, tl->name); |
| 266 |
free (sec); |
| 267 |
|
| 268 |
/* We remove possibly old items. */ |
| 269 |
genidl_del_lib_item (tl->name); |
| 270 |
if (!no && tl->ti2_typs.buc[TITYP_NAME].count != 0 |
| 271 |
&& tl->ti2_typs.buc[TITYP_GUIDS].count != 0) |
| 272 |
return; |
| 273 |
tlbname = (char *) malloc (strlen ("TypeD_") + 8 + 1); |
| 274 |
*tlbname = 0; |
| 275 |
|
| 276 |
for (i = 0;i < no; i++) |
| 277 |
{ |
| 278 |
/* uint32_t mem = tl->ti2_typs.buc[TITYP_TYPINFO_NAMES].arr[i]->memid; */ |
| 279 |
char *name = tl->ti2_typs.buc[TITYP_TYPINFO_NAMES].arr[i]->name; |
| 280 |
/* sprintf (tlbname, "TypeB_%x", mem); */ |
| 281 |
sprintf (tlbname, "TypeB_%x", (unsigned int) i); |
| 282 |
genidl_add_lib_item (tl->name, tlbname, name); |
| 283 |
|
| 284 |
if (tl->typb[i].guid) |
| 285 |
{ |
| 286 |
char *hp = strdup (tl->typb[i].guid + 1); |
| 287 |
if (strrchr (hp, '\"') != NULL) |
| 288 |
* strrchr (hp, '\"') = 0; |
| 289 |
genidl_add_lib_item (tl->name, hp, name); |
| 290 |
free (hp); |
| 291 |
} |
| 292 |
/*if (tl->typb[i].tib->NameOffset != -1) |
| 293 |
{ |
| 294 |
sprintf (tlbname, "Name_%x", tl->typb[i].tib->NameOffset); |
| 295 |
genidl_add_lib_item (tl->name, tlbname, name); |
| 296 |
} */ |
| 297 |
} |
| 298 |
free (tlbname); |
| 299 |
} |
| 300 |
|
| 301 |
static int |
| 302 |
printVersion (FILE *fp, uint32_t version, int befirst, int befirstret, const char *prefix) |
| 303 |
{ |
| 304 |
if (befirst == 0) |
| 305 |
fprintf (fp, ",\n%s ", prefix); |
| 306 |
else if (befirst == -1) |
| 307 |
fprintf (fp, ", "); |
| 308 |
else if (befirstret == 0) |
| 309 |
fprintf (fp, "%s ", prefix); |
| 310 |
fprintf (fp,"version(%d.%d)", version & 0xffff, (version>>16) & 0xffff); |
| 311 |
return befirstret; |
| 312 |
} |
| 313 |
|
| 314 |
static int |
| 315 |
print_flagsstring (FILE *fp, const char *attr, int befirst, int befirstret, const char *prefix) |
| 316 |
{ |
| 317 |
if (befirst == 0) |
| 318 |
fprintf (fp, ",\n%s ", prefix); |
| 319 |
else if (befirst == -1) |
| 320 |
fprintf (fp, ", "); |
| 321 |
else if (befirstret == 0) |
| 322 |
fprintf (fp, "%s ", prefix); |
| 323 |
fprintf (fp, "%s", attr); |
| 324 |
return befirstret; |
| 325 |
} |
| 326 |
|
| 327 |
static int |
| 328 |
printString (FILE *fp, const char *name, const char *str, int befirst, int befirstret, const char *prefix) |
| 329 |
{ |
| 330 |
if (befirst == 0) |
| 331 |
fprintf (fp, ",\n%s ", prefix); |
| 332 |
else if (befirst == -1) |
| 333 |
fprintf (fp, ", "); |
| 334 |
else if (befirstret == 0) |
| 335 |
fprintf (fp, "%s ", prefix); |
| 336 |
if (!str) str = ""; |
| 337 |
if (*str != '"') |
| 338 |
fprintf (fp, "%s(\"%s\")", name, str); |
| 339 |
else |
| 340 |
fprintf (fp, "%s(%s)", name, str); |
| 341 |
return befirstret; |
| 342 |
} |
| 343 |
|
| 344 |
static int |
| 345 |
printUuid (FILE *fp, char *str,int befirst,int befirstret, const char *prefix) |
| 346 |
{ |
| 347 |
if (befirst == 0) |
| 348 |
fprintf (fp, ",\n%prefix ", prefix); |
| 349 |
else if (befirst == -1) |
| 350 |
fprintf (fp, ", "); |
| 351 |
else if (befirstret == 0) |
| 352 |
fprintf (fp, "%s ", prefix); |
| 353 |
if (!str || (str[0] == '"' && str[1]=='"')) |
| 354 |
fprintf (fp, "uuid(00000000-0000-0000-0000-000000000000)"); |
| 355 |
else if (*str != '"') |
| 356 |
{ |
| 357 |
fprintf (fp, "uuid(%s)", str); |
| 358 |
} |
| 359 |
else |
| 360 |
{ |
| 361 |
str++; |
| 362 |
fprintf (fp, "uuid("); |
| 363 |
while (*str != 0 && *str != '"') |
| 364 |
{ |
| 365 |
fputc (*str,fp); |
| 366 |
++str; |
| 367 |
} |
| 368 |
fprintf (fp, ")"); |
| 369 |
} |
| 370 |
return befirstret; |
| 371 |
} |
| 372 |
|
| 373 |
static const char *varflags[32] = { |
| 374 |
"readonly", "source", "bindable", "requestedit", |
| 375 |
"displaybind", "defaultbind", "hidden", "restricted", |
| 376 |
"defaultcollelem", "uidefault", "nonbrowsable", "replaceable", |
| 377 |
"immediatebind", "VARFLAG_2000","VARFLAG_4000","VARFLAG_8000", |
| 378 |
"VARFLAG_10000","VARFLAG_20000","VARFLAG_40000","VARFLAG_80000", |
| 379 |
"VARFLAG_100000","VARFLAG_200000","VARFLAG_400000","VARFLAG_800000", |
| 380 |
"VARFLAG_1000000","VARFLAG_2000000","VARFLAG_4000000","VARFLAG_8000000", |
| 381 |
"VARFLAG_10000000","VARFLAG_20000000","VARFLAG_40000000","VARFLAG_80000000" |
| 382 |
}; |
| 383 |
|
| 384 |
static const char *funcflags[32] = |
| 385 |
{ |
| 386 |
"restricted", "source", "bindable", "requestedit", |
| 387 |
"displaybind", "defaultbind", "hidden", "uselasterror", |
| 388 |
"defaultcollelem", "uidefault", "nonbrowsable", "replaceable", |
| 389 |
"immediatebind", "FUNCFLAG_2000","FUNCFLAG_4000","FUNCFLAG_8000", |
| 390 |
"FUNCFLAG_10000","FUNCFLAG_20000","FUNCFLAG_40000","FUNCFLAG_80000", |
| 391 |
"FUNCFLAG_100000","FUNCFLAG_200000","FUNCFLAG_400000","FUNCFLAG_800000", |
| 392 |
"FUNCFLAG_1000000","FUNCFLAG_2000000","FUNCFLAG_4000000","FUNCFLAG_8000000", |
| 393 |
"FUNCFLAG_10000000","FUNCFLAG_20000000","FUNCFLAG_40000000","FUNCFLAG_80000000" |
| 394 |
}; |
| 395 |
|
| 396 |
static const char *typb_flags[32] = { |
| 397 |
"appobject", "cancreate", "licensed", "predeclid", |
| 398 |
"hidden", "control", "dual", "nonextensible", |
| 399 |
"oleautomation", "restricted", "aggregatable", "replaceable", |
| 400 |
"dispatchable", "reversebind", "proxy", "TYPEFLAG_8000", |
| 401 |
"TYPEFLAG_10000","TYPEFLAG_20000","TYPEFLAG_40000","TYPEFLAG_80000", |
| 402 |
"TYPEFLAG_100000","TYPEFLAG_200000","TYPEFLAG_400000","TYPEFLAG_800000", |
| 403 |
"TYPEFLAG_1000000","TYPEFLAG_2000000","TYPEFLAG_4000000","TYPEFLAG_8000000", |
| 404 |
"TYPEFLAG_10000000","TYPEFLAG_20000000","TYPEFLAG_40000000","TYPEFLAG_80000000" |
| 405 |
}; |
| 406 |
|
| 407 |
static const char *param_flags[32] = { |
| 408 |
"in", "out", "lcid", "retval", |
| 409 |
"opt", "\0hasdefault", "hascustomdata", "PARAMFLAG_80", |
| 410 |
"PARAMFLAG_100","PARAMFLAG_200","PARAMFLAG_400","PARAMFLAG_800", |
| 411 |
"PARAMFLAG_1000","PARAMFLAG_2000","PARAMFLAG_4000","PARAMFLAG_8000", |
| 412 |
"PARAMFLAG_10000","PARAMFLAG_20000","PARAMFLAG_40000","PARAMFLAG_80000", |
| 413 |
"PARAMFLAG_100000","PARAMFLAG_200000","PARAMFLAG_400000","PARAMFLAG_800000", |
| 414 |
"PARAMFLAG_1000000","PARAMFLAG_2000000","PARAMFLAG_4000000","PARAMFLAG_8000000", |
| 415 |
"PARAMFLAG_10000000","PARAMFLAG_20000000","PARAMFLAG_40000000","PARAMFLAG_80000000" |
| 416 |
}; |
| 417 |
|
| 418 |
static void |
| 419 |
printArgFlags (FILE *fp, uint32_t aflags) |
| 420 |
{ |
| 421 |
int idx = 0, befirst = 1; |
| 422 |
if (!aflags || (aflags & ~PARAMFLAG_FHASDEFAULT)==0) |
| 423 |
return; |
| 424 |
fprintf (fp, "["); |
| 425 |
while (aflags != 0 && idx < 32) |
| 426 |
{ |
| 427 |
if ((aflags & 1)!=0 && param_flags[idx][0] != 0) |
| 428 |
{ |
| 429 |
fprintf (fp, "%s%s", befirst ? "" : " ", param_flags[idx]); |
| 430 |
befirst = 0; |
| 431 |
} |
| 432 |
aflags >>= 1; |
| 433 |
idx++; |
| 434 |
} |
| 435 |
fprintf (fp, "] "); |
| 436 |
} |
| 437 |
|
| 438 |
static void |
| 439 |
print_typb_options (FILE *fp, sTI2TypLib *tl, sTI2TypeBase *tb, const char *prefix, const char *dllname) |
| 440 |
{ |
| 441 |
int befirst = 1; |
| 442 |
uint32_t flags = tb->flags, idx = 0; |
| 443 |
|
| 444 |
if (tl) |
| 445 |
befirst = 1; |
| 446 |
if (!tb) |
| 447 |
return; |
| 448 |
if (tb->flags == 0 && tb->docstr == NULL && tb->guid == NULL |
| 449 |
&& tb->version == 0 && dllname == NULL) |
| 450 |
return; |
| 451 |
fprintf (fp, "%s[\n", prefix); |
| 452 |
if (tb->guid != NULL) |
| 453 |
befirst = printUuid (fp, tb->guid,befirst, 0, prefix); |
| 454 |
if (tb->version != 0) |
| 455 |
befirst = printVersion (fp, tb->version, befirst, 0, prefix); |
| 456 |
if (tb->docstr) |
| 457 |
befirst = printString (fp, "helpstring", tb->docstr, befirst, 0, prefix); |
| 458 |
while (flags != 0 && idx != 32) |
| 459 |
{ |
| 460 |
if ((flags & 1) != 0 && typb_flags[idx][0] != 0) |
| 461 |
befirst = print_flagsstring (fp, typb_flags[idx], befirst, 0, prefix); |
| 462 |
flags >>= 1; idx++; |
| 463 |
} |
| 464 |
if (dllname) |
| 465 |
befirst = printString (fp, "dllname", dllname, befirst, 0, prefix); |
| 466 |
if (befirst != 1) |
| 467 |
fprintf (fp, "\n"); |
| 468 |
fprintf (fp, "%s]\n", prefix); |
| 469 |
} |
| 470 |
|
| 471 |
static void |
| 472 |
TI2_typlib_imports (FILE *fp, sTI2TypLib *tl, const char *prefix) |
| 473 |
{ |
| 474 |
size_t i; |
| 475 |
sTITypsHash *th = &tl->ti2_typs.buc[TITYP_IMP]; |
| 476 |
for (i = 0;i < th->count; i++) |
| 477 |
{ |
| 478 |
fprintf (fp, "%simportlib(\"%s\");\n", prefix, th->arr[i]->name); |
| 479 |
} |
| 480 |
if (i != 0) |
| 481 |
fprintf (fp, "\n"); |
| 482 |
} |
| 483 |
|
| 484 |
static char *mk_guard (const char *name, const char *addition) |
| 485 |
{ |
| 486 |
char *r, *h; |
| 487 |
size_t len; |
| 488 |
if (!addition) |
| 489 |
addition = ""; |
| 490 |
len = strlen (name) + strlen (addition) + 1 + strlen ("__"); |
| 491 |
r = (char *) malloc (len); |
| 492 |
sprintf (r, "__%s%s", name, addition); |
| 493 |
h = r; |
| 494 |
while (*h != 0) |
| 495 |
{ |
| 496 |
if (*h >= 'a' && *h <= 'z') |
| 497 |
{ |
| 498 |
h[0] -= 'a'; |
| 499 |
h[0] += 'A'; |
| 500 |
} |
| 501 |
else if (*h <= 0x20) |
| 502 |
*h = '_'; |
| 503 |
h++; |
| 504 |
} |
| 505 |
return r; |
| 506 |
} |
| 507 |
|
| 508 |
static void |
| 509 |
TI2_typlib_forward_declare (FILE *fp, sTI2TypLib *tl, int behdr) |
| 510 |
{ |
| 511 |
size_t i; |
| 512 |
char *guard = NULL; |
| 513 |
int befirst; |
| 514 |
befirst = 1; |
| 515 |
if (!behdr) |
| 516 |
{ |
| 517 |
/* |
| 518 |
fprintf (fp, "/ * Typedef definitions of basic types. * /\n" |
| 519 |
"typedef unsigned short USHORT;\n" |
| 520 |
"typedef signed short SHORT;\n" |
| 521 |
"typedef unsigned char UCHAR;\n" |
| 522 |
"typedef signed char CHAR;\n" |
| 523 |
"typedef unsigned int UINT;\n" |
| 524 |
"typedef signed int INT;\n" |
| 525 |
"typedef int WINBOOL;\n" |
| 526 |
"typedef struct _tagVARIANT VARIANT;\n" |
| 527 |
"typedef unsigned short *BSTR;\n" |
| 528 |
"typedef int SCODE;\n" |
| 529 |
"typedef struct _CY CY;\n"); |
| 530 |
*/ |
| 531 |
} |
| 532 |
for (i=0;i<tl->nr_typinfos;i++) |
| 533 |
{ |
| 534 |
if (tl->typb[i].kind != TKIND_INTERFACE) |
| 535 |
continue; |
| 536 |
if (befirst) |
| 537 |
{ |
| 538 |
fprintf (fp, "/* Interface forward declarations. */\n"); |
| 539 |
befirst = 0; |
| 540 |
} |
| 541 |
if (behdr) |
| 542 |
guard = mk_guard (tl->typb[i].name, "_FORWARDER_DEFINED"); |
| 543 |
if (guard && *guard != 0) |
| 544 |
fprintf (fp, "#ifndef %s\n#define %s\n", guard, guard); |
| 545 |
fprintf (fp, "%s;\n", tl->typb[i].name); |
| 546 |
if (guard) |
| 547 |
{ |
| 548 |
if (*guard != 0) |
| 549 |
fprintf (fp,"#endif /* %s */\n\n", guard); |
| 550 |
free (guard); |
| 551 |
guard = NULL; |
| 552 |
} |
| 553 |
} |
| 554 |
if (!befirst) |
| 555 |
fprintf (fp, "\n"); |
| 556 |
befirst = 1; |
| 557 |
for (i=0;i<tl->nr_typinfos;i++) |
| 558 |
{ |
| 559 |
char *hn; |
| 560 |
if (tl->typb[i].kind != TKIND_RECORD) |
| 561 |
continue; |
| 562 |
if (befirst) |
| 563 |
{ |
| 564 |
fprintf (fp, "/* Structure forward declarations. */\n"); |
| 565 |
befirst = 0; |
| 566 |
} |
| 567 |
if (behdr) |
| 568 |
guard = mk_guard (tl->typb[i].name, "_FORWARDER_DEFINED"); |
| 569 |
if (guard && *guard != 0) |
| 570 |
fprintf (fp, "#ifndef %s\n#define %s\n", guard, guard); |
| 571 |
if ((hn = strchr (tl->typb[i].name, ' ')) == NULL) |
| 572 |
hn = tl->typb[i].name; |
| 573 |
else hn++; |
| 574 |
fprintf (fp, "typedef %s %s;\n", tl->typb[i].name, hn); |
| 575 |
if (guard) |
| 576 |
{ |
| 577 |
if (*guard != 0) |
| 578 |
fprintf (fp,"#endif /* %s */\n\n", guard); |
| 579 |
free (guard); |
| 580 |
guard = NULL; |
| 581 |
} |
| 582 |
} |
| 583 |
if (!befirst) |
| 584 |
fprintf (fp, "\n"); |
| 585 |
befirst = 1; |
| 586 |
for (i=0;i<tl->nr_typinfos;i++) |
| 587 |
{ |
| 588 |
char *hn; |
| 589 |
if (tl->typb[i].kind != TKIND_UNION) |
| 590 |
continue; |
| 591 |
if (befirst) |
| 592 |
{ |
| 593 |
fprintf (fp, "/* Union record forward declarations. */\n"); |
| 594 |
befirst = 0; |
| 595 |
} |
| 596 |
if (behdr) |
| 597 |
guard = mk_guard (tl->typb[i].name, "_FORWARDER_DEFINED"); |
| 598 |
if (guard && *guard != 0) |
| 599 |
fprintf (fp, "#ifndef %s\n#define %s\n", guard, guard); |
| 600 |
if ((hn = strchr (tl->typb[i].name, ' ')) == NULL) |
| 601 |
hn = tl->typb[i].name; |
| 602 |
else hn++; |
| 603 |
fprintf (fp, "typedef %s %s;\n", tl->typb[i].name, hn); |
| 604 |
if (guard) |
| 605 |
{ |
| 606 |
if (*guard != 0) |
| 607 |
fprintf (fp,"#endif /* %s */\n\n", guard); |
| 608 |
free (guard); |
| 609 |
guard = NULL; |
| 610 |
} |
| 611 |
} |
| 612 |
if (!befirst) |
| 613 |
fprintf (fp, "\n"); |
| 614 |
befirst = 1; |
| 615 |
for (i=0;i<tl->nr_typinfos;i++) |
| 616 |
{ |
| 617 |
if (tl->typb[i].kind != TKIND_DISPATCH) |
| 618 |
continue; |
| 619 |
if (befirst) |
| 620 |
{ |
| 621 |
fprintf (fp, "/* Dispatch record forward declarations. */\n"); |
| 622 |
befirst = 0; |
| 623 |
} |
| 624 |
if (behdr) |
| 625 |
guard = mk_guard (tl->typb[i].name, "_FORWARDER_DEFINED"); |
| 626 |
if (guard && *guard != 0) |
| 627 |
fprintf (fp, "#ifndef %s\n#define %s\n", guard, guard); |
| 628 |
fprintf (fp, "%s;\n", tl->typb[i].name); |
| 629 |
if (guard) |
| 630 |
{ |
| 631 |
if (*guard != 0) |
| 632 |
fprintf (fp,"#endif /* %s */\n\n", guard); |
| 633 |
free (guard); |
| 634 |
guard = NULL; |
| 635 |
} |
| 636 |
} |
| 637 |
if (!befirst) |
| 638 |
fprintf (fp, "\n"); |
| 639 |
befirst = 1; |
| 640 |
for (i=0;i<tl->nr_typinfos;i++) |
| 641 |
{ |
| 642 |
if (tl->typb[i].kind != TKIND_COCLASS) |
| 643 |
continue; |
| 644 |
if (befirst) |
| 645 |
{ |
| 646 |
fprintf (fp, "/* Coclass record forward declarations. */\n"); |
| 647 |
befirst = 0; |
| 648 |
} |
| 649 |
if (behdr) |
| 650 |
guard = mk_guard (tl->typb[i].name, "_FORWARDER_DEFINED"); |
| 651 |
if (guard && *guard != 0) |
| 652 |
fprintf (fp, "#ifndef %s\n#define %s\n", guard, guard); |
| 653 |
fprintf (fp, "%s;\n", tl->typb[i].name); |
| 654 |
if (guard) |
| 655 |
{ |
| 656 |
if (*guard != 0) |
| 657 |
fprintf (fp,"#endif /* %s */\n\n", guard); |
| 658 |
free (guard); |
| 659 |
guard = NULL; |
| 660 |
} |
| 661 |
} |
| 662 |
if (!befirst) |
| 663 |
fprintf (fp, "\n"); |
| 664 |
} |
| 665 |
|
| 666 |
static void |
| 667 |
TI2_typlib_typedefs (FILE *fp, sTI2TypLib *tl, const char *prefix, int behdr) |
| 668 |
{ |
| 669 |
char *guard = NULL; |
| 670 |
size_t i; |
| 671 |
int befirst; |
| 672 |
befirst = 1; |
| 673 |
for (i=0;i<tl->nr_typinfos;i++) |
| 674 |
{ |
| 675 |
if (tl->typb[i].kind != TKIND_ALIAS) |
| 676 |
continue; |
| 677 |
if (befirst) |
| 678 |
{ |
| 679 |
fprintf (fp, "%s/* Type definitions. */\n", prefix); |
| 680 |
befirst = 0; |
| 681 |
} |
| 682 |
if (!behdr) |
| 683 |
print_typb_options (fp,tl, &tl->typb[i],prefix, NULL); |
| 684 |
if (behdr) |
| 685 |
guard = mk_guard (tl->typb[i].name, "_TYPEDEF_DEFINED"); |
| 686 |
if (guard && *guard != 0) |
| 687 |
fprintf (fp, "#ifndef %s\n#define %s\n", guard, guard); |
| 688 |
fprintf (fp, "%stypedef %s %s;\n", prefix, |
| 689 |
(tl->typb[i].dataType ? tl->typb[i].dataType : "<unknown>"), |
| 690 |
tl->typb[i].name); |
| 691 |
if (guard) |
| 692 |
{ |
| 693 |
if (*guard != 0) |
| 694 |
fprintf (fp,"#endif /* %s */\n\n", guard); |
| 695 |
free (guard); |
| 696 |
guard = NULL; |
| 697 |
} |
| 698 |
} |
| 699 |
if (!befirst) |
| 700 |
fprintf (fp, "\n"); |
| 701 |
} |
| 702 |
|
| 703 |
static void |
| 704 |
TI2_typlib_enumerations (FILE *fp, sTI2TypLib *tl, const char *prefix, int behdr) |
| 705 |
{ |
| 706 |
char *guard = NULL; |
| 707 |
size_t i; |
| 708 |
int befirst; |
| 709 |
befirst = 1; |
| 710 |
for (i=0;i<tl->nr_typinfos;i++) |
| 711 |
{ |
| 712 |
if (tl->typb[i].kind != TKIND_ENUM) |
| 713 |
continue; |
| 714 |
if (befirst) |
| 715 |
{ |
| 716 |
fprintf (fp, "%s/* Enumeration declarations. */\n", prefix); |
| 717 |
befirst = 0; |
| 718 |
} |
| 719 |
if (!behdr) |
| 720 |
print_typb_options (fp,tl, &tl->typb[i],prefix, NULL); |
| 721 |
if (behdr) |
| 722 |
guard = mk_guard (tl->typb[i].name, "_DEFINED"); |
| 723 |
if (guard && *guard != 0) |
| 724 |
fprintf (fp, "#ifndef %s\n#define %s\n", guard, guard); |
| 725 |
fprintf (fp, "%s%s\n", prefix, tl->typb[i].name); |
| 726 |
fprintf (fp, "%s{\n", prefix); |
| 727 |
printEnum (fp, tl, &tl->typb[i], prefix); |
| 728 |
fprintf (fp, "%s};\n", prefix); |
| 729 |
if (guard) |
| 730 |
{ |
| 731 |
if (*guard != 0) |
| 732 |
fprintf (fp, "#endif /* %s */\n\n", guard); |
| 733 |
free (guard); |
| 734 |
guard = NULL; |
| 735 |
} |
| 736 |
} |
| 737 |
if (!befirst) |
| 738 |
fprintf (fp, "\n"); |
| 739 |
} |
| 740 |
|
| 741 |
static void |
| 742 |
TI2_typlib_dispinterface_hdr (FILE *fp, sTI2TypLib *tl, const char *prefix) |
| 743 |
{ |
| 744 |
size_t i; |
| 745 |
int befirst; |
| 746 |
befirst = 1; |
| 747 |
for (i=0;i<tl->nr_typinfos;i++) |
| 748 |
{ |
| 749 |
if (tl->typb[i].kind != TKIND_DISPATCH) |
| 750 |
continue; |
| 751 |
if (befirst) |
| 752 |
{ |
| 753 |
fprintf (fp, "%s/* Dispatch interface declarations. */\n", prefix); |
| 754 |
befirst = 0; |
| 755 |
} |
| 756 |
//print_typb_options (fp,tl, &tl->typb[i],prefix, NULL); |
| 757 |
fprintf (fp, "%s%s", prefix, tl->typb[i].name); |
| 758 |
if (tl->typb[i].dataType != NULL) |
| 759 |
{ |
| 760 |
char *h = tl->typb[i].dataType; |
| 761 |
if (strchr (h, ' ')!=NULL) |
| 762 |
h = strchr (h, ' ') + 1; |
| 763 |
fprintf (fp, " : %s", h); |
| 764 |
} |
| 765 |
fprintf (fp, "\n"); |
| 766 |
fprintf (fp, "%s{\n", prefix); |
| 767 |
printInterfaceFuncVars (fp, tl, &tl->typb[i], prefix); |
| 768 |
fprintf (fp, "%s};\n", prefix); |
| 769 |
} |
| 770 |
if (!befirst) |
| 771 |
fprintf (fp, "\n"); |
| 772 |
} |
| 773 |
|
| 774 |
static void |
| 775 |
TI2_typlib_dispinterface (FILE *fp, sTI2TypLib *tl, const char *prefix) |
| 776 |
{ |
| 777 |
size_t i; |
| 778 |
int befirst; |
| 779 |
befirst = 1; |
| 780 |
for (i=0;i<tl->nr_typinfos;i++) |
| 781 |
{ |
| 782 |
if (tl->typb[i].kind != TKIND_DISPATCH) |
| 783 |
continue; |
| 784 |
if (befirst) |
| 785 |
{ |
| 786 |
fprintf (fp, "%s/* Dispatch interface declarations. */\n", prefix); |
| 787 |
befirst = 0; |
| 788 |
} |
| 789 |
print_typb_options (fp,tl, &tl->typb[i],prefix, NULL); |
| 790 |
fprintf (fp, "%s%s", prefix, tl->typb[i].name); |
| 791 |
if (tl->typb[i].dataType != NULL) |
| 792 |
{ |
| 793 |
char *h = tl->typb[i].dataType; |
| 794 |
if (strchr (h, ' ')!=NULL) |
| 795 |
h = strchr (h, ' ') + 1; |
| 796 |
fprintf (fp, " : %s", h); |
| 797 |
} |
| 798 |
fprintf (fp, "\n"); |
| 799 |
fprintf (fp, "%s{\n", prefix); |
| 800 |
printInterfaceFuncVars (fp, tl, &tl->typb[i], prefix); |
| 801 |
fprintf (fp, "%s};\n", prefix); |
| 802 |
} |
| 803 |
if (!befirst) |
| 804 |
fprintf (fp, "\n"); |
| 805 |
} |
| 806 |
|
| 807 |
static void |
| 808 |
TI2_typlib_coclass_hdr (FILE *fp, sTI2TypLib *tl, const char *prefix, uint32_t tkind) |
| 809 |
{ |
| 810 |
size_t i; |
| 811 |
int befirst; |
| 812 |
befirst = 1; |
| 813 |
for (i=0;i<tl->nr_typinfos;i++) |
| 814 |
{ |
| 815 |
if (tl->typb[i].kind != tkind) |
| 816 |
continue; |
| 817 |
if (befirst) |
| 818 |
{ |
| 819 |
if (tkind == TKIND_COCLASS) |
| 820 |
fprintf (fp, "%s/* CoClass declarations. */\n", prefix); |
| 821 |
befirst = 0; |
| 822 |
} |
| 823 |
//print_typb_options (fp,tl,&tl->typb[i],prefix, NULL); |
| 824 |
fprintf (fp, "%s%s\n", prefix, tl->typb[i].name); |
| 825 |
fprintf (fp, "%s{\n", prefix); |
| 826 |
if (tl->typb[i].tib->datatype1 != -1) |
| 827 |
{ |
| 828 |
int offset_ref = tl->typb[i].tib->datatype1; |
| 829 |
char *ifname; |
| 830 |
sTITyp *rtyp; |
| 831 |
do { |
| 832 |
rtyp = TI_get_typ (&tl->ti2_typs, (uint32_t) offset_ref, TITYP_REF); |
| 833 |
ifname = TI_get_typ_name (&tl->ti2_typs, (uint32_t) offset_ref, TITYP_REF, ""); |
| 834 |
offset_ref = (rtyp == NULL ? -1 : (int) rtyp->refmem); |
| 835 |
if (ifname) |
| 836 |
fprintf (fp, "%s %s;\n",prefix,ifname); |
| 837 |
} while (offset_ref != -1); |
| 838 |
|
| 839 |
} |
| 840 |
printInterfaceFuncVars (fp, tl, &tl->typb[i], prefix); |
| 841 |
fprintf (fp, "%s};\n", prefix); |
| 842 |
} |
| 843 |
if (!befirst) |
| 844 |
fprintf (fp, "\n"); |
| 845 |
} |
| 846 |
|
| 847 |
static void |
| 848 |
TI2_typlib_coclass (FILE *fp, sTI2TypLib *tl, const char *prefix) |
| 849 |
{ |
| 850 |
size_t i; |
| 851 |
int befirst; |
| 852 |
befirst = 1; |
| 853 |
for (i=0;i<tl->nr_typinfos;i++) |
| 854 |
{ |
| 855 |
if (tl->typb[i].kind != TKIND_COCLASS) |
| 856 |
continue; |
| 857 |
if (befirst) |
| 858 |
{ |
| 859 |
fprintf (fp, "%s/* CoClass declarations. */\n", prefix); |
| 860 |
befirst = 0; |
| 861 |
} |
| 862 |
print_typb_options (fp,tl,&tl->typb[i],prefix, NULL); |
| 863 |
fprintf (fp, "%s%s\n", prefix, tl->typb[i].name); |
| 864 |
fprintf (fp, "%s{\n", prefix); |
| 865 |
if (tl->typb[i].tib->datatype1 != -1) |
| 866 |
{ |
| 867 |
int offset_ref = tl->typb[i].tib->datatype1; |
| 868 |
char *ifname; |
| 869 |
sTITyp *rtyp; |
| 870 |
do { |
| 871 |
rtyp = TI_get_typ (&tl->ti2_typs, (uint32_t) offset_ref, TITYP_REF); |
| 872 |
ifname = TI_get_typ_name (&tl->ti2_typs, (uint32_t) offset_ref, TITYP_REF, ""); |
| 873 |
offset_ref = (rtyp == NULL ? -1 : (int) rtyp->refmem); |
| 874 |
if (ifname) |
| 875 |
fprintf (fp, "%s %s;\n",prefix,ifname); |
| 876 |
} while (offset_ref != -1); |
| 877 |
|
| 878 |
} |
| 879 |
printInterfaceFuncVars (fp, tl, &tl->typb[i], prefix); |
| 880 |
fprintf (fp, "%s};\n", prefix); |
| 881 |
} |
| 882 |
if (!befirst) |
| 883 |
fprintf (fp, "\n"); |
| 884 |
} |
| 885 |
|
| 886 |
static void |
| 887 |
TI2_typlib_structures (FILE *fp, sTI2TypLib *tl, const char *prefix, int behdr) |
| 888 |
{ |
| 889 |
char *guard = NULL; |
| 890 |
size_t i; |
| 891 |
int befirst; |
| 892 |
befirst = 1; |
| 893 |
for (i=0;i<tl->nr_typinfos;i++) |
| 894 |
{ |
| 895 |
if (tl->typb[i].kind != TKIND_RECORD && tl->typb[i].kind != TKIND_UNION) |
| 896 |
continue; |
| 897 |
if (befirst) |
| 898 |
{ |
| 899 |
fprintf (fp, "%s/* Structure/union declarations. */\n", prefix); |
| 900 |
befirst = 0; |
| 901 |
} |
| 902 |
if (!behdr) |
| 903 |
print_typb_options (fp,tl, &tl->typb[i],prefix, NULL); |
| 904 |
if (behdr) |
| 905 |
guard = mk_guard (tl->typb[i].name, "_DEFINED"); |
| 906 |
if (guard && *guard != 0) |
| 907 |
fprintf (fp, "#ifndef %s\n#define %s\n", guard, guard); |
| 908 |
fprintf (fp, "%s%s\n", prefix, tl->typb[i].name); |
| 909 |
fprintf (fp, "%s{\n", prefix); |
| 910 |
printInterfaceFuncVars (fp, tl, &tl->typb[i], prefix); |
| 911 |
fprintf (fp, "%s};\n", prefix); |
| 912 |
if (guard) |
| 913 |
{ |
| 914 |
if (*guard != 0) |
| 915 |
fprintf (fp, "#endif /* %s */\n\n", guard); |
| 916 |
free (guard); |
| 917 |
guard = NULL; |
| 918 |
} |
| 919 |
} |
| 920 |
if (!befirst) |
| 921 |
fprintf (fp, "\n"); |
| 922 |
} |
| 923 |
|
| 924 |
static void |
| 925 |
TI2_typlib_modules (FILE *fp, sTI2TypLib *tl, const char *prefix) |
| 926 |
{ |
| 927 |
size_t i; |
| 928 |
int befirst; |
| 929 |
befirst = 1; |
| 930 |
for (i=0;i<tl->nr_typinfos;i++) |
| 931 |
{ |
| 932 |
if (tl->typb[i].kind != TKIND_MODULE) |
| 933 |
continue; |
| 934 |
if (befirst) |
| 935 |
{ |
| 936 |
fprintf (fp, "%s/* Module declarations. */\n", prefix); |
| 937 |
befirst = 0; |
| 938 |
} |
| 939 |
print_typb_options (fp,tl, &tl->typb[i],prefix, tl->typb[i].dataType); |
| 940 |
fprintf (fp, "%s%s", prefix, tl->typb[i].name); |
| 941 |
fprintf (fp, "\n"); |
| 942 |
fprintf (fp, "%s{\n", prefix); |
| 943 |
printInterfaceFuncVars (fp, tl, &tl->typb[i], prefix); |
| 944 |
fprintf (fp, "%s};\n", prefix); |
| 945 |
} |
| 946 |
if (!befirst) |
| 947 |
fprintf (fp, "\n"); |
| 948 |
} |
| 949 |
|
| 950 |
static void |
| 951 |
printEnum (FILE *fp, sTI2TypLib *tl, sTI2TypeBase *tb, const char *prefix_) |
| 952 |
{ |
| 953 |
char *prefix; |
| 954 |
size_t i; |
| 955 |
if (!tl || !tb || (tb->cFuncs == 0 && tb->cVars == 0)) |
| 956 |
return; |
| 957 |
prefix = (char *) malloc (strlen (prefix_) + 3); |
| 958 |
memset (prefix,' ',strlen (prefix_) + 2); |
| 959 |
prefix[strlen (prefix_) + 2] = 0; |
| 960 |
|
| 961 |
for (i = 0;i < tb->mem.count; i++) |
| 962 |
{ |
| 963 |
char *name = NULL; |
| 964 |
sTI2TypeBaseMemItem *mi = &tb->mem.items[i]; |
| 965 |
|
| 966 |
name = TI_get_typ_name (&tl->ti2_typs, mi->extData[mi->max], TITYP_NAME, ""); |
| 967 |
if (mi->beFunc) |
| 968 |
{ |
| 969 |
abort (); |
| 970 |
} |
| 971 |
else |
| 972 |
{ |
| 973 |
fprintf (fp, "%s%s = ", prefix, name); |
| 974 |
printValue (fp, &tl->ti2_typs,mi->var->oValue); |
| 975 |
fprintf (fp, "%s\n", ((i+1) != tb->mem.count ? "," : "")); |
| 976 |
} |
| 977 |
if (name) |
| 978 |
free (name); |
| 979 |
} |
| 980 |
free (prefix); |
| 981 |
} |
| 982 |
|
| 983 |
static void |
| 984 |
printInterfaceFuncVars (FILE *fp, sTI2TypLib *tl, sTI2TypeBase *tb, const char *prefix_) |
| 985 |
{ |
| 986 |
uint32_t defid; |
| 987 |
char *prefix; |
| 988 |
size_t i; |
| 989 |
if (!tl || !tb || (tb->cFuncs == 0 && tb->cVars == 0)) |
| 990 |
return; |
| 991 |
prefix = (char *) malloc (strlen (prefix_) + 3); |
| 992 |
memset (prefix,' ',strlen (prefix_) + 2); |
| 993 |
prefix[strlen (prefix_) + 2] = 0; |
| 994 |
|
| 995 |
switch (tb->kind) |
| 996 |
{ |
| 997 |
case TKIND_UNION: case TKIND_RECORD: |
| 998 |
defid = (uint32_t) 1073741824; break; |
| 999 |
default: |
| 1000 |
defid = 0xfefefefe; break; |
| 1001 |
} |
| 1002 |
|
| 1003 |
for (i = 0;i < tb->mem.count; i++) |
| 1004 |
{ |
| 1005 |
char *name = NULL; |
| 1006 |
char *rtyp = NULL; |
| 1007 |
uint32_t id; |
| 1008 |
sTI2TypeBaseMemItem *mi = &tb->mem.items[i]; |
| 1009 |
|
| 1010 |
name = TI_get_typ_name (&tl->ti2_typs, mi->extData[mi->max], TITYP_NAME, ""); |
| 1011 |
id = mi->extData[0]; |
| 1012 |
if (mi->beFunc) |
| 1013 |
{ |
| 1014 |
const char *val = ""; |
| 1015 |
printFuncOption (fp, mi->func->flags, id, defid, mi->func->f.funcKind, &val, prefix, |
| 1016 |
mi->func->f.invokeKind); |
| 1017 |
rtyp = TI_getVTorDref (&tl->ti2_typs, mi->func->datatype, "", 0); |
| 1018 |
fprintf (fp, "%s%s%s %s %s (", |
| 1019 |
prefix, val, rtyp, getCallConvName(mi->func->f.callconv), |
| 1020 |
name); |
| 1021 |
if (mi->func->nrArgs == 0) |
| 1022 |
fprintf (fp, "void);\n"); |
| 1023 |
else |
| 1024 |
{ |
| 1025 |
uint16_t a; |
| 1026 |
fprintf (fp, "\n"); |
| 1027 |
for (a = 0; a < mi->func->nrArgs;a++) |
| 1028 |
{ |
| 1029 |
char *aname = NULL; |
| 1030 |
char *atyp = NULL; |
| 1031 |
if (mi->funcParam[a].oName != -1) |
| 1032 |
aname = TI_get_typ_name (&tl->ti2_typs, mi->funcParam[a].oName, TITYP_NAME, ""); |
| 1033 |
else |
| 1034 |
{ |
| 1035 |
/* We have to generate an name for this argument. */ |
| 1036 |
aname = (char *) malloc (128); |
| 1037 |
sprintf (aname, "argNo%u", (uint32_t) a + 1); |
| 1038 |
} |
| 1039 |
atyp = TI_getVTorDref (&tl->ti2_typs, mi->funcParam[a].dataType, aname, 0); |
| 1040 |
fprintf (fp, "%s ", prefix); |
| 1041 |
printArgFlags (fp, mi->funcParam[a].flags); |
| 1042 |
fprintf (fp, "%s", atyp); |
| 1043 |
free (atyp); |
| 1044 |
free (aname); |
| 1045 |
if (mi->customData && (mi->funcParam[a].flags & PARAMFLAG_FHASDEFAULT) != 0) |
| 1046 |
{ |
| 1047 |
fprintf (fp," = "); |
| 1048 |
printValue (fp, &tl->ti2_typs,mi->customData[a]); |
| 1049 |
} |
| 1050 |
if ((a + 1) != mi->func->nrArgs) |
| 1051 |
fprintf (fp, ","); |
| 1052 |
fprintf (fp, "\n"); |
| 1053 |
} |
| 1054 |
fprintf (fp, "%s);\n", prefix); |
| 1055 |
} |
| 1056 |
} |
| 1057 |
else |
| 1058 |
{ |
| 1059 |
const char *val = ""; |
| 1060 |
printVarOption (fp, mi->var->flags, id, defid, mi->var->varKind, &val, prefix); |
| 1061 |
rtyp = TI_getVTorDref (&tl->ti2_typs, mi->var->datatype, name, 0); |
| 1062 |
fprintf (fp, "%s%s%s", prefix, val, rtyp); |
| 1063 |
if ((tb->kind == TKIND_DISPATCH || tb->kind == TKIND_INTERFACE) && mi->var->oValue != 0) |
| 1064 |
{ |
| 1065 |
fprintf (fp," = %d", mi->var->oValue); |
| 1066 |
} |
| 1067 |
else if (tb->kind != TKIND_RECORD && tb->kind != TKIND_UNION |
| 1068 |
&& !(tb->kind == TKIND_DISPATCH || tb->kind == TKIND_INTERFACE) |
| 1069 |
&& (uint32_t) mi->var->oValue != (uint32_t) -1) |
| 1070 |
{ |
| 1071 |
fprintf (fp," = "); |
| 1072 |
printValue (fp, &tl->ti2_typs,mi->var->oValue); |
| 1073 |
} |
| 1074 |
fprintf (fp, ";\n"); |
| 1075 |
} |
| 1076 |
if (rtyp) |
| 1077 |
free (rtyp); |
| 1078 |
if (name) |
| 1079 |
free (name); |
| 1080 |
defid = id + 1; |
| 1081 |
} |
| 1082 |
free (prefix); |
| 1083 |
} |
| 1084 |
|
| 1085 |
static void |
| 1086 |
TI2_typlib_interfaces (FILE *fp, sTI2TypLib *tl, const char *prefix) |
| 1087 |
{ |
| 1088 |
size_t i; |
| 1089 |
int befirst; |
| 1090 |
befirst = 1; |
| 1091 |
for (i=0;i<tl->nr_typinfos;i++) |
| 1092 |
{ |
| 1093 |
if (tl->typb[i].kind != TKIND_INTERFACE) |
| 1094 |
continue; |
| 1095 |
if (befirst) |
| 1096 |
{ |
| 1097 |
fprintf (fp, "%s/* Interface declarations. */\n", prefix); |
| 1098 |
befirst = 0; |
| 1099 |
} |
| 1100 |
print_typb_options (fp,tl, &tl->typb[i],prefix, NULL); |
| 1101 |
fprintf (fp, "%s%s", prefix, tl->typb[i].name); |
| 1102 |
if (tl->typb[i].dataType != NULL) |
| 1103 |
{ |
| 1104 |
char *h = tl->typb[i].dataType; |
| 1105 |
if (strchr (h, ' ')!=NULL) |
| 1106 |
h = strchr (h, ' ') + 1; |
| 1107 |
fprintf (fp, " : %s", h); |
| 1108 |
} |
| 1109 |
fprintf (fp, "\n"); |
| 1110 |
fprintf (fp, "%s{\n", prefix); |
| 1111 |
printInterfaceFuncVars (fp, tl, &tl->typb[i], prefix); |
| 1112 |
fprintf (fp, "%s};\n", prefix); |
| 1113 |
} |
| 1114 |
if (!befirst) |
| 1115 |
fprintf (fp, "\n"); |
| 1116 |
} |
| 1117 |
|
| 1118 |
static void |
| 1119 |
printVarOption (FILE *fp, uint32_t flags, uint32_t id, uint32_t defid, |
| 1120 |
uint32_t varKind, const char **varPrefix, |
| 1121 |
const char *prefix) |
| 1122 |
{ |
| 1123 |
int befirst = 1,idx = 0; |
| 1124 |
|
| 1125 |
switch (varKind) { |
| 1126 |
case VARKIND_PERINSTANCE: break; |
| 1127 |
case VARKIND_STATIC: *varPrefix = "static "; break; |
| 1128 |
case VARKIND_CONST: *varPrefix = "CONST "; break; |
| 1129 |
case VARKIND_DISPATCH: break; |
| 1130 |
} |
| 1131 |
if (id == defid && flags == 0) |
| 1132 |
return; |
| 1133 |
fprintf (fp, "%s[", prefix); |
| 1134 |
if (id != defid) |
| 1135 |
{ |
| 1136 |
if (id < 0x100) |
| 1137 |
fprintf (fp, "id(%u)", id); |
| 1138 |
else |
| 1139 |
fprintf (fp, "id(0x%x)", id); |
| 1140 |
befirst=0; |
| 1141 |
} |
| 1142 |
while (flags != 0) |
| 1143 |
{ |
| 1144 |
if ((flags & 1)!=0 && varflags[idx][0]!=0) |
| 1145 |
{ |
| 1146 |
if (!befirst) fprintf (fp, ", "); |
| 1147 |
befirst = 0; |
| 1148 |
fprintf (fp, "%s", varflags[idx]); |
| 1149 |
} |
| 1150 |
flags >>=1; idx++; |
| 1151 |
} |
| 1152 |
fprintf (fp, "]\n"); |
| 1153 |
} |
| 1154 |
|
| 1155 |
static void |
| 1156 |
printFuncOption (FILE *fp, uint32_t flags, uint32_t id, uint32_t defid, |
| 1157 |
uint32_t funcKind, const char **fctPrefix, const char *prefix, |
| 1158 |
uint32_t invokeKind) |
| 1159 |
{ |
| 1160 |
int befirst = 1, idx = 0; |
| 1161 |
const char *invoke = ""; |
| 1162 |
switch (funcKind) |
| 1163 |
{ |
| 1164 |
case FUNCTKIND_VIRTUAL: *fctPrefix = "virtual "; break; |
| 1165 |
case FUNCTKIND_PUREVIRTUAL: break; |
| 1166 |
case FUNCTKIND_NONVIRTUAL: break; |
| 1167 |
case FUNCTKIND_STATIC: *fctPrefix = "static "; break; |
| 1168 |
case FUNCTKIND_DISPATCH: |
| 1169 |
break; |
| 1170 |
} |
| 1171 |
switch ((invokeKind & ~1)) |
| 1172 |
{ |
| 1173 |
case INVOKIND_FUNC: break; |
| 1174 |
case INVOKIND_PROPERTYGET: invoke = "propget"; break; |
| 1175 |
case INVOKIND_PROPERTYPUT: invoke = "propput"; break; |
| 1176 |
case INVOKIND_PROPERTYGET | INVOKIND_PROPERTYPUT: |
| 1177 |
invoke = "propgetput"; break; |
| 1178 |
case INVOKIND_PROPERTYPUTREF: |
| 1179 |
invoke = "propputref"; break; |
| 1180 |
case INVOKIND_PROPERTYPUT | INVOKIND_PROPERTYPUTREF: |
| 1181 |
invoke = "propputputref"; break; |
| 1182 |
case INVOKIND_PROPERTYGET | INVOKIND_PROPERTYPUTREF: |
| 1183 |
invoke = "propgetputref"; break; |
| 1184 |
case INVOKIND_PROPERTYGET | INVOKIND_PROPERTYPUT | INVOKIND_PROPERTYPUTREF: |
| 1185 |
invoke = "propgetputputref"; break; |
| 1186 |
} |
| 1187 |
if (id == defid && flags == 0 && invoke[0]==0) |
| 1188 |
return; |
| 1189 |
fprintf (fp, "%s[", prefix); |
| 1190 |
if (id != defid) |
| 1191 |
{ |
| 1192 |
if (id < 0x100) |
| 1193 |
fprintf (fp, "id(%u)", id); |
| 1194 |
else |
| 1195 |
fprintf (fp, "id(0x%x)", id); |
| 1196 |
befirst = 0; |
| 1197 |
} |
| 1198 |
if (invoke[0]!=0) |
| 1199 |
{ |
| 1200 |
if (!befirst) |
| 1201 |
fprintf (fp, ", "); |
| 1202 |
fprintf (fp, "%s", invoke); |
| 1203 |
befirst = 0; |
| 1204 |
} |
| 1205 |
while (flags != 0) |
| 1206 |
{ |
| 1207 |
if ((flags & 1) != 0 && funcflags[idx][0]!=0) |
| 1208 |
{ |
| 1209 |
if (!befirst) |
| 1210 |
fprintf (fp, ", "); |
| 1211 |
fprintf (fp, "%s", funcflags[idx]); |
| 1212 |
befirst = 0; |
| 1213 |
} |
| 1214 |
flags >>=1; idx++; |
| 1215 |
} |
| 1216 |
fprintf (fp, "]\n"); |
| 1217 |
} |
| 1218 |
|
| 1219 |
void |
| 1220 |
TI2_typlib_hdr (FILE *fp, sTI2TypLib *tl, const char *orgfname) |
| 1221 |
{ |
| 1222 |
//int befirst; |
| 1223 |
if (!tl) |
| 1224 |
return; |
| 1225 |
fprintf (fp, "/* Automated generated header file <%s>.\n" |
| 1226 |
" * Generated by genidl tool (c) 2009-2016 Mingw-w64 project.\n" |
| 1227 |
" */\n\n", (tl->name ? tl->name : "unknown")); |
| 1228 |
TI2_update_config (tl, orgfname); |
| 1229 |
TI2_typlib_forward_declare (fp, tl, 1); |
| 1230 |
TI2_typlib_enumerations (fp, tl, "", 1); |
| 1231 |
TI2_typlib_structures (fp, tl, "",1); |
| 1232 |
TI2_typlib_typedefs (fp, tl, "", 1); |
| 1233 |
if (0) TI2_typlib_coclass_hdr (fp, tl, "", TKIND_COCLASS); |
| 1234 |
TI2_typlib_dispinterface_hdr (fp, tl, ""); |
| 1235 |
} |
| 1236 |
|
| 1237 |
void |
| 1238 |
TI2_typlib_idl (FILE *fp, sTI2TypLib *tl, const char *orgfname) |
| 1239 |
{ |
| 1240 |
int befirst; |
| 1241 |
if (!tl) |
| 1242 |
return; |
| 1243 |
fprintf (fp, "/* Automated generated idl file <%s>.\n" |
| 1244 |
" * Generated by genidl tool (c) 2009-2016 Mingw-w64 project.\n" |
| 1245 |
" */\n\n", (tl->name ? tl->name : "unknown")); |
| 1246 |
|
| 1247 |
TI2_update_config (tl, orgfname); |
| 1248 |
TI2_typlib_forward_declare (fp, tl, 0); |
| 1249 |
TI2_typlib_enumerations (fp, tl, "", 0); |
| 1250 |
TI2_typlib_structures (fp, tl, "", 0); |
| 1251 |
TI2_typlib_typedefs (fp, tl, "", 0); |
| 1252 |
fprintf (fp, "[\n"); |
| 1253 |
befirst = 1; |
| 1254 |
if (tl->guid) |
| 1255 |
befirst = printUuid (fp, tl->guid, befirst, 0, ""); |
| 1256 |
if (tl->version != 0) |
| 1257 |
befirst = printVersion (fp, tl->version, befirst, 0, ""); |
| 1258 |
if (tl->helpstring) |
| 1259 |
befirst = printString (fp, "helpstring", tl->helpstring, befirst, 0, ""); |
| 1260 |
if (tl->helpfile) |
| 1261 |
befirst = printString (fp, "helpfile", tl->helpfile, befirst, 0, ""); |
| 1262 |
if (befirst != 1) |
| 1263 |
fprintf (fp, "\n"); |
| 1264 |
fprintf (fp, "]\n"); |
| 1265 |
fprintf (fp, "library %s\n{\n", tl->name); |
| 1266 |
TI2_typlib_imports (fp, tl, " "); |
| 1267 |
// coclass |
| 1268 |
TI2_typlib_coclass (fp, tl, " "); |
| 1269 |
// dispinterface |
| 1270 |
TI2_typlib_dispinterface (fp, tl, " "); |
| 1271 |
fprintf (fp, "};\n\n"); |
| 1272 |
TI2_typlib_interfaces (fp, tl, ""); |
| 1273 |
TI2_typlib_modules (fp, tl, ""); |
| 1274 |
} |