7bf63c60c0d16f122ff527a54e813a4cb35ff5ef
[platform/upstream/flac.git] / src / metaflac / usage.c
1 /* metaflac - Command-line FLAC metadata editor
2  * Copyright (C) 2001,2002  Josh Coalson
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
17  */
18
19 #include "usage.h"
20 #include "FLAC/format.h"
21 #include <stdarg.h>
22 #include <stdio.h>
23
24 static void usage_header(FILE *out)
25 {
26         fprintf(out, "==============================================================================\n");
27         fprintf(out, "metaflac - Command-line FLAC metadata editor version %s\n", FLAC__VERSION_STRING);
28         fprintf(out, "Copyright (C) 2001,2002  Josh Coalson\n");
29         fprintf(out, "\n");
30         fprintf(out, "This program is free software; you can redistribute it and/or\n");
31         fprintf(out, "modify it under the terms of the GNU General Public License\n");
32         fprintf(out, "as published by the Free Software Foundation; either version 2\n");
33         fprintf(out, "of the License, or (at your option) any later version.\n");
34         fprintf(out, "\n");
35         fprintf(out, "This program is distributed in the hope that it will be useful,\n");
36         fprintf(out, "but WITHOUT ANY WARRANTY; without even the implied warranty of\n");
37         fprintf(out, "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n");
38         fprintf(out, "GNU General Public License for more details.\n");
39         fprintf(out, "\n");
40         fprintf(out, "You should have received a copy of the GNU General Public License\n");
41         fprintf(out, "along with this program; if not, write to the Free Software\n");
42         fprintf(out, "Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\n");
43         fprintf(out, "==============================================================================\n");
44 }
45
46 static void usage_summary(FILE *out)
47 {
48         fprintf(out, "Usage:\n");
49         fprintf(out, "  metaflac [options] [operations] FLACfile [FLACfile ...]\n");
50         fprintf(out, "\n");
51         fprintf(out, "Use metaflac to list, add, remove, or edit metadata in one or more FLAC files.\n");
52         fprintf(out, "You may perform one major operation, or many shorthand operations at a time.\n");
53         fprintf(out, "\n");
54         fprintf(out, "Options:\n");
55         fprintf(out, "--preserve-modtime    Preserve the original modification time in spite of edits\n");
56         fprintf(out, "--with-filename       Prefix each output line with the FLAC file name\n");
57         fprintf(out, "                      (the default if more than one FLAC file is specified)\n");
58         fprintf(out, "--no-filename         Do not prefix each output line with the FLAC file name\n");
59         fprintf(out, "                      (the default if only one FLAC file is specified)\n");
60         fprintf(out, "--no-utf8-convert     Do not convert Vorbis comments from UTF-8 to local charset,\n");
61         fprintf(out, "                      or vice versa.  This is useful for scripts.\n");
62         fprintf(out, "--dont-use-padding    By default metaflac tries to use padding where possible\n");
63         fprintf(out, "                      to avoid rewriting the entire file if the metadata size\n");
64         fprintf(out, "                      changes.  Use this option to tell metaflac to not take\n");
65         fprintf(out, "                      advantage of padding this way.\n");
66 }
67
68 int short_usage(const char *message, ...)
69 {
70         va_list args;
71
72         if(message) {
73                 va_start(args, message);
74
75                 (void) vfprintf(stderr, message, args);
76
77                 va_end(args);
78
79         }
80         usage_header(stderr);
81         fprintf(stderr, "\n");
82         fprintf(stderr, "This is the short help; for full help use 'metaflac --help'\n");
83         fprintf(stderr, "\n");
84         usage_summary(stderr);
85
86         return message? 1 : 0;
87 }
88
89 int long_usage(const char *message, ...)
90 {
91         FILE *out = (message? stderr : stdout);
92         va_list args;
93
94         if(message) {
95                 va_start(args, message);
96
97                 (void) vfprintf(stderr, message, args);
98
99                 va_end(args);
100
101         }
102         usage_header(out);
103         fprintf(out, "\n");
104         usage_summary(out);
105         fprintf(out, "\n");
106         fprintf(out, "Shorthand operations:\n");
107         fprintf(out, "--show-md5sum         Show the MD5 signature from the STREAMINFO block.\n");
108         fprintf(out, "--show-min-blocksize  Show the minimum block size from the STREAMINFO block.\n");
109         fprintf(out, "--show-max-blocksize  Show the maximum block size from the STREAMINFO block.\n");
110         fprintf(out, "--show-min-framesize  Show the minimum frame size from the STREAMINFO block.\n");
111         fprintf(out, "--show-max-framesize  Show the maximum frame size from the STREAMINFO block.\n");
112         fprintf(out, "--show-sample-rate    Show the sample rate from the STREAMINFO block.\n");
113         fprintf(out, "--show-channels       Show the number of channels from the STREAMINFO block.\n");
114         fprintf(out, "--show-bps            Show the # of bits per sample from the STREAMINFO block.\n");
115         fprintf(out, "--show-total-samples  Show the total # of samples from the STREAMINFO block.\n");
116         fprintf(out, "\n");
117         fprintf(out, "--show-vc-vendor      Show the vendor string from the VORBIS_COMMENT block.\n");
118         fprintf(out, "--show-vc-field=name  Show all Vorbis comment fields where the the field name\n");
119         fprintf(out, "                      matches 'name'.\n");
120         fprintf(out, "--remove-vc-field=name  Remove all Vorbis comment fields whose field name\n");
121         fprintf(out, "                      is 'name'.\n");
122         fprintf(out, "--remove-vc-firstfield=name  Remove first Vorbis comment field whose field\n");
123         fprintf(out, "                      name is 'name'.\n");
124         fprintf(out, "--remove-vc-all       Remove all Vorbis comment fields, leaving only the\n");
125         fprintf(out, "                      vendor string in the VORBIS_COMMENT block.\n");
126         fprintf(out, "--set-vc-field=field  Add a Vorbis comment field.  The field must comply with\n");
127         fprintf(out, "                      the Vorbis comment spec, of the form \"NAME=VALUE\".  If\n");
128         fprintf(out, "                      there is currently no VORBIS_COMMENT block, one will be\n");
129         fprintf(out, "                      created.\n");
130         fprintf(out, "--import-vc-from=file Import Vorbis comments from a file.  Use '-' for stdin.\n");
131         fprintf(out, "                      Each line should be of the form NAME=VALUE.  Multi-\n");
132         fprintf(out, "                      line comments are currently not supported.  Specify\n");
133         fprintf(out, "                      --remove-vc-all and/or --no-utf8-convert before\n");
134         fprintf(out, "                      --import-vc-from if necessary.\n");
135         fprintf(out, "--export-vc-to=file   Export Vorbis comments to a file.  Use '-' for stdin.\n");
136         fprintf(out, "                      Each line will be of the form NAME=VALUE.  Specify\n");
137         fprintf(out, "                      --no-utf8-convert if necessary.\n");
138         fprintf(out, "--import-cuesheet-from=file  Import a cuesheet from a file.  Only one FLAC\n");
139         fprintf(out, "                      file may be specified.  A seekpoint will be added for\n");
140         fprintf(out, "                      each index point in the cuesheet to the SEEKTABLE unless\n");
141         fprintf(out, "                      --no-cued-seekpoints is specified.\n");
142         fprintf(out, "--export-cuesheet-to=file  Export CUESHEET block to a cuesheet file, suitable\n");
143         fprintf(out, "                      for use by CD authoring software.  Use '-' for stdin.\n");
144         fprintf(out, "                      Only one FLAC file may be specified on the command line.\n");
145         fprintf(out, "--add-replay-gain     Calculates the title and album gains/peaks of the given\n");
146         fprintf(out, "                      FLAC files as if all the files were part of one album,\n");
147         fprintf(out, "                      then stores them in the VORBIS_COMMENT block.  The tags\n");
148         fprintf(out, "                      are the same as those used by vorbisgain.  Existing\n");
149         fprintf(out, "                      ReplayGain tags will be replaced.  If only one FLAC file\n");
150         fprintf(out, "                      is given, the album and title gains will be the same.\n");
151         fprintf(out, "                      Since this operation requires two passes, it is always\n");
152         fprintf(out, "                      executed last, after all other operations have been\n");
153         fprintf(out, "                      completed and written to disk.  All FLAC files specified\n");
154         fprintf(out, "                      must have the same resolution, sample rate, and number\n");
155         fprintf(out, "                      of channels.  The sample rate must be one of 8, 11.025,\n");
156         fprintf(out, "                      12, 16, 22.05, 24, 32, 44.1, or 48 kHz.\n");
157         fprintf(out, "--add-seekpoint={#|X|#x|#s}  Add seek points to a SEEKTABLE block\n");
158         fprintf(out, "       #  : a specific sample number for a seek point\n");
159         fprintf(out, "       X  : a placeholder point (always goes at the end of the SEEKTABLE)\n");
160         fprintf(out, "       #x : # evenly spaced seekpoints, the first being at sample 0\n");
161         fprintf(out, "       #s : a seekpoint every # seconds; # does not have to be a whole number\n");
162         fprintf(out, "                      If no SEEKTABLE block exists, one will be created.  If\n");
163         fprintf(out, "                      one already exists, points will be added to the existing\n");
164         fprintf(out, "                      table, and any duplicates will be turned into placeholder\n");
165         fprintf(out, "                      points.  You may use many --add-seekpoint options; the\n");
166         fprintf(out, "                      resulting SEEKTABLE will be the unique-ified union of\n");
167         fprintf(out, "                      all such values.  Example: --add-seekpoint=100x\n");
168         fprintf(out, "                      --add-seekpoint=3.5s will add 100 evenly spaced\n");
169         fprintf(out, "                      seekpoints and a seekpoint every 3.5 seconds.\n");
170         fprintf(out, "--add-padding=length  Add a padding block of the given length (in bytes).\n");
171         fprintf(out, "                      The overall length of the new block will be 4 + length;\n");
172         fprintf(out, "                      the extra 4 bytes is for the metadata block header.\n");
173         fprintf(out, "\n");
174         fprintf(out, "Major operations:\n");
175         fprintf(out, "--version\n");
176         fprintf(out, "    Show the metaflac version number.\n");
177         fprintf(out, "--list\n");
178         fprintf(out, "    List the contents of one or more metadata blocks to stdout.  By default,\n");
179         fprintf(out, "    all metadata blocks are listed in text format.  Use the following options\n");
180         fprintf(out, "    to change this behavior:\n");
181         fprintf(out, "\n");
182         fprintf(out, "    --block-number=#[,#[...]]\n");
183         fprintf(out, "    An optional comma-separated list of block numbers to display.  The first\n");
184         fprintf(out, "    block, the STREAMINFO block, is block 0.\n");
185         fprintf(out, "\n");
186         fprintf(out, "    --block-type=type[,type[...]]\n");
187         fprintf(out, "    --except-block-type=type[,type[...]]\n");
188         fprintf(out, "    An optional comma-separated list of block types to included or ignored\n");
189         fprintf(out, "    with this option.  Use only one of --block-type or --except-block-type.\n");
190         fprintf(out, "    The valid block types are: STREAMINFO, PADDING, APPLICATION, SEEKTABLE,\n");
191         fprintf(out, "    VORBIS_COMMENT.  You may narrow down the types of APPLICATION blocks\n");
192         fprintf(out, "    displayed as follows:\n");
193         fprintf(out, "        APPLICATION:abcd        The APPLICATION block(s) whose textual repre-\n");
194         fprintf(out, "                                sentation of the 4-byte ID is \"abcd\"\n");
195         fprintf(out, "        APPLICATION:0xXXXXXXXX  The APPLICATION block(s) whose hexadecimal big-\n");
196         fprintf(out, "                                endian representation of the 4-byte ID is\n");
197         fprintf(out, "                                \"0xXXXXXXXX\".  For the example \"abcd\" above the\n");
198         fprintf(out, "                                hexadecimal equivalalent is 0x61626364\n");
199         fprintf(out, "\n");
200         fprintf(out, "    NOTE: if both --block-number and --[except-]block-type are specified,\n");
201         fprintf(out, "          the result is the logical AND of both arguments.\n");
202         fprintf(out, "\n");
203 #if 0
204         /*@@@ not implemented yet */
205         fprintf(out, "    --data-format=binary|text\n");
206         fprintf(out, "    By default a human-readable text representation of the data is displayed.\n");
207         fprintf(out, "    You may specify --data-format=binary to dump the raw binary form of each\n");
208         fprintf(out, "    metadata block.  The output can be read in using a subsequent call to\n");
209         fprintf(out, "    "metaflac --append --from-file=..."\n");
210         fprintf(out, "\n");
211 #endif
212         fprintf(out, "    --application-data-format=hexdump|text\n");
213         fprintf(out, "    If the application block you are displaying contains binary data but your\n");
214         fprintf(out, "    --data-format=text, you can display a hex dump of the application data\n");
215         fprintf(out, "    contents instead using --application-data-format=hexdump\n");
216         fprintf(out, "\n");
217 #if 0
218         /*@@@ not implemented yet */
219         fprintf(out, "--append\n");
220         fprintf(out, "    Insert a metadata block from a file.  The input file must be in the same\n");
221         fprintf(out, "    format as generated with --list.\n");
222         fprintf(out, "\n");
223         fprintf(out, "    --block-number=#\n");
224         fprintf(out, "    Specify the insertion point (defaults to last block).  The new block will\n");
225         fprintf(out, "    be added after the given block number.  This prevents the illegal insertion\n");
226         fprintf(out, "    of a block before the first STREAMINFO block.  You may not --append another\n");
227         fprintf(out, "    STREAMINFO block.\n");
228         fprintf(out, "\n");
229         fprintf(out, "    --from-file=filename\n");
230         fprintf(out, "    Mandatory 'option' to specify the input file containing the block contents.\n");
231         fprintf(out, "\n");
232         fprintf(out, "    --data-format=binary|text\n");
233         fprintf(out, "    By default the block contents are assumed to be in binary format.  You can\n");
234         fprintf(out, "    override this by specifying --data-format=text\n");
235         fprintf(out, "\n");
236 #endif
237         fprintf(out, "--remove\n");
238         fprintf(out, "    Remove one or more metadata blocks from the metadata.  Unless\n");
239         fprintf(out, "    --dont-use-padding is specified, the blocks will be replaced with padding.\n");
240         fprintf(out, "    You may not remove the STREAMINFO block.\n");
241         fprintf(out, "\n");
242         fprintf(out, "    --block-number=#[,#[...]]\n");
243         fprintf(out, "    --block-type=type[,type[...]]\n");
244         fprintf(out, "    --except-block-type=type[,type[...]]\n");
245         fprintf(out, "    See --list above for usage.\n");
246         fprintf(out, "\n");
247         fprintf(out, "    NOTE: if both --block-number and --[except-]block-type are specified,\n");
248         fprintf(out, "          the result is the logical AND of both arguments.\n");
249         fprintf(out, "\n");
250         fprintf(out, "--remove-all\n");
251         fprintf(out, "    Remove all metadata blocks (except the STREAMINFO block) from the\n");
252         fprintf(out, "    metadata.  Unless --dont-use-padding is specified, the blocks will be\n");
253         fprintf(out, "    replaced with padding.\n");
254         fprintf(out, "\n");
255         fprintf(out, "--merge-padding\n");
256         fprintf(out, "    Merge adjacent PADDING blocks into single blocks.\n");
257         fprintf(out, "\n");
258         fprintf(out, "--sort-padding\n");
259         fprintf(out, "    Move all PADDING blocks to the end of the metadata and merge them into a\n");
260         fprintf(out, "    single block.\n");
261
262         return message? 1 : 0;
263 }