comparison mupdf-source/include/mupdf/fitz/getopt.h @ 2:b50eed0cc0ef upstream

ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4. The directory name has changed: no version number in the expanded directory now.
author Franz Glasner <fzglas.hg@dom66.de>
date Mon, 15 Sep 2025 11:43:07 +0200
parents
children
comparison
equal deleted inserted replaced
1:1d09e1dec1d9 2:b50eed0cc0ef
1 // Copyright (C) 2004-2021 Artifex Software, Inc.
2 //
3 // This file is part of MuPDF.
4 //
5 // MuPDF is free software: you can redistribute it and/or modify it under the
6 // terms of the GNU Affero General Public License as published by the Free
7 // Software Foundation, either version 3 of the License, or (at your option)
8 // any later version.
9 //
10 // MuPDF is distributed in the hope that it will be useful, but WITHOUT ANY
11 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 // FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
13 // details.
14 //
15 // You should have received a copy of the GNU Affero General Public License
16 // along with MuPDF. If not, see <https://www.gnu.org/licenses/agpl-3.0.en.html>
17 //
18 // Alternative licensing terms are available from the licensor.
19 // For commercial licensing, see <https://www.artifex.com/> or contact
20 // Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco,
21 // CA 94129, USA, for further information.
22
23 #ifndef MUPDF_FITZ_GETOPT_H
24 #define MUPDF_FITZ_GETOPT_H
25
26 #include "export.h"
27
28 typedef struct
29 {
30 char *option;
31 int *flag;
32 void *opaque;
33 } fz_getopt_long_options;
34
35 /**
36 Simple functions/variables for use in tools.
37
38 ostr = option string. Comprises single letter options, followed by : if there
39 is an argument to the option.
40
41 longopts: NULL (indicating no long options), or a pointer to an array of
42 longoptions, terminated by an entry with option == NULL.
43
44 In the event of matching a single char option, this function will normally
45 return the char. The exception to this is when the option requires an
46 argument and none is supplied; in this case we return ':'.
47
48 In the event of matching a long option, this function returns 0, with fz_optlong
49 set to point to the matching option.
50
51 A long option entry may be followed with : to indicate there is an argument to the
52 option. If the need for an argument is specified in this way, and no argument is
53 given, an error will be displayed and argument processing will stop. If an argument
54 is given, and the long option record contains a non-null flag pointer, then the code
55 will decode the argument and fill in that flag pointer. Specifically,
56 case-insensitive matches to 'yes', 'no', 'true' and 'false' will cause a value of 0
57 or 1 as appropriate to be written; failing this the arg will be interpreted as a
58 decimal integer using atoi.
59
60 A long option entry may be followed by an list of options (e.g. myoption=foo|bar|baz)
61 and the option will be passed to fz_opt_from_list. The return value of that will be
62 placed in fz_optitem. If the return value of that function is -1, then an error will
63 be displayed and argument processing will stop.
64
65 In the event of reaching the end of the arg list or '--', this function returns EOF.
66
67 In the event of failing to match anything, an error is printed, and we return '?'.
68
69 If an argument is expected for the option, then fz_optarg will be returned pointing
70 at the start of the argument. Examples of supported argument formats: '-r500', '-r 500',
71 '--resolution 500', '--resolution=500'.
72 */
73 extern int fz_getopt_long(int nargc, char * const *nargv, const char *ostr, const fz_getopt_long_options *longopts);
74
75 /**
76 Identical to fz_getopt_long, but with a NULL longopts field, signifying no long
77 options.
78 */
79 extern int fz_getopt(int nargc, char * const *nargv, const char *ostr);
80
81 /**
82 fz_optind is updated to point to the current index being read from the
83 arguments.
84 */
85 FZ_DATA extern int fz_optind;
86
87 /**
88 fz_optarg is a pointer to the argument data for the most recently
89 read option.
90 */
91 FZ_DATA extern char *fz_optarg;
92
93 /**
94 fz_optlong is a pointer to the record for the most recently
95 read long option. (i.e. if a long option is detected, this
96 will be set to point to the record for that option, otherwise
97 it will be NULL).
98 */
99 FZ_DATA extern const fz_getopt_long_options *fz_optlong;
100
101 /**
102 The item number for the most recently matched item list.
103
104 First item in the list is numbered 0. No match is -1.
105 */
106 FZ_DATA extern int fz_optitem;
107
108 /**
109 Return the index of a (case-insensitive) option within an optlist.
110
111 For instance for optlist = "Foo|Bar|Baz", and opt = "bar",
112 this would return 1.
113
114 If the optlist ends with "|*" then that is a catch all case and
115 matches all options allowing the caller to process it itself.
116 fz_optarg will be set to point to the option, and the return
117 value will be the index of the '*' option within that list.
118
119 If an optlist entry ends with ':' (e.g. "Foo:") then that option
120 may have suboptions appended to it (for example "JPG:80") and
121 fz_optarg will be set to point at "80". Otherwise fz_optarg will
122 be set to NULL.
123
124 In the event of no-match found, prints an error and returns -1.
125 */
126 int fz_opt_from_list(char *opt, const char *optlist);
127
128 /**
129 Convert "-" to "/dev/stdout" for use with command lines.
130 Also converts "nul" and "con" on Windows.
131 */
132 char *fz_optpath(char *opt);
133
134 #endif