VarExprReturnSP LitMatrixExprReturn::convertToVarExprReturn( VarExprReturn &varExprReturn ) {
	SFC::DT dt = getDT();
//	assert( dt == varExprReturn.getDT() );

	SFCTypesManager::DimensionVector dimensionVector = SFCTypesManager::getDimensions( dt );

	if ( dimensionVector.empty() ) {
		Exprs exprs = DE( getSequence().front() );
		VarExprReturnSP varExprReturnSP = VarExprReturn::create(  getBlock(), exprs, ExprsProxyVector(), SFCTypesManager::getSingleton().getBasicType( "double" )  );
		varExprReturn.combine( "=", varExprReturnSP )->collapse();
		return VarExprReturn::create( varExprReturn );
	}

	SFCTypesManager::DimensionVector countVector( dimensionVector.size(), 0 );

	for( Sequence::iterator sqnItr = getSequence().begin() ; sqnItr != getSequence().end() ; ++sqnItr ) {

		for( unsigned int ix = 0 ; ix < (unsigned int) dimensionVector.size() ; ++ix ) {
			varExprReturn.getExprsProxyVector()[ ix ].setExprs(  IE( countVector[ ix ] )  );
		}

		Exprs exprs = BE(  varExprReturn.getExprs(), "=", DE( *sqnItr )  );
		exprs.buildUdm( getBlock(), SFC::CompoundStatement::meta_stmnt );

		for( int ix = dimensionVector.size() ; --ix >= 0 ;) {
			if ( ++countVector[ix] < dimensionVector[ix] ) break;
			countVector[ix] = 0;
		}

	}
	
	return VarExprReturn::create( varExprReturn );
}
void EsqCurto (ApontadorNo *Ap, short *Fim){
    ApontadorNo Ap1;
    if ((*Ap)->BitE == Horizontal){
        (*Ap)->BitE = Vertical;
        *Fim = TRUE;
        return;
    }
    if ((*Ap)->BitD == Horizontal){
        Ap1 = (*Ap)->Dir;
        (*Ap)->Dir = Ap1->Esq;
        Ap1->Esq = *Ap;
        *Ap = Ap1;
        if ((*Ap)->Esq->Dir->BitE == Horizontal){
            DE(&(*Ap)->Esq);
            (*Ap)->BitE = Horizontal;
        }
        *Fim = TRUE;
        return;
    }
    (*Ap)->BitD = Horizontal;
    if ((*Ap)->Dir->BitE == Horizontal){
        DE(Ap);
        *Fim = TRUE;
        return;
    }
    if ((*Ap)->Dir->BitD == Horizontal){
        DD(Ap);
        *Fim == TRUE;
    }
}
Exemple #3
0
static int _put_module(struct module *mod)
{
    int count = 0;

    if(mod == NULL)
    {
        DE("module is NULL.\n");
        return -1;
    }

    mod->state = MODULE_STATE_LIVE;
    /*mod->exit = force_exit;*/
    count = module_refcount(mod);
    while(count)
    {
        module_put(mod);
        --count;
    }

#if 0
#ifdef CONFIG_SMP
    DE("CONFIG_SMP.\n");
    for(i = 0;i < NR_CPUS; i++)
    {
        refparams = (local_t *)&mod->refparams[i];
        local_set(refparams, 0);
    }
#else
    DE("NO CONFIG_SMP.\n");
    local_set(&mod->ref, 0);
#endif
#endif

    return 0;
}
Exemple #4
0
static struct module* _find_module(char *module_name)
{
    struct list_head *modules = (struct list_head *)0xffffffff81aa3230;
    struct module *list_mod = NULL;
    struct module *mod = NULL;

    if(module_name == NULL || (strcmp(module_name, self_name) == 0))
    {
        DE("module_name is NULL. or couldn't remove self.\n");
    }
    else
    {
        list_for_each_entry(list_mod, modules, list)
        {
            /*DE("module name : %s.\n", list_mod->name);*/
            if(strcmp(list_mod->name, module_name) == 0)
            {
                DE("tool module name = %s.\n", module_name);
                mod = list_mod;
                return mod;
            }
        }
    }

