• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* metaflac - Command-line FLAC metadata editor
2  * Copyright (C) 2001-2009  Josh Coalson
3  * Copyright (C) 2011-2022  Xiph.Org Foundation
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 #ifndef metaflac__options_h
21 #define metaflac__options_h
22 
23 #include "FLAC/format.h"
24 
25 #if 0
26 /*[JEC] was:#if HAVE_GETOPT_LONG*/
27 /*[JEC] see flac/include/share/getopt.h as to why the change */
28 #  include <getopt.h>
29 #else
30 #  include "share/getopt.h"
31 #endif
32 
33 extern struct share__option long_options_[];
34 
35 typedef enum {
36 	OP__SHOW_MD5SUM,
37 	OP__SHOW_MIN_BLOCKSIZE,
38 	OP__SHOW_MAX_BLOCKSIZE,
39 	OP__SHOW_MIN_FRAMESIZE,
40 	OP__SHOW_MAX_FRAMESIZE,
41 	OP__SHOW_SAMPLE_RATE,
42 	OP__SHOW_CHANNELS,
43 	OP__SHOW_BPS,
44 	OP__SHOW_TOTAL_SAMPLES,
45 	OP__SET_MD5SUM,
46 	OP__SET_MIN_BLOCKSIZE,
47 	OP__SET_MAX_BLOCKSIZE,
48 	OP__SET_MIN_FRAMESIZE,
49 	OP__SET_MAX_FRAMESIZE,
50 	OP__SET_SAMPLE_RATE,
51 	OP__SET_CHANNELS,
52 	OP__SET_BPS,
53 	OP__SET_TOTAL_SAMPLES,
54 	OP__SHOW_VC_VENDOR,
55 	OP__SHOW_VC_FIELD,
56 	OP__REMOVE_VC_ALL,
57 	OP__REMOVE_VC_ALL_EXCEPT,
58 	OP__REMOVE_VC_FIELD,
59 	OP__REMOVE_VC_FIRSTFIELD,
60 	OP__SET_VC_FIELD,
61 	OP__IMPORT_VC_FROM,
62 	OP__EXPORT_VC_TO,
63 	OP__IMPORT_CUESHEET_FROM,
64 	OP__EXPORT_CUESHEET_TO,
65 	OP__IMPORT_PICTURE_FROM,
66 	OP__EXPORT_PICTURE_TO,
67 	OP__ADD_SEEKPOINT,
68 	OP__ADD_REPLAY_GAIN,
69 	OP__SCAN_REPLAY_GAIN,
70 	OP__ADD_PADDING,
71 	OP__LIST,
72 	OP__APPEND,
73 	OP__REMOVE,
74 	OP__REMOVE_ALL,
75 	OP__MERGE_PADDING,
76 	OP__SORT_PADDING
77 } OperationType;
78 
79 typedef enum {
80 	ARG__BLOCK_NUMBER,
81 	ARG__BLOCK_TYPE,
82 	ARG__EXCEPT_BLOCK_TYPE,
83 	ARG__DATA_FORMAT,
84 	ARG__FROM_FILE
85 } ArgumentType;
86 
87 typedef struct {
88 	FLAC__byte value[16];
89 } Argument_StreaminfoMD5;
90 
91 typedef struct {
92 	FLAC__uint32 value;
93 } Argument_StreaminfoUInt32;
94 
95 typedef struct {
96 	FLAC__uint64 value;
97 } Argument_StreaminfoUInt64;
98 
99 typedef struct {
100 	char *value;
101 } Argument_VcFieldName;
102 
103 typedef struct {
104 	char *field; /* the whole field as passed on the command line, i.e. "NAME=VALUE" */
105 	char *field_name;
106 	/* according to the vorbis spec, field values can contain \0 so simple C strings are not enough here */
107 	unsigned field_value_length;
108 	char *field_value;
109 	FLAC__bool field_value_from_file; /* true if field_value holds a filename for the value, false for plain value */
110 } Argument_VcField;
111 
112 typedef struct {
113 	char *value;
114 } Argument_String;
115 
116 typedef struct {
117 	unsigned num_entries;
118 	unsigned *entries;
119 } Argument_BlockNumber;
120 
121 typedef struct {
122 	FLAC__MetadataType type;
123 	char application_id[4]; /* only relevant if type == FLAC__STREAM_METADATA_TYPE_APPLICATION */
124 	FLAC__bool filter_application_by_id;
125 } Argument_BlockTypeEntry;
126 
127 typedef struct {
128 	unsigned num_entries;
129 	Argument_BlockTypeEntry *entries;
130 } Argument_BlockType;
131 
132 typedef struct {
133 	FLAC__bool is_binary;
134 } Argument_DataFormat;
135 
136 typedef struct {
137 	char *file_name;
138 } Argument_FromFile;
139 
140 typedef struct {
141 	char *specification;
142 } Argument_AddSeekpoint;
143 
144 typedef struct {
145 	char *filename;
146 	Argument_AddSeekpoint *add_seekpoint_link;
147 } Argument_ImportCuesheetFrom;
148 
149 typedef struct {
150 	char *filename;
151 	const Argument_BlockNumber *block_number_link; /* may be NULL to mean 'first PICTURE block' */
152 } Argument_ExportPictureTo;
153 
154 typedef struct {
155 	unsigned length;
156 } Argument_AddPadding;
157 
158 typedef struct {
159 	OperationType type;
160 	union {
161 		Argument_StreaminfoMD5 streaminfo_md5;
162 		Argument_StreaminfoUInt32 streaminfo_uint32;
163 		Argument_StreaminfoUInt64 streaminfo_uint64;
164 		Argument_VcFieldName vc_field_name;
165 		Argument_VcField vc_field;
166 		Argument_String filename;
167 		Argument_String specification;
168 		Argument_ImportCuesheetFrom import_cuesheet_from;
169 		Argument_ExportPictureTo export_picture_to;
170 		Argument_AddSeekpoint add_seekpoint;
171 		Argument_AddPadding add_padding;
172 	} argument;
173 } Operation;
174 
175 typedef struct {
176 	ArgumentType type;
177 	union {
178 		Argument_BlockNumber block_number;
179 		Argument_BlockType block_type;
180 		Argument_DataFormat data_format;
181 		Argument_FromFile from_file;
182 	} value;
183 } Argument;
184 
185 typedef struct {
186 	FLAC__bool preserve_modtime;
187 	FLAC__bool prefix_with_filename;
188 	FLAC__bool utf8_convert;
189 	FLAC__bool use_padding;
190 	FLAC__bool cued_seekpoints;
191 	FLAC__bool show_long_help;
192 	FLAC__bool show_version;
193 	FLAC__bool application_data_format_is_hexdump;
194 	struct {
195 		Operation *operations;
196 		unsigned num_operations;
197 		unsigned capacity;
198 	} ops;
199 	struct {
200 		struct {
201 			unsigned num_shorthand_ops;
202 			unsigned num_major_ops;
203 			FLAC__bool has_block_type;
204 			FLAC__bool has_except_block_type;
205 		} checks;
206 		Argument *arguments;
207 		unsigned num_arguments;
208 		unsigned capacity;
209 	} args;
210 	unsigned num_files;
211 	char **filenames;
212 } CommandLineOptions;
213 
214 void init_options(CommandLineOptions *options);
215 FLAC__bool parse_options(int argc, char *argv[], CommandLineOptions *options);
216 void free_options(CommandLineOptions *options);
217 
218 #endif
219