1 /* metaflac - Command-line FLAC metadata editor
2 * Copyright (C) 2001 Josh Coalson
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.
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.
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.
20 * WATCHOUT - this is meant to be very lightweight an not even dependent
21 * on libFLAC, so there are a couple places where FLAC__* variables are
22 * duplicated here. Look for 'DUPLICATE:' in comments.
33 static const char *sync_string_ = "fLaC"; /* DUPLICATE:FLAC__STREAM_SYNC_STRING */
35 static int usage(const char *message, ...);
36 static bool list(FILE *f, bool verbose);
38 int main(int argc, char *argv[])
41 bool verbose = false, list_mode = true;
47 for(i = 1; i < argc; i++) {
48 if(argv[i][0] != '-' || argv[i][1] == 0)
50 if(0 == strcmp(argv[i], "-l"))
52 else if(0 == strcmp(argv[i], "-v"))
54 else if(0 == strcmp(argv[i], "-v-"))
57 return usage("ERROR: invalid option '%s'\n", argv[i]);
60 if(i + (list_mode? 1:2) != argc)
61 return usage("ERROR: invalid arguments (more/less than %d filename%s?)\n", (list_mode? 1:2), (list_mode? "":"s"));
64 FILE *f = fopen(argv[i], "r");
67 fprintf(stderr, "ERROR opening %s\n", argv[i]);
80 int usage(const char *message, ...)
85 va_start(args, message);
87 (void) vfprintf(stderr, message, args);
92 printf("==============================================================================\n");
93 printf("metaflac - Command-line FLAC metadata editor version %s\n", FLAC__VERSION_STRING);
94 printf("Copyright (C) 2001 Josh Coalson\n");
96 printf("This program is free software; you can redistribute it and/or\n");
97 printf("modify it under the terms of the GNU General Public License\n");
98 printf("as published by the Free Software Foundation; either version 2\n");
99 printf("of the License, or (at your option) any later version.\n");
101 printf("This program is distributed in the hope that it will be useful,\n");
102 printf("but WITHOUT ANY WARRANTY; without even the implied warranty of\n");
103 printf("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n");
104 printf("GNU General Public License for more details.\n");
106 printf("You should have received a copy of the GNU General Public License\n");
107 printf("along with this program; if not, write to the Free Software\n");
108 printf("Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n");
109 printf("==============================================================================\n");
111 printf(" metaflac [options] infile [outfile]\n");
113 printf("options:\n");
114 printf(" -l : list metadata blocks\n");
115 printf(" -v : verbose\n");
116 printf(" -v- can all be used to turn off a particular option\n");
121 bool list(FILE *f, bool verbose)
123 static byte buf[65536];
124 FLAC__StreamMetaData metadata;
126 /* read the stream sync code */
127 if(fread(buf, 1, 4, f) < 4 || memcmp(buf, sync_string_, 4)) {
128 fprintf(stderr, "ERROR: not a FLAC file (no '%s' header)\n", sync_string_);
132 /* read the metadata blocks */
134 /* read the metadata block header */
135 if(fread(buf, 1, 4, f) < 4) {
136 fprintf(stderr, "ERROR: short count reading metadata block header\n");
139 metadata.is_last = (buf[0] & 0x80)? true:false;
140 metadata.type = (FLAC__MetaDataType)(buf[0] & 0x7f);
141 metadata.length = (((unsigned)buf[1]) << 16) | (((unsigned)buf[2]) << 8) | ((unsigned)buf[3]);
143 /* read the metadata block data */
146 printf("METADATA block:\n");
147 printf("\ttype: %u\n", (unsigned)metadata.type);
148 printf("\tis last: %s\n", metadata.is_last? "true":"false");
149 printf("\tlength: %u\n", metadata.length);
150 } while (!metadata.is_last);