Пример #1
0
int main()
{
    char r[20];
    scanf("%s",r);
    printf("%s\n",r);
    //StrReplace(r,'a','b');
    //StrReverse(r);
    //StrDelete(r,'a');
    int n=StrIndex(r,"lle",5);
    printf("%s\nn=%d\n",r,n);
}
Пример #2
0
PUBLIC int HTMemLog_callback (char * data, size_t len, char * fmt, va_list pArgs)
{
#ifdef HTDEBUG
    char buff[PRINT_BUFF_SIZE];
    int ret;
#ifdef USE_EXCLUDES
    if (StrIndex(fmt, Excludes, sizeof(Excludes)/sizeof(Excludes[0])))
        return 0;
#endif /* USE_EXCLUDES */
#ifdef USE_SYSLOG
    vsprintf(buff, fmt, pArgs);
    ret = strlen(buff);
    syslog(LOG_DEBUG, "%s\n", buff);
    if (len > 8192)
        len = 8192;
    strncpy(buff, data, len);
    buff[len] = 0;
    syslog(LOG_DEBUG, "%s\n", buff);
#else /* USE_SYSLOG */
    HTMemLog_addTime();
#ifdef HAVE_LONG_SIZE_T
    sprintf(buff, " %ld ", len);
    ret = strlen(buff);
#else
    sprintf(buff, " %d ", len);
    ret = strlen(buff);
#endif
    HTMemLog_add(buff, ret);

    if (fmt) {
        vsprintf(buff, fmt, pArgs);
        ret = strlen(buff);
        HTMemLog_add(buff, ret);
    }
    HTMemLog_add("\n", 1);

    HTMemLog_add(data, len);
    HTMemLog_add("\n", 1);
#endif /* !USE_SYSLOG */
    return ret;
#else
    return 0;
#endif /* HTDEBUG */
}
Пример #3
0
char *WriteSeq(    char *outSpec,  /* Output sequence spec              */
               SeqEntry *seq,      /* Seq Entry data structure          */
                    int  format)   /* Output format                     */
{

#define SIZE   255    /* String size                         */

char line[SIZE], header[SIZE], code[SIZE], testCode[SIZE];
char outFName[SIZE];

char *cPos, *pStrand;

int lineSize, blockSize;
int count, nOut;

Boolean twoFiles;
Boolean doText;
char errMsg[SIZE];

static char outFileName[SIZE];    /* Static because it's the return value */

FILE *outFile, *inFile;


/*
** Process available text for formats which allow freely formated text.
*/

	switch ( format ) {
	  case PIR:
	  case GCG:
	    doText = (seq->text != NULL); break;
	  default:
	    doText = 0; break;
	}

/*
** Set LineSize and BlockSize for variou formats
*/
	switch ( seq->spec->format ) {
	  case GCG:
	    lineSize = 50; blockSize= 10; break;
	  case PIR:
	  case IBI:
	    lineSize = 60; blockSize = 10; break;
	  case  IG:
	  case STRIDER:
	  default:
	    lineSize = blockSize= 80;
	}
/*
** Extract the the code from OutSpec for multi-entry files. If OutSpec just 
** has a filename then strip off the extension and use the filename as the code.
** Filenames are to the right of the equals.  
** N.B. does not yet support pathnames.
**
**    Outspec will look like either:
**
**                code=filename.ext     OR    filename.ext
*/

	if ( (cPos = strchr(outSpec,';')) ) *cPos = '\0'; /* Remove version */

	strcpy(code,outSpec);
	if ( (cPos = strchr(code,'=')) ) *cPos = '\0'; /* code=filename.ext */
	if ( (cPos = strchr(code,'.')) ) *cPos = '\0'; /* filename.ext */
	StrToUpper(code);
	strcpy(outFName,outSpec);
	if ( (cPos = strchr(outFName,'=')) ) strcpy(outFName, ++cPos);

/*
**  Are we dealing with a new or old sequence file?  Test for an existing
**  file set "twoFiles" flag accordingly.
*/

	if ( (inFile = fopen(outFName, "r")) ) {
	  if ( !(outFile = fopen(outFName, "w")) ) goto Error;
	  twoFiles = 1;
	} else {
	  if ( !(outFile = fopen(outFName, "w")) ) goto Error;
	  twoFiles = 0;
	}

/*
** Do what needs to be done to prepare the file for writing or over-writing
** the new sequence data.
**
**  PIR    - create header, read into filename until we find the entry to
**           replace or reach EOF. Save existing text if there is no new text.
**
**  IG     - Save any lines beginning with ";" these are comment characters.
**           Write out codeword.  Generate circular/linear flag.
**
**  STADEN - Translate symbols from IUPAC to STADEN, append end of sequence
**           character, "@".
**
**  GCG    - Save all text at the top of the file up to but not including the
**           line with ".." in it, unless we have new text. Convert "-"'s to
**           "."'s.  Recalculate CheckSum.  Write a new GCG descriptor line.
**
**  IBI    - Rewrite the LOCUS line and ORIGIN line.
**
**  STRIDER- Write out strider header line and sequnce title.
**
**  RAWSEQ - Do nothing.
*/

	switch ( format ) {

	  case PIR:
	    strcpy(header, ">");
	    switch (seq->type ) {
	      case  PROTEIN: strcat(header,"P1;"); break;
	      case FRAGMENT: strcat(header,"F1;"); break;
	      case      DNA: 
	        seq->circular ? strcat(header,"DC;"):strcat(header,"DL;") ; break;
	      case      RNA:
	        seq->circular ? strcat(header,"RC;"):strcat(header,"RL;") ; break;
	      case     RRNA: strcat(header,"N1;"); break;
	      case     TRNA: strcat(header,"N3;"); break;
	            default: strcat(header,"XX;"); break;
	    }
	    strcat(header, code);

	    /* 
	    ** Read in/out until the beginning of entry to be overwritten
	    **  or End of File.
	    */
	    
	    if ( twoFiles ) {
	      testCode[0] = '\0';
	      while ( fgets(line, 255, inFile) ) {
	        if( line[0] == '>') {
	          strcpy(testCode, &line[4]);
	          if ( (cPos = strchr(testCode, '\n')) ) *cPos = '\0';
	          StrToUpper(StrCollapse(testCode));
	          if( strcmp(testCode,code) == 0 ) break;
	        }  
                fputs(line,outFile);
	      }
	    }

	    /* 
	    **  Write out the header and title lines.
	    */

	    fprintf(outFile,"%s\n", header);
	    fprintf(outFile,"%s\n", seq->title);
	    break;

	/****************************************************************/

	  case IG:
	  /*
	  **  For IG format save any lines beginning with ";" these
	  **  are comment characters
	  */
	    if ( twoFiles && !doText ) {
	      while ( fgets(line, 255, inFile) ) {
	        if ( line[0] != ';' )  break;
                fputs(line,outFile);
	      }
	    } else if ( doText ) {
	      if ( seq->text ) fputs(seq->text,outFile);
	    } else
	      fprintf(outFile, "; %s\n; %s\n", seq->title,seq->desc);

	    fprintf(outFile, "%s\n", code);
	    break;

	/****************************************************************/

	   case STADEN:
	    if (seq->type >= DNA ) {
	      StrChange(seq->mem,'M','5');
	      StrChange(seq->mem,'K','6');
	      StrChange(seq->mem,'W','7');
	      StrChange(seq->mem,'S','8');
	      StrChange(seq->mem,'m','5');
	      StrChange(seq->mem,'k','6');
	      StrChange(seq->mem,'w','7');
	      StrChange(seq->mem,'s','8');
	    }
	    break;

	/****************************************************************/

	  case GCG:
	    if ( twoFiles && !doText ) {
	      while ( fgets(line, 255, inFile) ) {
	        if ( StrIndex("..",line) )  break;
                fputs(line,outFile);
	      }
	    } else if ( doText ) {
	        if ( seq->text ) fputs(seq->text,outFile);
	    } else
	      fprintf(outFile, "  %s\n  %s\n\n", seq->title,seq->desc);

	    StrChange(seq->mem,'-','.');
	    seq->checkSum = CheckSum(seq->mem);
	    fprintf(outFile, "  %s  Length: %ld  %s  Check: %d ..\n",
	            outFName, seq->length, GetTime(3), seq->checkSum);
	    fprintf(outFile,"        1 ");
	    break;
	  
	/****************************************************************/

	  case IBI:
	    fprintf(outFile,
	      "LOCUS       %s         %ld BP           UPDATED  %s\n",
	       code, seq->length, GetTime(0));
	    if ( twoFiles && !doText ) {
	      while ( fgets(line, 255, inFile) ) {
	        if ( StrIndex("LOCUS",line) ) continue;
	        if ( StrIndex("ORIGIN",line) )  break;
                fputs(line,outFile);
	      }
	    } else if ( doText && seq->text ) {
	      if ( (cPos = StrIndex("LOCUS     ",seq->text)) )
	        strcpy(seq->text,strchr(cPos,'\n'));
	      if ( (cPos = StrIndex("\nORIGIN",seq->text)) )
	        *cPos = '\0';
	      fputs(seq->text,outFile);
	    }
	    fprintf(outFile, "ORIGIN      %s\n", seq->title);
	    fprintf(outFile,"        1 ");
	    break;

	/****************************************************************/

	   case STRIDER:
	    fprintf(outFile,"; ### from DNA Strider  %s\n",GetTime(3));
	    fprintf(outFile,"; %s sequence  %s length %ld",
	      DecodeType(seq->type),seq->name,seq->length);
	    if ( seq->type <= PROTEIN )
	      fprintf(outFile," a.a. complete sequence\n; %s\n",seq->title);
	    else
	      fprintf(outFile," n.a. complete sequence\n; %s\n",seq->title);
	    break;

	/****************************************************************/

	  case RAWSEQ:
	  default:
	    break;

	}
/*
**  Write the sequence in Block/Line size.  "NOut" counts the number 
**  of symbols written in each line.  Support GCG and IBI line numbering
**  schemes.
*/

	nOut = 0;
	count = 1;
	pStrand = seq->mem;
	while( *pStrand ) {
	  fprintf(outFile, "%c", *pStrand);
	  nOut++;
	  count++;
	  if ( nOut == lineSize ) {
	    switch ( format ) {
	      case IBI:
	      case GCG:
	       fprintf(outFile,"\n%9d ",count);
	       break;
	      default:
	       fprintf(outFile, "\n");
	    }
	    nOut=0;
	  } else 
	    if ( nOut%blockSize == 0 ) fprintf(outFile, " ");
	  pStrand++;
	}

/*
** Depending on the format we have some finishing up to do.
**
** PIR     - Add the End of sequence character. Read past the old sequence
**           form the original file. If "DoText" is true, write out the new 
**           text comments, skip over the comments in the old file, if any.
**           Finally, copy the balance of the old file into the new file.
**
** IBI     - Add sequence terminator "//"
**
** IG      - Append linear/circular flag at end of sequence.
**
** STRIDER - Add sequence terminator "//"
**
** STADEN  - Add end of sequence character. Convert sequence symbols back 
**           to IUPAC.
**
** GCG     - Convert "."'s back to "-"'s. Recalc CheckSum.
*/
	
	switch ( format ) {

	  case PIR:

	    fprintf(outFile,"*\n");

	    /* Skip over sequence in the old file */

	    if ( twoFiles )
	      while ( fgets(line, 255, inFile) )
	        if( strchr(line,'*' ) ) break;

	    /* Skip over old comments, if any. */

	    if ( doText ) {
	      if ( seq->text ) fputs(seq->text,outFile);
	      if ( twoFiles )
	        while ( fgets(line, 255, inFile) )
	          if( *line == '>' ) {
	            fputs(line,outFile);
	            break;
	          }
	    }

	    /* Copy the remainder of the file */

	    if ( twoFiles ) {
	      while ( fgets(line, 255, inFile) )
	        fputs(line, outFile);
	    }
	    break;

	/****************************************************************/

	  case IBI:
	    fprintf(outFile,"\n//");  
	    break;

	/****************************************************************/

	  case IG:
	    fprintf(outFile,"%c",seq->circular ? '2' : '1');
	    break;

	/****************************************************************/

	  case STRIDER:
	    fprintf(outFile,"\n//");  
	    break;

	/****************************************************************/

	  case STADEN:
	    fprintf(outFile,"@");  
	    if (seq->type >= DNA ) {
	      StrChange(seq->mem,'5','M');
	      StrChange(seq->mem,'6','K');
	      StrChange(seq->mem,'7','W');
	      StrChange(seq->mem,'8','S');
	    }
	    break;

	/****************************************************************/

	  case GCG:
	    StrChange(seq->mem,'.','-');
	    seq->checkSum = CheckSum(seq->mem);
	    break;
	}	

	/*	fgetname(outFile, outFileName); NO IDEA PUT strcopy to compile il*/
	strcpy(outFileName,outFName);

	fclose(outFile);
	if ( twoFiles ) fclose(inFile);

	return(outFileName);

/*
** The output file could not be created.  Set error message and return
**  NULL
*/

Error:
	sprintf(errMsg, "Output file \"%s\" could not be created.", outFName);
	PostError(2,errMsg);
	return(NULL);

} /* End of WriteSeq */
Пример #4
0
static Boolean NextIndSpec(SeqSpec *indSpec, SeqSpec *thisSpec)

