示例#1
0
int main(){
  	int i=0,j,f=0;
  	char key[2];
  	printf("Enter the grammer. Enter 's' to stop\n");
  	while(1){
    	scanf("%s",inp[i]);
    	if(strcmp(inp[i],"s")==0)
      	break;
    	i++;
  	}
  	len=i;
  	for(i=0;i<len;i++){
    	f=0;
    	for(j=0;inp[i][j]!='\0';j++){
      	if((inp[i][j]=='>' || inp[i][j]=='|') && inp[i][j+1]==inp[i][0]){
        	im_rec(i);
        	indirect(i,out_ptr-2);
        	f=1;
        	break;
      	}
    	}
    	if(f==0){
      	strcpy(out[out_ptr++],inp[i]);
      	indirect(i,out_ptr-1);
    	}	
  	}
  	printf("Grammer without Left Recursion\n");
  	for(i=0;i<out_ptr;i++)
    	printf("%s\n",out[i]);
  	return 0;
}
示例#2
0
/* this for testing crash dumps */
static sqInt
indirect(long p)
{
	return p > 99
		? indirect(p - 100), indirect(p - 50) /* evade tail recursion opt */
		: *(sqInt *)p;
}
/* this for testing crash dumps */
static sqInt
indirect(sqIntptr_t p)
{
	if ((p & 2))
		error("crashInThisOrAnotherThread");
	return p > 99
		? indirect(p - 100), indirect(p - 50) /* evade tail recursion opt */
		: *(sqInt *)p;
}
示例#4
0
glm::vec3 radiance (const Ray & r, int iterations = 3)
{
    float t = 1.0f;
    glm::vec3 normale, normale2;
    Object* o = intersect(r, t, normale);
    if (t == noIntersect)
        return glm::vec3(0,0,0);
    glm::vec3 pointIntersection = r.origin + t*r.direction;

    // Calcul pour les ombres douces, point aléatoire de lumière autour de scene::light
    float pdf = 0;
    glm::vec3 normaleSphereLumiere = glm::normalize(pointIntersection - scene::light);
    glm::vec3 vecLumiere = sample_sphere(10, random_u(), random_u(), pdf, normaleSphereLumiere);
    glm::vec3 light = scene::light + vecLumiere;

    glm::vec3 directionLum = light - pointIntersection;
    glm::vec3 directionLumNormalize = glm::normalize(directionLum);
    Ray rayLum{pointIntersection+directionLumNormalize*0.1f, directionLumNormalize};
    intersect(rayLum, t, normale2);

    glm::vec3 direct(0,0,0);

    if (t*t > longueurCarree(directionLum))
    {
        direct = o->direct(normale, directionLumNormalize) / (pdf*longueurCarree(directionLum));
    }

    glm::vec3 indirect(0,0,0);

    if (iterations > 0)
         indirect = o->indirect(r.direction, pointIntersection, normale, iterations);

    return direct + indirect;
}
示例#5
0
void egg_example()
{
    std::plus<int> plus;
    BOOST_CHECK( (1|pipable(plus)(3)) == 1+3 );
    BOOST_CHECK( (1|(plus|pipi)(3)) == 1+3 );

    counter c;
    int a[] = {1,2,3};
    std::for_each(a, a+3, indirect(&c)); /*< `indirect(&c)` is copyable, whereas `c` is not. >*/
    BOOST_CHECK(c.m_count == 3);
}
示例#6
0
	void* add(EntityID id)
	{
		auto& idx = indirect(id);
		if (!idx)
		{
			return vtable->addToPool(pool, id, idx);
		}
		else
		{
			return vtable->indexIntoPool(pool, idx);
		}
	}
