initial import
[platform/upstream/flac.git] / src / metaflac / main.c
1 /* metaflac - Command-line FLAC metadata editor
2  * Copyright (C) 2001  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 <assert.h>
20 #include <ctype.h>
21 #include <stdarg.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include "FLAC/all.h"
26
27 static int usage(const char *message, ...);
28
29 int main(int argc, char *argv[])
30 {
31         bool verbose, list_mode;
32
33         if(argc <= 1)
34                 return usage(0);
35
36         /* get the options */
37         for(i = 1; i < argc; i++) {
38                 if(argv[i][0] != '-' || argv[i][1] == 0)
39                         break;
40                 if(0 == strcmp(argv[i], "-l"))
41                         list_mode = true;
42                 else if(0 == strcmp(argv[i], "-v"))
43                         verbose = true;
44                 else if(0 == strcmp(argv[i], "-v-"))
45                         verbose = false;
46                 else {
47                         return usage("ERROR: invalid option '%s'\n", argv[i]);
48                 }
49         }
50         if(i + (list_mode? 1:2) != argc)
51                 return usage("ERROR: invalid arguments (more/less than %d filename%s?)\n", (list_mode? 1:2), (list_mode? "":"s"));
52
53         return 0;
54 }
55
56 int usage(const char *message, ...)
57 {
58         va_list args;
59
60         if(message) {
61                 va_start(args, message);
62
63                 (void) vfprintf(stderr, message, args);
64
65                 va_end(args);
66
67         }
68         printf("==============================================================================\n");
69         printf("metaflac - Command-line FLAC metadata editor version %s\n", FLAC__VERSION_STRING);
70         printf("Copyright (C) 2001  Josh Coalson\n");
71         printf("\n");
72         printf("This program is free software; you can redistribute it and/or\n");
73         printf("modify it under the terms of the GNU General Public License\n");
74         printf("as published by the Free Software Foundation; either version 2\n");
75         printf("of the License, or (at your option) any later version.\n");
76         printf("\n");
77         printf("This program is distributed in the hope that it will be useful,\n");
78         printf("but WITHOUT ANY WARRANTY; without even the implied warranty of\n");
79         printf("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n");
80         printf("GNU General Public License for more details.\n");
81         printf("\n");
82         printf("You should have received a copy of the GNU General Public License\n");
83         printf("along with this program; if not, write to the Free Software\n");
84         printf("Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\n");
85         printf("==============================================================================\n");
86         printf("Usage:\n");
87         printf("  metaflac [options] infile [outfile]\n");
88         printf("\n");
89         printf("options:\n");
90         printf("  -l : list metadata blocks\n");
91         printf("  -v : verbose\n");
92         printf("  -v- can all be used to turn off a particular option\n");
93
94         return 1;
95 }