MagickCore 7.0.10
option.c
Go to the documentation of this file.
1/*
2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3% %
4% %
5% OOO PPPP TTTTT IIIII OOO N N %
6% O O P P T I O O NN N %
7% O O PPPP T I O O N N N %
8% O O P T I O O N NN %
9% OOO P T IIIII OOO N N %
10% %
11% %
12% Wizard's Toolkit Option Methods %
13% %
14% Software Design %
15% Cristy %
16% March 2003 %
17% %
18% %
19% Copyright @ 1999 ImageMagick Studio LLC, a non-profit organization %
20% dedicated to making software imaging solutions freely available. %
21% %
22% You may not use this file except in compliance with the License. You may %
23% obtain a copy of the License at %
24% %
25% https://imagemagick.org/script/license.php %
26% %
27% Unless required by applicable law or agreed to in writing, software %
28% distributed under the License is distributed on an "AS IS" BASIS, %
29% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
30% See the License for the specific language governing permissions and %
31% limitations under the License. %
32% %
33%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
34%
35%
36*/
37
38/*
39 Include declarations.
40*/
41#include "wizard/studio.h"
42#include "wizard/authenticate.h"
43#include "wizard/cipher.h"
44#include "wizard/entropy.h"
46#include "wizard/memory_.h"
47#include "wizard/mime.h"
48#include "wizard/mime-private.h"
49#include "wizard/option.h"
50#include "wizard/resource_.h"
51#include "wizard/string_.h"
52#include "wizard/token.h"
53
54/*
55 Option declarations.
56*/
57static const OptionInfo
59 {
60 { "Undefined", (ssize_t) UndefinedAuthenticate },
61 { "Public", (ssize_t) PublicAuthenticateMethod },
62 { "Secret", (ssize_t) SecretAuthenticateMethod },
63 { (char *) NULL, UndefinedAuthenticate }
64 },
66 {
67 { "Undefined", (ssize_t) UndefinedCipher },
68 { "AES", (ssize_t) AESCipher },
69 { "Chacha", (ssize_t) ChachaCipher },
70 { "None", (ssize_t) NoCipher },
71 { "Serpent", (ssize_t) SerpentCipher },
72 { "Twofish", (ssize_t) TwofishCipher },
73 { (char *) NULL, UndefinedCipher }
74 },
76 {
77 { "+authenticate", 1L },
78 { "-authenticate", 1L },
79 { "+chunksize", 1L },
80 { "-chunksize", 1L },
81 { "+decipher", 0L },
82 { "-decipher", 0L },
83 { "+debug", 1L },
84 { "-debug", 1L },
85 { "+entropy", 1L },
86 { "-entropy", 1L },
87 { "+hash", 1L },
88 { "-hash", 1L },
89 { "+help", 0L },
90 { "-help", 0L },
91 { "+key", 1L },
92 { "-key", 1L },
93 { "+key-length", 1L },
94 { "-key-length", 1L },
95 { "+mac", 1L },
96 { "-mac", 1L },
97 { "+level", 1L },
98 { "-level", 1L },
99 { "+list", 1L },
100 { "-list", 1L },
101 { "+log", 1L },
102 { "-log", 1L },
103 { "+mode", 1L },
104 { "-mode", 1L },
105 { "+properties", 1L },
106 { "-properties", 1L },
107 { "+random", 1L },
108 { "-random", 1L },
109 { "+verbose", 0L },
110 { "-verbose", 0L },
111 { "+version", 1L },
112 { "-version", 1L },
113 { (char *) NULL, 0L }
114 },
116 {
117 { "Undefined", (ssize_t) UndefinedData },
118 { "Byte", (ssize_t) ByteData },
119 { "Long", (ssize_t) LongData },
120 { "Short", (ssize_t) ShortData },
121 { "String", (ssize_t) StringData },
122 { (char *) NULL, (ssize_t) UndefinedData }
123 },
125 {
126 { "Undefined", (ssize_t) UndefinedEndian },
127 { "LSB", (ssize_t) LSBEndian },
128 { "MSB", (ssize_t) MSBEndian },
129 { (char *) NULL, (ssize_t) UndefinedEndian }
130 },
132 {
133 { "0", 0L },
134 { "1", 1L },
135 { "2", 2L },
136 { "3", 3L },
137 { "4", 4L },
138 { "5", 5L },
139 { "6", 6L },
140 { "7", 7L },
141 { "8", 8L },
142 { "9", 9L },
143 { (char *) NULL, 0L }
144 },
146 {
147 { "Undefined", (ssize_t) UndefinedEntropy },
148 { "None", (ssize_t) NoEntropy },
149 { "BZip", (ssize_t) BZIPEntropy },
150 { "LZMA", (ssize_t) LZMAEntropy },
151 { "Zip", (ssize_t) ZIPEntropy },
152 { (char *) NULL, UndefinedEntropy }
153 },
155 {
156 { "256", 256L },
157 { "512", 512L },
158 { "1024", 1024L },
159 { "2048", 2048L },
160 { (char *) NULL, 0L }
161 },
163 {
164 { "Undefined", (ssize_t) UndefinedHash },
165 { "CRC64", (ssize_t) CRC64Hash },
166 { "MD5", (ssize_t) MD5Hash },
167 { "None", (ssize_t) NoHash },
168 { "SHA1", (ssize_t) SHA1Hash },
169 { "SHA224", (ssize_t) SHA2224Hash },
170 { "SHA256", (ssize_t) SHA2256Hash },
171 { "SHA384", (ssize_t) SHA2384Hash },
172 { "SHA512", (ssize_t) SHA2512Hash },
173 { "SHA2", (ssize_t) SHA2Hash },
174 { "SHA2-224", (ssize_t) SHA2224Hash },
175 { "SHA2-256", (ssize_t) SHA2256Hash },
176 { "SHA2-384", (ssize_t) SHA2384Hash },
177 { "SHA2-512", (ssize_t) SHA2512Hash },
178 { "SHA3", (ssize_t) SHA3Hash },
179 { "SHA3-224", (ssize_t) SHA3224Hash },
180 { "SHA3-256", (ssize_t) SHA3256Hash },
181 { "SHA3-384", (ssize_t) SHA3384Hash },
182 { "SHA3-512", (ssize_t) SHA3512Hash },
183 { (char *) NULL, UndefinedHash }
184 },
186 {
187 { "Authenticate", (ssize_t) WizardAuthenticateOptions },
188 { "Cipher", (ssize_t) WizardCipherOptions },
189 { "Command", (ssize_t) WizardCommandOptions },
190 { "DataType", (ssize_t) WizardDataTypeOptions },
191 { "Debug", (ssize_t) WizardDebugOptions },
192 { "Endian", (ssize_t) WizardEndianOptions },
193 { "Entropy", (ssize_t) WizardEntropyOptions },
194 { "EntropyLevel", (ssize_t) WizardEntropyLevelOptions },
195 { "Hash", (ssize_t) WizardHashOptions },
196 { "KeyLength", (ssize_t) WizardKeyLengthOptions },
197 { "List", (ssize_t) WizardListOptions },
198 { "Mode", (ssize_t) WizardModeOptions },
199 { (char *) NULL, (ssize_t) WizardUndefinedOptions }
200 },
202 {
203 { "All", (ssize_t) (AllEvents &~ TraceEvent) },
204 { "Blob", (ssize_t) BlobEvent },
205 { "Deprecate", (ssize_t) DeprecateEvent },
206 { "Configure", (ssize_t) ConfigureEvent },
207 { "Exception", (ssize_t) ExceptionEvent },
208 { "Locale", (ssize_t) LocaleEvent },
209 { "None", (ssize_t) NoEvents },
210 { "Resource", (ssize_t) ResourceEvent },
211 { "Trace", (ssize_t) TraceEvent },
212 { "User", (ssize_t) UserEvent },
213 { "Warning", (ssize_t) WarningEvent },
214 { (char *) NULL, UndefinedEvents }
215 },
217 {
218 { "Undefined", (ssize_t) UndefinedMode },
219 { "CBC", (ssize_t) CBCMode },
220 { "CFB", (ssize_t) CFBMode },
221 { "CTR", (ssize_t) CTRMode },
222 { "ECB", (ssize_t) ECBMode },
223 { "OFB", (ssize_t) OFBMode },
224 { (char *) NULL, UndefinedMode }
225 },
227 {
228 { "Undefined", (ssize_t) UndefinedResource },
229 { "Area", (ssize_t) AreaResource },
230 { "Disk", (ssize_t) DiskResource },
231 { "File", (ssize_t) FileResource },
232 { "Map", (ssize_t) MapResource },
233 { "Memory", (ssize_t) MemoryResource },
234 { (char *) NULL, (ssize_t) UndefinedResource }
235 };
236
237/*
238%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
239% %
240% %
241% %
242% G e t W i z a r d O p t i o n s %
243% %
244% %
245% %
246%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
247%
248% GetWizardOptions() returns a list of options.
249%
250% The format of the GetWizardOptions method is:
251%
252% const char **GetWizardOptions(const WizardOption option)
253%
254% A description of each parameter follows:
255%
256% o option: The option.
257%
258*/
259
260static const OptionInfo *GetOptionInfo(const WizardOption option)
261{
262 switch (option)
263 {
273 case WizardHashOptions: return(HashOptions);
274 case WizardListOptions: return(ListOptions);
276 case WizardModeOptions: return(ModeOptions);
278 default: break;
279 }
280 return((const OptionInfo *) NULL);
281}
282
284{
285 char
286 **options;
287
288 const OptionInfo
289 *option_info;
290
291 ssize_t
292 i;
293
294 option_info=GetOptionInfo(option);
295 if (option_info == (const OptionInfo *) NULL)
296 return((char **) NULL);
297 for (i=0; option_info[i].mnemonic != (const char *) NULL; i++) ;
298 options=(char **) AcquireQuantumMemory((size_t) i+1UL,sizeof(*options));
299 if (options == (char **) NULL)
300 ThrowFatalException(ResourceFatalError,"unable to acquire string `%s'");
301 for (i=0; option_info[i].mnemonic != (const char *) NULL; i++)
302 options[i]=AcquireString(option_info[i].mnemonic);
303 options[i]=(char *) NULL;
304 return(options);
305}
306
307/*
308%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
309% %
310% %
311% %
312% I s W i z a r d O p t i o n %
313% %
314% %
315% %
316%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
317%
318% IsWizardOption() returns WizardTrue if the option begins with a - or + and
319% the first character that follows is alphanumeric.
320%
321% The format of the IsWizardOption method is:
322%
323% WizardBooleanType IsWizardOption(const char *option)
324%
325% A description of each parameter follows:
326%
327% o option: The option.
328%
329*/
331{
332 assert(option != (const char *) NULL);
333 if ((*option != '-') && (*option != '+'))
334 return(WizardFalse);
335 if (strlen(option) == 1)
336 return(WizardFalse);
337 option++;
338 if (isalpha((int) ((unsigned char) *option)) == 0)
339 return(WizardFalse);
340 return(WizardTrue);
341}
342
343/*
344%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
345% %
346% %
347% %
348% L i s t W i z a r d O p t i o n s %
349% %
350% %
351% %
352%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
353%
354% ListWizardOptions() lists the contents of enumerated option type(s).
355%
356% The format of the ListWizardOptions method is:
357%
358% WizardBooleanType ListWizardOptions(FILE *file,const WizardOption option,
359% ExceptionInfo *exception)
360%
361% A description of each parameter follows:
362%
363% o file: list options to this file handle.
364%
365% o option: which option list to display.
366%
367% o exception: return any errors or warnings in this structure.
368%
369*/
371 const WizardOption option,ExceptionInfo *wizard_unused(exception))
372{
373 const OptionInfo
374 *option_info;
375
376 ssize_t
377 i;
378
379 if (file == (FILE *) NULL)
380 file=stdout;
381 option_info=GetOptionInfo(option);
382 if (option_info == (const OptionInfo *) NULL)
383 return(WizardFalse);
384 for (i=0; option_info[i].mnemonic != (char *) NULL; i++)
385 {
386 if ((i == 0) && (strcmp(option_info[i].mnemonic,"Undefined") == 0))
387 continue;
388 (void) fprintf(file,"%s\n",option_info[i].mnemonic);
389 }
390 return(WizardTrue);
391}
392
393/*
394%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
395% %
396% %
397% %
398% P a r s e W i z a r d O p t i o n %
399% %
400% %
401% %
402%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
403%
404% ParseWizardOption() parses an option string and returns an enumerated option
405% type(s).
406%
407% The format of the ParseWizardOption method is:
408%
409% ssize_t ParseWizardOption(const WizardOption option,
410% const WizardBooleanType list,const char *options)
411%
412% A description of each parameter follows:
413%
414% o option: The option.
415%
416% o list: A option other than zero permits more than one option separated by
417% commas.
418%
419% o options: One or more options separated by commas.
420%
421*/
423 const WizardBooleanType list,const char *options)
424{
425 char
426 token[WizardPathExtent];
427
428 const OptionInfo
429 *option_info;
430
431 ssize_t
432 option_types;
433
434 char
435 *q;
436
437 const char
438 *p;
439
440 ssize_t
441 i;
442
444 negate;
445
446 option_info=GetOptionInfo(option);
447 if (option_info == (const OptionInfo *) NULL)
448 return(-1);
449 option_types=0;
450 for (p=options; p != (char *) NULL; p=strchr(p,','))
451 {
452 while (((isspace((int) ((unsigned char) *p)) != 0) || (*p == ',')) &&
453 (*p != '\0'))
454 p++;
455 if ((*p == '-') || (*p == '+'))
456 p++;
457 negate=(*p == '!') ? WizardTrue : WizardFalse;
458 if (negate != WizardFalse)
459 p++;
460 q=token;
461 while (((isspace((int) ((unsigned char) *p)) == 0) && (*p != ',')) &&
462 (*p != '\0'))
463 {
464 if ((q-token) >= (WizardPathExtent-1))
465 break;
466 *q++=(*p++);
467 }
468 *q='\0';
469 for (i=0; option_info[i].mnemonic != (char *) NULL; i++)
470 {
471 if (LocaleCompare(token,option_info[i].mnemonic) == 0)
472 {
473 if (*token == '!')
474 option_types=option_types &~ option_info[i].type;
475 else
476 option_types=option_types | option_info[i].type;
477 break;
478 }
479 }
480 if ((option_info[i].mnemonic == (char *) NULL) &&
481 ((strchr(token+1,'-') != (char *) NULL) ||
482 (strchr(token+1,'_') != (char *) NULL)))
483 {
484 while ((q=strchr(token+1,'-')) != (char *) NULL)
485 (void) CopyWizardString(q,q+1,WizardPathExtent-strlen(q));
486 while ((q=strchr(token+1,'_')) != (char *) NULL)
487 (void) CopyWizardString(q,q+1,WizardPathExtent-strlen(q));
488 for (i=0; option_info[i].mnemonic != (char *) NULL; i++)
489 if (LocaleCompare(token,option_info[i].mnemonic) == 0)
490 {
491 if (*token == '!')
492 option_types=option_types &~ option_info[i].type;
493 else
494 option_types=option_types | option_info[i].type;
495 break;
496 }
497 }
498 if (option_info[i].mnemonic == (char *) NULL)
499 return(-1);
500 if (list == WizardFalse)
501 break;
502 }
503 return(option_types);
504}
505
506/*
507%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
508% %
509% %
510% %
511% W i z a r d O p t i o n T o M n e m o n i c %
512% %
513% %
514% %
515%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
516%
517% WizardOptionToMnemonic() returns an enumerated option as a mnemonic.
518%
519% The format of the WizardOptionToMnemonic method is:
520%
521% const char *WizardOptionToMnemonic(const WizardOption option,
522% const ssize_t type)
523%
524% A description of each parameter follows:
525%
526% o option: the option.
527%
528% o type: one or more options separated by commas.
529%
530*/
532 const ssize_t type)
533{
534 const OptionInfo
535 *option_info;
536
537 ssize_t
538 i;
539
540 option_info=GetOptionInfo(option);
541 if (option_info == (const OptionInfo *) NULL)
542 return((const char *) NULL);
543 for (i=0; option_info[i].mnemonic != (const char *) NULL; i++)
544 if (type == option_info[i].type)
545 break;
546 if (option_info[i].mnemonic == (const char *) NULL)
547 return("undefined");
548 return(option_info[i].mnemonic);
549}
@ SecretAuthenticateMethod
@ PublicAuthenticateMethod
@ UndefinedAuthenticate
@ UndefinedCipher
Definition cipher.h:41
@ SerpentCipher
Definition cipher.h:45
@ ChachaCipher
Definition cipher.h:44
@ NoCipher
Definition cipher.h:42
@ TwofishCipher
Definition cipher.h:46
@ AESCipher
Definition cipher.h:43
@ CTRMode
Definition cipher.h:34
@ CFBMode
Definition cipher.h:33
@ CBCMode
Definition cipher.h:32
@ UndefinedMode
Definition cipher.h:31
@ OFBMode
Definition cipher.h:36
@ ECBMode
Definition cipher.h:35
@ NoEntropy
Definition entropy.h:31
@ BZIPEntropy
Definition entropy.h:33
@ ZIPEntropy
Definition entropy.h:32
@ LZMAEntropy
Definition entropy.h:34
@ UndefinedEntropy
Definition entropy.h:30
#define ThrowFatalException(severity, tag)
@ ResourceFatalError
Definition exception.h:121
@ SHA3512Hash
Definition hash.h:43
@ SHA3Hash
Definition hash.h:39
@ CRC64Hash
Definition hash.h:31
@ SHA2224Hash
Definition hash.h:35
@ SHA2512Hash
Definition hash.h:38
@ SHA3256Hash
Definition hash.h:41
@ MD5Hash
Definition hash.h:32
@ SHA3384Hash
Definition hash.h:42
@ SHA2256Hash
Definition hash.h:36
@ SHA2Hash
Definition hash.h:34
@ SHA3224Hash
Definition hash.h:40
@ SHA1Hash
Definition hash.h:33
@ NoHash
Definition hash.h:30
@ SHA2384Hash
Definition hash.h:37
@ UndefinedHash
Definition hash.h:29
@ NoEvents
Definition log.h:38
@ UserEvent
Definition log.h:52
@ LocaleEvent
Definition log.h:47
@ WarningEvent
Definition log.h:51
@ DeprecateEvent
Definition log.h:45
@ AllEvents
Definition log.h:53
@ TraceEvent
Definition log.h:39
@ UndefinedEvents
Definition log.h:37
@ ExceptionEvent
Definition log.h:46
@ ConfigureEvent
Definition log.h:44
@ BlobEvent
Definition log.h:41
@ ResourceEvent
Definition log.h:49
WizardExport void * AcquireQuantumMemory(const size_t count, const size_t quantum)
Definition memory.c:657
#define WizardExport
#define WizardPathExtent
#define wizard_unused(x)
@ MSBEndian
@ LSBEndian
@ UndefinedEndian
@ StringData
@ ShortData
@ UndefinedData
@ LongData
@ ByteData
static const OptionInfo HashOptions[]
Definition option.c:162
static const OptionInfo ResourceOptions[]
Definition option.c:226
WizardExport WizardBooleanType ListWizardOptions(FILE *file, const WizardOption option, ExceptionInfo *wizard_unused(exception))
Definition option.c:370
static const OptionInfo CipherOptions[]
Definition option.c:65
static const OptionInfo ModeOptions[]
Definition option.c:216
static const OptionInfo EntropyLevelOptions[]
Definition option.c:131
static const OptionInfo EndianOptions[]
Definition option.c:124
WizardExport char ** GetWizardOptions(const WizardOption option)
Definition option.c:283
static const OptionInfo CommandOptions[]
Definition option.c:75
WizardExport ssize_t ParseWizardOption(const WizardOption option, const WizardBooleanType list, const char *options)
Definition option.c:422
static const OptionInfo AuthenticateOptions[]
Definition option.c:58
static const OptionInfo * GetOptionInfo(const WizardOption option)
Definition option.c:260
static const OptionInfo EntropyOptions[]
Definition option.c:145
WizardExport WizardBooleanType IsWizardOption(const char *option)
Definition option.c:330
static const OptionInfo KeyLengthOptions[]
Definition option.c:154
static const OptionInfo DataTypeOptions[]
Definition option.c:115
WizardExport const char * WizardOptionToMnemonic(const WizardOption option, const ssize_t type)
Definition option.c:531
static const OptionInfo ListOptions[]
Definition option.c:185
static const OptionInfo LogWizardEventOptions[]
Definition option.c:201
WizardOption
Definition option.h:38
@ WizardAuthenticateOptions
Definition option.h:40
@ WizardDataTypeOptions
Definition option.h:43
@ WizardEndianOptions
Definition option.h:45
@ WizardCommandOptions
Definition option.h:42
@ WizardEntropyLevelOptions
Definition option.h:47
@ WizardDebugOptions
Definition option.h:44
@ WizardKeyLengthOptions
Definition option.h:48
@ WizardModeOptions
Definition option.h:51
@ WizardUndefinedOptions
Definition option.h:39
@ WizardEntropyOptions
Definition option.h:46
@ WizardHashOptions
Definition option.h:49
@ WizardListOptions
Definition option.h:50
@ WizardLogEventOptions
Definition option.h:52
@ WizardResourceOptions
Definition option.h:53
@ WizardCipherOptions
Definition option.h:41
@ DiskResource
Definition resource_.h:36
@ AreaResource
Definition resource_.h:35
@ UndefinedResource
Definition resource_.h:34
@ MapResource
Definition resource_.h:38
@ FileResource
Definition resource_.h:37
@ MemoryResource
Definition resource_.h:39
WizardExport int LocaleCompare(const char *p, const char *q)
Definition string.c:1510
WizardExport char * AcquireString(const char *source)
Definition string.c:133
WizardExport size_t CopyWizardString(char *destination, const char *source, const size_t length)
Definition string.c:762
ssize_t type
Definition option.h:34
const char * mnemonic
Definition option.h:31
WizardBooleanType
Definition wizard-type.h:26
@ WizardTrue
Definition wizard-type.h:28
@ WizardFalse
Definition wizard-type.h:27