예제 #1
0
파일: scoreSTOP.c 프로젝트: WenchaoLin/JAMg
/* convert the acgt sequence into a sequence of 0123 -- integers */
int *basetoint(char sequence[], long length)
{
  int *intarray;
  long i;
  
  intarray = (int *) malloc((length+1)*sizeof(int));
  MemCheck(intarray,"intarray");

  for(i = 0; i < length; i++) {
    switch(sequence[i]) {
    case 'a':
      intarray[i] = 0;
      break;
    case 'c':
      intarray[i] = 1;
      break;
    case 'g':
      intarray[i] = 2;
      break;
    case 't':
      intarray[i] = 3;
      break;
    default:
      fprintf(stderr,
	      "non-acgt character in string (position %ld)\n",
	      i);
      intarray[i] = -1;
      break;
    }
  }

  return intarray;
}
예제 #2
0
파일: flsupport.cpp 프로젝트: Angeldude/pd
FLEXT_TEMPIMPL(void FLEXT_CLASSDEF(flext_root))::operator delete(void *blk)
{
    if(!blk) return;

    FLEXT_ASSERT(MemCheck(blk));

#ifdef FLEXT_DEBUGMEM
	char *ori = (char *)blk-sizeof(size_t)-sizeof(memtest);
#else
    char *ori = (char *)blk-sizeof(size_t);
#endif
	size_t bytes = *(size_t *)ori;

    if(UNLIKELY(bytes >= LARGEALLOC)) {
#if FLEXT_SYS == FLEXT_SYS_MAX && defined(_SYSMEM_H_)
        sysmem_freeptr(ori);
#else
        // use C library function for large memory blocks
        free(ori);
#endif
    }
    else {
	    //! We need system locking here for secondary threads!
        SYSLOCK();
	    freebytes(ori,bytes);
        SYSUNLOCK();
    }
}
예제 #3
0
파일: FORM.C 프로젝트: LesInk/Test
T_void FormCleanUp(T_void)
{
    T_word16 i;
    T_formObjectStruct *p_object;
    E_Boolean UScrewedUpSomewhere = FALSE;

    DebugRoutine("FormCleanUp");

    /* update the graphics */
    GraphicUpdateAllGraphics();

    /* loop through all objects, deleting structures if available */
    for (i = 0; i < MAX_FORM_OBJECTS; i++) {
        if (G_formObjectArray[i] != NULL ) {
            p_object = (T_formObjectStruct *)G_formObjectArray[i];
            /* first delete the object (button, textfield, ect) */
            DebugCheck(p_object != NULL);
            switch (p_object->objtype) {
                case FORM_OBJECT_BUTTON:
                    ButtonDelete((T_buttonID)p_object->objID);
                    break;
                case FORM_OBJECT_TEXT:
                    TextDelete((T_textID)p_object->objID);
                    break;
                case FORM_OBJECT_GRAPHIC:
                    GraphicDelete((T_graphicID)p_object->objID);
                    break;
                case FORM_OBJECT_TEXTFIELD:
                    TxtfldDelete((T_TxtfldID)p_object->objID);
                    break;
                case FORM_OBJECT_TEXTBOX:
                    TxtboxDelete((T_TxtboxID)p_object->objID);
                    break;
                case FORM_OBJECT_SLIDER:
                    SliderDelete((T_sliderID)p_object->objID);
                    break;
                default:
                    /* something is wrong! */
                    DebugCheck(UScrewedUpSomewhere==TRUE);
                    break;
            }

            /* now delete the object structure */
            MemFree(G_formObjectArray[i]);
            MemCheck(101);
            G_formObjectArray[i] = NULL;
        }
    }

    G_formHasTextBoxes = FALSE;
    G_formHasButtons = FALSE;
    DebugEnd();
}
예제 #4
0
ARSE_API void HandleException(SAppBase* pAppBase, const std::string& message, const std::vector<std::string>& callstack)
{
#ifdef USE_MEMCHECK
	MemCheck().clear();
#endif

	std::string lastFile;
	try
	{
		lastFile = *pAppBase->filesystem().lastOpen();

		if (!callstack.empty())
		{
			dlog << join(callstack, " <- ") << dlog.endl;
			derr << "FATAL EXCEPTION: \n\n" << join(callstack, " <- ") << dlog.endl;
		}
	}
	catch(...)
	{
	}

	try
	{
		if (!pAppBase || !pAppBase->validForDisplay())
			throw message;

		// try fancy exception catch
		pAppBase->onException(callstack, message + "\n\nLast file opened: " + lastFile);
		pAppBase->run();
		delete pAppBase;
	}
	catch (...)
	{
		// last-ditch exception catch (exception during fancy exception)
		try
		{
			alertf("%s\r%s\rLast file opened: %s", join(callstack, " <- ").c_str(), message.c_str(), lastFile.c_str());
			if (pAppBase)
				DestroyWindow(pAppBase->hWnd());
		}
		catch (...)
		{
			MessageBox(0, message.c_str(), "ARSE Fatal Error", 0);
		}
	}
}
예제 #5
0
파일: SLIDR.C 프로젝트: LesInk/Test
T_void SliderCleanUp (T_void)
{
	T_word16 i;
	T_sliderStruct *p_slider;

	DebugRoutine ("SliderCleanUp");

	for (i=0;i<MAX_SLIDERS;i++)
	if (G_sliderArray[i]!=NULL)
	{
      p_slider = (T_sliderStruct *)G_sliderArray[i];
      GraphicDelete (p_slider->knobgraphic);
      MemFree (G_sliderArray[i]);
      MemCheck (601);
      G_sliderArray[i]=NULL;
	}
	DebugEnd();
}
예제 #6
0
파일: SLIDR.C 프로젝트: LesInk/Test
T_void SliderDelete (T_sliderID sliderID)
{
	T_word16 i;
	T_sliderStruct *p_slider;

	DebugRoutine ("SliderDelete");
	if (sliderID!=NULL)
	{
		for (i=0;i<MAX_SLIDERS;i++)
		{
			if (G_sliderArray[i]==sliderID) //found it, now kill it
			{
            p_slider=(T_sliderStruct *)sliderID;
            GraphicDelete (p_slider->knobgraphic);
				MemFree (G_sliderArray[i]);
            MemCheck (600);
            G_sliderArray[i]=NULL;
				break;
			}
		}
	}

	DebugEnd();
}
예제 #7
0
	void OSCheckMemDebug(void *pvCpuVAddr, u32 uSize,
			     const char *pszFileName, const u32 uLine) {
		OSMEM_DEBUG_INFO const *psInfo =
		    (OSMEM_DEBUG_INFO *) ((u32) pvCpuVAddr -
					  TEST_BUFFER_PADDING_STATUS);

		if (pvCpuVAddr == NULL) {
			PVR_DPF((PVR_DBG_ERROR, "Pointer 0x%X : null pointer"
				 " - referenced %s:%d - allocated %s:%d",
				 pvCpuVAddr,
				 pszFileName, uLine,
				 psInfo->sFileName, psInfo->uLineNo));
			while (STOP_ON_ERROR) ;
		}

		if (((u32) pvCpuVAddr & 3) != 0) {
			PVR_DPF((PVR_DBG_ERROR,
				 "Pointer 0x%X : invalid alignment"
				 " - referenced %s:%d - allocated %s:%d",
				 pvCpuVAddr, pszFileName, uLine,
				 psInfo->sFileName, psInfo->uLineNo));
			while (STOP_ON_ERROR) ;
		}

		if (!MemCheck
		    ((void *)psInfo->sGuardRegionBefore, 0xB1,
		     sizeof(psInfo->sGuardRegionBefore))) {
			PVR_DPF((PVR_DBG_ERROR,
				 "Pointer 0x%X : guard region before overwritten"
				 " - referenced %s:%d - allocated %s:%d",
				 pvCpuVAddr, pszFileName, uLine,
				 psInfo->sFileName, psInfo->uLineNo));
			while (STOP_ON_ERROR) ;
		}

		if (uSize != psInfo->uSize) {
			PVR_DPF((PVR_DBG_WARNING,
				 "Pointer 0x%X : supplied size was different to stored size (0x%X != 0x%X)"
				 " - referenced %s:%d - allocated %s:%d",
				 pvCpuVAddr, uSize, psInfo->uSize, pszFileName,
				 uLine, psInfo->sFileName, psInfo->uLineNo));
			while (STOP_ON_ERROR) ;
		}

		if ((0x01234567 ^ psInfo->uSizeParityCheck) != psInfo->uSize) {
			PVR_DPF((PVR_DBG_WARNING,
				 "Pointer 0x%X : stored size parity error (0x%X != 0x%X)"
				 " - referenced %s:%d - allocated %s:%d",
				 pvCpuVAddr, psInfo->uSize,
				 0x01234567 ^ psInfo->uSizeParityCheck,
				 pszFileName, uLine, psInfo->sFileName,
				 psInfo->uLineNo));
			while (STOP_ON_ERROR) ;
		} else {

			uSize = psInfo->uSize;
		}

		if (uSize) {
			if (!MemCheck
			    ((void *)((u32) pvCpuVAddr + uSize), 0xB2,
			     TEST_BUFFER_PADDING_AFTER)) {
				PVR_DPF((PVR_DBG_ERROR,
					 "Pointer 0x%X : guard region after overwritten"
					 " - referenced from %s:%d - allocated from %s:%d",
					 pvCpuVAddr, pszFileName, uLine,
					 psInfo->sFileName, psInfo->uLineNo));
			}
		}

		if (psInfo->eValid != isAllocated) {
			PVR_DPF((PVR_DBG_ERROR,
				 "Pointer 0x%X : not allocated (freed? %d)"
				 " - referenced %s:%d - freed %s:%d",
				 pvCpuVAddr, psInfo->eValid == isFree,
				 pszFileName, uLine, psInfo->sFileName,
				 psInfo->uLineNo));
			while (STOP_ON_ERROR) ;
		}
	}
