예제 #1
0
/* =============================================================================
 * freeNodes
 * =============================================================================
 */
static void
freeNodes (adtree_node_t* nodePtr)
{
    if (nodePtr) {
        vector_t* varyVectorPtr = nodePtr->varyVectorPtr;
        long v;
        long numVary = vector_getSize(varyVectorPtr);
        for (v = 0; v < numVary; v++) {
            adtree_vary_t* varyPtr = (adtree_vary_t*)vector_at(varyVectorPtr, v);
            freeNodes(varyPtr->zeroNodePtr);
            freeNodes(varyPtr->oneNodePtr);
            freeVary(varyPtr);
        }
        freeNode(nodePtr);
    }
}
예제 #2
0
파일: peres.c 프로젝트: neriberto/pev
int main(int argc, char **argv)
{
	if (argc < 3) {
		usage();
		exit(EXIT_FAILURE);
	}

	options_t *options = parse_options(argc, argv); // opcoes

	const char *path = argv[argc-1];
	pe_ctx_t ctx;

	pe_err_e err = pe_load_file(&ctx, path);
	if (err != LIBPE_E_OK) {
		pe_error_print(stderr, err);
		return EXIT_FAILURE;
	}

	err = pe_parse(&ctx);
	if (err != LIBPE_E_OK) {
		pe_error_print(stderr, err);
		return EXIT_FAILURE;
	}

	if (!pe_is_pe(&ctx))
		EXIT_ERROR("not a valid PE file");

	NODE_PERES *node = discoveryNodesPeres(&ctx);
	if (node == NULL) {
		fprintf(stderr, "this file has no resources\n");
		return EXIT_SUCCESS;
	}

	if (options->all) {
		showInformations(node);
		showStatistics(node);
		extractResources(&ctx, node);
	} else {
		if (options->extract)
			extractResources(&ctx, node);
		if (options->info)
			showInformations(node);
		if (options->statistics)
			showStatistics(node);
	}

	freeNodes(node);

	// libera a memoria
	free_options(options);

	// free
	err = pe_unload(&ctx);
	if (err != LIBPE_E_OK) {
		pe_error_print(stderr, err);
		return EXIT_FAILURE;
	}

	return EXIT_SUCCESS;
}
예제 #3
0
파일: ai.hpp 프로젝트: mviljane/TiraLabra
 ~moveTree() {
     if (gameTree) {
         freeNodes(gameTree);
         delete gameTree;
     }
     if (moveList)
         delete moveList;
 }
