Example #1
0
void XAP_Dialog_Print::setPaperSize(const char * szPageSize)
{
	FREEP(m_pageSize);
	if (szPageSize && *szPageSize)
		m_pageSize = g_strdup(szPageSize);
}
Example #2
0
void XAP_Dialog_Print::setDocumentTitle(const char * szDocTitle)
{
	FREEP(m_szDocumentTitle);
	if (szDocTitle && *szDocTitle)
		m_szDocumentTitle = g_strdup(szDocTitle);
}
Example #3
0
XAP_FontPreview::~XAP_FontPreview(void)
{
	FREEP(m_drawString);
	DELETEP(m_pFontPreview);
}
Example #4
0
XAP_Args::XAP_Args(const char * szCmdLine)
{
    // build an argc,argv for this command line

    m_argc = 0;
    m_argv = NULL;
    m_szBuf = NULL;

    if (!szCmdLine || !*szCmdLine)
        return;

    // copy command line into work buffer
    // and put pointers to the tokens in m_argv
    //
    // we support (with apologies to Flex & Bison):
    //
    //    WHITE [ \t]+
    //    DQUOTE '"'
    //    SQUOTE '\''
    //    OTHER [^ \t'"]
    //
    //    T1 := OTHER*
    //    T2 := DQUOTE [^DQUOTE]* DQUOTE
    //    T3 := SQUOTE [^SQUOTE]* SQUOTE
    //
    //    WHITE ({T1|T2|T3}WHITE)* [WHITE]

    m_szBuf = g_strdup(szCmdLine);
    UT_ASSERT(m_szBuf);

    int count = 10;	// start with 10 and g_try_realloc if necessary
    int k = 0;
    char ** argv = (char **)UT_calloc(count,sizeof(char *));

    enum _state { S_START, S_INTOKEN, S_INDQUOTE, S_INSQUOTE } state;
    state = S_START;

#define GrowArrayIfNecessary()								\
	do	{	if (k==count)									\
			{	int newsize = (count+10)*sizeof(char *);	\
				argv = (char **)g_try_realloc(argv,newsize);	\
				count += 10;								\
		}} while (0)

    char * p = m_szBuf;
    while (*p)
    {
        switch (state)
        {
        case S_START:
            if ( (*p==' ') || (*p=='\t') )
            {
                p++;
                break;
            }

            if (*p=='\'')
            {
                state=S_INSQUOTE;
                *p++=0;					// don't include starting quote in token
            }
            else if (*p=='"')
            {
                state=S_INDQUOTE;
                *p++=0;					// don't include starting quote in token
            }
            else
                state=S_INTOKEN;

            GrowArrayIfNecessary();
            argv[k++] = p++;
            break;

        case S_INTOKEN:
            if ( (*p==' ') || (*p=='\t') )
            {
                state=S_START;
                *p++=0;
                break;
            }

            p++;
            break;

        case S_INDQUOTE:
            if ( (*p=='"') )
            {
                state=S_START;
                *p++=0;
                break;
            }

            p++;
            break;

        case S_INSQUOTE:
            if ( (*p=='\'') )
            {
                state=S_START;
                *p++=0;
                break;
            }

            p++;
            break;
        }
    }

    if (k==0)
    {
        FREEP(m_szBuf);
        return;
    }

    m_argv = argv;
    m_argc = k;

#ifdef DEBUG
    for (int kk=0; kk<m_argc; kk++)
        UT_DEBUGMSG(("ParsedCommandLine: argv[%d][%s]\n",kk,m_argv[kk]));
#endif

    return;
}
Example #5
0
MaxResults adjust_max_map(Model B, PoSition **Pos,  double *adj_map)

   /*=======================================================================*/
   /* FUNCTION NAME : adjust_max_map                                        */
   /*                                                                       */
   /* DESCRIPTION : Improves the maximal alignment by including motif       */
   /*               motif elements whose inclusion (whether it is forward   */
   /*               or reverse complement) improves upon the maximum        */
   /*               calculated map value                                    */
   /*=======================================================================*/
 
