PAB3
view release on metacpan or search on metacpan
xs/PAB3/Utils/Utils.xs view on Meta::CPAN
RETVAL = var;
OUTPUT:
RETVAL
#/*****************************************************************************
# * _get_current_thread_id()
# *****************************************************************************/
unsigned long
_get_current_thread_id()
CODE:
RETVAL = get_current_thread_id();
OUTPUT:
RETVAL
#/*****************************************************************************
# * _set_module_path( path )
# *****************************************************************************/
void
_set_module_path( mpath )
SV *mpath;
PREINIT:
dMY_CXT;
STRLEN i, len;
char *path, *s1, *s2;
CODE:
path = SvPVx( mpath, len );
//fprintf( stderr, "set module path [%s]\n", path );
MY_CXT_LOCK;
s1 = MY_CXT.locale_path;
s2 = MY_CXT.zoneinfo_path;
for( i = len; i > 0; i -- ) {
*s1 ++ = *path;
*s2 ++ = *path;
path ++;
}
Copy( "locale/", s1, 7, char );
Copy( "zoneinfo/", s2, 9, char );
*( s1 += 7 ) = '\0';
*( s2 += 9 ) = '\0';
MY_CXT.locale_path_length = (int) ( s1 - MY_CXT.locale_path );
MY_CXT.zoneinfo_path_length = (int) ( s2 - MY_CXT.zoneinfo_path );
read_locale_alias( &MY_CXT );
MY_CXT_UNLOCK;
#/*****************************************************************************
# * new( class, ... )
# *****************************************************************************/
void
new( class, ... )
SV *class;
PREINIT:
dMY_CXT;
SV *sv;
HV *hv;
PPCODE:
sv = sv_2mortal( newSVuv( 0 ) );
SvUV_set( sv, (size_t) sv );
hv = gv_stashpv( SvPVX( class ), FALSE );
XPUSHs( sv_bless( sv_2mortal( newRV( sv ) ), hv ) );
#/*****************************************************************************
# * str_trim( string )
# *****************************************************************************/
void
str_trim( string )
SV *string;
PREINIT:
STRLEN lstr, p1, p2;
char *sstr, ch;
CODE:
sstr = SvPVx( string, lstr );
for( p1 = 0; p1 < lstr; p1 ++ ) {
ch = sstr[p1];
if( ! ISWHITECHAR( ch ) ) break;
}
for( p2 = lstr - 1; p2 >= 0; p2 -- ) {
ch = sstr[p2];
if( ! ISWHITECHAR( ch ) ) break;
}
ST(0) = sv_2mortal( newSVpvn( &sstr[p1], p2 - p1 + 1 ) );
#/*****************************************************************************
# * round( num, ... )
# *****************************************************************************/
double
round( num, ... )
double num;
PREINIT:
int prec;
CODE:
if( items < 2 )
prec = 0;
else {
prec = (int) SvIV( ST(1) );
if( prec > ROUND_PREC_MAX )
prec = ROUND_PREC_MAX;
else if( prec < 0 )
prec = 0;
}
RETVAL = floor( num * ROUND_PREC[prec] + (num < 0.0 ? -0.5 : 0.5) ) / ROUND_PREC[prec];
OUTPUT:
RETVAL
#/*****************************************************************************
# * _set_locale( tid, ... )
# *****************************************************************************/
char *
_set_locale( tid, ... )
UV tid;
xs/PAB3/Utils/Utils.xs view on Meta::CPAN
find_or_create_tv( &MY_CXT, tv, tid );
if( pnt == 0 ) pnt = tv->locale.decimal_point;
if( thou == 0 || ! SvOK( thou ) )
thousep = tv->locale.thousands_sep;
else if( SvPOK( thou ) )
thousep = (char)* SvPV_nolen( thou );
else
thousep = 0;
if( neg == 0 ) neg = tv->locale.negative_sign;
if( pos == 0 || ! SvOK( pos ) )
pos2 = 0;
else if( SvPOK( pos ) )
pos2 = (char)* SvPV_nolen( pos );
else
pos2 = tv->locale.positive_sign;
_int_number_format(
value, str, 255, dec, pnt, thousep, neg, pos2, zerofill, fillchar
);
ST(0) = sv_2mortal( newSVpv( str, 0 ) );
#/*****************************************************************************
# * _set_timezone( tid, tz )
# *****************************************************************************/
int
_set_timezone( tid, tz )
UV tid;
char *tz;
PREINIT:
dMY_CXT;
my_thread_var_t *tv;
CODE:
find_or_create_tv( &MY_CXT, tv, tid );
if(
!tv->timezone.id[0]
|| strcmp( tv->timezone.id, tz ) != 0
) {
Zero( &tv->timezone, 1, my_vtimezone_t );
RETVAL = read_timezone( &MY_CXT, tz, &tv->timezone );
}
else {
RETVAL = 1;
}
OUTPUT:
RETVAL
#/*****************************************************************************
# * _localtime( tid, ... )
# *****************************************************************************/
void
_localtime( tid, ... )
UV tid;
PREINIT:
dMY_CXT;
time_t timer;
my_vdatetime_t *tim;
my_thread_var_t *tv;
PPCODE:
find_or_create_tv( &MY_CXT, tv, tid );
if( items < 2 )
timer = time( 0 );
else
timer = (time_t) SvUV( ST(1) );
tim = apply_timezone( tv, &timer );
EXTEND( SP, 9 );
XPUSHs( sv_2mortal( newSVuv( tim->tm_sec ) ) );
XPUSHs( sv_2mortal( newSVuv( tim->tm_min ) ) );
XPUSHs( sv_2mortal( newSVuv( tim->tm_hour ) ) );
XPUSHs( sv_2mortal( newSVuv( tim->tm_mday ) ) );
XPUSHs( sv_2mortal( newSVuv( tim->tm_mon ) ) );
XPUSHs( sv_2mortal( newSVuv( tim->tm_year ) ) );
XPUSHs( sv_2mortal( newSVuv( tim->tm_wday ) ) );
XPUSHs( sv_2mortal( newSVuv( tim->tm_yday ) ) );
XPUSHs( sv_2mortal( newSVuv( tim->tm_isdst ) ) );
#/*****************************************************************************
# * _strftime( format, ... )
# *****************************************************************************/
void
_strftime( tid, format, ... )
UV tid;
SV *format;
PREINIT:
dMY_CXT;
my_thread_var_t *tv;
STRLEN len;
int gmt;
my_vdatetime_t *tim;
time_t timestamp;
char *tmp, *fmt;
CODE:
find_or_create_tv( &MY_CXT, tv, tid );
fmt = SvPVx( format, len );
if( ! len ) {
ST(0) = &PL_sv_undef;
goto exit;
}
len = 64 + len * 4;
New( 1, tmp, len, char );
if( items < 3 )
timestamp = time( 0 );
else
timestamp = (time_t) SvUV( ST(2) );
if( items < 4 )
gmt = 0;
else
gmt = (long) SvIV( ST(3) );
if( ! gmt )
tim = apply_timezone( tv, ×tamp );
else {
copy_tm_to_vdatetime( gmtime( ×tamp ), &tv->time_struct );
tim = &tv->time_struct;
tim->tm_gmtoff = 0;
tim->tm_zone = DEFAULT_ZONE;
}
len = _int_strftime( tv, tmp, len, fmt, tim );
( run in 1.001 second using v1.01-cache-2.11-cpan-5511b514fd6 )