示例#1
0
文件: sqio.c 项目: obbila/CustomWise
static void 
readGenBank(struct ReadSeqVars *V)
{
  char *sptr;
  int   in_definition;

  while (strncmp(V->sbuffer, "LOCUS", 5) != 0)
    getline2(V);

  if ((sptr = strtok(V->sbuffer+12, "\n\t ")) != NULL)
    {
      SetSeqinfoString(V->sqinfo, sptr, SQINFO_NAME);
      SetSeqinfoString(V->sqinfo, sptr, SQINFO_ID);
    }

  in_definition = FALSE;
  while (! feof(V->f))
    {
      getline2(V);
      if (! feof(V->f) && strstr(V->sbuffer, "DEFINITION") == V->sbuffer)
	{
	  if ((sptr = strtok(V->sbuffer+12, "\n")) != NULL)
	    SetSeqinfoString(V->sqinfo, sptr, SQINFO_DESC);
	  in_definition = TRUE;
	}
      else if (! feof(V->f) && strstr(V->sbuffer, "ACCESSION") == V->sbuffer)
	{
	  if ((sptr = strtok(V->sbuffer+12, "\n\t ")) != NULL)
	    SetSeqinfoString(V->sqinfo, sptr, SQINFO_ACC);
	  in_definition = FALSE;
	}
      else if (strncmp(V->sbuffer,"ORIGIN", 6) != 0)
	{
	  if (in_definition)
	    SetSeqinfoString(V->sqinfo, V->sbuffer, SQINFO_DESC);
	}
      else
	break;
    }

  readLoop(0, endGB, V);

  /* reading a real GenBank database file, we keep the source coords
   */
  V->sqinfo->start = 1;
  V->sqinfo->stop  = V->seqlen;
  V->sqinfo->olen  = V->seqlen;
  V->sqinfo->flags |= SQINFO_START | SQINFO_STOP | SQINFO_OLEN;


  while (!(feof(V->f) || ((*V->sbuffer!=0) && (strstr(V->sbuffer,"LOCUS") == V->sbuffer))))
    getline2(V);
				/* SRE: V->s now holds "//", so sequential
				   reads are wedged: fixed Tue Jul 13 1993 */
  while (!feof(V->f) && strstr(V->sbuffer, "LOCUS  ") != V->sbuffer)
    getline2(V);
}
示例#2
0
int main(int argc, char *argv[]) {
  int length = 0;
  char line[MAX_LINE_LENGTH];
  int distance;

  if(argc != 2 || !isnumerical(argv[1])) {
    usage();
    exit(EXIT_FAILURE);

  } else {
    distance = atoi(argv[1]);

  }

  while((length = getline2(line, MAX_LINE_LENGTH)) >= 0) {
    if(isnumerical(line)) {
      printf("%u\n", rightrot(atoi(line), distance));

    } else {
      exit(EXIT_FAILURE);

    }
  }

  exit(EXIT_SUCCESS);
}
示例#3
0
文件: ex.c 项目: xbot/c-ex
int main(int argc, char **argv)
{
    char s1[MAX_LINE_LEN];
    char s2[MAX_LINE_LEN];

    int m, n, m2, n2;

    m = DEFAULTSTARTCOL;
    n = DEFAULTTABWIDTH;

    while (--argc > 0) {
        argv++;
        if (**argv == '-') {
            if ((m2 = atoi(++*argv)) > 0)
                m = m2;
        } else if (**argv == '+') {
            if ((n2 = atoi(++*argv)) > 0)
                n = n2;
        }
    }
    
    printf("Usage example: entab -2 +8\n");

    printf("Input some characters, then press enter:\n");
    while (getline2(s1) == 0);

    detab(s1, s2, m, n);
    /* entab(s1, s2, m, n); */
    printf("result:\n%s\n", s2);

    return 0;
}
示例#4
0
文件: sqio.c 项目: obbila/CustomWise
static void 
readPearson(struct ReadSeqVars *V)
{
  char *sptr;

  if ((sptr = strtok(V->sbuffer+1, "\n\t ")) != NULL)
    SetSeqinfoString(V->sqinfo, sptr, SQINFO_NAME);
  if ((sptr = strtok(NULL, "\n")) != NULL)
    SetSeqinfoString(V->sqinfo, sptr, SQINFO_DESC);
				/* workaround for long NCBI NR lines */
  while (V->longline && ! feof(V->f)) getline2(V);

  readLoop(0, endPearson, V);

  while (!(feof(V->f) || ((*V->sbuffer != 0) && (*V->sbuffer == '>'))))
    getline2(V);
}
示例#5
0
int main() {
	int len;
	char line[MAXLINE];

	while((len = getline2(line, MAXLINE)) > 0) {
		fold(line, COLUMN);
	}
}
示例#6
0
文件: sqio.c 项目: obbila/CustomWise
/* Function: SeqfilePosition()
 * 
 * Purpose:  Move to a particular offset in a seqfile.
 *           Will not work on interleaved files (SELEX, MSF).
 */
