Exemple #1
0
Boolean LIBCALL StrToInt4 (CharPtr str, Int4Ptr longval)
{
  Nlm_Char     ch;
  Nlm_Int2     i;
  Nlm_Int2     len;
  Nlm_Char     local [64];
  Nlm_Boolean  nodigits;
  Nlm_Boolean  rsult;
  long int     val;

  rsult = FALSE;
  if (longval != NULL) {
    *longval = (Nlm_Int4) 0;
  }
  len = (Nlm_Int2) Nlm_StringLen (str);
  if (len != 0) {
    rsult = TRUE;
    nodigits = TRUE;
    for (i = 0; i < len; i++) {
      ch = str [i];
      if (ch == ' ' || ch == '+' || ch == '-') {
      } else if (ch < '0' || ch > '9') {
        rsult = FALSE;
      } else {
        nodigits = FALSE;
      }
    }
    if (nodigits) {
      rsult = FALSE;
    }
    if (rsult && longval != NULL) {
      Nlm_StringNCpy (local, str, sizeof (local));
      if (sscanf (local, "%ld", &val) == 1) {
        *longval = val;
      }
    }
  }
  return rsult;
}
Exemple #2
0
/** GET_MATRIX_PATH callback to find the path to a specified matrix.
 * Looks first in current directory, then one specified by
 * .ncbirc, then in local data directory, then env
 * variables.
 * @param matrix_name name of the matrix (e.g., BLOSUM50) [in]
 * @param is_prot protein matrix if TRUE [in]
 * @return path to matrix if found, or NULL.
 */
