Ejemplo n.º 1
0
static void add (char c, char* *buf, int *buflen, int n)
{
  if (!buf)
    return ;
  if (n >= *buflen)
    { if (*buflen < 0)
	{ *buflen = -*buflen ;
	  *buf = (char*) messalloc (*buflen) ;
	}
      else
	{ char *newbuf ;
	  *buflen *= 2 ;
	  newbuf = (char*) messalloc (*buflen) ;
	  memcpy (newbuf, *buf, n) ;
	  messfree (*buf) ;
	  *buf = newbuf ;
	}
    }
  (*buf)[n] = c ;	  
}
Ejemplo n.º 2
0
static void add (char c, char* *buf, int *buflen, int n)
{
  if (n >= *buflen)
    { 
      int blen = *buflen;
      if (blen < 0)
	{ blen = -blen ;
	  *buf = (char*) messalloc (blen) ;
	}
      else
	{ blen *= 2 ;
	  if ((*buf = realloc(*buf,blen)) == NULL)
             { fprintf (stderr, "REALLOC failure reqesting %d bytes - aborting\n", blen) ;
               exit (-1) ;
             }
	}
      *buflen = blen; 
    }
  (*buf)[n] = c;
}
Ejemplo n.º 3
0
int readMatrix (char *name, int *conv, int** *mat)
{
  char matdirname[256] ;
  char fullname[512] ;
  FILE *fil ;
  char line[1024] = "#", *p;
  int i, j, nsymb, smax = 0 ;
  int symb[128] ;
  extern char* strtok (char*, const char*) ;

  if (getenv ("BLASTMAT")) 
    strcpy (matdirname, getenv ("BLASTMAT")) ;
  else
    strcpy (matdirname, "/nfs/disk100/pubseq/blastdb/") ;
  strcpy (fullname, matdirname) ;
  strcat (fullname, name) ;

  if (!(fil = fopen (name, "r")) && !(fil = fopen (fullname, "r")))
    { fprintf (stderr, "ERROR in readMatrix: could not open %s or %s\n",
	       name, matdirname) ;
      return 0 ;
    }
    
  while (!feof(fil) && *line == '#') /* comments */
    fgets (line, 1023, fil) ;

				/* character set */
  p = line ; while (*p == ' ' || *p == '\t' || *p == '\n') ++p ;
  for (i = 0 ; *p && i < 128 ; ++i)
    { symb[i] = conv[*p] ;
      if (symb[i] < -2)
	{ fprintf (stderr, "ERROR in readMatrix: illegal symbol %c\n", *p) ;
	  fclose (fil) ;
	  return 0 ;
	}
      if (symb[i] > smax)
	smax = symb[i] ;
      ++p ; while (*p == ' ' || *p == '\t' || *p == '\n') ++p ;
    }
  nsymb = i ;

  ++smax ;
  *mat = (int**) messalloc (smax * sizeof (int*)) ;
  for (i = 0 ; i < smax ; ++i)
    (*mat)[i] = (int*) messalloc (smax * sizeof (int)) ;

  for (i = 0 ; fgets(line, 1023, fil) && i < nsymb ; ++i)
    { p = line ; while (*p == ' ' || *p == '\t' || *p == '\n') ++p ;
      if (p && conv[*p] == symb[i])
	{ ++p ; while (*p == ' ' || *p == '\t' || *p == '\n') ++p ; }
      for (j = 0 ; *p && j < 128 ; ++j)
	{ if (symb[i] >= 0 && symb[j] >= 0) 
	    (*mat)[symb[i]][symb[j]] = atoi(p) ;
	  if (*p == '-') ++p ;
	  while (p && *p >= '0' && *p <= '9') ++p ;
	  while (*p == ' ' || *p == '\t' || *p == '\n') ++p ;
	}
      if (j != nsymb)
	{ fprintf (stderr, "ERROR in readMatrix: bad line: %s\n", line) ;
	  fclose (fil) ;
	  return 0 ;
	} 
    }

  fclose (fil) ;
  return 1 ;
}