MagickCore  7.1.1-43
Convert, Edit, Or Compose Bitmap Images
delegate-private.h
1 /*
2  Copyright @ 1999 ImageMagick Studio LLC, a non-profit organization
3  dedicated to making software imaging solutions freely available.
4 
5  You may not use this file except in compliance with the License. You may
6  obtain a copy of the License at
7 
8  https://imagemagick.org/script/license.php
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15 
16  MagickCore delegates private methods.
17 */
18 #ifndef MAGICKCORE_DELEGATE_PRIVATE_H
19 #define MAGICKCORE_DELEGATE_PRIVATE_H
20 
21 #include "MagickCore/locale_.h"
22 #include "MagickCore/string_.h"
23 
24 #if defined(MAGICKCORE_GS_DELEGATE)
25 #include "ghostscript/iapi.h"
26 #include "ghostscript/ierrors.h"
27 #else
28 typedef struct gsapi_revision_s
29 {
30  const char *product;
31  const char *copyright;
32  long revision;
33  long revisiondate;
35 #endif
36 
37 #if defined(__cplusplus) || defined(c_plusplus)
38 extern "C" {
39 #endif
40 
41 #ifndef gs_main_instance_DEFINED
42 # define gs_main_instance_DEFINED
43 typedef struct gs_main_instance_s
44  gs_main_instance;
45 #endif
46 
47 #if !defined(MagickDLLCall)
48 # if defined(MAGICKCORE_WINDOWS_SUPPORT)
49 # define MagickDLLCall __stdcall
50 # else
51 # define MagickDLLCall
52 # endif
53 #endif
54 
55 typedef struct _GhostInfo
56 {
57  void
58  (MagickDLLCall *delete_instance)(gs_main_instance *);
59 
60  int
61  (MagickDLLCall *exit)(gs_main_instance *);
62 
63  int
64  (MagickDLLCall *init_with_args)(gs_main_instance *,int,char **);
65 
66  int
67  (MagickDLLCall *new_instance)(gs_main_instance **,void *);
68 
69  int
70  (MagickDLLCall *run_string)(gs_main_instance *,const char *,int,int *);
71 
72  int
73  (MagickDLLCall* set_arg_encoding)(gs_main_instance*, int);
74 
75  int
76  (MagickDLLCall *set_stdio)(gs_main_instance *,int(MagickDLLCall *)(void *,
77  char *,int),int(MagickDLLCall *)(void *,const char *,int),
78  int(MagickDLLCall *)(void *,const char *,int));
79 
80  int
81  (MagickDLLCall *revision)(gsapi_revision_t *, int);
82 } GhostInfo;
83 
84 static inline char *SanitizeDelegateString(const char *source)
85 {
86  char
87  *sanitize_source;
88 
89  const char
90  *q;
91 
92  char
93  *p;
94 
95  static char
96 #if defined(MAGICKCORE_WINDOWS_SUPPORT)
97  allowlist[] =
98  "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 "
99  "$-_.+!;*(),{}|^~[]`\'><#%/?:@&=";
100 #else
101  allowlist[] =
102  "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 "
103  "$-_.+!;*(),{}|\\^~[]`\"><#%/?:@&=";
104 #endif
105 
106  sanitize_source=AcquireString(source);
107  p=sanitize_source;
108  q=sanitize_source+strlen(sanitize_source);
109  for (p+=strspn(p,allowlist); p != q; p+=(ptrdiff_t) strspn(p,allowlist))
110  *p='_';
111  return(sanitize_source);
112 }
113 
114 #if defined(MAGICKCORE_WINDOWS_SUPPORT)
115 static inline void FormatSanitizedDelegateOption(char *string,
116  const size_t length,const char *windows_format,
117  const char *magick_unused(non_windows_format),const char *option)
118 {
119  char
120  *sanitized_option;
121 
122  magick_unreferenced(non_windows_format);
123  sanitized_option=SanitizeDelegateString(option);
124  (void) FormatLocaleString(string,length,windows_format,sanitized_option);
125  sanitized_option=DestroyString(sanitized_option);
126 }
127 #else
128 static inline void FormatSanitizedDelegateOption(char *string,
129  const size_t length,const char *magick_unused(windows_format),
130  const char *non_windows_format,const char *option)
131 {
132  char
133  *sanitized_option;
134 
135  magick_unreferenced(windows_format);
136  sanitized_option=SanitizeDelegateString(option);
137  (void) FormatLocaleString(string,length,non_windows_format,sanitized_option);
138  sanitized_option=DestroyString(sanitized_option);
139 }
140 #endif
141 
142 extern MagickPrivate MagickBooleanType
143  DelegateComponentGenesis(void);
144 
145 extern MagickPrivate void
146  DelegateComponentTerminus(void);
147 
148 #if defined(__cplusplus) || defined(c_plusplus)
149 }
150 #endif
151 
152 #endif
gsapi_revision_s
Definition: delegate-private.h:28
_GhostInfo
Definition: delegate-private.h:55