예제 #8
0
/**
 *  MemDumpDiscarded is for debugging purposes only (and only will
 *  be compiled in debug mode).  It will output a list of blocks to the
 *  file "debugmem.txt".
 *
 *  NOTE: 
 *  None really.
 *
 *<!-----------------------------------------------------------------------*/
T_void MemDumpDiscarded(T_void)
{
#ifndef REAL_MODE
    FILE *fp ;
    T_memBlockHeader *p_header ;
//extern T_word32 G_packetsAlloc ;
//extern T_word32 G_packetsFree ;
struct _heapinfo h_info ;
int heap_status ;
    T_word32 totalUsed = 0 ;
    T_word32 totalFree = 0 ;

    DebugRoutine("MemDumpDiscarded") ;

printf("Dumping discard info!\n") ;
fflush(stdout) ;
MemCheck(991) ;
    fp = fopen("debugmem.txt", "w") ;
//fp = stdout ;
    DebugCheck(fp != NULL) ;

    fprintf(fp, "\n\nList of discarded memory:\n") ;
    fprintf(fp,     "-------------------------\n") ;
    p_header = P_startOfDiscardList ;
    fprintf(fp, "##### tag next: prev: callback?\n") ;
    fflush(fp) ;
    fprintf(fp, "start: %p  end: %p\n", P_startOfDiscardList, P_endOfDiscardList) ;
    fprintf(fp, "Start: %5d\n",
        (P_startOfDiscardList == NULL)?0:
            P_startOfDiscardList->blockId) ;
    fflush(fp) ;
    fprintf(fp, "  End: %5d\n",
        (P_endOfDiscardList == NULL)?0:
            P_endOfDiscardList->blockId) ;
    fprintf(fp, "\n\n") ;
    fflush(fp) ;

    while (p_header != NULL)  {
        fprintf(fp, "p_header = %p\n", p_header) ;
        fflush(fp) ;
        fprintf(fp, "%5d %s %5d %5d %c %s\n",
            p_header->blockId,
            p_header->blockTag,
            (p_header->p_nextBlock==NULL)?0:
                p_header->p_nextBlock->blockId,
            (p_header->p_prevBlock==NULL)?0:
                p_header->p_prevBlock->blockId,
            (p_header->p_callback == NULL)?'N':'Y',
#ifdef _MEM_RECORD_ROUTINES_
                p_header->routine) ;
#else
                "") ; //            p_header->routine) ;
#endif
        p_header = p_header->p_nextBlock ;
        fflush(fp) ;
    }
    fprintf(fp, "%d blocks allocated\n", G_allocCount-1) ;
    fprintf(fp, "%d blocks freed\n\n", G_deallocCount) ;
    fprintf(fp, "%d free memory\n", FreeMemory()) ;
    fflush(fp) ;
