typedef struct _GhostInfo
{
+ void
+ (MagickDLLCall *delete_instance)(gs_main_instance *);
+
int
(MagickDLLCall *exit)(gs_main_instance *);
int
(MagickDLLCall *run_string)(gs_main_instance *,const char *,int,int *);
- void
- (MagickDLLCall *delete_instance)(gs_main_instance *);
+ int
+ (MagickDLLCall *set_stdio)(gs_main_instance *,int(MagickDLLCall *)(void *,
+ char *,int),int(MagickDLLCall *)(void *,const char *,int),
+ int(MagickDLLCall *)(void *,const char *,int));
} GhostInfo;
extern MagickPrivate MagickBooleanType
if (ghost_handle == (void *) NULL)
return(FALSE);
(void) ResetMagickMemory((void *) &ghost_info,0,sizeof(GhostInfo));
+ ghost_info.delete_instance=(void (MagickDLLCall *) (gs_main_instance *)) (
+ lt_dlsym(ghost_handle,"gsapi_delete_instance"));
ghost_info.exit=(int (MagickDLLCall *)(gs_main_instance*))
lt_dlsym(ghost_handle,"gsapi_exit");
ghost_info.init_with_args=(int (MagickDLLCall *)(gs_main_instance *,int,
lt_dlsym(ghost_handle,"gsapi_new_instance"));
ghost_info.run_string=(int (MagickDLLCall *)(gs_main_instance *,const char *,
int,int *)) (lt_dlsym(ghost_handle,"gsapi_run_string"));
- ghost_info.delete_instance=(void (MagickDLLCall *) (gs_main_instance *)) (
- lt_dlsym(ghost_handle,"gsapi_delete_instance"));
- if ((ghost_info.exit == NULL) || (ghost_info.init_with_args == NULL) ||
- (ghost_info.new_instance == NULL) || (ghost_info.run_string == NULL) ||
- (ghost_info.delete_instance == NULL))
+ ghost_info.set_stdio=(int (MagickDLLCall *)(gs_main_instance *,int(
+ MagickDLLCall *)(void *,char *,int),int(MagickDLLCall *)(void *,
+ const char *,int),int(MagickDLLCall *)(void *,const char *,int)))
+ (lt_dlsym(ghost_handle,"gsapi_set_stdio"));
+ if ((ghost_info.delete_instance == NULL) || (ghost_info.exit == NULL) ||
+ (ghost_info.init_with_args == NULL) || (ghost_info.new_instance == NULL)
+ || (ghost_info.run_string == NULL) || (ghost_info.set_stdio == NULL)
+ )
return(FALSE);
return(TRUE);
}
#endif
if (status < 0)
(void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
- "'%s' (%d)",command,status);
+ "FailedToExecuteCommand","`%s' (%d)",command,status);
if (shell_command != command)
shell_command=DestroyString(shell_command);
for (i=0; i < (ssize_t) number_arguments; i++)
% o exception: return any errors or warnings in this structure.
%
*/
+static int MagickDLLCall PDFDelegateMessage(void *handle,const char *msg,
+ int len)
+{
+ char
+ **messages;
+
+ size_t offset;
+
+ offset=0;
+ messages=(char **)handle;
+ if (*messages == (char *) NULL)
+ *messages=(char *) AcquireQuantumMemory(len+1,sizeof(char *));
+ else
+ {
+ offset=strlen(*messages);
+ *messages=(char *) ResizeQuantumMemory(*messages,offset+len+1,
+ sizeof(char *));
+ }
+ (void) memcpy(*messages+offset,msg,len);
+ (*messages)[offset+len] ='\0';
+ return(len);
+}
+
static MagickBooleanType InvokePDFDelegate(const MagickBooleanType verbose,
const char *command,ExceptionInfo *exception)
{
+#define SetArgsStart \
+ if (args_start == (const char *) NULL) \
+ { \
+ if (command[0] != '"') \
+ args_start=strchr(command,' '); \
+ else \
+ { \
+ args_start=strchr(command+1,'"'); \
+ if (args_start != (const char *) NULL) \
+ args_start++; \
+ } \
+ }
+
+ const char
+ *args_start=NULL;
+
int
status;
#if defined(MAGICKCORE_GS_DELEGATE) || defined(MAGICKCORE_WINDOWS_SUPPORT)
char
- **argv;
+ **argv,
+ *errors;
const GhostInfo
*ghost_info;
ghost_info=(&ghost_info_struct);
(void) ResetMagickMemory(&ghost_info,0,sizeof(ghost_info));
+ ghost_info_struct.delete_instance=(void (*)(gs_main_instance *))
+ gsapi_delete_instance;
+ ghost_info_struct.exit=(int (*)(gs_main_instance *)) gsapi_exit;
ghost_info_struct.new_instance=(int (*)(gs_main_instance **,void *))
gsapi_new_instance;
ghost_info_struct.init_with_args=(int (*)(gs_main_instance *,int,char **))
gsapi_init_with_args;
ghost_info_struct.run_string=(int (*)(gs_main_instance *,const char *,int,
int *)) gsapi_run_string;
- ghost_info_struct.delete_instance=(void (*)(gs_main_instance *))
- gsapi_delete_instance;
- ghost_info_struct.exit=(int (*)(gs_main_instance *)) gsapi_exit;
+ ghost_info_struct.set_stdio=(int (*)(gs_main_instance *,int(*)(void *,char *,
+ int),int(*)(void *,const char *,int),int(*)(void *, const char *, int)))
+ gsapi_set_stdio;
#endif
if (ghost_info == (GhostInfo *) NULL)
{
if (verbose != MagickFalse)
{
(void) fputs("[ghostscript library]",stdout);
- (void) fputs(strchr(command,' '),stdout);
+ SetArgsStart
+ (void) fputs(args_start,stdout);
}
- status=(ghost_info->new_instance)(&interpreter,(void *) NULL);
+ errors=(char *) NULL;
+ status=(ghost_info->new_instance)(&interpreter,(void *) &errors);
if (status < 0)
{
status=SystemCommand(MagickFalse,verbose,command,exception);
argv=StringToArgv(command,&argc);
if (argv == (char **) NULL)
return(MagickFalse);
+ (void) (ghost_info->set_stdio)(interpreter,(int(MagickDLLCall *)(void *,
+ char *,int)) NULL,PDFDelegateMessage,PDFDelegateMessage);
status=(ghost_info->init_with_args)(interpreter,argc-1,argv+1);
if (status == 0)
status=(ghost_info->run_string)(interpreter,"systemdict /start get exec\n",
argv=(char **) RelinquishMagickMemory(argv);
if ((status != 0) && (status != -101))
{
- char
- *message;
-
- message=GetExceptionMessage(errno);
+ SetArgsStart
(void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
- "`%s': %s",command,message);
- message=DestroyString(message);
+ "PDFDelegateFailed","`[ghostscript library]%s': %s",args_start,
+ errors);
+ if (errors != (char *) NULL)
+ errors=DestroyString(errors);
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
"Ghostscript returns status %d, exit code %d",status,code);
return(MagickFalse);
}
+ if (errors != (char *) NULL)
+ errors=DestroyString(errors);
return(MagickTrue);
#else
status=SystemCommand(MagickFalse,verbose,command,exception);
read_info=DestroyImageInfo(read_info);
if (pdf_image == (Image *) NULL)
{
- ThrowFileException(exception,DelegateError,"PostscriptDelegateFailed",
- image_info->filename);
image=DestroyImage(image);
return((Image *) NULL);
}
% o exception: return any errors or warnings in this structure.
%
*/
+static int MagickDLLCall PostscriptDelegateMessage(void *handle,
+ const char *msg,int len)
+{
+ char
+ **messages;
+
+ size_t offset;
+
+ offset=0;
+ messages=(char **)handle;
+ if (*messages == (char *) NULL)
+ *messages=(char *) AcquireQuantumMemory(len+1,sizeof(char *));
+ else
+ {
+ offset=strlen(*messages);
+ *messages=(char *) ResizeQuantumMemory(*messages,offset+len+1,
+ sizeof(char *));
+ }
+ (void) memcpy(*messages+offset,msg,len);
+ (*messages)[offset+len] ='\0';
+ return(len);
+}
+
static MagickBooleanType InvokePostscriptDelegate(
const MagickBooleanType verbose,const char *command,ExceptionInfo *exception)
{
+#define SetArgsStart \
+ if (args_start == (const char *) NULL) \
+ { \
+ if (command[0] != '"') \
+ args_start=strchr(command,' '); \
+ else \
+ { \
+ args_start=strchr(command+1,'"'); \
+ if (args_start != (const char *) NULL) \
+ args_start++; \
+ } \
+ }
+
+ const char
+ *args_start=NULL;
+
int
status;
#if defined(MAGICKCORE_GS_DELEGATE) || defined(MAGICKCORE_WINDOWS_SUPPORT)
char
- **argv;
+ **argv,
+ *errors;
const GhostInfo
*ghost_info;
ghost_info=(&ghost_info_struct);
(void) ResetMagickMemory(&ghost_info,0,sizeof(ghost_info));
+ ghost_info_struct.delete_instance=(void (*)(gs_main_instance *))
+ gsapi_delete_instance;
+ ghost_info_struct.exit=(int (*)(gs_main_instance *)) gsapi_exit;
ghost_info_struct.new_instance=(int (*)(gs_main_instance **,void *))
gsapi_new_instance;
ghost_info_struct.init_with_args=(int (*)(gs_main_instance *,int,char **))
gsapi_init_with_args;
ghost_info_struct.run_string=(int (*)(gs_main_instance *,const char *,int,
int *)) gsapi_run_string;
- ghost_info_struct.delete_instance=(void (*)(gs_main_instance *))
- gsapi_delete_instance;
- ghost_info_struct.exit=(int (*)(gs_main_instance *)) gsapi_exit;
+ ghost_info_struct.set_stdio=(int (*)(gs_main_instance *,int(*)(void *,char *,
+ int),int(*)(void *,const char *,int),int(*)(void *, const char *, int)))
+ gsapi_set_stdio;
#endif
if (ghost_info == (GhostInfo *) NULL)
{
if (verbose != MagickFalse)
{
(void) fputs("[ghostscript library]",stdout);
- (void) fputs(strchr(command,' '),stdout);
+ SetArgsStart
+ (void) fputs(args_start,stdout);
}
- status=(ghost_info->new_instance)(&interpreter,(void *) NULL);
+ errors=(char *) NULL;
+ status=(ghost_info->new_instance)(&interpreter,(void *) &errors);
if (status < 0)
{
status=SystemCommand(MagickFalse,verbose,command,exception);
argv=StringToArgv(command,&argc);
if (argv == (char **) NULL)
return(MagickFalse);
+ (void) (ghost_info->set_stdio)(interpreter,(int(MagickDLLCall *)(void *,
+ char *,int)) NULL,PostscriptDelegateMessage,PostscriptDelegateMessage);
status=(ghost_info->init_with_args)(interpreter,argc-1,argv+1);
if (status == 0)
status=(ghost_info->run_string)(interpreter,"systemdict /start get exec\n",
argv=(char **) RelinquishMagickMemory(argv);
if ((status != 0) && (status != -101))
{
- char
- *message;
-
- message=GetExceptionMessage(errno);
+ SetArgsStart
(void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
- "`%s': %s",command,message);
- message=DestroyString(message);
+ "PostscriptDelegateFailed","`[ghostscript library]%s': %s",args_start,
+ errors);
+ if (errors != (char *) NULL)
+ errors=DestroyString(errors);
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
"Ghostscript returns status %d, exit code %d",status,code);
return(MagickFalse);
}
+ if (errors != (char *) NULL)
+ errors=DestroyString(errors);
return(MagickTrue);
#else
status=SystemCommand(MagickFalse,verbose,command,exception);
if (postscript_image == (Image *) NULL)
{
image=DestroyImageList(image);
- ThrowFileException(exception,DelegateError,"PostscriptDelegateFailed",
- image_info->filename);
return((Image *) NULL);
}
if (LocaleCompare(postscript_image->magick,"BMP") == 0)