예제 #4
0
파일: deque.c 프로젝트: jcarlosadm/classes
Node* freeNodes(Node* node){
    if(!node)
        return NULL;
    else{
        Node* current = node;
        node = node->nextNode;
        free(current);
        return freeNodes(node);
    }
}
예제 #5
0
/* Free memory of hash nodes (sinonimous) */
void freeNodes(pnode node)
{
  if (node == NULL)
    ;
  else
    {
      freeNodes(node->next);
      free(node);
    }
}
예제 #6
0
void freeNodes(node* thisNode)
{
    for (int i = 0; i < SIZE_OF_ALPHABET; i++)
    {
        if (thisNode->children[i] != NULL)
        {
            freeNodes(thisNode->children[i]);
        }
    }
    
    free(thisNode);
}
예제 #7
0
/*=============================================================*/
DIGITS* add(DIGITS *p, DIGITS *q){
	int sum, remainder, len;
	DIGITS *head, *big, *small;

	head = NULL;
	big = moveToEnd(p);
	small = moveToEnd(q);

	remainder = 0;
	len = 1;

	while (big != NULL){
		if (small != NULL){
			sum = big->digit + small->digit + remainder;
			small = small->prev;
		}
		else{
			sum = big->digit + remainder;
		}

		if (sum > 9){
			sum = 0;
			remainder = 1;
		}
		else{
			remainder = 0;
		}
		head = insertDigit(head, sum);
		big = big->prev;
	}

	if (remainder == 1){
		head = insertDigit(head, 1);
	}

	freeNodes(p);
	freeNodes(q);
	return head;
}
예제 #8
0
/* Free memory of the whole dictionary */
void freeDict(dict* d)
{
  int i;
  
  /* free all of the words in the dictionary */
  for(i=0; i<MAXENTRY; i++)
	{
      freeNodes(d->T[i]);
      d->T[i] = NULL;
	}
  
  /* free the dictionary */
  free(d); 
}
예제 #9
0
파일: fileUtil.c 프로젝트: jerryyeezus/u
int doCapServer( msg_t *rcvInfo, msg_t *sndInfo, int capSize ) {
    capInfo *capNodes = getAllowedFiles();
    capInfo *ptr = capNodes;

    int i = 0;
    int size = 0;
    capSize *= 1000000;
    while ( ptr != NULL )
    {
        if((size + ptr->size) < capSize) {
            strcpy(sndInfo->filenames[i++], ptr->name);
            size += ptr->size;
        }
        ptr = ptr->next;
    }

    freeNodes ( &capNodes );
    return i;
}
HuffmanNode *huffmanCompress(InStream *in, OutStream *out){
  HuffmanNode *returnedNewNode;
  HuffmanNode *NodeForCase = NULL;
  root = adaptiveHuffmanTreeInit();
  root->order = Symbol;
  uint32 Symb = 0;
  HuffmanNode *arraySymbol[Symbol];
  clearArraySymbol(arraySymbol);
  fflush(stdout);
  while(!feof(in->file)){
    Symb = streamReadBits(in);
    if(!arraySymbol[Symb]){
      if (!Symb){ //EOF, object file
        break;
      }
      if(!NodeForCase){ // First Unseen Symbol
        returnedNewNode = buildAndAddNewHuffmanTree(out,root,arraySymbol,Symb);
        fflush(out->file);
        NodeForCase = returnedNewNode;
      }
      else{ // Following Unseen Symbol
        returnedNewNode = buildAndAddNewHuffmanTree(out,returnedNewNode,arraySymbol,Symb);
        fflush(out->file);
      }
    }
    else{ // Symbol Seen before
      emitPathCode(out,arraySymbol[Symb]);
      huffmanUpdateAndRestructure(arraySymbol[Symb]);
      fflush(out->file);
    }
  }
  while (streamOut.bitIndex != 7){ //fill remaining with 0
    streamWriteBit(out , 0);
    fflush(out->file);
  }
  clearArraySymbol(arraySymbol);
  fflush(stdout);
  fflush(out->file);
  fflush(in->file);
  return returnedNewNode;
  freeNodes(root);
  root = NULL;
}
예제 #11
0
파일: main.c 프로젝트: frcoelho/pesti
int main(int argc, char *argv[])
{
        time_t     inicio, fim;
	double i;

	if (argc != 5) {
		printf("Usage: %s <CFG> <iterations> <error> <confidence>\n",
				argv[0]);
		exit(-1);
	}
	// Obtem o tempo corrente
	time(&inicio);

	puts("Loading CFG\n");
	loadCfg(argv[1]);
	//printf("no raiz: %s\n", start_block->info_node.id);

	for (i = start_range; i <= end_range; i += step) {
		
		if (start_range && end_range && step)
			setup(i);
		printf("Simulating CFG\n");
		runCfg(start_block, atoi(argv[2]), atof(argv[3]), atof(argv[4]), i);
		printf("Listing CFG\n");
		listNodes(start_block, i);
		if (!start_range || !end_range || !step)
			break;
	}
	freeNodes(start_block);

	time(&fim);

	printf("Tempo total de simulação: %11.3f segundo(s)\n", difftime(fim, inicio));

	return 0;
}
예제 #12
0
파일: adtree.c 프로젝트: amohtasham/rstm
/* =============================================================================
 * adtree_free
 * =============================================================================
 */
void
adtree_free (adtree_t* adtreePtr)
{
    freeNodes(adtreePtr->rootNodePtr);
    SEQ_FREE(adtreePtr);
}
예제 #13
0
파일: ai.hpp 프로젝트: mviljane/TiraLabra
 void freeNodes(tree< moveNode* > *ptr) {
     for (int i = 0; i < ptr->children->size; i++)
         freeNodes((*ptr->children)[i]);
     delete ptr->item;
 }