{
  double     map_fwd, map_rev, map_same;
  int        n, t, newpos; 
  MaxResults M; /** Have to set these -- will then be returned **/
  int        last_inc;
  double     dMax, dLocMax;
  double     **dProbArray;
  int        maxnum;
  ProbStruct P;		/* BT 2/21/97 */
  int        start, end;
  int        nSeq;
  int        typ;
  int        p;
  int        len;

  init_maxdata(&M);
  map_fwd = map_rev = map_same = (*adj_map);
  for( nSeq = 0; nSeq < B->IP->nNumSequences; nSeq += SeqInc( B, nSeq ) )
    {
      len = SequenceLength( B, nSeq ); 
      start = SequenceStartPos( B, nSeq );
      end = SequenceEndPos( B, nSeq );
      for(n = start; n <= end; n++) 
	{      
	  for(t = 0; t < B->IP->nNumMotifTypes; t++) 
	    {
	      if(((B->IP->is_defined[cl_E] && 
		   B->RP->nSites[nSeq] < B->RP->nMaxBlocks) || 
		  (! B->IP->is_defined[cl_E])) &&
		 PossibleStartPos( Pos, n, t, len, nSeq, B) &&
		 !OverlapsPrevMotif(n,B->IP->nNumMotifTypes,Pos) &&  
		 !Pos[t][n].nMotifStartPos) 
		{
		  newpos = -1;	/* BT 3/12/97 */
		  if( AnyOverlap(B, n, t, Pos, &newpos, &typ) )
		    {
		      for( p = 0; p < SeqInc( B, nSeq ); p++ )
			{
			  adjust_counts(B,DELETE,newpos + p * len, typ, Pos[typ][newpos + p * len].RevComp);
			  B->IP->nNumMotifs[typ][Pos[typ][newpos + p * len].RevComp]--;
			  B->RP->nSites[nSeq + p]--;
			  not_in_motif(Pos, newpos + p * len,B,typ);
			}
		    } 
		  
		  /* Calculate the map values for the current position */
		  /* being excluded (map_same), included as a forward  */
		  /* motif (map_fwd), or being included as a reverse   */
		  /* complement motif (map_rev).                       */
		  
		  map_same = CalcMapProb(B, B->IP->is_defined[cl_R]); 
		  
		  if( PossibleStartPos( Pos, n, t, len, nSeq, B) )
		    {		  
		      for( p = 0; p < SeqInc( B, nSeq ); p++ )
			{
			  adjust_counts(B, ADD, n + p * len,t,FALSE);
			  B->RP->nSites[nSeq+p]++;	      
			  B->IP->nNumMotifs[t][FORWARD]++;		/* BT 3/12/97 */
			}
		      map_fwd = CalcMapProb(B, B->IP->is_defined[cl_R]);	      
		      for( p = 0; p < SeqInc( B, nSeq ); p++ )
			{
			  adjust_counts(B, DELETE, n + p * len,t,FALSE);
			  B->RP->nSites[nSeq+p]--;
			  B->IP->nNumMotifs[t][FORWARD]--;		/* BT 3/12/97 */
			}
		      
		      if(B->IP->RevComplement) 
			{
			  for( p = 0; p < SeqInc( B, nSeq ); p++ )
			    {
			      adjust_counts(B, ADD, n + p * len, t,TRUE);
			      B->RP->nSites[nSeq+p]++;
			      B->IP->nNumMotifs[t][REVERSE]++;		/* BT 3/12/97 */
			    }
			  map_rev = CalcMapProb(B, B->IP->is_defined[cl_R]);
			  for( p = 0; p < SeqInc( B, nSeq ); p++ )
			    {
			      adjust_counts(B, DELETE, n + p * len, t, TRUE);
			      B->RP->nSites[nSeq+p]--;
			      B->IP->nNumMotifs[t][REVERSE]--;		/* BT 3/12/97 */
			    }
			}
		      
		      /* See if the forward map improves the maximal */
		      /* map calculated so far                       */
		      
		      if((map_fwd >= map_same)  && (map_fwd >= map_rev) &&
			 (map_fwd >= (*adj_map)))
			{
			  for( p = 0; p < SeqInc( B, nSeq ); p++ )
			    {
			      adjust_counts(B, ADD, n + p * len,t, FALSE);
			      B->RP->nSites[nSeq+p]++;
			      B->IP->nNumMotifs[t][FORWARD]++;
			      set_in_motif(Pos,n + p * len,B,t,FALSE);
			    }
			  (*adj_map) = map_fwd;
			  
			  /* as this segment in alignment, we need to check */
			  /* segments do not overlap with this segment */
			  n += (MotifWidth( B, t ) - 1);
			}		
		      
		      /* See if the reverse complement map improves */
		      /* the maximal map calculated so far          */
		      
		      else if(B->IP->RevComplement && 
			      (map_rev >= map_same) && (map_rev >= map_fwd) && 
			      (map_rev >= (*adj_map))) 
			{
			  for( p = 0; p < SeqInc( B, nSeq ); p++ )
			    {
			      adjust_counts(B, ADD, n + p * len,t, TRUE);
			      B->RP->nSites[nSeq+p]++;
			      B->IP->nNumMotifs[t][REVERSE]++;
			      set_in_motif(Pos,n + p * len,B,t,TRUE);
			    }
			  (*adj_map) = map_rev;
			  /* as this segment in alignment, we need to check */
			  /* segments do not overlap with this segment */
			  n += (MotifWidth( B, t ) - 1);
			}     		  
		      /* if we removed a motif and things did not improve when we */
		      /* added n, put the old motif back */
		      /* BT 3/12/97 */ 
		      else if( newpos >= 0 )
			{
			  for( p = 0; p < SeqInc( B, nSeq ); p++ )
			    {
			      adjust_counts(B, ADD,newpos + p * len,typ,Pos[typ][newpos + p * len].RevComp);
			      B->IP->nNumMotifs[typ][Pos[typ][newpos+p*len].RevComp]++;
			      set_in_motif(Pos,newpos + p*len,B,typ, Pos[typ][newpos+p*len].RevComp);
			      B->RP->nSites[nSeq+p]++;
			    }
			}           		
		      else if(Pos[t][n].nMotifStartPos) 
			/* as this segment in alignment, we need to check */
			/* segments do not overlap with this segment */
			n += (MotifWidth( B, t ) - 1);
		    }
		}
	    }
	}
    }
   
   maxnum = findMaxNumMotif(B->IP);
      
   init_prob( &P, B->IP );			/* BT 2/21/97 */
   update_prob( &P, B, TRUE  );
   update_posterior_prob(B);		/* BT 3/17/97 */

   dProbArray = setElementProb( B, Pos, P );

   M = setMaxData(B->F, B->IP, (*adj_map), 1, Pos, &last_inc, &dMax,
                  &dLocMax, M, dProbArray, B);
   FREEP(dProbArray, maxnum); 
   M.frequency = NULL; 

   free_prob( &P, B->IP );
    
   return M;
}
Example #6
0
MaxResults suboptSampler(Model B, PoSition **Pos, SimTime *S)
 