示例#7
0
int main()
{
    printf("meow\n");
    if (&somefunction != nullptr)
        printf("somefunction existed and it returned %d\n", somefunction());
    else
        printf("somefunction did not exist\n");
#if SHOULD_INSTALL_LIB
    indirect();
#endif
    return 0;
}
示例#8
0
文件: filestore.C 项目: Amit-DU/dht
void store(char *name) {
  struct stat st;
  if(stat(name, &st) == -1)
    fatal("couldn't stat file\n");

  inode *n = New inode(basename(name), st.st_size);

  FILE *f = fopen(name, "r");
  if(f == NULL)
    fatal("couldn't open file\n");

  indirect *in = New indirect(n);
  store_send(f, in, n);
}
示例#9
0
void main(void){

    char c[3];

    c[0] = 'h';
    c[1] = 'i';
    c[2] = '\0';

    print_string(c);
    print_string("\n");
    indirect(c);
    print_string("\n");
    print_string(c);
    print_string("\n");
}
示例#10
0
sqInt
crashInThisOrAnotherThread(sqInt inThisThread)
{
	if (inThisThread)
		return indirect(0);
	else {
		pthread_t newThread;

		(void)pthread_create(
				&newThread,					/* pthread_t *new_thread_ID */ 
				0,							/* const pthread_attr_t *attr */
				(void *(*)(void *))indirect,/* void * (*thread_execp)(void *) */
				(void *)300					/* void *arg */);
		sleep(1);
	}
	return 0;
}
示例#11
0
void Dimap::createIndirectGrid(double ulcX, double ulcY, int nbrSamp, int nbrLine,
                               double stepCarto, std::vector<double> const &vAltitude,
							   std::vector<Pt2dr> &vPtImg, std::string targetSyst, std::string inputSyst,
                               std::vector<double> vRefineCoef, double rowCrop, double sampCrop)const
{
    vPtImg.clear();

    // On cree un fichier de points cartographiques pour les transformer avec proj4
    {
        std::ofstream fic("processing/indirect_ptCarto.txt");
        fic << std::setprecision(15);
        for(int l=0;l<nbrLine;++l)
        {
            double Y = ulcY - l*stepCarto;
            for(int c = 0;c<nbrSamp;++c)
            {
                double X =ulcX + c*stepCarto;
                fic << X <<" "<<Y<<";"<<std::endl;
            }
        }
    }
    // transfo en Geo
    std::string command;

    command = g_externalToolHandler.get( "cs2cs" ).callName() + " " + targetSyst + " +to " + inputSyst + " -f %.12f -s processing/indirect_ptCarto.txt >processing/indirect_ptGeo.txt";
    int res = system(command.c_str());
    if (res != 0) std::cout<<"error calling cs2cs in createIndirectGrid"<<std::endl;
    for(size_t i=0;i<vAltitude.size();++i)
    {
        double altitude = vAltitude[i];
        // chargement des points
        std::ifstream fic("processing/indirect_ptGeo.txt");
        while(!fic.eof()&&fic.good())
        {
            double lon ,lat ,Z;
            char c;
            fic >> lat  >> lon >> Z >> c;
            if (fic.good())
            {
                vPtImg.push_back(indirect(Pt2dr(lat,lon),altitude,vRefineCoef,rowCrop,sampCrop));
            }
        }
    }
    std::cout << "createIndirectGrid - Nombre de points lus : "<<vPtImg.size()<<std::endl;
}
/* bit 0 = thread to crash in; 1 => this thread
 * bit 1 = crash method; 0 => indirect through null pointer; 1 => call exit
 */
sqInt
crashInThisOrAnotherThread(sqInt flags)
{
	if ((flags & 1)) {
		if (!(flags & 2))
			return indirect(flags & ~1);
		error("crashInThisOrAnotherThread");
		return 0;
	}
	else {
		CreateThread(0, /* no security */
					 0, /* default stack size */
					 (LPTHREAD_START_ROUTINE)indirect,
					 (void *)300,
					 STACK_SIZE_PARAM_IS_A_RESERVATION, /* creation flags 0 => run immediately */
					 0  /* thread id; we don't use it */);
		Sleep(1000);
	}
	return 0;
}
/* bit 0 = thread to crash in; 1 => this thread
 * bit 1 = crash method; 0 => indirect through null pointer; 1 => call exit
 */
sqInt
crashInThisOrAnotherThread(sqInt flags)
{
	if ((flags & 1)) {
		if (!(flags & 2))
			return indirect(flags & ~1);
		error("crashInThisOrAnotherThread");
		return 0;
	}
	else {
		pthread_t newThread;

		(void)pthread_create(
				&newThread,					/* pthread_t *new_thread_ID */ 
				0,							/* const pthread_attr_t *attr */
				(void *(*)(void *))indirect,/* void * (*thread_execp)(void *) */
				(void *)300					/* void *arg */);
		sleep(1);
	}
	return 0;
}
示例#14
0
	void* get(EntityID id)
	{
		auto idx = indirect(id);
		if (!idx) return nullptr;
		return vtable->indexIntoPool(pool, idx);
	}
示例#15
0
	void remove(EntityID id)
	{
		auto& idx = indirect(id);
		if (!idx) return;
		vtable->removeFromPool(pool, idx, indirection);
	}
示例#16
0
	bool theirIndirect() const
	{
		return indirect() && !ourRestart;
	}
示例#17
0
 bool ourIndirect() const
 {
     return indirect() && ourRestart;
 }
