static void _rts_approx_rise_and_set (double *m_rts, double h0) { double h0_dfrac = h0/360.0; m_rts[SUN_RISE] = _wrap ((m_rts[SUN_TRANSIT] - h0_dfrac), 0, 1); m_rts[SUN_SET] = _wrap ((m_rts[SUN_TRANSIT] + h0_dfrac), 0, 1); m_rts[SUN_TRANSIT] = _wrap ((m_rts[SUN_TRANSIT]), 0, 1); }
static double _rts_alpha_delta_prime (double *ad, double n) { double a = ad[JD_ZERO] - ad[JD_MINUS]; double b = ad[JD_PLUS] - ad[JD_ZERO]; if (fabs(a) >= 2.0) a = _wrap (a, 0, 1); if (fabs(b) >= 2.0) b = _wrap (b, 0, 1); return ad[JD_ZERO] + n * (a + b + (b-a)*n)/2.0; }
inline LZHASH LZHLCompressor::_updateTable( LZHASH hash, const uint8_t* src, LZPOS pos, ptrdiff_t len ) { if ( len <= 0 ) return 0; if ( len > LZSKIPHASH ) { ++src; hash = 0; const uint8_t* pEnd = src + len + LZMATCH; for ( const uint8_t* p=src+len; p < pEnd ; ) { UPDATE_HASH( hash, *p++ ); } return hash; } UPDATE_HASH_EX( hash, src ); ++src; for ( int i=0; i < len ; ++i ) { table[ HASH_POS( hash ) ] = (LZTableItem)_wrap( pos + i ); UPDATE_HASH_EX( hash, src + i ); } return hash; }
static double _top_azimuth_angle_astro(double h_prime, double latitude, double delta_prime) { double h_prime_rad = _deg2rad(h_prime); double lat_rad = _deg2rad(latitude); return _wrap (_rad2deg (atan2(sin(h_prime_rad), cos(h_prime_rad)*sin(lat_rad) - tan(_deg2rad(delta_prime))*cos(lat_rad))), 0, 360); }
/*! * \brief * Calculate geocentric right ascension * \return [deg] */ static double _geo_right_ascension(double lamda, double epsilon, double beta) { double lamda_rad = _deg2rad (lamda); double epsilon_rad = _deg2rad (epsilon); return _wrap (_rad2deg ( atan2( sin (lamda_rad)*cos (epsilon_rad) - tan (_deg2rad (beta))*sin (epsilon_rad), cos (lamda_rad))), 0, 360); }
/*! * \brief * Calculate Earth's Heliocentric longitude * \return [deg] */ static double _earth_hel_longitude (double jme) { double sum[L_COUNT]; int i; for (i = 0; i < L_COUNT; i++) sum[i] = _periodic_term_sum (L_TERMS[i], l_subcount[i], jme); return _wrap (_rad2deg (_earth_values (sum, L_COUNT, jme)), 0, 360); }
static double _rts_hour_angle_at_rise_set (double latitude, double delta_zero, double h0_prime) { double h0 = -99999; double latitude_rad = _deg2rad (latitude); double delta_zero_rad = _deg2rad (delta_zero); double argument = (sin(_deg2rad(h0_prime)) - sin(latitude_rad)*sin(delta_zero_rad)) / (cos(latitude_rad)*cos(delta_zero_rad)); if (fabs(argument) <= 1) h0 = _wrap (_rad2deg(acos(argument)), 0, 180); return h0; }
t_list *sm_split(char *str, char spliter) { int i; int j; t_list *list; char *n_str; i = -1; j = 0; if (!str) return (NULL); if (!(list = new_list())) return (NULL); while (str[++i]) if (str[i] == spliter) { n_str = sm_dupn(&str[j], i - j); list->push(list, _wrap(n_str, sm_len(n_str))); j = i + 1; } if (j != i) list->push(list, _wrap(sm_dup(&str[j]), sm_len(&str[j]))); return (list); }
void LZBuffer::_bufCpy( uint8_t* dst, LZPOS pos, size_t sz ) { assert( sz < LZBUFSIZE ); LZPOS begin = _wrap( pos ); LZPOS end = begin + (LZPOS)sz; if ( end > LZBUFSIZE ) { size_t left = LZBUFSIZE - begin; memcpy( dst, buf + begin, left ); memcpy( dst + left, buf, sz - left ); } else { memcpy( dst, buf + begin, sz ); } }
int b_alias(t_system *sys, t_execute *alias) { char *key; char *value; t_opt *opt; if (alias->params->length != 2) { sys->print(sys, "alias [KEY] [VALUE]\n"); return (1); } key = (char*)alias->params->at(alias->params, 0)->mem; value = (char*)alias->params->at(alias->params, 1)->mem; if (sys->isenable(sys, key)) return (st_alias(sys, key, value)); opt = new_opt(key, 1, value); sys->opts->push(sys->opts, _wrap(opt, sizeof(opt))); return (0); }
void LZBuffer::_toBuf( const uint8_t* src, size_t sz ) { assert( sz < LZBUFSIZE ); LZPOS begin = _wrap( bufPos ); LZPOS end = begin + (LZPOS)sz; if ( end > LZBUFSIZE ) { size_t left = LZBUFSIZE - begin; memcpy( buf + begin, src, left ); memcpy( buf, src + left, sz - left ); } else { memcpy( buf + begin, src, sz ); } bufPos += sz; }
static void setWireRenderStates(const Color* color) { _dxCR( dxSetRenderState( D3DRS_COLORVERTEX, FALSE ) ); _dxCR( dxSetRenderState( D3DRS_AMBIENTMATERIALSOURCE, D3DMCS_MATERIAL ) ); _dxCR( dxSetRenderState( D3DRS_EMISSIVEMATERIALSOURCE, D3DMCS_MATERIAL ) ); _dxCR( dxSetRenderState( D3DRS_SPECULARMATERIALSOURCE, D3DMCS_MATERIAL ) ); _dxCR( dxSetRenderState( D3DRS_DIFFUSEMATERIALSOURCE, D3DMCS_MATERIAL ) ); D3DMATERIAL9 material; material.Diffuse = _wrap( wrap( *color ) ); material.Ambient = material.Diffuse; material.Specular = material.Diffuse; material.Emissive = material.Diffuse; _dxCR( dxSetMaterial( &material ) ); _dxCR( dxSetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG2 ) ); _dxCR( dxSetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE ) ); _dxCR( dxSetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG2 ) ); _dxCR( dxSetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE ) ); _dxCR( dxSetTextureStageState( 1, D3DTSS_ALPHAOP, D3DTOP_DISABLE ) ); _dxCR( dxSetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_DISABLE ) ); }
void myriad_putorder(t_rt *rt, t_dispatcher *dispatcher) { int x; int y; t_pixel *pixel; y = 0; while (y < (int)rt->size_y) { x = 0; while (x < (int)rt->size_x) { pixel = new_pixel(x, y, 0xFFFFFF); pixel->x[1] = (x + 1 >= (int)rt->size_x) ? -1 : x + 1; pixel->y[1] = (x + 1 >= (int)rt->size_x) ? -1 : y; pixel->x[2] = (x + 2 >= (int)rt->size_x) ? -1 : x + 2; pixel->y[2] = (x + 2 >= (int)rt->size_x) ? -1 : y; dispatcher->orders->push(dispatcher->orders, _wrap(pixel, sizeof(t_pixel))); x += 3; } y++; } }
/*! * \brief * Calculate Equation of time sun rise, transit and set */ static void _eot_and_sun_rts(spa_t *spa, _spa_data_t *_spa_data, spa_output_t *spa_out) { _spa_data_t sun_rts = *_spa_data; spa_time_t utc_rts = spa->utc; double nu, m, h0, n; double alpha[JD_COUNT], delta[JD_COUNT]; double m_rts[SUN_COUNT], nu_rts[SUN_COUNT], h_rts[SUN_COUNT]; double alpha_prime[SUN_COUNT], delta_prime[SUN_COUNT], h_prime[SUN_COUNT]; double h0_prime = -1*(SUN_RADIUS + spa->atmos.refract); int i; m = _rts_sun_mean_lon (_spa_data->jme); sun_rts.eot = _rts_eot (m, sun_rts.alpha, sun_rts.del_psi, sun_rts.epsilon); // Clear hour and keep Date only utc_rts.hour = utc_rts.min = utc_rts.sec = 0; utc_rts.delta_ut1 = utc_rts.timezone = 0.0; sun_rts.jd = _julian_day (utc_rts); _geo_sun_ra_and_decl (utc_rts.delta_t); nu = sun_rts.nu; utc_rts.delta_t = 0; sun_rts.jd--; for (i = 0; i < JD_COUNT; i++) { _geo_sun_ra_and_decl (utc_rts.delta_t); alpha[i] = sun_rts.alpha; delta[i] = sun_rts.delta; sun_rts.jd++; } m_rts[SUN_TRANSIT] = _rts_approx_sun_transit_time (alpha[JD_ZERO], spa->loc.longitude, nu); h0 = _rts_hour_angle_at_rise_set (spa->loc.latitude, delta[JD_ZERO], h0_prime); if (h0 >= 0) { _rts_approx_rise_and_set (m_rts, h0); for (i=0; i<SUN_COUNT; ++i) { nu_rts[i] = nu + 360.985647*m_rts[i]; n = m_rts[i] + spa->utc.delta_t/86400.0; alpha_prime[i] = _rts_alpha_delta_prime (alpha, n); delta_prime[i] = _rts_alpha_delta_prime (delta, n); h_prime[i] = _wrap ((nu_rts[i] + spa->loc.longitude - alpha_prime[i]), -180, 180); h_rts[i] = _rts_sun_altitude (spa->loc.latitude, delta_prime[i], h_prime[i]); } _spa_data->srha = h_prime[SUN_RISE]; _spa_data->ssha = h_prime[SUN_SET]; _spa_data->sta = h_rts[SUN_TRANSIT]; spa_out->suntransit = _dayfrac_to_local_hr ((m_rts[SUN_TRANSIT] - h_prime[SUN_TRANSIT] / 360.0), spa->utc.timezone); spa_out->sunrise = _dayfrac_to_local_hr ( _rts_sun_rise_and_set(m_rts, h_rts, delta_prime, spa->loc.latitude, h_prime, h0_prime, SUN_RISE), spa->utc.timezone); spa_out->sunset = _dayfrac_to_local_hr ( _rts_sun_rise_and_set (m_rts, h_rts, delta_prime, spa->loc.latitude, h_prime, h0_prime, SUN_SET), spa->utc.timezone); } else { _spa_data->srha = _spa_data->ssha = _spa_data->sta = -99999; spa_out->suntransit= spa_out->sunrise= spa_out->sunset= -99999; } }
void LZBuffer::_toBuf( uint8_t c ) { buf[ _wrap( bufPos++ ) ] = c; }
void Shader::setSpecularColor(const Vector4f& value) { _materialColor.Specular = _wrap( value ); }
Vector4f Shader::getSpecularColor(void) { return _wrap( _materialColor.Specular ); }
void Shader::setDiffuseColor(const Vector4f& value) { _materialColor.Diffuse = _wrap( value ); }
Vector4f Shader::getDiffuseColor(void) { return _wrap( _materialColor.Diffuse ); }
static QUVIcode run_parse_func(_quvi_llst_node_t n, _quvi_media_t m) { static const char *f = "parse"; _quvi_lua_script_t s; _quvi_t quvi; lua_State *l; QUVIcode rc; assert(n != NULL); assert(m != NULL); quvi = m->quvi; /* seterr macro needs this. */ l = quvi->lua; s = (_quvi_lua_script_t) n->data; rc = QUVI_OK; lua_getglobal(l, f); if (!lua_isfunction(l, -1)) { freprintf(&quvi->errmsg, "%s: `%s' function not found", s->path, f); return (QUVI_LUA); } lua_newtable(l); setfield_reg_userdata(l, USERDATA_QUVI_MEDIA_T, m); setfield_s(l, "requested_format", m->quvi->format); setfield_s(l, "page_url", m->page_url); setfield_s(l, "thumbnail_url", ""); setfield_s(l, "redirect_url", ""); setfield_s(l, "start_time", ""); setfield_n(l, "duration", 0); if (lua_pcall(l, 1, 1, 0)) { freprintf(&quvi->errmsg, "%s", lua_tostring(l, -1)); return (QUVI_LUA); } if (!lua_istable(l, -1)) { freprintf(&quvi->errmsg, "expected `%s' function return a table", f); return (QUVI_LUA); } freprintf(&m->redirect_url, "%s", getfield_s(l, "redirect_url", s, f)); if (strlen(m->redirect_url) == 0) { const int r = luaL_ref(l, LUA_REGISTRYINDEX); rc = run_lua_trim_fields_func(m, r); luaL_unref(l, LUA_REGISTRYINDEX, r); if (rc == QUVI_OK) { #define _wrap(n) \ do { freprintf(&m->n, "%s", getfield_s(l, #n, s, f)); } while (0) _wrap(thumbnail_url); _wrap(start_time); _wrap(host_id); _wrap(title); _wrap(id); #undef _wrap m->duration = getfield_n(l, "duration", s, f); rc = getfield_iter_table_s(l, "url", m, s, f); } } lua_pop(l, 1); return (rc); }
QUVIcode run_ident_func(_quvi_ident_t ident, _quvi_llst_node_t node) { static const char *f = "ident"; _quvi_lua_script_t s; _quvi_t quvi; lua_State *l; QUVIcode rc; assert(ident != NULL); assert(node != NULL); quvi = ident->quvi; assert(quvi != NULL); /* seterr macro uses this. */ l = quvi->lua; assert(l != NULL); rc = QUVI_NOSUPPORT; s = (_quvi_lua_script_t) node->data; lua_pushnil(l); lua_pushnil(l); lua_setglobal(l, "ident"); lua_setglobal(l, "parse"); if (luaL_dofile(l, s->path)) { freprintf(&quvi->errmsg, "%s", lua_tostring(l, -1)); return (QUVI_LUA); } lua_getglobal(l, "ident"); if (!lua_isfunction(l, -1)) { freprintf(&quvi->errmsg, "%s: `ident' function not found", s->path); return (QUVI_LUA); } lua_newtable(l); setfield_s(l, "page_url", ident->url); { char *b = NULL; char *d = _dirname(s->path, &b); setfield_s(l, "script_dir", d); _free(b); } if (lua_pcall(l, 1, 1, 0)) { freprintf(&quvi->errmsg, "%s", lua_tostring(l, -1)); return (QUVI_LUA); } if (lua_istable(l, -1)) { #define _wrap(n) \ do { freprintf(&ident->n, "%s", getfield_s(l, #n, s, f)); } while (0) _wrap(formats); _wrap(domain); #undef _wrap ident->categories = getfield_n(l, "categories", s, f); rc = getfield_b(l, "handles", s, f) ? QUVI_OK : QUVI_NOSUPPORT; if (rc == QUVI_OK) { rc = (ident->categories & quvi->category) ? QUVI_OK : QUVI_NOSUPPORT; } } else luaL_error(l, "%s: expected `ident' to return table", s->path); lua_pop(l, 1); return (rc); }
size_t LZHLCompressor::compress( uint8_t* dst, const uint8_t* src, size_t sz ) { LZHLEncoder coder( &stat, dst ); // (unused) const uint8_t* srcBegin = src; const uint8_t* srcEnd = src + sz; LZHASH hash = 0; if ( sz >= LZMATCH ) { const uint8_t* pEnd = src + LZMATCH; for ( const uint8_t* p=src; p < pEnd ; ) { UPDATE_HASH( hash, *p++ ); } } for (;;) { ptrdiff_t srcLeft = srcEnd - src; if ( srcLeft < LZMATCH ) { if ( srcLeft ) { _toBuf( src, srcLeft ); coder.putRaw( src, srcLeft ); } break; //forever } ptrdiff_t nRaw = 0; ptrdiff_t maxRaw = std::min( srcLeft - LZMATCH, (ptrdiff_t)LZHLEncoder::maxRaw ); #ifdef LZLAZYMATCH int lazyMatchLen = 0; int lazyMatchHashPos = 0; LZPOS lazyMatchBufPos = 0; ptrdiff_t lazyMatchNRaw = 0; LZHASH lazyMatchHash = 0; bool lazyForceMatch = false; #endif for (;;) { LZHASH hash2 = HASH_POS( hash ); LZPOS hashPos = table[ hash2 ]; LZPOS wrapBufPos = _wrap( bufPos ); table[ hash2 ] = (LZTableItem)wrapBufPos; int matchLen = 0; if ( hashPos != (LZTABLEINT)(-1) && hashPos != wrapBufPos ) { int matchLimit = std::min( std::min( _distance( wrapBufPos - hashPos ), (int)(srcLeft - nRaw) ), LZMIN + LZHLEncoder::maxMatchOver ); matchLen = _nMatch( hashPos, src + nRaw, matchLimit ); #ifdef LZOVERLAP if ( _wrap( hashPos + matchLen ) == wrapBufPos ) { assert( matchLen != 0 ); ptrdiff_t xtraMatchLimit = std::min( LZMIN + (ptrdiff_t)LZHLEncoder::maxMatchOver - matchLen, srcLeft - nRaw - matchLen ); int xtraMatch; for ( xtraMatch = 0; xtraMatch < xtraMatchLimit ; ++xtraMatch ) { if ( src[ nRaw + xtraMatch ] != src[ nRaw + xtraMatch + matchLen ] ) break;//for ( xtraMatch ) } matchLen += xtraMatch; } #endif #ifdef LZBACKWARDMATCH if ( matchLen >= LZMIN - 1 )//to ensure that buf will be overwritten { int xtraMatchLimit = (int)std::min( LZMIN + LZHLEncoder::maxMatchOver - (ptrdiff_t)matchLen, nRaw ); int d = (int)_distance( bufPos - hashPos ); xtraMatchLimit = std::min( std::min( xtraMatchLimit, d - matchLen ), LZBUFSIZE - d ); int xtraMatch; for ( xtraMatch = 0; xtraMatch < xtraMatchLimit ; ++xtraMatch ) { if ( buf[ _wrap( hashPos - xtraMatch - 1 ) ] != src[ nRaw - xtraMatch - 1 ] ) break;//for ( xtraMatch ) } if ( xtraMatch > 0 ) { assert( matchLen + xtraMatch >= LZMIN ); assert( matchLen + xtraMatch <= _distance( bufPos - hashPos ) ); nRaw -= xtraMatch; bufPos -= xtraMatch; hashPos -= xtraMatch; matchLen += xtraMatch; wrapBufPos = _wrap( bufPos ); hash = _calcHash( src + nRaw ); #ifdef LZLAZYMATCH lazyForceMatch = true; #endif } } #endif } #ifdef LZLAZYMATCH if ( lazyMatchLen >= LZMIN ) { if ( matchLen > lazyMatchLen ) { coder.putMatch( src, nRaw, matchLen - LZMIN, _distance( wrapBufPos - hashPos ) ); hash = _updateTable( hash, src + nRaw, bufPos + 1, std::min( (ptrdiff_t)matchLen - 1, srcEnd - (src + nRaw + 1) - LZMATCH ) ); _toBuf( src + nRaw, matchLen ); src += nRaw + matchLen; break;//for ( nRaw ) } else { nRaw = lazyMatchNRaw; bufPos = lazyMatchBufPos; hash = lazyMatchHash; UPDATE_HASH_EX( hash, src + nRaw ); coder.putMatch( src, nRaw, lazyMatchLen - LZMIN, _distance( bufPos - lazyMatchHashPos ) ); hash = _updateTable( hash, src + nRaw + 1, bufPos + 2, std::min( (ptrdiff_t)lazyMatchLen - 2, srcEnd - (src + nRaw + 2) - LZMATCH ) ); _toBuf( src + nRaw, lazyMatchLen ); src += nRaw + lazyMatchLen; break;//for ( nRaw ) } } #endif if ( matchLen >= LZMIN ) { #ifdef LZLAZYMATCH if ( !lazyForceMatch ) { lazyMatchLen = matchLen; lazyMatchHashPos = hashPos; lazyMatchNRaw = nRaw; lazyMatchBufPos = bufPos; lazyMatchHash = hash; } else #endif { coder.putMatch( src, nRaw, matchLen - LZMIN, _distance( wrapBufPos - hashPos ) ); hash = _updateTable( hash, src + nRaw, bufPos + 1, std::min( (ptrdiff_t)matchLen - 1, srcEnd - (src + nRaw + 1) - LZMATCH ) ); _toBuf( src + nRaw, matchLen ); src += nRaw + matchLen; break;//for ( nRaw ) } } #ifdef LZLAZYMATCH assert( !lazyForceMatch ); #endif if ( nRaw + 1 > maxRaw ) { #ifdef LZLAZYMATCH if ( lazyMatchLen >= LZMIN ) { coder.putMatch( src, nRaw, lazyMatchLen - LZMIN, _distance( bufPos - lazyMatchHashPos ) ); hash = _updateTable( hash, src + nRaw, bufPos + 1, std::min( (ptrdiff_t)lazyMatchLen - 1, srcEnd - (src + nRaw + 1) - LZMATCH ) ); _toBuf( src + nRaw, lazyMatchLen ); src += nRaw + lazyMatchLen; break;//for ( nRaw ) } #endif if ( nRaw + LZMATCH >= srcLeft && srcLeft <= LZHLEncoder::maxRaw ) { _toBuf( src + nRaw, srcLeft - nRaw ); nRaw = srcLeft; } coder.putRaw( src, nRaw ); src += nRaw; break;//for ( nRaw ) } UPDATE_HASH_EX( hash, src + nRaw ); _toBuf( src[ nRaw++ ] ); }//for ( nRaw ) }//forever return coder.flush(); }
*/ #include <signal.h> #include <unistd.h> #include <stdio.h> #include <stdlib.h> #include <errno.h> #include "neptune/clust/dispatcher.h" static void send_data(t_dispatcher *this, t_socket *client) { t_metadata *meta; t_elem *data; meta = new_metadata(MR_DATA, MD_LIST); data = _wrap(meta, sizeof(t_metadata)); data->save(data, (t_io*)client); this->data->save(this->data, (t_io*)client); free(meta); delete_elem(data); } static void send_order(t_socket *s, t_list *list, t_list *lo) { t_metadata *meta; t_elem *data; t_elem *elem; list->rewind(list); while ((elem = list->next(list))) {
** ** Started on ven. mai 29 16:17:08 2015 Antoine Favarel ** Last update mer. juin 03 16:53:00 2015 Antoine Favarel */ #include <stdlib.h> #include <stdio.h> #include "neptune/clust/dispatcher.h" static void st_elem(t_dispatcher *this, t_socket *client, t_list *lo) { t_elem *respond; t_elem *akn; respond = new_elem(); akn = _wrap(new_metadata(MR_AKN, MD_DATA), sizeof(t_metadata)); if (respond->load(respond, (t_io*)client) == EXIT_FAILURE) return ; this->responds->push(this->responds, respond->dup(respond)); lo->remove(lo, lo->get(lo, respond->id)); akn->save(akn, (t_io*)client); delete_elem(akn); delete_elem(respond); } static void st_loop(t_dispatcher *this, t_socket *c, t_list *lo, t_list *r) { t_elem *tmp; r->rewind(r); while ((tmp = r->next(r)))