//    fprintf(fp, "%d packets alloc\n", G_packetsAlloc) ;
//    fprintf(fp, "%d packets free\n", G_packetsFree) ;

fprintf(fp, "\n\nHeap walk:\n\n") ;
h_info._pentry = NULL ;
for(;;)  {
  heap_status = _heapwalk(&h_info) ;
  if (heap_status != _HEAPOK)
    break ;
  fprintf(fp, "  %s %Fp %8.8X\n",
    (h_info._useflag == _USEDENTRY?"USED":"FREE"),
    h_info._pentry, h_info._size) ;
  if (h_info._useflag == _USEDENTRY)
      totalUsed += h_info._size ;
  else
      totalFree += h_info._size ;
}
fprintf(fp, "  heap status: %d\n", heap_status) ;
fprintf(fp, "  Total used: %ld bytes\n", totalUsed) ;
fprintf(fp, "  Total free: %ld bytes\n", totalFree) ;

    fflush(fp) ;
    fclose(fp) ;

    DebugEnd() ;
#endif
}
예제 #9
0
/**
 *  FindFreeSpace is the routine called by MemAlloc when it just tried
 *  to allocate new memory and could not.  This routine is called to free
 *  up space use by discarded memory.  If there is memory freed up, this
 *  routine returns with a TRUE, otherwise FALSE.  It does this by looking
 *  at the discard list and freeing up the oldest block.  It will only
 *  discard one block and then return with a TRUE status.
 *  Also, before the block is freed, it's callback routine is called
 *  to note the block's disappearance.
 *
 *  NOTE: 
 *  A future version might want to free up a certain amount of space
 *  instead of being called several times.  However, when you are running
 *  out of memory, this method is probably just as good.
 *
 *  @return TRUE = memory was freed
 *      FALSE = no more memory can be freed.
 *
 *<!-----------------------------------------------------------------------*/