void
SeqfilePosition(SQFILE *sqfp, long offset)
{
  if (sqfp->do_stdin || sqfp->do_gzip || IsInterleavedFormat(sqfp->format))
    Die("SeqfilePosition() failed: in a nonrewindable data file or stream");

  fseek(sqfp->f, offset, SEEK_SET);
  getline2(sqfp);
}
示例#7
0
文件: sqio.c 项目: obbila/CustomWise
static void
readZuker(struct ReadSeqVars *V)
{
  char *sptr;

  getline2(V);  /*s == "seqLen seqid string..."*/

  if ((sptr = strtok(V->sbuffer+6, " \t\n")) != NULL)
    SetSeqinfoString(V->sqinfo, sptr, SQINFO_NAME);

  if ((sptr = strtok(NULL, "\n")) != NULL)
    SetSeqinfoString(V->sqinfo, sptr, SQINFO_DESC);

  readLoop(0, endZuker, V);

  while (!(feof(V->f) | ((*V->sbuffer != '\0') & (*V->sbuffer == '('))))
    getline2(V);
}
int main() {
    int len;
    char line[MAXLINE];
    char longest[MAXLINE];

    while ((len = getline2(line, MAXLINE)) > 0) {
        if(len > LONGLINE)
            printf("\n The number of longest line is %d\n", len);
    }
}
示例#9
0
文件: 1-18.c 项目: jplino/TCPL
main()
{
	int c;
	char line[MAXLINE];
	
	while((getline2(line, MAXLINE)) > 0)
		if (remover(line) > 0)
			printf("%s", line);
	return 0;
}
示例#10
0
/*wypisz wiersze dłuższe niż LONGLINE*/
main()
{
	int len;		/*długość bieżącego wiersza*/
	char line[MAXLINE];	/*kopia bieżącego wiersza*/
	
	while ((len = getline2(line, MAXLINE)) > 0)
		if (len > LONGLINE)
			printf("%s", line);
	return 0;
}
示例#11
0
文件: sqio.c 项目: obbila/CustomWise
static void 
readEMBL(struct ReadSeqVars *V)
{
  char *sptr;

				/* make sure we have first line */
  while (!feof(V->f) && strncmp(V->sbuffer, "ID  ", 4) != 0)
    getline2(V);

  if ((sptr = strtok(V->sbuffer+5, "\n\t ")) != NULL)
    {
      SetSeqinfoString(V->sqinfo, sptr, SQINFO_NAME);
      SetSeqinfoString(V->sqinfo, sptr, SQINFO_ID);
    }

  do {
    getline2(V);
    if (!feof(V->f) && strstr(V->sbuffer, "AC  ") == V->sbuffer)
      {
	if ((sptr = strtok(V->sbuffer+5, ";  \t\n")) != NULL)
	  SetSeqinfoString(V->sqinfo, sptr, SQINFO_ACC);
      }
    else if (!feof(V->f) && strstr(V->sbuffer, "DE  ") == V->sbuffer)
      {
	if ((sptr = strtok(V->sbuffer+5, "\n")) != NULL)
	  SetSeqinfoString(V->sqinfo, sptr, SQINFO_DESC);
      }
  } while (! feof(V->f) && strncmp(V->sbuffer,"SQ",2) != 0);
  
  readLoop(0, endEMBL, V);

  /* reading a real EMBL database file, we keep the source coords
   */
  V->sqinfo->start = 1;
  V->sqinfo->stop  = V->seqlen;
  V->sqinfo->olen  = V->seqlen;
  V->sqinfo->flags |= SQINFO_START | SQINFO_STOP | SQINFO_OLEN;

				/* load next record's ID line */
  while (!feof(V->f) && strncmp(V->sbuffer, "ID  ", 4) != 0)
    getline2(V);
}
示例#12
0
文件: 1.21_entab.c 项目: jyli7/KR
main() {
	int len;
	char line[MAXLINE];
	char new_line[MAXLINE];
	while ((len = getline2(line, MAXLINE)) > 0)
	{
		tab_replace(line, len);
		printf("%s\n", line);
		clear_line(line, len);
	}
}
示例#13
0
文件: 1-19.c 项目: bramwelt/k_r
main()
{
    int len;
    char line[MAXLINE];

    while ((len = getline2(line, MAXLINE)) > 0) {
        reverse(line);
        printf("%s", line);
    }
    return 0;
}
示例#14
0
文件: sqio.c 项目: obbila/CustomWise
static void 
readIG(struct ReadSeqVars *V)
{
  char *nm;
				/* position past ';' comments */
  do {
    getline2(V);
  } while (! (feof(V->f) || ((*V->sbuffer != 0) && (*V->sbuffer != ';')) ));

  if (!feof(V->f))
    {
      if ((nm = strtok(V->sbuffer, "\n\t ")) != NULL)
	SetSeqinfoString(V->sqinfo, nm, SQINFO_NAME);

      readLoop(0, endIG, V);
    }
  
  while (!(feof(V->f) || ((*V->sbuffer != '\0') && (*V->sbuffer == ';'))))
    getline2(V);
}
示例#15
0
文件: sqio.c 项目: obbila/CustomWise
static void
readGCGdata(struct ReadSeqVars *V)
{
  int   binary = FALSE;		/* whether data are binary or not */
  int   blen;			/* length of binary sequence */
  
				/* first line contains ">>>>" followed by name */
  if (Strparse(">>>>([^ ]+) .+2BIT +Len: ([0-9]+)", V->sbuffer, 2) == 0) 
    {
      binary = TRUE;
      SetSeqinfoString(V->sqinfo, sqd_parse[1], SQINFO_NAME);
      blen = atoi(sqd_parse[2]);
    } 
  else if (Strparse(">>>>([^ ]+) .+ASCII +Len: [0-9]+", V->sbuffer, 1) == 0) 
    SetSeqinfoString(V->sqinfo, sqd_parse[1], SQINFO_NAME);
  else 
    Die("bogus GCGdata format? %s", V->sbuffer);

				/* second line contains free text description */
  getline2(V);
  SetSeqinfoString(V->sqinfo, V->sbuffer, SQINFO_DESC);

  if (binary) {
    /* allocate for blen characters +3... (allow for 3 bytes of slop) */
    if (blen >= V->maxseq) {
      V->maxseq = blen;
      if ((V->seq = (char *) realloc (V->seq, sizeof(char)*(V->maxseq+4)))==NULL)
	Die("malloc failed");
    }
				/* read (blen+3)/4 bytes from file */
    if (fread(V->seq, sizeof(char), (blen+3)/4, V->f) < (size_t) ((blen+3)/4))
      Die("fread failed");
    V->seqlen = blen;
				/* convert binary code to seq */
    GCGBinaryToSequence(V->seq, blen);
  }
  else readLoop(0, endGCGdata, V);
  
  while (!(feof(V->f) || ((*V->sbuffer != 0) && (*V->sbuffer == '>'))))
    getline2(V);
}
示例#16
0
文件: sqio.c 项目: obbila/CustomWise
/* Function: SeqfileRewind()
 * 
 * Purpose:  Set a sequence file back to the first sequence.
 *           How to do this varies with whether the file is an
 *           unaligned file, or an alignment file for which
 *           we're hacking sequential access.
 */
