file
stringlengths
18
26
data
stringlengths
2
1.05M
the_stack_data/1230075.c
#include <stdlib.h> int main( void ) { struct { int node; int type; } lastglob[1] = { { 0 , 1 } }; if (lastglob[0].node != 0 || lastglob[0].type != 1) abort (); exit (0); }
the_stack_data/700575.c
// RUN: %ucc -S -o %t %s // RUN: [ `grep -c 'call.*f' < %t` -eq 1 ] int *f(); q() { ++*f(); }
the_stack_data/834591.c
int puts(const char *); static char *str; static void func(void) { puts(str); } static void (*getfunc(char *s))(void) { str = s; return func; } int arr[] = {1, 2}; int bar(void) { int *(a[2]); a[0] = &arr[0]; a[1] = &arr[1]; return *a[0] + *a[1]; } int main(void) { void (*foo)(void) = getfunc("Hello World!"); foo(); return bar(); }
the_stack_data/184518171.c
// RUN: 3c -alltypes -addcr %s -- | FileCheck -match-full-lines -check-prefixes="CHECK_ALL","CHECK" %s // RUN: 3c -addcr %s -- | FileCheck -match-full-lines -check-prefixes="CHECK_NOALL","CHECK" %s // RUN: 3c -addcr %s -- | %clang -c -fcheckedc-extension -x c -o /dev/null - // RUN: 3c -output-postfix=checked -alltypes %s // RUN: 3c -alltypes %S/inline_anon_structs.checked.c -- | count 0 // RUN: rm %S/inline_anon_structs.checked.c /*This code ensures conversion happens as expected when an inlinestruct and its associated VarDecl have different locations*/ int valuable; static struct foo { const char* name; //CHECK_NOALL: const char* name; //CHECK_ALL: _Ptr<const char> name; int* p_valuable; //CHECK: _Ptr<int> p_valuable; } array[] = { { "mystery", &valuable } }; /*This code is a series of more complex tests for inline structs*/ /* a, b, c below all stay as WILD pointers; d can be a _Ptr<...>*/ /* one decl; x rewrites to _Ptr<int> */ struct foo1 { int *x; } *a; //CHECK: struct foo1 { _Ptr<int> x; } *a; struct baz { int *z; }; //CHECK: struct baz { _Ptr<int> z; }; struct baz *d; //CHECK: _Ptr<struct baz> d = ((void *)0); struct bad { int* y; } *b, *c; //CHECK: struct bad { int* y; } *b, *c; /* two decls, y should be converted */ struct bar { int* y; } *e, *f; //CHECK: struct bar { _Ptr<int> y; } *e, *f; void foo(void) { a->x = (void*)0; b->y = (int *) 5; d->z = (void*)0; } /*This code tests anonymous structs */ struct { /*the fields of the anonymous struct are free to be marked checked*/ int *data; //CHECK_NOALL: int *data; //CHECK_ALL: _Array_ptr<int> data : count(4); /* but the actual pointer can't be */ } *x; /*ensure trivial conversion*/ void foo1(int *w) { //CHECK: void foo1(_Ptr<int> w) { x->data = malloc(sizeof(int)*4); x->data[1] = 4; } /*This code tests more complex variable declarations*/ struct alpha { int *data; //CHECK: _Ptr<int> data; }; struct alpha *al[4]; //CHECK_NOALL: struct alpha *al[4]; //CHECK_ALL: _Ptr<struct alpha> al _Checked[4] = {((void *)0)}; /*be should be made wild, whereas a should be converted*/ struct { int *a; //CHECK: _Ptr<int> a; } *be[4]; /*this code checks inline structs withiin functions*/ void foo2(int *x) { //CHECK: void foo2(_Ptr<int> x) { struct bar { int *x; } *y = 0; //CHECK: struct bar { _Ptr<int> x; } *y = 0; /*A non-pointer struct without an init will be marked wild*/ struct something { int *x; } z; //CHECK: struct something { int *x; } z; /*so will ones that are anonymous*/ struct { int *x; } a; //CHECK: struct { int *x; } a; /*if it have an initializer, the rewriter won't have trouble*/ struct { int * c; } b = {}; //CHECK: struct { _Ptr<int> c; } b = {}; }
the_stack_data/48576350.c
#include <math.h> #include <stdlib.h> #include <string.h> #include <stdio.h> #include <complex.h> #ifdef complex #undef complex #endif #ifdef I #undef I #endif #if defined(_WIN64) typedef long long BLASLONG; typedef unsigned long long BLASULONG; #else typedef long BLASLONG; typedef unsigned long BLASULONG; #endif #ifdef LAPACK_ILP64 typedef BLASLONG blasint; #if defined(_WIN64) #define blasabs(x) llabs(x) #else #define blasabs(x) labs(x) #endif #else typedef int blasint; #define blasabs(x) abs(x) #endif typedef blasint integer; typedef unsigned int uinteger; typedef char *address; typedef short int shortint; typedef float real; typedef double doublereal; typedef struct { real r, i; } complex; typedef struct { doublereal r, i; } doublecomplex; #ifdef _MSC_VER static inline _Fcomplex Cf(complex *z) {_Fcomplex zz={z->r , z->i}; return zz;} static inline _Dcomplex Cd(doublecomplex *z) {_Dcomplex zz={z->r , z->i};return zz;} static inline _Fcomplex * _pCf(complex *z) {return (_Fcomplex*)z;} static inline _Dcomplex * _pCd(doublecomplex *z) {return (_Dcomplex*)z;} #else static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;} static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;} static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;} static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;} #endif #define pCf(z) (*_pCf(z)) #define pCd(z) (*_pCd(z)) typedef int logical; typedef short int shortlogical; typedef char logical1; typedef char integer1; #define TRUE_ (1) #define FALSE_ (0) /* Extern is for use with -E */ #ifndef Extern #define Extern extern #endif /* I/O stuff */ typedef int flag; typedef int ftnlen; typedef int ftnint; /*external read, write*/ typedef struct { flag cierr; ftnint ciunit; flag ciend; char *cifmt; ftnint cirec; } cilist; /*internal read, write*/ typedef struct { flag icierr; char *iciunit; flag iciend; char *icifmt; ftnint icirlen; ftnint icirnum; } icilist; /*open*/ typedef struct { flag oerr; ftnint ounit; char *ofnm; ftnlen ofnmlen; char *osta; char *oacc; char *ofm; ftnint orl; char *oblnk; } olist; /*close*/ typedef struct { flag cerr; ftnint cunit; char *csta; } cllist; /*rewind, backspace, endfile*/ typedef struct { flag aerr; ftnint aunit; } alist; /* inquire */ typedef struct { flag inerr; ftnint inunit; char *infile; ftnlen infilen; ftnint *inex; /*parameters in standard's order*/ ftnint *inopen; ftnint *innum; ftnint *innamed; char *inname; ftnlen innamlen; char *inacc; ftnlen inacclen; char *inseq; ftnlen inseqlen; char *indir; ftnlen indirlen; char *infmt; ftnlen infmtlen; char *inform; ftnint informlen; char *inunf; ftnlen inunflen; ftnint *inrecl; ftnint *innrec; char *inblank; ftnlen inblanklen; } inlist; #define VOID void union Multitype { /* for multiple entry points */ integer1 g; shortint h; integer i; /* longint j; */ real r; doublereal d; complex c; doublecomplex z; }; typedef union Multitype Multitype; struct Vardesc { /* for Namelist */ char *name; char *addr; ftnlen *dims; int type; }; typedef struct Vardesc Vardesc; struct Namelist { char *name; Vardesc **vars; int nvars; }; typedef struct Namelist Namelist; #define abs(x) ((x) >= 0 ? (x) : -(x)) #define dabs(x) (fabs(x)) #define f2cmin(a,b) ((a) <= (b) ? (a) : (b)) #define f2cmax(a,b) ((a) >= (b) ? (a) : (b)) #define dmin(a,b) (f2cmin(a,b)) #define dmax(a,b) (f2cmax(a,b)) #define bit_test(a,b) ((a) >> (b) & 1) #define bit_clear(a,b) ((a) & ~((uinteger)1 << (b))) #define bit_set(a,b) ((a) | ((uinteger)1 << (b))) #define abort_() { sig_die("Fortran abort routine called", 1); } #define c_abs(z) (cabsf(Cf(z))) #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); } #ifdef _MSC_VER #define c_div(c, a, b) {Cf(c)._Val[0] = (Cf(a)._Val[0]/Cf(b)._Val[0]); Cf(c)._Val[1]=(Cf(a)._Val[1]/Cf(b)._Val[1]);} #define z_div(c, a, b) {Cd(c)._Val[0] = (Cd(a)._Val[0]/Cd(b)._Val[0]); Cd(c)._Val[1]=(Cd(a)._Val[1]/df(b)._Val[1]);} #else #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);} #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);} #endif #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));} #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));} #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));} //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));} #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));} #define d_abs(x) (fabs(*(x))) #define d_acos(x) (acos(*(x))) #define d_asin(x) (asin(*(x))) #define d_atan(x) (atan(*(x))) #define d_atn2(x, y) (atan2(*(x),*(y))) #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); } #define r_cnjg(R, Z) { pCf(R) = conjf(Cf(Z)); } #define d_cos(x) (cos(*(x))) #define d_cosh(x) (cosh(*(x))) #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 ) #define d_exp(x) (exp(*(x))) #define d_imag(z) (cimag(Cd(z))) #define r_imag(z) (cimagf(Cf(z))) #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x))) #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x))) #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) ) #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) ) #define d_log(x) (log(*(x))) #define d_mod(x, y) (fmod(*(x), *(y))) #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x))) #define d_nint(x) u_nint(*(x)) #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a))) #define d_sign(a,b) u_sign(*(a),*(b)) #define r_sign(a,b) u_sign(*(a),*(b)) #define d_sin(x) (sin(*(x))) #define d_sinh(x) (sinh(*(x))) #define d_sqrt(x) (sqrt(*(x))) #define d_tan(x) (tan(*(x))) #define d_tanh(x) (tanh(*(x))) #define i_abs(x) abs(*(x)) #define i_dnnt(x) ((integer)u_nint(*(x))) #define i_len(s, n) (n) #define i_nint(x) ((integer)u_nint(*(x))) #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b))) #define pow_dd(ap, bp) ( pow(*(ap), *(bp))) #define pow_si(B,E) spow_ui(*(B),*(E)) #define pow_ri(B,E) spow_ui(*(B),*(E)) #define pow_di(B,E) dpow_ui(*(B),*(E)) #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));} #define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));} #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));} #define s_cat(lpp, rpp, rnp, np, llp) { ftnlen i, nc, ll; char *f__rp, *lp; ll = (llp); lp = (lpp); for(i=0; i < (int)*(np); ++i) { nc = ll; if((rnp)[i] < nc) nc = (rnp)[i]; ll -= nc; f__rp = (rpp)[i]; while(--nc >= 0) *lp++ = *(f__rp)++; } while(--ll >= 0) *lp++ = ' '; } #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d)))) #define s_copy(A,B,C,D) { int __i,__m; for (__i=0, __m=f2cmin((C),(D)); __i<__m && (B)[__i] != 0; ++__i) (A)[__i] = (B)[__i]; } #define sig_die(s, kill) { exit(1); } #define s_stop(s, n) {exit(0);} static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n"; #define z_abs(z) (cabs(Cd(z))) #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));} #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));} #define myexit_() break; #define mycycle() continue; #define myceiling(w) {ceil(w)} #define myhuge(w) {HUGE_VAL} //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);} #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)} /* procedure parameter types for -A and -C++ */ #define F2C_proc_par_types 1 #ifdef __cplusplus typedef logical (*L_fp)(...); #else typedef logical (*L_fp)(); #endif static float spow_ui(float x, integer n) { float pow=1.0; unsigned long int u; if(n != 0) { if(n < 0) n = -n, x = 1/x; for(u = n; ; ) { if(u & 01) pow *= x; if(u >>= 1) x *= x; else break; } } return pow; } static double dpow_ui(double x, integer n) { double pow=1.0; unsigned long int u; if(n != 0) { if(n < 0) n = -n, x = 1/x; for(u = n; ; ) { if(u & 01) pow *= x; if(u >>= 1) x *= x; else break; } } return pow; } #ifdef _MSC_VER static _Fcomplex cpow_ui(complex x, integer n) { complex pow={1.0,0.0}; unsigned long int u; if(n != 0) { if(n < 0) n = -n, x.r = 1/x.r, x.i=1/x.i; for(u = n; ; ) { if(u & 01) pow.r *= x.r, pow.i *= x.i; if(u >>= 1) x.r *= x.r, x.i *= x.i; else break; } } _Fcomplex p={pow.r, pow.i}; return p; } #else static _Complex float cpow_ui(_Complex float x, integer n) { _Complex float pow=1.0; unsigned long int u; if(n != 0) { if(n < 0) n = -n, x = 1/x; for(u = n; ; ) { if(u & 01) pow *= x; if(u >>= 1) x *= x; else break; } } return pow; } #endif #ifdef _MSC_VER static _Dcomplex zpow_ui(_Dcomplex x, integer n) { _Dcomplex pow={1.0,0.0}; unsigned long int u; if(n != 0) { if(n < 0) n = -n, x._Val[0] = 1/x._Val[0], x._Val[1] =1/x._Val[1]; for(u = n; ; ) { if(u & 01) pow._Val[0] *= x._Val[0], pow._Val[1] *= x._Val[1]; if(u >>= 1) x._Val[0] *= x._Val[0], x._Val[1] *= x._Val[1]; else break; } } _Dcomplex p = {pow._Val[0], pow._Val[1]}; return p; } #else static _Complex double zpow_ui(_Complex double x, integer n) { _Complex double pow=1.0; unsigned long int u; if(n != 0) { if(n < 0) n = -n, x = 1/x; for(u = n; ; ) { if(u & 01) pow *= x; if(u >>= 1) x *= x; else break; } } return pow; } #endif static integer pow_ii(integer x, integer n) { integer pow; unsigned long int u; if (n <= 0) { if (n == 0 || x == 1) pow = 1; else if (x != -1) pow = x == 0 ? 1/x : 0; else n = -n; } if ((n > 0) || !(n == 0 || x == 1 || x != -1)) { u = n; for(pow = 1; ; ) { if(u & 01) pow *= x; if(u >>= 1) x *= x; else break; } } return pow; } static integer dmaxloc_(double *w, integer s, integer e, integer *n) { double m; integer i, mi; for(m=w[s-1], mi=s, i=s+1; i<=e; i++) if (w[i-1]>m) mi=i ,m=w[i-1]; return mi-s+1; } static integer smaxloc_(float *w, integer s, integer e, integer *n) { float m; integer i, mi; for(m=w[s-1], mi=s, i=s+1; i<=e; i++) if (w[i-1]>m) mi=i ,m=w[i-1]; return mi-s+1; } static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) { integer n = *n_, incx = *incx_, incy = *incy_, i; #ifdef _MSC_VER _Fcomplex zdotc = {0.0, 0.0}; if (incx == 1 && incy == 1) { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc._Val[0] += conjf(Cf(&x[i]))._Val[0] * Cf(&y[i])._Val[0]; zdotc._Val[1] += conjf(Cf(&x[i]))._Val[1] * Cf(&y[i])._Val[1]; } } else { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc._Val[0] += conjf(Cf(&x[i*incx]))._Val[0] * Cf(&y[i*incy])._Val[0]; zdotc._Val[1] += conjf(Cf(&x[i*incx]))._Val[1] * Cf(&y[i*incy])._Val[1]; } } pCf(z) = zdotc; } #else _Complex float zdotc = 0.0; if (incx == 1 && incy == 1) { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += conjf(Cf(&x[i])) * Cf(&y[i]); } } else { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]); } } pCf(z) = zdotc; } #endif static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) { integer n = *n_, incx = *incx_, incy = *incy_, i; #ifdef _MSC_VER _Dcomplex zdotc = {0.0, 0.0}; if (incx == 1 && incy == 1) { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc._Val[0] += conj(Cd(&x[i]))._Val[0] * Cd(&y[i])._Val[0]; zdotc._Val[1] += conj(Cd(&x[i]))._Val[1] * Cd(&y[i])._Val[1]; } } else { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc._Val[0] += conj(Cd(&x[i*incx]))._Val[0] * Cd(&y[i*incy])._Val[0]; zdotc._Val[1] += conj(Cd(&x[i*incx]))._Val[1] * Cd(&y[i*incy])._Val[1]; } } pCd(z) = zdotc; } #else _Complex double zdotc = 0.0; if (incx == 1 && incy == 1) { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += conj(Cd(&x[i])) * Cd(&y[i]); } } else { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]); } } pCd(z) = zdotc; } #endif static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) { integer n = *n_, incx = *incx_, incy = *incy_, i; #ifdef _MSC_VER _Fcomplex zdotc = {0.0, 0.0}; if (incx == 1 && incy == 1) { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc._Val[0] += Cf(&x[i])._Val[0] * Cf(&y[i])._Val[0]; zdotc._Val[1] += Cf(&x[i])._Val[1] * Cf(&y[i])._Val[1]; } } else { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc._Val[0] += Cf(&x[i*incx])._Val[0] * Cf(&y[i*incy])._Val[0]; zdotc._Val[1] += Cf(&x[i*incx])._Val[1] * Cf(&y[i*incy])._Val[1]; } } pCf(z) = zdotc; } #else _Complex float zdotc = 0.0; if (incx == 1 && incy == 1) { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += Cf(&x[i]) * Cf(&y[i]); } } else { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]); } } pCf(z) = zdotc; } #endif static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) { integer n = *n_, incx = *incx_, incy = *incy_, i; #ifdef _MSC_VER _Dcomplex zdotc = {0.0, 0.0}; if (incx == 1 && incy == 1) { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc._Val[0] += Cd(&x[i])._Val[0] * Cd(&y[i])._Val[0]; zdotc._Val[1] += Cd(&x[i])._Val[1] * Cd(&y[i])._Val[1]; } } else { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc._Val[0] += Cd(&x[i*incx])._Val[0] * Cd(&y[i*incy])._Val[0]; zdotc._Val[1] += Cd(&x[i*incx])._Val[1] * Cd(&y[i*incy])._Val[1]; } } pCd(z) = zdotc; } #else _Complex double zdotc = 0.0; if (incx == 1 && incy == 1) { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += Cd(&x[i]) * Cd(&y[i]); } } else { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]); } } pCd(z) = zdotc; } #endif /* -- translated by f2c (version 20000121). You must link the resulting object file with the libraries: -lf2c -lm (in that order) */ /* Table of constant values */ static integer c__1 = 1; /* > \brief \b CTPRFS */ /* =========== DOCUMENTATION =========== */ /* Online html documentation available at */ /* http://www.netlib.org/lapack/explore-html/ */ /* > \htmlonly */ /* > Download CTPRFS + dependencies */ /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/ctprfs. f"> */ /* > [TGZ]</a> */ /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/ctprfs. f"> */ /* > [ZIP]</a> */ /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/ctprfs. f"> */ /* > [TXT]</a> */ /* > \endhtmlonly */ /* Definition: */ /* =========== */ /* SUBROUTINE CTPRFS( UPLO, TRANS, DIAG, N, NRHS, AP, B, LDB, X, LDX, */ /* FERR, BERR, WORK, RWORK, INFO ) */ /* CHARACTER DIAG, TRANS, UPLO */ /* INTEGER INFO, LDB, LDX, N, NRHS */ /* REAL BERR( * ), FERR( * ), RWORK( * ) */ /* COMPLEX AP( * ), B( LDB, * ), WORK( * ), X( LDX, * ) */ /* > \par Purpose: */ /* ============= */ /* > */ /* > \verbatim */ /* > */ /* > CTPRFS provides error bounds and backward error estimates for the */ /* > solution to a system of linear equations with a triangular packed */ /* > coefficient matrix. */ /* > */ /* > The solution matrix X must be computed by CTPTRS or some other */ /* > means before entering this routine. CTPRFS does not do iterative */ /* > refinement because doing so cannot improve the backward error. */ /* > \endverbatim */ /* Arguments: */ /* ========== */ /* > \param[in] UPLO */ /* > \verbatim */ /* > UPLO is CHARACTER*1 */ /* > = 'U': A is upper triangular; */ /* > = 'L': A is lower triangular. */ /* > \endverbatim */ /* > */ /* > \param[in] TRANS */ /* > \verbatim */ /* > TRANS is CHARACTER*1 */ /* > Specifies the form of the system of equations: */ /* > = 'N': A * X = B (No transpose) */ /* > = 'T': A**T * X = B (Transpose) */ /* > = 'C': A**H * X = B (Conjugate transpose) */ /* > \endverbatim */ /* > */ /* > \param[in] DIAG */ /* > \verbatim */ /* > DIAG is CHARACTER*1 */ /* > = 'N': A is non-unit triangular; */ /* > = 'U': A is unit triangular. */ /* > \endverbatim */ /* > */ /* > \param[in] N */ /* > \verbatim */ /* > N is INTEGER */ /* > The order of the matrix A. N >= 0. */ /* > \endverbatim */ /* > */ /* > \param[in] NRHS */ /* > \verbatim */ /* > NRHS is INTEGER */ /* > The number of right hand sides, i.e., the number of columns */ /* > of the matrices B and X. NRHS >= 0. */ /* > \endverbatim */ /* > */ /* > \param[in] AP */ /* > \verbatim */ /* > AP is COMPLEX array, dimension (N*(N+1)/2) */ /* > The upper or lower triangular matrix A, packed columnwise in */ /* > a linear array. The j-th column of A is stored in the array */ /* > AP as follows: */ /* > if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j; */ /* > if UPLO = 'L', AP(i + (j-1)*(2n-j)/2) = A(i,j) for j<=i<=n. */ /* > If DIAG = 'U', the diagonal elements of A are not referenced */ /* > and are assumed to be 1. */ /* > \endverbatim */ /* > */ /* > \param[in] B */ /* > \verbatim */ /* > B is COMPLEX array, dimension (LDB,NRHS) */ /* > The right hand side matrix B. */ /* > \endverbatim */ /* > */ /* > \param[in] LDB */ /* > \verbatim */ /* > LDB is INTEGER */ /* > The leading dimension of the array B. LDB >= f2cmax(1,N). */ /* > \endverbatim */ /* > */ /* > \param[in] X */ /* > \verbatim */ /* > X is COMPLEX array, dimension (LDX,NRHS) */ /* > The solution matrix X. */ /* > \endverbatim */ /* > */ /* > \param[in] LDX */ /* > \verbatim */ /* > LDX is INTEGER */ /* > The leading dimension of the array X. LDX >= f2cmax(1,N). */ /* > \endverbatim */ /* > */ /* > \param[out] FERR */ /* > \verbatim */ /* > FERR is REAL array, dimension (NRHS) */ /* > The estimated forward error bound for each solution vector */ /* > X(j) (the j-th column of the solution matrix X). */ /* > If XTRUE is the true solution corresponding to X(j), FERR(j) */ /* > is an estimated upper bound for the magnitude of the largest */ /* > element in (X(j) - XTRUE) divided by the magnitude of the */ /* > largest element in X(j). The estimate is as reliable as */ /* > the estimate for RCOND, and is almost always a slight */ /* > overestimate of the true error. */ /* > \endverbatim */ /* > */ /* > \param[out] BERR */ /* > \verbatim */ /* > BERR is REAL array, dimension (NRHS) */ /* > The componentwise relative backward error of each solution */ /* > vector X(j) (i.e., the smallest relative change in */ /* > any element of A or B that makes X(j) an exact solution). */ /* > \endverbatim */ /* > */ /* > \param[out] WORK */ /* > \verbatim */ /* > WORK is COMPLEX array, dimension (2*N) */ /* > \endverbatim */ /* > */ /* > \param[out] RWORK */ /* > \verbatim */ /* > RWORK is REAL array, dimension (N) */ /* > \endverbatim */ /* > */ /* > \param[out] INFO */ /* > \verbatim */ /* > INFO is INTEGER */ /* > = 0: successful exit */ /* > < 0: if INFO = -i, the i-th argument had an illegal value */ /* > \endverbatim */ /* Authors: */ /* ======== */ /* > \author Univ. of Tennessee */ /* > \author Univ. of California Berkeley */ /* > \author Univ. of Colorado Denver */ /* > \author NAG Ltd. */ /* > \date December 2016 */ /* > \ingroup complexOTHERcomputational */ /* ===================================================================== */ /* Subroutine */ int ctprfs_(char *uplo, char *trans, char *diag, integer *n, integer *nrhs, complex *ap, complex *b, integer *ldb, complex *x, integer *ldx, real *ferr, real *berr, complex *work, real *rwork, integer *info) { /* System generated locals */ integer b_dim1, b_offset, x_dim1, x_offset, i__1, i__2, i__3, i__4, i__5; real r__1, r__2, r__3, r__4; complex q__1; /* Local variables */ integer kase; real safe1, safe2; integer i__, j, k; real s; extern logical lsame_(char *, char *); integer isave[3]; extern /* Subroutine */ int ccopy_(integer *, complex *, integer *, complex *, integer *), caxpy_(integer *, complex *, complex *, integer *, complex *, integer *), ctpmv_(char *, char *, char *, integer *, complex *, complex *, integer *); logical upper; extern /* Subroutine */ int ctpsv_(char *, char *, char *, integer *, complex *, complex *, integer *), clacn2_( integer *, complex *, complex *, real *, integer *, integer *); integer kc; real xk; extern real slamch_(char *); integer nz; real safmin; extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen); logical notran; char transn[1], transt[1]; logical nounit; real lstres, eps; /* -- LAPACK computational routine (version 3.7.0) -- */ /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */ /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */ /* December 2016 */ /* ===================================================================== */ /* Test the input parameters. */ /* Parameter adjustments */ --ap; b_dim1 = *ldb; b_offset = 1 + b_dim1 * 1; b -= b_offset; x_dim1 = *ldx; x_offset = 1 + x_dim1 * 1; x -= x_offset; --ferr; --berr; --work; --rwork; /* Function Body */ *info = 0; upper = lsame_(uplo, "U"); notran = lsame_(trans, "N"); nounit = lsame_(diag, "N"); if (! upper && ! lsame_(uplo, "L")) { *info = -1; } else if (! notran && ! lsame_(trans, "T") && ! lsame_(trans, "C")) { *info = -2; } else if (! nounit && ! lsame_(diag, "U")) { *info = -3; } else if (*n < 0) { *info = -4; } else if (*nrhs < 0) { *info = -5; } else if (*ldb < f2cmax(1,*n)) { *info = -8; } else if (*ldx < f2cmax(1,*n)) { *info = -10; } if (*info != 0) { i__1 = -(*info); xerbla_("CTPRFS", &i__1, (ftnlen)6); return 0; } /* Quick return if possible */ if (*n == 0 || *nrhs == 0) { i__1 = *nrhs; for (j = 1; j <= i__1; ++j) { ferr[j] = 0.f; berr[j] = 0.f; /* L10: */ } return 0; } if (notran) { *(unsigned char *)transn = 'N'; *(unsigned char *)transt = 'C'; } else { *(unsigned char *)transn = 'C'; *(unsigned char *)transt = 'N'; } /* NZ = maximum number of nonzero elements in each row of A, plus 1 */ nz = *n + 1; eps = slamch_("Epsilon"); safmin = slamch_("Safe minimum"); safe1 = nz * safmin; safe2 = safe1 / eps; /* Do for each right hand side */ i__1 = *nrhs; for (j = 1; j <= i__1; ++j) { /* Compute residual R = B - op(A) * X, */ /* where op(A) = A, A**T, or A**H, depending on TRANS. */ ccopy_(n, &x[j * x_dim1 + 1], &c__1, &work[1], &c__1); ctpmv_(uplo, trans, diag, n, &ap[1], &work[1], &c__1); q__1.r = -1.f, q__1.i = 0.f; caxpy_(n, &q__1, &b[j * b_dim1 + 1], &c__1, &work[1], &c__1); /* Compute componentwise relative backward error from formula */ /* f2cmax(i) ( abs(R(i)) / ( abs(op(A))*abs(X) + abs(B) )(i) ) */ /* where abs(Z) is the componentwise absolute value of the matrix */ /* or vector Z. If the i-th component of the denominator is less */ /* than SAFE2, then SAFE1 is added to the i-th components of the */ /* numerator and denominator before dividing. */ i__2 = *n; for (i__ = 1; i__ <= i__2; ++i__) { i__3 = i__ + j * b_dim1; rwork[i__] = (r__1 = b[i__3].r, abs(r__1)) + (r__2 = r_imag(&b[ i__ + j * b_dim1]), abs(r__2)); /* L20: */ } if (notran) { /* Compute abs(A)*abs(X) + abs(B). */ if (upper) { kc = 1; if (nounit) { i__2 = *n; for (k = 1; k <= i__2; ++k) { i__3 = k + j * x_dim1; xk = (r__1 = x[i__3].r, abs(r__1)) + (r__2 = r_imag(& x[k + j * x_dim1]), abs(r__2)); i__3 = k; for (i__ = 1; i__ <= i__3; ++i__) { i__4 = kc + i__ - 1; rwork[i__] += ((r__1 = ap[i__4].r, abs(r__1)) + ( r__2 = r_imag(&ap[kc + i__ - 1]), abs( r__2))) * xk; /* L30: */ } kc += k; /* L40: */ } } else { i__2 = *n; for (k = 1; k <= i__2; ++k) { i__3 = k + j * x_dim1; xk = (r__1 = x[i__3].r, abs(r__1)) + (r__2 = r_imag(& x[k + j * x_dim1]), abs(r__2)); i__3 = k - 1; for (i__ = 1; i__ <= i__3; ++i__) { i__4 = kc + i__ - 1; rwork[i__] += ((r__1 = ap[i__4].r, abs(r__1)) + ( r__2 = r_imag(&ap[kc + i__ - 1]), abs( r__2))) * xk; /* L50: */ } rwork[k] += xk; kc += k; /* L60: */ } } } else { kc = 1; if (nounit) { i__2 = *n; for (k = 1; k <= i__2; ++k) { i__3 = k + j * x_dim1; xk = (r__1 = x[i__3].r, abs(r__1)) + (r__2 = r_imag(& x[k + j * x_dim1]), abs(r__2)); i__3 = *n; for (i__ = k; i__ <= i__3; ++i__) { i__4 = kc + i__ - k; rwork[i__] += ((r__1 = ap[i__4].r, abs(r__1)) + ( r__2 = r_imag(&ap[kc + i__ - k]), abs( r__2))) * xk; /* L70: */ } kc = kc + *n - k + 1; /* L80: */ } } else { i__2 = *n; for (k = 1; k <= i__2; ++k) { i__3 = k + j * x_dim1; xk = (r__1 = x[i__3].r, abs(r__1)) + (r__2 = r_imag(& x[k + j * x_dim1]), abs(r__2)); i__3 = *n; for (i__ = k + 1; i__ <= i__3; ++i__) { i__4 = kc + i__ - k; rwork[i__] += ((r__1 = ap[i__4].r, abs(r__1)) + ( r__2 = r_imag(&ap[kc + i__ - k]), abs( r__2))) * xk; /* L90: */ } rwork[k] += xk; kc = kc + *n - k + 1; /* L100: */ } } } } else { /* Compute abs(A**H)*abs(X) + abs(B). */ if (upper) { kc = 1; if (nounit) { i__2 = *n; for (k = 1; k <= i__2; ++k) { s = 0.f; i__3 = k; for (i__ = 1; i__ <= i__3; ++i__) { i__4 = kc + i__ - 1; i__5 = i__ + j * x_dim1; s += ((r__1 = ap[i__4].r, abs(r__1)) + (r__2 = r_imag(&ap[kc + i__ - 1]), abs(r__2))) * ( (r__3 = x[i__5].r, abs(r__3)) + (r__4 = r_imag(&x[i__ + j * x_dim1]), abs(r__4))); /* L110: */ } rwork[k] += s; kc += k; /* L120: */ } } else { i__2 = *n; for (k = 1; k <= i__2; ++k) { i__3 = k + j * x_dim1; s = (r__1 = x[i__3].r, abs(r__1)) + (r__2 = r_imag(&x[ k + j * x_dim1]), abs(r__2)); i__3 = k - 1; for (i__ = 1; i__ <= i__3; ++i__) { i__4 = kc + i__ - 1; i__5 = i__ + j * x_dim1; s += ((r__1 = ap[i__4].r, abs(r__1)) + (r__2 = r_imag(&ap[kc + i__ - 1]), abs(r__2))) * ( (r__3 = x[i__5].r, abs(r__3)) + (r__4 = r_imag(&x[i__ + j * x_dim1]), abs(r__4))); /* L130: */ } rwork[k] += s; kc += k; /* L140: */ } } } else { kc = 1; if (nounit) { i__2 = *n; for (k = 1; k <= i__2; ++k) { s = 0.f; i__3 = *n; for (i__ = k; i__ <= i__3; ++i__) { i__4 = kc + i__ - k; i__5 = i__ + j * x_dim1; s += ((r__1 = ap[i__4].r, abs(r__1)) + (r__2 = r_imag(&ap[kc + i__ - k]), abs(r__2))) * ( (r__3 = x[i__5].r, abs(r__3)) + (r__4 = r_imag(&x[i__ + j * x_dim1]), abs(r__4))); /* L150: */ } rwork[k] += s; kc = kc + *n - k + 1; /* L160: */ } } else { i__2 = *n; for (k = 1; k <= i__2; ++k) { i__3 = k + j * x_dim1; s = (r__1 = x[i__3].r, abs(r__1)) + (r__2 = r_imag(&x[ k + j * x_dim1]), abs(r__2)); i__3 = *n; for (i__ = k + 1; i__ <= i__3; ++i__) { i__4 = kc + i__ - k; i__5 = i__ + j * x_dim1; s += ((r__1 = ap[i__4].r, abs(r__1)) + (r__2 = r_imag(&ap[kc + i__ - k]), abs(r__2))) * ( (r__3 = x[i__5].r, abs(r__3)) + (r__4 = r_imag(&x[i__ + j * x_dim1]), abs(r__4))); /* L170: */ } rwork[k] += s; kc = kc + *n - k + 1; /* L180: */ } } } } s = 0.f; i__2 = *n; for (i__ = 1; i__ <= i__2; ++i__) { if (rwork[i__] > safe2) { /* Computing MAX */ i__3 = i__; r__3 = s, r__4 = ((r__1 = work[i__3].r, abs(r__1)) + (r__2 = r_imag(&work[i__]), abs(r__2))) / rwork[i__]; s = f2cmax(r__3,r__4); } else { /* Computing MAX */ i__3 = i__; r__3 = s, r__4 = ((r__1 = work[i__3].r, abs(r__1)) + (r__2 = r_imag(&work[i__]), abs(r__2)) + safe1) / (rwork[i__] + safe1); s = f2cmax(r__3,r__4); } /* L190: */ } berr[j] = s; /* Bound error from formula */ /* norm(X - XTRUE) / norm(X) .le. FERR = */ /* norm( abs(inv(op(A)))* */ /* ( abs(R) + NZ*EPS*( abs(op(A))*abs(X)+abs(B) ))) / norm(X) */ /* where */ /* norm(Z) is the magnitude of the largest component of Z */ /* inv(op(A)) is the inverse of op(A) */ /* abs(Z) is the componentwise absolute value of the matrix or */ /* vector Z */ /* NZ is the maximum number of nonzeros in any row of A, plus 1 */ /* EPS is machine epsilon */ /* The i-th component of abs(R)+NZ*EPS*(abs(op(A))*abs(X)+abs(B)) */ /* is incremented by SAFE1 if the i-th component of */ /* abs(op(A))*abs(X) + abs(B) is less than SAFE2. */ /* Use CLACN2 to estimate the infinity-norm of the matrix */ /* inv(op(A)) * diag(W), */ /* where W = abs(R) + NZ*EPS*( abs(op(A))*abs(X)+abs(B) ))) */ i__2 = *n; for (i__ = 1; i__ <= i__2; ++i__) { if (rwork[i__] > safe2) { i__3 = i__; rwork[i__] = (r__1 = work[i__3].r, abs(r__1)) + (r__2 = r_imag(&work[i__]), abs(r__2)) + nz * eps * rwork[i__] ; } else { i__3 = i__; rwork[i__] = (r__1 = work[i__3].r, abs(r__1)) + (r__2 = r_imag(&work[i__]), abs(r__2)) + nz * eps * rwork[i__] + safe1; } /* L200: */ } kase = 0; L210: clacn2_(n, &work[*n + 1], &work[1], &ferr[j], &kase, isave); if (kase != 0) { if (kase == 1) { /* Multiply by diag(W)*inv(op(A)**H). */ ctpsv_(uplo, transt, diag, n, &ap[1], &work[1], &c__1); i__2 = *n; for (i__ = 1; i__ <= i__2; ++i__) { i__3 = i__; i__4 = i__; i__5 = i__; q__1.r = rwork[i__4] * work[i__5].r, q__1.i = rwork[i__4] * work[i__5].i; work[i__3].r = q__1.r, work[i__3].i = q__1.i; /* L220: */ } } else { /* Multiply by inv(op(A))*diag(W). */ i__2 = *n; for (i__ = 1; i__ <= i__2; ++i__) { i__3 = i__; i__4 = i__; i__5 = i__; q__1.r = rwork[i__4] * work[i__5].r, q__1.i = rwork[i__4] * work[i__5].i; work[i__3].r = q__1.r, work[i__3].i = q__1.i; /* L230: */ } ctpsv_(uplo, transn, diag, n, &ap[1], &work[1], &c__1); } goto L210; } /* Normalize error. */ lstres = 0.f; i__2 = *n; for (i__ = 1; i__ <= i__2; ++i__) { /* Computing MAX */ i__3 = i__ + j * x_dim1; r__3 = lstres, r__4 = (r__1 = x[i__3].r, abs(r__1)) + (r__2 = r_imag(&x[i__ + j * x_dim1]), abs(r__2)); lstres = f2cmax(r__3,r__4); /* L240: */ } if (lstres != 0.f) { ferr[j] /= lstres; } /* L250: */ } return 0; /* End of CTPRFS */ } /* ctprfs_ */
the_stack_data/31388206.c
// // Created by ulysses on 1/16/17. // #include<stdio.h> void swap(int *x, int *y); int main(void){ int x = 10, y = 15; printf("The values of x and y are %d and %d respectively.\n", x, y); swap(&x, &y); printf("Now their values are %d and %d.\n", x, y); return 0; } void swap(int *x, int *y){ int temp = *x; *x = *y; *y = temp; }
the_stack_data/90766053.c
/**/ #include <stdio.h> #include <math.h> #include <stdlib.h> int main(){ int d1,d2,d3,d4,d5,d6,d7,d8,d9,d10, absnum, num; double floatnum; printf("\nEnter an integer > "); scanf("%lf", &floatnum); num = (int)floatnum; absnum = abs(num); if (!(num >= 0 && absnum < 10000000000)){ d1 = (absnum % 10); d2 = (absnum % 100)/10; d3 = (absnum % 1000)/100; d4 = (absnum % 10000)/1000; d5 = (absnum % 100000)/10000; d6 = (absnum % 1000000)/100000; d7 = (absnum % 10000000)/1000000; d8 = (absnum % 100000000)/10000000; d9 = (absnum % 1000000000)/100000000; d10 = ((num - d1-(d2*10)-(d3*100)- (d4*1000)-(d5*10000)-(d6*100000)-(d7*1000000)-(d8*10000000)-(d9*100000000))/1000000000); if (d10 == 0 && d9 != 0) printf("\n%d\n%d\n%d\n%d\n%d\n%d\n%d\n%d\n-%d\n",d1,d2,d3,d4,d5,d6,d7,d8,d9); else if(d10 == 0 && d9 == 0 && d8 != 0) printf("\n%d\n%d\n%d\n%d\n%d\n%d\n%d\n-%d\n",d1,d2,d3,d4,d5,d6,d7,d8); else if (d10 == 0 && d9 == 0 && d8 == 0 && d7 != 0) printf("\n%d\n%d\n%d\n%d\n%d\n%d\n-%d\n",d1,d2,d3,d4,d5,d6,d7); else if (d10 == 0 && d9 == 0 && d8 == 0 && d7 == 0 && d6 != 0) printf("\n%d\n%d\n%d\n%d\n%d\n-%d\n",d1,d2,d3,d4,d5,d6); else if (d10 == 0 && d9 == 0 && d8 == 0 && d7 == 0 && d6 == 0 && d5 != 0) printf("\n%d\n%d\n%d\n%d\n-%d\n",d1,d2,d3,d4,d5); else if (d10 == 0 && d9 == 0 && d8 == 0 && d7 == 0 && d6 == 0 && d5 == 0 && d4 != 0) printf("\n%d\n%d\n%d\n-%d\n",d1,d2,d3,d4); else if (d10 == 0 && d9 == 0 && d8 == 0 && d7 == 0 && d6 == 0 && d5 == 0 && d4 == 0 && d3 != 0) printf("\n%d\n%d\n-%d\n", d1, d2, d3); else if (d10 == 0 && d9 == 0 && d8 == 0 && d7 == 0 && d6 == 0 && d5 == 0 && d4 == 0 && d3 == 0 && d2 != 0) printf("\n%d\n-%d\n", d1, d2); else if (d10 == 0 && d9 == 0 && d8 == 0 && d7 == 0 && d6 == 0 && d5 == 0 && d4 == 0 && d3 == 0 && d2 == 0 && d1!= 0) printf("\n-%d\n", d1); } else if (num >= 0 && num < 10000000000){ d1 = (num % 10); d2 = (num % 100)/10; d3 = (num % 1000)/100; d4 = (num % 10000)/1000; d5 = (num % 100000)/10000; d6 = (num % 1000000)/100000; d7 = (num % 10000000)/1000000; d8 = (num % 100000000)/10000000; d9 = (num % 1000000000)/100000000; d10 = ((num - d1-(d2*10)-(d3*100)- (d4*1000)-(d5*10000)-(d6*100000)-(d7*1000000)-(d8*10000000)-(d9*100000000))/1000000000); if (d10 == 0 && d9 != 0) printf("\n%d\n%d\n%d\n%d\n%d\n%d\n%d\n%d\n%d\n",d1,d2,d3,d4,d5,d6,d7,d8,d9); else if(d10 == 0 && d9 == 0 && d8 != 0) printf("\n%d\n%d\n%d\n%d\n%d\n%d\n%d\n%d\n",d1,d2,d3,d4,d5,d6,d7,d8); else if (d10 == 0 && d9 == 0 && d8 == 0 && d7 != 0) printf("\n%d\n%d\n%d\n%d\n%d\n%d\n%d\n",d1,d2,d3,d4,d5,d6,d7); else if (d10 == 0 && d9 == 0 && d8 == 0 && d7 == 0 && d6 != 0) printf("\n%d\n%d\n%d\n%d\n%d\n%d\n",d1,d2,d3,d4,d5,d6); else if (d10 == 0 && d9 == 0 && d8 == 0 && d7 == 0 && d6 == 0 && d5 != 0) printf("\n%d\n%d\n%d\n%d\n%d\n",d1,d2,d3,d4,d5); else if (d10 == 0 && d9 == 0 && d8 == 0 && d7 == 0 && d6 == 0 && d5 == 0 && d4 != 0) printf("\n%d\n%d\n%d\n%d\n",d1,d2,d3,d4); else if (d10 == 0 && d9 == 0 && d8 == 0 && d7 == 0 && d6 == 0 && d5 == 0 && d4 == 0 && d3 != 0) printf("\n%d\n%d\n%d\n", d1, d2, d3); else if (d10 == 0 && d9 == 0 && d8 == 0 && d7 == 0 && d6 == 0 && d5 == 0 && d4 == 0 && d3 == 0 && d2 != 0) printf("\n%d\n%d\n", d1, d2); else if (d10 == 0 && d9 == 0 && d8 == 0 && d7 == 0 && d6 == 0 && d5 == 0 && d4 == 0 && d3 == 0 && d2 == 0 && d1!= 0) printf("\n%d\n", d1); else if(d10 == 0 && d9 == 0 && d8 == 0 && d7 == 0 && d6 == 0 && d5 == 0 && d4 == 0 && d3 == 0 && d2 == 0 && d1== 0) printf("\n0\n"); } if (floatnum >= 10000000000) printf("\n7\n4\n6\n3\n8\n4\n7\n4\n1\n2\n"); printf("That's all, have a nice day!\n"); return(0); }
the_stack_data/40936.c
// // Program.c // Listing 11 // // Created by Mustafa Youldash on 9/3/17. // Copyright © 2017 Umm Al-Qura University. All rights reserved. // #include <stdio.h> int main(void) { int a[2][3] = { {1,2}, {4,5,6} }; int i, j; printf("Values in a are: \n"); for (i = 0; i <= 1; ++i) { for (j = 0; j <= 2; ++j) { printf("a[%d][%d] = %d\n", i, j, a[i][j]); } } return 0; }
the_stack_data/25139066.c
/* Soal : 2 A : 5 B : 6 */ #include <stdio.h> int main(){ int A=5, B=9, u=A, s=A; printf("Deret Aritmatikanya adalah\n"); for(int i=0;i<5;i++){ for(int j=0;j<6;j++){ printf("%d\t", u); u=u+B; s=s+u; } printf("\n"); } s=s-u; printf("Jumlah Deret Aritmatikanya adalah %d\n", s); }
the_stack_data/32949336.c
//***************************************************************************** // // startup_ccs.c - Startup code for use with TI's Code Composer Studio. // // Copyright (c) 2005-2013 Texas Instruments Incorporated. All rights reserved. // Software License Agreement // // Texas Instruments (TI) is supplying this software for use solely and // exclusively on TI's microcontroller products. The software is owned by // TI and/or its suppliers, and is protected under applicable copyright // laws. You may not combine this software with "viral" open-source // software in order to form a larger program. // // THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS. // NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT // NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY // CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL // DAMAGES, FOR ANY REASON WHATSOEVER. // // This is part of revision 10636 of the EK-LM3S8962 Firmware Package. // //***************************************************************************** //***************************************************************************** // // Forward declaration of the default fault handlers. // //***************************************************************************** void ResetISR(void); static void NmiSR(void); static void FaultISR(void); static void IntDefaultHandler(void); //***************************************************************************** // // External declaration for the reset handler that is to be called when the // processor is started // //***************************************************************************** extern void _c_int00(void); //***************************************************************************** // // Linker variable that marks the top of the stack. // //***************************************************************************** extern unsigned long __STACK_TOP; //***************************************************************************** // // External declarations for the interrupt handlers used by the application. // //***************************************************************************** extern void Timer0IntHandler(void); extern void Timer1IntHandler(void); //***************************************************************************** // // The vector table. Note that the proper constructs must be placed on this to // ensure that it ends up at physical address 0x0000.0000 or at the start of // the program if located at a start address other than 0. // //***************************************************************************** #pragma DATA_SECTION(g_pfnVectors, ".intvecs") void (* const g_pfnVectors[])(void) = { (void (*)(void))((unsigned long)&__STACK_TOP), // The initial stack pointer ResetISR, // The reset handler NmiSR, // The NMI handler FaultISR, // The hard fault handler IntDefaultHandler, // The MPU fault handler IntDefaultHandler, // The bus fault handler IntDefaultHandler, // The usage fault handler 0, // Reserved 0, // Reserved 0, // Reserved 0, // Reserved IntDefaultHandler, // SVCall handler IntDefaultHandler, // Debug monitor handler 0, // Reserved IntDefaultHandler, // The PendSV handler IntDefaultHandler, // The SysTick handler IntDefaultHandler, // GPIO Port A IntDefaultHandler, // GPIO Port B IntDefaultHandler, // GPIO Port C IntDefaultHandler, // GPIO Port D IntDefaultHandler, // GPIO Port E IntDefaultHandler, // UART0 Rx and Tx IntDefaultHandler, // UART1 Rx and Tx IntDefaultHandler, // SSI0 Rx and Tx IntDefaultHandler, // I2C0 Master and Slave IntDefaultHandler, // PWM Fault IntDefaultHandler, // PWM Generator 0 IntDefaultHandler, // PWM Generator 1 IntDefaultHandler, // PWM Generator 2 IntDefaultHandler, // Quadrature Encoder 0 IntDefaultHandler, // ADC Sequence 0 IntDefaultHandler, // ADC Sequence 1 IntDefaultHandler, // ADC Sequence 2 IntDefaultHandler, // ADC Sequence 3 IntDefaultHandler, // Watchdog timer Timer0IntHandler, // Timer 0 subtimer A IntDefaultHandler, // Timer 0 subtimer B Timer1IntHandler, // Timer 1 subtimer A IntDefaultHandler, // Timer 1 subtimer B IntDefaultHandler, // Timer 2 subtimer A IntDefaultHandler, // Timer 2 subtimer B IntDefaultHandler, // Analog Comparator 0 IntDefaultHandler, // Analog Comparator 1 IntDefaultHandler, // Analog Comparator 2 IntDefaultHandler, // System Control (PLL, OSC, BO) IntDefaultHandler, // FLASH Control IntDefaultHandler, // GPIO Port F IntDefaultHandler, // GPIO Port G IntDefaultHandler, // GPIO Port H IntDefaultHandler, // UART2 Rx and Tx IntDefaultHandler, // SSI1 Rx and Tx IntDefaultHandler, // Timer 3 subtimer A IntDefaultHandler, // Timer 3 subtimer B IntDefaultHandler, // I2C1 Master and Slave IntDefaultHandler, // Quadrature Encoder 1 IntDefaultHandler, // CAN0 IntDefaultHandler, // CAN1 IntDefaultHandler, // CAN2 IntDefaultHandler, // Ethernet IntDefaultHandler // Hibernate }; //***************************************************************************** // // This is the code that gets called when the processor first starts execution // following a reset event. Only the absolutely necessary set is performed, // after which the application supplied entry() routine is called. Any fancy // actions (such as making decisions based on the reset cause register, and // resetting the bits in that register) are left solely in the hands of the // application. // //***************************************************************************** void ResetISR(void) { // // Jump to the CCS C initialization routine. // __asm(" .global _c_int00\n" " b.w _c_int00"); } //***************************************************************************** // // This is the code that gets called when the processor receives a NMI. This // simply enters an infinite loop, preserving the system state for examination // by a debugger. // //***************************************************************************** static void NmiSR(void) { // // Enter an infinite loop. // while(1) { } } //***************************************************************************** // // This is the code that gets called when the processor receives a fault // interrupt. This simply enters an infinite loop, preserving the system state // for examination by a debugger. // //***************************************************************************** static void FaultISR(void) { // // Enter an infinite loop. // while(1) { } } //***************************************************************************** // // This is the code that gets called when the processor receives an unexpected // interrupt. This simply enters an infinite loop, preserving the system state // for examination by a debugger. // //***************************************************************************** static void IntDefaultHandler(void) { // // Go into an infinite loop. // while(1) { } }
the_stack_data/646804.c
/* SJF in C */ #include <stdio.h> void findWaitingTime(int processes[], int n, int bt[], int wt[]) { wt[0] = 0; for (int i = 1; i < n; i++) wt[i] = bt[i - 1] + wt[i - 1]; } void findTurnAroundTime(int processes[], int n, int bt[], int wt[], int tat[]) { for (int i = 0; i < n; i++) tat[i] = bt[i] + wt[i]; } void findavgTime(int processes[], int n, int bt[]) { int wt[n], tat[n], total_wt = 0, total_tat = 0; findWaitingTime(processes, n, bt, wt); findTurnAroundTime(processes, n, bt, wt, tat); printf("Processes\t\tBurst-time\t\tWaiting-time\t\tTurn-around-time\n"); for (int i = 0; i < n; i++) { total_wt = total_wt + wt[i]; total_tat = total_tat + tat[i]; printf("%d\t\t\t\t\t", (i + 1)); printf("%d\t\t\t\t\t", bt[i]); printf("%d\t\t\t\t\t", wt[i]); printf("%d\n", tat[i]); } int s = (float)total_wt / (float)n; int t = (float)total_tat / (float)n; printf("Average waiting time = %d\n", s); printf("Average turn around time = %d\n", t); } int main() { int processes[] = {1, 2, 3}; int n = sizeof processes / sizeof processes[0]; int burst_time[] = {10, 5, 8}; findavgTime(processes, n, burst_time); return 0; }
the_stack_data/28374.c
/*** * This code is a part of EvoApproxLib library (ehw.fit.vutbr.cz/approxlib) distributed under The MIT License. * When used, please cite the following article(s): V. Mrazek, S. S. Sarwar, L. Sekanina, Z. Vasicek and K. Roy, "Design of power-efficient approximate multipliers for approximate artificial neural networks," 2016 IEEE/ACM International Conference on Computer-Aided Design (ICCAD), Austin, TX, 2016, pp. 1-7. doi: 10.1145/2966986.2967021 * This file contains a circuit from a sub-set of pareto optimal circuits with respect to the pwr and wce parameters ***/ // MAE% = 1.18 % // MAE = 49343 // WCE% = 6.03 % // WCE = 252964 // WCRE% = 3051.52 % // EP% = 99.90 % // MRE% = 19.95 % // MSE = 37290.89e5 // PDK45_PWR = 0.236 mW // PDK45_AREA = 524.2 um2 // PDK45_DELAY = 1.13 ns #include <stdint.h> #include <stdlib.h> uint64_t mul11u_0DX(uint64_t a, uint64_t b) { int wa[11]; int wb[11]; uint64_t y = 0; wa[0] = (a >> 0) & 0x01; wb[0] = (b >> 0) & 0x01; wa[1] = (a >> 1) & 0x01; wb[1] = (b >> 1) & 0x01; wa[2] = (a >> 2) & 0x01; wb[2] = (b >> 2) & 0x01; wa[3] = (a >> 3) & 0x01; wb[3] = (b >> 3) & 0x01; wa[4] = (a >> 4) & 0x01; wb[4] = (b >> 4) & 0x01; wa[5] = (a >> 5) & 0x01; wb[5] = (b >> 5) & 0x01; wa[6] = (a >> 6) & 0x01; wb[6] = (b >> 6) & 0x01; wa[7] = (a >> 7) & 0x01; wb[7] = (b >> 7) & 0x01; wa[8] = (a >> 8) & 0x01; wb[8] = (b >> 8) & 0x01; wa[9] = (a >> 9) & 0x01; wb[9] = (b >> 9) & 0x01; wa[10] = (a >> 10) & 0x01; wb[10] = (b >> 10) & 0x01; int sig_30 = wa[8] & wb[7]; int sig_75 = ~(wb[0] | wb[4]); int sig_76 = wa[10] & wb[4]; int sig_86 = wa[9] & wb[5]; int sig_87 = wa[10] & wb[5]; int sig_95 = wa[0] & wb[0]; int sig_96 = wa[8] & wb[6]; int sig_97 = wa[9] & wb[6]; int sig_98 = wa[10] & wb[6]; int sig_106 = wa[7] & wb[5]; int sig_107 = wa[8] & wb[7]; int sig_108 = wa[9] & wb[7]; int sig_109 = wa[10] & wb[7]; int sig_114 = wa[4] & wb[8]; int sig_116 = wa[6] & wb[8]; int sig_117 = wa[7] & wb[8]; int sig_118 = wa[8] & wb[8]; int sig_119 = wa[9] & wb[8]; int sig_120 = wa[10] & wb[8]; int sig_127 = wa[6] & wb[9]; int sig_128 = wa[7] & wb[9]; int sig_129 = wa[8] & wb[9]; int sig_130 = wa[9] & wb[9]; int sig_131 = wa[10] & wb[9]; int sig_137 = wa[5] & wb[10]; int sig_138 = wa[6] & wb[10]; int sig_139 = wa[7] & wb[10]; int sig_140 = wa[8] & wb[10]; int sig_141 = wa[9] & wb[10]; int sig_142 = wa[10] & wb[10]; int sig_156 = wb[6] & wa[5]; int sig_235 = wa[1] & sig_75; int sig_238 = sig_235; int sig_239 = sig_76 & sig_86; int sig_240 = sig_76 ^ sig_86; int sig_243 = wb[7] & wa[10]; int sig_269 = sig_95 & wb[6]; int sig_272 = sig_269 | wb[4]; int sig_273 = sig_96; int sig_274 = wa[8] & sig_106; int sig_275 = sig_273 & sig_116; int sig_276 = sig_273 ^ sig_116; int sig_277 = sig_274 | sig_275; int sig_278 = sig_97 ^ sig_107; int sig_279 = sig_97 & sig_107; int sig_280 = sig_278 & sig_117; int sig_282 = sig_279 | sig_280; int sig_283 = sig_98 ^ sig_108; int sig_284 = sig_98 & sig_108; int sig_285 = sig_283 & sig_118; int sig_286 = sig_283 ^ sig_118; int sig_287 = sig_284 | sig_285; int sig_288 = sig_109 & sig_119; int sig_289 = sig_109 ^ sig_119; int sig_376 = sig_238 ^ sig_276; int sig_377 = sig_238 & sig_276; int sig_378 = sig_376 & sig_272; int sig_379 = sig_376 ^ sig_272; int sig_380 = sig_377 | sig_378; int sig_381 = sig_239; int sig_382 = sig_239 & wa[3]; int sig_384 = sig_381 ^ sig_277; int sig_385 = sig_382; int sig_386 = sig_286 & sig_282; int sig_387 = sig_286 ^ sig_282; int sig_388 = sig_289 & sig_287; int sig_389 = sig_289 ^ sig_287; int sig_390 = sig_120 & sig_288; int sig_391 = sig_120 ^ sig_288; int sig_420 = wb[3]; int sig_441 = sig_240 & sig_379; int sig_442 = sig_240 ^ sig_379; int sig_443 = sig_87 & sig_384; int sig_444 = sig_87 ^ sig_384; int sig_472 = sig_380 ^ sig_127; int sig_473 = sig_380 & sig_127; int sig_474 = sig_472 & sig_137; int sig_475 = sig_472 ^ sig_137; int sig_476 = sig_473 | sig_474; int sig_477 = sig_385 ^ sig_128; int sig_478 = sig_385 & sig_128; int sig_479 = sig_477 & sig_138; int sig_480 = sig_477 ^ sig_138; int sig_481 = sig_478 | sig_479; int sig_482 = sig_386 ^ sig_129; int sig_483 = sig_386 & sig_129; int sig_484 = sig_482 & sig_139; int sig_485 = sig_482 ^ sig_139; int sig_486 = sig_483 | sig_484; int sig_487 = sig_388 ^ sig_130; int sig_488 = sig_388 & sig_130; int sig_489 = sig_487 & sig_140; int sig_490 = sig_487 ^ sig_140; int sig_491 = sig_488 | sig_489; int sig_492 = sig_390 ^ sig_131; int sig_493 = sig_390 & sig_131; int sig_494 = sig_492 & sig_141; int sig_495 = sig_492 ^ sig_141; int sig_496 = sig_493 | sig_494; int sig_519 = wa[10] & sig_420; int sig_538 = wa[5]; int sig_539 = sig_442 & wb[6]; int sig_540 = !sig_538; int sig_542 = sig_539 | sig_540; int sig_543 = sig_444 ^ sig_441; int sig_544 = sig_444 | sig_441; int sig_545 = sig_543 & wb[2]; int sig_546 = sig_543 ^ sig_475; int sig_547 = sig_544 | sig_545; int sig_548 = sig_387 ^ sig_443; int sig_549 = sig_387 & sig_443; int sig_550 = sig_548 & sig_480; int sig_551 = sig_548 ^ sig_480; int sig_552 = sig_549 | sig_550; int sig_553 = sig_389 & sig_485; int sig_554 = sig_389 ^ sig_485; int sig_555 = sig_391 & sig_490; int sig_556 = sig_391 ^ sig_490; int sig_575 = wa[8] ^ wa[8]; int sig_591 = wb[8] & wa[5]; int sig_592 = sig_546 ^ sig_542; int sig_593 = sig_546 & sig_542; int sig_595 = !sig_592; int sig_596 = sig_593; int sig_597 = sig_551 ^ sig_547; int sig_598 = sig_551 & sig_547; int sig_599 = sig_597 & sig_476; int sig_600 = sig_597 ^ sig_476; int sig_601 = sig_598 | sig_599; int sig_602 = sig_554 ^ sig_552; int sig_603 = sig_554 & sig_552; int sig_604 = sig_602 & sig_481; int sig_605 = sig_602 ^ sig_481; int sig_606 = sig_603 | sig_604; int sig_607 = sig_556 ^ sig_553; int sig_608 = sig_556 & sig_553; int sig_609 = sig_607 & sig_486; int sig_610 = sig_607 ^ sig_486; int sig_611 = sig_608 | sig_609; int sig_612 = sig_495 ^ sig_555; int sig_613 = sig_495 & sig_555; int sig_614 = sig_612 & sig_491; int sig_615 = sig_612 ^ sig_491; int sig_616 = sig_613 | sig_614; int sig_617 = sig_142 & sig_496; int sig_618 = sig_142 ^ sig_496; int sig_621 = wa[2]; int sig_623 = sig_621 & wb[7]; int sig_625 = wa[1] | sig_623; int sig_652 = sig_575 & wa[5]; int sig_655 = sig_652; int sig_691 = ~(sig_625 | wa[0]); int sig_692 = sig_655 & sig_691; int sig_693 = wb[6] & sig_625; int sig_694 = sig_692 ^ sig_693; int sig_707 = sig_595 ^ sig_591; int sig_708 = wb[3] & wa[10]; int sig_709 = sig_707 & wb[6]; int sig_711 = sig_708 | sig_709; int sig_748 = sig_711 & wa[7]; int sig_749 = wa[6] & sig_694; int sig_750 = sig_748 | sig_749; int sig_751 = sig_600 ^ sig_596; int sig_752 = sig_600 & sig_596; int sig_753 = sig_605 ^ sig_601; int sig_754 = sig_605 & sig_601; int sig_755 = sig_753 & sig_752; int sig_756 = sig_753 ^ sig_752; int sig_757 = sig_754 | sig_755; int sig_758 = sig_610 ^ sig_606; int sig_759 = sig_610 & sig_606; int sig_760 = sig_758 & sig_757; int sig_761 = sig_758 ^ sig_757; int sig_762 = sig_759 | sig_760; int sig_763 = sig_615 ^ sig_611; int sig_764 = sig_615 & sig_611; int sig_765 = sig_763 & sig_762; int sig_766 = sig_763 ^ sig_762; int sig_767 = sig_764 | sig_765; int sig_768 = ~(sig_600 ^ wa[2]); int sig_769 = sig_600 & wb[9]; int sig_770 = !sig_768; int sig_771 = sig_769 | sig_768; int sig_772 = sig_605 ^ sig_601; int sig_773 = sig_605 & sig_601; int sig_774 = sig_772 & sig_771; int sig_775 = sig_772 ^ sig_771; int sig_776 = sig_773 ^ sig_774; int sig_777 = sig_610 ^ sig_606; int sig_778 = sig_610 & sig_606; int sig_779 = sig_777 & sig_776; int sig_780 = sig_777 ^ sig_776; int sig_781 = sig_778 | sig_779; int sig_782 = sig_615 ^ sig_611; int sig_783 = sig_615 & sig_611; int sig_784 = sig_782 & sig_781; int sig_785 = sig_782 ^ sig_781; int sig_786 = sig_783 | sig_784; int sig_787 = !sig_750; int sig_788 = sig_751 & sig_787; int sig_789 = sig_770 & sig_750; int sig_790 = sig_788 | sig_789; int sig_791 = !sig_750; int sig_792 = sig_756 & sig_791; int sig_793 = sig_775 & sig_750; int sig_794 = sig_792 | sig_793; int sig_795 = !sig_750; int sig_796 = sig_761 & sig_795; int sig_797 = sig_780 & sig_750; int sig_798 = sig_796 | sig_797; int sig_799 = !sig_750; int sig_800 = sig_766 & sig_799; int sig_801 = sig_785 & sig_750; int sig_802 = sig_800 ^ sig_801; int sig_803 = !sig_750; int sig_804 = sig_767 & sig_803; int sig_805 = sig_786 & sig_750; int sig_806 = sig_804 | sig_805; int sig_807 = sig_618 ^ sig_616; int sig_808 = sig_618 & sig_616; int sig_810 = sig_617 ^ sig_808; int sig_811 = sig_618 ^ sig_616; int sig_812 = wa[6] & sig_616; int sig_813 = !sig_811; int sig_814 = sig_812 | sig_811; int sig_816 = sig_617 ^ sig_814; int sig_817 = !sig_806; int sig_818 = sig_807 & sig_817; int sig_819 = sig_813 & sig_806; int sig_820 = sig_818 | sig_819; int sig_821 = !sig_806; int sig_822 = sig_810 & sig_821; int sig_823 = sig_816 & sig_806; int sig_824 = sig_822 | sig_823; y |= (sig_492 & 0x01) << 0; // default output y |= (sig_602 & 0x01) << 1; // default output y |= (sig_603 & 0x01) << 2; // default output y |= (sig_30 & 0x01) << 3; // default output y |= (sig_276 & 0x01) << 4; // default output y |= (sig_519 & 0x01) << 5; // default output y |= (sig_243 & 0x01) << 6; // default output y |= (sig_114 & 0x01) << 7; // default output y |= (sig_156 & 0x01) << 8; // default output y |= (sig_443 & 0x01) << 9; // default output y |= (sig_616 & 0x01) << 10; // default output y |= (sig_794 & 0x01) << 11; // default output y |= (sig_796 & 0x01) << 12; // default output y |= (sig_614 & 0x01) << 13; // default output y |= (sig_800 & 0x01) << 14; // default output y |= (sig_472 & 0x01) << 15; // default output y |= (sig_790 & 0x01) << 16; // default output y |= (sig_794 & 0x01) << 17; // default output y |= (sig_798 & 0x01) << 18; // default output y |= (sig_802 & 0x01) << 19; // default output y |= (sig_820 & 0x01) << 20; // default output y |= (sig_824 & 0x01) << 21; // default output return y; }
the_stack_data/107183.c
#include <stdio.h> int main(int argc, char* argv[]){ int n1, n2; printf("Input a pair of numbers (for example 10,2 : 2,10):\n"); scanf("%d", &n1); scanf("%d", &n2); if (n1 > n2){ printf("Descending order\n"); } else if (n2 > n1){ printf("Ascending order\n"); } return 0; }
the_stack_data/65323.c
#include <stdio.h> #include <stdlib.h> #include <math.h> int main() { float a[64],p,sum=0; //float k; int i=0,l; while((scanf("%f",&p))!=EOF){ a[i]=p; int t=1; for(int n=0;n<i;n++){ if(a[i]==a[n])t=0; } if(t)i++; } printf("%d",i); for(l=0;l<i;l++){ sum=sum+fmod(a[l],i); } printf("\n%.3f",sum); return 0; }
the_stack_data/42465.c
// Copyright 2021 The golang.design Initiative Authors. // All rights reserved. Use of this source code is governed // by a MIT license that can be found in the LICENSE file. // // Written by Changkun Ou <changkun.de> //go:build linux && !android // +build linux,!android #include <stdlib.h> #include <stdio.h> #include <stdint.h> #include <string.h> #include <dlfcn.h> #include <X11/Xlib.h> #include <X11/Xatom.h> // syncStatus is a function from the Go side. extern void syncStatus(uintptr_t handle, int status); void *libX11; Display* (*P_XOpenDisplay)(int); void (*P_XCloseDisplay)(Display*); Window (*P_XDefaultRootWindow)(Display*); Window (*P_XCreateSimpleWindow)(Display*, Window, int, int, int, int, int, int, int); Atom (*P_XInternAtom)(Display*, char*, int); void (*P_XSetSelectionOwner)(Display*, Atom, Window, unsigned long); Window (*P_XGetSelectionOwner)(Display*, Atom); void (*P_XNextEvent)(Display*, XEvent*); int (*P_XChangeProperty)(Display*, Window, Atom, Atom, int, int, unsigned char*, int); void (*P_XSendEvent)(Display*, Window, int, long , XEvent*); int (*P_XGetWindowProperty) (Display*, Window, Atom, long, long, Bool, Atom, Atom*, int*, unsigned long *, unsigned long *, unsigned char **); void (*P_XFree) (void*); void (*P_XDeleteProperty) (Display*, Window, Atom); void (*P_XConvertSelection)(Display*, Atom, Atom, Atom, Window, Time); int initX11() { if (libX11) { return 1; } libX11 = dlopen("libX11.so", RTLD_LAZY); if (!libX11) { return -1; } P_XOpenDisplay = (Display* (*)(int)) dlsym(libX11, "XOpenDisplay"); P_XCloseDisplay = (void (*)(Display*)) dlsym(libX11, "XCloseDisplay"); P_XDefaultRootWindow = (Window (*)(Display*)) dlsym(libX11, "XDefaultRootWindow"); P_XCreateSimpleWindow = (Window (*)(Display*, Window, int, int, int, int, int, int, int)) dlsym(libX11, "XCreateSimpleWindow"); P_XInternAtom = (Atom (*)(Display*, char*, int)) dlsym(libX11, "XInternAtom"); P_XSetSelectionOwner = (void (*)(Display*, Atom, Window, unsigned long)) dlsym(libX11, "XSetSelectionOwner"); P_XGetSelectionOwner = (Window (*)(Display*, Atom)) dlsym(libX11, "XGetSelectionOwner"); P_XNextEvent = (void (*)(Display*, XEvent*)) dlsym(libX11, "XNextEvent"); P_XChangeProperty = (int (*)(Display*, Window, Atom, Atom, int, int, unsigned char*, int)) dlsym(libX11, "XChangeProperty"); P_XSendEvent = (void (*)(Display*, Window, int, long , XEvent*)) dlsym(libX11, "XSendEvent"); P_XGetWindowProperty = (int (*)(Display*, Window, Atom, long, long, Bool, Atom, Atom*, int*, unsigned long *, unsigned long *, unsigned char **)) dlsym(libX11, "XGetWindowProperty"); P_XFree = (void (*)(void*)) dlsym(libX11, "XFree"); P_XDeleteProperty = (void (*)(Display*, Window, Atom)) dlsym(libX11, "XDeleteProperty"); P_XConvertSelection = (void (*)(Display*, Atom, Atom, Atom, Window, Time)) dlsym(libX11, "XConvertSelection"); return 1; } int clipboard_test() { if (!initX11()) { return -1; } Display* d = NULL; for (int i = 0; i < 42; i++) { d = (*P_XOpenDisplay)(0); if (d == NULL) { continue; } break; } if (d == NULL) { return -1; } (*P_XCloseDisplay)(d); return 0; } // clipboard_write writes the given buf of size n as type typ. // if start is provided, the value of start will be changed to 1 to indicate // if the write is availiable for reading. int clipboard_write(char *typ, unsigned char *buf, size_t n, uintptr_t handle) { if (!initX11()) { return -1; } Display* d = NULL; for (int i = 0; i < 42; i++) { d = (*P_XOpenDisplay)(0); if (d == NULL) { continue; } break; } if (d == NULL) { syncStatus(handle, -1); return -1; } Window w = (*P_XCreateSimpleWindow)(d, (*P_XDefaultRootWindow)(d), 0, 0, 1, 1, 0, 0, 0); // Use False because these may not available for the first time. Atom sel = (*P_XInternAtom)(d, "CLIPBOARD", 0); Atom atomString = (*P_XInternAtom)(d, "UTF8_STRING", 0); Atom atomImage = (*P_XInternAtom)(d, "image/png", 0); Atom targetsAtom = (*P_XInternAtom)(d, "TARGETS", 0); // Use True to makesure the requested type is a valid type. Atom target = (*P_XInternAtom)(d, typ, 1); if (target == None) { (*P_XCloseDisplay)(d); syncStatus(handle, -2); return -2; } (*P_XSetSelectionOwner)(d, sel, w, CurrentTime); if ((*P_XGetSelectionOwner)(d, sel) != w) { (*P_XCloseDisplay)(d); syncStatus(handle, -3); return -3; } XEvent event; XSelectionRequestEvent* xsr; int notified = 0; for (;;) { if (notified == 0) { syncStatus(handle, 1); // notify Go side notified = 1; } (*P_XNextEvent)(d, &event); switch (event.type) { case SelectionClear: // For debugging: // printf("x11write: lost ownership of clipboard selection.\n"); // fflush(stdout); (*P_XCloseDisplay)(d); return 0; case SelectionNotify: // For debugging: // printf("x11write: notify.\n"); // fflush(stdout); break; case SelectionRequest: if (event.xselectionrequest.selection != sel) { break; } XSelectionRequestEvent * xsr = &event.xselectionrequest; XSelectionEvent ev = {0}; int R = 0; ev.type = SelectionNotify; ev.display = xsr->display; ev.requestor = xsr->requestor; ev.selection = xsr->selection; ev.time = xsr->time; ev.target = xsr->target; ev.property = xsr->property; if (ev.target == atomString && ev.target == target) { R = (*P_XChangeProperty)(ev.display, ev.requestor, ev.property, atomString, 8, PropModeReplace, buf, n); } else if (ev.target == atomImage && ev.target == target) { R = (*P_XChangeProperty)(ev.display, ev.requestor, ev.property, atomImage, 8, PropModeReplace, buf, n); } else if (ev.target == targetsAtom) { // Reply atoms for supported targets, other clients should // request the clipboard again and obtain the data if their // implementation is correct. Atom targets[] = { atomString, atomImage }; R = (*P_XChangeProperty)(ev.display, ev.requestor, ev.property, XA_ATOM, 32, PropModeReplace, (unsigned char *)&targets, sizeof(targets)/sizeof(Atom)); } else { ev.property = None; } if ((R & 2) == 0) (*P_XSendEvent)(d, ev.requestor, 0, 0, (XEvent *)&ev); break; } } } // read_data reads the property of a selection if the target atom matches // the actual atom. unsigned long read_data(XSelectionEvent *sev, Atom sel, Atom prop, Atom target, char **buf) { if (!initX11()) { return -1; } unsigned char *data; Atom actual; int format; unsigned long n = 0; unsigned long size = 0; if (sev->property == None || sev->selection != sel || sev->property != prop) { return 0; } int ret = (*P_XGetWindowProperty)(sev->display, sev->requestor, sev->property, 0L, (~0L), 0, AnyPropertyType, &actual, &format, &size, &n, &data); if (ret != Success) { return 0; } if (actual == target && buf != NULL) { *buf = (char *)malloc(size * sizeof(char)); memcpy(*buf, data, size*sizeof(char)); } (*P_XFree)(data); (*P_XDeleteProperty)(sev->display, sev->requestor, sev->property); return size * sizeof(char); } // clipboard_read reads the clipboard selection in given format typ. // the readed bytes is written into buf and returns the size of the buffer. // // The caller of this function should responsible for the free of the buf. unsigned long clipboard_read(char* typ, char **buf) { if (!initX11()) { return -1; } Display* d = NULL; for (int i = 0; i < 42; i++) { d = (*P_XOpenDisplay)(0); if (d == NULL) { continue; } break; } if (d == NULL) { return -1; } Window w = (*P_XCreateSimpleWindow)(d, (*P_XDefaultRootWindow)(d), 0, 0, 1, 1, 0, 0, 0); // Use False because these may not available for the first time. Atom sel = (*P_XInternAtom)(d, "CLIPBOARD", False); Atom prop = (*P_XInternAtom)(d, "GOLANG_DESIGN_DATA", False); // Use True to makesure the requested type is a valid type. Atom target = (*P_XInternAtom)(d, typ, True); if (target == None) { (*P_XCloseDisplay)(d); return -2; } (*P_XConvertSelection)(d, sel, target, prop, w, CurrentTime); XEvent event; for (;;) { (*P_XNextEvent)(d, &event); if (event.type != SelectionNotify) continue; break; } unsigned long n = read_data((XSelectionEvent *)&event.xselection, sel, prop, target, buf); (*P_XCloseDisplay)(d); return n; }
the_stack_data/1055832.c
// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name c-captured.c %s -o - -emit-llvm -fprofile-instrument=clang | FileCheck -allow-deprecated-dag-overlap -check-prefix=PGOGEN -check-prefix=PGOALL %s // RUN: llvm-profdata merge %S/Inputs/c-captured.proftext -o %t.profdata // RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name c-captured.c %s -o - -emit-llvm -fprofile-instrument-use-path=%t.profdata | FileCheck -allow-deprecated-dag-overlap -check-prefix=PGOUSE -check-prefix=PGOALL %s // PGOGEN: @[[DCC:__profc_debug_captured]] = private global [3 x i64] zeroinitializer // PGOGEN: @[[CSC:__profc_c_captured.c___captured_stmt]] = private global [2 x i64] zeroinitializer // PGOGEN: @[[C1C:__profc_c_captured.c___captured_stmt.1]] = private global [3 x i64] zeroinitializer // PGOALL-LABEL: define{{.*}} void @debug_captured() // PGOGEN: store {{.*}} @[[DCC]], i32 0, i32 0 void debug_captured(void) { int x = 10; // Check both debug_captured counters, so we can do this all in one pass // PGOGEN: store {{.*}} @[[DCC]], i32 0, i32 1 // PGOUSE: br {{.*}} !prof ![[DC1:[0-9]+]] // PGOGEN: store {{.*}} @[[DCC]], i32 0, i32 2 // PGOUSE: br {{.*}} !prof ![[DC2:[0-9]+]] // PGOALL: ret // PGOALL-LABEL: define internal void @__captured_stmt( // PGOGEN: store {{.*}} @[[CSC]], i32 0, i32 0 #pragma clang __debug captured { // PGOGEN: store {{.*}} @[[CSC]], i32 0, i32 1 // PGOUSE: br {{.*}} !prof ![[CS1:[0-9]+]] if (x) {} // PGOALL: ret } if (x) {} // This is DC1. Checked above. // PGOALL-LABEL: define internal void @__captured_stmt.1( // PGOGEN: store {{.*}} @[[C1C]], i32 0, i32 0 #pragma clang __debug captured { // PGOGEN: store {{.*}} @[[C1C]], i32 0, i32 1 // PGOUSE: br {{.*}} !prof ![[C11:[0-9]+]] for (int i = 0; i < x; ++i) {} // PGOGEN: store {{.*}} @[[C1C]], i32 0, i32 2 // PGOUSE: br {{.*}} !prof ![[C12:[0-9]+]] if (x) {} // PGOALL: ret } if (x) {} // This is DC2. Checked above. } // PGOUSE-DAG: ![[DC1]] = !{!"branch_weights", i32 2, i32 1} // PGOUSE-DAG: ![[DC2]] = !{!"branch_weights", i32 2, i32 1} // PGOUSE-DAG: ![[CS1]] = !{!"branch_weights", i32 2, i32 1} // PGOUSE-DAG: ![[C11]] = !{!"branch_weights", i32 11, i32 2} // PGOUSE-DAG: ![[C12]] = !{!"branch_weights", i32 2, i32 1} int main(int argc, const char *argv[]) { debug_captured(); return 0; }
the_stack_data/117327739.c
void kernel_jacobi_1d(int tsteps, int n, double A[ 2000 + 0], double B[ 2000 + 0]) { int t, i; for (t = 0; t < tsteps; t++) { #pragma clang loop(i1) tile sizes(64) #pragma clang loop id(i1) for (i = 1; i < n - 1; i++) B[i] = 0.33333 * (A[i-1] + A[i] + A[i + 1]); #pragma clang loop(i2) tile sizes(64) #pragma clang loop id(i2) for (i = 1; i < n - 1; i++) A[i] = 0.33333 * (B[i-1] + B[i] + B[i + 1]); } }
the_stack_data/85665.c
void clang_analyzer_dump(const char*); void testing(char *src, int idx) { clang_analyzer_dump(&src[idx + 2]); }
the_stack_data/1134205.c
#include <inttypes.h> extern int jump64divsteps_mod3(int minusdelta, uint32_t *M1, uint32_t *f, uint32_t *g); int jump1024divsteps_mod3_64(int minusdelta, uint32_t *M, uint32_t *f, uint32_t *g); extern void __update_fg_64x512(uint32_t *f, uint32_t *g, uint32_t *M1); extern void __update_VS_64x64(uint32_t *V, uint32_t *S, uint32_t *M1); extern void __update_VS_64x128(uint32_t *V, uint32_t *S, uint32_t *M1); extern void __update_VS_64x192(uint32_t *V, uint32_t *S, uint32_t *M1); extern void __update_VS_64x256(uint32_t *V, uint32_t *S, uint32_t *M1); extern void __update_VS_64x320(uint32_t *V, uint32_t *S, uint32_t *M1); extern void __update_VS_64x384(uint32_t *V, uint32_t *S, uint32_t *M1); extern void __update_VS_64x448(uint32_t *V, uint32_t *S, uint32_t *M1); extern void __update_VS_64x512(uint32_t *V, uint32_t *S, uint32_t *M1); extern void __update_VS_64x528(uint32_t *V, uint32_t *S, uint32_t *M1); extern void __update_fg_64x448(uint32_t *f, uint32_t *g, uint32_t *M1); extern void __update_fg_64x384(uint32_t *f, uint32_t *g, uint32_t *M1); extern void __update_fg_64x320(uint32_t *f, uint32_t *g, uint32_t *M1); extern void __update_fg_64x256(uint32_t *f, uint32_t *g, uint32_t *M1); extern void __update_fg_64x192(uint32_t *f, uint32_t *g, uint32_t *M1); extern void __update_fg_64x128(uint32_t *f, uint32_t *g, uint32_t *M1); extern void __update_fg_64x64(uint32_t *f, uint32_t *g, uint32_t *M1); int jump1024divsteps_mod3_64(int minusdelta, uint32_t *M, uint32_t *f, uint32_t *g){ uint32_t V[132]; uint32_t S[132]; uint32_t M1[96]; // 64 coefficients * 6 uint32_t *ptr = M; for(int i = 0; i < 132; i++){ V[i] = 0; S[i] = 0; } *(S) = 1; // 1: 8 minusdelta = jump64divsteps_mod3(minusdelta,M1,f,g); __update_fg_64x512(f, g, M1+32); __update_VS_64x64(V, S, M1+32); minusdelta = jump64divsteps_mod3(minusdelta,M1,f,g); __update_fg_64x512(f, g, M1+32); __update_VS_64x64(V, S, M1+32); minusdelta = jump64divsteps_mod3(minusdelta,M1,f,g); __update_fg_64x512(f, g, M1+32); __update_VS_64x128(V, S, M1+32); minusdelta = jump64divsteps_mod3(minusdelta,M1,f,g); __update_fg_64x512(f, g, M1+32); __update_VS_64x192(V, S, M1+32); minusdelta = jump64divsteps_mod3(minusdelta,M1,f,g); __update_fg_64x512(f, g, M1+32); __update_VS_64x256(V, S, M1+32); minusdelta = jump64divsteps_mod3(minusdelta,M1,f,g); __update_fg_64x512(f, g, M1+32); __update_VS_64x320(V, S, M1+32); minusdelta = jump64divsteps_mod3(minusdelta,M1,f,g); __update_fg_64x512(f, g, M1+32); __update_VS_64x384(V, S, M1+32); minusdelta = jump64divsteps_mod3(minusdelta,M1,f,g); __update_fg_64x512(f, g, M1+32); __update_VS_64x448(V, S, M1+32); // 2 minusdelta = jump64divsteps_mod3(minusdelta,M1,f,g); __update_fg_64x512(f, g, M1+32); __update_VS_64x512(V, S, M1+32); // 3 minusdelta = jump64divsteps_mod3(minusdelta,M1,f,g); __update_fg_64x448(f, g, M1+32); __update_VS_64x512(V, S, M1+32); minusdelta = jump64divsteps_mod3(minusdelta,M1,f,g); __update_fg_64x384(f, g, M1+32); __update_VS_64x512(V, S, M1+32); minusdelta = jump64divsteps_mod3(minusdelta,M1,f,g); __update_fg_64x320(f, g, M1+32); __update_VS_64x512(V, S, M1+32); minusdelta = jump64divsteps_mod3(minusdelta,M1,f,g); __update_fg_64x256(f, g, M1+32); __update_VS_64x512(V, S, M1+32); minusdelta = jump64divsteps_mod3(minusdelta,M1,f,g); __update_fg_64x192(f, g, M1+32); __update_VS_64x512(V, S, M1+32); minusdelta = jump64divsteps_mod3(minusdelta,M1,f,g); __update_fg_64x128(f, g, M1+32); __update_VS_64x512(V, S, M1+32); minusdelta = jump64divsteps_mod3(minusdelta,M1,f,g); __update_fg_64x64(f, g, M1+32); __update_VS_64x528(V, S, M1+32); for (int i = 0; i < 132; i++) { *ptr++ = V[i]; } return minusdelta; }
the_stack_data/165766186.c
// SKIP PARAM: --set solver td3 --enable ana.int.interval --enable ana.base.partition-arrays.enabled --set ana.base.partition-arrays.keep-expr "last" --set ana.activated "['base','threadid','threadflag','escape','expRelation','apron','mallocWrapper']" --set ana.base.privatization none --set sem.int.signed_overflow assume_none void main(void) { example1(); example2(); example3(); example4(); example4a(); example4b(); example4c(); example5(); example6(); example7(); example8(); mineEx1(); } void example1(void) { int a[20]; int i = 0; int j = 0; int top; int z; // Necessary so we can not answer the queries below from the base domain // and actually test the behavior of the octagons int between1and8; if(between1and8 < 1) { between1and8 = 1; } if(between1and8 > 8) { between1and8 = 8; } while(i < 20) { a[i] = 0; i++; } while(j < between1and8) { a[j] = 1; j++; } a[j] = 2; // a -> (j,([1,1],[2,2],[0,0])) if(top) { z = j; } else { z = j-1; } // Values that may be read are 1 or 2 assert(a[z] == 1); //UNKNOWN assert(a[z] == 2); //UNKNOWN // Relies on option sem.int.signed_overflow assume_none assert(a[z] != 0); } void example2(void) { int a[20]; int i = 0; int j = 0; int top; int z; // Necessary so we can not answer the queries below from the base domain // and actually test the behavior of the octagons int between1and8; if(between1and8 < 1) { between1and8 = 1; } if(between1and8 > 8) { between1and8 = 8; } while(i < 20) { a[i] = 0; i++; } while(j < between1and8) { a[j] = 2; j++; } a[j] = 1; // a -> (j,([2,2],[1,1],[0,0])) if(top) { z = j; } else { z = j+1; } // Values that may be read are 1 or 0 assert(a[z] == 1); //UNKNOWN assert(a[z] == 0); //UNKNOWN // Relies on option sem.int.signed_overflow assume_none assert(a[z] != 2); } // Simple example (employing MustBeEqual) void example3(void) { int a[42]; int i = 0; int x; while(i < 42) { a[i] = 0; int v = i; x = a[v]; assert(x == 0); i++; } } // Simple example (employing MayBeEqual / MayBeSmaller) void example4(void) { int a[42]; int i = 0; while(i<=9) { a[i] = 9; int j = i+5; a[j] = 42; // Here we know a[i] is 9 when we have MayBeEqual assert(a[i] == 9); // UNKNOWN // but only about the part to the left of i if we also have MayBeSmaller if(i>0) { int k = a[i-1]; assert(k == 9); // UNKNOWN int l = a[0]; assert(l == 9); // UNKNOWN } i++; } } // Just like the example before except that it tests correct behavior when variable order is reversed void example4a(void) { int a[42]; int j; int i = 0; while(i<=9) { a[i] = 9; j = i+5; a[j] = 42; // Here we know a[i] is 9 when we have MayBeEqual assert(a[i] == 9); //UNKNOWN // but only about the part to the left of i if we also have MayBeSmaller if(i>0) { assert(a[i-1] == 9); //UNKNOWN } i++; } } // Just like the example before except that it tests correct behavior when operands for + are reversed void example4b(void) { int a[42]; int j; int i = 0; while(i<=9) { a[i] = 9; j = 5+i; a[j] = 42; // Here we know a[i] is 9 when we have MayBeEqual assert(a[i] == 9); //UNKNOWN // but only about the part to the left of i if we also have MayBeSmaller if(i>0) { assert(a[i-1] == 9); //UNKNOWN } i++; } } // Like example before but iterating backwards void example4c(void) { int a[42]; int j; int i = 41; while(i > 8) { a[i] = 7; a[i-2] = 31; if(i < 41) { assert(a[i+1] == 7); //UNKNOWN } i--; } } void example5(void) { int a[40]; int i = 0; // This is a dirty cheat to get the array to be partitioned before entering the loop // This is needed because the may be less of the octagons is not sophisticated enough yet. // Once that is fixed this will also work without this line a[i] = 0; while(i < 42) { int j = i; a[j] = 0; i++; assert(a[i] == 0); //UNKNOWN assert(a[i-1] == 0); assert(a[j] == 0); if (i>1) { assert(a[i-2] == 0); assert(a[j-1] == 0); } } } void example6(void) { int a[42]; int i = 0; int top; while(i<30) { a[i] = 0; i++; assert(a[top] == 0); //UNKNOWN int j=0; while(j<i) { assert(a[j] == 0); j++; } } } void example7(void) { int top; int a[42]; int i = 0; int j; while(i<30) { a[i] = 0; i++; if(i > 10) { if(top) { j = i-5; } else { j = i-7; } assert(a[j] == 0); } } } void example8(void) { int a[42]; int i = 0; int j = i; int N; if(N < 5) { N = 5; } if(N > 40) { N = 40; } while(i < N) { a[i] = 0; i++; j = i; a[j-1] = 0; a[j] = 0; j++; // Octagon knows -1 <= i-j <= -1 i = j; // Without octagons, we lose partitioning here because we don't know how far the move has been assert(a[i-1] == 0); assert(a[i-2] == 0); } j = 0; while(j < N) { assert(a[j] == 0); //UNKNOWN j++; } } // Example from https://www-apr.lip6.fr/~mine/publi/article-mine-HOSC06.pdf void mineEx1(void) { int X = 0; int N = rand(); if(N < 0) { N = 0; } while(X < N) { X++; } assert(X-N == 0); // assert(X == N); // Currently not able to assert this because octagon doesn't handle it if(X == N) { N = 8; } else { // is dead code but if that is detected or not depends on what we do in branch // currenlty we can't detect this N = 42; } }
the_stack_data/155098.c
#include <math.h> // terminar esto, no se en que punto quieren que la evalue float sin_taylorW (float x) { const float pi = 3.14159265359; int k = floor(x/(2*pi)); float r = x - k*2*pi; x = r - pi; float y = x - (pow(x,3)/6) + (pow(x,5)/120) - (pow(x,7)/5040); return y; } void waves_c ( unsigned char *src, unsigned char *dst, int m, int n, int row_size, float x_scale, float y_scale, float g_scale ) { unsigned char (*src_matrix)[row_size] = (unsigned char (*)[row_size]) src; unsigned char (*dst_matrix)[row_size] = (unsigned char (*)[row_size]) dst; double prof; int i, j; for (i = 0; i < m; ++i){ for (j = 0; j < n; ++j){ prof = ( x_scale*sin_taylorW(i/8.0) + y_scale*sin_taylorW(j/8.0) )/2; double newValue = prof*g_scale + src_matrix[i][j]; if(newValue > 255) newValue = 255; else if(newValue < 0) newValue = 0; unsigned int value = floor(newValue); dst_matrix[i][j] = value; } } }
the_stack_data/43888200.c
// // Created by zing on 5/23/2020. // #include <pthread.h> #include <stdio.h> #include <errno.h> #include <unistd.h> static void *thread_start(void *arg) { printf("thread_start pid %d thread_id %lx\n",getpid(),pthread_self()); return NULL; } int pthread_create1() { pthread_t pthread; pthread_attr_t pthreadAttr; if (pthread_attr_init(&pthreadAttr) != 0) { perror("pthread_attr_init"); return errno; } int s = pthread_create(&pthread, &pthreadAttr, &thread_start, NULL); if (s != 0) { perror("pthread_create"); return errno; } s = pthread_create(&pthread, &pthreadAttr, &thread_start, NULL); if (s != 0) { perror("pthread_create"); return errno; } return 0; } //void *(*__start_routine) (void *), void *print1(void *argv) { printf("print1 pid %d thread_id %lx\n",getpid(),pthread_self()); printf("get param { %s }\n",(char *)argv); for (int i = 0; i < 10; i++) { sleep(1); printf("print1 %d\n", i); } return 0; } pthread_t pthread_create2() { pthread_t pthread; if (0 != pthread_create(&pthread, NULL, &print1, "i am from pthread_create2")) { perror("pthread_create"); return errno; } return pthread; } int main(int argc, char *argv[]) { printf("main pid %d thread_id %lx\n",getpid(),pthread_self()); pthread_create1(); pthread_t p2 = pthread_create2(); void *rev2; pthread_join(p2,&rev2); return 0; }
the_stack_data/867702.c
// RUN: %crabllvm --inline --lower-select --lower-unsigned-icmp --do-not-print-invariants --crab-dom=boxes --crab-check=assert %opts "%s" 2>&1 | OutputCheck -l debug %s // CHECK: ^0 Number of total safe checks$ // CHECK: ^0 Number of total error checks$ // CHECK: ^1 Number of total warning checks$ extern void __VERIFIER_error() __attribute__ ((__noreturn__)); extern char __VERIFIER_nondet_char(void); extern int __VERIFIER_nondet_int(void); extern long __VERIFIER_nondet_long(void); extern void *__VERIFIER_nondet_pointer(void); extern int __VERIFIER_nondet_int(); /* Generated by CIL v. 1.3.6 */ /* print_CIL_Input is true */ int ssl3_accept(int initial_state ) { int s__info_callback = __VERIFIER_nondet_int() ; int s__in_handshake = __VERIFIER_nondet_int() ; int s__state ; int s__new_session ; int s__server ; int s__version = __VERIFIER_nondet_int() ; int s__type ; int s__init_num ; int s__hit = __VERIFIER_nondet_int() ; int s__rwstate ; int s__init_buf___0 ; int s__debug = __VERIFIER_nondet_int() ; int s__shutdown ; int s__cert = __VERIFIER_nondet_int() ; int s__options = __VERIFIER_nondet_int() ; int s__verify_mode = __VERIFIER_nondet_int() ; int s__session__peer = __VERIFIER_nondet_int() ; int s__cert__pkeys__AT0__privatekey = __VERIFIER_nondet_int() ; int s__ctx__info_callback = __VERIFIER_nondet_int() ; int s__ctx__stats__sess_accept_renegotiate = __VERIFIER_nondet_int() ; int s__ctx__stats__sess_accept = __VERIFIER_nondet_int() ; int s__ctx__stats__sess_accept_good = __VERIFIER_nondet_int() ; int s__s3__tmp__cert_request ; int s__s3__tmp__reuse_message = __VERIFIER_nondet_int() ; int s__s3__tmp__use_rsa_tmp ; int s__s3__tmp__new_cipher = __VERIFIER_nondet_int() ; int s__s3__tmp__new_cipher__algorithms = __VERIFIER_nondet_int() ; int s__s3__tmp__next_state___0 ; int s__s3__tmp__new_cipher__algo_strength = __VERIFIER_nondet_int() ; int s__session__cipher ; int buf = __VERIFIER_nondet_int() ; unsigned long l ; unsigned long Time ; unsigned long tmp = __VERIFIER_nondet_long() ; int cb ; long num1 ; int ret ; int new_state ; int state ; int skip ; int got_new_session ; int tmp___1 = __VERIFIER_nondet_int() ; int tmp___2 = __VERIFIER_nondet_int() ; int tmp___3 ; int tmp___4 ; int tmp___5 ; int tmp___6 ; int tmp___7 ; long tmp___8 = __VERIFIER_nondet_long() ; int tmp___9 ; int tmp___10 ; int blastFlag ; int __cil_tmp55 ; unsigned long __cil_tmp56 ; unsigned long __cil_tmp57 ; unsigned long __cil_tmp58 ; unsigned long __cil_tmp59 ; int __cil_tmp60 ; unsigned long __cil_tmp61 ; { ; s__state = initial_state; blastFlag = 0; Time = tmp; cb = 0; ret = -1; skip = 0; got_new_session = 0; if (s__info_callback != 0) { cb = s__info_callback; } else { if (s__ctx__info_callback != 0) { cb = s__ctx__info_callback; } } s__in_handshake ++; if (tmp___1 + 12288) { if (tmp___2 + 16384) { } } if (s__cert == 0) { return (-1); } { while (1) { while_0_continue: /* CIL Label */ ; state = s__state; if (s__state == 12292) { goto switch_1_12292; } else { if (s__state == 16384) { goto switch_1_16384; } else { if (s__state == 8192) { goto switch_1_8192; } else { if (s__state == 24576) { goto switch_1_24576; } else { if (s__state == 8195) { goto switch_1_8195; } else { if (s__state == 8480) { goto switch_1_8480; } else { if (s__state == 8481) { goto switch_1_8481; } else { if (s__state == 8482) { goto switch_1_8482; } else { if (s__state == 8464) { goto switch_1_8464; } else { if (s__state == 8465) { goto switch_1_8465; } else { if (s__state == 8466) { goto switch_1_8466; } else { if (s__state == 8496) { goto switch_1_8496; } else { if (s__state == 8497) { goto switch_1_8497; } else { if (s__state == 8512) { goto switch_1_8512; } else { if (s__state == 8513) { goto switch_1_8513; } else { if (s__state == 8528) { goto switch_1_8528; } else { if (s__state == 8529) { goto switch_1_8529; } else { if (s__state == 8544) { goto switch_1_8544; } else { if (s__state == 8545) { goto switch_1_8545; } else { if (s__state == 8560) { goto switch_1_8560; } else { if (s__state == 8561) { goto switch_1_8561; } else { if (s__state == 8448) { goto switch_1_8448; } else { if (s__state == 8576) { goto switch_1_8576; } else { if (s__state == 8577) { goto switch_1_8577; } else { if (s__state == 8592) { goto switch_1_8592; } else { if (s__state == 8593) { goto switch_1_8593; } else { if (s__state == 8608) { goto switch_1_8608; } else { if (s__state == 8609) { goto switch_1_8609; } else { if (s__state == 8640) { goto switch_1_8640; } else { if (s__state == 8641) { goto switch_1_8641; } else { if (s__state == 8656) { goto switch_1_8656; } else { if (s__state == 8657) { goto switch_1_8657; } else { if (s__state == 8672) { goto switch_1_8672; } else { if (s__state == 8673) { goto switch_1_8673; } else { if (s__state == 3) { goto switch_1_3; } else { goto switch_1_default; if (0) { switch_1_12292: s__new_session = 1; switch_1_16384: ; switch_1_8192: ; switch_1_24576: ; switch_1_8195: s__server = 1; if (cb != 0) { } { __cil_tmp55 = s__version * 8; if (__cil_tmp55 != 3) { return (-1); } } s__type = 8192; if (s__init_buf___0 == 0) { tmp___3 = __VERIFIER_nondet_int(); if (! tmp___3) { ret = -1; goto end; } s__init_buf___0 = buf; } tmp___4 = __VERIFIER_nondet_int(); if (! tmp___4) { ret = -1; goto end; } s__init_num = 0; if (s__state != 12292) { tmp___5 = __VERIFIER_nondet_int(); if (! tmp___5) { ret = -1; goto end; } s__state = 8464; s__ctx__stats__sess_accept ++; } else { s__ctx__stats__sess_accept_renegotiate ++; s__state = 8480; } goto switch_1_break; switch_1_8480: ; switch_1_8481: s__shutdown = 0; ret = __VERIFIER_nondet_int(); if (ret <= 0) { goto end; } s__s3__tmp__next_state___0 = 8482; s__state = 8448; s__init_num = 0; goto switch_1_break; switch_1_8482: s__state = 3; goto switch_1_break; switch_1_8464: ; switch_1_8465: ; switch_1_8466: s__shutdown = 0; ret = __VERIFIER_nondet_int(); if (blastFlag == 0) { blastFlag = 1; } if (ret <= 0) { goto end; } got_new_session = 1; s__state = 8496; s__init_num = 0; goto switch_1_break; switch_1_8496: ; switch_1_8497: ret = __VERIFIER_nondet_int(); if (blastFlag == 1) { blastFlag = 2; } if (ret <= 0) { goto end; } if (s__hit) { s__state = 8656; } else { s__state = 8512; } s__init_num = 0; goto switch_1_break; switch_1_8512: ; switch_1_8513: ; { __cil_tmp56 = (unsigned long )s__s3__tmp__new_cipher__algorithms; if (__cil_tmp56 + 256UL) { skip = 1; } else { ret = __VERIFIER_nondet_int(); if (ret <= 0) { goto end; } } } s__state = 8528; s__init_num = 0; goto switch_1_break; switch_1_8528: ; switch_1_8529: l = (unsigned long )s__s3__tmp__new_cipher__algorithms; { __cil_tmp57 = (unsigned long )s__options; if (__cil_tmp57 + 2097152UL) { s__s3__tmp__use_rsa_tmp = 1; } else { s__s3__tmp__use_rsa_tmp = 0; } } if (s__s3__tmp__use_rsa_tmp) { goto _L___0; } else { if (l + 30UL) { goto _L___0; } else { if (l + 1UL) { if (s__cert__pkeys__AT0__privatekey == 0) { goto _L___0; } else { { __cil_tmp58 = (unsigned long )s__s3__tmp__new_cipher__algo_strength; if (__cil_tmp58 + 2UL) { tmp___6 = __VERIFIER_nondet_int(); { __cil_tmp59 = (unsigned long )s__s3__tmp__new_cipher__algo_strength; if (__cil_tmp59 + 4UL) { tmp___7 = 512; } else { tmp___7 = 1024; } } { __cil_tmp60 = tmp___6 * 8; if (__cil_tmp60 > tmp___7) { _L___0: ret = __VERIFIER_nondet_int(); if (ret <= 0) { goto end; } } else { skip = 1; } } } else { skip = 1; } } } } else { skip = 1; } } } s__state = 8544; s__init_num = 0; goto switch_1_break; switch_1_8544: ; switch_1_8545: ; if (s__verify_mode + 1) { if (s__session__peer != 0) { if (s__verify_mode + 4) { skip = 1; s__s3__tmp__cert_request = 0; s__state = 8560; } else { goto _L___2; } } else { _L___2: { __cil_tmp61 = (unsigned long )s__s3__tmp__new_cipher__algorithms; if (__cil_tmp61 + 256UL) { if (s__verify_mode + 2) { goto _L___1; } else { skip = 1; s__s3__tmp__cert_request = 0; s__state = 8560; } } else { _L___1: s__s3__tmp__cert_request = 1; ret = __VERIFIER_nondet_int(); if (ret <= 0) { goto end; } s__state = 8448; s__s3__tmp__next_state___0 = 8576; s__init_num = 0; } } } } else { skip = 1; s__s3__tmp__cert_request = 0; s__state = 8560; } goto switch_1_break; switch_1_8560: ; switch_1_8561: ret = __VERIFIER_nondet_int(); if (ret <= 0) { goto end; } s__s3__tmp__next_state___0 = 8576; s__state = 8448; s__init_num = 0; goto switch_1_break; switch_1_8448: num1 = __VERIFIER_nondet_int(); if (num1 > 0L) { s__rwstate = 2; num1 = tmp___8; if (num1 <= 0L) { ret = -1; goto end; } s__rwstate = 1; } s__state = s__s3__tmp__next_state___0; goto switch_1_break; switch_1_8576: ; switch_1_8577: ret = __VERIFIER_nondet_int(); if (ret <= 0) { goto end; } if (ret == 2) { s__state = 8466; } else { ret = __VERIFIER_nondet_int(); if (ret <= 0) { goto end; } s__init_num = 0; s__state = 8592; } goto switch_1_break; switch_1_8592: ; switch_1_8593: ret = __VERIFIER_nondet_int(); if (ret <= 0) { goto end; } s__state = 8608; s__init_num = 0; goto switch_1_break; switch_1_8608: ; switch_1_8609: ret = __VERIFIER_nondet_int(); if (ret <= 0) { goto end; } s__state = 8640; s__init_num = 0; goto switch_1_break; switch_1_8640: ; switch_1_8641: ret = __VERIFIER_nondet_int(); if (blastFlag == 3) { blastFlag = 4; } if (ret <= 0) { goto end; } if (s__hit) { s__state = 3; } else { s__state = 8656; } s__init_num = 0; goto switch_1_break; switch_1_8656: ; switch_1_8657: s__session__cipher = s__s3__tmp__new_cipher; tmp___9 = __VERIFIER_nondet_int(); if (! tmp___9) { ret = -1; goto end; } ret = __VERIFIER_nondet_int(); if (blastFlag == 2) { blastFlag = 3; } if (ret <= 0) { goto end; } s__state = 8672; s__init_num = 0; tmp___10 = __VERIFIER_nondet_int(); if (! tmp___10) { ret = -1; goto end; } goto switch_1_break; switch_1_8672: ; switch_1_8673: ret = __VERIFIER_nondet_int(); if (blastFlag == 4) { blastFlag = 5; } else { if (blastFlag == 3) { goto ERROR; } } if (ret <= 0) { goto end; } s__state = 8448; if (s__hit) { s__s3__tmp__next_state___0 = 8640; } else { s__s3__tmp__next_state___0 = 3; } s__init_num = 0; goto switch_1_break; switch_1_3: s__init_buf___0 = 0; s__init_num = 0; if (got_new_session) { s__new_session = 0; s__ctx__stats__sess_accept_good ++; if (cb != 0) { } } ret = 1; goto end; switch_1_default: ret = -1; goto end; } else { switch_1_break: ; } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } if (! s__s3__tmp__reuse_message) { if (! skip) { if (s__debug) { ret = __VERIFIER_nondet_int(); if (ret <= 0) { goto end; } } if (cb != 0) { if (s__state != state) { new_state = s__state; s__state = state; s__state = new_state; } } } } skip = 0; } while_0_break: /* CIL Label */ ; } end: s__in_handshake --; if (cb != 0) { } return (ret); ERROR: __VERIFIER_error(); return (-1); } } int main(void) { int s ; int tmp ; { { s = 8464; tmp = ssl3_accept(s); } return (tmp); } }
the_stack_data/840044.c
/* display.c, X11 interface */ /* Copyright (C) 1996, MPEG Software Simulation Group. All Rights Reserved. */ /* * Disclaimer of Warranty * * These software programs are available to the user without any license fee or * royalty on an "as is" basis. The MPEG Software Simulation Group disclaims * any and all warranties, whether express, implied, or statuary, including any * implied warranties or merchantability or of fitness for a particular * purpose. In no event shall the copyright-holder be liable for any * incidental, punitive, or consequential damages of any kind whatsoever * arising from the use of these programs. * * This disclaimer of warranty extends to the user of these programs and user's * customers, employees, agents, transferees, successors, and assigns. * * The MPEG Software Simulation Group does not represent or warrant that the * programs furnished hereunder are free of infringement of any third-party * patents. * * Commercial implementations of MPEG-1 and MPEG-2 video, including shareware, * are subject to royalty fees to patent holders. Many of these patents are * general enough such that they are unavoidable regardless of implementation * design. * */ #ifdef DISPLAY /* the Xlib interface is closely modeled after * mpeg_play 2.0 by the Berkeley Plateau Research Group */ #include <stdio.h> #include <stdlib.h> #include <X11/Xlib.h> #include <X11/Xutil.h> #include "config.h" #include "global.h" /* private prototypes */ static void Display_Image _ANSI_ARGS_((XImage *Ximage_Ptr, unsigned char *Dithered_Image)); static void Dither_Frame _ANSI_ARGS_((unsigned char *src[])); static void Dither_Top_Field _ANSI_ARGS_((unsigned char *src[], unsigned char *dst)); static void Dither_Bottom_Field _ANSI_ARGS_((unsigned char *src[], unsigned char *dst)); static void Dither_Top_Field420 _ANSI_ARGS_((unsigned char *src[], unsigned char *dst)); static void Dither_Bottom_Field420 _ANSI_ARGS_((unsigned char *src[], unsigned char *dst)); /* local data */ static unsigned char *Dithered_Image, *Dithered_Image2; static unsigned char Y_Table[256+16]; static unsigned char Cb_Table[128+16]; static unsigned char Cr_Table[128+16]; /* X11 related variables */ static Display *Display_Ptr; static Window Window_Instance; static GC GC_Instance; static XImage *Ximage_Ptr, *Ximage_Ptr2; static unsigned char Pixel[256]; #ifdef SH_MEM #include <sys/ipc.h> #include <sys/shm.h> #include <X11/extensions/XShm.h> static int HandleXError _ANSI_ARGS_((Display *dpy, XErrorEvent *event)); static void InstallXErrorHandler _ANSI_ARGS_((void)); static void DeInstallXErrorHandler _ANSI_ARGS_((void)); static int Shmem_Flag; static XShmSegmentInfo Shminfo1, Shminfo2; static int gXErrorFlag; static int CompletionType = -1; static int HandleXError(Dpy, Event) Display *Dpy; XErrorEvent *Event; { gXErrorFlag = 1; return 0; } static void InstallXErrorHandler() { XSetErrorHandler(HandleXError); XFlush(Display_Ptr); } static void DeInstallXErrorHandler() { XSetErrorHandler(NULL); XFlush(Display_Ptr); } #endif /* connect to server, create and map window, * allocate colors and (shared) memory */ void Initialize_Display_Process(name) char *name; { int crv, cbu, cgu, cgv; int Y, Cb, Cr, R, G, B; int i; char dummy; int screen; Colormap cmap; int private; XColor xcolor; unsigned int fg, bg; char *hello = "MPEG-2 Display"; XSizeHints hint; XVisualInfo vinfo; XEvent xev; unsigned long tmp_pixel; XWindowAttributes xwa; Display_Ptr = XOpenDisplay(name); if (Display_Ptr == NULL) Error("Can not open display\n"); screen = DefaultScreen(Display_Ptr); hint.x = 200; hint.y = 200; hint.width = horizontal_size; hint.height = vertical_size; hint.flags = PPosition | PSize; /* Get some colors */ bg = WhitePixel (Display_Ptr, screen); fg = BlackPixel (Display_Ptr, screen); /* Make the window */ if (!XMatchVisualInfo(Display_Ptr, screen, 8, PseudoColor, &vinfo)) { if (!XMatchVisualInfo(Display_Ptr, screen, 8, GrayScale, &vinfo)) Error("requires 8 bit display\n"); } Window_Instance = XCreateSimpleWindow (Display_Ptr, DefaultRootWindow (Display_Ptr), hint.x, hint.y, hint.width, hint.height, 4, fg, bg); XSelectInput(Display_Ptr, Window_Instance, StructureNotifyMask); /* Tell other applications about this window */ XSetStandardProperties (Display_Ptr, Window_Instance, hello, hello, None, NULL, 0, &hint); /* Map window. */ XMapWindow(Display_Ptr, Window_Instance); /* Wait for map. */ do { XNextEvent(Display_Ptr, &xev); } while (xev.type != MapNotify || xev.xmap.event != Window_Instance); XSelectInput(Display_Ptr, Window_Instance, NoEventMask); /* matrix coefficients */ crv = Inverse_Table_6_9[matrix_coefficients][0]; cbu = Inverse_Table_6_9[matrix_coefficients][1]; cgu = Inverse_Table_6_9[matrix_coefficients][2]; cgv = Inverse_Table_6_9[matrix_coefficients][3]; /* allocate colors */ GC_Instance = DefaultGC(Display_Ptr, screen); cmap = DefaultColormap(Display_Ptr, screen); private = 0; /* color allocation: * i is the (internal) 8 bit color number, it consists of separate * bit fields for Y, U and V: i = (yyyyuuvv), we don't use yyyy=0000 * and yyyy=1111, this leaves 32 colors for other applications * * the allocated colors correspond to the following Y, U and V values: * Y: 24, 40, 56, 72, 88, 104, 120, 136, 152, 168, 184, 200, 216, 232 * U,V: -48, -16, 16, 48 * * U and V values span only about half the color space; this gives * usually much better quality, although highly saturated colors can * not be displayed properly * * translation to R,G,B is implicitly done by the color look-up table */ for (i=16; i<240; i++) { /* color space conversion */ Y = 16*((i>>4)&15) + 8; Cb = 32*((i>>2)&3) - 48; Cr = 32*(i&3) - 48; Y = 76309 * (Y - 16); /* (255/219)*65536 */ R = Clip[(Y + crv*Cr + 32768)>>16]; G = Clip[(Y - cgu*Cb - cgv*Cr + 32768)>>16]; B = Clip[(Y + cbu*Cb + 32786)>>16]; /* X11 colors are 16 bit */ xcolor.red = R << 8; xcolor.green = G << 8; xcolor.blue = B << 8; if (XAllocColor(Display_Ptr, cmap, &xcolor) != 0) Pixel[i] = xcolor.pixel; else { /* allocation failed, have to use a private colormap */ if (private) Error("Couldn't allocate private colormap"); private = 1; if (!Quiet_Flag) fprintf(stderr, "Using private colormap (%d colors were available).\n", i-16); /* Free colors. */ while (--i >= 16) { tmp_pixel = Pixel[i]; /* because XFreeColors expects unsigned long */ XFreeColors(Display_Ptr, cmap, &tmp_pixel, 1, 0); } /* i is now 15, this restarts the outer loop */ /* create private colormap */ XGetWindowAttributes(Display_Ptr, Window_Instance, &xwa); cmap = XCreateColormap(Display_Ptr, Window_Instance, xwa.visual, AllocNone); XSetWindowColormap(Display_Ptr, Window_Instance, cmap); } } #ifdef SH_MEM if (XShmQueryExtension(Display_Ptr)) Shmem_Flag = 1; else { Shmem_Flag = 0; if (!Quiet_Flag) fprintf(stderr, "Shared memory not supported\nReverting to normal Xlib\n"); } if (Shmem_Flag) CompletionType = XShmGetEventBase(Display_Ptr) + ShmCompletion; InstallXErrorHandler(); if (Shmem_Flag) { Ximage_Ptr = XShmCreateImage(Display_Ptr, None, 8, ZPixmap, NULL, &Shminfo1, Coded_Picture_Width, Coded_Picture_Height); if (!progressive_sequence) Ximage_Ptr2 = XShmCreateImage(Display_Ptr, None, 8, ZPixmap, NULL, &Shminfo2, Coded_Picture_Width, Coded_Picture_Height); /* If no go, then revert to normal Xlib calls. */ if (Ximage_Ptr==NULL || (!progressive_sequence && Ximage_Ptr2==NULL)) { if (Ximage_Ptr!=NULL) XDestroyImage(Ximage_Ptr); if (!progressive_sequence && Ximage_Ptr2!=NULL) XDestroyImage(Ximage_Ptr2); if (!Quiet_Flag) fprintf(stderr, "Shared memory error, disabling (Ximage error)\n"); goto shmemerror; } /* Success here, continue. */ Shminfo1.shmid = shmget(IPC_PRIVATE, Ximage_Ptr->bytes_per_line * Ximage_Ptr->height, IPC_CREAT | 0777); if (!progressive_sequence) Shminfo2.shmid = shmget(IPC_PRIVATE, Ximage_Ptr2->bytes_per_line * Ximage_Ptr2->height, IPC_CREAT | 0777); if (Shminfo1.shmid<0 || (!progressive_sequence && Shminfo2.shmid<0)) { XDestroyImage(Ximage_Ptr); if (!progressive_sequence) XDestroyImage(Ximage_Ptr2); if (!Quiet_Flag) fprintf(stderr, "Shared memory error, disabling (seg id error)\n"); goto shmemerror; } Shminfo1.shmaddr = (char *) shmat(Shminfo1.shmid, 0, 0); Shminfo2.shmaddr = (char *) shmat(Shminfo2.shmid, 0, 0); if (Shminfo1.shmaddr==((char *) -1) || (!progressive_sequence && Shminfo2.shmaddr==((char *) -1))) { XDestroyImage(Ximage_Ptr); if (Shminfo1.shmaddr!=((char *) -1)) shmdt(Shminfo1.shmaddr); if (!progressive_sequence) { XDestroyImage(Ximage_Ptr2); if (Shminfo2.shmaddr!=((char *) -1)) shmdt(Shminfo2.shmaddr); } if (!Quiet_Flag) { fprintf(stderr, "Shared memory error, disabling (address error)\n"); } goto shmemerror; } Ximage_Ptr->data = Shminfo1.shmaddr; Dithered_Image = (unsigned char *)Ximage_Ptr->data; Shminfo1.readOnly = False; XShmAttach(Display_Ptr, &Shminfo1); if (!progressive_sequence) { Ximage_Ptr2->data = Shminfo2.shmaddr; Dithered_Image2 = (unsigned char *)Ximage_Ptr2->data; Shminfo2.readOnly = False; XShmAttach(Display_Ptr, &Shminfo2); } XSync(Display_Ptr, False); if (gXErrorFlag) { /* Ultimate failure here. */ XDestroyImage(Ximage_Ptr); shmdt(Shminfo1.shmaddr); if (!progressive_sequence) { XDestroyImage(Ximage_Ptr2); shmdt(Shminfo2.shmaddr); } if (!Quiet_Flag) fprintf(stderr, "Shared memory error, disabling.\n"); gXErrorFlag = 0; goto shmemerror; } else { shmctl(Shminfo1.shmid, IPC_RMID, 0); if (!progressive_sequence) shmctl(Shminfo2.shmid, IPC_RMID, 0); } if (!Quiet_Flag) { fprintf(stderr, "Sharing memory.\n"); } } else { shmemerror: Shmem_Flag = 0; #endif Ximage_Ptr = XCreateImage(Display_Ptr,None,8,ZPixmap,0,&dummy, Coded_Picture_Width,Coded_Picture_Height,8,0); if (!(Dithered_Image = (unsigned char *)malloc(Coded_Picture_Width* Coded_Picture_Height))) Error("malloc failed"); if (!progressive_sequence) { Ximage_Ptr2 = XCreateImage(Display_Ptr,None,8,ZPixmap,0,&dummy, Coded_Picture_Width,Coded_Picture_Height,8,0); if (!(Dithered_Image2 = (unsigned char *)malloc(Coded_Picture_Width* Coded_Picture_Height))) Error("malloc failed"); } #ifdef SH_MEM } DeInstallXErrorHandler(); #endif } void Terminate_Display_Process() { #ifdef SH_MEM if (Shmem_Flag) { XShmDetach(Display_Ptr, &Shminfo1); XDestroyImage(Ximage_Ptr); shmdt(Shminfo1.shmaddr); if (!progressive_sequence) { XShmDetach(Display_Ptr, &Shminfo2); XDestroyImage(Ximage_Ptr2); shmdt(Shminfo2.shmaddr); } } #endif } static void Display_Image(Ximage_Ptr,Dithered_Image) XImage *Ximage_Ptr; unsigned char *Dithered_Image; { /* display dithered image */ #ifdef SH_MEM if (Shmem_Flag) { XShmPutImage(Display_Ptr, Window_Instance, GC_Instance, Ximage_Ptr, 0, 0, 0, 0, Ximage_Ptr->width, Ximage_Ptr->height, True); XFlush(Display_Ptr); while (1) { XEvent xev; XNextEvent(Display_Ptr, &xev); if (xev.type == CompletionType) break; } } else #endif { Ximage_Ptr->data = (char *) Dithered_Image; XPutImage(Display_Ptr, Window_Instance, GC_Instance, Ximage_Ptr, 0, 0, 0, 0, Ximage_Ptr->width, Ximage_Ptr->height); } } void Display_Second_Field() { Display_Image(Ximage_Ptr2,Dithered_Image2); } /* 4x4 ordered dither * * threshold pattern: * 0 8 2 10 * 12 4 14 6 * 3 11 1 9 * 15 7 13 5 */ void Initialize_Dither_Matrix() { int i, v; for (i=-8; i<256+8; i++) { v = i>>4; if (v<1) v = 1; else if (v>14) v = 14; Y_Table[i+8] = v<<4; } for (i=0; i<128+16; i++) { v = (i-40)>>4; if (v<0) v = 0; else if (v>3) v = 3; Cb_Table[i] = v<<2; Cr_Table[i] = v; } } void dither(src) unsigned char *src[]; { /* should this test only the display flag, not progressive_sequence ? --CF */ /* CHANGE 95/05/13: progressive_sequence -> progressive_frame */ if( progressive_frame || Display_Progressive_Flag) Dither_Frame(src); else { if ((picture_structure==FRAME_PICTURE && top_field_first) || picture_structure==BOTTOM_FIELD) { /* top field first */ if (chroma_format==CHROMA420 && hiQdither) { Dither_Top_Field420(src,Dithered_Image); Dither_Bottom_Field420(src,Dithered_Image2); } else { Dither_Top_Field(src,Dithered_Image); Dither_Bottom_Field(src,Dithered_Image2); } } else { /* bottom field first */ if (chroma_format==CHROMA420 && hiQdither) { Dither_Bottom_Field420(src,Dithered_Image); Dither_Top_Field420(src,Dithered_Image2); } else { Dither_Bottom_Field(src,Dithered_Image); Dither_Top_Field(src,Dithered_Image2); } } } Display_Image(Ximage_Ptr,Dithered_Image); } static void Dither_Frame(src) unsigned char *src[]; { int i,j; int y,u,v; unsigned char *py,*pu,*pv,*dst; py = src[0]; pu = src[1]; pv = src[2]; dst = Dithered_Image; for (j=0; j<Coded_Picture_Height; j+=4) { /* line j + 0 */ for (i=0; i<Coded_Picture_Width; i+=4) { y = *py++; u = *pu++ >> 1; v = *pv++ >> 1; *dst++ = Pixel[Y_Table[y]|Cb_Table[u]|Cr_Table[v]]; y = *py++; if (chroma_format==CHROMA444) { u = *pu++ >> 1; v = *pv++ >> 1; } *dst++ = Pixel[Y_Table[y+8]|Cb_Table[u+8]|Cr_Table[v+8]]; y = *py++; u = *pu++ >> 1; v = *pv++ >> 1; *dst++ = Pixel[Y_Table[y+2]|Cb_Table[u+2]|Cr_Table[v+2]]; y = *py++; if (chroma_format==CHROMA444) { u = *pu++ >> 1; v = *pv++ >> 1; } *dst++ = Pixel[Y_Table[y+10]|Cb_Table[u+10]|Cr_Table[v+10]]; } if (chroma_format==CHROMA420) { pu -= Chroma_Width; pv -= Chroma_Width; } /* line j + 1 */ for (i=0; i<Coded_Picture_Width; i+=4) { y = *py++; u = *pu++ >> 1; v = *pv++ >> 1; *dst++ = Pixel[Y_Table[y+12]|Cb_Table[u+12]|Cr_Table[v+12]]; y = *py++; if (chroma_format==CHROMA444) { u = *pu++ >> 1; v = *pv++ >> 1; } *dst++ = Pixel[Y_Table[y+4]|Cb_Table[u+4]|Cr_Table[v+4]]; y = *py++; u = *pu++ >> 1; v = *pv++ >> 1; *dst++ = Pixel[Y_Table[y+14]|Cb_Table[u+14]|Cr_Table[v+14]]; y = *py++; if (chroma_format==CHROMA444) { u = *pu++ >> 1; v = *pv++ >> 1; } *dst++ = Pixel[Y_Table[y+6]|Cb_Table[u+6]|Cr_Table[v+6]]; } /* line j + 2 */ for (i=0; i<Coded_Picture_Width; i+=4) { y = *py++; u = *pu++ >> 1; v = *pv++ >> 1; *dst++ = Pixel[Y_Table[y+3]|Cb_Table[u+3]|Cr_Table[v+3]]; y = *py++; if (chroma_format==CHROMA444) { u = *pu++ >> 1; v = *pv++ >> 1; } *dst++ = Pixel[Y_Table[y+11]|Cb_Table[u+11]|Cr_Table[v+11]]; y = *py++; u = *pu++ >> 1; v = *pv++ >> 1; *dst++ = Pixel[Y_Table[y+1]|Cb_Table[u+1]|Cr_Table[v+1]]; y = *py++; if (chroma_format==CHROMA444) { u = *pu++ >> 1; v = *pv++ >> 1; } *dst++ = Pixel[Y_Table[y+9]|Cb_Table[u+9]|Cr_Table[v+9]]; } if (chroma_format==CHROMA420) { pu -= Chroma_Width; pv -= Chroma_Width; } /* line j + 3 */ for (i=0; i<Coded_Picture_Width; i+=4) { y = *py++; u = *pu++ >> 1; v = *pv++ >> 1; *dst++ = Pixel[Y_Table[y+15]|Cb_Table[u+15]|Cr_Table[v+15]]; y = *py++; if (chroma_format==CHROMA444) { u = *pu++ >> 1; v = *pv++ >> 1; } *dst++ = Pixel[Y_Table[y+7]|Cb_Table[u+7]|Cr_Table[v+7]]; y = *py++; u = *pu++ >> 1; v = *pv++ >> 1; *dst++ = Pixel[Y_Table[y+13]|Cb_Table[u+13]|Cr_Table[v+13]]; y = *py++; if (chroma_format==CHROMA444) { u = *pu++ >> 1; v = *pv++ >> 1; } *dst++ = Pixel[Y_Table[y+5]|Cb_Table[u+5]|Cr_Table[v+5]]; } } } static void Dither_Top_Field(src,dst) unsigned char *src[]; unsigned char *dst; { int i,j; int y,Y2,u,v; unsigned char *py,*Y2_ptr,*pu,*pv,*dst2; py = src[0]; Y2_ptr = src[0] + (Coded_Picture_Width<<1); pu = src[1]; pv = src[2]; dst2 = dst + Coded_Picture_Width; for (j=0; j<Coded_Picture_Height; j+=4) { /* line j + 0, j + 1 */ for (i=0; i<Coded_Picture_Width; i+=4) { y = *py++; Y2 = *Y2_ptr++; u = *pu++ >> 1; v = *pv++ >> 1; *dst++ = Pixel[Y_Table[y]|Cb_Table[u]|Cr_Table[v]]; *dst2++ = Pixel[Y_Table[((y+Y2)>>1)+12]|Cb_Table[u+12]|Cr_Table[v+12]]; y = *py++; Y2 = *Y2_ptr++; if (chroma_format==CHROMA444) { u = *pu++ >> 1; v = *pv++ >> 1; } *dst++ = Pixel[Y_Table[y+8]|Cb_Table[u+8]|Cr_Table[v+8]]; *dst2++ = Pixel[Y_Table[((y+Y2)>>1)+4]|Cb_Table[u+4]|Cr_Table[v+4]]; y = *py++; Y2 = *Y2_ptr++; u = *pu++ >> 1; v = *pv++ >> 1; *dst++ = Pixel[Y_Table[y+2]|Cb_Table[u+2]|Cr_Table[v+2]]; *dst2++ = Pixel[Y_Table[((y+Y2)>>1)+14]|Cb_Table[u+14]|Cr_Table[v+14]]; y = *py++; Y2 = *Y2_ptr++; if (chroma_format==CHROMA444) { u = *pu++ >> 1; v = *pv++ >> 1; } *dst++ = Pixel[Y_Table[y+10]|Cb_Table[u+10]|Cr_Table[v+10]]; *dst2++ = Pixel[Y_Table[((y+Y2)>>1)+6]|Cb_Table[u+6]|Cr_Table[v+6]]; } py += Coded_Picture_Width; if (j!=(Coded_Picture_Height-4)) Y2_ptr += Coded_Picture_Width; else Y2_ptr -= Coded_Picture_Width; dst += Coded_Picture_Width; dst2 += Coded_Picture_Width; if (chroma_format==CHROMA420) { pu -= Chroma_Width; pv -= Chroma_Width; } else { pu += Chroma_Width; pv += Chroma_Width; } /* line j + 2, j + 3 */ for (i=0; i<Coded_Picture_Width; i+=4) { y = *py++; Y2 = *Y2_ptr++; u = *pu++ >> 1; v = *pv++ >> 1; *dst++ = Pixel[Y_Table[y+3]|Cb_Table[u+3]|Cr_Table[v+3]]; *dst2++ = Pixel[Y_Table[((y+Y2)>>1)+15]|Cb_Table[u+15]|Cr_Table[v+15]]; y = *py++; Y2 = *Y2_ptr++; if (chroma_format==CHROMA444) { u = *pu++ >> 1; v = *pv++ >> 1; } *dst++ = Pixel[Y_Table[y+11]|Cb_Table[u+11]|Cr_Table[v+11]]; *dst2++ = Pixel[Y_Table[((y+Y2)>>1)+7]|Cb_Table[u+7]|Cr_Table[v+7]]; y = *py++; Y2 = *Y2_ptr++; u = *pu++ >> 1; v = *pv++ >> 1; *dst++ = Pixel[Y_Table[y+1]|Cb_Table[u+1]|Cr_Table[v+1]]; *dst2++ = Pixel[Y_Table[((y+Y2)>>1)+13]|Cb_Table[u+13]|Cr_Table[v+13]]; y = *py++; Y2 = *Y2_ptr++; if (chroma_format==CHROMA444) { u = *pu++ >> 1; v = *pv++ >> 1; } *dst++ = Pixel[Y_Table[y+9]|Cb_Table[u+9]|Cr_Table[v+9]]; *dst2++ = Pixel[Y_Table[((y+Y2)>>1)+5]|Cb_Table[u+5]|Cr_Table[v+5]]; } py += Coded_Picture_Width; Y2_ptr += Coded_Picture_Width; dst += Coded_Picture_Width; dst2 += Coded_Picture_Width; pu += Chroma_Width; pv += Chroma_Width; } } static void Dither_Bottom_Field(src,dst) unsigned char *src[]; unsigned char *dst; { int i,j; int y,Y2,u,v; unsigned char *py,*Y2_ptr,*pu,*pv,*dst2; py = src[0] + Coded_Picture_Width; Y2_ptr = py; pu = src[1] + Chroma_Width; pv = src[2] + Chroma_Width; dst2 = dst + Coded_Picture_Width; for (j=0; j<Coded_Picture_Height; j+=4) { /* line j + 0, j + 1 */ for (i=0; i<Coded_Picture_Width; i+=4) { y = *py++; Y2 = *Y2_ptr++; u = *pu++ >> 1; v = *pv++ >> 1; *dst++ = Pixel[Y_Table[((y+Y2)>>1)]|Cb_Table[u]|Cr_Table[v]]; *dst2++ = Pixel[Y_Table[Y2+12]|Cb_Table[u+12]|Cr_Table[v+12]]; y = *py++; Y2 = *Y2_ptr++; if (chroma_format==CHROMA444) { u = *pu++ >> 1; v = *pv++ >> 1; } *dst++ = Pixel[Y_Table[((y+Y2)>>1)+8]|Cb_Table[u+8]|Cr_Table[v+8]]; *dst2++ = Pixel[Y_Table[Y2+4]|Cb_Table[u+4]|Cr_Table[v+4]]; y = *py++; Y2 = *Y2_ptr++; u = *pu++ >> 1; v = *pv++ >> 1; *dst++ = Pixel[Y_Table[((y+Y2)>>1)+2]|Cb_Table[u+2]|Cr_Table[v+2]]; *dst2++ = Pixel[Y_Table[Y2+14]|Cb_Table[u+14]|Cr_Table[v+14]]; y = *py++; Y2 = *Y2_ptr++; if (chroma_format==CHROMA444) { u = *pu++ >> 1; v = *pv++ >> 1; } *dst++ = Pixel[Y_Table[((y+Y2)>>1)+10]|Cb_Table[u+10]|Cr_Table[v+10]]; *dst2++ = Pixel[Y_Table[Y2+6]|Cb_Table[u+6]|Cr_Table[v+6]]; } if (j==0) py -= Coded_Picture_Width; else py += Coded_Picture_Width; Y2_ptr += Coded_Picture_Width; dst += Coded_Picture_Width; dst2 += Coded_Picture_Width; if (chroma_format==CHROMA420) { pu -= Chroma_Width; pv -= Chroma_Width; } else { pu += Chroma_Width; pv += Chroma_Width; } /* line j + 2. j + 3 */ for (i=0; i<Coded_Picture_Width; i+=4) { y = *py++; Y2 = *Y2_ptr++; u = *pu++ >> 1; v = *pv++ >> 1; *dst++ = Pixel[Y_Table[((y+Y2)>>1)+3]|Cb_Table[u+3]|Cr_Table[v+3]]; *dst2++ = Pixel[Y_Table[Y2+15]|Cb_Table[u+15]|Cr_Table[v+15]]; y = *py++; Y2 = *Y2_ptr++; if (chroma_format==CHROMA444) { u = *pu++ >> 1; v = *pv++ >> 1; } *dst++ = Pixel[Y_Table[((y+Y2)>>1)+11]|Cb_Table[u+11]|Cr_Table[v+11]]; *dst2++ = Pixel[Y_Table[Y2+7]|Cb_Table[u+7]|Cr_Table[v+7]]; y = *py++; Y2 = *Y2_ptr++; u = *pu++ >> 1; v = *pv++ >> 1; *dst++ = Pixel[Y_Table[((y+Y2)>>1)+1]|Cb_Table[u+1]|Cr_Table[v+1]]; *dst2++ = Pixel[Y_Table[Y2+13]|Cb_Table[u+13]|Cr_Table[v+13]]; y = *py++; Y2 = *Y2_ptr++; if (chroma_format==CHROMA444) { u = *pu++ >> 1; v = *pv++ >> 1; } *dst++ = Pixel[Y_Table[((y+Y2)>>1)+9]|Cb_Table[u+9]|Cr_Table[v+9]]; *dst2++ = Pixel[Y_Table[Y2+5]|Cb_Table[u+5]|Cr_Table[v+5]]; } py += Coded_Picture_Width; Y2_ptr += Coded_Picture_Width; dst += Coded_Picture_Width; dst2 += Coded_Picture_Width; pu += Chroma_Width; pv += Chroma_Width; } } static void Dither_Top_Field420(src,dst) unsigned char *src[]; unsigned char *dst; { int i,j; int Y1,Cb1,Cr1,Y2,Cb2,Cr2; unsigned char *Y1_ptr,*Cb1_ptr,*Cr1_ptr,*Y2_ptr,*Cb2_ptr,*Cr2_ptr,*dst2; Y1_ptr = src[0]; Cb1_ptr = src[1]; Cr1_ptr = src[2]; Y2_ptr = Y1_ptr + (Coded_Picture_Width<<1); Cb2_ptr = Cb1_ptr + (Chroma_Width<<1); Cr2_ptr = Cr1_ptr + (Chroma_Width<<1); dst2 = dst + Coded_Picture_Width; for (j=0; j<Coded_Picture_Height; j+=4) { /* line j + 0, j + 1 */ for (i=0; i<Coded_Picture_Width; i+=4) { Y1 = *Y1_ptr++; Y2 = *Y2_ptr++; Cb1 = *Cb1_ptr++ >> 1; Cr1 = *Cr1_ptr++ >> 1; Cb2 = *Cb2_ptr++ >> 1; Cr2 = *Cr2_ptr++ >> 1; *dst++ = Pixel[Y_Table[((3*Y1+Y2)>>2)]|Cb_Table[Cb1]|Cr_Table[Cr1]]; *dst2++ = Pixel[Y_Table[((Y1+3*Y2)>>2)+12]|Cb_Table[((3*Cb1+Cb2)>>2)+12] |Cr_Table[((3*Cr1+Cr2)>>2)+12]]; Y1 = *Y1_ptr++; Y2 = *Y2_ptr++; *dst++ = Pixel[Y_Table[((3*Y1+Y2)>>2)+8]|Cb_Table[Cb1+8]|Cr_Table[Cr1+8]]; *dst2++ = Pixel[Y_Table[((Y1+3*Y2)>>2)+4]|Cb_Table[((3*Cb1+Cb2)>>2)+4] |Cr_Table[((3*Cr1+Cr2)>>2)+4]]; Y1 = *Y1_ptr++; Y2 = *Y2_ptr++; Cb1 = *Cb1_ptr++ >> 1; Cr1 = *Cr1_ptr++ >> 1; Cb2 = *Cb2_ptr++ >> 1; Cr2 = *Cr2_ptr++ >> 1; *dst++ = Pixel[Y_Table[((3*Y1+Y2)>>2)+2]|Cb_Table[Cb1+2]|Cr_Table[Cr1+2]]; *dst2++ = Pixel[Y_Table[((Y1+3*Y2)>>2)+14]|Cb_Table[((3*Cb1+Cb2)>>2)+14] |Cr_Table[((3*Cr1+Cr2)>>2)+14]]; Y1 = *Y1_ptr++; Y2 = *Y2_ptr++; *dst++ = Pixel[Y_Table[((3*Y1+Y2)>>2)+10]|Cb_Table[Cb1+10]|Cr_Table[Cr1+10]]; *dst2++ = Pixel[Y_Table[((Y1+3*Y2)>>2)+6]|Cb_Table[((3*Cb1+Cb2)>>2)+6] |Cr_Table[((3*Cr1+Cr2)>>2)+6]]; } Y1_ptr += Coded_Picture_Width; if (j!=(Coded_Picture_Height-4)) Y2_ptr += Coded_Picture_Width; else Y2_ptr -= Coded_Picture_Width; Cb1_ptr -= Chroma_Width; Cr1_ptr -= Chroma_Width; Cb2_ptr -= Chroma_Width; Cr2_ptr -= Chroma_Width; dst += Coded_Picture_Width; dst2 += Coded_Picture_Width; /* line j + 2, j + 3 */ for (i=0; i<Coded_Picture_Width; i+=4) { Y1 = *Y1_ptr++; Y2 = *Y2_ptr++; Cb1 = *Cb1_ptr++ >> 1; Cr1 = *Cr1_ptr++ >> 1; Cb2 = *Cb2_ptr++ >> 1; Cr2 = *Cr2_ptr++ >> 1; *dst++ = Pixel[Y_Table[((3*Y1+Y2)>>2)+3]|Cb_Table[((Cb1+Cb2)>>1)+3] |Cr_Table[((Cr1+Cr2)>>1)+3]]; *dst2++ = Pixel[Y_Table[((Y1+3*Y2)>>2)+15]|Cb_Table[((Cb1+3*Cb2)>>2)+15] |Cr_Table[((Cr1+3*Cr2)>>2)+15]]; Y1 = *Y1_ptr++; Y2 = *Y2_ptr++; *dst++ = Pixel[Y_Table[((3*Y1+Y2)>>2)+11]|Cb_Table[((Cb1+Cb2)>>1)+11] |Cr_Table[((Cr1+Cr2)>>1)+11]]; *dst2++ = Pixel[Y_Table[((Y1+3*Y2)>>2)+7]|Cb_Table[((Cb1+3*Cb2)>>2)+7] |Cr_Table[((Cr1+3*Cr2)>>2)+7]]; Y1 = *Y1_ptr++; Y2 = *Y2_ptr++; Cb1 = *Cb1_ptr++ >> 1; Cr1 = *Cr1_ptr++ >> 1; Cb2 = *Cb2_ptr++ >> 1; Cr2 = *Cr2_ptr++ >> 1; *dst++ = Pixel[Y_Table[((3*Y1+Y2)>>2)+1]|Cb_Table[((Cb1+Cb2)>>1)+1] |Cr_Table[((Cr1+Cr2)>>1)+1]]; *dst2++ = Pixel[Y_Table[((Y1+3*Y2)>>2)+13]|Cb_Table[((Cb1+3*Cb2)>>2)+13] |Cr_Table[((Cr1+3*Cr2)>>2)+13]]; Y1 = *Y1_ptr++; Y2 = *Y2_ptr++; *dst++ = Pixel[Y_Table[((3*Y1+Y2)>>2)+9]|Cb_Table[((Cb1+Cb2)>>1)+9] |Cr_Table[((Cr1+Cr2)>>1)+9]]; *dst2++ = Pixel[Y_Table[((Y1+3*Y2)>>2)+5]|Cb_Table[((Cb1+3*Cb2)>>2)+5] |Cr_Table[((Cr1+3*Cr2)>>2)+5]]; } Y1_ptr += Coded_Picture_Width; Y2_ptr += Coded_Picture_Width; Cb1_ptr += Chroma_Width; Cr1_ptr += Chroma_Width; if (j!=(Coded_Picture_Height-8)) { Cb2_ptr += Chroma_Width; Cr2_ptr += Chroma_Width; } else { Cb2_ptr -= Chroma_Width; Cr2_ptr -= Chroma_Width; } dst += Coded_Picture_Width; dst2+= Coded_Picture_Width; } } static void Dither_Bottom_Field420(src,dst) unsigned char *src[]; unsigned char *dst; { int i,j; int Y1,Cb1,Cr1,Y2,Cb2,Cr2; unsigned char *Y1_ptr,*Cb1_ptr,*Cr1_ptr,*Y2_ptr,*Cb2_ptr,*Cr2_ptr,*dst2; Y2_ptr = Y1_ptr = src[0] + Coded_Picture_Width; Cb2_ptr = Cb1_ptr = src[1] + Chroma_Width; Cr2_ptr = Cr1_ptr = src[2] + Chroma_Width; dst2 = dst; for (j=0; j<Coded_Picture_Height; j+=4) { /* line j + 0, j + 1 */ for (i=0; i<Coded_Picture_Width; i+=4) { Y1 = *Y1_ptr++; Y2 = *Y2_ptr++; Cb1 = *Cb1_ptr++ >> 1; Cr1 = *Cr1_ptr++ >> 1; Cb2 = *Cb2_ptr++ >> 1; Cr2 = *Cr2_ptr++ >> 1; *dst++ = Pixel[Y_Table[((3*Y1+Y2)>>2)+15]|Cb_Table[((3*Cb1+Cb2)>>2)+15] |Cr_Table[((3*Cr1+Cr2)>>2)+15]]; *dst2++ = Pixel[Y_Table[((Y1+3*Y2)>>2)]|Cb_Table[((Cb1+Cb2)>>1)] |Cr_Table[((Cr1+Cr2)>>1)]]; Y1 = *Y1_ptr++; Y2 = *Y2_ptr++; *dst++ = Pixel[Y_Table[((3*Y1+Y2)>>2)+7]|Cb_Table[((3*Cb1+Cb2)>>2)+7] |Cr_Table[((3*Cr1+Cr2)>>2)+7]]; *dst2++ = Pixel[Y_Table[((Y1+3*Y2)>>2)+8]|Cb_Table[((Cb1+Cb2)>>1)+8] |Cr_Table[((Cr1+Cr2)>>1)+8]]; Y1 = *Y1_ptr++; Y2 = *Y2_ptr++; Cb1 = *Cb1_ptr++ >> 1; Cr1 = *Cr1_ptr++ >> 1; Cb2 = *Cb2_ptr++ >> 1; Cr2 = *Cr2_ptr++ >> 1; *dst++ = Pixel[Y_Table[((3*Y1+Y2)>>2)+13]|Cb_Table[((3*Cb1+Cb2)>>2)+13] |Cr_Table[((3*Cr1+Cr2)>>2)+13]]; *dst2++ = Pixel[Y_Table[((Y1+3*Y2)>>2)+2]|Cb_Table[((Cb1+Cb2)>>1)+2] |Cr_Table[((Cr1+Cr2)>>1)+2]]; Y1 = *Y1_ptr++; Y2 = *Y2_ptr++; *dst++ = Pixel[Y_Table[((3*Y1+Y2)>>2)+5]|Cb_Table[((3*Cb1+Cb2)>>2)+5] |Cr_Table[((3*Cr1+Cr2)>>2)+5]]; *dst2++ = Pixel[Y_Table[((Y1+3*Y2)>>2)+10]|Cb_Table[((Cb1+Cb2)>>1)+10] |Cr_Table[((Cr1+Cr2)>>1)+10]]; } if (j!=0) Y1_ptr += Coded_Picture_Width; else Y1_ptr -= Coded_Picture_Width; Y2_ptr += Coded_Picture_Width; Cb1_ptr -= Chroma_Width; Cr1_ptr -= Chroma_Width; Cb2_ptr -= Chroma_Width; Cr2_ptr -= Chroma_Width; if (j!=0) dst += Coded_Picture_Width; dst2 += Coded_Picture_Width; /* line j + 2, j + 3 */ for (i=0; i<Coded_Picture_Width; i+=4) { Y1 = *Y1_ptr++; Y2 = *Y2_ptr++; Cb1 = *Cb1_ptr++ >> 1; Cr1 = *Cr1_ptr++ >> 1; Cb2 = *Cb2_ptr++ >> 1; Cr2 = *Cr2_ptr++ >> 1; *dst++ = Pixel[Y_Table[((3*Y1+Y2)>>2)+12]|Cb_Table[((Cb1+3*Cb2)>>2)+12] |Cr_Table[((Cr1+3*Cr2)>>2)+12]]; *dst2++ = Pixel[Y_Table[((Y1+3*Y2)>>2)+3]|Cb_Table[Cb2+3] |Cr_Table[Cr2+3]]; Y1 = *Y1_ptr++; Y2 = *Y2_ptr++; *dst++ = Pixel[Y_Table[((3*Y1+Y2)>>2)+4]|Cb_Table[((Cb1+3*Cb2)>>2)+4] |Cr_Table[((Cr1+3*Cr2)>>2)+4]]; *dst2++ = Pixel[Y_Table[((Y1+3*Y2)>>2)+11]|Cb_Table[Cb2+11] |Cr_Table[Cr2+11]]; Y1 = *Y1_ptr++; Y2 = *Y2_ptr++; Cb1 = *Cb1_ptr++ >> 1; Cr1 = *Cr1_ptr++ >> 1; Cb2 = *Cb2_ptr++ >> 1; Cr2 = *Cr2_ptr++ >> 1; *dst++ = Pixel[Y_Table[((3*Y1+Y2)>>2)+14]|Cb_Table[((Cb1+3*Cb2)>>2)+14] |Cr_Table[((Cr1+3*Cr2)>>2)+14]]; *dst2++ = Pixel[Y_Table[((Y1+3*Y2)>>2)+1]|Cb_Table[Cb2+1] |Cr_Table[Cr2+1]]; Y1 = *Y1_ptr++; Y2 = *Y2_ptr++; *dst++ = Pixel[Y_Table[((3*Y1+Y2)>>2)+6]|Cb_Table[((Cb1+3*Cb2)>>2)+6] |Cr_Table[((Cr1+3*Cr2)>>2)+6]]; *dst2++ = Pixel[Y_Table[((Y1+3*Y2)>>2)+9]|Cb_Table[Cb2+9] |Cr_Table[Cr2+9]]; } Y1_ptr += Coded_Picture_Width; Y2_ptr += Coded_Picture_Width; if (j!=0) { Cb1_ptr += Chroma_Width; Cr1_ptr += Chroma_Width; } else { Cb1_ptr -= Chroma_Width; Cr1_ptr -= Chroma_Width; } Cb2_ptr += Chroma_Width; Cr2_ptr += Chroma_Width; dst += Coded_Picture_Width; dst2+= Coded_Picture_Width; } Y2_ptr -= (Coded_Picture_Width<<1); Cb2_ptr -= (Chroma_Width<<1); Cr2_ptr -= (Chroma_Width<<1); /* dither last line */ for (i=0; i<Coded_Picture_Width; i+=4) { Y1 = *Y1_ptr++; Y2 = *Y2_ptr++; Cb1 = *Cb1_ptr++ >> 1; Cr1 = *Cr1_ptr++ >> 1; Cb2 = *Cb2_ptr++ >> 1; Cr2 = *Cr2_ptr++ >> 1; *dst++ = Pixel[Y_Table[((3*Y1+Y2)>>2)+15]|Cb_Table[((3*Cb1+Cb2)>>2)+15] |Cr_Table[((3*Cr1+Cr2)>>2)+15]]; Y1 = *Y1_ptr++; Y2 = *Y2_ptr++; *dst++ = Pixel[Y_Table[((3*Y1+Y2)>>2)+7]|Cb_Table[((3*Cb1+Cb2)>>2)+7] |Cr_Table[((3*Cr1+Cr2)>>2)+7]]; Y1 = *Y1_ptr++; Y2 = *Y2_ptr++; Cb1 = *Cb1_ptr++ >> 1; Cr1 = *Cr1_ptr++ >> 1; Cb2 = *Cb2_ptr++ >> 1; Cr2 = *Cr2_ptr++ >> 1; *dst++ = Pixel[Y_Table[((3*Y1+Y2)>>2)+13]|Cb_Table[((3*Cb1+Cb2)>>2)+13] |Cr_Table[((3*Cr1+Cr2)>>2)+13]]; Y1 = *Y1_ptr++; Y2 = *Y2_ptr++; *dst++ = Pixel[Y_Table[((3*Y1+Y2)>>2)+5]|Cb_Table[((3*Cb1+Cb2)>>2)+5] |Cr_Table[((3*Cr1+Cr2)>>2)+5]]; } } #endif
the_stack_data/43889188.c
/* * Copyright 2016 The Emscripten Authors. All rights reserved. * Emscripten is available under two separate licenses, the MIT license and the * University of Illinois/NCSA Open Source License. Both these licenses can be * found in the LICENSE file. */ #include <math.h> #include <stdio.h> int main(int argc, char **argv) { float (*fn)(float) = argc != 12 ? &sqrtf : &fabsf; float (*fn2)(float) = argc != 13 ? &fabsf : &sqrtf; float (*fn3)(float) = argc != 14 ? &erff : &fabsf; printf("fn2(-5) = %d, fn(10) = %.2f, erf(10) = %.2f\n", (int)fn2(-5), fn(10), fn3(10)); return 0; }
the_stack_data/154310.c
// // Created by kang on 19-2-14. // #include <stdio.h> #include <unistd.h> void func() { printf("------step 1------\n"); printf("------step 2------\n"); printf("------step 3------\n"); printf("------step 4------\n"); printf("------step 5------\n"); return; } int main() { printf("---write data to R15(5473)---\n"); __asm__ __volatile__("movq $5473, %R15"); // 手动写数据到R15寄存器 printf("---write data to R15 fin------\n"); printf("---read data from R14--------\n"); long v; __asm__ __volatile__("movq %%R14, %0" : "=r"(v)); printf("---read data %ld from R14----\n", v); printf("---exam memmory-----------\n"); long value = 1024; printf("address:%ld\n", &value); printf("---modify memory----------\n"); printf("now value is %ld\n", value); printf("---memory fin-------------\n"); printf("------backtrace and step--\n"); func(); printf("--backtrace and step fin--\n"); printf("------sheep fin-----------\n"); return 0; }
the_stack_data/87636890.c
#include <stdio.h> float soma(float x, float y) { return x + y; } int main(void) { float a; float b; printf("digite A: "); scanf("%f", &a); printf("digite B: "); scanf("%f", &b); printf("\nResultado: %f", soma(a, b)); }
the_stack_data/156392535.c
/***************************************************************************** * gettimeofday.c: gettimeofday() replacement ***************************************************************************** * Copyright © 2014 VLC authors and VideoLAN * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ #ifdef HAVE_CONFIG_H # include <config.h> #endif #ifdef _WIN32 #include <winsock2.h> /* FILETIME of Jan 1 1970 00:00:00. */ static const unsigned __int64 epoch = 116444736000000000; /* * timezone information is stored outside the kernel so tzp isn't used anymore. * * Note: this function is not for Win32 high precision timing purpose. See * elapsed_time(). */ int gettimeofday(struct timeval * tp, struct timezone * tzp) { (void)tzp; FILETIME file_time; SYSTEMTIME system_time; ULARGE_INTEGER ularge; GetSystemTime(&system_time); SystemTimeToFileTime(&system_time, &file_time); ularge.LowPart = file_time.dwLowDateTime; ularge.HighPart = file_time.dwHighDateTime; tp->tv_sec = (long) ((ularge.QuadPart - epoch) / 10000000L); tp->tv_usec = (long) (system_time.wMilliseconds * 1000); return 0; } #endif /* _WIN32 */
the_stack_data/133944.c
#include <stdio.h> #include <stdlib.h> static int compare(const void *a, const void *b) { return *(int *) a - *(int *) b; } static void two_sum(int *nums, int low, int high, int target, int **results, int *count) { while (low < high) { int sum = nums[low] + nums[high]; if (sum < target) { low++; } else if (sum > target) { high--; } else { results[*count] = malloc(3 * sizeof(int)); results[*count][0] = -target; results[*count][1] = nums[low]; results[*count][2] = nums[high]; (*count)++; while (++low < high && nums[low] == nums[low - 1]) {} while (--high > low && nums[high] == nums[high + 1]) {} } } } /** ** Return an array of arrays of size *returnSize. ** Note: The returned array must be malloced, assume caller calls free(). **/ int** threeSum(int* nums, int numsSize, int* returnSize) { if (numsSize < 3) { return NULL; } qsort(nums, numsSize, sizeof(*nums), compare); *returnSize = 0; int i, j, capacity = 50000; int **results = malloc(capacity * sizeof(int *)); for (i = 0; i < numsSize - 2; i++) { if (i == 0 || i > 0 && nums[i] != nums[i - 1]) { two_sum(nums, i + 1, numsSize - 1, -nums[i], results, returnSize); } } return results; } int main(void) { int i, count; //int nums[] = { -1, 0, 1, 2, -1, -4 }; //int nums[] = { 0, 0, 0 }; //int nums[] = { -1, 0, 1, 0 }; int nums[] = {-2,0,0,2,2}; int **triplets = threeSum(nums, sizeof(nums) / sizeof(*nums), &count); for (i = 0; i < count; i++) { printf("%d %d %d\n", triplets[i][0], triplets[i][1], triplets[i][2]); } return 0; }
the_stack_data/6388968.c
///* // * main.c // * // * Created on: Aug 21, 2016 // * Author: fabian // */ // // //#include <avr/io.h> //#include <stdint.h> //#include "avr/interrupt.h" //#include "stdbool.h" //#include "segment_display.h" // //#define ADC_AVERAGES 200 // //enum { // ADC_CURRENT = 0x00, // ADC0 // ADC_VOLTAGE_POS = 0x01, // ADC6 // ADC_VOLTAGE_NEG = 0x02, // ADC7 // ADC_INVERT_VOLTAGE = 0x04 //}; // //// ADC flags for channel selection //volatile uint8_t adc_flags = ADC_CURRENT; // //// adc_mux are the multiplexer bits based on the adc selection in adc_flags //uint8_t adc_mux[3] = { 0b0000 /*ADC0*/, 0b0110 /*ADC6*/, 0b0111 /*ADC7*/ }; // //// averaging memory //int16_t adc_current_mem[ADC_AVERAGES]; //int16_t adc_voltage_mem[ADC_AVERAGES]; //volatile uint8_t adc_mem_offset = 0; //volatile bool adc_refresh = false; // //void beginAdcOperation() //{ // ADMUX = (1 << REFS1) | (1 << REFS0) | adc_mux[adc_flags & 0b11]; // // Prescaler should be 80 for 200kHz sampling clock. set to 64 or 128 // ADCSRA = (1 << ADIE) | (1 << ADPS2) | (1 << ADPS1) | (0 << ADPS0); // // enable and start conversion // ADCSRA |= (1 << ADEN) | (1 << ADSC); //} // //void setAdcAdmux(uint8_t mux) //{ // ADMUX &= 0xF0; // ADMUX |= mux; //} // //ISR(ADC_vect) //{ // uint8_t flags = adc_flags; // uint8_t converter = flags & 0b11; // // if(converter == 0) // { // // store result // adc_current_mem[adc_mem_offset] = ADC; // // // select next channel // if(flags & ADC_INVERT_VOLTAGE) // converter = ADC_VOLTAGE_NEG; // else // converter = ADC_VOLTAGE_POS; // } // else // { // int16_t res = ADC; // // if(flags & ADC_INVERT_VOLTAGE) // res = -res; // // // store result // adc_voltage_mem[adc_mem_offset] = res; // // // switch inverting mode // if(res == 0) // flags ^= ADC_INVERT_VOLTAGE; // // // set display refresh // adc_refresh = true; // // // new offset // ++adc_mem_offset; // // if(adc_mem_offset >= ADC_AVERAGES) // adc_mem_offset = 0; // // // select next channel // converter = ADC_CURRENT; // } // // // update flags // adc_flags = (flags & 0xFC) | converter; // // // select next channel // setAdcAdmux(adc_mux[converter]); // // start conversion // ADCSRA |= (1 << ADSC); //} // //int main_movav(void) //{ // sei(); // // segmentDisplayInit(); // // beginAdcOperation(); // // while(1) // { // if(adc_refresh) // { // adc_refresh = false; // // int32_t sum = 0; // // for(int i = 0; i < ADC_AVERAGES; ++i) // sum += adc_voltage_mem[i]; // // float voltage = 15.0 * 2.56 / (1.36363636 * 1024.0 * ADC_AVERAGES) * (float)sum; // // displayValues(voltage, -10); // } // } //} //
the_stack_data/43887216.c
#include<stdio.h> #include<stdlib.h> #include<string.h> FILE *open_todo_file(char mode[]) { // getting todo.txt location char *home[] = { getenv("HOME"), NULL }; char todo_file_name[25] = "/.local/share/todo.txt"; strcat(*home, todo_file_name); FILE *fp = fopen(*home, mode); // error if (fp == NULL) { fprintf(stderr, "cannot open ~/.local/share/todo.txt\n"); fprintf(stderr, "maybe file is not created? try creating a task with --create, it should creates the file.\n"); exit(1); } return(fp); }
the_stack_data/75279.c
#include <stdio.h> int main(void) { printf("one\ntwo\nthree\nfour"); return 0; }
the_stack_data/165769190.c
/* * Copyright (c) 2006 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * * This file contains Original Code and/or Modifications of Original Code * as defined in and that are subject to the Apple Public Source License * Version 2.0 (the 'License'). You may not use this file except in * compliance with the License. Please obtain a copy of the License at * http://www.opensource.apple.com/apsl/ and read it before using this * file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. * Please see the License for the specific language governing rights and * limitations under the License. * * @APPLE_LICENSE_HEADER_END@ */ int base() { return 10; }
the_stack_data/15764099.c
#include <dlfcn.h> #include <stdio.h> int main(void) { int i; void *dh; void (*test_init)(void); int (*test_foo)(void); void (*test_exit)(void); dh = dlopen("./T3807test.so", RTLD_NOW | RTLD_GLOBAL); if (!dh) { printf("Failed to open shared library: %s\n", dlerror()); return 1; } test_init = dlsym(dh, "test_init"); if (!test_init) { printf("Failed to find test_init: %s", dlerror()); return 1; } test_foo = dlsym(dh, "foo"); if (!test_foo) { printf("Failed to find test_foo: %s", dlerror()); return 1; } test_exit = dlsym(dh, "test_exit"); if (!test_exit) { printf("Failed to find test_exit: %s", dlerror()); return 1; } test_init(); i = test_foo(); printf("i is %d\n", i); test_exit(); return 0; }
the_stack_data/67325626.c
/* * BSD LICENSE * * Copyright(c) 2018-2019 Intel Corporation. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * Neither the name of Intel Corporation nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #define _GNU_SOURCE #include <ctype.h> #include <errno.h> #include <limits.h> #include <stdio.h> #include <stdlib.h> #include <stdint.h> #include <stdarg.h> #include <string.h> #include <unistd.h> #include <signal.h> #include <sys/time.h> #include <pthread.h> #include <getopt.h> #ifdef __linux__ #include <sched.h> #include <cpuid.h> #endif #ifdef __FreeBSD__ #include <sys/param.h> #include <sys/cpuset.h> #endif /** * MACROS */ #define UNUSED_PARAM(x) (void)(x) #ifdef __linux__ #define PAGE_SIZE (4 * 1024) #endif #define MEMCHUNK_SIZE (PAGE_SIZE * 32 * 1024) /* 128MB chunk */ #define CL_SIZE (64) #define CHUNKS (128) #ifdef DEBUG #include <assert.h> #define ALWAYS_INLINE static inline #else #define assert(x) #define ALWAYS_INLINE static inline __attribute__((always_inline)) #endif #define MAX_OPTARG_LEN 64 #define MAX_MEM_BW 100 * 1000 /* 100GBps */ /** * DATA STRUCTURES */ /** * Define read and write types */ enum cl_type { CL_TYPE_INVALID, CL_TYPE_PREFETCH_T0, CL_TYPE_PREFETCH_T1, CL_TYPE_PREFETCH_T2, CL_TYPE_PREFETCH_NTA, CL_TYPE_PREFETCH_W, CL_TYPE_READ_NTQ, CL_TYPE_READ_WB, CL_TYPE_READ_WB_DQA, CL_TYPE_READ_MOD_WRITE, CL_TYPE_WRITE_DQA, CL_TYPE_WRITE_DQA_FLUSH, CL_TYPE_WRITE_WB, CL_TYPE_WRITE_WB_AVX512, CL_TYPE_WRITE_WB_CLWB, CL_TYPE_WRITE_WB_FLUSH, CL_TYPE_WRITE_NTI, CL_TYPE_WRITE_NTI_CLWB, CL_TYPE_WRITE_NT512, CL_TYPE_WRITE_NTDQ }; /** * COMMON DATA */ static int stop_loop = 0; static void *memchunk = NULL; static unsigned memchunk_offset = 0; /** * UTILS */ /** * @brief Function to bind thread to a cpu * * @param cpuid cpu to bind thread to */ static void set_thread_affinity(const unsigned cpuid) { #ifdef __linux__ cpu_set_t cpuset; #endif #ifdef __FreeBSD__ cpuset_t cpuset; #endif int res = -1; CPU_ZERO(&cpuset); CPU_SET((int)cpuid, &cpuset); #ifdef __linux__ res = sched_setaffinity(0, sizeof(cpuset), &cpuset); #endif #ifdef __FreeBSD__ res = cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TID, -1, sizeof(cpuset), &cpuset); #endif if (res != 0) perror("Error setting core affinity "); } /** * @brief Function to flush cache * * @param p line of cache to flush */ ALWAYS_INLINE void cl_flush(void *p) { asm volatile("clflush (%0)\n\t" : : "r"(p) : "memory"); } /** * @brief Serialize store operations, prevent reordering of writes */ ALWAYS_INLINE void sb(void) { asm volatile("sfence\n\t" : : : "memory"); } /** * @brief Cache line write back * * @param p line of cache */ ALWAYS_INLINE void cl_wb(void *p) { #ifdef bit_CLWB asm volatile("clwb (%0)\n\t" : : "r"(p) : "memory"); #else UNUSED_PARAM(p); printf("clwb instruction is not suported\n"); exit(EXIT_FAILURE); #endif } /** * @brief Flush memory * * @param p memory allocated * @param s size of memory to flush */ ALWAYS_INLINE void mem_flush(void *p, size_t s) { char *cp = (char *)p; size_t i = 0; s = s / CL_SIZE; /* mem size in cache lines */ for (i = 0; i < s; i++) cl_flush(&cp[i * CL_SIZE]); sb(); } /** * @brief Function to initialize and allocate memory to thread * * @param s size of memory to allocate to thread * * @retval p allocated memory */ static void *malloc_and_init_memory(size_t s) { void *p = NULL; int ret; ret = posix_memalign(&p, PAGE_SIZE, s - s % PAGE_SIZE); if (ret != 0 || p == NULL) { printf("ERROR: Failed to allocate %lu bytes\n", (unsigned long) s - s % PAGE_SIZE); stop_loop = 1; return NULL; } uint64_t *p64 = (uint64_t *)p; size_t s64 = s / sizeof(uint64_t); while (s64 > 0) { *p64 = (uint64_t) rand(); p64 += (CL_SIZE / sizeof(uint64_t)); s64 -= (CL_SIZE / sizeof(uint64_t)); } mem_flush(p, MEMCHUNK_SIZE); return p; } /** * MEMORY OPERATIONS */ /** * @brief Perform prefetcht0 * * @param p pointer to memory location */ ALWAYS_INLINE void cl_prefetch_t0(void *p) { asm volatile("prefetcht0 (%0)\n\t" : : "r"(p) : "memory"); } /** * @brief Perform prefetcht1 * * @param p pointer to memory location */ ALWAYS_INLINE void cl_prefetch_t1(void *p) { asm volatile("prefetcht1 (%0)\n\t" : : "r"(p) : "memory"); } /** * @brief Perform prefetcht2 * * @param p pointer to memory location */ ALWAYS_INLINE void cl_prefetch_t2(void *p) { asm volatile("prefetcht2 (%0)\n\t" : : "r"(p) : "memory"); } /** * @brief Perform prefetchnta * * @param p pointer to memory location */ ALWAYS_INLINE void cl_prefetch_nta(void *p) { asm volatile("prefetchnta (%0)\n\t" : : "r"(p) : "memory"); } /** * @brief Perform prefetchw * * @param p pointer to memory location */ ALWAYS_INLINE void cl_prefetch_w(void *p) { asm volatile("prefetchw (%0)\n\t" : : "r"(p) : "memory"); } /** * @brief Load XOR writes * * @param p pointer to memory * @param v value to xor with value in memory location and write back */ ALWAYS_INLINE void cl_read_mod_write(void *p, const uint64_t v) { asm volatile("xor %0, (%1)\n\t" "xor %0, 8(%1)\n\t" "xor %0, 16(%1)\n\t" "xor %0, 24(%1)\n\t" "xor %0, 32(%1)\n\t" "xor %0, 40(%1)\n\t" "xor %0, 48(%1)\n\t" "xor %0, 56(%1)\n\t" : : "r"(v), "r"(p) : "memory"); } /** * @brief WB store vector version * * @param p pointer to memory location to be written * @param v value to overwrite memory location */ ALWAYS_INLINE void cl_write_avx512(void *p, const uint64_t v) { #if defined(__x86_64__) && defined(bit_AVX512F) asm volatile("vmovq %0, %%xmm1\n\t" "vmovdqa64 %%zmm1, (%1)\n\t" : : "r"(v), "r"(p) : "%zmm1", "memory"); #else UNUSED_PARAM(p); UNUSED_PARAM(v); printf("Instruction is not suported\n"); exit(EXIT_FAILURE); #endif } /** * @brief WB vector version * * @param p pointer to memory location to be written * @param v value to overwrite memory location */ ALWAYS_INLINE void cl_write_dqa(void *p, const uint64_t v) { #ifdef __x86_64__ asm volatile("movq %0, %%xmm1\n\t" "movdqa %%xmm1, (%1)\n\t" "movdqa %%xmm1, 16(%1)\n\t" "movdqa %%xmm1, 32(%1)\n\t" "movdqa %%xmm1, 48(%1)\n\t" : : "r"(v), "r"(p) : "%xmm1", "memory"); #else UNUSED_PARAM(p); UNUSED_PARAM(v); printf("Instruction is not suported\n"); exit(EXIT_FAILURE); #endif } /** * @brief Perform SSE write operation to specified cache line with flush * * @param p pointer to memory location to be written * @param v value to overwrite memory location */ ALWAYS_INLINE void cl_write_dqa_flush(void *p, const uint64_t v) { cl_write_dqa(p, v); cl_flush(p); } /** * @brief Perform write operation to specified cache line * * @param p pointer to memory location to be written * @param v value to overwrite memory location */ ALWAYS_INLINE void cl_write(void *p, const uint64_t v) { #ifdef __x86_64__ asm volatile("movq %0, (%1)\n\t" "movq %0, 8(%1)\n\t" "movq %0, 16(%1)\n\t" "movq %0, 24(%1)\n\t" "movq %0, 32(%1)\n\t" "movq %0, 40(%1)\n\t" "movq %0, 48(%1)\n\t" "movq %0, 56(%1)\n\t" : : "r"(v), "r"(p) : "memory"); #else asm volatile("movl %0, (%1)\n\t" "movl %0, 4(%1)\n\t" "movl %0, 8(%1)\n\t" "movl %0, 12(%1)\n\t" "movl %0, 16(%1)\n\t" "movl %0, 20(%1)\n\t" "movl %0, 24(%1)\n\t" "movl %0, 28(%1)\n\t" "movl %0, 32(%1)\n\t" "movl %0, 36(%1)\n\t" "movl %0, 40(%1)\n\t" "movl %0, 44(%1)\n\t" "movl %0, 48(%1)\n\t" "movl %0, 52(%1)\n\t" "movl %0, 56(%1)\n\t" "movl %0, 64(%1)\n\t" : : "r"(v), "r"(p) : "memory"); #endif } /** * @brief Perform write operation to specified cache line with clwb * * @param p pointer to memory location to be written * @param v value to overwrite memory location */ ALWAYS_INLINE void cl_write_clwb(void *p, const uint64_t v) { cl_write(p, v); cl_wb(p); } /** * @brief Perform write operation to specified cache line with flush * * @param p pointer to memory location to be written * @param v value to overwrite memory location */ ALWAYS_INLINE void cl_write_flush(void *p, const uint64_t v) { cl_write(p, v); cl_flush(p); } /** * @brief Perform write operation to memory giving non-temporal hint * * @param p pointer to memory location to be written * @param v value to overwrite memory location */ ALWAYS_INLINE void cl_write_nti(void *p, const uint64_t v) { #ifdef __x86_64__ asm volatile("movnti %0, (%1)\n\t" "movnti %0, 8(%1)\n\t" "movnti %0, 16(%1)\n\t" "movnti %0, 24(%1)\n\t" "movnti %0, 32(%1)\n\t" "movnti %0, 40(%1)\n\t" "movnti %0, 48(%1)\n\t" "movnti %0, 56(%1)\n\t" : : "r"(v), "r"(p) : "memory"); #else uint32_t v2 = (uint32_t)v; asm volatile("movnti %0, (%1)\n\t" "movnti %0, 4(%1)\n\t" "movnti %0, 8(%1)\n\t" "movnti %0, 12(%1)\n\t" "movnti %0, 16(%1)\n\t" "movnti %0, 20(%1)\n\t" "movnti %0, 24(%1)\n\t" "movnti %0, 28(%1)\n\t" "movnti %0, 32(%1)\n\t" "movnti %0, 36(%1)\n\t" "movnti %0, 40(%1)\n\t" "movnti %0, 44(%1)\n\t" "movnti %0, 48(%1)\n\t" "movnti %0, 52(%1)\n\t" "movnti %0, 56(%1)\n\t" "movnti %0, 64(%1)\n\t" : : "r"(v2), "r"(p) : "memory"); #endif } /** * @brief non-temporal store vector version * * @param p pointer to memory location to be written * @param v value to overwrite memory location */ ALWAYS_INLINE void cl_write_nt512(void *p, const uint64_t v) { #if defined(__x86_64__) && defined(bit_AVX512F) asm volatile("vmovq %0, %%xmm1\n\t" "vmovntpd %%zmm1, (%1)\n\t" : : "r"(v), "r"(p) : "%zmm1", "memory"); #else UNUSED_PARAM(p); UNUSED_PARAM(v); printf("Instruction is not suported\n"); exit(EXIT_FAILURE); #endif } /** * @brief Perform write operation to memory giving non-temporal hint with cache * line write back * * @param p pointer to memory location to be written * @param v value to overwrite memory location */ ALWAYS_INLINE void cl_write_nti_clwb(void *p, const uint64_t v) { cl_write_nti(p, v); cl_wb(p); } /** * @brief Non temporal store vector version * * @param p pointer to memory location to be written * @param v value to overwrite memory location */ ALWAYS_INLINE void cl_write_ntdq(void *p, const uint64_t v) { #ifdef __x86_64__ asm volatile("movq %0, %%xmm1\n\t" "movntdq %%xmm1, (%1)\n\t" "movntdq %%xmm1, 16(%1)\n\t" "movntdq %%xmm1, 32(%1)\n\t" "movntdq %%xmm1, 48(%1)\n\t" : : "r"(v), "r"(p) : "%xmm1", "memory"); #else UNUSED_PARAM(p); UNUSED_PARAM(v); printf("Instruction is not suported\n"); exit(EXIT_FAILURE); #endif } /** * @brief Function to perform non-temporal read operation * from specified memory location, vector version * * @param p pointer to memory location to read from */ ALWAYS_INLINE void cl_read_ntq(void *p) { asm volatile("movntdqa (%0), %%xmm1\n\t" "movntdqa 16(%0), %%xmm1\n\t" "movntdqa 32(%0), %%xmm1\n\t" "movntdqa 48(%0), %%xmm1\n\t" : : "r"(p) : "%xmm1", "memory"); } /** * @brief Function to perform read operation from specified memory location * * @param p pointer to memory location to read from */ ALWAYS_INLINE void cl_read(void *p) { register uint64_t v = 0; #ifdef __x86_64__ asm volatile("movq (%1), %0\n\t" "movq 8(%1), %0\n\t" "movq 16(%1), %0\n\t" "movq 24(%1), %0\n\t" "movq 32(%1), %0\n\t" "movq 40(%1), %0\n\t" "movq 48(%1), %0\n\t" "movq 56(%1), %0\n\t" : : "r"(v), "r"(p) : "memory"); #else asm volatile("movl (%1), %0\n\t" "movl 4(%1), %0\n\t" "movl 8(%1), %0\n\t" "movl 12(%1), %0\n\t" "movl 16(%1), %0\n\t" "movl 20(%1), %0\n\t" "movl 24(%1), %0\n\t" "movl 28(%1), %0\n\t" "movl 32(%1), %0\n\t" "movl 36(%1), %0\n\t" "movl 40(%1), %0\n\t" "movl 44(%1), %0\n\t" "movl 48(%1), %0\n\t" "movl 52(%1), %0\n\t" "movl 56(%1), %0\n\t" "movl 64(%1), %0\n\t" : : "r"(v), "r"(p) : "memory"); #endif } /** * @brief Function to perform read operation from specified memory location, * vector version * * @param p pointer to memory location to read from */ ALWAYS_INLINE void cl_read_dqa(void *p) { asm volatile("movdqa (%0), %%xmm1\n\t" "movdqa 16(%0), %%xmm1\n\t" "movdqa 32(%0), %%xmm1\n\t" "movdqa 48(%0), %%xmm1\n\t" : : "r"(p) : "%xmm1", "memory"); } /** * @brief Function to find selected operation and execute it * * @param bw amount of bandwidth * @param type operation type to perform on core */ ALWAYS_INLINE void mem_execute(const unsigned bw, const enum cl_type type) { const uint64_t val = (uint64_t) rand(); char *cp = (char *)memchunk; unsigned i = 0; const size_t s = MEMCHUNK_SIZE / CL_SIZE; /* mem size in cache lines */ assert(memchunk != NULL); for (i = 0; i < bw; i++) { char *ptr = cp + (memchunk_offset * CL_SIZE); switch (type) { case CL_TYPE_PREFETCH_T0: cl_prefetch_t0(ptr); break; case CL_TYPE_PREFETCH_T1: cl_prefetch_t1(ptr); break; case CL_TYPE_PREFETCH_T2: cl_prefetch_t2(ptr); break; case CL_TYPE_PREFETCH_NTA: cl_prefetch_nta(ptr); break; case CL_TYPE_PREFETCH_W: cl_prefetch_w(ptr); break; case CL_TYPE_READ_NTQ: cl_read_ntq(ptr); break; case CL_TYPE_READ_WB: cl_read(ptr); break; case CL_TYPE_READ_WB_DQA: cl_read_dqa(ptr); break; case CL_TYPE_READ_MOD_WRITE: cl_read_mod_write(ptr, val); break; case CL_TYPE_WRITE_DQA: cl_write_dqa(ptr, val); break; case CL_TYPE_WRITE_DQA_FLUSH: cl_write_dqa_flush(ptr, val); break; case CL_TYPE_WRITE_WB: cl_write(ptr, val); break; case CL_TYPE_WRITE_WB_AVX512: cl_write_avx512(ptr, val); break; case CL_TYPE_WRITE_WB_CLWB: cl_write_clwb(ptr, val); break; case CL_TYPE_WRITE_WB_FLUSH: cl_write_flush(ptr, val); break; case CL_TYPE_WRITE_NTI: cl_write_nti(ptr, val); break; case CL_TYPE_WRITE_NT512: cl_write_nt512(ptr, val); break; case CL_TYPE_WRITE_NTI_CLWB: cl_write_nti_clwb(ptr, val); break; case CL_TYPE_WRITE_NTDQ: cl_write_ntdq(ptr, val); break; default: assert(0); break; } if (++memchunk_offset >= s) memchunk_offset = 0; } sb(); } /** * MAIN */ /** * @brief Function to print Membw command line usage * * @param argv list of arguments supplied by user */ static void usage(char **argv) { printf("Usage: %s -c <cpu> -b <BW [MB/s]> <operation type>\n" "Description:\n" " -c, --cpu cpu to generate B/W\n" " -b, --bandwidth memory B/W specified in MBps\n" "Operation types:\n" " --prefetch-t0 prefetcht0\n" " --prefetch-t1 prefetcht1\n" " --prefetch-t2 prefetcht2\n" " --prefetch-nta prefetchtnta\n" " --prefetch-w prefetchw\n" " --read x86 loads\n" " --read-sse SSE loads\n" " --nt-read-sse SSE NT loads\n" " --read-mod-write x86 load XOR write\n" " --write x86 stores\n" " --write-avx512 AVX512 stores\n" " --write-clwb x86 stores + clwb\n" " --write-flush x86 stores & clflush (naturally generates" " loads & stores)\n" " --write-sse SSE stores\n" " --write-sse-flush SSE stores & clflush (naturally generates " "loads & stores)\n" " --nt-write x86 NT stores\n" " --nt-write-avx512 AVX512 NT stores\n" " --nt-write-clwb x86 NT stores + clwb\n" " --nt-write-sse SSE NT stores\n", argv[0]); } /** * @brief Calculate microseconds to the nearest measurement interval * * @param tv_s start time of memory operation * @param tv_e end time of memory operation * * @retval long time taken to execute operation */ ALWAYS_INLINE long get_usec_diff(struct timeval *tv_s, struct timeval *tv_e) { long usec_start, usec_end = 0; usec_start = ((long)tv_s->tv_usec) + ((long)tv_s->tv_sec*1000000L); usec_end = ((long)tv_e->tv_usec) + ((long)tv_e->tv_sec*1000000L); return usec_end - usec_start; } /** * @brief Sleep before executing operation * * @param usec_diff time taken to execute operation * @param interval maximum time operation should take */ ALWAYS_INLINE void nano_sleep(const long interval, long usec_diff) { struct timespec req, rem; memset(&rem, 0, sizeof(rem)); memset(&req, 0, sizeof(req)); req.tv_sec = (interval - usec_diff) / 1000000L; req.tv_nsec = ((interval - usec_diff) % 1000000L) * 1000L; if (nanosleep(&req, &rem) == -1) { req = rem; memset(&rem, 0, sizeof(rem)); nanosleep(&req, &rem); } } /** * @brief Converts string str to UINT * * @param [in] str string * @param [in] base numerical base * @param [out] value UINT value * * @return number of parsed characters * @retval positive on success * @retval negative on error (-errno) */ static int str_to_uint(const char *str, const unsigned base, unsigned *value) { const char *str_start = str; char *str_end = NULL; unsigned tmp = 0; if (NULL == str || NULL == value) return -EINVAL; while (isblank(*str_start)) str_start++; if (base == 10 && !isdigit(*str_start)) return -EINVAL; if (base == 16 && !isxdigit(*str_start)) return -EINVAL; errno = 0; tmp = strtoul(str_start, &str_end, base); if (errno != 0 || !(*str_start != '\0' && *str_end == '\0')) return -EINVAL; *value = tmp; return 0; } int main(int argc, char **argv) { int cmd = EXIT_SUCCESS; enum cl_type type = CL_TYPE_INVALID; unsigned mem_bw = 0; unsigned cpu = UINT_MAX; int option_index; int ret; struct option options[] = { {"bandwidth", required_argument, 0, 'b'}, {"cpu", required_argument, 0, 'c'}, {"prefetch-t0", no_argument, 0, CL_TYPE_PREFETCH_T0}, {"prefetch-t1", no_argument, 0, CL_TYPE_PREFETCH_T1}, {"prefetch-t2", no_argument, 0, CL_TYPE_PREFETCH_T2}, {"prefetch-nta", no_argument, 0, CL_TYPE_PREFETCH_NTA}, {"prefetch-w", no_argument, 0, CL_TYPE_PREFETCH_W}, {"read", no_argument, 0, CL_TYPE_READ_WB}, {"read-sse", no_argument, 0, CL_TYPE_READ_WB_DQA}, {"nt-read-sse", no_argument, 0, CL_TYPE_READ_NTQ}, {"read-mod-write", no_argument, 0, CL_TYPE_READ_MOD_WRITE}, {"write", no_argument, 0, CL_TYPE_WRITE_WB}, {"write-avx512", no_argument, 0, CL_TYPE_WRITE_WB_AVX512}, {"write-clwb", no_argument, 0, CL_TYPE_WRITE_WB_CLWB}, {"write-flush", no_argument, 0, CL_TYPE_WRITE_WB_FLUSH}, {"write-sse", no_argument, 0, CL_TYPE_WRITE_DQA}, {"write-sse-flush", no_argument, 0, CL_TYPE_WRITE_DQA_FLUSH}, {"nt-write", no_argument, 0, CL_TYPE_WRITE_NTI}, {"nt-write-avx512", no_argument, 0, CL_TYPE_WRITE_NT512}, {"nt-write-clwb", no_argument, 0, CL_TYPE_WRITE_NTI_CLWB}, {"nt-write-sse", no_argument, 0, CL_TYPE_WRITE_NTDQ}, {0, 0, 0, 0} }; /* Process command line arguments */ while ((cmd = getopt_long_only(argc, argv, "b:c:", options, &option_index)) != -1) { switch (cmd) { case 'c': ret = str_to_uint(optarg, 10, &cpu); if (ret != 0) { printf("Invalid CPU specified!\n"); return EXIT_FAILURE; } break; case 'b': ret = str_to_uint(optarg, 10, &mem_bw); if (ret != 0 || mem_bw == 0 || mem_bw > MAX_MEM_BW) { printf("Invalid B/W specified!\n"); return EXIT_FAILURE; } break; case CL_TYPE_PREFETCH_T0: case CL_TYPE_PREFETCH_T1: case CL_TYPE_PREFETCH_T2: case CL_TYPE_PREFETCH_NTA: case CL_TYPE_PREFETCH_W: case CL_TYPE_READ_NTQ: case CL_TYPE_READ_WB: case CL_TYPE_READ_WB_DQA: case CL_TYPE_READ_MOD_WRITE: case CL_TYPE_WRITE_DQA: case CL_TYPE_WRITE_DQA_FLUSH: case CL_TYPE_WRITE_WB: case CL_TYPE_WRITE_WB_AVX512: case CL_TYPE_WRITE_WB_CLWB: case CL_TYPE_WRITE_WB_FLUSH: case CL_TYPE_WRITE_NTI: case CL_TYPE_WRITE_NT512: case CL_TYPE_WRITE_NTI_CLWB: case CL_TYPE_WRITE_NTDQ: type = (enum cl_type) cmd; break; default: usage(argv); return EXIT_FAILURE; break; } } /* Check if user has supplied all required arguments */ if (type == CL_TYPE_INVALID || cpu == UINT_MAX || !mem_bw || optind < argc) { usage(argv); return EXIT_FAILURE; } printf("- THREAD logical core id: %u, " " memory bandwidth [MB]: %u, starting...\n", cpu, mem_bw); /* Bind thread to cpu */ set_thread_affinity(cpu); /* Allocate memory */ memchunk = malloc_and_init_memory(MEMCHUNK_SIZE); if (memchunk == NULL) { printf("Failed to allocate memory!\n"); return EXIT_FAILURE; } /* Calculate memory bandwidth to use */ mem_bw *= (((1024 * 1024) / CL_SIZE)) / CHUNKS; /* Stress memory bandwidth */ while (stop_loop == 0) { struct timeval tv_s, tv_e; long usec_diff; const long interval = 1000000L / CHUNKS; /* interval in [us] */ /* Get time before executing operation in loop */ gettimeofday(&tv_s, NULL); /* Execute operation */ mem_execute(mem_bw, type); /* Get time after executing operation */ gettimeofday(&tv_e, NULL); usec_diff = get_usec_diff(&tv_s, &tv_e); if (usec_diff < interval) { /* Sleep before executing operation again */ nano_sleep(interval, usec_diff); } } /* Terminate thread */ free(memchunk); printf("\nexiting...\n"); return 0; }
the_stack_data/165768218.c
// SoftEther VPN Source Code - Developer Edition Master Branch // Cedar Communication Module // EM.c // EtherLogger Manager for Win32 #ifdef OS_WIN32 #define WINUI_C #include "EM.h" #include "EMInner.h" #include "CMInner.h" #include "Database.h" #include "EtherLog.h" #include "Remote.h" #include "SMInner.h" #include "WinUi.h" #include "Mayaqua/FileIO.h" #include "Mayaqua/Internat.h" #include "Mayaqua/Memory.h" #include "Mayaqua/Microsoft.h" #include "Mayaqua/Str.h" #include "Mayaqua/Table.h" #include "../PenCore/resource.h" #include <shellapi.h> #include <ShlObj.h> // License registration process void EmLicenseAddDlgOnOk(HWND hWnd, RPC *s) { } // Shift treatment of text input void EmLicenseAddDlgShiftTextItem(HWND hWnd, UINT id1, UINT id2, UINT *next_focus) { char *s; // Validate arguments if (hWnd == NULL || next_focus == NULL) { return; } s = GetTextA(hWnd, id1); if (StrLen(s) >= 6) { char *s2 = CopyStr(s); char tmp[MAX_SIZE]; s2[6] = 0; SetTextA(hWnd, id1, s2); Free(s2); if (id2 != 0) { GetTxtA(hWnd, id2, tmp, sizeof(tmp)); StrCat(tmp, sizeof(tmp), s + 6); ReplaceStrEx(tmp, sizeof(tmp), tmp, "-", "", false); SetTextA(hWnd, id2, tmp); *next_focus = id2; } else { *next_focus = IDOK; } } Free(s); } // Make a text from the input data void EmLicenseAddDlgGetText(HWND hWnd, char *str, UINT size) { char *k1, *k2, *k3, *k4, *k5, *k6; // Validate arguments if (hWnd == NULL || str == NULL) { return; } k1 = GetTextA(hWnd, B_KEY1); k2 = GetTextA(hWnd, B_KEY2); k3 = GetTextA(hWnd, B_KEY3); k4 = GetTextA(hWnd, B_KEY4); k5 = GetTextA(hWnd, B_KEY5); k6 = GetTextA(hWnd, B_KEY6); Format(str, size, "%s-%s-%s-%s-%s-%s", k1, k2, k3, k4, k5, k6); Free(k1); Free(k2); Free(k3); Free(k4); Free(k5); Free(k6); } // License addition dialog update void EmLicenseAddDlgUpdate(HWND hWnd, RPC *s) { } // License addition dialog initialization void EmLicenseAddDlgInit(HWND hWnd, RPC *s) { HFONT h; // Validate arguments if (hWnd == NULL || s == NULL) { return; } h = GetFont("Arial", 10, true, false, false, false); SetFont(hWnd, B_KEY1, h); SetFont(hWnd, B_KEY2, h); SetFont(hWnd, B_KEY3, h); SetFont(hWnd, B_KEY4, h); SetFont(hWnd, B_KEY5, h); SetFont(hWnd, B_KEY6, h); DlgFont(hWnd, S_INFO, 10, true); EmLicenseAddDlgUpdate(hWnd, s); } // License addition dialog UINT EmLicenseAddDlg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param) { RPC *s = (RPC *)param; // Validate arguments if (hWnd == NULL) { return 0; } switch (msg) { case WM_INITDIALOG: EmLicenseAddDlgInit(hWnd, s); break; case WM_COMMAND: switch (LOWORD(wParam)) { case B_KEY1: case B_KEY2: case B_KEY3: case B_KEY4: case B_KEY5: case B_KEY6: switch (HIWORD(wParam)) { case EN_CHANGE: EmLicenseAddDlgUpdate(hWnd, s); switch (LOWORD(wParam)) { case B_KEY2: if (GetTextLen(hWnd, B_KEY2, true) == 0) { FocusEx(hWnd, B_KEY1); } break; case B_KEY3: if (GetTextLen(hWnd, B_KEY3, true) == 0) { FocusEx(hWnd, B_KEY2); } break; case B_KEY4: if (GetTextLen(hWnd, B_KEY4, true) == 0) { FocusEx(hWnd, B_KEY3); } break; case B_KEY5: if (GetTextLen(hWnd, B_KEY5, true) == 0) { FocusEx(hWnd, B_KEY4); } break; case B_KEY6: if (GetTextLen(hWnd, B_KEY6, true) == 0) { FocusEx(hWnd, B_KEY5); } break; } break; } break; } switch (wParam) { case IDOK: EmLicenseAddDlgOnOk(hWnd, s); break; case IDCANCEL: Close(hWnd); break; } break; case WM_CLOSE: EndDialog(hWnd, 0); break; } return 0; } // Add a license bool EmLicenseAdd(HWND hWnd, RPC *s) { // Validate arguments if (s == NULL) { return false; } return Dialog(hWnd, D_EM_LICENSE_ADD, EmLicenseAddDlg, s); } // License dialog initialization void EmLicenseDlgInit(HWND hWnd, RPC *s) { // Validate arguments if (hWnd == NULL || s == NULL) { return; } SetIcon(hWnd, 0, ICO_CERT); DlgFont(hWnd, S_BOLD, 0, true); DlgFont(hWnd, S_BOLD2, 0, true); LvInit(hWnd, L_LIST); LvSetStyle(hWnd, L_LIST, LVS_EX_GRIDLINES); LvInsertColumn(hWnd, L_LIST, 0, _UU("SM_LICENSE_COLUMN_1"), 50); LvInsertColumn(hWnd, L_LIST, 1, _UU("SM_LICENSE_COLUMN_2"), 100); LvInsertColumn(hWnd, L_LIST, 2, _UU("SM_LICENSE_COLUMN_3"), 290); LvInsertColumn(hWnd, L_LIST, 3, _UU("SM_LICENSE_COLUMN_4"), 150); LvInsertColumn(hWnd, L_LIST, 4, _UU("SM_LICENSE_COLUMN_5"), 120); LvInsertColumn(hWnd, L_LIST, 5, _UU("SM_LICENSE_COLUMN_6"), 250); LvInsertColumn(hWnd, L_LIST, 6, _UU("SM_LICENSE_COLUMN_7"), 100); LvInsertColumn(hWnd, L_LIST, 7, _UU("SM_LICENSE_COLUMN_8"), 100); LvInsertColumn(hWnd, L_LIST, 8, _UU("SM_LICENSE_COLUMN_9"), 100); LvInitEx(hWnd, L_STATUS, true); LvInsertColumn(hWnd, L_STATUS, 0, _UU("SM_STATUS_COLUMN_1"), 100); LvInsertColumn(hWnd, L_STATUS, 1, _UU("SM_STATUS_COLUMN_2"), 100); EmLicenseDlgRefresh(hWnd, s); } // License dialog update void EmLicenseDlgRefresh(HWND hWnd, RPC *s) { RPC_ENUM_LICENSE_KEY t; RPC_EL_LICENSE_STATUS st; UINT i; wchar_t tmp[MAX_SIZE]; LVB *b; // Validate arguments if (hWnd == NULL || s == NULL) { return; } Zero(&t, sizeof(t)); if (CALL(hWnd, EcEnumLicenseKey(s, &t)) == false) { Close(hWnd); return; } b = LvInsertStart(); for (i = 0;i < t.NumItem;i++) { wchar_t tmp1[32], tmp2[LICENSE_KEYSTR_LEN + 1], tmp3[LICENSE_MAX_PRODUCT_NAME_LEN + 1], *tmp4, tmp5[128], tmp6[LICENSE_LICENSEID_STR_LEN + 1], tmp7[64], tmp8[64], tmp9[64]; RPC_ENUM_LICENSE_KEY_ITEM *e = &t.Items[i]; UniToStru(tmp1, e->Id); StrToUni(tmp2, sizeof(tmp2), e->LicenseKey); StrToUni(tmp3, sizeof(tmp3), e->LicenseName); tmp4 = LiGetLicenseStatusStr(e->Status); if (e->Expires == 0) { UniStrCpy(tmp5, sizeof(tmp5), _UU("SM_LICENSE_NO_EXPIRES")); } else { GetDateStrEx64(tmp5, sizeof(tmp5), e->Expires, NULL); } StrToUni(tmp6, sizeof(tmp6), e->LicenseId); UniToStru(tmp7, e->ProductId); UniFormat(tmp8, sizeof(tmp8), L"%I64u", e->SystemId); UniToStru(tmp9, e->SerialId); LvInsertAdd(b, e->Status == LICENSE_STATUS_OK ? ICO_PASS : ICO_DISCARD, (void *)e->Id, 9, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7, tmp8, tmp9); } LvInsertEnd(b, hWnd, L_LIST); FreeRpcEnumLicenseKey(&t); Zero(&st, sizeof(st)); if (CALL(hWnd, EcGetLicenseStatus(s, &st)) == false) { Close(hWnd); return; } b = LvInsertStart(); if (st.Valid == false) { LvInsertAdd(b, 0, NULL, 2, _UU("EM_NO_LICENSE_COLUMN"), _UU("EM_NO_LICENSE")); } else { // Current system ID UniFormat(tmp, sizeof(tmp), L"%I64u", st.SystemId); LvInsertAdd(b, 0, NULL, 2, _UU("SM_LICENSE_STATUS_SYSTEM_ID"), tmp); // Expiration date of the current license product if (st.SystemExpires == 0) { UniStrCpy(tmp, sizeof(tmp), _UU("SM_LICENSE_NO_EXPIRES")); } else { GetDateStrEx64(tmp, sizeof(tmp), st.SystemExpires, NULL); } LvInsertAdd(b, 0, NULL, 2, _UU("SM_LICENSE_STATUS_EXPIRES"), tmp); } LvInsertEnd(b, hWnd, L_STATUS); if (LvNum(hWnd, L_STATUS) >= 1) { LvAutoSize(hWnd, L_STATUS); } EmLicenseDlgUpdate(hWnd, s); } // License dialog control update void EmLicenseDlgUpdate(HWND hWnd, RPC *s) { bool b = false; // Validate arguments if (hWnd == NULL || s == NULL) { return; } b = LvIsSingleSelected(hWnd, L_LIST); SetEnable(hWnd, B_DEL, b); SetEnable(hWnd, IDOK, b); } // License dialog UINT EmLicenseDlg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param) { RPC *s = (RPC *)param; NMHDR *n; // Validate arguments if (hWnd == NULL) { return 0; } switch (msg) { case WM_INITDIALOG: EmLicenseDlgInit(hWnd, s); break; case WM_NOTIFY: n = (NMHDR *)lParam; switch (n->code) { case LVN_ITEMCHANGED: switch (n->idFrom) { case L_LIST: case L_STATUS: EmLicenseDlgUpdate(hWnd, s); break; } break; } break; case WM_COMMAND: switch (wParam) { case IDOK: if (IsEnable(hWnd, IDOK)) { UINT i = LvGetSelected(hWnd, L_LIST); if (i != INFINITE) { char *s = LvGetStrA(hWnd, L_LIST, i, 5); char tmp[MAX_SIZE]; Format(tmp, sizeof(tmp), _SS("LICENSE_SUPPORT_URL"), s); ShellExecute(hWnd, "open", tmp, NULL, NULL, SW_SHOW); Free(s); } } break; case B_OBTAIN: ShellExecute(hWnd, "open", _SS("LICENSE_INFO_URL"), NULL, NULL, SW_SHOW); break; case B_ADD: if (EmLicenseAdd(hWnd, s)) { EmLicenseDlgRefresh(hWnd, s); } break; case B_DEL: if (IsEnable(hWnd, B_DEL)) { UINT id = (UINT)LvGetParam(hWnd, L_LIST, LvGetSelected(hWnd, L_LIST)); if (id != 0) { if (MsgBox(hWnd, MB_ICONQUESTION | MB_YESNO | MB_DEFBUTTON2, _UU("SM_LICENSE_DELETE_MSG")) == IDYES) { RPC_TEST t; Zero(&t, sizeof(t)); t.IntValue = id; if (CALL(hWnd, EcDelLicenseKey(s, &t))) { EmLicenseDlgRefresh(hWnd, s); } } } } break; case IDCANCEL: Close(hWnd); break; } break; case WM_CLOSE: EndDialog(hWnd, 0); break; } LvStandardHandler(hWnd, msg, wParam, lParam, L_LIST); return 0; } // Change Password dialog UINT EmPasswordDlg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param) { RPC *r = (RPC *)param; char pass1[MAX_PATH]; char pass2[MAX_PATH]; UCHAR hash[SHA1_SIZE]; RPC_SET_PASSWORD t; // Validate arguments if (hWnd == NULL) { return 0; } switch (msg) { case WM_INITDIALOG: Focus(hWnd, E_PASSWORD1); break; case WM_COMMAND: switch (wParam) { case IDOK: GetTxtA(hWnd, E_PASSWORD1, pass1, sizeof(pass1)); Sha0(hash, pass1, StrLen(pass1)); Zero(&t, sizeof(t)); Copy(t.HashedPassword, hash, SHA1_SIZE); if (CALL(hWnd, EcSetPassword(r, &t)) == false) { break; } MsgBox(hWnd, MB_ICONINFORMATION, _UU("CM_PASSWORD_SET")); EndDialog(hWnd, 1); break; case IDCANCEL: Close(hWnd); break; } switch (LOWORD(wParam)) { case E_PASSWORD1: case E_PASSWORD2: GetTxtA(hWnd, E_PASSWORD1, pass1, sizeof(pass1)); GetTxtA(hWnd, E_PASSWORD2, pass2, sizeof(pass2)); SetEnable(hWnd, IDOK, StrCmp(pass1, pass2) == 0 ? true : false); break; } break; case WM_CLOSE: EndDialog(hWnd, 0); break; } return 0; } // Copy the state of the dialog to the HUB_LOG void EmDlgToHubLog(HWND hWnd, HUB_LOG *g) { // Validate arguments if (hWnd == NULL || g == NULL) { return; } Zero(g, sizeof(HUB_LOG)); g->PacketLogSwitchType = CbGetSelect(hWnd, C_PACKET_SWITCH); g->PacketLogConfig[0] = IsChecked(hWnd, B_PACKET_0_0) ? 0 : IsChecked(hWnd, B_PACKET_0_1) ? 1 : 2; g->PacketLogConfig[1] = IsChecked(hWnd, B_PACKET_1_0) ? 0 : IsChecked(hWnd, B_PACKET_1_1) ? 1 : 2; g->PacketLogConfig[2] = IsChecked(hWnd, B_PACKET_2_0) ? 0 : IsChecked(hWnd, B_PACKET_2_1) ? 1 : 2; g->PacketLogConfig[3] = IsChecked(hWnd, B_PACKET_3_0) ? 0 : IsChecked(hWnd, B_PACKET_3_1) ? 1 : 2; g->PacketLogConfig[4] = IsChecked(hWnd, B_PACKET_4_0) ? 0 : IsChecked(hWnd, B_PACKET_4_1) ? 1 : 2; g->PacketLogConfig[5] = IsChecked(hWnd, B_PACKET_5_0) ? 0 : IsChecked(hWnd, B_PACKET_5_1) ? 1 : 2; g->PacketLogConfig[6] = IsChecked(hWnd, B_PACKET_6_0) ? 0 : IsChecked(hWnd, B_PACKET_6_1) ? 1 : 2; g->PacketLogConfig[7] = IsChecked(hWnd, B_PACKET_7_0) ? 0 : IsChecked(hWnd, B_PACKET_7_1) ? 1 : 2; } // Copy the HUB_LOG to the state of the dialog void EmHubLogToDlg(HWND hWnd, HUB_LOG *g) { // Validate arguments if (hWnd == NULL || g == NULL) { return; } CbSelect(hWnd, C_PACKET_SWITCH, g->PacketLogSwitchType); Check(hWnd, B_PACKET_0_0, g->PacketLogConfig[0] == 0); Check(hWnd, B_PACKET_0_1, g->PacketLogConfig[0] == 1); Check(hWnd, B_PACKET_0_2, g->PacketLogConfig[0] == 2); Check(hWnd, B_PACKET_1_0, g->PacketLogConfig[1] == 0); Check(hWnd, B_PACKET_1_1, g->PacketLogConfig[1] == 1); Check(hWnd, B_PACKET_1_2, g->PacketLogConfig[1] == 2); Check(hWnd, B_PACKET_2_0, g->PacketLogConfig[2] == 0); Check(hWnd, B_PACKET_2_1, g->PacketLogConfig[2] == 1); Check(hWnd, B_PACKET_2_2, g->PacketLogConfig[2] == 2); Check(hWnd, B_PACKET_3_0, g->PacketLogConfig[3] == 0); Check(hWnd, B_PACKET_3_1, g->PacketLogConfig[3] == 1); Check(hWnd, B_PACKET_3_2, g->PacketLogConfig[3] == 2); Check(hWnd, B_PACKET_4_0, g->PacketLogConfig[4] == 0); Check(hWnd, B_PACKET_4_1, g->PacketLogConfig[4] == 1); Check(hWnd, B_PACKET_4_2, g->PacketLogConfig[4] == 2); Check(hWnd, B_PACKET_5_0, g->PacketLogConfig[5] == 0); Check(hWnd, B_PACKET_5_1, g->PacketLogConfig[5] == 1); Check(hWnd, B_PACKET_5_2, g->PacketLogConfig[5] == 2); Check(hWnd, B_PACKET_6_0, g->PacketLogConfig[6] == 0); Check(hWnd, B_PACKET_6_1, g->PacketLogConfig[6] == 1); Check(hWnd, B_PACKET_6_2, g->PacketLogConfig[6] == 2); Check(hWnd, B_PACKET_7_0, g->PacketLogConfig[7] == 0); Check(hWnd, B_PACKET_7_1, g->PacketLogConfig[7] == 1); Check(hWnd, B_PACKET_7_2, g->PacketLogConfig[7] == 2); } // Initialize void EmAddInit(HWND hWnd, EM_ADD *p) { // Validate arguments if (hWnd == NULL || p == NULL) { return; } // Initialize controls CbAddStr(hWnd, C_PACKET_SWITCH, _UU("SM_LOG_SWITCH_0"), 0); CbAddStr(hWnd, C_PACKET_SWITCH, _UU("SM_LOG_SWITCH_1"), 1); CbAddStr(hWnd, C_PACKET_SWITCH, _UU("SM_LOG_SWITCH_2"), 2); CbAddStr(hWnd, C_PACKET_SWITCH, _UU("SM_LOG_SWITCH_3"), 3); CbAddStr(hWnd, C_PACKET_SWITCH, _UU("SM_LOG_SWITCH_4"), 4); CbAddStr(hWnd, C_PACKET_SWITCH, _UU("SM_LOG_SWITCH_5"), 5); if (p->NewMode) { // Newly creation mode RPC_ENUM_DEVICE t; HUB_LOG g; Zero(&g, sizeof(g)); g.PacketLogSwitchType = LOG_SWITCH_DAY; g.PacketLogConfig[PACKET_LOG_TCP_CONN] = g.PacketLogConfig[PACKET_LOG_DHCP] = 1; EmHubLogToDlg(hWnd, &g); Zero(&t, sizeof(t)); if (CALL(hWnd, EcEnumAllDevice(p->Rpc, &t))) { UINT i; CbSetHeight(hWnd, C_DEVICE, 18); for (i = 0;i < t.NumItem;i++) { RPC_ENUM_DEVICE_ITEM *dev = &t.Items[i]; wchar_t tmp[MAX_SIZE]; StrToUni(tmp, sizeof(tmp), dev->DeviceName); CbAddStr(hWnd, C_DEVICE, tmp, 0); } FreeRpcEnumDevice(&t); } SetText(hWnd, 0, _UU("EM_ADD_NEW")); } else { // Edit mode (to obtain a configuration) wchar_t tmp[MAX_PATH]; RPC_ADD_DEVICE t; Hide(hWnd, R_PROMISCUOUS); Zero(&t, sizeof(t)); StrCpy(t.DeviceName, sizeof(t.DeviceName), p->DeviceName); if (CALL(hWnd, EcGetDevice(p->Rpc, &t))) { EmHubLogToDlg(hWnd, &t.LogSetting); } else { Close(hWnd); } StrToUni(tmp, sizeof(tmp), p->DeviceName); CbAddStr(hWnd, C_DEVICE, tmp, 0); Disable(hWnd, C_DEVICE); SetText(hWnd, 0, _UU("EM_ADD_EDIT")); } EmAddUpdate(hWnd, p); } // [OK] button void EmAddOk(HWND hWnd, EM_ADD *p) { RPC_ADD_DEVICE t; wchar_t *tmp; char *name; // Validate arguments if (hWnd == NULL || p == NULL) { return; } Zero(&t, sizeof(t)); EmDlgToHubLog(hWnd, &t.LogSetting); tmp = CbGetStr(hWnd, C_DEVICE); name = CopyUniToStr(tmp); StrCpy(t.DeviceName, sizeof(t.DeviceName), name); if (p->NewMode) { t.NoPromiscuous = IsChecked(hWnd, R_PROMISCUOUS); } if (p->NewMode) { if (CALL(hWnd, EcAddDevice(p->Rpc, &t))) { Close(hWnd); } } else { if (CALL(hWnd, EcSetDevice(p->Rpc, &t))) { Close(hWnd); } } Free(name); Free(tmp); } // Control update void EmAddUpdate(HWND hWnd, EM_ADD *p) { wchar_t *tmp; char *name; // Validate arguments if (hWnd == NULL || p == NULL) { return; } tmp = CbGetStr(hWnd, C_DEVICE); name = CopyUniToStr(tmp); Trim(name); if (StrLen(name) == 0) { Disable(hWnd, IDOK); } else { Enable(hWnd, IDCANCEL); } Free(name); Free(tmp); } // Device Add / Edit dialog UINT EmAddDlg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param) { EM_ADD *p = (EM_ADD *)param; // Validate arguments if (hWnd == NULL) { return 0; } switch (msg) { case WM_INITDIALOG: EmAddInit(hWnd, p); break; case WM_COMMAND: EmAddUpdate(hWnd, p); switch (wParam) { case IDOK: EmAddOk(hWnd, p); break; case IDCANCEL: Close(hWnd); break; } break; case WM_CLOSE: EndDialog(hWnd, 0); break; } return 0; } // Add or edit void EmAdd(HWND hWnd, RPC *r, char *device_name) { EM_ADD p; // Validate arguments if (hWnd == NULL || r == NULL) { return; } Zero(&p, sizeof(p)); p.Rpc = r; if (device_name != NULL) { StrCpy(p.DeviceName, sizeof(p.DeviceName), device_name); } else { p.NewMode = true; } Dialog(hWnd, D_EM_ADD, EmAddDlg, &p); } // Initialize void EmMainInit(HWND hWnd, RPC *r) { // Validate arguments if (hWnd == NULL || r == NULL) { return; } LvInit(hWnd, L_LIST); LvInsertColumn(hWnd, L_LIST, 0, _UU("EM_MAIN_COLUMN_1"), 300); LvInsertColumn(hWnd, L_LIST, 1, _UU("EM_MAIN_COLUMN_2"), 150); SetIcon(hWnd, 0, ICO_NIC_ONLINE); EmMainRefresh(hWnd, r); SetTimer(hWnd, 1, 1000, NULL); } // Control update void EmMainUpdate(HWND hWnd, RPC *r) { // Validate arguments if (hWnd == NULL || r == NULL) { return; } SetEnable(hWnd, IDOK, LvIsMasked(hWnd, L_LIST) && LvIsMultiMasked(hWnd, L_LIST) == false); SetEnable(hWnd, B_DELETE, LvIsMasked(hWnd, L_LIST) && LvIsMultiMasked(hWnd, L_LIST) == false); } // Update void EmMainRefresh(HWND hWnd, RPC *r) { RPC_ENUM_DEVICE t; // Validate arguments if (hWnd == NULL || r == NULL) { return; } Zero(&t, sizeof(t)); if (CALL(hWnd, EcEnumDevice(r, &t))) { UINT i; LVB *b; b = LvInsertStart(); for (i = 0;i < t.NumItem;i++) { wchar_t tmp[MAX_PATH]; RPC_ENUM_DEVICE_ITEM *dev = &t.Items[i]; StrToUni(tmp, sizeof(tmp), dev->DeviceName); LvInsertAdd(b, dev->Active ? ICO_NIC_ONLINE : ICO_NIC_OFFLINE, NULL, 2, tmp, dev->Active ? _UU("EM_MAIN_OK") : _UU("EM_MAIN_ERROR")); } LvInsertEnd(b, hWnd, L_LIST); FreeRpcEnumDevice(&t); SetShow(hWnd, B_LICENSE, t.IsLicenseSupported); } else { Close(hWnd); } EmMainUpdate(hWnd, r); } // Main dialog procedure UINT EmMainDlg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param) { NMHDR *n; RPC *r = (RPC *)param; UINT i; char *name; // Validate arguments if (hWnd == NULL) { return 0; } switch (msg) { case WM_INITDIALOG: EmMainInit(hWnd, r); break; case WM_COMMAND: switch (wParam) { case IDOK: // Edit i = LvGetSelected(hWnd, L_LIST); if (i != INFINITE) { wchar_t *tmp; tmp = LvGetStr(hWnd, L_LIST, i, 0); if (tmp != NULL) { name = CopyUniToStr(tmp); EmAdd(hWnd, r, name); Free(tmp); Free(name); } } break; case B_PASSWORD: // Admin password Dialog(hWnd, D_EM_PASSWORD, EmPasswordDlg, r); break; case B_LICENSE: // Admin password Dialog(hWnd, D_EM_LICENSE, EmLicenseDlg, r); break; case B_ADD: // Add EmAdd(hWnd, r, NULL); EmMainRefresh(hWnd, r); break; case B_DELETE: // Delete i = LvGetSelected(hWnd, L_LIST); if (i != INFINITE) { wchar_t *tmp; tmp = LvGetStr(hWnd, L_LIST, i, 0); if (tmp != NULL) { RPC_DELETE_DEVICE t; wchar_t msg[MAX_SIZE]; name = CopyUniToStr(tmp); UniFormat(msg, sizeof(msg), _UU("EM_DELETE_CONFIRM"), name); if (MsgBox(hWnd, MB_YESNO | MB_ICONEXCLAMATION | MB_DEFBUTTON2, msg) == IDYES) { Zero(&t, sizeof(t)); StrCpy(t.DeviceName, sizeof(t.DeviceName), name); if (CALL(hWnd, EcDelDevice(r, &t))) { EmMainRefresh(hWnd, r); } } Free(tmp); Free(name); } } break; case IDCANCEL: Close(hWnd); break; } break; case WM_TIMER: switch (wParam) { case 1: KillTimer(hWnd, 1); EmMainRefresh(hWnd, r); SetTimer(hWnd, 1, 1000, NULL); break; } break; case WM_NOTIFY: n = (NMHDR *)lParam; switch (n->code) { case NM_DBLCLK: switch (n->idFrom) { case L_LIST: if (IsEnable(hWnd, IDOK)) { Command(hWnd, IDOK); } break; } break; case LVN_ITEMCHANGED: switch (n->idFrom) { case L_LIST: EmMainUpdate(hWnd, r); break; } break; } break; case WM_CLOSE: EndDialog(hWnd, 0); break; } return 0; } // Installation of WinPcap void EmInstallWinPcap(HWND hWnd, RPC *r) { wchar_t temp_name[MAX_SIZE]; HGLOBAL g; HINSTANCE h; HRSRC hr; UINT size; void *data; IO *io; // Ask whether the user want to start the installation if (MsgBox(hWnd, MB_ICONQUESTION | MB_YESNO, _UU("EM_WPCAP_INSTALL")) == IDNO) { return; } // Generate a temporary file name UniFormat(temp_name, sizeof(temp_name), L"%s\\winpcap_installer.exe", MsGetTempDirW()); // Read from the resource h = GetUiDll(); hr = FindResource(h, MAKEINTRESOURCE(BIN_WINPCAP), "BIN"); if (hr == NULL) { RES_ERROR: MsgBox(hWnd, MB_ICONSTOP, _UU("EM_RESOURCE")); return; } g = LoadResource(h, hr); if (g == NULL) { goto RES_ERROR; } size = SizeofResource(h, hr); data = LockResource(g); if (data == NULL) { goto RES_ERROR; } // Write to a temporary file io = FileCreateW(temp_name); if (io == NULL) { goto RES_ERROR; } FileWrite(io, data, size); FileClose(io); // Run if (RunW(temp_name, NULL, false, true) == false) { // Failure FileDeleteW(temp_name); goto RES_ERROR; } FileDeleteW(temp_name); if (r == NULL) { return; } // Need to restart the service if (MsgBox(hWnd, MB_ICONQUESTION | MB_YESNO, _UU("EM_WPCAP_REBOOT2")) == IDNO) { // Not restart } else { // Restart RPC_TEST t; RPC_BRIDGE_SUPPORT t2; Zero(&t, sizeof(t)); EcRebootServer(r, &t); SleepThread(500); Zero(&t2, sizeof(t2)); CALL(hWnd, EcGetBridgeSupport(r, &t2)); } } // Main screen void EMMain(RPC *r) { RPC_BRIDGE_SUPPORT t; // Validate arguments if (r == NULL) { return; } // Examine the bridge support status of the server side first Zero(&t, sizeof(t)); if (CALLEX(NULL, ScGetBridgeSupport(r, &t)) == ERR_NO_ERROR) { if (t.IsBridgeSupportedOs == false) { // OS does not support the bridge MsgBox(NULL, MB_ICONEXCLAMATION, _UU("EM_UNSUPPORTED")); return; } if (t.IsWinPcapNeeded) { if (r->Sock->RemoteIP.addr[0] != 127) { // WinPcap is required, but can not do anything because it is in remote management mode MsgBox(NULL, MB_ICONINFORMATION, _UU("EM_WPCAP_REMOTE")); return; } else { // WinPcap is required, and it's in local management mode if (MsIsAdmin()) { // Administrators EmInstallWinPcap(NULL, r); return; } else { // Non-Administrators MsgBox(NULL, MB_ICONINFORMATION, _UU("EM_WPCAP_ROOT")); return; } } } } Dialog(NULL, D_EM_MAIN, EmMainDlg, r); } // Remote connection dialog procedure UINT EmRemoteDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param) { WINUI_REMOTE *r = (WINUI_REMOTE *)param; CEDAR *c; // Validate arguments if (hWnd == NULL) { return 0; } switch (msg) { case WM_INITDIALOG: RemoteDlgInit(hWnd, r); SetTimer(hWnd, 1, 100, NULL); break; case WM_TIMER: switch (wParam) { case 1: KillTimer(hWnd, 1); RemoteDlgRefresh(hWnd, r); SetTimer(hWnd, 1, 100, NULL); break; } break; case WM_COMMAND: switch (wParam) { case R_LOCAL: if (IsChecked(hWnd, R_LOCAL) == false) { SetTextA(hWnd, C_HOSTNAME, ""); RemoteDlgRefresh(hWnd, r); FocusEx(hWnd, C_HOSTNAME); } else { SetTextA(hWnd, C_HOSTNAME, "localhost"); RemoteDlgRefresh(hWnd, r); Focus(hWnd, IDOK); } break; case IDCANCEL: Close(hWnd); break; case IDOK: RemoteDlgOnOk(hWnd, r); break; case B_ABOUT: c = NewCedar(NULL, NULL); About(hWnd, c, _UU("PRODUCT_NAME_ELOGMGR")); ReleaseCedar(c); } switch (LOWORD(wParam)) { case R_LOCAL: case C_HOSTNAME: RemoteDlgRefresh(hWnd, r); break; } break; case WM_CLOSE: FreeCandidateList(r->CandidateList); EndDialog(hWnd, false); break; } return 0; } // Remote connection dialog char *EmRemoteDlg() { WINUI_REMOTE r; Zero(&r, sizeof(r)); r.RegKeyName = EM_REG_KEY; r.Caption = _UU("EM_TITLE"); r.Title = _UU("EM_REMOTE_TITLE"); r.Icon = ICO_USER_ADMIN; r.DefaultHostname = NULL; if (Dialog(NULL, D_EM_REMOTE, EmRemoteDlgProc, &r) == false) { return NULL; } return r.Hostname; } // Start the EtherLogger Manager void EMExec() { char *host; char *ret; bool cancel_now = false; TOKEN_LIST *t; UINT port = EL_ADMIN_PORT; InitWinUi(_UU("EM_TITLE"), _SS("DEFAULT_FONT"), _II("DEFAULT_FONT_SIZE")); while (true) { ret = EmRemoteDlg(); if (ret != NULL) { t = ParseToken(ret, ":"); if (t->NumTokens == 1 || t->NumTokens == 2) { RPC *rpc = NULL; bool ok = false; UINT ret; host = t->Token[0]; if (t->NumTokens == 2) { port = ToInt(t->Token[1]); } else { port = EL_ADMIN_PORT; } // Try without a password first ret = EcConnect(host, port, "", &rpc); RETRY: if (ret != ERR_NO_ERROR && ret != ERR_AUTH_FAILED) { // Connection failed CALL(NULL, ret); } else { if (ret == ERR_NO_ERROR) { // Successful connection ok = true; } else { // Password required char *pass = SmPassword(NULL, host); if (pass == NULL) { // Cancel cancel_now = true; } else { // Retry ret = EcConnect(host, port, pass, &rpc); Free(pass); if (ret == ERR_NO_ERROR) { ok = true; } else { goto RETRY; } } } } if (ok) { // Main screen EMMain(rpc); // Disconnect EcDisconnect(rpc); cancel_now = true; } FreeToken(t); } Free(ret); } else { cancel_now = true; } if (cancel_now) { break; } } FreeWinUi(); } #endif // WIN32
the_stack_data/45450867.c
extern void __VERIFIER_error() __attribute__ ((__noreturn__)); void __VERIFIER_assert(int cond) { if(!(cond)) { ERROR: __VERIFIER_error(); } } #define N 100 int main( ) { int a1[N]; int a2[N]; int a3[N]; int a4[N]; int i; for ( i = 0 ; i < N ; i++ ) { a2[i] = a1[i]; } for ( i = 0 ; i < N ; i++ ) { a3[i] = a2[i]; } for ( i = 0 ; i < N ; i++ ) { a4[i] = a3[i]; } int x; for ( x = 0 ; x < N ; x++ ) { __VERIFIER_assert( a1[x] == a4[x] ); } return 0; }
the_stack_data/175142863.c
#include <stdio.h> int main(int argc, char *argv[]) { printf("hello world"); return 0; }
the_stack_data/237642864.c
#include <stdio.h> #include <stdlib.h> int main() { typedef struct { char nome[80]; int idade; } treg; treg reg; strcpy(reg.nome,"Maria"); reg.idade = 30; printf("%s", reg.nome); printf(" tem "); printf("%d", reg.idade); printf(" anos"); return 0; }
the_stack_data/108195.c
/* * phase1b.c - The user's input must match the specified string */ void phase_1(char *input) { #if defined(PROBLEM) if (strings_not_equal(input, "SOME_STRING_SET") != 0) explode_bomb(); #elif defined(SOLUTION) printf("SOME_STRING_GET\n"); #else invalid_phase("1b"); #endif }
the_stack_data/27362.c
/******************************************************************************* * * Intel Ethernet Controller XL710 Family Linux Driver * Copyright(c) 2013 - 2014 Intel Corporation. * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see <http://www.gnu.org/licenses/>. * * The full GNU General Public License is included in this distribution in * the file called "COPYING". * * Contact Information: * e1000-devel Mailing List <[email protected]> * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 * ******************************************************************************/ #ifdef CONFIG_DEBUG_FS #include <linux/fs.h> #include <linux/debugfs.h> #include "i40e.h" static struct dentry *i40e_dbg_root; /** * i40e_dbg_find_vsi - searches for the vsi with the given seid * @pf - the pf structure to search for the vsi * @seid - seid of the vsi it is searching for **/ static struct i40e_vsi *i40e_dbg_find_vsi(struct i40e_pf *pf, int seid) { int i; if (seid < 0) dev_info(&pf->pdev->dev, "%d: bad seid\n", seid); else for (i = 0; i < pf->hw.func_caps.num_vsis; i++) if (pf->vsi[i] && (pf->vsi[i]->seid == seid)) return pf->vsi[i]; return NULL; } /** * i40e_dbg_find_veb - searches for the veb with the given seid * @pf - the pf structure to search for the veb * @seid - seid of the veb it is searching for **/ static struct i40e_veb *i40e_dbg_find_veb(struct i40e_pf *pf, int seid) { int i; if ((seid < I40E_BASE_VEB_SEID) || (seid > (I40E_BASE_VEB_SEID + I40E_MAX_VEB))) dev_info(&pf->pdev->dev, "%d: bad seid\n", seid); else for (i = 0; i < I40E_MAX_VEB; i++) if (pf->veb[i] && pf->veb[i]->seid == seid) return pf->veb[i]; return NULL; } /************************************************************** * dump * The dump entry in debugfs is for getting a data snapshow of * the driver's current configuration and runtime details. * When the filesystem entry is written, a snapshot is taken. * When the entry is read, the most recent snapshot data is dumped. **************************************************************/ static char *i40e_dbg_dump_buf; static ssize_t i40e_dbg_dump_data_len; static ssize_t i40e_dbg_dump_buffer_len; /** * i40e_dbg_dump_read - read the dump data * @filp: the opened file * @buffer: where to write the data for the user to read * @count: the size of the user's buffer * @ppos: file position offset **/ static ssize_t i40e_dbg_dump_read(struct file *filp, char __user *buffer, size_t count, loff_t *ppos) { int bytes_not_copied; int len; /* is *ppos bigger than the available data? */ if (*ppos >= i40e_dbg_dump_data_len || !i40e_dbg_dump_buf) return 0; /* be sure to not read beyond the end of available data */ len = min_t(int, count, (i40e_dbg_dump_data_len - *ppos)); bytes_not_copied = copy_to_user(buffer, &i40e_dbg_dump_buf[*ppos], len); if (bytes_not_copied < 0) return bytes_not_copied; *ppos += len; return len; } /** * i40e_dbg_prep_dump_buf * @pf: the pf we're working with * @buflen: the desired buffer length * * Return positive if success, 0 if failed **/ static int i40e_dbg_prep_dump_buf(struct i40e_pf *pf, int buflen) { /* if not already big enough, prep for re alloc */ if (i40e_dbg_dump_buffer_len && i40e_dbg_dump_buffer_len < buflen) { kfree(i40e_dbg_dump_buf); i40e_dbg_dump_buffer_len = 0; i40e_dbg_dump_buf = NULL; } /* get a new buffer if needed */ if (!i40e_dbg_dump_buf) { i40e_dbg_dump_buf = kzalloc(buflen, GFP_KERNEL); if (i40e_dbg_dump_buf != NULL) i40e_dbg_dump_buffer_len = buflen; } return i40e_dbg_dump_buffer_len; } /** * i40e_dbg_dump_write - trigger a datadump snapshot * @filp: the opened file * @buffer: where to find the user's data * @count: the length of the user's data * @ppos: file position offset * * Any write clears the stats **/ static ssize_t i40e_dbg_dump_write(struct file *filp, const char __user *buffer, size_t count, loff_t *ppos) { struct i40e_pf *pf = filp->private_data; bool seid_found = false; long seid = -1; int buflen = 0; int i, ret; int len; u8 *p; /* don't allow partial writes */ if (*ppos != 0) return 0; /* decode the SEID given to be dumped */ ret = kstrtol_from_user(buffer, count, 0, &seid); if (ret) { dev_info(&pf->pdev->dev, "bad seid value\n"); } else if (seid == 0) { seid_found = true; kfree(i40e_dbg_dump_buf); i40e_dbg_dump_buffer_len = 0; i40e_dbg_dump_data_len = 0; i40e_dbg_dump_buf = NULL; dev_info(&pf->pdev->dev, "debug buffer freed\n"); } else if (seid == pf->pf_seid || seid == 1) { seid_found = true; buflen = sizeof(struct i40e_pf); buflen += (sizeof(struct i40e_aq_desc) * (pf->hw.aq.num_arq_entries + pf->hw.aq.num_asq_entries)); if (i40e_dbg_prep_dump_buf(pf, buflen)) { p = i40e_dbg_dump_buf; len = sizeof(struct i40e_pf); memcpy(p, pf, len); p += len; len = (sizeof(struct i40e_aq_desc) * pf->hw.aq.num_asq_entries); memcpy(p, pf->hw.aq.asq.desc_buf.va, len); p += len; len = (sizeof(struct i40e_aq_desc) * pf->hw.aq.num_arq_entries); memcpy(p, pf->hw.aq.arq.desc_buf.va, len); p += len; i40e_dbg_dump_data_len = buflen; dev_info(&pf->pdev->dev, "PF seid %ld dumped %d bytes\n", seid, (int)i40e_dbg_dump_data_len); } } else if (seid >= I40E_BASE_VSI_SEID) { struct i40e_vsi *vsi = NULL; struct i40e_mac_filter *f; int filter_count = 0; mutex_lock(&pf->switch_mutex); vsi = i40e_dbg_find_vsi(pf, seid); if (!vsi) { mutex_unlock(&pf->switch_mutex); goto write_exit; } buflen = sizeof(struct i40e_vsi); buflen += sizeof(struct i40e_q_vector) * vsi->num_q_vectors; buflen += sizeof(struct i40e_ring) * 2 * vsi->num_queue_pairs; buflen += sizeof(struct i40e_tx_buffer) * vsi->num_queue_pairs; buflen += sizeof(struct i40e_rx_buffer) * vsi->num_queue_pairs; list_for_each_entry(f, &vsi->mac_filter_list, list) filter_count++; buflen += sizeof(struct i40e_mac_filter) * filter_count; if (i40e_dbg_prep_dump_buf(pf, buflen)) { p = i40e_dbg_dump_buf; seid_found = true; len = sizeof(struct i40e_vsi); memcpy(p, vsi, len); p += len; if (vsi->num_q_vectors) { len = (sizeof(struct i40e_q_vector) * vsi->num_q_vectors); memcpy(p, vsi->q_vectors, len); p += len; } if (vsi->num_queue_pairs) { len = (sizeof(struct i40e_ring) * vsi->num_queue_pairs); memcpy(p, vsi->tx_rings, len); p += len; memcpy(p, vsi->rx_rings, len); p += len; } if (vsi->tx_rings[0]) { len = sizeof(struct i40e_tx_buffer); for (i = 0; i < vsi->num_queue_pairs; i++) { memcpy(p, vsi->tx_rings[i]->tx_bi, len); p += len; } len = sizeof(struct i40e_rx_buffer); for (i = 0; i < vsi->num_queue_pairs; i++) { memcpy(p, vsi->rx_rings[i]->rx_bi, len); p += len; } } /* macvlan filter list */ len = sizeof(struct i40e_mac_filter); list_for_each_entry(f, &vsi->mac_filter_list, list) { memcpy(p, f, len); p += len; } i40e_dbg_dump_data_len = buflen; dev_info(&pf->pdev->dev, "VSI seid %ld dumped %d bytes\n", seid, (int)i40e_dbg_dump_data_len); } mutex_unlock(&pf->switch_mutex); } else if (seid >= I40E_BASE_VEB_SEID) { struct i40e_veb *veb = NULL; mutex_lock(&pf->switch_mutex); veb = i40e_dbg_find_veb(pf, seid); if (!veb) { mutex_unlock(&pf->switch_mutex); goto write_exit; } buflen = sizeof(struct i40e_veb); if (i40e_dbg_prep_dump_buf(pf, buflen)) { seid_found = true; memcpy(i40e_dbg_dump_buf, veb, buflen); i40e_dbg_dump_data_len = buflen; dev_info(&pf->pdev->dev, "VEB seid %ld dumped %d bytes\n", seid, (int)i40e_dbg_dump_data_len); } mutex_unlock(&pf->switch_mutex); } write_exit: if (!seid_found) dev_info(&pf->pdev->dev, "unknown seid %ld\n", seid); return count; } static const struct file_operations i40e_dbg_dump_fops = { .owner = THIS_MODULE, .open = simple_open, .read = i40e_dbg_dump_read, .write = i40e_dbg_dump_write, }; /************************************************************** * command * The command entry in debugfs is for giving the driver commands * to be executed - these may be for changing the internal switch * setup, adding or removing filters, or other things. Many of * these will be useful for some forms of unit testing. **************************************************************/ static char i40e_dbg_command_buf[256] = "hello world"; /** * i40e_dbg_command_read - read for command datum * @filp: the opened file * @buffer: where to write the data for the user to read * @count: the size of the user's buffer * @ppos: file position offset **/ static ssize_t i40e_dbg_command_read(struct file *filp, char __user *buffer, size_t count, loff_t *ppos) { struct i40e_pf *pf = filp->private_data; int bytes_not_copied; int buf_size = 256; char *buf; int len; /* don't allow partial reads */ if (*ppos != 0) return 0; if (count < buf_size) return -ENOSPC; buf = kzalloc(buf_size, GFP_KERNEL); if (!buf) return -ENOSPC; len = snprintf(buf, buf_size, "%s: %s\n", pf->vsi[pf->lan_vsi]->netdev->name, i40e_dbg_command_buf); bytes_not_copied = copy_to_user(buffer, buf, len); kfree(buf); if (bytes_not_copied < 0) return bytes_not_copied; *ppos = len; return len; } /** * i40e_dbg_dump_vsi_seid - handles dump vsi seid write into command datum * @pf: the i40e_pf created in command write * @seid: the seid the user put in **/ static void i40e_dbg_dump_vsi_seid(struct i40e_pf *pf, int seid) { struct rtnl_link_stats64 *nstat; struct i40e_mac_filter *f; struct i40e_vsi *vsi; int i; vsi = i40e_dbg_find_vsi(pf, seid); if (!vsi) { dev_info(&pf->pdev->dev, "dump %d: seid not found\n", seid); return; } dev_info(&pf->pdev->dev, "vsi seid %d\n", seid); if (vsi->netdev) dev_info(&pf->pdev->dev, " netdev: name = %s\n", vsi->netdev->name); if (vsi->active_vlans) dev_info(&pf->pdev->dev, " vlgrp: & = %p\n", vsi->active_vlans); dev_info(&pf->pdev->dev, " netdev_registered = %i, current_netdev_flags = 0x%04x, state = %li flags = 0x%08lx\n", vsi->netdev_registered, vsi->current_netdev_flags, vsi->state, vsi->flags); list_for_each_entry(f, &vsi->mac_filter_list, list) { dev_info(&pf->pdev->dev, " mac_filter_list: %pM vid=%d, is_netdev=%d is_vf=%d counter=%d\n", f->macaddr, f->vlan, f->is_netdev, f->is_vf, f->counter); } nstat = i40e_get_vsi_stats_struct(vsi); dev_info(&pf->pdev->dev, " net_stats: rx_packets = %lu, rx_bytes = %lu, rx_errors = %lu, rx_dropped = %lu\n", (long unsigned int)nstat->rx_packets, (long unsigned int)nstat->rx_bytes, (long unsigned int)nstat->rx_errors, (long unsigned int)nstat->rx_dropped); dev_info(&pf->pdev->dev, " net_stats: tx_packets = %lu, tx_bytes = %lu, tx_errors = %lu, tx_dropped = %lu\n", (long unsigned int)nstat->tx_packets, (long unsigned int)nstat->tx_bytes, (long unsigned int)nstat->tx_errors, (long unsigned int)nstat->tx_dropped); dev_info(&pf->pdev->dev, " net_stats: multicast = %lu, collisions = %lu\n", (long unsigned int)nstat->multicast, (long unsigned int)nstat->collisions); dev_info(&pf->pdev->dev, " net_stats: rx_length_errors = %lu, rx_over_errors = %lu, rx_crc_errors = %lu\n", (long unsigned int)nstat->rx_length_errors, (long unsigned int)nstat->rx_over_errors, (long unsigned int)nstat->rx_crc_errors); dev_info(&pf->pdev->dev, " net_stats: rx_frame_errors = %lu, rx_fifo_errors = %lu, rx_missed_errors = %lu\n", (long unsigned int)nstat->rx_frame_errors, (long unsigned int)nstat->rx_fifo_errors, (long unsigned int)nstat->rx_missed_errors); dev_info(&pf->pdev->dev, " net_stats: tx_aborted_errors = %lu, tx_carrier_errors = %lu, tx_fifo_errors = %lu\n", (long unsigned int)nstat->tx_aborted_errors, (long unsigned int)nstat->tx_carrier_errors, (long unsigned int)nstat->tx_fifo_errors); dev_info(&pf->pdev->dev, " net_stats: tx_heartbeat_errors = %lu, tx_window_errors = %lu\n", (long unsigned int)nstat->tx_heartbeat_errors, (long unsigned int)nstat->tx_window_errors); dev_info(&pf->pdev->dev, " net_stats: rx_compressed = %lu, tx_compressed = %lu\n", (long unsigned int)nstat->rx_compressed, (long unsigned int)nstat->tx_compressed); dev_info(&pf->pdev->dev, " net_stats_offsets: rx_packets = %lu, rx_bytes = %lu, rx_errors = %lu, rx_dropped = %lu\n", (long unsigned int)vsi->net_stats_offsets.rx_packets, (long unsigned int)vsi->net_stats_offsets.rx_bytes, (long unsigned int)vsi->net_stats_offsets.rx_errors, (long unsigned int)vsi->net_stats_offsets.rx_dropped); dev_info(&pf->pdev->dev, " net_stats_offsets: tx_packets = %lu, tx_bytes = %lu, tx_errors = %lu, tx_dropped = %lu\n", (long unsigned int)vsi->net_stats_offsets.tx_packets, (long unsigned int)vsi->net_stats_offsets.tx_bytes, (long unsigned int)vsi->net_stats_offsets.tx_errors, (long unsigned int)vsi->net_stats_offsets.tx_dropped); dev_info(&pf->pdev->dev, " net_stats_offsets: multicast = %lu, collisions = %lu\n", (long unsigned int)vsi->net_stats_offsets.multicast, (long unsigned int)vsi->net_stats_offsets.collisions); dev_info(&pf->pdev->dev, " net_stats_offsets: rx_length_errors = %lu, rx_over_errors = %lu, rx_crc_errors = %lu\n", (long unsigned int)vsi->net_stats_offsets.rx_length_errors, (long unsigned int)vsi->net_stats_offsets.rx_over_errors, (long unsigned int)vsi->net_stats_offsets.rx_crc_errors); dev_info(&pf->pdev->dev, " net_stats_offsets: rx_frame_errors = %lu, rx_fifo_errors = %lu, rx_missed_errors = %lu\n", (long unsigned int)vsi->net_stats_offsets.rx_frame_errors, (long unsigned int)vsi->net_stats_offsets.rx_fifo_errors, (long unsigned int)vsi->net_stats_offsets.rx_missed_errors); dev_info(&pf->pdev->dev, " net_stats_offsets: tx_aborted_errors = %lu, tx_carrier_errors = %lu, tx_fifo_errors = %lu\n", (long unsigned int)vsi->net_stats_offsets.tx_aborted_errors, (long unsigned int)vsi->net_stats_offsets.tx_carrier_errors, (long unsigned int)vsi->net_stats_offsets.tx_fifo_errors); dev_info(&pf->pdev->dev, " net_stats_offsets: tx_heartbeat_errors = %lu, tx_window_errors = %lu\n", (long unsigned int)vsi->net_stats_offsets.tx_heartbeat_errors, (long unsigned int)vsi->net_stats_offsets.tx_window_errors); dev_info(&pf->pdev->dev, " net_stats_offsets: rx_compressed = %lu, tx_compressed = %lu\n", (long unsigned int)vsi->net_stats_offsets.rx_compressed, (long unsigned int)vsi->net_stats_offsets.tx_compressed); dev_info(&pf->pdev->dev, " tx_restart = %d, tx_busy = %d, rx_buf_failed = %d, rx_page_failed = %d\n", vsi->tx_restart, vsi->tx_busy, vsi->rx_buf_failed, vsi->rx_page_failed); rcu_read_lock(); for (i = 0; i < vsi->num_queue_pairs; i++) { struct i40e_ring *rx_ring = ACCESS_ONCE(vsi->rx_rings[i]); if (!rx_ring) continue; dev_info(&pf->pdev->dev, " rx_rings[%i]: desc = %p\n", i, rx_ring->desc); dev_info(&pf->pdev->dev, " rx_rings[%i]: dev = %p, netdev = %p, rx_bi = %p\n", i, rx_ring->dev, rx_ring->netdev, rx_ring->rx_bi); dev_info(&pf->pdev->dev, " rx_rings[%i]: state = %li, queue_index = %d, reg_idx = %d\n", i, rx_ring->state, rx_ring->queue_index, rx_ring->reg_idx); dev_info(&pf->pdev->dev, " rx_rings[%i]: rx_hdr_len = %d, rx_buf_len = %d, dtype = %d\n", i, rx_ring->rx_hdr_len, rx_ring->rx_buf_len, rx_ring->dtype); dev_info(&pf->pdev->dev, " rx_rings[%i]: hsplit = %d, next_to_use = %d, next_to_clean = %d, ring_active = %i\n", i, rx_ring->hsplit, rx_ring->next_to_use, rx_ring->next_to_clean, rx_ring->ring_active); dev_info(&pf->pdev->dev, " rx_rings[%i]: rx_stats: packets = %lld, bytes = %lld, non_eop_descs = %lld\n", i, rx_ring->stats.packets, rx_ring->stats.bytes, rx_ring->rx_stats.non_eop_descs); dev_info(&pf->pdev->dev, " rx_rings[%i]: rx_stats: alloc_page_failed = %lld, alloc_buff_failed = %lld\n", i, rx_ring->rx_stats.alloc_page_failed, rx_ring->rx_stats.alloc_buff_failed); dev_info(&pf->pdev->dev, " rx_rings[%i]: size = %i, dma = 0x%08lx\n", i, rx_ring->size, (long unsigned int)rx_ring->dma); dev_info(&pf->pdev->dev, " rx_rings[%i]: vsi = %p, q_vector = %p\n", i, rx_ring->vsi, rx_ring->q_vector); } for (i = 0; i < vsi->num_queue_pairs; i++) { struct i40e_ring *tx_ring = ACCESS_ONCE(vsi->tx_rings[i]); if (!tx_ring) continue; dev_info(&pf->pdev->dev, " tx_rings[%i]: desc = %p\n", i, tx_ring->desc); dev_info(&pf->pdev->dev, " tx_rings[%i]: dev = %p, netdev = %p, tx_bi = %p\n", i, tx_ring->dev, tx_ring->netdev, tx_ring->tx_bi); dev_info(&pf->pdev->dev, " tx_rings[%i]: state = %li, queue_index = %d, reg_idx = %d\n", i, tx_ring->state, tx_ring->queue_index, tx_ring->reg_idx); dev_info(&pf->pdev->dev, " tx_rings[%i]: dtype = %d\n", i, tx_ring->dtype); dev_info(&pf->pdev->dev, " tx_rings[%i]: hsplit = %d, next_to_use = %d, next_to_clean = %d, ring_active = %i\n", i, tx_ring->hsplit, tx_ring->next_to_use, tx_ring->next_to_clean, tx_ring->ring_active); dev_info(&pf->pdev->dev, " tx_rings[%i]: tx_stats: packets = %lld, bytes = %lld, restart_queue = %lld\n", i, tx_ring->stats.packets, tx_ring->stats.bytes, tx_ring->tx_stats.restart_queue); dev_info(&pf->pdev->dev, " tx_rings[%i]: tx_stats: tx_busy = %lld, tx_done_old = %lld\n", i, tx_ring->tx_stats.tx_busy, tx_ring->tx_stats.tx_done_old); dev_info(&pf->pdev->dev, " tx_rings[%i]: size = %i, dma = 0x%08lx\n", i, tx_ring->size, (long unsigned int)tx_ring->dma); dev_info(&pf->pdev->dev, " tx_rings[%i]: vsi = %p, q_vector = %p\n", i, tx_ring->vsi, tx_ring->q_vector); dev_info(&pf->pdev->dev, " tx_rings[%i]: DCB tc = %d\n", i, tx_ring->dcb_tc); } rcu_read_unlock(); dev_info(&pf->pdev->dev, " work_limit = %d, rx_itr_setting = %d (%s), tx_itr_setting = %d (%s)\n", vsi->work_limit, vsi->rx_itr_setting, ITR_IS_DYNAMIC(vsi->rx_itr_setting) ? "dynamic" : "fixed", vsi->tx_itr_setting, ITR_IS_DYNAMIC(vsi->tx_itr_setting) ? "dynamic" : "fixed"); dev_info(&pf->pdev->dev, " max_frame = %d, rx_hdr_len = %d, rx_buf_len = %d dtype = %d\n", vsi->max_frame, vsi->rx_hdr_len, vsi->rx_buf_len, vsi->dtype); dev_info(&pf->pdev->dev, " num_q_vectors = %i, base_vector = %i\n", vsi->num_q_vectors, vsi->base_vector); dev_info(&pf->pdev->dev, " seid = %d, id = %d, uplink_seid = %d\n", vsi->seid, vsi->id, vsi->uplink_seid); dev_info(&pf->pdev->dev, " base_queue = %d, num_queue_pairs = %d, num_desc = %d\n", vsi->base_queue, vsi->num_queue_pairs, vsi->num_desc); dev_info(&pf->pdev->dev, " type = %i\n", vsi->type); dev_info(&pf->pdev->dev, " info: valid_sections = 0x%04x, switch_id = 0x%04x\n", vsi->info.valid_sections, vsi->info.switch_id); dev_info(&pf->pdev->dev, " info: sw_reserved[] = 0x%02x 0x%02x\n", vsi->info.sw_reserved[0], vsi->info.sw_reserved[1]); dev_info(&pf->pdev->dev, " info: sec_flags = 0x%02x, sec_reserved = 0x%02x\n", vsi->info.sec_flags, vsi->info.sec_reserved); dev_info(&pf->pdev->dev, " info: pvid = 0x%04x, fcoe_pvid = 0x%04x, port_vlan_flags = 0x%02x\n", vsi->info.pvid, vsi->info.fcoe_pvid, vsi->info.port_vlan_flags); dev_info(&pf->pdev->dev, " info: pvlan_reserved[] = 0x%02x 0x%02x 0x%02x\n", vsi->info.pvlan_reserved[0], vsi->info.pvlan_reserved[1], vsi->info.pvlan_reserved[2]); dev_info(&pf->pdev->dev, " info: ingress_table = 0x%08x, egress_table = 0x%08x\n", vsi->info.ingress_table, vsi->info.egress_table); dev_info(&pf->pdev->dev, " info: cas_pv_stag = 0x%04x, cas_pv_flags= 0x%02x, cas_pv_reserved = 0x%02x\n", vsi->info.cas_pv_tag, vsi->info.cas_pv_flags, vsi->info.cas_pv_reserved); dev_info(&pf->pdev->dev, " info: queue_mapping[0..7 ] = 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x\n", vsi->info.queue_mapping[0], vsi->info.queue_mapping[1], vsi->info.queue_mapping[2], vsi->info.queue_mapping[3], vsi->info.queue_mapping[4], vsi->info.queue_mapping[5], vsi->info.queue_mapping[6], vsi->info.queue_mapping[7]); dev_info(&pf->pdev->dev, " info: queue_mapping[8..15] = 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x\n", vsi->info.queue_mapping[8], vsi->info.queue_mapping[9], vsi->info.queue_mapping[10], vsi->info.queue_mapping[11], vsi->info.queue_mapping[12], vsi->info.queue_mapping[13], vsi->info.queue_mapping[14], vsi->info.queue_mapping[15]); dev_info(&pf->pdev->dev, " info: tc_mapping[] = 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x\n", vsi->info.tc_mapping[0], vsi->info.tc_mapping[1], vsi->info.tc_mapping[2], vsi->info.tc_mapping[3], vsi->info.tc_mapping[4], vsi->info.tc_mapping[5], vsi->info.tc_mapping[6], vsi->info.tc_mapping[7]); dev_info(&pf->pdev->dev, " info: queueing_opt_flags = 0x%02x queueing_opt_reserved[0..2] = 0x%02x 0x%02x 0x%02x\n", vsi->info.queueing_opt_flags, vsi->info.queueing_opt_reserved[0], vsi->info.queueing_opt_reserved[1], vsi->info.queueing_opt_reserved[2]); dev_info(&pf->pdev->dev, " info: up_enable_bits = 0x%02x\n", vsi->info.up_enable_bits); dev_info(&pf->pdev->dev, " info: sched_reserved = 0x%02x, outer_up_table = 0x%04x\n", vsi->info.sched_reserved, vsi->info.outer_up_table); dev_info(&pf->pdev->dev, " info: cmd_reserved[] = 0x%02x 0x%02x 0x%02x 0x0%02x 0x%02x 0x%02x 0x%02x 0x0%02x\n", vsi->info.cmd_reserved[0], vsi->info.cmd_reserved[1], vsi->info.cmd_reserved[2], vsi->info.cmd_reserved[3], vsi->info.cmd_reserved[4], vsi->info.cmd_reserved[5], vsi->info.cmd_reserved[6], vsi->info.cmd_reserved[7]); dev_info(&pf->pdev->dev, " info: qs_handle[] = 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x\n", vsi->info.qs_handle[0], vsi->info.qs_handle[1], vsi->info.qs_handle[2], vsi->info.qs_handle[3], vsi->info.qs_handle[4], vsi->info.qs_handle[5], vsi->info.qs_handle[6], vsi->info.qs_handle[7]); dev_info(&pf->pdev->dev, " info: stat_counter_idx = 0x%04x, sched_id = 0x%04x\n", vsi->info.stat_counter_idx, vsi->info.sched_id); dev_info(&pf->pdev->dev, " info: resp_reserved[] = 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n", vsi->info.resp_reserved[0], vsi->info.resp_reserved[1], vsi->info.resp_reserved[2], vsi->info.resp_reserved[3], vsi->info.resp_reserved[4], vsi->info.resp_reserved[5], vsi->info.resp_reserved[6], vsi->info.resp_reserved[7], vsi->info.resp_reserved[8], vsi->info.resp_reserved[9], vsi->info.resp_reserved[10], vsi->info.resp_reserved[11]); if (vsi->back) dev_info(&pf->pdev->dev, " pf = %p\n", vsi->back); dev_info(&pf->pdev->dev, " idx = %d\n", vsi->idx); dev_info(&pf->pdev->dev, " tc_config: numtc = %d, enabled_tc = 0x%x\n", vsi->tc_config.numtc, vsi->tc_config.enabled_tc); for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { dev_info(&pf->pdev->dev, " tc_config: tc = %d, qoffset = %d, qcount = %d, netdev_tc = %d\n", i, vsi->tc_config.tc_info[i].qoffset, vsi->tc_config.tc_info[i].qcount, vsi->tc_config.tc_info[i].netdev_tc); } dev_info(&pf->pdev->dev, " bw: bw_limit = %d, bw_max_quanta = %d\n", vsi->bw_limit, vsi->bw_max_quanta); for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { dev_info(&pf->pdev->dev, " bw[%d]: ets_share_credits = %d, ets_limit_credits = %d, max_quanta = %d\n", i, vsi->bw_ets_share_credits[i], vsi->bw_ets_limit_credits[i], vsi->bw_ets_max_quanta[i]); } } /** * i40e_dbg_dump_aq_desc - handles dump aq_desc write into command datum * @pf: the i40e_pf created in command write **/ static void i40e_dbg_dump_aq_desc(struct i40e_pf *pf) { struct i40e_adminq_ring *ring; struct i40e_hw *hw = &pf->hw; char hdr[32]; int i; snprintf(hdr, sizeof(hdr), "%s %s: ", dev_driver_string(&pf->pdev->dev), dev_name(&pf->pdev->dev)); /* first the send (command) ring, then the receive (event) ring */ dev_info(&pf->pdev->dev, "AdminQ Tx Ring\n"); ring = &(hw->aq.asq); for (i = 0; i < ring->count; i++) { struct i40e_aq_desc *d = I40E_ADMINQ_DESC(*ring, i); dev_info(&pf->pdev->dev, " at[%02d] flags=0x%04x op=0x%04x dlen=0x%04x ret=0x%04x cookie_h=0x%08x cookie_l=0x%08x\n", i, d->flags, d->opcode, d->datalen, d->retval, d->cookie_high, d->cookie_low); print_hex_dump(KERN_INFO, hdr, DUMP_PREFIX_NONE, 16, 1, d->params.raw, 16, 0); } dev_info(&pf->pdev->dev, "AdminQ Rx Ring\n"); ring = &(hw->aq.arq); for (i = 0; i < ring->count; i++) { struct i40e_aq_desc *d = I40E_ADMINQ_DESC(*ring, i); dev_info(&pf->pdev->dev, " ar[%02d] flags=0x%04x op=0x%04x dlen=0x%04x ret=0x%04x cookie_h=0x%08x cookie_l=0x%08x\n", i, d->flags, d->opcode, d->datalen, d->retval, d->cookie_high, d->cookie_low); print_hex_dump(KERN_INFO, hdr, DUMP_PREFIX_NONE, 16, 1, d->params.raw, 16, 0); } } /** * i40e_dbg_dump_desc - handles dump desc write into command datum * @cnt: number of arguments that the user supplied * @vsi_seid: vsi id entered by user * @ring_id: ring id entered by user * @desc_n: descriptor number entered by user * @pf: the i40e_pf created in command write * @is_rx_ring: true if rx, false if tx **/ static void i40e_dbg_dump_desc(int cnt, int vsi_seid, int ring_id, int desc_n, struct i40e_pf *pf, bool is_rx_ring) { struct i40e_tx_desc *txd; union i40e_rx_desc *rxd; struct i40e_ring ring; struct i40e_vsi *vsi; int i; vsi = i40e_dbg_find_vsi(pf, vsi_seid); if (!vsi) { dev_info(&pf->pdev->dev, "vsi %d not found\n", vsi_seid); return; } if (ring_id >= vsi->num_queue_pairs || ring_id < 0) { dev_info(&pf->pdev->dev, "ring %d not found\n", ring_id); return; } if (!vsi->tx_rings || !vsi->tx_rings[0]->desc) { dev_info(&pf->pdev->dev, "descriptor rings have not been allocated for vsi %d\n", vsi_seid); return; } if (is_rx_ring) ring = *vsi->rx_rings[ring_id]; else ring = *vsi->tx_rings[ring_id]; if (cnt == 2) { dev_info(&pf->pdev->dev, "vsi = %02i %s ring = %02i\n", vsi_seid, is_rx_ring ? "rx" : "tx", ring_id); for (i = 0; i < ring.count; i++) { if (!is_rx_ring) { txd = I40E_TX_DESC(&ring, i); dev_info(&pf->pdev->dev, " d[%03i] = 0x%016llx 0x%016llx\n", i, txd->buffer_addr, txd->cmd_type_offset_bsz); } else if (sizeof(union i40e_rx_desc) == sizeof(union i40e_16byte_rx_desc)) { rxd = I40E_RX_DESC(&ring, i); dev_info(&pf->pdev->dev, " d[%03i] = 0x%016llx 0x%016llx\n", i, rxd->read.pkt_addr, rxd->read.hdr_addr); } else { rxd = I40E_RX_DESC(&ring, i); dev_info(&pf->pdev->dev, " d[%03i] = 0x%016llx 0x%016llx 0x%016llx 0x%016llx\n", i, rxd->read.pkt_addr, rxd->read.hdr_addr, rxd->read.rsvd1, rxd->read.rsvd2); } } } else if (cnt == 3) { if (desc_n >= ring.count || desc_n < 0) { dev_info(&pf->pdev->dev, "descriptor %d not found\n", desc_n); return; } if (!is_rx_ring) { txd = I40E_TX_DESC(&ring, desc_n); dev_info(&pf->pdev->dev, "vsi = %02i tx ring = %02i d[%03i] = 0x%016llx 0x%016llx\n", vsi_seid, ring_id, desc_n, txd->buffer_addr, txd->cmd_type_offset_bsz); } else if (sizeof(union i40e_rx_desc) == sizeof(union i40e_16byte_rx_desc)) { rxd = I40E_RX_DESC(&ring, desc_n); dev_info(&pf->pdev->dev, "vsi = %02i rx ring = %02i d[%03i] = 0x%016llx 0x%016llx\n", vsi_seid, ring_id, desc_n, rxd->read.pkt_addr, rxd->read.hdr_addr); } else { rxd = I40E_RX_DESC(&ring, desc_n); dev_info(&pf->pdev->dev, "vsi = %02i rx ring = %02i d[%03i] = 0x%016llx 0x%016llx 0x%016llx 0x%016llx\n", vsi_seid, ring_id, desc_n, rxd->read.pkt_addr, rxd->read.hdr_addr, rxd->read.rsvd1, rxd->read.rsvd2); } } else { dev_info(&pf->pdev->dev, "dump desc rx/tx <vsi_seid> <ring_id> [<desc_n>]\n"); } } /** * i40e_dbg_dump_vsi_no_seid - handles dump vsi write into command datum * @pf: the i40e_pf created in command write **/ static void i40e_dbg_dump_vsi_no_seid(struct i40e_pf *pf) { int i; for (i = 0; i < pf->hw.func_caps.num_vsis; i++) if (pf->vsi[i]) dev_info(&pf->pdev->dev, "dump vsi[%d]: %d\n", i, pf->vsi[i]->seid); } /** * i40e_dbg_dump_stats - handles dump stats write into command datum * @pf: the i40e_pf created in command write * @estats: the eth stats structure to be dumped **/ static void i40e_dbg_dump_eth_stats(struct i40e_pf *pf, struct i40e_eth_stats *estats) { dev_info(&pf->pdev->dev, " ethstats:\n"); dev_info(&pf->pdev->dev, " rx_bytes = \t%lld \trx_unicast = \t\t%lld \trx_multicast = \t%lld\n", estats->rx_bytes, estats->rx_unicast, estats->rx_multicast); dev_info(&pf->pdev->dev, " rx_broadcast = \t%lld \trx_discards = \t\t%lld \trx_errors = \t%lld\n", estats->rx_broadcast, estats->rx_discards, estats->rx_errors); dev_info(&pf->pdev->dev, " rx_missed = \t%lld \trx_unknown_protocol = \t%lld \ttx_bytes = \t%lld\n", estats->rx_missed, estats->rx_unknown_protocol, estats->tx_bytes); dev_info(&pf->pdev->dev, " tx_unicast = \t%lld \ttx_multicast = \t\t%lld \ttx_broadcast = \t%lld\n", estats->tx_unicast, estats->tx_multicast, estats->tx_broadcast); dev_info(&pf->pdev->dev, " tx_discards = \t%lld \ttx_errors = \t\t%lld\n", estats->tx_discards, estats->tx_errors); } /** * i40e_dbg_dump_stats - handles dump stats write into command datum * @pf: the i40e_pf created in command write * @stats: the stats structure to be dumped **/ static void i40e_dbg_dump_stats(struct i40e_pf *pf, struct i40e_hw_port_stats *stats) { int i; dev_info(&pf->pdev->dev, " stats:\n"); dev_info(&pf->pdev->dev, " crc_errors = \t\t%lld \tillegal_bytes = \t%lld \terror_bytes = \t\t%lld\n", stats->crc_errors, stats->illegal_bytes, stats->error_bytes); dev_info(&pf->pdev->dev, " mac_local_faults = \t%lld \tmac_remote_faults = \t%lld \trx_length_errors = \t%lld\n", stats->mac_local_faults, stats->mac_remote_faults, stats->rx_length_errors); dev_info(&pf->pdev->dev, " link_xon_rx = \t\t%lld \tlink_xoff_rx = \t\t%lld \tlink_xon_tx = \t\t%lld\n", stats->link_xon_rx, stats->link_xoff_rx, stats->link_xon_tx); dev_info(&pf->pdev->dev, " link_xoff_tx = \t\t%lld \trx_size_64 = \t\t%lld \trx_size_127 = \t\t%lld\n", stats->link_xoff_tx, stats->rx_size_64, stats->rx_size_127); dev_info(&pf->pdev->dev, " rx_size_255 = \t\t%lld \trx_size_511 = \t\t%lld \trx_size_1023 = \t\t%lld\n", stats->rx_size_255, stats->rx_size_511, stats->rx_size_1023); dev_info(&pf->pdev->dev, " rx_size_big = \t\t%lld \trx_undersize = \t\t%lld \trx_jabber = \t\t%lld\n", stats->rx_size_big, stats->rx_undersize, stats->rx_jabber); dev_info(&pf->pdev->dev, " rx_fragments = \t\t%lld \trx_oversize = \t\t%lld \ttx_size_64 = \t\t%lld\n", stats->rx_fragments, stats->rx_oversize, stats->tx_size_64); dev_info(&pf->pdev->dev, " tx_size_127 = \t\t%lld \ttx_size_255 = \t\t%lld \ttx_size_511 = \t\t%lld\n", stats->tx_size_127, stats->tx_size_255, stats->tx_size_511); dev_info(&pf->pdev->dev, " tx_size_1023 = \t\t%lld \ttx_size_big = \t\t%lld \tmac_short_packet_dropped = \t%lld\n", stats->tx_size_1023, stats->tx_size_big, stats->mac_short_packet_dropped); for (i = 0; i < 8; i += 4) { dev_info(&pf->pdev->dev, " priority_xon_rx[%d] = \t%lld \t[%d] = \t%lld \t[%d] = \t%lld \t[%d] = \t%lld\n", i, stats->priority_xon_rx[i], i+1, stats->priority_xon_rx[i+1], i+2, stats->priority_xon_rx[i+2], i+3, stats->priority_xon_rx[i+3]); } for (i = 0; i < 8; i += 4) { dev_info(&pf->pdev->dev, " priority_xoff_rx[%d] = \t%lld \t[%d] = \t%lld \t[%d] = \t%lld \t[%d] = \t%lld\n", i, stats->priority_xoff_rx[i], i+1, stats->priority_xoff_rx[i+1], i+2, stats->priority_xoff_rx[i+2], i+3, stats->priority_xoff_rx[i+3]); } for (i = 0; i < 8; i += 4) { dev_info(&pf->pdev->dev, " priority_xon_tx[%d] = \t%lld \t[%d] = \t%lld \t[%d] = \t%lld \t[%d] = \t%lld\n", i, stats->priority_xon_tx[i], i+1, stats->priority_xon_tx[i+1], i+2, stats->priority_xon_tx[i+2], i+3, stats->priority_xon_rx[i+3]); } for (i = 0; i < 8; i += 4) { dev_info(&pf->pdev->dev, " priority_xoff_tx[%d] = \t%lld \t[%d] = \t%lld \t[%d] = \t%lld \t[%d] = \t%lld\n", i, stats->priority_xoff_tx[i], i+1, stats->priority_xoff_tx[i+1], i+2, stats->priority_xoff_tx[i+2], i+3, stats->priority_xoff_tx[i+3]); } for (i = 0; i < 8; i += 4) { dev_info(&pf->pdev->dev, " priority_xon_2_xoff[%d] = \t%lld \t[%d] = \t%lld \t[%d] = \t%lld \t[%d] = \t%lld\n", i, stats->priority_xon_2_xoff[i], i+1, stats->priority_xon_2_xoff[i+1], i+2, stats->priority_xon_2_xoff[i+2], i+3, stats->priority_xon_2_xoff[i+3]); } i40e_dbg_dump_eth_stats(pf, &stats->eth); } /** * i40e_dbg_dump_veb_seid - handles dump stats of a single given veb * @pf: the i40e_pf created in command write * @seid: the seid the user put in **/ static void i40e_dbg_dump_veb_seid(struct i40e_pf *pf, int seid) { struct i40e_veb *veb; if ((seid < I40E_BASE_VEB_SEID) || (seid >= (I40E_MAX_VEB + I40E_BASE_VEB_SEID))) { dev_info(&pf->pdev->dev, "%d: bad seid\n", seid); return; } veb = i40e_dbg_find_veb(pf, seid); if (!veb) { dev_info(&pf->pdev->dev, "can't find veb %d\n", seid); return; } dev_info(&pf->pdev->dev, "veb idx=%d,%d stats_ic=%d seid=%d uplink=%d\n", veb->idx, veb->veb_idx, veb->stats_idx, veb->seid, veb->uplink_seid); i40e_dbg_dump_eth_stats(pf, &veb->stats); } /** * i40e_dbg_dump_veb_all - dumps all known veb's stats * @pf: the i40e_pf created in command write **/ static void i40e_dbg_dump_veb_all(struct i40e_pf *pf) { struct i40e_veb *veb; int i; for (i = 0; i < I40E_MAX_VEB; i++) { veb = pf->veb[i]; if (veb) i40e_dbg_dump_veb_seid(pf, veb->seid); } } /** * i40e_dbg_cmd_fd_ctrl - Enable/disable FD sideband/ATR * @pf: the pf that would be altered * @flag: flag that needs enabling or disabling * @enable: Enable/disable FD SD/ATR **/ static void i40e_dbg_cmd_fd_ctrl(struct i40e_pf *pf, u64 flag, bool enable) { if (enable) { pf->flags |= flag; } else { pf->flags &= ~flag; pf->auto_disable_flags |= flag; } dev_info(&pf->pdev->dev, "requesting a pf reset\n"); i40e_do_reset_safe(pf, (1 << __I40E_PF_RESET_REQUESTED)); } #define I40E_MAX_DEBUG_OUT_BUFFER (4096*4) /** * i40e_dbg_command_write - write into command datum * @filp: the opened file * @buffer: where to find the user's data * @count: the length of the user's data * @ppos: file position offset **/ static ssize_t i40e_dbg_command_write(struct file *filp, const char __user *buffer, size_t count, loff_t *ppos) { struct i40e_pf *pf = filp->private_data; char *cmd_buf, *cmd_buf_tmp; int bytes_not_copied; struct i40e_vsi *vsi; int vsi_seid; int veb_seid; int cnt; /* don't allow partial writes */ if (*ppos != 0) return 0; cmd_buf = kzalloc(count + 1, GFP_KERNEL); if (!cmd_buf) return count; bytes_not_copied = copy_from_user(cmd_buf, buffer, count); if (bytes_not_copied < 0) return bytes_not_copied; if (bytes_not_copied > 0) count -= bytes_not_copied; cmd_buf[count] = '\0'; cmd_buf_tmp = strchr(cmd_buf, '\n'); if (cmd_buf_tmp) { *cmd_buf_tmp = '\0'; count = cmd_buf_tmp - cmd_buf + 1; } if (strncmp(cmd_buf, "add vsi", 7) == 0) { vsi_seid = -1; cnt = sscanf(&cmd_buf[7], "%i", &vsi_seid); if (cnt == 0) { /* default to PF VSI */ vsi_seid = pf->vsi[pf->lan_vsi]->seid; } else if (vsi_seid < 0) { dev_info(&pf->pdev->dev, "add VSI %d: bad vsi seid\n", vsi_seid); goto command_write_done; } vsi = i40e_vsi_setup(pf, I40E_VSI_VMDQ2, vsi_seid, 0); if (vsi) dev_info(&pf->pdev->dev, "added VSI %d to relay %d\n", vsi->seid, vsi->uplink_seid); else dev_info(&pf->pdev->dev, "'%s' failed\n", cmd_buf); } else if (strncmp(cmd_buf, "del vsi", 7) == 0) { sscanf(&cmd_buf[7], "%i", &vsi_seid); vsi = i40e_dbg_find_vsi(pf, vsi_seid); if (!vsi) { dev_info(&pf->pdev->dev, "del VSI %d: seid not found\n", vsi_seid); goto command_write_done; } dev_info(&pf->pdev->dev, "deleting VSI %d\n", vsi_seid); i40e_vsi_release(vsi); } else if (strncmp(cmd_buf, "add relay", 9) == 0) { struct i40e_veb *veb; int uplink_seid, i; cnt = sscanf(&cmd_buf[9], "%i %i", &uplink_seid, &vsi_seid); if (cnt != 2) { dev_info(&pf->pdev->dev, "add relay: bad command string, cnt=%d\n", cnt); goto command_write_done; } else if (uplink_seid < 0) { dev_info(&pf->pdev->dev, "add relay %d: bad uplink seid\n", uplink_seid); goto command_write_done; } vsi = i40e_dbg_find_vsi(pf, vsi_seid); if (!vsi) { dev_info(&pf->pdev->dev, "add relay: VSI %d not found\n", vsi_seid); goto command_write_done; } for (i = 0; i < I40E_MAX_VEB; i++) if (pf->veb[i] && pf->veb[i]->seid == uplink_seid) break; if (i >= I40E_MAX_VEB && uplink_seid != 0 && uplink_seid != pf->mac_seid) { dev_info(&pf->pdev->dev, "add relay: relay uplink %d not found\n", uplink_seid); goto command_write_done; } veb = i40e_veb_setup(pf, 0, uplink_seid, vsi_seid, vsi->tc_config.enabled_tc); if (veb) dev_info(&pf->pdev->dev, "added relay %d\n", veb->seid); else dev_info(&pf->pdev->dev, "add relay failed\n"); } else if (strncmp(cmd_buf, "del relay", 9) == 0) { int i; cnt = sscanf(&cmd_buf[9], "%i", &veb_seid); if (cnt != 1) { dev_info(&pf->pdev->dev, "del relay: bad command string, cnt=%d\n", cnt); goto command_write_done; } else if (veb_seid < 0) { dev_info(&pf->pdev->dev, "del relay %d: bad relay seid\n", veb_seid); goto command_write_done; } /* find the veb */ for (i = 0; i < I40E_MAX_VEB; i++) if (pf->veb[i] && pf->veb[i]->seid == veb_seid) break; if (i >= I40E_MAX_VEB) { dev_info(&pf->pdev->dev, "del relay: relay %d not found\n", veb_seid); goto command_write_done; } dev_info(&pf->pdev->dev, "deleting relay %d\n", veb_seid); i40e_veb_release(pf->veb[i]); } else if (strncmp(cmd_buf, "add macaddr", 11) == 0) { struct i40e_mac_filter *f; int vlan = 0; u8 ma[6]; int ret; cnt = sscanf(&cmd_buf[11], "%i %hhx:%hhx:%hhx:%hhx:%hhx:%hhx %i", &vsi_seid, &ma[0], &ma[1], &ma[2], &ma[3], &ma[4], &ma[5], &vlan); if (cnt == 7) { vlan = 0; } else if (cnt != 8) { dev_info(&pf->pdev->dev, "add macaddr: bad command string, cnt=%d\n", cnt); goto command_write_done; } vsi = i40e_dbg_find_vsi(pf, vsi_seid); if (!vsi) { dev_info(&pf->pdev->dev, "add macaddr: VSI %d not found\n", vsi_seid); goto command_write_done; } f = i40e_add_filter(vsi, ma, vlan, false, false); ret = i40e_sync_vsi_filters(vsi); if (f && !ret) dev_info(&pf->pdev->dev, "add macaddr: %pM vlan=%d added to VSI %d\n", ma, vlan, vsi_seid); else dev_info(&pf->pdev->dev, "add macaddr: %pM vlan=%d to VSI %d failed, f=%p ret=%d\n", ma, vlan, vsi_seid, f, ret); } else if (strncmp(cmd_buf, "del macaddr", 11) == 0) { int vlan = 0; u8 ma[6]; int ret; cnt = sscanf(&cmd_buf[11], "%i %hhx:%hhx:%hhx:%hhx:%hhx:%hhx %i", &vsi_seid, &ma[0], &ma[1], &ma[2], &ma[3], &ma[4], &ma[5], &vlan); if (cnt == 7) { vlan = 0; } else if (cnt != 8) { dev_info(&pf->pdev->dev, "del macaddr: bad command string, cnt=%d\n", cnt); goto command_write_done; } vsi = i40e_dbg_find_vsi(pf, vsi_seid); if (!vsi) { dev_info(&pf->pdev->dev, "del macaddr: VSI %d not found\n", vsi_seid); goto command_write_done; } i40e_del_filter(vsi, ma, vlan, false, false); ret = i40e_sync_vsi_filters(vsi); if (!ret) dev_info(&pf->pdev->dev, "del macaddr: %pM vlan=%d removed from VSI %d\n", ma, vlan, vsi_seid); else dev_info(&pf->pdev->dev, "del macaddr: %pM vlan=%d from VSI %d failed, ret=%d\n", ma, vlan, vsi_seid, ret); } else if (strncmp(cmd_buf, "add pvid", 8) == 0) { i40e_status ret; u16 vid; int v; cnt = sscanf(&cmd_buf[8], "%i %u", &vsi_seid, &v); if (cnt != 2) { dev_info(&pf->pdev->dev, "add pvid: bad command string, cnt=%d\n", cnt); goto command_write_done; } vsi = i40e_dbg_find_vsi(pf, vsi_seid); if (!vsi) { dev_info(&pf->pdev->dev, "add pvid: VSI %d not found\n", vsi_seid); goto command_write_done; } vid = (unsigned)v; ret = i40e_vsi_add_pvid(vsi, vid); if (!ret) dev_info(&pf->pdev->dev, "add pvid: %d added to VSI %d\n", vid, vsi_seid); else dev_info(&pf->pdev->dev, "add pvid: %d to VSI %d failed, ret=%d\n", vid, vsi_seid, ret); } else if (strncmp(cmd_buf, "del pvid", 8) == 0) { cnt = sscanf(&cmd_buf[8], "%i", &vsi_seid); if (cnt != 1) { dev_info(&pf->pdev->dev, "del pvid: bad command string, cnt=%d\n", cnt); goto command_write_done; } vsi = i40e_dbg_find_vsi(pf, vsi_seid); if (!vsi) { dev_info(&pf->pdev->dev, "del pvid: VSI %d not found\n", vsi_seid); goto command_write_done; } i40e_vsi_remove_pvid(vsi); dev_info(&pf->pdev->dev, "del pvid: removed from VSI %d\n", vsi_seid); } else if (strncmp(cmd_buf, "dump", 4) == 0) { if (strncmp(&cmd_buf[5], "switch", 6) == 0) { i40e_fetch_switch_configuration(pf, true); } else if (strncmp(&cmd_buf[5], "vsi", 3) == 0) { cnt = sscanf(&cmd_buf[8], "%i", &vsi_seid); if (cnt > 0) i40e_dbg_dump_vsi_seid(pf, vsi_seid); else i40e_dbg_dump_vsi_no_seid(pf); } else if (strncmp(&cmd_buf[5], "veb", 3) == 0) { cnt = sscanf(&cmd_buf[8], "%i", &vsi_seid); if (cnt > 0) i40e_dbg_dump_veb_seid(pf, vsi_seid); else i40e_dbg_dump_veb_all(pf); } else if (strncmp(&cmd_buf[5], "desc", 4) == 0) { int ring_id, desc_n; if (strncmp(&cmd_buf[10], "rx", 2) == 0) { cnt = sscanf(&cmd_buf[12], "%i %i %i", &vsi_seid, &ring_id, &desc_n); i40e_dbg_dump_desc(cnt, vsi_seid, ring_id, desc_n, pf, true); } else if (strncmp(&cmd_buf[10], "tx", 2) == 0) { cnt = sscanf(&cmd_buf[12], "%i %i %i", &vsi_seid, &ring_id, &desc_n); i40e_dbg_dump_desc(cnt, vsi_seid, ring_id, desc_n, pf, false); } else if (strncmp(&cmd_buf[10], "aq", 2) == 0) { i40e_dbg_dump_aq_desc(pf); } else { dev_info(&pf->pdev->dev, "dump desc tx <vsi_seid> <ring_id> [<desc_n>]\n"); dev_info(&pf->pdev->dev, "dump desc rx <vsi_seid> <ring_id> [<desc_n>]\n"); dev_info(&pf->pdev->dev, "dump desc aq\n"); } } else if (strncmp(&cmd_buf[5], "stats", 5) == 0) { dev_info(&pf->pdev->dev, "pf stats:\n"); i40e_dbg_dump_stats(pf, &pf->stats); dev_info(&pf->pdev->dev, "pf stats_offsets:\n"); i40e_dbg_dump_stats(pf, &pf->stats_offsets); } else if (strncmp(&cmd_buf[5], "reset stats", 11) == 0) { dev_info(&pf->pdev->dev, "core reset count: %d\n", pf->corer_count); dev_info(&pf->pdev->dev, "global reset count: %d\n", pf->globr_count); dev_info(&pf->pdev->dev, "emp reset count: %d\n", pf->empr_count); dev_info(&pf->pdev->dev, "pf reset count: %d\n", pf->pfr_count); } else if (strncmp(&cmd_buf[5], "port", 4) == 0) { struct i40e_aqc_query_port_ets_config_resp *bw_data; struct i40e_dcbx_config *cfg = &pf->hw.local_dcbx_config; struct i40e_dcbx_config *r_cfg = &pf->hw.remote_dcbx_config; int i, ret; bw_data = kzalloc(sizeof( struct i40e_aqc_query_port_ets_config_resp), GFP_KERNEL); if (!bw_data) { ret = -ENOMEM; goto command_write_done; } ret = i40e_aq_query_port_ets_config(&pf->hw, pf->mac_seid, bw_data, NULL); if (ret) { dev_info(&pf->pdev->dev, "Query Port ETS Config AQ command failed =0x%x\n", pf->hw.aq.asq_last_status); kfree(bw_data); bw_data = NULL; goto command_write_done; } dev_info(&pf->pdev->dev, "port bw: tc_valid=0x%x tc_strict_prio=0x%x, tc_bw_max=0x%04x,0x%04x\n", bw_data->tc_valid_bits, bw_data->tc_strict_priority_bits, le16_to_cpu(bw_data->tc_bw_max[0]), le16_to_cpu(bw_data->tc_bw_max[1])); for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { dev_info(&pf->pdev->dev, "port bw: tc_bw_share=%d tc_bw_limit=%d\n", bw_data->tc_bw_share_credits[i], le16_to_cpu(bw_data->tc_bw_limits[i])); } kfree(bw_data); bw_data = NULL; dev_info(&pf->pdev->dev, "port ets_cfg: willing=%d cbs=%d, maxtcs=%d\n", cfg->etscfg.willing, cfg->etscfg.cbs, cfg->etscfg.maxtcs); for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { dev_info(&pf->pdev->dev, "port ets_cfg: %d prio_tc=%d tcbw=%d tctsa=%d\n", i, cfg->etscfg.prioritytable[i], cfg->etscfg.tcbwtable[i], cfg->etscfg.tsatable[i]); } for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { dev_info(&pf->pdev->dev, "port ets_rec: %d prio_tc=%d tcbw=%d tctsa=%d\n", i, cfg->etsrec.prioritytable[i], cfg->etsrec.tcbwtable[i], cfg->etsrec.tsatable[i]); } dev_info(&pf->pdev->dev, "port pfc_cfg: willing=%d mbc=%d, pfccap=%d pfcenable=0x%x\n", cfg->pfc.willing, cfg->pfc.mbc, cfg->pfc.pfccap, cfg->pfc.pfcenable); dev_info(&pf->pdev->dev, "port app_table: num_apps=%d\n", cfg->numapps); for (i = 0; i < cfg->numapps; i++) { dev_info(&pf->pdev->dev, "port app_table: %d prio=%d selector=%d protocol=0x%x\n", i, cfg->app[i].priority, cfg->app[i].selector, cfg->app[i].protocolid); } /* Peer TLV DCBX data */ dev_info(&pf->pdev->dev, "remote port ets_cfg: willing=%d cbs=%d, maxtcs=%d\n", r_cfg->etscfg.willing, r_cfg->etscfg.cbs, r_cfg->etscfg.maxtcs); for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { dev_info(&pf->pdev->dev, "remote port ets_cfg: %d prio_tc=%d tcbw=%d tctsa=%d\n", i, r_cfg->etscfg.prioritytable[i], r_cfg->etscfg.tcbwtable[i], r_cfg->etscfg.tsatable[i]); } for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { dev_info(&pf->pdev->dev, "remote port ets_rec: %d prio_tc=%d tcbw=%d tctsa=%d\n", i, r_cfg->etsrec.prioritytable[i], r_cfg->etsrec.tcbwtable[i], r_cfg->etsrec.tsatable[i]); } dev_info(&pf->pdev->dev, "remote port pfc_cfg: willing=%d mbc=%d, pfccap=%d pfcenable=0x%x\n", r_cfg->pfc.willing, r_cfg->pfc.mbc, r_cfg->pfc.pfccap, r_cfg->pfc.pfcenable); dev_info(&pf->pdev->dev, "remote port app_table: num_apps=%d\n", r_cfg->numapps); for (i = 0; i < r_cfg->numapps; i++) { dev_info(&pf->pdev->dev, "remote port app_table: %d prio=%d selector=%d protocol=0x%x\n", i, r_cfg->app[i].priority, r_cfg->app[i].selector, r_cfg->app[i].protocolid); } } else { dev_info(&pf->pdev->dev, "dump desc tx <vsi_seid> <ring_id> [<desc_n>], dump desc rx <vsi_seid> <ring_id> [<desc_n>],\n"); dev_info(&pf->pdev->dev, "dump switch, dump vsi [seid] or\n"); dev_info(&pf->pdev->dev, "dump stats\n"); dev_info(&pf->pdev->dev, "dump reset stats\n"); dev_info(&pf->pdev->dev, "dump port\n"); dev_info(&pf->pdev->dev, "dump debug fwdata <cluster_id> <table_id> <index>\n"); } } else if (strncmp(cmd_buf, "msg_enable", 10) == 0) { u32 level; cnt = sscanf(&cmd_buf[10], "%i", &level); if (cnt) { if (I40E_DEBUG_USER & level) { pf->hw.debug_mask = level; dev_info(&pf->pdev->dev, "set hw.debug_mask = 0x%08x\n", pf->hw.debug_mask); } pf->msg_enable = level; dev_info(&pf->pdev->dev, "set msg_enable = 0x%08x\n", pf->msg_enable); } else { dev_info(&pf->pdev->dev, "msg_enable = 0x%08x\n", pf->msg_enable); } } else if (strncmp(cmd_buf, "pfr", 3) == 0) { dev_info(&pf->pdev->dev, "debugfs: forcing PFR\n"); i40e_do_reset_safe(pf, (1 << __I40E_PF_RESET_REQUESTED)); } else if (strncmp(cmd_buf, "corer", 5) == 0) { dev_info(&pf->pdev->dev, "debugfs: forcing CoreR\n"); i40e_do_reset_safe(pf, (1 << __I40E_CORE_RESET_REQUESTED)); } else if (strncmp(cmd_buf, "globr", 5) == 0) { dev_info(&pf->pdev->dev, "debugfs: forcing GlobR\n"); i40e_do_reset_safe(pf, (1 << __I40E_GLOBAL_RESET_REQUESTED)); } else if (strncmp(cmd_buf, "empr", 4) == 0) { dev_info(&pf->pdev->dev, "debugfs: forcing EMPR\n"); i40e_do_reset_safe(pf, (1 << __I40E_EMP_RESET_REQUESTED)); } else if (strncmp(cmd_buf, "read", 4) == 0) { u32 address; u32 value; cnt = sscanf(&cmd_buf[4], "%i", &address); if (cnt != 1) { dev_info(&pf->pdev->dev, "read <reg>\n"); goto command_write_done; } /* check the range on address */ if (address >= I40E_MAX_REGISTER) { dev_info(&pf->pdev->dev, "read reg address 0x%08x too large\n", address); goto command_write_done; } value = rd32(&pf->hw, address); dev_info(&pf->pdev->dev, "read: 0x%08x = 0x%08x\n", address, value); } else if (strncmp(cmd_buf, "write", 5) == 0) { u32 address, value; cnt = sscanf(&cmd_buf[5], "%i %i", &address, &value); if (cnt != 2) { dev_info(&pf->pdev->dev, "write <reg> <value>\n"); goto command_write_done; } /* check the range on address */ if (address >= I40E_MAX_REGISTER) { dev_info(&pf->pdev->dev, "write reg address 0x%08x too large\n", address); goto command_write_done; } wr32(&pf->hw, address, value); value = rd32(&pf->hw, address); dev_info(&pf->pdev->dev, "write: 0x%08x = 0x%08x\n", address, value); } else if (strncmp(cmd_buf, "clear_stats", 11) == 0) { if (strncmp(&cmd_buf[12], "vsi", 3) == 0) { cnt = sscanf(&cmd_buf[15], "%i", &vsi_seid); if (cnt == 0) { int i; for (i = 0; i < pf->hw.func_caps.num_vsis; i++) i40e_vsi_reset_stats(pf->vsi[i]); dev_info(&pf->pdev->dev, "vsi clear stats called for all vsi's\n"); } else if (cnt == 1) { vsi = i40e_dbg_find_vsi(pf, vsi_seid); if (!vsi) { dev_info(&pf->pdev->dev, "clear_stats vsi: bad vsi %d\n", vsi_seid); goto command_write_done; } i40e_vsi_reset_stats(vsi); dev_info(&pf->pdev->dev, "vsi clear stats called for vsi %d\n", vsi_seid); } else { dev_info(&pf->pdev->dev, "clear_stats vsi [seid]\n"); } } else if (strncmp(&cmd_buf[12], "pf", 2) == 0) { i40e_pf_reset_stats(pf); dev_info(&pf->pdev->dev, "pf clear stats called\n"); } else { dev_info(&pf->pdev->dev, "clear_stats vsi [seid] or clear_stats pf\n"); } } else if (strncmp(cmd_buf, "send aq_cmd", 11) == 0) { struct i40e_aq_desc *desc; i40e_status ret; desc = kzalloc(sizeof(struct i40e_aq_desc), GFP_KERNEL); if (!desc) goto command_write_done; cnt = sscanf(&cmd_buf[11], "%hx %hx %hx %hx %x %x %x %x %x %x", &desc->flags, &desc->opcode, &desc->datalen, &desc->retval, &desc->cookie_high, &desc->cookie_low, &desc->params.internal.param0, &desc->params.internal.param1, &desc->params.internal.param2, &desc->params.internal.param3); if (cnt != 10) { dev_info(&pf->pdev->dev, "send aq_cmd: bad command string, cnt=%d\n", cnt); kfree(desc); desc = NULL; goto command_write_done; } ret = i40e_asq_send_command(&pf->hw, desc, NULL, 0, NULL); if (!ret) { dev_info(&pf->pdev->dev, "AQ command sent Status : Success\n"); } else if (ret == I40E_ERR_ADMIN_QUEUE_ERROR) { dev_info(&pf->pdev->dev, "AQ command send failed Opcode %x AQ Error: %d\n", desc->opcode, pf->hw.aq.asq_last_status); } else { dev_info(&pf->pdev->dev, "AQ command send failed Opcode %x Status: %d\n", desc->opcode, ret); } dev_info(&pf->pdev->dev, "AQ desc WB 0x%04x 0x%04x 0x%04x 0x%04x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n", desc->flags, desc->opcode, desc->datalen, desc->retval, desc->cookie_high, desc->cookie_low, desc->params.internal.param0, desc->params.internal.param1, desc->params.internal.param2, desc->params.internal.param3); kfree(desc); desc = NULL; } else if (strncmp(cmd_buf, "send indirect aq_cmd", 20) == 0) { struct i40e_aq_desc *desc; i40e_status ret; u16 buffer_len; u8 *buff; desc = kzalloc(sizeof(struct i40e_aq_desc), GFP_KERNEL); if (!desc) goto command_write_done; cnt = sscanf(&cmd_buf[20], "%hx %hx %hx %hx %x %x %x %x %x %x %hd", &desc->flags, &desc->opcode, &desc->datalen, &desc->retval, &desc->cookie_high, &desc->cookie_low, &desc->params.internal.param0, &desc->params.internal.param1, &desc->params.internal.param2, &desc->params.internal.param3, &buffer_len); if (cnt != 11) { dev_info(&pf->pdev->dev, "send indirect aq_cmd: bad command string, cnt=%d\n", cnt); kfree(desc); desc = NULL; goto command_write_done; } /* Just stub a buffer big enough in case user messed up */ if (buffer_len == 0) buffer_len = 1280; buff = kzalloc(buffer_len, GFP_KERNEL); if (!buff) { kfree(desc); desc = NULL; goto command_write_done; } desc->flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF); ret = i40e_asq_send_command(&pf->hw, desc, buff, buffer_len, NULL); if (!ret) { dev_info(&pf->pdev->dev, "AQ command sent Status : Success\n"); } else if (ret == I40E_ERR_ADMIN_QUEUE_ERROR) { dev_info(&pf->pdev->dev, "AQ command send failed Opcode %x AQ Error: %d\n", desc->opcode, pf->hw.aq.asq_last_status); } else { dev_info(&pf->pdev->dev, "AQ command send failed Opcode %x Status: %d\n", desc->opcode, ret); } dev_info(&pf->pdev->dev, "AQ desc WB 0x%04x 0x%04x 0x%04x 0x%04x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n", desc->flags, desc->opcode, desc->datalen, desc->retval, desc->cookie_high, desc->cookie_low, desc->params.internal.param0, desc->params.internal.param1, desc->params.internal.param2, desc->params.internal.param3); print_hex_dump(KERN_INFO, "AQ buffer WB: ", DUMP_PREFIX_OFFSET, 16, 1, buff, buffer_len, true); kfree(buff); buff = NULL; kfree(desc); desc = NULL; } else if ((strncmp(cmd_buf, "add fd_filter", 13) == 0) || (strncmp(cmd_buf, "rem fd_filter", 13) == 0)) { struct i40e_fdir_filter fd_data; u16 packet_len, i, j = 0; char *asc_packet; u8 *raw_packet; bool add = false; int ret; if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED)) goto command_write_done; if (strncmp(cmd_buf, "add", 3) == 0) add = true; if (add && (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)) goto command_write_done; asc_packet = kzalloc(I40E_FDIR_MAX_RAW_PACKET_SIZE, GFP_KERNEL); if (!asc_packet) goto command_write_done; raw_packet = kzalloc(I40E_FDIR_MAX_RAW_PACKET_SIZE, GFP_KERNEL); if (!raw_packet) { kfree(asc_packet); asc_packet = NULL; goto command_write_done; } cnt = sscanf(&cmd_buf[13], "%hx %2hhx %2hhx %hx %2hhx %2hhx %hx %x %hd %511s", &fd_data.q_index, &fd_data.flex_off, &fd_data.pctype, &fd_data.dest_vsi, &fd_data.dest_ctl, &fd_data.fd_status, &fd_data.cnt_index, &fd_data.fd_id, &packet_len, asc_packet); if (cnt != 10) { dev_info(&pf->pdev->dev, "program fd_filter: bad command string, cnt=%d\n", cnt); kfree(asc_packet); asc_packet = NULL; kfree(raw_packet); goto command_write_done; } /* fix packet length if user entered 0 */ if (packet_len == 0) packet_len = I40E_FDIR_MAX_RAW_PACKET_SIZE; /* make sure to check the max as well */ packet_len = min_t(u16, packet_len, I40E_FDIR_MAX_RAW_PACKET_SIZE); for (i = 0; i < packet_len; i++) { sscanf(&asc_packet[j], "%2hhx ", &raw_packet[i]); j += 3; } dev_info(&pf->pdev->dev, "FD raw packet dump\n"); print_hex_dump(KERN_INFO, "FD raw packet: ", DUMP_PREFIX_OFFSET, 16, 1, raw_packet, packet_len, true); ret = i40e_program_fdir_filter(&fd_data, raw_packet, pf, add); if (!ret) { dev_info(&pf->pdev->dev, "Filter command send Status : Success\n"); } else { dev_info(&pf->pdev->dev, "Filter command send failed %d\n", ret); } kfree(raw_packet); raw_packet = NULL; kfree(asc_packet); asc_packet = NULL; } else if (strncmp(cmd_buf, "fd-atr off", 10) == 0) { i40e_dbg_cmd_fd_ctrl(pf, I40E_FLAG_FD_ATR_ENABLED, false); } else if (strncmp(cmd_buf, "fd-atr on", 9) == 0) { i40e_dbg_cmd_fd_ctrl(pf, I40E_FLAG_FD_ATR_ENABLED, true); } else if (strncmp(cmd_buf, "fd-sb off", 9) == 0) { i40e_dbg_cmd_fd_ctrl(pf, I40E_FLAG_FD_SB_ENABLED, false); } else if (strncmp(cmd_buf, "fd-sb on", 8) == 0) { i40e_dbg_cmd_fd_ctrl(pf, I40E_FLAG_FD_SB_ENABLED, true); } else if (strncmp(cmd_buf, "lldp", 4) == 0) { if (strncmp(&cmd_buf[5], "stop", 4) == 0) { int ret; ret = i40e_aq_stop_lldp(&pf->hw, false, NULL); if (ret) { dev_info(&pf->pdev->dev, "Stop LLDP AQ command failed =0x%x\n", pf->hw.aq.asq_last_status); goto command_write_done; } ret = i40e_aq_add_rem_control_packet_filter(&pf->hw, pf->hw.mac.addr, I40E_ETH_P_LLDP, 0, pf->vsi[pf->lan_vsi]->seid, 0, true, NULL, NULL); if (ret) { dev_info(&pf->pdev->dev, "%s: Add Control Packet Filter AQ command failed =0x%x\n", __func__, pf->hw.aq.asq_last_status); goto command_write_done; } #ifdef CONFIG_I40E_DCB pf->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_IEEE; #endif /* CONFIG_I40E_DCB */ } else if (strncmp(&cmd_buf[5], "start", 5) == 0) { int ret; ret = i40e_aq_add_rem_control_packet_filter(&pf->hw, pf->hw.mac.addr, I40E_ETH_P_LLDP, 0, pf->vsi[pf->lan_vsi]->seid, 0, false, NULL, NULL); if (ret) { dev_info(&pf->pdev->dev, "%s: Remove Control Packet Filter AQ command failed =0x%x\n", __func__, pf->hw.aq.asq_last_status); /* Continue and start FW LLDP anyways */ } ret = i40e_aq_start_lldp(&pf->hw, NULL); if (ret) { dev_info(&pf->pdev->dev, "Start LLDP AQ command failed =0x%x\n", pf->hw.aq.asq_last_status); goto command_write_done; } #ifdef CONFIG_I40E_DCB pf->dcbx_cap = DCB_CAP_DCBX_LLD_MANAGED | DCB_CAP_DCBX_VER_IEEE; #endif /* CONFIG_I40E_DCB */ } else if (strncmp(&cmd_buf[5], "get local", 9) == 0) { u16 llen, rlen; int ret; u8 *buff; buff = kzalloc(I40E_LLDPDU_SIZE, GFP_KERNEL); if (!buff) goto command_write_done; ret = i40e_aq_get_lldp_mib(&pf->hw, 0, I40E_AQ_LLDP_MIB_LOCAL, buff, I40E_LLDPDU_SIZE, &llen, &rlen, NULL); if (ret) { dev_info(&pf->pdev->dev, "Get LLDP MIB (local) AQ command failed =0x%x\n", pf->hw.aq.asq_last_status); kfree(buff); buff = NULL; goto command_write_done; } dev_info(&pf->pdev->dev, "LLDP MIB (local)\n"); print_hex_dump(KERN_INFO, "LLDP MIB (local): ", DUMP_PREFIX_OFFSET, 16, 1, buff, I40E_LLDPDU_SIZE, true); kfree(buff); buff = NULL; } else if (strncmp(&cmd_buf[5], "get remote", 10) == 0) { u16 llen, rlen; int ret; u8 *buff; buff = kzalloc(I40E_LLDPDU_SIZE, GFP_KERNEL); if (!buff) goto command_write_done; ret = i40e_aq_get_lldp_mib(&pf->hw, I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE, I40E_AQ_LLDP_MIB_LOCAL, buff, I40E_LLDPDU_SIZE, &llen, &rlen, NULL); if (ret) { dev_info(&pf->pdev->dev, "Get LLDP MIB (remote) AQ command failed =0x%x\n", pf->hw.aq.asq_last_status); kfree(buff); buff = NULL; goto command_write_done; } dev_info(&pf->pdev->dev, "LLDP MIB (remote)\n"); print_hex_dump(KERN_INFO, "LLDP MIB (remote): ", DUMP_PREFIX_OFFSET, 16, 1, buff, I40E_LLDPDU_SIZE, true); kfree(buff); buff = NULL; } else if (strncmp(&cmd_buf[5], "event on", 8) == 0) { int ret; ret = i40e_aq_cfg_lldp_mib_change_event(&pf->hw, true, NULL); if (ret) { dev_info(&pf->pdev->dev, "Config LLDP MIB Change Event (on) AQ command failed =0x%x\n", pf->hw.aq.asq_last_status); goto command_write_done; } } else if (strncmp(&cmd_buf[5], "event off", 9) == 0) { int ret; ret = i40e_aq_cfg_lldp_mib_change_event(&pf->hw, false, NULL); if (ret) { dev_info(&pf->pdev->dev, "Config LLDP MIB Change Event (off) AQ command failed =0x%x\n", pf->hw.aq.asq_last_status); goto command_write_done; } } } else if (strncmp(cmd_buf, "nvm read", 8) == 0) { u16 buffer_len, bytes; u16 module; u32 offset; u16 *buff; int ret; cnt = sscanf(&cmd_buf[8], "%hx %x %hx", &module, &offset, &buffer_len); if (cnt == 0) { module = 0; offset = 0; buffer_len = 0; } else if (cnt == 1) { offset = 0; buffer_len = 0; } else if (cnt == 2) { buffer_len = 0; } else if (cnt > 3) { dev_info(&pf->pdev->dev, "nvm read: bad command string, cnt=%d\n", cnt); goto command_write_done; } /* set the max length */ buffer_len = min_t(u16, buffer_len, I40E_MAX_AQ_BUF_SIZE/2); bytes = 2 * buffer_len; /* read at least 1k bytes, no more than 4kB */ bytes = clamp(bytes, (u16)1024, (u16)I40E_MAX_AQ_BUF_SIZE); buff = kzalloc(bytes, GFP_KERNEL); if (!buff) goto command_write_done; ret = i40e_acquire_nvm(&pf->hw, I40E_RESOURCE_READ); if (ret) { dev_info(&pf->pdev->dev, "Failed Acquiring NVM resource for read err=%d status=0x%x\n", ret, pf->hw.aq.asq_last_status); kfree(buff); goto command_write_done; } ret = i40e_aq_read_nvm(&pf->hw, module, (2 * offset), bytes, (u8 *)buff, true, NULL); i40e_release_nvm(&pf->hw); if (ret) { dev_info(&pf->pdev->dev, "Read NVM AQ failed err=%d status=0x%x\n", ret, pf->hw.aq.asq_last_status); } else { dev_info(&pf->pdev->dev, "Read NVM module=0x%x offset=0x%x words=%d\n", module, offset, buffer_len); if (bytes) print_hex_dump(KERN_INFO, "NVM Dump: ", DUMP_PREFIX_OFFSET, 16, 2, buff, bytes, true); } kfree(buff); buff = NULL; } else { dev_info(&pf->pdev->dev, "unknown command '%s'\n", cmd_buf); dev_info(&pf->pdev->dev, "available commands\n"); dev_info(&pf->pdev->dev, " add vsi [relay_seid]\n"); dev_info(&pf->pdev->dev, " del vsi [vsi_seid]\n"); dev_info(&pf->pdev->dev, " add relay <uplink_seid> <vsi_seid>\n"); dev_info(&pf->pdev->dev, " del relay <relay_seid>\n"); dev_info(&pf->pdev->dev, " add macaddr <vsi_seid> <aa:bb:cc:dd:ee:ff> [vlan]\n"); dev_info(&pf->pdev->dev, " del macaddr <vsi_seid> <aa:bb:cc:dd:ee:ff> [vlan]\n"); dev_info(&pf->pdev->dev, " add pvid <vsi_seid> <vid>\n"); dev_info(&pf->pdev->dev, " del pvid <vsi_seid>\n"); dev_info(&pf->pdev->dev, " dump switch\n"); dev_info(&pf->pdev->dev, " dump vsi [seid]\n"); dev_info(&pf->pdev->dev, " dump desc tx <vsi_seid> <ring_id> [<desc_n>]\n"); dev_info(&pf->pdev->dev, " dump desc rx <vsi_seid> <ring_id> [<desc_n>]\n"); dev_info(&pf->pdev->dev, " dump desc aq\n"); dev_info(&pf->pdev->dev, " dump stats\n"); dev_info(&pf->pdev->dev, " dump reset stats\n"); dev_info(&pf->pdev->dev, " msg_enable [level]\n"); dev_info(&pf->pdev->dev, " read <reg>\n"); dev_info(&pf->pdev->dev, " write <reg> <value>\n"); dev_info(&pf->pdev->dev, " clear_stats vsi [seid]\n"); dev_info(&pf->pdev->dev, " clear_stats pf\n"); dev_info(&pf->pdev->dev, " pfr\n"); dev_info(&pf->pdev->dev, " corer\n"); dev_info(&pf->pdev->dev, " globr\n"); dev_info(&pf->pdev->dev, " send aq_cmd <flags> <opcode> <datalen> <retval> <cookie_h> <cookie_l> <param0> <param1> <param2> <param3>\n"); dev_info(&pf->pdev->dev, " send indirect aq_cmd <flags> <opcode> <datalen> <retval> <cookie_h> <cookie_l> <param0> <param1> <param2> <param3> <buffer_len>\n"); dev_info(&pf->pdev->dev, " add fd_filter <dest q_index> <flex_off> <pctype> <dest_vsi> <dest_ctl> <fd_status> <cnt_index> <fd_id> <packet_len> <packet>\n"); dev_info(&pf->pdev->dev, " rem fd_filter <dest q_index> <flex_off> <pctype> <dest_vsi> <dest_ctl> <fd_status> <cnt_index> <fd_id> <packet_len> <packet>\n"); dev_info(&pf->pdev->dev, " fd-atr off\n"); dev_info(&pf->pdev->dev, " fd-atr on\n"); dev_info(&pf->pdev->dev, " fd-sb off\n"); dev_info(&pf->pdev->dev, " fd-sb on\n"); dev_info(&pf->pdev->dev, " lldp start\n"); dev_info(&pf->pdev->dev, " lldp stop\n"); dev_info(&pf->pdev->dev, " lldp get local\n"); dev_info(&pf->pdev->dev, " lldp get remote\n"); dev_info(&pf->pdev->dev, " lldp event on\n"); dev_info(&pf->pdev->dev, " lldp event off\n"); dev_info(&pf->pdev->dev, " nvm read [module] [word_offset] [word_count]\n"); } command_write_done: kfree(cmd_buf); cmd_buf = NULL; return count; } static const struct file_operations i40e_dbg_command_fops = { .owner = THIS_MODULE, .open = simple_open, .read = i40e_dbg_command_read, .write = i40e_dbg_command_write, }; /************************************************************** * netdev_ops * The netdev_ops entry in debugfs is for giving the driver commands * to be executed from the netdev operations. **************************************************************/ static char i40e_dbg_netdev_ops_buf[256] = "hello world"; /** * i40e_dbg_netdev_ops - read for netdev_ops datum * @filp: the opened file * @buffer: where to write the data for the user to read * @count: the size of the user's buffer * @ppos: file position offset **/ static ssize_t i40e_dbg_netdev_ops_read(struct file *filp, char __user *buffer, size_t count, loff_t *ppos) { struct i40e_pf *pf = filp->private_data; int bytes_not_copied; int buf_size = 256; char *buf; int len; /* don't allow partal reads */ if (*ppos != 0) return 0; if (count < buf_size) return -ENOSPC; buf = kzalloc(buf_size, GFP_KERNEL); if (!buf) return -ENOSPC; len = snprintf(buf, buf_size, "%s: %s\n", pf->vsi[pf->lan_vsi]->netdev->name, i40e_dbg_netdev_ops_buf); bytes_not_copied = copy_to_user(buffer, buf, len); kfree(buf); if (bytes_not_copied < 0) return bytes_not_copied; *ppos = len; return len; } /** * i40e_dbg_netdev_ops_write - write into netdev_ops datum * @filp: the opened file * @buffer: where to find the user's data * @count: the length of the user's data * @ppos: file position offset **/ static ssize_t i40e_dbg_netdev_ops_write(struct file *filp, const char __user *buffer, size_t count, loff_t *ppos) { struct i40e_pf *pf = filp->private_data; int bytes_not_copied; struct i40e_vsi *vsi; char *buf_tmp; int vsi_seid; int i, cnt; /* don't allow partial writes */ if (*ppos != 0) return 0; if (count >= sizeof(i40e_dbg_netdev_ops_buf)) return -ENOSPC; memset(i40e_dbg_netdev_ops_buf, 0, sizeof(i40e_dbg_netdev_ops_buf)); bytes_not_copied = copy_from_user(i40e_dbg_netdev_ops_buf, buffer, count); if (bytes_not_copied < 0) return bytes_not_copied; else if (bytes_not_copied > 0) count -= bytes_not_copied; i40e_dbg_netdev_ops_buf[count] = '\0'; buf_tmp = strchr(i40e_dbg_netdev_ops_buf, '\n'); if (buf_tmp) { *buf_tmp = '\0'; count = buf_tmp - i40e_dbg_netdev_ops_buf + 1; } if (strncmp(i40e_dbg_netdev_ops_buf, "tx_timeout", 10) == 0) { cnt = sscanf(&i40e_dbg_netdev_ops_buf[11], "%i", &vsi_seid); if (cnt != 1) { dev_info(&pf->pdev->dev, "tx_timeout <vsi_seid>\n"); goto netdev_ops_write_done; } vsi = i40e_dbg_find_vsi(pf, vsi_seid); if (!vsi) { dev_info(&pf->pdev->dev, "tx_timeout: VSI %d not found\n", vsi_seid); } else if (!vsi->netdev) { dev_info(&pf->pdev->dev, "tx_timeout: no netdev for VSI %d\n", vsi_seid); } else if (test_bit(__I40E_DOWN, &vsi->state)) { dev_info(&pf->pdev->dev, "tx_timeout: VSI %d not UP\n", vsi_seid); } else if (rtnl_trylock()) { vsi->netdev->netdev_ops->ndo_tx_timeout(vsi->netdev); rtnl_unlock(); dev_info(&pf->pdev->dev, "tx_timeout called\n"); } else { dev_info(&pf->pdev->dev, "Could not acquire RTNL - please try again\n"); } } else if (strncmp(i40e_dbg_netdev_ops_buf, "change_mtu", 10) == 0) { int mtu; cnt = sscanf(&i40e_dbg_netdev_ops_buf[11], "%i %i", &vsi_seid, &mtu); if (cnt != 2) { dev_info(&pf->pdev->dev, "change_mtu <vsi_seid> <mtu>\n"); goto netdev_ops_write_done; } vsi = i40e_dbg_find_vsi(pf, vsi_seid); if (!vsi) { dev_info(&pf->pdev->dev, "change_mtu: VSI %d not found\n", vsi_seid); } else if (!vsi->netdev) { dev_info(&pf->pdev->dev, "change_mtu: no netdev for VSI %d\n", vsi_seid); } else if (rtnl_trylock()) { vsi->netdev->netdev_ops->ndo_change_mtu(vsi->netdev, mtu); rtnl_unlock(); dev_info(&pf->pdev->dev, "change_mtu called\n"); } else { dev_info(&pf->pdev->dev, "Could not acquire RTNL - please try again\n"); } } else if (strncmp(i40e_dbg_netdev_ops_buf, "set_rx_mode", 11) == 0) { cnt = sscanf(&i40e_dbg_netdev_ops_buf[11], "%i", &vsi_seid); if (cnt != 1) { dev_info(&pf->pdev->dev, "set_rx_mode <vsi_seid>\n"); goto netdev_ops_write_done; } vsi = i40e_dbg_find_vsi(pf, vsi_seid); if (!vsi) { dev_info(&pf->pdev->dev, "set_rx_mode: VSI %d not found\n", vsi_seid); } else if (!vsi->netdev) { dev_info(&pf->pdev->dev, "set_rx_mode: no netdev for VSI %d\n", vsi_seid); } else if (rtnl_trylock()) { vsi->netdev->netdev_ops->ndo_set_rx_mode(vsi->netdev); rtnl_unlock(); dev_info(&pf->pdev->dev, "set_rx_mode called\n"); } else { dev_info(&pf->pdev->dev, "Could not acquire RTNL - please try again\n"); } } else if (strncmp(i40e_dbg_netdev_ops_buf, "napi", 4) == 0) { cnt = sscanf(&i40e_dbg_netdev_ops_buf[4], "%i", &vsi_seid); if (cnt != 1) { dev_info(&pf->pdev->dev, "napi <vsi_seid>\n"); goto netdev_ops_write_done; } vsi = i40e_dbg_find_vsi(pf, vsi_seid); if (!vsi) { dev_info(&pf->pdev->dev, "napi: VSI %d not found\n", vsi_seid); } else if (!vsi->netdev) { dev_info(&pf->pdev->dev, "napi: no netdev for VSI %d\n", vsi_seid); } else { for (i = 0; i < vsi->num_q_vectors; i++) napi_schedule(&vsi->q_vectors[i]->napi); dev_info(&pf->pdev->dev, "napi called\n"); } } else { dev_info(&pf->pdev->dev, "unknown command '%s'\n", i40e_dbg_netdev_ops_buf); dev_info(&pf->pdev->dev, "available commands\n"); dev_info(&pf->pdev->dev, " tx_timeout <vsi_seid>\n"); dev_info(&pf->pdev->dev, " change_mtu <vsi_seid> <mtu>\n"); dev_info(&pf->pdev->dev, " set_rx_mode <vsi_seid>\n"); dev_info(&pf->pdev->dev, " napi <vsi_seid>\n"); } netdev_ops_write_done: return count; } static const struct file_operations i40e_dbg_netdev_ops_fops = { .owner = THIS_MODULE, .open = simple_open, .read = i40e_dbg_netdev_ops_read, .write = i40e_dbg_netdev_ops_write, }; /** * i40e_dbg_pf_init - setup the debugfs directory for the pf * @pf: the pf that is starting up **/ void i40e_dbg_pf_init(struct i40e_pf *pf) { struct dentry *pfile; const char *name = pci_name(pf->pdev); const struct device *dev = &pf->pdev->dev; pf->i40e_dbg_pf = debugfs_create_dir(name, i40e_dbg_root); if (!pf->i40e_dbg_pf) return; pfile = debugfs_create_file("command", 0600, pf->i40e_dbg_pf, pf, &i40e_dbg_command_fops); if (!pfile) goto create_failed; pfile = debugfs_create_file("dump", 0600, pf->i40e_dbg_pf, pf, &i40e_dbg_dump_fops); if (!pfile) goto create_failed; pfile = debugfs_create_file("netdev_ops", 0600, pf->i40e_dbg_pf, pf, &i40e_dbg_netdev_ops_fops); if (!pfile) goto create_failed; return; create_failed: dev_info(dev, "debugfs dir/file for %s failed\n", name); debugfs_remove_recursive(pf->i40e_dbg_pf); return; } /** * i40e_dbg_pf_exit - clear out the pf's debugfs entries * @pf: the pf that is stopping **/ void i40e_dbg_pf_exit(struct i40e_pf *pf) { debugfs_remove_recursive(pf->i40e_dbg_pf); pf->i40e_dbg_pf = NULL; kfree(i40e_dbg_dump_buf); i40e_dbg_dump_buf = NULL; } /** * i40e_dbg_init - start up debugfs for the driver **/ void i40e_dbg_init(void) { i40e_dbg_root = debugfs_create_dir(i40e_driver_name, NULL); if (!i40e_dbg_root) pr_info("init of debugfs failed\n"); } /** * i40e_dbg_exit - clean out the driver's debugfs entries **/ void i40e_dbg_exit(void) { debugfs_remove_recursive(i40e_dbg_root); i40e_dbg_root = NULL; } #endif /* CONFIG_DEBUG_FS */
the_stack_data/173577539.c
/* * refclock_arbiter - clock driver for Arbiter 1088A/B Satellite * Controlled Clock */ #ifdef HAVE_CONFIG_H #include <config.h> #endif #if defined(REFCLOCK) && defined(CLOCK_ARBITER) #include "ntpd.h" #include "ntp_io.h" #include "ntp_refclock.h" #include "ntp_stdlib.h" #include <stdio.h> #include <ctype.h> /* * This driver supports the Arbiter 1088A/B Satellite Controlled Clock. * The claimed accuracy of this clock is 100 ns relative to the PPS * output when receiving four or more satellites. * * The receiver should be configured before starting the NTP daemon, in * order to establish reliable position and operating conditions. It * does not initiate surveying or hold mode. For use with NTP, the * daylight savings time feature should be disables (D0 command) and the * broadcast mode set to operate in UTC (BU command). * * The timecode format supported by this driver is selected by the poll * sequence "B5", which initiates a line in the following format to be * repeated once per second until turned off by the "B0" poll sequence. * * Format B5 (24 ASCII printing characters): * * <cr><lf>i yy ddd hh:mm:ss.000bbb * * on-time = <cr> * i = synchronization flag (' ' = locked, '?' = unlocked) * yy = year of century * ddd = day of year * hh:mm:ss = hours, minutes, seconds * .000 = fraction of second (not used) * bbb = tailing spaces for fill * * The alarm condition is indicated by a '?' at i, which indicates the * receiver is not synchronized. In normal operation, a line consisting * of the timecode followed by the time quality character (TQ) followed * by the receiver status string (SR) is written to the clockstats file. * The time quality character is encoded in IEEE P1344 standard: * * Format TQ (IEEE P1344 estimated worst-case time quality) * * 0 clock locked, maximum accuracy * F clock failure, time not reliable * 4 clock unlocked, accuracy < 1 us * 5 clock unlocked, accuracy < 10 us * 6 clock unlocked, accuracy < 100 us * 7 clock unlocked, accuracy < 1 ms * 8 clock unlocked, accuracy < 10 ms * 9 clock unlocked, accuracy < 100 ms * A clock unlocked, accuracy < 1 s * B clock unlocked, accuracy < 10 s * * The status string is encoded as follows: * * Format SR (25 ASCII printing characters) * * V=vv S=ss T=t P=pdop E=ee * * vv = satellites visible * ss = relative signal strength * t = satellites tracked * pdop = position dilution of precision (meters) * ee = hardware errors * * If flag4 is set, an additional line consisting of the receiver * latitude (LA), longitude (LO) and elevation (LH) (meters) is written * to this file. If channel B is enabled for deviation mode and connected * to a 1-PPS signal, the last two numbers on the line are the deviation * and standard deviation averaged over the last 15 seconds. */ /* * Interface definitions */ #define DEVICE "/dev/gps%d" /* device name and unit */ #define SPEED232 B9600 /* uart speed (9600 baud) */ #define PRECISION (-20) /* precision assumed (about 1 us) */ #define REFID "GPS " /* reference ID */ #define DESCRIPTION "Arbiter 1088A/B GPS Receiver" /* WRU */ #define LENARB 24 /* format B5 timecode length */ #define MAXSTA 30 /* max length of status string */ #define MAXPOS 70 /* max length of position string */ /* * ARB unit control structure */ struct arbunit { l_fp laststamp; /* last receive timestamp */ int tcswitch; /* timecode switch/counter */ char qualchar; /* IEEE P1344 quality (TQ command) */ char status[MAXSTA]; /* receiver status (SR command) */ char latlon[MAXPOS]; /* receiver position (lat/lon/alt) */ }; /* * Function prototypes */ static int arb_start P((int, struct peer *)); static void arb_shutdown P((int, struct peer *)); static void arb_receive P((struct recvbuf *)); static void arb_poll P((int, struct peer *)); /* * Transfer vector */ struct refclock refclock_arbiter = { arb_start, /* start up driver */ arb_shutdown, /* shut down driver */ arb_poll, /* transmit poll message */ noentry, /* not used (old arb_control) */ noentry, /* initialize driver (not used) */ noentry, /* not used (old arb_buginfo) */ NOFLAGS /* not used */ }; /* * arb_start - open the devices and initialize data for processing */ static int arb_start( int unit, struct peer *peer ) { register struct arbunit *up; struct refclockproc *pp; int fd; char device[20]; /* * Open serial port. Use CLK line discipline, if available. */ (void)sprintf(device, DEVICE, unit); if (!(fd = refclock_open(device, SPEED232, LDISC_CLK))) return (0); /* * Allocate and initialize unit structure */ if (!(up = (struct arbunit *)emalloc(sizeof(struct arbunit)))) { (void) close(fd); return (0); } memset((char *)up, 0, sizeof(struct arbunit)); pp = peer->procptr; pp->io.clock_recv = arb_receive; pp->io.srcclock = (caddr_t)peer; pp->io.datalen = 0; pp->io.fd = fd; if (!io_addclock(&pp->io)) { (void) close(fd); free(up); return (0); } pp->unitptr = (caddr_t)up; /* * Initialize miscellaneous variables */ peer->precision = PRECISION; pp->clockdesc = DESCRIPTION; memcpy((char *)&pp->refid, REFID, 4); write(pp->io.fd, "B0", 2); return (1); } /* * arb_shutdown - shut down the clock */ static void arb_shutdown( int unit, struct peer *peer ) { register struct arbunit *up; struct refclockproc *pp; pp = peer->procptr; up = (struct arbunit *)pp->unitptr; io_closeclock(&pp->io); free(up); } /* * arb_receive - receive data from the serial interface */ static void arb_receive( struct recvbuf *rbufp ) { register struct arbunit *up; struct refclockproc *pp; struct peer *peer; l_fp trtmp; int temp; u_char syncchar; /* synchronization indicator */ /* * Initialize pointers and read the timecode and timestamp */ peer = (struct peer *)rbufp->recv_srcclock; pp = peer->procptr; up = (struct arbunit *)pp->unitptr; temp = refclock_gtlin(rbufp, pp->a_lastcode, BMAX, &trtmp); /* * Note we get a buffer and timestamp for both a <cr> and <lf>, * but only the <cr> timestamp is retained. The program first * sends a TQ and expects the echo followed by the time quality * character. It then sends a B5 starting the timecode broadcast * and expects the echo followed some time later by the on-time * character <cr> and then the <lf> beginning the timecode * itself. Finally, at the <cr> beginning the next timecode at * the next second, the program sends a B0 shutting down the * timecode broadcast. * * If flag4 is set, the program snatches the latitude, longitude * and elevation and writes it to the clockstats file. */ if (temp == 0) return; pp->lastrec = up->laststamp; up->laststamp = trtmp; if (temp < 3) return; if (up->tcswitch == 0) { /* * Collect statistics. If nothing is recogized, just * ignore; sometimes the clock doesn't stop spewing * timecodes for awhile after the B0 commant. */ if (!strncmp(pp->a_lastcode, "TQ", 2)) { up->qualchar = pp->a_lastcode[2]; write(pp->io.fd, "SR", 2); } else if (!strncmp(pp->a_lastcode, "SR", 2)) { strcpy(up->status, pp->a_lastcode + 2); if (pp->sloppyclockflag & CLK_FLAG4) write(pp->io.fd, "LA", 2); else { write(pp->io.fd, "B5", 2); up->tcswitch++; } } else if (!strncmp(pp->a_lastcode, "LA", 2)) { strcpy(up->latlon, pp->a_lastcode + 2); write(pp->io.fd, "LO", 2); } else if (!strncmp(pp->a_lastcode, "LO", 2)) { strcat(up->latlon, " "); strcat(up->latlon, pp->a_lastcode + 2); write(pp->io.fd, "LH", 2); } else if (!strncmp(pp->a_lastcode, "LH", 2)) { strcat(up->latlon, " "); strcat(up->latlon, pp->a_lastcode + 2); write(pp->io.fd, "DB", 2); } else if (!strncmp(pp->a_lastcode, "DB", 2)) { strcat(up->latlon, " "); strcat(up->latlon, pp->a_lastcode + 2); record_clock_stats(&peer->srcadr, up->latlon); write(pp->io.fd, "B5", 2); up->tcswitch++; } return; } pp->lencode = temp; /* * We get down to business, check the timecode format and decode * its contents. If the timecode has valid length, but not in * proper format, we declare bad format and exit. If the * timecode has invalid length, which sometimes occurs when the * B0 amputates the broadcast, we just quietly steal away. Note * that the time quality character and receiver status string is * tacked on the end for clockstats display. */ if (pp->lencode == LENARB) { /* * Timecode format B5: "i yy ddd hh:mm:ss.000 " */ pp->a_lastcode[LENARB - 2] = up->qualchar; strcat(pp->a_lastcode, up->status); syncchar = ' '; if (sscanf(pp->a_lastcode, "%c%2d %3d %2d:%2d:%2d", &syncchar, &pp->year, &pp->day, &pp->hour, &pp->minute, &pp->second) != 6) { refclock_report(peer, CEVNT_BADREPLY); write(pp->io.fd, "B0", 2); return; } } else { write(pp->io.fd, "B0", 2); return; } up->tcswitch++; /* * We decode the clock dispersion from the time quality * character. */ switch (up->qualchar) { case '0': /* locked, max accuracy */ pp->disp = 1e-7; break; case '4': /* unlock accuracy < 1 us */ pp->disp = 1e-6; break; case '5': /* unlock accuracy < 10 us */ pp->disp = 1e-5; break; case '6': /* unlock accuracy < 100 us */ pp->disp = 1e-4; break; case '7': /* unlock accuracy < 1 ms */ pp->disp = .001; break; case '8': /* unlock accuracy < 10 ms */ pp->disp = .01; break; case '9': /* unlock accuracy < 100 ms */ pp->disp = .1; break; case 'A': /* unlock accuracy < 1 s */ pp->disp = 1; break; case 'B': /* unlock accuracy < 10 s */ pp->disp = 10; break; case 'F': /* clock failure */ pp->disp = MAXDISPERSE; refclock_report(peer, CEVNT_FAULT); write(pp->io.fd, "B0", 2); return; default: pp->disp = MAXDISPERSE; refclock_report(peer, CEVNT_BADREPLY); write(pp->io.fd, "B0", 2); return; } if (syncchar != ' ') pp->leap = LEAP_NOTINSYNC; else pp->leap = LEAP_NOWARNING; #ifdef DEBUG if (debug) printf("arbiter: timecode %d %s\n", pp->lencode, pp->a_lastcode); #endif if (up->tcswitch >= NSTAGE) write(pp->io.fd, "B0", 2); /* * Process the new sample in the median filter and determine the * timecode timestamp. */ if (!refclock_process(pp)) refclock_report(peer, CEVNT_BADTIME); } /* * arb_poll - called by the transmit procedure */ static void arb_poll( int unit, struct peer *peer ) { register struct arbunit *up; struct refclockproc *pp; /* * Time to poll the clock. The Arbiter clock responds to a "B5" * by returning a timecode in the format specified above. * Transmission occurs once per second, unless turned off by a * "B0". Note there is no checking on state, since this may not * be the only customer reading the clock. Only one customer * need poll the clock; all others just listen in. If nothing is * heard from the clock for two polls, declare a timeout and * keep going. */ pp = peer->procptr; up = (struct arbunit *)pp->unitptr; up->tcswitch = 0; if (write(pp->io.fd, "TQ", 2) != 2) { refclock_report(peer, CEVNT_FAULT); } else pp->polls++; if (pp->coderecv == pp->codeproc) { refclock_report(peer, CEVNT_TIMEOUT); return; } record_clock_stats(&peer->srcadr, pp->a_lastcode); refclock_receive(peer); } #else int refclock_arbiter_bs; #endif /* REFCLOCK */
the_stack_data/1218725.c
/* Generated by CIL v. 1.7.0 */ /* print_CIL_Input is false */ struct _IO_FILE; struct timeval; extern void signal(int sig , void *func ) ; extern float strtof(char const *str , char const *endptr ) ; typedef struct _IO_FILE FILE; extern int atoi(char const *s ) ; extern double strtod(char const *str , char const *endptr ) ; extern int fclose(void *stream ) ; extern void *fopen(char const *filename , char const *mode ) ; extern void abort() ; extern void exit(int status ) ; extern int raise(int sig ) ; extern int fprintf(struct _IO_FILE *stream , char const *format , ...) ; extern int strcmp(char const *a , char const *b ) ; extern int rand() ; extern unsigned long strtoul(char const *str , char const *endptr , int base ) ; void RandomFunc(unsigned short input[1] , unsigned short output[1] ) ; extern int strncmp(char const *s1 , char const *s2 , unsigned long maxlen ) ; extern int gettimeofday(struct timeval *tv , void *tz , ...) ; extern int printf(char const *format , ...) ; int main(int argc , char *argv[] ) ; void megaInit(void) ; extern unsigned long strlen(char const *s ) ; extern long strtol(char const *str , char const *endptr , int base ) ; extern unsigned long strnlen(char const *s , unsigned long maxlen ) ; extern void *memcpy(void *s1 , void const *s2 , unsigned long size ) ; struct timeval { long tv_sec ; long tv_usec ; }; extern void *malloc(unsigned long size ) ; extern int scanf(char const *format , ...) ; int main(int argc , char *argv[] ) { unsigned short input[1] ; unsigned short output[1] ; int randomFuns_i5 ; unsigned short randomFuns_value6 ; int randomFuns_main_i7 ; { megaInit(); if (argc != 2) { printf("Call this program with %i arguments\n", 1); exit(-1); } else { } randomFuns_i5 = 0; while (randomFuns_i5 < 1) { randomFuns_value6 = (unsigned short )strtoul(argv[randomFuns_i5 + 1], 0, 10); input[randomFuns_i5] = randomFuns_value6; randomFuns_i5 ++; } RandomFunc(input, output); if (output[0] == 19924) { printf("You win!\n"); } else { } randomFuns_main_i7 = 0; while (randomFuns_main_i7 < 1) { printf("%u\n", output[randomFuns_main_i7]); randomFuns_main_i7 ++; } } } void megaInit(void) { { } } void RandomFunc(unsigned short input[1] , unsigned short output[1] ) { unsigned short state[1] ; unsigned short local2 ; unsigned short local1 ; { state[0UL] = (input[0UL] + 914778474UL) ^ (unsigned short)11; local1 = 0UL; while (local1 < input[1UL]) { local2 = 0UL; while (local2 < input[1UL]) { state[local2] |= (state[0UL] & (unsigned short)63) << 4UL; local2 += 2UL; } local1 ++; } output[0UL] = (state[0UL] >> (unsigned short)1) | (state[0UL] << (unsigned short)15); } }
the_stack_data/248581795.c
// Copyright (c) 2013 Google Inc. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. static void the_static_function() {} __attribute__((used)) void the_used_function() {} __attribute__((visibility("hidden"))) __attribute__((used)) void the_hidden_function() {} __attribute__((visibility("default"))) __attribute__((used)) void the_visible_function() {} void the_function() {} extern const int eci; __attribute__((used)) int i; __attribute__((used)) const int ci = 34623; int main() { the_function(); the_static_function(); the_used_function(); the_hidden_function(); the_visible_function(); }
the_stack_data/178266147.c
#include <stdio.h> long int fibonnaci(int n); int main(){ int n; printf("Input n: "); // n_max = 49 scanf("%d", &n); printf("Fibonnaci_n = %ld\n", fibonnaci(n)); return 0; } long int fibonnaci(int n){ int i, t1 = 0, t2 = 1, nextTerm = 0; for(i = 1; i <= n; ++i){ if (i == 1){ nextTerm = t1; continue; } if (i == 2){ nextTerm = t2; continue; } nextTerm = t1 + t2; t1 = t2; t2 = nextTerm; //printf("%d\n", nextTerm); } return nextTerm; }
the_stack_data/31387210.c
//file: _insn_test_st_Y2.c //op=206 #include <stdio.h> #include <stdlib.h> void func_exit(void) { printf("%s\n", __func__); exit(0); } void func_call(void) { printf("%s\n", __func__); exit(0); } unsigned long mem[2] = { 0xdf38a6238f47ee5b, 0x2c24dd020e9fa33f }; int main(void) { unsigned long a[4] = { 0, 0 }; asm __volatile__ ( "moveli r29, -2884\n" "shl16insli r29, r29, 28785\n" "shl16insli r29, r29, 7136\n" "shl16insli r29, r29, 32281\n" "moveli r6, -14930\n" "shl16insli r6, r6, -27555\n" "shl16insli r6, r6, -15233\n" "shl16insli r6, r6, -7776\n" "move r29, %2\n" "{ fnop ; fnop ; st r29, r6 }\n" "move %0, r29\n" "move %1, r6\n" :"=r"(a[0]),"=r"(a[1]) : "r"(mem)); printf("%016lx %016lx\n", mem[0], mem[1]); printf("%016lx\n", a[0]); printf("%016lx\n", a[1]); return 0; }
the_stack_data/184517167.c
#include <stdio.h> int main() { int n = 5, x = 1; for(int i = n; i >= 1; i--) { for(int j = 1; j <= i; j++) { printf("%2d ", x++); } printf("\n"); } return 0; }
the_stack_data/23574624.c
/********** * ZUCC Cprograming task * Author: Takuron@github **********/ #include <stdio.h> int main() { int sum = 0; char ch; while ((ch = getchar()) != '\n') if(ch >= '0' && ch <= '9') sum = sum * 10 + (ch - '0'); printf("%d\n", sum); return 0; }
the_stack_data/458580.c
/* Append an allocated pointer to a list of NULL pointers. Free every item in the list. Free the pointer again, causing a double free. */ #include <stdlib.h> #include <string.h> #define SZ 1000 struct T { char *array[SZ]; }; int main() { char *m; struct T a; int i; m = malloc(sizeof(char) * 1000); for (i = 0; i < SZ; i++) a.array[i] = NULL; memcpy(&a.array[SZ - 1], &m, sizeof(char *)); for (i = 0; i < SZ; i++) free(a.array[i]); free(m); return 0; }
the_stack_data/150143704.c
#include <stdlib.h> #include <stdio.h> #include <unistd.h> #include <string.h> #include <inttypes.h> int main(int argc, char **argv) { int ii; int needed; int sizealign; int nullfill; char *FileName; FILE *FileInput; // default FileName = ""; sizealign = 256; nullfill = 0; // parse parmeters for (ii=1; ii<argc; ii++) { if (!strcmp(argv[ii], "-sizealign")) { ii++; sizealign = strtoimax(argv[ii], NULL, 0); if (!sizealign) sizealign = 1; } else if (!strcmp(argv[ii], "-nullfill")) { ii++; nullfill = strtoimax(argv[ii], NULL, 0); } else if (!FileName[0]) FileName = argv[ii]; } FileInput = fopen(FileName, "rb"); if (!FileInput) { printf("Couldn't open input file %s\n", FileName); return 1; } else { // file exists, close and reopen for appending fclose(FileInput); FileInput = fopen(FileName, "ab"); } // go to end of file fseek(FileInput, 0, SEEK_END); // calculate how many extra byte are needed needed = ftell(FileInput) & (sizealign - 1); if (needed) { unsigned char *mem; // complete missing bytes needed = sizealign - needed; mem = malloc(needed); if (mem) { memset(mem, nullfill, needed); fwrite(mem, needed, 1, FileInput); free(mem); } else for (ii=0; ii<needed; ii++) fputc(nullfill, FileInput); } fclose(FileInput); return 0; }
the_stack_data/212643703.c
/* C program to check whether a number is prime or not. */ #include <stdio.h> int _divides (int n, int m) { return (m % n == 0); } int main() { int n, i, flag=0; printf("Enter a positive integer: "); scanf("%d",&n); for(i=2;i<=n/2;++i) { int d = _divides(i,n); if(d==0) { flag=1; //break; } } if (flag==0) printf("%d is a prime number.\n",n); else printf("%d is not a prime number.\n",n); return 0; }
the_stack_data/116351.c
#include <stdio.h> int decompose(unsigned int n) { unsigned int p = 2; while (n > p * p) { if ( n % p ) { p++; p|=1; } else { n /= p; // printf(" %d",p); } } // printf(" %d",n); } int main() { int i; for (i = 10000; i >= 0; i--) decompose(i); return 0; }
the_stack_data/131417.c
#include<stdio.h> int main() { int c, nl, nt, ns; nl = 0; nt = 0; ns = 0; while ((c = getchar()) != EOF) { if (c == '\n') ++nl; if (c == '\t') ++nt; if (c == ' ') ++ns; } printf("Blanks: %d\nTabs: %d\nNewlines: %d\n", ns, nt, nl); }
the_stack_data/157951696.c
#include <stdio.h> int main() { printf(" 1 == 1 : %s\n", 1 == 1 ? "true" : "false"); printf(" 1 != 1 : %s\n", 1 != 1 ? "true" : "false"); printf(" 5 < 10 : %s\n", 5 < 10 ? "true" : "false"); printf(" 5 > 10 : %s\n", 5 > 10 ? "true" : "false"); printf("12 <= 10 : %s\n", 12 <= 10 ? "true" : "false"); printf("12 >= 10 : %s\n", 12 >= 10 ? "true" : "false"); }
the_stack_data/218894126.c
/* See the "Run-time ABI for the ARM Architecture", Section 4.2 */ #include <assert.h> typedef unsigned int uint32_t; long long __aeabi_llsl(long long value, int shift) { uint32_t low = (uint32_t)value << shift; /* "Shift behavior is undefined if the right operand is negative, or greater * than or equal to the length in bits of the promoted left operand" according * to C++ spec. However, arm compiler fill the vacated bits with 0 */ assert(shift < 32 || low == 0); uint32_t high = ((uint32_t)(value >> 32) << shift); // Same comment assert(shift < 32 || high == 0); if (shift < 32) { high |= ((uint32_t)value >> (32 - shift)); } else { high |= ((uint32_t)value << (shift - 32)); } return ((long long)high << 32) | low; }
the_stack_data/179831277.c
#include <stdio.h> #include <string.h> // Given two strings, check if the second is a rotation of the first // E.g., "tca" is a rotation of "cat" int main(int argc, char *argv[]) { if (argc == 1) { printf("No arguments passed"); return 1; } else if (argc < 3) { printf("This program requires two arguments"); return 1; } else if (argc >= 4) { printf("This program only accepts two arguments"); return 1; } char *first_str = argv[1]; char *second_str = argv[2]; if (strlen(first_str) != strlen(second_str)) { printf("Both arguments must be of the same length"); return 1; } int len = strlen(first_str); char permutations[len][len]; int current_char; for (int i = 0; i < len; i++) { current_char = i; for (int j = 0; j < len; j++) { if (current_char > len -1) current_char = 0; permutations[i][j] = first_str[current_char]; current_char++; } } int is_rotation; for (int i = 0; i < len; i++) { for (int j = 0; j < len; j++) { if (second_str[j] == permutations[i][j]) { is_rotation = 1; } else { is_rotation = 0; break; } } if (is_rotation) { printf("%s is a rotation of %s", second_str, first_str); return 0; } } printf("%s is not a rotation of %s", second_str, first_str); return 1; }
the_stack_data/75332.c
/* 2020-5-19 14点47分 通过使用函数fdopen将文件描述符转换为FILE结构体指针 */ #include <stdio.h> #include <fcntl.h> int main() { FILE *fp; int fd = open("data.txt", O_WRONLY|O_CREAT|O_TRUNC); if (-1 == fd) { fputs("文件打开失败",stderr); return -1; } fp = fdopen(fd,"w"); fputs("JamesWu9527 \n",fp); fclose(fp); //这里的文件指针通过fclose关闭后,fd文件描述符将变成一个没有意义的整型变量 return 0; }
the_stack_data/52474.c
#ifndef lint // static char sccsid[] = "@(#)grep.c 4.6 (Berkeley) 5/14/84"; #endif /* * grep -- print lines matching (or not matching) a pattern * * status returns: * 0 - ok, and some matches * 1 - ok, but no matches * 2 - some error */ #include <stdio.h> #include <ctype.h> #include <stdlib.h> #include <unistd.h> #define CBRA 1 #define CCHR 2 #define CDOT 4 #define CCL 6 #define NCCL 8 #define CDOL 10 #define CEOF 11 #define CKET 12 #define CBRC 14 #define CLET 15 #define CBACK 18 #define STAR 01 #define LBSIZE BUFSIZ #define ESIZE 256 #define NBRA 9 char expbuf[ESIZE]; long lnum; char linebuf[LBSIZE+1]; char ybuf[ESIZE]; int bflag; int lflag; int nflag; int cflag; int vflag; int nfile; int hflag = 1; int sflag; int yflag; int wflag; int retcode = 0; int circf; int blkno; long tln; int nsucc; char *braslist[NBRA]; char *braelist[NBRA]; char bittab[] = { 1, 2, 4, 8, 16, 32, 64, 128 }; void compile(char *astr); void execute(char *file); int advance(char *lp, char *ep); void succeed(char *f); int ecmp(char *a, char *b, int count); void errexit(char *s, char *f); int main(int argc, char **argv) { while (--argc > 0 && (++argv)[0][0]=='-') switch (argv[0][1]) { case 'i': case 'y': yflag++; continue; case 'w': wflag++; continue; case 'h': hflag = 0; continue; case 's': sflag++; continue; case 'v': vflag++; continue; case 'b': bflag++; continue; case 'l': lflag++; continue; case 'c': cflag++; continue; case 'n': nflag++; continue; case 'e': --argc; ++argv; goto out; default: errexit("grep: unknown flag\n", (char *)NULL); continue; } out: if (argc<=0) exit(2); if (yflag) { register char *p, *s; for (s = ybuf, p = *argv; *p; ) { if (*p == '\\') { *s++ = *p++; if (*p) *s++ = *p++; } else if (*p == '[') { while (*p != '\0' && *p != ']') *s++ = *p++; } else if (islower(*p)) { *s++ = '['; *s++ = toupper(*p); *s++ = *p++; *s++ = ']'; } else *s++ = *p++; if (s >= ybuf+ESIZE-5) errexit("grep: argument too long\n", (char *)NULL); } *s = '\0'; *argv = ybuf; } compile(*argv); nfile = --argc; if (argc<=0) { if (lflag) exit(1); execute((char *)NULL); } else while (--argc >= 0) { argv++; execute(*argv); } exit(retcode != 0 ? retcode : nsucc == 0); } void compile(char *astr) { register int c; register char *ep, *sp; char *cstart; char *lastep; int cclcnt; char bracket[NBRA], *bracketp; int closed; char numbra; char neg; ep = expbuf; sp = astr; lastep = 0; bracketp = bracket; closed = numbra = 0; if (*sp == '^') { circf++; sp++; } if (wflag) *ep++ = CBRC; for (;;) { if (ep >= &expbuf[ESIZE]) goto cerror; if ((c = *sp++) != '*') lastep = ep; switch (c) { case '\0': if (wflag) *ep++ = CLET; *ep++ = CEOF; return; case '.': *ep++ = CDOT; continue; case '*': if (lastep==0 || *lastep==CBRA || *lastep==CKET || *lastep == CBRC || *lastep == CLET) goto defchar; *lastep |= STAR; continue; case '$': if (*sp != '\0') goto defchar; *ep++ = CDOL; continue; case '[': if(&ep[17] >= &expbuf[ESIZE]) goto cerror; *ep++ = CCL; neg = 0; if((c = *sp++) == '^') { neg = 1; c = *sp++; } cstart = sp; do { if (c=='\0') goto cerror; if (c=='-' && sp>cstart && *sp!=']') { for (c = sp[-2]; c<*sp; c++) ep[c>>3] |= bittab[c&07]; sp++; } ep[c>>3] |= bittab[c&07]; } while((c = *sp++) != ']'); if(neg) { for(cclcnt = 0; cclcnt < 16; cclcnt++) ep[cclcnt] ^= -1; ep[0] &= 0376; } ep += 16; continue; case '\\': if((c = *sp++) == 0) goto cerror; if(c == '<') { *ep++ = CBRC; continue; } if(c == '>') { *ep++ = CLET; continue; } if(c == '(') { if(numbra >= NBRA) { goto cerror; } *bracketp++ = numbra; *ep++ = CBRA; *ep++ = numbra++; continue; } if(c == ')') { if(bracketp <= bracket) { goto cerror; } *ep++ = CKET; *ep++ = *--bracketp; closed++; continue; } if(c >= '1' && c <= '9') { if((c -= '1') >= closed) goto cerror; *ep++ = CBACK; *ep++ = c; continue; } defchar: default: *ep++ = CCHR; *ep++ = c; } } cerror: errexit("grep: RE error\n", (char *)NULL); } void execute(char *file) { register char *p1, *p2; register int c; if (file) { if (freopen(file, "r", stdin) == NULL) { perror(file); retcode = 2; } } lnum = 0; tln = 0; for (;;) { lnum++; p1 = linebuf; while ((c = getchar()) != '\n') { if (c == EOF) { if (cflag) { if (nfile>1) printf("%s:", file); printf("%D\n", tln); fflush(stdout); } return; } *p1++ = c; if (p1 >= &linebuf[LBSIZE-1]) break; } *p1++ = '\0'; p1 = linebuf; p2 = expbuf; if (circf) { if (advance(p1, p2)) goto found; goto nfound; } /* fast check for first character */ if (*p2==CCHR) { c = p2[1]; do { if (*p1!=c) continue; if (advance(p1, p2)) goto found; } while (*p1++); goto nfound; } /* regular algorithm */ do { if (advance(p1, p2)) goto found; } while (*p1++); nfound: if (vflag) succeed(file); continue; found: if (vflag==0) succeed(file); } } int advance(char *lp, char *ep) { register char *curlp; char c; char *bbeg; int ct; for (;;) switch (*ep++) { case CCHR: if (*ep++ == *lp++) continue; return(0); case CDOT: if (*lp++) continue; return(0); case CDOL: if (*lp==0) continue; return(0); case CEOF: return(1); case CCL: c = *lp++ & 0177; if(ep[c>>3] & bittab[(int)c & 07]) { ep += 16; continue; } return(0); case CBRA: braslist[(int)*ep++] = lp; continue; case CKET: braelist[(int)*ep++] = lp; continue; case CBACK: bbeg = braslist[(int)*ep]; if (braelist[(int)*ep]==0) return(0); ct = braelist[(int)*ep++] - bbeg; if(ecmp(bbeg, lp, ct)) { lp += ct; continue; } return(0); case CBACK|STAR: bbeg = braslist[(int)*ep]; if (braelist[(int)*ep]==0) return(0); ct = braelist[(int)*ep++] - bbeg; curlp = lp; while(ecmp(bbeg, lp, ct)) lp += ct; while(lp >= curlp) { if(advance(lp, ep)) return(1); lp -= ct; } return(0); case CDOT|STAR: curlp = lp; while (*lp++); goto star; case CCHR|STAR: curlp = lp; while (*lp++ == *ep); ep++; goto star; case CCL|STAR: curlp = lp; do { c = *lp++ & 0177; } while(ep[(int)c>>3] & bittab[c & 07]); ep += 16; goto star; star: if(--lp == curlp) { continue; } if(*ep == CCHR) { c = ep[1]; do { if(*lp != c) continue; if(advance(lp, ep)) return(1); } while(lp-- > curlp); return(0); } do { if (advance(lp, ep)) return(1); } while (lp-- > curlp); return(0); case CBRC: if (lp == expbuf) continue; #define uletter(c) (isalpha(c) || (c) == '_') if (uletter(*lp) || isdigit(*lp)) if (!uletter(lp[-1]) && !isdigit(lp[-1])) continue; return (0); case CLET: if (!uletter(*lp) && !isdigit(*lp)) continue; return (0); default: errexit("grep RE botch\n", (char *)NULL); } return(0); } void succeed(char *f) { nsucc = 1; if (sflag) return; if (cflag) { tln++; return; } if (lflag) { printf("%s\n", f); fflush(stdout); fseek(stdin, 0l, 2); return; } if (nfile > 1 && hflag) printf("%s:", f); if (bflag) printf("%u:", blkno); if (nflag) printf("%ld:", lnum); printf("%s\n", linebuf); fflush(stdout); } int ecmp(char *a, char *b, int count) { register int cc = count; while(cc--) if(*a++ != *b++) return(0); return(1); } void errexit(char *s, char *f) { fprintf(stderr, s, f); exit(2); }
the_stack_data/672188.c
/* vi: set sw=4 ts=4: */ /* daemon implementation for uClibc * * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * 3. <BSD Advertising Clause omitted per the July 22, 1999 licensing change * ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change> * * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ /* * Copyright (C) 2000-2006 Erik Andersen <[email protected]> * * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. * Modified for uClibc by Erik Andersen <[email protected]> */ #include <stdio.h> #include <features.h> #include <fcntl.h> #include <paths.h> #include <unistd.h> #if defined __USE_BSD || (defined __USE_XOPEN && !defined __USE_UNIX98) libc_hidden_proto(open) libc_hidden_proto(close) libc_hidden_proto(_exit) libc_hidden_proto(dup2) libc_hidden_proto(setsid) libc_hidden_proto(chdir) libc_hidden_proto(fork) int daemon( int nochdir, int noclose ) { int fd; switch (fork()) { case -1: return(-1); case 0: break; default: _exit(0); } if (setsid() == -1) return(-1); /* Make certain we are not a session leader, or else we * might reacquire a controlling terminal */ if (fork()) _exit(0); if (!nochdir) chdir("/"); if (!noclose && (fd = open(_PATH_DEVNULL, O_RDWR, 0)) != -1) { dup2(fd, STDIN_FILENO); dup2(fd, STDOUT_FILENO); dup2(fd, STDERR_FILENO); if (fd > 2) close(fd); } return(0); } #endif
the_stack_data/6388823.c
// RUN: rm -rf %t* // RUN: 3c -base-dir=%S -addcr -alltypes -output-dir=%t.checkedALL2 %S/unsafefptrargsafemulti1.c %s -- // RUN: 3c -base-dir=%S -addcr -output-dir=%t.checkedNOALL2 %S/unsafefptrargsafemulti1.c %s -- // RUN: %clang -working-directory=%t.checkedNOALL2 -c unsafefptrargsafemulti1.c unsafefptrargsafemulti2.c // RUN: FileCheck -match-full-lines -check-prefixes="CHECK_NOALL","CHECK" --input-file %t.checkedNOALL2/unsafefptrargsafemulti2.c %s // RUN: FileCheck -match-full-lines -check-prefixes="CHECK_ALL","CHECK" --input-file %t.checkedALL2/unsafefptrargsafemulti2.c %s // RUN: 3c -base-dir=%S -alltypes -output-dir=%t.checked %S/unsafefptrargsafemulti1.c %s -- // RUN: 3c -base-dir=%t.checked -alltypes -output-dir=%t.convert_again %t.checked/unsafefptrargsafemulti1.c %t.checked/unsafefptrargsafemulti2.c -- // RUN: test ! -f %t.convert_again/unsafefptrargsafemulti1.c // RUN: test ! -f %t.convert_again/unsafefptrargsafemulti2.c /******************************************************************************/ /*This file tests three functions: two callers bar and foo, and a callee sus*/ /*In particular, this file tests: passing a function pointer as an argument to a function unsafely (by casting it unsafely)*/ /*For robustness, this test is identical to unsafefptrargprotosafe.c and unsafefptrargsafe.c except in that the callee and callers are split amongst two files to see how the tool performs conversions*/ /*In this test, foo, bar, and sus will all treat their return values safely*/ /******************************************************************************/ #include <stddef.h> #include <stdlib.h> #include <stdio.h> #include <string.h> struct general { int data; struct general *next; //CHECK: _Ptr<struct general> next; }; struct warr { int data1[5]; //CHECK_NOALL: int data1[5]; //CHECK_ALL: int data1 _Checked[5]; char *name; //CHECK: _Ptr<char> name; }; struct fptrarr { int *values; //CHECK: _Ptr<int> values; char *name; //CHECK: _Ptr<char> name; int (*mapper)(int); //CHECK: _Ptr<int (int)> mapper; }; struct fptr { int *value; //CHECK: _Ptr<int> value; int (*func)(int); //CHECK: _Ptr<int (int)> func; }; struct arrfptr { int args[5]; //CHECK_NOALL: int args[5]; //CHECK_ALL: int args _Checked[5]; int (*funcs[5])(int); //CHECK_NOALL: int (*funcs[5])(int); //CHECK_ALL: _Ptr<int (int)> funcs _Checked[5]; }; static int add1(int x) { //CHECK: static int add1(int x) _Checked { return x + 1; } static int sub1(int x) { //CHECK: static int sub1(int x) _Checked { return x - 1; } static int fact(int n) { //CHECK: static int fact(int n) _Checked { if (n == 0) { return 1; } return n * fact(n - 1); } static int fib(int n) { //CHECK: static int fib(int n) _Checked { if (n == 0) { return 0; } if (n == 1) { return 1; } return fib(n - 1) + fib(n - 2); } static int zerohuh(int n) { //CHECK: static int zerohuh(int n) _Checked { return !n; } static int *mul2(int *x) { //CHECK: static _Ptr<int> mul2(_Ptr<int> x) _Checked { *x *= 2; return x; } int *sus(int (*x)(int), int (*y)(int)) { //CHECK_NOALL: int *sus(int (*x)(int), _Ptr<int (int)> y) : itype(_Ptr<int>) { //CHECK_ALL: _Array_ptr<int> sus(int (*x)(int), _Ptr<int (int)> y) : count(5) { x = (int (*)(int))5; //CHECK: x = (int (*)(int))5; int *z = calloc(5, sizeof(int)); //CHECK_NOALL: int *z = calloc<int>(5, sizeof(int)); //CHECK_ALL: _Array_ptr<int> z : count(5) = calloc<int>(5, sizeof(int)); int i; for (i = 0; i < 5; i++) { //CHECK_NOALL: for (i = 0; i < 5; i++) { //CHECK_ALL: for (i = 0; i < 5; i++) _Checked { z[i] = y(i); } return z; }
the_stack_data/68888370.c
#include <stdio.h> #define HEIGHT 17 int main(void) { int i = 0; printf("\n\nCCCCCCCCCCCCCCCCCCCCCCCCCC\n"); printf("CCCCCCCCCCCCCCCCCCCCCCCCCC\n"); while(i < HEIGHT) { printf("CCC\n"); i=i+1; } printf("CCCCCCCCCCCCCCCCCCCCCCCCCC\n"); printf("CCCCCCCCCCCCCCCCCCCCCCCCCC\n\n\n"); return(0); }
the_stack_data/150140894.c
/* * arrow_access.c -- program accesses structure members using arrow operator */ #include <stdio.h> typedef struct student { char srollno[10]; char sclass[10]; char name[25]; char fname[25]; char mname[25]; char add[200]; } Student; void arrow_access(Student const *); /* prototype */ int main(void) { Student a = {"35M2K14", "cs", "Christine", "James", "Hayek", "Post Box 1234, Park Avenue, UK"}; printf("Student a Information:\n"); arrow_access(&a); return 0; } void arrow_access(Student const *stu) /* 'stu' is a pointer-to-Student */ { /* Let's access members of 'a' using arrow operator */ printf("roll no.: %s\n", stu->srollno); printf("class: %s\n", stu->sclass); printf("name: %s\n", stu->name); printf("father's name: %s\n", stu->fname); printf("mother's name: %s\n", stu->mname); printf("And address: %s\n", stu->add); }
the_stack_data/220455055.c
#include <string.h> #include <stdlib.h> #include <assert.h> #include <stdio.h> #include <limits.h> #include <ctype.h> #include <setjmp.h> #define TRUE 1 #define FALSE 0 typedef unsigned char uint8_t; typedef short int16_t; #define ARRAY(T) struct {\ int16_t size;\ int16_t capacity;\ T *data;\ } * #define ARRAY_CREATE(array, init_capacity, init_size) {\ array = malloc(sizeof(*array)); \ array->data = malloc((init_capacity) * sizeof(*array->data)); \ assert(array->data != NULL); \ array->capacity = init_capacity; \ array->size = init_size; \ } #define ARRAY_PUSH(array, item) {\ if (array->size == array->capacity) { \ array->capacity *= 2; \ array->data = realloc(array->data, array->capacity * sizeof(*array->data)); \ assert(array->data != NULL); \ } \ array->data[array->size++] = item; \ } #define ARRAY_INSERT(array, pos, item) {\ ARRAY_PUSH(array, item); \ if (pos < array->size - 1) {\ memmove(&(array->data[(pos) + 1]), &(array->data[pos]), (array->size - (pos) - 1) * sizeof(*array->data)); \ array->data[pos] = item; \ } \ } int16_t dict_find_pos(const char ** keys, int16_t keys_size, const char * key) { int16_t low = 0; int16_t high = keys_size - 1; if (keys_size == 0 || key == NULL) return -1; while (low <= high) { int mid = (low + high) / 2; int res = strcmp(keys[mid], key); if (res == 0) return mid; else if (res < 0) low = mid + 1; else high = mid - 1; } return -1 - low; } #define DICT_CREATE(dict, init_capacity) { \ dict = malloc(sizeof(*dict)); \ ARRAY_CREATE(dict->index, init_capacity, 0); \ ARRAY_CREATE(dict->values, init_capacity, 0); \ } int16_t tmp_dict_pos; #define DICT_GET(dict, prop, default) ((tmp_dict_pos = dict_find_pos(dict->index->data, dict->index->size, prop)) < 0 ? default : dict->values->data[tmp_dict_pos]) int16_t tmp_dict_pos2; #define DICT_SET(dict, prop, value) { \ tmp_dict_pos2 = dict_find_pos(dict->index->data, dict->index->size, prop); \ if (tmp_dict_pos2 < 0) { \ tmp_dict_pos2 = -tmp_dict_pos2 - 1; \ ARRAY_INSERT(dict->index, tmp_dict_pos2, prop); \ ARRAY_INSERT(dict->values, tmp_dict_pos2, value); \ } else \ dict->values->data[tmp_dict_pos2] = value; \ } #define STR_INT16_T_BUFLEN ((CHAR_BIT * sizeof(int16_t) - 1) / 3 + 2) enum js_var_type {JS_VAR_NULL, JS_VAR_UNDEFINED, JS_VAR_NAN, JS_VAR_BOOL, JS_VAR_INT16, JS_VAR_STRING, JS_VAR_ARRAY, JS_VAR_DICT}; struct js_var { enum js_var_type type; int16_t number; void *data; }; struct array_js_var_t { int16_t size; int16_t capacity; struct js_var *data; }; struct array_string_t { int16_t size; int16_t capacity; const char ** data; }; struct dict_js_var_t { struct array_string_t *index; struct array_js_var_t *values; }; struct js_var js_var_from(enum js_var_type type) { struct js_var v; v.type = type; v.data = NULL; return v; } struct js_var js_var_from_int16_t(int16_t n) { struct js_var v; v.type = JS_VAR_INT16; v.number = n; v.data = NULL; return v; } struct js_var js_var_from_str(const char *s) { struct js_var v; v.type = JS_VAR_STRING; v.data = (void *)s; return v; } struct js_var js_var_from_array(struct array_js_var_t *arr) { struct js_var v; v.type = JS_VAR_ARRAY; v.data = (void *)arr; return v; } struct js_var js_var_from_dict(struct dict_js_var_t *dict) { struct js_var v; v.type = JS_VAR_DICT; v.data = (void *)dict; return v; } struct js_var str_to_int16_t(const char * str) { struct js_var v; const char *p = str; int r; v.data = NULL; while (*p && isspace(*p)) p++; if (*p == 0) str = "0"; if (*p == '-' && *(p+1)) p++; while (*p) { if (!isdigit(*p)) { v.type = JS_VAR_NAN; return v; } p++; } sscanf(str, "%d", &r); v.type = JS_VAR_INT16; v.number = (int16_t)r; return v; } const char * js_var_to_str(struct js_var v, uint8_t *need_dispose) { char *buf; int16_t i; *need_dispose = 0; if (v.type == JS_VAR_INT16) { buf = malloc(STR_INT16_T_BUFLEN); assert(buf != NULL); *need_dispose = 1; sprintf(buf, "%d", v.number); return buf; } else if (v.type == JS_VAR_BOOL) return v.number ? "true" : "false"; else if (v.type == JS_VAR_STRING) return (const char *)v.data; else if (v.type == JS_VAR_ARRAY) { struct array_js_var_t * arr = (struct array_js_var_t *)v.data; uint8_t dispose_elem = 0; buf = malloc(1); assert(buf != NULL); *need_dispose = 1; buf[0] = 0; for (i = 0; i < arr->size; i++) { const char * elem = js_var_to_str(arr->data[i], &dispose_elem); buf = realloc(buf, strlen(buf) + strlen(elem) + 1 + (i != 0 ? 1 : 0)); assert(buf != NULL); if (i != 0) strcat(buf, ","); strcat(buf, elem); if (dispose_elem) free((void *)elem); } return buf; } else if (v.type == JS_VAR_DICT) return "[object Object]"; else if (v.type == JS_VAR_NAN) return "NaN"; else if (v.type == JS_VAR_NULL) return "null"; else if (v.type == JS_VAR_UNDEFINED) return "undefined"; return NULL; } struct js_var js_var_to_number(struct js_var v) { struct js_var result; result.type = JS_VAR_INT16; result.number = 0; if (v.type == JS_VAR_INT16) result.number = v.number; else if (v.type == JS_VAR_BOOL) result.number = v.number; else if (v.type == JS_VAR_STRING) return str_to_int16_t((const char *)v.data); else if (v.type == JS_VAR_ARRAY) { struct array_js_var_t * arr = (struct array_js_var_t *)v.data; if (arr->size == 0) result.number = 0; else if (arr->size > 1) result.type = JS_VAR_NAN; else result = js_var_to_number(arr->data[0]); } else if (v.type != JS_VAR_NULL) result.type = JS_VAR_NAN; return result; } uint8_t js_var_to_bool(struct js_var v) { if (v.type == JS_VAR_INT16) return v.number != 0; else if (v.type == JS_VAR_BOOL) return v.number; else if (v.type == JS_VAR_STRING) return *((const char *)v.data) != 0; else if (v.type == JS_VAR_NULL || v.type == JS_VAR_UNDEFINED || v.type == JS_VAR_NAN) return FALSE; else return TRUE; } int err_i = 0; jmp_buf err_jmp[10]; #define TRY { int err_val = setjmp(err_jmp[err_i++]); if (!err_val) { #define CATCH } else { #define THROW(x) longjmp(err_jmp[--err_i], x) struct array_string_t * err_defs; #define END_TRY err_defs->size--; } } struct js_var js_var_get(struct js_var v, struct js_var arg) { struct js_var tmp; const char *key; uint8_t need_dispose = 0; if (v.type == JS_VAR_ARRAY) { tmp = js_var_to_number(arg); if (tmp.type == JS_VAR_NAN) return js_var_from(JS_VAR_UNDEFINED); else return ((struct array_js_var_t *)v.data)->data[tmp.number]; } else if (v.type == JS_VAR_DICT) { key = js_var_to_str(arg, &need_dispose); tmp = DICT_GET(((struct dict_js_var_t *)v.data), key, js_var_from(JS_VAR_UNDEFINED)); if (need_dispose) free((void *)key); return tmp; } else if (v.type == JS_VAR_NULL || v.type == JS_VAR_UNDEFINED) { ARRAY_PUSH(err_defs, "TypeError: Cannot read property of null or undefined."); THROW(err_defs->size); } else return js_var_from(JS_VAR_UNDEFINED); } static struct js_var x; static struct js_var y; static struct array_js_var_t * tmp_array = NULL; static const char * tmp_str; static uint8_t tmp_need_dispose; struct array_js_var_t * tmp_array_2 = NULL; int main(void) { ARRAY_CREATE(err_defs, 2, 0); x = js_var_from_int16_t(0); ARRAY_CREATE(tmp_array, 2, 1); tmp_array->data[0] = js_var_from_int16_t(5); y = js_var_from_array(tmp_array); printf("%s\n", tmp_str = js_var_to_str(x, &tmp_need_dispose)); if (tmp_need_dispose) free((void *)tmp_str); printf("%s\n", tmp_str = js_var_to_str(js_var_to_number(y), &tmp_need_dispose)); if (tmp_need_dispose) free((void *)tmp_str); x = js_var_get(y, x); if (js_var_to_bool(x)) { ARRAY_CREATE(tmp_array_2, 4, 4); tmp_array_2->data[0] = js_var_from_int16_t(1); tmp_array_2->data[1] = js_var_from_int16_t(2); tmp_array_2->data[2] = js_var_from_int16_t(3); tmp_array_2->data[3] = x; x = js_var_from_array(tmp_array_2); } printf("%s\n", tmp_str = js_var_to_str(x, &tmp_need_dispose)); if (tmp_need_dispose) free((void *)tmp_str); y = js_var_from_str("hello"); printf("%s\n", tmp_str = js_var_to_str(y, &tmp_need_dispose)); if (tmp_need_dispose) free((void *)tmp_str); free(tmp_array->data); free(tmp_array); free(tmp_array_2->data); free(tmp_array_2); return 0; }
the_stack_data/161080236.c
#include <stdio.h> #include <unistd.h> #include <string.h> int main(int argc, char *argv[]) { int ret = -1; if(argc != 2){ printf("mkdir: no argument support!\n"); }else{ if(rmdir(argv[1]) == 0){ //printf("rmdir: remove %s success.\n", argv[1]); ret = 0; }else{ printf("rmdir: remove %s faild!\n", argv[1]); } } return ret; }
the_stack_data/654546.c
/* LOCALIZE_DECLARATION should deal with structures Loop index should be declared outside of the loop, not inside... :-) */ #include <stdlib.h> #include <stdio.h> #include <math.h> #define N 256 #define M 256 #define N 64 #define M 64 #define SIGIMA 1.0 #define PI M_PI #define ZERO 1.0e-37 typedef struct { float re; float im; } complex; complex imagein[N][N], imageout[M][M]; void getimage(char *filename) { double z,amp,sum,squares; int i,j,conj,nx,ny; unsigned char c; FILE *fp; /* Erase the memory, in case the image is not big enough: */ for(i=0;i<N;i++) for(j=0;j<N;j++) { imagein[i][j].re=0.0; imagein[i][j].im=0.0; } }
the_stack_data/95674.c
struct s { char :2; char f:3; }; int foo(struct s s, int a) { s.f = a; return s.f; } /* * check-name: bitfield-store-load signed * check-command: test-linearize -Wno-decl $file * * check-output-ignore * check-output-excludes: shl\\. * check-output-excludes: lsr\\. * check-output-excludes: or\\. * check-output-excludes: [sz]ext\\. * check-output-excludes: trunc\\. * check-output-pattern(1): and\\. */
the_stack_data/117328664.c
/* Author: ph-u Script: 02_4.c Desc: variable types impact Input: clang 02_4.c -o 02_4;./02_4 Output: terminal output Arguments: 2 Date: Dec 2019 */ #include <stdio.h> int main (void){ int x = 'a'; char x1 = 'a'; // " & ' incompetable printf("output of %c is %i\n", x1,x); }
the_stack_data/165768353.c
/** * @file * * @date Nov 15, 2013 * @author: Anton Bondarev */ #include <unistd.h> int fsync(int fd) { //DPRINTF(("fsync(%d) = %d\n", fd, 0)); return 0; }
the_stack_data/145089.c
/* Code generated from eC source file: ecs.ec */ #if defined(_WIN32) #define __runtimePlatform 1 #elif defined(__APPLE__) #define __runtimePlatform 3 #else #define __runtimePlatform 2 #endif #if defined(__GNUC__) typedef long long int64; typedef unsigned long long uint64; #ifndef _WIN32 #define __declspec(x) #endif #elif defined(__TINYC__) #include <stdarg.h> #define __builtin_va_list va_list #define __builtin_va_start va_start #define __builtin_va_end va_end #ifdef _WIN32 #define strcasecmp stricmp #define strncasecmp strnicmp #define __declspec(x) __attribute__((x)) #else #define __declspec(x) #endif typedef long long int64; typedef unsigned long long uint64; #else typedef __int64 int64; typedef unsigned __int64 uint64; #endif #ifdef __BIG_ENDIAN__ #define __ENDIAN_PAD(x) (8 - (x)) #else #define __ENDIAN_PAD(x) 0 #endif #if defined(_WIN32) # if defined(__GNUC__) || defined(__TINYC__) # define ecere_stdcall __attribute__((__stdcall__)) # define ecere_gcc_struct __attribute__((gcc_struct)) # else # define ecere_stdcall __stdcall # define ecere_gcc_struct # endif #else # define ecere_stdcall # define ecere_gcc_struct #endif #include <stdint.h> #include <sys/types.h> static unsigned int i18n; static unsigned int outputPot; static unsigned int disabledPooling; static int targetPlatform; static int targetBits; static unsigned int isConsole; static unsigned int isDynamicLibrary; static unsigned int isStaticLibrary; static struct Context * theGlobalContext; static char mainModuleName[797]; static char projectName[797]; extern struct __ecereNameSpace__ecere__com__Property * __ecereProp___ecereNameSpace__ecere__sys__BinaryTree_first; extern struct __ecereNameSpace__ecere__com__Property * __ecereProp___ecereNameSpace__ecere__sys__BTNode_next; extern struct __ecereNameSpace__ecere__com__Property * __ecereProp___ecereNameSpace__ecere__com__Platform_char__PTR_; extern struct __ecereNameSpace__ecere__com__Property * __ecereProp___ecereNameSpace__ecere__com__MapIterator_map; extern struct __ecereNameSpace__ecere__com__Property * __ecereProp___ecereNameSpace__ecere__com__Iterator_data; extern struct __ecereNameSpace__ecere__com__Property * __ecereProp___ecereNameSpace__ecere__com__MapIterator_key; struct __ecereNameSpace__ecere__sys__OldList { void * first; void * last; int count; unsigned int offset; unsigned int circ; } ecere_gcc_struct; struct __ecereNameSpace__ecere__com__DataValue { union { char c; unsigned char uc; short s; unsigned short us; int i; unsigned int ui; void * p; float f; double d; long long i64; uint64 ui64; } ecere_gcc_struct __anon1; } ecere_gcc_struct; struct __ecereNameSpace__ecere__com__SerialBuffer { unsigned char * _buffer; unsigned int count; unsigned int _size; unsigned int pos; } ecere_gcc_struct; extern void * __ecereNameSpace__ecere__com__eSystem_New(unsigned int size); extern void * __ecereNameSpace__ecere__com__eSystem_New0(unsigned int size); extern void * __ecereNameSpace__ecere__com__eSystem_Renew(void * memory, unsigned int size); extern void * __ecereNameSpace__ecere__com__eSystem_Renew0(void * memory, unsigned int size); extern void __ecereNameSpace__ecere__com__eSystem_Delete(void * memory); struct External; struct CodePosition { int line; int charPos; int pos; int included; } ecere_gcc_struct; struct Context; struct Expression; extern char * __ecereNameSpace__ecere__sys__TrimLSpaces(const char * string, char * output); extern int strcmp(const char * , const char * ); extern char * __ecereNameSpace__ecere__sys__CopyString(const char * string); extern char * __ecereNameSpace__ecere__sys__GetLastDirectory(const char * string, char * output); extern unsigned int __ecereNameSpace__ecere__sys__StripExtension(char * string); extern char * strcpy(char * , const char * ); extern void FixModuleName(char * moduleName); extern void FullClassNameCat(char * output, const char * className, unsigned int includeTemplateParams); struct TemplateParameter; extern int sprintf(char * , const char * , ...); struct TypeName; struct Declarator; struct Identifier; extern char * strcat(char * , const char * ); extern int GetHostBits(void); extern void SetSymbolsDir(const char * s); extern int printf(const char * , ...); extern const char * __ecereNameSpace__ecere__GetTranslatedString(const char * name, const char * string, const char * stringAndContext); extern char * __ecereNameSpace__ecere__sys__GetExtension(const char * string, char * output); extern void SetTargetPlatform(int platform); extern void SetTargetBits(int bits); extern void SetInSymbolGen(unsigned int b); struct __ecereNameSpace__ecere__com__IteratorPointer; extern int __ecereNameSpace__ecere__sys__Tokenize(char * string, int maxTokens, char * tokens[], unsigned int esc); extern int strcasecmp(const char * , const char * ); extern unsigned int LoadSymbols(const char * fileName, int importType, unsigned int loadDllOnly); extern void CheckDataRedefinitions(void); extern char * __ecereNameSpace__ecere__sys__ChangeExtension(const char * string, const char * ext, char * output); extern char * strstr(const char * , const char * ); extern size_t strlen(const char * ); struct ContextStringPair { char * string; char * context; } ecere_gcc_struct; struct __ecereNameSpace__ecere__com__CustomAVLTree { struct __ecereNameSpace__ecere__com__AVLNode * root; int count; } ecere_gcc_struct; extern char * __ecereNameSpace__ecere__sys__PathCat(char * string, const char * addedPath); struct Definition; extern void FreeIncludeFiles(void); const char * __ecereProp___ecereNameSpace__ecere__com__Platform_Get_char__PTR_(int this); int __ecereProp___ecereNameSpace__ecere__com__Platform_Set_char__PTR_(const char * value); static struct __ecereNameSpace__ecere__sys__OldList modules; struct __ecereNameSpace__ecere__sys__OldList _defines = { 0, 0, 0, 0, 0 }; struct __ecereNameSpace__ecere__sys__OldList _imports = { 0, 0, 0, 0, 0 }; extern struct __ecereNameSpace__ecere__sys__OldList * MkList(void); extern void SetDefines(struct __ecereNameSpace__ecere__sys__OldList * list); extern void SetImports(struct __ecereNameSpace__ecere__sys__OldList * list); extern void SetExcludedSymbols(struct __ecereNameSpace__ecere__sys__OldList * list); extern void FreeExcludedSymbols(struct __ecereNameSpace__ecere__sys__OldList * excludedSymbols); unsigned int __ecereMethod___ecereNameSpace__ecere__sys__OldList_AddName(struct __ecereNameSpace__ecere__sys__OldList * this, void * item); void * __ecereMethod___ecereNameSpace__ecere__sys__OldList_FindName(struct __ecereNameSpace__ecere__sys__OldList * this, const char * name, unsigned int warn); void __ecereMethod___ecereNameSpace__ecere__sys__OldList_Add(struct __ecereNameSpace__ecere__sys__OldList * this, void * item); void __ecereMethod___ecereNameSpace__ecere__sys__OldList_Free(struct __ecereNameSpace__ecere__sys__OldList * this, void (* freeFn)(void * )); struct Location { struct CodePosition start; struct CodePosition end; } ecere_gcc_struct; extern void FinishTemplatesContext(struct Context * context); extern void SetGlobalContext(struct Context * context); extern void SetTopContext(struct Context * context); extern void SetCurrentContext(struct Context * context); extern void FreeContext(struct Context * context); extern struct Declarator * SpecDeclFromString(const char * string, struct __ecereNameSpace__ecere__sys__OldList * specs, struct Declarator * baseDecl); extern struct TypeName * MkTypeName(struct __ecereNameSpace__ecere__sys__OldList * qualifiers, struct Declarator * declarator); extern struct Declarator * MkDeclaratorIdentifier(struct Identifier * id); extern struct Identifier * MkIdentifier(const char * string); extern void FreeModuleDefine(struct Definition * def); struct ModuleImport; static struct ModuleImport * mainModule; extern struct ModuleImport * GetMainModule(void); extern void SetMainModule(struct ModuleImport * moduleImport); struct ModuleImport { struct ModuleImport * prev; struct ModuleImport * next; char * name; struct __ecereNameSpace__ecere__sys__OldList classes; struct __ecereNameSpace__ecere__sys__OldList functions; int importType; int importAccess; } ecere_gcc_struct; extern void FreeModuleImport(struct ModuleImport * imp); struct __ecereNameSpace__ecere__com__Class; struct __ecereNameSpace__ecere__com__Instance { void * * _vTbl; struct __ecereNameSpace__ecere__com__Class * _class; int _refCount; } ecere_gcc_struct; extern long long __ecereNameSpace__ecere__com__eClass_GetProperty(struct __ecereNameSpace__ecere__com__Class * _class, const char * name); extern void __ecereNameSpace__ecere__com__eClass_SetProperty(struct __ecereNameSpace__ecere__com__Class * _class, const char * name, long long value); static struct __ecereNameSpace__ecere__com__Class * thisAppClass; extern struct Context * SetupTemplatesContext(struct __ecereNameSpace__ecere__com__Class * _class); extern void * __ecereNameSpace__ecere__com__eInstance_New(struct __ecereNameSpace__ecere__com__Class * _class); extern void __ecereNameSpace__ecere__com__eInstance_SetMethod(struct __ecereNameSpace__ecere__com__Instance * instance, const char * name, void * function); extern void __ecereNameSpace__ecere__com__eInstance_IncRef(struct __ecereNameSpace__ecere__com__Instance * instance); static struct __ecereNameSpace__ecere__com__Instance * dcomSymbols; extern struct __ecereNameSpace__ecere__com__Instance * __ecereNameSpace__ecere__sys__FileOpen(const char * fileName, int mode); extern void __ecereNameSpace__ecere__com__eInstance_Delete(struct __ecereNameSpace__ecere__com__Instance * instance); extern void OutputTypeName(struct TypeName * type, struct __ecereNameSpace__ecere__com__Instance * f, unsigned int typeName); struct __ecereNameSpace__ecere__com__MapIterator { struct __ecereNameSpace__ecere__com__Instance * container; struct __ecereNameSpace__ecere__com__IteratorPointer * pointer; } ecere_gcc_struct; struct __ecereNameSpace__ecere__com__Iterator { struct __ecereNameSpace__ecere__com__Instance * container; struct __ecereNameSpace__ecere__com__IteratorPointer * pointer; } ecere_gcc_struct; unsigned int __ecereMethod___ecereNameSpace__ecere__sys__File_GetLine(struct __ecereNameSpace__ecere__com__Instance * this, char * s, int max); extern void __ecereNameSpace__ecere__com__eInstance_DecRef(struct __ecereNameSpace__ecere__com__Instance * instance); int __ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts; int __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(struct __ecereNameSpace__ecere__com__Instance * this, const char * format, ...); int __ecereVMethodID___ecereNameSpace__ecere__sys__File_Seek; int __ecereVMethodID___ecereNameSpace__ecere__sys__File_Eof; int __ecereVMethodID___ecereNameSpace__ecere__sys__File_Read; int __ecereVMethodID___ecereNameSpace__ecere__sys__File_Write; int __ecereVMethodID___ecereNameSpace__ecere__com__Container_Add; int __ecereVMethodID___ecereNameSpace__ecere__com__Container_RemoveAll; int __ecereVMethodID___ecereNameSpace__ecere__com__Container_Free; struct __ecereNameSpace__ecere__com__Instance * __ecereProp___ecereNameSpace__ecere__com__MapIterator_Get_map(struct __ecereNameSpace__ecere__com__MapIterator * this); void __ecereProp___ecereNameSpace__ecere__com__MapIterator_Set_map(struct __ecereNameSpace__ecere__com__MapIterator * this, struct __ecereNameSpace__ecere__com__Instance * value); const uint64 __ecereProp___ecereNameSpace__ecere__com__MapIterator_Get_key(struct __ecereNameSpace__ecere__com__MapIterator * this); unsigned int __ecereMethod___ecereNameSpace__ecere__com__Iterator_Index(struct __ecereNameSpace__ecere__com__Iterator * this, const uint64 index, unsigned int create); uint64 __ecereProp___ecereNameSpace__ecere__com__Iterator_Get_data(struct __ecereNameSpace__ecere__com__Iterator * this); void __ecereProp___ecereNameSpace__ecere__com__Iterator_Set_data(struct __ecereNameSpace__ecere__com__Iterator * this, uint64 value); unsigned int __ecereMethod___ecereNameSpace__ecere__com__Iterator_Next(); struct ModuleInfo; struct ModuleInfo { struct ModuleInfo * prev, * next; char * name; unsigned int globalInstance; } ecere_gcc_struct; struct __ecereNameSpace__ecere__sys__BTNode; struct __ecereNameSpace__ecere__sys__BTNode { uintptr_t key; struct __ecereNameSpace__ecere__sys__BTNode * parent; struct __ecereNameSpace__ecere__sys__BTNode * left; struct __ecereNameSpace__ecere__sys__BTNode * right; int depth; } ecere_gcc_struct; struct __ecereNameSpace__ecere__sys__BTNode * __ecereProp___ecereNameSpace__ecere__sys__BTNode_Get_next(struct __ecereNameSpace__ecere__sys__BTNode * this); struct __ecereNameSpace__ecere__com__Property; extern void __ecereNameSpace__ecere__com__eInstance_FireSelfWatchers(struct __ecereNameSpace__ecere__com__Instance * instance, struct __ecereNameSpace__ecere__com__Property * _property); extern void __ecereNameSpace__ecere__com__eInstance_StopWatching(struct __ecereNameSpace__ecere__com__Instance * instance, struct __ecereNameSpace__ecere__com__Property * _property, struct __ecereNameSpace__ecere__com__Instance * object); extern void __ecereNameSpace__ecere__com__eInstance_Watch(void * instance, struct __ecereNameSpace__ecere__com__Property * _property, void * object, void (* callback)(void * , void * )); extern void __ecereNameSpace__ecere__com__eInstance_FireWatchers(struct __ecereNameSpace__ecere__com__Instance * instance, struct __ecereNameSpace__ecere__com__Property * _property); struct FunctionImport; struct FunctionImport { struct FunctionImport * prev; struct FunctionImport * next; char * name; } ecere_gcc_struct; struct MethodImport; struct MethodImport { struct MethodImport * prev; struct MethodImport * next; char * name; unsigned int isVirtual; } ecere_gcc_struct; struct PropertyImport; struct PropertyImport { struct PropertyImport * prev; struct PropertyImport * next; char * name; unsigned int isVirtual; unsigned int hasSet; unsigned int hasGet; } ecere_gcc_struct; struct ImportedModule; struct ImportedModule { struct ImportedModule * prev; struct ImportedModule * next; char * name; int type; int importType; unsigned int globalInstance; unsigned int dllOnly; int importAccess; } ecere_gcc_struct; struct Type; struct __ecereNameSpace__ecere__com__Property { struct __ecereNameSpace__ecere__com__Property * prev; struct __ecereNameSpace__ecere__com__Property * next; const char * name; unsigned int isProperty; int memberAccess; int id; struct __ecereNameSpace__ecere__com__Class * _class; const char * dataTypeString; struct __ecereNameSpace__ecere__com__Class * dataTypeClass; struct Type * dataType; void (* Set)(void * , int); int (* Get)(void * ); unsigned int (* IsSet)(void * ); void * data; void * symbol; int vid; unsigned int conversion; unsigned int watcherOffset; const char * category; unsigned int compiled; unsigned int selfWatchable; unsigned int isWatchable; } ecere_gcc_struct; extern struct Type * ProcessTypeString(const char * string, unsigned int staticMethod); extern void PrintTypeNoConst(struct Type * type, char * string, unsigned int printName, unsigned int fullName); extern void PrintType(struct Type * type, char * string, unsigned int printName, unsigned int fullName); struct __ecereNameSpace__ecere__com__BTNamedLink; struct __ecereNameSpace__ecere__com__BTNamedLink { const char * name; struct __ecereNameSpace__ecere__com__BTNamedLink * parent; struct __ecereNameSpace__ecere__com__BTNamedLink * left; struct __ecereNameSpace__ecere__com__BTNamedLink * right; int depth; void * data; } ecere_gcc_struct; struct __ecereNameSpace__ecere__sys__OldLink; struct __ecereNameSpace__ecere__sys__OldLink { struct __ecereNameSpace__ecere__sys__OldLink * prev; struct __ecereNameSpace__ecere__sys__OldLink * next; void * data; } ecere_gcc_struct; struct Symbol; extern void DeclareClass(struct External * neededFor, struct Symbol * classSym, const char * className); extern struct Symbol * FindClass(const char * name); struct __ecereNameSpace__ecere__com__NameSpace; extern void SetGlobalData(struct __ecereNameSpace__ecere__com__NameSpace * nameSpace); struct ClassImport; struct ClassImport { struct ClassImport * prev; struct ClassImport * next; char * name; struct __ecereNameSpace__ecere__sys__OldList methods; struct __ecereNameSpace__ecere__sys__OldList properties; unsigned int itself; int isRemote; } ecere_gcc_struct; struct __ecereNameSpace__ecere__com__Method; struct __ecereNameSpace__ecere__com__Method { const char * name; struct __ecereNameSpace__ecere__com__Method * parent; struct __ecereNameSpace__ecere__com__Method * left; struct __ecereNameSpace__ecere__com__Method * right; int depth; int (* function)(); int vid; int type; struct __ecereNameSpace__ecere__com__Class * _class; void * symbol; const char * dataTypeString; struct Type * dataType; int memberAccess; } ecere_gcc_struct; struct Symbol { char * string; struct Symbol * parent; struct Symbol * left; struct Symbol * right; int depth; struct Type * type; union { struct __ecereNameSpace__ecere__com__Method * method; struct __ecereNameSpace__ecere__com__Property * _property; struct __ecereNameSpace__ecere__com__Class * registered; } ecere_gcc_struct __anon1; unsigned int notYetDeclared; union { struct { struct External * pointerExternal; struct External * structExternal; } ecere_gcc_struct __anon1; struct { struct External * externalGet; struct External * externalSet; struct External * externalPtr; struct External * externalIsSet; } ecere_gcc_struct __anon2; struct { struct External * methodExternal; struct External * methodCodeExternal; } ecere_gcc_struct __anon3; } ecere_gcc_struct __anon2; unsigned int imported; unsigned int declaredStructSym; struct __ecereNameSpace__ecere__com__Class * _class; unsigned int declaredStruct; unsigned int needConstructor; unsigned int needDestructor; char * constructorName; char * structName; char * className; char * destructorName; struct ModuleImport * module; struct ClassImport * _import; struct Location nameLoc; unsigned int isParam; unsigned int isRemote; unsigned int isStruct; unsigned int fireWatchersDone; int declaring; unsigned int classData; unsigned int isStatic; char * shortName; struct __ecereNameSpace__ecere__sys__OldList * templateParams; struct __ecereNameSpace__ecere__sys__OldList templatedClasses; struct Context * ctx; int isIterator; struct Expression * propCategory; unsigned int mustRegister; } ecere_gcc_struct; struct Type { struct Type * prev; struct Type * next; int refCount; union { struct Symbol * _class; struct { struct __ecereNameSpace__ecere__sys__OldList members; char * enumName; } ecere_gcc_struct __anon1; struct { struct Type * returnType; struct __ecereNameSpace__ecere__sys__OldList params; struct Symbol * thisClass; unsigned int staticMethod; struct TemplateParameter * thisClassTemplate; } ecere_gcc_struct __anon2; struct { struct __ecereNameSpace__ecere__com__Method * method; struct __ecereNameSpace__ecere__com__Class * methodClass; struct __ecereNameSpace__ecere__com__Class * usedClass; } ecere_gcc_struct __anon3; struct { struct Type * arrayType; int arraySize; struct Expression * arraySizeExp; unsigned int freeExp; struct Symbol * enumClass; } ecere_gcc_struct __anon4; struct Type * type; struct TemplateParameter * templateParameter; } ecere_gcc_struct __anon1; int kind; unsigned int size; char * name; char * typeName; struct __ecereNameSpace__ecere__com__Class * thisClassFrom; int promotedFrom; int classObjectType; int alignment; unsigned int offset; int bitFieldCount; int count; int bitMemberSize; unsigned int isSigned : 1; unsigned int constant : 1; unsigned int truth : 1; unsigned int byReference : 1; unsigned int extraParam : 1; unsigned int directClassAccess : 1; unsigned int computing : 1; unsigned int keepCast : 1; unsigned int passAsTemplate : 1; unsigned int dllExport : 1; unsigned int attrStdcall : 1; unsigned int declaredWithStruct : 1; unsigned int typedByReference : 1; unsigned int casted : 1; unsigned int pointerAlignment : 1; unsigned int isLong : 1; unsigned int signedBeforePromotion : 1; unsigned int isVector : 1; } ecere_gcc_struct; extern void DeclareMethod(struct External * neededFor, struct __ecereNameSpace__ecere__com__Method * method, const char * name); extern struct __ecereNameSpace__ecere__com__Method * __ecereNameSpace__ecere__com__eClass_AddMethod(struct __ecereNameSpace__ecere__com__Class * _class, const char * name, const char * type, void * function, int declMode); struct __ecereNameSpace__ecere__sys__OldList _excludedSymbols = { 0, 0, 0, (unsigned int)(uintptr_t)&((struct Symbol *)(void * )0)->left, 0 }; struct __ecereNameSpace__ecere__com__Module; static struct __ecereNameSpace__ecere__com__Instance * privateModule; extern struct __ecereNameSpace__ecere__com__Class * __ecereNameSpace__ecere__com__eSystem_FindClass(struct __ecereNameSpace__ecere__com__Instance * module, const char * name); extern struct __ecereNameSpace__ecere__com__Method * __ecereNameSpace__ecere__com__eClass_FindMethod(struct __ecereNameSpace__ecere__com__Class * _class, const char * name, struct __ecereNameSpace__ecere__com__Instance * module); extern void SetPrivateModule(struct __ecereNameSpace__ecere__com__Instance * module); extern void ComputeModuleClasses(struct __ecereNameSpace__ecere__com__Instance * module); extern void FreeTypeData(struct __ecereNameSpace__ecere__com__Instance * privateModule); extern struct __ecereNameSpace__ecere__com__Class * __ecereNameSpace__ecere__com__eSystem_RegisterClass(int type, const char * name, const char * baseName, int size, int sizeClass, unsigned int (* Constructor)(void * ), void (* Destructor)(void * ), struct __ecereNameSpace__ecere__com__Instance * module, int declMode, int inheritanceAccess); extern struct __ecereNameSpace__ecere__com__Instance * __thisModule; struct __ecereNameSpace__ecere__com__Application; extern struct __ecereNameSpace__ecere__com__Instance * __ecereNameSpace__ecere__com____ecere_COM_Initialize(unsigned int guiApp, int argc, char * argv[]); struct __ecereNameSpace__ecere__sys__BinaryTree; struct __ecereNameSpace__ecere__sys__BinaryTree { struct __ecereNameSpace__ecere__sys__BTNode * root; int count; int (* CompareKey)(struct __ecereNameSpace__ecere__sys__BinaryTree * tree, uintptr_t a, uintptr_t b); void (* FreeKey)(void * key); } ecere_gcc_struct; struct __ecereNameSpace__ecere__com__NameSpace { const char * name; struct __ecereNameSpace__ecere__com__NameSpace * btParent; struct __ecereNameSpace__ecere__com__NameSpace * left; struct __ecereNameSpace__ecere__com__NameSpace * right; int depth; struct __ecereNameSpace__ecere__com__NameSpace * parent; struct __ecereNameSpace__ecere__sys__BinaryTree nameSpaces; struct __ecereNameSpace__ecere__sys__BinaryTree classes; struct __ecereNameSpace__ecere__sys__BinaryTree defines; struct __ecereNameSpace__ecere__sys__BinaryTree functions; } ecere_gcc_struct; struct __ecereNameSpace__ecere__sys__BTNode * __ecereProp___ecereNameSpace__ecere__sys__BinaryTree_Get_first(struct __ecereNameSpace__ecere__sys__BinaryTree * this); int __ecereMethod___ecereNameSpace__ecere__sys__BinaryTree_CompareString(struct __ecereNameSpace__ecere__sys__BinaryTree * this, const char * a, const char * b); struct __ecereNameSpace__ecere__com__Application { int argc; const char * * argv; int exitCode; unsigned int isGUIApp; struct __ecereNameSpace__ecere__sys__OldList allModules; char * parsedCommand; struct __ecereNameSpace__ecere__com__NameSpace systemNameSpace; } ecere_gcc_struct; struct __ecereNameSpace__ecere__com__Module { struct __ecereNameSpace__ecere__com__Instance * application; struct __ecereNameSpace__ecere__sys__OldList classes; struct __ecereNameSpace__ecere__sys__OldList defines; struct __ecereNameSpace__ecere__sys__OldList functions; struct __ecereNameSpace__ecere__sys__OldList modules; struct __ecereNameSpace__ecere__com__Instance * prev; struct __ecereNameSpace__ecere__com__Instance * next; const char * name; void * library; void * Unload; int importType; int origImportType; struct __ecereNameSpace__ecere__com__NameSpace privateNameSpace; struct __ecereNameSpace__ecere__com__NameSpace publicNameSpace; } ecere_gcc_struct; static struct __ecereNameSpace__ecere__com__NameSpace globalData; extern void FreeGlobalData(struct __ecereNameSpace__ecere__com__NameSpace * globalDataList); void __ecereUnregisterModule_ecs(struct __ecereNameSpace__ecere__com__Instance * module) { } struct __ecereNameSpace__ecere__com__DataMember; struct __ecereNameSpace__ecere__com__ClassTemplateArgument { union { struct { const char * dataTypeString; struct __ecereNameSpace__ecere__com__Class * dataTypeClass; } ecere_gcc_struct __anon1; struct __ecereNameSpace__ecere__com__DataValue expression; struct { const char * memberString; union { struct __ecereNameSpace__ecere__com__DataMember * member; struct __ecereNameSpace__ecere__com__Property * prop; struct __ecereNameSpace__ecere__com__Method * method; } ecere_gcc_struct __anon1; } ecere_gcc_struct __anon2; } ecere_gcc_struct __anon1; } ecere_gcc_struct; struct __ecereNameSpace__ecere__com__DataMember { struct __ecereNameSpace__ecere__com__DataMember * prev; struct __ecereNameSpace__ecere__com__DataMember * next; const char * name; unsigned int isProperty; int memberAccess; int id; struct __ecereNameSpace__ecere__com__Class * _class; const char * dataTypeString; struct __ecereNameSpace__ecere__com__Class * dataTypeClass; struct Type * dataType; int type; int offset; int memberID; struct __ecereNameSpace__ecere__sys__OldList members; struct __ecereNameSpace__ecere__sys__BinaryTree membersAlpha; int memberOffset; short structAlignment; short pointerAlignment; } ecere_gcc_struct; struct __ecereNameSpace__ecere__com__Class { struct __ecereNameSpace__ecere__com__Class * prev; struct __ecereNameSpace__ecere__com__Class * next; const char * name; int offset; int structSize; void * * _vTbl; int vTblSize; unsigned int (* Constructor)(void * ); void (* Destructor)(void * ); int offsetClass; int sizeClass; struct __ecereNameSpace__ecere__com__Class * base; struct __ecereNameSpace__ecere__sys__BinaryTree methods; struct __ecereNameSpace__ecere__sys__BinaryTree members; struct __ecereNameSpace__ecere__sys__BinaryTree prop; struct __ecereNameSpace__ecere__sys__OldList membersAndProperties; struct __ecereNameSpace__ecere__sys__BinaryTree classProperties; struct __ecereNameSpace__ecere__sys__OldList derivatives; int memberID; int startMemberID; int type; struct __ecereNameSpace__ecere__com__Instance * module; struct __ecereNameSpace__ecere__com__NameSpace * nameSpace; const char * dataTypeString; struct Type * dataType; int typeSize; int defaultAlignment; void (* Initialize)(); int memberOffset; struct __ecereNameSpace__ecere__sys__OldList selfWatchers; const char * designerClass; unsigned int noExpansion; const char * defaultProperty; unsigned int comRedefinition; int count; int isRemote; unsigned int internalDecl; void * data; unsigned int computeSize; short structAlignment; short pointerAlignment; int destructionWatchOffset; unsigned int fixed; struct __ecereNameSpace__ecere__sys__OldList delayedCPValues; int inheritanceAccess; const char * fullName; void * symbol; struct __ecereNameSpace__ecere__sys__OldList conversions; struct __ecereNameSpace__ecere__sys__OldList templateParams; struct __ecereNameSpace__ecere__com__ClassTemplateArgument * templateArgs; struct __ecereNameSpace__ecere__com__Class * templateClass; struct __ecereNameSpace__ecere__sys__OldList templatized; int numParams; unsigned int isInstanceClass; unsigned int byValueSystemClass; } ecere_gcc_struct; static struct __ecereNameSpace__ecere__com__Class * __ecereClass_ModuleInfo; static struct __ecereNameSpace__ecere__com__Class * __ecereClass_SymbolgenApp; static struct __ecereNameSpace__ecere__com__Class * FindAppClass(struct __ecereNameSpace__ecere__com__NameSpace * nameSpace, unsigned int thisModule) { struct __ecereNameSpace__ecere__com__BTNamedLink * link; struct __ecereNameSpace__ecere__com__NameSpace * ns; for(link = (struct __ecereNameSpace__ecere__com__BTNamedLink *)__ecereProp___ecereNameSpace__ecere__sys__BinaryTree_Get_first(&(*nameSpace).classes); link; link = (struct __ecereNameSpace__ecere__com__BTNamedLink *)__ecereProp___ecereNameSpace__ecere__sys__BTNode_Get_next(((struct __ecereNameSpace__ecere__sys__BTNode *)link))) { struct __ecereNameSpace__ecere__com__Class * _class = link->data; if(strcmp(_class->fullName, "ecere::com::Application") && (!thisModule || _class->module == privateModule)) { struct __ecereNameSpace__ecere__com__Class * base; for(base = _class->base; base && base->type != 1000; base = base->base) if(!strcmp(base->fullName, "ecere::com::Application")) return _class; } } for(ns = (struct __ecereNameSpace__ecere__com__NameSpace *)__ecereProp___ecereNameSpace__ecere__sys__BinaryTree_Get_first(&(*nameSpace).nameSpaces); ns; ns = (struct __ecereNameSpace__ecere__com__NameSpace *)__ecereProp___ecereNameSpace__ecere__sys__BTNode_Get_next(((struct __ecereNameSpace__ecere__sys__BTNode *)ns))) { struct __ecereNameSpace__ecere__com__Class * _class = FindAppClass(ns, thisModule); if(_class) return _class; } return (((void *)0)); } extern struct __ecereNameSpace__ecere__com__Class * __ecereClass_ModuleImport; extern struct __ecereNameSpace__ecere__com__Class * __ecereClass_MethodImport; extern struct __ecereNameSpace__ecere__com__Class * __ecereClass_PropertyImport; extern struct __ecereNameSpace__ecere__com__Class * __ecereClass_ClassImport; extern struct __ecereNameSpace__ecere__com__Class * __ecereClass_FunctionImport; extern struct __ecereNameSpace__ecere__com__Class * __ecereClass___ecereNameSpace__ecere__sys__TempFile; extern struct __ecereNameSpace__ecere__com__Class * __ecereClass___ecereNameSpace__ecere__com__Map_TPL_ContextStringPair__ecere__com__List_TPL_String___; extern struct __ecereNameSpace__ecere__com__Class * __ecereClass_ImportedModule; extern struct __ecereNameSpace__ecere__com__Class * __ecereClass___ecereNameSpace__ecere__com__List_TPL_String_; extern struct __ecereNameSpace__ecere__com__Class * __ecereClass_Context; extern struct __ecereNameSpace__ecere__com__Class * __ecereClass___ecereNameSpace__ecere__sys__File; extern struct __ecereNameSpace__ecere__com__Class * __ecereClass___ecereNameSpace__ecere__com__Module; extern struct __ecereNameSpace__ecere__com__Class * __ecereClass___ecereNameSpace__ecere__com__Application; extern struct __ecereNameSpace__ecere__com__Class * __ecereClass___ecereNameSpace__ecere__com__List; extern struct __ecereNameSpace__ecere__com__Class * __ecereClass___ecereNameSpace__ecere__com__CustomAVLTree; extern struct __ecereNameSpace__ecere__com__Class * __ecereClass___ecereNameSpace__ecere__com__Map; static void LoadImports(const char * fileName) { struct __ecereNameSpace__ecere__com__Instance * f = __ecereNameSpace__ecere__sys__FileOpen(fileName, 1); if(f) { for(; ; ) { char line[1024]; if(!__ecereMethod___ecereNameSpace__ecere__sys__File_GetLine(f, line, sizeof (line))) break; __ecereNameSpace__ecere__sys__TrimLSpaces(line, line); if(line[0] == '[') { if(!strcmp(line, "[Imported Modules]")) { struct ModuleImport * module = (((void *)0)); for(; ; ) { if(!__ecereMethod___ecereNameSpace__ecere__sys__File_GetLine(f, line, sizeof (line))) break; __ecereNameSpace__ecere__sys__TrimLSpaces(line, line); if(!strcmp(line, ".")) break; if(line[0] == '[') { struct ClassImport * _class = (((void *)0)); struct FunctionImport * function = (((void *)0)); if(!strcmp(line, "[This]")) { if((mainModule = GetMainModule())) module = mainModule; else { mainModule = __ecereNameSpace__ecere__com__eInstance_New(__ecereClass_ModuleImport); SetMainModule(mainModule); module = mainModule; __ecereMethod___ecereNameSpace__ecere__sys__OldList_AddName(&_imports, module); } } else if(!strcmp(line, "[Static]")) { module->importType = 1; } else if(!strcmp(line, "[Remote]")) { module->importType = 2; } else if(!strcmp(line, "[Private]")) { if(module->importAccess != 1) module->importAccess = 2; } else if(!strcmp(line, "[Public]")) { module->importAccess = 1; } else if(!strcmp(line, "[Imported Classes]")) { for(; ; ) { if(!__ecereMethod___ecereNameSpace__ecere__sys__File_GetLine(f, line, sizeof (line))) break; __ecereNameSpace__ecere__sys__TrimLSpaces(line, line); if(!strcmp(line, ".")) break; if(line[0] == '[') { if(!strcmp(line, "[Instantiated]")) { _class->itself = 1; } else if(!strcmp(line, "[Remote]")) { _class->isRemote = 1; } else if(!strcmp(line, "[Imported Methods]")) { struct MethodImport * method = (((void *)0)); for(; ; ) { if(!__ecereMethod___ecereNameSpace__ecere__sys__File_GetLine(f, line, sizeof (line))) break; __ecereNameSpace__ecere__sys__TrimLSpaces(line, line); if(!strcmp(line, ".")) break; if(line[0] != '[') { if(!(method = __ecereMethod___ecereNameSpace__ecere__sys__OldList_FindName(&_class->methods, line, 0))) { method = __extension__ ({ struct MethodImport * __ecereInstance1 = __ecereNameSpace__ecere__com__eInstance_New(__ecereClass_MethodImport); __ecereInstance1->name = __ecereNameSpace__ecere__sys__CopyString(line), __ecereInstance1; }); __ecereMethod___ecereNameSpace__ecere__sys__OldList_AddName(&_class->methods, method); } } else if(!strcmp(line, "[Virtual]")) method->isVirtual = 1; } } else if(!strcmp(line, "[Imported Properties]")) { struct PropertyImport * prop = (((void *)0)); for(; ; ) { if(!__ecereMethod___ecereNameSpace__ecere__sys__File_GetLine(f, line, sizeof (line))) break; __ecereNameSpace__ecere__sys__TrimLSpaces(line, line); if(!strcmp(line, ".")) break; if(line[0] != '[') { if(!(prop = __ecereMethod___ecereNameSpace__ecere__sys__OldList_FindName(&_class->properties, line, 0))) { prop = __extension__ ({ struct PropertyImport * __ecereInstance1 = __ecereNameSpace__ecere__com__eInstance_New(__ecereClass_PropertyImport); __ecereInstance1->name = __ecereNameSpace__ecere__sys__CopyString(line), __ecereInstance1; }); __ecereMethod___ecereNameSpace__ecere__sys__OldList_AddName(&_class->properties, prop); } } else if(!strcmp(line, "[Set]")) prop->hasSet = 1; else if(!strcmp(line, "[Get]")) prop->hasGet = 1; else if(!strcmp(line, "[Virtual]")) prop->isVirtual = 1; } } } else { if(!(_class = __ecereMethod___ecereNameSpace__ecere__sys__OldList_FindName(&module->classes, line, 0))) { _class = __extension__ ({ struct ClassImport * __ecereInstance1 = __ecereNameSpace__ecere__com__eInstance_New(__ecereClass_ClassImport); __ecereInstance1->name = __ecereNameSpace__ecere__sys__CopyString(line), __ecereInstance1; }); __ecereMethod___ecereNameSpace__ecere__sys__OldList_AddName(&module->classes, _class); } } } } else if(!strcmp(line, "[Imported Functions]")) { for(; ; ) { if(!__ecereMethod___ecereNameSpace__ecere__sys__File_GetLine(f, line, sizeof (line))) break; __ecereNameSpace__ecere__sys__TrimLSpaces(line, line); if(!strcmp(line, ".")) break; if(line[0] == '[') { } else { if(!(function = __ecereMethod___ecereNameSpace__ecere__sys__OldList_FindName(&module->functions, line, 0))) { function = __extension__ ({ struct FunctionImport * __ecereInstance1 = __ecereNameSpace__ecere__com__eInstance_New(__ecereClass_FunctionImport); __ecereInstance1->name = __ecereNameSpace__ecere__sys__CopyString(line), __ecereInstance1; }); __ecereMethod___ecereNameSpace__ecere__sys__OldList_AddName(&module->functions, function); } } } } } else { if(!(module = __ecereMethod___ecereNameSpace__ecere__sys__OldList_FindName(&_imports, line, 0))) { if(!strcmp(line, "ecereCOM")) { module = __ecereMethod___ecereNameSpace__ecere__sys__OldList_FindName(&_imports, "ecere", 0); } else if(!strcmp(line, "ecere")) { module = __ecereMethod___ecereNameSpace__ecere__sys__OldList_FindName(&_imports, "ecereCOM", 0); if(module) { (__ecereNameSpace__ecere__com__eSystem_Delete(module->name), module->name = 0); module->name = __ecereNameSpace__ecere__sys__CopyString("ecere"); } } if(!module) { module = __extension__ ({ struct ModuleImport * __ecereInstance1 = __ecereNameSpace__ecere__com__eInstance_New(__ecereClass_ModuleImport); __ecereInstance1->name = __ecereNameSpace__ecere__sys__CopyString(line), __ecereInstance1; }); __ecereMethod___ecereNameSpace__ecere__sys__OldList_AddName(&_imports, module); } } } } } } } (__ecereNameSpace__ecere__com__eInstance_DecRef(f), f = 0); } } void __ecereCreateModuleInstances_ecs() { (globalData.classes.CompareKey = (void *)__ecereMethod___ecereNameSpace__ecere__sys__BinaryTree_CompareString, globalData.defines.CompareKey = (void *)__ecereMethod___ecereNameSpace__ecere__sys__BinaryTree_CompareString, globalData.functions.CompareKey = (void *)__ecereMethod___ecereNameSpace__ecere__sys__BinaryTree_CompareString, globalData.nameSpaces.CompareKey = (void *)__ecereMethod___ecereNameSpace__ecere__sys__BinaryTree_CompareString); theGlobalContext = __ecereNameSpace__ecere__com__eInstance_New(__ecereClass_Context); } void __ecereDestroyModuleInstances_ecs() { ((theGlobalContext ? __extension__ ({ void * __ecerePtrToDelete = (theGlobalContext); __ecereClass_Context->Destructor ? __ecereClass_Context->Destructor((void *)__ecerePtrToDelete) : 0, __ecereNameSpace__ecere__com__eSystem_Delete(__ecerePtrToDelete); }) : 0), theGlobalContext = 0); } static void BindDCOMClient() { struct __ecereNameSpace__ecere__com__Class * dcomClientObjectClass = __ecereNameSpace__ecere__com__eSystem_FindClass(privateModule, "ecere::net::DCOMClientObject"); struct __ecereNameSpace__ecere__sys__OldLink * deriv; if(dcomClientObjectClass && dcomClientObjectClass->derivatives.first) { struct __ecereNameSpace__ecere__com__Instance * f; if(!dcomSymbols) dcomSymbols = __ecereNameSpace__ecere__com__eInstance_New(__ecereClass___ecereNameSpace__ecere__sys__TempFile); f = dcomSymbols; for(deriv = dcomClientObjectClass->derivatives.first; deriv; deriv = deriv->next) { struct __ecereNameSpace__ecere__com__Class * _class = deriv->data; struct __ecereNameSpace__ecere__com__Method * method, * next; int id = 0; int vid; unsigned int doVirtual; DeclareClass((((void *)0)), FindClass("ecere::net::DCOMClientObject"), "__ecereClass___ecereNameSpace__ecere__net__DCOMClientObject"); __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, "class %s : ecere::net::DCOMClientObject\n", _class->fullName); __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, "{\n"); if(_class->vTblSize > _class->base->vTblSize) { int vid; __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " virtual void CallVirtualMethod(uint __ecereMethodID, SerialBuffer __ecereBuffer)\n"); __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " {\n"); __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " switch(__ecereMethodID)\n"); __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " {\n"); for(vid = _class->base->vTblSize; vid < _class->vTblSize; vid++) { struct __ecereNameSpace__ecere__com__Method * method; for(method = (struct __ecereNameSpace__ecere__com__Method *)__ecereProp___ecereNameSpace__ecere__sys__BinaryTree_Get_first(&_class->methods); method; method = (struct __ecereNameSpace__ecere__com__Method *)__ecereProp___ecereNameSpace__ecere__sys__BTNode_Get_next(((struct __ecereNameSpace__ecere__sys__BTNode *)method))) { if(method->type == 1 && method->_class == _class && method->vid == vid) break; } if(method) { struct Type * param; method->dataType = ProcessTypeString(method->dataTypeString, 0); if(method->dataType && method->dataType->name) { __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " case %d:\n", vid - _class->base->vTblSize); __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " {\n"); { if(method->dataType->__anon1.__anon2.returnType->kind != 0) { struct TypeName * resultType; struct __ecereNameSpace__ecere__sys__OldList * specs = MkList(); struct Declarator * decl; char type[1024] = ""; char className[1024]; struct Symbol * classSym; if(method->dataType->__anon1.__anon2.returnType->kind == 8) classSym = method->dataType->__anon1.__anon2.returnType->__anon1._class; else { PrintTypeNoConst(method->dataType->__anon1.__anon2.returnType, type, 0, 1); classSym = FindClass(type); type[0] = 0; } strcpy(className, "__ecereClass_"); FullClassNameCat(className, classSym->string, 1); DeclareClass((((void *)0)), classSym, className); PrintType(method->dataType->__anon1.__anon2.returnType, type, 1, 1); decl = SpecDeclFromString(type, specs, MkDeclaratorIdentifier(MkIdentifier("__ecereResult"))); resultType = MkTypeName(specs, decl); __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " "); OutputTypeName(resultType, f, 0); __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, ";\n"); } for(param = method->dataType->__anon1.__anon2.params.first; param; param = param->next) { if(param->kind == 8 && !strcmp(param->__anon1._class->string, "String")) { __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " char %s[1024];\n", param->name); DeclareClass((((void *)0)), FindClass("StaticString"), "__ecereClass_StaticString"); DeclareClass((((void *)0)), FindClass("String"), "__ecereClass_String"); } else { struct TypeName * paramTypeName; struct __ecereNameSpace__ecere__sys__OldList * specs = MkList(); struct Declarator * decl; char type[1024] = ""; char className[1024]; struct Symbol * classSym; if(param->kind == 8) classSym = param->__anon1._class; else { PrintTypeNoConst(param, type, 0, 1); classSym = FindClass(type); type[0] = 0; } strcpy(className, "__ecereClass_"); FullClassNameCat(className, classSym->string, 1); DeclareClass((((void *)0)), classSym, className); PrintType(param, type, 1, 1); decl = SpecDeclFromString(type, specs, MkDeclaratorIdentifier(MkIdentifier(param->name))); paramTypeName = MkTypeName(specs, decl); __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " "); OutputTypeName(paramTypeName, f, 0); __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, ";\n"); } } __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, "\n"); for(param = method->dataType->__anon1.__anon2.params.first; param; param = param->next) { __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " __ecereBuffer.Unserialize("); if(param->kind == 8 && !strcmp(param->__anon1._class->string, "String")) { DeclareClass((((void *)0)), FindClass("StaticString"), "__ecereClass_StaticString"); __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, "(StaticString)"); } (__extension__ ({ unsigned int (* __internal_VirtualMethod)(struct __ecereNameSpace__ecere__com__Instance *, const char * string); __internal_VirtualMethod = ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char * string))__extension__ ({ struct __ecereNameSpace__ecere__com__Instance * __internal_ClassInst = f; __internal_ClassInst ? __internal_ClassInst->_vTbl : __ecereClass___ecereNameSpace__ecere__sys__File->_vTbl; })[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts]); __internal_VirtualMethod ? __internal_VirtualMethod(f, param->name) : (unsigned int)1; })); __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, ");\n"); } __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " "); if(method->dataType->__anon1.__anon2.returnType->kind != 0) __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, "__ecereResult = "); __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, "%s(", method->name); for(param = method->dataType->__anon1.__anon2.params.first; param; param = param->next) { if(param->prev) __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, ", "); __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, "%s", param->name); } __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, ");\n"); for(param = method->dataType->__anon1.__anon2.params.first; param; param = param->next) { if(param->kind == 8 && ((param->__anon1._class && param->__anon1._class->__anon1.registered && param->__anon1._class->__anon1.registered->type == 1) || !strcmp(param->__anon1._class->string, "String")) && !param->constant) { if(!strcmp(param->__anon1._class->string, "String")) { DeclareClass((((void *)0)), FindClass("StaticString"), "__ecereClass_StaticString"); __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " __ecereBuffer.Serialize((StaticString)%s);\n", param->name); } else __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " __ecereBuffer.Serialize(%s);\n", param->name); } } if(method->dataType->__anon1.__anon2.returnType->kind != 0) { __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " __ecereBuffer.Serialize(__ecereResult);\n"); } for(param = method->dataType->__anon1.__anon2.params.first; param; param = param->next) { if(param->kind == 8 && strcmp(param->__anon1._class->string, "String") && param->__anon1._class->__anon1.registered && (param->__anon1._class->__anon1.registered->type == 0 || param->__anon1._class->__anon1.registered->type == 5)) { __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " delete %s;\n", param->name); } } if(method->dataType->__anon1.__anon2.returnType->kind == 8 && strcmp(method->dataType->__anon1.__anon2.returnType->__anon1._class->string, "String") && method->dataType->__anon1.__anon2.returnType->__anon1._class->__anon1.registered && (method->dataType->__anon1.__anon2.returnType->__anon1._class->__anon1.registered->type == 0 || method->dataType->__anon1.__anon2.returnType->__anon1._class->__anon1.registered->type == 5)) { __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " delete __ecereResult;\n"); } } __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " break;\n"); __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " }\n"); } } } __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " }\n"); __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " }\n"); __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, "\n"); } doVirtual = 1; id = 0; vid = _class->base->vTblSize; next = (struct __ecereNameSpace__ecere__com__Method *)__ecereProp___ecereNameSpace__ecere__sys__BinaryTree_Get_first(&_class->methods); while(next && ((next->type == 1) != doVirtual || (doVirtual && next->vid != vid))) { id++; next = (struct __ecereNameSpace__ecere__com__Method *)__ecereProp___ecereNameSpace__ecere__sys__BTNode_Get_next(((struct __ecereNameSpace__ecere__sys__BTNode *)next)); if(!next && doVirtual) { if(vid == _class->vTblSize) doVirtual = 0; else vid++; id = 0; next = (struct __ecereNameSpace__ecere__com__Method *)__ecereProp___ecereNameSpace__ecere__sys__BinaryTree_Get_first(&_class->methods); } } for(method = next; method; method = next) { struct Type * param; if(!method->dataType) method->dataType = ProcessTypeString(method->dataTypeString, 0); if(method->dataType->name) { __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " "); if(doVirtual) { char name[1024]; strcpy(name, "__ecereVMethodID_"); FullClassNameCat(name, method->_class->fullName, 1); strcat(name, "_"); strcat(name, method->name); DeclareMethod((((void *)0)), method, name); __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, "virtual "); } __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, "%s\n", method->dataTypeString); __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " {\n"); if(method->dataType) { if(method->dataType->__anon1.__anon2.returnType->kind != 0) { struct TypeName * resultType; struct __ecereNameSpace__ecere__sys__OldList * specs = MkList(); struct Declarator * decl; char type[1024] = ""; char className[1024]; struct Symbol * classSym; if(method->dataType->__anon1.__anon2.returnType->kind == 8) classSym = method->dataType->__anon1.__anon2.returnType->__anon1._class; else { PrintTypeNoConst(method->dataType->__anon1.__anon2.returnType, type, 0, 1); classSym = FindClass(type); type[0] = 0; } strcpy(className, "__ecereClass_"); FullClassNameCat(className, classSym->string, 1); DeclareClass((((void *)0)), classSym, className); PrintType(method->dataType->__anon1.__anon2.returnType, type, 1, 1); decl = SpecDeclFromString(type, specs, MkDeclaratorIdentifier(MkIdentifier("__ecereResult"))); resultType = MkTypeName(specs, decl); __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " "); OutputTypeName(resultType, f, 0); if(method->dataType->__anon1.__anon2.returnType->kind == 9) __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " = { 0 }"); else if(method->dataType->__anon1.__anon2.returnType->kind == 8 && method->dataType->__anon1.__anon2.returnType->__anon1._class->__anon1.registered && method->dataType->__anon1.__anon2.returnType->__anon1._class->__anon1.registered->type == 1) __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " { }"); else __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " = 0"); __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, ";\n\n"); } __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " safeIncRef();\n"); for(param = method->dataType->__anon1.__anon2.params.first; param; param = param->next) { char type[1024] = ""; char className[1024]; struct Symbol * classSym; if(param->kind == 8) classSym = param->__anon1._class; else { PrintTypeNoConst(param, type, 0, 1); classSym = FindClass(type); type[0] = 0; } strcpy(className, "__ecereClass_"); FullClassNameCat(className, classSym->string, 1); DeclareClass((((void *)0)), classSym, className); if(param->kind == 8 && !strcmp(param->__anon1._class->string, "String")) { DeclareClass((((void *)0)), FindClass("StaticString"), "__ecereClass_StaticString"); __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " __ecereBuffer.Serialize((StaticString)%s);\n", param->name); } else __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " __ecereBuffer.Serialize(%s);\n", param->name); } DeclareMethod((((void *)0)), __ecereNameSpace__ecere__com__eClass_FindMethod(__ecereNameSpace__ecere__com__eSystem_FindClass(privateModule, "ecere::net::DCOMClientObject"), "CallMethod", privateModule), "__ecereMethod___ecereNameSpace__ecere__net__DCOMClientObject_CallMethod"); __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " if(DCOMClientObject::CallMethod(%d))\n", id++); __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " {\n"); for(param = method->dataType->__anon1.__anon2.params.first; param; param = param->next) { if(param->kind == 8 && ((param->__anon1._class && param->__anon1._class->__anon1.registered && param->__anon1._class->__anon1.registered->type == 1) || !strcmp(param->__anon1._class->string, "String")) && !param->constant) { if(!strcmp(param->__anon1._class->string, "String")) { DeclareClass((((void *)0)), FindClass("StaticString"), "__ecereClass_StaticString"); __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " __ecereBuffer.Unserialize((StaticString)%s);\n", param->name); } else __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " __ecereBuffer.Unserialize(%s);\n", param->name); } } if(method->dataType->__anon1.__anon2.returnType->kind != 0) { if(method->dataType->__anon1.__anon2.returnType->kind == 8 && !strcmp(method->dataType->__anon1.__anon2.returnType->__anon1._class->string, "String")) { DeclareClass((((void *)0)), FindClass("StaticString"), "__ecereClass_StaticString"); __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " __ecereBuffer.Unserialize((StaticString)__ecereResult);\n"); } else __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " __ecereBuffer.Unserialize(__ecereResult);\n"); } __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " }\n"); __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " __ecereBuffer.Free();\n"); __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " safeDecRef();\n"); if(method->dataType->__anon1.__anon2.returnType->kind != 0) { __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " return __ecereResult;\n"); } } __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " }\n"); } next = (struct __ecereNameSpace__ecere__com__Method *)__ecereProp___ecereNameSpace__ecere__sys__BTNode_Get_next(((struct __ecereNameSpace__ecere__sys__BTNode *)method)); while((!next && doVirtual) || (next && ((next->type == 1) != doVirtual || (doVirtual && next->vid != vid)))) { id++; next = next ? (struct __ecereNameSpace__ecere__com__Method *)__ecereProp___ecereNameSpace__ecere__sys__BTNode_Get_next(((struct __ecereNameSpace__ecere__sys__BTNode *)next)) : (((void *)0)); if(!next && doVirtual) { if(vid == _class->vTblSize) doVirtual = 0; else vid++; id = 0; next = (struct __ecereNameSpace__ecere__com__Method *)__ecereProp___ecereNameSpace__ecere__sys__BinaryTree_Get_first(&_class->methods); } } if(next) __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, "\n"); } __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, "}\n"); if(deriv->next) __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, "\n"); } } } static void BindDCOMServer() { unsigned int mutexDeclared = 0; struct __ecereNameSpace__ecere__com__Class * _class; for(_class = ((struct __ecereNameSpace__ecere__com__Module *)(((char *)privateModule + sizeof(struct __ecereNameSpace__ecere__com__Instance))))->classes.first; _class; _class = _class->next) { if(_class->isRemote == 3) break; } if(_class) { struct __ecereNameSpace__ecere__com__Instance * f; if(!dcomSymbols) dcomSymbols = __ecereNameSpace__ecere__com__eInstance_New(__ecereClass___ecereNameSpace__ecere__sys__TempFile); f = dcomSymbols; DeclareClass((((void *)0)), FindClass("ecere::net::DCOMServerObject"), "__ecereClass___ecereNameSpace__ecere__net__DCOMServerObject"); for(_class = ((struct __ecereNameSpace__ecere__com__Module *)(((char *)privateModule + sizeof(struct __ecereNameSpace__ecere__com__Instance))))->classes.first; _class; _class = _class->next) { if(_class->isRemote == 3) { struct __ecereNameSpace__ecere__com__Method * method; int id = 0; int vid; __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, "class DCOM%s : ecere::net::DCOMServerObject\n", _class->fullName); __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, "{\n"); __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " virtual void CallMethod(uint __ecereMethodID, SerialBuffer __ecereBuffer)\n"); __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " {\n"); __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " %s inst = (%s)instance;\n", _class->fullName, _class->fullName); __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " incref inst;\n"); __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " switch(__ecereMethodID)\n"); __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " {\n"); for(method = (struct __ecereNameSpace__ecere__com__Method *)__ecereProp___ecereNameSpace__ecere__sys__BinaryTree_Get_first(&_class->methods); method; method = (struct __ecereNameSpace__ecere__com__Method *)__ecereProp___ecereNameSpace__ecere__sys__BTNode_Get_next(((struct __ecereNameSpace__ecere__sys__BTNode *)method))) { struct Type * param; method->dataType = ProcessTypeString(method->dataTypeString, 0); if(method->dataType && method->dataType->name) { __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " case %d:\n", id++); __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " {\n"); { if(method->dataType->__anon1.__anon2.returnType->kind != 0) { struct TypeName * resultType; struct __ecereNameSpace__ecere__sys__OldList * specs = MkList(); struct Declarator * decl; char type[1024] = ""; char className[1024]; struct Symbol * classSym; if(method->dataType->__anon1.__anon2.returnType->kind == 8) classSym = method->dataType->__anon1.__anon2.returnType->__anon1._class; else { PrintTypeNoConst(method->dataType->__anon1.__anon2.returnType, type, 0, 1); classSym = FindClass(type); type[0] = 0; } strcpy(className, "__ecereClass_"); FullClassNameCat(className, classSym->string, 1); DeclareClass((((void *)0)), classSym, className); PrintType(method->dataType->__anon1.__anon2.returnType, type, 1, 1); decl = SpecDeclFromString(type, specs, MkDeclaratorIdentifier(MkIdentifier("__ecereResult"))); resultType = MkTypeName(specs, decl); __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " "); OutputTypeName(resultType, f, 0); __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, ";\n"); } for(param = method->dataType->__anon1.__anon2.params.first; param; param = param->next) { if(param->kind == 8 && !strcmp(param->__anon1._class->string, "String")) { __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " char %s[1024];\n", param->name); DeclareClass((((void *)0)), FindClass("StaticString"), "__ecereClass_StaticString"); DeclareClass((((void *)0)), FindClass("String"), "__ecereClass_String"); } else { struct TypeName * paramTypeName; struct __ecereNameSpace__ecere__sys__OldList * specs = MkList(); struct Declarator * decl; char type[1024] = ""; char className[1024]; struct Symbol * classSym; if(param->kind == 8) classSym = param->__anon1._class; else { PrintTypeNoConst(param, type, 0, 1); classSym = FindClass(type); type[0] = 0; } strcpy(className, "__ecereClass_"); FullClassNameCat(className, classSym->string, 1); DeclareClass((((void *)0)), classSym, className); PrintType(param, type, 1, 1); decl = SpecDeclFromString(type, specs, MkDeclaratorIdentifier(MkIdentifier(param->name))); paramTypeName = MkTypeName(specs, decl); __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " "); OutputTypeName(paramTypeName, f, 0); __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, ";\n"); } } __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, "\n"); for(param = method->dataType->__anon1.__anon2.params.first; param; param = param->next) { __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " __ecereBuffer.Unserialize("); if(param->kind == 8 && !strcmp(param->__anon1._class->string, "String")) { DeclareClass((((void *)0)), FindClass("StaticString"), "__ecereClass_StaticString"); __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, "(StaticString)"); } (__extension__ ({ unsigned int (* __internal_VirtualMethod)(struct __ecereNameSpace__ecere__com__Instance *, const char * string); __internal_VirtualMethod = ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char * string))__extension__ ({ struct __ecereNameSpace__ecere__com__Instance * __internal_ClassInst = f; __internal_ClassInst ? __internal_ClassInst->_vTbl : __ecereClass___ecereNameSpace__ecere__sys__File->_vTbl; })[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts]); __internal_VirtualMethod ? __internal_VirtualMethod(f, param->name) : (unsigned int)1; })); __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, ");\n"); } __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " "); if(method->dataType->__anon1.__anon2.returnType->kind != 0) __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, "__ecereResult = "); __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, "((%s)instance).%s(", _class->fullName, method->name); for(param = method->dataType->__anon1.__anon2.params.first; param; param = param->next) { if(param->prev) __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, ", "); __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, "%s", param->name); } __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, ");\n"); for(param = method->dataType->__anon1.__anon2.params.first; param; param = param->next) { if(param->kind == 8 && ((param->__anon1._class && param->__anon1._class->__anon1.registered && param->__anon1._class->__anon1.registered->type == 1) || !strcmp(param->__anon1._class->string, "String")) && !param->constant) { if(!strcmp(param->__anon1._class->string, "String")) { DeclareClass((((void *)0)), FindClass("StaticString"), "__ecereClass_StaticString"); __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " __ecereBuffer.Serialize((StaticString)%s);\n", param->name); } else __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " __ecereBuffer.Serialize(%s);\n", param->name); } } if(method->dataType->__anon1.__anon2.returnType->kind != 0) { __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " __ecereBuffer.Serialize(__ecereResult);\n"); } for(param = method->dataType->__anon1.__anon2.params.first; param; param = param->next) { if(param->kind == 8 && strcmp(param->__anon1._class->string, "String") && param->__anon1._class->__anon1.registered && (param->__anon1._class->__anon1.registered->type == 0 || param->__anon1._class->__anon1.registered->type == 5)) { __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " delete %s;\n", param->name); } } if(method->dataType->__anon1.__anon2.returnType->kind == 8 && strcmp(method->dataType->__anon1.__anon2.returnType->__anon1._class->string, "String") && method->dataType->__anon1.__anon2.returnType->__anon1._class->__anon1.registered && (method->dataType->__anon1.__anon2.returnType->__anon1._class->__anon1.registered->type == 0 || method->dataType->__anon1.__anon2.returnType->__anon1._class->__anon1.registered->type == 5)) { __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " delete __ecereResult;\n"); } } __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " break;\n"); __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " }\n"); } } __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " }\n"); __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " delete inst;\n"); __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " }\n"); for(vid = _class->base->vTblSize; vid < _class->vTblSize; vid++) { struct __ecereNameSpace__ecere__com__Method * method; struct Type * param; for(method = (struct __ecereNameSpace__ecere__com__Method *)__ecereProp___ecereNameSpace__ecere__sys__BinaryTree_Get_first(&_class->methods); method; method = (struct __ecereNameSpace__ecere__com__Method *)__ecereProp___ecereNameSpace__ecere__sys__BTNode_Get_next(((struct __ecereNameSpace__ecere__sys__BTNode *)method))) if(method->type == 1 && method->_class == _class && method->vid == vid) break; if(method) { if(!mutexDeclared) { DeclareClass((((void *)0)), FindClass("ecere::sys::Mutex"), "__ecereClass___ecereNameSpace__ecere__sys__Mutex"); DeclareMethod((((void *)0)), __ecereNameSpace__ecere__com__eClass_FindMethod(__ecereNameSpace__ecere__com__eSystem_FindClass(privateModule, "ecere::sys::Mutex"), "Wait", privateModule), "__ecereMethod___ecereNameSpace__ecere__sys__Mutex_Wait"); DeclareMethod((((void *)0)), __ecereNameSpace__ecere__com__eClass_FindMethod(__ecereNameSpace__ecere__com__eSystem_FindClass(privateModule, "ecere::sys::Mutex"), "Release", privateModule), "__ecereMethod___ecereNameSpace__ecere__sys__Mutex_Release"); mutexDeclared = 1; } __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, "\n"); if(!method->dataType) method->dataType = ProcessTypeString(method->dataTypeString, 0); if(method->dataType->name) { __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " virtual %s\n", method->dataTypeString); __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " {\n"); if(method->dataType) { __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " DCOM%s __ecereObject = (void *)_vTbl[-1];\n", _class->fullName); if(method->dataType->__anon1.__anon2.returnType->kind != 0) { struct TypeName * resultType; struct __ecereNameSpace__ecere__sys__OldList * specs = MkList(); struct Declarator * decl; char type[1024] = ""; char className[1024]; struct Symbol * classSym; if(method->dataType->__anon1.__anon2.returnType->kind == 8) classSym = method->dataType->__anon1.__anon2.returnType->__anon1._class; else { PrintTypeNoConst(method->dataType->__anon1.__anon2.returnType, type, 0, 1); classSym = FindClass(type); type[0] = 0; } strcpy(className, "__ecereClass_"); FullClassNameCat(className, classSym->string, 1); DeclareClass((((void *)0)), classSym, className); PrintType(method->dataType->__anon1.__anon2.returnType, type, 1, 1); decl = SpecDeclFromString(type, specs, MkDeclaratorIdentifier(MkIdentifier("__ecereResult"))); resultType = MkTypeName(specs, decl); __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " "); OutputTypeName(resultType, f, 0); if(method->dataType->__anon1.__anon2.returnType->kind == 9) __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " = { 0 }"); else if(method->dataType->__anon1.__anon2.returnType->kind == 8 && method->dataType->__anon1.__anon2.returnType->__anon1._class->__anon1.registered && method->dataType->__anon1.__anon2.returnType->__anon1._class->__anon1.registered->type == 1) __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " { }"); else __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " = 0"); __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, ";\n\n"); } __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " incref __ecereObject;\n"); __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " __ecereMethod___ecereNameSpace__ecere__sys__Mutex_Wait(__ecereObject.mutex);\n"); for(param = method->dataType->__anon1.__anon2.params.first; param; param = param->next) { char type[1024] = ""; char className[1024]; struct Symbol * classSym; if(param->kind == 8) classSym = param->__anon1._class; else { PrintTypeNoConst(param, type, 0, 1); classSym = FindClass(type); type[0] = 0; } strcpy(className, "__ecereClass_"); FullClassNameCat(className, classSym->string, 1); DeclareClass((((void *)0)), classSym, className); if(param->kind == 8 && !strcmp(param->__anon1._class->string, "String")) { DeclareClass((((void *)0)), FindClass("StaticString"), "__ecereClass_StaticString"); __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " __ecereObject.argsBuffer.Serialize((StaticString)%s);\n", param->name); } else __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " __ecereObject.argsBuffer.Serialize(%s);\n", param->name); } DeclareMethod((((void *)0)), __ecereNameSpace__ecere__com__eClass_FindMethod(__ecereNameSpace__ecere__com__eSystem_FindClass(privateModule, "ecere::net::DCOMServerObject"), "CallVirtualMethod", privateModule), "__ecereMethod___ecereNameSpace__ecere__net__DCOMServerObject_CallVirtualMethod"); { unsigned int hasReturnValue = method->dataType->__anon1.__anon2.returnType->kind != 0; if(!hasReturnValue) { for(param = method->dataType->__anon1.__anon2.params.first; param; param = param->next) { if(param->kind == 8 && ((param->__anon1._class && param->__anon1._class->__anon1.registered && param->__anon1._class->__anon1.registered->type == 1) || !strcmp(param->__anon1._class->string, "String")) && !param->constant) { hasReturnValue = 1; break; } } } __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " if(__ecereObject.CallVirtualMethod(%d, %s))\n", vid - _class->base->vTblSize, hasReturnValue ? "true" : "false"); } __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " {\n"); for(param = method->dataType->__anon1.__anon2.params.first; param; param = param->next) { if(param->kind == 8 && ((param->__anon1._class && param->__anon1._class->__anon1.registered && param->__anon1._class->__anon1.registered->type == 1) || !strcmp(param->__anon1._class->string, "String")) && !param->constant) { if(!strcmp(param->__anon1._class->string, "String")) { DeclareClass((((void *)0)), FindClass("StaticString"), "__ecereClass_StaticString"); __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " __ecereObject.returnBuffer.Unserialize((StaticString)%s);\n", param->name); } else __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " __ecereObject.returnBuffer.Unserialize(%s);\n", param->name); } } if(method->dataType->__anon1.__anon2.returnType->kind != 0) { if(method->dataType->__anon1.__anon2.returnType->kind == 8 && !strcmp(method->dataType->__anon1.__anon2.returnType->__anon1._class->string, "String")) { DeclareClass((((void *)0)), FindClass("StaticString"), "__ecereClass_StaticString"); __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " __ecereObject.returnBuffer.Unserialize((StaticString)__ecereResult);\n"); } else __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " __ecereObject.returnBuffer.Unserialize(__ecereResult);\n"); } __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " }\n"); __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " else\n"); __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " ((%s)this).%s::%s(", _class->fullName, _class->fullName, method->name); for(param = method->dataType->__anon1.__anon2.params.first; param; param = param->next) { __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, "%s", param->name); if(param->next) __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, ", "); } __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, ");\n"); __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " __ecereObject.returnBuffer.Free();\n"); __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " __ecereMethod___ecereNameSpace__ecere__sys__Mutex_Release(__ecereObject.mutex);\n"); __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " delete __ecereObject;\n"); if(method->dataType->__anon1.__anon2.returnType->kind != 0) { __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " return __ecereResult;\n"); } } __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " }\n"); } } } __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, "}\n"); } } } } struct __ecereNameSpace__ecere__com__GlobalFunction; extern struct __ecereNameSpace__ecere__com__GlobalFunction * __ecereNameSpace__ecere__com__eSystem_FindFunction(struct __ecereNameSpace__ecere__com__Instance * module, const char * name); struct __ecereNameSpace__ecere__com__GlobalFunction { struct __ecereNameSpace__ecere__com__GlobalFunction * prev; struct __ecereNameSpace__ecere__com__GlobalFunction * next; const char * name; int (* function)(); struct __ecereNameSpace__ecere__com__Instance * module; struct __ecereNameSpace__ecere__com__NameSpace * nameSpace; const char * dataTypeString; struct Type * dataType; void * symbol; } ecere_gcc_struct; static void WriteMain(const char * fileName) { struct __ecereNameSpace__ecere__com__Instance * f = __ecereNameSpace__ecere__sys__FileOpen(fileName, 2); if(f) { struct ModuleImport * module; struct ModuleInfo * defModule; unsigned int anyMethod = 0, anyProp = 0, anyFunction = 0; struct ImportedModule * importedModule; __ecereNameSpace__ecere__sys__GetLastDirectory(fileName, mainModuleName); __ecereNameSpace__ecere__sys__StripExtension(mainModuleName); if(!projectName[0]) { strcpy(projectName, mainModuleName); __ecereNameSpace__ecere__sys__StripExtension(projectName); } FixModuleName(mainModuleName); if(targetPlatform == 1 && !isConsole && !isStaticLibrary && !isDynamicLibrary) { (__extension__ ({ unsigned int (* __internal_VirtualMethod)(struct __ecereNameSpace__ecere__com__Instance *, const char * string); __internal_VirtualMethod = ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char * string))__extension__ ({ struct __ecereNameSpace__ecere__com__Instance * __internal_ClassInst = f; __internal_ClassInst ? __internal_ClassInst->_vTbl : __ecereClass___ecereNameSpace__ecere__sys__File->_vTbl; })[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts]); __internal_VirtualMethod ? __internal_VirtualMethod(f, "typedef void * HINSTANCE;\n") : (unsigned int)1; })); (__extension__ ({ unsigned int (* __internal_VirtualMethod)(struct __ecereNameSpace__ecere__com__Instance *, const char * string); __internal_VirtualMethod = ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char * string))__extension__ ({ struct __ecereNameSpace__ecere__com__Instance * __internal_ClassInst = f; __internal_ClassInst ? __internal_ClassInst->_vTbl : __ecereClass___ecereNameSpace__ecere__sys__File->_vTbl; })[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts]); __internal_VirtualMethod ? __internal_VirtualMethod(f, "#define WINAPI __stdcall\n") : (unsigned int)1; })); } for(importedModule = _defines.first; importedModule; importedModule = importedModule->next) { if(importedModule->type == 0) { __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, "import "); if(importedModule->importType == 1) __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, "static ", importedModule->name); __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, "\"%s\"\n", importedModule->name); } } (__extension__ ({ unsigned int (* __internal_VirtualMethod)(struct __ecereNameSpace__ecere__com__Instance *, const char * string); __internal_VirtualMethod = ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char * string))__extension__ ({ struct __ecereNameSpace__ecere__com__Instance * __internal_ClassInst = f; __internal_ClassInst ? __internal_ClassInst->_vTbl : __ecereClass___ecereNameSpace__ecere__sys__File->_vTbl; })[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts]); __internal_VirtualMethod ? __internal_VirtualMethod(f, "default:\n") : (unsigned int)1; })); (__extension__ ({ unsigned int (* __internal_VirtualMethod)(struct __ecereNameSpace__ecere__com__Instance *, const char * string); __internal_VirtualMethod = ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char * string))__extension__ ({ struct __ecereNameSpace__ecere__com__Instance * __internal_ClassInst = f; __internal_ClassInst ? __internal_ClassInst->_vTbl : __ecereClass___ecereNameSpace__ecere__sys__File->_vTbl; })[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts]); __internal_VirtualMethod ? __internal_VirtualMethod(f, "static Module __currentModule;\n\n") : (unsigned int)1; })); if(!isStaticLibrary) (__extension__ ({ unsigned int (* __internal_VirtualMethod)(struct __ecereNameSpace__ecere__com__Instance *, const char * string); __internal_VirtualMethod = ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char * string))__extension__ ({ struct __ecereNameSpace__ecere__com__Instance * __internal_ClassInst = f; __internal_ClassInst ? __internal_ClassInst->_vTbl : __ecereClass___ecereNameSpace__ecere__sys__File->_vTbl; })[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts]); __internal_VirtualMethod ? __internal_VirtualMethod(f, "Module __thisModule;\n\n") : (unsigned int)1; })); BindDCOMServer(); BindDCOMClient(); if(dcomSymbols) __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, "void __ecereRegisterModule_%s(Module module);\n\n", mainModuleName); for(module = _imports.first; module; module = module->next) { struct ClassImport * _class; struct FunctionImport * function; if(module->importType == 1) { { __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, "bool __ecereDll_Load_%s(Module module);\n", module->name); __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, "bool __ecereDll_Unload_%s(Module module);\n", module->name); } } for(_class = module->classes.first; _class; _class = _class->next) { struct MethodImport * method; struct PropertyImport * prop; char className[1024] = ""; struct __ecereNameSpace__ecere__com__Class * regClass = __ecereNameSpace__ecere__com__eSystem_FindClass(privateModule, _class->name); FullClassNameCat(className, _class->name, 1); if(_class->itself) __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, "Class __ecereClass_%s;\n", className); { { for(method = _class->methods.first; method; method = method->next) { struct __ecereNameSpace__ecere__com__Method * meth = __ecereNameSpace__ecere__com__eClass_FindMethod(regClass, method->name, privateModule); if(meth && !meth->dataType) { struct Context * context = SetupTemplatesContext(regClass); meth->dataType = ProcessTypeString(meth->dataTypeString, 0); FinishTemplatesContext(context); } if(method->isVirtual) __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, "int __ecereVMethodID_%s_%s;\n", className, method->name); else if((!strcmp(_class->name, "float") || !strcmp(_class->name, "double") || module->name) && module->importType != 1 && (!meth || !meth->dataType->dllExport)) { __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, "int (*__ecereMethod_%s_%s)();\n", className, method->name); } anyMethod = 1; } } for(prop = _class->properties.first; prop; prop = prop->next) { char propName[1024]; propName[0] = 0; FullClassNameCat(propName, prop->name, 1); if((!strcmp(_class->name, "float") || !strcmp(_class->name, "double") || module->name) && module->importType != 1) { if(prop->hasSet) __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, "void * __ecereProp_%s_Set_%s;\n", className, propName); if(prop->hasGet) __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, "void * __ecereProp_%s_Get_%s;\n", className, propName); } __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, "Property __ecereProp_%s_%s;\n", className, propName); anyProp = 1; } } } for(function = module->functions.first; function; function = function->next) { struct __ecereNameSpace__ecere__com__GlobalFunction * func = __ecereNameSpace__ecere__com__eSystem_FindFunction(privateModule, function->name); if(func && !func->dataType) func->dataType = ProcessTypeString(func->dataTypeString, 0); if(module->name && module->importType != 1 && (!func || !func->dataType || !func->dataType->dllExport)) { char functionName[1024]; functionName[0] = 0; FullClassNameCat(functionName, function->name, 0); __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, "void * __ecereFunction_%s;\n", functionName); anyFunction = 1; } } } for(defModule = modules.first; defModule; defModule = defModule->next) { char moduleName[1024]; strcpy(moduleName, defModule->name); FixModuleName(moduleName); __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, "void __ecereRegisterModule_%s(Module module);\n", moduleName); __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, "void __ecereUnregisterModule_%s(Module module);\n", moduleName); if(defModule->globalInstance) { __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, "void __ecereCreateModuleInstances_%s();\n", moduleName); __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, "void __ecereDestroyModuleInstances_%s();\n", moduleName); } } if(dcomSymbols) { __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, "\n"); (__extension__ ({ unsigned int (* __internal_VirtualMethod)(struct __ecereNameSpace__ecere__com__Instance *, int pos, int mode); __internal_VirtualMethod = ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, int pos, int mode))__extension__ ({ struct __ecereNameSpace__ecere__com__Instance * __internal_ClassInst = dcomSymbols; __internal_ClassInst ? __internal_ClassInst->_vTbl : __ecereClass___ecereNameSpace__ecere__sys__File->_vTbl; })[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Seek]); __internal_VirtualMethod ? __internal_VirtualMethod(dcomSymbols, 0, 0) : (unsigned int)1; })); while(!(__extension__ ({ unsigned int (* __internal_VirtualMethod)(struct __ecereNameSpace__ecere__com__Instance *); __internal_VirtualMethod = ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *))__extension__ ({ struct __ecereNameSpace__ecere__com__Instance * __internal_ClassInst = dcomSymbols; __internal_ClassInst ? __internal_ClassInst->_vTbl : __ecereClass___ecereNameSpace__ecere__sys__File->_vTbl; })[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Eof]); __internal_VirtualMethod ? __internal_VirtualMethod(dcomSymbols) : (unsigned int)1; }))) { char buffer[4096]; int read = (__extension__ ({ int (* __internal_VirtualMethod)(struct __ecereNameSpace__ecere__com__Instance *, void * buffer, unsigned int size, unsigned int count); __internal_VirtualMethod = ((int (*)(struct __ecereNameSpace__ecere__com__Instance *, void * buffer, unsigned int size, unsigned int count))__extension__ ({ struct __ecereNameSpace__ecere__com__Instance * __internal_ClassInst = dcomSymbols; __internal_ClassInst ? __internal_ClassInst->_vTbl : __ecereClass___ecereNameSpace__ecere__sys__File->_vTbl; })[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Read]); __internal_VirtualMethod ? __internal_VirtualMethod(dcomSymbols, buffer, 1, sizeof (buffer)) : (int)1; })); if(!read) break; (__extension__ ({ int (* __internal_VirtualMethod)(struct __ecereNameSpace__ecere__com__Instance *, const void * buffer, unsigned int size, unsigned int count); __internal_VirtualMethod = ((int (*)(struct __ecereNameSpace__ecere__com__Instance *, const void * buffer, unsigned int size, unsigned int count))__extension__ ({ struct __ecereNameSpace__ecere__com__Instance * __internal_ClassInst = f; __internal_ClassInst ? __internal_ClassInst->_vTbl : __ecereClass___ecereNameSpace__ecere__sys__File->_vTbl; })[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Write]); __internal_VirtualMethod ? __internal_VirtualMethod(f, buffer, 1, read) : (int)1; })); } __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, "\n"); } if(isStaticLibrary) { __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, "\nbool __ecereDll_Load_%s(Module module)\n{\n", projectName); } else if(isDynamicLibrary) { if(targetPlatform == 1) (__extension__ ({ unsigned int (* __internal_VirtualMethod)(struct __ecereNameSpace__ecere__com__Instance *, const char * string); __internal_VirtualMethod = ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char * string))__extension__ ({ struct __ecereNameSpace__ecere__com__Instance * __internal_ClassInst = f; __internal_ClassInst ? __internal_ClassInst->_vTbl : __ecereClass___ecereNameSpace__ecere__sys__File->_vTbl; })[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts]); __internal_VirtualMethod ? __internal_VirtualMethod(f, "\ndllexport bool __stdcall __ecereDll_Load(Module module)\n{\n") : (unsigned int)1; })); else (__extension__ ({ unsigned int (* __internal_VirtualMethod)(struct __ecereNameSpace__ecere__com__Instance *, const char * string); __internal_VirtualMethod = ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char * string))__extension__ ({ struct __ecereNameSpace__ecere__com__Instance * __internal_ClassInst = f; __internal_ClassInst ? __internal_ClassInst->_vTbl : __ecereClass___ecereNameSpace__ecere__sys__File->_vTbl; })[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts]); __internal_VirtualMethod ? __internal_VirtualMethod(f, "\ndllexport bool __ecereDll_Load(Module module)\n{\n") : (unsigned int)1; })); } else if(targetPlatform == 1 && !isConsole) { (__extension__ ({ unsigned int (* __internal_VirtualMethod)(struct __ecereNameSpace__ecere__com__Instance *, const char * string); __internal_VirtualMethod = ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char * string))__extension__ ({ struct __ecereNameSpace__ecere__com__Instance * __internal_ClassInst = f; __internal_ClassInst ? __internal_ClassInst->_vTbl : __ecereClass___ecereNameSpace__ecere__sys__File->_vTbl; })[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts]); __internal_VirtualMethod ? __internal_VirtualMethod(f, "\nint WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst, char * cmdLine, int show)\n{\n") : (unsigned int)1; })); } else (__extension__ ({ unsigned int (* __internal_VirtualMethod)(struct __ecereNameSpace__ecere__com__Instance *, const char * string); __internal_VirtualMethod = ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char * string))__extension__ ({ struct __ecereNameSpace__ecere__com__Instance * __internal_ClassInst = f; __internal_ClassInst ? __internal_ClassInst->_vTbl : __ecereClass___ecereNameSpace__ecere__sys__File->_vTbl; })[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts]); __internal_VirtualMethod ? __internal_VirtualMethod(f, "\nint main(int _argc, char * _argv[])\n{\n") : (unsigned int)1; })); if(!isDynamicLibrary) { (__extension__ ({ unsigned int (* __internal_VirtualMethod)(struct __ecereNameSpace__ecere__com__Instance *, const char * string); __internal_VirtualMethod = ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char * string))__extension__ ({ struct __ecereNameSpace__ecere__com__Instance * __internal_ClassInst = f; __internal_ClassInst ? __internal_ClassInst->_vTbl : __ecereClass___ecereNameSpace__ecere__sys__File->_vTbl; })[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts]); __internal_VirtualMethod ? __internal_VirtualMethod(f, " int exitCode;\n") : (unsigned int)1; })); (__extension__ ({ unsigned int (* __internal_VirtualMethod)(struct __ecereNameSpace__ecere__com__Instance *, const char * string); __internal_VirtualMethod = ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char * string))__extension__ ({ struct __ecereNameSpace__ecere__com__Instance * __internal_ClassInst = f; __internal_ClassInst ? __internal_ClassInst->_vTbl : __ecereClass___ecereNameSpace__ecere__sys__File->_vTbl; })[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts]); __internal_VirtualMethod ? __internal_VirtualMethod(f, " Module module;\n") : (unsigned int)1; })); } (__extension__ ({ unsigned int (* __internal_VirtualMethod)(struct __ecereNameSpace__ecere__com__Instance *, const char * string); __internal_VirtualMethod = ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char * string))__extension__ ({ struct __ecereNameSpace__ecere__com__Instance * __internal_ClassInst = f; __internal_ClassInst ? __internal_ClassInst->_vTbl : __ecereClass___ecereNameSpace__ecere__sys__File->_vTbl; })[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts]); __internal_VirtualMethod ? __internal_VirtualMethod(f, " __attribute__((unused)) Class _class;\n") : (unsigned int)1; })); if(anyMethod) (__extension__ ({ unsigned int (* __internal_VirtualMethod)(struct __ecereNameSpace__ecere__com__Instance *, const char * string); __internal_VirtualMethod = ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char * string))__extension__ ({ struct __ecereNameSpace__ecere__com__Instance * __internal_ClassInst = f; __internal_ClassInst ? __internal_ClassInst->_vTbl : __ecereClass___ecereNameSpace__ecere__sys__File->_vTbl; })[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts]); __internal_VirtualMethod ? __internal_VirtualMethod(f, " __attribute__((unused)) Method method;\n") : (unsigned int)1; })); if(anyProp) (__extension__ ({ unsigned int (* __internal_VirtualMethod)(struct __ecereNameSpace__ecere__com__Instance *, const char * string); __internal_VirtualMethod = ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char * string))__extension__ ({ struct __ecereNameSpace__ecere__com__Instance * __internal_ClassInst = f; __internal_ClassInst ? __internal_ClassInst->_vTbl : __ecereClass___ecereNameSpace__ecere__sys__File->_vTbl; })[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts]); __internal_VirtualMethod ? __internal_VirtualMethod(f, " __attribute__((unused)) Property _property;\n") : (unsigned int)1; })); if(anyFunction) (__extension__ ({ unsigned int (* __internal_VirtualMethod)(struct __ecereNameSpace__ecere__com__Instance *, const char * string); __internal_VirtualMethod = ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char * string))__extension__ ({ struct __ecereNameSpace__ecere__com__Instance * __internal_ClassInst = f; __internal_ClassInst ? __internal_ClassInst->_vTbl : __ecereClass___ecereNameSpace__ecere__sys__File->_vTbl; })[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts]); __internal_VirtualMethod ? __internal_VirtualMethod(f, " __attribute__((unused)) GlobalFunction function;\n") : (unsigned int)1; })); (__extension__ ({ unsigned int (* __internal_VirtualMethod)(struct __ecereNameSpace__ecere__com__Instance *, const char * string); __internal_VirtualMethod = ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char * string))__extension__ ({ struct __ecereNameSpace__ecere__com__Instance * __internal_ClassInst = f; __internal_ClassInst ? __internal_ClassInst->_vTbl : __ecereClass___ecereNameSpace__ecere__sys__File->_vTbl; })[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts]); __internal_VirtualMethod ? __internal_VirtualMethod(f, "\n") : (unsigned int)1; })); if(disabledPooling) { (__extension__ ({ unsigned int (* __internal_VirtualMethod)(struct __ecereNameSpace__ecere__com__Instance *, const char * string); __internal_VirtualMethod = ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char * string))__extension__ ({ struct __ecereNameSpace__ecere__com__Instance * __internal_ClassInst = f; __internal_ClassInst ? __internal_ClassInst->_vTbl : __ecereClass___ecereNameSpace__ecere__sys__File->_vTbl; })[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts]); __internal_VirtualMethod ? __internal_VirtualMethod(f, " eSystem_SetPoolingDisabled(true);\n") : (unsigned int)1; })); (__extension__ ({ unsigned int (* __internal_VirtualMethod)(struct __ecereNameSpace__ecere__com__Instance *, const char * string); __internal_VirtualMethod = ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char * string))__extension__ ({ struct __ecereNameSpace__ecere__com__Instance * __internal_ClassInst = f; __internal_ClassInst ? __internal_ClassInst->_vTbl : __ecereClass___ecereNameSpace__ecere__sys__File->_vTbl; })[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts]); __internal_VirtualMethod ? __internal_VirtualMethod(f, "\n") : (unsigned int)1; })); } if(isDynamicLibrary) { (__extension__ ({ unsigned int (* __internal_VirtualMethod)(struct __ecereNameSpace__ecere__com__Instance *, const char * string); __internal_VirtualMethod = ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char * string))__extension__ ({ struct __ecereNameSpace__ecere__com__Instance * __internal_ClassInst = f; __internal_ClassInst ? __internal_ClassInst->_vTbl : __ecereClass___ecereNameSpace__ecere__sys__File->_vTbl; })[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts]); __internal_VirtualMethod ? __internal_VirtualMethod(f, " if(!__currentModule)\n") : (unsigned int)1; })); (__extension__ ({ unsigned int (* __internal_VirtualMethod)(struct __ecereNameSpace__ecere__com__Instance *, const char * string); __internal_VirtualMethod = ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char * string))__extension__ ({ struct __ecereNameSpace__ecere__com__Instance * __internal_ClassInst = f; __internal_ClassInst ? __internal_ClassInst->_vTbl : __ecereClass___ecereNameSpace__ecere__sys__File->_vTbl; })[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts]); __internal_VirtualMethod ? __internal_VirtualMethod(f, " {\n") : (unsigned int)1; })); (__extension__ ({ unsigned int (* __internal_VirtualMethod)(struct __ecereNameSpace__ecere__com__Instance *, const char * string); __internal_VirtualMethod = ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char * string))__extension__ ({ struct __ecereNameSpace__ecere__com__Instance * __internal_ClassInst = f; __internal_ClassInst ? __internal_ClassInst->_vTbl : __ecereClass___ecereNameSpace__ecere__sys__File->_vTbl; })[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts]); __internal_VirtualMethod ? __internal_VirtualMethod(f, " __currentModule = module;\n") : (unsigned int)1; })); if(!isStaticLibrary) (__extension__ ({ unsigned int (* __internal_VirtualMethod)(struct __ecereNameSpace__ecere__com__Instance *, const char * string); __internal_VirtualMethod = ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char * string))__extension__ ({ struct __ecereNameSpace__ecere__com__Instance * __internal_ClassInst = f; __internal_ClassInst ? __internal_ClassInst->_vTbl : __ecereClass___ecereNameSpace__ecere__sys__File->_vTbl; })[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts]); __internal_VirtualMethod ? __internal_VirtualMethod(f, " __thisModule = module;\n") : (unsigned int)1; })); (__extension__ ({ unsigned int (* __internal_VirtualMethod)(struct __ecereNameSpace__ecere__com__Instance *, const char * string); __internal_VirtualMethod = ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char * string))__extension__ ({ struct __ecereNameSpace__ecere__com__Instance * __internal_ClassInst = f; __internal_ClassInst ? __internal_ClassInst->_vTbl : __ecereClass___ecereNameSpace__ecere__sys__File->_vTbl; })[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts]); __internal_VirtualMethod ? __internal_VirtualMethod(f, " }\n\n") : (unsigned int)1; })); } else if(targetPlatform == 1 && !isConsole) (__extension__ ({ unsigned int (* __internal_VirtualMethod)(struct __ecereNameSpace__ecere__com__Instance *, const char * string); __internal_VirtualMethod = ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char * string))__extension__ ({ struct __ecereNameSpace__ecere__com__Instance * __internal_ClassInst = f; __internal_ClassInst ? __internal_ClassInst->_vTbl : __ecereClass___ecereNameSpace__ecere__sys__File->_vTbl; })[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts]); __internal_VirtualMethod ? __internal_VirtualMethod(f, " __thisModule = __currentModule = module = __ecere_COM_Initialize(1, 0, null);\n\n") : (unsigned int)1; })); else (__extension__ ({ unsigned int (* __internal_VirtualMethod)(struct __ecereNameSpace__ecere__com__Instance *, const char * string); __internal_VirtualMethod = ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char * string))__extension__ ({ struct __ecereNameSpace__ecere__com__Instance * __internal_ClassInst = f; __internal_ClassInst ? __internal_ClassInst->_vTbl : __ecereClass___ecereNameSpace__ecere__sys__File->_vTbl; })[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts]); __internal_VirtualMethod ? __internal_VirtualMethod(f, " __thisModule = __currentModule = module = __ecere_COM_Initialize(1, _argc, (void *)_argv);\n\n") : (unsigned int)1; })); if(_imports.count) { for(module = _imports.first; module; module = module->next) { if(module->name) { { if(module->importType == 1) __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " eModule_LoadStatic(module, \"%s\", %s, __ecereDll_Load_%s, __ecereDll_Unload_%s);\n", module->name, (module->importAccess == 2) ? "privateAccess" : "publicAccess", module->name, module->name); else __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " eModule_Load(module, \"%s\", %s);\n", module->name, (module->importAccess == 2) ? "privateAccess" : "publicAccess"); } } } __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, "\n"); } if(modules.count) { for(defModule = modules.first; defModule; defModule = defModule->next) { char moduleName[1024]; strcpy(moduleName, defModule->name); FixModuleName(moduleName); __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " __ecereRegisterModule_%s(module);\n", moduleName); } __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, "\n"); } if(dcomSymbols) { __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " __ecereRegisterModule_%s(module);\n\n", mainModuleName); (__ecereNameSpace__ecere__com__eInstance_DecRef(dcomSymbols), dcomSymbols = 0); } if(isDynamicLibrary) { (__extension__ ({ unsigned int (* __internal_VirtualMethod)(struct __ecereNameSpace__ecere__com__Instance *, const char * string); __internal_VirtualMethod = ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char * string))__extension__ ({ struct __ecereNameSpace__ecere__com__Instance * __internal_ClassInst = f; __internal_ClassInst ? __internal_ClassInst->_vTbl : __ecereClass___ecereNameSpace__ecere__sys__File->_vTbl; })[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts]); __internal_VirtualMethod ? __internal_VirtualMethod(f, " if(__currentModule == module)\n") : (unsigned int)1; })); (__extension__ ({ unsigned int (* __internal_VirtualMethod)(struct __ecereNameSpace__ecere__com__Instance *, const char * string); __internal_VirtualMethod = ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char * string))__extension__ ({ struct __ecereNameSpace__ecere__com__Instance * __internal_ClassInst = f; __internal_ClassInst ? __internal_ClassInst->_vTbl : __ecereClass___ecereNameSpace__ecere__sys__File->_vTbl; })[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts]); __internal_VirtualMethod ? __internal_VirtualMethod(f, " {\n") : (unsigned int)1; })); } for(module = _imports.first; module; module = module->next) { struct ClassImport * _class; struct FunctionImport * function; if(module->classes.count) { for(_class = module->classes.first; _class; _class = _class->next) { struct __ecereNameSpace__ecere__com__Class * regClass = __ecereNameSpace__ecere__com__eSystem_FindClass(privateModule, _class->name); { struct MethodImport * method; struct PropertyImport * prop; char classID[1024]; char className[1024] = ""; FullClassNameCat(className, _class->name, 1); if(_class->itself) sprintf(classID, "__ecereClass_%s", className); else strcpy(classID, "_class"); if(isDynamicLibrary && !isStaticLibrary) __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " %s = eSystem_FindClass(__currentModule, \"%s\");\n", classID, _class->name); else __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " %s = eSystem_FindClass(module, \"%s\");\n", classID, _class->name); for(method = _class->methods.first; method; method = method->next) { struct __ecereNameSpace__ecere__com__Method * meth = __ecereNameSpace__ecere__com__eClass_FindMethod(regClass, method->name, privateModule); if(!meth || !meth->dataType->dllExport) { if(method->isVirtual || ((!strcmp(_class->name, "float") || !strcmp(_class->name, "double") || module->name) && module->importType != 1)) { __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " method = eClass_FindMethod(%s, \"%s\", module);\n", classID, method->name); if(method->isVirtual) __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " if(method) __ecereVMethodID_%s_%s = method.vid;\n", className, method->name); else __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " if(method) __ecereMethod_%s_%s = method.function;\n", className, method->name); } } } for(prop = _class->properties.first; prop; prop = prop->next) { char propName[1024]; propName[0] = 0; FullClassNameCat(propName, prop->name, 1); __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " __ecereProp_%s_%s = _property = eClass_FindProperty(%s, \"%s\", module);\n", className, propName, classID, prop->name); if((!strcmp(_class->name, "float") || !strcmp(_class->name, "double") || module->name) && module->importType != 1) { if(prop->hasSet) __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " __ecereProp_%s_Set_%s = _property.Set;\n", className, propName); if(prop->hasGet) __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " __ecereProp_%s_Get_%s = _property.Get;\n", className, propName); } } __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, "\n"); } } } if(module->functions.count) { for(function = module->functions.first; function; function = function->next) { struct __ecereNameSpace__ecere__com__GlobalFunction * func = __ecereNameSpace__ecere__com__eSystem_FindFunction(privateModule, function->name); if(module->name && module->importType != 1 && (!func || !func->dataType || !func->dataType->dllExport)) { char functionName[1024]; functionName[0] = 0; FullClassNameCat(functionName, function->name, 0); if(isDynamicLibrary && !isStaticLibrary) __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " function = eSystem_FindFunction(__currentModule, \"%s\");\n", function->name); else __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " function = eSystem_FindFunction(module, \"%s\");\n", function->name); __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " if(function) __ecereFunction_%s = function.function;\n", functionName); __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, "\n"); } } __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, "\n"); } } for(defModule = modules.first; defModule; defModule = defModule->next) if(defModule->globalInstance) { if(!strcmp(defModule->name, "i18n")) __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " __ecereCreateModuleInstances_i18n();\n"); } if(i18n) { if(isDynamicLibrary) __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " LoadTranslatedStrings(\"%s\", \"%s\");\n", projectName, projectName); else __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " LoadTranslatedStrings(null, \"%s\");\n", projectName); } if(isDynamicLibrary) { (__extension__ ({ unsigned int (* __internal_VirtualMethod)(struct __ecereNameSpace__ecere__com__Instance *, const char * string); __internal_VirtualMethod = ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char * string))__extension__ ({ struct __ecereNameSpace__ecere__com__Instance * __internal_ClassInst = f; __internal_ClassInst ? __internal_ClassInst->_vTbl : __ecereClass___ecereNameSpace__ecere__sys__File->_vTbl; })[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts]); __internal_VirtualMethod ? __internal_VirtualMethod(f, " }\n") : (unsigned int)1; })); } if(!isDynamicLibrary && thisAppClass) { __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " _class = eSystem_FindClass(__currentModule, \"%s\");\n", thisAppClass->name); __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " eInstance_Evolve((Instance *)&__currentModule, _class);\n"); __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " __thisModule = __currentModule;\n"); } if(isDynamicLibrary) { (__extension__ ({ unsigned int (* __internal_VirtualMethod)(struct __ecereNameSpace__ecere__com__Instance *, const char * string); __internal_VirtualMethod = ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char * string))__extension__ ({ struct __ecereNameSpace__ecere__com__Instance * __internal_ClassInst = f; __internal_ClassInst ? __internal_ClassInst->_vTbl : __ecereClass___ecereNameSpace__ecere__sys__File->_vTbl; })[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts]); __internal_VirtualMethod ? __internal_VirtualMethod(f, " if(__currentModule == module)\n") : (unsigned int)1; })); (__extension__ ({ unsigned int (* __internal_VirtualMethod)(struct __ecereNameSpace__ecere__com__Instance *, const char * string); __internal_VirtualMethod = ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char * string))__extension__ ({ struct __ecereNameSpace__ecere__com__Instance * __internal_ClassInst = f; __internal_ClassInst ? __internal_ClassInst->_vTbl : __ecereClass___ecereNameSpace__ecere__sys__File->_vTbl; })[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts]); __internal_VirtualMethod ? __internal_VirtualMethod(f, " {\n") : (unsigned int)1; })); } if(modules.count) { for(defModule = modules.first; defModule; defModule = defModule->next) if(defModule->globalInstance) { char moduleName[1024]; if(!strcmp(defModule->name, "i18n")) continue; strcpy(moduleName, defModule->name); FixModuleName(moduleName); __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " __ecereCreateModuleInstances_%s();\n", moduleName); } __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, "\n"); } if(isDynamicLibrary) { (__extension__ ({ unsigned int (* __internal_VirtualMethod)(struct __ecereNameSpace__ecere__com__Instance *, const char * string); __internal_VirtualMethod = ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char * string))__extension__ ({ struct __ecereNameSpace__ecere__com__Instance * __internal_ClassInst = f; __internal_ClassInst ? __internal_ClassInst->_vTbl : __ecereClass___ecereNameSpace__ecere__sys__File->_vTbl; })[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts]); __internal_VirtualMethod ? __internal_VirtualMethod(f, " }\n") : (unsigned int)1; })); } if(!isDynamicLibrary && thisAppClass) { __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " ((void(*)(void *))(void *)__currentModule._vTbl[12])(__currentModule);\n"); } if(isDynamicLibrary) { (__extension__ ({ unsigned int (* __internal_VirtualMethod)(struct __ecereNameSpace__ecere__com__Instance *, const char * string); __internal_VirtualMethod = ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char * string))__extension__ ({ struct __ecereNameSpace__ecere__com__Instance * __internal_ClassInst = f; __internal_ClassInst ? __internal_ClassInst->_vTbl : __ecereClass___ecereNameSpace__ecere__sys__File->_vTbl; })[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts]); __internal_VirtualMethod ? __internal_VirtualMethod(f, " return true;\n") : (unsigned int)1; })); (__extension__ ({ unsigned int (* __internal_VirtualMethod)(struct __ecereNameSpace__ecere__com__Instance *, const char * string); __internal_VirtualMethod = ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char * string))__extension__ ({ struct __ecereNameSpace__ecere__com__Instance * __internal_ClassInst = f; __internal_ClassInst ? __internal_ClassInst->_vTbl : __ecereClass___ecereNameSpace__ecere__sys__File->_vTbl; })[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts]); __internal_VirtualMethod ? __internal_VirtualMethod(f, "}\n") : (unsigned int)1; })); if(isStaticLibrary) { __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, "\nbool __ecereDll_Unload_%s(Module module)\n{\n", projectName); } else { if(targetPlatform == 1) (__extension__ ({ unsigned int (* __internal_VirtualMethod)(struct __ecereNameSpace__ecere__com__Instance *, const char * string); __internal_VirtualMethod = ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char * string))__extension__ ({ struct __ecereNameSpace__ecere__com__Instance * __internal_ClassInst = f; __internal_ClassInst ? __internal_ClassInst->_vTbl : __ecereClass___ecereNameSpace__ecere__sys__File->_vTbl; })[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts]); __internal_VirtualMethod ? __internal_VirtualMethod(f, "\ndllexport bool __stdcall __ecereDll_Unload(Module module)\n{\n") : (unsigned int)1; })); else (__extension__ ({ unsigned int (* __internal_VirtualMethod)(struct __ecereNameSpace__ecere__com__Instance *, const char * string); __internal_VirtualMethod = ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char * string))__extension__ ({ struct __ecereNameSpace__ecere__com__Instance * __internal_ClassInst = f; __internal_ClassInst ? __internal_ClassInst->_vTbl : __ecereClass___ecereNameSpace__ecere__sys__File->_vTbl; })[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts]); __internal_VirtualMethod ? __internal_VirtualMethod(f, "\ndllexport bool __ecereDll_Unload(Module module)\n{\n") : (unsigned int)1; })); } } if(isDynamicLibrary) { (__extension__ ({ unsigned int (* __internal_VirtualMethod)(struct __ecereNameSpace__ecere__com__Instance *, const char * string); __internal_VirtualMethod = ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char * string))__extension__ ({ struct __ecereNameSpace__ecere__com__Instance * __internal_ClassInst = f; __internal_ClassInst ? __internal_ClassInst->_vTbl : __ecereClass___ecereNameSpace__ecere__sys__File->_vTbl; })[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts]); __internal_VirtualMethod ? __internal_VirtualMethod(f, " if(__currentModule == module)\n") : (unsigned int)1; })); (__extension__ ({ unsigned int (* __internal_VirtualMethod)(struct __ecereNameSpace__ecere__com__Instance *, const char * string); __internal_VirtualMethod = ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char * string))__extension__ ({ struct __ecereNameSpace__ecere__com__Instance * __internal_ClassInst = f; __internal_ClassInst ? __internal_ClassInst->_vTbl : __ecereClass___ecereNameSpace__ecere__sys__File->_vTbl; })[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts]); __internal_VirtualMethod ? __internal_VirtualMethod(f, " {\n") : (unsigned int)1; })); } { unsigned int destroyI18n = 0; if(modules.count) { for(defModule = modules.last; defModule; defModule = defModule->prev) if(defModule->globalInstance) { char moduleName[1024]; if(!strcmp(defModule->name, "i18n")) { destroyI18n = 1; continue; } strcpy(moduleName, defModule->name); FixModuleName(moduleName); __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " __ecereDestroyModuleInstances_%s();\n", moduleName); } __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, "\n"); } if(i18n) __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " UnloadTranslatedStrings(\"%s\");\n", projectName); if(destroyI18n) __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " __ecereDestroyModuleInstances_i18n();\n"); } if(isDynamicLibrary) { (__extension__ ({ unsigned int (* __internal_VirtualMethod)(struct __ecereNameSpace__ecere__com__Instance *, const char * string); __internal_VirtualMethod = ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char * string))__extension__ ({ struct __ecereNameSpace__ecere__com__Instance * __internal_ClassInst = f; __internal_ClassInst ? __internal_ClassInst->_vTbl : __ecereClass___ecereNameSpace__ecere__sys__File->_vTbl; })[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts]); __internal_VirtualMethod ? __internal_VirtualMethod(f, " }\n") : (unsigned int)1; })); if(isDynamicLibrary) { } if(modules.count) { for(defModule = modules.first; defModule; defModule = defModule->next) { char moduleName[1024]; strcpy(moduleName, defModule->name); FixModuleName(moduleName); __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, " __ecereUnregisterModule_%s(module);\n", moduleName); } __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(f, "\n"); } (__extension__ ({ unsigned int (* __internal_VirtualMethod)(struct __ecereNameSpace__ecere__com__Instance *, const char * string); __internal_VirtualMethod = ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char * string))__extension__ ({ struct __ecereNameSpace__ecere__com__Instance * __internal_ClassInst = f; __internal_ClassInst ? __internal_ClassInst->_vTbl : __ecereClass___ecereNameSpace__ecere__sys__File->_vTbl; })[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts]); __internal_VirtualMethod ? __internal_VirtualMethod(f, " if(__currentModule == module)\n") : (unsigned int)1; })); (__extension__ ({ unsigned int (* __internal_VirtualMethod)(struct __ecereNameSpace__ecere__com__Instance *, const char * string); __internal_VirtualMethod = ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char * string))__extension__ ({ struct __ecereNameSpace__ecere__com__Instance * __internal_ClassInst = f; __internal_ClassInst ? __internal_ClassInst->_vTbl : __ecereClass___ecereNameSpace__ecere__sys__File->_vTbl; })[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts]); __internal_VirtualMethod ? __internal_VirtualMethod(f, " __currentModule = (void *)0;\n") : (unsigned int)1; })); if(!isStaticLibrary) { (__extension__ ({ unsigned int (* __internal_VirtualMethod)(struct __ecereNameSpace__ecere__com__Instance *, const char * string); __internal_VirtualMethod = ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char * string))__extension__ ({ struct __ecereNameSpace__ecere__com__Instance * __internal_ClassInst = f; __internal_ClassInst ? __internal_ClassInst->_vTbl : __ecereClass___ecereNameSpace__ecere__sys__File->_vTbl; })[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts]); __internal_VirtualMethod ? __internal_VirtualMethod(f, " if(__thisModule == module)\n") : (unsigned int)1; })); (__extension__ ({ unsigned int (* __internal_VirtualMethod)(struct __ecereNameSpace__ecere__com__Instance *, const char * string); __internal_VirtualMethod = ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char * string))__extension__ ({ struct __ecereNameSpace__ecere__com__Instance * __internal_ClassInst = f; __internal_ClassInst ? __internal_ClassInst->_vTbl : __ecereClass___ecereNameSpace__ecere__sys__File->_vTbl; })[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts]); __internal_VirtualMethod ? __internal_VirtualMethod(f, " __thisModule = (void *)0;\n") : (unsigned int)1; })); } } if(!isDynamicLibrary) { (__extension__ ({ unsigned int (* __internal_VirtualMethod)(struct __ecereNameSpace__ecere__com__Instance *, const char * string); __internal_VirtualMethod = ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char * string))__extension__ ({ struct __ecereNameSpace__ecere__com__Instance * __internal_ClassInst = f; __internal_ClassInst ? __internal_ClassInst->_vTbl : __ecereClass___ecereNameSpace__ecere__sys__File->_vTbl; })[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts]); __internal_VirtualMethod ? __internal_VirtualMethod(f, "\n _class = eSystem_FindClass(__currentModule, \"ecere::com::Application\");\n exitCode = ((ecere::com::Application)__currentModule).exitCode;\n delete __currentModule;\n return exitCode;\n") : (unsigned int)1; })); } else (__extension__ ({ unsigned int (* __internal_VirtualMethod)(struct __ecereNameSpace__ecere__com__Instance *, const char * string); __internal_VirtualMethod = ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char * string))__extension__ ({ struct __ecereNameSpace__ecere__com__Instance * __internal_ClassInst = f; __internal_ClassInst ? __internal_ClassInst->_vTbl : __ecereClass___ecereNameSpace__ecere__sys__File->_vTbl; })[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts]); __internal_VirtualMethod ? __internal_VirtualMethod(f, " return true;\n") : (unsigned int)1; })); (__extension__ ({ unsigned int (* __internal_VirtualMethod)(struct __ecereNameSpace__ecere__com__Instance *, const char * string); __internal_VirtualMethod = ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char * string))__extension__ ({ struct __ecereNameSpace__ecere__com__Instance * __internal_ClassInst = f; __internal_ClassInst ? __internal_ClassInst->_vTbl : __ecereClass___ecereNameSpace__ecere__sys__File->_vTbl; })[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts]); __internal_VirtualMethod ? __internal_VirtualMethod(f, "}\n") : (unsigned int)1; })); __ecereNameSpace__ecere__com__eInstance_Delete(f); } } struct __ecereNameSpace__ecere__com__SubModule; struct __ecereNameSpace__ecere__com__SubModule { struct __ecereNameSpace__ecere__com__SubModule * prev; struct __ecereNameSpace__ecere__com__SubModule * next; struct __ecereNameSpace__ecere__com__Instance * module; int importMode; } ecere_gcc_struct; static struct __ecereNameSpace__ecere__com__Class * SearchAppClass_Module(struct __ecereNameSpace__ecere__com__Instance * module) { struct __ecereNameSpace__ecere__com__Class * appClass; struct __ecereNameSpace__ecere__com__SubModule * subModule; appClass = FindAppClass(&((struct __ecereNameSpace__ecere__com__Module *)(((char *)module + sizeof(struct __ecereNameSpace__ecere__com__Instance))))->publicNameSpace, 0); if(appClass) return appClass; appClass = FindAppClass(&((struct __ecereNameSpace__ecere__com__Module *)(((char *)module + sizeof(struct __ecereNameSpace__ecere__com__Instance))))->privateNameSpace, 0); if(appClass) return appClass; for(subModule = ((struct __ecereNameSpace__ecere__com__Module *)(((char *)module + sizeof(struct __ecereNameSpace__ecere__com__Instance))))->modules.first; subModule; subModule = subModule->next) { appClass = SearchAppClass_Module(subModule->module); if(appClass) return appClass; } return (((void *)0)); } void __ecereMethod_SymbolgenApp_Main(struct __ecereNameSpace__ecere__com__Instance * this) { int c; unsigned int valid = 1; const char * output = (((void *)0)); outputPot = 0; disabledPooling = 0; targetPlatform = __runtimePlatform; targetBits = GetHostBits(); for(c = 1; c < ((struct __ecereNameSpace__ecere__com__Application *)(((char *)this + sizeof(struct __ecereNameSpace__ecere__com__Module) + sizeof(struct __ecereNameSpace__ecere__com__Instance))))->argc; c++) { const char * arg = ((struct __ecereNameSpace__ecere__com__Application *)(((char *)this + sizeof(struct __ecereNameSpace__ecere__com__Module) + sizeof(struct __ecereNameSpace__ecere__com__Instance))))->argv[c]; if(arg[0] == '-') { if(!strcmp(arg + 1, "m32") || !strcmp(arg + 1, "m64")) { targetBits = !strcmp(arg + 1, "m32") ? 32 : 64; } else if(!strcmp(arg + 1, "t32") || !strcmp(arg + 1, "t64")) { targetBits = !strcmp(arg + 1, "t32") ? 32 : 64; } else if(!strcmp(arg + 1, "o")) { if(!output && c + 1 < ((struct __ecereNameSpace__ecere__com__Application *)(((char *)this + sizeof(struct __ecereNameSpace__ecere__com__Module) + sizeof(struct __ecereNameSpace__ecere__com__Instance))))->argc) { output = ((struct __ecereNameSpace__ecere__com__Application *)(((char *)this + sizeof(struct __ecereNameSpace__ecere__com__Module) + sizeof(struct __ecereNameSpace__ecere__com__Instance))))->argv[c + 1]; c++; } else valid = 0; } else if(!strcmp(arg, "-name")) { if(c + 1 < ((struct __ecereNameSpace__ecere__com__Application *)(((char *)this + sizeof(struct __ecereNameSpace__ecere__com__Module) + sizeof(struct __ecereNameSpace__ecere__com__Instance))))->argc) { strcpy(projectName, ((struct __ecereNameSpace__ecere__com__Application *)(((char *)this + sizeof(struct __ecereNameSpace__ecere__com__Module) + sizeof(struct __ecereNameSpace__ecere__com__Instance))))->argv[c + 1]); c++; } else valid = 0; } else if(!strcmp(arg, "-t")) { if(++c < ((struct __ecereNameSpace__ecere__com__Application *)(((char *)this + sizeof(struct __ecereNameSpace__ecere__com__Module) + sizeof(struct __ecereNameSpace__ecere__com__Instance))))->argc) targetPlatform = __ecereProp___ecereNameSpace__ecere__com__Platform_Set_char__PTR_(((struct __ecereNameSpace__ecere__com__Application *)(((char *)this + sizeof(struct __ecereNameSpace__ecere__com__Module) + sizeof(struct __ecereNameSpace__ecere__com__Instance))))->argv[c]); else valid = 0; } else if(!strcmp(arg, "-outputpot")) outputPot = 1; else if(!strcmp(arg, "-disabled-pooling")) disabledPooling = 1; else if(!strcmp(arg, "-console")) isConsole = 1; else if(!strcmp(arg, "-dynamiclib")) isDynamicLibrary = 1; else if(!strcmp(arg, "-staticlib")) { isDynamicLibrary = 1; isStaticLibrary = 1; } else if(!strcmp(arg, "-symbols")) { if(c + 1 < ((struct __ecereNameSpace__ecere__com__Application *)(((char *)this + sizeof(struct __ecereNameSpace__ecere__com__Module) + sizeof(struct __ecereNameSpace__ecere__com__Instance))))->argc) { SetSymbolsDir(((struct __ecereNameSpace__ecere__com__Application *)(((char *)this + sizeof(struct __ecereNameSpace__ecere__com__Module) + sizeof(struct __ecereNameSpace__ecere__com__Instance))))->argv[c + 1]); c++; } else valid = 0; } } } if(!output) valid = 0; if(!valid) { printf("%s", __ecereNameSpace__ecere__GetTranslatedString("ecs", "Syntax:\n ecs [-t <target platform>] <input>[, <input>]* -o <output>\n", (((void *)0)))); } else { int c; char ext[17]; char symbolModule[274]; __ecereNameSpace__ecere__sys__GetExtension(output, ext); __ecereNameSpace__ecere__sys__GetLastDirectory(output, symbolModule); SetDefines(&_defines); SetImports(&_imports); SetGlobalData(&globalData); SetExcludedSymbols(&_excludedSymbols); SetGlobalContext(theGlobalContext); SetTopContext(theGlobalContext); SetCurrentContext(theGlobalContext); SetTargetPlatform(targetPlatform); SetTargetBits(targetBits); SetInSymbolGen(1); privateModule = (struct __ecereNameSpace__ecere__com__Instance *)__ecereNameSpace__ecere__com____ecere_COM_Initialize((unsigned int)(1 | (targetBits == sizeof(uintptr_t) * 8 ? (unsigned int)0 : targetBits == 64 ? 2 : targetBits == 32 ? 4 : (unsigned int)0) | 8), 1, (((void *)0))); SetPrivateModule(privateModule); mainModule = __ecereNameSpace__ecere__com__eInstance_New(__ecereClass_ModuleImport); SetMainModule(mainModule); __ecereMethod___ecereNameSpace__ecere__sys__OldList_Add(&_imports, mainModule); { struct __ecereNameSpace__ecere__com__Instance * intlStrings = __ecereNameSpace__ecere__com__eInstance_New(__ecereClass___ecereNameSpace__ecere__com__Map_TPL_ContextStringPair__ecere__com__List_TPL_String___); struct __ecereNameSpace__ecere__com__MapIterator it = (it.container = (void *)0, it.pointer = (void *)0, __ecereProp___ecereNameSpace__ecere__com__MapIterator_Set_map(&it, intlStrings), it); for(c = 1; c < ((struct __ecereNameSpace__ecere__com__Application *)(((char *)this + sizeof(struct __ecereNameSpace__ecere__com__Module) + sizeof(struct __ecereNameSpace__ecere__com__Instance))))->argc; c++) { const char * file = ((struct __ecereNameSpace__ecere__com__Application *)(((char *)this + sizeof(struct __ecereNameSpace__ecere__com__Module) + sizeof(struct __ecereNameSpace__ecere__com__Instance))))->argv[c]; struct __ecereNameSpace__ecere__com__Instance * f = (((void *)0)); char line[16384]; int count = 0; char * tokens[512]; if(file[0] == '-') { if(!strcmp(file, "-c")) c++; } else if(file[0] == '@') f = __ecereNameSpace__ecere__sys__FileOpen(&file[1], 1); else { count = 1; tokens[0] = (char *)file; } while(count || f) { int c; if(f) { while(!count && __ecereMethod___ecereNameSpace__ecere__sys__File_GetLine(f, line, sizeof (line))) count = __ecereNameSpace__ecere__sys__Tokenize(line, sizeof (tokens) / sizeof (tokens[0]), tokens, 2); if(!count) (__ecereNameSpace__ecere__com__eInstance_DecRef(f), f = 0); } for(c = 0; c < count; c++) { char ext[17]; file = tokens[c]; __ecereNameSpace__ecere__sys__GetExtension(file, ext); if(!strcmp(ext, "imp")) LoadImports(file); } count = 0; } } for(c = 1; c < ((struct __ecereNameSpace__ecere__com__Application *)(((char *)this + sizeof(struct __ecereNameSpace__ecere__com__Module) + sizeof(struct __ecereNameSpace__ecere__com__Instance))))->argc; c++) { const char * file = ((struct __ecereNameSpace__ecere__com__Application *)(((char *)this + sizeof(struct __ecereNameSpace__ecere__com__Module) + sizeof(struct __ecereNameSpace__ecere__com__Instance))))->argv[c]; if(file[0] == '-') { if(!strcmp(file, "-c")) c++; } } for(c = 1; c < ((struct __ecereNameSpace__ecere__com__Application *)(((char *)this + sizeof(struct __ecereNameSpace__ecere__com__Module) + sizeof(struct __ecereNameSpace__ecere__com__Instance))))->argc; c++) { const char * file = ((struct __ecereNameSpace__ecere__com__Application *)(((char *)this + sizeof(struct __ecereNameSpace__ecere__com__Module) + sizeof(struct __ecereNameSpace__ecere__com__Instance))))->argv[c]; struct __ecereNameSpace__ecere__com__Instance * f = (((void *)0)); char line[16384]; int count = 0; char * tokens[512]; if(file[0] == '-') { if(!strcmp(file, "-c")) c++; } else if(file[0] == '@') f = __ecereNameSpace__ecere__sys__FileOpen(&file[1], 1); else { count = 1; tokens[0] = (char *)file; } while(count || f) { int c; if(f) { while(!count && __ecereMethod___ecereNameSpace__ecere__sys__File_GetLine(f, line, sizeof (line))) count = __ecereNameSpace__ecere__sys__Tokenize(line, sizeof (tokens) / sizeof (tokens[0]), tokens, 2); if(!count) (__ecereNameSpace__ecere__com__eInstance_DecRef(f), f = 0); } for(c = 0; c < count; c++) { char ext[17]; char moduleName[797]; file = tokens[c]; __ecereNameSpace__ecere__sys__GetExtension(file, ext); __ecereNameSpace__ecere__sys__GetLastDirectory(file, moduleName); __ecereNameSpace__ecere__sys__StripExtension(moduleName); strcat(moduleName, ".ec"); if(((__runtimePlatform == 1) ? (strcasecmp) : strcmp)(moduleName, symbolModule) && (!strcmp(ext, "sym") || !strcmp(ext, "ec"))) { struct ImportedModule * importedModule; struct ModuleInfo * module = __ecereNameSpace__ecere__com__eInstance_New(__ecereClass_ModuleInfo); char fileName[274]; __ecereMethod___ecereNameSpace__ecere__sys__OldList_Add(&modules, module); __ecereNameSpace__ecere__sys__GetLastDirectory(file, fileName); module->name = __ecereNameSpace__ecere__sys__CopyString(fileName); __ecereNameSpace__ecere__sys__StripExtension(module->name); for(importedModule = _defines.first; importedModule; importedModule = importedModule->next) { if(importedModule->type == 0 && !(strcasecmp)(importedModule->name, module->name) && !(importedModule->importType == 2)) break; } if(importedModule) module->globalInstance = importedModule->globalInstance; else { importedModule = __extension__ ({ struct ImportedModule * __ecereInstance1 = __ecereNameSpace__ecere__com__eInstance_New(__ecereClass_ImportedModule); __ecereInstance1->name = __ecereNameSpace__ecere__sys__CopyString(module->name), __ecereInstance1->type = 0, __ecereInstance1->importType = 0, __ecereInstance1; }); __ecereMethod___ecereNameSpace__ecere__sys__OldList_AddName(&_defines, importedModule); module->globalInstance = LoadSymbols(file, 0, 0); CheckDataRedefinitions(); } { struct __ecereNameSpace__ecere__com__Instance * f; __ecereNameSpace__ecere__sys__ChangeExtension(file, "bowl", fileName); f = __ecereNameSpace__ecere__sys__FileOpen(fileName, 1); if(f) { static char line[65536]; struct __ecereNameSpace__ecere__com__Instance * comments = __ecereNameSpace__ecere__com__eInstance_New(__ecereClass___ecereNameSpace__ecere__com__List_TPL_String_); char * msgid = (((void *)0)), * msgstr = (((void *)0)), * msgctxt = (((void *)0)); while(!(__extension__ ({ unsigned int (* __internal_VirtualMethod)(struct __ecereNameSpace__ecere__com__Instance *); __internal_VirtualMethod = ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *))__extension__ ({ struct __ecereNameSpace__ecere__com__Instance * __internal_ClassInst = f; __internal_ClassInst ? __internal_ClassInst->_vTbl : __ecereClass___ecereNameSpace__ecere__sys__File->_vTbl; })[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Eof]); __internal_VirtualMethod ? __internal_VirtualMethod(f) : (unsigned int)1; }))) { if(__ecereMethod___ecereNameSpace__ecere__sys__File_GetLine(f, line, sizeof (line))) { int len; __ecereNameSpace__ecere__sys__TrimLSpaces(line, line); if(line[0] == '#') { (__extension__ ({ struct __ecereNameSpace__ecere__com__IteratorPointer * (* __internal_VirtualMethod)(struct __ecereNameSpace__ecere__com__Instance *, uint64 value); __internal_VirtualMethod = ((struct __ecereNameSpace__ecere__com__IteratorPointer * (*)(struct __ecereNameSpace__ecere__com__Instance *, uint64 value))__extension__ ({ struct __ecereNameSpace__ecere__com__Instance * __internal_ClassInst = comments; __internal_ClassInst ? __internal_ClassInst->_vTbl : __ecereClass___ecereNameSpace__ecere__com__List->_vTbl; })[__ecereVMethodID___ecereNameSpace__ecere__com__Container_Add]); __internal_VirtualMethod ? __internal_VirtualMethod(comments, (uint64)(uintptr_t)(__ecereNameSpace__ecere__sys__CopyString(line))) : (struct __ecereNameSpace__ecere__com__IteratorPointer *)1; })); } else if(strstr(line, "msgid \"") == line) { (__ecereNameSpace__ecere__com__eSystem_Delete(msgid), msgid = 0); msgid = __ecereNameSpace__ecere__sys__CopyString(line + 7); len = strlen(msgid); if(len) msgid[len - 1] = 0; } else if(strstr(line, "msgctxt \"") == line) { (__ecereNameSpace__ecere__com__eSystem_Delete(msgctxt), msgctxt = 0); msgctxt = __ecereNameSpace__ecere__sys__CopyString(line + 9); len = strlen(msgctxt); if(len) msgctxt[len - 1] = 0; } else if(strstr(line, "msgstr \"") == line) { (__ecereNameSpace__ecere__com__eSystem_Delete(msgstr), msgstr = 0); msgstr = __ecereNameSpace__ecere__sys__CopyString(line + 8); len = strlen(msgstr); if(len) msgstr[len - 1] = 0; } if(msgid && msgstr) { struct ContextStringPair pair = { msgid, msgctxt }; i18n = 1; if(!__ecereMethod___ecereNameSpace__ecere__com__Iterator_Index((void *)(&it), (uint64)(uintptr_t)(&pair), 0)) { msgid = (((void *)0)); msgctxt = (((void *)0)); __extension__ ({ struct __ecereNameSpace__ecere__com__Iterator __internalIterator = { intlStrings, 0 }; __ecereMethod___ecereNameSpace__ecere__com__Iterator_Index(&__internalIterator, ((uint64)(uintptr_t)(&pair)), 1); __ecereProp___ecereNameSpace__ecere__com__Iterator_Set_data(&__internalIterator, (uint64)(uintptr_t)(comments)); }); comments = __ecereNameSpace__ecere__com__eInstance_New(__ecereClass___ecereNameSpace__ecere__com__List_TPL_String_); } else { { struct __ecereNameSpace__ecere__com__Iterator s = { (comments), 0 }; while(__ecereMethod___ecereNameSpace__ecere__com__Iterator_Next(&s)) (__extension__ ({ struct __ecereNameSpace__ecere__com__IteratorPointer * (* __internal_VirtualMethod)(struct __ecereNameSpace__ecere__com__Instance *, uint64 value); __internal_VirtualMethod = ((struct __ecereNameSpace__ecere__com__IteratorPointer * (*)(struct __ecereNameSpace__ecere__com__Instance *, uint64 value))__extension__ ({ struct __ecereNameSpace__ecere__com__Instance * __internal_ClassInst = ((struct __ecereNameSpace__ecere__com__Instance *)(uintptr_t)__ecereProp___ecereNameSpace__ecere__com__Iterator_Get_data((void *)(&it))); __internal_ClassInst ? __internal_ClassInst->_vTbl : __ecereClass___ecereNameSpace__ecere__com__List->_vTbl; })[__ecereVMethodID___ecereNameSpace__ecere__com__Container_Add]); __internal_VirtualMethod ? __internal_VirtualMethod(((struct __ecereNameSpace__ecere__com__Instance *)(uintptr_t)__ecereProp___ecereNameSpace__ecere__com__Iterator_Get_data((void *)(&it))), __ecereProp___ecereNameSpace__ecere__com__Iterator_Get_data(&s)) : (struct __ecereNameSpace__ecere__com__IteratorPointer *)1; })); } (__extension__ ({ void (* __internal_VirtualMethod)(struct __ecereNameSpace__ecere__com__Instance *); __internal_VirtualMethod = ((void (*)(struct __ecereNameSpace__ecere__com__Instance *))__extension__ ({ struct __ecereNameSpace__ecere__com__Instance * __internal_ClassInst = comments; __internal_ClassInst ? __internal_ClassInst->_vTbl : __ecereClass___ecereNameSpace__ecere__com__List->_vTbl; })[__ecereVMethodID___ecereNameSpace__ecere__com__Container_RemoveAll]); __internal_VirtualMethod ? __internal_VirtualMethod(comments) : (void)1; })); } (__ecereNameSpace__ecere__com__eSystem_Delete(msgid), msgid = 0); (__ecereNameSpace__ecere__com__eSystem_Delete(msgctxt), msgctxt = 0); (__ecereNameSpace__ecere__com__eSystem_Delete(msgstr), msgstr = 0); } } } (__extension__ ({ void (* __internal_VirtualMethod)(struct __ecereNameSpace__ecere__com__Instance *); __internal_VirtualMethod = ((void (*)(struct __ecereNameSpace__ecere__com__Instance *))__extension__ ({ struct __ecereNameSpace__ecere__com__Instance * __internal_ClassInst = comments; __internal_ClassInst ? __internal_ClassInst->_vTbl : __ecereClass___ecereNameSpace__ecere__com__List->_vTbl; })[__ecereVMethodID___ecereNameSpace__ecere__com__Container_Free]); __internal_VirtualMethod ? __internal_VirtualMethod(comments) : (void)1; })); (__ecereNameSpace__ecere__com__eInstance_DecRef(comments), comments = 0); (__ecereNameSpace__ecere__com__eInstance_DecRef(f), f = 0); } } } } count = 0; } } ComputeModuleClasses(privateModule); if(!isDynamicLibrary) { thisAppClass = SearchAppClass_Module(privateModule); } WriteMain(output); if(outputPot && ((struct __ecereNameSpace__ecere__com__CustomAVLTree *)(((char *)intlStrings + 0 + sizeof(struct __ecereNameSpace__ecere__com__Instance))))->count) { struct __ecereNameSpace__ecere__com__Instance * potFile; char potFileName[797]; strcpy(potFileName, "locale"); __ecereNameSpace__ecere__sys__PathCat(potFileName, projectName); __ecereNameSpace__ecere__sys__ChangeExtension(potFileName, "pot", potFileName); potFile = __ecereNameSpace__ecere__sys__FileOpen(potFileName, 2); if(potFile) { (__extension__ ({ unsigned int (* __internal_VirtualMethod)(struct __ecereNameSpace__ecere__com__Instance *, const char * string); __internal_VirtualMethod = ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char * string))__extension__ ({ struct __ecereNameSpace__ecere__com__Instance * __internal_ClassInst = potFile; __internal_ClassInst ? __internal_ClassInst->_vTbl : __ecereClass___ecereNameSpace__ecere__sys__File->_vTbl; })[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts]); __internal_VirtualMethod ? __internal_VirtualMethod(potFile, "msgid \"\"\n") : (unsigned int)1; })); (__extension__ ({ unsigned int (* __internal_VirtualMethod)(struct __ecereNameSpace__ecere__com__Instance *, const char * string); __internal_VirtualMethod = ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char * string))__extension__ ({ struct __ecereNameSpace__ecere__com__Instance * __internal_ClassInst = potFile; __internal_ClassInst ? __internal_ClassInst->_vTbl : __ecereClass___ecereNameSpace__ecere__sys__File->_vTbl; })[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts]); __internal_VirtualMethod ? __internal_VirtualMethod(potFile, "msgstr \"\"\n") : (unsigned int)1; })); (__extension__ ({ unsigned int (* __internal_VirtualMethod)(struct __ecereNameSpace__ecere__com__Instance *, const char * string); __internal_VirtualMethod = ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char * string))__extension__ ({ struct __ecereNameSpace__ecere__com__Instance * __internal_ClassInst = potFile; __internal_ClassInst ? __internal_ClassInst->_vTbl : __ecereClass___ecereNameSpace__ecere__sys__File->_vTbl; })[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts]); __internal_VirtualMethod ? __internal_VirtualMethod(potFile, "\"Project-Id-Version: \\n\"\n") : (unsigned int)1; })); (__extension__ ({ unsigned int (* __internal_VirtualMethod)(struct __ecereNameSpace__ecere__com__Instance *, const char * string); __internal_VirtualMethod = ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char * string))__extension__ ({ struct __ecereNameSpace__ecere__com__Instance * __internal_ClassInst = potFile; __internal_ClassInst ? __internal_ClassInst->_vTbl : __ecereClass___ecereNameSpace__ecere__sys__File->_vTbl; })[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts]); __internal_VirtualMethod ? __internal_VirtualMethod(potFile, "\"POT-Creation-Date: \\n\"\n") : (unsigned int)1; })); (__extension__ ({ unsigned int (* __internal_VirtualMethod)(struct __ecereNameSpace__ecere__com__Instance *, const char * string); __internal_VirtualMethod = ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char * string))__extension__ ({ struct __ecereNameSpace__ecere__com__Instance * __internal_ClassInst = potFile; __internal_ClassInst ? __internal_ClassInst->_vTbl : __ecereClass___ecereNameSpace__ecere__sys__File->_vTbl; })[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts]); __internal_VirtualMethod ? __internal_VirtualMethod(potFile, "\"PO-Revision-Date: \\n\"\n") : (unsigned int)1; })); (__extension__ ({ unsigned int (* __internal_VirtualMethod)(struct __ecereNameSpace__ecere__com__Instance *, const char * string); __internal_VirtualMethod = ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char * string))__extension__ ({ struct __ecereNameSpace__ecere__com__Instance * __internal_ClassInst = potFile; __internal_ClassInst ? __internal_ClassInst->_vTbl : __ecereClass___ecereNameSpace__ecere__sys__File->_vTbl; })[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts]); __internal_VirtualMethod ? __internal_VirtualMethod(potFile, "\"Last-Translator: \\n\"\n") : (unsigned int)1; })); (__extension__ ({ unsigned int (* __internal_VirtualMethod)(struct __ecereNameSpace__ecere__com__Instance *, const char * string); __internal_VirtualMethod = ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char * string))__extension__ ({ struct __ecereNameSpace__ecere__com__Instance * __internal_ClassInst = potFile; __internal_ClassInst ? __internal_ClassInst->_vTbl : __ecereClass___ecereNameSpace__ecere__sys__File->_vTbl; })[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts]); __internal_VirtualMethod ? __internal_VirtualMethod(potFile, "\"Language-Team: \\n\"\n") : (unsigned int)1; })); (__extension__ ({ unsigned int (* __internal_VirtualMethod)(struct __ecereNameSpace__ecere__com__Instance *, const char * string); __internal_VirtualMethod = ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char * string))__extension__ ({ struct __ecereNameSpace__ecere__com__Instance * __internal_ClassInst = potFile; __internal_ClassInst ? __internal_ClassInst->_vTbl : __ecereClass___ecereNameSpace__ecere__sys__File->_vTbl; })[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts]); __internal_VirtualMethod ? __internal_VirtualMethod(potFile, "\"MIME-Version: 1.0\\n\"\n") : (unsigned int)1; })); (__extension__ ({ unsigned int (* __internal_VirtualMethod)(struct __ecereNameSpace__ecere__com__Instance *, const char * string); __internal_VirtualMethod = ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char * string))__extension__ ({ struct __ecereNameSpace__ecere__com__Instance * __internal_ClassInst = potFile; __internal_ClassInst ? __internal_ClassInst->_vTbl : __ecereClass___ecereNameSpace__ecere__sys__File->_vTbl; })[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts]); __internal_VirtualMethod ? __internal_VirtualMethod(potFile, "\"Content-Type: text/plain; charset=iso-8859-1\\n\"\n") : (unsigned int)1; })); (__extension__ ({ unsigned int (* __internal_VirtualMethod)(struct __ecereNameSpace__ecere__com__Instance *, const char * string); __internal_VirtualMethod = ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char * string))__extension__ ({ struct __ecereNameSpace__ecere__com__Instance * __internal_ClassInst = potFile; __internal_ClassInst ? __internal_ClassInst->_vTbl : __ecereClass___ecereNameSpace__ecere__sys__File->_vTbl; })[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts]); __internal_VirtualMethod ? __internal_VirtualMethod(potFile, "\"Content-Transfer-Encoding: 8bit\\n\"\n") : (unsigned int)1; })); (__extension__ ({ unsigned int (* __internal_VirtualMethod)(struct __ecereNameSpace__ecere__com__Instance *, const char * string); __internal_VirtualMethod = ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char * string))__extension__ ({ struct __ecereNameSpace__ecere__com__Instance * __internal_ClassInst = potFile; __internal_ClassInst ? __internal_ClassInst->_vTbl : __ecereClass___ecereNameSpace__ecere__sys__File->_vTbl; })[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts]); __internal_VirtualMethod ? __internal_VirtualMethod(potFile, "\"X-Poedit-Basepath: ../\\n\"\n") : (unsigned int)1; })); (__extension__ ({ unsigned int (* __internal_VirtualMethod)(struct __ecereNameSpace__ecere__com__Instance *, const char * string); __internal_VirtualMethod = ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char * string))__extension__ ({ struct __ecereNameSpace__ecere__com__Instance * __internal_ClassInst = potFile; __internal_ClassInst ? __internal_ClassInst->_vTbl : __ecereClass___ecereNameSpace__ecere__sys__File->_vTbl; })[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts]); __internal_VirtualMethod ? __internal_VirtualMethod(potFile, "\n") : (unsigned int)1; })); { struct __ecereNameSpace__ecere__com__MapIterator i = (i.container = (void *)0, i.pointer = (void *)0, __ecereProp___ecereNameSpace__ecere__com__MapIterator_Set_map(&i, (intlStrings)), i); while(__ecereMethod___ecereNameSpace__ecere__com__Iterator_Next((void *)(&i))) { struct ContextStringPair pair = (*(struct ContextStringPair *)(uintptr_t)__ecereProp___ecereNameSpace__ecere__com__MapIterator_Get_key(&i)); struct __ecereNameSpace__ecere__com__Instance * comments = ((struct __ecereNameSpace__ecere__com__Instance *)(uintptr_t)__ecereProp___ecereNameSpace__ecere__com__Iterator_Get_data((void *)(&i))); { struct __ecereNameSpace__ecere__com__Iterator s = { (comments), 0 }; while(__ecereMethod___ecereNameSpace__ecere__com__Iterator_Next(&s)) { __ecereMethod___ecereNameSpace__ecere__sys__File_Printf(potFile, ((char * )((uintptr_t)(__ecereProp___ecereNameSpace__ecere__com__Iterator_Get_data(&s))))); (__extension__ ({ unsigned int (* __internal_VirtualMethod)(struct __ecereNameSpace__ecere__com__Instance *, const char * string); __internal_VirtualMethod = ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char * string))__extension__ ({ struct __ecereNameSpace__ecere__com__Instance * __internal_ClassInst = potFile; __internal_ClassInst ? __internal_ClassInst->_vTbl : __ecereClass___ecereNameSpace__ecere__sys__File->_vTbl; })[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts]); __internal_VirtualMethod ? __internal_VirtualMethod(potFile, "\n") : (unsigned int)1; })); } } if(pair.context) { (__extension__ ({ unsigned int (* __internal_VirtualMethod)(struct __ecereNameSpace__ecere__com__Instance *, const char * string); __internal_VirtualMethod = ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char * string))__extension__ ({ struct __ecereNameSpace__ecere__com__Instance * __internal_ClassInst = potFile; __internal_ClassInst ? __internal_ClassInst->_vTbl : __ecereClass___ecereNameSpace__ecere__sys__File->_vTbl; })[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts]); __internal_VirtualMethod ? __internal_VirtualMethod(potFile, "msgctxt \"") : (unsigned int)1; })); (__extension__ ({ unsigned int (* __internal_VirtualMethod)(struct __ecereNameSpace__ecere__com__Instance *, const char * string); __internal_VirtualMethod = ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char * string))__extension__ ({ struct __ecereNameSpace__ecere__com__Instance * __internal_ClassInst = potFile; __internal_ClassInst ? __internal_ClassInst->_vTbl : __ecereClass___ecereNameSpace__ecere__sys__File->_vTbl; })[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts]); __internal_VirtualMethod ? __internal_VirtualMethod(potFile, pair.context) : (unsigned int)1; })); (__extension__ ({ unsigned int (* __internal_VirtualMethod)(struct __ecereNameSpace__ecere__com__Instance *, const char * string); __internal_VirtualMethod = ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char * string))__extension__ ({ struct __ecereNameSpace__ecere__com__Instance * __internal_ClassInst = potFile; __internal_ClassInst ? __internal_ClassInst->_vTbl : __ecereClass___ecereNameSpace__ecere__sys__File->_vTbl; })[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts]); __internal_VirtualMethod ? __internal_VirtualMethod(potFile, "\"\n") : (unsigned int)1; })); } (__extension__ ({ unsigned int (* __internal_VirtualMethod)(struct __ecereNameSpace__ecere__com__Instance *, const char * string); __internal_VirtualMethod = ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char * string))__extension__ ({ struct __ecereNameSpace__ecere__com__Instance * __internal_ClassInst = potFile; __internal_ClassInst ? __internal_ClassInst->_vTbl : __ecereClass___ecereNameSpace__ecere__sys__File->_vTbl; })[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts]); __internal_VirtualMethod ? __internal_VirtualMethod(potFile, "msgid \"") : (unsigned int)1; })); (__extension__ ({ unsigned int (* __internal_VirtualMethod)(struct __ecereNameSpace__ecere__com__Instance *, const char * string); __internal_VirtualMethod = ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char * string))__extension__ ({ struct __ecereNameSpace__ecere__com__Instance * __internal_ClassInst = potFile; __internal_ClassInst ? __internal_ClassInst->_vTbl : __ecereClass___ecereNameSpace__ecere__sys__File->_vTbl; })[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts]); __internal_VirtualMethod ? __internal_VirtualMethod(potFile, pair.string) : (unsigned int)1; })); (__extension__ ({ unsigned int (* __internal_VirtualMethod)(struct __ecereNameSpace__ecere__com__Instance *, const char * string); __internal_VirtualMethod = ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char * string))__extension__ ({ struct __ecereNameSpace__ecere__com__Instance * __internal_ClassInst = potFile; __internal_ClassInst ? __internal_ClassInst->_vTbl : __ecereClass___ecereNameSpace__ecere__sys__File->_vTbl; })[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts]); __internal_VirtualMethod ? __internal_VirtualMethod(potFile, "\"\n") : (unsigned int)1; })); (__extension__ ({ unsigned int (* __internal_VirtualMethod)(struct __ecereNameSpace__ecere__com__Instance *, const char * string); __internal_VirtualMethod = ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char * string))__extension__ ({ struct __ecereNameSpace__ecere__com__Instance * __internal_ClassInst = potFile; __internal_ClassInst ? __internal_ClassInst->_vTbl : __ecereClass___ecereNameSpace__ecere__sys__File->_vTbl; })[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts]); __internal_VirtualMethod ? __internal_VirtualMethod(potFile, "msgstr \"") : (unsigned int)1; })); (__extension__ ({ unsigned int (* __internal_VirtualMethod)(struct __ecereNameSpace__ecere__com__Instance *, const char * string); __internal_VirtualMethod = ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char * string))__extension__ ({ struct __ecereNameSpace__ecere__com__Instance * __internal_ClassInst = potFile; __internal_ClassInst ? __internal_ClassInst->_vTbl : __ecereClass___ecereNameSpace__ecere__sys__File->_vTbl; })[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts]); __internal_VirtualMethod ? __internal_VirtualMethod(potFile, pair.string) : (unsigned int)1; })); (__extension__ ({ unsigned int (* __internal_VirtualMethod)(struct __ecereNameSpace__ecere__com__Instance *, const char * string); __internal_VirtualMethod = ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char * string))__extension__ ({ struct __ecereNameSpace__ecere__com__Instance * __internal_ClassInst = potFile; __internal_ClassInst ? __internal_ClassInst->_vTbl : __ecereClass___ecereNameSpace__ecere__sys__File->_vTbl; })[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts]); __internal_VirtualMethod ? __internal_VirtualMethod(potFile, "\"\n") : (unsigned int)1; })); (__extension__ ({ unsigned int (* __internal_VirtualMethod)(struct __ecereNameSpace__ecere__com__Instance *, const char * string); __internal_VirtualMethod = ((unsigned int (*)(struct __ecereNameSpace__ecere__com__Instance *, const char * string))__extension__ ({ struct __ecereNameSpace__ecere__com__Instance * __internal_ClassInst = potFile; __internal_ClassInst ? __internal_ClassInst->_vTbl : __ecereClass___ecereNameSpace__ecere__sys__File->_vTbl; })[__ecereVMethodID___ecereNameSpace__ecere__sys__File_Puts]); __internal_VirtualMethod ? __internal_VirtualMethod(potFile, "\n") : (unsigned int)1; })); } } (__extension__ ({ void (* __internal_VirtualMethod)(struct __ecereNameSpace__ecere__com__Instance *); __internal_VirtualMethod = ((void (*)(struct __ecereNameSpace__ecere__com__Instance *))__extension__ ({ struct __ecereNameSpace__ecere__com__Instance * __internal_ClassInst = intlStrings; __internal_ClassInst ? __internal_ClassInst->_vTbl : __ecereClass___ecereNameSpace__ecere__com__Map->_vTbl; })[__ecereVMethodID___ecereNameSpace__ecere__com__Container_Free]); __internal_VirtualMethod ? __internal_VirtualMethod(intlStrings) : (void)1; })); (__ecereNameSpace__ecere__com__eInstance_DecRef(intlStrings), intlStrings = 0); (__ecereNameSpace__ecere__com__eInstance_DecRef(potFile), potFile = 0); } } } FreeContext(theGlobalContext); FreeExcludedSymbols(&_excludedSymbols); __ecereMethod___ecereNameSpace__ecere__sys__OldList_Free(&_defines, (void *)(FreeModuleDefine)); __ecereMethod___ecereNameSpace__ecere__sys__OldList_Free(&_imports, (void *)(FreeModuleImport)); FreeTypeData(privateModule); FreeIncludeFiles(); FreeGlobalData(&globalData); (__ecereNameSpace__ecere__com__eInstance_DecRef(privateModule), privateModule = 0); } SetSymbolsDir((((void *)0))); } void __ecereRegisterModule_ecs(struct __ecereNameSpace__ecere__com__Instance * module) { struct __ecereNameSpace__ecere__com__Class __attribute__((unused)) * class; class = __ecereNameSpace__ecere__com__eSystem_RegisterClass(5, "ModuleInfo", 0, sizeof(struct ModuleInfo), 0, (void *)0, (void *)0, module, 2, 1); if(((struct __ecereNameSpace__ecere__com__Module *)(((char *)module + sizeof(struct __ecereNameSpace__ecere__com__Instance))))->application == ((struct __ecereNameSpace__ecere__com__Module *)(((char *)__thisModule + sizeof(struct __ecereNameSpace__ecere__com__Instance))))->application && class) __ecereClass_ModuleInfo = class; class = __ecereNameSpace__ecere__com__eSystem_RegisterClass(0, "SymbolgenApp", "ecere::com::Application", 0, 0, (void *)0, (void *)0, module, 2, 1); if(((struct __ecereNameSpace__ecere__com__Module *)(((char *)module + sizeof(struct __ecereNameSpace__ecere__com__Instance))))->application == ((struct __ecereNameSpace__ecere__com__Module *)(((char *)__thisModule + sizeof(struct __ecereNameSpace__ecere__com__Instance))))->application && class) __ecereClass_SymbolgenApp = class; __ecereNameSpace__ecere__com__eClass_AddMethod(class, "Main", 0, __ecereMethod_SymbolgenApp_Main, 1); }
the_stack_data/26701317.c
#include <stdlib.h> #include <string.h> #include <stdio.h> struct ts { int x; int y; }; struct ts ats; void second() { //ats.x = 3; <--- BEACHTE if (ats.x == 1) { goto error; error: printf("error!\n"); } } int main() { ats.x = 3; second(); return 0; }
the_stack_data/897255.c
#include<stdio.h> #include<assert.h> int main() { int rd, rs, rt; int result; rs = 0x00000010; rt = 0x00000001; result = 0x00000009; __asm ("addqh_r.w %0, %1, %2\n\t" : "=r"(rd) : "r"(rs), "r"(rt) ); assert(rd == result); rs = 0xFFFFFFFE; rt = 0x00000001; result = 0x00000000; __asm ("addqh_r.w %0, %1, %2\n\t" : "=r"(rd) : "r"(rs), "r"(rt) ); assert(rd == result); return 0; }
the_stack_data/144301.c
#include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <sys/types.h> #include <sys/wait.h> int main() { int pipefd[2]; int x = pipe(pipefd); int p = fork(); if (p < 0) perror("AAA"); if (p == 0) { int leidos = 0; char* s = malloc(10); do { leidos = read(pipefd[0],s,10); if (leidos > 0) printf("recibidendo %s \n",s); } while (leidos > 0); } else { char* s = malloc(10); for (int i = 0; i < 10; i++) { sprintf(s,"%d\n",i); write(pipefd[1],s,i/10+1); } close(pipefd[1]); wait(NULL); } }
the_stack_data/461149.c
#include <stdio.h> #include <stdlib.h> #include <stdint.h> #include <sys/mman.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> void handle_error(char *msg) { do { perror(msg); exit(EXIT_FAILURE); } while (0); } int main(int argc, char *argv[]) { const char *memblock; int fd; struct stat sb; fd = open(argv[1], O_RDONLY); fstat(fd, &sb); printf("Size: %llu\n", (uint64_t)sb.st_size); memblock = mmap(NULL, sb.st_size, PROT_WRITE, MAP_PRIVATE, fd, 0); if (memblock == MAP_FAILED) handle_error("mmap"); for(uint64_t i = 0; i < 10; i++) { printf("[%llu]=%X\n", i, memblock[i]); } printf("\n"); return 0; }
the_stack_data/109356.c
/// /// Perform several driver tests for SYCL offloading on Windows. /// // REQUIRES: clang-driver // REQUIRES: x86-registered-target /// Test behaviors of -foffload-static-lib=<lib> with single object. // Build the offload library that is used for the tests. // RUN: echo "void foo() {}" > %t.c // RUN: %clang_cl --target=x86_64-pc-windows-msvc -fsycl -c -Fo%t-orig.obj %t.c // RUN: llvm-ar cr %t-orig.lib %t-orig.obj // RUN: %clang --target=x86_64-pc-windows-msvc -fsycl -fno-sycl-device-lib=all %t-orig.lib %t-orig.obj -### 2>&1 \ // RUN: | FileCheck %s -check-prefix=FOFFLOAD_STATIC_LIB // RUN: %clang_cl --target=x86_64-pc-windows-msvc -fsycl -fno-sycl-device-lib=all %t-orig.lib %t-orig.obj -### 2>&1 \ // RUN: | FileCheck %s -check-prefix=FOFFLOAD_STATIC_LIB // FOFFLOAD_STATIC_LIB: clang-offload-bundler{{(.exe)?}}{{.+}} "-type=o" "-targets=host-x86_64-pc-windows-msvc,sycl-spir64-unknown-unknown-sycldevice" "-inputs={{.*}}-orig.obj" "-outputs={{.+}}.{{(o|obj)}},{{.+}}.{{(o|obj)}}" "-unbundle" // FOFFLOAD_STATIC_LIB: clang-offload-bundler{{(.exe)?}}{{.+}} "-type=a" "-targets=sycl-spir64-{{.+}}-sycldevice" "-inputs={{.*}}-orig.lib" "-outputs=[[OUTLIB:.+\.a]]" "-unbundle" // FOFFLOAD_STATIC_LIB: llvm-link{{(.exe)?}}{{.*}} "[[OUTLIB]]" // FOFFLOAD_STATIC_LIB: link{{(.exe)?}}{{.+}} "{{.*}}-orig.lib" /// ########################################################################### /// Test behaviors of -foffload-static-lib=<lib> with multiple objects. // RUN: touch %t-orig.lib // RUN: touch %t-1.obj // RUN: touch %t-2.obj // RUN: touch %t-3.obj // RUN: %clang --target=x86_64-pc-windows-msvc -fsycl %t-orig.lib %t-1.obj %t-2.obj %t-3.obj -### 2>&1 \ // RUN: | FileCheck %s -check-prefix=FOFFLOAD_STATIC_LIB_MULTI_O // RUN: %clang_cl --target=x86_64-pc-windows-msvc -fsycl %t-orig.lib %t-1.obj %t-2.obj %t-3.obj -### 2>&1 \ // RUN: | FileCheck %s -check-prefix=FOFFLOAD_STATIC_LIB_MULTI_O // FOFFLOAD_STATIC_LIB_MULTI_O: clang-offload-bundler{{(.exe)?}}{{.+}} "-type=o"{{.+}} "-inputs={{.*}}-1.obj"{{.+}} "-unbundle" // FOFFLOAD_STATIC_LIB_MULTI_O: clang-offload-bundler{{(.exe)?}}{{.+}} "-type=o"{{.+}} "-inputs={{.*}}-2.obj"{{.+}} "-unbundle" // FOFFLOAD_STATIC_LIB_MULTI_O: clang-offload-bundler{{(.exe)?}}{{.+}} "-type=o"{{.+}} "-inputs={{.*}}-3.obj"{{.+}} "-unbundle" // FOFFLOAD_STATIC_LIB_MULTI_O: clang-offload-bundler{{(.exe)?}}{{.+}} "-type=a" "-targets=sycl-spir64-{{.+}}-sycldevice" "-inputs={{.*}}-orig.lib" "-outputs=[[OUTLIB:.+\.a]]" "-unbundle" // FOFFLOAD_STATIC_LIB_MULTI_O: llvm-link{{(.exe)?}}{{.*}} "[[OUTLIB]]" // FOFFLOAD_STATIC_LIB_MULTI_O: link{{(.exe)?}}{{.+}} "{{.*}}-orig.lib" /// ########################################################################### /// Test behaviors with multiple -foffload-static-lib=<lib> options. // RUN: cp %t-orig.lib %t1.lib // RUN: cp %t-orig.lib %t2.lib // RUN: touch %t-orig.obj // RUN: %clang --target=x86_64-pc-windows-msvc -fsycl %t1.lib %t2.lib %t-orig.obj -### 2>&1 \ // RUN: | FileCheck %s -check-prefix=FOFFLOAD_STATIC_MULTI_LIB // RUN: %clang_cl --target=x86_64-pc-windows-msvc -fsycl %t1.lib %t2.lib %t-orig.obj -### 2>&1 \ // RUN: | FileCheck %s -check-prefix=FOFFLOAD_STATIC_MULTI_LIB // FOFFLOAD_STATIC_MULTI_LIB: clang-offload-bundler{{(.exe)?}}{{.+}} "-type=o"{{.+}} "-inputs={{.*}}-orig.obj"{{.+}} "-unbundle" // FOFFLOAD_STATIC_MULTI_LIB: clang-offload-bundler{{(.exe)?}}{{.+}} "-type=a" "-targets=sycl-spir64-{{.+}}-sycldevice" "-inputs={{.*}}1.lib" "-outputs=[[OUTLIB1:.+\.a]]" "-unbundle" // FOFFLOAD_STATIC_MULTI_LIB: clang-offload-bundler{{(.exe)?}}{{.+}} "-type=a" "-targets=sycl-spir64-{{.+}}-sycldevice" "-inputs={{.*}}2.lib" "-outputs=[[OUTLIB2:.+\.a]]" "-unbundle" // FOFFLOAD_STATIC_MULTI_LIB: llvm-link{{(.exe)?}}{{.*}} "[[OUTLIB1]]" "[[OUTLIB2]]" // FOFFLOAD_STATIC_MULTI_LIB: link{{(.exe)?}}{{.+}} "{{.*}}1.lib" "{{.*}}2.lib" /// ########################################################################### /// Test behaviors of -foffload-static-lib=<lib> from source. // RUN: touch %t-orig.lib // RUN: %clang --target=x86_64-pc-windows-msvc -fsycl -fno-sycl-device-lib=all %t-orig.lib -ccc-print-phases %s 2>&1 \ // RUN: | FileCheck %s -check-prefix=FOFFLOAD_STATIC_LIB_SRC // RUN: %clang_cl --target=x86_64-pc-windows-msvc -fsycl -fno-sycl-device-lib=all %t-orig.lib -ccc-print-phases %s 2>&1 \ // RUN: | FileCheck %s -check-prefix=FOFFLOAD_STATIC_LIB_SRC // FOFFLOAD_STATIC_LIB_SRC: 0: input, "[[INPUTLIB:.+\.lib]]", object, (host-sycl) // FOFFLOAD_STATIC_LIB_SRC: 1: input, "[[INPUTC:.+\.c]]", c++, (host-sycl) // FOFFLOAD_STATIC_LIB_SRC: 2: preprocessor, {1}, c++-cpp-output, (host-sycl) // FOFFLOAD_STATIC_LIB_SRC: 3: append-footer, {2}, c++, (host-sycl) // FOFFLOAD_STATIC_LIB_SRC: 4: preprocessor, {3}, c++-cpp-output, (host-sycl) // FOFFLOAD_STATIC_LIB_SRC: 5: input, "[[INPUTC]]", c++, (device-sycl) // FOFFLOAD_STATIC_LIB_SRC: 6: preprocessor, {5}, c++-cpp-output, (device-sycl) // FOFFLOAD_STATIC_LIB_SRC: 7: compiler, {6}, ir, (device-sycl) // FOFFLOAD_STATIC_LIB_SRC: 8: offload, "host-sycl (x86_64-pc-windows-msvc)" {4}, "device-sycl (spir64-unknown-unknown-sycldevice)" {7}, c++-cpp-output // FOFFLOAD_STATIC_LIB_SRC: 9: compiler, {8}, ir, (host-sycl) // FOFFLOAD_STATIC_LIB_SRC: 10: backend, {9}, assembler, (host-sycl) // FOFFLOAD_STATIC_LIB_SRC: 11: assembler, {10}, object, (host-sycl) // FOFFLOAD_STATIC_LIB_SRC: 12: linker, {0, 11}, image, (host-sycl) // FOFFLOAD_STATIC_LIB_SRC: 13: linker, {0, 11}, host_dep_image, (host-sycl) // FOFFLOAD_STATIC_LIB_SRC: 14: clang-offload-deps, {13}, ir, (host-sycl) // FOFFLOAD_STATIC_LIB_SRC: 15: input, "[[INPUTLIB]]", archive // FOFFLOAD_STATIC_LIB_SRC: 16: clang-offload-unbundler, {15}, archive // FOFFLOAD_STATIC_LIB_SRC: 17: linker, {7, 14, 16}, ir, (device-sycl) // FOFFLOAD_STATIC_LIB_SRC: 18: sycl-post-link, {17}, tempfiletable, (device-sycl) // FOFFLOAD_STATIC_LIB_SRC: 19: file-table-tform, {18}, tempfilelist, (device-sycl) // FOFFLOAD_STATIC_LIB_SRC: 20: llvm-spirv, {19}, tempfilelist, (device-sycl) // FOFFLOAD_STATIC_LIB_SRC: 21: file-table-tform, {18, 20}, tempfiletable, (device-sycl) // FOFFLOAD_STATIC_LIB_SRC: 22: clang-offload-wrapper, {21}, object, (device-sycl) // FOFFLOAD_STATIC_LIB_SRC: 23: offload, "host-sycl (x86_64-pc-windows-msvc)" {12}, "device-sycl (spir64-unknown-unknown-sycldevice)" {22}, image /// ########################################################################### // RUN: touch %t-orig.lib // RUN: %clang --target=x86_64-pc-windows-msvc -fsycl %t-orig.lib %s -### 2>&1 \ // RUN: | FileCheck %s -check-prefix=FOFFLOAD_STATIC_LIB_SRC2 // RUN: %clang_cl --target=x86_64-pc-windows-msvc -fsycl -foffload-static-lib=%t-orig.lib %s -### 2>&1 \ // RUN: | FileCheck %s -check-prefix=FOFFLOAD_STATIC_LIB_SRC2 // FOFFLOAD_STATIC_LIB_SRC2: clang-offload-bundler{{(.exe)?}}{{.+}} "-type=a" "-targets=sycl-spir64-{{.+}}-sycldevice" "-inputs={{.*}}-orig.lib" "-outputs=[[OUTLIB:.+\.a]]" "-unbundle" // FOFFLOAD_STATIC_LIB_SRC2: llvm-link{{(.exe)?}}{{.*}} "[[OUTLIB]]" // FOFFLOAD_STATIC_LIB_SRC2: link{{(.exe)?}}{{.+}} "{{.*}}-orig.lib" // Check for /P behaviors // RUN: %clang_cl --target=x86_64-pc-windows-msvc -fsycl -P %s -### 2>&1 | FileCheck -check-prefix=FSYCL_P %s // FSYCL_P: clang{{.*}} "-cc1" "-triple" "spir64-unknown-unknown-sycldevice" {{.*}} "-E" {{.*}} "-o" "[[DEVICEPP:.+\.ii]]" // FSYCL_P: clang{{.*}} "-cc1" "-triple" "x86_64-pc-windows-msvc{{.*}}" {{.*}} "-E" {{.*}} "-o" "[[HOSTPP:.+\.ii]]" // FSYCL_P: append-file{{.*}} "[[HOSTPP]]"{{.*}} "--output=[[APPEND:.+\.cpp]]" // FSYCL_P: clang{{.*}} "-cc1" "-triple" "x86_64-pc-windows-msvc{{.*}}" {{.*}} "-E" {{.*}} "-o" "[[HOSTPP:.+\.ii]]"{{.*}} "[[APPEND]]" // FSYCL_P: clang-offload-bundler{{.*}} "-type=ii" "-targets=sycl-spir64-unknown-unknown-sycldevice,host-x86_64-pc-windows-msvc" {{.*}} "-inputs=[[DEVICEPP]],[[HOSTPP]]" // RUN: touch %t-orig.lib // RUN: %clang_cl --target=x86_64-pc-windows-msvc -fsycl %t-orig.lib %s -### /link -out:force_out_file 2>&1 \ // RUN: | FileCheck %s -check-prefix=HOSTDEP_LINK_OVERRIDE // HOSTDEP_LINK_OVERRIDE: link{{.*}} "-out:[[HOSTDEP_LINK_OUT:.+\.out]]"{{.*}} "-out:force_out_file" "-out:[[HOSTDEP_LINK_OUT]]" // HOSTDEP_LINK_OVERRIDE: clang-offload-deps{{.*}} // HOSTDEP_LINK_OVERRIDE: link{{.*}} "-out:[[LINK_OUT:.+\.exe]]"{{.*}} "-out:force_out_file" // HOSTDEP_LINK_OVERRIDE-NOT: "-out:[[LINK_OUT]]"
the_stack_data/86074321.c
// RUN: %clam --inline --lower-select --lower-unsigned-icmp --crab-do-not-print-invariants --crab-dom=boxes --crab-check=assert %opts --crab-sanity-checks --llvm-pp-loops "%s" 2>&1 | OutputCheck -l debug %s // CHECK: ^1 Number of total safe checks$ // CHECK: ^0 Number of total error checks$ // CHECK: ^0 Number of total warning checks$ extern void __VERIFIER_error() __attribute__ ((__noreturn__)); extern char __VERIFIER_nondet_char(void); extern int __VERIFIER_nondet_int(void); extern long __VERIFIER_nondet_long(void); extern void *__VERIFIER_nondet_pointer(void); extern int __VERIFIER_nondet_int(); /* Generated by CIL v. 1.3.6 */ /* print_CIL_Input is true */ int ssl3_accept(int initial_state ) { int s__info_callback = __VERIFIER_nondet_int() ; int s__in_handshake = __VERIFIER_nondet_int() ; int s__state ; int s__new_session ; int s__server ; int s__version = __VERIFIER_nondet_int() ; int s__type ; int s__init_num ; int s__hit = __VERIFIER_nondet_int() ; int s__rwstate ; int s__init_buf___0 ; int s__debug = __VERIFIER_nondet_int() ; int s__shutdown ; int s__cert = __VERIFIER_nondet_int() ; int s__options = __VERIFIER_nondet_int() ; int s__verify_mode = __VERIFIER_nondet_int() ; int s__session__peer = __VERIFIER_nondet_int() ; int s__cert__pkeys__AT0__privatekey = __VERIFIER_nondet_int() ; int s__ctx__info_callback = __VERIFIER_nondet_int() ; int s__ctx__stats__sess_accept_renegotiate = __VERIFIER_nondet_int() ; int s__ctx__stats__sess_accept = __VERIFIER_nondet_int() ; int s__ctx__stats__sess_accept_good = __VERIFIER_nondet_int() ; int s__s3__tmp__cert_request ; int s__s3__tmp__reuse_message = __VERIFIER_nondet_int() ; int s__s3__tmp__use_rsa_tmp ; int s__s3__tmp__new_cipher = __VERIFIER_nondet_int() ; int s__s3__tmp__new_cipher__algorithms = __VERIFIER_nondet_int() ; int s__s3__tmp__next_state___0 ; int s__s3__tmp__new_cipher__algo_strength = __VERIFIER_nondet_int() ; int s__session__cipher ; int buf ; unsigned long l ; unsigned long Time ; unsigned long tmp ; int cb ; long num1 ; int ret ; int new_state ; int state ; int skip ; int got_new_session ; int tmp___1 = __VERIFIER_nondet_int() ; int tmp___2 = __VERIFIER_nondet_int() ; int tmp___3 = __VERIFIER_nondet_int() ; int tmp___4 = __VERIFIER_nondet_int() ; int tmp___5 = __VERIFIER_nondet_int() ; int tmp___6 = __VERIFIER_nondet_int() ; int tmp___7 ; long tmp___8 = __VERIFIER_nondet_long() ; int tmp___9 = __VERIFIER_nondet_int() ; int tmp___10 = __VERIFIER_nondet_int() ; int blastFlag ; int __cil_tmp55 ; unsigned long __cil_tmp56 ; unsigned long __cil_tmp57 ; unsigned long __cil_tmp58 ; unsigned long __cil_tmp59 ; int __cil_tmp60 ; unsigned long __cil_tmp61 ; { ; s__state = initial_state; blastFlag = 0; tmp = __VERIFIER_nondet_int(); Time = tmp; cb = 0; ret = -1; skip = 0; got_new_session = 0; if (s__info_callback != 0) { cb = s__info_callback; } else { if (s__ctx__info_callback != 0) { cb = s__ctx__info_callback; } } s__in_handshake ++; if (tmp___1 + 12288) { if (tmp___2 + 16384) { } } if (s__cert == 0) { return (-1); } { while (1) { while_0_continue: /* CIL Label */ ; state = s__state; if (s__state == 12292) { goto switch_1_12292; } else { if (s__state == 16384) { goto switch_1_16384; } else { if (s__state == 8192) { goto switch_1_8192; } else { if (s__state == 24576) { goto switch_1_24576; } else { if (s__state == 8195) { goto switch_1_8195; } else { if (s__state == 8480) { goto switch_1_8480; } else { if (s__state == 8481) { goto switch_1_8481; } else { if (s__state == 8482) { goto switch_1_8482; } else { if (s__state == 8464) { goto switch_1_8464; } else { if (s__state == 8465) { goto switch_1_8465; } else { if (s__state == 8466) { goto switch_1_8466; } else { if (s__state == 8496) { goto switch_1_8496; } else { if (s__state == 8497) { goto switch_1_8497; } else { if (s__state == 8512) { goto switch_1_8512; } else { if (s__state == 8513) { goto switch_1_8513; } else { if (s__state == 8528) { goto switch_1_8528; } else { if (s__state == 8529) { goto switch_1_8529; } else { if (s__state == 8544) { goto switch_1_8544; } else { if (s__state == 8545) { goto switch_1_8545; } else { if (s__state == 8560) { goto switch_1_8560; } else { if (s__state == 8561) { goto switch_1_8561; } else { if (s__state == 8448) { goto switch_1_8448; } else { if (s__state == 8576) { goto switch_1_8576; } else { if (s__state == 8577) { goto switch_1_8577; } else { if (s__state == 8592) { goto switch_1_8592; } else { if (s__state == 8593) { goto switch_1_8593; } else { if (s__state == 8608) { goto switch_1_8608; } else { if (s__state == 8609) { goto switch_1_8609; } else { if (s__state == 8640) { goto switch_1_8640; } else { if (s__state == 8641) { goto switch_1_8641; } else { if (s__state == 8656) { goto switch_1_8656; } else { if (s__state == 8657) { goto switch_1_8657; } else { if (s__state == 8672) { goto switch_1_8672; } else { if (s__state == 8673) { goto switch_1_8673; } else { if (s__state == 3) { goto switch_1_3; } else { goto switch_1_default; if (0) { switch_1_12292: s__new_session = 1; switch_1_16384: ; switch_1_8192: ; switch_1_24576: ; switch_1_8195: s__server = 1; if (cb != 0) { } { __cil_tmp55 = s__version * 8; if (__cil_tmp55 != 3) { return (-1); } } s__type = 8192; if (s__init_buf___0 == 0) { buf = __VERIFIER_nondet_int(); if (buf == 0) { ret = -1; goto end; } if (! tmp___3) { ret = -1; goto end; } s__init_buf___0 = buf; } if (! tmp___4) { ret = -1; goto end; } s__init_num = 0; if (s__state != 12292) { if (! tmp___5) { ret = -1; goto end; } s__state = 8464; s__ctx__stats__sess_accept ++; } else { s__ctx__stats__sess_accept_renegotiate ++; s__state = 8480; } goto switch_1_break; switch_1_8480: ; switch_1_8481: s__shutdown = 0; ret = __VERIFIER_nondet_int(); if (ret <= 0) { goto end; } s__s3__tmp__next_state___0 = 8482; s__state = 8448; s__init_num = 0; goto switch_1_break; switch_1_8482: s__state = 3; goto switch_1_break; switch_1_8464: ; switch_1_8465: ; switch_1_8466: s__shutdown = 0; ret = __VERIFIER_nondet_int(); if (blastFlag == 0) { blastFlag = 1; } if (ret <= 0) { goto end; } got_new_session = 1; s__state = 8496; s__init_num = 0; goto switch_1_break; switch_1_8496: ; switch_1_8497: ret = __VERIFIER_nondet_int(); if (blastFlag == 1) { blastFlag = 2; } if (ret <= 0) { goto end; } if (s__hit) { s__state = 8656; } else { s__state = 8512; } s__init_num = 0; goto switch_1_break; switch_1_8512: ; switch_1_8513: ; { __cil_tmp56 = (unsigned long )s__s3__tmp__new_cipher__algorithms; if (__cil_tmp56 + 256UL) { skip = 1; } else { ret = __VERIFIER_nondet_int(); if (blastFlag == 2) { blastFlag = 3; } if (ret <= 0) { goto end; } } } s__state = 8528; s__init_num = 0; goto switch_1_break; switch_1_8528: ; switch_1_8529: l = (unsigned long )s__s3__tmp__new_cipher__algorithms; { __cil_tmp57 = (unsigned long )s__options; if (__cil_tmp57 + 2097152UL) { s__s3__tmp__use_rsa_tmp = 1; } else { s__s3__tmp__use_rsa_tmp = 0; } } if (s__s3__tmp__use_rsa_tmp) { goto _L___0; } else { if (l + 30UL) { goto _L___0; } else { if (l + 1UL) { if (s__cert__pkeys__AT0__privatekey == 0) { goto _L___0; } else { { __cil_tmp58 = (unsigned long )s__s3__tmp__new_cipher__algo_strength; if (__cil_tmp58 + 2UL) { { __cil_tmp59 = (unsigned long )s__s3__tmp__new_cipher__algo_strength; if (__cil_tmp59 + 4UL) { tmp___7 = 512; } else { tmp___7 = 1024; } } { __cil_tmp60 = tmp___6 * 8; if (__cil_tmp60 > tmp___7) { _L___0: ret = __VERIFIER_nondet_int(); if (blastFlag == 3) { blastFlag = 4; } if (ret <= 0) { goto end; } } else { skip = 1; } } } else { skip = 1; } } } } else { skip = 1; } } } s__state = 8544; s__init_num = 0; goto switch_1_break; switch_1_8544: ; switch_1_8545: ; if (s__verify_mode + 1) { if (s__session__peer != 0) { if (s__verify_mode + 4) { skip = 1; s__s3__tmp__cert_request = 0; s__state = 8560; } else { goto _L___2; } } else { _L___2: { __cil_tmp61 = (unsigned long )s__s3__tmp__new_cipher__algorithms; if (__cil_tmp61 + 256UL) { if (s__verify_mode + 2) { goto _L___1; } else { skip = 1; s__s3__tmp__cert_request = 0; s__state = 8560; } } else { _L___1: s__s3__tmp__cert_request = 1; ret = __VERIFIER_nondet_int(); if (blastFlag == 4) { blastFlag = 5; } if (ret <= 0) { goto end; } s__state = 8448; s__s3__tmp__next_state___0 = 8576; s__init_num = 0; } } } } else { skip = 1; s__s3__tmp__cert_request = 0; s__state = 8560; } goto switch_1_break; switch_1_8560: ; switch_1_8561: ret = __VERIFIER_nondet_int(); if (ret <= 0) { goto end; } s__s3__tmp__next_state___0 = 8576; s__state = 8448; s__init_num = 0; goto switch_1_break; switch_1_8448: if (num1 > 0L) { s__rwstate = 2; num1 = tmp___8; if (num1 <= 0L) { ret = -1; goto end; } s__rwstate = 1; } s__state = s__s3__tmp__next_state___0; goto switch_1_break; switch_1_8576: ; switch_1_8577: ret = __VERIFIER_nondet_int(); if (blastFlag == 5) { blastFlag = 6; } if (ret <= 0) { goto end; } if (ret == 2) { s__state = 8466; } else { ret = __VERIFIER_nondet_int(); if (blastFlag == 6) { blastFlag = 7; } if (ret <= 0) { goto end; } s__init_num = 0; s__state = 8592; } goto switch_1_break; switch_1_8592: ; switch_1_8593: ret = __VERIFIER_nondet_int(); if (blastFlag == 7) { blastFlag = 8; } if (ret <= 0) { goto end; } s__state = 8608; s__init_num = 0; goto switch_1_break; switch_1_8608: ; switch_1_8609: ret = __VERIFIER_nondet_int(); if (blastFlag == 8) { blastFlag = 9; } if (ret <= 0) { goto end; } s__state = 8640; s__init_num = 0; goto switch_1_break; switch_1_8640: ; switch_1_8641: ret = __VERIFIER_nondet_int(); if (blastFlag == 9) { blastFlag = 10; } else { if (blastFlag == 12) { blastFlag = 13; } else { if (blastFlag == 15) { blastFlag = 16; } else { if (blastFlag == 18) { blastFlag = 19; } else { if (blastFlag == 21) { goto ERROR; } } } } } if (ret <= 0) { goto end; } if (s__hit) { s__state = 3; } else { s__state = 8656; } s__init_num = 0; goto switch_1_break; switch_1_8656: ; switch_1_8657: s__session__cipher = s__s3__tmp__new_cipher; if (! tmp___9) { ret = -1; goto end; } ret = __VERIFIER_nondet_int(); if (blastFlag == 10) { blastFlag = 11; } else { if (blastFlag == 13) { blastFlag = 14; } else { if (blastFlag == 16) { blastFlag = 17; } else { if (blastFlag == 19) { blastFlag = 20; } } } } if (ret <= 0) { goto end; } s__state = 8672; s__init_num = 0; if (! tmp___10) { ret = -1; goto end; } goto switch_1_break; switch_1_8672: ; switch_1_8673: ret = __VERIFIER_nondet_int(); if (blastFlag == 11) { blastFlag = 12; } else { if (blastFlag == 14) { blastFlag = 15; } else { if (blastFlag == 17) { blastFlag = 18; } else { if (blastFlag == 20) { blastFlag = 21; } } } } if (ret <= 0) { goto end; } s__state = 8448; if (s__hit) { s__s3__tmp__next_state___0 = 8640; } else { s__s3__tmp__next_state___0 = 3; } s__init_num = 0; goto switch_1_break; switch_1_3: s__init_buf___0 = 0; s__init_num = 0; if (got_new_session) { s__new_session = 0; s__ctx__stats__sess_accept_good ++; if (cb != 0) { } } ret = 1; goto end; switch_1_default: ret = -1; goto end; } else { switch_1_break: ; } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } if (! s__s3__tmp__reuse_message) { if (! skip) { if (s__debug) { ret = __VERIFIER_nondet_int(); if (ret <= 0) { goto end; } } if (cb != 0) { if (s__state != state) { new_state = s__state; s__state = state; s__state = new_state; } } } } skip = 0; } while_0_break: /* CIL Label */ ; } end: s__in_handshake --; if (cb != 0) { } return (ret); ERROR: __VERIFIER_error(); return (-1); } } int main(void) { int s ; int tmp ; { { s = 8464; tmp = ssl3_accept(s); } return (tmp); } }
the_stack_data/27229.c
#include <sys/mman.h> #include <sys/stat.h> #include <fcntl.h> #include <unistd.h> #include <stdlib.h> #include <stdio.h> int main(int argc, char *argv[]) { int fd; caddr_t addr; struct stat statbuf; if (argc != 2) { fprintf(stderr, "Usage : %s filename\n", argv[0]); exit(1); } if (stat(argv[1], &statbuf) == -1) { perror("stat"); exit(1); } if ((fd = open(argv[1], O_RDWR)) == -1) { perror("open"); exit(1); } addr = mmap(NULL, statbuf.st_size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, (off_t)0); if (addr == MAP_FAILED) { perror("mmap"); exit(1); } close(fd); printf("%s", addr); printf("---------\n"); addr[0] = 'D'; printf("%s", addr); msync(addr, statbuf.st_size, MS_SYNC); return 0; }
the_stack_data/173577472.c
#include <stdio.h> void swap(int* a, int* b) { int t = *a; *a = *b; *b = t; } int partition (int arr[], int low, int high) { int pivot = arr[high]; int i = (low - 1); for (int j = low; j <= high- 1; j++) { if (arr[j] < pivot) { i++; swap(&arr[i], &arr[j]); } } swap(&arr[i + 1], &arr[high]); return (i + 1); } void quickSort(int arr[], int low, int high) { if (low < high) { int pi = partition(arr, low, high); quickSort(arr, low, pi - 1); quickSort(arr, pi + 1, high); } } void printArray(int arr[], int size) { int i; for (i=0; i < size; i++) printf("%d ", arr[i]); printf("\n"); } int main() { int n,i; printf("Enter the number of elements:"); scanf("%d",&n); int arr[n]; printf("Enter the elements:"); for (i=0;i<n;i++) scanf("%d",&arr[i]); int a = sizeof(arr)/sizeof(arr[0]); quickSort(arr, 0, a-1); printf("Sorted array: \n"); printArray(arr, a); return 0; }
the_stack_data/175142928.c
//Write a menu based C program to perform operations (+,-and *) on matrices #include<stdio.h> int main() { int i, j, k, choice, m=2,n=2, sum=0; int first[2][2] = {5,6,7,8}, second[2][2] = {1,2,3,4}, result1[2][2], result2[2][2], result3[2][2]; lable: do { printf("\nEnter the choice :"); printf("\n 1 for Addition of two matrix"); printf("\n 2 for Subtraction of two matrix"); printf("\n 3 for Multiplication of two matrix"); printf("\n 0 for Exit"); printf("\n"); scanf("%d", &choice); if(choice != 0) break; }while(choice > 0); switch(choice) { case 0:break; case 1://program for addition of two matrices for(i=0; i<m; i++) { for(j=0; j<n; j++) { sum = 0; sum = first[i][j]+second[i][j]; result1[i][j] = sum; } } printf("Addition of two matrices:-\n"); for(i=0; i<m; i++) { for(j=0; j<n; j++) printf("%d\t", result1[i][j]); printf("\n"); } goto lable; break; case 2://program for subtraction of two matrices for(i=0; i<m; i++) { for(j=0; j<n; j++) { sum = 0; sum = first[i][j] - second[i][j]; result2[i][j] = sum; } } printf("Subtraction of two matrices:-\n"); for(i=0; i<m; i++) { for(j=0; j<n; j++) printf("%d\t", result2[i][j]); printf("\n"); } goto lable; break; case 3://program for multiplication of two matrices for(i=0; i<m; i++) { for(j=0; j<n; j++) { for(k=0; k<n; k++) sum = sum + first[i][k] * second[k][j]; result3[i][j] = sum; sum = 0; } } printf("Multiplication of two matrices:-\n"); for(i=0; i<m; i++) { for(j=0; j<n; j++) printf("%d\t", result3[i][j]); printf("\n"); } goto lable; break; default:printf("Invalid Input"); goto lable; break; } return 0; }
the_stack_data/153269021.c
// CONSTANTIN MIHAI - 336CA // Resurse // https://rosettacode.org/wiki/Fast_Fourier_transform#C #include <stdio.h> #include <stdlib.h> #include <math.h> #include <complex.h> #include <pthread.h> double PI = atan2(1, 1) * 4; FILE* in; FILE* out; int N; // number of values double* buffer; // values buffer int P; // number of threads typedef double complex cplx; void getArgs(int argc, char** argv) { if(argc < 4) { printf("Not enough paramters: ./homeworkFT inputValues.txt outputValues.txt numThreads\n"); exit(1); } in = fopen(argv[1], "r"); out = fopen(argv[2], "w"); if (in == NULL || out == NULL) { fprintf(stdout, "Failed to open at least one file.\n"); exit(1); } P = atoi(argv[3]); } void init() { int ret = fscanf(in, "%d", &N); if (ret != 1) { fprintf(stdout, "Failed to read N.\n"); exit(1); } buffer = (double*) malloc(N * sizeof(double)); for(int i = 0; i < N; i++) { ret = fscanf(in, "%lf", &buffer[i]); if (ret != 1) { fprintf(stdout, "Failed to read the %dth value from input file\n", i); exit(1); } } } void ft() { fprintf(out, "%d\n", N); for(double k = 0; k < N; k++) { // calculate X_k cplx xk = 0; for(int n = 0; n < N; n++) { xk += buffer[n] * cexp(-I * 2 * PI * k * (double)n / N); } fprintf(out, "%0.6lf %.6lf\n", creal(xk), cimag(xk)); } } int main(int argc, char* argv[]) { getArgs(argc, argv); init(); ft(); return 0; }
the_stack_data/248580556.c
#if defined(WIN32) || defined(_WIN32) #include <Winsock2.h> #include <windows.h> #include <iphlpapi.h> #include <stdio.h> #include <sys/types.h> #include <string.h> #include <malloc.h> #include <tchar.h> #include "../../lft_ifname.h" typedef enum { KWV_UNKNOWN, //while unknown (before first call of this module) KWV_VISTA, //Vista KWV_2K, //98/ME, NTSP4, W2K and XP KWV_NT4, //NT4 with SP<4 KWV_95 //Win95 }KNOWN_WIN_VERSION; static KNOWN_WIN_VERSION VerifyWindowsVersion() { static KNOWN_WIN_VERSION WinVersion=KWV_UNKNOWN; OSVERSIONINFOEX osvi; BOOL bOsVersionInfoEx; if(WinVersion!=KWV_UNKNOWN) return WinVersion; // Try calling GetVersionEx using the OSVERSIONINFOEX structure. // If that fails, try using the OSVERSIONINFO structure. ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX)); osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); if(!(bOsVersionInfoEx = GetVersionEx((OSVERSIONINFO *) &osvi))) { osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); if(!GetVersionEx( (OSVERSIONINFO *) &osvi)) return KWV_UNKNOWN; } switch(osvi.dwPlatformId) { case VER_PLATFORM_WIN32_NT: //Test for the Windows NT product family if(osvi.dwMajorVersion<=4) //NT4 { if(osvi.wServicePackMajor<4) WinVersion=KWV_NT4; else WinVersion=KWV_2K; } else { if(osvi.dwMajorVersion>5) WinVersion=KWV_VISTA; else WinVersion=KWV_2K; //2K and XP } break; case VER_PLATFORM_WIN32_WINDOWS: //Test for the Windows Me/98/95 default: WinVersion=KWV_95; break; } return WinVersion; } static u_long lft_getifaddr_95(const char *argifname) { HKEY key; char ethname[5]="eth/"; char pppname[5]="ppp/"; int i; FILETIME update; LONG res; DWORD size; u_long ret; char ifname[256]; if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"Enum\\Network\\MSTCP", 0, KEY_READ, &key) != ERROR_SUCCESS) return -1; size = sizeof(ifname); for(i=0;(res = RegEnumKeyEx(key, i, (LPTSTR)ifname, &size, 0, 0, 0, &update))!=ERROR_NO_MORE_ITEMS;i++) { HKEY ifkey, subkey; DWORD dsize,ipsize,npsize,asize; char driver[256], classname[256], netname[256]; char adapter[256], ip[256], np[256]; if(res != ERROR_SUCCESS || RegOpenKeyEx(key, (LPCTSTR)ifname, 0, KEY_READ, &ifkey) != ERROR_SUCCESS) continue; dsize = sizeof(driver); if(RegQueryValueEx(ifkey, L"Driver", 0, NULL, (unsigned char *)driver, &dsize) != ERROR_SUCCESS) { RegCloseKey(ifkey); continue; } strcpy(classname, "System\\CurrentControlSet\\Services\\Class\\"); strcat(classname, driver); if((res = RegOpenKeyEx(HKEY_LOCAL_MACHINE, (LPCTSTR)classname, 0, KEY_READ, &subkey)) != ERROR_SUCCESS) { RegCloseKey(ifkey); continue; } ipsize=sizeof(ip); npsize=sizeof(np); if(RegQueryValueEx(subkey, L"IPAddress", 0, NULL, (unsigned char *) ip, &ipsize) == ERROR_SUCCESS) { ret=inet_addr(ip); RegCloseKey (subkey); strcpy(netname, "System\\CurrentControlSet\\Services\\Class\\Net\\"); strcat(netname, ifname); if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, (LPCTSTR)netname, 0, KEY_READ, &subkey) != ERROR_SUCCESS) { RegCloseKey(ifkey); continue; } asize=sizeof(adapter); if( RegQueryValueEx (subkey, L"AdapterName", 0, NULL, (unsigned char *) adapter, &asize) == ERROR_SUCCESS && !strcmp(adapter, "MS$PPP")) { pppname[3]++; } else { ethname[3]++; } RegCloseKey(subkey); RegCloseKey(ifkey); if(!strcmp(pppname,argifname) || !strcmp(ethname,argifname)) break; else ret=-1; } } RegCloseKey(key); return ret; } static char * lft_getifname_95(struct in_addr addr) { HKEY key; char ethname[5]="eth/"; char pppname[5]="ppp/"; int i; FILETIME update; LONG res; DWORD size; u_long ret; int isethaddr,isfound; char ifname[256]; if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"Enum\\Network\\MSTCP", 0, KEY_READ, &key) != ERROR_SUCCESS) return NULL; size = sizeof(ifname); for(i=0;(res = RegEnumKeyEx(key, i, (TCHAR *)ifname, &size, 0, 0, 0, &update))!=ERROR_NO_MORE_ITEMS;i++) { HKEY ifkey, subkey; DWORD dsize,ipsize,npsize,asize; char driver[256], classname[256], netname[256]; char adapter[256], ip[256], np[256]; if(res != ERROR_SUCCESS || RegOpenKeyEx(key, (LPCTSTR)ifname, 0, KEY_READ, &ifkey) != ERROR_SUCCESS) continue; dsize = sizeof(driver); if(RegQueryValueEx(ifkey, L"Driver", 0, NULL, (unsigned char *)driver, &dsize) != ERROR_SUCCESS) { RegCloseKey(ifkey); continue; } strcpy(classname, "System\\CurrentControlSet\\Services\\Class\\"); strcat(classname, driver); if((res = RegOpenKeyEx(HKEY_LOCAL_MACHINE, (LPCTSTR)classname, 0, KEY_READ, &subkey)) != ERROR_SUCCESS) { RegCloseKey(ifkey); continue; } ipsize=sizeof(ip); npsize=sizeof(np); if(RegQueryValueEx(subkey, L"IPAddress", 0, NULL, (unsigned char *) ip, &ipsize) == ERROR_SUCCESS) { ret=inet_addr(ip); RegCloseKey (subkey); strcpy(netname, "System\\CurrentControlSet\\Services\\Class\\Net\\"); strcat(netname, ifname); if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, (LPCTSTR)netname, 0, KEY_READ, &subkey) != ERROR_SUCCESS) { RegCloseKey(ifkey); continue; } asize=sizeof(adapter); if( RegQueryValueEx (subkey, L"AdapterName", 0, NULL, (unsigned char *) adapter, &asize) == ERROR_SUCCESS && !strcmp(adapter, "MS$PPP")) { pppname[3]++; isethaddr=0; } else { ethname[3]++; isethaddr=1; } RegCloseKey(subkey); RegCloseKey(ifkey); if(ret==addr.s_addr) { isfound=1; break; } else isfound=0; } } RegCloseKey(key); if(!isfound) return NULL; if(isethaddr) return strdup(ethname); return strdup(pppname); } static u_long lft_getifaddr_NT4(const char *ifname) { HKEY key; char devname[256]; struct sockaddr_in *sa = NULL; struct sockaddr *so = NULL; DWORD size; int cnt = 1,isfound; u_long ret; char *binding = (char *)0; if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Linkage", 0, KEY_READ, &key) == ERROR_SUCCESS) { if(RegQueryValueEx(key, L"Bind", NULL, NULL, NULL, &size) == ERROR_SUCCESS) { binding = (char *)_alloca(size); if(RegQueryValueEx (key, L"Bind", NULL, NULL, (unsigned char *)binding, &size) != ERROR_SUCCESS) binding = NULL; } RegCloseKey(key); } if(binding) { char *bp, eth[2] = "/"; int ipsize; char cardkey[256], ipaddress[256]; for(bp = binding; *bp; bp+=strlen(bp)+1) { bp += strlen("\\Device\\"); strcpy(cardkey, "SYSTEM\\CurrentControlSet\\Services\\"); strcat(cardkey, bp); strcat(cardkey, "\\Parameters\\Tcpip"); if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, (LPCTSTR)cardkey, 0, KEY_READ, &key) != ERROR_SUCCESS) continue; ipsize=256; if(RegQueryValueEx(key, L"IPAddress", NULL, NULL, (unsigned char *) ipaddress, &ipsize) == ERROR_SUCCESS) { char *ip; for(ip = ipaddress; *ip; ip += strlen(ip)+1) { if(!strncmp(bp, "NdisWan", 7)) { strcpy(devname, "ppp"); strcat(devname, bp + 7); } else { eth[0]++; strcpy(devname, "eth"); strcat(devname, eth); } ret=inet_addr(ipaddress); if(!ret) { ipsize=256; if(RegQueryValueEx (key, L"DhcpIPAddress", NULL, NULL, (unsigned char *) ipaddress, &ipsize) == ERROR_SUCCESS) { ret=inet_addr(ipaddress); } } if(!strcmp(devname,ifname)) { isfound=1; break; } else isfound=0; } } RegCloseKey(key); if(isfound) return ret; } } return -1; } static char * lft_getifname_NT4(struct in_addr addr) { HKEY key; char devname[256]; struct sockaddr_in *sa = NULL; struct sockaddr *so = NULL; DWORD size; int cnt = 1,isfound; u_long ret; char *binding = (char *)0; if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Linkage", 0, KEY_READ, &key) == ERROR_SUCCESS) { if(RegQueryValueEx(key, L"Bind", NULL, NULL, NULL, &size) == ERROR_SUCCESS) { binding = (char *)_alloca(size); if(RegQueryValueEx (key, L"Bind", NULL, NULL, (unsigned char *)binding, &size) != ERROR_SUCCESS) binding = NULL; } RegCloseKey(key); } if(binding) { char *bp, eth[2] = "/"; int ipsize; char cardkey[256]; char ipaddress[256]; for(bp = binding; *bp; bp+=strlen(bp)+1) { bp += strlen("\\Device\\"); strcpy(cardkey, "SYSTEM\\CurrentControlSet\\Services\\"); strcat(cardkey, bp); strcat(cardkey, "\\Parameters\\Tcpip"); if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, (LPCTSTR)cardkey, 0, KEY_READ, &key) != ERROR_SUCCESS) continue; ipsize=256; if(RegQueryValueEx(key, L"IPAddress", NULL, NULL, (unsigned char *) ipaddress, &ipsize) == ERROR_SUCCESS) { char *ip; for(ip = ipaddress; *ip; ip += strlen(ip)+1) { if(!strncmp(bp, "NdisWan", 7)) { strcpy(devname, "ppp"); strcat(devname, bp + 7); } else { eth[0]++; strcpy(devname, "eth"); strcat(devname, eth); } ret=inet_addr(ipaddress); if(!ret) { ipsize=256; if(RegQueryValueEx (key, L"DhcpIPAddress", NULL, NULL, (unsigned char *) ipaddress, &ipsize) == ERROR_SUCCESS) { ret=inet_addr(ipaddress); } } if(addr.s_addr==ret) { isfound=1; break; } else isfound=0; } } RegCloseKey(key); if(isfound) return strdup(devname); } } return NULL; } static u_long lft_getifaddr_2K(const char *ifname) { int cnt = 0; int ethId = 0, pppId = 0, slpId = 0, tokId = 0; DWORD ip_cnt; DWORD siz_ip_table = 0; PMIB_IPADDRTABLE ipt; PMIB_IFROW ifrow; char devname[256]; typedef struct { DWORD ifIndex; size_t count; unsigned int enumerated; // for eth0:1 unsigned int classId; // for eth0, tok0 ... } ifcount_t; ifcount_t *iflist, *ifEntry; if(GetIpAddrTable (NULL, &siz_ip_table, TRUE) == ERROR_INSUFFICIENT_BUFFER) { ifrow = (PMIB_IFROW)_alloca(sizeof(MIB_IFROW)); ipt = (PMIB_IPADDRTABLE)_alloca(siz_ip_table); } if(GetIpAddrTable (ipt, &siz_ip_table, TRUE) != NO_ERROR) return -1; iflist = (ifcount_t *) alloca(sizeof(ifcount_t)*(ipt->dwNumEntries + 1)); memset(iflist, 0, sizeof (ifcount_t) * (ipt->dwNumEntries + 1)); for(ip_cnt = 0; ip_cnt < ipt->dwNumEntries; ++ip_cnt) { ifEntry = iflist; /* search for matching entry (and stop at first free entry) */ while(ifEntry->count != 0) { if(ifEntry->ifIndex == ipt->table[ip_cnt].dwIndex) break; ifEntry++; } if(ifEntry->count == 0) { ifEntry->count = 1; ifEntry->ifIndex = ipt->table[ip_cnt].dwIndex; } else { ifEntry->count++; } } // reset the last element. This is just the stopper for the loop. iflist[ipt->dwNumEntries].count = 0; for(ip_cnt = 0; ip_cnt < ipt->dwNumEntries; ip_cnt++) { ifcount_t *ifEntry = iflist; memset(ifrow, 0, sizeof(MIB_IFROW)); ifrow->dwIndex = ipt->table[ip_cnt].dwIndex; if(GetIfEntry(ifrow) != NO_ERROR) continue; /* search for matching entry (and stop at first free entry) */ while(ifEntry->count != 0) { if(ifEntry->ifIndex == ipt->table[ip_cnt].dwIndex) break; ifEntry++; } /* Setup the interface name */ switch(ifrow->dwType) { case MIB_IF_TYPE_TOKENRING: if(ifEntry->enumerated == 0) { ifEntry->classId = tokId++; sprintf(devname, "tok%u", ifEntry->classId); } else { sprintf(devname, "tok%u:%u", ifEntry->classId, ifEntry->enumerated - 1); } ifEntry->enumerated++; break; #ifdef IF_TYPE_IEEE80211 case IF_TYPE_IEEE80211: #endif case MIB_IF_TYPE_ETHERNET: if(ifEntry->enumerated == 0) { ifEntry->classId = ethId++; sprintf(devname, "eth%u", ifEntry->classId); } else { sprintf(devname, "eth%u:%u", ifEntry->classId, ifEntry->enumerated - 1); } ifEntry->enumerated++; break; case MIB_IF_TYPE_PPP: if(ifEntry->enumerated == 0) { ifEntry->classId = pppId++; sprintf(devname, "ppp%u", ifEntry->classId); } else { sprintf(devname, "ppp%u:%u", ifEntry->classId, ifEntry->enumerated - 1); } ifEntry->enumerated++; break; case MIB_IF_TYPE_SLIP: if(ifEntry->enumerated == 0) { ifEntry->classId = slpId++; sprintf(devname, "slp%u", ifEntry->classId); } else { sprintf(devname, "slp%u:%u", ifEntry->classId, ifEntry->enumerated - 1); } ifEntry->enumerated++; break; case MIB_IF_TYPE_LOOPBACK: strcpy(devname, "lo"); break; default: continue; } if(!strcmp(devname,ifname)) { return ipt->table[ip_cnt].dwAddr; } } return -1; } static char * lft_getifname_2K(struct in_addr addr) { int cnt = 0; int ethId = 0, pppId = 0, slpId = 0, tokId = 0; DWORD ip_cnt; DWORD siz_ip_table = 0; PMIB_IPADDRTABLE ipt; PMIB_IFROW ifrow; static char devname[256]; static struct in_addr savedaddr; static int FirstTime=1; typedef struct { DWORD ifIndex; size_t count; unsigned int enumerated; // for eth0:1 unsigned int classId; // for eth0, tok0 ... } ifcount_t; ifcount_t *iflist, *ifEntry; if(!FirstTime && savedaddr.s_addr==addr.s_addr) { return strdup(devname); } savedaddr.s_addr=addr.s_addr; if(GetIpAddrTable (NULL, &siz_ip_table, TRUE) == ERROR_INSUFFICIENT_BUFFER) { ifrow = (PMIB_IFROW)_alloca(sizeof(MIB_IFROW)); ipt = (PMIB_IPADDRTABLE)_alloca(siz_ip_table); } if(GetIpAddrTable (ipt, &siz_ip_table, TRUE) != NO_ERROR) return NULL; iflist = (ifcount_t *) alloca(sizeof(ifcount_t)*(ipt->dwNumEntries + 1)); memset(iflist, 0, sizeof (ifcount_t) * (ipt->dwNumEntries + 1)); for(ip_cnt = 0; ip_cnt < ipt->dwNumEntries; ++ip_cnt) { ifEntry = iflist; /* search for matching entry (and stop at first free entry) */ while(ifEntry->count != 0) { if(ifEntry->ifIndex == ipt->table[ip_cnt].dwIndex) break; ifEntry++; } if(ifEntry->count == 0) { ifEntry->count = 1; ifEntry->ifIndex = ipt->table[ip_cnt].dwIndex; } else { ifEntry->count++; } } // reset the last element. This is just the stopper for the loop. iflist[ipt->dwNumEntries].count = 0; for(ip_cnt = 0; ip_cnt < ipt->dwNumEntries; ip_cnt++) { ifcount_t *ifEntry = iflist; memset(ifrow, 0, sizeof(MIB_IFROW)); ifrow->dwIndex = ipt->table[ip_cnt].dwIndex; if(GetIfEntry(ifrow) != NO_ERROR) continue; /* search for matching entry (and stop at first free entry) */ while(ifEntry->count != 0) { if(ifEntry->ifIndex == ipt->table[ip_cnt].dwIndex) break; ifEntry++; } /* Setup the interface name */ switch(ifrow->dwType) { case MIB_IF_TYPE_TOKENRING: if(ifEntry->enumerated == 0) { ifEntry->classId = tokId++; sprintf(devname, "tok%u", ifEntry->classId); } else { sprintf(devname, "tok%u:%u", ifEntry->classId, ifEntry->enumerated - 1); } ifEntry->enumerated++; break; #ifdef IF_TYPE_IEEE80211 case IF_TYPE_IEEE80211: #endif case MIB_IF_TYPE_ETHERNET: if(ifEntry->enumerated == 0) { ifEntry->classId = ethId++; sprintf(devname, "eth%u", ifEntry->classId); } else { sprintf(devname, "eth%u:%u", ifEntry->classId, ifEntry->enumerated - 1); } ifEntry->enumerated++; break; case MIB_IF_TYPE_PPP: if(ifEntry->enumerated == 0) { ifEntry->classId = pppId++; sprintf(devname, "ppp%u", ifEntry->classId); } else { sprintf(devname, "ppp%u:%u", ifEntry->classId, ifEntry->enumerated - 1); } ifEntry->enumerated++; break; case MIB_IF_TYPE_SLIP: if(ifEntry->enumerated == 0) { ifEntry->classId = slpId++; sprintf(devname, "slp%u", ifEntry->classId); } else { sprintf(devname, "slp%u:%u", ifEntry->classId, ifEntry->enumerated - 1); } ifEntry->enumerated++; break; case MIB_IF_TYPE_LOOPBACK: strcpy(devname, "lo"); break; default: continue; } if(addr.s_addr==ipt->table[ip_cnt].dwAddr) { FirstTime=0; return strdup(devname); } } return NULL; } u_long lft_getifaddr (const char *ifname) { switch(VerifyWindowsVersion()) { case KWV_95: return lft_getifaddr_95(ifname); case KWV_2K: case KWV_VISTA: return lft_getifaddr_2K(ifname); case KWV_NT4: return lft_getifaddr_NT4(ifname); } return -1; } char * lft_getifname (struct in_addr addr) { static char ifname[256]; static struct in_addr savedaddr; static int FirstTime=1; char * ret; if(!FirstTime && savedaddr.s_addr==addr.s_addr) { return strdup(ifname); } switch(VerifyWindowsVersion()) { case KWV_95: ret=lft_getifname_95(addr); break; case KWV_2K: case KWV_VISTA: ret=lft_getifname_2K(addr); break; case KWV_NT4: ret=lft_getifname_NT4(addr); break; } savedaddr.s_addr=addr.s_addr; FirstTime=0; strncpy(ifname,ret,255); return ret; } #ifdef LFT_IFADDR_TESTING extern int main (int argc, char *argv[]) { struct in_addr in; char *addr; if (argc > 1) addr = strdup (argv[1]); else addr = strdup ("eth0"); in.s_addr = lft_getifaddr (addr); if (in.s_addr == -1) { fprintf (stderr, "%s: Error reading ifname\n", addr); fflush (stderr); free(addr); exit (-1); } fprintf (stdout, "%s: %s\n", addr, inet_ntoa (in)); fflush (stdout); free (addr); exit (0); } #endif /*LFT_IFNAME_TESTING*/ #endif
the_stack_data/356048.c
#include <stdio.h> #include <stdlib.h> #include <locale.h> /* 5) Cadastrar 10 estruturas a seguir: o horário de partida de vôos, com os dados: código, horário de partida, quantidade de passageiros, valor da passagem, origem e destino. Solicitar ao usuário a origem e mostrar todos os dados dos vôos que possuem esta origem. Mostrar, também, todos os vôos que possuem horário de partida pela manhã. */ #define viagem 2//10 struct aircompany { int code; int inicio_voo; int quant_passag; float preco; char origem[20]; char destino[20]; }; void infovoos(struct aircompany A[viagem]) { int cont; printf("\n========== Infomações de viagem ==========\n"); for (cont = 0; cont < viagem; cont++) { A[cont].inicio_voo >= 0 && A[cont].inicio_voo <= 23; printf("\nCódigo do voo: "); scanf("%d", &A[cont].code); printf("Horário de partida (Digite em numero inteiro): "); scanf("%d", &A[cont].inicio_voo); printf("Quantos passageiros: "); scanf("%d", &A[cont].quant_passag); printf("Preço da passagem: "); scanf("%f", &A[cont].preco); printf("Origem: "); scanf("%s", &A[cont].origem); printf("Destino: "); scanf("%s", &A[cont].destino); } } void passageiro(struct aircompany A[viagem]) { int cont; printf("\n========== Cadastro de Viagens ==========\n"); for (cont = 0; cont < viagem; cont++) { printf("Informe a origem da viagem: "); scanf("%s", &A[cont].origem); { printf("\nCódigo do voo: \n", A[cont].code); printf("Horário de partida (Digite em numero inteiro): \n", A[cont].inicio_voo); printf("Quantos passageiros: \n", A[cont].quant_passag); printf("Preço da passagem: \n", A[cont].preco); printf("Origem: \n", A[cont].origem); printf("Destino: \n", A[cont].destino); } } } void horamanha(struct aircompany A[viagem]) { int cont; printf("\n========== Horários disponíveis (Manhã) ==========\n"); for (cont = 0; cont < viagem; cont++) { if (A[cont].inicio_voo >= 6 || A[cont].inicio_voo <= 12) { printf("\nCódigo do voo: \n", A[cont].code); printf("Horário de partida (Digite em numero inteiro): \n", A[cont].inicio_voo); printf("Quantos passageiros: \n", A[cont].quant_passag); printf("Preço da passagem: \n", A[cont].preco); printf("Origem: \n", A[cont].origem); printf("Destino: \n", A[cont].destino); } } } struct aircompany B[viagem]; int main() { setlocale(LC_ALL, "Portuguese"); system("clear"); //system("cls"); infovoos(B); system("clear"); //system("cls"); passageiro(B); system("clear"); //system("cls"); horamanha(B); return 0; }
the_stack_data/50927.c
// // Longest_Common_Prefix.c // MyLeetCode // // Created by poco on 2019/2/11. // Copyright © 2019 zyy. All rights reserved. // char* longestCommonPrefix(char** strs, int strsSize) { if(strsSize == 0) { return ""; } else if(strsSize == 1) { return strs[0]; } int i,j; for(i = 1;i < strsSize;i++) { for(j = 0;strs[0][j] != '\0';j++) { if(strs[i][j] != strs[0][j]) { strs[0][j] = '\0'; if(j == 0) { return ""; } break; } } } return strs[0]; }
the_stack_data/8820.c
#include <stdio.h> int main(void){ double money = 1000000.0; int i = 0; do{ money = 1.08 * money - 100000.0; i++; printf("还剩下 %f 钱\n",money); }while(money >= 0); printf("经过 %d 年后把钱取完\n",i); return 0; }
the_stack_data/40763025.c
#include <stdio.h> #include <stdlib.h> #include <string.h> char const* dogGreet(void){ return "vau!"; } char const* dogMenu(void){ return "kuhanu govedinu"; } char const* catGreet(void){ return "mijau!"; } char const* catMenu(void){ return "konzerviranu tunjevinu"; } typedef char const* (*PTRFUN)(); // char const* (*dog_fs[2])() = {&dogGreet, &dogMenu}; // char const* (*cat_fs[2])() = {&catGreet, &catMenu}; PTRFUN dog_fs[] = {&dogGreet, &dogMenu}; PTRFUN cat_fs[] = {&catGreet, &catMenu}; struct Animal{ const char* name; PTRFUN* functions; }; void AnimalPrintGreeting(struct Animal* animal_ptr){ printf("%s pozdravlja: %s\n", animal_ptr->name, (*(animal_ptr->functions))()); } void AnimalPrintMenu(struct Animal* animal_ptr){ printf("%s voli: %s\n", animal_ptr->name, (*((animal_ptr->functions)+1))()); } struct Animal* constructDog( struct Animal* animal_ptr, char* dogName ){ animal_ptr->name = dogName; animal_ptr->functions = dog_fs; } struct Animal* constructCat( struct Animal* animal_ptr, char* catName ){ animal_ptr->name = catName; animal_ptr->functions = cat_fs; } struct Animal* createDog(char* name){ struct Animal* animal_mem = malloc(sizeof(struct Animal)); return constructDog(animal_mem, name); } struct Animal* createCat(char* name){ struct Animal* animal_mem = malloc(sizeof(struct Animal)); return constructDog(animal_mem, name); } void create_n_dogs(int n){ struct Animal* dogs = (struct Animal*) malloc(n*sizeof(struct Animal)); for(int i=0; i<n; i++){ char* buff = malloc(10*sizeof(char)); sprintf(buff,"%d", i+1); constructDog(dogs+i, buff); } for(int i=0; i<n; i++){ AnimalPrintGreeting((dogs+i)); } } void testAnimals(void){ struct Animal* p1=createDog("Hamlet"); struct Animal* p2=createCat("Ofelija"); struct Animal* p3=createDog("Polonije"); AnimalPrintGreeting(p1); AnimalPrintGreeting(p2); AnimalPrintGreeting(p3); AnimalPrintMenu(p1); AnimalPrintMenu(p2); AnimalPrintMenu(p3); free(p1); free(p2); free(p3); } int main(){ testAnimals(); create_n_dogs(15); //na stogu struct Animal doggo; doggo.name = "mr husky"; doggo.functions = dog_fs; AnimalPrintGreeting(&doggo); //na heapu struct Animal* doggo2 = createDog("mr corgi"); AnimalPrintGreeting(doggo2); }
the_stack_data/212643648.c
//Sprite created using Mollusk's PASpriteConverter //This sprite uses weapon_Pal const unsigned char weapon_9_Sprite[768] __attribute__ ((aligned (4))) = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32, 33, 0, 0, 0, 0, 0, 34, 6, 35, 36, 33, 0, 0, 34, 36, 35, 37, 37, 35, 0, 33, 34, 6, 35, 6, 36, 37, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 35, 33, 33, 0, 0, 0, 0, 0, 37, 37, 37, 33, 33, 0, 0, 0, 0, 32, 36, 36, 36, 37, 37, 35, 0, 33, 38, 37, 37, 35, 35, 6, 0, 33, 35, 36, 35, 36, 36, 36, 0, 0, 32, 37, 37, 36, 36, 33, 0, 0, 0, 32, 33, 33, 33, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 35, 36, 36, 37, 38, 36, 0, 0, 36, 36, 35, 35, 37, 35, 34, 0, 35, 36, 35, 37, 33, 0, 0, 0, 33, 33, 33, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 33, 33, 0, 0, 0, 0, 33, 33, 35, 35, 0, 0, 0, 33, 35, 36, 35, 37, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 33, 33, 34, 0, 0, 33, 33, 33, 38, 36, 34, 0, 0, 37, 37, 37, 38, 37, 0, 0, 0, 37, 36, 35, 35, 33, 0, 0, 0, 35, 36, 36, 35, 33, 0, 0, 0, 0, 0, 0, 6, 35, 37, 36, 37, 0, 0, 0, 36, 35, 37, 37, 37, 0, 0, 0, 34, 6, 35, 37, 35, 0, 0, 0, 34, 36, 36, 37, 35, 0, 0, 0, 32, 36, 38, 36, 35, 0, 0, 0, 0, 33, 38, 32, 37, 0, 0, 0, 0, 0, 33, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 36, 36, 33, 0, 0, 0, 0, 6, 36, 33, 0, 0, 0, 0, 0, 36, 36, 0, 0, 0, 0, 0, 0, 36, 33, 0, 0, 0, 0, 0, 0, 33, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 36, 0, 0, 0, 0, 0, 0, 33, 38, 0, 0, 0, 0, 0, 0, 33, 37, 0, 0, 0, 0, 0, 33, 37, 36, 0, 0, 0, 0, 0, 33, 37, 36, 0, 0, 0, 0, 0, 35, 37, 35, 0, 0, 0, 0, 0, 0, 0, 0, 34, 0, 0, 0, 0, 0, 0, 0, 35, 0, 0, 0, 0, 0, 0, 0, 37, 33, 0, 0, 0, 0, 0, 0, 35, 37, 0, 0, 0, 0, 0, 0, 35, 35, 33, 0, 0, 0, 0, 0, 36, 36, 33, 0, 0, 0, 0, 0, 36, 35, 33, 0, 0, 0, 0, 0, 0, 0, 0, 0, 33, 35, 37, 35, 0, 0, 0, 0, 36, 37, 36, 37, 0, 0, 0, 33, 35, 37, 6, 37, 0, 0, 0, 32, 6, 35, 35, 36, 0, 0, 0, 0, 34, 36, 6, 36, 0, 0, 0, 0, 0, 34, 34, 36, 0, 0, 0, 0, 0, 0, 33, 32, 0, 0, 0, 0, 0, 0, 0, 0, 6, 36, 33, 0, 0, 0, 0, 0, 35, 36, 36, 33, 0, 0, 0, 0, 35, 36, 36, 33, 0, 0, 0, 0, 37, 35, 37, 33, 0, 0, 0, 0, 37, 36, 37, 32, 0, 0, 0, 0, 38, 35, 32, 0, 0, 0, 0, 0, 33, 33, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
the_stack_data/38365.c
int foo(){ __asm__("#called"); return 1; } int main(){ __asm__("#call"); return foo(); }
the_stack_data/117192.c
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_atoi_base.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: angmarti <[email protected]> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2021/08/22 20:18:38 by angmarti #+# #+# */ /* Updated: 2021/08/25 00:41:52 by angmarti ### ########.fr */ /* */ /* ************************************************************************** */ #include <unistd.h> #include <stdio.h> #include <stdlib.h> int ft_atoi(char *str); int ft_ckeck_base(char *base); void ft_putnbr_base_aux(int nbr, char *base, char str[], int k) { int i; int negativo; long num; num = nbr; if (nbr < 0) { num *= -1; negativo = 1; } i = -1; while (i++ < 35) str[i] = ' '; i = 0; while (num >= k && i < 32) { str[32 - i] = base[num % k]; num /= k; i++; } str[32 - i++] = base[num]; if (negativo) str[32 - i] = '-'; } int ckeck_base(char *base) { int base_ok; int i; int j; i = -1; base_ok = 1; if (base[0] == '\0' || base[1] == '\0') base_ok = 0; while (base[++i] && base_ok) { if (*base == '+' || *base == '-') base_ok = 0; j = i; while (base[++j] && base_ok) if (base[i] == base[j]) base_ok = 0; } return (base_ok); } char *ft_putnbr_base(int nbr, char *base, char s[]) { int i; int j; int k; int base_ok; base_ok = ckeck_base(base); if (base_ok) { k = 0; while (base[k]) k++; ft_putnbr_base_aux(nbr, base, s, k); i = 34; // while (s[i] == ' ' && i < 32) // i++; j = 0; // while (--i >= 0){ // // printf("i: %d\tc: '%c'\n", i, s[i]); // } // printf("\n%s\n", s); } return (s); } int ft_atoi(char *str) { int multiplier; int status; int num; multiplier = 1; status = 0; num = 0; while (status != -1 && *str) { if (!(status == 0 && *str == ' ') && status == 1 && !(*str >= '0' && *str <= '9')) status = -1; else if (!(status == 0 && *str == ' ') && ((*str >= '0' && *str <= '9') || *str == '-')) { status = 1; if (*str == '-') multiplier *= -1; else if (*str >= '0' && *str <= '9') num = num * 10 + *str - '0' ; } str++; } return (num * multiplier); } int ft_atoi_base(char *str, char *base) { int nbr; char nbr_str[35]; nbr = ft_atoi(str); printf("Primer atoi: %d\n", nbr); printf("Number base: %s\n", ft_putnbr_base(nbr, base, nbr_str)); ft_atoi(ft_putnbr_base(nbr, base, nbr_str)); printf("Second atoi: %d\n", ft_atoi(ft_putnbr_base(nbr, base, nbr_str))); return (ft_atoi(ft_putnbr_base(nbr, base, nbr_str))); } int main(void) { int n; n = ft_atoi_base("-123456", "01234567"); // printf("%d\n", n); }
the_stack_data/7949798.c
int numWays(int n){ int a = 1, b = 1, c; for (int i=2; i<=n; ++i) { c = b; b = (a+b)%1000000007; a = c; } return b; }
the_stack_data/242330752.c
#include <stdio.h> // The main entry point for the application. int main() { printf("Hello, World!\n"); }
the_stack_data/10435.c
#define Dim 1000 #include "syscall.h" int A[Dim]; int random[11]; int random2[11]; main() { int i; int j; random[0] = 694; random[1] = 692; random[2] = 462; random[3] = 129; random[4] = 910; random[5] = 732; random[6] = 363; random[7] = 777; random[8] = 395; random[9] = 326; random[10] = 680; random2[0] =421; random2[1] =60; random2[2] =720; random2[3] =590; random2[4] =590; random2[5] =812; random2[6] =648; random2[7] =245; random2[8] =594; random2[9] =941; random2[10]=492; for (i = 0; i < Dim; i++) /* first initialize the matrices */ { A[i]=i; } for (i = 0; i < 11; i++) /* first initialize the matrices */ { A[random[i]] = i; } for (i = 0; i < 11; i++) /* first initialize the matrices */ { A[random2[i]]=i ; } Exit(1); }
the_stack_data/118184.c
/* pgen.c Password Generator. Written by someone, sometime, somewhere. The author of this software shall not be held responsible for the user's use, misuse, or abuse of this software. The user of this software assumes all risk and liability arising out of their use, misuse, or abuse of this software. This software is provided "AS IS" without any warranty of any kind whatsoever. The user that uses this software does so entirely at their own risk. This software is provided for educational purposes only and is not intended to be used for any illegal purpose. This program sends the output string to stdout using printf() instead of using a file pointer with fprintf() to eliminate one stack access operation. This program has been optimized for speed. All other output uses fprintf() to send the output to stderr which, unless redirected on the command line when running the program, will send such messages to the screen while allowing the user to send each output string to a file by redirecting stdout to a file when running this program from the command line. This program could generate a file that is so large that the file system will be unable to handle it. If this progam is run on a computer running something like Linux or Unix then the user could redirect stdout to a pipe file that had another program waiting to read the data. Using SUPPRESS_OUTPUT allows the user to gauge the performance of the program's logic apart from any delays associated with its output. The time specified in the performance statistics may differ from how long it appears to take for the program to run if your device is not able to print the output fast enough to keep up with the program. The program's output may be buffered by your operating system even when printing to the screen. */ #include <stdio.h> #include <stdlib.h> /* Define DEBUG if you want to print debugging output. */ #define DEBUG /* Define SUPPRESS_OUTPUT if you don't want the output string printed. */ #undef SUPPRESS_OUTPUT /* Define SHOW_STATS if you want the performance statistics printed. */ #undef SHOW_STATS #ifdef SHOW_STATS #include <time.h> #endif /* Put the characters you want to use in your passwords in the choices array. If you put them in in the correct order, the output will be sorted, otherwise it won't be. The last entry in the choices array MUST be 0. Specify the smallest and largest password lengths you would like to find. You may use up to 63 characters in your passwords. The space character is ASCII 32d. The zero character is ASCII 48d. There are 95 different 7 bit characters that can be typed from a common US keyboard. */ /* char choices[] = { 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 0 }; */ /* */ char choices[] = { 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 0 }; /* */ char str[ 64 ]; signed long int pos[ 64 ]; const signed int smallest = 8; const signed int largest = 63; int main( void ) { signed int current, exit_inner_loop; signed int exit_outer_loop, last, num_choices; register signed int count; #ifdef SHOW_STATS time_t seconds, start, stop; unsigned long long int acc, max, mem, total; #endif /* Make sure we have values we can use. */ if ( largest > 63 ) { fprintf( stderr, "Invalid value for largest: %d.\n", largest ); exit( EXIT_FAILURE ); } if ( smallest < 1 || smallest > largest ) { fprintf( stderr, "Invalid value for smallest: %d.\n", smallest ); exit( EXIT_FAILURE ); } /* Find out how many choices we have available. */ num_choices = 0; while( choices[ num_choices ] != 0 && num_choices < 96 ) { num_choices++; } /* It doesn't help to try the same password twice. This can also happen if the last entry in the choices array is not null. */ if ( num_choices == 96 ) { fprintf( stderr, "Too many entries in the choices array.\n" ); exit( EXIT_FAILURE ); } /* We can't make any passwords if we don't have anything to work with. */ if ( num_choices == 0 ) { fprintf( stderr, "No choices available.\n" ); exit( EXIT_FAILURE ); } #ifdef SHOW_STATS /* Make sure total won't overflow while the program is running. */ /* max is max unsigned long long int */ max = ( unsigned long long int )18446744073709551615; for( count = smallest; count <= largest; count++ ) { acc = 1; for( current = 0; current < count; current++ ) { mem = acc; acc = acc * ( unsigned long long int )num_choices; if ( mem > acc ) { fprintf( stderr, "\ (1) Data type overflow with %d characters in the output string.\n\ (1) To avoid this problem either undefine SHOW_STATS or change largest.\n", count ); exit( EXIT_FAILURE ); } } if ( max < acc ) { fprintf( stderr, "\ (2) Data type overflow with %d characters in the output string.\n\ (2) To avoid this problem either undefine SHOW_STATS or change largest.\n", count ); exit( EXIT_FAILURE ); } max = max - acc; } #endif /* Clear the output string and the position array. */ for( count = 63; count != 0; count-- ) { str[ count ] = 0; pos[ count ] = -1; } str[ 0 ] = 0; pos[ 0 ] = -1; #ifdef DEBUG fprintf( stderr, "(1) choices(%d): { ", ( num_choices + 1 ) ); for( count = 0; count < num_choices; count++ ) { fprintf( stderr, "\'%c\', ", choices[ count ] ); } if ( choices[ count ] == 0 ) { fprintf( stderr, "\'\\0\' }\n" ); } else { fprintf( stderr, "\'%c\' }\n", choices[ count ] ); fprintf( stderr, "The choices array does not end with null.\n" ); exit( EXIT_FAILURE ); } fprintf( stderr, "(2) smallest: %d, largest: %d.\n", smallest, largest ); #endif /* Load the output string and position array with initial values. */ for( count = 0; count < smallest; count++ ) { str[ count ] = choices[ 0 ]; pos[ count ] = 0; } /* last is the array position of the last character in the output string. */ last = smallest - 1; /* Adjust num_choices to be used as an array position. */ num_choices--; #ifdef DEBUG fprintf( stderr, "\ (3) Starting str: \"%s\", last: %d, num_choices: %d.\n", str, last, num_choices ); #endif exit_outer_loop = 0; #ifdef SHOW_STATS total = 0; start = time( NULL ); #endif /* This is the part of the program that does the real work. */ do { current = last; #ifndef SUPPRESS_OUTPUT /* Print the current output string. */ printf( "%s\n", str ); #endif #ifdef SHOW_STATS total++; #endif /* Increment if we can or roll it over and carry. */ if ( pos[ current ] < num_choices ) { ( pos[ current ] )++; str[ current ] = choices[ pos[ current ] ]; } else /* Roll over and carry. */ { exit_inner_loop = 0; do { if ( current == 0 ) { /* If so, we're done. */ if ( ( last + 1 ) == largest ) { exit_inner_loop = 1; exit_outer_loop = 1; } else /* Otherwise add another character. */ { last++; for( count = last; count != 0; count-- ) { str[ count ] = choices[ 0 ]; pos[ count ] = 0; } str[ 0 ] = choices[ 0 ]; pos[ 0 ] = 0; exit_inner_loop = 1; } } else /* current != 0 */ { /* Roll over the current character. */ pos[ current ] = 0; str[ current ] = choices[ 0 ]; /* Move to the previous character. */ current--; /* Increment if we can. */ if ( pos[ current ] < num_choices ) { ( pos[ current ] )++; str[ current ] = choices[ pos[ current ] ]; exit_inner_loop = 1; } } /* if ( current == 0 ) */ } while( exit_inner_loop == 0 ); } /* if ( pos[ last ] < num_choices ) */ } while( exit_outer_loop == 0 ); /* Now we're done. Show the performance statistics if requested and exit. */ #ifdef SHOW_STATS stop = time( NULL ); seconds = stop - start; /* My compiler, C4droid, requires %llu to print an unsigned long long int. */ fprintf( stderr, "total: %llu.\n", total ); if ( seconds == 1 ) { fprintf( stderr, "Time taken: 1 second.\n" ); } else { fprintf( stderr, "Time taken: %d seconds.\n", seconds ); } if ( seconds == 0 ) { fprintf( stderr, "\ Insufficient runtime to determine approximate combinations per second.\n" ); } else { fprintf( stderr, "Approximate combinations per second: %lu.\n", ( unsigned long int )( total / ( unsigned long long int )seconds ) ); } #endif #ifdef SUPPRESS_OUTPUT /* Show something to let the user know we're done. */ fprintf( stderr, "Program finished.\nExiting.\n" ); #endif exit( EXIT_SUCCESS ); } /* EOF pgen.c */
the_stack_data/37373.c
/* Write a program to print the corresponding C to F table */ /* add a different function to go from C to F && re-use the * structure of the previous program*/ #include <stdio.h> float fahrenheitToCelsius(int f); float celsiusToFahrenheit(int c); int main(void) { int i, s, step, limit; float cel; i = 1; // 1 = special case we want to print s = 20; // start at twenty step = 20; // increase base temp in increments of 20 printf(" C : F\n"); // header printf("%3d : %3.1f\n", i, celsiusToFahrenheit(i)); while ( s < 320 ) { printf("%3d : %3.1f\n", s, celsiusToFahrenheit(s)); s += step; } } float fahrenheitToCelsius(int f) { return (f - 32) * (5.0 / 9.0); } float celsiusToFahrenheit(int c) { // with transitivity and order of operations this should work return c * 9 / 5 + 32; }
the_stack_data/7836.c
#include <stdio.h> int minimum(int no1, int no2); int maximum(int no1, int no2); int multiply(int no1, int no2); int main() { int no1, no2; printf("Enter a value for no 1 : "); scanf("%d", &no1); printf("Enter a value for no 2 : "); scanf("%d", &no2); printf("%d ", minimum(no1, no2)); printf("%d ", maximum(no1, no2)); printf("%d ", multiply(no1, no2)); return 0; } int minimum(int no1, int no2) { if (no1>no2) { return no2; } else { return no1; } } int maximum(int no1, int no2) { if (no1>no2) { return no1; } else { return no2; } } int multiply(int no1, int no2) { return no1 * no2; }
the_stack_data/211079921.c
/*** * This code is a part of EvoApproxLib library (ehw.fit.vutbr.cz/approxlib) distributed under The MIT License. * When used, please cite the following article(s): V. Mrazek, R. Hrbacek, Z. Vasicek and L. Sekanina, "EvoApprox8b: Library of approximate adders and multipliers for circuit design and benchmarking of approximation methods". Design, Automation & Test in Europe Conference & Exhibition (DATE), 2017, Lausanne, 2017, pp. 258-261. doi: 10.23919/DATE.2017.7926993 * This file contains a circuit from evoapprox8b dataset. Note that a new version of library was already published. ***/ #include <stdint.h> #include <stdlib.h> /// Approximate function add8_286 /// Library = EvoApprox8b /// Circuit = add8_286 /// Area (180) = 840 /// Delay (180) = 1.620 /// Power (180) = 222.10 /// Area (45) = 61 /// Delay (45) = 0.620 /// Power (45) = 21.87 /// Nodes = 12 /// HD = 138496 /// MAE = 1.73438 /// MSE = 6.17188 /// MRE = 0.89 % /// WCE = 7 /// WCRE = 100 % /// EP = 71.7 % uint16_t add8_286(uint8_t a, uint8_t b) { uint16_t c = 0; uint8_t n0 = (a >> 0) & 0x1; uint8_t n2 = (a >> 1) & 0x1; uint8_t n4 = (a >> 2) & 0x1; uint8_t n6 = (a >> 3) & 0x1; uint8_t n8 = (a >> 4) & 0x1; uint8_t n10 = (a >> 5) & 0x1; uint8_t n12 = (a >> 6) & 0x1; uint8_t n14 = (a >> 7) & 0x1; uint8_t n18 = (b >> 1) & 0x1; uint8_t n20 = (b >> 2) & 0x1; uint8_t n22 = (b >> 3) & 0x1; uint8_t n24 = (b >> 4) & 0x1; uint8_t n26 = (b >> 5) & 0x1; uint8_t n28 = (b >> 6) & 0x1; uint8_t n30 = (b >> 7) & 0x1; uint8_t n37; uint8_t n50; uint8_t n66; uint8_t n82; uint8_t n85; uint8_t n126; uint8_t n132; uint8_t n182; uint8_t n183; uint8_t n232; uint8_t n233; uint8_t n282; uint8_t n283; uint8_t n332; uint8_t n333; uint8_t n382; uint8_t n383; n37 = ~(n6 | n14 | n30); n50 = n20 & n37; n66 = n4 & n50; n82 = n2 | n18; n85 = n66; n126 = ~(n0 & n85); n132 = n4 | n20; n182 = (n6 ^ n22) ^ n85; n183 = (n6 & n22) | (n22 & n85) | (n6 & n85); n232 = (n8 ^ n24) ^ n183; n233 = (n8 & n24) | (n24 & n183) | (n8 & n183); n282 = (n10 ^ n26) ^ n233; n283 = (n10 & n26) | (n26 & n233) | (n10 & n233); n332 = (n12 ^ n28) ^ n283; n333 = (n12 & n28) | (n28 & n283) | (n12 & n283); n382 = (n14 ^ n30) ^ n333; n383 = (n14 & n30) | (n30 & n333) | (n14 & n333); c |= (n126 & 0x1) << 0; c |= (n82 & 0x1) << 1; c |= (n132 & 0x1) << 2; c |= (n182 & 0x1) << 3; c |= (n232 & 0x1) << 4; c |= (n282 & 0x1) << 5; c |= (n332 & 0x1) << 6; c |= (n382 & 0x1) << 7; c |= (n383 & 0x1) << 8; return c; }
the_stack_data/448591.c
/* Exercise 1 - Calculations Write a C program to input marks of two subjects. Calculate and print the average of the two marks. */ //Ex1 #include <stdio.h> int main() { int mark1 , mark2 , tot; float avg; printf("Enter mark 1 : "); scanf("%d",&mark1); printf("Enter mark2 : "); scanf("%d",&mark2); tot = mark1 + mark2; avg = tot/2; printf("Avarage is : %.2f",avg); return 0; }
the_stack_data/173578464.c
// // Sample Code: // #include <stdio.h> #include <stdlib.h> #include <string.h> void pre_Initializing_Input_Tensors(); void post_Correctness(); int main(int argc, char** argv) { // for sd2 double *host_t3, *host_t3_chk; double *host_t2_1, *host_t2_2, *host_t2_3, *host_t2_4, *host_t2_5, *host_t2_6, *host_t2_7, *host_t2_8, *host_t2_9; double *host_v2_1, *host_v2_2, *host_v2_3, *host_v2_4, *host_v2_5, *host_v2_6, *host_v2_7, *host_v2_8, *host_v2_9; int size_h3, size_h2, size_h1, size_p6, size_p5, size_p4, size_h7; int opt_register_transpose; // Problem Size size_h3 = 16; size_h2 = 16; size_h1 = 16; size_p6 = 16; size_p5 = 16; size_p4 = 16; size_h7 = 16; opt_register_transpose = 1; // if (argc == 9) { size_h3 = atoi(argv[1]); size_h2 = atoi(argv[2]); size_h1 = atoi(argv[3]); size_p6 = atoi(argv[4]); size_p5 = atoi(argv[5]); size_p4 = atoi(argv[6]); size_h7 = atoi(argv[7]); opt_register_transpose = atoi(argv[8]); } printf (">>> Problem Size (h3,h2,h1,p6,p5,p4) and (h7): (%2d,%2d,%2d,%2d,%2d,%2d) and (%2d)\n", size_h3, size_h2, size_h1, size_p6, size_p5, size_p4, size_h7); printf (">>> Option for Register Transpose: %2d\n", opt_register_transpose); int size_T3; int size_T2_1, size_T2_2, size_T2_3, size_T2_4, size_T2_5, size_T2_6, size_T2_7, size_T2_8, size_T2_9; int size_V2_1, size_V2_2, size_V2_3, size_V2_4, size_V2_5, size_V2_6, size_V2_7, size_V2_8, size_V2_9; int size_internal; // size_internal = size_h7; size_T3 = size_h3 * size_h2 * size_h1 * size_p6 * size_p5 * size_p4; /* >> sd1 << 1: t3 [h3,16,h2,16,h1,16,p6,16,p5,16,p4,16] -= sum(h7,16) * t2_1 [h7,p4,p5,h1] * v2_1 [h3,h2,p6,h7]; 2: t3 [h3,16,h2,16,h1,16,p6,16,p5,16,p4,16] += sum(h7,16) * t2_2 [h7,p4,p5,h2] * v2_2 [h3,h1,p6,h7]; 3: t3 [h3,16,h2,16,h1,16,p6,16,p5,16,p4,16] -= sum(h7,16) * t2_3 [h7,p4,p5,h3] * v2_3 [h2,h1,p6,h7]; 4: t3 [h3,16,h2,16,h1,16,p6,16,p5,16,p4,16] -= sum(h7,16) * t2_4 [h7,p5,p6,h1] * v2_4 [h3,h2,p4,h7]; 5: t3 [h3,16,h2,16,h1,16,p6,16,p5,16,p4,16] += sum(h7,16) * t2_5 [h7,p5,p6,h2] * v2_5 [h3,h1,p4,h7]; 6: t3 [h3,16,h2,16,h1,16,p6,16,p5,16,p4,16] -= sum(h7,16) * t2_6 [h7,p5,p6,h3] * v2_6 [h2,h1,p4,h7]; 7: t3 [h3,16,h2,16,h1,16,p6,16,p5,16,p4,16] += sum(h7,16) * t2_7 [h7,p4,p6,h1] * v2_7 [h3,h2,p5,h7]; 8: t3 [h3,16,h2,16,h1,16,p6,16,p5,16,p4,16] -= sum(h7,16) * t2_8 [h7,p4,p6,h2] * v2_8 [h3,h1,p5,h7]; 9: t3 [h3,16,h2,16,h1,16,p6,16,p5,16,p4,16] += sum(h7,16) * t2_8 [h7,p4,p6,h3] * v2_9 [h2,h1,p5,h7]; */ // size_T2_1 = size_h7 * size_p4 * size_p5 * size_h1; size_V2_1 = size_h3 * size_h2 * size_p6 * size_h7; size_T2_2 = size_h7 * size_p4 * size_p5 * size_h2; size_V2_2 = size_h3 * size_h1 * size_p6 * size_h7; size_T2_3 = size_h7 * size_p4 * size_p5 * size_h3; size_V2_3 = size_h2 * size_h1 * size_p6 * size_h7; size_T2_4 = size_h7 * size_p5 * size_p6 * size_h1; size_V2_4 = size_h3 * size_h2 * size_p4 * size_h7; size_T2_5 = size_h7 * size_p5 * size_p6 * size_h2; size_V2_5 = size_h3 * size_h1 * size_p4 * size_h7; size_T2_6 = size_h7 * size_p5 * size_p6 * size_h3; size_V2_6 = size_h2 * size_h1 * size_p4 * size_h7; size_T2_7 = size_h7 * size_p4 * size_p6 * size_h1; size_V2_7 = size_h3 * size_h2 * size_p5 * size_h7; size_T2_8 = size_h7 * size_p4 * size_p6 * size_h2; size_V2_8 = size_h3 * size_h1 * size_p5 * size_h7; size_T2_9 = size_h7 * size_p4 * size_p6 * size_h3; size_V2_9 = size_h2 * size_h1 * size_p5 * size_h7; host_t3 = (double*)malloc(sizeof(double) * size_T3); host_t3_chk = (double*)malloc(sizeof(double) * size_T3); host_t2_1 = (double*)malloc(sizeof(double) * size_T2_1); host_t2_2 = (double*)malloc(sizeof(double) * size_T2_2); host_t2_3 = (double*)malloc(sizeof(double) * size_T2_3); host_t2_4 = (double*)malloc(sizeof(double) * size_T2_4); host_t2_5 = (double*)malloc(sizeof(double) * size_T2_5); host_t2_6 = (double*)malloc(sizeof(double) * size_T2_6); host_t2_7 = (double*)malloc(sizeof(double) * size_T2_7); host_t2_8 = (double*)malloc(sizeof(double) * size_T2_8); host_t2_9 = (double*)malloc(sizeof(double) * size_T2_9); host_v2_1 = (double*)malloc(sizeof(double) * size_V2_1); host_v2_2 = (double*)malloc(sizeof(double) * size_V2_2); host_v2_3 = (double*)malloc(sizeof(double) * size_V2_3); host_v2_4 = (double*)malloc(sizeof(double) * size_V2_4); host_v2_5 = (double*)malloc(sizeof(double) * size_V2_5); host_v2_6 = (double*)malloc(sizeof(double) * size_V2_6); host_v2_7 = (double*)malloc(sizeof(double) * size_V2_7); host_v2_8 = (double*)malloc(sizeof(double) * size_V2_8); host_v2_9 = (double*)malloc(sizeof(double) * size_V2_9); printf ("==========================================================================================================\n"); printf (" >>> %s <<<\n", __func__); printf (" T3: %'12d\n", size_T3); printf (" T2_1: %'12d, V2_1: %'12d\n", size_T2_1, size_V2_1); printf (" T2_2: %'12d, V2_2: %'12d\n", size_T2_2, size_V2_2); printf (" T2_3: %'12d, V2_3: %'12d\n", size_T2_3, size_V2_3); printf (" T2_4: %'12d, V2_4: %'12d\n", size_T2_4, size_V2_4); printf (" T2_5: %'12d, V2_5: %'12d\n", size_T2_5, size_V2_5); printf (" T2_6: %'12d, V2_6: %'12d\n", size_T2_6, size_V2_6); printf (" T2_7: %'12d, V2_7: %'12d\n", size_T2_7, size_V2_7); printf (" T2_8: %'12d, V2_8: %'12d\n", size_T2_8, size_V2_8); printf (" T2_9: %'12d, V2_9: %'12d\n", size_T2_9, size_V2_9); printf ("==========================================================================================================\n"); // // Initialze "1" Output and "2 x 9" Inputs pre_Initializing_Input_Tensors(host_t3, host_t3_chk, host_t2_1, host_v2_1, host_t2_2, host_v2_2, host_t2_3, host_v2_3, host_t2_4, host_v2_4, host_t2_5, host_v2_5, host_t2_6, host_v2_6, host_t2_7, host_v2_7, host_t2_8, host_v2_8, host_t2_9, host_v2_9, size_h3, size_h2, size_h1, size_p6, size_p5, size_p4, size_h7); // Run the Kernels sd_t_d2_fusion_(size_h3, size_h2, size_h1, size_p6, size_p5, size_p4, size_h7, host_t3, host_t2_6, host_v2_6, 1, opt_register_transpose); // Correctness-Check post_Correctness(host_t3, host_t3_chk, host_t2_1, host_v2_1, host_t2_2, host_v2_2, host_t2_3, host_v2_3, host_t2_4, host_v2_4, host_t2_5, host_v2_5, host_t2_6, host_v2_6, host_t2_7, host_v2_7, host_t2_8, host_v2_8, host_t2_9, host_v2_9, 1, 1, 1, 1, 1, 1, 1, 1, 1, size_h3, size_h2, size_h1, size_p6, size_p5, size_p4, size_h7); // Free free(host_t3); free(host_t3_chk); free(host_t2_1); free(host_t2_2); free(host_t2_3); free(host_t2_4); free(host_t2_5); free(host_t2_6); free(host_t2_7); free(host_t2_8); free(host_t2_9); free(host_v2_1); free(host_v2_2); free(host_v2_3); free(host_v2_4); free(host_v2_5); free(host_v2_6); free(host_v2_7); free(host_v2_8); free(host_v2_9); return 0; } // Initialize t3 (t3_temp), 9 t2 and 9 v2. void pre_Initializing_Input_Tensors(double* h_t3, double* h_t3_chk, double* h_t2_1, double* h_v2_1, double* h_t2_2, double* h_v2_2, double* h_t2_3, double* h_v2_3, double* h_t2_4, double* h_v2_4, double* h_t2_5, double* h_v2_5, double* h_t2_6, double* h_v2_6, double* h_t2_7, double* h_v2_7, double* h_t2_8, double* h_v2_8, double* h_t2_9, double* h_v2_9, int size_idx_h3, int size_idx_h2, int size_idx_h1, int size_idx_p6, int size_idx_p5, int size_idx_p4, int size_idx_h7) { int size_T3; int size_T2_1, size_T2_2, size_T2_3, size_T2_4, size_T2_5, size_T2_6, size_T2_7, size_T2_8, size_T2_9; int size_V2_1, size_V2_2, size_V2_3, size_V2_4, size_V2_5, size_V2_6, size_V2_7, size_V2_8, size_V2_9; int size_internal; // size_internal = size_idx_h7; size_T3 = size_idx_h3 * size_idx_h2 * size_idx_h1 * size_idx_p6 * size_idx_p5 * size_idx_p4; /* >> sd1 << 1: t3 [h3,16,h2,16,h1,16,p6,16,p5,16,p4,16] -= sum(h7,16) * t2_1 [h7,p4,p5,h1] * v2_1 [h3,h2,p6,h7]; 2: t3 [h3,16,h2,16,h1,16,p6,16,p5,16,p4,16] += sum(h7,16) * t2_2 [h7,p4,p5,h2] * v2_2 [h3,h1,p6,h7]; 3: t3 [h3,16,h2,16,h1,16,p6,16,p5,16,p4,16] -= sum(h7,16) * t2_3 [h7,p4,p5,h3] * v2_3 [h2,h1,p6,h7]; 4: t3 [h3,16,h2,16,h1,16,p6,16,p5,16,p4,16] -= sum(h7,16) * t2_4 [h7,p5,p6,h1] * v2_4 [h3,h2,p4,h7]; 5: t3 [h3,16,h2,16,h1,16,p6,16,p5,16,p4,16] += sum(h7,16) * t2_5 [h7,p5,p6,h2] * v2_5 [h3,h1,p4,h7]; 6: t3 [h3,16,h2,16,h1,16,p6,16,p5,16,p4,16] -= sum(h7,16) * t2_6 [h7,p5,p6,h3] * v2_6 [h2,h1,p4,h7]; 7: t3 [h3,16,h2,16,h1,16,p6,16,p5,16,p4,16] += sum(h7,16) * t2_7 [h7,p4,p6,h1] * v2_7 [h3,h2,p5,h7]; 8: t3 [h3,16,h2,16,h1,16,p6,16,p5,16,p4,16] -= sum(h7,16) * t2_8 [h7,p4,p6,h2] * v2_8 [h3,h1,p5,h7]; 9: t3 [h3,16,h2,16,h1,16,p6,16,p5,16,p4,16] += sum(h7,16) * t2_8 [h7,p4,p6,h3] * v2_9 [h2,h1,p5,h7]; */ // size_T2_1 = size_idx_h7 * size_idx_p4 * size_idx_p5 * size_idx_h1; size_V2_1 = size_idx_h3 * size_idx_h2 * size_idx_p6 * size_idx_h7; size_T2_2 = size_idx_h7 * size_idx_p4 * size_idx_p5 * size_idx_h2; size_V2_2 = size_idx_h3 * size_idx_h1 * size_idx_p6 * size_idx_h7; size_T2_3 = size_idx_h7 * size_idx_p4 * size_idx_p5 * size_idx_h3; size_V2_3 = size_idx_h2 * size_idx_h1 * size_idx_p6 * size_idx_h7; size_T2_4 = size_idx_h7 * size_idx_p5 * size_idx_p6 * size_idx_h1; size_V2_4 = size_idx_h3 * size_idx_h2 * size_idx_p4 * size_idx_h7; size_T2_5 = size_idx_h7 * size_idx_p5 * size_idx_p6 * size_idx_h2; size_V2_5 = size_idx_h3 * size_idx_h1 * size_idx_p4 * size_idx_h7; size_T2_6 = size_idx_h7 * size_idx_p5 * size_idx_p6 * size_idx_h3; size_V2_6 = size_idx_h2 * size_idx_h1 * size_idx_p4 * size_idx_h7; size_T2_7 = size_idx_h7 * size_idx_p4 * size_idx_p6 * size_idx_h1; size_V2_7 = size_idx_h3 * size_idx_h2 * size_idx_p5 * size_idx_h7; size_T2_8 = size_idx_h7 * size_idx_p4 * size_idx_p6 * size_idx_h2; size_V2_8 = size_idx_h3 * size_idx_h1 * size_idx_p5 * size_idx_h7; size_T2_9 = size_idx_h7 * size_idx_p4 * size_idx_p6 * size_idx_h3; size_V2_9 = size_idx_h2 * size_idx_h1 * size_idx_p5 * size_idx_h7; // t3 int i, j; for (i = 0; i < size_T3; i++) { h_t3[i] = 0.0; h_t3_chk[i] = 0.0; } for (j = 0; j < size_T2_1; j++) { h_t2_1[j] = ((double)rand() / RAND_MAX); } for (j = 0; j < size_V2_1; j++) { h_v2_1[j] = ((double)rand() / RAND_MAX); } for (j = 0; j < size_T2_2; j++) { h_t2_2[j] = ((double)rand() / RAND_MAX); } for (j = 0; j < size_V2_2; j++) { h_v2_2[j] = ((double)rand() / RAND_MAX); } for (j = 0; j < size_T2_3; j++) { h_t2_3[j] = ((double)rand() / RAND_MAX); } for (j = 0; j < size_V2_3; j++) { h_v2_3[j] = ((double)rand() / RAND_MAX); } for (j = 0; j < size_T2_4; j++) { h_t2_4[j] = ((double)rand() / RAND_MAX); } for (j = 0; j < size_V2_4; j++) { h_v2_4[j] = ((double)rand() / RAND_MAX); } for (j = 0; j < size_T2_5; j++) { h_t2_5[j] = ((double)rand() / RAND_MAX); } for (j = 0; j < size_V2_5; j++) { h_v2_5[j] = ((double)rand() / RAND_MAX); } for (j = 0; j < size_T2_6; j++) { h_t2_6[j] = ((double)rand() / RAND_MAX); } for (j = 0; j < size_V2_6; j++) { h_v2_6[j] = ((double)rand() / RAND_MAX); } for (j = 0; j < size_T2_7; j++) { h_t2_7[j] = ((double)rand() / RAND_MAX); } for (j = 0; j < size_V2_7; j++) { h_v2_7[j] = ((double)rand() / RAND_MAX); } for (j = 0; j < size_T2_8; j++) { h_t2_8[j] = ((double)rand() / RAND_MAX); } for (j = 0; j < size_V2_8; j++) { h_v2_8[j] = ((double)rand() / RAND_MAX); } for (j = 0; j < size_T2_9; j++) { h_t2_9[j] = ((double)rand() / RAND_MAX); } for (j = 0; j < size_V2_9; j++) { h_v2_9[j] = ((double)rand() / RAND_MAX); } printf ("==========================================================================================================\n"); printf (" >>> %s <<<\n", __func__); printf (" T3: %'12d\n", size_T3); printf (" T2_1: %'12d, V2_1: %'12d\n", size_T2_1, size_V2_1); printf (" T2_2: %'12d, V2_2: %'12d\n", size_T2_2, size_V2_2); printf (" T2_3: %'12d, V2_3: %'12d\n", size_T2_3, size_V2_3); printf (" T2_4: %'12d, V2_4: %'12d\n", size_T2_4, size_V2_4); printf (" T2_5: %'12d, V2_5: %'12d\n", size_T2_5, size_V2_5); printf (" T2_6: %'12d, V2_6: %'12d\n", size_T2_6, size_V2_6); printf (" T2_7: %'12d, V2_7: %'12d\n", size_T2_7, size_V2_7); printf (" T2_8: %'12d, V2_8: %'12d\n", size_T2_8, size_V2_8); printf (" T2_9: %'12d, V2_9: %'12d\n", size_T2_9, size_V2_9); printf ("==========================================================================================================\n"); } // void post_Correctness(double* h_t3, double* h_t3_chk, double* h_t2_1, double* h_v2_1, double* h_t2_2, double* h_v2_2, double* h_t2_3, double* h_v2_3, double* h_t2_4, double* h_v2_4, double* h_t2_5, double* h_v2_5, double* h_t2_6, double* h_v2_6, double* h_t2_7, double* h_v2_7, double* h_t2_8, double* h_v2_8, double* h_t2_9, double* h_v2_9, int kernel_1, int kernel_2, int kernel_3, int kernel_4, int kernel_5, int kernel_6, int kernel_7, int kernel_8, int kernel_9, int size_idx_h3, int size_idx_h2, int size_idx_h1, int size_idx_p6, int size_idx_p5, int size_idx_p4, int size_idx_h7) { int SIZE_IDX_H3; int SIZE_IDX_H2; int SIZE_IDX_H1; int SIZE_IDX_P6; int SIZE_IDX_P5; int SIZE_IDX_P4; int SIZE_IDX_H7; int STR_SD2_T3_H3; int STR_SD2_T3_H2;// STR_SD2_T3_H3 * SIZE_IDX_H3 int STR_SD2_T3_H1;// STR_SD2_T3_H2 * SIZE_IDX_H2 int STR_SD2_T3_P6;// STR_SD2_T3_H1 * SIZE_IDX_H1 int STR_SD2_T3_P5;// STR_SD2_T3_P6 * SIZE_IDX_P6 int STR_SD2_T3_P4;// STR_SD2_T3_P5 * SIZE_IDX_P5 // t2 for inputs int STR_SD2_T2_4_H7;// 1 int STR_SD2_T2_4_P5;// STR_SD2_T2_4_H7 * SIZE_IDX_H7 int STR_SD2_T2_4_P6;// STR_SD2_T2_4_P5 * SIZE_IDX_P5 int STR_SD2_T2_4_H1;// STR_SD2_T2_4_P6 * SIZE_IDX_P6 // v2 for inputs int STR_SD2_V2_4_H3;// 1 int STR_SD2_V2_4_H2;// STR_SD2_V2_4_H3 * SIZE_IDX_H3 int STR_SD2_V2_4_P4;// STR_SD2_V2_4_H2 * SIZE_IDX_H2 int STR_SD2_V2_4_H7;// STR_SD2_V2_4_P4 * SIZE_IDX_P4 // t2 for inputs int STR_SD2_T2_5_H7;// 1 int STR_SD2_T2_5_P5;// STR_SD2_T2_5_H7 * SIZE_IDX_H7 int STR_SD2_T2_5_P6;// STR_SD2_T2_5_P5 * SIZE_IDX_P5 int STR_SD2_T2_5_H2;// STR_SD2_T2_5_P6 * SIZE_IDX_P6 // v2 for inputs int STR_SD2_V2_5_H3;// 1 int STR_SD2_V2_5_H1;// STR_SD2_V2_5_H3 * SIZE_IDX_H3 int STR_SD2_V2_5_P4;// STR_SD2_V2_5_H1 * SIZE_IDX_H1 int STR_SD2_V2_5_H7;// STR_SD2_V2_5_P4 * SIZE_IDX_P4 // t2 for inputs int STR_SD2_T2_6_H7;// 1 int STR_SD2_T2_6_P5;// STR_SD2_T2_6_H7 * SIZE_IDX_H7 int STR_SD2_T2_6_P6;// STR_SD2_T2_6_P5 * SIZE_IDX_P5 int STR_SD2_T2_6_H3;// STR_SD2_T2_6_P6 * SIZE_IDX_P6 // v2 for inputs int STR_SD2_V2_6_H2;// 1 int STR_SD2_V2_6_H1;// STR_SD2_V2_6_H2 * SIZE_IDX_H2 int STR_SD2_V2_6_P4;// STR_SD2_V2_6_H1 * SIZE_IDX_H1 int STR_SD2_V2_6_H7;// STR_SD2_V2_6_P4 * SIZE_IDX_P4 // t2 for inputs int STR_SD2_T2_7_H7;// 1 int STR_SD2_T2_7_P4;// STR_SD2_T2_7_H7 * SIZE_IDX_H7 int STR_SD2_T2_7_P6;// STR_SD2_T2_7_P4 * SIZE_IDX_P4 int STR_SD2_T2_7_H1;// STR_SD2_T2_7_P6 * SIZE_IDX_P6 // v2 for inputs int STR_SD2_V2_7_H3;// 1 int STR_SD2_V2_7_H2;// STR_SD2_V2_7_H3 * SIZE_IDX_H3 int STR_SD2_V2_7_P5;// STR_SD2_V2_7_H2 * SIZE_IDX_H2 int STR_SD2_V2_7_H7;// STR_SD2_V2_7_P5 * SIZE_IDX_P5 // t2 for inputs int STR_SD2_T2_8_H7;// 1 int STR_SD2_T2_8_P4;// STR_SD2_T2_8_H7 * SIZE_IDX_H7 int STR_SD2_T2_8_P6;// STR_SD2_T2_8_P4 * SIZE_IDX_P4 int STR_SD2_T2_8_H2;// STR_SD2_T2_8_P6 * SIZE_IDX_P6 // v2 for inputs int STR_SD2_V2_8_H3;// 1 int STR_SD2_V2_8_H1;// STR_SD2_V2_8_H3 * SIZE_IDX_H3 int STR_SD2_V2_8_P5;// STR_SD2_V2_8_H1 * SIZE_IDX_H1 int STR_SD2_V2_8_H7;// STR_SD2_V2_8_P5 * SIZE_IDX_P5 // t2 for inputs int STR_SD2_T2_9_H7;// 1 int STR_SD2_T2_9_P4;// STR_SD2_T2_9_H7 * SIZE_IDX_H7 int STR_SD2_T2_9_P6;// STR_SD2_T2_9_P4 * SIZE_IDX_P4 int STR_SD2_T2_9_H3;// STR_SD2_T2_9_P6 * SIZE_IDX_P6 // v2 for inputs int STR_SD2_V2_9_H2;// 1 int STR_SD2_V2_9_H1;// STR_SD2_V2_9_H2 * SIZE_IDX_H2 int STR_SD2_V2_9_P5;// STR_SD2_V2_9_H1 * SIZE_IDX_H1 int STR_SD2_V2_9_H7;// STR_SD2_V2_9_P5 * SIZE_IDX_P5 // t2 for inputs int STR_SD2_T2_1_H7;// 1 int STR_SD2_T2_1_P4;// STR_SD2_T2_1_H7 * SIZE_IDX_H7 int STR_SD2_T2_1_P5;// STR_SD2_T2_1_P4 * SIZE_IDX_P4 int STR_SD2_T2_1_H1;// STR_SD2_T2_1_P5 * SIZE_IDX_P5 // v2 for inputs int STR_SD2_V2_1_H3;// 1 int STR_SD2_V2_1_H2;// STR_SD2_V2_1_H3 * SIZE_IDX_H3 int STR_SD2_V2_1_P6;// STR_SD2_V2_1_H2 * SIZE_IDX_H2 int STR_SD2_V2_1_H7;// STR_SD2_V2_1_P6 * SIZE_IDX_P6 // t2 for inputs int STR_SD2_T2_2_H7;// 1 int STR_SD2_T2_2_P4;// STR_SD2_T2_2_H7 * SIZE_IDX_H7 int STR_SD2_T2_2_P5;// STR_SD2_T2_2_P4 * SIZE_IDX_P4 int STR_SD2_T2_2_H2;// STR_SD2_T2_2_P5 * SIZE_IDX_P5 // v2 for inputs int STR_SD2_V2_2_H3;// 1 int STR_SD2_V2_2_H1;// STR_SD2_V2_2_H3 * SIZE_IDX_H3 int STR_SD2_V2_2_P6;// STR_SD2_V2_2_H1 * SIZE_IDX_H1 int STR_SD2_V2_2_H7;// STR_SD2_V2_2_P6 * SIZE_IDX_P6 // t2 for inputs int STR_SD2_T2_3_H7;// 1 int STR_SD2_T2_3_P4;// STR_SD2_T2_3_H7 * SIZE_IDX_H7 int STR_SD2_T2_3_P5;// STR_SD2_T2_3_P4 * SIZE_IDX_P4 int STR_SD2_T2_3_H3;// STR_SD2_T2_3_P5 * SIZE_IDX_P5 // v2 for inputs int STR_SD2_V2_3_H2;// 1 int STR_SD2_V2_3_H1;// STR_SD2_V2_3_H2 * SIZE_IDX_H2 int STR_SD2_V2_3_P6;// STR_SD2_V2_3_H1 * SIZE_IDX_H1 int STR_SD2_V2_3_H7;// STR_SD2_V2_3_P6 * SIZE_IDX_P6 // Indices SIZE_IDX_H3 = size_idx_h3; SIZE_IDX_H2 = size_idx_h2; SIZE_IDX_H1 = size_idx_h1; SIZE_IDX_P6 = size_idx_p6; SIZE_IDX_P5 = size_idx_p5; SIZE_IDX_P4 = size_idx_p4; SIZE_IDX_H7 = size_idx_h7; // t3 STR_SD2_T3_H3 = 1; STR_SD2_T3_H2 = STR_SD2_T3_H3 * SIZE_IDX_H3; STR_SD2_T3_H1 = STR_SD2_T3_H2 * SIZE_IDX_H2; STR_SD2_T3_P6 = STR_SD2_T3_H1 * SIZE_IDX_H1; STR_SD2_T3_P5 = STR_SD2_T3_P6 * SIZE_IDX_P6; STR_SD2_T3_P4 = STR_SD2_T3_P5 * SIZE_IDX_P5; /* >> sd1 << 1: t3 [h3,16,h2,16,h1,16,p6,16,p5,16,p4,16] -= sum(h7,16) * t2_1 [h7,p4,p5,h1] * v2_1 [h3,h2,p6,h7]; 2: t3 [h3,16,h2,16,h1,16,p6,16,p5,16,p4,16] += sum(h7,16) * t2_2 [h7,p4,p5,h2] * v2_2 [h3,h1,p6,h7]; 3: t3 [h3,16,h2,16,h1,16,p6,16,p5,16,p4,16] -= sum(h7,16) * t2_3 [h7,p4,p5,h3] * v2_3 [h2,h1,p6,h7]; 4: t3 [h3,16,h2,16,h1,16,p6,16,p5,16,p4,16] -= sum(h7,16) * t2_4 [h7,p5,p6,h1] * v2_4 [h3,h2,p4,h7]; 5: t3 [h3,16,h2,16,h1,16,p6,16,p5,16,p4,16] += sum(h7,16) * t2_5 [h7,p5,p6,h2] * v2_5 [h3,h1,p4,h7]; 6: t3 [h3,16,h2,16,h1,16,p6,16,p5,16,p4,16] -= sum(h7,16) * t2_6 [h7,p5,p6,h3] * v2_6 [h2,h1,p4,h7]; 7: t3 [h3,16,h2,16,h1,16,p6,16,p5,16,p4,16] += sum(h7,16) * t2_7 [h7,p4,p6,h1] * v2_7 [h3,h2,p5,h7]; 8: t3 [h3,16,h2,16,h1,16,p6,16,p5,16,p4,16] -= sum(h7,16) * t2_8 [h7,p4,p6,h2] * v2_8 [h3,h1,p5,h7]; 9: t3 [h3,16,h2,16,h1,16,p6,16,p5,16,p4,16] += sum(h7,16) * t2_8 [h7,p4,p6,h3] * v2_9 [h2,h1,p5,h7]; */ // t2 for inputs STR_SD2_T2_4_H7 = 1; STR_SD2_T2_4_P5 = STR_SD2_T2_4_H7 * SIZE_IDX_H7; STR_SD2_T2_4_P6 = STR_SD2_T2_4_P5 * SIZE_IDX_P5; STR_SD2_T2_4_H1 = STR_SD2_T2_4_P6 * SIZE_IDX_P6; // v2 for inputs STR_SD2_V2_4_H3 = 1; STR_SD2_V2_4_H2 = STR_SD2_V2_4_H3 * SIZE_IDX_H3; STR_SD2_V2_4_P4 = STR_SD2_V2_4_H2 * SIZE_IDX_H2; STR_SD2_V2_4_H7 = STR_SD2_V2_4_P4 * SIZE_IDX_P4; // t2 for inputs STR_SD2_T2_5_H7 = 1; STR_SD2_T2_5_P5 = STR_SD2_T2_5_H7 * SIZE_IDX_H7; STR_SD2_T2_5_P6 = STR_SD2_T2_5_P5 * SIZE_IDX_P5; STR_SD2_T2_5_H2 = STR_SD2_T2_5_P6 * SIZE_IDX_P6; // v2 for inputs STR_SD2_V2_5_H3 = 1; STR_SD2_V2_5_H1 = STR_SD2_V2_5_H3 * SIZE_IDX_H3; STR_SD2_V2_5_P4 = STR_SD2_V2_5_H1 * SIZE_IDX_H1; STR_SD2_V2_5_H7 = STR_SD2_V2_5_P4 * SIZE_IDX_P4; // t2 for inputs STR_SD2_T2_6_H7 = 1; STR_SD2_T2_6_P5 = STR_SD2_T2_6_H7 * SIZE_IDX_H7; STR_SD2_T2_6_P6 = STR_SD2_T2_6_P5 * SIZE_IDX_P5; STR_SD2_T2_6_H3 = STR_SD2_T2_6_P6 * SIZE_IDX_P6; // v2 for inputs STR_SD2_V2_6_H2 = 1; STR_SD2_V2_6_H1 = STR_SD2_V2_6_H2 * SIZE_IDX_H2; STR_SD2_V2_6_P4 = STR_SD2_V2_6_H1 * SIZE_IDX_H1; STR_SD2_V2_6_H7 = STR_SD2_V2_6_P4 * SIZE_IDX_P4; // t2 for inputs STR_SD2_T2_7_H7 = 1; STR_SD2_T2_7_P4 = STR_SD2_T2_7_H7 * SIZE_IDX_H7; STR_SD2_T2_7_P6 = STR_SD2_T2_7_P4 * SIZE_IDX_P4; STR_SD2_T2_7_H1 = STR_SD2_T2_7_P6 * SIZE_IDX_P6; // v2 for inputs STR_SD2_V2_7_H3 = 1; STR_SD2_V2_7_H2 = STR_SD2_V2_7_H3 * SIZE_IDX_H3; STR_SD2_V2_7_P5 = STR_SD2_V2_7_H2 * SIZE_IDX_H2; STR_SD2_V2_7_H7 = STR_SD2_V2_7_P5 * SIZE_IDX_P5; // t2 for inputs STR_SD2_T2_8_H7 = 1; STR_SD2_T2_8_P4 = STR_SD2_T2_8_H7 * SIZE_IDX_H7; STR_SD2_T2_8_P6 = STR_SD2_T2_8_P4 * SIZE_IDX_P4; STR_SD2_T2_8_H2 = STR_SD2_T2_8_P6 * SIZE_IDX_P6; // v2 for inputs STR_SD2_V2_8_H3 = 1; STR_SD2_V2_8_H1 = STR_SD2_V2_8_H3 * SIZE_IDX_H3; STR_SD2_V2_8_P5 = STR_SD2_V2_8_H1 * SIZE_IDX_H1; STR_SD2_V2_8_H7 = STR_SD2_V2_8_P5 * SIZE_IDX_P5; // t2 for inputs STR_SD2_T2_9_H7 = 1; STR_SD2_T2_9_P4 = STR_SD2_T2_9_H7 * SIZE_IDX_H7; STR_SD2_T2_9_P6 = STR_SD2_T2_9_P4 * SIZE_IDX_P4; STR_SD2_T2_9_H3 = STR_SD2_T2_9_P6 * SIZE_IDX_P6; // v2 for inputs STR_SD2_V2_9_H2 = 1; STR_SD2_V2_9_H1 = STR_SD2_V2_9_H2 * SIZE_IDX_H2; STR_SD2_V2_9_P5 = STR_SD2_V2_9_H1 * SIZE_IDX_H1; STR_SD2_V2_9_H7 = STR_SD2_V2_9_P5 * SIZE_IDX_P5; // t2 for inputs STR_SD2_T2_1_H7 = 1; STR_SD2_T2_1_P4 = STR_SD2_T2_1_H7 * SIZE_IDX_H7; STR_SD2_T2_1_P5 = STR_SD2_T2_1_P4 * SIZE_IDX_P4; STR_SD2_T2_1_H1 = STR_SD2_T2_1_P5 * SIZE_IDX_P5;; // v2 for inputs STR_SD2_V2_1_H3 = 1; STR_SD2_V2_1_H2 = STR_SD2_V2_1_H3 * SIZE_IDX_H3; STR_SD2_V2_1_P6 = STR_SD2_V2_1_H2 * SIZE_IDX_H2; STR_SD2_V2_1_H7 = STR_SD2_V2_1_P6 * SIZE_IDX_P6; // t2 for inputs STR_SD2_T2_2_H7 = 1; STR_SD2_T2_2_P4 = STR_SD2_T2_2_H7 * SIZE_IDX_H7; STR_SD2_T2_2_P5 = STR_SD2_T2_2_P4 * SIZE_IDX_P4; STR_SD2_T2_2_H2 = STR_SD2_T2_2_P5 * SIZE_IDX_P5; // v2 for inputs STR_SD2_V2_2_H3 = 1; STR_SD2_V2_2_H1 = STR_SD2_V2_2_H3 * SIZE_IDX_H3; STR_SD2_V2_2_P6 = STR_SD2_V2_2_H1 * SIZE_IDX_H1; STR_SD2_V2_2_H7 = STR_SD2_V2_2_P6 * SIZE_IDX_P6; // t2 for inputs STR_SD2_T2_3_H7 = 1; STR_SD2_T2_3_P4 = STR_SD2_T2_3_H7 * SIZE_IDX_H7; STR_SD2_T2_3_P5 = STR_SD2_T2_3_P4 * SIZE_IDX_P4; STR_SD2_T2_3_H3 = STR_SD2_T2_3_P5 * SIZE_IDX_P5; // v2 for inputs STR_SD2_V2_3_H2 = 1; STR_SD2_V2_3_H1 = STR_SD2_V2_3_H2 * SIZE_IDX_H2; STR_SD2_V2_3_P6 = STR_SD2_V2_3_H1 * SIZE_IDX_H1; STR_SD2_V2_3_H7 = STR_SD2_V2_3_P6 * SIZE_IDX_P6; long long int tmp_ops = 0; int ops = 0; int t3_h3, t3_h2, t3_h1, t3_p6, t3_p5, t3_p4, t3_h7; for (t3_h3 = 0; t3_h3 < SIZE_IDX_H3; t3_h3++) for (t3_h2 = 0; t3_h2 < SIZE_IDX_H2; t3_h2++) for (t3_h1 = 0; t3_h1 < SIZE_IDX_H1; t3_h1++) for (t3_p6 = 0; t3_p6 < SIZE_IDX_P6; t3_p6++) for (t3_p5 = 0; t3_p5 < SIZE_IDX_P5; t3_p5++) for (t3_p4 = 0; t3_p4 < SIZE_IDX_P4; t3_p4++) { int tmp_r_idx = t3_h3 * STR_SD2_T3_H3 + t3_h2 * STR_SD2_T3_H2 + t3_h1 * STR_SD2_T3_H1 + t3_p6 * STR_SD2_T3_P6 + t3_p5 * STR_SD2_T3_P5 + t3_p4 * STR_SD2_T3_P4; for (t3_h7 = 0; t3_h7 < SIZE_IDX_H7; t3_h7++, ops = 0) { /* if (kernel_4 == 1) { h_t3_chk[tmp_r_idx] -= h_t2_4[t3_h7 * STR_SD2_T2_4_H7 + t3_p5 * STR_SD2_T2_4_P5 + t3_p6 * STR_SD2_T2_4_P6 + t3_h1 * STR_SD2_T2_4_H1] * h_v2_4[t3_h3 * STR_SD2_V2_4_H3 + t3_h2 * STR_SD2_V2_4_H2 + t3_p4 * STR_SD2_V2_4_P4 + t3_h7 * STR_SD2_V2_4_H7]; ops++; } */ /* if (kernel_5 == 1) { h_t3_chk[tmp_r_idx] += h_t2_5[t3_h7 * STR_SD2_T2_5_H7 + t3_p5 * STR_SD2_T2_5_P5 + t3_p6 * STR_SD2_T2_5_P6 + t3_h2 * STR_SD2_T2_5_H2] * h_v2_5[t3_h3 * STR_SD2_V2_5_H3 + t3_h1 * STR_SD2_V2_5_H1 + t3_p4 * STR_SD2_V2_5_P4 + t3_h7 * STR_SD2_V2_5_H7]; ops++; }*/ h_t3_chk[tmp_r_idx] += h_t2_6[t3_h7 * STR_SD2_T2_6_H7 + t3_p5 * STR_SD2_T2_6_P5 + t3_p6 * STR_SD2_T2_6_P6 + t3_h3 * STR_SD2_T2_6_H3] * h_v2_6[t3_h2 * STR_SD2_V2_6_H2 + t3_h1 * STR_SD2_V2_6_H1 + t3_p4 * STR_SD2_V2_6_P4 + t3_h7 * STR_SD2_V2_6_H7]; ops++; /* if (kernel_7 == 1) { h_t3_chk[tmp_r_idx] += h_t2_7[t3_h7 * STR_SD2_T2_7_H7 + t3_p4 * STR_SD2_T2_7_P4 + t3_p6 * STR_SD2_T2_7_P6 + t3_h1 * STR_SD2_T2_7_H1] * h_v2_7[t3_h3 * STR_SD2_V2_7_H3 + t3_h2 * STR_SD2_V2_7_H2 + t3_p5 * STR_SD2_V2_7_P5 + t3_h7 * STR_SD2_V2_7_H7]; ops++; } if (kernel_8 == 1) { h_t3_chk[tmp_r_idx] -= h_t2_8[t3_h7 * STR_SD2_T2_8_H7 + t3_p4 * STR_SD2_T2_8_P4 + t3_p6 * STR_SD2_T2_8_P6 + t3_h2 * STR_SD2_T2_8_H2] * h_v2_8[t3_h3 * STR_SD2_V2_8_H3 + t3_h1 * STR_SD2_V2_8_H1 + t3_p5 * STR_SD2_V2_8_P5 + t3_h7 * STR_SD2_V2_8_H7]; ops++; } if (kernel_9 == 1) { h_t3_chk[tmp_r_idx] += h_t2_9[t3_h7 * STR_SD2_T2_9_H7 + t3_p4 * STR_SD2_T2_9_P4 + t3_p6 * STR_SD2_T2_9_P6 + t3_h3 * STR_SD2_T2_9_H3] * h_v2_9[t3_h2 * STR_SD2_V2_9_H2 + t3_h1 * STR_SD2_V2_9_H1 + t3_p5 * STR_SD2_V2_9_P5 + t3_h7 * STR_SD2_V2_9_H7]; ops++; } if (kernel_1 == 1) { h_t3_chk[tmp_r_idx] -= h_t2_1[t3_h7 * STR_SD2_T2_1_H7 + t3_p4 * STR_SD2_T2_1_P4 + t3_p5 * STR_SD2_T2_1_P5 + t3_h1 * STR_SD2_T2_1_H1] * h_v2_1[t3_h3 * STR_SD2_V2_1_H3 + t3_h2 * STR_SD2_V2_1_H2 + t3_p6 * STR_SD2_V2_1_P6 + t3_h7 * STR_SD2_V2_1_H7]; ops++; } */ /* h_t3_chk[tmp_r_idx] += h_t2_2[t3_h7 * STR_SD2_T2_2_H7 + t3_p4 * STR_SD2_T2_2_P4 + t3_p5 * STR_SD2_T2_2_P5 + t3_h2 * STR_SD2_T2_2_H2] * h_v2_2[t3_h3 * STR_SD2_V2_2_H3 + t3_h1 * STR_SD2_V2_2_H1 + t3_p6 * STR_SD2_V2_2_P6 + t3_h7 * STR_SD2_V2_2_H7]; ops++; */ /* if (tmp_r_idx == 0) { printf ("[%d][%2d] t2_2: %f (%d), v2_2: %f (%d)\n", tmp_r_idx, t3_h7, h_t2_2[t3_h7 * STR_SD2_T2_2_H7 + t3_p4 * STR_SD2_T2_2_P4 + t3_p5 * STR_SD2_T2_2_P5 + t3_h2 * STR_SD2_T2_2_H2], t3_h7 * STR_SD2_T2_2_H7 + t3_p4 * STR_SD2_T2_2_P4 + t3_p5 * STR_SD2_T2_2_P5 + t3_h2 * STR_SD2_T2_2_H2, h_v2_2[t3_h3 * STR_SD2_V2_2_H3 + t3_h1 * STR_SD2_V2_2_H1 + t3_p6 * STR_SD2_V2_2_P6 + t3_h7 * STR_SD2_V2_2_H7], t3_h3 * STR_SD2_V2_2_H3 + t3_h1 * STR_SD2_V2_2_H1 + t3_p6 * STR_SD2_V2_2_P6 + t3_h7 * STR_SD2_V2_2_H7); } */ /* if (kernel_3 == 1) { h_t3_chk[tmp_r_idx] -= h_t2_3[t3_h7 * STR_SD2_T2_3_H7 + t3_p4 * STR_SD2_T2_3_P4 + t3_p5 * STR_SD2_T2_3_P5 + t3_h3 * STR_SD2_T2_3_H3] * h_v2_3[t3_h2 * STR_SD2_V2_3_H2 + t3_h1 * STR_SD2_V2_3_H1 + t3_p6 * STR_SD2_V2_3_P6 + t3_h7 * STR_SD2_V2_3_H7]; ops++; } */ tmp_ops = tmp_ops + ops; } } printf ("======================================= Correctness Check ==========================================\n"); double epsilon = 0.00000001; int diff = 0; int same = 0; int i; for (i = 0; i < size_idx_h3 * size_idx_h2 * size_idx_h1 * size_idx_p6 * size_idx_p5 * size_idx_p4; i++) { double check = h_t3_chk[i] - h_t3[i]; if (check < 0) check *= -1; if (check > epsilon) { diff++; if (diff < 8) printf ("Index: %5d, (Host) %8.4f, (Dev.) %8.4f >> (Diff.) %8.4f\n", i, h_t3_chk[i], h_t3[i], check); } else { same++; } } printf (" >>> PASSED: %'10d among %'10d in t3\n", same, size_idx_h3 * size_idx_h2 * size_idx_h1 * size_idx_p6 * size_idx_p5 * size_idx_p4); printf (" >>> ERROR : %'10d among %'10d in t3\n", diff, size_idx_h3 * size_idx_h2 * size_idx_h1 * size_idx_p6 * size_idx_p5 * size_idx_p4); printf (" >>> Total Operations: %'lld\n", tmp_ops * 2); printf ("====================================================================================================\n"); }
the_stack_data/76699230.c
#include <stdlib.h> #define o_new(res) res = (struct state_t *)malloc(sizeof(struct state_t)) #define o_clone(src) { \ struct state_t* tmp; \ o_new(tmp); \ tmp->x = (src)->x; \ dst = tmp; \ } #define o_read(st,rv) rv = st.x #define o_write(st,rv,v) { st.x = v; rv = 0; }
the_stack_data/95449786.c
/**************************************************************************** **************************************************************************** * * * Copyright (C) 2018 Genome Research Ltd. * * * * Author: Zemin Ning ([email protected]) * * * * This file is part of ScaffHiC pipeline. * * * * ScaffHiC is a free software: you can redistribute it and/or modify it * * under the terms of the GNU General Public License as published by the * * Free Software Foundation, either version 3 of the License, or (at your * * option) any later version. * * * * This program is distributed in the hope that it will be useful, but * * WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * * General Public License for more details. * * * * You should have received a copy of the GNU General Public License along * * with this program. If not, see <http://www.gnu.org/licenses/>. * * * **************************************************************************** ****************************************************************************/ /****************************************************************************/ #include <math.h> #include <values.h> #include <stdio.h> #include <netinet/in.h> #include <stdlib.h> #include <dirent.h> #include <string.h> #include <ctype.h> #define GT '>' #define GT4 (((((GT<<8)+GT)<<8)+GT)<<8)+GT #define ENDS_EXTRA 0 #define PADCHAR '-' #define MAX_N_BRG 50000 #define MAX_N_ROW 50000 #define Max_N_NameBase 60 #define Max_N_Pair 100 static char **S_Name,**R_Name,**R_Name2,**T_Name,**cellname; static int *hit_locus,*hit_masks,*hit_mscore,*hit_length,*readIndex; /* SSAS default parameters */ static int IMOD=0; static int n_type=0; static int barreads=10; static int file_flag=2; static int tiles_flag=0; static int block_set=2500; static int edge_flag=0; static int mpscore=20; static int nContig=0; static int max_len = 100000; int main(int argc, char **argv) { FILE *namef; int i,j,nSeq,args,idi,idj; int n_contig,n_reads,n_readsMaxctg,nseq; void decodeReadpair(int nSeq); void HashFasta_Head(int i, int nSeq); void HashFasta_Table(int i, int nSeq); void Assemble_SM(int arr,int brr); void Mapping_Process(char **argv,int args,int nSeq); void Memory_Allocate(int arr); char line[2000]={0},tempc1[60],lociname[60],tempc[60],readname[60],tmpname[60],*st,*ed; char **cmatrix(long nrl,long nrh,long ncl,long nch); if(argc < 2) { printf("Usage: %s [-block 2500] [-reads 10] [-score 20] <input_barcode_file> <barcode_sorted_file>\n",argv[0]); exit(1); } nSeq=0; args=1; for(i=1;i<argc;i++) { if(!strcmp(argv[i],"-mod")) { sscanf(argv[++i],"%d",&IMOD); args=args+2; } else if(!strcmp(argv[i],"-type")) { sscanf(argv[++i],"%d",&n_type); args=args+2; } else if(!strcmp(argv[i],"-block")) { sscanf(argv[++i],"%d",&block_set); edge_flag=1; args=args+2; } else if(!strcmp(argv[i],"-tile")) { sscanf(argv[++i],"%d",&tiles_flag); args=args+2; } else if(!strcmp(argv[i],"-reads")) { sscanf(argv[++i],"%d",&barreads); args=args+2; } else if(!strcmp(argv[i],"-score")) { sscanf(argv[++i],"%d",&mpscore); args=args+2; } else if(!strcmp(argv[i],"-max")) { sscanf(argv[++i],"%d",&max_len); args=args+2; } else if(!strcmp(argv[i],"-file")) { sscanf(argv[++i],"%d",&file_flag); args=args+2; } } nseq=0; if((namef = fopen(argv[args],"r")) == NULL) { printf("ERROR main:: args \n"); exit(1); } while(!feof(namef)) { if(fgets(line,2000,namef) == NULL) { // printf("fgets command error:\n); } if(feof(namef)) break; nseq++; } fclose(namef); /* nRead=0; if((namef = fopen(argv[args+1],"r")) == NULL) { printf("ERROR main:: args+1 \n"); exit(1); } while(!feof(namef)) { fgets(line,2000,namef); if(feof(namef)) break; nRead++; } fclose(namef); */ if((hit_masks = (int *)calloc(nseq,sizeof(int))) == NULL) { printf("fmate: calloc - hit_locus2\n"); exit(1); } if((readIndex = (int *)calloc(nseq,sizeof(int))) == NULL) { printf("fmate: calloc - hit_locus2\n"); exit(1); } nSeq=nseq; S_Name=cmatrix(0,nseq+10,0,Max_N_NameBase); R_Name=cmatrix(0,nseq+10,0,Max_N_NameBase); n_readsMaxctg=0; n_contig=0; n_reads=0; if((namef = fopen(argv[args],"r")) == NULL) { printf("ERROR main:: reads group file \n"); exit(1); } /* read the alignment files */ i=0; while(fscanf(namef,"%s %s %s %s %s %s",R_Name[i],readname,lociname,tempc1,tempc1,tempc1)!=EOF) // while(fscanf(namef,"%s %s %s %s %s %s",tempc1,readname,lociname,tempc1,tempc1,tempc1)!=EOF) { int idt; st = readname; ed= strrchr(readname,'_'); memset(tmpname,'\0',60); strcpy(tmpname,ed); strcat(lociname,tmpname); strcat(lociname,"-"); idt = atoi(ed+1); j = i/2; if((i%2) == 0) { idi = idt; strcpy(S_Name[j],lociname); } else { idj = idt; strcat(S_Name[j],lociname); readIndex[j] = j; printf("%d %s %s %s %d %d\n",j,S_Name[j],lociname,readname,idi,idj); } i++; } fclose(namef); n_reads=i/2; // Readname_match(seq,argv,args,n_reads,nRead); Mapping_Process(argv,args,n_reads); // Read_Pairs(argv,args,seq,n_reads); return EXIT_SUCCESS; } /* end of the main */ /* subroutine to sort out read pairs */ /* =============================== */ void Mapping_Process(char **argv,int args,int nSeq) /* =============================== */ { int i,j,k,m,n,n_uniqs; int num_hits,stopflag; FILE *namef,*namef2; char line[2000]; void ArraySort_String(int n,char **Pair_Name,int *brr); ArraySort_String(nSeq,S_Name,readIndex); printf("Total reads: %d\n",nSeq); num_hits =0; k = 0; n_uniqs = 0; for(i=0;i<(nSeq-1);i++) { stopflag=0; j=i+1; while((j<nSeq)&&(stopflag==0)) { if(strcmp(S_Name[i],S_Name[j])==0) { j++; } else stopflag=1; } k = readIndex[i]; num_hits = j-i; if(num_hits>=2) { n_uniqs++; for(n=(i+1);n<j;n++) { int idd = 2*readIndex[n]; // printf("Duplicates: %d %d %s %s\n",k,readIndex[n],S_Name[i],R_Name[idd]); hit_masks[idd] = 1; hit_masks[idd+1] = 1; } } else { // printf("www: %s %d %d\n",R_Name[i],hit_read2[i],superlength[i]); n_uniqs++; } i=j-1; } if((namef = fopen(argv[args],"r")) == NULL) { printf("ERROR main:: reads group file \n"); exit(1); } if((namef2 = fopen(argv[args+1],"w")) == NULL) { printf("ERROR main:: reads group file \n"); exit(1); } i=0; while(!feof(namef)) { if(fgets(line,2000,namef) == NULL) { // printf("fgets command error:\n); } if(feof(namef)) break; if(hit_masks[i] == 0) fprintf(namef2,"%s",line); i++; } fclose(namef); fclose(namef2); printf("Masked reads %d %d %d\n",i,nSeq,n_uniqs); } #define SWAP(a,b) temp=(a);(a)=b;(b)=temp; /* Subroutine to sort an array arr[0,...,n-1] into ascending order while making the corresponding reaarangement of the array brr[0,...,n-1] by the use of Quicksort (Sedgwick, R. 1978, Communications o fthe ACM, vol. 21, pp. 847-857) also see Numerical Recipes in C */ /* =============================== */ void ArraySort_Long(int n, long *arr) /* =============================== */ { int i,ir=n-1,j,k,m=0,jstack=0,NSTACK=50,istack[NSTACK]; long a,temp,MIN=7; for(;;) { /* Insertion sort when subarray is small enough */ if(ir-m<MIN) { for(j=m+1;j<=ir;j++) { a=arr[j]; for(i=j-1;i>=m;i--) { if(arr[i]<=a) break; arr[i+1]=arr[i]; } arr[i+1]=a; } if(!jstack) return; ir=istack[jstack--]; m=istack[jstack--]; } else { k=(m+ir)>>1; SWAP(arr[k],arr[m+1]); if(arr[m]>arr[ir]) { SWAP(arr[m],arr[ir]); } if(arr[m+1]>arr[ir]) { SWAP(arr[m+1],arr[ir]); } if(arr[m]>arr[m+1]) { SWAP(arr[m],arr[m+1]); } i=m+1; j=ir; a=arr[m+1]; for(;;) { do i++; while (arr[i]<a); do j--; while (arr[j]>a); if(j<i) break; SWAP(arr[i],arr[j]); } arr[m+1]=arr[j]; arr[j]=a; jstack+=2; /* Push pointers to larger subarray on stack */ /* process smaller subarray immediately */ if(jstack>NSTACK) { printf("Stack error: NSTACK too small\n"); exit(0); } if(ir-i+1>=j-m) { istack[jstack]=ir; istack[jstack-1]=i; ir=j-1; } else { istack[jstack]=j-1; istack[jstack-1]=m; m=i; } } } } /* =============================== */ void ArraySort_Int(int n, int *arr) /* =============================== */ { int i,ir=n-1,j,k,m=0,jstack=0,NSTACK=50,istack[NSTACK]; int a,temp,MIN=7; for(;;) { /* Insertion sort when subarray is small enough */ if(ir-m<MIN) { for(j=m+1;j<=ir;j++) { a=arr[j]; for(i=j-1;i>=m;i--) { if(arr[i]<=a) break; arr[i+1]=arr[i]; } arr[i+1]=a; } if(!jstack) return; ir=istack[jstack--]; m=istack[jstack--]; } else { k=(m+ir)>>1; SWAP(arr[k],arr[m+1]); if(arr[m]>arr[ir]) { SWAP(arr[m],arr[ir]); } if(arr[m+1]>arr[ir]) { SWAP(arr[m+1],arr[ir]); } if(arr[m]>arr[m+1]) { SWAP(arr[m],arr[m+1]); } i=m+1; j=ir; a=arr[m+1]; for(;;) { do i++; while (arr[i]<a); do j--; while (arr[j]>a); if(j<i) break; SWAP(arr[i],arr[j]); } arr[m+1]=arr[j]; arr[j]=a; jstack+=2; /* Push pointers to larger subarray on stack */ /* process smaller subarray immediately */ if(jstack>NSTACK) { printf("Stack error: NSTACK too small\n"); exit(0); } if(ir-i+1>=j-m) { istack[jstack]=ir; istack[jstack-1]=i; ir=j-1; } else { istack[jstack]=j-1; istack[jstack-1]=m; m=i; } } } } /* =============================== */ void ArraySort_Mix(int n, long *arr, int *brr) /* =============================== */ { int i,ir=n-1,j,k,m=0,jstack=0,b,NSTACK=50,istack[NSTACK]; long a,temp,MIN=7; for(;;) { /* Insertion sort when subarray is small enough */ if(ir-m<MIN) { for(j=m+1;j<=ir;j++) { a=arr[j]; b=brr[j]; for(i=j-1;i>=m;i--) { if(arr[i]<=a) break; arr[i+1]=arr[i]; brr[i+1]=brr[i]; } arr[i+1]=a; brr[i+1]=b; } if(!jstack) return; ir=istack[jstack--]; m=istack[jstack--]; } else { k=(m+ir)>>1; SWAP(arr[k],arr[m+1]); SWAP(brr[k],brr[m+1]); if(arr[m]>arr[ir]) { SWAP(arr[m],arr[ir]); SWAP(brr[m],brr[ir]); } if(arr[m+1]>arr[ir]) { SWAP(arr[m+1],arr[ir]); SWAP(brr[m+1],brr[ir]); } if(arr[m]>arr[m+1]) { SWAP(arr[m],arr[m+1]); SWAP(brr[m],brr[m+1]); } i=m+1; j=ir; a=arr[m+1]; b=brr[m+1]; for(;;) { do i++; while (arr[i]<a); do j--; while (arr[j]>a); if(j<i) break; SWAP(arr[i],arr[j]); SWAP(brr[i],brr[j]); } arr[m+1]=arr[j]; arr[j]=a; brr[m+1]=brr[j]; brr[j]=b; jstack+=2; /* Push pointers to larger subarray on stack */ /* process smaller subarray immediately */ if(jstack>NSTACK) { printf("Stack error: NSTACK too small\n"); exit(0); } if(ir-i+1>=j-m) { istack[jstack]=ir; istack[jstack-1]=i; ir=j-1; } else { istack[jstack]=j-1; istack[jstack-1]=m; m=i; } } } } /* =============================== */ void ArraySort_Int2(int n, int *arr, int *brr) /* =============================== */ { int i,ir=n-1,j,k,m=0,jstack=0,b,NSTACK=50,istack[NSTACK]; int a,temp,MIN=7; for(;;) { /* Insertion sort when subarray is small enough */ if(ir-m<MIN) { for(j=m+1;j<=ir;j++) { a=arr[j]; b=brr[j]; for(i=j-1;i>=m;i--) { if(arr[i]<=a) break; arr[i+1]=arr[i]; brr[i+1]=brr[i]; } arr[i+1]=a; brr[i+1]=b; } if(!jstack) return; ir=istack[jstack--]; m=istack[jstack--]; } else { k=(m+ir)>>1; SWAP(arr[k],arr[m+1]); SWAP(brr[k],brr[m+1]); if(arr[m]>arr[ir]) { SWAP(arr[m],arr[ir]); SWAP(brr[m],brr[ir]); } if(arr[m+1]>arr[ir]) { SWAP(arr[m+1],arr[ir]); SWAP(brr[m+1],brr[ir]); } if(arr[m]>arr[m+1]) { SWAP(arr[m],arr[m+1]); SWAP(brr[m],brr[m+1]); } i=m+1; j=ir; a=arr[m+1]; b=brr[m+1]; for(;;) { do i++; while (arr[i]<a); do j--; while (arr[j]>a); if(j<i) break; SWAP(arr[i],arr[j]); SWAP(brr[i],brr[j]); } arr[m+1]=arr[j]; arr[j]=a; brr[m+1]=brr[j]; brr[j]=b; jstack+=2; /* Push pointers to larger subarray on stack */ /* process smaller subarray immediately */ if(jstack>NSTACK) { printf("Stack error: NSTACK too small\n"); exit(0); } if(ir-i+1>=j-m) { istack[jstack]=ir; istack[jstack-1]=i; ir=j-1; } else { istack[jstack]=j-1; istack[jstack-1]=m; m=i; } } } } /* function to sort an array into a decreasing order: a>b>c>.... */ /* =============================== */ void ArraySort2_Int2(int n, int *arr, int *brr) /* =============================== */ { int i,ir=n-1,j,k,m=0,jstack=0,b,NSTACK=50,istack[NSTACK]; int a,temp,MIN=7; for(;;) { /* Insertion sort when subarray is small enough */ if(ir-m<MIN) { for(j=m+1;j<=ir;j++) { a=arr[j]; b=brr[j]; for(i=j-1;i>=m;i--) { if(arr[i]>=a) break; arr[i+1]=arr[i]; brr[i+1]=brr[i]; } arr[i+1]=a; brr[i+1]=b; } if(!jstack) return; ir=istack[jstack--]; m=istack[jstack--]; } else { k=(m+ir)>>1; SWAP(arr[k],arr[m+1]); SWAP(brr[k],brr[m+1]); if(arr[m]<arr[ir]) { SWAP(arr[m],arr[ir]); SWAP(brr[m],brr[ir]); } if(arr[m+1]<arr[ir]) { SWAP(arr[m+1],arr[ir]); SWAP(brr[m+1],brr[ir]); } if(arr[m]<arr[m+1]) { SWAP(arr[m],arr[m+1]); SWAP(brr[m],brr[m+1]); } i=m+1; j=ir; a=arr[m+1]; b=brr[m+1]; for(;;) { do i++; while (arr[i]>a); do j--; while (arr[j]<a); if(j<i) break; SWAP(arr[i],arr[j]); SWAP(brr[i],brr[j]); } arr[m+1]=arr[j]; arr[j]=a; brr[m+1]=brr[j]; brr[j]=b; jstack+=2; /* Push pointers to larger subarray on stack */ /* process smaller subarray immediately */ if(jstack>NSTACK) { printf("Stack error: NSTACK too small\n"); exit(0); } if(ir-i+1>=j-m) { istack[jstack]=ir; istack[jstack-1]=i; ir=j-1; } else { istack[jstack]=j-1; istack[jstack-1]=m; m=i; } } } } /* =============================== */ void ArraySort_Mix3(int n, long *arr, int *brr, int *crr) /* =============================== */ { int i,ir=n-1,j,k,m=0,jstack=0,b,c,NSTACK=50,istack[NSTACK]; long a,temp,MIN=7; for(;;) { /* Insertion sort when subarray is small enough */ if(ir-m<MIN) { for(j=m+1;j<=ir;j++) { a=arr[j]; b=brr[j]; c=crr[j]; for(i=j-1;i>=m;i--) { if(arr[i]<=a) break; arr[i+1]=arr[i]; brr[i+1]=brr[i]; crr[i+1]=crr[i]; } arr[i+1]=a; brr[i+1]=b; crr[i+1]=c; } if(!jstack) return; ir=istack[jstack--]; m=istack[jstack--]; } else { k=(m+ir)>>1; SWAP(arr[k],arr[m+1]); SWAP(brr[k],brr[m+1]); SWAP(crr[k],crr[m+1]); if(arr[m]>arr[ir]) { SWAP(arr[m],arr[ir]); SWAP(brr[m],brr[ir]); SWAP(crr[m],crr[ir]); } if(arr[m+1]>arr[ir]) { SWAP(arr[m+1],arr[ir]); SWAP(brr[m+1],brr[ir]); SWAP(crr[m+1],crr[ir]); } if(arr[m]>arr[m+1]) { SWAP(arr[m],arr[m+1]); SWAP(brr[m],brr[m+1]); SWAP(crr[m],crr[m+1]); } i=m+1; j=ir; a=arr[m+1]; b=brr[m+1]; c=crr[m+1]; for(;;) { do i++; while (arr[i]<a); do j--; while (arr[j]>a); if(j<i) break; SWAP(arr[i],arr[j]); SWAP(brr[i],brr[j]); SWAP(crr[i],crr[j]); } arr[m+1]=arr[j]; arr[j]=a; brr[m+1]=brr[j]; brr[j]=b; crr[m+1]=crr[j]; crr[j]=c; jstack+=2; /* Push pointers to larger subarray on stack */ /* process smaller subarray immediately */ if(jstack>NSTACK) { printf("Stack error: NSTACK too small\n"); exit(0); } if(ir-i+1>=j-m) { istack[jstack]=ir; istack[jstack-1]=i; ir=j-1; } else { istack[jstack]=j-1; istack[jstack-1]=m; m=i; } } } } /* to swap the string arrays */ /* ============================================= */ void s_swap(char **Pair_Name, int i, int j) /* ============================================= */ { char temp[Max_N_NameBase]; strcpy(temp,Pair_Name[i]); strcpy(Pair_Name[i],Pair_Name[j]); strcpy(Pair_Name[j],temp); } /* to sort the string array in order */ /* ============================================= */ void ArraySort_String(int n, char **Pair_Name, int *brr) /* ============================================= */ { int i,ir=n-1,j,k,m=0,jstack=0,b,NSTACK=50,istack[NSTACK]; int temp,MIN=7; char p[Max_N_NameBase]; for(;;) { /* Insertion sort when subarray is small enough */ if(ir-m<MIN) { for(j=m+1;j<=ir;j++) { strcpy(p,Pair_Name[j]); b=brr[j]; for(i=j-1;i>=m;i--) { if(strcmp(Pair_Name[i],p)<=0) break; strcpy(Pair_Name[i+1],Pair_Name[i]); brr[i+1]=brr[i]; } strcpy(Pair_Name[i+1],p); brr[i+1]=b; } if(!jstack) return; ir=istack[jstack--]; m=istack[jstack--]; } else { k=(m+ir)>>1; s_swap(Pair_Name,k,m+1); SWAP(brr[k],brr[m+1]); if(strcmp(Pair_Name[m],Pair_Name[ir])>0) { s_swap(Pair_Name,m,ir); SWAP(brr[m],brr[ir]); } if(strcmp(Pair_Name[m+1],Pair_Name[ir])>0) { s_swap(Pair_Name,m+1,ir); SWAP(brr[m+1],brr[ir]); } if(strcmp(Pair_Name[m],Pair_Name[m+1])>0) { s_swap(Pair_Name,m,m+1); SWAP(brr[m],brr[m+1]); } i=m+1; j=ir; strcpy(p,Pair_Name[m+1]); b=brr[m+1]; for(;;) { do i++; while (strcmp(Pair_Name[i],p)<0); do j--; while (strcmp(Pair_Name[j],p)>0); if(j<i) break; s_swap(Pair_Name,i,j); SWAP(brr[i],brr[j]); } strcpy(Pair_Name[m+1],Pair_Name[j]); strcpy(Pair_Name[j],p); brr[m+1]=brr[j]; brr[j]=b; jstack+=2; /* Push pointers to larger subarray on stack */ /* process smaller subarray immediately */ if(jstack>NSTACK) { printf("Stack error: NSTACK too small\n"); exit(0); } if(ir-i+1>=j-m) { istack[jstack]=ir; istack[jstack-1]=i; ir=j-1; } else { istack[jstack]=j-1; istack[jstack-1]=m; m=i; } } } } /* creat an int matrix with subscript ange m[nrl...nrh][ncl...nch] */ int **imatrix(long nrl,long nrh,long ncl,long nch) { long i, nrow=nrh-nrl+1,ncol=nch-ncl+1; int **m; /* allocate pointers to rows */ if((m=(int **)calloc(nrow,sizeof(int*)))==NULL) { printf("error imatrix: calloc error No. 1 \n"); return(NULL); } m+=0; m-=nrl; /* allocate rows and set pointers to them */ if((m[nrl]=(int *)calloc(nrow*ncol,sizeof(int)))==NULL) { printf("error imatrix: calloc error No. 2 \n"); return(NULL); } m[nrl]+=0; m[nrl]-=nrl; for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol; /* return pointer to array of pointers to rows */ return m; } /* creat char matrix with subscript ange cm[nrl...nrh][ncl...nch] */ char **cmatrix(long nrl,long nrh,long ncl,long nch) { long i, nrow=nrh-nrl+1,ncol=nch-ncl+1; char **cm; /* allocate pointers to rows */ if((cm=(char **)calloc(nrow,sizeof(char*)))==NULL) { printf("error cmatrix: calloc error No. 1 \n"); return(NULL); } cm+=0; cm-=nrl; /* allocate rows and set pointers to them */ if((cm[nrl]=(char *)calloc(nrow*ncol,sizeof(char)))==NULL) { printf("error cmatrix: calloc error No. 2 \n"); return(NULL); } cm[nrl]+=0; cm[nrl]-=nrl; for(i=nrl+1;i<=nrh;i++) cm[i]=cm[i-1]+ncol; /* return pointer to array of pointers to rows */ return cm; }
the_stack_data/82950541.c
/* Test for VLA size evaluation in va_arg. */ /* Origin: Joseph Myers <[email protected]> */ /* { dg-do run } */ /* { dg-options "-std=gnu99" } */ #include <stdarg.h> extern void exit (int); extern void abort (void); int a[10]; int i = 9; void f (int n, ...) { va_list ap; void *p; va_start (ap, n); p = va_arg (ap, typeof (int (*)[++i])); if (p != a) abort (); if (i != n) abort (); va_end (ap); } int main (void) { f (10, &a); exit (0); }
the_stack_data/90766118.c
/* PR 5878. We ICEd in verify_local_live_at_start because we incorrectly forced the PIC register live between BAR and BAZ. We did this because the definition of PIC_OFFSET_TABLE_REGNUM was incorrectly not INVALID_REGNUM when !flag_pic for most targets. */ /* { dg-do run } */ /* { dg-options "-O -fno-pic" } */ #if #cpu(a29k) /* No pic register. */ #elif defined(__alpha__) /* PIC register is $29, but is used even without -fpic. */ #elif defined(__arc__) # define PIC_REG "26" #elif defined(__arm__) # define PIC_REG "9" #elif defined(AVR) /* No pic register. */ #elif defined(__clipper__) /* No pic register. */ #elif defined(__convex__) /* No pic register. */ #elif defined(__cris__) # define PIC_REG "0" #elif defined(__D30V__) /* No pic register. */ #elif defined(__dsp1600__) /* No pic register. */ #elif defined(__elxsi__) /* No pic register. */ #elif defined(__fr30__) /* No pic register. */ #elif defined(__H8300__) || defined(__H8300H__) || defined(__H8300S__) /* No pic register. */ #elif defined(_IBMR2) /* No pic register. */ #elif #cpu(i370) /* No pic register. */ #elif defined(__i386__) # define PIC_REG "ebx" #elif defined(__i860__) /* No pic register. */ #elif defined(__i960__) /* No pic register. */ #elif defined(__ia64__) /* PIC register is r1, but is used even without -fpic. */ #elif defined(__M32R__) /* No pic register. */ #elif defined(__m68k__) # define PIC_REG "a5" #elif defined(__m88k__) # define PIC_REG "25" #elif defined(__mc68hc1x__) /* No pic register. */ #elif defined(__mcore__) /* No pic register. */ #elif defined(__mips__) /* PIC register is $28, but is used even without -fpic. */ #elif defined(__MMIX__) /* No pic register. */ #elif defined(__mn10200__) /* No pic register. */ #elif defined(__mn10300__) /* No pic register. */ #elif #cpu(ns32k) /* No pic register. */ #elif defined(__hppa__) /* PIC register is %r27 or %r19, but is used even without -fpic. */ #elif defined(__pdp11__) /* No pic register. */ #elif defined(__pj__) /* No pic register. */ #elif defined(__powerpc__) || defined(__PPC__) || defined(__POWERPC__) # ifdef __MACH__ # define PIC_REG "31" # else # define PIC_REG "30" # endif #elif defined(__ibm032__) /* aka romp */ /* No pic register. */ #elif defined(__s390__) # define PIC_REG "12" #elif defined(__sparc__) # define PIC_REG "l7" #elif defined(__v850) /* No pic register. */ #elif defined(__vax__) /* No pic register. */ #elif defined(__we32000__) /* No pic register. */ #elif defined(__xstormy16__) /* No pic register. */ #elif defined(__XTENSA__) /* No pic register. */ #elif defined(__sh__) # define PIC_REG "r12" #elif defined(__x86_64__) /* No pic register. */ #else # error "Modify the test for your target." #endif #if defined PIC_REG && !defined __PIC__ && !defined __pic__ register void *reg __asm__(PIC_REG); #else /* We really need a global register variable set to the PIC register to expose the bug. Oh well, let the test case not fail. */ static void *reg; #endif void * __attribute__((noinline)) dummy (void *x) { return x; } void f (void) { goto *dummy (&&bar); for (;;) { foo: reg = (void *) 1; if (!reg) goto baz; reg = &&foo; } bar: baz: reg = 0; } int main() { void *old_reg = reg; reg = (void *) 1; f (); /* Additionally test that the prologue/epilogue properly does *not* save and restore global registers. Not possible when the PIC register is in a register window, of course. On Darwin, you can't call library routines from non-PIC code. */ #if !defined (__sparc__) && !(defined(__MACH__) && defined(__POWERPC__)) if (reg) abort (); #endif reg = old_reg; return 0; }