static E_Boolean IMemFindFreeSpace(T_void)
{
    E_Boolean answer = FALSE ;
    T_memBlockHeader *p_header ;
    T_word16 pos ;

    DebugRoutine("IMemFindFreeSpace") ;

//printf("Finding free space!\n") ;
//fprintf(stderr, "Finding free space!") ;
MemCheck(2925) ;
//MemDumpDiscarded() ;
//_heapmin() ;

/*
printf("List:\n") ;
p_header = P_startOfDiscardList ;
while (p_header)  {
    printf("  %p\n", ((T_byte8 *)p_header)+sizeof(T_memBlockHeader)) ;
    p_header = p_header->p_nextBlock ;
}
printf("End of list\n\n") ;
*/
    /* Do we have any blocks on the discard list? */
    if (P_startOfDiscardList != NULL)  {
        /* Yes, call it's callback routine -- it is about to be */
        /* freed from memory.  Make sure to pass a pointer to the */
        /* true data part (past header) of the memory block. */
        p_header = P_startOfDiscardList ;

        /* Make sure you are freeing a discarded block. */
        DebugCheck(strcmp(p_header->blockTag, "DaG") == 0) ;

//printf("Discard %p\n", (((T_byte8 *)p_header)+sizeof(T_memBlockHeader))) ;
        p_header->p_callback(((T_byte8 *)p_header)+sizeof(T_memBlockHeader)) ;

        /* Make sure you are freeing a discarded block. */
        DebugCheck(strcmp(p_header->blockTag, "DaG") == 0) ;

        /* Now that the block's owner has been notified, we */
        /* can continue. */

        /* We first need to note the previous block that the next block */
        /* is disappearing. */
#if 0
        if (p_header->p_nextBlock != NULL)  {
            p_header->p_nextBlock->p_prevBlock = NULL ;

            /* If there is a previous block, make it the new end. */
            P_startOfDiscardList = p_header->p_nextBlock ;
        } else {
            /* If there is no previous block, the list is now empty. */
            P_endOfDiscardList =
                P_startOfDiscardList = NULL ;
        }
#endif
        P_startOfDiscardList = p_header->p_nextBlock ;
        if (P_startOfDiscardList == NULL)
            P_endOfDiscardList = NULL ;
        else
            p_header->p_nextBlock->p_prevBlock = NULL ;

        /* Note that the total is now less. */
        G_sizeAllocated -= sizeof(T_memBlockHeader) + p_header->size ;
#ifdef COMPILE_OPTION_OUTPUT_ALLOCATION
printf("!F %d %s\n", p_header->size, DebugGetCallerFile()) ;
printf("!F %d %s:%s\n", p_header->size, DebugGetCallerFile(), DebugGetCallerName()) ;
#endif

#ifndef NDEBUG
        /* Make sure we didn't roll under. */
        DebugCheck(G_sizeAllocated < 0xF0000000) ;
#endif

#ifdef _MEM_CHECK_FULL_
        /* Find the block on the list (if it is there). */
        pos = IFindPointer(p_header) ;

        if (pos == 0xFFFF)  {
            printf("bad attempt to free memory at %p\n", p_header+1) ;
            DebugCheck(FALSE) ;
        }
        /* Remove the block from the alloc list and put on the free list. */
        G_blockList[pos] = ((T_memBlockHeader *)((T_word32)G_firstFree)) ;

        G_firstFree = pos ;
#endif
#ifndef NDEBUG
        /* Mark the block as fully freed. */
        strcpy(p_header->blockTag, "!!!") ;

        /* Fill the block with junk. */
        memset(((T_byte8 *)p_header)+sizeof(T_memBlockHeader), 0xCE, p_header->size) ;
#endif
#ifndef NDEBUG
    memset(p_header, 0xCD, sizeof(T_memBlockHeader) + p_header->size) ;
#endif
        /* Ok, now we can actually free the block. */
        free(p_header) ;

        /* Note that memory *was* freed. */
        answer = TRUE ;
    }

    DebugCheck(answer < BOOLEAN_UNKNOWN) ;
    DebugEnd() ;
    return answer ;
}
예제 #10
0
/**
 *  MemFree frees a block of memory that was previously allocated.
 *  It also checks the integrity of the pointer given to it.  If the
 *  pointer is NULL, it crashes.  If the pointer does not point to a
 *  block that was allocated, it crashes.
 *
 *  NOTE: 
 *  None that I can think of (except this will definitely slow down
 *  the system a little).
 *
 *  @param p_data -- Pointer to block to free
 *      Normally we can assume p_data points to data and is not NULL.
 *
 *<!-----------------------------------------------------------------------*/
