adding HAWK_MODLIBDIR
This commit is contained in:
parent
b72110af74
commit
fd94b20974
@ -209,7 +209,7 @@ struct hawk_t
|
|||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
int trait;
|
int trait;
|
||||||
hawk_oocs_t mod[2];
|
hawk_oocs_t mod[3];
|
||||||
hawk_oocs_t incldirs;
|
hawk_oocs_t incldirs;
|
||||||
|
|
||||||
union
|
union
|
||||||
|
@ -461,6 +461,7 @@ int hawk_setopt (hawk_t* hawk, hawk_opt_t id, const void* value)
|
|||||||
hawk->opt.trait = *(const int*)value;
|
hawk->opt.trait = *(const int*)value;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
case HAWK_MODLIBDIR:
|
||||||
case HAWK_MODPREFIX:
|
case HAWK_MODPREFIX:
|
||||||
case HAWK_MODPOSTFIX:
|
case HAWK_MODPOSTFIX:
|
||||||
{
|
{
|
||||||
@ -469,7 +470,7 @@ int hawk_setopt (hawk_t* hawk, hawk_opt_t id, const void* value)
|
|||||||
|
|
||||||
if (dup_str_opt(hawk, value, &tmp) <= -1) return -1;
|
if (dup_str_opt(hawk, value, &tmp) <= -1) return -1;
|
||||||
|
|
||||||
idx = id - HAWK_MODPREFIX;
|
idx = id - HAWK_MODLIBDIR;
|
||||||
if (hawk->opt.mod[idx].ptr) hawk_freemem (hawk, hawk->opt.mod[idx].ptr);
|
if (hawk->opt.mod[idx].ptr) hawk_freemem (hawk, hawk->opt.mod[idx].ptr);
|
||||||
|
|
||||||
hawk->opt.mod[idx] = tmp;
|
hawk->opt.mod[idx] = tmp;
|
||||||
@ -524,9 +525,10 @@ int hawk_getopt (hawk_t* hawk, hawk_opt_t id, void* value)
|
|||||||
*(int*)value = hawk->opt.trait;
|
*(int*)value = hawk->opt.trait;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
case HAWK_MODLIBDIR:
|
||||||
case HAWK_MODPREFIX:
|
case HAWK_MODPREFIX:
|
||||||
case HAWK_MODPOSTFIX:
|
case HAWK_MODPOSTFIX:
|
||||||
*(const hawk_ooch_t**)value = hawk->opt.mod[id - HAWK_MODPREFIX].ptr;
|
*(const hawk_ooch_t**)value = hawk->opt.mod[id - HAWK_MODLIBDIR].ptr;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
case HAWK_INCLUDEDIRS:
|
case HAWK_INCLUDEDIRS:
|
||||||
|
@ -481,6 +481,7 @@ typedef struct hawk_mod_spec_t hawk_mod_spec_t;
|
|||||||
|
|
||||||
struct hawk_mod_spec_t
|
struct hawk_mod_spec_t
|
||||||
{
|
{
|
||||||
|
const hawk_ooch_t* libdir;
|
||||||
const hawk_ooch_t* prefix;
|
const hawk_ooch_t* prefix;
|
||||||
const hawk_ooch_t* postfix;
|
const hawk_ooch_t* postfix;
|
||||||
const hawk_ooch_t* name;
|
const hawk_ooch_t* name;
|
||||||
@ -1143,6 +1144,7 @@ enum hawk_opt_t
|
|||||||
/** trait option. 0 or bitwise-ORed of ::hawk_trait_t values */
|
/** trait option. 0 or bitwise-ORed of ::hawk_trait_t values */
|
||||||
HAWK_TRAIT,
|
HAWK_TRAIT,
|
||||||
|
|
||||||
|
HAWK_MODLIBDIR,
|
||||||
HAWK_MODPREFIX,
|
HAWK_MODPREFIX,
|
||||||
HAWK_MODPOSTFIX,
|
HAWK_MODPOSTFIX,
|
||||||
|
|
||||||
|
@ -26,6 +26,10 @@
|
|||||||
|
|
||||||
#include "hawk-prv.h"
|
#include "hawk-prv.h"
|
||||||
|
|
||||||
|
#if !defined(HAWK_DEFAULT_MODLIBDIR)
|
||||||
|
# define HAWK_DEFAULT_MODLIBDIR ""
|
||||||
|
#endif
|
||||||
|
|
||||||
#if !defined(HAWK_DEFAULT_MODPREFIX)
|
#if !defined(HAWK_DEFAULT_MODPREFIX)
|
||||||
# if defined(_WIN32)
|
# if defined(_WIN32)
|
||||||
# define HAWK_DEFAULT_MODPREFIX "hawk-"
|
# define HAWK_DEFAULT_MODPREFIX "hawk-"
|
||||||
@ -7336,33 +7340,51 @@ static hawk_mod_t* query_module (hawk_t* awk, const hawk_oocs_t segs[], int nseg
|
|||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (!awk->prm.modopen || !awk->prm.modgetsym || !awk->prm.modclose)
|
||||||
|
{
|
||||||
|
hawk_seterrfmt (awk, HAWK_NULL, HAWK_EINVAL, HAWK_T("module callbacks not set properly"));
|
||||||
|
goto open_fail;
|
||||||
|
}
|
||||||
|
|
||||||
hawk_seterrnum (awk, HAWK_NULL, HAWK_ENOERR);
|
hawk_seterrnum (awk, HAWK_NULL, HAWK_ENOERR);
|
||||||
|
|
||||||
/* attempt to find an external module */
|
/* attempt to find an external module */
|
||||||
HAWK_MEMSET (&spec, 0, HAWK_SIZEOF(spec));
|
HAWK_MEMSET (&spec, 0, HAWK_SIZEOF(spec));
|
||||||
if (awk->opt.mod[0].len > 0)
|
if (awk->opt.mod[0].len > 0)
|
||||||
spec.prefix = awk->opt.mod[0].ptr;
|
spec.libdir = awk->opt.mod[0].ptr;
|
||||||
else spec.prefix = HAWK_T(HAWK_DEFAULT_MODPREFIX);
|
else
|
||||||
|
spec.libdir = HAWK_T(HAWK_DEFAULT_MODLIBDIR);
|
||||||
|
|
||||||
if (awk->opt.mod[1].len > 0)
|
if (awk->opt.mod[1].len > 0)
|
||||||
spec.postfix = awk->opt.mod[1].ptr;
|
spec.prefix = awk->opt.mod[1].ptr;
|
||||||
|
else spec.prefix = HAWK_T(HAWK_DEFAULT_MODPREFIX);
|
||||||
|
|
||||||
|
if (awk->opt.mod[2].len > 0)
|
||||||
|
spec.postfix = awk->opt.mod[2].ptr;
|
||||||
else spec.postfix = HAWK_T(HAWK_DEFAULT_MODPOSTFIX);
|
else spec.postfix = HAWK_T(HAWK_DEFAULT_MODPOSTFIX);
|
||||||
|
|
||||||
HAWK_MEMSET (&md, 0, HAWK_SIZEOF(md));
|
HAWK_MEMSET (&md, 0, HAWK_SIZEOF(md));
|
||||||
spec.name = segs[0].ptr;
|
spec.name = segs[0].ptr;
|
||||||
md.handle = HAWK_NULL;
|
do
|
||||||
if (awk->prm.modopen && awk->prm.modgetsym && awk->prm.modclose)
|
|
||||||
{
|
{
|
||||||
md.handle = awk->prm.modopen(awk, &spec);
|
hawk_ooch_t* colon;
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
hawk_seterrfmt (awk, HAWK_NULL, HAWK_EINVAL, HAWK_T("module callbacks not set properly"));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (md.handle == HAWK_NULL)
|
colon = hawk_find_oochar_in_oocstr(spec.libdir, ':');
|
||||||
|
if (colon) *colon = '\0';
|
||||||
|
|
||||||
|
md.handle = awk->prm.modopen(awk, &spec);
|
||||||
|
if (!colon) break;
|
||||||
|
|
||||||
|
*colon = ':';
|
||||||
|
}
|
||||||
|
while (!md.handle);
|
||||||
|
|
||||||
|
if (!md.handle)
|
||||||
{
|
{
|
||||||
const hawk_ooch_t* bem = hawk_backuperrmsg(awk);
|
const hawk_ooch_t* bem;
|
||||||
|
open_fail:
|
||||||
|
bem = hawk_backuperrmsg(awk);
|
||||||
hawk_seterrfmt (awk, HAWK_NULL, HAWK_ENOENT, HAWK_T("'%js%js%js' for module '%js' not found - %js"),
|
hawk_seterrfmt (awk, HAWK_NULL, HAWK_ENOENT, HAWK_T("'%js%js%js' for module '%js' not found - %js"),
|
||||||
(spec.prefix? spec.prefix: HAWK_T("")), spec.name, (spec.postfix? spec.postfix: HAWK_T("")), spec.name, bem);
|
(spec.prefix? spec.prefix: HAWK_T("")), spec.name, (spec.postfix? spec.postfix: HAWK_T("")), spec.name, bem);
|
||||||
return HAWK_NULL;
|
return HAWK_NULL;
|
||||||
|
@ -307,10 +307,19 @@ void* hawk_stdmodopen (hawk_t* awk, const hawk_mod_spec_t* spec)
|
|||||||
void* h;
|
void* h;
|
||||||
lt_dladvise adv;
|
lt_dladvise adv;
|
||||||
hawk_bch_t* modpath;
|
hawk_bch_t* modpath;
|
||||||
const hawk_ooch_t* tmp[4];
|
const hawk_ooch_t* tmp[6];
|
||||||
int count;
|
int count;
|
||||||
|
static hawk_ooch_t ds[] = { '/', '\0' };
|
||||||
|
|
||||||
count = 0;
|
count = 0;
|
||||||
|
if (spec->libdir)
|
||||||
|
{
|
||||||
|
hawk_oow_t len;
|
||||||
|
|
||||||
|
tmp[count++] = spec->libdir;
|
||||||
|
len = hawk_count_oocstr(spec->libdir);
|
||||||
|
if (len > 0 && spec->libdir[len - 1] != '/') tmp[count++] = ds;
|
||||||
|
}
|
||||||
if (spec->prefix) tmp[count++] = spec->prefix;
|
if (spec->prefix) tmp[count++] = spec->prefix;
|
||||||
tmp[count++] = spec->name;
|
tmp[count++] = spec->name;
|
||||||
if (spec->postfix) tmp[count++] = spec->postfix;
|
if (spec->postfix) tmp[count++] = spec->postfix;
|
||||||
@ -344,10 +353,22 @@ void* hawk_stdmodopen (hawk_t* awk, const hawk_mod_spec_t* spec)
|
|||||||
|
|
||||||
HMODULE h;
|
HMODULE h;
|
||||||
hawk_ooch_t* modpath;
|
hawk_ooch_t* modpath;
|
||||||
const hawk_ooch_t* tmp[4];
|
const hawk_ooch_t* tmp[6];
|
||||||
int count;
|
int count;
|
||||||
|
static hawk_ooch_t ds[][2] = { { '\\', '\0' }, { '/', '\0' } }
|
||||||
|
false 0 treu 1
|
||||||
count = 0;
|
count = 0;
|
||||||
|
if (spec->libdir)
|
||||||
|
{
|
||||||
|
hawk_oow_t len;
|
||||||
|
|
||||||
|
tmp[count++] = spec->libdir;
|
||||||
|
len = hawk_count_oocstr(spec->libdir);
|
||||||
|
if (len > 0 && (spec->libdir[len - 1] != '/' && spec->libdir[len - 1] != '\\'))
|
||||||
|
{
|
||||||
|
tmp[count++] = ds[hawk_find_oochar_in_oocstr(spec->libdir, '/') != HAWK_NULL];
|
||||||
|
}
|
||||||
|
}
|
||||||
if (spec->prefix) tmp[count++] = spec->prefix;
|
if (spec->prefix) tmp[count++] = spec->prefix;
|
||||||
tmp[count++] = spec->name;
|
tmp[count++] = spec->name;
|
||||||
if (spec->postfix) tmp[count++] = spec->postfix;
|
if (spec->postfix) tmp[count++] = spec->postfix;
|
||||||
@ -368,12 +389,21 @@ void* hawk_stdmodopen (hawk_t* awk, const hawk_mod_spec_t* spec)
|
|||||||
|
|
||||||
HMODULE h;
|
HMODULE h;
|
||||||
hawk_bch_t* modpath;
|
hawk_bch_t* modpath;
|
||||||
const hawk_ooch_t* tmp[4];
|
const hawk_ooch_t* tmp[6];
|
||||||
int count;
|
int count;
|
||||||
char errbuf[CCHMAXPATH];
|
char errbuf[CCHMAXPATH];
|
||||||
APIRET rc;
|
APIRET rc;
|
||||||
|
static hawk_ooch_t ds[] = { '\\', '\0' };
|
||||||
|
|
||||||
count = 0;
|
count = 0;
|
||||||
|
if (spec->libdir)
|
||||||
|
{
|
||||||
|
hawk_oow_t len;
|
||||||
|
|
||||||
|
tmp[count++] = spec->libdir;
|
||||||
|
len = hawk_count_oocstr(spec->libdir);
|
||||||
|
if (len > 0 && spec->libdir[len - 1] != '\\') tmp[count++] = ds;
|
||||||
|
}
|
||||||
if (spec->prefix) tmp[count++] = spec->prefix;
|
if (spec->prefix) tmp[count++] = spec->prefix;
|
||||||
tmp[count++] = spec->name;
|
tmp[count++] = spec->name;
|
||||||
if (spec->postfix) tmp[count++] = spec->postfix;
|
if (spec->postfix) tmp[count++] = spec->postfix;
|
||||||
@ -407,10 +437,19 @@ void* hawk_stdmodopen (hawk_t* awk, const hawk_mod_spec_t* spec)
|
|||||||
* when building for DOS. */
|
* when building for DOS. */
|
||||||
void* h;
|
void* h;
|
||||||
hawk_bch_t* modpath;
|
hawk_bch_t* modpath;
|
||||||
const hawk_ooch_t* tmp[4];
|
const hawk_ooch_t* tmp[6];
|
||||||
int count;
|
int count;
|
||||||
|
static hawk_ooch_t ds[] = { '\\', '\0' };
|
||||||
|
|
||||||
count = 0;
|
count = 0;
|
||||||
|
if (spec->libdir)
|
||||||
|
{
|
||||||
|
hawk_oow_t len;
|
||||||
|
|
||||||
|
tmp[count++] = spec->libdir;
|
||||||
|
len = hawk_count_oocstr(spec->libdir);
|
||||||
|
if (len > 0 && spec->libdir[len - 1] != '/') tmp[count++] = ds;
|
||||||
|
}
|
||||||
if (spec->prefix) tmp[count++] = spec->prefix;
|
if (spec->prefix) tmp[count++] = spec->prefix;
|
||||||
tmp[count++] = spec->name;
|
tmp[count++] = spec->name;
|
||||||
if (spec->postfix) tmp[count++] = spec->postfix;
|
if (spec->postfix) tmp[count++] = spec->postfix;
|
||||||
@ -434,10 +473,19 @@ void* hawk_stdmodopen (hawk_t* awk, const hawk_mod_spec_t* spec)
|
|||||||
#elif defined(USE_DLFCN)
|
#elif defined(USE_DLFCN)
|
||||||
void* h;
|
void* h;
|
||||||
hawk_bch_t* modpath;
|
hawk_bch_t* modpath;
|
||||||
const hawk_ooch_t* tmp[4];
|
const hawk_ooch_t* tmp[6];
|
||||||
int count;
|
int count;
|
||||||
|
static hawk_ooch_t ds[] = { '/', '\0' };
|
||||||
|
|
||||||
count = 0;
|
count = 0;
|
||||||
|
if (spec->libdir)
|
||||||
|
{
|
||||||
|
hawk_oow_t len;
|
||||||
|
|
||||||
|
tmp[count++] = spec->libdir;
|
||||||
|
len = hawk_count_oocstr(spec->libdir);
|
||||||
|
if (len > 0 && spec->libdir[len - 1] != '/') tmp[count++] = ds;
|
||||||
|
}
|
||||||
if (spec->prefix) tmp[count++] = spec->prefix;
|
if (spec->prefix) tmp[count++] = spec->prefix;
|
||||||
tmp[count++] = spec->name;
|
tmp[count++] = spec->name;
|
||||||
if (spec->postfix) tmp[count++] = spec->postfix;
|
if (spec->postfix) tmp[count++] = spec->postfix;
|
||||||
|
Loading…
Reference in New Issue
Block a user