{
   int        **nNumMotifs, 
              **startPos,   /* startPos[MotifType][motifnum] */
              i, j, seed_run = 0, t, k; 
   int        maxnum;  /* maximum number of motif in one type motif */
   register   Mlist M; 
   MaxResults maxData, locMax;
   RPType     RP;
   IPtype     IP;      /* for quick access of input data    */
   PoSition   *Pos_t;  /* Pos_t=Pos[t] */
   int	      n;				/* BT 2/7/97 */ 
   int        nPos;
   int        sum;
   double     dCurrProb;
#ifdef _MPI_
   MPI_Status status;
   double     dTempInfo[4];
#endif

   IP=B->IP;
   RP = B->RP;

   init_maxdata(&maxData);
   init_maxdata(&locMax);
   BeginTime(S);

#ifdef _MPI_
   if( ! IP->is_defined[cl_hm] )
     {
       /* get the go ahead to start */
       Gibbs_MPI_Recv( B, &dTempInfo, 4, MPI_DOUBLE, MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, 
		       &status );
       if( status.MPI_TAG == G_MPI_DONE )
	 return maxData;
       
       if( IP->is_defined[cl_X] && B->AN->bExchange )
	 {
	   B->AN->currTemp = dTempInfo[0];
	   B->AN->dMinTemp = B->AN->currTemp;
	   B->AN->dMaxTemp = B->AN->currTemp;
	   PrintTempOut(IP->Datafiles->mpiTemp_fpt, "currTemp = %f maxTemp = %f minTemp = %f\n",
			B->AN->currTemp, B->AN->dMaxTemp, B->AN->dMinTemp );
	 }
     }
#endif
   
   /* save the inital number of motifs */
   for(t = 0; t < IP->nNumMotifTypes; t++)		/* BT 2/7/97 */
     {
       RP->nPriorMotifSites[t][FORWARD] = IP->nNumMotifs[t][FORWARD];
       RP->nPriorMotifSites[t][REVERSE] = IP->nNumMotifs[t][REVERSE];
     }

   /* copy the original counts into current counts */
   copy_counts(B);  
   nNumMotifs = copy_motif_num(IP);
   zero_motifs(IP); /* set motif count to zero */

   /* If not running Wilcox test initialize random number gerator. */
   /* Wilcox already did this */

   if( ! IP->is_defined[cl_l] )      /* BT 7/23/97 */ 
       sRandom(B, IP->lSeedVal);  

   /* calculate the probability of NULL model */
   /* IP->dnull_map = CalcMapProb(B, IP->is_defined[cl_R]); */
   IP->dnull_map = CalcNullMap(B);  /* 2/16/2001 */

   reset_motif_num(nNumMotifs,IP);

   /* mark all possible motif sites */
   if( ! IP->inCentroidAlign )
     set_indicator_vector(Pos, B->Seq, B);
   maxnum = findMaxNumMotif(IP);
   
   if( IP->is_defined[cl_E] ||
       RP->nUseSpacingProb || IP->is_defined[cl_T]  )  /* BT 11/20/2000 */
     {
       CountAlignments( B, Pos ); 
       SaveAlignmentCounts( B );
     }
       
   /* allocate space for start positions of motifs */
   NEWP(startPos,IP->nNumMotifTypes, int);
   for(i = 0; i <IP->nNumMotifTypes ; i++)
     NEW(startPos[i],maxnum, int);

   /* Loop through for a number of different seeds */
   while(seed_run++ < IP->nSeeds) 
     {  
       if( IP->is_defined[cl_X] )
	 {
	   /* if( ! B->AN->bExchange )
	      B->AN->currTemp = B->AN->dMaxTemp; */
	   if( ! IP->is_defined[cl_Z] )	    
	     printf( "Current temperature: %7.2f\n", B->AN->currTemp );
	 }
       IP->nSeedRun = seed_run;
        
       if(!IP->is_defined[cl_F])
	 initMask(B);

       if( IP->is_defined[cl_X] )
	 init_maxdata( &(B->AN->results[seed_run]) );
       
       /* initialize the Pos */
       for(t=0;t<IP->nNumMotifTypes;t++)
	 {
	   Pos_t=Pos[t];
	   for(i = 0; i < IP->nSeqLen; i++) 
	     {
	       Pos_t[i].nInMotif=FALSE;
	       Pos_t[i].nMotifStartPos=FALSE;
	     }
	 }

       for( t= 0; t < IP->nNumMotifTypes; t++ )          /* BT 5/23/97 */
	 {
	   IP->nMotifLen[t] = IP->nInputMotifLen[t];        /* restore original lengths */
	   SetPossibleSites( B, t );                       /* restore original site count */
	 }
       if( IP->is_defined[cl_d] && ! IP->inCentroidAlign ) 
	 set_indicator_vector(Pos, B->Seq, B);
       
       if( ! IP->site_samp )                      /* BT 7/16/97 */
	 set_posterior_prob(IP, B->C);         /* Set initial posterior prob */
       
       /* random select a set of motifs */
       if( ! IP->is_defined[cl_V] ) /* BT 04/16/03 */
	 {
	   if( B->InitPos == NULL || seed_run > 1 )
	     {
	       if( IP->is_defined[cl_A] )
		 {
		   set_posterior_prob(IP, B->C);     
		   for( t = 0; t < IP->nNumMotifTypes; t++ )
		     {
		       IP->nNumMotifs[t][FORWARD] = 0;
		       IP->nNumMotifs[t][REVERSE] = 0;
		     }
		 }
	       set_random_sequences(B, Pos, startPos); /* set alignment &*/
	     }
	   else
	     {
	       SetInitSequences( B, Pos, startPos );  /* BT 8/5/98 */
	       
	       set_posterior_prob(IP, B->First);     

	       if( RP->bUsePosMatrix )
		 InitializePosMatrix( B );
	       else if( RP->bUseTrans )
		 InitializeTransMatrix( B );
	     }
	 }
       else
	 {
	   if( B->InitPos == NULL )
	     {
	       for( t = 0; t < IP->nNumMotifTypes; t++ )
		 {
		   IP->nNumMotifs[t][FORWARD] = 0;
		   IP->nNumMotifs[t][REVERSE] = 0;
		 }
	     }
	   else
	     {
	       SetInitSequences( B, Pos, startPos ); 
	       set_counts( B );  /* BT 10/23/03 */
	       set_posterior_prob(IP, B->First);     
	     }
	   set_posterior_prob(IP, B->C);     
	 }

       reset_counts(B, startPos, Pos);             /* its counts     */

       if(  B->InitPos != NULL && seed_run == 1 )
	 {
	   RP->dInitProb = CalcMapProb( B, IP->is_defined[cl_R] );
	   if( ! IP->inCentroidAlign )
	     {
	       fprintf( IP->Datafiles->out_fpt, "seed = %d Initial MAP =  %.5f sites = %d \n",  
			IP->nSeedRun, 
			RP->dInitProb,
			TotalNumMotifs( B ));
	       for( t = 0; t < IP->nNumMotifTypes; t++ )
		 {
		   fprintf(IP->Datafiles->out_fpt, 
			    "Motif %d Map =  %.5f Frag =  %.5f\n", t, 
			    CalcMotifMap(B, t, IP->is_defined[cl_R]),
			    CalcMotifFragMap(B, t, IP->is_defined[cl_R]) );
		 }
	     }


#ifdef _MPI_
	   PrintTempOut( IP->Datafiles->mpiTemp_fpt,
			 "rank = %d process = %d seed = %d Initial MAP =  %.5f sites = %d\n",  
			 IP->nRank,
			 IP->nMPIProcesses,
			 IP->nSeedRun, 
			  RP->dInitProb,
			 TotalNumMotifs( B ) );

	   for( t = 0; t < IP->nNumMotifTypes; t++ )
	     {
	       PrintTempOut( IP->Datafiles->mpiTemp_fpt,
			     "%d Motif =  %.5f Frag =  %.5f\n", t, 
			     CalcMotifMap(B, t, IP->is_defined[cl_R]),
			     CalcMotifFragMap(B, t, IP->is_defined[cl_R]) );
	     }
	   PrintTempOut( IP->Datafiles->mpiTemp_fpt,
			 "Bkgnd =  %.5f Beta =  %.5f Null = %.5f\n",  
			 CalcBkgndMap(B, IP->is_defined[cl_R]),
			 CalcBetaMap( B, IP->is_defined[cl_R]),
			 IP->dnull_map );	  
#else
	   fprintf( stdout, "seed = %d Initial MAP =  %.5f sites = %d\n",  
		    IP->nSeedRun, 
		    B->RP->dInitProb,
		    TotalNumMotifs( B ) );

	   for( t = 0; t < IP->nNumMotifTypes; t++ )
	     {
	       fprintf( stdout, 
			"%d Motif =  %.5f Frag =  %.5f\n", t, 
			CalcMotifMap(B, t, IP->is_defined[cl_R]),
			CalcMotifFragMap(B, t, IP->is_defined[cl_R]) );
	     }
	   fprintf( stdout, 
		    "Bkgnd =  %.5f Beta =  %.5f Seq = %.5f Null = %.5f\n",  
		    CalcBkgndMap(B, IP->is_defined[cl_R]),
		    CalcBetaMap( B, IP->is_defined[cl_R]),
		    CalcSitePerSeqMap( B ), 
		    IP->dnull_map );	  
#endif

	   for( t = 0; t < IP->nNumMotifTypes; t++ )
	     {
	       fprintf( stdout, 
			"-----------------------------------------------------------\n" );
	       fprintf( stdout, "                          MOTIF %c\n\n", (char)(97 + t));
	       DumpMotifPositions( t, B, Pos, stdout );
	       fprintf( stdout, "%d sites\n", NUMMOTIFS( IP->nNumMotifs[t]) );
	     }
	   fflush( stdout );
	 }
       
       /* create a motif element list */
       M = set_motif_info(IP, startPos, B->Seq);

#ifdef _DEBUG_
       /* ==================================================================== */
       for( t = 0; t < IP->nNumMotifTypes; t++ )
	 {
	   fprintf( stdout, 
		    "-----------------------------------------------------------\n" );
	   fprintf( stdout, "                          MOTIF %c\n\n", (char)(97 + t));
	   DumpMotifPositions( t, B, Pos, stdout );
	   fprintf( stdout, "%d sites\n", NUMMOTIFS( IP->nNumMotifs[t]) );
	   DumpCounts( B, t, stdout );
	   fflush( stdout );
	 }
       /*  ==================================================================== */
#endif

       if( ! IP->is_defined[cl_Z] )
	 {
	   put_prior(B);
	   fprintf(stdout, "\r** %d **\n", seed_run);
	   fflush( stdout );    /* BT 9/19/97 */
	 }

       if(seed_run > 1) 
	 {
	   RestoreAlignmentCounts( B );
	   if(IP->site_samp) 
	     locMax = site_sampler(B, Pos, M); 
	   else if( IP->is_defined[cl_bayes] )
	     locMax = bayes_sampler(B, Pos, M, seed_run); 
	   else if( IP->is_defined[cl_E] )
	     locMax = rsite_sampler(B, Pos, M, seed_run); 
	   else
	     locMax = motif_sampler(B,Pos,M);

	   if( IP->is_defined[cl_X] )
	     CopyMaxResults( &(B->AN->results[seed_run]), &locMax, B );
	   
	   dCurrProb = locMax.dProbability;

	   if(locMax.dProbability > maxData.dProbability) 
	     {
	       /* Check to see if current run is max */
	       free_maxdata(&maxData, IP);                  
	       maxData = locMax;     
	       maxData.nSuboptSeed = seed_run;
	       if( (! IP->is_defined[cl_Z]) && IP->is_defined[cl_opt] )
		 print_maxData(IP->nNumMotifTypes, maxData);
	       }
	   else 
	     free_maxdata(&locMax, IP); 
	 }
       else 
	 {  /* Set Maximum first time through */
	     if(IP->site_samp) 
	       maxData = site_sampler(B, Pos, M); 
	     else if( IP->is_defined[cl_bayes] )
	       maxData = bayes_sampler(B, Pos, M, seed_run); 
	     else if( IP->is_defined[cl_E] )
	       maxData = rsite_sampler(B, Pos, M, seed_run); 
	     else              
	       maxData = motif_sampler(B,Pos,M);
	     
	     dCurrProb = maxData.dProbability;
	     maxData.nSuboptSeed = seed_run;

	     if( IP->is_defined[cl_X] )
	       CopyMaxResults( &(B->AN->results[seed_run]), &maxData, B );
	     if( (! IP->is_defined[cl_Z]) && IP->is_defined[cl_opt] )
	       print_maxData(IP->nNumMotifTypes, maxData);
	 }
              
       reset_motif_num(nNumMotifs, IP);
       copy_counts(B);                        /* Counts w/o motifs */
       free_motifs(B, M); 

#ifdef _MPI_
       if( IP->is_defined[cl_hm] )
	 {
	   if( seed_run == IP->nSeeds )
	     SendSuboptMsg( B, G_MPI_SUBOPT_DONE, seed_run );
	   else
	     SendSuboptMsg( B, G_MPI_SEED_DONE, seed_run );
	 }
       else
	 {
	   dTempInfo[1] = dCurrProb;
	   dTempInfo[3] = 0;
	   if( IP->is_defined[cl_opt] )  
	     {
	       for(t = 0; t < IP->nNumMotifTypes; t++) 
		 {
		   dTempInfo[3] += (double) maxData.nNumMotifs[t];
		 }
	     }
	   
	   Gibbs_MPI_Send( B, dTempInfo, 4, MPI_DOUBLE, 0, G_MPI_DATA, MPI_COMM_WORLD );
	 }

       Gibbs_MPI_Recv( B, dTempInfo, 4, MPI_DOUBLE, 0, MPI_ANY_TAG, MPI_COMM_WORLD, 
		       &status );

       if( status.MPI_TAG == G_MPI_DONE )
	 {
	   PrintTempOut( IP->Datafiles->mpiTemp_fpt, "Received MPI_DONE signal\n" );
	   break;
	 }
       else if( status.MPI_TAG == G_MPI_FINISH )
	 {
	   PrintTempOut( IP->Datafiles->mpiTemp_fpt, "Received subopt end signal\n" );
	   break;
	 }
#endif       
     }/* end of while loop, at this time we have MaxData */
   FREEP(startPos,IP->nNumMotifTypes );
   
   if(!IP->is_defined[cl_F] && maxData.F) 
     {
       for(t = 0; t < IP->nNumMotifTypes; t++)		/* BT 2/7/97 */
	 { 
	   for(n = 0; n < B->F->nMaxLen[t]; n++)
	     B->F->nColMask[t][n] = maxData.F->nColMask[t][n];
	   B->F->FragWidth[t] = maxData.F->FragWidth[t];
	   for( n = 0; n < IP->nMotifLen[t]; n++ )
	     B->F->fragPos[t][n] = maxData.F->fragPos[t][n];
	 } 
     }
   
   for(t = 0; t < IP->nNumMotifTypes; t++)
     {            /* Add in motifs   */
       if( maxData.nMotifLen )
	 IP->nMotifLen[t] = maxData.nMotifLen[t];
       /* Reset Pos in case width changed */
       if( ! IP->inCentroidAlign )
	 set_indicator_vector(Pos, B->Seq, B);       /* BT 9/12/97 */  
       if(  maxData.nNumMotifs )
	 {
	   for(i = 0; i < maxData.nNumMotifs[t]; i++)        /* from the maximum */
	     adjust_counts(B, ADD, maxData.nMotifLoc[i][t], /* alignment       */
			   t, maxData.RevComp[i][t]);
	 }
     }
   
   if(  maxData.nNumMotifs )
     {
       setMotifNum(IP, maxData);      /* BT 5/30/97 */
     }
   
   if( IP->is_defined[cl_u] )
     print_info(B, maxData, TRUE, SUBOPT);		/* BT 3/19/97 */
   
   if( IP->is_defined[cl_d] && IP->is_defined[cl_q] )
     GetWidthCounts( B );

   FREEP(nNumMotifs, IP->nNumMotifTypes);
   free(nNumMotifs);

   if( IP->is_defined[cl_Q] )     /* BT 3/27/98 */
     {
       fprintf( IP->Datafiles->occur_fpt, "seq pos pos2 motif count\n" );
       for( i = 0; i < IP->nNumSequences; i++ )
	 {
	   for( j = 0; j < SequenceLength( B, i ); j++ )
	     {
	       nPos =  SequenceStartPos( B, i ) + j;
	       for(  t = 0;  t < IP->nNumMotifTypes; t++ )
		 {
		   for( sum = 0, k = 1; k <= IP->nSeeds; k++ )
		     {
		       sum += IP->nAlignCnts[k][t][i][j];
		     }
		   fprintf( IP->Datafiles->occur_fpt, "%5d %5d %5d %5d %5d\n",
			    i, j, nPos, t, sum );
		 }
	     }
	   fflush(  IP->Datafiles->occur_fpt );
	 }
     }

   if( ! IP->is_defined[cl_Z] && ! IP->is_defined[cl_nopt] )
     printf( "Max subopt MAP found on seed %d\n", maxData.nSuboptSeed );
   
   return maxData;
}
Example #7
0
UT_ByteBuf::~UT_ByteBuf()
{
  FREEP(m_pBuf);
}
void 
AP_UnixDialog_Spell::_updateWindow (void)
{             
	GtkTextBuffer * buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(m_txWrong));
	GtkTextIter iter2;

	// Empty buffer
	gtk_text_buffer_set_text(buffer, "", -1);

	const UT_UCSChar *p;
	UT_sint32 iLength;
	// insert start of sentence
	p = m_pWordIterator->getPreWord(iLength);
	if (0 < iLength)
	{
		gchar * preword = (gchar*) _convertToMB(p, iLength);
		gtk_text_buffer_set_text(buffer, preword, -1);
		FREEP(preword);
	}

	// insert misspelled word (in highlight color)
	p = m_pWordIterator->getCurrentWord(iLength);
	gchar * word = (gchar*) _convertToMB(p, iLength);
	GtkTextTag * txt_tag = gtk_text_buffer_create_tag(buffer, NULL, "foreground-gdk", &m_highlight, NULL); 
	gtk_text_buffer_get_end_iter(buffer, &iter2);
	gtk_text_buffer_insert_with_tags(buffer, &iter2, word, -1, txt_tag, NULL);
	// word is freed at the end of the method...
	
	// insert end of sentence
	p = m_pWordIterator->getPostWord(iLength);
	if (0 < iLength)
	{
		gchar * postword = (gchar*) _convertToMB(p, iLength);
		gtk_text_buffer_get_end_iter(buffer, &iter2);
		gtk_text_buffer_insert(buffer, &iter2, postword, -1);
		FREEP(postword);
	}
	else
	{
		// Insert space to make gtk_text_buffer understand that it
		// really should highlight the selected word. This is a
		// workaround for bug 5459. It really should be fixed in GTK.
		gtk_text_buffer_get_end_iter(buffer, &iter2);
		gtk_text_buffer_insert(buffer, &iter2, " ", -1);
	}
	// TODO: set scroll position so misspelled word is centered


	GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW (m_lvSuggestions));
	
	// Detach model for faster updates
	g_object_ref (G_OBJECT (model));	
	gtk_tree_view_set_model (GTK_TREE_VIEW (m_lvSuggestions), NULL);
	gtk_list_store_clear (GTK_LIST_STORE (model));	
     
	GtkTreeSelection *selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (m_lvSuggestions));

	UT_DEBUGMSG (("ROB: AP_UnixDialog_Spell::_updateWindow() itemcount=%d\n", m_Suggestions->getItemCount ()));
	if (m_Suggestions->getItemCount () == 0) {

		GtkTreeIter iter;
		gtk_tree_selection_set_mode (selection, GTK_SELECTION_NONE);

		const XAP_StringSet * pSS = m_pApp->getStringSet();
		std::string s;
		pSS->getValueUTF8(AP_STRING_ID_DLG_Spell_NoSuggestions,s);

		gtk_list_store_append (GTK_LIST_STORE (model), &iter);
		gtk_list_store_set (GTK_LIST_STORE (model), &iter, 
				    COLUMN_SUGGESTION, s.c_str(),
							COLUMN_NUMBER, -1,
							-1);

		g_signal_handler_block(G_OBJECT(m_eChange), m_replaceHandlerID);
		gtk_entry_set_text(GTK_ENTRY(m_eChange), word);
		g_signal_handler_unblock(G_OBJECT(m_eChange), m_replaceHandlerID);      
	} 
	else
	{

		GtkTreeIter iter;
		gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);

		gchar * suggest = NULL;   
		for (UT_sint32 i = 0; i < m_Suggestions->getItemCount(); i++)
		{
			suggest = (gchar*) _convertToMB((UT_UCSChar*)m_Suggestions->getNthItem(i));
			gtk_list_store_append (GTK_LIST_STORE (model), &iter);
			gtk_list_store_set (GTK_LIST_STORE (model), &iter, 
								COLUMN_SUGGESTION, suggest,  
								COLUMN_NUMBER, i,
								-1);
		}
		// put the first suggestion in the entry
		suggest = (gchar*) _convertToMB((UT_UCSChar*)m_Suggestions->getNthItem(0));
		g_signal_handler_block(G_OBJECT(m_eChange), m_replaceHandlerID);
		gtk_entry_set_text(GTK_ENTRY(m_eChange), suggest);
		g_signal_handler_unblock(G_OBJECT(m_eChange), m_replaceHandlerID);      
	}

	gtk_tree_view_set_model (GTK_TREE_VIEW (m_lvSuggestions), model);
	g_object_unref (G_OBJECT (model));	

	// select first
	if (m_Suggestions->getItemCount () > 0) {
		GtkTreePath *path = gtk_tree_path_new_first ();
		gtk_tree_selection_select_path (selection, path);
		gtk_tree_path_free (path);
	}

	FREEP (word);
}
void AbiCollabSessionManager::storeProfile()
{
	UT_DEBUGMSG(("AbiCollabSessionManager::storeProfile()\n"));

	xmlBufferPtr doc = xmlBufferCreate();
	if (doc)
	{
		xmlTextWriterPtr writer = xmlNewTextWriterMemory(doc, 0);
		if (writer)
		{
			int rc = xmlTextWriterStartDocument(writer, NULL, "UTF-8", NULL);
			if (rc >= 0)
			{
				// TODO: one could check every return value here, but I'm lazy right now
				xmlTextWriterStartElement(writer, reinterpret_cast<const xmlChar*>("AbiCollabProfile"));
				
				for (UT_uint32 i = 0; i < m_vecAccounts.size(); i++)
				{
					AccountHandler* pHandler = m_vecAccounts[i];
					UT_continue_if_fail(pHandler);
					
					xmlTextWriterStartElement(writer, reinterpret_cast<const xmlChar*>("AccountHandler"));
					
					// write out the account handler type
					xmlTextWriterWriteAttribute(writer, reinterpret_cast<const xmlChar*>("type"), BAD_CAST pHandler->getStorageType().utf8_str());
					
					// write out the account handler properties
					for (PropertyMap::const_iterator cit = pHandler->getProperties().begin(); cit != pHandler->getProperties().end(); cit++)
					{
						xmlTextWriterWriteElement(writer, BAD_CAST cit->first.c_str(), BAD_CAST BAD_CAST cit->second.c_str());
					}
					
					// write out the account handler buddies
					xmlTextWriterStartElement(writer, reinterpret_cast<const xmlChar*>("buddies"));
					
					for (UT_uint32 j = 0; j < pHandler->getBuddies().size(); j++)
					{
						BuddyPtr pBuddy = pHandler->getBuddies()[j];
						UT_continue_if_fail(pBuddy);
						if (!pBuddy->isVolatile())
						{
							// we need to be able to store buddy properties
							UT_ASSERT_HARMLESS(UT_NOT_IMPLEMENTED);
							/*xmlTextWriterStartElement(writer, reinterpret_cast<const xmlChar*>("buddy"));
							// write out the buddy properties
							// TODO: for now, the only useful property a buddy has is its "name";
							// However in the future we really should write out a generic property list
							xmlTextWriterWriteElement(
									writer,
									reinterpret_cast<const xmlChar*>("name"), 
									reinterpret_cast<const xmlChar*>(pBuddy->getName().utf8_str())
								);
							xmlTextWriterEndElement(writer);*/ /* end buddy */
						}
					}
					
					xmlTextWriterEndElement(writer); /* end buddies */
					xmlTextWriterEndElement(writer); /* end AccountHandler */
				}
				
				xmlTextWriterEndElement(writer); /* end AbiCollabProfile */
			}
			xmlTextWriterEndDocument(writer);
			xmlFreeTextWriter(writer);

			gchar * s = g_build_filename(XAP_App::getApp()->getUserPrivateDirectory(), 
										 "AbiCollab.Profile",NULL);
			UT_UTF8String profile(s);
			FREEP(s);

			char *uri = UT_go_filename_to_uri(profile.utf8_str());
			GError* error = 0;
			GsfOutput* out = UT_go_file_create (uri, &error);
			if (out)
			{
				gsf_output_write(out, 
							strlen(reinterpret_cast<const char*>(const_cast<const xmlChar*>(doc->content))), 
							reinterpret_cast<const guint8*>(const_cast<const xmlChar*>(doc->content))
						);
				gsf_output_close(out);
				g_object_unref(G_OBJECT(out));
			}
			else
            {
				UT_DEBUGMSG(("Error creating AbiCollab Profile %s: %s!\n", profile.utf8_str(), error ? error->message : "unknown error"));
            }
			FREEP(uri);
		}
		else
        {
			UT_DEBUGMSG(("Error creating XML output writer\n"));
        }
		xmlBufferFree(doc);
	}
	else
    {
		UT_DEBUGMSG(("Error creating XML output buffer\n"));
    }
}
Example #10
0
IE_Imp_XML::~IE_Imp_XML()
{
	FREEP(m_currentDataItemName);
}
void AbiCollabSessionManager::loadProfile()
{
	UT_DEBUGMSG(("AbiCollabSessionManager::loadProfile()\n"));

	gchar *s = g_build_filename(XAP_App::getApp()->getUserPrivateDirectory(), 
								"AbiCollab.Profile", (void*)0);
	UT_UTF8String profile(s);
	FREEP(s);

	GsfInput* in = NULL;
	char *uri = UT_go_filename_to_uri(profile.utf8_str());
	UT_return_if_fail(uri);

	in = UT_go_file_open(uri, NULL); // TODO: shouldn't use NULL here, but check for errors
	FREEP(uri);
	if (!in)
		return;

	guint8 const* contents = gsf_input_read(in, gsf_input_size(in), NULL);
	if (contents)
	{
		xmlDocPtr reader = xmlReadMemory(reinterpret_cast<const char*>(contents), 
							strlen(reinterpret_cast<const char*>(contents)), 0, "UTF-8", 0);
		if (reader)
		{
			xmlNode* node = xmlDocGetRootElement(reader);
			if (node)
			{
				if (strcmp(reinterpret_cast<const char*>(node->name), "AbiCollabProfile") == 0)
				{
					for (xmlNode* accountNode = node->children; accountNode; accountNode = accountNode->next)
					{
						// TODO: check if this node is really an AccountHandler node

						// find the account handler belonging to this type
						xmlChar* prop = xmlGetProp(accountNode, BAD_CAST "type");
						UT_UTF8String handlerType = reinterpret_cast<char *>(prop); 
						xmlFree(prop);
						std::map<UT_UTF8String, AccountHandlerConstructor>::iterator handler_iter = m_regAccountHandlers.find(handlerType);
						if (handler_iter == m_regAccountHandlers.end())
						    continue; // could happen for example when the sugar backend is found in the profile, which does not have a registered account handler belowing to it for now
						
						AccountHandlerConstructor constructor = handler_iter->second;
						AccountHandler* pHandler = constructor();
						UT_continue_if_fail(pHandler);

						for (xmlNode* accountProp = accountNode->children; accountProp; accountProp = accountProp->next)
						{
							if (accountProp->type == XML_ELEMENT_NODE)
							{
								// some node names are pre-defined...
								if (strcmp(reinterpret_cast<const char*>(accountProp->name), "buddies") == 0)
								{
									for (xmlNode* buddyNode = accountProp->children; buddyNode; buddyNode = buddyNode->next)
									{
										if (buddyNode->type != XML_ELEMENT_NODE)
										    continue;
										UT_continue_if_fail(strcmp(reinterpret_cast<const char*>(buddyNode->name), "buddy") == 0);
										UT_continue_if_fail(buddyNode->children);
										
										// read all buddy properties
										PropertyMap vBuddyProps;
										for (xmlNode* buddyPropertyNode = buddyNode->children; buddyPropertyNode; buddyPropertyNode = buddyPropertyNode->next)
										{
											UT_continue_if_fail(buddyPropertyNode->type == XML_ELEMENT_NODE);
											
											UT_UTF8String buddyPropValue = reinterpret_cast<const char*>(xmlNodeGetContent(buddyPropertyNode));
											UT_continue_if_fail(buddyPropertyNode->name && *buddyPropertyNode->name && buddyPropValue.size() > 0);
											
											vBuddyProps.insert(PropertyMap::value_type(
													reinterpret_cast<const char*>(buddyPropertyNode->name), 
													buddyPropValue.utf8_str())
												);
										}
										
										// construct the buddy	
										BuddyPtr pBuddy = pHandler->constructBuddy(vBuddyProps);
										if (pBuddy)
										{
											// add the buddy to the account handler
											pHandler->addBuddy(pBuddy);
										}
									}
								}
								else
								{
									// ... the rest are generic properties
									UT_UTF8String propValue = reinterpret_cast<const char*>(xmlNodeGetContent(accountProp));
									pHandler->addProperty(reinterpret_cast<const char*>(accountProp->name), propValue.utf8_str());
								}
							}
						}

						// add the account to the account list if it is not a duplicate
						if (addAccount(pHandler))
						{
							if (pHandler->autoConnect())
								pHandler->connect();
						}
						else
						{
							_deleteAccount(pHandler);
						}
					}
				}
			}
			xmlFreeDoc(reader);
		}
	}
	g_object_unref(G_OBJECT(in));
}
void WordPerfect_Listener::_closeSpan()
{
	const PP_AttrProp * pAP = m_pAP_Span;

	if (pAP)
	{
		const gchar * szValue;
		
		if (
			(pAP->getProperty("text-position", szValue))
			&& !strcmp(szValue, "superscript")
			)
		{
			_handleAttributeOff((char) 5);  // FIXME: use defines
		}

		if (
			(pAP->getProperty("text-position", szValue))
			&& !strcmp(szValue, "subscript")
			)
		{
			_handleAttributeOff((char) 6);  // FIXME: use defines
		}
		
		if (
			(pAP->getProperty("font-style", szValue))
			&& !strcmp(szValue, "italic")
			)
		{
			_handleAttributeOff((char) 8);  // FIXME: use defines
		}

		if (
			(pAP->getProperty("font-weight", szValue))
			&& !strcmp(szValue, "bold")
			)
		{
			_handleAttributeOff((char) 12); // FIXME: use defines
		}

		if (
			(pAP->getProperty("text-decoration", szValue))
			)
		{
			const gchar* pszDecor = szValue;

			gchar* p;
			if (!(p = g_strdup(pszDecor)))
			{
				// TODO outofmem
			}

			UT_return_if_fail(p || !pszDecor);
			gchar*	q = strtok(p, " ");

			while (q)
			{
				if (0 == strcmp(q, "line-through"))
				{
					_handleAttributeOff((char) 13);  // FIXME: use defines
				}

				q = strtok(NULL, " ");
			}

			FREEP(p);
		}
		
		if (
			(pAP->getProperty("text-decoration", szValue))
			)
		{
			const gchar* pszDecor = szValue;

			gchar* p;
			if (!(p = g_strdup(pszDecor)))
			{
				// TODO outofmem
			}

			UT_return_if_fail(p || !pszDecor);
			gchar*	q = strtok(p, " ");

			while (q)
			{
				if (0 == strcmp(q, "underline"))
				{
					_handleAttributeOff((char) 14);  // FIXME: use defines
				}

				q = strtok(NULL, " ");
			}

			FREEP(p);
		}		
	}
}
void WordPerfect_Listener::_openSpan(PT_AttrPropIndex api)
{
	if (!m_bInBlock)
	{
		return;
	}

	const PP_AttrProp * pAP = NULL;
	bool bHaveProp = m_pDocument->getAttrProp(api,&pAP);

	if (bHaveProp && pAP)
	{
		const gchar * szValue;
		
		if (
			(pAP->getProperty("text-position", szValue))
			&& !strcmp(szValue, "superscript")
			)
		{
			_handleAttributeOn((char) 5);  // FIXME: use defines
		}

		if (
			(pAP->getProperty("text-position", szValue))
			&& !strcmp(szValue, "subscript")
			)
		{
			_handleAttributeOn((char) 6);  // FIXME: use defines
		}
		
		if (
			(pAP->getProperty("font-style", szValue))
			&& !strcmp(szValue, "italic")
			)
		{
			_handleAttributeOn((char) 8);  // FIXME: use defines
		}
		
		if (
			(pAP->getProperty("font-weight", szValue))
			&& !strcmp(szValue, "bold")
			)
		{
			_handleAttributeOn((char) 12);  // FIXME: use defines
		}
		
		if (
			(pAP->getProperty("text-decoration", szValue))
			)
		{
			const gchar* pszDecor = szValue;

			gchar* p;
			if (!(p = g_strdup(pszDecor)))
			{
				// TODO outofmem
			}

			UT_return_if_fail(p || !pszDecor);
			gchar*	q = strtok(p, " ");

			while (q)
			{
				if (0 == strcmp(q, "line-through"))
				{
					_handleAttributeOn((char) 13);  // FIXME: use defines
				}

				q = strtok(NULL, " ");
			}

			FREEP(p);
		}
		
		if (
			(pAP->getProperty("text-decoration", szValue))
			)
		{
			const gchar* pszDecor = szValue;

			gchar* p;
			if (!(p = g_strdup(pszDecor)))
			{
				// TODO outofmem
			}

			UT_return_if_fail(p || !pszDecor);
			gchar*	q = strtok(p, " ");

			while (q)
			{
				if (0 == strcmp(q, "underline"))
				{
					_handleAttributeOn((char) 14);  // FIXME: use defines
				}

				q = strtok(NULL, " ");
			}

			FREEP(p);
		}

		if (
			(pAP->getProperty("color", szValue))
		    || (pAP->getProperty("font-size", szValue))
		    || (pAP->getProperty("font-family", szValue))
			|| (pAP->getProperty("bgcolor", szValue))
			)
		{
			const gchar* pszColor = NULL;
			const gchar* pszBgColor = NULL;
			const gchar* pszFontSize = NULL;
			const gchar* pszFontFamily = NULL;

			pAP->getProperty("color", pszColor);
			pAP->getProperty("font-size", pszFontSize);
			pAP->getProperty("font-family", pszFontFamily);
			pAP->getProperty("bgcolor", pszBgColor);
			
			if (pszColor)
			{
				// ...
			}
			
			if (pszFontSize)
			{
				UT_LocaleTransactor lt (LC_NUMERIC, "C");
				_handleFontSizeChange(UT_convertToPoints(pszFontSize));
			}
			
			if (pszFontFamily)
			{
				// ...
			}
			
			if (pszBgColor)
			{
				// ...
			}
		}

		m_pAP_Span = pAP;
	}
}
Example #14
0
void XAP_Dialog_Print::setDocumentPathname(const char * szDocPath)
{
	FREEP(m_szDocumentPathname);
	if (szDocPath && *szDocPath)
		m_szDocumentPathname = g_strdup(szDocPath);
}
Example #15
0
AP_Preview_PageNumbers::~AP_Preview_PageNumbers(void)
{
	FREEP(m_str);
}
Example #16
0
bool XAP_Dialog_Print::_getPrintToFilePathname(XAP_Frame * pFrame,
												 const char * szSuggestedName)
{
	UT_return_val_if_fail(pFrame,false);
	UT_ASSERT(szSuggestedName && *szSuggestedName);

	XAP_Dialog_Id id = XAP_DIALOG_ID_PRINTTOFILE;
	
	XAP_DialogFactory * pDialogFactory
		= (XAP_DialogFactory *)(pFrame->getDialogFactory());

	XAP_Dialog_FileOpenSaveAs * pDialog
		= (XAP_Dialog_FileOpenSaveAs *)(pDialogFactory->requestDialog(id));
	UT_return_val_if_fail(pDialog,false);

	pDialog->setCurrentPathname(szSuggestedName);
	pDialog->setSuggestFilename(true);

	const char ** szDescList = NULL;
	const char ** szSuffixList = NULL;
	UT_sint32 * nTypeList = NULL;
	{
		// TODO : FIX THIS!  Make this pull dynamic types from the export
		// TODO : filter list (creat that while you're at it).

		// TODO : Right now we can just feed the dialog some static filters
		// TODO : that will be ignored by Windows but will be required
		// TODO : by Unix.

		UT_uint32 filterCount = 1;

		szDescList = (const char **) UT_calloc(filterCount + 1,
														  sizeof(char *));
		szSuffixList = (const char **) UT_calloc(filterCount + 1,
															sizeof(char *));
		// HACK : this should be IEFileType
		nTypeList = (UT_sint32 *) UT_calloc(filterCount + 1,
													 sizeof(UT_sint32));

		szDescList[0] = "PostScript 2.0";
		szSuffixList[0] = "ps";
		nTypeList[0] = 0;

		pDialog->setFileTypeList(szDescList, szSuffixList, (const UT_sint32 *) nTypeList);
	}

	pDialog->runModal(pFrame);

	XAP_Dialog_FileOpenSaveAs::tAnswer ans = pDialog->getAnswer();
	bool bOK = (ans == XAP_Dialog_FileOpenSaveAs::a_OK);

	if (bOK)
		m_szPrintToFilePathname = g_strdup(pDialog->getPathname());       

	FREEP(szDescList);
	FREEP(szSuffixList);
	FREEP(nTypeList);

	pDialogFactory->releaseDialog(pDialog);
	
	return bOK;
}
Example #17
0
c_lb::~c_lb(void)
{

    FREEP(m_name);
    DELETEP (m_pebm);
}