예제 #14
0
/* =============================================================================
 * adtree_free
 * =============================================================================
 */
void
adtree_free (adtree_t* adtreePtr)
{
    freeNodes(adtreePtr->rootNodePtr);
    free(adtreePtr);
}
예제 #15
0
/**
 * Unloads dictionary from memory.  Returns true if successful else false.
 */
bool unload(void)
{
    freeNodes(root);
    
    return true;
}
예제 #16
0
파일: peres.c 프로젝트: neriberto/pev
static NODE_PERES * discoveryNodesPeres(pe_ctx_t *ctx)
{
#ifdef LIBPE_ENABLE_OUTPUT_COMPAT_WITH_V06
	typedef struct {
		ImageDirectoryEntry entry;
		const char * const name;
	} ImageDirectoryEntryName;
	static const ImageDirectoryEntryName directoryEntryNames[] = {
		{ IMAGE_DIRECTORY_ENTRY_EXPORT,			"Export Table"				}, // "Export directory",
		{ IMAGE_DIRECTORY_ENTRY_IMPORT,			"Import Table"				}, // "Import directory",
		{ IMAGE_DIRECTORY_ENTRY_RESOURCE,		"Resource Table"			}, // "Resource directory",
		{ IMAGE_DIRECTORY_ENTRY_EXCEPTION,		"Exception Table"			}, // "Exception directory",
		{ IMAGE_DIRECTORY_ENTRY_SECURITY,		"Certificate Table"			}, // "Security directory",
		{ IMAGE_DIRECTORY_ENTRY_BASERELOC,		"Base Relocation Table"		}, // "Base relocation table",
		{ IMAGE_DIRECTORY_ENTRY_DEBUG,			"Debug"						}, // "Debug directory",
		{ IMAGE_DIRECTORY_ENTRY_ARCHITECTURE,	"Architecture"				}, // "Architecture-specific data",
		{ IMAGE_DIRECTORY_ENTRY_GLOBALPTR,		"Global Ptr"				}, // "Global pointer",
		{ IMAGE_DIRECTORY_ENTRY_TLS,			"Thread Local Storage (TLS)"}, // "Thread local storage (TLS) directory",
		{ IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG,	"Load Config Table"			}, // "Load configuration directory",
		{ IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT,	"Bound Import"				}, // "Bound import directory",
		{ IMAGE_DIRECTORY_ENTRY_IAT,			"Import Address Table (IAT)"}, // "Import address table (IAT)",
		{ IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT,	"Delay Import Descriptor"	}, // "Delay import table",
		{ IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR,	"CLR Runtime Header"		}, // "COM descriptor table"
		{ IMAGE_DIRECTORY_RESERVED,				""							}  // "Reserved"
	};
	//static const size_t max_directory_entry = LIBPE_SIZEOF_ARRAY(names);
#endif

	const IMAGE_DATA_DIRECTORY * const resourceDirectory = pe_directory_by_entry(ctx, IMAGE_DIRECTORY_ENTRY_RESOURCE);
	if (resourceDirectory == NULL || resourceDirectory->Size == 0)
		return NULL;

	uint64_t resourceDirOffset = pe_rva2ofs(ctx, resourceDirectory->VirtualAddress);
	char s[MAX_MSG];

	if (resourceDirectory->Size != 0) {
		snprintf(s, MAX_MSG, "%#x (%d bytes)",
				resourceDirectory->VirtualAddress,
				resourceDirectory->Size);

#ifdef LIBPE_ENABLE_OUTPUT_COMPAT_WITH_V06
		output(directory_names[IMAGE_DIRECTORY_ENTRY_RESOURCE], s); // Resource table
#else
		output(pe_directory_name(IMAGE_DIRECTORY_ENTRY_RESOURCE), s); // Resource table
#endif
		//printf("Offset by RVA: 0x%x\n\n", resourceDirOffset);
	}

	uintptr_t offset = resourceDirOffset;
	void *ptr = LIBPE_PTR_ADD(ctx->map_addr, offset);
	if (LIBPE_IS_PAST_THE_END(ctx, ptr, sizeof(IMAGE_RESOURCE_DIRECTORY))) {
		// TODO: Should we report something?
		return NULL;
	}

	NODE_PERES *node = malloc_s(sizeof(NODE_PERES));
	node->lastNode = NULL; // root
	node->nodeType = RDT_RESOURCE_DIRECTORY;
	node->nodeLevel = RDT_LEVEL1;
	node->resource.resourceDirectory = ptr;
	//showNode(node);

	for (int i = 1, offsetDirectory1 = 0; i <= (lastNodeByTypeAndLevel(node, RDT_RESOURCE_DIRECTORY, RDT_LEVEL1)->resource.resourceDirectory->NumberOfNamedEntries +
												lastNodeByTypeAndLevel(node, RDT_RESOURCE_DIRECTORY, RDT_LEVEL1)->resource.resourceDirectory->NumberOfIdEntries); i++)
	{
		offsetDirectory1 += (i == 1) ? 16 : 8;
		offset = resourceDirOffset + offsetDirectory1;
		ptr = LIBPE_PTR_ADD(ctx->map_addr, offset);
		if (LIBPE_IS_PAST_THE_END(ctx, ptr, sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY))) {
			// TODO: Should we report something?
			goto _error;
		}

		node = createNode(node, RDT_DIRECTORY_ENTRY);
		NODE_PERES *rootNode = node;
		node->rootNode = rootNode;
		node->nodeLevel = RDT_LEVEL1;
		node->resource.directoryEntry = ptr;
		//showNode(node);

		const NODE_PERES * lastDirectoryEntryNodeAtLevel1 = lastNodeByTypeAndLevel(node, RDT_DIRECTORY_ENTRY, RDT_LEVEL1);

		if (lastDirectoryEntryNodeAtLevel1->resource.directoryEntry->DirectoryData.data.DataIsDirectory)
		{
			offset = resourceDirOffset + lastDirectoryEntryNodeAtLevel1->resource.directoryEntry->DirectoryData.data.OffsetToDirectory;
			ptr = LIBPE_PTR_ADD(ctx->map_addr, offset);
			if (LIBPE_IS_PAST_THE_END(ctx, ptr, sizeof(IMAGE_RESOURCE_DIRECTORY))) {
				// TODO: Should we report something?
				goto _error;
			}

			node = createNode(node, RDT_RESOURCE_DIRECTORY);
			node->rootNode = (NODE_PERES *)lastDirectoryEntryNodeAtLevel1;
			node->nodeLevel = RDT_LEVEL2;
			node->resource.resourceDirectory = ptr;
			//showNode(node);

			for (int j = 1, offsetDirectory2 = 0; j <= (lastNodeByTypeAndLevel(node, RDT_RESOURCE_DIRECTORY, RDT_LEVEL2)->resource.resourceDirectory->NumberOfNamedEntries +
					lastNodeByTypeAndLevel(node, RDT_RESOURCE_DIRECTORY, RDT_LEVEL2)->resource.resourceDirectory->NumberOfIdEntries); j++)
			{
				offsetDirectory2 += (j == 1) ? 16 : 8;
				offset = resourceDirOffset + lastNodeByTypeAndLevel(node, RDT_DIRECTORY_ENTRY, RDT_LEVEL1)->resource.directoryEntry->DirectoryData.data.OffsetToDirectory + offsetDirectory2;
				ptr = LIBPE_PTR_ADD(ctx->map_addr, offset);
				if (LIBPE_IS_PAST_THE_END(ctx, ptr, sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY))) {
					// TODO: Should we report something?
					goto _error;
				}

				node = createNode(node, RDT_DIRECTORY_ENTRY);
				node->rootNode = rootNode;
				node->nodeLevel = RDT_LEVEL2;
				node->resource.directoryEntry = ptr;
				//showNode(node);

				offset = resourceDirOffset + node->resource.directoryEntry->DirectoryData.data.OffsetToDirectory; // posiciona em 0x72
				ptr = LIBPE_PTR_ADD(ctx->map_addr, offset);
				if (LIBPE_IS_PAST_THE_END(ctx, ptr, sizeof(IMAGE_RESOURCE_DIRECTORY))) {
					// TODO: Should we report something?
					goto _error;
				}

				node = createNode(node, RDT_RESOURCE_DIRECTORY);
				node->rootNode = rootNode;
				node->nodeLevel = RDT_LEVEL3;
				node->resource.resourceDirectory = ptr;
				//showNode(node);

				offset += sizeof(IMAGE_RESOURCE_DIRECTORY);

				for (int y = 1; y <= (lastNodeByTypeAndLevel(node, RDT_RESOURCE_DIRECTORY, RDT_LEVEL3)->resource.resourceDirectory->NumberOfNamedEntries +
									lastNodeByTypeAndLevel(node, RDT_RESOURCE_DIRECTORY, RDT_LEVEL3)->resource.resourceDirectory->NumberOfIdEntries); y++)
				{
					ptr = LIBPE_PTR_ADD(ctx->map_addr, offset);
					if (LIBPE_IS_PAST_THE_END(ctx, ptr, sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY))) {
						// TODO: Should we report something?
						goto _error;
					}
					node = createNode(node, RDT_DIRECTORY_ENTRY);
					node->rootNode = rootNode;
					node->nodeLevel = RDT_LEVEL3;
					node->resource.directoryEntry = ptr;
					//showNode(node);

					offset = resourceDirOffset + node->resource.directoryEntry->DirectoryName.name.NameOffset;
					ptr = LIBPE_PTR_ADD(ctx->map_addr, offset);
					if (LIBPE_IS_PAST_THE_END(ctx, ptr, sizeof(IMAGE_RESOURCE_DATA_STRING))) {
						// TODO: Should we report something?
						goto _error;
					}
					node = createNode(node, RDT_DATA_STRING);
					node->rootNode = rootNode;
					node->nodeLevel = RDT_LEVEL3;
					node->resource.dataString = ptr;
					//showNode(node);

					offset = resourceDirOffset + node->lastNode->resource.directoryEntry->DirectoryData.data.OffsetToDirectory;
					ptr = LIBPE_PTR_ADD(ctx->map_addr, offset);
					if (LIBPE_IS_PAST_THE_END(ctx, ptr, sizeof(IMAGE_RESOURCE_DATA_ENTRY))) {
						// TODO: Should we report something?
						goto _error;
					}
					node = createNode(node, RDT_DATA_ENTRY);
					node->rootNode = rootNode;
					node->nodeLevel = RDT_LEVEL3;
					node->resource.dataEntry = ptr;
					//showNode(node);

					offset += sizeof(IMAGE_RESOURCE_DATA_ENTRY);
				}
			}
		}
	}

	return node;