示例#18
0
void cgCallBuiltin(IRLS& env, const IRInstruction* inst) {
  auto const extra = inst->extra<CallBuiltin>();
  auto const callee = extra->callee;
  auto const returnType = inst->typeParam();
  auto const funcReturnType = callee->returnType();
  auto const returnByValue = callee->isReturnByValue();

  auto const dstData = dstLoc(env, inst, 0).reg(0);
  auto const dstType = dstLoc(env, inst, 0).reg(1);

  auto& v = vmain(env);

  // Whether `t' is passed in/out of C++ as String&/Array&/Object&.
  auto const isReqPtrRef = [] (MaybeDataType t) {
    return isStringType(t) || isArrayLikeType(t) ||
           t == KindOfObject || t == KindOfResource;
  };

  if (FixupMap::eagerRecord(callee)) {
    auto const sp = srcLoc(env, inst, 1).reg();
    auto const spOffset = cellsToBytes(extra->spOffset.offset);
    auto const& marker = inst->marker();
    auto const pc = marker.fixupSk().unit()->entry() + marker.fixupBcOff();

    auto const synced_sp = v.makeReg();
    v << lea{sp[spOffset], synced_sp};
    emitEagerSyncPoint(v, pc, rvmtl(), srcLoc(env, inst, 0).reg(), synced_sp);
  }

  int returnOffset = rds::kVmMInstrStateOff +
                     offsetof(MInstrState, tvBuiltinReturn);
  auto args = argGroup(env, inst);

  if (!returnByValue) {
    if (isBuiltinByRef(funcReturnType)) {
      if (isReqPtrRef(funcReturnType)) {
        returnOffset += TVOFF(m_data);
      }
      // Pass the address of tvBuiltinReturn to the native function as the
      // location where it can construct the return Array, String, Object, or
      // Variant.
      args.addr(rvmtl(), returnOffset);
      args.indirect();
    }
  }

  // The srcs past the first two (sp and fp) are the arguments to the callee.
  auto srcNum = uint32_t{2};

  // Add the this_ or self_ argument for HNI builtins.
  if (callee->isMethod()) {
    if (callee->isStatic()) {
      args.ssa(srcNum);
      ++srcNum;
    } else {
      // Note that we don't support objects with vtables here (if they may need
      // a $this pointer adjustment).  This should be filtered out during irgen
      // or before.
      args.ssa(srcNum);
      ++srcNum;
    }
  }

  // Add the func_num_args() value if needed.
  if (callee->attrs() & AttrNumArgs) {
    // If `numNonDefault' is negative, this is passed as an src.
    if (extra->numNonDefault >= 0) {
      args.imm((int64_t)extra->numNonDefault);
    } else {
      args.ssa(srcNum);
      ++srcNum;
    }
  }

  // Add the positional arguments.
  for (uint32_t i = 0; i < callee->numParams(); ++i, ++srcNum) {
    auto const& pi = callee->params()[i];

    // Non-pointer and NativeArg args are passed by value.  String, Array,
    // Object, and Variant are passed by const&, i.e. a pointer to stack memory
    // holding the value, so we expect PtrToT types for these.  Pointers to
    // req::ptr types (String, Array, Object) need adjusting to point to
    // &ptr->m_data.
    if (TVOFF(m_data) && !pi.nativeArg && isReqPtrRef(pi.builtinType)) {
      assertx(inst->src(srcNum)->type() <= TPtrToGen);
      args.addr(srcLoc(env, inst, srcNum).reg(), TVOFF(m_data));
    } else if (pi.nativeArg && !pi.builtinType && !callee->byRef(i)) {
      // This condition indicates a MixedTV (i.e., TypedValue-by-value) arg.
      args.typedValue(srcNum);
    } else {
      args.ssa(srcNum, pi.builtinType == KindOfDouble);
    }
  }

  auto dest = [&] () -> CallDest {
    if (isBuiltinByRef(funcReturnType)) {
      if (!returnByValue) return kVoidDest; // indirect return
      return funcReturnType
        ? callDest(dstData) // String, Array, or Object
        : callDest(dstData, dstType); // Variant
    }
    return funcReturnType == KindOfDouble
      ? callDestDbl(env, inst)
      : callDest(env, inst);
  }();

  cgCallHelper(v, env, CallSpec::direct(callee->nativeFuncPtr()),
               dest, SyncOptions::Sync, args);

  // For primitive return types (int, bool, double) and returnByValue, the
  // return value is already in dstData/dstType.
  if (returnType.isSimpleType() || returnByValue) return;

  // For return by reference (String, Object, Array, Variant), the builtin
  // writes the return value into MInstrState::tvBuiltinReturn, from where it
  // has to be tested and copied.

  if (returnType.isReferenceType()) {
    // The return type is String, Array, or Object; fold nullptr to KindOfNull.
    assertx(isBuiltinByRef(funcReturnType) && isReqPtrRef(funcReturnType));

    v << load{rvmtl()[returnOffset], dstData};

    if (dstType.isValid()) {
      auto const sf = v.makeReg();
      auto const rtype = v.cns(returnType.toDataType());
      auto const nulltype = v.cns(KindOfNull);
      v << testq{dstData, dstData, sf};
      v << cmovb{CC_Z, sf, rtype, nulltype, dstType};
    }
    return;
  }

  if (returnType <= TCell || returnType <= TBoxedCell) {
    // The return type is Variant; fold KindOfUninit to KindOfNull.
    assertx(isBuiltinByRef(funcReturnType) && !isReqPtrRef(funcReturnType));
    static_assert(KindOfUninit == 0, "KindOfUninit must be 0 for test");

    v << load{rvmtl()[returnOffset + TVOFF(m_data)], dstData};

    if (dstType.isValid()) {
      auto const rtype = v.makeReg();
      v << loadb{rvmtl()[returnOffset + TVOFF(m_type)], rtype};

      auto const sf = v.makeReg();
      auto const nulltype = v.cns(KindOfNull);
      v << testb{rtype, rtype, sf};
      v << cmovb{CC_Z, sf, rtype, nulltype, dstType};
    }
    return;
  }

  not_reached();
}
示例#19
0
文件: flatten-3.c 项目: 0day-ci/gcc
static void indirect1(void)
{
  indirect();
}
int main(int argc, char *argv[])
{
int x; int z;
char input[TOKEN];int i = 0;
while(1)
{printf("SHELL:");fflush(stdin);  fgets(input,TOKEN,stdin);x=strlen(input);
z=x-1;
input[z]='\0';
										for (  i = 0 ; input[i] != '\0' && (input[i] == ' '  || input[i] == '\t') ; i++ );
if ( input[i] == '\0' )
continue;
if ( feof(stdin) )exit(0);
int fd[2]= {-1,-1};
	int pd[2]= { -1,-1};
	pid_t pid1;
	int *inp;
	int *out;
	char subInput[25][TOKEN];

	char *tmp1 = input-1;
	y=0;

	while ( (tmp1 = strchr(tmp1+1,'\174')) != NULL)
		y++;

        out = fd;
	inp = pd;
	int j= 0;
	char *piper = strtok(input,"\174");
	int i = 0;

	char *arg[35];
	while( piper != NULL )
	{
		strcpy(subInput[i],piper);
		i++;
		piper = strtok(NULL,"\174");
	}


	for ( i = 0 ;  i < y+1 ; i++ )
	{


		char *args[100];
		char tmp[TOKEN];
		strcpy(tmp,subInput[i]);
		int k = 0;
		char *p;
		FILE *r = NULL;
		FILE *w = NULL;

		char *fileName = malloc(200);

		int stat = indirect(fileName,tmp,&r,i);

		if ( stat == -1)
			return;
		stat = outdirect(fileName,tmp,&w,i);
		if ( stat == -1)
			return;


		tmp1 = strchr(tmp,'\076');
		char * tmp2 = strchr(tmp,'\074');

		if ( tmp1)
			*tmp1='\0';
		if ( tmp2)
			*tmp2='\0';



		piper = strtok(tmp," ");

		while ( piper != NULL )
		{
			arg[k] = piper;
			k++;
			piper = strtok(NULL," ");
		}

		arg[k]=NULL;

		pipe(out);
		if ( fork() == 0 ) {



			if ( i != 0 )
				dup2(inp[0],0);
			if ( r != NULL  ) {
			  
				dup2(fileno(r),0);
				fclose(r);
			}

			if ( i != y ) {

				dup2(out[1],1);
				if ( w != NULL ){
					fprintf(stderr,"\nAMBIGUOUS ");
					return;
				}

			}
			else
			{
				if ( w != NULL )
					dup2(fileno(w),1);
			}


			cl(inp);
			cl(out);
			
			if ( execvp(*arg,arg) < 0 ) {
				fprintf(stderr,"\nCOMMAND NOT FOUND %s",*arg);
				exit(-1);
			}

		}
		cl(inp);
		pipe(inp);
		int *new = inp;
		inp = out;
		out = new;

		arg[j] = strtok(NULL,"\174");
		j++;

	}
	cl(fd);
	cl(pd);


	for ( i = 0 ; i < y+1; i++ ) {
		wait(NULL);
	}

}
}
示例#21
0
size_t calcB(void) {
    size_t (*indirect)(void);
    indirect = calcC;
    return sizeof(int) + indirect();
}