{
	char *cPos, line[256];
	int i;

	static SeqSpec tempSpec = {NULL,NULL,NULL,NULL,0,0,0,UNDEF};

	static char options[5][80], currIndFName[256];
	static int depth;
	static FILE *file[5];

/*
**  Is this the same indirect command file or a new one?  If so,
**  copy the filename to list at the zero level. Open the file and
**  see if it exists. Scan it for ".." to see there are any header comments
**  if ".." cannot be found start back at the top.  Read the first line
**  of the file by jumping to the "NextLine" label.  This seem a little
**  convoluted but remeber that this peice of code get executed once, from
**  then on it's a nice little dance between the "NextLine" and "NextSeqSpec"
**  labels. Read the comments, it does make sence.
*/

	if ( strcmp(currIndFName, indSpec->file) != 0 ) {
	  depth = 0;
	  if ( indSpec->file) strcpy(currIndFName, indSpec->file);
	  if ( indSpec->options) strcpy(options[depth],indSpec->options);
	  if ( (file[depth] = fopen(&indSpec->file[1], "r")) == NULL )
	    return(0);
	  while ( fgets(line, 255, file[depth]) )
	    if ( StrIndex("..", line) ) break;
	  if ( feof(file[depth]) ) rewind(file[depth]);
	  goto NextLine;
	}

/*
** At this point a Spec is either from a User file or a database.
*/

NextSeqSpec:

	if ( tempSpec.isUser ) {
	  if ( NextUserSpec(&tempSpec, thisSpec) )
	    return(1);
	} else {
	  if ( NextDBSpec(&tempSpec, thisSpec) )
	    return(1);
	}
/*
** Get a line from the indirect file(s), goto NextSeqSpec until it
** the current spec exhausts, i.e. returns false.  At which point you will
** fall through to here in order to read the next line. 
*/

NextLine:
	while ( depth >= 0 ) {
	  while ( fgets(line, 255, file[depth]) ) {
	    if ( (cPos = strchr(line, ' ')) ) *cPos = '\0';  /* First token */
	    if ( (cPos = strchr(line, '!')) ) *cPos = '\0';  /* Uncomment   */
	    if ( (cPos = strchr(line, '\n')) )*cPos = '\0';  /* String-ize  */
	    if ( line[0] == '\0' ) continue;               /* Blank line  */
	    if ( line[0] == '@' ) {                        /* Another FOSS*/
	      if ( depth < 5 ) {
	        depth++;
	        if ( (cPos = strchr(line,'/')) ) {
	          strcpy(options[depth],cPos);
	          *cPos = '\0';
	        }
	        if ( (file[depth] = fopen(&line[1], "r")) ) {
	          while ( fgets(line, 255, file[depth]) )
	            if ( StrIndex("..", line) ) break;
	          if ( feof(file[depth]) ) rewind(file[depth]);
	        } else {
	          depth--;
	        }
	      } else {
	        PostError(2,"SeqSpec lists are too deeply nested!!");
	      }
	    } else {                         /* A Sequence Spec              */
	      for ( i=depth; i>=0; i-- )     /* Append the options from every*/
	        strcat(line, options[i]);    /*   FOSS file which came before*/
	      MakeSeqSpec(&tempSpec, line);  /* Assign the SeqSpec structure */
	      goto NextSeqSpec;              /* Dispatch and run down.        */
	    }
	  }
	  fclose(file[depth]);
	  depth--;
	}
/*
**  Fall through to here when all of the Sequence Specification from all
**  of the FOSS files are finished.
*/
	currIndFName[0] = '\0';
	return(0);
}
Пример #5
0
/******************************+++********************************/
int DbCheck(const string Name)
/*****************************************************************/
/*   Purpose:  Return status of database object and add a row to */
/*             DbStatus.                                         */
/*                                                               */
/*   Returns:  INPUT_ERR, INCOMPAT_ERR, or OK.                   */
/*                                                               */
/*   Version:  1996.02.11                                        */
/*****************************************************************/
{
     DbMatrix  *D;
     int       ErrNum;
     size_t    j, Row, Index;

     if (stricmp(Name, EXP_REG) == 0)
     {
          if ( (ErrNum = RegExtract(&XDescrip, X_DESCRIP, "." FIT,
                    &ExpReg)) == OK)
               ErrNum = RegCandCompat(&Cand, &ExpReg);

     }

     else if (stricmp(Name, PRED_REG) == 0)
     {
          if ( (ErrNum = RegExtract(&XDescrip, X_DESCRIP, "." PRED,
                    &PredReg)) == OK)
               ErrNum = RegCandCompat(&Cand, &PredReg);
     }

     if (stricmp(Name, EXP_REG) == 0 ||
               stricmp(Name, PRED_REG) == 0)
     {
          if (ErrNum != OK)
          {
               Row = StrIndex(X_DESCRIP,
                         MatStrCol(&DbStatus, DB_STATUS_OBJ_COL),
                         MatNumRows(&DbStatus));
               MatPutStrElem(&DbStatus, Row, DB_STATUS_OK_COL, NO_STR);
          }
          return ErrNum;
     }

     if (MatNumRows(&DbStatus) == 0)
     {
          MatAllocate(1, NumStr(DbStatusColName), RECT, MIXED,
                    DbStatusColType, YES, &DbStatus);
          for (j = 0; j < MatNumCols(&DbStatus); j++)
               MatPutColName(&DbStatus, j, DbStatusColName[j]);
          MatPutText(&DbStatus, "Database status:\n");
     }
     else
          /* Add a new row to DbStatus. */
          MatReAlloc(MatNumRows(&DbStatus) + 1,
                    MatNumCols(&DbStatus), &DbStatus);

     /* Status information goes in this row. */
     Row = MatNumRows(&DbStatus) - 1;

     MatPutStrElem(&DbStatus, Row, DB_STATUS_OBJ_COL, Name);

     if ( (Index = DbScalIndex(Name, NO)) != INDEX_ERR)
     {
          MatPutStrElem(&DbStatus, Row, DB_STATUS_CLASS_COL,
                    "Scalar");
          ErrNum = DbScalCheck(Index);
          MatPutStrElem(&DbStatus, Row, DB_STATUS_VAL_COL,
                    DbScalValue(Index));
          MatPutSize_tElem(&DbStatus, Row, DB_STATUS_ROWS_COL,
                    NA_SIZE_T);
          MatPutSize_tElem(&DbStatus, Row, DB_STATUS_COLS_COL,
                    NA_SIZE_T);

          if (ErrNum == OK && stricmp(Name, DESIGN_CRIT) == 0)
               /* Errors in subsequent input ignored. */
               CritInput(CritNum);
     }
     else
     {
          MatPutStrElem(&DbStatus, Row, DB_STATUS_CLASS_COL,
                    "Matrix");
          D = DbMatFind(Name, YES);

          ErrNum = DbMatCheck(D,
                    &MatStrElem(&DbStatus, Row, DB_STATUS_VAL_COL));
          MatPutSize_tElem(&DbStatus, Row, DB_STATUS_ROWS_COL,
                    D->M->NumRows);
          MatPutSize_tElem(&DbStatus, Row, DB_STATUS_COLS_COL,
                    D->M->NumCols);

          if (D->IsOutput == YES ||
                    ((stricmp(Name, REG_MOD) == 0 ||
                    stricmp(Name, SP_MOD) == 0) &&
                    stricmp(FuncName, "Fit") == 0))
               /* Store the matrix title as the row name:  */
               /* Will be used later in DbOutputMatStatus. */
               MatPutRowName(&DbStatus, Row, D->Title);
     }

     MatPutStrElem(&DbStatus, Row, DB_STATUS_OK_COL, (ErrNum == OK) ?
               YES_STR : NO_STR);

     /* Always override defaults. */
     if (stricmp(Name, RAN_NUM_SEED) == 0)
          RandInit(Seed, Seed, Seed);

     return ErrNum;
}