2
% Copyright (C) 2003 GraphicsMagick Group
3
% Copyright (C) 2002 ImageMagick Studio
5
% This program is covered by multiple licenses, which are described in
6
% Copyright.txt. You should have received a copy of Copyright.txt with this
7
% package; otherwise see http://www.graphicsmagick.org/www/Copyright.html.
9
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
12
% DDDD EEEEE L EEEEE GGGG AAA TTTTT EEEEE %
13
% D D E L E G A A T E %
14
% D D EEE L EEE G GG AAAAA T EEE %
15
% D D E L E G G A A T E %
16
% DDDD EEEEE LLLLL EEEEE GGG A A T EEEEE %
19
% Methods to Read/Write/Invoke Delegates %
28
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30
% The Delegates methods associate a set of commands with a particular
31
% image format. GraphicsMagick uses delegates for formats it does not handle
34
% Thanks to Bob Friesenhahn for the initial inspiration and design of the
43
#include "magick/studio.h"
44
#include "magick/blob.h"
45
#include "magick/constitute.h"
46
#include "magick/delegate.h"
47
#if defined(WIN32) || defined(__CYGWIN__)
48
# include "magick/nt_feature.h"
50
#include "magick/semaphore.h"
51
#include "magick/tempfile.h"
52
#include "magick/utility.h"
57
#define DelegateFilename "delegates.mgk"
63
*DelegateMap = (char *)
64
"<?xml version=\"1.0\"?>"
66
" <delegate stealth=\"True\" />"
73
*delegate_semaphore = (SemaphoreInfo *) NULL;
76
*delegate_list = (DelegateInfo *) NULL;
79
Forward declaractions.
82
ReadConfigureFile(const char *,const unsigned long,ExceptionInfo *);
85
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
89
% D e s t r o y D e l e g a t e I n f o %
93
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
95
% Method DestroyDelegateInfo deallocates memory associated with the delegates
98
% The format of the DestroyDelegateInfo method is:
100
% DestroyDelegateInfo(void)
103
MagickExport void DestroyDelegateInfo(void)
108
register DelegateInfo
111
AcquireSemaphoreInfo(&delegate_semaphore);
112
for (p=delegate_list; p != (DelegateInfo *) NULL; )
116
if (delegate_info->path != (char *) NULL)
117
MagickFreeMemory(delegate_info->path);
118
if (delegate_info->decode != (char *) NULL)
119
MagickFreeMemory(delegate_info->decode);
120
if (delegate_info->encode != (char *) NULL)
121
MagickFreeMemory(delegate_info->encode);
122
if (delegate_info->commands != (char *) NULL)
123
MagickFreeMemory(delegate_info->commands);
124
MagickFreeMemory(delegate_info);
126
delegate_list=(DelegateInfo *) NULL;
127
LiberateSemaphoreInfo(&delegate_semaphore);
128
DestroySemaphoreInfo(&delegate_semaphore);
132
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
136
% G e t D e l e g a t e C o m m a n d %
140
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
142
% Method GetDelegateCommand replaces any embedded formatting characters with
143
% the appropriate image attribute and returns the resulting command.
145
% The format of the GetDelegateCommand method is:
147
% char *GetDelegateCommand(const ImageInfo *image_info,Image *image,
148
% const char *decode,const char *encode,ExceptionInfo *exception)
150
% A description of each parameter follows:
152
% o command: Method GetDelegateCommand returns the command associated
153
% with specified delegate tag.
155
% o image_info: The image info.
157
% o image: The image.
159
% o decode: Specifies the decode delegate we are searching for as a
162
% o encode: Specifies the encode delegate we are searching for as a
165
% o exception: Return any errors or warnings in this structure.
169
MagickExport char *GetDelegateCommand(const ImageInfo *image_info,Image *image,
170
const char *decode,const char *encode,ExceptionInfo *exception)
182
assert(image_info != (ImageInfo *) NULL);
183
assert(image_info->signature == MagickSignature);
184
assert(image != (Image *) NULL);
185
assert(image->signature == MagickSignature);
186
delegate_info=GetDelegateInfo(decode,encode,exception);
187
if (delegate_info == (const DelegateInfo *) NULL)
189
ThrowException(exception,DelegateError,NoTagFound,
190
decode ? decode : encode);
191
return((char *) NULL);
193
commands=StringToList(delegate_info->commands);
194
if (commands == (char **) NULL)
196
ThrowException(exception,ResourceLimitError,MemoryAllocationFailed,
197
decode ? decode : encode);
198
return((char *) NULL);
200
command=TranslateText(image_info,image,commands[0]);
201
if (command == (char *) NULL)
202
ThrowException(exception,ResourceLimitError,MemoryAllocationFailed,
207
for (i=0; commands[i] != (char *) NULL; i++)
208
MagickFreeMemory(commands[i]);
209
MagickFreeMemory(commands);
214
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
218
% G e t D e l e g a t e I n f o %
222
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
224
% Method GetDelegateInfo returns any delegates associated with the specified
227
% The format of the GetDelegateInfo method is:
229
% const DelegateInfo *GetDelegateInfo(const char *decode,
230
% const char *encode,ExceptionInfo *exception)
232
% A description of each parameter follows:
234
% o delgate_info: Method GetDelegateInfo returns any delegates associated
235
% with the specified tag.
237
% o decode: Specifies the decode delegate we are searching for as a
240
% o encode: Specifies the encode delegate we are searching for as a
243
% o exception: Return any errors or warnings in this structure.
247
MagickExport const DelegateInfo *GetDelegateInfo(const char *decode,
248
const char *encode,ExceptionInfo *exception)
250
register DelegateInfo
253
if (delegate_list == (DelegateInfo *) NULL)
255
AcquireSemaphoreInfo(&delegate_semaphore);
256
if (delegate_list == (DelegateInfo *) NULL)
257
(void) ReadConfigureFile(DelegateFilename,0,exception);
258
LiberateSemaphoreInfo(&delegate_semaphore);
260
if ((LocaleCompare(decode,"*") == 0) && (LocaleCompare(encode,"*") == 0))
261
return((const DelegateInfo *) delegate_list);
263
Search for requested delegate.
265
AcquireSemaphoreInfo(&delegate_semaphore);
266
for (p=delegate_list; p != (const DelegateInfo *) NULL; p=p->next)
270
if (LocaleCompare(p->decode,decode) == 0)
276
if (LocaleCompare(p->encode,encode) == 0)
280
if (LocaleCompare(decode,p->decode) == 0)
281
if (LocaleCompare(encode,p->encode) == 0)
283
if (LocaleCompare(decode,"*") == 0)
284
if (LocaleCompare(encode,p->encode) == 0)
286
if (LocaleCompare(decode,p->decode) == 0)
287
if (LocaleCompare(encode,"*") == 0)
290
if (p != (DelegateInfo *) NULL)
291
if (p != delegate_list)
296
if (p->previous != (DelegateInfo *) NULL)
297
p->previous->next=p->next;
298
if (p->next != (DelegateInfo *) NULL)
299
p->next->previous=p->previous;
300
p->previous=(DelegateInfo *) NULL;
301
p->next=delegate_list;
302
delegate_list->previous=p;
305
LiberateSemaphoreInfo(&delegate_semaphore);
306
return((const DelegateInfo *) p);
310
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
314
% I n v o k e D e l e g a t e %
318
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
320
% Method InvokeDelegate replaces any embedded formatting characters with
321
% the appropriate image attribute and executes the resulting command. False
322
% is returned if the commands execute with success otherwise True.
324
% The format of the InvokeDelegate method is:
326
% unsigned int InvokeDelegate(ImageInfo *image_info,Image *image,
327
% const char *decode,const char *encode,ExceptionInfo *exception)
329
% A description of each parameter follows:
331
% o image_info: The imageInfo.
333
% o image: The image.
335
% o exception: Return any errors or warnings in this structure.
339
MagickExport unsigned int InvokeDelegate(ImageInfo *image_info,Image *image,
340
const char *decode,const char *encode,ExceptionInfo *exception)
345
filename[MaxTextExtent];
355
temporary_image_filename;
360
assert(image_info != (ImageInfo *) NULL);
361
assert(image_info->signature == MagickSignature);
362
assert(image != (Image *) NULL);
363
assert(image->signature == MagickSignature);
364
temporary_image_filename=(*image->filename == '\0');
365
if (temporary_image_filename)
367
/* Allocate a temporary filename if image is unnamed. */
368
if(!AcquireTemporaryFileName(image->filename))
370
(void) ThrowException(exception,FileOpenError,UnableToCreateTemporaryFile,image->filename);
374
(void) strncpy(filename,image->filename,MaxTextExtent-1);
375
delegate_info=GetDelegateInfo(decode,encode,exception);
376
if (delegate_info == (DelegateInfo *) NULL)
378
if (temporary_image_filename)
379
LiberateTemporaryFile(image->filename);
380
(void) ThrowException(exception,DelegateError,NoTagFound,
381
decode ? decode : encode);
385
if (*image_info->filename == '\0')
387
/* ReadImage will normally have already set image_info->filename
388
to the name of a temporary file. If not, then assign
389
one. Setting image_info->temporary to True indicates that
390
there is a temporary file to be removed later. */
391
if(!AcquireTemporaryFileName(image_info->filename))
393
if (temporary_image_filename)
394
LiberateTemporaryFile(image->filename);
395
(void) ThrowException(exception,FileOpenError,UnableToCreateTemporaryFile,image_info->filename);
398
image_info->temporary=True;
401
if (delegate_info->mode != 0)
402
if ((decode && (delegate_info->encode != (char *) NULL)) ||
403
(encode && (delegate_info->decode != (char *) NULL)))
406
filename[MaxTextExtent],
416
Delegate requires a particular image format.
419
if (!AcquireTemporaryFileName(image_info->unique))
421
if (temporary_image_filename)
422
LiberateTemporaryFile(image->filename);
423
(void) ThrowException(exception,FileOpenError,UnableToCreateTemporaryFile,image_info->unique);
427
if (!AcquireTemporaryFileName(image_info->zero))
429
if (temporary_image_filename)
430
LiberateTemporaryFile(image->filename);
431
LiberateTemporaryFile(image_info->unique);
432
(void) ThrowException(exception,FileOpenError,UnableToCreateTemporaryFile,image_info->zero);
435
/* Expand sprintf-style codes in delegate command to command string */
436
magick=TranslateText(image_info,image,decode != (char *) NULL ?
437
delegate_info->encode : delegate_info->decode);
438
if (magick == (char *) NULL)
440
LiberateTemporaryFile(image_info->unique);
441
LiberateTemporaryFile(image_info->zero);
442
if (temporary_image_filename)
443
LiberateTemporaryFile(image->filename);
444
(void) ThrowException(exception,DelegateError,DelegateFailed,
445
decode ? decode : encode);
449
clone_info=CloneImageInfo(image_info);
450
(void) strncpy((char *) clone_info->magick,magick,MaxTextExtent-1);
451
(void) strncpy(image->magick,magick,MaxTextExtent-1);
452
MagickFreeMemory(magick);
453
(void) strncpy(filename,image->filename,MaxTextExtent-1);
454
FormatString(clone_info->filename,"%.1024s:",delegate_info->decode);
455
(void) SetImageInfo(clone_info,True,exception);
456
(void) strncpy(clone_info->filename,image_info->filename,
458
for (p=image; p != (Image *) NULL; p=p->next)
460
FormatString(p->filename,"%.1024s:%.1024s",delegate_info->decode,
462
status=WriteImage(clone_info,p);
465
LiberateTemporaryFile(image_info->unique);
466
LiberateTemporaryFile(image_info->zero);
467
if (temporary_image_filename)
468
LiberateTemporaryFile(image->filename);
469
DestroyImageInfo(clone_info);
470
(void) ThrowException(exception,DelegateError,DelegateFailed,
471
decode ? decode : encode);
474
if (clone_info->adjoin)
477
LiberateTemporaryFile(image_info->unique);
478
LiberateTemporaryFile(image_info->zero);
479
DestroyImageInfo(clone_info);
484
(void) strncpy(image->filename,filename,MaxTextExtent-1);
485
commands=StringToList(delegate_info->commands);
486
if (commands == (char **) NULL)
488
if (temporary_image_filename)
489
LiberateTemporaryFile(image->filename);
490
(void) ThrowException(exception,ResourceLimitError,MemoryAllocationFailed,decode ? decode : encode);
493
command=(char *) NULL;
495
/* For each delegate command ... */
496
for (i=0; commands[i] != (char *) NULL; i++)
499
/* Allocate convenience temporary files */
500
if (!AcquireTemporaryFileName(image_info->unique))
502
(void) ThrowException(exception,FileOpenError,UnableToCreateTemporaryFile,image_info->unique);
506
if (!AcquireTemporaryFileName(image_info->zero))
508
(void) ThrowException(exception,FileOpenError,UnableToCreateTemporaryFile,image_info->zero);
509
LiberateTemporaryFile(image_info->unique);
513
/* Expand sprintf-style codes in delegate command to command string */
514
command=TranslateText(image_info,image,commands[i]);
515
if (command == (char *) NULL)
517
/* Handle commands which should be backgrounded */
518
if (delegate_info->spawn)
519
(void) ConcatenateString(&command," &");
520
/* Execute delegate. */
521
status=SystemCommand(image_info->verbose,command);
522
MagickFreeMemory(command);
523
/* Liberate convenience temporary files */
524
LiberateTemporaryFile(image_info->unique);
525
LiberateTemporaryFile(image_info->zero);
528
(void) ThrowException(exception,DelegateError,DelegateFailed,
532
MagickFreeMemory(commands[i]);
538
if (temporary_image_filename)
539
LiberateTemporaryFile(image->filename);
540
for ( ; commands[i] != (char *) NULL; i++)
541
MagickFreeMemory(commands[i]);
542
MagickFreeMemory(commands);
543
return(status != False);
547
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
551
% I n v o k e P o s t s r i p t D e l e g a t e %
555
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
557
% InvokePostscriptDelegate() executes the postscript interpreter with the
560
% The format of the InvokePostscriptDelegate method is:
562
% unsigned int InvokePostscriptDelegate(const unsigned int verbose,
563
% const char *command)
565
% A description of each parameter follows:
567
% o status: Method InvokePostscriptDelegate returns True is the command
568
% is successfully executed, otherwise False.
570
% o verbose: A value other than zero displays the command prior to
573
% o command: The address of a character string containing the command to
578
MagickExport unsigned int InvokePostscriptDelegate(const unsigned int verbose,
581
#if defined(HasGS) || defined(WIN32)
597
const GhostscriptVectors
600
gs_func=NTGhostscriptDLLVectors();
605
const GhostscriptVectors
608
gs_func=(&gs_func_struct);
609
gs_func_struct.exit=gsapi_exit;
610
gs_func_struct.init_with_args=gsapi_init_with_args;
611
gs_func_struct.new_instance=gsapi_new_instance;
612
gs_func_struct.run_string=gsapi_run_string;
613
gs_func_struct.delete_instance=gsapi_delete_instance;
615
if (gs_func == (GhostscriptVectors *) NULL)
618
(void) fputs(command,stdout);
619
return(SystemCommand(verbose,command));
623
(void) fputs("[ghostscript library]",stdout);
624
(void) fputs(strchr(command,' '),stdout);
626
status=(gs_func->new_instance)(&interpreter,(void *) NULL);
629
argv=StringToArgv(command,&argc);
630
if (argv == (char **) NULL)
632
status=(gs_func->init_with_args)(interpreter,argc-1,argv+1);
634
status=(gs_func->run_string)
635
(interpreter,"systemdict /start get exec\n",0,&code);
636
(gs_func->exit)(interpreter);
637
(gs_func->delete_instance)(interpreter);
638
for (i=0; i < argc; i++)
639
MagickFreeMemory(argv[i]);
640
MagickFreeMemory(argv);
641
if ((status == 0) || (status == -101))
645
return(SystemCommand(verbose,command));
650
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
654
% L i s t D e l e g a t e I n f o %
658
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
660
% Method ListDelegateInfo lists the image formats to a file.
662
% The format of the ListDelegateInfo method is:
664
% unsigned int ListDelegateInfo(FILE *file,ExceptionInfo *exception)
666
% A description of each parameter follows.
668
% o file: An pointer to a FILE.
670
% o exception: Return any errors or warnings in this structure.
674
MagickExport unsigned int ListDelegateInfo(FILE *file,ExceptionInfo *exception)
678
delegate[MaxTextExtent];
683
register const DelegateInfo
686
if (file == (const FILE *) NULL)
688
(void) GetDelegateInfo("*","*",exception);
689
AcquireSemaphoreInfo(&delegate_semaphore);
690
for (p=delegate_list; p != (const DelegateInfo *) NULL; p=p->next)
692
if ((p->previous == (DelegateInfo *) NULL) ||
693
(LocaleCompare(p->path,p->previous->path) != 0))
695
if (p->previous != (DelegateInfo *) NULL)
696
(void) fprintf(file,"\n");
697
if (p->path != (char *) NULL)
698
(void) fprintf(file,"Path: %.1024s\n\n",p->path);
699
(void) fprintf(file,"Delegate Command\n");
700
(void) fprintf(file,"-------------------------------------------------"
701
"------------------------------\n");
706
if (p->encode != (char *) NULL)
707
(void) strncpy(delegate,p->encode,MaxTextExtent-1);
708
(void) strcat(delegate," ");
710
commands=StringToList(p->commands);
711
if (commands == (char **) NULL)
715
command_start_column,
725
/* Format output so that command spans multiple lines if
727
if (getenv("COLUMNS"))
728
screen_width=atoi(getenv("COLUMNS"))-1;
729
command_length=strlen(commands[0]);
730
command_start_column=fprintf(file,"%8s%c=%c%s ",p->decode ? p->decode : "",
731
p->mode <= 0 ? '<' : ' ',p->mode >= 0 ? '>' : ' ',delegate);
732
for (s=commands[0]; length < command_length; s+=formatted_chars)
734
if (s != commands[0])
735
fprintf(file,"%*s",command_start_column,"");
736
strip_length=screen_width-command_start_column;
737
if (length+strip_length < command_length)
742
for(e=s+strip_length; (*e != ' ') && (e > s) ; e--);
745
formatted_chars=fprintf(file,"%.*s",strip_length,s);
746
length+=formatted_chars;
748
if (formatted_chars <= 0)
752
for (i=0; commands[i] != (char *) NULL; i++)
753
MagickFreeMemory(commands[i]);
756
LiberateSemaphoreInfo(&delegate_semaphore);
761
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
765
+ R e a d C o n f i g u r e F i l e %
769
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
771
% Method ReadConfigureFile reads the color configuration file which maps
772
% color strings with a particular image format.
774
% The format of the ReadConfigureFile method is:
776
% unsigned int ReadConfigureFile(const char *basename,
777
% const unsigned long depth,ExceptionInfo *exception)
779
% A description of each parameter follows:
781
% o status: Method ReadConfigureFile returns True if at least one color
782
% is defined otherwise False.
784
% o basename: The color configuration filename.
786
% o depth: depth of <include /> statements.
788
% o exception: Return any errors or warnings in this structure.
793
static void CatDelegatePath(char *path,
797
strcpy(path,binpath);
798
strcat(path,command);
799
if (IsAccessibleNoLogging(path))
802
strcpy(path,command);
805
#endif /* defined(WIN32) */
806
static unsigned int ReadConfigureFile(const char *basename,
807
const unsigned long depth,ExceptionInfo *exception)
810
keyword[MaxTextExtent],
820
Read the delegates configure file.
822
(void) strcpy(path,basename);
824
xml=(char *) GetConfigureBlob(basename,path,&length,exception);
826
xml=(char *) FileToBlob(basename,&length,exception);
827
if (xml == (char *) NULL)
828
xml=AllocateString(DelegateMap);
829
token=AllocateString(xml);
830
for (q=xml; *q != '\0'; )
835
GetToken(q,&q,token);
838
(void) strncpy(keyword,token,MaxTextExtent-1);
839
if (LocaleNCompare(keyword,"<!--",4) == 0)
844
while ((LocaleNCompare(q,"->",2) != 0) && (*q != '\0'))
845
GetToken(q,&q,token);
848
if (LocaleCompare(keyword,"<include") == 0)
853
while ((*token != '>') && (*q != '\0'))
855
(void) strncpy(keyword,token,MaxTextExtent-1);
856
GetToken(q,&q,token);
859
GetToken(q,&q,token);
860
if (LocaleCompare(keyword,"file") == 0)
863
ThrowException(exception,ConfigureError,IncludeElementNestedTooDeeply,path);
867
filename[MaxTextExtent];
869
GetPathComponent(path,HeadPath,filename);
870
if (*filename != '\0')
871
(void) strcat(filename,DirectorySeparator);
872
(void) strncat(filename,token,MaxTextExtent-
874
(void) ReadConfigureFile(filename,depth+1,exception);
876
if (delegate_list != (DelegateInfo *) NULL)
877
while (delegate_list->next != (DelegateInfo *) NULL)
878
delegate_list=delegate_list->next;
883
if (LocaleCompare(keyword,"<delegate") == 0)
889
Allocate memory for the delegate list.
891
delegate_info=MagickAllocateMemory(DelegateInfo *,sizeof(DelegateInfo));
892
if (delegate_info == (DelegateInfo *) NULL)
893
MagickFatalError3(ResourceLimitFatalError,MemoryAllocationFailed,
894
UnableToAllocateDelegateInfo);
895
(void) memset(delegate_info,0,sizeof(DelegateInfo));
896
delegate_info->path=AcquireString(path);
897
delegate_info->signature=MagickSignature;
898
if (delegate_list == (DelegateInfo *) NULL)
900
delegate_list=delegate_info;
903
delegate_list->next=delegate_info;
904
delegate_info->previous=delegate_list;
905
delegate_list=delegate_list->next;
908
if (delegate_list == (DelegateInfo *) NULL)
910
GetToken(q,(char **) NULL,token);
913
GetToken(q,&q,token);
914
GetToken(q,&q,token);
920
if (LocaleCompare((char *) keyword,"command") == 0)
922
delegate_list->commands=AllocateString(token);
924
if (strchr(delegate_list->commands,'@') != (char *) NULL)
927
BinPath[MaxTextExtent],
931
/* Substitute @PSDelegate@ with path to Ghostscript */
932
NTGhostscriptEXE(path,MaxTextExtent-1);
933
SubstituteString((char **) &delegate_list->commands,
934
"@PSDelegate@",path);
936
# if defined(UseInstalledMagick)
937
# if defined(MagickBinPath)
938
strcpy(BinPath,MagickBinPath);
945
/* Obtain installation path from registry */
947
key_value=NTRegistryKeyLookup(key);
950
ThrowException(exception,ConfigureError,
951
RegistryKeyLookupFailed,key);
955
strcpy(BinPath,key_value);
956
MagickFreeMemory(key_value);
959
# endif /* defined(MagickBinPath) */
961
/* Base path off of client path */
962
strcpy(BinPath,SetClientPath(NULL));
963
# endif /* defined(UseInstalledMagick) */
964
if ((BinPath[0] != 0) &&
965
(BinPath[strlen(BinPath)-1] != *DirectorySeparator))
966
strcat(BinPath,DirectorySeparator);
968
/* Substitute @GMDelegate@ with path to gm.exe */
969
CatDelegatePath(path,BinPath,"gm.exe");
970
SubstituteString((char **) &delegate_list->commands,
971
"@GMDelegate@",path);
973
/* Substitute @GMDisplayDelegate@ with path to
975
CatDelegatePath(path,BinPath,"gmdisplay.exe");
976
SubstituteString((char **) &delegate_list->commands,
977
"@GMDisplayDelegate@",path);
979
/* Substitute @MPEGDecodeDelegate@ with path to
981
CatDelegatePath(path,BinPath,"mpeg2dec.exe");
982
SubstituteString((char **) &delegate_list->commands,
983
"@MPEGDecodeDelegate@",path);
985
/* Substitute @MPEGEncodeDelegate@ with path to
987
CatDelegatePath(path,BinPath,"mpeg2enc.exe");
988
SubstituteString((char **) &delegate_list->commands,
989
"@MPEGEncodeDelegate@",path);
991
/* Substitute @HPGLDecodeDelegate@ with path to
993
CatDelegatePath(path,BinPath,"hp2xx.exe");
994
SubstituteString((char **) &delegate_list->commands,
995
"@HPGLDecodeDelegate@",path);
997
#endif /* defined(WIN32) */
998
} /* LocaleCompare */
1004
if (LocaleCompare((char *) keyword,"decode") == 0)
1006
delegate_list->decode=AcquireString(token);
1007
delegate_list->mode=1;
1015
if (LocaleCompare((char *) keyword,"encode") == 0)
1017
delegate_list->encode=AcquireString(token);
1018
delegate_list->mode=(-1);
1026
if (LocaleCompare((char *) keyword,"mode") == 0)
1028
delegate_list->mode=1;
1029
if (LocaleCompare(token,"bi") == 0)
1030
delegate_list->mode=0;
1032
if (LocaleCompare(token,"encode") == 0)
1033
delegate_list->mode=(-1);
1041
if (LocaleCompare((char *) keyword,"spawn") == 0)
1043
delegate_list->spawn=LocaleCompare(token,"True") == 0;
1046
if (LocaleCompare((char *) keyword,"stealth") == 0)
1048
delegate_list->stealth=LocaleCompare(token,"True") == 0;
1057
MagickFreeMemory(token);
1058
MagickFreeMemory(xml);
1059
if (delegate_list == (DelegateInfo *) NULL)
1061
while (delegate_list->previous != (DelegateInfo *) NULL)
1062
delegate_list=delegate_list->previous;
1067
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1071
% S e t D e l e g a t e I n f o %
1075
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1077
% Method SetDelegateInfo adds or replaces a delegate in the delegate list and
1078
% returns the address of the first delegate. If the delegate is NULL, just
1079
% the address of the first delegate is returned.
1081
% The format of the SetDelegateInfo method is:
1083
% DelegateInfo *SetDelegateInfo(DelegateInfo *delegate_info)
1085
% A description of each parameter follows:
1087
% o delegate_info: Method SetDelegateInfo returns the address of the
1088
% first delegate in the delegates list.
1090
% o delegate_info: A structure of type DelegateInfo. This information
1091
% is added to the end of the delegates linked-list.
1095
MagickExport DelegateInfo *SetDelegateInfo(DelegateInfo *delegate_info)
1097
register DelegateInfo
1104
Initialize new delegate.
1106
assert(delegate_info != (DelegateInfo *) NULL);
1107
assert(delegate_info->signature == MagickSignature);
1108
delegate=MagickAllocateMemory(DelegateInfo *,sizeof(DelegateInfo));
1109
if (delegate == (DelegateInfo *) NULL)
1110
return((DelegateInfo *) delegate_list);
1111
delegate->decode=AcquireString(delegate_info->decode);
1112
delegate->encode=AcquireString(delegate_info->encode);
1113
delegate->mode=delegate_info->mode;
1114
delegate->commands=(char *) NULL;
1115
if (delegate_info->commands != (char *) NULL)
1116
delegate->commands=AllocateString(delegate_info->commands);
1117
delegate->previous=(DelegateInfo *) NULL;
1118
delegate->next=(DelegateInfo *) NULL;
1119
if (delegate_list == (DelegateInfo *) NULL)
1121
delegate_list=delegate;
1122
return((DelegateInfo *) delegate_list);
1124
for (p=delegate_list; p != (DelegateInfo *) NULL; p=p->next)
1126
if ((LocaleCompare(p->decode,delegate_info->decode) == 0) &&
1127
(LocaleCompare(p->encode,delegate_info->encode) == 0) &&
1128
(p->mode == delegate_info->mode))
1131
Delegate overrides an existing one with the same tags.
1133
MagickFreeMemory(p->commands);
1134
p->commands=delegate->commands;
1135
MagickFreeMemory(delegate);
1136
return((DelegateInfo *) delegate_list);
1138
if (p->next == (DelegateInfo *) NULL)
1142
Place new delegate at the end of the delegate list.
1144
delegate->previous=p;
1146
return((DelegateInfo *) delegate_list);