void
SeqfileRewind(SQFILE *sqfp)
{
  if (sqfp->do_stdin || sqfp->do_gzip)
    Die("SeqfileRewind() failed: in a nonrewindable data file or stream");

  if (sqfp->ali_aseqs != NULL) sqfp->ali_curridx = 0;
  else {
    rewind(sqfp->f);
    getline2(sqfp);
  }
}
示例#17
0
main()
{
	int len; /*current line length*/
	char line[MAXLINE];
	while ((len = getline2(line, MAXLINE)) > 0)
		if (len > THRESHOLD) {
			printf("%s", line);
			printf("%d", len);
		}
		
	return 0;
}
示例#18
0
int main()
{
	char line[MAXLIMIT];
	int found = 0;

	while((getline2(line, MAXLIMIT)) > 0) 
		if((strindex(line, pattern)) >= 0) {
			printf("%s", line);
			found++;
		}
	return found;
}	
示例#19
0
文件: sqio.c 项目: obbila/CustomWise
static void
readPIR(struct ReadSeqVars *V)
{
  char *sptr;
				/* load first line of entry  */
  while (!feof(V->f) && strncmp(V->sbuffer, "ENTRY", 5) != 0)
    getline2(V);
  if (feof(V->f)) return;

  if ((sptr = strtok(V->sbuffer + 15, "\n\t ")) != NULL)
    {
      SetSeqinfoString(V->sqinfo, sptr, SQINFO_NAME);
      SetSeqinfoString(V->sqinfo, sptr, SQINFO_ID);
    }
  do {
    getline2(V);
    if (!feof(V->f) && strncmp(V->sbuffer, "TITLE", 5) == 0)
      SetSeqinfoString(V->sqinfo, V->sbuffer+15, SQINFO_DESC);
    else if (!feof(V->f) && strncmp(V->sbuffer, "ACCESSION", 9) == 0)
      {
	if ((sptr = strtok(V->sbuffer+15, " \t\n")) != NULL)
	  SetSeqinfoString(V->sqinfo, sptr, SQINFO_ACC);
      }
  } while (! feof(V->f) && (strncmp(V->sbuffer,"SEQUENCE", 8) != 0));
  getline2(V);			/* skip next line, coords */

  readLoop(0, endPIR, V);

  /* reading a real PIR-CODATA database file, we keep the source coords
   */
  V->sqinfo->start = 1;
  V->sqinfo->stop  = V->seqlen;
  V->sqinfo->olen  = V->seqlen;
  V->sqinfo->flags |= SQINFO_START | SQINFO_STOP | SQINFO_OLEN;

  /* get next line
   */
  while (!feof(V->f) && strncmp(V->sbuffer, "ENTRY", 5) != 0)
    getline2(V);
}
示例#20
0
int main() {
    int length;
    char line[MAX_LINE_LENGTH];

    length = 0;

    while ((length = getline2(line, MAX_LINE_LENGTH)) >= 0) {
        reverse(line, length);
        printf("%s\n", line);
    }

    return 0;
}
示例#21
0
文件: sqio.c 项目: obbila/CustomWise
static void 
readStrider(struct ReadSeqVars *V)
{ 
  char *nm;
  
  while ((!feof(V->f)) && (*V->sbuffer == ';')) 
    {
      if (strncmp(V->sbuffer,"; DNA sequence", 14) == 0)
	{
	  if ((nm = strtok(V->sbuffer+16, ",\n\t ")) != NULL)
	    SetSeqinfoString(V->sqinfo, nm, SQINFO_NAME);
	}
      getline2(V);
    }

  if (! feof(V->f))
    readLoop(1, endStrider, V);

  /* load next line
   */
  while ((!feof(V->f)) && (*V->sbuffer != ';')) 
    getline2(V);
}
示例#22
0
/* print longest input line */
main()
{
    int len;            /* current line length */
    int max;            /* maximum length seen so far */
    char line[MAXLINE];     /* current input line */
    char longest[MAXLINE];  /* longest line saved here */

    max = 0;
    while ((len = getline2(line, MAXLINE)) > 0){
        reverse(line,len);
        printf("reversed:%s\n",line);
    }
    return 0;
}
示例#23
0
文件: 1-18.c 项目: tahnok/c-book
main()
{
  int len;
  int cleaned_len;
  char line[MAXLENGTH];
  char longest[MAXLENGTH];

  cleaned_len = 0;
  while ((len =  getline2(line, MAXLENGTH)) > 0)
  {
    if(clean(line, len) > 0)
      printf("%s", line);
  }
  return 0;
}
示例#24
0
main()
{
    int len;
    extern int max;
    extern char longest[];

    max = 0;
    while ((len = getline2()) > 0)
        if (len > max) {
            max = len;
            copy();
        }
    if (max > 0)
        printf("%s", longest);
    return 0;
}
示例#25
0
文件: sort.c 项目: bnjzer/c
int readlines(char *lineptr[], char lines[], int maxlines){
  int len, totalLength, nlines;

  nlines = 0;
  totalLength=0;
  while((len=getline2(lines, MAXLEN)) > 0){
    if (nlines >= MAXLINES){
      return -1;
    } else {
      totalLength += len;
      lineptr[nlines++] = lines;
      lines+=totalLength;
    }
  }
  return nlines;
}
示例#26
0
文件: 5_7.c 项目: taras-ko/c
/* readlines: read input lines */
int readlines(char *lineptr[], char *p, int maxlines)
{
	int len, nlines;
	char line[MAXLEN];
	nlines = 0;
	while ((len = getline2(line, MAXLEN)) > 0 )
		if (nlines >= maxlines)
			return -1;
		else {
			line[len-1] = '\0'; /* delete newline */
			strcpy(p, line);
			lineptr[nlines++] = p;
			p += len; //offseting pointer to BUF
		}
	return nlines;
}
示例#27
0
/*wypisywanie najdłuższego wiersza danych wejściowych; wersja wyspecjalizowana*/
main()
{
	int len;
	extern int max;
	extern char longest[];

	max = 0;
	while ((len = getline2()) > 0)
		if (len > max) {
			max = len;
			copy();
		}
	if (max > 0) /*był co najmniej jeden wiersz*/
		printf("%s", longest);
	return 0;
}
示例#28
0
main()
{
	int len; /*current line length*/
	int max; /*max length seen so far */
	char line[MAXLINE]; /*current input line */
	char longest[MAXLINE]; /*longest line saved here */
	
	max = 0;
	while ((len = getline2(line, MAXLINE)) > 0)
		if (len > max) {
			max = len;
			copy(longest, line);
		}
	if (max > 0) /*there was a line */
		printf("%s\n%d", longest, max);
	return 0;
}
示例#29
0
int main(int argc, char *argv[]) {
  int sorted[MAX_VALUES];
  int i, length, opt, key, result, timed = 0, iterations = 1;
  char line[MAX_LINE_LENGTH];
  clock_t time;

  // parse command-line

  while((opt = getopt(argc, argv, "tk:i:")) != -1) {
    switch (opt) {
    case 't':
      timed = 1;
      break;
    case 'k':
      key = atoi(optarg);
      break;
    case 'i':
      iterations = atoi(optarg);
      break;
    default: /* '?' */
      fprintf(stderr, "Usage: %s [-t ] [-k key]\n", argv[0]);
      exit(EXIT_FAILURE);
    }
  }

  // build the list

  for(length = 0; (getline2(line, MAX_LINE_LENGTH)) >= 0 && length < MAX_VALUES; length++) {
    sorted[length] = atoi(line);
  }

  // clocked invocation

  time = clock();

  for(i = 0; i < iterations; i++) {
    result = binsearch(key, sorted, length);
  }

  time = clock() - time;

  timed ? printf("%f\n", time * 1.0) : printf(":%i\n", result);

  exit(EXIT_SUCCESS);
}
示例#30
0
文件: sqio.c 项目: obbila/CustomWise
static void 
readLoop(int addfirst, int (*endTest)(char *,int *), struct ReadSeqVars *V)
{
  int addend = 0;
  int done   = 0;

  V->seqlen = 0;
  if (addfirst) addseq(V->sbuffer, V);
  do {
    getline2(V);
	/* feof() alone is a bug; files not necessarily \n terminated */
    if (*(V->sbuffer) == '\0' && feof(V->f))
      done = TRUE;
    done |= (*endTest)(V->sbuffer, &addend);
    if (addend || !done)
      addseq(V->sbuffer, V);
  } while (!done);
}