コード例 #1
0
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                                             %
%                                                                             %
%                                                                             %
%  G e t C o n f i g u r e P a t h s                                          %
%                                                                             %
%                                                                             %
%                                                                             %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  GetConfigurePaths() returns any Magick configuration paths associated
%  with the specified filename.
%
%  The format of the GetConfigurePaths method is:
%
%      LinkedListInfo *GetConfigurePaths(const char *filename,
%        ExceptionInfo *exception)
%
%  A description of each parameter follows:
%
%    o filename: the configure file name.
%
%    o exception: return any errors or warnings in this structure.
%
*/
MagickExport LinkedListInfo *GetConfigurePaths(const char *filename,
  ExceptionInfo *exception)
{
#define RegistryKey  "ConfigurePath"
#define MagickCoreDLL  "CORE_RL_magick_.dll"
#define MagickCoreDebugDLL  "CORE_DB_magick_.dll"

  char
    path[MaxTextExtent];

  LinkedListInfo
    *paths;

  assert(filename != (const char *) NULL);
  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",filename);
  assert(exception != (ExceptionInfo *) NULL);
  (void) CopyMagickString(path,filename,MaxTextExtent);
  paths=NewLinkedList(0);
  {
    char
      *configure_path;

    /*
      Search $MAGICK_CONFIGURE_PATH.
    */
    configure_path=GetEnvironmentValue("MAGICK_CONFIGURE_PATH");
    if (configure_path != (char *) NULL)
      {
        register char
          *p,
          *q;

        for (p=configure_path-1; p != (char *) NULL; )
        {
          (void) CopyMagickString(path,p+1,MaxTextExtent);
          q=strchr(path,DirectoryListSeparator);
          if (q != (char *) NULL)
            *q='\0';
          q=path+strlen(path)-1;
          if ((q >= path) && (*q != *DirectorySeparator))
            (void) ConcatenateMagickString(path,DirectorySeparator,
              MaxTextExtent);
          (void) AppendValueToLinkedList(paths,ConstantString(path));
          p=strchr(p+1,DirectoryListSeparator);
        }
        configure_path=DestroyString(configure_path);
      }
  }
#if defined(MAGICKCORE_INSTALLED_SUPPORT)
#if defined(MAGICKCORE_SHARE_PATH)
  (void) AppendValueToLinkedList(paths,ConstantString(MAGICKCORE_SHARE_PATH));
#endif
#if defined(MAGICKCORE_SHAREARCH_PATH)
  (void) AppendValueToLinkedList(paths,ConstantString(
    MAGICKCORE_SHAREARCH_PATH));
#endif
#if defined(MAGICKCORE_CONFIGURE_PATH)
  (void) AppendValueToLinkedList(paths,ConstantString(
    MAGICKCORE_CONFIGURE_PATH));
#endif
#if defined(MAGICKCORE_DOCUMENTATION_PATH)
  (void) AppendValueToLinkedList(paths,ConstantString(
    MAGICKCORE_DOCUMENTATION_PATH));
#endif
#if defined(MAGICKCORE_WINDOWS_SUPPORT) && !(defined(MAGICKCORE_CONFIGURE_PATH) || defined(MAGICKCORE_SHARE_PATH))
  {
    unsigned char
      *key_value;

    /*
      Locate file via registry key.
    */
    key_value=NTRegistryKeyLookup(RegistryKey);
    if (key_value != (unsigned char *) NULL)
      {
        (void) FormatLocaleString(path,MaxTextExtent,"%s%s",(char *) key_value,
          DirectorySeparator);
        (void) AppendValueToLinkedList(paths,ConstantString(path));
        key_value=(unsigned char *) RelinquishMagickMemory(key_value);
      }
  }
#endif
#else
  {
    char
      *home;

    /*
      Search under MAGICK_HOME.
    */
    home=GetEnvironmentValue("MAGICK_HOME");
    if (home != (char *) NULL)
      {
#if !defined(MAGICKCORE_POSIX_SUPPORT)
        (void) FormatLocaleString(path,MaxTextExtent,"%s%s",home,
          DirectorySeparator);
        (void) AppendValueToLinkedList(paths,ConstantString(path));
#else
        (void) FormatLocaleString(path,MaxTextExtent,"%s/etc/%s/",home,
          MAGICKCORE_CONFIGURE_RELATIVE_PATH);
        (void) AppendValueToLinkedList(paths,ConstantString(path));
        (void) FormatLocaleString(path,MaxTextExtent,"%s/share/%s/",home,
          MAGICKCORE_SHARE_RELATIVE_PATH);
        (void) AppendValueToLinkedList(paths,ConstantString(path));
#endif
        home=DestroyString(home);
      }
    }
  if (*GetClientPath() != '\0')
    {
#if !defined(MAGICKCORE_POSIX_SUPPORT)
      (void) FormatLocaleString(path,MaxTextExtent,"%s%s",GetClientPath(),
        DirectorySeparator);
      (void) AppendValueToLinkedList(paths,ConstantString(path));
#else
      char
        prefix[MaxTextExtent];

      /*
        Search based on executable directory if directory is known.
      */
      (void) CopyMagickString(prefix,GetClientPath(),MaxTextExtent);
      ChopPathComponents(prefix,1);
      (void) FormatLocaleString(path,MaxTextExtent,"%s/etc/%s/",prefix,
        MAGICKCORE_CONFIGURE_RELATIVE_PATH);
      (void) AppendValueToLinkedList(paths,ConstantString(path));
      (void) FormatLocaleString(path,MaxTextExtent,"%s/share/%s/",prefix,
        MAGICKCORE_SHARE_RELATIVE_PATH);
      (void) AppendValueToLinkedList(paths,ConstantString(path));
#endif
    }
  /*
    Search current directory.
  */
  (void) AppendValueToLinkedList(paths,ConstantString(""));
#endif
  {
    char
      *home;

    home=GetEnvironmentValue("HOME");
    if (home == (char *) NULL)
      home=GetEnvironmentValue("USERPROFILE");
    if (home != (char *) NULL)
      {
        /*
          Search $HOME/.magick.
        */
        (void) FormatLocaleString(path,MaxTextExtent,"%s%s.magick%s",home,
          DirectorySeparator,DirectorySeparator);
        (void) AppendValueToLinkedList(paths,ConstantString(path));
        home=DestroyString(home);
      }
  }
#if defined(MAGICKCORE_WINDOWS_SUPPORT)

  {
    char
      module_path[MaxTextExtent];

    if ((NTGetModulePath(MagickCoreDLL,module_path) != MagickFalse) ||
        (NTGetModulePath(MagickCoreDebugDLL,module_path) != MagickFalse))
      {
        unsigned char
          *key_value;

        /*
          Search module path.
        */
        (void) FormatLocaleString(path,MaxTextExtent,"%s%s",module_path,
          DirectorySeparator);
        key_value=NTRegistryKeyLookup(RegistryKey);
        if (key_value == (unsigned char *) NULL)
          (void) AppendValueToLinkedList(paths,ConstantString(path));
        else
          key_value=(unsigned char *) RelinquishMagickMemory(key_value);
      }
    if (NTGetModulePath("Magick.dll",module_path) != MagickFalse)
      {
        /*
          Search PerlMagick module path.
        */
        (void) FormatLocaleString(path,MaxTextExtent,"%s%s",module_path,
          DirectorySeparator);
        (void) AppendValueToLinkedList(paths,ConstantString(path));
        (void) FormatLocaleString(path,MaxTextExtent,"%s%s",module_path,
          "\\inc\\lib\\auto\\Image\\Magick\\");
        (void) AppendValueToLinkedList(paths,ConstantString(path));
      }
  }
#endif
  return(paths);
}
コード例 #2
0
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                                             %
%                                                                             %
%                                                                             %
%  G e t C o n f i g u r e P a t h s                                          %
%                                                                             %
%                                                                             %
%                                                                             %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  GetConfigurePaths() returns any Wizard configuration paths associated
%  with the specified filename.
%
%  The format of the GetConfigurePaths method is:
%
%      LinkedListInfo *GetConfigurePaths(const char *filename,
%        ExceptionInfo *exception)
%
%  A description of each parameter follows:
%
%    o filename: The configure file name.
%
%    o exception: Return any errors or warnings in this structure.
%
*/
WizardExport LinkedListInfo *GetConfigurePaths(const char *filename,
  ExceptionInfo *exception)
{
#define RegistryKey  "ConfigurePath"
#define WizardsToolkitDLL  "Wizard's Toolkit.dll"

  char
    path[WizardPathExtent];

  LinkedListInfo
    *paths;

  assert(filename != (const char *) NULL);
  (void) LogWizardEvent(TraceEvent,GetWizardModule(),"%s",filename);
  assert(exception != (ExceptionInfo *) NULL);
  (void) CopyWizardString(path,filename,WizardPathExtent);
  paths=NewLinkedList(0);
  {
    char
      *configure_path;

    register char
      *q;

    register const char
      *p;

    /*
      Search WIZARD_CONFIGURE_PATH.
    */
    configure_path=GetEnvironmentValue("WIZARD_CONFIGURE_PATH");
    if (configure_path != (char *) NULL)
      {
        for (p=configure_path-1; p != (char *) NULL; )
        {
          (void) CopyWizardString(path,p+1,WizardPathExtent);
          q=strchr(path,DirectoryListSeparator);
          if (q != (char *) NULL)
            *q='\0';
          q=path+strlen(path)-1;
          if ((q >= path) && (*q != *DirectorySeparator))
            (void) ConcatenateWizardString(path,DirectorySeparator,
              WizardPathExtent);
          (void) AppendValueToLinkedList(paths,AcquireString(path));
          p=strchr(p+1,DirectoryListSeparator);
        }
        configure_path=(char *) RelinquishWizardMemory(configure_path);
      }
  }
#if defined(WIZARDSTOOLKIT_INSTALLED_SUPPORT)
#if defined(WIZARDSTOOLKIT_CONFIGURE_PATH)
  (void) AppendValueToLinkedList(paths,AcquireString(
    WIZARDSTOOLKIT_CONFIGURE_PATH));
#endif
#if defined(WIZARDSTOOLKIT_SHARE_PATH)
  (void) AppendValueToLinkedList(paths,AcquireString(
    WIZARDSTOOLKIT_SHARE_PATH));
#endif
#if defined(WIZARDSTOOLKIT_SHAREARCH_PATH)
  (void) AppendValueToLinkedList(paths,ConstantString(
    WIZARDSTOOLKIT_SHAREARCH_PATH));
#endif
#if defined(WIZARDSTOOLKIT_DOCUMENTATION_PATH)
  (void) AppendValueToLinkedList(paths,AcquireString(
    WIZARDSTOOLKIT_DOCUMENTATION_PATH));
#endif
#if defined(WIZARDSTOOLKIT_SHARE_PATH)
  (void) AppendValueToLinkedList(paths,AcquireString(
    WIZARDSTOOLKIT_SHARE_PATH));
#endif
#if defined(WIZARDSTOOLKIT_WINDOWS_SUPPORT) && !(defined(WIZARDSTOOLKIT_CONFIGURE_PATH) || defined(WIZARDSTOOLKIT_SHARE_PATH))
  {
    unsigned char
      *key_value;

    /*
      Locate file via registry key.
    */
    key_value=NTRegistryKeyLookup(RegistryKey);
    if (key_value != (unsigned char *) NULL)
      {
        (void) FormatLocaleString(path,WizardPathExtent,"%s%s",(char *) key_value,
          DirectorySeparator);
        (void) AppendValueToLinkedList(paths,ConstantString(path));
        key_value=(unsigned char *) RelinquishWizardMemory(key_value);
      }
  }
#endif
#else
  {
    char
      *home;

    /*
      Search under WIZARD_HOME.
    */
    home=GetEnvironmentValue("WIZARD_HOME");
		if (home != (char *) NULL)
      {
#if !defined(WIZARDSTOOLKIT_POSIX_SUPPORT)
        (void) FormatLocaleString(path,WizardPathExtent,
          "%s%s.config%sWizardsToolkit%s",home,DirectorySeparator,
          DirectorySeparator,DirectorySeparator);
        (void) AppendValueToLinkedList(paths,AcquireString(path));
#else
        (void) FormatLocaleString(path,WizardPathExtent,"%s/etc/%s/",home,
          WIZARDSTOOLKIT_CONFIGURE_RELATIVE_PATH);
        (void) AppendValueToLinkedList(paths,AcquireString(path));
        (void) FormatLocaleString(path,WizardPathExtent,"%s/share/%s/",home,
          WIZARDSTOOLKIT_SHARE_RELATIVE_PATH);
        (void) AppendValueToLinkedList(paths,AcquireString(path));
        (void) FormatLocaleString(path,WizardPathExtent,"%s",
          WIZARDSTOOLKIT_SHAREARCH_PATH);
        (void) AppendValueToLinkedList(paths,AcquireString(path));
#endif
        home=(char *) RelinquishWizardMemory(home);
      }
    }
  if (*GetClientPath() != '\0')
    {
#if !defined(WIZARDSTOOLKIT_POSIX_SUPPORT)
      (void) FormatLocaleString(path,WizardPathExtent,"%s%s",GetClientPath(),
        DirectorySeparator);
      (void) AppendValueToLinkedList(paths,AcquireString(path));
#else
      char
        prefix[WizardPathExtent];

      /*
        Search based on executable directory if directory is known.
      */
      (void) CopyWizardString(prefix,GetClientPath(),WizardPathExtent);
      ChopPathComponents(prefix,1);
      (void) FormatLocaleString(path,WizardPathExtent,"%s/etc/%s/",prefix,
        WIZARDSTOOLKIT_CONFIGURE_RELATIVE_PATH);
      (void) AppendValueToLinkedList(paths,AcquireString(path));
      (void) FormatLocaleString(path,WizardPathExtent,"%s/share/%s/",prefix,
        WIZARDSTOOLKIT_SHARE_RELATIVE_PATH);
      (void) AppendValueToLinkedList(paths,AcquireString(path));
      (void) FormatLocaleString(path,WizardPathExtent,"%s",
        WIZARDSTOOLKIT_SHAREARCH_PATH);
      (void) AppendValueToLinkedList(paths,AcquireString(path));
#endif
    }
  /*
    Search current directory.
  */
  (void) AppendValueToLinkedList(paths,AcquireString(""));
#endif
  {
    char
      *home;

    home=GetEnvironmentValue("XDG_CONFIG_HOME");
    if (home == (char *) NULL)
      home=GetEnvironmentValue("LOCALAPPDATA");
    if (home == (char *) NULL)
      home=GetEnvironmentValue("APPDATA");
    if (home == (char *) NULL)
      home=GetEnvironmentValue("USERPROFILE");
    if (home != (char *) NULL)
      {
        /*
          Search $XDG_CONFIG_HOME/ImageMagick.
        */
        (void) FormatLocaleString(path,WizardPathExtent,
          "%s%sWizardsToolkit%s%s",home,DirectorySeparator,DirectorySeparator,
          filename);
        (void) AppendValueToLinkedList(paths,ConstantString(path));
        home=DestroyString(home);
      }
    home=GetEnvironmentValue("HOME");
    if (home != (char *) NULL)
      {
        /*
          Search $HOME/.config/WizardsToolkit.
        */
        (void) FormatLocaleString(path,WizardPathExtent,
          "%s%s.config%sWizardsToolkit%s",home,DirectorySeparator,
          DirectorySeparator,DirectorySeparator);
        (void) AppendValueToLinkedList(paths,AcquireString(path));
        home=(char *) RelinquishWizardMemory(home);
      }
  }
#if defined(WIZARDSTOOLKIT_WINDOWS_SUPPORT)
  {
    char
      module_path[WizardPathExtent];

    if (NTGetModulePath(WizardsToolkitDLL,module_path) != WizardFalse)
      {
        unsigned char
          *key_value;

        /*
          Search module path.
        */
        (void) FormatLocaleString(path,WizardPathExtent,"%s%s",module_path,
          DirectorySeparator);
        key_value=NTRegistryKeyLookup(RegistryKey);
        if (key_value == (unsigned char *) NULL)
          (void) AppendValueToLinkedList(paths,ConstantString(path));
        else
          key_value=(unsigned char *) RelinquishWizardMemory(key_value);
       }
  }
#endif
  return(paths);
}