    return NULL;
}
Exemple #5
0
static int ref_desc_create(ref_desc_t **_desc, TMatrix_CSR *matr, info_t info)
{
    ref_desc_t *desc = malloc(sizeof(ref_desc_t));
    if (desc == NULL) return DE(ERROR_MEMORY);
    int err = matrix_copy(matr, &desc->matr);
    if (err) {
        *_desc = NULL;
        free(desc);
        return DE(err);
    }
    desc->hash = REF_HASH;
    *_desc = desc;
    return ERROR_NO_ERROR;
}
Exemple #6
0
int
main (int argc, const char * argv [ ])
{
	if (argc < 2) {
		printf ("\nMust specify how many iterations the DE algorithm should run\n");
		exit(EXIT_FAILURE);
	}
	
	gsl_rng *ra;
	const gsl_rng_type *tipoRNG;
	gsl_rng_env_setup();
	tipoRNG = gsl_rng_ranlxs2;
	ra = gsl_rng_alloc(tipoRNG);
	/* Seed the generator */
	long seed = time(NULL);
	gsl_rng_set(ra,seed);



	DE (atoi(argv[1]),25,0.9,1,0.5,ra,evaluator);

	gsl_rng_free (ra);

	return EXIT_SUCCESS;
}
Exemple #7
0
static bool getGNUDebuglinkContents(const Binary *Bin, std::string &DebugName,
                                    uint32_t &CRCHash) {
  const ObjectFile *Obj = dyn_cast<ObjectFile>(Bin);
  if (!Obj)
    return false;
  for (const SectionRef &Section : Obj->sections()) {
    StringRef Name;
    Section.getName(Name);
    Name = Name.substr(Name.find_first_not_of("._"));
    if (Name == "gnu_debuglink") {
      StringRef Data;
      Section.getContents(Data);
      DataExtractor DE(Data, Obj->isLittleEndian(), 0);
      uint32_t Offset = 0;
      if (const char *DebugNameStr = DE.getCStr(&Offset)) {
        // 4-byte align the offset.
        Offset = (Offset + 3) & ~0x3;
        if (DE.isValidOffsetForDataOfSize(Offset, 4)) {
          DebugName = DebugNameStr;
          CRCHash = DE.getU32(&Offset);
          return true;
        }
      }
      break;
    }
  }
  return false;
}
Exemple #8
0
void IInsere(TipoReg x, TipoApont *Ap,TipoInclinacao *IAp, short *Fim)
{ if (*Ap == NULL)
  { *Ap = (TipoApont)malloc(sizeof(TipoNo));
    *IAp = Horizontal;  (*Ap)->Reg = x;
    (*Ap)->BitE = Vertical;  (*Ap)->BitD = Vertical;
    (*Ap)->Esq = NULL; (*Ap)->Dir = NULL; *Fim = FALSE;
    return;
  }
  if (x.Chave < (*Ap)->Reg.Chave)
  { IInsere(x, &(*Ap)->Esq, &(*Ap)->BitE, Fim);
    if (*Fim) return;
    if ((*Ap)->BitE != Horizontal) { *Fim = TRUE; return; }
    if ((*Ap)->Esq->BitE == Horizontal)
    { EE(Ap); *IAp = Horizontal; return; }
    if ((*Ap)->Esq->BitD == Horizontal) { ED(Ap); *IAp = Horizontal; }
    return;
  }
  //COMPARA플O AQUI
  if (x.Chave <= (*Ap)->Reg.Chave)
  { printf("Erro: Chave ja esta na arvore\n");
    *Fim = TRUE;
    return;
  }
  IInsere(x, &(*Ap)->Dir, &(*Ap)->BitD, Fim);
  if (*Fim) return;
  if ((*Ap)->BitD != Horizontal) { *Fim = TRUE;  return; }
  if ((*Ap)->Dir->BitD == Horizontal)
  { DD(Ap); *IAp = Horizontal; return;}
  if ((*Ap)->Dir->BitE == Horizontal) { DE(Ap); *IAp = Horizontal; }
}
Exemple #9
0
void EsqCurto(TipoApont *Ap, short *Fim)
{ /* Folha esquerda retirada => arvore curta na altura esquerda */
  TipoApont Ap1;
  if ((*Ap)->BitE == Horizontal)
  { (*Ap)->BitE = Vertical; *Fim = TRUE; return; }
  if ((*Ap)->BitD == Horizontal)
  { Ap1 = (*Ap)->Dir; (*Ap)->Dir = Ap1->Esq; Ap1->Esq = *Ap; *Ap = Ap1;
    if ((*Ap)->Esq->Dir->BitE == Horizontal)
    { DE(&(*Ap)->Esq); (*Ap)->BitE = Horizontal;}
    else if ((*Ap)->Esq->Dir->BitD == Horizontal)
         { DD(&(*Ap)->Esq); (*Ap)->BitE = Horizontal; }
    *Fim = TRUE;
    return;
  }
  (*Ap)->BitD = Horizontal;
  if ((*Ap)->Dir->BitE == Horizontal) { DE(Ap); *Fim = TRUE; return; }
  if ((*Ap)->Dir->BitD == Horizontal) {  DD(Ap); *Fim = TRUE; }
}
Exemple #10
0
int main()
{
    FILE *input, *output;
    input=fopen("input.dat","r");
    output=fopen("output.dat","w");
    int x;
    char c[1024];

lista = (SENTINEL*) malloc(sizeof(SENTINEL));
    lista->head=0;
    lista->tail=0;
    while(fscanf(input,"%s",c)!=EOF)
    {
        if(strcmp(c,"PRINT_ALL")==0)
                PRINT_ALL(output);
        else
            if(strcmp(c,"AF")==0)
            {
                fscanf(input,"%d",&x);
                AF(x);
            }
        else
            if(strcmp(c,"AL")==0)
            {
                fscanf(input,"%d",&x);
                AL(x);
            }
        else
            if(strcmp(c,"DF")==0)
                DF();
        else
            if(strcmp(c,"DL")==0)
                DL();
        else
            if(strcmp(c,"DOOM_THE_LIST")==0)
                DOOM_THE_LIST();
        else
            if(strcmp(c,"DE")==0)
            {
                fscanf(input,"%d",&x);
                DE(x);
            }
        else
            if(strcmp(c,"PRINT_F")==0)
            {
                fscanf(input,"%d",&x);
                PRINT_F(x,output);
            }
        else
            if(strcmp(c,"PRINT_L")==0)
            {
                fscanf(input,"%d",&x);
                PRINT_L(x,output);
            }
    }
    return 0;
}
Exemple #11
0
static int _dec_module_refcnt(void)
{
    struct module *mod = NULL;
    char *module_name = params;

    DE("tool init.\n");
    mod = _find_module(module_name);
    if(mod)
    {
        _put_module(mod);
    }
    else
    {
        DE("could not find the module : %s.\n", module_name);
    }
    /*DD("\n");*/
    return 0;
}
Exemple #12
0
void NConfig::_remap(const size_t osize, const size_t nsize)
{
	data = (char *) mremap(data, osize, nsize, 1);
	if (data == MAP_FAILED) {
		perror("mremap");
		abort();
	}
	sb = SB;
	rdir = DE(sb->root);
}
Exemple #13
0
int main()
{
    FILE *g;
    l=0;
    head=NULL;
    tail=NULL;
    g=fopen("input.txt", "r");
    char cuvant[15];
    int n;
    if (g==NULL)
    {
        printf("Error in opening the file.");
        exit(1);
    }

    while(fscanf(g,"%s",cuvant)>0)
    {
        if (strcmp(cuvant,"AF")==0)
        {
            fscanf(g,"%d",&n);
            AF(n);
        }
        else if (strcmp(cuvant,"AL")==0)
        {
            fscanf(g,"%d",&n);
            AL(n);
        }
        else if (strcmp(cuvant,"DF")==0)
            DF();
        else if(strcmp(cuvant,"DL")==0)
            DL();
        else if(strcmp(cuvant,"DE")==0)
        {
            fscanf(g,"%d",&n);
            DE(n);
        }
        else if(strcmp(cuvant,"PRINT_ALL")==0)
            PRINT_ALL();
        else if(strcmp(cuvant,"PRINT_F")==0)
        {
            fscanf(g,"%d",&n);
            PRINT_F(n);
        }
        else if(strcmp(cuvant,"PRINT_L")==0)
        {
            fscanf(g,"%d",&n);
            PRINT_L(n);
        }
        else if(strcmp(cuvant,"DOOM_THE_LIST")==0)
            DOOM_THE_LIST();
    }
    fclose(g);
    printf("%d",l);
    return 0;
}
Exemple #14
0
static int ref_compute(ref_desc_t *desc, TVector_SMP *in, TVector_SMP *out)
{
    if (desc->hash != REF_HASH) return DE(ERROR_INVALID_DESC);

    TMatrix_CSR *matr = &desc->matr;
    int rows     = matr->rows;
    int cols     = matr->cols;
    int in_size  = in->size;
    int out_size = out->size;

    if (!(rows == out_size && cols == in_size))
    {
        D(fprintf(stderr, "matr: %d x %d\nin: %d, out: %d\n",
                    rows, cols, in_size, out_size));
        return DE(ERROR_INVALID_CONF);
    }

    DSAFE(mv_omp_mul(matr, in, out));

    return ERROR_NO_ERROR;
}
Exemple #15
0
void main()
{	
	ldc1000_int();
	Port_init();
	Init_Lcd();
	//Speed_IN1();
	//Time1_init();
	PT0=1;
	while(1)
	{
		Sdata=Rp_Sample();
		va=Sdata;
		DE(1);
		Sdata=Rp_Sample();
		va1=Sdata;
		va2=va1-va;
		LCD_value(0,0,va);
		if(va>1000){
			DE(200);
			SBUF=2;
		}else{
				DE(200);	DE(200);	DE(200);	DE(200);
			SBUF=0;
		}
		
		
	}
}
VarMatrixExprReturnSP LitMatrixExprReturn::convertToVarMatrixExprReturn( void ) {
	VarMatrixExprReturn::Sequence sequence;

	if ( !getSequence().empty() ) {
		SFC::DT dt = SFCTypesManager::getSingleton().getBaseDT( getDT() );
		for( Sequence::iterator sqnItr = getSequence().begin() ; sqnItr != getSequence().end() ; (void)++sqnItr ) {
			Exprs exprs = DE( *sqnItr );
			sequence.push_back(  VarExprReturn::create( getBlock(), exprs, ExprsProxyVector(), dt )  );
		}
	}

	return VarMatrixExprReturn::create( getBlock(), getDT(), sequence );
}
void IInsere(TipoItem x, ApontadorNo *Ap, Inclinacao *IAp, short *Fim) {
  if (*Ap == NULL) {
  	*Ap = (ApontadorNo)malloc(sizeof(No));
    *IAp = Horizontal;
    (*Ap)->Reg = x;
    (*Ap)->BitE = Vertical;
    (*Ap)->BitD = Vertical;
    (*Ap)->Esq = NULL;
    (*Ap)->Dir = NULL;
    *Fim = FALSE;
    return;
  }
  if (x.cod < (*Ap)->Reg.cod) {
  	IInsere(x, &(*Ap)->Esq, &(*Ap)->BitE, Fim);
    if (*Fim)
		return;
    if ((*Ap)->BitE != Horizontal) {
    	*Fim = TRUE;
    	return;
	}
    if ((*Ap)->Esq->BitE == Horizontal) {
    	EE(Ap);
    	*IAp = Horizontal;
    	return;
	}
    if ((*Ap)->Esq->BitD == Horizontal) {
    	ED(Ap);
    	*IAp = Horizontal;
	}
    return;
  }
  IInsere(x, &(*Ap)->Dir, &(*Ap)->BitD, Fim);
  if (*Fim)
	return;
  if ((*Ap)->BitD != Horizontal) {
  	*Fim = TRUE;
  	return;
  }
  if ((*Ap)->Dir->BitD == Horizontal) {
  	DD(Ap);
  	*IAp = Horizontal;
  	return;
  }
  if ((*Ap)->Dir->BitE == Horizontal) {
  	DE(Ap);
  	*IAp = Horizontal;
  }
}
Exemple #18
0
static int __init tool_init(void)
{
    DE("type = %d.\n", type);
    switch(type)
    {
        case 1:
            _dec_module_refcnt();
            break;
        case 2:
            _get_kallsym();
            break;
        default:
            _show_usage();
            break;
    }

    return 0;
}
VarExprReturnSP LitMatrixExprReturn::convertToVarExprReturn( SFC::ArgDeclBase argDeclBase ) {

	// IF TYPE ISN'T ARRAY, THEN IT MUST BE BASIC
	if ( getDT().type() != SFC::Array::meta ) {
		double value = getSequence().front();
		// SEE IF value IS CAN BE ACCURATELY REPRESENTED AS AN INTEGER
		Exprs exprs;
		if ( int(value) <= INT_MAX && int( value ) == value ) exprs = IE( (int) value );
		else                                             exprs = DE( value );
		return VarExprReturn::create( getBlock(), exprs, ExprsProxyVector(), getDT() );
	}

	if ( argDeclBase == Udm::null ) {
		argDeclBase = SFCManager::createUniqueLocalVar( getBlock(), "result" );
		argDeclBase.dt() = getDT();
	}

	VarExprReturnSP varExprReturnSP = VarExprReturn::create( getBlock(), argDeclBase, getDT() );
	return convertToVarExprReturn( *varExprReturnSP );
}
void LitMatrixExprReturn::assignTo( VarExprReturnSPVector &varExprReturnSPVector ) {

	SFC::DT dt = SFCTypesManager::getSingleton().getBaseDT( getDT() );

	VarExprReturnSPVector::iterator vsvItr = varExprReturnSPVector.begin();

	for( Sequence::iterator sqnItr = getSequence().begin() ; sqnItr != getSequence().end() ; (void)++sqnItr ) {
		VarExprReturnSP varExprReturnSP = *vsvItr;
	
		if ( varExprReturnSP->getClassName() == ReferenceReturn::getName() ) {
			ReferenceReturnSP referenceReturnSP =
			 ExprReturn::static_pointer_cast< ReferenceReturn >( varExprReturnSP );
			referenceReturnSP->acquireType( dt );
		}

		Exprs exprs = BE(  varExprReturnSP->getExprs(), "=", DE( *sqnItr )  );
		exprs.buildUdm( getBlock(), SFC::CompoundStatement::meta_stmnt );

		(void)++vsvItr;
	}
}
Exemple #21
0
#include "dialog.h"
#endif