T_void MemFree(T_void *p_data)
{
    T_byte8 *p_bytes ;
    T_memBlockHeader *p_header ;
    T_word16 pos ;

    DebugRoutine("MemFree") ;
    DebugCheck(p_data != NULL) ;

    /* Back up from the pointer we are given and try to find the
       header tag. */
    p_bytes = p_data ;
    p_bytes -= sizeof(T_memBlockHeader) ;

    p_header = (T_memBlockHeader *)p_bytes ;
//printf("Freeing %p, ID: %d, for %s\n", p_data, p_header->blockId, DebugGetCallerName()) ;

//printf("free ID: %ld, @ %p, %s\n", p_header->blockId, p_data, DebugGetCallerName()) ;
//fflush(stdout) ;
#ifdef _MEM_CHECK_FULL_
    MemCheck(10210) ;
    /* Find the block on the list (if it is there). */
    pos = IFindPointer(p_header) ;

    if (pos == 0xFFFF)  {
        printf("bad attempt to free memory at %p\n", p_data) ;
        DebugCheck(FALSE) ;
    }
    /* Remove the block from the alloc list and put on the free list. */
    G_blockList[pos] = ((T_memBlockHeader *)((T_word32)G_firstFree)) ;

    G_firstFree = pos ;
#endif

//printf("MemFree: %s (%p)\n", ((T_memBlockHeader *)p_bytes)->blockTag, p_data) ;
    /* Make sure we are freeing one of our blocks. */
    DebugCheck(strcmp (((T_memBlockHeader *)p_bytes)->blockTag, "DaG") != 0) ;
    DebugCheck(strcmp (((T_memBlockHeader *)p_bytes)->blockTag, "TaG") == 0) ;

    /* Check if the tag is there, or bomb. */
    DebugCheck(strcmp(((T_memBlockHeader *)p_bytes)->blockTag, "TaG") == 0) ;
    strcpy(((T_memBlockHeader *)p_bytes)->blockTag, "!!!");

//#ifndef NDEBUG
    /* Note that the total is now less. */
    G_sizeAllocated -= sizeof(T_memBlockHeader) + p_header->size ;
#ifdef COMPILE_OPTION_OUTPUT_ALLOCATION
printf("!F %d %s (@0x%08X)\n", p_header->size, DebugGetCallerFile(), p_bytes) ;
printf("!F %d %s:%s\n", p_header->size, DebugGetCallerFile(), DebugGetCallerName()) ;
#endif

#ifndef NDEBUG
    /* Make sure we didn't roll under. */
    DebugCheck(G_sizeAllocated < 0xF0000000) ;
#endif
#ifndef NDEBUG
    memset(p_bytes, 0xCD, sizeof(T_memBlockHeader) + p_header->size) ;
#endif
    /* OK, free up the valid block. */
    free(p_bytes) ;
//puts("OK") ;
//printf("FREE: %d   \r", FreeMemory()) ;
//fflush(stdout) ;

    /* Cound how many are freed. */
    G_deallocCount++ ;

    DebugEnd() ;
}
예제 #11
0
파일: karlin.c 프로젝트: WenchaoLin/JAMg
void split(tree *t, char *Inname,char *Outname)
{
   FILE  *Infile, *NextInfile1, *NextInfile2, *Outfile;
   char  *S, *T ,*Copy;
   int *B;
   int i, j, k, N, N1, N2, maxi, tempnofile ;
   int String_Len;
   char Outname1[20], Outname2[20];
   double max, Sum;
   fpos_t pos;
   
   Infile = fopen (Inname, "r");
   if  (Infile == NULL)
       {
        fprintf (stderr, "ERROR:  Unable to open file %s\n", Inname);
        exit (EXIT_FAILURE);
       }

   String_Len = 1 + Stop_Position - Start_Position;  

   /* initialize frequencies for consensus */
   for(i=0;i<String_Len;i++)
      	for(j=0;j<4;j++)
      		V[i][j]=0;

   T = (char *) malloc((MAX_STRING_LEN+1)*sizeof(char));
   MemCheck(T,"T");
   S = (char *) malloc((MAX_STRING_LEN+1)*sizeof(char));
   MemCheck(S,"S");

   N = 0;
   while  (fgets (T, MAX_STRING_LEN, Infile) != NULL)
     {
      sscanf (T, "%*s %s", S);
      assert (strlen (S) == NUM_POSITIONS);
      strncpy (T, S + Start_Position, String_Len);
      T [String_Len] = '\0'; 
      N++;

      B = basetoint(T,String_Len); 

      /* compute frequencies for each position */
      
      for(i=0;i<String_Len;i++)
      	V[i][B[i]]++;
      	
      free(B); 
    }  

    t->no=N;

    /* compute consensus */
    for(i=0;i<String_Len;i++)
      {
      	max=0;
      	for(j=0;j<4;j++)
      		if(V[i][j]>max)
      		{
				C[i]=j;
				max=V[i][j];
			}
	  } 

	/*compute match between consensus and variable at position j */
	for(i=0;i<String_Len;i++)
		for(j=0;j<String_Len;j++)
			for(k=0;k<4;k++)
				M[i][j][k]=0;
	/*pos=0;
	  fsetpos(Infile,&pos);*/
	rewind(Infile);
	while  (fgets (T, MAX_STRING_LEN, Infile) != NULL)
     {
      sscanf (T, "%*s %s", S);
      assert (strlen (S) == NUM_POSITIONS);
      strncpy (T, S + Start_Position, String_Len);
      T [String_Len] = '\0'; 
      B = basetoint(T,String_Len);
      for(i=0;i<String_Len;i++)
      	if(C[i]==B[i])
      		for(j=0;j<String_Len;j++)
      				M[i][j][B[j]]++;
      free(B);
      }


    /* for each position compute the chi_square and where to do the partition */


   max=0;
   maxi=-1;
   for(i=0;i<String_Len;i++)
   if(W[i])
   {
	Sum=0;
	W[i]=0;
	for(j=0;j<String_Len;j++)
	{
		/*printf("i=%d,j=%d,Ci=%d,Vj0=%d,Vj1=%d,Vj2=%d,Vj3=%d,Mij0=%d,Mij1=%d,Mij2=%d,Mij3=%d\n",i,j,C[i],V[j][0],V[j][1],V[j][2],V[j][3],M[i][j][0],M[i][j][1],M[i][j][2],M[i][j][3]);
		fflush(stdout);*/

		if(W[j]) 
			Sum+=chi_square(i,j);
	}
	W[i]=1;

	if(Sum>max)
	{
		max=Sum;
		maxi=i;

	}
   } 

   printf("Consens %d pe poz %d\n",C[maxi],maxi);

   /* open output files */

   sprintf(Outname1,"%s%d",Outname,Nofile + 1);
   sprintf(Outname2,"%s%d",Outname,Nofile + 2);

   NextInfile1 = fopen (Outname1, "w");
   if  (NextInfile1 == NULL)
       {
        fprintf (stderr, "ERROR:  Unable to open file %s\n", Outname1);
        exit (EXIT_FAILURE);
       }

   NextInfile2 = fopen (Outname2, "w");
   if  (NextInfile2 == NULL)
       {
        fprintf (stderr, "ERROR:  Unable to open file %s\n", Outname2);
        exit (EXIT_FAILURE);
       }

   Copy = (char *) malloc((MAX_STRING_LEN+1)*sizeof(char));
   MemCheck(Copy,"Copy");
   N1=0;
   N2=0;
   /* split into 2 leaves if necessary */
   /*pos=0;
     fsetpos(Infile,&pos);*/
   rewind(Infile);
   while  (fgets (T, MAX_STRING_LEN, Infile) != NULL)
     {  
     	strcpy(Copy,T);
		sscanf (T, "%*s %s", S);
      	assert (strlen (S) == NUM_POSITIONS);
      	strncpy (T, S + Start_Position, String_Len);
      	T [String_Len] = '\0'; 
	    B = basetoint(T,String_Len); 
	    if(B[maxi] == C[maxi])
	    { 
	    	N1++;
	    	fprintf(NextInfile1,"%s",Copy);
	    }
	    else
	    {
			N2++;
	    	fprintf(NextInfile2,"%s",Copy);
	    }
	}

	free(S);
	free(T);
	free(Copy);

	fclose(NextInfile1);
	fclose(NextInfile2);

	printf("Frunze de %d si %d componente\n",N1,N2);

	tempnofile=Nofile;
	Nofile+=2;

	//if(N1+N2>224)
	//if(N1+N2>1000)
	if(N1>400 && N2>400)
	{   t->consens=C[maxi];
   		t->poz=maxi;   	
		t->left = (tree *) malloc(sizeof(tree));
   		if (t->left == NULL) {fprintf(stderr,"%s: Memory allocation for tree failure.\n"); abort();}
		(t->left)->val=tempnofile+1;
   		(t->left)->consens=-1;
		(t->left)->poz=-1;
		(t->left)->no=N1;
   		(t->left)->left=NULL;
   		(t->left)->right=NULL;	
		if(N1>350) 
			{ 
				W[maxi]=0;
				split(t->left,Outname1,Outname);
			}
		W[maxi]=1;
		t->right = (tree *) malloc(sizeof(tree));
   		if (t->right == NULL) {fprintf(stderr,"%s: Memory allocation for tree failure.\n"); abort();}
   		(t->right)->val=tempnofile+2;
   		(t->right)->consens=-1;
   		(t->right)->poz=-1;
   		(t->right)->no=N2;
   		(t->right)->left=NULL;
   		(t->right)->right=NULL;
		if(N2>350) split(t->right,Outname2,Outname);
	}
   		
   fclose(Infile);

}
예제 #12
0
	/*
	This function expects the pointer to the user data, not the debug data.
	*/
	IMG_VOID OSCheckMemDebug(IMG_PVOID pvCpuVAddr, IMG_SIZE_T uSize, const IMG_CHAR *pszFileName, const IMG_UINT32 uLine)
	{
		OSMEM_DEBUG_INFO const *psInfo = (OSMEM_DEBUG_INFO *)((IMG_UINTPTR_T)pvCpuVAddr - TEST_BUFFER_PADDING_STATUS);

		/* invalid pointer */
		if (pvCpuVAddr == IMG_NULL)
		{
			PVR_DPF((PVR_DBG_ERROR, "Pointer 0x%p : null pointer"
					 " - referenced %s:%d - allocated %s:%d",
					 pvCpuVAddr,
					 pszFileName, uLine,
					 psInfo->sFileName, psInfo->uLineNo));
			while (STOP_ON_ERROR);
		}

		/* align */
		if (((IMG_UINT32)pvCpuVAddr&3) != 0)
		{
			PVR_DPF((PVR_DBG_ERROR, "Pointer 0x%p : invalid alignment"
					 " - referenced %s:%d - allocated %s:%d",
					 pvCpuVAddr,
					 pszFileName, uLine,
					 psInfo->sFileName, psInfo->uLineNo));
			while (STOP_ON_ERROR);
		}

		/*check guard region before*/
		if (!MemCheck((IMG_PVOID)psInfo->sGuardRegionBefore, 0xB1, sizeof(psInfo->sGuardRegionBefore)))
		{
			PVR_DPF((PVR_DBG_ERROR, "Pointer 0x%p : guard region before overwritten"
					 " - referenced %s:%d - allocated %s:%d",
					 pvCpuVAddr,
					 pszFileName, uLine,
					 psInfo->sFileName, psInfo->uLineNo));
			while (STOP_ON_ERROR);
		}

		/*check size*/
		if (uSize != psInfo->uSize)
		{
			PVR_DPF((PVR_DBG_WARNING,
					"Pointer 0x%p : supplied size was different to stored size (0x%"
					SIZE_T_FMT_LEN "X != 0x%" SIZE_T_FMT_LEN "X)"
					 " - referenced %s:%d - allocated %s:%d",
					 pvCpuVAddr, uSize, psInfo->uSize,
					 pszFileName, uLine,
					 psInfo->sFileName, psInfo->uLineNo));
			while (STOP_ON_ERROR);
		}

		/*check size parity*/
		if ((0x01234567 ^ psInfo->uSizeParityCheck) != psInfo->uSize)
		{
			PVR_DPF((PVR_DBG_WARNING,
					"Pointer 0x%p : stored size parity error (0x%"
					SIZE_T_FMT_LEN "X != 0x%" SIZE_T_FMT_LEN "X)"
					 " - referenced %s:%d - allocated %s:%d",
					 pvCpuVAddr, psInfo->uSize, 0x01234567 ^ psInfo->uSizeParityCheck,
					 pszFileName, uLine,
					 psInfo->sFileName, psInfo->uLineNo));
			while (STOP_ON_ERROR);
		}
		else
		{
			/*the stored size is ok, so we use it instead the supplied uSize*/
			uSize = psInfo->uSize;
		}

		/*check padding after*/
		if (uSize)
		{
			if (!MemCheck((IMG_VOID*)((IMG_UINTPTR_T)pvCpuVAddr + uSize), 0xB2, TEST_BUFFER_PADDING_AFTER))
			{
				PVR_DPF((PVR_DBG_ERROR, "Pointer 0x%p : guard region after overwritten"
						 " - referenced from %s:%d - allocated from %s:%d",
						 pvCpuVAddr,
						 pszFileName, uLine,
						 psInfo->sFileName, psInfo->uLineNo));
			}
		}

		/* allocated... */
		if (psInfo->eValid != isAllocated)
		{
			PVR_DPF((PVR_DBG_ERROR, "Pointer 0x%p : not allocated (freed? %d)"
					 " - referenced %s:%d - freed %s:%d",
					 pvCpuVAddr, psInfo->eValid == isFree,
					 pszFileName, uLine,
					 psInfo->sFileName, psInfo->uLineNo));
			while (STOP_ON_ERROR);
		}
	}