static void gdg(const gsl_vector *y,void *gparams,double *g,gsl_vector *dg){ struct g_params *p= (struct g_params *) gparams; size_t i; double dtmp1,dtmp2; /* dereference useful stuff */ const size_t n = p->n; const unsigned *type = p->type; const double * xmin = p->xmin; const double * xmax = p->xmax; double *x = (double *) my_alloc(sizeof(double)*n); double *dx = (double *) my_alloc(sizeof(double)*n); double *df = (double *) my_alloc(sizeof(double)*n); /* compute values of x and of dx/dy */ for(i=0;i<n;i++){ if(type==NULL){ x[i]= GET(y,i); dx[i]= 1; } else switch(type[i]){ case 0:/* (-inf,+inf) */ x[i]= GET(y,i); dx[i]= 1; break; case 1:/* [a,+inf) */ x[i]= xmin[i]+GET(y,i)*GET(y,i); dx[i]= 2.*GET(y,i); break; case 2:/* (-inf,a] */ x[i]= xmax[i]-GET(y,i)*GET(y,i); dx[i]= -2.*GET(y,i); break; case 3:/* [a,b] */ dtmp1 = sin( GET(y,i) ); x[i]= .5*(xmin[i]*(1-dtmp1) +xmax[i]*(1+dtmp1)); dx[i]= .5*(xmax[i]-xmin[i])*cos(GET(y,i)); break; case 4:/* (a,+inf) */ dtmp1 = exp( GET(y,i) ); x[i]= xmin[i]+dtmp1; dx[i]= dtmp1; break; case 5:/* (-inf,a) */ dtmp1 = -exp( GET(y,i) ); x[i]= xmax[i]+dtmp1; dx[i]= dtmp1; break; case 6:/* (a,b) */ dtmp1 = tanh( GET(y,i) ); dtmp2 = cosh( GET(y,i) ); x[i]= .5*(xmin[i]*(1-dtmp1) +xmax[i]*(1+dtmp1)); dx[i]= .5*(xmax[i]-xmin[i])/(dtmp2*dtmp2); break; case 7:/* (a,b) second approach */ dtmp1 = GET(y,i)/sqrt(1.+GET(y,i)*GET(y,i)); dtmp2 = (1.+GET(y,i)*GET(y,i))*sqrt(1.+GET(y,i)*GET(y,i)) ; x[i]= .5*(xmin[i]*(1-dtmp1) +xmax[i]*(1+dtmp1)); dx[i]= .5*(xmax[i]-xmin[i])/dtmp2; break; case 8:/* (a,+inf) second approach */ dtmp1 = GET(y,i); dtmp2 = sqrt(1.+dtmp1*dtmp1); x[i]= xmin[i] + .5*(dtmp1+dtmp2); dx[i]= .5*(dtmp1+dtmp2)/dtmp2; break; } } p->fdf(n,x,p->fparams,g,df); /* fprintf(stderr,"#gdg: f=%f x=( ",g); */ /* for(i=0;i<n;i++) */ /* fprintf(stderr,"%f ",GET(x,i)); */ /* fprintf(stderr,") dx=( "); */ /* for(i=0;i<n;i++) */ /* fprintf(stderr,"%f ",GET(dx,i)); */ /* fprintf(stderr,") df=( "); */ /* for(i=0;i<n;i++) */ /* fprintf(stderr,"%f ",GET(dg,i)); */ /* fprintf(stderr,")\n"); */ for(i=0;i<n;i++){ SET(dg,i,df[i]*dx[i]); } free (x); free (dx); free (df); }
static void gs_md5_process(gs_md5_state_t *pms, const gs_md5_byte_t *data /*[64]*/) { gs_md5_word_t a = pms->abcd[0], b = pms->abcd[1], c = pms->abcd[2], d = pms->abcd[3]; gs_md5_word_t t; #if BYTE_ORDER > 0 /* Define storage only for big-endian CPUs. */ gs_md5_word_t X[16]; #else /* Define storage for little-endian or both types of CPUs. */ gs_md5_word_t xbuf[16]; const gs_md5_word_t *X; #endif { #if BYTE_ORDER == 0 /* * Determine dynamically whether this is a big-endian or * little-endian machine, since we can use a more efficient * algorithm on the latter. */ static const int w = 1; if (*((const gs_md5_byte_t *)&w)) /* dynamic little-endian */ #endif #if BYTE_ORDER <= 0 /* little-endian */ { /* * On little-endian machines, we can process properly aligned * data without copying it. */ if (!((data - (const gs_md5_byte_t *)0) & 3)) { /* data are properly aligned */ X = (const gs_md5_word_t *)data; } else { /* not aligned */ memcpy(xbuf, data, 64); X = xbuf; } } #endif #if BYTE_ORDER == 0 else /* dynamic big-endian */ #endif #if BYTE_ORDER >= 0 /* big-endian */ { /* * On big-endian machines, we must arrange the bytes in the * right order. */ const gs_md5_byte_t *xp = data; int i; # if BYTE_ORDER == 0 X = xbuf; /* (dynamic only) */ # else # define xbuf X /* (static only) */ # endif for (i = 0; i < 16; ++i, xp += 4) xbuf[i] = xp[0] + (xp[1] << 8) + (xp[2] << 16) + (xp[3] << 24); } #endif } #define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32 - (n)))) /* Round 1. */ /* Let [abcd k s i] denote the operation a = b + ((a + F(b,c,d) + X[k] + T[i]) <<< s). */ #define F(x, y, z) (((x) & (y)) | (~(x) & (z))) #define SET(a, b, c, d, k, s, Ti)\ t = a + F(b,c,d) + X[k] + Ti;\ a = ROTATE_LEFT(t, s) + b /* Do the following 16 operations. */ SET(a, b, c, d, 0, 7, T1); SET(d, a, b, c, 1, 12, T2); SET(c, d, a, b, 2, 17, T3); SET(b, c, d, a, 3, 22, T4); SET(a, b, c, d, 4, 7, T5); SET(d, a, b, c, 5, 12, T6); SET(c, d, a, b, 6, 17, T7); SET(b, c, d, a, 7, 22, T8); SET(a, b, c, d, 8, 7, T9); SET(d, a, b, c, 9, 12, T10); SET(c, d, a, b, 10, 17, T11); SET(b, c, d, a, 11, 22, T12); SET(a, b, c, d, 12, 7, T13); SET(d, a, b, c, 13, 12, T14); SET(c, d, a, b, 14, 17, T15); SET(b, c, d, a, 15, 22, T16); #undef SET /* Round 2. */ /* Let [abcd k s i] denote the operation a = b + ((a + G(b,c,d) + X[k] + T[i]) <<< s). */ #define G(x, y, z) (((x) & (z)) | ((y) & ~(z))) #define SET(a, b, c, d, k, s, Ti)\ t = a + G(b,c,d) + X[k] + Ti;\ a = ROTATE_LEFT(t, s) + b /* Do the following 16 operations. */ SET(a, b, c, d, 1, 5, T17); SET(d, a, b, c, 6, 9, T18); SET(c, d, a, b, 11, 14, T19); SET(b, c, d, a, 0, 20, T20); SET(a, b, c, d, 5, 5, T21); SET(d, a, b, c, 10, 9, T22); SET(c, d, a, b, 15, 14, T23); SET(b, c, d, a, 4, 20, T24); SET(a, b, c, d, 9, 5, T25); SET(d, a, b, c, 14, 9, T26); SET(c, d, a, b, 3, 14, T27); SET(b, c, d, a, 8, 20, T28); SET(a, b, c, d, 13, 5, T29); SET(d, a, b, c, 2, 9, T30); SET(c, d, a, b, 7, 14, T31); SET(b, c, d, a, 12, 20, T32); #undef SET /* Round 3. */ /* Let [abcd k s t] denote the operation a = b + ((a + H(b,c,d) + X[k] + T[i]) <<< s). */ #define H(x, y, z) ((x) ^ (y) ^ (z)) #define SET(a, b, c, d, k, s, Ti)\ t = a + H(b,c,d) + X[k] + Ti;\ a = ROTATE_LEFT(t, s) + b /* Do the following 16 operations. */ SET(a, b, c, d, 5, 4, T33); SET(d, a, b, c, 8, 11, T34); SET(c, d, a, b, 11, 16, T35); SET(b, c, d, a, 14, 23, T36); SET(a, b, c, d, 1, 4, T37); SET(d, a, b, c, 4, 11, T38); SET(c, d, a, b, 7, 16, T39); SET(b, c, d, a, 10, 23, T40); SET(a, b, c, d, 13, 4, T41); SET(d, a, b, c, 0, 11, T42); SET(c, d, a, b, 3, 16, T43); SET(b, c, d, a, 6, 23, T44); SET(a, b, c, d, 9, 4, T45); SET(d, a, b, c, 12, 11, T46); SET(c, d, a, b, 15, 16, T47); SET(b, c, d, a, 2, 23, T48); #undef SET /* Round 4. */ /* Let [abcd k s t] denote the operation a = b + ((a + I(b,c,d) + X[k] + T[i]) <<< s). */ #define I(x, y, z) ((y) ^ ((x) | ~(z))) #define SET(a, b, c, d, k, s, Ti)\ t = a + I(b,c,d) + X[k] + Ti;\ a = ROTATE_LEFT(t, s) + b /* Do the following 16 operations. */ SET(a, b, c, d, 0, 6, T49); SET(d, a, b, c, 7, 10, T50); SET(c, d, a, b, 14, 15, T51); SET(b, c, d, a, 5, 21, T52); SET(a, b, c, d, 12, 6, T53); SET(d, a, b, c, 3, 10, T54); SET(c, d, a, b, 10, 15, T55); SET(b, c, d, a, 1, 21, T56); SET(a, b, c, d, 8, 6, T57); SET(d, a, b, c, 15, 10, T58); SET(c, d, a, b, 6, 15, T59); SET(b, c, d, a, 13, 21, T60); SET(a, b, c, d, 4, 6, T61); SET(d, a, b, c, 11, 10, T62); SET(c, d, a, b, 2, 15, T63); SET(b, c, d, a, 9, 21, T64); #undef SET /* Then perform the following additions. (That is increment each of the four registers by the value it had before this block was started.) */ pms->abcd[0] += a; pms->abcd[1] += b; pms->abcd[2] += c; pms->abcd[3] += d; }
static void dint(tms32010_state *cpustate) { SET(cpustate, INTM_FLAG); }
bool sTrimeshBoxColliderData::_cldTestSeparatingAxes(const dVector3 &v0, const dVector3 &v1, const dVector3 &v2) { // reset best axis m_iBestAxis = 0; m_iExitAxis = -1; m_fBestDepth = MAXVALUE; // calculate edges SUBTRACT(v1,v0,m_vE0); SUBTRACT(v2,v0,m_vE1); SUBTRACT(m_vE1,m_vE0,m_vE2); // calculate poly normal dCROSS(m_vN,=,m_vE0,m_vE1); // calculate length of face normal dReal fNLen = LENGTHOF(m_vN); // Even though all triangles might be initially valid, // a triangle may degenerate into a segment after applying // space transformation. if (!fNLen) { return false; } // extract box axes as vectors dVector3 vA0,vA1,vA2; GETCOL(m_mHullBoxRot,0,vA0); GETCOL(m_mHullBoxRot,1,vA1); GETCOL(m_mHullBoxRot,2,vA2); // box halfsizes dReal fa0 = m_vBoxHalfSize[0]; dReal fa1 = m_vBoxHalfSize[1]; dReal fa2 = m_vBoxHalfSize[2]; // calculate relative position between box and triangle dVector3 vD; SUBTRACT(v0,m_vHullBoxPos,vD); dVector3 vL; dReal fp0, fp1, fp2, fR, fD; // Test separating axes for intersection // ************************************************ // Axis 1 - Triangle Normal SET(vL,m_vN); fp0 = dDOT(vL,vD); fp1 = fp0; fp2 = fp0; fR=fa0*dFabs( dDOT(m_vN,vA0) ) + fa1 * dFabs( dDOT(m_vN,vA1) ) + fa2 * dFabs( dDOT(m_vN,vA2) ); if (!_cldTestNormal(fp0, fR, vL, 1)) { m_iExitAxis=1; return false; } // ************************************************ // Test Faces // ************************************************ // Axis 2 - Box X-Axis SET(vL,vA0); fD = dDOT(vL,m_vN)/fNLen; fp0 = dDOT(vL,vD); fp1 = fp0 + dDOT(vA0,m_vE0); fp2 = fp0 + dDOT(vA0,m_vE1); fR = fa0; if (!_cldTestFace(fp0, fp1, fp2, fR, fD, vL, 2)) { m_iExitAxis=2; return false; } // ************************************************ // ************************************************ // Axis 3 - Box Y-Axis SET(vL,vA1); fD = dDOT(vL,m_vN)/fNLen; fp0 = dDOT(vL,vD); fp1 = fp0 + dDOT(vA1,m_vE0); fp2 = fp0 + dDOT(vA1,m_vE1); fR = fa1; if (!_cldTestFace(fp0, fp1, fp2, fR, fD, vL, 3)) { m_iExitAxis=3; return false; } // ************************************************ // ************************************************ // Axis 4 - Box Z-Axis SET(vL,vA2); fD = dDOT(vL,m_vN)/fNLen; fp0 = dDOT(vL,vD); fp1 = fp0 + dDOT(vA2,m_vE0); fp2 = fp0 + dDOT(vA2,m_vE1); fR = fa2; if (!_cldTestFace(fp0, fp1, fp2, fR, fD, vL, 4)) { m_iExitAxis=4; return false; } // ************************************************ // Test Edges // ************************************************ // Axis 5 - Box X-Axis cross Edge0 dCROSS(vL,=,vA0,m_vE0); fD = dDOT(vL,m_vN)/fNLen; fp0 = dDOT(vL,vD); fp1 = fp0; fp2 = fp0 + dDOT(vA0,m_vN); fR = fa1 * dFabs(dDOT(vA2,m_vE0)) + fa2 * dFabs(dDOT(vA1,m_vE0)); if (!_cldTestEdge(fp1, fp2, fR, fD, vL, 5)) { m_iExitAxis=5; return false; } // ************************************************ // ************************************************ // Axis 6 - Box X-Axis cross Edge1 dCROSS(vL,=,vA0,m_vE1); fD = dDOT(vL,m_vN)/fNLen; fp0 = dDOT(vL,vD); fp1 = fp0 - dDOT(vA0,m_vN); fp2 = fp0; fR = fa1 * dFabs(dDOT(vA2,m_vE1)) + fa2 * dFabs(dDOT(vA1,m_vE1)); if (!_cldTestEdge(fp0, fp1, fR, fD, vL, 6)) { m_iExitAxis=6; return false; } // ************************************************ // ************************************************ // Axis 7 - Box X-Axis cross Edge2 dCROSS(vL,=,vA0,m_vE2); fD = dDOT(vL,m_vN)/fNLen; fp0 = dDOT(vL,vD); fp1 = fp0 - dDOT(vA0,m_vN); fp2 = fp0 - dDOT(vA0,m_vN); fR = fa1 * dFabs(dDOT(vA2,m_vE2)) + fa2 * dFabs(dDOT(vA1,m_vE2)); if (!_cldTestEdge(fp0, fp1, fR, fD, vL, 7)) { m_iExitAxis=7; return false; } // ************************************************ // ************************************************ // Axis 8 - Box Y-Axis cross Edge0 dCROSS(vL,=,vA1,m_vE0); fD = dDOT(vL,m_vN)/fNLen; fp0 = dDOT(vL,vD); fp1 = fp0; fp2 = fp0 + dDOT(vA1,m_vN); fR = fa0 * dFabs(dDOT(vA2,m_vE0)) + fa2 * dFabs(dDOT(vA0,m_vE0)); if (!_cldTestEdge(fp0, fp2, fR, fD, vL, 8)) { m_iExitAxis=8; return false; } // ************************************************ // ************************************************ // Axis 9 - Box Y-Axis cross Edge1 dCROSS(vL,=,vA1,m_vE1); fD = dDOT(vL,m_vN)/fNLen; fp0 = dDOT(vL,vD); fp1 = fp0 - dDOT(vA1,m_vN); fp2 = fp0; fR = fa0 * dFabs(dDOT(vA2,m_vE1)) + fa2 * dFabs(dDOT(vA0,m_vE1)); if (!_cldTestEdge(fp0, fp1, fR, fD, vL, 9)) { m_iExitAxis=9; return false; } // ************************************************ // ************************************************ // Axis 10 - Box Y-Axis cross Edge2 dCROSS(vL,=,vA1,m_vE2); fD = dDOT(vL,m_vN)/fNLen; fp0 = dDOT(vL,vD); fp1 = fp0 - dDOT(vA1,m_vN); fp2 = fp0 - dDOT(vA1,m_vN); fR = fa0 * dFabs(dDOT(vA2,m_vE2)) + fa2 * dFabs(dDOT(vA0,m_vE2)); if (!_cldTestEdge(fp0, fp1, fR, fD, vL, 10)) { m_iExitAxis=10; return false; } // ************************************************ // ************************************************ // Axis 11 - Box Z-Axis cross Edge0 dCROSS(vL,=,vA2,m_vE0); fD = dDOT(vL,m_vN)/fNLen; fp0 = dDOT(vL,vD); fp1 = fp0; fp2 = fp0 + dDOT(vA2,m_vN); fR = fa0 * dFabs(dDOT(vA1,m_vE0)) + fa1 * dFabs(dDOT(vA0,m_vE0)); if (!_cldTestEdge(fp0, fp2, fR, fD, vL, 11)) { m_iExitAxis=11; return false; } // ************************************************ // ************************************************ // Axis 12 - Box Z-Axis cross Edge1 dCROSS(vL,=,vA2,m_vE1); fD = dDOT(vL,m_vN)/fNLen; fp0 = dDOT(vL,vD); fp1 = fp0 - dDOT(vA2,m_vN); fp2 = fp0; fR = fa0 * dFabs(dDOT(vA1,m_vE1)) + fa1 * dFabs(dDOT(vA0,m_vE1)); if (!_cldTestEdge(fp0, fp1, fR, fD, vL, 12)) { m_iExitAxis=12; return false; } // ************************************************ // ************************************************ // Axis 13 - Box Z-Axis cross Edge2 dCROSS(vL,=,vA2,m_vE2); fD = dDOT(vL,m_vN)/fNLen; fp0 = dDOT(vL,vD); fp1 = fp0 - dDOT(vA2,m_vN); fp2 = fp0 - dDOT(vA2,m_vN); fR = fa0 * dFabs(dDOT(vA1,m_vE2)) + fa1 * dFabs(dDOT(vA0,m_vE2)); if (!_cldTestEdge(fp0, fp1, fR, fD, vL, 13)) { m_iExitAxis=13; return false; } // ************************************************ return true; }
static void md5_process(md5_state_t *pms, const md5_byte_t *data /*[64]*/) { md5_word_t a = pms->abcd[0], b = pms->abcd[1], c = pms->abcd[2], d = pms->abcd[3]; md5_word_t t; #ifndef ARCH_IS_BIG_ENDIAN # define ARCH_IS_BIG_ENDIAN 1 /* slower, default implementation */ #endif #if ARCH_IS_BIG_ENDIAN /* * On big-endian machines, we must arrange the bytes in the right * order. (This also works on machines of unknown byte order.) */ md5_word_t X[16]; const md5_byte_t *xp = data; int i; for (i = 0; i < 16; ++i, xp += 4) X[i] = xp[0] + (xp[1] << 8) + (xp[2] << 16) + (xp[3] << 24); #else /* !ARCH_IS_BIG_ENDIAN */ /* * On little-endian machines, we can process properly aligned data * without copying it. */ md5_word_t xbuf[16]; const md5_word_t *X; if (!((data - (const md5_byte_t *)0) & 3)) { /* data are properly aligned */ X = (const md5_word_t *)data; } else { /* not aligned */ memcpy(xbuf, data, 64); X = xbuf; } #endif #define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32 - (n)))) /* Round 1. */ /* Let [abcd k s i] denote the operation a = b + ((a + F(b,c,d) + X[k] + T[i]) <<< s). */ #define F(x, y, z) (((x) & (y)) | (~(x) & (z))) #define SET(a, b, c, d, k, s, Ti)\ t = a + F(b,c,d) + X[k] + Ti;\ a = ROTATE_LEFT(t, s) + b /* Do the following 16 operations. */ SET(a, b, c, d, 0, 7, T1); SET(d, a, b, c, 1, 12, T2); SET(c, d, a, b, 2, 17, T3); SET(b, c, d, a, 3, 22, T4); SET(a, b, c, d, 4, 7, T5); SET(d, a, b, c, 5, 12, T6); SET(c, d, a, b, 6, 17, T7); SET(b, c, d, a, 7, 22, T8); SET(a, b, c, d, 8, 7, T9); SET(d, a, b, c, 9, 12, T10); SET(c, d, a, b, 10, 17, T11); SET(b, c, d, a, 11, 22, T12); SET(a, b, c, d, 12, 7, T13); SET(d, a, b, c, 13, 12, T14); SET(c, d, a, b, 14, 17, T15); SET(b, c, d, a, 15, 22, T16); #undef SET /* Round 2. */ /* Let [abcd k s i] denote the operation a = b + ((a + G(b,c,d) + X[k] + T[i]) <<< s). */ #define G(x, y, z) (((x) & (z)) | ((y) & ~(z))) #define SET(a, b, c, d, k, s, Ti)\ t = a + G(b,c,d) + X[k] + Ti;\ a = ROTATE_LEFT(t, s) + b /* Do the following 16 operations. */ SET(a, b, c, d, 1, 5, T17); SET(d, a, b, c, 6, 9, T18); SET(c, d, a, b, 11, 14, T19); SET(b, c, d, a, 0, 20, T20); SET(a, b, c, d, 5, 5, T21); SET(d, a, b, c, 10, 9, T22); SET(c, d, a, b, 15, 14, T23); SET(b, c, d, a, 4, 20, T24); SET(a, b, c, d, 9, 5, T25); SET(d, a, b, c, 14, 9, T26); SET(c, d, a, b, 3, 14, T27); SET(b, c, d, a, 8, 20, T28); SET(a, b, c, d, 13, 5, T29); SET(d, a, b, c, 2, 9, T30); SET(c, d, a, b, 7, 14, T31); SET(b, c, d, a, 12, 20, T32); #undef SET /* Round 3. */ /* Let [abcd k s t] denote the operation a = b + ((a + H(b,c,d) + X[k] + T[i]) <<< s). */ #define H(x, y, z) ((x) ^ (y) ^ (z)) #define SET(a, b, c, d, k, s, Ti)\ t = a + H(b,c,d) + X[k] + Ti;\ a = ROTATE_LEFT(t, s) + b /* Do the following 16 operations. */ SET(a, b, c, d, 5, 4, T33); SET(d, a, b, c, 8, 11, T34); SET(c, d, a, b, 11, 16, T35); SET(b, c, d, a, 14, 23, T36); SET(a, b, c, d, 1, 4, T37); SET(d, a, b, c, 4, 11, T38); SET(c, d, a, b, 7, 16, T39); SET(b, c, d, a, 10, 23, T40); SET(a, b, c, d, 13, 4, T41); SET(d, a, b, c, 0, 11, T42); SET(c, d, a, b, 3, 16, T43); SET(b, c, d, a, 6, 23, T44); SET(a, b, c, d, 9, 4, T45); SET(d, a, b, c, 12, 11, T46); SET(c, d, a, b, 15, 16, T47); SET(b, c, d, a, 2, 23, T48); #undef SET /* Round 4. */ /* Let [abcd k s t] denote the operation a = b + ((a + I(b,c,d) + X[k] + T[i]) <<< s). */ #define I(x, y, z) ((y) ^ ((x) | ~(z))) #define SET(a, b, c, d, k, s, Ti)\ t = a + I(b,c,d) + X[k] + Ti;\ a = ROTATE_LEFT(t, s) + b /* Do the following 16 operations. */ SET(a, b, c, d, 0, 6, T49); SET(d, a, b, c, 7, 10, T50); SET(c, d, a, b, 14, 15, T51); SET(b, c, d, a, 5, 21, T52); SET(a, b, c, d, 12, 6, T53); SET(d, a, b, c, 3, 10, T54); SET(c, d, a, b, 10, 15, T55); SET(b, c, d, a, 1, 21, T56); SET(a, b, c, d, 8, 6, T57); SET(d, a, b, c, 15, 10, T58); SET(c, d, a, b, 6, 15, T59); SET(b, c, d, a, 13, 21, T60); SET(a, b, c, d, 4, 6, T61); SET(d, a, b, c, 11, 10, T62); SET(c, d, a, b, 2, 15, T63); SET(b, c, d, a, 9, 21, T64); #undef SET /* Then perform the following additions. (That is increment each of the four registers by the value it had before this block was started.) */ pms->abcd[0] += a; pms->abcd[1] += b; pms->abcd[2] += c; pms->abcd[3] += d; }
void pic16c62x_device::pic16c62x_soft_reset() { SET(STATUS, (TO_FLAG | PD_FLAG | Z_FLAG | DC_FLAG | C_FLAG)); pic16c62x_reset_regs(); }
void pic16c62x_device::clrw() { m_W = 0; SET(STATUS, Z_FLAG); }
// ---------------------------------------------------------------------------- uint8_t mcp2515_send_message(tCAN *message) { uint8_t status = mcp2515_read_status(SPI_READ_STATUS); /* Statusbyte: * * Bit Function * 2 TXB0CNTRL.TXREQ * 4 TXB1CNTRL.TXREQ * 6 TXB2CNTRL.TXREQ */ uint8_t address; uint8_t t; // SET(LED2_HIGH); if (bit_is_clear(status, 2)) { address = 0x00; } else if (bit_is_clear(status, 4)) { address = 0x02; } else if (bit_is_clear(status, 6)) { address = 0x04; } else { // all buffer used => could not send message return 0; } RESET(MCP2515_CS); spi_putc(SPI_WRITE_TX | address); spi_putc(message->id >> 3); spi_putc(message->id << 5); spi_putc(0); spi_putc(0); uint8_t length = message->header.length & 0x0f; if (message->header.rtr) { // a rtr-frame has a length, but contains no data spi_putc((1<<RTR) | length); } else { // set message length spi_putc(length); // data for (t=0;t<length;t++) { spi_putc(message->data[t]); } } SET(MCP2515_CS); _delay_us(1); // send message RESET(MCP2515_CS); address = (address == 0) ? 1 : address; spi_putc(SPI_RTS | address); SET(MCP2515_CS); return address; }
// test one mesh triangle on intersection with capsule void sTrimeshCapsuleColliderData::_cldTestOneTriangleVSCapsule( const dVector3 &v0, const dVector3 &v1, const dVector3 &v2, uint8 flags) { // calculate edges SUBTRACT(v1,v0,m_vE0); SUBTRACT(v2,v1,m_vE1); SUBTRACT(v0,v2,m_vE2); dVector3 _minus_vE0; SUBTRACT(v0,v1,_minus_vE0); // calculate poly normal dCalcVectorCross3(m_vN,m_vE1,_minus_vE0); // Even though all triangles might be initially valid, // a triangle may degenerate into a segment after applying // space transformation. if (!dSafeNormalize3(m_vN)) { return; } // create plane from triangle dReal plDistance = -dCalcVectorDot3(v0,m_vN); dVector4 plTrianglePlane; CONSTRUCTPLANE(plTrianglePlane,m_vN,plDistance); // calculate capsule distance to plane dReal fDistanceCapsuleCenterToPlane = POINTDISTANCE(plTrianglePlane,m_vCapsulePosition); // Capsule must be over positive side of triangle if (fDistanceCapsuleCenterToPlane < 0 /* && !bDoubleSided*/) { // if not don't generate contacts return; } dVector3 vPnt0; SET (vPnt0,v0); dVector3 vPnt1; SET (vPnt1,v1); dVector3 vPnt2; SET (vPnt2,v2); if (fDistanceCapsuleCenterToPlane < 0 ) { SET (vPnt0,v0); SET (vPnt1,v2); SET (vPnt2,v1); } // do intersection test and find best separating axis if (!_cldTestSeparatingAxesOfCapsule(vPnt0, vPnt1, vPnt2, flags)) { // if not found do nothing return; } // if best separation axis is not found if (m_iBestAxis == 0 ) { // this should not happen (we should already exit in that case) dIASSERT(FALSE); // do nothing return; } // calculate caps centers in absolute space dVector3 vCposTrans; vCposTrans[0] = m_vCapsulePosition[0] + m_vNormal[0]*m_vCapsuleRadius; vCposTrans[1] = m_vCapsulePosition[1] + m_vNormal[1]*m_vCapsuleRadius; vCposTrans[2] = m_vCapsulePosition[2] + m_vNormal[2]*m_vCapsuleRadius; dVector3 vCEdgePoint0; vCEdgePoint0[0] = vCposTrans[0] + m_vCapsuleAxis[0]*(m_fCapsuleSize*REAL(0.5)-m_vCapsuleRadius); vCEdgePoint0[1] = vCposTrans[1] + m_vCapsuleAxis[1]*(m_fCapsuleSize*REAL(0.5)-m_vCapsuleRadius); vCEdgePoint0[2] = vCposTrans[2] + m_vCapsuleAxis[2]*(m_fCapsuleSize*REAL(0.5)-m_vCapsuleRadius); dVector3 vCEdgePoint1; vCEdgePoint1[0] = vCposTrans[0] - m_vCapsuleAxis[0]*(m_fCapsuleSize*REAL(0.5)-m_vCapsuleRadius); vCEdgePoint1[1] = vCposTrans[1] - m_vCapsuleAxis[1]*(m_fCapsuleSize*REAL(0.5)-m_vCapsuleRadius); vCEdgePoint1[2] = vCposTrans[2] - m_vCapsuleAxis[2]*(m_fCapsuleSize*REAL(0.5)-m_vCapsuleRadius); // transform capsule edge points into triangle space vCEdgePoint0[0] -= vPnt0[0]; vCEdgePoint0[1] -= vPnt0[1]; vCEdgePoint0[2] -= vPnt0[2]; vCEdgePoint1[0] -= vPnt0[0]; vCEdgePoint1[1] -= vPnt0[1]; vCEdgePoint1[2] -= vPnt0[2]; dVector4 plPlane; dVector3 _minus_vN; _minus_vN[0] = -m_vN[0]; _minus_vN[1] = -m_vN[1]; _minus_vN[2] = -m_vN[2]; // triangle plane CONSTRUCTPLANE(plPlane,_minus_vN,0); //plPlane = Plane4f( -m_vN, 0); if (!_cldClipEdgeToPlane( vCEdgePoint0, vCEdgePoint1, plPlane )) { return; } // plane with edge 0 dVector3 vTemp; dCalcVectorCross3(vTemp,m_vN,m_vE0); CONSTRUCTPLANE(plPlane, vTemp, REAL(1e-5)); if (!_cldClipEdgeToPlane( vCEdgePoint0, vCEdgePoint1, plPlane )) { return; } dCalcVectorCross3(vTemp,m_vN,m_vE1); CONSTRUCTPLANE(plPlane, vTemp, -(dCalcVectorDot3(m_vE0,vTemp)-REAL(1e-5))); if (!_cldClipEdgeToPlane( vCEdgePoint0, vCEdgePoint1, plPlane )) { return; } dCalcVectorCross3(vTemp,m_vN,m_vE2); CONSTRUCTPLANE(plPlane, vTemp, REAL(1e-5)); if (!_cldClipEdgeToPlane( vCEdgePoint0, vCEdgePoint1, plPlane )) { return; } // return capsule edge points into absolute space vCEdgePoint0[0] += vPnt0[0]; vCEdgePoint0[1] += vPnt0[1]; vCEdgePoint0[2] += vPnt0[2]; vCEdgePoint1[0] += vPnt0[0]; vCEdgePoint1[1] += vPnt0[1]; vCEdgePoint1[2] += vPnt0[2]; // calculate depths for both contact points SUBTRACT(vCEdgePoint0,m_vCapsulePosition,vTemp); dReal fDepth0 = dCalcVectorDot3(vTemp,m_vNormal) - (m_fBestCenter-m_fBestrt); SUBTRACT(vCEdgePoint1,m_vCapsulePosition,vTemp); dReal fDepth1 = dCalcVectorDot3(vTemp,m_vNormal) - (m_fBestCenter-m_fBestrt); // clamp depths to zero if (fDepth0 < 0) { fDepth0 = 0.0f; } if (fDepth1 < 0 ) { fDepth1 = 0.0f; } // Cached contacts's data // contact 0 dIASSERT(m_ctContacts < (m_iFlags & NUMC_MASK)); // Do not call function if there is no room to store result m_gLocalContacts[m_ctContacts].fDepth = fDepth0; SET(m_gLocalContacts[m_ctContacts].vNormal,m_vNormal); SET(m_gLocalContacts[m_ctContacts].vPos,vCEdgePoint0); m_gLocalContacts[m_ctContacts].nFlags = 1; m_ctContacts++; if (m_ctContacts < (m_iFlags & NUMC_MASK)) { // contact 1 m_gLocalContacts[m_ctContacts].fDepth = fDepth1; SET(m_gLocalContacts[m_ctContacts].vNormal,m_vNormal); SET(m_gLocalContacts[m_ctContacts].vPos,vCEdgePoint1); m_gLocalContacts[m_ctContacts].nFlags = 1; m_ctContacts++; } }
void set_flags(int n) { tcflag_t iflag, oflag, cflag, lflag; switch (n) { case 0: if (C0set && I0set && L0set && O0set) { tmode.c_cflag = C0; tmode.c_iflag = I0; tmode.c_lflag = L0; tmode.c_oflag = O0; return; } break; case 1: if (C1set && I1set && L1set && O1set) { tmode.c_cflag = C1; tmode.c_iflag = I1; tmode.c_lflag = L1; tmode.c_oflag = O1; return; } break; default: if (C2set && I2set && L2set && O2set) { tmode.c_cflag = C2; tmode.c_iflag = I2; tmode.c_lflag = L2; tmode.c_oflag = O2; return; } break; } iflag = omode.c_iflag; oflag = omode.c_oflag; cflag = omode.c_cflag; lflag = omode.c_lflag; if (NP) { CLR(cflag, CSIZE|PARENB); SET(cflag, CS8); CLR(iflag, ISTRIP|INPCK|IGNPAR); } else if (AP || EP || OP) { CLR(cflag, CSIZE); SET(cflag, CS7|PARENB); SET(iflag, ISTRIP); if (OP && !EP) { SET(iflag, INPCK|IGNPAR); SET(cflag, PARODD); if (AP) CLR(iflag, INPCK); } else if (EP && !OP) { SET(iflag, INPCK|IGNPAR); CLR(cflag, PARODD); if (AP) CLR(iflag, INPCK); } else if (AP || (EP && OP)) { CLR(iflag, INPCK|IGNPAR); CLR(cflag, PARODD); } } /* else, leave as is */ #if 0 if (UC) f |= LCASE; #endif if (HC) SET(cflag, HUPCL); else CLR(cflag, HUPCL); if (MB) SET(cflag, MDMBUF); else CLR(cflag, MDMBUF); if (HW) SET(cflag, CRTSCTS); else CLR(cflag, CRTSCTS); if (NL) { SET(iflag, ICRNL); SET(oflag, ONLCR|OPOST); } else { CLR(iflag, ICRNL); CLR(oflag, ONLCR); } if (!HT) SET(oflag, OXTABS|OPOST); else CLR(oflag, OXTABS); #ifdef XXX_DELAY SET(f, delaybits()); #endif if (n == 1) { /* read mode flags */ if (RW) { iflag = 0; CLR(oflag, OPOST); CLR(cflag, CSIZE|PARENB); SET(cflag, CS8); lflag = 0; } else { CLR(lflag, ICANON); } goto out; } if (n == 0) goto out; #if 0 if (CB) SET(f, CRTBS); #endif if (CE) SET(lflag, ECHOE); else CLR(lflag, ECHOE); if (CK) SET(lflag, ECHOKE); else CLR(lflag, ECHOKE); if (PE) SET(lflag, ECHOPRT); else CLR(lflag, ECHOPRT); if (EC) SET(lflag, ECHO); else CLR(lflag, ECHO); if (XC) SET(lflag, ECHOCTL); else CLR(lflag, ECHOCTL); if (DX) SET(lflag, IXANY); else CLR(lflag, IXANY); out: tmode.c_iflag = iflag; tmode.c_oflag = oflag; tmode.c_cflag = cflag; tmode.c_lflag = lflag; }
// ------------------------------------------------------------------------- uint8_t mcp2515_init(uint8_t speed) { SET(MCP2515_CS); SET_OUTPUT(MCP2515_CS); RESET(P_SCK); RESET(P_MOSI); RESET(P_MISO); SET_OUTPUT(P_SCK); SET_OUTPUT(P_MOSI); SET_INPUT(P_MISO); SET_INPUT(MCP2515_INT); SET(MCP2515_INT); // active SPI master interface SPCR = (1<<SPE)|(1<<MSTR) | (0<<SPR1)|(1<<SPR0); SPSR = 0; // reset MCP2515 by software reset. // After this he is in configuration mode. RESET(MCP2515_CS); spi_putc(SPI_RESET); SET(MCP2515_CS); // wait a little bit until the MCP2515 has restarted _delay_us(10); // load CNF1..3 Register RESET(MCP2515_CS); spi_putc(SPI_WRITE); spi_putc(CNF3); /* spi_putc((1<<PHSEG21)); // Bitrate 125 kbps at 16 MHz spi_putc((1<<BTLMODE)|(1<<PHSEG11)); spi_putc((1<<BRP2)|(1<<BRP1)|(1<<BRP0)); */ /* spi_putc((1<<PHSEG21)); // Bitrate 250 kbps at 16 MHz spi_putc((1<<BTLMODE)|(1<<PHSEG11)); spi_putc((1<<BRP1)|(1<<BRP0)); */ spi_putc((1<<PHSEG21)); // Bitrate 250 kbps at 16 MHz spi_putc((1<<BTLMODE)|(1<<PHSEG11)); //spi_putc(1<<BRP0); spi_putc(speed); // activate interrupts spi_putc((1<<RX1IE)|(1<<RX0IE)); SET(MCP2515_CS); // test if we could read back the value => is the chip accessible? if (mcp2515_read_register(CNF1) != speed) { SET(LED2_HIGH); return false; } // deaktivate the RXnBF Pins (High Impedance State) mcp2515_write_register(BFPCTRL, 0); // set TXnRTS as inputs mcp2515_write_register(TXRTSCTRL, 0); // turn off filters => receive any message mcp2515_write_register(RXB0CTRL, (1<<RXM1)|(1<<RXM0)); mcp2515_write_register(RXB1CTRL, (1<<RXM1)|(1<<RXM0)); // reset device to normal mode mcp2515_write_register(CANCTRL, 0); // SET(LED2_HIGH); return true; }
/* * Old TTY => termios, snatched from <sys/kern/tty_compat.c> */ void compatflags(long flags) { tcflag_t iflag, oflag, cflag, lflag; iflag = BRKINT|ICRNL|IMAXBEL|IXON|IXANY; oflag = OPOST|ONLCR|OXTABS; cflag = CREAD; lflag = ICANON|ISIG|IEXTEN; if (ISSET(flags, TANDEM)) SET(iflag, IXOFF); else CLR(iflag, IXOFF); if (ISSET(flags, ECHO)) SET(lflag, ECHO); else CLR(lflag, ECHO); if (ISSET(flags, CRMOD)) { SET(iflag, ICRNL); SET(oflag, ONLCR); } else { CLR(iflag, ICRNL); CLR(oflag, ONLCR); } if (ISSET(flags, XTABS)) SET(oflag, OXTABS); else CLR(oflag, OXTABS); if (ISSET(flags, RAW)) { iflag &= IXOFF; CLR(lflag, ISIG|ICANON|IEXTEN); CLR(cflag, PARENB); } else { SET(iflag, BRKINT|IXON|IMAXBEL); SET(lflag, ISIG|IEXTEN); if (ISSET(flags, CBREAK)) CLR(lflag, ICANON); else SET(lflag, ICANON); switch (ISSET(flags, ANYP)) { case 0: CLR(cflag, PARENB); break; case ANYP: SET(cflag, PARENB); CLR(iflag, INPCK); break; case EVENP: SET(cflag, PARENB); SET(iflag, INPCK); CLR(cflag, PARODD); break; case ODDP: SET(cflag, PARENB); SET(iflag, INPCK); SET(cflag, PARODD); break; } } /* Nothing we can do with CRTBS. */ if (ISSET(flags, PRTERA)) SET(lflag, ECHOPRT); else CLR(lflag, ECHOPRT); if (ISSET(flags, CRTERA)) SET(lflag, ECHOE); else CLR(lflag, ECHOE); /* Nothing we can do with TILDE. */ if (ISSET(flags, MDMBUF)) SET(cflag, MDMBUF); else CLR(cflag, MDMBUF); if (ISSET(flags, NOHANG)) CLR(cflag, HUPCL); else SET(cflag, HUPCL); if (ISSET(flags, CRTKIL)) SET(lflag, ECHOKE); else CLR(lflag, ECHOKE); if (ISSET(flags, CTLECH)) SET(lflag, ECHOCTL); else CLR(lflag, ECHOCTL); if (!ISSET(flags, DECCTQ)) SET(iflag, IXANY); else CLR(iflag, IXANY); CLR(lflag, TOSTOP|FLUSHO|PENDIN|NOFLSH); SET(lflag, ISSET(flags, TOSTOP|FLUSHO|PENDIN|NOFLSH)); if (ISSET(flags, RAW|LITOUT|PASS8)) { CLR(cflag, CSIZE); SET(cflag, CS8); if (!ISSET(flags, RAW|PASS8)) SET(iflag, ISTRIP); else CLR(iflag, ISTRIP); if (!ISSET(flags, RAW|LITOUT)) SET(oflag, OPOST); else CLR(oflag, OPOST); } else { CLR(cflag, CSIZE); SET(cflag, CS7); SET(iflag, ISTRIP); SET(oflag, OPOST); } tmode.c_iflag = iflag; tmode.c_oflag = oflag; tmode.c_cflag = cflag; tmode.c_lflag = lflag; }
function<void()> smoothmouse(RenderWindow&window, ui &UI){ return [&window, &UI](){ //void smoothmouse(RenderWindow&window, ui &UI){ // tidy code organization, here we predeclare methods just like a header would, it's redundant but necessary function<void()> draw, loop, init, update; function<void(Vec2 pos)> mousemoved; function<void(sf::Mouse::Button button)> mouseclick, mouserelease; function<void(Event&e)> treatotherevent; function<void(Keyboard::Key k)> treatkeyevent; // we don't have a class/interface/struct with data, everything is local to this function, like a classic stack that all programs are anyway. Texture cursor_tx; Sprite cursor; configfile cfg; cfg.init("bedlab.cfg"); if (!cursor_tx.loadFromFile(cfg.getstr("cursor"))) cout << "did not load cursor" << endl; cursor.setTexture(cursor_tx); cursor.setOrigin(3, 3); window.setMouseCursorVisible(false); float lag; SET(lag); CircleShape cursorlag(10); //cursor.setFillColor(Color::White); cursorlag.setFillColor(Color(255,0,0,128)); recenter(cursorlag); Vec2 mpos; //then we actually define the functions, note how all function captures the local context by reference draw = [&](){ UI.draw(window); window.draw(cursor); window.draw(cursorlag); }; update = [&](){ Vec2 trans = cursorlag.getPosition() - cursor.getPosition(); auto dist = vectlen(trans); //cursorlag.move(-(trans)*lag); // equivalent of getposition()+-trans*.01f //cursorlag.move(-normalized(trans)*max(dist*dist, 100.f)*lag); // equivalent of getposition()+-trans*.01f Vec2 move = vectlen(trans) > 0 ? -normalized(trans)*dist*lag :Vec2{0,0}; cursorlag.move(move); // equivalent of getposition()+-trans*.01f show(cursorlag.getPosition()); show(dist); show(trans); }; loop = [&](){ while (window.isOpen()) { sf::Event event; while (window.pollEvent(event)) { switch (event.type) { case sf::Event::KeyPressed: if (event.key.code == sf::Keyboard::Escape) window.close(); treatkeyevent(event.key.code); break; case sf::Event::Closed: window.close(); break; case sf::Event::MouseButtonPressed: mouseclick(event.mouseButton.button); break; case sf::Event::MouseButtonReleased: mouserelease(event.mouseButton.button); break; case sf::Event::MouseMoved: mpos = Vec2(event.mouseMove.x, event.mouseMove.y); mousemoved(mpos); break; default: treatotherevent(event); break; } } window.clear(); update(); draw(); //window.draw(shape); UI.draw(window); window.display(); } }; treatkeyevent = [&](Keyboard::Key k){ switch (k) { case Keyboard::Space: cursorlag.setPosition(mpos); cursor.setPosition(mpos); } }; mousemoved = [&](Vec2 pos){ //msg(pos); cursor.setPosition(pos); //UI.put(mpos); show(mpos); }; treatotherevent = [&](Event&e){ }; mouseclick = [&](sf::Mouse::Button button){ }; mouserelease = [&](sf::Mouse::Button button){ }; loop(); }; }
void multimin(size_t n,double *x,double *fun, const unsigned *type, const double *xmin,const double *xmax, void (*f) (const size_t,const double *,void *,double *), void (* df) (const size_t,const double *, void *,double *), void (* fdf) (const size_t,const double *, void *,double *,double *), void *fparams, const struct multimin_params oparams) { unsigned iter=0; int status; size_t i; double dtmp1; const gsl_multimin_fdfminimizer_type *Tfdf; const gsl_multimin_fminimizer_type *Tf; const char *Tname; gsl_vector * y = gsl_vector_alloc (n); /* set the algorithm */ switch(oparams.method){ case 0:/* Fletcher-Reeves conjugate gradient */ Tfdf = gsl_multimin_fdfminimizer_conjugate_fr; Tname = Tfdf->name; break; case 1:/* Polak-Ribiere conjugate gradient */ Tfdf = gsl_multimin_fdfminimizer_conjugate_pr; Tname = Tfdf->name; break; case 2:/* Vector Broyden-Fletcher-Goldfarb-Shanno method */ Tfdf = gsl_multimin_fdfminimizer_vector_bfgs; Tname = Tfdf->name; break; case 3:/* Steepest descent algorithm */ Tfdf =gsl_multimin_fdfminimizer_steepest_descent; Tname = Tfdf->name; break; case 4:/* Simplex */ Tf = gsl_multimin_fminimizer_nmsimplex2; Tname = Tf->name; break; case 5:/* Vector Broyden-Fletcher-Goldfarb-Shanno2 method */ Tfdf = gsl_multimin_fdfminimizer_vector_bfgs2; Tname = Tfdf->name; break; default: fprintf(stderr,"Optimization method not recognized. Try -h\n"); exit(EXIT_FAILURE); } /* --- OUPUT ---------------------------------- */ if(oparams.verbosity>0){ fprintf(stderr,"#--- MULTIMIN START\n"); fprintf(stderr,"# method %s\n",Tname); if(oparams.method<4 || oparams.method==5){ fprintf(stderr,"# initial step size %g\n", oparams.step_size); fprintf(stderr,"# line minimization tolerance %g\n",oparams.tol); fprintf(stderr,"# maximum number of iterations %u\n",oparams.maxiter); fprintf(stderr,"# precision %g\n",oparams.epsabs); } else{ fprintf(stderr,"# maximum number of iterations %u\n",oparams.maxiter); fprintf(stderr,"# maximum simplex size %g\n",oparams.maxsize); } } /* -------------------------------------------- */ /* compute values of y for initial condition */ for(i=0;i<n;i++){ if(type==NULL) SET(y,i,x[i]); else switch(type[i]){ case 0:/* (-inf,+inf) */ SET(y,i,x[i]); break; case 1:/* [a,+inf) */ SET(y,i,sqrt( x[i]-xmin[i] )); break; case 2:/* (-inf,a] */ SET(y,i,sqrt( xmax[i]-x[i] )); break; case 3:/* [a,b] */ dtmp1 = (xmax[i]>xmin[i]? (2.*x[i]-xmax[i]-xmin[i])/(xmax[i]-xmin[i]) : 0); /* dtmp1 = (2.*x[i]-xmax[i]-xmin[i])/(xmax[i]-xmin[i]); */ SET(y,i,asin( dtmp1 )); break; case 4:/* (a,+inf) */ SET(y,i,log( x[i]-xmin[i] )); break; case 5:/* (-inf,a) */ SET(y,i,log( xmax[i]-x[i] )); break; case 6:/* (a,b) */ dtmp1 = (2.*x[i]-xmax[i]-xmin[i])/(xmax[i]-xmin[i]); SET(y,i,gsl_atanh ( dtmp1 )); break; case 7:/* (a,b) second approach */ dtmp1 = (2.*x[i]-xmax[i]-xmin[i])/(xmax[i]-xmin[i]); SET(y,i, dtmp1/sqrt(1-dtmp1*dtmp1)); break; case 8:/* (a,+inf) second approach */ dtmp1 = x[i]-xmin[i]; SET(y,i, dtmp1-1./(4.*dtmp1)); break; } } /* --- OUPUT ---------------------------------- */ if(oparams.verbosity>1){ fprintf(stderr,"# - variables initial value and boundaries\n"); for(i=0;i<n;i++){ if(type==NULL) fprintf(stderr,"# x[%d]=%e (-inf,+inf) -> %e\n",(int) i,x[i],GET(y,i)); else switch(type[i]){ case 0:/* (-inf,+inf) */ fprintf(stderr,"# x[%d]=%e (-inf,+inf) -> %e\n",(int) i,x[i],GET(y,i)); break; case 1:/* [a,+inf) */ fprintf(stderr,"# x[%d]=%e [%g,+inf) -> %e\n",(int) i,x[i],xmin[i],GET(y,i)); break; case 2:/* (-inf,a] */ fprintf(stderr,"# x[%d]=%e (-inf,%g] -> %e\n",(int) i,x[i],xmax[i],GET(y,i)); break; case 3:/* [a,b] */ fprintf(stderr,"# x[%d]=%e [%g,%g] -> %e\n",(int) i,x[i],xmin[i],xmax[i],GET(y,i)); break; case 4:/* (a,+inf) */ fprintf(stderr,"# x[%d]=%e (%g,+inf) -> %e\n",(int) i,x[i],xmin[i],GET(y,i)); break; case 5:/* (-inf,a) */ fprintf(stderr,"# x[%d]=%e (-inf,%g) -> %e\n",(int) i,x[i],xmax[i],GET(y,i)); break; case 6:/* (a,b) */ case 7: fprintf(stderr,"# x[%d]=%e (%g,%g) -> %e\n",(int) i,x[i],xmin[i],xmax[i],GET(y,i)); break; case 8:/* [a,+inf) */ fprintf(stderr,"# x[%d]=%e (%g,+inf) -> %e\n",(int) i,x[i],xmin[i],GET(y,i)); break; } } { double res; fprintf(stderr,"# - function initial value\n"); f(n,x,fparams,&res); fprintf(stderr,"# f=%e\n",res); } } /* -------------------------------------------- */ if(oparams.method<4 || oparams.method==5){/* methods with derivatives */ struct g_params gparams; gsl_multimin_function_fdf GdG; gsl_multimin_fdfminimizer *s = gsl_multimin_fdfminimizer_alloc (Tfdf,n); /* set the parameters of the new function */ gparams.n = n; gparams.type = type; gparams.xmin = xmin; gparams.xmax = xmax; gparams.f = f; gparams.df = df; gparams.fdf = fdf; gparams.fparams = fparams; /* set the function to solve */ GdG.f=g; GdG.df=dg; GdG.fdf=gdg; GdG.n=n; GdG.params=(void *) &gparams; /* initialize minimizer */ status=gsl_multimin_fdfminimizer_set(s,&GdG,y,oparams.step_size,oparams.tol); if(status) { fprintf(stderr,"#ERROR: %s\n",gsl_strerror (status)); exit(EXIT_FAILURE); } /* +++++++++++++++++++++++++++++++++++++++++++++++ */ if(oparams.verbosity>2) fprintf(stderr,"# - start minimization \n"); /* +++++++++++++++++++++++++++++++++++++++++++++++ */ do { iter++; status = gsl_multimin_fdfminimizer_iterate (s); /* +++++++++++++++++++++++++++++++++++++++++++++++ */ if(oparams.verbosity>2){ fprintf(stderr,"# [%d]",iter); fprintf(stderr," g=%+12.6e y=( ",s->f); for(i=0;i<n;i++) fprintf(stderr,"%+12.6e ",GET(s->x,i)); fprintf(stderr,") dg=( "); for(i=0;i<n;i++) fprintf(stderr,"%+12.6e ",GET(s->gradient,i)); fprintf(stderr,") |dg|=%12.6e ",gsl_blas_dnrm2 (s->gradient)); fprintf(stderr,"|dx|=%12.6e\n",gsl_blas_dnrm2 (s->dx)); } /* +++++++++++++++++++++++++++++++++++++++++++++++ */ if(status == GSL_ENOPROG){ fprintf(stderr,"# status: %s\n",gsl_strerror (status)); break; } if(status){ fprintf(stderr,"#WARNING: %s\n", gsl_strerror (status)); break; } /* { */ /* const double eps = oparams.epsabs; */ /* const double norm_x = gsl_blas_dnrm2 (s->x); */ /* const double norm_dx = gsl_blas_dnrm2 (s->dx); */ /* const double norm_g = gsl_blas_dnrm2 (s->gradient); */ /* if( norm_dx < eps && norm_dx < norm_x*eps && norm_g < eps ) */ /* status = GSL_SUCCESS; */ /* else */ /* status = GSL_CONTINUE; */ /* fprintf(stderr,"|x|=%f |dx|=%f |dg|=%f\n",norm_x,norm_dx,norm_g); */ /* } */ status = gsl_multimin_test_gradient (s->gradient,oparams.epsabs); } while (status == GSL_CONTINUE && iter < oparams.maxiter); gsl_vector_memcpy (y,s->x); *fun=s->f; gsl_multimin_fdfminimizer_free (s); } else{ /* methods without derivatives */ gsl_vector *ss = gsl_vector_alloc (n); struct g_params gparams; gsl_multimin_function G; gsl_multimin_fminimizer *s=gsl_multimin_fminimizer_alloc (Tf,n); /* set the parameters of the new function */ gparams.n = n; gparams.type = type; gparams.xmin = xmin; gparams.xmax = xmax; gparams.f = f; gparams.fparams = fparams; /* set the function to solve */ G.f=g; G.n=n; G.params=(void *) &gparams; /* Initial vertex size vector */ { /* size_t i; */ /* dg(y,&gparams,ss); */ /* gsl_vector_set_all (ss,1); */ /* for(i=0;i<n;i++) */ /* SET(ss,i,fabs(GET(ss,i))); */ /* gsl_vector_add_constant (ss,oparams.maxsize); */ gsl_vector_set_all (ss,oparams.step_size+oparams.maxsize); } /* --- OUPUT ---------------------------------- */ if(oparams.verbosity>0){ size_t i; fprintf(stderr,"# initial simplex sizes\n"); fprintf(stderr,"# "); for(i=0;i<n;i++) fprintf(stderr," %g", GET(ss,i)); fprintf(stderr,"\n"); } /* -------------------------------------------- */ /* Initialize minimizer */ status=gsl_multimin_fminimizer_set(s,&G,y,ss); do { status = gsl_multimin_fminimizer_iterate(s); const double size = gsl_multimin_fminimizer_size (s); iter++; /* +++++++++++++++++++++++++++++++++++++++++++++++ */ if(oparams.verbosity>2){ fprintf(stderr,"# g=%g y=( ",s->fval); for(i=0;i<n;i++) fprintf(stderr,"%g ",GET(s->x,i)); fprintf(stderr,") "); fprintf(stderr," simplex size=%g ",size); fprintf(stderr,"\n"); } /* +++++++++++++++++++++++++++++++++++++++++++++++ */ status=gsl_multimin_test_size (size,oparams.maxsize); } while (status == GSL_CONTINUE && iter < oparams.maxiter); gsl_vector_memcpy (y, s->x); *fun=s->fval; gsl_multimin_fminimizer_free (s); gsl_vector_free(ss); } /* compute values of x */ for(i=0;i<n;i++){ if(type==NULL) /* (-inf,+inf) */ x[i]=GET(y,i); else switch(type[i]){ case 0:/* (-inf,+inf) */ x[i]=GET(y,i); break; case 1:/* [a,+inf) */ x[i]=xmin[i]+GET(y,i)*GET(y,i); break; case 2:/* (-inf,a] */ x[i]=xmax[i]-GET(y,i)*GET(y,i); break; case 3:/* [a,b] */ dtmp1 = sin( GET(y,i) ); x[i]=.5*(xmin[i]*(1-dtmp1) +xmax[i]*(1+dtmp1)); break; case 4:/* (a,+inf) */ dtmp1 = exp( GET(y,i) ); x[i]=xmin[i]+dtmp1; break; case 5:/* (-inf,a) */ dtmp1 = -exp( GET(y,i) ); x[i]=xmax[i]+dtmp1; break; case 6:/* (a,b) */ dtmp1 = tanh( GET(y,i) ); x[i]=.5*(xmin[i]*(1-dtmp1) +xmax[i]*(1+dtmp1)); break; case 7:/* (a,b) second approach */ dtmp1 = GET(y,i) ; dtmp1 = dtmp1/sqrt(1.+dtmp1*dtmp1); x[i]=.5*(xmin[i]*(1-dtmp1) +xmax[i]*(1+dtmp1)); break; case 8:/* (a,+inf) second approach */ dtmp1 = sqrt(1.+GET(y,i)*GET(y,i)); x[i]= xmin[i] + .5*(dtmp1+GET(y,i)); break; } } /* --- OUPUT ---------------------------------- */ if(oparams.verbosity>0){ fprintf(stderr,"# - end minimization\n"); fprintf(stderr,"# iterations %u\n",iter); for(i=0;i<n;i++) fprintf(stderr,"# %e -> x[%zd]=%e\n",GET(y,i),i,x[i]); fprintf(stderr,"#--- MULTIMIN END --- \n"); } /* -------------------------------------------- */ gsl_vector_free (y); }
/* NS990113 */ static void rrc_a(void) { UINT8 i=M_Cy; if (R.A & 1) SET(C_FLAG); else CLR(C_FLAG); R.A >>= 1; if (i) R.A |= 0x80; else R.A &= 0x7f; }
int maildir_filter_loadrules(struct maildirfilter *r, const char *filename) { FILE *f=fopen(filename, "r"); char buf[BUFSIZ]; char *p; enum maildirfiltertype new_type; char new_header[256]; char new_value[256]; char new_folder[256]; char new_autoreplyfrom[512]; int flags; if (!f) return (MF_LOADNOTFOUND); if (fgets(buf, sizeof(buf), f) == 0 || strncmp(buf, "#MFMAILDROP=", 12)) { fclose(f); return (MF_LOADFOREIGN); } flags=atoi(buf+12); if (flags != 1 && flags != 2) { fclose(f); return (MF_LOADFOREIGN); } new_type=contains; new_header[0]=0; new_value[0]=0; new_folder[0]=0; new_autoreplyfrom[0]=0; flags=0; #define SET(f,b) { f[0]=0; strncat( (f), (b), sizeof(f)-1); } while ( fgets(buf, sizeof(buf), f)) { int i; p=strchr(buf, '\n'); if (p) *p=0; if (strncmp(buf, "##", 2)) continue; p=buf+2; while ( *p && isspace((int)(unsigned char)*p)) ++p; if (strncasecmp(p, "From:", 5) == 0) { p += 5; SET(new_autoreplyfrom, p); continue; } if (strncasecmp(p, "Op:", 3) == 0) { p += 3; for (i=0; typelist[i].name; i++) if (strcasecmp(typelist[i].name, p) == 0) break; if (!typelist[i].name) { fclose(f); return (MF_LOADFOREIGN); } new_type=typelist[i].type; continue; } if (strncasecmp(p, "Header:", 7) == 0) { p += 7; SET(new_header, p); continue; } if (strncasecmp(p, "Value:", 6) == 0) { p += 6; SET(new_value, p); continue; } if (strncasecmp(p, "Folder:", 7) == 0) { p += 7; if (*p == '.') { strcpy(new_folder, INBOX); } else new_folder[0]=0; if (strcmp(p, ".")) strncat(new_folder, p, sizeof(new_folder)-1-strlen(new_folder)); continue; } if (strcasecmp(p, "plainstring") == 0) { flags |= MFR_PLAINSTRING; continue; } if (strcasecmp(p, "doesnot") == 0) { flags |= MFR_DOESNOT; continue; } if (strcasecmp(p, "continue") == 0) { flags |= MFR_CONTINUE; continue; } if (strcasecmp(p, "body") == 0) { flags |= MFR_BODY; continue; } if (strncasecmp(p, "Name:", 5) == 0) { int dummy; p += 5; maildir_filter_appendrule(r, p, new_type, flags, new_header, new_value, new_folder, new_autoreplyfrom, "utf-8", &dummy); new_type=contains; new_header[0]=0; new_value[0]=0; new_folder[0]=0; new_autoreplyfrom[0]=0; flags=0; } } fclose(f); return (MF_LOADOK); }
static void sel_rb1(void) { SET(B_FLAG); regPTR = 24; }
/* * Deserialize args, settings and user_info arrays. * Fills in struct sudo_user and other common sudoers state. */ int sudoers_policy_deserialize_info(void *v, char **runas_user, char **runas_group) { struct sudoers_policy_open_info *info = v; char * const *cur; const char *p, *errstr, *groups = NULL; const char *remhost = NULL; int flags = 0; debug_decl(sudoers_policy_deserialize_info, SUDOERS_DEBUG_PLUGIN) #define MATCHES(s, v) (strncmp(s, v, sizeof(v) - 1) == 0) /* Parse sudo.conf plugin args. */ if (info->plugin_args != NULL) { for (cur = info->plugin_args; *cur != NULL; cur++) { if (MATCHES(*cur, "sudoers_file=")) { sudoers_file = *cur + sizeof("sudoers_file=") - 1; continue; } if (MATCHES(*cur, "sudoers_uid=")) { p = *cur + sizeof("sudoers_uid=") - 1; sudoers_uid = (uid_t) sudo_strtoid(p, NULL, NULL, &errstr); if (errstr != NULL) { sudo_warnx(U_("%s: %s"), *cur, U_(errstr)); goto bad; } continue; } if (MATCHES(*cur, "sudoers_gid=")) { p = *cur + sizeof("sudoers_gid=") - 1; sudoers_gid = (gid_t) sudo_strtoid(p, NULL, NULL, &errstr); if (errstr != NULL) { sudo_warnx(U_("%s: %s"), *cur, U_(errstr)); goto bad; } continue; } if (MATCHES(*cur, "sudoers_mode=")) { p = *cur + sizeof("sudoers_mode=") - 1; sudoers_mode = sudo_strtomode(p, &errstr); if (errstr != NULL) { sudo_warnx(U_("%s: %s"), *cur, U_(errstr)); goto bad; } continue; } if (MATCHES(*cur, "ldap_conf=")) { path_ldap_conf = *cur + sizeof("ldap_conf=") - 1; continue; } if (MATCHES(*cur, "ldap_secret=")) { path_ldap_secret = *cur + sizeof("ldap_secret=") - 1; continue; } } } /* Parse command line settings. */ user_closefrom = -1; for (cur = info->settings; *cur != NULL; cur++) { if (MATCHES(*cur, "closefrom=")) { errno = 0; p = *cur + sizeof("closefrom=") - 1; user_closefrom = strtonum(p, 4, INT_MAX, &errstr); if (user_closefrom == 0) { sudo_warnx(U_("%s: %s"), *cur, U_(errstr)); goto bad; } continue; } if (MATCHES(*cur, "runas_user="******"runas_user="******"runas_group=")) { *runas_group = *cur + sizeof("runas_group=") - 1; sudo_user.flags |= RUNAS_GROUP_SPECIFIED; continue; } if (MATCHES(*cur, "prompt=")) { user_prompt = *cur + sizeof("prompt=") - 1; def_passprompt_override = true; continue; } if (MATCHES(*cur, "set_home=")) { if (sudo_strtobool(*cur + sizeof("set_home=") - 1) == true) SET(flags, MODE_RESET_HOME); continue; } if (MATCHES(*cur, "preserve_environment=")) { if (sudo_strtobool(*cur + sizeof("preserve_environment=") - 1) == true) SET(flags, MODE_PRESERVE_ENV); continue; } if (MATCHES(*cur, "run_shell=")) { if (sudo_strtobool(*cur + sizeof("run_shell=") - 1) == true) SET(flags, MODE_SHELL); continue; } if (MATCHES(*cur, "login_shell=")) { if (sudo_strtobool(*cur + sizeof("login_shell=") - 1) == true) { SET(flags, MODE_LOGIN_SHELL); def_env_reset = true; } continue; } if (MATCHES(*cur, "implied_shell=")) { if (sudo_strtobool(*cur + sizeof("implied_shell=") - 1) == true) SET(flags, MODE_IMPLIED_SHELL); continue; } if (MATCHES(*cur, "preserve_groups=")) { if (sudo_strtobool(*cur + sizeof("preserve_groups=") - 1) == true) SET(flags, MODE_PRESERVE_GROUPS); continue; } if (MATCHES(*cur, "ignore_ticket=")) { if (sudo_strtobool(*cur + sizeof("ignore_ticket=") - 1) == true) SET(flags, MODE_IGNORE_TICKET); continue; } if (MATCHES(*cur, "noninteractive=")) { if (sudo_strtobool(*cur + sizeof("noninteractive=") - 1) == true) SET(flags, MODE_NONINTERACTIVE); continue; } if (MATCHES(*cur, "sudoedit=")) { if (sudo_strtobool(*cur + sizeof("sudoedit=") - 1) == true) SET(flags, MODE_EDIT); continue; } if (MATCHES(*cur, "login_class=")) { login_class = *cur + sizeof("login_class=") - 1; def_use_loginclass = true; continue; } #ifdef HAVE_PRIV_SET if (MATCHES(*cur, "runas_privs=")) { def_privs = *cur + sizeof("runas_privs=") - 1; continue; } if (MATCHES(*cur, "runas_limitprivs=")) { def_limitprivs = *cur + sizeof("runas_limitprivs=") - 1; continue; } #endif /* HAVE_PRIV_SET */ #ifdef HAVE_SELINUX if (MATCHES(*cur, "selinux_role=")) { user_role = *cur + sizeof("selinux_role=") - 1; continue; } if (MATCHES(*cur, "selinux_type=")) { user_type = *cur + sizeof("selinux_type=") - 1; continue; } #endif /* HAVE_SELINUX */ #ifdef HAVE_BSD_AUTH_H if (MATCHES(*cur, "bsdauth_type=")) { login_style = *cur + sizeof("bsdauth_type=") - 1; continue; } #endif /* HAVE_BSD_AUTH_H */ if (MATCHES(*cur, "network_addrs=")) { interfaces_string = *cur + sizeof("network_addrs=") - 1; set_interfaces(interfaces_string); continue; } if (MATCHES(*cur, "max_groups=")) { errno = 0; p = *cur + sizeof("max_groups=") - 1; sudo_user.max_groups = strtonum(p, 1, INT_MAX, &errstr); if (sudo_user.max_groups == 0) { sudo_warnx(U_("%s: %s"), *cur, U_(errstr)); goto bad; } continue; } if (MATCHES(*cur, "remote_host=")) { remhost = *cur + sizeof("remote_host=") - 1; continue; } } for (cur = info->user_info; *cur != NULL; cur++) { if (MATCHES(*cur, "user="******"user="******"uid=")) { p = *cur + sizeof("uid=") - 1; user_uid = (uid_t) sudo_strtoid(p, NULL, NULL, &errstr); if (errstr != NULL) { sudo_warnx(U_("%s: %s"), *cur, U_(errstr)); goto bad; } continue; } if (MATCHES(*cur, "gid=")) { p = *cur + sizeof("gid=") - 1; user_gid = (gid_t) sudo_strtoid(p, NULL, NULL, &errstr); if (errstr != NULL) { sudo_warnx(U_("%s: %s"), *cur, U_(errstr)); goto bad; } continue; } if (MATCHES(*cur, "groups=")) { groups = *cur + sizeof("groups=") - 1; continue; } if (MATCHES(*cur, "cwd=")) { user_cwd = sudo_estrdup(*cur + sizeof("cwd=") - 1); continue; } if (MATCHES(*cur, "tty=")) { user_tty = user_ttypath = sudo_estrdup(*cur + sizeof("tty=") - 1); if (strncmp(user_tty, _PATH_DEV, sizeof(_PATH_DEV) - 1) == 0) user_tty += sizeof(_PATH_DEV) - 1; continue; } if (MATCHES(*cur, "host=")) { user_host = user_shost = sudo_estrdup(*cur + sizeof("host=") - 1); if ((p = strchr(user_host, '.'))) user_shost = sudo_estrndup(user_host, (size_t)(p - user_host)); continue; } if (MATCHES(*cur, "lines=")) { errno = 0; p = *cur + sizeof("lines=") - 1; sudo_user.lines = strtonum(p, 1, INT_MAX, &errstr); if (sudo_user.lines == 0) { sudo_warnx(U_("%s: %s"), *cur, U_(errstr)); goto bad; } continue; } if (MATCHES(*cur, "cols=")) { errno = 0; p = *cur + sizeof("cols=") - 1; sudo_user.cols = strtonum(p, 1, INT_MAX, &errstr); if (sudo_user.lines == 0) { sudo_warnx(U_("%s: %s"), *cur, U_(errstr)); goto bad; } continue; } if (MATCHES(*cur, "sid=")) { p = *cur + sizeof("sid=") - 1; sudo_user.sid = (pid_t) sudo_strtoid(p, NULL, NULL, &errstr); if (errstr != NULL) { sudo_warnx(U_("%s: %s"), *cur, U_(errstr)); goto bad; } continue; } } user_runhost = user_srunhost = sudo_estrdup(remhost ? remhost : user_host); if ((p = strchr(user_runhost, '.'))) user_srunhost = sudo_estrndup(user_runhost, (size_t)(p - user_runhost)); if (user_cwd == NULL) user_cwd = sudo_estrdup("unknown"); if (user_tty == NULL) user_tty = sudo_estrdup("unknown"); /* user_ttypath remains NULL */ if (groups != NULL && groups[0] != '\0') { /* sudo_parse_gids() will print a warning on error. */ user_ngids = sudo_parse_gids(groups, &user_gid, &user_gids); if (user_ngids == -1) goto bad; } /* Stash initial umask for later use. */ user_umask = umask(SUDO_UMASK); umask(user_umask); /* Dump settings and user info (XXX - plugin args) */ for (cur = info->settings; *cur != NULL; cur++) sudo_debug_printf(SUDO_DEBUG_INFO, "settings: %s", *cur); for (cur = info->user_info; *cur != NULL; cur++) sudo_debug_printf(SUDO_DEBUG_INFO, "user_info: %s", *cur); #undef MATCHES debug_return_int(flags); bad: debug_return_int(MODE_ERROR); }
void pic16c62x_device::CALCULATE_Z_FLAG() { if (m_ALU == 0) SET(STATUS, Z_FLAG); else CLR(STATUS, Z_FLAG); }
FTSENT * fts_read(FTS *sp) { FTSENT *p, *tmp; int instr; char *t; int saved_errno; /* If finished or unrecoverable error, return NULL. */ if (sp->fts_cur == NULL || ISSET(FTS_STOP)) return (NULL); /* Set current node pointer. */ p = sp->fts_cur; /* Save and zero out user instructions. */ instr = p->fts_instr; p->fts_instr = FTS_NOINSTR; /* Any type of file may be re-visited; re-stat and re-turn. */ if (instr == FTS_AGAIN) { p->fts_info = fts_stat(sp, p, 0); return (p); } /* * Following a symlink -- SLNONE test allows application to see * SLNONE and recover. If indirecting through a symlink, have * keep a pointer to current location. If unable to get that * pointer, follow fails. */ if (instr == FTS_FOLLOW && (p->fts_info == FTS_SL || p->fts_info == FTS_SLNONE)) { p->fts_info = fts_stat(sp, p, 1); if (p->fts_info == FTS_D && !ISSET(FTS_NOCHDIR)) { if ((p->fts_symfd = open(".", O_RDONLY, 0)) < 0) { p->fts_errno = errno; p->fts_info = FTS_ERR; } else p->fts_flags |= FTS_SYMFOLLOW; } return (p); } /* Directory in pre-order. */ if (p->fts_info == FTS_D) { /* If skipped or crossed mount point, do post-order visit. */ if (instr == FTS_SKIP || (ISSET(FTS_XDEV) && p->fts_dev != sp->fts_dev)) { if (p->fts_flags & FTS_SYMFOLLOW) (void)close(p->fts_symfd); if (sp->fts_child) { fts_lfree(sp->fts_child); sp->fts_child = NULL; } p->fts_info = FTS_DP; return (p); } /* Rebuild if only read the names and now traversing. */ if (sp->fts_child && ISSET(FTS_NAMEONLY)) { CLR(FTS_NAMEONLY); fts_lfree(sp->fts_child); sp->fts_child = NULL; } /* * Cd to the subdirectory. * * If have already read and now fail to chdir, whack the list * to make the names come out right, and set the parent errno * so the application will eventually get an error condition. * Set the FTS_DONTCHDIR flag so that when we logically change * directories back to the parent we don't do a chdir. * * If haven't read do so. If the read fails, fts_build sets * FTS_STOP or the fts_info field of the node. */ if (sp->fts_child) { if (fts_safe_changedir(sp, p, -1, p->fts_accpath)) { p->fts_errno = errno; p->fts_flags |= FTS_DONTCHDIR; for (p = sp->fts_child; p; p = p->fts_link) p->fts_accpath = p->fts_parent->fts_accpath; } } else if ((sp->fts_child = fts_build(sp, BREAD)) == NULL) { if (ISSET(FTS_STOP)) return (NULL); return (p); } p = sp->fts_child; sp->fts_child = NULL; goto name; } /* Move to the next node on this level. */ next: tmp = p; if ((p = p->fts_link)) { free(tmp); /* * If reached the top, return to the original directory (or * the root of the tree), and load the paths for the next root. */ if (p->fts_level == FTS_ROOTLEVEL) { if (FCHDIR(sp, sp->fts_rfd)) { SET(FTS_STOP); return (NULL); } fts_load(sp, p); return (sp->fts_cur = p); } /* * User may have called fts_set on the node. If skipped, * ignore. If followed, get a file descriptor so we can * get back if necessary. */ if (p->fts_instr == FTS_SKIP) goto next; if (p->fts_instr == FTS_FOLLOW) { p->fts_info = fts_stat(sp, p, 1); if (p->fts_info == FTS_D && !ISSET(FTS_NOCHDIR)) { if ((p->fts_symfd = open(".", O_RDONLY, 0)) < 0) { p->fts_errno = errno; p->fts_info = FTS_ERR; } else p->fts_flags |= FTS_SYMFOLLOW; } p->fts_instr = FTS_NOINSTR; } name: t = sp->fts_path + NAPPEND(p->fts_parent); *t++ = '/'; memmove(t, p->fts_name, p->fts_namelen + 1); return (sp->fts_cur = p); } /* Move up to the parent node. */ p = tmp->fts_parent; free(tmp); if (p->fts_level == FTS_ROOTPARENTLEVEL) { /* * Done; free everything up and set errno to 0 so the user * can distinguish between error and EOF. */ free(p); errno = 0; return (sp->fts_cur = NULL); } /* NUL terminate the pathname. */ sp->fts_path[p->fts_pathlen] = '\0'; /* * Return to the parent directory. If at a root node or came through * a symlink, go back through the file descriptor. Otherwise, cd up * one directory. */ if (p->fts_level == FTS_ROOTLEVEL) { if (FCHDIR(sp, sp->fts_rfd)) { SET(FTS_STOP); sp->fts_cur = p; return (NULL); } } else if (p->fts_flags & FTS_SYMFOLLOW) { if (FCHDIR(sp, p->fts_symfd)) { saved_errno = errno; (void)close(p->fts_symfd); errno = saved_errno; SET(FTS_STOP); sp->fts_cur = p; return (NULL); } (void)close(p->fts_symfd); } else if (!(p->fts_flags & FTS_DONTCHDIR) && fts_safe_changedir(sp, p->fts_parent, -1, "..")) { SET(FTS_STOP); sp->fts_cur = p; return (NULL); } p->fts_info = p->fts_errno ? FTS_ERR : FTS_DP; return (sp->fts_cur = p); }
void pic16c62x_device::clrf() { STORE_REGFILE(ADDR, 0); SET(STATUS, Z_FLAG); }
FTSENT * fts_children(FTS *sp, int instr) { FTSENT *p; int fd; if (instr && instr != FTS_NAMEONLY) { errno = EINVAL; return (NULL); } /* Set current node pointer. */ p = sp->fts_cur; /* * Errno set to 0 so user can distinguish empty directory from * an error. */ errno = 0; /* Fatal errors stop here. */ if (ISSET(FTS_STOP)) return (NULL); /* Return logical hierarchy of user's arguments. */ if (p->fts_info == FTS_INIT) return (p->fts_link); /* * If not a directory being visited in pre-order, stop here. Could * allow FTS_DNR, assuming the user has fixed the problem, but the * same effect is available with FTS_AGAIN. */ if (p->fts_info != FTS_D /* && p->fts_info != FTS_DNR */) return (NULL); /* Free up any previous child list. */ if (sp->fts_child) fts_lfree(sp->fts_child); if (instr == FTS_NAMEONLY) { SET(FTS_NAMEONLY); instr = BNAMES; } else instr = BCHILD; /* * If using chdir on a relative path and called BEFORE fts_read does * its chdir to the root of a traversal, we can lose -- we need to * chdir into the subdirectory, and we don't know where the current * directory is, so we can't get back so that the upcoming chdir by * fts_read will work. */ if (p->fts_level != FTS_ROOTLEVEL || p->fts_accpath[0] == '/' || ISSET(FTS_NOCHDIR)) return (sp->fts_child = fts_build(sp, instr)); if ((fd = open(".", O_RDONLY, 0)) < 0) return (NULL); sp->fts_child = fts_build(sp, instr); if (fchdir(fd)) { (void)close(fd); return (NULL); } (void)close(fd); return (sp->fts_child); }
// clip and generate contacts void sTrimeshBoxColliderData::_cldClipping(const dVector3 &v0, const dVector3 &v1, const dVector3 &v2, int TriIndex) { dIASSERT( !(m_iFlags & CONTACTS_UNIMPORTANT) || m_ctContacts < (m_iFlags & NUMC_MASK) ); // Do not call the function if there is no room to store results // if we have edge/edge intersection if (m_iBestAxis > 4 ) { dVector3 vub,vPb,vPa; SET(vPa,m_vHullBoxPos); // calculate point on box edge for( int i=0; i<3; i++) { dVector3 vRotCol; GETCOL(m_mHullBoxRot,i,vRotCol); dReal fSign = dDOT(m_vBestNormal,vRotCol) > 0 ? 1.0f : -1.0f; vPa[0] += fSign * m_vBoxHalfSize[i] * vRotCol[0]; vPa[1] += fSign * m_vBoxHalfSize[i] * vRotCol[1]; vPa[2] += fSign * m_vBoxHalfSize[i] * vRotCol[2]; } int iEdge = (m_iBestAxis-5)%3; // decide which edge is on triangle if ( iEdge == 0 ) { SET(vPb,v0); SET(vub,m_vE0); } else if ( iEdge == 1) { SET(vPb,v2); SET(vub,m_vE1); } else { SET(vPb,v1); SET(vub,m_vE2); } // setup direction parameter for face edge dNormalize3(vub); dReal fParam1, fParam2; // setup direction parameter for box edge dVector3 vua; int col=(m_iBestAxis-5)/3; GETCOL(m_mHullBoxRot,col,vua); // find two closest points on both edges _cldClosestPointOnTwoLines( vPa, vua, vPb, vub, fParam1, fParam2 ); vPa[0] += vua[0]*fParam1; vPa[1] += vua[1]*fParam1; vPa[2] += vua[2]*fParam1; vPb[0] += vub[0]*fParam2; vPb[1] += vub[1]*fParam2; vPb[2] += vub[2]*fParam2; // calculate collision point dVector3 vPntTmp; ADD(vPa,vPb,vPntTmp); vPntTmp[0]*=0.5f; vPntTmp[1]*=0.5f; vPntTmp[2]*=0.5f; // generate contact point between two closest points #if 0 //#ifdef ORIG -- if to use conditional define, GenerateContact must be moved into #else dContactGeom* Contact = SAFECONTACT(m_iFlags, m_ContactGeoms, m_ctContacts, m_iStride); Contact->depth = m_fBestDepth; SET(Contact->normal,m_vBestNormal); SET(Contact->pos,vPntTmp); Contact->g1 = Geom1; Contact->g2 = Geom2; Contact->side1 = TriIndex; Contact->side2 = -1; m_ctContacts++; #endif GenerateContact(m_iFlags, m_ContactGeoms, m_iStride, m_Geom1, m_Geom2, TriIndex, vPntTmp, m_vBestNormal, m_fBestDepth, m_ctContacts); // if triangle is the referent face then clip box to triangle face } else if (m_iBestAxis == 1) { dVector3 vNormal2; vNormal2[0]=-m_vBestNormal[0]; vNormal2[1]=-m_vBestNormal[1]; vNormal2[2]=-m_vBestNormal[2]; // vNr is normal in box frame, pointing from triangle to box dMatrix3 mTransposed; mTransposed[0*4+0]=m_mHullBoxRot[0*4+0]; mTransposed[0*4+1]=m_mHullBoxRot[1*4+0]; mTransposed[0*4+2]=m_mHullBoxRot[2*4+0]; mTransposed[1*4+0]=m_mHullBoxRot[0*4+1]; mTransposed[1*4+1]=m_mHullBoxRot[1*4+1]; mTransposed[1*4+2]=m_mHullBoxRot[2*4+1]; mTransposed[2*4+0]=m_mHullBoxRot[0*4+2]; mTransposed[2*4+1]=m_mHullBoxRot[1*4+2]; mTransposed[2*4+2]=m_mHullBoxRot[2*4+2]; dVector3 vNr; vNr[0]=mTransposed[0*4+0]*vNormal2[0]+ mTransposed[0*4+1]*vNormal2[1]+ mTransposed[0*4+2]*vNormal2[2]; vNr[1]=mTransposed[1*4+0]*vNormal2[0]+ mTransposed[1*4+1]*vNormal2[1]+ mTransposed[1*4+2]*vNormal2[2]; vNr[2]=mTransposed[2*4+0]*vNormal2[0]+ mTransposed[2*4+1]*vNormal2[1]+ mTransposed[2*4+2]*vNormal2[2]; dVector3 vAbsNormal; vAbsNormal[0] = dFabs( vNr[0] ); vAbsNormal[1] = dFabs( vNr[1] ); vAbsNormal[2] = dFabs( vNr[2] ); // get closest face from box int iB0, iB1, iB2; if (vAbsNormal[1] > vAbsNormal[0]) { if (vAbsNormal[1] > vAbsNormal[2]) { iB1 = 0; iB0 = 1; iB2 = 2; } else { iB1 = 0; iB2 = 1; iB0 = 2; } } else { if (vAbsNormal[0] > vAbsNormal[2]) { iB0 = 0; iB1 = 1; iB2 = 2; } else { iB1 = 0; iB2 = 1; iB0 = 2; } } // Here find center of box face we are going to project dVector3 vCenter; dVector3 vRotCol; GETCOL(m_mHullBoxRot,iB0,vRotCol); if (vNr[iB0] > 0) { vCenter[0] = m_vHullBoxPos[0] - v0[0] - m_vBoxHalfSize[iB0] * vRotCol[0]; vCenter[1] = m_vHullBoxPos[1] - v0[1] - m_vBoxHalfSize[iB0] * vRotCol[1]; vCenter[2] = m_vHullBoxPos[2] - v0[2] - m_vBoxHalfSize[iB0] * vRotCol[2]; } else { vCenter[0] = m_vHullBoxPos[0] - v0[0] + m_vBoxHalfSize[iB0] * vRotCol[0]; vCenter[1] = m_vHullBoxPos[1] - v0[1] + m_vBoxHalfSize[iB0] * vRotCol[1]; vCenter[2] = m_vHullBoxPos[2] - v0[2] + m_vBoxHalfSize[iB0] * vRotCol[2]; } // Here find 4 corner points of box dVector3 avPoints[4]; dVector3 vRotCol2; GETCOL(m_mHullBoxRot,iB1,vRotCol); GETCOL(m_mHullBoxRot,iB2,vRotCol2); for(int x=0;x<3;x++) { avPoints[0][x] = vCenter[x] + (m_vBoxHalfSize[iB1] * vRotCol[x]) - (m_vBoxHalfSize[iB2] * vRotCol2[x]); avPoints[1][x] = vCenter[x] - (m_vBoxHalfSize[iB1] * vRotCol[x]) - (m_vBoxHalfSize[iB2] * vRotCol2[x]); avPoints[2][x] = vCenter[x] - (m_vBoxHalfSize[iB1] * vRotCol[x]) + (m_vBoxHalfSize[iB2] * vRotCol2[x]); avPoints[3][x] = vCenter[x] + (m_vBoxHalfSize[iB1] * vRotCol[x]) + (m_vBoxHalfSize[iB2] * vRotCol2[x]); } // clip Box face with 4 planes of triangle (1 face plane, 3 egde planes) dVector3 avTempArray1[9]; dVector3 avTempArray2[9]; dVector4 plPlane; int iTempCnt1=0; int iTempCnt2=0; // zeroify vectors - necessary? for(int i=0; i<9; i++) { avTempArray1[i][0]=0; avTempArray1[i][1]=0; avTempArray1[i][2]=0; avTempArray2[i][0]=0; avTempArray2[i][1]=0; avTempArray2[i][2]=0; } // Normal plane dVector3 vTemp; vTemp[0]=-m_vN[0]; vTemp[1]=-m_vN[1]; vTemp[2]=-m_vN[2]; dNormalize3(vTemp); CONSTRUCTPLANE(plPlane,vTemp,0); _cldClipPolyToPlane( avPoints, 4, avTempArray1, iTempCnt1, plPlane ); // Plane p0 dVector3 vTemp2; SUBTRACT(v1,v0,vTemp2); dCROSS(vTemp,=,m_vN,vTemp2); dNormalize3(vTemp); CONSTRUCTPLANE(plPlane,vTemp,0); _cldClipPolyToPlane( avTempArray1, iTempCnt1, avTempArray2, iTempCnt2, plPlane ); // Plane p1 SUBTRACT(v2,v1,vTemp2); dCROSS(vTemp,=,m_vN,vTemp2); dNormalize3(vTemp); SUBTRACT(v0,v2,vTemp2); CONSTRUCTPLANE(plPlane,vTemp,dDOT(vTemp2,vTemp)); _cldClipPolyToPlane( avTempArray2, iTempCnt2, avTempArray1, iTempCnt1, plPlane ); // Plane p2 SUBTRACT(v0,v2,vTemp2); dCROSS(vTemp,=,m_vN,vTemp2); dNormalize3(vTemp); CONSTRUCTPLANE(plPlane,vTemp,0); _cldClipPolyToPlane( avTempArray1, iTempCnt1, avTempArray2, iTempCnt2, plPlane ); // END of clipping polygons // for each generated contact point for ( int i=0; i<iTempCnt2; i++ ) { // calculate depth dReal fTempDepth = dDOT(vNormal2,avTempArray2[i]); // clamp depth to zero if (fTempDepth > 0) { fTempDepth = 0; } dVector3 vPntTmp; ADD(avTempArray2[i],v0,vPntTmp); #if 0 //#ifdef ORIG -- if to use conditional define, GenerateContact must be moved into #else dContactGeom* Contact = SAFECONTACT(m_iFlags, m_ContactGeoms, m_ctContacts, m_iStride); Contact->depth = -fTempDepth; SET(Contact->normal,m_vBestNormal); SET(Contact->pos,vPntTmp); Contact->g1 = Geom1; Contact->g2 = Geom2; Contact->side1 = TriIndex; Contact->side2 = -1; m_ctContacts++; #endif GenerateContact(m_iFlags, m_ContactGeoms, m_iStride, m_Geom1, m_Geom2, TriIndex, vPntTmp, m_vBestNormal, -fTempDepth, m_ctContacts); if ((m_ctContacts | CONTACTS_UNIMPORTANT) == (m_iFlags & (NUMC_MASK | CONTACTS_UNIMPORTANT))) { break; } } //dAASSERT(m_ctContacts>0); // if box face is the referent face, then clip triangle on box face } else { // 2 <= if iBestAxis <= 4
/* * This is the tricky part -- do not casually change *anything* in here. The * idea is to build the linked list of entries that are used by fts_children * and fts_read. There are lots of special cases. * * The real slowdown in walking the tree is the stat calls. If FTS_NOSTAT is * set and it's a physical walk (so that symbolic links can't be directories), * we can do things quickly. First, if it's a 4.4BSD file system, the type * of the file is in the directory entry. Otherwise, we assume that the number * of subdirectories in a node is equal to the number of links to the parent. * The former skips all stat calls. The latter skips stat calls in any leaf * directories and for any files after the subdirectories in the directory have * been found, cutting the stat calls by about 2/3. */ static FTSENT * fts_build(FTS *sp, int type) { struct dirent *dp; FTSENT *p, *head; FTSENT *cur, *tail; DIR *dirp; void *oldaddr; size_t len, maxlen; int nitems, cderrno, descend, level, nlinks, nostat, doadjust; int saved_errno; char *cp; /* Set current node pointer. */ cur = sp->fts_cur; /* * Open the directory for reading. If this fails, we're done. * If being called from fts_read, set the fts_info field. */ if ((dirp = opendir(cur->fts_accpath)) == NULL) { if (type == BREAD) { cur->fts_info = FTS_DNR; cur->fts_errno = errno; } return (NULL); } /* * Nlinks is the number of possible entries of type directory in the * directory if we're cheating on stat calls, 0 if we're not doing * any stat calls at all, -1 if we're doing stats on everything. */ if (type == BNAMES) nlinks = 0; else if (ISSET(FTS_NOSTAT) && ISSET(FTS_PHYSICAL)) { nlinks = cur->fts_nlink - (ISSET(FTS_SEEDOT) ? 0 : 2); nostat = 1; } else { nlinks = -1; nostat = 0; } #ifdef notdef (void)printf("nlinks == %d (cur: %u)\n", nlinks, cur->fts_nlink); (void)printf("NOSTAT %d PHYSICAL %d SEEDOT %d\n", ISSET(FTS_NOSTAT), ISSET(FTS_PHYSICAL), ISSET(FTS_SEEDOT)); #endif /* * If we're going to need to stat anything or we want to descend * and stay in the directory, chdir. If this fails we keep going, * but set a flag so we don't chdir after the post-order visit. * We won't be able to stat anything, but we can still return the * names themselves. Note, that since fts_read won't be able to * chdir into the directory, it will have to return different path * names than before, i.e. "a/b" instead of "b". Since the node * has already been visited in pre-order, have to wait until the * post-order visit to return the error. There is a special case * here, if there was nothing to stat then it's not an error to * not be able to stat. This is all fairly nasty. If a program * needed sorted entries or stat information, they had better be * checking FTS_NS on the returned nodes. */ cderrno = 0; if (nlinks || type == BREAD) { if (fts_safe_changedir(sp, cur, dirfd(dirp), NULL)) { if (nlinks && type == BREAD) cur->fts_errno = errno; cur->fts_flags |= FTS_DONTCHDIR; descend = 0; cderrno = errno; (void)closedir(dirp); dirp = NULL; } else descend = 1; } else descend = 0; /* * Figure out the max file name length that can be stored in the * current path -- the inner loop allocates more path as necessary. * We really wouldn't have to do the maxlen calculations here, we * could do them in fts_read before returning the path, but it's a * lot easier here since the length is part of the dirent structure. * * If not changing directories set a pointer so that can just append * each new name into the path. */ len = NAPPEND(cur); if (ISSET(FTS_NOCHDIR)) { cp = sp->fts_path + len; *cp++ = '/'; } len++; maxlen = sp->fts_pathlen - len; /* * fts_level is signed so we must prevent it from wrapping * around to FTS_ROOTLEVEL and FTS_ROOTPARENTLEVEL. */ level = cur->fts_level; if (level < FTS_MAXLEVEL) level++; /* Read the directory, attaching each entry to the `link' pointer. */ doadjust = 0; for (head = tail = NULL, nitems = 0; dirp && (dp = readdir(dirp));) { if (!ISSET(FTS_SEEDOT) && ISDOT(dp->d_name)) continue; if (!(p = fts_alloc(sp, dp->d_name, (size_t)dp->d_namlen))) goto mem1; if (dp->d_namlen >= maxlen) { /* include space for NUL */ oldaddr = sp->fts_path; if (fts_palloc(sp, dp->d_namlen +len + 1)) { /* * No more memory for path or structures. Save * errno, free up the current structure and the * structures already allocated. */ mem1: saved_errno = errno; if (p) free(p); fts_lfree(head); (void)closedir(dirp); cur->fts_info = FTS_ERR; SET(FTS_STOP); errno = saved_errno; return (NULL); } /* Did realloc() change the pointer? */ if (oldaddr != sp->fts_path) { doadjust = 1; if (ISSET(FTS_NOCHDIR)) cp = sp->fts_path + len; } maxlen = sp->fts_pathlen - len; } p->fts_level = level; p->fts_parent = sp->fts_cur; p->fts_pathlen = len + dp->d_namlen; if (p->fts_pathlen < len) { /* * If we wrap, free up the current structure and * the structures already allocated, then error * out with ENAMETOOLONG. */ free(p); fts_lfree(head); (void)closedir(dirp); cur->fts_info = FTS_ERR; SET(FTS_STOP); errno = ENAMETOOLONG; return (NULL); } if (cderrno) { if (nlinks) { p->fts_info = FTS_NS; p->fts_errno = cderrno; } else p->fts_info = FTS_NSOK; p->fts_accpath = cur->fts_accpath; } else if (nlinks == 0 #ifdef DT_DIR || (nostat && dp->d_type != DT_DIR && dp->d_type != DT_UNKNOWN) #endif ) { p->fts_accpath = ISSET(FTS_NOCHDIR) ? p->fts_path : p->fts_name; p->fts_info = FTS_NSOK; } else { /* Build a file name for fts_stat to stat. */ if (ISSET(FTS_NOCHDIR)) { p->fts_accpath = p->fts_path; memmove(cp, p->fts_name, p->fts_namelen + 1); } else p->fts_accpath = p->fts_name; /* Stat it. */ p->fts_info = fts_stat(sp, p, 0); /* Decrement link count if applicable. */ if (nlinks > 0 && (p->fts_info == FTS_D || p->fts_info == FTS_DC || p->fts_info == FTS_DOT)) --nlinks; } /* We walk in directory order so "ls -f" doesn't get upset. */ p->fts_link = NULL; if (head == NULL) head = tail = p; else { tail->fts_link = p; tail = p; } ++nitems; } if (dirp) (void)closedir(dirp); /* * If realloc() changed the address of the path, adjust the * addresses for the rest of the tree and the dir list. */ if (doadjust) fts_padjust(sp, head); /* * If not changing directories, reset the path back to original * state. */ if (ISSET(FTS_NOCHDIR)) { if (len == sp->fts_pathlen || nitems == 0) --cp; *cp = '\0'; } /* * If descended after called from fts_children or after called from * fts_read and nothing found, get back. At the root level we use * the saved fd; if one of fts_open()'s arguments is a relative path * to an empty directory, we wind up here with no other way back. If * can't get back, we're done. */ if (descend && (type == BCHILD || !nitems) && (cur->fts_level == FTS_ROOTLEVEL ? FCHDIR(sp, sp->fts_rfd) : fts_safe_changedir(sp, cur->fts_parent, -1, ".."))) { cur->fts_info = FTS_ERR; SET(FTS_STOP); return (NULL); } /* If didn't find anything, return NULL. */ if (!nitems) { if (type == BREAD) cur->fts_info = FTS_DP; return (NULL); } /* Sort the entries. */ if (sp->fts_compar && nitems > 1) head = fts_sort(sp, head, nitems); return (head); }
static int vfs_mount_9p(mount_t mp, vnode_t devvp, user_addr_t data, vfs_context_t ctx) { #pragma unused(devvp) struct sockaddr *addr, *authaddr; struct vfsstatfs *sp; char authkey[DESKEYLEN+1]; kauth_cred_t cred; user_args_9p args; mount_9p *nmp; size_t size; fid_9p fid; qid_9p qid; char *vers; int e; TRACE(); nmp = NULL; addr = NULL; authaddr = NULL; fid = NOFID; if (vfs_isupdate(mp)) return ENOTSUP; if (vfs_context_is64bit(ctx)) { if ((e=copyin(data, &args, sizeof(args)))) goto error; } else { args_9p args32; if ((e=copyin(data, &args32, sizeof(args32)))) goto error; args.spec = CAST_USER_ADDR_T(args32.spec); args.addr = CAST_USER_ADDR_T(args32.addr); args.addrlen = args32.addrlen; args.authaddr = CAST_USER_ADDR_T(args32.authaddr); args.authaddrlen = args32.authaddrlen; args.volume = CAST_USER_ADDR_T(args32.volume); args.uname = CAST_USER_ADDR_T(args32.uname); args.aname = CAST_USER_ADDR_T(args32.aname); args.authkey = CAST_USER_ADDR_T(args32.authkey); args.flags = args32.flags; } e = ENOMEM; nmp = malloc_9p(sizeof(*nmp)); if (nmp == NULL) return e; nmp->mp = mp; TAILQ_INIT(&nmp->req); nmp->lck = lck_mtx_alloc_init(lck_grp_9p, LCK_ATTR_NULL); nmp->reqlck = lck_mtx_alloc_init(lck_grp_9p, LCK_ATTR_NULL); nmp->nodelck = lck_mtx_alloc_init(lck_grp_9p, LCK_ATTR_NULL); nmp->node = hashinit(desiredvnodes, M_TEMP, &nmp->nodelen); if (nmp->lck==NULL || nmp->reqlck==NULL || nmp->nodelck==NULL || nmp->node==NULL) goto error; if ((e=nameget_9p(args.volume, &nmp->volume))) goto error; if ((e=nameget_9p(args.uname, &nmp->uname))) goto error; if ((e=nameget_9p(args.aname, &nmp->aname))) goto error; cred = vfs_context_ucred(ctx); if (IS_VALID_CRED(cred)) { nmp->uid = kauth_cred_getuid(cred); nmp->gid = kauth_cred_getgid(cred); } else { nmp->uid = KAUTH_UID_NONE; nmp->gid = KAUTH_GID_NONE; } vfs_getnewfsid(mp); vfs_setfsprivate(mp, nmp); nmp->flags = args.flags; if ((e=addrget_9p(args.addr, args.addrlen, &addr))) goto error; if ((e=connect_9p(nmp, addr))) goto error; vers = VERSION9P; if (ISSET(nmp->flags, FLAG_DOTU)) vers = VERSION9PDOTU; if ((e=version_9p(nmp, vers, &nmp->version))) goto error; if (ISSET(nmp->flags, FLAG_DOTU) && strcmp(VERSION9PDOTU, nmp->version)==0) SET(nmp->flags, F_DOTU); nmp->afid = NOFID; if (args.authaddr && args.authaddrlen && args.authkey) { if ((e=copyin(args.authkey, authkey, DESKEYLEN))) goto error; if ((e=addrget_9p(args.authaddr, args.authaddrlen, &authaddr))) goto error; if ((e=auth_9p(nmp, nmp->uname, nmp->aname, nmp->uid, &nmp->afid, &qid))) goto error; if (nmp->afid!=NOFID && (e=authp9any_9p(nmp, nmp->afid, authaddr, nmp->uname, authkey))) goto error; bzero(authkey, DESKEYLEN); } if ((e=attach_9p(nmp, nmp->uname, nmp->aname, nmp->afid, nmp->uid, &fid, &qid))) goto error; if ((e=nget_9p(nmp, fid, qid, NULL, &nmp->root, NULL, ctx))) goto error; nunlock_9p(NTO9P(nmp->root)); e = vnode_ref(nmp->root); vnode_put(nmp->root); if (e) goto error; vfs_setauthopaque(mp); vfs_clearauthopaqueaccess(mp); vfs_setlocklocal(mp); // init stats sp = vfs_statfs(nmp->mp); copyinstr(args.spec, sp->f_mntfromname, MNAMELEN-1, &size); bzero(sp->f_mntfromname+size, MNAMELEN-size); sp->f_bsize = PAGE_SIZE; sp->f_iosize = nmp->msize-IOHDRSZ; sp->f_blocks = sp->f_bfree = sp->f_bavail = sp->f_bused = -1; sp->f_files = 65535; sp->f_ffree = sp->f_files-2; sp->f_flags = vfs_flags(mp); free_9p(addr); free_9p(authaddr); return 0; error: bzero(authkey, DESKEYLEN); free_9p(addr); free_9p(authaddr); if (nmp->so) { clunk_9p(nmp, fid); disconnect_9p(nmp); } freemount_9p(nmp); vfs_setfsprivate(mp, NULL); return e; }
FTS * fts_open(char * const *argv, int options, int (*compar)(const FTSENT **, const FTSENT **)) { FTS *sp; FTSENT *p, *root; int nitems; FTSENT *parent, *tmp; size_t len; /* Options check. */ if (options & ~FTS_OPTIONMASK) { errno = EINVAL; return (NULL); } /* Allocate/initialize the stream */ if ((sp = calloc(1, sizeof(FTS))) == NULL) return (NULL); sp->fts_compar = compar; sp->fts_options = options; /* Logical walks turn on NOCHDIR; symbolic links are too hard. */ if (ISSET(FTS_LOGICAL)) SET(FTS_NOCHDIR); /* * Start out with 1K of path space, and enough, in any case, * to hold the user's paths. */ if (fts_palloc(sp, MAX(fts_maxarglen(argv), PATH_MAX))) goto mem1; /* Allocate/initialize root's parent. */ if ((parent = fts_alloc(sp, "", 0)) == NULL) goto mem2; parent->fts_level = FTS_ROOTPARENTLEVEL; /* Allocate/initialize root(s). */ for (root = NULL, nitems = 0; *argv; ++argv, ++nitems) { /* Don't allow zero-length paths. */ if ((len = strlen(*argv)) == 0) { errno = ENOENT; goto mem3; } if ((p = fts_alloc(sp, *argv, len)) == NULL) goto mem3; p->fts_level = FTS_ROOTLEVEL; p->fts_parent = parent; p->fts_accpath = p->fts_name; p->fts_info = fts_stat(sp, p, ISSET(FTS_COMFOLLOW)); /* Command-line "." and ".." are real directories. */ if (p->fts_info == FTS_DOT) p->fts_info = FTS_D; /* * If comparison routine supplied, traverse in sorted * order; otherwise traverse in the order specified. */ if (compar) { p->fts_link = root; root = p; } else { p->fts_link = NULL; if (root == NULL) tmp = root = p; else { tmp->fts_link = p; tmp = p; } } } if (compar && nitems > 1) root = fts_sort(sp, root, nitems); /* * Allocate a dummy pointer and make fts_read think that we've just * finished the node before the root(s); set p->fts_info to FTS_INIT * so that everything about the "current" node is ignored. */ if ((sp->fts_cur = fts_alloc(sp, "", 0)) == NULL) goto mem3; sp->fts_cur->fts_link = root; sp->fts_cur->fts_info = FTS_INIT; /* * If using chdir(2), grab a file descriptor pointing to dot to ensure * that we can get back here; this could be avoided for some paths, * but almost certainly not worth the effort. Slashes, symbolic links, * and ".." are all fairly nasty problems. Note, if we can't get the * descriptor we run anyway, just more slowly. */ if (!ISSET(FTS_NOCHDIR) && (sp->fts_rfd = open(".", O_RDONLY, 0)) < 0) SET(FTS_NOCHDIR); if (nitems == 0) free(parent); return (sp); mem3: fts_lfree(root); free(parent); mem2: free(sp->fts_path); mem1: free(sp); return (NULL); }
namespace OS { auto defaultFont() -> QFont { return QFontDatabase::systemFont(QFontDatabase::GeneralFont); } #ifndef Q_OS_WIN auto canAssociateFileTypes() -> bool { return false; } auto unassociateFileTypes(QWindow *, bool) -> bool { return false; } auto associateFileTypes(QWindow *, bool, const QStringList &) -> bool { return false; } auto defaultFixedFont() -> QFont { return QFontDatabase::systemFont(QFontDatabase::FixedFont); } #endif #ifndef Q_OS_LINUX auto screensaverMethods() -> QStringList { return { u"auto"_q }; } auto setScreensaverMethod(const QString &) -> void { } #endif auto getHwAcc() -> HwAcc*; auto hwAcc() -> HwAcc* { auto api = getHwAcc(); if (!api) { static HwAcc none; api = &none; } return api; } auto HwAcc::fullCodecList() -> QList<CodecId> { static const QList<CodecId> ids = QList<CodecId>() << CodecId::Mpeg1 << CodecId::Mpeg2 << CodecId::Mpeg4 << CodecId::H264 << CodecId::Vc1 << CodecId::Wmv3 << CodecId::Hevc; return ids; } struct ApiInfo { HwAcc::Api api; QString name, desc; }; const std::array<ApiInfo, HwAcc::NoApi> s_infos = [] () { std::array<ApiInfo, HwAcc::NoApi> ret; #define SET(a, n, d) {ret[HwAcc::a] = {HwAcc::a, n, d};} SET(VaApiGLX, u"vaapi"_q, u"VA-API(Video Acceleration API)"_q); SET(VdpauX11, u"vdpau"_q, u"VDPAU(Video Decode and Presentation API for Unix)"_q ); SET(Dxva2Copy, u"dxva2-copy"_q, u"DXVA 2.0(DirectX Video Accelaction 2.0)"_q ); #undef SET return ret; }(); struct HwAcc::Data { Api api = NoApi; QList<CodecId> codecs; QList<DeintMethod> deints; }; HwAcc::HwAcc(Api api) : d(new Data) { d->api = api; } HwAcc::~HwAcc() { delete d; } auto HwAcc::isAvailable() const -> bool { return d->api != NoApi; } auto HwAcc::supports(CodecId codec) -> bool { return d->codecs.contains(codec); } auto HwAcc::supports(DeintMethod method) -> bool { return d->deints.contains(method); } auto HwAcc::api() const -> Api { return d->api; } auto HwAcc::name() const -> QString { return name(d->api); } auto HwAcc::description() const -> QString { return description(d->api); } auto HwAcc::name(Api api) -> QString { if (_InRange0(api, NoApi)) return s_infos[api].name; return QString(); } auto HwAcc::description(Api api) -> QString { if (_InRange0(api, NoApi)) return s_infos[api].desc; return QString(); } auto HwAcc::api(const QString &name) -> Api { for (auto &info : s_infos) { if (info.name == name) return info.api; } return NoApi; } auto HwAcc::setSupportedCodecs(const QList<CodecId> &codecs) -> void { d->codecs = codecs; } auto HwAcc::setSupportedDeints(const QList<DeintMethod> &deints) -> void { d->deints = deints; } auto HwAcc::download(mp_hwdec_ctx *, const mp_image *, mp_image_pool *) -> mp_image* { return nullptr; } #ifndef Q_OS_WIN auto setImeEnabled(QWindow *w, bool enabled) -> void { Q_UNUSED(w); Q_UNUSED(enabled); } #endif WindowAdapter::WindowAdapter(QWindow *parent) : QObject(parent) { m_window = parent; #ifndef Q_OS_WIN connect(m_window, &QWindow::windowStateChanged, this, &WindowAdapter::setState); #endif } auto WindowAdapter::setFramelessHint(bool frameless) -> void { auto flags = m_window->flags(); if (frameless) flags |= Qt::FramelessWindowHint; else flags &= ~Qt::FramelessWindowHint; m_window->setFlags(flags); } auto WindowAdapter::setFullScreenHint(bool fs) -> void { m_window->setWindowState(fs ? Qt::WindowFullScreen : m_oldState); } auto WindowAdapter::isFullScreen() const -> bool { return m_window->windowState() & Qt::WindowFullScreen; } auto WindowAdapter::setFullScreen(bool fs) -> void { auto visible = m_window->isVisible(); setFullScreenHint(fs); if (visible) m_window->setVisible(true); } auto WindowAdapter::setState(Qt::WindowState ws) -> void { if (m_state != ws) { m_oldState = m_state; m_state = ws; emit stateChanged(m_state, m_oldState); } } auto WindowAdapter::startMoveByDrag(const QPointF &m) -> void { m_started = true; m_mouseStartPos = m.toPoint(); m_winStartPos = m_window->position(); } auto WindowAdapter::positionArea(const QRect &r, const QSize &s) const -> QRect { const auto m = frameMargins(); return r.adjusted(m.left(), m.top(), -m.right() - s.width() + 1, -m.bottom() - s.height() + 1); } auto WindowAdapter::snapHint(const QPoint &pos, const QSize &size, Qt::Edges edges, int threshold) const -> QPoint { auto p = pos; const auto s = positionArea(m_window->screen()->availableGeometry(), size); const auto g = positionArea(m_window->screen()->geometry(), size); auto check = [&] (int &p, int v) -> bool { return (qAbs(p - v) > threshold) ? false : (p = v, true); }; bool x = false, y = false; x = !x && (edges & Qt::LeftEdge) && (check(p.rx(), s.left()) || check(p.rx(), g.left())); x = !x && (edges & Qt::RightEdge) && (check(p.rx(), s.right()) || check(p.rx(), g.right())); y = !y && (edges & Qt::TopEdge) && (check(p.ry(), s.top()) || check(p.ry(), g.top())); y = !y && (edges & Qt::BottomEdge) && (check(p.ry(), s.bottom()) || check(p.ry(), g.bottom())); return p; } auto WindowAdapter::snapHint(const QPoint &pos, Qt::Edges edges, int threshold) const -> QPoint { return snapHint(pos, m_window->size(), edges, threshold); } auto WindowAdapter::moveByDrag(const QPointF &m) -> void { if (m_started) { auto p = m_winStartPos + (m.toPoint() - m_mouseStartPos); if (isSnappableToEdge()) p = snapHint(p); m_window->setPosition(p); setMovingByDrag(true); } } auto WindowAdapter::endMoveByDrag() -> void { setMovingByDrag(false); m_started = false; m_mouseStartPos = m_winStartPos = QPoint(); } auto WindowAdapter::isFrameless() const -> bool { return m_window->flags() & Qt::FramelessWindowHint; } auto WindowAdapter::setFrameless(bool frameless) -> void { if (WindowAdapter::isFrameless() == frameless) return; const bool visible = m_window->isVisible(); setFramelessHint(frameless); if (visible) m_window->show(); } auto createAdapter(QWindow *w) -> WindowAdapter*; auto adapter(QWindow *w) -> WindowAdapter* { static const constexpr char *property = "_b_window_adpater"; auto a = static_cast<WindowAdapter*>(w->property(property).value<WindowAdapter*>()); if (!a) { a = createAdapter(w); w->setProperty(property, QVariant::fromValue(a)); } return a; } }
/* NS990113 */ static void rlc_a(void) { UINT8 i=M_Cy; if (R.A & 0x80) SET(C_FLAG); else CLR(C_FLAG); R.A <<= 1; if (i) R.A |= 0x01; else R.A &= 0xfe; }
token CTok; int &line = CTok.at_line; static char *Cpp; static int Ci, Clen; /****************************************************************************** Maybe this is faster than ctype.h macros The first 127 ASCII characters is a universal constant. ******************************************************************************/ static char ll_ctypes [256]; static void initctypes () { #define SET(x,y) ll_ctypes [(int)x] = y; SET('A',2) SET('B',2) SET('C',2) SET('D',2) SET('E',2) SET('F',3) SET('G',2) SET('H',2) SET('I',2) SET('J',2) SET('K',2) SET('L',3) SET('M',2) SET('N',2) SET('O',2) SET('P',2) SET('Q',2) SET('R',2) SET('S',2) SET('T',2) SET('U',3) SET('V',2) SET('W',2) SET('X',2) SET('Y',2) SET('Z',2) SET('a',2) SET('b',2) SET('c',2) SET('d',2) SET('e',2) SET('f',3) SET('g',2) SET('h',2) SET('i',2) SET('j',2) SET('k',2) SET('l',3) SET('m',2) SET('n',2) SET('o',2) SET('p',2) SET('q',2) SET('r',2) SET('s',2) SET('t',2) SET('u',3) SET('v',2) SET('w',2) SET('x',2) SET('y',2) SET('z',2) SET('_',2) SET('0',1) SET('1',1) SET('2',1) SET('3',1) SET('4',1) SET('5',1) SET('6',1) SET('7',1) SET('8',1) SET('9',1) } #define ISNIEND(x) (ll_ctypes [(int)x] == 3) #define ISALPHA(x) (ll_ctypes [(int)x] >= 2) #define ISDIGIT(x) (ll_ctypes [(int)x] == 1)
int main() { SshTimeMeasure total_timer; SshTimeMeasure timer_1; SshTimeMeasure timer_2; SshTimeMeasure timer_3; SshTimeMeasure timer_4; SshTimeMeasure timer_5; static struct SshTimeMeasureRec timer_6_rec = SSH_TIME_MEASURE_INITIALIZER; SshTimeMeasure timer_6; int i; double rv = 0.0; int ev = 0; #ifdef HAVE_GETTIMEOFDAY struct timeval tv; #endif /* HAVE_GETTIMEOFDAY */ SshUInt64 seconds; SshUInt32 nanoseconds; total_timer = ssh_time_measure_allocate(); timer_1 = ssh_time_measure_allocate(); timer_2 = ssh_time_measure_allocate(); timer_3 = ssh_time_measure_allocate(); timer_4 = ssh_time_measure_allocate(); timer_5 = ssh_time_measure_allocate(); timer_6 = &timer_6_rec; if (ssh_time_measure_get(timer_5, SSH_TIME_GRANULARITY_NANOSECOND) != 0) { ssh_warning("Weird initial stamp value.\n"); ev++; } if (ssh_time_measure_get(timer_6, SSH_TIME_GRANULARITY_NANOSECOND) != 0) { ssh_warning("Weird initial (static) stamp value.\n"); ev++; } rv = (double)ssh_time_measure_get(total_timer, SSH_TIME_GRANULARITY_SECOND); if ((rv < 0.0) || (rv > 0.0)) { ssh_warning("Weird initial value.\n"); ev++; } ssh_time_measure_granularity(&seconds, &nanoseconds); if ((seconds == 0) && (nanoseconds == 0)) { ssh_warning("Weird granularity.\n"); ev++; } else { printf("granularity is %lu sec %lu nsec\n", (unsigned long)seconds, (unsigned long)nanoseconds); } START(total_timer); START(timer_1); START(timer_3); START(timer_4); START(timer_5); STAMP(total_timer); printf("testing stamps\n"); NANOSTAMP(timer_1); MICROSTAMP(timer_1); MILLISTAMP(timer_1); STAMP(timer_1); USLEEP(1000000); NANOSTAMP(timer_1); MICROSTAMP(timer_1); MILLISTAMP(timer_1); STAMP(timer_1); USLEEP(1000000); NANOSTAMP(timer_1); MICROSTAMP(timer_1); MILLISTAMP(timer_1); STAMP(timer_1); USLEEP(1000000); NANOSTAMP(timer_1); MICROSTAMP(timer_1); MILLISTAMP(timer_1); STAMP(timer_1); CHECKNANOSTAMP(timer_1); USLEEP(1000000); NANOSTAMP(timer_1); MICROSTAMP(timer_1); MILLISTAMP(timer_1); STAMP(timer_1); CHECKNANOSTAMP(timer_1); USLEEP(1000000); NANOSTAMP(timer_1); MICROSTAMP(timer_1); MILLISTAMP(timer_1); STAMP(timer_1); CHECKNANOSTAMP(timer_1); USLEEP(1000000); NANOSTAMP(timer_1); MICROSTAMP(timer_1); MILLISTAMP(timer_1); STAMP(timer_1); CHECKNANOSTAMP(timer_1); USLEEP(2000000); STAMP(total_timer); SET(timer_5, 12345, 12345678); INTERMEDIATE(timer_5); if ((rv < 12345.0) || (rv > 12350.0)) { ssh_warning("Weird intermediate after running set.\n"); ev++; } INTERMEDIATE(timer_1); if (rv < 1.0) { ssh_warning("Weird intermediate.\n"); ev++; } STOP(timer_3); if (rv < 1.0) { ssh_warning("Weird stop value.\n"); ev++; } START(timer_2); RESET(timer_4); USLEEP(3000000); STAMP(total_timer); INTERMEDIATE(timer_2); INTERMEDIATE(timer_5); START(timer_3); if (rv < 1.0) { ssh_warning("Weird restart value.\n"); ev++; } RESET(timer_4); STOP(timer_1); USLEEP(4000000); STAMP(total_timer); STOP(timer_5); #ifdef SSHUINT64_IS_64BITS printf("Setting timer_5 to big value.\n"); ssh_time_measure_set_value(timer_5, ((SshUInt64)0xffffffff) * ((SshUInt64)30), 987654321); INTERMEDIATE(timer_5); if ((rv < 128849018000.0) || (rv > 128849019000.0)) { ssh_warning("Weird intermediate after stopped set.\n"); ev++; } #else SET(timer_5, 1234567890, 987654321); INTERMEDIATE(timer_5); if ((rv < 1234567890.0) || (rv > 1234567900.0)) { ssh_warning("Weird intermediate after stopped set.\n"); ev++; } #endif STOP(timer_4); STOP(timer_3); STOP(timer_2); STOP(timer_1); #define TIMESTAMPS 1000000 ssh_time_measure_reset(timer_1); ssh_time_measure_reset(timer_2); printf("\nGenerating %d timestamps.\n", TIMESTAMPS); START(timer_2); START(timer_1); for (i = 1; i < TIMESTAMPS; i++) { ssh_time_measure_stamp(timer_2, SSH_TIME_GRANULARITY_MICROSECOND); } STOP(timer_1); STOP(timer_2); printf("Time elapsed %.12f seconds (%.12f seconds/timestamp", (double)ssh_time_measure_get(timer_1, SSH_TIME_GRANULARITY_SECOND), (double)ssh_time_measure_get(timer_1, SSH_TIME_GRANULARITY_SECOND) / (double)TIMESTAMPS); if ((double)ssh_time_measure_get(timer_1, SSH_TIME_GRANULARITY_SECOND) > 0.0) printf(", %d timestamps/second", (int)((double)TIMESTAMPS / (double)ssh_time_measure_get(timer_1, SSH_TIME_GRANULARITY_SECOND))); printf(")\n"); ssh_time_measure_reset(timer_3); ssh_time_measure_reset(timer_4); printf("\nFor reference generating %d timestamps with time(3).\n", TIMESTAMPS); START(timer_4); START(timer_3); for (i = 1; i < TIMESTAMPS; i++) { ssh_time(); } STOP(timer_3); STOP(timer_4); printf("Time elapsed %.12f seconds (%.12f seconds/timestamp", (double)ssh_time_measure_get(timer_3, SSH_TIME_GRANULARITY_SECOND), (double)ssh_time_measure_get(timer_3, SSH_TIME_GRANULARITY_SECOND) / (double)TIMESTAMPS); if ((double)ssh_time_measure_get(timer_3, SSH_TIME_GRANULARITY_SECOND) > 0.0) printf(", %d timestamps/second", (int)((double)TIMESTAMPS / (double)ssh_time_measure_get(timer_3, SSH_TIME_GRANULARITY_SECOND))); printf(")\n"); if (((double)ssh_time_measure_get(timer_1, SSH_TIME_GRANULARITY_SECOND) > 0.0) && ((double)ssh_time_measure_get(timer_3, SSH_TIME_GRANULARITY_SECOND) > 0.0)) printf("Using time(3) is %2.1f%% faster than ssh_..._stamp.\n", (((double)ssh_time_measure_get(timer_1, SSH_TIME_GRANULARITY_SECOND) - (double)ssh_time_measure_get(timer_3, SSH_TIME_GRANULARITY_SECOND)) / (double)ssh_time_measure_get(timer_1, SSH_TIME_GRANULARITY_SECOND)) * 100.0); #ifdef HAVE_GETTIMEOFDAY ssh_time_measure_reset(timer_3); ssh_time_measure_reset(timer_4); printf("\nFor reference generating %d timestamps with gettimeofday.\n", TIMESTAMPS); START(timer_4); START(timer_3); for (i = 1; i < TIMESTAMPS; i++) { gettimeofday(&tv, NULL); } STOP(timer_3); STOP(timer_4); printf("Time elapsed %.12f seconds (%.12f seconds/timestamp", (double)ssh_time_measure_get(timer_3, SSH_TIME_GRANULARITY_SECOND), (double)ssh_time_measure_get(timer_3, SSH_TIME_GRANULARITY_SECOND) / (double)TIMESTAMPS); if ((double)ssh_time_measure_get(timer_3, SSH_TIME_GRANULARITY_SECOND) > 0.0) printf(", %d timestamps/second", (int)((double)TIMESTAMPS / (double)ssh_time_measure_get(timer_3, SSH_TIME_GRANULARITY_SECOND))); printf(")\n"); if (((double)ssh_time_measure_get(timer_1, SSH_TIME_GRANULARITY_SECOND) > 0.0) && ((double)ssh_time_measure_get(timer_3, SSH_TIME_GRANULARITY_SECOND) > 0.0)) printf("Using gettimeofday(3) is %2.1f%% faster than ssh_..._stamp.\n", (((double)ssh_time_measure_get(timer_1, SSH_TIME_GRANULARITY_SECOND) - (double)ssh_time_measure_get(timer_3, SSH_TIME_GRANULARITY_SECOND)) / (double)ssh_time_measure_get(timer_1, SSH_TIME_GRANULARITY_SECOND)) * 100.0); #endif /* HAVE_GETTIMEOFDAY */ printf("making start stop test. timers are silently started and stopped.\n"); printf("timer_3 runs while timer_4 is started and stopped in loop.\n"); ssh_time_measure_stop(timer_3); ssh_time_measure_stop(timer_4); ssh_time_measure_reset(timer_3); ssh_time_measure_reset(timer_4); ssh_time_measure_start(timer_3); for (i = 0; i < 1000000; i++) { ssh_time_measure_start(timer_4); ssh_time_measure_stop(timer_4); } ssh_time_measure_stop(timer_3); INTERMEDIATE(timer_4); INTERMEDIATE(timer_3); STOP(total_timer); GET_INT(timer_1); INTERMEDIATE(timer_1); GET_INT(timer_2); INTERMEDIATE(timer_2); GET_INT(timer_3); INTERMEDIATE(timer_3); GET_INT(timer_4); INTERMEDIATE(timer_4); GET_INT(timer_5); INTERMEDIATE(timer_5); GET_INT(total_timer); INTERMEDIATE(total_timer); printf("Testing granularities\n"); GET_NANOSECONDS(total_timer); GET_MICROSECONDS(total_timer); GET_MILLISECONDS(total_timer); GET_SECONDS(total_timer); GET_MINUTES(total_timer); GET_HOURS(total_timer); GET_DAYS(total_timer); GET_WEEKS(total_timer); GET_MONTHS(total_timer); GET_YEARS(total_timer); GET_NANOSECONDS(timer_5); GET_MICROSECONDS(timer_5); GET_MILLISECONDS(timer_5); GET_SECONDS(timer_5); GET_MINUTES(timer_5); GET_HOURS(timer_5); GET_DAYS(timer_5); GET_WEEKS(timer_5); GET_MONTHS(timer_5); GET_MONTHS_2(timer_5); GET_YEARS(timer_5); GET_YEARS_2(timer_5); GET_YEARS_3(timer_5); ssh_time_measure_free(timer_5); ssh_time_measure_free(timer_4); ssh_time_measure_free(timer_3); ssh_time_measure_free(timer_2); ssh_time_measure_free(timer_1); ssh_time_measure_free(total_timer); exit(ev); }