CString CAdventureDesc::GetDesc (void) // GetDesc // // Returns a description for the adventure { CString sText; if (TranslateText(NULL, LANGUAGE_DESCRIPTION, &sText)) return CTextBlock::LoadAsRichText(sText); else return CONSTLIT("{/rtf }"); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % G e t D e l e g a t e C o m m a n d % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % Method GetDelegateCommand replaces any embedded formatting characters with % the appropriate image attribute and returns the resulting command. % % The format of the GetDelegateCommand method is: % % char *GetDelegateCommand(const ImageInfo *image_info,Image *image, % const char *decode,const char *encode,ExceptionInfo *exception) % % A description of each parameter follows: % % o command: Method GetDelegateCommand returns the command associated % with specified delegate tag. % % o image_info: The image info. % % o image: The image. % % o decode: Specifies the decode delegate we are searching for as a % character string. % % o encode: Specifies the encode delegate we are searching for as a % character string. % % o exception: Return any errors or warnings in this structure. % % */ MagickExport char *GetDelegateCommand(const ImageInfo *image_info,Image *image, const char *decode,const char *encode,ExceptionInfo *exception) { char *command, **commands; const DelegateInfo *delegate_info; register long i; assert(image_info != (ImageInfo *) NULL); assert(image_info->signature == MagickSignature); assert(image != (Image *) NULL); assert(image->signature == MagickSignature); delegate_info=GetDelegateInfo(decode,encode,exception); if (delegate_info == (const DelegateInfo *) NULL) { ThrowException(exception,DelegateError,NoTagFound, decode ? decode : encode); return((char *) NULL); } commands=StringToList(delegate_info->commands); if (commands == (char **) NULL) { ThrowException(exception,ResourceLimitError,MemoryAllocationFailed, decode ? decode : encode); return((char *) NULL); } command=TranslateText(image_info,image,commands[0]); if (command == (char *) NULL) ThrowException(exception,ResourceLimitError,MemoryAllocationFailed, commands[0]); /* Free resources. */ for (i=0; commands[i] != (char *) NULL; i++) MagickFreeMemory(commands[i]); MagickFreeMemory(commands); return(command); }
BOOL TranslateText(LPCTSTR szText, LPTSTR& szTranslated) { return TranslateText(szText, NULL, szTranslated); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % W r i t e I N F O I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % WriteINFOImage() writes image descriptive info to stdout. % % The format of the WriteINFOImage method is: % % MagickPassFail WriteINFOImage(const ImageInfo *image_info,Image *image) % % A description of each parameter follows. % % o image_info: The image info. % % o image: The image. % % */ static MagickPassFail WriteINFOImage(const ImageInfo *image_info,Image *image) { MagickPassFail status; FILE *file; Image *list_entry; char temporary_filename[MaxTextExtent]; const char *format; assert(image_info != (const ImageInfo *) NULL); assert(image_info->signature == MagickSignature); assert(image != (Image *) NULL); assert(image->signature == MagickSignature); /* Obtain optional 'identify' style output specification. */ format=AccessDefinition(image_info,"info","format"); if (format != (char *) NULL) (void) LogMagickEvent(CoderEvent,GetMagickModule(), "info:format=\"%s\"",format); /* Open blob. */ status=OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception); if (status == MagickFail) ThrowWriterException(FileOpenError,UnableToOpenFile,image); /* Allocate and open a temporary file to write output to. */ temporary_filename[0]='\0'; if ((file=GetBlobFileHandle(image)) == (FILE *) NULL) { if(!AcquireTemporaryFileName(temporary_filename)) ThrowWriterException(FileOpenError,UnableToCreateTemporaryFile,image); if ((file=fopen(temporary_filename,"w")) == (FILE *) NULL) { (void) LiberateTemporaryFile(temporary_filename); ThrowWriterException(FileOpenError,UnableToCreateTemporaryFile,image); } } list_entry=image; while (list_entry != (Image *) NULL) { /* Avoid convert style output syntax by restoring original filename. */ (void) strlcpy(list_entry->filename,list_entry->magick_filename, sizeof(list_entry->filename)); /* Describe image. */ if (format != (char *) NULL) { char *text; text=TranslateText(image_info,list_entry,format); if (text != (char *) NULL) { (void) fputs(text,file); (void) fputs("\n",file); MagickFreeMemory(text); } } else { if ((status=DescribeImage(list_entry,file,image_info->verbose)) == MagickFail) break; } list_entry=GetNextImageInList(list_entry); } if ('\0' != temporary_filename[0]) { /* Close temporary file. */ (void) fclose(file); /* Send content of temporary file to blob stream. */ if (WriteBlobFile(image,temporary_filename) == MagickFail) status=MagickFail; (void) LiberateTemporaryFile(temporary_filename); } CloseBlob(image); return status; }
MagickExport unsigned int InvokeDelegate(ImageInfo *image_info,Image *image, const char *decode,const char *encode,ExceptionInfo *exception) { char *command, **commands, filename[MaxTextExtent]; const DelegateInfo *delegate_info; register long i; unsigned int status, temporary_image_filename; /* Get delegate. */ assert(image_info != (ImageInfo *) NULL); assert(image_info->signature == MagickSignature); assert(image != (Image *) NULL); assert(image->signature == MagickSignature); temporary_image_filename=(*image->filename == '\0'); if (temporary_image_filename) { /* Allocate a temporary filename if image is unnamed. */ if(!AcquireTemporaryFileName(image->filename)) { (void) ThrowException(exception,FileOpenError,UnableToCreateTemporaryFile,image->filename); return(False); } } (void) strlcpy(filename,image->filename,MaxTextExtent); delegate_info=GetDelegateInfo(decode,encode,exception); if (delegate_info == (DelegateInfo *) NULL) { if (temporary_image_filename) (void) LiberateTemporaryFile(image->filename); (void) ThrowException(exception,DelegateError,NoTagFound, decode ? decode : encode); return(False); } if (*image_info->filename == '\0') { /* ReadImage will normally have already set image_info->filename to the name of a temporary file. If not, then assign one. Setting image_info->temporary to True indicates that there is a temporary file to be removed later. */ if(!AcquireTemporaryFileName(image_info->filename)) { if (temporary_image_filename) (void) LiberateTemporaryFile(image->filename); (void) ThrowException(exception,FileOpenError,UnableToCreateTemporaryFile,image_info->filename); return(False); } image_info->temporary=True; } if (delegate_info->mode != 0) if ((decode && (delegate_info->encode != (char *) NULL)) || (encode && (delegate_info->decode != (char *) NULL))) { char decode_filename[MaxTextExtent], *magick; ImageInfo *clone_info; register Image *p; /* Delegate requires a particular image format. */ if (!AcquireTemporaryFileName(image_info->unique)) { if (temporary_image_filename) (void) LiberateTemporaryFile(image->filename); (void) ThrowException(exception,FileOpenError,UnableToCreateTemporaryFile,image_info->unique); return(False); } if (!AcquireTemporaryFileName(image_info->zero)) { if (temporary_image_filename) (void) LiberateTemporaryFile(image->filename); (void) LiberateTemporaryFile(image_info->unique); (void) ThrowException(exception,FileOpenError,UnableToCreateTemporaryFile,image_info->zero); return(False); } /* Expand sprintf-style codes in delegate command to command string */ magick=TranslateText(image_info,image,decode != (char *) NULL ? delegate_info->encode : delegate_info->decode); if (magick == (char *) NULL) { (void) LiberateTemporaryFile(image_info->unique); (void) LiberateTemporaryFile(image_info->zero); if (temporary_image_filename) (void) LiberateTemporaryFile(image->filename); (void) ThrowException(exception,DelegateError,DelegateFailed, decode ? decode : encode); return(False); } LocaleUpper(magick); clone_info=CloneImageInfo(image_info); (void) strlcpy((char *) clone_info->magick,magick,MaxTextExtent); (void) strlcpy(image->magick,magick,MaxTextExtent); MagickFreeMemory(magick); (void) strlcpy(decode_filename,image->filename,MaxTextExtent); FormatString(clone_info->filename,"%.1024s:",delegate_info->decode); (void) SetImageInfo(clone_info,True,exception); (void) strlcpy(clone_info->filename,image_info->filename, MaxTextExtent); for (p=image; p != (Image *) NULL; p=p->next) { FormatString(p->filename,"%.1024s:%.1024s",delegate_info->decode, decode_filename); status=WriteImage(clone_info,p); if (status == False) { (void) LiberateTemporaryFile(image_info->unique); (void) LiberateTemporaryFile(image_info->zero); if (temporary_image_filename) (void) LiberateTemporaryFile(image->filename); DestroyImageInfo(clone_info); (void) ThrowException(exception,DelegateError,DelegateFailed, decode ? decode : encode); return(False); } if (clone_info->adjoin) break; } (void) LiberateTemporaryFile(image_info->unique); (void) LiberateTemporaryFile(image_info->zero); DestroyImageInfo(clone_info); } /* Invoke delegate. */ (void) strlcpy(image->filename,filename,MaxTextExtent); commands=StringToList(delegate_info->commands); if (commands == (char **) NULL) { if (temporary_image_filename) (void) LiberateTemporaryFile(image->filename); (void) ThrowException(exception,ResourceLimitError,MemoryAllocationFailed,decode ? decode : encode); return(False); } command=(char *) NULL; status=True; /* For each delegate command ... */ for (i=0; commands[i] != (char *) NULL; i++) { status=True; /* Allocate convenience temporary files */ if (!AcquireTemporaryFileName(image_info->unique)) { (void) ThrowException(exception,FileOpenError,UnableToCreateTemporaryFile,image_info->unique); status=False; goto error_exit; } if (!AcquireTemporaryFileName(image_info->zero)) { (void) ThrowException(exception,FileOpenError,UnableToCreateTemporaryFile,image_info->zero); (void) LiberateTemporaryFile(image_info->unique); status=False; goto error_exit; } #if defined(POSIX) { MagickBool needs_shell; /* Check to see if command template must be executed via shell due to using constructs requiring multiple processes or I/O redirection. */ needs_shell = MagickFalse; { char * p; p = commands[i]; for (p = commands[i]; *p; p++) { if (('&' == *p) || (';' == *p) || ('<' == *p) || ('>' == *p) || ('|' == *p)) { needs_shell = MagickTrue; break; } } } if (MagickFalse == needs_shell) { int arg_count, j; char **arg_array; /* Convert command template into an argument array. Translate each argument array element individually in order to absolutely avoid any possibility that the number of arguments may be altered due to substituted data. */ arg_array = StringToArgv(commands[i],&arg_count); for (j = 0; arg_array[j] != (const char*) NULL; j++) { if (strchr(arg_array[j], '%') != (const char*) NULL) { char *expanded = TranslateText(image_info,image,arg_array[j]); if (expanded != (char *) NULL) { MagickFreeMemory(arg_array[j]); arg_array[j] = expanded; } } } /* Execute delegate using our secure "spawn" facility. */ status = MagickSpawnVP(image_info->verbose,arg_array[1],arg_array+1); } else { /* Expand sprintf-style codes in delegate command to command string, escaping replacement text appropriately */ command=TranslateTextEx(image_info,image,commands[i],UnixShellTextEscape); if (command == (char *) NULL) break; /* Execute delegate using command shell. */ status=SystemCommand(image_info->verbose,command); } } #else { /* Expand sprintf-style codes in delegate command to command string */ command=TranslateText(image_info,image,commands[i]); if (command == (char *) NULL) break; /* Execute delegate using command shell. */ status=SystemCommand(image_info->verbose,command); } #endif MagickFreeMemory(command); /* Liberate convenience temporary files */ (void) LiberateTemporaryFile(image_info->unique); (void) LiberateTemporaryFile(image_info->zero); if (status != False) { (void) ThrowException(exception,DelegateError,DelegateFailed, commands[i]); goto error_exit; } MagickFreeMemory(commands[i]); } /* Free resources. */ error_exit: if (temporary_image_filename) (void) LiberateTemporaryFile(image->filename); for ( ; commands[i] != (char *) NULL; i++) MagickFreeMemory(commands[i]); MagickFreeMemory(commands); return(status != False); }