_export p4cell
p4_search_option_value (const p4char* nm, int l,
p4cell defval, p4_Options* opt)
{
p4xt xt = p4_search_option (nm, l, opt);
if (xt && IS_VALUE_RT(xt)) return *P4_TO_BODY(xt);
if (l >= 32) return defval;
{
# ifdef __vxworks
long* symval;
const p4char prefix[] = "p4__default_" ;
# else
const p4char prefix[] = "pfe_default_" ;
# endif
# define strlen_prefix (sizeof(prefix)-1)
p4char symbol[strlen_prefix+32+5];
p4char* s;
if (*nm == '/' ) {
memcpy (&symbol[0], prefix, strlen_prefix);
memcpy (&symbol[strlen_prefix], nm+1, l-1);
memcpy (&symbol[strlen_prefix+l-1], "_size" , 6);
}else{
memcpy (&symbol[0], prefix, sizeof(prefix)-1);
memcpy (&symbol[strlen_prefix], nm, l);
symbol[strlen_prefix+l] = '\0' ;
}
for (s=symbol; *s; s++) if (! isalnum(*(p4char*)s)) *s = '_' ;
# ifdef __vxworks
if (symFindByName (sysSymTbl, symbol, (char**) &symval, 0) == OK)
if (symval)
{
P4_info4 ("seen '%.*s' = %ld (%s)" , l, nm, *symval, symbol);
return *symval;
}
# else
# ifndef _toupper
# define _toupper(X) toupper(X)
# endif
for (s=symbol; *s; s++) if (islower(*s)) *s = _toupper(*s);
if ((s=getenv(symbol)))
{
int newval; errno = 0; newval = atoi (s);
if (! errno)
{
P4_info4 ("seen '%.*s' = %d (%s)" , l, nm, newval, symbol);
return newval;
}
}
# endif
P4_info4 ("keep '%.*s' = %ld (%s not found)" , l, nm, (long)defval,
symbol);
}
return defval;
} |