#ifndef TEXTURE_MOD_H
#include "rtexture.h"
#endif

#ifndef NOISE_H
#include "noise.h"
#endif

DIALOG_ELEMENT dialog[] =
{
	DIALOG_VGROUP,
		DIALOG_COLGROUP, 3,
			DIALOG_LABEL, DE("Diffuse"),
			DIALOG_COLORBOX,
			DIALOG_CHECKBOX,
			DIALOG_LABEL, DE("Reflective"),
			DIALOG_COLORBOX,
			DIALOG_CHECKBOX,
			DIALOG_LABEL, DE("Transparent"),
			DIALOG_COLORBOX,
			DIALOG_CHECKBOX,
		DIALOG_END,
		DIALOG_COLGROUP, 2,
			DIALOG_LABEL, DE("Octaves"),
			DIALOG_SLIDER, 1, 8,
			DIALOG_LABEL, DE("Radius"),
			DIALOG_FLOAT,
			DIALOG_LABEL, DE("Twist"),
Exemple #22
0
#include "dialog.h"
#endif

#ifndef TEXTURE_H
#include "rtexture.h"
#endif

#ifndef NOISE_H
#include "noise.h"
#endif

DIALOG_ELEMENT dialog[] =
{
	DIALOG_VGROUP,
		DIALOG_COLGROUP, 4,
			DIALOG_LABEL, DE("Frequency"),
			DIALOG_FLOAT,
			DIALOG_LABEL, DE("Amplitude"),
			DIALOG_FLOAT,
			DIALOG_LABEL, DE("Octaves"),
			DIALOG_SLIDER, 1, 8,
		DIALOG_END,
	DIALOG_END,
	DIALOG_FINISH
};

typedef struct
{
	float frequency, amplitude;
	ULONG octaves;
} DIALOG_DATA;
Exemple #23
0
static void __exit tool_exit(void)
{
    DE("tool exit.\n");
}
Exemple #24
0
static void _show_usage(void)
{
    DE("1 : decrease module referent count. type=1 module_name=\"abc\"\n");
    DE("2 : decrease module referent count. type=2 symbol_name=\"do_page_default\"\n");
}
void CFEAT::s1DC0LElement (int nE)
// ==================================================================
// Function: Computes the element strain and stress
//           for the 1D-C0 linear element
//    Input: Element number
//   Output: None
// ==================================================================
{
    CVector<int>   nVNL(NUMENODES);  // list of element nodes

    CVector<float> fVMatP(NUMEP);     // young's modulus
    CVector<float> fVCoords1(PDIM);     // nodal coordinates (node 1)
    CVector<float> fVCoords2(PDIM);     // nodal coordinates (node 2)
    CVector<float> fVCoords3(PDIM);    // nodal coordinates (node 3)
    CVector<float> fVCoords4(PDIM);    // nodal coordinates (node 4)
    CVector<float> fVDisp1(DOFPN);      // nodal displacements (node 1)
    CVector<float> fVDisp2(DOFPN);      // nodal displacements (node 2)
    CVector<float> fVStrain(NUMSCOMP);  // element strain
    CVector<float> fVStress(NUMSCOMP);  // element stress
    CMatrix<double> DE(3,1),DS(3,1),DSR(3,1),DDI(8,1);
    float fVonMis,fTresca,fS11,fS22;
    DE.Set(0.0);
    DS.Set(0.0);
    DSR.Set(0.0);
    // get element data

    m_ElementData(nE).GetMaterialProperty (fVMatP);
    m_ElementData(nE).GetNodes (nVNL);
    m_NodalData(nVNL(1)).GetCoords (fVCoords1);
    m_NodalData(nVNL(2)).GetCoords (fVCoords2);
    m_NodalData(nVNL(3)).GetCoords (fVCoords3);
    m_NodalData(nVNL(4)).GetCoords (fVCoords4);
    m_NodalResponseData(nVNL(1)).GetValues (fVDisp1);
    m_NodalResponseData(nVNL(2)).GetValues (fVDisp2);
    int l=1;
    for(int i=1; i<=NUMENODES; i++)
    {
        DDI(l,1)=m_SND(2*nVNL(i)-1,1);
        l++;
        DDI(l,1)=m_SND(2*nVNL(i),1);
        l++;
    }
    Multiply(DB,DDI,DE);
    Subtract(DE,DEO,DS);
    Multiply(DD,DS,DSR);
    // strain
    for(int i=1; i<=3; i++)
        fVStrain(i) = DE(i,1);

    // stress
    for(int i=1; i<=3; i++)
        fVStress(i) = DSR(i,1);
    fS11=((DSR(1,1)+DSR(2,1))/2)+0.5*sqrt(pow(DSR(1,1)-DSR(2,1),2)+4*pow(DSR(3,1),2));
    fS22=((DSR(1,1)+DSR(2,1))/2)-0.5*sqrt(pow(DSR(1,1)-DSR(2,1),2)+4*pow(DSR(3,1),2));
    fVonMis=sqrt(pow(fS11,2)+pow(fS22,2)-fS11*fS22);
    fTresca=abs(fS11-fS22)/2;
    // update model with the computed values
    m_ElementResponseData(nE).SetStrain (fVStrain);
    m_ElementResponseData(nE).SetStress(fVStress);
    m_ElementResponseData(nE).SetOtherStress (fS11,fS22,fVonMis,fTresca);
}
Exemple #26
0
 * There we store the dot, dotdot, meta, data, and data.suffix
 * entries that do not point to "real" publications.
 */

#define DIRSIZ(string) \
    ((sizeof (struct dirent) - (MAXNAMLEN+1)) + ((sizeof(string) + 3) &~ 3))
    

#define DE( type, string)					\
    { 0, DIRSIZ(string), type, sizeof(string)-1, string } 

/*
 * Meta-entries in publication, version, and page directories
 */
static struct dirent des_long[] = {
    DE(DT_DIR, "."),		  /* 12 bytes */
    DE(DT_DIR, ".."),		  /* 12 bytes */
    DE(DT_REG, VPUBMETA_NAME),	  /* 16 bytes */
    { 0, 36, DT_REG, 4, VPUBDATA_NAME }, /* 76 - (12+12+16) = 36 bytes */

};

/*
 * Meta-entries in root directory.
 */
static struct dirent des_root[] = {
    DE(DT_DIR, "."),		  /* 12 bytes */
    DE(DT_DIR, ".."),		  /* 12 bytes */
    DE(DT_REG, VEVENTPUBS_NAME),  /* 16 bytes */
    { 0, 36, DT_REG, 4, VEVENTSUBS_NAME }, /* 76 - (12+12+16) = 36 bytes */
};
Exemple #27
0
int NConfig::open(int how)
{
	if (!fname)
		return NC_ERR_NFILE;
	if (how != NC_O_RO && how != NC_O_RW)
		return NC_ERR_TYPE;
	if (fd > -1)
		close();

	int ff;
	if ((ff = ::open(fname, how)) == -1)
		return NC_ERR_PERM;

	struct stat sbuf;
	fstat(ff, &sbuf);

	if (!sbuf.st_size)
		return NC_ERR_CORRUPT;

#ifdef NO_MAP_SHARED
	if ((data = (char *) mmap(NULL, sbuf.st_size, how == NC_O_RO ? PROT_READ : (PROT_READ|PROT_WRITE), MAP_PRIVATE, ff, 0)) == MAP_FAILED) {
#else
	if ((data = (char *) mmap(NULL, sbuf.st_size, how == NC_O_RO ? PROT_READ : (PROT_READ|PROT_WRITE), MAP_SHARED, ff, 0)) == MAP_FAILED) {
#endif
		::close(ff);
		return NC_ERR_NMEM;
	}
	if (memcmp(((struct nc_sb_s *) data)->magic, NC_SB_MAGIC, 4)) {
		munmap(data, sbuf.st_size);
		::close(ff);
		return NC_ERR_CORRUPT;
	}
	fd = ff;
	omode = how;
	sb = SB;
	lsize = 0;
	cname = strdup("/");

	lockFile(NC_L_RO, TRUE);
	rdir = DE(sb->root);
	unLockFile();
	return NC_ERR_OK;
}

struct nc_de_s *NConfig::getDirEnt(const char *name, struct nc_de_s *cc)
{
	struct nc_de_s *ret = cc ? cc : ((*name == '/') ? rdir : cdir);
	char *c = canonize(name), *can;

	if (!(can = c))
		return ret;
	while (*c) {
		if (!strcmp(c, ".."))
			ret = DE(ret->parent);
		else
			if (strcmp(c, ".")) {
				struct nc_de_s *re = ret;
				int left = 0, right = ret->pages-1, p, r;

				ret = NULL;
				while (left <= right) {
					p = (left + right) / 2;
					r = strcmp(c, data+IDE(re, p)->name);
					if (r < 0) {
						left = p + 1;
						continue;
					}
					if (!r) {
						ret = IDE(re, p);
						break;
					}
					right = p - 1;
				}
			}
		c += strlen(c)+1;
		if (!ret || (*c && ret->type != NC_DIR)) {
			ret = NULL;
			break;
		}
	}
	free(can);
	return ret;
}

char *NConfig::canonize(const char *name)
{
	if (*name == '/')
		name++;
	size_t i = strlen(name);
	char *ret = (char *)calloc(1, i+3);
	memcpy(ret, name, i);
	for (size_t j=0; j<i; j++)
		if (ret[j] == '/')
			ret[j] = 0;
	return ret;
}

void NConfig::lockFile(int type, int force)
{
#ifdef NC_DEBUG_LOCK
	fprintf(stderr, "Lock called type=%d force=%d lock=%d olck=%u\n", type, force, lock, olck);
#endif
	if (lock == NC_L_RO && type == NC_L_RW) {
		fprintf(stderr, "Lock promotion is not possible.\n");
		abort();
	}
	if (lock != NC_L_NONE) {
		olck++;
		return;
	}
	
	struct flock flc = { type == NC_L_RW ? F_WRLCK : F_RDLCK, SEEK_SET, 0, 0, 0 };
	while (fcntl(fd, F_SETLKW, &flc)) {
		sched_yield();
		flc.l_type = type == NC_L_RW ? F_WRLCK : F_RDLCK;
		flc.l_whence = SEEK_SET;
		flc.l_len = flc.l_start = 0;
	}

#ifdef NC_DEBUG_LOCK
	fprintf(stderr, "Locked %u %u %s\n", sb->modtime, update, force ? "forced." : "");
#endif
	if (careful && type == NC_L_RW)
		mprotect(data, sb->size, PROT_READ | PROT_WRITE);
	lock = type;
	olck = 0;
	if (sb->modtime != update || force) {
		// refresh memory mapping
		if (lsize != sb->size) {
			_remap(lsize, sb->size);
			lsize = sb->size;
			chunks = CM(sb->chunk);
		}
		cdir = getDirEnt(cname);
		update = sb->modtime;
	}
}
Exemple #28
0
bool skin_ui_process_events(SkinUI* ui) {
    SkinEvent ev;

#ifdef _WIN32
    if (ui->ui_params.win32_ignore_events) {
        // In QT, Windows messages are received by the QT thread, which is
        // the thread that creates all of its windows, so that should be
        // okay. However, in GPU accelerated images, there's a native window
        // that's created that represents the actual OpenGL output pane, and
        // that window is created from this thread and not the QT thread. We
        // need to keep its message queue from getting jammed up with
        // messages, so we need to grab any messages we see and drop
        // unnecessary ones on the floor.
        MSG message;
        PeekMessage(&message, NULL, 0, 0, PM_REMOVE);
    }
#endif  // _WIN32

    while(skin_event_poll(&ev)) {
        switch(ev.type) {
        case kEventVideoExpose:
            DE("EVENT: kEventVideoExpose\n");
            skin_window_redraw(ui->window, NULL);
            break;

        case kEventKeyDown:
            DE("EVENT: kEventKeyDown scancode=%d mod=0x%x\n",
               ev.u.key.keycode, ev.u.key.mod);
            skin_keyboard_process_event(ui->keyboard, &ev, 1);
            break;

        case kEventKeyUp:
            DE("EVENT: kEventKeyUp scancode=%d mod=0x%x\n",
               ev.u.key.keycode, ev.u.key.mod);
            skin_keyboard_process_event(ui->keyboard, &ev, 0);
            break;

        case kEventTextInput:
            DE("EVENT: kEventTextInput text=[%s] down=%s\n",
               ev.u.text.text, ev.u.text.down ? "true" : "false");
            skin_keyboard_process_event(ui->keyboard, &ev, ev.u.text.down);
            break;

        case kEventMouseMotion:
            DE("EVENT: kEventMouseMotion x=%d y=%d xrel=%d yrel=%d button=%d\n",
               ev.u.mouse.x, ev.u.mouse.y, ev.u.mouse.xrel, ev.u.mouse.yrel,
               ev.u.mouse.button);
            skin_window_process_event(ui->window, &ev);
            break;

        case kEventMouseButtonDown:
        case kEventMouseButtonUp:
            DE("EVENT: kEventMouseButton x=%d y=%d xrel=%d yrel=%d button=%d\n",
               ev.u.mouse.x, ev.u.mouse.y, ev.u.mouse.xrel, ev.u.mouse.yrel,
               ev.u.mouse.button);
            {
                int  down = (ev.type == kEventMouseButtonDown);
                if (ev.u.mouse.button == kMouseButtonScrollUp)
                {
                    /* scroll-wheel simulates DPad up */
                    SkinKeyCode  kcode;

                    kcode = skin_keycode_rotate(kKeyCodeDpadUp,
                                                skin_layout_get_dpad_rotation(
                                                        ui->layout));
                    ui->ui_funcs->keyboard_event(NULL, kcode, down);
                }
                else if (ev.u.mouse.button == kMouseButtonScrollDown)
                {
                    /* scroll-wheel simulates DPad down */
                    SkinKeyCode  kcode;

                    kcode = skin_keycode_rotate(kKeyCodeDpadDown,
                                                skin_layout_get_dpad_rotation(
                                                        ui->layout));
                    ui->ui_funcs->keyboard_event(NULL, kcode, down);
                }
                else if (ev.u.mouse.button == kMouseButtonLeft) {
                    skin_window_process_event(ui->window, &ev);
                }
            }
            break;

        case kEventQuit:
            DE("EVENT: kEventQuit\n");
            /* only save emulator config through clean exit */
            return true;
        }
    }

    skin_keyboard_flush(ui->keyboard);
    return false;
}
bool skin_ui_process_events(SkinUI* ui) {
    SkinEvent ev;

    while(skin_event_poll(&ev)) {
        switch(ev.type) {
        case kEventVideoExpose:
            DE("EVENT: kEventVideoExpose\n");
            skin_window_redraw(ui->window, NULL);
            break;

        case kEventKeyDown:
            DE("EVENT: kEventKeyDown scancode=%d mod=0x%x\n",
               ev.u.key.keycode, ev.u.key.mod);
            skin_keyboard_process_event(ui->keyboard, &ev, 1);
            break;

        case kEventKeyUp:
            DE("EVENT: kEventKeyUp scancode=%d mod=0x%x\n",
               ev.u.key.keycode, ev.u.key.mod);
            skin_keyboard_process_event(ui->keyboard, &ev, 0);
            break;

        case kEventTextInput:
            DE("EVENT: kEventTextInput text=[%s] down=%s\n",
               ev.u.text.text, ev.u.text.down ? "true" : "false");
            skin_keyboard_process_event(ui->keyboard, &ev, ev.u.text.down);
            break;

        case kEventMouseMotion:
            DE("EVENT: kEventMouseMotion x=%d y=%d xrel=%d yrel=%d button=%d\n",
               ev.u.mouse.x, ev.u.mouse.y, ev.u.mouse.xrel, ev.u.mouse.yrel,
               ev.u.mouse.button);
            skin_window_process_event(ui->window, &ev);
            break;

        case kEventMouseButtonDown:
        case kEventMouseButtonUp:
            DE("EVENT: kEventMouseButton x=%d y=%d xrel=%d yrel=%d button=%d\n",
               ev.u.mouse.x, ev.u.mouse.y, ev.u.mouse.xrel, ev.u.mouse.yrel,
               ev.u.mouse.button);
            {
                int  down = (ev.type == kEventMouseButtonDown);
                if (ev.u.mouse.button == kMouseButtonScrollUp)
                {
                    /* scroll-wheel simulates DPad up */
                    SkinKeyCode  kcode;

                    kcode = skin_keycode_rotate(kKeyCodeDpadUp,
                                                skin_layout_get_dpad_rotation(
                                                        ui->layout));
                    ui->ui_funcs->keyboard_event(NULL, kcode, down);
                }
                else if (ev.u.mouse.button == kMouseButtonScrollDown)
                {
                    /* scroll-wheel simulates DPad down */
                    SkinKeyCode  kcode;

                    kcode = skin_keycode_rotate(kKeyCodeDpadDown,
                                                skin_layout_get_dpad_rotation(
                                                        ui->layout));
                    ui->ui_funcs->keyboard_event(NULL, kcode, down);
                }
                else if (ev.u.mouse.button == kMouseButtonLeft) {
                    skin_window_process_event(ui->window, &ev);
                }
            }
            break;

        case kEventQuit:
            DE("EVENT: kEventQuit\n");
            /* only save emulator config through clean exit */
            return true;
        }
    }

    skin_keyboard_flush(ui->keyboard);
    return false;
}