Ejemplo n.º 1
0
char *Locate_Filename(char *filename, unsigned int stype, bool err_flag)
{
  int i,ii,l[4];
  char pathname[FILE_NAME_LENGTH];
  char file[FILE_NAME_LENGTH];
  char file_x[4][FILE_NAME_LENGTH];
  char *result = NULL;

  if (Has_Extension(filename))
  {
    for(i = 0; i < 4; i++)
      l[i]=0;
  }
  else
  {
    for(i = 0; i < 4; i++)
    {
      if ((l[i] = strlen(gPOV_File_Extensions[stype].ext[i])) > 0)
      {
        strcpy(file_x[i], filename);
        strcat(file_x[i], gPOV_File_Extensions[stype].ext[i]);
      }
    }
  }

  /* Check the current directory first. */
  for(i = 0; i < 4; i++)
  {
    /* Try appending the variations of the file extension */
    if(l[i])
    {
      if (EXIST_FILE(file_x[i]) == true)
      {
        result = new char[strlen(file_x[i]) + 1];
        POV_GET_FULL_PATH(file_x[i], result);
        return result;
      }
    }
  }
  /* Try the filename without any modifications */
  if (EXIST_FILE(filename) == true)
  {
    result = new char[strlen(filename) + 1];
    POV_GET_FULL_PATH(filename, result);
    return result;
  }
  
  /* Walk through the library paths, trying with and without file extensions */
  for (i = 0; i < opts.Library_Path_Index; i++)
  {
    strcpy(file, opts.Library_Paths[i]);
    file[strlen(file)+1] = '\0';
    if (file[strlen(file) - 1] != DRIVE_SEPARATOR)
      file[strlen(file)] = FILENAME_SEPARATOR;
    
    for(ii = 0; ii < 4; ii++)
    {
      if(l[ii])
      {
        strcpy(pathname, file);
        strcat(pathname, file_x[ii]);
        if (EXIST_FILE(pathname) == true)
        {
          result = new char[strlen(pathname) + 1];
          POV_GET_FULL_PATH(pathname, result);
          return result;
        }
      }
    }
    
    strcpy(pathname, file);
    strcat(pathname, filename);
    if (EXIST_FILE(pathname) == true)
    {
      result = new char[strlen(pathname) + 1];
      POV_GET_FULL_PATH(pathname, result);
      return result;
    }
  }

  // Allow system specific access of font files:
  // Obviously this requires POV_NEW_ISTREAM
  // to be platform specific as well! [trf]
  if(stype == POV_File_Font_TTF)
  {
    if(EXIST_FONT_FILE(filename))
    {
       result = new char[strlen(filename) + 1];
       strcpy(filename, result);
       return result;
    }
  }

  if (err_flag)
  {
    if (l[0])
      PossibleError("Could not find file '%s%s'",filename,gPOV_File_Extensions[stype].ext[0]);
    else
      PossibleError("Could not find file '%s'",filename);
  }
  
  return NULL;
}
Ejemplo n.º 2
0
ITextStream *ProcessRenderOptions::OpenINIFileStream(const char *filename, unsigned int stype, char *buffer, POVMSObjectPtr obj)
{
    int i,ii,l[4];
    char pathname[FILE_NAME_LENGTH];
    char file[FILE_NAME_LENGTH];
    char file_x[4][FILE_NAME_LENGTH];
    int cnt = 0;
    int ll;
    POVMSAttribute attr, item;

    if(Has_Extension(filename))
    {
        for(i = 0; i < 4; i++)
            l[i]=0;
    }
    else
    {
        for(i = 0; i < 4; i++)
        {
            if((l[i] = strlen(gPOV_File_Extensions[stype].ext[i])) > 0)
            {
                strcpy(file_x[i], filename);
                strcat(file_x[i], gPOV_File_Extensions[stype].ext[i]);
            }
        }
    }

    // Check the current directory first
    for(i = 0; i < 4; i++)
    {
        if(l[i])
        {
            if(EXIST_FILE(file_x[i]) == true)
            {
                strcpy(buffer,file_x[i]);
                return new ITextStream(file_x[i], stype);
            }
        }
    }
    if(EXIST_FILE(filename) == true)
    {
        strcpy(buffer,filename);
        return new ITextStream(filename, stype);
    }

    if(POVMSObject_Get(obj, &attr, kPOVAttrib_LibraryPath) != 0)
        return NULL;

    if(POVMSAttrList_Count(&attr, &cnt) != 0)
    {
        (void)POVMSAttrList_Delete(&attr);
        return NULL;
    }

    for (i = 1; i <= cnt; i++)
    {
        (void)POVMSAttr_New(&item);
        if(POVMSAttrList_GetNth(&attr, i, &item) != 0)
            continue;
        ll = 0;
        if(POVMSAttr_Size(&item, &ll) != 0)
        {
            (void)POVMSAttr_Delete(&item);
            continue;
        }
        if(ll <= 0)
        {
            (void)POVMSAttr_Delete(&item);
            continue;
        }
        if(POVMSAttr_Get(&item, kPOVMSType_CString, file, &ll) != 0)
        {
            (void)POVMSAttr_Delete(&item);
            continue;
        }
        (void)POVMSAttr_Delete(&item);

        file[strlen(file)+1] = '\0';
        if(file[strlen(file) - 1] != DRIVE_SEPARATOR)
            file[strlen(file)] = FILENAME_SEPARATOR;

        for(ii = 0; ii < 4; ii++)
        {
            if(l[ii])
            {
                strcpy(pathname, file);
                strcat(pathname, file_x[ii]);
                if(EXIST_FILE(pathname) == true)
                {
                    strcpy(buffer,pathname);
                    (void)POVMSAttrList_Delete(&attr);
                    return new ITextStream(pathname, stype);
                }
            }
        }
        strcpy(pathname, file);
        strcat(pathname, filename);
        if(EXIST_FILE(pathname) == true)
        {
            strcpy(buffer,pathname);
            (void)POVMSAttrList_Delete(&attr);
            return new ITextStream(pathname, stype);
        }
    }

    (void)POVMSAttrList_Delete(&attr);

    if(l[0])
        ParseError("Could not find file '%s%s'", filename, gPOV_File_Extensions[stype].ext[0]);
    else
        ParseError("Could not find file '%s'", filename);

    return NULL;
}