static char*
s_BlastFindMatrixPath(const char* matrix_name, Boolean is_prot)
{
     char* matrix_path = NULL;  /* return value. */
     char buf_path[PATH_MAX];  /* Used for path without matrix filename. */
     char buf_full[PATH_MAX];  /* used for full path with filename. */
     char* ptr = NULL;

     if (matrix_name == NULL)
       return NULL;

     /* current directory */
     if (Nlm_FileLength((char*) matrix_name) > 0)
     {
         char buf_path_2[PATH_MAX];
         Nlm_ProgramPath(buf_path, PATH_MAX);
         ptr = StringRChr (buf_path, DIRDELIMCHR);
         if (ptr != NULL)
             *ptr = '\0';
         sprintf(buf_path_2, "%s%s", buf_path, DIRDELIMSTR);
         matrix_path = StringSave(buf_path_2);
         return matrix_path;
     }
     
     /* local data directory. */
     sprintf(buf_full, "data%s%s", DIRDELIMSTR, matrix_name);
     if (Nlm_FileLength(buf_full) > 0)
     {
         char buf_path_2[PATH_MAX];
         Nlm_ProgramPath(buf_path, PATH_MAX);
         ptr = StringRChr (buf_path, DIRDELIMCHR);
         if (ptr != NULL)
             *ptr = '\0';
         sprintf(buf_path_2, "%s%sdata%s", buf_path, DIRDELIMSTR, DIRDELIMSTR);
         matrix_path = StringSave(buf_path_2);
         return matrix_path;
     }

     if(FindPath("ncbi", "ncbi", "data", buf_path, PATH_MAX)) {
            sprintf(buf_full, "%s%s", buf_path, matrix_name);
            if(FileLength(buf_full) > 0) {
                matrix_path = StringSave(buf_path);
                return matrix_path;
            } else {
                 char alphabet_type[3];     /* aa or nt */
                 if (is_prot)
                      Nlm_StringNCpy(alphabet_type, "aa", 2);
                 else
                      Nlm_StringNCpy(alphabet_type, "nt", 2);
                 alphabet_type[2] = NULLB;

                 sprintf(buf_full, "%s%s%s%s", buf_path,
                          alphabet_type, DIRDELIMSTR, matrix_name);
                 if(FileLength(buf_full) > 0)
                 {
                    matrix_path = StringSave(buf_path);
                    return matrix_path;
                 }
            }
     }

     return NULL;
}
Exemple #3
0
static Boolean
LoadMMDBIdx(CharPtr db,  CharPtr idx)
{
  FILE *f;
  Char fullpath [PATH_MAX];
  CharPtr ptr;
  Char pcBuf[100];
  CharPtr pcTest;
  Char  pcMmdb[20];
  Char  pcPdb[20];
  Uint4Ptr     pU4Pdb;
  Int4Ptr      pI4Mmdb;
  long count = 0;
  long mmdbid = 0;
  /* StrToLong stuff */
  Nlm_Char     ch;
  Nlm_Int2     i;
  Nlm_Int2     len;
  Nlm_Char     local [64];
  Nlm_Boolean  nodigits;
  Nlm_Boolean  rsult;
  long int     val;
 

  StringCpy(fullpath, db);
  StringCat(fullpath, idx);
  if ((f = FileOpen (fullpath, "r")) == NULL) 
    {
      ErrPostEx(SEV_FATAL,0,0, "MMDBInit - Failed to load MMDB index - check config file.");
      return FALSE;
    } 
   
  pcTest = fgets(pcBuf, (size_t)100, f);
  if (pcTest)
    {
      sscanf(pcBuf, "%ld", &iMMDBSize);
    }
  if ((iMMDBSize == 0) || (iMMDBSize > 100000))
    {
      ErrPostEx(SEV_FATAL,0,0, "Internal - LoadMMDBIdx() Failure 2;");
      return FALSE;
    } 
  pI4Mmdbidx = (Int4Ptr) MemNew((size_t) ((iMMDBSize)*sizeof(Int4)));
  pU4Pdbidx = (Uint4Ptr) MemNew((size_t) ((iMMDBSize)*sizeof(Uint4)));

  if ((!pI4Mmdbidx) || (!pU4Pdbidx))
    {
      ErrPostEx(SEV_FATAL,0,0, "Internal - LoadMMDBIdx() Out of Memory;");
      return FALSE;
    }
   
  pI4Mmdb = pI4Mmdbidx;
  pU4Pdb = pU4Pdbidx;
   
  do 
    {
      pcBuf[0] = '\0';
      pcTest = fgets(pcBuf,  (size_t)100,  f);
      if (pcTest)
        {
          sscanf(pcBuf, "%s%s",  pcMmdb ,  pcPdb);
          StrUpper(pcPdb);	 
          mmdbid = 0;
 	    
          /* this is code from Nlm StrToLong */
          rsult = FALSE;
          len = (Nlm_Int2) Nlm_StringLen (pcMmdb);
          if (len != 0) {
            rsult = TRUE;
            nodigits = TRUE;
            for (i = 0; i < len; i++) {
              ch = pcMmdb [i];
              if (ch == ' ' || ch == '+' || ch == '-') {
              } else if (ch < '0' || ch > '9') {
                rsult = FALSE;
              } else {
                nodigits = FALSE;
              }
            }
            if (nodigits) {
              rsult = FALSE;
            }
            if (rsult) {
              Nlm_StringNCpy (local, pcMmdb, sizeof (local));
              if (sscanf (local, "%ld", &val) == 1) {
                mmdbid = val;
              }
            }
          }

          /* printf("%ld %s %ld %ld\n", mmdbid, pcPdb, (long) count, (long) iMMDBSize-1);  */
          if ((mmdbid == 0) ||  (StringLen(pcPdb) > 4))
            {
              MMDBFini();
              ErrPostEx(SEV_FATAL,0,0, "Internal - LoadMMDBIdx() Bad Index Values");
              return FALSE;
            }
    
          *pI4Mmdb = mmdbid;
          *pU4Pdb =  HashPDBCode(pcPdb);
          pI4Mmdb++;
          pU4Pdb++;
          count++;
	}   
      if (count > (iMMDBSize))
        {
          MMDBFini();
          ErrPostEx(SEV_FATAL,0,0, "Internal - LoadMMDBIdx() Index count is wrong at top of file;");
          return FALSE;
        }
    } while (pcTest);   
  FileClose(f);
  return TRUE;
}