_error:
	if (node != NULL)
		freeNodes(node);
	return NULL;
}
예제 #17
0
파일: deque.c 프로젝트: jcarlosadm/classes
Deque* DEQUE_free(Deque* deque){
    deque->first = freeNodes(deque->first);
    deque->end = NULL;
    free(deque);
    return NULL;
}
예제 #18
0
파일: bounce.c 프로젝트: klutt/hpc_ass2
int main(int argc, char *argv[]) 
{
	int i, N=2500;
	const float L=1,W=1,dt=1e-6;
	G=2.0/N;
	double *x,*y,*mass,*forceX,*forceY,*u,*v,ax,ay;
	const int frameskip=100;
	int frame=frameskip-1;
	const double initSpeedLimit=0.001;
	const float theta = 0.8;
	x = (double *)malloc(N*sizeof(double));
	y = (double *)malloc(N*sizeof(double));
	u = (double *)malloc(N*sizeof(double));
	v = (double *)malloc(N*sizeof(double));
	mass = (double *)malloc(N*sizeof(double));
	forceX = (double *)malloc(N*sizeof(double));
	forceY = (double *)malloc(N*sizeof(double));
	#ifndef DISTRIBUTION_AS_IN_ASSIGNMENT
  	for(i=0;i<N;i++) 
  	{
		x[i]=frand(0,1);
		y[i]=frand(.25,.75);
		relativePosition(&u[i], &v[i], 0, 0, x[i], y[i]);
		u[i]*=frand(-initSpeedLimit,initSpeedLimit);
		v[i]*=frand(-initSpeedLimit,initSpeedLimit);
		mass[i]=frand(1, 100);
		forceX[i]=0;
		forceY[i]=0;
  	}
  
	  x[0]=x[1]=0.5;
	  y[0]=0.45; y[1]=0.55;
	  v[0]=v[1]=0;
	  u[0]=-0.007;
	  u[1]=0.007;
	  mass[0]=mass[1]=1000;
	  #endif
	 #ifdef DISTRIBUTION_AS_IN_ASSIGNMENT

	const double alpha=0.25;
	const double V=20.0;
	for(i = 0; i<N; i++)
	  {
	    mass[i]=1;
	    double R=frand(0, L/4.0);
	    double fi=frand(0, 2*3.1415);
	    x[i]=L/2.0+R*cos(fi);
	    y[i]=W/2.0+alpha*R*sin(fi);
	    double Rprim = sqrt((x[i]-L/2.0)*(x[i]-L/2.0) + (y[i]-W/2.0)*(y[i]-W/2.0));
	    u[i] = -V*Rprim*sin(fi);
	    v[i] = V*Rprim*cos(fi);
	    forceX[i]=0;
	    forceY[i]=0;
	  }
	#endif
	
	  InitializeGraphics(argv[0],windowWidth,windowWidth);
	  SetCAxes(0,1);
	  Node *root;
	  printf("Hit q to quit.\n");
	  int iterations=0;
  	while(!CheckForQuit()) 
  	{
	  iterations++;
  		#ifndef BARNESHUT
  		for(i=0;i<N;i++) {
  		#endif
  		
  	
  		#ifdef BARNESHUT
		  //  		Bounce(&x[0],&y[0],&u[0],&v[0],L,W); 
  		root = createNode(0,x,y,mass);
		for(i=1;i<N;i++) {
		#endif
			if (x[i] > 2*L || x[i]< -1 || y[i] > 2*W || y[i] < -1)
			{
				printf("Things are going out of bounds");
				exit(-1);
			}
			//			Bounce(&x[i],&y[i],&u[i],&v[i],L,W); 
			#ifndef BARNESHUT
				calculateForce(&forceX[i], &forceY[i], i, x, y, mass, N);
			#endif
			#ifdef BARNESHUT
				insertParticle(root, x, y, mass, i);	
			#endif
		}
		#ifdef BARNESHUT
	  		for(i=0; i<N; i++)
				BarnesHut(root, x, y, mass, theta, i, &forceX[i], &forceY[i]);
		#endif
  		update(x,y,u,v,mass,forceX, forceY,dt, N);
		frame++;
		frame=frame%frameskip;
		if(frame==0) {
		  ClearScreen();  
		  for(i=0;i<N;i++)
		    DrawCircle(x[i],y[i],L,W,(1+log10(mass[i]))*circleRadius,circleColor);
		  Refresh();
		}
		freeNodes(root);
	}
	XFlush(display);
	XCloseDisplay(display);
	printf("Iterations: %d\n", iterations);
	return 0;
}

/*
 * Function: Bounce
 * Usage: Bounce(&x[i],&y[i],&u[i],&v[i],L,W);
 * -------------------------------------------
 * If a particle moves beyond any of the boundaries then set
 * it on the other side of the boundary back in the domain and
 * reverse the velocities.
 *
 */
void Bounce(double *x, double *y, double *u, double *v, double L, double W) {
  if(*x>L ) {
    *x=2*L-*x;
    *u=-*u;
  }

  if(*x<0 ) {
    *x=-*x;
    *u=-*u;
  }

  if(*y>W ) {
    *y=2*W-*y;
    *v=-*v;
  }

  if(*y<0 ) {
    *y=-*y;
    *v=-*v;
  }
}